diff --git a/c/test/auto_check_sbp_acquisition_MsgAcqResult.c b/c/test/auto_check_sbp_acquisition_MsgAcqResult.c new file mode 100644 index 0000000000..b1ee71b191 --- /dev/null +++ b/c/test/auto_check_sbp_acquisition_MsgAcqResult.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_acquisition_MsgAcqResult) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x2f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, + 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, 189, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.acq_result.cf = 8241.2001953125; + + test_msg.acq_result.cn0 = 14.5; + + test_msg.acq_result.cp = 72.19999694824219; + + test_msg.acq_result.sid.code = 0; + + test_msg.acq_result.sid.sat = 8; + + sbp_message_send(&sbp_state, SbpMsgAcqResult, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAcqResult, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.acq_result.cf * 100 - 8241.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.acq_result.cf, expected " + "8241.20019531, is %s", + last_msg.msg.acq_result.cf); + + ck_assert_msg( + (last_msg.msg.acq_result.cn0 * 100 - 14.5 * 100) < 0.05, + "incorrect value for last_msg.msg.acq_result.cn0, expected 14.5, is %s", + last_msg.msg.acq_result.cn0); + + ck_assert_msg( + (last_msg.msg.acq_result.cp * 100 - 72.1999969482 * 100) < 0.05, + "incorrect value for last_msg.msg.acq_result.cp, expected " + "72.1999969482, is %s", + last_msg.msg.acq_result.cp); + + ck_assert_msg(last_msg.msg.acq_result.sid.code == 0, + "incorrect value for last_msg.msg.acq_result.sid.code, " + "expected 0, is %d", + last_msg.msg.acq_result.sid.code); + + ck_assert_msg(last_msg.msg.acq_result.sid.sat == 8, + "incorrect value for last_msg.msg.acq_result.sid.sat, " + "expected 8, is %d", + last_msg.msg.acq_result.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_acquisition_MsgAcqResult_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_acquisition_MsgAcqResult"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_acquisition_MsgAcqResult"); + tcase_add_test(tc_acq, test_auto_check_sbp_acquisition_MsgAcqResult); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_acquisition_MsgAcqSvProfile.c b/c/test/auto_check_sbp_acquisition_MsgAcqSvProfile.c new file mode 100644 index 0000000000..1c3d722aea --- /dev/null +++ b/c/test/auto_check_sbp_acquisition_MsgAcqSvProfile.c @@ -0,0 +1,474 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_acquisition_MsgAcqSvProfile) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x2e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, + 0, 52, 0, 0, 0, 49, 0, 0, 0, 61, 0, 0, 0, 147, + 0, 0, 0, 47, 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, + 0, 253, 23, 1, 121, 0, 190, 0, 0, 0, 175, 0, 0, 0, + 175, 0, 0, 0, 142, 0, 0, 0, 237, 0, 0, 0, 12, 0, + 0, 0, 126, 88, 21, 0, 153, 24, 0, 8, 0, 130, 0, 0, + 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, 0, 84, + 0, 0, 0, 82, 0, 0, 0, 168, 177, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.acq_sv_profile.acq_sv_profile[0].bin_width = 174; + + test_msg.acq_sv_profile.acq_sv_profile[0].cf = 47; + + test_msg.acq_sv_profile.acq_sv_profile[0].cf_max = 147; + + test_msg.acq_sv_profile.acq_sv_profile[0].cf_min = 61; + + test_msg.acq_sv_profile.acq_sv_profile[0].cn0 = 38; + + test_msg.acq_sv_profile.acq_sv_profile[0].cp = 140; + + test_msg.acq_sv_profile.acq_sv_profile[0].int_time = 97; + + test_msg.acq_sv_profile.acq_sv_profile[0].job_type = 7; + + test_msg.acq_sv_profile.acq_sv_profile[0].sid.code = 0; + + test_msg.acq_sv_profile.acq_sv_profile[0].sid.sat = 22; + + test_msg.acq_sv_profile.acq_sv_profile[0].status = 13; + + test_msg.acq_sv_profile.acq_sv_profile[0].time_spent = 49; + + test_msg.acq_sv_profile.acq_sv_profile[0].timestamp = 52; + + test_msg.acq_sv_profile.acq_sv_profile[1].bin_width = 121; + + test_msg.acq_sv_profile.acq_sv_profile[1].cf = 237; + + test_msg.acq_sv_profile.acq_sv_profile[1].cf_max = 142; + + test_msg.acq_sv_profile.acq_sv_profile[1].cf_min = 175; + + test_msg.acq_sv_profile.acq_sv_profile[1].cn0 = 59; + + test_msg.acq_sv_profile.acq_sv_profile[1].cp = 12; + + test_msg.acq_sv_profile.acq_sv_profile[1].int_time = 253; + + test_msg.acq_sv_profile.acq_sv_profile[1].job_type = 166; + + test_msg.acq_sv_profile.acq_sv_profile[1].sid.code = 1; + + test_msg.acq_sv_profile.acq_sv_profile[1].sid.sat = 23; + + test_msg.acq_sv_profile.acq_sv_profile[1].status = 210; + + test_msg.acq_sv_profile.acq_sv_profile[1].time_spent = 175; + + test_msg.acq_sv_profile.acq_sv_profile[1].timestamp = 190; + + test_msg.acq_sv_profile.acq_sv_profile[2].bin_width = 8; + + test_msg.acq_sv_profile.acq_sv_profile[2].cf = 84; + + test_msg.acq_sv_profile.acq_sv_profile[2].cf_max = 191; + + test_msg.acq_sv_profile.acq_sv_profile[2].cf_min = 91; + + test_msg.acq_sv_profile.acq_sv_profile[2].cn0 = 21; + + test_msg.acq_sv_profile.acq_sv_profile[2].cp = 82; + + test_msg.acq_sv_profile.acq_sv_profile[2].int_time = 153; + + test_msg.acq_sv_profile.acq_sv_profile[2].job_type = 126; + + test_msg.acq_sv_profile.acq_sv_profile[2].sid.code = 0; + + test_msg.acq_sv_profile.acq_sv_profile[2].sid.sat = 24; + + test_msg.acq_sv_profile.acq_sv_profile[2].status = 88; + + test_msg.acq_sv_profile.acq_sv_profile[2].time_spent = 172; + + test_msg.acq_sv_profile.acq_sv_profile[2].timestamp = 130; + + test_msg.acq_sv_profile.n_acq_sv_profile = 3; + + sbp_message_send(&sbp_state, SbpMsgAcqSvProfile, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAcqSvProfile, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[0].bin_width == 174, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].bin_width, expected " + "174, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].bin_width); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf == 47, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf, " + "expected 47, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_max == 147, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_max, " + "expected 147, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_max); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_min == 61, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_min, " + "expected 61, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cf_min); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cn0 == 38, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].cn0, expected 38, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cn0); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cp == 140, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[0].cp, " + "expected 140, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].cp); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].int_time == 97, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].int_time, " + "expected 97, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].int_time); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].job_type == 7, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].job_type, " + "expected 7, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].job_type); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.code == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.code, " + "expected 0, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.code); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.sat == 22, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.sat, " + "expected 22, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].sid.sat); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].status == 13, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].status, " + "expected 13, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[0].time_spent == 49, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].time_spent, expected " + "49, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].time_spent); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[0].timestamp == 52, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[0].timestamp, " + "expected 52, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[0].timestamp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].bin_width == 121, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].bin_width, expected " + "121, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].bin_width); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf == 237, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf, " + "expected 237, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_max == 142, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_max, " + "expected 142, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_max); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_min == 175, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_min, " + "expected 175, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cf_min); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cn0 == 59, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].cn0, expected 59, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cn0); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cp == 12, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[1].cp, " + "expected 12, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].cp); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].int_time == 253, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].int_time, " + "expected 253, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].int_time); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].job_type == 166, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].job_type, " + "expected 166, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].job_type); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.code == 1, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.code, " + "expected 1, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.code); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.sat == 23, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.sat, " + "expected 23, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].sid.sat); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[1].status == 210, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].status, " + "expected 210, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].time_spent == 175, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].time_spent, expected " + "175, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].time_spent); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[1].timestamp == 190, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[1].timestamp, expected " + "190, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[1].timestamp); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].bin_width == 8, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].bin_width, " + "expected 8, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].bin_width); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf == 84, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf, " + "expected 84, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_max == 191, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_max, " + "expected 191, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_max); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_min == 91, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_min, " + "expected 91, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cf_min); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cn0 == 21, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].cn0, expected 21, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cn0); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cp == 82, + "incorrect value for last_msg.msg.acq_sv_profile.acq_sv_profile[2].cp, " + "expected 82, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].cp); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].int_time == 153, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].int_time, " + "expected 153, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].int_time); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].job_type == 126, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].job_type, " + "expected 126, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].job_type); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.code == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.code, " + "expected 0, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.code); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.sat == 24, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.sat, " + "expected 24, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].sid.sat); + + ck_assert_msg(last_msg.msg.acq_sv_profile.acq_sv_profile[2].status == 88, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].status, " + "expected 88, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[2].time_spent == 172, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].time_spent, expected " + "172, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].time_spent); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.acq_sv_profile[2].timestamp == 130, + "incorrect value for " + "last_msg.msg.acq_sv_profile.acq_sv_profile[2].timestamp, expected " + "130, is %d", + last_msg.msg.acq_sv_profile.acq_sv_profile[2].timestamp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile.n_acq_sv_profile == 3, + "incorrect value for last_msg.msg.acq_sv_profile.n_acq_sv_profile, " + "expected 3, is %d", + last_msg.msg.acq_sv_profile.n_acq_sv_profile); + } +} +END_TEST + +Suite *auto_check_sbp_acquisition_MsgAcqSvProfile_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_acquisition_MsgAcqSvProfile"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_acquisition_MsgAcqSvProfile"); + tcase_add_test(tc_acq, test_auto_check_sbp_acquisition_MsgAcqSvProfile); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c b/c/test/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c new file mode 100644 index 0000000000..7069fb3799 --- /dev/null +++ b/c/test/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c @@ -0,0 +1,525 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_acquisition_MsgAcqSvProfileDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, + 187, 0, 91, 0, 0, 0, 75, 0, 0, 0, 132, 0, 0, 0, 36, + 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, + 179, 23, 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, + 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, 247, 0, 0, + 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, + 0, 245, 0, 0, 0, 76, 0, 0, 0, 248, 0, 0, 0, 212, 0, + 0, 0, 101, 0, 0, 0, 67, 132, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].bin_width = 187; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].cf = 60; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].cf_max = 36; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].cf_min = 132; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].cn0 = 151; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].cp = 241; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].int_time = 12; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].job_type = 67; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].sid.code = 0; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].sid.reserved = 0; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].sid.sat = 22; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].status = 103; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].time_spent = 75; + + test_msg.acq_sv_profile_dep.acq_sv_profile[0].timestamp = 91; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].bin_width = 176; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].cf = 212; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].cf_max = 24; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].cf_min = 155; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].cn0 = 111; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].cp = 247; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].int_time = 179; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].job_type = 238; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].sid.code = 1; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].sid.reserved = 0; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].sid.sat = 23; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].status = 38; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].time_spent = 234; + + test_msg.acq_sv_profile_dep.acq_sv_profile[1].timestamp = 166; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].bin_width = 52; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].cf = 212; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].cf_max = 248; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].cf_min = 76; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].cn0 = 68; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].cp = 101; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].int_time = 53; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].job_type = 142; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].sid.code = 0; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].sid.reserved = 0; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].sid.sat = 24; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].status = 213; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].time_spent = 245; + + test_msg.acq_sv_profile_dep.acq_sv_profile[2].timestamp = 49; + + test_msg.acq_sv_profile_dep.n_acq_sv_profile = 3; + + sbp_message_send(&sbp_state, SbpMsgAcqSvProfileDep, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAcqSvProfileDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].bin_width == 187, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].bin_width, expected " + "187, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].bin_width); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf == 60, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf, " + "expected 60, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_max == 36, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_max, expected " + "36, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_max); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_min == 132, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_min, expected " + "132, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cf_min); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cn0 == 151, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cn0, " + "expected 151, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cn0); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cp == 241, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cp, " + "expected 241, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].cp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].int_time == 12, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].int_time, expected " + "12, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].int_time); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].job_type == 67, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].job_type, expected " + "67, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].job_type); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.code == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.code, expected " + "0, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.code); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.reserved == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.reserved, " + "expected 0, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.reserved); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.sat == 22, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.sat, expected " + "22, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].sid.sat); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].status == 103, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].status, expected " + "103, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].time_spent == 75, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].time_spent, " + "expected 75, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].time_spent); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].timestamp == 91, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].timestamp, expected " + "91, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[0].timestamp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].bin_width == 176, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].bin_width, expected " + "176, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].bin_width); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf == 212, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf, " + "expected 212, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_max == 24, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_max, expected " + "24, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_max); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_min == 155, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_min, expected " + "155, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cf_min); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cn0 == 111, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cn0, " + "expected 111, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cn0); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cp == 247, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cp, " + "expected 247, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].cp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].int_time == 179, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].int_time, expected " + "179, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].int_time); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].job_type == 238, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].job_type, expected " + "238, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].job_type); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.code == 1, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.code, expected " + "1, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.code); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.reserved == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.reserved, " + "expected 0, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.reserved); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.sat == 23, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.sat, expected " + "23, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].sid.sat); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].status == 38, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].status, expected " + "38, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].time_spent == 234, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].time_spent, " + "expected 234, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].time_spent); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].timestamp == 166, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].timestamp, expected " + "166, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[1].timestamp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].bin_width == 52, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].bin_width, expected " + "52, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].bin_width); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf == 212, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf, " + "expected 212, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_max == 248, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_max, expected " + "248, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_max); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_min == 76, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_min, expected " + "76, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cf_min); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cn0 == 68, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cn0, " + "expected 68, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cn0); + + ck_assert_msg(last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cp == 101, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cp, " + "expected 101, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].cp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].int_time == 53, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].int_time, expected " + "53, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].int_time); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].job_type == 142, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].job_type, expected " + "142, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].job_type); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.code == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.code, expected " + "0, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.code); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.reserved == 0, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.reserved, " + "expected 0, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.reserved); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.sat == 24, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.sat, expected " + "24, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].sid.sat); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].status == 213, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].status, expected " + "213, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].status); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].time_spent == 245, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].time_spent, " + "expected 245, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].time_spent); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].timestamp == 49, + "incorrect value for " + "last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].timestamp, expected " + "49, is %d", + last_msg.msg.acq_sv_profile_dep.acq_sv_profile[2].timestamp); + + ck_assert_msg( + last_msg.msg.acq_sv_profile_dep.n_acq_sv_profile == 3, + "incorrect value for last_msg.msg.acq_sv_profile_dep.n_acq_sv_profile, " + "expected 3, is %d", + last_msg.msg.acq_sv_profile_dep.n_acq_sv_profile); + } +} +END_TEST + +Suite *auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_acquisition_MsgAcqSvProfileDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_acquisition_MsgAcqSvProfileDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_acquisition_MsgAcqSvProfileDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c b/c/test/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c new file mode 100644 index 0000000000..6821debaf1 --- /dev/null +++ b/c/test/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_bootload_MsgBootloaderHandshakeReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 179, 0, 136, 247, 0, 65, 216, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgBootloaderHandshakeReq, 63368, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63368, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgBootloaderHandshakeReq, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_bootload_MsgBootloaderHandshakeReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_bootload_MsgBootloaderHandshakeReq"); + tcase_add_test(tc_acq, + test_auto_check_sbp_bootload_MsgBootloaderHandshakeReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c b/c/test/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c new file mode 100644 index 0000000000..f79ab0ae9b --- /dev/null +++ b/c/test/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_bootload_MsgBootloaderJumptoApp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 177, 0, 205, 18, 1, 216, 105, 96, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.bootloader_jump_to_app.jump = 216; + + sbp_message_send(&sbp_state, SbpMsgBootloaderJumpToApp, 4813, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 4813, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgBootloaderJumpToApp, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.bootloader_jump_to_app.jump == 216, + "incorrect value for last_msg.msg.bootloader_jump_to_app.jump, " + "expected 216, is %d", + last_msg.msg.bootloader_jump_to_app.jump); + } +} +END_TEST + +Suite *auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_bootload_MsgBootloaderJumptoApp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_bootload_MsgBootloaderJumptoApp"); + tcase_add_test(tc_acq, test_auto_check_sbp_bootload_MsgBootloaderJumptoApp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c b/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c new file mode 100644 index 0000000000..6f499d9ca8 --- /dev/null +++ b/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_bootload_MsgNapDeviceDnaReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xde, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 222, 0, 128, 50, 0, 231, 160, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgNapDeviceDnaReq, 12928, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 12928, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgNapDeviceDnaReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_bootload_MsgNapDeviceDnaReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_bootload_MsgNapDeviceDnaReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_bootload_MsgNapDeviceDnaReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c b/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c new file mode 100644 index 0000000000..11eef7961e --- /dev/null +++ b/c/test/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_bootload_MsgNapDeviceDnaResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xdd, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.nap_device_dna_resp.dna[0] = 2; + + test_msg.nap_device_dna_resp.dna[1] = 187; + + test_msg.nap_device_dna_resp.dna[2] = 1; + + test_msg.nap_device_dna_resp.dna[3] = 130; + + test_msg.nap_device_dna_resp.dna[4] = 173; + + test_msg.nap_device_dna_resp.dna[5] = 244; + + test_msg.nap_device_dna_resp.dna[6] = 67; + + test_msg.nap_device_dna_resp.dna[7] = 122; + + sbp_message_send(&sbp_state, SbpMsgNapDeviceDnaResp, 14505, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14505, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgNapDeviceDnaResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.nap_device_dna_resp.dna[0] == 2, + "incorrect value for " + "last_msg.msg.nap_device_dna_resp.dna[0], expected 2, is %d", + last_msg.msg.nap_device_dna_resp.dna[0]); + ck_assert_msg( + last_msg.msg.nap_device_dna_resp.dna[1] == 187, + "incorrect value for last_msg.msg.nap_device_dna_resp.dna[1], expected " + "187, is %d", + last_msg.msg.nap_device_dna_resp.dna[1]); + ck_assert_msg(last_msg.msg.nap_device_dna_resp.dna[2] == 1, + "incorrect value for " + "last_msg.msg.nap_device_dna_resp.dna[2], expected 1, is %d", + last_msg.msg.nap_device_dna_resp.dna[2]); + ck_assert_msg( + last_msg.msg.nap_device_dna_resp.dna[3] == 130, + "incorrect value for last_msg.msg.nap_device_dna_resp.dna[3], expected " + "130, is %d", + last_msg.msg.nap_device_dna_resp.dna[3]); + ck_assert_msg( + last_msg.msg.nap_device_dna_resp.dna[4] == 173, + "incorrect value for last_msg.msg.nap_device_dna_resp.dna[4], expected " + "173, is %d", + last_msg.msg.nap_device_dna_resp.dna[4]); + ck_assert_msg( + last_msg.msg.nap_device_dna_resp.dna[5] == 244, + "incorrect value for last_msg.msg.nap_device_dna_resp.dna[5], expected " + "244, is %d", + last_msg.msg.nap_device_dna_resp.dna[5]); + ck_assert_msg(last_msg.msg.nap_device_dna_resp.dna[6] == 67, + "incorrect value for " + "last_msg.msg.nap_device_dna_resp.dna[6], expected 67, is %d", + last_msg.msg.nap_device_dna_resp.dna[6]); + ck_assert_msg( + last_msg.msg.nap_device_dna_resp.dna[7] == 122, + "incorrect value for last_msg.msg.nap_device_dna_resp.dna[7], expected " + "122, is %d", + last_msg.msg.nap_device_dna_resp.dna[7]); + } +} +END_TEST + +Suite *auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_bootload_MsgNapDeviceDnaResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_bootload_MsgNapDeviceDnaResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_bootload_MsgNapDeviceDnaResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioConfigReq.c b/c/test/auto_check_sbp_file_io_MsgFileioConfigReq.c new file mode 100644 index 0000000000..3d086cbbfa --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioConfigReq.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioConfigReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1001, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.fileio_config_req.sequence = 1514527339; + + sbp_message_send(&sbp_state, SbpMsgFileioConfigReq, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioConfigReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.fileio_config_req.sequence == 1514527339, + "incorrect value for last_msg.msg.fileio_config_req.sequence, expected " + "1514527339, is %d", + last_msg.msg.fileio_config_req.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioConfigReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioConfigReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_file_io_MsgFileioConfigReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioConfigReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioConfigResp.c b/c/test/auto_check_sbp_file_io_MsgFileioConfigResp.c new file mode 100644 index 0000000000..792e6b068a --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioConfigResp.c @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioConfigResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1002, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, + 44, 3, 216, 151, 255, 61, 12, 97, 66, 144, 239, 115, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.fileio_config_resp.batch_size = 1040160728; + + test_msg.fileio_config_resp.fileio_version = 2420269324; + + test_msg.fileio_config_resp.sequence = 1530154154; + + test_msg.fileio_config_resp.window_size = 53262997; + + sbp_message_send(&sbp_state, SbpMsgFileioConfigResp, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioConfigResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.fileio_config_resp.batch_size == 1040160728, + "incorrect value for last_msg.msg.fileio_config_resp.batch_size, " + "expected 1040160728, is %d", + last_msg.msg.fileio_config_resp.batch_size); + + ck_assert_msg( + last_msg.msg.fileio_config_resp.fileio_version == 2420269324, + "incorrect value for last_msg.msg.fileio_config_resp.fileio_version, " + "expected 2420269324, is %d", + last_msg.msg.fileio_config_resp.fileio_version); + + ck_assert_msg( + last_msg.msg.fileio_config_resp.sequence == 1530154154, + "incorrect value for last_msg.msg.fileio_config_resp.sequence, " + "expected 1530154154, is %d", + last_msg.msg.fileio_config_resp.sequence); + + ck_assert_msg( + last_msg.msg.fileio_config_resp.window_size == 53262997, + "incorrect value for last_msg.msg.fileio_config_resp.window_size, " + "expected 53262997, is %d", + last_msg.msg.fileio_config_resp.window_size); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioConfigResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioConfigResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_file_io_MsgFileioConfigResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioConfigResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioReadDirReq.c b/c/test/auto_check_sbp_file_io_MsgFileioReadDirReq.c new file mode 100644 index 0000000000..8e1498d994 --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioReadDirReq.c @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioReadDirReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa9, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, + 47, 134, 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, + 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg(sbp_msg_fileio_read_dir_req_dirname_set( + &test_msg.fileio_read_dir_req, "/some/random/path", false, + &written), + "Can't assign text"); + ck_assert_msg(written == strlen("/some/random/path"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_fileio_read_dir_req_dirname_encoded_len( + &test_msg.fileio_read_dir_req) == 18, + "String not encoded properly"); + + test_msg.fileio_read_dir_req.offset = 2251261636; + + test_msg.fileio_read_dir_req.sequence = 1526720386; + + sbp_message_send(&sbp_state, SbpMsgFileioReadDirReq, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioReadDirReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_fileio_read_dir_req_dirname_encoded_len( + &last_msg.msg.fileio_read_dir_req) == 18, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_fileio_read_dir_req_dirname_get( + &last_msg.msg.fileio_read_dir_req), + "/some/random/path") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.fileio_read_dir_req.offset == 2251261636, + "incorrect value for last_msg.msg.fileio_read_dir_req.offset, expected " + "2251261636, is %d", + last_msg.msg.fileio_read_dir_req.offset); + + ck_assert_msg( + last_msg.msg.fileio_read_dir_req.sequence == 1526720386, + "incorrect value for last_msg.msg.fileio_read_dir_req.sequence, " + "expected 1526720386, is %d", + last_msg.msg.fileio_read_dir_req.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioReadDirReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioReadDirReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_file_io_MsgFileioReadDirReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioReadDirReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioReadDirResp.c b/c/test/auto_check_sbp_file_io_MsgFileioReadDirResp.c new file mode 100644 index 0000000000..513d40c542 --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioReadDirResp.c @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioReadDirResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xaa, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, + 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, 108, 101, + 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, 111, + 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_fileio_read_dir_resp_contents_add_section( + &test_msg.fileio_read_dir_resp, "file1") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_fileio_read_dir_resp_contents_add_section( + &test_msg.fileio_read_dir_resp, "another file") == true, + "Can't assign section 1"); + ck_assert_msg( + sbp_msg_fileio_read_dir_resp_contents_add_section( + &test_msg.fileio_read_dir_resp, "definitely not a file") == true, + "Can't assign section 2"); + ck_assert_msg(sbp_msg_fileio_read_dir_resp_contents_encoded_len( + &test_msg.fileio_read_dir_resp) == 41, + "String not encoded properly"); + + test_msg.fileio_read_dir_resp.sequence = 3957390670; + + sbp_message_send(&sbp_state, SbpMsgFileioReadDirResp, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioReadDirResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_fileio_read_dir_resp_contents_encoded_len( + &last_msg.msg.fileio_read_dir_resp) == 41, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_fileio_read_dir_resp_contents_get_section( + &last_msg.msg.fileio_read_dir_resp, 0), + "file1") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_fileio_read_dir_resp_contents_get_section( + &last_msg.msg.fileio_read_dir_resp, 1), + "another file") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_fileio_read_dir_resp_contents_get_section( + &last_msg.msg.fileio_read_dir_resp, 2), + "definitely not a file") == 0, + "Section 2 not decoded properly"); + + ck_assert_msg( + last_msg.msg.fileio_read_dir_resp.sequence == 3957390670, + "incorrect value for last_msg.msg.fileio_read_dir_resp.sequence, " + "expected 3957390670, is %d", + last_msg.msg.fileio_read_dir_resp.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioReadDirResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioReadDirResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_file_io_MsgFileioReadDirResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioReadDirResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioReadReq.c b/c/test/auto_check_sbp_file_io_MsgFileioReadReq.c new file mode 100644 index 0000000000..b1d9ee4d8b --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioReadReq.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioReadReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, + 190, 23, 53, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.fileio_read_req.chunk_size = 53; + + size_t written; + ck_assert_msg( + sbp_msg_fileio_read_req_filename_set( + &test_msg.fileio_read_req, "/path/to/some/file", false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("/path/to/some/file"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_fileio_read_req_filename_encoded_len( + &test_msg.fileio_read_req) == 19, + "String not encoded properly"); + + test_msg.fileio_read_req.offset = 398373474; + + test_msg.fileio_read_req.sequence = 679648290; + + sbp_message_send(&sbp_state, SbpMsgFileioReadReq, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioReadReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.fileio_read_req.chunk_size == 53, + "incorrect value for " + "last_msg.msg.fileio_read_req.chunk_size, expected 53, is %d", + last_msg.msg.fileio_read_req.chunk_size); + + ck_assert_msg(sbp_msg_fileio_read_req_filename_encoded_len( + &last_msg.msg.fileio_read_req) == 19, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_fileio_read_req_filename_get( + &last_msg.msg.fileio_read_req), + "/path/to/some/file") == 0, + "String not decoded properly"); + + ck_assert_msg(last_msg.msg.fileio_read_req.offset == 398373474, + "incorrect value for last_msg.msg.fileio_read_req.offset, " + "expected 398373474, is %d", + last_msg.msg.fileio_read_req.offset); + + ck_assert_msg(last_msg.msg.fileio_read_req.sequence == 679648290, + "incorrect value for last_msg.msg.fileio_read_req.sequence, " + "expected 679648290, is %d", + last_msg.msg.fileio_read_req.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioReadReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_file_io_MsgFileioReadReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioReadResp.c b/c/test/auto_check_sbp_file_io_MsgFileioReadResp.c new file mode 100644 index 0000000000..45f0aae40c --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioReadResp.c @@ -0,0 +1,1931 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioReadResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, + 18, 76, 68, 229, 216, 21, 98, 183, 69, 190, 5, 252, 176, 55, + 32, 78, 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, 46, 79, + 118, 248, 118, 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, + 206, 185, 140, 249, 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, + 77, 224, 124, 238, 205, 65, 103, 35, 104, 209, 5, 191, 47, 249, + 176, 166, 213, 46, 192, 86, 32, 103, 146, 252, 4, 16, 54, 161, + 60, 6, 13, 191, 116, 182, 42, 191, 213, 20, 217, 8, 142, 187, + 238, 120, 184, 250, 31, 151, 37, 51, 177, 130, 190, 155, 71, 68, + 56, 238, 92, 130, 37, 137, 146, 246, 114, 116, 138, 165, 217, 79, + 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, 236, 228, 194, 0, + 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, 3, 240, 205, + 253, 113, 25, 28, 187, 81, 101, 216, 121, 41, 179, 120, 152, 18, + 116, 53, 212, 100, 2, 114, 198, 200, 10, 147, 25, 33, 115, 208, + 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, 133, + 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, + 180, 180, 125, 97, 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, + 65, 4, 64, 19, 74, 223, 111, 109, 52, 43, 167, 186, 202, 111, + 11, 91, 21, 236, 234, 196, 36, 171, 147, 10, 240, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.fileio_read_resp.contents[0] = 73; + + test_msg.fileio_read_resp.contents[1] = 231; + + test_msg.fileio_read_resp.contents[2] = 227; + + test_msg.fileio_read_resp.contents[3] = 179; + + test_msg.fileio_read_resp.contents[4] = 18; + + test_msg.fileio_read_resp.contents[5] = 76; + + test_msg.fileio_read_resp.contents[6] = 68; + + test_msg.fileio_read_resp.contents[7] = 229; + + test_msg.fileio_read_resp.contents[8] = 216; + + test_msg.fileio_read_resp.contents[9] = 21; + + test_msg.fileio_read_resp.contents[10] = 98; + + test_msg.fileio_read_resp.contents[11] = 183; + + test_msg.fileio_read_resp.contents[12] = 69; + + test_msg.fileio_read_resp.contents[13] = 190; + + test_msg.fileio_read_resp.contents[14] = 5; + + test_msg.fileio_read_resp.contents[15] = 252; + + test_msg.fileio_read_resp.contents[16] = 176; + + test_msg.fileio_read_resp.contents[17] = 55; + + test_msg.fileio_read_resp.contents[18] = 32; + + test_msg.fileio_read_resp.contents[19] = 78; + + test_msg.fileio_read_resp.contents[20] = 8; + + test_msg.fileio_read_resp.contents[21] = 52; + + test_msg.fileio_read_resp.contents[22] = 127; + + test_msg.fileio_read_resp.contents[23] = 50; + + test_msg.fileio_read_resp.contents[24] = 71; + + test_msg.fileio_read_resp.contents[25] = 106; + + test_msg.fileio_read_resp.contents[26] = 61; + + test_msg.fileio_read_resp.contents[27] = 79; + + test_msg.fileio_read_resp.contents[28] = 191; + + test_msg.fileio_read_resp.contents[29] = 106; + + test_msg.fileio_read_resp.contents[30] = 46; + + test_msg.fileio_read_resp.contents[31] = 79; + + test_msg.fileio_read_resp.contents[32] = 118; + + test_msg.fileio_read_resp.contents[33] = 248; + + test_msg.fileio_read_resp.contents[34] = 118; + + test_msg.fileio_read_resp.contents[35] = 207; + + test_msg.fileio_read_resp.contents[36] = 206; + + test_msg.fileio_read_resp.contents[37] = 210; + + test_msg.fileio_read_resp.contents[38] = 91; + + test_msg.fileio_read_resp.contents[39] = 73; + + test_msg.fileio_read_resp.contents[40] = 251; + + test_msg.fileio_read_resp.contents[41] = 81; + + test_msg.fileio_read_resp.contents[42] = 131; + + test_msg.fileio_read_resp.contents[43] = 205; + + test_msg.fileio_read_resp.contents[44] = 193; + + test_msg.fileio_read_resp.contents[45] = 146; + + test_msg.fileio_read_resp.contents[46] = 206; + + test_msg.fileio_read_resp.contents[47] = 185; + + test_msg.fileio_read_resp.contents[48] = 140; + + test_msg.fileio_read_resp.contents[49] = 249; + + test_msg.fileio_read_resp.contents[50] = 163; + + test_msg.fileio_read_resp.contents[51] = 231; + + test_msg.fileio_read_resp.contents[52] = 65; + + test_msg.fileio_read_resp.contents[53] = 67; + + test_msg.fileio_read_resp.contents[54] = 94; + + test_msg.fileio_read_resp.contents[55] = 250; + + test_msg.fileio_read_resp.contents[56] = 109; + + test_msg.fileio_read_resp.contents[57] = 152; + + test_msg.fileio_read_resp.contents[58] = 95; + + test_msg.fileio_read_resp.contents[59] = 123; + + test_msg.fileio_read_resp.contents[60] = 77; + + test_msg.fileio_read_resp.contents[61] = 224; + + test_msg.fileio_read_resp.contents[62] = 124; + + test_msg.fileio_read_resp.contents[63] = 238; + + test_msg.fileio_read_resp.contents[64] = 205; + + test_msg.fileio_read_resp.contents[65] = 65; + + test_msg.fileio_read_resp.contents[66] = 103; + + test_msg.fileio_read_resp.contents[67] = 35; + + test_msg.fileio_read_resp.contents[68] = 104; + + test_msg.fileio_read_resp.contents[69] = 209; + + test_msg.fileio_read_resp.contents[70] = 5; + + test_msg.fileio_read_resp.contents[71] = 191; + + test_msg.fileio_read_resp.contents[72] = 47; + + test_msg.fileio_read_resp.contents[73] = 249; + + test_msg.fileio_read_resp.contents[74] = 176; + + test_msg.fileio_read_resp.contents[75] = 166; + + test_msg.fileio_read_resp.contents[76] = 213; + + test_msg.fileio_read_resp.contents[77] = 46; + + test_msg.fileio_read_resp.contents[78] = 192; + + test_msg.fileio_read_resp.contents[79] = 86; + + test_msg.fileio_read_resp.contents[80] = 32; + + test_msg.fileio_read_resp.contents[81] = 103; + + test_msg.fileio_read_resp.contents[82] = 146; + + test_msg.fileio_read_resp.contents[83] = 252; + + test_msg.fileio_read_resp.contents[84] = 4; + + test_msg.fileio_read_resp.contents[85] = 16; + + test_msg.fileio_read_resp.contents[86] = 54; + + test_msg.fileio_read_resp.contents[87] = 161; + + test_msg.fileio_read_resp.contents[88] = 60; + + test_msg.fileio_read_resp.contents[89] = 6; + + test_msg.fileio_read_resp.contents[90] = 13; + + test_msg.fileio_read_resp.contents[91] = 191; + + test_msg.fileio_read_resp.contents[92] = 116; + + test_msg.fileio_read_resp.contents[93] = 182; + + test_msg.fileio_read_resp.contents[94] = 42; + + test_msg.fileio_read_resp.contents[95] = 191; + + test_msg.fileio_read_resp.contents[96] = 213; + + test_msg.fileio_read_resp.contents[97] = 20; + + test_msg.fileio_read_resp.contents[98] = 217; + + test_msg.fileio_read_resp.contents[99] = 8; + + test_msg.fileio_read_resp.contents[100] = 142; + + test_msg.fileio_read_resp.contents[101] = 187; + + test_msg.fileio_read_resp.contents[102] = 238; + + test_msg.fileio_read_resp.contents[103] = 120; + + test_msg.fileio_read_resp.contents[104] = 184; + + test_msg.fileio_read_resp.contents[105] = 250; + + test_msg.fileio_read_resp.contents[106] = 31; + + test_msg.fileio_read_resp.contents[107] = 151; + + test_msg.fileio_read_resp.contents[108] = 37; + + test_msg.fileio_read_resp.contents[109] = 51; + + test_msg.fileio_read_resp.contents[110] = 177; + + test_msg.fileio_read_resp.contents[111] = 130; + + test_msg.fileio_read_resp.contents[112] = 190; + + test_msg.fileio_read_resp.contents[113] = 155; + + test_msg.fileio_read_resp.contents[114] = 71; + + test_msg.fileio_read_resp.contents[115] = 68; + + test_msg.fileio_read_resp.contents[116] = 56; + + test_msg.fileio_read_resp.contents[117] = 238; + + test_msg.fileio_read_resp.contents[118] = 92; + + test_msg.fileio_read_resp.contents[119] = 130; + + test_msg.fileio_read_resp.contents[120] = 37; + + test_msg.fileio_read_resp.contents[121] = 137; + + test_msg.fileio_read_resp.contents[122] = 146; + + test_msg.fileio_read_resp.contents[123] = 246; + + test_msg.fileio_read_resp.contents[124] = 114; + + test_msg.fileio_read_resp.contents[125] = 116; + + test_msg.fileio_read_resp.contents[126] = 138; + + test_msg.fileio_read_resp.contents[127] = 165; + + test_msg.fileio_read_resp.contents[128] = 217; + + test_msg.fileio_read_resp.contents[129] = 79; + + test_msg.fileio_read_resp.contents[130] = 10; + + test_msg.fileio_read_resp.contents[131] = 189; + + test_msg.fileio_read_resp.contents[132] = 128; + + test_msg.fileio_read_resp.contents[133] = 189; + + test_msg.fileio_read_resp.contents[134] = 2; + + test_msg.fileio_read_resp.contents[135] = 240; + + test_msg.fileio_read_resp.contents[136] = 92; + + test_msg.fileio_read_resp.contents[137] = 28; + + test_msg.fileio_read_resp.contents[138] = 126; + + test_msg.fileio_read_resp.contents[139] = 105; + + test_msg.fileio_read_resp.contents[140] = 236; + + test_msg.fileio_read_resp.contents[141] = 228; + + test_msg.fileio_read_resp.contents[142] = 194; + + test_msg.fileio_read_resp.contents[143] = 0; + + test_msg.fileio_read_resp.contents[144] = 51; + + test_msg.fileio_read_resp.contents[145] = 61; + + test_msg.fileio_read_resp.contents[146] = 74; + + test_msg.fileio_read_resp.contents[147] = 41; + + test_msg.fileio_read_resp.contents[148] = 10; + + test_msg.fileio_read_resp.contents[149] = 239; + + test_msg.fileio_read_resp.contents[150] = 133; + + test_msg.fileio_read_resp.contents[151] = 106; + + test_msg.fileio_read_resp.contents[152] = 190; + + test_msg.fileio_read_resp.contents[153] = 30; + + test_msg.fileio_read_resp.contents[154] = 27; + + test_msg.fileio_read_resp.contents[155] = 3; + + test_msg.fileio_read_resp.contents[156] = 240; + + test_msg.fileio_read_resp.contents[157] = 205; + + test_msg.fileio_read_resp.contents[158] = 253; + + test_msg.fileio_read_resp.contents[159] = 113; + + test_msg.fileio_read_resp.contents[160] = 25; + + test_msg.fileio_read_resp.contents[161] = 28; + + test_msg.fileio_read_resp.contents[162] = 187; + + test_msg.fileio_read_resp.contents[163] = 81; + + test_msg.fileio_read_resp.contents[164] = 101; + + test_msg.fileio_read_resp.contents[165] = 216; + + test_msg.fileio_read_resp.contents[166] = 121; + + test_msg.fileio_read_resp.contents[167] = 41; + + test_msg.fileio_read_resp.contents[168] = 179; + + test_msg.fileio_read_resp.contents[169] = 120; + + test_msg.fileio_read_resp.contents[170] = 152; + + test_msg.fileio_read_resp.contents[171] = 18; + + test_msg.fileio_read_resp.contents[172] = 116; + + test_msg.fileio_read_resp.contents[173] = 53; + + test_msg.fileio_read_resp.contents[174] = 212; + + test_msg.fileio_read_resp.contents[175] = 100; + + test_msg.fileio_read_resp.contents[176] = 2; + + test_msg.fileio_read_resp.contents[177] = 114; + + test_msg.fileio_read_resp.contents[178] = 198; + + test_msg.fileio_read_resp.contents[179] = 200; + + test_msg.fileio_read_resp.contents[180] = 10; + + test_msg.fileio_read_resp.contents[181] = 147; + + test_msg.fileio_read_resp.contents[182] = 25; + + test_msg.fileio_read_resp.contents[183] = 33; + + test_msg.fileio_read_resp.contents[184] = 115; + + test_msg.fileio_read_resp.contents[185] = 208; + + test_msg.fileio_read_resp.contents[186] = 113; + + test_msg.fileio_read_resp.contents[187] = 60; + + test_msg.fileio_read_resp.contents[188] = 179; + + test_msg.fileio_read_resp.contents[189] = 183; + + test_msg.fileio_read_resp.contents[190] = 0; + + test_msg.fileio_read_resp.contents[191] = 41; + + test_msg.fileio_read_resp.contents[192] = 217; + + test_msg.fileio_read_resp.contents[193] = 206; + + test_msg.fileio_read_resp.contents[194] = 255; + + test_msg.fileio_read_resp.contents[195] = 211; + + test_msg.fileio_read_resp.contents[196] = 225; + + test_msg.fileio_read_resp.contents[197] = 142; + + test_msg.fileio_read_resp.contents[198] = 191; + + test_msg.fileio_read_resp.contents[199] = 133; + + test_msg.fileio_read_resp.contents[200] = 81; + + test_msg.fileio_read_resp.contents[201] = 15; + + test_msg.fileio_read_resp.contents[202] = 248; + + test_msg.fileio_read_resp.contents[203] = 193; + + test_msg.fileio_read_resp.contents[204] = 66; + + test_msg.fileio_read_resp.contents[205] = 191; + + test_msg.fileio_read_resp.contents[206] = 244; + + test_msg.fileio_read_resp.contents[207] = 221; + + test_msg.fileio_read_resp.contents[208] = 248; + + test_msg.fileio_read_resp.contents[209] = 199; + + test_msg.fileio_read_resp.contents[210] = 241; + + test_msg.fileio_read_resp.contents[211] = 112; + + test_msg.fileio_read_resp.contents[212] = 51; + + test_msg.fileio_read_resp.contents[213] = 1; + + test_msg.fileio_read_resp.contents[214] = 180; + + test_msg.fileio_read_resp.contents[215] = 180; + + test_msg.fileio_read_resp.contents[216] = 125; + + test_msg.fileio_read_resp.contents[217] = 97; + + test_msg.fileio_read_resp.contents[218] = 145; + + test_msg.fileio_read_resp.contents[219] = 25; + + test_msg.fileio_read_resp.contents[220] = 72; + + test_msg.fileio_read_resp.contents[221] = 210; + + test_msg.fileio_read_resp.contents[222] = 215; + + test_msg.fileio_read_resp.contents[223] = 208; + + test_msg.fileio_read_resp.contents[224] = 15; + + test_msg.fileio_read_resp.contents[225] = 126; + + test_msg.fileio_read_resp.contents[226] = 56; + + test_msg.fileio_read_resp.contents[227] = 38; + + test_msg.fileio_read_resp.contents[228] = 65; + + test_msg.fileio_read_resp.contents[229] = 4; + + test_msg.fileio_read_resp.contents[230] = 64; + + test_msg.fileio_read_resp.contents[231] = 19; + + test_msg.fileio_read_resp.contents[232] = 74; + + test_msg.fileio_read_resp.contents[233] = 223; + + test_msg.fileio_read_resp.contents[234] = 111; + + test_msg.fileio_read_resp.contents[235] = 109; + + test_msg.fileio_read_resp.contents[236] = 52; + + test_msg.fileio_read_resp.contents[237] = 43; + + test_msg.fileio_read_resp.contents[238] = 167; + + test_msg.fileio_read_resp.contents[239] = 186; + + test_msg.fileio_read_resp.contents[240] = 202; + + test_msg.fileio_read_resp.contents[241] = 111; + + test_msg.fileio_read_resp.contents[242] = 11; + + test_msg.fileio_read_resp.contents[243] = 91; + + test_msg.fileio_read_resp.contents[244] = 21; + + test_msg.fileio_read_resp.contents[245] = 236; + + test_msg.fileio_read_resp.contents[246] = 234; + + test_msg.fileio_read_resp.contents[247] = 196; + + test_msg.fileio_read_resp.contents[248] = 36; + + test_msg.fileio_read_resp.contents[249] = 171; + + test_msg.fileio_read_resp.contents[250] = 147; + + test_msg.fileio_read_resp.n_contents = 251; + + test_msg.fileio_read_resp.sequence = 259241795; + + sbp_message_send(&sbp_state, SbpMsgFileioReadResp, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioReadResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[0] == 73, + "incorrect value for last_msg.msg.fileio_read_resp.contents[0], " + "expected 73, is %d", + last_msg.msg.fileio_read_resp.contents[0]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[1] == 231, + "incorrect value for last_msg.msg.fileio_read_resp.contents[1], " + "expected 231, is %d", + last_msg.msg.fileio_read_resp.contents[1]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[2] == 227, + "incorrect value for last_msg.msg.fileio_read_resp.contents[2], " + "expected 227, is %d", + last_msg.msg.fileio_read_resp.contents[2]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[3] == 179, + "incorrect value for last_msg.msg.fileio_read_resp.contents[3], " + "expected 179, is %d", + last_msg.msg.fileio_read_resp.contents[3]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[4] == 18, + "incorrect value for last_msg.msg.fileio_read_resp.contents[4], " + "expected 18, is %d", + last_msg.msg.fileio_read_resp.contents[4]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[5] == 76, + "incorrect value for last_msg.msg.fileio_read_resp.contents[5], " + "expected 76, is %d", + last_msg.msg.fileio_read_resp.contents[5]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[6] == 68, + "incorrect value for last_msg.msg.fileio_read_resp.contents[6], " + "expected 68, is %d", + last_msg.msg.fileio_read_resp.contents[6]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[7] == 229, + "incorrect value for last_msg.msg.fileio_read_resp.contents[7], " + "expected 229, is %d", + last_msg.msg.fileio_read_resp.contents[7]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[8] == 216, + "incorrect value for last_msg.msg.fileio_read_resp.contents[8], " + "expected 216, is %d", + last_msg.msg.fileio_read_resp.contents[8]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[9] == 21, + "incorrect value for last_msg.msg.fileio_read_resp.contents[9], " + "expected 21, is %d", + last_msg.msg.fileio_read_resp.contents[9]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[10] == 98, + "incorrect value for last_msg.msg.fileio_read_resp.contents[10], " + "expected 98, is %d", + last_msg.msg.fileio_read_resp.contents[10]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[11] == 183, + "incorrect value for last_msg.msg.fileio_read_resp.contents[11], " + "expected 183, is %d", + last_msg.msg.fileio_read_resp.contents[11]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[12] == 69, + "incorrect value for last_msg.msg.fileio_read_resp.contents[12], " + "expected 69, is %d", + last_msg.msg.fileio_read_resp.contents[12]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[13] == 190, + "incorrect value for last_msg.msg.fileio_read_resp.contents[13], " + "expected 190, is %d", + last_msg.msg.fileio_read_resp.contents[13]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[14] == 5, + "incorrect value for last_msg.msg.fileio_read_resp.contents[14], " + "expected 5, is %d", + last_msg.msg.fileio_read_resp.contents[14]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[15] == 252, + "incorrect value for last_msg.msg.fileio_read_resp.contents[15], " + "expected 252, is %d", + last_msg.msg.fileio_read_resp.contents[15]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[16] == 176, + "incorrect value for last_msg.msg.fileio_read_resp.contents[16], " + "expected 176, is %d", + last_msg.msg.fileio_read_resp.contents[16]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[17] == 55, + "incorrect value for last_msg.msg.fileio_read_resp.contents[17], " + "expected 55, is %d", + last_msg.msg.fileio_read_resp.contents[17]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[18] == 32, + "incorrect value for last_msg.msg.fileio_read_resp.contents[18], " + "expected 32, is %d", + last_msg.msg.fileio_read_resp.contents[18]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[19] == 78, + "incorrect value for last_msg.msg.fileio_read_resp.contents[19], " + "expected 78, is %d", + last_msg.msg.fileio_read_resp.contents[19]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[20] == 8, + "incorrect value for last_msg.msg.fileio_read_resp.contents[20], " + "expected 8, is %d", + last_msg.msg.fileio_read_resp.contents[20]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[21] == 52, + "incorrect value for last_msg.msg.fileio_read_resp.contents[21], " + "expected 52, is %d", + last_msg.msg.fileio_read_resp.contents[21]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[22] == 127, + "incorrect value for last_msg.msg.fileio_read_resp.contents[22], " + "expected 127, is %d", + last_msg.msg.fileio_read_resp.contents[22]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[23] == 50, + "incorrect value for last_msg.msg.fileio_read_resp.contents[23], " + "expected 50, is %d", + last_msg.msg.fileio_read_resp.contents[23]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[24] == 71, + "incorrect value for last_msg.msg.fileio_read_resp.contents[24], " + "expected 71, is %d", + last_msg.msg.fileio_read_resp.contents[24]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[25] == 106, + "incorrect value for last_msg.msg.fileio_read_resp.contents[25], " + "expected 106, is %d", + last_msg.msg.fileio_read_resp.contents[25]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[26] == 61, + "incorrect value for last_msg.msg.fileio_read_resp.contents[26], " + "expected 61, is %d", + last_msg.msg.fileio_read_resp.contents[26]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[27] == 79, + "incorrect value for last_msg.msg.fileio_read_resp.contents[27], " + "expected 79, is %d", + last_msg.msg.fileio_read_resp.contents[27]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[28] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[28], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[28]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[29] == 106, + "incorrect value for last_msg.msg.fileio_read_resp.contents[29], " + "expected 106, is %d", + last_msg.msg.fileio_read_resp.contents[29]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[30] == 46, + "incorrect value for last_msg.msg.fileio_read_resp.contents[30], " + "expected 46, is %d", + last_msg.msg.fileio_read_resp.contents[30]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[31] == 79, + "incorrect value for last_msg.msg.fileio_read_resp.contents[31], " + "expected 79, is %d", + last_msg.msg.fileio_read_resp.contents[31]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[32] == 118, + "incorrect value for last_msg.msg.fileio_read_resp.contents[32], " + "expected 118, is %d", + last_msg.msg.fileio_read_resp.contents[32]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[33] == 248, + "incorrect value for last_msg.msg.fileio_read_resp.contents[33], " + "expected 248, is %d", + last_msg.msg.fileio_read_resp.contents[33]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[34] == 118, + "incorrect value for last_msg.msg.fileio_read_resp.contents[34], " + "expected 118, is %d", + last_msg.msg.fileio_read_resp.contents[34]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[35] == 207, + "incorrect value for last_msg.msg.fileio_read_resp.contents[35], " + "expected 207, is %d", + last_msg.msg.fileio_read_resp.contents[35]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[36] == 206, + "incorrect value for last_msg.msg.fileio_read_resp.contents[36], " + "expected 206, is %d", + last_msg.msg.fileio_read_resp.contents[36]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[37] == 210, + "incorrect value for last_msg.msg.fileio_read_resp.contents[37], " + "expected 210, is %d", + last_msg.msg.fileio_read_resp.contents[37]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[38] == 91, + "incorrect value for last_msg.msg.fileio_read_resp.contents[38], " + "expected 91, is %d", + last_msg.msg.fileio_read_resp.contents[38]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[39] == 73, + "incorrect value for last_msg.msg.fileio_read_resp.contents[39], " + "expected 73, is %d", + last_msg.msg.fileio_read_resp.contents[39]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[40] == 251, + "incorrect value for last_msg.msg.fileio_read_resp.contents[40], " + "expected 251, is %d", + last_msg.msg.fileio_read_resp.contents[40]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[41] == 81, + "incorrect value for last_msg.msg.fileio_read_resp.contents[41], " + "expected 81, is %d", + last_msg.msg.fileio_read_resp.contents[41]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[42] == 131, + "incorrect value for last_msg.msg.fileio_read_resp.contents[42], " + "expected 131, is %d", + last_msg.msg.fileio_read_resp.contents[42]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[43] == 205, + "incorrect value for last_msg.msg.fileio_read_resp.contents[43], " + "expected 205, is %d", + last_msg.msg.fileio_read_resp.contents[43]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[44] == 193, + "incorrect value for last_msg.msg.fileio_read_resp.contents[44], " + "expected 193, is %d", + last_msg.msg.fileio_read_resp.contents[44]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[45] == 146, + "incorrect value for last_msg.msg.fileio_read_resp.contents[45], " + "expected 146, is %d", + last_msg.msg.fileio_read_resp.contents[45]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[46] == 206, + "incorrect value for last_msg.msg.fileio_read_resp.contents[46], " + "expected 206, is %d", + last_msg.msg.fileio_read_resp.contents[46]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[47] == 185, + "incorrect value for last_msg.msg.fileio_read_resp.contents[47], " + "expected 185, is %d", + last_msg.msg.fileio_read_resp.contents[47]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[48] == 140, + "incorrect value for last_msg.msg.fileio_read_resp.contents[48], " + "expected 140, is %d", + last_msg.msg.fileio_read_resp.contents[48]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[49] == 249, + "incorrect value for last_msg.msg.fileio_read_resp.contents[49], " + "expected 249, is %d", + last_msg.msg.fileio_read_resp.contents[49]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[50] == 163, + "incorrect value for last_msg.msg.fileio_read_resp.contents[50], " + "expected 163, is %d", + last_msg.msg.fileio_read_resp.contents[50]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[51] == 231, + "incorrect value for last_msg.msg.fileio_read_resp.contents[51], " + "expected 231, is %d", + last_msg.msg.fileio_read_resp.contents[51]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[52] == 65, + "incorrect value for last_msg.msg.fileio_read_resp.contents[52], " + "expected 65, is %d", + last_msg.msg.fileio_read_resp.contents[52]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[53] == 67, + "incorrect value for last_msg.msg.fileio_read_resp.contents[53], " + "expected 67, is %d", + last_msg.msg.fileio_read_resp.contents[53]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[54] == 94, + "incorrect value for last_msg.msg.fileio_read_resp.contents[54], " + "expected 94, is %d", + last_msg.msg.fileio_read_resp.contents[54]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[55] == 250, + "incorrect value for last_msg.msg.fileio_read_resp.contents[55], " + "expected 250, is %d", + last_msg.msg.fileio_read_resp.contents[55]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[56] == 109, + "incorrect value for last_msg.msg.fileio_read_resp.contents[56], " + "expected 109, is %d", + last_msg.msg.fileio_read_resp.contents[56]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[57] == 152, + "incorrect value for last_msg.msg.fileio_read_resp.contents[57], " + "expected 152, is %d", + last_msg.msg.fileio_read_resp.contents[57]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[58] == 95, + "incorrect value for last_msg.msg.fileio_read_resp.contents[58], " + "expected 95, is %d", + last_msg.msg.fileio_read_resp.contents[58]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[59] == 123, + "incorrect value for last_msg.msg.fileio_read_resp.contents[59], " + "expected 123, is %d", + last_msg.msg.fileio_read_resp.contents[59]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[60] == 77, + "incorrect value for last_msg.msg.fileio_read_resp.contents[60], " + "expected 77, is %d", + last_msg.msg.fileio_read_resp.contents[60]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[61] == 224, + "incorrect value for last_msg.msg.fileio_read_resp.contents[61], " + "expected 224, is %d", + last_msg.msg.fileio_read_resp.contents[61]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[62] == 124, + "incorrect value for last_msg.msg.fileio_read_resp.contents[62], " + "expected 124, is %d", + last_msg.msg.fileio_read_resp.contents[62]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[63] == 238, + "incorrect value for last_msg.msg.fileio_read_resp.contents[63], " + "expected 238, is %d", + last_msg.msg.fileio_read_resp.contents[63]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[64] == 205, + "incorrect value for last_msg.msg.fileio_read_resp.contents[64], " + "expected 205, is %d", + last_msg.msg.fileio_read_resp.contents[64]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[65] == 65, + "incorrect value for last_msg.msg.fileio_read_resp.contents[65], " + "expected 65, is %d", + last_msg.msg.fileio_read_resp.contents[65]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[66] == 103, + "incorrect value for last_msg.msg.fileio_read_resp.contents[66], " + "expected 103, is %d", + last_msg.msg.fileio_read_resp.contents[66]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[67] == 35, + "incorrect value for last_msg.msg.fileio_read_resp.contents[67], " + "expected 35, is %d", + last_msg.msg.fileio_read_resp.contents[67]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[68] == 104, + "incorrect value for last_msg.msg.fileio_read_resp.contents[68], " + "expected 104, is %d", + last_msg.msg.fileio_read_resp.contents[68]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[69] == 209, + "incorrect value for last_msg.msg.fileio_read_resp.contents[69], " + "expected 209, is %d", + last_msg.msg.fileio_read_resp.contents[69]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[70] == 5, + "incorrect value for last_msg.msg.fileio_read_resp.contents[70], " + "expected 5, is %d", + last_msg.msg.fileio_read_resp.contents[70]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[71] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[71], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[71]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[72] == 47, + "incorrect value for last_msg.msg.fileio_read_resp.contents[72], " + "expected 47, is %d", + last_msg.msg.fileio_read_resp.contents[72]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[73] == 249, + "incorrect value for last_msg.msg.fileio_read_resp.contents[73], " + "expected 249, is %d", + last_msg.msg.fileio_read_resp.contents[73]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[74] == 176, + "incorrect value for last_msg.msg.fileio_read_resp.contents[74], " + "expected 176, is %d", + last_msg.msg.fileio_read_resp.contents[74]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[75] == 166, + "incorrect value for last_msg.msg.fileio_read_resp.contents[75], " + "expected 166, is %d", + last_msg.msg.fileio_read_resp.contents[75]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[76] == 213, + "incorrect value for last_msg.msg.fileio_read_resp.contents[76], " + "expected 213, is %d", + last_msg.msg.fileio_read_resp.contents[76]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[77] == 46, + "incorrect value for last_msg.msg.fileio_read_resp.contents[77], " + "expected 46, is %d", + last_msg.msg.fileio_read_resp.contents[77]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[78] == 192, + "incorrect value for last_msg.msg.fileio_read_resp.contents[78], " + "expected 192, is %d", + last_msg.msg.fileio_read_resp.contents[78]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[79] == 86, + "incorrect value for last_msg.msg.fileio_read_resp.contents[79], " + "expected 86, is %d", + last_msg.msg.fileio_read_resp.contents[79]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[80] == 32, + "incorrect value for last_msg.msg.fileio_read_resp.contents[80], " + "expected 32, is %d", + last_msg.msg.fileio_read_resp.contents[80]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[81] == 103, + "incorrect value for last_msg.msg.fileio_read_resp.contents[81], " + "expected 103, is %d", + last_msg.msg.fileio_read_resp.contents[81]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[82] == 146, + "incorrect value for last_msg.msg.fileio_read_resp.contents[82], " + "expected 146, is %d", + last_msg.msg.fileio_read_resp.contents[82]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[83] == 252, + "incorrect value for last_msg.msg.fileio_read_resp.contents[83], " + "expected 252, is %d", + last_msg.msg.fileio_read_resp.contents[83]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[84] == 4, + "incorrect value for last_msg.msg.fileio_read_resp.contents[84], " + "expected 4, is %d", + last_msg.msg.fileio_read_resp.contents[84]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[85] == 16, + "incorrect value for last_msg.msg.fileio_read_resp.contents[85], " + "expected 16, is %d", + last_msg.msg.fileio_read_resp.contents[85]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[86] == 54, + "incorrect value for last_msg.msg.fileio_read_resp.contents[86], " + "expected 54, is %d", + last_msg.msg.fileio_read_resp.contents[86]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[87] == 161, + "incorrect value for last_msg.msg.fileio_read_resp.contents[87], " + "expected 161, is %d", + last_msg.msg.fileio_read_resp.contents[87]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[88] == 60, + "incorrect value for last_msg.msg.fileio_read_resp.contents[88], " + "expected 60, is %d", + last_msg.msg.fileio_read_resp.contents[88]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[89] == 6, + "incorrect value for last_msg.msg.fileio_read_resp.contents[89], " + "expected 6, is %d", + last_msg.msg.fileio_read_resp.contents[89]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[90] == 13, + "incorrect value for last_msg.msg.fileio_read_resp.contents[90], " + "expected 13, is %d", + last_msg.msg.fileio_read_resp.contents[90]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[91] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[91], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[91]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[92] == 116, + "incorrect value for last_msg.msg.fileio_read_resp.contents[92], " + "expected 116, is %d", + last_msg.msg.fileio_read_resp.contents[92]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[93] == 182, + "incorrect value for last_msg.msg.fileio_read_resp.contents[93], " + "expected 182, is %d", + last_msg.msg.fileio_read_resp.contents[93]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[94] == 42, + "incorrect value for last_msg.msg.fileio_read_resp.contents[94], " + "expected 42, is %d", + last_msg.msg.fileio_read_resp.contents[94]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[95] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[95], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[95]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[96] == 213, + "incorrect value for last_msg.msg.fileio_read_resp.contents[96], " + "expected 213, is %d", + last_msg.msg.fileio_read_resp.contents[96]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[97] == 20, + "incorrect value for last_msg.msg.fileio_read_resp.contents[97], " + "expected 20, is %d", + last_msg.msg.fileio_read_resp.contents[97]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[98] == 217, + "incorrect value for last_msg.msg.fileio_read_resp.contents[98], " + "expected 217, is %d", + last_msg.msg.fileio_read_resp.contents[98]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[99] == 8, + "incorrect value for last_msg.msg.fileio_read_resp.contents[99], " + "expected 8, is %d", + last_msg.msg.fileio_read_resp.contents[99]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[100] == 142, + "incorrect value for last_msg.msg.fileio_read_resp.contents[100], " + "expected 142, is %d", + last_msg.msg.fileio_read_resp.contents[100]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[101] == 187, + "incorrect value for last_msg.msg.fileio_read_resp.contents[101], " + "expected 187, is %d", + last_msg.msg.fileio_read_resp.contents[101]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[102] == 238, + "incorrect value for last_msg.msg.fileio_read_resp.contents[102], " + "expected 238, is %d", + last_msg.msg.fileio_read_resp.contents[102]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[103] == 120, + "incorrect value for last_msg.msg.fileio_read_resp.contents[103], " + "expected 120, is %d", + last_msg.msg.fileio_read_resp.contents[103]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[104] == 184, + "incorrect value for last_msg.msg.fileio_read_resp.contents[104], " + "expected 184, is %d", + last_msg.msg.fileio_read_resp.contents[104]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[105] == 250, + "incorrect value for last_msg.msg.fileio_read_resp.contents[105], " + "expected 250, is %d", + last_msg.msg.fileio_read_resp.contents[105]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[106] == 31, + "incorrect value for last_msg.msg.fileio_read_resp.contents[106], " + "expected 31, is %d", + last_msg.msg.fileio_read_resp.contents[106]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[107] == 151, + "incorrect value for last_msg.msg.fileio_read_resp.contents[107], " + "expected 151, is %d", + last_msg.msg.fileio_read_resp.contents[107]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[108] == 37, + "incorrect value for last_msg.msg.fileio_read_resp.contents[108], " + "expected 37, is %d", + last_msg.msg.fileio_read_resp.contents[108]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[109] == 51, + "incorrect value for last_msg.msg.fileio_read_resp.contents[109], " + "expected 51, is %d", + last_msg.msg.fileio_read_resp.contents[109]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[110] == 177, + "incorrect value for last_msg.msg.fileio_read_resp.contents[110], " + "expected 177, is %d", + last_msg.msg.fileio_read_resp.contents[110]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[111] == 130, + "incorrect value for last_msg.msg.fileio_read_resp.contents[111], " + "expected 130, is %d", + last_msg.msg.fileio_read_resp.contents[111]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[112] == 190, + "incorrect value for last_msg.msg.fileio_read_resp.contents[112], " + "expected 190, is %d", + last_msg.msg.fileio_read_resp.contents[112]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[113] == 155, + "incorrect value for last_msg.msg.fileio_read_resp.contents[113], " + "expected 155, is %d", + last_msg.msg.fileio_read_resp.contents[113]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[114] == 71, + "incorrect value for last_msg.msg.fileio_read_resp.contents[114], " + "expected 71, is %d", + last_msg.msg.fileio_read_resp.contents[114]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[115] == 68, + "incorrect value for last_msg.msg.fileio_read_resp.contents[115], " + "expected 68, is %d", + last_msg.msg.fileio_read_resp.contents[115]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[116] == 56, + "incorrect value for last_msg.msg.fileio_read_resp.contents[116], " + "expected 56, is %d", + last_msg.msg.fileio_read_resp.contents[116]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[117] == 238, + "incorrect value for last_msg.msg.fileio_read_resp.contents[117], " + "expected 238, is %d", + last_msg.msg.fileio_read_resp.contents[117]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[118] == 92, + "incorrect value for last_msg.msg.fileio_read_resp.contents[118], " + "expected 92, is %d", + last_msg.msg.fileio_read_resp.contents[118]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[119] == 130, + "incorrect value for last_msg.msg.fileio_read_resp.contents[119], " + "expected 130, is %d", + last_msg.msg.fileio_read_resp.contents[119]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[120] == 37, + "incorrect value for last_msg.msg.fileio_read_resp.contents[120], " + "expected 37, is %d", + last_msg.msg.fileio_read_resp.contents[120]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[121] == 137, + "incorrect value for last_msg.msg.fileio_read_resp.contents[121], " + "expected 137, is %d", + last_msg.msg.fileio_read_resp.contents[121]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[122] == 146, + "incorrect value for last_msg.msg.fileio_read_resp.contents[122], " + "expected 146, is %d", + last_msg.msg.fileio_read_resp.contents[122]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[123] == 246, + "incorrect value for last_msg.msg.fileio_read_resp.contents[123], " + "expected 246, is %d", + last_msg.msg.fileio_read_resp.contents[123]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[124] == 114, + "incorrect value for last_msg.msg.fileio_read_resp.contents[124], " + "expected 114, is %d", + last_msg.msg.fileio_read_resp.contents[124]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[125] == 116, + "incorrect value for last_msg.msg.fileio_read_resp.contents[125], " + "expected 116, is %d", + last_msg.msg.fileio_read_resp.contents[125]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[126] == 138, + "incorrect value for last_msg.msg.fileio_read_resp.contents[126], " + "expected 138, is %d", + last_msg.msg.fileio_read_resp.contents[126]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[127] == 165, + "incorrect value for last_msg.msg.fileio_read_resp.contents[127], " + "expected 165, is %d", + last_msg.msg.fileio_read_resp.contents[127]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[128] == 217, + "incorrect value for last_msg.msg.fileio_read_resp.contents[128], " + "expected 217, is %d", + last_msg.msg.fileio_read_resp.contents[128]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[129] == 79, + "incorrect value for last_msg.msg.fileio_read_resp.contents[129], " + "expected 79, is %d", + last_msg.msg.fileio_read_resp.contents[129]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[130] == 10, + "incorrect value for last_msg.msg.fileio_read_resp.contents[130], " + "expected 10, is %d", + last_msg.msg.fileio_read_resp.contents[130]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[131] == 189, + "incorrect value for last_msg.msg.fileio_read_resp.contents[131], " + "expected 189, is %d", + last_msg.msg.fileio_read_resp.contents[131]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[132] == 128, + "incorrect value for last_msg.msg.fileio_read_resp.contents[132], " + "expected 128, is %d", + last_msg.msg.fileio_read_resp.contents[132]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[133] == 189, + "incorrect value for last_msg.msg.fileio_read_resp.contents[133], " + "expected 189, is %d", + last_msg.msg.fileio_read_resp.contents[133]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[134] == 2, + "incorrect value for last_msg.msg.fileio_read_resp.contents[134], " + "expected 2, is %d", + last_msg.msg.fileio_read_resp.contents[134]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[135] == 240, + "incorrect value for last_msg.msg.fileio_read_resp.contents[135], " + "expected 240, is %d", + last_msg.msg.fileio_read_resp.contents[135]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[136] == 92, + "incorrect value for last_msg.msg.fileio_read_resp.contents[136], " + "expected 92, is %d", + last_msg.msg.fileio_read_resp.contents[136]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[137] == 28, + "incorrect value for last_msg.msg.fileio_read_resp.contents[137], " + "expected 28, is %d", + last_msg.msg.fileio_read_resp.contents[137]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[138] == 126, + "incorrect value for last_msg.msg.fileio_read_resp.contents[138], " + "expected 126, is %d", + last_msg.msg.fileio_read_resp.contents[138]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[139] == 105, + "incorrect value for last_msg.msg.fileio_read_resp.contents[139], " + "expected 105, is %d", + last_msg.msg.fileio_read_resp.contents[139]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[140] == 236, + "incorrect value for last_msg.msg.fileio_read_resp.contents[140], " + "expected 236, is %d", + last_msg.msg.fileio_read_resp.contents[140]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[141] == 228, + "incorrect value for last_msg.msg.fileio_read_resp.contents[141], " + "expected 228, is %d", + last_msg.msg.fileio_read_resp.contents[141]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[142] == 194, + "incorrect value for last_msg.msg.fileio_read_resp.contents[142], " + "expected 194, is %d", + last_msg.msg.fileio_read_resp.contents[142]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[143] == 0, + "incorrect value for last_msg.msg.fileio_read_resp.contents[143], " + "expected 0, is %d", + last_msg.msg.fileio_read_resp.contents[143]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[144] == 51, + "incorrect value for last_msg.msg.fileio_read_resp.contents[144], " + "expected 51, is %d", + last_msg.msg.fileio_read_resp.contents[144]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[145] == 61, + "incorrect value for last_msg.msg.fileio_read_resp.contents[145], " + "expected 61, is %d", + last_msg.msg.fileio_read_resp.contents[145]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[146] == 74, + "incorrect value for last_msg.msg.fileio_read_resp.contents[146], " + "expected 74, is %d", + last_msg.msg.fileio_read_resp.contents[146]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[147] == 41, + "incorrect value for last_msg.msg.fileio_read_resp.contents[147], " + "expected 41, is %d", + last_msg.msg.fileio_read_resp.contents[147]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[148] == 10, + "incorrect value for last_msg.msg.fileio_read_resp.contents[148], " + "expected 10, is %d", + last_msg.msg.fileio_read_resp.contents[148]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[149] == 239, + "incorrect value for last_msg.msg.fileio_read_resp.contents[149], " + "expected 239, is %d", + last_msg.msg.fileio_read_resp.contents[149]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[150] == 133, + "incorrect value for last_msg.msg.fileio_read_resp.contents[150], " + "expected 133, is %d", + last_msg.msg.fileio_read_resp.contents[150]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[151] == 106, + "incorrect value for last_msg.msg.fileio_read_resp.contents[151], " + "expected 106, is %d", + last_msg.msg.fileio_read_resp.contents[151]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[152] == 190, + "incorrect value for last_msg.msg.fileio_read_resp.contents[152], " + "expected 190, is %d", + last_msg.msg.fileio_read_resp.contents[152]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[153] == 30, + "incorrect value for last_msg.msg.fileio_read_resp.contents[153], " + "expected 30, is %d", + last_msg.msg.fileio_read_resp.contents[153]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[154] == 27, + "incorrect value for last_msg.msg.fileio_read_resp.contents[154], " + "expected 27, is %d", + last_msg.msg.fileio_read_resp.contents[154]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[155] == 3, + "incorrect value for last_msg.msg.fileio_read_resp.contents[155], " + "expected 3, is %d", + last_msg.msg.fileio_read_resp.contents[155]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[156] == 240, + "incorrect value for last_msg.msg.fileio_read_resp.contents[156], " + "expected 240, is %d", + last_msg.msg.fileio_read_resp.contents[156]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[157] == 205, + "incorrect value for last_msg.msg.fileio_read_resp.contents[157], " + "expected 205, is %d", + last_msg.msg.fileio_read_resp.contents[157]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[158] == 253, + "incorrect value for last_msg.msg.fileio_read_resp.contents[158], " + "expected 253, is %d", + last_msg.msg.fileio_read_resp.contents[158]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[159] == 113, + "incorrect value for last_msg.msg.fileio_read_resp.contents[159], " + "expected 113, is %d", + last_msg.msg.fileio_read_resp.contents[159]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[160] == 25, + "incorrect value for last_msg.msg.fileio_read_resp.contents[160], " + "expected 25, is %d", + last_msg.msg.fileio_read_resp.contents[160]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[161] == 28, + "incorrect value for last_msg.msg.fileio_read_resp.contents[161], " + "expected 28, is %d", + last_msg.msg.fileio_read_resp.contents[161]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[162] == 187, + "incorrect value for last_msg.msg.fileio_read_resp.contents[162], " + "expected 187, is %d", + last_msg.msg.fileio_read_resp.contents[162]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[163] == 81, + "incorrect value for last_msg.msg.fileio_read_resp.contents[163], " + "expected 81, is %d", + last_msg.msg.fileio_read_resp.contents[163]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[164] == 101, + "incorrect value for last_msg.msg.fileio_read_resp.contents[164], " + "expected 101, is %d", + last_msg.msg.fileio_read_resp.contents[164]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[165] == 216, + "incorrect value for last_msg.msg.fileio_read_resp.contents[165], " + "expected 216, is %d", + last_msg.msg.fileio_read_resp.contents[165]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[166] == 121, + "incorrect value for last_msg.msg.fileio_read_resp.contents[166], " + "expected 121, is %d", + last_msg.msg.fileio_read_resp.contents[166]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[167] == 41, + "incorrect value for last_msg.msg.fileio_read_resp.contents[167], " + "expected 41, is %d", + last_msg.msg.fileio_read_resp.contents[167]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[168] == 179, + "incorrect value for last_msg.msg.fileio_read_resp.contents[168], " + "expected 179, is %d", + last_msg.msg.fileio_read_resp.contents[168]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[169] == 120, + "incorrect value for last_msg.msg.fileio_read_resp.contents[169], " + "expected 120, is %d", + last_msg.msg.fileio_read_resp.contents[169]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[170] == 152, + "incorrect value for last_msg.msg.fileio_read_resp.contents[170], " + "expected 152, is %d", + last_msg.msg.fileio_read_resp.contents[170]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[171] == 18, + "incorrect value for last_msg.msg.fileio_read_resp.contents[171], " + "expected 18, is %d", + last_msg.msg.fileio_read_resp.contents[171]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[172] == 116, + "incorrect value for last_msg.msg.fileio_read_resp.contents[172], " + "expected 116, is %d", + last_msg.msg.fileio_read_resp.contents[172]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[173] == 53, + "incorrect value for last_msg.msg.fileio_read_resp.contents[173], " + "expected 53, is %d", + last_msg.msg.fileio_read_resp.contents[173]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[174] == 212, + "incorrect value for last_msg.msg.fileio_read_resp.contents[174], " + "expected 212, is %d", + last_msg.msg.fileio_read_resp.contents[174]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[175] == 100, + "incorrect value for last_msg.msg.fileio_read_resp.contents[175], " + "expected 100, is %d", + last_msg.msg.fileio_read_resp.contents[175]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[176] == 2, + "incorrect value for last_msg.msg.fileio_read_resp.contents[176], " + "expected 2, is %d", + last_msg.msg.fileio_read_resp.contents[176]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[177] == 114, + "incorrect value for last_msg.msg.fileio_read_resp.contents[177], " + "expected 114, is %d", + last_msg.msg.fileio_read_resp.contents[177]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[178] == 198, + "incorrect value for last_msg.msg.fileio_read_resp.contents[178], " + "expected 198, is %d", + last_msg.msg.fileio_read_resp.contents[178]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[179] == 200, + "incorrect value for last_msg.msg.fileio_read_resp.contents[179], " + "expected 200, is %d", + last_msg.msg.fileio_read_resp.contents[179]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[180] == 10, + "incorrect value for last_msg.msg.fileio_read_resp.contents[180], " + "expected 10, is %d", + last_msg.msg.fileio_read_resp.contents[180]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[181] == 147, + "incorrect value for last_msg.msg.fileio_read_resp.contents[181], " + "expected 147, is %d", + last_msg.msg.fileio_read_resp.contents[181]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[182] == 25, + "incorrect value for last_msg.msg.fileio_read_resp.contents[182], " + "expected 25, is %d", + last_msg.msg.fileio_read_resp.contents[182]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[183] == 33, + "incorrect value for last_msg.msg.fileio_read_resp.contents[183], " + "expected 33, is %d", + last_msg.msg.fileio_read_resp.contents[183]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[184] == 115, + "incorrect value for last_msg.msg.fileio_read_resp.contents[184], " + "expected 115, is %d", + last_msg.msg.fileio_read_resp.contents[184]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[185] == 208, + "incorrect value for last_msg.msg.fileio_read_resp.contents[185], " + "expected 208, is %d", + last_msg.msg.fileio_read_resp.contents[185]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[186] == 113, + "incorrect value for last_msg.msg.fileio_read_resp.contents[186], " + "expected 113, is %d", + last_msg.msg.fileio_read_resp.contents[186]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[187] == 60, + "incorrect value for last_msg.msg.fileio_read_resp.contents[187], " + "expected 60, is %d", + last_msg.msg.fileio_read_resp.contents[187]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[188] == 179, + "incorrect value for last_msg.msg.fileio_read_resp.contents[188], " + "expected 179, is %d", + last_msg.msg.fileio_read_resp.contents[188]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[189] == 183, + "incorrect value for last_msg.msg.fileio_read_resp.contents[189], " + "expected 183, is %d", + last_msg.msg.fileio_read_resp.contents[189]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[190] == 0, + "incorrect value for last_msg.msg.fileio_read_resp.contents[190], " + "expected 0, is %d", + last_msg.msg.fileio_read_resp.contents[190]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[191] == 41, + "incorrect value for last_msg.msg.fileio_read_resp.contents[191], " + "expected 41, is %d", + last_msg.msg.fileio_read_resp.contents[191]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[192] == 217, + "incorrect value for last_msg.msg.fileio_read_resp.contents[192], " + "expected 217, is %d", + last_msg.msg.fileio_read_resp.contents[192]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[193] == 206, + "incorrect value for last_msg.msg.fileio_read_resp.contents[193], " + "expected 206, is %d", + last_msg.msg.fileio_read_resp.contents[193]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[194] == 255, + "incorrect value for last_msg.msg.fileio_read_resp.contents[194], " + "expected 255, is %d", + last_msg.msg.fileio_read_resp.contents[194]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[195] == 211, + "incorrect value for last_msg.msg.fileio_read_resp.contents[195], " + "expected 211, is %d", + last_msg.msg.fileio_read_resp.contents[195]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[196] == 225, + "incorrect value for last_msg.msg.fileio_read_resp.contents[196], " + "expected 225, is %d", + last_msg.msg.fileio_read_resp.contents[196]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[197] == 142, + "incorrect value for last_msg.msg.fileio_read_resp.contents[197], " + "expected 142, is %d", + last_msg.msg.fileio_read_resp.contents[197]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[198] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[198], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[198]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[199] == 133, + "incorrect value for last_msg.msg.fileio_read_resp.contents[199], " + "expected 133, is %d", + last_msg.msg.fileio_read_resp.contents[199]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[200] == 81, + "incorrect value for last_msg.msg.fileio_read_resp.contents[200], " + "expected 81, is %d", + last_msg.msg.fileio_read_resp.contents[200]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[201] == 15, + "incorrect value for last_msg.msg.fileio_read_resp.contents[201], " + "expected 15, is %d", + last_msg.msg.fileio_read_resp.contents[201]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[202] == 248, + "incorrect value for last_msg.msg.fileio_read_resp.contents[202], " + "expected 248, is %d", + last_msg.msg.fileio_read_resp.contents[202]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[203] == 193, + "incorrect value for last_msg.msg.fileio_read_resp.contents[203], " + "expected 193, is %d", + last_msg.msg.fileio_read_resp.contents[203]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[204] == 66, + "incorrect value for last_msg.msg.fileio_read_resp.contents[204], " + "expected 66, is %d", + last_msg.msg.fileio_read_resp.contents[204]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[205] == 191, + "incorrect value for last_msg.msg.fileio_read_resp.contents[205], " + "expected 191, is %d", + last_msg.msg.fileio_read_resp.contents[205]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[206] == 244, + "incorrect value for last_msg.msg.fileio_read_resp.contents[206], " + "expected 244, is %d", + last_msg.msg.fileio_read_resp.contents[206]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[207] == 221, + "incorrect value for last_msg.msg.fileio_read_resp.contents[207], " + "expected 221, is %d", + last_msg.msg.fileio_read_resp.contents[207]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[208] == 248, + "incorrect value for last_msg.msg.fileio_read_resp.contents[208], " + "expected 248, is %d", + last_msg.msg.fileio_read_resp.contents[208]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[209] == 199, + "incorrect value for last_msg.msg.fileio_read_resp.contents[209], " + "expected 199, is %d", + last_msg.msg.fileio_read_resp.contents[209]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[210] == 241, + "incorrect value for last_msg.msg.fileio_read_resp.contents[210], " + "expected 241, is %d", + last_msg.msg.fileio_read_resp.contents[210]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[211] == 112, + "incorrect value for last_msg.msg.fileio_read_resp.contents[211], " + "expected 112, is %d", + last_msg.msg.fileio_read_resp.contents[211]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[212] == 51, + "incorrect value for last_msg.msg.fileio_read_resp.contents[212], " + "expected 51, is %d", + last_msg.msg.fileio_read_resp.contents[212]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[213] == 1, + "incorrect value for last_msg.msg.fileio_read_resp.contents[213], " + "expected 1, is %d", + last_msg.msg.fileio_read_resp.contents[213]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[214] == 180, + "incorrect value for last_msg.msg.fileio_read_resp.contents[214], " + "expected 180, is %d", + last_msg.msg.fileio_read_resp.contents[214]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[215] == 180, + "incorrect value for last_msg.msg.fileio_read_resp.contents[215], " + "expected 180, is %d", + last_msg.msg.fileio_read_resp.contents[215]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[216] == 125, + "incorrect value for last_msg.msg.fileio_read_resp.contents[216], " + "expected 125, is %d", + last_msg.msg.fileio_read_resp.contents[216]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[217] == 97, + "incorrect value for last_msg.msg.fileio_read_resp.contents[217], " + "expected 97, is %d", + last_msg.msg.fileio_read_resp.contents[217]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[218] == 145, + "incorrect value for last_msg.msg.fileio_read_resp.contents[218], " + "expected 145, is %d", + last_msg.msg.fileio_read_resp.contents[218]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[219] == 25, + "incorrect value for last_msg.msg.fileio_read_resp.contents[219], " + "expected 25, is %d", + last_msg.msg.fileio_read_resp.contents[219]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[220] == 72, + "incorrect value for last_msg.msg.fileio_read_resp.contents[220], " + "expected 72, is %d", + last_msg.msg.fileio_read_resp.contents[220]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[221] == 210, + "incorrect value for last_msg.msg.fileio_read_resp.contents[221], " + "expected 210, is %d", + last_msg.msg.fileio_read_resp.contents[221]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[222] == 215, + "incorrect value for last_msg.msg.fileio_read_resp.contents[222], " + "expected 215, is %d", + last_msg.msg.fileio_read_resp.contents[222]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[223] == 208, + "incorrect value for last_msg.msg.fileio_read_resp.contents[223], " + "expected 208, is %d", + last_msg.msg.fileio_read_resp.contents[223]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[224] == 15, + "incorrect value for last_msg.msg.fileio_read_resp.contents[224], " + "expected 15, is %d", + last_msg.msg.fileio_read_resp.contents[224]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[225] == 126, + "incorrect value for last_msg.msg.fileio_read_resp.contents[225], " + "expected 126, is %d", + last_msg.msg.fileio_read_resp.contents[225]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[226] == 56, + "incorrect value for last_msg.msg.fileio_read_resp.contents[226], " + "expected 56, is %d", + last_msg.msg.fileio_read_resp.contents[226]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[227] == 38, + "incorrect value for last_msg.msg.fileio_read_resp.contents[227], " + "expected 38, is %d", + last_msg.msg.fileio_read_resp.contents[227]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[228] == 65, + "incorrect value for last_msg.msg.fileio_read_resp.contents[228], " + "expected 65, is %d", + last_msg.msg.fileio_read_resp.contents[228]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[229] == 4, + "incorrect value for last_msg.msg.fileio_read_resp.contents[229], " + "expected 4, is %d", + last_msg.msg.fileio_read_resp.contents[229]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[230] == 64, + "incorrect value for last_msg.msg.fileio_read_resp.contents[230], " + "expected 64, is %d", + last_msg.msg.fileio_read_resp.contents[230]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[231] == 19, + "incorrect value for last_msg.msg.fileio_read_resp.contents[231], " + "expected 19, is %d", + last_msg.msg.fileio_read_resp.contents[231]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[232] == 74, + "incorrect value for last_msg.msg.fileio_read_resp.contents[232], " + "expected 74, is %d", + last_msg.msg.fileio_read_resp.contents[232]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[233] == 223, + "incorrect value for last_msg.msg.fileio_read_resp.contents[233], " + "expected 223, is %d", + last_msg.msg.fileio_read_resp.contents[233]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[234] == 111, + "incorrect value for last_msg.msg.fileio_read_resp.contents[234], " + "expected 111, is %d", + last_msg.msg.fileio_read_resp.contents[234]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[235] == 109, + "incorrect value for last_msg.msg.fileio_read_resp.contents[235], " + "expected 109, is %d", + last_msg.msg.fileio_read_resp.contents[235]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[236] == 52, + "incorrect value for last_msg.msg.fileio_read_resp.contents[236], " + "expected 52, is %d", + last_msg.msg.fileio_read_resp.contents[236]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[237] == 43, + "incorrect value for last_msg.msg.fileio_read_resp.contents[237], " + "expected 43, is %d", + last_msg.msg.fileio_read_resp.contents[237]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[238] == 167, + "incorrect value for last_msg.msg.fileio_read_resp.contents[238], " + "expected 167, is %d", + last_msg.msg.fileio_read_resp.contents[238]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[239] == 186, + "incorrect value for last_msg.msg.fileio_read_resp.contents[239], " + "expected 186, is %d", + last_msg.msg.fileio_read_resp.contents[239]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[240] == 202, + "incorrect value for last_msg.msg.fileio_read_resp.contents[240], " + "expected 202, is %d", + last_msg.msg.fileio_read_resp.contents[240]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[241] == 111, + "incorrect value for last_msg.msg.fileio_read_resp.contents[241], " + "expected 111, is %d", + last_msg.msg.fileio_read_resp.contents[241]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[242] == 11, + "incorrect value for last_msg.msg.fileio_read_resp.contents[242], " + "expected 11, is %d", + last_msg.msg.fileio_read_resp.contents[242]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[243] == 91, + "incorrect value for last_msg.msg.fileio_read_resp.contents[243], " + "expected 91, is %d", + last_msg.msg.fileio_read_resp.contents[243]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[244] == 21, + "incorrect value for last_msg.msg.fileio_read_resp.contents[244], " + "expected 21, is %d", + last_msg.msg.fileio_read_resp.contents[244]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[245] == 236, + "incorrect value for last_msg.msg.fileio_read_resp.contents[245], " + "expected 236, is %d", + last_msg.msg.fileio_read_resp.contents[245]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[246] == 234, + "incorrect value for last_msg.msg.fileio_read_resp.contents[246], " + "expected 234, is %d", + last_msg.msg.fileio_read_resp.contents[246]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[247] == 196, + "incorrect value for last_msg.msg.fileio_read_resp.contents[247], " + "expected 196, is %d", + last_msg.msg.fileio_read_resp.contents[247]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[248] == 36, + "incorrect value for last_msg.msg.fileio_read_resp.contents[248], " + "expected 36, is %d", + last_msg.msg.fileio_read_resp.contents[248]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[249] == 171, + "incorrect value for last_msg.msg.fileio_read_resp.contents[249], " + "expected 171, is %d", + last_msg.msg.fileio_read_resp.contents[249]); + ck_assert_msg( + last_msg.msg.fileio_read_resp.contents[250] == 147, + "incorrect value for last_msg.msg.fileio_read_resp.contents[250], " + "expected 147, is %d", + last_msg.msg.fileio_read_resp.contents[250]); + + ck_assert_msg( + last_msg.msg.fileio_read_resp.n_contents == 251, + "incorrect value for last_msg.msg.fileio_read_resp.n_contents, " + "expected 251, is %d", + last_msg.msg.fileio_read_resp.n_contents); + + ck_assert_msg(last_msg.msg.fileio_read_resp.sequence == 259241795, + "incorrect value for last_msg.msg.fileio_read_resp.sequence, " + "expected 259241795, is %d", + last_msg.msg.fileio_read_resp.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioReadResp"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_file_io_MsgFileioReadResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_file_io_MsgFileioRemove.c b/c/test/auto_check_sbp_file_io_MsgFileioRemove.c new file mode 100644 index 0000000000..d5101211ee --- /dev/null +++ b/c/test/auto_check_sbp_file_io_MsgFileioRemove.c @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_file_io_MsgFileioRemove) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xac, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 102, 105, 108, 101, 0, 46, 243, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_fileio_remove_filename_set(&test_msg.fileio_remove, + "/path/to/file", false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("/path/to/file"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_fileio_remove_filename_encoded_len( + &test_msg.fileio_remove) == 14, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgFileioRemove, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFileioRemove, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_fileio_remove_filename_encoded_len( + &last_msg.msg.fileio_remove) == 14, + "Invalid encoded len"); + ck_assert_msg( + strcmp(sbp_msg_fileio_remove_filename_get(&last_msg.msg.fileio_remove), + "/path/to/file") == 0, + "String not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_file_io_MsgFileioRemove_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_file_io_MsgFileioRemove"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_file_io_MsgFileioRemove"); + tcase_add_test(tc_acq, test_auto_check_sbp_file_io_MsgFileioRemove); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgFlashDone.c b/c/test/auto_check_sbp_flash_MsgFlashDone.c new file mode 100644 index 0000000000..2d0c9d4572 --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgFlashDone.c @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgFlashDone) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 224, 0, 195, 4, 1, 82, 6, 54, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.flash_done.response = 82; + + sbp_message_send(&sbp_state, SbpMsgFlashDone, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFlashDone, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.flash_done.response == 82, + "incorrect value for last_msg.msg.flash_done.response, " + "expected 82, is %d", + last_msg.msg.flash_done.response); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgFlashDone_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgFlashDone"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgFlashDone"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgFlashDone); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgFlashErase.c b/c/test/auto_check_sbp_flash_MsgFlashErase.c new file mode 100644 index 0000000000..e742b4b79a --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgFlashErase.c @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgFlashErase) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.flash_erase.sector_num = 2222371310; + + test_msg.flash_erase.target = 74; + + sbp_message_send(&sbp_state, SbpMsgFlashErase, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFlashErase, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.flash_erase.sector_num == 2222371310, + "incorrect value for last_msg.msg.flash_erase.sector_num, " + "expected 2222371310, is %d", + last_msg.msg.flash_erase.sector_num); + + ck_assert_msg(last_msg.msg.flash_erase.target == 74, + "incorrect value for last_msg.msg.flash_erase.target, " + "expected 74, is %d", + last_msg.msg.flash_erase.target); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgFlashErase_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgFlashErase"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgFlashErase"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgFlashErase); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgFlashProgram.c b/c/test/auto_check_sbp_flash_MsgFlashProgram.c new file mode 100644 index 0000000000..3c356bf435 --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgFlashProgram.c @@ -0,0 +1,1695 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgFlashProgram) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, + 106, 144, 29, 141, 255, 3, 16, 192, 237, 172, 254, 213, 4, 220, + 98, 34, 222, 230, 214, 6, 217, 172, 122, 46, 13, 38, 240, 236, + 60, 121, 47, 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, + 21, 214, 57, 245, 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, + 98, 39, 70, 232, 133, 25, 10, 134, 129, 69, 228, 134, 9, 88, + 183, 133, 171, 255, 166, 100, 152, 231, 92, 9, 196, 106, 246, 29, + 145, 156, 151, 32, 67, 188, 63, 233, 142, 174, 139, 154, 127, 35, + 60, 56, 187, 121, 103, 135, 152, 182, 88, 160, 255, 227, 240, 54, + 100, 91, 31, 141, 102, 130, 254, 54, 227, 229, 62, 53, 225, 143, + 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, 57, 87, 130, 178, + 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, 235, 213, 186, + 159, 221, 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, 13, 50, + 71, 73, 193, 201, 250, 172, 193, 13, 20, 238, 130, 243, 68, 4, + 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, 92, 160, + 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, + 239, 168, 32, 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, + 217, 151, 251, 83, 20, 113, 37, 151, 34, 37, 71, 95, 105, 235, + 144, 164, 83, 197, 254, 183, 223, 91, 19, 45, 227, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.flash_program.addr_len = 250; + + test_msg.flash_program.addr_start[0] = 87; + + test_msg.flash_program.addr_start[1] = 52; + + test_msg.flash_program.addr_start[2] = 244; + + test_msg.flash_program.data[0] = 176; + + test_msg.flash_program.data[1] = 222; + + test_msg.flash_program.data[2] = 235; + + test_msg.flash_program.data[3] = 106; + + test_msg.flash_program.data[4] = 144; + + test_msg.flash_program.data[5] = 29; + + test_msg.flash_program.data[6] = 141; + + test_msg.flash_program.data[7] = 255; + + test_msg.flash_program.data[8] = 3; + + test_msg.flash_program.data[9] = 16; + + test_msg.flash_program.data[10] = 192; + + test_msg.flash_program.data[11] = 237; + + test_msg.flash_program.data[12] = 172; + + test_msg.flash_program.data[13] = 254; + + test_msg.flash_program.data[14] = 213; + + test_msg.flash_program.data[15] = 4; + + test_msg.flash_program.data[16] = 220; + + test_msg.flash_program.data[17] = 98; + + test_msg.flash_program.data[18] = 34; + + test_msg.flash_program.data[19] = 222; + + test_msg.flash_program.data[20] = 230; + + test_msg.flash_program.data[21] = 214; + + test_msg.flash_program.data[22] = 6; + + test_msg.flash_program.data[23] = 217; + + test_msg.flash_program.data[24] = 172; + + test_msg.flash_program.data[25] = 122; + + test_msg.flash_program.data[26] = 46; + + test_msg.flash_program.data[27] = 13; + + test_msg.flash_program.data[28] = 38; + + test_msg.flash_program.data[29] = 240; + + test_msg.flash_program.data[30] = 236; + + test_msg.flash_program.data[31] = 60; + + test_msg.flash_program.data[32] = 121; + + test_msg.flash_program.data[33] = 47; + + test_msg.flash_program.data[34] = 252; + + test_msg.flash_program.data[35] = 163; + + test_msg.flash_program.data[36] = 141; + + test_msg.flash_program.data[37] = 222; + + test_msg.flash_program.data[38] = 29; + + test_msg.flash_program.data[39] = 168; + + test_msg.flash_program.data[40] = 214; + + test_msg.flash_program.data[41] = 118; + + test_msg.flash_program.data[42] = 55; + + test_msg.flash_program.data[43] = 201; + + test_msg.flash_program.data[44] = 233; + + test_msg.flash_program.data[45] = 21; + + test_msg.flash_program.data[46] = 214; + + test_msg.flash_program.data[47] = 57; + + test_msg.flash_program.data[48] = 245; + + test_msg.flash_program.data[49] = 246; + + test_msg.flash_program.data[50] = 19; + + test_msg.flash_program.data[51] = 3; + + test_msg.flash_program.data[52] = 121; + + test_msg.flash_program.data[53] = 49; + + test_msg.flash_program.data[54] = 231; + + test_msg.flash_program.data[55] = 37; + + test_msg.flash_program.data[56] = 186; + + test_msg.flash_program.data[57] = 58; + + test_msg.flash_program.data[58] = 238; + + test_msg.flash_program.data[59] = 98; + + test_msg.flash_program.data[60] = 39; + + test_msg.flash_program.data[61] = 70; + + test_msg.flash_program.data[62] = 232; + + test_msg.flash_program.data[63] = 133; + + test_msg.flash_program.data[64] = 25; + + test_msg.flash_program.data[65] = 10; + + test_msg.flash_program.data[66] = 134; + + test_msg.flash_program.data[67] = 129; + + test_msg.flash_program.data[68] = 69; + + test_msg.flash_program.data[69] = 228; + + test_msg.flash_program.data[70] = 134; + + test_msg.flash_program.data[71] = 9; + + test_msg.flash_program.data[72] = 88; + + test_msg.flash_program.data[73] = 183; + + test_msg.flash_program.data[74] = 133; + + test_msg.flash_program.data[75] = 171; + + test_msg.flash_program.data[76] = 255; + + test_msg.flash_program.data[77] = 166; + + test_msg.flash_program.data[78] = 100; + + test_msg.flash_program.data[79] = 152; + + test_msg.flash_program.data[80] = 231; + + test_msg.flash_program.data[81] = 92; + + test_msg.flash_program.data[82] = 9; + + test_msg.flash_program.data[83] = 196; + + test_msg.flash_program.data[84] = 106; + + test_msg.flash_program.data[85] = 246; + + test_msg.flash_program.data[86] = 29; + + test_msg.flash_program.data[87] = 145; + + test_msg.flash_program.data[88] = 156; + + test_msg.flash_program.data[89] = 151; + + test_msg.flash_program.data[90] = 32; + + test_msg.flash_program.data[91] = 67; + + test_msg.flash_program.data[92] = 188; + + test_msg.flash_program.data[93] = 63; + + test_msg.flash_program.data[94] = 233; + + test_msg.flash_program.data[95] = 142; + + test_msg.flash_program.data[96] = 174; + + test_msg.flash_program.data[97] = 139; + + test_msg.flash_program.data[98] = 154; + + test_msg.flash_program.data[99] = 127; + + test_msg.flash_program.data[100] = 35; + + test_msg.flash_program.data[101] = 60; + + test_msg.flash_program.data[102] = 56; + + test_msg.flash_program.data[103] = 187; + + test_msg.flash_program.data[104] = 121; + + test_msg.flash_program.data[105] = 103; + + test_msg.flash_program.data[106] = 135; + + test_msg.flash_program.data[107] = 152; + + test_msg.flash_program.data[108] = 182; + + test_msg.flash_program.data[109] = 88; + + test_msg.flash_program.data[110] = 160; + + test_msg.flash_program.data[111] = 255; + + test_msg.flash_program.data[112] = 227; + + test_msg.flash_program.data[113] = 240; + + test_msg.flash_program.data[114] = 54; + + test_msg.flash_program.data[115] = 100; + + test_msg.flash_program.data[116] = 91; + + test_msg.flash_program.data[117] = 31; + + test_msg.flash_program.data[118] = 141; + + test_msg.flash_program.data[119] = 102; + + test_msg.flash_program.data[120] = 130; + + test_msg.flash_program.data[121] = 254; + + test_msg.flash_program.data[122] = 54; + + test_msg.flash_program.data[123] = 227; + + test_msg.flash_program.data[124] = 229; + + test_msg.flash_program.data[125] = 62; + + test_msg.flash_program.data[126] = 53; + + test_msg.flash_program.data[127] = 225; + + test_msg.flash_program.data[128] = 143; + + test_msg.flash_program.data[129] = 88; + + test_msg.flash_program.data[130] = 139; + + test_msg.flash_program.data[131] = 126; + + test_msg.flash_program.data[132] = 235; + + test_msg.flash_program.data[133] = 235; + + test_msg.flash_program.data[134] = 35; + + test_msg.flash_program.data[135] = 54; + + test_msg.flash_program.data[136] = 134; + + test_msg.flash_program.data[137] = 163; + + test_msg.flash_program.data[138] = 92; + + test_msg.flash_program.data[139] = 57; + + test_msg.flash_program.data[140] = 87; + + test_msg.flash_program.data[141] = 130; + + test_msg.flash_program.data[142] = 178; + + test_msg.flash_program.data[143] = 22; + + test_msg.flash_program.data[144] = 158; + + test_msg.flash_program.data[145] = 18; + + test_msg.flash_program.data[146] = 237; + + test_msg.flash_program.data[147] = 209; + + test_msg.flash_program.data[148] = 187; + + test_msg.flash_program.data[149] = 226; + + test_msg.flash_program.data[150] = 1; + + test_msg.flash_program.data[151] = 46; + + test_msg.flash_program.data[152] = 64; + + test_msg.flash_program.data[153] = 226; + + test_msg.flash_program.data[154] = 235; + + test_msg.flash_program.data[155] = 213; + + test_msg.flash_program.data[156] = 186; + + test_msg.flash_program.data[157] = 159; + + test_msg.flash_program.data[158] = 221; + + test_msg.flash_program.data[159] = 186; + + test_msg.flash_program.data[160] = 25; + + test_msg.flash_program.data[161] = 115; + + test_msg.flash_program.data[162] = 84; + + test_msg.flash_program.data[163] = 131; + + test_msg.flash_program.data[164] = 167; + + test_msg.flash_program.data[165] = 201; + + test_msg.flash_program.data[166] = 104; + + test_msg.flash_program.data[167] = 1; + + test_msg.flash_program.data[168] = 200; + + test_msg.flash_program.data[169] = 13; + + test_msg.flash_program.data[170] = 50; + + test_msg.flash_program.data[171] = 71; + + test_msg.flash_program.data[172] = 73; + + test_msg.flash_program.data[173] = 193; + + test_msg.flash_program.data[174] = 201; + + test_msg.flash_program.data[175] = 250; + + test_msg.flash_program.data[176] = 172; + + test_msg.flash_program.data[177] = 193; + + test_msg.flash_program.data[178] = 13; + + test_msg.flash_program.data[179] = 20; + + test_msg.flash_program.data[180] = 238; + + test_msg.flash_program.data[181] = 130; + + test_msg.flash_program.data[182] = 243; + + test_msg.flash_program.data[183] = 68; + + test_msg.flash_program.data[184] = 4; + + test_msg.flash_program.data[185] = 72; + + test_msg.flash_program.data[186] = 46; + + test_msg.flash_program.data[187] = 194; + + test_msg.flash_program.data[188] = 113; + + test_msg.flash_program.data[189] = 255; + + test_msg.flash_program.data[190] = 238; + + test_msg.flash_program.data[191] = 15; + + test_msg.flash_program.data[192] = 230; + + test_msg.flash_program.data[193] = 64; + + test_msg.flash_program.data[194] = 178; + + test_msg.flash_program.data[195] = 127; + + test_msg.flash_program.data[196] = 217; + + test_msg.flash_program.data[197] = 92; + + test_msg.flash_program.data[198] = 160; + + test_msg.flash_program.data[199] = 201; + + test_msg.flash_program.data[200] = 118; + + test_msg.flash_program.data[201] = 163; + + test_msg.flash_program.data[202] = 144; + + test_msg.flash_program.data[203] = 58; + + test_msg.flash_program.data[204] = 28; + + test_msg.flash_program.data[205] = 174; + + test_msg.flash_program.data[206] = 65; + + test_msg.flash_program.data[207] = 73; + + test_msg.flash_program.data[208] = 45; + + test_msg.flash_program.data[209] = 123; + + test_msg.flash_program.data[210] = 118; + + test_msg.flash_program.data[211] = 83; + + test_msg.flash_program.data[212] = 107; + + test_msg.flash_program.data[213] = 239; + + test_msg.flash_program.data[214] = 168; + + test_msg.flash_program.data[215] = 32; + + test_msg.flash_program.data[216] = 212; + + test_msg.flash_program.data[217] = 191; + + test_msg.flash_program.data[218] = 81; + + test_msg.flash_program.data[219] = 93; + + test_msg.flash_program.data[220] = 186; + + test_msg.flash_program.data[221] = 223; + + test_msg.flash_program.data[222] = 32; + + test_msg.flash_program.data[223] = 19; + + test_msg.flash_program.data[224] = 58; + + test_msg.flash_program.data[225] = 137; + + test_msg.flash_program.data[226] = 72; + + test_msg.flash_program.data[227] = 217; + + test_msg.flash_program.data[228] = 151; + + test_msg.flash_program.data[229] = 251; + + test_msg.flash_program.data[230] = 83; + + test_msg.flash_program.data[231] = 20; + + test_msg.flash_program.data[232] = 113; + + test_msg.flash_program.data[233] = 37; + + test_msg.flash_program.data[234] = 151; + + test_msg.flash_program.data[235] = 34; + + test_msg.flash_program.data[236] = 37; + + test_msg.flash_program.data[237] = 71; + + test_msg.flash_program.data[238] = 95; + + test_msg.flash_program.data[239] = 105; + + test_msg.flash_program.data[240] = 235; + + test_msg.flash_program.data[241] = 144; + + test_msg.flash_program.data[242] = 164; + + test_msg.flash_program.data[243] = 83; + + test_msg.flash_program.data[244] = 197; + + test_msg.flash_program.data[245] = 254; + + test_msg.flash_program.data[246] = 183; + + test_msg.flash_program.data[247] = 223; + + test_msg.flash_program.data[248] = 91; + + test_msg.flash_program.data[249] = 19; + + test_msg.flash_program.target = 212; + + sbp_message_send(&sbp_state, SbpMsgFlashProgram, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFlashProgram, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.flash_program.addr_len == 250, + "incorrect value for last_msg.msg.flash_program.addr_len, " + "expected 250, is %d", + last_msg.msg.flash_program.addr_len); + + ck_assert_msg( + last_msg.msg.flash_program.addr_start[0] == 87, + "incorrect value for last_msg.msg.flash_program.addr_start[0], " + "expected 87, is %d", + last_msg.msg.flash_program.addr_start[0]); + ck_assert_msg( + last_msg.msg.flash_program.addr_start[1] == 52, + "incorrect value for last_msg.msg.flash_program.addr_start[1], " + "expected 52, is %d", + last_msg.msg.flash_program.addr_start[1]); + ck_assert_msg( + last_msg.msg.flash_program.addr_start[2] == 244, + "incorrect value for last_msg.msg.flash_program.addr_start[2], " + "expected 244, is %d", + last_msg.msg.flash_program.addr_start[2]); + + ck_assert_msg(last_msg.msg.flash_program.data[0] == 176, + "incorrect value for last_msg.msg.flash_program.data[0], " + "expected 176, is %d", + last_msg.msg.flash_program.data[0]); + ck_assert_msg(last_msg.msg.flash_program.data[1] == 222, + "incorrect value for last_msg.msg.flash_program.data[1], " + "expected 222, is %d", + last_msg.msg.flash_program.data[1]); + ck_assert_msg(last_msg.msg.flash_program.data[2] == 235, + "incorrect value for last_msg.msg.flash_program.data[2], " + "expected 235, is %d", + last_msg.msg.flash_program.data[2]); + ck_assert_msg(last_msg.msg.flash_program.data[3] == 106, + "incorrect value for last_msg.msg.flash_program.data[3], " + "expected 106, is %d", + last_msg.msg.flash_program.data[3]); + ck_assert_msg(last_msg.msg.flash_program.data[4] == 144, + "incorrect value for last_msg.msg.flash_program.data[4], " + "expected 144, is %d", + last_msg.msg.flash_program.data[4]); + ck_assert_msg(last_msg.msg.flash_program.data[5] == 29, + "incorrect value for last_msg.msg.flash_program.data[5], " + "expected 29, is %d", + last_msg.msg.flash_program.data[5]); + ck_assert_msg(last_msg.msg.flash_program.data[6] == 141, + "incorrect value for last_msg.msg.flash_program.data[6], " + "expected 141, is %d", + last_msg.msg.flash_program.data[6]); + ck_assert_msg(last_msg.msg.flash_program.data[7] == 255, + "incorrect value for last_msg.msg.flash_program.data[7], " + "expected 255, is %d", + last_msg.msg.flash_program.data[7]); + ck_assert_msg(last_msg.msg.flash_program.data[8] == 3, + "incorrect value for last_msg.msg.flash_program.data[8], " + "expected 3, is %d", + last_msg.msg.flash_program.data[8]); + ck_assert_msg(last_msg.msg.flash_program.data[9] == 16, + "incorrect value for last_msg.msg.flash_program.data[9], " + "expected 16, is %d", + last_msg.msg.flash_program.data[9]); + ck_assert_msg(last_msg.msg.flash_program.data[10] == 192, + "incorrect value for last_msg.msg.flash_program.data[10], " + "expected 192, is %d", + last_msg.msg.flash_program.data[10]); + ck_assert_msg(last_msg.msg.flash_program.data[11] == 237, + "incorrect value for last_msg.msg.flash_program.data[11], " + "expected 237, is %d", + last_msg.msg.flash_program.data[11]); + ck_assert_msg(last_msg.msg.flash_program.data[12] == 172, + "incorrect value for last_msg.msg.flash_program.data[12], " + "expected 172, is %d", + last_msg.msg.flash_program.data[12]); + ck_assert_msg(last_msg.msg.flash_program.data[13] == 254, + "incorrect value for last_msg.msg.flash_program.data[13], " + "expected 254, is %d", + last_msg.msg.flash_program.data[13]); + ck_assert_msg(last_msg.msg.flash_program.data[14] == 213, + "incorrect value for last_msg.msg.flash_program.data[14], " + "expected 213, is %d", + last_msg.msg.flash_program.data[14]); + ck_assert_msg(last_msg.msg.flash_program.data[15] == 4, + "incorrect value for last_msg.msg.flash_program.data[15], " + "expected 4, is %d", + last_msg.msg.flash_program.data[15]); + ck_assert_msg(last_msg.msg.flash_program.data[16] == 220, + "incorrect value for last_msg.msg.flash_program.data[16], " + "expected 220, is %d", + last_msg.msg.flash_program.data[16]); + ck_assert_msg(last_msg.msg.flash_program.data[17] == 98, + "incorrect value for last_msg.msg.flash_program.data[17], " + "expected 98, is %d", + last_msg.msg.flash_program.data[17]); + ck_assert_msg(last_msg.msg.flash_program.data[18] == 34, + "incorrect value for last_msg.msg.flash_program.data[18], " + "expected 34, is %d", + last_msg.msg.flash_program.data[18]); + ck_assert_msg(last_msg.msg.flash_program.data[19] == 222, + "incorrect value for last_msg.msg.flash_program.data[19], " + "expected 222, is %d", + last_msg.msg.flash_program.data[19]); + ck_assert_msg(last_msg.msg.flash_program.data[20] == 230, + "incorrect value for last_msg.msg.flash_program.data[20], " + "expected 230, is %d", + last_msg.msg.flash_program.data[20]); + ck_assert_msg(last_msg.msg.flash_program.data[21] == 214, + "incorrect value for last_msg.msg.flash_program.data[21], " + "expected 214, is %d", + last_msg.msg.flash_program.data[21]); + ck_assert_msg(last_msg.msg.flash_program.data[22] == 6, + "incorrect value for last_msg.msg.flash_program.data[22], " + "expected 6, is %d", + last_msg.msg.flash_program.data[22]); + ck_assert_msg(last_msg.msg.flash_program.data[23] == 217, + "incorrect value for last_msg.msg.flash_program.data[23], " + "expected 217, is %d", + last_msg.msg.flash_program.data[23]); + ck_assert_msg(last_msg.msg.flash_program.data[24] == 172, + "incorrect value for last_msg.msg.flash_program.data[24], " + "expected 172, is %d", + last_msg.msg.flash_program.data[24]); + ck_assert_msg(last_msg.msg.flash_program.data[25] == 122, + "incorrect value for last_msg.msg.flash_program.data[25], " + "expected 122, is %d", + last_msg.msg.flash_program.data[25]); + ck_assert_msg(last_msg.msg.flash_program.data[26] == 46, + "incorrect value for last_msg.msg.flash_program.data[26], " + "expected 46, is %d", + last_msg.msg.flash_program.data[26]); + ck_assert_msg(last_msg.msg.flash_program.data[27] == 13, + "incorrect value for last_msg.msg.flash_program.data[27], " + "expected 13, is %d", + last_msg.msg.flash_program.data[27]); + ck_assert_msg(last_msg.msg.flash_program.data[28] == 38, + "incorrect value for last_msg.msg.flash_program.data[28], " + "expected 38, is %d", + last_msg.msg.flash_program.data[28]); + ck_assert_msg(last_msg.msg.flash_program.data[29] == 240, + "incorrect value for last_msg.msg.flash_program.data[29], " + "expected 240, is %d", + last_msg.msg.flash_program.data[29]); + ck_assert_msg(last_msg.msg.flash_program.data[30] == 236, + "incorrect value for last_msg.msg.flash_program.data[30], " + "expected 236, is %d", + last_msg.msg.flash_program.data[30]); + ck_assert_msg(last_msg.msg.flash_program.data[31] == 60, + "incorrect value for last_msg.msg.flash_program.data[31], " + "expected 60, is %d", + last_msg.msg.flash_program.data[31]); + ck_assert_msg(last_msg.msg.flash_program.data[32] == 121, + "incorrect value for last_msg.msg.flash_program.data[32], " + "expected 121, is %d", + last_msg.msg.flash_program.data[32]); + ck_assert_msg(last_msg.msg.flash_program.data[33] == 47, + "incorrect value for last_msg.msg.flash_program.data[33], " + "expected 47, is %d", + last_msg.msg.flash_program.data[33]); + ck_assert_msg(last_msg.msg.flash_program.data[34] == 252, + "incorrect value for last_msg.msg.flash_program.data[34], " + "expected 252, is %d", + last_msg.msg.flash_program.data[34]); + ck_assert_msg(last_msg.msg.flash_program.data[35] == 163, + "incorrect value for last_msg.msg.flash_program.data[35], " + "expected 163, is %d", + last_msg.msg.flash_program.data[35]); + ck_assert_msg(last_msg.msg.flash_program.data[36] == 141, + "incorrect value for last_msg.msg.flash_program.data[36], " + "expected 141, is %d", + last_msg.msg.flash_program.data[36]); + ck_assert_msg(last_msg.msg.flash_program.data[37] == 222, + "incorrect value for last_msg.msg.flash_program.data[37], " + "expected 222, is %d", + last_msg.msg.flash_program.data[37]); + ck_assert_msg(last_msg.msg.flash_program.data[38] == 29, + "incorrect value for last_msg.msg.flash_program.data[38], " + "expected 29, is %d", + last_msg.msg.flash_program.data[38]); + ck_assert_msg(last_msg.msg.flash_program.data[39] == 168, + "incorrect value for last_msg.msg.flash_program.data[39], " + "expected 168, is %d", + last_msg.msg.flash_program.data[39]); + ck_assert_msg(last_msg.msg.flash_program.data[40] == 214, + "incorrect value for last_msg.msg.flash_program.data[40], " + "expected 214, is %d", + last_msg.msg.flash_program.data[40]); + ck_assert_msg(last_msg.msg.flash_program.data[41] == 118, + "incorrect value for last_msg.msg.flash_program.data[41], " + "expected 118, is %d", + last_msg.msg.flash_program.data[41]); + ck_assert_msg(last_msg.msg.flash_program.data[42] == 55, + "incorrect value for last_msg.msg.flash_program.data[42], " + "expected 55, is %d", + last_msg.msg.flash_program.data[42]); + ck_assert_msg(last_msg.msg.flash_program.data[43] == 201, + "incorrect value for last_msg.msg.flash_program.data[43], " + "expected 201, is %d", + last_msg.msg.flash_program.data[43]); + ck_assert_msg(last_msg.msg.flash_program.data[44] == 233, + "incorrect value for last_msg.msg.flash_program.data[44], " + "expected 233, is %d", + last_msg.msg.flash_program.data[44]); + ck_assert_msg(last_msg.msg.flash_program.data[45] == 21, + "incorrect value for last_msg.msg.flash_program.data[45], " + "expected 21, is %d", + last_msg.msg.flash_program.data[45]); + ck_assert_msg(last_msg.msg.flash_program.data[46] == 214, + "incorrect value for last_msg.msg.flash_program.data[46], " + "expected 214, is %d", + last_msg.msg.flash_program.data[46]); + ck_assert_msg(last_msg.msg.flash_program.data[47] == 57, + "incorrect value for last_msg.msg.flash_program.data[47], " + "expected 57, is %d", + last_msg.msg.flash_program.data[47]); + ck_assert_msg(last_msg.msg.flash_program.data[48] == 245, + "incorrect value for last_msg.msg.flash_program.data[48], " + "expected 245, is %d", + last_msg.msg.flash_program.data[48]); + ck_assert_msg(last_msg.msg.flash_program.data[49] == 246, + "incorrect value for last_msg.msg.flash_program.data[49], " + "expected 246, is %d", + last_msg.msg.flash_program.data[49]); + ck_assert_msg(last_msg.msg.flash_program.data[50] == 19, + "incorrect value for last_msg.msg.flash_program.data[50], " + "expected 19, is %d", + last_msg.msg.flash_program.data[50]); + ck_assert_msg(last_msg.msg.flash_program.data[51] == 3, + "incorrect value for last_msg.msg.flash_program.data[51], " + "expected 3, is %d", + last_msg.msg.flash_program.data[51]); + ck_assert_msg(last_msg.msg.flash_program.data[52] == 121, + "incorrect value for last_msg.msg.flash_program.data[52], " + "expected 121, is %d", + last_msg.msg.flash_program.data[52]); + ck_assert_msg(last_msg.msg.flash_program.data[53] == 49, + "incorrect value for last_msg.msg.flash_program.data[53], " + "expected 49, is %d", + last_msg.msg.flash_program.data[53]); + ck_assert_msg(last_msg.msg.flash_program.data[54] == 231, + "incorrect value for last_msg.msg.flash_program.data[54], " + "expected 231, is %d", + last_msg.msg.flash_program.data[54]); + ck_assert_msg(last_msg.msg.flash_program.data[55] == 37, + "incorrect value for last_msg.msg.flash_program.data[55], " + "expected 37, is %d", + last_msg.msg.flash_program.data[55]); + ck_assert_msg(last_msg.msg.flash_program.data[56] == 186, + "incorrect value for last_msg.msg.flash_program.data[56], " + "expected 186, is %d", + last_msg.msg.flash_program.data[56]); + ck_assert_msg(last_msg.msg.flash_program.data[57] == 58, + "incorrect value for last_msg.msg.flash_program.data[57], " + "expected 58, is %d", + last_msg.msg.flash_program.data[57]); + ck_assert_msg(last_msg.msg.flash_program.data[58] == 238, + "incorrect value for last_msg.msg.flash_program.data[58], " + "expected 238, is %d", + last_msg.msg.flash_program.data[58]); + ck_assert_msg(last_msg.msg.flash_program.data[59] == 98, + "incorrect value for last_msg.msg.flash_program.data[59], " + "expected 98, is %d", + last_msg.msg.flash_program.data[59]); + ck_assert_msg(last_msg.msg.flash_program.data[60] == 39, + "incorrect value for last_msg.msg.flash_program.data[60], " + "expected 39, is %d", + last_msg.msg.flash_program.data[60]); + ck_assert_msg(last_msg.msg.flash_program.data[61] == 70, + "incorrect value for last_msg.msg.flash_program.data[61], " + "expected 70, is %d", + last_msg.msg.flash_program.data[61]); + ck_assert_msg(last_msg.msg.flash_program.data[62] == 232, + "incorrect value for last_msg.msg.flash_program.data[62], " + "expected 232, is %d", + last_msg.msg.flash_program.data[62]); + ck_assert_msg(last_msg.msg.flash_program.data[63] == 133, + "incorrect value for last_msg.msg.flash_program.data[63], " + "expected 133, is %d", + last_msg.msg.flash_program.data[63]); + ck_assert_msg(last_msg.msg.flash_program.data[64] == 25, + "incorrect value for last_msg.msg.flash_program.data[64], " + "expected 25, is %d", + last_msg.msg.flash_program.data[64]); + ck_assert_msg(last_msg.msg.flash_program.data[65] == 10, + "incorrect value for last_msg.msg.flash_program.data[65], " + "expected 10, is %d", + last_msg.msg.flash_program.data[65]); + ck_assert_msg(last_msg.msg.flash_program.data[66] == 134, + "incorrect value for last_msg.msg.flash_program.data[66], " + "expected 134, is %d", + last_msg.msg.flash_program.data[66]); + ck_assert_msg(last_msg.msg.flash_program.data[67] == 129, + "incorrect value for last_msg.msg.flash_program.data[67], " + "expected 129, is %d", + last_msg.msg.flash_program.data[67]); + ck_assert_msg(last_msg.msg.flash_program.data[68] == 69, + "incorrect value for last_msg.msg.flash_program.data[68], " + "expected 69, is %d", + last_msg.msg.flash_program.data[68]); + ck_assert_msg(last_msg.msg.flash_program.data[69] == 228, + "incorrect value for last_msg.msg.flash_program.data[69], " + "expected 228, is %d", + last_msg.msg.flash_program.data[69]); + ck_assert_msg(last_msg.msg.flash_program.data[70] == 134, + "incorrect value for last_msg.msg.flash_program.data[70], " + "expected 134, is %d", + last_msg.msg.flash_program.data[70]); + ck_assert_msg(last_msg.msg.flash_program.data[71] == 9, + "incorrect value for last_msg.msg.flash_program.data[71], " + "expected 9, is %d", + last_msg.msg.flash_program.data[71]); + ck_assert_msg(last_msg.msg.flash_program.data[72] == 88, + "incorrect value for last_msg.msg.flash_program.data[72], " + "expected 88, is %d", + last_msg.msg.flash_program.data[72]); + ck_assert_msg(last_msg.msg.flash_program.data[73] == 183, + "incorrect value for last_msg.msg.flash_program.data[73], " + "expected 183, is %d", + last_msg.msg.flash_program.data[73]); + ck_assert_msg(last_msg.msg.flash_program.data[74] == 133, + "incorrect value for last_msg.msg.flash_program.data[74], " + "expected 133, is %d", + last_msg.msg.flash_program.data[74]); + ck_assert_msg(last_msg.msg.flash_program.data[75] == 171, + "incorrect value for last_msg.msg.flash_program.data[75], " + "expected 171, is %d", + last_msg.msg.flash_program.data[75]); + ck_assert_msg(last_msg.msg.flash_program.data[76] == 255, + "incorrect value for last_msg.msg.flash_program.data[76], " + "expected 255, is %d", + last_msg.msg.flash_program.data[76]); + ck_assert_msg(last_msg.msg.flash_program.data[77] == 166, + "incorrect value for last_msg.msg.flash_program.data[77], " + "expected 166, is %d", + last_msg.msg.flash_program.data[77]); + ck_assert_msg(last_msg.msg.flash_program.data[78] == 100, + "incorrect value for last_msg.msg.flash_program.data[78], " + "expected 100, is %d", + last_msg.msg.flash_program.data[78]); + ck_assert_msg(last_msg.msg.flash_program.data[79] == 152, + "incorrect value for last_msg.msg.flash_program.data[79], " + "expected 152, is %d", + last_msg.msg.flash_program.data[79]); + ck_assert_msg(last_msg.msg.flash_program.data[80] == 231, + "incorrect value for last_msg.msg.flash_program.data[80], " + "expected 231, is %d", + last_msg.msg.flash_program.data[80]); + ck_assert_msg(last_msg.msg.flash_program.data[81] == 92, + "incorrect value for last_msg.msg.flash_program.data[81], " + "expected 92, is %d", + last_msg.msg.flash_program.data[81]); + ck_assert_msg(last_msg.msg.flash_program.data[82] == 9, + "incorrect value for last_msg.msg.flash_program.data[82], " + "expected 9, is %d", + last_msg.msg.flash_program.data[82]); + ck_assert_msg(last_msg.msg.flash_program.data[83] == 196, + "incorrect value for last_msg.msg.flash_program.data[83], " + "expected 196, is %d", + last_msg.msg.flash_program.data[83]); + ck_assert_msg(last_msg.msg.flash_program.data[84] == 106, + "incorrect value for last_msg.msg.flash_program.data[84], " + "expected 106, is %d", + last_msg.msg.flash_program.data[84]); + ck_assert_msg(last_msg.msg.flash_program.data[85] == 246, + "incorrect value for last_msg.msg.flash_program.data[85], " + "expected 246, is %d", + last_msg.msg.flash_program.data[85]); + ck_assert_msg(last_msg.msg.flash_program.data[86] == 29, + "incorrect value for last_msg.msg.flash_program.data[86], " + "expected 29, is %d", + last_msg.msg.flash_program.data[86]); + ck_assert_msg(last_msg.msg.flash_program.data[87] == 145, + "incorrect value for last_msg.msg.flash_program.data[87], " + "expected 145, is %d", + last_msg.msg.flash_program.data[87]); + ck_assert_msg(last_msg.msg.flash_program.data[88] == 156, + "incorrect value for last_msg.msg.flash_program.data[88], " + "expected 156, is %d", + last_msg.msg.flash_program.data[88]); + ck_assert_msg(last_msg.msg.flash_program.data[89] == 151, + "incorrect value for last_msg.msg.flash_program.data[89], " + "expected 151, is %d", + last_msg.msg.flash_program.data[89]); + ck_assert_msg(last_msg.msg.flash_program.data[90] == 32, + "incorrect value for last_msg.msg.flash_program.data[90], " + "expected 32, is %d", + last_msg.msg.flash_program.data[90]); + ck_assert_msg(last_msg.msg.flash_program.data[91] == 67, + "incorrect value for last_msg.msg.flash_program.data[91], " + "expected 67, is %d", + last_msg.msg.flash_program.data[91]); + ck_assert_msg(last_msg.msg.flash_program.data[92] == 188, + "incorrect value for last_msg.msg.flash_program.data[92], " + "expected 188, is %d", + last_msg.msg.flash_program.data[92]); + ck_assert_msg(last_msg.msg.flash_program.data[93] == 63, + "incorrect value for last_msg.msg.flash_program.data[93], " + "expected 63, is %d", + last_msg.msg.flash_program.data[93]); + ck_assert_msg(last_msg.msg.flash_program.data[94] == 233, + "incorrect value for last_msg.msg.flash_program.data[94], " + "expected 233, is %d", + last_msg.msg.flash_program.data[94]); + ck_assert_msg(last_msg.msg.flash_program.data[95] == 142, + "incorrect value for last_msg.msg.flash_program.data[95], " + "expected 142, is %d", + last_msg.msg.flash_program.data[95]); + ck_assert_msg(last_msg.msg.flash_program.data[96] == 174, + "incorrect value for last_msg.msg.flash_program.data[96], " + "expected 174, is %d", + last_msg.msg.flash_program.data[96]); + ck_assert_msg(last_msg.msg.flash_program.data[97] == 139, + "incorrect value for last_msg.msg.flash_program.data[97], " + "expected 139, is %d", + last_msg.msg.flash_program.data[97]); + ck_assert_msg(last_msg.msg.flash_program.data[98] == 154, + "incorrect value for last_msg.msg.flash_program.data[98], " + "expected 154, is %d", + last_msg.msg.flash_program.data[98]); + ck_assert_msg(last_msg.msg.flash_program.data[99] == 127, + "incorrect value for last_msg.msg.flash_program.data[99], " + "expected 127, is %d", + last_msg.msg.flash_program.data[99]); + ck_assert_msg(last_msg.msg.flash_program.data[100] == 35, + "incorrect value for last_msg.msg.flash_program.data[100], " + "expected 35, is %d", + last_msg.msg.flash_program.data[100]); + ck_assert_msg(last_msg.msg.flash_program.data[101] == 60, + "incorrect value for last_msg.msg.flash_program.data[101], " + "expected 60, is %d", + last_msg.msg.flash_program.data[101]); + ck_assert_msg(last_msg.msg.flash_program.data[102] == 56, + "incorrect value for last_msg.msg.flash_program.data[102], " + "expected 56, is %d", + last_msg.msg.flash_program.data[102]); + ck_assert_msg(last_msg.msg.flash_program.data[103] == 187, + "incorrect value for last_msg.msg.flash_program.data[103], " + "expected 187, is %d", + last_msg.msg.flash_program.data[103]); + ck_assert_msg(last_msg.msg.flash_program.data[104] == 121, + "incorrect value for last_msg.msg.flash_program.data[104], " + "expected 121, is %d", + last_msg.msg.flash_program.data[104]); + ck_assert_msg(last_msg.msg.flash_program.data[105] == 103, + "incorrect value for last_msg.msg.flash_program.data[105], " + "expected 103, is %d", + last_msg.msg.flash_program.data[105]); + ck_assert_msg(last_msg.msg.flash_program.data[106] == 135, + "incorrect value for last_msg.msg.flash_program.data[106], " + "expected 135, is %d", + last_msg.msg.flash_program.data[106]); + ck_assert_msg(last_msg.msg.flash_program.data[107] == 152, + "incorrect value for last_msg.msg.flash_program.data[107], " + "expected 152, is %d", + last_msg.msg.flash_program.data[107]); + ck_assert_msg(last_msg.msg.flash_program.data[108] == 182, + "incorrect value for last_msg.msg.flash_program.data[108], " + "expected 182, is %d", + last_msg.msg.flash_program.data[108]); + ck_assert_msg(last_msg.msg.flash_program.data[109] == 88, + "incorrect value for last_msg.msg.flash_program.data[109], " + "expected 88, is %d", + last_msg.msg.flash_program.data[109]); + ck_assert_msg(last_msg.msg.flash_program.data[110] == 160, + "incorrect value for last_msg.msg.flash_program.data[110], " + "expected 160, is %d", + last_msg.msg.flash_program.data[110]); + ck_assert_msg(last_msg.msg.flash_program.data[111] == 255, + "incorrect value for last_msg.msg.flash_program.data[111], " + "expected 255, is %d", + last_msg.msg.flash_program.data[111]); + ck_assert_msg(last_msg.msg.flash_program.data[112] == 227, + "incorrect value for last_msg.msg.flash_program.data[112], " + "expected 227, is %d", + last_msg.msg.flash_program.data[112]); + ck_assert_msg(last_msg.msg.flash_program.data[113] == 240, + "incorrect value for last_msg.msg.flash_program.data[113], " + "expected 240, is %d", + last_msg.msg.flash_program.data[113]); + ck_assert_msg(last_msg.msg.flash_program.data[114] == 54, + "incorrect value for last_msg.msg.flash_program.data[114], " + "expected 54, is %d", + last_msg.msg.flash_program.data[114]); + ck_assert_msg(last_msg.msg.flash_program.data[115] == 100, + "incorrect value for last_msg.msg.flash_program.data[115], " + "expected 100, is %d", + last_msg.msg.flash_program.data[115]); + ck_assert_msg(last_msg.msg.flash_program.data[116] == 91, + "incorrect value for last_msg.msg.flash_program.data[116], " + "expected 91, is %d", + last_msg.msg.flash_program.data[116]); + ck_assert_msg(last_msg.msg.flash_program.data[117] == 31, + "incorrect value for last_msg.msg.flash_program.data[117], " + "expected 31, is %d", + last_msg.msg.flash_program.data[117]); + ck_assert_msg(last_msg.msg.flash_program.data[118] == 141, + "incorrect value for last_msg.msg.flash_program.data[118], " + "expected 141, is %d", + last_msg.msg.flash_program.data[118]); + ck_assert_msg(last_msg.msg.flash_program.data[119] == 102, + "incorrect value for last_msg.msg.flash_program.data[119], " + "expected 102, is %d", + last_msg.msg.flash_program.data[119]); + ck_assert_msg(last_msg.msg.flash_program.data[120] == 130, + "incorrect value for last_msg.msg.flash_program.data[120], " + "expected 130, is %d", + last_msg.msg.flash_program.data[120]); + ck_assert_msg(last_msg.msg.flash_program.data[121] == 254, + "incorrect value for last_msg.msg.flash_program.data[121], " + "expected 254, is %d", + last_msg.msg.flash_program.data[121]); + ck_assert_msg(last_msg.msg.flash_program.data[122] == 54, + "incorrect value for last_msg.msg.flash_program.data[122], " + "expected 54, is %d", + last_msg.msg.flash_program.data[122]); + ck_assert_msg(last_msg.msg.flash_program.data[123] == 227, + "incorrect value for last_msg.msg.flash_program.data[123], " + "expected 227, is %d", + last_msg.msg.flash_program.data[123]); + ck_assert_msg(last_msg.msg.flash_program.data[124] == 229, + "incorrect value for last_msg.msg.flash_program.data[124], " + "expected 229, is %d", + last_msg.msg.flash_program.data[124]); + ck_assert_msg(last_msg.msg.flash_program.data[125] == 62, + "incorrect value for last_msg.msg.flash_program.data[125], " + "expected 62, is %d", + last_msg.msg.flash_program.data[125]); + ck_assert_msg(last_msg.msg.flash_program.data[126] == 53, + "incorrect value for last_msg.msg.flash_program.data[126], " + "expected 53, is %d", + last_msg.msg.flash_program.data[126]); + ck_assert_msg(last_msg.msg.flash_program.data[127] == 225, + "incorrect value for last_msg.msg.flash_program.data[127], " + "expected 225, is %d", + last_msg.msg.flash_program.data[127]); + ck_assert_msg(last_msg.msg.flash_program.data[128] == 143, + "incorrect value for last_msg.msg.flash_program.data[128], " + "expected 143, is %d", + last_msg.msg.flash_program.data[128]); + ck_assert_msg(last_msg.msg.flash_program.data[129] == 88, + "incorrect value for last_msg.msg.flash_program.data[129], " + "expected 88, is %d", + last_msg.msg.flash_program.data[129]); + ck_assert_msg(last_msg.msg.flash_program.data[130] == 139, + "incorrect value for last_msg.msg.flash_program.data[130], " + "expected 139, is %d", + last_msg.msg.flash_program.data[130]); + ck_assert_msg(last_msg.msg.flash_program.data[131] == 126, + "incorrect value for last_msg.msg.flash_program.data[131], " + "expected 126, is %d", + last_msg.msg.flash_program.data[131]); + ck_assert_msg(last_msg.msg.flash_program.data[132] == 235, + "incorrect value for last_msg.msg.flash_program.data[132], " + "expected 235, is %d", + last_msg.msg.flash_program.data[132]); + ck_assert_msg(last_msg.msg.flash_program.data[133] == 235, + "incorrect value for last_msg.msg.flash_program.data[133], " + "expected 235, is %d", + last_msg.msg.flash_program.data[133]); + ck_assert_msg(last_msg.msg.flash_program.data[134] == 35, + "incorrect value for last_msg.msg.flash_program.data[134], " + "expected 35, is %d", + last_msg.msg.flash_program.data[134]); + ck_assert_msg(last_msg.msg.flash_program.data[135] == 54, + "incorrect value for last_msg.msg.flash_program.data[135], " + "expected 54, is %d", + last_msg.msg.flash_program.data[135]); + ck_assert_msg(last_msg.msg.flash_program.data[136] == 134, + "incorrect value for last_msg.msg.flash_program.data[136], " + "expected 134, is %d", + last_msg.msg.flash_program.data[136]); + ck_assert_msg(last_msg.msg.flash_program.data[137] == 163, + "incorrect value for last_msg.msg.flash_program.data[137], " + "expected 163, is %d", + last_msg.msg.flash_program.data[137]); + ck_assert_msg(last_msg.msg.flash_program.data[138] == 92, + "incorrect value for last_msg.msg.flash_program.data[138], " + "expected 92, is %d", + last_msg.msg.flash_program.data[138]); + ck_assert_msg(last_msg.msg.flash_program.data[139] == 57, + "incorrect value for last_msg.msg.flash_program.data[139], " + "expected 57, is %d", + last_msg.msg.flash_program.data[139]); + ck_assert_msg(last_msg.msg.flash_program.data[140] == 87, + "incorrect value for last_msg.msg.flash_program.data[140], " + "expected 87, is %d", + last_msg.msg.flash_program.data[140]); + ck_assert_msg(last_msg.msg.flash_program.data[141] == 130, + "incorrect value for last_msg.msg.flash_program.data[141], " + "expected 130, is %d", + last_msg.msg.flash_program.data[141]); + ck_assert_msg(last_msg.msg.flash_program.data[142] == 178, + "incorrect value for last_msg.msg.flash_program.data[142], " + "expected 178, is %d", + last_msg.msg.flash_program.data[142]); + ck_assert_msg(last_msg.msg.flash_program.data[143] == 22, + "incorrect value for last_msg.msg.flash_program.data[143], " + "expected 22, is %d", + last_msg.msg.flash_program.data[143]); + ck_assert_msg(last_msg.msg.flash_program.data[144] == 158, + "incorrect value for last_msg.msg.flash_program.data[144], " + "expected 158, is %d", + last_msg.msg.flash_program.data[144]); + ck_assert_msg(last_msg.msg.flash_program.data[145] == 18, + "incorrect value for last_msg.msg.flash_program.data[145], " + "expected 18, is %d", + last_msg.msg.flash_program.data[145]); + ck_assert_msg(last_msg.msg.flash_program.data[146] == 237, + "incorrect value for last_msg.msg.flash_program.data[146], " + "expected 237, is %d", + last_msg.msg.flash_program.data[146]); + ck_assert_msg(last_msg.msg.flash_program.data[147] == 209, + "incorrect value for last_msg.msg.flash_program.data[147], " + "expected 209, is %d", + last_msg.msg.flash_program.data[147]); + ck_assert_msg(last_msg.msg.flash_program.data[148] == 187, + "incorrect value for last_msg.msg.flash_program.data[148], " + "expected 187, is %d", + last_msg.msg.flash_program.data[148]); + ck_assert_msg(last_msg.msg.flash_program.data[149] == 226, + "incorrect value for last_msg.msg.flash_program.data[149], " + "expected 226, is %d", + last_msg.msg.flash_program.data[149]); + ck_assert_msg(last_msg.msg.flash_program.data[150] == 1, + "incorrect value for last_msg.msg.flash_program.data[150], " + "expected 1, is %d", + last_msg.msg.flash_program.data[150]); + ck_assert_msg(last_msg.msg.flash_program.data[151] == 46, + "incorrect value for last_msg.msg.flash_program.data[151], " + "expected 46, is %d", + last_msg.msg.flash_program.data[151]); + ck_assert_msg(last_msg.msg.flash_program.data[152] == 64, + "incorrect value for last_msg.msg.flash_program.data[152], " + "expected 64, is %d", + last_msg.msg.flash_program.data[152]); + ck_assert_msg(last_msg.msg.flash_program.data[153] == 226, + "incorrect value for last_msg.msg.flash_program.data[153], " + "expected 226, is %d", + last_msg.msg.flash_program.data[153]); + ck_assert_msg(last_msg.msg.flash_program.data[154] == 235, + "incorrect value for last_msg.msg.flash_program.data[154], " + "expected 235, is %d", + last_msg.msg.flash_program.data[154]); + ck_assert_msg(last_msg.msg.flash_program.data[155] == 213, + "incorrect value for last_msg.msg.flash_program.data[155], " + "expected 213, is %d", + last_msg.msg.flash_program.data[155]); + ck_assert_msg(last_msg.msg.flash_program.data[156] == 186, + "incorrect value for last_msg.msg.flash_program.data[156], " + "expected 186, is %d", + last_msg.msg.flash_program.data[156]); + ck_assert_msg(last_msg.msg.flash_program.data[157] == 159, + "incorrect value for last_msg.msg.flash_program.data[157], " + "expected 159, is %d", + last_msg.msg.flash_program.data[157]); + ck_assert_msg(last_msg.msg.flash_program.data[158] == 221, + "incorrect value for last_msg.msg.flash_program.data[158], " + "expected 221, is %d", + last_msg.msg.flash_program.data[158]); + ck_assert_msg(last_msg.msg.flash_program.data[159] == 186, + "incorrect value for last_msg.msg.flash_program.data[159], " + "expected 186, is %d", + last_msg.msg.flash_program.data[159]); + ck_assert_msg(last_msg.msg.flash_program.data[160] == 25, + "incorrect value for last_msg.msg.flash_program.data[160], " + "expected 25, is %d", + last_msg.msg.flash_program.data[160]); + ck_assert_msg(last_msg.msg.flash_program.data[161] == 115, + "incorrect value for last_msg.msg.flash_program.data[161], " + "expected 115, is %d", + last_msg.msg.flash_program.data[161]); + ck_assert_msg(last_msg.msg.flash_program.data[162] == 84, + "incorrect value for last_msg.msg.flash_program.data[162], " + "expected 84, is %d", + last_msg.msg.flash_program.data[162]); + ck_assert_msg(last_msg.msg.flash_program.data[163] == 131, + "incorrect value for last_msg.msg.flash_program.data[163], " + "expected 131, is %d", + last_msg.msg.flash_program.data[163]); + ck_assert_msg(last_msg.msg.flash_program.data[164] == 167, + "incorrect value for last_msg.msg.flash_program.data[164], " + "expected 167, is %d", + last_msg.msg.flash_program.data[164]); + ck_assert_msg(last_msg.msg.flash_program.data[165] == 201, + "incorrect value for last_msg.msg.flash_program.data[165], " + "expected 201, is %d", + last_msg.msg.flash_program.data[165]); + ck_assert_msg(last_msg.msg.flash_program.data[166] == 104, + "incorrect value for last_msg.msg.flash_program.data[166], " + "expected 104, is %d", + last_msg.msg.flash_program.data[166]); + ck_assert_msg(last_msg.msg.flash_program.data[167] == 1, + "incorrect value for last_msg.msg.flash_program.data[167], " + "expected 1, is %d", + last_msg.msg.flash_program.data[167]); + ck_assert_msg(last_msg.msg.flash_program.data[168] == 200, + "incorrect value for last_msg.msg.flash_program.data[168], " + "expected 200, is %d", + last_msg.msg.flash_program.data[168]); + ck_assert_msg(last_msg.msg.flash_program.data[169] == 13, + "incorrect value for last_msg.msg.flash_program.data[169], " + "expected 13, is %d", + last_msg.msg.flash_program.data[169]); + ck_assert_msg(last_msg.msg.flash_program.data[170] == 50, + "incorrect value for last_msg.msg.flash_program.data[170], " + "expected 50, is %d", + last_msg.msg.flash_program.data[170]); + ck_assert_msg(last_msg.msg.flash_program.data[171] == 71, + "incorrect value for last_msg.msg.flash_program.data[171], " + "expected 71, is %d", + last_msg.msg.flash_program.data[171]); + ck_assert_msg(last_msg.msg.flash_program.data[172] == 73, + "incorrect value for last_msg.msg.flash_program.data[172], " + "expected 73, is %d", + last_msg.msg.flash_program.data[172]); + ck_assert_msg(last_msg.msg.flash_program.data[173] == 193, + "incorrect value for last_msg.msg.flash_program.data[173], " + "expected 193, is %d", + last_msg.msg.flash_program.data[173]); + ck_assert_msg(last_msg.msg.flash_program.data[174] == 201, + "incorrect value for last_msg.msg.flash_program.data[174], " + "expected 201, is %d", + last_msg.msg.flash_program.data[174]); + ck_assert_msg(last_msg.msg.flash_program.data[175] == 250, + "incorrect value for last_msg.msg.flash_program.data[175], " + "expected 250, is %d", + last_msg.msg.flash_program.data[175]); + ck_assert_msg(last_msg.msg.flash_program.data[176] == 172, + "incorrect value for last_msg.msg.flash_program.data[176], " + "expected 172, is %d", + last_msg.msg.flash_program.data[176]); + ck_assert_msg(last_msg.msg.flash_program.data[177] == 193, + "incorrect value for last_msg.msg.flash_program.data[177], " + "expected 193, is %d", + last_msg.msg.flash_program.data[177]); + ck_assert_msg(last_msg.msg.flash_program.data[178] == 13, + "incorrect value for last_msg.msg.flash_program.data[178], " + "expected 13, is %d", + last_msg.msg.flash_program.data[178]); + ck_assert_msg(last_msg.msg.flash_program.data[179] == 20, + "incorrect value for last_msg.msg.flash_program.data[179], " + "expected 20, is %d", + last_msg.msg.flash_program.data[179]); + ck_assert_msg(last_msg.msg.flash_program.data[180] == 238, + "incorrect value for last_msg.msg.flash_program.data[180], " + "expected 238, is %d", + last_msg.msg.flash_program.data[180]); + ck_assert_msg(last_msg.msg.flash_program.data[181] == 130, + "incorrect value for last_msg.msg.flash_program.data[181], " + "expected 130, is %d", + last_msg.msg.flash_program.data[181]); + ck_assert_msg(last_msg.msg.flash_program.data[182] == 243, + "incorrect value for last_msg.msg.flash_program.data[182], " + "expected 243, is %d", + last_msg.msg.flash_program.data[182]); + ck_assert_msg(last_msg.msg.flash_program.data[183] == 68, + "incorrect value for last_msg.msg.flash_program.data[183], " + "expected 68, is %d", + last_msg.msg.flash_program.data[183]); + ck_assert_msg(last_msg.msg.flash_program.data[184] == 4, + "incorrect value for last_msg.msg.flash_program.data[184], " + "expected 4, is %d", + last_msg.msg.flash_program.data[184]); + ck_assert_msg(last_msg.msg.flash_program.data[185] == 72, + "incorrect value for last_msg.msg.flash_program.data[185], " + "expected 72, is %d", + last_msg.msg.flash_program.data[185]); + ck_assert_msg(last_msg.msg.flash_program.data[186] == 46, + "incorrect value for last_msg.msg.flash_program.data[186], " + "expected 46, is %d", + last_msg.msg.flash_program.data[186]); + ck_assert_msg(last_msg.msg.flash_program.data[187] == 194, + "incorrect value for last_msg.msg.flash_program.data[187], " + "expected 194, is %d", + last_msg.msg.flash_program.data[187]); + ck_assert_msg(last_msg.msg.flash_program.data[188] == 113, + "incorrect value for last_msg.msg.flash_program.data[188], " + "expected 113, is %d", + last_msg.msg.flash_program.data[188]); + ck_assert_msg(last_msg.msg.flash_program.data[189] == 255, + "incorrect value for last_msg.msg.flash_program.data[189], " + "expected 255, is %d", + last_msg.msg.flash_program.data[189]); + ck_assert_msg(last_msg.msg.flash_program.data[190] == 238, + "incorrect value for last_msg.msg.flash_program.data[190], " + "expected 238, is %d", + last_msg.msg.flash_program.data[190]); + ck_assert_msg(last_msg.msg.flash_program.data[191] == 15, + "incorrect value for last_msg.msg.flash_program.data[191], " + "expected 15, is %d", + last_msg.msg.flash_program.data[191]); + ck_assert_msg(last_msg.msg.flash_program.data[192] == 230, + "incorrect value for last_msg.msg.flash_program.data[192], " + "expected 230, is %d", + last_msg.msg.flash_program.data[192]); + ck_assert_msg(last_msg.msg.flash_program.data[193] == 64, + "incorrect value for last_msg.msg.flash_program.data[193], " + "expected 64, is %d", + last_msg.msg.flash_program.data[193]); + ck_assert_msg(last_msg.msg.flash_program.data[194] == 178, + "incorrect value for last_msg.msg.flash_program.data[194], " + "expected 178, is %d", + last_msg.msg.flash_program.data[194]); + ck_assert_msg(last_msg.msg.flash_program.data[195] == 127, + "incorrect value for last_msg.msg.flash_program.data[195], " + "expected 127, is %d", + last_msg.msg.flash_program.data[195]); + ck_assert_msg(last_msg.msg.flash_program.data[196] == 217, + "incorrect value for last_msg.msg.flash_program.data[196], " + "expected 217, is %d", + last_msg.msg.flash_program.data[196]); + ck_assert_msg(last_msg.msg.flash_program.data[197] == 92, + "incorrect value for last_msg.msg.flash_program.data[197], " + "expected 92, is %d", + last_msg.msg.flash_program.data[197]); + ck_assert_msg(last_msg.msg.flash_program.data[198] == 160, + "incorrect value for last_msg.msg.flash_program.data[198], " + "expected 160, is %d", + last_msg.msg.flash_program.data[198]); + ck_assert_msg(last_msg.msg.flash_program.data[199] == 201, + "incorrect value for last_msg.msg.flash_program.data[199], " + "expected 201, is %d", + last_msg.msg.flash_program.data[199]); + ck_assert_msg(last_msg.msg.flash_program.data[200] == 118, + "incorrect value for last_msg.msg.flash_program.data[200], " + "expected 118, is %d", + last_msg.msg.flash_program.data[200]); + ck_assert_msg(last_msg.msg.flash_program.data[201] == 163, + "incorrect value for last_msg.msg.flash_program.data[201], " + "expected 163, is %d", + last_msg.msg.flash_program.data[201]); + ck_assert_msg(last_msg.msg.flash_program.data[202] == 144, + "incorrect value for last_msg.msg.flash_program.data[202], " + "expected 144, is %d", + last_msg.msg.flash_program.data[202]); + ck_assert_msg(last_msg.msg.flash_program.data[203] == 58, + "incorrect value for last_msg.msg.flash_program.data[203], " + "expected 58, is %d", + last_msg.msg.flash_program.data[203]); + ck_assert_msg(last_msg.msg.flash_program.data[204] == 28, + "incorrect value for last_msg.msg.flash_program.data[204], " + "expected 28, is %d", + last_msg.msg.flash_program.data[204]); + ck_assert_msg(last_msg.msg.flash_program.data[205] == 174, + "incorrect value for last_msg.msg.flash_program.data[205], " + "expected 174, is %d", + last_msg.msg.flash_program.data[205]); + ck_assert_msg(last_msg.msg.flash_program.data[206] == 65, + "incorrect value for last_msg.msg.flash_program.data[206], " + "expected 65, is %d", + last_msg.msg.flash_program.data[206]); + ck_assert_msg(last_msg.msg.flash_program.data[207] == 73, + "incorrect value for last_msg.msg.flash_program.data[207], " + "expected 73, is %d", + last_msg.msg.flash_program.data[207]); + ck_assert_msg(last_msg.msg.flash_program.data[208] == 45, + "incorrect value for last_msg.msg.flash_program.data[208], " + "expected 45, is %d", + last_msg.msg.flash_program.data[208]); + ck_assert_msg(last_msg.msg.flash_program.data[209] == 123, + "incorrect value for last_msg.msg.flash_program.data[209], " + "expected 123, is %d", + last_msg.msg.flash_program.data[209]); + ck_assert_msg(last_msg.msg.flash_program.data[210] == 118, + "incorrect value for last_msg.msg.flash_program.data[210], " + "expected 118, is %d", + last_msg.msg.flash_program.data[210]); + ck_assert_msg(last_msg.msg.flash_program.data[211] == 83, + "incorrect value for last_msg.msg.flash_program.data[211], " + "expected 83, is %d", + last_msg.msg.flash_program.data[211]); + ck_assert_msg(last_msg.msg.flash_program.data[212] == 107, + "incorrect value for last_msg.msg.flash_program.data[212], " + "expected 107, is %d", + last_msg.msg.flash_program.data[212]); + ck_assert_msg(last_msg.msg.flash_program.data[213] == 239, + "incorrect value for last_msg.msg.flash_program.data[213], " + "expected 239, is %d", + last_msg.msg.flash_program.data[213]); + ck_assert_msg(last_msg.msg.flash_program.data[214] == 168, + "incorrect value for last_msg.msg.flash_program.data[214], " + "expected 168, is %d", + last_msg.msg.flash_program.data[214]); + ck_assert_msg(last_msg.msg.flash_program.data[215] == 32, + "incorrect value for last_msg.msg.flash_program.data[215], " + "expected 32, is %d", + last_msg.msg.flash_program.data[215]); + ck_assert_msg(last_msg.msg.flash_program.data[216] == 212, + "incorrect value for last_msg.msg.flash_program.data[216], " + "expected 212, is %d", + last_msg.msg.flash_program.data[216]); + ck_assert_msg(last_msg.msg.flash_program.data[217] == 191, + "incorrect value for last_msg.msg.flash_program.data[217], " + "expected 191, is %d", + last_msg.msg.flash_program.data[217]); + ck_assert_msg(last_msg.msg.flash_program.data[218] == 81, + "incorrect value for last_msg.msg.flash_program.data[218], " + "expected 81, is %d", + last_msg.msg.flash_program.data[218]); + ck_assert_msg(last_msg.msg.flash_program.data[219] == 93, + "incorrect value for last_msg.msg.flash_program.data[219], " + "expected 93, is %d", + last_msg.msg.flash_program.data[219]); + ck_assert_msg(last_msg.msg.flash_program.data[220] == 186, + "incorrect value for last_msg.msg.flash_program.data[220], " + "expected 186, is %d", + last_msg.msg.flash_program.data[220]); + ck_assert_msg(last_msg.msg.flash_program.data[221] == 223, + "incorrect value for last_msg.msg.flash_program.data[221], " + "expected 223, is %d", + last_msg.msg.flash_program.data[221]); + ck_assert_msg(last_msg.msg.flash_program.data[222] == 32, + "incorrect value for last_msg.msg.flash_program.data[222], " + "expected 32, is %d", + last_msg.msg.flash_program.data[222]); + ck_assert_msg(last_msg.msg.flash_program.data[223] == 19, + "incorrect value for last_msg.msg.flash_program.data[223], " + "expected 19, is %d", + last_msg.msg.flash_program.data[223]); + ck_assert_msg(last_msg.msg.flash_program.data[224] == 58, + "incorrect value for last_msg.msg.flash_program.data[224], " + "expected 58, is %d", + last_msg.msg.flash_program.data[224]); + ck_assert_msg(last_msg.msg.flash_program.data[225] == 137, + "incorrect value for last_msg.msg.flash_program.data[225], " + "expected 137, is %d", + last_msg.msg.flash_program.data[225]); + ck_assert_msg(last_msg.msg.flash_program.data[226] == 72, + "incorrect value for last_msg.msg.flash_program.data[226], " + "expected 72, is %d", + last_msg.msg.flash_program.data[226]); + ck_assert_msg(last_msg.msg.flash_program.data[227] == 217, + "incorrect value for last_msg.msg.flash_program.data[227], " + "expected 217, is %d", + last_msg.msg.flash_program.data[227]); + ck_assert_msg(last_msg.msg.flash_program.data[228] == 151, + "incorrect value for last_msg.msg.flash_program.data[228], " + "expected 151, is %d", + last_msg.msg.flash_program.data[228]); + ck_assert_msg(last_msg.msg.flash_program.data[229] == 251, + "incorrect value for last_msg.msg.flash_program.data[229], " + "expected 251, is %d", + last_msg.msg.flash_program.data[229]); + ck_assert_msg(last_msg.msg.flash_program.data[230] == 83, + "incorrect value for last_msg.msg.flash_program.data[230], " + "expected 83, is %d", + last_msg.msg.flash_program.data[230]); + ck_assert_msg(last_msg.msg.flash_program.data[231] == 20, + "incorrect value for last_msg.msg.flash_program.data[231], " + "expected 20, is %d", + last_msg.msg.flash_program.data[231]); + ck_assert_msg(last_msg.msg.flash_program.data[232] == 113, + "incorrect value for last_msg.msg.flash_program.data[232], " + "expected 113, is %d", + last_msg.msg.flash_program.data[232]); + ck_assert_msg(last_msg.msg.flash_program.data[233] == 37, + "incorrect value for last_msg.msg.flash_program.data[233], " + "expected 37, is %d", + last_msg.msg.flash_program.data[233]); + ck_assert_msg(last_msg.msg.flash_program.data[234] == 151, + "incorrect value for last_msg.msg.flash_program.data[234], " + "expected 151, is %d", + last_msg.msg.flash_program.data[234]); + ck_assert_msg(last_msg.msg.flash_program.data[235] == 34, + "incorrect value for last_msg.msg.flash_program.data[235], " + "expected 34, is %d", + last_msg.msg.flash_program.data[235]); + ck_assert_msg(last_msg.msg.flash_program.data[236] == 37, + "incorrect value for last_msg.msg.flash_program.data[236], " + "expected 37, is %d", + last_msg.msg.flash_program.data[236]); + ck_assert_msg(last_msg.msg.flash_program.data[237] == 71, + "incorrect value for last_msg.msg.flash_program.data[237], " + "expected 71, is %d", + last_msg.msg.flash_program.data[237]); + ck_assert_msg(last_msg.msg.flash_program.data[238] == 95, + "incorrect value for last_msg.msg.flash_program.data[238], " + "expected 95, is %d", + last_msg.msg.flash_program.data[238]); + ck_assert_msg(last_msg.msg.flash_program.data[239] == 105, + "incorrect value for last_msg.msg.flash_program.data[239], " + "expected 105, is %d", + last_msg.msg.flash_program.data[239]); + ck_assert_msg(last_msg.msg.flash_program.data[240] == 235, + "incorrect value for last_msg.msg.flash_program.data[240], " + "expected 235, is %d", + last_msg.msg.flash_program.data[240]); + ck_assert_msg(last_msg.msg.flash_program.data[241] == 144, + "incorrect value for last_msg.msg.flash_program.data[241], " + "expected 144, is %d", + last_msg.msg.flash_program.data[241]); + ck_assert_msg(last_msg.msg.flash_program.data[242] == 164, + "incorrect value for last_msg.msg.flash_program.data[242], " + "expected 164, is %d", + last_msg.msg.flash_program.data[242]); + ck_assert_msg(last_msg.msg.flash_program.data[243] == 83, + "incorrect value for last_msg.msg.flash_program.data[243], " + "expected 83, is %d", + last_msg.msg.flash_program.data[243]); + ck_assert_msg(last_msg.msg.flash_program.data[244] == 197, + "incorrect value for last_msg.msg.flash_program.data[244], " + "expected 197, is %d", + last_msg.msg.flash_program.data[244]); + ck_assert_msg(last_msg.msg.flash_program.data[245] == 254, + "incorrect value for last_msg.msg.flash_program.data[245], " + "expected 254, is %d", + last_msg.msg.flash_program.data[245]); + ck_assert_msg(last_msg.msg.flash_program.data[246] == 183, + "incorrect value for last_msg.msg.flash_program.data[246], " + "expected 183, is %d", + last_msg.msg.flash_program.data[246]); + ck_assert_msg(last_msg.msg.flash_program.data[247] == 223, + "incorrect value for last_msg.msg.flash_program.data[247], " + "expected 223, is %d", + last_msg.msg.flash_program.data[247]); + ck_assert_msg(last_msg.msg.flash_program.data[248] == 91, + "incorrect value for last_msg.msg.flash_program.data[248], " + "expected 91, is %d", + last_msg.msg.flash_program.data[248]); + ck_assert_msg(last_msg.msg.flash_program.data[249] == 19, + "incorrect value for last_msg.msg.flash_program.data[249], " + "expected 19, is %d", + last_msg.msg.flash_program.data[249]); + + ck_assert_msg(last_msg.msg.flash_program.target == 212, + "incorrect value for last_msg.msg.flash_program.target, " + "expected 212, is %d", + last_msg.msg.flash_program.target); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgFlashProgram_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgFlashProgram"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgFlashProgram"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgFlashProgram); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgFlashReadReq.c b/c/test/auto_check_sbp_flash_MsgFlashReadReq.c new file mode 100644 index 0000000000..f4fd6569fc --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgFlashReadReq.c @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgFlashReadReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe7, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.flash_read_req.addr_len = 71; + + test_msg.flash_read_req.addr_start[0] = 28; + + test_msg.flash_read_req.addr_start[1] = 75; + + test_msg.flash_read_req.addr_start[2] = 244; + + test_msg.flash_read_req.target = 241; + + sbp_message_send(&sbp_state, SbpMsgFlashReadReq, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFlashReadReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.flash_read_req.addr_len == 71, + "incorrect value for last_msg.msg.flash_read_req.addr_len, " + "expected 71, is %d", + last_msg.msg.flash_read_req.addr_len); + + ck_assert_msg( + last_msg.msg.flash_read_req.addr_start[0] == 28, + "incorrect value for last_msg.msg.flash_read_req.addr_start[0], " + "expected 28, is %d", + last_msg.msg.flash_read_req.addr_start[0]); + ck_assert_msg( + last_msg.msg.flash_read_req.addr_start[1] == 75, + "incorrect value for last_msg.msg.flash_read_req.addr_start[1], " + "expected 75, is %d", + last_msg.msg.flash_read_req.addr_start[1]); + ck_assert_msg( + last_msg.msg.flash_read_req.addr_start[2] == 244, + "incorrect value for last_msg.msg.flash_read_req.addr_start[2], " + "expected 244, is %d", + last_msg.msg.flash_read_req.addr_start[2]); + + ck_assert_msg(last_msg.msg.flash_read_req.target == 241, + "incorrect value for last_msg.msg.flash_read_req.target, " + "expected 241, is %d", + last_msg.msg.flash_read_req.target); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgFlashReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgFlashReadReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgFlashReadReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgFlashReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgFlashReadResp.c b/c/test/auto_check_sbp_flash_MsgFlashReadResp.c new file mode 100644 index 0000000000..df7ebd422f --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgFlashReadResp.c @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgFlashReadResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.flash_read_resp.addr_len = 124; + + test_msg.flash_read_resp.addr_start[0] = 155; + + test_msg.flash_read_resp.addr_start[1] = 52; + + test_msg.flash_read_resp.addr_start[2] = 172; + + test_msg.flash_read_resp.target = 136; + + sbp_message_send(&sbp_state, SbpMsgFlashReadResp, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFlashReadResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.flash_read_resp.addr_len == 124, + "incorrect value for last_msg.msg.flash_read_resp.addr_len, " + "expected 124, is %d", + last_msg.msg.flash_read_resp.addr_len); + + ck_assert_msg( + last_msg.msg.flash_read_resp.addr_start[0] == 155, + "incorrect value for last_msg.msg.flash_read_resp.addr_start[0], " + "expected 155, is %d", + last_msg.msg.flash_read_resp.addr_start[0]); + ck_assert_msg( + last_msg.msg.flash_read_resp.addr_start[1] == 52, + "incorrect value for last_msg.msg.flash_read_resp.addr_start[1], " + "expected 52, is %d", + last_msg.msg.flash_read_resp.addr_start[1]); + ck_assert_msg( + last_msg.msg.flash_read_resp.addr_start[2] == 172, + "incorrect value for last_msg.msg.flash_read_resp.addr_start[2], " + "expected 172, is %d", + last_msg.msg.flash_read_resp.addr_start[2]); + + ck_assert_msg(last_msg.msg.flash_read_resp.target == 136, + "incorrect value for last_msg.msg.flash_read_resp.target, " + "expected 136, is %d", + last_msg.msg.flash_read_resp.target); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgFlashReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgFlashReadResp"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgFlashReadResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgFlashReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgM25FlashWriteStatus.c b/c/test/auto_check_sbp_flash_MsgM25FlashWriteStatus.c new file mode 100644 index 0000000000..d260553d2e --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgM25FlashWriteStatus.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgM25FlashWriteStatus) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xf3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 243, 0, 195, 4, 1, 5, 112, 200, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.m25_flash_write_status.status[0] = 5; + + sbp_message_send(&sbp_state, SbpMsgM25FlashWriteStatus, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgM25FlashWriteStatus, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.m25_flash_write_status.status[0] == 5, + "incorrect value for last_msg.msg.m25_flash_write_status.status[0], " + "expected 5, is %d", + last_msg.msg.m25_flash_write_status.status[0]); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgM25FlashWriteStatus_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgM25FlashWriteStatus"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_flash_MsgM25FlashWriteStatus"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgM25FlashWriteStatus); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgStmFlashLockSector.c b/c/test/auto_check_sbp_flash_MsgStmFlashLockSector.c new file mode 100644 index 0000000000..c95dbf82c5 --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgStmFlashLockSector.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgStmFlashLockSector) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.stm_flash_lock_sector.sector = 1137047457; + + sbp_message_send(&sbp_state, SbpMsgStmFlashLockSector, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgStmFlashLockSector, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.stm_flash_lock_sector.sector == 1137047457, + "incorrect value for last_msg.msg.stm_flash_lock_sector.sector, " + "expected 1137047457, is %d", + last_msg.msg.stm_flash_lock_sector.sector); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgStmFlashLockSector_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgStmFlashLockSector"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_flash_MsgStmFlashLockSector"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgStmFlashLockSector); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgStmFlashUnlockSector.c b/c/test/auto_check_sbp_flash_MsgStmFlashUnlockSector.c new file mode 100644 index 0000000000..97e763e06d --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgStmFlashUnlockSector.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgStmFlashUnlockSector) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe4, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.stm_flash_unlock_sector.sector = 837226527; + + sbp_message_send(&sbp_state, SbpMsgStmFlashUnlockSector, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgStmFlashUnlockSector, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.stm_flash_unlock_sector.sector == 837226527, + "incorrect value for last_msg.msg.stm_flash_unlock_sector.sector, " + "expected 837226527, is %d", + last_msg.msg.stm_flash_unlock_sector.sector); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgStmFlashUnlockSector_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgStmFlashUnlockSector"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_flash_MsgStmFlashUnlockSector"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgStmFlashUnlockSector); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgStmUniqueIdReq.c b/c/test/auto_check_sbp_flash_MsgStmUniqueIdReq.c new file mode 100644 index 0000000000..aaa8c287fb --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgStmUniqueIdReq.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgStmUniqueIdReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 232, 0, 195, 4, 0, 66, 138, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgStmUniqueIdReq, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgStmUniqueIdReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgStmUniqueIdReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgStmUniqueIdReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgStmUniqueIdReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgStmUniqueIdReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_flash_MsgStmUniqueIdResp.c b/c/test/auto_check_sbp_flash_MsgStmUniqueIdResp.c new file mode 100644 index 0000000000..ec979ad43a --- /dev/null +++ b/c/test/auto_check_sbp_flash_MsgStmUniqueIdResp.c @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_flash_MsgStmUniqueIdResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xe5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, + 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.stm_unique_id_resp.stm_id[0] = 196; + + test_msg.stm_unique_id_resp.stm_id[1] = 16; + + test_msg.stm_unique_id_resp.stm_id[2] = 15; + + test_msg.stm_unique_id_resp.stm_id[3] = 163; + + test_msg.stm_unique_id_resp.stm_id[4] = 85; + + test_msg.stm_unique_id_resp.stm_id[5] = 221; + + test_msg.stm_unique_id_resp.stm_id[6] = 119; + + test_msg.stm_unique_id_resp.stm_id[7] = 102; + + test_msg.stm_unique_id_resp.stm_id[8] = 32; + + test_msg.stm_unique_id_resp.stm_id[9] = 194; + + test_msg.stm_unique_id_resp.stm_id[10] = 56; + + test_msg.stm_unique_id_resp.stm_id[11] = 144; + + sbp_message_send(&sbp_state, SbpMsgStmUniqueIdResp, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgStmUniqueIdResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[0] == 196, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[0], " + "expected 196, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[0]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[1] == 16, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[1], " + "expected 16, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[1]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[2] == 15, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[2], " + "expected 15, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[2]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[3] == 163, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[3], " + "expected 163, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[3]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[4] == 85, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[4], " + "expected 85, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[4]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[5] == 221, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[5], " + "expected 221, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[5]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[6] == 119, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[6], " + "expected 119, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[6]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[7] == 102, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[7], " + "expected 102, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[7]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[8] == 32, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[8], " + "expected 32, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[8]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[9] == 194, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[9], " + "expected 194, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[9]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[10] == 56, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[10], " + "expected 56, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[10]); + ck_assert_msg( + last_msg.msg.stm_unique_id_resp.stm_id[11] == 144, + "incorrect value for last_msg.msg.stm_unique_id_resp.stm_id[11], " + "expected 144, is %d", + last_msg.msg.stm_unique_id_resp.stm_id[11]); + } +} +END_TEST + +Suite *auto_check_sbp_flash_MsgStmUniqueIdResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_flash_MsgStmUniqueIdResp"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_flash_MsgStmUniqueIdResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_flash_MsgStmUniqueIdResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxCpuState.c b/c/test/auto_check_sbp_linux_MsgLinuxCpuState.c new file mode 100644 index 0000000000..a737b4a3d0 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxCpuState.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxCpuState) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f08, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, + 235, 20, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, 229, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_cpu_state_cmdline_set( + &test_msg.linux_cpu_state, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_cpu_state_cmdline_encoded_len( + &test_msg.linux_cpu_state) == 46, + "String not encoded properly"); + + test_msg.linux_cpu_state.flags = 20; + + test_msg.linux_cpu_state.index = 101; + + test_msg.linux_cpu_state.pcpu = 98; + + test_msg.linux_cpu_state.pid = 50042; + + test_msg.linux_cpu_state.time = 3948815319; + + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg.linux_cpu_state.tname, assign_string, + sizeof(assign_string)); + } + + sbp_message_send(&sbp_state, SbpMsgLinuxCpuState, 34196, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34196, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxCpuState, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_cpu_state_cmdline_encoded_len( + &last_msg.msg.linux_cpu_state) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_cpu_state_cmdline_get( + &last_msg.msg.linux_cpu_state), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg(last_msg.msg.linux_cpu_state.flags == 20, + "incorrect value for last_msg.msg.linux_cpu_state.flags, " + "expected 20, is %d", + last_msg.msg.linux_cpu_state.flags); + + ck_assert_msg(last_msg.msg.linux_cpu_state.index == 101, + "incorrect value for last_msg.msg.linux_cpu_state.index, " + "expected 101, is %d", + last_msg.msg.linux_cpu_state.index); + + ck_assert_msg(last_msg.msg.linux_cpu_state.pcpu == 98, + "incorrect value for last_msg.msg.linux_cpu_state.pcpu, " + "expected 98, is %d", + last_msg.msg.linux_cpu_state.pcpu); + + ck_assert_msg(last_msg.msg.linux_cpu_state.pid == 50042, + "incorrect value for last_msg.msg.linux_cpu_state.pid, " + "expected 50042, is %d", + last_msg.msg.linux_cpu_state.pid); + + ck_assert_msg(last_msg.msg.linux_cpu_state.time == 3948815319, + "incorrect value for last_msg.msg.linux_cpu_state.time, " + "expected 3948815319, is %d", + last_msg.msg.linux_cpu_state.time); + + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg(memcmp(&last_msg.msg.linux_cpu_state.tname, check_string, + sizeof(check_string)) == 0, + "incorrect value for last_msg.msg.linux_cpu_state.tname, " + "expected string '%s', is '%s'", + check_string, last_msg.msg.linux_cpu_state.tname); + } + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxCpuState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxCpuState"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxCpuState"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxCpuState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c b/c/test/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c new file mode 100644 index 0000000000..67ab2396bb --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxCpuStateDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f00, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, + 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, + 51, 32, 97, 114, 103, 52, 80, 48, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_cpu_state_dep_a_cmdline_set( + &test_msg.linux_cpu_state_dep_a, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len( + &test_msg.linux_cpu_state_dep_a) == 46, + "String not encoded properly"); + + test_msg.linux_cpu_state_dep_a.index = 51; + + test_msg.linux_cpu_state_dep_a.pcpu = 178; + + test_msg.linux_cpu_state_dep_a.pid = 64240; + + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg.linux_cpu_state_dep_a.tname, assign_string, + sizeof(assign_string)); + } + + sbp_message_send(&sbp_state, SbpMsgLinuxCpuStateDepA, 23308, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 23308, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxCpuStateDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len( + &last_msg.msg.linux_cpu_state_dep_a) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_cpu_state_dep_a_cmdline_get( + &last_msg.msg.linux_cpu_state_dep_a), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_cpu_state_dep_a.index == 51, + "incorrect value for last_msg.msg.linux_cpu_state_dep_a.index, " + "expected 51, is %d", + last_msg.msg.linux_cpu_state_dep_a.index); + + ck_assert_msg( + last_msg.msg.linux_cpu_state_dep_a.pcpu == 178, + "incorrect value for last_msg.msg.linux_cpu_state_dep_a.pcpu, expected " + "178, is %d", + last_msg.msg.linux_cpu_state_dep_a.pcpu); + + ck_assert_msg(last_msg.msg.linux_cpu_state_dep_a.pid == 64240, + "incorrect value for last_msg.msg.linux_cpu_state_dep_a.pid, " + "expected 64240, is %d", + last_msg.msg.linux_cpu_state_dep_a.pid); + + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(&last_msg.msg.linux_cpu_state_dep_a.tname, check_string, + sizeof(check_string)) == 0, + "incorrect value for last_msg.msg.linux_cpu_state_dep_a.tname, " + "expected string '%s', is '%s'", + check_string, last_msg.msg.linux_cpu_state_dep_a.tname); + } + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxCpuStateDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxCpuStateDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxCpuStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxMemState.c b/c/test/auto_check_sbp_linux_MsgLinuxMemState.c new file mode 100644 index 0000000000..d6964e8b78 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxMemState.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxMemState) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f09, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, + 187, 76, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_mem_state_cmdline_set( + &test_msg.linux_mem_state, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_mem_state_cmdline_encoded_len( + &test_msg.linux_mem_state) == 46, + "String not encoded properly"); + + test_msg.linux_mem_state.flags = 76; + + test_msg.linux_mem_state.index = 154; + + test_msg.linux_mem_state.pid = 57279; + + test_msg.linux_mem_state.pmem = 19; + + test_msg.linux_mem_state.time = 3139057143; + + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg.linux_mem_state.tname, assign_string, + sizeof(assign_string)); + } + + sbp_message_send(&sbp_state, SbpMsgLinuxMemState, 64863, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 64863, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxMemState, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_mem_state_cmdline_encoded_len( + &last_msg.msg.linux_mem_state) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_mem_state_cmdline_get( + &last_msg.msg.linux_mem_state), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg(last_msg.msg.linux_mem_state.flags == 76, + "incorrect value for last_msg.msg.linux_mem_state.flags, " + "expected 76, is %d", + last_msg.msg.linux_mem_state.flags); + + ck_assert_msg(last_msg.msg.linux_mem_state.index == 154, + "incorrect value for last_msg.msg.linux_mem_state.index, " + "expected 154, is %d", + last_msg.msg.linux_mem_state.index); + + ck_assert_msg(last_msg.msg.linux_mem_state.pid == 57279, + "incorrect value for last_msg.msg.linux_mem_state.pid, " + "expected 57279, is %d", + last_msg.msg.linux_mem_state.pid); + + ck_assert_msg(last_msg.msg.linux_mem_state.pmem == 19, + "incorrect value for last_msg.msg.linux_mem_state.pmem, " + "expected 19, is %d", + last_msg.msg.linux_mem_state.pmem); + + ck_assert_msg(last_msg.msg.linux_mem_state.time == 3139057143, + "incorrect value for last_msg.msg.linux_mem_state.time, " + "expected 3139057143, is %d", + last_msg.msg.linux_mem_state.time); + + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg(memcmp(&last_msg.msg.linux_mem_state.tname, check_string, + sizeof(check_string)) == 0, + "incorrect value for last_msg.msg.linux_mem_state.tname, " + "expected string '%s', is '%s'", + check_string, last_msg.msg.linux_mem_state.tname); + } + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxMemState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxMemState"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxMemState"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxMemState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxMemStateDepA.c b/c/test/auto_check_sbp_linux_MsgLinuxMemStateDepA.c new file mode 100644 index 0000000000..fde3af27a0 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxMemStateDepA.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxMemStateDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f01, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, + 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, + 51, 32, 97, 114, 103, 52, 17, 137, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_mem_state_dep_a_cmdline_set( + &test_msg.linux_mem_state_dep_a, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len( + &test_msg.linux_mem_state_dep_a) == 46, + "String not encoded properly"); + + test_msg.linux_mem_state_dep_a.index = 247; + + test_msg.linux_mem_state_dep_a.pid = 12381; + + test_msg.linux_mem_state_dep_a.pmem = 193; + + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg.linux_mem_state_dep_a.tname, assign_string, + sizeof(assign_string)); + } + + sbp_message_send(&sbp_state, SbpMsgLinuxMemStateDepA, 28089, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 28089, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxMemStateDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len( + &last_msg.msg.linux_mem_state_dep_a) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_mem_state_dep_a_cmdline_get( + &last_msg.msg.linux_mem_state_dep_a), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_mem_state_dep_a.index == 247, + "incorrect value for last_msg.msg.linux_mem_state_dep_a.index, " + "expected 247, is %d", + last_msg.msg.linux_mem_state_dep_a.index); + + ck_assert_msg(last_msg.msg.linux_mem_state_dep_a.pid == 12381, + "incorrect value for last_msg.msg.linux_mem_state_dep_a.pid, " + "expected 12381, is %d", + last_msg.msg.linux_mem_state_dep_a.pid); + + ck_assert_msg( + last_msg.msg.linux_mem_state_dep_a.pmem == 193, + "incorrect value for last_msg.msg.linux_mem_state_dep_a.pmem, expected " + "193, is %d", + last_msg.msg.linux_mem_state_dep_a.pmem); + + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(&last_msg.msg.linux_mem_state_dep_a.tname, check_string, + sizeof(check_string)) == 0, + "incorrect value for last_msg.msg.linux_mem_state_dep_a.tname, " + "expected string '%s', is '%s'", + check_string, last_msg.msg.linux_mem_state_dep_a.tname); + } + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxMemStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxMemStateDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxMemStateDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxMemStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxProcessFdCount.c b/c/test/auto_check_sbp_linux_MsgLinuxProcessFdCount.c new file mode 100644 index 0000000000..3c698ad006 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxProcessFdCount.c @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxProcessFdCount) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f06, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, + 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 94, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_process_fd_count_cmdline_set( + &test_msg.linux_process_fd_count, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_process_fd_count_cmdline_encoded_len( + &test_msg.linux_process_fd_count) == 46, + "String not encoded properly"); + + test_msg.linux_process_fd_count.fd_count = 35589; + + test_msg.linux_process_fd_count.index = 164; + + test_msg.linux_process_fd_count.pid = 42429; + + sbp_message_send(&sbp_state, SbpMsgLinuxProcessFdCount, 49950, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 49950, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgLinuxProcessFdCount, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_process_fd_count_cmdline_encoded_len( + &last_msg.msg.linux_process_fd_count) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_process_fd_count_cmdline_get( + &last_msg.msg.linux_process_fd_count), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_process_fd_count.fd_count == 35589, + "incorrect value for last_msg.msg.linux_process_fd_count.fd_count, " + "expected 35589, is %d", + last_msg.msg.linux_process_fd_count.fd_count); + + ck_assert_msg( + last_msg.msg.linux_process_fd_count.index == 164, + "incorrect value for last_msg.msg.linux_process_fd_count.index, " + "expected 164, is %d", + last_msg.msg.linux_process_fd_count.index); + + ck_assert_msg( + last_msg.msg.linux_process_fd_count.pid == 42429, + "incorrect value for last_msg.msg.linux_process_fd_count.pid, expected " + "42429, is %d", + last_msg.msg.linux_process_fd_count.pid); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxProcessFdCount_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxProcessFdCount"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_linux_MsgLinuxProcessFdCount"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxProcessFdCount); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c b/c/test/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c new file mode 100644 index 0000000000..8fc2ed2796 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxProcessFdSummary) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f07, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, + 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, + 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd1") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd2") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd3") == true, + "Can't assign section 2"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd4") == true, + "Can't assign section 3"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd5") == true, + "Can't assign section 4"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg.linux_process_fd_summary, "fd6") == true, + "Can't assign section 5"); + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_encoded_len( + &test_msg.linux_process_fd_summary) == 25, + "String not encoded properly"); + + test_msg.linux_process_fd_summary.sys_fd_count = 1304986387; + + sbp_message_send(&sbp_state, SbpMsgLinuxProcessFdSummary, 63591, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63591, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgLinuxProcessFdSummary, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_process_fd_summary_most_opened_encoded_len( + &last_msg.msg.linux_process_fd_summary) == 25, + "Invalid encoded len"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 0), + "fd1") == 0, + "Section 0 not decoded properly"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 1), + "fd2") == 0, + "Section 1 not decoded properly"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 2), + "fd3") == 0, + "Section 2 not decoded properly"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 3), + "fd4") == 0, + "Section 3 not decoded properly"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 4), + "fd5") == 0, + "Section 4 not decoded properly"); + ck_assert_msg( + strcmp(sbp_msg_linux_process_fd_summary_most_opened_get_section( + &last_msg.msg.linux_process_fd_summary, 5), + "fd6") == 0, + "Section 5 not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_process_fd_summary.sys_fd_count == 1304986387, + "incorrect value for " + "last_msg.msg.linux_process_fd_summary.sys_fd_count, expected " + "1304986387, is %d", + last_msg.msg.linux_process_fd_summary.sys_fd_count); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_linux_MsgLinuxProcessFdSummary"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_linux_MsgLinuxProcessFdSummary"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxProcessFdSummary); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c b/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c new file mode 100644 index 0000000000..54cba969db --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxProcessSocketCounts) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f03, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, + 114, 115, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, + 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 180, 131, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_linux_process_socket_counts_cmdline_set( + &test_msg.linux_process_socket_counts, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_process_socket_counts_cmdline_encoded_len( + &test_msg.linux_process_socket_counts) == 46, + "String not encoded properly"); + + test_msg.linux_process_socket_counts.index = 51; + + test_msg.linux_process_socket_counts.pid = 28553; + + test_msg.linux_process_socket_counts.socket_count = 30287; + + test_msg.linux_process_socket_counts.socket_states = 29554; + + test_msg.linux_process_socket_counts.socket_types = 35843; + + sbp_message_send(&sbp_state, SbpMsgLinuxProcessSocketCounts, 2412, + &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 2412, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgLinuxProcessSocketCounts, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_linux_process_socket_counts_cmdline_encoded_len( + &last_msg.msg.linux_process_socket_counts) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_process_socket_counts_cmdline_get( + &last_msg.msg.linux_process_socket_counts), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_process_socket_counts.index == 51, + "incorrect value for last_msg.msg.linux_process_socket_counts.index, " + "expected 51, is %d", + last_msg.msg.linux_process_socket_counts.index); + + ck_assert_msg( + last_msg.msg.linux_process_socket_counts.pid == 28553, + "incorrect value for last_msg.msg.linux_process_socket_counts.pid, " + "expected 28553, is %d", + last_msg.msg.linux_process_socket_counts.pid); + + ck_assert_msg( + last_msg.msg.linux_process_socket_counts.socket_count == 30287, + "incorrect value for " + "last_msg.msg.linux_process_socket_counts.socket_count, expected " + "30287, is %d", + last_msg.msg.linux_process_socket_counts.socket_count); + + ck_assert_msg( + last_msg.msg.linux_process_socket_counts.socket_states == 29554, + "incorrect value for " + "last_msg.msg.linux_process_socket_counts.socket_states, expected " + "29554, is %d", + last_msg.msg.linux_process_socket_counts.socket_states); + + ck_assert_msg( + last_msg.msg.linux_process_socket_counts.socket_types == 35843, + "incorrect value for " + "last_msg.msg.linux_process_socket_counts.socket_types, expected " + "35843, is %d", + last_msg.msg.linux_process_socket_counts.socket_types); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_linux_MsgLinuxProcessSocketCounts"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_linux_MsgLinuxProcessSocketCounts"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxProcessSocketCounts); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c b/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c new file mode 100644 index 0000000000..ee317dafa8 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxProcessSocketQueues) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f04, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, + 80, 109, 15, 223, 97, 100, 100, 114, 101, 115, 115, 32, 111, + 102, 32, 108, 97, 114, 103, 101, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, + 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, + 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, + 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 247, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + { + const char assign_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg.linux_process_socket_queues.address_of_largest, + assign_string, sizeof(assign_string)); + } + + size_t written; + ck_assert_msg( + sbp_msg_linux_process_socket_queues_cmdline_set( + &test_msg.linux_process_socket_queues, + "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written), + "Can't assign text"); + ck_assert_msg( + written == strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_linux_process_socket_queues_cmdline_encoded_len( + &test_msg.linux_process_socket_queues) == 46, + "String not encoded properly"); + + test_msg.linux_process_socket_queues.index = 181; + + test_msg.linux_process_socket_queues.pid = 19335; + + test_msg.linux_process_socket_queues.recv_queued = 54265; + + test_msg.linux_process_socket_queues.send_queued = 64547; + + test_msg.linux_process_socket_queues.socket_states = 57103; + + test_msg.linux_process_socket_queues.socket_types = 27984; + + sbp_message_send(&sbp_state, SbpMsgLinuxProcessSocketQueues, 59579, + &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 59579, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgLinuxProcessSocketQueues, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + { + const char check_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(&last_msg.msg.linux_process_socket_queues.address_of_largest, + check_string, sizeof(check_string)) == 0, + "incorrect value for " + "last_msg.msg.linux_process_socket_queues.address_of_largest, " + "expected string '%s', is '%s'", + check_string, + last_msg.msg.linux_process_socket_queues.address_of_largest); + } + + ck_assert_msg(sbp_msg_linux_process_socket_queues_cmdline_encoded_len( + &last_msg.msg.linux_process_socket_queues) == 46, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_linux_process_socket_queues_cmdline_get( + &last_msg.msg.linux_process_socket_queues), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4") == 0, + "String not decoded properly"); + + ck_assert_msg( + last_msg.msg.linux_process_socket_queues.index == 181, + "incorrect value for last_msg.msg.linux_process_socket_queues.index, " + "expected 181, is %d", + last_msg.msg.linux_process_socket_queues.index); + + ck_assert_msg( + last_msg.msg.linux_process_socket_queues.pid == 19335, + "incorrect value for last_msg.msg.linux_process_socket_queues.pid, " + "expected 19335, is %d", + last_msg.msg.linux_process_socket_queues.pid); + + ck_assert_msg(last_msg.msg.linux_process_socket_queues.recv_queued == 54265, + "incorrect value for " + "last_msg.msg.linux_process_socket_queues.recv_queued, " + "expected 54265, is %d", + last_msg.msg.linux_process_socket_queues.recv_queued); + + ck_assert_msg(last_msg.msg.linux_process_socket_queues.send_queued == 64547, + "incorrect value for " + "last_msg.msg.linux_process_socket_queues.send_queued, " + "expected 64547, is %d", + last_msg.msg.linux_process_socket_queues.send_queued); + + ck_assert_msg( + last_msg.msg.linux_process_socket_queues.socket_states == 57103, + "incorrect value for " + "last_msg.msg.linux_process_socket_queues.socket_states, expected " + "57103, is %d", + last_msg.msg.linux_process_socket_queues.socket_states); + + ck_assert_msg( + last_msg.msg.linux_process_socket_queues.socket_types == 27984, + "incorrect value for " + "last_msg.msg.linux_process_socket_queues.socket_types, expected " + "27984, is %d", + last_msg.msg.linux_process_socket_queues.socket_types); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_linux_MsgLinuxProcessSocketQueues"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_linux_MsgLinuxProcessSocketQueues"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxProcessSocketQueues); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxSocketUsage.c b/c/test/auto_check_sbp_linux_MsgLinuxSocketUsage.c new file mode 100644 index 0000000000..0936657d96 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxSocketUsage.c @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxSocketUsage) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f05, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, + 246, 154, 251, 17, 224, 179, 26, 169, 177, 90, 149, 213, 214, 6, + 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, 217, 209, 52, 14, + 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, + 176, 74, 159, 129, 154, 153, 162, 229, 130, 154, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.linux_socket_usage.avg_queue_depth = 2907030541; + + test_msg.linux_socket_usage.max_queue_depth = 3048922691; + + test_msg.linux_socket_usage.socket_state_counts[0] = 39670; + + test_msg.linux_socket_usage.socket_state_counts[1] = 4603; + + test_msg.linux_socket_usage.socket_state_counts[2] = 46048; + + test_msg.linux_socket_usage.socket_state_counts[3] = 43290; + + test_msg.linux_socket_usage.socket_state_counts[4] = 23217; + + test_msg.linux_socket_usage.socket_state_counts[5] = 54677; + + test_msg.linux_socket_usage.socket_state_counts[6] = 1750; + + test_msg.linux_socket_usage.socket_state_counts[7] = 16510; + + test_msg.linux_socket_usage.socket_state_counts[8] = 47480; + + test_msg.linux_socket_usage.socket_state_counts[9] = 33620; + + test_msg.linux_socket_usage.socket_state_counts[10] = 28616; + + test_msg.linux_socket_usage.socket_state_counts[11] = 36128; + + test_msg.linux_socket_usage.socket_state_counts[12] = 53721; + + test_msg.linux_socket_usage.socket_state_counts[13] = 3636; + + test_msg.linux_socket_usage.socket_state_counts[14] = 37822; + + test_msg.linux_socket_usage.socket_state_counts[15] = 63135; + + test_msg.linux_socket_usage.socket_type_counts[0] = 31373; + + test_msg.linux_socket_usage.socket_type_counts[1] = 30676; + + test_msg.linux_socket_usage.socket_type_counts[2] = 7811; + + test_msg.linux_socket_usage.socket_type_counts[3] = 12152; + + test_msg.linux_socket_usage.socket_type_counts[4] = 27929; + + test_msg.linux_socket_usage.socket_type_counts[5] = 16794; + + test_msg.linux_socket_usage.socket_type_counts[6] = 42116; + + test_msg.linux_socket_usage.socket_type_counts[7] = 7719; + + test_msg.linux_socket_usage.socket_type_counts[8] = 44830; + + test_msg.linux_socket_usage.socket_type_counts[9] = 11272; + + test_msg.linux_socket_usage.socket_type_counts[10] = 28444; + + test_msg.linux_socket_usage.socket_type_counts[11] = 61676; + + test_msg.linux_socket_usage.socket_type_counts[12] = 19120; + + test_msg.linux_socket_usage.socket_type_counts[13] = 33183; + + test_msg.linux_socket_usage.socket_type_counts[14] = 39322; + + test_msg.linux_socket_usage.socket_type_counts[15] = 58786; + + sbp_message_send(&sbp_state, SbpMsgLinuxSocketUsage, 35442, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 35442, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxSocketUsage, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.linux_socket_usage.avg_queue_depth == 2907030541, + "incorrect value for last_msg.msg.linux_socket_usage.avg_queue_depth, " + "expected 2907030541, is %d", + last_msg.msg.linux_socket_usage.avg_queue_depth); + + ck_assert_msg( + last_msg.msg.linux_socket_usage.max_queue_depth == 3048922691, + "incorrect value for last_msg.msg.linux_socket_usage.max_queue_depth, " + "expected 3048922691, is %d", + last_msg.msg.linux_socket_usage.max_queue_depth); + + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[0] == 39670, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[0], expected " + "39670, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[0]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[1] == 4603, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[1], expected " + "4603, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[1]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[2] == 46048, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[2], expected " + "46048, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[2]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[3] == 43290, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[3], expected " + "43290, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[3]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[4] == 23217, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[4], expected " + "23217, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[4]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[5] == 54677, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[5], expected " + "54677, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[5]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[6] == 1750, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[6], expected " + "1750, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[6]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[7] == 16510, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[7], expected " + "16510, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[7]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[8] == 47480, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[8], expected " + "47480, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[8]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[9] == 33620, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[9], expected " + "33620, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[9]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[10] == 28616, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[10], expected " + "28616, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[10]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[11] == 36128, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[11], expected " + "36128, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[11]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[12] == 53721, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[12], expected " + "53721, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[12]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[13] == 3636, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[13], expected " + "3636, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[13]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[14] == 37822, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[14], expected " + "37822, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[14]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_state_counts[15] == 63135, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_state_counts[15], expected " + "63135, is %d", + last_msg.msg.linux_socket_usage.socket_state_counts[15]); + + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[0] == 31373, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[0], expected " + "31373, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[0]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[1] == 30676, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[1], expected " + "30676, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[1]); + ck_assert_msg(last_msg.msg.linux_socket_usage.socket_type_counts[2] == 7811, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[2], " + "expected 7811, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[2]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[3] == 12152, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[3], expected " + "12152, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[3]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[4] == 27929, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[4], expected " + "27929, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[4]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[5] == 16794, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[5], expected " + "16794, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[5]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[6] == 42116, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[6], expected " + "42116, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[6]); + ck_assert_msg(last_msg.msg.linux_socket_usage.socket_type_counts[7] == 7719, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[7], " + "expected 7719, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[7]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[8] == 44830, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[8], expected " + "44830, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[8]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[9] == 11272, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[9], expected " + "11272, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[9]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[10] == 28444, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[10], expected " + "28444, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[10]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[11] == 61676, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[11], expected " + "61676, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[11]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[12] == 19120, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[12], expected " + "19120, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[12]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[13] == 33183, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[13], expected " + "33183, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[13]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[14] == 39322, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[14], expected " + "39322, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[14]); + ck_assert_msg( + last_msg.msg.linux_socket_usage.socket_type_counts[15] == 58786, + "incorrect value for " + "last_msg.msg.linux_socket_usage.socket_type_counts[15], expected " + "58786, is %d", + last_msg.msg.linux_socket_usage.socket_type_counts[15]); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxSocketUsage_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxSocketUsage"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxSocketUsage"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxSocketUsage); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxSysState.c b/c/test/auto_check_sbp_linux_MsgLinuxSysState.c new file mode 100644 index 0000000000..2f736fa715 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxSysState.c @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxSysState) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f0a, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, + 161, 229, 250, 186, 108, 30, 106, 5, 9, 229, 242, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.linux_sys_state.flags = 9; + + test_msg.linux_sys_state.mem_total = 53012; + + test_msg.linux_sys_state.pcpu = 125; + + test_msg.linux_sys_state.pid_count = 47866; + + test_msg.linux_sys_state.pmem = 215; + + test_msg.linux_sys_state.procs_starting = 18372; + + test_msg.linux_sys_state.procs_stopping = 58785; + + test_msg.linux_sys_state.time = 90840684; + + sbp_message_send(&sbp_state, SbpMsgLinuxSysState, 42837, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 42837, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxSysState, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.linux_sys_state.flags == 9, + "incorrect value for last_msg.msg.linux_sys_state.flags, " + "expected 9, is %d", + last_msg.msg.linux_sys_state.flags); + + ck_assert_msg(last_msg.msg.linux_sys_state.mem_total == 53012, + "incorrect value for last_msg.msg.linux_sys_state.mem_total, " + "expected 53012, is %d", + last_msg.msg.linux_sys_state.mem_total); + + ck_assert_msg(last_msg.msg.linux_sys_state.pcpu == 125, + "incorrect value for last_msg.msg.linux_sys_state.pcpu, " + "expected 125, is %d", + last_msg.msg.linux_sys_state.pcpu); + + ck_assert_msg(last_msg.msg.linux_sys_state.pid_count == 47866, + "incorrect value for last_msg.msg.linux_sys_state.pid_count, " + "expected 47866, is %d", + last_msg.msg.linux_sys_state.pid_count); + + ck_assert_msg(last_msg.msg.linux_sys_state.pmem == 215, + "incorrect value for last_msg.msg.linux_sys_state.pmem, " + "expected 215, is %d", + last_msg.msg.linux_sys_state.pmem); + + ck_assert_msg( + last_msg.msg.linux_sys_state.procs_starting == 18372, + "incorrect value for last_msg.msg.linux_sys_state.procs_starting, " + "expected 18372, is %d", + last_msg.msg.linux_sys_state.procs_starting); + + ck_assert_msg( + last_msg.msg.linux_sys_state.procs_stopping == 58785, + "incorrect value for last_msg.msg.linux_sys_state.procs_stopping, " + "expected 58785, is %d", + last_msg.msg.linux_sys_state.procs_stopping); + + ck_assert_msg(last_msg.msg.linux_sys_state.time == 90840684, + "incorrect value for last_msg.msg.linux_sys_state.time, " + "expected 90840684, is %d", + last_msg.msg.linux_sys_state.time); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxSysState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxSysState"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxSysState"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxSysState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_linux_MsgLinuxSysStateDepA.c b/c/test/auto_check_sbp_linux_MsgLinuxSysStateDepA.c new file mode 100644 index 0000000000..d04d8183c8 --- /dev/null +++ b/c/test/auto_check_sbp_linux_MsgLinuxSysStateDepA.c @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_linux_MsgLinuxSysStateDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x7f02, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 2, 127, 84, 56, 10, 188, 163, 211, + 194, 115, 71, 101, 103, 124, 201, 223, 223, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.linux_sys_state_dep_a.mem_total = 41916; + + test_msg.linux_sys_state_dep_a.pcpu = 211; + + test_msg.linux_sys_state_dep_a.pid_count = 51580; + + test_msg.linux_sys_state_dep_a.pmem = 194; + + test_msg.linux_sys_state_dep_a.procs_starting = 18291; + + test_msg.linux_sys_state_dep_a.procs_stopping = 26469; + + sbp_message_send(&sbp_state, SbpMsgLinuxSysStateDepA, 14420, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14420, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgLinuxSysStateDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.linux_sys_state_dep_a.mem_total == 41916, + "incorrect value for last_msg.msg.linux_sys_state_dep_a.mem_total, " + "expected 41916, is %d", + last_msg.msg.linux_sys_state_dep_a.mem_total); + + ck_assert_msg( + last_msg.msg.linux_sys_state_dep_a.pcpu == 211, + "incorrect value for last_msg.msg.linux_sys_state_dep_a.pcpu, expected " + "211, is %d", + last_msg.msg.linux_sys_state_dep_a.pcpu); + + ck_assert_msg( + last_msg.msg.linux_sys_state_dep_a.pid_count == 51580, + "incorrect value for last_msg.msg.linux_sys_state_dep_a.pid_count, " + "expected 51580, is %d", + last_msg.msg.linux_sys_state_dep_a.pid_count); + + ck_assert_msg( + last_msg.msg.linux_sys_state_dep_a.pmem == 194, + "incorrect value for last_msg.msg.linux_sys_state_dep_a.pmem, expected " + "194, is %d", + last_msg.msg.linux_sys_state_dep_a.pmem); + + ck_assert_msg(last_msg.msg.linux_sys_state_dep_a.procs_starting == 18291, + "incorrect value for " + "last_msg.msg.linux_sys_state_dep_a.procs_starting, expected " + "18291, is %d", + last_msg.msg.linux_sys_state_dep_a.procs_starting); + + ck_assert_msg(last_msg.msg.linux_sys_state_dep_a.procs_stopping == 26469, + "incorrect value for " + "last_msg.msg.linux_sys_state_dep_a.procs_stopping, expected " + "26469, is %d", + last_msg.msg.linux_sys_state_dep_a.procs_stopping); + } +} +END_TEST + +Suite *auto_check_sbp_linux_MsgLinuxSysStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_linux_MsgLinuxSysStateDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_linux_MsgLinuxSysStateDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_linux_MsgLinuxSysStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_mag_MsgMagRaw.c b/c/test/auto_check_sbp_mag_MsgMagRaw.c new file mode 100644 index 0000000000..562a10f34e --- /dev/null +++ b/c/test/auto_check_sbp_mag_MsgMagRaw.c @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_mag_MsgMagRaw) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x902, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, + 206, 98, 3, 230, 2, 110, 229, 159, 23, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.mag_raw.mag_x = 866; + + test_msg.mag_raw.mag_y = 742; + + test_msg.mag_raw.mag_z = -6802; + + test_msg.mag_raw.tow = 3332301741; + + test_msg.mag_raw.tow_f = 206; + + sbp_message_send(&sbp_state, SbpMsgMagRaw, 1219, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgMagRaw, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.mag_raw.mag_x == 866, + "incorrect value for last_msg.msg.mag_raw.mag_x, expected 866, is %d", + last_msg.msg.mag_raw.mag_x); + + ck_assert_msg( + last_msg.msg.mag_raw.mag_y == 742, + "incorrect value for last_msg.msg.mag_raw.mag_y, expected 742, is %d", + last_msg.msg.mag_raw.mag_y); + + ck_assert_msg( + last_msg.msg.mag_raw.mag_z == -6802, + "incorrect value for last_msg.msg.mag_raw.mag_z, expected -6802, is %d", + last_msg.msg.mag_raw.mag_z); + + ck_assert_msg(last_msg.msg.mag_raw.tow == 3332301741, + "incorrect value for last_msg.msg.mag_raw.tow, expected " + "3332301741, is %d", + last_msg.msg.mag_raw.tow); + + ck_assert_msg( + last_msg.msg.mag_raw.tow_f == 206, + "incorrect value for last_msg.msg.mag_raw.tow_f, expected 206, is %d", + last_msg.msg.mag_raw.tow_f); + } +} +END_TEST + +Suite *auto_check_sbp_mag_MsgMagRaw_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_mag_MsgMagRaw"); + TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_mag_MsgMagRaw"); + tcase_add_test(tc_acq, test_auto_check_sbp_mag_MsgMagRaw); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c b/c/test/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c new file mode 100644 index 0000000000..ed35ced76c --- /dev/null +++ b/c/test/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_navigation_MsgBaselineHeadingDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x207, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 7, 2, 124, 206, 10, 82, 109, 88, + 176, 68, 14, 82, 203, 186, 58, 173, 182, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.baseline_heading_dep_a.flags = 58; + + test_msg.baseline_heading_dep_a.heading = 3411152452; + + test_msg.baseline_heading_dep_a.n_sats = 186; + + test_msg.baseline_heading_dep_a.tow = 2958585170; + + sbp_message_send(&sbp_state, SbpMsgBaselineHeadingDepA, 52860, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52860, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgBaselineHeadingDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.baseline_heading_dep_a.flags == 58, + "incorrect value for last_msg.msg.baseline_heading_dep_a.flags, " + "expected 58, is %d", + last_msg.msg.baseline_heading_dep_a.flags); + + ck_assert_msg( + last_msg.msg.baseline_heading_dep_a.heading == 3411152452, + "incorrect value for last_msg.msg.baseline_heading_dep_a.heading, " + "expected 3411152452, is %d", + last_msg.msg.baseline_heading_dep_a.heading); + + ck_assert_msg( + last_msg.msg.baseline_heading_dep_a.n_sats == 186, + "incorrect value for last_msg.msg.baseline_heading_dep_a.n_sats, " + "expected 186, is %d", + last_msg.msg.baseline_heading_dep_a.n_sats); + + ck_assert_msg( + last_msg.msg.baseline_heading_dep_a.tow == 2958585170, + "incorrect value for last_msg.msg.baseline_heading_dep_a.tow, expected " + "2958585170, is %d", + last_msg.msg.baseline_heading_dep_a.tow); + } +} +END_TEST + +Suite *auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_navigation_MsgBaselineHeadingDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_navigation_MsgBaselineHeadingDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_navigation_MsgBaselineHeadingDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_navigation_MsgPosLlhAcc.c b/c/test/auto_check_sbp_navigation_MsgPosLlhAcc.c new file mode 100644 index 0000000000..3813b3c5d6 --- /dev/null +++ b/c/test/auto_check_sbp_navigation_MsgPosLlhAcc.c @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_navigation_MsgPosLlhAcc) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x218, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, + 51, 51, 139, 189, 64, 154, 153, 153, 153, 25, 151, 192, 64, + 51, 51, 51, 51, 51, 161, 176, 64, 51, 51, 51, 51, 51, + 101, 179, 64, 51, 163, 22, 69, 154, 25, 173, 69, 102, 134, + 243, 68, 154, 201, 196, 69, 205, 224, 0, 70, 51, 35, 72, + 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.pos_llh_acc.at_accuracy = 6297.2001953125; + + test_msg.pos_llh_acc.confidence_and_geoid = 95; + + test_msg.pos_llh_acc.ct_accuracy = 1948.199951171875; + + test_msg.pos_llh_acc.flags = 72; + + test_msg.pos_llh_acc.h_accuracy = 2410.199951171875; + + test_msg.pos_llh_acc.h_ellipse.orientation = 2550.199951171875; + + test_msg.pos_llh_acc.h_ellipse.semi_major = 8248.2001953125; + + test_msg.pos_llh_acc.h_ellipse.semi_minor = 3202.199951171875; + + test_msg.pos_llh_acc.height = 4257.2; + + test_msg.pos_llh_acc.lat = 7563.2; + + test_msg.pos_llh_acc.lon = 8494.2; + + test_msg.pos_llh_acc.n_sats = 27; + + test_msg.pos_llh_acc.orthometric_height = 4965.2; + + test_msg.pos_llh_acc.tow = 309229607; + + test_msg.pos_llh_acc.v_accuracy = 5539.2001953125; + + sbp_message_send(&sbp_state, SbpMsgPosLlhAcc, 7170, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 7170, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgPosLlhAcc, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.pos_llh_acc.at_accuracy * 100 - + 6297.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.at_accuracy, " + "expected 6297.20019531, is %s", + last_msg.msg.pos_llh_acc.at_accuracy); + + ck_assert_msg( + last_msg.msg.pos_llh_acc.confidence_and_geoid == 95, + "incorrect value for last_msg.msg.pos_llh_acc.confidence_and_geoid, " + "expected 95, is %d", + last_msg.msg.pos_llh_acc.confidence_and_geoid); + + ck_assert_msg((last_msg.msg.pos_llh_acc.ct_accuracy * 100 - + 1948.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.ct_accuracy, " + "expected 1948.19995117, is %s", + last_msg.msg.pos_llh_acc.ct_accuracy); + + ck_assert_msg(last_msg.msg.pos_llh_acc.flags == 72, + "incorrect value for last_msg.msg.pos_llh_acc.flags, " + "expected 72, is %d", + last_msg.msg.pos_llh_acc.flags); + + ck_assert_msg((last_msg.msg.pos_llh_acc.h_accuracy * 100 - + 2410.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.h_accuracy, " + "expected 2410.19995117, is %s", + last_msg.msg.pos_llh_acc.h_accuracy); + + ck_assert_msg( + (last_msg.msg.pos_llh_acc.h_ellipse.orientation * 100 - + 2550.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.h_ellipse.orientation, " + "expected 2550.19995117, is %s", + last_msg.msg.pos_llh_acc.h_ellipse.orientation); + + ck_assert_msg( + (last_msg.msg.pos_llh_acc.h_ellipse.semi_major * 100 - + 8248.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.h_ellipse.semi_major, " + "expected 8248.20019531, is %s", + last_msg.msg.pos_llh_acc.h_ellipse.semi_major); + + ck_assert_msg( + (last_msg.msg.pos_llh_acc.h_ellipse.semi_minor * 100 - + 3202.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.h_ellipse.semi_minor, " + "expected 3202.19995117, is %s", + last_msg.msg.pos_llh_acc.h_ellipse.semi_minor); + + ck_assert_msg((last_msg.msg.pos_llh_acc.height * 100 - 4257.2 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.height, " + "expected 4257.2, is %s", + last_msg.msg.pos_llh_acc.height); + + ck_assert_msg((last_msg.msg.pos_llh_acc.lat * 100 - 7563.2 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.lat, expected " + "7563.2, is %s", + last_msg.msg.pos_llh_acc.lat); + + ck_assert_msg((last_msg.msg.pos_llh_acc.lon * 100 - 8494.2 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.lon, expected " + "8494.2, is %s", + last_msg.msg.pos_llh_acc.lon); + + ck_assert_msg(last_msg.msg.pos_llh_acc.n_sats == 27, + "incorrect value for last_msg.msg.pos_llh_acc.n_sats, " + "expected 27, is %d", + last_msg.msg.pos_llh_acc.n_sats); + + ck_assert_msg( + (last_msg.msg.pos_llh_acc.orthometric_height * 100 - 4965.2 * 100) < + 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.orthometric_height, " + "expected 4965.2, is %s", + last_msg.msg.pos_llh_acc.orthometric_height); + + ck_assert_msg(last_msg.msg.pos_llh_acc.tow == 309229607, + "incorrect value for last_msg.msg.pos_llh_acc.tow, expected " + "309229607, is %d", + last_msg.msg.pos_llh_acc.tow); + + ck_assert_msg((last_msg.msg.pos_llh_acc.v_accuracy * 100 - + 5539.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.pos_llh_acc.v_accuracy, " + "expected 5539.20019531, is %s", + last_msg.msg.pos_llh_acc.v_accuracy); + } +} +END_TEST + +Suite *auto_check_sbp_navigation_MsgPosLlhAcc_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_navigation_MsgPosLlhAcc"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_navigation_MsgPosLlhAcc"); + tcase_add_test(tc_acq, test_auto_check_sbp_navigation_MsgPosLlhAcc); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_navigation_MsgProtectionLevel.c b/c/test/auto_check_sbp_navigation_MsgProtectionLevel.c index dfa5c8a458..2c89e103f6 100644 --- a/c/test/auto_check_sbp_navigation_MsgProtectionLevel.c +++ b/c/test/auto_check_sbp_navigation_MsgProtectionLevel.c @@ -90,13 +90,16 @@ START_TEST(test_auto_check_sbp_navigation_MsgProtectionLevel) { logging_reset(); - sbp_callback_register(&sbp_state, 0x216, &msg_callback, + sbp_callback_register(&sbp_state, 0x217, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); u8 encoded_frame[] = { - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, + 89, 84, 167, 41, 57, 21, 217, 244, 61, 161, 83, 104, 140, 137, + 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, 153, 153, + 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, + 38, 221, 208, 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, + 235, 227, 183, 160, 187, 93, 116, 224, 105, 40, 32, 33, 133, 188, }; dummy_reset(); @@ -104,21 +107,49 @@ START_TEST(test_auto_check_sbp_navigation_MsgProtectionLevel) { sbp_msg_t test_msg; memset(&test_msg, 0, sizeof(test_msg)); - test_msg.protection_level_dep_a.flags = 0; + test_msg.protection_level.atpl = 10663; - test_msg.protection_level_dep_a.height = 0.0; + test_msg.protection_level.ctpl = 5433; - test_msg.protection_level_dep_a.hpl = 0; + test_msg.protection_level.flags = 555755625; - test_msg.protection_level_dep_a.lat = 0.0; + test_msg.protection_level.heading = -529244741; - test_msg.protection_level_dep_a.lon = 0.0; + test_msg.protection_level.height = 412.2; - test_msg.protection_level_dep_a.tow = 501867400; + test_msg.protection_level.hopl = 26707; - test_msg.protection_level_dep_a.vpl = 0; + test_msg.protection_level.hpl = 41013; - sbp_message_send(&sbp_state, SbpMsgProtectionLevelDepA, 4096, &test_msg, + test_msg.protection_level.hvpl = 62681; + + test_msg.protection_level.lat = 5290.2; + + test_msg.protection_level.lon = 9904.2; + + test_msg.protection_level.pitch = -1598561301; + + test_msg.protection_level.popl = 35212; + + test_msg.protection_level.roll = 1018834477; + + test_msg.protection_level.ropl = 63066; + + test_msg.protection_level.tow = 4060370030; + + test_msg.protection_level.v_x = -584647705; + + test_msg.protection_level.v_y = 1353168848; + + test_msg.protection_level.v_z = -1537140001; + + test_msg.protection_level.vpl = 21593; + + test_msg.protection_level.vvpl = 41277; + + test_msg.protection_level.wn = 13102; + + sbp_message_send(&sbp_state, SbpMsgProtectionLevel, 813, &test_msg, &dummy_write); ck_assert_msg(dummy_wr == sizeof(encoded_frame), @@ -135,52 +166,120 @@ START_TEST(test_auto_check_sbp_navigation_MsgProtectionLevel) { ck_assert_msg(last_msg.n_callbacks_logged == 1, "msg_callback: one callback should have been logged"); - ck_assert_msg(last_msg.sender_id == 4096, + ck_assert_msg(last_msg.sender_id == 813, "msg_callback: sender_id decoded incorrectly"); - ck_assert_msg(sbp_message_cmp(SbpMsgProtectionLevelDepA, &last_msg.msg, - &test_msg) == 0, - "Sent and received messages did not compare equal"); - ck_assert_msg( - last_msg.msg.protection_level_dep_a.flags == 0, - "incorrect value for last_msg.msg.protection_level_dep_a.flags, " - "expected 0, is %d", - last_msg.msg.protection_level_dep_a.flags); + sbp_message_cmp(SbpMsgProtectionLevel, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); - ck_assert_msg( - (last_msg.msg.protection_level_dep_a.height * 100 - 0.0 * 100) < 0.05, - "incorrect value for last_msg.msg.protection_level_dep_a.height, " - "expected 0.0, is %s", - last_msg.msg.protection_level_dep_a.height); + ck_assert_msg(last_msg.msg.protection_level.atpl == 10663, + "incorrect value for last_msg.msg.protection_level.atpl, " + "expected 10663, is %d", + last_msg.msg.protection_level.atpl); + + ck_assert_msg(last_msg.msg.protection_level.ctpl == 5433, + "incorrect value for last_msg.msg.protection_level.ctpl, " + "expected 5433, is %d", + last_msg.msg.protection_level.ctpl); + + ck_assert_msg(last_msg.msg.protection_level.flags == 555755625, + "incorrect value for last_msg.msg.protection_level.flags, " + "expected 555755625, is %d", + last_msg.msg.protection_level.flags); - ck_assert_msg(last_msg.msg.protection_level_dep_a.hpl == 0, - "incorrect value for " - "last_msg.msg.protection_level_dep_a.hpl, expected 0, is %d", - last_msg.msg.protection_level_dep_a.hpl); + ck_assert_msg(last_msg.msg.protection_level.heading == -529244741, + "incorrect value for last_msg.msg.protection_level.heading, " + "expected -529244741, is %d", + last_msg.msg.protection_level.heading); ck_assert_msg( - (last_msg.msg.protection_level_dep_a.lat * 100 - 0.0 * 100) < 0.05, - "incorrect value for last_msg.msg.protection_level_dep_a.lat, expected " - "0.0, is %s", - last_msg.msg.protection_level_dep_a.lat); + (last_msg.msg.protection_level.height * 100 - 412.2 * 100) < 0.05, + "incorrect value for last_msg.msg.protection_level.height, expected " + "412.2, is %s", + last_msg.msg.protection_level.height); + + ck_assert_msg(last_msg.msg.protection_level.hopl == 26707, + "incorrect value for last_msg.msg.protection_level.hopl, " + "expected 26707, is %d", + last_msg.msg.protection_level.hopl); + + ck_assert_msg(last_msg.msg.protection_level.hpl == 41013, + "incorrect value for last_msg.msg.protection_level.hpl, " + "expected 41013, is %d", + last_msg.msg.protection_level.hpl); + + ck_assert_msg(last_msg.msg.protection_level.hvpl == 62681, + "incorrect value for last_msg.msg.protection_level.hvpl, " + "expected 62681, is %d", + last_msg.msg.protection_level.hvpl); ck_assert_msg( - (last_msg.msg.protection_level_dep_a.lon * 100 - 0.0 * 100) < 0.05, - "incorrect value for last_msg.msg.protection_level_dep_a.lon, expected " - "0.0, is %s", - last_msg.msg.protection_level_dep_a.lon); + (last_msg.msg.protection_level.lat * 100 - 5290.2 * 100) < 0.05, + "incorrect value for last_msg.msg.protection_level.lat, expected " + "5290.2, is %s", + last_msg.msg.protection_level.lat); ck_assert_msg( - last_msg.msg.protection_level_dep_a.tow == 501867400, - "incorrect value for last_msg.msg.protection_level_dep_a.tow, expected " - "501867400, is %d", - last_msg.msg.protection_level_dep_a.tow); - - ck_assert_msg(last_msg.msg.protection_level_dep_a.vpl == 0, - "incorrect value for " - "last_msg.msg.protection_level_dep_a.vpl, expected 0, is %d", - last_msg.msg.protection_level_dep_a.vpl); + (last_msg.msg.protection_level.lon * 100 - 9904.2 * 100) < 0.05, + "incorrect value for last_msg.msg.protection_level.lon, expected " + "9904.2, is %s", + last_msg.msg.protection_level.lon); + + ck_assert_msg(last_msg.msg.protection_level.pitch == -1598561301, + "incorrect value for last_msg.msg.protection_level.pitch, " + "expected -1598561301, is %d", + last_msg.msg.protection_level.pitch); + + ck_assert_msg(last_msg.msg.protection_level.popl == 35212, + "incorrect value for last_msg.msg.protection_level.popl, " + "expected 35212, is %d", + last_msg.msg.protection_level.popl); + + ck_assert_msg(last_msg.msg.protection_level.roll == 1018834477, + "incorrect value for last_msg.msg.protection_level.roll, " + "expected 1018834477, is %d", + last_msg.msg.protection_level.roll); + + ck_assert_msg(last_msg.msg.protection_level.ropl == 63066, + "incorrect value for last_msg.msg.protection_level.ropl, " + "expected 63066, is %d", + last_msg.msg.protection_level.ropl); + + ck_assert_msg(last_msg.msg.protection_level.tow == 4060370030, + "incorrect value for last_msg.msg.protection_level.tow, " + "expected 4060370030, is %d", + last_msg.msg.protection_level.tow); + + ck_assert_msg(last_msg.msg.protection_level.v_x == -584647705, + "incorrect value for last_msg.msg.protection_level.v_x, " + "expected -584647705, is %d", + last_msg.msg.protection_level.v_x); + + ck_assert_msg(last_msg.msg.protection_level.v_y == 1353168848, + "incorrect value for last_msg.msg.protection_level.v_y, " + "expected 1353168848, is %d", + last_msg.msg.protection_level.v_y); + + ck_assert_msg(last_msg.msg.protection_level.v_z == -1537140001, + "incorrect value for last_msg.msg.protection_level.v_z, " + "expected -1537140001, is %d", + last_msg.msg.protection_level.v_z); + + ck_assert_msg(last_msg.msg.protection_level.vpl == 21593, + "incorrect value for last_msg.msg.protection_level.vpl, " + "expected 21593, is %d", + last_msg.msg.protection_level.vpl); + + ck_assert_msg(last_msg.msg.protection_level.vvpl == 41277, + "incorrect value for last_msg.msg.protection_level.vvpl, " + "expected 41277, is %d", + last_msg.msg.protection_level.vvpl); + + ck_assert_msg(last_msg.msg.protection_level.wn == 13102, + "incorrect value for last_msg.msg.protection_level.wn, " + "expected 13102, is %d", + last_msg.msg.protection_level.wn); } } END_TEST diff --git a/c/test/auto_check_sbp_navigation_MsgProtectionLevelDepA.c b/c/test/auto_check_sbp_navigation_MsgProtectionLevelDepA.c new file mode 100644 index 0000000000..203fd44f75 --- /dev/null +++ b/c/test/auto_check_sbp_navigation_MsgProtectionLevelDepA.c @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_navigation_MsgProtectionLevelDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x216, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, + 51, 51, 51, 51, 51, 244, 190, 64, 102, 102, 102, 102, 102, 204, + 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, 81, 104, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.protection_level_dep_a.flags = 248; + + test_msg.protection_level_dep_a.height = 8270.2; + + test_msg.protection_level_dep_a.hpl = 35588; + + test_msg.protection_level_dep_a.lat = 7924.2; + + test_msg.protection_level_dep_a.lon = 3174.2; + + test_msg.protection_level_dep_a.tow = 3108339252; + + test_msg.protection_level_dep_a.vpl = 21807; + + sbp_message_send(&sbp_state, SbpMsgProtectionLevelDepA, 5780, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 5780, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgProtectionLevelDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.protection_level_dep_a.flags == 248, + "incorrect value for last_msg.msg.protection_level_dep_a.flags, " + "expected 248, is %d", + last_msg.msg.protection_level_dep_a.flags); + + ck_assert_msg( + (last_msg.msg.protection_level_dep_a.height * 100 - 8270.2 * 100) < + 0.05, + "incorrect value for last_msg.msg.protection_level_dep_a.height, " + "expected 8270.2, is %s", + last_msg.msg.protection_level_dep_a.height); + + ck_assert_msg( + last_msg.msg.protection_level_dep_a.hpl == 35588, + "incorrect value for last_msg.msg.protection_level_dep_a.hpl, expected " + "35588, is %d", + last_msg.msg.protection_level_dep_a.hpl); + + ck_assert_msg( + (last_msg.msg.protection_level_dep_a.lat * 100 - 7924.2 * 100) < 0.05, + "incorrect value for last_msg.msg.protection_level_dep_a.lat, expected " + "7924.2, is %s", + last_msg.msg.protection_level_dep_a.lat); + + ck_assert_msg( + (last_msg.msg.protection_level_dep_a.lon * 100 - 3174.2 * 100) < 0.05, + "incorrect value for last_msg.msg.protection_level_dep_a.lon, expected " + "3174.2, is %s", + last_msg.msg.protection_level_dep_a.lon); + + ck_assert_msg( + last_msg.msg.protection_level_dep_a.tow == 3108339252, + "incorrect value for last_msg.msg.protection_level_dep_a.tow, expected " + "3108339252, is %d", + last_msg.msg.protection_level_dep_a.tow); + + ck_assert_msg( + last_msg.msg.protection_level_dep_a.vpl == 21807, + "incorrect value for last_msg.msg.protection_level_dep_a.vpl, expected " + "21807, is %d", + last_msg.msg.protection_level_dep_a.vpl); + } +} +END_TEST + +Suite *auto_check_sbp_navigation_MsgProtectionLevelDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_navigation_MsgProtectionLevelDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_navigation_MsgProtectionLevelDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_navigation_MsgProtectionLevelDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ndb_MsgNdbEvent.c b/c/test/auto_check_sbp_ndb_MsgNdbEvent.c new file mode 100644 index 0000000000..c38c677326 --- /dev/null +++ b/c/test/auto_check_sbp_ndb_MsgNdbEvent.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ndb_MsgNdbEvent) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x400, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, + 0, 249, 73, 205, 115, 238, 74, 98, 66, 182, 148, 16, 166, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ndb_event.data_source = 115; + + test_msg.ndb_event.event = 249; + + test_msg.ndb_event.object_sid.code = 74; + + test_msg.ndb_event.object_sid.sat = 238; + + test_msg.ndb_event.object_type = 73; + + test_msg.ndb_event.original_sender = 38070; + + test_msg.ndb_event.recv_time = 299461164286; + + test_msg.ndb_event.result = 205; + + test_msg.ndb_event.src_sid.code = 66; + + test_msg.ndb_event.src_sid.sat = 98; + + sbp_message_send(&sbp_state, SbpMsgNdbEvent, 44708, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 44708, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgNdbEvent, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.ndb_event.data_source == 115, + "incorrect value for last_msg.msg.ndb_event.data_source, " + "expected 115, is %d", + last_msg.msg.ndb_event.data_source); + + ck_assert_msg( + last_msg.msg.ndb_event.event == 249, + "incorrect value for last_msg.msg.ndb_event.event, expected 249, is %d", + last_msg.msg.ndb_event.event); + + ck_assert_msg(last_msg.msg.ndb_event.object_sid.code == 74, + "incorrect value for last_msg.msg.ndb_event.object_sid.code, " + "expected 74, is %d", + last_msg.msg.ndb_event.object_sid.code); + + ck_assert_msg(last_msg.msg.ndb_event.object_sid.sat == 238, + "incorrect value for last_msg.msg.ndb_event.object_sid.sat, " + "expected 238, is %d", + last_msg.msg.ndb_event.object_sid.sat); + + ck_assert_msg(last_msg.msg.ndb_event.object_type == 73, + "incorrect value for last_msg.msg.ndb_event.object_type, " + "expected 73, is %d", + last_msg.msg.ndb_event.object_type); + + ck_assert_msg(last_msg.msg.ndb_event.original_sender == 38070, + "incorrect value for last_msg.msg.ndb_event.original_sender, " + "expected 38070, is %d", + last_msg.msg.ndb_event.original_sender); + + ck_assert_msg(last_msg.msg.ndb_event.recv_time == 299461164286, + "incorrect value for last_msg.msg.ndb_event.recv_time, " + "expected 299461164286, is %d", + last_msg.msg.ndb_event.recv_time); + + ck_assert_msg(last_msg.msg.ndb_event.result == 205, + "incorrect value for last_msg.msg.ndb_event.result, expected " + "205, is %d", + last_msg.msg.ndb_event.result); + + ck_assert_msg(last_msg.msg.ndb_event.src_sid.code == 66, + "incorrect value for last_msg.msg.ndb_event.src_sid.code, " + "expected 66, is %d", + last_msg.msg.ndb_event.src_sid.code); + + ck_assert_msg(last_msg.msg.ndb_event.src_sid.sat == 98, + "incorrect value for last_msg.msg.ndb_event.src_sid.sat, " + "expected 98, is %d", + last_msg.msg.ndb_event.src_sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_ndb_MsgNdbEvent_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_ndb_MsgNdbEvent"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ndb_MsgNdbEvent"); + tcase_add_test(tc_acq, test_auto_check_sbp_ndb_MsgNdbEvent); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgAlmanacGLO.c b/c/test/auto_check_sbp_observation_MsgAlmanacGLO.c new file mode 100644 index 0000000000..03f6e8444e --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgAlmanacGLO.c @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgAlmanacGLO) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x73, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, + 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, + 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, + 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 155, 87, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.almanac_glo.common.fit_interval = 14400; + + test_msg.almanac_glo.common.health_bits = 0; + + test_msg.almanac_glo.common.sid.code = 0; + + test_msg.almanac_glo.common.sid.sat = 22; + + test_msg.almanac_glo.common.toa.tow = 446384; + + test_msg.almanac_glo.common.toa.wn = 2154; + + test_msg.almanac_glo.common.ura = 2.2; + + test_msg.almanac_glo.common.valid = 1; + + test_msg.almanac_glo.epsilon = -0.9893036629599647; + + test_msg.almanac_glo.i = 5153.550029754639; + + test_msg.almanac_glo.lambda_na = -0.02200078842114688; + + test_msg.almanac_glo.omega = 0.9341514480259797; + + test_msg.almanac_glo.t = -1.8731818448797617; + + test_msg.almanac_glo.t_dot = -8.903585155774196e-09; + + test_msg.almanac_glo.t_lambda_na = 0.007072207052260637; + + sbp_message_send(&sbp_state, SbpMsgAlmanacGlo, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAlmanacGlo, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.almanac_glo.common.fit_interval == 14400, + "incorrect value for last_msg.msg.almanac_glo.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.almanac_glo.common.fit_interval); + + ck_assert_msg( + last_msg.msg.almanac_glo.common.health_bits == 0, + "incorrect value for last_msg.msg.almanac_glo.common.health_bits, " + "expected 0, is %d", + last_msg.msg.almanac_glo.common.health_bits); + + ck_assert_msg(last_msg.msg.almanac_glo.common.sid.code == 0, + "incorrect value for " + "last_msg.msg.almanac_glo.common.sid.code, expected 0, is %d", + last_msg.msg.almanac_glo.common.sid.code); + + ck_assert_msg(last_msg.msg.almanac_glo.common.sid.sat == 22, + "incorrect value for " + "last_msg.msg.almanac_glo.common.sid.sat, expected 22, is %d", + last_msg.msg.almanac_glo.common.sid.sat); + + ck_assert_msg( + last_msg.msg.almanac_glo.common.toa.tow == 446384, + "incorrect value for last_msg.msg.almanac_glo.common.toa.tow, expected " + "446384, is %d", + last_msg.msg.almanac_glo.common.toa.tow); + + ck_assert_msg(last_msg.msg.almanac_glo.common.toa.wn == 2154, + "incorrect value for last_msg.msg.almanac_glo.common.toa.wn, " + "expected 2154, is %d", + last_msg.msg.almanac_glo.common.toa.wn); + + ck_assert_msg( + (last_msg.msg.almanac_glo.common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.common.ura, expected " + "2.2, is %s", + last_msg.msg.almanac_glo.common.ura); + + ck_assert_msg(last_msg.msg.almanac_glo.common.valid == 1, + "incorrect value for last_msg.msg.almanac_glo.common.valid, " + "expected 1, is %d", + last_msg.msg.almanac_glo.common.valid); + + ck_assert_msg( + (last_msg.msg.almanac_glo.epsilon * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.epsilon, expected " + "-0.98930366296, is %s", + last_msg.msg.almanac_glo.epsilon); + + ck_assert_msg( + (last_msg.msg.almanac_glo.i * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.i, expected " + "5153.55002975, is %s", + last_msg.msg.almanac_glo.i); + + ck_assert_msg((last_msg.msg.almanac_glo.lambda_na * 100 - + -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.lambda_na, " + "expected -0.0220007884211, is %s", + last_msg.msg.almanac_glo.lambda_na); + + ck_assert_msg( + (last_msg.msg.almanac_glo.omega * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.omega, expected " + "0.934151448026, is %s", + last_msg.msg.almanac_glo.omega); + + ck_assert_msg( + (last_msg.msg.almanac_glo.t * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.t, expected " + "-1.87318184488, is %s", + last_msg.msg.almanac_glo.t); + + ck_assert_msg((last_msg.msg.almanac_glo.t_dot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.t_dot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.almanac_glo.t_dot); + + ck_assert_msg((last_msg.msg.almanac_glo.t_lambda_na * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo.t_lambda_na, " + "expected 0.00707220705226, is %s", + last_msg.msg.almanac_glo.t_lambda_na); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgAlmanacGLO_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgAlmanacGLO"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgAlmanacGLO"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgAlmanacGLO); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgAlmanacGLODep.c b/c/test/auto_check_sbp_observation_MsgAlmanacGLODep.c new file mode 100644 index 0000000000..0f52eff33a --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgAlmanacGLODep.c @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgAlmanacGLODep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x71, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, + 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, + 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, + 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 203, 178, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.almanac_glo_dep.common.fit_interval = 14400; + + test_msg.almanac_glo_dep.common.health_bits = 0; + + test_msg.almanac_glo_dep.common.sid.code = 0; + + test_msg.almanac_glo_dep.common.sid.reserved = 0; + + test_msg.almanac_glo_dep.common.sid.sat = 22; + + test_msg.almanac_glo_dep.common.toa.tow = 446384; + + test_msg.almanac_glo_dep.common.toa.wn = 2154; + + test_msg.almanac_glo_dep.common.ura = 2.2; + + test_msg.almanac_glo_dep.common.valid = 1; + + test_msg.almanac_glo_dep.epsilon = -0.9893036629599647; + + test_msg.almanac_glo_dep.i = 5153.550029754639; + + test_msg.almanac_glo_dep.lambda_na = -0.02200078842114688; + + test_msg.almanac_glo_dep.omega = 0.9341514480259797; + + test_msg.almanac_glo_dep.t = -1.8731818448797617; + + test_msg.almanac_glo_dep.t_dot = -8.903585155774196e-09; + + test_msg.almanac_glo_dep.t_lambda_na = 0.007072207052260637; + + sbp_message_send(&sbp_state, SbpMsgAlmanacGloDep, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAlmanacGloDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.fit_interval == 14400, + "incorrect value for last_msg.msg.almanac_glo_dep.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.almanac_glo_dep.common.fit_interval); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.health_bits == 0, + "incorrect value for last_msg.msg.almanac_glo_dep.common.health_bits, " + "expected 0, is %d", + last_msg.msg.almanac_glo_dep.common.health_bits); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.sid.code == 0, + "incorrect value for last_msg.msg.almanac_glo_dep.common.sid.code, " + "expected 0, is %d", + last_msg.msg.almanac_glo_dep.common.sid.code); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.sid.reserved == 0, + "incorrect value for last_msg.msg.almanac_glo_dep.common.sid.reserved, " + "expected 0, is %d", + last_msg.msg.almanac_glo_dep.common.sid.reserved); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.sid.sat == 22, + "incorrect value for last_msg.msg.almanac_glo_dep.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.almanac_glo_dep.common.sid.sat); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.toa.tow == 446384, + "incorrect value for last_msg.msg.almanac_glo_dep.common.toa.tow, " + "expected 446384, is %d", + last_msg.msg.almanac_glo_dep.common.toa.tow); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.toa.wn == 2154, + "incorrect value for last_msg.msg.almanac_glo_dep.common.toa.wn, " + "expected 2154, is %d", + last_msg.msg.almanac_glo_dep.common.toa.wn); + + ck_assert_msg( + (last_msg.msg.almanac_glo_dep.common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.common.ura, expected " + "2.2, is %s", + last_msg.msg.almanac_glo_dep.common.ura); + + ck_assert_msg( + last_msg.msg.almanac_glo_dep.common.valid == 1, + "incorrect value for last_msg.msg.almanac_glo_dep.common.valid, " + "expected 1, is %d", + last_msg.msg.almanac_glo_dep.common.valid); + + ck_assert_msg((last_msg.msg.almanac_glo_dep.epsilon * 100 - + -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.epsilon, " + "expected -0.98930366296, is %s", + last_msg.msg.almanac_glo_dep.epsilon); + + ck_assert_msg( + (last_msg.msg.almanac_glo_dep.i * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.i, expected " + "5153.55002975, is %s", + last_msg.msg.almanac_glo_dep.i); + + ck_assert_msg((last_msg.msg.almanac_glo_dep.lambda_na * 100 - + -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.lambda_na, " + "expected -0.0220007884211, is %s", + last_msg.msg.almanac_glo_dep.lambda_na); + + ck_assert_msg((last_msg.msg.almanac_glo_dep.omega * 100 - + 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.omega, " + "expected 0.934151448026, is %s", + last_msg.msg.almanac_glo_dep.omega); + + ck_assert_msg( + (last_msg.msg.almanac_glo_dep.t * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.t, expected " + "-1.87318184488, is %s", + last_msg.msg.almanac_glo_dep.t); + + ck_assert_msg((last_msg.msg.almanac_glo_dep.t_dot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.t_dot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.almanac_glo_dep.t_dot); + + ck_assert_msg( + (last_msg.msg.almanac_glo_dep.t_lambda_na * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_glo_dep.t_lambda_na, " + "expected 0.00707220705226, is %s", + last_msg.msg.almanac_glo_dep.t_lambda_na); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgAlmanacGLODep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgAlmanacGLODep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgAlmanacGLODep"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgAlmanacGLODep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgAlmanacGPS.c b/c/test/auto_check_sbp_observation_MsgAlmanacGPS.c new file mode 100644 index 0000000000..1bd1b43219 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgAlmanacGPS.c @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgAlmanacGPS) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x72, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, + 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, + 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, + 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.almanac_gps.af0 = -0.0006315018981695175; + + test_msg.almanac_gps.af1 = 8.981260180007666e-12; + + test_msg.almanac_gps.common.fit_interval = 14400; + + test_msg.almanac_gps.common.health_bits = 0; + + test_msg.almanac_gps.common.sid.code = 0; + + test_msg.almanac_gps.common.sid.sat = 22; + + test_msg.almanac_gps.common.toa.tow = 446384; + + test_msg.almanac_gps.common.toa.wn = 2154; + + test_msg.almanac_gps.common.ura = 2.2; + + test_msg.almanac_gps.common.valid = 1; + + test_msg.almanac_gps.ecc = 0.007072207052260637; + + test_msg.almanac_gps.inc = 0.9341514480259797; + + test_msg.almanac_gps.m0 = -0.02200078842114688; + + test_msg.almanac_gps.omega0 = -1.8731818448797617; + + test_msg.almanac_gps.omegadot = -8.903585155774196e-09; + + test_msg.almanac_gps.sqrta = 5153.550029754639; + + test_msg.almanac_gps.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgAlmanacGps, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAlmanacGps, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.almanac_gps.af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.af0, expected " + "-0.00063150189817, is %s", + last_msg.msg.almanac_gps.af0); + + ck_assert_msg( + (last_msg.msg.almanac_gps.af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.af1, expected " + "8.98126018001e-12, is %s", + last_msg.msg.almanac_gps.af1); + + ck_assert_msg( + last_msg.msg.almanac_gps.common.fit_interval == 14400, + "incorrect value for last_msg.msg.almanac_gps.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.almanac_gps.common.fit_interval); + + ck_assert_msg( + last_msg.msg.almanac_gps.common.health_bits == 0, + "incorrect value for last_msg.msg.almanac_gps.common.health_bits, " + "expected 0, is %d", + last_msg.msg.almanac_gps.common.health_bits); + + ck_assert_msg(last_msg.msg.almanac_gps.common.sid.code == 0, + "incorrect value for " + "last_msg.msg.almanac_gps.common.sid.code, expected 0, is %d", + last_msg.msg.almanac_gps.common.sid.code); + + ck_assert_msg(last_msg.msg.almanac_gps.common.sid.sat == 22, + "incorrect value for " + "last_msg.msg.almanac_gps.common.sid.sat, expected 22, is %d", + last_msg.msg.almanac_gps.common.sid.sat); + + ck_assert_msg( + last_msg.msg.almanac_gps.common.toa.tow == 446384, + "incorrect value for last_msg.msg.almanac_gps.common.toa.tow, expected " + "446384, is %d", + last_msg.msg.almanac_gps.common.toa.tow); + + ck_assert_msg(last_msg.msg.almanac_gps.common.toa.wn == 2154, + "incorrect value for last_msg.msg.almanac_gps.common.toa.wn, " + "expected 2154, is %d", + last_msg.msg.almanac_gps.common.toa.wn); + + ck_assert_msg( + (last_msg.msg.almanac_gps.common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.common.ura, expected " + "2.2, is %s", + last_msg.msg.almanac_gps.common.ura); + + ck_assert_msg(last_msg.msg.almanac_gps.common.valid == 1, + "incorrect value for last_msg.msg.almanac_gps.common.valid, " + "expected 1, is %d", + last_msg.msg.almanac_gps.common.valid); + + ck_assert_msg( + (last_msg.msg.almanac_gps.ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.ecc, expected " + "0.00707220705226, is %s", + last_msg.msg.almanac_gps.ecc); + + ck_assert_msg( + (last_msg.msg.almanac_gps.inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.inc, expected " + "0.934151448026, is %s", + last_msg.msg.almanac_gps.inc); + + ck_assert_msg( + (last_msg.msg.almanac_gps.m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.m0, expected " + "-0.0220007884211, is %s", + last_msg.msg.almanac_gps.m0); + + ck_assert_msg( + (last_msg.msg.almanac_gps.omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.omega0, expected " + "-1.87318184488, is %s", + last_msg.msg.almanac_gps.omega0); + + ck_assert_msg((last_msg.msg.almanac_gps.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.almanac_gps.omegadot); + + ck_assert_msg( + (last_msg.msg.almanac_gps.sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.sqrta, expected " + "5153.55002975, is %s", + last_msg.msg.almanac_gps.sqrta); + + ck_assert_msg( + (last_msg.msg.almanac_gps.w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps.w, expected " + "-0.98930366296, is %s", + last_msg.msg.almanac_gps.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgAlmanacGPS_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgAlmanacGPS"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgAlmanacGPS"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgAlmanacGPS); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgAlmanacGPSDep.c b/c/test/auto_check_sbp_observation_MsgAlmanacGPSDep.c new file mode 100644 index 0000000000..0cb4e58800 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgAlmanacGPSDep.c @@ -0,0 +1,291 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgAlmanacGPSDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x70, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, + 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, + 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, + 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, + 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 144, 232, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.almanac_gps_dep.af0 = -0.0006315018981695175; + + test_msg.almanac_gps_dep.af1 = 8.981260180007666e-12; + + test_msg.almanac_gps_dep.common.fit_interval = 14400; + + test_msg.almanac_gps_dep.common.health_bits = 0; + + test_msg.almanac_gps_dep.common.sid.code = 0; + + test_msg.almanac_gps_dep.common.sid.reserved = 0; + + test_msg.almanac_gps_dep.common.sid.sat = 22; + + test_msg.almanac_gps_dep.common.toa.tow = 446384; + + test_msg.almanac_gps_dep.common.toa.wn = 2154; + + test_msg.almanac_gps_dep.common.ura = 2.2; + + test_msg.almanac_gps_dep.common.valid = 1; + + test_msg.almanac_gps_dep.ecc = 0.007072207052260637; + + test_msg.almanac_gps_dep.inc = 0.9341514480259797; + + test_msg.almanac_gps_dep.m0 = -0.02200078842114688; + + test_msg.almanac_gps_dep.omega0 = -1.8731818448797617; + + test_msg.almanac_gps_dep.omegadot = -8.903585155774196e-09; + + test_msg.almanac_gps_dep.sqrta = 5153.550029754639; + + test_msg.almanac_gps_dep.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgAlmanacGpsDep, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgAlmanacGpsDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.almanac_gps_dep.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.almanac_gps_dep.af0); + + ck_assert_msg((last_msg.msg.almanac_gps_dep.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.almanac_gps_dep.af1); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.fit_interval == 14400, + "incorrect value for last_msg.msg.almanac_gps_dep.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.almanac_gps_dep.common.fit_interval); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.health_bits == 0, + "incorrect value for last_msg.msg.almanac_gps_dep.common.health_bits, " + "expected 0, is %d", + last_msg.msg.almanac_gps_dep.common.health_bits); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.sid.code == 0, + "incorrect value for last_msg.msg.almanac_gps_dep.common.sid.code, " + "expected 0, is %d", + last_msg.msg.almanac_gps_dep.common.sid.code); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.sid.reserved == 0, + "incorrect value for last_msg.msg.almanac_gps_dep.common.sid.reserved, " + "expected 0, is %d", + last_msg.msg.almanac_gps_dep.common.sid.reserved); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.sid.sat == 22, + "incorrect value for last_msg.msg.almanac_gps_dep.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.almanac_gps_dep.common.sid.sat); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.toa.tow == 446384, + "incorrect value for last_msg.msg.almanac_gps_dep.common.toa.tow, " + "expected 446384, is %d", + last_msg.msg.almanac_gps_dep.common.toa.tow); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.toa.wn == 2154, + "incorrect value for last_msg.msg.almanac_gps_dep.common.toa.wn, " + "expected 2154, is %d", + last_msg.msg.almanac_gps_dep.common.toa.wn); + + ck_assert_msg( + (last_msg.msg.almanac_gps_dep.common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.common.ura, expected " + "2.2, is %s", + last_msg.msg.almanac_gps_dep.common.ura); + + ck_assert_msg( + last_msg.msg.almanac_gps_dep.common.valid == 1, + "incorrect value for last_msg.msg.almanac_gps_dep.common.valid, " + "expected 1, is %d", + last_msg.msg.almanac_gps_dep.common.valid); + + ck_assert_msg((last_msg.msg.almanac_gps_dep.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.almanac_gps_dep.ecc); + + ck_assert_msg( + (last_msg.msg.almanac_gps_dep.inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.inc, expected " + "0.934151448026, is %s", + last_msg.msg.almanac_gps_dep.inc); + + ck_assert_msg( + (last_msg.msg.almanac_gps_dep.m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.m0, expected " + "-0.0220007884211, is %s", + last_msg.msg.almanac_gps_dep.m0); + + ck_assert_msg((last_msg.msg.almanac_gps_dep.omega0 * 100 - + -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.omega0, " + "expected -1.87318184488, is %s", + last_msg.msg.almanac_gps_dep.omega0); + + ck_assert_msg((last_msg.msg.almanac_gps_dep.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.almanac_gps_dep.omegadot); + + ck_assert_msg( + (last_msg.msg.almanac_gps_dep.sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.sqrta, expected " + "5153.55002975, is %s", + last_msg.msg.almanac_gps_dep.sqrta); + + ck_assert_msg( + (last_msg.msg.almanac_gps_dep.w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.almanac_gps_dep.w, expected " + "-0.98930366296, is %s", + last_msg.msg.almanac_gps_dep.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgAlmanacGPSDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgAlmanacGPSDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgAlmanacGPSDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgAlmanacGPSDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgBasePosLLH.c b/c/test/auto_check_sbp_observation_MsgBasePosLLH.c new file mode 100644 index 0000000000..3ef77e307b --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgBasePosLLH.c @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgBasePosLLH) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x44, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, + 70, 235, 0, 120, 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.base_pos_llh.height = 37.939512310879216; + + test_msg.base_pos_llh.lat = 37.251292578377395; + + test_msg.base_pos_llh.lon = -121.87505609407974; + + sbp_message_send(&sbp_state, SbpMsgBasePosLlh, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgBasePosLlh, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.base_pos_llh.height * 100 - 37.9395123109 * 100) < 0.05, + "incorrect value for last_msg.msg.base_pos_llh.height, expected " + "37.9395123109, is %s", + last_msg.msg.base_pos_llh.height); + + ck_assert_msg( + (last_msg.msg.base_pos_llh.lat * 100 - 37.2512925784 * 100) < 0.05, + "incorrect value for last_msg.msg.base_pos_llh.lat, expected " + "37.2512925784, is %s", + last_msg.msg.base_pos_llh.lat); + + ck_assert_msg( + (last_msg.msg.base_pos_llh.lon * 100 - -121.875056094 * 100) < 0.05, + "incorrect value for last_msg.msg.base_pos_llh.lon, expected " + "-121.875056094, is %s", + last_msg.msg.base_pos_llh.lon); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgBasePosLLH_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgBasePosLLH"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgBasePosLLH"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgBasePosLLH); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisDepA.c b/c/test/auto_check_sbp_observation_MsgEphemerisDepA.c new file mode 100644 index 0000000000..ca9541c294 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisDepA.c @@ -0,0 +1,355 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1a, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 242, + 84, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_dep_a.af0 = -0.0006315018981695175; + + test_msg.ephemeris_dep_a.af1 = 8.981260180007666e-12; + + test_msg.ephemeris_dep_a.af2 = 0.2; + + test_msg.ephemeris_dep_a.c_ic = 7.450580596923828e-09; + + test_msg.ephemeris_dep_a.c_is = -1.1548399925231934e-07; + + test_msg.ephemeris_dep_a.c_rc = 308.625; + + test_msg.ephemeris_dep_a.c_rs = -52.3125; + + test_msg.ephemeris_dep_a.c_uc = -2.7436763048171997e-06; + + test_msg.ephemeris_dep_a.c_us = 3.1366944313049316e-06; + + test_msg.ephemeris_dep_a.dn = 5.694522914022375e-09; + + test_msg.ephemeris_dep_a.ecc = 0.007072207052260637; + + test_msg.ephemeris_dep_a.healthy = 0; + + test_msg.ephemeris_dep_a.inc = 0.9341514480259797; + + test_msg.ephemeris_dep_a.inc_dot = -4.035882396415757e-11; + + test_msg.ephemeris_dep_a.m0 = -0.02200078842114688; + + test_msg.ephemeris_dep_a.omega0 = -1.8731818448797617; + + test_msg.ephemeris_dep_a.omegadot = -8.903585155774196e-09; + + test_msg.ephemeris_dep_a.prn = 22; + + test_msg.ephemeris_dep_a.sqrta = 5153.550029754639; + + test_msg.ephemeris_dep_a.tgd = -1.7695128917694092e-08; + + test_msg.ephemeris_dep_a.toc_tow = 446384.2; + + test_msg.ephemeris_dep_a.toc_wn = 2154; + + test_msg.ephemeris_dep_a.toe_tow = 446384.2; + + test_msg.ephemeris_dep_a.toe_wn = 2154; + + test_msg.ephemeris_dep_a.valid = 1; + + test_msg.ephemeris_dep_a.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgEphemerisDepA, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_dep_a.af0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_dep_a.af1); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.af2, " + "expected 0.2, is %s", + last_msg.msg.ephemeris_dep_a.af2); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.c_ic * 100 - + 7.45058059692e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_ic, " + "expected 7.45058059692e-09, is %s", + last_msg.msg.ephemeris_dep_a.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.c_is * 100 - + -1.15483999252e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_is, " + "expected -1.15483999252e-07, is %s", + last_msg.msg.ephemeris_dep_a.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_rc, expected " + "308.625, is %s", + last_msg.msg.ephemeris_dep_a.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_rs, expected " + "-52.3125, is %s", + last_msg.msg.ephemeris_dep_a.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.c_uc * 100 - + -2.74367630482e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_uc, " + "expected -2.74367630482e-06, is %s", + last_msg.msg.ephemeris_dep_a.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.c_us * 100 - + 3.1366944313e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.c_us, " + "expected 3.1366944313e-06, is %s", + last_msg.msg.ephemeris_dep_a.c_us); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.dn * 100 - + 5.69452291402e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.dn, " + "expected 5.69452291402e-09, is %s", + last_msg.msg.ephemeris_dep_a.dn); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.ephemeris_dep_a.ecc); + + ck_assert_msg(last_msg.msg.ephemeris_dep_a.healthy == 0, + "incorrect value for last_msg.msg.ephemeris_dep_a.healthy, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_a.healthy); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.inc, expected " + "0.934151448026, is %s", + last_msg.msg.ephemeris_dep_a.inc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.inc_dot * 100 - + -4.03588239642e-11 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.inc_dot, " + "expected -4.03588239642e-11, is %s", + last_msg.msg.ephemeris_dep_a.inc_dot); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.m0, expected " + "-0.0220007884211, is %s", + last_msg.msg.ephemeris_dep_a.m0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.omega0 * 100 - + -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.omega0, " + "expected -1.87318184488, is %s", + last_msg.msg.ephemeris_dep_a.omega0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.ephemeris_dep_a.omegadot); + + ck_assert_msg(last_msg.msg.ephemeris_dep_a.prn == 22, + "incorrect value for last_msg.msg.ephemeris_dep_a.prn, " + "expected 22, is %d", + last_msg.msg.ephemeris_dep_a.prn); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.sqrta, expected " + "5153.55002975, is %s", + last_msg.msg.ephemeris_dep_a.sqrta); + + ck_assert_msg((last_msg.msg.ephemeris_dep_a.tgd * 100 - + -1.76951289177e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.tgd, " + "expected -1.76951289177e-08, is %s", + last_msg.msg.ephemeris_dep_a.tgd); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.toc_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_a.toc_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_a.toc_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_a.toc_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_a.toc_wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.toe_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_a.toe_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_a.toe_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_a.toe_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_a.toe_wn); + + ck_assert_msg(last_msg.msg.ephemeris_dep_a.valid == 1, + "incorrect value for last_msg.msg.ephemeris_dep_a.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_dep_a.valid); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_a.w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_a.w, expected " + "-0.98930366296, is %s", + last_msg.msg.ephemeris_dep_a.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgEphemerisDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisDepC.c b/c/test/auto_check_sbp_observation_MsgEphemerisDepC.c new file mode 100644 index 0000000000..bad8784048 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisDepC.c @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisDepC) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x47, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, + 0, 0, 45, 45, 0, 0, 0, 0, 0, 23, 170, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_dep_c.af0 = -0.0006315018981695175; + + test_msg.ephemeris_dep_c.af1 = 8.981260180007666e-12; + + test_msg.ephemeris_dep_c.af2 = 0.2; + + test_msg.ephemeris_dep_c.c_ic = 7.450580596923828e-09; + + test_msg.ephemeris_dep_c.c_is = -1.1548399925231934e-07; + + test_msg.ephemeris_dep_c.c_rc = 308.625; + + test_msg.ephemeris_dep_c.c_rs = -52.3125; + + test_msg.ephemeris_dep_c.c_uc = -2.7436763048171997e-06; + + test_msg.ephemeris_dep_c.c_us = 3.1366944313049316e-06; + + test_msg.ephemeris_dep_c.dn = 5.694522914022375e-09; + + test_msg.ephemeris_dep_c.ecc = 0.007072207052260637; + + test_msg.ephemeris_dep_c.healthy = 0; + + test_msg.ephemeris_dep_c.inc = 0.9341514480259797; + + test_msg.ephemeris_dep_c.inc_dot = -4.035882396415757e-11; + + test_msg.ephemeris_dep_c.iodc = 45; + + test_msg.ephemeris_dep_c.iode = 45; + + test_msg.ephemeris_dep_c.m0 = -0.02200078842114688; + + test_msg.ephemeris_dep_c.omega0 = -1.8731818448797617; + + test_msg.ephemeris_dep_c.omegadot = -8.903585155774196e-09; + + test_msg.ephemeris_dep_c.reserved = 0; + + test_msg.ephemeris_dep_c.sid.code = 0; + + test_msg.ephemeris_dep_c.sid.reserved = 0; + + test_msg.ephemeris_dep_c.sid.sat = 22; + + test_msg.ephemeris_dep_c.sqrta = 5153.550029754639; + + test_msg.ephemeris_dep_c.tgd = -1.7695128917694092e-08; + + test_msg.ephemeris_dep_c.toc_tow = 446384.2; + + test_msg.ephemeris_dep_c.toc_wn = 2154; + + test_msg.ephemeris_dep_c.toe_tow = 446384.2; + + test_msg.ephemeris_dep_c.toe_wn = 2154; + + test_msg.ephemeris_dep_c.valid = 1; + + test_msg.ephemeris_dep_c.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgEphemerisDepC, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisDepC, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_dep_c.af0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_dep_c.af1); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.af2, " + "expected 0.2, is %s", + last_msg.msg.ephemeris_dep_c.af2); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.c_ic * 100 - + 7.45058059692e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_ic, " + "expected 7.45058059692e-09, is %s", + last_msg.msg.ephemeris_dep_c.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.c_is * 100 - + -1.15483999252e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_is, " + "expected -1.15483999252e-07, is %s", + last_msg.msg.ephemeris_dep_c.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_rc, expected " + "308.625, is %s", + last_msg.msg.ephemeris_dep_c.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_rs, expected " + "-52.3125, is %s", + last_msg.msg.ephemeris_dep_c.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.c_uc * 100 - + -2.74367630482e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_uc, " + "expected -2.74367630482e-06, is %s", + last_msg.msg.ephemeris_dep_c.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.c_us * 100 - + 3.1366944313e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.c_us, " + "expected 3.1366944313e-06, is %s", + last_msg.msg.ephemeris_dep_c.c_us); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.dn * 100 - + 5.69452291402e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.dn, " + "expected 5.69452291402e-09, is %s", + last_msg.msg.ephemeris_dep_c.dn); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.ephemeris_dep_c.ecc); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.healthy == 0, + "incorrect value for last_msg.msg.ephemeris_dep_c.healthy, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_c.healthy); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.inc, expected " + "0.934151448026, is %s", + last_msg.msg.ephemeris_dep_c.inc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.inc_dot * 100 - + -4.03588239642e-11 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.inc_dot, " + "expected -4.03588239642e-11, is %s", + last_msg.msg.ephemeris_dep_c.inc_dot); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.iodc == 45, + "incorrect value for last_msg.msg.ephemeris_dep_c.iodc, " + "expected 45, is %d", + last_msg.msg.ephemeris_dep_c.iodc); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.iode == 45, + "incorrect value for last_msg.msg.ephemeris_dep_c.iode, " + "expected 45, is %d", + last_msg.msg.ephemeris_dep_c.iode); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.m0, expected " + "-0.0220007884211, is %s", + last_msg.msg.ephemeris_dep_c.m0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.omega0 * 100 - + -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.omega0, " + "expected -1.87318184488, is %s", + last_msg.msg.ephemeris_dep_c.omega0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.ephemeris_dep_c.omegadot); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.reserved == 0, + "incorrect value for last_msg.msg.ephemeris_dep_c.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_c.reserved); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.sid.code == 0, + "incorrect value for last_msg.msg.ephemeris_dep_c.sid.code, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_c.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_dep_c.sid.reserved == 0, + "incorrect value for last_msg.msg.ephemeris_dep_c.sid.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_c.sid.reserved); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_dep_c.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_dep_c.sid.sat); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.sqrta, expected " + "5153.55002975, is %s", + last_msg.msg.ephemeris_dep_c.sqrta); + + ck_assert_msg((last_msg.msg.ephemeris_dep_c.tgd * 100 - + -1.76951289177e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.tgd, " + "expected -1.76951289177e-08, is %s", + last_msg.msg.ephemeris_dep_c.tgd); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.toc_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_c.toc_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.toc_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_c.toc_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_c.toc_wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.toe_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_c.toe_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.toe_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_c.toe_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_c.toe_wn); + + ck_assert_msg(last_msg.msg.ephemeris_dep_c.valid == 1, + "incorrect value for last_msg.msg.ephemeris_dep_c.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_dep_c.valid); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_c.w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_c.w, expected " + "-0.98930366296, is %s", + last_msg.msg.ephemeris_dep_c.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisDepC_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgEphemerisDepC"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisDepC"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisDepC); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisDepD.c b/c/test/auto_check_sbp_observation_MsgEphemerisDepD.c new file mode 100644 index 0000000000..3e86531e97 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisDepD.c @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisDepD) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x80, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, + 0, 0, 45, 45, 0, 0, 0, 0, 0, 95, 7, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_dep_d.af0 = -0.0006315018981695175; + + test_msg.ephemeris_dep_d.af1 = 8.981260180007666e-12; + + test_msg.ephemeris_dep_d.af2 = 0.2; + + test_msg.ephemeris_dep_d.c_ic = 7.450580596923828e-09; + + test_msg.ephemeris_dep_d.c_is = -1.1548399925231934e-07; + + test_msg.ephemeris_dep_d.c_rc = 308.625; + + test_msg.ephemeris_dep_d.c_rs = -52.3125; + + test_msg.ephemeris_dep_d.c_uc = -2.7436763048171997e-06; + + test_msg.ephemeris_dep_d.c_us = 3.1366944313049316e-06; + + test_msg.ephemeris_dep_d.dn = 5.694522914022375e-09; + + test_msg.ephemeris_dep_d.ecc = 0.007072207052260637; + + test_msg.ephemeris_dep_d.healthy = 0; + + test_msg.ephemeris_dep_d.inc = 0.9341514480259797; + + test_msg.ephemeris_dep_d.inc_dot = -4.035882396415757e-11; + + test_msg.ephemeris_dep_d.iodc = 45; + + test_msg.ephemeris_dep_d.iode = 45; + + test_msg.ephemeris_dep_d.m0 = -0.02200078842114688; + + test_msg.ephemeris_dep_d.omega0 = -1.8731818448797617; + + test_msg.ephemeris_dep_d.omegadot = -8.903585155774196e-09; + + test_msg.ephemeris_dep_d.reserved = 0; + + test_msg.ephemeris_dep_d.sid.code = 0; + + test_msg.ephemeris_dep_d.sid.reserved = 0; + + test_msg.ephemeris_dep_d.sid.sat = 22; + + test_msg.ephemeris_dep_d.sqrta = 5153.550029754639; + + test_msg.ephemeris_dep_d.tgd = -1.7695128917694092e-08; + + test_msg.ephemeris_dep_d.toc_tow = 446384.2; + + test_msg.ephemeris_dep_d.toc_wn = 2154; + + test_msg.ephemeris_dep_d.toe_tow = 446384.2; + + test_msg.ephemeris_dep_d.toe_wn = 2154; + + test_msg.ephemeris_dep_d.valid = 1; + + test_msg.ephemeris_dep_d.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgEphemerisDepD, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisDepD, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_dep_d.af0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_dep_d.af1); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.af2, " + "expected 0.2, is %s", + last_msg.msg.ephemeris_dep_d.af2); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.c_ic * 100 - + 7.45058059692e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_ic, " + "expected 7.45058059692e-09, is %s", + last_msg.msg.ephemeris_dep_d.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.c_is * 100 - + -1.15483999252e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_is, " + "expected -1.15483999252e-07, is %s", + last_msg.msg.ephemeris_dep_d.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_rc, expected " + "308.625, is %s", + last_msg.msg.ephemeris_dep_d.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_rs, expected " + "-52.3125, is %s", + last_msg.msg.ephemeris_dep_d.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.c_uc * 100 - + -2.74367630482e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_uc, " + "expected -2.74367630482e-06, is %s", + last_msg.msg.ephemeris_dep_d.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.c_us * 100 - + 3.1366944313e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.c_us, " + "expected 3.1366944313e-06, is %s", + last_msg.msg.ephemeris_dep_d.c_us); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.dn * 100 - + 5.69452291402e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.dn, " + "expected 5.69452291402e-09, is %s", + last_msg.msg.ephemeris_dep_d.dn); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.ephemeris_dep_d.ecc); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.healthy == 0, + "incorrect value for last_msg.msg.ephemeris_dep_d.healthy, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_d.healthy); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.inc, expected " + "0.934151448026, is %s", + last_msg.msg.ephemeris_dep_d.inc); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.inc_dot * 100 - + -4.03588239642e-11 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.inc_dot, " + "expected -4.03588239642e-11, is %s", + last_msg.msg.ephemeris_dep_d.inc_dot); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.iodc == 45, + "incorrect value for last_msg.msg.ephemeris_dep_d.iodc, " + "expected 45, is %d", + last_msg.msg.ephemeris_dep_d.iodc); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.iode == 45, + "incorrect value for last_msg.msg.ephemeris_dep_d.iode, " + "expected 45, is %d", + last_msg.msg.ephemeris_dep_d.iode); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.m0, expected " + "-0.0220007884211, is %s", + last_msg.msg.ephemeris_dep_d.m0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.omega0 * 100 - + -1.87318184488 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.omega0, " + "expected -1.87318184488, is %s", + last_msg.msg.ephemeris_dep_d.omega0); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.ephemeris_dep_d.omegadot); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.reserved == 0, + "incorrect value for last_msg.msg.ephemeris_dep_d.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_d.reserved); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.sid.code == 0, + "incorrect value for last_msg.msg.ephemeris_dep_d.sid.code, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_d.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_dep_d.sid.reserved == 0, + "incorrect value for last_msg.msg.ephemeris_dep_d.sid.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_dep_d.sid.reserved); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_dep_d.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_dep_d.sid.sat); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.sqrta, expected " + "5153.55002975, is %s", + last_msg.msg.ephemeris_dep_d.sqrta); + + ck_assert_msg((last_msg.msg.ephemeris_dep_d.tgd * 100 - + -1.76951289177e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.tgd, " + "expected -1.76951289177e-08, is %s", + last_msg.msg.ephemeris_dep_d.tgd); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.toc_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_d.toc_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.toc_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_d.toc_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_d.toc_wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.toe_tow, expected " + "446384.2, is %s", + last_msg.msg.ephemeris_dep_d.toe_tow); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.toe_wn == 2154, + "incorrect value for last_msg.msg.ephemeris_dep_d.toe_wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_dep_d.toe_wn); + + ck_assert_msg(last_msg.msg.ephemeris_dep_d.valid == 1, + "incorrect value for last_msg.msg.ephemeris_dep_d.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_dep_d.valid); + + ck_assert_msg( + (last_msg.msg.ephemeris_dep_d.w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_dep_d.w, expected " + "-0.98930366296, is %s", + last_msg.msg.ephemeris_dep_d.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisDepD_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgEphemerisDepD"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisDepD"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisDepD); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGLODepA.c b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepA.c new file mode 100644 index 0000000000..3bde7e6740 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepA.c @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGLODepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x83, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, + 106, 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, + 48, 236, 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, + 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, + 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 112, 199, 62, 202, 238, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_glo_dep_a.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_a.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_a.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_glo_dep_a.common.fit_interval = 2400; + + test_msg.ephemeris_glo_dep_a.common.health_bits = 0; + + test_msg.ephemeris_glo_dep_a.common.sid.code = 3; + + test_msg.ephemeris_glo_dep_a.common.sid.reserved = 0; + + test_msg.ephemeris_glo_dep_a.common.sid.sat = 4; + + test_msg.ephemeris_glo_dep_a.common.toe.tow = 443718; + + test_msg.ephemeris_glo_dep_a.common.toe.wn = 2154; + + test_msg.ephemeris_glo_dep_a.common.ura = 5.2; + + test_msg.ephemeris_glo_dep_a.common.valid = 1; + + test_msg.ephemeris_glo_dep_a.gamma = 9.094947017729282e-13; + + test_msg.ephemeris_glo_dep_a.pos[0] = -12177330.078125; + + test_msg.ephemeris_glo_dep_a.pos[1] = 599893.06640625; + + test_msg.ephemeris_glo_dep_a.pos[2] = -22373708.49609375; + + test_msg.ephemeris_glo_dep_a.tau = -8.36281105875969e-05; + + test_msg.ephemeris_glo_dep_a.vel[0] = -1726.506233215332; + + test_msg.ephemeris_glo_dep_a.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_glo_dep_a.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGloDepA, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGloDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.acc[0], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_a.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.acc[1], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_a.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.acc[2], expected " + "2.79396772385e-06, is %s", + last_msg.msg.ephemeris_glo_dep_a.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_a.common.fit_interval == 2400, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_a.common.fit_interval, " + "expected 2400, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_a.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_a.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_a.common.sid.code == 3, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.sid.code, " + "expected 3, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.sid.code); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_a.common.sid.reserved == 0, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_a.common.sid.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.sid.reserved); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_a.common.sid.sat == 4, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.sid.sat, " + "expected 4, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_a.common.toe.tow == 443718, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.toe.tow, " + "expected 443718, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_a.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.ura, " + "expected 5.2, is %s", + last_msg.msg.ephemeris_glo_dep_a.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_a.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_glo_dep_a.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_a.gamma * 100 - + 9.09494701773e-13 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.gamma, " + "expected 9.09494701773e-13, is %s", + last_msg.msg.ephemeris_glo_dep_a.gamma); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.pos[0] * 100 - -12177330.0781 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.pos[0], expected " + "-12177330.0781, is %s", + last_msg.msg.ephemeris_glo_dep_a.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.pos[1], expected " + "599893.066406, is %s", + last_msg.msg.ephemeris_glo_dep_a.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.pos[2] * 100 - -22373708.4961 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.pos[2], expected " + "-22373708.4961, is %s", + last_msg.msg.ephemeris_glo_dep_a.pos[2]); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_a.tau * 100 - + -8.36281105876e-05 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.tau, " + "expected -8.36281105876e-05, is %s", + last_msg.msg.ephemeris_glo_dep_a.tau); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.vel[0] * 100 - -1726.50623322 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.vel[0], expected " + "-1726.50623322, is %s", + last_msg.msg.ephemeris_glo_dep_a.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.vel[1] * 100 - -2542.61493683 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.vel[1], expected " + "-2542.61493683, is %s", + last_msg.msg.ephemeris_glo_dep_a.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_a.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_a.vel[2], expected " + "869.817733765, is %s", + last_msg.msg.ephemeris_glo_dep_a.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGLODepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGLODepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGLODepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGLODepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGLODepB.c b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepB.c new file mode 100644 index 0000000000..5aceb08bcc --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepB.c @@ -0,0 +1,304 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGLODepB) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x85, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, + 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, + 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 122, 127, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_glo_dep_b.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_b.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_b.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_glo_dep_b.common.fit_interval = 2400; + + test_msg.ephemeris_glo_dep_b.common.health_bits = 0; + + test_msg.ephemeris_glo_dep_b.common.sid.code = 3; + + test_msg.ephemeris_glo_dep_b.common.sid.sat = 4; + + test_msg.ephemeris_glo_dep_b.common.toe.tow = 443718; + + test_msg.ephemeris_glo_dep_b.common.toe.wn = 2154; + + test_msg.ephemeris_glo_dep_b.common.ura = 5.2; + + test_msg.ephemeris_glo_dep_b.common.valid = 1; + + test_msg.ephemeris_glo_dep_b.gamma = 9.094947017729282e-13; + + test_msg.ephemeris_glo_dep_b.pos[0] = -12177330.078125; + + test_msg.ephemeris_glo_dep_b.pos[1] = 599893.06640625; + + test_msg.ephemeris_glo_dep_b.pos[2] = -22373708.49609375; + + test_msg.ephemeris_glo_dep_b.tau = -8.36281105875969e-05; + + test_msg.ephemeris_glo_dep_b.vel[0] = -1726.506233215332; + + test_msg.ephemeris_glo_dep_b.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_glo_dep_b.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGloDepB, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGloDepB, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.acc[0], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_b.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.acc[1], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_b.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.acc[2], expected " + "2.79396772385e-06, is %s", + last_msg.msg.ephemeris_glo_dep_b.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_b.common.fit_interval == 2400, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_b.common.fit_interval, " + "expected 2400, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_b.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_b.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_b.common.sid.code == 3, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.sid.code, " + "expected 3, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_b.common.sid.sat == 4, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.sid.sat, " + "expected 4, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_b.common.toe.tow == 443718, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.toe.tow, " + "expected 443718, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_b.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.ura, " + "expected 5.2, is %s", + last_msg.msg.ephemeris_glo_dep_b.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_b.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_glo_dep_b.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_b.gamma * 100 - + 9.09494701773e-13 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.gamma, " + "expected 9.09494701773e-13, is %s", + last_msg.msg.ephemeris_glo_dep_b.gamma); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.pos[0] * 100 - -12177330.0781 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.pos[0], expected " + "-12177330.0781, is %s", + last_msg.msg.ephemeris_glo_dep_b.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.pos[1], expected " + "599893.066406, is %s", + last_msg.msg.ephemeris_glo_dep_b.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.pos[2] * 100 - -22373708.4961 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.pos[2], expected " + "-22373708.4961, is %s", + last_msg.msg.ephemeris_glo_dep_b.pos[2]); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_b.tau * 100 - + -8.36281105876e-05 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.tau, " + "expected -8.36281105876e-05, is %s", + last_msg.msg.ephemeris_glo_dep_b.tau); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.vel[0] * 100 - -1726.50623322 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.vel[0], expected " + "-1726.50623322, is %s", + last_msg.msg.ephemeris_glo_dep_b.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.vel[1] * 100 - -2542.61493683 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.vel[1], expected " + "-2542.61493683, is %s", + last_msg.msg.ephemeris_glo_dep_b.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_b.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_b.vel[2], expected " + "869.817733765, is %s", + last_msg.msg.ephemeris_glo_dep_b.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGLODepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGLODepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGLODepB"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGLODepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGLODepC.c b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepC.c new file mode 100644 index 0000000000..fb8b3bef72 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepC.c @@ -0,0 +1,320 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGLODepC) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x87, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, + 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, 190, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, + 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, + 0, 0, 0, 0, 112, 199, 62, 14, 151, 65, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_glo_dep_c.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_c.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_c.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_glo_dep_c.common.fit_interval = 2400; + + test_msg.ephemeris_glo_dep_c.common.health_bits = 0; + + test_msg.ephemeris_glo_dep_c.common.sid.code = 3; + + test_msg.ephemeris_glo_dep_c.common.sid.sat = 4; + + test_msg.ephemeris_glo_dep_c.common.toe.tow = 443718; + + test_msg.ephemeris_glo_dep_c.common.toe.wn = 2154; + + test_msg.ephemeris_glo_dep_c.common.ura = 5.2; + + test_msg.ephemeris_glo_dep_c.common.valid = 1; + + test_msg.ephemeris_glo_dep_c.d_tau = -2.7939677238464355e-09; + + test_msg.ephemeris_glo_dep_c.fcn = 14; + + test_msg.ephemeris_glo_dep_c.gamma = 9.094947017729282e-13; + + test_msg.ephemeris_glo_dep_c.pos[0] = -12177330.078125; + + test_msg.ephemeris_glo_dep_c.pos[1] = 599893.06640625; + + test_msg.ephemeris_glo_dep_c.pos[2] = -22373708.49609375; + + test_msg.ephemeris_glo_dep_c.tau = -8.36281105875969e-05; + + test_msg.ephemeris_glo_dep_c.vel[0] = -1726.506233215332; + + test_msg.ephemeris_glo_dep_c.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_glo_dep_c.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGloDepC, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGloDepC, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.acc[0], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_c.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.acc[1], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_c.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.acc[2], expected " + "2.79396772385e-06, is %s", + last_msg.msg.ephemeris_glo_dep_c.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_c.common.fit_interval == 2400, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_c.common.fit_interval, " + "expected 2400, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_c.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_c.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_c.common.sid.code == 3, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.sid.code, " + "expected 3, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_c.common.sid.sat == 4, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.sid.sat, " + "expected 4, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_c.common.toe.tow == 443718, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.toe.tow, " + "expected 443718, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_c.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.ura, " + "expected 5.2, is %s", + last_msg.msg.ephemeris_glo_dep_c.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_c.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_glo_dep_c.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_c.d_tau * 100 - + -2.79396772385e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.d_tau, " + "expected -2.79396772385e-09, is %s", + last_msg.msg.ephemeris_glo_dep_c.d_tau); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_c.fcn == 14, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.fcn, " + "expected 14, is %d", + last_msg.msg.ephemeris_glo_dep_c.fcn); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_c.gamma * 100 - + 9.09494701773e-13 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.gamma, " + "expected 9.09494701773e-13, is %s", + last_msg.msg.ephemeris_glo_dep_c.gamma); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.pos[0] * 100 - -12177330.0781 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.pos[0], expected " + "-12177330.0781, is %s", + last_msg.msg.ephemeris_glo_dep_c.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.pos[1], expected " + "599893.066406, is %s", + last_msg.msg.ephemeris_glo_dep_c.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.pos[2] * 100 - -22373708.4961 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.pos[2], expected " + "-22373708.4961, is %s", + last_msg.msg.ephemeris_glo_dep_c.pos[2]); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_c.tau * 100 - + -8.36281105876e-05 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.tau, " + "expected -8.36281105876e-05, is %s", + last_msg.msg.ephemeris_glo_dep_c.tau); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.vel[0] * 100 - -1726.50623322 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.vel[0], expected " + "-1726.50623322, is %s", + last_msg.msg.ephemeris_glo_dep_c.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.vel[1] * 100 - -2542.61493683 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.vel[1], expected " + "-2542.61493683, is %s", + last_msg.msg.ephemeris_glo_dep_c.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_c.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_c.vel[2], expected " + "869.817733765, is %s", + last_msg.msg.ephemeris_glo_dep_c.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGLODepC_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGLODepC"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGLODepC"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGLODepC); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGLODepD.c b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepD.c new file mode 100644 index 0000000000..06973082f6 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGLODepD.c @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGLODepD) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x88, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, + 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, 190, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, + 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, + 0, 0, 0, 0, 112, 199, 62, 14, 100, 82, 64, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_glo_dep_d.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_d.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_glo_dep_d.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_glo_dep_d.common.fit_interval = 2400; + + test_msg.ephemeris_glo_dep_d.common.health_bits = 0; + + test_msg.ephemeris_glo_dep_d.common.sid.code = 3; + + test_msg.ephemeris_glo_dep_d.common.sid.sat = 4; + + test_msg.ephemeris_glo_dep_d.common.toe.tow = 443718; + + test_msg.ephemeris_glo_dep_d.common.toe.wn = 2154; + + test_msg.ephemeris_glo_dep_d.common.ura = 5.2; + + test_msg.ephemeris_glo_dep_d.common.valid = 1; + + test_msg.ephemeris_glo_dep_d.d_tau = -2.7939677238464355e-09; + + test_msg.ephemeris_glo_dep_d.fcn = 14; + + test_msg.ephemeris_glo_dep_d.gamma = 9.094947017729282e-13; + + test_msg.ephemeris_glo_dep_d.iod = 100; + + test_msg.ephemeris_glo_dep_d.pos[0] = -12177330.078125; + + test_msg.ephemeris_glo_dep_d.pos[1] = 599893.06640625; + + test_msg.ephemeris_glo_dep_d.pos[2] = -22373708.49609375; + + test_msg.ephemeris_glo_dep_d.tau = -8.36281105875969e-05; + + test_msg.ephemeris_glo_dep_d.vel[0] = -1726.506233215332; + + test_msg.ephemeris_glo_dep_d.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_glo_dep_d.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGloDepD, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGloDepD, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.acc[0], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_d.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.acc[1], expected " + "9.31322574615e-07, is %s", + last_msg.msg.ephemeris_glo_dep_d.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.acc[2], expected " + "2.79396772385e-06, is %s", + last_msg.msg.ephemeris_glo_dep_d.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_d.common.fit_interval == 2400, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_d.common.fit_interval, " + "expected 2400, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_d.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_glo_dep_d.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_d.common.sid.code == 3, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.sid.code, " + "expected 3, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_d.common.sid.sat == 4, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.sid.sat, " + "expected 4, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_d.common.toe.tow == 443718, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.toe.tow, " + "expected 443718, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_d.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.ura, " + "expected 5.2, is %s", + last_msg.msg.ephemeris_glo_dep_d.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_glo_dep_d.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_glo_dep_d.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_d.d_tau * 100 - + -2.79396772385e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.d_tau, " + "expected -2.79396772385e-09, is %s", + last_msg.msg.ephemeris_glo_dep_d.d_tau); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_d.fcn == 14, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.fcn, " + "expected 14, is %d", + last_msg.msg.ephemeris_glo_dep_d.fcn); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_d.gamma * 100 - + 9.09494701773e-13 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.gamma, " + "expected 9.09494701773e-13, is %s", + last_msg.msg.ephemeris_glo_dep_d.gamma); + + ck_assert_msg(last_msg.msg.ephemeris_glo_dep_d.iod == 100, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.iod, " + "expected 100, is %d", + last_msg.msg.ephemeris_glo_dep_d.iod); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.pos[0] * 100 - -12177330.0781 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.pos[0], expected " + "-12177330.0781, is %s", + last_msg.msg.ephemeris_glo_dep_d.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.pos[1], expected " + "599893.066406, is %s", + last_msg.msg.ephemeris_glo_dep_d.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.pos[2] * 100 - -22373708.4961 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.pos[2], expected " + "-22373708.4961, is %s", + last_msg.msg.ephemeris_glo_dep_d.pos[2]); + + ck_assert_msg((last_msg.msg.ephemeris_glo_dep_d.tau * 100 - + -8.36281105876e-05 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.tau, " + "expected -8.36281105876e-05, is %s", + last_msg.msg.ephemeris_glo_dep_d.tau); + + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.vel[0] * 100 - -1726.50623322 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.vel[0], expected " + "-1726.50623322, is %s", + last_msg.msg.ephemeris_glo_dep_d.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.vel[1] * 100 - -2542.61493683 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.vel[1], expected " + "-2542.61493683, is %s", + last_msg.msg.ephemeris_glo_dep_d.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_glo_dep_d.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_glo_dep_d.vel[2], expected " + "869.817733765, is %s", + last_msg.msg.ephemeris_glo_dep_d.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGLODepD_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGLODepD"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGLODepD"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGLODepD); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepE.c b/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepE.c new file mode 100644 index 0000000000..6fe9dc3bc3 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepE.c @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGPSDepE) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x81, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, + 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, + 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, + 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, + 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, + 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, + 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, + 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, + 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_gps_dep_e.af0 = -0.0006315018981695175; + + test_msg.ephemeris_gps_dep_e.af1 = 8.981260180007666e-12; + + test_msg.ephemeris_gps_dep_e.af2 = 0.0; + + test_msg.ephemeris_gps_dep_e.c_ic = 7.450580596923828e-09; + + test_msg.ephemeris_gps_dep_e.c_is = -1.1548399925231934e-07; + + test_msg.ephemeris_gps_dep_e.c_rc = 308.625; + + test_msg.ephemeris_gps_dep_e.c_rs = -52.3125; + + test_msg.ephemeris_gps_dep_e.c_uc = -2.7436763048171997e-06; + + test_msg.ephemeris_gps_dep_e.c_us = 3.1366944313049316e-06; + + test_msg.ephemeris_gps_dep_e.common.fit_interval = 14400; + + test_msg.ephemeris_gps_dep_e.common.health_bits = 0; + + test_msg.ephemeris_gps_dep_e.common.sid.code = 0; + + test_msg.ephemeris_gps_dep_e.common.sid.reserved = 0; + + test_msg.ephemeris_gps_dep_e.common.sid.sat = 22; + + test_msg.ephemeris_gps_dep_e.common.toe.tow = 446384; + + test_msg.ephemeris_gps_dep_e.common.toe.wn = 2154; + + test_msg.ephemeris_gps_dep_e.common.ura = 2.0; + + test_msg.ephemeris_gps_dep_e.common.valid = 1; + + test_msg.ephemeris_gps_dep_e.dn = 5.694522914022375e-09; + + test_msg.ephemeris_gps_dep_e.ecc = 0.007072207052260637; + + test_msg.ephemeris_gps_dep_e.inc = 0.9341514480259797; + + test_msg.ephemeris_gps_dep_e.inc_dot = -4.035882396415757e-11; + + test_msg.ephemeris_gps_dep_e.iodc = 45; + + test_msg.ephemeris_gps_dep_e.iode = 45; + + test_msg.ephemeris_gps_dep_e.m0 = -0.02200078842114688; + + test_msg.ephemeris_gps_dep_e.omega0 = -1.8731818448797617; + + test_msg.ephemeris_gps_dep_e.omegadot = -8.903585155774196e-09; + + test_msg.ephemeris_gps_dep_e.sqrta = 5153.550029754639; + + test_msg.ephemeris_gps_dep_e.tgd = -1.7695128917694092e-08; + + test_msg.ephemeris_gps_dep_e.toc.tow = 446384; + + test_msg.ephemeris_gps_dep_e.toc.wn = 2154; + + test_msg.ephemeris_gps_dep_e.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGpsDepE, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGpsDepE, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_gps_dep_e.af0); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_gps_dep_e.af1); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.af2 * 100 - 0.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.af2, expected " + "0.0, is %s", + last_msg.msg.ephemeris_gps_dep_e.af2); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.c_ic * 100 - + 7.45058059692e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_ic, " + "expected 7.45058059692e-09, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.c_is * 100 - + -1.15483999252e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_is, " + "expected -1.15483999252e-07, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_rc, expected " + "308.625, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_rs, expected " + "-52.3125, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.c_uc * 100 - + -2.74367630482e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_uc, " + "expected -2.74367630482e-06, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.c_us * 100 - + 3.1366944313e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.c_us, " + "expected 3.1366944313e-06, is %s", + last_msg.msg.ephemeris_gps_dep_e.c_us); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_e.common.fit_interval == 14400, + "incorrect value for " + "last_msg.msg.ephemeris_gps_dep_e.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_e.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_gps_dep_e.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.common.sid.code == 0, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.sid.code, " + "expected 0, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.sid.code); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_e.common.sid.reserved == 0, + "incorrect value for " + "last_msg.msg.ephemeris_gps_dep_e.common.sid.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.sid.reserved); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.common.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.common.toe.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.toe.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.ura, " + "expected 2.0, is %s", + last_msg.msg.ephemeris_gps_dep_e.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_gps_dep_e.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.dn * 100 - + 5.69452291402e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.dn, " + "expected 5.69452291402e-09, is %s", + last_msg.msg.ephemeris_gps_dep_e.dn); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.ephemeris_gps_dep_e.ecc); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.inc * 100 - + 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.inc, " + "expected 0.934151448026, is %s", + last_msg.msg.ephemeris_gps_dep_e.inc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.inc_dot * 100 - + -4.03588239642e-11 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.inc_dot, " + "expected -4.03588239642e-11, is %s", + last_msg.msg.ephemeris_gps_dep_e.inc_dot); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_e.iodc == 45, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.iodc, " + "expected 45, is %d", + last_msg.msg.ephemeris_gps_dep_e.iodc); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_e.iode == 45, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.iode, " + "expected 45, is %d", + last_msg.msg.ephemeris_gps_dep_e.iode); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.m0 * 100 - + -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.m0, " + "expected -0.0220007884211, is %s", + last_msg.msg.ephemeris_gps_dep_e.m0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.omega0 * 100 - -1.87318184488 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.omega0, expected " + "-1.87318184488, is %s", + last_msg.msg.ephemeris_gps_dep_e.omega0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_e.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.ephemeris_gps_dep_e.omegadot); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.sqrta * 100 - + 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.sqrta, " + "expected 5153.55002975, is %s", + last_msg.msg.ephemeris_gps_dep_e.sqrta); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.tgd * 100 - + -1.76951289177e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.tgd, " + "expected -1.76951289177e-08, is %s", + last_msg.msg.ephemeris_gps_dep_e.tgd); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.toc.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.toc.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_gps_dep_e.toc.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_e.toc.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.toc.wn, expected " + "2154, is %d", + last_msg.msg.ephemeris_gps_dep_e.toc.wn); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_e.w * 100 - + -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_e.w, " + "expected -0.98930366296, is %s", + last_msg.msg.ephemeris_gps_dep_e.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGPSDepE_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGPSDepE"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGPSDepE"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGPSDepE); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepF.c b/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepF.c new file mode 100644 index 0000000000..9e9d512220 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGPSDepF.c @@ -0,0 +1,403 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGPSDepF) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x86, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, + 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, + 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, + 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, + 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, + 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, + 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, + 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, + 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, 176, 207, + 6, 0, 106, 8, 45, 45, 0, 115, 254, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_gps_dep_f.af0 = -0.0006315018981695175; + + test_msg.ephemeris_gps_dep_f.af1 = 8.981260180007666e-12; + + test_msg.ephemeris_gps_dep_f.af2 = 0.0; + + test_msg.ephemeris_gps_dep_f.c_ic = 7.450580596923828e-09; + + test_msg.ephemeris_gps_dep_f.c_is = -1.1548399925231934e-07; + + test_msg.ephemeris_gps_dep_f.c_rc = 308.625; + + test_msg.ephemeris_gps_dep_f.c_rs = -52.3125; + + test_msg.ephemeris_gps_dep_f.c_uc = -2.7436763048171997e-06; + + test_msg.ephemeris_gps_dep_f.c_us = 3.1366944313049316e-06; + + test_msg.ephemeris_gps_dep_f.common.fit_interval = 14400; + + test_msg.ephemeris_gps_dep_f.common.health_bits = 0; + + test_msg.ephemeris_gps_dep_f.common.sid.code = 0; + + test_msg.ephemeris_gps_dep_f.common.sid.sat = 22; + + test_msg.ephemeris_gps_dep_f.common.toe.tow = 446384; + + test_msg.ephemeris_gps_dep_f.common.toe.wn = 2154; + + test_msg.ephemeris_gps_dep_f.common.ura = 2.0; + + test_msg.ephemeris_gps_dep_f.common.valid = 1; + + test_msg.ephemeris_gps_dep_f.dn = 5.694522914022375e-09; + + test_msg.ephemeris_gps_dep_f.ecc = 0.007072207052260637; + + test_msg.ephemeris_gps_dep_f.inc = 0.9341514480259797; + + test_msg.ephemeris_gps_dep_f.inc_dot = -4.035882396415757e-11; + + test_msg.ephemeris_gps_dep_f.iodc = 45; + + test_msg.ephemeris_gps_dep_f.iode = 45; + + test_msg.ephemeris_gps_dep_f.m0 = -0.02200078842114688; + + test_msg.ephemeris_gps_dep_f.omega0 = -1.8731818448797617; + + test_msg.ephemeris_gps_dep_f.omegadot = -8.903585155774196e-09; + + test_msg.ephemeris_gps_dep_f.sqrta = 5153.550029754639; + + test_msg.ephemeris_gps_dep_f.tgd = -1.7695128917694092e-08; + + test_msg.ephemeris_gps_dep_f.toc.tow = 446384; + + test_msg.ephemeris_gps_dep_f.toc.wn = 2154; + + test_msg.ephemeris_gps_dep_f.w = -0.9893036629599647; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGpsDepF, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGpsDepF, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.af0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.af0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_gps_dep_f.af0); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.af1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.af1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_gps_dep_f.af1); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.af2 * 100 - 0.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.af2, expected " + "0.0, is %s", + last_msg.msg.ephemeris_gps_dep_f.af2); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.c_ic * 100 - + 7.45058059692e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_ic, " + "expected 7.45058059692e-09, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.c_is * 100 - + -1.15483999252e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_is, " + "expected -1.15483999252e-07, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_rc, expected " + "308.625, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_rs, expected " + "-52.3125, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.c_uc * 100 - + -2.74367630482e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_uc, " + "expected -2.74367630482e-06, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.c_us * 100 - + 3.1366944313e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.c_us, " + "expected 3.1366944313e-06, is %s", + last_msg.msg.ephemeris_gps_dep_f.c_us); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_f.common.fit_interval == 14400, + "incorrect value for " + "last_msg.msg.ephemeris_gps_dep_f.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_f.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_gps_dep_f.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.common.sid.code == 0, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.sid.code, " + "expected 0, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.common.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.common.toe.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.toe.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.ura, " + "expected 2.0, is %s", + last_msg.msg.ephemeris_gps_dep_f.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_gps_dep_f.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.dn * 100 - + 5.69452291402e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.dn, " + "expected 5.69452291402e-09, is %s", + last_msg.msg.ephemeris_gps_dep_f.dn); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.ecc * 100 - + 0.00707220705226 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.ecc, " + "expected 0.00707220705226, is %s", + last_msg.msg.ephemeris_gps_dep_f.ecc); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.inc * 100 - + 0.934151448026 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.inc, " + "expected 0.934151448026, is %s", + last_msg.msg.ephemeris_gps_dep_f.inc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.inc_dot * 100 - + -4.03588239642e-11 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.inc_dot, " + "expected -4.03588239642e-11, is %s", + last_msg.msg.ephemeris_gps_dep_f.inc_dot); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_f.iodc == 45, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.iodc, " + "expected 45, is %d", + last_msg.msg.ephemeris_gps_dep_f.iodc); + + ck_assert_msg(last_msg.msg.ephemeris_gps_dep_f.iode == 45, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.iode, " + "expected 45, is %d", + last_msg.msg.ephemeris_gps_dep_f.iode); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.m0 * 100 - + -0.0220007884211 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.m0, " + "expected -0.0220007884211, is %s", + last_msg.msg.ephemeris_gps_dep_f.m0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.omega0 * 100 - -1.87318184488 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.omega0, expected " + "-1.87318184488, is %s", + last_msg.msg.ephemeris_gps_dep_f.omega0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gps_dep_f.omegadot * 100 - + -8.90358515577e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.omegadot, " + "expected -8.90358515577e-09, is %s", + last_msg.msg.ephemeris_gps_dep_f.omegadot); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.sqrta * 100 - + 5153.55002975 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.sqrta, " + "expected 5153.55002975, is %s", + last_msg.msg.ephemeris_gps_dep_f.sqrta); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.tgd * 100 - + -1.76951289177e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.tgd, " + "expected -1.76951289177e-08, is %s", + last_msg.msg.ephemeris_gps_dep_f.tgd); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.toc.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.toc.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_gps_dep_f.toc.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gps_dep_f.toc.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.toc.wn, expected " + "2154, is %d", + last_msg.msg.ephemeris_gps_dep_f.toc.wn); + + ck_assert_msg((last_msg.msg.ephemeris_gps_dep_f.w * 100 - + -0.98930366296 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gps_dep_f.w, " + "expected -0.98930366296, is %s", + last_msg.msg.ephemeris_gps_dep_f.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGPSDepF_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGPSDepF"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGPSDepF"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGPSDepF); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisGalDepA.c b/c/test/auto_check_sbp_observation_MsgEphemerisGalDepA.c new file mode 100644 index 0000000000..4077d3e3a2 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisGalDepA.c @@ -0,0 +1,412 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisGalDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x95, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, + 102, 102, 230, 64, 64, 56, 0, 0, 1, 0, 154, 153, 153, 63, + 205, 204, 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, + 166, 64, 102, 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, + 217, 204, 130, 105, 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, + 253, 191, 0, 0, 0, 0, 151, 92, 38, 63, 0, 0, 0, 55, + 154, 64, 181, 64, 56, 38, 1, 141, 255, 182, 242, 63, 222, 147, + 136, 39, 79, 186, 56, 190, 80, 114, 204, 251, 193, 92, 191, 63, + 237, 55, 19, 41, 177, 73, 239, 63, 49, 65, 189, 240, 8, 216, + 245, 189, 255, 255, 255, 255, 67, 235, 241, 190, 255, 255, 255, 255, + 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, 6, 0, 106, 8, + 108, 0, 108, 0, 168, 49, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_gal_dep_a.af0 = -1.7088896129280325e-05; + + test_msg.ephemeris_gal_dep_a.af1 = -8.185452315956353e-12; + + test_msg.ephemeris_gal_dep_a.af2 = 0.20000000298023224; + + test_msg.ephemeris_gal_dep_a.bgd_e1e5a = 1.2000000476837158; + + test_msg.ephemeris_gal_dep_a.bgd_e1e5b = 2.200000047683716; + + test_msg.ephemeris_gal_dep_a.c_ic = 3.200000047683716; + + test_msg.ephemeris_gal_dep_a.c_is = 4.199999809265137; + + test_msg.ephemeris_gal_dep_a.c_rc = 265.4375; + + test_msg.ephemeris_gal_dep_a.c_rs = 10.125; + + test_msg.ephemeris_gal_dep_a.c_uc = 5.199999809265137; + + test_msg.ephemeris_gal_dep_a.c_us = 6.199999809265137; + + test_msg.ephemeris_gal_dep_a.common.fit_interval = 14400; + + test_msg.ephemeris_gal_dep_a.common.health_bits = 0; + + test_msg.ephemeris_gal_dep_a.common.sid.code = 14; + + test_msg.ephemeris_gal_dep_a.common.sid.sat = 27; + + test_msg.ephemeris_gal_dep_a.common.toe.tow = 448800; + + test_msg.ephemeris_gal_dep_a.common.toe.wn = 2154; + + test_msg.ephemeris_gal_dep_a.common.ura = 7.199999809265137; + + test_msg.ephemeris_gal_dep_a.common.valid = 1; + + test_msg.ephemeris_gal_dep_a.dn = 3.2262058129932258e-09; + + test_msg.ephemeris_gal_dep_a.ecc = 0.00017060607206076384; + + test_msg.ephemeris_gal_dep_a.inc = 0.9777456094977858; + + test_msg.ephemeris_gal_dep_a.inc_dot = -3.1787038343451465e-10; + + test_msg.ephemeris_gal_dep_a.iodc = 108; + + test_msg.ephemeris_gal_dep_a.iode = 108; + + test_msg.ephemeris_gal_dep_a.m0 = -1.8457115744155868; + + test_msg.ephemeris_gal_dep_a.omega0 = 1.16967730598334; + + test_msg.ephemeris_gal_dep_a.omegadot = -5.757382675240872e-09; + + test_msg.ephemeris_gal_dep_a.sqrta = 5440.602401733398; + + test_msg.ephemeris_gal_dep_a.toc.tow = 448800; + + test_msg.ephemeris_gal_dep_a.toc.wn = 2154; + + test_msg.ephemeris_gal_dep_a.w = 0.12250912091662625; + + sbp_message_send(&sbp_state, SbpMsgEphemerisGalDepA, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisGalDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.af0 * 100 - + -1.70888961293e-05 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.af0, " + "expected -1.70888961293e-05, is %s", + last_msg.msg.ephemeris_gal_dep_a.af0); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.af1 * 100 - + -8.18545231596e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.af1, " + "expected -8.18545231596e-12, is %s", + last_msg.msg.ephemeris_gal_dep_a.af1); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.af2 * 100 - + 0.20000000298 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.af2, " + "expected 0.20000000298, is %s", + last_msg.msg.ephemeris_gal_dep_a.af2); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5a * 100 - + 1.20000004768 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5a, " + "expected 1.20000004768, is %s", + last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5a); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5b * 100 - + 2.20000004768 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5b, " + "expected 2.20000004768, is %s", + last_msg.msg.ephemeris_gal_dep_a.bgd_e1e5b); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.c_ic * 100 - + 3.20000004768 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_ic, " + "expected 3.20000004768, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_ic); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.c_is * 100 - + 4.19999980927 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_is, " + "expected 4.19999980927, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_is); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.c_rc * 100 - 265.4375 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_rc, expected " + "265.4375, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_rc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.c_rs * 100 - 10.125 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_rs, expected " + "10.125, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_rs); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.c_uc * 100 - + 5.19999980927 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_uc, " + "expected 5.19999980927, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_uc); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.c_us * 100 - + 6.19999980927 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.c_us, " + "expected 6.19999980927, is %s", + last_msg.msg.ephemeris_gal_dep_a.c_us); + + ck_assert_msg(last_msg.msg.ephemeris_gal_dep_a.common.fit_interval == 14400, + "incorrect value for " + "last_msg.msg.ephemeris_gal_dep_a.common.fit_interval, " + "expected 14400, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_gal_dep_a.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_gal_dep_a.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.common.sid.code == 14, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.sid.code, " + "expected 14, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.common.sid.sat == 27, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.sid.sat, " + "expected 27, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.common.toe.tow == 448800, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.toe.tow, " + "expected 448800, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.common.ura * 100 - + 7.19999980927 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.ura, " + "expected 7.19999980927, is %s", + last_msg.msg.ephemeris_gal_dep_a.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_gal_dep_a.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.dn * 100 - + 3.22620581299e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.dn, " + "expected 3.22620581299e-09, is %s", + last_msg.msg.ephemeris_gal_dep_a.dn); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.ecc * 100 - + 0.000170606072061 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.ecc, " + "expected 0.000170606072061, is %s", + last_msg.msg.ephemeris_gal_dep_a.ecc); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.inc * 100 - + 0.977745609498 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.inc, " + "expected 0.977745609498, is %s", + last_msg.msg.ephemeris_gal_dep_a.inc); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.inc_dot * 100 - + -3.17870383435e-10 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.inc_dot, " + "expected -3.17870383435e-10, is %s", + last_msg.msg.ephemeris_gal_dep_a.inc_dot); + + ck_assert_msg(last_msg.msg.ephemeris_gal_dep_a.iodc == 108, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.iodc, " + "expected 108, is %d", + last_msg.msg.ephemeris_gal_dep_a.iodc); + + ck_assert_msg(last_msg.msg.ephemeris_gal_dep_a.iode == 108, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.iode, " + "expected 108, is %d", + last_msg.msg.ephemeris_gal_dep_a.iode); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.m0 * 100 - + -1.84571157442 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.m0, " + "expected -1.84571157442, is %s", + last_msg.msg.ephemeris_gal_dep_a.m0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.omega0 * 100 - 1.16967730598 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.omega0, expected " + "1.16967730598, is %s", + last_msg.msg.ephemeris_gal_dep_a.omega0); + + ck_assert_msg( + (last_msg.msg.ephemeris_gal_dep_a.omegadot * 100 - + -5.75738267524e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.omegadot, " + "expected -5.75738267524e-09, is %s", + last_msg.msg.ephemeris_gal_dep_a.omegadot); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.sqrta * 100 - + 5440.60240173 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.sqrta, " + "expected 5440.60240173, is %s", + last_msg.msg.ephemeris_gal_dep_a.sqrta); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.toc.tow == 448800, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.toc.tow, " + "expected 448800, is %d", + last_msg.msg.ephemeris_gal_dep_a.toc.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_gal_dep_a.toc.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.toc.wn, expected " + "2154, is %d", + last_msg.msg.ephemeris_gal_dep_a.toc.wn); + + ck_assert_msg((last_msg.msg.ephemeris_gal_dep_a.w * 100 - + 0.122509120917 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_gal_dep_a.w, " + "expected 0.122509120917, is %s", + last_msg.msg.ephemeris_gal_dep_a.w); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisGalDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisGalDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisGalDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisGalDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisSbas.c b/c/test/auto_check_sbp_observation_MsgEphemerisSbas.c new file mode 100644 index 0000000000..3294ec50a4 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisSbas.c @@ -0,0 +1,290 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisSbas) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x8c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, + 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, + 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, 122, 53, 0, 128, + 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_sbas.a_gf0 = -0.0006315018981695175; + + test_msg.ephemeris_sbas.a_gf1 = 8.981260180007666e-12; + + test_msg.ephemeris_sbas.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_sbas.common.fit_interval = 0; + + test_msg.ephemeris_sbas.common.health_bits = 0; + + test_msg.ephemeris_sbas.common.sid.code = 6; + + test_msg.ephemeris_sbas.common.sid.sat = 22; + + test_msg.ephemeris_sbas.common.toe.tow = 446384; + + test_msg.ephemeris_sbas.common.toe.wn = 2154; + + test_msg.ephemeris_sbas.common.ura = -2.7939677238464355e-09; + + test_msg.ephemeris_sbas.common.valid = 1; + + test_msg.ephemeris_sbas.pos[0] = -12177330.078125; + + test_msg.ephemeris_sbas.pos[1] = 599893.06640625; + + test_msg.ephemeris_sbas.pos[2] = -22373708.49609375; + + test_msg.ephemeris_sbas.vel[0] = -1726.5062255859375; + + test_msg.ephemeris_sbas.vel[1] = -2542.614990234375; + + test_msg.ephemeris_sbas.vel[2] = 869.8177490234375; + + sbp_message_send(&sbp_state, SbpMsgEphemerisSbas, 1219, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisSbas, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.a_gf0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.a_gf0, " + "expected -0.00063150189817, is %s", + last_msg.msg.ephemeris_sbas.a_gf0); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.a_gf1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.a_gf1, " + "expected 8.98126018001e-12, is %s", + last_msg.msg.ephemeris_sbas.a_gf1); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.acc[0], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas.acc[0]); + ck_assert_msg((last_msg.msg.ephemeris_sbas.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.acc[1], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas.acc[1]); + ck_assert_msg((last_msg.msg.ephemeris_sbas.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.acc[2], " + "expected 2.79396772385e-06, is %s", + last_msg.msg.ephemeris_sbas.acc[2]); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.fit_interval == 0, + "incorrect value for last_msg.msg.ephemeris_sbas.common.fit_interval, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas.common.fit_interval); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.health_bits == 0, + "incorrect value for last_msg.msg.ephemeris_sbas.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.sid.code == 6, + "incorrect value for last_msg.msg.ephemeris_sbas.common.sid.code, " + "expected 6, is %d", + last_msg.msg.ephemeris_sbas.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_sbas.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_sbas.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.toe.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_sbas.common.toe.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_sbas.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_sbas.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_sbas.common.toe.wn); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.common.ura * 100 - + -2.79396772385e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.common.ura, " + "expected -2.79396772385e-09, is %s", + last_msg.msg.ephemeris_sbas.common.ura); + + ck_assert_msg(last_msg.msg.ephemeris_sbas.common.valid == 1, + "incorrect value for " + "last_msg.msg.ephemeris_sbas.common.valid, expected 1, is %d", + last_msg.msg.ephemeris_sbas.common.valid); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.pos[0] * 100 - + -12177330.0781 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.pos[0], " + "expected -12177330.0781, is %s", + last_msg.msg.ephemeris_sbas.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas.pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.pos[1], expected " + "599893.066406, is %s", + last_msg.msg.ephemeris_sbas.pos[1]); + ck_assert_msg((last_msg.msg.ephemeris_sbas.pos[2] * 100 - + -22373708.4961 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.pos[2], " + "expected -22373708.4961, is %s", + last_msg.msg.ephemeris_sbas.pos[2]); + + ck_assert_msg((last_msg.msg.ephemeris_sbas.vel[0] * 100 - + -1726.50622559 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.vel[0], " + "expected -1726.50622559, is %s", + last_msg.msg.ephemeris_sbas.vel[0]); + ck_assert_msg((last_msg.msg.ephemeris_sbas.vel[1] * 100 - + -2542.61499023 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.vel[1], " + "expected -2542.61499023, is %s", + last_msg.msg.ephemeris_sbas.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas.vel[2] * 100 - 869.817749023 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas.vel[2], expected " + "869.817749023, is %s", + last_msg.msg.ephemeris_sbas.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisSbas_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgEphemerisSbas"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisSbas"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisSbas); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepA.c b/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepA.c new file mode 100644 index 0000000000..37d0edcc42 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepA.c @@ -0,0 +1,314 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisSbasDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x82, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, + 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, + 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, + 0, 0, 0, 192, 163, 61, 178, 180, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_sbas_dep_a.a_gf0 = -0.0006315018981695175; + + test_msg.ephemeris_sbas_dep_a.a_gf1 = 8.981260180007666e-12; + + test_msg.ephemeris_sbas_dep_a.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas_dep_a.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas_dep_a.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_sbas_dep_a.common.fit_interval = 0; + + test_msg.ephemeris_sbas_dep_a.common.health_bits = 0; + + test_msg.ephemeris_sbas_dep_a.common.sid.code = 6; + + test_msg.ephemeris_sbas_dep_a.common.sid.reserved = 0; + + test_msg.ephemeris_sbas_dep_a.common.sid.sat = 22; + + test_msg.ephemeris_sbas_dep_a.common.toe.tow = 446384; + + test_msg.ephemeris_sbas_dep_a.common.toe.wn = 2154; + + test_msg.ephemeris_sbas_dep_a.common.ura = 2.0; + + test_msg.ephemeris_sbas_dep_a.common.valid = 1; + + test_msg.ephemeris_sbas_dep_a.pos[0] = -12177330.078125; + + test_msg.ephemeris_sbas_dep_a.pos[1] = 599893.06640625; + + test_msg.ephemeris_sbas_dep_a.pos[2] = -22373708.49609375; + + test_msg.ephemeris_sbas_dep_a.vel[0] = -1726.506233215332; + + test_msg.ephemeris_sbas_dep_a.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_sbas_dep_a.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisSbasDepA, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisSbasDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.a_gf0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.a_gf0, expected " + "-0.00063150189817, is %s", + last_msg.msg.ephemeris_sbas_dep_a.a_gf0); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.a_gf1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.a_gf1, expected " + "8.98126018001e-12, is %s", + last_msg.msg.ephemeris_sbas_dep_a.a_gf1); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.acc[0], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas_dep_a.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.acc[1], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas_dep_a.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.acc[2], " + "expected 2.79396772385e-06, is %s", + last_msg.msg.ephemeris_sbas_dep_a.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_sbas_dep_a.common.fit_interval == 0, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_a.common.fit_interval, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_sbas_dep_a.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_a.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_a.common.sid.code == 6, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_a.common.sid.code, expected 6, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.sid.code); + + ck_assert_msg(last_msg.msg.ephemeris_sbas_dep_a.common.sid.reserved == 0, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_a.common.sid.reserved, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.sid.reserved); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_a.common.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_a.common.toe.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.common.toe.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_a.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.common.ura, " + "expected 2.0, is %s", + last_msg.msg.ephemeris_sbas_dep_a.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_a.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_sbas_dep_a.common.valid); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.pos[0] * 100 - + -12177330.0781 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.pos[0], " + "expected -12177330.0781, is %s", + last_msg.msg.ephemeris_sbas_dep_a.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.pos[1], " + "expected 599893.066406, is %s", + last_msg.msg.ephemeris_sbas_dep_a.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.pos[2] * 100 - + -22373708.4961 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.pos[2], " + "expected -22373708.4961, is %s", + last_msg.msg.ephemeris_sbas_dep_a.pos[2]); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.vel[0] * 100 - + -1726.50623322 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.vel[0], " + "expected -1726.50623322, is %s", + last_msg.msg.ephemeris_sbas_dep_a.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.vel[1] * 100 - + -2542.61493683 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.vel[1], " + "expected -2542.61493683, is %s", + last_msg.msg.ephemeris_sbas_dep_a.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_a.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_a.vel[2], " + "expected 869.817733765, is %s", + last_msg.msg.ephemeris_sbas_dep_a.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisSbasDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisSbasDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisSbasDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisSbasDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepB.c b/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepB.c new file mode 100644 index 0000000000..db70886ad8 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgEphemerisSbasDepB.c @@ -0,0 +1,306 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgEphemerisSbasDepB) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x84, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, + 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, + 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, + 0, 192, 163, 61, 145, 104, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ephemeris_sbas_dep_b.a_gf0 = -0.0006315018981695175; + + test_msg.ephemeris_sbas_dep_b.a_gf1 = 8.981260180007666e-12; + + test_msg.ephemeris_sbas_dep_b.acc[0] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas_dep_b.acc[1] = 9.313225746154785e-07; + + test_msg.ephemeris_sbas_dep_b.acc[2] = 2.7939677238464355e-06; + + test_msg.ephemeris_sbas_dep_b.common.fit_interval = 0; + + test_msg.ephemeris_sbas_dep_b.common.health_bits = 0; + + test_msg.ephemeris_sbas_dep_b.common.sid.code = 6; + + test_msg.ephemeris_sbas_dep_b.common.sid.sat = 22; + + test_msg.ephemeris_sbas_dep_b.common.toe.tow = 446384; + + test_msg.ephemeris_sbas_dep_b.common.toe.wn = 2154; + + test_msg.ephemeris_sbas_dep_b.common.ura = 2.0; + + test_msg.ephemeris_sbas_dep_b.common.valid = 1; + + test_msg.ephemeris_sbas_dep_b.pos[0] = -12177330.078125; + + test_msg.ephemeris_sbas_dep_b.pos[1] = 599893.06640625; + + test_msg.ephemeris_sbas_dep_b.pos[2] = -22373708.49609375; + + test_msg.ephemeris_sbas_dep_b.vel[0] = -1726.506233215332; + + test_msg.ephemeris_sbas_dep_b.vel[1] = -2542.6149368286133; + + test_msg.ephemeris_sbas_dep_b.vel[2] = 869.8177337646484; + + sbp_message_send(&sbp_state, SbpMsgEphemerisSbasDepB, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgEphemerisSbasDepB, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.a_gf0 * 100 - + -0.00063150189817 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.a_gf0, expected " + "-0.00063150189817, is %s", + last_msg.msg.ephemeris_sbas_dep_b.a_gf0); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.a_gf1 * 100 - + 8.98126018001e-12 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.a_gf1, expected " + "8.98126018001e-12, is %s", + last_msg.msg.ephemeris_sbas_dep_b.a_gf1); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.acc[0] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.acc[0], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas_dep_b.acc[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.acc[1] * 100 - + 9.31322574615e-07 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.acc[1], " + "expected 9.31322574615e-07, is %s", + last_msg.msg.ephemeris_sbas_dep_b.acc[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.acc[2] * 100 - + 2.79396772385e-06 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.acc[2], " + "expected 2.79396772385e-06, is %s", + last_msg.msg.ephemeris_sbas_dep_b.acc[2]); + + ck_assert_msg(last_msg.msg.ephemeris_sbas_dep_b.common.fit_interval == 0, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_b.common.fit_interval, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.fit_interval); + + ck_assert_msg(last_msg.msg.ephemeris_sbas_dep_b.common.health_bits == 0, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_b.common.health_bits, " + "expected 0, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.health_bits); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_b.common.sid.code == 6, + "incorrect value for " + "last_msg.msg.ephemeris_sbas_dep_b.common.sid.code, expected 6, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.sid.code); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_b.common.sid.sat == 22, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.common.sid.sat, " + "expected 22, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.sid.sat); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_b.common.toe.tow == 446384, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.common.toe.tow, " + "expected 446384, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.toe.tow); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_b.common.toe.wn == 2154, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.common.toe.wn, " + "expected 2154, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.toe.wn); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.common.ura, " + "expected 2.0, is %s", + last_msg.msg.ephemeris_sbas_dep_b.common.ura); + + ck_assert_msg( + last_msg.msg.ephemeris_sbas_dep_b.common.valid == 1, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.common.valid, " + "expected 1, is %d", + last_msg.msg.ephemeris_sbas_dep_b.common.valid); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.pos[0] * 100 - + -12177330.0781 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.pos[0], " + "expected -12177330.0781, is %s", + last_msg.msg.ephemeris_sbas_dep_b.pos[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.pos[1] * 100 - 599893.066406 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.pos[1], " + "expected 599893.066406, is %s", + last_msg.msg.ephemeris_sbas_dep_b.pos[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.pos[2] * 100 - + -22373708.4961 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.pos[2], " + "expected -22373708.4961, is %s", + last_msg.msg.ephemeris_sbas_dep_b.pos[2]); + + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.vel[0] * 100 - + -1726.50623322 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.vel[0], " + "expected -1726.50623322, is %s", + last_msg.msg.ephemeris_sbas_dep_b.vel[0]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.vel[1] * 100 - + -2542.61493683 * 100) < 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.vel[1], " + "expected -2542.61493683, is %s", + last_msg.msg.ephemeris_sbas_dep_b.vel[1]); + ck_assert_msg( + (last_msg.msg.ephemeris_sbas_dep_b.vel[2] * 100 - 869.817733765 * 100) < + 0.05, + "incorrect value for last_msg.msg.ephemeris_sbas_dep_b.vel[2], " + "expected 869.817733765, is %s", + last_msg.msg.ephemeris_sbas_dep_b.vel[2]); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgEphemerisSbasDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgEphemerisSbasDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgEphemerisSbasDepB"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgEphemerisSbasDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgGnssCapb.c b/c/test/auto_check_sbp_observation_MsgGnssCapb.c new file mode 100644 index 0000000000..23a89669e2 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgGnssCapb.c @@ -0,0 +1,265 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgGnssCapb) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x96, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, + 64, 0, 0, 0, 0, 81, 173, 144, 46, 0, 0, 0, 0, 209, 139, + 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, 240, + 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, + 0, 0, 0, 0, 40, 75, 250, 114, 0, 0, 0, 0, 119, 147, 123, + 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, 116, + 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, + 0, 0, 0, 252, 62, 221, 28, 0, 0, 0, 0, 163, 90, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.gnss_capb.gc.bds_active = 1929005864; + + test_msg.gnss_capb.gc.bds_b2 = 33839445; + + test_msg.gnss_capb.gc.bds_b2a = 378107113; + + test_msg.gnss_capb.gc.bds_d2nav = 1367053175; + + test_msg.gnss_capb.gc.gal_active = 1392028637; + + test_msg.gnss_capb.gc.gal_e5 = 484261628; + + test_msg.gnss_capb.gc.glo_active = 13159676; + + test_msg.gnss_capb.gc.glo_l2of = 824073421; + + test_msg.gnss_capb.gc.glo_l3 = 404081648; + + test_msg.gnss_capb.gc.gps_active = 1079028506; + + test_msg.gnss_capb.gc.gps_l2c = 781233489; + + test_msg.gnss_capb.gc.gps_l5 = 1818069969; + + test_msg.gnss_capb.gc.qzss_active = 198929863; + + test_msg.gnss_capb.gc.sbas_active = 548822484; + + test_msg.gnss_capb.gc.sbas_l5 = 465576041; + + test_msg.gnss_capb.t_nmct.tow = 446384; + + test_msg.gnss_capb.t_nmct.wn = 2154; + + sbp_message_send(&sbp_state, SbpMsgGnssCapb, 123, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgGnssCapb, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.bds_active == 1929005864, + "incorrect value for last_msg.msg.gnss_capb.gc.bds_active, " + "expected 1929005864, is %d", + last_msg.msg.gnss_capb.gc.bds_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.bds_b2 == 33839445, + "incorrect value for last_msg.msg.gnss_capb.gc.bds_b2, " + "expected 33839445, is %d", + last_msg.msg.gnss_capb.gc.bds_b2); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.bds_b2a == 378107113, + "incorrect value for last_msg.msg.gnss_capb.gc.bds_b2a, " + "expected 378107113, is %d", + last_msg.msg.gnss_capb.gc.bds_b2a); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.bds_d2nav == 1367053175, + "incorrect value for last_msg.msg.gnss_capb.gc.bds_d2nav, " + "expected 1367053175, is %d", + last_msg.msg.gnss_capb.gc.bds_d2nav); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.gal_active == 1392028637, + "incorrect value for last_msg.msg.gnss_capb.gc.gal_active, " + "expected 1392028637, is %d", + last_msg.msg.gnss_capb.gc.gal_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.gal_e5 == 484261628, + "incorrect value for last_msg.msg.gnss_capb.gc.gal_e5, " + "expected 484261628, is %d", + last_msg.msg.gnss_capb.gc.gal_e5); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.glo_active == 13159676, + "incorrect value for last_msg.msg.gnss_capb.gc.glo_active, " + "expected 13159676, is %d", + last_msg.msg.gnss_capb.gc.glo_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.glo_l2of == 824073421, + "incorrect value for last_msg.msg.gnss_capb.gc.glo_l2of, " + "expected 824073421, is %d", + last_msg.msg.gnss_capb.gc.glo_l2of); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.glo_l3 == 404081648, + "incorrect value for last_msg.msg.gnss_capb.gc.glo_l3, " + "expected 404081648, is %d", + last_msg.msg.gnss_capb.gc.glo_l3); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.gps_active == 1079028506, + "incorrect value for last_msg.msg.gnss_capb.gc.gps_active, " + "expected 1079028506, is %d", + last_msg.msg.gnss_capb.gc.gps_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.gps_l2c == 781233489, + "incorrect value for last_msg.msg.gnss_capb.gc.gps_l2c, " + "expected 781233489, is %d", + last_msg.msg.gnss_capb.gc.gps_l2c); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.gps_l5 == 1818069969, + "incorrect value for last_msg.msg.gnss_capb.gc.gps_l5, " + "expected 1818069969, is %d", + last_msg.msg.gnss_capb.gc.gps_l5); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.qzss_active == 198929863, + "incorrect value for last_msg.msg.gnss_capb.gc.qzss_active, " + "expected 198929863, is %d", + last_msg.msg.gnss_capb.gc.qzss_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.sbas_active == 548822484, + "incorrect value for last_msg.msg.gnss_capb.gc.sbas_active, " + "expected 548822484, is %d", + last_msg.msg.gnss_capb.gc.sbas_active); + + ck_assert_msg(last_msg.msg.gnss_capb.gc.sbas_l5 == 465576041, + "incorrect value for last_msg.msg.gnss_capb.gc.sbas_l5, " + "expected 465576041, is %d", + last_msg.msg.gnss_capb.gc.sbas_l5); + + ck_assert_msg(last_msg.msg.gnss_capb.t_nmct.tow == 446384, + "incorrect value for last_msg.msg.gnss_capb.t_nmct.tow, " + "expected 446384, is %d", + last_msg.msg.gnss_capb.t_nmct.tow); + + ck_assert_msg(last_msg.msg.gnss_capb.t_nmct.wn == 2154, + "incorrect value for last_msg.msg.gnss_capb.t_nmct.wn, " + "expected 2154, is %d", + last_msg.msg.gnss_capb.t_nmct.wn); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgGnssCapb_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgGnssCapb"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgGnssCapb"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgGnssCapb); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgGroupDelay.c b/c/test/auto_check_sbp_observation_MsgGroupDelay.c new file mode 100644 index 0000000000..9f851c7744 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgGroupDelay.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgGroupDelay) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x94, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, + 22, 0, 1, 254, 253, 165, 255, 237, 23, 2, 201, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.group_delay.isc_l1ca = -91; + + test_msg.group_delay.isc_l2c = 6125; + + test_msg.group_delay.sid.code = 0; + + test_msg.group_delay.sid.sat = 22; + + test_msg.group_delay.t_op.tow = 446384; + + test_msg.group_delay.t_op.wn = 2154; + + test_msg.group_delay.tgd = -514; + + test_msg.group_delay.valid = 1; + + sbp_message_send(&sbp_state, SbpMsgGroupDelay, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgGroupDelay, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.group_delay.isc_l1ca == -91, + "incorrect value for last_msg.msg.group_delay.isc_l1ca, " + "expected -91, is %d", + last_msg.msg.group_delay.isc_l1ca); + + ck_assert_msg(last_msg.msg.group_delay.isc_l2c == 6125, + "incorrect value for last_msg.msg.group_delay.isc_l2c, " + "expected 6125, is %d", + last_msg.msg.group_delay.isc_l2c); + + ck_assert_msg(last_msg.msg.group_delay.sid.code == 0, + "incorrect value for last_msg.msg.group_delay.sid.code, " + "expected 0, is %d", + last_msg.msg.group_delay.sid.code); + + ck_assert_msg(last_msg.msg.group_delay.sid.sat == 22, + "incorrect value for last_msg.msg.group_delay.sid.sat, " + "expected 22, is %d", + last_msg.msg.group_delay.sid.sat); + + ck_assert_msg(last_msg.msg.group_delay.t_op.tow == 446384, + "incorrect value for last_msg.msg.group_delay.t_op.tow, " + "expected 446384, is %d", + last_msg.msg.group_delay.t_op.tow); + + ck_assert_msg(last_msg.msg.group_delay.t_op.wn == 2154, + "incorrect value for last_msg.msg.group_delay.t_op.wn, " + "expected 2154, is %d", + last_msg.msg.group_delay.t_op.wn); + + ck_assert_msg(last_msg.msg.group_delay.tgd == -514, + "incorrect value for last_msg.msg.group_delay.tgd, expected " + "-514, is %d", + last_msg.msg.group_delay.tgd); + + ck_assert_msg( + last_msg.msg.group_delay.valid == 1, + "incorrect value for last_msg.msg.group_delay.valid, expected 1, is %d", + last_msg.msg.group_delay.valid); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgGroupDelay_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgGroupDelay"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgGroupDelay"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgGroupDelay); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgGroupDelayDepA.c b/c/test/auto_check_sbp_observation_MsgGroupDelayDepA.c new file mode 100644 index 0000000000..28f5845e33 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgGroupDelayDepA.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgGroupDelayDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x92, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, + 8, 22, 1, 254, 253, 165, 255, 237, 23, 162, 91, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.group_delay_dep_a.isc_l1ca = -91; + + test_msg.group_delay_dep_a.isc_l2c = 6125; + + test_msg.group_delay_dep_a.prn = 22; + + test_msg.group_delay_dep_a.t_op.tow = 446384; + + test_msg.group_delay_dep_a.t_op.wn = 2154; + + test_msg.group_delay_dep_a.tgd = -514; + + test_msg.group_delay_dep_a.valid = 1; + + sbp_message_send(&sbp_state, SbpMsgGroupDelayDepA, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgGroupDelayDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.group_delay_dep_a.isc_l1ca == -91, + "incorrect value for last_msg.msg.group_delay_dep_a.isc_l1ca, expected " + "-91, is %d", + last_msg.msg.group_delay_dep_a.isc_l1ca); + + ck_assert_msg(last_msg.msg.group_delay_dep_a.isc_l2c == 6125, + "incorrect value for last_msg.msg.group_delay_dep_a.isc_l2c, " + "expected 6125, is %d", + last_msg.msg.group_delay_dep_a.isc_l2c); + + ck_assert_msg(last_msg.msg.group_delay_dep_a.prn == 22, + "incorrect value for last_msg.msg.group_delay_dep_a.prn, " + "expected 22, is %d", + last_msg.msg.group_delay_dep_a.prn); + + ck_assert_msg( + last_msg.msg.group_delay_dep_a.t_op.tow == 446384, + "incorrect value for last_msg.msg.group_delay_dep_a.t_op.tow, expected " + "446384, is %d", + last_msg.msg.group_delay_dep_a.t_op.tow); + + ck_assert_msg(last_msg.msg.group_delay_dep_a.t_op.wn == 2154, + "incorrect value for last_msg.msg.group_delay_dep_a.t_op.wn, " + "expected 2154, is %d", + last_msg.msg.group_delay_dep_a.t_op.wn); + + ck_assert_msg(last_msg.msg.group_delay_dep_a.tgd == -514, + "incorrect value for last_msg.msg.group_delay_dep_a.tgd, " + "expected -514, is %d", + last_msg.msg.group_delay_dep_a.tgd); + + ck_assert_msg(last_msg.msg.group_delay_dep_a.valid == 1, + "incorrect value for last_msg.msg.group_delay_dep_a.valid, " + "expected 1, is %d", + last_msg.msg.group_delay_dep_a.valid); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgGroupDelayDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgGroupDelayDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgGroupDelayDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgGroupDelayDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgGroupDelayDepB.c b/c/test/auto_check_sbp_observation_MsgGroupDelayDepB.c new file mode 100644 index 0000000000..d18887dff3 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgGroupDelayDepB.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgGroupDelayDepB) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x93, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, + 0, 0, 0, 1, 254, 253, 165, 255, 237, 23, 221, 202, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.group_delay_dep_b.isc_l1ca = -91; + + test_msg.group_delay_dep_b.isc_l2c = 6125; + + test_msg.group_delay_dep_b.sid.code = 0; + + test_msg.group_delay_dep_b.sid.reserved = 0; + + test_msg.group_delay_dep_b.sid.sat = 22; + + test_msg.group_delay_dep_b.t_op.tow = 446384; + + test_msg.group_delay_dep_b.t_op.wn = 2154; + + test_msg.group_delay_dep_b.tgd = -514; + + test_msg.group_delay_dep_b.valid = 1; + + sbp_message_send(&sbp_state, SbpMsgGroupDelayDepB, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgGroupDelayDepB, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.group_delay_dep_b.isc_l1ca == -91, + "incorrect value for last_msg.msg.group_delay_dep_b.isc_l1ca, expected " + "-91, is %d", + last_msg.msg.group_delay_dep_b.isc_l1ca); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.isc_l2c == 6125, + "incorrect value for last_msg.msg.group_delay_dep_b.isc_l2c, " + "expected 6125, is %d", + last_msg.msg.group_delay_dep_b.isc_l2c); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.sid.code == 0, + "incorrect value for " + "last_msg.msg.group_delay_dep_b.sid.code, expected 0, is %d", + last_msg.msg.group_delay_dep_b.sid.code); + + ck_assert_msg( + last_msg.msg.group_delay_dep_b.sid.reserved == 0, + "incorrect value for last_msg.msg.group_delay_dep_b.sid.reserved, " + "expected 0, is %d", + last_msg.msg.group_delay_dep_b.sid.reserved); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.sid.sat == 22, + "incorrect value for last_msg.msg.group_delay_dep_b.sid.sat, " + "expected 22, is %d", + last_msg.msg.group_delay_dep_b.sid.sat); + + ck_assert_msg( + last_msg.msg.group_delay_dep_b.t_op.tow == 446384, + "incorrect value for last_msg.msg.group_delay_dep_b.t_op.tow, expected " + "446384, is %d", + last_msg.msg.group_delay_dep_b.t_op.tow); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.t_op.wn == 2154, + "incorrect value for last_msg.msg.group_delay_dep_b.t_op.wn, " + "expected 2154, is %d", + last_msg.msg.group_delay_dep_b.t_op.wn); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.tgd == -514, + "incorrect value for last_msg.msg.group_delay_dep_b.tgd, " + "expected -514, is %d", + last_msg.msg.group_delay_dep_b.tgd); + + ck_assert_msg(last_msg.msg.group_delay_dep_b.valid == 1, + "incorrect value for last_msg.msg.group_delay_dep_b.valid, " + "expected 1, is %d", + last_msg.msg.group_delay_dep_b.valid); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgGroupDelayDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgGroupDelayDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgGroupDelayDepB"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgGroupDelayDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgIono.c b/c/test/auto_check_sbp_observation_MsgIono.c new file mode 100644 index 0000000000..91e8662a08 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgIono.c @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgIono) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x90, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, 80, 62, 0, 0, 0, 0, + 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, + 0, 0, 243, 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, + 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, 101, 31, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.iono.a0 = 4.6566128730773926e-09; + + test_msg.iono.a1 = 1.4901161193847656e-08; + + test_msg.iono.a2 = -5.960464477539063e-08; + + test_msg.iono.a3 = -5.960464477539063e-08; + + test_msg.iono.b0 = 77824.0; + + test_msg.iono.b1 = 49152.0; + + test_msg.iono.b2 = -65536.0; + + test_msg.iono.b3 = -327680.0; + + test_msg.iono.t_nmct.tow = 0; + + test_msg.iono.t_nmct.wn = 0; + + sbp_message_send(&sbp_state, SbpMsgIono, 123, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgIono, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.iono.a0 * 100 - 4.65661287308e-09 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.a0, expected " + "4.65661287308e-09, is %s", + last_msg.msg.iono.a0); + + ck_assert_msg((last_msg.msg.iono.a1 * 100 - 1.49011611938e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.a1, expected " + "1.49011611938e-08, is %s", + last_msg.msg.iono.a1); + + ck_assert_msg( + (last_msg.msg.iono.a2 * 100 - -5.96046447754e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.a2, expected " + "-5.96046447754e-08, is %s", + last_msg.msg.iono.a2); + + ck_assert_msg( + (last_msg.msg.iono.a3 * 100 - -5.96046447754e-08 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.a3, expected " + "-5.96046447754e-08, is %s", + last_msg.msg.iono.a3); + + ck_assert_msg( + (last_msg.msg.iono.b0 * 100 - 77824.0 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.b0, expected 77824.0, is %s", + last_msg.msg.iono.b0); + + ck_assert_msg( + (last_msg.msg.iono.b1 * 100 - 49152.0 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.b1, expected 49152.0, is %s", + last_msg.msg.iono.b1); + + ck_assert_msg( + (last_msg.msg.iono.b2 * 100 - -65536.0 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.b2, expected -65536.0, is %s", + last_msg.msg.iono.b2); + + ck_assert_msg( + (last_msg.msg.iono.b3 * 100 - -327680.0 * 100) < 0.05, + "incorrect value for last_msg.msg.iono.b3, expected -327680.0, is %s", + last_msg.msg.iono.b3); + + ck_assert_msg( + last_msg.msg.iono.t_nmct.tow == 0, + "incorrect value for last_msg.msg.iono.t_nmct.tow, expected 0, is %d", + last_msg.msg.iono.t_nmct.tow); + + ck_assert_msg( + last_msg.msg.iono.t_nmct.wn == 0, + "incorrect value for last_msg.msg.iono.t_nmct.wn, expected 0, is %d", + last_msg.msg.iono.t_nmct.wn); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgIono_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_observation_MsgIono"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_observation_MsgIono"); + tcase_add_test(tc_acq, test_auto_check_sbp_observation_MsgIono); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c b/c/test/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c new file mode 100644 index 0000000000..0ec6273221 --- /dev/null +++ b/c/test/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_observation_MsgSvConfigurationGpsDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x91, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.sv_configuration_gps_dep.l2c_mask = 2808462402; + + test_msg.sv_configuration_gps_dep.t_nmct.tow = 0; + + test_msg.sv_configuration_gps_dep.t_nmct.wn = 0; + + sbp_message_send(&sbp_state, SbpMsgSvConfigurationGpsDep, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSvConfigurationGpsDep, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.sv_configuration_gps_dep.l2c_mask == 2808462402, + "incorrect value for last_msg.msg.sv_configuration_gps_dep.l2c_mask, " + "expected 2808462402, is %d", + last_msg.msg.sv_configuration_gps_dep.l2c_mask); + + ck_assert_msg( + last_msg.msg.sv_configuration_gps_dep.t_nmct.tow == 0, + "incorrect value for last_msg.msg.sv_configuration_gps_dep.t_nmct.tow, " + "expected 0, is %d", + last_msg.msg.sv_configuration_gps_dep.t_nmct.tow); + + ck_assert_msg( + last_msg.msg.sv_configuration_gps_dep.t_nmct.wn == 0, + "incorrect value for last_msg.msg.sv_configuration_gps_dep.t_nmct.wn, " + "expected 0, is %d", + last_msg.msg.sv_configuration_gps_dep.t_nmct.wn); + } +} +END_TEST + +Suite *auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_observation_MsgSvConfigurationGpsDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_observation_MsgSvConfigurationGpsDep"); + tcase_add_test(tc_acq, + test_auto_check_sbp_observation_MsgSvConfigurationGpsDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_orientation_MsgBaselineHeading.c b/c/test/auto_check_sbp_orientation_MsgBaselineHeading.c new file mode 100644 index 0000000000..f69089bae5 --- /dev/null +++ b/c/test/auto_check_sbp_orientation_MsgBaselineHeading.c @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_orientation_MsgBaselineHeading) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x20f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 15, 2, 211, 93, 10, 156, 45, 13, + 196, 44, 84, 197, 61, 91, 91, 224, 254, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.baseline_heading.flags = 91; + + test_msg.baseline_heading.heading = 1036342316; + + test_msg.baseline_heading.n_sats = 91; + + test_msg.baseline_heading.tow = 3289197980; + + sbp_message_send(&sbp_state, SbpMsgBaselineHeading, 24019, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 24019, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgBaselineHeading, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.baseline_heading.flags == 91, + "incorrect value for last_msg.msg.baseline_heading.flags, " + "expected 91, is %d", + last_msg.msg.baseline_heading.flags); + + ck_assert_msg(last_msg.msg.baseline_heading.heading == 1036342316, + "incorrect value for last_msg.msg.baseline_heading.heading, " + "expected 1036342316, is %d", + last_msg.msg.baseline_heading.heading); + + ck_assert_msg(last_msg.msg.baseline_heading.n_sats == 91, + "incorrect value for last_msg.msg.baseline_heading.n_sats, " + "expected 91, is %d", + last_msg.msg.baseline_heading.n_sats); + + ck_assert_msg(last_msg.msg.baseline_heading.tow == 3289197980, + "incorrect value for last_msg.msg.baseline_heading.tow, " + "expected 3289197980, is %d", + last_msg.msg.baseline_heading.tow); + } +} +END_TEST + +Suite *auto_check_sbp_orientation_MsgBaselineHeading_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_orientation_MsgBaselineHeading"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_orientation_MsgBaselineHeading"); + tcase_add_test(tc_acq, test_auto_check_sbp_orientation_MsgBaselineHeading); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgAlmanac.c b/c/test/auto_check_sbp_piksi_MsgAlmanac.c new file mode 100644 index 0000000000..79a14493ac --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgAlmanac.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgAlmanac) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x69, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 105, 0, 108, 138, 0, 249, 171, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgAlmanac, 35436, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 35436, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgAlmanac, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgAlmanac_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_piksi_MsgAlmanac"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgAlmanac"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgAlmanac); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCellModemStatus.c b/c/test/auto_check_sbp_piksi_MsgCellModemStatus.c new file mode 100644 index 0000000000..d0cd017009 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCellModemStatus.c @@ -0,0 +1,1934 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCellModemStatus) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xbe, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, + 52, 64, 176, 154, 98, 43, 132, 196, 89, 253, 161, 250, 174, 204, + 110, 47, 38, 187, 63, 102, 177, 162, 49, 80, 194, 37, 107, 60, + 225, 52, 101, 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, + 80, 243, 30, 206, 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, + 85, 146, 100, 190, 232, 207, 61, 61, 201, 220, 31, 78, 34, 57, + 82, 59, 104, 65, 221, 0, 43, 210, 9, 32, 122, 29, 237, 11, + 151, 223, 18, 81, 204, 172, 234, 127, 3, 82, 133, 169, 12, 176, + 193, 0, 24, 121, 85, 55, 214, 198, 75, 234, 179, 214, 85, 94, + 115, 21, 73, 121, 75, 46, 158, 63, 100, 122, 213, 20, 85, 212, + 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, 39, 164, 5, 175, + 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, 177, 0, 47, + 140, 33, 126, 221, 110, 144, 97, 74, 250, 181, 199, 27, 176, 65, + 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, 4, 90, 36, 7, + 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, + 83, 16, 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, + 141, 232, 33, 101, 231, 38, 75, 178, 243, 119, 1, 248, 218, 86, + 7, 88, 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, 156, 217, + 67, 239, 219, 31, 224, 176, 129, 81, 80, 40, 230, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.cell_modem_status.n_reserved = 250; + + test_msg.cell_modem_status.reserved[0] = 123; + + test_msg.cell_modem_status.reserved[1] = 242; + + test_msg.cell_modem_status.reserved[2] = 46; + + test_msg.cell_modem_status.reserved[3] = 52; + + test_msg.cell_modem_status.reserved[4] = 64; + + test_msg.cell_modem_status.reserved[5] = 176; + + test_msg.cell_modem_status.reserved[6] = 154; + + test_msg.cell_modem_status.reserved[7] = 98; + + test_msg.cell_modem_status.reserved[8] = 43; + + test_msg.cell_modem_status.reserved[9] = 132; + + test_msg.cell_modem_status.reserved[10] = 196; + + test_msg.cell_modem_status.reserved[11] = 89; + + test_msg.cell_modem_status.reserved[12] = 253; + + test_msg.cell_modem_status.reserved[13] = 161; + + test_msg.cell_modem_status.reserved[14] = 250; + + test_msg.cell_modem_status.reserved[15] = 174; + + test_msg.cell_modem_status.reserved[16] = 204; + + test_msg.cell_modem_status.reserved[17] = 110; + + test_msg.cell_modem_status.reserved[18] = 47; + + test_msg.cell_modem_status.reserved[19] = 38; + + test_msg.cell_modem_status.reserved[20] = 187; + + test_msg.cell_modem_status.reserved[21] = 63; + + test_msg.cell_modem_status.reserved[22] = 102; + + test_msg.cell_modem_status.reserved[23] = 177; + + test_msg.cell_modem_status.reserved[24] = 162; + + test_msg.cell_modem_status.reserved[25] = 49; + + test_msg.cell_modem_status.reserved[26] = 80; + + test_msg.cell_modem_status.reserved[27] = 194; + + test_msg.cell_modem_status.reserved[28] = 37; + + test_msg.cell_modem_status.reserved[29] = 107; + + test_msg.cell_modem_status.reserved[30] = 60; + + test_msg.cell_modem_status.reserved[31] = 225; + + test_msg.cell_modem_status.reserved[32] = 52; + + test_msg.cell_modem_status.reserved[33] = 101; + + test_msg.cell_modem_status.reserved[34] = 178; + + test_msg.cell_modem_status.reserved[35] = 142; + + test_msg.cell_modem_status.reserved[36] = 246; + + test_msg.cell_modem_status.reserved[37] = 21; + + test_msg.cell_modem_status.reserved[38] = 17; + + test_msg.cell_modem_status.reserved[39] = 93; + + test_msg.cell_modem_status.reserved[40] = 75; + + test_msg.cell_modem_status.reserved[41] = 169; + + test_msg.cell_modem_status.reserved[42] = 86; + + test_msg.cell_modem_status.reserved[43] = 16; + + test_msg.cell_modem_status.reserved[44] = 209; + + test_msg.cell_modem_status.reserved[45] = 80; + + test_msg.cell_modem_status.reserved[46] = 243; + + test_msg.cell_modem_status.reserved[47] = 30; + + test_msg.cell_modem_status.reserved[48] = 206; + + test_msg.cell_modem_status.reserved[49] = 220; + + test_msg.cell_modem_status.reserved[50] = 206; + + test_msg.cell_modem_status.reserved[51] = 115; + + test_msg.cell_modem_status.reserved[52] = 47; + + test_msg.cell_modem_status.reserved[53] = 154; + + test_msg.cell_modem_status.reserved[54] = 91; + + test_msg.cell_modem_status.reserved[55] = 227; + + test_msg.cell_modem_status.reserved[56] = 88; + + test_msg.cell_modem_status.reserved[57] = 11; + + test_msg.cell_modem_status.reserved[58] = 1; + + test_msg.cell_modem_status.reserved[59] = 85; + + test_msg.cell_modem_status.reserved[60] = 146; + + test_msg.cell_modem_status.reserved[61] = 100; + + test_msg.cell_modem_status.reserved[62] = 190; + + test_msg.cell_modem_status.reserved[63] = 232; + + test_msg.cell_modem_status.reserved[64] = 207; + + test_msg.cell_modem_status.reserved[65] = 61; + + test_msg.cell_modem_status.reserved[66] = 61; + + test_msg.cell_modem_status.reserved[67] = 201; + + test_msg.cell_modem_status.reserved[68] = 220; + + test_msg.cell_modem_status.reserved[69] = 31; + + test_msg.cell_modem_status.reserved[70] = 78; + + test_msg.cell_modem_status.reserved[71] = 34; + + test_msg.cell_modem_status.reserved[72] = 57; + + test_msg.cell_modem_status.reserved[73] = 82; + + test_msg.cell_modem_status.reserved[74] = 59; + + test_msg.cell_modem_status.reserved[75] = 104; + + test_msg.cell_modem_status.reserved[76] = 65; + + test_msg.cell_modem_status.reserved[77] = 221; + + test_msg.cell_modem_status.reserved[78] = 0; + + test_msg.cell_modem_status.reserved[79] = 43; + + test_msg.cell_modem_status.reserved[80] = 210; + + test_msg.cell_modem_status.reserved[81] = 9; + + test_msg.cell_modem_status.reserved[82] = 32; + + test_msg.cell_modem_status.reserved[83] = 122; + + test_msg.cell_modem_status.reserved[84] = 29; + + test_msg.cell_modem_status.reserved[85] = 237; + + test_msg.cell_modem_status.reserved[86] = 11; + + test_msg.cell_modem_status.reserved[87] = 151; + + test_msg.cell_modem_status.reserved[88] = 223; + + test_msg.cell_modem_status.reserved[89] = 18; + + test_msg.cell_modem_status.reserved[90] = 81; + + test_msg.cell_modem_status.reserved[91] = 204; + + test_msg.cell_modem_status.reserved[92] = 172; + + test_msg.cell_modem_status.reserved[93] = 234; + + test_msg.cell_modem_status.reserved[94] = 127; + + test_msg.cell_modem_status.reserved[95] = 3; + + test_msg.cell_modem_status.reserved[96] = 82; + + test_msg.cell_modem_status.reserved[97] = 133; + + test_msg.cell_modem_status.reserved[98] = 169; + + test_msg.cell_modem_status.reserved[99] = 12; + + test_msg.cell_modem_status.reserved[100] = 176; + + test_msg.cell_modem_status.reserved[101] = 193; + + test_msg.cell_modem_status.reserved[102] = 0; + + test_msg.cell_modem_status.reserved[103] = 24; + + test_msg.cell_modem_status.reserved[104] = 121; + + test_msg.cell_modem_status.reserved[105] = 85; + + test_msg.cell_modem_status.reserved[106] = 55; + + test_msg.cell_modem_status.reserved[107] = 214; + + test_msg.cell_modem_status.reserved[108] = 198; + + test_msg.cell_modem_status.reserved[109] = 75; + + test_msg.cell_modem_status.reserved[110] = 234; + + test_msg.cell_modem_status.reserved[111] = 179; + + test_msg.cell_modem_status.reserved[112] = 214; + + test_msg.cell_modem_status.reserved[113] = 85; + + test_msg.cell_modem_status.reserved[114] = 94; + + test_msg.cell_modem_status.reserved[115] = 115; + + test_msg.cell_modem_status.reserved[116] = 21; + + test_msg.cell_modem_status.reserved[117] = 73; + + test_msg.cell_modem_status.reserved[118] = 121; + + test_msg.cell_modem_status.reserved[119] = 75; + + test_msg.cell_modem_status.reserved[120] = 46; + + test_msg.cell_modem_status.reserved[121] = 158; + + test_msg.cell_modem_status.reserved[122] = 63; + + test_msg.cell_modem_status.reserved[123] = 100; + + test_msg.cell_modem_status.reserved[124] = 122; + + test_msg.cell_modem_status.reserved[125] = 213; + + test_msg.cell_modem_status.reserved[126] = 20; + + test_msg.cell_modem_status.reserved[127] = 85; + + test_msg.cell_modem_status.reserved[128] = 212; + + test_msg.cell_modem_status.reserved[129] = 131; + + test_msg.cell_modem_status.reserved[130] = 50; + + test_msg.cell_modem_status.reserved[131] = 224; + + test_msg.cell_modem_status.reserved[132] = 218; + + test_msg.cell_modem_status.reserved[133] = 215; + + test_msg.cell_modem_status.reserved[134] = 215; + + test_msg.cell_modem_status.reserved[135] = 149; + + test_msg.cell_modem_status.reserved[136] = 2; + + test_msg.cell_modem_status.reserved[137] = 19; + + test_msg.cell_modem_status.reserved[138] = 129; + + test_msg.cell_modem_status.reserved[139] = 39; + + test_msg.cell_modem_status.reserved[140] = 164; + + test_msg.cell_modem_status.reserved[141] = 5; + + test_msg.cell_modem_status.reserved[142] = 175; + + test_msg.cell_modem_status.reserved[143] = 6; + + test_msg.cell_modem_status.reserved[144] = 62; + + test_msg.cell_modem_status.reserved[145] = 51; + + test_msg.cell_modem_status.reserved[146] = 78; + + test_msg.cell_modem_status.reserved[147] = 66; + + test_msg.cell_modem_status.reserved[148] = 248; + + test_msg.cell_modem_status.reserved[149] = 116; + + test_msg.cell_modem_status.reserved[150] = 88; + + test_msg.cell_modem_status.reserved[151] = 90; + + test_msg.cell_modem_status.reserved[152] = 128; + + test_msg.cell_modem_status.reserved[153] = 226; + + test_msg.cell_modem_status.reserved[154] = 177; + + test_msg.cell_modem_status.reserved[155] = 0; + + test_msg.cell_modem_status.reserved[156] = 47; + + test_msg.cell_modem_status.reserved[157] = 140; + + test_msg.cell_modem_status.reserved[158] = 33; + + test_msg.cell_modem_status.reserved[159] = 126; + + test_msg.cell_modem_status.reserved[160] = 221; + + test_msg.cell_modem_status.reserved[161] = 110; + + test_msg.cell_modem_status.reserved[162] = 144; + + test_msg.cell_modem_status.reserved[163] = 97; + + test_msg.cell_modem_status.reserved[164] = 74; + + test_msg.cell_modem_status.reserved[165] = 250; + + test_msg.cell_modem_status.reserved[166] = 181; + + test_msg.cell_modem_status.reserved[167] = 199; + + test_msg.cell_modem_status.reserved[168] = 27; + + test_msg.cell_modem_status.reserved[169] = 176; + + test_msg.cell_modem_status.reserved[170] = 65; + + test_msg.cell_modem_status.reserved[171] = 185; + + test_msg.cell_modem_status.reserved[172] = 110; + + test_msg.cell_modem_status.reserved[173] = 92; + + test_msg.cell_modem_status.reserved[174] = 34; + + test_msg.cell_modem_status.reserved[175] = 44; + + test_msg.cell_modem_status.reserved[176] = 131; + + test_msg.cell_modem_status.reserved[177] = 96; + + test_msg.cell_modem_status.reserved[178] = 178; + + test_msg.cell_modem_status.reserved[179] = 40; + + test_msg.cell_modem_status.reserved[180] = 176; + + test_msg.cell_modem_status.reserved[181] = 4; + + test_msg.cell_modem_status.reserved[182] = 90; + + test_msg.cell_modem_status.reserved[183] = 36; + + test_msg.cell_modem_status.reserved[184] = 7; + + test_msg.cell_modem_status.reserved[185] = 180; + + test_msg.cell_modem_status.reserved[186] = 244; + + test_msg.cell_modem_status.reserved[187] = 244; + + test_msg.cell_modem_status.reserved[188] = 23; + + test_msg.cell_modem_status.reserved[189] = 108; + + test_msg.cell_modem_status.reserved[190] = 171; + + test_msg.cell_modem_status.reserved[191] = 204; + + test_msg.cell_modem_status.reserved[192] = 196; + + test_msg.cell_modem_status.reserved[193] = 61; + + test_msg.cell_modem_status.reserved[194] = 51; + + test_msg.cell_modem_status.reserved[195] = 179; + + test_msg.cell_modem_status.reserved[196] = 242; + + test_msg.cell_modem_status.reserved[197] = 156; + + test_msg.cell_modem_status.reserved[198] = 81; + + test_msg.cell_modem_status.reserved[199] = 83; + + test_msg.cell_modem_status.reserved[200] = 16; + + test_msg.cell_modem_status.reserved[201] = 15; + + test_msg.cell_modem_status.reserved[202] = 134; + + test_msg.cell_modem_status.reserved[203] = 40; + + test_msg.cell_modem_status.reserved[204] = 245; + + test_msg.cell_modem_status.reserved[205] = 253; + + test_msg.cell_modem_status.reserved[206] = 150; + + test_msg.cell_modem_status.reserved[207] = 94; + + test_msg.cell_modem_status.reserved[208] = 150; + + test_msg.cell_modem_status.reserved[209] = 144; + + test_msg.cell_modem_status.reserved[210] = 197; + + test_msg.cell_modem_status.reserved[211] = 113; + + test_msg.cell_modem_status.reserved[212] = 5; + + test_msg.cell_modem_status.reserved[213] = 141; + + test_msg.cell_modem_status.reserved[214] = 232; + + test_msg.cell_modem_status.reserved[215] = 33; + + test_msg.cell_modem_status.reserved[216] = 101; + + test_msg.cell_modem_status.reserved[217] = 231; + + test_msg.cell_modem_status.reserved[218] = 38; + + test_msg.cell_modem_status.reserved[219] = 75; + + test_msg.cell_modem_status.reserved[220] = 178; + + test_msg.cell_modem_status.reserved[221] = 243; + + test_msg.cell_modem_status.reserved[222] = 119; + + test_msg.cell_modem_status.reserved[223] = 1; + + test_msg.cell_modem_status.reserved[224] = 248; + + test_msg.cell_modem_status.reserved[225] = 218; + + test_msg.cell_modem_status.reserved[226] = 86; + + test_msg.cell_modem_status.reserved[227] = 7; + + test_msg.cell_modem_status.reserved[228] = 88; + + test_msg.cell_modem_status.reserved[229] = 197; + + test_msg.cell_modem_status.reserved[230] = 148; + + test_msg.cell_modem_status.reserved[231] = 240; + + test_msg.cell_modem_status.reserved[232] = 227; + + test_msg.cell_modem_status.reserved[233] = 2; + + test_msg.cell_modem_status.reserved[234] = 65; + + test_msg.cell_modem_status.reserved[235] = 173; + + test_msg.cell_modem_status.reserved[236] = 122; + + test_msg.cell_modem_status.reserved[237] = 143; + + test_msg.cell_modem_status.reserved[238] = 251; + + test_msg.cell_modem_status.reserved[239] = 156; + + test_msg.cell_modem_status.reserved[240] = 217; + + test_msg.cell_modem_status.reserved[241] = 67; + + test_msg.cell_modem_status.reserved[242] = 239; + + test_msg.cell_modem_status.reserved[243] = 219; + + test_msg.cell_modem_status.reserved[244] = 31; + + test_msg.cell_modem_status.reserved[245] = 224; + + test_msg.cell_modem_status.reserved[246] = 176; + + test_msg.cell_modem_status.reserved[247] = 129; + + test_msg.cell_modem_status.reserved[248] = 81; + + test_msg.cell_modem_status.reserved[249] = 80; + + test_msg.cell_modem_status.signal_error_rate = 8588.2001953125; + + test_msg.cell_modem_status.signal_strength = 103; + + sbp_message_send(&sbp_state, SbpMsgCellModemStatus, 6931, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 6931, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCellModemStatus, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.cell_modem_status.n_reserved == 250, + "incorrect value for last_msg.msg.cell_modem_status.n_reserved, " + "expected 250, is %d", + last_msg.msg.cell_modem_status.n_reserved); + + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[0] == 123, + "incorrect value for last_msg.msg.cell_modem_status.reserved[0], " + "expected 123, is %d", + last_msg.msg.cell_modem_status.reserved[0]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[1] == 242, + "incorrect value for last_msg.msg.cell_modem_status.reserved[1], " + "expected 242, is %d", + last_msg.msg.cell_modem_status.reserved[1]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[2] == 46, + "incorrect value for last_msg.msg.cell_modem_status.reserved[2], " + "expected 46, is %d", + last_msg.msg.cell_modem_status.reserved[2]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[3] == 52, + "incorrect value for last_msg.msg.cell_modem_status.reserved[3], " + "expected 52, is %d", + last_msg.msg.cell_modem_status.reserved[3]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[4] == 64, + "incorrect value for last_msg.msg.cell_modem_status.reserved[4], " + "expected 64, is %d", + last_msg.msg.cell_modem_status.reserved[4]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[5] == 176, + "incorrect value for last_msg.msg.cell_modem_status.reserved[5], " + "expected 176, is %d", + last_msg.msg.cell_modem_status.reserved[5]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[6] == 154, + "incorrect value for last_msg.msg.cell_modem_status.reserved[6], " + "expected 154, is %d", + last_msg.msg.cell_modem_status.reserved[6]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[7] == 98, + "incorrect value for last_msg.msg.cell_modem_status.reserved[7], " + "expected 98, is %d", + last_msg.msg.cell_modem_status.reserved[7]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[8] == 43, + "incorrect value for last_msg.msg.cell_modem_status.reserved[8], " + "expected 43, is %d", + last_msg.msg.cell_modem_status.reserved[8]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[9] == 132, + "incorrect value for last_msg.msg.cell_modem_status.reserved[9], " + "expected 132, is %d", + last_msg.msg.cell_modem_status.reserved[9]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[10] == 196, + "incorrect value for last_msg.msg.cell_modem_status.reserved[10], " + "expected 196, is %d", + last_msg.msg.cell_modem_status.reserved[10]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[11] == 89, + "incorrect value for last_msg.msg.cell_modem_status.reserved[11], " + "expected 89, is %d", + last_msg.msg.cell_modem_status.reserved[11]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[12] == 253, + "incorrect value for last_msg.msg.cell_modem_status.reserved[12], " + "expected 253, is %d", + last_msg.msg.cell_modem_status.reserved[12]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[13] == 161, + "incorrect value for last_msg.msg.cell_modem_status.reserved[13], " + "expected 161, is %d", + last_msg.msg.cell_modem_status.reserved[13]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[14] == 250, + "incorrect value for last_msg.msg.cell_modem_status.reserved[14], " + "expected 250, is %d", + last_msg.msg.cell_modem_status.reserved[14]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[15] == 174, + "incorrect value for last_msg.msg.cell_modem_status.reserved[15], " + "expected 174, is %d", + last_msg.msg.cell_modem_status.reserved[15]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[16] == 204, + "incorrect value for last_msg.msg.cell_modem_status.reserved[16], " + "expected 204, is %d", + last_msg.msg.cell_modem_status.reserved[16]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[17] == 110, + "incorrect value for last_msg.msg.cell_modem_status.reserved[17], " + "expected 110, is %d", + last_msg.msg.cell_modem_status.reserved[17]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[18] == 47, + "incorrect value for last_msg.msg.cell_modem_status.reserved[18], " + "expected 47, is %d", + last_msg.msg.cell_modem_status.reserved[18]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[19] == 38, + "incorrect value for last_msg.msg.cell_modem_status.reserved[19], " + "expected 38, is %d", + last_msg.msg.cell_modem_status.reserved[19]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[20] == 187, + "incorrect value for last_msg.msg.cell_modem_status.reserved[20], " + "expected 187, is %d", + last_msg.msg.cell_modem_status.reserved[20]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[21] == 63, + "incorrect value for last_msg.msg.cell_modem_status.reserved[21], " + "expected 63, is %d", + last_msg.msg.cell_modem_status.reserved[21]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[22] == 102, + "incorrect value for last_msg.msg.cell_modem_status.reserved[22], " + "expected 102, is %d", + last_msg.msg.cell_modem_status.reserved[22]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[23] == 177, + "incorrect value for last_msg.msg.cell_modem_status.reserved[23], " + "expected 177, is %d", + last_msg.msg.cell_modem_status.reserved[23]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[24] == 162, + "incorrect value for last_msg.msg.cell_modem_status.reserved[24], " + "expected 162, is %d", + last_msg.msg.cell_modem_status.reserved[24]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[25] == 49, + "incorrect value for last_msg.msg.cell_modem_status.reserved[25], " + "expected 49, is %d", + last_msg.msg.cell_modem_status.reserved[25]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[26] == 80, + "incorrect value for last_msg.msg.cell_modem_status.reserved[26], " + "expected 80, is %d", + last_msg.msg.cell_modem_status.reserved[26]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[27] == 194, + "incorrect value for last_msg.msg.cell_modem_status.reserved[27], " + "expected 194, is %d", + last_msg.msg.cell_modem_status.reserved[27]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[28] == 37, + "incorrect value for last_msg.msg.cell_modem_status.reserved[28], " + "expected 37, is %d", + last_msg.msg.cell_modem_status.reserved[28]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[29] == 107, + "incorrect value for last_msg.msg.cell_modem_status.reserved[29], " + "expected 107, is %d", + last_msg.msg.cell_modem_status.reserved[29]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[30] == 60, + "incorrect value for last_msg.msg.cell_modem_status.reserved[30], " + "expected 60, is %d", + last_msg.msg.cell_modem_status.reserved[30]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[31] == 225, + "incorrect value for last_msg.msg.cell_modem_status.reserved[31], " + "expected 225, is %d", + last_msg.msg.cell_modem_status.reserved[31]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[32] == 52, + "incorrect value for last_msg.msg.cell_modem_status.reserved[32], " + "expected 52, is %d", + last_msg.msg.cell_modem_status.reserved[32]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[33] == 101, + "incorrect value for last_msg.msg.cell_modem_status.reserved[33], " + "expected 101, is %d", + last_msg.msg.cell_modem_status.reserved[33]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[34] == 178, + "incorrect value for last_msg.msg.cell_modem_status.reserved[34], " + "expected 178, is %d", + last_msg.msg.cell_modem_status.reserved[34]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[35] == 142, + "incorrect value for last_msg.msg.cell_modem_status.reserved[35], " + "expected 142, is %d", + last_msg.msg.cell_modem_status.reserved[35]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[36] == 246, + "incorrect value for last_msg.msg.cell_modem_status.reserved[36], " + "expected 246, is %d", + last_msg.msg.cell_modem_status.reserved[36]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[37] == 21, + "incorrect value for last_msg.msg.cell_modem_status.reserved[37], " + "expected 21, is %d", + last_msg.msg.cell_modem_status.reserved[37]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[38] == 17, + "incorrect value for last_msg.msg.cell_modem_status.reserved[38], " + "expected 17, is %d", + last_msg.msg.cell_modem_status.reserved[38]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[39] == 93, + "incorrect value for last_msg.msg.cell_modem_status.reserved[39], " + "expected 93, is %d", + last_msg.msg.cell_modem_status.reserved[39]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[40] == 75, + "incorrect value for last_msg.msg.cell_modem_status.reserved[40], " + "expected 75, is %d", + last_msg.msg.cell_modem_status.reserved[40]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[41] == 169, + "incorrect value for last_msg.msg.cell_modem_status.reserved[41], " + "expected 169, is %d", + last_msg.msg.cell_modem_status.reserved[41]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[42] == 86, + "incorrect value for last_msg.msg.cell_modem_status.reserved[42], " + "expected 86, is %d", + last_msg.msg.cell_modem_status.reserved[42]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[43] == 16, + "incorrect value for last_msg.msg.cell_modem_status.reserved[43], " + "expected 16, is %d", + last_msg.msg.cell_modem_status.reserved[43]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[44] == 209, + "incorrect value for last_msg.msg.cell_modem_status.reserved[44], " + "expected 209, is %d", + last_msg.msg.cell_modem_status.reserved[44]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[45] == 80, + "incorrect value for last_msg.msg.cell_modem_status.reserved[45], " + "expected 80, is %d", + last_msg.msg.cell_modem_status.reserved[45]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[46] == 243, + "incorrect value for last_msg.msg.cell_modem_status.reserved[46], " + "expected 243, is %d", + last_msg.msg.cell_modem_status.reserved[46]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[47] == 30, + "incorrect value for last_msg.msg.cell_modem_status.reserved[47], " + "expected 30, is %d", + last_msg.msg.cell_modem_status.reserved[47]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[48] == 206, + "incorrect value for last_msg.msg.cell_modem_status.reserved[48], " + "expected 206, is %d", + last_msg.msg.cell_modem_status.reserved[48]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[49] == 220, + "incorrect value for last_msg.msg.cell_modem_status.reserved[49], " + "expected 220, is %d", + last_msg.msg.cell_modem_status.reserved[49]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[50] == 206, + "incorrect value for last_msg.msg.cell_modem_status.reserved[50], " + "expected 206, is %d", + last_msg.msg.cell_modem_status.reserved[50]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[51] == 115, + "incorrect value for last_msg.msg.cell_modem_status.reserved[51], " + "expected 115, is %d", + last_msg.msg.cell_modem_status.reserved[51]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[52] == 47, + "incorrect value for last_msg.msg.cell_modem_status.reserved[52], " + "expected 47, is %d", + last_msg.msg.cell_modem_status.reserved[52]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[53] == 154, + "incorrect value for last_msg.msg.cell_modem_status.reserved[53], " + "expected 154, is %d", + last_msg.msg.cell_modem_status.reserved[53]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[54] == 91, + "incorrect value for last_msg.msg.cell_modem_status.reserved[54], " + "expected 91, is %d", + last_msg.msg.cell_modem_status.reserved[54]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[55] == 227, + "incorrect value for last_msg.msg.cell_modem_status.reserved[55], " + "expected 227, is %d", + last_msg.msg.cell_modem_status.reserved[55]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[56] == 88, + "incorrect value for last_msg.msg.cell_modem_status.reserved[56], " + "expected 88, is %d", + last_msg.msg.cell_modem_status.reserved[56]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[57] == 11, + "incorrect value for last_msg.msg.cell_modem_status.reserved[57], " + "expected 11, is %d", + last_msg.msg.cell_modem_status.reserved[57]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[58] == 1, + "incorrect value for last_msg.msg.cell_modem_status.reserved[58], " + "expected 1, is %d", + last_msg.msg.cell_modem_status.reserved[58]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[59] == 85, + "incorrect value for last_msg.msg.cell_modem_status.reserved[59], " + "expected 85, is %d", + last_msg.msg.cell_modem_status.reserved[59]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[60] == 146, + "incorrect value for last_msg.msg.cell_modem_status.reserved[60], " + "expected 146, is %d", + last_msg.msg.cell_modem_status.reserved[60]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[61] == 100, + "incorrect value for last_msg.msg.cell_modem_status.reserved[61], " + "expected 100, is %d", + last_msg.msg.cell_modem_status.reserved[61]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[62] == 190, + "incorrect value for last_msg.msg.cell_modem_status.reserved[62], " + "expected 190, is %d", + last_msg.msg.cell_modem_status.reserved[62]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[63] == 232, + "incorrect value for last_msg.msg.cell_modem_status.reserved[63], " + "expected 232, is %d", + last_msg.msg.cell_modem_status.reserved[63]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[64] == 207, + "incorrect value for last_msg.msg.cell_modem_status.reserved[64], " + "expected 207, is %d", + last_msg.msg.cell_modem_status.reserved[64]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[65] == 61, + "incorrect value for last_msg.msg.cell_modem_status.reserved[65], " + "expected 61, is %d", + last_msg.msg.cell_modem_status.reserved[65]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[66] == 61, + "incorrect value for last_msg.msg.cell_modem_status.reserved[66], " + "expected 61, is %d", + last_msg.msg.cell_modem_status.reserved[66]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[67] == 201, + "incorrect value for last_msg.msg.cell_modem_status.reserved[67], " + "expected 201, is %d", + last_msg.msg.cell_modem_status.reserved[67]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[68] == 220, + "incorrect value for last_msg.msg.cell_modem_status.reserved[68], " + "expected 220, is %d", + last_msg.msg.cell_modem_status.reserved[68]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[69] == 31, + "incorrect value for last_msg.msg.cell_modem_status.reserved[69], " + "expected 31, is %d", + last_msg.msg.cell_modem_status.reserved[69]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[70] == 78, + "incorrect value for last_msg.msg.cell_modem_status.reserved[70], " + "expected 78, is %d", + last_msg.msg.cell_modem_status.reserved[70]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[71] == 34, + "incorrect value for last_msg.msg.cell_modem_status.reserved[71], " + "expected 34, is %d", + last_msg.msg.cell_modem_status.reserved[71]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[72] == 57, + "incorrect value for last_msg.msg.cell_modem_status.reserved[72], " + "expected 57, is %d", + last_msg.msg.cell_modem_status.reserved[72]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[73] == 82, + "incorrect value for last_msg.msg.cell_modem_status.reserved[73], " + "expected 82, is %d", + last_msg.msg.cell_modem_status.reserved[73]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[74] == 59, + "incorrect value for last_msg.msg.cell_modem_status.reserved[74], " + "expected 59, is %d", + last_msg.msg.cell_modem_status.reserved[74]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[75] == 104, + "incorrect value for last_msg.msg.cell_modem_status.reserved[75], " + "expected 104, is %d", + last_msg.msg.cell_modem_status.reserved[75]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[76] == 65, + "incorrect value for last_msg.msg.cell_modem_status.reserved[76], " + "expected 65, is %d", + last_msg.msg.cell_modem_status.reserved[76]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[77] == 221, + "incorrect value for last_msg.msg.cell_modem_status.reserved[77], " + "expected 221, is %d", + last_msg.msg.cell_modem_status.reserved[77]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[78] == 0, + "incorrect value for last_msg.msg.cell_modem_status.reserved[78], " + "expected 0, is %d", + last_msg.msg.cell_modem_status.reserved[78]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[79] == 43, + "incorrect value for last_msg.msg.cell_modem_status.reserved[79], " + "expected 43, is %d", + last_msg.msg.cell_modem_status.reserved[79]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[80] == 210, + "incorrect value for last_msg.msg.cell_modem_status.reserved[80], " + "expected 210, is %d", + last_msg.msg.cell_modem_status.reserved[80]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[81] == 9, + "incorrect value for last_msg.msg.cell_modem_status.reserved[81], " + "expected 9, is %d", + last_msg.msg.cell_modem_status.reserved[81]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[82] == 32, + "incorrect value for last_msg.msg.cell_modem_status.reserved[82], " + "expected 32, is %d", + last_msg.msg.cell_modem_status.reserved[82]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[83] == 122, + "incorrect value for last_msg.msg.cell_modem_status.reserved[83], " + "expected 122, is %d", + last_msg.msg.cell_modem_status.reserved[83]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[84] == 29, + "incorrect value for last_msg.msg.cell_modem_status.reserved[84], " + "expected 29, is %d", + last_msg.msg.cell_modem_status.reserved[84]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[85] == 237, + "incorrect value for last_msg.msg.cell_modem_status.reserved[85], " + "expected 237, is %d", + last_msg.msg.cell_modem_status.reserved[85]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[86] == 11, + "incorrect value for last_msg.msg.cell_modem_status.reserved[86], " + "expected 11, is %d", + last_msg.msg.cell_modem_status.reserved[86]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[87] == 151, + "incorrect value for last_msg.msg.cell_modem_status.reserved[87], " + "expected 151, is %d", + last_msg.msg.cell_modem_status.reserved[87]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[88] == 223, + "incorrect value for last_msg.msg.cell_modem_status.reserved[88], " + "expected 223, is %d", + last_msg.msg.cell_modem_status.reserved[88]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[89] == 18, + "incorrect value for last_msg.msg.cell_modem_status.reserved[89], " + "expected 18, is %d", + last_msg.msg.cell_modem_status.reserved[89]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[90] == 81, + "incorrect value for last_msg.msg.cell_modem_status.reserved[90], " + "expected 81, is %d", + last_msg.msg.cell_modem_status.reserved[90]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[91] == 204, + "incorrect value for last_msg.msg.cell_modem_status.reserved[91], " + "expected 204, is %d", + last_msg.msg.cell_modem_status.reserved[91]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[92] == 172, + "incorrect value for last_msg.msg.cell_modem_status.reserved[92], " + "expected 172, is %d", + last_msg.msg.cell_modem_status.reserved[92]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[93] == 234, + "incorrect value for last_msg.msg.cell_modem_status.reserved[93], " + "expected 234, is %d", + last_msg.msg.cell_modem_status.reserved[93]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[94] == 127, + "incorrect value for last_msg.msg.cell_modem_status.reserved[94], " + "expected 127, is %d", + last_msg.msg.cell_modem_status.reserved[94]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[95] == 3, + "incorrect value for last_msg.msg.cell_modem_status.reserved[95], " + "expected 3, is %d", + last_msg.msg.cell_modem_status.reserved[95]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[96] == 82, + "incorrect value for last_msg.msg.cell_modem_status.reserved[96], " + "expected 82, is %d", + last_msg.msg.cell_modem_status.reserved[96]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[97] == 133, + "incorrect value for last_msg.msg.cell_modem_status.reserved[97], " + "expected 133, is %d", + last_msg.msg.cell_modem_status.reserved[97]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[98] == 169, + "incorrect value for last_msg.msg.cell_modem_status.reserved[98], " + "expected 169, is %d", + last_msg.msg.cell_modem_status.reserved[98]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[99] == 12, + "incorrect value for last_msg.msg.cell_modem_status.reserved[99], " + "expected 12, is %d", + last_msg.msg.cell_modem_status.reserved[99]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[100] == 176, + "incorrect value for last_msg.msg.cell_modem_status.reserved[100], " + "expected 176, is %d", + last_msg.msg.cell_modem_status.reserved[100]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[101] == 193, + "incorrect value for last_msg.msg.cell_modem_status.reserved[101], " + "expected 193, is %d", + last_msg.msg.cell_modem_status.reserved[101]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[102] == 0, + "incorrect value for last_msg.msg.cell_modem_status.reserved[102], " + "expected 0, is %d", + last_msg.msg.cell_modem_status.reserved[102]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[103] == 24, + "incorrect value for last_msg.msg.cell_modem_status.reserved[103], " + "expected 24, is %d", + last_msg.msg.cell_modem_status.reserved[103]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[104] == 121, + "incorrect value for last_msg.msg.cell_modem_status.reserved[104], " + "expected 121, is %d", + last_msg.msg.cell_modem_status.reserved[104]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[105] == 85, + "incorrect value for last_msg.msg.cell_modem_status.reserved[105], " + "expected 85, is %d", + last_msg.msg.cell_modem_status.reserved[105]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[106] == 55, + "incorrect value for last_msg.msg.cell_modem_status.reserved[106], " + "expected 55, is %d", + last_msg.msg.cell_modem_status.reserved[106]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[107] == 214, + "incorrect value for last_msg.msg.cell_modem_status.reserved[107], " + "expected 214, is %d", + last_msg.msg.cell_modem_status.reserved[107]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[108] == 198, + "incorrect value for last_msg.msg.cell_modem_status.reserved[108], " + "expected 198, is %d", + last_msg.msg.cell_modem_status.reserved[108]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[109] == 75, + "incorrect value for last_msg.msg.cell_modem_status.reserved[109], " + "expected 75, is %d", + last_msg.msg.cell_modem_status.reserved[109]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[110] == 234, + "incorrect value for last_msg.msg.cell_modem_status.reserved[110], " + "expected 234, is %d", + last_msg.msg.cell_modem_status.reserved[110]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[111] == 179, + "incorrect value for last_msg.msg.cell_modem_status.reserved[111], " + "expected 179, is %d", + last_msg.msg.cell_modem_status.reserved[111]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[112] == 214, + "incorrect value for last_msg.msg.cell_modem_status.reserved[112], " + "expected 214, is %d", + last_msg.msg.cell_modem_status.reserved[112]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[113] == 85, + "incorrect value for last_msg.msg.cell_modem_status.reserved[113], " + "expected 85, is %d", + last_msg.msg.cell_modem_status.reserved[113]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[114] == 94, + "incorrect value for last_msg.msg.cell_modem_status.reserved[114], " + "expected 94, is %d", + last_msg.msg.cell_modem_status.reserved[114]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[115] == 115, + "incorrect value for last_msg.msg.cell_modem_status.reserved[115], " + "expected 115, is %d", + last_msg.msg.cell_modem_status.reserved[115]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[116] == 21, + "incorrect value for last_msg.msg.cell_modem_status.reserved[116], " + "expected 21, is %d", + last_msg.msg.cell_modem_status.reserved[116]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[117] == 73, + "incorrect value for last_msg.msg.cell_modem_status.reserved[117], " + "expected 73, is %d", + last_msg.msg.cell_modem_status.reserved[117]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[118] == 121, + "incorrect value for last_msg.msg.cell_modem_status.reserved[118], " + "expected 121, is %d", + last_msg.msg.cell_modem_status.reserved[118]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[119] == 75, + "incorrect value for last_msg.msg.cell_modem_status.reserved[119], " + "expected 75, is %d", + last_msg.msg.cell_modem_status.reserved[119]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[120] == 46, + "incorrect value for last_msg.msg.cell_modem_status.reserved[120], " + "expected 46, is %d", + last_msg.msg.cell_modem_status.reserved[120]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[121] == 158, + "incorrect value for last_msg.msg.cell_modem_status.reserved[121], " + "expected 158, is %d", + last_msg.msg.cell_modem_status.reserved[121]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[122] == 63, + "incorrect value for last_msg.msg.cell_modem_status.reserved[122], " + "expected 63, is %d", + last_msg.msg.cell_modem_status.reserved[122]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[123] == 100, + "incorrect value for last_msg.msg.cell_modem_status.reserved[123], " + "expected 100, is %d", + last_msg.msg.cell_modem_status.reserved[123]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[124] == 122, + "incorrect value for last_msg.msg.cell_modem_status.reserved[124], " + "expected 122, is %d", + last_msg.msg.cell_modem_status.reserved[124]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[125] == 213, + "incorrect value for last_msg.msg.cell_modem_status.reserved[125], " + "expected 213, is %d", + last_msg.msg.cell_modem_status.reserved[125]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[126] == 20, + "incorrect value for last_msg.msg.cell_modem_status.reserved[126], " + "expected 20, is %d", + last_msg.msg.cell_modem_status.reserved[126]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[127] == 85, + "incorrect value for last_msg.msg.cell_modem_status.reserved[127], " + "expected 85, is %d", + last_msg.msg.cell_modem_status.reserved[127]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[128] == 212, + "incorrect value for last_msg.msg.cell_modem_status.reserved[128], " + "expected 212, is %d", + last_msg.msg.cell_modem_status.reserved[128]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[129] == 131, + "incorrect value for last_msg.msg.cell_modem_status.reserved[129], " + "expected 131, is %d", + last_msg.msg.cell_modem_status.reserved[129]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[130] == 50, + "incorrect value for last_msg.msg.cell_modem_status.reserved[130], " + "expected 50, is %d", + last_msg.msg.cell_modem_status.reserved[130]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[131] == 224, + "incorrect value for last_msg.msg.cell_modem_status.reserved[131], " + "expected 224, is %d", + last_msg.msg.cell_modem_status.reserved[131]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[132] == 218, + "incorrect value for last_msg.msg.cell_modem_status.reserved[132], " + "expected 218, is %d", + last_msg.msg.cell_modem_status.reserved[132]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[133] == 215, + "incorrect value for last_msg.msg.cell_modem_status.reserved[133], " + "expected 215, is %d", + last_msg.msg.cell_modem_status.reserved[133]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[134] == 215, + "incorrect value for last_msg.msg.cell_modem_status.reserved[134], " + "expected 215, is %d", + last_msg.msg.cell_modem_status.reserved[134]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[135] == 149, + "incorrect value for last_msg.msg.cell_modem_status.reserved[135], " + "expected 149, is %d", + last_msg.msg.cell_modem_status.reserved[135]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[136] == 2, + "incorrect value for last_msg.msg.cell_modem_status.reserved[136], " + "expected 2, is %d", + last_msg.msg.cell_modem_status.reserved[136]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[137] == 19, + "incorrect value for last_msg.msg.cell_modem_status.reserved[137], " + "expected 19, is %d", + last_msg.msg.cell_modem_status.reserved[137]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[138] == 129, + "incorrect value for last_msg.msg.cell_modem_status.reserved[138], " + "expected 129, is %d", + last_msg.msg.cell_modem_status.reserved[138]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[139] == 39, + "incorrect value for last_msg.msg.cell_modem_status.reserved[139], " + "expected 39, is %d", + last_msg.msg.cell_modem_status.reserved[139]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[140] == 164, + "incorrect value for last_msg.msg.cell_modem_status.reserved[140], " + "expected 164, is %d", + last_msg.msg.cell_modem_status.reserved[140]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[141] == 5, + "incorrect value for last_msg.msg.cell_modem_status.reserved[141], " + "expected 5, is %d", + last_msg.msg.cell_modem_status.reserved[141]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[142] == 175, + "incorrect value for last_msg.msg.cell_modem_status.reserved[142], " + "expected 175, is %d", + last_msg.msg.cell_modem_status.reserved[142]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[143] == 6, + "incorrect value for last_msg.msg.cell_modem_status.reserved[143], " + "expected 6, is %d", + last_msg.msg.cell_modem_status.reserved[143]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[144] == 62, + "incorrect value for last_msg.msg.cell_modem_status.reserved[144], " + "expected 62, is %d", + last_msg.msg.cell_modem_status.reserved[144]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[145] == 51, + "incorrect value for last_msg.msg.cell_modem_status.reserved[145], " + "expected 51, is %d", + last_msg.msg.cell_modem_status.reserved[145]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[146] == 78, + "incorrect value for last_msg.msg.cell_modem_status.reserved[146], " + "expected 78, is %d", + last_msg.msg.cell_modem_status.reserved[146]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[147] == 66, + "incorrect value for last_msg.msg.cell_modem_status.reserved[147], " + "expected 66, is %d", + last_msg.msg.cell_modem_status.reserved[147]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[148] == 248, + "incorrect value for last_msg.msg.cell_modem_status.reserved[148], " + "expected 248, is %d", + last_msg.msg.cell_modem_status.reserved[148]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[149] == 116, + "incorrect value for last_msg.msg.cell_modem_status.reserved[149], " + "expected 116, is %d", + last_msg.msg.cell_modem_status.reserved[149]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[150] == 88, + "incorrect value for last_msg.msg.cell_modem_status.reserved[150], " + "expected 88, is %d", + last_msg.msg.cell_modem_status.reserved[150]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[151] == 90, + "incorrect value for last_msg.msg.cell_modem_status.reserved[151], " + "expected 90, is %d", + last_msg.msg.cell_modem_status.reserved[151]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[152] == 128, + "incorrect value for last_msg.msg.cell_modem_status.reserved[152], " + "expected 128, is %d", + last_msg.msg.cell_modem_status.reserved[152]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[153] == 226, + "incorrect value for last_msg.msg.cell_modem_status.reserved[153], " + "expected 226, is %d", + last_msg.msg.cell_modem_status.reserved[153]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[154] == 177, + "incorrect value for last_msg.msg.cell_modem_status.reserved[154], " + "expected 177, is %d", + last_msg.msg.cell_modem_status.reserved[154]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[155] == 0, + "incorrect value for last_msg.msg.cell_modem_status.reserved[155], " + "expected 0, is %d", + last_msg.msg.cell_modem_status.reserved[155]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[156] == 47, + "incorrect value for last_msg.msg.cell_modem_status.reserved[156], " + "expected 47, is %d", + last_msg.msg.cell_modem_status.reserved[156]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[157] == 140, + "incorrect value for last_msg.msg.cell_modem_status.reserved[157], " + "expected 140, is %d", + last_msg.msg.cell_modem_status.reserved[157]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[158] == 33, + "incorrect value for last_msg.msg.cell_modem_status.reserved[158], " + "expected 33, is %d", + last_msg.msg.cell_modem_status.reserved[158]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[159] == 126, + "incorrect value for last_msg.msg.cell_modem_status.reserved[159], " + "expected 126, is %d", + last_msg.msg.cell_modem_status.reserved[159]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[160] == 221, + "incorrect value for last_msg.msg.cell_modem_status.reserved[160], " + "expected 221, is %d", + last_msg.msg.cell_modem_status.reserved[160]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[161] == 110, + "incorrect value for last_msg.msg.cell_modem_status.reserved[161], " + "expected 110, is %d", + last_msg.msg.cell_modem_status.reserved[161]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[162] == 144, + "incorrect value for last_msg.msg.cell_modem_status.reserved[162], " + "expected 144, is %d", + last_msg.msg.cell_modem_status.reserved[162]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[163] == 97, + "incorrect value for last_msg.msg.cell_modem_status.reserved[163], " + "expected 97, is %d", + last_msg.msg.cell_modem_status.reserved[163]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[164] == 74, + "incorrect value for last_msg.msg.cell_modem_status.reserved[164], " + "expected 74, is %d", + last_msg.msg.cell_modem_status.reserved[164]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[165] == 250, + "incorrect value for last_msg.msg.cell_modem_status.reserved[165], " + "expected 250, is %d", + last_msg.msg.cell_modem_status.reserved[165]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[166] == 181, + "incorrect value for last_msg.msg.cell_modem_status.reserved[166], " + "expected 181, is %d", + last_msg.msg.cell_modem_status.reserved[166]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[167] == 199, + "incorrect value for last_msg.msg.cell_modem_status.reserved[167], " + "expected 199, is %d", + last_msg.msg.cell_modem_status.reserved[167]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[168] == 27, + "incorrect value for last_msg.msg.cell_modem_status.reserved[168], " + "expected 27, is %d", + last_msg.msg.cell_modem_status.reserved[168]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[169] == 176, + "incorrect value for last_msg.msg.cell_modem_status.reserved[169], " + "expected 176, is %d", + last_msg.msg.cell_modem_status.reserved[169]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[170] == 65, + "incorrect value for last_msg.msg.cell_modem_status.reserved[170], " + "expected 65, is %d", + last_msg.msg.cell_modem_status.reserved[170]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[171] == 185, + "incorrect value for last_msg.msg.cell_modem_status.reserved[171], " + "expected 185, is %d", + last_msg.msg.cell_modem_status.reserved[171]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[172] == 110, + "incorrect value for last_msg.msg.cell_modem_status.reserved[172], " + "expected 110, is %d", + last_msg.msg.cell_modem_status.reserved[172]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[173] == 92, + "incorrect value for last_msg.msg.cell_modem_status.reserved[173], " + "expected 92, is %d", + last_msg.msg.cell_modem_status.reserved[173]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[174] == 34, + "incorrect value for last_msg.msg.cell_modem_status.reserved[174], " + "expected 34, is %d", + last_msg.msg.cell_modem_status.reserved[174]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[175] == 44, + "incorrect value for last_msg.msg.cell_modem_status.reserved[175], " + "expected 44, is %d", + last_msg.msg.cell_modem_status.reserved[175]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[176] == 131, + "incorrect value for last_msg.msg.cell_modem_status.reserved[176], " + "expected 131, is %d", + last_msg.msg.cell_modem_status.reserved[176]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[177] == 96, + "incorrect value for last_msg.msg.cell_modem_status.reserved[177], " + "expected 96, is %d", + last_msg.msg.cell_modem_status.reserved[177]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[178] == 178, + "incorrect value for last_msg.msg.cell_modem_status.reserved[178], " + "expected 178, is %d", + last_msg.msg.cell_modem_status.reserved[178]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[179] == 40, + "incorrect value for last_msg.msg.cell_modem_status.reserved[179], " + "expected 40, is %d", + last_msg.msg.cell_modem_status.reserved[179]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[180] == 176, + "incorrect value for last_msg.msg.cell_modem_status.reserved[180], " + "expected 176, is %d", + last_msg.msg.cell_modem_status.reserved[180]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[181] == 4, + "incorrect value for last_msg.msg.cell_modem_status.reserved[181], " + "expected 4, is %d", + last_msg.msg.cell_modem_status.reserved[181]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[182] == 90, + "incorrect value for last_msg.msg.cell_modem_status.reserved[182], " + "expected 90, is %d", + last_msg.msg.cell_modem_status.reserved[182]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[183] == 36, + "incorrect value for last_msg.msg.cell_modem_status.reserved[183], " + "expected 36, is %d", + last_msg.msg.cell_modem_status.reserved[183]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[184] == 7, + "incorrect value for last_msg.msg.cell_modem_status.reserved[184], " + "expected 7, is %d", + last_msg.msg.cell_modem_status.reserved[184]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[185] == 180, + "incorrect value for last_msg.msg.cell_modem_status.reserved[185], " + "expected 180, is %d", + last_msg.msg.cell_modem_status.reserved[185]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[186] == 244, + "incorrect value for last_msg.msg.cell_modem_status.reserved[186], " + "expected 244, is %d", + last_msg.msg.cell_modem_status.reserved[186]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[187] == 244, + "incorrect value for last_msg.msg.cell_modem_status.reserved[187], " + "expected 244, is %d", + last_msg.msg.cell_modem_status.reserved[187]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[188] == 23, + "incorrect value for last_msg.msg.cell_modem_status.reserved[188], " + "expected 23, is %d", + last_msg.msg.cell_modem_status.reserved[188]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[189] == 108, + "incorrect value for last_msg.msg.cell_modem_status.reserved[189], " + "expected 108, is %d", + last_msg.msg.cell_modem_status.reserved[189]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[190] == 171, + "incorrect value for last_msg.msg.cell_modem_status.reserved[190], " + "expected 171, is %d", + last_msg.msg.cell_modem_status.reserved[190]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[191] == 204, + "incorrect value for last_msg.msg.cell_modem_status.reserved[191], " + "expected 204, is %d", + last_msg.msg.cell_modem_status.reserved[191]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[192] == 196, + "incorrect value for last_msg.msg.cell_modem_status.reserved[192], " + "expected 196, is %d", + last_msg.msg.cell_modem_status.reserved[192]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[193] == 61, + "incorrect value for last_msg.msg.cell_modem_status.reserved[193], " + "expected 61, is %d", + last_msg.msg.cell_modem_status.reserved[193]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[194] == 51, + "incorrect value for last_msg.msg.cell_modem_status.reserved[194], " + "expected 51, is %d", + last_msg.msg.cell_modem_status.reserved[194]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[195] == 179, + "incorrect value for last_msg.msg.cell_modem_status.reserved[195], " + "expected 179, is %d", + last_msg.msg.cell_modem_status.reserved[195]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[196] == 242, + "incorrect value for last_msg.msg.cell_modem_status.reserved[196], " + "expected 242, is %d", + last_msg.msg.cell_modem_status.reserved[196]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[197] == 156, + "incorrect value for last_msg.msg.cell_modem_status.reserved[197], " + "expected 156, is %d", + last_msg.msg.cell_modem_status.reserved[197]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[198] == 81, + "incorrect value for last_msg.msg.cell_modem_status.reserved[198], " + "expected 81, is %d", + last_msg.msg.cell_modem_status.reserved[198]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[199] == 83, + "incorrect value for last_msg.msg.cell_modem_status.reserved[199], " + "expected 83, is %d", + last_msg.msg.cell_modem_status.reserved[199]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[200] == 16, + "incorrect value for last_msg.msg.cell_modem_status.reserved[200], " + "expected 16, is %d", + last_msg.msg.cell_modem_status.reserved[200]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[201] == 15, + "incorrect value for last_msg.msg.cell_modem_status.reserved[201], " + "expected 15, is %d", + last_msg.msg.cell_modem_status.reserved[201]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[202] == 134, + "incorrect value for last_msg.msg.cell_modem_status.reserved[202], " + "expected 134, is %d", + last_msg.msg.cell_modem_status.reserved[202]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[203] == 40, + "incorrect value for last_msg.msg.cell_modem_status.reserved[203], " + "expected 40, is %d", + last_msg.msg.cell_modem_status.reserved[203]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[204] == 245, + "incorrect value for last_msg.msg.cell_modem_status.reserved[204], " + "expected 245, is %d", + last_msg.msg.cell_modem_status.reserved[204]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[205] == 253, + "incorrect value for last_msg.msg.cell_modem_status.reserved[205], " + "expected 253, is %d", + last_msg.msg.cell_modem_status.reserved[205]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[206] == 150, + "incorrect value for last_msg.msg.cell_modem_status.reserved[206], " + "expected 150, is %d", + last_msg.msg.cell_modem_status.reserved[206]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[207] == 94, + "incorrect value for last_msg.msg.cell_modem_status.reserved[207], " + "expected 94, is %d", + last_msg.msg.cell_modem_status.reserved[207]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[208] == 150, + "incorrect value for last_msg.msg.cell_modem_status.reserved[208], " + "expected 150, is %d", + last_msg.msg.cell_modem_status.reserved[208]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[209] == 144, + "incorrect value for last_msg.msg.cell_modem_status.reserved[209], " + "expected 144, is %d", + last_msg.msg.cell_modem_status.reserved[209]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[210] == 197, + "incorrect value for last_msg.msg.cell_modem_status.reserved[210], " + "expected 197, is %d", + last_msg.msg.cell_modem_status.reserved[210]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[211] == 113, + "incorrect value for last_msg.msg.cell_modem_status.reserved[211], " + "expected 113, is %d", + last_msg.msg.cell_modem_status.reserved[211]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[212] == 5, + "incorrect value for last_msg.msg.cell_modem_status.reserved[212], " + "expected 5, is %d", + last_msg.msg.cell_modem_status.reserved[212]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[213] == 141, + "incorrect value for last_msg.msg.cell_modem_status.reserved[213], " + "expected 141, is %d", + last_msg.msg.cell_modem_status.reserved[213]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[214] == 232, + "incorrect value for last_msg.msg.cell_modem_status.reserved[214], " + "expected 232, is %d", + last_msg.msg.cell_modem_status.reserved[214]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[215] == 33, + "incorrect value for last_msg.msg.cell_modem_status.reserved[215], " + "expected 33, is %d", + last_msg.msg.cell_modem_status.reserved[215]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[216] == 101, + "incorrect value for last_msg.msg.cell_modem_status.reserved[216], " + "expected 101, is %d", + last_msg.msg.cell_modem_status.reserved[216]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[217] == 231, + "incorrect value for last_msg.msg.cell_modem_status.reserved[217], " + "expected 231, is %d", + last_msg.msg.cell_modem_status.reserved[217]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[218] == 38, + "incorrect value for last_msg.msg.cell_modem_status.reserved[218], " + "expected 38, is %d", + last_msg.msg.cell_modem_status.reserved[218]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[219] == 75, + "incorrect value for last_msg.msg.cell_modem_status.reserved[219], " + "expected 75, is %d", + last_msg.msg.cell_modem_status.reserved[219]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[220] == 178, + "incorrect value for last_msg.msg.cell_modem_status.reserved[220], " + "expected 178, is %d", + last_msg.msg.cell_modem_status.reserved[220]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[221] == 243, + "incorrect value for last_msg.msg.cell_modem_status.reserved[221], " + "expected 243, is %d", + last_msg.msg.cell_modem_status.reserved[221]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[222] == 119, + "incorrect value for last_msg.msg.cell_modem_status.reserved[222], " + "expected 119, is %d", + last_msg.msg.cell_modem_status.reserved[222]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[223] == 1, + "incorrect value for last_msg.msg.cell_modem_status.reserved[223], " + "expected 1, is %d", + last_msg.msg.cell_modem_status.reserved[223]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[224] == 248, + "incorrect value for last_msg.msg.cell_modem_status.reserved[224], " + "expected 248, is %d", + last_msg.msg.cell_modem_status.reserved[224]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[225] == 218, + "incorrect value for last_msg.msg.cell_modem_status.reserved[225], " + "expected 218, is %d", + last_msg.msg.cell_modem_status.reserved[225]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[226] == 86, + "incorrect value for last_msg.msg.cell_modem_status.reserved[226], " + "expected 86, is %d", + last_msg.msg.cell_modem_status.reserved[226]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[227] == 7, + "incorrect value for last_msg.msg.cell_modem_status.reserved[227], " + "expected 7, is %d", + last_msg.msg.cell_modem_status.reserved[227]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[228] == 88, + "incorrect value for last_msg.msg.cell_modem_status.reserved[228], " + "expected 88, is %d", + last_msg.msg.cell_modem_status.reserved[228]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[229] == 197, + "incorrect value for last_msg.msg.cell_modem_status.reserved[229], " + "expected 197, is %d", + last_msg.msg.cell_modem_status.reserved[229]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[230] == 148, + "incorrect value for last_msg.msg.cell_modem_status.reserved[230], " + "expected 148, is %d", + last_msg.msg.cell_modem_status.reserved[230]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[231] == 240, + "incorrect value for last_msg.msg.cell_modem_status.reserved[231], " + "expected 240, is %d", + last_msg.msg.cell_modem_status.reserved[231]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[232] == 227, + "incorrect value for last_msg.msg.cell_modem_status.reserved[232], " + "expected 227, is %d", + last_msg.msg.cell_modem_status.reserved[232]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[233] == 2, + "incorrect value for last_msg.msg.cell_modem_status.reserved[233], " + "expected 2, is %d", + last_msg.msg.cell_modem_status.reserved[233]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[234] == 65, + "incorrect value for last_msg.msg.cell_modem_status.reserved[234], " + "expected 65, is %d", + last_msg.msg.cell_modem_status.reserved[234]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[235] == 173, + "incorrect value for last_msg.msg.cell_modem_status.reserved[235], " + "expected 173, is %d", + last_msg.msg.cell_modem_status.reserved[235]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[236] == 122, + "incorrect value for last_msg.msg.cell_modem_status.reserved[236], " + "expected 122, is %d", + last_msg.msg.cell_modem_status.reserved[236]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[237] == 143, + "incorrect value for last_msg.msg.cell_modem_status.reserved[237], " + "expected 143, is %d", + last_msg.msg.cell_modem_status.reserved[237]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[238] == 251, + "incorrect value for last_msg.msg.cell_modem_status.reserved[238], " + "expected 251, is %d", + last_msg.msg.cell_modem_status.reserved[238]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[239] == 156, + "incorrect value for last_msg.msg.cell_modem_status.reserved[239], " + "expected 156, is %d", + last_msg.msg.cell_modem_status.reserved[239]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[240] == 217, + "incorrect value for last_msg.msg.cell_modem_status.reserved[240], " + "expected 217, is %d", + last_msg.msg.cell_modem_status.reserved[240]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[241] == 67, + "incorrect value for last_msg.msg.cell_modem_status.reserved[241], " + "expected 67, is %d", + last_msg.msg.cell_modem_status.reserved[241]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[242] == 239, + "incorrect value for last_msg.msg.cell_modem_status.reserved[242], " + "expected 239, is %d", + last_msg.msg.cell_modem_status.reserved[242]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[243] == 219, + "incorrect value for last_msg.msg.cell_modem_status.reserved[243], " + "expected 219, is %d", + last_msg.msg.cell_modem_status.reserved[243]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[244] == 31, + "incorrect value for last_msg.msg.cell_modem_status.reserved[244], " + "expected 31, is %d", + last_msg.msg.cell_modem_status.reserved[244]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[245] == 224, + "incorrect value for last_msg.msg.cell_modem_status.reserved[245], " + "expected 224, is %d", + last_msg.msg.cell_modem_status.reserved[245]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[246] == 176, + "incorrect value for last_msg.msg.cell_modem_status.reserved[246], " + "expected 176, is %d", + last_msg.msg.cell_modem_status.reserved[246]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[247] == 129, + "incorrect value for last_msg.msg.cell_modem_status.reserved[247], " + "expected 129, is %d", + last_msg.msg.cell_modem_status.reserved[247]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[248] == 81, + "incorrect value for last_msg.msg.cell_modem_status.reserved[248], " + "expected 81, is %d", + last_msg.msg.cell_modem_status.reserved[248]); + ck_assert_msg( + last_msg.msg.cell_modem_status.reserved[249] == 80, + "incorrect value for last_msg.msg.cell_modem_status.reserved[249], " + "expected 80, is %d", + last_msg.msg.cell_modem_status.reserved[249]); + + ck_assert_msg( + (last_msg.msg.cell_modem_status.signal_error_rate * 100 - + 8588.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.cell_modem_status.signal_error_rate, " + "expected 8588.20019531, is %s", + last_msg.msg.cell_modem_status.signal_error_rate); + + ck_assert_msg( + last_msg.msg.cell_modem_status.signal_strength == 103, + "incorrect value for last_msg.msg.cell_modem_status.signal_strength, " + "expected 103, is %d", + last_msg.msg.cell_modem_status.signal_strength); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCellModemStatus_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgCellModemStatus"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCellModemStatus"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCellModemStatus); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCommandOutput.c b/c/test/auto_check_sbp_piksi_MsgCommandOutput.c new file mode 100644 index 0000000000..77b835c59c --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCommandOutput.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCommandOutput) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xbc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, + 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116, 11, 109, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg( + sbp_msg_command_output_line_set(&test_msg.command_output, + "Some output text", false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("Some output text"), + "Wrote different to expected"); + ck_assert_msg( + sbp_msg_command_output_line_encoded_len(&test_msg.command_output) == 16, + "String not encoded properly"); + + test_msg.command_output.sequence = 2507449470; + + sbp_message_send(&sbp_state, SbpMsgCommandOutput, 21554, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 21554, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCommandOutput, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_command_output_line_encoded_len( + &last_msg.msg.command_output) == 16, + "Invalid encoded len"); + ck_assert_msg( + strcmp(sbp_msg_command_output_line_get(&last_msg.msg.command_output), + "Some output text") == 0, + "String not decoded properly"); + + ck_assert_msg(last_msg.msg.command_output.sequence == 2507449470, + "incorrect value for last_msg.msg.command_output.sequence, " + "expected 2507449470, is %d", + last_msg.msg.command_output.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCommandOutput_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgCommandOutput"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCommandOutput"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCommandOutput); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCommandReq.c b/c/test/auto_check_sbp_piksi_MsgCommandReq.c new file mode 100644 index 0000000000..12d76b1bc1 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCommandReq.c @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCommandReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, + 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, 24, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + size_t written; + ck_assert_msg(sbp_msg_command_req_command_set(&test_msg.command_req, + "/path/to/command with args", + false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("/path/to/command with args"), + "Wrote different to expected"); + ck_assert_msg( + sbp_msg_command_req_command_encoded_len(&test_msg.command_req) == 27, + "String not encoded properly"); + + test_msg.command_req.sequence = 1755532595; + + sbp_message_send(&sbp_state, SbpMsgCommandReq, 47274, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 47274, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCommandReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_command_req_command_encoded_len( + &last_msg.msg.command_req) == 27, + "Invalid encoded len"); + ck_assert_msg( + strcmp(sbp_msg_command_req_command_get(&last_msg.msg.command_req), + "/path/to/command with args") == 0, + "String not decoded properly"); + + ck_assert_msg(last_msg.msg.command_req.sequence == 1755532595, + "incorrect value for last_msg.msg.command_req.sequence, " + "expected 1755532595, is %d", + last_msg.msg.command_req.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCommandReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgCommandReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCommandReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCommandReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCommandResp.c b/c/test/auto_check_sbp_piksi_MsgCommandResp.c new file mode 100644 index 0000000000..2488b5f023 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCommandResp.c @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCommandResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb9, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 185, 0, 57, 206, 8, 118, 215, + 131, 160, 210, 110, 150, 103, 164, 240, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.command_resp.code = 1737912018; + + test_msg.command_resp.sequence = 2692994934; + + sbp_message_send(&sbp_state, SbpMsgCommandResp, 52793, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52793, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCommandResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.command_resp.code == 1737912018, + "incorrect value for last_msg.msg.command_resp.code, " + "expected 1737912018, is %d", + last_msg.msg.command_resp.code); + + ck_assert_msg(last_msg.msg.command_resp.sequence == 2692994934, + "incorrect value for last_msg.msg.command_resp.sequence, " + "expected 2692994934, is %d", + last_msg.msg.command_resp.sequence); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCommandResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgCommandResp"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCommandResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCommandResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCwResults.c b/c/test/auto_check_sbp_piksi_MsgCwResults.c new file mode 100644 index 0000000000..0a842caa12 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCwResults.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCwResults) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xc0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 192, 0, 99, 246, 0, 228, 72, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgCwResults, 63075, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63075, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCwResults, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCwResults_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgCwResults"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCwResults"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCwResults); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgCwStart.c b/c/test/auto_check_sbp_piksi_MsgCwStart.c new file mode 100644 index 0000000000..44857c29ca --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgCwStart.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgCwStart) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xc1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 193, 0, 30, 179, 0, 213, 138, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgCwStart, 45854, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 45854, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgCwStart, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgCwStart_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_piksi_MsgCwStart"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgCwStart"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgCwStart); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgFrontEndGain.c b/c/test/auto_check_sbp_piksi_MsgFrontEndGain.c new file mode 100644 index 0000000000..d3b1708918 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgFrontEndGain.c @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgFrontEndGain) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xbf, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, + 38, 38, 246, 233, 216, 80, 187, 213, 85, 2, 235, 135, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.front_end_gain.if_gain[0] = -10; + + test_msg.front_end_gain.if_gain[1] = -23; + + test_msg.front_end_gain.if_gain[2] = -40; + + test_msg.front_end_gain.if_gain[3] = 80; + + test_msg.front_end_gain.if_gain[4] = -69; + + test_msg.front_end_gain.if_gain[5] = -43; + + test_msg.front_end_gain.if_gain[6] = 85; + + test_msg.front_end_gain.if_gain[7] = 2; + + test_msg.front_end_gain.rf_gain[0] = 41; + + test_msg.front_end_gain.rf_gain[1] = -123; + + test_msg.front_end_gain.rf_gain[2] = -122; + + test_msg.front_end_gain.rf_gain[3] = 10; + + test_msg.front_end_gain.rf_gain[4] = 105; + + test_msg.front_end_gain.rf_gain[5] = 20; + + test_msg.front_end_gain.rf_gain[6] = 38; + + test_msg.front_end_gain.rf_gain[7] = 38; + + sbp_message_send(&sbp_state, SbpMsgFrontEndGain, 62895, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 62895, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgFrontEndGain, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[0] == -10, + "incorrect value for last_msg.msg.front_end_gain.if_gain[0], " + "expected -10, is %d", + last_msg.msg.front_end_gain.if_gain[0]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[1] == -23, + "incorrect value for last_msg.msg.front_end_gain.if_gain[1], " + "expected -23, is %d", + last_msg.msg.front_end_gain.if_gain[1]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[2] == -40, + "incorrect value for last_msg.msg.front_end_gain.if_gain[2], " + "expected -40, is %d", + last_msg.msg.front_end_gain.if_gain[2]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[3] == 80, + "incorrect value for last_msg.msg.front_end_gain.if_gain[3], " + "expected 80, is %d", + last_msg.msg.front_end_gain.if_gain[3]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[4] == -69, + "incorrect value for last_msg.msg.front_end_gain.if_gain[4], " + "expected -69, is %d", + last_msg.msg.front_end_gain.if_gain[4]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[5] == -43, + "incorrect value for last_msg.msg.front_end_gain.if_gain[5], " + "expected -43, is %d", + last_msg.msg.front_end_gain.if_gain[5]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[6] == 85, + "incorrect value for last_msg.msg.front_end_gain.if_gain[6], " + "expected 85, is %d", + last_msg.msg.front_end_gain.if_gain[6]); + ck_assert_msg(last_msg.msg.front_end_gain.if_gain[7] == 2, + "incorrect value for last_msg.msg.front_end_gain.if_gain[7], " + "expected 2, is %d", + last_msg.msg.front_end_gain.if_gain[7]); + + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[0] == 41, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[0], " + "expected 41, is %d", + last_msg.msg.front_end_gain.rf_gain[0]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[1] == -123, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[1], " + "expected -123, is %d", + last_msg.msg.front_end_gain.rf_gain[1]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[2] == -122, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[2], " + "expected -122, is %d", + last_msg.msg.front_end_gain.rf_gain[2]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[3] == 10, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[3], " + "expected 10, is %d", + last_msg.msg.front_end_gain.rf_gain[3]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[4] == 105, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[4], " + "expected 105, is %d", + last_msg.msg.front_end_gain.rf_gain[4]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[5] == 20, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[5], " + "expected 20, is %d", + last_msg.msg.front_end_gain.rf_gain[5]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[6] == 38, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[6], " + "expected 38, is %d", + last_msg.msg.front_end_gain.rf_gain[6]); + ck_assert_msg(last_msg.msg.front_end_gain.rf_gain[7] == 38, + "incorrect value for last_msg.msg.front_end_gain.rf_gain[7], " + "expected 38, is %d", + last_msg.msg.front_end_gain.rf_gain[7]); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgFrontEndGain_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgFrontEndGain"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgFrontEndGain"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgFrontEndGain); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgInitBaseDep.c b/c/test/auto_check_sbp_piksi_MsgInitBaseDep.c new file mode 100644 index 0000000000..791fb1de38 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgInitBaseDep.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgInitBaseDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x23, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 35, 0, 184, 41, 0, 70, 13, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgInitBaseDep, 10680, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 10680, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgInitBaseDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgInitBaseDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgInitBaseDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgInitBaseDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgInitBaseDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgMaskSatellite.c b/c/test/auto_check_sbp_piksi_MsgMaskSatellite.c new file mode 100644 index 0000000000..e71e116bce --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgMaskSatellite.c @@ -0,0 +1,161 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgMaskSatellite) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x2b, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.mask_satellite.mask = 183; + + test_msg.mask_satellite.sid.code = 57; + + test_msg.mask_satellite.sid.sat = 87; + + sbp_message_send(&sbp_state, SbpMsgMaskSatellite, 38829, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 38829, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgMaskSatellite, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.mask_satellite.mask == 183, + "incorrect value for last_msg.msg.mask_satellite.mask, " + "expected 183, is %d", + last_msg.msg.mask_satellite.mask); + + ck_assert_msg(last_msg.msg.mask_satellite.sid.code == 57, + "incorrect value for last_msg.msg.mask_satellite.sid.code, " + "expected 57, is %d", + last_msg.msg.mask_satellite.sid.code); + + ck_assert_msg(last_msg.msg.mask_satellite.sid.sat == 87, + "incorrect value for last_msg.msg.mask_satellite.sid.sat, " + "expected 87, is %d", + last_msg.msg.mask_satellite.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgMaskSatellite_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgMaskSatellite"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgMaskSatellite"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgMaskSatellite); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgMaskSatelliteDep.c b/c/test/auto_check_sbp_piksi_MsgMaskSatelliteDep.c new file mode 100644 index 0000000000..b9aefa4d1c --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgMaskSatelliteDep.c @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgMaskSatelliteDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1b, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.mask_satellite_dep.mask = 33; + + test_msg.mask_satellite_dep.sid.code = 95; + + test_msg.mask_satellite_dep.sid.reserved = 4; + + test_msg.mask_satellite_dep.sid.sat = 39170; + + sbp_message_send(&sbp_state, SbpMsgMaskSatelliteDep, 34491, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34491, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgMaskSatelliteDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.mask_satellite_dep.mask == 33, + "incorrect value for last_msg.msg.mask_satellite_dep.mask, " + "expected 33, is %d", + last_msg.msg.mask_satellite_dep.mask); + + ck_assert_msg( + last_msg.msg.mask_satellite_dep.sid.code == 95, + "incorrect value for last_msg.msg.mask_satellite_dep.sid.code, " + "expected 95, is %d", + last_msg.msg.mask_satellite_dep.sid.code); + + ck_assert_msg( + last_msg.msg.mask_satellite_dep.sid.reserved == 4, + "incorrect value for last_msg.msg.mask_satellite_dep.sid.reserved, " + "expected 4, is %d", + last_msg.msg.mask_satellite_dep.sid.reserved); + + ck_assert_msg( + last_msg.msg.mask_satellite_dep.sid.sat == 39170, + "incorrect value for last_msg.msg.mask_satellite_dep.sid.sat, expected " + "39170, is %d", + last_msg.msg.mask_satellite_dep.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgMaskSatelliteDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgMaskSatelliteDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgMaskSatelliteDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgMaskSatelliteDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgNetworkStateReq.c b/c/test/auto_check_sbp_piksi_MsgNetworkStateReq.c new file mode 100644 index 0000000000..21406c318a --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgNetworkStateReq.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgNetworkStateReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xba, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 186, 0, 83, 62, 0, 148, 73, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgNetworkStateReq, 15955, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 15955, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgNetworkStateReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgNetworkStateReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgNetworkStateReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgNetworkStateReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgNetworkStateReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgNetworkStateResp.c b/c/test/auto_check_sbp_piksi_MsgNetworkStateResp.c new file mode 100644 index 0000000000..646f31ddae --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgNetworkStateResp.c @@ -0,0 +1,347 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgNetworkStateResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xbb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, + 137, 32, 44, 114, 147, 68, 222, 92, 192, 78, 235, 63, + 208, 114, 53, 183, 24, 244, 231, 26, 105, 25, 136, 3, + 105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.network_state_resp.flags = 2471552451; + + { + const char assign_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg.network_state_resp.interface_name, assign_string, + sizeof(assign_string)); + } + + test_msg.network_state_resp.ipv4_address[0] = 143; + + test_msg.network_state_resp.ipv4_address[1] = 241; + + test_msg.network_state_resp.ipv4_address[2] = 84; + + test_msg.network_state_resp.ipv4_address[3] = 180; + + test_msg.network_state_resp.ipv4_mask_size = 152; + + test_msg.network_state_resp.ipv6_address[0] = 194; + + test_msg.network_state_resp.ipv6_address[1] = 137; + + test_msg.network_state_resp.ipv6_address[2] = 32; + + test_msg.network_state_resp.ipv6_address[3] = 44; + + test_msg.network_state_resp.ipv6_address[4] = 114; + + test_msg.network_state_resp.ipv6_address[5] = 147; + + test_msg.network_state_resp.ipv6_address[6] = 68; + + test_msg.network_state_resp.ipv6_address[7] = 222; + + test_msg.network_state_resp.ipv6_address[8] = 92; + + test_msg.network_state_resp.ipv6_address[9] = 192; + + test_msg.network_state_resp.ipv6_address[10] = 78; + + test_msg.network_state_resp.ipv6_address[11] = 235; + + test_msg.network_state_resp.ipv6_address[12] = 63; + + test_msg.network_state_resp.ipv6_address[13] = 208; + + test_msg.network_state_resp.ipv6_address[14] = 114; + + test_msg.network_state_resp.ipv6_address[15] = 53; + + test_msg.network_state_resp.ipv6_mask_size = 183; + + test_msg.network_state_resp.rx_bytes = 451408920; + + test_msg.network_state_resp.tx_bytes = 59251049; + + sbp_message_send(&sbp_state, SbpMsgNetworkStateResp, 3880, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 3880, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgNetworkStateResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.network_state_resp.flags == 2471552451, + "incorrect value for last_msg.msg.network_state_resp.flags, " + "expected 2471552451, is %d", + last_msg.msg.network_state_resp.flags); + + { + const char check_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(&last_msg.msg.network_state_resp.interface_name, check_string, + sizeof(check_string)) == 0, + "incorrect value for last_msg.msg.network_state_resp.interface_name, " + "expected string '%s', is '%s'", + check_string, last_msg.msg.network_state_resp.interface_name); + } + + ck_assert_msg( + last_msg.msg.network_state_resp.ipv4_address[0] == 143, + "incorrect value for last_msg.msg.network_state_resp.ipv4_address[0], " + "expected 143, is %d", + last_msg.msg.network_state_resp.ipv4_address[0]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv4_address[1] == 241, + "incorrect value for last_msg.msg.network_state_resp.ipv4_address[1], " + "expected 241, is %d", + last_msg.msg.network_state_resp.ipv4_address[1]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv4_address[2] == 84, + "incorrect value for last_msg.msg.network_state_resp.ipv4_address[2], " + "expected 84, is %d", + last_msg.msg.network_state_resp.ipv4_address[2]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv4_address[3] == 180, + "incorrect value for last_msg.msg.network_state_resp.ipv4_address[3], " + "expected 180, is %d", + last_msg.msg.network_state_resp.ipv4_address[3]); + + ck_assert_msg( + last_msg.msg.network_state_resp.ipv4_mask_size == 152, + "incorrect value for last_msg.msg.network_state_resp.ipv4_mask_size, " + "expected 152, is %d", + last_msg.msg.network_state_resp.ipv4_mask_size); + + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[0] == 194, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[0], " + "expected 194, is %d", + last_msg.msg.network_state_resp.ipv6_address[0]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[1] == 137, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[1], " + "expected 137, is %d", + last_msg.msg.network_state_resp.ipv6_address[1]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[2] == 32, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[2], " + "expected 32, is %d", + last_msg.msg.network_state_resp.ipv6_address[2]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[3] == 44, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[3], " + "expected 44, is %d", + last_msg.msg.network_state_resp.ipv6_address[3]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[4] == 114, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[4], " + "expected 114, is %d", + last_msg.msg.network_state_resp.ipv6_address[4]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[5] == 147, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[5], " + "expected 147, is %d", + last_msg.msg.network_state_resp.ipv6_address[5]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[6] == 68, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[6], " + "expected 68, is %d", + last_msg.msg.network_state_resp.ipv6_address[6]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[7] == 222, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[7], " + "expected 222, is %d", + last_msg.msg.network_state_resp.ipv6_address[7]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[8] == 92, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[8], " + "expected 92, is %d", + last_msg.msg.network_state_resp.ipv6_address[8]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[9] == 192, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[9], " + "expected 192, is %d", + last_msg.msg.network_state_resp.ipv6_address[9]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[10] == 78, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[10], " + "expected 78, is %d", + last_msg.msg.network_state_resp.ipv6_address[10]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[11] == 235, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[11], " + "expected 235, is %d", + last_msg.msg.network_state_resp.ipv6_address[11]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[12] == 63, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[12], " + "expected 63, is %d", + last_msg.msg.network_state_resp.ipv6_address[12]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[13] == 208, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[13], " + "expected 208, is %d", + last_msg.msg.network_state_resp.ipv6_address[13]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[14] == 114, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[14], " + "expected 114, is %d", + last_msg.msg.network_state_resp.ipv6_address[14]); + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_address[15] == 53, + "incorrect value for last_msg.msg.network_state_resp.ipv6_address[15], " + "expected 53, is %d", + last_msg.msg.network_state_resp.ipv6_address[15]); + + ck_assert_msg( + last_msg.msg.network_state_resp.ipv6_mask_size == 183, + "incorrect value for last_msg.msg.network_state_resp.ipv6_mask_size, " + "expected 183, is %d", + last_msg.msg.network_state_resp.ipv6_mask_size); + + ck_assert_msg( + last_msg.msg.network_state_resp.rx_bytes == 451408920, + "incorrect value for last_msg.msg.network_state_resp.rx_bytes, " + "expected 451408920, is %d", + last_msg.msg.network_state_resp.rx_bytes); + + ck_assert_msg( + last_msg.msg.network_state_resp.tx_bytes == 59251049, + "incorrect value for last_msg.msg.network_state_resp.tx_bytes, " + "expected 59251049, is %d", + last_msg.msg.network_state_resp.tx_bytes); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgNetworkStateResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgNetworkStateResp"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgNetworkStateResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgNetworkStateResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgReset.c b/c/test/auto_check_sbp_piksi_MsgReset.c new file mode 100644 index 0000000000..687aa88c4a --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgReset.c @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgReset) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.reset.flags = 334428248; + + sbp_message_send(&sbp_state, SbpMsgReset, 53823, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 53823, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgReset, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.reset.flags == 334428248, + "incorrect value for last_msg.msg.reset.flags, expected " + "334428248, is %d", + last_msg.msg.reset.flags); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgReset_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_piksi_MsgReset"); + TCase *tc_acq = tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgReset"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgReset); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgResetDep.c b/c/test/auto_check_sbp_piksi_MsgResetDep.c new file mode 100644 index 0000000000..872b3f749d --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgResetDep.c @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgResetDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xb2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 178, 0, 64, 11, 0, 234, 171, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgResetDep, 2880, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 2880, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgResetDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgResetDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgResetDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgResetDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgResetDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgResetFilters.c b/c/test/auto_check_sbp_piksi_MsgResetFilters.c new file mode 100644 index 0000000000..ad5657e072 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgResetFilters.c @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgResetFilters) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x22, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 34, 0, 81, 200, 1, 100, 130, 45, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.reset_filters.filter = 100; + + sbp_message_send(&sbp_state, SbpMsgResetFilters, 51281, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 51281, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgResetFilters, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.reset_filters.filter == 100, + "incorrect value for last_msg.msg.reset_filters.filter, " + "expected 100, is %d", + last_msg.msg.reset_filters.filter); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgResetFilters_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgResetFilters"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgResetFilters"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgResetFilters); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgSetTime.c b/c/test/auto_check_sbp_piksi_MsgSetTime.c new file mode 100644 index 0000000000..0edcee299b --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgSetTime.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgSetTime) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x68, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 104, 0, 21, 170, 0, 215, 65, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgSetTime, 43541, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 43541, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSetTime, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgSetTime_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_piksi_MsgSetTime"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgSetTime"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgSetTime); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgSpecan.c b/c/test/auto_check_sbp_piksi_MsgSpecan.c new file mode 100644 index 0000000000..9abeb6dc93 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgSpecan.c @@ -0,0 +1,1764 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgSpecan) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x51, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, + 215, 167, 211, 19, 154, 201, 241, 69, 205, 136, 0, 70, 51, 67, + 108, 69, 102, 38, 166, 68, 100, 179, 185, 17, 175, 49, 193, 228, + 228, 47, 33, 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, + 223, 167, 174, 9, 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, + 218, 241, 101, 107, 45, 137, 93, 114, 230, 43, 224, 23, 74, 209, + 199, 211, 130, 89, 220, 163, 68, 20, 253, 7, 206, 50, 129, 116, + 194, 23, 31, 226, 217, 157, 205, 221, 5, 224, 92, 82, 109, 223, + 195, 233, 165, 1, 82, 141, 157, 177, 169, 244, 131, 96, 109, 111, + 253, 149, 28, 225, 225, 72, 158, 158, 210, 196, 206, 70, 63, 225, + 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, 179, 148, 66, 254, + 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, 171, 102, 163, + 175, 50, 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, 237, 156, + 62, 117, 47, 143, 94, 135, 22, 155, 113, 110, 15, 243, 141, 227, + 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, 88, 38, 117, + 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, + 70, 182, 239, 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, + 123, 210, 168, 90, 124, 20, 7, 220, 144, 168, 69, 22, 72, 162, + 69, 111, 91, 251, 72, 220, 28, 119, 150, 95, 2, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.specan.amplitude_ref = 3780.199951171875; + + test_msg.specan.amplitude_unit = 1329.199951171875; + + test_msg.specan.amplitude_value[0] = 100; + + test_msg.specan.amplitude_value[1] = 179; + + test_msg.specan.amplitude_value[2] = 185; + + test_msg.specan.amplitude_value[3] = 17; + + test_msg.specan.amplitude_value[4] = 175; + + test_msg.specan.amplitude_value[5] = 49; + + test_msg.specan.amplitude_value[6] = 193; + + test_msg.specan.amplitude_value[7] = 228; + + test_msg.specan.amplitude_value[8] = 228; + + test_msg.specan.amplitude_value[9] = 47; + + test_msg.specan.amplitude_value[10] = 33; + + test_msg.specan.amplitude_value[11] = 24; + + test_msg.specan.amplitude_value[12] = 141; + + test_msg.specan.amplitude_value[13] = 177; + + test_msg.specan.amplitude_value[14] = 18; + + test_msg.specan.amplitude_value[15] = 99; + + test_msg.specan.amplitude_value[16] = 246; + + test_msg.specan.amplitude_value[17] = 121; + + test_msg.specan.amplitude_value[18] = 61; + + test_msg.specan.amplitude_value[19] = 40; + + test_msg.specan.amplitude_value[20] = 91; + + test_msg.specan.amplitude_value[21] = 145; + + test_msg.specan.amplitude_value[22] = 223; + + test_msg.specan.amplitude_value[23] = 167; + + test_msg.specan.amplitude_value[24] = 174; + + test_msg.specan.amplitude_value[25] = 9; + + test_msg.specan.amplitude_value[26] = 116; + + test_msg.specan.amplitude_value[27] = 11; + + test_msg.specan.amplitude_value[28] = 247; + + test_msg.specan.amplitude_value[29] = 84; + + test_msg.specan.amplitude_value[30] = 49; + + test_msg.specan.amplitude_value[31] = 153; + + test_msg.specan.amplitude_value[32] = 205; + + test_msg.specan.amplitude_value[33] = 2; + + test_msg.specan.amplitude_value[34] = 230; + + test_msg.specan.amplitude_value[35] = 194; + + test_msg.specan.amplitude_value[36] = 218; + + test_msg.specan.amplitude_value[37] = 241; + + test_msg.specan.amplitude_value[38] = 101; + + test_msg.specan.amplitude_value[39] = 107; + + test_msg.specan.amplitude_value[40] = 45; + + test_msg.specan.amplitude_value[41] = 137; + + test_msg.specan.amplitude_value[42] = 93; + + test_msg.specan.amplitude_value[43] = 114; + + test_msg.specan.amplitude_value[44] = 230; + + test_msg.specan.amplitude_value[45] = 43; + + test_msg.specan.amplitude_value[46] = 224; + + test_msg.specan.amplitude_value[47] = 23; + + test_msg.specan.amplitude_value[48] = 74; + + test_msg.specan.amplitude_value[49] = 209; + + test_msg.specan.amplitude_value[50] = 199; + + test_msg.specan.amplitude_value[51] = 211; + + test_msg.specan.amplitude_value[52] = 130; + + test_msg.specan.amplitude_value[53] = 89; + + test_msg.specan.amplitude_value[54] = 220; + + test_msg.specan.amplitude_value[55] = 163; + + test_msg.specan.amplitude_value[56] = 68; + + test_msg.specan.amplitude_value[57] = 20; + + test_msg.specan.amplitude_value[58] = 253; + + test_msg.specan.amplitude_value[59] = 7; + + test_msg.specan.amplitude_value[60] = 206; + + test_msg.specan.amplitude_value[61] = 50; + + test_msg.specan.amplitude_value[62] = 129; + + test_msg.specan.amplitude_value[63] = 116; + + test_msg.specan.amplitude_value[64] = 194; + + test_msg.specan.amplitude_value[65] = 23; + + test_msg.specan.amplitude_value[66] = 31; + + test_msg.specan.amplitude_value[67] = 226; + + test_msg.specan.amplitude_value[68] = 217; + + test_msg.specan.amplitude_value[69] = 157; + + test_msg.specan.amplitude_value[70] = 205; + + test_msg.specan.amplitude_value[71] = 221; + + test_msg.specan.amplitude_value[72] = 5; + + test_msg.specan.amplitude_value[73] = 224; + + test_msg.specan.amplitude_value[74] = 92; + + test_msg.specan.amplitude_value[75] = 82; + + test_msg.specan.amplitude_value[76] = 109; + + test_msg.specan.amplitude_value[77] = 223; + + test_msg.specan.amplitude_value[78] = 195; + + test_msg.specan.amplitude_value[79] = 233; + + test_msg.specan.amplitude_value[80] = 165; + + test_msg.specan.amplitude_value[81] = 1; + + test_msg.specan.amplitude_value[82] = 82; + + test_msg.specan.amplitude_value[83] = 141; + + test_msg.specan.amplitude_value[84] = 157; + + test_msg.specan.amplitude_value[85] = 177; + + test_msg.specan.amplitude_value[86] = 169; + + test_msg.specan.amplitude_value[87] = 244; + + test_msg.specan.amplitude_value[88] = 131; + + test_msg.specan.amplitude_value[89] = 96; + + test_msg.specan.amplitude_value[90] = 109; + + test_msg.specan.amplitude_value[91] = 111; + + test_msg.specan.amplitude_value[92] = 253; + + test_msg.specan.amplitude_value[93] = 149; + + test_msg.specan.amplitude_value[94] = 28; + + test_msg.specan.amplitude_value[95] = 225; + + test_msg.specan.amplitude_value[96] = 225; + + test_msg.specan.amplitude_value[97] = 72; + + test_msg.specan.amplitude_value[98] = 158; + + test_msg.specan.amplitude_value[99] = 158; + + test_msg.specan.amplitude_value[100] = 210; + + test_msg.specan.amplitude_value[101] = 196; + + test_msg.specan.amplitude_value[102] = 206; + + test_msg.specan.amplitude_value[103] = 70; + + test_msg.specan.amplitude_value[104] = 63; + + test_msg.specan.amplitude_value[105] = 225; + + test_msg.specan.amplitude_value[106] = 184; + + test_msg.specan.amplitude_value[107] = 150; + + test_msg.specan.amplitude_value[108] = 174; + + test_msg.specan.amplitude_value[109] = 240; + + test_msg.specan.amplitude_value[110] = 45; + + test_msg.specan.amplitude_value[111] = 146; + + test_msg.specan.amplitude_value[112] = 59; + + test_msg.specan.amplitude_value[113] = 82; + + test_msg.specan.amplitude_value[114] = 194; + + test_msg.specan.amplitude_value[115] = 4; + + test_msg.specan.amplitude_value[116] = 179; + + test_msg.specan.amplitude_value[117] = 148; + + test_msg.specan.amplitude_value[118] = 66; + + test_msg.specan.amplitude_value[119] = 254; + + test_msg.specan.amplitude_value[120] = 115; + + test_msg.specan.amplitude_value[121] = 77; + + test_msg.specan.amplitude_value[122] = 30; + + test_msg.specan.amplitude_value[123] = 46; + + test_msg.specan.amplitude_value[124] = 4; + + test_msg.specan.amplitude_value[125] = 204; + + test_msg.specan.amplitude_value[126] = 37; + + test_msg.specan.amplitude_value[127] = 200; + + test_msg.specan.amplitude_value[128] = 121; + + test_msg.specan.amplitude_value[129] = 18; + + test_msg.specan.amplitude_value[130] = 17; + + test_msg.specan.amplitude_value[131] = 171; + + test_msg.specan.amplitude_value[132] = 102; + + test_msg.specan.amplitude_value[133] = 163; + + test_msg.specan.amplitude_value[134] = 175; + + test_msg.specan.amplitude_value[135] = 50; + + test_msg.specan.amplitude_value[136] = 66; + + test_msg.specan.amplitude_value[137] = 101; + + test_msg.specan.amplitude_value[138] = 69; + + test_msg.specan.amplitude_value[139] = 13; + + test_msg.specan.amplitude_value[140] = 223; + + test_msg.specan.amplitude_value[141] = 172; + + test_msg.specan.amplitude_value[142] = 160; + + test_msg.specan.amplitude_value[143] = 233; + + test_msg.specan.amplitude_value[144] = 220; + + test_msg.specan.amplitude_value[145] = 101; + + test_msg.specan.amplitude_value[146] = 237; + + test_msg.specan.amplitude_value[147] = 156; + + test_msg.specan.amplitude_value[148] = 62; + + test_msg.specan.amplitude_value[149] = 117; + + test_msg.specan.amplitude_value[150] = 47; + + test_msg.specan.amplitude_value[151] = 143; + + test_msg.specan.amplitude_value[152] = 94; + + test_msg.specan.amplitude_value[153] = 135; + + test_msg.specan.amplitude_value[154] = 22; + + test_msg.specan.amplitude_value[155] = 155; + + test_msg.specan.amplitude_value[156] = 113; + + test_msg.specan.amplitude_value[157] = 110; + + test_msg.specan.amplitude_value[158] = 15; + + test_msg.specan.amplitude_value[159] = 243; + + test_msg.specan.amplitude_value[160] = 141; + + test_msg.specan.amplitude_value[161] = 227; + + test_msg.specan.amplitude_value[162] = 46; + + test_msg.specan.amplitude_value[163] = 143; + + test_msg.specan.amplitude_value[164] = 227; + + test_msg.specan.amplitude_value[165] = 209; + + test_msg.specan.amplitude_value[166] = 249; + + test_msg.specan.amplitude_value[167] = 2; + + test_msg.specan.amplitude_value[168] = 153; + + test_msg.specan.amplitude_value[169] = 168; + + test_msg.specan.amplitude_value[170] = 131; + + test_msg.specan.amplitude_value[171] = 249; + + test_msg.specan.amplitude_value[172] = 160; + + test_msg.specan.amplitude_value[173] = 88; + + test_msg.specan.amplitude_value[174] = 38; + + test_msg.specan.amplitude_value[175] = 117; + + test_msg.specan.amplitude_value[176] = 129; + + test_msg.specan.amplitude_value[177] = 57; + + test_msg.specan.amplitude_value[178] = 40; + + test_msg.specan.amplitude_value[179] = 109; + + test_msg.specan.amplitude_value[180] = 209; + + test_msg.specan.amplitude_value[181] = 177; + + test_msg.specan.amplitude_value[182] = 38; + + test_msg.specan.amplitude_value[183] = 47; + + test_msg.specan.amplitude_value[184] = 12; + + test_msg.specan.amplitude_value[185] = 15; + + test_msg.specan.amplitude_value[186] = 16; + + test_msg.specan.amplitude_value[187] = 9; + + test_msg.specan.amplitude_value[188] = 175; + + test_msg.specan.amplitude_value[189] = 69; + + test_msg.specan.amplitude_value[190] = 70; + + test_msg.specan.amplitude_value[191] = 182; + + test_msg.specan.amplitude_value[192] = 239; + + test_msg.specan.amplitude_value[193] = 117; + + test_msg.specan.amplitude_value[194] = 135; + + test_msg.specan.amplitude_value[195] = 6; + + test_msg.specan.amplitude_value[196] = 71; + + test_msg.specan.amplitude_value[197] = 99; + + test_msg.specan.amplitude_value[198] = 230; + + test_msg.specan.amplitude_value[199] = 115; + + test_msg.specan.amplitude_value[200] = 2; + + test_msg.specan.amplitude_value[201] = 71; + + test_msg.specan.amplitude_value[202] = 165; + + test_msg.specan.amplitude_value[203] = 228; + + test_msg.specan.amplitude_value[204] = 123; + + test_msg.specan.amplitude_value[205] = 210; + + test_msg.specan.amplitude_value[206] = 168; + + test_msg.specan.amplitude_value[207] = 90; + + test_msg.specan.amplitude_value[208] = 124; + + test_msg.specan.amplitude_value[209] = 20; + + test_msg.specan.amplitude_value[210] = 7; + + test_msg.specan.amplitude_value[211] = 220; + + test_msg.specan.amplitude_value[212] = 144; + + test_msg.specan.amplitude_value[213] = 168; + + test_msg.specan.amplitude_value[214] = 69; + + test_msg.specan.amplitude_value[215] = 22; + + test_msg.specan.amplitude_value[216] = 72; + + test_msg.specan.amplitude_value[217] = 162; + + test_msg.specan.amplitude_value[218] = 69; + + test_msg.specan.amplitude_value[219] = 111; + + test_msg.specan.amplitude_value[220] = 91; + + test_msg.specan.amplitude_value[221] = 251; + + test_msg.specan.amplitude_value[222] = 72; + + test_msg.specan.amplitude_value[223] = 220; + + test_msg.specan.amplitude_value[224] = 28; + + test_msg.specan.amplitude_value[225] = 119; + + test_msg.specan.amplitude_value[226] = 150; + + test_msg.specan.channel_tag = 35146; + + test_msg.specan.freq_ref = 7737.2001953125; + + test_msg.specan.freq_step = 8226.2001953125; + + test_msg.specan.n_amplitude_value = 227; + + test_msg.specan.t.ns_residual = -1479025396; + + test_msg.specan.t.tow = 1227027783; + + test_msg.specan.t.wn = 5075; + + sbp_message_send(&sbp_state, SbpMsgSpecan, 54300, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54300, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSpecan, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + (last_msg.msg.specan.amplitude_ref * 100 - 3780.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.specan.amplitude_ref, expected " + "3780.19995117, is %s", + last_msg.msg.specan.amplitude_ref); + + ck_assert_msg( + (last_msg.msg.specan.amplitude_unit * 100 - 1329.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.specan.amplitude_unit, expected " + "1329.19995117, is %s", + last_msg.msg.specan.amplitude_unit); + + ck_assert_msg(last_msg.msg.specan.amplitude_value[0] == 100, + "incorrect value for last_msg.msg.specan.amplitude_value[0], " + "expected 100, is %d", + last_msg.msg.specan.amplitude_value[0]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[1] == 179, + "incorrect value for last_msg.msg.specan.amplitude_value[1], " + "expected 179, is %d", + last_msg.msg.specan.amplitude_value[1]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[2] == 185, + "incorrect value for last_msg.msg.specan.amplitude_value[2], " + "expected 185, is %d", + last_msg.msg.specan.amplitude_value[2]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[3] == 17, + "incorrect value for last_msg.msg.specan.amplitude_value[3], " + "expected 17, is %d", + last_msg.msg.specan.amplitude_value[3]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[4] == 175, + "incorrect value for last_msg.msg.specan.amplitude_value[4], " + "expected 175, is %d", + last_msg.msg.specan.amplitude_value[4]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[5] == 49, + "incorrect value for last_msg.msg.specan.amplitude_value[5], " + "expected 49, is %d", + last_msg.msg.specan.amplitude_value[5]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[6] == 193, + "incorrect value for last_msg.msg.specan.amplitude_value[6], " + "expected 193, is %d", + last_msg.msg.specan.amplitude_value[6]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[7] == 228, + "incorrect value for last_msg.msg.specan.amplitude_value[7], " + "expected 228, is %d", + last_msg.msg.specan.amplitude_value[7]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[8] == 228, + "incorrect value for last_msg.msg.specan.amplitude_value[8], " + "expected 228, is %d", + last_msg.msg.specan.amplitude_value[8]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[9] == 47, + "incorrect value for last_msg.msg.specan.amplitude_value[9], " + "expected 47, is %d", + last_msg.msg.specan.amplitude_value[9]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[10] == 33, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[10], expected 33, is %d", + last_msg.msg.specan.amplitude_value[10]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[11] == 24, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[11], expected 24, is %d", + last_msg.msg.specan.amplitude_value[11]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[12] == 141, + "incorrect value for last_msg.msg.specan.amplitude_value[12], expected " + "141, is %d", + last_msg.msg.specan.amplitude_value[12]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[13] == 177, + "incorrect value for last_msg.msg.specan.amplitude_value[13], expected " + "177, is %d", + last_msg.msg.specan.amplitude_value[13]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[14] == 18, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[14], expected 18, is %d", + last_msg.msg.specan.amplitude_value[14]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[15] == 99, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[15], expected 99, is %d", + last_msg.msg.specan.amplitude_value[15]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[16] == 246, + "incorrect value for last_msg.msg.specan.amplitude_value[16], expected " + "246, is %d", + last_msg.msg.specan.amplitude_value[16]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[17] == 121, + "incorrect value for last_msg.msg.specan.amplitude_value[17], expected " + "121, is %d", + last_msg.msg.specan.amplitude_value[17]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[18] == 61, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[18], expected 61, is %d", + last_msg.msg.specan.amplitude_value[18]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[19] == 40, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[19], expected 40, is %d", + last_msg.msg.specan.amplitude_value[19]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[20] == 91, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[20], expected 91, is %d", + last_msg.msg.specan.amplitude_value[20]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[21] == 145, + "incorrect value for last_msg.msg.specan.amplitude_value[21], expected " + "145, is %d", + last_msg.msg.specan.amplitude_value[21]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[22] == 223, + "incorrect value for last_msg.msg.specan.amplitude_value[22], expected " + "223, is %d", + last_msg.msg.specan.amplitude_value[22]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[23] == 167, + "incorrect value for last_msg.msg.specan.amplitude_value[23], expected " + "167, is %d", + last_msg.msg.specan.amplitude_value[23]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[24] == 174, + "incorrect value for last_msg.msg.specan.amplitude_value[24], expected " + "174, is %d", + last_msg.msg.specan.amplitude_value[24]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[25] == 9, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[25], expected 9, is %d", + last_msg.msg.specan.amplitude_value[25]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[26] == 116, + "incorrect value for last_msg.msg.specan.amplitude_value[26], expected " + "116, is %d", + last_msg.msg.specan.amplitude_value[26]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[27] == 11, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[27], expected 11, is %d", + last_msg.msg.specan.amplitude_value[27]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[28] == 247, + "incorrect value for last_msg.msg.specan.amplitude_value[28], expected " + "247, is %d", + last_msg.msg.specan.amplitude_value[28]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[29] == 84, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[29], expected 84, is %d", + last_msg.msg.specan.amplitude_value[29]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[30] == 49, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[30], expected 49, is %d", + last_msg.msg.specan.amplitude_value[30]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[31] == 153, + "incorrect value for last_msg.msg.specan.amplitude_value[31], expected " + "153, is %d", + last_msg.msg.specan.amplitude_value[31]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[32] == 205, + "incorrect value for last_msg.msg.specan.amplitude_value[32], expected " + "205, is %d", + last_msg.msg.specan.amplitude_value[32]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[33] == 2, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[33], expected 2, is %d", + last_msg.msg.specan.amplitude_value[33]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[34] == 230, + "incorrect value for last_msg.msg.specan.amplitude_value[34], expected " + "230, is %d", + last_msg.msg.specan.amplitude_value[34]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[35] == 194, + "incorrect value for last_msg.msg.specan.amplitude_value[35], expected " + "194, is %d", + last_msg.msg.specan.amplitude_value[35]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[36] == 218, + "incorrect value for last_msg.msg.specan.amplitude_value[36], expected " + "218, is %d", + last_msg.msg.specan.amplitude_value[36]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[37] == 241, + "incorrect value for last_msg.msg.specan.amplitude_value[37], expected " + "241, is %d", + last_msg.msg.specan.amplitude_value[37]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[38] == 101, + "incorrect value for last_msg.msg.specan.amplitude_value[38], expected " + "101, is %d", + last_msg.msg.specan.amplitude_value[38]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[39] == 107, + "incorrect value for last_msg.msg.specan.amplitude_value[39], expected " + "107, is %d", + last_msg.msg.specan.amplitude_value[39]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[40] == 45, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[40], expected 45, is %d", + last_msg.msg.specan.amplitude_value[40]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[41] == 137, + "incorrect value for last_msg.msg.specan.amplitude_value[41], expected " + "137, is %d", + last_msg.msg.specan.amplitude_value[41]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[42] == 93, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[42], expected 93, is %d", + last_msg.msg.specan.amplitude_value[42]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[43] == 114, + "incorrect value for last_msg.msg.specan.amplitude_value[43], expected " + "114, is %d", + last_msg.msg.specan.amplitude_value[43]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[44] == 230, + "incorrect value for last_msg.msg.specan.amplitude_value[44], expected " + "230, is %d", + last_msg.msg.specan.amplitude_value[44]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[45] == 43, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[45], expected 43, is %d", + last_msg.msg.specan.amplitude_value[45]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[46] == 224, + "incorrect value for last_msg.msg.specan.amplitude_value[46], expected " + "224, is %d", + last_msg.msg.specan.amplitude_value[46]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[47] == 23, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[47], expected 23, is %d", + last_msg.msg.specan.amplitude_value[47]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[48] == 74, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[48], expected 74, is %d", + last_msg.msg.specan.amplitude_value[48]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[49] == 209, + "incorrect value for last_msg.msg.specan.amplitude_value[49], expected " + "209, is %d", + last_msg.msg.specan.amplitude_value[49]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[50] == 199, + "incorrect value for last_msg.msg.specan.amplitude_value[50], expected " + "199, is %d", + last_msg.msg.specan.amplitude_value[50]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[51] == 211, + "incorrect value for last_msg.msg.specan.amplitude_value[51], expected " + "211, is %d", + last_msg.msg.specan.amplitude_value[51]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[52] == 130, + "incorrect value for last_msg.msg.specan.amplitude_value[52], expected " + "130, is %d", + last_msg.msg.specan.amplitude_value[52]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[53] == 89, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[53], expected 89, is %d", + last_msg.msg.specan.amplitude_value[53]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[54] == 220, + "incorrect value for last_msg.msg.specan.amplitude_value[54], expected " + "220, is %d", + last_msg.msg.specan.amplitude_value[54]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[55] == 163, + "incorrect value for last_msg.msg.specan.amplitude_value[55], expected " + "163, is %d", + last_msg.msg.specan.amplitude_value[55]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[56] == 68, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[56], expected 68, is %d", + last_msg.msg.specan.amplitude_value[56]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[57] == 20, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[57], expected 20, is %d", + last_msg.msg.specan.amplitude_value[57]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[58] == 253, + "incorrect value for last_msg.msg.specan.amplitude_value[58], expected " + "253, is %d", + last_msg.msg.specan.amplitude_value[58]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[59] == 7, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[59], expected 7, is %d", + last_msg.msg.specan.amplitude_value[59]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[60] == 206, + "incorrect value for last_msg.msg.specan.amplitude_value[60], expected " + "206, is %d", + last_msg.msg.specan.amplitude_value[60]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[61] == 50, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[61], expected 50, is %d", + last_msg.msg.specan.amplitude_value[61]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[62] == 129, + "incorrect value for last_msg.msg.specan.amplitude_value[62], expected " + "129, is %d", + last_msg.msg.specan.amplitude_value[62]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[63] == 116, + "incorrect value for last_msg.msg.specan.amplitude_value[63], expected " + "116, is %d", + last_msg.msg.specan.amplitude_value[63]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[64] == 194, + "incorrect value for last_msg.msg.specan.amplitude_value[64], expected " + "194, is %d", + last_msg.msg.specan.amplitude_value[64]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[65] == 23, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[65], expected 23, is %d", + last_msg.msg.specan.amplitude_value[65]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[66] == 31, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[66], expected 31, is %d", + last_msg.msg.specan.amplitude_value[66]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[67] == 226, + "incorrect value for last_msg.msg.specan.amplitude_value[67], expected " + "226, is %d", + last_msg.msg.specan.amplitude_value[67]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[68] == 217, + "incorrect value for last_msg.msg.specan.amplitude_value[68], expected " + "217, is %d", + last_msg.msg.specan.amplitude_value[68]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[69] == 157, + "incorrect value for last_msg.msg.specan.amplitude_value[69], expected " + "157, is %d", + last_msg.msg.specan.amplitude_value[69]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[70] == 205, + "incorrect value for last_msg.msg.specan.amplitude_value[70], expected " + "205, is %d", + last_msg.msg.specan.amplitude_value[70]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[71] == 221, + "incorrect value for last_msg.msg.specan.amplitude_value[71], expected " + "221, is %d", + last_msg.msg.specan.amplitude_value[71]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[72] == 5, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[72], expected 5, is %d", + last_msg.msg.specan.amplitude_value[72]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[73] == 224, + "incorrect value for last_msg.msg.specan.amplitude_value[73], expected " + "224, is %d", + last_msg.msg.specan.amplitude_value[73]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[74] == 92, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[74], expected 92, is %d", + last_msg.msg.specan.amplitude_value[74]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[75] == 82, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[75], expected 82, is %d", + last_msg.msg.specan.amplitude_value[75]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[76] == 109, + "incorrect value for last_msg.msg.specan.amplitude_value[76], expected " + "109, is %d", + last_msg.msg.specan.amplitude_value[76]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[77] == 223, + "incorrect value for last_msg.msg.specan.amplitude_value[77], expected " + "223, is %d", + last_msg.msg.specan.amplitude_value[77]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[78] == 195, + "incorrect value for last_msg.msg.specan.amplitude_value[78], expected " + "195, is %d", + last_msg.msg.specan.amplitude_value[78]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[79] == 233, + "incorrect value for last_msg.msg.specan.amplitude_value[79], expected " + "233, is %d", + last_msg.msg.specan.amplitude_value[79]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[80] == 165, + "incorrect value for last_msg.msg.specan.amplitude_value[80], expected " + "165, is %d", + last_msg.msg.specan.amplitude_value[80]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[81] == 1, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[81], expected 1, is %d", + last_msg.msg.specan.amplitude_value[81]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[82] == 82, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[82], expected 82, is %d", + last_msg.msg.specan.amplitude_value[82]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[83] == 141, + "incorrect value for last_msg.msg.specan.amplitude_value[83], expected " + "141, is %d", + last_msg.msg.specan.amplitude_value[83]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[84] == 157, + "incorrect value for last_msg.msg.specan.amplitude_value[84], expected " + "157, is %d", + last_msg.msg.specan.amplitude_value[84]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[85] == 177, + "incorrect value for last_msg.msg.specan.amplitude_value[85], expected " + "177, is %d", + last_msg.msg.specan.amplitude_value[85]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[86] == 169, + "incorrect value for last_msg.msg.specan.amplitude_value[86], expected " + "169, is %d", + last_msg.msg.specan.amplitude_value[86]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[87] == 244, + "incorrect value for last_msg.msg.specan.amplitude_value[87], expected " + "244, is %d", + last_msg.msg.specan.amplitude_value[87]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[88] == 131, + "incorrect value for last_msg.msg.specan.amplitude_value[88], expected " + "131, is %d", + last_msg.msg.specan.amplitude_value[88]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[89] == 96, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[89], expected 96, is %d", + last_msg.msg.specan.amplitude_value[89]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[90] == 109, + "incorrect value for last_msg.msg.specan.amplitude_value[90], expected " + "109, is %d", + last_msg.msg.specan.amplitude_value[90]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[91] == 111, + "incorrect value for last_msg.msg.specan.amplitude_value[91], expected " + "111, is %d", + last_msg.msg.specan.amplitude_value[91]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[92] == 253, + "incorrect value for last_msg.msg.specan.amplitude_value[92], expected " + "253, is %d", + last_msg.msg.specan.amplitude_value[92]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[93] == 149, + "incorrect value for last_msg.msg.specan.amplitude_value[93], expected " + "149, is %d", + last_msg.msg.specan.amplitude_value[93]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[94] == 28, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[94], expected 28, is %d", + last_msg.msg.specan.amplitude_value[94]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[95] == 225, + "incorrect value for last_msg.msg.specan.amplitude_value[95], expected " + "225, is %d", + last_msg.msg.specan.amplitude_value[95]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[96] == 225, + "incorrect value for last_msg.msg.specan.amplitude_value[96], expected " + "225, is %d", + last_msg.msg.specan.amplitude_value[96]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[97] == 72, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[97], expected 72, is %d", + last_msg.msg.specan.amplitude_value[97]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[98] == 158, + "incorrect value for last_msg.msg.specan.amplitude_value[98], expected " + "158, is %d", + last_msg.msg.specan.amplitude_value[98]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[99] == 158, + "incorrect value for last_msg.msg.specan.amplitude_value[99], expected " + "158, is %d", + last_msg.msg.specan.amplitude_value[99]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[100] == 210, + "incorrect value for last_msg.msg.specan.amplitude_value[100], " + "expected 210, is %d", + last_msg.msg.specan.amplitude_value[100]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[101] == 196, + "incorrect value for last_msg.msg.specan.amplitude_value[101], " + "expected 196, is %d", + last_msg.msg.specan.amplitude_value[101]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[102] == 206, + "incorrect value for last_msg.msg.specan.amplitude_value[102], " + "expected 206, is %d", + last_msg.msg.specan.amplitude_value[102]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[103] == 70, + "incorrect value for last_msg.msg.specan.amplitude_value[103], " + "expected 70, is %d", + last_msg.msg.specan.amplitude_value[103]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[104] == 63, + "incorrect value for last_msg.msg.specan.amplitude_value[104], " + "expected 63, is %d", + last_msg.msg.specan.amplitude_value[104]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[105] == 225, + "incorrect value for last_msg.msg.specan.amplitude_value[105], " + "expected 225, is %d", + last_msg.msg.specan.amplitude_value[105]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[106] == 184, + "incorrect value for last_msg.msg.specan.amplitude_value[106], " + "expected 184, is %d", + last_msg.msg.specan.amplitude_value[106]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[107] == 150, + "incorrect value for last_msg.msg.specan.amplitude_value[107], " + "expected 150, is %d", + last_msg.msg.specan.amplitude_value[107]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[108] == 174, + "incorrect value for last_msg.msg.specan.amplitude_value[108], " + "expected 174, is %d", + last_msg.msg.specan.amplitude_value[108]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[109] == 240, + "incorrect value for last_msg.msg.specan.amplitude_value[109], " + "expected 240, is %d", + last_msg.msg.specan.amplitude_value[109]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[110] == 45, + "incorrect value for last_msg.msg.specan.amplitude_value[110], " + "expected 45, is %d", + last_msg.msg.specan.amplitude_value[110]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[111] == 146, + "incorrect value for last_msg.msg.specan.amplitude_value[111], " + "expected 146, is %d", + last_msg.msg.specan.amplitude_value[111]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[112] == 59, + "incorrect value for last_msg.msg.specan.amplitude_value[112], " + "expected 59, is %d", + last_msg.msg.specan.amplitude_value[112]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[113] == 82, + "incorrect value for last_msg.msg.specan.amplitude_value[113], " + "expected 82, is %d", + last_msg.msg.specan.amplitude_value[113]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[114] == 194, + "incorrect value for last_msg.msg.specan.amplitude_value[114], " + "expected 194, is %d", + last_msg.msg.specan.amplitude_value[114]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[115] == 4, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[115], expected 4, is %d", + last_msg.msg.specan.amplitude_value[115]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[116] == 179, + "incorrect value for last_msg.msg.specan.amplitude_value[116], " + "expected 179, is %d", + last_msg.msg.specan.amplitude_value[116]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[117] == 148, + "incorrect value for last_msg.msg.specan.amplitude_value[117], " + "expected 148, is %d", + last_msg.msg.specan.amplitude_value[117]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[118] == 66, + "incorrect value for last_msg.msg.specan.amplitude_value[118], " + "expected 66, is %d", + last_msg.msg.specan.amplitude_value[118]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[119] == 254, + "incorrect value for last_msg.msg.specan.amplitude_value[119], " + "expected 254, is %d", + last_msg.msg.specan.amplitude_value[119]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[120] == 115, + "incorrect value for last_msg.msg.specan.amplitude_value[120], " + "expected 115, is %d", + last_msg.msg.specan.amplitude_value[120]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[121] == 77, + "incorrect value for last_msg.msg.specan.amplitude_value[121], " + "expected 77, is %d", + last_msg.msg.specan.amplitude_value[121]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[122] == 30, + "incorrect value for last_msg.msg.specan.amplitude_value[122], " + "expected 30, is %d", + last_msg.msg.specan.amplitude_value[122]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[123] == 46, + "incorrect value for last_msg.msg.specan.amplitude_value[123], " + "expected 46, is %d", + last_msg.msg.specan.amplitude_value[123]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[124] == 4, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[124], expected 4, is %d", + last_msg.msg.specan.amplitude_value[124]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[125] == 204, + "incorrect value for last_msg.msg.specan.amplitude_value[125], " + "expected 204, is %d", + last_msg.msg.specan.amplitude_value[125]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[126] == 37, + "incorrect value for last_msg.msg.specan.amplitude_value[126], " + "expected 37, is %d", + last_msg.msg.specan.amplitude_value[126]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[127] == 200, + "incorrect value for last_msg.msg.specan.amplitude_value[127], " + "expected 200, is %d", + last_msg.msg.specan.amplitude_value[127]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[128] == 121, + "incorrect value for last_msg.msg.specan.amplitude_value[128], " + "expected 121, is %d", + last_msg.msg.specan.amplitude_value[128]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[129] == 18, + "incorrect value for last_msg.msg.specan.amplitude_value[129], " + "expected 18, is %d", + last_msg.msg.specan.amplitude_value[129]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[130] == 17, + "incorrect value for last_msg.msg.specan.amplitude_value[130], " + "expected 17, is %d", + last_msg.msg.specan.amplitude_value[130]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[131] == 171, + "incorrect value for last_msg.msg.specan.amplitude_value[131], " + "expected 171, is %d", + last_msg.msg.specan.amplitude_value[131]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[132] == 102, + "incorrect value for last_msg.msg.specan.amplitude_value[132], " + "expected 102, is %d", + last_msg.msg.specan.amplitude_value[132]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[133] == 163, + "incorrect value for last_msg.msg.specan.amplitude_value[133], " + "expected 163, is %d", + last_msg.msg.specan.amplitude_value[133]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[134] == 175, + "incorrect value for last_msg.msg.specan.amplitude_value[134], " + "expected 175, is %d", + last_msg.msg.specan.amplitude_value[134]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[135] == 50, + "incorrect value for last_msg.msg.specan.amplitude_value[135], " + "expected 50, is %d", + last_msg.msg.specan.amplitude_value[135]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[136] == 66, + "incorrect value for last_msg.msg.specan.amplitude_value[136], " + "expected 66, is %d", + last_msg.msg.specan.amplitude_value[136]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[137] == 101, + "incorrect value for last_msg.msg.specan.amplitude_value[137], " + "expected 101, is %d", + last_msg.msg.specan.amplitude_value[137]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[138] == 69, + "incorrect value for last_msg.msg.specan.amplitude_value[138], " + "expected 69, is %d", + last_msg.msg.specan.amplitude_value[138]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[139] == 13, + "incorrect value for last_msg.msg.specan.amplitude_value[139], " + "expected 13, is %d", + last_msg.msg.specan.amplitude_value[139]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[140] == 223, + "incorrect value for last_msg.msg.specan.amplitude_value[140], " + "expected 223, is %d", + last_msg.msg.specan.amplitude_value[140]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[141] == 172, + "incorrect value for last_msg.msg.specan.amplitude_value[141], " + "expected 172, is %d", + last_msg.msg.specan.amplitude_value[141]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[142] == 160, + "incorrect value for last_msg.msg.specan.amplitude_value[142], " + "expected 160, is %d", + last_msg.msg.specan.amplitude_value[142]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[143] == 233, + "incorrect value for last_msg.msg.specan.amplitude_value[143], " + "expected 233, is %d", + last_msg.msg.specan.amplitude_value[143]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[144] == 220, + "incorrect value for last_msg.msg.specan.amplitude_value[144], " + "expected 220, is %d", + last_msg.msg.specan.amplitude_value[144]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[145] == 101, + "incorrect value for last_msg.msg.specan.amplitude_value[145], " + "expected 101, is %d", + last_msg.msg.specan.amplitude_value[145]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[146] == 237, + "incorrect value for last_msg.msg.specan.amplitude_value[146], " + "expected 237, is %d", + last_msg.msg.specan.amplitude_value[146]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[147] == 156, + "incorrect value for last_msg.msg.specan.amplitude_value[147], " + "expected 156, is %d", + last_msg.msg.specan.amplitude_value[147]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[148] == 62, + "incorrect value for last_msg.msg.specan.amplitude_value[148], " + "expected 62, is %d", + last_msg.msg.specan.amplitude_value[148]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[149] == 117, + "incorrect value for last_msg.msg.specan.amplitude_value[149], " + "expected 117, is %d", + last_msg.msg.specan.amplitude_value[149]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[150] == 47, + "incorrect value for last_msg.msg.specan.amplitude_value[150], " + "expected 47, is %d", + last_msg.msg.specan.amplitude_value[150]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[151] == 143, + "incorrect value for last_msg.msg.specan.amplitude_value[151], " + "expected 143, is %d", + last_msg.msg.specan.amplitude_value[151]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[152] == 94, + "incorrect value for last_msg.msg.specan.amplitude_value[152], " + "expected 94, is %d", + last_msg.msg.specan.amplitude_value[152]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[153] == 135, + "incorrect value for last_msg.msg.specan.amplitude_value[153], " + "expected 135, is %d", + last_msg.msg.specan.amplitude_value[153]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[154] == 22, + "incorrect value for last_msg.msg.specan.amplitude_value[154], " + "expected 22, is %d", + last_msg.msg.specan.amplitude_value[154]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[155] == 155, + "incorrect value for last_msg.msg.specan.amplitude_value[155], " + "expected 155, is %d", + last_msg.msg.specan.amplitude_value[155]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[156] == 113, + "incorrect value for last_msg.msg.specan.amplitude_value[156], " + "expected 113, is %d", + last_msg.msg.specan.amplitude_value[156]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[157] == 110, + "incorrect value for last_msg.msg.specan.amplitude_value[157], " + "expected 110, is %d", + last_msg.msg.specan.amplitude_value[157]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[158] == 15, + "incorrect value for last_msg.msg.specan.amplitude_value[158], " + "expected 15, is %d", + last_msg.msg.specan.amplitude_value[158]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[159] == 243, + "incorrect value for last_msg.msg.specan.amplitude_value[159], " + "expected 243, is %d", + last_msg.msg.specan.amplitude_value[159]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[160] == 141, + "incorrect value for last_msg.msg.specan.amplitude_value[160], " + "expected 141, is %d", + last_msg.msg.specan.amplitude_value[160]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[161] == 227, + "incorrect value for last_msg.msg.specan.amplitude_value[161], " + "expected 227, is %d", + last_msg.msg.specan.amplitude_value[161]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[162] == 46, + "incorrect value for last_msg.msg.specan.amplitude_value[162], " + "expected 46, is %d", + last_msg.msg.specan.amplitude_value[162]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[163] == 143, + "incorrect value for last_msg.msg.specan.amplitude_value[163], " + "expected 143, is %d", + last_msg.msg.specan.amplitude_value[163]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[164] == 227, + "incorrect value for last_msg.msg.specan.amplitude_value[164], " + "expected 227, is %d", + last_msg.msg.specan.amplitude_value[164]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[165] == 209, + "incorrect value for last_msg.msg.specan.amplitude_value[165], " + "expected 209, is %d", + last_msg.msg.specan.amplitude_value[165]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[166] == 249, + "incorrect value for last_msg.msg.specan.amplitude_value[166], " + "expected 249, is %d", + last_msg.msg.specan.amplitude_value[166]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[167] == 2, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[167], expected 2, is %d", + last_msg.msg.specan.amplitude_value[167]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[168] == 153, + "incorrect value for last_msg.msg.specan.amplitude_value[168], " + "expected 153, is %d", + last_msg.msg.specan.amplitude_value[168]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[169] == 168, + "incorrect value for last_msg.msg.specan.amplitude_value[169], " + "expected 168, is %d", + last_msg.msg.specan.amplitude_value[169]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[170] == 131, + "incorrect value for last_msg.msg.specan.amplitude_value[170], " + "expected 131, is %d", + last_msg.msg.specan.amplitude_value[170]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[171] == 249, + "incorrect value for last_msg.msg.specan.amplitude_value[171], " + "expected 249, is %d", + last_msg.msg.specan.amplitude_value[171]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[172] == 160, + "incorrect value for last_msg.msg.specan.amplitude_value[172], " + "expected 160, is %d", + last_msg.msg.specan.amplitude_value[172]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[173] == 88, + "incorrect value for last_msg.msg.specan.amplitude_value[173], " + "expected 88, is %d", + last_msg.msg.specan.amplitude_value[173]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[174] == 38, + "incorrect value for last_msg.msg.specan.amplitude_value[174], " + "expected 38, is %d", + last_msg.msg.specan.amplitude_value[174]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[175] == 117, + "incorrect value for last_msg.msg.specan.amplitude_value[175], " + "expected 117, is %d", + last_msg.msg.specan.amplitude_value[175]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[176] == 129, + "incorrect value for last_msg.msg.specan.amplitude_value[176], " + "expected 129, is %d", + last_msg.msg.specan.amplitude_value[176]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[177] == 57, + "incorrect value for last_msg.msg.specan.amplitude_value[177], " + "expected 57, is %d", + last_msg.msg.specan.amplitude_value[177]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[178] == 40, + "incorrect value for last_msg.msg.specan.amplitude_value[178], " + "expected 40, is %d", + last_msg.msg.specan.amplitude_value[178]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[179] == 109, + "incorrect value for last_msg.msg.specan.amplitude_value[179], " + "expected 109, is %d", + last_msg.msg.specan.amplitude_value[179]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[180] == 209, + "incorrect value for last_msg.msg.specan.amplitude_value[180], " + "expected 209, is %d", + last_msg.msg.specan.amplitude_value[180]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[181] == 177, + "incorrect value for last_msg.msg.specan.amplitude_value[181], " + "expected 177, is %d", + last_msg.msg.specan.amplitude_value[181]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[182] == 38, + "incorrect value for last_msg.msg.specan.amplitude_value[182], " + "expected 38, is %d", + last_msg.msg.specan.amplitude_value[182]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[183] == 47, + "incorrect value for last_msg.msg.specan.amplitude_value[183], " + "expected 47, is %d", + last_msg.msg.specan.amplitude_value[183]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[184] == 12, + "incorrect value for last_msg.msg.specan.amplitude_value[184], " + "expected 12, is %d", + last_msg.msg.specan.amplitude_value[184]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[185] == 15, + "incorrect value for last_msg.msg.specan.amplitude_value[185], " + "expected 15, is %d", + last_msg.msg.specan.amplitude_value[185]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[186] == 16, + "incorrect value for last_msg.msg.specan.amplitude_value[186], " + "expected 16, is %d", + last_msg.msg.specan.amplitude_value[186]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[187] == 9, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[187], expected 9, is %d", + last_msg.msg.specan.amplitude_value[187]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[188] == 175, + "incorrect value for last_msg.msg.specan.amplitude_value[188], " + "expected 175, is %d", + last_msg.msg.specan.amplitude_value[188]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[189] == 69, + "incorrect value for last_msg.msg.specan.amplitude_value[189], " + "expected 69, is %d", + last_msg.msg.specan.amplitude_value[189]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[190] == 70, + "incorrect value for last_msg.msg.specan.amplitude_value[190], " + "expected 70, is %d", + last_msg.msg.specan.amplitude_value[190]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[191] == 182, + "incorrect value for last_msg.msg.specan.amplitude_value[191], " + "expected 182, is %d", + last_msg.msg.specan.amplitude_value[191]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[192] == 239, + "incorrect value for last_msg.msg.specan.amplitude_value[192], " + "expected 239, is %d", + last_msg.msg.specan.amplitude_value[192]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[193] == 117, + "incorrect value for last_msg.msg.specan.amplitude_value[193], " + "expected 117, is %d", + last_msg.msg.specan.amplitude_value[193]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[194] == 135, + "incorrect value for last_msg.msg.specan.amplitude_value[194], " + "expected 135, is %d", + last_msg.msg.specan.amplitude_value[194]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[195] == 6, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[195], expected 6, is %d", + last_msg.msg.specan.amplitude_value[195]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[196] == 71, + "incorrect value for last_msg.msg.specan.amplitude_value[196], " + "expected 71, is %d", + last_msg.msg.specan.amplitude_value[196]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[197] == 99, + "incorrect value for last_msg.msg.specan.amplitude_value[197], " + "expected 99, is %d", + last_msg.msg.specan.amplitude_value[197]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[198] == 230, + "incorrect value for last_msg.msg.specan.amplitude_value[198], " + "expected 230, is %d", + last_msg.msg.specan.amplitude_value[198]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[199] == 115, + "incorrect value for last_msg.msg.specan.amplitude_value[199], " + "expected 115, is %d", + last_msg.msg.specan.amplitude_value[199]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[200] == 2, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[200], expected 2, is %d", + last_msg.msg.specan.amplitude_value[200]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[201] == 71, + "incorrect value for last_msg.msg.specan.amplitude_value[201], " + "expected 71, is %d", + last_msg.msg.specan.amplitude_value[201]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[202] == 165, + "incorrect value for last_msg.msg.specan.amplitude_value[202], " + "expected 165, is %d", + last_msg.msg.specan.amplitude_value[202]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[203] == 228, + "incorrect value for last_msg.msg.specan.amplitude_value[203], " + "expected 228, is %d", + last_msg.msg.specan.amplitude_value[203]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[204] == 123, + "incorrect value for last_msg.msg.specan.amplitude_value[204], " + "expected 123, is %d", + last_msg.msg.specan.amplitude_value[204]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[205] == 210, + "incorrect value for last_msg.msg.specan.amplitude_value[205], " + "expected 210, is %d", + last_msg.msg.specan.amplitude_value[205]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[206] == 168, + "incorrect value for last_msg.msg.specan.amplitude_value[206], " + "expected 168, is %d", + last_msg.msg.specan.amplitude_value[206]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[207] == 90, + "incorrect value for last_msg.msg.specan.amplitude_value[207], " + "expected 90, is %d", + last_msg.msg.specan.amplitude_value[207]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[208] == 124, + "incorrect value for last_msg.msg.specan.amplitude_value[208], " + "expected 124, is %d", + last_msg.msg.specan.amplitude_value[208]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[209] == 20, + "incorrect value for last_msg.msg.specan.amplitude_value[209], " + "expected 20, is %d", + last_msg.msg.specan.amplitude_value[209]); + ck_assert_msg(last_msg.msg.specan.amplitude_value[210] == 7, + "incorrect value for " + "last_msg.msg.specan.amplitude_value[210], expected 7, is %d", + last_msg.msg.specan.amplitude_value[210]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[211] == 220, + "incorrect value for last_msg.msg.specan.amplitude_value[211], " + "expected 220, is %d", + last_msg.msg.specan.amplitude_value[211]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[212] == 144, + "incorrect value for last_msg.msg.specan.amplitude_value[212], " + "expected 144, is %d", + last_msg.msg.specan.amplitude_value[212]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[213] == 168, + "incorrect value for last_msg.msg.specan.amplitude_value[213], " + "expected 168, is %d", + last_msg.msg.specan.amplitude_value[213]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[214] == 69, + "incorrect value for last_msg.msg.specan.amplitude_value[214], " + "expected 69, is %d", + last_msg.msg.specan.amplitude_value[214]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[215] == 22, + "incorrect value for last_msg.msg.specan.amplitude_value[215], " + "expected 22, is %d", + last_msg.msg.specan.amplitude_value[215]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[216] == 72, + "incorrect value for last_msg.msg.specan.amplitude_value[216], " + "expected 72, is %d", + last_msg.msg.specan.amplitude_value[216]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[217] == 162, + "incorrect value for last_msg.msg.specan.amplitude_value[217], " + "expected 162, is %d", + last_msg.msg.specan.amplitude_value[217]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[218] == 69, + "incorrect value for last_msg.msg.specan.amplitude_value[218], " + "expected 69, is %d", + last_msg.msg.specan.amplitude_value[218]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[219] == 111, + "incorrect value for last_msg.msg.specan.amplitude_value[219], " + "expected 111, is %d", + last_msg.msg.specan.amplitude_value[219]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[220] == 91, + "incorrect value for last_msg.msg.specan.amplitude_value[220], " + "expected 91, is %d", + last_msg.msg.specan.amplitude_value[220]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[221] == 251, + "incorrect value for last_msg.msg.specan.amplitude_value[221], " + "expected 251, is %d", + last_msg.msg.specan.amplitude_value[221]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[222] == 72, + "incorrect value for last_msg.msg.specan.amplitude_value[222], " + "expected 72, is %d", + last_msg.msg.specan.amplitude_value[222]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[223] == 220, + "incorrect value for last_msg.msg.specan.amplitude_value[223], " + "expected 220, is %d", + last_msg.msg.specan.amplitude_value[223]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[224] == 28, + "incorrect value for last_msg.msg.specan.amplitude_value[224], " + "expected 28, is %d", + last_msg.msg.specan.amplitude_value[224]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[225] == 119, + "incorrect value for last_msg.msg.specan.amplitude_value[225], " + "expected 119, is %d", + last_msg.msg.specan.amplitude_value[225]); + ck_assert_msg( + last_msg.msg.specan.amplitude_value[226] == 150, + "incorrect value for last_msg.msg.specan.amplitude_value[226], " + "expected 150, is %d", + last_msg.msg.specan.amplitude_value[226]); + + ck_assert_msg(last_msg.msg.specan.channel_tag == 35146, + "incorrect value for last_msg.msg.specan.channel_tag, " + "expected 35146, is %d", + last_msg.msg.specan.channel_tag); + + ck_assert_msg( + (last_msg.msg.specan.freq_ref * 100 - 7737.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.specan.freq_ref, expected " + "7737.20019531, is %s", + last_msg.msg.specan.freq_ref); + + ck_assert_msg( + (last_msg.msg.specan.freq_step * 100 - 8226.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.specan.freq_step, expected " + "8226.20019531, is %s", + last_msg.msg.specan.freq_step); + + ck_assert_msg(last_msg.msg.specan.n_amplitude_value == 227, + "incorrect value for last_msg.msg.specan.n_amplitude_value, " + "expected 227, is %d", + last_msg.msg.specan.n_amplitude_value); + + ck_assert_msg(last_msg.msg.specan.t.ns_residual == -1479025396, + "incorrect value for last_msg.msg.specan.t.ns_residual, " + "expected -1479025396, is %d", + last_msg.msg.specan.t.ns_residual); + + ck_assert_msg(last_msg.msg.specan.t.tow == 1227027783, + "incorrect value for last_msg.msg.specan.t.tow, expected " + "1227027783, is %d", + last_msg.msg.specan.t.tow); + + ck_assert_msg( + last_msg.msg.specan.t.wn == 5075, + "incorrect value for last_msg.msg.specan.t.wn, expected 5075, is %d", + last_msg.msg.specan.t.wn); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgSpecan_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_piksi_MsgSpecan"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgSpecan"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgSpecan); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgSpecanDep.c b/c/test/auto_check_sbp_piksi_MsgSpecanDep.c new file mode 100644 index 0000000000..4bac3701f3 --- /dev/null +++ b/c/test/auto_check_sbp_piksi_MsgSpecanDep.c @@ -0,0 +1,1837 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_piksi_MsgSpecanDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x50, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, + 154, 97, 198, 69, 154, 1, 144, 69, 205, 20, 18, 70, 51, 211, + 89, 69, 240, 14, 179, 186, 227, 244, 173, 240, 182, 71, 166, 117, + 196, 13, 44, 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, + 77, 186, 68, 135, 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, + 216, 44, 67, 212, 156, 75, 81, 53, 250, 225, 23, 205, 26, 34, + 119, 50, 101, 64, 7, 231, 124, 183, 203, 102, 234, 84, 83, 208, + 23, 68, 54, 179, 98, 96, 116, 244, 246, 94, 104, 94, 13, 56, + 210, 18, 191, 22, 133, 81, 153, 159, 161, 219, 59, 21, 164, 121, + 145, 203, 171, 132, 57, 180, 102, 101, 11, 229, 175, 145, 73, 72, + 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, 193, 7, 109, 44, + 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, 231, 161, 81, + 216, 114, 60, 231, 163, 163, 49, 237, 244, 185, 240, 89, 143, 174, + 165, 211, 241, 13, 16, 61, 141, 101, 89, 37, 117, 189, 86, 118, + 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, 100, + 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, + 181, 12, 140, 16, 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, + 59, 64, 241, 183, 238, 105, 181, 170, 45, 8, 166, 164, 238, 83, + 148, 173, 108, 228, 67, 89, 189, 67, 26, 39, 216, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.specan_dep.amplitude_ref = 9349.2001953125; + + test_msg.specan_dep.amplitude_unit = 3485.199951171875; + + test_msg.specan_dep.amplitude_value[0] = 240; + + test_msg.specan_dep.amplitude_value[1] = 14; + + test_msg.specan_dep.amplitude_value[2] = 179; + + test_msg.specan_dep.amplitude_value[3] = 186; + + test_msg.specan_dep.amplitude_value[4] = 227; + + test_msg.specan_dep.amplitude_value[5] = 244; + + test_msg.specan_dep.amplitude_value[6] = 173; + + test_msg.specan_dep.amplitude_value[7] = 240; + + test_msg.specan_dep.amplitude_value[8] = 182; + + test_msg.specan_dep.amplitude_value[9] = 71; + + test_msg.specan_dep.amplitude_value[10] = 166; + + test_msg.specan_dep.amplitude_value[11] = 117; + + test_msg.specan_dep.amplitude_value[12] = 196; + + test_msg.specan_dep.amplitude_value[13] = 13; + + test_msg.specan_dep.amplitude_value[14] = 44; + + test_msg.specan_dep.amplitude_value[15] = 27; + + test_msg.specan_dep.amplitude_value[16] = 33; + + test_msg.specan_dep.amplitude_value[17] = 28; + + test_msg.specan_dep.amplitude_value[18] = 67; + + test_msg.specan_dep.amplitude_value[19] = 254; + + test_msg.specan_dep.amplitude_value[20] = 3; + + test_msg.specan_dep.amplitude_value[21] = 249; + + test_msg.specan_dep.amplitude_value[22] = 92; + + test_msg.specan_dep.amplitude_value[23] = 44; + + test_msg.specan_dep.amplitude_value[24] = 122; + + test_msg.specan_dep.amplitude_value[25] = 169; + + test_msg.specan_dep.amplitude_value[26] = 77; + + test_msg.specan_dep.amplitude_value[27] = 186; + + test_msg.specan_dep.amplitude_value[28] = 68; + + test_msg.specan_dep.amplitude_value[29] = 135; + + test_msg.specan_dep.amplitude_value[30] = 63; + + test_msg.specan_dep.amplitude_value[31] = 168; + + test_msg.specan_dep.amplitude_value[32] = 162; + + test_msg.specan_dep.amplitude_value[33] = 89; + + test_msg.specan_dep.amplitude_value[34] = 36; + + test_msg.specan_dep.amplitude_value[35] = 186; + + test_msg.specan_dep.amplitude_value[36] = 99; + + test_msg.specan_dep.amplitude_value[37] = 63; + + test_msg.specan_dep.amplitude_value[38] = 105; + + test_msg.specan_dep.amplitude_value[39] = 116; + + test_msg.specan_dep.amplitude_value[40] = 216; + + test_msg.specan_dep.amplitude_value[41] = 44; + + test_msg.specan_dep.amplitude_value[42] = 67; + + test_msg.specan_dep.amplitude_value[43] = 212; + + test_msg.specan_dep.amplitude_value[44] = 156; + + test_msg.specan_dep.amplitude_value[45] = 75; + + test_msg.specan_dep.amplitude_value[46] = 81; + + test_msg.specan_dep.amplitude_value[47] = 53; + + test_msg.specan_dep.amplitude_value[48] = 250; + + test_msg.specan_dep.amplitude_value[49] = 225; + + test_msg.specan_dep.amplitude_value[50] = 23; + + test_msg.specan_dep.amplitude_value[51] = 205; + + test_msg.specan_dep.amplitude_value[52] = 26; + + test_msg.specan_dep.amplitude_value[53] = 34; + + test_msg.specan_dep.amplitude_value[54] = 119; + + test_msg.specan_dep.amplitude_value[55] = 50; + + test_msg.specan_dep.amplitude_value[56] = 101; + + test_msg.specan_dep.amplitude_value[57] = 64; + + test_msg.specan_dep.amplitude_value[58] = 7; + + test_msg.specan_dep.amplitude_value[59] = 231; + + test_msg.specan_dep.amplitude_value[60] = 124; + + test_msg.specan_dep.amplitude_value[61] = 183; + + test_msg.specan_dep.amplitude_value[62] = 203; + + test_msg.specan_dep.amplitude_value[63] = 102; + + test_msg.specan_dep.amplitude_value[64] = 234; + + test_msg.specan_dep.amplitude_value[65] = 84; + + test_msg.specan_dep.amplitude_value[66] = 83; + + test_msg.specan_dep.amplitude_value[67] = 208; + + test_msg.specan_dep.amplitude_value[68] = 23; + + test_msg.specan_dep.amplitude_value[69] = 68; + + test_msg.specan_dep.amplitude_value[70] = 54; + + test_msg.specan_dep.amplitude_value[71] = 179; + + test_msg.specan_dep.amplitude_value[72] = 98; + + test_msg.specan_dep.amplitude_value[73] = 96; + + test_msg.specan_dep.amplitude_value[74] = 116; + + test_msg.specan_dep.amplitude_value[75] = 244; + + test_msg.specan_dep.amplitude_value[76] = 246; + + test_msg.specan_dep.amplitude_value[77] = 94; + + test_msg.specan_dep.amplitude_value[78] = 104; + + test_msg.specan_dep.amplitude_value[79] = 94; + + test_msg.specan_dep.amplitude_value[80] = 13; + + test_msg.specan_dep.amplitude_value[81] = 56; + + test_msg.specan_dep.amplitude_value[82] = 210; + + test_msg.specan_dep.amplitude_value[83] = 18; + + test_msg.specan_dep.amplitude_value[84] = 191; + + test_msg.specan_dep.amplitude_value[85] = 22; + + test_msg.specan_dep.amplitude_value[86] = 133; + + test_msg.specan_dep.amplitude_value[87] = 81; + + test_msg.specan_dep.amplitude_value[88] = 153; + + test_msg.specan_dep.amplitude_value[89] = 159; + + test_msg.specan_dep.amplitude_value[90] = 161; + + test_msg.specan_dep.amplitude_value[91] = 219; + + test_msg.specan_dep.amplitude_value[92] = 59; + + test_msg.specan_dep.amplitude_value[93] = 21; + + test_msg.specan_dep.amplitude_value[94] = 164; + + test_msg.specan_dep.amplitude_value[95] = 121; + + test_msg.specan_dep.amplitude_value[96] = 145; + + test_msg.specan_dep.amplitude_value[97] = 203; + + test_msg.specan_dep.amplitude_value[98] = 171; + + test_msg.specan_dep.amplitude_value[99] = 132; + + test_msg.specan_dep.amplitude_value[100] = 57; + + test_msg.specan_dep.amplitude_value[101] = 180; + + test_msg.specan_dep.amplitude_value[102] = 102; + + test_msg.specan_dep.amplitude_value[103] = 101; + + test_msg.specan_dep.amplitude_value[104] = 11; + + test_msg.specan_dep.amplitude_value[105] = 229; + + test_msg.specan_dep.amplitude_value[106] = 175; + + test_msg.specan_dep.amplitude_value[107] = 145; + + test_msg.specan_dep.amplitude_value[108] = 73; + + test_msg.specan_dep.amplitude_value[109] = 72; + + test_msg.specan_dep.amplitude_value[110] = 124; + + test_msg.specan_dep.amplitude_value[111] = 4; + + test_msg.specan_dep.amplitude_value[112] = 184; + + test_msg.specan_dep.amplitude_value[113] = 228; + + test_msg.specan_dep.amplitude_value[114] = 61; + + test_msg.specan_dep.amplitude_value[115] = 234; + + test_msg.specan_dep.amplitude_value[116] = 218; + + test_msg.specan_dep.amplitude_value[117] = 62; + + test_msg.specan_dep.amplitude_value[118] = 226; + + test_msg.specan_dep.amplitude_value[119] = 217; + + test_msg.specan_dep.amplitude_value[120] = 193; + + test_msg.specan_dep.amplitude_value[121] = 7; + + test_msg.specan_dep.amplitude_value[122] = 109; + + test_msg.specan_dep.amplitude_value[123] = 44; + + test_msg.specan_dep.amplitude_value[124] = 83; + + test_msg.specan_dep.amplitude_value[125] = 201; + + test_msg.specan_dep.amplitude_value[126] = 20; + + test_msg.specan_dep.amplitude_value[127] = 101; + + test_msg.specan_dep.amplitude_value[128] = 9; + + test_msg.specan_dep.amplitude_value[129] = 140; + + test_msg.specan_dep.amplitude_value[130] = 186; + + test_msg.specan_dep.amplitude_value[131] = 162; + + test_msg.specan_dep.amplitude_value[132] = 81; + + test_msg.specan_dep.amplitude_value[133] = 91; + + test_msg.specan_dep.amplitude_value[134] = 30; + + test_msg.specan_dep.amplitude_value[135] = 231; + + test_msg.specan_dep.amplitude_value[136] = 161; + + test_msg.specan_dep.amplitude_value[137] = 81; + + test_msg.specan_dep.amplitude_value[138] = 216; + + test_msg.specan_dep.amplitude_value[139] = 114; + + test_msg.specan_dep.amplitude_value[140] = 60; + + test_msg.specan_dep.amplitude_value[141] = 231; + + test_msg.specan_dep.amplitude_value[142] = 163; + + test_msg.specan_dep.amplitude_value[143] = 163; + + test_msg.specan_dep.amplitude_value[144] = 49; + + test_msg.specan_dep.amplitude_value[145] = 237; + + test_msg.specan_dep.amplitude_value[146] = 244; + + test_msg.specan_dep.amplitude_value[147] = 185; + + test_msg.specan_dep.amplitude_value[148] = 240; + + test_msg.specan_dep.amplitude_value[149] = 89; + + test_msg.specan_dep.amplitude_value[150] = 143; + + test_msg.specan_dep.amplitude_value[151] = 174; + + test_msg.specan_dep.amplitude_value[152] = 165; + + test_msg.specan_dep.amplitude_value[153] = 211; + + test_msg.specan_dep.amplitude_value[154] = 241; + + test_msg.specan_dep.amplitude_value[155] = 13; + + test_msg.specan_dep.amplitude_value[156] = 16; + + test_msg.specan_dep.amplitude_value[157] = 61; + + test_msg.specan_dep.amplitude_value[158] = 141; + + test_msg.specan_dep.amplitude_value[159] = 101; + + test_msg.specan_dep.amplitude_value[160] = 89; + + test_msg.specan_dep.amplitude_value[161] = 37; + + test_msg.specan_dep.amplitude_value[162] = 117; + + test_msg.specan_dep.amplitude_value[163] = 189; + + test_msg.specan_dep.amplitude_value[164] = 86; + + test_msg.specan_dep.amplitude_value[165] = 118; + + test_msg.specan_dep.amplitude_value[166] = 176; + + test_msg.specan_dep.amplitude_value[167] = 228; + + test_msg.specan_dep.amplitude_value[168] = 12; + + test_msg.specan_dep.amplitude_value[169] = 14; + + test_msg.specan_dep.amplitude_value[170] = 119; + + test_msg.specan_dep.amplitude_value[171] = 135; + + test_msg.specan_dep.amplitude_value[172] = 129; + + test_msg.specan_dep.amplitude_value[173] = 243; + + test_msg.specan_dep.amplitude_value[174] = 50; + + test_msg.specan_dep.amplitude_value[175] = 29; + + test_msg.specan_dep.amplitude_value[176] = 207; + + test_msg.specan_dep.amplitude_value[177] = 198; + + test_msg.specan_dep.amplitude_value[178] = 117; + + test_msg.specan_dep.amplitude_value[179] = 100; + + test_msg.specan_dep.amplitude_value[180] = 225; + + test_msg.specan_dep.amplitude_value[181] = 6; + + test_msg.specan_dep.amplitude_value[182] = 139; + + test_msg.specan_dep.amplitude_value[183] = 110; + + test_msg.specan_dep.amplitude_value[184] = 39; + + test_msg.specan_dep.amplitude_value[185] = 210; + + test_msg.specan_dep.amplitude_value[186] = 68; + + test_msg.specan_dep.amplitude_value[187] = 199; + + test_msg.specan_dep.amplitude_value[188] = 43; + + test_msg.specan_dep.amplitude_value[189] = 132; + + test_msg.specan_dep.amplitude_value[190] = 64; + + test_msg.specan_dep.amplitude_value[191] = 17; + + test_msg.specan_dep.amplitude_value[192] = 51; + + test_msg.specan_dep.amplitude_value[193] = 173; + + test_msg.specan_dep.amplitude_value[194] = 181; + + test_msg.specan_dep.amplitude_value[195] = 12; + + test_msg.specan_dep.amplitude_value[196] = 140; + + test_msg.specan_dep.amplitude_value[197] = 16; + + test_msg.specan_dep.amplitude_value[198] = 247; + + test_msg.specan_dep.amplitude_value[199] = 84; + + test_msg.specan_dep.amplitude_value[200] = 183; + + test_msg.specan_dep.amplitude_value[201] = 105; + + test_msg.specan_dep.amplitude_value[202] = 39; + + test_msg.specan_dep.amplitude_value[203] = 157; + + test_msg.specan_dep.amplitude_value[204] = 77; + + test_msg.specan_dep.amplitude_value[205] = 30; + + test_msg.specan_dep.amplitude_value[206] = 205; + + test_msg.specan_dep.amplitude_value[207] = 194; + + test_msg.specan_dep.amplitude_value[208] = 59; + + test_msg.specan_dep.amplitude_value[209] = 64; + + test_msg.specan_dep.amplitude_value[210] = 241; + + test_msg.specan_dep.amplitude_value[211] = 183; + + test_msg.specan_dep.amplitude_value[212] = 238; + + test_msg.specan_dep.amplitude_value[213] = 105; + + test_msg.specan_dep.amplitude_value[214] = 181; + + test_msg.specan_dep.amplitude_value[215] = 170; + + test_msg.specan_dep.amplitude_value[216] = 45; + + test_msg.specan_dep.amplitude_value[217] = 8; + + test_msg.specan_dep.amplitude_value[218] = 166; + + test_msg.specan_dep.amplitude_value[219] = 164; + + test_msg.specan_dep.amplitude_value[220] = 238; + + test_msg.specan_dep.amplitude_value[221] = 83; + + test_msg.specan_dep.amplitude_value[222] = 148; + + test_msg.specan_dep.amplitude_value[223] = 173; + + test_msg.specan_dep.amplitude_value[224] = 108; + + test_msg.specan_dep.amplitude_value[225] = 228; + + test_msg.specan_dep.amplitude_value[226] = 67; + + test_msg.specan_dep.amplitude_value[227] = 89; + + test_msg.specan_dep.amplitude_value[228] = 189; + + test_msg.specan_dep.amplitude_value[229] = 67; + + test_msg.specan_dep.amplitude_value[230] = 26; + + test_msg.specan_dep.channel_tag = 5878; + + test_msg.specan_dep.freq_ref = 6348.2001953125; + + test_msg.specan_dep.freq_step = 4608.2001953125; + + test_msg.specan_dep.n_amplitude_value = 231; + + test_msg.specan_dep.t.tow = 992295133; + + test_msg.specan_dep.t.wn = 6957; + + sbp_message_send(&sbp_state, SbpMsgSpecanDep, 55664, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 55664, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSpecanDep, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg((last_msg.msg.specan_dep.amplitude_ref * 100 - + 9349.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.specan_dep.amplitude_ref, " + "expected 9349.20019531, is %s", + last_msg.msg.specan_dep.amplitude_ref); + + ck_assert_msg((last_msg.msg.specan_dep.amplitude_unit * 100 - + 3485.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.specan_dep.amplitude_unit, " + "expected 3485.19995117, is %s", + last_msg.msg.specan_dep.amplitude_unit); + + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[0] == 240, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[0], " + "expected 240, is %d", + last_msg.msg.specan_dep.amplitude_value[0]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[1] == 14, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[1], " + "expected 14, is %d", + last_msg.msg.specan_dep.amplitude_value[1]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[2] == 179, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[2], " + "expected 179, is %d", + last_msg.msg.specan_dep.amplitude_value[2]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[3] == 186, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[3], " + "expected 186, is %d", + last_msg.msg.specan_dep.amplitude_value[3]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[4] == 227, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[4], " + "expected 227, is %d", + last_msg.msg.specan_dep.amplitude_value[4]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[5] == 244, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[5], " + "expected 244, is %d", + last_msg.msg.specan_dep.amplitude_value[5]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[6] == 173, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[6], " + "expected 173, is %d", + last_msg.msg.specan_dep.amplitude_value[6]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[7] == 240, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[7], " + "expected 240, is %d", + last_msg.msg.specan_dep.amplitude_value[7]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[8] == 182, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[8], " + "expected 182, is %d", + last_msg.msg.specan_dep.amplitude_value[8]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[9] == 71, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[9], " + "expected 71, is %d", + last_msg.msg.specan_dep.amplitude_value[9]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[10] == 166, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[10], " + "expected 166, is %d", + last_msg.msg.specan_dep.amplitude_value[10]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[11] == 117, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[11], " + "expected 117, is %d", + last_msg.msg.specan_dep.amplitude_value[11]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[12] == 196, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[12], " + "expected 196, is %d", + last_msg.msg.specan_dep.amplitude_value[12]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[13] == 13, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[13], " + "expected 13, is %d", + last_msg.msg.specan_dep.amplitude_value[13]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[14] == 44, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[14], " + "expected 44, is %d", + last_msg.msg.specan_dep.amplitude_value[14]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[15] == 27, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[15], " + "expected 27, is %d", + last_msg.msg.specan_dep.amplitude_value[15]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[16] == 33, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[16], " + "expected 33, is %d", + last_msg.msg.specan_dep.amplitude_value[16]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[17] == 28, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[17], " + "expected 28, is %d", + last_msg.msg.specan_dep.amplitude_value[17]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[18] == 67, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[18], " + "expected 67, is %d", + last_msg.msg.specan_dep.amplitude_value[18]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[19] == 254, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[19], " + "expected 254, is %d", + last_msg.msg.specan_dep.amplitude_value[19]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[20] == 3, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[20], " + "expected 3, is %d", + last_msg.msg.specan_dep.amplitude_value[20]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[21] == 249, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[21], " + "expected 249, is %d", + last_msg.msg.specan_dep.amplitude_value[21]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[22] == 92, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[22], " + "expected 92, is %d", + last_msg.msg.specan_dep.amplitude_value[22]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[23] == 44, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[23], " + "expected 44, is %d", + last_msg.msg.specan_dep.amplitude_value[23]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[24] == 122, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[24], " + "expected 122, is %d", + last_msg.msg.specan_dep.amplitude_value[24]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[25] == 169, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[25], " + "expected 169, is %d", + last_msg.msg.specan_dep.amplitude_value[25]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[26] == 77, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[26], " + "expected 77, is %d", + last_msg.msg.specan_dep.amplitude_value[26]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[27] == 186, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[27], " + "expected 186, is %d", + last_msg.msg.specan_dep.amplitude_value[27]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[28] == 68, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[28], " + "expected 68, is %d", + last_msg.msg.specan_dep.amplitude_value[28]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[29] == 135, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[29], " + "expected 135, is %d", + last_msg.msg.specan_dep.amplitude_value[29]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[30] == 63, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[30], " + "expected 63, is %d", + last_msg.msg.specan_dep.amplitude_value[30]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[31] == 168, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[31], " + "expected 168, is %d", + last_msg.msg.specan_dep.amplitude_value[31]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[32] == 162, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[32], " + "expected 162, is %d", + last_msg.msg.specan_dep.amplitude_value[32]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[33] == 89, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[33], " + "expected 89, is %d", + last_msg.msg.specan_dep.amplitude_value[33]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[34] == 36, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[34], " + "expected 36, is %d", + last_msg.msg.specan_dep.amplitude_value[34]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[35] == 186, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[35], " + "expected 186, is %d", + last_msg.msg.specan_dep.amplitude_value[35]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[36] == 99, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[36], " + "expected 99, is %d", + last_msg.msg.specan_dep.amplitude_value[36]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[37] == 63, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[37], " + "expected 63, is %d", + last_msg.msg.specan_dep.amplitude_value[37]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[38] == 105, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[38], " + "expected 105, is %d", + last_msg.msg.specan_dep.amplitude_value[38]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[39] == 116, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[39], " + "expected 116, is %d", + last_msg.msg.specan_dep.amplitude_value[39]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[40] == 216, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[40], " + "expected 216, is %d", + last_msg.msg.specan_dep.amplitude_value[40]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[41] == 44, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[41], " + "expected 44, is %d", + last_msg.msg.specan_dep.amplitude_value[41]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[42] == 67, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[42], " + "expected 67, is %d", + last_msg.msg.specan_dep.amplitude_value[42]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[43] == 212, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[43], " + "expected 212, is %d", + last_msg.msg.specan_dep.amplitude_value[43]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[44] == 156, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[44], " + "expected 156, is %d", + last_msg.msg.specan_dep.amplitude_value[44]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[45] == 75, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[45], " + "expected 75, is %d", + last_msg.msg.specan_dep.amplitude_value[45]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[46] == 81, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[46], " + "expected 81, is %d", + last_msg.msg.specan_dep.amplitude_value[46]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[47] == 53, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[47], " + "expected 53, is %d", + last_msg.msg.specan_dep.amplitude_value[47]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[48] == 250, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[48], " + "expected 250, is %d", + last_msg.msg.specan_dep.amplitude_value[48]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[49] == 225, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[49], " + "expected 225, is %d", + last_msg.msg.specan_dep.amplitude_value[49]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[50] == 23, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[50], " + "expected 23, is %d", + last_msg.msg.specan_dep.amplitude_value[50]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[51] == 205, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[51], " + "expected 205, is %d", + last_msg.msg.specan_dep.amplitude_value[51]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[52] == 26, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[52], " + "expected 26, is %d", + last_msg.msg.specan_dep.amplitude_value[52]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[53] == 34, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[53], " + "expected 34, is %d", + last_msg.msg.specan_dep.amplitude_value[53]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[54] == 119, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[54], " + "expected 119, is %d", + last_msg.msg.specan_dep.amplitude_value[54]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[55] == 50, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[55], " + "expected 50, is %d", + last_msg.msg.specan_dep.amplitude_value[55]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[56] == 101, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[56], " + "expected 101, is %d", + last_msg.msg.specan_dep.amplitude_value[56]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[57] == 64, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[57], " + "expected 64, is %d", + last_msg.msg.specan_dep.amplitude_value[57]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[58] == 7, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[58], " + "expected 7, is %d", + last_msg.msg.specan_dep.amplitude_value[58]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[59] == 231, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[59], " + "expected 231, is %d", + last_msg.msg.specan_dep.amplitude_value[59]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[60] == 124, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[60], " + "expected 124, is %d", + last_msg.msg.specan_dep.amplitude_value[60]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[61] == 183, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[61], " + "expected 183, is %d", + last_msg.msg.specan_dep.amplitude_value[61]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[62] == 203, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[62], " + "expected 203, is %d", + last_msg.msg.specan_dep.amplitude_value[62]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[63] == 102, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[63], " + "expected 102, is %d", + last_msg.msg.specan_dep.amplitude_value[63]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[64] == 234, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[64], " + "expected 234, is %d", + last_msg.msg.specan_dep.amplitude_value[64]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[65] == 84, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[65], " + "expected 84, is %d", + last_msg.msg.specan_dep.amplitude_value[65]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[66] == 83, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[66], " + "expected 83, is %d", + last_msg.msg.specan_dep.amplitude_value[66]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[67] == 208, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[67], " + "expected 208, is %d", + last_msg.msg.specan_dep.amplitude_value[67]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[68] == 23, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[68], " + "expected 23, is %d", + last_msg.msg.specan_dep.amplitude_value[68]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[69] == 68, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[69], " + "expected 68, is %d", + last_msg.msg.specan_dep.amplitude_value[69]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[70] == 54, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[70], " + "expected 54, is %d", + last_msg.msg.specan_dep.amplitude_value[70]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[71] == 179, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[71], " + "expected 179, is %d", + last_msg.msg.specan_dep.amplitude_value[71]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[72] == 98, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[72], " + "expected 98, is %d", + last_msg.msg.specan_dep.amplitude_value[72]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[73] == 96, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[73], " + "expected 96, is %d", + last_msg.msg.specan_dep.amplitude_value[73]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[74] == 116, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[74], " + "expected 116, is %d", + last_msg.msg.specan_dep.amplitude_value[74]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[75] == 244, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[75], " + "expected 244, is %d", + last_msg.msg.specan_dep.amplitude_value[75]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[76] == 246, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[76], " + "expected 246, is %d", + last_msg.msg.specan_dep.amplitude_value[76]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[77] == 94, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[77], " + "expected 94, is %d", + last_msg.msg.specan_dep.amplitude_value[77]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[78] == 104, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[78], " + "expected 104, is %d", + last_msg.msg.specan_dep.amplitude_value[78]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[79] == 94, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[79], " + "expected 94, is %d", + last_msg.msg.specan_dep.amplitude_value[79]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[80] == 13, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[80], " + "expected 13, is %d", + last_msg.msg.specan_dep.amplitude_value[80]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[81] == 56, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[81], " + "expected 56, is %d", + last_msg.msg.specan_dep.amplitude_value[81]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[82] == 210, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[82], " + "expected 210, is %d", + last_msg.msg.specan_dep.amplitude_value[82]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[83] == 18, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[83], " + "expected 18, is %d", + last_msg.msg.specan_dep.amplitude_value[83]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[84] == 191, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[84], " + "expected 191, is %d", + last_msg.msg.specan_dep.amplitude_value[84]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[85] == 22, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[85], " + "expected 22, is %d", + last_msg.msg.specan_dep.amplitude_value[85]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[86] == 133, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[86], " + "expected 133, is %d", + last_msg.msg.specan_dep.amplitude_value[86]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[87] == 81, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[87], " + "expected 81, is %d", + last_msg.msg.specan_dep.amplitude_value[87]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[88] == 153, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[88], " + "expected 153, is %d", + last_msg.msg.specan_dep.amplitude_value[88]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[89] == 159, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[89], " + "expected 159, is %d", + last_msg.msg.specan_dep.amplitude_value[89]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[90] == 161, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[90], " + "expected 161, is %d", + last_msg.msg.specan_dep.amplitude_value[90]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[91] == 219, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[91], " + "expected 219, is %d", + last_msg.msg.specan_dep.amplitude_value[91]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[92] == 59, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[92], " + "expected 59, is %d", + last_msg.msg.specan_dep.amplitude_value[92]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[93] == 21, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[93], " + "expected 21, is %d", + last_msg.msg.specan_dep.amplitude_value[93]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[94] == 164, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[94], " + "expected 164, is %d", + last_msg.msg.specan_dep.amplitude_value[94]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[95] == 121, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[95], " + "expected 121, is %d", + last_msg.msg.specan_dep.amplitude_value[95]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[96] == 145, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[96], " + "expected 145, is %d", + last_msg.msg.specan_dep.amplitude_value[96]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[97] == 203, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[97], " + "expected 203, is %d", + last_msg.msg.specan_dep.amplitude_value[97]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[98] == 171, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[98], " + "expected 171, is %d", + last_msg.msg.specan_dep.amplitude_value[98]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[99] == 132, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[99], " + "expected 132, is %d", + last_msg.msg.specan_dep.amplitude_value[99]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[100] == 57, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[100], " + "expected 57, is %d", + last_msg.msg.specan_dep.amplitude_value[100]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[101] == 180, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[101], " + "expected 180, is %d", + last_msg.msg.specan_dep.amplitude_value[101]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[102] == 102, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[102], " + "expected 102, is %d", + last_msg.msg.specan_dep.amplitude_value[102]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[103] == 101, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[103], " + "expected 101, is %d", + last_msg.msg.specan_dep.amplitude_value[103]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[104] == 11, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[104], " + "expected 11, is %d", + last_msg.msg.specan_dep.amplitude_value[104]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[105] == 229, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[105], " + "expected 229, is %d", + last_msg.msg.specan_dep.amplitude_value[105]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[106] == 175, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[106], " + "expected 175, is %d", + last_msg.msg.specan_dep.amplitude_value[106]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[107] == 145, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[107], " + "expected 145, is %d", + last_msg.msg.specan_dep.amplitude_value[107]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[108] == 73, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[108], " + "expected 73, is %d", + last_msg.msg.specan_dep.amplitude_value[108]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[109] == 72, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[109], " + "expected 72, is %d", + last_msg.msg.specan_dep.amplitude_value[109]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[110] == 124, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[110], " + "expected 124, is %d", + last_msg.msg.specan_dep.amplitude_value[110]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[111] == 4, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[111], " + "expected 4, is %d", + last_msg.msg.specan_dep.amplitude_value[111]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[112] == 184, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[112], " + "expected 184, is %d", + last_msg.msg.specan_dep.amplitude_value[112]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[113] == 228, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[113], " + "expected 228, is %d", + last_msg.msg.specan_dep.amplitude_value[113]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[114] == 61, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[114], " + "expected 61, is %d", + last_msg.msg.specan_dep.amplitude_value[114]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[115] == 234, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[115], " + "expected 234, is %d", + last_msg.msg.specan_dep.amplitude_value[115]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[116] == 218, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[116], " + "expected 218, is %d", + last_msg.msg.specan_dep.amplitude_value[116]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[117] == 62, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[117], " + "expected 62, is %d", + last_msg.msg.specan_dep.amplitude_value[117]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[118] == 226, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[118], " + "expected 226, is %d", + last_msg.msg.specan_dep.amplitude_value[118]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[119] == 217, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[119], " + "expected 217, is %d", + last_msg.msg.specan_dep.amplitude_value[119]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[120] == 193, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[120], " + "expected 193, is %d", + last_msg.msg.specan_dep.amplitude_value[120]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[121] == 7, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[121], " + "expected 7, is %d", + last_msg.msg.specan_dep.amplitude_value[121]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[122] == 109, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[122], " + "expected 109, is %d", + last_msg.msg.specan_dep.amplitude_value[122]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[123] == 44, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[123], " + "expected 44, is %d", + last_msg.msg.specan_dep.amplitude_value[123]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[124] == 83, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[124], " + "expected 83, is %d", + last_msg.msg.specan_dep.amplitude_value[124]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[125] == 201, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[125], " + "expected 201, is %d", + last_msg.msg.specan_dep.amplitude_value[125]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[126] == 20, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[126], " + "expected 20, is %d", + last_msg.msg.specan_dep.amplitude_value[126]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[127] == 101, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[127], " + "expected 101, is %d", + last_msg.msg.specan_dep.amplitude_value[127]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[128] == 9, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[128], " + "expected 9, is %d", + last_msg.msg.specan_dep.amplitude_value[128]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[129] == 140, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[129], " + "expected 140, is %d", + last_msg.msg.specan_dep.amplitude_value[129]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[130] == 186, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[130], " + "expected 186, is %d", + last_msg.msg.specan_dep.amplitude_value[130]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[131] == 162, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[131], " + "expected 162, is %d", + last_msg.msg.specan_dep.amplitude_value[131]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[132] == 81, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[132], " + "expected 81, is %d", + last_msg.msg.specan_dep.amplitude_value[132]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[133] == 91, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[133], " + "expected 91, is %d", + last_msg.msg.specan_dep.amplitude_value[133]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[134] == 30, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[134], " + "expected 30, is %d", + last_msg.msg.specan_dep.amplitude_value[134]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[135] == 231, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[135], " + "expected 231, is %d", + last_msg.msg.specan_dep.amplitude_value[135]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[136] == 161, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[136], " + "expected 161, is %d", + last_msg.msg.specan_dep.amplitude_value[136]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[137] == 81, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[137], " + "expected 81, is %d", + last_msg.msg.specan_dep.amplitude_value[137]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[138] == 216, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[138], " + "expected 216, is %d", + last_msg.msg.specan_dep.amplitude_value[138]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[139] == 114, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[139], " + "expected 114, is %d", + last_msg.msg.specan_dep.amplitude_value[139]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[140] == 60, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[140], " + "expected 60, is %d", + last_msg.msg.specan_dep.amplitude_value[140]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[141] == 231, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[141], " + "expected 231, is %d", + last_msg.msg.specan_dep.amplitude_value[141]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[142] == 163, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[142], " + "expected 163, is %d", + last_msg.msg.specan_dep.amplitude_value[142]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[143] == 163, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[143], " + "expected 163, is %d", + last_msg.msg.specan_dep.amplitude_value[143]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[144] == 49, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[144], " + "expected 49, is %d", + last_msg.msg.specan_dep.amplitude_value[144]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[145] == 237, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[145], " + "expected 237, is %d", + last_msg.msg.specan_dep.amplitude_value[145]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[146] == 244, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[146], " + "expected 244, is %d", + last_msg.msg.specan_dep.amplitude_value[146]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[147] == 185, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[147], " + "expected 185, is %d", + last_msg.msg.specan_dep.amplitude_value[147]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[148] == 240, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[148], " + "expected 240, is %d", + last_msg.msg.specan_dep.amplitude_value[148]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[149] == 89, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[149], " + "expected 89, is %d", + last_msg.msg.specan_dep.amplitude_value[149]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[150] == 143, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[150], " + "expected 143, is %d", + last_msg.msg.specan_dep.amplitude_value[150]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[151] == 174, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[151], " + "expected 174, is %d", + last_msg.msg.specan_dep.amplitude_value[151]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[152] == 165, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[152], " + "expected 165, is %d", + last_msg.msg.specan_dep.amplitude_value[152]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[153] == 211, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[153], " + "expected 211, is %d", + last_msg.msg.specan_dep.amplitude_value[153]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[154] == 241, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[154], " + "expected 241, is %d", + last_msg.msg.specan_dep.amplitude_value[154]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[155] == 13, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[155], " + "expected 13, is %d", + last_msg.msg.specan_dep.amplitude_value[155]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[156] == 16, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[156], " + "expected 16, is %d", + last_msg.msg.specan_dep.amplitude_value[156]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[157] == 61, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[157], " + "expected 61, is %d", + last_msg.msg.specan_dep.amplitude_value[157]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[158] == 141, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[158], " + "expected 141, is %d", + last_msg.msg.specan_dep.amplitude_value[158]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[159] == 101, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[159], " + "expected 101, is %d", + last_msg.msg.specan_dep.amplitude_value[159]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[160] == 89, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[160], " + "expected 89, is %d", + last_msg.msg.specan_dep.amplitude_value[160]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[161] == 37, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[161], " + "expected 37, is %d", + last_msg.msg.specan_dep.amplitude_value[161]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[162] == 117, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[162], " + "expected 117, is %d", + last_msg.msg.specan_dep.amplitude_value[162]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[163] == 189, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[163], " + "expected 189, is %d", + last_msg.msg.specan_dep.amplitude_value[163]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[164] == 86, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[164], " + "expected 86, is %d", + last_msg.msg.specan_dep.amplitude_value[164]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[165] == 118, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[165], " + "expected 118, is %d", + last_msg.msg.specan_dep.amplitude_value[165]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[166] == 176, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[166], " + "expected 176, is %d", + last_msg.msg.specan_dep.amplitude_value[166]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[167] == 228, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[167], " + "expected 228, is %d", + last_msg.msg.specan_dep.amplitude_value[167]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[168] == 12, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[168], " + "expected 12, is %d", + last_msg.msg.specan_dep.amplitude_value[168]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[169] == 14, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[169], " + "expected 14, is %d", + last_msg.msg.specan_dep.amplitude_value[169]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[170] == 119, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[170], " + "expected 119, is %d", + last_msg.msg.specan_dep.amplitude_value[170]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[171] == 135, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[171], " + "expected 135, is %d", + last_msg.msg.specan_dep.amplitude_value[171]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[172] == 129, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[172], " + "expected 129, is %d", + last_msg.msg.specan_dep.amplitude_value[172]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[173] == 243, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[173], " + "expected 243, is %d", + last_msg.msg.specan_dep.amplitude_value[173]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[174] == 50, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[174], " + "expected 50, is %d", + last_msg.msg.specan_dep.amplitude_value[174]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[175] == 29, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[175], " + "expected 29, is %d", + last_msg.msg.specan_dep.amplitude_value[175]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[176] == 207, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[176], " + "expected 207, is %d", + last_msg.msg.specan_dep.amplitude_value[176]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[177] == 198, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[177], " + "expected 198, is %d", + last_msg.msg.specan_dep.amplitude_value[177]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[178] == 117, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[178], " + "expected 117, is %d", + last_msg.msg.specan_dep.amplitude_value[178]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[179] == 100, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[179], " + "expected 100, is %d", + last_msg.msg.specan_dep.amplitude_value[179]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[180] == 225, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[180], " + "expected 225, is %d", + last_msg.msg.specan_dep.amplitude_value[180]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[181] == 6, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[181], " + "expected 6, is %d", + last_msg.msg.specan_dep.amplitude_value[181]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[182] == 139, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[182], " + "expected 139, is %d", + last_msg.msg.specan_dep.amplitude_value[182]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[183] == 110, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[183], " + "expected 110, is %d", + last_msg.msg.specan_dep.amplitude_value[183]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[184] == 39, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[184], " + "expected 39, is %d", + last_msg.msg.specan_dep.amplitude_value[184]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[185] == 210, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[185], " + "expected 210, is %d", + last_msg.msg.specan_dep.amplitude_value[185]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[186] == 68, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[186], " + "expected 68, is %d", + last_msg.msg.specan_dep.amplitude_value[186]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[187] == 199, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[187], " + "expected 199, is %d", + last_msg.msg.specan_dep.amplitude_value[187]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[188] == 43, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[188], " + "expected 43, is %d", + last_msg.msg.specan_dep.amplitude_value[188]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[189] == 132, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[189], " + "expected 132, is %d", + last_msg.msg.specan_dep.amplitude_value[189]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[190] == 64, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[190], " + "expected 64, is %d", + last_msg.msg.specan_dep.amplitude_value[190]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[191] == 17, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[191], " + "expected 17, is %d", + last_msg.msg.specan_dep.amplitude_value[191]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[192] == 51, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[192], " + "expected 51, is %d", + last_msg.msg.specan_dep.amplitude_value[192]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[193] == 173, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[193], " + "expected 173, is %d", + last_msg.msg.specan_dep.amplitude_value[193]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[194] == 181, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[194], " + "expected 181, is %d", + last_msg.msg.specan_dep.amplitude_value[194]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[195] == 12, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[195], " + "expected 12, is %d", + last_msg.msg.specan_dep.amplitude_value[195]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[196] == 140, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[196], " + "expected 140, is %d", + last_msg.msg.specan_dep.amplitude_value[196]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[197] == 16, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[197], " + "expected 16, is %d", + last_msg.msg.specan_dep.amplitude_value[197]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[198] == 247, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[198], " + "expected 247, is %d", + last_msg.msg.specan_dep.amplitude_value[198]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[199] == 84, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[199], " + "expected 84, is %d", + last_msg.msg.specan_dep.amplitude_value[199]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[200] == 183, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[200], " + "expected 183, is %d", + last_msg.msg.specan_dep.amplitude_value[200]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[201] == 105, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[201], " + "expected 105, is %d", + last_msg.msg.specan_dep.amplitude_value[201]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[202] == 39, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[202], " + "expected 39, is %d", + last_msg.msg.specan_dep.amplitude_value[202]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[203] == 157, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[203], " + "expected 157, is %d", + last_msg.msg.specan_dep.amplitude_value[203]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[204] == 77, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[204], " + "expected 77, is %d", + last_msg.msg.specan_dep.amplitude_value[204]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[205] == 30, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[205], " + "expected 30, is %d", + last_msg.msg.specan_dep.amplitude_value[205]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[206] == 205, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[206], " + "expected 205, is %d", + last_msg.msg.specan_dep.amplitude_value[206]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[207] == 194, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[207], " + "expected 194, is %d", + last_msg.msg.specan_dep.amplitude_value[207]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[208] == 59, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[208], " + "expected 59, is %d", + last_msg.msg.specan_dep.amplitude_value[208]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[209] == 64, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[209], " + "expected 64, is %d", + last_msg.msg.specan_dep.amplitude_value[209]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[210] == 241, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[210], " + "expected 241, is %d", + last_msg.msg.specan_dep.amplitude_value[210]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[211] == 183, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[211], " + "expected 183, is %d", + last_msg.msg.specan_dep.amplitude_value[211]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[212] == 238, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[212], " + "expected 238, is %d", + last_msg.msg.specan_dep.amplitude_value[212]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[213] == 105, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[213], " + "expected 105, is %d", + last_msg.msg.specan_dep.amplitude_value[213]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[214] == 181, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[214], " + "expected 181, is %d", + last_msg.msg.specan_dep.amplitude_value[214]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[215] == 170, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[215], " + "expected 170, is %d", + last_msg.msg.specan_dep.amplitude_value[215]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[216] == 45, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[216], " + "expected 45, is %d", + last_msg.msg.specan_dep.amplitude_value[216]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[217] == 8, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[217], " + "expected 8, is %d", + last_msg.msg.specan_dep.amplitude_value[217]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[218] == 166, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[218], " + "expected 166, is %d", + last_msg.msg.specan_dep.amplitude_value[218]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[219] == 164, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[219], " + "expected 164, is %d", + last_msg.msg.specan_dep.amplitude_value[219]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[220] == 238, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[220], " + "expected 238, is %d", + last_msg.msg.specan_dep.amplitude_value[220]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[221] == 83, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[221], " + "expected 83, is %d", + last_msg.msg.specan_dep.amplitude_value[221]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[222] == 148, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[222], " + "expected 148, is %d", + last_msg.msg.specan_dep.amplitude_value[222]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[223] == 173, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[223], " + "expected 173, is %d", + last_msg.msg.specan_dep.amplitude_value[223]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[224] == 108, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[224], " + "expected 108, is %d", + last_msg.msg.specan_dep.amplitude_value[224]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[225] == 228, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[225], " + "expected 228, is %d", + last_msg.msg.specan_dep.amplitude_value[225]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[226] == 67, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[226], " + "expected 67, is %d", + last_msg.msg.specan_dep.amplitude_value[226]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[227] == 89, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[227], " + "expected 89, is %d", + last_msg.msg.specan_dep.amplitude_value[227]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[228] == 189, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[228], " + "expected 189, is %d", + last_msg.msg.specan_dep.amplitude_value[228]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[229] == 67, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[229], " + "expected 67, is %d", + last_msg.msg.specan_dep.amplitude_value[229]); + ck_assert_msg( + last_msg.msg.specan_dep.amplitude_value[230] == 26, + "incorrect value for last_msg.msg.specan_dep.amplitude_value[230], " + "expected 26, is %d", + last_msg.msg.specan_dep.amplitude_value[230]); + + ck_assert_msg(last_msg.msg.specan_dep.channel_tag == 5878, + "incorrect value for last_msg.msg.specan_dep.channel_tag, " + "expected 5878, is %d", + last_msg.msg.specan_dep.channel_tag); + + ck_assert_msg( + (last_msg.msg.specan_dep.freq_ref * 100 - 6348.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.specan_dep.freq_ref, expected " + "6348.20019531, is %s", + last_msg.msg.specan_dep.freq_ref); + + ck_assert_msg( + (last_msg.msg.specan_dep.freq_step * 100 - 4608.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.specan_dep.freq_step, expected " + "4608.20019531, is %s", + last_msg.msg.specan_dep.freq_step); + + ck_assert_msg( + last_msg.msg.specan_dep.n_amplitude_value == 231, + "incorrect value for last_msg.msg.specan_dep.n_amplitude_value, " + "expected 231, is %d", + last_msg.msg.specan_dep.n_amplitude_value); + + ck_assert_msg(last_msg.msg.specan_dep.t.tow == 992295133, + "incorrect value for last_msg.msg.specan_dep.t.tow, expected " + "992295133, is %d", + last_msg.msg.specan_dep.t.tow); + + ck_assert_msg(last_msg.msg.specan_dep.t.wn == 6957, + "incorrect value for last_msg.msg.specan_dep.t.wn, expected " + "6957, is %d", + last_msg.msg.specan_dep.t.wn); + } +} +END_TEST + +Suite *auto_check_sbp_piksi_MsgSpecanDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_piksi_MsgSpecanDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_piksi_MsgSpecanDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_piksi_MsgSpecanDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_piksi_MsgUartState.c b/c/test/auto_check_sbp_piksi_MsgUartState.c index 3eef1a0438..a78a5211a0 100644 --- a/c/test/auto_check_sbp_piksi_MsgUartState.c +++ b/c/test/auto_check_sbp_piksi_MsgUartState.c @@ -90,6 +90,269 @@ START_TEST(test_auto_check_sbp_piksi_MsgUartState) { logging_reset(); + sbp_callback_register(&sbp_state, 0x1d, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, + 89, 98, 79, 184, 138, 244, 154, 73, 201, 69, 154, 65, 211, 69, + 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, 51, 211, 7, 69, + 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, + 10, 113, 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, + 107, 111, 253, 168, 244, 158, 112, 19, 251, 131, 100, 225, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.uart_state.latency.avg = 319865629; + + test_msg.uart_state.latency.current = 364253831; + + test_msg.uart_state.latency.lmax = -611749622; + + test_msg.uart_state.latency.lmin = 289902239; + + test_msg.uart_state.obs_period.avg = -1002717658; + + test_msg.uart_state.obs_period.current = -2080697488; + + test_msg.uart_state.obs_period.pmax = -1628133123; + + test_msg.uart_state.obs_period.pmin = 1869323177; + + test_msg.uart_state.uart_a.crc_error_count = 25177; + + test_msg.uart_state.uart_a.io_error_count = 47183; + + test_msg.uart_state.uart_a.rx_buffer_level = 244; + + test_msg.uart_state.uart_a.rx_throughput = 1853.199951171875; + + test_msg.uart_state.uart_a.tx_buffer_level = 138; + + test_msg.uart_state.uart_a.tx_throughput = 7765.2001953125; + + test_msg.uart_state.uart_b.crc_error_count = 4297; + + test_msg.uart_state.uart_b.io_error_count = 63847; + + test_msg.uart_state.uart_b.rx_buffer_level = 161; + + test_msg.uart_state.uart_b.rx_throughput = 6760.2001953125; + + test_msg.uart_state.uart_b.tx_buffer_level = 143; + + test_msg.uart_state.uart_b.tx_throughput = 6441.2001953125; + + test_msg.uart_state.uart_ftdi.crc_error_count = 38359; + + test_msg.uart_state.uart_ftdi.io_error_count = 6653; + + test_msg.uart_state.uart_ftdi.rx_buffer_level = 24; + + test_msg.uart_state.uart_ftdi.rx_throughput = 2173.199951171875; + + test_msg.uart_state.uart_ftdi.tx_buffer_level = 218; + + test_msg.uart_state.uart_ftdi.tx_throughput = 5954.2001953125; + + sbp_message_send(&sbp_state, SbpMsgUartState, 57544, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 57544, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgUartState, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.uart_state.latency.avg == 319865629, + "incorrect value for last_msg.msg.uart_state.latency.avg, " + "expected 319865629, is %d", + last_msg.msg.uart_state.latency.avg); + + ck_assert_msg( + last_msg.msg.uart_state.latency.current == 364253831, + "incorrect value for last_msg.msg.uart_state.latency.current, expected " + "364253831, is %d", + last_msg.msg.uart_state.latency.current); + + ck_assert_msg(last_msg.msg.uart_state.latency.lmax == -611749622, + "incorrect value for last_msg.msg.uart_state.latency.lmax, " + "expected -611749622, is %d", + last_msg.msg.uart_state.latency.lmax); + + ck_assert_msg(last_msg.msg.uart_state.latency.lmin == 289902239, + "incorrect value for last_msg.msg.uart_state.latency.lmin, " + "expected 289902239, is %d", + last_msg.msg.uart_state.latency.lmin); + + ck_assert_msg(last_msg.msg.uart_state.obs_period.avg == -1002717658, + "incorrect value for last_msg.msg.uart_state.obs_period.avg, " + "expected -1002717658, is %d", + last_msg.msg.uart_state.obs_period.avg); + + ck_assert_msg( + last_msg.msg.uart_state.obs_period.current == -2080697488, + "incorrect value for last_msg.msg.uart_state.obs_period.current, " + "expected -2080697488, is %d", + last_msg.msg.uart_state.obs_period.current); + + ck_assert_msg( + last_msg.msg.uart_state.obs_period.pmax == -1628133123, + "incorrect value for last_msg.msg.uart_state.obs_period.pmax, expected " + "-1628133123, is %d", + last_msg.msg.uart_state.obs_period.pmax); + + ck_assert_msg( + last_msg.msg.uart_state.obs_period.pmin == 1869323177, + "incorrect value for last_msg.msg.uart_state.obs_period.pmin, expected " + "1869323177, is %d", + last_msg.msg.uart_state.obs_period.pmin); + + ck_assert_msg( + last_msg.msg.uart_state.uart_a.crc_error_count == 25177, + "incorrect value for last_msg.msg.uart_state.uart_a.crc_error_count, " + "expected 25177, is %d", + last_msg.msg.uart_state.uart_a.crc_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_a.io_error_count == 47183, + "incorrect value for last_msg.msg.uart_state.uart_a.io_error_count, " + "expected 47183, is %d", + last_msg.msg.uart_state.uart_a.io_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_a.rx_buffer_level == 244, + "incorrect value for last_msg.msg.uart_state.uart_a.rx_buffer_level, " + "expected 244, is %d", + last_msg.msg.uart_state.uart_a.rx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_a.rx_throughput * 100 - + 1853.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_a.rx_throughput, " + "expected 1853.19995117, is %s", + last_msg.msg.uart_state.uart_a.rx_throughput); + + ck_assert_msg( + last_msg.msg.uart_state.uart_a.tx_buffer_level == 138, + "incorrect value for last_msg.msg.uart_state.uart_a.tx_buffer_level, " + "expected 138, is %d", + last_msg.msg.uart_state.uart_a.tx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_a.tx_throughput * 100 - + 7765.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_a.tx_throughput, " + "expected 7765.20019531, is %s", + last_msg.msg.uart_state.uart_a.tx_throughput); + + ck_assert_msg( + last_msg.msg.uart_state.uart_b.crc_error_count == 4297, + "incorrect value for last_msg.msg.uart_state.uart_b.crc_error_count, " + "expected 4297, is %d", + last_msg.msg.uart_state.uart_b.crc_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_b.io_error_count == 63847, + "incorrect value for last_msg.msg.uart_state.uart_b.io_error_count, " + "expected 63847, is %d", + last_msg.msg.uart_state.uart_b.io_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_b.rx_buffer_level == 161, + "incorrect value for last_msg.msg.uart_state.uart_b.rx_buffer_level, " + "expected 161, is %d", + last_msg.msg.uart_state.uart_b.rx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_b.rx_throughput * 100 - + 6760.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_b.rx_throughput, " + "expected 6760.20019531, is %s", + last_msg.msg.uart_state.uart_b.rx_throughput); + + ck_assert_msg( + last_msg.msg.uart_state.uart_b.tx_buffer_level == 143, + "incorrect value for last_msg.msg.uart_state.uart_b.tx_buffer_level, " + "expected 143, is %d", + last_msg.msg.uart_state.uart_b.tx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_b.tx_throughput * 100 - + 6441.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_b.tx_throughput, " + "expected 6441.20019531, is %s", + last_msg.msg.uart_state.uart_b.tx_throughput); + + ck_assert_msg(last_msg.msg.uart_state.uart_ftdi.crc_error_count == 38359, + "incorrect value for " + "last_msg.msg.uart_state.uart_ftdi.crc_error_count, expected " + "38359, is %d", + last_msg.msg.uart_state.uart_ftdi.crc_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_ftdi.io_error_count == 6653, + "incorrect value for last_msg.msg.uart_state.uart_ftdi.io_error_count, " + "expected 6653, is %d", + last_msg.msg.uart_state.uart_ftdi.io_error_count); + + ck_assert_msg( + last_msg.msg.uart_state.uart_ftdi.rx_buffer_level == 24, + "incorrect value for " + "last_msg.msg.uart_state.uart_ftdi.rx_buffer_level, expected 24, is %d", + last_msg.msg.uart_state.uart_ftdi.rx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_ftdi.rx_throughput * 100 - + 2173.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_ftdi.rx_throughput, " + "expected 2173.19995117, is %s", + last_msg.msg.uart_state.uart_ftdi.rx_throughput); + + ck_assert_msg(last_msg.msg.uart_state.uart_ftdi.tx_buffer_level == 218, + "incorrect value for " + "last_msg.msg.uart_state.uart_ftdi.tx_buffer_level, expected " + "218, is %d", + last_msg.msg.uart_state.uart_ftdi.tx_buffer_level); + + ck_assert_msg( + (last_msg.msg.uart_state.uart_ftdi.tx_throughput * 100 - + 5954.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.uart_state.uart_ftdi.tx_throughput, " + "expected 5954.20019531, is %s", + last_msg.msg.uart_state.uart_ftdi.tx_throughput); + } + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + sbp_callback_register(&sbp_state, 0x18, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); diff --git a/c/test/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c b/c/test/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c new file mode 100644 index 0000000000..22b803a688 --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsReadByIndexReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 162, 0, 122, 123, 2, 244, 34, 235, 23, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.settings_read_by_index_req.index = 8948; + + sbp_message_send(&sbp_state, SbpMsgSettingsReadByIndexReq, 31610, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 31610, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSettingsReadByIndexReq, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.settings_read_by_index_req.index == 8948, + "incorrect value for last_msg.msg.settings_read_by_index_req.index, " + "expected 8948, is %d", + last_msg.msg.settings_read_by_index_req.index); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_settings_MsgSettingsReadByIndexReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsReadByIndexReq"); + tcase_add_test(tc_acq, + test_auto_check_sbp_settings_MsgSettingsReadByIndexReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsReadReq.c b/c/test/auto_check_sbp_settings_MsgSettingsReadReq.c new file mode 100644 index 0000000000..55176e666b --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsReadReq.c @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsReadReq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa4, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_read_req_setting_add_section( + &test_msg.settings_read_req, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_read_req_setting_add_section( + &test_msg.settings_read_req, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_settings_read_req_setting_encoded_len( + &test_msg.settings_read_req) == 26, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgSettingsReadReq, 54936, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54936, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsReadReq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_read_req_setting_encoded_len( + &last_msg.msg.settings_read_req) == 26, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_read_req_setting_get_section( + &last_msg.msg.settings_read_req, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_read_req_setting_get_section( + &last_msg.msg.settings_read_req, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsReadReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsReadReq"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsReadResp.c b/c/test/auto_check_sbp_settings_MsgSettingsReadResp.c new file mode 100644 index 0000000000..a5f24dbbd9 --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsReadResp.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsReadResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, + 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, + 118, 97, 108, 117, 101, 51, 0, 203, 199, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_read_resp_setting_add_section( + &test_msg.settings_read_resp, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_read_resp_setting_add_section( + &test_msg.settings_read_resp, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_settings_read_resp_setting_add_section( + &test_msg.settings_read_resp, "setting-value") == true, + "Can't assign section 2"); + ck_assert_msg( + sbp_msg_settings_read_resp_setting_add_section( + &test_msg.settings_read_resp, "enum;value1,value2,value3") == true, + "Can't assign section 3"); + ck_assert_msg(sbp_msg_settings_read_resp_setting_encoded_len( + &test_msg.settings_read_resp) == 66, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgSettingsReadResp, 61576, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61576, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsReadResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_read_resp_setting_encoded_len( + &last_msg.msg.settings_read_resp) == 66, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_read_resp_setting_get_section( + &last_msg.msg.settings_read_resp, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_read_resp_setting_get_section( + &last_msg.msg.settings_read_resp, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_read_resp_setting_get_section( + &last_msg.msg.settings_read_resp, 2), + "setting-value") == 0, + "Section 2 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_read_resp_setting_get_section( + &last_msg.msg.settings_read_resp, 3), + "enum;value1,value2,value3") == 0, + "Section 3 not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsReadResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsReadResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsRegister.c b/c/test/auto_check_sbp_settings_MsgSettingsRegister.c new file mode 100644 index 0000000000..c3ca49c41b --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsRegister.c @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsRegister) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xae, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, + 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, + 118, 97, 108, 117, 101, 51, 0, 142, 235, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_register_setting_add_section( + &test_msg.settings_register, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_register_setting_add_section( + &test_msg.settings_register, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_settings_register_setting_add_section( + &test_msg.settings_register, "setting-value") == true, + "Can't assign section 2"); + ck_assert_msg( + sbp_msg_settings_register_setting_add_section( + &test_msg.settings_register, "enum;value1,value2,value3") == true, + "Can't assign section 3"); + ck_assert_msg(sbp_msg_settings_register_setting_encoded_len( + &test_msg.settings_register) == 66, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgSettingsRegister, 1620, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1620, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsRegister, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_register_setting_encoded_len( + &last_msg.msg.settings_register) == 66, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_register_setting_get_section( + &last_msg.msg.settings_register, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_setting_get_section( + &last_msg.msg.settings_register, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_setting_get_section( + &last_msg.msg.settings_register, 2), + "setting-value") == 0, + "Section 2 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_setting_get_section( + &last_msg.msg.settings_register, 3), + "enum;value1,value2,value3") == 0, + "Section 3 not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsRegister_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsRegister"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsRegister"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsRegister); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsRegisterResp.c b/c/test/auto_check_sbp_settings_MsgSettingsRegisterResp.c new file mode 100644 index 0000000000..fea665035a --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsRegisterResp.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsRegisterResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1af, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, + 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, + 44, 118, 97, 108, 117, 101, 51, 0, 82, 16, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_register_resp_setting_add_section( + &test_msg.settings_register_resp, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_register_resp_setting_add_section( + &test_msg.settings_register_resp, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg( + sbp_msg_settings_register_resp_setting_add_section( + &test_msg.settings_register_resp, "setting-value") == true, + "Can't assign section 2"); + ck_assert_msg(sbp_msg_settings_register_resp_setting_add_section( + &test_msg.settings_register_resp, + "enum;value1,value2,value3") == true, + "Can't assign section 3"); + ck_assert_msg(sbp_msg_settings_register_resp_setting_encoded_len( + &test_msg.settings_register_resp) == 66, + "String not encoded properly"); + + test_msg.settings_register_resp.status = 18; + + sbp_message_send(&sbp_state, SbpMsgSettingsRegisterResp, 54569, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54569, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSettingsRegisterResp, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_register_resp_setting_encoded_len( + &last_msg.msg.settings_register_resp) == 66, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_register_resp_setting_get_section( + &last_msg.msg.settings_register_resp, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_resp_setting_get_section( + &last_msg.msg.settings_register_resp, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_resp_setting_get_section( + &last_msg.msg.settings_register_resp, 2), + "setting-value") == 0, + "Section 2 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_register_resp_setting_get_section( + &last_msg.msg.settings_register_resp, 3), + "enum;value1,value2,value3") == 0, + "Section 3 not decoded properly"); + + ck_assert_msg( + last_msg.msg.settings_register_resp.status == 18, + "incorrect value for last_msg.msg.settings_register_resp.status, " + "expected 18, is %d", + last_msg.msg.settings_register_resp.status); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsRegisterResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_settings_MsgSettingsRegisterResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsRegisterResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsRegisterResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsSave.c b/c/test/auto_check_sbp_settings_MsgSettingsSave.c new file mode 100644 index 0000000000..342a0ce19f --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsSave.c @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsSave) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 161, 0, 162, 224, 0, 123, 67, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + sbp_message_send(&sbp_state, SbpMsgSettingsSave, 57506, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 57506, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsSave, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsSave_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsSave"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_settings_MsgSettingsSave"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsSave); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsWrite.c b/c/test/auto_check_sbp_settings_MsgSettingsWrite.c new file mode 100644 index 0000000000..7f2dc4988f --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsWrite.c @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsWrite) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xa0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_write_setting_add_section( + &test_msg.settings_write, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_write_setting_add_section( + &test_msg.settings_write, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_settings_write_setting_add_section( + &test_msg.settings_write, "setting-value") == true, + "Can't assign section 2"); + ck_assert_msg(sbp_msg_settings_write_setting_encoded_len( + &test_msg.settings_write) == 40, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgSettingsWrite, 123, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsWrite, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_write_setting_encoded_len( + &last_msg.msg.settings_write) == 40, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_write_setting_get_section( + &last_msg.msg.settings_write, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_write_setting_get_section( + &last_msg.msg.settings_write, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_write_setting_get_section( + &last_msg.msg.settings_write, 2), + "setting-value") == 0, + "Section 2 not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsWrite_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsWrite"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_settings_MsgSettingsWrite"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsWrite); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_settings_MsgSettingsWriteResp.c b/c/test/auto_check_sbp_settings_MsgSettingsWriteResp.c new file mode 100644 index 0000000000..1bec9590bb --- /dev/null +++ b/c/test/auto_check_sbp_settings_MsgSettingsWriteResp.c @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_settings_MsgSettingsWriteResp) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xaf, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, + 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, + 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + ck_assert_msg(sbp_msg_settings_write_resp_setting_add_section( + &test_msg.settings_write_resp, "section-name") == true, + "Can't assign section 0"); + ck_assert_msg(sbp_msg_settings_write_resp_setting_add_section( + &test_msg.settings_write_resp, "setting-name") == true, + "Can't assign section 1"); + ck_assert_msg(sbp_msg_settings_write_resp_setting_add_section( + &test_msg.settings_write_resp, "setting-value") == true, + "Can't assign section 2"); + ck_assert_msg( + sbp_msg_settings_write_resp_setting_add_section( + &test_msg.settings_write_resp, "enum;value1,value2,value3") == true, + "Can't assign section 3"); + ck_assert_msg(sbp_msg_settings_write_resp_setting_encoded_len( + &test_msg.settings_write_resp) == 66, + "String not encoded properly"); + + test_msg.settings_write_resp.status = 152; + + sbp_message_send(&sbp_state, SbpMsgSettingsWriteResp, 14171, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14171, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSettingsWriteResp, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(sbp_msg_settings_write_resp_setting_encoded_len( + &last_msg.msg.settings_write_resp) == 66, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_settings_write_resp_setting_get_section( + &last_msg.msg.settings_write_resp, 0), + "section-name") == 0, + "Section 0 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_write_resp_setting_get_section( + &last_msg.msg.settings_write_resp, 1), + "setting-name") == 0, + "Section 1 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_write_resp_setting_get_section( + &last_msg.msg.settings_write_resp, 2), + "setting-value") == 0, + "Section 2 not decoded properly"); + ck_assert_msg(strcmp(sbp_msg_settings_write_resp_setting_get_section( + &last_msg.msg.settings_write_resp, 3), + "enum;value1,value2,value3") == 0, + "Section 3 not decoded properly"); + + ck_assert_msg( + last_msg.msg.settings_write_resp.status == 152, + "incorrect value for last_msg.msg.settings_write_resp.status, expected " + "152, is %d", + last_msg.msg.settings_write_resp.status); + } +} +END_TEST + +Suite *auto_check_sbp_settings_MsgSettingsWriteResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_settings_MsgSettingsWriteResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_settings_MsgSettingsWriteResp"); + tcase_add_test(tc_acq, test_auto_check_sbp_settings_MsgSettingsWriteResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_solution_meta_MsgSolnMeta.c b/c/test/auto_check_sbp_solution_meta_MsgSolnMeta.c new file mode 100644 index 0000000000..69dfbf71e2 --- /dev/null +++ b/c/test/auto_check_sbp_solution_meta_MsgSolnMeta.c @@ -0,0 +1,2068 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_solution_meta_MsgSolnMeta) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff0e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, + 144, 228, 8, 83, 89, 87, 3, 213, 95, 109, 86, 131, 71, 70, + 84, 73, 131, 26, 82, 247, 140, 97, 115, 110, 118, 253, 2, 122, + 186, 148, 122, 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, + 208, 89, 56, 10, 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, + 238, 123, 102, 230, 76, 190, 225, 182, 207, 228, 7, 218, 117, 89, + 29, 191, 56, 248, 185, 255, 46, 18, 72, 142, 82, 113, 26, 4, + 172, 254, 178, 136, 113, 115, 58, 193, 89, 227, 182, 246, 76, 77, + 108, 245, 41, 31, 70, 124, 249, 145, 15, 78, 228, 38, 241, 129, + 8, 176, 251, 72, 248, 80, 115, 244, 231, 145, 191, 190, 178, 168, + 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, 92, 79, 101, 223, + 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, 36, 219, 56, + 146, 90, 219, 104, 227, 102, 83, 12, 41, 122, 173, 94, 1, 174, + 134, 130, 104, 237, 116, 249, 107, 230, 130, 123, 25, 162, 57, 223, + 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, 100, 66, 72, + 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, + 141, 25, 183, 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, + 180, 46, 140, 130, 36, 17, 194, 209, 65, 254, 115, 103, 152, 129, + 234, 235, 194, 234, 170, 201, 210, 154, 150, 247, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.soln_meta.age_corrections = 21256; + + test_msg.soln_meta.age_gnss = 3573765977; + + test_msg.soln_meta.hdop = 41156; + + test_msg.soln_meta.n_sol_in = 119; + + test_msg.soln_meta.pdop = 11642; + + test_msg.soln_meta.sol_in[0].flags = 109; + + test_msg.soln_meta.sol_in[0].sensor_type = 95; + + test_msg.soln_meta.sol_in[1].flags = 131; + + test_msg.soln_meta.sol_in[1].sensor_type = 86; + + test_msg.soln_meta.sol_in[2].flags = 70; + + test_msg.soln_meta.sol_in[2].sensor_type = 71; + + test_msg.soln_meta.sol_in[3].flags = 73; + + test_msg.soln_meta.sol_in[3].sensor_type = 84; + + test_msg.soln_meta.sol_in[4].flags = 26; + + test_msg.soln_meta.sol_in[4].sensor_type = 131; + + test_msg.soln_meta.sol_in[5].flags = 247; + + test_msg.soln_meta.sol_in[5].sensor_type = 82; + + test_msg.soln_meta.sol_in[6].flags = 97; + + test_msg.soln_meta.sol_in[6].sensor_type = 140; + + test_msg.soln_meta.sol_in[7].flags = 110; + + test_msg.soln_meta.sol_in[7].sensor_type = 115; + + test_msg.soln_meta.sol_in[8].flags = 253; + + test_msg.soln_meta.sol_in[8].sensor_type = 118; + + test_msg.soln_meta.sol_in[9].flags = 122; + + test_msg.soln_meta.sol_in[9].sensor_type = 2; + + test_msg.soln_meta.sol_in[10].flags = 148; + + test_msg.soln_meta.sol_in[10].sensor_type = 186; + + test_msg.soln_meta.sol_in[11].flags = 148; + + test_msg.soln_meta.sol_in[11].sensor_type = 122; + + test_msg.soln_meta.sol_in[12].flags = 231; + + test_msg.soln_meta.sol_in[12].sensor_type = 180; + + test_msg.soln_meta.sol_in[13].flags = 46; + + test_msg.soln_meta.sol_in[13].sensor_type = 68; + + test_msg.soln_meta.sol_in[14].flags = 102; + + test_msg.soln_meta.sol_in[14].sensor_type = 190; + + test_msg.soln_meta.sol_in[15].flags = 48; + + test_msg.soln_meta.sol_in[15].sensor_type = 243; + + test_msg.soln_meta.sol_in[16].flags = 15; + + test_msg.soln_meta.sol_in[16].sensor_type = 192; + + test_msg.soln_meta.sol_in[17].flags = 89; + + test_msg.soln_meta.sol_in[17].sensor_type = 208; + + test_msg.soln_meta.sol_in[18].flags = 10; + + test_msg.soln_meta.sol_in[18].sensor_type = 56; + + test_msg.soln_meta.sol_in[19].flags = 2; + + test_msg.soln_meta.sol_in[19].sensor_type = 245; + + test_msg.soln_meta.sol_in[20].flags = 201; + + test_msg.soln_meta.sol_in[20].sensor_type = 254; + + test_msg.soln_meta.sol_in[21].flags = 32; + + test_msg.soln_meta.sol_in[21].sensor_type = 120; + + test_msg.soln_meta.sol_in[22].flags = 2; + + test_msg.soln_meta.sol_in[22].sensor_type = 126; + + test_msg.soln_meta.sol_in[23].flags = 161; + + test_msg.soln_meta.sol_in[23].sensor_type = 83; + + test_msg.soln_meta.sol_in[24].flags = 123; + + test_msg.soln_meta.sol_in[24].sensor_type = 238; + + test_msg.soln_meta.sol_in[25].flags = 230; + + test_msg.soln_meta.sol_in[25].sensor_type = 102; + + test_msg.soln_meta.sol_in[26].flags = 190; + + test_msg.soln_meta.sol_in[26].sensor_type = 76; + + test_msg.soln_meta.sol_in[27].flags = 182; + + test_msg.soln_meta.sol_in[27].sensor_type = 225; + + test_msg.soln_meta.sol_in[28].flags = 228; + + test_msg.soln_meta.sol_in[28].sensor_type = 207; + + test_msg.soln_meta.sol_in[29].flags = 218; + + test_msg.soln_meta.sol_in[29].sensor_type = 7; + + test_msg.soln_meta.sol_in[30].flags = 89; + + test_msg.soln_meta.sol_in[30].sensor_type = 117; + + test_msg.soln_meta.sol_in[31].flags = 191; + + test_msg.soln_meta.sol_in[31].sensor_type = 29; + + test_msg.soln_meta.sol_in[32].flags = 248; + + test_msg.soln_meta.sol_in[32].sensor_type = 56; + + test_msg.soln_meta.sol_in[33].flags = 255; + + test_msg.soln_meta.sol_in[33].sensor_type = 185; + + test_msg.soln_meta.sol_in[34].flags = 18; + + test_msg.soln_meta.sol_in[34].sensor_type = 46; + + test_msg.soln_meta.sol_in[35].flags = 142; + + test_msg.soln_meta.sol_in[35].sensor_type = 72; + + test_msg.soln_meta.sol_in[36].flags = 113; + + test_msg.soln_meta.sol_in[36].sensor_type = 82; + + test_msg.soln_meta.sol_in[37].flags = 4; + + test_msg.soln_meta.sol_in[37].sensor_type = 26; + + test_msg.soln_meta.sol_in[38].flags = 254; + + test_msg.soln_meta.sol_in[38].sensor_type = 172; + + test_msg.soln_meta.sol_in[39].flags = 136; + + test_msg.soln_meta.sol_in[39].sensor_type = 178; + + test_msg.soln_meta.sol_in[40].flags = 115; + + test_msg.soln_meta.sol_in[40].sensor_type = 113; + + test_msg.soln_meta.sol_in[41].flags = 193; + + test_msg.soln_meta.sol_in[41].sensor_type = 58; + + test_msg.soln_meta.sol_in[42].flags = 227; + + test_msg.soln_meta.sol_in[42].sensor_type = 89; + + test_msg.soln_meta.sol_in[43].flags = 246; + + test_msg.soln_meta.sol_in[43].sensor_type = 182; + + test_msg.soln_meta.sol_in[44].flags = 77; + + test_msg.soln_meta.sol_in[44].sensor_type = 76; + + test_msg.soln_meta.sol_in[45].flags = 245; + + test_msg.soln_meta.sol_in[45].sensor_type = 108; + + test_msg.soln_meta.sol_in[46].flags = 31; + + test_msg.soln_meta.sol_in[46].sensor_type = 41; + + test_msg.soln_meta.sol_in[47].flags = 124; + + test_msg.soln_meta.sol_in[47].sensor_type = 70; + + test_msg.soln_meta.sol_in[48].flags = 145; + + test_msg.soln_meta.sol_in[48].sensor_type = 249; + + test_msg.soln_meta.sol_in[49].flags = 78; + + test_msg.soln_meta.sol_in[49].sensor_type = 15; + + test_msg.soln_meta.sol_in[50].flags = 38; + + test_msg.soln_meta.sol_in[50].sensor_type = 228; + + test_msg.soln_meta.sol_in[51].flags = 129; + + test_msg.soln_meta.sol_in[51].sensor_type = 241; + + test_msg.soln_meta.sol_in[52].flags = 176; + + test_msg.soln_meta.sol_in[52].sensor_type = 8; + + test_msg.soln_meta.sol_in[53].flags = 72; + + test_msg.soln_meta.sol_in[53].sensor_type = 251; + + test_msg.soln_meta.sol_in[54].flags = 80; + + test_msg.soln_meta.sol_in[54].sensor_type = 248; + + test_msg.soln_meta.sol_in[55].flags = 244; + + test_msg.soln_meta.sol_in[55].sensor_type = 115; + + test_msg.soln_meta.sol_in[56].flags = 145; + + test_msg.soln_meta.sol_in[56].sensor_type = 231; + + test_msg.soln_meta.sol_in[57].flags = 190; + + test_msg.soln_meta.sol_in[57].sensor_type = 191; + + test_msg.soln_meta.sol_in[58].flags = 168; + + test_msg.soln_meta.sol_in[58].sensor_type = 178; + + test_msg.soln_meta.sol_in[59].flags = 233; + + test_msg.soln_meta.sol_in[59].sensor_type = 89; + + test_msg.soln_meta.sol_in[60].flags = 176; + + test_msg.soln_meta.sol_in[60].sensor_type = 69; + + test_msg.soln_meta.sol_in[61].flags = 140; + + test_msg.soln_meta.sol_in[61].sensor_type = 174; + + test_msg.soln_meta.sol_in[62].flags = 141; + + test_msg.soln_meta.sol_in[62].sensor_type = 182; + + test_msg.soln_meta.sol_in[63].flags = 82; + + test_msg.soln_meta.sol_in[63].sensor_type = 81; + + test_msg.soln_meta.sol_in[64].flags = 79; + + test_msg.soln_meta.sol_in[64].sensor_type = 92; + + test_msg.soln_meta.sol_in[65].flags = 223; + + test_msg.soln_meta.sol_in[65].sensor_type = 101; + + test_msg.soln_meta.sol_in[66].flags = 64; + + test_msg.soln_meta.sol_in[66].sensor_type = 100; + + test_msg.soln_meta.sol_in[67].flags = 215; + + test_msg.soln_meta.sol_in[67].sensor_type = 184; + + test_msg.soln_meta.sol_in[68].flags = 37; + + test_msg.soln_meta.sol_in[68].sensor_type = 124; + + test_msg.soln_meta.sol_in[69].flags = 227; + + test_msg.soln_meta.sol_in[69].sensor_type = 21; + + test_msg.soln_meta.sol_in[70].flags = 102; + + test_msg.soln_meta.sol_in[70].sensor_type = 135; + + test_msg.soln_meta.sol_in[71].flags = 36; + + test_msg.soln_meta.sol_in[71].sensor_type = 72; + + test_msg.soln_meta.sol_in[72].flags = 56; + + test_msg.soln_meta.sol_in[72].sensor_type = 219; + + test_msg.soln_meta.sol_in[73].flags = 90; + + test_msg.soln_meta.sol_in[73].sensor_type = 146; + + test_msg.soln_meta.sol_in[74].flags = 104; + + test_msg.soln_meta.sol_in[74].sensor_type = 219; + + test_msg.soln_meta.sol_in[75].flags = 102; + + test_msg.soln_meta.sol_in[75].sensor_type = 227; + + test_msg.soln_meta.sol_in[76].flags = 12; + + test_msg.soln_meta.sol_in[76].sensor_type = 83; + + test_msg.soln_meta.sol_in[77].flags = 122; + + test_msg.soln_meta.sol_in[77].sensor_type = 41; + + test_msg.soln_meta.sol_in[78].flags = 94; + + test_msg.soln_meta.sol_in[78].sensor_type = 173; + + test_msg.soln_meta.sol_in[79].flags = 174; + + test_msg.soln_meta.sol_in[79].sensor_type = 1; + + test_msg.soln_meta.sol_in[80].flags = 130; + + test_msg.soln_meta.sol_in[80].sensor_type = 134; + + test_msg.soln_meta.sol_in[81].flags = 237; + + test_msg.soln_meta.sol_in[81].sensor_type = 104; + + test_msg.soln_meta.sol_in[82].flags = 249; + + test_msg.soln_meta.sol_in[82].sensor_type = 116; + + test_msg.soln_meta.sol_in[83].flags = 230; + + test_msg.soln_meta.sol_in[83].sensor_type = 107; + + test_msg.soln_meta.sol_in[84].flags = 123; + + test_msg.soln_meta.sol_in[84].sensor_type = 130; + + test_msg.soln_meta.sol_in[85].flags = 162; + + test_msg.soln_meta.sol_in[85].sensor_type = 25; + + test_msg.soln_meta.sol_in[86].flags = 223; + + test_msg.soln_meta.sol_in[86].sensor_type = 57; + + test_msg.soln_meta.sol_in[87].flags = 174; + + test_msg.soln_meta.sol_in[87].sensor_type = 193; + + test_msg.soln_meta.sol_in[88].flags = 193; + + test_msg.soln_meta.sol_in[88].sensor_type = 146; + + test_msg.soln_meta.sol_in[89].flags = 44; + + test_msg.soln_meta.sol_in[89].sensor_type = 239; + + test_msg.soln_meta.sol_in[90].flags = 197; + + test_msg.soln_meta.sol_in[90].sensor_type = 246; + + test_msg.soln_meta.sol_in[91].flags = 80; + + test_msg.soln_meta.sol_in[91].sensor_type = 214; + + test_msg.soln_meta.sol_in[92].flags = 100; + + test_msg.soln_meta.sol_in[92].sensor_type = 83; + + test_msg.soln_meta.sol_in[93].flags = 72; + + test_msg.soln_meta.sol_in[93].sensor_type = 66; + + test_msg.soln_meta.sol_in[94].flags = 137; + + test_msg.soln_meta.sol_in[94].sensor_type = 133; + + test_msg.soln_meta.sol_in[95].flags = 82; + + test_msg.soln_meta.sol_in[95].sensor_type = 140; + + test_msg.soln_meta.sol_in[96].flags = 2; + + test_msg.soln_meta.sol_in[96].sensor_type = 2; + + test_msg.soln_meta.sol_in[97].flags = 9; + + test_msg.soln_meta.sol_in[97].sensor_type = 96; + + test_msg.soln_meta.sol_in[98].flags = 158; + + test_msg.soln_meta.sol_in[98].sensor_type = 96; + + test_msg.soln_meta.sol_in[99].flags = 97; + + test_msg.soln_meta.sol_in[99].sensor_type = 134; + + test_msg.soln_meta.sol_in[100].flags = 129; + + test_msg.soln_meta.sol_in[100].sensor_type = 43; + + test_msg.soln_meta.sol_in[101].flags = 25; + + test_msg.soln_meta.sol_in[101].sensor_type = 141; + + test_msg.soln_meta.sol_in[102].flags = 200; + + test_msg.soln_meta.sol_in[102].sensor_type = 183; + + test_msg.soln_meta.sol_in[103].flags = 57; + + test_msg.soln_meta.sol_in[103].sensor_type = 214; + + test_msg.soln_meta.sol_in[104].flags = 103; + + test_msg.soln_meta.sol_in[104].sensor_type = 248; + + test_msg.soln_meta.sol_in[105].flags = 65; + + test_msg.soln_meta.sol_in[105].sensor_type = 222; + + test_msg.soln_meta.sol_in[106].flags = 15; + + test_msg.soln_meta.sol_in[106].sensor_type = 195; + + test_msg.soln_meta.sol_in[107].flags = 21; + + test_msg.soln_meta.sol_in[107].sensor_type = 244; + + test_msg.soln_meta.sol_in[108].flags = 46; + + test_msg.soln_meta.sol_in[108].sensor_type = 180; + + test_msg.soln_meta.sol_in[109].flags = 130; + + test_msg.soln_meta.sol_in[109].sensor_type = 140; + + test_msg.soln_meta.sol_in[110].flags = 17; + + test_msg.soln_meta.sol_in[110].sensor_type = 36; + + test_msg.soln_meta.sol_in[111].flags = 209; + + test_msg.soln_meta.sol_in[111].sensor_type = 194; + + test_msg.soln_meta.sol_in[112].flags = 254; + + test_msg.soln_meta.sol_in[112].sensor_type = 65; + + test_msg.soln_meta.sol_in[113].flags = 103; + + test_msg.soln_meta.sol_in[113].sensor_type = 115; + + test_msg.soln_meta.sol_in[114].flags = 129; + + test_msg.soln_meta.sol_in[114].sensor_type = 152; + + test_msg.soln_meta.sol_in[115].flags = 235; + + test_msg.soln_meta.sol_in[115].sensor_type = 234; + + test_msg.soln_meta.sol_in[116].flags = 234; + + test_msg.soln_meta.sol_in[116].sensor_type = 194; + + test_msg.soln_meta.sol_in[117].flags = 201; + + test_msg.soln_meta.sol_in[117].sensor_type = 170; + + test_msg.soln_meta.sol_in[118].flags = 154; + + test_msg.soln_meta.sol_in[118].sensor_type = 210; + + test_msg.soln_meta.tow = 3628191792; + + test_msg.soln_meta.vdop = 58512; + + sbp_message_send(&sbp_state, SbpMsgSolnMeta, 15360, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 15360, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSolnMeta, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.soln_meta.age_corrections == 21256, + "incorrect value for last_msg.msg.soln_meta.age_corrections, " + "expected 21256, is %d", + last_msg.msg.soln_meta.age_corrections); + + ck_assert_msg(last_msg.msg.soln_meta.age_gnss == 3573765977, + "incorrect value for last_msg.msg.soln_meta.age_gnss, " + "expected 3573765977, is %d", + last_msg.msg.soln_meta.age_gnss); + + ck_assert_msg(last_msg.msg.soln_meta.hdop == 41156, + "incorrect value for last_msg.msg.soln_meta.hdop, expected " + "41156, is %d", + last_msg.msg.soln_meta.hdop); + + ck_assert_msg(last_msg.msg.soln_meta.n_sol_in == 119, + "incorrect value for last_msg.msg.soln_meta.n_sol_in, " + "expected 119, is %d", + last_msg.msg.soln_meta.n_sol_in); + + ck_assert_msg(last_msg.msg.soln_meta.pdop == 11642, + "incorrect value for last_msg.msg.soln_meta.pdop, expected " + "11642, is %d", + last_msg.msg.soln_meta.pdop); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[0].flags == 109, + "incorrect value for last_msg.msg.soln_meta.sol_in[0].flags, " + "expected 109, is %d", + last_msg.msg.soln_meta.sol_in[0].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[0].sensor_type == 95, + "incorrect value for last_msg.msg.soln_meta.sol_in[0].sensor_type, " + "expected 95, is %d", + last_msg.msg.soln_meta.sol_in[0].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[1].flags == 131, + "incorrect value for last_msg.msg.soln_meta.sol_in[1].flags, " + "expected 131, is %d", + last_msg.msg.soln_meta.sol_in[1].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[1].sensor_type == 86, + "incorrect value for last_msg.msg.soln_meta.sol_in[1].sensor_type, " + "expected 86, is %d", + last_msg.msg.soln_meta.sol_in[1].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[2].flags == 70, + "incorrect value for last_msg.msg.soln_meta.sol_in[2].flags, " + "expected 70, is %d", + last_msg.msg.soln_meta.sol_in[2].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[2].sensor_type == 71, + "incorrect value for last_msg.msg.soln_meta.sol_in[2].sensor_type, " + "expected 71, is %d", + last_msg.msg.soln_meta.sol_in[2].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[3].flags == 73, + "incorrect value for last_msg.msg.soln_meta.sol_in[3].flags, " + "expected 73, is %d", + last_msg.msg.soln_meta.sol_in[3].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[3].sensor_type == 84, + "incorrect value for last_msg.msg.soln_meta.sol_in[3].sensor_type, " + "expected 84, is %d", + last_msg.msg.soln_meta.sol_in[3].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[4].flags == 26, + "incorrect value for last_msg.msg.soln_meta.sol_in[4].flags, " + "expected 26, is %d", + last_msg.msg.soln_meta.sol_in[4].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[4].sensor_type == 131, + "incorrect value for last_msg.msg.soln_meta.sol_in[4].sensor_type, " + "expected 131, is %d", + last_msg.msg.soln_meta.sol_in[4].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[5].flags == 247, + "incorrect value for last_msg.msg.soln_meta.sol_in[5].flags, " + "expected 247, is %d", + last_msg.msg.soln_meta.sol_in[5].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[5].sensor_type == 82, + "incorrect value for last_msg.msg.soln_meta.sol_in[5].sensor_type, " + "expected 82, is %d", + last_msg.msg.soln_meta.sol_in[5].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[6].flags == 97, + "incorrect value for last_msg.msg.soln_meta.sol_in[6].flags, " + "expected 97, is %d", + last_msg.msg.soln_meta.sol_in[6].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[6].sensor_type == 140, + "incorrect value for last_msg.msg.soln_meta.sol_in[6].sensor_type, " + "expected 140, is %d", + last_msg.msg.soln_meta.sol_in[6].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[7].flags == 110, + "incorrect value for last_msg.msg.soln_meta.sol_in[7].flags, " + "expected 110, is %d", + last_msg.msg.soln_meta.sol_in[7].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[7].sensor_type == 115, + "incorrect value for last_msg.msg.soln_meta.sol_in[7].sensor_type, " + "expected 115, is %d", + last_msg.msg.soln_meta.sol_in[7].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[8].flags == 253, + "incorrect value for last_msg.msg.soln_meta.sol_in[8].flags, " + "expected 253, is %d", + last_msg.msg.soln_meta.sol_in[8].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[8].sensor_type == 118, + "incorrect value for last_msg.msg.soln_meta.sol_in[8].sensor_type, " + "expected 118, is %d", + last_msg.msg.soln_meta.sol_in[8].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[9].flags == 122, + "incorrect value for last_msg.msg.soln_meta.sol_in[9].flags, " + "expected 122, is %d", + last_msg.msg.soln_meta.sol_in[9].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[9].sensor_type == 2, + "incorrect value for last_msg.msg.soln_meta.sol_in[9].sensor_type, " + "expected 2, is %d", + last_msg.msg.soln_meta.sol_in[9].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[10].flags == 148, + "incorrect value for last_msg.msg.soln_meta.sol_in[10].flags, expected " + "148, is %d", + last_msg.msg.soln_meta.sol_in[10].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[10].sensor_type == 186, + "incorrect value for last_msg.msg.soln_meta.sol_in[10].sensor_type, " + "expected 186, is %d", + last_msg.msg.soln_meta.sol_in[10].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[11].flags == 148, + "incorrect value for last_msg.msg.soln_meta.sol_in[11].flags, expected " + "148, is %d", + last_msg.msg.soln_meta.sol_in[11].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[11].sensor_type == 122, + "incorrect value for last_msg.msg.soln_meta.sol_in[11].sensor_type, " + "expected 122, is %d", + last_msg.msg.soln_meta.sol_in[11].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[12].flags == 231, + "incorrect value for last_msg.msg.soln_meta.sol_in[12].flags, expected " + "231, is %d", + last_msg.msg.soln_meta.sol_in[12].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[12].sensor_type == 180, + "incorrect value for last_msg.msg.soln_meta.sol_in[12].sensor_type, " + "expected 180, is %d", + last_msg.msg.soln_meta.sol_in[12].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[13].flags == 46, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[13].flags, expected 46, is %d", + last_msg.msg.soln_meta.sol_in[13].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[13].sensor_type == 68, + "incorrect value for last_msg.msg.soln_meta.sol_in[13].sensor_type, " + "expected 68, is %d", + last_msg.msg.soln_meta.sol_in[13].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[14].flags == 102, + "incorrect value for last_msg.msg.soln_meta.sol_in[14].flags, expected " + "102, is %d", + last_msg.msg.soln_meta.sol_in[14].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[14].sensor_type == 190, + "incorrect value for last_msg.msg.soln_meta.sol_in[14].sensor_type, " + "expected 190, is %d", + last_msg.msg.soln_meta.sol_in[14].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[15].flags == 48, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[15].flags, expected 48, is %d", + last_msg.msg.soln_meta.sol_in[15].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[15].sensor_type == 243, + "incorrect value for last_msg.msg.soln_meta.sol_in[15].sensor_type, " + "expected 243, is %d", + last_msg.msg.soln_meta.sol_in[15].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[16].flags == 15, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[16].flags, expected 15, is %d", + last_msg.msg.soln_meta.sol_in[16].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[16].sensor_type == 192, + "incorrect value for last_msg.msg.soln_meta.sol_in[16].sensor_type, " + "expected 192, is %d", + last_msg.msg.soln_meta.sol_in[16].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[17].flags == 89, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[17].flags, expected 89, is %d", + last_msg.msg.soln_meta.sol_in[17].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[17].sensor_type == 208, + "incorrect value for last_msg.msg.soln_meta.sol_in[17].sensor_type, " + "expected 208, is %d", + last_msg.msg.soln_meta.sol_in[17].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[18].flags == 10, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[18].flags, expected 10, is %d", + last_msg.msg.soln_meta.sol_in[18].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[18].sensor_type == 56, + "incorrect value for last_msg.msg.soln_meta.sol_in[18].sensor_type, " + "expected 56, is %d", + last_msg.msg.soln_meta.sol_in[18].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[19].flags == 2, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[19].flags, expected 2, is %d", + last_msg.msg.soln_meta.sol_in[19].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[19].sensor_type == 245, + "incorrect value for last_msg.msg.soln_meta.sol_in[19].sensor_type, " + "expected 245, is %d", + last_msg.msg.soln_meta.sol_in[19].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[20].flags == 201, + "incorrect value for last_msg.msg.soln_meta.sol_in[20].flags, expected " + "201, is %d", + last_msg.msg.soln_meta.sol_in[20].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[20].sensor_type == 254, + "incorrect value for last_msg.msg.soln_meta.sol_in[20].sensor_type, " + "expected 254, is %d", + last_msg.msg.soln_meta.sol_in[20].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[21].flags == 32, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[21].flags, expected 32, is %d", + last_msg.msg.soln_meta.sol_in[21].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[21].sensor_type == 120, + "incorrect value for last_msg.msg.soln_meta.sol_in[21].sensor_type, " + "expected 120, is %d", + last_msg.msg.soln_meta.sol_in[21].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[22].flags == 2, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[22].flags, expected 2, is %d", + last_msg.msg.soln_meta.sol_in[22].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[22].sensor_type == 126, + "incorrect value for last_msg.msg.soln_meta.sol_in[22].sensor_type, " + "expected 126, is %d", + last_msg.msg.soln_meta.sol_in[22].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[23].flags == 161, + "incorrect value for last_msg.msg.soln_meta.sol_in[23].flags, expected " + "161, is %d", + last_msg.msg.soln_meta.sol_in[23].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[23].sensor_type == 83, + "incorrect value for last_msg.msg.soln_meta.sol_in[23].sensor_type, " + "expected 83, is %d", + last_msg.msg.soln_meta.sol_in[23].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[24].flags == 123, + "incorrect value for last_msg.msg.soln_meta.sol_in[24].flags, expected " + "123, is %d", + last_msg.msg.soln_meta.sol_in[24].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[24].sensor_type == 238, + "incorrect value for last_msg.msg.soln_meta.sol_in[24].sensor_type, " + "expected 238, is %d", + last_msg.msg.soln_meta.sol_in[24].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[25].flags == 230, + "incorrect value for last_msg.msg.soln_meta.sol_in[25].flags, expected " + "230, is %d", + last_msg.msg.soln_meta.sol_in[25].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[25].sensor_type == 102, + "incorrect value for last_msg.msg.soln_meta.sol_in[25].sensor_type, " + "expected 102, is %d", + last_msg.msg.soln_meta.sol_in[25].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[26].flags == 190, + "incorrect value for last_msg.msg.soln_meta.sol_in[26].flags, expected " + "190, is %d", + last_msg.msg.soln_meta.sol_in[26].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[26].sensor_type == 76, + "incorrect value for last_msg.msg.soln_meta.sol_in[26].sensor_type, " + "expected 76, is %d", + last_msg.msg.soln_meta.sol_in[26].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[27].flags == 182, + "incorrect value for last_msg.msg.soln_meta.sol_in[27].flags, expected " + "182, is %d", + last_msg.msg.soln_meta.sol_in[27].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[27].sensor_type == 225, + "incorrect value for last_msg.msg.soln_meta.sol_in[27].sensor_type, " + "expected 225, is %d", + last_msg.msg.soln_meta.sol_in[27].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[28].flags == 228, + "incorrect value for last_msg.msg.soln_meta.sol_in[28].flags, expected " + "228, is %d", + last_msg.msg.soln_meta.sol_in[28].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[28].sensor_type == 207, + "incorrect value for last_msg.msg.soln_meta.sol_in[28].sensor_type, " + "expected 207, is %d", + last_msg.msg.soln_meta.sol_in[28].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[29].flags == 218, + "incorrect value for last_msg.msg.soln_meta.sol_in[29].flags, expected " + "218, is %d", + last_msg.msg.soln_meta.sol_in[29].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[29].sensor_type == 7, + "incorrect value for last_msg.msg.soln_meta.sol_in[29].sensor_type, " + "expected 7, is %d", + last_msg.msg.soln_meta.sol_in[29].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[30].flags == 89, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[30].flags, expected 89, is %d", + last_msg.msg.soln_meta.sol_in[30].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[30].sensor_type == 117, + "incorrect value for last_msg.msg.soln_meta.sol_in[30].sensor_type, " + "expected 117, is %d", + last_msg.msg.soln_meta.sol_in[30].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[31].flags == 191, + "incorrect value for last_msg.msg.soln_meta.sol_in[31].flags, expected " + "191, is %d", + last_msg.msg.soln_meta.sol_in[31].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[31].sensor_type == 29, + "incorrect value for last_msg.msg.soln_meta.sol_in[31].sensor_type, " + "expected 29, is %d", + last_msg.msg.soln_meta.sol_in[31].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[32].flags == 248, + "incorrect value for last_msg.msg.soln_meta.sol_in[32].flags, expected " + "248, is %d", + last_msg.msg.soln_meta.sol_in[32].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[32].sensor_type == 56, + "incorrect value for last_msg.msg.soln_meta.sol_in[32].sensor_type, " + "expected 56, is %d", + last_msg.msg.soln_meta.sol_in[32].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[33].flags == 255, + "incorrect value for last_msg.msg.soln_meta.sol_in[33].flags, expected " + "255, is %d", + last_msg.msg.soln_meta.sol_in[33].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[33].sensor_type == 185, + "incorrect value for last_msg.msg.soln_meta.sol_in[33].sensor_type, " + "expected 185, is %d", + last_msg.msg.soln_meta.sol_in[33].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[34].flags == 18, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[34].flags, expected 18, is %d", + last_msg.msg.soln_meta.sol_in[34].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[34].sensor_type == 46, + "incorrect value for last_msg.msg.soln_meta.sol_in[34].sensor_type, " + "expected 46, is %d", + last_msg.msg.soln_meta.sol_in[34].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[35].flags == 142, + "incorrect value for last_msg.msg.soln_meta.sol_in[35].flags, expected " + "142, is %d", + last_msg.msg.soln_meta.sol_in[35].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[35].sensor_type == 72, + "incorrect value for last_msg.msg.soln_meta.sol_in[35].sensor_type, " + "expected 72, is %d", + last_msg.msg.soln_meta.sol_in[35].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[36].flags == 113, + "incorrect value for last_msg.msg.soln_meta.sol_in[36].flags, expected " + "113, is %d", + last_msg.msg.soln_meta.sol_in[36].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[36].sensor_type == 82, + "incorrect value for last_msg.msg.soln_meta.sol_in[36].sensor_type, " + "expected 82, is %d", + last_msg.msg.soln_meta.sol_in[36].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[37].flags == 4, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[37].flags, expected 4, is %d", + last_msg.msg.soln_meta.sol_in[37].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[37].sensor_type == 26, + "incorrect value for last_msg.msg.soln_meta.sol_in[37].sensor_type, " + "expected 26, is %d", + last_msg.msg.soln_meta.sol_in[37].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[38].flags == 254, + "incorrect value for last_msg.msg.soln_meta.sol_in[38].flags, expected " + "254, is %d", + last_msg.msg.soln_meta.sol_in[38].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[38].sensor_type == 172, + "incorrect value for last_msg.msg.soln_meta.sol_in[38].sensor_type, " + "expected 172, is %d", + last_msg.msg.soln_meta.sol_in[38].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[39].flags == 136, + "incorrect value for last_msg.msg.soln_meta.sol_in[39].flags, expected " + "136, is %d", + last_msg.msg.soln_meta.sol_in[39].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[39].sensor_type == 178, + "incorrect value for last_msg.msg.soln_meta.sol_in[39].sensor_type, " + "expected 178, is %d", + last_msg.msg.soln_meta.sol_in[39].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[40].flags == 115, + "incorrect value for last_msg.msg.soln_meta.sol_in[40].flags, expected " + "115, is %d", + last_msg.msg.soln_meta.sol_in[40].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[40].sensor_type == 113, + "incorrect value for last_msg.msg.soln_meta.sol_in[40].sensor_type, " + "expected 113, is %d", + last_msg.msg.soln_meta.sol_in[40].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[41].flags == 193, + "incorrect value for last_msg.msg.soln_meta.sol_in[41].flags, expected " + "193, is %d", + last_msg.msg.soln_meta.sol_in[41].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[41].sensor_type == 58, + "incorrect value for last_msg.msg.soln_meta.sol_in[41].sensor_type, " + "expected 58, is %d", + last_msg.msg.soln_meta.sol_in[41].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[42].flags == 227, + "incorrect value for last_msg.msg.soln_meta.sol_in[42].flags, expected " + "227, is %d", + last_msg.msg.soln_meta.sol_in[42].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[42].sensor_type == 89, + "incorrect value for last_msg.msg.soln_meta.sol_in[42].sensor_type, " + "expected 89, is %d", + last_msg.msg.soln_meta.sol_in[42].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[43].flags == 246, + "incorrect value for last_msg.msg.soln_meta.sol_in[43].flags, expected " + "246, is %d", + last_msg.msg.soln_meta.sol_in[43].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[43].sensor_type == 182, + "incorrect value for last_msg.msg.soln_meta.sol_in[43].sensor_type, " + "expected 182, is %d", + last_msg.msg.soln_meta.sol_in[43].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[44].flags == 77, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[44].flags, expected 77, is %d", + last_msg.msg.soln_meta.sol_in[44].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[44].sensor_type == 76, + "incorrect value for last_msg.msg.soln_meta.sol_in[44].sensor_type, " + "expected 76, is %d", + last_msg.msg.soln_meta.sol_in[44].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[45].flags == 245, + "incorrect value for last_msg.msg.soln_meta.sol_in[45].flags, expected " + "245, is %d", + last_msg.msg.soln_meta.sol_in[45].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[45].sensor_type == 108, + "incorrect value for last_msg.msg.soln_meta.sol_in[45].sensor_type, " + "expected 108, is %d", + last_msg.msg.soln_meta.sol_in[45].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[46].flags == 31, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[46].flags, expected 31, is %d", + last_msg.msg.soln_meta.sol_in[46].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[46].sensor_type == 41, + "incorrect value for last_msg.msg.soln_meta.sol_in[46].sensor_type, " + "expected 41, is %d", + last_msg.msg.soln_meta.sol_in[46].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[47].flags == 124, + "incorrect value for last_msg.msg.soln_meta.sol_in[47].flags, expected " + "124, is %d", + last_msg.msg.soln_meta.sol_in[47].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[47].sensor_type == 70, + "incorrect value for last_msg.msg.soln_meta.sol_in[47].sensor_type, " + "expected 70, is %d", + last_msg.msg.soln_meta.sol_in[47].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[48].flags == 145, + "incorrect value for last_msg.msg.soln_meta.sol_in[48].flags, expected " + "145, is %d", + last_msg.msg.soln_meta.sol_in[48].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[48].sensor_type == 249, + "incorrect value for last_msg.msg.soln_meta.sol_in[48].sensor_type, " + "expected 249, is %d", + last_msg.msg.soln_meta.sol_in[48].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[49].flags == 78, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[49].flags, expected 78, is %d", + last_msg.msg.soln_meta.sol_in[49].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[49].sensor_type == 15, + "incorrect value for last_msg.msg.soln_meta.sol_in[49].sensor_type, " + "expected 15, is %d", + last_msg.msg.soln_meta.sol_in[49].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[50].flags == 38, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[50].flags, expected 38, is %d", + last_msg.msg.soln_meta.sol_in[50].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[50].sensor_type == 228, + "incorrect value for last_msg.msg.soln_meta.sol_in[50].sensor_type, " + "expected 228, is %d", + last_msg.msg.soln_meta.sol_in[50].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[51].flags == 129, + "incorrect value for last_msg.msg.soln_meta.sol_in[51].flags, expected " + "129, is %d", + last_msg.msg.soln_meta.sol_in[51].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[51].sensor_type == 241, + "incorrect value for last_msg.msg.soln_meta.sol_in[51].sensor_type, " + "expected 241, is %d", + last_msg.msg.soln_meta.sol_in[51].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[52].flags == 176, + "incorrect value for last_msg.msg.soln_meta.sol_in[52].flags, expected " + "176, is %d", + last_msg.msg.soln_meta.sol_in[52].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[52].sensor_type == 8, + "incorrect value for last_msg.msg.soln_meta.sol_in[52].sensor_type, " + "expected 8, is %d", + last_msg.msg.soln_meta.sol_in[52].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[53].flags == 72, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[53].flags, expected 72, is %d", + last_msg.msg.soln_meta.sol_in[53].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[53].sensor_type == 251, + "incorrect value for last_msg.msg.soln_meta.sol_in[53].sensor_type, " + "expected 251, is %d", + last_msg.msg.soln_meta.sol_in[53].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[54].flags == 80, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[54].flags, expected 80, is %d", + last_msg.msg.soln_meta.sol_in[54].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[54].sensor_type == 248, + "incorrect value for last_msg.msg.soln_meta.sol_in[54].sensor_type, " + "expected 248, is %d", + last_msg.msg.soln_meta.sol_in[54].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[55].flags == 244, + "incorrect value for last_msg.msg.soln_meta.sol_in[55].flags, expected " + "244, is %d", + last_msg.msg.soln_meta.sol_in[55].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[55].sensor_type == 115, + "incorrect value for last_msg.msg.soln_meta.sol_in[55].sensor_type, " + "expected 115, is %d", + last_msg.msg.soln_meta.sol_in[55].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[56].flags == 145, + "incorrect value for last_msg.msg.soln_meta.sol_in[56].flags, expected " + "145, is %d", + last_msg.msg.soln_meta.sol_in[56].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[56].sensor_type == 231, + "incorrect value for last_msg.msg.soln_meta.sol_in[56].sensor_type, " + "expected 231, is %d", + last_msg.msg.soln_meta.sol_in[56].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[57].flags == 190, + "incorrect value for last_msg.msg.soln_meta.sol_in[57].flags, expected " + "190, is %d", + last_msg.msg.soln_meta.sol_in[57].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[57].sensor_type == 191, + "incorrect value for last_msg.msg.soln_meta.sol_in[57].sensor_type, " + "expected 191, is %d", + last_msg.msg.soln_meta.sol_in[57].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[58].flags == 168, + "incorrect value for last_msg.msg.soln_meta.sol_in[58].flags, expected " + "168, is %d", + last_msg.msg.soln_meta.sol_in[58].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[58].sensor_type == 178, + "incorrect value for last_msg.msg.soln_meta.sol_in[58].sensor_type, " + "expected 178, is %d", + last_msg.msg.soln_meta.sol_in[58].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[59].flags == 233, + "incorrect value for last_msg.msg.soln_meta.sol_in[59].flags, expected " + "233, is %d", + last_msg.msg.soln_meta.sol_in[59].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[59].sensor_type == 89, + "incorrect value for last_msg.msg.soln_meta.sol_in[59].sensor_type, " + "expected 89, is %d", + last_msg.msg.soln_meta.sol_in[59].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[60].flags == 176, + "incorrect value for last_msg.msg.soln_meta.sol_in[60].flags, expected " + "176, is %d", + last_msg.msg.soln_meta.sol_in[60].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[60].sensor_type == 69, + "incorrect value for last_msg.msg.soln_meta.sol_in[60].sensor_type, " + "expected 69, is %d", + last_msg.msg.soln_meta.sol_in[60].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[61].flags == 140, + "incorrect value for last_msg.msg.soln_meta.sol_in[61].flags, expected " + "140, is %d", + last_msg.msg.soln_meta.sol_in[61].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[61].sensor_type == 174, + "incorrect value for last_msg.msg.soln_meta.sol_in[61].sensor_type, " + "expected 174, is %d", + last_msg.msg.soln_meta.sol_in[61].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[62].flags == 141, + "incorrect value for last_msg.msg.soln_meta.sol_in[62].flags, expected " + "141, is %d", + last_msg.msg.soln_meta.sol_in[62].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[62].sensor_type == 182, + "incorrect value for last_msg.msg.soln_meta.sol_in[62].sensor_type, " + "expected 182, is %d", + last_msg.msg.soln_meta.sol_in[62].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[63].flags == 82, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[63].flags, expected 82, is %d", + last_msg.msg.soln_meta.sol_in[63].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[63].sensor_type == 81, + "incorrect value for last_msg.msg.soln_meta.sol_in[63].sensor_type, " + "expected 81, is %d", + last_msg.msg.soln_meta.sol_in[63].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[64].flags == 79, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[64].flags, expected 79, is %d", + last_msg.msg.soln_meta.sol_in[64].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[64].sensor_type == 92, + "incorrect value for last_msg.msg.soln_meta.sol_in[64].sensor_type, " + "expected 92, is %d", + last_msg.msg.soln_meta.sol_in[64].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[65].flags == 223, + "incorrect value for last_msg.msg.soln_meta.sol_in[65].flags, expected " + "223, is %d", + last_msg.msg.soln_meta.sol_in[65].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[65].sensor_type == 101, + "incorrect value for last_msg.msg.soln_meta.sol_in[65].sensor_type, " + "expected 101, is %d", + last_msg.msg.soln_meta.sol_in[65].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[66].flags == 64, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[66].flags, expected 64, is %d", + last_msg.msg.soln_meta.sol_in[66].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[66].sensor_type == 100, + "incorrect value for last_msg.msg.soln_meta.sol_in[66].sensor_type, " + "expected 100, is %d", + last_msg.msg.soln_meta.sol_in[66].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[67].flags == 215, + "incorrect value for last_msg.msg.soln_meta.sol_in[67].flags, expected " + "215, is %d", + last_msg.msg.soln_meta.sol_in[67].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[67].sensor_type == 184, + "incorrect value for last_msg.msg.soln_meta.sol_in[67].sensor_type, " + "expected 184, is %d", + last_msg.msg.soln_meta.sol_in[67].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[68].flags == 37, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[68].flags, expected 37, is %d", + last_msg.msg.soln_meta.sol_in[68].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[68].sensor_type == 124, + "incorrect value for last_msg.msg.soln_meta.sol_in[68].sensor_type, " + "expected 124, is %d", + last_msg.msg.soln_meta.sol_in[68].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[69].flags == 227, + "incorrect value for last_msg.msg.soln_meta.sol_in[69].flags, expected " + "227, is %d", + last_msg.msg.soln_meta.sol_in[69].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[69].sensor_type == 21, + "incorrect value for last_msg.msg.soln_meta.sol_in[69].sensor_type, " + "expected 21, is %d", + last_msg.msg.soln_meta.sol_in[69].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[70].flags == 102, + "incorrect value for last_msg.msg.soln_meta.sol_in[70].flags, expected " + "102, is %d", + last_msg.msg.soln_meta.sol_in[70].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[70].sensor_type == 135, + "incorrect value for last_msg.msg.soln_meta.sol_in[70].sensor_type, " + "expected 135, is %d", + last_msg.msg.soln_meta.sol_in[70].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[71].flags == 36, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[71].flags, expected 36, is %d", + last_msg.msg.soln_meta.sol_in[71].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[71].sensor_type == 72, + "incorrect value for last_msg.msg.soln_meta.sol_in[71].sensor_type, " + "expected 72, is %d", + last_msg.msg.soln_meta.sol_in[71].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[72].flags == 56, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[72].flags, expected 56, is %d", + last_msg.msg.soln_meta.sol_in[72].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[72].sensor_type == 219, + "incorrect value for last_msg.msg.soln_meta.sol_in[72].sensor_type, " + "expected 219, is %d", + last_msg.msg.soln_meta.sol_in[72].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[73].flags == 90, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[73].flags, expected 90, is %d", + last_msg.msg.soln_meta.sol_in[73].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[73].sensor_type == 146, + "incorrect value for last_msg.msg.soln_meta.sol_in[73].sensor_type, " + "expected 146, is %d", + last_msg.msg.soln_meta.sol_in[73].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[74].flags == 104, + "incorrect value for last_msg.msg.soln_meta.sol_in[74].flags, expected " + "104, is %d", + last_msg.msg.soln_meta.sol_in[74].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[74].sensor_type == 219, + "incorrect value for last_msg.msg.soln_meta.sol_in[74].sensor_type, " + "expected 219, is %d", + last_msg.msg.soln_meta.sol_in[74].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[75].flags == 102, + "incorrect value for last_msg.msg.soln_meta.sol_in[75].flags, expected " + "102, is %d", + last_msg.msg.soln_meta.sol_in[75].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[75].sensor_type == 227, + "incorrect value for last_msg.msg.soln_meta.sol_in[75].sensor_type, " + "expected 227, is %d", + last_msg.msg.soln_meta.sol_in[75].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[76].flags == 12, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[76].flags, expected 12, is %d", + last_msg.msg.soln_meta.sol_in[76].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[76].sensor_type == 83, + "incorrect value for last_msg.msg.soln_meta.sol_in[76].sensor_type, " + "expected 83, is %d", + last_msg.msg.soln_meta.sol_in[76].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[77].flags == 122, + "incorrect value for last_msg.msg.soln_meta.sol_in[77].flags, expected " + "122, is %d", + last_msg.msg.soln_meta.sol_in[77].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[77].sensor_type == 41, + "incorrect value for last_msg.msg.soln_meta.sol_in[77].sensor_type, " + "expected 41, is %d", + last_msg.msg.soln_meta.sol_in[77].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[78].flags == 94, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[78].flags, expected 94, is %d", + last_msg.msg.soln_meta.sol_in[78].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[78].sensor_type == 173, + "incorrect value for last_msg.msg.soln_meta.sol_in[78].sensor_type, " + "expected 173, is %d", + last_msg.msg.soln_meta.sol_in[78].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[79].flags == 174, + "incorrect value for last_msg.msg.soln_meta.sol_in[79].flags, expected " + "174, is %d", + last_msg.msg.soln_meta.sol_in[79].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[79].sensor_type == 1, + "incorrect value for last_msg.msg.soln_meta.sol_in[79].sensor_type, " + "expected 1, is %d", + last_msg.msg.soln_meta.sol_in[79].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[80].flags == 130, + "incorrect value for last_msg.msg.soln_meta.sol_in[80].flags, expected " + "130, is %d", + last_msg.msg.soln_meta.sol_in[80].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[80].sensor_type == 134, + "incorrect value for last_msg.msg.soln_meta.sol_in[80].sensor_type, " + "expected 134, is %d", + last_msg.msg.soln_meta.sol_in[80].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[81].flags == 237, + "incorrect value for last_msg.msg.soln_meta.sol_in[81].flags, expected " + "237, is %d", + last_msg.msg.soln_meta.sol_in[81].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[81].sensor_type == 104, + "incorrect value for last_msg.msg.soln_meta.sol_in[81].sensor_type, " + "expected 104, is %d", + last_msg.msg.soln_meta.sol_in[81].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[82].flags == 249, + "incorrect value for last_msg.msg.soln_meta.sol_in[82].flags, expected " + "249, is %d", + last_msg.msg.soln_meta.sol_in[82].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[82].sensor_type == 116, + "incorrect value for last_msg.msg.soln_meta.sol_in[82].sensor_type, " + "expected 116, is %d", + last_msg.msg.soln_meta.sol_in[82].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[83].flags == 230, + "incorrect value for last_msg.msg.soln_meta.sol_in[83].flags, expected " + "230, is %d", + last_msg.msg.soln_meta.sol_in[83].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[83].sensor_type == 107, + "incorrect value for last_msg.msg.soln_meta.sol_in[83].sensor_type, " + "expected 107, is %d", + last_msg.msg.soln_meta.sol_in[83].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[84].flags == 123, + "incorrect value for last_msg.msg.soln_meta.sol_in[84].flags, expected " + "123, is %d", + last_msg.msg.soln_meta.sol_in[84].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[84].sensor_type == 130, + "incorrect value for last_msg.msg.soln_meta.sol_in[84].sensor_type, " + "expected 130, is %d", + last_msg.msg.soln_meta.sol_in[84].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[85].flags == 162, + "incorrect value for last_msg.msg.soln_meta.sol_in[85].flags, expected " + "162, is %d", + last_msg.msg.soln_meta.sol_in[85].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[85].sensor_type == 25, + "incorrect value for last_msg.msg.soln_meta.sol_in[85].sensor_type, " + "expected 25, is %d", + last_msg.msg.soln_meta.sol_in[85].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[86].flags == 223, + "incorrect value for last_msg.msg.soln_meta.sol_in[86].flags, expected " + "223, is %d", + last_msg.msg.soln_meta.sol_in[86].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[86].sensor_type == 57, + "incorrect value for last_msg.msg.soln_meta.sol_in[86].sensor_type, " + "expected 57, is %d", + last_msg.msg.soln_meta.sol_in[86].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[87].flags == 174, + "incorrect value for last_msg.msg.soln_meta.sol_in[87].flags, expected " + "174, is %d", + last_msg.msg.soln_meta.sol_in[87].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[87].sensor_type == 193, + "incorrect value for last_msg.msg.soln_meta.sol_in[87].sensor_type, " + "expected 193, is %d", + last_msg.msg.soln_meta.sol_in[87].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[88].flags == 193, + "incorrect value for last_msg.msg.soln_meta.sol_in[88].flags, expected " + "193, is %d", + last_msg.msg.soln_meta.sol_in[88].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[88].sensor_type == 146, + "incorrect value for last_msg.msg.soln_meta.sol_in[88].sensor_type, " + "expected 146, is %d", + last_msg.msg.soln_meta.sol_in[88].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[89].flags == 44, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[89].flags, expected 44, is %d", + last_msg.msg.soln_meta.sol_in[89].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[89].sensor_type == 239, + "incorrect value for last_msg.msg.soln_meta.sol_in[89].sensor_type, " + "expected 239, is %d", + last_msg.msg.soln_meta.sol_in[89].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[90].flags == 197, + "incorrect value for last_msg.msg.soln_meta.sol_in[90].flags, expected " + "197, is %d", + last_msg.msg.soln_meta.sol_in[90].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[90].sensor_type == 246, + "incorrect value for last_msg.msg.soln_meta.sol_in[90].sensor_type, " + "expected 246, is %d", + last_msg.msg.soln_meta.sol_in[90].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[91].flags == 80, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[91].flags, expected 80, is %d", + last_msg.msg.soln_meta.sol_in[91].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[91].sensor_type == 214, + "incorrect value for last_msg.msg.soln_meta.sol_in[91].sensor_type, " + "expected 214, is %d", + last_msg.msg.soln_meta.sol_in[91].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[92].flags == 100, + "incorrect value for last_msg.msg.soln_meta.sol_in[92].flags, expected " + "100, is %d", + last_msg.msg.soln_meta.sol_in[92].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[92].sensor_type == 83, + "incorrect value for last_msg.msg.soln_meta.sol_in[92].sensor_type, " + "expected 83, is %d", + last_msg.msg.soln_meta.sol_in[92].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[93].flags == 72, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[93].flags, expected 72, is %d", + last_msg.msg.soln_meta.sol_in[93].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[93].sensor_type == 66, + "incorrect value for last_msg.msg.soln_meta.sol_in[93].sensor_type, " + "expected 66, is %d", + last_msg.msg.soln_meta.sol_in[93].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[94].flags == 137, + "incorrect value for last_msg.msg.soln_meta.sol_in[94].flags, expected " + "137, is %d", + last_msg.msg.soln_meta.sol_in[94].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[94].sensor_type == 133, + "incorrect value for last_msg.msg.soln_meta.sol_in[94].sensor_type, " + "expected 133, is %d", + last_msg.msg.soln_meta.sol_in[94].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[95].flags == 82, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[95].flags, expected 82, is %d", + last_msg.msg.soln_meta.sol_in[95].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[95].sensor_type == 140, + "incorrect value for last_msg.msg.soln_meta.sol_in[95].sensor_type, " + "expected 140, is %d", + last_msg.msg.soln_meta.sol_in[95].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[96].flags == 2, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[96].flags, expected 2, is %d", + last_msg.msg.soln_meta.sol_in[96].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[96].sensor_type == 2, + "incorrect value for last_msg.msg.soln_meta.sol_in[96].sensor_type, " + "expected 2, is %d", + last_msg.msg.soln_meta.sol_in[96].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[97].flags == 9, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[97].flags, expected 9, is %d", + last_msg.msg.soln_meta.sol_in[97].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[97].sensor_type == 96, + "incorrect value for last_msg.msg.soln_meta.sol_in[97].sensor_type, " + "expected 96, is %d", + last_msg.msg.soln_meta.sol_in[97].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[98].flags == 158, + "incorrect value for last_msg.msg.soln_meta.sol_in[98].flags, expected " + "158, is %d", + last_msg.msg.soln_meta.sol_in[98].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[98].sensor_type == 96, + "incorrect value for last_msg.msg.soln_meta.sol_in[98].sensor_type, " + "expected 96, is %d", + last_msg.msg.soln_meta.sol_in[98].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.sol_in[99].flags == 97, + "incorrect value for " + "last_msg.msg.soln_meta.sol_in[99].flags, expected 97, is %d", + last_msg.msg.soln_meta.sol_in[99].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[99].sensor_type == 134, + "incorrect value for last_msg.msg.soln_meta.sol_in[99].sensor_type, " + "expected 134, is %d", + last_msg.msg.soln_meta.sol_in[99].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[100].flags == 129, + "incorrect value for last_msg.msg.soln_meta.sol_in[100].flags, " + "expected 129, is %d", + last_msg.msg.soln_meta.sol_in[100].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[100].sensor_type == 43, + "incorrect value for last_msg.msg.soln_meta.sol_in[100].sensor_type, " + "expected 43, is %d", + last_msg.msg.soln_meta.sol_in[100].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[101].flags == 25, + "incorrect value for last_msg.msg.soln_meta.sol_in[101].flags, " + "expected 25, is %d", + last_msg.msg.soln_meta.sol_in[101].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[101].sensor_type == 141, + "incorrect value for last_msg.msg.soln_meta.sol_in[101].sensor_type, " + "expected 141, is %d", + last_msg.msg.soln_meta.sol_in[101].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[102].flags == 200, + "incorrect value for last_msg.msg.soln_meta.sol_in[102].flags, " + "expected 200, is %d", + last_msg.msg.soln_meta.sol_in[102].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[102].sensor_type == 183, + "incorrect value for last_msg.msg.soln_meta.sol_in[102].sensor_type, " + "expected 183, is %d", + last_msg.msg.soln_meta.sol_in[102].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[103].flags == 57, + "incorrect value for last_msg.msg.soln_meta.sol_in[103].flags, " + "expected 57, is %d", + last_msg.msg.soln_meta.sol_in[103].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[103].sensor_type == 214, + "incorrect value for last_msg.msg.soln_meta.sol_in[103].sensor_type, " + "expected 214, is %d", + last_msg.msg.soln_meta.sol_in[103].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[104].flags == 103, + "incorrect value for last_msg.msg.soln_meta.sol_in[104].flags, " + "expected 103, is %d", + last_msg.msg.soln_meta.sol_in[104].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[104].sensor_type == 248, + "incorrect value for last_msg.msg.soln_meta.sol_in[104].sensor_type, " + "expected 248, is %d", + last_msg.msg.soln_meta.sol_in[104].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[105].flags == 65, + "incorrect value for last_msg.msg.soln_meta.sol_in[105].flags, " + "expected 65, is %d", + last_msg.msg.soln_meta.sol_in[105].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[105].sensor_type == 222, + "incorrect value for last_msg.msg.soln_meta.sol_in[105].sensor_type, " + "expected 222, is %d", + last_msg.msg.soln_meta.sol_in[105].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[106].flags == 15, + "incorrect value for last_msg.msg.soln_meta.sol_in[106].flags, " + "expected 15, is %d", + last_msg.msg.soln_meta.sol_in[106].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[106].sensor_type == 195, + "incorrect value for last_msg.msg.soln_meta.sol_in[106].sensor_type, " + "expected 195, is %d", + last_msg.msg.soln_meta.sol_in[106].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[107].flags == 21, + "incorrect value for last_msg.msg.soln_meta.sol_in[107].flags, " + "expected 21, is %d", + last_msg.msg.soln_meta.sol_in[107].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[107].sensor_type == 244, + "incorrect value for last_msg.msg.soln_meta.sol_in[107].sensor_type, " + "expected 244, is %d", + last_msg.msg.soln_meta.sol_in[107].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[108].flags == 46, + "incorrect value for last_msg.msg.soln_meta.sol_in[108].flags, " + "expected 46, is %d", + last_msg.msg.soln_meta.sol_in[108].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[108].sensor_type == 180, + "incorrect value for last_msg.msg.soln_meta.sol_in[108].sensor_type, " + "expected 180, is %d", + last_msg.msg.soln_meta.sol_in[108].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[109].flags == 130, + "incorrect value for last_msg.msg.soln_meta.sol_in[109].flags, " + "expected 130, is %d", + last_msg.msg.soln_meta.sol_in[109].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[109].sensor_type == 140, + "incorrect value for last_msg.msg.soln_meta.sol_in[109].sensor_type, " + "expected 140, is %d", + last_msg.msg.soln_meta.sol_in[109].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[110].flags == 17, + "incorrect value for last_msg.msg.soln_meta.sol_in[110].flags, " + "expected 17, is %d", + last_msg.msg.soln_meta.sol_in[110].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[110].sensor_type == 36, + "incorrect value for last_msg.msg.soln_meta.sol_in[110].sensor_type, " + "expected 36, is %d", + last_msg.msg.soln_meta.sol_in[110].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[111].flags == 209, + "incorrect value for last_msg.msg.soln_meta.sol_in[111].flags, " + "expected 209, is %d", + last_msg.msg.soln_meta.sol_in[111].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[111].sensor_type == 194, + "incorrect value for last_msg.msg.soln_meta.sol_in[111].sensor_type, " + "expected 194, is %d", + last_msg.msg.soln_meta.sol_in[111].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[112].flags == 254, + "incorrect value for last_msg.msg.soln_meta.sol_in[112].flags, " + "expected 254, is %d", + last_msg.msg.soln_meta.sol_in[112].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[112].sensor_type == 65, + "incorrect value for last_msg.msg.soln_meta.sol_in[112].sensor_type, " + "expected 65, is %d", + last_msg.msg.soln_meta.sol_in[112].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[113].flags == 103, + "incorrect value for last_msg.msg.soln_meta.sol_in[113].flags, " + "expected 103, is %d", + last_msg.msg.soln_meta.sol_in[113].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[113].sensor_type == 115, + "incorrect value for last_msg.msg.soln_meta.sol_in[113].sensor_type, " + "expected 115, is %d", + last_msg.msg.soln_meta.sol_in[113].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[114].flags == 129, + "incorrect value for last_msg.msg.soln_meta.sol_in[114].flags, " + "expected 129, is %d", + last_msg.msg.soln_meta.sol_in[114].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[114].sensor_type == 152, + "incorrect value for last_msg.msg.soln_meta.sol_in[114].sensor_type, " + "expected 152, is %d", + last_msg.msg.soln_meta.sol_in[114].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[115].flags == 235, + "incorrect value for last_msg.msg.soln_meta.sol_in[115].flags, " + "expected 235, is %d", + last_msg.msg.soln_meta.sol_in[115].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[115].sensor_type == 234, + "incorrect value for last_msg.msg.soln_meta.sol_in[115].sensor_type, " + "expected 234, is %d", + last_msg.msg.soln_meta.sol_in[115].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[116].flags == 234, + "incorrect value for last_msg.msg.soln_meta.sol_in[116].flags, " + "expected 234, is %d", + last_msg.msg.soln_meta.sol_in[116].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[116].sensor_type == 194, + "incorrect value for last_msg.msg.soln_meta.sol_in[116].sensor_type, " + "expected 194, is %d", + last_msg.msg.soln_meta.sol_in[116].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[117].flags == 201, + "incorrect value for last_msg.msg.soln_meta.sol_in[117].flags, " + "expected 201, is %d", + last_msg.msg.soln_meta.sol_in[117].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[117].sensor_type == 170, + "incorrect value for last_msg.msg.soln_meta.sol_in[117].sensor_type, " + "expected 170, is %d", + last_msg.msg.soln_meta.sol_in[117].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[118].flags == 154, + "incorrect value for last_msg.msg.soln_meta.sol_in[118].flags, " + "expected 154, is %d", + last_msg.msg.soln_meta.sol_in[118].flags); + + ck_assert_msg( + last_msg.msg.soln_meta.sol_in[118].sensor_type == 210, + "incorrect value for last_msg.msg.soln_meta.sol_in[118].sensor_type, " + "expected 210, is %d", + last_msg.msg.soln_meta.sol_in[118].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta.tow == 3628191792, + "incorrect value for last_msg.msg.soln_meta.tow, expected " + "3628191792, is %d", + last_msg.msg.soln_meta.tow); + + ck_assert_msg(last_msg.msg.soln_meta.vdop == 58512, + "incorrect value for last_msg.msg.soln_meta.vdop, expected " + "58512, is %d", + last_msg.msg.soln_meta.vdop); + } +} +END_TEST + +Suite *auto_check_sbp_solution_meta_MsgSolnMeta_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_solution_meta_MsgSolnMeta"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_solution_meta_MsgSolnMeta"); + tcase_add_test(tc_acq, test_auto_check_sbp_solution_meta_MsgSolnMeta); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c b/c/test/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c new file mode 100644 index 0000000000..61beda07dc --- /dev/null +++ b/c/test/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c @@ -0,0 +1,2115 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_solution_meta_MsgSolnMetaDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff0f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, + 190, 115, 93, 59, 103, 36, 83, 161, 156, 46, 253, 67, 87, 200, + 39, 250, 245, 242, 228, 72, 18, 222, 11, 88, 207, 218, 231, 13, + 226, 224, 22, 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, + 146, 40, 204, 51, 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, + 240, 190, 93, 219, 103, 42, 41, 182, 76, 222, 17, 23, 125, 31, + 18, 229, 28, 47, 214, 25, 100, 84, 106, 72, 48, 10, 222, 232, + 235, 73, 109, 163, 51, 152, 133, 235, 87, 70, 2, 108, 91, 101, + 200, 55, 24, 156, 233, 73, 39, 66, 97, 140, 252, 227, 230, 237, + 135, 241, 245, 205, 70, 0, 219, 188, 107, 136, 178, 58, 1, 29, + 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, 203, 18, 3, 222, + 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, 159, 174, 121, + 112, 167, 240, 40, 59, 3, 230, 52, 149, 148, 218, 142, 212, 109, + 176, 71, 179, 172, 77, 1, 193, 70, 147, 149, 23, 144, 148, 239, + 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, 222, 222, + 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, + 106, 236, 93, 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, + 221, 185, 202, 21, 252, 51, 130, 59, 166, 202, 127, 170, 58, 193, + 215, 125, 22, 58, 135, 47, 88, 142, 77, 211, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.soln_meta_dep_a.age_corrections = 48671; + + test_msg.soln_meta_dep_a.alignment_status = 115; + + test_msg.soln_meta_dep_a.hdop = 31133; + + test_msg.soln_meta_dep_a.last_used_gnss_pos_tow = 610745181; + + test_msg.soln_meta_dep_a.last_used_gnss_vel_tow = 782016851; + + test_msg.soln_meta_dep_a.n_sats = 238; + + test_msg.soln_meta_dep_a.n_sol_in = 118; + + test_msg.soln_meta_dep_a.pdop = 57015; + + test_msg.soln_meta_dep_a.sol_in[0].flags = 67; + + test_msg.soln_meta_dep_a.sol_in[0].sensor_type = 253; + + test_msg.soln_meta_dep_a.sol_in[1].flags = 200; + + test_msg.soln_meta_dep_a.sol_in[1].sensor_type = 87; + + test_msg.soln_meta_dep_a.sol_in[2].flags = 250; + + test_msg.soln_meta_dep_a.sol_in[2].sensor_type = 39; + + test_msg.soln_meta_dep_a.sol_in[3].flags = 242; + + test_msg.soln_meta_dep_a.sol_in[3].sensor_type = 245; + + test_msg.soln_meta_dep_a.sol_in[4].flags = 72; + + test_msg.soln_meta_dep_a.sol_in[4].sensor_type = 228; + + test_msg.soln_meta_dep_a.sol_in[5].flags = 222; + + test_msg.soln_meta_dep_a.sol_in[5].sensor_type = 18; + + test_msg.soln_meta_dep_a.sol_in[6].flags = 88; + + test_msg.soln_meta_dep_a.sol_in[6].sensor_type = 11; + + test_msg.soln_meta_dep_a.sol_in[7].flags = 218; + + test_msg.soln_meta_dep_a.sol_in[7].sensor_type = 207; + + test_msg.soln_meta_dep_a.sol_in[8].flags = 13; + + test_msg.soln_meta_dep_a.sol_in[8].sensor_type = 231; + + test_msg.soln_meta_dep_a.sol_in[9].flags = 224; + + test_msg.soln_meta_dep_a.sol_in[9].sensor_type = 226; + + test_msg.soln_meta_dep_a.sol_in[10].flags = 196; + + test_msg.soln_meta_dep_a.sol_in[10].sensor_type = 22; + + test_msg.soln_meta_dep_a.sol_in[11].flags = 242; + + test_msg.soln_meta_dep_a.sol_in[11].sensor_type = 21; + + test_msg.soln_meta_dep_a.sol_in[12].flags = 89; + + test_msg.soln_meta_dep_a.sol_in[12].sensor_type = 12; + + test_msg.soln_meta_dep_a.sol_in[13].flags = 219; + + test_msg.soln_meta_dep_a.sol_in[13].sensor_type = 71; + + test_msg.soln_meta_dep_a.sol_in[14].flags = 85; + + test_msg.soln_meta_dep_a.sol_in[14].sensor_type = 182; + + test_msg.soln_meta_dep_a.sol_in[15].flags = 204; + + test_msg.soln_meta_dep_a.sol_in[15].sensor_type = 145; + + test_msg.soln_meta_dep_a.sol_in[16].flags = 40; + + test_msg.soln_meta_dep_a.sol_in[16].sensor_type = 146; + + test_msg.soln_meta_dep_a.sol_in[17].flags = 51; + + test_msg.soln_meta_dep_a.sol_in[17].sensor_type = 204; + + test_msg.soln_meta_dep_a.sol_in[18].flags = 153; + + test_msg.soln_meta_dep_a.sol_in[18].sensor_type = 21; + + test_msg.soln_meta_dep_a.sol_in[19].flags = 44; + + test_msg.soln_meta_dep_a.sol_in[19].sensor_type = 227; + + test_msg.soln_meta_dep_a.sol_in[20].flags = 28; + + test_msg.soln_meta_dep_a.sol_in[20].sensor_type = 15; + + test_msg.soln_meta_dep_a.sol_in[21].flags = 39; + + test_msg.soln_meta_dep_a.sol_in[21].sensor_type = 255; + + test_msg.soln_meta_dep_a.sol_in[22].flags = 216; + + test_msg.soln_meta_dep_a.sol_in[22].sensor_type = 205; + + test_msg.soln_meta_dep_a.sol_in[23].flags = 190; + + test_msg.soln_meta_dep_a.sol_in[23].sensor_type = 240; + + test_msg.soln_meta_dep_a.sol_in[24].flags = 219; + + test_msg.soln_meta_dep_a.sol_in[24].sensor_type = 93; + + test_msg.soln_meta_dep_a.sol_in[25].flags = 42; + + test_msg.soln_meta_dep_a.sol_in[25].sensor_type = 103; + + test_msg.soln_meta_dep_a.sol_in[26].flags = 182; + + test_msg.soln_meta_dep_a.sol_in[26].sensor_type = 41; + + test_msg.soln_meta_dep_a.sol_in[27].flags = 222; + + test_msg.soln_meta_dep_a.sol_in[27].sensor_type = 76; + + test_msg.soln_meta_dep_a.sol_in[28].flags = 23; + + test_msg.soln_meta_dep_a.sol_in[28].sensor_type = 17; + + test_msg.soln_meta_dep_a.sol_in[29].flags = 31; + + test_msg.soln_meta_dep_a.sol_in[29].sensor_type = 125; + + test_msg.soln_meta_dep_a.sol_in[30].flags = 229; + + test_msg.soln_meta_dep_a.sol_in[30].sensor_type = 18; + + test_msg.soln_meta_dep_a.sol_in[31].flags = 47; + + test_msg.soln_meta_dep_a.sol_in[31].sensor_type = 28; + + test_msg.soln_meta_dep_a.sol_in[32].flags = 25; + + test_msg.soln_meta_dep_a.sol_in[32].sensor_type = 214; + + test_msg.soln_meta_dep_a.sol_in[33].flags = 84; + + test_msg.soln_meta_dep_a.sol_in[33].sensor_type = 100; + + test_msg.soln_meta_dep_a.sol_in[34].flags = 72; + + test_msg.soln_meta_dep_a.sol_in[34].sensor_type = 106; + + test_msg.soln_meta_dep_a.sol_in[35].flags = 10; + + test_msg.soln_meta_dep_a.sol_in[35].sensor_type = 48; + + test_msg.soln_meta_dep_a.sol_in[36].flags = 232; + + test_msg.soln_meta_dep_a.sol_in[36].sensor_type = 222; + + test_msg.soln_meta_dep_a.sol_in[37].flags = 73; + + test_msg.soln_meta_dep_a.sol_in[37].sensor_type = 235; + + test_msg.soln_meta_dep_a.sol_in[38].flags = 163; + + test_msg.soln_meta_dep_a.sol_in[38].sensor_type = 109; + + test_msg.soln_meta_dep_a.sol_in[39].flags = 152; + + test_msg.soln_meta_dep_a.sol_in[39].sensor_type = 51; + + test_msg.soln_meta_dep_a.sol_in[40].flags = 235; + + test_msg.soln_meta_dep_a.sol_in[40].sensor_type = 133; + + test_msg.soln_meta_dep_a.sol_in[41].flags = 70; + + test_msg.soln_meta_dep_a.sol_in[41].sensor_type = 87; + + test_msg.soln_meta_dep_a.sol_in[42].flags = 108; + + test_msg.soln_meta_dep_a.sol_in[42].sensor_type = 2; + + test_msg.soln_meta_dep_a.sol_in[43].flags = 101; + + test_msg.soln_meta_dep_a.sol_in[43].sensor_type = 91; + + test_msg.soln_meta_dep_a.sol_in[44].flags = 55; + + test_msg.soln_meta_dep_a.sol_in[44].sensor_type = 200; + + test_msg.soln_meta_dep_a.sol_in[45].flags = 156; + + test_msg.soln_meta_dep_a.sol_in[45].sensor_type = 24; + + test_msg.soln_meta_dep_a.sol_in[46].flags = 73; + + test_msg.soln_meta_dep_a.sol_in[46].sensor_type = 233; + + test_msg.soln_meta_dep_a.sol_in[47].flags = 66; + + test_msg.soln_meta_dep_a.sol_in[47].sensor_type = 39; + + test_msg.soln_meta_dep_a.sol_in[48].flags = 140; + + test_msg.soln_meta_dep_a.sol_in[48].sensor_type = 97; + + test_msg.soln_meta_dep_a.sol_in[49].flags = 227; + + test_msg.soln_meta_dep_a.sol_in[49].sensor_type = 252; + + test_msg.soln_meta_dep_a.sol_in[50].flags = 237; + + test_msg.soln_meta_dep_a.sol_in[50].sensor_type = 230; + + test_msg.soln_meta_dep_a.sol_in[51].flags = 241; + + test_msg.soln_meta_dep_a.sol_in[51].sensor_type = 135; + + test_msg.soln_meta_dep_a.sol_in[52].flags = 205; + + test_msg.soln_meta_dep_a.sol_in[52].sensor_type = 245; + + test_msg.soln_meta_dep_a.sol_in[53].flags = 0; + + test_msg.soln_meta_dep_a.sol_in[53].sensor_type = 70; + + test_msg.soln_meta_dep_a.sol_in[54].flags = 188; + + test_msg.soln_meta_dep_a.sol_in[54].sensor_type = 219; + + test_msg.soln_meta_dep_a.sol_in[55].flags = 136; + + test_msg.soln_meta_dep_a.sol_in[55].sensor_type = 107; + + test_msg.soln_meta_dep_a.sol_in[56].flags = 58; + + test_msg.soln_meta_dep_a.sol_in[56].sensor_type = 178; + + test_msg.soln_meta_dep_a.sol_in[57].flags = 29; + + test_msg.soln_meta_dep_a.sol_in[57].sensor_type = 1; + + test_msg.soln_meta_dep_a.sol_in[58].flags = 213; + + test_msg.soln_meta_dep_a.sol_in[58].sensor_type = 44; + + test_msg.soln_meta_dep_a.sol_in[59].flags = 147; + + test_msg.soln_meta_dep_a.sol_in[59].sensor_type = 225; + + test_msg.soln_meta_dep_a.sol_in[60].flags = 96; + + test_msg.soln_meta_dep_a.sol_in[60].sensor_type = 190; + + test_msg.soln_meta_dep_a.sol_in[61].flags = 108; + + test_msg.soln_meta_dep_a.sol_in[61].sensor_type = 192; + + test_msg.soln_meta_dep_a.sol_in[62].flags = 15; + + test_msg.soln_meta_dep_a.sol_in[62].sensor_type = 228; + + test_msg.soln_meta_dep_a.sol_in[63].flags = 18; + + test_msg.soln_meta_dep_a.sol_in[63].sensor_type = 203; + + test_msg.soln_meta_dep_a.sol_in[64].flags = 222; + + test_msg.soln_meta_dep_a.sol_in[64].sensor_type = 3; + + test_msg.soln_meta_dep_a.sol_in[65].flags = 68; + + test_msg.soln_meta_dep_a.sol_in[65].sensor_type = 180; + + test_msg.soln_meta_dep_a.sol_in[66].flags = 229; + + test_msg.soln_meta_dep_a.sol_in[66].sensor_type = 101; + + test_msg.soln_meta_dep_a.sol_in[67].flags = 203; + + test_msg.soln_meta_dep_a.sol_in[67].sensor_type = 223; + + test_msg.soln_meta_dep_a.sol_in[68].flags = 164; + + test_msg.soln_meta_dep_a.sol_in[68].sensor_type = 243; + + test_msg.soln_meta_dep_a.sol_in[69].flags = 165; + + test_msg.soln_meta_dep_a.sol_in[69].sensor_type = 92; + + test_msg.soln_meta_dep_a.sol_in[70].flags = 159; + + test_msg.soln_meta_dep_a.sol_in[70].sensor_type = 220; + + test_msg.soln_meta_dep_a.sol_in[71].flags = 121; + + test_msg.soln_meta_dep_a.sol_in[71].sensor_type = 174; + + test_msg.soln_meta_dep_a.sol_in[72].flags = 167; + + test_msg.soln_meta_dep_a.sol_in[72].sensor_type = 112; + + test_msg.soln_meta_dep_a.sol_in[73].flags = 40; + + test_msg.soln_meta_dep_a.sol_in[73].sensor_type = 240; + + test_msg.soln_meta_dep_a.sol_in[74].flags = 3; + + test_msg.soln_meta_dep_a.sol_in[74].sensor_type = 59; + + test_msg.soln_meta_dep_a.sol_in[75].flags = 52; + + test_msg.soln_meta_dep_a.sol_in[75].sensor_type = 230; + + test_msg.soln_meta_dep_a.sol_in[76].flags = 148; + + test_msg.soln_meta_dep_a.sol_in[76].sensor_type = 149; + + test_msg.soln_meta_dep_a.sol_in[77].flags = 142; + + test_msg.soln_meta_dep_a.sol_in[77].sensor_type = 218; + + test_msg.soln_meta_dep_a.sol_in[78].flags = 109; + + test_msg.soln_meta_dep_a.sol_in[78].sensor_type = 212; + + test_msg.soln_meta_dep_a.sol_in[79].flags = 71; + + test_msg.soln_meta_dep_a.sol_in[79].sensor_type = 176; + + test_msg.soln_meta_dep_a.sol_in[80].flags = 172; + + test_msg.soln_meta_dep_a.sol_in[80].sensor_type = 179; + + test_msg.soln_meta_dep_a.sol_in[81].flags = 1; + + test_msg.soln_meta_dep_a.sol_in[81].sensor_type = 77; + + test_msg.soln_meta_dep_a.sol_in[82].flags = 70; + + test_msg.soln_meta_dep_a.sol_in[82].sensor_type = 193; + + test_msg.soln_meta_dep_a.sol_in[83].flags = 149; + + test_msg.soln_meta_dep_a.sol_in[83].sensor_type = 147; + + test_msg.soln_meta_dep_a.sol_in[84].flags = 144; + + test_msg.soln_meta_dep_a.sol_in[84].sensor_type = 23; + + test_msg.soln_meta_dep_a.sol_in[85].flags = 239; + + test_msg.soln_meta_dep_a.sol_in[85].sensor_type = 148; + + test_msg.soln_meta_dep_a.sol_in[86].flags = 186; + + test_msg.soln_meta_dep_a.sol_in[86].sensor_type = 195; + + test_msg.soln_meta_dep_a.sol_in[87].flags = 30; + + test_msg.soln_meta_dep_a.sol_in[87].sensor_type = 86; + + test_msg.soln_meta_dep_a.sol_in[88].flags = 143; + + test_msg.soln_meta_dep_a.sol_in[88].sensor_type = 34; + + test_msg.soln_meta_dep_a.sol_in[89].flags = 207; + + test_msg.soln_meta_dep_a.sol_in[89].sensor_type = 156; + + test_msg.soln_meta_dep_a.sol_in[90].flags = 55; + + test_msg.soln_meta_dep_a.sol_in[90].sensor_type = 63; + + test_msg.soln_meta_dep_a.sol_in[91].flags = 255; + + test_msg.soln_meta_dep_a.sol_in[91].sensor_type = 117; + + test_msg.soln_meta_dep_a.sol_in[92].flags = 222; + + test_msg.soln_meta_dep_a.sol_in[92].sensor_type = 222; + + test_msg.soln_meta_dep_a.sol_in[93].flags = 145; + + test_msg.soln_meta_dep_a.sol_in[93].sensor_type = 219; + + test_msg.soln_meta_dep_a.sol_in[94].flags = 191; + + test_msg.soln_meta_dep_a.sol_in[94].sensor_type = 224; + + test_msg.soln_meta_dep_a.sol_in[95].flags = 109; + + test_msg.soln_meta_dep_a.sol_in[95].sensor_type = 210; + + test_msg.soln_meta_dep_a.sol_in[96].flags = 153; + + test_msg.soln_meta_dep_a.sol_in[96].sensor_type = 86; + + test_msg.soln_meta_dep_a.sol_in[97].flags = 32; + + test_msg.soln_meta_dep_a.sol_in[97].sensor_type = 21; + + test_msg.soln_meta_dep_a.sol_in[98].flags = 10; + + test_msg.soln_meta_dep_a.sol_in[98].sensor_type = 226; + + test_msg.soln_meta_dep_a.sol_in[99].flags = 63; + + test_msg.soln_meta_dep_a.sol_in[99].sensor_type = 60; + + test_msg.soln_meta_dep_a.sol_in[100].flags = 236; + + test_msg.soln_meta_dep_a.sol_in[100].sensor_type = 106; + + test_msg.soln_meta_dep_a.sol_in[101].flags = 96; + + test_msg.soln_meta_dep_a.sol_in[101].sensor_type = 93; + + test_msg.soln_meta_dep_a.sol_in[102].flags = 163; + + test_msg.soln_meta_dep_a.sol_in[102].sensor_type = 30; + + test_msg.soln_meta_dep_a.sol_in[103].flags = 238; + + test_msg.soln_meta_dep_a.sol_in[103].sensor_type = 106; + + test_msg.soln_meta_dep_a.sol_in[104].flags = 133; + + test_msg.soln_meta_dep_a.sol_in[104].sensor_type = 147; + + test_msg.soln_meta_dep_a.sol_in[105].flags = 107; + + test_msg.soln_meta_dep_a.sol_in[105].sensor_type = 132; + + test_msg.soln_meta_dep_a.sol_in[106].flags = 214; + + test_msg.soln_meta_dep_a.sol_in[106].sensor_type = 152; + + test_msg.soln_meta_dep_a.sol_in[107].flags = 185; + + test_msg.soln_meta_dep_a.sol_in[107].sensor_type = 221; + + test_msg.soln_meta_dep_a.sol_in[108].flags = 21; + + test_msg.soln_meta_dep_a.sol_in[108].sensor_type = 202; + + test_msg.soln_meta_dep_a.sol_in[109].flags = 51; + + test_msg.soln_meta_dep_a.sol_in[109].sensor_type = 252; + + test_msg.soln_meta_dep_a.sol_in[110].flags = 59; + + test_msg.soln_meta_dep_a.sol_in[110].sensor_type = 130; + + test_msg.soln_meta_dep_a.sol_in[111].flags = 202; + + test_msg.soln_meta_dep_a.sol_in[111].sensor_type = 166; + + test_msg.soln_meta_dep_a.sol_in[112].flags = 170; + + test_msg.soln_meta_dep_a.sol_in[112].sensor_type = 127; + + test_msg.soln_meta_dep_a.sol_in[113].flags = 193; + + test_msg.soln_meta_dep_a.sol_in[113].sensor_type = 58; + + test_msg.soln_meta_dep_a.sol_in[114].flags = 125; + + test_msg.soln_meta_dep_a.sol_in[114].sensor_type = 215; + + test_msg.soln_meta_dep_a.sol_in[115].flags = 58; + + test_msg.soln_meta_dep_a.sol_in[115].sensor_type = 22; + + test_msg.soln_meta_dep_a.sol_in[116].flags = 47; + + test_msg.soln_meta_dep_a.sol_in[116].sensor_type = 135; + + test_msg.soln_meta_dep_a.sol_in[117].flags = 142; + + test_msg.soln_meta_dep_a.sol_in[117].sensor_type = 88; + + test_msg.soln_meta_dep_a.vdop = 41989; + + sbp_message_send(&sbp_state, SbpMsgSolnMetaDepA, 61780, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61780, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSolnMetaDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.age_corrections == 48671, + "incorrect value for last_msg.msg.soln_meta_dep_a.age_corrections, " + "expected 48671, is %d", + last_msg.msg.soln_meta_dep_a.age_corrections); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.alignment_status == 115, + "incorrect value for last_msg.msg.soln_meta_dep_a.alignment_status, " + "expected 115, is %d", + last_msg.msg.soln_meta_dep_a.alignment_status); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.hdop == 31133, + "incorrect value for last_msg.msg.soln_meta_dep_a.hdop, " + "expected 31133, is %d", + last_msg.msg.soln_meta_dep_a.hdop); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.last_used_gnss_pos_tow == 610745181, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.last_used_gnss_pos_tow, expected " + "610745181, is %d", + last_msg.msg.soln_meta_dep_a.last_used_gnss_pos_tow); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.last_used_gnss_vel_tow == 782016851, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.last_used_gnss_vel_tow, expected " + "782016851, is %d", + last_msg.msg.soln_meta_dep_a.last_used_gnss_vel_tow); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.n_sats == 238, + "incorrect value for last_msg.msg.soln_meta_dep_a.n_sats, " + "expected 238, is %d", + last_msg.msg.soln_meta_dep_a.n_sats); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.n_sol_in == 118, + "incorrect value for last_msg.msg.soln_meta_dep_a.n_sol_in, " + "expected 118, is %d", + last_msg.msg.soln_meta_dep_a.n_sol_in); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.pdop == 57015, + "incorrect value for last_msg.msg.soln_meta_dep_a.pdop, " + "expected 57015, is %d", + last_msg.msg.soln_meta_dep_a.pdop); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[0].flags == 67, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[0].flags, " + "expected 67, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[0].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[0].sensor_type == 253, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[0].sensor_type, " + "expected 253, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[0].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[1].flags == 200, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[1].flags, " + "expected 200, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[1].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[1].sensor_type == 87, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[1].sensor_type, " + "expected 87, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[1].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[2].flags == 250, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[2].flags, " + "expected 250, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[2].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[2].sensor_type == 39, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[2].sensor_type, " + "expected 39, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[2].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[3].flags == 242, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[3].flags, " + "expected 242, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[3].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[3].sensor_type == 245, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[3].sensor_type, " + "expected 245, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[3].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[4].flags == 72, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[4].flags, " + "expected 72, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[4].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[4].sensor_type == 228, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[4].sensor_type, " + "expected 228, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[4].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[5].flags == 222, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[5].flags, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[5].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[5].sensor_type == 18, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[5].sensor_type, " + "expected 18, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[5].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[6].flags == 88, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[6].flags, " + "expected 88, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[6].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[6].sensor_type == 11, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[6].sensor_type, " + "expected 11, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[6].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[7].flags == 218, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[7].flags, " + "expected 218, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[7].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[7].sensor_type == 207, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[7].sensor_type, " + "expected 207, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[7].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[8].flags == 13, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[8].flags, " + "expected 13, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[8].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[8].sensor_type == 231, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[8].sensor_type, " + "expected 231, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[8].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[9].flags == 224, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[9].flags, " + "expected 224, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[9].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[9].sensor_type == 226, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[9].sensor_type, " + "expected 226, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[9].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[10].flags == 196, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[10].flags, " + "expected 196, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[10].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[10].sensor_type == 22, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[10].sensor_type, " + "expected 22, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[10].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[11].flags == 242, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[11].flags, " + "expected 242, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[11].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[11].sensor_type == 21, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[11].sensor_type, " + "expected 21, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[11].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[12].flags == 89, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[12].flags, " + "expected 89, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[12].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[12].sensor_type == 12, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[12].sensor_type, " + "expected 12, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[12].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[13].flags == 219, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[13].flags, " + "expected 219, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[13].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[13].sensor_type == 71, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[13].sensor_type, " + "expected 71, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[13].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[14].flags == 85, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[14].flags, " + "expected 85, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[14].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[14].sensor_type == 182, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[14].sensor_type, " + "expected 182, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[14].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[15].flags == 204, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[15].flags, " + "expected 204, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[15].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[15].sensor_type == 145, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[15].sensor_type, " + "expected 145, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[15].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[16].flags == 40, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[16].flags, " + "expected 40, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[16].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[16].sensor_type == 146, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[16].sensor_type, " + "expected 146, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[16].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[17].flags == 51, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[17].flags, " + "expected 51, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[17].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[17].sensor_type == 204, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[17].sensor_type, " + "expected 204, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[17].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[18].flags == 153, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[18].flags, " + "expected 153, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[18].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[18].sensor_type == 21, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[18].sensor_type, " + "expected 21, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[18].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[19].flags == 44, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[19].flags, " + "expected 44, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[19].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[19].sensor_type == 227, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[19].sensor_type, " + "expected 227, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[19].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[20].flags == 28, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[20].flags, " + "expected 28, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[20].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[20].sensor_type == 15, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[20].sensor_type, " + "expected 15, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[20].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[21].flags == 39, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[21].flags, " + "expected 39, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[21].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[21].sensor_type == 255, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[21].sensor_type, " + "expected 255, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[21].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[22].flags == 216, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[22].flags, " + "expected 216, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[22].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[22].sensor_type == 205, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[22].sensor_type, " + "expected 205, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[22].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[23].flags == 190, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[23].flags, " + "expected 190, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[23].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[23].sensor_type == 240, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[23].sensor_type, " + "expected 240, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[23].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[24].flags == 219, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[24].flags, " + "expected 219, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[24].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[24].sensor_type == 93, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[24].sensor_type, " + "expected 93, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[24].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[25].flags == 42, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[25].flags, " + "expected 42, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[25].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[25].sensor_type == 103, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[25].sensor_type, " + "expected 103, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[25].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[26].flags == 182, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[26].flags, " + "expected 182, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[26].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[26].sensor_type == 41, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[26].sensor_type, " + "expected 41, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[26].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[27].flags == 222, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[27].flags, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[27].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[27].sensor_type == 76, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[27].sensor_type, " + "expected 76, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[27].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[28].flags == 23, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[28].flags, " + "expected 23, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[28].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[28].sensor_type == 17, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[28].sensor_type, " + "expected 17, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[28].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[29].flags == 31, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[29].flags, " + "expected 31, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[29].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[29].sensor_type == 125, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[29].sensor_type, " + "expected 125, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[29].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[30].flags == 229, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[30].flags, " + "expected 229, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[30].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[30].sensor_type == 18, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[30].sensor_type, " + "expected 18, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[30].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[31].flags == 47, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[31].flags, " + "expected 47, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[31].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[31].sensor_type == 28, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[31].sensor_type, " + "expected 28, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[31].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[32].flags == 25, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[32].flags, " + "expected 25, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[32].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[32].sensor_type == 214, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[32].sensor_type, " + "expected 214, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[32].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[33].flags == 84, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[33].flags, " + "expected 84, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[33].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[33].sensor_type == 100, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[33].sensor_type, " + "expected 100, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[33].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[34].flags == 72, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[34].flags, " + "expected 72, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[34].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[34].sensor_type == 106, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[34].sensor_type, " + "expected 106, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[34].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[35].flags == 10, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[35].flags, " + "expected 10, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[35].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[35].sensor_type == 48, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[35].sensor_type, " + "expected 48, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[35].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[36].flags == 232, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[36].flags, " + "expected 232, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[36].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[36].sensor_type == 222, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[36].sensor_type, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[36].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[37].flags == 73, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[37].flags, " + "expected 73, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[37].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[37].sensor_type == 235, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[37].sensor_type, " + "expected 235, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[37].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[38].flags == 163, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[38].flags, " + "expected 163, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[38].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[38].sensor_type == 109, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[38].sensor_type, " + "expected 109, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[38].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[39].flags == 152, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[39].flags, " + "expected 152, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[39].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[39].sensor_type == 51, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[39].sensor_type, " + "expected 51, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[39].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[40].flags == 235, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[40].flags, " + "expected 235, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[40].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[40].sensor_type == 133, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[40].sensor_type, " + "expected 133, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[40].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[41].flags == 70, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[41].flags, " + "expected 70, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[41].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[41].sensor_type == 87, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[41].sensor_type, " + "expected 87, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[41].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[42].flags == 108, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[42].flags, " + "expected 108, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[42].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[42].sensor_type == 2, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[42].sensor_type, " + "expected 2, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[42].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[43].flags == 101, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[43].flags, " + "expected 101, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[43].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[43].sensor_type == 91, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[43].sensor_type, " + "expected 91, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[43].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[44].flags == 55, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[44].flags, " + "expected 55, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[44].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[44].sensor_type == 200, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[44].sensor_type, " + "expected 200, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[44].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[45].flags == 156, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[45].flags, " + "expected 156, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[45].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[45].sensor_type == 24, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[45].sensor_type, " + "expected 24, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[45].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[46].flags == 73, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[46].flags, " + "expected 73, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[46].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[46].sensor_type == 233, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[46].sensor_type, " + "expected 233, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[46].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[47].flags == 66, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[47].flags, " + "expected 66, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[47].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[47].sensor_type == 39, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[47].sensor_type, " + "expected 39, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[47].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[48].flags == 140, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[48].flags, " + "expected 140, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[48].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[48].sensor_type == 97, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[48].sensor_type, " + "expected 97, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[48].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[49].flags == 227, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[49].flags, " + "expected 227, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[49].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[49].sensor_type == 252, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[49].sensor_type, " + "expected 252, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[49].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[50].flags == 237, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[50].flags, " + "expected 237, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[50].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[50].sensor_type == 230, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[50].sensor_type, " + "expected 230, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[50].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[51].flags == 241, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[51].flags, " + "expected 241, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[51].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[51].sensor_type == 135, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[51].sensor_type, " + "expected 135, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[51].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[52].flags == 205, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[52].flags, " + "expected 205, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[52].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[52].sensor_type == 245, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[52].sensor_type, " + "expected 245, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[52].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[53].flags == 0, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[53].flags, " + "expected 0, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[53].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[53].sensor_type == 70, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[53].sensor_type, " + "expected 70, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[53].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[54].flags == 188, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[54].flags, " + "expected 188, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[54].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[54].sensor_type == 219, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[54].sensor_type, " + "expected 219, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[54].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[55].flags == 136, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[55].flags, " + "expected 136, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[55].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[55].sensor_type == 107, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[55].sensor_type, " + "expected 107, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[55].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[56].flags == 58, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[56].flags, " + "expected 58, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[56].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[56].sensor_type == 178, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[56].sensor_type, " + "expected 178, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[56].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[57].flags == 29, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[57].flags, " + "expected 29, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[57].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[57].sensor_type == 1, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[57].sensor_type, " + "expected 1, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[57].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[58].flags == 213, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[58].flags, " + "expected 213, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[58].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[58].sensor_type == 44, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[58].sensor_type, " + "expected 44, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[58].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[59].flags == 147, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[59].flags, " + "expected 147, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[59].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[59].sensor_type == 225, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[59].sensor_type, " + "expected 225, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[59].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[60].flags == 96, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[60].flags, " + "expected 96, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[60].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[60].sensor_type == 190, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[60].sensor_type, " + "expected 190, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[60].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[61].flags == 108, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[61].flags, " + "expected 108, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[61].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[61].sensor_type == 192, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[61].sensor_type, " + "expected 192, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[61].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[62].flags == 15, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[62].flags, " + "expected 15, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[62].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[62].sensor_type == 228, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[62].sensor_type, " + "expected 228, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[62].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[63].flags == 18, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[63].flags, " + "expected 18, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[63].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[63].sensor_type == 203, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[63].sensor_type, " + "expected 203, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[63].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[64].flags == 222, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[64].flags, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[64].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[64].sensor_type == 3, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[64].sensor_type, " + "expected 3, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[64].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[65].flags == 68, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[65].flags, " + "expected 68, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[65].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[65].sensor_type == 180, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[65].sensor_type, " + "expected 180, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[65].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[66].flags == 229, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[66].flags, " + "expected 229, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[66].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[66].sensor_type == 101, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[66].sensor_type, " + "expected 101, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[66].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[67].flags == 203, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[67].flags, " + "expected 203, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[67].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[67].sensor_type == 223, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[67].sensor_type, " + "expected 223, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[67].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[68].flags == 164, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[68].flags, " + "expected 164, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[68].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[68].sensor_type == 243, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[68].sensor_type, " + "expected 243, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[68].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[69].flags == 165, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[69].flags, " + "expected 165, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[69].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[69].sensor_type == 92, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[69].sensor_type, " + "expected 92, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[69].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[70].flags == 159, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[70].flags, " + "expected 159, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[70].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[70].sensor_type == 220, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[70].sensor_type, " + "expected 220, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[70].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[71].flags == 121, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[71].flags, " + "expected 121, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[71].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[71].sensor_type == 174, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[71].sensor_type, " + "expected 174, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[71].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[72].flags == 167, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[72].flags, " + "expected 167, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[72].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[72].sensor_type == 112, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[72].sensor_type, " + "expected 112, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[72].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[73].flags == 40, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[73].flags, " + "expected 40, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[73].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[73].sensor_type == 240, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[73].sensor_type, " + "expected 240, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[73].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[74].flags == 3, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[74].flags, " + "expected 3, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[74].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[74].sensor_type == 59, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[74].sensor_type, " + "expected 59, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[74].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[75].flags == 52, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[75].flags, " + "expected 52, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[75].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[75].sensor_type == 230, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[75].sensor_type, " + "expected 230, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[75].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[76].flags == 148, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[76].flags, " + "expected 148, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[76].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[76].sensor_type == 149, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[76].sensor_type, " + "expected 149, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[76].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[77].flags == 142, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[77].flags, " + "expected 142, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[77].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[77].sensor_type == 218, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[77].sensor_type, " + "expected 218, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[77].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[78].flags == 109, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[78].flags, " + "expected 109, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[78].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[78].sensor_type == 212, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[78].sensor_type, " + "expected 212, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[78].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[79].flags == 71, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[79].flags, " + "expected 71, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[79].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[79].sensor_type == 176, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[79].sensor_type, " + "expected 176, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[79].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[80].flags == 172, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[80].flags, " + "expected 172, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[80].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[80].sensor_type == 179, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[80].sensor_type, " + "expected 179, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[80].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[81].flags == 1, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[81].flags, " + "expected 1, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[81].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[81].sensor_type == 77, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[81].sensor_type, " + "expected 77, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[81].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[82].flags == 70, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[82].flags, " + "expected 70, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[82].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[82].sensor_type == 193, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[82].sensor_type, " + "expected 193, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[82].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[83].flags == 149, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[83].flags, " + "expected 149, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[83].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[83].sensor_type == 147, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[83].sensor_type, " + "expected 147, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[83].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[84].flags == 144, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[84].flags, " + "expected 144, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[84].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[84].sensor_type == 23, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[84].sensor_type, " + "expected 23, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[84].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[85].flags == 239, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[85].flags, " + "expected 239, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[85].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[85].sensor_type == 148, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[85].sensor_type, " + "expected 148, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[85].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[86].flags == 186, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[86].flags, " + "expected 186, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[86].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[86].sensor_type == 195, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[86].sensor_type, " + "expected 195, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[86].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[87].flags == 30, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[87].flags, " + "expected 30, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[87].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[87].sensor_type == 86, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[87].sensor_type, " + "expected 86, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[87].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[88].flags == 143, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[88].flags, " + "expected 143, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[88].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[88].sensor_type == 34, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[88].sensor_type, " + "expected 34, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[88].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[89].flags == 207, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[89].flags, " + "expected 207, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[89].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[89].sensor_type == 156, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[89].sensor_type, " + "expected 156, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[89].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[90].flags == 55, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[90].flags, " + "expected 55, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[90].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[90].sensor_type == 63, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[90].sensor_type, " + "expected 63, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[90].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[91].flags == 255, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[91].flags, " + "expected 255, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[91].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[91].sensor_type == 117, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[91].sensor_type, " + "expected 117, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[91].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[92].flags == 222, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[92].flags, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[92].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[92].sensor_type == 222, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[92].sensor_type, " + "expected 222, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[92].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[93].flags == 145, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[93].flags, " + "expected 145, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[93].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[93].sensor_type == 219, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[93].sensor_type, " + "expected 219, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[93].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[94].flags == 191, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[94].flags, " + "expected 191, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[94].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[94].sensor_type == 224, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[94].sensor_type, " + "expected 224, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[94].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[95].flags == 109, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[95].flags, " + "expected 109, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[95].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[95].sensor_type == 210, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[95].sensor_type, " + "expected 210, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[95].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[96].flags == 153, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[96].flags, " + "expected 153, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[96].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[96].sensor_type == 86, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[96].sensor_type, " + "expected 86, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[96].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[97].flags == 32, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[97].flags, " + "expected 32, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[97].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[97].sensor_type == 21, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[97].sensor_type, " + "expected 21, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[97].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[98].flags == 10, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[98].flags, " + "expected 10, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[98].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[98].sensor_type == 226, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[98].sensor_type, " + "expected 226, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[98].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[99].flags == 63, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[99].flags, " + "expected 63, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[99].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[99].sensor_type == 60, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[99].sensor_type, " + "expected 60, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[99].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[100].flags == 236, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[100].flags, " + "expected 236, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[100].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[100].sensor_type == 106, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[100].sensor_type, " + "expected 106, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[100].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[101].flags == 96, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[101].flags, " + "expected 96, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[101].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[101].sensor_type == 93, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[101].sensor_type, " + "expected 93, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[101].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[102].flags == 163, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[102].flags, " + "expected 163, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[102].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[102].sensor_type == 30, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[102].sensor_type, " + "expected 30, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[102].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[103].flags == 238, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[103].flags, " + "expected 238, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[103].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[103].sensor_type == 106, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[103].sensor_type, " + "expected 106, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[103].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[104].flags == 133, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[104].flags, " + "expected 133, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[104].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[104].sensor_type == 147, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[104].sensor_type, " + "expected 147, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[104].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[105].flags == 107, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[105].flags, " + "expected 107, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[105].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[105].sensor_type == 132, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[105].sensor_type, " + "expected 132, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[105].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[106].flags == 214, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[106].flags, " + "expected 214, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[106].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[106].sensor_type == 152, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[106].sensor_type, " + "expected 152, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[106].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[107].flags == 185, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[107].flags, " + "expected 185, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[107].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[107].sensor_type == 221, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[107].sensor_type, " + "expected 221, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[107].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[108].flags == 21, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[108].flags, " + "expected 21, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[108].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[108].sensor_type == 202, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[108].sensor_type, " + "expected 202, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[108].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[109].flags == 51, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[109].flags, " + "expected 51, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[109].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[109].sensor_type == 252, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[109].sensor_type, " + "expected 252, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[109].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[110].flags == 59, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[110].flags, " + "expected 59, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[110].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[110].sensor_type == 130, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[110].sensor_type, " + "expected 130, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[110].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[111].flags == 202, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[111].flags, " + "expected 202, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[111].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[111].sensor_type == 166, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[111].sensor_type, " + "expected 166, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[111].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[112].flags == 170, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[112].flags, " + "expected 170, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[112].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[112].sensor_type == 127, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[112].sensor_type, " + "expected 127, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[112].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[113].flags == 193, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[113].flags, " + "expected 193, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[113].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[113].sensor_type == 58, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[113].sensor_type, " + "expected 58, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[113].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[114].flags == 125, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[114].flags, " + "expected 125, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[114].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[114].sensor_type == 215, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[114].sensor_type, " + "expected 215, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[114].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[115].flags == 58, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[115].flags, " + "expected 58, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[115].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[115].sensor_type == 22, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[115].sensor_type, " + "expected 22, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[115].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[116].flags == 47, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[116].flags, " + "expected 47, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[116].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[116].sensor_type == 135, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[116].sensor_type, " + "expected 135, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[116].sensor_type); + + ck_assert_msg( + last_msg.msg.soln_meta_dep_a.sol_in[117].flags == 142, + "incorrect value for last_msg.msg.soln_meta_dep_a.sol_in[117].flags, " + "expected 142, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[117].flags); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.sol_in[117].sensor_type == 88, + "incorrect value for " + "last_msg.msg.soln_meta_dep_a.sol_in[117].sensor_type, " + "expected 88, is %d", + last_msg.msg.soln_meta_dep_a.sol_in[117].sensor_type); + + ck_assert_msg(last_msg.msg.soln_meta_dep_a.vdop == 41989, + "incorrect value for last_msg.msg.soln_meta_dep_a.vdop, " + "expected 41989, is %d", + last_msg.msg.soln_meta_dep_a.vdop); + } +} +END_TEST + +Suite *auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_solution_meta_MsgSolnMetaDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_solution_meta_MsgSolnMetaDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_solution_meta_MsgSolnMetaDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrCodeBiases.c b/c/test/auto_check_sbp_ssr_MsgSsrCodeBiases.c new file mode 100644 index 0000000000..6261b1f9c2 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrCodeBiases.c @@ -0,0 +1,1504 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrCodeBiases) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5e1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, + 254, 132, 51, 4, 131, 240, 120, 83, 148, 209, 213, 62, 228, 232, + 71, 66, 188, 210, 128, 54, 131, 152, 129, 111, 139, 242, 177, 145, + 44, 9, 245, 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, + 98, 191, 23, 128, 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, + 209, 139, 13, 101, 32, 7, 18, 29, 70, 250, 109, 73, 202, 79, + 144, 9, 146, 69, 241, 52, 22, 99, 98, 204, 3, 171, 230, 180, + 75, 62, 145, 86, 130, 31, 30, 155, 37, 18, 55, 210, 39, 127, + 242, 66, 13, 237, 152, 170, 212, 15, 246, 59, 94, 180, 195, 157, + 69, 100, 119, 16, 68, 179, 175, 144, 113, 81, 82, 30, 151, 21, + 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, 6, 78, 81, 143, + 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, 247, 34, 97, + 74, 97, 176, 48, 236, 173, 12, 174, 101, 130, 30, 169, 193, 190, + 204, 196, 123, 107, 25, 225, 74, 9, 10, 55, 3, 131, 246, 99, + 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, + 10, 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, + 191, 120, 77, 192, 91, 224, 1, 226, 50, 87, 146, 148, 238, 100, + 179, 125, 227, 215, 104, 184, 31, 57, 90, 79, 21, 156, 245, 81, + 60, 93, 170, 60, 200, 167, 13, 125, 132, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_code_biases.biases[0].code = 51; + + test_msg.ssr_code_biases.biases[0].value = -31996; + + test_msg.ssr_code_biases.biases[1].code = 240; + + test_msg.ssr_code_biases.biases[1].value = 21368; + + test_msg.ssr_code_biases.biases[2].code = 148; + + test_msg.ssr_code_biases.biases[2].value = -10799; + + test_msg.ssr_code_biases.biases[3].code = 62; + + test_msg.ssr_code_biases.biases[3].value = -5916; + + test_msg.ssr_code_biases.biases[4].code = 71; + + test_msg.ssr_code_biases.biases[4].value = -17342; + + test_msg.ssr_code_biases.biases[5].code = 210; + + test_msg.ssr_code_biases.biases[5].value = 13952; + + test_msg.ssr_code_biases.biases[6].code = 131; + + test_msg.ssr_code_biases.biases[6].value = -32360; + + test_msg.ssr_code_biases.biases[7].code = 111; + + test_msg.ssr_code_biases.biases[7].value = -3445; + + test_msg.ssr_code_biases.biases[8].code = 177; + + test_msg.ssr_code_biases.biases[8].value = 11409; + + test_msg.ssr_code_biases.biases[9].code = 9; + + test_msg.ssr_code_biases.biases[9].value = -12299; + + test_msg.ssr_code_biases.biases[10].code = 241; + + test_msg.ssr_code_biases.biases[10].value = -26934; + + test_msg.ssr_code_biases.biases[11].code = 141; + + test_msg.ssr_code_biases.biases[11].value = -24782; + + test_msg.ssr_code_biases.biases[12].code = 220; + + test_msg.ssr_code_biases.biases[12].value = 9611; + + test_msg.ssr_code_biases.biases[13].code = 187; + + test_msg.ssr_code_biases.biases[13].value = -16542; + + test_msg.ssr_code_biases.biases[14].code = 23; + + test_msg.ssr_code_biases.biases[14].value = -30592; + + test_msg.ssr_code_biases.biases[15].code = 167; + + test_msg.ssr_code_biases.biases[15].value = 1736; + + test_msg.ssr_code_biases.biases[16].code = 211; + + test_msg.ssr_code_biases.biases[16].value = 5978; + + test_msg.ssr_code_biases.biases[17].code = 244; + + test_msg.ssr_code_biases.biases[17].value = -10358; + + test_msg.ssr_code_biases.biases[18].code = 209; + + test_msg.ssr_code_biases.biases[18].value = 3467; + + test_msg.ssr_code_biases.biases[19].code = 101; + + test_msg.ssr_code_biases.biases[19].value = 1824; + + test_msg.ssr_code_biases.biases[20].code = 18; + + test_msg.ssr_code_biases.biases[20].value = 17949; + + test_msg.ssr_code_biases.biases[21].code = 250; + + test_msg.ssr_code_biases.biases[21].value = 18797; + + test_msg.ssr_code_biases.biases[22].code = 202; + + test_msg.ssr_code_biases.biases[22].value = -28593; + + test_msg.ssr_code_biases.biases[23].code = 9; + + test_msg.ssr_code_biases.biases[23].value = 17810; + + test_msg.ssr_code_biases.biases[24].code = 241; + + test_msg.ssr_code_biases.biases[24].value = 5684; + + test_msg.ssr_code_biases.biases[25].code = 99; + + test_msg.ssr_code_biases.biases[25].value = -13214; + + test_msg.ssr_code_biases.biases[26].code = 3; + + test_msg.ssr_code_biases.biases[26].value = -6485; + + test_msg.ssr_code_biases.biases[27].code = 180; + + test_msg.ssr_code_biases.biases[27].value = 15947; + + test_msg.ssr_code_biases.biases[28].code = 145; + + test_msg.ssr_code_biases.biases[28].value = -32170; + + test_msg.ssr_code_biases.biases[29].code = 31; + + test_msg.ssr_code_biases.biases[29].value = -25826; + + test_msg.ssr_code_biases.biases[30].code = 37; + + test_msg.ssr_code_biases.biases[30].value = 14098; + + test_msg.ssr_code_biases.biases[31].code = 210; + + test_msg.ssr_code_biases.biases[31].value = 32551; + + test_msg.ssr_code_biases.biases[32].code = 242; + + test_msg.ssr_code_biases.biases[32].value = 3394; + + test_msg.ssr_code_biases.biases[33].code = 237; + + test_msg.ssr_code_biases.biases[33].value = -21864; + + test_msg.ssr_code_biases.biases[34].code = 212; + + test_msg.ssr_code_biases.biases[34].value = -2545; + + test_msg.ssr_code_biases.biases[35].code = 59; + + test_msg.ssr_code_biases.biases[35].value = -19362; + + test_msg.ssr_code_biases.biases[36].code = 195; + + test_msg.ssr_code_biases.biases[36].value = 17821; + + test_msg.ssr_code_biases.biases[37].code = 100; + + test_msg.ssr_code_biases.biases[37].value = 4215; + + test_msg.ssr_code_biases.biases[38].code = 68; + + test_msg.ssr_code_biases.biases[38].value = -20557; + + test_msg.ssr_code_biases.biases[39].code = 144; + + test_msg.ssr_code_biases.biases[39].value = 20849; + + test_msg.ssr_code_biases.biases[40].code = 82; + + test_msg.ssr_code_biases.biases[40].value = -26850; + + test_msg.ssr_code_biases.biases[41].code = 21; + + test_msg.ssr_code_biases.biases[41].value = 10605; + + test_msg.ssr_code_biases.biases[42].code = 225; + + test_msg.ssr_code_biases.biases[42].value = 19720; + + test_msg.ssr_code_biases.biases[43].code = 164; + + test_msg.ssr_code_biases.biases[43].value = 157; + + test_msg.ssr_code_biases.biases[44].code = 73; + + test_msg.ssr_code_biases.biases[44].value = 1566; + + test_msg.ssr_code_biases.biases[45].code = 78; + + test_msg.ssr_code_biases.biases[45].value = -28847; + + test_msg.ssr_code_biases.biases[46].code = 116; + + test_msg.ssr_code_biases.biases[46].value = -26640; + + test_msg.ssr_code_biases.biases[47].code = 55; + + test_msg.ssr_code_biases.biases[47].value = -22087; + + test_msg.ssr_code_biases.biases[48].code = 254; + + test_msg.ssr_code_biases.biases[48].value = 10035; + + test_msg.ssr_code_biases.biases[49].code = 74; + + test_msg.ssr_code_biases.biases[49].value = -2129; + + test_msg.ssr_code_biases.biases[50].code = 34; + + test_msg.ssr_code_biases.biases[50].value = 19041; + + test_msg.ssr_code_biases.biases[51].code = 97; + + test_msg.ssr_code_biases.biases[51].value = 12464; + + test_msg.ssr_code_biases.biases[52].code = 236; + + test_msg.ssr_code_biases.biases[52].value = 3245; + + test_msg.ssr_code_biases.biases[53].code = 174; + + test_msg.ssr_code_biases.biases[53].value = -32155; + + test_msg.ssr_code_biases.biases[54].code = 30; + + test_msg.ssr_code_biases.biases[54].value = -15959; + + test_msg.ssr_code_biases.biases[55].code = 190; + + test_msg.ssr_code_biases.biases[55].value = -15156; + + test_msg.ssr_code_biases.biases[56].code = 123; + + test_msg.ssr_code_biases.biases[56].value = 6507; + + test_msg.ssr_code_biases.biases[57].code = 225; + + test_msg.ssr_code_biases.biases[57].value = 2378; + + test_msg.ssr_code_biases.biases[58].code = 10; + + test_msg.ssr_code_biases.biases[58].value = 823; + + test_msg.ssr_code_biases.biases[59].code = 131; + + test_msg.ssr_code_biases.biases[59].value = 25590; + + test_msg.ssr_code_biases.biases[60].code = 133; + + test_msg.ssr_code_biases.biases[60].value = -7390; + + test_msg.ssr_code_biases.biases[61].code = 203; + + test_msg.ssr_code_biases.biases[61].value = 4676; + + test_msg.ssr_code_biases.biases[62].code = 97; + + test_msg.ssr_code_biases.biases[62].value = 23007; + + test_msg.ssr_code_biases.biases[63].code = 192; + + test_msg.ssr_code_biases.biases[63].value = 13046; + + test_msg.ssr_code_biases.biases[64].code = 69; + + test_msg.ssr_code_biases.biases[64].value = 2651; + + test_msg.ssr_code_biases.biases[65].code = 151; + + test_msg.ssr_code_biases.biases[65].value = 30282; + + test_msg.ssr_code_biases.biases[66].code = 110; + + test_msg.ssr_code_biases.biases[66].value = -22492; + + test_msg.ssr_code_biases.biases[67].code = 247; + + test_msg.ssr_code_biases.biases[67].value = 19872; + + test_msg.ssr_code_biases.biases[68].code = 179; + + test_msg.ssr_code_biases.biases[68].value = -19827; + + test_msg.ssr_code_biases.biases[69].code = 99; + + test_msg.ssr_code_biases.biases[69].value = 30911; + + test_msg.ssr_code_biases.biases[70].code = 77; + + test_msg.ssr_code_biases.biases[70].value = 23488; + + test_msg.ssr_code_biases.biases[71].code = 224; + + test_msg.ssr_code_biases.biases[71].value = -7679; + + test_msg.ssr_code_biases.biases[72].code = 50; + + test_msg.ssr_code_biases.biases[72].value = -28073; + + test_msg.ssr_code_biases.biases[73].code = 148; + + test_msg.ssr_code_biases.biases[73].value = 25838; + + test_msg.ssr_code_biases.biases[74].code = 179; + + test_msg.ssr_code_biases.biases[74].value = -7299; + + test_msg.ssr_code_biases.biases[75].code = 215; + + test_msg.ssr_code_biases.biases[75].value = -18328; + + test_msg.ssr_code_biases.biases[76].code = 31; + + test_msg.ssr_code_biases.biases[76].value = 23097; + + test_msg.ssr_code_biases.biases[77].code = 79; + + test_msg.ssr_code_biases.biases[77].value = -25579; + + test_msg.ssr_code_biases.biases[78].code = 245; + + test_msg.ssr_code_biases.biases[78].value = 15441; + + test_msg.ssr_code_biases.biases[79].code = 93; + + test_msg.ssr_code_biases.biases[79].value = 15530; + + test_msg.ssr_code_biases.biases[80].code = 200; + + test_msg.ssr_code_biases.biases[80].value = 3495; + + test_msg.ssr_code_biases.iod_ssr = 132; + + test_msg.ssr_code_biases.n_biases = 81; + + test_msg.ssr_code_biases.sid.code = 241; + + test_msg.ssr_code_biases.sid.sat = 133; + + test_msg.ssr_code_biases.time.tow = 387144400; + + test_msg.ssr_code_biases.time.wn = 16905; + + test_msg.ssr_code_biases.update_interval = 254; + + sbp_message_send(&sbp_state, SbpMsgSsrCodeBiases, 22311, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 22311, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSsrCodeBiases, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[0].code == 51, + "incorrect value for last_msg.msg.ssr_code_biases.biases[0].code, " + "expected 51, is %d", + last_msg.msg.ssr_code_biases.biases[0].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[0].value == -31996, + "incorrect value for last_msg.msg.ssr_code_biases.biases[0].value, " + "expected -31996, is %d", + last_msg.msg.ssr_code_biases.biases[0].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[1].code == 240, + "incorrect value for last_msg.msg.ssr_code_biases.biases[1].code, " + "expected 240, is %d", + last_msg.msg.ssr_code_biases.biases[1].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[1].value == 21368, + "incorrect value for last_msg.msg.ssr_code_biases.biases[1].value, " + "expected 21368, is %d", + last_msg.msg.ssr_code_biases.biases[1].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[2].code == 148, + "incorrect value for last_msg.msg.ssr_code_biases.biases[2].code, " + "expected 148, is %d", + last_msg.msg.ssr_code_biases.biases[2].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[2].value == -10799, + "incorrect value for last_msg.msg.ssr_code_biases.biases[2].value, " + "expected -10799, is %d", + last_msg.msg.ssr_code_biases.biases[2].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[3].code == 62, + "incorrect value for last_msg.msg.ssr_code_biases.biases[3].code, " + "expected 62, is %d", + last_msg.msg.ssr_code_biases.biases[3].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[3].value == -5916, + "incorrect value for last_msg.msg.ssr_code_biases.biases[3].value, " + "expected -5916, is %d", + last_msg.msg.ssr_code_biases.biases[3].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[4].code == 71, + "incorrect value for last_msg.msg.ssr_code_biases.biases[4].code, " + "expected 71, is %d", + last_msg.msg.ssr_code_biases.biases[4].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[4].value == -17342, + "incorrect value for last_msg.msg.ssr_code_biases.biases[4].value, " + "expected -17342, is %d", + last_msg.msg.ssr_code_biases.biases[4].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[5].code == 210, + "incorrect value for last_msg.msg.ssr_code_biases.biases[5].code, " + "expected 210, is %d", + last_msg.msg.ssr_code_biases.biases[5].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[5].value == 13952, + "incorrect value for last_msg.msg.ssr_code_biases.biases[5].value, " + "expected 13952, is %d", + last_msg.msg.ssr_code_biases.biases[5].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[6].code == 131, + "incorrect value for last_msg.msg.ssr_code_biases.biases[6].code, " + "expected 131, is %d", + last_msg.msg.ssr_code_biases.biases[6].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[6].value == -32360, + "incorrect value for last_msg.msg.ssr_code_biases.biases[6].value, " + "expected -32360, is %d", + last_msg.msg.ssr_code_biases.biases[6].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[7].code == 111, + "incorrect value for last_msg.msg.ssr_code_biases.biases[7].code, " + "expected 111, is %d", + last_msg.msg.ssr_code_biases.biases[7].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[7].value == -3445, + "incorrect value for last_msg.msg.ssr_code_biases.biases[7].value, " + "expected -3445, is %d", + last_msg.msg.ssr_code_biases.biases[7].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[8].code == 177, + "incorrect value for last_msg.msg.ssr_code_biases.biases[8].code, " + "expected 177, is %d", + last_msg.msg.ssr_code_biases.biases[8].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[8].value == 11409, + "incorrect value for last_msg.msg.ssr_code_biases.biases[8].value, " + "expected 11409, is %d", + last_msg.msg.ssr_code_biases.biases[8].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[9].code == 9, + "incorrect value for last_msg.msg.ssr_code_biases.biases[9].code, " + "expected 9, is %d", + last_msg.msg.ssr_code_biases.biases[9].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[9].value == -12299, + "incorrect value for last_msg.msg.ssr_code_biases.biases[9].value, " + "expected -12299, is %d", + last_msg.msg.ssr_code_biases.biases[9].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[10].code == 241, + "incorrect value for last_msg.msg.ssr_code_biases.biases[10].code, " + "expected 241, is %d", + last_msg.msg.ssr_code_biases.biases[10].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[10].value == -26934, + "incorrect value for last_msg.msg.ssr_code_biases.biases[10].value, " + "expected -26934, is %d", + last_msg.msg.ssr_code_biases.biases[10].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[11].code == 141, + "incorrect value for last_msg.msg.ssr_code_biases.biases[11].code, " + "expected 141, is %d", + last_msg.msg.ssr_code_biases.biases[11].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[11].value == -24782, + "incorrect value for last_msg.msg.ssr_code_biases.biases[11].value, " + "expected -24782, is %d", + last_msg.msg.ssr_code_biases.biases[11].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[12].code == 220, + "incorrect value for last_msg.msg.ssr_code_biases.biases[12].code, " + "expected 220, is %d", + last_msg.msg.ssr_code_biases.biases[12].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[12].value == 9611, + "incorrect value for last_msg.msg.ssr_code_biases.biases[12].value, " + "expected 9611, is %d", + last_msg.msg.ssr_code_biases.biases[12].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[13].code == 187, + "incorrect value for last_msg.msg.ssr_code_biases.biases[13].code, " + "expected 187, is %d", + last_msg.msg.ssr_code_biases.biases[13].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[13].value == -16542, + "incorrect value for last_msg.msg.ssr_code_biases.biases[13].value, " + "expected -16542, is %d", + last_msg.msg.ssr_code_biases.biases[13].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[14].code == 23, + "incorrect value for last_msg.msg.ssr_code_biases.biases[14].code, " + "expected 23, is %d", + last_msg.msg.ssr_code_biases.biases[14].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[14].value == -30592, + "incorrect value for last_msg.msg.ssr_code_biases.biases[14].value, " + "expected -30592, is %d", + last_msg.msg.ssr_code_biases.biases[14].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[15].code == 167, + "incorrect value for last_msg.msg.ssr_code_biases.biases[15].code, " + "expected 167, is %d", + last_msg.msg.ssr_code_biases.biases[15].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[15].value == 1736, + "incorrect value for last_msg.msg.ssr_code_biases.biases[15].value, " + "expected 1736, is %d", + last_msg.msg.ssr_code_biases.biases[15].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[16].code == 211, + "incorrect value for last_msg.msg.ssr_code_biases.biases[16].code, " + "expected 211, is %d", + last_msg.msg.ssr_code_biases.biases[16].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[16].value == 5978, + "incorrect value for last_msg.msg.ssr_code_biases.biases[16].value, " + "expected 5978, is %d", + last_msg.msg.ssr_code_biases.biases[16].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[17].code == 244, + "incorrect value for last_msg.msg.ssr_code_biases.biases[17].code, " + "expected 244, is %d", + last_msg.msg.ssr_code_biases.biases[17].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[17].value == -10358, + "incorrect value for last_msg.msg.ssr_code_biases.biases[17].value, " + "expected -10358, is %d", + last_msg.msg.ssr_code_biases.biases[17].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[18].code == 209, + "incorrect value for last_msg.msg.ssr_code_biases.biases[18].code, " + "expected 209, is %d", + last_msg.msg.ssr_code_biases.biases[18].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[18].value == 3467, + "incorrect value for last_msg.msg.ssr_code_biases.biases[18].value, " + "expected 3467, is %d", + last_msg.msg.ssr_code_biases.biases[18].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[19].code == 101, + "incorrect value for last_msg.msg.ssr_code_biases.biases[19].code, " + "expected 101, is %d", + last_msg.msg.ssr_code_biases.biases[19].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[19].value == 1824, + "incorrect value for last_msg.msg.ssr_code_biases.biases[19].value, " + "expected 1824, is %d", + last_msg.msg.ssr_code_biases.biases[19].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[20].code == 18, + "incorrect value for last_msg.msg.ssr_code_biases.biases[20].code, " + "expected 18, is %d", + last_msg.msg.ssr_code_biases.biases[20].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[20].value == 17949, + "incorrect value for last_msg.msg.ssr_code_biases.biases[20].value, " + "expected 17949, is %d", + last_msg.msg.ssr_code_biases.biases[20].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[21].code == 250, + "incorrect value for last_msg.msg.ssr_code_biases.biases[21].code, " + "expected 250, is %d", + last_msg.msg.ssr_code_biases.biases[21].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[21].value == 18797, + "incorrect value for last_msg.msg.ssr_code_biases.biases[21].value, " + "expected 18797, is %d", + last_msg.msg.ssr_code_biases.biases[21].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[22].code == 202, + "incorrect value for last_msg.msg.ssr_code_biases.biases[22].code, " + "expected 202, is %d", + last_msg.msg.ssr_code_biases.biases[22].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[22].value == -28593, + "incorrect value for last_msg.msg.ssr_code_biases.biases[22].value, " + "expected -28593, is %d", + last_msg.msg.ssr_code_biases.biases[22].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[23].code == 9, + "incorrect value for last_msg.msg.ssr_code_biases.biases[23].code, " + "expected 9, is %d", + last_msg.msg.ssr_code_biases.biases[23].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[23].value == 17810, + "incorrect value for last_msg.msg.ssr_code_biases.biases[23].value, " + "expected 17810, is %d", + last_msg.msg.ssr_code_biases.biases[23].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[24].code == 241, + "incorrect value for last_msg.msg.ssr_code_biases.biases[24].code, " + "expected 241, is %d", + last_msg.msg.ssr_code_biases.biases[24].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[24].value == 5684, + "incorrect value for last_msg.msg.ssr_code_biases.biases[24].value, " + "expected 5684, is %d", + last_msg.msg.ssr_code_biases.biases[24].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[25].code == 99, + "incorrect value for last_msg.msg.ssr_code_biases.biases[25].code, " + "expected 99, is %d", + last_msg.msg.ssr_code_biases.biases[25].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[25].value == -13214, + "incorrect value for last_msg.msg.ssr_code_biases.biases[25].value, " + "expected -13214, is %d", + last_msg.msg.ssr_code_biases.biases[25].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[26].code == 3, + "incorrect value for last_msg.msg.ssr_code_biases.biases[26].code, " + "expected 3, is %d", + last_msg.msg.ssr_code_biases.biases[26].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[26].value == -6485, + "incorrect value for last_msg.msg.ssr_code_biases.biases[26].value, " + "expected -6485, is %d", + last_msg.msg.ssr_code_biases.biases[26].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[27].code == 180, + "incorrect value for last_msg.msg.ssr_code_biases.biases[27].code, " + "expected 180, is %d", + last_msg.msg.ssr_code_biases.biases[27].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[27].value == 15947, + "incorrect value for last_msg.msg.ssr_code_biases.biases[27].value, " + "expected 15947, is %d", + last_msg.msg.ssr_code_biases.biases[27].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[28].code == 145, + "incorrect value for last_msg.msg.ssr_code_biases.biases[28].code, " + "expected 145, is %d", + last_msg.msg.ssr_code_biases.biases[28].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[28].value == -32170, + "incorrect value for last_msg.msg.ssr_code_biases.biases[28].value, " + "expected -32170, is %d", + last_msg.msg.ssr_code_biases.biases[28].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[29].code == 31, + "incorrect value for last_msg.msg.ssr_code_biases.biases[29].code, " + "expected 31, is %d", + last_msg.msg.ssr_code_biases.biases[29].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[29].value == -25826, + "incorrect value for last_msg.msg.ssr_code_biases.biases[29].value, " + "expected -25826, is %d", + last_msg.msg.ssr_code_biases.biases[29].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[30].code == 37, + "incorrect value for last_msg.msg.ssr_code_biases.biases[30].code, " + "expected 37, is %d", + last_msg.msg.ssr_code_biases.biases[30].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[30].value == 14098, + "incorrect value for last_msg.msg.ssr_code_biases.biases[30].value, " + "expected 14098, is %d", + last_msg.msg.ssr_code_biases.biases[30].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[31].code == 210, + "incorrect value for last_msg.msg.ssr_code_biases.biases[31].code, " + "expected 210, is %d", + last_msg.msg.ssr_code_biases.biases[31].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[31].value == 32551, + "incorrect value for last_msg.msg.ssr_code_biases.biases[31].value, " + "expected 32551, is %d", + last_msg.msg.ssr_code_biases.biases[31].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[32].code == 242, + "incorrect value for last_msg.msg.ssr_code_biases.biases[32].code, " + "expected 242, is %d", + last_msg.msg.ssr_code_biases.biases[32].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[32].value == 3394, + "incorrect value for last_msg.msg.ssr_code_biases.biases[32].value, " + "expected 3394, is %d", + last_msg.msg.ssr_code_biases.biases[32].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[33].code == 237, + "incorrect value for last_msg.msg.ssr_code_biases.biases[33].code, " + "expected 237, is %d", + last_msg.msg.ssr_code_biases.biases[33].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[33].value == -21864, + "incorrect value for last_msg.msg.ssr_code_biases.biases[33].value, " + "expected -21864, is %d", + last_msg.msg.ssr_code_biases.biases[33].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[34].code == 212, + "incorrect value for last_msg.msg.ssr_code_biases.biases[34].code, " + "expected 212, is %d", + last_msg.msg.ssr_code_biases.biases[34].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[34].value == -2545, + "incorrect value for last_msg.msg.ssr_code_biases.biases[34].value, " + "expected -2545, is %d", + last_msg.msg.ssr_code_biases.biases[34].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[35].code == 59, + "incorrect value for last_msg.msg.ssr_code_biases.biases[35].code, " + "expected 59, is %d", + last_msg.msg.ssr_code_biases.biases[35].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[35].value == -19362, + "incorrect value for last_msg.msg.ssr_code_biases.biases[35].value, " + "expected -19362, is %d", + last_msg.msg.ssr_code_biases.biases[35].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[36].code == 195, + "incorrect value for last_msg.msg.ssr_code_biases.biases[36].code, " + "expected 195, is %d", + last_msg.msg.ssr_code_biases.biases[36].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[36].value == 17821, + "incorrect value for last_msg.msg.ssr_code_biases.biases[36].value, " + "expected 17821, is %d", + last_msg.msg.ssr_code_biases.biases[36].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[37].code == 100, + "incorrect value for last_msg.msg.ssr_code_biases.biases[37].code, " + "expected 100, is %d", + last_msg.msg.ssr_code_biases.biases[37].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[37].value == 4215, + "incorrect value for last_msg.msg.ssr_code_biases.biases[37].value, " + "expected 4215, is %d", + last_msg.msg.ssr_code_biases.biases[37].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[38].code == 68, + "incorrect value for last_msg.msg.ssr_code_biases.biases[38].code, " + "expected 68, is %d", + last_msg.msg.ssr_code_biases.biases[38].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[38].value == -20557, + "incorrect value for last_msg.msg.ssr_code_biases.biases[38].value, " + "expected -20557, is %d", + last_msg.msg.ssr_code_biases.biases[38].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[39].code == 144, + "incorrect value for last_msg.msg.ssr_code_biases.biases[39].code, " + "expected 144, is %d", + last_msg.msg.ssr_code_biases.biases[39].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[39].value == 20849, + "incorrect value for last_msg.msg.ssr_code_biases.biases[39].value, " + "expected 20849, is %d", + last_msg.msg.ssr_code_biases.biases[39].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[40].code == 82, + "incorrect value for last_msg.msg.ssr_code_biases.biases[40].code, " + "expected 82, is %d", + last_msg.msg.ssr_code_biases.biases[40].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[40].value == -26850, + "incorrect value for last_msg.msg.ssr_code_biases.biases[40].value, " + "expected -26850, is %d", + last_msg.msg.ssr_code_biases.biases[40].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[41].code == 21, + "incorrect value for last_msg.msg.ssr_code_biases.biases[41].code, " + "expected 21, is %d", + last_msg.msg.ssr_code_biases.biases[41].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[41].value == 10605, + "incorrect value for last_msg.msg.ssr_code_biases.biases[41].value, " + "expected 10605, is %d", + last_msg.msg.ssr_code_biases.biases[41].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[42].code == 225, + "incorrect value for last_msg.msg.ssr_code_biases.biases[42].code, " + "expected 225, is %d", + last_msg.msg.ssr_code_biases.biases[42].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[42].value == 19720, + "incorrect value for last_msg.msg.ssr_code_biases.biases[42].value, " + "expected 19720, is %d", + last_msg.msg.ssr_code_biases.biases[42].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[43].code == 164, + "incorrect value for last_msg.msg.ssr_code_biases.biases[43].code, " + "expected 164, is %d", + last_msg.msg.ssr_code_biases.biases[43].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[43].value == 157, + "incorrect value for last_msg.msg.ssr_code_biases.biases[43].value, " + "expected 157, is %d", + last_msg.msg.ssr_code_biases.biases[43].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[44].code == 73, + "incorrect value for last_msg.msg.ssr_code_biases.biases[44].code, " + "expected 73, is %d", + last_msg.msg.ssr_code_biases.biases[44].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[44].value == 1566, + "incorrect value for last_msg.msg.ssr_code_biases.biases[44].value, " + "expected 1566, is %d", + last_msg.msg.ssr_code_biases.biases[44].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[45].code == 78, + "incorrect value for last_msg.msg.ssr_code_biases.biases[45].code, " + "expected 78, is %d", + last_msg.msg.ssr_code_biases.biases[45].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[45].value == -28847, + "incorrect value for last_msg.msg.ssr_code_biases.biases[45].value, " + "expected -28847, is %d", + last_msg.msg.ssr_code_biases.biases[45].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[46].code == 116, + "incorrect value for last_msg.msg.ssr_code_biases.biases[46].code, " + "expected 116, is %d", + last_msg.msg.ssr_code_biases.biases[46].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[46].value == -26640, + "incorrect value for last_msg.msg.ssr_code_biases.biases[46].value, " + "expected -26640, is %d", + last_msg.msg.ssr_code_biases.biases[46].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[47].code == 55, + "incorrect value for last_msg.msg.ssr_code_biases.biases[47].code, " + "expected 55, is %d", + last_msg.msg.ssr_code_biases.biases[47].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[47].value == -22087, + "incorrect value for last_msg.msg.ssr_code_biases.biases[47].value, " + "expected -22087, is %d", + last_msg.msg.ssr_code_biases.biases[47].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[48].code == 254, + "incorrect value for last_msg.msg.ssr_code_biases.biases[48].code, " + "expected 254, is %d", + last_msg.msg.ssr_code_biases.biases[48].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[48].value == 10035, + "incorrect value for last_msg.msg.ssr_code_biases.biases[48].value, " + "expected 10035, is %d", + last_msg.msg.ssr_code_biases.biases[48].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[49].code == 74, + "incorrect value for last_msg.msg.ssr_code_biases.biases[49].code, " + "expected 74, is %d", + last_msg.msg.ssr_code_biases.biases[49].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[49].value == -2129, + "incorrect value for last_msg.msg.ssr_code_biases.biases[49].value, " + "expected -2129, is %d", + last_msg.msg.ssr_code_biases.biases[49].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[50].code == 34, + "incorrect value for last_msg.msg.ssr_code_biases.biases[50].code, " + "expected 34, is %d", + last_msg.msg.ssr_code_biases.biases[50].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[50].value == 19041, + "incorrect value for last_msg.msg.ssr_code_biases.biases[50].value, " + "expected 19041, is %d", + last_msg.msg.ssr_code_biases.biases[50].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[51].code == 97, + "incorrect value for last_msg.msg.ssr_code_biases.biases[51].code, " + "expected 97, is %d", + last_msg.msg.ssr_code_biases.biases[51].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[51].value == 12464, + "incorrect value for last_msg.msg.ssr_code_biases.biases[51].value, " + "expected 12464, is %d", + last_msg.msg.ssr_code_biases.biases[51].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[52].code == 236, + "incorrect value for last_msg.msg.ssr_code_biases.biases[52].code, " + "expected 236, is %d", + last_msg.msg.ssr_code_biases.biases[52].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[52].value == 3245, + "incorrect value for last_msg.msg.ssr_code_biases.biases[52].value, " + "expected 3245, is %d", + last_msg.msg.ssr_code_biases.biases[52].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[53].code == 174, + "incorrect value for last_msg.msg.ssr_code_biases.biases[53].code, " + "expected 174, is %d", + last_msg.msg.ssr_code_biases.biases[53].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[53].value == -32155, + "incorrect value for last_msg.msg.ssr_code_biases.biases[53].value, " + "expected -32155, is %d", + last_msg.msg.ssr_code_biases.biases[53].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[54].code == 30, + "incorrect value for last_msg.msg.ssr_code_biases.biases[54].code, " + "expected 30, is %d", + last_msg.msg.ssr_code_biases.biases[54].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[54].value == -15959, + "incorrect value for last_msg.msg.ssr_code_biases.biases[54].value, " + "expected -15959, is %d", + last_msg.msg.ssr_code_biases.biases[54].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[55].code == 190, + "incorrect value for last_msg.msg.ssr_code_biases.biases[55].code, " + "expected 190, is %d", + last_msg.msg.ssr_code_biases.biases[55].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[55].value == -15156, + "incorrect value for last_msg.msg.ssr_code_biases.biases[55].value, " + "expected -15156, is %d", + last_msg.msg.ssr_code_biases.biases[55].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[56].code == 123, + "incorrect value for last_msg.msg.ssr_code_biases.biases[56].code, " + "expected 123, is %d", + last_msg.msg.ssr_code_biases.biases[56].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[56].value == 6507, + "incorrect value for last_msg.msg.ssr_code_biases.biases[56].value, " + "expected 6507, is %d", + last_msg.msg.ssr_code_biases.biases[56].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[57].code == 225, + "incorrect value for last_msg.msg.ssr_code_biases.biases[57].code, " + "expected 225, is %d", + last_msg.msg.ssr_code_biases.biases[57].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[57].value == 2378, + "incorrect value for last_msg.msg.ssr_code_biases.biases[57].value, " + "expected 2378, is %d", + last_msg.msg.ssr_code_biases.biases[57].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[58].code == 10, + "incorrect value for last_msg.msg.ssr_code_biases.biases[58].code, " + "expected 10, is %d", + last_msg.msg.ssr_code_biases.biases[58].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[58].value == 823, + "incorrect value for last_msg.msg.ssr_code_biases.biases[58].value, " + "expected 823, is %d", + last_msg.msg.ssr_code_biases.biases[58].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[59].code == 131, + "incorrect value for last_msg.msg.ssr_code_biases.biases[59].code, " + "expected 131, is %d", + last_msg.msg.ssr_code_biases.biases[59].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[59].value == 25590, + "incorrect value for last_msg.msg.ssr_code_biases.biases[59].value, " + "expected 25590, is %d", + last_msg.msg.ssr_code_biases.biases[59].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[60].code == 133, + "incorrect value for last_msg.msg.ssr_code_biases.biases[60].code, " + "expected 133, is %d", + last_msg.msg.ssr_code_biases.biases[60].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[60].value == -7390, + "incorrect value for last_msg.msg.ssr_code_biases.biases[60].value, " + "expected -7390, is %d", + last_msg.msg.ssr_code_biases.biases[60].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[61].code == 203, + "incorrect value for last_msg.msg.ssr_code_biases.biases[61].code, " + "expected 203, is %d", + last_msg.msg.ssr_code_biases.biases[61].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[61].value == 4676, + "incorrect value for last_msg.msg.ssr_code_biases.biases[61].value, " + "expected 4676, is %d", + last_msg.msg.ssr_code_biases.biases[61].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[62].code == 97, + "incorrect value for last_msg.msg.ssr_code_biases.biases[62].code, " + "expected 97, is %d", + last_msg.msg.ssr_code_biases.biases[62].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[62].value == 23007, + "incorrect value for last_msg.msg.ssr_code_biases.biases[62].value, " + "expected 23007, is %d", + last_msg.msg.ssr_code_biases.biases[62].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[63].code == 192, + "incorrect value for last_msg.msg.ssr_code_biases.biases[63].code, " + "expected 192, is %d", + last_msg.msg.ssr_code_biases.biases[63].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[63].value == 13046, + "incorrect value for last_msg.msg.ssr_code_biases.biases[63].value, " + "expected 13046, is %d", + last_msg.msg.ssr_code_biases.biases[63].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[64].code == 69, + "incorrect value for last_msg.msg.ssr_code_biases.biases[64].code, " + "expected 69, is %d", + last_msg.msg.ssr_code_biases.biases[64].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[64].value == 2651, + "incorrect value for last_msg.msg.ssr_code_biases.biases[64].value, " + "expected 2651, is %d", + last_msg.msg.ssr_code_biases.biases[64].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[65].code == 151, + "incorrect value for last_msg.msg.ssr_code_biases.biases[65].code, " + "expected 151, is %d", + last_msg.msg.ssr_code_biases.biases[65].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[65].value == 30282, + "incorrect value for last_msg.msg.ssr_code_biases.biases[65].value, " + "expected 30282, is %d", + last_msg.msg.ssr_code_biases.biases[65].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[66].code == 110, + "incorrect value for last_msg.msg.ssr_code_biases.biases[66].code, " + "expected 110, is %d", + last_msg.msg.ssr_code_biases.biases[66].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[66].value == -22492, + "incorrect value for last_msg.msg.ssr_code_biases.biases[66].value, " + "expected -22492, is %d", + last_msg.msg.ssr_code_biases.biases[66].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[67].code == 247, + "incorrect value for last_msg.msg.ssr_code_biases.biases[67].code, " + "expected 247, is %d", + last_msg.msg.ssr_code_biases.biases[67].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[67].value == 19872, + "incorrect value for last_msg.msg.ssr_code_biases.biases[67].value, " + "expected 19872, is %d", + last_msg.msg.ssr_code_biases.biases[67].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[68].code == 179, + "incorrect value for last_msg.msg.ssr_code_biases.biases[68].code, " + "expected 179, is %d", + last_msg.msg.ssr_code_biases.biases[68].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[68].value == -19827, + "incorrect value for last_msg.msg.ssr_code_biases.biases[68].value, " + "expected -19827, is %d", + last_msg.msg.ssr_code_biases.biases[68].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[69].code == 99, + "incorrect value for last_msg.msg.ssr_code_biases.biases[69].code, " + "expected 99, is %d", + last_msg.msg.ssr_code_biases.biases[69].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[69].value == 30911, + "incorrect value for last_msg.msg.ssr_code_biases.biases[69].value, " + "expected 30911, is %d", + last_msg.msg.ssr_code_biases.biases[69].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[70].code == 77, + "incorrect value for last_msg.msg.ssr_code_biases.biases[70].code, " + "expected 77, is %d", + last_msg.msg.ssr_code_biases.biases[70].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[70].value == 23488, + "incorrect value for last_msg.msg.ssr_code_biases.biases[70].value, " + "expected 23488, is %d", + last_msg.msg.ssr_code_biases.biases[70].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[71].code == 224, + "incorrect value for last_msg.msg.ssr_code_biases.biases[71].code, " + "expected 224, is %d", + last_msg.msg.ssr_code_biases.biases[71].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[71].value == -7679, + "incorrect value for last_msg.msg.ssr_code_biases.biases[71].value, " + "expected -7679, is %d", + last_msg.msg.ssr_code_biases.biases[71].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[72].code == 50, + "incorrect value for last_msg.msg.ssr_code_biases.biases[72].code, " + "expected 50, is %d", + last_msg.msg.ssr_code_biases.biases[72].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[72].value == -28073, + "incorrect value for last_msg.msg.ssr_code_biases.biases[72].value, " + "expected -28073, is %d", + last_msg.msg.ssr_code_biases.biases[72].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[73].code == 148, + "incorrect value for last_msg.msg.ssr_code_biases.biases[73].code, " + "expected 148, is %d", + last_msg.msg.ssr_code_biases.biases[73].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[73].value == 25838, + "incorrect value for last_msg.msg.ssr_code_biases.biases[73].value, " + "expected 25838, is %d", + last_msg.msg.ssr_code_biases.biases[73].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[74].code == 179, + "incorrect value for last_msg.msg.ssr_code_biases.biases[74].code, " + "expected 179, is %d", + last_msg.msg.ssr_code_biases.biases[74].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[74].value == -7299, + "incorrect value for last_msg.msg.ssr_code_biases.biases[74].value, " + "expected -7299, is %d", + last_msg.msg.ssr_code_biases.biases[74].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[75].code == 215, + "incorrect value for last_msg.msg.ssr_code_biases.biases[75].code, " + "expected 215, is %d", + last_msg.msg.ssr_code_biases.biases[75].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[75].value == -18328, + "incorrect value for last_msg.msg.ssr_code_biases.biases[75].value, " + "expected -18328, is %d", + last_msg.msg.ssr_code_biases.biases[75].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[76].code == 31, + "incorrect value for last_msg.msg.ssr_code_biases.biases[76].code, " + "expected 31, is %d", + last_msg.msg.ssr_code_biases.biases[76].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[76].value == 23097, + "incorrect value for last_msg.msg.ssr_code_biases.biases[76].value, " + "expected 23097, is %d", + last_msg.msg.ssr_code_biases.biases[76].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[77].code == 79, + "incorrect value for last_msg.msg.ssr_code_biases.biases[77].code, " + "expected 79, is %d", + last_msg.msg.ssr_code_biases.biases[77].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[77].value == -25579, + "incorrect value for last_msg.msg.ssr_code_biases.biases[77].value, " + "expected -25579, is %d", + last_msg.msg.ssr_code_biases.biases[77].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[78].code == 245, + "incorrect value for last_msg.msg.ssr_code_biases.biases[78].code, " + "expected 245, is %d", + last_msg.msg.ssr_code_biases.biases[78].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[78].value == 15441, + "incorrect value for last_msg.msg.ssr_code_biases.biases[78].value, " + "expected 15441, is %d", + last_msg.msg.ssr_code_biases.biases[78].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[79].code == 93, + "incorrect value for last_msg.msg.ssr_code_biases.biases[79].code, " + "expected 93, is %d", + last_msg.msg.ssr_code_biases.biases[79].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[79].value == 15530, + "incorrect value for last_msg.msg.ssr_code_biases.biases[79].value, " + "expected 15530, is %d", + last_msg.msg.ssr_code_biases.biases[79].value); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[80].code == 200, + "incorrect value for last_msg.msg.ssr_code_biases.biases[80].code, " + "expected 200, is %d", + last_msg.msg.ssr_code_biases.biases[80].code); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.biases[80].value == 3495, + "incorrect value for last_msg.msg.ssr_code_biases.biases[80].value, " + "expected 3495, is %d", + last_msg.msg.ssr_code_biases.biases[80].value); + + ck_assert_msg(last_msg.msg.ssr_code_biases.iod_ssr == 132, + "incorrect value for last_msg.msg.ssr_code_biases.iod_ssr, " + "expected 132, is %d", + last_msg.msg.ssr_code_biases.iod_ssr); + + ck_assert_msg(last_msg.msg.ssr_code_biases.n_biases == 81, + "incorrect value for last_msg.msg.ssr_code_biases.n_biases, " + "expected 81, is %d", + last_msg.msg.ssr_code_biases.n_biases); + + ck_assert_msg(last_msg.msg.ssr_code_biases.sid.code == 241, + "incorrect value for last_msg.msg.ssr_code_biases.sid.code, " + "expected 241, is %d", + last_msg.msg.ssr_code_biases.sid.code); + + ck_assert_msg(last_msg.msg.ssr_code_biases.sid.sat == 133, + "incorrect value for last_msg.msg.ssr_code_biases.sid.sat, " + "expected 133, is %d", + last_msg.msg.ssr_code_biases.sid.sat); + + ck_assert_msg(last_msg.msg.ssr_code_biases.time.tow == 387144400, + "incorrect value for last_msg.msg.ssr_code_biases.time.tow, " + "expected 387144400, is %d", + last_msg.msg.ssr_code_biases.time.tow); + + ck_assert_msg(last_msg.msg.ssr_code_biases.time.wn == 16905, + "incorrect value for last_msg.msg.ssr_code_biases.time.wn, " + "expected 16905, is %d", + last_msg.msg.ssr_code_biases.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_code_biases.update_interval == 254, + "incorrect value for last_msg.msg.ssr_code_biases.update_interval, " + "expected 254, is %d", + last_msg.msg.ssr_code_biases.update_interval); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrCodeBiases_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrCodeBiases"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ssr_MsgSsrCodeBiases"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrCodeBiases); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c new file mode 100644 index 0000000000..196b28519b --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c @@ -0,0 +1,1943 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5f5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, + 52, 92, 104, 25, 204, 182, 22, 98, 203, 123, 211, 38, 13, 253, + 129, 173, 171, 235, 253, 26, 203, 3, 120, 126, 42, 44, 39, 87, + 69, 154, 13, 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, + 57, 120, 243, 151, 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, + 144, 158, 239, 90, 56, 71, 120, 67, 221, 114, 10, 190, 4, 230, + 164, 171, 78, 185, 90, 46, 177, 82, 228, 123, 222, 227, 145, 195, + 219, 27, 56, 227, 246, 215, 144, 158, 31, 214, 241, 254, 200, 86, + 142, 89, 12, 121, 29, 124, 9, 19, 153, 44, 35, 126, 14, 217, + 65, 116, 26, 139, 122, 114, 90, 124, 81, 0, 186, 246, 46, 98, + 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, 42, 150, 221, 102, + 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, 128, 193, 53, + 94, 99, 63, 182, 2, 186, 220, 77, 186, 224, 220, 13, 212, 182, + 88, 15, 151, 5, 93, 251, 164, 18, 228, 168, 226, 195, 44, 170, + 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, 159, 189, + 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, + 19, 151, 136, 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, + 212, 68, 60, 206, 106, 207, 243, 158, 94, 6, 3, 205, 92, 84, + 2, 220, 50, 61, 38, 141, 117, 108, 101, 76, 139, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_grid_definition_dep_a.header.area_width = 43860; + + test_msg.ssr_grid_definition_dep_a.header.lat_nw_corner_enc = 34021; + + test_msg.ssr_grid_definition_dep_a.header.lon_nw_corner_enc = 11919; + + test_msg.ssr_grid_definition_dep_a.header.num_msgs = 204; + + test_msg.ssr_grid_definition_dep_a.header.region_size_inverse = 11; + + test_msg.ssr_grid_definition_dep_a.header.seq_num = 52; + + test_msg.ssr_grid_definition_dep_a.n_rle_list = 246; + + test_msg.ssr_grid_definition_dep_a.rle_list[0] = 92; + + test_msg.ssr_grid_definition_dep_a.rle_list[1] = 104; + + test_msg.ssr_grid_definition_dep_a.rle_list[2] = 25; + + test_msg.ssr_grid_definition_dep_a.rle_list[3] = 204; + + test_msg.ssr_grid_definition_dep_a.rle_list[4] = 182; + + test_msg.ssr_grid_definition_dep_a.rle_list[5] = 22; + + test_msg.ssr_grid_definition_dep_a.rle_list[6] = 98; + + test_msg.ssr_grid_definition_dep_a.rle_list[7] = 203; + + test_msg.ssr_grid_definition_dep_a.rle_list[8] = 123; + + test_msg.ssr_grid_definition_dep_a.rle_list[9] = 211; + + test_msg.ssr_grid_definition_dep_a.rle_list[10] = 38; + + test_msg.ssr_grid_definition_dep_a.rle_list[11] = 13; + + test_msg.ssr_grid_definition_dep_a.rle_list[12] = 253; + + test_msg.ssr_grid_definition_dep_a.rle_list[13] = 129; + + test_msg.ssr_grid_definition_dep_a.rle_list[14] = 173; + + test_msg.ssr_grid_definition_dep_a.rle_list[15] = 171; + + test_msg.ssr_grid_definition_dep_a.rle_list[16] = 235; + + test_msg.ssr_grid_definition_dep_a.rle_list[17] = 253; + + test_msg.ssr_grid_definition_dep_a.rle_list[18] = 26; + + test_msg.ssr_grid_definition_dep_a.rle_list[19] = 203; + + test_msg.ssr_grid_definition_dep_a.rle_list[20] = 3; + + test_msg.ssr_grid_definition_dep_a.rle_list[21] = 120; + + test_msg.ssr_grid_definition_dep_a.rle_list[22] = 126; + + test_msg.ssr_grid_definition_dep_a.rle_list[23] = 42; + + test_msg.ssr_grid_definition_dep_a.rle_list[24] = 44; + + test_msg.ssr_grid_definition_dep_a.rle_list[25] = 39; + + test_msg.ssr_grid_definition_dep_a.rle_list[26] = 87; + + test_msg.ssr_grid_definition_dep_a.rle_list[27] = 69; + + test_msg.ssr_grid_definition_dep_a.rle_list[28] = 154; + + test_msg.ssr_grid_definition_dep_a.rle_list[29] = 13; + + test_msg.ssr_grid_definition_dep_a.rle_list[30] = 28; + + test_msg.ssr_grid_definition_dep_a.rle_list[31] = 179; + + test_msg.ssr_grid_definition_dep_a.rle_list[32] = 32; + + test_msg.ssr_grid_definition_dep_a.rle_list[33] = 47; + + test_msg.ssr_grid_definition_dep_a.rle_list[34] = 36; + + test_msg.ssr_grid_definition_dep_a.rle_list[35] = 195; + + test_msg.ssr_grid_definition_dep_a.rle_list[36] = 39; + + test_msg.ssr_grid_definition_dep_a.rle_list[37] = 198; + + test_msg.ssr_grid_definition_dep_a.rle_list[38] = 134; + + test_msg.ssr_grid_definition_dep_a.rle_list[39] = 235; + + test_msg.ssr_grid_definition_dep_a.rle_list[40] = 134; + + test_msg.ssr_grid_definition_dep_a.rle_list[41] = 57; + + test_msg.ssr_grid_definition_dep_a.rle_list[42] = 120; + + test_msg.ssr_grid_definition_dep_a.rle_list[43] = 243; + + test_msg.ssr_grid_definition_dep_a.rle_list[44] = 151; + + test_msg.ssr_grid_definition_dep_a.rle_list[45] = 35; + + test_msg.ssr_grid_definition_dep_a.rle_list[46] = 17; + + test_msg.ssr_grid_definition_dep_a.rle_list[47] = 201; + + test_msg.ssr_grid_definition_dep_a.rle_list[48] = 211; + + test_msg.ssr_grid_definition_dep_a.rle_list[49] = 125; + + test_msg.ssr_grid_definition_dep_a.rle_list[50] = 117; + + test_msg.ssr_grid_definition_dep_a.rle_list[51] = 164; + + test_msg.ssr_grid_definition_dep_a.rle_list[52] = 142; + + test_msg.ssr_grid_definition_dep_a.rle_list[53] = 101; + + test_msg.ssr_grid_definition_dep_a.rle_list[54] = 239; + + test_msg.ssr_grid_definition_dep_a.rle_list[55] = 144; + + test_msg.ssr_grid_definition_dep_a.rle_list[56] = 158; + + test_msg.ssr_grid_definition_dep_a.rle_list[57] = 239; + + test_msg.ssr_grid_definition_dep_a.rle_list[58] = 90; + + test_msg.ssr_grid_definition_dep_a.rle_list[59] = 56; + + test_msg.ssr_grid_definition_dep_a.rle_list[60] = 71; + + test_msg.ssr_grid_definition_dep_a.rle_list[61] = 120; + + test_msg.ssr_grid_definition_dep_a.rle_list[62] = 67; + + test_msg.ssr_grid_definition_dep_a.rle_list[63] = 221; + + test_msg.ssr_grid_definition_dep_a.rle_list[64] = 114; + + test_msg.ssr_grid_definition_dep_a.rle_list[65] = 10; + + test_msg.ssr_grid_definition_dep_a.rle_list[66] = 190; + + test_msg.ssr_grid_definition_dep_a.rle_list[67] = 4; + + test_msg.ssr_grid_definition_dep_a.rle_list[68] = 230; + + test_msg.ssr_grid_definition_dep_a.rle_list[69] = 164; + + test_msg.ssr_grid_definition_dep_a.rle_list[70] = 171; + + test_msg.ssr_grid_definition_dep_a.rle_list[71] = 78; + + test_msg.ssr_grid_definition_dep_a.rle_list[72] = 185; + + test_msg.ssr_grid_definition_dep_a.rle_list[73] = 90; + + test_msg.ssr_grid_definition_dep_a.rle_list[74] = 46; + + test_msg.ssr_grid_definition_dep_a.rle_list[75] = 177; + + test_msg.ssr_grid_definition_dep_a.rle_list[76] = 82; + + test_msg.ssr_grid_definition_dep_a.rle_list[77] = 228; + + test_msg.ssr_grid_definition_dep_a.rle_list[78] = 123; + + test_msg.ssr_grid_definition_dep_a.rle_list[79] = 222; + + test_msg.ssr_grid_definition_dep_a.rle_list[80] = 227; + + test_msg.ssr_grid_definition_dep_a.rle_list[81] = 145; + + test_msg.ssr_grid_definition_dep_a.rle_list[82] = 195; + + test_msg.ssr_grid_definition_dep_a.rle_list[83] = 219; + + test_msg.ssr_grid_definition_dep_a.rle_list[84] = 27; + + test_msg.ssr_grid_definition_dep_a.rle_list[85] = 56; + + test_msg.ssr_grid_definition_dep_a.rle_list[86] = 227; + + test_msg.ssr_grid_definition_dep_a.rle_list[87] = 246; + + test_msg.ssr_grid_definition_dep_a.rle_list[88] = 215; + + test_msg.ssr_grid_definition_dep_a.rle_list[89] = 144; + + test_msg.ssr_grid_definition_dep_a.rle_list[90] = 158; + + test_msg.ssr_grid_definition_dep_a.rle_list[91] = 31; + + test_msg.ssr_grid_definition_dep_a.rle_list[92] = 214; + + test_msg.ssr_grid_definition_dep_a.rle_list[93] = 241; + + test_msg.ssr_grid_definition_dep_a.rle_list[94] = 254; + + test_msg.ssr_grid_definition_dep_a.rle_list[95] = 200; + + test_msg.ssr_grid_definition_dep_a.rle_list[96] = 86; + + test_msg.ssr_grid_definition_dep_a.rle_list[97] = 142; + + test_msg.ssr_grid_definition_dep_a.rle_list[98] = 89; + + test_msg.ssr_grid_definition_dep_a.rle_list[99] = 12; + + test_msg.ssr_grid_definition_dep_a.rle_list[100] = 121; + + test_msg.ssr_grid_definition_dep_a.rle_list[101] = 29; + + test_msg.ssr_grid_definition_dep_a.rle_list[102] = 124; + + test_msg.ssr_grid_definition_dep_a.rle_list[103] = 9; + + test_msg.ssr_grid_definition_dep_a.rle_list[104] = 19; + + test_msg.ssr_grid_definition_dep_a.rle_list[105] = 153; + + test_msg.ssr_grid_definition_dep_a.rle_list[106] = 44; + + test_msg.ssr_grid_definition_dep_a.rle_list[107] = 35; + + test_msg.ssr_grid_definition_dep_a.rle_list[108] = 126; + + test_msg.ssr_grid_definition_dep_a.rle_list[109] = 14; + + test_msg.ssr_grid_definition_dep_a.rle_list[110] = 217; + + test_msg.ssr_grid_definition_dep_a.rle_list[111] = 65; + + test_msg.ssr_grid_definition_dep_a.rle_list[112] = 116; + + test_msg.ssr_grid_definition_dep_a.rle_list[113] = 26; + + test_msg.ssr_grid_definition_dep_a.rle_list[114] = 139; + + test_msg.ssr_grid_definition_dep_a.rle_list[115] = 122; + + test_msg.ssr_grid_definition_dep_a.rle_list[116] = 114; + + test_msg.ssr_grid_definition_dep_a.rle_list[117] = 90; + + test_msg.ssr_grid_definition_dep_a.rle_list[118] = 124; + + test_msg.ssr_grid_definition_dep_a.rle_list[119] = 81; + + test_msg.ssr_grid_definition_dep_a.rle_list[120] = 0; + + test_msg.ssr_grid_definition_dep_a.rle_list[121] = 186; + + test_msg.ssr_grid_definition_dep_a.rle_list[122] = 246; + + test_msg.ssr_grid_definition_dep_a.rle_list[123] = 46; + + test_msg.ssr_grid_definition_dep_a.rle_list[124] = 98; + + test_msg.ssr_grid_definition_dep_a.rle_list[125] = 179; + + test_msg.ssr_grid_definition_dep_a.rle_list[126] = 243; + + test_msg.ssr_grid_definition_dep_a.rle_list[127] = 198; + + test_msg.ssr_grid_definition_dep_a.rle_list[128] = 217; + + test_msg.ssr_grid_definition_dep_a.rle_list[129] = 36; + + test_msg.ssr_grid_definition_dep_a.rle_list[130] = 30; + + test_msg.ssr_grid_definition_dep_a.rle_list[131] = 202; + + test_msg.ssr_grid_definition_dep_a.rle_list[132] = 12; + + test_msg.ssr_grid_definition_dep_a.rle_list[133] = 135; + + test_msg.ssr_grid_definition_dep_a.rle_list[134] = 61; + + test_msg.ssr_grid_definition_dep_a.rle_list[135] = 42; + + test_msg.ssr_grid_definition_dep_a.rle_list[136] = 150; + + test_msg.ssr_grid_definition_dep_a.rle_list[137] = 221; + + test_msg.ssr_grid_definition_dep_a.rle_list[138] = 102; + + test_msg.ssr_grid_definition_dep_a.rle_list[139] = 83; + + test_msg.ssr_grid_definition_dep_a.rle_list[140] = 179; + + test_msg.ssr_grid_definition_dep_a.rle_list[141] = 43; + + test_msg.ssr_grid_definition_dep_a.rle_list[142] = 252; + + test_msg.ssr_grid_definition_dep_a.rle_list[143] = 81; + + test_msg.ssr_grid_definition_dep_a.rle_list[144] = 62; + + test_msg.ssr_grid_definition_dep_a.rle_list[145] = 126; + + test_msg.ssr_grid_definition_dep_a.rle_list[146] = 204; + + test_msg.ssr_grid_definition_dep_a.rle_list[147] = 195; + + test_msg.ssr_grid_definition_dep_a.rle_list[148] = 238; + + test_msg.ssr_grid_definition_dep_a.rle_list[149] = 18; + + test_msg.ssr_grid_definition_dep_a.rle_list[150] = 128; + + test_msg.ssr_grid_definition_dep_a.rle_list[151] = 193; + + test_msg.ssr_grid_definition_dep_a.rle_list[152] = 53; + + test_msg.ssr_grid_definition_dep_a.rle_list[153] = 94; + + test_msg.ssr_grid_definition_dep_a.rle_list[154] = 99; + + test_msg.ssr_grid_definition_dep_a.rle_list[155] = 63; + + test_msg.ssr_grid_definition_dep_a.rle_list[156] = 182; + + test_msg.ssr_grid_definition_dep_a.rle_list[157] = 2; + + test_msg.ssr_grid_definition_dep_a.rle_list[158] = 186; + + test_msg.ssr_grid_definition_dep_a.rle_list[159] = 220; + + test_msg.ssr_grid_definition_dep_a.rle_list[160] = 77; + + test_msg.ssr_grid_definition_dep_a.rle_list[161] = 186; + + test_msg.ssr_grid_definition_dep_a.rle_list[162] = 224; + + test_msg.ssr_grid_definition_dep_a.rle_list[163] = 220; + + test_msg.ssr_grid_definition_dep_a.rle_list[164] = 13; + + test_msg.ssr_grid_definition_dep_a.rle_list[165] = 212; + + test_msg.ssr_grid_definition_dep_a.rle_list[166] = 182; + + test_msg.ssr_grid_definition_dep_a.rle_list[167] = 88; + + test_msg.ssr_grid_definition_dep_a.rle_list[168] = 15; + + test_msg.ssr_grid_definition_dep_a.rle_list[169] = 151; + + test_msg.ssr_grid_definition_dep_a.rle_list[170] = 5; + + test_msg.ssr_grid_definition_dep_a.rle_list[171] = 93; + + test_msg.ssr_grid_definition_dep_a.rle_list[172] = 251; + + test_msg.ssr_grid_definition_dep_a.rle_list[173] = 164; + + test_msg.ssr_grid_definition_dep_a.rle_list[174] = 18; + + test_msg.ssr_grid_definition_dep_a.rle_list[175] = 228; + + test_msg.ssr_grid_definition_dep_a.rle_list[176] = 168; + + test_msg.ssr_grid_definition_dep_a.rle_list[177] = 226; + + test_msg.ssr_grid_definition_dep_a.rle_list[178] = 195; + + test_msg.ssr_grid_definition_dep_a.rle_list[179] = 44; + + test_msg.ssr_grid_definition_dep_a.rle_list[180] = 170; + + test_msg.ssr_grid_definition_dep_a.rle_list[181] = 145; + + test_msg.ssr_grid_definition_dep_a.rle_list[182] = 36; + + test_msg.ssr_grid_definition_dep_a.rle_list[183] = 58; + + test_msg.ssr_grid_definition_dep_a.rle_list[184] = 96; + + test_msg.ssr_grid_definition_dep_a.rle_list[185] = 107; + + test_msg.ssr_grid_definition_dep_a.rle_list[186] = 144; + + test_msg.ssr_grid_definition_dep_a.rle_list[187] = 11; + + test_msg.ssr_grid_definition_dep_a.rle_list[188] = 228; + + test_msg.ssr_grid_definition_dep_a.rle_list[189] = 12; + + test_msg.ssr_grid_definition_dep_a.rle_list[190] = 163; + + test_msg.ssr_grid_definition_dep_a.rle_list[191] = 238; + + test_msg.ssr_grid_definition_dep_a.rle_list[192] = 247; + + test_msg.ssr_grid_definition_dep_a.rle_list[193] = 159; + + test_msg.ssr_grid_definition_dep_a.rle_list[194] = 189; + + test_msg.ssr_grid_definition_dep_a.rle_list[195] = 1; + + test_msg.ssr_grid_definition_dep_a.rle_list[196] = 115; + + test_msg.ssr_grid_definition_dep_a.rle_list[197] = 65; + + test_msg.ssr_grid_definition_dep_a.rle_list[198] = 202; + + test_msg.ssr_grid_definition_dep_a.rle_list[199] = 121; + + test_msg.ssr_grid_definition_dep_a.rle_list[200] = 47; + + test_msg.ssr_grid_definition_dep_a.rle_list[201] = 193; + + test_msg.ssr_grid_definition_dep_a.rle_list[202] = 11; + + test_msg.ssr_grid_definition_dep_a.rle_list[203] = 96; + + test_msg.ssr_grid_definition_dep_a.rle_list[204] = 93; + + test_msg.ssr_grid_definition_dep_a.rle_list[205] = 72; + + test_msg.ssr_grid_definition_dep_a.rle_list[206] = 81; + + test_msg.ssr_grid_definition_dep_a.rle_list[207] = 207; + + test_msg.ssr_grid_definition_dep_a.rle_list[208] = 121; + + test_msg.ssr_grid_definition_dep_a.rle_list[209] = 19; + + test_msg.ssr_grid_definition_dep_a.rle_list[210] = 151; + + test_msg.ssr_grid_definition_dep_a.rle_list[211] = 136; + + test_msg.ssr_grid_definition_dep_a.rle_list[212] = 233; + + test_msg.ssr_grid_definition_dep_a.rle_list[213] = 51; + + test_msg.ssr_grid_definition_dep_a.rle_list[214] = 133; + + test_msg.ssr_grid_definition_dep_a.rle_list[215] = 195; + + test_msg.ssr_grid_definition_dep_a.rle_list[216] = 77; + + test_msg.ssr_grid_definition_dep_a.rle_list[217] = 44; + + test_msg.ssr_grid_definition_dep_a.rle_list[218] = 147; + + test_msg.ssr_grid_definition_dep_a.rle_list[219] = 206; + + test_msg.ssr_grid_definition_dep_a.rle_list[220] = 120; + + test_msg.ssr_grid_definition_dep_a.rle_list[221] = 252; + + test_msg.ssr_grid_definition_dep_a.rle_list[222] = 77; + + test_msg.ssr_grid_definition_dep_a.rle_list[223] = 212; + + test_msg.ssr_grid_definition_dep_a.rle_list[224] = 68; + + test_msg.ssr_grid_definition_dep_a.rle_list[225] = 60; + + test_msg.ssr_grid_definition_dep_a.rle_list[226] = 206; + + test_msg.ssr_grid_definition_dep_a.rle_list[227] = 106; + + test_msg.ssr_grid_definition_dep_a.rle_list[228] = 207; + + test_msg.ssr_grid_definition_dep_a.rle_list[229] = 243; + + test_msg.ssr_grid_definition_dep_a.rle_list[230] = 158; + + test_msg.ssr_grid_definition_dep_a.rle_list[231] = 94; + + test_msg.ssr_grid_definition_dep_a.rle_list[232] = 6; + + test_msg.ssr_grid_definition_dep_a.rle_list[233] = 3; + + test_msg.ssr_grid_definition_dep_a.rle_list[234] = 205; + + test_msg.ssr_grid_definition_dep_a.rle_list[235] = 92; + + test_msg.ssr_grid_definition_dep_a.rle_list[236] = 84; + + test_msg.ssr_grid_definition_dep_a.rle_list[237] = 2; + + test_msg.ssr_grid_definition_dep_a.rle_list[238] = 220; + + test_msg.ssr_grid_definition_dep_a.rle_list[239] = 50; + + test_msg.ssr_grid_definition_dep_a.rle_list[240] = 61; + + test_msg.ssr_grid_definition_dep_a.rle_list[241] = 38; + + test_msg.ssr_grid_definition_dep_a.rle_list[242] = 141; + + test_msg.ssr_grid_definition_dep_a.rle_list[243] = 117; + + test_msg.ssr_grid_definition_dep_a.rle_list[244] = 108; + + test_msg.ssr_grid_definition_dep_a.rle_list[245] = 101; + + sbp_message_send(&sbp_state, SbpMsgSsrGridDefinitionDepA, 63413, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63413, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrGridDefinitionDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_grid_definition_dep_a.header.area_width == 43860, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.area_width, expected " + "43860, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.area_width); + + ck_assert_msg( + last_msg.msg.ssr_grid_definition_dep_a.header.lat_nw_corner_enc == + 34021, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.lat_nw_corner_enc, " + "expected 34021, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.lat_nw_corner_enc); + + ck_assert_msg( + last_msg.msg.ssr_grid_definition_dep_a.header.lon_nw_corner_enc == + 11919, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.lon_nw_corner_enc, " + "expected 11919, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.lon_nw_corner_enc); + + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.header.num_msgs == 204, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.num_msgs, " + "expected 204, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.num_msgs); + + ck_assert_msg( + last_msg.msg.ssr_grid_definition_dep_a.header.region_size_inverse == 11, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.region_size_inverse, " + "expected 11, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.region_size_inverse); + + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.header.seq_num == 52, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.header.seq_num, " + "expected 52, is %d", + last_msg.msg.ssr_grid_definition_dep_a.header.seq_num); + + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.n_rle_list == 246, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.n_rle_list, expected " + "246, is %d", + last_msg.msg.ssr_grid_definition_dep_a.n_rle_list); + + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[0] == 92, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[0], " + "expected 92, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[0]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[1] == 104, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[1], " + "expected 104, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[1]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[2] == 25, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[2], " + "expected 25, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[2]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[3] == 204, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[3], " + "expected 204, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[3]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[4] == 182, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[4], " + "expected 182, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[4]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[5] == 22, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[5], " + "expected 22, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[5]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[6] == 98, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[6], " + "expected 98, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[6]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[7] == 203, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[7], " + "expected 203, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[7]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[8] == 123, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[8], " + "expected 123, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[8]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[9] == 211, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[9], " + "expected 211, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[9]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[10] == 38, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[10], " + "expected 38, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[10]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[11] == 13, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[11], " + "expected 13, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[11]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[12] == 253, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[12], " + "expected 253, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[12]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[13] == 129, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[13], " + "expected 129, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[13]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[14] == 173, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[14], " + "expected 173, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[14]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[15] == 171, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[15], " + "expected 171, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[15]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[16] == 235, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[16], " + "expected 235, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[16]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[17] == 253, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[17], " + "expected 253, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[17]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[18] == 26, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[18], " + "expected 26, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[18]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[19] == 203, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[19], " + "expected 203, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[19]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[20] == 3, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[20], " + "expected 3, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[20]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[21] == 120, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[21], " + "expected 120, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[21]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[22] == 126, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[22], " + "expected 126, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[22]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[23] == 42, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[23], " + "expected 42, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[23]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[24] == 44, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[24], " + "expected 44, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[24]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[25] == 39, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[25], " + "expected 39, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[25]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[26] == 87, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[26], " + "expected 87, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[26]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[27] == 69, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[27], " + "expected 69, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[27]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[28] == 154, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[28], " + "expected 154, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[28]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[29] == 13, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[29], " + "expected 13, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[29]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[30] == 28, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[30], " + "expected 28, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[30]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[31] == 179, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[31], " + "expected 179, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[31]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[32] == 32, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[32], " + "expected 32, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[32]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[33] == 47, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[33], " + "expected 47, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[33]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[34] == 36, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[34], " + "expected 36, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[34]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[35] == 195, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[35], " + "expected 195, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[35]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[36] == 39, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[36], " + "expected 39, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[36]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[37] == 198, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[37], " + "expected 198, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[37]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[38] == 134, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[38], " + "expected 134, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[38]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[39] == 235, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[39], " + "expected 235, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[39]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[40] == 134, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[40], " + "expected 134, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[40]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[41] == 57, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[41], " + "expected 57, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[41]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[42] == 120, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[42], " + "expected 120, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[42]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[43] == 243, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[43], " + "expected 243, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[43]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[44] == 151, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[44], " + "expected 151, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[44]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[45] == 35, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[45], " + "expected 35, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[45]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[46] == 17, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[46], " + "expected 17, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[46]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[47] == 201, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[47], " + "expected 201, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[47]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[48] == 211, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[48], " + "expected 211, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[48]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[49] == 125, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[49], " + "expected 125, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[49]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[50] == 117, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[50], " + "expected 117, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[50]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[51] == 164, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[51], " + "expected 164, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[51]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[52] == 142, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[52], " + "expected 142, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[52]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[53] == 101, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[53], " + "expected 101, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[53]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[54] == 239, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[54], " + "expected 239, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[54]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[55] == 144, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[55], " + "expected 144, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[55]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[56] == 158, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[56], " + "expected 158, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[56]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[57] == 239, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[57], " + "expected 239, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[57]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[58] == 90, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[58], " + "expected 90, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[58]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[59] == 56, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[59], " + "expected 56, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[59]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[60] == 71, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[60], " + "expected 71, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[60]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[61] == 120, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[61], " + "expected 120, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[61]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[62] == 67, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[62], " + "expected 67, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[62]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[63] == 221, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[63], " + "expected 221, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[63]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[64] == 114, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[64], " + "expected 114, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[64]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[65] == 10, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[65], " + "expected 10, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[65]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[66] == 190, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[66], " + "expected 190, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[66]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[67] == 4, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[67], " + "expected 4, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[67]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[68] == 230, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[68], " + "expected 230, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[68]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[69] == 164, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[69], " + "expected 164, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[69]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[70] == 171, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[70], " + "expected 171, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[70]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[71] == 78, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[71], " + "expected 78, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[71]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[72] == 185, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[72], " + "expected 185, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[72]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[73] == 90, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[73], " + "expected 90, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[73]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[74] == 46, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[74], " + "expected 46, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[74]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[75] == 177, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[75], " + "expected 177, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[75]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[76] == 82, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[76], " + "expected 82, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[76]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[77] == 228, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[77], " + "expected 228, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[77]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[78] == 123, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[78], " + "expected 123, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[78]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[79] == 222, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[79], " + "expected 222, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[79]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[80] == 227, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[80], " + "expected 227, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[80]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[81] == 145, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[81], " + "expected 145, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[81]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[82] == 195, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[82], " + "expected 195, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[82]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[83] == 219, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[83], " + "expected 219, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[83]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[84] == 27, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[84], " + "expected 27, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[84]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[85] == 56, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[85], " + "expected 56, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[85]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[86] == 227, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[86], " + "expected 227, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[86]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[87] == 246, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[87], " + "expected 246, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[87]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[88] == 215, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[88], " + "expected 215, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[88]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[89] == 144, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[89], " + "expected 144, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[89]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[90] == 158, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[90], " + "expected 158, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[90]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[91] == 31, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[91], " + "expected 31, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[91]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[92] == 214, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[92], " + "expected 214, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[92]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[93] == 241, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[93], " + "expected 241, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[93]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[94] == 254, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[94], " + "expected 254, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[94]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[95] == 200, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[95], " + "expected 200, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[95]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[96] == 86, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[96], " + "expected 86, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[96]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[97] == 142, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[97], " + "expected 142, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[97]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[98] == 89, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[98], " + "expected 89, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[98]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[99] == 12, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[99], " + "expected 12, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[99]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[100] == 121, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[100], " + "expected 121, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[100]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[101] == 29, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[101], " + "expected 29, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[101]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[102] == 124, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[102], " + "expected 124, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[102]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[103] == 9, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[103], " + "expected 9, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[103]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[104] == 19, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[104], " + "expected 19, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[104]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[105] == 153, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[105], " + "expected 153, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[105]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[106] == 44, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[106], " + "expected 44, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[106]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[107] == 35, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[107], " + "expected 35, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[107]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[108] == 126, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[108], " + "expected 126, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[108]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[109] == 14, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[109], " + "expected 14, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[109]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[110] == 217, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[110], " + "expected 217, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[110]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[111] == 65, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[111], " + "expected 65, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[111]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[112] == 116, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[112], " + "expected 116, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[112]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[113] == 26, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[113], " + "expected 26, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[113]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[114] == 139, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[114], " + "expected 139, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[114]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[115] == 122, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[115], " + "expected 122, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[115]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[116] == 114, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[116], " + "expected 114, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[116]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[117] == 90, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[117], " + "expected 90, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[117]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[118] == 124, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[118], " + "expected 124, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[118]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[119] == 81, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[119], " + "expected 81, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[119]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[120] == 0, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[120], " + "expected 0, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[120]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[121] == 186, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[121], " + "expected 186, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[121]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[122] == 246, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[122], " + "expected 246, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[122]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[123] == 46, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[123], " + "expected 46, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[123]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[124] == 98, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[124], " + "expected 98, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[124]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[125] == 179, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[125], " + "expected 179, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[125]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[126] == 243, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[126], " + "expected 243, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[126]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[127] == 198, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[127], " + "expected 198, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[127]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[128] == 217, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[128], " + "expected 217, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[128]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[129] == 36, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[129], " + "expected 36, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[129]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[130] == 30, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[130], " + "expected 30, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[130]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[131] == 202, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[131], " + "expected 202, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[131]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[132] == 12, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[132], " + "expected 12, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[132]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[133] == 135, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[133], " + "expected 135, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[133]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[134] == 61, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[134], " + "expected 61, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[134]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[135] == 42, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[135], " + "expected 42, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[135]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[136] == 150, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[136], " + "expected 150, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[136]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[137] == 221, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[137], " + "expected 221, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[137]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[138] == 102, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[138], " + "expected 102, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[138]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[139] == 83, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[139], " + "expected 83, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[139]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[140] == 179, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[140], " + "expected 179, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[140]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[141] == 43, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[141], " + "expected 43, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[141]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[142] == 252, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[142], " + "expected 252, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[142]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[143] == 81, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[143], " + "expected 81, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[143]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[144] == 62, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[144], " + "expected 62, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[144]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[145] == 126, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[145], " + "expected 126, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[145]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[146] == 204, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[146], " + "expected 204, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[146]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[147] == 195, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[147], " + "expected 195, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[147]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[148] == 238, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[148], " + "expected 238, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[148]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[149] == 18, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[149], " + "expected 18, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[149]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[150] == 128, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[150], " + "expected 128, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[150]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[151] == 193, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[151], " + "expected 193, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[151]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[152] == 53, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[152], " + "expected 53, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[152]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[153] == 94, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[153], " + "expected 94, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[153]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[154] == 99, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[154], " + "expected 99, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[154]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[155] == 63, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[155], " + "expected 63, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[155]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[156] == 182, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[156], " + "expected 182, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[156]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[157] == 2, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[157], " + "expected 2, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[157]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[158] == 186, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[158], " + "expected 186, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[158]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[159] == 220, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[159], " + "expected 220, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[159]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[160] == 77, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[160], " + "expected 77, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[160]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[161] == 186, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[161], " + "expected 186, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[161]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[162] == 224, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[162], " + "expected 224, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[162]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[163] == 220, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[163], " + "expected 220, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[163]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[164] == 13, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[164], " + "expected 13, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[164]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[165] == 212, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[165], " + "expected 212, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[165]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[166] == 182, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[166], " + "expected 182, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[166]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[167] == 88, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[167], " + "expected 88, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[167]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[168] == 15, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[168], " + "expected 15, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[168]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[169] == 151, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[169], " + "expected 151, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[169]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[170] == 5, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[170], " + "expected 5, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[170]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[171] == 93, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[171], " + "expected 93, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[171]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[172] == 251, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[172], " + "expected 251, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[172]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[173] == 164, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[173], " + "expected 164, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[173]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[174] == 18, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[174], " + "expected 18, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[174]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[175] == 228, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[175], " + "expected 228, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[175]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[176] == 168, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[176], " + "expected 168, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[176]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[177] == 226, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[177], " + "expected 226, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[177]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[178] == 195, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[178], " + "expected 195, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[178]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[179] == 44, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[179], " + "expected 44, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[179]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[180] == 170, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[180], " + "expected 170, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[180]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[181] == 145, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[181], " + "expected 145, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[181]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[182] == 36, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[182], " + "expected 36, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[182]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[183] == 58, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[183], " + "expected 58, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[183]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[184] == 96, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[184], " + "expected 96, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[184]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[185] == 107, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[185], " + "expected 107, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[185]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[186] == 144, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[186], " + "expected 144, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[186]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[187] == 11, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[187], " + "expected 11, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[187]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[188] == 228, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[188], " + "expected 228, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[188]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[189] == 12, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[189], " + "expected 12, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[189]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[190] == 163, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[190], " + "expected 163, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[190]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[191] == 238, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[191], " + "expected 238, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[191]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[192] == 247, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[192], " + "expected 247, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[192]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[193] == 159, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[193], " + "expected 159, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[193]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[194] == 189, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[194], " + "expected 189, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[194]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[195] == 1, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[195], " + "expected 1, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[195]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[196] == 115, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[196], " + "expected 115, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[196]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[197] == 65, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[197], " + "expected 65, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[197]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[198] == 202, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[198], " + "expected 202, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[198]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[199] == 121, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[199], " + "expected 121, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[199]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[200] == 47, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[200], " + "expected 47, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[200]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[201] == 193, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[201], " + "expected 193, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[201]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[202] == 11, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[202], " + "expected 11, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[202]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[203] == 96, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[203], " + "expected 96, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[203]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[204] == 93, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[204], " + "expected 93, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[204]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[205] == 72, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[205], " + "expected 72, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[205]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[206] == 81, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[206], " + "expected 81, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[206]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[207] == 207, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[207], " + "expected 207, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[207]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[208] == 121, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[208], " + "expected 121, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[208]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[209] == 19, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[209], " + "expected 19, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[209]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[210] == 151, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[210], " + "expected 151, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[210]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[211] == 136, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[211], " + "expected 136, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[211]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[212] == 233, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[212], " + "expected 233, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[212]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[213] == 51, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[213], " + "expected 51, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[213]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[214] == 133, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[214], " + "expected 133, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[214]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[215] == 195, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[215], " + "expected 195, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[215]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[216] == 77, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[216], " + "expected 77, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[216]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[217] == 44, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[217], " + "expected 44, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[217]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[218] == 147, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[218], " + "expected 147, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[218]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[219] == 206, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[219], " + "expected 206, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[219]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[220] == 120, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[220], " + "expected 120, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[220]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[221] == 252, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[221], " + "expected 252, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[221]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[222] == 77, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[222], " + "expected 77, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[222]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[223] == 212, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[223], " + "expected 212, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[223]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[224] == 68, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[224], " + "expected 68, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[224]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[225] == 60, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[225], " + "expected 60, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[225]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[226] == 206, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[226], " + "expected 206, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[226]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[227] == 106, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[227], " + "expected 106, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[227]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[228] == 207, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[228], " + "expected 207, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[228]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[229] == 243, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[229], " + "expected 243, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[229]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[230] == 158, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[230], " + "expected 158, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[230]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[231] == 94, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[231], " + "expected 94, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[231]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[232] == 6, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[232], " + "expected 6, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[232]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[233] == 3, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[233], " + "expected 3, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[233]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[234] == 205, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[234], " + "expected 205, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[234]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[235] == 92, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[235], " + "expected 92, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[235]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[236] == 84, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[236], " + "expected 84, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[236]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[237] == 2, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[237], " + "expected 2, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[237]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[238] == 220, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[238], " + "expected 220, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[238]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[239] == 50, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[239], " + "expected 50, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[239]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[240] == 61, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[240], " + "expected 61, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[240]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[241] == 38, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[241], " + "expected 38, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[241]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[242] == 141, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[242], " + "expected 141, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[242]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[243] == 117, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[243], " + "expected 117, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[243]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[244] == 108, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[244], " + "expected 108, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[244]); + ck_assert_msg(last_msg.msg.ssr_grid_definition_dep_a.rle_list[245] == 101, + "incorrect value for " + "last_msg.msg.ssr_grid_definition_dep_a.rle_list[245], " + "expected 101, is %d", + last_msg.msg.ssr_grid_definition_dep_a.rle_list[245]); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrGridDefinitionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c new file mode 100644 index 0000000000..15c437aeb8 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c @@ -0,0 +1,2077 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrGriddedCorrection) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5fc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, + 174, 229, 151, 189, 204, 196, 105, 170, 120, 149, 169, 37, 244, 78, + 72, 140, 101, 2, 173, 88, 70, 180, 54, 152, 115, 78, 201, 161, + 23, 135, 152, 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, + 230, 69, 172, 191, 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, + 52, 166, 166, 120, 57, 221, 12, 3, 156, 70, 156, 35, 127, 8, + 127, 58, 128, 55, 115, 80, 157, 122, 153, 124, 27, 128, 98, 103, + 204, 75, 238, 128, 226, 148, 248, 61, 216, 208, 149, 167, 224, 40, + 144, 186, 157, 227, 72, 240, 100, 35, 12, 212, 7, 59, 176, 81, + 86, 27, 24, 155, 67, 43, 132, 45, 203, 44, 6, 112, 183, 231, + 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, 23, 62, 227, 240, + 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, 176, 201, 202, + 91, 105, 115, 146, 59, 110, 44, 109, 128, 183, 185, 67, 31, 165, + 92, 79, 189, 180, 94, 7, 162, 121, 156, 210, 47, 7, 7, 205, + 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, 219, + 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, + 247, 64, 189, 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, + 45, 251, 239, 115, 88, 218, 10, 209, 120, 65, 175, 131, 194, 41, + 174, 137, 17, 68, 28, 253, 42, 178, 35, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_gridded_correction.header.iod_atmo = 170; + + test_msg.ssr_gridded_correction.header.num_msgs = 48535; + + test_msg.ssr_gridded_correction.header.seq_num = 50380; + + test_msg.ssr_gridded_correction.header.tile_id = 12951; + + test_msg.ssr_gridded_correction.header.tile_set_id = 3605; + + test_msg.ssr_gridded_correction.header.time.tow = 2535294328; + + test_msg.ssr_gridded_correction.header.time.wn = 58798; + + test_msg.ssr_gridded_correction.header.tropo_quality_indicator = 120; + + test_msg.ssr_gridded_correction.header.update_interval = 105; + + test_msg.ssr_gridded_correction.index = 43413; + + test_msg.ssr_gridded_correction.n_stec_residuals = 46; + + test_msg.ssr_gridded_correction.stec_residuals[0].residual = -21246; + + test_msg.ssr_gridded_correction.stec_residuals[0].stddev = 88; + + test_msg.ssr_gridded_correction.stec_residuals[0].sv_id.constellation = 101; + + test_msg.ssr_gridded_correction.stec_residuals[0].sv_id.satId = 140; + + test_msg.ssr_gridded_correction.stec_residuals[1].residual = -26570; + + test_msg.ssr_gridded_correction.stec_residuals[1].stddev = 115; + + test_msg.ssr_gridded_correction.stec_residuals[1].sv_id.constellation = 180; + + test_msg.ssr_gridded_correction.stec_residuals[1].sv_id.satId = 70; + + test_msg.ssr_gridded_correction.stec_residuals[2].residual = 6049; + + test_msg.ssr_gridded_correction.stec_residuals[2].stddev = 135; + + test_msg.ssr_gridded_correction.stec_residuals[2].sv_id.constellation = 201; + + test_msg.ssr_gridded_correction.stec_residuals[2].sv_id.satId = 78; + + test_msg.ssr_gridded_correction.stec_residuals[3].residual = 19261; + + test_msg.ssr_gridded_correction.stec_residuals[3].stddev = 178; + + test_msg.ssr_gridded_correction.stec_residuals[3].sv_id.constellation = 98; + + test_msg.ssr_gridded_correction.stec_residuals[3].sv_id.satId = 152; + + test_msg.ssr_gridded_correction.stec_residuals[4].residual = 14226; + + test_msg.ssr_gridded_correction.stec_residuals[4].stddev = 58; + + test_msg.ssr_gridded_correction.stec_residuals[4].sv_id.constellation = 229; + + test_msg.ssr_gridded_correction.stec_residuals[4].sv_id.satId = 120; + + test_msg.ssr_gridded_correction.stec_residuals[5].residual = 17894; + + test_msg.ssr_gridded_correction.stec_residuals[5].stddev = 172; + + test_msg.ssr_gridded_correction.stec_residuals[5].sv_id.constellation = 234; + + test_msg.ssr_gridded_correction.stec_residuals[5].sv_id.satId = 169; + + test_msg.ssr_gridded_correction.stec_residuals[6].residual = 22930; + + test_msg.ssr_gridded_correction.stec_residuals[6].stddev = 150; + + test_msg.ssr_gridded_correction.stec_residuals[6].sv_id.constellation = 127; + + test_msg.ssr_gridded_correction.stec_residuals[6].sv_id.satId = 191; + + test_msg.ssr_gridded_correction.stec_residuals[7].residual = 10721; + + test_msg.ssr_gridded_correction.stec_residuals[7].stddev = 17; + + test_msg.ssr_gridded_correction.stec_residuals[7].sv_id.constellation = 111; + + test_msg.ssr_gridded_correction.stec_residuals[7].sv_id.satId = 91; + + test_msg.ssr_gridded_correction.stec_residuals[8].residual = -22874; + + test_msg.ssr_gridded_correction.stec_residuals[8].stddev = 120; + + test_msg.ssr_gridded_correction.stec_residuals[8].sv_id.constellation = 52; + + test_msg.ssr_gridded_correction.stec_residuals[8].sv_id.satId = 119; + + test_msg.ssr_gridded_correction.stec_residuals[9].residual = 780; + + test_msg.ssr_gridded_correction.stec_residuals[9].stddev = 156; + + test_msg.ssr_gridded_correction.stec_residuals[9].sv_id.constellation = 221; + + test_msg.ssr_gridded_correction.stec_residuals[9].sv_id.satId = 57; + + test_msg.ssr_gridded_correction.stec_residuals[10].residual = 32547; + + test_msg.ssr_gridded_correction.stec_residuals[10].stddev = 8; + + test_msg.ssr_gridded_correction.stec_residuals[10].sv_id.constellation = + 156; + + test_msg.ssr_gridded_correction.stec_residuals[10].sv_id.satId = 70; + + test_msg.ssr_gridded_correction.stec_residuals[11].residual = 14208; + + test_msg.ssr_gridded_correction.stec_residuals[11].stddev = 115; + + test_msg.ssr_gridded_correction.stec_residuals[11].sv_id.constellation = 58; + + test_msg.ssr_gridded_correction.stec_residuals[11].sv_id.satId = 127; + + test_msg.ssr_gridded_correction.stec_residuals[12].residual = -26246; + + test_msg.ssr_gridded_correction.stec_residuals[12].stddev = 124; + + test_msg.ssr_gridded_correction.stec_residuals[12].sv_id.constellation = + 157; + + test_msg.ssr_gridded_correction.stec_residuals[12].sv_id.satId = 80; + + test_msg.ssr_gridded_correction.stec_residuals[13].residual = 26466; + + test_msg.ssr_gridded_correction.stec_residuals[13].stddev = 204; + + test_msg.ssr_gridded_correction.stec_residuals[13].sv_id.constellation = + 128; + + test_msg.ssr_gridded_correction.stec_residuals[13].sv_id.satId = 27; + + test_msg.ssr_gridded_correction.stec_residuals[14].residual = -7552; + + test_msg.ssr_gridded_correction.stec_residuals[14].stddev = 148; + + test_msg.ssr_gridded_correction.stec_residuals[14].sv_id.constellation = + 238; + + test_msg.ssr_gridded_correction.stec_residuals[14].sv_id.satId = 75; + + test_msg.ssr_gridded_correction.stec_residuals[15].residual = -12072; + + test_msg.ssr_gridded_correction.stec_residuals[15].stddev = 149; + + test_msg.ssr_gridded_correction.stec_residuals[15].sv_id.constellation = 61; + + test_msg.ssr_gridded_correction.stec_residuals[15].sv_id.satId = 248; + + test_msg.ssr_gridded_correction.stec_residuals[16].residual = -28632; + + test_msg.ssr_gridded_correction.stec_residuals[16].stddev = 186; + + test_msg.ssr_gridded_correction.stec_residuals[16].sv_id.constellation = + 224; + + test_msg.ssr_gridded_correction.stec_residuals[16].sv_id.satId = 167; + + test_msg.ssr_gridded_correction.stec_residuals[17].residual = -4024; + + test_msg.ssr_gridded_correction.stec_residuals[17].stddev = 100; + + test_msg.ssr_gridded_correction.stec_residuals[17].sv_id.constellation = + 227; + + test_msg.ssr_gridded_correction.stec_residuals[17].sv_id.satId = 157; + + test_msg.ssr_gridded_correction.stec_residuals[18].residual = 2004; + + test_msg.ssr_gridded_correction.stec_residuals[18].stddev = 59; + + test_msg.ssr_gridded_correction.stec_residuals[18].sv_id.constellation = 12; + + test_msg.ssr_gridded_correction.stec_residuals[18].sv_id.satId = 35; + + test_msg.ssr_gridded_correction.stec_residuals[19].residual = 6998; + + test_msg.ssr_gridded_correction.stec_residuals[19].stddev = 24; + + test_msg.ssr_gridded_correction.stec_residuals[19].sv_id.constellation = 81; + + test_msg.ssr_gridded_correction.stec_residuals[19].sv_id.satId = 176; + + test_msg.ssr_gridded_correction.stec_residuals[20].residual = -31701; + + test_msg.ssr_gridded_correction.stec_residuals[20].stddev = 45; + + test_msg.ssr_gridded_correction.stec_residuals[20].sv_id.constellation = 67; + + test_msg.ssr_gridded_correction.stec_residuals[20].sv_id.satId = 155; + + test_msg.ssr_gridded_correction.stec_residuals[21].residual = 28678; + + test_msg.ssr_gridded_correction.stec_residuals[21].stddev = 183; + + test_msg.ssr_gridded_correction.stec_residuals[21].sv_id.constellation = 44; + + test_msg.ssr_gridded_correction.stec_residuals[21].sv_id.satId = 203; + + test_msg.ssr_gridded_correction.stec_residuals[22].residual = -15793; + + test_msg.ssr_gridded_correction.stec_residuals[22].stddev = 253; + + test_msg.ssr_gridded_correction.stec_residuals[22].sv_id.constellation = + 176; + + test_msg.ssr_gridded_correction.stec_residuals[22].sv_id.satId = 231; + + test_msg.ssr_gridded_correction.stec_residuals[23].residual = -7589; + + test_msg.ssr_gridded_correction.stec_residuals[23].stddev = 116; + + test_msg.ssr_gridded_correction.stec_residuals[23].sv_id.constellation = + 103; + + test_msg.ssr_gridded_correction.stec_residuals[23].sv_id.satId = 247; + + test_msg.ssr_gridded_correction.stec_residuals[24].residual = -7362; + + test_msg.ssr_gridded_correction.stec_residuals[24].stddev = 240; + + test_msg.ssr_gridded_correction.stec_residuals[24].sv_id.constellation = 23; + + test_msg.ssr_gridded_correction.stec_residuals[24].sv_id.satId = 148; + + test_msg.ssr_gridded_correction.stec_residuals[25].residual = 4813; + + test_msg.ssr_gridded_correction.stec_residuals[25].stddev = 242; + + test_msg.ssr_gridded_correction.stec_residuals[25].sv_id.constellation = + 219; + + test_msg.ssr_gridded_correction.stec_residuals[25].sv_id.satId = 29; + + test_msg.ssr_gridded_correction.stec_residuals[26].residual = 20295; + + test_msg.ssr_gridded_correction.stec_residuals[26].stddev = 37; + + test_msg.ssr_gridded_correction.stec_residuals[26].sv_id.constellation = 72; + + test_msg.ssr_gridded_correction.stec_residuals[26].sv_id.satId = 207; + + test_msg.ssr_gridded_correction.stec_residuals[27].residual = -13623; + + test_msg.ssr_gridded_correction.stec_residuals[27].stddev = 91; + + test_msg.ssr_gridded_correction.stec_residuals[27].sv_id.constellation = + 176; + + test_msg.ssr_gridded_correction.stec_residuals[27].sv_id.satId = 42; + + test_msg.ssr_gridded_correction.stec_residuals[28].residual = 15250; + + test_msg.ssr_gridded_correction.stec_residuals[28].stddev = 110; + + test_msg.ssr_gridded_correction.stec_residuals[28].sv_id.constellation = + 115; + + test_msg.ssr_gridded_correction.stec_residuals[28].sv_id.satId = 105; + + test_msg.ssr_gridded_correction.stec_residuals[29].residual = -18560; + + test_msg.ssr_gridded_correction.stec_residuals[29].stddev = 185; + + test_msg.ssr_gridded_correction.stec_residuals[29].sv_id.constellation = + 109; + + test_msg.ssr_gridded_correction.stec_residuals[29].sv_id.satId = 44; + + test_msg.ssr_gridded_correction.stec_residuals[30].residual = 23717; + + test_msg.ssr_gridded_correction.stec_residuals[30].stddev = 79; + + test_msg.ssr_gridded_correction.stec_residuals[30].sv_id.constellation = 31; + + test_msg.ssr_gridded_correction.stec_residuals[30].sv_id.satId = 67; + + test_msg.ssr_gridded_correction.stec_residuals[31].residual = 1886; + + test_msg.ssr_gridded_correction.stec_residuals[31].stddev = 162; + + test_msg.ssr_gridded_correction.stec_residuals[31].sv_id.constellation = + 180; + + test_msg.ssr_gridded_correction.stec_residuals[31].sv_id.satId = 189; + + test_msg.ssr_gridded_correction.stec_residuals[32].residual = 12242; + + test_msg.ssr_gridded_correction.stec_residuals[32].stddev = 7; + + test_msg.ssr_gridded_correction.stec_residuals[32].sv_id.constellation = + 156; + + test_msg.ssr_gridded_correction.stec_residuals[32].sv_id.satId = 121; + + test_msg.ssr_gridded_correction.stec_residuals[33].residual = 10670; + + test_msg.ssr_gridded_correction.stec_residuals[33].stddev = 241; + + test_msg.ssr_gridded_correction.stec_residuals[33].sv_id.constellation = + 205; + + test_msg.ssr_gridded_correction.stec_residuals[33].sv_id.satId = 7; + + test_msg.ssr_gridded_correction.stec_residuals[34].residual = 25899; + + test_msg.ssr_gridded_correction.stec_residuals[34].stddev = 186; + + test_msg.ssr_gridded_correction.stec_residuals[34].sv_id.constellation = + 210; + + test_msg.ssr_gridded_correction.stec_residuals[34].sv_id.satId = 129; + + test_msg.ssr_gridded_correction.stec_residuals[35].residual = -2078; + + test_msg.ssr_gridded_correction.stec_residuals[35].stddev = 187; + + test_msg.ssr_gridded_correction.stec_residuals[35].sv_id.constellation = + 195; + + test_msg.ssr_gridded_correction.stec_residuals[35].sv_id.satId = 208; + + test_msg.ssr_gridded_correction.stec_residuals[36].residual = -16264; + + test_msg.ssr_gridded_correction.stec_residuals[36].stddev = 102; + + test_msg.ssr_gridded_correction.stec_residuals[36].sv_id.constellation = + 160; + + test_msg.ssr_gridded_correction.stec_residuals[36].sv_id.satId = 219; + + test_msg.ssr_gridded_correction.stec_residuals[37].residual = -21002; + + test_msg.ssr_gridded_correction.stec_residuals[37].stddev = 94; + + test_msg.ssr_gridded_correction.stec_residuals[37].sv_id.constellation = 42; + + test_msg.ssr_gridded_correction.stec_residuals[37].sv_id.satId = 166; + + test_msg.ssr_gridded_correction.stec_residuals[38].residual = 7902; + + test_msg.ssr_gridded_correction.stec_residuals[38].stddev = 35; + + test_msg.ssr_gridded_correction.stec_residuals[38].sv_id.constellation = + 156; + + test_msg.ssr_gridded_correction.stec_residuals[38].sv_id.satId = 102; + + test_msg.ssr_gridded_correction.stec_residuals[39].residual = -30275; + + test_msg.ssr_gridded_correction.stec_residuals[39].stddev = 204; + + test_msg.ssr_gridded_correction.stec_residuals[39].sv_id.constellation = 64; + + test_msg.ssr_gridded_correction.stec_residuals[39].sv_id.satId = 247; + + test_msg.ssr_gridded_correction.stec_residuals[40].residual = -8633; + + test_msg.ssr_gridded_correction.stec_residuals[40].stddev = 222; + + test_msg.ssr_gridded_correction.stec_residuals[40].sv_id.constellation = 32; + + test_msg.ssr_gridded_correction.stec_residuals[40].sv_id.satId = 220; + + test_msg.ssr_gridded_correction.stec_residuals[41].residual = 6403; + + test_msg.ssr_gridded_correction.stec_residuals[41].stddev = 45; + + test_msg.ssr_gridded_correction.stec_residuals[41].sv_id.constellation = + 246; + + test_msg.ssr_gridded_correction.stec_residuals[41].sv_id.satId = 201; + + test_msg.ssr_gridded_correction.stec_residuals[42].residual = 22643; + + test_msg.ssr_gridded_correction.stec_residuals[42].stddev = 218; + + test_msg.ssr_gridded_correction.stec_residuals[42].sv_id.constellation = + 239; + + test_msg.ssr_gridded_correction.stec_residuals[42].sv_id.satId = 251; + + test_msg.ssr_gridded_correction.stec_residuals[43].residual = 16760; + + test_msg.ssr_gridded_correction.stec_residuals[43].stddev = 175; + + test_msg.ssr_gridded_correction.stec_residuals[43].sv_id.constellation = + 209; + + test_msg.ssr_gridded_correction.stec_residuals[43].sv_id.satId = 10; + + test_msg.ssr_gridded_correction.stec_residuals[44].residual = -20951; + + test_msg.ssr_gridded_correction.stec_residuals[44].stddev = 137; + + test_msg.ssr_gridded_correction.stec_residuals[44].sv_id.constellation = + 194; + + test_msg.ssr_gridded_correction.stec_residuals[44].sv_id.satId = 131; + + test_msg.ssr_gridded_correction.stec_residuals[45].residual = -740; + + test_msg.ssr_gridded_correction.stec_residuals[45].stddev = 42; + + test_msg.ssr_gridded_correction.stec_residuals[45].sv_id.constellation = 68; + + test_msg.ssr_gridded_correction.stec_residuals[45].sv_id.satId = 17; + + test_msg.ssr_gridded_correction.tropo_delay_correction.hydro = -3035; + + test_msg.ssr_gridded_correction.tropo_delay_correction.stddev = 72; + + test_msg.ssr_gridded_correction.tropo_delay_correction.wet = 78; + + sbp_message_send(&sbp_state, SbpMsgSsrGriddedCorrection, 63940, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63940, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrGriddedCorrection, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.header.iod_atmo == 170, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.iod_atmo, " + "expected 170, is %d", + last_msg.msg.ssr_gridded_correction.header.iod_atmo); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.header.num_msgs == 48535, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.num_msgs, " + "expected 48535, is %d", + last_msg.msg.ssr_gridded_correction.header.num_msgs); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.header.seq_num == 50380, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.seq_num, " + "expected 50380, is %d", + last_msg.msg.ssr_gridded_correction.header.seq_num); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.header.tile_id == 12951, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.tile_id, " + "expected 12951, is %d", + last_msg.msg.ssr_gridded_correction.header.tile_id); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.header.tile_set_id == 3605, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.tile_set_id, expected " + "3605, is %d", + last_msg.msg.ssr_gridded_correction.header.tile_set_id); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.header.time.tow == 2535294328, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.time.tow, expected " + "2535294328, is %d", + last_msg.msg.ssr_gridded_correction.header.time.tow); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.header.time.wn == 58798, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.time.wn, " + "expected 58798, is %d", + last_msg.msg.ssr_gridded_correction.header.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.header.tropo_quality_indicator == + 120, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.tropo_quality_indicator, " + "expected 120, is %d", + last_msg.msg.ssr_gridded_correction.header.tropo_quality_indicator); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.header.update_interval == 105, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.header.update_interval, expected " + "105, is %d", + last_msg.msg.ssr_gridded_correction.header.update_interval); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.index == 43413, + "incorrect value for last_msg.msg.ssr_gridded_correction.index, " + "expected 43413, is %d", + last_msg.msg.ssr_gridded_correction.index); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.n_stec_residuals == 46, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.n_stec_residuals, " + "expected 46, is %d", + last_msg.msg.ssr_gridded_correction.n_stec_residuals); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[0].residual == + -21246, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[0].residual, " + "expected -21246, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[0].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[0].stddev == 88, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[0].stddev, " + "expected 88, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[0].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[0] + .sv_id.constellation == 101, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[0].sv_id." + "constellation, expected 101, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[0] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[0].sv_id.satId == + 140, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[0].sv_id.satId, " + "expected 140, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[0].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[1].residual == + -26570, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[1].residual, " + "expected -26570, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[1].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[1].stddev == 115, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[1].stddev, " + "expected 115, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[1].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[1] + .sv_id.constellation == 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[1].sv_id." + "constellation, expected 180, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[1] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[1].sv_id.satId == 70, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[1].sv_id.satId, " + "expected 70, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[1].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[2].residual == 6049, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[2].residual, " + "expected 6049, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[2].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[2].stddev == 135, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[2].stddev, " + "expected 135, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[2].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[2] + .sv_id.constellation == 201, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[2].sv_id." + "constellation, expected 201, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[2] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[2].sv_id.satId == 78, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[2].sv_id.satId, " + "expected 78, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[2].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[3].residual == 19261, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[3].residual, " + "expected 19261, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[3].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[3].stddev == 178, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[3].stddev, " + "expected 178, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[3].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[3] + .sv_id.constellation == 98, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[3].sv_id." + "constellation, expected 98, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[3] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[3].sv_id.satId == + 152, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[3].sv_id.satId, " + "expected 152, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[3].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[4].residual == 14226, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[4].residual, " + "expected 14226, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[4].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[4].stddev == 58, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[4].stddev, " + "expected 58, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[4].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[4] + .sv_id.constellation == 229, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[4].sv_id." + "constellation, expected 229, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[4] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[4].sv_id.satId == + 120, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[4].sv_id.satId, " + "expected 120, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[4].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[5].residual == 17894, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[5].residual, " + "expected 17894, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[5].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[5].stddev == 172, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[5].stddev, " + "expected 172, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[5].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[5] + .sv_id.constellation == 234, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[5].sv_id." + "constellation, expected 234, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[5] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[5].sv_id.satId == + 169, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[5].sv_id.satId, " + "expected 169, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[5].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[6].residual == 22930, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[6].residual, " + "expected 22930, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[6].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[6].stddev == 150, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[6].stddev, " + "expected 150, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[6].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[6] + .sv_id.constellation == 127, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[6].sv_id." + "constellation, expected 127, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[6] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[6].sv_id.satId == + 191, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[6].sv_id.satId, " + "expected 191, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[6].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[7].residual == 10721, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[7].residual, " + "expected 10721, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[7].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[7].stddev == 17, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[7].stddev, " + "expected 17, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[7].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[7] + .sv_id.constellation == 111, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[7].sv_id." + "constellation, expected 111, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[7] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[7].sv_id.satId == 91, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[7].sv_id.satId, " + "expected 91, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[7].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[8].residual == + -22874, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[8].residual, " + "expected -22874, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[8].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[8].stddev == 120, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[8].stddev, " + "expected 120, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[8].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[8] + .sv_id.constellation == 52, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[8].sv_id." + "constellation, expected 52, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[8] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[8].sv_id.satId == + 119, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[8].sv_id.satId, " + "expected 119, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[8].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[9].residual == 780, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[9].residual, " + "expected 780, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[9].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[9].stddev == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[9].stddev, " + "expected 156, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[9].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[9] + .sv_id.constellation == 221, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[9].sv_id." + "constellation, expected 221, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[9] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[9].sv_id.satId == 57, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[9].sv_id.satId, " + "expected 57, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[9].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[10].residual == + 32547, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[10].residual, " + "expected 32547, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[10].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[10].stddev == 8, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[10].stddev, " + "expected 8, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[10].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[10] + .sv_id.constellation == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[10].sv_" + "id.constellation, expected 156, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[10] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[10].sv_id.satId == + 70, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[10].sv_id.satId, " + "expected 70, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[10].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[11].residual == + 14208, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[11].residual, " + "expected 14208, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[11].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[11].stddev == 115, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[11].stddev, " + "expected 115, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[11].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[11] + .sv_id.constellation == 58, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[11].sv_" + "id.constellation, expected 58, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[11] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[11].sv_id.satId == + 127, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[11].sv_id.satId, " + "expected 127, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[11].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[12].residual == + -26246, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[12].residual, " + "expected -26246, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[12].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[12].stddev == 124, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[12].stddev, " + "expected 124, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[12].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[12] + .sv_id.constellation == 157, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[12].sv_" + "id.constellation, expected 157, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[12] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[12].sv_id.satId == + 80, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[12].sv_id.satId, " + "expected 80, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[12].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[13].residual == + 26466, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[13].residual, " + "expected 26466, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[13].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[13].stddev == 204, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[13].stddev, " + "expected 204, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[13].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[13] + .sv_id.constellation == 128, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[13].sv_" + "id.constellation, expected 128, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[13] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[13].sv_id.satId == + 27, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[13].sv_id.satId, " + "expected 27, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[13].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[14].residual == + -7552, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[14].residual, " + "expected -7552, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[14].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[14].stddev == 148, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[14].stddev, " + "expected 148, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[14].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[14] + .sv_id.constellation == 238, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[14].sv_" + "id.constellation, expected 238, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[14] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[14].sv_id.satId == + 75, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[14].sv_id.satId, " + "expected 75, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[14].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[15].residual == + -12072, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[15].residual, " + "expected -12072, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[15].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[15].stddev == 149, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[15].stddev, " + "expected 149, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[15].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[15] + .sv_id.constellation == 61, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[15].sv_" + "id.constellation, expected 61, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[15] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[15].sv_id.satId == + 248, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[15].sv_id.satId, " + "expected 248, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[15].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[16].residual == + -28632, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[16].residual, " + "expected -28632, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[16].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[16].stddev == 186, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[16].stddev, " + "expected 186, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[16].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[16] + .sv_id.constellation == 224, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[16].sv_" + "id.constellation, expected 224, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[16] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[16].sv_id.satId == + 167, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[16].sv_id.satId, " + "expected 167, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[16].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[17].residual == + -4024, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[17].residual, " + "expected -4024, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[17].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[17].stddev == 100, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[17].stddev, " + "expected 100, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[17].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[17] + .sv_id.constellation == 227, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[17].sv_" + "id.constellation, expected 227, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[17] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[17].sv_id.satId == + 157, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[17].sv_id.satId, " + "expected 157, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[17].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[18].residual == 2004, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[18].residual, " + "expected 2004, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[18].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[18].stddev == 59, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[18].stddev, " + "expected 59, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[18].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[18] + .sv_id.constellation == 12, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[18].sv_" + "id.constellation, expected 12, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[18] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[18].sv_id.satId == + 35, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[18].sv_id.satId, " + "expected 35, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[18].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[19].residual == 6998, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[19].residual, " + "expected 6998, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[19].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[19].stddev == 24, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[19].stddev, " + "expected 24, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[19].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[19] + .sv_id.constellation == 81, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[19].sv_" + "id.constellation, expected 81, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[19] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[19].sv_id.satId == + 176, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[19].sv_id.satId, " + "expected 176, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[19].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[20].residual == + -31701, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[20].residual, " + "expected -31701, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[20].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[20].stddev == 45, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[20].stddev, " + "expected 45, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[20].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[20] + .sv_id.constellation == 67, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[20].sv_" + "id.constellation, expected 67, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[20] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[20].sv_id.satId == + 155, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[20].sv_id.satId, " + "expected 155, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[20].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[21].residual == + 28678, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[21].residual, " + "expected 28678, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[21].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[21].stddev == 183, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[21].stddev, " + "expected 183, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[21].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[21] + .sv_id.constellation == 44, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[21].sv_" + "id.constellation, expected 44, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[21] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[21].sv_id.satId == + 203, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[21].sv_id.satId, " + "expected 203, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[21].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[22].residual == + -15793, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[22].residual, " + "expected -15793, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[22].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[22].stddev == 253, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[22].stddev, " + "expected 253, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[22].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[22] + .sv_id.constellation == 176, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[22].sv_" + "id.constellation, expected 176, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[22] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[22].sv_id.satId == + 231, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[22].sv_id.satId, " + "expected 231, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[22].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[23].residual == + -7589, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[23].residual, " + "expected -7589, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[23].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[23].stddev == 116, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[23].stddev, " + "expected 116, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[23].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[23] + .sv_id.constellation == 103, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[23].sv_" + "id.constellation, expected 103, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[23] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[23].sv_id.satId == + 247, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[23].sv_id.satId, " + "expected 247, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[23].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[24].residual == + -7362, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[24].residual, " + "expected -7362, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[24].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[24].stddev == 240, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[24].stddev, " + "expected 240, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[24].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[24] + .sv_id.constellation == 23, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[24].sv_" + "id.constellation, expected 23, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[24] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[24].sv_id.satId == + 148, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[24].sv_id.satId, " + "expected 148, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[24].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[25].residual == 4813, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[25].residual, " + "expected 4813, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[25].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[25].stddev == 242, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[25].stddev, " + "expected 242, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[25].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[25] + .sv_id.constellation == 219, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[25].sv_" + "id.constellation, expected 219, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[25] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[25].sv_id.satId == + 29, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[25].sv_id.satId, " + "expected 29, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[25].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[26].residual == + 20295, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[26].residual, " + "expected 20295, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[26].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[26].stddev == 37, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[26].stddev, " + "expected 37, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[26].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[26] + .sv_id.constellation == 72, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[26].sv_" + "id.constellation, expected 72, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[26] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[26].sv_id.satId == + 207, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[26].sv_id.satId, " + "expected 207, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[26].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[27].residual == + -13623, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[27].residual, " + "expected -13623, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[27].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[27].stddev == 91, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[27].stddev, " + "expected 91, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[27].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[27] + .sv_id.constellation == 176, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[27].sv_" + "id.constellation, expected 176, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[27] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[27].sv_id.satId == + 42, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[27].sv_id.satId, " + "expected 42, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[27].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[28].residual == + 15250, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[28].residual, " + "expected 15250, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[28].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[28].stddev == 110, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[28].stddev, " + "expected 110, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[28].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[28] + .sv_id.constellation == 115, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[28].sv_" + "id.constellation, expected 115, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[28] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[28].sv_id.satId == + 105, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[28].sv_id.satId, " + "expected 105, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[28].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[29].residual == + -18560, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[29].residual, " + "expected -18560, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[29].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[29].stddev == 185, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[29].stddev, " + "expected 185, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[29].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[29] + .sv_id.constellation == 109, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[29].sv_" + "id.constellation, expected 109, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[29] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[29].sv_id.satId == + 44, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[29].sv_id.satId, " + "expected 44, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[29].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[30].residual == + 23717, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[30].residual, " + "expected 23717, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[30].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[30].stddev == 79, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[30].stddev, " + "expected 79, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[30].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[30] + .sv_id.constellation == 31, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[30].sv_" + "id.constellation, expected 31, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[30] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[30].sv_id.satId == + 67, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[30].sv_id.satId, " + "expected 67, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[30].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[31].residual == 1886, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[31].residual, " + "expected 1886, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[31].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[31].stddev == 162, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[31].stddev, " + "expected 162, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[31].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[31] + .sv_id.constellation == 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[31].sv_" + "id.constellation, expected 180, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[31] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[31].sv_id.satId == + 189, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[31].sv_id.satId, " + "expected 189, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[31].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[32].residual == + 12242, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[32].residual, " + "expected 12242, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[32].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[32].stddev == 7, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[32].stddev, " + "expected 7, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[32].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[32] + .sv_id.constellation == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[32].sv_" + "id.constellation, expected 156, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[32] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[32].sv_id.satId == + 121, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[32].sv_id.satId, " + "expected 121, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[32].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[33].residual == + 10670, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[33].residual, " + "expected 10670, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[33].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[33].stddev == 241, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[33].stddev, " + "expected 241, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[33].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[33] + .sv_id.constellation == 205, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[33].sv_" + "id.constellation, expected 205, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[33] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[33].sv_id.satId == 7, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[33].sv_id.satId, " + "expected 7, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[33].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[34].residual == + 25899, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[34].residual, " + "expected 25899, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[34].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[34].stddev == 186, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[34].stddev, " + "expected 186, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[34].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[34] + .sv_id.constellation == 210, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[34].sv_" + "id.constellation, expected 210, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[34] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[34].sv_id.satId == + 129, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[34].sv_id.satId, " + "expected 129, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[34].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[35].residual == + -2078, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[35].residual, " + "expected -2078, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[35].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[35].stddev == 187, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[35].stddev, " + "expected 187, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[35].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[35] + .sv_id.constellation == 195, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[35].sv_" + "id.constellation, expected 195, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[35] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[35].sv_id.satId == + 208, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[35].sv_id.satId, " + "expected 208, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[35].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[36].residual == + -16264, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[36].residual, " + "expected -16264, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[36].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[36].stddev == 102, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[36].stddev, " + "expected 102, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[36].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[36] + .sv_id.constellation == 160, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[36].sv_" + "id.constellation, expected 160, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[36] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[36].sv_id.satId == + 219, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[36].sv_id.satId, " + "expected 219, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[36].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[37].residual == + -21002, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[37].residual, " + "expected -21002, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[37].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[37].stddev == 94, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[37].stddev, " + "expected 94, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[37].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[37] + .sv_id.constellation == 42, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[37].sv_" + "id.constellation, expected 42, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[37] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[37].sv_id.satId == + 166, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[37].sv_id.satId, " + "expected 166, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[37].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[38].residual == 7902, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[38].residual, " + "expected 7902, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[38].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[38].stddev == 35, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[38].stddev, " + "expected 35, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[38].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[38] + .sv_id.constellation == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[38].sv_" + "id.constellation, expected 156, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[38] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[38].sv_id.satId == + 102, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[38].sv_id.satId, " + "expected 102, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[38].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[39].residual == + -30275, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[39].residual, " + "expected -30275, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[39].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[39].stddev == 204, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[39].stddev, " + "expected 204, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[39].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[39] + .sv_id.constellation == 64, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[39].sv_" + "id.constellation, expected 64, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[39] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[39].sv_id.satId == + 247, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[39].sv_id.satId, " + "expected 247, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[39].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[40].residual == + -8633, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[40].residual, " + "expected -8633, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[40].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[40].stddev == 222, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[40].stddev, " + "expected 222, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[40].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[40] + .sv_id.constellation == 32, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[40].sv_" + "id.constellation, expected 32, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[40] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[40].sv_id.satId == + 220, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[40].sv_id.satId, " + "expected 220, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[40].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[41].residual == 6403, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[41].residual, " + "expected 6403, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[41].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[41].stddev == 45, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[41].stddev, " + "expected 45, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[41].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[41] + .sv_id.constellation == 246, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[41].sv_" + "id.constellation, expected 246, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[41] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[41].sv_id.satId == + 201, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[41].sv_id.satId, " + "expected 201, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[41].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[42].residual == + 22643, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[42].residual, " + "expected 22643, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[42].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[42].stddev == 218, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[42].stddev, " + "expected 218, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[42].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[42] + .sv_id.constellation == 239, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[42].sv_" + "id.constellation, expected 239, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[42] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[42].sv_id.satId == + 251, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[42].sv_id.satId, " + "expected 251, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[42].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[43].residual == + 16760, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[43].residual, " + "expected 16760, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[43].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[43].stddev == 175, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[43].stddev, " + "expected 175, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[43].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[43] + .sv_id.constellation == 209, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[43].sv_" + "id.constellation, expected 209, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[43] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[43].sv_id.satId == + 10, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[43].sv_id.satId, " + "expected 10, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[43].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[44].residual == + -20951, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[44].residual, " + "expected -20951, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[44].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[44].stddev == 137, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[44].stddev, " + "expected 137, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[44].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[44] + .sv_id.constellation == 194, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[44].sv_" + "id.constellation, expected 194, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[44] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[44].sv_id.satId == + 131, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[44].sv_id.satId, " + "expected 131, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[44].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[45].residual == -740, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[45].residual, " + "expected -740, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[45].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[45].stddev == 42, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[45].stddev, " + "expected 42, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[45].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction.stec_residuals[45] + .sv_id.constellation == 68, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[45].sv_" + "id.constellation, expected 68, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[45] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.stec_residuals[45].sv_id.satId == + 17, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.stec_residuals[45].sv_id.satId, " + "expected 17, is %d", + last_msg.msg.ssr_gridded_correction.stec_residuals[45].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.hydro == + -3035, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.tropo_delay_correction.hydro, " + "expected -3035, is %d", + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.hydro); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.stddev == 72, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.tropo_delay_correction.stddev, " + "expected 72, is %d", + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.stddev); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.wet == 78, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction.tropo_delay_correction.wet, " + "expected 78, is %d", + last_msg.msg.ssr_gridded_correction.tropo_delay_correction.wet); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrGriddedCorrection"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrGriddedCorrection"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrGriddedCorrection); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c new file mode 100644 index 0000000000..b3b91d9c5d --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c @@ -0,0 +1,2197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5fa, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, + 104, 252, 133, 245, 28, 95, 100, 147, 41, 33, 92, 87, 25, 142, + 151, 74, 151, 95, 94, 7, 146, 237, 45, 167, 86, 42, 116, 224, + 169, 234, 220, 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, + 206, 151, 158, 22, 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, + 110, 38, 65, 104, 244, 19, 238, 227, 88, 169, 164, 146, 63, 37, + 183, 85, 71, 235, 168, 114, 211, 105, 221, 156, 60, 18, 230, 2, + 142, 172, 16, 39, 33, 126, 106, 99, 188, 234, 41, 162, 197, 138, + 227, 80, 12, 54, 67, 238, 5, 93, 1, 207, 129, 13, 46, 115, + 49, 58, 185, 127, 156, 200, 96, 217, 202, 15, 245, 55, 198, 81, + 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, 96, 138, 55, 214, + 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, 245, 112, 168, + 210, 10, 5, 117, 1, 57, 108, 248, 212, 145, 119, 226, 165, 5, + 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, 215, 12, 137, 16, + 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, + 31, 48, 132, 72, 229, 126, 186, 68, 76, 133, 21, 0, 180, 139, + 164, 148, 119, 149, 214, 120, 177, 201, 80, 80, 105, 10, 136, 118, + 77, 46, 233, 233, 227, 11, 158, 103, 167, 216, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_gridded_correction_dep_a.header.iod_atmo = 245; + + test_msg.ssr_gridded_correction_dep_a.header.num_msgs = 37695; + + test_msg.ssr_gridded_correction_dep_a.header.seq_num = 64616; + + test_msg.ssr_gridded_correction_dep_a.header.time.tow = 892131748; + + test_msg.ssr_gridded_correction_dep_a.header.time.wn = 23906; + + test_msg.ssr_gridded_correction_dep_a.header.tropo_quality_indicator = 28; + + test_msg.ssr_gridded_correction_dep_a.header.update_interval = 133; + + test_msg.ssr_gridded_correction_dep_a.index = 25695; + + test_msg.ssr_gridded_correction_dep_a.n_stec_residuals = 47; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[0].residual = -26738; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[0].stddev = 74; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[0] + .sv_id.constellation = 25; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[0].sv_id.satId = 87; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[1].residual = 1886; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[1].stddev = 146; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[1] + .sv_id.constellation = 95; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[1].sv_id.satId = 151; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[2].residual = 22183; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[2].stddev = 42; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[2] + .sv_id.constellation = 45; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[2].sv_id.satId = 237; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[3].residual = -5463; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[3].stddev = 220; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[3] + .sv_id.constellation = 224; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[3].sv_id.satId = 116; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[4].residual = 3346; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[4].stddev = 178; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[4] + .sv_id.constellation = 176; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[4].sv_id.satId = 23; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[5].residual = 28320; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[5].stddev = 15; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[5] + .sv_id.constellation = 160; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[5].sv_id.satId = 79; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[6].residual = -24937; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[6].stddev = 22; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[6] + .sv_id.constellation = 206; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[6].sv_id.satId = 53; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[7].residual = -21968; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[7].stddev = 82; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[7] + .sv_id.constellation = 184; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[7].sv_id.satId = 117; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[8].residual = 17786; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[8].stddev = 180; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[8] + .sv_id.constellation = 53; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[8].sv_id.satId = 40; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[9].residual = 26689; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[9].stddev = 244; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[9] + .sv_id.constellation = 38; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[9].sv_id.satId = 110; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[10].residual = 22755; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[10].stddev = 169; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[10] + .sv_id.constellation = 238; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[10].sv_id.satId = 19; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[11].residual = 9535; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[11].stddev = 183; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[11] + .sv_id.constellation = 146; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[11].sv_id.satId = 164; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[12].residual = -22293; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[12].stddev = 114; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[12] + .sv_id.constellation = 71; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[12].sv_id.satId = 85; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[13].residual = -25379; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[13].stddev = 60; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[13] + .sv_id.constellation = 105; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[13].sv_id.satId = 211; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[14].residual = -29182; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[14].stddev = 172; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[14] + .sv_id.constellation = 230; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[14].sv_id.satId = 18; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[15].residual = 32289; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[15].stddev = 106; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[15] + .sv_id.constellation = 39; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[15].sv_id.satId = 16; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[16].residual = 10730; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[16].stddev = 162; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[16] + .sv_id.constellation = 188; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[16].sv_id.satId = 99; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[17].residual = 20707; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[17].stddev = 12; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[17] + .sv_id.constellation = 138; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[17].sv_id.satId = 197; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[18].residual = 1518; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[18].stddev = 93; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[18] + .sv_id.constellation = 67; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[18].sv_id.satId = 54; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[19].residual = 3457; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[19].stddev = 46; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[19] + .sv_id.constellation = 207; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[19].sv_id.satId = 1; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[20].residual = -18118; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[20].stddev = 127; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[20] + .sv_id.constellation = 49; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[20].sv_id.satId = 115; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[21].residual = -9888; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[21].stddev = 202; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[21] + .sv_id.constellation = 200; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[21].sv_id.satId = 156; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[22].residual = -14793; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[22].stddev = 81; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[22] + .sv_id.constellation = 245; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[22].sv_id.satId = 15; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[23].residual = 18758; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[23].stddev = 82; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[23] + .sv_id.constellation = 132; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[23].sv_id.satId = 218; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[24].residual = 3839; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[24].stddev = 134; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[24] + .sv_id.constellation = 26; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[24].sv_id.satId = 147; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[25].residual = -10697; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[25].stddev = 83; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[25] + .sv_id.constellation = 138; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[25].sv_id.satId = 96; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[26].residual = 20387; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[26].stddev = 173; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[26] + .sv_id.constellation = 170; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[26].sv_id.satId = 156; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[27].residual = -3789; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[27].stddev = 107; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[27] + .sv_id.constellation = 115; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[27].sv_id.satId = 228; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[28].residual = -11608; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[28].stddev = 10; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[28] + .sv_id.constellation = 112; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[28].sv_id.satId = 245; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[29].residual = 14593; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[29].stddev = 108; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[29] + .sv_id.constellation = 117; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[29].sv_id.satId = 5; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[30].residual = 30609; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[30].stddev = 226; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[30] + .sv_id.constellation = 212; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[30].sv_id.satId = 248; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[31].residual = -13683; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[31].stddev = 106; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[31] + .sv_id.constellation = 5; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[31].sv_id.satId = 165; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[32].residual = 15652; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[32].stddev = 243; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[32] + .sv_id.constellation = 60; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[32].sv_id.satId = 0; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[33].residual = 3287; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[33].stddev = 137; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[33] + .sv_id.constellation = 216; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[33].sv_id.satId = 203; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[34].residual = 29687; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[34].stddev = 152; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[34] + .sv_id.constellation = 28; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[34].sv_id.satId = 16; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[35].residual = -6960; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[35].stddev = 203; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[35] + .sv_id.constellation = 119; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[35].sv_id.satId = 181; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[36].residual = -15193; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[36].stddev = 32; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[36] + .sv_id.constellation = 34; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[36].sv_id.satId = 236; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[37].residual = 25873; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[37].stddev = 200; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[37] + .sv_id.constellation = 1; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[37].sv_id.satId = 109; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[38].residual = -22403; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[38].stddev = 137; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[38] + .sv_id.constellation = 94; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[38].sv_id.satId = 25; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[39].residual = 7588; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[39].stddev = 31; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[39] + .sv_id.constellation = 4; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[39].sv_id.satId = 157; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[40].residual = -6840; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[40].stddev = 126; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[40] + .sv_id.constellation = 132; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[40].sv_id.satId = 48; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[41].residual = -31412; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[41].stddev = 21; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[41] + .sv_id.constellation = 68; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[41].sv_id.satId = 186; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[42].residual = -23413; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[42].stddev = 148; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[42] + .sv_id.constellation = 180; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[42].sv_id.satId = 0; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[43].residual = 30934; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[43].stddev = 177; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[43] + .sv_id.constellation = 149; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[43].sv_id.satId = 119; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[44].residual = 26960; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[44].stddev = 10; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[44] + .sv_id.constellation = 80; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[44].sv_id.satId = 201; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[45].residual = 11853; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[45].stddev = 233; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[45] + .sv_id.constellation = 118; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[45].sv_id.satId = 136; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[46].residual = -25077; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[46].stddev = 103; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[46] + .sv_id.constellation = 227; + + test_msg.ssr_gridded_correction_dep_a.stec_residuals[46].sv_id.satId = 233; + + test_msg.ssr_gridded_correction_dep_a.tropo_delay_correction.hydro = 10643; + + test_msg.ssr_gridded_correction_dep_a.tropo_delay_correction.stddev = 92; + + test_msg.ssr_gridded_correction_dep_a.tropo_delay_correction.wet = 33; + + sbp_message_send(&sbp_state, SbpMsgSsrGriddedCorrectionDepA, 27244, + &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 27244, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrGriddedCorrectionDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.iod_atmo == 245, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.iod_atmo, expected " + "245, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.iod_atmo); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.num_msgs == 37695, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.num_msgs, expected " + "37695, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.num_msgs); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.seq_num == 64616, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.seq_num, expected " + "64616, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.seq_num); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.time.tow == 892131748, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.time.tow, expected " + "892131748, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.time.tow); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.time.wn == 23906, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.time.wn, expected " + "23906, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.time.wn); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.header + .tropo_quality_indicator == 28, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.tropo_" + "quality_indicator, expected 28, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header + .tropo_quality_indicator); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.header.update_interval == 133, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.header.update_interval, " + "expected 133, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.header.update_interval); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.index == 25695, + "incorrect value for last_msg.msg.ssr_gridded_correction_dep_a.index, " + "expected 25695, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.index); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.n_stec_residuals == 47, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.n_stec_residuals, expected " + "47, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.n_stec_residuals); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].residual == + -26738, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].residual, " + "expected -26738, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].stddev == + 74, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].stddev, " + "expected 74, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0] + .sv_id.constellation == 25, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0]." + "sv_id.constellation, expected 25, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0] + .sv_id.satId == 87, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0]." + "sv_id.satId, expected 87, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[0] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].residual == + 1886, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].residual, " + "expected 1886, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].stddev == + 146, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].stddev, " + "expected 146, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1] + .sv_id.constellation == 95, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1]." + "sv_id.constellation, expected 95, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1] + .sv_id.satId == 151, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1]." + "sv_id.satId, expected 151, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[1] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].residual == + 22183, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].residual, " + "expected 22183, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].stddev == + 42, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].stddev, " + "expected 42, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2] + .sv_id.constellation == 45, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2]." + "sv_id.constellation, expected 45, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2] + .sv_id.satId == 237, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2]." + "sv_id.satId, expected 237, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[2] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].residual == + -5463, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].residual, " + "expected -5463, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].stddev == + 220, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].stddev, " + "expected 220, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3] + .sv_id.constellation == 224, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3]." + "sv_id.constellation, expected 224, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3] + .sv_id.satId == 116, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3]." + "sv_id.satId, expected 116, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[3] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].residual == + 3346, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].residual, " + "expected 3346, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].stddev == + 178, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].stddev, " + "expected 178, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4] + .sv_id.constellation == 176, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4]." + "sv_id.constellation, expected 176, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4] + .sv_id.satId == 23, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4]." + "sv_id.satId, expected 23, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[4] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].residual == + 28320, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].residual, " + "expected 28320, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].stddev == + 15, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].stddev, " + "expected 15, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5] + .sv_id.constellation == 160, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5]." + "sv_id.constellation, expected 160, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5] + .sv_id.satId == 79, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5]." + "sv_id.satId, expected 79, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[5] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].residual == + -24937, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].residual, " + "expected -24937, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].stddev == + 22, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].stddev, " + "expected 22, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6] + .sv_id.constellation == 206, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6]." + "sv_id.constellation, expected 206, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6] + .sv_id.satId == 53, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6]." + "sv_id.satId, expected 53, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[6] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].residual == + -21968, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].residual, " + "expected -21968, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].stddev == + 82, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].stddev, " + "expected 82, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7] + .sv_id.constellation == 184, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7]." + "sv_id.constellation, expected 184, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7] + .sv_id.satId == 117, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7]." + "sv_id.satId, expected 117, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[7] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].residual == + 17786, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].residual, " + "expected 17786, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].stddev == + 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].stddev, " + "expected 180, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8] + .sv_id.constellation == 53, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8]." + "sv_id.constellation, expected 53, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8] + .sv_id.satId == 40, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8]." + "sv_id.satId, expected 40, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[8] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].residual == + 26689, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].residual, " + "expected 26689, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].stddev == + 244, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].stddev, " + "expected 244, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9] + .sv_id.constellation == 38, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9]." + "sv_id.constellation, expected 38, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9] + .sv_id.satId == 110, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9]." + "sv_id.satId, expected 110, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[9] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].residual == + 22755, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].residual," + " expected 22755, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].stddev == + 169, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].stddev, " + "expected 169, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10] + .sv_id.constellation == 238, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10]" + ".sv_id.constellation, expected 238, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10] + .sv_id.satId == 19, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10]" + ".sv_id.satId, expected 19, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[10] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].residual == + 9535, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].residual," + " expected 9535, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].stddev == + 183, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].stddev, " + "expected 183, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11] + .sv_id.constellation == 146, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11]" + ".sv_id.constellation, expected 146, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11] + .sv_id.satId == 164, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11]" + ".sv_id.satId, expected 164, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[11] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].residual == + -22293, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].residual," + " expected -22293, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].stddev == + 114, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].stddev, " + "expected 114, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12] + .sv_id.constellation == 71, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12]" + ".sv_id.constellation, expected 71, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12] + .sv_id.satId == 85, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12]" + ".sv_id.satId, expected 85, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[12] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].residual == + -25379, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].residual," + " expected -25379, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].stddev == + 60, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].stddev, " + "expected 60, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13] + .sv_id.constellation == 105, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13]" + ".sv_id.constellation, expected 105, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13] + .sv_id.satId == 211, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13]" + ".sv_id.satId, expected 211, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[13] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].residual == + -29182, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].residual," + " expected -29182, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].stddev == + 172, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].stddev, " + "expected 172, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14] + .sv_id.constellation == 230, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14]" + ".sv_id.constellation, expected 230, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14] + .sv_id.satId == 18, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14]" + ".sv_id.satId, expected 18, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[14] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].residual == + 32289, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].residual," + " expected 32289, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].stddev == + 106, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].stddev, " + "expected 106, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15] + .sv_id.constellation == 39, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15]" + ".sv_id.constellation, expected 39, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15] + .sv_id.satId == 16, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15]" + ".sv_id.satId, expected 16, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[15] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].residual == + 10730, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].residual," + " expected 10730, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].stddev == + 162, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].stddev, " + "expected 162, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16] + .sv_id.constellation == 188, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16]" + ".sv_id.constellation, expected 188, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16] + .sv_id.satId == 99, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16]" + ".sv_id.satId, expected 99, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[16] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].residual == + 20707, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].residual," + " expected 20707, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].stddev == + 12, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].stddev, " + "expected 12, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17] + .sv_id.constellation == 138, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17]" + ".sv_id.constellation, expected 138, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17] + .sv_id.satId == 197, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17]" + ".sv_id.satId, expected 197, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[17] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].residual == + 1518, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].residual," + " expected 1518, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].stddev == + 93, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].stddev, " + "expected 93, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18] + .sv_id.constellation == 67, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18]" + ".sv_id.constellation, expected 67, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18] + .sv_id.satId == 54, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18]" + ".sv_id.satId, expected 54, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[18] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].residual == + 3457, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].residual," + " expected 3457, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].stddev == + 46, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].stddev, " + "expected 46, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19] + .sv_id.constellation == 207, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19]" + ".sv_id.constellation, expected 207, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19] + .sv_id.satId == 1, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19]" + ".sv_id.satId, expected 1, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[19] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].residual == + -18118, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].residual," + " expected -18118, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].stddev == + 127, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].stddev, " + "expected 127, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20] + .sv_id.constellation == 49, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20]" + ".sv_id.constellation, expected 49, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20] + .sv_id.satId == 115, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20]" + ".sv_id.satId, expected 115, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[20] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].residual == + -9888, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].residual," + " expected -9888, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].stddev == + 202, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].stddev, " + "expected 202, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21] + .sv_id.constellation == 200, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21]" + ".sv_id.constellation, expected 200, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21] + .sv_id.satId == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21]" + ".sv_id.satId, expected 156, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[21] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].residual == + -14793, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].residual," + " expected -14793, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].stddev == + 81, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].stddev, " + "expected 81, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22] + .sv_id.constellation == 245, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22]" + ".sv_id.constellation, expected 245, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22] + .sv_id.satId == 15, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22]" + ".sv_id.satId, expected 15, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[22] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].residual == + 18758, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].residual," + " expected 18758, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].stddev == + 82, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].stddev, " + "expected 82, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23] + .sv_id.constellation == 132, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23]" + ".sv_id.constellation, expected 132, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23] + .sv_id.satId == 218, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23]" + ".sv_id.satId, expected 218, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[23] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].residual == + 3839, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].residual," + " expected 3839, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].stddev == + 134, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].stddev, " + "expected 134, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24] + .sv_id.constellation == 26, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24]" + ".sv_id.constellation, expected 26, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24] + .sv_id.satId == 147, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24]" + ".sv_id.satId, expected 147, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[24] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].residual == + -10697, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].residual," + " expected -10697, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].stddev == + 83, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].stddev, " + "expected 83, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25] + .sv_id.constellation == 138, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25]" + ".sv_id.constellation, expected 138, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25] + .sv_id.satId == 96, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25]" + ".sv_id.satId, expected 96, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[25] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].residual == + 20387, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].residual," + " expected 20387, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].stddev == + 173, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].stddev, " + "expected 173, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26] + .sv_id.constellation == 170, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26]" + ".sv_id.constellation, expected 170, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26] + .sv_id.satId == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26]" + ".sv_id.satId, expected 156, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[26] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].residual == + -3789, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].residual," + " expected -3789, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].stddev == + 107, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].stddev, " + "expected 107, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27] + .sv_id.constellation == 115, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27]" + ".sv_id.constellation, expected 115, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27] + .sv_id.satId == 228, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27]" + ".sv_id.satId, expected 228, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[27] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].residual == + -11608, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].residual," + " expected -11608, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].stddev == + 10, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].stddev, " + "expected 10, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28] + .sv_id.constellation == 112, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28]" + ".sv_id.constellation, expected 112, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28] + .sv_id.satId == 245, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28]" + ".sv_id.satId, expected 245, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[28] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].residual == + 14593, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].residual," + " expected 14593, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].stddev == + 108, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].stddev, " + "expected 108, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29] + .sv_id.constellation == 117, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29]" + ".sv_id.constellation, expected 117, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29] + .sv_id.satId == 5, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29]" + ".sv_id.satId, expected 5, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[29] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].residual == + 30609, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].residual," + " expected 30609, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].stddev == + 226, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].stddev, " + "expected 226, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30] + .sv_id.constellation == 212, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30]" + ".sv_id.constellation, expected 212, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30] + .sv_id.satId == 248, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30]" + ".sv_id.satId, expected 248, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[30] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].residual == + -13683, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].residual," + " expected -13683, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].stddev == + 106, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].stddev, " + "expected 106, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31] + .sv_id.constellation == 5, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31]" + ".sv_id.constellation, expected 5, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31] + .sv_id.satId == 165, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31]" + ".sv_id.satId, expected 165, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[31] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].residual == + 15652, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].residual," + " expected 15652, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].stddev == + 243, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].stddev, " + "expected 243, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32] + .sv_id.constellation == 60, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32]" + ".sv_id.constellation, expected 60, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32] + .sv_id.satId == 0, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32]" + ".sv_id.satId, expected 0, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[32] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].residual == + 3287, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].residual," + " expected 3287, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].stddev == + 137, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].stddev, " + "expected 137, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33] + .sv_id.constellation == 216, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33]" + ".sv_id.constellation, expected 216, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33] + .sv_id.satId == 203, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33]" + ".sv_id.satId, expected 203, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[33] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].residual == + 29687, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].residual," + " expected 29687, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].stddev == + 152, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].stddev, " + "expected 152, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34] + .sv_id.constellation == 28, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34]" + ".sv_id.constellation, expected 28, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34] + .sv_id.satId == 16, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34]" + ".sv_id.satId, expected 16, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[34] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].residual == + -6960, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].residual," + " expected -6960, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].stddev == + 203, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].stddev, " + "expected 203, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35] + .sv_id.constellation == 119, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35]" + ".sv_id.constellation, expected 119, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35] + .sv_id.satId == 181, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35]" + ".sv_id.satId, expected 181, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[35] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].residual == + -15193, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].residual," + " expected -15193, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].stddev == + 32, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].stddev, " + "expected 32, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36] + .sv_id.constellation == 34, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36]" + ".sv_id.constellation, expected 34, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36] + .sv_id.satId == 236, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36]" + ".sv_id.satId, expected 236, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[36] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].residual == + 25873, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].residual," + " expected 25873, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].stddev == + 200, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].stddev, " + "expected 200, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37] + .sv_id.constellation == 1, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37]" + ".sv_id.constellation, expected 1, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37] + .sv_id.satId == 109, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37]" + ".sv_id.satId, expected 109, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[37] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].residual == + -22403, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].residual," + " expected -22403, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].stddev == + 137, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].stddev, " + "expected 137, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38] + .sv_id.constellation == 94, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38]" + ".sv_id.constellation, expected 94, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38] + .sv_id.satId == 25, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38]" + ".sv_id.satId, expected 25, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[38] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].residual == + 7588, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].residual," + " expected 7588, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].stddev == + 31, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].stddev, " + "expected 31, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39] + .sv_id.constellation == 4, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39]" + ".sv_id.constellation, expected 4, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39] + .sv_id.satId == 157, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39]" + ".sv_id.satId, expected 157, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[39] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].residual == + -6840, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].residual," + " expected -6840, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].stddev == + 126, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].stddev, " + "expected 126, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40] + .sv_id.constellation == 132, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40]" + ".sv_id.constellation, expected 132, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40] + .sv_id.satId == 48, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40]" + ".sv_id.satId, expected 48, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[40] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].residual == + -31412, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].residual," + " expected -31412, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].stddev == + 21, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].stddev, " + "expected 21, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41] + .sv_id.constellation == 68, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41]" + ".sv_id.constellation, expected 68, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41] + .sv_id.satId == 186, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41]" + ".sv_id.satId, expected 186, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[41] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].residual == + -23413, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].residual," + " expected -23413, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].stddev == + 148, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].stddev, " + "expected 148, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42] + .sv_id.constellation == 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42]" + ".sv_id.constellation, expected 180, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42] + .sv_id.satId == 0, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42]" + ".sv_id.satId, expected 0, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[42] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].residual == + 30934, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].residual," + " expected 30934, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].stddev == + 177, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].stddev, " + "expected 177, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43] + .sv_id.constellation == 149, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43]" + ".sv_id.constellation, expected 149, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43] + .sv_id.satId == 119, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43]" + ".sv_id.satId, expected 119, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[43] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].residual == + 26960, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].residual," + " expected 26960, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].stddev == + 10, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].stddev, " + "expected 10, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44] + .sv_id.constellation == 80, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44]" + ".sv_id.constellation, expected 80, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44] + .sv_id.satId == 201, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44]" + ".sv_id.satId, expected 201, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[44] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].residual == + 11853, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].residual," + " expected 11853, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].stddev == + 233, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].stddev, " + "expected 233, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45] + .sv_id.constellation == 118, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45]" + ".sv_id.constellation, expected 118, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45] + .sv_id.satId == 136, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45]" + ".sv_id.satId, expected 136, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[45] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].residual == + -25077, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].residual," + " expected -25077, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].stddev == + 103, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].stddev, " + "expected 103, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46].stddev); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46] + .sv_id.constellation == 227, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46]" + ".sv_id.constellation, expected 227, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46] + .sv_id.constellation); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46] + .sv_id.satId == 233, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46]" + ".sv_id.satId, expected 233, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.stec_residuals[46] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction + .hydro == 10643, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction." + "hydro, expected 10643, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction.hydro); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_dep_a + .tropo_delay_correction.stddev == 92, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_" + "correction.stddev, expected 92, is %d", + last_msg.msg.ssr_gridded_correction_dep_a + .tropo_delay_correction.stddev); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction.wet == + 33, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction.wet, " + "expected 33, is %d", + last_msg.msg.ssr_gridded_correction_dep_a.tropo_delay_correction.wet); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c new file mode 100644 index 0000000000..0591c3e5ff --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c @@ -0,0 +1,2393 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5f0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, + 67, 248, 233, 236, 230, 230, 103, 122, 63, 101, 231, 157, 115, 162, + 197, 146, 35, 107, 222, 109, 52, 41, 86, 12, 237, 184, 65, 204, + 137, 148, 171, 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, + 203, 92, 166, 30, 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, + 95, 250, 99, 196, 92, 214, 159, 253, 195, 222, 233, 146, 233, 63, + 76, 24, 106, 40, 253, 65, 9, 183, 40, 215, 188, 59, 117, 69, + 97, 115, 60, 56, 0, 141, 207, 171, 54, 161, 23, 61, 0, 87, + 230, 123, 87, 36, 184, 255, 14, 163, 187, 224, 43, 151, 151, 104, + 39, 57, 5, 54, 48, 224, 181, 129, 60, 92, 171, 114, 109, 109, + 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, 24, 68, 160, 36, + 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, 221, 253, 15, + 62, 23, 121, 185, 168, 116, 4, 147, 123, 72, 223, 119, 226, 242, + 161, 204, 180, 202, 137, 166, 58, 24, 124, 19, 181, 188, 16, 107, + 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, 221, + 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, + 99, 44, 95, 131, 89, 192, 225, 55, 95, 171, 88, 205, 21, 116, + 231, 83, 71, 71, 100, 110, 217, 254, 152, 212, 18, 8, 40, 157, + 244, 54, 72, 240, 231, 189, 111, 195, 205, 81, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_gridded_correction_no_std_dep_a.header.iod_atmo = 236; + + test_msg.ssr_gridded_correction_no_std_dep_a.header.num_msgs = 62837; + + test_msg.ssr_gridded_correction_no_std_dep_a.header.seq_num = 63555; + + test_msg.ssr_gridded_correction_no_std_dep_a.header.time.tow = 2837573811; + + test_msg.ssr_gridded_correction_no_std_dep_a.header.time.wn = 8940; + + test_msg.ssr_gridded_correction_no_std_dep_a.header + .tropo_quality_indicator = 230; + + test_msg.ssr_gridded_correction_no_std_dep_a.header.update_interval = 233; + + test_msg.ssr_gridded_correction_no_std_dep_a.index = 26598; + + test_msg.ssr_gridded_correction_no_std_dep_a.n_stec_residuals = 59; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0].residual = + -23949; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .sv_id.constellation = 157; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0].sv_id.satId = + 231; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1].residual = + 27427; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .sv_id.constellation = 146; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1].sv_id.satId = + 197; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2].residual = + 10548; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .sv_id.constellation = 109; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2].sv_id.satId = + 222; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3].residual = + -18195; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .sv_id.constellation = 12; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3].sv_id.satId = + 86; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4].residual = + -27511; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .sv_id.constellation = 204; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4].sv_id.satId = + 65; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5].residual = + 11; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .sv_id.constellation = 183; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5].sv_id.satId = + 171; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6].residual = + 13740; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .sv_id.constellation = 203; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6].sv_id.satId = + 180; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7].residual = + 29626; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .sv_id.constellation = 85; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7].sv_id.satId = + 196; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8].residual = + 7846; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .sv_id.constellation = 92; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8].sv_id.satId = + 203; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9].residual = + 18376; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .sv_id.constellation = 13; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9].sv_id.satId = + 42; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10].residual = + -24357; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.constellation = 137; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.satId = 98; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11].residual = + -1441; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.constellation = 216; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.satId = 95; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12].residual = + -10660; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.constellation = 196; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.satId = 99; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13].residual = + -8509; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.constellation = 253; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.satId = 159; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14].residual = + 16361; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.constellation = 146; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.satId = 233; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15].residual = + 10346; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.constellation = 24; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.satId = 76; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16].residual = + -18679; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.constellation = 65; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.satId = 253; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17].residual = + 15292; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.constellation = 215; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.satId = 40; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18].residual = + 29537; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.constellation = 69; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.satId = 117; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19].residual = + -29440; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.constellation = 56; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.satId = 60; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20].residual = + -24266; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.constellation = 171; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.satId = 207; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21].residual = + 22272; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.constellation = 61; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.satId = 23; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22].residual = + 9303; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.constellation = 123; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.satId = 230; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23].residual = + -23794; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.constellation = 255; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.satId = 184; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24].residual = + -26837; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.constellation = 224; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.satId = 187; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25].residual = + 14631; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.constellation = 104; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.satId = 151; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26].residual = + -8144; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.constellation = 54; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.satId = 5; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27].residual = + 23612; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.constellation = 129; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.satId = 181; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28].residual = + 28013; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.constellation = 114; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.satId = 171; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29].residual = + 2166; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.constellation = 23; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.satId = 12; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30].residual = + -10186; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.constellation = 159; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.satId = 64; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31].residual = + 17432; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.constellation = 20; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.satId = 33; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32].residual = + -8666; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.constellation = 36; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.satId = 160; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33].residual = + 25436; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.constellation = 190; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.satId = 145; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34].residual = + -3864; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.constellation = 159; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.satId = 108; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35].residual = + 4093; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.constellation = 221; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.satId = 227; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36].residual = + -18055; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.constellation = 23; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.satId = 62; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37].residual = + -27900; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.constellation = 116; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.satId = 168; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38].residual = + 30687; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.constellation = 72; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.satId = 123; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39].residual = + -13151; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.constellation = 242; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.satId = 226; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40].residual = + -22903; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.constellation = 202; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.satId = 180; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41].residual = + 4988; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.constellation = 24; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.satId = 58; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42].residual = + 27408; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.constellation = 188; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.satId = 181; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43].residual = + 319; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.constellation = 231; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.satId = 66; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44].residual = + 15987; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.constellation = 252; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.satId = 64; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45].residual = + 22266; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.constellation = 97; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.satId = 233; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46].residual = + -19919; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.constellation = 221; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.satId = 156; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47].residual = + 17350; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.constellation = 73; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.satId = 32; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48].residual = + 14410; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.constellation = 253; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.satId = 249; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49].residual = + 23671; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.constellation = 165; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.satId = 38; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50].residual = + -31905; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.constellation = 44; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.satId = 99; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51].residual = + 14305; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.constellation = 192; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.satId = 89; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52].residual = + -12968; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.constellation = 171; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.satId = 95; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53].residual = + 21479; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.constellation = 116; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.satId = 21; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54].residual = + 28260; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.constellation = 71; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.satId = 71; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55].residual = + -11112; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.constellation = 254; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.satId = 217; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56].residual = + -25304; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.constellation = 8; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.satId = 18; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57].residual = + -4024; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.constellation = 54; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.satId = 244; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58].residual = + -15505; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.constellation = 189; + + test_msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.satId = 231; + + test_msg.ssr_gridded_correction_no_std_dep_a.tropo_delay_correction.hydro = + 16250; + + test_msg.ssr_gridded_correction_no_std_dep_a.tropo_delay_correction.wet = + 101; + + sbp_message_send(&sbp_state, SbpMsgSsrGriddedCorrectionNoStdDepA, 7270, + &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 7270, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrGriddedCorrectionNoStdDepA, + &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.iod_atmo == 236, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.iod_atmo, " + "expected 236, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.iod_atmo); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.num_msgs == + 62837, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.num_msgs, " + "expected 62837, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.num_msgs); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.seq_num == + 63555, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.seq_num, " + "expected 63555, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.seq_num); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.tow == + 2837573811, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.tow, " + "expected 2837573811, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.tow); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.wn == 8940, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.wn, " + "expected 8940, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header.time.wn); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_no_std_dep_a.header + .tropo_quality_indicator == 230, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header." + "tropo_quality_indicator, expected 230, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header + .tropo_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_no_std_dep_a.header + .update_interval == 233, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.header." + "update_interval, expected 233, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.header + .update_interval); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.index == 26598, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.index, expected " + "26598, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.index); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.n_stec_residuals == 59, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.n_stec_residuals, " + "expected 59, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.n_stec_residuals); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .residual == -23949, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0]." + "residual, expected -23949, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .sv_id.constellation == 157, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0].sv_" + "id.constellation, expected 157, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .sv_id.satId == 231, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0].sv_" + "id.satId, expected 231, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[0] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .residual == 27427, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1]." + "residual, expected 27427, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .sv_id.constellation == 146, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1].sv_" + "id.constellation, expected 146, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .sv_id.satId == 197, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1].sv_" + "id.satId, expected 197, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[1] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .residual == 10548, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2]." + "residual, expected 10548, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .sv_id.constellation == 109, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2].sv_" + "id.constellation, expected 109, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .sv_id.satId == 222, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2].sv_" + "id.satId, expected 222, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[2] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .residual == -18195, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3]." + "residual, expected -18195, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .sv_id.constellation == 12, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3].sv_" + "id.constellation, expected 12, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .sv_id.satId == 86, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3].sv_" + "id.satId, expected 86, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[3] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .residual == -27511, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4]." + "residual, expected -27511, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .sv_id.constellation == 204, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4].sv_" + "id.constellation, expected 204, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .sv_id.satId == 65, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4].sv_" + "id.satId, expected 65, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[4] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .residual == 11, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5]." + "residual, expected 11, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .sv_id.constellation == 183, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5].sv_" + "id.constellation, expected 183, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .sv_id.satId == 171, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5].sv_" + "id.satId, expected 171, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[5] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .residual == 13740, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6]." + "residual, expected 13740, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .sv_id.constellation == 203, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6].sv_" + "id.constellation, expected 203, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .sv_id.satId == 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6].sv_" + "id.satId, expected 180, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[6] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .residual == 29626, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7]." + "residual, expected 29626, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .sv_id.constellation == 85, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7].sv_" + "id.constellation, expected 85, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .sv_id.satId == 196, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7].sv_" + "id.satId, expected 196, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[7] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .residual == 7846, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8]." + "residual, expected 7846, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .sv_id.constellation == 92, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8].sv_" + "id.constellation, expected 92, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .sv_id.satId == 203, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8].sv_" + "id.satId, expected 203, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[8] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .residual == 18376, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9]." + "residual, expected 18376, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .sv_id.constellation == 13, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9].sv_" + "id.constellation, expected 13, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .sv_id.satId == 42, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9].sv_" + "id.satId, expected 42, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[9] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .residual == -24357, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10]." + "residual, expected -24357, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.constellation == 137, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10]." + "sv_id.constellation, expected 137, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.satId == 98, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10]." + "sv_id.satId, expected 98, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[10] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .residual == -1441, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11]." + "residual, expected -1441, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.constellation == 216, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11]." + "sv_id.constellation, expected 216, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.satId == 95, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11]." + "sv_id.satId, expected 95, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[11] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .residual == -10660, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12]." + "residual, expected -10660, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.constellation == 196, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12]." + "sv_id.constellation, expected 196, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.satId == 99, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12]." + "sv_id.satId, expected 99, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[12] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .residual == -8509, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13]." + "residual, expected -8509, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.constellation == 253, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13]." + "sv_id.constellation, expected 253, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.satId == 159, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13]." + "sv_id.satId, expected 159, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[13] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .residual == 16361, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14]." + "residual, expected 16361, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.constellation == 146, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14]." + "sv_id.constellation, expected 146, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.satId == 233, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14]." + "sv_id.satId, expected 233, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[14] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .residual == 10346, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15]." + "residual, expected 10346, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.constellation == 24, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15]." + "sv_id.constellation, expected 24, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.satId == 76, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15]." + "sv_id.satId, expected 76, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[15] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .residual == -18679, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16]." + "residual, expected -18679, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.constellation == 65, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16]." + "sv_id.constellation, expected 65, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.satId == 253, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16]." + "sv_id.satId, expected 253, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[16] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .residual == 15292, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17]." + "residual, expected 15292, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.constellation == 215, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17]." + "sv_id.constellation, expected 215, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.satId == 40, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17]." + "sv_id.satId, expected 40, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[17] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .residual == 29537, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18]." + "residual, expected 29537, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.constellation == 69, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18]." + "sv_id.constellation, expected 69, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.satId == 117, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18]." + "sv_id.satId, expected 117, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[18] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .residual == -29440, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19]." + "residual, expected -29440, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.constellation == 56, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19]." + "sv_id.constellation, expected 56, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.satId == 60, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19]." + "sv_id.satId, expected 60, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[19] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .residual == -24266, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20]." + "residual, expected -24266, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.constellation == 171, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20]." + "sv_id.constellation, expected 171, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.satId == 207, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20]." + "sv_id.satId, expected 207, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[20] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .residual == 22272, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21]." + "residual, expected 22272, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.constellation == 61, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21]." + "sv_id.constellation, expected 61, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.satId == 23, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21]." + "sv_id.satId, expected 23, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[21] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .residual == 9303, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22]." + "residual, expected 9303, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.constellation == 123, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22]." + "sv_id.constellation, expected 123, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.satId == 230, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22]." + "sv_id.satId, expected 230, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[22] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .residual == -23794, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23]." + "residual, expected -23794, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.constellation == 255, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23]." + "sv_id.constellation, expected 255, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.satId == 184, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23]." + "sv_id.satId, expected 184, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[23] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .residual == -26837, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24]." + "residual, expected -26837, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.constellation == 224, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24]." + "sv_id.constellation, expected 224, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.satId == 187, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24]." + "sv_id.satId, expected 187, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[24] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .residual == 14631, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25]." + "residual, expected 14631, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.constellation == 104, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25]." + "sv_id.constellation, expected 104, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.satId == 151, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25]." + "sv_id.satId, expected 151, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[25] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .residual == -8144, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26]." + "residual, expected -8144, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.constellation == 54, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26]." + "sv_id.constellation, expected 54, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.satId == 5, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26]." + "sv_id.satId, expected 5, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[26] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .residual == 23612, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27]." + "residual, expected 23612, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.constellation == 129, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27]." + "sv_id.constellation, expected 129, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.satId == 181, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27]." + "sv_id.satId, expected 181, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[27] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .residual == 28013, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28]." + "residual, expected 28013, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.constellation == 114, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28]." + "sv_id.constellation, expected 114, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.satId == 171, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28]." + "sv_id.satId, expected 171, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[28] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .residual == 2166, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29]." + "residual, expected 2166, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.constellation == 23, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29]." + "sv_id.constellation, expected 23, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.satId == 12, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29]." + "sv_id.satId, expected 12, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[29] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .residual == -10186, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30]." + "residual, expected -10186, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.constellation == 159, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30]." + "sv_id.constellation, expected 159, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.satId == 64, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30]." + "sv_id.satId, expected 64, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[30] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .residual == 17432, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31]." + "residual, expected 17432, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.constellation == 20, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31]." + "sv_id.constellation, expected 20, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.satId == 33, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31]." + "sv_id.satId, expected 33, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[31] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .residual == -8666, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32]." + "residual, expected -8666, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.constellation == 36, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32]." + "sv_id.constellation, expected 36, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.satId == 160, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32]." + "sv_id.satId, expected 160, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[32] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .residual == 25436, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33]." + "residual, expected 25436, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.constellation == 190, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33]." + "sv_id.constellation, expected 190, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.satId == 145, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33]." + "sv_id.satId, expected 145, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[33] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .residual == -3864, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34]." + "residual, expected -3864, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.constellation == 159, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34]." + "sv_id.constellation, expected 159, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.satId == 108, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34]." + "sv_id.satId, expected 108, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[34] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .residual == 4093, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35]." + "residual, expected 4093, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.constellation == 221, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35]." + "sv_id.constellation, expected 221, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.satId == 227, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35]." + "sv_id.satId, expected 227, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[35] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .residual == -18055, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36]." + "residual, expected -18055, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.constellation == 23, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36]." + "sv_id.constellation, expected 23, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.satId == 62, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36]." + "sv_id.satId, expected 62, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[36] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .residual == -27900, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37]." + "residual, expected -27900, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.constellation == 116, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37]." + "sv_id.constellation, expected 116, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.satId == 168, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37]." + "sv_id.satId, expected 168, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[37] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .residual == 30687, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38]." + "residual, expected 30687, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.constellation == 72, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38]." + "sv_id.constellation, expected 72, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.satId == 123, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38]." + "sv_id.satId, expected 123, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[38] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .residual == -13151, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39]." + "residual, expected -13151, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.constellation == 242, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39]." + "sv_id.constellation, expected 242, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.satId == 226, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39]." + "sv_id.satId, expected 226, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[39] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .residual == -22903, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40]." + "residual, expected -22903, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.constellation == 202, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40]." + "sv_id.constellation, expected 202, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.satId == 180, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40]." + "sv_id.satId, expected 180, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[40] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .residual == 4988, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41]." + "residual, expected 4988, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.constellation == 24, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41]." + "sv_id.constellation, expected 24, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.satId == 58, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41]." + "sv_id.satId, expected 58, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[41] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .residual == 27408, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42]." + "residual, expected 27408, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.constellation == 188, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42]." + "sv_id.constellation, expected 188, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.satId == 181, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42]." + "sv_id.satId, expected 181, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[42] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .residual == 319, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43]." + "residual, expected 319, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.constellation == 231, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43]." + "sv_id.constellation, expected 231, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.satId == 66, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43]." + "sv_id.satId, expected 66, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[43] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .residual == 15987, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44]." + "residual, expected 15987, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.constellation == 252, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44]." + "sv_id.constellation, expected 252, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.satId == 64, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44]." + "sv_id.satId, expected 64, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[44] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .residual == 22266, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45]." + "residual, expected 22266, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.constellation == 97, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45]." + "sv_id.constellation, expected 97, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.satId == 233, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45]." + "sv_id.satId, expected 233, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[45] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .residual == -19919, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46]." + "residual, expected -19919, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.constellation == 221, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46]." + "sv_id.constellation, expected 221, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.satId == 156, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46]." + "sv_id.satId, expected 156, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[46] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .residual == 17350, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47]." + "residual, expected 17350, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.constellation == 73, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47]." + "sv_id.constellation, expected 73, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.satId == 32, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47]." + "sv_id.satId, expected 32, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[47] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .residual == 14410, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48]." + "residual, expected 14410, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.constellation == 253, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48]." + "sv_id.constellation, expected 253, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.satId == 249, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48]." + "sv_id.satId, expected 249, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[48] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .residual == 23671, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49]." + "residual, expected 23671, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.constellation == 165, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49]." + "sv_id.constellation, expected 165, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.satId == 38, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49]." + "sv_id.satId, expected 38, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[49] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .residual == -31905, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50]." + "residual, expected -31905, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.constellation == 44, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50]." + "sv_id.constellation, expected 44, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.satId == 99, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50]." + "sv_id.satId, expected 99, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[50] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .residual == 14305, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51]." + "residual, expected 14305, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.constellation == 192, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51]." + "sv_id.constellation, expected 192, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.satId == 89, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51]." + "sv_id.satId, expected 89, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[51] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .residual == -12968, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52]." + "residual, expected -12968, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.constellation == 171, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52]." + "sv_id.constellation, expected 171, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.satId == 95, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52]." + "sv_id.satId, expected 95, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[52] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .residual == 21479, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53]." + "residual, expected 21479, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.constellation == 116, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53]." + "sv_id.constellation, expected 116, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.satId == 21, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53]." + "sv_id.satId, expected 21, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[53] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .residual == 28260, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54]." + "residual, expected 28260, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.constellation == 71, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54]." + "sv_id.constellation, expected 71, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.satId == 71, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54]." + "sv_id.satId, expected 71, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[54] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .residual == -11112, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55]." + "residual, expected -11112, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.constellation == 254, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55]." + "sv_id.constellation, expected 254, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.satId == 217, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55]." + "sv_id.satId, expected 217, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[55] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .residual == -25304, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56]." + "residual, expected -25304, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.constellation == 8, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56]." + "sv_id.constellation, expected 8, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.satId == 18, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56]." + "sv_id.satId, expected 18, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[56] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .residual == -4024, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57]." + "residual, expected -4024, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.constellation == 54, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57]." + "sv_id.constellation, expected 54, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.satId == 244, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57]." + "sv_id.satId, expected 244, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[57] + .sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .residual == -15505, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58]." + "residual, expected -15505, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .residual); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.constellation == 189, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58]." + "sv_id.constellation, expected 189, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.satId == 231, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58]." + "sv_id.satId, expected 231, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a.stec_residuals[58] + .sv_id.satId); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_no_std_dep_a + .tropo_delay_correction.hydro == 16250, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.tropo_" + "delay_correction.hydro, expected 16250, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a + .tropo_delay_correction.hydro); + + ck_assert_msg(last_msg.msg.ssr_gridded_correction_no_std_dep_a + .tropo_delay_correction.wet == 101, + "incorrect value for " + "last_msg.msg.ssr_gridded_correction_no_std_dep_a.tropo_" + "delay_correction.wet, expected 101, is %d", + last_msg.msg.ssr_gridded_correction_no_std_dep_a + .tropo_delay_correction.wet); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA"); + tcase_add_test(tc_acq, + test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrOrbitClock.c b/c/test/auto_check_sbp_ssr_MsgSsrOrbitClock.c new file mode 100644 index 0000000000..46611abed5 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrOrbitClock.c @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrOrbitClock) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5dd, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, + 203, 212, 236, 255, 152, 233, 207, 55, 94, 54, 58, 128, + 68, 27, 117, 176, 110, 251, 61, 244, 122, 50, 95, 52, + 144, 232, 24, 10, 37, 127, 163, 66, 177, 105, 156, 245, + 10, 249, 107, 218, 17, 186, 56, 72, 14, 22, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_orbit_clock.along = -1334502588; + + test_msg.ssr_orbit_clock.c0 = -174298703; + + test_msg.ssr_orbit_clock.c1 = -630458102; + + test_msg.ssr_orbit_clock.c2 = 1211677201; + + test_msg.ssr_orbit_clock.cross = -197264530; + + test_msg.ssr_orbit_clock.dot_along = 169404560; + + test_msg.ssr_orbit_clock.dot_cross = 1118011173; + + test_msg.ssr_orbit_clock.dot_radial = 878654074; + + test_msg.ssr_orbit_clock.iod = 936372632; + + test_msg.ssr_orbit_clock.iod_ssr = 255; + + test_msg.ssr_orbit_clock.radial = -2143668642; + + test_msg.ssr_orbit_clock.sid.code = 212; + + test_msg.ssr_orbit_clock.sid.sat = 203; + + test_msg.ssr_orbit_clock.time.tow = 3479621715; + + test_msg.ssr_orbit_clock.time.wn = 7588; + + test_msg.ssr_orbit_clock.update_interval = 236; + + sbp_message_send(&sbp_state, SbpMsgSsrOrbitClock, 58677, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 58677, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSsrOrbitClock, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.along == -1334502588, + "incorrect value for last_msg.msg.ssr_orbit_clock.along, " + "expected -1334502588, is %d", + last_msg.msg.ssr_orbit_clock.along); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.c0 == -174298703, + "incorrect value for last_msg.msg.ssr_orbit_clock.c0, " + "expected -174298703, is %d", + last_msg.msg.ssr_orbit_clock.c0); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.c1 == -630458102, + "incorrect value for last_msg.msg.ssr_orbit_clock.c1, " + "expected -630458102, is %d", + last_msg.msg.ssr_orbit_clock.c1); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.c2 == 1211677201, + "incorrect value for last_msg.msg.ssr_orbit_clock.c2, " + "expected 1211677201, is %d", + last_msg.msg.ssr_orbit_clock.c2); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.cross == -197264530, + "incorrect value for last_msg.msg.ssr_orbit_clock.cross, " + "expected -197264530, is %d", + last_msg.msg.ssr_orbit_clock.cross); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.dot_along == 169404560, + "incorrect value for last_msg.msg.ssr_orbit_clock.dot_along, " + "expected 169404560, is %d", + last_msg.msg.ssr_orbit_clock.dot_along); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.dot_cross == 1118011173, + "incorrect value for last_msg.msg.ssr_orbit_clock.dot_cross, " + "expected 1118011173, is %d", + last_msg.msg.ssr_orbit_clock.dot_cross); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock.dot_radial == 878654074, + "incorrect value for last_msg.msg.ssr_orbit_clock.dot_radial, expected " + "878654074, is %d", + last_msg.msg.ssr_orbit_clock.dot_radial); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.iod == 936372632, + "incorrect value for last_msg.msg.ssr_orbit_clock.iod, " + "expected 936372632, is %d", + last_msg.msg.ssr_orbit_clock.iod); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.iod_ssr == 255, + "incorrect value for last_msg.msg.ssr_orbit_clock.iod_ssr, " + "expected 255, is %d", + last_msg.msg.ssr_orbit_clock.iod_ssr); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.radial == -2143668642, + "incorrect value for last_msg.msg.ssr_orbit_clock.radial, " + "expected -2143668642, is %d", + last_msg.msg.ssr_orbit_clock.radial); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.sid.code == 212, + "incorrect value for last_msg.msg.ssr_orbit_clock.sid.code, " + "expected 212, is %d", + last_msg.msg.ssr_orbit_clock.sid.code); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.sid.sat == 203, + "incorrect value for last_msg.msg.ssr_orbit_clock.sid.sat, " + "expected 203, is %d", + last_msg.msg.ssr_orbit_clock.sid.sat); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.time.tow == 3479621715, + "incorrect value for last_msg.msg.ssr_orbit_clock.time.tow, " + "expected 3479621715, is %d", + last_msg.msg.ssr_orbit_clock.time.tow); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock.time.wn == 7588, + "incorrect value for last_msg.msg.ssr_orbit_clock.time.wn, " + "expected 7588, is %d", + last_msg.msg.ssr_orbit_clock.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock.update_interval == 236, + "incorrect value for last_msg.msg.ssr_orbit_clock.update_interval, " + "expected 236, is %d", + last_msg.msg.ssr_orbit_clock.update_interval); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrOrbitClock_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrOrbitClock"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ssr_MsgSsrOrbitClock"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrOrbitClock); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c new file mode 100644 index 0000000000..2255a0aaf2 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrOrbitClockDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5dc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, + 194, 211, 193, 175, 161, 143, 254, 56, 63, 232, 7, 216, 69, 1, + 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, 151, 18, 171, + 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_orbit_clock_dep_a.along = 132661048; + + test_msg.ssr_orbit_clock_dep_a.c0 = -970026069; + + test_msg.ssr_orbit_clock_dep_a.c1 = -503975083; + + test_msg.ssr_orbit_clock_dep_a.c2 = -759858197; + + test_msg.ssr_orbit_clock_dep_a.cross = 1845577176; + + test_msg.ssr_orbit_clock_dep_a.dot_along = 72905755; + + test_msg.ssr_orbit_clock_dep_a.dot_cross = 311886653; + + test_msg.ssr_orbit_clock_dep_a.dot_radial = -1111196507; + + test_msg.ssr_orbit_clock_dep_a.iod = 193; + + test_msg.ssr_orbit_clock_dep_a.iod_ssr = 211; + + test_msg.ssr_orbit_clock_dep_a.radial = -24141393; + + test_msg.ssr_orbit_clock_dep_a.sid.code = 30; + + test_msg.ssr_orbit_clock_dep_a.sid.sat = 1; + + test_msg.ssr_orbit_clock_dep_a.time.tow = 3172954849; + + test_msg.ssr_orbit_clock_dep_a.time.wn = 7723; + + test_msg.ssr_orbit_clock_dep_a.update_interval = 194; + + sbp_message_send(&sbp_state, SbpMsgSsrOrbitClockDepA, 42529, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 42529, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSsrOrbitClockDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.along == 132661048, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.along, " + "expected 132661048, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.along); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock_dep_a.c0 == -970026069, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.c0, " + "expected -970026069, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.c0); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock_dep_a.c1 == -503975083, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.c1, " + "expected -503975083, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.c1); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock_dep_a.c2 == -759858197, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.c2, " + "expected -759858197, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.c2); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.cross == 1845577176, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.cross, " + "expected 1845577176, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.cross); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.dot_along == 72905755, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.dot_along, " + "expected 72905755, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.dot_along); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.dot_cross == 311886653, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.dot_cross, " + "expected 311886653, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.dot_cross); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.dot_radial == -1111196507, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.dot_radial, " + "expected -1111196507, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.dot_radial); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock_dep_a.iod == 193, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.iod, " + "expected 193, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.iod); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.iod_ssr == 211, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.iod_ssr, " + "expected 211, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.iod_ssr); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.radial == -24141393, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.radial, " + "expected -24141393, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.radial); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.sid.code == 30, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.sid.code, " + "expected 30, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.sid.code); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.sid.sat == 1, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.sid.sat, " + "expected 1, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.time.tow == 3172954849, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.time.tow, " + "expected 3172954849, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.time.tow); + + ck_assert_msg( + last_msg.msg.ssr_orbit_clock_dep_a.time.wn == 7723, + "incorrect value for last_msg.msg.ssr_orbit_clock_dep_a.time.wn, " + "expected 7723, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.time.wn); + + ck_assert_msg(last_msg.msg.ssr_orbit_clock_dep_a.update_interval == 194, + "incorrect value for " + "last_msg.msg.ssr_orbit_clock_dep_a.update_interval, " + "expected 194, is %d", + last_msg.msg.ssr_orbit_clock_dep_a.update_interval); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrOrbitClockDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ssr_MsgSsrOrbitClockDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrOrbitClockDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrPhaseBiases.c b/c/test/auto_check_sbp_ssr_MsgSsrPhaseBiases.c new file mode 100644 index 0000000000..d4d391b2e0 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrPhaseBiases.c @@ -0,0 +1,1558 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrPhaseBiases) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5e6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, + 177, 230, 98, 209, 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, + 177, 207, 187, 33, 146, 58, 204, 164, 65, 114, 49, 248, 52, 8, + 161, 44, 252, 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, + 155, 129, 143, 184, 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, + 203, 87, 34, 188, 141, 104, 189, 102, 156, 252, 22, 251, 136, 49, + 188, 157, 222, 245, 49, 132, 16, 34, 142, 228, 85, 139, 221, 197, + 235, 98, 74, 107, 70, 36, 38, 239, 251, 112, 188, 124, 246, 141, + 164, 150, 104, 7, 213, 44, 21, 244, 192, 4, 143, 24, 42, 21, + 84, 136, 7, 42, 118, 45, 23, 174, 175, 129, 54, 169, 14, 213, + 2, 197, 98, 60, 13, 207, 105, 100, 129, 72, 136, 240, 140, 129, + 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, 242, 254, 215, + 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, 97, 36, + 207, 92, 224, 26, 116, 155, 211, 165, 47, 102, 38, 67, 199, 55, + 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, 62, 147, 173, 173, + 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, + 207, 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, + 75, 230, 26, 213, 181, 56, 64, 97, 88, 255, 6, 147, 16, 89, + 203, 27, 68, 243, 230, 55, 242, 167, 169, 219, 240, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_phase_biases.biases[0].bias = -1311498533; + + test_msg.ssr_phase_biases.biases[0].code = 29; + + test_msg.ssr_phase_biases.biases[0].discontinuity_counter = 193; + + test_msg.ssr_phase_biases.biases[0].integer_indicator = 250; + + test_msg.ssr_phase_biases.biases[0].widelane_integer_indicator = 245; + + test_msg.ssr_phase_biases.biases[1].bias = 1101319226; + + test_msg.ssr_phase_biases.biases[1].code = 207; + + test_msg.ssr_phase_biases.biases[1].discontinuity_counter = 146; + + test_msg.ssr_phase_biases.biases[1].integer_indicator = 187; + + test_msg.ssr_phase_biases.biases[1].widelane_integer_indicator = 33; + + test_msg.ssr_phase_biases.biases[2].bias = -64184056; + + test_msg.ssr_phase_biases.biases[2].code = 114; + + test_msg.ssr_phase_biases.biases[2].discontinuity_counter = 52; + + test_msg.ssr_phase_biases.biases[2].integer_indicator = 49; + + test_msg.ssr_phase_biases.biases[2].widelane_integer_indicator = 248; + + test_msg.ssr_phase_biases.biases[3].bias = -240298362; + + test_msg.ssr_phase_biases.biases[3].code = 166; + + test_msg.ssr_phase_biases.biases[3].discontinuity_counter = 124; + + test_msg.ssr_phase_biases.biases[3].integer_indicator = 168; + + test_msg.ssr_phase_biases.biases[3].widelane_integer_indicator = 232; + + test_msg.ssr_phase_biases.biases[4].bias = -1581740159; + + test_msg.ssr_phase_biases.biases[4].code = 174; + + test_msg.ssr_phase_biases.biases[4].discontinuity_counter = 155; + + test_msg.ssr_phase_biases.biases[4].integer_indicator = 44; + + test_msg.ssr_phase_biases.biases[4].widelane_integer_indicator = 142; + + test_msg.ssr_phase_biases.biases[5].bias = -1730297136; + + test_msg.ssr_phase_biases.biases[5].code = 211; + + test_msg.ssr_phase_biases.biases[5].discontinuity_counter = 189; + + test_msg.ssr_phase_biases.biases[5].integer_indicator = 15; + + test_msg.ssr_phase_biases.biases[5].widelane_integer_indicator = 36; + + test_msg.ssr_phase_biases.biases[6].bias = -1117221444; + + test_msg.ssr_phase_biases.biases[6].code = 16; + + test_msg.ssr_phase_biases.biases[6].discontinuity_counter = 34; + + test_msg.ssr_phase_biases.biases[6].integer_indicator = 203; + + test_msg.ssr_phase_biases.biases[6].widelane_integer_indicator = 87; + + test_msg.ssr_phase_biases.biases[7].bias = -1137604357; + + test_msg.ssr_phase_biases.biases[7].code = 102; + + test_msg.ssr_phase_biases.biases[7].discontinuity_counter = 22; + + test_msg.ssr_phase_biases.biases[7].integer_indicator = 156; + + test_msg.ssr_phase_biases.biases[7].widelane_integer_indicator = 252; + + test_msg.ssr_phase_biases.biases[8].bias = -1910370172; + + test_msg.ssr_phase_biases.biases[8].code = 157; + + test_msg.ssr_phase_biases.biases[8].discontinuity_counter = 49; + + test_msg.ssr_phase_biases.biases[8].integer_indicator = 222; + + test_msg.ssr_phase_biases.biases[8].widelane_integer_indicator = 245; + + test_msg.ssr_phase_biases.biases[9].bias = 1247996869; + + test_msg.ssr_phase_biases.biases[9].code = 228; + + test_msg.ssr_phase_biases.biases[9].discontinuity_counter = 221; + + test_msg.ssr_phase_biases.biases[9].integer_indicator = 85; + + test_msg.ssr_phase_biases.biases[9].widelane_integer_indicator = 139; + + test_msg.ssr_phase_biases.biases[10].bias = -1133446161; + + test_msg.ssr_phase_biases.biases[10].code = 107; + + test_msg.ssr_phase_biases.biases[10].discontinuity_counter = 38; + + test_msg.ssr_phase_biases.biases[10].integer_indicator = 70; + + test_msg.ssr_phase_biases.biases[10].widelane_integer_indicator = 36; + + test_msg.ssr_phase_biases.biases[11].bias = -720934762; + + test_msg.ssr_phase_biases.biases[11].code = 124; + + test_msg.ssr_phase_biases.biases[11].discontinuity_counter = 164; + + test_msg.ssr_phase_biases.biases[11].integer_indicator = 246; + + test_msg.ssr_phase_biases.biases[11].widelane_integer_indicator = 141; + + test_msg.ssr_phase_biases.biases[12].bias = 706252548; + + test_msg.ssr_phase_biases.biases[12].code = 44; + + test_msg.ssr_phase_biases.biases[12].discontinuity_counter = 192; + + test_msg.ssr_phase_biases.biases[12].integer_indicator = 21; + + test_msg.ssr_phase_biases.biases[12].widelane_integer_indicator = 244; + + test_msg.ssr_phase_biases.biases[13].bias = 388855338; + + test_msg.ssr_phase_biases.biases[13].code = 21; + + test_msg.ssr_phase_biases.biases[13].discontinuity_counter = 7; + + test_msg.ssr_phase_biases.biases[13].integer_indicator = 84; + + test_msg.ssr_phase_biases.biases[13].widelane_integer_indicator = 136; + + test_msg.ssr_phase_biases.biases[14].bias = 47517353; + + test_msg.ssr_phase_biases.biases[14].code = 174; + + test_msg.ssr_phase_biases.biases[14].discontinuity_counter = 54; + + test_msg.ssr_phase_biases.biases[14].integer_indicator = 175; + + test_msg.ssr_phase_biases.biases[14].widelane_integer_indicator = 129; + + test_msg.ssr_phase_biases.biases[15].bias = -2124125745; + + test_msg.ssr_phase_biases.biases[15].code = 197; + + test_msg.ssr_phase_biases.biases[15].discontinuity_counter = 13; + + test_msg.ssr_phase_biases.biases[15].integer_indicator = 98; + + test_msg.ssr_phase_biases.biases[15].widelane_integer_indicator = 60; + + test_msg.ssr_phase_biases.biases[16].bias = -1401812607; + + test_msg.ssr_phase_biases.biases[16].code = 72; + + test_msg.ssr_phase_biases.biases[16].discontinuity_counter = 140; + + test_msg.ssr_phase_biases.biases[16].integer_indicator = 136; + + test_msg.ssr_phase_biases.biases[16].widelane_integer_indicator = 240; + + test_msg.ssr_phase_biases.biases[17].bias = 60257151; + + test_msg.ssr_phase_biases.biases[17].code = 151; + + test_msg.ssr_phase_biases.biases[17].discontinuity_counter = 210; + + test_msg.ssr_phase_biases.biases[17].integer_indicator = 150; + + test_msg.ssr_phase_biases.biases[17].widelane_integer_indicator = 17; + + test_msg.ssr_phase_biases.biases[18].bias = 41820677; + + test_msg.ssr_phase_biases.biases[18].code = 242; + + test_msg.ssr_phase_biases.biases[18].discontinuity_counter = 14; + + test_msg.ssr_phase_biases.biases[18].integer_indicator = 254; + + test_msg.ssr_phase_biases.biases[18].widelane_integer_indicator = 215; + + test_msg.ssr_phase_biases.biases[19].bias = 1640616471; + + test_msg.ssr_phase_biases.biases[19].code = 215; + + test_msg.ssr_phase_biases.biases[19].discontinuity_counter = 176; + + test_msg.ssr_phase_biases.biases[19].integer_indicator = 65; + + test_msg.ssr_phase_biases.biases[19].widelane_integer_indicator = 38; + + test_msg.ssr_phase_biases.biases[20].bias = -744786918; + + test_msg.ssr_phase_biases.biases[20].code = 36; + + test_msg.ssr_phase_biases.biases[20].discontinuity_counter = 224; + + test_msg.ssr_phase_biases.biases[20].integer_indicator = 207; + + test_msg.ssr_phase_biases.biases[20].widelane_integer_indicator = 92; + + test_msg.ssr_phase_biases.biases[21].bias = 1966589763; + + test_msg.ssr_phase_biases.biases[21].code = 165; + + test_msg.ssr_phase_biases.biases[21].discontinuity_counter = 38; + + test_msg.ssr_phase_biases.biases[21].integer_indicator = 47; + + test_msg.ssr_phase_biases.biases[21].widelane_integer_indicator = 102; + + test_msg.ssr_phase_biases.biases[22].bias = 364366310; + + test_msg.ssr_phase_biases.biases[22].code = 36; + + test_msg.ssr_phase_biases.biases[22].discontinuity_counter = 1; + + test_msg.ssr_phase_biases.biases[22].integer_indicator = 169; + + test_msg.ssr_phase_biases.biases[22].widelane_integer_indicator = 33; + + test_msg.ssr_phase_biases.biases[23].bias = -1839031379; + + test_msg.ssr_phase_biases.biases[23].code = 42; + + test_msg.ssr_phase_biases.biases[23].discontinuity_counter = 173; + + test_msg.ssr_phase_biases.biases[23].integer_indicator = 62; + + test_msg.ssr_phase_biases.biases[23].widelane_integer_indicator = 147; + + test_msg.ssr_phase_biases.biases[24].bias = 31817639; + + test_msg.ssr_phase_biases.biases[24].code = 231; + + test_msg.ssr_phase_biases.biases[24].discontinuity_counter = 82; + + test_msg.ssr_phase_biases.biases[24].integer_indicator = 167; + + test_msg.ssr_phase_biases.biases[24].widelane_integer_indicator = 138; + + test_msg.ssr_phase_biases.biases[25].bias = -1619830156; + + test_msg.ssr_phase_biases.biases[25].code = 2; + + test_msg.ssr_phase_biases.biases[25].discontinuity_counter = 207; + + test_msg.ssr_phase_biases.biases[25].integer_indicator = 127; + + test_msg.ssr_phase_biases.biases[25].widelane_integer_indicator = 237; + + test_msg.ssr_phase_biases.biases[26].bias = -83375622; + + test_msg.ssr_phase_biases.biases[26].code = 3; + + test_msg.ssr_phase_biases.biases[26].discontinuity_counter = 145; + + test_msg.ssr_phase_biases.biases[26].integer_indicator = 42; + + test_msg.ssr_phase_biases.biases[26].widelane_integer_indicator = 66; + + test_msg.ssr_phase_biases.biases[27].bias = 1077458389; + + test_msg.ssr_phase_biases.biases[27].code = 2; + + test_msg.ssr_phase_biases.biases[27].discontinuity_counter = 26; + + test_msg.ssr_phase_biases.biases[27].integer_indicator = 75; + + test_msg.ssr_phase_biases.biases[27].widelane_integer_indicator = 230; + + test_msg.ssr_phase_biases.biases[28].bias = -883355501; + + test_msg.ssr_phase_biases.biases[28].code = 97; + + test_msg.ssr_phase_biases.biases[28].discontinuity_counter = 6; + + test_msg.ssr_phase_biases.biases[28].integer_indicator = 88; + + test_msg.ssr_phase_biases.biases[28].widelane_integer_indicator = 255; + + test_msg.ssr_phase_biases.biases[29].bias = -1448611273; + + test_msg.ssr_phase_biases.biases[29].code = 27; + + test_msg.ssr_phase_biases.biases[29].discontinuity_counter = 230; + + test_msg.ssr_phase_biases.biases[29].integer_indicator = 68; + + test_msg.ssr_phase_biases.biases[29].widelane_integer_indicator = 243; + + test_msg.ssr_phase_biases.dispersive_bias = 98; + + test_msg.ssr_phase_biases.iod_ssr = 230; + + test_msg.ssr_phase_biases.mw_consistency = 209; + + test_msg.ssr_phase_biases.n_biases = 30; + + test_msg.ssr_phase_biases.sid.code = 82; + + test_msg.ssr_phase_biases.sid.sat = 169; + + test_msg.ssr_phase_biases.time.tow = 210803409; + + test_msg.ssr_phase_biases.time.wn = 42197; + + test_msg.ssr_phase_biases.update_interval = 177; + + test_msg.ssr_phase_biases.yaw = 5881; + + test_msg.ssr_phase_biases.yaw_rate = 17; + + sbp_message_send(&sbp_state, SbpMsgSsrPhaseBiases, 52955, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52955, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgSsrPhaseBiases, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[0].bias == -1311498533, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[0].bias, " + "expected -1311498533, is %d", + last_msg.msg.ssr_phase_biases.biases[0].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[0].code == 29, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[0].code, " + "expected 29, is %d", + last_msg.msg.ssr_phase_biases.biases[0].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[0].discontinuity_counter == 193, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[0].discontinuity_counter, " + "expected 193, is %d", + last_msg.msg.ssr_phase_biases.biases[0].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[0].integer_indicator == 250, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[0].integer_indicator, expected " + "250, is %d", + last_msg.msg.ssr_phase_biases.biases[0].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[0].widelane_integer_indicator == + 245, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[0].widelane_integer_indicator, " + "expected 245, is %d", + last_msg.msg.ssr_phase_biases.biases[0].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[1].bias == 1101319226, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[1].bias, " + "expected 1101319226, is %d", + last_msg.msg.ssr_phase_biases.biases[1].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[1].code == 207, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[1].code, " + "expected 207, is %d", + last_msg.msg.ssr_phase_biases.biases[1].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[1].discontinuity_counter == 146, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[1].discontinuity_counter, " + "expected 146, is %d", + last_msg.msg.ssr_phase_biases.biases[1].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[1].integer_indicator == 187, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[1].integer_indicator, expected " + "187, is %d", + last_msg.msg.ssr_phase_biases.biases[1].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[1].widelane_integer_indicator == + 33, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[1].widelane_integer_indicator, " + "expected 33, is %d", + last_msg.msg.ssr_phase_biases.biases[1].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[2].bias == -64184056, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[2].bias, " + "expected -64184056, is %d", + last_msg.msg.ssr_phase_biases.biases[2].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[2].code == 114, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[2].code, " + "expected 114, is %d", + last_msg.msg.ssr_phase_biases.biases[2].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[2].discontinuity_counter == 52, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[2].discontinuity_counter, " + "expected 52, is %d", + last_msg.msg.ssr_phase_biases.biases[2].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[2].integer_indicator == 49, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[2].integer_indicator, expected " + "49, is %d", + last_msg.msg.ssr_phase_biases.biases[2].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[2].widelane_integer_indicator == + 248, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[2].widelane_integer_indicator, " + "expected 248, is %d", + last_msg.msg.ssr_phase_biases.biases[2].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[3].bias == -240298362, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[3].bias, " + "expected -240298362, is %d", + last_msg.msg.ssr_phase_biases.biases[3].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[3].code == 166, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[3].code, " + "expected 166, is %d", + last_msg.msg.ssr_phase_biases.biases[3].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[3].discontinuity_counter == 124, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[3].discontinuity_counter, " + "expected 124, is %d", + last_msg.msg.ssr_phase_biases.biases[3].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[3].integer_indicator == 168, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[3].integer_indicator, expected " + "168, is %d", + last_msg.msg.ssr_phase_biases.biases[3].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[3].widelane_integer_indicator == + 232, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[3].widelane_integer_indicator, " + "expected 232, is %d", + last_msg.msg.ssr_phase_biases.biases[3].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[4].bias == -1581740159, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[4].bias, " + "expected -1581740159, is %d", + last_msg.msg.ssr_phase_biases.biases[4].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[4].code == 174, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[4].code, " + "expected 174, is %d", + last_msg.msg.ssr_phase_biases.biases[4].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[4].discontinuity_counter == 155, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[4].discontinuity_counter, " + "expected 155, is %d", + last_msg.msg.ssr_phase_biases.biases[4].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[4].integer_indicator == 44, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[4].integer_indicator, expected " + "44, is %d", + last_msg.msg.ssr_phase_biases.biases[4].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[4].widelane_integer_indicator == + 142, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[4].widelane_integer_indicator, " + "expected 142, is %d", + last_msg.msg.ssr_phase_biases.biases[4].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[5].bias == -1730297136, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[5].bias, " + "expected -1730297136, is %d", + last_msg.msg.ssr_phase_biases.biases[5].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[5].code == 211, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[5].code, " + "expected 211, is %d", + last_msg.msg.ssr_phase_biases.biases[5].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[5].discontinuity_counter == 189, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[5].discontinuity_counter, " + "expected 189, is %d", + last_msg.msg.ssr_phase_biases.biases[5].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[5].integer_indicator == 15, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[5].integer_indicator, expected " + "15, is %d", + last_msg.msg.ssr_phase_biases.biases[5].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[5].widelane_integer_indicator == + 36, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[5].widelane_integer_indicator, " + "expected 36, is %d", + last_msg.msg.ssr_phase_biases.biases[5].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[6].bias == -1117221444, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[6].bias, " + "expected -1117221444, is %d", + last_msg.msg.ssr_phase_biases.biases[6].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[6].code == 16, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[6].code, " + "expected 16, is %d", + last_msg.msg.ssr_phase_biases.biases[6].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[6].discontinuity_counter == 34, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[6].discontinuity_counter, " + "expected 34, is %d", + last_msg.msg.ssr_phase_biases.biases[6].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[6].integer_indicator == 203, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[6].integer_indicator, expected " + "203, is %d", + last_msg.msg.ssr_phase_biases.biases[6].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[6].widelane_integer_indicator == + 87, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[6].widelane_integer_indicator, " + "expected 87, is %d", + last_msg.msg.ssr_phase_biases.biases[6].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[7].bias == -1137604357, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[7].bias, " + "expected -1137604357, is %d", + last_msg.msg.ssr_phase_biases.biases[7].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[7].code == 102, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[7].code, " + "expected 102, is %d", + last_msg.msg.ssr_phase_biases.biases[7].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[7].discontinuity_counter == 22, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[7].discontinuity_counter, " + "expected 22, is %d", + last_msg.msg.ssr_phase_biases.biases[7].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[7].integer_indicator == 156, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[7].integer_indicator, expected " + "156, is %d", + last_msg.msg.ssr_phase_biases.biases[7].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[7].widelane_integer_indicator == + 252, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[7].widelane_integer_indicator, " + "expected 252, is %d", + last_msg.msg.ssr_phase_biases.biases[7].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[8].bias == -1910370172, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[8].bias, " + "expected -1910370172, is %d", + last_msg.msg.ssr_phase_biases.biases[8].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[8].code == 157, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[8].code, " + "expected 157, is %d", + last_msg.msg.ssr_phase_biases.biases[8].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[8].discontinuity_counter == 49, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[8].discontinuity_counter, " + "expected 49, is %d", + last_msg.msg.ssr_phase_biases.biases[8].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[8].integer_indicator == 222, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[8].integer_indicator, expected " + "222, is %d", + last_msg.msg.ssr_phase_biases.biases[8].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[8].widelane_integer_indicator == + 245, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[8].widelane_integer_indicator, " + "expected 245, is %d", + last_msg.msg.ssr_phase_biases.biases[8].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[9].bias == 1247996869, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[9].bias, " + "expected 1247996869, is %d", + last_msg.msg.ssr_phase_biases.biases[9].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[9].code == 228, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[9].code, " + "expected 228, is %d", + last_msg.msg.ssr_phase_biases.biases[9].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[9].discontinuity_counter == 221, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[9].discontinuity_counter, " + "expected 221, is %d", + last_msg.msg.ssr_phase_biases.biases[9].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[9].integer_indicator == 85, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[9].integer_indicator, expected " + "85, is %d", + last_msg.msg.ssr_phase_biases.biases[9].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[9].widelane_integer_indicator == + 139, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[9].widelane_integer_indicator, " + "expected 139, is %d", + last_msg.msg.ssr_phase_biases.biases[9].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[10].bias == -1133446161, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[10].bias, " + "expected -1133446161, is %d", + last_msg.msg.ssr_phase_biases.biases[10].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[10].code == 107, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[10].code, " + "expected 107, is %d", + last_msg.msg.ssr_phase_biases.biases[10].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[10].discontinuity_counter == 38, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[10].discontinuity_counter, " + "expected 38, is %d", + last_msg.msg.ssr_phase_biases.biases[10].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[10].integer_indicator == 70, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[10].integer_indicator, expected " + "70, is %d", + last_msg.msg.ssr_phase_biases.biases[10].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[10].widelane_integer_indicator == + 36, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[10].widelane_integer_indicator, " + "expected 36, is %d", + last_msg.msg.ssr_phase_biases.biases[10].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[11].bias == -720934762, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[11].bias, " + "expected -720934762, is %d", + last_msg.msg.ssr_phase_biases.biases[11].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[11].code == 124, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[11].code, " + "expected 124, is %d", + last_msg.msg.ssr_phase_biases.biases[11].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[11].discontinuity_counter == 164, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[11].discontinuity_counter, " + "expected 164, is %d", + last_msg.msg.ssr_phase_biases.biases[11].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[11].integer_indicator == 246, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[11].integer_indicator, expected " + "246, is %d", + last_msg.msg.ssr_phase_biases.biases[11].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[11].widelane_integer_indicator == + 141, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[11].widelane_integer_indicator, " + "expected 141, is %d", + last_msg.msg.ssr_phase_biases.biases[11].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[12].bias == 706252548, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[12].bias, " + "expected 706252548, is %d", + last_msg.msg.ssr_phase_biases.biases[12].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[12].code == 44, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[12].code, " + "expected 44, is %d", + last_msg.msg.ssr_phase_biases.biases[12].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[12].discontinuity_counter == 192, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[12].discontinuity_counter, " + "expected 192, is %d", + last_msg.msg.ssr_phase_biases.biases[12].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[12].integer_indicator == 21, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[12].integer_indicator, expected " + "21, is %d", + last_msg.msg.ssr_phase_biases.biases[12].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[12].widelane_integer_indicator == + 244, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[12].widelane_integer_indicator, " + "expected 244, is %d", + last_msg.msg.ssr_phase_biases.biases[12].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[13].bias == 388855338, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[13].bias, " + "expected 388855338, is %d", + last_msg.msg.ssr_phase_biases.biases[13].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[13].code == 21, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[13].code, " + "expected 21, is %d", + last_msg.msg.ssr_phase_biases.biases[13].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[13].discontinuity_counter == 7, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[13].discontinuity_counter, " + "expected 7, is %d", + last_msg.msg.ssr_phase_biases.biases[13].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[13].integer_indicator == 84, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[13].integer_indicator, expected " + "84, is %d", + last_msg.msg.ssr_phase_biases.biases[13].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[13].widelane_integer_indicator == + 136, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[13].widelane_integer_indicator, " + "expected 136, is %d", + last_msg.msg.ssr_phase_biases.biases[13].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[14].bias == 47517353, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[14].bias, " + "expected 47517353, is %d", + last_msg.msg.ssr_phase_biases.biases[14].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[14].code == 174, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[14].code, " + "expected 174, is %d", + last_msg.msg.ssr_phase_biases.biases[14].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[14].discontinuity_counter == 54, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[14].discontinuity_counter, " + "expected 54, is %d", + last_msg.msg.ssr_phase_biases.biases[14].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[14].integer_indicator == 175, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[14].integer_indicator, expected " + "175, is %d", + last_msg.msg.ssr_phase_biases.biases[14].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[14].widelane_integer_indicator == + 129, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[14].widelane_integer_indicator, " + "expected 129, is %d", + last_msg.msg.ssr_phase_biases.biases[14].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[15].bias == -2124125745, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[15].bias, " + "expected -2124125745, is %d", + last_msg.msg.ssr_phase_biases.biases[15].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[15].code == 197, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[15].code, " + "expected 197, is %d", + last_msg.msg.ssr_phase_biases.biases[15].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[15].discontinuity_counter == 13, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[15].discontinuity_counter, " + "expected 13, is %d", + last_msg.msg.ssr_phase_biases.biases[15].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[15].integer_indicator == 98, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[15].integer_indicator, expected " + "98, is %d", + last_msg.msg.ssr_phase_biases.biases[15].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[15].widelane_integer_indicator == + 60, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[15].widelane_integer_indicator, " + "expected 60, is %d", + last_msg.msg.ssr_phase_biases.biases[15].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[16].bias == -1401812607, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[16].bias, " + "expected -1401812607, is %d", + last_msg.msg.ssr_phase_biases.biases[16].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[16].code == 72, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[16].code, " + "expected 72, is %d", + last_msg.msg.ssr_phase_biases.biases[16].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[16].discontinuity_counter == 140, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[16].discontinuity_counter, " + "expected 140, is %d", + last_msg.msg.ssr_phase_biases.biases[16].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[16].integer_indicator == 136, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[16].integer_indicator, expected " + "136, is %d", + last_msg.msg.ssr_phase_biases.biases[16].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[16].widelane_integer_indicator == + 240, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[16].widelane_integer_indicator, " + "expected 240, is %d", + last_msg.msg.ssr_phase_biases.biases[16].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[17].bias == 60257151, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[17].bias, " + "expected 60257151, is %d", + last_msg.msg.ssr_phase_biases.biases[17].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[17].code == 151, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[17].code, " + "expected 151, is %d", + last_msg.msg.ssr_phase_biases.biases[17].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[17].discontinuity_counter == 210, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[17].discontinuity_counter, " + "expected 210, is %d", + last_msg.msg.ssr_phase_biases.biases[17].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[17].integer_indicator == 150, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[17].integer_indicator, expected " + "150, is %d", + last_msg.msg.ssr_phase_biases.biases[17].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[17].widelane_integer_indicator == + 17, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[17].widelane_integer_indicator, " + "expected 17, is %d", + last_msg.msg.ssr_phase_biases.biases[17].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[18].bias == 41820677, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[18].bias, " + "expected 41820677, is %d", + last_msg.msg.ssr_phase_biases.biases[18].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[18].code == 242, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[18].code, " + "expected 242, is %d", + last_msg.msg.ssr_phase_biases.biases[18].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[18].discontinuity_counter == 14, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[18].discontinuity_counter, " + "expected 14, is %d", + last_msg.msg.ssr_phase_biases.biases[18].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[18].integer_indicator == 254, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[18].integer_indicator, expected " + "254, is %d", + last_msg.msg.ssr_phase_biases.biases[18].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[18].widelane_integer_indicator == + 215, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[18].widelane_integer_indicator, " + "expected 215, is %d", + last_msg.msg.ssr_phase_biases.biases[18].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[19].bias == 1640616471, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[19].bias, " + "expected 1640616471, is %d", + last_msg.msg.ssr_phase_biases.biases[19].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[19].code == 215, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[19].code, " + "expected 215, is %d", + last_msg.msg.ssr_phase_biases.biases[19].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[19].discontinuity_counter == 176, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[19].discontinuity_counter, " + "expected 176, is %d", + last_msg.msg.ssr_phase_biases.biases[19].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[19].integer_indicator == 65, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[19].integer_indicator, expected " + "65, is %d", + last_msg.msg.ssr_phase_biases.biases[19].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[19].widelane_integer_indicator == + 38, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[19].widelane_integer_indicator, " + "expected 38, is %d", + last_msg.msg.ssr_phase_biases.biases[19].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[20].bias == -744786918, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[20].bias, " + "expected -744786918, is %d", + last_msg.msg.ssr_phase_biases.biases[20].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[20].code == 36, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[20].code, " + "expected 36, is %d", + last_msg.msg.ssr_phase_biases.biases[20].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[20].discontinuity_counter == 224, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[20].discontinuity_counter, " + "expected 224, is %d", + last_msg.msg.ssr_phase_biases.biases[20].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[20].integer_indicator == 207, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[20].integer_indicator, expected " + "207, is %d", + last_msg.msg.ssr_phase_biases.biases[20].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[20].widelane_integer_indicator == + 92, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[20].widelane_integer_indicator, " + "expected 92, is %d", + last_msg.msg.ssr_phase_biases.biases[20].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[21].bias == 1966589763, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[21].bias, " + "expected 1966589763, is %d", + last_msg.msg.ssr_phase_biases.biases[21].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[21].code == 165, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[21].code, " + "expected 165, is %d", + last_msg.msg.ssr_phase_biases.biases[21].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[21].discontinuity_counter == 38, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[21].discontinuity_counter, " + "expected 38, is %d", + last_msg.msg.ssr_phase_biases.biases[21].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[21].integer_indicator == 47, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[21].integer_indicator, expected " + "47, is %d", + last_msg.msg.ssr_phase_biases.biases[21].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[21].widelane_integer_indicator == + 102, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[21].widelane_integer_indicator, " + "expected 102, is %d", + last_msg.msg.ssr_phase_biases.biases[21].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[22].bias == 364366310, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[22].bias, " + "expected 364366310, is %d", + last_msg.msg.ssr_phase_biases.biases[22].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[22].code == 36, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[22].code, " + "expected 36, is %d", + last_msg.msg.ssr_phase_biases.biases[22].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[22].discontinuity_counter == 1, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[22].discontinuity_counter, " + "expected 1, is %d", + last_msg.msg.ssr_phase_biases.biases[22].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[22].integer_indicator == 169, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[22].integer_indicator, expected " + "169, is %d", + last_msg.msg.ssr_phase_biases.biases[22].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[22].widelane_integer_indicator == + 33, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[22].widelane_integer_indicator, " + "expected 33, is %d", + last_msg.msg.ssr_phase_biases.biases[22].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[23].bias == -1839031379, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[23].bias, " + "expected -1839031379, is %d", + last_msg.msg.ssr_phase_biases.biases[23].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[23].code == 42, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[23].code, " + "expected 42, is %d", + last_msg.msg.ssr_phase_biases.biases[23].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[23].discontinuity_counter == 173, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[23].discontinuity_counter, " + "expected 173, is %d", + last_msg.msg.ssr_phase_biases.biases[23].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[23].integer_indicator == 62, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[23].integer_indicator, expected " + "62, is %d", + last_msg.msg.ssr_phase_biases.biases[23].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[23].widelane_integer_indicator == + 147, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[23].widelane_integer_indicator, " + "expected 147, is %d", + last_msg.msg.ssr_phase_biases.biases[23].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[24].bias == 31817639, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[24].bias, " + "expected 31817639, is %d", + last_msg.msg.ssr_phase_biases.biases[24].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[24].code == 231, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[24].code, " + "expected 231, is %d", + last_msg.msg.ssr_phase_biases.biases[24].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[24].discontinuity_counter == 82, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[24].discontinuity_counter, " + "expected 82, is %d", + last_msg.msg.ssr_phase_biases.biases[24].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[24].integer_indicator == 167, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[24].integer_indicator, expected " + "167, is %d", + last_msg.msg.ssr_phase_biases.biases[24].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[24].widelane_integer_indicator == + 138, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[24].widelane_integer_indicator, " + "expected 138, is %d", + last_msg.msg.ssr_phase_biases.biases[24].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[25].bias == -1619830156, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[25].bias, " + "expected -1619830156, is %d", + last_msg.msg.ssr_phase_biases.biases[25].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[25].code == 2, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[25].code, " + "expected 2, is %d", + last_msg.msg.ssr_phase_biases.biases[25].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[25].discontinuity_counter == 207, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[25].discontinuity_counter, " + "expected 207, is %d", + last_msg.msg.ssr_phase_biases.biases[25].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[25].integer_indicator == 127, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[25].integer_indicator, expected " + "127, is %d", + last_msg.msg.ssr_phase_biases.biases[25].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[25].widelane_integer_indicator == + 237, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[25].widelane_integer_indicator, " + "expected 237, is %d", + last_msg.msg.ssr_phase_biases.biases[25].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[26].bias == -83375622, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[26].bias, " + "expected -83375622, is %d", + last_msg.msg.ssr_phase_biases.biases[26].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[26].code == 3, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[26].code, " + "expected 3, is %d", + last_msg.msg.ssr_phase_biases.biases[26].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[26].discontinuity_counter == 145, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[26].discontinuity_counter, " + "expected 145, is %d", + last_msg.msg.ssr_phase_biases.biases[26].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[26].integer_indicator == 42, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[26].integer_indicator, expected " + "42, is %d", + last_msg.msg.ssr_phase_biases.biases[26].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[26].widelane_integer_indicator == + 66, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[26].widelane_integer_indicator, " + "expected 66, is %d", + last_msg.msg.ssr_phase_biases.biases[26].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[27].bias == 1077458389, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[27].bias, " + "expected 1077458389, is %d", + last_msg.msg.ssr_phase_biases.biases[27].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[27].code == 2, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[27].code, " + "expected 2, is %d", + last_msg.msg.ssr_phase_biases.biases[27].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[27].discontinuity_counter == 26, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[27].discontinuity_counter, " + "expected 26, is %d", + last_msg.msg.ssr_phase_biases.biases[27].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[27].integer_indicator == 75, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[27].integer_indicator, expected " + "75, is %d", + last_msg.msg.ssr_phase_biases.biases[27].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[27].widelane_integer_indicator == + 230, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[27].widelane_integer_indicator, " + "expected 230, is %d", + last_msg.msg.ssr_phase_biases.biases[27].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[28].bias == -883355501, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[28].bias, " + "expected -883355501, is %d", + last_msg.msg.ssr_phase_biases.biases[28].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[28].code == 97, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[28].code, " + "expected 97, is %d", + last_msg.msg.ssr_phase_biases.biases[28].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[28].discontinuity_counter == 6, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[28].discontinuity_counter, " + "expected 6, is %d", + last_msg.msg.ssr_phase_biases.biases[28].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[28].integer_indicator == 88, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[28].integer_indicator, expected " + "88, is %d", + last_msg.msg.ssr_phase_biases.biases[28].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[28].widelane_integer_indicator == + 255, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[28].widelane_integer_indicator, " + "expected 255, is %d", + last_msg.msg.ssr_phase_biases.biases[28].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[29].bias == -1448611273, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[29].bias, " + "expected -1448611273, is %d", + last_msg.msg.ssr_phase_biases.biases[29].bias); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[29].code == 27, + "incorrect value for last_msg.msg.ssr_phase_biases.biases[29].code, " + "expected 27, is %d", + last_msg.msg.ssr_phase_biases.biases[29].code); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[29].discontinuity_counter == 230, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[29].discontinuity_counter, " + "expected 230, is %d", + last_msg.msg.ssr_phase_biases.biases[29].discontinuity_counter); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[29].integer_indicator == 68, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[29].integer_indicator, expected " + "68, is %d", + last_msg.msg.ssr_phase_biases.biases[29].integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.biases[29].widelane_integer_indicator == + 243, + "incorrect value for " + "last_msg.msg.ssr_phase_biases.biases[29].widelane_integer_indicator, " + "expected 243, is %d", + last_msg.msg.ssr_phase_biases.biases[29].widelane_integer_indicator); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.dispersive_bias == 98, + "incorrect value for last_msg.msg.ssr_phase_biases.dispersive_bias, " + "expected 98, is %d", + last_msg.msg.ssr_phase_biases.dispersive_bias); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.iod_ssr == 230, + "incorrect value for last_msg.msg.ssr_phase_biases.iod_ssr, " + "expected 230, is %d", + last_msg.msg.ssr_phase_biases.iod_ssr); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.mw_consistency == 209, + "incorrect value for last_msg.msg.ssr_phase_biases.mw_consistency, " + "expected 209, is %d", + last_msg.msg.ssr_phase_biases.mw_consistency); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.n_biases == 30, + "incorrect value for last_msg.msg.ssr_phase_biases.n_biases, " + "expected 30, is %d", + last_msg.msg.ssr_phase_biases.n_biases); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.sid.code == 82, + "incorrect value for last_msg.msg.ssr_phase_biases.sid.code, " + "expected 82, is %d", + last_msg.msg.ssr_phase_biases.sid.code); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.sid.sat == 169, + "incorrect value for last_msg.msg.ssr_phase_biases.sid.sat, " + "expected 169, is %d", + last_msg.msg.ssr_phase_biases.sid.sat); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.time.tow == 210803409, + "incorrect value for last_msg.msg.ssr_phase_biases.time.tow, " + "expected 210803409, is %d", + last_msg.msg.ssr_phase_biases.time.tow); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.time.wn == 42197, + "incorrect value for last_msg.msg.ssr_phase_biases.time.wn, " + "expected 42197, is %d", + last_msg.msg.ssr_phase_biases.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_phase_biases.update_interval == 177, + "incorrect value for last_msg.msg.ssr_phase_biases.update_interval, " + "expected 177, is %d", + last_msg.msg.ssr_phase_biases.update_interval); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.yaw == 5881, + "incorrect value for last_msg.msg.ssr_phase_biases.yaw, " + "expected 5881, is %d", + last_msg.msg.ssr_phase_biases.yaw); + + ck_assert_msg(last_msg.msg.ssr_phase_biases.yaw_rate == 17, + "incorrect value for last_msg.msg.ssr_phase_biases.yaw_rate, " + "expected 17, is %d", + last_msg.msg.ssr_phase_biases.yaw_rate); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrPhaseBiases_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrPhaseBiases"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ssr_MsgSsrPhaseBiases"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrPhaseBiases); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c new file mode 100644 index 0000000000..83eb8541ca --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c @@ -0,0 +1,1577 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x604, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, + 214, 212, 4, 8, 33, 31, 80, 21, 4, 105, 225, 39, 139, 124, + 149, 48, 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, 49, 135, + 97, 39, 90, 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, + 2, 102, 74, 149, 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, + 83, 188, 181, 194, 27, 84, 226, 142, 123, 77, 217, 248, 67, 215, + 129, 114, 138, 25, 240, 10, 56, 76, 61, 161, 216, 22, 181, 174, + 33, 13, 252, 236, 230, 196, 128, 215, 239, 234, 179, 220, 44, 212, + 57, 44, 173, 49, 36, 137, 248, 235, 97, 112, 157, 139, 26, 115, + 192, 31, 85, 127, 228, 81, 252, 219, 249, 110, 147, 8, 161, 215, + 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, 74, 23, 4, 239, + 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, 99, 45, 83, + 159, 11, 250, 135, 170, 42, 217, 199, 233, 42, 170, 78, 206, 41, + 43, 81, 247, 99, 198, 144, 2, 132, 2, 224, 220, 148, 58, 85, + 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, 37, + 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, + 119, 101, 252, 223, 144, 153, 50, 13, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_satellite_apc_dep.apc[0].pco[0] = -21547; + + test_msg.ssr_satellite_apc_dep.apc[0].pco[1] = -10498; + + test_msg.ssr_satellite_apc_dep.apc[0].pco[2] = 1236; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[0] = 8; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[1] = 33; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[2] = 31; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[3] = 80; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[4] = 21; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[5] = 4; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[6] = 105; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[7] = -31; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[8] = 39; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[9] = -117; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[10] = 124; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[11] = -107; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[12] = 48; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[13] = 15; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[14] = -42; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[15] = -59; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[16] = -115; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[17] = 32; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[18] = 33; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[19] = -121; + + test_msg.ssr_satellite_apc_dep.apc[0].pcv[20] = -106; + + test_msg.ssr_satellite_apc_dep.apc[0].sat_info = 240; + + test_msg.ssr_satellite_apc_dep.apc[0].sid.code = 169; + + test_msg.ssr_satellite_apc_dep.apc[0].sid.sat = 203; + + test_msg.ssr_satellite_apc_dep.apc[0].svn = 1102; + + test_msg.ssr_satellite_apc_dep.apc[1].pco[0] = 23079; + + test_msg.ssr_satellite_apc_dep.apc[1].pco[1] = -22252; + + test_msg.ssr_satellite_apc_dep.apc[1].pco[2] = 12271; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[0] = -103; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[1] = -81; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[2] = 35; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[3] = -111; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[4] = -111; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[5] = 123; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[6] = -62; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[7] = 2; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[8] = 102; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[9] = 74; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[10] = -107; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[11] = 95; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[12] = -85; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[13] = -18; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[14] = -7; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[15] = 7; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[16] = -19; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[17] = -86; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[18] = 125; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[19] = 106; + + test_msg.ssr_satellite_apc_dep.apc[1].pcv[20] = -98; + + test_msg.ssr_satellite_apc_dep.apc[1].sat_info = 49; + + test_msg.ssr_satellite_apc_dep.apc[1].sid.code = 123; + + test_msg.ssr_satellite_apc_dep.apc[1].sid.sat = 148; + + test_msg.ssr_satellite_apc_dep.apc[1].svn = 24967; + + test_msg.ssr_satellite_apc_dep.apc[2].pco[0] = -7596; + + test_msg.ssr_satellite_apc_dep.apc[2].pco[1] = 31630; + + test_msg.ssr_satellite_apc_dep.apc[2].pco[2] = -9907; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[0] = -8; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[1] = 67; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[2] = -41; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[3] = -127; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[4] = 114; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[5] = -118; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[6] = 25; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[7] = -16; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[8] = 10; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[9] = 56; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[10] = 76; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[11] = 61; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[12] = -95; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[13] = -40; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[14] = 22; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[15] = -75; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[16] = -82; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[17] = 33; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[18] = 13; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[19] = -4; + + test_msg.ssr_satellite_apc_dep.apc[2].pcv[20] = -20; + + test_msg.ssr_satellite_apc_dep.apc[2].sat_info = 181; + + test_msg.ssr_satellite_apc_dep.apc[2].sid.code = 188; + + test_msg.ssr_satellite_apc_dep.apc[2].sid.sat = 83; + + test_msg.ssr_satellite_apc_dep.apc[2].svn = 7106; + + test_msg.ssr_satellite_apc_dep.apc[3].pco[0] = -19478; + + test_msg.ssr_satellite_apc_dep.apc[3].pco[1] = 11484; + + test_msg.ssr_satellite_apc_dep.apc[3].pco[2] = 14804; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[0] = 44; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[1] = -83; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[2] = 49; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[3] = 36; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[4] = -119; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[5] = -8; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[6] = -21; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[7] = 97; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[8] = 112; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[9] = -99; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[10] = -117; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[11] = 26; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[12] = 115; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[13] = -64; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[14] = 31; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[15] = 85; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[16] = 127; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[17] = -28; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[18] = 81; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[19] = -4; + + test_msg.ssr_satellite_apc_dep.apc[3].pcv[20] = -37; + + test_msg.ssr_satellite_apc_dep.apc[3].sat_info = 128; + + test_msg.ssr_satellite_apc_dep.apc[3].sid.code = 196; + + test_msg.ssr_satellite_apc_dep.apc[3].sid.sat = 230; + + test_msg.ssr_satellite_apc_dep.apc[3].svn = 61399; + + test_msg.ssr_satellite_apc_dep.apc[4].pco[0] = -11049; + + test_msg.ssr_satellite_apc_dep.apc[4].pco[1] = 6580; + + test_msg.ssr_satellite_apc_dep.apc[4].pco[2] = -28589; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[0] = -9; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[1] = 12; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[2] = 27; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[3] = -57; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[4] = -83; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[5] = 74; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[6] = 23; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[7] = 4; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[8] = -17; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[9] = 103; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[10] = -33; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[11] = -36; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[12] = -117; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[13] = 91; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[14] = 127; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[15] = -42; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[16] = 86; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[17] = 48; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[18] = -53; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[19] = -28; + + test_msg.ssr_satellite_apc_dep.apc[4].pcv[20] = 99; + + test_msg.ssr_satellite_apc_dep.apc[4].sat_info = 147; + + test_msg.ssr_satellite_apc_dep.apc[4].sid.code = 110; + + test_msg.ssr_satellite_apc_dep.apc[4].sid.sat = 249; + + test_msg.ssr_satellite_apc_dep.apc[4].svn = 41224; + + test_msg.ssr_satellite_apc_dep.apc[5].pco[0] = -21881; + + test_msg.ssr_satellite_apc_dep.apc[5].pco[1] = -9942; + + test_msg.ssr_satellite_apc_dep.apc[5].pco[2] = -5689; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[0] = 42; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[1] = -86; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[2] = 78; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[3] = -50; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[4] = 41; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[5] = 43; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[6] = 81; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[7] = -9; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[8] = 99; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[9] = -58; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[10] = -112; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[11] = 2; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[12] = -124; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[13] = 2; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[14] = -32; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[15] = -36; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[16] = -108; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[17] = 58; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[18] = 85; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[19] = -118; + + test_msg.ssr_satellite_apc_dep.apc[5].pcv[20] = -46; + + test_msg.ssr_satellite_apc_dep.apc[5].sat_info = 159; + + test_msg.ssr_satellite_apc_dep.apc[5].sid.code = 83; + + test_msg.ssr_satellite_apc_dep.apc[5].sid.sat = 45; + + test_msg.ssr_satellite_apc_dep.apc[5].svn = 64011; + + test_msg.ssr_satellite_apc_dep.apc[6].pco[0] = -14290; + + test_msg.ssr_satellite_apc_dep.apc[6].pco[1] = 30340; + + test_msg.ssr_satellite_apc_dep.apc[6].pco[2] = 3569; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[0] = 37; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[1] = 62; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[2] = 107; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[3] = -3; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[4] = -66; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[5] = -120; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[6] = 66; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[7] = 9; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[8] = 84; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[9] = -101; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[10] = 86; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[11] = -76; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[12] = 41; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[13] = -60; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[14] = 40; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[15] = 119; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[16] = 101; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[17] = -4; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[18] = -33; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[19] = -112; + + test_msg.ssr_satellite_apc_dep.apc[6].pcv[20] = -103; + + test_msg.ssr_satellite_apc_dep.apc[6].sat_info = 7; + + test_msg.ssr_satellite_apc_dep.apc[6].sid.code = 158; + + test_msg.ssr_satellite_apc_dep.apc[6].sid.sat = 200; + + test_msg.ssr_satellite_apc_dep.apc[6].svn = 17310; + + test_msg.ssr_satellite_apc_dep.n_apc = 7; + + sbp_message_send(&sbp_state, SbpMsgSsrSatelliteApcDep, 4920, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 4920, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrSatelliteApcDep, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[0] == -21547, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[0], " + "expected -21547, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[1] == -10498, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[1], " + "expected -10498, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[2] == 1236, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[2], " + "expected 1236, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[0] == 8, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[0], " + "expected 8, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[1] == 33, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[1], " + "expected 33, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[2] == 31, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[2], " + "expected 31, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[3] == 80, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[3], " + "expected 80, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[4] == 21, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[4], " + "expected 21, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[5] == 4, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[5], " + "expected 4, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[6] == 105, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[6], " + "expected 105, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[7] == -31, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[7], " + "expected -31, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[8] == 39, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[8], " + "expected 39, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[9] == -117, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[9], " + "expected -117, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[9]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[10] == 124, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[10], expected " + "124, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[10]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[11] == -107, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[11], expected " + "-107, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[11]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[12] == 48, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[12], expected 48, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[12]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[13] == 15, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[13], expected 15, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[13]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[14] == -42, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[14], expected " + "-42, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[14]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[15] == -59, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[15], expected " + "-59, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[16] == -115, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[16], expected " + "-115, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[16]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[17] == 32, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[17], expected 32, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[17]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[18] == 33, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[18], expected 33, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[18]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[19] == -121, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[19], expected " + "-121, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[20] == -106, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[20], expected " + "-106, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].sat_info == 240, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].sat_info, " + "expected 240, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.code == 169, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.code, " + "expected 169, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.code); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.sat == 203, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.sat, expected " + "203, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[0].svn == 1102, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[0].svn, " + "expected 1102, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[0].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[0] == 23079, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[0], " + "expected 23079, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[1] == -22252, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[1], " + "expected -22252, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[2] == 12271, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[2], " + "expected 12271, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[0] == -103, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[0], " + "expected -103, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[1] == -81, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[1], " + "expected -81, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[2] == 35, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[2], " + "expected 35, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[3] == -111, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[3], " + "expected -111, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[4] == -111, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[4], " + "expected -111, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[5] == 123, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[5], " + "expected 123, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[6] == -62, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[6], " + "expected -62, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[7] == 2, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[7], " + "expected 2, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[8] == 102, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[8], " + "expected 102, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[9] == 74, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[9], " + "expected 74, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[9]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[10] == -107, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[10], expected " + "-107, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[10]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[11] == 95, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[11], expected 95, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[11]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[12] == -85, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[12], expected " + "-85, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[12]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[13] == -18, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[13], expected " + "-18, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[13]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[14] == -7, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[14], expected -7, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[14]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[15] == 7, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[15], expected 7, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[16] == -19, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[16], expected " + "-19, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[16]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[17] == -86, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[17], expected " + "-86, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[17]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[18] == 125, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[18], expected " + "125, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[18]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[19] == 106, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[19], expected " + "106, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[20] == -98, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[20], expected " + "-98, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].sat_info == 49, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].sat_info, " + "expected 49, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.code == 123, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.code, " + "expected 123, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.code); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.sat == 148, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.sat, expected " + "148, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[1].svn == 24967, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[1].svn, " + "expected 24967, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[1].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[0] == -7596, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[0], " + "expected -7596, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[1] == 31630, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[1], " + "expected 31630, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[2] == -9907, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[2], " + "expected -9907, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[0] == -8, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[0], " + "expected -8, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[1] == 67, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[1], " + "expected 67, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[2] == -41, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[2], " + "expected -41, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[3] == -127, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[3], " + "expected -127, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[4] == 114, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[4], " + "expected 114, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[5] == -118, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[5], " + "expected -118, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[6] == 25, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[6], " + "expected 25, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[7] == -16, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[7], " + "expected -16, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[8] == 10, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[8], " + "expected 10, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[9] == 56, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[9], " + "expected 56, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[9]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[10] == 76, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[10], expected 76, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[10]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[11] == 61, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[11], expected 61, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[11]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[12] == -95, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[12], expected " + "-95, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[12]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[13] == -40, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[13], expected " + "-40, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[13]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[14] == 22, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[14], expected 22, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[14]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[15] == -75, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[15], expected " + "-75, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[16] == -82, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[16], expected " + "-82, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[16]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[17] == 33, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[17], expected 33, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[17]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[18] == 13, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[18], expected 13, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[18]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[19] == -4, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[19], expected -4, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[20] == -20, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[20], expected " + "-20, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].sat_info == 181, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].sat_info, " + "expected 181, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.code == 188, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.code, " + "expected 188, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.code); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.sat == 83, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.sat, expected 83, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[2].svn == 7106, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[2].svn, " + "expected 7106, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[2].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[0] == -19478, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[0], " + "expected -19478, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[1] == 11484, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[1], " + "expected 11484, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[2] == 14804, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[2], " + "expected 14804, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[0] == 44, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[0], " + "expected 44, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[1] == -83, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[1], " + "expected -83, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[2] == 49, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[2], " + "expected 49, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[3] == 36, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[3], " + "expected 36, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[4] == -119, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[4], " + "expected -119, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[5] == -8, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[5], " + "expected -8, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[6] == -21, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[6], " + "expected -21, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[7] == 97, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[7], " + "expected 97, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[8] == 112, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[8], " + "expected 112, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[9] == -99, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[9], " + "expected -99, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[9]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[10] == -117, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[10], expected " + "-117, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[10]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[11] == 26, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[11], expected 26, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[11]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[12] == 115, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[12], expected " + "115, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[12]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[13] == -64, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[13], expected " + "-64, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[13]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[14] == 31, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[14], expected 31, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[14]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[15] == 85, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[15], expected 85, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[16] == 127, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[16], expected " + "127, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[16]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[17] == -28, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[17], expected " + "-28, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[17]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[18] == 81, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[18], expected 81, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[18]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[19] == -4, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[19], expected -4, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[20] == -37, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[20], expected " + "-37, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].sat_info == 128, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].sat_info, " + "expected 128, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.code == 196, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.code, " + "expected 196, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.code); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.sat == 230, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.sat, expected " + "230, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[3].svn == 61399, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[3].svn, " + "expected 61399, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[3].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[0] == -11049, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[0], " + "expected -11049, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[1] == 6580, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[1], " + "expected 6580, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[2] == -28589, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[2], " + "expected -28589, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[0] == -9, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[0], " + "expected -9, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[1] == 12, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[1], " + "expected 12, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[2] == 27, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[2], " + "expected 27, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[3] == -57, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[3], " + "expected -57, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[4] == -83, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[4], " + "expected -83, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[5] == 74, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[5], " + "expected 74, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[6] == 23, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[6], " + "expected 23, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[7] == 4, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[7], " + "expected 4, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[8] == -17, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[8], " + "expected -17, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[9] == 103, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[9], " + "expected 103, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[9]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[10] == -33, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[10], expected " + "-33, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[10]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[11] == -36, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[11], expected " + "-36, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[11]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[12] == -117, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[12], expected " + "-117, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[12]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[13] == 91, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[13], expected 91, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[13]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[14] == 127, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[14], expected " + "127, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[14]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[15] == -42, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[15], expected " + "-42, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[15]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[16] == 86, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[16], expected 86, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[16]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[17] == 48, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[17], expected 48, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[17]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[18] == -53, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[18], expected " + "-53, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[18]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[19] == -28, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[19], expected " + "-28, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[19]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[20] == 99, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[20], expected 99, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].sat_info == 147, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].sat_info, " + "expected 147, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.code == 110, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.code, " + "expected 110, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.code); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.sat == 249, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.sat, expected " + "249, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[4].svn == 41224, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[4].svn, " + "expected 41224, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[4].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[0] == -21881, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[0], " + "expected -21881, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[1] == -9942, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[1], " + "expected -9942, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[2] == -5689, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[2], " + "expected -5689, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[0] == 42, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[0], " + "expected 42, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[1] == -86, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[1], " + "expected -86, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[2] == 78, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[2], " + "expected 78, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[3] == -50, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[3], " + "expected -50, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[4] == 41, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[4], " + "expected 41, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[5] == 43, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[5], " + "expected 43, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[6] == 81, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[6], " + "expected 81, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[7] == -9, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[7], " + "expected -9, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[8] == 99, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[8], " + "expected 99, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[9] == -58, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[9], " + "expected -58, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[9]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[10] == -112, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[10], expected " + "-112, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[10]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[11] == 2, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[11], expected 2, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[11]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[12] == -124, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[12], expected " + "-124, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[12]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[13] == 2, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[13], expected 2, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[13]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[14] == -32, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[14], expected " + "-32, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[14]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[15] == -36, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[15], expected " + "-36, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[16] == -108, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[16], expected " + "-108, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[16]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[17] == 58, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[17], expected 58, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[17]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[18] == 85, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[18], expected 85, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[18]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[19] == -118, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[19], expected " + "-118, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[20] == -46, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[20], expected " + "-46, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].pcv[20]); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].sat_info == 159, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].sat_info, " + "expected 159, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.code == 83, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.code, " + "expected 83, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.code); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.sat == 45, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.sat, expected 45, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[5].svn == 64011, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[5].svn, " + "expected 64011, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[5].svn); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[0] == -14290, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[0], " + "expected -14290, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[1] == 30340, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[1], " + "expected 30340, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[2] == 3569, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[2], " + "expected 3569, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pco[2]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[0] == 37, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[0], " + "expected 37, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[0]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[1] == 62, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[1], " + "expected 62, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[1]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[2] == 107, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[2], " + "expected 107, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[2]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[3] == -3, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[3], " + "expected -3, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[3]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[4] == -66, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[4], " + "expected -66, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[4]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[5] == -120, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[5], " + "expected -120, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[5]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[6] == 66, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[6], " + "expected 66, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[6]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[7] == 9, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[7], " + "expected 9, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[7]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[8] == 84, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[8], " + "expected 84, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[8]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[9] == -101, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[9], " + "expected -101, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[9]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[10] == 86, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[10], expected 86, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[10]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[11] == -76, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[11], expected " + "-76, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[11]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[12] == 41, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[12], expected 41, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[12]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[13] == -60, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[13], expected " + "-60, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[13]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[14] == 40, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[14], expected 40, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[14]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[15] == 119, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[15], expected " + "119, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[15]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[16] == 101, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[16], expected " + "101, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[16]); + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[17] == -4, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[17], expected -4, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[17]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[18] == -33, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[18], expected " + "-33, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[18]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[19] == -112, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[19], expected " + "-112, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[19]); + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[20] == -103, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[20], expected " + "-103, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].pcv[20]); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].sat_info == 7, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].sat_info, expected 7, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].sat_info); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.code == 158, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.code, " + "expected 158, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.code); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.sat == 200, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.sat, expected " + "200, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].sid.sat); + + ck_assert_msg( + last_msg.msg.ssr_satellite_apc_dep.apc[6].svn == 17310, + "incorrect value for last_msg.msg.ssr_satellite_apc_dep.apc[6].svn, " + "expected 17310, is %d", + last_msg.msg.ssr_satellite_apc_dep.apc[6].svn); + + ck_assert_msg(last_msg.msg.ssr_satellite_apc_dep.n_apc == 7, + "incorrect value for " + "last_msg.msg.ssr_satellite_apc_dep.n_apc, expected 7, is %d", + last_msg.msg.ssr_satellite_apc_dep.n_apc); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrSatelliteApcDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c b/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c new file mode 100644 index 0000000000..8ac9d0cfb0 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c @@ -0,0 +1,1659 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrStecCorrectionDep) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5fb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, + 119, 156, 157, 112, 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, + 3, 14, 8, 70, 12, 44, 53, 181, 90, 174, 247, 150, 58, 172, + 247, 179, 119, 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, + 53, 222, 187, 146, 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, + 91, 234, 0, 213, 139, 95, 179, 50, 21, 74, 174, 169, 61, 86, + 91, 142, 51, 108, 9, 38, 225, 146, 101, 73, 139, 56, 117, 82, + 37, 213, 108, 205, 93, 18, 19, 195, 33, 202, 87, 206, 178, 125, + 188, 119, 56, 69, 150, 150, 76, 3, 131, 18, 73, 208, 72, 232, + 8, 250, 203, 178, 170, 163, 252, 86, 49, 247, 178, 166, 56, 31, + 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, 124, 169, 121, 158, + 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, 110, 23, 12, + 241, 88, 69, 239, 252, 57, 93, 44, 201, 216, 173, 242, 178, 17, + 5, 223, 169, 192, 3, 77, 107, 2, 144, 233, 14, 88, 32, 209, + 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, + 126, 217, 79, 171, 239, 237, 188, 238, 112, 201, 118, 141, 18, 163, + 103, 35, 63, 21, 82, 129, 18, 117, 85, 190, 79, 210, 215, 227, + 177, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_stec_correction_dep.header.iod_atmo = 60; + + test_msg.ssr_stec_correction_dep.header.num_msgs = 157; + + test_msg.ssr_stec_correction_dep.header.seq_num = 112; + + test_msg.ssr_stec_correction_dep.header.tile_id = 30066; + + test_msg.ssr_stec_correction_dep.header.tile_set_id = 58526; + + test_msg.ssr_stec_correction_dep.header.time.tow = 714907186; + + test_msg.ssr_stec_correction_dep.header.time.wn = 40055; + + test_msg.ssr_stec_correction_dep.header.update_interval = 47; + + test_msg.ssr_stec_correction_dep.n_stec_sat_list = 21; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[0] = -5289; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[1] = -20141; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[2] = 966; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[3] = 2062; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].stec_quality_indicator = + 70; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id.constellation = 40; + + test_msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id.satId = 132; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[0] = -19147; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[1] = -20902; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[2] = -26889; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[3] = -21446; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].stec_quality_indicator = + 44; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id.constellation = 12; + + test_msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id.satId = 70; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[0] = 32176; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[1] = -20220; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[2] = 29157; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[3] = 19726; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].stec_quality_indicator = + 119; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id.constellation = 179; + + test_msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id.satId = 247; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[0] = -8651; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[1] = -27973; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[2] = 23546; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[3] = -10284; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].stec_quality_indicator = + 23; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id.constellation = 185; + + test_msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id.satId = 153; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[0] = 27486; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[1] = 23329; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[2] = 234; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[3] = -29739; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].stec_quality_indicator = + 250; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id.constellation = 107; + + test_msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id.satId = 14; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[0] = 18965; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[1] = -22098; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[2] = 22077; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[3] = -29093; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].stec_quality_indicator = + 50; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id.constellation = 179; + + test_msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id.satId = 95; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[0] = -7898; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[1] = 26002; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[2] = -29879; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[3] = 30008; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].stec_quality_indicator = + 9; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id.constellation = 108; + + test_msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id.satId = 51; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[0] = -12948; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[1] = 4701; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[2] = -15597; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[3] = -13791; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].stec_quality_indicator = + 213; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id.constellation = 37; + + test_msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id.satId = 82; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[0] = -17283; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[1] = 14455; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[2] = -27067; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[3] = 19606; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].stec_quality_indicator = + 178; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id.constellation = 206; + + test_msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id.satId = 87; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[0] = -12215; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[1] = -6072; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[2] = -1528; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[3] = -19765; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].stec_quality_indicator = + 18; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id.constellation = 131; + + test_msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id.satId = 3; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[0] = 12630; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[1] = -19721; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[2] = 14502; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[3] = 2591; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].stec_quality_indicator = + 252; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].sv_id.constellation = + 163; + + test_msg.ssr_stec_correction_dep.stec_sat_list[10].sv_id.satId = 170; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[0] = -23340; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[1] = -24063; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[2] = 4650; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[3] = -22148; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].stec_quality_indicator = + 241; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].sv_id.constellation = + 213; + + test_msg.ssr_stec_correction_dep.stec_sat_list[11].sv_id.satId = 119; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[0] = 5944; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[1] = 32142; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[2] = 30760; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[3] = 11587; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].stec_quality_indicator = + 26; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].sv_id.constellation = + 158; + + test_msg.ssr_stec_correction_dep.stec_sat_list[12].sv_id.satId = 121; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[0] = 3095; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[1] = 22769; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[2] = -4283; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[3] = 14844; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].stec_quality_indicator = + 110; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].sv_id.constellation = + 235; + + test_msg.ssr_stec_correction_dep.stec_sat_list[13].sv_id.satId = 126; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[0] = -21032; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[1] = -19726; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[2] = 1297; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[3] = -22049; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].stec_quality_indicator = + 201; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].sv_id.constellation = 44; + + test_msg.ssr_stec_correction_dep.stec_sat_list[14].sv_id.satId = 93; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[0] = 619; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[1] = -5744; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[2] = 22542; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[3] = -12000; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].stec_quality_indicator = + 77; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].sv_id.constellation = 3; + + test_msg.ssr_stec_correction_dep.stec_sat_list[15].sv_id.satId = 192; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[0] = 10651; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[1] = -2889; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[2] = 21150; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[3] = 26421; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].stec_quality_indicator = + 123; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].sv_id.constellation = 17; + + test_msg.ssr_stec_correction_dep.stec_sat_list[16].sv_id.satId = 1; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[0] = -19165; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[1] = 30229; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[2] = -1282; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[3] = -18382; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].stec_quality_indicator = + 185; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].sv_id.constellation = + 202; + + test_msg.ssr_stec_correction_dep.stec_sat_list[17].sv_id.satId = 14; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[0] = -23752; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[1] = 32433; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[2] = 20441; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[3] = -4181; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].stec_quality_indicator = + 45; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].sv_id.constellation = 31; + + test_msg.ssr_stec_correction_dep.stec_sat_list[18].sv_id.satId = 50; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[0] = -13968; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[1] = -29322; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[2] = -23790; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[3] = 9063; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].stec_quality_indicator = + 238; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].sv_id.constellation = + 188; + + test_msg.ssr_stec_correction_dep.stec_sat_list[19].sv_id.satId = 237; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[0] = 4737; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[1] = 21877; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[2] = 20414; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[3] = -10286; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].stec_quality_indicator = + 82; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].sv_id.constellation = 21; + + test_msg.ssr_stec_correction_dep.stec_sat_list[20].sv_id.satId = 63; + + sbp_message_send(&sbp_state, SbpMsgSsrStecCorrectionDep, 38860, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 38860, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrStecCorrectionDep, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.header.iod_atmo == 60, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.iod_atmo, " + "expected 60, is %d", + last_msg.msg.ssr_stec_correction_dep.header.iod_atmo); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.header.num_msgs == 157, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.num_msgs, " + "expected 157, is %d", + last_msg.msg.ssr_stec_correction_dep.header.num_msgs); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.header.seq_num == 112, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.seq_num, " + "expected 112, is %d", + last_msg.msg.ssr_stec_correction_dep.header.seq_num); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.header.tile_id == 30066, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.tile_id, " + "expected 30066, is %d", + last_msg.msg.ssr_stec_correction_dep.header.tile_id); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.header.tile_set_id == 58526, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.tile_set_id, expected " + "58526, is %d", + last_msg.msg.ssr_stec_correction_dep.header.tile_set_id); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.header.time.tow == 714907186, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.time.tow, expected " + "714907186, is %d", + last_msg.msg.ssr_stec_correction_dep.header.time.tow); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.header.time.wn == 40055, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.time.wn, " + "expected 40055, is %d", + last_msg.msg.ssr_stec_correction_dep.header.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.header.update_interval == 47, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.header.update_interval, expected " + "47, is %d", + last_msg.msg.ssr_stec_correction_dep.header.update_interval); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.n_stec_sat_list == 21, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.n_stec_sat_list, " + "expected 21, is %d", + last_msg.msg.ssr_stec_correction_dep.n_stec_sat_list); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[0] == + -5289, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[0], " + "expected -5289, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[1] == + -20141, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[1], " + "expected -20141, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[2] == + 966, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[2], " + "expected 966, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[3] == + 2062, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[3], " + "expected 2062, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0] + .stec_quality_indicator == 70, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].stec_" + "quality_indicator, expected 70, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0] + .sv_id.constellation == 40, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id." + "constellation, expected 40, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id.satId == + 132, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id.satId, " + "expected 132, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[0].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[0] == + -19147, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[0], " + "expected -19147, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[1] == + -20902, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[1], " + "expected -20902, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[2] == + -26889, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[2], " + "expected -26889, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[3] == + -21446, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[3], " + "expected -21446, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1] + .stec_quality_indicator == 44, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].stec_" + "quality_indicator, expected 44, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1] + .sv_id.constellation == 12, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id." + "constellation, expected 12, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id.satId == 70, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id.satId, " + "expected 70, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[1].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[0] == + 32176, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[0], " + "expected 32176, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[1] == + -20220, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[1], " + "expected -20220, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[2] == + 29157, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[2], " + "expected 29157, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[3] == + 19726, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[3], " + "expected 19726, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2] + .stec_quality_indicator == 119, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].stec_" + "quality_indicator, expected 119, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2] + .sv_id.constellation == 179, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id." + "constellation, expected 179, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id.satId == + 247, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id.satId, " + "expected 247, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[2].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[0] == + -8651, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[0], " + "expected -8651, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[1] == + -27973, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[1], " + "expected -27973, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[2] == + 23546, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[2], " + "expected 23546, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[3] == + -10284, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[3], " + "expected -10284, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3] + .stec_quality_indicator == 23, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].stec_" + "quality_indicator, expected 23, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3] + .sv_id.constellation == 185, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id." + "constellation, expected 185, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id.satId == + 153, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id.satId, " + "expected 153, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[3].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[0] == + 27486, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[0], " + "expected 27486, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[1] == + 23329, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[1], " + "expected 23329, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[2] == + 234, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[2], " + "expected 234, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[3] == + -29739, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[3], " + "expected -29739, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4] + .stec_quality_indicator == 250, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].stec_" + "quality_indicator, expected 250, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4] + .sv_id.constellation == 107, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id." + "constellation, expected 107, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id.satId == 14, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id.satId, " + "expected 14, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[4].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[0] == + 18965, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[0], " + "expected 18965, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[1] == + -22098, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[1], " + "expected -22098, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[2] == + 22077, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[2], " + "expected 22077, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[3] == + -29093, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[3], " + "expected -29093, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5] + .stec_quality_indicator == 50, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].stec_" + "quality_indicator, expected 50, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5] + .sv_id.constellation == 179, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id." + "constellation, expected 179, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id.satId == 95, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id.satId, " + "expected 95, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[5].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[0] == + -7898, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[0], " + "expected -7898, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[1] == + 26002, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[1], " + "expected 26002, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[2] == + -29879, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[2], " + "expected -29879, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[3] == + 30008, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[3], " + "expected 30008, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6] + .stec_quality_indicator == 9, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].stec_" + "quality_indicator, expected 9, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6] + .sv_id.constellation == 108, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id." + "constellation, expected 108, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id.satId == 51, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id.satId, " + "expected 51, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[6].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[0] == + -12948, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[0], " + "expected -12948, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[1] == + 4701, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[1], " + "expected 4701, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[2] == + -15597, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[2], " + "expected -15597, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[3] == + -13791, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[3], " + "expected -13791, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7] + .stec_quality_indicator == 213, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].stec_" + "quality_indicator, expected 213, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7] + .sv_id.constellation == 37, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id." + "constellation, expected 37, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id.satId == 82, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id.satId, " + "expected 82, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[7].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[0] == + -17283, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[0], " + "expected -17283, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[1] == + 14455, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[1], " + "expected 14455, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[2] == + -27067, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[2], " + "expected -27067, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[3] == + 19606, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[3], " + "expected 19606, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8] + .stec_quality_indicator == 178, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].stec_" + "quality_indicator, expected 178, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8] + .sv_id.constellation == 206, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id." + "constellation, expected 206, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id.satId == 87, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id.satId, " + "expected 87, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[8].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[0] == + -12215, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[0], " + "expected -12215, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[1] == + -6072, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[1], " + "expected -6072, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[2] == + -1528, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[2], " + "expected -1528, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[3] == + -19765, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[3], " + "expected -19765, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9] + .stec_quality_indicator == 18, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].stec_" + "quality_indicator, expected 18, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9] + .sv_id.constellation == 131, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id." + "constellation, expected 131, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id.satId == 3, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id.satId, " + "expected 3, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[9].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[0] == + 12630, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[0], " + "expected 12630, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[1] == + -19721, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[1], " + "expected -19721, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[2] == + 14502, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[2], " + "expected 14502, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[3] == + 2591, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[3], " + "expected 2591, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10] + .stec_quality_indicator == 252, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].stec_" + "quality_indicator, expected 252, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10] + .sv_id.constellation == 163, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].sv_" + "id.constellation, expected 163, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].sv_id.satId == + 170, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].sv_id.satId, " + "expected 170, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[10].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[0] == + -23340, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[0], " + "expected -23340, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[1] == + -24063, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[1], " + "expected -24063, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[2] == + 4650, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[2], " + "expected 4650, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[3] == + -22148, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[3], " + "expected -22148, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11] + .stec_quality_indicator == 241, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].stec_" + "quality_indicator, expected 241, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11] + .sv_id.constellation == 213, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].sv_" + "id.constellation, expected 213, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].sv_id.satId == + 119, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].sv_id.satId, " + "expected 119, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[11].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[0] == + 5944, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[0], " + "expected 5944, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[1] == + 32142, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[1], " + "expected 32142, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[2] == + 30760, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[2], " + "expected 30760, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[3] == + 11587, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[3], " + "expected 11587, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12] + .stec_quality_indicator == 26, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].stec_" + "quality_indicator, expected 26, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12] + .sv_id.constellation == 158, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].sv_" + "id.constellation, expected 158, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].sv_id.satId == + 121, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].sv_id.satId, " + "expected 121, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[12].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[0] == + 3095, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[0], " + "expected 3095, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[1] == + 22769, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[1], " + "expected 22769, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[2] == + -4283, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[2], " + "expected -4283, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[3] == + 14844, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[3], " + "expected 14844, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13] + .stec_quality_indicator == 110, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].stec_" + "quality_indicator, expected 110, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13] + .sv_id.constellation == 235, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].sv_" + "id.constellation, expected 235, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].sv_id.satId == + 126, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].sv_id.satId, " + "expected 126, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[13].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[0] == + -21032, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[0], " + "expected -21032, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[1] == + -19726, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[1], " + "expected -19726, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[2] == + 1297, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[2], " + "expected 1297, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[3] == + -22049, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[3], " + "expected -22049, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14] + .stec_quality_indicator == 201, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].stec_" + "quality_indicator, expected 201, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14] + .sv_id.constellation == 44, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].sv_" + "id.constellation, expected 44, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].sv_id.satId == + 93, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].sv_id.satId, " + "expected 93, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[14].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[0] == + 619, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[0], " + "expected 619, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[1] == + -5744, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[1], " + "expected -5744, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[2] == + 22542, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[2], " + "expected 22542, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[3] == + -12000, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[3], " + "expected -12000, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15] + .stec_quality_indicator == 77, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].stec_" + "quality_indicator, expected 77, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15] + .sv_id.constellation == 3, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].sv_" + "id.constellation, expected 3, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].sv_id.satId == + 192, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].sv_id.satId, " + "expected 192, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[15].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[0] == + 10651, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[0], " + "expected 10651, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[1] == + -2889, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[1], " + "expected -2889, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[2] == + 21150, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[2], " + "expected 21150, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[3] == + 26421, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[3], " + "expected 26421, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16] + .stec_quality_indicator == 123, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].stec_" + "quality_indicator, expected 123, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16] + .sv_id.constellation == 17, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].sv_" + "id.constellation, expected 17, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].sv_id.satId == 1, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].sv_id.satId, " + "expected 1, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[16].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[0] == + -19165, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[0], " + "expected -19165, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[1] == + 30229, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[1], " + "expected 30229, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[2] == + -1282, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[2], " + "expected -1282, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[3] == + -18382, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[3], " + "expected -18382, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17] + .stec_quality_indicator == 185, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].stec_" + "quality_indicator, expected 185, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17] + .sv_id.constellation == 202, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].sv_" + "id.constellation, expected 202, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].sv_id.satId == + 14, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].sv_id.satId, " + "expected 14, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[17].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[0] == + -23752, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[0], " + "expected -23752, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[1] == + 32433, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[1], " + "expected 32433, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[2] == + 20441, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[2], " + "expected 20441, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[3] == + -4181, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[3], " + "expected -4181, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18] + .stec_quality_indicator == 45, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].stec_" + "quality_indicator, expected 45, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18] + .sv_id.constellation == 31, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].sv_" + "id.constellation, expected 31, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].sv_id.satId == + 50, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].sv_id.satId, " + "expected 50, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[18].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[0] == + -13968, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[0], " + "expected -13968, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[1] == + -29322, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[1], " + "expected -29322, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[2] == + -23790, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[2], " + "expected -23790, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[3] == + 9063, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[3], " + "expected 9063, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19] + .stec_quality_indicator == 238, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].stec_" + "quality_indicator, expected 238, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19] + .sv_id.constellation == 188, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].sv_" + "id.constellation, expected 188, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].sv_id.satId == + 237, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].sv_id.satId, " + "expected 237, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[19].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[0] == + 4737, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[0], " + "expected 4737, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[1] == + 21877, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[1], " + "expected 21877, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[2] == + 20414, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[2], " + "expected 20414, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[3] == + -10286, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[3], " + "expected -10286, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20] + .stec_quality_indicator == 82, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].stec_" + "quality_indicator, expected 82, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20] + .sv_id.constellation == 21, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].sv_" + "id.constellation, expected 21, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].sv_id.satId == + 63, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].sv_id.satId, " + "expected 63, is %d", + last_msg.msg.ssr_stec_correction_dep.stec_sat_list[20].sv_id.satId); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrStecCorrectionDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrStecCorrectionDep"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrStecCorrectionDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c new file mode 100644 index 0000000000..0758c4f039 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c @@ -0,0 +1,1734 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5eb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, + 39, 4, 126, 19, 111, 97, 248, 130, 217, 217, 106, 58, 12, 65, + 230, 171, 81, 95, 86, 16, 39, 84, 228, 208, 201, 81, 219, 99, + 203, 61, 182, 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, + 93, 218, 247, 158, 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, + 148, 147, 72, 225, 180, 236, 205, 201, 33, 3, 246, 204, 19, 3, + 98, 4, 194, 191, 246, 76, 219, 31, 191, 113, 79, 177, 15, 251, + 33, 19, 96, 54, 58, 146, 210, 100, 249, 72, 21, 161, 211, 198, + 21, 238, 111, 107, 36, 227, 225, 213, 3, 71, 243, 63, 65, 236, + 92, 77, 0, 169, 15, 182, 5, 240, 180, 9, 122, 86, 232, 6, + 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, 216, 55, 50, 181, + 5, 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, 66, 124, 168, + 59, 139, 106, 118, 51, 187, 216, 191, 158, 77, 92, 58, 253, 132, + 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, 181, 196, 23, 53, + 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, + 201, 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, + 22, 178, 226, 109, 88, 157, 30, 196, 175, 26, 76, 34, 116, 220, + 154, 232, 12, 179, 244, 15, 155, 196, 202, 72, 70, 115, 10, 214, + 114, 39, 245, 28, 237, 68, 136, 155, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_stec_correction_dep_a.header.iod_atmo = 4; + + test_msg.ssr_stec_correction_dep_a.header.num_msgs = 147; + + test_msg.ssr_stec_correction_dep_a.header.seq_num = 123; + + test_msg.ssr_stec_correction_dep_a.header.time.tow = 3905179974; + + test_msg.ssr_stec_correction_dep_a.header.time.wn = 11193; + + test_msg.ssr_stec_correction_dep_a.header.update_interval = 39; + + test_msg.ssr_stec_correction_dep_a.n_stec_sat_list = 22; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[0] = -1951; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[1] = -9854; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[2] = 27353; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[3] = 3130; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_quality_indicator = + 111; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_id.constellation = + 19; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_id.satId = 126; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[0] = 24401; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[1] = 4182; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[2] = 21543; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[3] = -12060; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_quality_indicator = + 171; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_id.constellation = + 230; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_id.satId = 65; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[0] = -13469; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[1] = -18883; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[2] = 32066; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[3] = 971; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_quality_indicator = + 219; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_id.constellation = + 81; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_id.satId = 201; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[0] = 32220; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[1] = 5436; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[2] = -9635; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[3] = -24841; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_quality_indicator = + 100; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_id.constellation = + 44; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_id.satId = 193; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[0] = 3718; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[1] = 12497; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[2] = -10482; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[3] = -27495; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_quality_indicator = + 129; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_id.constellation = + 93; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_id.satId = 207; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[0] = -4940; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[1] = -13875; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[2] = 801; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[3] = -13066; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_quality_indicator = + 225; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_id.constellation = + 72; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_id.satId = 147; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[0] = -15868; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[1] = -2369; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[2] = -9396; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[3] = -16609; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_quality_indicator = + 98; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_id.constellation = 3; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_id.satId = 19; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[0] = -1265; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[1] = 4897; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[2] = 13920; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[3] = -28102; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_quality_indicator = + 177; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_id.constellation = + 79; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_id.satId = 113; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[0] = 5448; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[1] = -11359; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[2] = 5574; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[3] = 28654; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_quality_indicator = + 249; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_id.constellation = + 100; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_id.satId = 210; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[0] = -10783; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[1] = 18179; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[2] = 16371; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[3] = -5055; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_quality_indicator = + 227; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_id.constellation = + 36; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_id.satId = 107; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[0] = 4009; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[1] = 1462; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[2] = -19216; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[3] = 31241; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_quality_indicator = 0; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_id.constellation = + 77; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_id.satId = 92; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[0] = 26727; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[1] = -16898; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[2] = 28241; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[3] = 12546; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_quality_indicator = 6; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_id.constellation = + 232; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_id.satId = 86; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[0] = 12855; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[1] = 1461; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[2] = 20603; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[3] = -3023; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_quality_indicator = 216; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_id.constellation = + 84; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_id.satId = 202; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[0] = -6492; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[1] = 16952; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[2] = -22404; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[3] = -29893; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_quality_indicator = 125; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_id.constellation = + 188; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_id.satId = 224; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[0] = -10053; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[1] = -24897; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[2] = 23629; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[3] = -710; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_quality_indicator = 51; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_id.constellation = + 118; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_id.satId = 106; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[0] = -26103; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[1] = -9539; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[2] = -11971; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[3] = 20993; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_quality_indicator = 165; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_id.constellation = + 150; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_id.satId = 132; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[0] = -18891; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[1] = -16272; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[2] = -22578; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[3] = -2915; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_quality_indicator = 23; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_id.constellation = + 196; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_id.satId = 181; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[0] = 15833; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[1] = 24920; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[2] = -13879; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[3] = -1206; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_quality_indicator = 189; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_id.constellation = + 1; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_id.satId = 35; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[0] = 14008; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[1] = 18996; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[2] = 2798; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[3] = 5761; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_quality_indicator = 104; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_id.constellation = + 14; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_id.satId = 217; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[0] = -25256; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[1] = -15330; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[2] = 6831; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[3] = 8780; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_quality_indicator = 109; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_id.constellation = + 226; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_id.satId = 178; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[0] = 3304; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[1] = -2893; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[2] = -25841; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[3] = -13628; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_quality_indicator = 154; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_id.constellation = + 220; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_id.satId = 116; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[0] = -10742; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[1] = 10098; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[2] = 7413; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[3] = 17645; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_quality_indicator = 115; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_id.constellation = + 70; + + test_msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_id.satId = 72; + + sbp_message_send(&sbp_state, SbpMsgSsrStecCorrectionDepA, 1831, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1831, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrStecCorrectionDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.header.iod_atmo == 4, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.iod_atmo, " + "expected 4, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.iod_atmo); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.header.num_msgs == 147, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.num_msgs, " + "expected 147, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.num_msgs); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.header.seq_num == 123, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.seq_num, " + "expected 123, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.seq_num); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.header.time.tow == 3905179974, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.time.tow, expected " + "3905179974, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.time.tow); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.header.time.wn == 11193, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.time.wn, expected " + "11193, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.time.wn); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.header.update_interval == 39, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.header.update_interval, " + "expected 39, is %d", + last_msg.msg.ssr_stec_correction_dep_a.header.update_interval); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.n_stec_sat_list == 22, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.n_stec_sat_list, " + "expected 22, is %d", + last_msg.msg.ssr_stec_correction_dep_a.n_stec_sat_list); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[0] == + -1951, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[0]," + " expected -1951, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[1] == + -9854, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[1]," + " expected -9854, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[2] == + 27353, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[2]," + " expected 27353, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[3] == + 3130, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[3]," + " expected 3130, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0] + .stec_quality_indicator == 111, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0]." + "stec_quality_indicator, expected 111, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0] + .sv_id.constellation == 19, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_" + "id.constellation, expected 19, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_id.satId == + 126, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_id.satId, " + "expected 126, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[0].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[0] == + 24401, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[0]," + " expected 24401, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[1] == + 4182, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[1]," + " expected 4182, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[2] == + 21543, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[2]," + " expected 21543, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[3] == + -12060, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[3]," + " expected -12060, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1] + .stec_quality_indicator == 171, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1]." + "stec_quality_indicator, expected 171, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1] + .sv_id.constellation == 230, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_" + "id.constellation, expected 230, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_id.satId == + 65, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_id.satId, " + "expected 65, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[1].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[0] == + -13469, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[0]," + " expected -13469, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[1] == + -18883, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[1]," + " expected -18883, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[2] == + 32066, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[2]," + " expected 32066, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[3] == + 971, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[3]," + " expected 971, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2] + .stec_quality_indicator == 219, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2]." + "stec_quality_indicator, expected 219, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2] + .sv_id.constellation == 81, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_" + "id.constellation, expected 81, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_id.satId == + 201, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_id.satId, " + "expected 201, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[2].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[0] == + 32220, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[0]," + " expected 32220, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[1] == + 5436, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[1]," + " expected 5436, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[2] == + -9635, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[2]," + " expected -9635, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[3] == + -24841, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[3]," + " expected -24841, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3] + .stec_quality_indicator == 100, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3]." + "stec_quality_indicator, expected 100, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3] + .sv_id.constellation == 44, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_" + "id.constellation, expected 44, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_id.satId == + 193, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_id.satId, " + "expected 193, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[3].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[0] == + 3718, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[0]," + " expected 3718, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[1] == + 12497, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[1]," + " expected 12497, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[2] == + -10482, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[2]," + " expected -10482, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[3] == + -27495, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[3]," + " expected -27495, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4] + .stec_quality_indicator == 129, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4]." + "stec_quality_indicator, expected 129, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4] + .sv_id.constellation == 93, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_" + "id.constellation, expected 93, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_id.satId == + 207, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_id.satId, " + "expected 207, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[4].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[0] == + -4940, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[0]," + " expected -4940, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[1] == + -13875, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[1]," + " expected -13875, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[2] == + 801, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[2]," + " expected 801, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[3] == + -13066, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[3]," + " expected -13066, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5] + .stec_quality_indicator == 225, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5]." + "stec_quality_indicator, expected 225, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5] + .sv_id.constellation == 72, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_" + "id.constellation, expected 72, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_id.satId == + 147, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_id.satId, " + "expected 147, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[5].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[0] == + -15868, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[0]," + " expected -15868, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[1] == + -2369, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[1]," + " expected -2369, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[2] == + -9396, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[2]," + " expected -9396, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[3] == + -16609, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[3]," + " expected -16609, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6] + .stec_quality_indicator == 98, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6]." + "stec_quality_indicator, expected 98, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6] + .sv_id.constellation == 3, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_" + "id.constellation, expected 3, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_id.satId == + 19, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_id.satId, " + "expected 19, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[6].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[0] == + -1265, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[0]," + " expected -1265, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[1] == + 4897, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[1]," + " expected 4897, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[2] == + 13920, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[2]," + " expected 13920, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[3] == + -28102, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[3]," + " expected -28102, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7] + .stec_quality_indicator == 177, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7]." + "stec_quality_indicator, expected 177, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7] + .sv_id.constellation == 79, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_" + "id.constellation, expected 79, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_id.satId == + 113, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_id.satId, " + "expected 113, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[7].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[0] == + 5448, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[0]," + " expected 5448, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[1] == + -11359, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[1]," + " expected -11359, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[2] == + 5574, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[2]," + " expected 5574, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[3] == + 28654, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[3]," + " expected 28654, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8] + .stec_quality_indicator == 249, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8]." + "stec_quality_indicator, expected 249, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8] + .sv_id.constellation == 100, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_" + "id.constellation, expected 100, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_id.satId == + 210, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_id.satId, " + "expected 210, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[8].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[0] == + -10783, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[0]," + " expected -10783, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[1] == + 18179, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[1]," + " expected 18179, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[2] == + 16371, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[2]," + " expected 16371, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[3] == + -5055, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[3]," + " expected -5055, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9] + .stec_quality_indicator == 227, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9]." + "stec_quality_indicator, expected 227, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9] + .sv_id.constellation == 36, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_" + "id.constellation, expected 36, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_id.satId == + 107, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_id.satId, " + "expected 107, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[9].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_coeff[0] == 4009, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[0]" + ", expected 4009, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_coeff[1] == 1462, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[1]" + ", expected 1462, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_coeff[2] == -19216, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[2]" + ", expected -19216, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_coeff[3] == 31241, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[3]" + ", expected 31241, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_quality_indicator == 0, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10]." + "stec_quality_indicator, expected 0, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .sv_id.constellation == 77, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_" + "id.constellation, expected 77, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_id.satId == + 92, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_id.satId, " + "expected 92, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[10].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_coeff[0] == 26727, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[0]" + ", expected 26727, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_coeff[1] == -16898, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[1]" + ", expected -16898, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_coeff[2] == 28241, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[2]" + ", expected 28241, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_coeff[3] == 12546, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[3]" + ", expected 12546, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_quality_indicator == 6, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11]." + "stec_quality_indicator, expected 6, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .sv_id.constellation == 232, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_" + "id.constellation, expected 232, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_id.satId == + 86, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_id.satId, " + "expected 86, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[11].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_coeff[0] == 12855, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[0]" + ", expected 12855, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_coeff[1] == 1461, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[1]" + ", expected 1461, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_coeff[2] == 20603, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[2]" + ", expected 20603, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_coeff[3] == -3023, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[3]" + ", expected -3023, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_quality_indicator == 216, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12]." + "stec_quality_indicator, expected 216, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .sv_id.constellation == 84, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_" + "id.constellation, expected 84, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_id.satId == + 202, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_id.satId, " + "expected 202, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[12].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_coeff[0] == -6492, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[0]" + ", expected -6492, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_coeff[1] == 16952, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[1]" + ", expected 16952, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_coeff[2] == -22404, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[2]" + ", expected -22404, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_coeff[3] == -29893, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[3]" + ", expected -29893, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_quality_indicator == 125, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13]." + "stec_quality_indicator, expected 125, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .sv_id.constellation == 188, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_" + "id.constellation, expected 188, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_id.satId == + 224, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_id.satId, " + "expected 224, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[13].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_coeff[0] == -10053, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[0]" + ", expected -10053, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_coeff[1] == -24897, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[1]" + ", expected -24897, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_coeff[2] == 23629, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[2]" + ", expected 23629, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_coeff[3] == -710, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[3]" + ", expected -710, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_quality_indicator == 51, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14]." + "stec_quality_indicator, expected 51, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .sv_id.constellation == 118, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_" + "id.constellation, expected 118, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_id.satId == + 106, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_id.satId, " + "expected 106, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[14].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_coeff[0] == -26103, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[0]" + ", expected -26103, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_coeff[1] == -9539, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[1]" + ", expected -9539, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_coeff[2] == -11971, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[2]" + ", expected -11971, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_coeff[3] == 20993, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[3]" + ", expected 20993, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_quality_indicator == 165, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15]." + "stec_quality_indicator, expected 165, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .sv_id.constellation == 150, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_" + "id.constellation, expected 150, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_id.satId == + 132, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_id.satId, " + "expected 132, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[15].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_coeff[0] == -18891, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[0]" + ", expected -18891, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_coeff[1] == -16272, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[1]" + ", expected -16272, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_coeff[2] == -22578, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[2]" + ", expected -22578, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_coeff[3] == -2915, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[3]" + ", expected -2915, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_quality_indicator == 23, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16]." + "stec_quality_indicator, expected 23, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .sv_id.constellation == 196, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_" + "id.constellation, expected 196, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_id.satId == + 181, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_id.satId, " + "expected 181, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[16].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_coeff[0] == 15833, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[0]" + ", expected 15833, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_coeff[1] == 24920, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[1]" + ", expected 24920, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_coeff[2] == -13879, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[2]" + ", expected -13879, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_coeff[3] == -1206, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[3]" + ", expected -1206, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_quality_indicator == 189, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17]." + "stec_quality_indicator, expected 189, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .sv_id.constellation == 1, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_" + "id.constellation, expected 1, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_id.satId == + 35, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_id.satId, " + "expected 35, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[17].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_coeff[0] == 14008, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[0]" + ", expected 14008, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_coeff[1] == 18996, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[1]" + ", expected 18996, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_coeff[2] == 2798, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[2]" + ", expected 2798, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_coeff[3] == 5761, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[3]" + ", expected 5761, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_quality_indicator == 104, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18]." + "stec_quality_indicator, expected 104, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .sv_id.constellation == 14, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_" + "id.constellation, expected 14, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_id.satId == + 217, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_id.satId, " + "expected 217, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[18].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_coeff[0] == -25256, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[0]" + ", expected -25256, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_coeff[1] == -15330, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[1]" + ", expected -15330, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_coeff[2] == 6831, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[2]" + ", expected 6831, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_coeff[3] == 8780, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[3]" + ", expected 8780, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_quality_indicator == 109, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19]." + "stec_quality_indicator, expected 109, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .sv_id.constellation == 226, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_" + "id.constellation, expected 226, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_id.satId == + 178, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_id.satId, " + "expected 178, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[19].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_coeff[0] == 3304, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[0]" + ", expected 3304, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_coeff[1] == -2893, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[1]" + ", expected -2893, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_coeff[2] == -25841, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[2]" + ", expected -25841, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_coeff[3] == -13628, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[3]" + ", expected -13628, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_quality_indicator == 154, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20]." + "stec_quality_indicator, expected 154, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .sv_id.constellation == 220, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_" + "id.constellation, expected 220, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_id.satId == + 116, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_id.satId, " + "expected 116, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[20].sv_id.satId); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_coeff[0] == -10742, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[0]" + ", expected -10742, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[0]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_coeff[1] == 10098, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[1]" + ", expected 10098, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[1]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_coeff[2] == 7413, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[2]" + ", expected 7413, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[2]); + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_coeff[3] == 17645, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[3]" + ", expected 17645, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].stec_coeff[3]); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_quality_indicator == 115, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21]." + "stec_quality_indicator, expected 115, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .stec_quality_indicator); + + ck_assert_msg(last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .sv_id.constellation == 70, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_" + "id.constellation, expected 70, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21] + .sv_id.constellation); + + ck_assert_msg( + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_id.satId == + 72, + "incorrect value for " + "last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_id.satId, " + "expected 72, is %d", + last_msg.msg.ssr_stec_correction_dep_a.stec_sat_list[21].sv_id.satId); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrStecCorrectionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c b/c/test/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c new file mode 100644 index 0000000000..e683653581 --- /dev/null +++ b/c/test/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x5f6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, + 185, 9, 181, 162, 240, 65, 19, 255, 143, 21, 191, + 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.ssr_tile_definition_dep_a.bitmask = 11259375; + + test_msg.ssr_tile_definition_dep_a.cols = 48917; + + test_msg.ssr_tile_definition_dep_a.corner_nw_lat = -18168; + + test_msg.ssr_tile_definition_dep_a.corner_nw_lon = -19191; + + test_msg.ssr_tile_definition_dep_a.rows = 36863; + + test_msg.ssr_tile_definition_dep_a.spacing_lat = 61602; + + test_msg.ssr_tile_definition_dep_a.spacing_lon = 4929; + + test_msg.ssr_tile_definition_dep_a.tile_id = 63410; + + test_msg.ssr_tile_definition_dep_a.tile_set_id = 48697; + + sbp_message_send(&sbp_state, SbpMsgSsrTileDefinitionDepA, 34248, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34248, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgSsrTileDefinitionDepA, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.bitmask == 11259375, + "incorrect value for last_msg.msg.ssr_tile_definition_dep_a.bitmask, " + "expected 11259375, is %d", + last_msg.msg.ssr_tile_definition_dep_a.bitmask); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.cols == 48917, + "incorrect value for last_msg.msg.ssr_tile_definition_dep_a.cols, " + "expected 48917, is %d", + last_msg.msg.ssr_tile_definition_dep_a.cols); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lat == -18168, + "incorrect value for " + "last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lat, expected " + "-18168, is %d", + last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lat); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lon == -19191, + "incorrect value for " + "last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lon, expected " + "-19191, is %d", + last_msg.msg.ssr_tile_definition_dep_a.corner_nw_lon); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.rows == 36863, + "incorrect value for last_msg.msg.ssr_tile_definition_dep_a.rows, " + "expected 36863, is %d", + last_msg.msg.ssr_tile_definition_dep_a.rows); + + ck_assert_msg(last_msg.msg.ssr_tile_definition_dep_a.spacing_lat == 61602, + "incorrect value for " + "last_msg.msg.ssr_tile_definition_dep_a.spacing_lat, " + "expected 61602, is %d", + last_msg.msg.ssr_tile_definition_dep_a.spacing_lat); + + ck_assert_msg(last_msg.msg.ssr_tile_definition_dep_a.spacing_lon == 4929, + "incorrect value for " + "last_msg.msg.ssr_tile_definition_dep_a.spacing_lon, " + "expected 4929, is %d", + last_msg.msg.ssr_tile_definition_dep_a.spacing_lon); + + ck_assert_msg( + last_msg.msg.ssr_tile_definition_dep_a.tile_id == 63410, + "incorrect value for last_msg.msg.ssr_tile_definition_dep_a.tile_id, " + "expected 63410, is %d", + last_msg.msg.ssr_tile_definition_dep_a.tile_id); + + ck_assert_msg(last_msg.msg.ssr_tile_definition_dep_a.tile_set_id == 48697, + "incorrect value for " + "last_msg.msg.ssr_tile_definition_dep_a.tile_set_id, " + "expected 48697, is %d", + last_msg.msg.ssr_tile_definition_dep_a.tile_set_id); + } +} +END_TEST + +Suite *auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_ssr_MsgSsrTileDefinitionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_system_MsgCsacTelemetry.c b/c/test/auto_check_sbp_system_MsgCsacTelemetry.c new file mode 100644 index 0000000000..13a661be44 --- /dev/null +++ b/c/test/auto_check_sbp_system_MsgCsacTelemetry.c @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_system_MsgCsacTelemetry) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff04, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 4, 255, 244, 169, 10, 105, 115, 111, + 109, 101, 32, 100, 97, 116, 97, 229, 94, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.csac_telemetry.id = 105; + + size_t written; + ck_assert_msg(sbp_msg_csac_telemetry_telemetry_set( + &test_msg.csac_telemetry, "some data", false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("some data"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_csac_telemetry_telemetry_encoded_len( + &test_msg.csac_telemetry) == 9, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgCsacTelemetry, 43508, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 43508, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgCsacTelemetry, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.csac_telemetry.id == 105, + "incorrect value for last_msg.msg.csac_telemetry.id, " + "expected 105, is %d", + last_msg.msg.csac_telemetry.id); + + ck_assert_msg(sbp_msg_csac_telemetry_telemetry_encoded_len( + &last_msg.msg.csac_telemetry) == 9, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_csac_telemetry_telemetry_get( + &last_msg.msg.csac_telemetry), + "some data") == 0, + "String not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_system_MsgCsacTelemetry_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_system_MsgCsacTelemetry"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_system_MsgCsacTelemetry"); + tcase_add_test(tc_acq, test_auto_check_sbp_system_MsgCsacTelemetry); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_system_MsgCsacTelemetryLabels.c b/c/test/auto_check_sbp_system_MsgCsacTelemetryLabels.c new file mode 100644 index 0000000000..f0cfa6e9aa --- /dev/null +++ b/c/test/auto_check_sbp_system_MsgCsacTelemetryLabels.c @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_system_MsgCsacTelemetryLabels) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff05, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, + 101, 32, 108, 97, 98, 101, 108, 115, 86, 236, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.csac_telemetry_labels.id = 186; + + size_t written; + ck_assert_msg( + sbp_msg_csac_telemetry_labels_telemetry_labels_set( + &test_msg.csac_telemetry_labels, "some labels", false, &written), + "Can't assign text"); + ck_assert_msg(written == strlen("some labels"), + "Wrote different to expected"); + ck_assert_msg(sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len( + &test_msg.csac_telemetry_labels) == 11, + "String not encoded properly"); + + sbp_message_send(&sbp_state, SbpMsgCsacTelemetryLabels, 51291, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 51291, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgCsacTelemetryLabels, &last_msg.msg, + &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.csac_telemetry_labels.id == 186, + "incorrect value for last_msg.msg.csac_telemetry_labels.id, " + "expected 186, is %d", + last_msg.msg.csac_telemetry_labels.id); + + ck_assert_msg(sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len( + &last_msg.msg.csac_telemetry_labels) == 11, + "Invalid encoded len"); + ck_assert_msg(strcmp(sbp_msg_csac_telemetry_labels_telemetry_labels_get( + &last_msg.msg.csac_telemetry_labels), + "some labels") == 0, + "String not decoded properly"); + } +} +END_TEST + +Suite *auto_check_sbp_system_MsgCsacTelemetryLabels_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_system_MsgCsacTelemetryLabels"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_system_MsgCsacTelemetryLabels"); + tcase_add_test(tc_acq, test_auto_check_sbp_system_MsgCsacTelemetryLabels); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_system_MsgGnssTimeOffset.c b/c/test/auto_check_sbp_system_MsgGnssTimeOffset.c new file mode 100644 index 0000000000..d617e29e23 --- /dev/null +++ b/c/test/auto_check_sbp_system_MsgGnssTimeOffset.c @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_system_MsgGnssTimeOffset) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff07, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.gnss_time_offset.flags = 221; + + test_msg.gnss_time_offset.microseconds = 9494; + + test_msg.gnss_time_offset.milliseconds = 1728664402; + + test_msg.gnss_time_offset.weeks = 14857; + + sbp_message_send(&sbp_state, SbpMsgGnssTimeOffset, 3862, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 3862, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgGnssTimeOffset, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.gnss_time_offset.flags == 221, + "incorrect value for last_msg.msg.gnss_time_offset.flags, " + "expected 221, is %d", + last_msg.msg.gnss_time_offset.flags); + + ck_assert_msg( + last_msg.msg.gnss_time_offset.microseconds == 9494, + "incorrect value for last_msg.msg.gnss_time_offset.microseconds, " + "expected 9494, is %d", + last_msg.msg.gnss_time_offset.microseconds); + + ck_assert_msg( + last_msg.msg.gnss_time_offset.milliseconds == 1728664402, + "incorrect value for last_msg.msg.gnss_time_offset.milliseconds, " + "expected 1728664402, is %d", + last_msg.msg.gnss_time_offset.milliseconds); + + ck_assert_msg(last_msg.msg.gnss_time_offset.weeks == 14857, + "incorrect value for last_msg.msg.gnss_time_offset.weeks, " + "expected 14857, is %d", + last_msg.msg.gnss_time_offset.weeks); + } +} +END_TEST + +Suite *auto_check_sbp_system_MsgGnssTimeOffset_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_system_MsgGnssTimeOffset"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_system_MsgGnssTimeOffset"); + tcase_add_test(tc_acq, test_auto_check_sbp_system_MsgGnssTimeOffset); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_system_MsgPpsTime.c b/c/test/auto_check_sbp_system_MsgPpsTime.c new file mode 100644 index 0000000000..da6f072b08 --- /dev/null +++ b/c/test/auto_check_sbp_system_MsgPpsTime.c @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_system_MsgPpsTime) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xff08, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 8, 255, 222, 209, 9, 140, 146, 133, + 197, 160, 0, 0, 0, 255, 125, 149, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.pps_time.flags = 255; + + test_msg.pps_time.time = 690508632716; + + sbp_message_send(&sbp_state, SbpMsgPpsTime, 53726, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 53726, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgPpsTime, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.pps_time.flags == 255, + "incorrect value for last_msg.msg.pps_time.flags, expected 255, is %d", + last_msg.msg.pps_time.flags); + + ck_assert_msg(last_msg.msg.pps_time.time == 690508632716, + "incorrect value for last_msg.msg.pps_time.time, expected " + "690508632716, is %d", + last_msg.msg.pps_time.time); + } +} +END_TEST + +Suite *auto_check_sbp_system_MsgPpsTime_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_system_MsgPpsTime"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_system_MsgPpsTime"); + tcase_add_test(tc_acq, test_auto_check_sbp_system_MsgPpsTime); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_system_MsgStatusReport.c b/c/test/auto_check_sbp_system_MsgStatusReport.c new file mode 100644 index 0000000000..9e23d15272 --- /dev/null +++ b/c/test/auto_check_sbp_system_MsgStatusReport.c @@ -0,0 +1,1634 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_system_MsgStatusReport) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0xfffe, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, + 233, 21, 208, 98, 247, 203, 221, 198, 156, 207, 217, 238, 162, 136, + 154, 11, 114, 236, 134, 235, 12, 133, 9, 30, 175, 145, 26, 114, + 215, 20, 146, 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, + 5, 248, 225, 149, 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, + 103, 68, 76, 184, 33, 206, 194, 163, 123, 30, 151, 176, 149, 172, + 184, 231, 118, 230, 200, 168, 100, 109, 10, 233, 4, 60, 247, 82, + 215, 166, 28, 138, 110, 45, 98, 218, 244, 179, 126, 107, 92, 124, + 94, 157, 42, 187, 124, 6, 97, 247, 160, 188, 110, 120, 254, 214, + 110, 51, 240, 164, 147, 18, 74, 178, 67, 4, 27, 73, 190, 64, + 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, 40, 161, 173, 242, + 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, 40, 191, 113, + 230, 200, 72, 8, 215, 245, 78, 59, 222, 250, 115, 32, 33, 30, + 211, 170, 145, 92, 157, 75, 24, 169, 6, 55, 62, 8, 107, 82, + 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, + 148, 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, + 23, 248, 192, 20, 83, 195, 95, 180, 54, 36, 186, 75, 64, 20, + 157, 133, 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, 245, 30, + 228, 88, 142, 212, 53, 224, 158, 166, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.status_report.n_status = 60; + + test_msg.status_report.reporting_system = 64850; + + test_msg.status_report.sbp_version = 24497; + + test_msg.status_report.sequence = 1519336451; + + test_msg.status_report.status[0].component = 52215; + + test_msg.status_report.status[0].generic = 221; + + test_msg.status_report.status[0].specific = 198; + + test_msg.status_report.status[1].component = 53148; + + test_msg.status_report.status[1].generic = 217; + + test_msg.status_report.status[1].specific = 238; + + test_msg.status_report.status[2].component = 34978; + + test_msg.status_report.status[2].generic = 154; + + test_msg.status_report.status[2].specific = 11; + + test_msg.status_report.status[3].component = 60530; + + test_msg.status_report.status[3].generic = 134; + + test_msg.status_report.status[3].specific = 235; + + test_msg.status_report.status[4].component = 34060; + + test_msg.status_report.status[4].generic = 9; + + test_msg.status_report.status[4].specific = 30; + + test_msg.status_report.status[5].component = 37295; + + test_msg.status_report.status[5].generic = 26; + + test_msg.status_report.status[5].specific = 114; + + test_msg.status_report.status[6].component = 5335; + + test_msg.status_report.status[6].generic = 146; + + test_msg.status_report.status[6].specific = 249; + + test_msg.status_report.status[7].component = 13878; + + test_msg.status_report.status[7].generic = 133; + + test_msg.status_report.status[7].specific = 193; + + test_msg.status_report.status[8].component = 47722; + + test_msg.status_report.status[8].generic = 210; + + test_msg.status_report.status[8].specific = 183; + + test_msg.status_report.status[9].component = 33024; + + test_msg.status_report.status[9].generic = 5; + + test_msg.status_report.status[9].specific = 248; + + test_msg.status_report.status[10].component = 38369; + + test_msg.status_report.status[10].generic = 135; + + test_msg.status_report.status[10].specific = 127; + + test_msg.status_report.status[11].component = 6658; + + test_msg.status_report.status[11].generic = 88; + + test_msg.status_report.status[11].specific = 92; + + test_msg.status_report.status[12].component = 26378; + + test_msg.status_report.status[12].generic = 73; + + test_msg.status_report.status[12].specific = 3; + + test_msg.status_report.status[13].component = 17511; + + test_msg.status_report.status[13].generic = 76; + + test_msg.status_report.status[13].specific = 184; + + test_msg.status_report.status[14].component = 52769; + + test_msg.status_report.status[14].generic = 194; + + test_msg.status_report.status[14].specific = 163; + + test_msg.status_report.status[15].component = 7803; + + test_msg.status_report.status[15].generic = 151; + + test_msg.status_report.status[15].specific = 176; + + test_msg.status_report.status[16].component = 44181; + + test_msg.status_report.status[16].generic = 184; + + test_msg.status_report.status[16].specific = 231; + + test_msg.status_report.status[17].component = 58998; + + test_msg.status_report.status[17].generic = 200; + + test_msg.status_report.status[17].specific = 168; + + test_msg.status_report.status[18].component = 28004; + + test_msg.status_report.status[18].generic = 10; + + test_msg.status_report.status[18].specific = 233; + + test_msg.status_report.status[19].component = 15364; + + test_msg.status_report.status[19].generic = 247; + + test_msg.status_report.status[19].specific = 82; + + test_msg.status_report.status[20].component = 42711; + + test_msg.status_report.status[20].generic = 28; + + test_msg.status_report.status[20].specific = 138; + + test_msg.status_report.status[21].component = 11630; + + test_msg.status_report.status[21].generic = 98; + + test_msg.status_report.status[21].specific = 218; + + test_msg.status_report.status[22].component = 46068; + + test_msg.status_report.status[22].generic = 126; + + test_msg.status_report.status[22].specific = 107; + + test_msg.status_report.status[23].component = 31836; + + test_msg.status_report.status[23].generic = 94; + + test_msg.status_report.status[23].specific = 157; + + test_msg.status_report.status[24].component = 47914; + + test_msg.status_report.status[24].generic = 124; + + test_msg.status_report.status[24].specific = 6; + + test_msg.status_report.status[25].component = 63329; + + test_msg.status_report.status[25].generic = 160; + + test_msg.status_report.status[25].specific = 188; + + test_msg.status_report.status[26].component = 30830; + + test_msg.status_report.status[26].generic = 254; + + test_msg.status_report.status[26].specific = 214; + + test_msg.status_report.status[27].component = 13166; + + test_msg.status_report.status[27].generic = 240; + + test_msg.status_report.status[27].specific = 164; + + test_msg.status_report.status[28].component = 4755; + + test_msg.status_report.status[28].generic = 74; + + test_msg.status_report.status[28].specific = 178; + + test_msg.status_report.status[29].component = 1091; + + test_msg.status_report.status[29].generic = 27; + + test_msg.status_report.status[29].specific = 73; + + test_msg.status_report.status[30].component = 16574; + + test_msg.status_report.status[30].generic = 179; + + test_msg.status_report.status[30].specific = 146; + + test_msg.status_report.status[31].component = 39293; + + test_msg.status_report.status[31].generic = 192; + + test_msg.status_report.status[31].specific = 46; + + test_msg.status_report.status[32].component = 17098; + + test_msg.status_report.status[32].generic = 248; + + test_msg.status_report.status[32].specific = 46; + + test_msg.status_report.status[33].component = 41256; + + test_msg.status_report.status[33].generic = 173; + + test_msg.status_report.status[33].specific = 242; + + test_msg.status_report.status[34].component = 982; + + test_msg.status_report.status[34].generic = 11; + + test_msg.status_report.status[34].specific = 1; + + test_msg.status_report.status[35].component = 18038; + + test_msg.status_report.status[35].generic = 162; + + test_msg.status_report.status[35].specific = 61; + + test_msg.status_report.status[36].component = 7090; + + test_msg.status_report.status[36].generic = 156; + + test_msg.status_report.status[36].specific = 40; + + test_msg.status_report.status[37].component = 29119; + + test_msg.status_report.status[37].generic = 230; + + test_msg.status_report.status[37].specific = 200; + + test_msg.status_report.status[38].component = 2120; + + test_msg.status_report.status[38].generic = 215; + + test_msg.status_report.status[38].specific = 245; + + test_msg.status_report.status[39].component = 15182; + + test_msg.status_report.status[39].generic = 222; + + test_msg.status_report.status[39].specific = 250; + + test_msg.status_report.status[40].component = 8307; + + test_msg.status_report.status[40].generic = 33; + + test_msg.status_report.status[40].specific = 30; + + test_msg.status_report.status[41].component = 43731; + + test_msg.status_report.status[41].generic = 145; + + test_msg.status_report.status[41].specific = 92; + + test_msg.status_report.status[42].component = 19357; + + test_msg.status_report.status[42].generic = 24; + + test_msg.status_report.status[42].specific = 169; + + test_msg.status_report.status[43].component = 14086; + + test_msg.status_report.status[43].generic = 62; + + test_msg.status_report.status[43].specific = 8; + + test_msg.status_report.status[44].component = 21099; + + test_msg.status_report.status[44].generic = 140; + + test_msg.status_report.status[44].specific = 49; + + test_msg.status_report.status[45].component = 31411; + + test_msg.status_report.status[45].generic = 90; + + test_msg.status_report.status[45].specific = 71; + + test_msg.status_report.status[46].component = 22556; + + test_msg.status_report.status[46].generic = 103; + + test_msg.status_report.status[46].specific = 51; + + test_msg.status_report.status[47].component = 18609; + + test_msg.status_report.status[47].generic = 93; + + test_msg.status_report.status[47].specific = 39; + + test_msg.status_report.status[48].component = 2964; + + test_msg.status_report.status[48].generic = 202; + + test_msg.status_report.status[48].specific = 42; + + test_msg.status_report.status[49].component = 23586; + + test_msg.status_report.status[49].generic = 204; + + test_msg.status_report.status[49].specific = 102; + + test_msg.status_report.status[50].component = 25117; + + test_msg.status_report.status[50].generic = 249; + + test_msg.status_report.status[50].specific = 91; + + test_msg.status_report.status[51].component = 24454; + + test_msg.status_report.status[51].generic = 23; + + test_msg.status_report.status[51].specific = 248; + + test_msg.status_report.status[52].component = 5312; + + test_msg.status_report.status[52].generic = 83; + + test_msg.status_report.status[52].specific = 195; + + test_msg.status_report.status[53].component = 46175; + + test_msg.status_report.status[53].generic = 54; + + test_msg.status_report.status[53].specific = 36; + + test_msg.status_report.status[54].component = 19386; + + test_msg.status_report.status[54].generic = 64; + + test_msg.status_report.status[54].specific = 20; + + test_msg.status_report.status[55].component = 34205; + + test_msg.status_report.status[55].generic = 12; + + test_msg.status_report.status[55].specific = 149; + + test_msg.status_report.status[56].component = 3612; + + test_msg.status_report.status[56].generic = 185; + + test_msg.status_report.status[56].specific = 129; + + test_msg.status_report.status[57].component = 61285; + + test_msg.status_report.status[57].generic = 74; + + test_msg.status_report.status[57].specific = 248; + + test_msg.status_report.status[58].component = 7925; + + test_msg.status_report.status[58].generic = 228; + + test_msg.status_report.status[58].specific = 88; + + test_msg.status_report.status[59].component = 54414; + + test_msg.status_report.status[59].generic = 53; + + test_msg.status_report.status[59].specific = 224; + + test_msg.status_report.uptime = 1657804265; + + sbp_message_send(&sbp_state, SbpMsgStatusReport, 21510, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 21510, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgStatusReport, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.status_report.n_status == 60, + "incorrect value for last_msg.msg.status_report.n_status, " + "expected 60, is %d", + last_msg.msg.status_report.n_status); + + ck_assert_msg( + last_msg.msg.status_report.reporting_system == 64850, + "incorrect value for last_msg.msg.status_report.reporting_system, " + "expected 64850, is %d", + last_msg.msg.status_report.reporting_system); + + ck_assert_msg(last_msg.msg.status_report.sbp_version == 24497, + "incorrect value for last_msg.msg.status_report.sbp_version, " + "expected 24497, is %d", + last_msg.msg.status_report.sbp_version); + + ck_assert_msg(last_msg.msg.status_report.sequence == 1519336451, + "incorrect value for last_msg.msg.status_report.sequence, " + "expected 1519336451, is %d", + last_msg.msg.status_report.sequence); + + ck_assert_msg( + last_msg.msg.status_report.status[0].component == 52215, + "incorrect value for last_msg.msg.status_report.status[0].component, " + "expected 52215, is %d", + last_msg.msg.status_report.status[0].component); + + ck_assert_msg( + last_msg.msg.status_report.status[0].generic == 221, + "incorrect value for last_msg.msg.status_report.status[0].generic, " + "expected 221, is %d", + last_msg.msg.status_report.status[0].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[0].specific == 198, + "incorrect value for last_msg.msg.status_report.status[0].specific, " + "expected 198, is %d", + last_msg.msg.status_report.status[0].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[1].component == 53148, + "incorrect value for last_msg.msg.status_report.status[1].component, " + "expected 53148, is %d", + last_msg.msg.status_report.status[1].component); + + ck_assert_msg( + last_msg.msg.status_report.status[1].generic == 217, + "incorrect value for last_msg.msg.status_report.status[1].generic, " + "expected 217, is %d", + last_msg.msg.status_report.status[1].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[1].specific == 238, + "incorrect value for last_msg.msg.status_report.status[1].specific, " + "expected 238, is %d", + last_msg.msg.status_report.status[1].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[2].component == 34978, + "incorrect value for last_msg.msg.status_report.status[2].component, " + "expected 34978, is %d", + last_msg.msg.status_report.status[2].component); + + ck_assert_msg( + last_msg.msg.status_report.status[2].generic == 154, + "incorrect value for last_msg.msg.status_report.status[2].generic, " + "expected 154, is %d", + last_msg.msg.status_report.status[2].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[2].specific == 11, + "incorrect value for last_msg.msg.status_report.status[2].specific, " + "expected 11, is %d", + last_msg.msg.status_report.status[2].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[3].component == 60530, + "incorrect value for last_msg.msg.status_report.status[3].component, " + "expected 60530, is %d", + last_msg.msg.status_report.status[3].component); + + ck_assert_msg( + last_msg.msg.status_report.status[3].generic == 134, + "incorrect value for last_msg.msg.status_report.status[3].generic, " + "expected 134, is %d", + last_msg.msg.status_report.status[3].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[3].specific == 235, + "incorrect value for last_msg.msg.status_report.status[3].specific, " + "expected 235, is %d", + last_msg.msg.status_report.status[3].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[4].component == 34060, + "incorrect value for last_msg.msg.status_report.status[4].component, " + "expected 34060, is %d", + last_msg.msg.status_report.status[4].component); + + ck_assert_msg( + last_msg.msg.status_report.status[4].generic == 9, + "incorrect value for last_msg.msg.status_report.status[4].generic, " + "expected 9, is %d", + last_msg.msg.status_report.status[4].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[4].specific == 30, + "incorrect value for last_msg.msg.status_report.status[4].specific, " + "expected 30, is %d", + last_msg.msg.status_report.status[4].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[5].component == 37295, + "incorrect value for last_msg.msg.status_report.status[5].component, " + "expected 37295, is %d", + last_msg.msg.status_report.status[5].component); + + ck_assert_msg( + last_msg.msg.status_report.status[5].generic == 26, + "incorrect value for last_msg.msg.status_report.status[5].generic, " + "expected 26, is %d", + last_msg.msg.status_report.status[5].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[5].specific == 114, + "incorrect value for last_msg.msg.status_report.status[5].specific, " + "expected 114, is %d", + last_msg.msg.status_report.status[5].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[6].component == 5335, + "incorrect value for last_msg.msg.status_report.status[6].component, " + "expected 5335, is %d", + last_msg.msg.status_report.status[6].component); + + ck_assert_msg( + last_msg.msg.status_report.status[6].generic == 146, + "incorrect value for last_msg.msg.status_report.status[6].generic, " + "expected 146, is %d", + last_msg.msg.status_report.status[6].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[6].specific == 249, + "incorrect value for last_msg.msg.status_report.status[6].specific, " + "expected 249, is %d", + last_msg.msg.status_report.status[6].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[7].component == 13878, + "incorrect value for last_msg.msg.status_report.status[7].component, " + "expected 13878, is %d", + last_msg.msg.status_report.status[7].component); + + ck_assert_msg( + last_msg.msg.status_report.status[7].generic == 133, + "incorrect value for last_msg.msg.status_report.status[7].generic, " + "expected 133, is %d", + last_msg.msg.status_report.status[7].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[7].specific == 193, + "incorrect value for last_msg.msg.status_report.status[7].specific, " + "expected 193, is %d", + last_msg.msg.status_report.status[7].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[8].component == 47722, + "incorrect value for last_msg.msg.status_report.status[8].component, " + "expected 47722, is %d", + last_msg.msg.status_report.status[8].component); + + ck_assert_msg( + last_msg.msg.status_report.status[8].generic == 210, + "incorrect value for last_msg.msg.status_report.status[8].generic, " + "expected 210, is %d", + last_msg.msg.status_report.status[8].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[8].specific == 183, + "incorrect value for last_msg.msg.status_report.status[8].specific, " + "expected 183, is %d", + last_msg.msg.status_report.status[8].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[9].component == 33024, + "incorrect value for last_msg.msg.status_report.status[9].component, " + "expected 33024, is %d", + last_msg.msg.status_report.status[9].component); + + ck_assert_msg( + last_msg.msg.status_report.status[9].generic == 5, + "incorrect value for last_msg.msg.status_report.status[9].generic, " + "expected 5, is %d", + last_msg.msg.status_report.status[9].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[9].specific == 248, + "incorrect value for last_msg.msg.status_report.status[9].specific, " + "expected 248, is %d", + last_msg.msg.status_report.status[9].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[10].component == 38369, + "incorrect value for last_msg.msg.status_report.status[10].component, " + "expected 38369, is %d", + last_msg.msg.status_report.status[10].component); + + ck_assert_msg( + last_msg.msg.status_report.status[10].generic == 135, + "incorrect value for last_msg.msg.status_report.status[10].generic, " + "expected 135, is %d", + last_msg.msg.status_report.status[10].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[10].specific == 127, + "incorrect value for last_msg.msg.status_report.status[10].specific, " + "expected 127, is %d", + last_msg.msg.status_report.status[10].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[11].component == 6658, + "incorrect value for last_msg.msg.status_report.status[11].component, " + "expected 6658, is %d", + last_msg.msg.status_report.status[11].component); + + ck_assert_msg( + last_msg.msg.status_report.status[11].generic == 88, + "incorrect value for last_msg.msg.status_report.status[11].generic, " + "expected 88, is %d", + last_msg.msg.status_report.status[11].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[11].specific == 92, + "incorrect value for last_msg.msg.status_report.status[11].specific, " + "expected 92, is %d", + last_msg.msg.status_report.status[11].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[12].component == 26378, + "incorrect value for last_msg.msg.status_report.status[12].component, " + "expected 26378, is %d", + last_msg.msg.status_report.status[12].component); + + ck_assert_msg( + last_msg.msg.status_report.status[12].generic == 73, + "incorrect value for last_msg.msg.status_report.status[12].generic, " + "expected 73, is %d", + last_msg.msg.status_report.status[12].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[12].specific == 3, + "incorrect value for last_msg.msg.status_report.status[12].specific, " + "expected 3, is %d", + last_msg.msg.status_report.status[12].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[13].component == 17511, + "incorrect value for last_msg.msg.status_report.status[13].component, " + "expected 17511, is %d", + last_msg.msg.status_report.status[13].component); + + ck_assert_msg( + last_msg.msg.status_report.status[13].generic == 76, + "incorrect value for last_msg.msg.status_report.status[13].generic, " + "expected 76, is %d", + last_msg.msg.status_report.status[13].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[13].specific == 184, + "incorrect value for last_msg.msg.status_report.status[13].specific, " + "expected 184, is %d", + last_msg.msg.status_report.status[13].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[14].component == 52769, + "incorrect value for last_msg.msg.status_report.status[14].component, " + "expected 52769, is %d", + last_msg.msg.status_report.status[14].component); + + ck_assert_msg( + last_msg.msg.status_report.status[14].generic == 194, + "incorrect value for last_msg.msg.status_report.status[14].generic, " + "expected 194, is %d", + last_msg.msg.status_report.status[14].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[14].specific == 163, + "incorrect value for last_msg.msg.status_report.status[14].specific, " + "expected 163, is %d", + last_msg.msg.status_report.status[14].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[15].component == 7803, + "incorrect value for last_msg.msg.status_report.status[15].component, " + "expected 7803, is %d", + last_msg.msg.status_report.status[15].component); + + ck_assert_msg( + last_msg.msg.status_report.status[15].generic == 151, + "incorrect value for last_msg.msg.status_report.status[15].generic, " + "expected 151, is %d", + last_msg.msg.status_report.status[15].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[15].specific == 176, + "incorrect value for last_msg.msg.status_report.status[15].specific, " + "expected 176, is %d", + last_msg.msg.status_report.status[15].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[16].component == 44181, + "incorrect value for last_msg.msg.status_report.status[16].component, " + "expected 44181, is %d", + last_msg.msg.status_report.status[16].component); + + ck_assert_msg( + last_msg.msg.status_report.status[16].generic == 184, + "incorrect value for last_msg.msg.status_report.status[16].generic, " + "expected 184, is %d", + last_msg.msg.status_report.status[16].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[16].specific == 231, + "incorrect value for last_msg.msg.status_report.status[16].specific, " + "expected 231, is %d", + last_msg.msg.status_report.status[16].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[17].component == 58998, + "incorrect value for last_msg.msg.status_report.status[17].component, " + "expected 58998, is %d", + last_msg.msg.status_report.status[17].component); + + ck_assert_msg( + last_msg.msg.status_report.status[17].generic == 200, + "incorrect value for last_msg.msg.status_report.status[17].generic, " + "expected 200, is %d", + last_msg.msg.status_report.status[17].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[17].specific == 168, + "incorrect value for last_msg.msg.status_report.status[17].specific, " + "expected 168, is %d", + last_msg.msg.status_report.status[17].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[18].component == 28004, + "incorrect value for last_msg.msg.status_report.status[18].component, " + "expected 28004, is %d", + last_msg.msg.status_report.status[18].component); + + ck_assert_msg( + last_msg.msg.status_report.status[18].generic == 10, + "incorrect value for last_msg.msg.status_report.status[18].generic, " + "expected 10, is %d", + last_msg.msg.status_report.status[18].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[18].specific == 233, + "incorrect value for last_msg.msg.status_report.status[18].specific, " + "expected 233, is %d", + last_msg.msg.status_report.status[18].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[19].component == 15364, + "incorrect value for last_msg.msg.status_report.status[19].component, " + "expected 15364, is %d", + last_msg.msg.status_report.status[19].component); + + ck_assert_msg( + last_msg.msg.status_report.status[19].generic == 247, + "incorrect value for last_msg.msg.status_report.status[19].generic, " + "expected 247, is %d", + last_msg.msg.status_report.status[19].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[19].specific == 82, + "incorrect value for last_msg.msg.status_report.status[19].specific, " + "expected 82, is %d", + last_msg.msg.status_report.status[19].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[20].component == 42711, + "incorrect value for last_msg.msg.status_report.status[20].component, " + "expected 42711, is %d", + last_msg.msg.status_report.status[20].component); + + ck_assert_msg( + last_msg.msg.status_report.status[20].generic == 28, + "incorrect value for last_msg.msg.status_report.status[20].generic, " + "expected 28, is %d", + last_msg.msg.status_report.status[20].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[20].specific == 138, + "incorrect value for last_msg.msg.status_report.status[20].specific, " + "expected 138, is %d", + last_msg.msg.status_report.status[20].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[21].component == 11630, + "incorrect value for last_msg.msg.status_report.status[21].component, " + "expected 11630, is %d", + last_msg.msg.status_report.status[21].component); + + ck_assert_msg( + last_msg.msg.status_report.status[21].generic == 98, + "incorrect value for last_msg.msg.status_report.status[21].generic, " + "expected 98, is %d", + last_msg.msg.status_report.status[21].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[21].specific == 218, + "incorrect value for last_msg.msg.status_report.status[21].specific, " + "expected 218, is %d", + last_msg.msg.status_report.status[21].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[22].component == 46068, + "incorrect value for last_msg.msg.status_report.status[22].component, " + "expected 46068, is %d", + last_msg.msg.status_report.status[22].component); + + ck_assert_msg( + last_msg.msg.status_report.status[22].generic == 126, + "incorrect value for last_msg.msg.status_report.status[22].generic, " + "expected 126, is %d", + last_msg.msg.status_report.status[22].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[22].specific == 107, + "incorrect value for last_msg.msg.status_report.status[22].specific, " + "expected 107, is %d", + last_msg.msg.status_report.status[22].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[23].component == 31836, + "incorrect value for last_msg.msg.status_report.status[23].component, " + "expected 31836, is %d", + last_msg.msg.status_report.status[23].component); + + ck_assert_msg( + last_msg.msg.status_report.status[23].generic == 94, + "incorrect value for last_msg.msg.status_report.status[23].generic, " + "expected 94, is %d", + last_msg.msg.status_report.status[23].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[23].specific == 157, + "incorrect value for last_msg.msg.status_report.status[23].specific, " + "expected 157, is %d", + last_msg.msg.status_report.status[23].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[24].component == 47914, + "incorrect value for last_msg.msg.status_report.status[24].component, " + "expected 47914, is %d", + last_msg.msg.status_report.status[24].component); + + ck_assert_msg( + last_msg.msg.status_report.status[24].generic == 124, + "incorrect value for last_msg.msg.status_report.status[24].generic, " + "expected 124, is %d", + last_msg.msg.status_report.status[24].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[24].specific == 6, + "incorrect value for last_msg.msg.status_report.status[24].specific, " + "expected 6, is %d", + last_msg.msg.status_report.status[24].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[25].component == 63329, + "incorrect value for last_msg.msg.status_report.status[25].component, " + "expected 63329, is %d", + last_msg.msg.status_report.status[25].component); + + ck_assert_msg( + last_msg.msg.status_report.status[25].generic == 160, + "incorrect value for last_msg.msg.status_report.status[25].generic, " + "expected 160, is %d", + last_msg.msg.status_report.status[25].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[25].specific == 188, + "incorrect value for last_msg.msg.status_report.status[25].specific, " + "expected 188, is %d", + last_msg.msg.status_report.status[25].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[26].component == 30830, + "incorrect value for last_msg.msg.status_report.status[26].component, " + "expected 30830, is %d", + last_msg.msg.status_report.status[26].component); + + ck_assert_msg( + last_msg.msg.status_report.status[26].generic == 254, + "incorrect value for last_msg.msg.status_report.status[26].generic, " + "expected 254, is %d", + last_msg.msg.status_report.status[26].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[26].specific == 214, + "incorrect value for last_msg.msg.status_report.status[26].specific, " + "expected 214, is %d", + last_msg.msg.status_report.status[26].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[27].component == 13166, + "incorrect value for last_msg.msg.status_report.status[27].component, " + "expected 13166, is %d", + last_msg.msg.status_report.status[27].component); + + ck_assert_msg( + last_msg.msg.status_report.status[27].generic == 240, + "incorrect value for last_msg.msg.status_report.status[27].generic, " + "expected 240, is %d", + last_msg.msg.status_report.status[27].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[27].specific == 164, + "incorrect value for last_msg.msg.status_report.status[27].specific, " + "expected 164, is %d", + last_msg.msg.status_report.status[27].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[28].component == 4755, + "incorrect value for last_msg.msg.status_report.status[28].component, " + "expected 4755, is %d", + last_msg.msg.status_report.status[28].component); + + ck_assert_msg( + last_msg.msg.status_report.status[28].generic == 74, + "incorrect value for last_msg.msg.status_report.status[28].generic, " + "expected 74, is %d", + last_msg.msg.status_report.status[28].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[28].specific == 178, + "incorrect value for last_msg.msg.status_report.status[28].specific, " + "expected 178, is %d", + last_msg.msg.status_report.status[28].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[29].component == 1091, + "incorrect value for last_msg.msg.status_report.status[29].component, " + "expected 1091, is %d", + last_msg.msg.status_report.status[29].component); + + ck_assert_msg( + last_msg.msg.status_report.status[29].generic == 27, + "incorrect value for last_msg.msg.status_report.status[29].generic, " + "expected 27, is %d", + last_msg.msg.status_report.status[29].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[29].specific == 73, + "incorrect value for last_msg.msg.status_report.status[29].specific, " + "expected 73, is %d", + last_msg.msg.status_report.status[29].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[30].component == 16574, + "incorrect value for last_msg.msg.status_report.status[30].component, " + "expected 16574, is %d", + last_msg.msg.status_report.status[30].component); + + ck_assert_msg( + last_msg.msg.status_report.status[30].generic == 179, + "incorrect value for last_msg.msg.status_report.status[30].generic, " + "expected 179, is %d", + last_msg.msg.status_report.status[30].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[30].specific == 146, + "incorrect value for last_msg.msg.status_report.status[30].specific, " + "expected 146, is %d", + last_msg.msg.status_report.status[30].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[31].component == 39293, + "incorrect value for last_msg.msg.status_report.status[31].component, " + "expected 39293, is %d", + last_msg.msg.status_report.status[31].component); + + ck_assert_msg( + last_msg.msg.status_report.status[31].generic == 192, + "incorrect value for last_msg.msg.status_report.status[31].generic, " + "expected 192, is %d", + last_msg.msg.status_report.status[31].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[31].specific == 46, + "incorrect value for last_msg.msg.status_report.status[31].specific, " + "expected 46, is %d", + last_msg.msg.status_report.status[31].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[32].component == 17098, + "incorrect value for last_msg.msg.status_report.status[32].component, " + "expected 17098, is %d", + last_msg.msg.status_report.status[32].component); + + ck_assert_msg( + last_msg.msg.status_report.status[32].generic == 248, + "incorrect value for last_msg.msg.status_report.status[32].generic, " + "expected 248, is %d", + last_msg.msg.status_report.status[32].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[32].specific == 46, + "incorrect value for last_msg.msg.status_report.status[32].specific, " + "expected 46, is %d", + last_msg.msg.status_report.status[32].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[33].component == 41256, + "incorrect value for last_msg.msg.status_report.status[33].component, " + "expected 41256, is %d", + last_msg.msg.status_report.status[33].component); + + ck_assert_msg( + last_msg.msg.status_report.status[33].generic == 173, + "incorrect value for last_msg.msg.status_report.status[33].generic, " + "expected 173, is %d", + last_msg.msg.status_report.status[33].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[33].specific == 242, + "incorrect value for last_msg.msg.status_report.status[33].specific, " + "expected 242, is %d", + last_msg.msg.status_report.status[33].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[34].component == 982, + "incorrect value for last_msg.msg.status_report.status[34].component, " + "expected 982, is %d", + last_msg.msg.status_report.status[34].component); + + ck_assert_msg( + last_msg.msg.status_report.status[34].generic == 11, + "incorrect value for last_msg.msg.status_report.status[34].generic, " + "expected 11, is %d", + last_msg.msg.status_report.status[34].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[34].specific == 1, + "incorrect value for last_msg.msg.status_report.status[34].specific, " + "expected 1, is %d", + last_msg.msg.status_report.status[34].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[35].component == 18038, + "incorrect value for last_msg.msg.status_report.status[35].component, " + "expected 18038, is %d", + last_msg.msg.status_report.status[35].component); + + ck_assert_msg( + last_msg.msg.status_report.status[35].generic == 162, + "incorrect value for last_msg.msg.status_report.status[35].generic, " + "expected 162, is %d", + last_msg.msg.status_report.status[35].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[35].specific == 61, + "incorrect value for last_msg.msg.status_report.status[35].specific, " + "expected 61, is %d", + last_msg.msg.status_report.status[35].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[36].component == 7090, + "incorrect value for last_msg.msg.status_report.status[36].component, " + "expected 7090, is %d", + last_msg.msg.status_report.status[36].component); + + ck_assert_msg( + last_msg.msg.status_report.status[36].generic == 156, + "incorrect value for last_msg.msg.status_report.status[36].generic, " + "expected 156, is %d", + last_msg.msg.status_report.status[36].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[36].specific == 40, + "incorrect value for last_msg.msg.status_report.status[36].specific, " + "expected 40, is %d", + last_msg.msg.status_report.status[36].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[37].component == 29119, + "incorrect value for last_msg.msg.status_report.status[37].component, " + "expected 29119, is %d", + last_msg.msg.status_report.status[37].component); + + ck_assert_msg( + last_msg.msg.status_report.status[37].generic == 230, + "incorrect value for last_msg.msg.status_report.status[37].generic, " + "expected 230, is %d", + last_msg.msg.status_report.status[37].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[37].specific == 200, + "incorrect value for last_msg.msg.status_report.status[37].specific, " + "expected 200, is %d", + last_msg.msg.status_report.status[37].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[38].component == 2120, + "incorrect value for last_msg.msg.status_report.status[38].component, " + "expected 2120, is %d", + last_msg.msg.status_report.status[38].component); + + ck_assert_msg( + last_msg.msg.status_report.status[38].generic == 215, + "incorrect value for last_msg.msg.status_report.status[38].generic, " + "expected 215, is %d", + last_msg.msg.status_report.status[38].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[38].specific == 245, + "incorrect value for last_msg.msg.status_report.status[38].specific, " + "expected 245, is %d", + last_msg.msg.status_report.status[38].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[39].component == 15182, + "incorrect value for last_msg.msg.status_report.status[39].component, " + "expected 15182, is %d", + last_msg.msg.status_report.status[39].component); + + ck_assert_msg( + last_msg.msg.status_report.status[39].generic == 222, + "incorrect value for last_msg.msg.status_report.status[39].generic, " + "expected 222, is %d", + last_msg.msg.status_report.status[39].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[39].specific == 250, + "incorrect value for last_msg.msg.status_report.status[39].specific, " + "expected 250, is %d", + last_msg.msg.status_report.status[39].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[40].component == 8307, + "incorrect value for last_msg.msg.status_report.status[40].component, " + "expected 8307, is %d", + last_msg.msg.status_report.status[40].component); + + ck_assert_msg( + last_msg.msg.status_report.status[40].generic == 33, + "incorrect value for last_msg.msg.status_report.status[40].generic, " + "expected 33, is %d", + last_msg.msg.status_report.status[40].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[40].specific == 30, + "incorrect value for last_msg.msg.status_report.status[40].specific, " + "expected 30, is %d", + last_msg.msg.status_report.status[40].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[41].component == 43731, + "incorrect value for last_msg.msg.status_report.status[41].component, " + "expected 43731, is %d", + last_msg.msg.status_report.status[41].component); + + ck_assert_msg( + last_msg.msg.status_report.status[41].generic == 145, + "incorrect value for last_msg.msg.status_report.status[41].generic, " + "expected 145, is %d", + last_msg.msg.status_report.status[41].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[41].specific == 92, + "incorrect value for last_msg.msg.status_report.status[41].specific, " + "expected 92, is %d", + last_msg.msg.status_report.status[41].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[42].component == 19357, + "incorrect value for last_msg.msg.status_report.status[42].component, " + "expected 19357, is %d", + last_msg.msg.status_report.status[42].component); + + ck_assert_msg( + last_msg.msg.status_report.status[42].generic == 24, + "incorrect value for last_msg.msg.status_report.status[42].generic, " + "expected 24, is %d", + last_msg.msg.status_report.status[42].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[42].specific == 169, + "incorrect value for last_msg.msg.status_report.status[42].specific, " + "expected 169, is %d", + last_msg.msg.status_report.status[42].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[43].component == 14086, + "incorrect value for last_msg.msg.status_report.status[43].component, " + "expected 14086, is %d", + last_msg.msg.status_report.status[43].component); + + ck_assert_msg( + last_msg.msg.status_report.status[43].generic == 62, + "incorrect value for last_msg.msg.status_report.status[43].generic, " + "expected 62, is %d", + last_msg.msg.status_report.status[43].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[43].specific == 8, + "incorrect value for last_msg.msg.status_report.status[43].specific, " + "expected 8, is %d", + last_msg.msg.status_report.status[43].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[44].component == 21099, + "incorrect value for last_msg.msg.status_report.status[44].component, " + "expected 21099, is %d", + last_msg.msg.status_report.status[44].component); + + ck_assert_msg( + last_msg.msg.status_report.status[44].generic == 140, + "incorrect value for last_msg.msg.status_report.status[44].generic, " + "expected 140, is %d", + last_msg.msg.status_report.status[44].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[44].specific == 49, + "incorrect value for last_msg.msg.status_report.status[44].specific, " + "expected 49, is %d", + last_msg.msg.status_report.status[44].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[45].component == 31411, + "incorrect value for last_msg.msg.status_report.status[45].component, " + "expected 31411, is %d", + last_msg.msg.status_report.status[45].component); + + ck_assert_msg( + last_msg.msg.status_report.status[45].generic == 90, + "incorrect value for last_msg.msg.status_report.status[45].generic, " + "expected 90, is %d", + last_msg.msg.status_report.status[45].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[45].specific == 71, + "incorrect value for last_msg.msg.status_report.status[45].specific, " + "expected 71, is %d", + last_msg.msg.status_report.status[45].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[46].component == 22556, + "incorrect value for last_msg.msg.status_report.status[46].component, " + "expected 22556, is %d", + last_msg.msg.status_report.status[46].component); + + ck_assert_msg( + last_msg.msg.status_report.status[46].generic == 103, + "incorrect value for last_msg.msg.status_report.status[46].generic, " + "expected 103, is %d", + last_msg.msg.status_report.status[46].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[46].specific == 51, + "incorrect value for last_msg.msg.status_report.status[46].specific, " + "expected 51, is %d", + last_msg.msg.status_report.status[46].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[47].component == 18609, + "incorrect value for last_msg.msg.status_report.status[47].component, " + "expected 18609, is %d", + last_msg.msg.status_report.status[47].component); + + ck_assert_msg( + last_msg.msg.status_report.status[47].generic == 93, + "incorrect value for last_msg.msg.status_report.status[47].generic, " + "expected 93, is %d", + last_msg.msg.status_report.status[47].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[47].specific == 39, + "incorrect value for last_msg.msg.status_report.status[47].specific, " + "expected 39, is %d", + last_msg.msg.status_report.status[47].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[48].component == 2964, + "incorrect value for last_msg.msg.status_report.status[48].component, " + "expected 2964, is %d", + last_msg.msg.status_report.status[48].component); + + ck_assert_msg( + last_msg.msg.status_report.status[48].generic == 202, + "incorrect value for last_msg.msg.status_report.status[48].generic, " + "expected 202, is %d", + last_msg.msg.status_report.status[48].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[48].specific == 42, + "incorrect value for last_msg.msg.status_report.status[48].specific, " + "expected 42, is %d", + last_msg.msg.status_report.status[48].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[49].component == 23586, + "incorrect value for last_msg.msg.status_report.status[49].component, " + "expected 23586, is %d", + last_msg.msg.status_report.status[49].component); + + ck_assert_msg( + last_msg.msg.status_report.status[49].generic == 204, + "incorrect value for last_msg.msg.status_report.status[49].generic, " + "expected 204, is %d", + last_msg.msg.status_report.status[49].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[49].specific == 102, + "incorrect value for last_msg.msg.status_report.status[49].specific, " + "expected 102, is %d", + last_msg.msg.status_report.status[49].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[50].component == 25117, + "incorrect value for last_msg.msg.status_report.status[50].component, " + "expected 25117, is %d", + last_msg.msg.status_report.status[50].component); + + ck_assert_msg( + last_msg.msg.status_report.status[50].generic == 249, + "incorrect value for last_msg.msg.status_report.status[50].generic, " + "expected 249, is %d", + last_msg.msg.status_report.status[50].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[50].specific == 91, + "incorrect value for last_msg.msg.status_report.status[50].specific, " + "expected 91, is %d", + last_msg.msg.status_report.status[50].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[51].component == 24454, + "incorrect value for last_msg.msg.status_report.status[51].component, " + "expected 24454, is %d", + last_msg.msg.status_report.status[51].component); + + ck_assert_msg( + last_msg.msg.status_report.status[51].generic == 23, + "incorrect value for last_msg.msg.status_report.status[51].generic, " + "expected 23, is %d", + last_msg.msg.status_report.status[51].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[51].specific == 248, + "incorrect value for last_msg.msg.status_report.status[51].specific, " + "expected 248, is %d", + last_msg.msg.status_report.status[51].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[52].component == 5312, + "incorrect value for last_msg.msg.status_report.status[52].component, " + "expected 5312, is %d", + last_msg.msg.status_report.status[52].component); + + ck_assert_msg( + last_msg.msg.status_report.status[52].generic == 83, + "incorrect value for last_msg.msg.status_report.status[52].generic, " + "expected 83, is %d", + last_msg.msg.status_report.status[52].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[52].specific == 195, + "incorrect value for last_msg.msg.status_report.status[52].specific, " + "expected 195, is %d", + last_msg.msg.status_report.status[52].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[53].component == 46175, + "incorrect value for last_msg.msg.status_report.status[53].component, " + "expected 46175, is %d", + last_msg.msg.status_report.status[53].component); + + ck_assert_msg( + last_msg.msg.status_report.status[53].generic == 54, + "incorrect value for last_msg.msg.status_report.status[53].generic, " + "expected 54, is %d", + last_msg.msg.status_report.status[53].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[53].specific == 36, + "incorrect value for last_msg.msg.status_report.status[53].specific, " + "expected 36, is %d", + last_msg.msg.status_report.status[53].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[54].component == 19386, + "incorrect value for last_msg.msg.status_report.status[54].component, " + "expected 19386, is %d", + last_msg.msg.status_report.status[54].component); + + ck_assert_msg( + last_msg.msg.status_report.status[54].generic == 64, + "incorrect value for last_msg.msg.status_report.status[54].generic, " + "expected 64, is %d", + last_msg.msg.status_report.status[54].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[54].specific == 20, + "incorrect value for last_msg.msg.status_report.status[54].specific, " + "expected 20, is %d", + last_msg.msg.status_report.status[54].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[55].component == 34205, + "incorrect value for last_msg.msg.status_report.status[55].component, " + "expected 34205, is %d", + last_msg.msg.status_report.status[55].component); + + ck_assert_msg( + last_msg.msg.status_report.status[55].generic == 12, + "incorrect value for last_msg.msg.status_report.status[55].generic, " + "expected 12, is %d", + last_msg.msg.status_report.status[55].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[55].specific == 149, + "incorrect value for last_msg.msg.status_report.status[55].specific, " + "expected 149, is %d", + last_msg.msg.status_report.status[55].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[56].component == 3612, + "incorrect value for last_msg.msg.status_report.status[56].component, " + "expected 3612, is %d", + last_msg.msg.status_report.status[56].component); + + ck_assert_msg( + last_msg.msg.status_report.status[56].generic == 185, + "incorrect value for last_msg.msg.status_report.status[56].generic, " + "expected 185, is %d", + last_msg.msg.status_report.status[56].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[56].specific == 129, + "incorrect value for last_msg.msg.status_report.status[56].specific, " + "expected 129, is %d", + last_msg.msg.status_report.status[56].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[57].component == 61285, + "incorrect value for last_msg.msg.status_report.status[57].component, " + "expected 61285, is %d", + last_msg.msg.status_report.status[57].component); + + ck_assert_msg( + last_msg.msg.status_report.status[57].generic == 74, + "incorrect value for last_msg.msg.status_report.status[57].generic, " + "expected 74, is %d", + last_msg.msg.status_report.status[57].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[57].specific == 248, + "incorrect value for last_msg.msg.status_report.status[57].specific, " + "expected 248, is %d", + last_msg.msg.status_report.status[57].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[58].component == 7925, + "incorrect value for last_msg.msg.status_report.status[58].component, " + "expected 7925, is %d", + last_msg.msg.status_report.status[58].component); + + ck_assert_msg( + last_msg.msg.status_report.status[58].generic == 228, + "incorrect value for last_msg.msg.status_report.status[58].generic, " + "expected 228, is %d", + last_msg.msg.status_report.status[58].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[58].specific == 88, + "incorrect value for last_msg.msg.status_report.status[58].specific, " + "expected 88, is %d", + last_msg.msg.status_report.status[58].specific); + + ck_assert_msg( + last_msg.msg.status_report.status[59].component == 54414, + "incorrect value for last_msg.msg.status_report.status[59].component, " + "expected 54414, is %d", + last_msg.msg.status_report.status[59].component); + + ck_assert_msg( + last_msg.msg.status_report.status[59].generic == 53, + "incorrect value for last_msg.msg.status_report.status[59].generic, " + "expected 53, is %d", + last_msg.msg.status_report.status[59].generic); + + ck_assert_msg( + last_msg.msg.status_report.status[59].specific == 224, + "incorrect value for last_msg.msg.status_report.status[59].specific, " + "expected 224, is %d", + last_msg.msg.status_report.status[59].specific); + + ck_assert_msg(last_msg.msg.status_report.uptime == 1657804265, + "incorrect value for last_msg.msg.status_report.uptime, " + "expected 1657804265, is %d", + last_msg.msg.status_report.uptime); + } +} +END_TEST + +Suite *auto_check_sbp_system_MsgStatusReport_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_system_MsgStatusReport"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_system_MsgStatusReport"); + tcase_add_test(tc_acq, test_auto_check_sbp_system_MsgStatusReport); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingIq.c b/c/test/auto_check_sbp_tracking_MsgTrackingIq.c new file mode 100644 index 0000000000..fd976f5220 --- /dev/null +++ b/c/test/auto_check_sbp_tracking_MsgTrackingIq.c @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_tracking_MsgTrackingIq) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x2d, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, + 55, 45, 38, 189, 88, 159, 19, 208, 12, 97, 167, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_iq.channel = 145; + + test_msg.tracking_iq.corrs[0].I = -9937; + + test_msg.tracking_iq.corrs[0].Q = 14319; + + test_msg.tracking_iq.corrs[1].I = 9773; + + test_msg.tracking_iq.corrs[1].Q = 22717; + + test_msg.tracking_iq.corrs[2].I = 5023; + + test_msg.tracking_iq.corrs[2].Q = 3280; + + test_msg.tracking_iq.sid.code = 203; + + test_msg.tracking_iq.sid.sat = 121; + + sbp_message_send(&sbp_state, SbpMsgTrackingIq, 20482, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 20482, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgTrackingIq, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.tracking_iq.channel == 145, + "incorrect value for last_msg.msg.tracking_iq.channel, " + "expected 145, is %d", + last_msg.msg.tracking_iq.channel); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[0].I == -9937, + "incorrect value for last_msg.msg.tracking_iq.corrs[0].I, " + "expected -9937, is %d", + last_msg.msg.tracking_iq.corrs[0].I); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[0].Q == 14319, + "incorrect value for last_msg.msg.tracking_iq.corrs[0].Q, " + "expected 14319, is %d", + last_msg.msg.tracking_iq.corrs[0].Q); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[1].I == 9773, + "incorrect value for last_msg.msg.tracking_iq.corrs[1].I, " + "expected 9773, is %d", + last_msg.msg.tracking_iq.corrs[1].I); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[1].Q == 22717, + "incorrect value for last_msg.msg.tracking_iq.corrs[1].Q, " + "expected 22717, is %d", + last_msg.msg.tracking_iq.corrs[1].Q); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[2].I == 5023, + "incorrect value for last_msg.msg.tracking_iq.corrs[2].I, " + "expected 5023, is %d", + last_msg.msg.tracking_iq.corrs[2].I); + + ck_assert_msg(last_msg.msg.tracking_iq.corrs[2].Q == 3280, + "incorrect value for last_msg.msg.tracking_iq.corrs[2].Q, " + "expected 3280, is %d", + last_msg.msg.tracking_iq.corrs[2].Q); + + ck_assert_msg(last_msg.msg.tracking_iq.sid.code == 203, + "incorrect value for last_msg.msg.tracking_iq.sid.code, " + "expected 203, is %d", + last_msg.msg.tracking_iq.sid.code); + + ck_assert_msg(last_msg.msg.tracking_iq.sid.sat == 121, + "incorrect value for last_msg.msg.tracking_iq.sid.sat, " + "expected 121, is %d", + last_msg.msg.tracking_iq.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_tracking_MsgTrackingIq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_tracking_MsgTrackingIq"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_tracking_MsgTrackingIq"); + tcase_add_test(tc_acq, test_auto_check_sbp_tracking_MsgTrackingIq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingIqDepA.c b/c/test/auto_check_sbp_tracking_MsgTrackingIqDepA.c new file mode 100644 index 0000000000..84a7986d66 --- /dev/null +++ b/c/test/auto_check_sbp_tracking_MsgTrackingIqDepA.c @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_tracking_MsgTrackingIqDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x1c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, + 170, 96, 71, 121, 33, 161, 52, 211, 162, 101, 41, 36, 226, + 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_iq_dep_a.channel = 139; + + test_msg.tracking_iq_dep_a.corrs[0].I = 1621776995; + + test_msg.tracking_iq_dep_a.corrs[0].Q = -1591641785; + + test_msg.tracking_iq_dep_a.corrs[1].I = 1705169716; + + test_msg.tracking_iq_dep_a.corrs[1].Q = 1675764777; + + test_msg.tracking_iq_dep_a.corrs[2].I = -267498681; + + test_msg.tracking_iq_dep_a.corrs[2].Q = 1403998854; + + test_msg.tracking_iq_dep_a.sid.code = 15; + + test_msg.tracking_iq_dep_a.sid.reserved = 0; + + test_msg.tracking_iq_dep_a.sid.sat = 64028; + + sbp_message_send(&sbp_state, SbpMsgTrackingIqDepA, 17336, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 17336, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgTrackingIqDepA, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.tracking_iq_dep_a.channel == 139, + "incorrect value for last_msg.msg.tracking_iq_dep_a.channel, " + "expected 139, is %d", + last_msg.msg.tracking_iq_dep_a.channel); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[0].I == 1621776995, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[0].I, " + "expected 1621776995, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[0].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[0].Q == -1591641785, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[0].Q, " + "expected -1591641785, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[0].Q); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[1].I == 1705169716, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[1].I, " + "expected 1705169716, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[1].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[1].Q == 1675764777, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[1].Q, " + "expected 1675764777, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[1].Q); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[2].I == -267498681, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[2].I, " + "expected -267498681, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[2].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.corrs[2].Q == 1403998854, + "incorrect value for last_msg.msg.tracking_iq_dep_a.corrs[2].Q, " + "expected 1403998854, is %d", + last_msg.msg.tracking_iq_dep_a.corrs[2].Q); + + ck_assert_msg(last_msg.msg.tracking_iq_dep_a.sid.code == 15, + "incorrect value for " + "last_msg.msg.tracking_iq_dep_a.sid.code, expected 15, is %d", + last_msg.msg.tracking_iq_dep_a.sid.code); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_a.sid.reserved == 0, + "incorrect value for last_msg.msg.tracking_iq_dep_a.sid.reserved, " + "expected 0, is %d", + last_msg.msg.tracking_iq_dep_a.sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_iq_dep_a.sid.sat == 64028, + "incorrect value for last_msg.msg.tracking_iq_dep_a.sid.sat, " + "expected 64028, is %d", + last_msg.msg.tracking_iq_dep_a.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_tracking_MsgTrackingIqDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_tracking_MsgTrackingIqDepA"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_tracking_MsgTrackingIqDepA"); + tcase_add_test(tc_acq, test_auto_check_sbp_tracking_MsgTrackingIqDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingIqDepB.c b/c/test/auto_check_sbp_tracking_MsgTrackingIqDepB.c new file mode 100644 index 0000000000..0cc82d96a1 --- /dev/null +++ b/c/test/auto_check_sbp_tracking_MsgTrackingIqDepB.c @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_tracking_MsgTrackingIqDepB) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x2c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, + 15, 187, 249, 101, 24, 135, 146, 180, 224, 123, 235, 142, + 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_iq_dep_b.channel = 45; + + test_msg.tracking_iq_dep_b.corrs[0].I = 261994824; + + test_msg.tracking_iq_dep_b.corrs[0].Q = 409336251; + + test_msg.tracking_iq_dep_b.corrs[1].I = -525036921; + + test_msg.tracking_iq_dep_b.corrs[1].Q = -795939973; + + test_msg.tracking_iq_dep_b.corrs[2].I = 353988710; + + test_msg.tracking_iq_dep_b.corrs[2].Q = 1148477617; + + test_msg.tracking_iq_dep_b.sid.code = 183; + + test_msg.tracking_iq_dep_b.sid.sat = 188; + + sbp_message_send(&sbp_state, SbpMsgTrackingIqDepB, 25895, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 25895, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgTrackingIqDepB, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.tracking_iq_dep_b.channel == 45, + "incorrect value for last_msg.msg.tracking_iq_dep_b.channel, " + "expected 45, is %d", + last_msg.msg.tracking_iq_dep_b.channel); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[0].I == 261994824, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[0].I, " + "expected 261994824, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[0].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[0].Q == 409336251, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[0].Q, " + "expected 409336251, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[0].Q); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[1].I == -525036921, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[1].I, " + "expected -525036921, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[1].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[1].Q == -795939973, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[1].Q, " + "expected -795939973, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[1].Q); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[2].I == 353988710, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[2].I, " + "expected 353988710, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[2].I); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.corrs[2].Q == 1148477617, + "incorrect value for last_msg.msg.tracking_iq_dep_b.corrs[2].Q, " + "expected 1148477617, is %d", + last_msg.msg.tracking_iq_dep_b.corrs[2].Q); + + ck_assert_msg( + last_msg.msg.tracking_iq_dep_b.sid.code == 183, + "incorrect value for last_msg.msg.tracking_iq_dep_b.sid.code, expected " + "183, is %d", + last_msg.msg.tracking_iq_dep_b.sid.code); + + ck_assert_msg(last_msg.msg.tracking_iq_dep_b.sid.sat == 188, + "incorrect value for last_msg.msg.tracking_iq_dep_b.sid.sat, " + "expected 188, is %d", + last_msg.msg.tracking_iq_dep_b.sid.sat); + } +} +END_TEST + +Suite *auto_check_sbp_tracking_MsgTrackingIqDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_tracking_MsgTrackingIqDepB"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_tracking_MsgTrackingIqDepB"); + tcase_add_test(tc_acq, test_auto_check_sbp_tracking_MsgTrackingIqDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingState.c b/c/test/auto_check_sbp_tracking_MsgTrackingState.c index 8b61fc01bf..b553bcf856 100644 --- a/c/test/auto_check_sbp_tracking_MsgTrackingState.c +++ b/c/test/auto_check_sbp_tracking_MsgTrackingState.c @@ -90,6 +90,2095 @@ START_TEST(test_auto_check_sbp_tracking_MsgTrackingState) { logging_reset(); + sbp_callback_register(&sbp_state, 0x41, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, + 25, 4, 90, 195, 246, 108, 75, 82, 137, 127, 45, 163, 32, 46, + 187, 93, 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, 219, 69, + 254, 136, 3, 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, + 218, 62, 242, 84, 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, + 253, 227, 216, 227, 24, 26, 210, 179, 19, 15, 227, 255, 122, 75, + 187, 200, 217, 48, 218, 122, 187, 238, 142, 149, 238, 55, 251, 212, + 128, 160, 194, 104, 113, 255, 141, 62, 43, 69, 245, 39, 100, 230, + 108, 56, 247, 68, 149, 143, 137, 101, 233, 70, 49, 165, 38, 110, + 218, 230, 80, 213, 196, 179, 139, 128, 15, 178, 196, 171, 8, 212, + 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, 5, 25, 105, 186, + 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, 49, 86, 19, + 142, 146, 91, 124, 115, 64, 28, 230, 115, 178, 190, 131, 16, 242, + 105, 59, 182, 113, 192, 180, 48, 179, 166, 31, 172, 211, 77, 228, + 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, 129, 55, + 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, + 148, 190, 236, 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, + 219, 172, 145, 17, 192, 179, 111, 97, 207, 56, 208, 134, 180, 17, + 43, 226, 255, 182, 140, 113, 141, 111, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_state.n_states = 63; + + test_msg.tracking_state.states[0].cn0 = 102; + + test_msg.tracking_state.states[0].fcn = 3; + + test_msg.tracking_state.states[0].sid.code = 184; + + test_msg.tracking_state.states[0].sid.sat = 117; + + test_msg.tracking_state.states[1].cn0 = 141; + + test_msg.tracking_state.states[1].fcn = 140; + + test_msg.tracking_state.states[1].sid.code = 106; + + test_msg.tracking_state.states[1].sid.sat = 38; + + test_msg.tracking_state.states[2].cn0 = 195; + + test_msg.tracking_state.states[2].fcn = 90; + + test_msg.tracking_state.states[2].sid.code = 4; + + test_msg.tracking_state.states[2].sid.sat = 25; + + test_msg.tracking_state.states[3].cn0 = 82; + + test_msg.tracking_state.states[3].fcn = 75; + + test_msg.tracking_state.states[3].sid.code = 108; + + test_msg.tracking_state.states[3].sid.sat = 246; + + test_msg.tracking_state.states[4].cn0 = 163; + + test_msg.tracking_state.states[4].fcn = 45; + + test_msg.tracking_state.states[4].sid.code = 127; + + test_msg.tracking_state.states[4].sid.sat = 137; + + test_msg.tracking_state.states[5].cn0 = 93; + + test_msg.tracking_state.states[5].fcn = 187; + + test_msg.tracking_state.states[5].sid.code = 46; + + test_msg.tracking_state.states[5].sid.sat = 32; + + test_msg.tracking_state.states[6].cn0 = 147; + + test_msg.tracking_state.states[6].fcn = 201; + + test_msg.tracking_state.states[6].sid.code = 60; + + test_msg.tracking_state.states[6].sid.sat = 153; + + test_msg.tracking_state.states[7].cn0 = 208; + + test_msg.tracking_state.states[7].fcn = 5; + + test_msg.tracking_state.states[7].sid.code = 29; + + test_msg.tracking_state.states[7].sid.sat = 23; + + test_msg.tracking_state.states[8].cn0 = 69; + + test_msg.tracking_state.states[8].fcn = 219; + + test_msg.tracking_state.states[8].sid.code = 30; + + test_msg.tracking_state.states[8].sid.sat = 181; + + test_msg.tracking_state.states[9].cn0 = 121; + + test_msg.tracking_state.states[9].fcn = 3; + + test_msg.tracking_state.states[9].sid.code = 136; + + test_msg.tracking_state.states[9].sid.sat = 254; + + test_msg.tracking_state.states[10].cn0 = 215; + + test_msg.tracking_state.states[10].fcn = 144; + + test_msg.tracking_state.states[10].sid.code = 98; + + test_msg.tracking_state.states[10].sid.sat = 33; + + test_msg.tracking_state.states[11].cn0 = 56; + + test_msg.tracking_state.states[11].fcn = 14; + + test_msg.tracking_state.states[11].sid.code = 182; + + test_msg.tracking_state.states[11].sid.sat = 133; + + test_msg.tracking_state.states[12].cn0 = 62; + + test_msg.tracking_state.states[12].fcn = 218; + + test_msg.tracking_state.states[12].sid.code = 77; + + test_msg.tracking_state.states[12].sid.sat = 169; + + test_msg.tracking_state.states[13].cn0 = 249; + + test_msg.tracking_state.states[13].fcn = 171; + + test_msg.tracking_state.states[13].sid.code = 84; + + test_msg.tracking_state.states[13].sid.sat = 242; + + test_msg.tracking_state.states[14].cn0 = 130; + + test_msg.tracking_state.states[14].fcn = 131; + + test_msg.tracking_state.states[14].sid.code = 137; + + test_msg.tracking_state.states[14].sid.sat = 152; + + test_msg.tracking_state.states[15].cn0 = 68; + + test_msg.tracking_state.states[15].fcn = 42; + + test_msg.tracking_state.states[15].sid.code = 21; + + test_msg.tracking_state.states[15].sid.sat = 193; + + test_msg.tracking_state.states[16].cn0 = 227; + + test_msg.tracking_state.states[16].fcn = 216; + + test_msg.tracking_state.states[16].sid.code = 227; + + test_msg.tracking_state.states[16].sid.sat = 253; + + test_msg.tracking_state.states[17].cn0 = 179; + + test_msg.tracking_state.states[17].fcn = 210; + + test_msg.tracking_state.states[17].sid.code = 26; + + test_msg.tracking_state.states[17].sid.sat = 24; + + test_msg.tracking_state.states[18].cn0 = 255; + + test_msg.tracking_state.states[18].fcn = 227; + + test_msg.tracking_state.states[18].sid.code = 15; + + test_msg.tracking_state.states[18].sid.sat = 19; + + test_msg.tracking_state.states[19].cn0 = 200; + + test_msg.tracking_state.states[19].fcn = 187; + + test_msg.tracking_state.states[19].sid.code = 75; + + test_msg.tracking_state.states[19].sid.sat = 122; + + test_msg.tracking_state.states[20].cn0 = 122; + + test_msg.tracking_state.states[20].fcn = 218; + + test_msg.tracking_state.states[20].sid.code = 48; + + test_msg.tracking_state.states[20].sid.sat = 217; + + test_msg.tracking_state.states[21].cn0 = 149; + + test_msg.tracking_state.states[21].fcn = 142; + + test_msg.tracking_state.states[21].sid.code = 238; + + test_msg.tracking_state.states[21].sid.sat = 187; + + test_msg.tracking_state.states[22].cn0 = 212; + + test_msg.tracking_state.states[22].fcn = 251; + + test_msg.tracking_state.states[22].sid.code = 55; + + test_msg.tracking_state.states[22].sid.sat = 238; + + test_msg.tracking_state.states[23].cn0 = 104; + + test_msg.tracking_state.states[23].fcn = 194; + + test_msg.tracking_state.states[23].sid.code = 160; + + test_msg.tracking_state.states[23].sid.sat = 128; + + test_msg.tracking_state.states[24].cn0 = 62; + + test_msg.tracking_state.states[24].fcn = 141; + + test_msg.tracking_state.states[24].sid.code = 255; + + test_msg.tracking_state.states[24].sid.sat = 113; + + test_msg.tracking_state.states[25].cn0 = 39; + + test_msg.tracking_state.states[25].fcn = 245; + + test_msg.tracking_state.states[25].sid.code = 69; + + test_msg.tracking_state.states[25].sid.sat = 43; + + test_msg.tracking_state.states[26].cn0 = 56; + + test_msg.tracking_state.states[26].fcn = 108; + + test_msg.tracking_state.states[26].sid.code = 230; + + test_msg.tracking_state.states[26].sid.sat = 100; + + test_msg.tracking_state.states[27].cn0 = 143; + + test_msg.tracking_state.states[27].fcn = 149; + + test_msg.tracking_state.states[27].sid.code = 68; + + test_msg.tracking_state.states[27].sid.sat = 247; + + test_msg.tracking_state.states[28].cn0 = 70; + + test_msg.tracking_state.states[28].fcn = 233; + + test_msg.tracking_state.states[28].sid.code = 101; + + test_msg.tracking_state.states[28].sid.sat = 137; + + test_msg.tracking_state.states[29].cn0 = 110; + + test_msg.tracking_state.states[29].fcn = 38; + + test_msg.tracking_state.states[29].sid.code = 165; + + test_msg.tracking_state.states[29].sid.sat = 49; + + test_msg.tracking_state.states[30].cn0 = 213; + + test_msg.tracking_state.states[30].fcn = 80; + + test_msg.tracking_state.states[30].sid.code = 230; + + test_msg.tracking_state.states[30].sid.sat = 218; + + test_msg.tracking_state.states[31].cn0 = 128; + + test_msg.tracking_state.states[31].fcn = 139; + + test_msg.tracking_state.states[31].sid.code = 179; + + test_msg.tracking_state.states[31].sid.sat = 196; + + test_msg.tracking_state.states[32].cn0 = 171; + + test_msg.tracking_state.states[32].fcn = 196; + + test_msg.tracking_state.states[32].sid.code = 178; + + test_msg.tracking_state.states[32].sid.sat = 15; + + test_msg.tracking_state.states[33].cn0 = 194; + + test_msg.tracking_state.states[33].fcn = 97; + + test_msg.tracking_state.states[33].sid.code = 212; + + test_msg.tracking_state.states[33].sid.sat = 8; + + test_msg.tracking_state.states[34].cn0 = 99; + + test_msg.tracking_state.states[34].fcn = 79; + + test_msg.tracking_state.states[34].sid.code = 233; + + test_msg.tracking_state.states[34].sid.sat = 83; + + test_msg.tracking_state.states[35].cn0 = 180; + + test_msg.tracking_state.states[35].fcn = 31; + + test_msg.tracking_state.states[35].sid.code = 90; + + test_msg.tracking_state.states[35].sid.sat = 55; + + test_msg.tracking_state.states[36].cn0 = 186; + + test_msg.tracking_state.states[36].fcn = 105; + + test_msg.tracking_state.states[36].sid.code = 25; + + test_msg.tracking_state.states[36].sid.sat = 5; + + test_msg.tracking_state.states[37].cn0 = 111; + + test_msg.tracking_state.states[37].fcn = 80; + + test_msg.tracking_state.states[37].sid.code = 224; + + test_msg.tracking_state.states[37].sid.sat = 22; + + test_msg.tracking_state.states[38].cn0 = 166; + + test_msg.tracking_state.states[38].fcn = 106; + + test_msg.tracking_state.states[38].sid.code = 48; + + test_msg.tracking_state.states[38].sid.sat = 8; + + test_msg.tracking_state.states[39].cn0 = 49; + + test_msg.tracking_state.states[39].fcn = 156; + + test_msg.tracking_state.states[39].sid.code = 48; + + test_msg.tracking_state.states[39].sid.sat = 4; + + test_msg.tracking_state.states[40].cn0 = 146; + + test_msg.tracking_state.states[40].fcn = 142; + + test_msg.tracking_state.states[40].sid.code = 19; + + test_msg.tracking_state.states[40].sid.sat = 86; + + test_msg.tracking_state.states[41].cn0 = 64; + + test_msg.tracking_state.states[41].fcn = 115; + + test_msg.tracking_state.states[41].sid.code = 124; + + test_msg.tracking_state.states[41].sid.sat = 91; + + test_msg.tracking_state.states[42].cn0 = 178; + + test_msg.tracking_state.states[42].fcn = 115; + + test_msg.tracking_state.states[42].sid.code = 230; + + test_msg.tracking_state.states[42].sid.sat = 28; + + test_msg.tracking_state.states[43].cn0 = 242; + + test_msg.tracking_state.states[43].fcn = 16; + + test_msg.tracking_state.states[43].sid.code = 131; + + test_msg.tracking_state.states[43].sid.sat = 190; + + test_msg.tracking_state.states[44].cn0 = 113; + + test_msg.tracking_state.states[44].fcn = 182; + + test_msg.tracking_state.states[44].sid.code = 59; + + test_msg.tracking_state.states[44].sid.sat = 105; + + test_msg.tracking_state.states[45].cn0 = 179; + + test_msg.tracking_state.states[45].fcn = 48; + + test_msg.tracking_state.states[45].sid.code = 180; + + test_msg.tracking_state.states[45].sid.sat = 192; + + test_msg.tracking_state.states[46].cn0 = 211; + + test_msg.tracking_state.states[46].fcn = 172; + + test_msg.tracking_state.states[46].sid.code = 31; + + test_msg.tracking_state.states[46].sid.sat = 166; + + test_msg.tracking_state.states[47].cn0 = 49; + + test_msg.tracking_state.states[47].fcn = 140; + + test_msg.tracking_state.states[47].sid.code = 228; + + test_msg.tracking_state.states[47].sid.sat = 77; + + test_msg.tracking_state.states[48].cn0 = 194; + + test_msg.tracking_state.states[48].fcn = 240; + + test_msg.tracking_state.states[48].sid.code = 77; + + test_msg.tracking_state.states[48].sid.sat = 128; + + test_msg.tracking_state.states[49].cn0 = 58; + + test_msg.tracking_state.states[49].fcn = 41; + + test_msg.tracking_state.states[49].sid.code = 194; + + test_msg.tracking_state.states[49].sid.sat = 134; + + test_msg.tracking_state.states[50].cn0 = 55; + + test_msg.tracking_state.states[50].fcn = 129; + + test_msg.tracking_state.states[50].sid.code = 53; + + test_msg.tracking_state.states[50].sid.sat = 18; + + test_msg.tracking_state.states[51].cn0 = 92; + + test_msg.tracking_state.states[51].fcn = 134; + + test_msg.tracking_state.states[51].sid.code = 72; + + test_msg.tracking_state.states[51].sid.sat = 91; + + test_msg.tracking_state.states[52].cn0 = 56; + + test_msg.tracking_state.states[52].fcn = 157; + + test_msg.tracking_state.states[52].sid.code = 224; + + test_msg.tracking_state.states[52].sid.sat = 33; + + test_msg.tracking_state.states[53].cn0 = 174; + + test_msg.tracking_state.states[53].fcn = 224; + + test_msg.tracking_state.states[53].sid.code = 54; + + test_msg.tracking_state.states[53].sid.sat = 186; + + test_msg.tracking_state.states[54].cn0 = 190; + + test_msg.tracking_state.states[54].fcn = 148; + + test_msg.tracking_state.states[54].sid.code = 84; + + test_msg.tracking_state.states[54].sid.sat = 82; + + test_msg.tracking_state.states[55].cn0 = 67; + + test_msg.tracking_state.states[55].fcn = 62; + + test_msg.tracking_state.states[55].sid.code = 54; + + test_msg.tracking_state.states[55].sid.sat = 236; + + test_msg.tracking_state.states[56].cn0 = 254; + + test_msg.tracking_state.states[56].fcn = 57; + + test_msg.tracking_state.states[56].sid.code = 215; + + test_msg.tracking_state.states[56].sid.sat = 52; + + test_msg.tracking_state.states[57].cn0 = 174; + + test_msg.tracking_state.states[57].fcn = 36; + + test_msg.tracking_state.states[57].sid.code = 133; + + test_msg.tracking_state.states[57].sid.sat = 16; + + test_msg.tracking_state.states[58].cn0 = 17; + + test_msg.tracking_state.states[58].fcn = 145; + + test_msg.tracking_state.states[58].sid.code = 172; + + test_msg.tracking_state.states[58].sid.sat = 219; + + test_msg.tracking_state.states[59].cn0 = 97; + + test_msg.tracking_state.states[59].fcn = 111; + + test_msg.tracking_state.states[59].sid.code = 179; + + test_msg.tracking_state.states[59].sid.sat = 192; + + test_msg.tracking_state.states[60].cn0 = 134; + + test_msg.tracking_state.states[60].fcn = 208; + + test_msg.tracking_state.states[60].sid.code = 56; + + test_msg.tracking_state.states[60].sid.sat = 207; + + test_msg.tracking_state.states[61].cn0 = 226; + + test_msg.tracking_state.states[61].fcn = 43; + + test_msg.tracking_state.states[61].sid.code = 17; + + test_msg.tracking_state.states[61].sid.sat = 180; + + test_msg.tracking_state.states[62].cn0 = 113; + + test_msg.tracking_state.states[62].fcn = 140; + + test_msg.tracking_state.states[62].sid.code = 182; + + test_msg.tracking_state.states[62].sid.sat = 255; + + sbp_message_send(&sbp_state, SbpMsgTrackingState, 33079, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 33079, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgTrackingState, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.tracking_state.n_states == 63, + "incorrect value for last_msg.msg.tracking_state.n_states, " + "expected 63, is %d", + last_msg.msg.tracking_state.n_states); + + ck_assert_msg( + last_msg.msg.tracking_state.states[0].cn0 == 102, + "incorrect value for last_msg.msg.tracking_state.states[0].cn0, " + "expected 102, is %d", + last_msg.msg.tracking_state.states[0].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[0].fcn == 3, + "incorrect value for last_msg.msg.tracking_state.states[0].fcn, " + "expected 3, is %d", + last_msg.msg.tracking_state.states[0].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[0].sid.code == 184, + "incorrect value for last_msg.msg.tracking_state.states[0].sid.code, " + "expected 184, is %d", + last_msg.msg.tracking_state.states[0].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[0].sid.sat == 117, + "incorrect value for last_msg.msg.tracking_state.states[0].sid.sat, " + "expected 117, is %d", + last_msg.msg.tracking_state.states[0].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[1].cn0 == 141, + "incorrect value for last_msg.msg.tracking_state.states[1].cn0, " + "expected 141, is %d", + last_msg.msg.tracking_state.states[1].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[1].fcn == 140, + "incorrect value for last_msg.msg.tracking_state.states[1].fcn, " + "expected 140, is %d", + last_msg.msg.tracking_state.states[1].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[1].sid.code == 106, + "incorrect value for last_msg.msg.tracking_state.states[1].sid.code, " + "expected 106, is %d", + last_msg.msg.tracking_state.states[1].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[1].sid.sat == 38, + "incorrect value for last_msg.msg.tracking_state.states[1].sid.sat, " + "expected 38, is %d", + last_msg.msg.tracking_state.states[1].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[2].cn0 == 195, + "incorrect value for last_msg.msg.tracking_state.states[2].cn0, " + "expected 195, is %d", + last_msg.msg.tracking_state.states[2].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[2].fcn == 90, + "incorrect value for last_msg.msg.tracking_state.states[2].fcn, " + "expected 90, is %d", + last_msg.msg.tracking_state.states[2].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[2].sid.code == 4, + "incorrect value for last_msg.msg.tracking_state.states[2].sid.code, " + "expected 4, is %d", + last_msg.msg.tracking_state.states[2].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[2].sid.sat == 25, + "incorrect value for last_msg.msg.tracking_state.states[2].sid.sat, " + "expected 25, is %d", + last_msg.msg.tracking_state.states[2].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[3].cn0 == 82, + "incorrect value for last_msg.msg.tracking_state.states[3].cn0, " + "expected 82, is %d", + last_msg.msg.tracking_state.states[3].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[3].fcn == 75, + "incorrect value for last_msg.msg.tracking_state.states[3].fcn, " + "expected 75, is %d", + last_msg.msg.tracking_state.states[3].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[3].sid.code == 108, + "incorrect value for last_msg.msg.tracking_state.states[3].sid.code, " + "expected 108, is %d", + last_msg.msg.tracking_state.states[3].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[3].sid.sat == 246, + "incorrect value for last_msg.msg.tracking_state.states[3].sid.sat, " + "expected 246, is %d", + last_msg.msg.tracking_state.states[3].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[4].cn0 == 163, + "incorrect value for last_msg.msg.tracking_state.states[4].cn0, " + "expected 163, is %d", + last_msg.msg.tracking_state.states[4].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[4].fcn == 45, + "incorrect value for last_msg.msg.tracking_state.states[4].fcn, " + "expected 45, is %d", + last_msg.msg.tracking_state.states[4].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[4].sid.code == 127, + "incorrect value for last_msg.msg.tracking_state.states[4].sid.code, " + "expected 127, is %d", + last_msg.msg.tracking_state.states[4].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[4].sid.sat == 137, + "incorrect value for last_msg.msg.tracking_state.states[4].sid.sat, " + "expected 137, is %d", + last_msg.msg.tracking_state.states[4].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[5].cn0 == 93, + "incorrect value for last_msg.msg.tracking_state.states[5].cn0, " + "expected 93, is %d", + last_msg.msg.tracking_state.states[5].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[5].fcn == 187, + "incorrect value for last_msg.msg.tracking_state.states[5].fcn, " + "expected 187, is %d", + last_msg.msg.tracking_state.states[5].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[5].sid.code == 46, + "incorrect value for last_msg.msg.tracking_state.states[5].sid.code, " + "expected 46, is %d", + last_msg.msg.tracking_state.states[5].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[5].sid.sat == 32, + "incorrect value for last_msg.msg.tracking_state.states[5].sid.sat, " + "expected 32, is %d", + last_msg.msg.tracking_state.states[5].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[6].cn0 == 147, + "incorrect value for last_msg.msg.tracking_state.states[6].cn0, " + "expected 147, is %d", + last_msg.msg.tracking_state.states[6].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[6].fcn == 201, + "incorrect value for last_msg.msg.tracking_state.states[6].fcn, " + "expected 201, is %d", + last_msg.msg.tracking_state.states[6].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[6].sid.code == 60, + "incorrect value for last_msg.msg.tracking_state.states[6].sid.code, " + "expected 60, is %d", + last_msg.msg.tracking_state.states[6].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[6].sid.sat == 153, + "incorrect value for last_msg.msg.tracking_state.states[6].sid.sat, " + "expected 153, is %d", + last_msg.msg.tracking_state.states[6].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[7].cn0 == 208, + "incorrect value for last_msg.msg.tracking_state.states[7].cn0, " + "expected 208, is %d", + last_msg.msg.tracking_state.states[7].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[7].fcn == 5, + "incorrect value for last_msg.msg.tracking_state.states[7].fcn, " + "expected 5, is %d", + last_msg.msg.tracking_state.states[7].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[7].sid.code == 29, + "incorrect value for last_msg.msg.tracking_state.states[7].sid.code, " + "expected 29, is %d", + last_msg.msg.tracking_state.states[7].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[7].sid.sat == 23, + "incorrect value for last_msg.msg.tracking_state.states[7].sid.sat, " + "expected 23, is %d", + last_msg.msg.tracking_state.states[7].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[8].cn0 == 69, + "incorrect value for last_msg.msg.tracking_state.states[8].cn0, " + "expected 69, is %d", + last_msg.msg.tracking_state.states[8].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[8].fcn == 219, + "incorrect value for last_msg.msg.tracking_state.states[8].fcn, " + "expected 219, is %d", + last_msg.msg.tracking_state.states[8].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[8].sid.code == 30, + "incorrect value for last_msg.msg.tracking_state.states[8].sid.code, " + "expected 30, is %d", + last_msg.msg.tracking_state.states[8].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[8].sid.sat == 181, + "incorrect value for last_msg.msg.tracking_state.states[8].sid.sat, " + "expected 181, is %d", + last_msg.msg.tracking_state.states[8].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[9].cn0 == 121, + "incorrect value for last_msg.msg.tracking_state.states[9].cn0, " + "expected 121, is %d", + last_msg.msg.tracking_state.states[9].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[9].fcn == 3, + "incorrect value for last_msg.msg.tracking_state.states[9].fcn, " + "expected 3, is %d", + last_msg.msg.tracking_state.states[9].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[9].sid.code == 136, + "incorrect value for last_msg.msg.tracking_state.states[9].sid.code, " + "expected 136, is %d", + last_msg.msg.tracking_state.states[9].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[9].sid.sat == 254, + "incorrect value for last_msg.msg.tracking_state.states[9].sid.sat, " + "expected 254, is %d", + last_msg.msg.tracking_state.states[9].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[10].cn0 == 215, + "incorrect value for last_msg.msg.tracking_state.states[10].cn0, " + "expected 215, is %d", + last_msg.msg.tracking_state.states[10].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[10].fcn == 144, + "incorrect value for last_msg.msg.tracking_state.states[10].fcn, " + "expected 144, is %d", + last_msg.msg.tracking_state.states[10].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[10].sid.code == 98, + "incorrect value for last_msg.msg.tracking_state.states[10].sid.code, " + "expected 98, is %d", + last_msg.msg.tracking_state.states[10].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[10].sid.sat == 33, + "incorrect value for last_msg.msg.tracking_state.states[10].sid.sat, " + "expected 33, is %d", + last_msg.msg.tracking_state.states[10].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[11].cn0 == 56, + "incorrect value for last_msg.msg.tracking_state.states[11].cn0, " + "expected 56, is %d", + last_msg.msg.tracking_state.states[11].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[11].fcn == 14, + "incorrect value for last_msg.msg.tracking_state.states[11].fcn, " + "expected 14, is %d", + last_msg.msg.tracking_state.states[11].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[11].sid.code == 182, + "incorrect value for last_msg.msg.tracking_state.states[11].sid.code, " + "expected 182, is %d", + last_msg.msg.tracking_state.states[11].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[11].sid.sat == 133, + "incorrect value for last_msg.msg.tracking_state.states[11].sid.sat, " + "expected 133, is %d", + last_msg.msg.tracking_state.states[11].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[12].cn0 == 62, + "incorrect value for last_msg.msg.tracking_state.states[12].cn0, " + "expected 62, is %d", + last_msg.msg.tracking_state.states[12].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[12].fcn == 218, + "incorrect value for last_msg.msg.tracking_state.states[12].fcn, " + "expected 218, is %d", + last_msg.msg.tracking_state.states[12].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[12].sid.code == 77, + "incorrect value for last_msg.msg.tracking_state.states[12].sid.code, " + "expected 77, is %d", + last_msg.msg.tracking_state.states[12].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[12].sid.sat == 169, + "incorrect value for last_msg.msg.tracking_state.states[12].sid.sat, " + "expected 169, is %d", + last_msg.msg.tracking_state.states[12].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[13].cn0 == 249, + "incorrect value for last_msg.msg.tracking_state.states[13].cn0, " + "expected 249, is %d", + last_msg.msg.tracking_state.states[13].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[13].fcn == 171, + "incorrect value for last_msg.msg.tracking_state.states[13].fcn, " + "expected 171, is %d", + last_msg.msg.tracking_state.states[13].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[13].sid.code == 84, + "incorrect value for last_msg.msg.tracking_state.states[13].sid.code, " + "expected 84, is %d", + last_msg.msg.tracking_state.states[13].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[13].sid.sat == 242, + "incorrect value for last_msg.msg.tracking_state.states[13].sid.sat, " + "expected 242, is %d", + last_msg.msg.tracking_state.states[13].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[14].cn0 == 130, + "incorrect value for last_msg.msg.tracking_state.states[14].cn0, " + "expected 130, is %d", + last_msg.msg.tracking_state.states[14].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[14].fcn == 131, + "incorrect value for last_msg.msg.tracking_state.states[14].fcn, " + "expected 131, is %d", + last_msg.msg.tracking_state.states[14].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[14].sid.code == 137, + "incorrect value for last_msg.msg.tracking_state.states[14].sid.code, " + "expected 137, is %d", + last_msg.msg.tracking_state.states[14].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[14].sid.sat == 152, + "incorrect value for last_msg.msg.tracking_state.states[14].sid.sat, " + "expected 152, is %d", + last_msg.msg.tracking_state.states[14].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[15].cn0 == 68, + "incorrect value for last_msg.msg.tracking_state.states[15].cn0, " + "expected 68, is %d", + last_msg.msg.tracking_state.states[15].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[15].fcn == 42, + "incorrect value for last_msg.msg.tracking_state.states[15].fcn, " + "expected 42, is %d", + last_msg.msg.tracking_state.states[15].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[15].sid.code == 21, + "incorrect value for last_msg.msg.tracking_state.states[15].sid.code, " + "expected 21, is %d", + last_msg.msg.tracking_state.states[15].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[15].sid.sat == 193, + "incorrect value for last_msg.msg.tracking_state.states[15].sid.sat, " + "expected 193, is %d", + last_msg.msg.tracking_state.states[15].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[16].cn0 == 227, + "incorrect value for last_msg.msg.tracking_state.states[16].cn0, " + "expected 227, is %d", + last_msg.msg.tracking_state.states[16].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[16].fcn == 216, + "incorrect value for last_msg.msg.tracking_state.states[16].fcn, " + "expected 216, is %d", + last_msg.msg.tracking_state.states[16].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[16].sid.code == 227, + "incorrect value for last_msg.msg.tracking_state.states[16].sid.code, " + "expected 227, is %d", + last_msg.msg.tracking_state.states[16].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[16].sid.sat == 253, + "incorrect value for last_msg.msg.tracking_state.states[16].sid.sat, " + "expected 253, is %d", + last_msg.msg.tracking_state.states[16].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[17].cn0 == 179, + "incorrect value for last_msg.msg.tracking_state.states[17].cn0, " + "expected 179, is %d", + last_msg.msg.tracking_state.states[17].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[17].fcn == 210, + "incorrect value for last_msg.msg.tracking_state.states[17].fcn, " + "expected 210, is %d", + last_msg.msg.tracking_state.states[17].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[17].sid.code == 26, + "incorrect value for last_msg.msg.tracking_state.states[17].sid.code, " + "expected 26, is %d", + last_msg.msg.tracking_state.states[17].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[17].sid.sat == 24, + "incorrect value for last_msg.msg.tracking_state.states[17].sid.sat, " + "expected 24, is %d", + last_msg.msg.tracking_state.states[17].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[18].cn0 == 255, + "incorrect value for last_msg.msg.tracking_state.states[18].cn0, " + "expected 255, is %d", + last_msg.msg.tracking_state.states[18].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[18].fcn == 227, + "incorrect value for last_msg.msg.tracking_state.states[18].fcn, " + "expected 227, is %d", + last_msg.msg.tracking_state.states[18].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[18].sid.code == 15, + "incorrect value for last_msg.msg.tracking_state.states[18].sid.code, " + "expected 15, is %d", + last_msg.msg.tracking_state.states[18].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[18].sid.sat == 19, + "incorrect value for last_msg.msg.tracking_state.states[18].sid.sat, " + "expected 19, is %d", + last_msg.msg.tracking_state.states[18].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[19].cn0 == 200, + "incorrect value for last_msg.msg.tracking_state.states[19].cn0, " + "expected 200, is %d", + last_msg.msg.tracking_state.states[19].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[19].fcn == 187, + "incorrect value for last_msg.msg.tracking_state.states[19].fcn, " + "expected 187, is %d", + last_msg.msg.tracking_state.states[19].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[19].sid.code == 75, + "incorrect value for last_msg.msg.tracking_state.states[19].sid.code, " + "expected 75, is %d", + last_msg.msg.tracking_state.states[19].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[19].sid.sat == 122, + "incorrect value for last_msg.msg.tracking_state.states[19].sid.sat, " + "expected 122, is %d", + last_msg.msg.tracking_state.states[19].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[20].cn0 == 122, + "incorrect value for last_msg.msg.tracking_state.states[20].cn0, " + "expected 122, is %d", + last_msg.msg.tracking_state.states[20].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[20].fcn == 218, + "incorrect value for last_msg.msg.tracking_state.states[20].fcn, " + "expected 218, is %d", + last_msg.msg.tracking_state.states[20].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[20].sid.code == 48, + "incorrect value for last_msg.msg.tracking_state.states[20].sid.code, " + "expected 48, is %d", + last_msg.msg.tracking_state.states[20].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[20].sid.sat == 217, + "incorrect value for last_msg.msg.tracking_state.states[20].sid.sat, " + "expected 217, is %d", + last_msg.msg.tracking_state.states[20].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[21].cn0 == 149, + "incorrect value for last_msg.msg.tracking_state.states[21].cn0, " + "expected 149, is %d", + last_msg.msg.tracking_state.states[21].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[21].fcn == 142, + "incorrect value for last_msg.msg.tracking_state.states[21].fcn, " + "expected 142, is %d", + last_msg.msg.tracking_state.states[21].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[21].sid.code == 238, + "incorrect value for last_msg.msg.tracking_state.states[21].sid.code, " + "expected 238, is %d", + last_msg.msg.tracking_state.states[21].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[21].sid.sat == 187, + "incorrect value for last_msg.msg.tracking_state.states[21].sid.sat, " + "expected 187, is %d", + last_msg.msg.tracking_state.states[21].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[22].cn0 == 212, + "incorrect value for last_msg.msg.tracking_state.states[22].cn0, " + "expected 212, is %d", + last_msg.msg.tracking_state.states[22].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[22].fcn == 251, + "incorrect value for last_msg.msg.tracking_state.states[22].fcn, " + "expected 251, is %d", + last_msg.msg.tracking_state.states[22].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[22].sid.code == 55, + "incorrect value for last_msg.msg.tracking_state.states[22].sid.code, " + "expected 55, is %d", + last_msg.msg.tracking_state.states[22].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[22].sid.sat == 238, + "incorrect value for last_msg.msg.tracking_state.states[22].sid.sat, " + "expected 238, is %d", + last_msg.msg.tracking_state.states[22].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[23].cn0 == 104, + "incorrect value for last_msg.msg.tracking_state.states[23].cn0, " + "expected 104, is %d", + last_msg.msg.tracking_state.states[23].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[23].fcn == 194, + "incorrect value for last_msg.msg.tracking_state.states[23].fcn, " + "expected 194, is %d", + last_msg.msg.tracking_state.states[23].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[23].sid.code == 160, + "incorrect value for last_msg.msg.tracking_state.states[23].sid.code, " + "expected 160, is %d", + last_msg.msg.tracking_state.states[23].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[23].sid.sat == 128, + "incorrect value for last_msg.msg.tracking_state.states[23].sid.sat, " + "expected 128, is %d", + last_msg.msg.tracking_state.states[23].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[24].cn0 == 62, + "incorrect value for last_msg.msg.tracking_state.states[24].cn0, " + "expected 62, is %d", + last_msg.msg.tracking_state.states[24].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[24].fcn == 141, + "incorrect value for last_msg.msg.tracking_state.states[24].fcn, " + "expected 141, is %d", + last_msg.msg.tracking_state.states[24].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[24].sid.code == 255, + "incorrect value for last_msg.msg.tracking_state.states[24].sid.code, " + "expected 255, is %d", + last_msg.msg.tracking_state.states[24].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[24].sid.sat == 113, + "incorrect value for last_msg.msg.tracking_state.states[24].sid.sat, " + "expected 113, is %d", + last_msg.msg.tracking_state.states[24].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[25].cn0 == 39, + "incorrect value for last_msg.msg.tracking_state.states[25].cn0, " + "expected 39, is %d", + last_msg.msg.tracking_state.states[25].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[25].fcn == 245, + "incorrect value for last_msg.msg.tracking_state.states[25].fcn, " + "expected 245, is %d", + last_msg.msg.tracking_state.states[25].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[25].sid.code == 69, + "incorrect value for last_msg.msg.tracking_state.states[25].sid.code, " + "expected 69, is %d", + last_msg.msg.tracking_state.states[25].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[25].sid.sat == 43, + "incorrect value for last_msg.msg.tracking_state.states[25].sid.sat, " + "expected 43, is %d", + last_msg.msg.tracking_state.states[25].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[26].cn0 == 56, + "incorrect value for last_msg.msg.tracking_state.states[26].cn0, " + "expected 56, is %d", + last_msg.msg.tracking_state.states[26].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[26].fcn == 108, + "incorrect value for last_msg.msg.tracking_state.states[26].fcn, " + "expected 108, is %d", + last_msg.msg.tracking_state.states[26].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[26].sid.code == 230, + "incorrect value for last_msg.msg.tracking_state.states[26].sid.code, " + "expected 230, is %d", + last_msg.msg.tracking_state.states[26].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[26].sid.sat == 100, + "incorrect value for last_msg.msg.tracking_state.states[26].sid.sat, " + "expected 100, is %d", + last_msg.msg.tracking_state.states[26].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[27].cn0 == 143, + "incorrect value for last_msg.msg.tracking_state.states[27].cn0, " + "expected 143, is %d", + last_msg.msg.tracking_state.states[27].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[27].fcn == 149, + "incorrect value for last_msg.msg.tracking_state.states[27].fcn, " + "expected 149, is %d", + last_msg.msg.tracking_state.states[27].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[27].sid.code == 68, + "incorrect value for last_msg.msg.tracking_state.states[27].sid.code, " + "expected 68, is %d", + last_msg.msg.tracking_state.states[27].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[27].sid.sat == 247, + "incorrect value for last_msg.msg.tracking_state.states[27].sid.sat, " + "expected 247, is %d", + last_msg.msg.tracking_state.states[27].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[28].cn0 == 70, + "incorrect value for last_msg.msg.tracking_state.states[28].cn0, " + "expected 70, is %d", + last_msg.msg.tracking_state.states[28].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[28].fcn == 233, + "incorrect value for last_msg.msg.tracking_state.states[28].fcn, " + "expected 233, is %d", + last_msg.msg.tracking_state.states[28].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[28].sid.code == 101, + "incorrect value for last_msg.msg.tracking_state.states[28].sid.code, " + "expected 101, is %d", + last_msg.msg.tracking_state.states[28].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[28].sid.sat == 137, + "incorrect value for last_msg.msg.tracking_state.states[28].sid.sat, " + "expected 137, is %d", + last_msg.msg.tracking_state.states[28].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[29].cn0 == 110, + "incorrect value for last_msg.msg.tracking_state.states[29].cn0, " + "expected 110, is %d", + last_msg.msg.tracking_state.states[29].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[29].fcn == 38, + "incorrect value for last_msg.msg.tracking_state.states[29].fcn, " + "expected 38, is %d", + last_msg.msg.tracking_state.states[29].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[29].sid.code == 165, + "incorrect value for last_msg.msg.tracking_state.states[29].sid.code, " + "expected 165, is %d", + last_msg.msg.tracking_state.states[29].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[29].sid.sat == 49, + "incorrect value for last_msg.msg.tracking_state.states[29].sid.sat, " + "expected 49, is %d", + last_msg.msg.tracking_state.states[29].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[30].cn0 == 213, + "incorrect value for last_msg.msg.tracking_state.states[30].cn0, " + "expected 213, is %d", + last_msg.msg.tracking_state.states[30].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[30].fcn == 80, + "incorrect value for last_msg.msg.tracking_state.states[30].fcn, " + "expected 80, is %d", + last_msg.msg.tracking_state.states[30].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[30].sid.code == 230, + "incorrect value for last_msg.msg.tracking_state.states[30].sid.code, " + "expected 230, is %d", + last_msg.msg.tracking_state.states[30].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[30].sid.sat == 218, + "incorrect value for last_msg.msg.tracking_state.states[30].sid.sat, " + "expected 218, is %d", + last_msg.msg.tracking_state.states[30].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[31].cn0 == 128, + "incorrect value for last_msg.msg.tracking_state.states[31].cn0, " + "expected 128, is %d", + last_msg.msg.tracking_state.states[31].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[31].fcn == 139, + "incorrect value for last_msg.msg.tracking_state.states[31].fcn, " + "expected 139, is %d", + last_msg.msg.tracking_state.states[31].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[31].sid.code == 179, + "incorrect value for last_msg.msg.tracking_state.states[31].sid.code, " + "expected 179, is %d", + last_msg.msg.tracking_state.states[31].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[31].sid.sat == 196, + "incorrect value for last_msg.msg.tracking_state.states[31].sid.sat, " + "expected 196, is %d", + last_msg.msg.tracking_state.states[31].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[32].cn0 == 171, + "incorrect value for last_msg.msg.tracking_state.states[32].cn0, " + "expected 171, is %d", + last_msg.msg.tracking_state.states[32].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[32].fcn == 196, + "incorrect value for last_msg.msg.tracking_state.states[32].fcn, " + "expected 196, is %d", + last_msg.msg.tracking_state.states[32].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[32].sid.code == 178, + "incorrect value for last_msg.msg.tracking_state.states[32].sid.code, " + "expected 178, is %d", + last_msg.msg.tracking_state.states[32].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[32].sid.sat == 15, + "incorrect value for last_msg.msg.tracking_state.states[32].sid.sat, " + "expected 15, is %d", + last_msg.msg.tracking_state.states[32].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[33].cn0 == 194, + "incorrect value for last_msg.msg.tracking_state.states[33].cn0, " + "expected 194, is %d", + last_msg.msg.tracking_state.states[33].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[33].fcn == 97, + "incorrect value for last_msg.msg.tracking_state.states[33].fcn, " + "expected 97, is %d", + last_msg.msg.tracking_state.states[33].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[33].sid.code == 212, + "incorrect value for last_msg.msg.tracking_state.states[33].sid.code, " + "expected 212, is %d", + last_msg.msg.tracking_state.states[33].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[33].sid.sat == 8, + "incorrect value for last_msg.msg.tracking_state.states[33].sid.sat, " + "expected 8, is %d", + last_msg.msg.tracking_state.states[33].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[34].cn0 == 99, + "incorrect value for last_msg.msg.tracking_state.states[34].cn0, " + "expected 99, is %d", + last_msg.msg.tracking_state.states[34].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[34].fcn == 79, + "incorrect value for last_msg.msg.tracking_state.states[34].fcn, " + "expected 79, is %d", + last_msg.msg.tracking_state.states[34].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[34].sid.code == 233, + "incorrect value for last_msg.msg.tracking_state.states[34].sid.code, " + "expected 233, is %d", + last_msg.msg.tracking_state.states[34].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[34].sid.sat == 83, + "incorrect value for last_msg.msg.tracking_state.states[34].sid.sat, " + "expected 83, is %d", + last_msg.msg.tracking_state.states[34].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[35].cn0 == 180, + "incorrect value for last_msg.msg.tracking_state.states[35].cn0, " + "expected 180, is %d", + last_msg.msg.tracking_state.states[35].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[35].fcn == 31, + "incorrect value for last_msg.msg.tracking_state.states[35].fcn, " + "expected 31, is %d", + last_msg.msg.tracking_state.states[35].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[35].sid.code == 90, + "incorrect value for last_msg.msg.tracking_state.states[35].sid.code, " + "expected 90, is %d", + last_msg.msg.tracking_state.states[35].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[35].sid.sat == 55, + "incorrect value for last_msg.msg.tracking_state.states[35].sid.sat, " + "expected 55, is %d", + last_msg.msg.tracking_state.states[35].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[36].cn0 == 186, + "incorrect value for last_msg.msg.tracking_state.states[36].cn0, " + "expected 186, is %d", + last_msg.msg.tracking_state.states[36].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[36].fcn == 105, + "incorrect value for last_msg.msg.tracking_state.states[36].fcn, " + "expected 105, is %d", + last_msg.msg.tracking_state.states[36].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[36].sid.code == 25, + "incorrect value for last_msg.msg.tracking_state.states[36].sid.code, " + "expected 25, is %d", + last_msg.msg.tracking_state.states[36].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[36].sid.sat == 5, + "incorrect value for last_msg.msg.tracking_state.states[36].sid.sat, " + "expected 5, is %d", + last_msg.msg.tracking_state.states[36].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[37].cn0 == 111, + "incorrect value for last_msg.msg.tracking_state.states[37].cn0, " + "expected 111, is %d", + last_msg.msg.tracking_state.states[37].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[37].fcn == 80, + "incorrect value for last_msg.msg.tracking_state.states[37].fcn, " + "expected 80, is %d", + last_msg.msg.tracking_state.states[37].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[37].sid.code == 224, + "incorrect value for last_msg.msg.tracking_state.states[37].sid.code, " + "expected 224, is %d", + last_msg.msg.tracking_state.states[37].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[37].sid.sat == 22, + "incorrect value for last_msg.msg.tracking_state.states[37].sid.sat, " + "expected 22, is %d", + last_msg.msg.tracking_state.states[37].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[38].cn0 == 166, + "incorrect value for last_msg.msg.tracking_state.states[38].cn0, " + "expected 166, is %d", + last_msg.msg.tracking_state.states[38].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[38].fcn == 106, + "incorrect value for last_msg.msg.tracking_state.states[38].fcn, " + "expected 106, is %d", + last_msg.msg.tracking_state.states[38].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[38].sid.code == 48, + "incorrect value for last_msg.msg.tracking_state.states[38].sid.code, " + "expected 48, is %d", + last_msg.msg.tracking_state.states[38].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[38].sid.sat == 8, + "incorrect value for last_msg.msg.tracking_state.states[38].sid.sat, " + "expected 8, is %d", + last_msg.msg.tracking_state.states[38].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[39].cn0 == 49, + "incorrect value for last_msg.msg.tracking_state.states[39].cn0, " + "expected 49, is %d", + last_msg.msg.tracking_state.states[39].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[39].fcn == 156, + "incorrect value for last_msg.msg.tracking_state.states[39].fcn, " + "expected 156, is %d", + last_msg.msg.tracking_state.states[39].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[39].sid.code == 48, + "incorrect value for last_msg.msg.tracking_state.states[39].sid.code, " + "expected 48, is %d", + last_msg.msg.tracking_state.states[39].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[39].sid.sat == 4, + "incorrect value for last_msg.msg.tracking_state.states[39].sid.sat, " + "expected 4, is %d", + last_msg.msg.tracking_state.states[39].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[40].cn0 == 146, + "incorrect value for last_msg.msg.tracking_state.states[40].cn0, " + "expected 146, is %d", + last_msg.msg.tracking_state.states[40].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[40].fcn == 142, + "incorrect value for last_msg.msg.tracking_state.states[40].fcn, " + "expected 142, is %d", + last_msg.msg.tracking_state.states[40].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[40].sid.code == 19, + "incorrect value for last_msg.msg.tracking_state.states[40].sid.code, " + "expected 19, is %d", + last_msg.msg.tracking_state.states[40].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[40].sid.sat == 86, + "incorrect value for last_msg.msg.tracking_state.states[40].sid.sat, " + "expected 86, is %d", + last_msg.msg.tracking_state.states[40].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[41].cn0 == 64, + "incorrect value for last_msg.msg.tracking_state.states[41].cn0, " + "expected 64, is %d", + last_msg.msg.tracking_state.states[41].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[41].fcn == 115, + "incorrect value for last_msg.msg.tracking_state.states[41].fcn, " + "expected 115, is %d", + last_msg.msg.tracking_state.states[41].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[41].sid.code == 124, + "incorrect value for last_msg.msg.tracking_state.states[41].sid.code, " + "expected 124, is %d", + last_msg.msg.tracking_state.states[41].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[41].sid.sat == 91, + "incorrect value for last_msg.msg.tracking_state.states[41].sid.sat, " + "expected 91, is %d", + last_msg.msg.tracking_state.states[41].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[42].cn0 == 178, + "incorrect value for last_msg.msg.tracking_state.states[42].cn0, " + "expected 178, is %d", + last_msg.msg.tracking_state.states[42].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[42].fcn == 115, + "incorrect value for last_msg.msg.tracking_state.states[42].fcn, " + "expected 115, is %d", + last_msg.msg.tracking_state.states[42].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[42].sid.code == 230, + "incorrect value for last_msg.msg.tracking_state.states[42].sid.code, " + "expected 230, is %d", + last_msg.msg.tracking_state.states[42].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[42].sid.sat == 28, + "incorrect value for last_msg.msg.tracking_state.states[42].sid.sat, " + "expected 28, is %d", + last_msg.msg.tracking_state.states[42].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[43].cn0 == 242, + "incorrect value for last_msg.msg.tracking_state.states[43].cn0, " + "expected 242, is %d", + last_msg.msg.tracking_state.states[43].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[43].fcn == 16, + "incorrect value for last_msg.msg.tracking_state.states[43].fcn, " + "expected 16, is %d", + last_msg.msg.tracking_state.states[43].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[43].sid.code == 131, + "incorrect value for last_msg.msg.tracking_state.states[43].sid.code, " + "expected 131, is %d", + last_msg.msg.tracking_state.states[43].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[43].sid.sat == 190, + "incorrect value for last_msg.msg.tracking_state.states[43].sid.sat, " + "expected 190, is %d", + last_msg.msg.tracking_state.states[43].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[44].cn0 == 113, + "incorrect value for last_msg.msg.tracking_state.states[44].cn0, " + "expected 113, is %d", + last_msg.msg.tracking_state.states[44].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[44].fcn == 182, + "incorrect value for last_msg.msg.tracking_state.states[44].fcn, " + "expected 182, is %d", + last_msg.msg.tracking_state.states[44].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[44].sid.code == 59, + "incorrect value for last_msg.msg.tracking_state.states[44].sid.code, " + "expected 59, is %d", + last_msg.msg.tracking_state.states[44].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[44].sid.sat == 105, + "incorrect value for last_msg.msg.tracking_state.states[44].sid.sat, " + "expected 105, is %d", + last_msg.msg.tracking_state.states[44].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[45].cn0 == 179, + "incorrect value for last_msg.msg.tracking_state.states[45].cn0, " + "expected 179, is %d", + last_msg.msg.tracking_state.states[45].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[45].fcn == 48, + "incorrect value for last_msg.msg.tracking_state.states[45].fcn, " + "expected 48, is %d", + last_msg.msg.tracking_state.states[45].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[45].sid.code == 180, + "incorrect value for last_msg.msg.tracking_state.states[45].sid.code, " + "expected 180, is %d", + last_msg.msg.tracking_state.states[45].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[45].sid.sat == 192, + "incorrect value for last_msg.msg.tracking_state.states[45].sid.sat, " + "expected 192, is %d", + last_msg.msg.tracking_state.states[45].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[46].cn0 == 211, + "incorrect value for last_msg.msg.tracking_state.states[46].cn0, " + "expected 211, is %d", + last_msg.msg.tracking_state.states[46].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[46].fcn == 172, + "incorrect value for last_msg.msg.tracking_state.states[46].fcn, " + "expected 172, is %d", + last_msg.msg.tracking_state.states[46].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[46].sid.code == 31, + "incorrect value for last_msg.msg.tracking_state.states[46].sid.code, " + "expected 31, is %d", + last_msg.msg.tracking_state.states[46].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[46].sid.sat == 166, + "incorrect value for last_msg.msg.tracking_state.states[46].sid.sat, " + "expected 166, is %d", + last_msg.msg.tracking_state.states[46].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[47].cn0 == 49, + "incorrect value for last_msg.msg.tracking_state.states[47].cn0, " + "expected 49, is %d", + last_msg.msg.tracking_state.states[47].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[47].fcn == 140, + "incorrect value for last_msg.msg.tracking_state.states[47].fcn, " + "expected 140, is %d", + last_msg.msg.tracking_state.states[47].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[47].sid.code == 228, + "incorrect value for last_msg.msg.tracking_state.states[47].sid.code, " + "expected 228, is %d", + last_msg.msg.tracking_state.states[47].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[47].sid.sat == 77, + "incorrect value for last_msg.msg.tracking_state.states[47].sid.sat, " + "expected 77, is %d", + last_msg.msg.tracking_state.states[47].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[48].cn0 == 194, + "incorrect value for last_msg.msg.tracking_state.states[48].cn0, " + "expected 194, is %d", + last_msg.msg.tracking_state.states[48].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[48].fcn == 240, + "incorrect value for last_msg.msg.tracking_state.states[48].fcn, " + "expected 240, is %d", + last_msg.msg.tracking_state.states[48].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[48].sid.code == 77, + "incorrect value for last_msg.msg.tracking_state.states[48].sid.code, " + "expected 77, is %d", + last_msg.msg.tracking_state.states[48].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[48].sid.sat == 128, + "incorrect value for last_msg.msg.tracking_state.states[48].sid.sat, " + "expected 128, is %d", + last_msg.msg.tracking_state.states[48].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[49].cn0 == 58, + "incorrect value for last_msg.msg.tracking_state.states[49].cn0, " + "expected 58, is %d", + last_msg.msg.tracking_state.states[49].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[49].fcn == 41, + "incorrect value for last_msg.msg.tracking_state.states[49].fcn, " + "expected 41, is %d", + last_msg.msg.tracking_state.states[49].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[49].sid.code == 194, + "incorrect value for last_msg.msg.tracking_state.states[49].sid.code, " + "expected 194, is %d", + last_msg.msg.tracking_state.states[49].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[49].sid.sat == 134, + "incorrect value for last_msg.msg.tracking_state.states[49].sid.sat, " + "expected 134, is %d", + last_msg.msg.tracking_state.states[49].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[50].cn0 == 55, + "incorrect value for last_msg.msg.tracking_state.states[50].cn0, " + "expected 55, is %d", + last_msg.msg.tracking_state.states[50].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[50].fcn == 129, + "incorrect value for last_msg.msg.tracking_state.states[50].fcn, " + "expected 129, is %d", + last_msg.msg.tracking_state.states[50].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[50].sid.code == 53, + "incorrect value for last_msg.msg.tracking_state.states[50].sid.code, " + "expected 53, is %d", + last_msg.msg.tracking_state.states[50].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[50].sid.sat == 18, + "incorrect value for last_msg.msg.tracking_state.states[50].sid.sat, " + "expected 18, is %d", + last_msg.msg.tracking_state.states[50].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[51].cn0 == 92, + "incorrect value for last_msg.msg.tracking_state.states[51].cn0, " + "expected 92, is %d", + last_msg.msg.tracking_state.states[51].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[51].fcn == 134, + "incorrect value for last_msg.msg.tracking_state.states[51].fcn, " + "expected 134, is %d", + last_msg.msg.tracking_state.states[51].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[51].sid.code == 72, + "incorrect value for last_msg.msg.tracking_state.states[51].sid.code, " + "expected 72, is %d", + last_msg.msg.tracking_state.states[51].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[51].sid.sat == 91, + "incorrect value for last_msg.msg.tracking_state.states[51].sid.sat, " + "expected 91, is %d", + last_msg.msg.tracking_state.states[51].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[52].cn0 == 56, + "incorrect value for last_msg.msg.tracking_state.states[52].cn0, " + "expected 56, is %d", + last_msg.msg.tracking_state.states[52].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[52].fcn == 157, + "incorrect value for last_msg.msg.tracking_state.states[52].fcn, " + "expected 157, is %d", + last_msg.msg.tracking_state.states[52].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[52].sid.code == 224, + "incorrect value for last_msg.msg.tracking_state.states[52].sid.code, " + "expected 224, is %d", + last_msg.msg.tracking_state.states[52].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[52].sid.sat == 33, + "incorrect value for last_msg.msg.tracking_state.states[52].sid.sat, " + "expected 33, is %d", + last_msg.msg.tracking_state.states[52].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[53].cn0 == 174, + "incorrect value for last_msg.msg.tracking_state.states[53].cn0, " + "expected 174, is %d", + last_msg.msg.tracking_state.states[53].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[53].fcn == 224, + "incorrect value for last_msg.msg.tracking_state.states[53].fcn, " + "expected 224, is %d", + last_msg.msg.tracking_state.states[53].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[53].sid.code == 54, + "incorrect value for last_msg.msg.tracking_state.states[53].sid.code, " + "expected 54, is %d", + last_msg.msg.tracking_state.states[53].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[53].sid.sat == 186, + "incorrect value for last_msg.msg.tracking_state.states[53].sid.sat, " + "expected 186, is %d", + last_msg.msg.tracking_state.states[53].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[54].cn0 == 190, + "incorrect value for last_msg.msg.tracking_state.states[54].cn0, " + "expected 190, is %d", + last_msg.msg.tracking_state.states[54].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[54].fcn == 148, + "incorrect value for last_msg.msg.tracking_state.states[54].fcn, " + "expected 148, is %d", + last_msg.msg.tracking_state.states[54].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[54].sid.code == 84, + "incorrect value for last_msg.msg.tracking_state.states[54].sid.code, " + "expected 84, is %d", + last_msg.msg.tracking_state.states[54].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[54].sid.sat == 82, + "incorrect value for last_msg.msg.tracking_state.states[54].sid.sat, " + "expected 82, is %d", + last_msg.msg.tracking_state.states[54].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[55].cn0 == 67, + "incorrect value for last_msg.msg.tracking_state.states[55].cn0, " + "expected 67, is %d", + last_msg.msg.tracking_state.states[55].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[55].fcn == 62, + "incorrect value for last_msg.msg.tracking_state.states[55].fcn, " + "expected 62, is %d", + last_msg.msg.tracking_state.states[55].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[55].sid.code == 54, + "incorrect value for last_msg.msg.tracking_state.states[55].sid.code, " + "expected 54, is %d", + last_msg.msg.tracking_state.states[55].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[55].sid.sat == 236, + "incorrect value for last_msg.msg.tracking_state.states[55].sid.sat, " + "expected 236, is %d", + last_msg.msg.tracking_state.states[55].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[56].cn0 == 254, + "incorrect value for last_msg.msg.tracking_state.states[56].cn0, " + "expected 254, is %d", + last_msg.msg.tracking_state.states[56].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[56].fcn == 57, + "incorrect value for last_msg.msg.tracking_state.states[56].fcn, " + "expected 57, is %d", + last_msg.msg.tracking_state.states[56].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[56].sid.code == 215, + "incorrect value for last_msg.msg.tracking_state.states[56].sid.code, " + "expected 215, is %d", + last_msg.msg.tracking_state.states[56].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[56].sid.sat == 52, + "incorrect value for last_msg.msg.tracking_state.states[56].sid.sat, " + "expected 52, is %d", + last_msg.msg.tracking_state.states[56].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[57].cn0 == 174, + "incorrect value for last_msg.msg.tracking_state.states[57].cn0, " + "expected 174, is %d", + last_msg.msg.tracking_state.states[57].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[57].fcn == 36, + "incorrect value for last_msg.msg.tracking_state.states[57].fcn, " + "expected 36, is %d", + last_msg.msg.tracking_state.states[57].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[57].sid.code == 133, + "incorrect value for last_msg.msg.tracking_state.states[57].sid.code, " + "expected 133, is %d", + last_msg.msg.tracking_state.states[57].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[57].sid.sat == 16, + "incorrect value for last_msg.msg.tracking_state.states[57].sid.sat, " + "expected 16, is %d", + last_msg.msg.tracking_state.states[57].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[58].cn0 == 17, + "incorrect value for last_msg.msg.tracking_state.states[58].cn0, " + "expected 17, is %d", + last_msg.msg.tracking_state.states[58].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[58].fcn == 145, + "incorrect value for last_msg.msg.tracking_state.states[58].fcn, " + "expected 145, is %d", + last_msg.msg.tracking_state.states[58].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[58].sid.code == 172, + "incorrect value for last_msg.msg.tracking_state.states[58].sid.code, " + "expected 172, is %d", + last_msg.msg.tracking_state.states[58].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[58].sid.sat == 219, + "incorrect value for last_msg.msg.tracking_state.states[58].sid.sat, " + "expected 219, is %d", + last_msg.msg.tracking_state.states[58].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[59].cn0 == 97, + "incorrect value for last_msg.msg.tracking_state.states[59].cn0, " + "expected 97, is %d", + last_msg.msg.tracking_state.states[59].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[59].fcn == 111, + "incorrect value for last_msg.msg.tracking_state.states[59].fcn, " + "expected 111, is %d", + last_msg.msg.tracking_state.states[59].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[59].sid.code == 179, + "incorrect value for last_msg.msg.tracking_state.states[59].sid.code, " + "expected 179, is %d", + last_msg.msg.tracking_state.states[59].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[59].sid.sat == 192, + "incorrect value for last_msg.msg.tracking_state.states[59].sid.sat, " + "expected 192, is %d", + last_msg.msg.tracking_state.states[59].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[60].cn0 == 134, + "incorrect value for last_msg.msg.tracking_state.states[60].cn0, " + "expected 134, is %d", + last_msg.msg.tracking_state.states[60].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[60].fcn == 208, + "incorrect value for last_msg.msg.tracking_state.states[60].fcn, " + "expected 208, is %d", + last_msg.msg.tracking_state.states[60].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[60].sid.code == 56, + "incorrect value for last_msg.msg.tracking_state.states[60].sid.code, " + "expected 56, is %d", + last_msg.msg.tracking_state.states[60].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[60].sid.sat == 207, + "incorrect value for last_msg.msg.tracking_state.states[60].sid.sat, " + "expected 207, is %d", + last_msg.msg.tracking_state.states[60].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[61].cn0 == 226, + "incorrect value for last_msg.msg.tracking_state.states[61].cn0, " + "expected 226, is %d", + last_msg.msg.tracking_state.states[61].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[61].fcn == 43, + "incorrect value for last_msg.msg.tracking_state.states[61].fcn, " + "expected 43, is %d", + last_msg.msg.tracking_state.states[61].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[61].sid.code == 17, + "incorrect value for last_msg.msg.tracking_state.states[61].sid.code, " + "expected 17, is %d", + last_msg.msg.tracking_state.states[61].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[61].sid.sat == 180, + "incorrect value for last_msg.msg.tracking_state.states[61].sid.sat, " + "expected 180, is %d", + last_msg.msg.tracking_state.states[61].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state.states[62].cn0 == 113, + "incorrect value for last_msg.msg.tracking_state.states[62].cn0, " + "expected 113, is %d", + last_msg.msg.tracking_state.states[62].cn0); + + ck_assert_msg( + last_msg.msg.tracking_state.states[62].fcn == 140, + "incorrect value for last_msg.msg.tracking_state.states[62].fcn, " + "expected 140, is %d", + last_msg.msg.tracking_state.states[62].fcn); + + ck_assert_msg( + last_msg.msg.tracking_state.states[62].sid.code == 182, + "incorrect value for last_msg.msg.tracking_state.states[62].sid.code, " + "expected 182, is %d", + last_msg.msg.tracking_state.states[62].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state.states[62].sid.sat == 255, + "incorrect value for last_msg.msg.tracking_state.states[62].sid.sat, " + "expected 255, is %d", + last_msg.msg.tracking_state.states[62].sid.sat); + } + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + sbp_callback_register(&sbp_state, 0x13, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingStateDepB.c b/c/test/auto_check_sbp_tracking_MsgTrackingStateDepB.c new file mode 100644 index 0000000000..0b62c6f6be --- /dev/null +++ b/c/test/auto_check_sbp_tracking_MsgTrackingStateDepB.c @@ -0,0 +1,1342 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_tracking_MsgTrackingStateDepB) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x13, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, + 69, 255, 175, 121, 43, 222, 51, 67, 35, 69, 78, 240, 5, 53, + 20, 51, 211, 54, 69, 153, 130, 237, 66, 155, 51, 227, 71, 69, + 53, 242, 136, 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, + 154, 217, 184, 69, 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, + 115, 141, 27, 12, 154, 225, 200, 69, 208, 44, 147, 39, 23, 51, + 3, 66, 69, 237, 159, 251, 49, 203, 51, 99, 102, 69, 70, 214, + 87, 128, 206, 154, 121, 186, 69, 14, 206, 111, 218, 19, 154, 121, + 169, 69, 216, 98, 209, 54, 2, 154, 25, 219, 67, 200, 133, 99, + 7, 34, 102, 198, 232, 68, 155, 43, 85, 135, 46, 154, 177, 170, + 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, 121, 43, 197, 16, + 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, 115, 66, 69, + 36, 20, 61, 153, 51, 154, 73, 134, 69, 46, 82, 116, 140, 22, + 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, 76, 107, 68, 220, + 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, + 135, 186, 171, 51, 163, 4, 69, 18, 124, 155, 85, 170, 205, 208, + 13, 70, 57, 244, 206, 255, 186, 154, 105, 149, 69, 165, 199, 93, + 181, 175, 51, 67, 64, 69, 6, 28, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_state_dep_b.n_states = 28; + + test_msg.tracking_state_dep_b.states[0].cn0 = 5856.2001953125; + + test_msg.tracking_state_dep_b.states[0].sid.code = 63; + + test_msg.tracking_state_dep_b.states[0].sid.reserved = 68; + + test_msg.tracking_state_dep_b.states[0].sid.sat = 58295; + + test_msg.tracking_state_dep_b.states[0].state = 115; + + test_msg.tracking_state_dep_b.states[1].cn0 = 2612.199951171875; + + test_msg.tracking_state_dep_b.states[1].sid.code = 43; + + test_msg.tracking_state_dep_b.states[1].sid.reserved = 222; + + test_msg.tracking_state_dep_b.states[1].sid.sat = 31151; + + test_msg.tracking_state_dep_b.states[1].state = 255; + + test_msg.tracking_state_dep_b.states[2].cn0 = 2925.199951171875; + + test_msg.tracking_state_dep_b.states[2].sid.code = 53; + + test_msg.tracking_state_dep_b.states[2].sid.reserved = 20; + + test_msg.tracking_state_dep_b.states[2].sid.sat = 1520; + + test_msg.tracking_state_dep_b.states[2].state = 78; + + test_msg.tracking_state_dep_b.states[3].cn0 = 3198.199951171875; + + test_msg.tracking_state_dep_b.states[3].sid.code = 66; + + test_msg.tracking_state_dep_b.states[3].sid.reserved = 155; + + test_msg.tracking_state_dep_b.states[3].sid.sat = 60802; + + test_msg.tracking_state_dep_b.states[3].state = 153; + + test_msg.tracking_state_dep_b.states[4].cn0 = 8623.2001953125; + + test_msg.tracking_state_dep_b.states[4].sid.code = 161; + + test_msg.tracking_state_dep_b.states[4].sid.reserved = 190; + + test_msg.tracking_state_dep_b.states[4].sid.sat = 35058; + + test_msg.tracking_state_dep_b.states[4].state = 53; + + test_msg.tracking_state_dep_b.states[5].cn0 = 5915.2001953125; + + test_msg.tracking_state_dep_b.states[5].sid.code = 142; + + test_msg.tracking_state_dep_b.states[5].sid.reserved = 149; + + test_msg.tracking_state_dep_b.states[5].sid.sat = 65405; + + test_msg.tracking_state_dep_b.states[5].state = 153; + + test_msg.tracking_state_dep_b.states[6].cn0 = 5412.2001953125; + + test_msg.tracking_state_dep_b.states[6].sid.code = 31; + + test_msg.tracking_state_dep_b.states[6].sid.reserved = 76; + + test_msg.tracking_state_dep_b.states[6].sid.sat = 24422; + + test_msg.tracking_state_dep_b.states[6].state = 248; + + test_msg.tracking_state_dep_b.states[7].cn0 = 6428.2001953125; + + test_msg.tracking_state_dep_b.states[7].sid.code = 27; + + test_msg.tracking_state_dep_b.states[7].sid.reserved = 12; + + test_msg.tracking_state_dep_b.states[7].sid.sat = 36211; + + test_msg.tracking_state_dep_b.states[7].state = 131; + + test_msg.tracking_state_dep_b.states[8].cn0 = 3104.199951171875; + + test_msg.tracking_state_dep_b.states[8].sid.code = 39; + + test_msg.tracking_state_dep_b.states[8].sid.reserved = 23; + + test_msg.tracking_state_dep_b.states[8].sid.sat = 37676; + + test_msg.tracking_state_dep_b.states[8].state = 208; + + test_msg.tracking_state_dep_b.states[9].cn0 = 3686.199951171875; + + test_msg.tracking_state_dep_b.states[9].sid.code = 49; + + test_msg.tracking_state_dep_b.states[9].sid.reserved = 203; + + test_msg.tracking_state_dep_b.states[9].sid.sat = 64415; + + test_msg.tracking_state_dep_b.states[9].state = 237; + + test_msg.tracking_state_dep_b.states[10].cn0 = 5967.2001953125; + + test_msg.tracking_state_dep_b.states[10].sid.code = 128; + + test_msg.tracking_state_dep_b.states[10].sid.reserved = 206; + + test_msg.tracking_state_dep_b.states[10].sid.sat = 22486; + + test_msg.tracking_state_dep_b.states[10].state = 70; + + test_msg.tracking_state_dep_b.states[11].cn0 = 5423.2001953125; + + test_msg.tracking_state_dep_b.states[11].sid.code = 218; + + test_msg.tracking_state_dep_b.states[11].sid.reserved = 19; + + test_msg.tracking_state_dep_b.states[11].sid.sat = 28622; + + test_msg.tracking_state_dep_b.states[11].state = 14; + + test_msg.tracking_state_dep_b.states[12].cn0 = 438.20001220703125; + + test_msg.tracking_state_dep_b.states[12].sid.code = 54; + + test_msg.tracking_state_dep_b.states[12].sid.reserved = 2; + + test_msg.tracking_state_dep_b.states[12].sid.sat = 53602; + + test_msg.tracking_state_dep_b.states[12].state = 216; + + test_msg.tracking_state_dep_b.states[13].cn0 = 1862.199951171875; + + test_msg.tracking_state_dep_b.states[13].sid.code = 7; + + test_msg.tracking_state_dep_b.states[13].sid.reserved = 34; + + test_msg.tracking_state_dep_b.states[13].sid.sat = 25477; + + test_msg.tracking_state_dep_b.states[13].state = 200; + + test_msg.tracking_state_dep_b.states[14].cn0 = 5462.2001953125; + + test_msg.tracking_state_dep_b.states[14].sid.code = 135; + + test_msg.tracking_state_dep_b.states[14].sid.reserved = 46; + + test_msg.tracking_state_dep_b.states[14].sid.sat = 21803; + + test_msg.tracking_state_dep_b.states[14].state = 155; + + test_msg.tracking_state_dep_b.states[15].cn0 = 7454.2001953125; + + test_msg.tracking_state_dep_b.states[15].sid.code = 171; + + test_msg.tracking_state_dep_b.states[15].sid.reserved = 201; + + test_msg.tracking_state_dep_b.states[15].sid.sat = 21251; + + test_msg.tracking_state_dep_b.states[15].state = 155; + + test_msg.tracking_state_dep_b.states[16].cn0 = 7134.2001953125; + + test_msg.tracking_state_dep_b.states[16].sid.code = 16; + + test_msg.tracking_state_dep_b.states[16].sid.reserved = 19; + + test_msg.tracking_state_dep_b.states[16].sid.sat = 50475; + + test_msg.tracking_state_dep_b.states[16].state = 121; + + test_msg.tracking_state_dep_b.states[17].cn0 = 3111.199951171875; + + test_msg.tracking_state_dep_b.states[17].sid.code = 63; + + test_msg.tracking_state_dep_b.states[17].sid.reserved = 176; + + test_msg.tracking_state_dep_b.states[17].sid.sat = 13813; + + test_msg.tracking_state_dep_b.states[17].state = 128; + + test_msg.tracking_state_dep_b.states[18].cn0 = 4297.2001953125; + + test_msg.tracking_state_dep_b.states[18].sid.code = 153; + + test_msg.tracking_state_dep_b.states[18].sid.reserved = 51; + + test_msg.tracking_state_dep_b.states[18].sid.sat = 15636; + + test_msg.tracking_state_dep_b.states[18].state = 36; + + test_msg.tracking_state_dep_b.states[19].cn0 = 2649.199951171875; + + test_msg.tracking_state_dep_b.states[19].sid.code = 140; + + test_msg.tracking_state_dep_b.states[19].sid.reserved = 22; + + test_msg.tracking_state_dep_b.states[19].sid.sat = 29778; + + test_msg.tracking_state_dep_b.states[19].state = 46; + + test_msg.tracking_state_dep_b.states[20].cn0 = 941.2000122070312; + + test_msg.tracking_state_dep_b.states[20].sid.code = 96; + + test_msg.tracking_state_dep_b.states[20].sid.reserved = 143; + + test_msg.tracking_state_dep_b.states[20].sid.sat = 37443; + + test_msg.tracking_state_dep_b.states[20].state = 177; + + test_msg.tracking_state_dep_b.states[21].cn0 = 1539.199951171875; + + test_msg.tracking_state_dep_b.states[21].sid.code = 201; + + test_msg.tracking_state_dep_b.states[21].sid.reserved = 251; + + test_msg.tracking_state_dep_b.states[21].sid.sat = 41011; + + test_msg.tracking_state_dep_b.states[21].state = 220; + + test_msg.tracking_state_dep_b.states[22].cn0 = 1443.199951171875; + + test_msg.tracking_state_dep_b.states[22].sid.code = 161; + + test_msg.tracking_state_dep_b.states[22].sid.reserved = 220; + + test_msg.tracking_state_dep_b.states[22].sid.sat = 706; + + test_msg.tracking_state_dep_b.states[22].state = 168; + + test_msg.tracking_state_dep_b.states[23].cn0 = 1074.199951171875; + + test_msg.tracking_state_dep_b.states[23].sid.code = 125; + + test_msg.tracking_state_dep_b.states[23].sid.reserved = 178; + + test_msg.tracking_state_dep_b.states[23].sid.sat = 2312; + + test_msg.tracking_state_dep_b.states[23].state = 69; + + test_msg.tracking_state_dep_b.states[24].cn0 = 2122.199951171875; + + test_msg.tracking_state_dep_b.states[24].sid.code = 186; + + test_msg.tracking_state_dep_b.states[24].sid.reserved = 171; + + test_msg.tracking_state_dep_b.states[24].sid.sat = 34580; + + test_msg.tracking_state_dep_b.states[24].state = 185; + + test_msg.tracking_state_dep_b.states[25].cn0 = 9076.2001953125; + + test_msg.tracking_state_dep_b.states[25].sid.code = 85; + + test_msg.tracking_state_dep_b.states[25].sid.reserved = 170; + + test_msg.tracking_state_dep_b.states[25].sid.sat = 39804; + + test_msg.tracking_state_dep_b.states[25].state = 18; + + test_msg.tracking_state_dep_b.states[26].cn0 = 4781.2001953125; + + test_msg.tracking_state_dep_b.states[26].sid.code = 255; + + test_msg.tracking_state_dep_b.states[26].sid.reserved = 186; + + test_msg.tracking_state_dep_b.states[26].sid.sat = 52980; + + test_msg.tracking_state_dep_b.states[26].state = 57; + + test_msg.tracking_state_dep_b.states[27].cn0 = 3076.199951171875; + + test_msg.tracking_state_dep_b.states[27].sid.code = 181; + + test_msg.tracking_state_dep_b.states[27].sid.reserved = 175; + + test_msg.tracking_state_dep_b.states[27].sid.sat = 24007; + + test_msg.tracking_state_dep_b.states[27].state = 165; + + sbp_message_send(&sbp_state, SbpMsgTrackingStateDepB, 61938, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61938, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgTrackingStateDepB, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.n_states == 28, + "incorrect value for last_msg.msg.tracking_state_dep_b.n_states, " + "expected 28, is %d", + last_msg.msg.tracking_state_dep_b.n_states); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[0].cn0 * 100 - + 5856.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[0].cn0, " + "expected 5856.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[0].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[0].sid.code == 63, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[0].sid.code, " + "expected 63, is %d", + last_msg.msg.tracking_state_dep_b.states[0].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[0].sid.reserved == 68, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[0].sid.reserved, expected " + "68, is %d", + last_msg.msg.tracking_state_dep_b.states[0].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[0].sid.sat == 58295, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[0].sid.sat, " + "expected 58295, is %d", + last_msg.msg.tracking_state_dep_b.states[0].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[0].state == 115, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[0].state, expected " + "115, is %d", + last_msg.msg.tracking_state_dep_b.states[0].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[1].cn0 * 100 - + 2612.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[1].cn0, " + "expected 2612.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[1].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[1].sid.code == 43, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[1].sid.code, " + "expected 43, is %d", + last_msg.msg.tracking_state_dep_b.states[1].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[1].sid.reserved == 222, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[1].sid.reserved, expected " + "222, is %d", + last_msg.msg.tracking_state_dep_b.states[1].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[1].sid.sat == 31151, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[1].sid.sat, " + "expected 31151, is %d", + last_msg.msg.tracking_state_dep_b.states[1].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[1].state == 255, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[1].state, expected " + "255, is %d", + last_msg.msg.tracking_state_dep_b.states[1].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[2].cn0 * 100 - + 2925.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[2].cn0, " + "expected 2925.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[2].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[2].sid.code == 53, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[2].sid.code, " + "expected 53, is %d", + last_msg.msg.tracking_state_dep_b.states[2].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[2].sid.reserved == 20, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[2].sid.reserved, expected " + "20, is %d", + last_msg.msg.tracking_state_dep_b.states[2].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[2].sid.sat == 1520, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[2].sid.sat, " + "expected 1520, is %d", + last_msg.msg.tracking_state_dep_b.states[2].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[2].state == 78, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[2].state, expected 78, is %d", + last_msg.msg.tracking_state_dep_b.states[2].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[3].cn0 * 100 - + 3198.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[3].cn0, " + "expected 3198.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[3].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[3].sid.code == 66, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[3].sid.code, " + "expected 66, is %d", + last_msg.msg.tracking_state_dep_b.states[3].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[3].sid.reserved == 155, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[3].sid.reserved, expected " + "155, is %d", + last_msg.msg.tracking_state_dep_b.states[3].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[3].sid.sat == 60802, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[3].sid.sat, " + "expected 60802, is %d", + last_msg.msg.tracking_state_dep_b.states[3].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[3].state == 153, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[3].state, expected " + "153, is %d", + last_msg.msg.tracking_state_dep_b.states[3].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[4].cn0 * 100 - + 8623.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[4].cn0, " + "expected 8623.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[4].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[4].sid.code == 161, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[4].sid.code, " + "expected 161, is %d", + last_msg.msg.tracking_state_dep_b.states[4].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[4].sid.reserved == 190, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[4].sid.reserved, expected " + "190, is %d", + last_msg.msg.tracking_state_dep_b.states[4].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[4].sid.sat == 35058, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[4].sid.sat, " + "expected 35058, is %d", + last_msg.msg.tracking_state_dep_b.states[4].sid.sat); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[4].state == 53, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[4].state, expected 53, is %d", + last_msg.msg.tracking_state_dep_b.states[4].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[5].cn0 * 100 - + 5915.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[5].cn0, " + "expected 5915.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[5].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[5].sid.code == 142, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[5].sid.code, " + "expected 142, is %d", + last_msg.msg.tracking_state_dep_b.states[5].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[5].sid.reserved == 149, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[5].sid.reserved, expected " + "149, is %d", + last_msg.msg.tracking_state_dep_b.states[5].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[5].sid.sat == 65405, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[5].sid.sat, " + "expected 65405, is %d", + last_msg.msg.tracking_state_dep_b.states[5].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[5].state == 153, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[5].state, expected " + "153, is %d", + last_msg.msg.tracking_state_dep_b.states[5].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[6].cn0 * 100 - + 5412.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[6].cn0, " + "expected 5412.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[6].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[6].sid.code == 31, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[6].sid.code, " + "expected 31, is %d", + last_msg.msg.tracking_state_dep_b.states[6].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[6].sid.reserved == 76, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[6].sid.reserved, expected " + "76, is %d", + last_msg.msg.tracking_state_dep_b.states[6].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[6].sid.sat == 24422, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[6].sid.sat, " + "expected 24422, is %d", + last_msg.msg.tracking_state_dep_b.states[6].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[6].state == 248, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[6].state, expected " + "248, is %d", + last_msg.msg.tracking_state_dep_b.states[6].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[7].cn0 * 100 - + 6428.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[7].cn0, " + "expected 6428.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[7].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[7].sid.code == 27, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[7].sid.code, " + "expected 27, is %d", + last_msg.msg.tracking_state_dep_b.states[7].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[7].sid.reserved == 12, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[7].sid.reserved, expected " + "12, is %d", + last_msg.msg.tracking_state_dep_b.states[7].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[7].sid.sat == 36211, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[7].sid.sat, " + "expected 36211, is %d", + last_msg.msg.tracking_state_dep_b.states[7].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[7].state == 131, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[7].state, expected " + "131, is %d", + last_msg.msg.tracking_state_dep_b.states[7].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[8].cn0 * 100 - + 3104.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[8].cn0, " + "expected 3104.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[8].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[8].sid.code == 39, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[8].sid.code, " + "expected 39, is %d", + last_msg.msg.tracking_state_dep_b.states[8].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[8].sid.reserved == 23, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[8].sid.reserved, expected " + "23, is %d", + last_msg.msg.tracking_state_dep_b.states[8].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[8].sid.sat == 37676, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[8].sid.sat, " + "expected 37676, is %d", + last_msg.msg.tracking_state_dep_b.states[8].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[8].state == 208, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[8].state, expected " + "208, is %d", + last_msg.msg.tracking_state_dep_b.states[8].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[9].cn0 * 100 - + 3686.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[9].cn0, " + "expected 3686.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[9].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[9].sid.code == 49, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[9].sid.code, " + "expected 49, is %d", + last_msg.msg.tracking_state_dep_b.states[9].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[9].sid.reserved == 203, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[9].sid.reserved, expected " + "203, is %d", + last_msg.msg.tracking_state_dep_b.states[9].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[9].sid.sat == 64415, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[9].sid.sat, " + "expected 64415, is %d", + last_msg.msg.tracking_state_dep_b.states[9].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[9].state == 237, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[9].state, expected " + "237, is %d", + last_msg.msg.tracking_state_dep_b.states[9].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[10].cn0 * 100 - + 5967.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[10].cn0, " + "expected 5967.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[10].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[10].sid.code == 128, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[10].sid.code, " + "expected 128, is %d", + last_msg.msg.tracking_state_dep_b.states[10].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[10].sid.reserved == 206, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[10].sid.reserved, expected " + "206, is %d", + last_msg.msg.tracking_state_dep_b.states[10].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[10].sid.sat == 22486, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[10].sid.sat, " + "expected 22486, is %d", + last_msg.msg.tracking_state_dep_b.states[10].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[10].state == 70, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[10].state, " + "expected 70, is %d", + last_msg.msg.tracking_state_dep_b.states[10].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[11].cn0 * 100 - + 5423.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[11].cn0, " + "expected 5423.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[11].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[11].sid.code == 218, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[11].sid.code, " + "expected 218, is %d", + last_msg.msg.tracking_state_dep_b.states[11].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[11].sid.reserved == 19, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[11].sid.reserved, expected " + "19, is %d", + last_msg.msg.tracking_state_dep_b.states[11].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[11].sid.sat == 28622, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[11].sid.sat, " + "expected 28622, is %d", + last_msg.msg.tracking_state_dep_b.states[11].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[11].state == 14, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[11].state, " + "expected 14, is %d", + last_msg.msg.tracking_state_dep_b.states[11].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[12].cn0 * 100 - + 438.200012207 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[12].cn0, " + "expected 438.200012207, is %s", + last_msg.msg.tracking_state_dep_b.states[12].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[12].sid.code == 54, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[12].sid.code, " + "expected 54, is %d", + last_msg.msg.tracking_state_dep_b.states[12].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[12].sid.reserved == 2, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[12].sid.reserved, expected " + "2, is %d", + last_msg.msg.tracking_state_dep_b.states[12].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[12].sid.sat == 53602, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[12].sid.sat, " + "expected 53602, is %d", + last_msg.msg.tracking_state_dep_b.states[12].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[12].state == 216, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[12].state, " + "expected 216, is %d", + last_msg.msg.tracking_state_dep_b.states[12].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[13].cn0 * 100 - + 1862.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[13].cn0, " + "expected 1862.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[13].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[13].sid.code == 7, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[13].sid.code, " + "expected 7, is %d", + last_msg.msg.tracking_state_dep_b.states[13].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[13].sid.reserved == 34, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[13].sid.reserved, expected " + "34, is %d", + last_msg.msg.tracking_state_dep_b.states[13].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[13].sid.sat == 25477, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[13].sid.sat, " + "expected 25477, is %d", + last_msg.msg.tracking_state_dep_b.states[13].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[13].state == 200, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[13].state, " + "expected 200, is %d", + last_msg.msg.tracking_state_dep_b.states[13].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[14].cn0 * 100 - + 5462.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[14].cn0, " + "expected 5462.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[14].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[14].sid.code == 135, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[14].sid.code, " + "expected 135, is %d", + last_msg.msg.tracking_state_dep_b.states[14].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[14].sid.reserved == 46, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[14].sid.reserved, expected " + "46, is %d", + last_msg.msg.tracking_state_dep_b.states[14].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[14].sid.sat == 21803, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[14].sid.sat, " + "expected 21803, is %d", + last_msg.msg.tracking_state_dep_b.states[14].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[14].state == 155, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[14].state, " + "expected 155, is %d", + last_msg.msg.tracking_state_dep_b.states[14].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[15].cn0 * 100 - + 7454.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[15].cn0, " + "expected 7454.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[15].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[15].sid.code == 171, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[15].sid.code, " + "expected 171, is %d", + last_msg.msg.tracking_state_dep_b.states[15].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[15].sid.reserved == 201, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[15].sid.reserved, expected " + "201, is %d", + last_msg.msg.tracking_state_dep_b.states[15].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[15].sid.sat == 21251, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[15].sid.sat, " + "expected 21251, is %d", + last_msg.msg.tracking_state_dep_b.states[15].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[15].state == 155, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[15].state, " + "expected 155, is %d", + last_msg.msg.tracking_state_dep_b.states[15].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[16].cn0 * 100 - + 7134.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[16].cn0, " + "expected 7134.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[16].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[16].sid.code == 16, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[16].sid.code, " + "expected 16, is %d", + last_msg.msg.tracking_state_dep_b.states[16].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[16].sid.reserved == 19, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[16].sid.reserved, expected " + "19, is %d", + last_msg.msg.tracking_state_dep_b.states[16].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[16].sid.sat == 50475, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[16].sid.sat, " + "expected 50475, is %d", + last_msg.msg.tracking_state_dep_b.states[16].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[16].state == 121, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[16].state, " + "expected 121, is %d", + last_msg.msg.tracking_state_dep_b.states[16].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[17].cn0 * 100 - + 3111.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[17].cn0, " + "expected 3111.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[17].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[17].sid.code == 63, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[17].sid.code, " + "expected 63, is %d", + last_msg.msg.tracking_state_dep_b.states[17].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[17].sid.reserved == 176, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[17].sid.reserved, expected " + "176, is %d", + last_msg.msg.tracking_state_dep_b.states[17].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[17].sid.sat == 13813, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[17].sid.sat, " + "expected 13813, is %d", + last_msg.msg.tracking_state_dep_b.states[17].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[17].state == 128, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[17].state, " + "expected 128, is %d", + last_msg.msg.tracking_state_dep_b.states[17].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[18].cn0 * 100 - + 4297.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[18].cn0, " + "expected 4297.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[18].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[18].sid.code == 153, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[18].sid.code, " + "expected 153, is %d", + last_msg.msg.tracking_state_dep_b.states[18].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[18].sid.reserved == 51, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[18].sid.reserved, expected " + "51, is %d", + last_msg.msg.tracking_state_dep_b.states[18].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[18].sid.sat == 15636, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[18].sid.sat, " + "expected 15636, is %d", + last_msg.msg.tracking_state_dep_b.states[18].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[18].state == 36, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[18].state, " + "expected 36, is %d", + last_msg.msg.tracking_state_dep_b.states[18].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[19].cn0 * 100 - + 2649.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[19].cn0, " + "expected 2649.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[19].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[19].sid.code == 140, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[19].sid.code, " + "expected 140, is %d", + last_msg.msg.tracking_state_dep_b.states[19].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[19].sid.reserved == 22, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[19].sid.reserved, expected " + "22, is %d", + last_msg.msg.tracking_state_dep_b.states[19].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[19].sid.sat == 29778, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[19].sid.sat, " + "expected 29778, is %d", + last_msg.msg.tracking_state_dep_b.states[19].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[19].state == 46, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[19].state, " + "expected 46, is %d", + last_msg.msg.tracking_state_dep_b.states[19].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[20].cn0 * 100 - + 941.200012207 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[20].cn0, " + "expected 941.200012207, is %s", + last_msg.msg.tracking_state_dep_b.states[20].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[20].sid.code == 96, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[20].sid.code, " + "expected 96, is %d", + last_msg.msg.tracking_state_dep_b.states[20].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[20].sid.reserved == 143, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[20].sid.reserved, expected " + "143, is %d", + last_msg.msg.tracking_state_dep_b.states[20].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[20].sid.sat == 37443, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[20].sid.sat, " + "expected 37443, is %d", + last_msg.msg.tracking_state_dep_b.states[20].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[20].state == 177, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[20].state, " + "expected 177, is %d", + last_msg.msg.tracking_state_dep_b.states[20].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[21].cn0 * 100 - + 1539.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[21].cn0, " + "expected 1539.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[21].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[21].sid.code == 201, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[21].sid.code, " + "expected 201, is %d", + last_msg.msg.tracking_state_dep_b.states[21].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[21].sid.reserved == 251, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[21].sid.reserved, expected " + "251, is %d", + last_msg.msg.tracking_state_dep_b.states[21].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[21].sid.sat == 41011, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[21].sid.sat, " + "expected 41011, is %d", + last_msg.msg.tracking_state_dep_b.states[21].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[21].state == 220, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[21].state, " + "expected 220, is %d", + last_msg.msg.tracking_state_dep_b.states[21].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[22].cn0 * 100 - + 1443.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[22].cn0, " + "expected 1443.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[22].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[22].sid.code == 161, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[22].sid.code, " + "expected 161, is %d", + last_msg.msg.tracking_state_dep_b.states[22].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[22].sid.reserved == 220, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[22].sid.reserved, expected " + "220, is %d", + last_msg.msg.tracking_state_dep_b.states[22].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[22].sid.sat == 706, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[22].sid.sat, " + "expected 706, is %d", + last_msg.msg.tracking_state_dep_b.states[22].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[22].state == 168, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[22].state, " + "expected 168, is %d", + last_msg.msg.tracking_state_dep_b.states[22].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[23].cn0 * 100 - + 1074.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[23].cn0, " + "expected 1074.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[23].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[23].sid.code == 125, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[23].sid.code, " + "expected 125, is %d", + last_msg.msg.tracking_state_dep_b.states[23].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[23].sid.reserved == 178, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[23].sid.reserved, expected " + "178, is %d", + last_msg.msg.tracking_state_dep_b.states[23].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[23].sid.sat == 2312, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[23].sid.sat, " + "expected 2312, is %d", + last_msg.msg.tracking_state_dep_b.states[23].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[23].state == 69, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[23].state, " + "expected 69, is %d", + last_msg.msg.tracking_state_dep_b.states[23].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[24].cn0 * 100 - + 2122.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[24].cn0, " + "expected 2122.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[24].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[24].sid.code == 186, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[24].sid.code, " + "expected 186, is %d", + last_msg.msg.tracking_state_dep_b.states[24].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[24].sid.reserved == 171, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[24].sid.reserved, expected " + "171, is %d", + last_msg.msg.tracking_state_dep_b.states[24].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[24].sid.sat == 34580, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[24].sid.sat, " + "expected 34580, is %d", + last_msg.msg.tracking_state_dep_b.states[24].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[24].state == 185, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[24].state, " + "expected 185, is %d", + last_msg.msg.tracking_state_dep_b.states[24].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[25].cn0 * 100 - + 9076.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[25].cn0, " + "expected 9076.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[25].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[25].sid.code == 85, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[25].sid.code, " + "expected 85, is %d", + last_msg.msg.tracking_state_dep_b.states[25].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[25].sid.reserved == 170, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[25].sid.reserved, expected " + "170, is %d", + last_msg.msg.tracking_state_dep_b.states[25].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[25].sid.sat == 39804, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[25].sid.sat, " + "expected 39804, is %d", + last_msg.msg.tracking_state_dep_b.states[25].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[25].state == 18, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[25].state, " + "expected 18, is %d", + last_msg.msg.tracking_state_dep_b.states[25].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[26].cn0 * 100 - + 4781.20019531 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[26].cn0, " + "expected 4781.20019531, is %s", + last_msg.msg.tracking_state_dep_b.states[26].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[26].sid.code == 255, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[26].sid.code, " + "expected 255, is %d", + last_msg.msg.tracking_state_dep_b.states[26].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[26].sid.reserved == 186, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[26].sid.reserved, expected " + "186, is %d", + last_msg.msg.tracking_state_dep_b.states[26].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[26].sid.sat == 52980, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[26].sid.sat, " + "expected 52980, is %d", + last_msg.msg.tracking_state_dep_b.states[26].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[26].state == 57, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[26].state, " + "expected 57, is %d", + last_msg.msg.tracking_state_dep_b.states[26].state); + + ck_assert_msg( + (last_msg.msg.tracking_state_dep_b.states[27].cn0 * 100 - + 3076.19995117 * 100) < 0.05, + "incorrect value for last_msg.msg.tracking_state_dep_b.states[27].cn0, " + "expected 3076.19995117, is %s", + last_msg.msg.tracking_state_dep_b.states[27].cn0); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[27].sid.code == 181, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[27].sid.code, " + "expected 181, is %d", + last_msg.msg.tracking_state_dep_b.states[27].sid.code); + + ck_assert_msg( + last_msg.msg.tracking_state_dep_b.states[27].sid.reserved == 175, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[27].sid.reserved, expected " + "175, is %d", + last_msg.msg.tracking_state_dep_b.states[27].sid.reserved); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[27].sid.sat == 24007, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[27].sid.sat, " + "expected 24007, is %d", + last_msg.msg.tracking_state_dep_b.states[27].sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_dep_b.states[27].state == 165, + "incorrect value for " + "last_msg.msg.tracking_state_dep_b.states[27].state, " + "expected 165, is %d", + last_msg.msg.tracking_state_dep_b.states[27].state); + } +} +END_TEST + +Suite *auto_check_sbp_tracking_MsgTrackingStateDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_tracking_MsgTrackingStateDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_tracking_MsgTrackingStateDepB"); + tcase_add_test(tc_acq, test_auto_check_sbp_tracking_MsgTrackingStateDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c b/c/test/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c new file mode 100644 index 0000000000..b35f24c70d --- /dev/null +++ b/c/test/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c @@ -0,0 +1,356 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x21, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, + 0, 133, 100, 71, 94, 192, 2, 160, 207, 212, 255, 135, 139, + 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, + 59, 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, + 15, 91, 249, 117, 142, 90, 219, 67, 25, 83, 62, 122, 100, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.tracking_state_detailed_dep_a.L.f = 204; + + test_msg.tracking_state_detailed_dep_a.L.i = -1601767965; + + test_msg.tracking_state_detailed_dep_a.P = 1044286343; + + test_msg.tracking_state_detailed_dep_a.P_std = 21427; + + test_msg.tracking_state_detailed_dep_a.acceleration = -114; + + test_msg.tracking_state_detailed_dep_a.clock_drift = 23311; + + test_msg.tracking_state_detailed_dep_a.clock_offset = 6012; + + test_msg.tracking_state_detailed_dep_a.cn0 = 78; + + test_msg.tracking_state_detailed_dep_a.corr_spacing = 30201; + + test_msg.tracking_state_detailed_dep_a.doppler = 1459556257; + + test_msg.tracking_state_detailed_dep_a.doppler_std = 63677; + + test_msg.tracking_state_detailed_dep_a.lock = 65375; + + test_msg.tracking_state_detailed_dep_a.misc_flags = 62; + + test_msg.tracking_state_detailed_dep_a.nav_flags = 25; + + test_msg.tracking_state_detailed_dep_a.pset_flags = 83; + + test_msg.tracking_state_detailed_dep_a.recv_time = 941247176494; + + test_msg.tracking_state_detailed_dep_a.sid.code = 59; + + test_msg.tracking_state_detailed_dep_a.sid.sat = 38; + + test_msg.tracking_state_detailed_dep_a.sync_flags = 90; + + test_msg.tracking_state_detailed_dep_a.tot.ns_residual = -811597120; + + test_msg.tracking_state_detailed_dep_a.tot.tow = 1581737093; + + test_msg.tracking_state_detailed_dep_a.tot.wn = 65492; + + test_msg.tracking_state_detailed_dep_a.tow_flags = 219; + + test_msg.tracking_state_detailed_dep_a.track_flags = 67; + + test_msg.tracking_state_detailed_dep_a.uptime = 3263741727; + + sbp_message_send(&sbp_state, SbpMsgTrackingStateDetailedDepA, 28315, + &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 28315, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg(sbp_message_cmp(SbpMsgTrackingStateDetailedDepA, + &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.L.f == 204, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.L.f, " + "expected 204, is %d", + last_msg.msg.tracking_state_detailed_dep_a.L.f); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.L.i == -1601767965, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.L.i, " + "expected -1601767965, is %d", + last_msg.msg.tracking_state_detailed_dep_a.L.i); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.P == 1044286343, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.P, " + "expected 1044286343, is %d", + last_msg.msg.tracking_state_detailed_dep_a.P); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.P_std == 21427, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.P_std, " + "expected 21427, is %d", + last_msg.msg.tracking_state_detailed_dep_a.P_std); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.acceleration == -114, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.acceleration, expected " + "-114, is %d", + last_msg.msg.tracking_state_detailed_dep_a.acceleration); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.clock_drift == 23311, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.clock_drift, expected " + "23311, is %d", + last_msg.msg.tracking_state_detailed_dep_a.clock_drift); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.clock_offset == 6012, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.clock_offset, expected " + "6012, is %d", + last_msg.msg.tracking_state_detailed_dep_a.clock_offset); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.cn0 == 78, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.cn0, " + "expected 78, is %d", + last_msg.msg.tracking_state_detailed_dep_a.cn0); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.corr_spacing == 30201, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.corr_spacing, expected " + "30201, is %d", + last_msg.msg.tracking_state_detailed_dep_a.corr_spacing); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.doppler == 1459556257, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.doppler, expected " + "1459556257, is %d", + last_msg.msg.tracking_state_detailed_dep_a.doppler); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.doppler_std == 63677, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.doppler_std, expected " + "63677, is %d", + last_msg.msg.tracking_state_detailed_dep_a.doppler_std); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.lock == 65375, + "incorrect value for last_msg.msg.tracking_state_detailed_dep_a.lock, " + "expected 65375, is %d", + last_msg.msg.tracking_state_detailed_dep_a.lock); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.misc_flags == 62, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.misc_flags, " + "expected 62, is %d", + last_msg.msg.tracking_state_detailed_dep_a.misc_flags); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.nav_flags == 25, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.nav_flags, " + "expected 25, is %d", + last_msg.msg.tracking_state_detailed_dep_a.nav_flags); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.pset_flags == 83, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.pset_flags, " + "expected 83, is %d", + last_msg.msg.tracking_state_detailed_dep_a.pset_flags); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.recv_time == 941247176494, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.recv_time, expected " + "941247176494, is %d", + last_msg.msg.tracking_state_detailed_dep_a.recv_time); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.sid.code == 59, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.sid.code, " + "expected 59, is %d", + last_msg.msg.tracking_state_detailed_dep_a.sid.code); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.sid.sat == 38, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.sid.sat, " + "expected 38, is %d", + last_msg.msg.tracking_state_detailed_dep_a.sid.sat); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.sync_flags == 90, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.sync_flags, " + "expected 90, is %d", + last_msg.msg.tracking_state_detailed_dep_a.sync_flags); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.tot.ns_residual == + -811597120, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.tot.ns_residual, " + "expected -811597120, is %d", + last_msg.msg.tracking_state_detailed_dep_a.tot.ns_residual); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.tot.tow == 1581737093, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.tot.tow, expected " + "1581737093, is %d", + last_msg.msg.tracking_state_detailed_dep_a.tot.tow); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.tot.wn == 65492, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.tot.wn, expected " + "65492, is %d", + last_msg.msg.tracking_state_detailed_dep_a.tot.wn); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.tow_flags == 219, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.tow_flags, " + "expected 219, is %d", + last_msg.msg.tracking_state_detailed_dep_a.tow_flags); + + ck_assert_msg(last_msg.msg.tracking_state_detailed_dep_a.track_flags == 67, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.track_flags, " + "expected 67, is %d", + last_msg.msg.tracking_state_detailed_dep_a.track_flags); + + ck_assert_msg( + last_msg.msg.tracking_state_detailed_dep_a.uptime == 3263741727, + "incorrect value for " + "last_msg.msg.tracking_state_detailed_dep_a.uptime, expected " + "3263741727, is %d", + last_msg.msg.tracking_state_detailed_dep_a.uptime); + } +} +END_TEST + +Suite *auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "auto_check_sbp_tracking_MsgTrackingStateDetailedDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA"); + tcase_add_test(tc_acq, + test_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_user_MsgUserData.c b/c/test/auto_check_sbp_user_MsgUserData.c new file mode 100644 index 0000000000..7db5079f0e --- /dev/null +++ b/c/test/auto_check_sbp_user_MsgUserData.c @@ -0,0 +1,1695 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_user_MsgUserData) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x800, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, + 149, 204, 113, 31, 108, 188, 179, 154, 156, 167, 145, 139, 42, 207, + 126, 242, 193, 9, 58, 75, 8, 135, 11, 92, 131, 245, 24, 90, + 255, 30, 58, 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, + 50, 148, 1, 99, 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, + 97, 96, 75, 174, 58, 219, 180, 148, 247, 59, 2, 116, 214, 114, + 55, 134, 54, 119, 108, 128, 73, 181, 20, 233, 23, 23, 73, 119, + 136, 231, 189, 26, 174, 128, 93, 30, 76, 45, 109, 134, 81, 0, + 116, 158, 127, 40, 133, 208, 134, 127, 140, 232, 183, 184, 108, 6, + 228, 54, 238, 59, 220, 30, 228, 212, 50, 182, 97, 20, 41, 76, + 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, 189, 44, 239, 232, + 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, 173, 157, 202, + 172, 180, 150, 213, 193, 177, 209, 156, 20, 174, 18, 73, 132, 215, + 115, 128, 175, 169, 116, 132, 100, 72, 45, 25, 14, 205, 213, 145, + 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, 6, 165, + 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, + 132, 59, 61, 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, + 56, 216, 19, 216, 70, 71, 161, 184, 5, 177, 45, 37, 98, 56, + 149, 0, 73, 221, 105, 239, 168, 205, 85, 81, 245, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.user_data.contents[0] = 53; + + test_msg.user_data.contents[1] = 5; + + test_msg.user_data.contents[2] = 172; + + test_msg.user_data.contents[3] = 138; + + test_msg.user_data.contents[4] = 50; + + test_msg.user_data.contents[5] = 49; + + test_msg.user_data.contents[6] = 206; + + test_msg.user_data.contents[7] = 234; + + test_msg.user_data.contents[8] = 149; + + test_msg.user_data.contents[9] = 204; + + test_msg.user_data.contents[10] = 113; + + test_msg.user_data.contents[11] = 31; + + test_msg.user_data.contents[12] = 108; + + test_msg.user_data.contents[13] = 188; + + test_msg.user_data.contents[14] = 179; + + test_msg.user_data.contents[15] = 154; + + test_msg.user_data.contents[16] = 156; + + test_msg.user_data.contents[17] = 167; + + test_msg.user_data.contents[18] = 145; + + test_msg.user_data.contents[19] = 139; + + test_msg.user_data.contents[20] = 42; + + test_msg.user_data.contents[21] = 207; + + test_msg.user_data.contents[22] = 126; + + test_msg.user_data.contents[23] = 242; + + test_msg.user_data.contents[24] = 193; + + test_msg.user_data.contents[25] = 9; + + test_msg.user_data.contents[26] = 58; + + test_msg.user_data.contents[27] = 75; + + test_msg.user_data.contents[28] = 8; + + test_msg.user_data.contents[29] = 135; + + test_msg.user_data.contents[30] = 11; + + test_msg.user_data.contents[31] = 92; + + test_msg.user_data.contents[32] = 131; + + test_msg.user_data.contents[33] = 245; + + test_msg.user_data.contents[34] = 24; + + test_msg.user_data.contents[35] = 90; + + test_msg.user_data.contents[36] = 255; + + test_msg.user_data.contents[37] = 30; + + test_msg.user_data.contents[38] = 58; + + test_msg.user_data.contents[39] = 31; + + test_msg.user_data.contents[40] = 109; + + test_msg.user_data.contents[41] = 148; + + test_msg.user_data.contents[42] = 56; + + test_msg.user_data.contents[43] = 178; + + test_msg.user_data.contents[44] = 140; + + test_msg.user_data.contents[45] = 30; + + test_msg.user_data.contents[46] = 159; + + test_msg.user_data.contents[47] = 70; + + test_msg.user_data.contents[48] = 17; + + test_msg.user_data.contents[49] = 170; + + test_msg.user_data.contents[50] = 50; + + test_msg.user_data.contents[51] = 148; + + test_msg.user_data.contents[52] = 1; + + test_msg.user_data.contents[53] = 99; + + test_msg.user_data.contents[54] = 112; + + test_msg.user_data.contents[55] = 88; + + test_msg.user_data.contents[56] = 217; + + test_msg.user_data.contents[57] = 36; + + test_msg.user_data.contents[58] = 84; + + test_msg.user_data.contents[59] = 34; + + test_msg.user_data.contents[60] = 234; + + test_msg.user_data.contents[61] = 82; + + test_msg.user_data.contents[62] = 144; + + test_msg.user_data.contents[63] = 144; + + test_msg.user_data.contents[64] = 97; + + test_msg.user_data.contents[65] = 96; + + test_msg.user_data.contents[66] = 75; + + test_msg.user_data.contents[67] = 174; + + test_msg.user_data.contents[68] = 58; + + test_msg.user_data.contents[69] = 219; + + test_msg.user_data.contents[70] = 180; + + test_msg.user_data.contents[71] = 148; + + test_msg.user_data.contents[72] = 247; + + test_msg.user_data.contents[73] = 59; + + test_msg.user_data.contents[74] = 2; + + test_msg.user_data.contents[75] = 116; + + test_msg.user_data.contents[76] = 214; + + test_msg.user_data.contents[77] = 114; + + test_msg.user_data.contents[78] = 55; + + test_msg.user_data.contents[79] = 134; + + test_msg.user_data.contents[80] = 54; + + test_msg.user_data.contents[81] = 119; + + test_msg.user_data.contents[82] = 108; + + test_msg.user_data.contents[83] = 128; + + test_msg.user_data.contents[84] = 73; + + test_msg.user_data.contents[85] = 181; + + test_msg.user_data.contents[86] = 20; + + test_msg.user_data.contents[87] = 233; + + test_msg.user_data.contents[88] = 23; + + test_msg.user_data.contents[89] = 23; + + test_msg.user_data.contents[90] = 73; + + test_msg.user_data.contents[91] = 119; + + test_msg.user_data.contents[92] = 136; + + test_msg.user_data.contents[93] = 231; + + test_msg.user_data.contents[94] = 189; + + test_msg.user_data.contents[95] = 26; + + test_msg.user_data.contents[96] = 174; + + test_msg.user_data.contents[97] = 128; + + test_msg.user_data.contents[98] = 93; + + test_msg.user_data.contents[99] = 30; + + test_msg.user_data.contents[100] = 76; + + test_msg.user_data.contents[101] = 45; + + test_msg.user_data.contents[102] = 109; + + test_msg.user_data.contents[103] = 134; + + test_msg.user_data.contents[104] = 81; + + test_msg.user_data.contents[105] = 0; + + test_msg.user_data.contents[106] = 116; + + test_msg.user_data.contents[107] = 158; + + test_msg.user_data.contents[108] = 127; + + test_msg.user_data.contents[109] = 40; + + test_msg.user_data.contents[110] = 133; + + test_msg.user_data.contents[111] = 208; + + test_msg.user_data.contents[112] = 134; + + test_msg.user_data.contents[113] = 127; + + test_msg.user_data.contents[114] = 140; + + test_msg.user_data.contents[115] = 232; + + test_msg.user_data.contents[116] = 183; + + test_msg.user_data.contents[117] = 184; + + test_msg.user_data.contents[118] = 108; + + test_msg.user_data.contents[119] = 6; + + test_msg.user_data.contents[120] = 228; + + test_msg.user_data.contents[121] = 54; + + test_msg.user_data.contents[122] = 238; + + test_msg.user_data.contents[123] = 59; + + test_msg.user_data.contents[124] = 220; + + test_msg.user_data.contents[125] = 30; + + test_msg.user_data.contents[126] = 228; + + test_msg.user_data.contents[127] = 212; + + test_msg.user_data.contents[128] = 50; + + test_msg.user_data.contents[129] = 182; + + test_msg.user_data.contents[130] = 97; + + test_msg.user_data.contents[131] = 20; + + test_msg.user_data.contents[132] = 41; + + test_msg.user_data.contents[133] = 76; + + test_msg.user_data.contents[134] = 227; + + test_msg.user_data.contents[135] = 88; + + test_msg.user_data.contents[136] = 12; + + test_msg.user_data.contents[137] = 95; + + test_msg.user_data.contents[138] = 112; + + test_msg.user_data.contents[139] = 209; + + test_msg.user_data.contents[140] = 183; + + test_msg.user_data.contents[141] = 127; + + test_msg.user_data.contents[142] = 4; + + test_msg.user_data.contents[143] = 165; + + test_msg.user_data.contents[144] = 189; + + test_msg.user_data.contents[145] = 44; + + test_msg.user_data.contents[146] = 239; + + test_msg.user_data.contents[147] = 232; + + test_msg.user_data.contents[148] = 132; + + test_msg.user_data.contents[149] = 9; + + test_msg.user_data.contents[150] = 114; + + test_msg.user_data.contents[151] = 184; + + test_msg.user_data.contents[152] = 249; + + test_msg.user_data.contents[153] = 208; + + test_msg.user_data.contents[154] = 246; + + test_msg.user_data.contents[155] = 194; + + test_msg.user_data.contents[156] = 250; + + test_msg.user_data.contents[157] = 2; + + test_msg.user_data.contents[158] = 97; + + test_msg.user_data.contents[159] = 173; + + test_msg.user_data.contents[160] = 157; + + test_msg.user_data.contents[161] = 202; + + test_msg.user_data.contents[162] = 172; + + test_msg.user_data.contents[163] = 180; + + test_msg.user_data.contents[164] = 150; + + test_msg.user_data.contents[165] = 213; + + test_msg.user_data.contents[166] = 193; + + test_msg.user_data.contents[167] = 177; + + test_msg.user_data.contents[168] = 209; + + test_msg.user_data.contents[169] = 156; + + test_msg.user_data.contents[170] = 20; + + test_msg.user_data.contents[171] = 174; + + test_msg.user_data.contents[172] = 18; + + test_msg.user_data.contents[173] = 73; + + test_msg.user_data.contents[174] = 132; + + test_msg.user_data.contents[175] = 215; + + test_msg.user_data.contents[176] = 115; + + test_msg.user_data.contents[177] = 128; + + test_msg.user_data.contents[178] = 175; + + test_msg.user_data.contents[179] = 169; + + test_msg.user_data.contents[180] = 116; + + test_msg.user_data.contents[181] = 132; + + test_msg.user_data.contents[182] = 100; + + test_msg.user_data.contents[183] = 72; + + test_msg.user_data.contents[184] = 45; + + test_msg.user_data.contents[185] = 25; + + test_msg.user_data.contents[186] = 14; + + test_msg.user_data.contents[187] = 205; + + test_msg.user_data.contents[188] = 213; + + test_msg.user_data.contents[189] = 145; + + test_msg.user_data.contents[190] = 68; + + test_msg.user_data.contents[191] = 137; + + test_msg.user_data.contents[192] = 249; + + test_msg.user_data.contents[193] = 54; + + test_msg.user_data.contents[194] = 40; + + test_msg.user_data.contents[195] = 174; + + test_msg.user_data.contents[196] = 215; + + test_msg.user_data.contents[197] = 148; + + test_msg.user_data.contents[198] = 166; + + test_msg.user_data.contents[199] = 190; + + test_msg.user_data.contents[200] = 63; + + test_msg.user_data.contents[201] = 118; + + test_msg.user_data.contents[202] = 6; + + test_msg.user_data.contents[203] = 165; + + test_msg.user_data.contents[204] = 212; + + test_msg.user_data.contents[205] = 74; + + test_msg.user_data.contents[206] = 68; + + test_msg.user_data.contents[207] = 200; + + test_msg.user_data.contents[208] = 38; + + test_msg.user_data.contents[209] = 139; + + test_msg.user_data.contents[210] = 212; + + test_msg.user_data.contents[211] = 112; + + test_msg.user_data.contents[212] = 45; + + test_msg.user_data.contents[213] = 167; + + test_msg.user_data.contents[214] = 236; + + test_msg.user_data.contents[215] = 255; + + test_msg.user_data.contents[216] = 106; + + test_msg.user_data.contents[217] = 92; + + test_msg.user_data.contents[218] = 132; + + test_msg.user_data.contents[219] = 59; + + test_msg.user_data.contents[220] = 61; + + test_msg.user_data.contents[221] = 233; + + test_msg.user_data.contents[222] = 3; + + test_msg.user_data.contents[223] = 246; + + test_msg.user_data.contents[224] = 158; + + test_msg.user_data.contents[225] = 83; + + test_msg.user_data.contents[226] = 134; + + test_msg.user_data.contents[227] = 246; + + test_msg.user_data.contents[228] = 154; + + test_msg.user_data.contents[229] = 17; + + test_msg.user_data.contents[230] = 0; + + test_msg.user_data.contents[231] = 6; + + test_msg.user_data.contents[232] = 56; + + test_msg.user_data.contents[233] = 216; + + test_msg.user_data.contents[234] = 19; + + test_msg.user_data.contents[235] = 216; + + test_msg.user_data.contents[236] = 70; + + test_msg.user_data.contents[237] = 71; + + test_msg.user_data.contents[238] = 161; + + test_msg.user_data.contents[239] = 184; + + test_msg.user_data.contents[240] = 5; + + test_msg.user_data.contents[241] = 177; + + test_msg.user_data.contents[242] = 45; + + test_msg.user_data.contents[243] = 37; + + test_msg.user_data.contents[244] = 98; + + test_msg.user_data.contents[245] = 56; + + test_msg.user_data.contents[246] = 149; + + test_msg.user_data.contents[247] = 0; + + test_msg.user_data.contents[248] = 73; + + test_msg.user_data.contents[249] = 221; + + test_msg.user_data.contents[250] = 105; + + test_msg.user_data.contents[251] = 239; + + test_msg.user_data.contents[252] = 168; + + test_msg.user_data.contents[253] = 205; + + test_msg.user_data.contents[254] = 85; + + test_msg.user_data.n_contents = 255; + + sbp_message_send(&sbp_state, SbpMsgUserData, 8574, &test_msg, &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 8574, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgUserData, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg(last_msg.msg.user_data.contents[0] == 53, + "incorrect value for last_msg.msg.user_data.contents[0], " + "expected 53, is %d", + last_msg.msg.user_data.contents[0]); + ck_assert_msg(last_msg.msg.user_data.contents[1] == 5, + "incorrect value for last_msg.msg.user_data.contents[1], " + "expected 5, is %d", + last_msg.msg.user_data.contents[1]); + ck_assert_msg(last_msg.msg.user_data.contents[2] == 172, + "incorrect value for last_msg.msg.user_data.contents[2], " + "expected 172, is %d", + last_msg.msg.user_data.contents[2]); + ck_assert_msg(last_msg.msg.user_data.contents[3] == 138, + "incorrect value for last_msg.msg.user_data.contents[3], " + "expected 138, is %d", + last_msg.msg.user_data.contents[3]); + ck_assert_msg(last_msg.msg.user_data.contents[4] == 50, + "incorrect value for last_msg.msg.user_data.contents[4], " + "expected 50, is %d", + last_msg.msg.user_data.contents[4]); + ck_assert_msg(last_msg.msg.user_data.contents[5] == 49, + "incorrect value for last_msg.msg.user_data.contents[5], " + "expected 49, is %d", + last_msg.msg.user_data.contents[5]); + ck_assert_msg(last_msg.msg.user_data.contents[6] == 206, + "incorrect value for last_msg.msg.user_data.contents[6], " + "expected 206, is %d", + last_msg.msg.user_data.contents[6]); + ck_assert_msg(last_msg.msg.user_data.contents[7] == 234, + "incorrect value for last_msg.msg.user_data.contents[7], " + "expected 234, is %d", + last_msg.msg.user_data.contents[7]); + ck_assert_msg(last_msg.msg.user_data.contents[8] == 149, + "incorrect value for last_msg.msg.user_data.contents[8], " + "expected 149, is %d", + last_msg.msg.user_data.contents[8]); + ck_assert_msg(last_msg.msg.user_data.contents[9] == 204, + "incorrect value for last_msg.msg.user_data.contents[9], " + "expected 204, is %d", + last_msg.msg.user_data.contents[9]); + ck_assert_msg(last_msg.msg.user_data.contents[10] == 113, + "incorrect value for last_msg.msg.user_data.contents[10], " + "expected 113, is %d", + last_msg.msg.user_data.contents[10]); + ck_assert_msg(last_msg.msg.user_data.contents[11] == 31, + "incorrect value for last_msg.msg.user_data.contents[11], " + "expected 31, is %d", + last_msg.msg.user_data.contents[11]); + ck_assert_msg(last_msg.msg.user_data.contents[12] == 108, + "incorrect value for last_msg.msg.user_data.contents[12], " + "expected 108, is %d", + last_msg.msg.user_data.contents[12]); + ck_assert_msg(last_msg.msg.user_data.contents[13] == 188, + "incorrect value for last_msg.msg.user_data.contents[13], " + "expected 188, is %d", + last_msg.msg.user_data.contents[13]); + ck_assert_msg(last_msg.msg.user_data.contents[14] == 179, + "incorrect value for last_msg.msg.user_data.contents[14], " + "expected 179, is %d", + last_msg.msg.user_data.contents[14]); + ck_assert_msg(last_msg.msg.user_data.contents[15] == 154, + "incorrect value for last_msg.msg.user_data.contents[15], " + "expected 154, is %d", + last_msg.msg.user_data.contents[15]); + ck_assert_msg(last_msg.msg.user_data.contents[16] == 156, + "incorrect value for last_msg.msg.user_data.contents[16], " + "expected 156, is %d", + last_msg.msg.user_data.contents[16]); + ck_assert_msg(last_msg.msg.user_data.contents[17] == 167, + "incorrect value for last_msg.msg.user_data.contents[17], " + "expected 167, is %d", + last_msg.msg.user_data.contents[17]); + ck_assert_msg(last_msg.msg.user_data.contents[18] == 145, + "incorrect value for last_msg.msg.user_data.contents[18], " + "expected 145, is %d", + last_msg.msg.user_data.contents[18]); + ck_assert_msg(last_msg.msg.user_data.contents[19] == 139, + "incorrect value for last_msg.msg.user_data.contents[19], " + "expected 139, is %d", + last_msg.msg.user_data.contents[19]); + ck_assert_msg(last_msg.msg.user_data.contents[20] == 42, + "incorrect value for last_msg.msg.user_data.contents[20], " + "expected 42, is %d", + last_msg.msg.user_data.contents[20]); + ck_assert_msg(last_msg.msg.user_data.contents[21] == 207, + "incorrect value for last_msg.msg.user_data.contents[21], " + "expected 207, is %d", + last_msg.msg.user_data.contents[21]); + ck_assert_msg(last_msg.msg.user_data.contents[22] == 126, + "incorrect value for last_msg.msg.user_data.contents[22], " + "expected 126, is %d", + last_msg.msg.user_data.contents[22]); + ck_assert_msg(last_msg.msg.user_data.contents[23] == 242, + "incorrect value for last_msg.msg.user_data.contents[23], " + "expected 242, is %d", + last_msg.msg.user_data.contents[23]); + ck_assert_msg(last_msg.msg.user_data.contents[24] == 193, + "incorrect value for last_msg.msg.user_data.contents[24], " + "expected 193, is %d", + last_msg.msg.user_data.contents[24]); + ck_assert_msg(last_msg.msg.user_data.contents[25] == 9, + "incorrect value for last_msg.msg.user_data.contents[25], " + "expected 9, is %d", + last_msg.msg.user_data.contents[25]); + ck_assert_msg(last_msg.msg.user_data.contents[26] == 58, + "incorrect value for last_msg.msg.user_data.contents[26], " + "expected 58, is %d", + last_msg.msg.user_data.contents[26]); + ck_assert_msg(last_msg.msg.user_data.contents[27] == 75, + "incorrect value for last_msg.msg.user_data.contents[27], " + "expected 75, is %d", + last_msg.msg.user_data.contents[27]); + ck_assert_msg(last_msg.msg.user_data.contents[28] == 8, + "incorrect value for last_msg.msg.user_data.contents[28], " + "expected 8, is %d", + last_msg.msg.user_data.contents[28]); + ck_assert_msg(last_msg.msg.user_data.contents[29] == 135, + "incorrect value for last_msg.msg.user_data.contents[29], " + "expected 135, is %d", + last_msg.msg.user_data.contents[29]); + ck_assert_msg(last_msg.msg.user_data.contents[30] == 11, + "incorrect value for last_msg.msg.user_data.contents[30], " + "expected 11, is %d", + last_msg.msg.user_data.contents[30]); + ck_assert_msg(last_msg.msg.user_data.contents[31] == 92, + "incorrect value for last_msg.msg.user_data.contents[31], " + "expected 92, is %d", + last_msg.msg.user_data.contents[31]); + ck_assert_msg(last_msg.msg.user_data.contents[32] == 131, + "incorrect value for last_msg.msg.user_data.contents[32], " + "expected 131, is %d", + last_msg.msg.user_data.contents[32]); + ck_assert_msg(last_msg.msg.user_data.contents[33] == 245, + "incorrect value for last_msg.msg.user_data.contents[33], " + "expected 245, is %d", + last_msg.msg.user_data.contents[33]); + ck_assert_msg(last_msg.msg.user_data.contents[34] == 24, + "incorrect value for last_msg.msg.user_data.contents[34], " + "expected 24, is %d", + last_msg.msg.user_data.contents[34]); + ck_assert_msg(last_msg.msg.user_data.contents[35] == 90, + "incorrect value for last_msg.msg.user_data.contents[35], " + "expected 90, is %d", + last_msg.msg.user_data.contents[35]); + ck_assert_msg(last_msg.msg.user_data.contents[36] == 255, + "incorrect value for last_msg.msg.user_data.contents[36], " + "expected 255, is %d", + last_msg.msg.user_data.contents[36]); + ck_assert_msg(last_msg.msg.user_data.contents[37] == 30, + "incorrect value for last_msg.msg.user_data.contents[37], " + "expected 30, is %d", + last_msg.msg.user_data.contents[37]); + ck_assert_msg(last_msg.msg.user_data.contents[38] == 58, + "incorrect value for last_msg.msg.user_data.contents[38], " + "expected 58, is %d", + last_msg.msg.user_data.contents[38]); + ck_assert_msg(last_msg.msg.user_data.contents[39] == 31, + "incorrect value for last_msg.msg.user_data.contents[39], " + "expected 31, is %d", + last_msg.msg.user_data.contents[39]); + ck_assert_msg(last_msg.msg.user_data.contents[40] == 109, + "incorrect value for last_msg.msg.user_data.contents[40], " + "expected 109, is %d", + last_msg.msg.user_data.contents[40]); + ck_assert_msg(last_msg.msg.user_data.contents[41] == 148, + "incorrect value for last_msg.msg.user_data.contents[41], " + "expected 148, is %d", + last_msg.msg.user_data.contents[41]); + ck_assert_msg(last_msg.msg.user_data.contents[42] == 56, + "incorrect value for last_msg.msg.user_data.contents[42], " + "expected 56, is %d", + last_msg.msg.user_data.contents[42]); + ck_assert_msg(last_msg.msg.user_data.contents[43] == 178, + "incorrect value for last_msg.msg.user_data.contents[43], " + "expected 178, is %d", + last_msg.msg.user_data.contents[43]); + ck_assert_msg(last_msg.msg.user_data.contents[44] == 140, + "incorrect value for last_msg.msg.user_data.contents[44], " + "expected 140, is %d", + last_msg.msg.user_data.contents[44]); + ck_assert_msg(last_msg.msg.user_data.contents[45] == 30, + "incorrect value for last_msg.msg.user_data.contents[45], " + "expected 30, is %d", + last_msg.msg.user_data.contents[45]); + ck_assert_msg(last_msg.msg.user_data.contents[46] == 159, + "incorrect value for last_msg.msg.user_data.contents[46], " + "expected 159, is %d", + last_msg.msg.user_data.contents[46]); + ck_assert_msg(last_msg.msg.user_data.contents[47] == 70, + "incorrect value for last_msg.msg.user_data.contents[47], " + "expected 70, is %d", + last_msg.msg.user_data.contents[47]); + ck_assert_msg(last_msg.msg.user_data.contents[48] == 17, + "incorrect value for last_msg.msg.user_data.contents[48], " + "expected 17, is %d", + last_msg.msg.user_data.contents[48]); + ck_assert_msg(last_msg.msg.user_data.contents[49] == 170, + "incorrect value for last_msg.msg.user_data.contents[49], " + "expected 170, is %d", + last_msg.msg.user_data.contents[49]); + ck_assert_msg(last_msg.msg.user_data.contents[50] == 50, + "incorrect value for last_msg.msg.user_data.contents[50], " + "expected 50, is %d", + last_msg.msg.user_data.contents[50]); + ck_assert_msg(last_msg.msg.user_data.contents[51] == 148, + "incorrect value for last_msg.msg.user_data.contents[51], " + "expected 148, is %d", + last_msg.msg.user_data.contents[51]); + ck_assert_msg(last_msg.msg.user_data.contents[52] == 1, + "incorrect value for last_msg.msg.user_data.contents[52], " + "expected 1, is %d", + last_msg.msg.user_data.contents[52]); + ck_assert_msg(last_msg.msg.user_data.contents[53] == 99, + "incorrect value for last_msg.msg.user_data.contents[53], " + "expected 99, is %d", + last_msg.msg.user_data.contents[53]); + ck_assert_msg(last_msg.msg.user_data.contents[54] == 112, + "incorrect value for last_msg.msg.user_data.contents[54], " + "expected 112, is %d", + last_msg.msg.user_data.contents[54]); + ck_assert_msg(last_msg.msg.user_data.contents[55] == 88, + "incorrect value for last_msg.msg.user_data.contents[55], " + "expected 88, is %d", + last_msg.msg.user_data.contents[55]); + ck_assert_msg(last_msg.msg.user_data.contents[56] == 217, + "incorrect value for last_msg.msg.user_data.contents[56], " + "expected 217, is %d", + last_msg.msg.user_data.contents[56]); + ck_assert_msg(last_msg.msg.user_data.contents[57] == 36, + "incorrect value for last_msg.msg.user_data.contents[57], " + "expected 36, is %d", + last_msg.msg.user_data.contents[57]); + ck_assert_msg(last_msg.msg.user_data.contents[58] == 84, + "incorrect value for last_msg.msg.user_data.contents[58], " + "expected 84, is %d", + last_msg.msg.user_data.contents[58]); + ck_assert_msg(last_msg.msg.user_data.contents[59] == 34, + "incorrect value for last_msg.msg.user_data.contents[59], " + "expected 34, is %d", + last_msg.msg.user_data.contents[59]); + ck_assert_msg(last_msg.msg.user_data.contents[60] == 234, + "incorrect value for last_msg.msg.user_data.contents[60], " + "expected 234, is %d", + last_msg.msg.user_data.contents[60]); + ck_assert_msg(last_msg.msg.user_data.contents[61] == 82, + "incorrect value for last_msg.msg.user_data.contents[61], " + "expected 82, is %d", + last_msg.msg.user_data.contents[61]); + ck_assert_msg(last_msg.msg.user_data.contents[62] == 144, + "incorrect value for last_msg.msg.user_data.contents[62], " + "expected 144, is %d", + last_msg.msg.user_data.contents[62]); + ck_assert_msg(last_msg.msg.user_data.contents[63] == 144, + "incorrect value for last_msg.msg.user_data.contents[63], " + "expected 144, is %d", + last_msg.msg.user_data.contents[63]); + ck_assert_msg(last_msg.msg.user_data.contents[64] == 97, + "incorrect value for last_msg.msg.user_data.contents[64], " + "expected 97, is %d", + last_msg.msg.user_data.contents[64]); + ck_assert_msg(last_msg.msg.user_data.contents[65] == 96, + "incorrect value for last_msg.msg.user_data.contents[65], " + "expected 96, is %d", + last_msg.msg.user_data.contents[65]); + ck_assert_msg(last_msg.msg.user_data.contents[66] == 75, + "incorrect value for last_msg.msg.user_data.contents[66], " + "expected 75, is %d", + last_msg.msg.user_data.contents[66]); + ck_assert_msg(last_msg.msg.user_data.contents[67] == 174, + "incorrect value for last_msg.msg.user_data.contents[67], " + "expected 174, is %d", + last_msg.msg.user_data.contents[67]); + ck_assert_msg(last_msg.msg.user_data.contents[68] == 58, + "incorrect value for last_msg.msg.user_data.contents[68], " + "expected 58, is %d", + last_msg.msg.user_data.contents[68]); + ck_assert_msg(last_msg.msg.user_data.contents[69] == 219, + "incorrect value for last_msg.msg.user_data.contents[69], " + "expected 219, is %d", + last_msg.msg.user_data.contents[69]); + ck_assert_msg(last_msg.msg.user_data.contents[70] == 180, + "incorrect value for last_msg.msg.user_data.contents[70], " + "expected 180, is %d", + last_msg.msg.user_data.contents[70]); + ck_assert_msg(last_msg.msg.user_data.contents[71] == 148, + "incorrect value for last_msg.msg.user_data.contents[71], " + "expected 148, is %d", + last_msg.msg.user_data.contents[71]); + ck_assert_msg(last_msg.msg.user_data.contents[72] == 247, + "incorrect value for last_msg.msg.user_data.contents[72], " + "expected 247, is %d", + last_msg.msg.user_data.contents[72]); + ck_assert_msg(last_msg.msg.user_data.contents[73] == 59, + "incorrect value for last_msg.msg.user_data.contents[73], " + "expected 59, is %d", + last_msg.msg.user_data.contents[73]); + ck_assert_msg(last_msg.msg.user_data.contents[74] == 2, + "incorrect value for last_msg.msg.user_data.contents[74], " + "expected 2, is %d", + last_msg.msg.user_data.contents[74]); + ck_assert_msg(last_msg.msg.user_data.contents[75] == 116, + "incorrect value for last_msg.msg.user_data.contents[75], " + "expected 116, is %d", + last_msg.msg.user_data.contents[75]); + ck_assert_msg(last_msg.msg.user_data.contents[76] == 214, + "incorrect value for last_msg.msg.user_data.contents[76], " + "expected 214, is %d", + last_msg.msg.user_data.contents[76]); + ck_assert_msg(last_msg.msg.user_data.contents[77] == 114, + "incorrect value for last_msg.msg.user_data.contents[77], " + "expected 114, is %d", + last_msg.msg.user_data.contents[77]); + ck_assert_msg(last_msg.msg.user_data.contents[78] == 55, + "incorrect value for last_msg.msg.user_data.contents[78], " + "expected 55, is %d", + last_msg.msg.user_data.contents[78]); + ck_assert_msg(last_msg.msg.user_data.contents[79] == 134, + "incorrect value for last_msg.msg.user_data.contents[79], " + "expected 134, is %d", + last_msg.msg.user_data.contents[79]); + ck_assert_msg(last_msg.msg.user_data.contents[80] == 54, + "incorrect value for last_msg.msg.user_data.contents[80], " + "expected 54, is %d", + last_msg.msg.user_data.contents[80]); + ck_assert_msg(last_msg.msg.user_data.contents[81] == 119, + "incorrect value for last_msg.msg.user_data.contents[81], " + "expected 119, is %d", + last_msg.msg.user_data.contents[81]); + ck_assert_msg(last_msg.msg.user_data.contents[82] == 108, + "incorrect value for last_msg.msg.user_data.contents[82], " + "expected 108, is %d", + last_msg.msg.user_data.contents[82]); + ck_assert_msg(last_msg.msg.user_data.contents[83] == 128, + "incorrect value for last_msg.msg.user_data.contents[83], " + "expected 128, is %d", + last_msg.msg.user_data.contents[83]); + ck_assert_msg(last_msg.msg.user_data.contents[84] == 73, + "incorrect value for last_msg.msg.user_data.contents[84], " + "expected 73, is %d", + last_msg.msg.user_data.contents[84]); + ck_assert_msg(last_msg.msg.user_data.contents[85] == 181, + "incorrect value for last_msg.msg.user_data.contents[85], " + "expected 181, is %d", + last_msg.msg.user_data.contents[85]); + ck_assert_msg(last_msg.msg.user_data.contents[86] == 20, + "incorrect value for last_msg.msg.user_data.contents[86], " + "expected 20, is %d", + last_msg.msg.user_data.contents[86]); + ck_assert_msg(last_msg.msg.user_data.contents[87] == 233, + "incorrect value for last_msg.msg.user_data.contents[87], " + "expected 233, is %d", + last_msg.msg.user_data.contents[87]); + ck_assert_msg(last_msg.msg.user_data.contents[88] == 23, + "incorrect value for last_msg.msg.user_data.contents[88], " + "expected 23, is %d", + last_msg.msg.user_data.contents[88]); + ck_assert_msg(last_msg.msg.user_data.contents[89] == 23, + "incorrect value for last_msg.msg.user_data.contents[89], " + "expected 23, is %d", + last_msg.msg.user_data.contents[89]); + ck_assert_msg(last_msg.msg.user_data.contents[90] == 73, + "incorrect value for last_msg.msg.user_data.contents[90], " + "expected 73, is %d", + last_msg.msg.user_data.contents[90]); + ck_assert_msg(last_msg.msg.user_data.contents[91] == 119, + "incorrect value for last_msg.msg.user_data.contents[91], " + "expected 119, is %d", + last_msg.msg.user_data.contents[91]); + ck_assert_msg(last_msg.msg.user_data.contents[92] == 136, + "incorrect value for last_msg.msg.user_data.contents[92], " + "expected 136, is %d", + last_msg.msg.user_data.contents[92]); + ck_assert_msg(last_msg.msg.user_data.contents[93] == 231, + "incorrect value for last_msg.msg.user_data.contents[93], " + "expected 231, is %d", + last_msg.msg.user_data.contents[93]); + ck_assert_msg(last_msg.msg.user_data.contents[94] == 189, + "incorrect value for last_msg.msg.user_data.contents[94], " + "expected 189, is %d", + last_msg.msg.user_data.contents[94]); + ck_assert_msg(last_msg.msg.user_data.contents[95] == 26, + "incorrect value for last_msg.msg.user_data.contents[95], " + "expected 26, is %d", + last_msg.msg.user_data.contents[95]); + ck_assert_msg(last_msg.msg.user_data.contents[96] == 174, + "incorrect value for last_msg.msg.user_data.contents[96], " + "expected 174, is %d", + last_msg.msg.user_data.contents[96]); + ck_assert_msg(last_msg.msg.user_data.contents[97] == 128, + "incorrect value for last_msg.msg.user_data.contents[97], " + "expected 128, is %d", + last_msg.msg.user_data.contents[97]); + ck_assert_msg(last_msg.msg.user_data.contents[98] == 93, + "incorrect value for last_msg.msg.user_data.contents[98], " + "expected 93, is %d", + last_msg.msg.user_data.contents[98]); + ck_assert_msg(last_msg.msg.user_data.contents[99] == 30, + "incorrect value for last_msg.msg.user_data.contents[99], " + "expected 30, is %d", + last_msg.msg.user_data.contents[99]); + ck_assert_msg(last_msg.msg.user_data.contents[100] == 76, + "incorrect value for last_msg.msg.user_data.contents[100], " + "expected 76, is %d", + last_msg.msg.user_data.contents[100]); + ck_assert_msg(last_msg.msg.user_data.contents[101] == 45, + "incorrect value for last_msg.msg.user_data.contents[101], " + "expected 45, is %d", + last_msg.msg.user_data.contents[101]); + ck_assert_msg(last_msg.msg.user_data.contents[102] == 109, + "incorrect value for last_msg.msg.user_data.contents[102], " + "expected 109, is %d", + last_msg.msg.user_data.contents[102]); + ck_assert_msg(last_msg.msg.user_data.contents[103] == 134, + "incorrect value for last_msg.msg.user_data.contents[103], " + "expected 134, is %d", + last_msg.msg.user_data.contents[103]); + ck_assert_msg(last_msg.msg.user_data.contents[104] == 81, + "incorrect value for last_msg.msg.user_data.contents[104], " + "expected 81, is %d", + last_msg.msg.user_data.contents[104]); + ck_assert_msg(last_msg.msg.user_data.contents[105] == 0, + "incorrect value for last_msg.msg.user_data.contents[105], " + "expected 0, is %d", + last_msg.msg.user_data.contents[105]); + ck_assert_msg(last_msg.msg.user_data.contents[106] == 116, + "incorrect value for last_msg.msg.user_data.contents[106], " + "expected 116, is %d", + last_msg.msg.user_data.contents[106]); + ck_assert_msg(last_msg.msg.user_data.contents[107] == 158, + "incorrect value for last_msg.msg.user_data.contents[107], " + "expected 158, is %d", + last_msg.msg.user_data.contents[107]); + ck_assert_msg(last_msg.msg.user_data.contents[108] == 127, + "incorrect value for last_msg.msg.user_data.contents[108], " + "expected 127, is %d", + last_msg.msg.user_data.contents[108]); + ck_assert_msg(last_msg.msg.user_data.contents[109] == 40, + "incorrect value for last_msg.msg.user_data.contents[109], " + "expected 40, is %d", + last_msg.msg.user_data.contents[109]); + ck_assert_msg(last_msg.msg.user_data.contents[110] == 133, + "incorrect value for last_msg.msg.user_data.contents[110], " + "expected 133, is %d", + last_msg.msg.user_data.contents[110]); + ck_assert_msg(last_msg.msg.user_data.contents[111] == 208, + "incorrect value for last_msg.msg.user_data.contents[111], " + "expected 208, is %d", + last_msg.msg.user_data.contents[111]); + ck_assert_msg(last_msg.msg.user_data.contents[112] == 134, + "incorrect value for last_msg.msg.user_data.contents[112], " + "expected 134, is %d", + last_msg.msg.user_data.contents[112]); + ck_assert_msg(last_msg.msg.user_data.contents[113] == 127, + "incorrect value for last_msg.msg.user_data.contents[113], " + "expected 127, is %d", + last_msg.msg.user_data.contents[113]); + ck_assert_msg(last_msg.msg.user_data.contents[114] == 140, + "incorrect value for last_msg.msg.user_data.contents[114], " + "expected 140, is %d", + last_msg.msg.user_data.contents[114]); + ck_assert_msg(last_msg.msg.user_data.contents[115] == 232, + "incorrect value for last_msg.msg.user_data.contents[115], " + "expected 232, is %d", + last_msg.msg.user_data.contents[115]); + ck_assert_msg(last_msg.msg.user_data.contents[116] == 183, + "incorrect value for last_msg.msg.user_data.contents[116], " + "expected 183, is %d", + last_msg.msg.user_data.contents[116]); + ck_assert_msg(last_msg.msg.user_data.contents[117] == 184, + "incorrect value for last_msg.msg.user_data.contents[117], " + "expected 184, is %d", + last_msg.msg.user_data.contents[117]); + ck_assert_msg(last_msg.msg.user_data.contents[118] == 108, + "incorrect value for last_msg.msg.user_data.contents[118], " + "expected 108, is %d", + last_msg.msg.user_data.contents[118]); + ck_assert_msg(last_msg.msg.user_data.contents[119] == 6, + "incorrect value for last_msg.msg.user_data.contents[119], " + "expected 6, is %d", + last_msg.msg.user_data.contents[119]); + ck_assert_msg(last_msg.msg.user_data.contents[120] == 228, + "incorrect value for last_msg.msg.user_data.contents[120], " + "expected 228, is %d", + last_msg.msg.user_data.contents[120]); + ck_assert_msg(last_msg.msg.user_data.contents[121] == 54, + "incorrect value for last_msg.msg.user_data.contents[121], " + "expected 54, is %d", + last_msg.msg.user_data.contents[121]); + ck_assert_msg(last_msg.msg.user_data.contents[122] == 238, + "incorrect value for last_msg.msg.user_data.contents[122], " + "expected 238, is %d", + last_msg.msg.user_data.contents[122]); + ck_assert_msg(last_msg.msg.user_data.contents[123] == 59, + "incorrect value for last_msg.msg.user_data.contents[123], " + "expected 59, is %d", + last_msg.msg.user_data.contents[123]); + ck_assert_msg(last_msg.msg.user_data.contents[124] == 220, + "incorrect value for last_msg.msg.user_data.contents[124], " + "expected 220, is %d", + last_msg.msg.user_data.contents[124]); + ck_assert_msg(last_msg.msg.user_data.contents[125] == 30, + "incorrect value for last_msg.msg.user_data.contents[125], " + "expected 30, is %d", + last_msg.msg.user_data.contents[125]); + ck_assert_msg(last_msg.msg.user_data.contents[126] == 228, + "incorrect value for last_msg.msg.user_data.contents[126], " + "expected 228, is %d", + last_msg.msg.user_data.contents[126]); + ck_assert_msg(last_msg.msg.user_data.contents[127] == 212, + "incorrect value for last_msg.msg.user_data.contents[127], " + "expected 212, is %d", + last_msg.msg.user_data.contents[127]); + ck_assert_msg(last_msg.msg.user_data.contents[128] == 50, + "incorrect value for last_msg.msg.user_data.contents[128], " + "expected 50, is %d", + last_msg.msg.user_data.contents[128]); + ck_assert_msg(last_msg.msg.user_data.contents[129] == 182, + "incorrect value for last_msg.msg.user_data.contents[129], " + "expected 182, is %d", + last_msg.msg.user_data.contents[129]); + ck_assert_msg(last_msg.msg.user_data.contents[130] == 97, + "incorrect value for last_msg.msg.user_data.contents[130], " + "expected 97, is %d", + last_msg.msg.user_data.contents[130]); + ck_assert_msg(last_msg.msg.user_data.contents[131] == 20, + "incorrect value for last_msg.msg.user_data.contents[131], " + "expected 20, is %d", + last_msg.msg.user_data.contents[131]); + ck_assert_msg(last_msg.msg.user_data.contents[132] == 41, + "incorrect value for last_msg.msg.user_data.contents[132], " + "expected 41, is %d", + last_msg.msg.user_data.contents[132]); + ck_assert_msg(last_msg.msg.user_data.contents[133] == 76, + "incorrect value for last_msg.msg.user_data.contents[133], " + "expected 76, is %d", + last_msg.msg.user_data.contents[133]); + ck_assert_msg(last_msg.msg.user_data.contents[134] == 227, + "incorrect value for last_msg.msg.user_data.contents[134], " + "expected 227, is %d", + last_msg.msg.user_data.contents[134]); + ck_assert_msg(last_msg.msg.user_data.contents[135] == 88, + "incorrect value for last_msg.msg.user_data.contents[135], " + "expected 88, is %d", + last_msg.msg.user_data.contents[135]); + ck_assert_msg(last_msg.msg.user_data.contents[136] == 12, + "incorrect value for last_msg.msg.user_data.contents[136], " + "expected 12, is %d", + last_msg.msg.user_data.contents[136]); + ck_assert_msg(last_msg.msg.user_data.contents[137] == 95, + "incorrect value for last_msg.msg.user_data.contents[137], " + "expected 95, is %d", + last_msg.msg.user_data.contents[137]); + ck_assert_msg(last_msg.msg.user_data.contents[138] == 112, + "incorrect value for last_msg.msg.user_data.contents[138], " + "expected 112, is %d", + last_msg.msg.user_data.contents[138]); + ck_assert_msg(last_msg.msg.user_data.contents[139] == 209, + "incorrect value for last_msg.msg.user_data.contents[139], " + "expected 209, is %d", + last_msg.msg.user_data.contents[139]); + ck_assert_msg(last_msg.msg.user_data.contents[140] == 183, + "incorrect value for last_msg.msg.user_data.contents[140], " + "expected 183, is %d", + last_msg.msg.user_data.contents[140]); + ck_assert_msg(last_msg.msg.user_data.contents[141] == 127, + "incorrect value for last_msg.msg.user_data.contents[141], " + "expected 127, is %d", + last_msg.msg.user_data.contents[141]); + ck_assert_msg(last_msg.msg.user_data.contents[142] == 4, + "incorrect value for last_msg.msg.user_data.contents[142], " + "expected 4, is %d", + last_msg.msg.user_data.contents[142]); + ck_assert_msg(last_msg.msg.user_data.contents[143] == 165, + "incorrect value for last_msg.msg.user_data.contents[143], " + "expected 165, is %d", + last_msg.msg.user_data.contents[143]); + ck_assert_msg(last_msg.msg.user_data.contents[144] == 189, + "incorrect value for last_msg.msg.user_data.contents[144], " + "expected 189, is %d", + last_msg.msg.user_data.contents[144]); + ck_assert_msg(last_msg.msg.user_data.contents[145] == 44, + "incorrect value for last_msg.msg.user_data.contents[145], " + "expected 44, is %d", + last_msg.msg.user_data.contents[145]); + ck_assert_msg(last_msg.msg.user_data.contents[146] == 239, + "incorrect value for last_msg.msg.user_data.contents[146], " + "expected 239, is %d", + last_msg.msg.user_data.contents[146]); + ck_assert_msg(last_msg.msg.user_data.contents[147] == 232, + "incorrect value for last_msg.msg.user_data.contents[147], " + "expected 232, is %d", + last_msg.msg.user_data.contents[147]); + ck_assert_msg(last_msg.msg.user_data.contents[148] == 132, + "incorrect value for last_msg.msg.user_data.contents[148], " + "expected 132, is %d", + last_msg.msg.user_data.contents[148]); + ck_assert_msg(last_msg.msg.user_data.contents[149] == 9, + "incorrect value for last_msg.msg.user_data.contents[149], " + "expected 9, is %d", + last_msg.msg.user_data.contents[149]); + ck_assert_msg(last_msg.msg.user_data.contents[150] == 114, + "incorrect value for last_msg.msg.user_data.contents[150], " + "expected 114, is %d", + last_msg.msg.user_data.contents[150]); + ck_assert_msg(last_msg.msg.user_data.contents[151] == 184, + "incorrect value for last_msg.msg.user_data.contents[151], " + "expected 184, is %d", + last_msg.msg.user_data.contents[151]); + ck_assert_msg(last_msg.msg.user_data.contents[152] == 249, + "incorrect value for last_msg.msg.user_data.contents[152], " + "expected 249, is %d", + last_msg.msg.user_data.contents[152]); + ck_assert_msg(last_msg.msg.user_data.contents[153] == 208, + "incorrect value for last_msg.msg.user_data.contents[153], " + "expected 208, is %d", + last_msg.msg.user_data.contents[153]); + ck_assert_msg(last_msg.msg.user_data.contents[154] == 246, + "incorrect value for last_msg.msg.user_data.contents[154], " + "expected 246, is %d", + last_msg.msg.user_data.contents[154]); + ck_assert_msg(last_msg.msg.user_data.contents[155] == 194, + "incorrect value for last_msg.msg.user_data.contents[155], " + "expected 194, is %d", + last_msg.msg.user_data.contents[155]); + ck_assert_msg(last_msg.msg.user_data.contents[156] == 250, + "incorrect value for last_msg.msg.user_data.contents[156], " + "expected 250, is %d", + last_msg.msg.user_data.contents[156]); + ck_assert_msg(last_msg.msg.user_data.contents[157] == 2, + "incorrect value for last_msg.msg.user_data.contents[157], " + "expected 2, is %d", + last_msg.msg.user_data.contents[157]); + ck_assert_msg(last_msg.msg.user_data.contents[158] == 97, + "incorrect value for last_msg.msg.user_data.contents[158], " + "expected 97, is %d", + last_msg.msg.user_data.contents[158]); + ck_assert_msg(last_msg.msg.user_data.contents[159] == 173, + "incorrect value for last_msg.msg.user_data.contents[159], " + "expected 173, is %d", + last_msg.msg.user_data.contents[159]); + ck_assert_msg(last_msg.msg.user_data.contents[160] == 157, + "incorrect value for last_msg.msg.user_data.contents[160], " + "expected 157, is %d", + last_msg.msg.user_data.contents[160]); + ck_assert_msg(last_msg.msg.user_data.contents[161] == 202, + "incorrect value for last_msg.msg.user_data.contents[161], " + "expected 202, is %d", + last_msg.msg.user_data.contents[161]); + ck_assert_msg(last_msg.msg.user_data.contents[162] == 172, + "incorrect value for last_msg.msg.user_data.contents[162], " + "expected 172, is %d", + last_msg.msg.user_data.contents[162]); + ck_assert_msg(last_msg.msg.user_data.contents[163] == 180, + "incorrect value for last_msg.msg.user_data.contents[163], " + "expected 180, is %d", + last_msg.msg.user_data.contents[163]); + ck_assert_msg(last_msg.msg.user_data.contents[164] == 150, + "incorrect value for last_msg.msg.user_data.contents[164], " + "expected 150, is %d", + last_msg.msg.user_data.contents[164]); + ck_assert_msg(last_msg.msg.user_data.contents[165] == 213, + "incorrect value for last_msg.msg.user_data.contents[165], " + "expected 213, is %d", + last_msg.msg.user_data.contents[165]); + ck_assert_msg(last_msg.msg.user_data.contents[166] == 193, + "incorrect value for last_msg.msg.user_data.contents[166], " + "expected 193, is %d", + last_msg.msg.user_data.contents[166]); + ck_assert_msg(last_msg.msg.user_data.contents[167] == 177, + "incorrect value for last_msg.msg.user_data.contents[167], " + "expected 177, is %d", + last_msg.msg.user_data.contents[167]); + ck_assert_msg(last_msg.msg.user_data.contents[168] == 209, + "incorrect value for last_msg.msg.user_data.contents[168], " + "expected 209, is %d", + last_msg.msg.user_data.contents[168]); + ck_assert_msg(last_msg.msg.user_data.contents[169] == 156, + "incorrect value for last_msg.msg.user_data.contents[169], " + "expected 156, is %d", + last_msg.msg.user_data.contents[169]); + ck_assert_msg(last_msg.msg.user_data.contents[170] == 20, + "incorrect value for last_msg.msg.user_data.contents[170], " + "expected 20, is %d", + last_msg.msg.user_data.contents[170]); + ck_assert_msg(last_msg.msg.user_data.contents[171] == 174, + "incorrect value for last_msg.msg.user_data.contents[171], " + "expected 174, is %d", + last_msg.msg.user_data.contents[171]); + ck_assert_msg(last_msg.msg.user_data.contents[172] == 18, + "incorrect value for last_msg.msg.user_data.contents[172], " + "expected 18, is %d", + last_msg.msg.user_data.contents[172]); + ck_assert_msg(last_msg.msg.user_data.contents[173] == 73, + "incorrect value for last_msg.msg.user_data.contents[173], " + "expected 73, is %d", + last_msg.msg.user_data.contents[173]); + ck_assert_msg(last_msg.msg.user_data.contents[174] == 132, + "incorrect value for last_msg.msg.user_data.contents[174], " + "expected 132, is %d", + last_msg.msg.user_data.contents[174]); + ck_assert_msg(last_msg.msg.user_data.contents[175] == 215, + "incorrect value for last_msg.msg.user_data.contents[175], " + "expected 215, is %d", + last_msg.msg.user_data.contents[175]); + ck_assert_msg(last_msg.msg.user_data.contents[176] == 115, + "incorrect value for last_msg.msg.user_data.contents[176], " + "expected 115, is %d", + last_msg.msg.user_data.contents[176]); + ck_assert_msg(last_msg.msg.user_data.contents[177] == 128, + "incorrect value for last_msg.msg.user_data.contents[177], " + "expected 128, is %d", + last_msg.msg.user_data.contents[177]); + ck_assert_msg(last_msg.msg.user_data.contents[178] == 175, + "incorrect value for last_msg.msg.user_data.contents[178], " + "expected 175, is %d", + last_msg.msg.user_data.contents[178]); + ck_assert_msg(last_msg.msg.user_data.contents[179] == 169, + "incorrect value for last_msg.msg.user_data.contents[179], " + "expected 169, is %d", + last_msg.msg.user_data.contents[179]); + ck_assert_msg(last_msg.msg.user_data.contents[180] == 116, + "incorrect value for last_msg.msg.user_data.contents[180], " + "expected 116, is %d", + last_msg.msg.user_data.contents[180]); + ck_assert_msg(last_msg.msg.user_data.contents[181] == 132, + "incorrect value for last_msg.msg.user_data.contents[181], " + "expected 132, is %d", + last_msg.msg.user_data.contents[181]); + ck_assert_msg(last_msg.msg.user_data.contents[182] == 100, + "incorrect value for last_msg.msg.user_data.contents[182], " + "expected 100, is %d", + last_msg.msg.user_data.contents[182]); + ck_assert_msg(last_msg.msg.user_data.contents[183] == 72, + "incorrect value for last_msg.msg.user_data.contents[183], " + "expected 72, is %d", + last_msg.msg.user_data.contents[183]); + ck_assert_msg(last_msg.msg.user_data.contents[184] == 45, + "incorrect value for last_msg.msg.user_data.contents[184], " + "expected 45, is %d", + last_msg.msg.user_data.contents[184]); + ck_assert_msg(last_msg.msg.user_data.contents[185] == 25, + "incorrect value for last_msg.msg.user_data.contents[185], " + "expected 25, is %d", + last_msg.msg.user_data.contents[185]); + ck_assert_msg(last_msg.msg.user_data.contents[186] == 14, + "incorrect value for last_msg.msg.user_data.contents[186], " + "expected 14, is %d", + last_msg.msg.user_data.contents[186]); + ck_assert_msg(last_msg.msg.user_data.contents[187] == 205, + "incorrect value for last_msg.msg.user_data.contents[187], " + "expected 205, is %d", + last_msg.msg.user_data.contents[187]); + ck_assert_msg(last_msg.msg.user_data.contents[188] == 213, + "incorrect value for last_msg.msg.user_data.contents[188], " + "expected 213, is %d", + last_msg.msg.user_data.contents[188]); + ck_assert_msg(last_msg.msg.user_data.contents[189] == 145, + "incorrect value for last_msg.msg.user_data.contents[189], " + "expected 145, is %d", + last_msg.msg.user_data.contents[189]); + ck_assert_msg(last_msg.msg.user_data.contents[190] == 68, + "incorrect value for last_msg.msg.user_data.contents[190], " + "expected 68, is %d", + last_msg.msg.user_data.contents[190]); + ck_assert_msg(last_msg.msg.user_data.contents[191] == 137, + "incorrect value for last_msg.msg.user_data.contents[191], " + "expected 137, is %d", + last_msg.msg.user_data.contents[191]); + ck_assert_msg(last_msg.msg.user_data.contents[192] == 249, + "incorrect value for last_msg.msg.user_data.contents[192], " + "expected 249, is %d", + last_msg.msg.user_data.contents[192]); + ck_assert_msg(last_msg.msg.user_data.contents[193] == 54, + "incorrect value for last_msg.msg.user_data.contents[193], " + "expected 54, is %d", + last_msg.msg.user_data.contents[193]); + ck_assert_msg(last_msg.msg.user_data.contents[194] == 40, + "incorrect value for last_msg.msg.user_data.contents[194], " + "expected 40, is %d", + last_msg.msg.user_data.contents[194]); + ck_assert_msg(last_msg.msg.user_data.contents[195] == 174, + "incorrect value for last_msg.msg.user_data.contents[195], " + "expected 174, is %d", + last_msg.msg.user_data.contents[195]); + ck_assert_msg(last_msg.msg.user_data.contents[196] == 215, + "incorrect value for last_msg.msg.user_data.contents[196], " + "expected 215, is %d", + last_msg.msg.user_data.contents[196]); + ck_assert_msg(last_msg.msg.user_data.contents[197] == 148, + "incorrect value for last_msg.msg.user_data.contents[197], " + "expected 148, is %d", + last_msg.msg.user_data.contents[197]); + ck_assert_msg(last_msg.msg.user_data.contents[198] == 166, + "incorrect value for last_msg.msg.user_data.contents[198], " + "expected 166, is %d", + last_msg.msg.user_data.contents[198]); + ck_assert_msg(last_msg.msg.user_data.contents[199] == 190, + "incorrect value for last_msg.msg.user_data.contents[199], " + "expected 190, is %d", + last_msg.msg.user_data.contents[199]); + ck_assert_msg(last_msg.msg.user_data.contents[200] == 63, + "incorrect value for last_msg.msg.user_data.contents[200], " + "expected 63, is %d", + last_msg.msg.user_data.contents[200]); + ck_assert_msg(last_msg.msg.user_data.contents[201] == 118, + "incorrect value for last_msg.msg.user_data.contents[201], " + "expected 118, is %d", + last_msg.msg.user_data.contents[201]); + ck_assert_msg(last_msg.msg.user_data.contents[202] == 6, + "incorrect value for last_msg.msg.user_data.contents[202], " + "expected 6, is %d", + last_msg.msg.user_data.contents[202]); + ck_assert_msg(last_msg.msg.user_data.contents[203] == 165, + "incorrect value for last_msg.msg.user_data.contents[203], " + "expected 165, is %d", + last_msg.msg.user_data.contents[203]); + ck_assert_msg(last_msg.msg.user_data.contents[204] == 212, + "incorrect value for last_msg.msg.user_data.contents[204], " + "expected 212, is %d", + last_msg.msg.user_data.contents[204]); + ck_assert_msg(last_msg.msg.user_data.contents[205] == 74, + "incorrect value for last_msg.msg.user_data.contents[205], " + "expected 74, is %d", + last_msg.msg.user_data.contents[205]); + ck_assert_msg(last_msg.msg.user_data.contents[206] == 68, + "incorrect value for last_msg.msg.user_data.contents[206], " + "expected 68, is %d", + last_msg.msg.user_data.contents[206]); + ck_assert_msg(last_msg.msg.user_data.contents[207] == 200, + "incorrect value for last_msg.msg.user_data.contents[207], " + "expected 200, is %d", + last_msg.msg.user_data.contents[207]); + ck_assert_msg(last_msg.msg.user_data.contents[208] == 38, + "incorrect value for last_msg.msg.user_data.contents[208], " + "expected 38, is %d", + last_msg.msg.user_data.contents[208]); + ck_assert_msg(last_msg.msg.user_data.contents[209] == 139, + "incorrect value for last_msg.msg.user_data.contents[209], " + "expected 139, is %d", + last_msg.msg.user_data.contents[209]); + ck_assert_msg(last_msg.msg.user_data.contents[210] == 212, + "incorrect value for last_msg.msg.user_data.contents[210], " + "expected 212, is %d", + last_msg.msg.user_data.contents[210]); + ck_assert_msg(last_msg.msg.user_data.contents[211] == 112, + "incorrect value for last_msg.msg.user_data.contents[211], " + "expected 112, is %d", + last_msg.msg.user_data.contents[211]); + ck_assert_msg(last_msg.msg.user_data.contents[212] == 45, + "incorrect value for last_msg.msg.user_data.contents[212], " + "expected 45, is %d", + last_msg.msg.user_data.contents[212]); + ck_assert_msg(last_msg.msg.user_data.contents[213] == 167, + "incorrect value for last_msg.msg.user_data.contents[213], " + "expected 167, is %d", + last_msg.msg.user_data.contents[213]); + ck_assert_msg(last_msg.msg.user_data.contents[214] == 236, + "incorrect value for last_msg.msg.user_data.contents[214], " + "expected 236, is %d", + last_msg.msg.user_data.contents[214]); + ck_assert_msg(last_msg.msg.user_data.contents[215] == 255, + "incorrect value for last_msg.msg.user_data.contents[215], " + "expected 255, is %d", + last_msg.msg.user_data.contents[215]); + ck_assert_msg(last_msg.msg.user_data.contents[216] == 106, + "incorrect value for last_msg.msg.user_data.contents[216], " + "expected 106, is %d", + last_msg.msg.user_data.contents[216]); + ck_assert_msg(last_msg.msg.user_data.contents[217] == 92, + "incorrect value for last_msg.msg.user_data.contents[217], " + "expected 92, is %d", + last_msg.msg.user_data.contents[217]); + ck_assert_msg(last_msg.msg.user_data.contents[218] == 132, + "incorrect value for last_msg.msg.user_data.contents[218], " + "expected 132, is %d", + last_msg.msg.user_data.contents[218]); + ck_assert_msg(last_msg.msg.user_data.contents[219] == 59, + "incorrect value for last_msg.msg.user_data.contents[219], " + "expected 59, is %d", + last_msg.msg.user_data.contents[219]); + ck_assert_msg(last_msg.msg.user_data.contents[220] == 61, + "incorrect value for last_msg.msg.user_data.contents[220], " + "expected 61, is %d", + last_msg.msg.user_data.contents[220]); + ck_assert_msg(last_msg.msg.user_data.contents[221] == 233, + "incorrect value for last_msg.msg.user_data.contents[221], " + "expected 233, is %d", + last_msg.msg.user_data.contents[221]); + ck_assert_msg(last_msg.msg.user_data.contents[222] == 3, + "incorrect value for last_msg.msg.user_data.contents[222], " + "expected 3, is %d", + last_msg.msg.user_data.contents[222]); + ck_assert_msg(last_msg.msg.user_data.contents[223] == 246, + "incorrect value for last_msg.msg.user_data.contents[223], " + "expected 246, is %d", + last_msg.msg.user_data.contents[223]); + ck_assert_msg(last_msg.msg.user_data.contents[224] == 158, + "incorrect value for last_msg.msg.user_data.contents[224], " + "expected 158, is %d", + last_msg.msg.user_data.contents[224]); + ck_assert_msg(last_msg.msg.user_data.contents[225] == 83, + "incorrect value for last_msg.msg.user_data.contents[225], " + "expected 83, is %d", + last_msg.msg.user_data.contents[225]); + ck_assert_msg(last_msg.msg.user_data.contents[226] == 134, + "incorrect value for last_msg.msg.user_data.contents[226], " + "expected 134, is %d", + last_msg.msg.user_data.contents[226]); + ck_assert_msg(last_msg.msg.user_data.contents[227] == 246, + "incorrect value for last_msg.msg.user_data.contents[227], " + "expected 246, is %d", + last_msg.msg.user_data.contents[227]); + ck_assert_msg(last_msg.msg.user_data.contents[228] == 154, + "incorrect value for last_msg.msg.user_data.contents[228], " + "expected 154, is %d", + last_msg.msg.user_data.contents[228]); + ck_assert_msg(last_msg.msg.user_data.contents[229] == 17, + "incorrect value for last_msg.msg.user_data.contents[229], " + "expected 17, is %d", + last_msg.msg.user_data.contents[229]); + ck_assert_msg(last_msg.msg.user_data.contents[230] == 0, + "incorrect value for last_msg.msg.user_data.contents[230], " + "expected 0, is %d", + last_msg.msg.user_data.contents[230]); + ck_assert_msg(last_msg.msg.user_data.contents[231] == 6, + "incorrect value for last_msg.msg.user_data.contents[231], " + "expected 6, is %d", + last_msg.msg.user_data.contents[231]); + ck_assert_msg(last_msg.msg.user_data.contents[232] == 56, + "incorrect value for last_msg.msg.user_data.contents[232], " + "expected 56, is %d", + last_msg.msg.user_data.contents[232]); + ck_assert_msg(last_msg.msg.user_data.contents[233] == 216, + "incorrect value for last_msg.msg.user_data.contents[233], " + "expected 216, is %d", + last_msg.msg.user_data.contents[233]); + ck_assert_msg(last_msg.msg.user_data.contents[234] == 19, + "incorrect value for last_msg.msg.user_data.contents[234], " + "expected 19, is %d", + last_msg.msg.user_data.contents[234]); + ck_assert_msg(last_msg.msg.user_data.contents[235] == 216, + "incorrect value for last_msg.msg.user_data.contents[235], " + "expected 216, is %d", + last_msg.msg.user_data.contents[235]); + ck_assert_msg(last_msg.msg.user_data.contents[236] == 70, + "incorrect value for last_msg.msg.user_data.contents[236], " + "expected 70, is %d", + last_msg.msg.user_data.contents[236]); + ck_assert_msg(last_msg.msg.user_data.contents[237] == 71, + "incorrect value for last_msg.msg.user_data.contents[237], " + "expected 71, is %d", + last_msg.msg.user_data.contents[237]); + ck_assert_msg(last_msg.msg.user_data.contents[238] == 161, + "incorrect value for last_msg.msg.user_data.contents[238], " + "expected 161, is %d", + last_msg.msg.user_data.contents[238]); + ck_assert_msg(last_msg.msg.user_data.contents[239] == 184, + "incorrect value for last_msg.msg.user_data.contents[239], " + "expected 184, is %d", + last_msg.msg.user_data.contents[239]); + ck_assert_msg(last_msg.msg.user_data.contents[240] == 5, + "incorrect value for last_msg.msg.user_data.contents[240], " + "expected 5, is %d", + last_msg.msg.user_data.contents[240]); + ck_assert_msg(last_msg.msg.user_data.contents[241] == 177, + "incorrect value for last_msg.msg.user_data.contents[241], " + "expected 177, is %d", + last_msg.msg.user_data.contents[241]); + ck_assert_msg(last_msg.msg.user_data.contents[242] == 45, + "incorrect value for last_msg.msg.user_data.contents[242], " + "expected 45, is %d", + last_msg.msg.user_data.contents[242]); + ck_assert_msg(last_msg.msg.user_data.contents[243] == 37, + "incorrect value for last_msg.msg.user_data.contents[243], " + "expected 37, is %d", + last_msg.msg.user_data.contents[243]); + ck_assert_msg(last_msg.msg.user_data.contents[244] == 98, + "incorrect value for last_msg.msg.user_data.contents[244], " + "expected 98, is %d", + last_msg.msg.user_data.contents[244]); + ck_assert_msg(last_msg.msg.user_data.contents[245] == 56, + "incorrect value for last_msg.msg.user_data.contents[245], " + "expected 56, is %d", + last_msg.msg.user_data.contents[245]); + ck_assert_msg(last_msg.msg.user_data.contents[246] == 149, + "incorrect value for last_msg.msg.user_data.contents[246], " + "expected 149, is %d", + last_msg.msg.user_data.contents[246]); + ck_assert_msg(last_msg.msg.user_data.contents[247] == 0, + "incorrect value for last_msg.msg.user_data.contents[247], " + "expected 0, is %d", + last_msg.msg.user_data.contents[247]); + ck_assert_msg(last_msg.msg.user_data.contents[248] == 73, + "incorrect value for last_msg.msg.user_data.contents[248], " + "expected 73, is %d", + last_msg.msg.user_data.contents[248]); + ck_assert_msg(last_msg.msg.user_data.contents[249] == 221, + "incorrect value for last_msg.msg.user_data.contents[249], " + "expected 221, is %d", + last_msg.msg.user_data.contents[249]); + ck_assert_msg(last_msg.msg.user_data.contents[250] == 105, + "incorrect value for last_msg.msg.user_data.contents[250], " + "expected 105, is %d", + last_msg.msg.user_data.contents[250]); + ck_assert_msg(last_msg.msg.user_data.contents[251] == 239, + "incorrect value for last_msg.msg.user_data.contents[251], " + "expected 239, is %d", + last_msg.msg.user_data.contents[251]); + ck_assert_msg(last_msg.msg.user_data.contents[252] == 168, + "incorrect value for last_msg.msg.user_data.contents[252], " + "expected 168, is %d", + last_msg.msg.user_data.contents[252]); + ck_assert_msg(last_msg.msg.user_data.contents[253] == 205, + "incorrect value for last_msg.msg.user_data.contents[253], " + "expected 205, is %d", + last_msg.msg.user_data.contents[253]); + ck_assert_msg(last_msg.msg.user_data.contents[254] == 85, + "incorrect value for last_msg.msg.user_data.contents[254], " + "expected 85, is %d", + last_msg.msg.user_data.contents[254]); + + ck_assert_msg(last_msg.msg.user_data.n_contents == 255, + "incorrect value for last_msg.msg.user_data.n_contents, " + "expected 255, is %d", + last_msg.msg.user_data.n_contents); + } +} +END_TEST + +Suite *auto_check_sbp_user_MsgUserData_suite(void) { + Suite *s = + suite_create("SBP generated test suite: auto_check_sbp_user_MsgUserData"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_user_MsgUserData"); + tcase_add_test(tc_acq, test_auto_check_sbp_user_MsgUserData); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/auto_check_sbp_vehicle_MsgWheeltick.c b/c/test/auto_check_sbp_vehicle_MsgWheeltick.c new file mode 100644 index 0000000000..4e5f93becc --- /dev/null +++ b/c/test/auto_check_sbp_vehicle_MsgWheeltick.c @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + sbp_msg_type_t msg_type; + sbp_msg_t msg; + void *context; +} last_msg; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static void *DUMMY_MEMORY_FOR_CALLBACKS = (void *)0xdeadbeef; +static void *DUMMY_MEMORY_FOR_IO = (void *)0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return (s32)real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return (s32)real_n; +} + +static void logging_reset() { memset(&last_msg, 0, sizeof(last_msg)); } + +static void msg_callback(u16 sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.msg_type = msg_type; + last_msg.msg = *msg; + last_msg.context = context; +} + +START_TEST(test_auto_check_sbp_vehicle_MsgWheeltick) { + static sbp_msg_callbacks_node_t n; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_callback_register(&sbp_state, 0x904, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + + u8 encoded_frame[] = { + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, + 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + }; + + dummy_reset(); + + sbp_msg_t test_msg; + memset(&test_msg, 0, sizeof(test_msg)); + + test_msg.wheeltick.flags = 1; + + test_msg.wheeltick.source = 146; + + test_msg.wheeltick.ticks = -771148831; + + test_msg.wheeltick.time = 112414825470; + + sbp_message_send(&sbp_state, SbpMsgWheeltick, 17771, &test_msg, + &dummy_write); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff (expected: %zu, " + "actual: %zu)", + sizeof(encoded_frame), dummy_wr); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 17771, + "msg_callback: sender_id decoded incorrectly"); + + ck_assert_msg( + sbp_message_cmp(SbpMsgWheeltick, &last_msg.msg, &test_msg) == 0, + "Sent and received messages did not compare equal"); + + ck_assert_msg( + last_msg.msg.wheeltick.flags == 1, + "incorrect value for last_msg.msg.wheeltick.flags, expected 1, is %d", + last_msg.msg.wheeltick.flags); + + ck_assert_msg(last_msg.msg.wheeltick.source == 146, + "incorrect value for last_msg.msg.wheeltick.source, expected " + "146, is %d", + last_msg.msg.wheeltick.source); + + ck_assert_msg(last_msg.msg.wheeltick.ticks == -771148831, + "incorrect value for last_msg.msg.wheeltick.ticks, expected " + "-771148831, is %d", + last_msg.msg.wheeltick.ticks); + + ck_assert_msg(last_msg.msg.wheeltick.time == 112414825470, + "incorrect value for last_msg.msg.wheeltick.time, expected " + "112414825470, is %d", + last_msg.msg.wheeltick.time); + } +} +END_TEST + +Suite *auto_check_sbp_vehicle_MsgWheeltick_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: auto_check_sbp_vehicle_MsgWheeltick"); + TCase *tc_acq = + tcase_create("Automated_Suite_auto_check_sbp_vehicle_MsgWheeltick"); + tcase_add_test(tc_acq, test_auto_check_sbp_vehicle_MsgWheeltick); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/check_main.c b/c/test/check_main.c index 68a6885a4f..b063512969 100644 --- a/c/test/check_main.c +++ b/c/test/check_main.c @@ -25,13 +25,38 @@ int main(void) { srunner_add_suite(sr, bitfield_macros_suite()); // auto-generated tests: + srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqResult_suite()); srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqResultDepA_suite()); srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqResultDepB_suite()); srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqResultDepC_suite()); + srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqSvProfile_suite()); + srunner_add_suite(sr, auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite()); + srunner_add_suite(sr, + auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite()); srunner_add_suite(sr, auto_check_sbp_bootload_MsgBootloaderHandshakeResp_suite()); + srunner_add_suite(sr, auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite()); + srunner_add_suite(sr, auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite()); + srunner_add_suite(sr, auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite()); srunner_add_suite(sr, auto_check_sbp_ext_events_MsgExtEvent_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioConfigReq_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioConfigResp_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioReadDirReq_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioReadDirResp_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioReadReq_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioReadResp_suite()); + srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioRemove_suite()); srunner_add_suite(sr, auto_check_sbp_file_io_MsgFileioWriteResp_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgFlashDone_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgFlashErase_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgFlashProgram_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgFlashReadReq_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgFlashReadResp_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgM25FlashWriteStatus_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgStmFlashLockSector_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgStmFlashUnlockSector_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgStmUniqueIdReq_suite()); + srunner_add_suite(sr, auto_check_sbp_flash_MsgStmUniqueIdResp_suite()); srunner_add_suite(sr, auto_check_sbp_imu_MsgImuAux_suite()); srunner_add_suite(sr, auto_check_sbp_imu_MsgImuRaw_suite()); srunner_add_suite(sr, auto_check_sbp_integrity_MsgAcknowledge_suite()); @@ -45,12 +70,28 @@ int main(void) { srunner_add_suite(sr, auto_check_sbp_integrity_MsgSsrFlagSatellites_suite()); srunner_add_suite(sr, auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxCpuState_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxMemState_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxMemStateDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxProcessFdCount_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite()); + srunner_add_suite(sr, + auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite()); + srunner_add_suite(sr, + auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxSocketUsage_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxSysState_suite()); + srunner_add_suite(sr, auto_check_sbp_linux_MsgLinuxSysStateDepA_suite()); srunner_add_suite(sr, auto_check_sbp_logging_MsgFwd_suite()); srunner_add_suite(sr, auto_check_sbp_logging_MsgLog_suite()); srunner_add_suite(sr, auto_check_sbp_logging_MsgPrintDep_suite()); + srunner_add_suite(sr, auto_check_sbp_mag_MsgMagRaw_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgAgeCorrections_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgBaselineECEF_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgBaselineECEFDepA_suite()); + srunner_add_suite(sr, + auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgBaselineNED_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgBaselineNEDDepA_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgDops_suite()); @@ -66,10 +107,13 @@ int main(void) { srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLLH_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLLHCov_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLLHDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLlhAcc_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLlhCovGnss_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgPosLlhGnss_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgPoseRelative_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgProtectionLevel_suite()); + srunner_add_suite(sr, + auto_check_sbp_navigation_MsgProtectionLevelDepA_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgReferenceFrameParam_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgUTCLeapSecond_suite()); @@ -87,34 +131,92 @@ int main(void) { srunner_add_suite(sr, auto_check_sbp_navigation_MsgVelNEDDepA_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgVelNedCovGnss_suite()); srunner_add_suite(sr, auto_check_sbp_navigation_MsgVelNedGnss_suite()); + srunner_add_suite(sr, auto_check_sbp_ndb_MsgNdbEvent_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgAlmanacGLO_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgAlmanacGLODep_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgAlmanacGPS_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgAlmanacGPSDep_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgBasePosEcef_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgBasePosLLH_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisBds_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisDepC_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisDepD_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGLO_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGLODepA_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGLODepB_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGLODepC_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGLODepD_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGPS_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGPSDepE_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGPSDepF_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGal_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisGalDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgEphemerisSbas_suite()); + srunner_add_suite(sr, + auto_check_sbp_observation_MsgEphemerisSbasDepA_suite()); + srunner_add_suite(sr, + auto_check_sbp_observation_MsgEphemerisSbasDepB_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgGloBiases_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgGnssCapb_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgGroupDelay_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgGroupDelayDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgGroupDelayDepB_suite()); + srunner_add_suite(sr, auto_check_sbp_observation_MsgIono_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgObs_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgObsDepB_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgObsDepC_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgOsr_suite()); srunner_add_suite(sr, auto_check_sbp_observation_MsgSvAzEl_suite()); + srunner_add_suite( + sr, auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite()); srunner_add_suite(sr, auto_check_sbp_observation_msgEphemerisDepB_suite()); srunner_add_suite(sr, auto_check_sbp_observation_msgEphemerisQzss_suite()); srunner_add_suite(sr, auto_check_sbp_observation_msgObsDepA_suite()); srunner_add_suite(sr, auto_check_sbp_orientation_MsgAngularRate_suite()); + srunner_add_suite(sr, auto_check_sbp_orientation_MsgBaselineHeading_suite()); srunner_add_suite(sr, auto_check_sbp_orientation_MsgOrientEuler_suite()); srunner_add_suite(sr, auto_check_sbp_orientation_MsgOrientQuat_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgAlmanac_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCellModemStatus_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCommandOutput_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCommandReq_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCommandResp_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCwResults_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgCwStart_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgDeviceMonitor_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgFrontEndGain_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgIarState_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgInitBaseDep_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgMaskSatellite_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgMaskSatelliteDep_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgNetworkBandwidthUsage_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgNetworkStateReq_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgNetworkStateResp_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgReset_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgResetDep_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgResetFilters_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgSetTime_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgSpecan_suite()); + srunner_add_suite(sr, auto_check_sbp_piksi_MsgSpecanDep_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgThreadState_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgUartState_suite()); srunner_add_suite(sr, auto_check_sbp_piksi_MsgUartStateDepA_suite()); srunner_add_suite(sr, auto_check_sbp_sbas_MsgSbasRaw_suite()); srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsReadByIndexDone_suite()); + srunner_add_suite(sr, + auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite()); srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsReadByIndexResp_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsReadReq_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsReadResp_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsRegister_suite()); + srunner_add_suite(sr, + auto_check_sbp_settings_MsgSettingsRegisterResp_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsSave_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsWrite_suite()); + srunner_add_suite(sr, auto_check_sbp_settings_MsgSettingsWriteResp_suite()); srunner_add_suite(sr, auto_check_sbp_signing_MsgCertificateChain_suite()); srunner_add_suite(sr, auto_check_sbp_signing_MsgCertificateChainDep_suite()); srunner_add_suite(sr, auto_check_sbp_signing_MsgEcdsaCertificate_suite()); @@ -125,31 +227,59 @@ int main(void) { auto_check_sbp_signing_MsgEd25519CertificateDep_suite()); srunner_add_suite(sr, auto_check_sbp_signing_MsgEd25519SignatureDepA_suite()); srunner_add_suite(sr, auto_check_sbp_signing_MsgEd25519SignatureDepB_suite()); + srunner_add_suite(sr, auto_check_sbp_solution_meta_MsgSolnMeta_suite()); + srunner_add_suite(sr, auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrCodeBiases_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite()); + srunner_add_suite( + sr, auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrOrbitClock_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrOrbitClockBounds_suite()); srunner_add_suite( sr, auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrPhaseBiases_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrSatelliteApc_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrStecCorrection_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrTileDefinition_suite()); + srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite()); srunner_add_suite(sr, auto_check_sbp_ssr_MsgSsrTileDefinitionDepB_suite()); + srunner_add_suite(sr, auto_check_sbp_system_MsgCsacTelemetry_suite()); + srunner_add_suite(sr, auto_check_sbp_system_MsgCsacTelemetryLabels_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgDgnssStatus_suite()); + srunner_add_suite(sr, auto_check_sbp_system_MsgGnssTimeOffset_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgGroupMeta_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgHeartbeat_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgInsStatus_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgInsUpdates_suite()); + srunner_add_suite(sr, auto_check_sbp_system_MsgPpsTime_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgSensorAidEvent_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgStartup_suite()); srunner_add_suite(sr, auto_check_sbp_system_MsgStatusJournal_suite()); + srunner_add_suite(sr, auto_check_sbp_system_MsgStatusReport_suite()); srunner_add_suite(sr, auto_check_sbp_telemetry_MsgTelSv_suite()); srunner_add_suite(sr, auto_check_sbp_tracking_MsgMeasurementState_suite()); + srunner_add_suite(sr, auto_check_sbp_tracking_MsgTrackingIq_suite()); + srunner_add_suite(sr, auto_check_sbp_tracking_MsgTrackingIqDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_tracking_MsgTrackingIqDepB_suite()); srunner_add_suite(sr, auto_check_sbp_tracking_MsgTrackingState_suite()); + srunner_add_suite(sr, auto_check_sbp_tracking_MsgTrackingStateDepB_suite()); srunner_add_suite( sr, auto_check_sbp_tracking_MsgTrackingStateDetailedDep_suite()); + srunner_add_suite( + sr, auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite()); srunner_add_suite(sr, auto_check_sbp_tracking_MsgtrackingStateDepA_suite()); + srunner_add_suite(sr, auto_check_sbp_user_MsgUserData_suite()); srunner_add_suite(sr, auto_check_sbp_vehicle_MsgOdometry_suite()); + srunner_add_suite(sr, auto_check_sbp_vehicle_MsgWheeltick_suite()); srunner_set_fork_status(sr, CK_NOFORK); srunner_run_all(sr, CK_NORMAL); diff --git a/c/test/check_main_legacy.c b/c/test/check_main_legacy.c index 08c7edda8b..f4fb8360da 100644 --- a/c/test/check_main_legacy.c +++ b/c/test/check_main_legacy.c @@ -25,17 +25,55 @@ int main(void) { srunner_add_suite(sr, bitfield_macros_suite()); // auto-generated tests: + srunner_add_suite(sr, legacy_auto_check_sbp_acquisition_MsgAcqResult_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_acquisition_MsgAcqResultDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_acquisition_MsgAcqResultDepB_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_acquisition_MsgAcqResultDepC_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_acquisition_MsgAcqSvProfile_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeResp_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ext_events_MsgExtEvent_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_file_io_MsgFileioConfigReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_file_io_MsgFileioConfigResp_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_file_io_MsgFileioReadDirReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_file_io_MsgFileioReadDirResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_file_io_MsgFileioReadReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_file_io_MsgFileioReadResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_file_io_MsgFileioRemove_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_file_io_MsgFileioWriteResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgFlashDone_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgFlashErase_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgFlashProgram_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgFlashReadReq_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgFlashReadResp_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_flash_MsgStmFlashLockSector_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgStmUniqueIdReq_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_flash_MsgStmUniqueIdResp_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_imu_MsgImuAux_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_imu_MsgImuRaw_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_integrity_MsgAcknowledge_suite()); @@ -52,15 +90,37 @@ int main(void) { sr, legacy_auto_check_sbp_integrity_MsgSsrFlagSatellites_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_linux_MsgLinuxCpuState_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_linux_MsgLinuxMemState_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_linux_MsgLinuxSocketUsage_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_linux_MsgLinuxSysState_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_logging_MsgFwd_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_logging_MsgLog_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_logging_MsgPrintDep_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_mag_MsgMagRaw_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgAgeCorrections_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgBaselineECEF_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_navigation_MsgBaselineECEFDepA_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgBaselineNED_suite()); srunner_add_suite( @@ -83,6 +143,7 @@ int main(void) { srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLLH_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLLHCov_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLLHDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLlhAcc_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLlhCovGnss_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgPosLlhGnss_suite()); @@ -90,6 +151,8 @@ int main(void) { legacy_auto_check_sbp_navigation_MsgPoseRelative_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_navigation_MsgProtectionLevel_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_navigation_MsgReferenceFrameParam_suite()); srunner_add_suite(sr, @@ -113,22 +176,69 @@ int main(void) { srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgVelNedCovGnss_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_navigation_MsgVelNedGnss_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_ndb_MsgNdbEvent_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgAlmanacGLO_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgAlmanacGLODep_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgAlmanacGPS_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgAlmanacGPSDep_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgBasePosEcef_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgBasePosLLH_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgEphemerisBds_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgEphemerisDepA_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgEphemerisDepC_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgEphemerisDepD_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgEphemerisGLO_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGLODepA_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGLODepB_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGLODepC_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGLODepD_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgEphemerisGPS_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgEphemerisGal_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisGalDepA_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgEphemerisSbas_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgGloBiases_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgGnssCapb_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_observation_MsgGroupDelay_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgGroupDelayDepA_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgGroupDelayDepB_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgIono_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgObs_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgObsDepB_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgObsDepC_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgOsr_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_MsgSvAzEl_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_observation_msgEphemerisDepB_suite()); srunner_add_suite(sr, @@ -136,22 +246,60 @@ int main(void) { srunner_add_suite(sr, legacy_auto_check_sbp_observation_msgObsDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_orientation_MsgAngularRate_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_orientation_MsgBaselineHeading_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_orientation_MsgOrientEuler_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_orientation_MsgOrientQuat_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgAlmanac_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCellModemStatus_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCommandOutput_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCommandReq_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCommandResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCwResults_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgCwStart_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgDeviceMonitor_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgFrontEndGain_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgIarState_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgInitBaseDep_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgMaskSatellite_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_piksi_MsgNetworkBandwidthUsage_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgNetworkStateReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_piksi_MsgNetworkStateResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgReset_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgResetDep_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgResetFilters_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgSetTime_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgSpecan_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgSpecanDep_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgThreadState_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgUartState_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_piksi_MsgUartStateDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_sbas_MsgSbasRaw_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_settings_MsgSettingsReadByIndexDone_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_settings_MsgSettingsReadByIndexResp_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_settings_MsgSettingsReadReq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_settings_MsgSettingsReadResp_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_settings_MsgSettingsRegister_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_settings_MsgSettingsRegisterResp_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_settings_MsgSettingsSave_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_settings_MsgSettingsWrite_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_settings_MsgSettingsWriteResp_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_signing_MsgCertificateChain_suite()); srunner_add_suite( @@ -170,37 +318,78 @@ int main(void) { sr, legacy_auto_check_sbp_signing_MsgEd25519SignatureDepA_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_signing_MsgEd25519SignatureDepB_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_solution_meta_MsgSolnMeta_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrCodeBiases_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrOrbitClock_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrOrbitClockBounds_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrSatelliteApc_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrStecCorrection_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrTileDefinition_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepB_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgCsacTelemetry_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_system_MsgCsacTelemetryLabels_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgDgnssStatus_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgGnssTimeOffset_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgGroupMeta_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgHeartbeat_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgInsStatus_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgInsUpdates_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgPpsTime_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgSensorAidEvent_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgStartup_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgStatusJournal_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_system_MsgStatusReport_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_telemetry_MsgTelSv_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_tracking_MsgMeasurementState_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_tracking_MsgTrackingIq_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_tracking_MsgTrackingIqDepA_suite()); + srunner_add_suite(sr, + legacy_auto_check_sbp_tracking_MsgTrackingIqDepB_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_tracking_MsgTrackingState_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_tracking_MsgTrackingStateDepB_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDep_suite()); + srunner_add_suite( + sr, legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite()); srunner_add_suite( sr, legacy_auto_check_sbp_tracking_MsgtrackingStateDepA_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_user_MsgUserData_suite()); srunner_add_suite(sr, legacy_auto_check_sbp_vehicle_MsgOdometry_suite()); + srunner_add_suite(sr, legacy_auto_check_sbp_vehicle_MsgWheeltick_suite()); srunner_set_fork_status(sr, CK_NOFORK); srunner_run_all(sr, CK_NORMAL); diff --git a/c/test/check_suites.h b/c/test/check_suites.h index b7d0f28c07..46ab46b4da 100644 --- a/c/test/check_suites.h +++ b/c/test/check_suites.h @@ -18,12 +18,36 @@ Suite* edc_suite(void); Suite* sbp_suite(void); Suite* bitfield_macros_suite(void); +Suite* auto_check_sbp_acquisition_MsgAcqResult_suite(void); Suite* auto_check_sbp_acquisition_MsgAcqResultDepA_suite(void); Suite* auto_check_sbp_acquisition_MsgAcqResultDepB_suite(void); Suite* auto_check_sbp_acquisition_MsgAcqResultDepC_suite(void); +Suite* auto_check_sbp_acquisition_MsgAcqSvProfile_suite(void); +Suite* auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite(void); +Suite* auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite(void); Suite* auto_check_sbp_bootload_MsgBootloaderHandshakeResp_suite(void); +Suite* auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite(void); +Suite* auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite(void); +Suite* auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite(void); Suite* auto_check_sbp_ext_events_MsgExtEvent_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioConfigReq_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioConfigResp_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioReadDirReq_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioReadDirResp_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioReadReq_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioReadResp_suite(void); +Suite* auto_check_sbp_file_io_MsgFileioRemove_suite(void); Suite* auto_check_sbp_file_io_MsgFileioWriteResp_suite(void); +Suite* auto_check_sbp_flash_MsgFlashDone_suite(void); +Suite* auto_check_sbp_flash_MsgFlashErase_suite(void); +Suite* auto_check_sbp_flash_MsgFlashProgram_suite(void); +Suite* auto_check_sbp_flash_MsgFlashReadReq_suite(void); +Suite* auto_check_sbp_flash_MsgFlashReadResp_suite(void); +Suite* auto_check_sbp_flash_MsgM25FlashWriteStatus_suite(void); +Suite* auto_check_sbp_flash_MsgStmFlashLockSector_suite(void); +Suite* auto_check_sbp_flash_MsgStmFlashUnlockSector_suite(void); +Suite* auto_check_sbp_flash_MsgStmUniqueIdReq_suite(void); +Suite* auto_check_sbp_flash_MsgStmUniqueIdResp_suite(void); Suite* auto_check_sbp_imu_MsgImuAux_suite(void); Suite* auto_check_sbp_imu_MsgImuRaw_suite(void); Suite* auto_check_sbp_integrity_MsgAcknowledge_suite(void); @@ -33,12 +57,25 @@ Suite* auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints_suite(void); Suite* auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos_suite(void); Suite* auto_check_sbp_integrity_MsgSsrFlagSatellites_suite(void); Suite* auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxCpuState_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxMemState_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxMemStateDepA_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxProcessFdCount_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxSocketUsage_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxSysState_suite(void); +Suite* auto_check_sbp_linux_MsgLinuxSysStateDepA_suite(void); Suite* auto_check_sbp_logging_MsgFwd_suite(void); Suite* auto_check_sbp_logging_MsgLog_suite(void); Suite* auto_check_sbp_logging_MsgPrintDep_suite(void); +Suite* auto_check_sbp_mag_MsgMagRaw_suite(void); Suite* auto_check_sbp_navigation_MsgAgeCorrections_suite(void); Suite* auto_check_sbp_navigation_MsgBaselineECEF_suite(void); Suite* auto_check_sbp_navigation_MsgBaselineECEFDepA_suite(void); +Suite* auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite(void); Suite* auto_check_sbp_navigation_MsgBaselineNED_suite(void); Suite* auto_check_sbp_navigation_MsgBaselineNEDDepA_suite(void); Suite* auto_check_sbp_navigation_MsgDops_suite(void); @@ -54,10 +91,12 @@ Suite* auto_check_sbp_navigation_MsgPosECEFGNSS_suite(void); Suite* auto_check_sbp_navigation_MsgPosLLH_suite(void); Suite* auto_check_sbp_navigation_MsgPosLLHCov_suite(void); Suite* auto_check_sbp_navigation_MsgPosLLHDepA_suite(void); +Suite* auto_check_sbp_navigation_MsgPosLlhAcc_suite(void); Suite* auto_check_sbp_navigation_MsgPosLlhCovGnss_suite(void); Suite* auto_check_sbp_navigation_MsgPosLlhGnss_suite(void); Suite* auto_check_sbp_navigation_MsgPoseRelative_suite(void); Suite* auto_check_sbp_navigation_MsgProtectionLevel_suite(void); +Suite* auto_check_sbp_navigation_MsgProtectionLevelDepA_suite(void); Suite* auto_check_sbp_navigation_MsgReferenceFrameParam_suite(void); Suite* auto_check_sbp_navigation_MsgUTCLeapSecond_suite(void); Suite* auto_check_sbp_navigation_MsgUTCTime_suite(void); @@ -74,32 +113,85 @@ Suite* auto_check_sbp_navigation_MsgVelNEDCOV_suite(void); Suite* auto_check_sbp_navigation_MsgVelNEDDepA_suite(void); Suite* auto_check_sbp_navigation_MsgVelNedCovGnss_suite(void); Suite* auto_check_sbp_navigation_MsgVelNedGnss_suite(void); +Suite* auto_check_sbp_ndb_MsgNdbEvent_suite(void); +Suite* auto_check_sbp_observation_MsgAlmanacGLO_suite(void); +Suite* auto_check_sbp_observation_MsgAlmanacGLODep_suite(void); +Suite* auto_check_sbp_observation_MsgAlmanacGPS_suite(void); +Suite* auto_check_sbp_observation_MsgAlmanacGPSDep_suite(void); Suite* auto_check_sbp_observation_MsgBasePosEcef_suite(void); +Suite* auto_check_sbp_observation_MsgBasePosLLH_suite(void); Suite* auto_check_sbp_observation_MsgEphemerisBds_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisDepA_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisDepC_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisDepD_suite(void); Suite* auto_check_sbp_observation_MsgEphemerisGLO_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGLODepA_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGLODepB_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGLODepC_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGLODepD_suite(void); Suite* auto_check_sbp_observation_MsgEphemerisGPS_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGPSDepE_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGPSDepF_suite(void); Suite* auto_check_sbp_observation_MsgEphemerisGal_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisGalDepA_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisSbas_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisSbasDepA_suite(void); +Suite* auto_check_sbp_observation_MsgEphemerisSbasDepB_suite(void); Suite* auto_check_sbp_observation_MsgGloBiases_suite(void); +Suite* auto_check_sbp_observation_MsgGnssCapb_suite(void); +Suite* auto_check_sbp_observation_MsgGroupDelay_suite(void); +Suite* auto_check_sbp_observation_MsgGroupDelayDepA_suite(void); +Suite* auto_check_sbp_observation_MsgGroupDelayDepB_suite(void); +Suite* auto_check_sbp_observation_MsgIono_suite(void); Suite* auto_check_sbp_observation_MsgObs_suite(void); Suite* auto_check_sbp_observation_MsgObsDepB_suite(void); Suite* auto_check_sbp_observation_MsgObsDepC_suite(void); Suite* auto_check_sbp_observation_MsgOsr_suite(void); Suite* auto_check_sbp_observation_MsgSvAzEl_suite(void); +Suite* auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite(void); Suite* auto_check_sbp_observation_msgEphemerisDepB_suite(void); Suite* auto_check_sbp_observation_msgEphemerisQzss_suite(void); Suite* auto_check_sbp_observation_msgObsDepA_suite(void); Suite* auto_check_sbp_orientation_MsgAngularRate_suite(void); +Suite* auto_check_sbp_orientation_MsgBaselineHeading_suite(void); Suite* auto_check_sbp_orientation_MsgOrientEuler_suite(void); Suite* auto_check_sbp_orientation_MsgOrientQuat_suite(void); +Suite* auto_check_sbp_piksi_MsgAlmanac_suite(void); +Suite* auto_check_sbp_piksi_MsgCellModemStatus_suite(void); +Suite* auto_check_sbp_piksi_MsgCommandOutput_suite(void); +Suite* auto_check_sbp_piksi_MsgCommandReq_suite(void); +Suite* auto_check_sbp_piksi_MsgCommandResp_suite(void); +Suite* auto_check_sbp_piksi_MsgCwResults_suite(void); +Suite* auto_check_sbp_piksi_MsgCwStart_suite(void); Suite* auto_check_sbp_piksi_MsgDeviceMonitor_suite(void); +Suite* auto_check_sbp_piksi_MsgFrontEndGain_suite(void); Suite* auto_check_sbp_piksi_MsgIarState_suite(void); +Suite* auto_check_sbp_piksi_MsgInitBaseDep_suite(void); +Suite* auto_check_sbp_piksi_MsgMaskSatellite_suite(void); +Suite* auto_check_sbp_piksi_MsgMaskSatelliteDep_suite(void); Suite* auto_check_sbp_piksi_MsgNetworkBandwidthUsage_suite(void); +Suite* auto_check_sbp_piksi_MsgNetworkStateReq_suite(void); +Suite* auto_check_sbp_piksi_MsgNetworkStateResp_suite(void); +Suite* auto_check_sbp_piksi_MsgReset_suite(void); +Suite* auto_check_sbp_piksi_MsgResetDep_suite(void); +Suite* auto_check_sbp_piksi_MsgResetFilters_suite(void); +Suite* auto_check_sbp_piksi_MsgSetTime_suite(void); +Suite* auto_check_sbp_piksi_MsgSpecan_suite(void); +Suite* auto_check_sbp_piksi_MsgSpecanDep_suite(void); Suite* auto_check_sbp_piksi_MsgThreadState_suite(void); Suite* auto_check_sbp_piksi_MsgUartState_suite(void); Suite* auto_check_sbp_piksi_MsgUartStateDepA_suite(void); Suite* auto_check_sbp_sbas_MsgSbasRaw_suite(void); Suite* auto_check_sbp_settings_MsgSettingsReadByIndexDone_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite(void); Suite* auto_check_sbp_settings_MsgSettingsReadByIndexResp_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsReadReq_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsReadResp_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsRegister_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsRegisterResp_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsSave_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsWrite_suite(void); +Suite* auto_check_sbp_settings_MsgSettingsWriteResp_suite(void); Suite* auto_check_sbp_signing_MsgCertificateChain_suite(void); Suite* auto_check_sbp_signing_MsgCertificateChainDep_suite(void); Suite* auto_check_sbp_signing_MsgEcdsaCertificate_suite(void); @@ -109,27 +201,53 @@ Suite* auto_check_sbp_signing_MsgEcdsaSignatureDepB_suite(void); Suite* auto_check_sbp_signing_MsgEd25519CertificateDep_suite(void); Suite* auto_check_sbp_signing_MsgEd25519SignatureDepA_suite(void); Suite* auto_check_sbp_signing_MsgEd25519SignatureDepB_suite(void); +Suite* auto_check_sbp_solution_meta_MsgSolnMeta_suite(void); +Suite* auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrCodeBiases_suite(void); Suite* auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite(void); Suite* auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrOrbitClock_suite(void); Suite* auto_check_sbp_ssr_MsgSsrOrbitClockBounds_suite(void); Suite* auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrPhaseBiases_suite(void); Suite* auto_check_sbp_ssr_MsgSsrSatelliteApc_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite(void); Suite* auto_check_sbp_ssr_MsgSsrStecCorrection_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite(void); Suite* auto_check_sbp_ssr_MsgSsrTileDefinition_suite(void); +Suite* auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite(void); Suite* auto_check_sbp_ssr_MsgSsrTileDefinitionDepB_suite(void); +Suite* auto_check_sbp_system_MsgCsacTelemetry_suite(void); +Suite* auto_check_sbp_system_MsgCsacTelemetryLabels_suite(void); Suite* auto_check_sbp_system_MsgDgnssStatus_suite(void); +Suite* auto_check_sbp_system_MsgGnssTimeOffset_suite(void); Suite* auto_check_sbp_system_MsgGroupMeta_suite(void); Suite* auto_check_sbp_system_MsgHeartbeat_suite(void); Suite* auto_check_sbp_system_MsgInsStatus_suite(void); Suite* auto_check_sbp_system_MsgInsUpdates_suite(void); +Suite* auto_check_sbp_system_MsgPpsTime_suite(void); Suite* auto_check_sbp_system_MsgSensorAidEvent_suite(void); Suite* auto_check_sbp_system_MsgStartup_suite(void); Suite* auto_check_sbp_system_MsgStatusJournal_suite(void); +Suite* auto_check_sbp_system_MsgStatusReport_suite(void); Suite* auto_check_sbp_telemetry_MsgTelSv_suite(void); Suite* auto_check_sbp_tracking_MsgMeasurementState_suite(void); +Suite* auto_check_sbp_tracking_MsgTrackingIq_suite(void); +Suite* auto_check_sbp_tracking_MsgTrackingIqDepA_suite(void); +Suite* auto_check_sbp_tracking_MsgTrackingIqDepB_suite(void); Suite* auto_check_sbp_tracking_MsgTrackingState_suite(void); +Suite* auto_check_sbp_tracking_MsgTrackingStateDepB_suite(void); Suite* auto_check_sbp_tracking_MsgTrackingStateDetailedDep_suite(void); +Suite* auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite(void); Suite* auto_check_sbp_tracking_MsgtrackingStateDepA_suite(void); +Suite* auto_check_sbp_user_MsgUserData_suite(void); Suite* auto_check_sbp_vehicle_MsgOdometry_suite(void); +Suite* auto_check_sbp_vehicle_MsgWheeltick_suite(void); #endif /* CHECK_SUITES_H */ \ No newline at end of file diff --git a/c/test/check_suites_legacy.h b/c/test/check_suites_legacy.h index 10254c99e1..6e091a8f5c 100644 --- a/c/test/check_suites_legacy.h +++ b/c/test/check_suites_legacy.h @@ -18,12 +18,36 @@ Suite* edc_suite(void); Suite* sbp_suite(void); Suite* bitfield_macros_suite(void); +Suite* legacy_auto_check_sbp_acquisition_MsgAcqResult_suite(void); Suite* legacy_auto_check_sbp_acquisition_MsgAcqResultDepA_suite(void); Suite* legacy_auto_check_sbp_acquisition_MsgAcqResultDepB_suite(void); Suite* legacy_auto_check_sbp_acquisition_MsgAcqResultDepC_suite(void); +Suite* legacy_auto_check_sbp_acquisition_MsgAcqSvProfile_suite(void); +Suite* legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite(void); +Suite* legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite(void); Suite* legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeResp_suite(void); +Suite* legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite(void); +Suite* legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite(void); +Suite* legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite(void); Suite* legacy_auto_check_sbp_ext_events_MsgExtEvent_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioConfigReq_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioConfigResp_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioReadDirReq_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioReadDirResp_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioReadReq_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioReadResp_suite(void); +Suite* legacy_auto_check_sbp_file_io_MsgFileioRemove_suite(void); Suite* legacy_auto_check_sbp_file_io_MsgFileioWriteResp_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgFlashDone_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgFlashErase_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgFlashProgram_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgFlashReadReq_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgFlashReadResp_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgStmFlashLockSector_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgStmUniqueIdReq_suite(void); +Suite* legacy_auto_check_sbp_flash_MsgStmUniqueIdResp_suite(void); Suite* legacy_auto_check_sbp_imu_MsgImuAux_suite(void); Suite* legacy_auto_check_sbp_imu_MsgImuRaw_suite(void); Suite* legacy_auto_check_sbp_integrity_MsgAcknowledge_suite(void); @@ -34,12 +58,25 @@ Suite* legacy_auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints_suite(void); Suite* legacy_auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos_suite(void); Suite* legacy_auto_check_sbp_integrity_MsgSsrFlagSatellites_suite(void); Suite* legacy_auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxCpuState_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxMemState_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxSocketUsage_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxSysState_suite(void); +Suite* legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA_suite(void); Suite* legacy_auto_check_sbp_logging_MsgFwd_suite(void); Suite* legacy_auto_check_sbp_logging_MsgLog_suite(void); Suite* legacy_auto_check_sbp_logging_MsgPrintDep_suite(void); +Suite* legacy_auto_check_sbp_mag_MsgMagRaw_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgAgeCorrections_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgBaselineECEF_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgBaselineECEFDepA_suite(void); +Suite* legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgBaselineNED_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgBaselineNEDDepA_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgDops_suite(void); @@ -55,10 +92,12 @@ Suite* legacy_auto_check_sbp_navigation_MsgPosECEFGNSS_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPosLLH_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPosLLHCov_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPosLLHDepA_suite(void); +Suite* legacy_auto_check_sbp_navigation_MsgPosLlhAcc_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPosLlhCovGnss_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPosLlhGnss_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgPoseRelative_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgProtectionLevel_suite(void); +Suite* legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgReferenceFrameParam_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgUTCLeapSecond_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgUTCTime_suite(void); @@ -75,32 +114,85 @@ Suite* legacy_auto_check_sbp_navigation_MsgVelNEDCOV_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgVelNEDDepA_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgVelNedCovGnss_suite(void); Suite* legacy_auto_check_sbp_navigation_MsgVelNedGnss_suite(void); +Suite* legacy_auto_check_sbp_ndb_MsgNdbEvent_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgAlmanacGLO_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgAlmanacGLODep_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgAlmanacGPS_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgAlmanacGPSDep_suite(void); Suite* legacy_auto_check_sbp_observation_MsgBasePosEcef_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgBasePosLLH_suite(void); Suite* legacy_auto_check_sbp_observation_MsgEphemerisBds_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisDepA_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisDepC_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisDepD_suite(void); Suite* legacy_auto_check_sbp_observation_MsgEphemerisGLO_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGLODepA_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGLODepB_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGLODepC_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGLODepD_suite(void); Suite* legacy_auto_check_sbp_observation_MsgEphemerisGPS_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF_suite(void); Suite* legacy_auto_check_sbp_observation_MsgEphemerisGal_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisGalDepA_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisSbas_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB_suite(void); Suite* legacy_auto_check_sbp_observation_MsgGloBiases_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgGnssCapb_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgGroupDelay_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgGroupDelayDepA_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgGroupDelayDepB_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgIono_suite(void); Suite* legacy_auto_check_sbp_observation_MsgObs_suite(void); Suite* legacy_auto_check_sbp_observation_MsgObsDepB_suite(void); Suite* legacy_auto_check_sbp_observation_MsgObsDepC_suite(void); Suite* legacy_auto_check_sbp_observation_MsgOsr_suite(void); Suite* legacy_auto_check_sbp_observation_MsgSvAzEl_suite(void); +Suite* legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite(void); Suite* legacy_auto_check_sbp_observation_msgEphemerisDepB_suite(void); Suite* legacy_auto_check_sbp_observation_msgEphemerisQzss_suite(void); Suite* legacy_auto_check_sbp_observation_msgObsDepA_suite(void); Suite* legacy_auto_check_sbp_orientation_MsgAngularRate_suite(void); +Suite* legacy_auto_check_sbp_orientation_MsgBaselineHeading_suite(void); Suite* legacy_auto_check_sbp_orientation_MsgOrientEuler_suite(void); Suite* legacy_auto_check_sbp_orientation_MsgOrientQuat_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgAlmanac_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCellModemStatus_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCommandOutput_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCommandReq_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCommandResp_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCwResults_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgCwStart_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgDeviceMonitor_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgFrontEndGain_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgIarState_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgInitBaseDep_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgMaskSatellite_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgNetworkBandwidthUsage_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgNetworkStateReq_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgNetworkStateResp_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgReset_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgResetDep_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgResetFilters_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgSetTime_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgSpecan_suite(void); +Suite* legacy_auto_check_sbp_piksi_MsgSpecanDep_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgThreadState_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgUartState_suite(void); Suite* legacy_auto_check_sbp_piksi_MsgUartStateDepA_suite(void); Suite* legacy_auto_check_sbp_sbas_MsgSbasRaw_suite(void); Suite* legacy_auto_check_sbp_settings_MsgSettingsReadByIndexDone_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite(void); Suite* legacy_auto_check_sbp_settings_MsgSettingsReadByIndexResp_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsReadReq_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsReadResp_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsRegister_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsRegisterResp_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsSave_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsWrite_suite(void); +Suite* legacy_auto_check_sbp_settings_MsgSettingsWriteResp_suite(void); Suite* legacy_auto_check_sbp_signing_MsgCertificateChain_suite(void); Suite* legacy_auto_check_sbp_signing_MsgCertificateChainDep_suite(void); Suite* legacy_auto_check_sbp_signing_MsgEcdsaCertificate_suite(void); @@ -110,27 +202,53 @@ Suite* legacy_auto_check_sbp_signing_MsgEcdsaSignatureDepB_suite(void); Suite* legacy_auto_check_sbp_signing_MsgEd25519CertificateDep_suite(void); Suite* legacy_auto_check_sbp_signing_MsgEd25519SignatureDepA_suite(void); Suite* legacy_auto_check_sbp_signing_MsgEd25519SignatureDepB_suite(void); +Suite* legacy_auto_check_sbp_solution_meta_MsgSolnMeta_suite(void); +Suite* legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrCodeBiases_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrOrbitClock_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrOrbitClockBounds_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrSatelliteApc_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrStecCorrection_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrTileDefinition_suite(void); +Suite* legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite(void); Suite* legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepB_suite(void); +Suite* legacy_auto_check_sbp_system_MsgCsacTelemetry_suite(void); +Suite* legacy_auto_check_sbp_system_MsgCsacTelemetryLabels_suite(void); Suite* legacy_auto_check_sbp_system_MsgDgnssStatus_suite(void); +Suite* legacy_auto_check_sbp_system_MsgGnssTimeOffset_suite(void); Suite* legacy_auto_check_sbp_system_MsgGroupMeta_suite(void); Suite* legacy_auto_check_sbp_system_MsgHeartbeat_suite(void); Suite* legacy_auto_check_sbp_system_MsgInsStatus_suite(void); Suite* legacy_auto_check_sbp_system_MsgInsUpdates_suite(void); +Suite* legacy_auto_check_sbp_system_MsgPpsTime_suite(void); Suite* legacy_auto_check_sbp_system_MsgSensorAidEvent_suite(void); Suite* legacy_auto_check_sbp_system_MsgStartup_suite(void); Suite* legacy_auto_check_sbp_system_MsgStatusJournal_suite(void); +Suite* legacy_auto_check_sbp_system_MsgStatusReport_suite(void); Suite* legacy_auto_check_sbp_telemetry_MsgTelSv_suite(void); Suite* legacy_auto_check_sbp_tracking_MsgMeasurementState_suite(void); +Suite* legacy_auto_check_sbp_tracking_MsgTrackingIq_suite(void); +Suite* legacy_auto_check_sbp_tracking_MsgTrackingIqDepA_suite(void); +Suite* legacy_auto_check_sbp_tracking_MsgTrackingIqDepB_suite(void); Suite* legacy_auto_check_sbp_tracking_MsgTrackingState_suite(void); +Suite* legacy_auto_check_sbp_tracking_MsgTrackingStateDepB_suite(void); Suite* legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDep_suite(void); +Suite* legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite(void); Suite* legacy_auto_check_sbp_tracking_MsgtrackingStateDepA_suite(void); +Suite* legacy_auto_check_sbp_user_MsgUserData_suite(void); Suite* legacy_auto_check_sbp_vehicle_MsgOdometry_suite(void); +Suite* legacy_auto_check_sbp_vehicle_MsgWheeltick_suite(void); #endif /* CHECK_SUITES_H */ \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc new file mode 100644 index 0000000000..26c8df00d2 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc @@ -0,0 +1,800 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqResult0 : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResult0() { + assign(test_msg_.cf, 8241.2001953125); + assign(test_msg_.cn0, 14.5); + assign(test_msg_.cp, 72.19999694824219); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.sat, 8); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResult, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResult); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result, sizeof(msg->acq_result)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResult); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xbdcf; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_t &lesser, + const sbp_msg_acq_result_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResult, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResult, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResult, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResult, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, + 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, 189, + }; + uint8_t encoded_payload_[14] = { + 0, 0, 104, 65, 102, 102, 144, 66, 205, 196, 0, 70, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAcqResult, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResult, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_acq_result_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_acq_result_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResult, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_acq_result_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResult, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResult, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResult, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_t lesser = info.test_msg; + sbp_msg_acq_result_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_t lesser = info.test_msg; + sbp_msg_acq_result_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_t lesser = info.test_msg; + sbp_msg_acq_result_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_t lesser = info.test_msg; + sbp_msg_acq_result_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_t lesser = info.test_msg; + sbp_msg_acq_result_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgAcqResult); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.acq_result, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResult, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResult0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResult, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepA.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepA.cc index 8e4297648d..245e098e8d 100644 --- a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepA.cc +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepA.cc @@ -16,551 +16,4694 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqResultDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepA0() { + assign(test_msg_.cf, 8241.943359375); + assign(test_msg_.cp, 727.0); + assign(test_msg_.prn, 8); + assign(test_msg_.snr, 14.5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4402; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { + 85, 21, 0, 195, 4, 13, 0, 0, 104, 65, 0, + 192, 53, 68, 198, 199, 0, 70, 8, 2, 68, + }; + uint8_t encoded_payload_[13] = { + 0, 0, 104, 65, 0, 192, 53, 68, 198, 199, 0, 70, 8, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepA1 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepA1() { + assign(test_msg_.cf, 749.2676391601562); + assign(test_msg_.cp, 359.5); + assign(test_msg_.prn, 9); + assign(test_msg_.snr, 15.300000190734863); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x1bdb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { + 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, + 192, 179, 67, 33, 81, 59, 68, 9, 219, 27, + }; + uint8_t encoded_payload_[13] = { + 205, 204, 116, 65, 0, 192, 179, 67, 33, 81, 59, 68, 9, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepA2 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepA2() { + assign(test_msg_.cf, -6493.65283203125); + assign(test_msg_.cp, 40.5); + assign(test_msg_.prn, 11); + assign(test_msg_.snr, 18.100000381469727); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x2396; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { + 85, 21, 0, 195, 4, 13, 205, 204, 144, 65, 0, + 0, 34, 66, 57, 237, 202, 197, 11, 150, 35, + }; + uint8_t encoded_payload_[13] = { + 205, 204, 144, 65, 0, 0, 34, 66, 57, 237, 202, 197, 11, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepA3 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepA3() { + assign(test_msg_.cf, -999.0234985351562); + assign(test_msg_.cp, 548.5); + assign(test_msg_.prn, 12); + assign(test_msg_.snr, 15.300000190734863); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x7692; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { + 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, + 32, 9, 68, 129, 193, 121, 196, 12, 146, 118, + }; + uint8_t encoded_payload_[13] = { + 205, 204, 116, 65, 0, 32, 9, 68, 129, 193, 121, 196, 12, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepA4 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepA4() { + assign(test_msg_.cf, 4745.361328125); + assign(test_msg_.cp, 780.5); + assign(test_msg_.prn, 14); + assign(test_msg_.snr, 15.300000190734863); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4b17; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { + 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, + 32, 67, 68, 228, 74, 148, 69, 14, 23, 75, + }; + uint8_t encoded_payload_[13] = { + 205, 204, 116, 65, 0, 32, 67, 68, 228, 74, 148, 69, 14, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 21, 0, 195, 4, 13, 0, 0, 104, 65, 0, - 192, 53, 68, 198, 199, 0, 70, 8, 2, 68, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = 8241.943359375; - test_msg.cp = 727.0; - test_msg.prn = 8; - test_msg.snr = 14.5; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 8241.94335938 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 8241.94335938, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 727.0 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 727.0, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 8) - << "incorrect value for last_msg_.prn, expected 8, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 14.5 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 14.5, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, - 192, 179, 67, 33, 81, 59, 68, 9, 219, 27, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = 749.2676391601562; - test_msg.cp = 359.5; - test_msg.prn = 9; - test_msg.snr = 15.300000190734863; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 749.26763916 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 749.26763916, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 359.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 359.5, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 9) - << "incorrect value for last_msg_.prn, expected 9, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 15.3000001907 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 15.3000001907, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 21, 0, 195, 4, 13, 205, 204, 144, 65, 0, - 0, 34, 66, 57, 237, 202, 197, 11, 150, 35, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = -6493.65283203125; - test_msg.cp = 40.5; - test_msg.prn = 11; - test_msg.snr = 18.100000381469727; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -6493.65283203 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -6493.65283203, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 40.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 40.5, is " << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 11) - << "incorrect value for last_msg_.prn, expected 11, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 18.1000003815 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 18.1000003815, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepA5 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepA5() { + assign(test_msg_.cf, -499.5117492675781); + assign(test_msg_.cp, 584.5); + assign(test_msg_.prn, 0); + assign(test_msg_.snr, 163.22222900390625); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, - 32, 9, 68, 129, 193, 121, 196, 12, 146, 118, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = -999.0234985351562; - test_msg.cp = 548.5; - test_msg.prn = 12; - test_msg.snr = 15.300000190734863; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -999.023498535 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -999.023498535, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 548.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 548.5, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 12) - << "incorrect value for last_msg_.prn, expected 12, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 15.3000001907 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 15.3000001907, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 21, 0, 195, 4, 13, 205, 204, 116, 65, 0, - 32, 67, 68, 228, 74, 148, 69, 14, 23, 75, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = 4745.361328125; - test_msg.cp = 780.5; - test_msg.prn = 14; - test_msg.snr = 15.300000190734863; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 4745.36132812 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 4745.36132812, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 780.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 780.5, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 14) - << "incorrect value for last_msg_.prn, expected 14, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 15.3000001907 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 15.3000001907, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_a, + sizeof(msg->acq_result_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xcfcc; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 13; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_acq_result_dep_a_t &lesser, + const sbp_msg_acq_result_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepA5, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_a_t test_msg_{}; + uint8_t encoded_frame_[13 + 8] = { 85, 21, 0, 195, 4, 13, 228, 56, 35, 67, 0, 32, 18, 68, 129, 193, 249, 195, 0, 204, 207, }; + uint8_t encoded_payload_[13] = { + 228, 56, 35, 67, 0, 32, 18, 68, 129, 193, 249, 195, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_acq_result_dep_a_t test_msg{}; - test_msg.cf = -499.5117492675781; - test_msg.cp = 584.5; - test_msg.prn = 0; - test_msg.snr = 163.22222900390625; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_a_t lesser = info.test_msg; + sbp_msg_acq_result_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_A"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[13]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 13), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 13); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + sbp::State state{}; + state.set_reader(&reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -499.511749268 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -499.511749268, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 584.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 584.5, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.prn, 0) - << "incorrect value for last_msg_.prn, expected 0, is " << last_msg_.prn; - EXPECT_LT((last_msg_.snr * 100 - 163.222229004 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 163.222229004, is " - << last_msg_.snr; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepB.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepB.cc index 975902b063..5557a24801 100644 --- a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepB.cc +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepB.cc @@ -16,506 +16,3984 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_acquisition_MsgAcqResultDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqResultDepB0 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepB0() { + assign(test_msg_.cf, 4995.1171875); + assign(test_msg_.cp, 322.0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 9); + assign(test_msg_.snr, 36.66360855102539); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_b, + sizeof(msg->acq_result_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xc350; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_b_t &lesser, + const sbp_msg_acq_result_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_b_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 20, 0, 246, 215, 16, 137, 167, 18, 66, 0, 0, + 161, 67, 240, 24, 156, 69, 9, 0, 0, 0, 80, 195, + }; + uint8_t encoded_payload_[16] = { + 137, 167, 18, 66, 0, 0, 161, 67, 240, 24, 156, 69, 9, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_B"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepB1 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepB1() { + assign(test_msg_.cf, -8241.943359375); + assign(test_msg_.cp, 843.0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 3); + assign(test_msg_.snr, 36.16875457763672); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_b, + sizeof(msg->acq_result_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8f95; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_b_t &lesser, + const sbp_msg_acq_result_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_b_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 20, 0, 246, 215, 16, 206, 172, 16, 66, 0, 192, + 82, 68, 198, 199, 0, 198, 3, 0, 0, 0, 149, 143, + }; + uint8_t encoded_payload_[16] = { + 206, 172, 16, 66, 0, 192, 82, 68, 198, 199, 0, 198, 3, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_B"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepB2 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepB2() { + assign(test_msg_.cf, 4745.361328125); + assign(test_msg_.cp, 794.0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 18); + assign(test_msg_.snr, 35.77723693847656); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_b, + sizeof(msg->acq_result_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x9bb3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_b_t &lesser, + const sbp_msg_acq_result_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_b_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 20, 0, 246, 215, 16, 228, 27, 15, 66, 0, 128, + 70, 68, 228, 74, 148, 69, 18, 0, 0, 0, 179, 155, + }; + uint8_t encoded_payload_[16] = { + 228, 27, 15, 66, 0, 128, 70, 68, 228, 74, 148, 69, 18, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_B"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepB3 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepB3() { + assign(test_msg_.cf, 2497.55859375); + assign(test_msg_.cp, 258.5); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 17); + assign(test_msg_.snr, 35.69451141357422); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_b, + sizeof(msg->acq_result_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xb512; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_b_t &lesser, + const sbp_msg_acq_result_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_b_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 20, 0, 246, 215, 16, 46, 199, 14, 66, 0, 64, + 129, 67, 240, 24, 28, 69, 17, 0, 0, 0, 18, 181, + }; + uint8_t encoded_payload_[16] = { + 46, 199, 14, 66, 0, 64, 129, 67, 240, 24, 28, 69, 17, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_B"); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepB0, Test) { - uint8_t encoded_frame[] = { - 85, 20, 0, 246, 215, 16, 137, 167, 18, 66, 0, 0, - 161, 67, 240, 24, 156, 69, 9, 0, 0, 0, 80, 195, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_acq_result_dep_b_t test_msg{}; - test_msg.cf = 4995.1171875; - test_msg.cp = 322.0; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 9; - test_msg.snr = 36.66360855102539; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 4995.1171875 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 4995.1171875, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 322.0 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 322.0, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 9) - << "incorrect value for last_msg_.sid.sat, expected 9, is " - << last_msg_.sid.sat; - EXPECT_LT((last_msg_.snr * 100 - 36.663608551 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 36.663608551, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepB1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepB1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepB1, Test) { - uint8_t encoded_frame[] = { - 85, 20, 0, 246, 215, 16, 206, 172, 16, 66, 0, 192, - 82, 68, 198, 199, 0, 198, 3, 0, 0, 0, 149, 143, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); - sbp_msg_acq_result_dep_b_t test_msg{}; - test_msg.cf = -8241.943359375; - test_msg.cp = 843.0; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 3; - test_msg.snr = 36.16875457763672; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -8241.94335938 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -8241.94335938, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 843.0 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 843.0, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 3) - << "incorrect value for last_msg_.sid.sat, expected 3, is " - << last_msg_.sid.sat; - EXPECT_LT((last_msg_.snr * 100 - 36.1687545776 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 36.1687545776, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepB2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + state.process_message(info.sender_id, SbpMsgAcqResultDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepB4 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepB2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepB4() { + assign(test_msg_.cf, -499.5117492675781); + assign(test_msg_.cp, 522.0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 5); + assign(test_msg_.snr, 35.52417755126953); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepB2, Test) { - uint8_t encoded_frame[] = { - 85, 20, 0, 246, 215, 16, 228, 27, 15, 66, 0, 128, - 70, 68, 228, 74, 148, 69, 18, 0, 0, 0, 179, 155, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_acq_result_dep_b_t test_msg{}; - test_msg.cf = 4745.361328125; - test_msg.cp = 794.0; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 18; - test_msg.snr = 35.77723693847656; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 4745.36132812 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 4745.36132812, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 794.0 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 794.0, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 18) - << "incorrect value for last_msg_.sid.sat, expected 18, is " - << last_msg_.sid.sat; - EXPECT_LT((last_msg_.snr * 100 - 35.7772369385 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 35.7772369385, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepB3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepB3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepB3, Test) { - uint8_t encoded_frame[] = { - 85, 20, 0, 246, 215, 16, 46, 199, 14, 66, 0, 64, - 129, 67, 240, 24, 28, 69, 17, 0, 0, 0, 18, 181, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_acq_result_dep_b_t test_msg{}; - test_msg.cf = 2497.55859375; - test_msg.cp = 258.5; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 17; - test_msg.snr = 35.69451141357422; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 2497.55859375 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 2497.55859375, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 258.5 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 258.5, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 17) - << "incorrect value for last_msg_.sid.sat, expected 17, is " - << last_msg_.sid.sat; - EXPECT_LT((last_msg_.snr * 100 - 35.6945114136 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 35.6945114136, is " - << last_msg_.snr; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepB4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepB4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_b, + sizeof(msg->acq_result_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xcb23; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_acq_result_dep_b_t &lesser, + const sbp_msg_acq_result_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepB4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_acq_result_dep_b_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { 85, 20, 0, 246, 215, 16, 194, 24, 14, 66, 0, 128, 2, 68, 129, 193, 249, 195, 5, 0, 0, 0, 35, 203, }; + uint8_t encoded_payload_[16] = { + 194, 24, 14, 66, 0, 128, 2, 68, 129, 193, 249, 195, 5, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_b_t lesser = info.test_msg; + sbp_msg_acq_result_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.snr, greater.snr); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_B"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_b, info.test_msg); - sbp_msg_acq_result_dep_b_t test_msg{}; - test_msg.cf = -499.5117492675781; - test_msg.cp = 522.0; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 5; - test_msg.snr = 35.52417755126953; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -499.511749268 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -499.511749268, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cp * 100 - 522.0 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 522.0, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 5) - << "incorrect value for last_msg_.sid.sat, expected 5, is " - << last_msg_.sid.sat; - EXPECT_LT((last_msg_.snr * 100 - 35.5241775513 * 100), 0.05) - << "incorrect value for last_msg_.snr, expected 35.5241775513, is " - << last_msg_.snr; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_b, info.test_msg); } + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepB4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepC.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepC.cc index b78988b1dd..0b469473c0 100644 --- a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepC.cc +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqResultDepC.cc @@ -16,506 +16,3984 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_acquisition_MsgAcqResultDepC0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqResultDepC0 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepC0() { + assign(test_msg_.cf, 1769.06591796875); + assign(test_msg_.cn0, 40.509063720703125); + assign(test_msg_.cp, 457.1922302246094); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 10); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_c, + sizeof(msg->acq_result_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepC); + info.sender_id = 3112; + info.preamble = 0x55; + info.crc = 0xbd09; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_c_t &lesser, + const sbp_msg_acq_result_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_c_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 31, 0, 40, 12, 16, 72, 9, 34, 66, 155, 152, + 228, 67, 28, 34, 221, 68, 10, 0, 0, 0, 9, 189, + }; + uint8_t encoded_payload_[16] = { + 72, 9, 34, 66, 155, 152, 228, 67, 28, 34, 221, 68, 10, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_C"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepC1 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepC1() { + assign(test_msg_.cf, -505.4473876953125); + assign(test_msg_.cn0, 43.49464416503906); + assign(test_msg_.cp, 865.4657592773438); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 6); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_c, + sizeof(msg->acq_result_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepC); + info.sender_id = 3112; + info.preamble = 0x55; + info.crc = 0xb988; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_c_t &lesser, + const sbp_msg_acq_result_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_c_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 31, 0, 40, 12, 16, 132, 250, 45, 66, 207, 93, + 88, 68, 68, 185, 252, 195, 6, 0, 0, 0, 136, 185, + }; + uint8_t encoded_payload_[16] = { + 132, 250, 45, 66, 207, 93, 88, 68, 68, 185, 252, 195, 6, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_C"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepC2 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqResultDepC2() { + assign(test_msg_.cf, -1263.618408203125); + assign(test_msg_.cn0, 38.2183952331543); + assign(test_msg_.cp, 230.3564453125); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 13); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_c, + sizeof(msg->acq_result_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepC); + info.sender_id = 3112; + info.preamble = 0x55; + info.crc = 0xa196; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_c_t &lesser, + const sbp_msg_acq_result_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_c_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 31, 0, 40, 12, 16, 163, 223, 24, 66, 64, 91, + 102, 67, 202, 243, 157, 196, 13, 0, 0, 0, 150, 161, + }; + uint8_t encoded_payload_[16] = { + 163, 223, 24, 66, 64, 91, 102, 67, 202, 243, 157, 196, 13, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_C"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepC3 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepC0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepC3() { + assign(test_msg_.cf, 3032.684326171875); + assign(test_msg_.cn0, 37.313968658447266); + assign(test_msg_.cp, 252.83935546875); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_c, + sizeof(msg->acq_result_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepC); + info.sender_id = 3112; + info.preamble = 0x55; + info.crc = 0xd16d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_result_dep_c_t &lesser, + const sbp_msg_acq_result_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_result_dep_c_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 31, 0, 40, 12, 16, 129, 65, 21, 66, 224, 214, + 124, 67, 243, 138, 61, 69, 1, 0, 0, 0, 109, 209, + }; + uint8_t encoded_payload_[16] = { + 129, 65, 21, 66, 224, 214, 124, 67, 243, 138, 61, 69, 1, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_C"); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepC0, Test) { - uint8_t encoded_frame[] = { - 85, 31, 0, 40, 12, 16, 72, 9, 34, 66, 155, 152, - 228, 67, 28, 34, 221, 68, 10, 0, 0, 0, 9, 189, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_acq_result_dep_c_t test_msg{}; - test_msg.cf = 1769.06591796875; - test_msg.cn0 = 40.509063720703125; - test_msg.cp = 457.1922302246094; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 10; - - EXPECT_EQ(send_message(3112, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 3112); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 1769.06591797 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 1769.06591797, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cn0 * 100 - 40.5090637207 * 100), 0.05) - << "incorrect value for last_msg_.cn0, expected 40.5090637207, is " - << last_msg_.cn0; - EXPECT_LT((last_msg_.cp * 100 - 457.192230225 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 457.192230225, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 10) - << "incorrect value for last_msg_.sid.sat, expected 10, is " - << last_msg_.sid.sat; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepC1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepC1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepC1, Test) { - uint8_t encoded_frame[] = { - 85, 31, 0, 40, 12, 16, 132, 250, 45, 66, 207, 93, - 88, 68, 68, 185, 252, 195, 6, 0, 0, 0, 136, 185, - }; +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); - sbp_msg_acq_result_dep_c_t test_msg{}; - test_msg.cf = -505.4473876953125; - test_msg.cn0 = 43.49464416503906; - test_msg.cp = 865.4657592773438; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 6; - - EXPECT_EQ(send_message(3112, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 3112); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -505.447387695 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -505.447387695, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cn0 * 100 - 43.494644165 * 100), 0.05) - << "incorrect value for last_msg_.cn0, expected 43.494644165, is " - << last_msg_.cn0; - EXPECT_LT((last_msg_.cp * 100 - 865.465759277 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 865.465759277, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 6) - << "incorrect value for last_msg_.sid.sat, expected 6, is " - << last_msg_.sid.sat; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepC2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + state.process_message(info.sender_id, SbpMsgAcqResultDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_acquisition_MsgAcqResultDepC4 + : public ::testing::Test { public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepC2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_acquisition_MsgAcqResultDepC4() { + assign(test_msg_.cf, 2527.23681640625); + assign(test_msg_.cn0, 47.53466033935547); + assign(test_msg_.cp, 920.5919189453125); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 27); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepC2, Test) { - uint8_t encoded_frame[] = { - 85, 31, 0, 40, 12, 16, 163, 223, 24, 66, 64, 91, - 102, 67, 202, 243, 157, 196, 13, 0, 0, 0, 150, 161, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_acq_result_dep_c_t test_msg{}; - test_msg.cf = -1263.618408203125; - test_msg.cn0 = 38.2183952331543; - test_msg.cp = 230.3564453125; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 13; - - EXPECT_EQ(send_message(3112, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 3112); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - -1263.6184082 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected -1263.6184082, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cn0 * 100 - 38.2183952332 * 100), 0.05) - << "incorrect value for last_msg_.cn0, expected 38.2183952332, is " - << last_msg_.cn0; - EXPECT_LT((last_msg_.cp * 100 - 230.356445312 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 230.356445312, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 13) - << "incorrect value for last_msg_.sid.sat, expected 13, is " - << last_msg_.sid.sat; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepC3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepC3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepC3, Test) { - uint8_t encoded_frame[] = { - 85, 31, 0, 40, 12, 16, 129, 65, 21, 66, 224, 214, - 124, 67, 243, 138, 61, 69, 1, 0, 0, 0, 109, 209, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_acq_result_dep_c_t test_msg{}; - test_msg.cf = 3032.684326171875; - test_msg.cn0 = 37.313968658447266; - test_msg.cp = 252.83935546875; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 1; - - EXPECT_EQ(send_message(3112, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 3112); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 3032.68432617 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 3032.68432617, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cn0 * 100 - 37.3139686584 * 100), 0.05) - << "incorrect value for last_msg_.cn0, expected 37.3139686584, is " - << last_msg_.cn0; - EXPECT_LT((last_msg_.cp * 100 - 252.839355469 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 252.839355469, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 1) - << "incorrect value for last_msg_.sid.sat, expected 1, is " - << last_msg_.sid.sat; -} -class Test_auto_check_sbp_acquisition_MsgAcqResultDepC4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_acquisition_MsgAcqResultDepC4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_result_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqResultDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_result_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqResultDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_result_dep_c, + sizeof(msg->acq_result_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_result_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_result_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqResultDepC); + info.sender_id = 3112; + info.preamble = 0x55; + info.crc = 0x435b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acq_result_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acq_result_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_acq_result_dep_c_t &lesser, + const sbp_msg_acq_result_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_result_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_result_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_result_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqResultDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_acquisition_MsgAcqResultDepC4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_acq_result_dep_c_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { 85, 31, 0, 40, 12, 16, 126, 35, 62, 66, 226, 37, 102, 68, 202, 243, 29, 69, 27, 0, 0, 0, 91, 67, }; + uint8_t encoded_payload_[16] = { + 126, 35, 62, 66, 226, 37, 102, 68, 202, 243, 29, 69, 27, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_result_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqResultDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqResultDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_acq_result_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqResultDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_acq_result_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_result_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqResultDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cf, greater.cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.cp, greater.cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_result_dep_c_t lesser = info.test_msg; + sbp_msg_acq_result_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqResultDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_RESULT_DEP_C"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_result_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_result_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_result_dep_c, info.test_msg); - sbp_msg_acq_result_dep_c_t test_msg{}; - test_msg.cf = 2527.23681640625; - test_msg.cn0 = 47.53466033935547; - test_msg.cp = 920.5919189453125; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 27; - - EXPECT_EQ(send_message(3112, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 3112); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cf * 100 - 2527.23681641 * 100), 0.05) - << "incorrect value for last_msg_.cf, expected 2527.23681641, is " - << last_msg_.cf; - EXPECT_LT((last_msg_.cn0 * 100 - 47.5346603394 * 100), 0.05) - << "incorrect value for last_msg_.cn0, expected 47.5346603394, is " - << last_msg_.cn0; - EXPECT_LT((last_msg_.cp * 100 - 920.591918945 * 100), 0.05) - << "incorrect value for last_msg_.cp, expected 920.591918945, is " - << last_msg_.cp; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 27) - << "incorrect value for last_msg_.sid.sat, expected 27, is " - << last_msg_.sid.sat; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_result_dep_c, info.test_msg); } + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_result_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqResultDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqResultDepC4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqResultDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc new file mode 100644 index 0000000000..c3a706d4c5 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc @@ -0,0 +1,1128 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqSvProfile0 : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqSvProfile0() { + assign(test_msg_.acq_sv_profile[0].bin_width, 174); + assign(test_msg_.acq_sv_profile[0].cf, 47); + assign(test_msg_.acq_sv_profile[0].cf_max, 147); + assign(test_msg_.acq_sv_profile[0].cf_min, 61); + assign(test_msg_.acq_sv_profile[0].cn0, 38); + assign(test_msg_.acq_sv_profile[0].cp, 140); + assign(test_msg_.acq_sv_profile[0].int_time, 97); + assign(test_msg_.acq_sv_profile[0].job_type, 7); + assign(test_msg_.acq_sv_profile[0].sid.code, 0); + assign(test_msg_.acq_sv_profile[0].sid.sat, 22); + assign(test_msg_.acq_sv_profile[0].status, 13); + assign(test_msg_.acq_sv_profile[0].time_spent, 49); + assign(test_msg_.acq_sv_profile[0].timestamp, 52); + + assign(test_msg_.acq_sv_profile[1].bin_width, 121); + assign(test_msg_.acq_sv_profile[1].cf, 237); + assign(test_msg_.acq_sv_profile[1].cf_max, 142); + assign(test_msg_.acq_sv_profile[1].cf_min, 175); + assign(test_msg_.acq_sv_profile[1].cn0, 59); + assign(test_msg_.acq_sv_profile[1].cp, 12); + assign(test_msg_.acq_sv_profile[1].int_time, 253); + assign(test_msg_.acq_sv_profile[1].job_type, 166); + assign(test_msg_.acq_sv_profile[1].sid.code, 1); + assign(test_msg_.acq_sv_profile[1].sid.sat, 23); + assign(test_msg_.acq_sv_profile[1].status, 210); + assign(test_msg_.acq_sv_profile[1].time_spent, 175); + assign(test_msg_.acq_sv_profile[1].timestamp, 190); + + assign(test_msg_.acq_sv_profile[2].bin_width, 8); + assign(test_msg_.acq_sv_profile[2].cf, 84); + assign(test_msg_.acq_sv_profile[2].cf_max, 191); + assign(test_msg_.acq_sv_profile[2].cf_min, 91); + assign(test_msg_.acq_sv_profile[2].cn0, 21); + assign(test_msg_.acq_sv_profile[2].cp, 82); + assign(test_msg_.acq_sv_profile[2].int_time, 153); + assign(test_msg_.acq_sv_profile[2].job_type, 126); + assign(test_msg_.acq_sv_profile[2].sid.code, 0); + assign(test_msg_.acq_sv_profile[2].sid.sat, 24); + assign(test_msg_.acq_sv_profile[2].status, 88); + assign(test_msg_.acq_sv_profile[2].time_spent, 172); + assign(test_msg_.acq_sv_profile[2].timestamp, 130); + assign(test_msg_.n_acq_sv_profile, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_sv_profile_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_sv_profile_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqSvProfile, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_sv_profile_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqSvProfile); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_sv_profile, + sizeof(msg->acq_sv_profile)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_sv_profile_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_sv_profile, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqSvProfile); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb1a8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_sv_profile_t &lesser, + const sbp_msg_acq_sv_profile_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_sv_profile_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_sv_profile_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_sv_profile_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_sv_profile_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqSvProfile, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcqSvProfile, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcqSvProfile, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcqSvProfile, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_sv_profile_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, 0, 52, + 0, 0, 0, 49, 0, 0, 0, 61, 0, 0, 0, 147, 0, 0, 0, 47, + 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, 0, 253, 23, 1, 121, 0, + 190, 0, 0, 0, 175, 0, 0, 0, 175, 0, 0, 0, 142, 0, 0, 0, + 237, 0, 0, 0, 12, 0, 0, 0, 126, 88, 21, 0, 153, 24, 0, 8, + 0, 130, 0, 0, 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, + 0, 84, 0, 0, 0, 82, 0, 0, 0, 168, 177, + }; + uint8_t encoded_payload_[99] = { + 7, 13, 38, 0, 97, 22, 0, 174, 0, 52, 0, 0, 0, 49, 0, + 0, 0, 61, 0, 0, 0, 147, 0, 0, 0, 47, 0, 0, 0, 140, + 0, 0, 0, 166, 210, 59, 0, 253, 23, 1, 121, 0, 190, 0, 0, + 0, 175, 0, 0, 0, 175, 0, 0, 0, 142, 0, 0, 0, 237, 0, + 0, 0, 12, 0, 0, 0, 126, 88, 21, 0, 153, 24, 0, 8, 0, + 130, 0, 0, 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, + 0, 84, 0, 0, 0, 82, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_sv_profile_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAcqSvProfile, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_sv_profile_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqSvProfile, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_acq_sv_profile_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ( + sbp_msg_acq_sv_profile_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_sv_profile_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqSvProfile, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_t msg{}; + + EXPECT_EQ(sbp_msg_acq_sv_profile_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_acq_sv_profile_t t{}; + return sbp_msg_acq_sv_profile_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_acq_sv_profile_t t{}; + t.n_acq_sv_profile = 1; + return sbp_msg_acq_sv_profile_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_acq_sv_profile_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_sv_profile_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqSvProfile, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqSvProfile, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqSvProfile, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].bin_width, + greater.acq_sv_profile[0].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf, + greater.acq_sv_profile[0].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf_max, + greater.acq_sv_profile[0].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf_min, + greater.acq_sv_profile[0].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cn0, + greater.acq_sv_profile[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cp, + greater.acq_sv_profile[0].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].int_time, + greater.acq_sv_profile[0].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].job_type, + greater.acq_sv_profile[0].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].sid.code, + greater.acq_sv_profile[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].sid.sat, + greater.acq_sv_profile[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].status, + greater.acq_sv_profile[0].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].time_spent, + greater.acq_sv_profile[0].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].timestamp, + greater.acq_sv_profile[0].timestamp); + comparison_tests(lesser, greater); + } + + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].bin_width, + greater.acq_sv_profile[1].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf, + greater.acq_sv_profile[1].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf_max, + greater.acq_sv_profile[1].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf_min, + greater.acq_sv_profile[1].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cn0, + greater.acq_sv_profile[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cp, + greater.acq_sv_profile[1].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].int_time, + greater.acq_sv_profile[1].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].job_type, + greater.acq_sv_profile[1].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].sid.code, + greater.acq_sv_profile[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].sid.sat, + greater.acq_sv_profile[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].status, + greater.acq_sv_profile[1].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].time_spent, + greater.acq_sv_profile[1].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].timestamp, + greater.acq_sv_profile[1].timestamp); + comparison_tests(lesser, greater); + } + + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].bin_width, + greater.acq_sv_profile[2].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf, + greater.acq_sv_profile[2].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf_max, + greater.acq_sv_profile[2].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf_min, + greater.acq_sv_profile[2].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cn0, + greater.acq_sv_profile[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cp, + greater.acq_sv_profile[2].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].int_time, + greater.acq_sv_profile[2].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].job_type, + greater.acq_sv_profile[2].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].sid.code, + greater.acq_sv_profile[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].sid.sat, + greater.acq_sv_profile[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].status, + greater.acq_sv_profile[2].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].time_spent, + greater.acq_sv_profile[2].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].timestamp, + greater.acq_sv_profile[2].timestamp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_t greater = info.test_msg; + make_lesser_greater(lesser.n_acq_sv_profile, greater.n_acq_sv_profile); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqSvProfile); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_SV_PROFILE"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_sv_profile_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_sv_profile_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acq_sv_profile, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_sv_profile, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqSvProfile, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfile0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqSvProfile, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc new file mode 100644 index 0000000000..d6e48fc5fe --- /dev/null +++ b/c/test/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc @@ -0,0 +1,1163 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0 + : public ::testing::Test { + public: + Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0() { + assign(test_msg_.acq_sv_profile[0].bin_width, 187); + assign(test_msg_.acq_sv_profile[0].cf, 60); + assign(test_msg_.acq_sv_profile[0].cf_max, 36); + assign(test_msg_.acq_sv_profile[0].cf_min, 132); + assign(test_msg_.acq_sv_profile[0].cn0, 151); + assign(test_msg_.acq_sv_profile[0].cp, 241); + assign(test_msg_.acq_sv_profile[0].int_time, 12); + assign(test_msg_.acq_sv_profile[0].job_type, 67); + assign(test_msg_.acq_sv_profile[0].sid.code, 0); + assign(test_msg_.acq_sv_profile[0].sid.reserved, 0); + assign(test_msg_.acq_sv_profile[0].sid.sat, 22); + assign(test_msg_.acq_sv_profile[0].status, 103); + assign(test_msg_.acq_sv_profile[0].time_spent, 75); + assign(test_msg_.acq_sv_profile[0].timestamp, 91); + + assign(test_msg_.acq_sv_profile[1].bin_width, 176); + assign(test_msg_.acq_sv_profile[1].cf, 212); + assign(test_msg_.acq_sv_profile[1].cf_max, 24); + assign(test_msg_.acq_sv_profile[1].cf_min, 155); + assign(test_msg_.acq_sv_profile[1].cn0, 111); + assign(test_msg_.acq_sv_profile[1].cp, 247); + assign(test_msg_.acq_sv_profile[1].int_time, 179); + assign(test_msg_.acq_sv_profile[1].job_type, 238); + assign(test_msg_.acq_sv_profile[1].sid.code, 1); + assign(test_msg_.acq_sv_profile[1].sid.reserved, 0); + assign(test_msg_.acq_sv_profile[1].sid.sat, 23); + assign(test_msg_.acq_sv_profile[1].status, 38); + assign(test_msg_.acq_sv_profile[1].time_spent, 234); + assign(test_msg_.acq_sv_profile[1].timestamp, 166); + + assign(test_msg_.acq_sv_profile[2].bin_width, 52); + assign(test_msg_.acq_sv_profile[2].cf, 212); + assign(test_msg_.acq_sv_profile[2].cf_max, 248); + assign(test_msg_.acq_sv_profile[2].cf_min, 76); + assign(test_msg_.acq_sv_profile[2].cn0, 68); + assign(test_msg_.acq_sv_profile[2].cp, 101); + assign(test_msg_.acq_sv_profile[2].int_time, 53); + assign(test_msg_.acq_sv_profile[2].job_type, 142); + assign(test_msg_.acq_sv_profile[2].sid.code, 0); + assign(test_msg_.acq_sv_profile[2].sid.reserved, 0); + assign(test_msg_.acq_sv_profile[2].sid.sat, 24); + assign(test_msg_.acq_sv_profile[2].status, 213); + assign(test_msg_.acq_sv_profile[2].time_spent, 245); + assign(test_msg_.acq_sv_profile[2].timestamp, 49); + assign(test_msg_.n_acq_sv_profile, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_sv_profile_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acq_sv_profile_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcqSvProfileDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acq_sv_profile_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcqSvProfileDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acq_sv_profile_dep, + sizeof(msg->acq_sv_profile_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acq_sv_profile_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acq_sv_profile_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcqSvProfileDep); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x8443; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 105; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_acq_sv_profile_dep_t &lesser, + const sbp_msg_acq_sv_profile_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acq_sv_profile_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acq_sv_profile_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqSvProfileDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAcqSvProfileDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgAcqSvProfileDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgAcqSvProfileDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acq_sv_profile_dep_t test_msg_{}; + uint8_t encoded_frame_[105 + 8] = { + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, + 187, 0, 91, 0, 0, 0, 75, 0, 0, 0, 132, 0, 0, 0, 36, + 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, + 179, 23, 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, + 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, 247, 0, 0, + 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, + 0, 245, 0, 0, 0, 76, 0, 0, 0, 248, 0, 0, 0, 212, 0, + 0, 0, 101, 0, 0, 0, 67, 132, + }; + uint8_t encoded_payload_[105] = { + 67, 103, 151, 0, 12, 22, 0, 0, 0, 187, 0, 91, 0, 0, 0, + 75, 0, 0, 0, 132, 0, 0, 0, 36, 0, 0, 0, 60, 0, 0, + 0, 241, 0, 0, 0, 238, 38, 111, 0, 179, 23, 0, 1, 0, 176, + 0, 166, 0, 0, 0, 234, 0, 0, 0, 155, 0, 0, 0, 24, 0, + 0, 0, 212, 0, 0, 0, 247, 0, 0, 0, 142, 213, 68, 0, 53, + 24, 0, 0, 0, 52, 0, 49, 0, 0, 0, 245, 0, 0, 0, 76, + 0, 0, 0, 248, 0, 0, 0, 212, 0, 0, 0, 101, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAcqSvProfileDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[105]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 105); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 105), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcqSvProfileDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 105); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 105), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[105]; + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 105), 0); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[105]; + + for (uint8_t i = 0; i < 105; i++) { + EXPECT_EQ( + sbp_msg_acq_sv_profile_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 105); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcqSvProfileDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 105); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_dep_t msg{}; + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_acq_sv_profile_dep_t t{}; + return sbp_msg_acq_sv_profile_dep_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_acq_sv_profile_dep_t t{}; + t.n_acq_sv_profile = 1; + return sbp_msg_acq_sv_profile_dep_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acq_sv_profile_dep_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqSvProfileDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcqSvProfileDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcqSvProfileDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].bin_width, + greater.acq_sv_profile[0].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf, + greater.acq_sv_profile[0].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf_max, + greater.acq_sv_profile[0].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cf_min, + greater.acq_sv_profile[0].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cn0, + greater.acq_sv_profile[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].cp, + greater.acq_sv_profile[0].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].int_time, + greater.acq_sv_profile[0].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].job_type, + greater.acq_sv_profile[0].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].sid.code, + greater.acq_sv_profile[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].sid.reserved, + greater.acq_sv_profile[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].sid.sat, + greater.acq_sv_profile[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].status, + greater.acq_sv_profile[0].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].time_spent, + greater.acq_sv_profile[0].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[0].timestamp, + greater.acq_sv_profile[0].timestamp); + comparison_tests(lesser, greater); + } + + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].bin_width, + greater.acq_sv_profile[1].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf, + greater.acq_sv_profile[1].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf_max, + greater.acq_sv_profile[1].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cf_min, + greater.acq_sv_profile[1].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cn0, + greater.acq_sv_profile[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].cp, + greater.acq_sv_profile[1].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].int_time, + greater.acq_sv_profile[1].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].job_type, + greater.acq_sv_profile[1].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].sid.code, + greater.acq_sv_profile[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].sid.reserved, + greater.acq_sv_profile[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].sid.sat, + greater.acq_sv_profile[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].status, + greater.acq_sv_profile[1].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].time_spent, + greater.acq_sv_profile[1].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[1].timestamp, + greater.acq_sv_profile[1].timestamp); + comparison_tests(lesser, greater); + } + + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].bin_width, + greater.acq_sv_profile[2].bin_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf, + greater.acq_sv_profile[2].cf); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf_max, + greater.acq_sv_profile[2].cf_max); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cf_min, + greater.acq_sv_profile[2].cf_min); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cn0, + greater.acq_sv_profile[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].cp, + greater.acq_sv_profile[2].cp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].int_time, + greater.acq_sv_profile[2].int_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].job_type, + greater.acq_sv_profile[2].job_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].sid.code, + greater.acq_sv_profile[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].sid.reserved, + greater.acq_sv_profile[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].sid.sat, + greater.acq_sv_profile[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].status, + greater.acq_sv_profile[2].status); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].time_spent, + greater.acq_sv_profile[2].time_spent); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acq_sv_profile[2].timestamp, + greater.acq_sv_profile[2].timestamp); + comparison_tests(lesser, greater); + } + { + sbp_msg_acq_sv_profile_dep_t lesser = info.test_msg; + sbp_msg_acq_sv_profile_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_acq_sv_profile, greater.n_acq_sv_profile); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcqSvProfileDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACQ_SV_PROFILE_DEP"); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acq_sv_profile_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acq_sv_profile_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.acq_sv_profile_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.acq_sv_profile_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[105]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 105); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 105), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acq_sv_profile_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 105); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcqSvProfileDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_acquisition_MsgAcqSvProfileDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcqSvProfileDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc new file mode 100644 index 0000000000..7e218c3622 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc @@ -0,0 +1,769 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0 + : public ::testing::Test { + public: + Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_bootloader_handshake_req_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_bootloader_handshake_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBootloaderHandshakeReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBootloaderHandshakeReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->bootloader_handshake_req, + sizeof(msg->bootloader_handshake_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_bootloader_handshake_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.bootloader_handshake_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBootloaderHandshakeReq); + info.sender_id = 63368; + info.preamble = 0x55; + info.crc = 0xd841; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_bootloader_handshake_req_t &lesser, + const sbp_msg_bootloader_handshake_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_bootloader_handshake_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_bootloader_handshake_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_bootloader_handshake_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBootloaderHandshakeReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBootloaderHandshakeReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_bootloader_handshake_req_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 179, 0, 136, 247, 0, 65, 216, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_bootloader_handshake_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBootloaderHandshakeReq, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBootloaderHandshakeReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgBootloaderHandshakeReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_req_t msg{}; + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_bootloader_handshake_req_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgBootloaderHandshakeReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBootloaderHandshakeReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BOOTLOADER_HANDSHAKE_REQ"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_bootloader_handshake_req_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_bootloader_handshake_req_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.bootloader_handshake_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.bootloader_handshake_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBootloaderHandshakeReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBootloaderHandshakeReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeResp.cc b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeResp.cc index 011184a04f..20757dc660 100644 --- a/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeResp.cc +++ b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeResp.cc @@ -16,185 +16,1896 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0 + : public ::testing::Test { public: - Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0() { + assign(test_msg_.flags, 0); + + size_t written; + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set( + &test_msg_, "v1.2\n", false, &written)); + EXPECT_EQ(written, strlen("v1.2\n")); + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_version_encoded_len(&test_msg_), + 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_bootloader_handshake_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_bootloader_handshake_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBootloaderHandshakeResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBootloaderHandshakeResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->bootloader_handshake_resp, + sizeof(msg->bootloader_handshake_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_bootloader_handshake_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.bootloader_handshake_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBootloaderHandshakeResp); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0x1c9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_bootloader_handshake_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_bootloader_handshake_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_bootloader_handshake_resp_t &lesser, + const sbp_msg_bootloader_handshake_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_bootloader_handshake_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_bootloader_handshake_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBootloaderHandshakeResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBootloaderHandshakeResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_bootloader_handshake_resp_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { 85, 180, 0, 0, 0, 9, 0, 0, 0, 0, 118, 49, 46, 50, 10, 201, 1, }; + uint8_t encoded_payload_[9] = { + 0, 0, 0, 0, 118, 49, 46, 50, 10, + }; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBootloaderHandshakeResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBootloaderHandshakeResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgBootloaderHandshakeResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_resp_t msg{}; + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_BOOTLOADER_HANDSHAKE_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_bootloader_handshake_resp_t t{}; + // return sbp_msg_bootloader_handshake_resp_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgBootloaderHandshakeResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_bootloader_handshake_resp_t lesser = info.test_msg; + sbp_msg_bootloader_handshake_resp_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_bootloader_handshake_resp_t lesser = info.test_msg; + sbp_msg_bootloader_handshake_resp_t greater = info.test_msg; + make_lesser_greater(lesser.version, greater.version); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBootloaderHandshakeResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BOOTLOADER_HANDSHAKE_RESP"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_bootloader_handshake_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_bootloader_handshake_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.bootloader_handshake_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.bootloader_handshake_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_bootloader_handshake_resp_t test_msg{}; - test_msg.flags = 0; + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBootloaderHandshakeResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBootloaderHandshakeResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version + : public Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0 {}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + StringInit) { + sbp_msg_bootloader_handshake_resp_t t{}; + sbp_msg_bootloader_handshake_resp_version_init(&t); + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_valid(&t)); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + IsValid) { + sbp_msg_bootloader_handshake_resp_t t{}; size_t written; - EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set(&test_msg, "v1.2\n", - false, &written)); + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set(&t, "v1.2\n", false, + &written)); EXPECT_EQ(written, strlen("v1.2\n")); - EXPECT_EQ(sbp_msg_bootloader_handshake_resp_version_encoded_len(&test_msg), - 5); + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_version_encoded_len(&t), 5); + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_valid(&t)); +} - EXPECT_EQ(send_message(0, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + SpaceRemaining) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_bootloader_handshake_resp_version_space_remaining(&t); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + size_t written; + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set(&t, "v1.2\n", false, + &written)); + EXPECT_EQ(written, strlen("v1.2\n")); + EXPECT_EQ(sbp_msg_bootloader_handshake_resp_version_encoded_len(&t), 5); + size_t assigned_space_remaining = + sbp_msg_bootloader_handshake_resp_version_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} - while (dummy_rd_ < dummy_wr_) { - process(); - } +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_resp_t t{}; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; + size_t nwritten{}; - EXPECT_EQ(sbp_msg_bootloader_handshake_resp_version_encoded_len(&last_msg_), - 5); - EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&last_msg_), - "v1.2\n"); + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set_raw( + &t, info.test_msg.version.data, + sbp_msg_bootloader_handshake_resp_version_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ( + sbp_msg_bootloader_handshake_resp_version_encoded_len(&info.test_msg), + sbp_msg_bootloader_handshake_resp_version_encoded_len(&t)); } -class Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, Set) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t nwritten{}; + const char *text = "v1.2\n"; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_set(&t, text, false, + &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + Printf) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t nwritten{}; + const char *text = "v1.2\n"; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + Vprintf) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t nwritten{}; + const char *text = "v1.2\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_bootloader_handshake_resp_version_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + AppendPrintf) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t nwritten{}; + char part1[] = "v1.2\n"; + char part2[] = "v1.2\n"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), "v1.2\n"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp0_version, + AppendVprintf) { + sbp_msg_bootloader_handshake_resp_t t{}; + size_t nwritten{}; + char part1[] = "v1.2\n"; + char part2[] = "v1.2\n"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_resp_version_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_bootloader_handshake_resp_version_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_bootloader_handshake_resp_version_get(&t), "v1.2\n"); +} + +class Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1 + : public ::testing::Test { public: - Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1() { + size_t written; + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_set( + &test_msg_, "v1.2", false, &written)); + EXPECT_EQ(written, strlen("v1.2")); + EXPECT_EQ( + sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&test_msg_), + 4); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_bootloader_handshake_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_bootloader_handshake_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBootloaderHandshakeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_handshake_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBootloaderHandshakeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->bootloader_handshake_dep_a, + sizeof(msg->bootloader_handshake_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_bootloader_handshake_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.bootloader_handshake_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBootloaderHandshakeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xce01; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_bootloader_handshake_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_bootloader_handshake_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_bootloader_handshake_dep_a_t &lesser, + const sbp_msg_bootloader_handshake_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_bootloader_handshake_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_bootloader_handshake_dep_a_cmp(&greater, &lesser), 0); -TEST_F(Test_auto_check_sbp_bootload_MsgBootloaderHandshakeResp1, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderHandshakeDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBootloaderHandshakeDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBootloaderHandshakeDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_bootloader_handshake_dep_a_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 176, 0, 195, 4, 4, 118, 49, 46, 50, 1, 206, }; + uint8_t encoded_payload_[4] = { + 118, + 49, + 46, + 50, + }; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBootloaderHandshakeDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBootloaderHandshakeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgBootloaderHandshakeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_BOOTLOADER_HANDSHAKE_DEP_A_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_bootloader_handshake_dep_a_t t{}; + // return sbp_msg_bootloader_handshake_dep_a_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} - sbp_msg_bootloader_handshake_dep_a_t test_msg{}; +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgBootloaderHandshakeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgBootloaderHandshakeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_bootloader_handshake_dep_a_t lesser = info.test_msg; + sbp_msg_bootloader_handshake_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.handshake, greater.handshake); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBootloaderHandshakeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BOOTLOADER_HANDSHAKE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_bootloader_handshake_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_bootloader_handshake_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.bootloader_handshake_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.bootloader_handshake_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBootloaderHandshakeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBootloaderHandshakeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake + : public Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1 {}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + StringInit) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + sbp_msg_bootloader_handshake_dep_a_handshake_init(&t); + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_valid(&t)); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + IsValid) { + sbp_msg_bootloader_handshake_dep_a_t t{}; size_t written; EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_set( - &test_msg, "v1.2", false, &written)); + &t, "v1.2", false, &written)); EXPECT_EQ(written, strlen("v1.2")); - EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&test_msg), - 4); + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&t), 4); + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_valid(&t)); +} - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + SpaceRemaining) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t empty_space_remaining = + sbp_msg_bootloader_handshake_dep_a_handshake_space_remaining(&t); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + size_t written; + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_set( + &t, "v1.2", false, &written)); + EXPECT_EQ(written, strlen("v1.2")); + EXPECT_EQ(sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&t), 4); + size_t assigned_space_remaining = + sbp_msg_bootloader_handshake_dep_a_handshake_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} - while (dummy_rd_ < dummy_wr_) { - process(); - } +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_handshake_dep_a_t t{}; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); + size_t nwritten{}; + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_set_raw( + &t, info.test_msg.handshake.data, + sbp_msg_bootloader_handshake_dep_a_handshake_strlen(&info.test_msg), + false, &nwritten)); EXPECT_EQ( - sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&last_msg_), 4); - EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&last_msg_), - "v1.2"); + sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&info.test_msg), + sbp_msg_bootloader_handshake_dep_a_handshake_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, Set) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t nwritten{}; + const char *text = "v1.2"; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_set(&t, text, false, + &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + Printf) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t nwritten{}; + const char *text = "v1.2"; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + Vprintf) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t nwritten{}; + const char *text = "v1.2"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_bootloader_handshake_dep_a_handshake_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), text); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + AppendPrintf) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "v1.2"; + char part2[] = "v1.2"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), "v1.2"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderHandshakeResp1_handshake, + AppendVprintf) { + sbp_msg_bootloader_handshake_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "v1.2"; + char part2[] = "v1.2"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_bootloader_handshake_dep_a_handshake_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_bootloader_handshake_dep_a_handshake_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_bootloader_handshake_dep_a_handshake_get(&t), "v1.2"); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc new file mode 100644 index 0000000000..e70b2fb31d --- /dev/null +++ b/c/test/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc @@ -0,0 +1,803 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0 + : public ::testing::Test { + public: + Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0() { + assign(test_msg_.jump, 216); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_jump_to_app_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_bootloader_jump_to_app_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBootloaderJumpToApp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_bootloader_jump_to_app_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBootloaderJumpToApp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->bootloader_jump_to_app, + sizeof(msg->bootloader_jump_to_app)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_bootloader_jump_to_app_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.bootloader_jump_to_app, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBootloaderJumpToApp); + info.sender_id = 4813; + info.preamble = 0x55; + info.crc = 0x6069; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 1; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_bootloader_jump_to_app_t &lesser, + const sbp_msg_bootloader_jump_to_app_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_bootloader_jump_to_app_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_bootloader_jump_to_app_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderJumpToApp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBootloaderJumpToApp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBootloaderJumpToApp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBootloaderJumpToApp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_bootloader_jump_to_app_t test_msg_{}; + uint8_t encoded_frame_[1 + 8] = { + 85, 177, 0, 205, 18, 1, 216, 105, 96, + }; + uint8_t encoded_payload_[1] = { + 216, + }; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBootloaderJumpToApp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBootloaderJumpToApp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_jump_to_app_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgBootloaderJumpToApp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_jump_to_app_t msg{}; + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_jump_to_app_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_bootloader_jump_to_app_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBootloaderJumpToApp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgBootloaderJumpToApp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBootloaderJumpToApp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_bootloader_jump_to_app_t lesser = info.test_msg; + sbp_msg_bootloader_jump_to_app_t greater = info.test_msg; + make_lesser_greater(lesser.jump, greater.jump); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBootloaderJumpToApp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BOOTLOADER_JUMP_TO_APP"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_bootloader_jump_to_app_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_bootloader_jump_to_app_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.bootloader_jump_to_app, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.bootloader_jump_to_app, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_bootloader_jump_to_app_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBootloaderJumpToApp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgBootloaderJumptoApp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBootloaderJumpToApp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc b/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc new file mode 100644 index 0000000000..bb43eb5eec --- /dev/null +++ b/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc @@ -0,0 +1,749 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0 : public ::testing::Test { + public: + Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_nap_device_dna_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_nap_device_dna_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNapDeviceDnaReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_nap_device_dna_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNapDeviceDnaReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->nap_device_dna_req, + sizeof(msg->nap_device_dna_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_nap_device_dna_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.nap_device_dna_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNapDeviceDnaReq); + info.sender_id = 12928; + info.preamble = 0x55; + info.crc = 0xa0e7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_nap_device_dna_req_t &lesser, + const sbp_msg_nap_device_dna_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_nap_device_dna_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_nap_device_dna_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_nap_device_dna_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_nap_device_dna_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNapDeviceDnaReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgNapDeviceDnaReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgNapDeviceDnaReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgNapDeviceDnaReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_nap_device_dna_req_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 222, 0, 128, 50, 0, 231, 160, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_nap_device_dna_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgNapDeviceDnaReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_nap_device_dna_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgNapDeviceDnaReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_nap_device_dna_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_nap_device_dna_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgNapDeviceDnaReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_req_t msg{}; + + EXPECT_EQ(sbp_msg_nap_device_dna_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_nap_device_dna_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNapDeviceDnaReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgNapDeviceDnaReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNapDeviceDnaReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgNapDeviceDnaReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_NAP_DEVICE_DNA_REQ"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_nap_device_dna_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_nap_device_dna_req_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.nap_device_dna_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.nap_device_dna_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNapDeviceDnaReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgNapDeviceDnaReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc b/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc new file mode 100644 index 0000000000..d19eca2c25 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc @@ -0,0 +1,853 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0 + : public ::testing::Test { + public: + Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0() { + assign(test_msg_.dna[0], 2); + + assign(test_msg_.dna[1], 187); + + assign(test_msg_.dna[2], 1); + + assign(test_msg_.dna[3], 130); + + assign(test_msg_.dna[4], 173); + + assign(test_msg_.dna[5], 244); + + assign(test_msg_.dna[6], 67); + + assign(test_msg_.dna[7], 122); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_nap_device_dna_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_nap_device_dna_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNapDeviceDnaResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_nap_device_dna_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNapDeviceDnaResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->nap_device_dna_resp, + sizeof(msg->nap_device_dna_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_nap_device_dna_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.nap_device_dna_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNapDeviceDnaResp); + info.sender_id = 14505; + info.preamble = 0x55; + info.crc = 0x5b46; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 8; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_nap_device_dna_resp_t &lesser, + const sbp_msg_nap_device_dna_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_nap_device_dna_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_nap_device_dna_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_nap_device_dna_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNapDeviceDnaResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgNapDeviceDnaResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgNapDeviceDnaResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgNapDeviceDnaResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_nap_device_dna_resp_t test_msg_{}; + uint8_t encoded_frame_[8 + 8] = { + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + }; + uint8_t encoded_payload_[8] = { + 2, 187, 1, 130, 173, 244, 67, 122, + }; +}; + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_nap_device_dna_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgNapDeviceDnaResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgNapDeviceDnaResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ( + sbp_msg_nap_device_dna_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgNapDeviceDnaResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_resp_t msg{}; + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_nap_device_dna_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNapDeviceDnaResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgNapDeviceDnaResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNapDeviceDnaResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[0], greater.dna[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[1], greater.dna[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[2], greater.dna[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[3], greater.dna[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[4], greater.dna[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[5], greater.dna[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[6], greater.dna[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_nap_device_dna_resp_t lesser = info.test_msg; + sbp_msg_nap_device_dna_resp_t greater = info.test_msg; + make_lesser_greater(lesser.dna[7], greater.dna[7]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgNapDeviceDnaResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_NAP_DEVICE_DNA_RESP"); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_nap_device_dna_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_nap_device_dna_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.nap_device_dna_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.nap_device_dna_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_nap_device_dna_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNapDeviceDnaResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_bootload_MsgNapDeviceDnaResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgNapDeviceDnaResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ext_events_MsgExtEvent.cc b/c/test/cpp/auto_check_sbp_ext_events_MsgExtEvent.cc index 4aa13a8542..449a6a2163 100644 --- a/c/test/cpp/auto_check_sbp_ext_events_MsgExtEvent.cc +++ b/c/test/cpp/auto_check_sbp_ext_events_MsgExtEvent.cc @@ -16,100 +16,778 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ext_events_MsgExtEvent0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ext_events_MsgExtEvent0 : public ::testing::Test { public: - Test_auto_check_sbp_ext_events_MsgExtEvent0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ext_events_MsgExtEvent0() { + assign(test_msg_.flags, 3); + assign(test_msg_.ns_residual, 999882); + assign(test_msg_.pin, 0); + assign(test_msg_.tow, 254924999); + assign(test_msg_.wn, 1840); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ext_event_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ext_event_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgExtEvent, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ext_event_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgExtEvent); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ext_event, sizeof(msg->ext_event)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ext_event_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ext_event, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgExtEvent); + info.sender_id = 1781; + info.preamble = 0x55; + info.crc = 0xcc3e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 12; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ext_event_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ext_event_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ext_event_t &lesser, + const sbp_msg_ext_event_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ext_event_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ext_event_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ext_event_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ext_event_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgExtEvent, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgExtEvent, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgExtEvent, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgExtEvent, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_ext_events_MsgExtEvent0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ext_event_t test_msg_{}; + uint8_t encoded_frame_[12 + 8] = { 85, 1, 1, 245, 6, 12, 48, 7, 199, 216, 49, 15, 202, 65, 15, 0, 3, 0, 62, 204, }; + uint8_t encoded_payload_[12] = { + 48, 7, 199, 216, 49, 15, 202, 65, 15, 0, 3, 0, + }; +}; - sbp_msg_ext_event_t test_msg{}; - test_msg.flags = 3; - test_msg.ns_residual = 999882; - test_msg.pin = 0; - test_msg.tow = 254924999; - test_msg.wn = 1840; - - EXPECT_EQ(send_message(1781, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1781); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 3) - << "incorrect value for last_msg_.flags, expected 3, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 999882) - << "incorrect value for last_msg_.ns_residual, expected 999882, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.pin, 0) - << "incorrect value for last_msg_.pin, expected 0, is " << last_msg_.pin; - EXPECT_EQ(last_msg_.tow, 254924999) - << "incorrect value for last_msg_.tow, expected 254924999, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1840) - << "incorrect value for last_msg_.wn, expected 1840, is " << last_msg_.wn; +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ext_event_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgExtEvent, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ext_event_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgExtEvent, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + EXPECT_EQ( + sbp_msg_ext_event_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_msg_ext_event_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ext_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ext_event_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgExtEvent, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ext_event_t msg{}; + + EXPECT_EQ(sbp_msg_ext_event_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ext_event_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_ext_event_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ext_event_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgExtEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgExtEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgExtEvent, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ext_event_t lesser = info.test_msg; + sbp_msg_ext_event_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_ext_event_t lesser = info.test_msg; + sbp_msg_ext_event_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ext_event_t lesser = info.test_msg; + sbp_msg_ext_event_t greater = info.test_msg; + make_lesser_greater(lesser.pin, greater.pin); + comparison_tests(lesser, greater); + } + { + sbp_msg_ext_event_t lesser = info.test_msg; + sbp_msg_ext_event_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ext_event_t lesser = info.test_msg; + sbp_msg_ext_event_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgExtEvent); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_EXT_EVENT"); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ext_event_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ext_event_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ext_event, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ext_event, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ext_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgExtEvent, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ext_events_MsgExtEvent0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgExtEvent, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc new file mode 100644 index 0000000000..ca31a1aba4 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc @@ -0,0 +1,785 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioConfigReq0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioConfigReq0() { + assign(test_msg_.sequence, 1514527339); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_config_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_config_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioConfigReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_config_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioConfigReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_config_req, + sizeof(msg->fileio_config_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_config_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_config_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioConfigReq); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x1bb9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_config_req_t &lesser, + const sbp_msg_fileio_config_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_config_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_config_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_config_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_config_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioConfigReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioConfigReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioConfigReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioConfigReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_config_req_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27, + }; + uint8_t encoded_payload_[4] = { + 107, + 218, + 69, + 90, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_config_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioConfigReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_config_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioConfigReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_fileio_config_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_msg_fileio_config_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_config_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioConfigReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_req_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_config_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_fileio_config_req_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_config_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioConfigReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioConfigReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioConfigReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_config_req_t lesser = info.test_msg; + sbp_msg_fileio_config_req_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioConfigReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_CONFIG_REQ"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_config_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_config_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.fileio_config_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_config_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioConfigReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioConfigReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc new file mode 100644 index 0000000000..d5a00b3247 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc @@ -0,0 +1,808 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioConfigResp0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioConfigResp0() { + assign(test_msg_.batch_size, 1040160728); + assign(test_msg_.fileio_version, 2420269324); + assign(test_msg_.sequence, 1530154154); + assign(test_msg_.window_size, 53262997); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_config_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_config_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioConfigResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_config_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioConfigResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_config_resp, + sizeof(msg->fileio_config_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_config_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_config_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioConfigResp); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x73ef; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_config_resp_t &lesser, + const sbp_msg_fileio_config_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_config_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_config_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_config_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_config_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioConfigResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioConfigResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioConfigResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioConfigResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_config_resp_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, + 44, 3, 216, 151, 255, 61, 12, 97, 66, 144, 239, 115, + }; + uint8_t encoded_payload_[16] = { + 170, 76, 52, 91, 149, 186, 44, 3, 216, 151, 255, 61, 12, 97, 66, 144, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_config_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioConfigResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_config_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioConfigResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_fileio_config_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_fileio_config_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_config_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioConfigResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_resp_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_config_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_fileio_config_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_config_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioConfigResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioConfigResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioConfigResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_config_resp_t lesser = info.test_msg; + sbp_msg_fileio_config_resp_t greater = info.test_msg; + make_lesser_greater(lesser.batch_size, greater.batch_size); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_config_resp_t lesser = info.test_msg; + sbp_msg_fileio_config_resp_t greater = info.test_msg; + make_lesser_greater(lesser.fileio_version, greater.fileio_version); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_config_resp_t lesser = info.test_msg; + sbp_msg_fileio_config_resp_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_config_resp_t lesser = info.test_msg; + sbp_msg_fileio_config_resp_t greater = info.test_msg; + make_lesser_greater(lesser.window_size, greater.window_size); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioConfigResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_CONFIG_RESP"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_config_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_config_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.fileio_config_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_config_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_config_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioConfigResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioConfigResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioConfigResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc new file mode 100644 index 0000000000..49a77b2bcf --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc @@ -0,0 +1,953 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioReadDirReq0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioReadDirReq0() { + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_set( + &test_msg_, "/some/random/path", false, &written)); + EXPECT_EQ(written, strlen("/some/random/path")); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_dirname_encoded_len(&test_msg_), 18); + assign(test_msg_.offset, 2251261636); + assign(test_msg_.sequence, 1526720386); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_dir_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_read_dir_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioReadDirReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_dir_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioReadDirReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_read_dir_req, + sizeof(msg->fileio_read_dir_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_read_dir_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_read_dir_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioReadDirReq); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xba1a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_read_dir_req_t &lesser, + const sbp_msg_fileio_read_dir_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_read_dir_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_read_dir_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadDirReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadDirReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioReadDirReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioReadDirReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_read_dir_req_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, + 47, 134, 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, + 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + }; + uint8_t encoded_payload_[26] = { + 130, 231, 255, 90, 196, 134, 47, 134, 47, 115, 111, 109, 101, + 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, 104, 0, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioReadDirReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioReadDirReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ( + sbp_msg_fileio_read_dir_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioReadDirReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_req_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_FILEIO_READ_DIR_REQ_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_fileio_read_dir_req_t t{}; return + // sbp_msg_fileio_read_dir_req_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_read_dir_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadDirReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioReadDirReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadDirReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_read_dir_req_t lesser = info.test_msg; + sbp_msg_fileio_read_dir_req_t greater = info.test_msg; + make_lesser_greater(lesser.dirname, greater.dirname); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_dir_req_t lesser = info.test_msg; + sbp_msg_fileio_read_dir_req_t greater = info.test_msg; + make_lesser_greater(lesser.offset, greater.offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_dir_req_t lesser = info.test_msg; + sbp_msg_fileio_read_dir_req_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioReadDirReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_READ_DIR_REQ"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_read_dir_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_read_dir_req_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.fileio_read_dir_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_read_dir_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioReadDirReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioReadDirReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname + : public Testauto_check_sbp_file_io_MsgFileioReadDirReq0 {}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, StringInit) { + sbp_msg_fileio_read_dir_req_t t{}; + sbp_msg_fileio_read_dir_req_dirname_init(&t); + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, IsValid) { + sbp_msg_fileio_read_dir_req_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_set(&t, "/some/random/path", + false, &written)); + EXPECT_EQ(written, strlen("/some/random/path")); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_dirname_encoded_len(&t), 18); + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, + SpaceRemaining) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t empty_space_remaining = + sbp_msg_fileio_read_dir_req_dirname_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_set(&t, "/some/random/path", + false, &written)); + EXPECT_EQ(written, strlen("/some/random/path")); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_dirname_encoded_len(&t), 18); + size_t assigned_space_remaining = + sbp_msg_fileio_read_dir_req_dirname_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_req_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_set_raw( + &t, info.test_msg.dirname.data, + sbp_msg_fileio_read_dir_req_dirname_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_fileio_read_dir_req_dirname_encoded_len(&info.test_msg), + sbp_msg_fileio_read_dir_req_dirname_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, Set) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t nwritten{}; + const char *text = "/some/random/path"; + + EXPECT_TRUE( + sbp_msg_fileio_read_dir_req_dirname_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, Printf) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t nwritten{}; + const char *text = "/some/random/path"; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_printf(&t, false, &nwritten, + "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, Vprintf) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t nwritten{}; + const char *text = "/some/random/path"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_dir_req_dirname_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, AppendPrintf) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t nwritten{}; + char part1[] = "/some/random/path"; + char part2[] = "/some/random/path"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), + "/some/random/path"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirReq0_dirname, AppendVprintf) { + sbp_msg_fileio_read_dir_req_t t{}; + size_t nwritten{}; + char part1[] = "/some/random/path"; + char part2[] = "/some/random/path"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_req_dirname_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_dir_req_dirname_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_dir_req_dirname_get(&t), + "/some/random/path"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc new file mode 100644 index 0000000000..a5c579dcf0 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc @@ -0,0 +1,1020 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioReadDirResp0 + : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioReadDirResp0() { + EXPECT_TRUE( + sbp_msg_fileio_read_dir_resp_contents_add_section(&test_msg_, "file1")); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section( + &test_msg_, "another file")); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section( + &test_msg_, "definitely not a file")); + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_contents_encoded_len(&test_msg_), + 41); + assign(test_msg_.sequence, 3957390670); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_dir_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_read_dir_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioReadDirResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_dir_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioReadDirResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_read_dir_resp, + sizeof(msg->fileio_read_dir_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_read_dir_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_read_dir_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioReadDirResp); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x89ba; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 45; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_read_dir_resp_t &lesser, + const sbp_msg_fileio_read_dir_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_read_dir_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_read_dir_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadDirResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadDirResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioReadDirResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioReadDirResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_read_dir_resp_t test_msg_{}; + uint8_t encoded_frame_[45 + 8] = { + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, + 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, 108, 101, + 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, 111, + 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + }; + uint8_t encoded_payload_[45] = { + 78, 253, 224, 235, 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, + 101, 114, 32, 102, 105, 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, + 101, 108, 121, 32, 110, 111, 116, 32, 97, 32, 102, 105, 108, 101, 0, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioReadDirResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioReadDirResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + + for (uint8_t i = 0; i < 45; i++) { + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioReadDirResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_resp_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_FILEIO_READ_DIR_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_fileio_read_dir_resp_t t{}; return + // sbp_msg_fileio_read_dir_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadDirResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioReadDirResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadDirResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_read_dir_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_dir_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents, greater.contents); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_dir_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_dir_resp_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioReadDirResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_READ_DIR_RESP"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_read_dir_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_read_dir_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.fileio_read_dir_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_read_dir_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_dir_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioReadDirResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioReadDirResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents + : public Testauto_check_sbp_file_io_MsgFileioReadDirResp0 {}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, StringInit) { + sbp_msg_fileio_read_dir_resp_t t{}; + sbp_msg_fileio_read_dir_resp_contents_init(&t); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, IsValid) { + sbp_msg_fileio_read_dir_resp_t t{}; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section(&t, "file1")); + EXPECT_TRUE( + sbp_msg_fileio_read_dir_resp_contents_add_section(&t, "another file")); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section( + &t, "definitely not a file")); + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_contents_encoded_len(&t), 41); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + SpaceRemaining) { + sbp_msg_fileio_read_dir_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_fileio_read_dir_resp_contents_space_remaining(&t); + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section(&t, "file1")); + EXPECT_TRUE( + sbp_msg_fileio_read_dir_resp_contents_add_section(&t, "another file")); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section( + &t, "definitely not a file")); + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_contents_encoded_len(&t), 41); + size_t assigned_space_remaining = + sbp_msg_fileio_read_dir_resp_contents_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp_msg_fileio_read_dir_resp_contents_count_sections(&info.test_msg), 3); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + AddSectionPrintf) { + sbp_msg_fileio_read_dir_resp_t t{}; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section_printf( + &t, "%s", "file1")); + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section_printf( + &t, "%s", "another file")); + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_add_section_printf( + &t, "%s", "definitely not a file")); + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_contents_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), + "file1"); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 1), + "another file"); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 2), + "definitely not a file"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + AddSectionVprintf) { + sbp_msg_fileio_read_dir_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_dir_resp_contents_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "file1")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_dir_resp_contents_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "another file")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_dir_resp_contents_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "definitely not a file")); + } + + EXPECT_EQ(sbp_msg_fileio_read_dir_resp_contents_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), + "file1"); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 1), + "another file"); + + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 2), + "definitely not a file"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, Append) { + sbp_msg_fileio_read_dir_resp_t t{}; + + char part1[] = "file1"; + char part2[] = "file1"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_append(&t, part1)); + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_fileio_read_dir_resp_contents_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), + "file1"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + AppendPrintf) { + sbp_msg_fileio_read_dir_resp_t t{}; + + char part1[] = "file1"; + char part2[] = "file1"; + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_fileio_read_dir_resp_contents_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_fileio_read_dir_resp_contents_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), + "file1"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + AppendVprintf) { + sbp_msg_fileio_read_dir_resp_t t{}; + + char part1[] = "file1"; + char part2[] = "file1"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_fileio_read_dir_resp_contents_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_fileio_read_dir_resp_contents_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_fileio_read_dir_resp_contents_get_section(&t, 0), + "file1"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadDirResp0_contents, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ( + sbp_msg_fileio_read_dir_resp_contents_section_strlen(&info.test_msg, 0), + strlen("file1")); + + EXPECT_EQ( + sbp_msg_fileio_read_dir_resp_contents_section_strlen(&info.test_msg, 1), + strlen("another file")); + + EXPECT_EQ( + sbp_msg_fileio_read_dir_resp_contents_section_strlen(&info.test_msg, 2), + strlen("definitely not a file")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc new file mode 100644 index 0000000000..cae1d5d259 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc @@ -0,0 +1,952 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioReadReq0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioReadReq0() { + assign(test_msg_.chunk_size, 53); + + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_set( + &test_msg_, "/path/to/some/file", false, &written)); + EXPECT_EQ(written, strlen("/path/to/some/file")); + EXPECT_EQ(sbp_msg_fileio_read_req_filename_encoded_len(&test_msg_), 19); + assign(test_msg_.offset, 398373474); + assign(test_msg_.sequence, 679648290); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_read_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioReadReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioReadReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_read_req, + sizeof(msg->fileio_read_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_read_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_read_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioReadReq); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6456; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 28; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_read_req_t &lesser, + const sbp_msg_fileio_read_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_read_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_read_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_read_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_read_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFileioReadReq, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFileioReadReq, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFileioReadReq, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_read_req_t test_msg_{}; + uint8_t encoded_frame_[28 + 8] = { + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, + 190, 23, 53, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + }; + uint8_t encoded_payload_[28] = { + 34, 156, 130, 40, 98, 178, 190, 23, 53, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_read_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioReadReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_read_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioReadReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + + EXPECT_EQ(sbp_msg_fileio_read_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + + for (uint8_t i = 0; i < 28; i++) { + EXPECT_EQ( + sbp_msg_fileio_read_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_read_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioReadReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_req_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_read_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_FILEIO_READ_REQ_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_fileio_read_req_t t{}; return + // sbp_msg_fileio_read_req_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_fileio_read_req_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_read_req_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_read_req_t lesser = info.test_msg; + sbp_msg_fileio_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.chunk_size, greater.chunk_size); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_req_t lesser = info.test_msg; + sbp_msg_fileio_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.filename, greater.filename); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_req_t lesser = info.test_msg; + sbp_msg_fileio_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.offset, greater.offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_req_t lesser = info.test_msg; + sbp_msg_fileio_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioReadReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_READ_REQ"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_read_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_read_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.fileio_read_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_read_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioReadReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioReadReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_file_io_MsgFileioReadReq0_filename + : public Testauto_check_sbp_file_io_MsgFileioReadReq0 {}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, StringInit) { + sbp_msg_fileio_read_req_t t{}; + sbp_msg_fileio_read_req_filename_init(&t); + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, IsValid) { + sbp_msg_fileio_read_req_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_set(&t, "/path/to/some/file", + false, &written)); + EXPECT_EQ(written, strlen("/path/to/some/file")); + EXPECT_EQ(sbp_msg_fileio_read_req_filename_encoded_len(&t), 19); + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, SpaceRemaining) { + sbp_msg_fileio_read_req_t t{}; + size_t empty_space_remaining = + sbp_msg_fileio_read_req_filename_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_set(&t, "/path/to/some/file", + false, &written)); + EXPECT_EQ(written, strlen("/path/to/some/file")); + EXPECT_EQ(sbp_msg_fileio_read_req_filename_encoded_len(&t), 19); + size_t assigned_space_remaining = + sbp_msg_fileio_read_req_filename_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_req_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_set_raw( + &t, info.test_msg.filename.data, + sbp_msg_fileio_read_req_filename_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_fileio_read_req_filename_encoded_len(&info.test_msg), + sbp_msg_fileio_read_req_filename_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, Set) { + sbp_msg_fileio_read_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/some/file"; + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, Printf) { + sbp_msg_fileio_read_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/some/file"; + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_printf(&t, false, &nwritten, + "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, Vprintf) { + sbp_msg_fileio_read_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/some/file"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_req_filename_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, AppendPrintf) { + sbp_msg_fileio_read_req_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/some/file"; + char part2[] = "/path/to/some/file"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), "/path/to/some/file"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadReq0_filename, AppendVprintf) { + sbp_msg_fileio_read_req_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/some/file"; + char part2[] = "/path/to/some/file"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_read_req_filename_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_read_req_filename_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_read_req_filename_get(&t), "/path/to/some/file"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc new file mode 100644 index 0000000000..4494b45a64 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc @@ -0,0 +1,3095 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioReadResp0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioReadResp0() { + assign(test_msg_.contents[0], 73); + + assign(test_msg_.contents[1], 231); + + assign(test_msg_.contents[2], 227); + + assign(test_msg_.contents[3], 179); + + assign(test_msg_.contents[4], 18); + + assign(test_msg_.contents[5], 76); + + assign(test_msg_.contents[6], 68); + + assign(test_msg_.contents[7], 229); + + assign(test_msg_.contents[8], 216); + + assign(test_msg_.contents[9], 21); + + assign(test_msg_.contents[10], 98); + + assign(test_msg_.contents[11], 183); + + assign(test_msg_.contents[12], 69); + + assign(test_msg_.contents[13], 190); + + assign(test_msg_.contents[14], 5); + + assign(test_msg_.contents[15], 252); + + assign(test_msg_.contents[16], 176); + + assign(test_msg_.contents[17], 55); + + assign(test_msg_.contents[18], 32); + + assign(test_msg_.contents[19], 78); + + assign(test_msg_.contents[20], 8); + + assign(test_msg_.contents[21], 52); + + assign(test_msg_.contents[22], 127); + + assign(test_msg_.contents[23], 50); + + assign(test_msg_.contents[24], 71); + + assign(test_msg_.contents[25], 106); + + assign(test_msg_.contents[26], 61); + + assign(test_msg_.contents[27], 79); + + assign(test_msg_.contents[28], 191); + + assign(test_msg_.contents[29], 106); + + assign(test_msg_.contents[30], 46); + + assign(test_msg_.contents[31], 79); + + assign(test_msg_.contents[32], 118); + + assign(test_msg_.contents[33], 248); + + assign(test_msg_.contents[34], 118); + + assign(test_msg_.contents[35], 207); + + assign(test_msg_.contents[36], 206); + + assign(test_msg_.contents[37], 210); + + assign(test_msg_.contents[38], 91); + + assign(test_msg_.contents[39], 73); + + assign(test_msg_.contents[40], 251); + + assign(test_msg_.contents[41], 81); + + assign(test_msg_.contents[42], 131); + + assign(test_msg_.contents[43], 205); + + assign(test_msg_.contents[44], 193); + + assign(test_msg_.contents[45], 146); + + assign(test_msg_.contents[46], 206); + + assign(test_msg_.contents[47], 185); + + assign(test_msg_.contents[48], 140); + + assign(test_msg_.contents[49], 249); + + assign(test_msg_.contents[50], 163); + + assign(test_msg_.contents[51], 231); + + assign(test_msg_.contents[52], 65); + + assign(test_msg_.contents[53], 67); + + assign(test_msg_.contents[54], 94); + + assign(test_msg_.contents[55], 250); + + assign(test_msg_.contents[56], 109); + + assign(test_msg_.contents[57], 152); + + assign(test_msg_.contents[58], 95); + + assign(test_msg_.contents[59], 123); + + assign(test_msg_.contents[60], 77); + + assign(test_msg_.contents[61], 224); + + assign(test_msg_.contents[62], 124); + + assign(test_msg_.contents[63], 238); + + assign(test_msg_.contents[64], 205); + + assign(test_msg_.contents[65], 65); + + assign(test_msg_.contents[66], 103); + + assign(test_msg_.contents[67], 35); + + assign(test_msg_.contents[68], 104); + + assign(test_msg_.contents[69], 209); + + assign(test_msg_.contents[70], 5); + + assign(test_msg_.contents[71], 191); + + assign(test_msg_.contents[72], 47); + + assign(test_msg_.contents[73], 249); + + assign(test_msg_.contents[74], 176); + + assign(test_msg_.contents[75], 166); + + assign(test_msg_.contents[76], 213); + + assign(test_msg_.contents[77], 46); + + assign(test_msg_.contents[78], 192); + + assign(test_msg_.contents[79], 86); + + assign(test_msg_.contents[80], 32); + + assign(test_msg_.contents[81], 103); + + assign(test_msg_.contents[82], 146); + + assign(test_msg_.contents[83], 252); + + assign(test_msg_.contents[84], 4); + + assign(test_msg_.contents[85], 16); + + assign(test_msg_.contents[86], 54); + + assign(test_msg_.contents[87], 161); + + assign(test_msg_.contents[88], 60); + + assign(test_msg_.contents[89], 6); + + assign(test_msg_.contents[90], 13); + + assign(test_msg_.contents[91], 191); + + assign(test_msg_.contents[92], 116); + + assign(test_msg_.contents[93], 182); + + assign(test_msg_.contents[94], 42); + + assign(test_msg_.contents[95], 191); + + assign(test_msg_.contents[96], 213); + + assign(test_msg_.contents[97], 20); + + assign(test_msg_.contents[98], 217); + + assign(test_msg_.contents[99], 8); + + assign(test_msg_.contents[100], 142); + + assign(test_msg_.contents[101], 187); + + assign(test_msg_.contents[102], 238); + + assign(test_msg_.contents[103], 120); + + assign(test_msg_.contents[104], 184); + + assign(test_msg_.contents[105], 250); + + assign(test_msg_.contents[106], 31); + + assign(test_msg_.contents[107], 151); + + assign(test_msg_.contents[108], 37); + + assign(test_msg_.contents[109], 51); + + assign(test_msg_.contents[110], 177); + + assign(test_msg_.contents[111], 130); + + assign(test_msg_.contents[112], 190); + + assign(test_msg_.contents[113], 155); + + assign(test_msg_.contents[114], 71); + + assign(test_msg_.contents[115], 68); + + assign(test_msg_.contents[116], 56); + + assign(test_msg_.contents[117], 238); + + assign(test_msg_.contents[118], 92); + + assign(test_msg_.contents[119], 130); + + assign(test_msg_.contents[120], 37); + + assign(test_msg_.contents[121], 137); + + assign(test_msg_.contents[122], 146); + + assign(test_msg_.contents[123], 246); + + assign(test_msg_.contents[124], 114); + + assign(test_msg_.contents[125], 116); + + assign(test_msg_.contents[126], 138); + + assign(test_msg_.contents[127], 165); + + assign(test_msg_.contents[128], 217); + + assign(test_msg_.contents[129], 79); + + assign(test_msg_.contents[130], 10); + + assign(test_msg_.contents[131], 189); + + assign(test_msg_.contents[132], 128); + + assign(test_msg_.contents[133], 189); + + assign(test_msg_.contents[134], 2); + + assign(test_msg_.contents[135], 240); + + assign(test_msg_.contents[136], 92); + + assign(test_msg_.contents[137], 28); + + assign(test_msg_.contents[138], 126); + + assign(test_msg_.contents[139], 105); + + assign(test_msg_.contents[140], 236); + + assign(test_msg_.contents[141], 228); + + assign(test_msg_.contents[142], 194); + + assign(test_msg_.contents[143], 0); + + assign(test_msg_.contents[144], 51); + + assign(test_msg_.contents[145], 61); + + assign(test_msg_.contents[146], 74); + + assign(test_msg_.contents[147], 41); + + assign(test_msg_.contents[148], 10); + + assign(test_msg_.contents[149], 239); + + assign(test_msg_.contents[150], 133); + + assign(test_msg_.contents[151], 106); + + assign(test_msg_.contents[152], 190); + + assign(test_msg_.contents[153], 30); + + assign(test_msg_.contents[154], 27); + + assign(test_msg_.contents[155], 3); + + assign(test_msg_.contents[156], 240); + + assign(test_msg_.contents[157], 205); + + assign(test_msg_.contents[158], 253); + + assign(test_msg_.contents[159], 113); + + assign(test_msg_.contents[160], 25); + + assign(test_msg_.contents[161], 28); + + assign(test_msg_.contents[162], 187); + + assign(test_msg_.contents[163], 81); + + assign(test_msg_.contents[164], 101); + + assign(test_msg_.contents[165], 216); + + assign(test_msg_.contents[166], 121); + + assign(test_msg_.contents[167], 41); + + assign(test_msg_.contents[168], 179); + + assign(test_msg_.contents[169], 120); + + assign(test_msg_.contents[170], 152); + + assign(test_msg_.contents[171], 18); + + assign(test_msg_.contents[172], 116); + + assign(test_msg_.contents[173], 53); + + assign(test_msg_.contents[174], 212); + + assign(test_msg_.contents[175], 100); + + assign(test_msg_.contents[176], 2); + + assign(test_msg_.contents[177], 114); + + assign(test_msg_.contents[178], 198); + + assign(test_msg_.contents[179], 200); + + assign(test_msg_.contents[180], 10); + + assign(test_msg_.contents[181], 147); + + assign(test_msg_.contents[182], 25); + + assign(test_msg_.contents[183], 33); + + assign(test_msg_.contents[184], 115); + + assign(test_msg_.contents[185], 208); + + assign(test_msg_.contents[186], 113); + + assign(test_msg_.contents[187], 60); + + assign(test_msg_.contents[188], 179); + + assign(test_msg_.contents[189], 183); + + assign(test_msg_.contents[190], 0); + + assign(test_msg_.contents[191], 41); + + assign(test_msg_.contents[192], 217); + + assign(test_msg_.contents[193], 206); + + assign(test_msg_.contents[194], 255); + + assign(test_msg_.contents[195], 211); + + assign(test_msg_.contents[196], 225); + + assign(test_msg_.contents[197], 142); + + assign(test_msg_.contents[198], 191); + + assign(test_msg_.contents[199], 133); + + assign(test_msg_.contents[200], 81); + + assign(test_msg_.contents[201], 15); + + assign(test_msg_.contents[202], 248); + + assign(test_msg_.contents[203], 193); + + assign(test_msg_.contents[204], 66); + + assign(test_msg_.contents[205], 191); + + assign(test_msg_.contents[206], 244); + + assign(test_msg_.contents[207], 221); + + assign(test_msg_.contents[208], 248); + + assign(test_msg_.contents[209], 199); + + assign(test_msg_.contents[210], 241); + + assign(test_msg_.contents[211], 112); + + assign(test_msg_.contents[212], 51); + + assign(test_msg_.contents[213], 1); + + assign(test_msg_.contents[214], 180); + + assign(test_msg_.contents[215], 180); + + assign(test_msg_.contents[216], 125); + + assign(test_msg_.contents[217], 97); + + assign(test_msg_.contents[218], 145); + + assign(test_msg_.contents[219], 25); + + assign(test_msg_.contents[220], 72); + + assign(test_msg_.contents[221], 210); + + assign(test_msg_.contents[222], 215); + + assign(test_msg_.contents[223], 208); + + assign(test_msg_.contents[224], 15); + + assign(test_msg_.contents[225], 126); + + assign(test_msg_.contents[226], 56); + + assign(test_msg_.contents[227], 38); + + assign(test_msg_.contents[228], 65); + + assign(test_msg_.contents[229], 4); + + assign(test_msg_.contents[230], 64); + + assign(test_msg_.contents[231], 19); + + assign(test_msg_.contents[232], 74); + + assign(test_msg_.contents[233], 223); + + assign(test_msg_.contents[234], 111); + + assign(test_msg_.contents[235], 109); + + assign(test_msg_.contents[236], 52); + + assign(test_msg_.contents[237], 43); + + assign(test_msg_.contents[238], 167); + + assign(test_msg_.contents[239], 186); + + assign(test_msg_.contents[240], 202); + + assign(test_msg_.contents[241], 111); + + assign(test_msg_.contents[242], 11); + + assign(test_msg_.contents[243], 91); + + assign(test_msg_.contents[244], 21); + + assign(test_msg_.contents[245], 236); + + assign(test_msg_.contents[246], 234); + + assign(test_msg_.contents[247], 196); + + assign(test_msg_.contents[248], 36); + + assign(test_msg_.contents[249], 171); + + assign(test_msg_.contents[250], 147); + assign(test_msg_.n_contents, 251); + assign(test_msg_.sequence, 259241795); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_read_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioReadResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_read_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioReadResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_read_resp, + sizeof(msg->fileio_read_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_read_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_read_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioReadResp); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xf00a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_read_resp_t &lesser, + const sbp_msg_fileio_read_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_read_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_read_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_read_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_read_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFileioReadResp, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioReadResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioReadResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioReadResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_read_resp_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, 18, + 76, 68, 229, 216, 21, 98, 183, 69, 190, 5, 252, 176, 55, 32, 78, + 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, 46, 79, 118, 248, 118, + 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, 206, 185, 140, 249, + 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, 77, 224, 124, 238, 205, + 65, 103, 35, 104, 209, 5, 191, 47, 249, 176, 166, 213, 46, 192, 86, + 32, 103, 146, 252, 4, 16, 54, 161, 60, 6, 13, 191, 116, 182, 42, + 191, 213, 20, 217, 8, 142, 187, 238, 120, 184, 250, 31, 151, 37, 51, + 177, 130, 190, 155, 71, 68, 56, 238, 92, 130, 37, 137, 146, 246, 114, + 116, 138, 165, 217, 79, 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, + 236, 228, 194, 0, 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, + 3, 240, 205, 253, 113, 25, 28, 187, 81, 101, 216, 121, 41, 179, 120, + 152, 18, 116, 53, 212, 100, 2, 114, 198, 200, 10, 147, 25, 33, 115, + 208, 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, 133, + 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, 180, + 180, 125, 97, 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, 65, 4, + 64, 19, 74, 223, 111, 109, 52, 43, 167, 186, 202, 111, 11, 91, 21, + 236, 234, 196, 36, 171, 147, 10, 240, + }; + uint8_t encoded_payload_[255] = { + 67, 183, 115, 15, 73, 231, 227, 179, 18, 76, 68, 229, 216, 21, 98, + 183, 69, 190, 5, 252, 176, 55, 32, 78, 8, 52, 127, 50, 71, 106, + 61, 79, 191, 106, 46, 79, 118, 248, 118, 207, 206, 210, 91, 73, 251, + 81, 131, 205, 193, 146, 206, 185, 140, 249, 163, 231, 65, 67, 94, 250, + 109, 152, 95, 123, 77, 224, 124, 238, 205, 65, 103, 35, 104, 209, 5, + 191, 47, 249, 176, 166, 213, 46, 192, 86, 32, 103, 146, 252, 4, 16, + 54, 161, 60, 6, 13, 191, 116, 182, 42, 191, 213, 20, 217, 8, 142, + 187, 238, 120, 184, 250, 31, 151, 37, 51, 177, 130, 190, 155, 71, 68, + 56, 238, 92, 130, 37, 137, 146, 246, 114, 116, 138, 165, 217, 79, 10, + 189, 128, 189, 2, 240, 92, 28, 126, 105, 236, 228, 194, 0, 51, 61, + 74, 41, 10, 239, 133, 106, 190, 30, 27, 3, 240, 205, 253, 113, 25, + 28, 187, 81, 101, 216, 121, 41, 179, 120, 152, 18, 116, 53, 212, 100, + 2, 114, 198, 200, 10, 147, 25, 33, 115, 208, 113, 60, 179, 183, 0, + 41, 217, 206, 255, 211, 225, 142, 191, 133, 81, 15, 248, 193, 66, 191, + 244, 221, 248, 199, 241, 112, 51, 1, 180, 180, 125, 97, 145, 25, 72, + 210, 215, 208, 15, 126, 56, 38, 65, 4, 64, 19, 74, 223, 111, 109, + 52, 43, 167, 186, 202, 111, 11, 91, 21, 236, 234, 196, 36, 171, 147, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_read_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioReadResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_read_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioReadResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ(sbp_msg_fileio_read_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ( + sbp_msg_fileio_read_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_read_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioReadResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_resp_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_read_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_fileio_read_resp_t t{}; + return sbp_msg_fileio_read_resp_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_fileio_read_resp_t t{}; + t.n_contents = 1; + return sbp_msg_fileio_read_resp_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_fileio_read_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_read_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioReadResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[0], greater.contents[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[1], greater.contents[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[2], greater.contents[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[3], greater.contents[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[4], greater.contents[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[5], greater.contents[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[6], greater.contents[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[7], greater.contents[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[8], greater.contents[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[9], greater.contents[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[10], greater.contents[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[11], greater.contents[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[12], greater.contents[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[13], greater.contents[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[14], greater.contents[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[15], greater.contents[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[16], greater.contents[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[17], greater.contents[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[18], greater.contents[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[19], greater.contents[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[20], greater.contents[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[21], greater.contents[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[22], greater.contents[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[23], greater.contents[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[24], greater.contents[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[25], greater.contents[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[26], greater.contents[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[27], greater.contents[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[28], greater.contents[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[29], greater.contents[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[30], greater.contents[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[31], greater.contents[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[32], greater.contents[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[33], greater.contents[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[34], greater.contents[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[35], greater.contents[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[36], greater.contents[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[37], greater.contents[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[38], greater.contents[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[39], greater.contents[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[40], greater.contents[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[41], greater.contents[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[42], greater.contents[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[43], greater.contents[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[44], greater.contents[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[45], greater.contents[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[46], greater.contents[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[47], greater.contents[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[48], greater.contents[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[49], greater.contents[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[50], greater.contents[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[51], greater.contents[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[52], greater.contents[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[53], greater.contents[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[54], greater.contents[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[55], greater.contents[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[56], greater.contents[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[57], greater.contents[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[58], greater.contents[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[59], greater.contents[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[60], greater.contents[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[61], greater.contents[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[62], greater.contents[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[63], greater.contents[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[64], greater.contents[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[65], greater.contents[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[66], greater.contents[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[67], greater.contents[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[68], greater.contents[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[69], greater.contents[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[70], greater.contents[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[71], greater.contents[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[72], greater.contents[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[73], greater.contents[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[74], greater.contents[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[75], greater.contents[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[76], greater.contents[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[77], greater.contents[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[78], greater.contents[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[79], greater.contents[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[80], greater.contents[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[81], greater.contents[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[82], greater.contents[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[83], greater.contents[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[84], greater.contents[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[85], greater.contents[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[86], greater.contents[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[87], greater.contents[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[88], greater.contents[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[89], greater.contents[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[90], greater.contents[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[91], greater.contents[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[92], greater.contents[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[93], greater.contents[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[94], greater.contents[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[95], greater.contents[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[96], greater.contents[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[97], greater.contents[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[98], greater.contents[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[99], greater.contents[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[100], greater.contents[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[101], greater.contents[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[102], greater.contents[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[103], greater.contents[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[104], greater.contents[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[105], greater.contents[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[106], greater.contents[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[107], greater.contents[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[108], greater.contents[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[109], greater.contents[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[110], greater.contents[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[111], greater.contents[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[112], greater.contents[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[113], greater.contents[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[114], greater.contents[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[115], greater.contents[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[116], greater.contents[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[117], greater.contents[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[118], greater.contents[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[119], greater.contents[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[120], greater.contents[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[121], greater.contents[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[122], greater.contents[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[123], greater.contents[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[124], greater.contents[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[125], greater.contents[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[126], greater.contents[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[127], greater.contents[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[128], greater.contents[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[129], greater.contents[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[130], greater.contents[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[131], greater.contents[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[132], greater.contents[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[133], greater.contents[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[134], greater.contents[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[135], greater.contents[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[136], greater.contents[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[137], greater.contents[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[138], greater.contents[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[139], greater.contents[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[140], greater.contents[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[141], greater.contents[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[142], greater.contents[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[143], greater.contents[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[144], greater.contents[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[145], greater.contents[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[146], greater.contents[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[147], greater.contents[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[148], greater.contents[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[149], greater.contents[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[150], greater.contents[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[151], greater.contents[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[152], greater.contents[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[153], greater.contents[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[154], greater.contents[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[155], greater.contents[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[156], greater.contents[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[157], greater.contents[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[158], greater.contents[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[159], greater.contents[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[160], greater.contents[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[161], greater.contents[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[162], greater.contents[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[163], greater.contents[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[164], greater.contents[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[165], greater.contents[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[166], greater.contents[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[167], greater.contents[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[168], greater.contents[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[169], greater.contents[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[170], greater.contents[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[171], greater.contents[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[172], greater.contents[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[173], greater.contents[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[174], greater.contents[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[175], greater.contents[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[176], greater.contents[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[177], greater.contents[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[178], greater.contents[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[179], greater.contents[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[180], greater.contents[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[181], greater.contents[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[182], greater.contents[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[183], greater.contents[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[184], greater.contents[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[185], greater.contents[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[186], greater.contents[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[187], greater.contents[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[188], greater.contents[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[189], greater.contents[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[190], greater.contents[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[191], greater.contents[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[192], greater.contents[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[193], greater.contents[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[194], greater.contents[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[195], greater.contents[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[196], greater.contents[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[197], greater.contents[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[198], greater.contents[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[199], greater.contents[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[200], greater.contents[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[201], greater.contents[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[202], greater.contents[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[203], greater.contents[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[204], greater.contents[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[205], greater.contents[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[206], greater.contents[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[207], greater.contents[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[208], greater.contents[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[209], greater.contents[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[210], greater.contents[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[211], greater.contents[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[212], greater.contents[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[213], greater.contents[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[214], greater.contents[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[215], greater.contents[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[216], greater.contents[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[217], greater.contents[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[218], greater.contents[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[219], greater.contents[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[220], greater.contents[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[221], greater.contents[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[222], greater.contents[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[223], greater.contents[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[224], greater.contents[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[225], greater.contents[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[226], greater.contents[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[227], greater.contents[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[228], greater.contents[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[229], greater.contents[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[230], greater.contents[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[231], greater.contents[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[232], greater.contents[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[233], greater.contents[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[234], greater.contents[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[235], greater.contents[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[236], greater.contents[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[237], greater.contents[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[238], greater.contents[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[239], greater.contents[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[240], greater.contents[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[241], greater.contents[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[242], greater.contents[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[243], greater.contents[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[244], greater.contents[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[245], greater.contents[245]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[246], greater.contents[246]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[247], greater.contents[247]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[248], greater.contents[248]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[249], greater.contents[249]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.contents[250], greater.contents[250]); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.n_contents, greater.n_contents); + comparison_tests(lesser, greater); + } + { + sbp_msg_fileio_read_resp_t lesser = info.test_msg; + sbp_msg_fileio_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioReadResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_READ_RESP"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_read_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_read_resp_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.fileio_read_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_read_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioReadResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioReadResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioReadResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc new file mode 100644 index 0000000000..16d2e5088e --- /dev/null +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc @@ -0,0 +1,922 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioRemove0 : public ::testing::Test { + public: + Testauto_check_sbp_file_io_MsgFileioRemove0() { + size_t written; + EXPECT_TRUE(sbp_msg_fileio_remove_filename_set(&test_msg_, "/path/to/file", + false, &written)); + EXPECT_EQ(written, strlen("/path/to/file")); + EXPECT_EQ(sbp_msg_fileio_remove_filename_encoded_len(&test_msg_), 14); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_remove_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_remove_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioRemove, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_remove_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioRemove); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_remove, + sizeof(msg->fileio_remove)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_remove_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_remove, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioRemove); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xf32e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_fileio_remove_t &lesser, + const sbp_msg_fileio_remove_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_remove_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_remove_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_remove_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_remove_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFileioRemove, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFileioRemove, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFileioRemove, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFileioRemove, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_remove_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 102, 105, 108, 101, 0, 46, 243, + }; + uint8_t encoded_payload_[14] = { + 47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_remove_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFileioRemove, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_remove_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioRemove, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ(sbp_msg_fileio_remove_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_fileio_remove_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_remove_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_remove_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioRemove, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_remove_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_remove_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_remove_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_FILEIO_REMOVE_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_fileio_remove_t t{}; return + // sbp_msg_fileio_remove_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_fileio_remove_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_remove_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioRemove, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioRemove, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioRemove, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_remove_t lesser = info.test_msg; + sbp_msg_fileio_remove_t greater = info.test_msg; + make_lesser_greater(lesser.filename, greater.filename); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioRemove); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_REMOVE"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_remove_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_remove_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.fileio_remove, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.fileio_remove, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_remove_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioRemove, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioRemove, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_file_io_MsgFileioRemove0_filename + : public Testauto_check_sbp_file_io_MsgFileioRemove0 {}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, StringInit) { + sbp_msg_fileio_remove_t t{}; + sbp_msg_fileio_remove_filename_init(&t); + EXPECT_TRUE(sbp_msg_fileio_remove_filename_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, IsValid) { + sbp_msg_fileio_remove_t t{}; + + size_t written; + EXPECT_TRUE( + sbp_msg_fileio_remove_filename_set(&t, "/path/to/file", false, &written)); + EXPECT_EQ(written, strlen("/path/to/file")); + EXPECT_EQ(sbp_msg_fileio_remove_filename_encoded_len(&t), 14); + EXPECT_TRUE(sbp_msg_fileio_remove_filename_valid(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, SpaceRemaining) { + sbp_msg_fileio_remove_t t{}; + size_t empty_space_remaining = + sbp_msg_fileio_remove_filename_space_remaining(&t); + + size_t written; + EXPECT_TRUE( + sbp_msg_fileio_remove_filename_set(&t, "/path/to/file", false, &written)); + EXPECT_EQ(written, strlen("/path/to/file")); + EXPECT_EQ(sbp_msg_fileio_remove_filename_encoded_len(&t), 14); + size_t assigned_space_remaining = + sbp_msg_fileio_remove_filename_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_fileio_remove_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_fileio_remove_filename_set_raw( + &t, info.test_msg.filename.data, + sbp_msg_fileio_remove_filename_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_fileio_remove_filename_encoded_len(&info.test_msg), + sbp_msg_fileio_remove_filename_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, Set) { + sbp_msg_fileio_remove_t t{}; + size_t nwritten{}; + const char *text = "/path/to/file"; + + EXPECT_TRUE(sbp_msg_fileio_remove_filename_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, Printf) { + sbp_msg_fileio_remove_t t{}; + size_t nwritten{}; + const char *text = "/path/to/file"; + + EXPECT_TRUE( + sbp_msg_fileio_remove_filename_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, Vprintf) { + sbp_msg_fileio_remove_t t{}; + size_t nwritten{}; + const char *text = "/path/to/file"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_remove_filename_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), text); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, AppendPrintf) { + sbp_msg_fileio_remove_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/file"; + char part2[] = "/path/to/file"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_remove_filename_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_fileio_remove_filename_append_printf(&t, false, &nwritten, + "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), "/path/to/file"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioRemove0_filename, AppendVprintf) { + sbp_msg_fileio_remove_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/file"; + char part2[] = "/path/to/file"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_fileio_remove_filename_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_fileio_remove_filename_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_fileio_remove_filename_get(&t), "/path/to/file"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_file_io_MsgFileioWriteResp.cc b/c/test/cpp/auto_check_sbp_file_io_MsgFileioWriteResp.cc index 5c28ff7902..89ff94cbf2 100644 --- a/c/test/cpp/auto_check_sbp_file_io_MsgFileioWriteResp.cc +++ b/c/test/cpp/auto_check_sbp_file_io_MsgFileioWriteResp.cc @@ -16,85 +16,770 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_file_io_MsgFileioWriteResp0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_file_io_MsgFileioWriteResp0 : public ::testing::Test { public: - Test_auto_check_sbp_file_io_MsgFileioWriteResp0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_file_io_MsgFileioWriteResp0() { + assign(test_msg_.sequence, 202); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_write_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_fileio_write_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFileioWriteResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fileio_write_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFileioWriteResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fileio_write_resp, + sizeof(msg->fileio_write_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fileio_write_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fileio_write_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFileioWriteResp); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xf3f3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_fileio_write_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_fileio_write_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_fileio_write_resp_t &lesser, + const sbp_msg_fileio_write_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fileio_write_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fileio_write_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fileio_write_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fileio_write_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioWriteResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFileioWriteResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFileioWriteResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFileioWriteResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_file_io_MsgFileioWriteResp0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fileio_write_resp_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 171, 0, 66, 0, 4, 202, 0, 0, 0, 243, 243, }; + uint8_t encoded_payload_[4] = { + 202, + 0, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fileio_write_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFileioWriteResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_fileio_write_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFileioWriteResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_fileio_write_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_msg_fileio_write_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_write_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fileio_write_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFileioWriteResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fileio_write_resp_t msg{}; + + EXPECT_EQ(sbp_msg_fileio_write_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fileio_write_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_fileio_write_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fileio_write_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioWriteResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_fileio_write_resp_t test_msg{}; - test_msg.sequence = 202; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + EXPECT_NE(sbp_message_send(&state, SbpMsgFileioWriteResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - while (dummy_rd_ < dummy_wr_) { - process(); + EXPECT_EQ(sbp_message_send(&state, SbpMsgFileioWriteResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_fileio_write_resp_t lesser = info.test_msg; + sbp_msg_fileio_write_resp_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); } +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFileioWriteResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FILEIO_WRITE_RESP"); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fileio_write_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fileio_write_resp_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.fileio_write_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.fileio_write_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.sequence, 202) - << "incorrect value for last_msg_.sequence, expected 202, is " - << last_msg_.sequence; + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); } + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fileio_write_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFileioWriteResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_file_io_MsgFileioWriteResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFileioWriteResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgFlashDone.cc b/c/test/cpp/auto_check_sbp_flash_MsgFlashDone.cc new file mode 100644 index 0000000000..f65d9c1560 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgFlashDone.cc @@ -0,0 +1,763 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgFlashDone0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgFlashDone0() { assign(test_msg_.response, 82); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_done_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_flash_done_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFlashDone, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_done_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFlashDone); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->flash_done, sizeof(msg->flash_done)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_flash_done_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.flash_done, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFlashDone); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x3606; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 1; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_flash_done_t &lesser, + const sbp_msg_flash_done_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_flash_done_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_flash_done_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_flash_done_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_flash_done_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashDone, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashDone, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFlashDone, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFlashDone, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_flash_done_t test_msg_{}; + uint8_t encoded_frame_[1 + 8] = { + 85, 224, 0, 195, 4, 1, 82, 6, 54, + }; + uint8_t encoded_payload_[1] = { + 82, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_flash_done_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFlashDone, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_flash_done_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFlashDone, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_flash_done_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_msg_flash_done_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_done_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_flash_done_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFlashDone, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_flash_done_t msg{}; + + EXPECT_EQ(sbp_msg_flash_done_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_flash_done_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_flash_done_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_flash_done_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashDone, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFlashDone, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashDone, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_flash_done_t lesser = info.test_msg; + sbp_msg_flash_done_t greater = info.test_msg; + make_lesser_greater(lesser.response, greater.response); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgFlashDone); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FLASH_DONE"); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_flash_done_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_flash_done_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.flash_done, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.flash_done, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_done_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFlashDone, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashDone0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFlashDone, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgFlashErase.cc b/c/test/cpp/auto_check_sbp_flash_MsgFlashErase.cc new file mode 100644 index 0000000000..6e95f36109 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgFlashErase.cc @@ -0,0 +1,774 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgFlashErase0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgFlashErase0() { + assign(test_msg_.sector_num, 2222371310); + assign(test_msg_.target, 74); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_erase_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_flash_erase_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFlashErase, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_erase_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFlashErase); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->flash_erase, sizeof(msg->flash_erase)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_flash_erase_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.flash_erase, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFlashErase); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xfb00; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 5; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_flash_erase_t &lesser, + const sbp_msg_flash_erase_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_flash_erase_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_flash_erase_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_flash_erase_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_flash_erase_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashErase, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashErase, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFlashErase, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFlashErase, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_flash_erase_t test_msg_{}; + uint8_t encoded_frame_[5 + 8] = { + 85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251, + }; + uint8_t encoded_payload_[5] = { + 74, 238, 177, 118, 132, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_flash_erase_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFlashErase, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_flash_erase_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFlashErase, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + EXPECT_EQ( + sbp_msg_flash_erase_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_msg_flash_erase_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_erase_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_flash_erase_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFlashErase, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_flash_erase_t msg{}; + + EXPECT_EQ(sbp_msg_flash_erase_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_flash_erase_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_flash_erase_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_flash_erase_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashErase, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFlashErase, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashErase, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_flash_erase_t lesser = info.test_msg; + sbp_msg_flash_erase_t greater = info.test_msg; + make_lesser_greater(lesser.sector_num, greater.sector_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_flash_erase_t lesser = info.test_msg; + sbp_msg_flash_erase_t greater = info.test_msg; + make_lesser_greater(lesser.target, greater.target); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgFlashErase); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FLASH_ERASE"); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_flash_erase_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_flash_erase_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.flash_erase, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.flash_erase, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_erase_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFlashErase, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashErase0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFlashErase, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgFlashProgram.cc b/c/test/cpp/auto_check_sbp_flash_MsgFlashProgram.cc new file mode 100644 index 0000000000..13aaa309d4 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgFlashProgram.cc @@ -0,0 +1,3107 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgFlashProgram0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgFlashProgram0() { + assign(test_msg_.addr_len, 250); + + assign(test_msg_.addr_start[0], 87); + + assign(test_msg_.addr_start[1], 52); + + assign(test_msg_.addr_start[2], 244); + + assign(test_msg_.data[0], 176); + + assign(test_msg_.data[1], 222); + + assign(test_msg_.data[2], 235); + + assign(test_msg_.data[3], 106); + + assign(test_msg_.data[4], 144); + + assign(test_msg_.data[5], 29); + + assign(test_msg_.data[6], 141); + + assign(test_msg_.data[7], 255); + + assign(test_msg_.data[8], 3); + + assign(test_msg_.data[9], 16); + + assign(test_msg_.data[10], 192); + + assign(test_msg_.data[11], 237); + + assign(test_msg_.data[12], 172); + + assign(test_msg_.data[13], 254); + + assign(test_msg_.data[14], 213); + + assign(test_msg_.data[15], 4); + + assign(test_msg_.data[16], 220); + + assign(test_msg_.data[17], 98); + + assign(test_msg_.data[18], 34); + + assign(test_msg_.data[19], 222); + + assign(test_msg_.data[20], 230); + + assign(test_msg_.data[21], 214); + + assign(test_msg_.data[22], 6); + + assign(test_msg_.data[23], 217); + + assign(test_msg_.data[24], 172); + + assign(test_msg_.data[25], 122); + + assign(test_msg_.data[26], 46); + + assign(test_msg_.data[27], 13); + + assign(test_msg_.data[28], 38); + + assign(test_msg_.data[29], 240); + + assign(test_msg_.data[30], 236); + + assign(test_msg_.data[31], 60); + + assign(test_msg_.data[32], 121); + + assign(test_msg_.data[33], 47); + + assign(test_msg_.data[34], 252); + + assign(test_msg_.data[35], 163); + + assign(test_msg_.data[36], 141); + + assign(test_msg_.data[37], 222); + + assign(test_msg_.data[38], 29); + + assign(test_msg_.data[39], 168); + + assign(test_msg_.data[40], 214); + + assign(test_msg_.data[41], 118); + + assign(test_msg_.data[42], 55); + + assign(test_msg_.data[43], 201); + + assign(test_msg_.data[44], 233); + + assign(test_msg_.data[45], 21); + + assign(test_msg_.data[46], 214); + + assign(test_msg_.data[47], 57); + + assign(test_msg_.data[48], 245); + + assign(test_msg_.data[49], 246); + + assign(test_msg_.data[50], 19); + + assign(test_msg_.data[51], 3); + + assign(test_msg_.data[52], 121); + + assign(test_msg_.data[53], 49); + + assign(test_msg_.data[54], 231); + + assign(test_msg_.data[55], 37); + + assign(test_msg_.data[56], 186); + + assign(test_msg_.data[57], 58); + + assign(test_msg_.data[58], 238); + + assign(test_msg_.data[59], 98); + + assign(test_msg_.data[60], 39); + + assign(test_msg_.data[61], 70); + + assign(test_msg_.data[62], 232); + + assign(test_msg_.data[63], 133); + + assign(test_msg_.data[64], 25); + + assign(test_msg_.data[65], 10); + + assign(test_msg_.data[66], 134); + + assign(test_msg_.data[67], 129); + + assign(test_msg_.data[68], 69); + + assign(test_msg_.data[69], 228); + + assign(test_msg_.data[70], 134); + + assign(test_msg_.data[71], 9); + + assign(test_msg_.data[72], 88); + + assign(test_msg_.data[73], 183); + + assign(test_msg_.data[74], 133); + + assign(test_msg_.data[75], 171); + + assign(test_msg_.data[76], 255); + + assign(test_msg_.data[77], 166); + + assign(test_msg_.data[78], 100); + + assign(test_msg_.data[79], 152); + + assign(test_msg_.data[80], 231); + + assign(test_msg_.data[81], 92); + + assign(test_msg_.data[82], 9); + + assign(test_msg_.data[83], 196); + + assign(test_msg_.data[84], 106); + + assign(test_msg_.data[85], 246); + + assign(test_msg_.data[86], 29); + + assign(test_msg_.data[87], 145); + + assign(test_msg_.data[88], 156); + + assign(test_msg_.data[89], 151); + + assign(test_msg_.data[90], 32); + + assign(test_msg_.data[91], 67); + + assign(test_msg_.data[92], 188); + + assign(test_msg_.data[93], 63); + + assign(test_msg_.data[94], 233); + + assign(test_msg_.data[95], 142); + + assign(test_msg_.data[96], 174); + + assign(test_msg_.data[97], 139); + + assign(test_msg_.data[98], 154); + + assign(test_msg_.data[99], 127); + + assign(test_msg_.data[100], 35); + + assign(test_msg_.data[101], 60); + + assign(test_msg_.data[102], 56); + + assign(test_msg_.data[103], 187); + + assign(test_msg_.data[104], 121); + + assign(test_msg_.data[105], 103); + + assign(test_msg_.data[106], 135); + + assign(test_msg_.data[107], 152); + + assign(test_msg_.data[108], 182); + + assign(test_msg_.data[109], 88); + + assign(test_msg_.data[110], 160); + + assign(test_msg_.data[111], 255); + + assign(test_msg_.data[112], 227); + + assign(test_msg_.data[113], 240); + + assign(test_msg_.data[114], 54); + + assign(test_msg_.data[115], 100); + + assign(test_msg_.data[116], 91); + + assign(test_msg_.data[117], 31); + + assign(test_msg_.data[118], 141); + + assign(test_msg_.data[119], 102); + + assign(test_msg_.data[120], 130); + + assign(test_msg_.data[121], 254); + + assign(test_msg_.data[122], 54); + + assign(test_msg_.data[123], 227); + + assign(test_msg_.data[124], 229); + + assign(test_msg_.data[125], 62); + + assign(test_msg_.data[126], 53); + + assign(test_msg_.data[127], 225); + + assign(test_msg_.data[128], 143); + + assign(test_msg_.data[129], 88); + + assign(test_msg_.data[130], 139); + + assign(test_msg_.data[131], 126); + + assign(test_msg_.data[132], 235); + + assign(test_msg_.data[133], 235); + + assign(test_msg_.data[134], 35); + + assign(test_msg_.data[135], 54); + + assign(test_msg_.data[136], 134); + + assign(test_msg_.data[137], 163); + + assign(test_msg_.data[138], 92); + + assign(test_msg_.data[139], 57); + + assign(test_msg_.data[140], 87); + + assign(test_msg_.data[141], 130); + + assign(test_msg_.data[142], 178); + + assign(test_msg_.data[143], 22); + + assign(test_msg_.data[144], 158); + + assign(test_msg_.data[145], 18); + + assign(test_msg_.data[146], 237); + + assign(test_msg_.data[147], 209); + + assign(test_msg_.data[148], 187); + + assign(test_msg_.data[149], 226); + + assign(test_msg_.data[150], 1); + + assign(test_msg_.data[151], 46); + + assign(test_msg_.data[152], 64); + + assign(test_msg_.data[153], 226); + + assign(test_msg_.data[154], 235); + + assign(test_msg_.data[155], 213); + + assign(test_msg_.data[156], 186); + + assign(test_msg_.data[157], 159); + + assign(test_msg_.data[158], 221); + + assign(test_msg_.data[159], 186); + + assign(test_msg_.data[160], 25); + + assign(test_msg_.data[161], 115); + + assign(test_msg_.data[162], 84); + + assign(test_msg_.data[163], 131); + + assign(test_msg_.data[164], 167); + + assign(test_msg_.data[165], 201); + + assign(test_msg_.data[166], 104); + + assign(test_msg_.data[167], 1); + + assign(test_msg_.data[168], 200); + + assign(test_msg_.data[169], 13); + + assign(test_msg_.data[170], 50); + + assign(test_msg_.data[171], 71); + + assign(test_msg_.data[172], 73); + + assign(test_msg_.data[173], 193); + + assign(test_msg_.data[174], 201); + + assign(test_msg_.data[175], 250); + + assign(test_msg_.data[176], 172); + + assign(test_msg_.data[177], 193); + + assign(test_msg_.data[178], 13); + + assign(test_msg_.data[179], 20); + + assign(test_msg_.data[180], 238); + + assign(test_msg_.data[181], 130); + + assign(test_msg_.data[182], 243); + + assign(test_msg_.data[183], 68); + + assign(test_msg_.data[184], 4); + + assign(test_msg_.data[185], 72); + + assign(test_msg_.data[186], 46); + + assign(test_msg_.data[187], 194); + + assign(test_msg_.data[188], 113); + + assign(test_msg_.data[189], 255); + + assign(test_msg_.data[190], 238); + + assign(test_msg_.data[191], 15); + + assign(test_msg_.data[192], 230); + + assign(test_msg_.data[193], 64); + + assign(test_msg_.data[194], 178); + + assign(test_msg_.data[195], 127); + + assign(test_msg_.data[196], 217); + + assign(test_msg_.data[197], 92); + + assign(test_msg_.data[198], 160); + + assign(test_msg_.data[199], 201); + + assign(test_msg_.data[200], 118); + + assign(test_msg_.data[201], 163); + + assign(test_msg_.data[202], 144); + + assign(test_msg_.data[203], 58); + + assign(test_msg_.data[204], 28); + + assign(test_msg_.data[205], 174); + + assign(test_msg_.data[206], 65); + + assign(test_msg_.data[207], 73); + + assign(test_msg_.data[208], 45); + + assign(test_msg_.data[209], 123); + + assign(test_msg_.data[210], 118); + + assign(test_msg_.data[211], 83); + + assign(test_msg_.data[212], 107); + + assign(test_msg_.data[213], 239); + + assign(test_msg_.data[214], 168); + + assign(test_msg_.data[215], 32); + + assign(test_msg_.data[216], 212); + + assign(test_msg_.data[217], 191); + + assign(test_msg_.data[218], 81); + + assign(test_msg_.data[219], 93); + + assign(test_msg_.data[220], 186); + + assign(test_msg_.data[221], 223); + + assign(test_msg_.data[222], 32); + + assign(test_msg_.data[223], 19); + + assign(test_msg_.data[224], 58); + + assign(test_msg_.data[225], 137); + + assign(test_msg_.data[226], 72); + + assign(test_msg_.data[227], 217); + + assign(test_msg_.data[228], 151); + + assign(test_msg_.data[229], 251); + + assign(test_msg_.data[230], 83); + + assign(test_msg_.data[231], 20); + + assign(test_msg_.data[232], 113); + + assign(test_msg_.data[233], 37); + + assign(test_msg_.data[234], 151); + + assign(test_msg_.data[235], 34); + + assign(test_msg_.data[236], 37); + + assign(test_msg_.data[237], 71); + + assign(test_msg_.data[238], 95); + + assign(test_msg_.data[239], 105); + + assign(test_msg_.data[240], 235); + + assign(test_msg_.data[241], 144); + + assign(test_msg_.data[242], 164); + + assign(test_msg_.data[243], 83); + + assign(test_msg_.data[244], 197); + + assign(test_msg_.data[245], 254); + + assign(test_msg_.data[246], 183); + + assign(test_msg_.data[247], 223); + + assign(test_msg_.data[248], 91); + + assign(test_msg_.data[249], 19); + assign(test_msg_.target, 212); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_program_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_flash_program_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFlashProgram, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_program_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFlashProgram); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->flash_program, + sizeof(msg->flash_program)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_flash_program_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.flash_program, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFlashProgram); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe32d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_flash_program_t &lesser, + const sbp_msg_flash_program_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_flash_program_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_flash_program_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_flash_program_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_flash_program_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashProgram, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashProgram, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFlashProgram, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFlashProgram, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_flash_program_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, 106, + 144, 29, 141, 255, 3, 16, 192, 237, 172, 254, 213, 4, 220, 98, 34, + 222, 230, 214, 6, 217, 172, 122, 46, 13, 38, 240, 236, 60, 121, 47, + 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, 21, 214, 57, 245, + 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, 98, 39, 70, 232, 133, + 25, 10, 134, 129, 69, 228, 134, 9, 88, 183, 133, 171, 255, 166, 100, + 152, 231, 92, 9, 196, 106, 246, 29, 145, 156, 151, 32, 67, 188, 63, + 233, 142, 174, 139, 154, 127, 35, 60, 56, 187, 121, 103, 135, 152, 182, + 88, 160, 255, 227, 240, 54, 100, 91, 31, 141, 102, 130, 254, 54, 227, + 229, 62, 53, 225, 143, 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, + 57, 87, 130, 178, 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, + 235, 213, 186, 159, 221, 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, + 13, 50, 71, 73, 193, 201, 250, 172, 193, 13, 20, 238, 130, 243, 68, + 4, 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, 92, 160, + 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, 239, + 168, 32, 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, 217, 151, + 251, 83, 20, 113, 37, 151, 34, 37, 71, 95, 105, 235, 144, 164, 83, + 197, 254, 183, 223, 91, 19, 45, 227, + }; + uint8_t encoded_payload_[255] = { + 212, 87, 52, 244, 250, 176, 222, 235, 106, 144, 29, 141, 255, 3, 16, + 192, 237, 172, 254, 213, 4, 220, 98, 34, 222, 230, 214, 6, 217, 172, + 122, 46, 13, 38, 240, 236, 60, 121, 47, 252, 163, 141, 222, 29, 168, + 214, 118, 55, 201, 233, 21, 214, 57, 245, 246, 19, 3, 121, 49, 231, + 37, 186, 58, 238, 98, 39, 70, 232, 133, 25, 10, 134, 129, 69, 228, + 134, 9, 88, 183, 133, 171, 255, 166, 100, 152, 231, 92, 9, 196, 106, + 246, 29, 145, 156, 151, 32, 67, 188, 63, 233, 142, 174, 139, 154, 127, + 35, 60, 56, 187, 121, 103, 135, 152, 182, 88, 160, 255, 227, 240, 54, + 100, 91, 31, 141, 102, 130, 254, 54, 227, 229, 62, 53, 225, 143, 88, + 139, 126, 235, 235, 35, 54, 134, 163, 92, 57, 87, 130, 178, 22, 158, + 18, 237, 209, 187, 226, 1, 46, 64, 226, 235, 213, 186, 159, 221, 186, + 25, 115, 84, 131, 167, 201, 104, 1, 200, 13, 50, 71, 73, 193, 201, + 250, 172, 193, 13, 20, 238, 130, 243, 68, 4, 72, 46, 194, 113, 255, + 238, 15, 230, 64, 178, 127, 217, 92, 160, 201, 118, 163, 144, 58, 28, + 174, 65, 73, 45, 123, 118, 83, 107, 239, 168, 32, 212, 191, 81, 93, + 186, 223, 32, 19, 58, 137, 72, 217, 151, 251, 83, 20, 113, 37, 151, + 34, 37, 71, 95, 105, 235, 144, 164, 83, 197, 254, 183, 223, 91, 19, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_flash_program_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFlashProgram, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_flash_program_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFlashProgram, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ(sbp_msg_flash_program_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_flash_program_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_program_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_flash_program_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFlashProgram, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_flash_program_t msg{}; + + EXPECT_EQ(sbp_msg_flash_program_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_flash_program_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_flash_program_t t{}; + return sbp_msg_flash_program_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_flash_program_t t{}; + t.addr_len = 1; + return sbp_msg_flash_program_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_flash_program_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_flash_program_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashProgram, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFlashProgram, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashProgram, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.addr_len, greater.addr_len); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[0], greater.addr_start[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[1], greater.addr_start[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[2], greater.addr_start[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[0], greater.data[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[1], greater.data[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[2], greater.data[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[3], greater.data[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[4], greater.data[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[5], greater.data[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[6], greater.data[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[7], greater.data[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[8], greater.data[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[9], greater.data[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[10], greater.data[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[11], greater.data[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[12], greater.data[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[13], greater.data[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[14], greater.data[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[15], greater.data[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[16], greater.data[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[17], greater.data[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[18], greater.data[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[19], greater.data[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[20], greater.data[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[21], greater.data[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[22], greater.data[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[23], greater.data[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[24], greater.data[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[25], greater.data[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[26], greater.data[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[27], greater.data[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[28], greater.data[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[29], greater.data[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[30], greater.data[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[31], greater.data[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[32], greater.data[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[33], greater.data[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[34], greater.data[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[35], greater.data[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[36], greater.data[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[37], greater.data[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[38], greater.data[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[39], greater.data[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[40], greater.data[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[41], greater.data[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[42], greater.data[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[43], greater.data[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[44], greater.data[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[45], greater.data[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[46], greater.data[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[47], greater.data[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[48], greater.data[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[49], greater.data[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[50], greater.data[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[51], greater.data[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[52], greater.data[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[53], greater.data[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[54], greater.data[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[55], greater.data[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[56], greater.data[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[57], greater.data[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[58], greater.data[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[59], greater.data[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[60], greater.data[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[61], greater.data[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[62], greater.data[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[63], greater.data[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[64], greater.data[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[65], greater.data[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[66], greater.data[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[67], greater.data[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[68], greater.data[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[69], greater.data[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[70], greater.data[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[71], greater.data[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[72], greater.data[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[73], greater.data[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[74], greater.data[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[75], greater.data[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[76], greater.data[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[77], greater.data[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[78], greater.data[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[79], greater.data[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[80], greater.data[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[81], greater.data[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[82], greater.data[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[83], greater.data[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[84], greater.data[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[85], greater.data[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[86], greater.data[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[87], greater.data[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[88], greater.data[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[89], greater.data[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[90], greater.data[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[91], greater.data[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[92], greater.data[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[93], greater.data[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[94], greater.data[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[95], greater.data[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[96], greater.data[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[97], greater.data[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[98], greater.data[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[99], greater.data[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[100], greater.data[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[101], greater.data[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[102], greater.data[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[103], greater.data[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[104], greater.data[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[105], greater.data[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[106], greater.data[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[107], greater.data[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[108], greater.data[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[109], greater.data[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[110], greater.data[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[111], greater.data[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[112], greater.data[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[113], greater.data[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[114], greater.data[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[115], greater.data[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[116], greater.data[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[117], greater.data[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[118], greater.data[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[119], greater.data[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[120], greater.data[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[121], greater.data[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[122], greater.data[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[123], greater.data[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[124], greater.data[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[125], greater.data[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[126], greater.data[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[127], greater.data[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[128], greater.data[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[129], greater.data[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[130], greater.data[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[131], greater.data[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[132], greater.data[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[133], greater.data[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[134], greater.data[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[135], greater.data[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[136], greater.data[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[137], greater.data[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[138], greater.data[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[139], greater.data[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[140], greater.data[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[141], greater.data[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[142], greater.data[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[143], greater.data[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[144], greater.data[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[145], greater.data[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[146], greater.data[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[147], greater.data[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[148], greater.data[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[149], greater.data[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[150], greater.data[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[151], greater.data[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[152], greater.data[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[153], greater.data[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[154], greater.data[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[155], greater.data[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[156], greater.data[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[157], greater.data[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[158], greater.data[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[159], greater.data[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[160], greater.data[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[161], greater.data[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[162], greater.data[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[163], greater.data[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[164], greater.data[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[165], greater.data[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[166], greater.data[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[167], greater.data[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[168], greater.data[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[169], greater.data[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[170], greater.data[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[171], greater.data[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[172], greater.data[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[173], greater.data[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[174], greater.data[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[175], greater.data[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[176], greater.data[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[177], greater.data[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[178], greater.data[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[179], greater.data[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[180], greater.data[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[181], greater.data[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[182], greater.data[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[183], greater.data[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[184], greater.data[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[185], greater.data[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[186], greater.data[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[187], greater.data[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[188], greater.data[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[189], greater.data[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[190], greater.data[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[191], greater.data[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[192], greater.data[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[193], greater.data[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[194], greater.data[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[195], greater.data[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[196], greater.data[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[197], greater.data[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[198], greater.data[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[199], greater.data[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[200], greater.data[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[201], greater.data[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[202], greater.data[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[203], greater.data[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[204], greater.data[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[205], greater.data[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[206], greater.data[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[207], greater.data[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[208], greater.data[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[209], greater.data[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[210], greater.data[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[211], greater.data[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[212], greater.data[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[213], greater.data[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[214], greater.data[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[215], greater.data[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[216], greater.data[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[217], greater.data[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[218], greater.data[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[219], greater.data[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[220], greater.data[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[221], greater.data[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[222], greater.data[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[223], greater.data[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[224], greater.data[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[225], greater.data[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[226], greater.data[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[227], greater.data[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[228], greater.data[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[229], greater.data[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[230], greater.data[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[231], greater.data[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[232], greater.data[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[233], greater.data[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[234], greater.data[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[235], greater.data[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[236], greater.data[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[237], greater.data[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[238], greater.data[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[239], greater.data[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[240], greater.data[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[241], greater.data[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[242], greater.data[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[243], greater.data[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[244], greater.data[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[245], greater.data[245]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[246], greater.data[246]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[247], greater.data[247]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[248], greater.data[248]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.data[249], greater.data[249]); + comparison_tests(lesser, greater); + } + { + sbp_msg_flash_program_t lesser = info.test_msg; + sbp_msg_flash_program_t greater = info.test_msg; + make_lesser_greater(lesser.target, greater.target); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFlashProgram); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FLASH_PROGRAM"); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_flash_program_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_flash_program_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.flash_program, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.flash_program, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_program_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFlashProgram, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashProgram0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFlashProgram, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc b/c/test/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc new file mode 100644 index 0000000000..11a1938880 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc @@ -0,0 +1,812 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgFlashReadReq0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgFlashReadReq0() { + assign(test_msg_.addr_len, 71); + + assign(test_msg_.addr_start[0], 28); + + assign(test_msg_.addr_start[1], 75); + + assign(test_msg_.addr_start[2], 244); + assign(test_msg_.target, 241); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_read_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_flash_read_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFlashReadReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_read_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFlashReadReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->flash_read_req, + sizeof(msg->flash_read_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_flash_read_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.flash_read_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFlashReadReq); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x39d2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 5; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_flash_read_req_t &lesser, + const sbp_msg_flash_read_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_flash_read_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_flash_read_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_flash_read_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_flash_read_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashReadReq, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashReadReq, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFlashReadReq, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFlashReadReq, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_flash_read_req_t test_msg_{}; + uint8_t encoded_frame_[5 + 8] = { + 85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57, + }; + uint8_t encoded_payload_[5] = { + 241, 28, 75, 244, 71, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_flash_read_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFlashReadReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_flash_read_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFlashReadReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + EXPECT_EQ(sbp_msg_flash_read_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ( + sbp_msg_flash_read_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_flash_read_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFlashReadReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_req_t msg{}; + + EXPECT_EQ(sbp_msg_flash_read_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_flash_read_req_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_flash_read_req_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFlashReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashReadReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_flash_read_req_t lesser = info.test_msg; + sbp_msg_flash_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.addr_len, greater.addr_len); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_req_t lesser = info.test_msg; + sbp_msg_flash_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[0], greater.addr_start[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_req_t lesser = info.test_msg; + sbp_msg_flash_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[1], greater.addr_start[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_req_t lesser = info.test_msg; + sbp_msg_flash_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[2], greater.addr_start[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_flash_read_req_t lesser = info.test_msg; + sbp_msg_flash_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.target, greater.target); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFlashReadReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FLASH_READ_REQ"); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_flash_read_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_flash_read_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.flash_read_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.flash_read_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFlashReadReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFlashReadReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc b/c/test/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc new file mode 100644 index 0000000000..0b944cecdd --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc @@ -0,0 +1,813 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgFlashReadResp0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgFlashReadResp0() { + assign(test_msg_.addr_len, 124); + + assign(test_msg_.addr_start[0], 155); + + assign(test_msg_.addr_start[1], 52); + + assign(test_msg_.addr_start[2], 172); + assign(test_msg_.target, 136); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_read_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_flash_read_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFlashReadResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_flash_read_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFlashReadResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->flash_read_resp, + sizeof(msg->flash_read_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_flash_read_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.flash_read_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFlashReadResp); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x8795; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 5; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_flash_read_resp_t &lesser, + const sbp_msg_flash_read_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_flash_read_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_flash_read_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_flash_read_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_flash_read_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFlashReadResp, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFlashReadResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFlashReadResp, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFlashReadResp, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_flash_read_resp_t test_msg_{}; + uint8_t encoded_frame_[5 + 8] = { + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + }; + uint8_t encoded_payload_[5] = { + 136, 155, 52, 172, 124, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_flash_read_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgFlashReadResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_flash_read_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFlashReadResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + EXPECT_EQ(sbp_msg_flash_read_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ( + sbp_msg_flash_read_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_flash_read_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFlashReadResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_resp_t msg{}; + + EXPECT_EQ(sbp_msg_flash_read_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_flash_read_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_flash_read_resp_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFlashReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFlashReadResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_flash_read_resp_t lesser = info.test_msg; + sbp_msg_flash_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.addr_len, greater.addr_len); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_resp_t lesser = info.test_msg; + sbp_msg_flash_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[0], greater.addr_start[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_resp_t lesser = info.test_msg; + sbp_msg_flash_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[1], greater.addr_start[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_flash_read_resp_t lesser = info.test_msg; + sbp_msg_flash_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.addr_start[2], greater.addr_start[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_flash_read_resp_t lesser = info.test_msg; + sbp_msg_flash_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.target, greater.target); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFlashReadResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FLASH_READ_RESP"); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_flash_read_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_flash_read_resp_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.flash_read_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.flash_read_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_flash_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFlashReadResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgFlashReadResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFlashReadResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc b/c/test/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc new file mode 100644 index 0000000000..3434be4b05 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc @@ -0,0 +1,796 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgM25FlashWriteStatus0 + : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgM25FlashWriteStatus0() { + assign(test_msg_.status[0], 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_m25_flash_write_status_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_m25_flash_write_status_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgM25FlashWriteStatus, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_m25_flash_write_status_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgM25FlashWriteStatus); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->m25_flash_write_status, + sizeof(msg->m25_flash_write_status)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_m25_flash_write_status_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.m25_flash_write_status, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgM25FlashWriteStatus); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xc870; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 1; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_m25_flash_write_status_t &lesser, + const sbp_msg_m25_flash_write_status_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_m25_flash_write_status_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_m25_flash_write_status_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_m25_flash_write_status_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_m25_flash_write_status_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgM25FlashWriteStatus, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgM25FlashWriteStatus, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgM25FlashWriteStatus, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgM25FlashWriteStatus, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_m25_flash_write_status_t test_msg_{}; + uint8_t encoded_frame_[1 + 8] = { + 85, 243, 0, 195, 4, 1, 5, 112, 200, + }; + uint8_t encoded_payload_[1] = { + 5, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_m25_flash_write_status_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgM25FlashWriteStatus, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_m25_flash_write_status_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgM25FlashWriteStatus, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_m25_flash_write_status_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_msg_m25_flash_write_status_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_m25_flash_write_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_m25_flash_write_status_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgM25FlashWriteStatus, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_m25_flash_write_status_t msg{}; + + EXPECT_EQ(sbp_msg_m25_flash_write_status_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_m25_flash_write_status_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_m25_flash_write_status_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_m25_flash_write_status_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgM25FlashWriteStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgM25FlashWriteStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgM25FlashWriteStatus, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_m25_flash_write_status_t lesser = info.test_msg; + sbp_msg_m25_flash_write_status_t greater = info.test_msg; + make_lesser_greater(lesser.status[0], greater.status[0]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgM25FlashWriteStatus); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_M25_FLASH_WRITE_STATUS"); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_m25_flash_write_status_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_m25_flash_write_status_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.m25_flash_write_status, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.m25_flash_write_status, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_m25_flash_write_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgM25FlashWriteStatus, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgM25FlashWriteStatus0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgM25FlashWriteStatus, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc b/c/test/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc new file mode 100644 index 0000000000..d9c971ec4f --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc @@ -0,0 +1,792 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgStmFlashLockSector0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgStmFlashLockSector0() { + assign(test_msg_.sector, 1137047457); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_flash_lock_sector_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_stm_flash_lock_sector_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStmFlashLockSector, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_flash_lock_sector_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStmFlashLockSector); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->stm_flash_lock_sector, + sizeof(msg->stm_flash_lock_sector)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_stm_flash_lock_sector_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.stm_flash_lock_sector, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStmFlashLockSector); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x20e5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_stm_flash_lock_sector_t &lesser, + const sbp_msg_stm_flash_lock_sector_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_stm_flash_lock_sector_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_stm_flash_lock_sector_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgStmFlashLockSector, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStmFlashLockSector, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStmFlashLockSector, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStmFlashLockSector, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_stm_flash_lock_sector_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32, + }; + uint8_t encoded_payload_[4] = { + 161, + 247, + 197, + 67, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgStmFlashLockSector, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStmFlashLockSector, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_lock_sector_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStmFlashLockSector, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_lock_sector_t msg{}; + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_lock_sector_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_stm_flash_lock_sector_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmFlashLockSector, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStmFlashLockSector, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmFlashLockSector, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_stm_flash_lock_sector_t lesser = info.test_msg; + sbp_msg_stm_flash_lock_sector_t greater = info.test_msg; + make_lesser_greater(lesser.sector, greater.sector); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStmFlashLockSector); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STM_FLASH_LOCK_SECTOR"); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_stm_flash_lock_sector_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_stm_flash_lock_sector_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.stm_flash_lock_sector, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.stm_flash_lock_sector, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_lock_sector_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStmFlashLockSector, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashLockSector0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStmFlashLockSector, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc b/c/test/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc new file mode 100644 index 0000000000..a1f56e2944 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc @@ -0,0 +1,801 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgStmFlashUnlockSector0 + : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgStmFlashUnlockSector0() { + assign(test_msg_.sector, 837226527); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_stm_flash_unlock_sector_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_flash_unlock_sector_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_stm_flash_unlock_sector_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStmFlashUnlockSector, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_flash_unlock_sector_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStmFlashUnlockSector); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->stm_flash_unlock_sector, + sizeof(msg->stm_flash_unlock_sector)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_stm_flash_unlock_sector_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.stm_flash_unlock_sector, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStmFlashUnlockSector); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xd935; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_stm_flash_unlock_sector_t &lesser, + const sbp_msg_stm_flash_unlock_sector_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_stm_flash_unlock_sector_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_stm_flash_unlock_sector_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgStmFlashUnlockSector, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStmFlashUnlockSector, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStmFlashUnlockSector, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStmFlashUnlockSector, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_stm_flash_unlock_sector_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217, + }; + uint8_t encoded_payload_[4] = { + 31, + 16, + 231, + 49, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgStmFlashUnlockSector, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStmFlashUnlockSector, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_unlock_sector_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgStmFlashUnlockSector, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_unlock_sector_t msg{}; + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_unlock_sector_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_stm_flash_unlock_sector_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmFlashUnlockSector, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgStmFlashUnlockSector, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmFlashUnlockSector, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_stm_flash_unlock_sector_t lesser = info.test_msg; + sbp_msg_stm_flash_unlock_sector_t greater = info.test_msg; + make_lesser_greater(lesser.sector, greater.sector); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStmFlashUnlockSector); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STM_FLASH_UNLOCK_SECTOR"); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_stm_flash_unlock_sector_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_stm_flash_unlock_sector_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.stm_flash_unlock_sector, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.stm_flash_unlock_sector, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_flash_unlock_sector_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStmFlashUnlockSector, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmFlashUnlockSector0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStmFlashUnlockSector, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc b/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc new file mode 100644 index 0000000000..11c8be6761 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc @@ -0,0 +1,745 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgStmUniqueIdReq0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgStmUniqueIdReq0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_unique_id_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_stm_unique_id_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStmUniqueIdReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_unique_id_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStmUniqueIdReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->stm_unique_id_req, + sizeof(msg->stm_unique_id_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_stm_unique_id_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.stm_unique_id_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStmUniqueIdReq); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x8a42; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_stm_unique_id_req_t &lesser, + const sbp_msg_stm_unique_id_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_stm_unique_id_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_stm_unique_id_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_stm_unique_id_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_stm_unique_id_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgStmUniqueIdReq, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStmUniqueIdReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStmUniqueIdReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStmUniqueIdReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_stm_unique_id_req_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 232, 0, 195, 4, 0, 66, 138, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_stm_unique_id_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgStmUniqueIdReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_stm_unique_id_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStmUniqueIdReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_stm_unique_id_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_stm_unique_id_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStmUniqueIdReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_req_t msg{}; + + EXPECT_EQ(sbp_msg_stm_unique_id_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_stm_unique_id_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmUniqueIdReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStmUniqueIdReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmUniqueIdReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStmUniqueIdReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STM_UNIQUE_ID_REQ"); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_stm_unique_id_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_stm_unique_id_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.stm_unique_id_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.stm_unique_id_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStmUniqueIdReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStmUniqueIdReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc b/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc new file mode 100644 index 0000000000..6239be455f --- /dev/null +++ b/c/test/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc @@ -0,0 +1,884 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_flash_MsgStmUniqueIdResp0 : public ::testing::Test { + public: + Testauto_check_sbp_flash_MsgStmUniqueIdResp0() { + assign(test_msg_.stm_id[0], 196); + + assign(test_msg_.stm_id[1], 16); + + assign(test_msg_.stm_id[2], 15); + + assign(test_msg_.stm_id[3], 163); + + assign(test_msg_.stm_id[4], 85); + + assign(test_msg_.stm_id[5], 221); + + assign(test_msg_.stm_id[6], 119); + + assign(test_msg_.stm_id[7], 102); + + assign(test_msg_.stm_id[8], 32); + + assign(test_msg_.stm_id[9], 194); + + assign(test_msg_.stm_id[10], 56); + + assign(test_msg_.stm_id[11], 144); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_unique_id_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_stm_unique_id_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStmUniqueIdResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_stm_unique_id_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStmUniqueIdResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->stm_unique_id_resp, + sizeof(msg->stm_unique_id_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_stm_unique_id_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.stm_unique_id_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStmUniqueIdResp); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xc4dd; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 12; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_stm_unique_id_resp_t &lesser, + const sbp_msg_stm_unique_id_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_stm_unique_id_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_stm_unique_id_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_stm_unique_id_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgStmUniqueIdResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStmUniqueIdResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStmUniqueIdResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStmUniqueIdResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_stm_unique_id_resp_t test_msg_{}; + uint8_t encoded_frame_[12 + 8] = { + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, + 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + }; + uint8_t encoded_payload_[12] = { + 196, 16, 15, 163, 85, 221, 119, 102, 32, 194, 56, 144, + }; +}; + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_stm_unique_id_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgStmUniqueIdResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStmUniqueIdResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ( + sbp_msg_stm_unique_id_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStmUniqueIdResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_resp_t msg{}; + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_stm_unique_id_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmUniqueIdResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStmUniqueIdResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStmUniqueIdResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[0], greater.stm_id[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[1], greater.stm_id[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[2], greater.stm_id[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[3], greater.stm_id[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[4], greater.stm_id[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[5], greater.stm_id[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[6], greater.stm_id[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[7], greater.stm_id[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[8], greater.stm_id[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[9], greater.stm_id[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[10], greater.stm_id[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_stm_unique_id_resp_t lesser = info.test_msg; + sbp_msg_stm_unique_id_resp_t greater = info.test_msg; + make_lesser_greater(lesser.stm_id[11], greater.stm_id[11]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStmUniqueIdResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STM_UNIQUE_ID_RESP"); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_stm_unique_id_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_stm_unique_id_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.stm_unique_id_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.stm_unique_id_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_stm_unique_id_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStmUniqueIdResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_flash_MsgStmUniqueIdResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStmUniqueIdResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_gnss_gnss_structs.cc b/c/test/cpp/auto_check_sbp_gnss_gnss_structs.cc new file mode 100644 index 0000000000..cfc213bd96 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_gnss_gnss_structs.cc @@ -0,0 +1,665 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/gnss/test_gnss_structs.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs0 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs0() { + assign(test_struct_.code, 244); + assign(test_struct_.sat, 162); + } + + struct TestStructInfo { + sbp_v4_gnss_signal_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_v4_gnss_signal_t test_struct_{}; + uint8_t encoded_data_[2] = { + 162, + 244, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_v4_gnss_signal_encoded_len(&info.test_struct), 2); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[2]; + EXPECT_EQ(sbp_v4_gnss_signal_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + EXPECT_EQ(sbp_v4_gnss_signal_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 2), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_v4_gnss_signal_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_v4_gnss_signal_t t{}; + EXPECT_EQ(sbp_v4_gnss_signal_decode(info.encoded_data, 2, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_v4_gnss_signal_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_v4_gnss_signal_t t{}; + EXPECT_EQ(sbp_v4_gnss_signal_decode(info.encoded_data, 2, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_v4_gnss_signal_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs0, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_v4_gnss_signal_t t{}; + + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_v4_gnss_signal_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs1 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs1() { + assign(test_struct_.constellation, 44); + assign(test_struct_.satId, 178); + } + + struct TestStructInfo { + sbp_sv_id_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_sv_id_t test_struct_{}; + uint8_t encoded_data_[2] = { + 178, + 44, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_sv_id_encoded_len(&info.test_struct), 2); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[2]; + EXPECT_EQ( + sbp_sv_id_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + EXPECT_EQ(sbp_sv_id_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 2), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_sv_id_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_sv_id_t t{}; + EXPECT_EQ(sbp_sv_id_decode(info.encoded_data, 2, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_sv_id_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_sv_id_t t{}; + EXPECT_EQ(sbp_sv_id_decode(info.encoded_data, 2, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_sv_id_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs1, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_sv_id_t t{}; + + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_sv_id_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs2 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs2() { + assign(test_struct_.code, 241); + assign(test_struct_.reserved, 245); + assign(test_struct_.sat, 17091); + } + + struct TestStructInfo { + sbp_gnss_signal_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gnss_signal_dep_t test_struct_{}; + uint8_t encoded_data_[4] = { + 195, + 66, + 241, + 245, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gnss_signal_dep_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_gnss_signal_dep_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_gnss_signal_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_gnss_signal_dep_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gnss_signal_dep_t t{}; + EXPECT_EQ(sbp_gnss_signal_dep_decode(info.encoded_data, 4, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gnss_signal_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gnss_signal_dep_t t{}; + EXPECT_EQ(sbp_gnss_signal_dep_decode(info.encoded_data, 4, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_gnss_signal_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs2, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gnss_signal_dep_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_gnss_signal_dep_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs3 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs3() { + assign(test_struct_.tow, 1454655020); + assign(test_struct_.wn, 26743); + } + + struct TestStructInfo { + sbp_gps_time_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gps_time_dep_t test_struct_{}; + uint8_t encoded_data_[6] = { + 44, 70, 180, 86, 119, 104, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gps_time_dep_encoded_len(&info.test_struct), 6); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[6]; + EXPECT_EQ(sbp_gps_time_dep_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + EXPECT_EQ( + sbp_gps_time_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 6), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_gps_time_dep_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gps_time_dep_t t{}; + EXPECT_EQ(sbp_gps_time_dep_decode(info.encoded_data, 6, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gps_time_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gps_time_dep_t t{}; + EXPECT_EQ(sbp_gps_time_dep_decode(info.encoded_data, 6, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_gps_time_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs3, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gps_time_dep_t t{}; + + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_gps_time_dep_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs4 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs4() { + assign(test_struct_.tow, 2061297728); + assign(test_struct_.wn, 62230); + } + + struct TestStructInfo { + sbp_gps_time_sec_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gps_time_sec_t test_struct_{}; + uint8_t encoded_data_[6] = { + 64, 232, 220, 122, 22, 243, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gps_time_sec_encoded_len(&info.test_struct), 6); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[6]; + EXPECT_EQ(sbp_gps_time_sec_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + EXPECT_EQ( + sbp_gps_time_sec_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 6), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_gps_time_sec_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gps_time_sec_t t{}; + EXPECT_EQ(sbp_gps_time_sec_decode(info.encoded_data, 6, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gps_time_sec_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gps_time_sec_t t{}; + EXPECT_EQ(sbp_gps_time_sec_decode(info.encoded_data, 6, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_gps_time_sec_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs4, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gps_time_sec_t t{}; + + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_gps_time_sec_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs5 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs5() { + assign(test_struct_.ns_residual, 471708190); + assign(test_struct_.tow, 96275743); + assign(test_struct_.wn, 47135); + } + + struct TestStructInfo { + sbp_v4_gps_time_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_v4_gps_time_t test_struct_{}; + uint8_t encoded_data_[10] = { + 31, 13, 189, 5, 30, 178, 29, 28, 31, 184, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_v4_gps_time_encoded_len(&info.test_struct), 10); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[10]; + EXPECT_EQ(sbp_v4_gps_time_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + EXPECT_EQ( + sbp_v4_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 10), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_v4_gps_time_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_v4_gps_time_t t{}; + EXPECT_EQ(sbp_v4_gps_time_decode(info.encoded_data, 10, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_v4_gps_time_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_v4_gps_time_t t{}; + EXPECT_EQ(sbp_v4_gps_time_decode(info.encoded_data, 10, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_v4_gps_time_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs5, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_v4_gps_time_t t{}; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_v4_gps_time_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_gnss_gnss_structs6 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_gnss_gnss_structs6() { + assign(test_struct_.f, 122); + assign(test_struct_.i, -2018454494); + } + + struct TestStructInfo { + sbp_carrier_phase_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_carrier_phase_t test_struct_{}; + uint8_t encoded_data_[5] = { + 34, 212, 176, 135, 122, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_carrier_phase_encoded_len(&info.test_struct), 5); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[5]; + EXPECT_EQ(sbp_carrier_phase_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + EXPECT_EQ(sbp_carrier_phase_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 5), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_carrier_phase_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_carrier_phase_t t{}; + EXPECT_EQ(sbp_carrier_phase_decode(info.encoded_data, 5, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_carrier_phase_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_carrier_phase_t t{}; + EXPECT_EQ(sbp_carrier_phase_decode(info.encoded_data, 5, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_carrier_phase_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_gnss_gnss_structs6, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_carrier_phase_t t{}; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_carrier_phase_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_imu_MsgImuAux.cc b/c/test/cpp/auto_check_sbp_imu_MsgImuAux.cc index 1a364b74f3..40a3a8a6b1 100644 --- a/c/test/cpp/auto_check_sbp_imu_MsgImuAux.cc +++ b/c/test/cpp/auto_check_sbp_imu_MsgImuAux.cc @@ -16,93 +16,760 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_imu_MsgImuAux0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_imu_MsgImuAux0 : public ::testing::Test { public: - Test_auto_check_sbp_imu_MsgImuAux0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_imu_MsgImuAux0() { + assign(test_msg_.imu_conf, 66); + assign(test_msg_.imu_type, 1); + assign(test_msg_.temp, 2804); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_imu_aux_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_imu_aux_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgImuAux, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_imu_aux_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgImuAux); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->imu_aux, sizeof(msg->imu_aux)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_imu_aux_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.imu_aux, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgImuAux); + info.sender_id = 4660; + info.preamble = 0x55; + info.crc = 0xfcc8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_imu_aux_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_imu_aux_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_imu_aux_t &lesser, + const sbp_msg_imu_aux_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_imu_aux_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_imu_aux_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_imu_aux_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_imu_aux_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgImuAux, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgImuAux, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgImuAux, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgImuAux, &wrapped_greater, &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_imu_MsgImuAux0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_imu_aux_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 1, 9, 52, 18, 4, 1, 244, 10, 66, 200, 252, }; + uint8_t encoded_payload_[4] = { + 1, + 244, + 10, + 66, + }; +}; + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_imu_aux_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgImuAux, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_imu_aux_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgImuAux, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_imu_aux_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_imu_aux_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_imu_aux_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_imu_aux_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgImuAux, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_imu_aux_t msg{}; + + EXPECT_EQ(sbp_msg_imu_aux_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_imu_aux_t msg{}; - sbp_msg_imu_aux_t test_msg{}; - test_msg.imu_conf = 66; - test_msg.imu_type = 1; - test_msg.temp = 2804; + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - EXPECT_EQ(send_message(4660, test_msg), SBP_OK); + EXPECT_EQ( + sbp_msg_imu_aux_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ(sbp_msg_imu_aux_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgImuAux, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgImuAux, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4660); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.imu_conf, 66) - << "incorrect value for last_msg_.imu_conf, expected 66, is " - << last_msg_.imu_conf; - EXPECT_EQ(last_msg_.imu_type, 1) - << "incorrect value for last_msg_.imu_type, expected 1, is " - << last_msg_.imu_type; - EXPECT_EQ(last_msg_.temp, 2804) - << "incorrect value for last_msg_.temp, expected 2804, is " - << last_msg_.temp; +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgImuAux, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_imu_aux_t lesser = info.test_msg; + sbp_msg_imu_aux_t greater = info.test_msg; + make_lesser_greater(lesser.imu_conf, greater.imu_conf); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_aux_t lesser = info.test_msg; + sbp_msg_imu_aux_t greater = info.test_msg; + make_lesser_greater(lesser.imu_type, greater.imu_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_aux_t lesser = info.test_msg; + sbp_msg_imu_aux_t greater = info.test_msg; + make_lesser_greater(lesser.temp, greater.temp); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgImuAux); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IMU_AUX"); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_imu_aux_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_imu_aux_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.imu_aux, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.imu_aux, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_imu_aux_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgImuAux, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuAux0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgImuAux, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_imu_MsgImuRaw.cc b/c/test/cpp/auto_check_sbp_imu_MsgImuRaw.cc index aba8b748ca..2ce5a6e8de 100644 --- a/c/test/cpp/auto_check_sbp_imu_MsgImuRaw.cc +++ b/c/test/cpp/auto_check_sbp_imu_MsgImuRaw.cc @@ -16,114 +16,793 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_imu_MsgImuRaw0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_imu_MsgImuRaw0 : public ::testing::Test { public: - Test_auto_check_sbp_imu_MsgImuRaw0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_imu_MsgImuRaw0() { + assign(test_msg_.acc_x, 96); + assign(test_msg_.acc_y, -33); + assign(test_msg_.acc_z, 4140); + assign(test_msg_.gyr_x, 60); + assign(test_msg_.gyr_y, -304); + assign(test_msg_.gyr_z, -18); + assign(test_msg_.tow, 3221225754); + assign(test_msg_.tow_f, 206); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_imu_raw_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_imu_raw_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgImuRaw, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_imu_raw_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgImuRaw); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->imu_raw, sizeof(msg->imu_raw)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_imu_raw_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.imu_raw, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgImuRaw); + info.sender_id = 4660; + info.preamble = 0x55; + info.crc = 0x8746; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 17; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_imu_raw_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_imu_raw_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_imu_raw_t &lesser, + const sbp_msg_imu_raw_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_imu_raw_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_imu_raw_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_imu_raw_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_imu_raw_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgImuRaw, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgImuRaw, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgImuRaw, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgImuRaw, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_imu_MsgImuRaw0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_imu_raw_t test_msg_{}; + uint8_t encoded_frame_[17 + 8] = { 85, 0, 9, 52, 18, 17, 26, 1, 0, 192, 206, 96, 0, 223, 255, 44, 16, 60, 0, 208, 254, 238, 255, 70, 135, }; + uint8_t encoded_payload_[17] = { + 26, 1, 0, 192, 206, 96, 0, 223, 255, 44, 16, 60, 0, 208, 254, 238, 255, + }; +}; + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_imu_raw_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgImuRaw, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_imu_raw_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgImuRaw, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + EXPECT_EQ( + sbp_msg_imu_raw_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ(sbp_msg_imu_raw_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_imu_raw_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_imu_raw_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgImuRaw, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_imu_raw_t msg{}; + + EXPECT_EQ(sbp_msg_imu_raw_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_imu_raw_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_imu_raw_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_imu_raw_t test_msg{}; - test_msg.acc_x = 96; - test_msg.acc_y = -33; - test_msg.acc_z = 4140; - test_msg.gyr_x = 60; - test_msg.gyr_y = -304; - test_msg.gyr_z = -18; - test_msg.tow = 3221225754; - test_msg.tow_f = 206; - - EXPECT_EQ(send_message(4660, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4660); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.acc_x, 96) - << "incorrect value for last_msg_.acc_x, expected 96, is " - << last_msg_.acc_x; - EXPECT_EQ(last_msg_.acc_y, -33) - << "incorrect value for last_msg_.acc_y, expected -33, is " - << last_msg_.acc_y; - EXPECT_EQ(last_msg_.acc_z, 4140) - << "incorrect value for last_msg_.acc_z, expected 4140, is " - << last_msg_.acc_z; - EXPECT_EQ(last_msg_.gyr_x, 60) - << "incorrect value for last_msg_.gyr_x, expected 60, is " - << last_msg_.gyr_x; - EXPECT_EQ(last_msg_.gyr_y, -304) - << "incorrect value for last_msg_.gyr_y, expected -304, is " - << last_msg_.gyr_y; - EXPECT_EQ(last_msg_.gyr_z, -18) - << "incorrect value for last_msg_.gyr_z, expected -18, is " - << last_msg_.gyr_z; - EXPECT_EQ(last_msg_.tow, 3221225754) - << "incorrect value for last_msg_.tow, expected 3221225754, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.tow_f, 206) - << "incorrect value for last_msg_.tow_f, expected 206, is " - << last_msg_.tow_f; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_imu_raw_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgImuRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgImuRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgImuRaw, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.acc_x, greater.acc_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.acc_y, greater.acc_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.acc_z, greater.acc_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.gyr_x, greater.gyr_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.gyr_y, greater.gyr_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.gyr_z, greater.gyr_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_imu_raw_t lesser = info.test_msg; + sbp_msg_imu_raw_t greater = info.test_msg; + make_lesser_greater(lesser.tow_f, greater.tow_f); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgImuRaw); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IMU_RAW"); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_imu_raw_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_imu_raw_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.imu_raw, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.imu_raw, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); } + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_imu_raw_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgImuRaw, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_imu_MsgImuRaw0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgImuRaw, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgAcknowledge.cc b/c/test/cpp/auto_check_sbp_integrity_MsgAcknowledge.cc index 3274f588e8..f6f681452c 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgAcknowledge.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgAcknowledge.cc @@ -16,106 +16,797 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgAcknowledge0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgAcknowledge0 : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgAcknowledge0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgAcknowledge0() { + assign(test_msg_.area_id, 123456); + assign(test_msg_.correction_mask_on_demand, 1); + assign(test_msg_.correction_mask_stream, 1); + assign(test_msg_.request_id, 30); + assign(test_msg_.response_code, 0); + assign(test_msg_.solution_id, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_acknowledge_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_acknowledge_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAcknowledge, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_acknowledge_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAcknowledge); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->acknowledge, sizeof(msg->acknowledge)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_acknowledge_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.acknowledge, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAcknowledge); + info.sender_id = 42; + info.preamble = 0x55; + info.crc = 0xB256; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_acknowledge_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_acknowledge_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_acknowledge_t &lesser, + const sbp_msg_acknowledge_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_acknowledge_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_acknowledge_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_acknowledge_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_acknowledge_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcknowledge, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAcknowledge, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAcknowledge, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAcknowledge, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_integrity_MsgAcknowledge0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_acknowledge_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { 85, 210, 11, 42, 0, 11, 30, 64, 226, 1, 0, 0, 1, 0, 1, 0, 2, 86, 178, }; + uint8_t encoded_payload_[11] = { + 30, 64, 226, 1, 0, 0, 1, 0, 1, 0, 2, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_acknowledge_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAcknowledge, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_acknowledge_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAcknowledge, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_acknowledge_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_acknowledge_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acknowledge_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_acknowledge_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAcknowledge, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_acknowledge_t msg{}; + + EXPECT_EQ(sbp_msg_acknowledge_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_acknowledge_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_acknowledge_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} - sbp_msg_acknowledge_t test_msg{}; - test_msg.area_id = 123456; - test_msg.correction_mask_on_demand = 1; - test_msg.correction_mask_stream = 1; - test_msg.request_id = 30; - test_msg.response_code = 0; - test_msg.solution_id = 2; - - EXPECT_EQ(send_message(42, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 42); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.area_id, 123456) - << "incorrect value for last_msg_.area_id, expected 123456, is " - << last_msg_.area_id; - EXPECT_EQ(last_msg_.correction_mask_on_demand, 1) - << "incorrect value for last_msg_.correction_mask_on_demand, expected 1, " - "is " - << last_msg_.correction_mask_on_demand; - EXPECT_EQ(last_msg_.correction_mask_stream, 1) - << "incorrect value for last_msg_.correction_mask_stream, expected 1, is " - << last_msg_.correction_mask_stream; - EXPECT_EQ(last_msg_.request_id, 30) - << "incorrect value for last_msg_.request_id, expected 30, is " - << last_msg_.request_id; - EXPECT_EQ(last_msg_.response_code, 0) - << "incorrect value for last_msg_.response_code, expected 0, is " - << last_msg_.response_code; - EXPECT_EQ(last_msg_.solution_id, 2) - << "incorrect value for last_msg_.solution_id, expected 2, is " - << last_msg_.solution_id; +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_acknowledge_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcknowledge, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAcknowledge, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAcknowledge, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.area_id, greater.area_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.correction_mask_on_demand, + greater.correction_mask_on_demand); + comparison_tests(lesser, greater); + } + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.correction_mask_stream, + greater.correction_mask_stream); + comparison_tests(lesser, greater); + } + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.request_id, greater.request_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.response_code, greater.response_code); + comparison_tests(lesser, greater); + } + { + sbp_msg_acknowledge_t lesser = info.test_msg; + sbp_msg_acknowledge_t greater = info.test_msg; + make_lesser_greater(lesser.solution_id, greater.solution_id); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAcknowledge); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ACKNOWLEDGE"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_acknowledge_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_acknowledge_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.acknowledge, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.acknowledge, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_acknowledge_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAcknowledge, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgAcknowledge0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAcknowledge, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagHighLevel.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagHighLevel.cc index 21dfbfe29c..f4ac781788 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagHighLevel.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagHighLevel.cc @@ -16,173 +16,934 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagHighLevel0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagHighLevel0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0() { + assign(test_msg_.chain_id, 40); + assign(test_msg_.corr_time.tow, 360); + assign(test_msg_.corr_time.wn, 6); + assign(test_msg_.obs_time.tow, 180); + assign(test_msg_.obs_time.wn, 3); + + assign(test_msg_.reserved[0], 0); + + assign(test_msg_.reserved[1], 0); + + assign(test_msg_.reserved[2], 0); + + assign(test_msg_.reserved[3], 0); + + assign(test_msg_.reserved[4], 0); + + assign(test_msg_.reserved[5], 0); + assign(test_msg_.ssr_sol_id, 10); + assign(test_msg_.tile_id, 30); + assign(test_msg_.tile_set_id, 20); + assign(test_msg_.use_bds_sat, 3); + assign(test_msg_.use_gal_sat, 2); + assign(test_msg_.use_gps_sat, 1); + assign(test_msg_.use_iono_grid_point_sat_los, 7); + assign(test_msg_.use_iono_grid_points, 5); + assign(test_msg_.use_iono_tile_sat_los, 6); + assign(test_msg_.use_tropo_grid_points, 4); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_high_level_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_flag_high_level_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagHighLevel, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_high_level_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagHighLevel); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_high_level, + sizeof(msg->ssr_flag_high_level)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_high_level_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_high_level, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrFlagHighLevel); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x4366; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 31; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_flag_high_level_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_high_level_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_flag_high_level_t &lesser, + const sbp_msg_ssr_flag_high_level_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_flag_high_level_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_flag_high_level_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_flag_high_level_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagHighLevel, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagHighLevel, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagHighLevel, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagHighLevel, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagHighLevel0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_high_level_t test_msg_{}; + uint8_t encoded_frame_[31 + 8] = { 85, 185, 11, 66, 0, 31, 180, 0, 0, 0, 3, 0, 104, 1, 0, 0, 6, 0, 10, 20, 0, 30, 0, 40, 1, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 102, 67, }; + uint8_t encoded_payload_[31] = { + 180, 0, 0, 0, 3, 0, 104, 1, 0, 0, 6, 0, 10, 20, 0, 30, + 0, 40, 1, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_flag_high_level_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrFlagHighLevel, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; - sbp_msg_ssr_flag_high_level_t test_msg{}; - test_msg.chain_id = 40; - test_msg.corr_time.tow = 360; - test_msg.corr_time.wn = 6; - test_msg.obs_time.tow = 180; - test_msg.obs_time.wn = 3; - - test_msg.reserved[0] = 0; - - test_msg.reserved[1] = 0; - - test_msg.reserved[2] = 0; - - test_msg.reserved[3] = 0; - - test_msg.reserved[4] = 0; - - test_msg.reserved[5] = 0; - test_msg.ssr_sol_id = 10; - test_msg.tile_id = 30; - test_msg.tile_set_id = 20; - test_msg.use_bds_sat = 3; - test_msg.use_gal_sat = 2; - test_msg.use_gps_sat = 1; - test_msg.use_iono_grid_point_sat_los = 7; - test_msg.use_iono_grid_points = 5; - test_msg.use_iono_tile_sat_los = 6; - test_msg.use_tropo_grid_points = 4; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.chain_id, 40) - << "incorrect value for last_msg_.chain_id, expected 40, is " - << last_msg_.chain_id; - EXPECT_EQ(last_msg_.corr_time.tow, 360) - << "incorrect value for last_msg_.corr_time.tow, expected 360, is " - << last_msg_.corr_time.tow; - EXPECT_EQ(last_msg_.corr_time.wn, 6) - << "incorrect value for last_msg_.corr_time.wn, expected 6, is " - << last_msg_.corr_time.wn; - EXPECT_EQ(last_msg_.obs_time.tow, 180) - << "incorrect value for last_msg_.obs_time.tow, expected 180, is " - << last_msg_.obs_time.tow; - EXPECT_EQ(last_msg_.obs_time.wn, 3) - << "incorrect value for last_msg_.obs_time.wn, expected 3, is " - << last_msg_.obs_time.wn; - EXPECT_EQ(last_msg_.reserved[0], 0) - << "incorrect value for last_msg_.reserved[0], expected 0, is " - << last_msg_.reserved[0]; - EXPECT_EQ(last_msg_.reserved[1], 0) - << "incorrect value for last_msg_.reserved[1], expected 0, is " - << last_msg_.reserved[1]; - EXPECT_EQ(last_msg_.reserved[2], 0) - << "incorrect value for last_msg_.reserved[2], expected 0, is " - << last_msg_.reserved[2]; - EXPECT_EQ(last_msg_.reserved[3], 0) - << "incorrect value for last_msg_.reserved[3], expected 0, is " - << last_msg_.reserved[3]; - EXPECT_EQ(last_msg_.reserved[4], 0) - << "incorrect value for last_msg_.reserved[4], expected 0, is " - << last_msg_.reserved[4]; - EXPECT_EQ(last_msg_.reserved[5], 0) - << "incorrect value for last_msg_.reserved[5], expected 0, is " - << last_msg_.reserved[5]; - EXPECT_EQ(last_msg_.ssr_sol_id, 10) - << "incorrect value for last_msg_.ssr_sol_id, expected 10, is " - << last_msg_.ssr_sol_id; - EXPECT_EQ(last_msg_.tile_id, 30) - << "incorrect value for last_msg_.tile_id, expected 30, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 20) - << "incorrect value for last_msg_.tile_set_id, expected 20, is " - << last_msg_.tile_set_id; - EXPECT_EQ(last_msg_.use_bds_sat, 3) - << "incorrect value for last_msg_.use_bds_sat, expected 3, is " - << last_msg_.use_bds_sat; - EXPECT_EQ(last_msg_.use_gal_sat, 2) - << "incorrect value for last_msg_.use_gal_sat, expected 2, is " - << last_msg_.use_gal_sat; - EXPECT_EQ(last_msg_.use_gps_sat, 1) - << "incorrect value for last_msg_.use_gps_sat, expected 1, is " - << last_msg_.use_gps_sat; - EXPECT_EQ(last_msg_.use_iono_grid_point_sat_los, 7) - << "incorrect value for last_msg_.use_iono_grid_point_sat_los, expected " - "7, is " - << last_msg_.use_iono_grid_point_sat_los; - EXPECT_EQ(last_msg_.use_iono_grid_points, 5) - << "incorrect value for last_msg_.use_iono_grid_points, expected 5, is " - << last_msg_.use_iono_grid_points; - EXPECT_EQ(last_msg_.use_iono_tile_sat_los, 6) - << "incorrect value for last_msg_.use_iono_tile_sat_los, expected 6, is " - << last_msg_.use_iono_tile_sat_los; - EXPECT_EQ(last_msg_.use_tropo_grid_points, 4) - << "incorrect value for last_msg_.use_tropo_grid_points, expected 4, is " - << last_msg_.use_tropo_grid_points; + EXPECT_EQ(sbp_msg_ssr_flag_high_level_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagHighLevel, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + for (uint8_t i = 0; i < 31; i++) { + EXPECT_EQ( + sbp_msg_ssr_flag_high_level_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_high_level_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrFlagHighLevel, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_high_level_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_high_level_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_high_level_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrFlagHighLevel, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrFlagHighLevel, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrFlagHighLevel, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.chain_id, greater.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.corr_time.tow, greater.corr_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.corr_time.wn, greater.corr_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.obs_time.tow, greater.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.obs_time.wn, greater.obs_time.wn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[0], greater.reserved[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[1], greater.reserved[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[2], greater.reserved[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[3], greater.reserved[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[4], greater.reserved[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[5], greater.reserved[5]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_sol_id, greater.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_bds_sat, greater.use_bds_sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_gal_sat, greater.use_gal_sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_gps_sat, greater.use_gps_sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_iono_grid_point_sat_los, + greater.use_iono_grid_point_sat_los); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_iono_grid_points, + greater.use_iono_grid_points); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_iono_tile_sat_los, + greater.use_iono_tile_sat_los); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_high_level_t lesser = info.test_msg; + sbp_msg_ssr_flag_high_level_t greater = info.test_msg; + make_lesser_greater(lesser.use_tropo_grid_points, + greater.use_tropo_grid_points); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagHighLevel); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_FLAG_HIGH_LEVEL"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_high_level_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_flag_high_level_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_flag_high_level, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_flag_high_level, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_high_level_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagHighLevel, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagHighLevel0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagHighLevel, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos.cc index 2dd620d95c..309d079fef 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos.cc @@ -16,143 +16,919 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0() { + assign(test_msg_.faulty_los[0].constellation, 11); + assign(test_msg_.faulty_los[0].satId, 10); + + assign(test_msg_.faulty_los[1].constellation, 14); + assign(test_msg_.faulty_los[1].satId, 15); + assign(test_msg_.grid_point_id, 30); + assign(test_msg_.header.chain_id, 6); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.obs_time.tow, 180); + assign(test_msg_.header.obs_time.wn, 3); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.ssr_sol_id, 3); + assign(test_msg_.header.tile_id, 5); + assign(test_msg_.header.tile_set_id, 4); + assign(test_msg_.n_faulty_los, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_flag_iono_grid_point_sat_los_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_flag_iono_grid_point_sat_los_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagIonoGridPointSatLos, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagIonoGridPointSatLos); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_iono_grid_point_sat_los, + sizeof(msg->ssr_flag_iono_grid_point_sat_los)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_iono_grid_point_sat_los, &test_msg_, + sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgSsrFlagIonoGridPointSatLos); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x9462; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 21; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_flag_iono_grid_point_sat_los_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_iono_grid_point_sat_los_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests( + const sbp_msg_ssr_flag_iono_grid_point_sat_los_t &lesser, + const sbp_msg_ssr_flag_iono_grid_point_sat_los_t &greater) { + sbp_msg_t wrapped_lesser = sbp::MessageTraits< + sbp_msg_ssr_flag_iono_grid_point_sat_los_t>::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = sbp::MessageTraits< + sbp_msg_ssr_flag_iono_grid_point_sat_los_t>::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_cmp(&lesser, &lesser), + 0); + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_cmp(&greater, &greater), + 0); + EXPECT_LE(sbp_msg_ssr_flag_iono_grid_point_sat_los_cmp(&lesser, &greater), + 0); + EXPECT_GT(sbp_msg_ssr_flag_iono_grid_point_sat_los_cmp(&greater, &lesser), + 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoGridPointSatLos, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoGridPointSatLos, + &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagIonoGridPointSatLos, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagIonoGridPointSatLos, + &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_iono_grid_point_sat_los_t test_msg_{}; + uint8_t encoded_frame_[21 + 8] = { 85, 209, 11, 66, 0, 21, 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 30, 0, 2, 10, 11, 15, 14, 98, 148, }; + uint8_t encoded_payload_[21] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 30, 0, 2, 10, 11, 15, 14, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp_msg_ssr_flag_iono_grid_point_sat_los_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrFlagIonoGridPointSatLos, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagIonoGridPointSatLos, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + for (uint8_t i = 0; i < 21; i++) { + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_encode( + &buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrFlagIonoGridPointSatLos, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t t{}; + return sbp_msg_ssr_flag_iono_grid_point_sat_los_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t t{}; + t.n_faulty_los = 1; + return sbp_msg_ssr_flag_iono_grid_point_sat_los_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); - sbp_msg_ssr_flag_iono_grid_point_sat_los_t test_msg{}; - - test_msg.faulty_los[0].constellation = 11; - test_msg.faulty_los[0].satId = 10; - - test_msg.faulty_los[1].constellation = 14; - test_msg.faulty_los[1].satId = 15; - test_msg.grid_point_id = 30; - test_msg.header.chain_id = 6; - test_msg.header.num_msgs = 1; - test_msg.header.obs_time.tow = 180; - test_msg.header.obs_time.wn = 3; - test_msg.header.seq_num = 2; - test_msg.header.ssr_sol_id = 3; - test_msg.header.tile_id = 5; - test_msg.header.tile_set_id = 4; - test_msg.n_faulty_los = 2; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.faulty_los[0].constellation, 11) - << "incorrect value for last_msg_.faulty_los[0].constellation, expected " - "11, is " - << last_msg_.faulty_los[0].constellation; - EXPECT_EQ(last_msg_.faulty_los[0].satId, 10) - << "incorrect value for last_msg_.faulty_los[0].satId, expected 10, is " - << last_msg_.faulty_los[0].satId; - EXPECT_EQ(last_msg_.faulty_los[1].constellation, 14) - << "incorrect value for last_msg_.faulty_los[1].constellation, expected " - "14, is " - << last_msg_.faulty_los[1].constellation; - EXPECT_EQ(last_msg_.faulty_los[1].satId, 15) - << "incorrect value for last_msg_.faulty_los[1].satId, expected 15, is " - << last_msg_.faulty_los[1].satId; - EXPECT_EQ(last_msg_.grid_point_id, 30) - << "incorrect value for last_msg_.grid_point_id, expected 30, is " - << last_msg_.grid_point_id; - EXPECT_EQ(last_msg_.header.chain_id, 6) - << "incorrect value for last_msg_.header.chain_id, expected 6, is " - << last_msg_.header.chain_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.obs_time.tow, 180) - << "incorrect value for last_msg_.header.obs_time.tow, expected 180, is " - << last_msg_.header.obs_time.tow; - EXPECT_EQ(last_msg_.header.obs_time.wn, 3) - << "incorrect value for last_msg_.header.obs_time.wn, expected 3, is " - << last_msg_.header.obs_time.wn; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.ssr_sol_id, 3) - << "incorrect value for last_msg_.header.ssr_sol_id, expected 3, is " - << last_msg_.header.ssr_sol_id; - EXPECT_EQ(last_msg_.header.tile_id, 5) - << "incorrect value for last_msg_.header.tile_id, expected 5, is " - << last_msg_.header.tile_id; - EXPECT_EQ(last_msg_.header.tile_set_id, 4) - << "incorrect value for last_msg_.header.tile_set_id, expected 4, is " - << last_msg_.header.tile_set_id; - EXPECT_EQ(last_msg_.n_faulty_los, 2) - << "incorrect value for last_msg_.n_faulty_los, expected 2, is " - << last_msg_.n_faulty_los; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } } + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_point_sat_los_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoGridPointSatLos, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrFlagIonoGridPointSatLos, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoGridPointSatLos, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[0].constellation, + greater.faulty_los[0].constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[0].satId, + greater.faulty_los[0].satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[1].constellation, + greater.faulty_los[1].constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[1].satId, + greater.faulty_los[1].satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.grid_point_id, greater.grid_point_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.chain_id, greater.header.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.tow, + greater.header.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.wn, greater.header.obs_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.ssr_sol_id, greater.header.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_point_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_point_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.n_faulty_los, greater.n_faulty_los); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagIonoGridPointSatLos); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_SSR_FLAG_IONO_GRID_POINT_SAT_LOS"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_iono_grid_point_sat_los_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_flag_iono_grid_point_sat_los_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits< + sbp_msg_ssr_flag_iono_grid_point_sat_los_t>::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_flag_iono_grid_point_sat_los, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_flag_iono_grid_point_sat_los, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits:: + encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ( + sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_point_sat_los_t msg{}; + uint8_t n_read; + + EXPECT_EQ( + sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagIonoGridPointSatLos, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPointSatLos0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagIonoGridPointSatLos, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints.cc index d0077dee23..d1f6ecc4af 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints.cc @@ -16,133 +16,892 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0() { + assign(test_msg_.faulty_points[0], 10); + + assign(test_msg_.faulty_points[1], 11); + + assign(test_msg_.faulty_points[2], 12); + assign(test_msg_.header.chain_id, 6); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.obs_time.tow, 180); + assign(test_msg_.header.obs_time.wn, 3); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.ssr_sol_id, 3); + assign(test_msg_.header.tile_id, 5); + assign(test_msg_.header.tile_set_id, 4); + assign(test_msg_.n_faulty_points, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_flag_iono_grid_points_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_grid_points_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_flag_iono_grid_points_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagIonoGridPoints, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_grid_points_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagIonoGridPoints); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_iono_grid_points, + sizeof(msg->ssr_flag_iono_grid_points)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_iono_grid_points_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_iono_grid_points, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrFlagIonoGridPoints); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x0735; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 21; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_flag_iono_grid_points_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_iono_grid_points_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_flag_iono_grid_points_t &lesser, + const sbp_msg_ssr_flag_iono_grid_points_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_flag_iono_grid_points_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_flag_iono_grid_points_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoGridPoints, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoGridPoints, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagIonoGridPoints, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagIonoGridPoints, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_iono_grid_points_t test_msg_{}; + uint8_t encoded_frame_[21 + 8] = { 85, 199, 11, 66, 0, 21, 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 3, 10, 0, 11, 0, 12, 0, 53, 7, }; + uint8_t encoded_payload_[21] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 3, 10, 0, 11, 0, 12, 0, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrFlagIonoGridPoints, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagIonoGridPoints, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + for (uint8_t i = 0; i < 21; i++) { + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_points_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrFlagIonoGridPoints, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_points_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_points_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_flag_iono_grid_points_t t{}; + return sbp_msg_ssr_flag_iono_grid_points_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_flag_iono_grid_points_t t{}; + t.n_faulty_points = 1; + return sbp_msg_ssr_flag_iono_grid_points_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ssr_flag_iono_grid_points_t test_msg{}; - - test_msg.faulty_points[0] = 10; - - test_msg.faulty_points[1] = 11; - - test_msg.faulty_points[2] = 12; - test_msg.header.chain_id = 6; - test_msg.header.num_msgs = 1; - test_msg.header.obs_time.tow = 180; - test_msg.header.obs_time.wn = 3; - test_msg.header.seq_num = 2; - test_msg.header.ssr_sol_id = 3; - test_msg.header.tile_id = 5; - test_msg.header.tile_set_id = 4; - test_msg.n_faulty_points = 3; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.faulty_points[0], 10) - << "incorrect value for last_msg_.faulty_points[0], expected 10, is " - << last_msg_.faulty_points[0]; - EXPECT_EQ(last_msg_.faulty_points[1], 11) - << "incorrect value for last_msg_.faulty_points[1], expected 11, is " - << last_msg_.faulty_points[1]; - EXPECT_EQ(last_msg_.faulty_points[2], 12) - << "incorrect value for last_msg_.faulty_points[2], expected 12, is " - << last_msg_.faulty_points[2]; - EXPECT_EQ(last_msg_.header.chain_id, 6) - << "incorrect value for last_msg_.header.chain_id, expected 6, is " - << last_msg_.header.chain_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.obs_time.tow, 180) - << "incorrect value for last_msg_.header.obs_time.tow, expected 180, is " - << last_msg_.header.obs_time.tow; - EXPECT_EQ(last_msg_.header.obs_time.wn, 3) - << "incorrect value for last_msg_.header.obs_time.wn, expected 3, is " - << last_msg_.header.obs_time.wn; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.ssr_sol_id, 3) - << "incorrect value for last_msg_.header.ssr_sol_id, expected 3, is " - << last_msg_.header.ssr_sol_id; - EXPECT_EQ(last_msg_.header.tile_id, 5) - << "incorrect value for last_msg_.header.tile_id, expected 5, is " - << last_msg_.header.tile_id; - EXPECT_EQ(last_msg_.header.tile_set_id, 4) - << "incorrect value for last_msg_.header.tile_set_id, expected 4, is " - << last_msg_.header.tile_set_id; - EXPECT_EQ(last_msg_.n_faulty_points, 3) - << "incorrect value for last_msg_.n_faulty_points, expected 3, is " - << last_msg_.n_faulty_points; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); } + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_grid_points_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoGridPoints, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrFlagIonoGridPoints, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoGridPoints, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[0], greater.faulty_points[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[1], greater.faulty_points[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[2], greater.faulty_points[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.chain_id, greater.header.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.tow, + greater.header.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.wn, greater.header.obs_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.ssr_sol_id, greater.header.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.n_faulty_points, greater.n_faulty_points); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagIonoGridPoints); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_FLAG_IONO_GRID_POINTS"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_iono_grid_points_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_flag_iono_grid_points_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_flag_iono_grid_points, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_flag_iono_grid_points, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_grid_points_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagIonoGridPoints, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoGridPoints0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagIonoGridPoints, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos.cc index 91580ed51f..d996e4391f 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos.cc @@ -16,139 +16,901 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0() { + assign(test_msg_.faulty_los[0].constellation, 11); + assign(test_msg_.faulty_los[0].satId, 10); + + assign(test_msg_.faulty_los[1].constellation, 14); + assign(test_msg_.faulty_los[1].satId, 15); + assign(test_msg_.header.chain_id, 6); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.obs_time.tow, 180); + assign(test_msg_.header.obs_time.wn, 3); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.ssr_sol_id, 3); + assign(test_msg_.header.tile_id, 5); + assign(test_msg_.header.tile_set_id, 4); + assign(test_msg_.n_faulty_los, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_flag_iono_tile_sat_los_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_tile_sat_los_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_flag_iono_tile_sat_los_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagIonoTileSatLos, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_iono_tile_sat_los_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagIonoTileSatLos); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_iono_tile_sat_los, + sizeof(msg->ssr_flag_iono_tile_sat_los)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_iono_tile_sat_los_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_iono_tile_sat_los, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrFlagIonoTileSatLos); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xEBEF; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 19; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_flag_iono_tile_sat_los_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_iono_tile_sat_los_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_flag_iono_tile_sat_los_t &lesser, + const sbp_msg_ssr_flag_iono_tile_sat_los_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_flag_iono_tile_sat_los_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_flag_iono_tile_sat_los_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoTileSatLos, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagIonoTileSatLos, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagIonoTileSatLos, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagIonoTileSatLos, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_iono_tile_sat_los_t test_msg_{}; + uint8_t encoded_frame_[19 + 8] = { 85, 205, 11, 66, 0, 19, 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 2, 10, 11, 15, 14, 239, 235, }; + uint8_t encoded_payload_[19] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 2, 10, 11, 15, 14, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrFlagIonoTileSatLos, + &info.test_msg_wrapped), + info.payload_len); +} - sbp_msg_ssr_flag_iono_tile_sat_los_t test_msg{}; - - test_msg.faulty_los[0].constellation = 11; - test_msg.faulty_los[0].satId = 10; - - test_msg.faulty_los[1].constellation = 14; - test_msg.faulty_los[1].satId = 15; - test_msg.header.chain_id = 6; - test_msg.header.num_msgs = 1; - test_msg.header.obs_time.tow = 180; - test_msg.header.obs_time.wn = 3; - test_msg.header.seq_num = 2; - test_msg.header.ssr_sol_id = 3; - test_msg.header.tile_id = 5; - test_msg.header.tile_set_id = 4; - test_msg.n_faulty_los = 2; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.faulty_los[0].constellation, 11) - << "incorrect value for last_msg_.faulty_los[0].constellation, expected " - "11, is " - << last_msg_.faulty_los[0].constellation; - EXPECT_EQ(last_msg_.faulty_los[0].satId, 10) - << "incorrect value for last_msg_.faulty_los[0].satId, expected 10, is " - << last_msg_.faulty_los[0].satId; - EXPECT_EQ(last_msg_.faulty_los[1].constellation, 14) - << "incorrect value for last_msg_.faulty_los[1].constellation, expected " - "14, is " - << last_msg_.faulty_los[1].constellation; - EXPECT_EQ(last_msg_.faulty_los[1].satId, 15) - << "incorrect value for last_msg_.faulty_los[1].satId, expected 15, is " - << last_msg_.faulty_los[1].satId; - EXPECT_EQ(last_msg_.header.chain_id, 6) - << "incorrect value for last_msg_.header.chain_id, expected 6, is " - << last_msg_.header.chain_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.obs_time.tow, 180) - << "incorrect value for last_msg_.header.obs_time.tow, expected 180, is " - << last_msg_.header.obs_time.tow; - EXPECT_EQ(last_msg_.header.obs_time.wn, 3) - << "incorrect value for last_msg_.header.obs_time.wn, expected 3, is " - << last_msg_.header.obs_time.wn; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.ssr_sol_id, 3) - << "incorrect value for last_msg_.header.ssr_sol_id, expected 3, is " - << last_msg_.header.ssr_sol_id; - EXPECT_EQ(last_msg_.header.tile_id, 5) - << "incorrect value for last_msg_.header.tile_id, expected 5, is " - << last_msg_.header.tile_id; - EXPECT_EQ(last_msg_.header.tile_set_id, 4) - << "incorrect value for last_msg_.header.tile_set_id, expected 4, is " - << last_msg_.header.tile_set_id; - EXPECT_EQ(last_msg_.n_faulty_los, 2) - << "incorrect value for last_msg_.n_faulty_los, expected 2, is " - << last_msg_.n_faulty_los; +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[19]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 19); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 19), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagIonoTileSatLos, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 19); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 19), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[19]; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 19), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[19]; + + for (uint8_t i = 0; i < 19; i++) { + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_tile_sat_los_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 19); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrFlagIonoTileSatLos, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 19); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_tile_sat_los_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_tile_sat_los_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_flag_iono_tile_sat_los_t t{}; + return sbp_msg_ssr_flag_iono_tile_sat_los_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_flag_iono_tile_sat_los_t t{}; + t.n_faulty_los = 1; + return sbp_msg_ssr_flag_iono_tile_sat_los_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } } + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_iono_tile_sat_los_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoTileSatLos, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrFlagIonoTileSatLos, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagIonoTileSatLos, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[0].constellation, + greater.faulty_los[0].constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[0].satId, + greater.faulty_los[0].satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[1].constellation, + greater.faulty_los[1].constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_los[1].satId, + greater.faulty_los[1].satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.chain_id, greater.header.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.tow, + greater.header.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.wn, greater.header.obs_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.ssr_sol_id, greater.header.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_iono_tile_sat_los_t lesser = info.test_msg; + sbp_msg_ssr_flag_iono_tile_sat_los_t greater = info.test_msg; + make_lesser_greater(lesser.n_faulty_los, greater.n_faulty_los); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagIonoTileSatLos); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_FLAG_IONO_TILE_SAT_LOS"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_iono_tile_sat_los_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_flag_iono_tile_sat_los_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_flag_iono_tile_sat_los, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_flag_iono_tile_sat_los, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[19]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 19); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 19), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_iono_tile_sat_los_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 19); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagIonoTileSatLos, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagIonoTileSatLos0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagIonoTileSatLos, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagSatellites.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagSatellites.cc index 6f2f141fb3..474e4096b1 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagSatellites.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagSatellites.cc @@ -16,129 +16,872 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagSatellites0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagSatellites0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagSatellites0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagSatellites0() { + assign(test_msg_.chain_id, 4); + assign(test_msg_.const_id, 5); + + assign(test_msg_.faulty_sats[0], 10); + + assign(test_msg_.faulty_sats[1], 11); + + assign(test_msg_.faulty_sats[2], 12); + assign(test_msg_.n_faulty_sats, 3); + assign(test_msg_.num_msgs, 1); + assign(test_msg_.obs_time.tow, 180); + assign(test_msg_.obs_time.wn, 3); + assign(test_msg_.seq_num, 2); + assign(test_msg_.ssr_sol_id, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_satellites_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_flag_satellites_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagSatellites, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_satellites_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagSatellites); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_satellites, + sizeof(msg->ssr_flag_satellites)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_satellites_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_satellites, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrFlagSatellites); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xA56E; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_flag_satellites_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_satellites_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_flag_satellites_t &lesser, + const sbp_msg_ssr_flag_satellites_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_flag_satellites_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_flag_satellites_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_flag_satellites_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagSatellites, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagSatellites, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagSatellites, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagSatellites, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagSatellites0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_satellites_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { 85, 189, 11, 66, 0, 15, 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 5, 3, 10, 11, 12, 110, 165, }; + uint8_t encoded_payload_[15] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 5, 3, 10, 11, 12, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_flag_satellites_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrFlagSatellites, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagSatellites, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ( + sbp_msg_ssr_flag_satellites_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_satellites_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrFlagSatellites, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_satellites_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_satellites_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_flag_satellites_t t{}; + return sbp_msg_ssr_flag_satellites_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_flag_satellites_t t{}; + t.n_faulty_sats = 1; + return sbp_msg_ssr_flag_satellites_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ssr_flag_satellites_t test_msg{}; - test_msg.chain_id = 4; - test_msg.const_id = 5; - - test_msg.faulty_sats[0] = 10; - - test_msg.faulty_sats[1] = 11; - - test_msg.faulty_sats[2] = 12; - test_msg.n_faulty_sats = 3; - test_msg.num_msgs = 1; - test_msg.obs_time.tow = 180; - test_msg.obs_time.wn = 3; - test_msg.seq_num = 2; - test_msg.ssr_sol_id = 3; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.chain_id, 4) - << "incorrect value for last_msg_.chain_id, expected 4, is " - << last_msg_.chain_id; - EXPECT_EQ(last_msg_.const_id, 5) - << "incorrect value for last_msg_.const_id, expected 5, is " - << last_msg_.const_id; - EXPECT_EQ(last_msg_.faulty_sats[0], 10) - << "incorrect value for last_msg_.faulty_sats[0], expected 10, is " - << last_msg_.faulty_sats[0]; - EXPECT_EQ(last_msg_.faulty_sats[1], 11) - << "incorrect value for last_msg_.faulty_sats[1], expected 11, is " - << last_msg_.faulty_sats[1]; - EXPECT_EQ(last_msg_.faulty_sats[2], 12) - << "incorrect value for last_msg_.faulty_sats[2], expected 12, is " - << last_msg_.faulty_sats[2]; - EXPECT_EQ(last_msg_.n_faulty_sats, 3) - << "incorrect value for last_msg_.n_faulty_sats, expected 3, is " - << last_msg_.n_faulty_sats; - EXPECT_EQ(last_msg_.num_msgs, 1) - << "incorrect value for last_msg_.num_msgs, expected 1, is " - << last_msg_.num_msgs; - EXPECT_EQ(last_msg_.obs_time.tow, 180) - << "incorrect value for last_msg_.obs_time.tow, expected 180, is " - << last_msg_.obs_time.tow; - EXPECT_EQ(last_msg_.obs_time.wn, 3) - << "incorrect value for last_msg_.obs_time.wn, expected 3, is " - << last_msg_.obs_time.wn; - EXPECT_EQ(last_msg_.seq_num, 2) - << "incorrect value for last_msg_.seq_num, expected 2, is " - << last_msg_.seq_num; - EXPECT_EQ(last_msg_.ssr_sol_id, 3) - << "incorrect value for last_msg_.ssr_sol_id, expected 3, is " - << last_msg_.ssr_sol_id; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } } + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_satellites_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrFlagSatellites, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrFlagSatellites, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrFlagSatellites, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.chain_id, greater.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.const_id, greater.const_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_sats[0], greater.faulty_sats[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_sats[1], greater.faulty_sats[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_sats[2], greater.faulty_sats[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.n_faulty_sats, greater.n_faulty_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.num_msgs, greater.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.obs_time.tow, greater.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.obs_time.wn, greater.obs_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.seq_num, greater.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_satellites_t lesser = info.test_msg; + sbp_msg_ssr_flag_satellites_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_sol_id, greater.ssr_sol_id); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagSatellites); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_FLAG_SATELLITES"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_satellites_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_flag_satellites_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_flag_satellites, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_flag_satellites, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_satellites_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagSatellites, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagSatellites0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagSatellites, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints.cc b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints.cc index 061cd6e850..0dcbf05b32 100644 --- a/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints.cc +++ b/c/test/cpp/auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints.cc @@ -16,134 +16,892 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0 + : public ::testing::Test { public: - Test_auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0() { + assign(test_msg_.faulty_points[0], 10); + + assign(test_msg_.faulty_points[1], 11); + + assign(test_msg_.faulty_points[2], 12); + assign(test_msg_.header.chain_id, 6); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.obs_time.tow, 180); + assign(test_msg_.header.obs_time.wn, 3); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.ssr_sol_id, 3); + assign(test_msg_.header.tile_id, 5); + assign(test_msg_.header.tile_set_id, 4); + assign(test_msg_.n_faulty_points, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_flag_tropo_grid_points_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_tropo_grid_points_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_flag_tropo_grid_points_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrFlagTropoGridPoints, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_flag_tropo_grid_points_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrFlagTropoGridPoints); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_flag_tropo_grid_points, + sizeof(msg->ssr_flag_tropo_grid_points)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_flag_tropo_grid_points_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_flag_tropo_grid_points, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrFlagTropoGridPoints); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x96F3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 21; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_flag_tropo_grid_points_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_flag_tropo_grid_points_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_flag_tropo_grid_points_t &lesser, + const sbp_msg_ssr_flag_tropo_grid_points_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_flag_tropo_grid_points_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_flag_tropo_grid_points_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagTropoGridPoints, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrFlagTropoGridPoints, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrFlagTropoGridPoints, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrFlagTropoGridPoints, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_flag_tropo_grid_points_t test_msg_{}; + uint8_t encoded_frame_[21 + 8] = { 85, 195, 11, 66, 0, 21, 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 3, 10, 0, 11, 0, 12, 0, 243, 150, }; + uint8_t encoded_payload_[21] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 4, 0, 5, 0, 6, 3, 10, 0, 11, 0, 12, 0, + }; +}; + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrFlagTropoGridPoints, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrFlagTropoGridPoints, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + + for (uint8_t i = 0; i < 21; i++) { + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_tropo_grid_points_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrFlagTropoGridPoints, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_tropo_grid_points_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_tropo_grid_points_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_flag_tropo_grid_points_t t{}; + return sbp_msg_ssr_flag_tropo_grid_points_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_flag_tropo_grid_points_t t{}; + t.n_faulty_points = 1; + return sbp_msg_ssr_flag_tropo_grid_points_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ssr_flag_tropo_grid_points_t test_msg{}; - - test_msg.faulty_points[0] = 10; - - test_msg.faulty_points[1] = 11; - - test_msg.faulty_points[2] = 12; - test_msg.header.chain_id = 6; - test_msg.header.num_msgs = 1; - test_msg.header.obs_time.tow = 180; - test_msg.header.obs_time.wn = 3; - test_msg.header.seq_num = 2; - test_msg.header.ssr_sol_id = 3; - test_msg.header.tile_id = 5; - test_msg.header.tile_set_id = 4; - test_msg.n_faulty_points = 3; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.faulty_points[0], 10) - << "incorrect value for last_msg_.faulty_points[0], expected 10, is " - << last_msg_.faulty_points[0]; - EXPECT_EQ(last_msg_.faulty_points[1], 11) - << "incorrect value for last_msg_.faulty_points[1], expected 11, is " - << last_msg_.faulty_points[1]; - EXPECT_EQ(last_msg_.faulty_points[2], 12) - << "incorrect value for last_msg_.faulty_points[2], expected 12, is " - << last_msg_.faulty_points[2]; - EXPECT_EQ(last_msg_.header.chain_id, 6) - << "incorrect value for last_msg_.header.chain_id, expected 6, is " - << last_msg_.header.chain_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.obs_time.tow, 180) - << "incorrect value for last_msg_.header.obs_time.tow, expected 180, is " - << last_msg_.header.obs_time.tow; - EXPECT_EQ(last_msg_.header.obs_time.wn, 3) - << "incorrect value for last_msg_.header.obs_time.wn, expected 3, is " - << last_msg_.header.obs_time.wn; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.ssr_sol_id, 3) - << "incorrect value for last_msg_.header.ssr_sol_id, expected 3, is " - << last_msg_.header.ssr_sol_id; - EXPECT_EQ(last_msg_.header.tile_id, 5) - << "incorrect value for last_msg_.header.tile_id, expected 5, is " - << last_msg_.header.tile_id; - EXPECT_EQ(last_msg_.header.tile_set_id, 4) - << "incorrect value for last_msg_.header.tile_set_id, expected 4, is " - << last_msg_.header.tile_set_id; - EXPECT_EQ(last_msg_.n_faulty_points, 3) - << "incorrect value for last_msg_.n_faulty_points, expected 3, is " - << last_msg_.n_faulty_points; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); } + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_flag_tropo_grid_points_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagTropoGridPoints, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrFlagTropoGridPoints, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrFlagTropoGridPoints, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[0], greater.faulty_points[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[1], greater.faulty_points[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.faulty_points[2], greater.faulty_points[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.chain_id, greater.header.chain_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.tow, + greater.header.obs_time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.obs_time.wn, greater.header.obs_time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.ssr_sol_id, greater.header.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_flag_tropo_grid_points_t lesser = info.test_msg; + sbp_msg_ssr_flag_tropo_grid_points_t greater = info.test_msg; + make_lesser_greater(lesser.n_faulty_points, greater.n_faulty_points); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrFlagTropoGridPoints); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_FLAG_TROPO_GRID_POINTS"); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_flag_tropo_grid_points_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_flag_tropo_grid_points_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_flag_tropo_grid_points, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_flag_tropo_grid_points, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[21]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 21); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 21), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_flag_tropo_grid_points_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 21); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrFlagTropoGridPoints, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_integrity_MsgSsrFlagTropoGridPoints0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrFlagTropoGridPoints, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_integrity_integrity_structs.cc b/c/test/cpp/auto_check_sbp_integrity_integrity_structs.cc new file mode 100644 index 0000000000..b528b4543d --- /dev/null +++ b/c/test/cpp/auto_check_sbp_integrity_integrity_structs.cc @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/integrity/test_integrity_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_integrity_integrity_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_integrity_integrity_structs0() { + assign(test_struct_.chain_id, 200); + assign(test_struct_.num_msgs, 240); + assign(test_struct_.obs_time.tow, 439933335); + assign(test_struct_.obs_time.wn, 37300); + assign(test_struct_.seq_num, 13); + assign(test_struct_.ssr_sol_id, 93); + assign(test_struct_.tile_id, 20278); + assign(test_struct_.tile_set_id, 24876); + } + + struct TestStructInfo { + sbp_integrity_ssr_header_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_integrity_ssr_header_t test_struct_{}; + uint8_t encoded_data_[14] = { + 151, 217, 56, 26, 180, 145, 240, 13, 93, 44, 97, 54, 79, 200, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_integrity_ssr_header_encoded_len(&info.test_struct), 14); +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[14]; + EXPECT_EQ(sbp_integrity_ssr_header_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + EXPECT_EQ(sbp_integrity_ssr_header_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 14), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ( + sbp_integrity_ssr_header_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_integrity_ssr_header_t t{}; + EXPECT_EQ(sbp_integrity_ssr_header_decode(info.encoded_data, 14, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_integrity_ssr_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_integrity_ssr_header_t t{}; + EXPECT_EQ(sbp_integrity_ssr_header_decode(info.encoded_data, 14, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_integrity_ssr_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_integrity_integrity_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_integrity_ssr_header_t t{}; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ( + sbp_integrity_ssr_header_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc new file mode 100644 index 0000000000..c6d7aa3dc2 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc @@ -0,0 +1,985 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxCpuState0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxCpuState0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_cmdline_encoded_len(&test_msg_), 46); + assign(test_msg_.flags, 20); + assign(test_msg_.index, 101); + assign(test_msg_.pcpu, 98); + assign(test_msg_.pid, 50042); + assign(test_msg_.time, 3948815319); + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg_.tname, assign_string, sizeof(assign_string)); + } + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_cpu_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_cpu_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxCpuState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_cpu_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxCpuState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_cpu_state, + sizeof(msg->linux_cpu_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_cpu_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_cpu_state, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxCpuState); + info.sender_id = 34196; + info.preamble = 0x55; + info.crc = 0xe544; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 70; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_cpu_state_t &lesser, + const sbp_msg_linux_cpu_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_linux_cpu_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_cpu_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_cpu_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_cpu_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgLinuxCpuState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxCpuState, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgLinuxCpuState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgLinuxCpuState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_cpu_state_t test_msg_{}; + uint8_t encoded_frame_[70 + 8] = { + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, + 235, 20, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, 229, + }; + uint8_t encoded_payload_[70] = { + 101, 122, 195, 98, 215, 35, 94, 235, 20, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, + 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, + 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_cpu_state_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxCpuState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_cpu_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxCpuState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + EXPECT_EQ(sbp_msg_linux_cpu_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + for (uint8_t i = 0; i < 70; i++) { + EXPECT_EQ( + sbp_msg_linux_cpu_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_cpu_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxCpuState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_t msg{}; + + EXPECT_EQ(sbp_msg_linux_cpu_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_CPU_STATE_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_cpu_state_t t{}; return + // sbp_msg_linux_cpu_state_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_cpu_state_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_cpu_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxCpuState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxCpuState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxCpuState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.pcpu, greater.pcpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_t greater = info.test_msg; + make_lesser_greater(lesser.tname, greater.tname); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxCpuState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_CPU_STATE"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_cpu_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_cpu_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.linux_cpu_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_cpu_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxCpuState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxCpuState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxCpuState0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, StringInit) { + sbp_msg_linux_cpu_state_t t{}; + sbp_msg_linux_cpu_state_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, IsValid) { + sbp_msg_linux_cpu_state_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, SpaceRemaining) { + sbp_msg_linux_cpu_state_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_cpu_state_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_cpu_state_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_cpu_state_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_linux_cpu_state_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_cpu_state_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, Set) { + sbp_msg_linux_cpu_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, Printf) { + sbp_msg_linux_cpu_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE( + sbp_msg_linux_cpu_state_cmdline_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, Vprintf) { + sbp_msg_linux_cpu_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_cpu_state_cmdline_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, AppendPrintf) { + sbp_msg_linux_cpu_state_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuState0_cmdline, AppendVprintf) { + sbp_msg_linux_cpu_state_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_cmdline_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_cpu_state_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_cpu_state_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc new file mode 100644 index 0000000000..024e9fc6fd --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc @@ -0,0 +1,978 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len(&test_msg_), + 46); + assign(test_msg_.index, 51); + assign(test_msg_.pcpu, 178); + assign(test_msg_.pid, 64240); + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg_.tname, assign_string, sizeof(assign_string)); + } + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_cpu_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_cpu_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxCpuStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_cpu_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxCpuStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_cpu_state_dep_a, + sizeof(msg->linux_cpu_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_cpu_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_cpu_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxCpuStateDepA); + info.sender_id = 23308; + info.preamble = 0x55; + info.crc = 0x3050; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 65; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_cpu_state_dep_a_t &lesser, + const sbp_msg_linux_cpu_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_cpu_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_cpu_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxCpuStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxCpuStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxCpuStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxCpuStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_cpu_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[65 + 8] = { + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 80, 48, + }; + uint8_t encoded_payload_[65] = { + 51, 240, 250, 178, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, + 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxCpuStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxCpuStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + + for (uint8_t i = 0; i < 65; i++) { + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxCpuStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_CPU_STATE_DEP_A_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_cpu_state_dep_a_t t{}; + // return sbp_msg_linux_cpu_state_dep_a_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxCpuStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxCpuStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxCpuStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_cpu_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pcpu, greater.pcpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_cpu_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_cpu_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tname, greater.tname); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxCpuStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_CPU_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_cpu_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_cpu_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_cpu_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_cpu_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxCpuStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxCpuStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, StringInit) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + sbp_msg_linux_cpu_state_dep_a_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, IsValid) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, SpaceRemaining) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_cpu_state_dep_a_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_cpu_state_dep_a_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_cpu_state_dep_a_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_cpu_state_dep_a_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_cpu_state_dep_a_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, Set) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE( + sbp_msg_linux_cpu_state_dep_a_cmdline_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, Printf) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, Vprintf) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_cpu_state_dep_a_cmdline_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, AppendPrintf) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxCpuStateDepA0_cmdline, AppendVprintf) { + sbp_msg_linux_cpu_state_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_cpu_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_cpu_state_dep_a_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_cpu_state_dep_a_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc new file mode 100644 index 0000000000..d878bc4447 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc @@ -0,0 +1,985 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxMemState0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxMemState0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_cmdline_encoded_len(&test_msg_), 46); + assign(test_msg_.flags, 76); + assign(test_msg_.index, 154); + assign(test_msg_.pid, 57279); + assign(test_msg_.pmem, 19); + assign(test_msg_.time, 3139057143); + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg_.tname, assign_string, sizeof(assign_string)); + } + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_mem_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_mem_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxMemState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_mem_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxMemState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_mem_state, + sizeof(msg->linux_mem_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_mem_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_mem_state, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxMemState); + info.sender_id = 64863; + info.preamble = 0x55; + info.crc = 0xb503; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 70; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_mem_state_t &lesser, + const sbp_msg_linux_mem_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_linux_mem_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_mem_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_mem_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_mem_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgLinuxMemState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxMemState, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgLinuxMemState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgLinuxMemState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_mem_state_t test_msg_{}; + uint8_t encoded_frame_[70 + 8] = { + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, + 187, 76, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + }; + uint8_t encoded_payload_[70] = { + 154, 191, 223, 19, 247, 53, 26, 187, 76, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, + 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, + 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_mem_state_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxMemState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_mem_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxMemState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + EXPECT_EQ(sbp_msg_linux_mem_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + for (uint8_t i = 0; i < 70; i++) { + EXPECT_EQ( + sbp_msg_linux_mem_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_mem_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxMemState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_t msg{}; + + EXPECT_EQ(sbp_msg_linux_mem_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_MEM_STATE_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_mem_state_t t{}; return + // sbp_msg_linux_mem_state_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_mem_state_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_mem_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxMemState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxMemState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxMemState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.pmem, greater.pmem); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_t lesser = info.test_msg; + sbp_msg_linux_mem_state_t greater = info.test_msg; + make_lesser_greater(lesser.tname, greater.tname); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxMemState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_MEM_STATE"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_mem_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_mem_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.linux_mem_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_mem_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxMemState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxMemState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxMemState0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, StringInit) { + sbp_msg_linux_mem_state_t t{}; + sbp_msg_linux_mem_state_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, IsValid) { + sbp_msg_linux_mem_state_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, SpaceRemaining) { + sbp_msg_linux_mem_state_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_mem_state_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_mem_state_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_mem_state_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_linux_mem_state_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_mem_state_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, Set) { + sbp_msg_linux_mem_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, Printf) { + sbp_msg_linux_mem_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE( + sbp_msg_linux_mem_state_cmdline_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, Vprintf) { + sbp_msg_linux_mem_state_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_mem_state_cmdline_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, AppendPrintf) { + sbp_msg_linux_mem_state_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemState0_cmdline, AppendVprintf) { + sbp_msg_linux_mem_state_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_mem_state_cmdline_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_mem_state_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_mem_state_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc new file mode 100644 index 0000000000..0a412bb468 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc @@ -0,0 +1,978 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxMemStateDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxMemStateDepA0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len(&test_msg_), + 46); + assign(test_msg_.index, 247); + assign(test_msg_.pid, 12381); + assign(test_msg_.pmem, 193); + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg_.tname, assign_string, sizeof(assign_string)); + } + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_mem_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_mem_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxMemStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_mem_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxMemStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_mem_state_dep_a, + sizeof(msg->linux_mem_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_mem_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_mem_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxMemStateDepA); + info.sender_id = 28089; + info.preamble = 0x55; + info.crc = 0x8911; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 65; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_mem_state_dep_a_t &lesser, + const sbp_msg_linux_mem_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_mem_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_mem_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxMemStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxMemStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxMemStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxMemStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_mem_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[65 + 8] = { + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 17, 137, + }; + uint8_t encoded_payload_[65] = { + 247, 93, 48, 193, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, + 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxMemStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxMemStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + + for (uint8_t i = 0; i < 65; i++) { + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxMemStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_MEM_STATE_DEP_A_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_mem_state_dep_a_t t{}; + // return sbp_msg_linux_mem_state_dep_a_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxMemStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxMemStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxMemStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_mem_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_mem_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_mem_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_mem_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_mem_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pmem, greater.pmem); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_mem_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_mem_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tname, greater.tname); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxMemStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_MEM_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_mem_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_mem_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_mem_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_mem_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[65]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 65); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 65), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 65); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxMemStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxMemStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxMemStateDepA0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, StringInit) { + sbp_msg_linux_mem_state_dep_a_t t{}; + sbp_msg_linux_mem_state_dep_a_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, IsValid) { + sbp_msg_linux_mem_state_dep_a_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, SpaceRemaining) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_mem_state_dep_a_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_mem_state_dep_a_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_mem_state_dep_a_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_mem_state_dep_a_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_mem_state_dep_a_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, Set) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE( + sbp_msg_linux_mem_state_dep_a_cmdline_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, Printf) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, Vprintf) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_mem_state_dep_a_cmdline_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, AppendPrintf) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxMemStateDepA0_cmdline, AppendVprintf) { + sbp_msg_linux_mem_state_dep_a_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_mem_state_dep_a_cmdline_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_mem_state_dep_a_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_mem_state_dep_a_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc new file mode 100644 index 0000000000..d4fd2f4d33 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc @@ -0,0 +1,975 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxProcessFdCount0 + : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxProcessFdCount0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmdline_encoded_len(&test_msg_), + 46); + assign(test_msg_.fd_count, 35589); + assign(test_msg_.index, 164); + assign(test_msg_.pid, 42429); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_fd_count_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_process_fd_count_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxProcessFdCount, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_fd_count_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxProcessFdCount); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_process_fd_count, + sizeof(msg->linux_process_fd_count)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_process_fd_count_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_process_fd_count, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxProcessFdCount); + info.sender_id = 49950; + info.preamble = 0x55; + info.crc = 0x5e02; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 51; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_process_fd_count_t &lesser, + const sbp_msg_linux_process_fd_count_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_process_fd_count_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_process_fd_count_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessFdCount, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessFdCount, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxProcessFdCount, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxProcessFdCount, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_process_fd_count_t test_msg_{}; + uint8_t encoded_frame_[51 + 8] = { + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, 112, 97, 116, + 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, + 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, + 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 94, + }; + uint8_t encoded_payload_[51] = { + 164, 189, 165, 5, 139, 47, 112, 97, 116, 104, 47, 116, 111, + 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, + 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, + 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_process_fd_count_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgLinuxProcessFdCount, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[51]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_process_fd_count_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 51); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 51), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxProcessFdCount, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 51); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 51), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[51]; + + EXPECT_EQ(sbp_msg_linux_process_fd_count_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 51), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[51]; + + for (uint8_t i = 0; i < 51; i++) { + EXPECT_EQ(sbp_msg_linux_process_fd_count_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_count_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_process_fd_count_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 51); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgLinuxProcessFdCount, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 51); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_count_t msg{}; + + EXPECT_EQ(sbp_msg_linux_process_fd_count_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_count_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_PROCESS_FD_COUNT_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_process_fd_count_t t{}; + // return sbp_msg_linux_process_fd_count_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_process_fd_count_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_process_fd_count_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxProcessFdCount, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgLinuxProcessFdCount, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxProcessFdCount, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_process_fd_count_t lesser = info.test_msg; + sbp_msg_linux_process_fd_count_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_fd_count_t lesser = info.test_msg; + sbp_msg_linux_process_fd_count_t greater = info.test_msg; + make_lesser_greater(lesser.fd_count, greater.fd_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_fd_count_t lesser = info.test_msg; + sbp_msg_linux_process_fd_count_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_fd_count_t lesser = info.test_msg; + sbp_msg_linux_process_fd_count_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxProcessFdCount); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_PROCESS_FD_COUNT"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_process_fd_count_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_linux_process_fd_count_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_process_fd_count, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.linux_process_fd_count, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[51]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 51); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 51), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_count_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 51); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxProcessFdCount, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxProcessFdCount, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxProcessFdCount0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, StringInit) { + sbp_msg_linux_process_fd_count_t t{}; + sbp_msg_linux_process_fd_count_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, IsValid) { + sbp_msg_linux_process_fd_count_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, + SpaceRemaining) { + sbp_msg_linux_process_fd_count_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_process_fd_count_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_process_fd_count_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_count_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_process_fd_count_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_linux_process_fd_count_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_process_fd_count_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, Set) { + sbp_msg_linux_process_fd_count_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE( + sbp_msg_linux_process_fd_count_cmdline_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, Printf) { + sbp_msg_linux_process_fd_count_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, Vprintf) { + sbp_msg_linux_process_fd_count_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_fd_count_cmdline_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, AppendPrintf) { + sbp_msg_linux_process_fd_count_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdCount0_cmdline, + AppendVprintf) { + sbp_msg_linux_process_fd_count_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_fd_count_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_fd_count_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_fd_count_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc new file mode 100644 index 0000000000..6ffd209593 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc @@ -0,0 +1,1143 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0 + : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0() { + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd1")); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd2")); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd3")); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd4")); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd5")); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section( + &test_msg_, "fd6")); + EXPECT_EQ( + sbp_msg_linux_process_fd_summary_most_opened_encoded_len(&test_msg_), + 25); + assign(test_msg_.sys_fd_count, 1304986387); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_linux_process_fd_summary_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_fd_summary_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_linux_process_fd_summary_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxProcessFdSummary, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_fd_summary_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxProcessFdSummary); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_process_fd_summary, + sizeof(msg->linux_process_fd_summary)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_process_fd_summary_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_process_fd_summary, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxProcessFdSummary); + info.sender_id = 63591; + info.preamble = 0x55; + info.crc = 0x5081; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 29; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_process_fd_summary_t &lesser, + const sbp_msg_linux_process_fd_summary_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_process_fd_summary_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_process_fd_summary_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_process_fd_summary_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessFdSummary, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessFdSummary, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxProcessFdSummary, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxProcessFdSummary, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_process_fd_summary_t test_msg_{}; + uint8_t encoded_frame_[29 + 8] = { + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, + 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, + 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + }; + uint8_t encoded_payload_[29] = { + 19, 131, 200, 77, 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, + 0, 102, 100, 52, 0, 102, 100, 53, 0, 102, 100, 54, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_process_fd_summary_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgLinuxProcessFdSummary, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxProcessFdSummary, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + for (uint8_t i = 0; i < 29; i++) { + EXPECT_EQ(sbp_msg_linux_process_fd_summary_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_summary_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgLinuxProcessFdSummary, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_summary_t msg{}; + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_summary_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_PROCESS_FD_SUMMARY_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_process_fd_summary_t t{}; + // return sbp_msg_linux_process_fd_summary_encoded_len(&t); }(); + overhead += 25; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessFdSummary, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgLinuxProcessFdSummary, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessFdSummary, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_process_fd_summary_t lesser = info.test_msg; + sbp_msg_linux_process_fd_summary_t greater = info.test_msg; + make_lesser_greater(lesser.most_opened, greater.most_opened); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_fd_summary_t lesser = info.test_msg; + sbp_msg_linux_process_fd_summary_t greater = info.test_msg; + make_lesser_greater(lesser.sys_fd_count, greater.sys_fd_count); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxProcessFdSummary); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_PROCESS_FD_SUMMARY"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_process_fd_summary_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_linux_process_fd_summary_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_process_fd_summary, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.linux_process_fd_summary, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_fd_summary_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxProcessFdSummary, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxProcessFdSummary, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened + : public Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + StringInit) { + sbp_msg_linux_process_fd_summary_t t{}; + sbp_msg_linux_process_fd_summary_most_opened_init(&t); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + IsValid) { + sbp_msg_linux_process_fd_summary_t t{}; + + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd1")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd2")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd3")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd4")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd5")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd6")); + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_encoded_len(&t), 25); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + SpaceRemaining) { + sbp_msg_linux_process_fd_summary_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_process_fd_summary_most_opened_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd1")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd2")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd3")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd4")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd5")); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_add_section(&t, "fd6")); + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_encoded_len(&t), 25); + size_t assigned_space_remaining = + sbp_msg_linux_process_fd_summary_most_opened_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_count_sections( + &info.test_msg), + 6); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + AddSectionPrintf) { + sbp_msg_linux_process_fd_summary_t t{}; + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd1")); + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd2")); + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd3")); + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd4")); + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd5")); + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_add_section_printf( + &t, "%s", "fd6")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_count_sections(&t), 6); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + "fd1"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 1), + "fd2"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 2), + "fd3"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 3), + "fd4"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 4), + "fd5"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 5), + "fd6"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + AddSectionVprintf) { + sbp_msg_linux_process_fd_summary_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd1")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd2")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd3")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd4")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd5")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_linux_process_fd_summary_most_opened_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "fd6")); + } + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_count_sections(&t), 6); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + "fd1"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 1), + "fd2"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 2), + "fd3"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 3), + "fd4"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 4), + "fd5"); + + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 5), + "fd6"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, Append) { + sbp_msg_linux_process_fd_summary_t t{}; + + char part1[] = "fd1"; + char part2[] = "fd1"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_append(&t, part1)); + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_linux_process_fd_summary_most_opened_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + "fd1"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + AppendPrintf) { + sbp_msg_linux_process_fd_summary_t t{}; + + char part1[] = "fd1"; + char part2[] = "fd1"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_linux_process_fd_summary_most_opened_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + "fd1"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + AppendVprintf) { + sbp_msg_linux_process_fd_summary_t t{}; + + char part1[] = "fd1"; + char part2[] = "fd1"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_fd_summary_most_opened_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_fd_summary_most_opened_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_linux_process_fd_summary_most_opened_get_section(&t, 0), + "fd1"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessFdSummary0_most_opened, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 0), + strlen("fd1")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 1), + strlen("fd2")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 2), + strlen("fd3")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 3), + strlen("fd4")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 4), + strlen("fd5")); + + EXPECT_EQ(sbp_msg_linux_process_fd_summary_most_opened_section_strlen( + &info.test_msg, 5), + strlen("fd6")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc new file mode 100644 index 0000000000..14cd828f86 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc @@ -0,0 +1,1007 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0 + : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0() { + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ( + sbp_msg_linux_process_socket_counts_cmdline_encoded_len(&test_msg_), + 46); + assign(test_msg_.index, 51); + assign(test_msg_.pid, 28553); + assign(test_msg_.socket_count, 30287); + assign(test_msg_.socket_states, 29554); + assign(test_msg_.socket_types, 35843); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_linux_process_socket_counts_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_socket_counts_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_linux_process_socket_counts_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxProcessSocketCounts, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_socket_counts_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxProcessSocketCounts); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_process_socket_counts, + sizeof(msg->linux_process_socket_counts)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_process_socket_counts_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_process_socket_counts, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxProcessSocketCounts); + info.sender_id = 2412; + info.preamble = 0x55; + info.crc = 0x83b4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_process_socket_counts_t &lesser, + const sbp_msg_linux_process_socket_counts_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_process_socket_counts_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_process_socket_counts_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_process_socket_counts_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessSocketCounts, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessSocketCounts, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxProcessSocketCounts, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxProcessSocketCounts, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_process_socket_counts_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, + 114, 115, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, + 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 180, 131, + }; + uint8_t encoded_payload_[55] = { + 51, 137, 111, 79, 118, 3, 140, 114, 115, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, + 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_process_socket_counts_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgLinuxProcessSocketCounts, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxProcessSocketCounts, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_linux_process_socket_counts_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_counts_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgLinuxProcessSocketCounts, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_counts_t msg{}; + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_counts_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_PROCESS_SOCKET_COUNTS_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_process_socket_counts_t t{}; + // return sbp_msg_linux_process_socket_counts_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_process_socket_counts_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessSocketCounts, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgLinuxProcessSocketCounts, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessSocketCounts, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.socket_count, greater.socket_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.socket_states, greater.socket_states); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_counts_t lesser = info.test_msg; + sbp_msg_linux_process_socket_counts_t greater = info.test_msg; + make_lesser_greater(lesser.socket_types, greater.socket_types); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxProcessSocketCounts); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_PROCESS_SOCKET_COUNTS"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_process_socket_counts_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_linux_process_socket_counts_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_process_socket_counts, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.linux_process_socket_counts, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_counts_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxProcessSocketCounts, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxProcessSocketCounts, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, + StringInit) { + sbp_msg_linux_process_socket_counts_t t{}; + sbp_msg_linux_process_socket_counts_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, IsValid) { + sbp_msg_linux_process_socket_counts_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_socket_counts_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, + SpaceRemaining) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_process_socket_counts_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_socket_counts_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_process_socket_counts_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_counts_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_process_socket_counts_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ( + sbp_msg_linux_process_socket_counts_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_process_socket_counts_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, Set) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_set(&t, text, false, + &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, Printf) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, Vprintf) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_socket_counts_cmdline_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, + AppendPrintf) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketCounts0_cmdline, + AppendVprintf) { + sbp_msg_linux_process_socket_counts_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_socket_counts_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_socket_counts_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_socket_counts_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc new file mode 100644 index 0000000000..d6c020b7c9 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc @@ -0,0 +1,1046 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0 + : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0() { + { + const char assign_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.address_of_largest, assign_string, + sizeof(assign_string)); + } + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_set( + &test_msg_, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, + &written)); + EXPECT_EQ(written, + strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ( + sbp_msg_linux_process_socket_queues_cmdline_encoded_len(&test_msg_), + 46); + assign(test_msg_.index, 181); + assign(test_msg_.pid, 19335); + assign(test_msg_.recv_queued, 54265); + assign(test_msg_.send_queued, 64547); + assign(test_msg_.socket_states, 57103); + assign(test_msg_.socket_types, 27984); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_linux_process_socket_queues_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_socket_queues_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_linux_process_socket_queues_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxProcessSocketQueues, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_process_socket_queues_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxProcessSocketQueues); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_process_socket_queues, + sizeof(msg->linux_process_socket_queues)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_process_socket_queues_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_process_socket_queues, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxProcessSocketQueues); + info.sender_id = 59579; + info.preamble = 0x55; + info.crc = 0xf702; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 121; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_process_socket_queues_t &lesser, + const sbp_msg_linux_process_socket_queues_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_process_socket_queues_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_process_socket_queues_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_process_socket_queues_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessSocketQueues, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxProcessSocketQueues, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxProcessSocketQueues, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxProcessSocketQueues, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_process_socket_queues_t test_msg_{}; + uint8_t encoded_frame_[121 + 8] = { + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, 80, 109, + 15, 223, 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, + 114, 103, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, + 103, 51, 32, 97, 114, 103, 52, 2, 247, + }; + uint8_t encoded_payload_[121] = { + 181, 135, 75, 249, 211, 35, 252, 80, 109, 15, 223, 97, 100, 100, + 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, 115, + 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, + 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_process_socket_queues_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgLinuxProcessSocketQueues, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[121]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 121); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 121), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxProcessSocketQueues, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 121); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 121), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[121]; + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 121), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[121]; + + for (uint8_t i = 0; i < 121; i++) { + EXPECT_EQ(sbp_msg_linux_process_socket_queues_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_queues_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 121); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgLinuxProcessSocketQueues, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 121); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_queues_t msg{}; + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_queues_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LINUX_PROCESS_SOCKET_QUEUES_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_linux_process_socket_queues_t t{}; + // return sbp_msg_linux_process_socket_queues_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_process_socket_queues_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessSocketQueues, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgLinuxProcessSocketQueues, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgLinuxProcessSocketQueues, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.address_of_largest, greater.address_of_largest); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.cmdline, greater.cmdline); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.pid, greater.pid); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.recv_queued, greater.recv_queued); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.send_queued, greater.send_queued); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.socket_states, greater.socket_states); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_process_socket_queues_t lesser = info.test_msg; + sbp_msg_linux_process_socket_queues_t greater = info.test_msg; + make_lesser_greater(lesser.socket_types, greater.socket_types); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxProcessSocketQueues); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_PROCESS_SOCKET_QUEUES"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_process_socket_queues_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_linux_process_socket_queues_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_process_socket_queues, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.linux_process_socket_queues, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[121]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 121); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 121), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_queues_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 121); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxProcessSocketQueues, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxProcessSocketQueues, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline + : public Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0 {}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, + StringInit) { + sbp_msg_linux_process_socket_queues_t t{}; + sbp_msg_linux_process_socket_queues_cmdline_init(&t); + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, IsValid) { + sbp_msg_linux_process_socket_queues_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_socket_queues_cmdline_encoded_len(&t), 46); + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_valid(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, + SpaceRemaining) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t empty_space_remaining = + sbp_msg_linux_process_socket_queues_cmdline_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_set( + &t, "/path/to/process-name arg0 arg1 arg2 arg3 arg4", false, &written)); + EXPECT_EQ(written, strlen("/path/to/process-name arg0 arg1 arg2 arg3 arg4")); + EXPECT_EQ(sbp_msg_linux_process_socket_queues_cmdline_encoded_len(&t), 46); + size_t assigned_space_remaining = + sbp_msg_linux_process_socket_queues_cmdline_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_linux_process_socket_queues_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_set_raw( + &t, info.test_msg.cmdline.data, + sbp_msg_linux_process_socket_queues_cmdline_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ( + sbp_msg_linux_process_socket_queues_cmdline_encoded_len(&info.test_msg), + sbp_msg_linux_process_socket_queues_cmdline_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, Set) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_set(&t, text, false, + &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, Printf) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, Vprintf) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t nwritten{}; + const char *text = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_socket_queues_cmdline_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), text); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, + AppendPrintf) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxProcessSocketQueues0_cmdline, + AppendVprintf) { + sbp_msg_linux_process_socket_queues_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + char part2[] = "/path/to/process-name arg0 arg1 arg2 arg3 arg4"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_linux_process_socket_queues_cmdline_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_linux_process_socket_queues_cmdline_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_linux_process_socket_queues_cmdline_get(&t), + "/path/to/process-name arg0 arg1 arg2 arg3 arg4"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc new file mode 100644 index 0000000000..ad480816a9 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc @@ -0,0 +1,1119 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxSocketUsage0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxSocketUsage0() { + assign(test_msg_.avg_queue_depth, 2907030541); + assign(test_msg_.max_queue_depth, 3048922691); + + assign(test_msg_.socket_state_counts[0], 39670); + + assign(test_msg_.socket_state_counts[1], 4603); + + assign(test_msg_.socket_state_counts[2], 46048); + + assign(test_msg_.socket_state_counts[3], 43290); + + assign(test_msg_.socket_state_counts[4], 23217); + + assign(test_msg_.socket_state_counts[5], 54677); + + assign(test_msg_.socket_state_counts[6], 1750); + + assign(test_msg_.socket_state_counts[7], 16510); + + assign(test_msg_.socket_state_counts[8], 47480); + + assign(test_msg_.socket_state_counts[9], 33620); + + assign(test_msg_.socket_state_counts[10], 28616); + + assign(test_msg_.socket_state_counts[11], 36128); + + assign(test_msg_.socket_state_counts[12], 53721); + + assign(test_msg_.socket_state_counts[13], 3636); + + assign(test_msg_.socket_state_counts[14], 37822); + + assign(test_msg_.socket_state_counts[15], 63135); + + assign(test_msg_.socket_type_counts[0], 31373); + + assign(test_msg_.socket_type_counts[1], 30676); + + assign(test_msg_.socket_type_counts[2], 7811); + + assign(test_msg_.socket_type_counts[3], 12152); + + assign(test_msg_.socket_type_counts[4], 27929); + + assign(test_msg_.socket_type_counts[5], 16794); + + assign(test_msg_.socket_type_counts[6], 42116); + + assign(test_msg_.socket_type_counts[7], 7719); + + assign(test_msg_.socket_type_counts[8], 44830); + + assign(test_msg_.socket_type_counts[9], 11272); + + assign(test_msg_.socket_type_counts[10], 28444); + + assign(test_msg_.socket_type_counts[11], 61676); + + assign(test_msg_.socket_type_counts[12], 19120); + + assign(test_msg_.socket_type_counts[13], 33183); + + assign(test_msg_.socket_type_counts[14], 39322); + + assign(test_msg_.socket_type_counts[15], 58786); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_socket_usage_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_socket_usage_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxSocketUsage, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_socket_usage_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxSocketUsage); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_socket_usage, + sizeof(msg->linux_socket_usage)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_socket_usage_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_socket_usage, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxSocketUsage); + info.sender_id = 35442; + info.preamble = 0x55; + info.crc = 0x9a82; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 72; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_socket_usage_t &lesser, + const sbp_msg_linux_socket_usage_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_linux_socket_usage_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_socket_usage_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_socket_usage_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_socket_usage_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxSocketUsage, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxSocketUsage, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxSocketUsage, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxSocketUsage, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_socket_usage_t test_msg_{}; + uint8_t encoded_frame_[72 + 8] = { + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, + 246, 154, 251, 17, 224, 179, 26, 169, 177, 90, 149, 213, 214, 6, + 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, 217, 209, 52, 14, + 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, + 176, 74, 159, 129, 154, 153, 162, 229, 130, 154, + }; + uint8_t encoded_payload_[72] = { + 13, 196, 69, 173, 67, 222, 186, 181, 246, 154, 251, 17, 224, 179, 26, + 169, 177, 90, 149, 213, 214, 6, 126, 64, 120, 185, 84, 131, 200, 111, + 32, 141, 217, 209, 52, 14, 190, 147, 159, 246, 141, 122, 212, 119, 131, + 30, 120, 47, 25, 109, 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, + 28, 111, 236, 240, 176, 74, 159, 129, 154, 153, 162, 229, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_socket_usage_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxSocketUsage, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_socket_usage_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxSocketUsage, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + EXPECT_EQ(sbp_msg_linux_socket_usage_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + for (uint8_t i = 0; i < 72; i++) { + EXPECT_EQ( + sbp_msg_linux_socket_usage_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_socket_usage_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_socket_usage_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxSocketUsage, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_socket_usage_t msg{}; + + EXPECT_EQ(sbp_msg_linux_socket_usage_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_socket_usage_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_linux_socket_usage_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_socket_usage_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSocketUsage, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxSocketUsage, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSocketUsage, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.avg_queue_depth, greater.avg_queue_depth); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.max_queue_depth, greater.max_queue_depth); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[0], + greater.socket_state_counts[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[1], + greater.socket_state_counts[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[2], + greater.socket_state_counts[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[3], + greater.socket_state_counts[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[4], + greater.socket_state_counts[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[5], + greater.socket_state_counts[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[6], + greater.socket_state_counts[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[7], + greater.socket_state_counts[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[8], + greater.socket_state_counts[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[9], + greater.socket_state_counts[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[10], + greater.socket_state_counts[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[11], + greater.socket_state_counts[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[12], + greater.socket_state_counts[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[13], + greater.socket_state_counts[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[14], + greater.socket_state_counts[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_state_counts[15], + greater.socket_state_counts[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[0], + greater.socket_type_counts[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[1], + greater.socket_type_counts[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[2], + greater.socket_type_counts[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[3], + greater.socket_type_counts[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[4], + greater.socket_type_counts[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[5], + greater.socket_type_counts[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[6], + greater.socket_type_counts[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[7], + greater.socket_type_counts[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[8], + greater.socket_type_counts[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[9], + greater.socket_type_counts[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[10], + greater.socket_type_counts[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[11], + greater.socket_type_counts[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[12], + greater.socket_type_counts[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[13], + greater.socket_type_counts[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[14], + greater.socket_type_counts[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_linux_socket_usage_t lesser = info.test_msg; + sbp_msg_linux_socket_usage_t greater = info.test_msg; + make_lesser_greater(lesser.socket_type_counts[15], + greater.socket_type_counts[15]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxSocketUsage); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_SOCKET_USAGE"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_socket_usage_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_socket_usage_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_socket_usage, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_socket_usage, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_socket_usage_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxSocketUsage, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSocketUsage0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxSocketUsage, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc new file mode 100644 index 0000000000..0798ad0b4c --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc @@ -0,0 +1,829 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxSysState0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxSysState0() { + assign(test_msg_.flags, 9); + assign(test_msg_.mem_total, 53012); + assign(test_msg_.pcpu, 125); + assign(test_msg_.pid_count, 47866); + assign(test_msg_.pmem, 215); + assign(test_msg_.procs_starting, 18372); + assign(test_msg_.procs_stopping, 58785); + assign(test_msg_.time, 90840684); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_sys_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_sys_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxSysState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_sys_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxSysState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_sys_state, + sizeof(msg->linux_sys_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_sys_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_sys_state, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxSysState); + info.sender_id = 42837; + info.preamble = 0x55; + info.crc = 0xf2e5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_sys_state_t &lesser, + const sbp_msg_linux_sys_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_linux_sys_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_sys_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_sys_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_sys_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgLinuxSysState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxSysState, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgLinuxSysState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgLinuxSysState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_sys_state_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, + 161, 229, 250, 186, 108, 30, 106, 5, 9, 229, 242, + }; + uint8_t encoded_payload_[15] = { + 20, 207, 125, 215, 196, 71, 161, 229, 250, 186, 108, 30, 106, 5, 9, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_sys_state_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxSysState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_sys_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxSysState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ(sbp_msg_linux_sys_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ( + sbp_msg_linux_sys_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_sys_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxSysState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_t msg{}; + + EXPECT_EQ(sbp_msg_linux_sys_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_linux_sys_state_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_sys_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSysState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxSysState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSysState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.mem_total, greater.mem_total); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.pcpu, greater.pcpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.pid_count, greater.pid_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.pmem, greater.pmem); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.procs_starting, greater.procs_starting); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.procs_stopping, greater.procs_stopping); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_t lesser = info.test_msg; + sbp_msg_linux_sys_state_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxSysState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_SYS_STATE"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_sys_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_sys_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.linux_sys_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_sys_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxSysState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxSysState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc new file mode 100644 index 0000000000..d5dc95f981 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc @@ -0,0 +1,821 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_linux_MsgLinuxSysStateDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_linux_MsgLinuxSysStateDepA0() { + assign(test_msg_.mem_total, 41916); + assign(test_msg_.pcpu, 211); + assign(test_msg_.pid_count, 51580); + assign(test_msg_.pmem, 194); + assign(test_msg_.procs_starting, 18291); + assign(test_msg_.procs_stopping, 26469); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_sys_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_linux_sys_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLinuxSysStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_linux_sys_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLinuxSysStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->linux_sys_state_dep_a, + sizeof(msg->linux_sys_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_linux_sys_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.linux_sys_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLinuxSysStateDepA); + info.sender_id = 14420; + info.preamble = 0x55; + info.crc = 0xdfdf; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_linux_sys_state_dep_a_t &lesser, + const sbp_msg_linux_sys_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_linux_sys_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_linux_sys_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxSysStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLinuxSysStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLinuxSysStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLinuxSysStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_linux_sys_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 2, 127, 84, 56, 10, 188, 163, 211, + 194, 115, 71, 101, 103, 124, 201, 223, 223, + }; + uint8_t encoded_payload_[10] = { + 188, 163, 211, 194, 115, 71, 101, 103, 124, 201, + }; +}; + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgLinuxSysStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgLinuxSysStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLinuxSysStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_linux_sys_state_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSysStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLinuxSysStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLinuxSysStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.mem_total, greater.mem_total); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pcpu, greater.pcpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pid_count, greater.pid_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pmem, greater.pmem); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.procs_starting, greater.procs_starting); + comparison_tests(lesser, greater); + } + { + sbp_msg_linux_sys_state_dep_a_t lesser = info.test_msg; + sbp_msg_linux_sys_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.procs_stopping, greater.procs_stopping); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgLinuxSysStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_LINUX_SYS_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_linux_sys_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_linux_sys_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.linux_sys_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.linux_sys_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_linux_sys_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLinuxSysStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_linux_MsgLinuxSysStateDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgLinuxSysStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_logging_MsgFwd.cc b/c/test/cpp/auto_check_sbp_logging_MsgFwd.cc index 2462b3c112..9b742c4f53 100644 --- a/c/test/cpp/auto_check_sbp_logging_MsgFwd.cc +++ b/c/test/cpp/auto_check_sbp_logging_MsgFwd.cc @@ -16,172 +16,910 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_logging_MsgFwd0 : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_logging_MsgFwd0 : public ::testing::Test { public: - Test_auto_check_sbp_logging_MsgFwd0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_logging_MsgFwd0() { + assign(test_msg_.fwd_payload[0], 86); + + assign(test_msg_.fwd_payload[1], 81); + + assign(test_msg_.fwd_payload[2], 68); + + assign(test_msg_.fwd_payload[3], 47); + + assign(test_msg_.fwd_payload[4], 81); + + assign(test_msg_.fwd_payload[5], 103); + + assign(test_msg_.fwd_payload[6], 65); + + assign(test_msg_.fwd_payload[7], 69); + + assign(test_msg_.fwd_payload[8], 65); + + assign(test_msg_.fwd_payload[9], 65); + + assign(test_msg_.fwd_payload[10], 65); + + assign(test_msg_.fwd_payload[11], 65); + + assign(test_msg_.fwd_payload[12], 65); + + assign(test_msg_.fwd_payload[13], 69); + + assign(test_msg_.fwd_payload[14], 97); + + assign(test_msg_.fwd_payload[15], 103); + assign(test_msg_.n_fwd_payload, 16); + assign(test_msg_.protocol, 0); + assign(test_msg_.source, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_fwd_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, const sbp_msg_fwd_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFwd, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_fwd_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFwd); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->fwd, sizeof(msg->fwd)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_fwd_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.fwd, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFwd); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x5f7d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 18; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_fwd_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_fwd_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_fwd_t &lesser, + const sbp_msg_fwd_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_fwd_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_fwd_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_fwd_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_fwd_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgFwd, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgFwd, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgFwd, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT(sbp_message_cmp(SbpMsgFwd, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); -TEST_F(Test_auto_check_sbp_logging_MsgFwd0, Test) { - uint8_t encoded_frame[] = { + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_fwd_t test_msg_{}; + uint8_t encoded_frame_[18 + 8] = { 85, 2, 4, 66, 0, 18, 0, 0, 86, 81, 68, 47, 81, 103, 65, 69, 65, 65, 65, 65, 65, 69, 97, 103, 125, 95, }; + uint8_t encoded_payload_[18] = { + 0, 0, 86, 81, 68, 47, 81, 103, 65, 69, 65, 65, 65, 65, 65, 69, 97, 103, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_fwd_encoded_len(&info.test_msg), info.payload_len); - sbp_msg_fwd_t test_msg{}; - - test_msg.fwd_payload[0] = 86; - - test_msg.fwd_payload[1] = 81; - - test_msg.fwd_payload[2] = 68; - - test_msg.fwd_payload[3] = 47; - - test_msg.fwd_payload[4] = 81; - - test_msg.fwd_payload[5] = 103; - - test_msg.fwd_payload[6] = 65; - - test_msg.fwd_payload[7] = 69; - - test_msg.fwd_payload[8] = 65; - - test_msg.fwd_payload[9] = 65; - - test_msg.fwd_payload[10] = 65; - - test_msg.fwd_payload[11] = 65; - - test_msg.fwd_payload[12] = 65; - - test_msg.fwd_payload[13] = 69; - - test_msg.fwd_payload[14] = 97; - - test_msg.fwd_payload[15] = 103; - test_msg.n_fwd_payload = 16; - test_msg.protocol = 0; - test_msg.source = 0; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.fwd_payload[0], 86) - << "incorrect value for last_msg_.fwd_payload[0], expected 86, is " - << last_msg_.fwd_payload[0]; - EXPECT_EQ(last_msg_.fwd_payload[1], 81) - << "incorrect value for last_msg_.fwd_payload[1], expected 81, is " - << last_msg_.fwd_payload[1]; - EXPECT_EQ(last_msg_.fwd_payload[2], 68) - << "incorrect value for last_msg_.fwd_payload[2], expected 68, is " - << last_msg_.fwd_payload[2]; - EXPECT_EQ(last_msg_.fwd_payload[3], 47) - << "incorrect value for last_msg_.fwd_payload[3], expected 47, is " - << last_msg_.fwd_payload[3]; - EXPECT_EQ(last_msg_.fwd_payload[4], 81) - << "incorrect value for last_msg_.fwd_payload[4], expected 81, is " - << last_msg_.fwd_payload[4]; - EXPECT_EQ(last_msg_.fwd_payload[5], 103) - << "incorrect value for last_msg_.fwd_payload[5], expected 103, is " - << last_msg_.fwd_payload[5]; - EXPECT_EQ(last_msg_.fwd_payload[6], 65) - << "incorrect value for last_msg_.fwd_payload[6], expected 65, is " - << last_msg_.fwd_payload[6]; - EXPECT_EQ(last_msg_.fwd_payload[7], 69) - << "incorrect value for last_msg_.fwd_payload[7], expected 69, is " - << last_msg_.fwd_payload[7]; - EXPECT_EQ(last_msg_.fwd_payload[8], 65) - << "incorrect value for last_msg_.fwd_payload[8], expected 65, is " - << last_msg_.fwd_payload[8]; - EXPECT_EQ(last_msg_.fwd_payload[9], 65) - << "incorrect value for last_msg_.fwd_payload[9], expected 65, is " - << last_msg_.fwd_payload[9]; - EXPECT_EQ(last_msg_.fwd_payload[10], 65) - << "incorrect value for last_msg_.fwd_payload[10], expected 65, is " - << last_msg_.fwd_payload[10]; - EXPECT_EQ(last_msg_.fwd_payload[11], 65) - << "incorrect value for last_msg_.fwd_payload[11], expected 65, is " - << last_msg_.fwd_payload[11]; - EXPECT_EQ(last_msg_.fwd_payload[12], 65) - << "incorrect value for last_msg_.fwd_payload[12], expected 65, is " - << last_msg_.fwd_payload[12]; - EXPECT_EQ(last_msg_.fwd_payload[13], 69) - << "incorrect value for last_msg_.fwd_payload[13], expected 69, is " - << last_msg_.fwd_payload[13]; - EXPECT_EQ(last_msg_.fwd_payload[14], 97) - << "incorrect value for last_msg_.fwd_payload[14], expected 97, is " - << last_msg_.fwd_payload[14]; - EXPECT_EQ(last_msg_.fwd_payload[15], 103) - << "incorrect value for last_msg_.fwd_payload[15], expected 103, is " - << last_msg_.fwd_payload[15]; - EXPECT_EQ(last_msg_.n_fwd_payload, 16) - << "incorrect value for last_msg_.n_fwd_payload, expected 16, is " - << last_msg_.n_fwd_payload; - EXPECT_EQ(last_msg_.protocol, 0) - << "incorrect value for last_msg_.protocol, expected 0, is " - << last_msg_.protocol; - EXPECT_EQ(last_msg_.source, 0) - << "incorrect value for last_msg_.source, expected 0, is " - << last_msg_.source; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFwd, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_fwd_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgFwd, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + + EXPECT_EQ(sbp_msg_fwd_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgFwd0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + + for (uint8_t i = 0; i < 18; i++) { + EXPECT_EQ(sbp_msg_fwd_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fwd_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_fwd_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFwd, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_fwd_t msg{}; + + EXPECT_EQ(sbp_msg_fwd_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgFwd0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_fwd_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_fwd_t t{}; + return sbp_msg_fwd_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_fwd_t t{}; + t.n_fwd_payload = 1; + return sbp_msg_fwd_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_fwd_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_fwd_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFwd, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFwd, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFwd, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[0], greater.fwd_payload[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[1], greater.fwd_payload[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[2], greater.fwd_payload[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[3], greater.fwd_payload[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[4], greater.fwd_payload[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[5], greater.fwd_payload[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[6], greater.fwd_payload[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[7], greater.fwd_payload[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[8], greater.fwd_payload[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[9], greater.fwd_payload[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[10], greater.fwd_payload[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[11], greater.fwd_payload[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[12], greater.fwd_payload[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[13], greater.fwd_payload[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[14], greater.fwd_payload[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.fwd_payload[15], greater.fwd_payload[15]); + comparison_tests(lesser, greater); + } + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.n_fwd_payload, greater.n_fwd_payload); + comparison_tests(lesser, greater); + } + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.protocol, greater.protocol); + comparison_tests(lesser, greater); + } + { + sbp_msg_fwd_t lesser = info.test_msg; + sbp_msg_fwd_t greater = info.test_msg; + make_lesser_greater(lesser.source, greater.source); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgFwd); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_FWD"); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_fwd_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_fwd_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.fwd, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.fwd, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_fwd_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFwd, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgFwd0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgFwd, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_logging_MsgLog.cc b/c/test/cpp/auto_check_sbp_logging_MsgLog.cc index d9cfb1cc46..029cc2de48 100644 --- a/c/test/cpp/auto_check_sbp_logging_MsgLog.cc +++ b/c/test/cpp/auto_check_sbp_logging_MsgLog.cc @@ -16,97 +16,891 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_logging_MsgLog0 : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_logging_MsgLog0 : public ::testing::Test { public: - Test_auto_check_sbp_logging_MsgLog0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_logging_MsgLog0() { + assign(test_msg_.level, 6); + + size_t written; + EXPECT_TRUE(sbp_msg_log_text_set( + &test_msg_, "Filtered all obs from 2314 at tow 83.539019", false, + &written)); + EXPECT_EQ(written, strlen("Filtered all obs from 2314 at tow 83.539019")); + EXPECT_EQ(sbp_msg_log_text_encoded_len(&test_msg_), 43); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_log_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, const sbp_msg_log_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgLog, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_log_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgLog); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->log, sizeof(msg->log)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_log_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.log, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgLog); + info.sender_id = 2314; + info.preamble = 0x55; + info.crc = 0xa3b1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 44; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_log_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_log_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_log_t &lesser, + const sbp_msg_log_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_log_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_log_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_log_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_log_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgLog, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgLog, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgLog, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT(sbp_message_cmp(SbpMsgLog, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_logging_MsgLog0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_log_t test_msg_{}; + uint8_t encoded_frame_[44 + 8] = { 85, 1, 4, 10, 9, 44, 6, 70, 105, 108, 116, 101, 114, 101, 100, 32, 97, 108, 108, 32, 111, 98, 115, 32, 102, 114, 111, 109, 32, 50, 51, 49, 52, 32, 97, 116, 32, 116, 111, 119, 32, 56, 51, 46, 53, 51, 57, 48, 49, 57, 177, 163, }; + uint8_t encoded_payload_[44] = { + 6, 70, 105, 108, 116, 101, 114, 101, 100, 32, 97, 108, 108, 32, 111, + 98, 115, 32, 102, 114, 111, 109, 32, 50, 51, 49, 52, 32, 97, 116, + 32, 116, 111, 119, 32, 56, 51, 46, 53, 51, 57, 48, 49, 57, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgLog0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_log_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgLog, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[44]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_log_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 44); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 44), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgLog, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 44); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 44), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[44]; + + EXPECT_EQ(sbp_msg_log_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 44), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgLog0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[44]; + + for (uint8_t i = 0; i < 44; i++) { + EXPECT_EQ(sbp_msg_log_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_log_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_log_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 44); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgLog, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 44); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_log_t msg{}; + + EXPECT_EQ(sbp_msg_log_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgLog0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_log_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_LOG_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_log_t t{}; return + // sbp_msg_log_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_log_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_log_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgLog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgLog, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_log_t lesser = info.test_msg; + sbp_msg_log_t greater = info.test_msg; + make_lesser_greater(lesser.level, greater.level); + comparison_tests(lesser, greater); + } + { + sbp_msg_log_t lesser = info.test_msg; + sbp_msg_log_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgLog); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_LOG"); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_log_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_log_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - sbp_msg_log_t test_msg{}; - test_msg.level = 6; + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.log, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.log, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[44]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 44); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 44), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_log_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 44); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgLog, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgLog, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgLog0_text + : public Testauto_check_sbp_logging_MsgLog0 {}; + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, StringInit) { + sbp_msg_log_t t{}; + sbp_msg_log_text_init(&t); + EXPECT_TRUE(sbp_msg_log_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, IsValid) { + sbp_msg_log_t t{}; size_t written; EXPECT_TRUE(sbp_msg_log_text_set( - &test_msg, "Filtered all obs from 2314 at tow 83.539019", false, - &written)); + &t, "Filtered all obs from 2314 at tow 83.539019", false, &written)); EXPECT_EQ(written, strlen("Filtered all obs from 2314 at tow 83.539019")); - EXPECT_EQ(sbp_msg_log_text_encoded_len(&test_msg), 43); + EXPECT_EQ(sbp_msg_log_text_encoded_len(&t), 43); + EXPECT_TRUE(sbp_msg_log_text_valid(&t)); +} - EXPECT_EQ(send_message(2314, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, SpaceRemaining) { + sbp_msg_log_t t{}; + size_t empty_space_remaining = sbp_msg_log_text_space_remaining(&t); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + size_t written; + EXPECT_TRUE(sbp_msg_log_text_set( + &t, "Filtered all obs from 2314 at tow 83.539019", false, &written)); + EXPECT_EQ(written, strlen("Filtered all obs from 2314 at tow 83.539019")); + EXPECT_EQ(sbp_msg_log_text_encoded_len(&t), 43); + size_t assigned_space_remaining = sbp_msg_log_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} - while (dummy_rd_ < dummy_wr_) { - process(); - } +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_log_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_log_text_set_raw(&t, info.test_msg.text.data, + sbp_msg_log_text_strlen(&info.test_msg), + false, &nwritten)); + EXPECT_EQ(sbp_msg_log_text_encoded_len(&info.test_msg), + sbp_msg_log_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, Set) { + sbp_msg_log_t t{}; + size_t nwritten{}; + const char *text = "Filtered all obs from 2314 at tow 83.539019"; + + EXPECT_TRUE(sbp_msg_log_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_log_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, Printf) { + sbp_msg_log_t t{}; + size_t nwritten{}; + const char *text = "Filtered all obs from 2314 at tow 83.539019"; + + EXPECT_TRUE(sbp_msg_log_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_log_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, Vprintf) { + sbp_msg_log_t t{}; + size_t nwritten{}; + const char *text = "Filtered all obs from 2314 at tow 83.539019"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_log_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_log_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, AppendPrintf) { + sbp_msg_log_t t{}; + size_t nwritten{}; + char part1[] = "Filtered all obs from 2314 at tow 83.539019"; + char part2[] = "Filtered all obs from 2314 at tow 83.539019"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_log_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_log_text_get(&t), &part1[0]); + + EXPECT_TRUE( + sbp_msg_log_text_append_printf(&t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_log_text_get(&t), + "Filtered all obs from 2314 at tow 83.539019"); +} + +TEST_F(Testauto_check_sbp_logging_MsgLog0_text, AppendVprintf) { + sbp_msg_log_t t{}; + size_t nwritten{}; + char part1[] = "Filtered all obs from 2314 at tow 83.539019"; + char part2[] = "Filtered all obs from 2314 at tow 83.539019"; + + part1[1] = 0; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 2314); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.level, 6) - << "incorrect value for last_msg_.level, expected 6, is " - << last_msg_.level; + EXPECT_TRUE(sbp_msg_log_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_log_text_get(&t), &part1[0]); - EXPECT_EQ(sbp_msg_log_text_encoded_len(&last_msg_), 43); - EXPECT_STREQ(sbp_msg_log_text_get(&last_msg_), + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_log_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_log_text_get(&t), "Filtered all obs from 2314 at tow 83.539019"); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_logging_MsgPrintDep.cc b/c/test/cpp/auto_check_sbp_logging_MsgPrintDep.cc index 2aa8b950da..7c2d6b86cc 100644 --- a/c/test/cpp/auto_check_sbp_logging_MsgPrintDep.cc +++ b/c/test/cpp/auto_check_sbp_logging_MsgPrintDep.cc @@ -16,535 +16,5289 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_logging_MsgPrintDep0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_logging_MsgPrintDep0 : public ::testing::Test { public: - Test_auto_check_sbp_logging_MsgPrintDep0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_logging_MsgPrintDep0() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n", false, + &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 43); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0x6774; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 43; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[43 + 8] = { 85, 16, 0, 34, 34, 43, 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, 80, 82, 78, 32, 49, 53, 32, 102, 111, 117, 110, 100, 32, 64, 32, 45, 50, 52, 57, 55, 32, 72, 122, 44, 32, 50, 48, 32, 83, 78, 82, 10, 116, 103, }; + uint8_t encoded_payload_[43] = { + 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, 80, 82, 78, 32, + 49, 53, 32, 102, 111, 117, 110, 100, 32, 64, 32, 45, 50, 52, 57, + 55, 32, 72, 122, 44, 32, 50, 48, 32, 83, 78, 82, 10, + }; +}; - sbp_msg_print_dep_t test_msg{}; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); - size_t written; - EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n", false, - &written)); - EXPECT_EQ(written, strlen("INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 43); + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[43]; + uint8_t n_written; - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 43); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 43), 0); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 43); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 43), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[43]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 43), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[43]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 43; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 43); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"); + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 43); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 43); + EXPECT_EQ(msg, info.test_msg); } -class Test_auto_check_sbp_logging_MsgPrintDep1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_logging_MsgPrintDep1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep1, Test) { - uint8_t encoded_frame[] = { - 85, 16, 0, 34, 34, 42, 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, - 80, 82, 78, 32, 51, 49, 32, 102, 111, 117, 110, 100, 32, 64, 32, 52, 50, - 52, 53, 32, 72, 122, 44, 32, 50, 49, 32, 83, 78, 82, 10, 140, 43, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_print_dep_t test_msg{}; + CHandler handler{&state}; - size_t written; - EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n", false, - &written)); - EXPECT_EQ(written, strlen("INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 42); + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CHandler handler(&state); - while (dummy_rd_ < dummy_wr_) { - process(); + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 42); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"); + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } -class Test_auto_check_sbp_logging_MsgPrintDep2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_logging_MsgPrintDep2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 0); +} -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep2, Test) { - uint8_t encoded_frame[] = { - 85, 16, 0, 34, 34, 35, 73, 78, 70, 79, 58, 32, 68, 105, 115, - 97, 98, 108, 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, - 48, 32, 40, 80, 82, 78, 32, 49, 49, 41, 10, 23, 143, - }; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_print_dep_t test_msg{}; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - size_t written; - EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: Disabling channel 0 (PRN 11)\n", false, &written)); - EXPECT_EQ(written, strlen("INFO: Disabling channel 0 (PRN 11)\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 35); + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - while (dummy_rd_ < dummy_wr_) { - process(); + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 35); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: Disabling channel 0 (PRN 11)\n"); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } -class Test_auto_check_sbp_logging_MsgPrintDep3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_logging_MsgPrintDep3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep3, Test) { - uint8_t encoded_frame[] = { - 85, 16, 0, 34, 34, 41, 73, 78, 70, 79, 58, 32, 97, - 99, 113, 58, 32, 80, 82, 78, 32, 50, 32, 102, 111, 117, - 110, 100, 32, 64, 32, 51, 57, 57, 54, 32, 72, 122, 44, - 32, 50, 48, 32, 83, 78, 82, 10, 239, 48, - }; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_print_dep_t test_msg{}; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; - size_t written; - EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n", false, - &written)); - EXPECT_EQ(written, strlen("INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 41); + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); - while (dummy_rd_ < dummy_wr_) { - process(); - } + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 41); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); } -class Test_auto_check_sbp_logging_MsgPrintDep4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_logging_MsgPrintDep4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[43]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 43); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 43), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 43); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep4, Test) { - uint8_t encoded_frame[] = { - 85, 16, 0, 34, 34, 42, 73, 78, 70, 79, 58, 32, 97, - 99, 113, 58, 32, 80, 82, 78, 32, 52, 32, 102, 111, 117, - 110, 100, 32, 64, 32, 45, 55, 52, 57, 50, 32, 72, 122, - 44, 32, 50, 48, 32, 83, 78, 82, 10, 47, 248, - }; +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_print_dep_t test_msg{}; + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep0_text + : public Testauto_check_sbp_logging_MsgPrintDep0 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, IsValid) { + sbp_msg_print_dep_t t{}; size_t written; EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n", false, - &written)); - EXPECT_EQ(written, strlen("INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 42); + &t, "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 43); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 43); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} - while (dummy_rd_ < dummy_wr_) { - process(); - } +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); + size_t nwritten{}; - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 42); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"); + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep0_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 15 found @ -2497 Hz, 20 SNR\n"); } -class Test_auto_check_sbp_logging_MsgPrintDep5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + +class Testauto_check_sbp_logging_MsgPrintDep1 : public ::testing::Test { public: - Test_auto_check_sbp_logging_MsgPrintDep5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_logging_MsgPrintDep1() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n", false, + &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 42); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_print_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_print_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_logging_MsgPrintDep5, Test) { - uint8_t encoded_frame[] = { - 85, 16, 0, 34, 34, 35, 73, 78, 70, 79, 58, 32, 68, 105, 115, - 97, 98, 108, 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, - 49, 32, 40, 80, 82, 78, 32, 49, 53, 41, 10, 158, 139, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_print_dep_t test_msg{}; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - size_t written; - EXPECT_TRUE(sbp_msg_print_dep_text_set( - &test_msg, "INFO: Disabling channel 1 (PRN 15)\n", false, &written)); - EXPECT_EQ(written, strlen("INFO: Disabling channel 1 (PRN 15)\n")); - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg), 35); + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } - EXPECT_EQ(send_message(8738, test_msg), SBP_OK); + uint32_t remaining() const noexcept { return len_ - offset_; } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } - while (dummy_rd_ < dummy_wr_) { - process(); - } + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 8738); - EXPECT_EQ(last_msg_, test_msg); + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&last_msg_), 35); - EXPECT_STREQ(sbp_msg_print_dep_text_get(&last_msg_), - "INFO: Disabling channel 1 (PRN 15)\n"); -} + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0x2b8c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { + 85, 16, 0, 34, 34, 42, 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, + 80, 82, 78, 32, 51, 49, 32, 102, 111, 117, 110, 100, 32, 64, 32, 52, 50, + 52, 53, 32, 72, 122, 44, 32, 50, 49, 32, 83, 78, 82, 10, 140, 43, + }; + uint8_t encoded_payload_[42] = { + 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, 80, 82, 78, + 32, 51, 49, 32, 102, 111, 117, 110, 100, 32, 64, 32, 52, 50, + 52, 53, 32, 72, 122, 44, 32, 50, 49, 32, 83, 78, 82, 10, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep1_text + : public Testauto_check_sbp_logging_MsgPrintDep1 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, IsValid) { + sbp_msg_print_dep_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 42); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 42); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + char part2[] = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep1_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + char part2[] = "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 31 found @ 4245 Hz, 21 SNR\n"); +} + +class Testauto_check_sbp_logging_MsgPrintDep2 : public ::testing::Test { + public: + Testauto_check_sbp_logging_MsgPrintDep2() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: Disabling channel 0 (PRN 11)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 0 (PRN 11)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 35); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0x8f17; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 35; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[35 + 8] = { + 85, 16, 0, 34, 34, 35, 73, 78, 70, 79, 58, 32, 68, 105, 115, + 97, 98, 108, 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, + 48, 32, 40, 80, 82, 78, 32, 49, 49, 41, 10, 23, 143, + }; + uint8_t encoded_payload_[35] = { + 73, 78, 70, 79, 58, 32, 68, 105, 115, 97, 98, 108, + 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, + 48, 32, 40, 80, 82, 78, 32, 49, 49, 41, 10, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep2_text + : public Testauto_check_sbp_logging_MsgPrintDep2 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, IsValid) { + sbp_msg_print_dep_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: Disabling channel 0 (PRN 11)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 0 (PRN 11)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 35); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: Disabling channel 0 (PRN 11)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 0 (PRN 11)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 35); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 0 (PRN 11)\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 0 (PRN 11)\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 0 (PRN 11)\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: Disabling channel 0 (PRN 11)\n"; + char part2[] = "INFO: Disabling channel 0 (PRN 11)\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: Disabling channel 0 (PRN 11)\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep2_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: Disabling channel 0 (PRN 11)\n"; + char part2[] = "INFO: Disabling channel 0 (PRN 11)\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: Disabling channel 0 (PRN 11)\n"); +} + +class Testauto_check_sbp_logging_MsgPrintDep3 : public ::testing::Test { + public: + Testauto_check_sbp_logging_MsgPrintDep3() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n", false, + &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 41); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0x30ef; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 41; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[41 + 8] = { + 85, 16, 0, 34, 34, 41, 73, 78, 70, 79, 58, 32, 97, + 99, 113, 58, 32, 80, 82, 78, 32, 50, 32, 102, 111, 117, + 110, 100, 32, 64, 32, 51, 57, 57, 54, 32, 72, 122, 44, + 32, 50, 48, 32, 83, 78, 82, 10, 239, 48, + }; + uint8_t encoded_payload_[41] = { + 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, 80, 82, 78, + 32, 50, 32, 102, 111, 117, 110, 100, 32, 64, 32, 51, 57, 57, + 54, 32, 72, 122, 44, 32, 50, 48, 32, 83, 78, 82, 10, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + + for (uint8_t i = 0; i < 41; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep3_text + : public Testauto_check_sbp_logging_MsgPrintDep3 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, IsValid) { + sbp_msg_print_dep_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 41); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 41); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep3_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 2 found @ 3996 Hz, 20 SNR\n"); +} + +class Testauto_check_sbp_logging_MsgPrintDep4 : public ::testing::Test { + public: + Testauto_check_sbp_logging_MsgPrintDep4() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n", false, + &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 42); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0xf82f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { + 85, 16, 0, 34, 34, 42, 73, 78, 70, 79, 58, 32, 97, + 99, 113, 58, 32, 80, 82, 78, 32, 52, 32, 102, 111, 117, + 110, 100, 32, 64, 32, 45, 55, 52, 57, 50, 32, 72, 122, + 44, 32, 50, 48, 32, 83, 78, 82, 10, 47, 248, + }; + uint8_t encoded_payload_[42] = { + 73, 78, 70, 79, 58, 32, 97, 99, 113, 58, 32, 80, 82, 78, + 32, 52, 32, 102, 111, 117, 110, 100, 32, 64, 32, 45, 55, 52, + 57, 50, 32, 72, 122, 44, 32, 50, 48, 32, 83, 78, 82, 10, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep4_text + : public Testauto_check_sbp_logging_MsgPrintDep4 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, IsValid) { + sbp_msg_print_dep_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 42); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 42); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep4_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + char part2[] = "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: acq: PRN 4 found @ -7492 Hz, 20 SNR\n"); +} + +class Testauto_check_sbp_logging_MsgPrintDep5 : public ::testing::Test { + public: + Testauto_check_sbp_logging_MsgPrintDep5() { + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &test_msg_, "INFO: Disabling channel 1 (PRN 15)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 1 (PRN 15)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&test_msg_), 35); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_print_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPrintDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_print_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPrintDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->print_dep, sizeof(msg->print_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_print_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.print_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPrintDep); + info.sender_id = 8738; + info.preamble = 0x55; + info.crc = 0x8b9e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 35; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_print_dep_t &lesser, + const sbp_msg_print_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_print_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_print_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_print_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_print_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPrintDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_print_dep_t test_msg_{}; + uint8_t encoded_frame_[35 + 8] = { + 85, 16, 0, 34, 34, 35, 73, 78, 70, 79, 58, 32, 68, 105, 115, + 97, 98, 108, 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, + 49, 32, 40, 80, 82, 78, 32, 49, 53, 41, 10, 158, 139, + }; + uint8_t encoded_payload_[35] = { + 73, 78, 70, 79, 58, 32, 68, 105, 115, 97, 98, 108, + 105, 110, 103, 32, 99, 104, 97, 110, 110, 101, 108, 32, + 49, 32, 40, 80, 82, 78, 32, 49, 53, 41, 10, + }; +}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_print_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPrintDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPrintDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + EXPECT_EQ( + sbp_msg_print_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ(sbp_msg_print_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPrintDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + EXPECT_EQ(sbp_msg_print_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_PRINT_DEP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_print_dep_t t{}; return + // sbp_msg_print_dep_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_print_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_print_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPrintDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_print_dep_t lesser = info.test_msg; + sbp_msg_print_dep_t greater = info.test_msg; + make_lesser_greater(lesser.text, greater.text); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPrintDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PRINT_DEP"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_print_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_print_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.print_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.print_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPrintDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPrintDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_logging_MsgPrintDep5_text + : public Testauto_check_sbp_logging_MsgPrintDep5 {}; + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, StringInit) { + sbp_msg_print_dep_t t{}; + sbp_msg_print_dep_text_init(&t); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, IsValid) { + sbp_msg_print_dep_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: Disabling channel 1 (PRN 15)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 1 (PRN 15)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 35); + EXPECT_TRUE(sbp_msg_print_dep_text_valid(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, SpaceRemaining) { + sbp_msg_print_dep_t t{}; + size_t empty_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_print_dep_text_set( + &t, "INFO: Disabling channel 1 (PRN 15)\n", false, &written)); + EXPECT_EQ(written, strlen("INFO: Disabling channel 1 (PRN 15)\n")); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&t), 35); + size_t assigned_space_remaining = sbp_msg_print_dep_text_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_print_dep_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_print_dep_text_set_raw( + &t, info.test_msg.text.data, + sbp_msg_print_dep_text_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_print_dep_text_encoded_len(&info.test_msg), + sbp_msg_print_dep_text_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, Set) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 1 (PRN 15)\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, Printf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 1 (PRN 15)\n"; + + EXPECT_TRUE(sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, Vprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + const char *text = "INFO: Disabling channel 1 (PRN 15)\n"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_print_dep_text_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), text); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, AppendPrintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: Disabling channel 1 (PRN 15)\n"; + char part2[] = "INFO: Disabling channel 1 (PRN 15)\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_print_dep_text_append_printf(&t, false, &nwritten, "%s", + &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: Disabling channel 1 (PRN 15)\n"); +} + +TEST_F(Testauto_check_sbp_logging_MsgPrintDep5_text, AppendVprintf) { + sbp_msg_print_dep_t t{}; + size_t nwritten{}; + char part1[] = "INFO: Disabling channel 1 (PRN 15)\n"; + char part2[] = "INFO: Disabling channel 1 (PRN 15)\n"; + + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_print_dep_text_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_print_dep_text_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_print_dep_text_get(&t), + "INFO: Disabling channel 1 (PRN 15)\n"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_mag_MsgMagRaw.cc b/c/test/cpp/auto_check_sbp_mag_MsgMagRaw.cc new file mode 100644 index 0000000000..11346ad0ca --- /dev/null +++ b/c/test/cpp/auto_check_sbp_mag_MsgMagRaw.cc @@ -0,0 +1,787 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_mag_MsgMagRaw0 : public ::testing::Test { + public: + Testauto_check_sbp_mag_MsgMagRaw0() { + assign(test_msg_.mag_x, 866); + assign(test_msg_.mag_y, 742); + assign(test_msg_.mag_z, -6802); + assign(test_msg_.tow, 3332301741); + assign(test_msg_.tow_f, 206); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_mag_raw_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_mag_raw_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgMagRaw, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_mag_raw_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgMagRaw); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->mag_raw, sizeof(msg->mag_raw)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_mag_raw_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.mag_raw, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgMagRaw); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x179f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_mag_raw_t &lesser, + const sbp_msg_mag_raw_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_mag_raw_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_mag_raw_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_mag_raw_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_mag_raw_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgMagRaw, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgMagRaw, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgMagRaw, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgMagRaw, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_mag_raw_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, + 206, 98, 3, 230, 2, 110, 229, 159, 23, + }; + uint8_t encoded_payload_[11] = { + 173, 227, 158, 198, 206, 98, 3, 230, 2, 110, 229, + }; +}; + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_mag_raw_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgMagRaw, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_mag_raw_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgMagRaw, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_mag_raw_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_mag_raw_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mag_raw_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_mag_raw_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgMagRaw, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_mag_raw_t msg{}; + + EXPECT_EQ(sbp_msg_mag_raw_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_mag_raw_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_mag_raw_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_mag_raw_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMagRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgMagRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMagRaw, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_mag_raw_t lesser = info.test_msg; + sbp_msg_mag_raw_t greater = info.test_msg; + make_lesser_greater(lesser.mag_x, greater.mag_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_mag_raw_t lesser = info.test_msg; + sbp_msg_mag_raw_t greater = info.test_msg; + make_lesser_greater(lesser.mag_y, greater.mag_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_mag_raw_t lesser = info.test_msg; + sbp_msg_mag_raw_t greater = info.test_msg; + make_lesser_greater(lesser.mag_z, greater.mag_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_mag_raw_t lesser = info.test_msg; + sbp_msg_mag_raw_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_mag_raw_t lesser = info.test_msg; + sbp_msg_mag_raw_t greater = info.test_msg; + make_lesser_greater(lesser.tow_f, greater.tow_f); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgMagRaw); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_MAG_RAW"); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_mag_raw_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_mag_raw_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.mag_raw, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.mag_raw, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mag_raw_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgMagRaw, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_mag_MsgMagRaw0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgMagRaw, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgAgeCorrections.cc b/c/test/cpp/auto_check_sbp_navigation_MsgAgeCorrections.cc index 490024fc15..ed6e3b0293 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgAgeCorrections.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgAgeCorrections.cc @@ -16,88 +16,779 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgAgeCorrections0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgAgeCorrections0 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgAgeCorrections0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgAgeCorrections0() { + assign(test_msg_.age, 30); + assign(test_msg_.tow, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_age_corrections_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_age_corrections_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAgeCorrections, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_age_corrections_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAgeCorrections); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->age_corrections, + sizeof(msg->age_corrections)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_age_corrections_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.age_corrections, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAgeCorrections); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xcae9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 6; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_age_corrections_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_age_corrections_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_age_corrections_t &lesser, + const sbp_msg_age_corrections_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_age_corrections_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_age_corrections_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_age_corrections_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_age_corrections_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAgeCorrections, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAgeCorrections, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgAgeCorrections, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgAgeCorrections, &wrapped_greater, + &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_navigation_MsgAgeCorrections0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_age_corrections_t test_msg_{}; + uint8_t encoded_frame_[6 + 8] = { 85, 16, 2, 66, 0, 6, 100, 0, 0, 0, 30, 0, 233, 202, }; + uint8_t encoded_payload_[6] = { + 100, 0, 0, 0, 30, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_age_corrections_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAgeCorrections, &info.test_msg_wrapped), + info.payload_len); +} - sbp_msg_age_corrections_t test_msg{}; - test_msg.age = 30; - test_msg.tow = 100; +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[6]; + uint8_t n_written; - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_age_corrections_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 6), 0); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAgeCorrections, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 6), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[6]; + + EXPECT_EQ(sbp_msg_age_corrections_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 6), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[6]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ( + sbp_msg_age_corrections_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_age_corrections_t msg{}; + uint8_t n_read; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.age, 30) - << "incorrect value for last_msg_.age, expected 30, is " << last_msg_.age; - EXPECT_EQ(last_msg_.tow, 100) - << "incorrect value for last_msg_.tow, expected 100, is " - << last_msg_.tow; + EXPECT_EQ(sbp_msg_age_corrections_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 6); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAgeCorrections, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 6); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_age_corrections_t msg{}; + + EXPECT_EQ(sbp_msg_age_corrections_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_age_corrections_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_age_corrections_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_age_corrections_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAgeCorrections, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAgeCorrections, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAgeCorrections, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_age_corrections_t lesser = info.test_msg; + sbp_msg_age_corrections_t greater = info.test_msg; + make_lesser_greater(lesser.age, greater.age); + comparison_tests(lesser, greater); + } + { + sbp_msg_age_corrections_t lesser = info.test_msg; + sbp_msg_age_corrections_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAgeCorrections); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_AGE_CORRECTIONS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_age_corrections_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_age_corrections_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.age_corrections, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.age_corrections, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[6]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 6), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_age_corrections_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 6); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAgeCorrections, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgAgeCorrections0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAgeCorrections, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEF.cc b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEF.cc index f267713d48..ea9a172b63 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEF.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEF.cc @@ -16,521 +16,3979 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgBaselineECEF0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgBaselineECEF0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEF0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 14); + assign(test_msg_.tow, 326825000); + assign(test_msg_.x, -1154410); + assign(test_msg_.y, 1327294); + assign(test_msg_.z, 631798); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef, + sizeof(msg->baseline_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xbfdb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_t &lesser, + const sbp_msg_baseline_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 11, 2, 211, 136, 20, 40, 244, 122, 19, 150, 98, 238, 255, + 190, 64, 20, 0, 246, 163, 9, 0, 0, 0, 14, 0, 219, 191, + }; + uint8_t encoded_payload_[20] = { + 40, 244, 122, 19, 150, 98, 238, 255, 190, 64, + 20, 0, 246, 163, 9, 0, 0, 0, 14, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcef, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEF1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEF1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.x, -1154232); + assign(test_msg_.y, 1327551); + assign(test_msg_.z, 631434); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef, + sizeof(msg->baseline_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x4ef0; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_t &lesser, + const sbp_msg_baseline_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 11, 2, 211, 136, 20, 16, 248, 122, 19, 72, 99, 238, 255, + 191, 65, 20, 0, 138, 162, 9, 0, 0, 0, 15, 0, 240, 78, + }; + uint8_t encoded_payload_[20] = { + 16, 248, 122, 19, 72, 99, 238, 255, 191, 65, + 20, 0, 138, 162, 9, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcef, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEF2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEF2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.x, -1154263); + assign(test_msg_.y, 1327541); + assign(test_msg_.z, 631188); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef, + sizeof(msg->baseline_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x8404; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_t &lesser, + const sbp_msg_baseline_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 11, 2, 211, 136, 20, 248, 251, 122, 19, 41, 99, 238, 255, + 181, 65, 20, 0, 148, 161, 9, 0, 0, 0, 15, 0, 4, 132, + }; + uint8_t encoded_payload_[20] = { + 248, 251, 122, 19, 41, 99, 238, 255, 181, 65, + 20, 0, 148, 161, 9, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcef, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEF3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineECEF0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineECEF3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326828000); + assign(test_msg_.x, -1154628); + assign(test_msg_.y, 1327185); + assign(test_msg_.z, 630849); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef, + sizeof(msg->baseline_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x5e43; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_t &lesser, + const sbp_msg_baseline_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 11, 2, 211, 136, 20, 224, 255, 122, 19, 188, 97, 238, 255, + 81, 64, 20, 0, 65, 160, 9, 0, 0, 0, 15, 0, 67, 94, + }; + uint8_t encoded_payload_[20] = { + 224, 255, 122, 19, 188, 97, 238, 255, 81, 64, + 20, 0, 65, 160, 9, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEF0, Test) { - uint8_t encoded_frame[] = { - 85, 11, 2, 211, 136, 20, 40, 244, 122, 19, 150, 98, 238, 255, - 190, 64, 20, 0, 246, 163, 9, 0, 0, 0, 14, 0, 219, 191, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_baseline_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 14; - test_msg.tow = 326825000; - test_msg.x = -1154410; - test_msg.y = 1327294; - test_msg.z = 631798; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 14) - << "incorrect value for last_msg_.n_sats, expected 14, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1154410) - << "incorrect value for last_msg_.x, expected -1154410, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1327294) - << "incorrect value for last_msg_.y, expected 1327294, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 631798) - << "incorrect value for last_msg_.z, expected 631798, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEF1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEF1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEF1, Test) { - uint8_t encoded_frame[] = { - 85, 11, 2, 211, 136, 20, 16, 248, 122, 19, 72, 99, 238, 255, - 191, 65, 20, 0, 138, 162, 9, 0, 0, 0, 15, 0, 240, 78, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcef, + &info.test_msg_wrapped); - sbp_msg_baseline_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.x = -1154232; - test_msg.y = 1327551; - test_msg.z = 631434; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1154232) - << "incorrect value for last_msg_.x, expected -1154232, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1327551) - << "incorrect value for last_msg_.y, expected 1327551, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 631434) - << "incorrect value for last_msg_.z, expected 631434, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEF2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEF4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineECEF2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineECEF4() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326829000); + assign(test_msg_.x, -1154883); + assign(test_msg_.y, 1326941); + assign(test_msg_.z, 630626); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEF2, Test) { - uint8_t encoded_frame[] = { - 85, 11, 2, 211, 136, 20, 248, 251, 122, 19, 41, 99, 238, 255, - 181, 65, 20, 0, 148, 161, 9, 0, 0, 0, 15, 0, 4, 132, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_baseline_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.x = -1154263; - test_msg.y = 1327541; - test_msg.z = 631188; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1154263) - << "incorrect value for last_msg_.x, expected -1154263, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1327541) - << "incorrect value for last_msg_.y, expected 1327541, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 631188) - << "incorrect value for last_msg_.z, expected 631188, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEF3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEF3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEF3, Test) { - uint8_t encoded_frame[] = { - 85, 11, 2, 211, 136, 20, 224, 255, 122, 19, 188, 97, 238, 255, - 81, 64, 20, 0, 65, 160, 9, 0, 0, 0, 15, 0, 67, 94, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326828000; - test_msg.x = -1154628; - test_msg.y = 1327185; - test_msg.z = 630849; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326828000) - << "incorrect value for last_msg_.tow, expected 326828000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1154628) - << "incorrect value for last_msg_.x, expected -1154628, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1327185) - << "incorrect value for last_msg_.y, expected 1327185, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 630849) - << "incorrect value for last_msg_.z, expected 630849, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEF4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEF4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef, + sizeof(msg->baseline_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x5e6a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_baseline_ecef_t &lesser, + const sbp_msg_baseline_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEF4, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 11, 2, 211, 136, 20, 200, 3, 123, 19, 189, 96, 238, 255, 93, 63, 20, 0, 98, 159, 9, 0, 0, 0, 15, 0, 106, 94, }; + uint8_t encoded_payload_[20] = { + 200, 3, 123, 19, 189, 96, 238, 255, 93, 63, + 20, 0, 98, 159, 9, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_baseline_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_baseline_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326829000; - test_msg.x = -1154883; - test_msg.y = 1326941; - test_msg.z = 630626; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326829000) - << "incorrect value for last_msg_.tow, expected 326829000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1154883) - << "incorrect value for last_msg_.x, expected -1154883, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1326941) - << "incorrect value for last_msg_.y, expected 1326941, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 630626) - << "incorrect value for last_msg_.z, expected 630626, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_t lesser = info.test_msg; + sbp_msg_baseline_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ecef, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcef, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEF4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEFDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEFDepA.cc index c08eac33f6..ebf963dee8 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEFDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineECEFDepA.cc @@ -16,1117 +16,8926 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.x, -53227); + assign(test_msg_.y, -35532); + assign(test_msg_.z, -76840); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8932; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 246, 215, 20, 20, 46, 39, 0, 21, 48, 255, 255, + 52, 117, 255, 255, 216, 211, 254, 255, 0, 0, 9, 1, 50, 137, + }; + uint8_t encoded_payload_[20] = { + 20, 46, 39, 0, 21, 48, 255, 255, 52, 117, + 255, 255, 216, 211, 254, 255, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA1 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.x, -52934); + assign(test_msg_.y, -35791); + assign(test_msg_.z, -76922); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x9be3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 246, 215, 20, 120, 46, 39, 0, 58, 49, 255, 255, + 49, 116, 255, 255, 134, 211, 254, 255, 0, 0, 9, 1, 227, 155, + }; + uint8_t encoded_payload_[20] = { + 120, 46, 39, 0, 58, 49, 255, 255, 49, 116, + 255, 255, 134, 211, 254, 255, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA2 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.x, -52639); + assign(test_msg_.y, -36049); + assign(test_msg_.z, -77004); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x7e3d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 246, 215, 20, 220, 46, 39, 0, 97, 50, 255, 255, + 47, 115, 255, 255, 52, 211, 254, 255, 0, 0, 9, 1, 61, 126, + }; + uint8_t encoded_payload_[20] = { + 220, 46, 39, 0, 97, 50, 255, 255, 47, 115, + 255, 255, 52, 211, 254, 255, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA3 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568000); + assign(test_msg_.x, -52344); + assign(test_msg_.y, -36307); + assign(test_msg_.z, -77084); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x4fc8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 246, 215, 20, 64, 47, 39, 0, 136, 51, 255, 255, + 45, 114, 255, 255, 228, 210, 254, 255, 0, 0, 9, 1, 200, 79, + }; + uint8_t encoded_payload_[20] = { + 64, 47, 39, 0, 136, 51, 255, 255, 45, 114, + 255, 255, 228, 210, 254, 255, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA4 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA4() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568100); + assign(test_msg_.x, -52048); + assign(test_msg_.y, -36564); + assign(test_msg_.z, -77163); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x1868; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 246, 215, 20, 164, 47, 39, 0, 176, 52, 255, 255, + 44, 113, 255, 255, 149, 210, 254, 255, 0, 0, 9, 1, 104, 24, + }; + uint8_t encoded_payload_[20] = { + 164, 47, 39, 0, 176, 52, 255, 255, 44, 113, + 255, 255, 149, 210, 254, 255, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA5 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA5() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180700); + assign(test_msg_.x, -6231); + assign(test_msg_.y, -12186); + assign(test_msg_.z, 7419); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xa892; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 195, 4, 20, 156, 21, 69, 24, 169, 231, 255, 255, + 102, 208, 255, 255, 251, 28, 0, 0, 0, 0, 6, 0, 146, 168, + }; + uint8_t encoded_payload_[20] = { + 156, 21, 69, 24, 169, 231, 255, 255, 102, 208, + 255, 255, 251, 28, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA6 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA6() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180800); + assign(test_msg_.x, -6231); + assign(test_msg_.y, -12185); + assign(test_msg_.z, 7420); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x7422; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 195, 4, 20, 0, 22, 69, 24, 169, 231, 255, 255, + 103, 208, 255, 255, 252, 28, 0, 0, 0, 0, 6, 0, 34, 116, + }; + uint8_t encoded_payload_[20] = { + 0, 22, 69, 24, 169, 231, 255, 255, 103, 208, + 255, 255, 252, 28, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA7 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA7() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180900); + assign(test_msg_.x, -8162); + assign(test_msg_.y, -18496); + assign(test_msg_.z, 13807); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xfe1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 195, 4, 20, 100, 22, 69, 24, 30, 224, 255, 255, + 192, 183, 255, 255, 239, 53, 0, 0, 0, 0, 6, 0, 225, 15, + }; + uint8_t encoded_payload_[20] = { + 100, 22, 69, 24, 30, 224, 255, 255, 192, 183, + 255, 255, 239, 53, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA8 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineECEFDepA8() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181000); + assign(test_msg_.x, -8164); + assign(test_msg_.y, -18497); + assign(test_msg_.z, 13810); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6423; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 195, 4, 20, 200, 22, 69, 24, 28, 224, 255, 255, + 191, 183, 255, 255, 242, 53, 0, 0, 0, 0, 6, 0, 35, 100, + }; + uint8_t encoded_payload_[20] = { + 200, 22, 69, 24, 28, 224, 255, 255, 191, 183, + 255, 255, 242, 53, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA9 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineECEFDepA9() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181100); + assign(test_msg_.x, -7400); + assign(test_msg_.y, -15591); + assign(test_msg_.z, 15257); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4242; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 2, 2, 195, 4, 20, 44, 23, 69, 24, 24, 227, 255, 255, + 25, 195, 255, 255, 153, 59, 0, 0, 0, 0, 6, 0, 66, 66, + }; + uint8_t encoded_payload_[20] = { + 44, 23, 69, 24, 24, 227, 255, 255, 25, 195, + 255, 255, 153, 59, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 246, 215, 20, 20, 46, 39, 0, 21, 48, 255, 255, - 52, 117, 255, 255, 216, 211, 254, 255, 0, 0, 9, 1, 50, 137, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.x = -53227; - test_msg.y = -35532; - test_msg.z = -76840; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -53227) - << "incorrect value for last_msg_.x, expected -53227, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -35532) - << "incorrect value for last_msg_.y, expected -35532, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -76840) - << "incorrect value for last_msg_.z, expected -76840, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineECEFDepA10 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineECEFDepA10() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181200); + assign(test_msg_.x, -7401); + assign(test_msg_.y, -15591); + assign(test_msg_.z, 15257); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 246, 215, 20, 120, 46, 39, 0, 58, 49, 255, 255, - 49, 116, 255, 255, 134, 211, 254, 255, 0, 0, 9, 1, 227, 155, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.x = -52934; - test_msg.y = -35791; - test_msg.z = -76922; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -52934) - << "incorrect value for last_msg_.x, expected -52934, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -35791) - << "incorrect value for last_msg_.y, expected -35791, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -76922) - << "incorrect value for last_msg_.z, expected -76922, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 246, 215, 20, 220, 46, 39, 0, 97, 50, 255, 255, - 47, 115, 255, 255, 52, 211, 254, 255, 0, 0, 9, 1, 61, 126, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.x = -52639; - test_msg.y = -36049; - test_msg.z = -77004; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -52639) - << "incorrect value for last_msg_.x, expected -52639, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -36049) - << "incorrect value for last_msg_.y, expected -36049, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -77004) - << "incorrect value for last_msg_.z, expected -77004, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 246, 215, 20, 64, 47, 39, 0, 136, 51, 255, 255, - 45, 114, 255, 255, 228, 210, 254, 255, 0, 0, 9, 1, 200, 79, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2568000; - test_msg.x = -52344; - test_msg.y = -36307; - test_msg.z = -77084; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568000) - << "incorrect value for last_msg_.tow, expected 2568000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -52344) - << "incorrect value for last_msg_.x, expected -52344, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -36307) - << "incorrect value for last_msg_.y, expected -36307, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -77084) - << "incorrect value for last_msg_.z, expected -77084, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 246, 215, 20, 164, 47, 39, 0, 176, 52, 255, 255, - 44, 113, 255, 255, 149, 210, 254, 255, 0, 0, 9, 1, 104, 24, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2568100; - test_msg.x = -52048; - test_msg.y = -36564; - test_msg.z = -77163; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568100) - << "incorrect value for last_msg_.tow, expected 2568100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -52048) - << "incorrect value for last_msg_.x, expected -52048, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -36564) - << "incorrect value for last_msg_.y, expected -36564, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -77163) - << "incorrect value for last_msg_.z, expected -77163, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 195, 4, 20, 156, 21, 69, 24, 169, 231, 255, 255, - 102, 208, 255, 255, 251, 28, 0, 0, 0, 0, 6, 0, 146, 168, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407180700; - test_msg.x = -6231; - test_msg.y = -12186; - test_msg.z = 7419; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180700) - << "incorrect value for last_msg_.tow, expected 407180700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -6231) - << "incorrect value for last_msg_.x, expected -6231, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -12186) - << "incorrect value for last_msg_.y, expected -12186, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 7419) - << "incorrect value for last_msg_.z, expected 7419, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineEcefDepA, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 195, 4, 20, 0, 22, 69, 24, 169, 231, 255, 255, - 103, 208, 255, 255, 252, 28, 0, 0, 0, 0, 6, 0, 34, 116, + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ecef_dep_a, + sizeof(msg->baseline_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407180800; - test_msg.x = -6231; - test_msg.y = -12185; - test_msg.z = 7420; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180800) - << "incorrect value for last_msg_.tow, expected 407180800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -6231) - << "incorrect value for last_msg_.x, expected -6231, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -12185) - << "incorrect value for last_msg_.y, expected -12185, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 7420) - << "incorrect value for last_msg_.z, expected 7420, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_baseline_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 195, 4, 20, 100, 22, 69, 24, 30, 224, 255, 255, - 192, 183, 255, 255, 239, 53, 0, 0, 0, 0, 6, 0, 225, 15, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407180900; - test_msg.x = -8162; - test_msg.y = -18496; - test_msg.z = 13807; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180900) - << "incorrect value for last_msg_.tow, expected 407180900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -8162) - << "incorrect value for last_msg_.x, expected -8162, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -18496) - << "incorrect value for last_msg_.y, expected -18496, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 13807) - << "incorrect value for last_msg_.z, expected 13807, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x8723; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_baseline_ecef_dep_a_t &lesser, + const sbp_msg_baseline_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 195, 4, 20, 200, 22, 69, 24, 28, 224, 255, 255, - 191, 183, 255, 255, 242, 53, 0, 0, 0, 0, 6, 0, 35, 100, - }; + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ecef_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407181000; - test_msg.x = -8164; - test_msg.y = -18497; - test_msg.z = 13810; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181000) - << "incorrect value for last_msg_.tow, expected 407181000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -8164) - << "incorrect value for last_msg_.x, expected -8164, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -18497) - << "incorrect value for last_msg_.y, expected -18497, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 13810) - << "incorrect value for last_msg_.z, expected 13810, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineEcefDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 2, 2, 195, 4, 20, 44, 23, 69, 24, 24, 227, 255, 255, - 25, 195, 255, 255, 153, 59, 0, 0, 0, 0, 6, 0, 66, 66, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407181100; - test_msg.x = -7400; - test_msg.y = -15591; - test_msg.z = 15257; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181100) - << "incorrect value for last_msg_.tow, expected 407181100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -7400) - << "incorrect value for last_msg_.x, expected -7400, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -15591) - << "incorrect value for last_msg_.y, expected -15591, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 15257) - << "incorrect value for last_msg_.z, expected 15257, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgBaselineECEFDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineECEFDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineECEFDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_baseline_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 2, 2, 195, 4, 20, 144, 23, 69, 24, 23, 227, 255, 255, 25, 195, 255, 255, 153, 59, 0, 0, 0, 0, 6, 0, 35, 135, }; + uint8_t encoded_payload_[20] = { + 144, 23, 69, 24, 23, 227, 255, 255, 25, 195, + 255, 255, 153, 59, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_baseline_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ecef_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_baseline_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 6; - test_msg.tow = 407181200; - test_msg.x = -7401; - test_msg.y = -15591; - test_msg.z = 15257; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181200) - << "incorrect value for last_msg_.tow, expected 407181200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -7401) - << "incorrect value for last_msg_.x, expected -7401, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -15591) - << "incorrect value for last_msg_.y, expected -15591, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 15257) - << "incorrect value for last_msg_.z, expected 15257, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ecef_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineECEFDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc new file mode 100644 index 0000000000..988091d039 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc @@ -0,0 +1,825 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0() { + assign(test_msg_.flags, 58); + assign(test_msg_.heading, 3411152452); + assign(test_msg_.n_sats, 186); + assign(test_msg_.tow, 2958585170); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_heading_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_heading_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineHeadingDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_heading_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineHeadingDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_heading_dep_a, + sizeof(msg->baseline_heading_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_heading_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_heading_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineHeadingDepA); + info.sender_id = 52860; + info.preamble = 0x55; + info.crc = 0xb6ad; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_heading_dep_a_t &lesser, + const sbp_msg_baseline_heading_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_heading_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_heading_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineHeadingDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineHeadingDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineHeadingDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineHeadingDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_heading_dep_a_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 7, 2, 124, 206, 10, 82, 109, 88, + 176, 68, 14, 82, 203, 186, 58, 173, 182, + }; + uint8_t encoded_payload_[10] = { + 82, 109, 88, 176, 68, 14, 82, 203, 186, 58, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineHeadingDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineHeadingDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgBaselineHeadingDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_heading_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineHeadingDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgBaselineHeadingDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineHeadingDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_heading_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_heading_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_heading_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.heading, greater.heading); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_heading_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_heading_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineHeadingDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_HEADING_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_heading_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_baseline_heading_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_heading_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_heading_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineHeadingDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineHeadingDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineHeadingDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNED.cc b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNED.cc index 023c4b323a..1c65abf602 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNED.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNED.cc @@ -16,536 +16,4004 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgBaselineNED0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgBaselineNED0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNED0() { + assign(test_msg_.d, 32153); + assign(test_msg_.e, -1681229); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 816073); + assign(test_msg_.n_sats, 14); + assign(test_msg_.tow, 326825000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNed, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned, + sizeof(msg->baseline_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x46e2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_t &lesser, + const sbp_msg_baseline_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 12, 2, 211, 136, 22, 40, 244, 122, 19, 201, 115, 12, 0, 179, + 88, 230, 255, 153, 125, 0, 0, 0, 0, 0, 0, 14, 0, 226, 70, + }; + uint8_t encoded_payload_[22] = { + 40, 244, 122, 19, 201, 115, 12, 0, 179, 88, 230, + 255, 153, 125, 0, 0, 0, 0, 0, 0, 14, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNed, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_baseline_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNed); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNed, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNed, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNED1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNED1() { + assign(test_msg_.d, 32622); + assign(test_msg_.e, -1681214); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 815970); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNed, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned, + sizeof(msg->baseline_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x5d45; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_t &lesser, + const sbp_msg_baseline_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 12, 2, 211, 136, 22, 16, 248, 122, 19, 98, 115, 12, 0, 194, + 88, 230, 255, 110, 127, 0, 0, 0, 0, 0, 0, 15, 0, 69, 93, + }; + uint8_t encoded_payload_[22] = { + 16, 248, 122, 19, 98, 115, 12, 0, 194, 88, 230, + 255, 110, 127, 0, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNed, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_baseline_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNed); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNed, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNed, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNED2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNED2() { + assign(test_msg_.d, 32750); + assign(test_msg_.e, -1681235); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 815759); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNed, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned, + sizeof(msg->baseline_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xa9d2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_t &lesser, + const sbp_msg_baseline_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 12, 2, 211, 136, 22, 248, 251, 122, 19, 143, 114, 12, 0, 173, + 88, 230, 255, 238, 127, 0, 0, 0, 0, 0, 0, 15, 0, 210, 169, + }; + uint8_t encoded_payload_[22] = { + 248, 251, 122, 19, 143, 114, 12, 0, 173, 88, 230, + 255, 238, 127, 0, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNed, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_baseline_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNed); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNed, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNed, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNED3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineNED0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineNED3() { + assign(test_msg_.d, 32559); + assign(test_msg_.e, -1681357); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 815190); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326828000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNed, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned, + sizeof(msg->baseline_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x6b87; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_t &lesser, + const sbp_msg_baseline_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 12, 2, 211, 136, 22, 224, 255, 122, 19, 86, 112, 12, 0, 51, + 88, 230, 255, 47, 127, 0, 0, 0, 0, 0, 0, 15, 0, 135, 107, + }; + uint8_t encoded_payload_[22] = { + 224, 255, 122, 19, 86, 112, 12, 0, 51, 88, 230, + 255, 47, 127, 0, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNed, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_baseline_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNed); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNED0, Test) { - uint8_t encoded_frame[] = { - 85, 12, 2, 211, 136, 22, 40, 244, 122, 19, 201, 115, 12, 0, 179, - 88, 230, 255, 153, 125, 0, 0, 0, 0, 0, 0, 14, 0, 226, 70, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_baseline_ned_t test_msg{}; - test_msg.d = 32153; - test_msg.e = -1681229; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 816073; - test_msg.n_sats = 14; - test_msg.tow = 326825000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 32153) - << "incorrect value for last_msg_.d, expected 32153, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1681229) - << "incorrect value for last_msg_.e, expected -1681229, is " - << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 816073) - << "incorrect value for last_msg_.n, expected 816073, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 14) - << "incorrect value for last_msg_.n_sats, expected 14, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNED1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNED1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNED1, Test) { - uint8_t encoded_frame[] = { - 85, 12, 2, 211, 136, 22, 16, 248, 122, 19, 98, 115, 12, 0, 194, - 88, 230, 255, 110, 127, 0, 0, 0, 0, 0, 0, 15, 0, 69, 93, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNed, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNed, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_baseline_ned_t test_msg{}; - test_msg.d = 32622; - test_msg.e = -1681214; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 815970; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 32622) - << "incorrect value for last_msg_.d, expected 32622, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1681214) - << "incorrect value for last_msg_.e, expected -1681214, is " - << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 815970) - << "incorrect value for last_msg_.n, expected 815970, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNED2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +class Testauto_check_sbp_navigation_MsgBaselineNED4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineNED2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineNED4() { + assign(test_msg_.d, 32421); + assign(test_msg_.e, -1681444); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 814806); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326829000); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNED2, Test) { - uint8_t encoded_frame[] = { - 85, 12, 2, 211, 136, 22, 248, 251, 122, 19, 143, 114, 12, 0, 173, - 88, 230, 255, 238, 127, 0, 0, 0, 0, 0, 0, 15, 0, 210, 169, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_baseline_ned_t test_msg{}; - test_msg.d = 32750; - test_msg.e = -1681235; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 815759; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 32750) - << "incorrect value for last_msg_.d, expected 32750, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1681235) - << "incorrect value for last_msg_.e, expected -1681235, is " - << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 815759) - << "incorrect value for last_msg_.n, expected 815759, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNED3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNED3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNED3, Test) { - uint8_t encoded_frame[] = { - 85, 12, 2, 211, 136, 22, 224, 255, 122, 19, 86, 112, 12, 0, 51, - 88, 230, 255, 47, 127, 0, 0, 0, 0, 0, 0, 15, 0, 135, 107, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ned_t test_msg{}; - test_msg.d = 32559; - test_msg.e = -1681357; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 815190; - test_msg.n_sats = 15; - test_msg.tow = 326828000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 32559) - << "incorrect value for last_msg_.d, expected 32559, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1681357) - << "incorrect value for last_msg_.e, expected -1681357, is " - << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 815190) - << "incorrect value for last_msg_.n, expected 815190, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326828000) - << "incorrect value for last_msg_.tow, expected 326828000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNED4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNED4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNed, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned, + sizeof(msg->baseline_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x50be; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_baseline_ned_t &lesser, + const sbp_msg_baseline_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBaselineNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNED4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_baseline_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { 85, 12, 2, 211, 136, 22, 200, 3, 123, 19, 214, 110, 12, 0, 220, 87, 230, 255, 165, 126, 0, 0, 0, 0, 0, 0, 15, 0, 190, 80, }; + uint8_t encoded_payload_[22] = { + 200, 3, 123, 19, 214, 110, 12, 0, 220, 87, 230, + 255, 165, 126, 0, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBaselineNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNed, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_baseline_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_baseline_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_baseline_ned_t test_msg{}; - test_msg.d = 32421; - test_msg.e = -1681444; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 814806; - test_msg.n_sats = 15; - test_msg.tow = 326829000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 32421) - << "incorrect value for last_msg_.d, expected 32421, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1681444) - << "incorrect value for last_msg_.e, expected -1681444, is " - << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 814806) - << "incorrect value for last_msg_.n, expected 814806, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326829000) - << "incorrect value for last_msg_.tow, expected 326829000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_t lesser = info.test_msg; + sbp_msg_baseline_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNed); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.baseline_ned, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNed, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNED4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNed, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNEDDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNEDDepA.cc index 09a39a63d7..c1aaf7c4e1 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNEDDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgBaselineNEDDepA.cc @@ -16,1161 +16,8950 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA0() { + assign(test_msg_.d, 0); + assign(test_msg_.e, -26134); + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -96525); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xc15d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 246, 215, 22, 20, 46, 39, 0, 243, 134, 254, 255, 234, + 153, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 93, 193, + }; + uint8_t encoded_payload_[22] = { + 20, 46, 39, 0, 243, 134, 254, 255, 234, 153, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA1 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA1() { + assign(test_msg_.d, 0); + assign(test_msg_.e, -25747); + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -96629); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x2726; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 246, 215, 22, 120, 46, 39, 0, 139, 134, 254, 255, 109, + 155, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 38, 39, + }; + uint8_t encoded_payload_[22] = { + 120, 46, 39, 0, 139, 134, 254, 255, 109, 155, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA2 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA2() { + assign(test_msg_.d, 0); + assign(test_msg_.e, -25360); + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -96731); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x853a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 246, 215, 22, 220, 46, 39, 0, 37, 134, 254, 255, 240, + 156, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 58, 133, + }; + uint8_t encoded_payload_[22] = { + 220, 46, 39, 0, 37, 134, 254, 255, 240, 156, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA3 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA3() { + assign(test_msg_.d, 0); + assign(test_msg_.e, -24973); + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -96831); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xd638; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 246, 215, 22, 64, 47, 39, 0, 193, 133, 254, 255, 115, + 158, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 56, 214, + }; + uint8_t encoded_payload_[22] = { + 64, 47, 39, 0, 193, 133, 254, 255, 115, 158, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA4 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA4() { + assign(test_msg_.d, 0); + assign(test_msg_.e, -24586); + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -96931); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568100); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xf4ea; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 246, 215, 22, 164, 47, 39, 0, 93, 133, 254, 255, 246, + 159, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 234, 244, + }; + uint8_t encoded_payload_[22] = { + 164, 47, 39, 0, 93, 133, 254, 255, 246, 159, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA5 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA5() { + assign(test_msg_.d, -15325); + assign(test_msg_.e, 1265); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -2430); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x15fa; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 195, 4, 22, 156, 21, 69, 24, 130, 246, 255, 255, 241, + 4, 0, 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, 250, 21, + }; + uint8_t encoded_payload_[22] = { + 156, 21, 69, 24, 130, 246, 255, 255, 241, 4, 0, + 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA6 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA6() { + assign(test_msg_.d, -15325); + assign(test_msg_.e, 1265); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -2430); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x85f0; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 195, 4, 22, 0, 22, 69, 24, 130, 246, 255, 255, 241, + 4, 0, 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, 240, 133, + }; + uint8_t encoded_payload_[22] = { + 0, 22, 69, 24, 130, 246, 255, 255, 241, 4, 0, + 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA7 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA7() { + assign(test_msg_.d, -24263); + assign(test_msg_.e, 3015); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -1248); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407180900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb50c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 195, 4, 22, 100, 22, 69, 24, 32, 251, 255, 255, 199, + 11, 0, 0, 57, 161, 255, 255, 0, 0, 0, 0, 6, 0, 12, 181, + }; + uint8_t encoded_payload_[22] = { + 100, 22, 69, 24, 32, 251, 255, 255, 199, 11, 0, + 0, 57, 161, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA8 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgBaselineNEDDepA8() { + assign(test_msg_.d, -24266); + assign(test_msg_.e, 3015); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -1247); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x3a56; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 195, 4, 22, 200, 22, 69, 24, 33, 251, 255, 255, 199, + 11, 0, 0, 54, 161, 255, 255, 0, 0, 0, 0, 6, 0, 86, 58, + }; + uint8_t encoded_payload_[22] = { + 200, 22, 69, 24, 33, 251, 255, 255, 199, 11, 0, + 0, 54, 161, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA9 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineNEDDepA9() { + assign(test_msg_.d, -22880); + assign(test_msg_.e, 2103); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 1646); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181100); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xf933; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 3, 2, 195, 4, 22, 44, 23, 69, 24, 110, 6, 0, 0, 55, + 8, 0, 0, 160, 166, 255, 255, 0, 0, 0, 0, 6, 0, 51, 249, + }; + uint8_t encoded_payload_[22] = { + 44, 23, 69, 24, 110, 6, 0, 0, 55, 8, 0, + 0, 160, 166, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 246, 215, 22, 20, 46, 39, 0, 243, 134, 254, 255, 234, - 153, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 93, 193, - }; +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = -26134; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.n = -96525; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -26134) - << "incorrect value for last_msg_.e, expected -26134, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -96525) - << "incorrect value for last_msg_.n, expected -96525, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgBaselineNEDDepA10 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgBaselineNEDDepA10() { + assign(test_msg_.d, -22880); + assign(test_msg_.e, 2102); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 1646); + assign(test_msg_.n_sats, 6); + assign(test_msg_.tow, 407181200); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 246, 215, 22, 120, 46, 39, 0, 139, 134, 254, 255, 109, - 155, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 38, 39, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = -25747; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.n = -96629; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -25747) - << "incorrect value for last_msg_.e, expected -25747, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -96629) - << "incorrect value for last_msg_.n, expected -96629, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 246, 215, 22, 220, 46, 39, 0, 37, 134, 254, 255, 240, - 156, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 58, 133, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = -25360; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.n = -96731; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -25360) - << "incorrect value for last_msg_.e, expected -25360, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -96731) - << "incorrect value for last_msg_.n, expected -96731, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 246, 215, 22, 64, 47, 39, 0, 193, 133, 254, 255, 115, - 158, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 56, 214, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = -24973; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.n = -96831; - test_msg.n_sats = 9; - test_msg.tow = 2568000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -24973) - << "incorrect value for last_msg_.e, expected -24973, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -96831) - << "incorrect value for last_msg_.n, expected -96831, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568000) - << "incorrect value for last_msg_.tow, expected 2568000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 246, 215, 22, 164, 47, 39, 0, 93, 133, 254, 255, 246, - 159, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 9, 1, 234, 244, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = -24586; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.n = -96931; - test_msg.n_sats = 9; - test_msg.tow = 2568100; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -24586) - << "incorrect value for last_msg_.e, expected -24586, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -96931) - << "incorrect value for last_msg_.n, expected -96931, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568100) - << "incorrect value for last_msg_.tow, expected 2568100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 195, 4, 22, 156, 21, 69, 24, 130, 246, 255, 255, 241, - 4, 0, 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, 250, 21, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -15325; - test_msg.e = 1265; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -2430; - test_msg.n_sats = 6; - test_msg.tow = 407180700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -15325) - << "incorrect value for last_msg_.d, expected -15325, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 1265) - << "incorrect value for last_msg_.e, expected 1265, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -2430) - << "incorrect value for last_msg_.n, expected -2430, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180700) - << "incorrect value for last_msg_.tow, expected 407180700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineNedDepA, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 195, 4, 22, 0, 22, 69, 24, 130, 246, 255, 255, 241, - 4, 0, 0, 35, 196, 255, 255, 0, 0, 0, 0, 6, 0, 240, 133, + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_ned_dep_a, + sizeof(msg->baseline_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -15325; - test_msg.e = 1265; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -2430; - test_msg.n_sats = 6; - test_msg.tow = 407180800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -15325) - << "incorrect value for last_msg_.d, expected -15325, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 1265) - << "incorrect value for last_msg_.e, expected 1265, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -2430) - << "incorrect value for last_msg_.n, expected -2430, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180800) - << "incorrect value for last_msg_.tow, expected 407180800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_baseline_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 195, 4, 22, 100, 22, 69, 24, 32, 251, 255, 255, 199, - 11, 0, 0, 57, 161, 255, 255, 0, 0, 0, 0, 6, 0, 12, 181, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -24263; - test_msg.e = 3015; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -1248; - test_msg.n_sats = 6; - test_msg.tow = 407180900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -24263) - << "incorrect value for last_msg_.d, expected -24263, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3015) - << "incorrect value for last_msg_.e, expected 3015, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -1248) - << "incorrect value for last_msg_.n, expected -1248, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407180900) - << "incorrect value for last_msg_.tow, expected 407180900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_ned_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x16ce; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_baseline_ned_dep_a_t &lesser, + const sbp_msg_baseline_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 195, 4, 22, 200, 22, 69, 24, 33, 251, 255, 255, 199, - 11, 0, 0, 54, 161, 255, 255, 0, 0, 0, 0, 6, 0, 86, 58, - }; + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_ned_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -24266; - test_msg.e = 3015; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -1247; - test_msg.n_sats = 6; - test_msg.tow = 407181000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -24266) - << "incorrect value for last_msg_.d, expected -24266, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3015) - << "incorrect value for last_msg_.e, expected 3015, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -1247) - << "incorrect value for last_msg_.n, expected -1247, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181000) - << "incorrect value for last_msg_.tow, expected 407181000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineNedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 3, 2, 195, 4, 22, 44, 23, 69, 24, 110, 6, 0, 0, 55, - 8, 0, 0, 160, 166, 255, 255, 0, 0, 0, 0, 6, 0, 51, 249, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -22880; - test_msg.e = 2103; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 1646; - test_msg.n_sats = 6; - test_msg.tow = 407181100; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -22880) - << "incorrect value for last_msg_.d, expected -22880, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 2103) - << "incorrect value for last_msg_.e, expected 2103, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 1646) - << "incorrect value for last_msg_.n, expected 1646, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181100) - << "incorrect value for last_msg_.tow, expected 407181100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgBaselineNEDDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgBaselineNEDDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_baseline_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_baseline_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgBaselineNEDDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_baseline_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { 85, 3, 2, 195, 4, 22, 144, 23, 69, 24, 110, 6, 0, 0, 54, 8, 0, 0, 160, 166, 255, 255, 0, 0, 0, 0, 6, 0, 206, 22, }; + uint8_t encoded_payload_[22] = { + 144, 23, 69, 24, 110, 6, 0, 0, 54, 8, 0, + 0, 160, 166, 255, 255, 0, 0, 0, 0, 6, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_msg_baseline_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_ned_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_baseline_ned_dep_a_t test_msg{}; - test_msg.d = -22880; - test_msg.e = 2102; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 1646; - test_msg.n_sats = 6; - test_msg.tow = 407181200; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -22880) - << "incorrect value for last_msg_.d, expected -22880, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 2102) - << "incorrect value for last_msg_.e, expected 2102, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 1646) - << "incorrect value for last_msg_.n, expected 1646, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 6) - << "incorrect value for last_msg_.n_sats, expected 6, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407181200) - << "incorrect value for last_msg_.tow, expected 407181200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_ned_dep_a_t lesser = info.test_msg; + sbp_msg_baseline_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.baseline_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_ned_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgBaselineNEDDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgDops.cc b/c/test/cpp/auto_check_sbp_navigation_MsgDops.cc index 461053d52c..96f8d0c152 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgDops.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgDops.cc @@ -16,109 +16,786 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgDops0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgDops0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgDops0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgDops0() { + assign(test_msg_.flags, 0); + assign(test_msg_.gdop, 2); + assign(test_msg_.hdop, 5); + assign(test_msg_.pdop, 6); + assign(test_msg_.tdop, 5); + assign(test_msg_.tow, 100); + assign(test_msg_.vdop, 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDops, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDops); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops, sizeof(msg->dops)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDops); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x4f4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_dops_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_dops_t &lesser, + const sbp_msg_dops_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDops, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDops, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgDops, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgDops, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgDops0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { 85, 8, 2, 66, 0, 15, 100, 0, 0, 0, 2, 0, 6, 0, 5, 0, 5, 0, 5, 0, 0, 244, 4, }; + uint8_t encoded_payload_[15] = { + 100, 0, 0, 0, 2, 0, 6, 0, 5, 0, 5, 0, 5, 0, 0, + }; +}; - sbp_msg_dops_t test_msg{}; - test_msg.flags = 0; - test_msg.gdop = 2; - test_msg.hdop = 5; - test_msg.pdop = 6; - test_msg.tdop = 5; - test_msg.tow = 100; - test_msg.vdop = 5; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.gdop, 2) - << "incorrect value for last_msg_.gdop, expected 2, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 5) - << "incorrect value for last_msg_.hdop, expected 5, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 6) - << "incorrect value for last_msg_.pdop, expected 6, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 5) - << "incorrect value for last_msg_.tdop, expected 5, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 100) - << "incorrect value for last_msg_.tow, expected 100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 5) - << "incorrect value for last_msg_.vdop, expected 5, is " - << last_msg_.vdop; +TEST_F(Testauto_check_sbp_navigation_MsgDops0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDops, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_dops_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDops, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ(sbp_msg_dops_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDops0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ(sbp_msg_dops_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDops, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_t msg{}; + + EXPECT_EQ(sbp_msg_dops_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDops0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_dops_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDops, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDops, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDops, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_t lesser = info.test_msg; + sbp_msg_dops_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDops); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_DOPS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDops, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDops0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDops, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgDopsDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgDopsDepA.cc index ee747da7a9..3ce2291a3c 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgDopsDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgDopsDepA.cc @@ -16,905 +16,6971 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgDopsDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgDopsDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA0() { + assign(test_msg_.gdop, 180); + assign(test_msg_.hdop, 160); + assign(test_msg_.pdop, 190); + assign(test_msg_.tdop, 170); + assign(test_msg_.tow, 2568200); + assign(test_msg_.vdop, 150); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xaa79; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 246, 215, 14, 8, 48, 39, 0, 180, + 0, 190, 0, 170, 0, 160, 0, 150, 0, 121, 170, + }; + uint8_t encoded_payload_[14] = { + 8, 48, 39, 0, 180, 0, 190, 0, 170, 0, 160, 0, 150, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA1() { + assign(test_msg_.gdop, 180); + assign(test_msg_.hdop, 160); + assign(test_msg_.pdop, 190); + assign(test_msg_.tdop, 170); + assign(test_msg_.tow, 2569200); + assign(test_msg_.vdop, 150); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xa94e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 246, 215, 14, 240, 51, 39, 0, 180, + 0, 190, 0, 170, 0, 160, 0, 150, 0, 78, 169, + }; + uint8_t encoded_payload_[14] = { + 240, 51, 39, 0, 180, 0, 190, 0, 170, 0, 160, 0, 150, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA2() { + assign(test_msg_.gdop, 180); + assign(test_msg_.hdop, 160); + assign(test_msg_.pdop, 190); + assign(test_msg_.tdop, 170); + assign(test_msg_.tow, 2570200); + assign(test_msg_.vdop, 150); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xda47; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 246, 215, 14, 216, 55, 39, 0, 180, + 0, 190, 0, 170, 0, 160, 0, 150, 0, 71, 218, + }; + uint8_t encoded_payload_[14] = { + 216, 55, 39, 0, 180, 0, 190, 0, 170, 0, 160, 0, 150, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA3() { + assign(test_msg_.gdop, 247); + assign(test_msg_.hdop, 273); + assign(test_msg_.pdop, 215); + assign(test_msg_.tdop, 123); + assign(test_msg_.tow, 407084500); + assign(test_msg_.vdop, 44); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x15ce; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 195, 4, 14, 212, 157, 67, 24, 247, + 0, 215, 0, 123, 0, 17, 1, 44, 0, 206, 21, + }; + uint8_t encoded_payload_[14] = { + 212, 157, 67, 24, 247, 0, 215, 0, 123, 0, 17, 1, 44, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA4() { + assign(test_msg_.gdop, 65535); + assign(test_msg_.hdop, 0); + assign(test_msg_.pdop, 65535); + assign(test_msg_.tdop, 0); + assign(test_msg_.tow, 0); + assign(test_msg_.vdop, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xc92; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 195, 4, 14, 0, 0, 0, 0, 255, + 255, 255, 255, 0, 0, 0, 0, 0, 0, 146, 12, + }; + uint8_t encoded_payload_[14] = { + 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA5() { + assign(test_msg_.gdop, 348); + assign(test_msg_.hdop, 637); + assign(test_msg_.pdop, 312); + assign(test_msg_.tdop, 155); + assign(test_msg_.tow, 407152000); + assign(test_msg_.vdop, 113); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x5d81; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 195, 4, 14, 128, 165, 68, 24, 92, + 1, 56, 1, 155, 0, 125, 2, 113, 0, 129, 93, + }; + uint8_t encoded_payload_[14] = { + 128, 165, 68, 24, 92, 1, 56, 1, 155, 0, 125, 2, 113, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgDopsDepA6() { + assign(test_msg_.gdop, 348); + assign(test_msg_.hdop, 637); + assign(test_msg_.pdop, 311); + assign(test_msg_.tdop, 155); + assign(test_msg_.tow, 407153000); + assign(test_msg_.vdop, 113); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x80d1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 195, 4, 14, 104, 169, 68, 24, 92, + 1, 55, 1, 155, 0, 125, 2, 113, 0, 209, 128, + }; + uint8_t encoded_payload_[14] = { + 104, 169, 68, 24, 92, 1, 55, 1, 155, 0, 125, 2, 113, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA7 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgDopsDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgDopsDepA7() { + assign(test_msg_.gdop, 348); + assign(test_msg_.hdop, 637); + assign(test_msg_.pdop, 311); + assign(test_msg_.tdop, 155); + assign(test_msg_.tow, 407154000); + assign(test_msg_.vdop, 112); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x61e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 6, 2, 195, 4, 14, 80, 173, 68, 24, 92, + 1, 55, 1, 155, 0, 125, 2, 112, 0, 30, 6, + }; + uint8_t encoded_payload_[14] = { + 80, 173, 68, 24, 92, 1, 55, 1, 155, 0, 125, 2, 112, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 246, 215, 14, 8, 48, 39, 0, 180, - 0, 190, 0, 170, 0, 160, 0, 150, 0, 121, 170, - }; +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 180; - test_msg.hdop = 160; - test_msg.pdop = 190; - test_msg.tdop = 170; - test_msg.tow = 2568200; - test_msg.vdop = 150; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 180) - << "incorrect value for last_msg_.gdop, expected 180, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 160) - << "incorrect value for last_msg_.hdop, expected 160, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 190) - << "incorrect value for last_msg_.pdop, expected 190, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 170) - << "incorrect value for last_msg_.tdop, expected 170, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 2568200) - << "incorrect value for last_msg_.tow, expected 2568200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 150) - << "incorrect value for last_msg_.vdop, expected 150, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 246, 215, 14, 240, 51, 39, 0, 180, - 0, 190, 0, 170, 0, 160, 0, 150, 0, 78, 169, - }; +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 180; - test_msg.hdop = 160; - test_msg.pdop = 190; - test_msg.tdop = 170; - test_msg.tow = 2569200; - test_msg.vdop = 150; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 180) - << "incorrect value for last_msg_.gdop, expected 180, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 160) - << "incorrect value for last_msg_.hdop, expected 160, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 190) - << "incorrect value for last_msg_.pdop, expected 190, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 170) - << "incorrect value for last_msg_.tdop, expected 170, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 2569200) - << "incorrect value for last_msg_.tow, expected 2569200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 150) - << "incorrect value for last_msg_.vdop, expected 150, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgDopsDepA8 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgDopsDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgDopsDepA8() { + assign(test_msg_.gdop, 348); + assign(test_msg_.hdop, 637); + assign(test_msg_.pdop, 311); + assign(test_msg_.tdop, 155); + assign(test_msg_.tow, 407155000); + assign(test_msg_.vdop, 112); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 246, 215, 14, 216, 55, 39, 0, 180, - 0, 190, 0, 170, 0, 160, 0, 150, 0, 71, 218, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 180; - test_msg.hdop = 160; - test_msg.pdop = 190; - test_msg.tdop = 170; - test_msg.tow = 2570200; - test_msg.vdop = 150; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 180) - << "incorrect value for last_msg_.gdop, expected 180, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 160) - << "incorrect value for last_msg_.hdop, expected 160, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 190) - << "incorrect value for last_msg_.pdop, expected 190, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 170) - << "incorrect value for last_msg_.tdop, expected 170, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 2570200) - << "incorrect value for last_msg_.tow, expected 2570200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 150) - << "incorrect value for last_msg_.vdop, expected 150, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 195, 4, 14, 212, 157, 67, 24, 247, - 0, 215, 0, 123, 0, 17, 1, 44, 0, 206, 21, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 247; - test_msg.hdop = 273; - test_msg.pdop = 215; - test_msg.tdop = 123; - test_msg.tow = 407084500; - test_msg.vdop = 44; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 247) - << "incorrect value for last_msg_.gdop, expected 247, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 273) - << "incorrect value for last_msg_.hdop, expected 273, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 215) - << "incorrect value for last_msg_.pdop, expected 215, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 123) - << "incorrect value for last_msg_.tdop, expected 123, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 44) - << "incorrect value for last_msg_.vdop, expected 44, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 195, 4, 14, 0, 0, 0, 0, 255, - 255, 255, 255, 0, 0, 0, 0, 0, 0, 146, 12, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 65535; - test_msg.hdop = 0; - test_msg.pdop = 65535; - test_msg.tdop = 0; - test_msg.tow = 0; - test_msg.vdop = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 65535) - << "incorrect value for last_msg_.gdop, expected 65535, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 0) - << "incorrect value for last_msg_.hdop, expected 0, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 65535) - << "incorrect value for last_msg_.pdop, expected 65535, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 0) - << "incorrect value for last_msg_.tdop, expected 0, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 0) - << "incorrect value for last_msg_.tow, expected 0, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 0) - << "incorrect value for last_msg_.vdop, expected 0, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 195, 4, 14, 128, 165, 68, 24, 92, - 1, 56, 1, 155, 0, 125, 2, 113, 0, 129, 93, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 348; - test_msg.hdop = 637; - test_msg.pdop = 312; - test_msg.tdop = 155; - test_msg.tow = 407152000; - test_msg.vdop = 113; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 348) - << "incorrect value for last_msg_.gdop, expected 348, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 637) - << "incorrect value for last_msg_.hdop, expected 637, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 312) - << "incorrect value for last_msg_.pdop, expected 312, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 155) - << "incorrect value for last_msg_.tdop, expected 155, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 407152000) - << "incorrect value for last_msg_.tow, expected 407152000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 113) - << "incorrect value for last_msg_.vdop, expected 113, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 195, 4, 14, 104, 169, 68, 24, 92, - 1, 55, 1, 155, 0, 125, 2, 113, 0, 209, 128, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dops_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 348; - test_msg.hdop = 637; - test_msg.pdop = 311; - test_msg.tdop = 155; - test_msg.tow = 407153000; - test_msg.vdop = 113; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 348) - << "incorrect value for last_msg_.gdop, expected 348, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 637) - << "incorrect value for last_msg_.hdop, expected 637, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 311) - << "incorrect value for last_msg_.pdop, expected 311, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 155) - << "incorrect value for last_msg_.tdop, expected 155, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 407153000) - << "incorrect value for last_msg_.tow, expected 407153000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 113) - << "incorrect value for last_msg_.vdop, expected 113, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDopsDepA, &CHandler::callback_static, + this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 6, 2, 195, 4, 14, 80, 173, 68, 24, 92, - 1, 55, 1, 155, 0, 125, 2, 112, 0, 30, 6, + struct Output final { + uint16_t sender_id; + sbp_msg_dops_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDopsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dops_dep_a, sizeof(msg->dops_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 348; - test_msg.hdop = 637; - test_msg.pdop = 311; - test_msg.tdop = 155; - test_msg.tow = 407154000; - test_msg.vdop = 112; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 348) - << "incorrect value for last_msg_.gdop, expected 348, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 637) - << "incorrect value for last_msg_.hdop, expected 637, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 311) - << "incorrect value for last_msg_.pdop, expected 311, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 155) - << "incorrect value for last_msg_.tdop, expected 155, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 407154000) - << "incorrect value for last_msg_.tow, expected 407154000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 112) - << "incorrect value for last_msg_.vdop, expected 112, is " - << last_msg_.vdop; -} -class Test_auto_check_sbp_navigation_MsgDopsDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgDopsDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + struct TestMsgInfo { + sbp_msg_dops_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dops_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDopsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4346; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dops_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dops_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_dops_dep_a_t &lesser, + const sbp_msg_dops_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dops_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dops_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dops_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDopsDepA, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgDopsDepA8, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_dops_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { 85, 6, 2, 195, 4, 14, 56, 177, 68, 24, 92, 1, 55, 1, 155, 0, 125, 2, 112, 0, 70, 67, }; + uint8_t encoded_payload_[14] = { + 56, 177, 68, 24, 92, 1, 55, 1, 155, 0, 125, 2, 112, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dops_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDopsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgDopsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_dops_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_dops_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDopsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_dops_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dops_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDopsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gdop, greater.gdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tdop, greater.tdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_dops_dep_a_t lesser = info.test_msg; + sbp_msg_dops_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgDopsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DOPS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dops_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dops_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dops_dep_a, info.test_msg); - sbp_msg_dops_dep_a_t test_msg{}; - test_msg.gdop = 348; - test_msg.hdop = 637; - test_msg.pdop = 311; - test_msg.tdop = 155; - test_msg.tow = 407155000; - test_msg.vdop = 112; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gdop, 348) - << "incorrect value for last_msg_.gdop, expected 348, is " - << last_msg_.gdop; - EXPECT_EQ(last_msg_.hdop, 637) - << "incorrect value for last_msg_.hdop, expected 637, is " - << last_msg_.hdop; - EXPECT_EQ(last_msg_.pdop, 311) - << "incorrect value for last_msg_.pdop, expected 311, is " - << last_msg_.pdop; - EXPECT_EQ(last_msg_.tdop, 155) - << "incorrect value for last_msg_.tdop, expected 155, is " - << last_msg_.tdop; - EXPECT_EQ(last_msg_.tow, 407155000) - << "incorrect value for last_msg_.tow, expected 407155000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vdop, 112) - << "incorrect value for last_msg_.vdop, expected 112, is " - << last_msg_.vdop; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dops_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dops_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDopsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgDopsDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgDopsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTime.cc b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTime.cc index 40f929f23d..a68096fb6e 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTime.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTime.cc @@ -16,461 +16,3799 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgGPSTime0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgGPSTime0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTime0() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 166900); + assign(test_msg_.tow, 326825000); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time, sizeof(msg->gps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTime); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x9822; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_t &lesser, + const sbp_msg_gps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 2, 1, 211, 136, 11, 128, 7, 40, 244, + 122, 19, 244, 139, 2, 0, 0, 34, 152, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 40, 244, 122, 19, 244, 139, 2, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GPS_TIME"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTime1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTime1() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 256638); + assign(test_msg_.tow, 326825500); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time, sizeof(msg->gps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTime); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x341; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_t &lesser, + const sbp_msg_gps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 2, 1, 211, 136, 11, 128, 7, 28, 246, + 122, 19, 126, 234, 3, 0, 0, 65, 3, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 28, 246, 122, 19, 126, 234, 3, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GPS_TIME"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTime2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTime2() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 265345); + assign(test_msg_.tow, 326826000); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time, sizeof(msg->gps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTime); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x540c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_t &lesser, + const sbp_msg_gps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 2, 1, 211, 136, 11, 128, 7, 16, 248, + 122, 19, 129, 12, 4, 0, 0, 12, 84, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 16, 248, 122, 19, 129, 12, 4, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GPS_TIME"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTime3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTime0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTime3() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 314505); + assign(test_msg_.tow, 326826500); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time, sizeof(msg->gps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTime); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xa532; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_t &lesser, + const sbp_msg_gps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 2, 1, 211, 136, 11, 128, 7, 4, 250, + 122, 19, 137, 204, 4, 0, 0, 50, 165, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 4, 250, 122, 19, 137, 204, 4, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTime0, Test) { - uint8_t encoded_frame[] = { - 85, 2, 1, 211, 136, 11, 128, 7, 40, 244, - 122, 19, 244, 139, 2, 0, 0, 34, 152, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_gps_time_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 166900; - test_msg.tow = 326825000; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 166900) - << "incorrect value for last_msg_.ns_residual, expected 166900, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTime1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTime1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GPS_TIME"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTime1, Test) { - uint8_t encoded_frame[] = { - 85, 2, 1, 211, 136, 11, 128, 7, 28, 246, - 122, 19, 126, 234, 3, 0, 0, 65, 3, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_gps_time_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 256638; - test_msg.tow = 326825500; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 256638) - << "incorrect value for last_msg_.ns_residual, expected 256638, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326825500) - << "incorrect value for last_msg_.tow, expected 326825500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTime2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTime2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTime2, Test) { - uint8_t encoded_frame[] = { - 85, 2, 1, 211, 136, 11, 128, 7, 16, 248, - 122, 19, 129, 12, 4, 0, 0, 12, 84, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_gps_time_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 265345; - test_msg.tow = 326826000; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 265345) - << "incorrect value for last_msg_.ns_residual, expected 265345, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTime3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTime4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTime3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTime4() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 362933); + assign(test_msg_.tow, 326827000); + assign(test_msg_.wn, 1920); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTime3, Test) { - uint8_t encoded_frame[] = { - 85, 2, 1, 211, 136, 11, 128, 7, 4, 250, - 122, 19, 137, 204, 4, 0, 0, 50, 165, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_gps_time_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 314505; - test_msg.tow = 326826500; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 314505) - << "incorrect value for last_msg_.ns_residual, expected 314505, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326826500) - << "incorrect value for last_msg_.tow, expected 326826500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTime4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTime4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time, sizeof(msg->gps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTime); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x21b4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_gps_time_t &lesser, + const sbp_msg_gps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTime4, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { 85, 2, 1, 211, 136, 11, 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, 180, 33, }; + uint8_t encoded_payload_[11] = { + 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ( + sbp_msg_gps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_gps_time_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 362933; - test_msg.tow = 326827000; - test_msg.wn = 1920; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_t lesser = info.test_msg; + sbp_msg_gps_time_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GPS_TIME"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + sbp::State state{}; + state.set_reader(&reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 362933) - << "incorrect value for last_msg_.ns_residual, expected 362933, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTime4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeDepA.cc index 4b5e38f733..43e6d45a7b 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeDepA.cc @@ -16,1000 +16,8521 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgGPSTimeDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA0() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 0); + assign(test_msg_.tow, 2567800); + assign(test_msg_.wn, 1787); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x2485; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 246, 215, 11, 251, 6, 120, 46, 39, 0, 0, 0, 0, 0, 0, 133, 36, + }; + uint8_t encoded_payload_[11] = { + 251, 6, 120, 46, 39, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA1() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 0); + assign(test_msg_.tow, 2567900); + assign(test_msg_.wn, 1787); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xa024; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 246, 215, 11, 251, 6, 220, 46, 39, 0, 0, 0, 0, 0, 0, 36, 160, + }; + uint8_t encoded_payload_[11] = { + 251, 6, 220, 46, 39, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA2() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 0); + assign(test_msg_.tow, 2568000); + assign(test_msg_.wn, 1787); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xbeab; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 246, 215, 11, 251, 6, 64, 47, 39, 0, 0, 0, 0, 0, 0, 171, 190, + }; + uint8_t encoded_payload_[11] = { + 251, 6, 64, 47, 39, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA3() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 0); + assign(test_msg_.tow, 2568100); + assign(test_msg_.wn, 1787); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x65d3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 246, 215, 11, 251, 6, 164, 47, 39, 0, 0, 0, 0, 0, 0, 211, 101, + }; + uint8_t encoded_payload_[11] = { + 251, 6, 164, 47, 39, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA4() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 0); + assign(test_msg_.tow, 2568200); + assign(test_msg_.wn, 1787); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x2cfb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 246, 215, 11, 251, 6, 8, 48, 39, 0, 0, 0, 0, 0, 0, 251, 44, + }; + uint8_t encoded_payload_[11] = { + 251, 6, 8, 48, 39, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA5() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, -224401); + assign(test_msg_.tow, 407084500); + assign(test_msg_.wn, 1838); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xbed7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 195, 4, 11, 46, 7, 212, 157, + 67, 24, 111, 147, 252, 255, 0, 215, 190, + }; + uint8_t encoded_payload_[11] = { + 46, 7, 212, 157, 67, 24, 111, 147, 252, 255, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA6() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 223085); + assign(test_msg_.tow, 407084600); + assign(test_msg_.wn, 1838); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x5986; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 195, 4, 11, 46, 7, 56, 158, 67, 24, 109, 103, 3, 0, 0, 134, 89, + }; + uint8_t encoded_payload_[11] = { + 46, 7, 56, 158, 67, 24, 109, 103, 3, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA7 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA7() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, -222999); + assign(test_msg_.tow, 407084700); + assign(test_msg_.wn, 1838); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xf1ce; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 195, 4, 11, 46, 7, 156, 158, + 67, 24, 233, 152, 252, 255, 0, 206, 241, + }; + uint8_t encoded_payload_[11] = { + 46, 7, 156, 158, 67, 24, 233, 152, 252, 255, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA8 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeDepA8() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 236272); + assign(test_msg_.tow, 407084800); + assign(test_msg_.wn, 1838); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6293; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 195, 4, 11, 46, 7, 0, 159, 67, 24, 240, 154, 3, 0, 0, 147, 98, + }; + uint8_t encoded_payload_[11] = { + 46, 7, 0, 159, 67, 24, 240, 154, 3, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA9 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTimeDepA9() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, -236144); + assign(test_msg_.tow, 407084900); + assign(test_msg_.wn, 1838); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x98ba; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 0, 1, 195, 4, 11, 46, 7, 100, 159, + 67, 24, 144, 101, 252, 255, 0, 186, 152, + }; + uint8_t encoded_payload_[11] = { + 46, 7, 100, 159, 67, 24, 144, 101, 252, 255, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 246, 215, 11, 251, 6, 120, 46, 39, 0, 0, 0, 0, 0, 0, 133, 36, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 0; - test_msg.tow = 2567800; - test_msg.wn = 1787; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 0) - << "incorrect value for last_msg_.ns_residual, expected 0, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1787) - << "incorrect value for last_msg_.wn, expected 1787, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 246, 215, 11, 251, 6, 220, 46, 39, 0, 0, 0, 0, 0, 0, 36, 160, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 0; - test_msg.tow = 2567900; - test_msg.wn = 1787; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 0) - << "incorrect value for last_msg_.ns_residual, expected 0, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1787) - << "incorrect value for last_msg_.wn, expected 1787, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 246, 215, 11, 251, 6, 64, 47, 39, 0, 0, 0, 0, 0, 0, 171, 190, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 0; - test_msg.tow = 2568000; - test_msg.wn = 1787; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 0) - << "incorrect value for last_msg_.ns_residual, expected 0, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 2568000) - << "incorrect value for last_msg_.tow, expected 2568000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1787) - << "incorrect value for last_msg_.wn, expected 1787, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeDepA10 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTimeDepA10() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, -334131); + assign(test_msg_.tow, 407151150); + assign(test_msg_.wn, 1838); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 246, 215, 11, 251, 6, 164, 47, 39, 0, 0, 0, 0, 0, 0, 211, 101, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 0; - test_msg.tow = 2568100; - test_msg.wn = 1787; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 0) - << "incorrect value for last_msg_.ns_residual, expected 0, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 2568100) - << "incorrect value for last_msg_.tow, expected 2568100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1787) - << "incorrect value for last_msg_.wn, expected 1787, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 246, 215, 11, 251, 6, 8, 48, 39, 0, 0, 0, 0, 0, 0, 251, 44, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 0; - test_msg.tow = 2568200; - test_msg.wn = 1787; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 0) - << "incorrect value for last_msg_.ns_residual, expected 0, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 2568200) - << "incorrect value for last_msg_.tow, expected 2568200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1787) - << "incorrect value for last_msg_.wn, expected 1787, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 195, 4, 11, 46, 7, 212, 157, - 67, 24, 111, 147, 252, 255, 0, 215, 190, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = -224401; - test_msg.tow = 407084500; - test_msg.wn = 1838; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, -224401) - << "incorrect value for last_msg_.ns_residual, expected -224401, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 195, 4, 11, 46, 7, 56, 158, 67, 24, 109, 103, 3, 0, 0, 134, 89, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 223085; - test_msg.tow = 407084600; - test_msg.wn = 1838; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 223085) - << "incorrect value for last_msg_.ns_residual, expected 223085, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407084600) - << "incorrect value for last_msg_.tow, expected 407084600, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 195, 4, 11, 46, 7, 156, 158, - 67, 24, 233, 152, 252, 255, 0, 206, 241, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = -222999; - test_msg.tow = 407084700; - test_msg.wn = 1838; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, -222999) - << "incorrect value for last_msg_.ns_residual, expected -222999, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407084700) - << "incorrect value for last_msg_.tow, expected 407084700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeDepA, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 195, 4, 11, 46, 7, 0, 159, 67, 24, 240, 154, 3, 0, 0, 147, 98, + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_dep_a, + sizeof(msg->gps_time_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 236272; - test_msg.tow = 407084800; - test_msg.wn = 1838; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 236272) - << "incorrect value for last_msg_.ns_residual, expected 236272, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407084800) - << "incorrect value for last_msg_.tow, expected 407084800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_gps_time_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 0, 1, 195, 4, 11, 46, 7, 100, 159, - 67, 24, 144, 101, 252, 255, 0, 186, 152, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = -236144; - test_msg.tow = 407084900; - test_msg.wn = 1838; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, -236144) - << "incorrect value for last_msg_.ns_residual, expected -236144, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407084900) - << "incorrect value for last_msg_.tow, expected 407084900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe10b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_gps_time_dep_a_t &lesser, + const sbp_msg_gps_time_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeDepA10, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_dep_a_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { 85, 0, 1, 195, 4, 11, 46, 7, 46, 162, 68, 24, 205, 230, 250, 255, 0, 11, 225, }; + uint8_t encoded_payload_[11] = { + 46, 7, 46, 162, 68, 24, 205, 230, 250, 255, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_msg_gps_time_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_gps_time_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = -334131; - test_msg.tow = 407151150; - test_msg.wn = 1838; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_dep_a_t lesser = info.test_msg; + sbp_msg_gps_time_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gps_time_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + sbp::State state{}; + state.set_reader(&reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, -334131) - << "incorrect value for last_msg_.ns_residual, expected -334131, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 407151150) - << "incorrect value for last_msg_.tow, expected 407151150, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1838) - << "incorrect value for last_msg_.wn, expected 1838, is " << last_msg_.wn; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeGNSS.cc b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeGNSS.cc index 3173164525..16af5d04b7 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeGNSS.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgGPSTimeGNSS.cc @@ -16,461 +16,3869 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgGPSTimeGNSS0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgGPSTimeGNSS0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeGNSS0() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 166900); + assign(test_msg_.tow, 326825000); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_gnss, + sizeof(msg->gps_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeGnss); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x5899; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_gnss_t &lesser, + const sbp_msg_gps_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 4, 1, 211, 136, 11, 128, 7, 40, 244, + 122, 19, 244, 139, 2, 0, 0, 153, 88, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 40, 244, 122, 19, 244, 139, 2, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeGNSS1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeGNSS1() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 256638); + assign(test_msg_.tow, 326825500); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_gnss, + sizeof(msg->gps_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeGnss); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xc3fa; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_gnss_t &lesser, + const sbp_msg_gps_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 4, 1, 211, 136, 11, 128, 7, 28, 246, + 122, 19, 126, 234, 3, 0, 0, 250, 195, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 28, 246, 122, 19, 126, 234, 3, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeGNSS2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgGPSTimeGNSS2() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 265345); + assign(test_msg_.tow, 326826000); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_gnss, + sizeof(msg->gps_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeGnss); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x94b7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_gnss_t &lesser, + const sbp_msg_gps_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 4, 1, 211, 136, 11, 128, 7, 16, 248, + 122, 19, 129, 12, 4, 0, 0, 183, 148, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 16, 248, 122, 19, 129, 12, 4, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeGNSS3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTimeGNSS0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTimeGNSS3() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 314505); + assign(test_msg_.tow, 326826500); + assign(test_msg_.wn, 1920); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_gnss, + sizeof(msg->gps_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeGnss); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x6589; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gps_time_gnss_t &lesser, + const sbp_msg_gps_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 4, 1, 211, 136, 11, 128, 7, 4, 250, + 122, 19, 137, 204, 4, 0, 0, 137, 101, + }; + uint8_t encoded_payload_[11] = { + 128, 7, 4, 250, 122, 19, 137, 204, 4, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeGNSS0, Test) { - uint8_t encoded_frame[] = { - 85, 4, 1, 211, 136, 11, 128, 7, 40, 244, - 122, 19, 244, 139, 2, 0, 0, 153, 88, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_gps_time_gnss_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 166900; - test_msg.tow = 326825000; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 166900) - << "incorrect value for last_msg_.ns_residual, expected 166900, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeGNSS1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeGNSS1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_GNSS"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeGNSS1, Test) { - uint8_t encoded_frame[] = { - 85, 4, 1, 211, 136, 11, 128, 7, 28, 246, - 122, 19, 126, 234, 3, 0, 0, 250, 195, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_gps_time_gnss_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 256638; - test_msg.tow = 326825500; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 256638) - << "incorrect value for last_msg_.ns_residual, expected 256638, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326825500) - << "incorrect value for last_msg_.tow, expected 326825500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeGNSS2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeGNSS2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeGNSS2, Test) { - uint8_t encoded_frame[] = { - 85, 4, 1, 211, 136, 11, 128, 7, 16, 248, - 122, 19, 129, 12, 4, 0, 0, 183, 148, - }; +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_gps_time_gnss_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 265345; - test_msg.tow = 326826000; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 265345) - << "incorrect value for last_msg_.ns_residual, expected 265345, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeGNSS3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgGPSTimeGNSS4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgGPSTimeGNSS3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgGPSTimeGNSS4() { + assign(test_msg_.flags, 0); + assign(test_msg_.ns_residual, 362933); + assign(test_msg_.tow, 326827000); + assign(test_msg_.wn, 1920); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeGNSS3, Test) { - uint8_t encoded_frame[] = { - 85, 4, 1, 211, 136, 11, 128, 7, 4, 250, - 122, 19, 137, 204, 4, 0, 0, 137, 101, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_gps_time_gnss_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 314505; - test_msg.tow = 326826500; - test_msg.wn = 1920; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 314505) - << "incorrect value for last_msg_.ns_residual, expected 314505, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326826500) - << "incorrect value for last_msg_.tow, expected 326826500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; -} -class Test_auto_check_sbp_navigation_MsgGPSTimeGNSS4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgGPSTimeGNSS4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gps_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGpsTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gps_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGpsTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gps_time_gnss, + sizeof(msg->gps_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gps_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gps_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGpsTimeGnss); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xe10f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_gps_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_gps_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_gps_time_gnss_t &lesser, + const sbp_msg_gps_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gps_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gps_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gps_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGpsTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgGPSTimeGNSS4, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gps_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { 85, 4, 1, 211, 136, 11, 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, 15, 225, }; + uint8_t encoded_payload_[11] = { + 128, 7, 248, 251, 122, 19, 181, 137, 5, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gps_time_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGpsTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_gps_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGpsTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gps_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_gps_time_gnss_t test_msg{}; - test_msg.flags = 0; - test_msg.ns_residual = 362933; - test_msg.tow = 326827000; - test_msg.wn = 1920; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gps_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGpsTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns_residual, greater.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gps_time_gnss_t lesser = info.test_msg; + sbp_msg_gps_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGpsTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GPS_TIME_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gps_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gps_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gps_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gps_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gps_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + sbp::State state{}; + state.set_reader(&reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.ns_residual, 362933) - << "incorrect value for last_msg_.ns_residual, expected 362933, is " - << last_msg_.ns_residual; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 1920) - << "incorrect value for last_msg_.wn, expected 1920, is " << last_msg_.wn; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGpsTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgGPSTimeGNSS4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGpsTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEF.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEF.cc index 6fa02cf9d5..1b4acb8be4 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEF.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEF.cc @@ -16,426 +16,3138 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosECEF0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosECEF0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEF0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.x, -2684269.0326572997); + assign(test_msg_.y, -4316646.751816); + assign(test_msg_.z, 3839646.7095350414); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef, sizeof(msg->pos_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x654; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_t &lesser, + const sbp_msg_pos_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 9, 2, 211, 136, 32, 16, 248, 122, 19, 73, 29, 46, 132, + 182, 122, 68, 193, 219, 192, 29, 176, 121, 119, 80, 193, 83, 11, + 210, 90, 79, 75, 77, 65, 0, 0, 15, 2, 84, 6, + }; + uint8_t encoded_payload_[32] = { + 16, 248, 122, 19, 73, 29, 46, 132, 182, 122, 68, + 193, 219, 192, 29, 176, 121, 119, 80, 193, 83, 11, + 210, 90, 79, 75, 77, 65, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEF1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEF1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.x, -2684269.064252186); + assign(test_msg_.y, -4316646.762264892); + assign(test_msg_.z, 3839646.463913912); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef, sizeof(msg->pos_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xd893; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_t &lesser, + const sbp_msg_pos_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 9, 2, 211, 136, 32, 248, 251, 122, 19, 103, 106, 57, 136, + 182, 122, 68, 193, 176, 242, 200, 176, 121, 119, 80, 193, 244, 135, + 97, 59, 79, 75, 77, 65, 0, 0, 15, 2, 147, 216, + }; + uint8_t encoded_payload_[32] = { + 248, 251, 122, 19, 103, 106, 57, 136, 182, 122, 68, + 193, 176, 242, 200, 176, 121, 119, 80, 193, 244, 135, + 97, 59, 79, 75, 77, 65, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEF2 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEF0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEF2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326828000); + assign(test_msg_.x, -2684269.4292816394); + assign(test_msg_.y, -4316647.118271949); + assign(test_msg_.z, 3839646.124909738); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef, sizeof(msg->pos_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xc928; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_t &lesser, + const sbp_msg_pos_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 9, 2, 211, 136, 32, 224, 255, 122, 19, 101, 179, 242, 182, + 182, 122, 68, 193, 130, 196, 145, 199, 121, 119, 80, 193, 212, 10, + 253, 15, 79, 75, 77, 65, 0, 0, 15, 2, 40, 201, + }; + uint8_t encoded_payload_[32] = { + 224, 255, 122, 19, 101, 179, 242, 182, 182, 122, 68, + 193, 130, 196, 145, 199, 121, 119, 80, 193, 212, 10, + 253, 15, 79, 75, 77, 65, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_ECEF"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEF0, Test) { - uint8_t encoded_frame[] = { - 85, 9, 2, 211, 136, 32, 16, 248, 122, 19, 73, 29, 46, 132, - 182, 122, 68, 193, 219, 192, 29, 176, 121, 119, 80, 193, 83, 11, - 210, 90, 79, 75, 77, 65, 0, 0, 15, 2, 84, 6, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_pos_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 2; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.x = -2684269.0326572997; - test_msg.y = -4316646.751816; - test_msg.z = 3839646.7095350414; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2684269.03266 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2684269.03266, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4316646.75182 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4316646.75182, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3839646.70954 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3839646.70954, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEF1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEF1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEF1, Test) { - uint8_t encoded_frame[] = { - 85, 9, 2, 211, 136, 32, 248, 251, 122, 19, 103, 106, 57, 136, - 182, 122, 68, 193, 176, 242, 200, 176, 121, 119, 80, 193, 244, 135, - 97, 59, 79, 75, 77, 65, 0, 0, 15, 2, 147, 216, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); - sbp_msg_pos_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 2; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.x = -2684269.064252186; - test_msg.y = -4316646.762264892; - test_msg.z = 3839646.463913912; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2684269.06425 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2684269.06425, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4316646.76226 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4316646.76226, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3839646.46391 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3839646.46391, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEF2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + state.process_message(info.sender_id, SbpMsgPosEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEF3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEF2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEF3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326829000); + assign(test_msg_.x, -2684269.683741399); + assign(test_msg_.y, -4316647.3623821335); + assign(test_msg_.z, 3839645.90179852); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEF2, Test) { - uint8_t encoded_frame[] = { - 85, 9, 2, 211, 136, 32, 224, 255, 122, 19, 101, 179, 242, 182, - 182, 122, 68, 193, 130, 196, 145, 199, 121, 119, 80, 193, 212, 10, - 253, 15, 79, 75, 77, 65, 0, 0, 15, 2, 40, 201, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_pos_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 2; - test_msg.n_sats = 15; - test_msg.tow = 326828000; - test_msg.x = -2684269.4292816394; - test_msg.y = -4316647.118271949; - test_msg.z = 3839646.124909738; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326828000) - << "incorrect value for last_msg_.tow, expected 326828000, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2684269.42928 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2684269.42928, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4316647.11827 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4316647.11827, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3839646.12491 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3839646.12491, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEF3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEF3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef, sizeof(msg->pos_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x56bb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_ecef_t &lesser, + const sbp_msg_pos_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEF3, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { 85, 9, 2, 211, 136, 32, 200, 3, 123, 19, 146, 214, 132, 215, 182, 122, 68, 193, 213, 68, 49, 215, 121, 119, 80, 193, 71, 34, 110, 243, 78, 75, 77, 65, 0, 0, 15, 2, 187, 86, }; + uint8_t encoded_payload_[32] = { + 200, 3, 123, 19, 146, 214, 132, 215, 182, 122, 68, + 193, 213, 68, 49, 215, 121, 119, 80, 193, 71, 34, + 110, 243, 78, 75, 77, 65, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ( + sbp_msg_pos_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_pos_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 2; - test_msg.n_sats = 15; - test_msg.tow = 326829000; - test_msg.x = -2684269.683741399; - test_msg.y = -4316647.3623821335; - test_msg.z = 3839645.90179852; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326829000) - << "incorrect value for last_msg_.tow, expected 326829000, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2684269.68374 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2684269.68374, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4316647.36238 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4316647.36238, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3839645.9018 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3839645.9018, is " - << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_t lesser = info.test_msg; + sbp_msg_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEF3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCov.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCov.cc index 684dd28174..3c05752689 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCov.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCov.cc @@ -16,128 +16,842 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosECEFCov0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosECEFCov0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEFCov0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEFCov0() { + assign(test_msg_.cov_x_x, 8.0); + assign(test_msg_.cov_x_y, 7.0); + assign(test_msg_.cov_x_z, 2.0); + assign(test_msg_.cov_y_y, 6.0); + assign(test_msg_.cov_y_z, 8.0); + assign(test_msg_.cov_z_z, 5.0); + assign(test_msg_.flags, 5); + assign(test_msg_.n_sats, 4); + assign(test_msg_.tow, 7); + assign(test_msg_.x, 6.0); + assign(test_msg_.y, 1.0); + assign(test_msg_.z, 4.0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_cov_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_cov_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefCov, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_cov_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefCov); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_cov, + sizeof(msg->pos_ecef_cov)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_cov_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_cov, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefCov); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xa7f9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 54; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_cov_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_cov_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_ecef_cov_t &lesser, + const sbp_msg_pos_ecef_cov_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cov_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cov_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cov_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cov_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefCov, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefCov, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefCov, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefCov, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFCov0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_cov_t test_msg_{}; + uint8_t encoded_frame_[54 + 8] = { 85, 20, 2, 66, 0, 54, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 64, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 16, 64, 0, 0, 0, 65, 0, 0, 224, 64, 0, 0, 0, 64, 0, 0, 192, 64, 0, 0, 0, 65, 0, 0, 160, 64, 4, 5, 249, 167, }; + uint8_t encoded_payload_[54] = { + 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 64, 0, 0, 0, 0, 0, 0, + 240, 63, 0, 0, 0, 0, 0, 0, 16, 64, 0, 0, 0, 65, 0, 0, 224, 64, + 0, 0, 0, 64, 0, 0, 192, 64, 0, 0, 0, 65, 0, 0, 160, 64, 4, 5, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_cov_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefCov, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefCov, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + for (uint8_t i = 0; i < 54; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_cov_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefCov, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_ecef_cov_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_pos_ecef_cov_t test_msg{}; - test_msg.cov_x_x = 8.0; - test_msg.cov_x_y = 7.0; - test_msg.cov_x_z = 2.0; - test_msg.cov_y_y = 6.0; - test_msg.cov_y_z = 8.0; - test_msg.cov_z_z = 5.0; - test_msg.flags = 5; - test_msg.n_sats = 4; - test_msg.tow = 7; - test_msg.x = 6.0; - test_msg.y = 1.0; - test_msg.z = 4.0; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_x_x * 100 - 8.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_x, expected 8.0, is " - << last_msg_.cov_x_x; - EXPECT_LT((last_msg_.cov_x_y * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_y, expected 7.0, is " - << last_msg_.cov_x_y; - EXPECT_LT((last_msg_.cov_x_z * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_z, expected 2.0, is " - << last_msg_.cov_x_z; - EXPECT_LT((last_msg_.cov_y_y * 100 - 6.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_y, expected 6.0, is " - << last_msg_.cov_y_y; - EXPECT_LT((last_msg_.cov_y_z * 100 - 8.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_z, expected 8.0, is " - << last_msg_.cov_y_z; - EXPECT_LT((last_msg_.cov_z_z * 100 - 5.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_z_z, expected 5.0, is " - << last_msg_.cov_z_z; - EXPECT_EQ(last_msg_.flags, 5) - << "incorrect value for last_msg_.flags, expected 5, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 4) - << "incorrect value for last_msg_.n_sats, expected 4, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 7) - << "incorrect value for last_msg_.tow, expected 7, is " << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - 6.0 * 100), 0.05) - << "incorrect value for last_msg_.x, expected 6.0, is " << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.y, expected 1.0, is " << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 4.0 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 4.0, is " << last_msg_.z; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_cov_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefCov, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_x, greater.cov_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_y, greater.cov_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_z, greater.cov_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_y, greater.cov_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_z, greater.cov_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_z_z, greater.cov_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefCov); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_COV"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_cov_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_cov_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_cov, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef_cov, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefCov, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCov0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefCov, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCovGNSS.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCovGNSS.cc index 84626db9c0..7891899c4b 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCovGNSS.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFCovGNSS.cc @@ -16,135 +16,856 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosECEFCovGNSS0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEFCovGNSS0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0() { + assign(test_msg_.cov_x_x, 0.009699014946818352); + assign(test_msg_.cov_x_y, 0.009086096659302711); + assign(test_msg_.cov_x_z, -0.006058753002434969); + assign(test_msg_.cov_y_y, 0.020321274176239967); + assign(test_msg_.cov_y_z, -0.009988312609493732); + assign(test_msg_.cov_z_z, 0.01487385667860508); + assign(test_msg_.flags, 4); + assign(test_msg_.n_sats, 18); + assign(test_msg_.tow, 501867800); + assign(test_msg_.x, -2694229.7079770807); + assign(test_msg_.y, -4264073.427345817); + assign(test_msg_.z, 3890655.013186158); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_cov_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_cov_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefCovGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_cov_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefCovGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_cov_gnss, + sizeof(msg->pos_ecef_cov_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_cov_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_cov_gnss, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefCovGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0x669f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 54; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_cov_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_cov_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_ecef_cov_gnss_t &lesser, + const sbp_msg_pos_ecef_cov_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_cov_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_cov_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefCovGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosEcefCovGnss, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosEcefCovGnss, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosEcefCovGnss, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFCovGNSS0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_cov_gnss_t test_msg_{}; + uint8_t encoded_frame_[54 + 8] = { 85, 52, 2, 0, 16, 54, 24, 229, 233, 29, 52, 254, 158, 218, 42, 142, 68, 193, 69, 162, 89, 91, 34, 68, 80, 193, 131, 21, 176, 129, 239, 174, 77, 65, 158, 232, 30, 60, 218, 221, 20, 60, 129, 136, 198, 187, 205, 120, 166, 60, 5, 166, 35, 188, 122, 177, 115, 60, 18, 4, 159, 102, }; + uint8_t encoded_payload_[54] = { + 24, 229, 233, 29, 52, 254, 158, 218, 42, 142, 68, 193, 69, 162, + 89, 91, 34, 68, 80, 193, 131, 21, 176, 129, 239, 174, 77, 65, + 158, 232, 30, 60, 218, 221, 20, 60, 129, 136, 198, 187, 205, 120, + 166, 60, 5, 166, 35, 188, 122, 177, 115, 60, 18, 4, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgPosEcefCovGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefCovGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + for (uint8_t i = 0; i < 54; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_cov_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefCovGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_pos_ecef_cov_gnss_t test_msg{}; - test_msg.cov_x_x = 0.009699014946818352; - test_msg.cov_x_y = 0.009086096659302711; - test_msg.cov_x_z = -0.006058753002434969; - test_msg.cov_y_y = 0.020321274176239967; - test_msg.cov_y_z = -0.009988312609493732; - test_msg.cov_z_z = 0.01487385667860508; - test_msg.flags = 4; - test_msg.n_sats = 18; - test_msg.tow = 501867800; - test_msg.x = -2694229.7079770807; - test_msg.y = -4264073.427345817; - test_msg.z = 3890655.013186158; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_x_x * 100 - 0.00969901494682 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_x, expected 0.00969901494682, is " - << last_msg_.cov_x_x; - EXPECT_LT((last_msg_.cov_x_y * 100 - 0.0090860966593 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_y, expected 0.0090860966593, is " - << last_msg_.cov_x_y; - EXPECT_LT((last_msg_.cov_x_z * 100 - -0.00605875300243 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_z, expected -0.00605875300243, " - "is " - << last_msg_.cov_x_z; - EXPECT_LT((last_msg_.cov_y_y * 100 - 0.0203212741762 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_y, expected 0.0203212741762, is " - << last_msg_.cov_y_y; - EXPECT_LT((last_msg_.cov_y_z * 100 - -0.00998831260949 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_z, expected -0.00998831260949, " - "is " - << last_msg_.cov_y_z; - EXPECT_LT((last_msg_.cov_z_z * 100 - 0.0148738566786 * 100), 0.05) - << "incorrect value for last_msg_.cov_z_z, expected 0.0148738566786, is " - << last_msg_.cov_z_z; - EXPECT_EQ(last_msg_.flags, 4) - << "incorrect value for last_msg_.flags, expected 4, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 18) - << "incorrect value for last_msg_.n_sats, expected 18, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2694229.70798 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2694229.70798, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4264073.42735 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4264073.42735, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3890655.01319 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3890655.01319, is " - << last_msg_.z; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_cov_gnss_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_x, greater.cov_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_y, greater.cov_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_z, greater.cov_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_y, greater.cov_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_z, greater.cov_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_z_z, greater.cov_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefCovGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_COV_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_cov_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_cov_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.pos_ecef_cov_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_cov_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefCovGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFCovGNSS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefCovGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFDepA.cc index 3ef6652a78..55e4820fe7 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFDepA.cc @@ -16,1161 +16,8786 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosECEFDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosECEFDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.x, -2700354.5912927105); + assign(test_msg_.y, -4292510.764041577); + assign(test_msg_.z, 3855357.977260149); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x560d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 246, 215, 32, 20, 46, 39, 0, 195, 122, 175, 75, + 33, 154, 68, 193, 164, 14, 230, 176, 231, 95, 80, 193, 78, 220, + 22, 253, 254, 105, 77, 65, 0, 0, 9, 0, 13, 86, + }; + uint8_t encoded_payload_[32] = { + 20, 46, 39, 0, 195, 122, 175, 75, 33, 154, 68, + 193, 164, 14, 230, 176, 231, 95, 80, 193, 78, 220, + 22, 253, 254, 105, 77, 65, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.x, -2700356.3285146747); + assign(test_msg_.y, -4292509.928737887); + assign(test_msg_.z, 3855357.5011712564); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8f4b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 246, 215, 32, 20, 46, 39, 0, 212, 196, 12, 42, + 34, 154, 68, 193, 9, 113, 112, 123, 231, 95, 80, 193, 54, 97, + 38, 192, 254, 105, 77, 65, 0, 0, 9, 1, 75, 143, + }; + uint8_t encoded_payload_[32] = { + 20, 46, 39, 0, 212, 196, 12, 42, 34, 154, 68, 193, 9, 113, 112, 123, + 231, 95, 80, 193, 54, 97, 38, 192, 254, 105, 77, 65, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.x, -2700357.485576801); + assign(test_msg_.y, -4292509.80414865); + assign(test_msg_.z, 3855356.517968082); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x71cc; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 246, 215, 32, 120, 46, 39, 0, 112, 97, 39, 190, + 34, 154, 68, 193, 230, 43, 119, 115, 231, 95, 80, 193, 50, 199, + 76, 66, 254, 105, 77, 65, 0, 0, 9, 0, 204, 113, + }; + uint8_t encoded_payload_[32] = { + 120, 46, 39, 0, 112, 97, 39, 190, 34, 154, 68, 193, 230, 43, 119, 115, + 231, 95, 80, 193, 50, 199, 76, 66, 254, 105, 77, 65, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 1); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.x, -2700356.0349524925); + assign(test_msg_.y, -4292510.187605589); + assign(test_msg_.z, 3855357.4185667858); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x4761; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 246, 215, 32, 120, 46, 39, 0, 194, 82, 121, 4, + 34, 154, 68, 193, 223, 186, 1, 140, 231, 95, 80, 193, 176, 152, + 147, 181, 254, 105, 77, 65, 0, 0, 9, 1, 97, 71, + }; + uint8_t encoded_payload_[32] = { + 120, 46, 39, 0, 194, 82, 121, 4, 34, 154, 68, 193, 223, 186, 1, 140, + 231, 95, 80, 193, 176, 152, 147, 181, 254, 105, 77, 65, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA4() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.x, -2700355.9913074784); + assign(test_msg_.y, -4292509.946935424); + assign(test_msg_.z, 3855359.0924900775); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x6207; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 246, 215, 32, 220, 46, 39, 0, 216, 41, 227, 254, + 33, 154, 68, 193, 9, 151, 154, 124, 231, 95, 80, 193, 1, 183, + 214, 139, 255, 105, 77, 65, 0, 0, 9, 0, 7, 98, + }; + uint8_t encoded_payload_[32] = { + 220, 46, 39, 0, 216, 41, 227, 254, 33, 154, 68, 193, 9, 151, 154, 124, + 231, 95, 80, 193, 1, 183, 214, 139, 255, 105, 77, 65, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA5() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084500); + assign(test_msg_.x, -2704376.0110433814); + assign(test_msg_.y, -4263209.753232954); + assign(test_msg_.z, 3884633.142084079); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x491; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 195, 4, 32, 212, 157, 67, 24, 153, 222, 105, 1, + 252, 161, 68, 193, 254, 247, 52, 112, 74, 67, 80, 193, 164, 207, + 47, 146, 44, 163, 77, 65, 0, 0, 8, 0, 145, 4, + }; + uint8_t encoded_payload_[32] = { + 212, 157, 67, 24, 153, 222, 105, 1, 252, 161, 68, + 193, 254, 247, 52, 112, 74, 67, 80, 193, 164, 207, + 47, 146, 44, 163, 77, 65, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA6() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084600); + assign(test_msg_.x, -2704375.9287024545); + assign(test_msg_.y, -4263208.610442672); + assign(test_msg_.z, 3884632.627157578); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x42f5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 195, 4, 32, 56, 158, 67, 24, 215, 184, 223, 246, + 251, 161, 68, 193, 36, 126, 17, 39, 74, 67, 80, 193, 19, 179, + 70, 80, 44, 163, 77, 65, 0, 0, 8, 0, 245, 66, + }; + uint8_t encoded_payload_[32] = { + 56, 158, 67, 24, 215, 184, 223, 246, 251, 161, 68, 193, 36, 126, 17, 39, + 74, 67, 80, 193, 19, 179, 70, 80, 44, 163, 77, 65, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA7 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA7() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084700); + assign(test_msg_.x, -2704375.162789617); + assign(test_msg_.y, -4263207.370641668); + assign(test_msg_.z, 3884631.282421521); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xdf05; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 195, 4, 32, 156, 158, 67, 24, 73, 74, 214, 148, + 251, 161, 68, 193, 213, 151, 184, 215, 73, 67, 80, 193, 110, 99, + 38, 164, 43, 163, 77, 65, 0, 0, 8, 0, 5, 223, + }; + uint8_t encoded_payload_[32] = { + 156, 158, 67, 24, 73, 74, 214, 148, 251, 161, 68, + 193, 213, 151, 184, 215, 73, 67, 80, 193, 110, 99, + 38, 164, 43, 163, 77, 65, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA8 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosECEFDepA8() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084800); + assign(test_msg_.x, -2704376.3549937834); + assign(test_msg_.y, -4263207.965250214); + assign(test_msg_.z, 3884632.1007095524); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xd48f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 195, 4, 32, 0, 159, 67, 24, 177, 111, 112, 45, + 252, 161, 68, 193, 213, 168, 198, 253, 73, 67, 80, 193, 245, 12, + 228, 12, 44, 163, 77, 65, 0, 0, 8, 0, 143, 212, + }; + uint8_t encoded_payload_[32] = { + 0, 159, 67, 24, 177, 111, 112, 45, 252, 161, 68, + 193, 213, 168, 198, 253, 73, 67, 80, 193, 245, 12, + 228, 12, 44, 163, 77, 65, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA9 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEFDepA9() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084900); + assign(test_msg_.x, -2704375.291287334); + assign(test_msg_.y, -4263207.314747473); + assign(test_msg_.z, 3884631.4773294823); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xdd46; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { + 85, 0, 2, 195, 4, 32, 100, 159, 67, 24, 67, 231, 72, 165, + 251, 161, 68, 193, 150, 210, 36, 212, 73, 67, 80, 193, 234, 33, + 25, 189, 43, 163, 77, 65, 0, 0, 8, 0, 70, 221, + }; + uint8_t encoded_payload_[32] = { + 100, 159, 67, 24, 67, 231, 72, 165, 251, 161, 68, + 193, 150, 210, 36, 212, 73, 67, 80, 193, 234, 33, + 25, 189, 43, 163, 77, 65, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 246, 215, 32, 20, 46, 39, 0, 195, 122, 175, 75, - 33, 154, 68, 193, 164, 14, 230, 176, 231, 95, 80, 193, 78, 220, - 22, 253, 254, 105, 77, 65, 0, 0, 9, 0, 13, 86, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.x = -2700354.5912927105; - test_msg.y = -4292510.764041577; - test_msg.z = 3855357.977260149; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2700354.59129 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2700354.59129, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4292510.76404 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4292510.76404, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3855357.97726 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3855357.97726, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosECEFDepA10 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEFDepA10() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 5); + assign(test_msg_.tow, 407151150); + assign(test_msg_.x, -2704375.68369399); + assign(test_msg_.y, -4263209.482329298); + assign(test_msg_.z, 3884635.5118107493); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 246, 215, 32, 20, 46, 39, 0, 212, 196, 12, 42, - 34, 154, 68, 193, 9, 113, 112, 123, 231, 95, 80, 193, 54, 97, - 38, 192, 254, 105, 77, 65, 0, 0, 9, 1, 75, 143, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.x = -2700356.3285146747; - test_msg.y = -4292509.928737887; - test_msg.z = 3855357.5011712564; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2700356.32851 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2700356.32851, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4292509.92874 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4292509.92874, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3855357.50117 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3855357.50117, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 246, 215, 32, 120, 46, 39, 0, 112, 97, 39, 190, - 34, 154, 68, 193, 230, 43, 119, 115, 231, 95, 80, 193, 50, 199, - 76, 66, 254, 105, 77, 65, 0, 0, 9, 0, 204, 113, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.x = -2700357.485576801; - test_msg.y = -4292509.80414865; - test_msg.z = 3855356.517968082; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2700357.48558 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2700357.48558, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4292509.80415 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4292509.80415, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3855356.51797 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3855356.51797, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 246, 215, 32, 120, 46, 39, 0, 194, 82, 121, 4, - 34, 154, 68, 193, 223, 186, 1, 140, 231, 95, 80, 193, 176, 152, - 147, 181, 254, 105, 77, 65, 0, 0, 9, 1, 97, 71, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 1; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.x = -2700356.0349524925; - test_msg.y = -4292510.187605589; - test_msg.z = 3855357.4185667858; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2700356.03495 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2700356.03495, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4292510.18761 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4292510.18761, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3855357.41857 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3855357.41857, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 246, 215, 32, 220, 46, 39, 0, 216, 41, 227, 254, - 33, 154, 68, 193, 9, 151, 154, 124, 231, 95, 80, 193, 1, 183, - 214, 139, 255, 105, 77, 65, 0, 0, 9, 0, 7, 98, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.x = -2700355.9913074784; - test_msg.y = -4292509.946935424; - test_msg.z = 3855359.0924900775; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2700355.99131 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2700355.99131, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4292509.94694 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4292509.94694, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3855359.09249 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3855359.09249, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 195, 4, 32, 212, 157, 67, 24, 153, 222, 105, 1, - 252, 161, 68, 193, 254, 247, 52, 112, 74, 67, 80, 193, 164, 207, - 47, 146, 44, 163, 77, 65, 0, 0, 8, 0, 145, 4, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084500; - test_msg.x = -2704376.0110433814; - test_msg.y = -4263209.753232954; - test_msg.z = 3884633.142084079; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704376.01104 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704376.01104, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263209.75323 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263209.75323, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884633.14208 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884633.14208, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefDepA, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 195, 4, 32, 56, 158, 67, 24, 215, 184, 223, 246, - 251, 161, 68, 193, 36, 126, 17, 39, 74, 67, 80, 193, 19, 179, - 70, 80, 44, 163, 77, 65, 0, 0, 8, 0, 245, 66, + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_dep_a, + sizeof(msg->pos_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084600; - test_msg.x = -2704375.9287024545; - test_msg.y = -4263208.610442672; - test_msg.z = 3884632.627157578; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084600) - << "incorrect value for last_msg_.tow, expected 407084600, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704375.9287 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704375.9287, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263208.61044 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263208.61044, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884632.62716 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884632.62716, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_pos_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 195, 4, 32, 156, 158, 67, 24, 73, 74, 214, 148, - 251, 161, 68, 193, 213, 151, 184, 215, 73, 67, 80, 193, 110, 99, - 38, 164, 43, 163, 77, 65, 0, 0, 8, 0, 5, 223, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084700; - test_msg.x = -2704375.162789617; - test_msg.y = -4263207.370641668; - test_msg.z = 3884631.282421521; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084700) - << "incorrect value for last_msg_.tow, expected 407084700, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704375.16279 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704375.16279, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263207.37064 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263207.37064, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884631.28242 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884631.28242, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xdd11; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_ecef_dep_a_t &lesser, + const sbp_msg_pos_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 195, 4, 32, 0, 159, 67, 24, 177, 111, 112, 45, - 252, 161, 68, 193, 213, 168, 198, 253, 73, 67, 80, 193, 245, 12, - 228, 12, 44, 163, 77, 65, 0, 0, 8, 0, 143, 212, - }; + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084800; - test_msg.x = -2704376.3549937834; - test_msg.y = -4263207.965250214; - test_msg.z = 3884632.1007095524; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084800) - << "incorrect value for last_msg_.tow, expected 407084800, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704376.35499 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704376.35499, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263207.96525 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263207.96525, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884632.10071 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884632.10071, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 0, 2, 195, 4, 32, 100, 159, 67, 24, 67, 231, 72, 165, - 251, 161, 68, 193, 150, 210, 36, 212, 73, 67, 80, 193, 234, 33, - 25, 189, 43, 163, 77, 65, 0, 0, 8, 0, 70, 221, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084900; - test_msg.x = -2704375.291287334; - test_msg.y = -4263207.314747473; - test_msg.z = 3884631.4773294823; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084900) - << "incorrect value for last_msg_.tow, expected 407084900, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704375.29129 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704375.29129, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263207.31475 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263207.31475, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884631.47733 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884631.47733, is " - << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgPosECEFDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosECEFDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_pos_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { 85, 0, 2, 195, 4, 32, 46, 162, 68, 24, 224, 72, 131, 215, 251, 161, 68, 193, 180, 123, 222, 94, 74, 67, 80, 193, 191, 3, 131, 193, 45, 163, 77, 65, 0, 0, 5, 0, 17, 221, }; + uint8_t encoded_payload_[32] = { + 46, 162, 68, 24, 224, 72, 131, 215, 251, 161, 68, 193, 180, 123, 222, 94, + 74, 67, 80, 193, 191, 3, 131, 193, 45, 163, 77, 65, 0, 0, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ( + sbp_msg_pos_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_pos_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 5; - test_msg.tow = 407151150; - test_msg.x = -2704375.68369399; - test_msg.y = -4263209.482329298; - test_msg.z = 3884635.5118107493; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 5) - << "incorrect value for last_msg_.n_sats, expected 5, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407151150) - << "incorrect value for last_msg_.tow, expected 407151150, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2704375.68369 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2704375.68369, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4263209.48233 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4263209.48233, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3884635.51181 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3884635.51181, is " - << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_pos_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_ecef_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFGNSS.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFGNSS.cc index fa042d8875..e6bfa0f95c 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFGNSS.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosECEFGNSS.cc @@ -16,111 +16,809 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosECEFGNSS0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosECEFGNSS0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosECEFGNSS0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosECEFGNSS0() { + assign(test_msg_.accuracy, 182); + assign(test_msg_.flags, 4); + assign(test_msg_.n_sats, 18); + assign(test_msg_.tow, 501867800); + assign(test_msg_.x, -2694229.7079770807); + assign(test_msg_.y, -4264073.427345817); + assign(test_msg_.z, 3890655.013186158); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_ecef_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosEcefGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_ecef_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosEcefGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_ecef_gnss, + sizeof(msg->pos_ecef_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_ecef_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_ecef_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosEcefGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0x287; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 32; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_ecef_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_ecef_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_ecef_gnss_t &lesser, + const sbp_msg_pos_ecef_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_ecef_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_ecef_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_ecef_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosEcefGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosEcefGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosEcefGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgPosECEFGNSS0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_ecef_gnss_t test_msg_{}; + uint8_t encoded_frame_[32 + 8] = { 85, 41, 2, 0, 16, 32, 24, 229, 233, 29, 52, 254, 158, 218, 42, 142, 68, 193, 69, 162, 89, 91, 34, 68, 80, 193, 131, 21, 176, 129, 239, 174, 77, 65, 182, 0, 18, 4, 135, 2, }; + uint8_t encoded_payload_[32] = { + 24, 229, 233, 29, 52, 254, 158, 218, 42, 142, 68, + 193, 69, 162, 89, 91, 34, 68, 80, 193, 131, 21, + 176, 129, 239, 174, 77, 65, 182, 0, 18, 4, + }; +}; - sbp_msg_pos_ecef_gnss_t test_msg{}; - test_msg.accuracy = 182; - test_msg.flags = 4; - test_msg.n_sats = 18; - test_msg.tow = 501867800; - test_msg.x = -2694229.7079770807; - test_msg.y = -4264073.427345817; - test_msg.z = 3890655.013186158; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 182) - << "incorrect value for last_msg_.accuracy, expected 182, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 4) - << "incorrect value for last_msg_.flags, expected 4, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 18) - << "incorrect value for last_msg_.n_sats, expected 18, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; - EXPECT_LT((last_msg_.x * 100 - -2694229.70798 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2694229.70798, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4264073.42735 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4264073.42735, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3890655.01319 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3890655.01319, is " - << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_ecef_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosEcefGnss, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosEcefGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_msg_pos_ecef_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosEcefGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_ecef_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosEcefGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosEcefGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_ecef_gnss_t lesser = info.test_msg; + sbp_msg_pos_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosEcefGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_ECEF_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_ecef_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_ecef_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_ecef_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_ecef_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[32]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 32), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_ecef_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 32); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosEcefGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosECEFGNSS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosEcefGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLH.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLH.cc index 0f9c667411..d99d37accb 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLH.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLH.cc @@ -16,551 +16,3939 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosLLH0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLLH0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLH0() { + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 28.21160739227208); + assign(test_msg_.lat, 37.25130398358085); + assign(test_msg_.lon, -121.87505366879361); + assign(test_msg_.n_sats, 14); + assign(test_msg_.tow, 326825000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh, sizeof(msg->pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlh); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xa2af; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_t &lesser, + const sbp_msg_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 10, 2, 211, 136, 34, 40, 244, 122, 19, 201, 106, 155, 186, + 42, 160, 66, 64, 168, 109, 26, 225, 0, 120, 94, 192, 130, 102, + 237, 230, 43, 54, 60, 64, 0, 0, 0, 0, 14, 2, 175, 162, + }; + uint8_t encoded_payload_[34] = { + 40, 244, 122, 19, 201, 106, 155, 186, 42, 160, 66, 64, + 168, 109, 26, 225, 0, 120, 94, 192, 130, 102, 237, 230, + 43, 54, 60, 64, 0, 0, 0, 0, 14, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosLlh, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_LLH"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlh, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosLlh, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLH1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLH1() { + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 27.742055560866373); + assign(test_msg_.lat, 37.251303074738104); + assign(test_msg_.lon, -121.87505349618341); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh, sizeof(msg->pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlh); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xb126; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_t &lesser, + const sbp_msg_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 10, 2, 211, 136, 34, 16, 248, 122, 19, 52, 177, 251, 178, + 42, 160, 66, 64, 237, 22, 97, 224, 0, 120, 94, 192, 107, 188, + 109, 90, 247, 189, 59, 64, 0, 0, 0, 0, 15, 2, 38, 177, + }; + uint8_t encoded_payload_[34] = { + 16, 248, 122, 19, 52, 177, 251, 178, 42, 160, 66, 64, + 237, 22, 97, 224, 0, 120, 94, 192, 107, 188, 109, 90, + 247, 189, 59, 64, 0, 0, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosLlh, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_LLH"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlh, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosLlh, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLH2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLH2() { + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 27.613721582970516); + assign(test_msg_.lat, 37.25130117370741); + assign(test_msg_.lon, -121.87505373641241); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh, sizeof(msg->pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlh); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x2833; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_t &lesser, + const sbp_msg_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 10, 2, 211, 136, 34, 248, 251, 122, 19, 135, 66, 9, 163, + 42, 160, 66, 64, 146, 8, 99, 225, 0, 120, 94, 192, 45, 181, + 143, 219, 28, 157, 59, 64, 0, 0, 0, 0, 15, 2, 51, 40, + }; + uint8_t encoded_payload_[34] = { + 248, 251, 122, 19, 135, 66, 9, 163, 42, 160, 66, 64, + 146, 8, 99, 225, 0, 120, 94, 192, 45, 181, 143, 219, + 28, 157, 59, 64, 0, 0, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosLlh, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_LLH"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlh, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosLlh, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLH3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLLH0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLLH3() { + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 27.80259807042305); + assign(test_msg_.lat, 37.251296042079176); + assign(test_msg_.lon, -121.87505511141057); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326828000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh, sizeof(msg->pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlh); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xc20c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_t &lesser, + const sbp_msg_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 10, 2, 211, 136, 34, 224, 255, 122, 19, 18, 44, 253, 119, + 42, 160, 66, 64, 48, 109, 39, 231, 0, 120, 94, 192, 185, 76, + 48, 17, 119, 205, 59, 64, 0, 0, 0, 0, 15, 2, 12, 194, + }; + uint8_t encoded_payload_[34] = { + 224, 255, 122, 19, 18, 44, 253, 119, 42, 160, 66, 64, + 48, 109, 39, 231, 0, 120, 94, 192, 185, 76, 48, 17, + 119, 205, 59, 64, 0, 0, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosLlh, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_LLH"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLH0, Test) { - uint8_t encoded_frame[] = { - 85, 10, 2, 211, 136, 34, 40, 244, 122, 19, 201, 106, 155, 186, - 42, 160, 66, 64, 168, 109, 26, 225, 0, 120, 94, 192, 130, 102, - 237, 230, 43, 54, 60, 64, 0, 0, 0, 0, 14, 2, 175, 162, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_pos_llh_t test_msg{}; - test_msg.flags = 2; - test_msg.h_accuracy = 0; - test_msg.height = 28.21160739227208; - test_msg.lat = 37.25130398358085; - test_msg.lon = -121.87505366879361; - test_msg.n_sats = 14; - test_msg.tow = 326825000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 28.2116073923 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 28.2116073923, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.2513039836 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.2513039836, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -121.875053669 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -121.875053669, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 14) - << "incorrect value for last_msg_.n_sats, expected 14, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLH1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLH1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLH1, Test) { - uint8_t encoded_frame[] = { - 85, 10, 2, 211, 136, 34, 16, 248, 122, 19, 52, 177, 251, 178, - 42, 160, 66, 64, 237, 22, 97, 224, 0, 120, 94, 192, 107, 188, - 109, 90, 247, 189, 59, 64, 0, 0, 0, 0, 15, 2, 38, 177, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlh, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); - sbp_msg_pos_llh_t test_msg{}; - test_msg.flags = 2; - test_msg.h_accuracy = 0; - test_msg.height = 27.742055560866373; - test_msg.lat = 37.251303074738104; - test_msg.lon = -121.87505349618341; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 27.7420555609 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 27.7420555609, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.2513030747 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.2513030747, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -121.875053496 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -121.875053496, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLH2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosLlh, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLH4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLLH2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLLH4() { + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 27.939512310879213); + assign(test_msg_.lat, 37.251292578377395); + assign(test_msg_.lon, -121.87505609407974); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326829000); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLH2, Test) { - uint8_t encoded_frame[] = { - 85, 10, 2, 211, 136, 34, 248, 251, 122, 19, 135, 66, 9, 163, - 42, 160, 66, 64, 146, 8, 99, 225, 0, 120, 94, 192, 45, 181, - 143, 219, 28, 157, 59, 64, 0, 0, 0, 0, 15, 2, 51, 40, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_pos_llh_t test_msg{}; - test_msg.flags = 2; - test_msg.h_accuracy = 0; - test_msg.height = 27.613721582970516; - test_msg.lat = 37.25130117370741; - test_msg.lon = -121.87505373641241; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 27.613721583 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 27.613721583, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.2513011737 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.2513011737, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -121.875053736 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -121.875053736, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLH3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLH3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLH3, Test) { - uint8_t encoded_frame[] = { - 85, 10, 2, 211, 136, 34, 224, 255, 122, 19, 18, 44, 253, 119, - 42, 160, 66, 64, 48, 109, 39, 231, 0, 120, 94, 192, 185, 76, - 48, 17, 119, 205, 59, 64, 0, 0, 0, 0, 15, 2, 12, 194, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_pos_llh_t test_msg{}; - test_msg.flags = 2; - test_msg.h_accuracy = 0; - test_msg.height = 27.80259807042305; - test_msg.lat = 37.251296042079176; - test_msg.lon = -121.87505511141057; - test_msg.n_sats = 15; - test_msg.tow = 326828000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 27.8025980704 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 27.8025980704, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.2512960421 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.2512960421, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -121.875055111 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -121.875055111, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326828000) - << "incorrect value for last_msg_.tow, expected 326828000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLH4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLH4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh, sizeof(msg->pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlh); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x6722; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_llh_t &lesser, + const sbp_msg_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLH4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { 85, 10, 2, 211, 136, 34, 200, 3, 123, 19, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, 70, 235, 0, 120, 94, 192, 101, 106, 249, 224, 131, 240, 59, 64, 0, 0, 0, 0, 15, 2, 34, 103, }; + uint8_t encoded_payload_[34] = { + 200, 3, 123, 19, 225, 237, 238, 90, 42, 160, 66, 64, + 59, 143, 70, 235, 0, 120, 94, 192, 101, 106, 249, 224, + 131, 240, 59, 64, 0, 0, 0, 0, 15, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPosLlh, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_pos_llh_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_pos_llh_t test_msg{}; - test_msg.flags = 2; - test_msg.h_accuracy = 0; - test_msg.height = 27.939512310879213; - test_msg.lat = 37.251292578377395; - test_msg.lon = -121.87505609407974; - test_msg.n_sats = 15; - test_msg.tow = 326829000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 27.9395123109 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 27.9395123109, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.2512925784 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.2512925784, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -121.875056094 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -121.875056094, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326829000) - << "incorrect value for last_msg_.tow, expected 326829000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_t lesser = info.test_msg; + sbp_msg_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_POS_LLH"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlh, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLH4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPosLlh, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHCov.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHCov.cc index e5339490e1..62b706e7c1 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHCov.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHCov.cc @@ -16,131 +16,837 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosLLHCov0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLLHCov0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLLHCov0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLLHCov0() { + assign(test_msg_.cov_d_d, 2.0); + assign(test_msg_.cov_e_d, 1.0); + assign(test_msg_.cov_e_e, 6.0); + assign(test_msg_.cov_n_d, 8.0); + assign(test_msg_.cov_n_e, 5.0); + assign(test_msg_.cov_n_n, 7.0); + assign(test_msg_.flags, 5); + assign(test_msg_.height, 0.0); + assign(test_msg_.lat, 0.0); + assign(test_msg_.lon, 7.0); + assign(test_msg_.n_sats, 5); + assign(test_msg_.tow, 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_cov_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_cov_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhCov, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_cov_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhCov); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_cov, sizeof(msg->pos_llh_cov)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_cov_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_cov, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhCov); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x6297; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 54; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_cov_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_cov_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_llh_cov_t &lesser, + const sbp_msg_pos_llh_cov_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cov_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cov_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cov_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cov_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhCov, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhCov, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhCov, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhCov, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHCov0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_cov_t test_msg_{}; + uint8_t encoded_frame_[54 + 8] = { 85, 17, 2, 66, 0, 54, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 64, 0, 0, 160, 64, 0, 0, 0, 65, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 5, 5, 151, 98, }; + uint8_t encoded_payload_[54] = { + 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 28, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 64, 0, 0, 160, 64, + 0, 0, 0, 65, 0, 0, 192, 64, 0, 0, 128, 63, 0, 0, 0, 64, 5, 5, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_cov_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhCov, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_cov_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhCov, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + EXPECT_EQ( + sbp_msg_pos_llh_cov_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + for (uint8_t i = 0; i < 54; i++) { + EXPECT_EQ(sbp_msg_pos_llh_cov_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_cov_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhCov, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_cov_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_cov_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_pos_llh_cov_t test_msg{}; - test_msg.cov_d_d = 2.0; - test_msg.cov_e_d = 1.0; - test_msg.cov_e_e = 6.0; - test_msg.cov_n_d = 8.0; - test_msg.cov_n_e = 5.0; - test_msg.cov_n_n = 7.0; - test_msg.flags = 5; - test_msg.height = 0.0; - test_msg.lat = 0.0; - test_msg.lon = 7.0; - test_msg.n_sats = 5; - test_msg.tow = 7; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_d_d * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_d_d, expected 2.0, is " - << last_msg_.cov_d_d; - EXPECT_LT((last_msg_.cov_e_d * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_d, expected 1.0, is " - << last_msg_.cov_e_d; - EXPECT_LT((last_msg_.cov_e_e * 100 - 6.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_e, expected 6.0, is " - << last_msg_.cov_e_e; - EXPECT_LT((last_msg_.cov_n_d * 100 - 8.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_d, expected 8.0, is " - << last_msg_.cov_n_d; - EXPECT_LT((last_msg_.cov_n_e * 100 - 5.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_e, expected 5.0, is " - << last_msg_.cov_n_e; - EXPECT_LT((last_msg_.cov_n_n * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_n, expected 7.0, is " - << last_msg_.cov_n_n; - EXPECT_EQ(last_msg_.flags, 5) - << "incorrect value for last_msg_.flags, expected 5, is " - << last_msg_.flags; - EXPECT_LT((last_msg_.height * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 0.0, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 0.0, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected 7.0, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 5) - << "incorrect value for last_msg_.n_sats, expected 5, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 7) - << "incorrect value for last_msg_.tow, expected 7, is " << last_msg_.tow; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_cov_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhCov, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_d_d, greater.cov_d_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_d, greater.cov_e_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_e, greater.cov_e_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_d, greater.cov_n_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_e, greater.cov_n_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_n, greater.cov_n_n); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlhCov); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_COV"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_cov_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_cov_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_cov, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_cov, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhCov, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHCov0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhCov, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHDepA.cc index 17826e7e15..7c596ca8fd 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLLHDepA.cc @@ -16,1205 +16,8825 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosLLHDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLLHDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA0() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 69.80437675175607); + assign(test_msg_.lat, 37.42906890908121); + assign(test_msg_.lon, -122.17338662202773); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8bec; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 246, 215, 34, 20, 46, 39, 0, 250, 29, 226, 186, + 235, 182, 66, 64, 19, 203, 51, 196, 24, 139, 94, 192, 31, 157, + 160, 232, 122, 115, 81, 64, 0, 0, 0, 0, 9, 0, 236, 139, + }; + uint8_t encoded_payload_[34] = { + 20, 46, 39, 0, 250, 29, 226, 186, 235, 182, 66, 64, + 19, 203, 51, 196, 24, 139, 94, 192, 31, 157, 160, 232, + 122, 115, 81, 64, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA1() { + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 69.68814067715354); + assign(test_msg_.lat, 37.42906430885274); + assign(test_msg_.lon, -122.17340826071865); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x7519; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 246, 215, 34, 20, 46, 39, 0, 161, 51, 75, 148, + 235, 182, 66, 64, 36, 41, 246, 30, 25, 139, 94, 192, 254, 218, + 49, 127, 10, 108, 81, 64, 0, 0, 0, 0, 9, 1, 25, 117, + }; + uint8_t encoded_payload_[34] = { + 20, 46, 39, 0, 161, 51, 75, 148, 235, 182, 66, 64, + 36, 41, 246, 30, 25, 139, 94, 192, 254, 218, 49, 127, + 10, 108, 81, 64, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA2() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 69.49608854815264); + assign(test_msg_.lat, 37.42905447764173); + assign(test_msg_.lon, -122.17342007549469); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x69ae; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 246, 215, 34, 120, 46, 39, 0, 56, 214, 210, 65, + 235, 182, 66, 64, 13, 46, 132, 80, 25, 139, 94, 192, 22, 143, + 46, 234, 191, 95, 81, 64, 0, 0, 0, 0, 9, 0, 174, 105, + }; + uint8_t encoded_payload_[34] = { + 120, 46, 39, 0, 56, 214, 210, 65, 235, 182, 66, 64, + 13, 46, 132, 80, 25, 139, 94, 192, 22, 143, 46, 234, + 191, 95, 81, 64, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA3() { + assign(test_msg_.flags, 1); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 69.68780458819901); + assign(test_msg_.lat, 37.429063373925565); + assign(test_msg_.lon, -122.17340389594972); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x7f7a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 246, 215, 34, 120, 46, 39, 0, 251, 117, 115, 140, + 235, 182, 66, 64, 152, 134, 167, 12, 25, 139, 94, 192, 160, 22, + 137, 253, 4, 108, 81, 64, 0, 0, 0, 0, 9, 1, 122, 127, + }; + uint8_t encoded_payload_[34] = { + 120, 46, 39, 0, 251, 117, 115, 140, 235, 182, 66, 64, + 152, 134, 167, 12, 25, 139, 94, 192, 160, 22, 137, 253, + 4, 108, 81, 64, 0, 0, 0, 0, 9, 1, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA4() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 70.5249547317965); + assign(test_msg_.lat, 37.42907659359516); + assign(test_msg_.lon, -122.17340492645452); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x9ec2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 246, 215, 34, 220, 46, 39, 0, 51, 124, 88, 251, + 235, 182, 66, 64, 153, 5, 250, 16, 25, 139, 94, 192, 146, 60, + 187, 219, 152, 161, 81, 64, 0, 0, 0, 0, 9, 0, 194, 158, + }; + uint8_t encoded_payload_[34] = { + 220, 46, 39, 0, 51, 124, 88, 251, 235, 182, 66, 64, + 153, 5, 250, 16, 25, 139, 94, 192, 146, 60, 187, 219, + 152, 161, 81, 64, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA5() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 4.039810885214956); + assign(test_msg_.lat, 37.76242171418386); + assign(test_msg_.lon, -122.38908437889262); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084500); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xa9ed; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 195, 4, 34, 212, 157, 67, 24, 8, 23, 228, 8, + 151, 225, 66, 64, 156, 174, 42, 194, 230, 152, 94, 192, 153, 23, + 72, 47, 196, 40, 16, 64, 0, 0, 0, 0, 8, 0, 237, 169, + }; + uint8_t encoded_payload_[34] = { + 212, 157, 67, 24, 8, 23, 228, 8, 151, 225, 66, 64, + 156, 174, 42, 194, 230, 152, 94, 192, 153, 23, 72, 47, + 196, 40, 16, 64, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA6() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 2.926714087009657); + assign(test_msg_.lat, 37.76242361423985); + assign(test_msg_.lon, -122.38909053700489); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084600); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb98; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 195, 4, 34, 56, 158, 67, 24, 220, 109, 212, 24, + 151, 225, 66, 64, 159, 231, 254, 219, 230, 152, 94, 192, 128, 151, + 67, 19, 233, 105, 7, 64, 0, 0, 0, 0, 8, 0, 152, 11, + }; + uint8_t encoded_payload_[34] = { + 56, 158, 67, 24, 220, 109, 212, 24, 151, 225, 66, 64, + 159, 231, 254, 219, 230, 152, 94, 192, 128, 151, 67, 19, + 233, 105, 7, 64, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA7 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA7() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 0.9512146647395566); + assign(test_msg_.lat, 37.762422076126406); + assign(test_msg_.lon, -122.3890907340148); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x9bdd; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 195, 4, 34, 156, 158, 67, 24, 13, 91, 237, 11, + 151, 225, 66, 64, 75, 113, 210, 220, 230, 152, 94, 192, 37, 6, + 145, 188, 89, 112, 238, 63, 0, 0, 0, 0, 8, 0, 221, 155, + }; + uint8_t encoded_payload_[34] = { + 156, 158, 67, 24, 13, 91, 237, 11, 151, 225, 66, 64, + 75, 113, 210, 220, 230, 152, 94, 192, 37, 6, 145, 188, + 89, 112, 238, 63, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA8 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLLHDepA8() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 2.354135752047538); + assign(test_msg_.lat, 37.762421610632735); + assign(test_msg_.lon, -122.38909854449612); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x5e52; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 195, 4, 34, 0, 159, 67, 24, 51, 183, 5, 8, + 151, 225, 66, 64, 13, 226, 148, 253, 230, 152, 94, 192, 187, 27, + 11, 32, 69, 213, 2, 64, 0, 0, 0, 0, 8, 0, 82, 94, + }; + uint8_t encoded_payload_[34] = { + 0, 159, 67, 24, 51, 183, 5, 8, 151, 225, 66, 64, + 13, 226, 148, 253, 230, 152, 94, 192, 187, 27, 11, 32, + 69, 213, 2, 64, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA9 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLLHDepA9() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 1.0876763181642641); + assign(test_msg_.lat, 37.76242334502801); + assign(test_msg_.lon, -122.38909230523223); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x3c46; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { + 85, 1, 2, 195, 4, 34, 100, 159, 67, 24, 22, 77, 146, 22, + 151, 225, 66, 64, 64, 134, 105, 227, 230, 152, 94, 192, 37, 99, + 114, 72, 31, 103, 241, 63, 0, 0, 0, 0, 8, 0, 70, 60, + }; + uint8_t encoded_payload_[34] = { + 100, 159, 67, 24, 22, 77, 146, 22, 151, 225, 66, 64, + 64, 134, 105, 227, 230, 152, 94, 192, 37, 99, 114, 72, + 31, 103, 241, 63, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 246, 215, 34, 20, 46, 39, 0, 250, 29, 226, 186, - 235, 182, 66, 64, 19, 203, 51, 196, 24, 139, 94, 192, 31, 157, - 160, 232, 122, 115, 81, 64, 0, 0, 0, 0, 9, 0, 236, 139, - }; +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 69.80437675175607; - test_msg.lat = 37.42906890908121; - test_msg.lon = -122.17338662202773; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 69.8043767518 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 69.8043767518, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.4290689091 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.4290689091, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.173386622 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.173386622, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgPosLLHDepA10 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLLHDepA10() { + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.height, 5.171533844654222); + assign(test_msg_.lat, 37.76244082253376); + assign(test_msg_.lon, -122.38908288868525); + assign(test_msg_.n_sats, 5); + assign(test_msg_.tow, 407151150); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 246, 215, 34, 20, 46, 39, 0, 161, 51, 75, 148, - 235, 182, 66, 64, 36, 41, 246, 30, 25, 139, 94, 192, 254, 218, - 49, 127, 10, 108, 81, 64, 0, 0, 0, 0, 9, 1, 25, 117, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.height = 69.68814067715354; - test_msg.lat = 37.42906430885274; - test_msg.lon = -122.17340826071865; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 69.6881406772 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 69.6881406772, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.4290643089 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.4290643089, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.173408261 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.173408261, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 246, 215, 34, 120, 46, 39, 0, 56, 214, 210, 65, - 235, 182, 66, 64, 13, 46, 132, 80, 25, 139, 94, 192, 22, 143, - 46, 234, 191, 95, 81, 64, 0, 0, 0, 0, 9, 0, 174, 105, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 69.49608854815264; - test_msg.lat = 37.42905447764173; - test_msg.lon = -122.17342007549469; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 69.4960885482 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 69.4960885482, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.4290544776 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.4290544776, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.173420075 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.173420075, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 246, 215, 34, 120, 46, 39, 0, 251, 117, 115, 140, - 235, 182, 66, 64, 152, 134, 167, 12, 25, 139, 94, 192, 160, 22, - 137, 253, 4, 108, 81, 64, 0, 0, 0, 0, 9, 1, 122, 127, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 1; - test_msg.h_accuracy = 0; - test_msg.height = 69.68780458819901; - test_msg.lat = 37.429063373925565; - test_msg.lon = -122.17340389594972; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 69.6878045882 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 69.6878045882, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.4290633739 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.4290633739, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.173403896 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.173403896, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 246, 215, 34, 220, 46, 39, 0, 51, 124, 88, 251, - 235, 182, 66, 64, 153, 5, 250, 16, 25, 139, 94, 192, 146, 60, - 187, 219, 152, 161, 81, 64, 0, 0, 0, 0, 9, 0, 194, 158, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 70.5249547317965; - test_msg.lat = 37.42907659359516; - test_msg.lon = -122.17340492645452; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 70.5249547318 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 70.5249547318, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.4290765936 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.4290765936, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.173404926 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.173404926, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 195, 4, 34, 212, 157, 67, 24, 8, 23, 228, 8, - 151, 225, 66, 64, 156, 174, 42, 194, 230, 152, 94, 192, 153, 23, - 72, 47, 196, 40, 16, 64, 0, 0, 0, 0, 8, 0, 237, 169, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 4.039810885214956; - test_msg.lat = 37.76242171418386; - test_msg.lon = -122.38908437889262; - test_msg.n_sats = 8; - test_msg.tow = 407084500; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 4.03981088521 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 4.03981088521, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.7624217142 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.7624217142, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389084379 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389084379, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhDepA, &CHandler::callback_static, + this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 195, 4, 34, 56, 158, 67, 24, 220, 109, 212, 24, - 151, 225, 66, 64, 159, 231, 254, 219, 230, 152, 94, 192, 128, 151, - 67, 19, 233, 105, 7, 64, 0, 0, 0, 0, 8, 0, 152, 11, + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_dep_a, + sizeof(msg->pos_llh_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 2.926714087009657; - test_msg.lat = 37.76242361423985; - test_msg.lon = -122.38909053700489; - test_msg.n_sats = 8; - test_msg.tow = 407084600; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 2.92671408701 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 2.92671408701, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.7624236142 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.7624236142, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389090537 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389090537, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084600) - << "incorrect value for last_msg_.tow, expected 407084600, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_pos_llh_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 195, 4, 34, 156, 158, 67, 24, 13, 91, 237, 11, - 151, 225, 66, 64, 75, 113, 210, 220, 230, 152, 94, 192, 37, 6, - 145, 188, 89, 112, 238, 63, 0, 0, 0, 0, 8, 0, 221, 155, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 0.9512146647395566; - test_msg.lat = 37.762422076126406; - test_msg.lon = -122.3890907340148; - test_msg.n_sats = 8; - test_msg.tow = 407084700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 0.95121466474 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 0.95121466474, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.7624220761 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.7624220761, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389090734 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389090734, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084700) - << "incorrect value for last_msg_.tow, expected 407084700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x79d4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_llh_dep_a_t &lesser, + const sbp_msg_pos_llh_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 195, 4, 34, 0, 159, 67, 24, 51, 183, 5, 8, - 151, 225, 66, 64, 13, 226, 148, 253, 230, 152, 94, 192, 187, 27, - 11, 32, 69, 213, 2, 64, 0, 0, 0, 0, 8, 0, 82, 94, - }; + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 2.354135752047538; - test_msg.lat = 37.762421610632735; - test_msg.lon = -122.38909854449612; - test_msg.n_sats = 8; - test_msg.tow = 407084800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 2.35413575205 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 2.35413575205, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.7624216106 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.7624216106, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389098544 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389098544, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084800) - << "incorrect value for last_msg_.tow, expected 407084800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 1, 2, 195, 4, 34, 100, 159, 67, 24, 22, 77, 146, 22, - 151, 225, 66, 64, 64, 134, 105, 227, 230, 152, 94, 192, 37, 99, - 114, 72, 31, 103, 241, 63, 0, 0, 0, 0, 8, 0, 70, 60, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 1.0876763181642641; - test_msg.lat = 37.76242334502801; - test_msg.lon = -122.38909230523223; - test_msg.n_sats = 8; - test_msg.tow = 407084900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 1.08767631816 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 1.08767631816, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.762423345 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.762423345, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389092305 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389092305, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084900) - << "incorrect value for last_msg_.tow, expected 407084900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgPosLLHDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgPosLLHDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLLHDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_pos_llh_dep_a_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { 85, 1, 2, 195, 4, 34, 46, 162, 68, 24, 124, 245, 46, 169, 151, 225, 66, 64, 135, 149, 234, 187, 230, 152, 94, 192, 194, 201, 115, 145, 166, 175, 20, 64, 0, 0, 0, 0, 5, 0, 212, 121, }; + uint8_t encoded_payload_[34] = { + 46, 162, 68, 24, 124, 245, 46, 169, 151, 225, 66, 64, + 135, 149, 234, 187, 230, 152, 94, 192, 194, 201, 115, 145, + 166, 175, 20, 64, 0, 0, 0, 0, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_pos_llh_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.height = 5.171533844654222; - test_msg.lat = 37.76244082253376; - test_msg.lon = -122.38908288868525; - test_msg.n_sats = 5; - test_msg.tow = 407151150; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - 5.17153384465 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 5.17153384465, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.7624408225 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.7624408225, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.389082889 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.389082889, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 5) - << "incorrect value for last_msg_.n_sats, expected 5, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407151150) - << "incorrect value for last_msg_.tow, expected 407151150, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_dep_a_t lesser = info.test_msg; + sbp_msg_pos_llh_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLLHDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc new file mode 100644 index 0000000000..a0be49ea65 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc @@ -0,0 +1,880 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLlhAcc0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgPosLlhAcc0() { + assign(test_msg_.at_accuracy, 6297.2001953125); + assign(test_msg_.confidence_and_geoid, 95); + assign(test_msg_.ct_accuracy, 1948.199951171875); + assign(test_msg_.flags, 72); + assign(test_msg_.h_accuracy, 2410.199951171875); + assign(test_msg_.h_ellipse.orientation, 2550.199951171875); + assign(test_msg_.h_ellipse.semi_major, 8248.2001953125); + assign(test_msg_.h_ellipse.semi_minor, 3202.199951171875); + assign(test_msg_.height, 4257.2); + assign(test_msg_.lat, 7563.2); + assign(test_msg_.lon, 8494.2); + assign(test_msg_.n_sats, 27); + assign(test_msg_.orthometric_height, 4965.2); + assign(test_msg_.tow, 309229607); + assign(test_msg_.v_accuracy, 5539.2001953125); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_acc_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_acc_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhAcc, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_acc_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhAcc); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_acc, sizeof(msg->pos_llh_acc)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_acc_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_acc, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhAcc); + info.sender_id = 7170; + info.preamble = 0x55; + info.crc = 0xb1dc; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 67; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pos_llh_acc_t &lesser, + const sbp_msg_pos_llh_acc_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_acc_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_acc_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_acc_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_acc_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhAcc, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhAcc, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhAcc, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhAcc, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_acc_t test_msg_{}; + uint8_t encoded_frame_[67 + 8] = { + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, 51, 51, + 139, 189, 64, 154, 153, 153, 153, 25, 151, 192, 64, 51, 51, 51, 51, + 51, 161, 176, 64, 51, 51, 51, 51, 51, 101, 179, 64, 51, 163, 22, + 69, 154, 25, 173, 69, 102, 134, 243, 68, 154, 201, 196, 69, 205, 224, + 0, 70, 51, 35, 72, 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + }; + uint8_t encoded_payload_[67] = { + 39, 120, 110, 18, 51, 51, 51, 51, 51, 139, 189, 64, 154, 153, + 153, 153, 25, 151, 192, 64, 51, 51, 51, 51, 51, 161, 176, 64, + 51, 51, 51, 51, 51, 101, 179, 64, 51, 163, 22, 69, 154, 25, + 173, 69, 102, 134, 243, 68, 154, 201, 196, 69, 205, 224, 0, 70, + 51, 35, 72, 69, 51, 99, 31, 69, 95, 27, 72, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_acc_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhAcc, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_acc_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhAcc, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + EXPECT_EQ( + sbp_msg_pos_llh_acc_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + for (uint8_t i = 0; i < 67; i++) { + EXPECT_EQ(sbp_msg_pos_llh_acc_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_acc_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_acc_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhAcc, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_acc_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_acc_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_acc_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_acc_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_acc_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhAcc, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhAcc, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhAcc, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.at_accuracy, greater.at_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.confidence_and_geoid, + greater.confidence_and_geoid); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.ct_accuracy, greater.ct_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.h_ellipse.orientation, + greater.h_ellipse.orientation); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.h_ellipse.semi_major, + greater.h_ellipse.semi_major); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.h_ellipse.semi_minor, + greater.h_ellipse.semi_minor); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.orthometric_height, greater.orthometric_height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_acc_t lesser = info.test_msg; + sbp_msg_pos_llh_acc_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPosLlhAcc); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_ACC"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_acc_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_acc_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_acc, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_acc, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_acc_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhAcc, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhAcc0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhAcc, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhCovGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhCovGnss.cc index e013d8865b..e8b8da4a2a 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhCovGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhCovGnss.cc @@ -16,135 +16,854 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosLlhCovGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLlhCovGnss0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLlhCovGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLlhCovGnss0() { + assign(test_msg_.cov_d_d, 0.03288137540221214); + assign(test_msg_.cov_e_d, -0.0008439270895905793); + assign(test_msg_.cov_e_e, 0.004523798823356628); + assign(test_msg_.cov_n_d, 0.0018563168123364449); + assign(test_msg_.cov_n_e, -0.00036755966721102595); + assign(test_msg_.cov_n_n, 0.007488971576094627); + assign(test_msg_.flags, 4); + assign(test_msg_.height, -17.39382124780135); + assign(test_msg_.lat, 37.83123196497633); + assign(test_msg_.lon, -122.28650381011681); + assign(test_msg_.n_sats, 18); + assign(test_msg_.tow, 501867800); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_cov_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_cov_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhCovGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_cov_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhCovGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_cov_gnss, + sizeof(msg->pos_llh_cov_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_cov_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_cov_gnss, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhCovGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0xc40a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 54; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_cov_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_cov_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_llh_cov_gnss_t &lesser, + const sbp_msg_pos_llh_cov_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_cov_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_cov_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhCovGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgPosLlhCovGnss, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhCovGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhCovGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPosLlhCovGnss0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_cov_gnss_t test_msg_{}; + uint8_t encoded_frame_[54 + 8] = { 85, 49, 2, 0, 16, 54, 24, 229, 233, 29, 73, 123, 28, 207, 101, 234, 66, 64, 100, 168, 19, 20, 86, 146, 94, 192, 214, 198, 35, 120, 209, 100, 49, 192, 12, 102, 245, 59, 6, 181, 192, 185, 168, 79, 243, 58, 96, 60, 148, 59, 253, 58, 93, 186, 159, 174, 6, 61, 18, 4, 10, 196, }; + uint8_t encoded_payload_[54] = { + 24, 229, 233, 29, 73, 123, 28, 207, 101, 234, 66, 64, 100, 168, + 19, 20, 86, 146, 94, 192, 214, 198, 35, 120, 209, 100, 49, 192, + 12, 102, 245, 59, 6, 181, 192, 185, 168, 79, 243, 58, 96, 60, + 148, 59, 253, 58, 93, 186, 159, 174, 6, 61, 18, 4, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgPosLlhCovGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhCovGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + + for (uint8_t i = 0; i < 54; i++) { + EXPECT_EQ( + sbp_msg_pos_llh_cov_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhCovGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_pos_llh_cov_gnss_t test_msg{}; - test_msg.cov_d_d = 0.03288137540221214; - test_msg.cov_e_d = -0.0008439270895905793; - test_msg.cov_e_e = 0.004523798823356628; - test_msg.cov_n_d = 0.0018563168123364449; - test_msg.cov_n_e = -0.00036755966721102595; - test_msg.cov_n_n = 0.007488971576094627; - test_msg.flags = 4; - test_msg.height = -17.39382124780135; - test_msg.lat = 37.83123196497633; - test_msg.lon = -122.28650381011681; - test_msg.n_sats = 18; - test_msg.tow = 501867800; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_d_d * 100 - 0.0328813754022 * 100), 0.05) - << "incorrect value for last_msg_.cov_d_d, expected 0.0328813754022, is " - << last_msg_.cov_d_d; - EXPECT_LT((last_msg_.cov_e_d * 100 - -0.000843927089591 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_d, expected -0.000843927089591, " - "is " - << last_msg_.cov_e_d; - EXPECT_LT((last_msg_.cov_e_e * 100 - 0.00452379882336 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_e, expected 0.00452379882336, is " - << last_msg_.cov_e_e; - EXPECT_LT((last_msg_.cov_n_d * 100 - 0.00185631681234 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_d, expected 0.00185631681234, is " - << last_msg_.cov_n_d; - EXPECT_LT((last_msg_.cov_n_e * 100 - -0.000367559667211 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_e, expected -0.000367559667211, " - "is " - << last_msg_.cov_n_e; - EXPECT_LT((last_msg_.cov_n_n * 100 - 0.00748897157609 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_n, expected 0.00748897157609, is " - << last_msg_.cov_n_n; - EXPECT_EQ(last_msg_.flags, 4) - << "incorrect value for last_msg_.flags, expected 4, is " - << last_msg_.flags; - EXPECT_LT((last_msg_.height * 100 - -17.3938212478 * 100), 0.05) - << "incorrect value for last_msg_.height, expected -17.3938212478, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.831231965 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.831231965, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.28650381 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.28650381, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 18) - << "incorrect value for last_msg_.n_sats, expected 18, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_cov_gnss_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhCovGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_d_d, greater.cov_d_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_d, greater.cov_e_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_e, greater.cov_e_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_d, greater.cov_n_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_e, greater.cov_n_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_n, greater.cov_n_n); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_cov_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhCovGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_COV_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_cov_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_cov_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_cov_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.pos_llh_cov_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[54]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 54); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 54), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 54); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhCovGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhCovGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhCovGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhGnss.cc index 371cfbec57..53f58847c1 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPosLlhGnss.cc @@ -16,115 +16,813 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPosLlhGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPosLlhGnss0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPosLlhGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPosLlhGnss0() { + assign(test_msg_.flags, 4); + assign(test_msg_.h_accuracy, 87); + assign(test_msg_.height, -17.39382124780135); + assign(test_msg_.lat, 37.83123196497633); + assign(test_msg_.lon, -122.28650381011681); + assign(test_msg_.n_sats, 18); + assign(test_msg_.tow, 501867800); + assign(test_msg_.v_accuracy, 181); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pos_llh_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPosLlhGnss, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pos_llh_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPosLlhGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pos_llh_gnss, + sizeof(msg->pos_llh_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pos_llh_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pos_llh_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPosLlhGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0x3769; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pos_llh_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pos_llh_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pos_llh_gnss_t &lesser, + const sbp_msg_pos_llh_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pos_llh_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pos_llh_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pos_llh_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pos_llh_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhGnss, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPosLlhGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPosLlhGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPosLlhGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgPosLlhGnss0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pos_llh_gnss_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { 85, 42, 2, 0, 16, 34, 24, 229, 233, 29, 73, 123, 28, 207, 101, 234, 66, 64, 100, 168, 19, 20, 86, 146, 94, 192, 214, 198, 35, 120, 209, 100, 49, 192, 87, 0, 181, 0, 18, 4, 105, 55, }; + uint8_t encoded_payload_[34] = { + 24, 229, 233, 29, 73, 123, 28, 207, 101, 234, 66, 64, + 100, 168, 19, 20, 86, 146, 94, 192, 214, 198, 35, 120, + 209, 100, 49, 192, 87, 0, 181, 0, 18, 4, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pos_llh_gnss_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPosLlhGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pos_llh_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPosLlhGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ(sbp_msg_pos_llh_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_pos_llh_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pos_llh_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPosLlhGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_pos_llh_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pos_llh_gnss_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_pos_llh_gnss_t test_msg{}; - test_msg.flags = 4; - test_msg.h_accuracy = 87; - test_msg.height = -17.39382124780135; - test_msg.lat = 37.83123196497633; - test_msg.lon = -122.28650381011681; - test_msg.n_sats = 18; - test_msg.tow = 501867800; - test_msg.v_accuracy = 181; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 4) - << "incorrect value for last_msg_.flags, expected 4, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 87) - << "incorrect value for last_msg_.h_accuracy, expected 87, is " - << last_msg_.h_accuracy; - EXPECT_LT((last_msg_.height * 100 - -17.3938212478 * 100), 0.05) - << "incorrect value for last_msg_.height, expected -17.3938212478, is " - << last_msg_.height; - EXPECT_LT((last_msg_.lat * 100 - 37.831231965 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 37.831231965, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - -122.28650381 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected -122.28650381, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.n_sats, 18) - << "incorrect value for last_msg_.n_sats, expected 18, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 181) - << "incorrect value for last_msg_.v_accuracy, expected 181, is " - << last_msg_.v_accuracy; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pos_llh_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPosLlhGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPosLlhGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_pos_llh_gnss_t lesser = info.test_msg; + sbp_msg_pos_llh_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPosLlhGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POS_LLH_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pos_llh_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pos_llh_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pos_llh_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pos_llh_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); } + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pos_llh_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPosLlhGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPosLlhGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPosLlhGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgPoseRelative.cc b/c/test/cpp/auto_check_sbp_navigation_MsgPoseRelative.cc index b2933e5870..3deed9678a 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgPoseRelative.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgPoseRelative.cc @@ -16,66 +16,391 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgPoseRelative0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgPoseRelative0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgPoseRelative0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgPoseRelative0() { + assign(test_msg_.cov_c_x_x, 2.0); + assign(test_msg_.cov_c_x_y, 0.0); + assign(test_msg_.cov_c_x_z, 0.0); + assign(test_msg_.cov_c_y_y, 2.0); + assign(test_msg_.cov_c_y_z, 0.0); + assign(test_msg_.cov_c_z_z, 2.0); + assign(test_msg_.cov_r_x_x, 1.0); + assign(test_msg_.cov_r_x_y, 0.0); + assign(test_msg_.cov_r_x_z, 0.0); + assign(test_msg_.cov_r_y_y, 1.0); + assign(test_msg_.cov_r_y_z, 0.0); + assign(test_msg_.cov_r_z_z, 1.0); + assign(test_msg_.flags, 5); + assign(test_msg_.sensor_id, 0); + assign(test_msg_.timestamp_1, 1110); + assign(test_msg_.timestamp_2, 2220); + assign(test_msg_.tow, 1110); + + assign(test_msg_.trans[0], 1100); + + assign(test_msg_.trans[1], 550); + + assign(test_msg_.trans[2], 100); + assign(test_msg_.w, -859307164); + assign(test_msg_.x, -6444804); + assign(test_msg_.y, -1866844813); + assign(test_msg_.z, 622997694); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pose_relative_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pose_relative_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPoseRelative, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pose_relative_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPoseRelative); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pose_relative, + sizeof(msg->pose_relative)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pose_relative_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pose_relative, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPoseRelative); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xBBAB; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 90; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_pose_relative_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_pose_relative_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_pose_relative_t &lesser, + const sbp_msg_pose_relative_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pose_relative_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pose_relative_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pose_relative_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pose_relative_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgPoseRelative, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPoseRelative, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgPoseRelative, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgPoseRelative, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgPoseRelative0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pose_relative_t test_msg_{}; + uint8_t encoded_frame_[90 + 8] = { 85, 69, 2, 66, 0, 90, 86, 4, 0, 0, 0, 86, 4, 0, 0, 172, 8, 0, 0, 76, 4, 0, 0, 38, 2, 0, 0, 100, 0, 0, 0, 100, 3, 200, 204, 252, 168, 157, 255, 115, 53, 186, @@ -84,118 +409,548 @@ TEST_F(Test_auto_check_sbp_navigation_MsgPoseRelative0, Test) { 63, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64, 5, 171, 187, }; + uint8_t encoded_payload_[90] = { + 86, 4, 0, 0, 0, 86, 4, 0, 0, 172, 8, 0, 0, 76, 4, + 0, 0, 38, 2, 0, 0, 100, 0, 0, 0, 100, 3, 200, 204, 252, + 168, 157, 255, 115, 53, 186, 144, 190, 48, 34, 37, 0, 0, 128, 63, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 63, 0, 0, 0, + 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 64, 5, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pose_relative_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPoseRelative, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[90]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_pose_relative_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 90); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 90), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgPoseRelative, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 90); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 90), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[90]; + + EXPECT_EQ(sbp_msg_pose_relative_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 90), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[90]; + + for (uint8_t i = 0; i < 90; i++) { + EXPECT_EQ(sbp_msg_pose_relative_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pose_relative_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pose_relative_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 90); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPoseRelative, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 90); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pose_relative_t msg{}; + + EXPECT_EQ(sbp_msg_pose_relative_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pose_relative_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_pose_relative_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_pose_relative_t test_msg{}; - test_msg.cov_c_x_x = 2.0; - test_msg.cov_c_x_y = 0.0; - test_msg.cov_c_x_z = 0.0; - test_msg.cov_c_y_y = 2.0; - test_msg.cov_c_y_z = 0.0; - test_msg.cov_c_z_z = 2.0; - test_msg.cov_r_x_x = 1.0; - test_msg.cov_r_x_y = 0.0; - test_msg.cov_r_x_z = 0.0; - test_msg.cov_r_y_y = 1.0; - test_msg.cov_r_y_z = 0.0; - test_msg.cov_r_z_z = 1.0; - test_msg.flags = 5; - test_msg.sensor_id = 0; - test_msg.timestamp_1 = 1110; - test_msg.timestamp_2 = 2220; - test_msg.tow = 1110; - - test_msg.trans[0] = 1100; - - test_msg.trans[1] = 550; - - test_msg.trans[2] = 100; - test_msg.w = -859307164; - test_msg.x = -6444804; - test_msg.y = -1866844813; - test_msg.z = 622997694; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_c_x_x * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_x_x, expected 2.0, is " - << last_msg_.cov_c_x_x; - EXPECT_LT((last_msg_.cov_c_x_y * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_x_y, expected 0.0, is " - << last_msg_.cov_c_x_y; - EXPECT_LT((last_msg_.cov_c_x_z * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_x_z, expected 0.0, is " - << last_msg_.cov_c_x_z; - EXPECT_LT((last_msg_.cov_c_y_y * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_y_y, expected 2.0, is " - << last_msg_.cov_c_y_y; - EXPECT_LT((last_msg_.cov_c_y_z * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_y_z, expected 0.0, is " - << last_msg_.cov_c_y_z; - EXPECT_LT((last_msg_.cov_c_z_z * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_c_z_z, expected 2.0, is " - << last_msg_.cov_c_z_z; - EXPECT_LT((last_msg_.cov_r_x_x * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_x_x, expected 1.0, is " - << last_msg_.cov_r_x_x; - EXPECT_LT((last_msg_.cov_r_x_y * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_x_y, expected 0.0, is " - << last_msg_.cov_r_x_y; - EXPECT_LT((last_msg_.cov_r_x_z * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_x_z, expected 0.0, is " - << last_msg_.cov_r_x_z; - EXPECT_LT((last_msg_.cov_r_y_y * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_y_y, expected 1.0, is " - << last_msg_.cov_r_y_y; - EXPECT_LT((last_msg_.cov_r_y_z * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_y_z, expected 0.0, is " - << last_msg_.cov_r_y_z; - EXPECT_LT((last_msg_.cov_r_z_z * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_r_z_z, expected 1.0, is " - << last_msg_.cov_r_z_z; - EXPECT_EQ(last_msg_.flags, 5) - << "incorrect value for last_msg_.flags, expected 5, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.sensor_id, 0) - << "incorrect value for last_msg_.sensor_id, expected 0, is " - << last_msg_.sensor_id; - EXPECT_EQ(last_msg_.timestamp_1, 1110) - << "incorrect value for last_msg_.timestamp_1, expected 1110, is " - << last_msg_.timestamp_1; - EXPECT_EQ(last_msg_.timestamp_2, 2220) - << "incorrect value for last_msg_.timestamp_2, expected 2220, is " - << last_msg_.timestamp_2; - EXPECT_EQ(last_msg_.tow, 1110) - << "incorrect value for last_msg_.tow, expected 1110, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.trans[0], 1100) - << "incorrect value for last_msg_.trans[0], expected 1100, is " - << last_msg_.trans[0]; - EXPECT_EQ(last_msg_.trans[1], 550) - << "incorrect value for last_msg_.trans[1], expected 550, is " - << last_msg_.trans[1]; - EXPECT_EQ(last_msg_.trans[2], 100) - << "incorrect value for last_msg_.trans[2], expected 100, is " - << last_msg_.trans[2]; - EXPECT_EQ(last_msg_.w, -859307164) - << "incorrect value for last_msg_.w, expected -859307164, is " - << last_msg_.w; - EXPECT_EQ(last_msg_.x, -6444804) - << "incorrect value for last_msg_.x, expected -6444804, is " - << last_msg_.x; - EXPECT_EQ(last_msg_.y, -1866844813) - << "incorrect value for last_msg_.y, expected -1866844813, is " - << last_msg_.y; - EXPECT_EQ(last_msg_.z, 622997694) - << "incorrect value for last_msg_.z, expected 622997694, is " - << last_msg_.z; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pose_relative_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPoseRelative, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPoseRelative, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } } + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPoseRelative, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_x_x, greater.cov_c_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_x_y, greater.cov_c_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_x_z, greater.cov_c_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_y_y, greater.cov_c_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_y_z, greater.cov_c_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_c_z_z, greater.cov_c_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_x_x, greater.cov_r_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_x_y, greater.cov_r_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_x_z, greater.cov_r_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_y_y, greater.cov_r_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_y_z, greater.cov_r_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.cov_r_z_z, greater.cov_r_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.sensor_id, greater.sensor_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.timestamp_1, greater.timestamp_1); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.timestamp_2, greater.timestamp_2); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.trans[0], greater.trans[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.trans[1], greater.trans[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.trans[2], greater.trans[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_pose_relative_t lesser = info.test_msg; + sbp_msg_pose_relative_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgPoseRelative); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_POSE_RELATIVE"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pose_relative_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pose_relative_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pose_relative, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pose_relative, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[90]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 90); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 90), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pose_relative_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 90); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPoseRelative, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgPoseRelative0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgPoseRelative, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc b/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc index 26749ca8be..c542d6f0e5 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc @@ -16,109 +16,924 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgProtectionLevel0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgProtectionLevel0 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgProtectionLevel0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgProtectionLevel0() { + assign(test_msg_.atpl, 10663); + assign(test_msg_.ctpl, 5433); + assign(test_msg_.flags, 555755625); + assign(test_msg_.heading, -529244741); + assign(test_msg_.height, 412.2); + assign(test_msg_.hopl, 26707); + assign(test_msg_.hpl, 41013); + assign(test_msg_.hvpl, 62681); + assign(test_msg_.lat, 5290.2); + assign(test_msg_.lon, 9904.2); + assign(test_msg_.pitch, -1598561301); + assign(test_msg_.popl, 35212); + assign(test_msg_.roll, 1018834477); + assign(test_msg_.ropl, 63066); + assign(test_msg_.tow, 4060370030); + assign(test_msg_.v_x, -584647705); + assign(test_msg_.v_y, 1353168848); + assign(test_msg_.v_z, -1537140001); + assign(test_msg_.vpl, 21593); + assign(test_msg_.vvpl, 41277); + assign(test_msg_.wn, 13102); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_protection_level_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_protection_level_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgProtectionLevel, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_protection_level_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgProtectionLevel); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->protection_level, + sizeof(msg->protection_level)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_protection_level_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.protection_level, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgProtectionLevel); + info.sender_id = 813; + info.preamble = 0x55; + info.crc = 0xbc85; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 76; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_protection_level_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_protection_level_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_protection_level_t &lesser, + const sbp_msg_protection_level_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_protection_level_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_protection_level_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_protection_level_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_protection_level_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgProtectionLevel, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgProtectionLevel, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgProtectionLevel, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgProtectionLevel, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); -TEST_F(Test_auto_check_sbp_navigation_MsgProtectionLevel0, Test) { - uint8_t encoded_frame[] = { - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_protection_level_t test_msg_{}; + uint8_t encoded_frame_[76 + 8] = { + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, + 89, 84, 167, 41, 57, 21, 217, 244, 61, 161, 83, 104, 140, 137, + 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, 153, 153, + 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, + 38, 221, 208, 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, + 235, 227, 183, 160, 187, 93, 116, 224, 105, 40, 32, 33, 133, 188, + }; + uint8_t encoded_payload_[76] = { + 110, 84, 4, 242, 46, 51, 53, 160, 89, 84, 167, 41, 57, + 21, 217, 244, 61, 161, 83, 104, 140, 137, 90, 246, 51, 51, + 51, 51, 51, 170, 180, 64, 154, 153, 153, 153, 25, 88, 195, + 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, 38, 221, + 208, 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, 235, + 227, 183, 160, 187, 93, 116, 224, 105, 40, 32, 33, }; +}; - sbp_msg_protection_level_dep_a_t test_msg{}; - test_msg.flags = 0; - test_msg.height = 0.0; - test_msg.hpl = 0; - test_msg.lat = 0.0; - test_msg.lon = 0.0; - test_msg.tow = 501867400; - test_msg.vpl = 0; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_LT((last_msg_.height * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.height, expected 0.0, is " - << last_msg_.height; - EXPECT_EQ(last_msg_.hpl, 0) - << "incorrect value for last_msg_.hpl, expected 0, is " << last_msg_.hpl; - EXPECT_LT((last_msg_.lat * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.lat, expected 0.0, is " - << last_msg_.lat; - EXPECT_LT((last_msg_.lon * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.lon, expected 0.0, is " - << last_msg_.lon; - EXPECT_EQ(last_msg_.tow, 501867400) - << "incorrect value for last_msg_.tow, expected 501867400, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.vpl, 0) - << "incorrect value for last_msg_.vpl, expected 0, is " << last_msg_.vpl; +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_protection_level_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgProtectionLevel, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[76]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_protection_level_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 76); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 76), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgProtectionLevel, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 76); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 76), 0); } + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[76]; + + EXPECT_EQ(sbp_msg_protection_level_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 76), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[76]; + + for (uint8_t i = 0; i < 76; i++) { + EXPECT_EQ( + sbp_msg_protection_level_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_protection_level_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 76); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgProtectionLevel, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 76); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_t msg{}; + + EXPECT_EQ(sbp_msg_protection_level_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_protection_level_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_protection_level_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgProtectionLevel, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgProtectionLevel, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgProtectionLevel, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.atpl, greater.atpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.ctpl, greater.ctpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.heading, greater.heading); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.hopl, greater.hopl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.hpl, greater.hpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.hvpl, greater.hvpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.pitch, greater.pitch); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.popl, greater.popl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.roll, greater.roll); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.ropl, greater.ropl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.v_x, greater.v_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.v_y, greater.v_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.v_z, greater.v_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.vpl, greater.vpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.vvpl, greater.vvpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_t lesser = info.test_msg; + sbp_msg_protection_level_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgProtectionLevel); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_PROTECTION_LEVEL"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_protection_level_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_protection_level_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.protection_level, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.protection_level, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[76]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 76); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 76), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 76); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgProtectionLevel, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevel0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgProtectionLevel, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc new file mode 100644 index 0000000000..ec95745b2b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc @@ -0,0 +1,849 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgProtectionLevelDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgProtectionLevelDepA0() { + assign(test_msg_.flags, 248); + assign(test_msg_.height, 8270.2); + assign(test_msg_.hpl, 35588); + assign(test_msg_.lat, 7924.2); + assign(test_msg_.lon, 3174.2); + assign(test_msg_.tow, 3108339252); + assign(test_msg_.vpl, 21807); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_protection_level_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_protection_level_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgProtectionLevelDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_protection_level_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgProtectionLevelDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->protection_level_dep_a, + sizeof(msg->protection_level_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_protection_level_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.protection_level_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgProtectionLevelDepA); + info.sender_id = 5780; + info.preamble = 0x55; + info.crc = 0x6851; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 33; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_protection_level_dep_a_t &lesser, + const sbp_msg_protection_level_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_protection_level_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_protection_level_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_protection_level_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_protection_level_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgProtectionLevelDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgProtectionLevelDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgProtectionLevelDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgProtectionLevelDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_protection_level_dep_a_t test_msg_{}; + uint8_t encoded_frame_[33 + 8] = { + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, + 51, 51, 51, 51, 51, 244, 190, 64, 102, 102, 102, 102, 102, 204, + 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, 81, 104, + }; + uint8_t encoded_payload_[33] = { + 52, 126, 69, 185, 47, 85, 4, 139, 51, 51, 51, + 51, 51, 244, 190, 64, 102, 102, 102, 102, 102, 204, + 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_protection_level_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgProtectionLevelDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_protection_level_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgProtectionLevelDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + EXPECT_EQ(sbp_msg_protection_level_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + for (uint8_t i = 0; i < 33; i++) { + EXPECT_EQ(sbp_msg_protection_level_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_protection_level_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgProtectionLevelDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_protection_level_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_protection_level_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_protection_level_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgProtectionLevelDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgProtectionLevelDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgProtectionLevelDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hpl, greater.hpl); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_protection_level_dep_a_t lesser = info.test_msg; + sbp_msg_protection_level_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vpl, greater.vpl); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgProtectionLevelDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_PROTECTION_LEVEL_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_protection_level_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_protection_level_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.protection_level_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.protection_level_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_protection_level_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgProtectionLevelDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgProtectionLevelDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgProtectionLevelDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgReferenceFrameParam.cc b/c/test/cpp/auto_check_sbp_navigation_MsgReferenceFrameParam.cc index 5b11ca773a..ff98406b6f 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgReferenceFrameParam.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgReferenceFrameParam.cc @@ -16,66 +16,403 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgReferenceFrameParam0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgReferenceFrameParam0 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgReferenceFrameParam0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgReferenceFrameParam0() { + assign(test_msg_.delta_X0, 7); + assign(test_msg_.delta_Y0, 8); + assign(test_msg_.delta_Z0, 9); + assign(test_msg_.dot_delta_X0, 14); + assign(test_msg_.dot_delta_Y0, 15); + assign(test_msg_.dot_delta_Z0, 16); + assign(test_msg_.dot_scale, 20); + assign(test_msg_.dot_theta_01, 17); + assign(test_msg_.dot_theta_02, 18); + assign(test_msg_.dot_theta_03, 19); + assign(test_msg_.re_t0, 6); + assign(test_msg_.scale, 13); + assign(test_msg_.sin, 4); + { + const char assign_string[] = { + (char)102, (char)111, (char)111, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.sn, assign_string, sizeof(assign_string)); + } + assign(test_msg_.ssr_iod, 1); + assign(test_msg_.theta_01, 10); + assign(test_msg_.theta_02, 11); + assign(test_msg_.theta_03, 12); + { + const char assign_string[] = { + (char)98, (char)97, (char)114, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.tn, assign_string, sizeof(assign_string)); + } + assign(test_msg_.utn, 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_reference_frame_param_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_reference_frame_param_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgReferenceFrameParam, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_reference_frame_param_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgReferenceFrameParam); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->reference_frame_param, + sizeof(msg->reference_frame_param)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_reference_frame_param_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.reference_frame_param, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgReferenceFrameParam); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xA106; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 124; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_reference_frame_param_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_reference_frame_param_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_reference_frame_param_t &lesser, + const sbp_msg_reference_frame_param_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); -TEST_F(Test_auto_check_sbp_navigation_MsgReferenceFrameParam0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_reference_frame_param_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_reference_frame_param_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_reference_frame_param_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_reference_frame_param_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgReferenceFrameParam, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgReferenceFrameParam, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgReferenceFrameParam, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgReferenceFrameParam, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_reference_frame_param_t test_msg_{}; + uint8_t encoded_frame_[124 + 8] = { 85, 68, 2, 66, 0, 124, 1, 102, 111, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 97, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -85,129 +422,542 @@ TEST_F(Test_auto_check_sbp_navigation_MsgReferenceFrameParam0, Test) { 0, 0, 14, 0, 0, 0, 15, 0, 0, 0, 16, 0, 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 19, 0, 0, 0, 20, 0, 6, 161, }; + uint8_t encoded_payload_[124] = { + 1, 102, 111, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 97, 114, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 0, 6, 0, 7, 0, + 0, 0, 8, 0, 0, 0, 9, 0, 0, 0, 10, 0, 0, 0, 11, 0, 0, 0, + 12, 0, 0, 0, 13, 0, 0, 0, 14, 0, 0, 0, 15, 0, 0, 0, 16, 0, + 0, 0, 17, 0, 0, 0, 18, 0, 0, 0, 19, 0, 0, 0, 20, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_reference_frame_param_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgReferenceFrameParam, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[124]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_reference_frame_param_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 124); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 124), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgReferenceFrameParam, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 124); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 124), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[124]; + + EXPECT_EQ(sbp_msg_reference_frame_param_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 124), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[124]; + + for (uint8_t i = 0; i < 124; i++) { + EXPECT_EQ(sbp_msg_reference_frame_param_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reference_frame_param_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_reference_frame_param_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 124); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgReferenceFrameParam, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 124); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_reference_frame_param_t msg{}; + + EXPECT_EQ(sbp_msg_reference_frame_param_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_reference_frame_param_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_reference_frame_param_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_reference_frame_param_t test_msg{}; - test_msg.delta_X0 = 7; - test_msg.delta_Y0 = 8; - test_msg.delta_Z0 = 9; - test_msg.dot_delta_X0 = 14; - test_msg.dot_delta_Y0 = 15; - test_msg.dot_delta_Z0 = 16; - test_msg.dot_scale = 20; - test_msg.dot_theta_01 = 17; - test_msg.dot_theta_02 = 18; - test_msg.dot_theta_03 = 19; - test_msg.re_t0 = 6; - test_msg.scale = 13; - test_msg.sin = 4; - { - const char assign_string[] = { - (char)102, (char)111, (char)111, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.sn, assign_string, sizeof(assign_string)); - } - test_msg.ssr_iod = 1; - test_msg.theta_01 = 10; - test_msg.theta_02 = 11; - test_msg.theta_03 = 12; - { - const char assign_string[] = { - (char)98, (char)97, (char)114, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.tn, assign_string, sizeof(assign_string)); - } - test_msg.utn = 5; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.delta_X0, 7) - << "incorrect value for last_msg_.delta_X0, expected 7, is " - << last_msg_.delta_X0; - EXPECT_EQ(last_msg_.delta_Y0, 8) - << "incorrect value for last_msg_.delta_Y0, expected 8, is " - << last_msg_.delta_Y0; - EXPECT_EQ(last_msg_.delta_Z0, 9) - << "incorrect value for last_msg_.delta_Z0, expected 9, is " - << last_msg_.delta_Z0; - EXPECT_EQ(last_msg_.dot_delta_X0, 14) - << "incorrect value for last_msg_.dot_delta_X0, expected 14, is " - << last_msg_.dot_delta_X0; - EXPECT_EQ(last_msg_.dot_delta_Y0, 15) - << "incorrect value for last_msg_.dot_delta_Y0, expected 15, is " - << last_msg_.dot_delta_Y0; - EXPECT_EQ(last_msg_.dot_delta_Z0, 16) - << "incorrect value for last_msg_.dot_delta_Z0, expected 16, is " - << last_msg_.dot_delta_Z0; - EXPECT_EQ(last_msg_.dot_scale, 20) - << "incorrect value for last_msg_.dot_scale, expected 20, is " - << last_msg_.dot_scale; - EXPECT_EQ(last_msg_.dot_theta_01, 17) - << "incorrect value for last_msg_.dot_theta_01, expected 17, is " - << last_msg_.dot_theta_01; - EXPECT_EQ(last_msg_.dot_theta_02, 18) - << "incorrect value for last_msg_.dot_theta_02, expected 18, is " - << last_msg_.dot_theta_02; - EXPECT_EQ(last_msg_.dot_theta_03, 19) - << "incorrect value for last_msg_.dot_theta_03, expected 19, is " - << last_msg_.dot_theta_03; - EXPECT_EQ(last_msg_.re_t0, 6) - << "incorrect value for last_msg_.re_t0, expected 6, is " - << last_msg_.re_t0; - EXPECT_EQ(last_msg_.scale, 13) - << "incorrect value for last_msg_.scale, expected 13, is " - << last_msg_.scale; - EXPECT_EQ(last_msg_.sin, 4) - << "incorrect value for last_msg_.sin, expected 4, is " << last_msg_.sin; - { - const char check_string[] = { - (char)102, (char)111, (char)111, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.sn, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.sn, expected string '" << check_string - << "', is '" << last_msg_.sn << "'"; - } - EXPECT_EQ(last_msg_.ssr_iod, 1) - << "incorrect value for last_msg_.ssr_iod, expected 1, is " - << last_msg_.ssr_iod; - EXPECT_EQ(last_msg_.theta_01, 10) - << "incorrect value for last_msg_.theta_01, expected 10, is " - << last_msg_.theta_01; - EXPECT_EQ(last_msg_.theta_02, 11) - << "incorrect value for last_msg_.theta_02, expected 11, is " - << last_msg_.theta_02; - EXPECT_EQ(last_msg_.theta_03, 12) - << "incorrect value for last_msg_.theta_03, expected 12, is " - << last_msg_.theta_03; - { - const char check_string[] = { - (char)98, (char)97, (char)114, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.tn, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.tn, expected string '" << check_string - << "', is '" << last_msg_.tn << "'"; - } - EXPECT_EQ(last_msg_.utn, 5) - << "incorrect value for last_msg_.utn, expected 5, is " << last_msg_.utn; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_reference_frame_param_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgReferenceFrameParam, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgReferenceFrameParam, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgReferenceFrameParam, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.delta_X0, greater.delta_X0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.delta_Y0, greater.delta_Y0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.delta_Z0, greater.delta_Z0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_delta_X0, greater.dot_delta_X0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_delta_Y0, greater.dot_delta_Y0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_delta_Z0, greater.dot_delta_Z0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_scale, greater.dot_scale); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_theta_01, greater.dot_theta_01); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_theta_02, greater.dot_theta_02); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.dot_theta_03, greater.dot_theta_03); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.re_t0, greater.re_t0); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.scale, greater.scale); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.sin, greater.sin); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.sn, greater.sn); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod, greater.ssr_iod); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.theta_01, greater.theta_01); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.theta_02, greater.theta_02); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.theta_03, greater.theta_03); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.tn, greater.tn); + comparison_tests(lesser, greater); + } + { + sbp_msg_reference_frame_param_t lesser = info.test_msg; + sbp_msg_reference_frame_param_t greater = info.test_msg; + make_lesser_greater(lesser.utn, greater.utn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgReferenceFrameParam); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_REFERENCE_FRAME_PARAM"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_reference_frame_param_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_reference_frame_param_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.reference_frame_param, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.reference_frame_param, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[124]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 124); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 124), 0); } + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reference_frame_param_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 124); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgReferenceFrameParam, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgReferenceFrameParam0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgReferenceFrameParam, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgUTCLeapSecond.cc b/c/test/cpp/auto_check_sbp_navigation_MsgUTCLeapSecond.cc index 16181641f9..d9a2968b4e 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgUTCLeapSecond.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgUTCLeapSecond.cc @@ -16,117 +16,826 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgUTCLeapSecond0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgUTCLeapSecond0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgUTCLeapSecond0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgUTCLeapSecond0() { + assign(test_msg_.count_after, 9); + assign(test_msg_.count_before, 4); + assign(test_msg_.ref_dn, 8); + assign(test_msg_.ref_wn, 7); + assign(test_msg_.reserved_0, 1); + assign(test_msg_.reserved_1, 2); + assign(test_msg_.reserved_2, 3); + assign(test_msg_.reserved_3, 5); + assign(test_msg_.reserved_4, 6); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_leap_second_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_utc_leap_second_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUtcLeapSecond, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_leap_second_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUtcLeapSecond); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->utc_leap_second, + sizeof(msg->utc_leap_second)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_utc_leap_second_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.utc_leap_second, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUtcLeapSecond); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xE832; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_utc_leap_second_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_utc_leap_second_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_utc_leap_second_t &lesser, + const sbp_msg_utc_leap_second_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgUTCLeapSecond0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_utc_leap_second_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_utc_leap_second_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_utc_leap_second_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_utc_leap_second_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUtcLeapSecond, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUtcLeapSecond, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUtcLeapSecond, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUtcLeapSecond, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_utc_leap_second_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { 85, 58, 2, 66, 0, 14, 1, 0, 2, 0, 3, 4, 5, 0, 6, 0, 7, 0, 8, 9, 50, 232, }; + uint8_t encoded_payload_[14] = { + 1, 0, 2, 0, 3, 4, 5, 0, 6, 0, 7, 0, 8, 9, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_utc_leap_second_encoded_len(&info.test_msg), + info.payload_len); - sbp_msg_utc_leap_second_t test_msg{}; - test_msg.count_after = 9; - test_msg.count_before = 4; - test_msg.ref_dn = 8; - test_msg.ref_wn = 7; - test_msg.reserved_0 = 1; - test_msg.reserved_1 = 2; - test_msg.reserved_2 = 3; - test_msg.reserved_3 = 5; - test_msg.reserved_4 = 6; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.count_after, 9) - << "incorrect value for last_msg_.count_after, expected 9, is " - << last_msg_.count_after; - EXPECT_EQ(last_msg_.count_before, 4) - << "incorrect value for last_msg_.count_before, expected 4, is " - << last_msg_.count_before; - EXPECT_EQ(last_msg_.ref_dn, 8) - << "incorrect value for last_msg_.ref_dn, expected 8, is " - << last_msg_.ref_dn; - EXPECT_EQ(last_msg_.ref_wn, 7) - << "incorrect value for last_msg_.ref_wn, expected 7, is " - << last_msg_.ref_wn; - EXPECT_EQ(last_msg_.reserved_0, 1) - << "incorrect value for last_msg_.reserved_0, expected 1, is " - << last_msg_.reserved_0; - EXPECT_EQ(last_msg_.reserved_1, 2) - << "incorrect value for last_msg_.reserved_1, expected 2, is " - << last_msg_.reserved_1; - EXPECT_EQ(last_msg_.reserved_2, 3) - << "incorrect value for last_msg_.reserved_2, expected 3, is " - << last_msg_.reserved_2; - EXPECT_EQ(last_msg_.reserved_3, 5) - << "incorrect value for last_msg_.reserved_3, expected 5, is " - << last_msg_.reserved_3; - EXPECT_EQ(last_msg_.reserved_4, 6) - << "incorrect value for last_msg_.reserved_4, expected 6, is " - << last_msg_.reserved_4; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUtcLeapSecond, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_utc_leap_second_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUtcLeapSecond, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ(sbp_msg_utc_leap_second_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ( + sbp_msg_utc_leap_second_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_leap_second_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_utc_leap_second_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUtcLeapSecond, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_utc_leap_second_t msg{}; + + EXPECT_EQ(sbp_msg_utc_leap_second_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_utc_leap_second_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_utc_leap_second_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_utc_leap_second_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcLeapSecond, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUtcLeapSecond, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcLeapSecond, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.count_after, greater.count_after); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.count_before, greater.count_before); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.ref_dn, greater.ref_dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.ref_wn, greater.ref_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.reserved_0, greater.reserved_0); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.reserved_1, greater.reserved_1); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.reserved_2, greater.reserved_2); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.reserved_3, greater.reserved_3); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_leap_second_t lesser = info.test_msg; + sbp_msg_utc_leap_second_t greater = info.test_msg; + make_lesser_greater(lesser.reserved_4, greater.reserved_4); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUtcLeapSecond); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UTC_LEAP_SECOND"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_utc_leap_second_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_utc_leap_second_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.utc_leap_second, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.utc_leap_second, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_leap_second_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUtcLeapSecond, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCLeapSecond0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUtcLeapSecond, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgUTCTime.cc b/c/test/cpp/auto_check_sbp_navigation_MsgUTCTime.cc index ba9dac766f..ada8f40706 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgUTCTime.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgUTCTime.cc @@ -16,117 +16,806 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgUTCTime0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgUTCTime0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgUTCTime0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgUTCTime0() { + assign(test_msg_.day, 9); + assign(test_msg_.flags, 1); + assign(test_msg_.hours, 19); + assign(test_msg_.minutes, 24); + assign(test_msg_.month, 4); + assign(test_msg_.ns, 800000000); + assign(test_msg_.seconds, 9); + assign(test_msg_.tow, 501867800); + assign(test_msg_.year, 2021); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_utc_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUtcTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUtcTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->utc_time, sizeof(msg->utc_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_utc_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.utc_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUtcTime); + info.sender_id = 789; + info.preamble = 0x55; + info.crc = 0xfdc7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_utc_time_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_utc_time_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_utc_time_t &lesser, + const sbp_msg_utc_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgUTCTime0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_utc_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_utc_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_utc_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_utc_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgUtcTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgUtcTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgUtcTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgUtcTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_utc_time_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { 85, 3, 1, 21, 3, 16, 1, 24, 229, 233, 29, 229, 7, 4, 9, 19, 24, 9, 0, 8, 175, 47, 199, 253, }; + uint8_t encoded_payload_[16] = { + 1, 24, 229, 233, 29, 229, 7, 4, 9, 19, 24, 9, 0, 8, 175, 47, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_utc_time_encoded_len(&info.test_msg), info.payload_len); - sbp_msg_utc_time_t test_msg{}; - test_msg.day = 9; - test_msg.flags = 1; - test_msg.hours = 19; - test_msg.minutes = 24; - test_msg.month = 4; - test_msg.ns = 800000000; - test_msg.seconds = 9; - test_msg.tow = 501867800; - test_msg.year = 2021; - - EXPECT_EQ(send_message(789, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 789); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.day, 9) - << "incorrect value for last_msg_.day, expected 9, is " << last_msg_.day; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.hours, 19) - << "incorrect value for last_msg_.hours, expected 19, is " - << last_msg_.hours; - EXPECT_EQ(last_msg_.minutes, 24) - << "incorrect value for last_msg_.minutes, expected 24, is " - << last_msg_.minutes; - EXPECT_EQ(last_msg_.month, 4) - << "incorrect value for last_msg_.month, expected 4, is " - << last_msg_.month; - EXPECT_EQ(last_msg_.ns, 800000000) - << "incorrect value for last_msg_.ns, expected 800000000, is " - << last_msg_.ns; - EXPECT_EQ(last_msg_.seconds, 9) - << "incorrect value for last_msg_.seconds, expected 9, is " - << last_msg_.seconds; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.year, 2021) - << "incorrect value for last_msg_.year, expected 2021, is " - << last_msg_.year; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgUtcTime, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_utc_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgUtcTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ( + sbp_msg_utc_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_msg_utc_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_utc_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUtcTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_t msg{}; + + EXPECT_EQ(sbp_msg_utc_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_utc_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_utc_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUtcTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.day, greater.day); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.hours, greater.hours); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.minutes, greater.minutes); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.month, greater.month); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.ns, greater.ns); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.seconds, greater.seconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_t lesser = info.test_msg; + sbp_msg_utc_time_t greater = info.test_msg; + make_lesser_greater(lesser.year, greater.year); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgUtcTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_UTC_TIME"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_utc_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_utc_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.utc_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.utc_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUtcTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTime0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgUtcTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgUTCTimeGNSS.cc b/c/test/cpp/auto_check_sbp_navigation_MsgUTCTimeGNSS.cc index 5f9bb6fbdb..9b8c0f0664 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgUTCTimeGNSS.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgUTCTimeGNSS.cc @@ -16,117 +16,820 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgUTCTimeGNSS0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgUTCTimeGNSS0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgUTCTimeGNSS0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgUTCTimeGNSS0() { + assign(test_msg_.day, 9); + assign(test_msg_.flags, 1); + assign(test_msg_.hours, 19); + assign(test_msg_.minutes, 24); + assign(test_msg_.month, 4); + assign(test_msg_.ns, 800000000); + assign(test_msg_.seconds, 9); + assign(test_msg_.tow, 501867800); + assign(test_msg_.year, 2021); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_time_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_utc_time_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUtcTimeGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_utc_time_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUtcTimeGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->utc_time_gnss, + sizeof(msg->utc_time_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_utc_time_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.utc_time_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUtcTimeGnss); + info.sender_id = 789; + info.preamble = 0x55; + info.crc = 0x21b1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_utc_time_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_utc_time_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_utc_time_gnss_t &lesser, + const sbp_msg_utc_time_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgUTCTimeGNSS0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_utc_time_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_utc_time_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_utc_time_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_utc_time_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUtcTimeGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgUtcTimeGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUtcTimeGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUtcTimeGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_utc_time_gnss_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { 85, 5, 1, 21, 3, 16, 1, 24, 229, 233, 29, 229, 7, 4, 9, 19, 24, 9, 0, 8, 175, 47, 177, 33, }; + uint8_t encoded_payload_[16] = { + 1, 24, 229, 233, 29, 229, 7, 4, 9, 19, 24, 9, 0, 8, 175, 47, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_utc_time_gnss_encoded_len(&info.test_msg), + info.payload_len); - sbp_msg_utc_time_gnss_t test_msg{}; - test_msg.day = 9; - test_msg.flags = 1; - test_msg.hours = 19; - test_msg.minutes = 24; - test_msg.month = 4; - test_msg.ns = 800000000; - test_msg.seconds = 9; - test_msg.tow = 501867800; - test_msg.year = 2021; - - EXPECT_EQ(send_message(789, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 789); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.day, 9) - << "incorrect value for last_msg_.day, expected 9, is " << last_msg_.day; - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.hours, 19) - << "incorrect value for last_msg_.hours, expected 19, is " - << last_msg_.hours; - EXPECT_EQ(last_msg_.minutes, 24) - << "incorrect value for last_msg_.minutes, expected 24, is " - << last_msg_.minutes; - EXPECT_EQ(last_msg_.month, 4) - << "incorrect value for last_msg_.month, expected 4, is " - << last_msg_.month; - EXPECT_EQ(last_msg_.ns, 800000000) - << "incorrect value for last_msg_.ns, expected 800000000, is " - << last_msg_.ns; - EXPECT_EQ(last_msg_.seconds, 9) - << "incorrect value for last_msg_.seconds, expected 9, is " - << last_msg_.seconds; - EXPECT_EQ(last_msg_.tow, 501867800) - << "incorrect value for last_msg_.tow, expected 501867800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.year, 2021) - << "incorrect value for last_msg_.year, expected 2021, is " - << last_msg_.year; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgUtcTimeGnss, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_utc_time_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUtcTimeGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_utc_time_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_msg_utc_time_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_utc_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUtcTimeGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_utc_time_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_utc_time_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_utc_time_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUtcTimeGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUtcTimeGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.day, greater.day); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.hours, greater.hours); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.minutes, greater.minutes); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.month, greater.month); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.ns, greater.ns); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.seconds, greater.seconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_utc_time_gnss_t lesser = info.test_msg; + sbp_msg_utc_time_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.year, greater.year); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUtcTimeGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UTC_TIME_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_utc_time_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_utc_time_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.utc_time_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.utc_time_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_utc_time_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUtcTimeGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgUTCTimeGNSS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUtcTimeGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelBody.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelBody.cc index eb7ad89acf..8b489e0809 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelBody.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelBody.cc @@ -16,127 +16,829 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelBody0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelBody0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelBody0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelBody0() { + assign(test_msg_.cov_x_x, 0.0); + assign(test_msg_.cov_x_y, 5.0); + assign(test_msg_.cov_x_z, 7.0); + assign(test_msg_.cov_y_y, 7.0); + assign(test_msg_.cov_y_z, 3.0); + assign(test_msg_.cov_z_z, 2.0); + assign(test_msg_.flags, 8); + assign(test_msg_.n_sats, 3); + assign(test_msg_.tow, 1); + assign(test_msg_.x, 4); + assign(test_msg_.y, 2); + assign(test_msg_.z, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_body_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_body_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelBody, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_body_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelBody); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_body, sizeof(msg->vel_body)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_body_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_body, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelBody); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x9078; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_body_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_body_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_body_t &lesser, + const sbp_msg_vel_body_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_body_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_body_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_body_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_body_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelBody, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelBody, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelBody, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelBody, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelBody0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_body_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { 85, 19, 2, 66, 0, 42, 1, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 64, 0, 0, 224, 64, 0, 0, 224, 64, 0, 0, 64, 64, 0, 0, 0, 64, 3, 8, 120, 144, }; + uint8_t encoded_payload_[42] = { + 1, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 160, 64, 0, 0, 224, 64, 0, 0, 224, 64, 0, 0, 64, 64, 0, 0, 0, 64, 3, 8, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_body_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelBody, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_body_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelBody, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ( + sbp_msg_vel_body_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ(sbp_msg_vel_body_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_body_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_body_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelBody, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_body_t msg{}; + + EXPECT_EQ(sbp_msg_vel_body_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_body_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_body_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_vel_body_t test_msg{}; - test_msg.cov_x_x = 0.0; - test_msg.cov_x_y = 5.0; - test_msg.cov_x_z = 7.0; - test_msg.cov_y_y = 7.0; - test_msg.cov_y_z = 3.0; - test_msg.cov_z_z = 2.0; - test_msg.flags = 8; - test_msg.n_sats = 3; - test_msg.tow = 1; - test_msg.x = 4; - test_msg.y = 2; - test_msg.z = 1; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_x_x * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_x, expected 0.0, is " - << last_msg_.cov_x_x; - EXPECT_LT((last_msg_.cov_x_y * 100 - 5.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_y, expected 5.0, is " - << last_msg_.cov_x_y; - EXPECT_LT((last_msg_.cov_x_z * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_z, expected 7.0, is " - << last_msg_.cov_x_z; - EXPECT_LT((last_msg_.cov_y_y * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_y, expected 7.0, is " - << last_msg_.cov_y_y; - EXPECT_LT((last_msg_.cov_y_z * 100 - 3.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_z, expected 3.0, is " - << last_msg_.cov_y_z; - EXPECT_LT((last_msg_.cov_z_z * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_z_z, expected 2.0, is " - << last_msg_.cov_z_z; - EXPECT_EQ(last_msg_.flags, 8) - << "incorrect value for last_msg_.flags, expected 8, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 3) - << "incorrect value for last_msg_.n_sats, expected 3, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 1) - << "incorrect value for last_msg_.tow, expected 1, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 4) - << "incorrect value for last_msg_.x, expected 4, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 2) - << "incorrect value for last_msg_.y, expected 2, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 1) - << "incorrect value for last_msg_.z, expected 1, is " << last_msg_.z; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_body_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelBody, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelBody, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelBody, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_x, greater.cov_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_y, greater.cov_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_z, greater.cov_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_y, greater.cov_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_z, greater.cov_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.cov_z_z, greater.cov_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_body_t lesser = info.test_msg; + sbp_msg_vel_body_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelBody); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_BODY"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_body_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_body_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_body, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_body, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_body_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelBody, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelBody0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelBody, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelCog.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelCog.cc index 597c8defdd..fe033c30da 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelCog.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelCog.cc @@ -16,330 +16,2365 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelCog0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelCog0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelCog0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelCog0() { + assign(test_msg_.cog, 1000); + assign(test_msg_.cog_accuracy, 4000); + assign(test_msg_.flags, 62); + assign(test_msg_.sog, 2000); + assign(test_msg_.sog_accuracy, 5000); + assign(test_msg_.tow, 326825520); + assign(test_msg_.v_up, 3000); + assign(test_msg_.v_up_accuracy, 6000); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_cog_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelCog, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelCog); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_cog, sizeof(msg->vel_cog)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_cog_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_cog, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelCog); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xC1D4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 30; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_cog_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_cog_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_cog_t &lesser, + const sbp_msg_vel_cog_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_cog_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_cog_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_cog_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_cog_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelCog0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_vel_cog_t test_msg_{}; + uint8_t encoded_frame_[30 + 8] = { 85, 28, 2, 211, 136, 30, 48, 246, 122, 19, 232, 3, 0, 0, 208, 7, 0, 0, 184, 11, 0, 0, 160, 15, 0, 0, 136, 19, 0, 0, 112, 23, 0, 0, 62, 0, 212, 193, }; + uint8_t encoded_payload_[30] = { + 48, 246, 122, 19, 232, 3, 0, 0, 208, 7, 0, 0, 184, 11, 0, + 0, 160, 15, 0, 0, 136, 19, 0, 0, 112, 23, 0, 0, 62, 0, + }; +}; - sbp_msg_vel_cog_t test_msg{}; - test_msg.cog = 1000; - test_msg.cog_accuracy = 4000; - test_msg.flags = 62; - test_msg.sog = 2000; - test_msg.sog_accuracy = 5000; - test_msg.tow = 326825520; - test_msg.v_up = 3000; - test_msg.v_up_accuracy = 6000; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cog, 1000) - << "incorrect value for last_msg_.cog, expected 1000, is " - << last_msg_.cog; - EXPECT_EQ(last_msg_.cog_accuracy, 4000) - << "incorrect value for last_msg_.cog_accuracy, expected 4000, is " - << last_msg_.cog_accuracy; - EXPECT_EQ(last_msg_.flags, 62) - << "incorrect value for last_msg_.flags, expected 62, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.sog, 2000) - << "incorrect value for last_msg_.sog, expected 2000, is " - << last_msg_.sog; - EXPECT_EQ(last_msg_.sog_accuracy, 5000) - << "incorrect value for last_msg_.sog_accuracy, expected 5000, is " - << last_msg_.sog_accuracy; - EXPECT_EQ(last_msg_.tow, 326825520) - << "incorrect value for last_msg_.tow, expected 326825520, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_up, 3000) - << "incorrect value for last_msg_.v_up, expected 3000, is " - << last_msg_.v_up; - EXPECT_EQ(last_msg_.v_up_accuracy, 6000) - << "incorrect value for last_msg_.v_up_accuracy, expected 6000, is " - << last_msg_.v_up_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelCog1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelCog1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_cog_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelCog, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelCog, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + for (uint8_t i = 0; i < 30; i++) { + EXPECT_EQ(sbp_msg_vel_cog_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_cog_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_cog_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_navigation_MsgVelCog1, Test) { - uint8_t encoded_frame[] = { - 85, 28, 2, 211, 136, 30, 48, 246, 122, 19, 123, 0, 0, - 0, 200, 1, 0, 0, 24, 252, 255, 255, 0, 149, 186, 10, - 100, 0, 0, 0, 100, 0, 0, 0, 0, 0, 90, 114, - }; + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelCog, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_cog_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_vel_cog_t test_msg{}; - test_msg.cog = 123; - test_msg.cog_accuracy = 180000000; - test_msg.flags = 0; - test_msg.sog = 456; - test_msg.sog_accuracy = 100; - test_msg.tow = 326825520; - test_msg.v_up = -1000; - test_msg.v_up_accuracy = 100; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cog, 123) - << "incorrect value for last_msg_.cog, expected 123, is " - << last_msg_.cog; - EXPECT_EQ(last_msg_.cog_accuracy, 180000000) - << "incorrect value for last_msg_.cog_accuracy, expected 180000000, is " - << last_msg_.cog_accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.sog, 456) - << "incorrect value for last_msg_.sog, expected 456, is " - << last_msg_.sog; - EXPECT_EQ(last_msg_.sog_accuracy, 100) - << "incorrect value for last_msg_.sog_accuracy, expected 100, is " - << last_msg_.sog_accuracy; - EXPECT_EQ(last_msg_.tow, 326825520) - << "incorrect value for last_msg_.tow, expected 326825520, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_up, -1000) - << "incorrect value for last_msg_.v_up, expected -1000, is " - << last_msg_.v_up; - EXPECT_EQ(last_msg_.v_up_accuracy, 100) - << "incorrect value for last_msg_.v_up_accuracy, expected 100, is " - << last_msg_.v_up_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelCog2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_cog_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog, greater.cog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog_accuracy, greater.cog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog, greater.sog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog_accuracy, greater.sog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up, greater.v_up); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up_accuracy, greater.v_up_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelCog); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_COG"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_cog_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_cog_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_cog, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_cog, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelCog, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelCog, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelCog1 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelCog2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelCog1() { + assign(test_msg_.cog, 123); + assign(test_msg_.cog_accuracy, 180000000); + assign(test_msg_.flags, 0); + assign(test_msg_.sog, 456); + assign(test_msg_.sog_accuracy, 100); + assign(test_msg_.tow, 326825520); + assign(test_msg_.v_up, -1000); + assign(test_msg_.v_up_accuracy, 100); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_cog_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_cog_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgVelCog2, Test) { - uint8_t encoded_frame[] = { - 85, 28, 2, 211, 136, 30, 48, 246, 122, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 210, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_vel_cog_t test_msg{}; - test_msg.cog = 0; - test_msg.cog_accuracy = 0; - test_msg.flags = 0; - test_msg.sog = 0; - test_msg.sog_accuracy = 0; - test_msg.tow = 326825520; - test_msg.v_up = 0; - test_msg.v_up_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cog, 0) - << "incorrect value for last_msg_.cog, expected 0, is " << last_msg_.cog; - EXPECT_EQ(last_msg_.cog_accuracy, 0) - << "incorrect value for last_msg_.cog_accuracy, expected 0, is " - << last_msg_.cog_accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.sog, 0) - << "incorrect value for last_msg_.sog, expected 0, is " << last_msg_.sog; - EXPECT_EQ(last_msg_.sog_accuracy, 0) - << "incorrect value for last_msg_.sog_accuracy, expected 0, is " - << last_msg_.sog_accuracy; - EXPECT_EQ(last_msg_.tow, 326825520) - << "incorrect value for last_msg_.tow, expected 326825520, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_up, 0) - << "incorrect value for last_msg_.v_up, expected 0, is " - << last_msg_.v_up; - EXPECT_EQ(last_msg_.v_up_accuracy, 0) - << "incorrect value for last_msg_.v_up_accuracy, expected 0, is " - << last_msg_.v_up_accuracy; -} + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_cog_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelCog, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelCog); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_cog, sizeof(msg->vel_cog)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_cog_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_cog, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelCog); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x725A; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 30; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_cog_t &lesser, + const sbp_msg_vel_cog_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_cog_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_cog_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_cog_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_cog_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_cog_t test_msg_{}; + uint8_t encoded_frame_[30 + 8] = { + 85, 28, 2, 211, 136, 30, 48, 246, 122, 19, 123, 0, 0, + 0, 200, 1, 0, 0, 24, 252, 255, 255, 0, 149, 186, 10, + 100, 0, 0, 0, 100, 0, 0, 0, 0, 0, 90, 114, + }; + uint8_t encoded_payload_[30] = { + 48, 246, 122, 19, 123, 0, 0, 0, 200, 1, 0, 0, 24, 252, 255, + 255, 0, 149, 186, 10, 100, 0, 0, 0, 100, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_cog_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelCog, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelCog, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + for (uint8_t i = 0; i < 30; i++) { + EXPECT_EQ(sbp_msg_vel_cog_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelCog, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_cog_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_cog_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog, greater.cog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog_accuracy, greater.cog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog, greater.sog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog_accuracy, greater.sog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up, greater.v_up); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up_accuracy, greater.v_up_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelCog); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_COG"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_cog_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_cog_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_cog, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_cog, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelCog, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelCog, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelCog2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelCog2() { + assign(test_msg_.cog, 0); + assign(test_msg_.cog_accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.sog, 0); + assign(test_msg_.sog_accuracy, 0); + assign(test_msg_.tow, 326825520); + assign(test_msg_.v_up, 0); + assign(test_msg_.v_up_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_cog_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelCog, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_cog_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelCog); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_cog, sizeof(msg->vel_cog)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_cog_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_cog, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelCog); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xD22A; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 30; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_cog_t &lesser, + const sbp_msg_vel_cog_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_cog_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_cog_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_cog_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_cog_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelCog, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelCog, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_cog_t test_msg_{}; + uint8_t encoded_frame_[30 + 8] = { + 85, 28, 2, 211, 136, 30, 48, 246, 122, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 210, + }; + uint8_t encoded_payload_[30] = { + 48, 246, 122, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_cog_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelCog, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelCog, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + EXPECT_EQ( + sbp_msg_vel_cog_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + + for (uint8_t i = 0; i < 30; i++) { + EXPECT_EQ(sbp_msg_vel_cog_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelCog, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + EXPECT_EQ(sbp_msg_vel_cog_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_cog_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_cog_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelCog, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog, greater.cog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.cog_accuracy, greater.cog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog, greater.sog); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.sog_accuracy, greater.sog_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up, greater.v_up); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_cog_t lesser = info.test_msg; + sbp_msg_vel_cog_t greater = info.test_msg; + make_lesser_greater(lesser.v_up_accuracy, greater.v_up_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelCog); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_COG"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_cog_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_cog_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_cog, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_cog, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[30]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 30); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 30), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_cog_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 30); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelCog, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelCog2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelCog, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEF.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEF.cc index f174fe5a0f..e380e5f02f 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEF.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEF.cc @@ -16,511 +16,3909 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelECEF0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelECEF0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEF0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 14); + assign(test_msg_.tow, 326825000); + assign(test_msg_.x, -8); + assign(test_msg_.y, -5); + assign(test_msg_.z, 10); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef, sizeof(msg->vel_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x63b5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_t &lesser, + const sbp_msg_vel_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 13, 2, 211, 136, 20, 40, 244, 122, 19, 248, 255, 255, 255, + 251, 255, 255, 255, 10, 0, 0, 0, 0, 0, 14, 0, 181, 99, + }; + uint8_t encoded_payload_[20] = { + 40, 244, 122, 19, 248, 255, 255, 255, 251, 255, + 255, 255, 10, 0, 0, 0, 0, 0, 14, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEF1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEF1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326825500); + assign(test_msg_.x, -12); + assign(test_msg_.y, -18); + assign(test_msg_.z, 11); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef, sizeof(msg->vel_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x78d7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_t &lesser, + const sbp_msg_vel_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 13, 2, 211, 136, 20, 28, 246, 122, 19, 244, 255, 255, 255, + 238, 255, 255, 255, 11, 0, 0, 0, 0, 0, 15, 0, 215, 120, + }; + uint8_t encoded_payload_[20] = { + 28, 246, 122, 19, 244, 255, 255, 255, 238, 255, + 255, 255, 11, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEF2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEF2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.x, -8); + assign(test_msg_.y, -6); + assign(test_msg_.z, 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef, sizeof(msg->vel_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xddf8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_t &lesser, + const sbp_msg_vel_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 13, 2, 211, 136, 20, 16, 248, 122, 19, 248, 255, 255, 255, + 250, 255, 255, 255, 7, 0, 0, 0, 0, 0, 15, 0, 248, 221, + }; + uint8_t encoded_payload_[20] = { + 16, 248, 122, 19, 248, 255, 255, 255, 250, 255, + 255, 255, 7, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEF3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelECEF0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelECEF3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826500); + assign(test_msg_.x, -7); + assign(test_msg_.y, -17); + assign(test_msg_.z, 16); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef, sizeof(msg->vel_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xa701; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_t &lesser, + const sbp_msg_vel_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 13, 2, 211, 136, 20, 4, 250, 122, 19, 249, 255, 255, 255, + 239, 255, 255, 255, 16, 0, 0, 0, 0, 0, 15, 0, 1, 167, + }; + uint8_t encoded_payload_[20] = { + 4, 250, 122, 19, 249, 255, 255, 255, 239, 255, + 255, 255, 16, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_ECEF"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEF0, Test) { - uint8_t encoded_frame[] = { - 85, 13, 2, 211, 136, 20, 40, 244, 122, 19, 248, 255, 255, 255, - 251, 255, 255, 255, 10, 0, 0, 0, 0, 0, 14, 0, 181, 99, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_vel_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 14; - test_msg.tow = 326825000; - test_msg.x = -8; - test_msg.y = -5; - test_msg.z = 10; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 14) - << "incorrect value for last_msg_.n_sats, expected 14, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -8) - << "incorrect value for last_msg_.x, expected -8, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -5) - << "incorrect value for last_msg_.y, expected -5, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 10) - << "incorrect value for last_msg_.z, expected 10, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEF1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEF1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEF1, Test) { - uint8_t encoded_frame[] = { - 85, 13, 2, 211, 136, 20, 28, 246, 122, 19, 244, 255, 255, 255, - 238, 255, 255, 255, 11, 0, 0, 0, 0, 0, 15, 0, 215, 120, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcef, &info.test_msg_wrapped); - sbp_msg_vel_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326825500; - test_msg.x = -12; - test_msg.y = -18; - test_msg.z = 11; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825500) - << "incorrect value for last_msg_.tow, expected 326825500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -12) - << "incorrect value for last_msg_.x, expected -12, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -18) - << "incorrect value for last_msg_.y, expected -18, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 11) - << "incorrect value for last_msg_.z, expected 11, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEF2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEF4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelECEF2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelECEF4() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.x, -9); + assign(test_msg_.y, -13); + assign(test_msg_.z, 14); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEF2, Test) { - uint8_t encoded_frame[] = { - 85, 13, 2, 211, 136, 20, 16, 248, 122, 19, 248, 255, 255, 255, - 250, 255, 255, 255, 7, 0, 0, 0, 0, 0, 15, 0, 248, 221, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_vel_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.x = -8; - test_msg.y = -6; - test_msg.z = 7; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -8) - << "incorrect value for last_msg_.x, expected -8, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -6) - << "incorrect value for last_msg_.y, expected -6, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 7) - << "incorrect value for last_msg_.z, expected 7, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEF3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEF3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEF3, Test) { - uint8_t encoded_frame[] = { - 85, 13, 2, 211, 136, 20, 4, 250, 122, 19, 249, 255, 255, 255, - 239, 255, 255, 255, 16, 0, 0, 0, 0, 0, 15, 0, 1, 167, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_vel_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326826500; - test_msg.x = -7; - test_msg.y = -17; - test_msg.z = 16; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826500) - << "incorrect value for last_msg_.tow, expected 326826500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -7) - << "incorrect value for last_msg_.x, expected -7, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -17) - << "incorrect value for last_msg_.y, expected -17, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 16) - << "incorrect value for last_msg_.z, expected 16, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEF4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEF4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcef, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef, sizeof(msg->vel_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcef); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x2bbf; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ecef_t &lesser, + const sbp_msg_vel_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcef, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEF4, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 13, 2, 211, 136, 20, 248, 251, 122, 19, 247, 255, 255, 255, 243, 255, 255, 255, 14, 0, 0, 0, 0, 0, 15, 0, 191, 43, }; + uint8_t encoded_payload_[20] = { + 248, 251, 122, 19, 247, 255, 255, 255, 243, 255, + 255, 255, 14, 0, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelEcef, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_vel_ecef_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_vel_ecef_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.x = -9; - test_msg.y = -13; - test_msg.z = 14; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -9) - << "incorrect value for last_msg_.x, expected -9, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -13) - << "incorrect value for last_msg_.y, expected -13, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 14) - << "incorrect value for last_msg_.z, expected 14, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_t lesser = info.test_msg; + sbp_msg_vel_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelEcef); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_ECEF"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcef, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEF4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelEcef, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFCov.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFCov.cc index 166bff0173..1958169e4c 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFCov.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFCov.cc @@ -16,127 +16,840 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelECEFCov0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelECEFCov0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelECEFCov0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelECEFCov0() { + assign(test_msg_.cov_x_x, 2.0); + assign(test_msg_.cov_x_y, 2.0); + assign(test_msg_.cov_x_z, 2.0); + assign(test_msg_.cov_y_y, 2.0); + assign(test_msg_.cov_y_z, 1.0); + assign(test_msg_.cov_z_z, 3.0); + assign(test_msg_.flags, 4); + assign(test_msg_.n_sats, 3); + assign(test_msg_.tow, 2); + assign(test_msg_.x, 0); + assign(test_msg_.y, 0); + assign(test_msg_.z, 6); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_cov_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_cov_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefCov, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_cov_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefCov); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_cov, + sizeof(msg->vel_ecef_cov)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_cov_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_cov, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefCov); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xfe5b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_cov_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_cov_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ecef_cov_t &lesser, + const sbp_msg_vel_ecef_cov_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cov_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cov_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cov_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cov_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefCov, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefCov, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefCov, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefCov, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFCov0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_cov_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { 85, 21, 2, 66, 0, 42, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 128, 63, 0, 0, 64, 64, 3, 4, 91, 254, }; + uint8_t encoded_payload_[42] = { + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 64, 0, + 0, 0, 64, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 128, 63, 0, 0, 64, 64, 3, 4, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_cov_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefCov, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefCov, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_cov_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefCov, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ecef_cov_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_vel_ecef_cov_t test_msg{}; - test_msg.cov_x_x = 2.0; - test_msg.cov_x_y = 2.0; - test_msg.cov_x_z = 2.0; - test_msg.cov_y_y = 2.0; - test_msg.cov_y_z = 1.0; - test_msg.cov_z_z = 3.0; - test_msg.flags = 4; - test_msg.n_sats = 3; - test_msg.tow = 2; - test_msg.x = 0; - test_msg.y = 0; - test_msg.z = 6; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_x_x * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_x, expected 2.0, is " - << last_msg_.cov_x_x; - EXPECT_LT((last_msg_.cov_x_y * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_y, expected 2.0, is " - << last_msg_.cov_x_y; - EXPECT_LT((last_msg_.cov_x_z * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_z, expected 2.0, is " - << last_msg_.cov_x_z; - EXPECT_LT((last_msg_.cov_y_y * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_y, expected 2.0, is " - << last_msg_.cov_y_y; - EXPECT_LT((last_msg_.cov_y_z * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_z, expected 1.0, is " - << last_msg_.cov_y_z; - EXPECT_LT((last_msg_.cov_z_z * 100 - 3.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_z_z, expected 3.0, is " - << last_msg_.cov_z_z; - EXPECT_EQ(last_msg_.flags, 4) - << "incorrect value for last_msg_.flags, expected 4, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 3) - << "incorrect value for last_msg_.n_sats, expected 3, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2) - << "incorrect value for last_msg_.tow, expected 2, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 0) - << "incorrect value for last_msg_.x, expected 0, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 0) - << "incorrect value for last_msg_.y, expected 0, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 6) - << "incorrect value for last_msg_.z, expected 6, is " << last_msg_.z; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_cov_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefCov, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_x, greater.cov_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_y, greater.cov_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_z, greater.cov_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_y, greater.cov_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_z, greater.cov_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_z_z, greater.cov_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefCov); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_COV"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_cov_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_cov_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_cov, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef_cov, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefCov, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFCov0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefCov, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFDepA.cc index c12ce5ab91..1aa6e439e1 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelECEFDepA.cc @@ -16,1117 +16,8768 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelECEFDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelECEFDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA0() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.x, 3034); + assign(test_msg_.y, -2682); + assign(test_msg_.z, -861); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xec50; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 246, 215, 20, 20, 46, 39, 0, 218, 11, 0, 0, + 134, 245, 255, 255, 163, 252, 255, 255, 0, 0, 9, 0, 80, 236, + }; + uint8_t encoded_payload_[20] = { + 20, 46, 39, 0, 218, 11, 0, 0, 134, 245, + 255, 255, 163, 252, 255, 255, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA1() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.x, 2884); + assign(test_msg_.y, -2536); + assign(test_msg_.z, -804); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8af8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 246, 215, 20, 120, 46, 39, 0, 68, 11, 0, 0, + 24, 246, 255, 255, 220, 252, 255, 255, 0, 0, 9, 0, 248, 138, + }; + uint8_t encoded_payload_[20] = { + 120, 46, 39, 0, 68, 11, 0, 0, 24, 246, + 255, 255, 220, 252, 255, 255, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA2() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.x, 2837); + assign(test_msg_.y, -2483); + assign(test_msg_.z, -777); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xae19; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 246, 215, 20, 220, 46, 39, 0, 21, 11, 0, 0, + 77, 246, 255, 255, 247, 252, 255, 255, 0, 0, 9, 0, 25, 174, + }; + uint8_t encoded_payload_[20] = { + 220, 46, 39, 0, 21, 11, 0, 0, 77, 246, + 255, 255, 247, 252, 255, 255, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA3() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568000); + assign(test_msg_.x, 2937); + assign(test_msg_.y, -2558); + assign(test_msg_.z, -790); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xe4c3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 246, 215, 20, 64, 47, 39, 0, 121, 11, 0, 0, + 2, 246, 255, 255, 234, 252, 255, 255, 0, 0, 9, 0, 195, 228, + }; + uint8_t encoded_payload_[20] = { + 64, 47, 39, 0, 121, 11, 0, 0, 2, 246, + 255, 255, 234, 252, 255, 255, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA4() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568100); + assign(test_msg_.x, 2847); + assign(test_msg_.y, -2467); + assign(test_msg_.z, -752); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xa4db; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 246, 215, 20, 164, 47, 39, 0, 31, 11, 0, 0, + 93, 246, 255, 255, 16, 253, 255, 255, 0, 0, 9, 0, 219, 164, + }; + uint8_t encoded_payload_[20] = { + 164, 47, 39, 0, 31, 11, 0, 0, 93, 246, + 255, 255, 16, 253, 255, 255, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA5() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084500); + assign(test_msg_.x, 24); + assign(test_msg_.y, -11); + assign(test_msg_.z, -37); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xff44; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 195, 4, 20, 212, 157, 67, 24, 24, 0, 0, 0, + 245, 255, 255, 255, 219, 255, 255, 255, 0, 0, 8, 0, 68, 255, + }; + uint8_t encoded_payload_[20] = { + 212, 157, 67, 24, 24, 0, 0, 0, 245, 255, + 255, 255, 219, 255, 255, 255, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA6() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084600); + assign(test_msg_.x, 4); + assign(test_msg_.y, -22); + assign(test_msg_.z, 18); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x88d6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 195, 4, 20, 56, 158, 67, 24, 4, 0, 0, 0, + 234, 255, 255, 255, 18, 0, 0, 0, 0, 0, 8, 0, 214, 136, + }; + uint8_t encoded_payload_[20] = { + 56, 158, 67, 24, 4, 0, 0, 0, 234, 255, 255, 255, 18, 0, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA7 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA7() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084700); + assign(test_msg_.x, -26); + assign(test_msg_.y, 4); + assign(test_msg_.z, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x9f7a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 195, 4, 20, 156, 158, 67, 24, 230, 255, 255, 255, + 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 0, 122, 159, + }; + uint8_t encoded_payload_[20] = { + 156, 158, 67, 24, 230, 255, 255, 255, 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA8 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelECEFDepA8() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084800); + assign(test_msg_.x, -9); + assign(test_msg_.y, -19); + assign(test_msg_.z, 28); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x92e8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 195, 4, 20, 0, 159, 67, 24, 247, 255, 255, 255, + 237, 255, 255, 255, 28, 0, 0, 0, 0, 0, 8, 0, 232, 146, + }; + uint8_t encoded_payload_[20] = { + 0, 159, 67, 24, 247, 255, 255, 255, 237, 255, + 255, 255, 28, 0, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA9 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelECEFDepA9() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084900); + assign(test_msg_.x, -1); + assign(test_msg_.y, 2); + assign(test_msg_.z, -11); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xeeab; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 4, 2, 195, 4, 20, 100, 159, 67, 24, 255, 255, 255, 255, + 2, 0, 0, 0, 245, 255, 255, 255, 0, 0, 8, 0, 171, 238, + }; + uint8_t encoded_payload_[20] = { + 100, 159, 67, 24, 255, 255, 255, 255, 2, 0, + 0, 0, 245, 255, 255, 255, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 246, 215, 20, 20, 46, 39, 0, 218, 11, 0, 0, - 134, 245, 255, 255, 163, 252, 255, 255, 0, 0, 9, 0, 80, 236, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.x = 3034; - test_msg.y = -2682; - test_msg.z = -861; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 3034) - << "incorrect value for last_msg_.x, expected 3034, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -2682) - << "incorrect value for last_msg_.y, expected -2682, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -861) - << "incorrect value for last_msg_.z, expected -861, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelECEFDepA10 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelECEFDepA10() { + assign(test_msg_.accuracy, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.n_sats, 5); + assign(test_msg_.tow, 407151150); + assign(test_msg_.x, -49); + assign(test_msg_.y, -71); + assign(test_msg_.z, 65); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 246, 215, 20, 120, 46, 39, 0, 68, 11, 0, 0, - 24, 246, 255, 255, 220, 252, 255, 255, 0, 0, 9, 0, 248, 138, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.x = 2884; - test_msg.y = -2536; - test_msg.z = -804; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 2884) - << "incorrect value for last_msg_.x, expected 2884, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -2536) - << "incorrect value for last_msg_.y, expected -2536, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -804) - << "incorrect value for last_msg_.z, expected -804, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 246, 215, 20, 220, 46, 39, 0, 21, 11, 0, 0, - 77, 246, 255, 255, 247, 252, 255, 255, 0, 0, 9, 0, 25, 174, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.x = 2837; - test_msg.y = -2483; - test_msg.z = -777; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 2837) - << "incorrect value for last_msg_.x, expected 2837, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -2483) - << "incorrect value for last_msg_.y, expected -2483, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -777) - << "incorrect value for last_msg_.z, expected -777, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 246, 215, 20, 64, 47, 39, 0, 121, 11, 0, 0, - 2, 246, 255, 255, 234, 252, 255, 255, 0, 0, 9, 0, 195, 228, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2568000; - test_msg.x = 2937; - test_msg.y = -2558; - test_msg.z = -790; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568000) - << "incorrect value for last_msg_.tow, expected 2568000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 2937) - << "incorrect value for last_msg_.x, expected 2937, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -2558) - << "incorrect value for last_msg_.y, expected -2558, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -790) - << "incorrect value for last_msg_.z, expected -790, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 246, 215, 20, 164, 47, 39, 0, 31, 11, 0, 0, - 93, 246, 255, 255, 16, 253, 255, 255, 0, 0, 9, 0, 219, 164, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 9; - test_msg.tow = 2568100; - test_msg.x = 2847; - test_msg.y = -2467; - test_msg.z = -752; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568100) - << "incorrect value for last_msg_.tow, expected 2568100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 2847) - << "incorrect value for last_msg_.x, expected 2847, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -2467) - << "incorrect value for last_msg_.y, expected -2467, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -752) - << "incorrect value for last_msg_.z, expected -752, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 195, 4, 20, 212, 157, 67, 24, 24, 0, 0, 0, - 245, 255, 255, 255, 219, 255, 255, 255, 0, 0, 8, 0, 68, 255, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084500; - test_msg.x = 24; - test_msg.y = -11; - test_msg.z = -37; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 24) - << "incorrect value for last_msg_.x, expected 24, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -11) - << "incorrect value for last_msg_.y, expected -11, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -37) - << "incorrect value for last_msg_.z, expected -37, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefDepA, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 195, 4, 20, 56, 158, 67, 24, 4, 0, 0, 0, - 234, 255, 255, 255, 18, 0, 0, 0, 0, 0, 8, 0, 214, 136, + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_dep_a, + sizeof(msg->vel_ecef_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084600; - test_msg.x = 4; - test_msg.y = -22; - test_msg.z = 18; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084600) - << "incorrect value for last_msg_.tow, expected 407084600, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 4) - << "incorrect value for last_msg_.x, expected 4, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -22) - << "incorrect value for last_msg_.y, expected -22, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 18) - << "incorrect value for last_msg_.z, expected 18, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_vel_ecef_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 195, 4, 20, 156, 158, 67, 24, 230, 255, 255, 255, - 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 0, 122, 159, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084700; - test_msg.x = -26; - test_msg.y = 4; - test_msg.z = 1; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084700) - << "incorrect value for last_msg_.tow, expected 407084700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -26) - << "incorrect value for last_msg_.x, expected -26, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 4) - << "incorrect value for last_msg_.y, expected 4, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 1) - << "incorrect value for last_msg_.z, expected 1, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x9a52; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ecef_dep_a_t &lesser, + const sbp_msg_vel_ecef_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 195, 4, 20, 0, 159, 67, 24, 247, 255, 255, 255, - 237, 255, 255, 255, 28, 0, 0, 0, 0, 0, 8, 0, 232, 146, - }; + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084800; - test_msg.x = -9; - test_msg.y = -19; - test_msg.z = 28; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084800) - << "incorrect value for last_msg_.tow, expected 407084800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -9) - << "incorrect value for last_msg_.x, expected -9, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -19) - << "incorrect value for last_msg_.y, expected -19, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 28) - << "incorrect value for last_msg_.z, expected 28, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 4, 2, 195, 4, 20, 100, 159, 67, 24, 255, 255, 255, 255, - 2, 0, 0, 0, 245, 255, 255, 255, 0, 0, 8, 0, 171, 238, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 8; - test_msg.tow = 407084900; - test_msg.x = -1; - test_msg.y = 2; - test_msg.z = -11; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084900) - << "incorrect value for last_msg_.tow, expected 407084900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -1) - << "incorrect value for last_msg_.x, expected -1, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 2) - << "incorrect value for last_msg_.y, expected 2, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, -11) - << "incorrect value for last_msg_.z, expected -11, is " << last_msg_.z; -} -class Test_auto_check_sbp_navigation_MsgVelECEFDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelECEFDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelECEFDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_vel_ecef_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 4, 2, 195, 4, 20, 46, 162, 68, 24, 207, 255, 255, 255, 185, 255, 255, 255, 65, 0, 0, 0, 0, 0, 5, 0, 82, 154, }; + uint8_t encoded_payload_[20] = { + 46, 162, 68, 24, 207, 255, 255, 255, 185, 255, + 255, 255, 65, 0, 0, 0, 0, 0, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - sbp_msg_vel_ecef_dep_a_t test_msg{}; - test_msg.accuracy = 0; - test_msg.flags = 0; - test_msg.n_sats = 5; - test_msg.tow = 407151150; - test_msg.x = -49; - test_msg.y = -71; - test_msg.z = 65; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 0) - << "incorrect value for last_msg_.accuracy, expected 0, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 5) - << "incorrect value for last_msg_.n_sats, expected 5, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407151150) - << "incorrect value for last_msg_.tow, expected 407151150, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -49) - << "incorrect value for last_msg_.x, expected -49, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, -71) - << "incorrect value for last_msg_.y, expected -71, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 65) - << "incorrect value for last_msg_.z, expected 65, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ecef_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelECEFDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefCovGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefCovGnss.cc index 2ae9141b0b..311177b4eb 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefCovGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefCovGnss.cc @@ -16,130 +16,854 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelEcefCovGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelEcefCovGnss0 + : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelEcefCovGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelEcefCovGnss0() { + assign(test_msg_.cov_x_x, 0.0024547684006392956); + assign(test_msg_.cov_x_y, 0.0021795108914375305); + assign(test_msg_.cov_x_z, -0.0016828652005642653); + assign(test_msg_.cov_y_y, 0.004218944814056158); + assign(test_msg_.cov_y_z, -0.0024961293675005436); + assign(test_msg_.cov_z_z, 0.0037804271560162306); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 21); + assign(test_msg_.tow, 501868000); + assign(test_msg_.x, -3); + assign(test_msg_.y, 1); + assign(test_msg_.z, 4); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_cov_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_cov_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefCovGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_cov_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefCovGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_cov_gnss, + sizeof(msg->vel_ecef_cov_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_cov_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_cov_gnss, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefCovGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0xe616; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_cov_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_cov_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ecef_cov_gnss_t &lesser, + const sbp_msg_vel_ecef_cov_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_cov_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_cov_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefCovGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelEcefCovGnss, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelEcefCovGnss, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelEcefCovGnss, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelEcefCovGnss0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_cov_gnss_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { 85, 53, 2, 0, 16, 42, 224, 229, 233, 29, 253, 255, 255, 255, 1, 0, 0, 0, 4, 0, 0, 0, 46, 224, 32, 59, 32, 214, 14, 59, 150, 147, 220, 186, 19, 63, 138, 59, 26, 150, 35, 187, 11, 193, 119, 59, 21, 2, 22, 230, }; + uint8_t encoded_payload_[42] = { + 224, 229, 233, 29, 253, 255, 255, 255, 1, 0, 0, 0, 4, 0, + 0, 0, 46, 224, 32, 59, 32, 214, 14, 59, 150, 147, 220, 186, + 19, 63, 138, 59, 26, 150, 35, 187, 11, 193, 119, 59, 21, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgVelEcefCovGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefCovGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ( + sbp_msg_vel_ecef_cov_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefCovGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_vel_ecef_cov_gnss_t test_msg{}; - test_msg.cov_x_x = 0.0024547684006392956; - test_msg.cov_x_y = 0.0021795108914375305; - test_msg.cov_x_z = -0.0016828652005642653; - test_msg.cov_y_y = 0.004218944814056158; - test_msg.cov_y_z = -0.0024961293675005436; - test_msg.cov_z_z = 0.0037804271560162306; - test_msg.flags = 2; - test_msg.n_sats = 21; - test_msg.tow = 501868000; - test_msg.x = -3; - test_msg.y = 1; - test_msg.z = 4; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_x_x * 100 - 0.00245476840064 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_x, expected 0.00245476840064, is " - << last_msg_.cov_x_x; - EXPECT_LT((last_msg_.cov_x_y * 100 - 0.00217951089144 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_y, expected 0.00217951089144, is " - << last_msg_.cov_x_y; - EXPECT_LT((last_msg_.cov_x_z * 100 - -0.00168286520056 * 100), 0.05) - << "incorrect value for last_msg_.cov_x_z, expected -0.00168286520056, " - "is " - << last_msg_.cov_x_z; - EXPECT_LT((last_msg_.cov_y_y * 100 - 0.00421894481406 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_y, expected 0.00421894481406, is " - << last_msg_.cov_y_y; - EXPECT_LT((last_msg_.cov_y_z * 100 - -0.0024961293675 * 100), 0.05) - << "incorrect value for last_msg_.cov_y_z, expected -0.0024961293675, is " - << last_msg_.cov_y_z; - EXPECT_LT((last_msg_.cov_z_z * 100 - 0.00378042715602 * 100), 0.05) - << "incorrect value for last_msg_.cov_z_z, expected 0.00378042715602, is " - << last_msg_.cov_z_z; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 21) - << "incorrect value for last_msg_.n_sats, expected 21, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501868000) - << "incorrect value for last_msg_.tow, expected 501868000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -3) - << "incorrect value for last_msg_.x, expected -3, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1) - << "incorrect value for last_msg_.y, expected 1, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 4) - << "incorrect value for last_msg_.z, expected 4, is " << last_msg_.z; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_cov_gnss_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefCovGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_x, greater.cov_x_x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_y, greater.cov_x_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_x_z, greater.cov_x_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_y, greater.cov_y_y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_y_z, greater.cov_y_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_z_z, greater.cov_z_z); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefCovGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_COV_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_cov_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_cov_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.vel_ecef_cov_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ecef_cov_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefCovGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefCovGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefCovGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefGnss.cc index 5d38db2857..de6bfda689 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelEcefGnss.cc @@ -16,107 +16,807 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelEcefGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelEcefGnss0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelEcefGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelEcefGnss0() { + assign(test_msg_.accuracy, 89); + assign(test_msg_.flags, 2); + assign(test_msg_.n_sats, 21); + assign(test_msg_.tow, 501868000); + assign(test_msg_.x, -3); + assign(test_msg_.y, 1); + assign(test_msg_.z, 4); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ecef_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelEcefGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ecef_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelEcefGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ecef_gnss, + sizeof(msg->vel_ecef_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ecef_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ecef_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelEcefGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0x10cd; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ecef_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ecef_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ecef_gnss_t &lesser, + const sbp_msg_vel_ecef_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ecef_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ecef_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ecef_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelEcefGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelEcefGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelEcefGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgVelEcefGnss0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ecef_gnss_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 45, 2, 0, 16, 20, 224, 229, 233, 29, 253, 255, 255, 255, 1, 0, 0, 0, 4, 0, 0, 0, 89, 0, 21, 2, 205, 16, }; + uint8_t encoded_payload_[20] = { + 224, 229, 233, 29, 253, 255, 255, 255, 1, 0, + 0, 0, 4, 0, 0, 0, 89, 0, 21, 2, + }; +}; - sbp_msg_vel_ecef_gnss_t test_msg{}; - test_msg.accuracy = 89; - test_msg.flags = 2; - test_msg.n_sats = 21; - test_msg.tow = 501868000; - test_msg.x = -3; - test_msg.y = 1; - test_msg.z = 4; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.accuracy, 89) - << "incorrect value for last_msg_.accuracy, expected 89, is " - << last_msg_.accuracy; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_sats, 21) - << "incorrect value for last_msg_.n_sats, expected 21, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501868000) - << "incorrect value for last_msg_.tow, expected 501868000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.x, -3) - << "incorrect value for last_msg_.x, expected -3, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 1) - << "incorrect value for last_msg_.y, expected 1, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 4) - << "incorrect value for last_msg_.z, expected 4, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ecef_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelEcefGnss, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelEcefGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_vel_ecef_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelEcefGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ecef_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelEcefGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelEcefGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.accuracy, greater.accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ecef_gnss_t lesser = info.test_msg; + sbp_msg_vel_ecef_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelEcefGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_ECEF_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ecef_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ecef_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ecef_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ecef_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ecef_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelEcefGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelEcefGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelEcefGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelNED.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelNED.cc index 9d6706314e..e9af0caa4f 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelNED.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelNED.cc @@ -16,531 +16,3929 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelNED0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelNED0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNED0() { + assign(test_msg_.d, -13); + assign(test_msg_.e, -4); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 3); + assign(test_msg_.n_sats, 14); + assign(test_msg_.tow, 326825000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNed, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned, sizeof(msg->vel_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xd156; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_t &lesser, + const sbp_msg_vel_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 14, 2, 211, 136, 22, 40, 244, 122, 19, 3, 0, 0, 0, 252, + 255, 255, 255, 243, 255, 255, 255, 0, 0, 0, 0, 14, 0, 86, 209, + }; + uint8_t encoded_payload_[22] = { + 40, 244, 122, 19, 3, 0, 0, 0, 252, 255, 255, + 255, 243, 255, 255, 255, 0, 0, 0, 0, 14, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelNed, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNed); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNed, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelNed, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNED1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNED1() { + assign(test_msg_.d, -24); + assign(test_msg_.e, -1); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -4); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326825500); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNed, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned, sizeof(msg->vel_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xe410; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_t &lesser, + const sbp_msg_vel_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 14, 2, 211, 136, 22, 28, 246, 122, 19, 252, 255, 255, 255, 255, + 255, 255, 255, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, 16, 228, + }; + uint8_t encoded_payload_[22] = { + 28, 246, 122, 19, 252, 255, 255, 255, 255, 255, 255, + 255, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelNed, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNed); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNed, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelNed, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNED2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNED2() { + assign(test_msg_.d, -12); + assign(test_msg_.e, -3); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 0); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNed, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned, sizeof(msg->vel_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xa40b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_t &lesser, + const sbp_msg_vel_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 14, 2, 211, 136, 22, 16, 248, 122, 19, 0, 0, 0, 0, 253, + 255, 255, 255, 244, 255, 255, 255, 0, 0, 0, 0, 15, 0, 11, 164, + }; + uint8_t encoded_payload_[22] = { + 16, 248, 122, 19, 0, 0, 0, 0, 253, 255, 255, + 255, 244, 255, 255, 255, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelNed, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNed); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNed, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelNed, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNED3 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNED0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNED3() { + assign(test_msg_.d, -24); + assign(test_msg_.e, 3); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 2); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326826500); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNed, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned, sizeof(msg->vel_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xd098; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_t &lesser, + const sbp_msg_vel_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 14, 2, 211, 136, 22, 4, 250, 122, 19, 2, 0, 0, 0, 3, + 0, 0, 0, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, 152, 208, + }; + uint8_t encoded_payload_[22] = { + 4, 250, 122, 19, 2, 0, 0, 0, 3, 0, 0, + 0, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelNed, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNed); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_NED"); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelNED0, Test) { - uint8_t encoded_frame[] = { - 85, 14, 2, 211, 136, 22, 40, 244, 122, 19, 3, 0, 0, 0, 252, - 255, 255, 255, 243, 255, 255, 255, 0, 0, 0, 0, 14, 0, 86, 209, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_vel_ned_t test_msg{}; - test_msg.d = -13; - test_msg.e = -4; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 3; - test_msg.n_sats = 14; - test_msg.tow = 326825000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -13) - << "incorrect value for last_msg_.d, expected -13, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -4) - << "incorrect value for last_msg_.e, expected -4, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 3) - << "incorrect value for last_msg_.n, expected 3, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 14) - << "incorrect value for last_msg_.n_sats, expected 14, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825000) - << "incorrect value for last_msg_.tow, expected 326825000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNED1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNED1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelNED1, Test) { - uint8_t encoded_frame[] = { - 85, 14, 2, 211, 136, 22, 28, 246, 122, 19, 252, 255, 255, 255, 255, - 255, 255, 255, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, 16, 228, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNed, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelNed, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_vel_ned_t test_msg{}; - test_msg.d = -24; - test_msg.e = -1; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -4; - test_msg.n_sats = 15; - test_msg.tow = 326825500; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -24) - << "incorrect value for last_msg_.d, expected -24, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -1) - << "incorrect value for last_msg_.e, expected -1, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -4) - << "incorrect value for last_msg_.n, expected -4, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326825500) - << "incorrect value for last_msg_.tow, expected 326825500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNED2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +class Testauto_check_sbp_navigation_MsgVelNED4 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNED2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNED4() { + assign(test_msg_.d, -21); + assign(test_msg_.e, 0); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 1); + assign(test_msg_.n_sats, 15); + assign(test_msg_.tow, 326827000); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgVelNED2, Test) { - uint8_t encoded_frame[] = { - 85, 14, 2, 211, 136, 22, 16, 248, 122, 19, 0, 0, 0, 0, 253, - 255, 255, 255, 244, 255, 255, 255, 0, 0, 0, 0, 15, 0, 11, 164, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_vel_ned_t test_msg{}; - test_msg.d = -12; - test_msg.e = -3; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 0; - test_msg.n_sats = 15; - test_msg.tow = 326826000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -12) - << "incorrect value for last_msg_.d, expected -12, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -3) - << "incorrect value for last_msg_.e, expected -3, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 0) - << "incorrect value for last_msg_.n, expected 0, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826000) - << "incorrect value for last_msg_.tow, expected 326826000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNED3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNED3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNED3, Test) { - uint8_t encoded_frame[] = { - 85, 14, 2, 211, 136, 22, 4, 250, 122, 19, 2, 0, 0, 0, 3, - 0, 0, 0, 232, 255, 255, 255, 0, 0, 0, 0, 15, 0, 152, 208, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_vel_ned_t test_msg{}; - test_msg.d = -24; - test_msg.e = 3; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 2; - test_msg.n_sats = 15; - test_msg.tow = 326826500; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -24) - << "incorrect value for last_msg_.d, expected -24, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3) - << "incorrect value for last_msg_.e, expected 3, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 2) - << "incorrect value for last_msg_.n, expected 2, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326826500) - << "incorrect value for last_msg_.tow, expected 326826500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNED4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNED4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNed, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNed); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned, sizeof(msg->vel_ned)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNed); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x78b6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ned_t &lesser, + const sbp_msg_vel_ned_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgVelNed, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgVelNed, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNED4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_vel_ned_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { 85, 14, 2, 211, 136, 22, 248, 251, 122, 19, 1, 0, 0, 0, 0, 0, 0, 0, 235, 255, 255, 255, 0, 0, 0, 0, 15, 0, 182, 120, }; + uint8_t encoded_payload_[22] = { + 248, 251, 122, 19, 1, 0, 0, 0, 0, 0, 0, + 0, 235, 255, 255, 255, 0, 0, 0, 0, 15, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNed, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgVelNed, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ( + sbp_msg_vel_ned_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNed, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_vel_ned_t test_msg{}; - test_msg.d = -21; - test_msg.e = 0; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 1; - test_msg.n_sats = 15; - test_msg.tow = 326827000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -21) - << "incorrect value for last_msg_.d, expected -21, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 0) - << "incorrect value for last_msg_.e, expected 0, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 1) - << "incorrect value for last_msg_.n, expected 1, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 15) - << "incorrect value for last_msg_.n_sats, expected 15, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 326827000) - << "incorrect value for last_msg_.tow, expected 326827000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNed, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_t lesser = info.test_msg; + sbp_msg_vel_ned_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNed); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_VEL_NED"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNed, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNED4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgVelNed, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDCOV.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDCOV.cc index 56d6ca0d05..d228b833d0 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDCOV.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDCOV.cc @@ -16,128 +16,836 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelNEDCOV0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelNEDCOV0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNEDCOV0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNEDCOV0() { + assign(test_msg_.cov_d_d, 1.0); + assign(test_msg_.cov_e_d, 1.0); + assign(test_msg_.cov_e_e, 1.0); + assign(test_msg_.cov_n_d, 1.0); + assign(test_msg_.cov_n_e, 1.0); + assign(test_msg_.cov_n_n, 1.0); + assign(test_msg_.d, 1); + assign(test_msg_.e, 1); + assign(test_msg_.flags, 0); + assign(test_msg_.n, 1); + assign(test_msg_.n_sats, 10); + assign(test_msg_.tow, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_cov_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_cov_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedCov, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_cov_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedCov); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_cov, sizeof(msg->vel_ned_cov)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_cov_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_cov, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedCov); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xCD58; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_cov_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_cov_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ned_cov_t &lesser, + const sbp_msg_vel_ned_cov_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cov_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cov_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cov_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cov_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedCov, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedCov, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedCov, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedCov, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDCOV0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_cov_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { 85, 18, 2, 66, 0, 42, 100, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 10, 0, 88, 205, }; + uint8_t encoded_payload_[42] = { + 100, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, 128, 63, 0, 0, 128, 63, 10, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_cov_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedCov, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_cov_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedCov, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ( + sbp_msg_vel_ned_cov_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ(sbp_msg_vel_ned_cov_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_cov_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedCov, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_cov_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_cov_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_vel_ned_cov_t test_msg{}; - test_msg.cov_d_d = 1.0; - test_msg.cov_e_d = 1.0; - test_msg.cov_e_e = 1.0; - test_msg.cov_n_d = 1.0; - test_msg.cov_n_e = 1.0; - test_msg.cov_n_n = 1.0; - test_msg.d = 1; - test_msg.e = 1; - test_msg.flags = 0; - test_msg.n = 1; - test_msg.n_sats = 10; - test_msg.tow = 100; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_d_d * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_d_d, expected 1.0, is " - << last_msg_.cov_d_d; - EXPECT_LT((last_msg_.cov_e_d * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_d, expected 1.0, is " - << last_msg_.cov_e_d; - EXPECT_LT((last_msg_.cov_e_e * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_e, expected 1.0, is " - << last_msg_.cov_e_e; - EXPECT_LT((last_msg_.cov_n_d * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_d, expected 1.0, is " - << last_msg_.cov_n_d; - EXPECT_LT((last_msg_.cov_n_e * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_e, expected 1.0, is " - << last_msg_.cov_n_e; - EXPECT_LT((last_msg_.cov_n_n * 100 - 1.0 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_n, expected 1.0, is " - << last_msg_.cov_n_n; - EXPECT_EQ(last_msg_.d, 1) - << "incorrect value for last_msg_.d, expected 1, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 1) - << "incorrect value for last_msg_.e, expected 1, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n, 1) - << "incorrect value for last_msg_.n, expected 1, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 10) - << "incorrect value for last_msg_.n_sats, expected 10, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 100) - << "incorrect value for last_msg_.tow, expected 100, is " - << last_msg_.tow; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_cov_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedCov, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedCov, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_d_d, greater.cov_d_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_d, greater.cov_e_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_e, greater.cov_e_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_d, greater.cov_n_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_e, greater.cov_n_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_n, greater.cov_n_n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgVelNedCov); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_COV"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_cov_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_cov_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_cov, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_cov, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedCov, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDCOV0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedCov, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDDepA.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDDepA.cc index 50b05b8aa4..55facb002a 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDDepA.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelNEDDepA.cc @@ -16,1161 +16,8803 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelNEDDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelNEDDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA0() { + assign(test_msg_.d, 0); + assign(test_msg_.e, 3996); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -1082); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x5ca1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 246, 215, 22, 20, 46, 39, 0, 198, 251, 255, 255, 156, + 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 161, 92, + }; + uint8_t encoded_payload_[22] = { + 20, 46, 39, 0, 198, 251, 255, 255, 156, 15, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA1() { + assign(test_msg_.d, 0); + assign(test_msg_.e, 3791); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -1010); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xa07d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 246, 215, 22, 120, 46, 39, 0, 14, 252, 255, 255, 207, + 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 125, 160, + }; + uint8_t encoded_payload_[22] = { + 120, 46, 39, 0, 14, 252, 255, 255, 207, 14, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA2() { + assign(test_msg_.d, 0); + assign(test_msg_.e, 3724); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -976); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2567900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x87b3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 246, 215, 22, 220, 46, 39, 0, 48, 252, 255, 255, 140, + 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 179, 135, + }; + uint8_t encoded_payload_[22] = { + 220, 46, 39, 0, 48, 252, 255, 255, 140, 14, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA3() { + assign(test_msg_.d, 0); + assign(test_msg_.e, 3848); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -992); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568000); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xb133; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 246, 215, 22, 64, 47, 39, 0, 32, 252, 255, 255, 8, + 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 51, 177, + }; + uint8_t encoded_payload_[22] = { + 64, 47, 39, 0, 32, 252, 255, 255, 8, 15, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA4() { + assign(test_msg_.d, 0); + assign(test_msg_.e, 3724); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -944); + assign(test_msg_.n_sats, 9); + assign(test_msg_.tow, 2568100); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x17; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 246, 215, 22, 164, 47, 39, 0, 80, 252, 255, 255, 140, + 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 23, 0, + }; + uint8_t encoded_payload_[22] = { + 164, 47, 39, 0, 80, 252, 255, 255, 140, 14, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA5() { + assign(test_msg_.d, 25); + assign(test_msg_.e, 26); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -27); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084500); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x1984; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 195, 4, 22, 212, 157, 67, 24, 229, 255, 255, 255, 26, + 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 8, 0, 132, 25, + }; + uint8_t encoded_payload_[22] = { + 212, 157, 67, 24, 229, 255, 255, 255, 26, 0, 0, + 0, 25, 0, 0, 0, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA6 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA6() { + assign(test_msg_.d, -24); + assign(test_msg_.e, 15); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 4); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084600); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe2a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 195, 4, 22, 56, 158, 67, 24, 4, 0, 0, 0, 15, + 0, 0, 0, 232, 255, 255, 255, 0, 0, 0, 0, 8, 0, 42, 14, + }; + uint8_t encoded_payload_[22] = { + 56, 158, 67, 24, 4, 0, 0, 0, 15, 0, 0, + 0, 232, 255, 255, 255, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA7 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA7() { + assign(test_msg_.d, -9); + assign(test_msg_.e, -24); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -5); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084700); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x94da; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 195, 4, 22, 156, 158, 67, 24, 251, 255, 255, 255, 232, + 255, 255, 255, 247, 255, 255, 255, 0, 0, 0, 0, 8, 0, 218, 148, + }; + uint8_t encoded_payload_[22] = { + 156, 158, 67, 24, 251, 255, 255, 255, 232, 255, 255, + 255, 247, 255, 255, 255, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA8 : public ::testing::Test { + public: + Testauto_check_sbp_navigation_MsgVelNEDDepA8() { + assign(test_msg_.d, -34); + assign(test_msg_.e, 2); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, 10); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084800); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x1094; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 195, 4, 22, 0, 159, 67, 24, 10, 0, 0, 0, 2, + 0, 0, 0, 222, 255, 255, 255, 0, 0, 0, 0, 8, 0, 148, 16, + }; + uint8_t encoded_payload_[22] = { + 0, 159, 67, 24, 10, 0, 0, 0, 2, 0, 0, + 0, 222, 255, 255, 255, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA9 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNEDDepA9() { + assign(test_msg_.d, 7); + assign(test_msg_.e, -2); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -8); + assign(test_msg_.n_sats, 8); + assign(test_msg_.tow, 407084900); + assign(test_msg_.v_accuracy, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xecff; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { + 85, 5, 2, 195, 4, 22, 100, 159, 67, 24, 248, 255, 255, 255, 254, + 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 255, 236, + }; + uint8_t encoded_payload_[22] = { + 100, 159, 67, 24, 248, 255, 255, 255, 254, 255, 255, + 255, 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 246, 215, 22, 20, 46, 39, 0, 198, 251, 255, 255, 156, - 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 161, 92, - }; +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = 3996; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -1082; - test_msg.n_sats = 9; - test_msg.tow = 2567700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3996) - << "incorrect value for last_msg_.e, expected 3996, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -1082) - << "incorrect value for last_msg_.n, expected -1082, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567700) - << "incorrect value for last_msg_.tow, expected 2567700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_navigation_MsgVelNEDDepA10 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNEDDepA10() { + assign(test_msg_.d, -108); + assign(test_msg_.e, -3); + assign(test_msg_.flags, 0); + assign(test_msg_.h_accuracy, 0); + assign(test_msg_.n, -1); + assign(test_msg_.n_sats, 5); + assign(test_msg_.tow, 407151150); + assign(test_msg_.v_accuracy, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 246, 215, 22, 120, 46, 39, 0, 14, 252, 255, 255, 207, - 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 125, 160, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = 3791; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -1010; - test_msg.n_sats = 9; - test_msg.tow = 2567800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3791) - << "incorrect value for last_msg_.e, expected 3791, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -1010) - << "incorrect value for last_msg_.n, expected -1010, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567800) - << "incorrect value for last_msg_.tow, expected 2567800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 246, 215, 22, 220, 46, 39, 0, 48, 252, 255, 255, 140, - 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 179, 135, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = 3724; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -976; - test_msg.n_sats = 9; - test_msg.tow = 2567900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3724) - << "incorrect value for last_msg_.e, expected 3724, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -976) - << "incorrect value for last_msg_.n, expected -976, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2567900) - << "incorrect value for last_msg_.tow, expected 2567900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 246, 215, 22, 64, 47, 39, 0, 32, 252, 255, 255, 8, - 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 51, 177, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = 3848; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -992; - test_msg.n_sats = 9; - test_msg.tow = 2568000; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3848) - << "incorrect value for last_msg_.e, expected 3848, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -992) - << "incorrect value for last_msg_.n, expected -992, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568000) - << "incorrect value for last_msg_.tow, expected 2568000, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 246, 215, 22, 164, 47, 39, 0, 80, 252, 255, 255, 140, - 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 23, 0, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 0; - test_msg.e = 3724; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -944; - test_msg.n_sats = 9; - test_msg.tow = 2568100; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 0) - << "incorrect value for last_msg_.d, expected 0, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 3724) - << "incorrect value for last_msg_.e, expected 3724, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -944) - << "incorrect value for last_msg_.n, expected -944, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 9) - << "incorrect value for last_msg_.n_sats, expected 9, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 2568100) - << "incorrect value for last_msg_.tow, expected 2568100, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 195, 4, 22, 212, 157, 67, 24, 229, 255, 255, 255, 26, - 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 8, 0, 132, 25, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 25; - test_msg.e = 26; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -27; - test_msg.n_sats = 8; - test_msg.tow = 407084500; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 25) - << "incorrect value for last_msg_.d, expected 25, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 26) - << "incorrect value for last_msg_.e, expected 26, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -27) - << "incorrect value for last_msg_.n, expected -27, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084500) - << "incorrect value for last_msg_.tow, expected 407084500, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedDepA, &CHandler::callback_static, + this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA6, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 195, 4, 22, 56, 158, 67, 24, 4, 0, 0, 0, 15, - 0, 0, 0, 232, 255, 255, 255, 0, 0, 0, 0, 8, 0, 42, 14, + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_dep_a, + sizeof(msg->vel_ned_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = -24; - test_msg.e = 15; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 4; - test_msg.n_sats = 8; - test_msg.tow = 407084600; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -24) - << "incorrect value for last_msg_.d, expected -24, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 15) - << "incorrect value for last_msg_.e, expected 15, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 4) - << "incorrect value for last_msg_.n, expected 4, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084600) - << "incorrect value for last_msg_.tow, expected 407084600, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_vel_ned_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA7, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 195, 4, 22, 156, 158, 67, 24, 251, 255, 255, 255, 232, - 255, 255, 255, 247, 255, 255, 255, 0, 0, 0, 0, 8, 0, 218, 148, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = -9; - test_msg.e = -24; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -5; - test_msg.n_sats = 8; - test_msg.tow = 407084700; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -9) - << "incorrect value for last_msg_.d, expected -9, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -24) - << "incorrect value for last_msg_.e, expected -24, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -5) - << "incorrect value for last_msg_.n, expected -5, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084700) - << "incorrect value for last_msg_.tow, expected 407084700, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xbda6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ned_dep_a_t &lesser, + const sbp_msg_vel_ned_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA8, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 195, 4, 22, 0, 159, 67, 24, 10, 0, 0, 0, 2, - 0, 0, 0, 222, 255, 255, 255, 0, 0, 0, 0, 8, 0, 148, 16, - }; + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_dep_a_cmp(&greater, &lesser), 0); - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = -34; - test_msg.e = 2; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = 10; - test_msg.n_sats = 8; - test_msg.tow = 407084800; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -34) - << "incorrect value for last_msg_.d, expected -34, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 2) - << "incorrect value for last_msg_.e, expected 2, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, 10) - << "incorrect value for last_msg_.n, expected 10, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084800) - << "incorrect value for last_msg_.tow, expected 407084800, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA9, Test) { - uint8_t encoded_frame[] = { - 85, 5, 2, 195, 4, 22, 100, 159, 67, 24, 248, 255, 255, 255, 254, - 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 255, 236, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = 7; - test_msg.e = -2; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -8; - test_msg.n_sats = 8; - test_msg.tow = 407084900; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, 7) - << "incorrect value for last_msg_.d, expected 7, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -2) - << "incorrect value for last_msg_.e, expected -2, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -8) - << "incorrect value for last_msg_.n, expected -8, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 8) - << "incorrect value for last_msg_.n_sats, expected 8, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407084900) - << "incorrect value for last_msg_.tow, expected 407084900, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; -} -class Test_auto_check_sbp_navigation_MsgVelNEDDepA10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_navigation_MsgVelNEDDepA10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNEDDepA10, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_vel_ned_dep_a_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { 85, 5, 2, 195, 4, 22, 46, 162, 68, 24, 255, 255, 255, 255, 253, 255, 255, 255, 148, 255, 255, 255, 0, 0, 0, 0, 5, 0, 166, 189, }; + uint8_t encoded_payload_[22] = { + 46, 162, 68, 24, 255, 255, 255, 255, 253, 255, 255, + 255, 148, 255, 255, 255, 0, 0, 0, 0, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_vel_ned_dep_a_t test_msg{}; - test_msg.d = -108; - test_msg.e = -3; - test_msg.flags = 0; - test_msg.h_accuracy = 0; - test_msg.n = -1; - test_msg.n_sats = 5; - test_msg.tow = 407151150; - test_msg.v_accuracy = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -108) - << "incorrect value for last_msg_.d, expected -108, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, -3) - << "incorrect value for last_msg_.e, expected -3, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 0) - << "incorrect value for last_msg_.h_accuracy, expected 0, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -1) - << "incorrect value for last_msg_.n, expected -1, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 5) - << "incorrect value for last_msg_.n_sats, expected 5, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 407151150) - << "incorrect value for last_msg_.tow, expected 407151150, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 0) - << "incorrect value for last_msg_.v_accuracy, expected 0, is " - << last_msg_.v_accuracy; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_dep_a_t lesser = info.test_msg; + sbp_msg_vel_ned_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_dep_a, info.test_msg); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNEDDepA10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelNedCovGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelNedCovGnss.cc index 4f72fffbe8..088835c0f2 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelNedCovGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelNedCovGnss.cc @@ -16,133 +16,852 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelNedCovGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelNedCovGnss0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNedCovGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNedCovGnss0() { + assign(test_msg_.cov_d_d, 0.007882959209382534); + assign(test_msg_.cov_e_d, 0.00016467059322167188); + assign(test_msg_.cov_e_e, 0.0009897587588056922); + assign(test_msg_.cov_n_d, 0.00017716512957122177); + assign(test_msg_.cov_n_e, 1.457612233934924e-05); + assign(test_msg_.cov_n_n, 0.0015810149488970637); + assign(test_msg_.d, -10); + assign(test_msg_.e, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.n, -5); + assign(test_msg_.n_sats, 21); + assign(test_msg_.tow, 501868200); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_cov_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_cov_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedCovGnss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_cov_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedCovGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_cov_gnss, + sizeof(msg->vel_ned_cov_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_cov_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_cov_gnss, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedCovGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0x39b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 42; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_cov_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_cov_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ned_cov_gnss_t &lesser, + const sbp_msg_vel_ned_cov_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_cov_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_cov_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedCovGnss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgVelNedCovGnss, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedCovGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedCovGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_navigation_MsgVelNedCovGnss0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_cov_gnss_t test_msg_{}; + uint8_t encoded_frame_[42 + 8] = { 85, 50, 2, 0, 16, 42, 168, 230, 233, 29, 251, 255, 255, 255, 0, 0, 0, 0, 246, 255, 255, 255, 15, 58, 207, 58, 248, 139, 116, 55, 103, 197, 57, 57, 203, 186, 129, 58, 109, 171, 44, 57, 135, 39, 1, 60, 21, 2, 155, 3, }; + uint8_t encoded_payload_[42] = { + 168, 230, 233, 29, 251, 255, 255, 255, 0, 0, 0, 0, 246, 255, + 255, 255, 15, 58, 207, 58, 248, 139, 116, 55, 103, 197, 57, 57, + 203, 186, 129, 58, 109, 171, 44, 57, 135, 39, 1, 60, 21, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgVelNedCovGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedCovGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + + for (uint8_t i = 0; i < 42; i++) { + EXPECT_EQ( + sbp_msg_vel_ned_cov_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedCovGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_vel_ned_cov_gnss_t test_msg{}; - test_msg.cov_d_d = 0.007882959209382534; - test_msg.cov_e_d = 0.00016467059322167188; - test_msg.cov_e_e = 0.0009897587588056922; - test_msg.cov_n_d = 0.00017716512957122177; - test_msg.cov_n_e = 1.457612233934924e-05; - test_msg.cov_n_n = 0.0015810149488970637; - test_msg.d = -10; - test_msg.e = 0; - test_msg.flags = 2; - test_msg.n = -5; - test_msg.n_sats = 21; - test_msg.tow = 501868200; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.cov_d_d * 100 - 0.00788295920938 * 100), 0.05) - << "incorrect value for last_msg_.cov_d_d, expected 0.00788295920938, is " - << last_msg_.cov_d_d; - EXPECT_LT((last_msg_.cov_e_d * 100 - 0.000164670593222 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_d, expected 0.000164670593222, " - "is " - << last_msg_.cov_e_d; - EXPECT_LT((last_msg_.cov_e_e * 100 - 0.000989758758806 * 100), 0.05) - << "incorrect value for last_msg_.cov_e_e, expected 0.000989758758806, " - "is " - << last_msg_.cov_e_e; - EXPECT_LT((last_msg_.cov_n_d * 100 - 0.000177165129571 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_d, expected 0.000177165129571, " - "is " - << last_msg_.cov_n_d; - EXPECT_LT((last_msg_.cov_n_e * 100 - 1.45761223393e-05 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_e, expected 1.45761223393e-05, " - "is " - << last_msg_.cov_n_e; - EXPECT_LT((last_msg_.cov_n_n * 100 - 0.0015810149489 * 100), 0.05) - << "incorrect value for last_msg_.cov_n_n, expected 0.0015810149489, is " - << last_msg_.cov_n_n; - EXPECT_EQ(last_msg_.d, -10) - << "incorrect value for last_msg_.d, expected -10, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 0) - << "incorrect value for last_msg_.e, expected 0, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n, -5) - << "incorrect value for last_msg_.n, expected -5, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 21) - << "incorrect value for last_msg_.n_sats, expected 21, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501868200) - << "incorrect value for last_msg_.tow, expected 501868200, is " - << last_msg_.tow; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_cov_gnss_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedCovGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedCovGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_d_d, greater.cov_d_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_d, greater.cov_e_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_e_e, greater.cov_e_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_d, greater.cov_n_d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_e, greater.cov_n_e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.cov_n_n, greater.cov_n_n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_cov_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_cov_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedCovGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_COV_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_cov_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_cov_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_cov_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.vel_ned_cov_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[42]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 42); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 42), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_cov_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 42); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedCovGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedCovGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedCovGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_MsgVelNedGnss.cc b/c/test/cpp/auto_check_sbp_navigation_MsgVelNedGnss.cc index 84cf898a38..73bce524c1 100644 --- a/c/test/cpp/auto_check_sbp_navigation_MsgVelNedGnss.cc +++ b/c/test/cpp/auto_check_sbp_navigation_MsgVelNedGnss.cc @@ -16,111 +16,811 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_navigation_MsgVelNedGnss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_navigation_MsgVelNedGnss0 : public ::testing::Test { public: - Test_auto_check_sbp_navigation_MsgVelNedGnss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_navigation_MsgVelNedGnss0() { + assign(test_msg_.d, -10); + assign(test_msg_.e, 0); + assign(test_msg_.flags, 2); + assign(test_msg_.h_accuracy, 40); + assign(test_msg_.n, -5); + assign(test_msg_.n_sats, 21); + assign(test_msg_.tow, 501868200); + assign(test_msg_.v_accuracy, 89); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_gnss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_vel_ned_gnss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgVelNedGnss, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_vel_ned_gnss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgVelNedGnss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->vel_ned_gnss, + sizeof(msg->vel_ned_gnss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_vel_ned_gnss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.vel_ned_gnss, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgVelNedGnss); + info.sender_id = 4096; + info.preamble = 0x55; + info.crc = 0xab63; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 22; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_vel_ned_gnss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_vel_ned_gnss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_vel_ned_gnss_t &lesser, + const sbp_msg_vel_ned_gnss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_vel_ned_gnss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_vel_ned_gnss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_vel_ned_gnss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_vel_ned_gnss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedGnss, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgVelNedGnss, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgVelNedGnss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgVelNedGnss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_navigation_MsgVelNedGnss0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_vel_ned_gnss_t test_msg_{}; + uint8_t encoded_frame_[22 + 8] = { 85, 46, 2, 0, 16, 22, 168, 230, 233, 29, 251, 255, 255, 255, 0, 0, 0, 0, 246, 255, 255, 255, 40, 0, 89, 0, 21, 2, 99, 171, }; + uint8_t encoded_payload_[22] = { + 168, 230, 233, 29, 251, 255, 255, 255, 0, 0, 0, + 0, 246, 255, 255, 255, 40, 0, 89, 0, 21, 2, + }; +}; + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_vel_ned_gnss_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgVelNedGnss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_vel_ned_gnss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgVelNedGnss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + EXPECT_EQ(sbp_msg_vel_ned_gnss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_msg_vel_ned_gnss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_vel_ned_gnss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgVelNedGnss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_gnss_t msg{}; + + EXPECT_EQ(sbp_msg_vel_ned_gnss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_gnss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_vel_ned_gnss_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_vel_ned_gnss_t test_msg{}; - test_msg.d = -10; - test_msg.e = 0; - test_msg.flags = 2; - test_msg.h_accuracy = 40; - test_msg.n = -5; - test_msg.n_sats = 21; - test_msg.tow = 501868200; - test_msg.v_accuracy = 89; - - EXPECT_EQ(send_message(4096, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.d, -10) - << "incorrect value for last_msg_.d, expected -10, is " << last_msg_.d; - EXPECT_EQ(last_msg_.e, 0) - << "incorrect value for last_msg_.e, expected 0, is " << last_msg_.e; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.h_accuracy, 40) - << "incorrect value for last_msg_.h_accuracy, expected 40, is " - << last_msg_.h_accuracy; - EXPECT_EQ(last_msg_.n, -5) - << "incorrect value for last_msg_.n, expected -5, is " << last_msg_.n; - EXPECT_EQ(last_msg_.n_sats, 21) - << "incorrect value for last_msg_.n_sats, expected 21, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.tow, 501868200) - << "incorrect value for last_msg_.tow, expected 501868200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.v_accuracy, 89) - << "incorrect value for last_msg_.v_accuracy, expected 89, is " - << last_msg_.v_accuracy; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_vel_ned_gnss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgVelNedGnss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgVelNedGnss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.d, greater.d); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.e, greater.e); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.h_accuracy, greater.h_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n, greater.n); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_vel_ned_gnss_t lesser = info.test_msg; + sbp_msg_vel_ned_gnss_t greater = info.test_msg; + make_lesser_greater(lesser.v_accuracy, greater.v_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgVelNedGnss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_VEL_NED_GNSS"); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_vel_ned_gnss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_vel_ned_gnss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.vel_ned_gnss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.vel_ned_gnss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[22]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 22), 0); } + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_vel_ned_gnss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 22); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgVelNedGnss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_navigation_MsgVelNedGnss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgVelNedGnss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_navigation_navigation_structs.cc b/c/test/cpp/auto_check_sbp_navigation_navigation_structs.cc new file mode 100644 index 0000000000..efdcafdea8 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_navigation_navigation_structs.cc @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_navigation_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_navigation_navigation_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_navigation_navigation_structs0() { + assign(test_struct_.orientation, 91.199997); + assign(test_struct_.semi_major, 4869.200195); + assign(test_struct_.semi_minor, 5968.200195); + } + + struct TestStructInfo { + sbp_estimated_horizontal_error_ellipse_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_estimated_horizontal_error_ellipse_t test_struct_{}; + uint8_t encoded_data_[12] = { + 154, 41, 152, 69, 154, 129, 186, 69, 102, 102, 182, 66, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ( + sbp_estimated_horizontal_error_ellipse_encoded_len(&info.test_struct), + 12); +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[12]; + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[12]; + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 12), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[12]; + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_estimated_horizontal_error_ellipse_t t{}; + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_decode(info.encoded_data, 12, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_cmp(&t, &info.test_struct), + 0); +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_estimated_horizontal_error_ellipse_t t{}; + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_decode(info.encoded_data, 12, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_cmp(&t, &info.test_struct), + 0); +} + +TEST_F(Test_Struct_auto_check_sbp_navigation_navigation_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_estimated_horizontal_error_ellipse_t t{}; + + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_estimated_horizontal_error_ellipse_decode(info.encoded_data, + i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc b/c/test/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc new file mode 100644 index 0000000000..71c3412154 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc @@ -0,0 +1,824 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ndb_MsgNdbEvent0 : public ::testing::Test { + public: + Testauto_check_sbp_ndb_MsgNdbEvent0() { + assign(test_msg_.data_source, 115); + assign(test_msg_.event, 249); + assign(test_msg_.object_sid.code, 74); + assign(test_msg_.object_sid.sat, 238); + assign(test_msg_.object_type, 73); + assign(test_msg_.original_sender, 38070); + assign(test_msg_.recv_time, 299461164286); + assign(test_msg_.result, 205); + assign(test_msg_.src_sid.code, 66); + assign(test_msg_.src_sid.sat, 98); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ndb_event_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ndb_event_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNdbEvent, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ndb_event_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNdbEvent); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ndb_event, sizeof(msg->ndb_event)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ndb_event_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ndb_event, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNdbEvent); + info.sender_id = 44708; + info.preamble = 0x55; + info.crc = 0xa610; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 18; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ndb_event_t &lesser, + const sbp_msg_ndb_event_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ndb_event_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ndb_event_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ndb_event_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ndb_event_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNdbEvent, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgNdbEvent, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgNdbEvent, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgNdbEvent, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ndb_event_t test_msg_{}; + uint8_t encoded_frame_[18 + 8] = { + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, + 0, 249, 73, 205, 115, 238, 74, 98, 66, 182, 148, 16, 166, + }; + uint8_t encoded_payload_[18] = { + 254, 188, 70, 185, 69, 0, 0, 0, 249, + 73, 205, 115, 238, 74, 98, 66, 182, 148, + }; +}; + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ndb_event_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgNdbEvent, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ndb_event_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgNdbEvent, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + + EXPECT_EQ( + sbp_msg_ndb_event_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + + for (uint8_t i = 0; i < 18; i++) { + EXPECT_EQ(sbp_msg_ndb_event_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ndb_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ndb_event_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgNdbEvent, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ndb_event_t msg{}; + + EXPECT_EQ(sbp_msg_ndb_event_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ndb_event_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_ndb_event_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ndb_event_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNdbEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgNdbEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNdbEvent, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.data_source, greater.data_source); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.event, greater.event); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.object_sid.code, greater.object_sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.object_sid.sat, greater.object_sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.object_type, greater.object_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.original_sender, greater.original_sender); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.result, greater.result); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.src_sid.code, greater.src_sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ndb_event_t lesser = info.test_msg; + sbp_msg_ndb_event_t greater = info.test_msg; + make_lesser_greater(lesser.src_sid.sat, greater.src_sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgNdbEvent); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_NDB_EVENT"); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ndb_event_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ndb_event_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ndb_event, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ndb_event, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[18]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 18), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ndb_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 18); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNdbEvent, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ndb_MsgNdbEvent0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgNdbEvent, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc new file mode 100644 index 0000000000..6a586ada48 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc @@ -0,0 +1,882 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgAlmanacGLO0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgAlmanacGLO0() { + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toa.tow, 446384); + assign(test_msg_.common.toa.wn, 2154); + assign(test_msg_.common.ura, 2.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.epsilon, -0.9893036629599647); + assign(test_msg_.i, 5153.550029754639); + assign(test_msg_.lambda_na, -0.02200078842114688); + assign(test_msg_.omega, 0.9341514480259797); + assign(test_msg_.t, -1.8731818448797617); + assign(test_msg_.t_dot, -8.903585155774196e-09); + assign(test_msg_.t_lambda_na, 0.007072207052260637); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_glo_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_almanac_glo_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAlmanacGlo, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_glo_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAlmanacGlo); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->almanac_glo, sizeof(msg->almanac_glo)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_almanac_glo_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.almanac_glo, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAlmanacGlo); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x579b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 78; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_almanac_glo_t &lesser, + const sbp_msg_almanac_glo_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_almanac_glo_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_almanac_glo_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_almanac_glo_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_almanac_glo_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGlo, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGlo, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAlmanacGlo, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAlmanacGlo, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_almanac_glo_t test_msg_{}; + uint8_t encoded_frame_[78 + 8] = { + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, 8, 154, + 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, + 191, 71, 11, 217, 147, 145, 228, 237, 63, 155, 87, + }; + uint8_t encoded_payload_[78] = { + 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, + 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, + 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_almanac_glo_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAlmanacGlo, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_almanac_glo_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAlmanacGlo, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + + EXPECT_EQ( + sbp_msg_almanac_glo_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + + for (uint8_t i = 0; i < 78; i++) { + EXPECT_EQ(sbp_msg_almanac_glo_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_almanac_glo_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAlmanacGlo, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_t msg{}; + + EXPECT_EQ(sbp_msg_almanac_glo_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_almanac_glo_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_almanac_glo_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGlo, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAlmanacGlo, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGlo, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.tow, greater.common.toa.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.wn, greater.common.toa.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.epsilon, greater.epsilon); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.i, greater.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.lambda_na, greater.lambda_na); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.omega, greater.omega); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.t, greater.t); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.t_dot, greater.t_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_t lesser = info.test_msg; + sbp_msg_almanac_glo_t greater = info.test_msg; + make_lesser_greater(lesser.t_lambda_na, greater.t_lambda_na); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgAlmanacGlo); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ALMANAC_GLO"); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_almanac_glo_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_almanac_glo_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.almanac_glo, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.almanac_glo, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAlmanacGlo, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLO0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAlmanacGlo, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc new file mode 100644 index 0000000000..a6fba0024b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc @@ -0,0 +1,904 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgAlmanacGLODep0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgAlmanacGLODep0() { + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.reserved, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toa.tow, 446384); + assign(test_msg_.common.toa.wn, 2154); + assign(test_msg_.common.ura, 2.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.epsilon, -0.9893036629599647); + assign(test_msg_.i, 5153.550029754639); + assign(test_msg_.lambda_na, -0.02200078842114688); + assign(test_msg_.omega, 0.9341514480259797); + assign(test_msg_.t, -1.8731818448797617); + assign(test_msg_.t_dot, -8.903585155774196e-09); + assign(test_msg_.t_lambda_na, 0.007072207052260637); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_glo_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_almanac_glo_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAlmanacGloDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_glo_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAlmanacGloDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->almanac_glo_dep, + sizeof(msg->almanac_glo_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_almanac_glo_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.almanac_glo_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAlmanacGloDep); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb2cb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 80; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_almanac_glo_dep_t &lesser, + const sbp_msg_almanac_glo_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_almanac_glo_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_almanac_glo_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_almanac_glo_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_almanac_glo_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGloDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAlmanacGloDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAlmanacGloDep, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAlmanacGloDep, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_almanac_glo_dep_t test_msg_{}; + uint8_t encoded_frame_[80 + 8] = { + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, + 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 203, 178, + }; + uint8_t encoded_payload_[80] = { + 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, + 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, + 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, + 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_almanac_glo_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAlmanacGloDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[80]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_almanac_glo_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 80); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 80), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAlmanacGloDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 80); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 80), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[80]; + + EXPECT_EQ(sbp_msg_almanac_glo_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 80), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[80]; + + for (uint8_t i = 0; i < 80; i++) { + EXPECT_EQ( + sbp_msg_almanac_glo_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_almanac_glo_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 80); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAlmanacGloDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 80); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_dep_t msg{}; + + EXPECT_EQ(sbp_msg_almanac_glo_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_almanac_glo_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_almanac_glo_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGloDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAlmanacGloDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGloDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.reserved, + greater.common.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.tow, greater.common.toa.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.wn, greater.common.toa.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.epsilon, greater.epsilon); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.i, greater.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lambda_na, greater.lambda_na); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.omega, greater.omega); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t, greater.t); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t_dot, greater.t_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_glo_dep_t lesser = info.test_msg; + sbp_msg_almanac_glo_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t_lambda_na, greater.t_lambda_na); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAlmanacGloDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ALMANAC_GLO_DEP"); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_almanac_glo_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_almanac_glo_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.almanac_glo_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.almanac_glo_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[80]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 80); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 80), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_glo_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 80); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAlmanacGloDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGLODep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAlmanacGloDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc new file mode 100644 index 0000000000..996fcac6a9 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc @@ -0,0 +1,898 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgAlmanacGPS0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgAlmanacGPS0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toa.tow, 446384); + assign(test_msg_.common.toa.wn, 2154); + assign(test_msg_.common.ura, 2.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_gps_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_almanac_gps_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAlmanacGps, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_gps_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAlmanacGps); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->almanac_gps, sizeof(msg->almanac_gps)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_almanac_gps_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.almanac_gps, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAlmanacGps); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x2dbe; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 94; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_almanac_gps_t &lesser, + const sbp_msg_almanac_gps_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_almanac_gps_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_almanac_gps_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_almanac_gps_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_almanac_gps_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGps, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGps, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAlmanacGps, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAlmanacGps, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_almanac_gps_t test_msg_{}; + uint8_t encoded_frame_[94 + 8] = { + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, 8, 154, + 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, + 191, 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + }; + uint8_t encoded_payload_[94] = { + 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, 153, + 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, + 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_almanac_gps_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAlmanacGps, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[94]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_almanac_gps_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 94); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 94), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAlmanacGps, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 94); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 94), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[94]; + + EXPECT_EQ( + sbp_msg_almanac_gps_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 94), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[94]; + + for (uint8_t i = 0; i < 94; i++) { + EXPECT_EQ(sbp_msg_almanac_gps_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_almanac_gps_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 94); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAlmanacGps, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 94); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_t msg{}; + + EXPECT_EQ(sbp_msg_almanac_gps_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_almanac_gps_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_almanac_gps_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGps, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAlmanacGps, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGps, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.tow, greater.common.toa.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.wn, greater.common.toa.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_t lesser = info.test_msg; + sbp_msg_almanac_gps_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgAlmanacGps); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ALMANAC_GPS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_almanac_gps_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_almanac_gps_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.almanac_gps, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.almanac_gps, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[94]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 94); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 94), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 94); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAlmanacGps, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAlmanacGps, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc new file mode 100644 index 0000000000..a6bf819b8c --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc @@ -0,0 +1,920 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgAlmanacGPSDep0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgAlmanacGPSDep0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.reserved, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toa.tow, 446384); + assign(test_msg_.common.toa.wn, 2154); + assign(test_msg_.common.ura, 2.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_gps_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_almanac_gps_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAlmanacGpsDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_gps_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAlmanacGpsDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->almanac_gps_dep, + sizeof(msg->almanac_gps_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_almanac_gps_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.almanac_gps_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAlmanacGpsDep); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe890; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 96; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_almanac_gps_dep_t &lesser, + const sbp_msg_almanac_gps_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_almanac_gps_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_almanac_gps_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_almanac_gps_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_almanac_gps_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanacGpsDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgAlmanacGpsDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAlmanacGpsDep, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAlmanacGpsDep, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_almanac_gps_dep_t test_msg_{}; + uint8_t encoded_frame_[96 + 8] = { + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, + 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, + 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 144, 232, + }; + uint8_t encoded_payload_[96] = { + 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, + 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, + 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, + 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, + 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_almanac_gps_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgAlmanacGpsDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[96]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_almanac_gps_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 96); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 96), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAlmanacGpsDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 96); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 96), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[96]; + + EXPECT_EQ(sbp_msg_almanac_gps_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 96), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[96]; + + for (uint8_t i = 0; i < 96; i++) { + EXPECT_EQ( + sbp_msg_almanac_gps_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_almanac_gps_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 96); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAlmanacGpsDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 96); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_dep_t msg{}; + + EXPECT_EQ(sbp_msg_almanac_gps_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_almanac_gps_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_almanac_gps_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGpsDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAlmanacGpsDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanacGpsDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.reserved, + greater.common.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.tow, greater.common.toa.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.toa.wn, greater.common.toa.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_almanac_gps_dep_t lesser = info.test_msg; + sbp_msg_almanac_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAlmanacGpsDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ALMANAC_GPS_DEP"); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_almanac_gps_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_almanac_gps_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.almanac_gps_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.almanac_gps_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[96]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 96); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 96), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_gps_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 96); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAlmanacGpsDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgAlmanacGPSDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAlmanacGpsDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgBasePosEcef.cc b/c/test/cpp/auto_check_sbp_observation_MsgBasePosEcef.cc index 9b1dd0cc60..8829626e51 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgBasePosEcef.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgBasePosEcef.cc @@ -16,95 +16,780 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgBasePosEcef0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgBasePosEcef0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgBasePosEcef0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgBasePosEcef0() { + assign(test_msg_.x, -2726575.9189); + assign(test_msg_.y, -4315267.2798); + assign(test_msg_.z, 3811455.9642); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_base_pos_ecef_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_base_pos_ecef_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBasePosEcef, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_base_pos_ecef_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBasePosEcef); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->base_pos_ecef, + sizeof(msg->base_pos_ecef)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_base_pos_ecef_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.base_pos_ecef, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBasePosEcef); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0x7dc2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 24; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_base_pos_ecef_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_base_pos_ecef_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_base_pos_ecef_t &lesser, + const sbp_msg_base_pos_ecef_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_base_pos_ecef_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_base_pos_ecef_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_base_pos_ecef_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_base_pos_ecef_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBasePosEcef, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBasePosEcef, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBasePosEcef, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBasePosEcef, &wrapped_greater, &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_observation_MsgBasePosEcef0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_base_pos_ecef_t test_msg_{}; + uint8_t encoded_frame_[24 + 8] = { 85, 72, 0, 0, 0, 24, 228, 131, 158, 245, 87, 205, 68, 193, 66, 62, 232, 209, 32, 118, 80, 193, 213, 231, 106, 251, 63, 20, 77, 65, 194, 125, }; + uint8_t encoded_payload_[24] = { + 228, 131, 158, 245, 87, 205, 68, 193, 66, 62, 232, 209, + 32, 118, 80, 193, 213, 231, 106, 251, 63, 20, 77, 65, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_base_pos_ecef_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBasePosEcef, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_base_pos_ecef_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBasePosEcef, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + EXPECT_EQ(sbp_msg_base_pos_ecef_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_msg_base_pos_ecef_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_base_pos_ecef_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBasePosEcef, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_ecef_t msg{}; + + EXPECT_EQ(sbp_msg_base_pos_ecef_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_ecef_t msg{}; - sbp_msg_base_pos_ecef_t test_msg{}; - test_msg.x = -2726575.9189; - test_msg.y = -4315267.2798; - test_msg.z = 3811455.9642; + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - EXPECT_EQ(send_message(0, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_base_pos_ecef_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ(sbp_msg_base_pos_ecef_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBasePosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBasePosEcef, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.x * 100 - -2726575.9189 * 100), 0.05) - << "incorrect value for last_msg_.x, expected -2726575.9189, is " - << last_msg_.x; - EXPECT_LT((last_msg_.y * 100 - -4315267.2798 * 100), 0.05) - << "incorrect value for last_msg_.y, expected -4315267.2798, is " - << last_msg_.y; - EXPECT_LT((last_msg_.z * 100 - 3811455.9642 * 100), 0.05) - << "incorrect value for last_msg_.z, expected 3811455.9642, is " - << last_msg_.z; +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBasePosEcef, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_base_pos_ecef_t lesser = info.test_msg; + sbp_msg_base_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_base_pos_ecef_t lesser = info.test_msg; + sbp_msg_base_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_base_pos_ecef_t lesser = info.test_msg; + sbp_msg_base_pos_ecef_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBasePosEcef); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASE_POS_ECEF"); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_base_pos_ecef_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_base_pos_ecef_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.base_pos_ecef, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.base_pos_ecef, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_ecef_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBasePosEcef, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosEcef0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBasePosEcef, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc b/c/test/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc new file mode 100644 index 0000000000..ef8f54d843 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc @@ -0,0 +1,791 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgBasePosLLH0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgBasePosLLH0() { + assign(test_msg_.height, 37.939512310879216); + assign(test_msg_.lat, 37.251292578377395); + assign(test_msg_.lon, -121.87505609407974); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_base_pos_llh_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_base_pos_llh_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBasePosLlh, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_base_pos_llh_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBasePosLlh); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->base_pos_llh, + sizeof(msg->base_pos_llh)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_base_pos_llh_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.base_pos_llh, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBasePosLlh); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xe652; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 24; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_base_pos_llh_t &lesser, + const sbp_msg_base_pos_llh_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_base_pos_llh_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_base_pos_llh_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_base_pos_llh_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_base_pos_llh_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgBasePosLlh, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgBasePosLlh, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgBasePosLlh, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgBasePosLlh, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_base_pos_llh_t test_msg_{}; + uint8_t encoded_frame_[24 + 8] = { + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, + 70, 235, 0, 120, 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + }; + uint8_t encoded_payload_[24] = { + 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, 70, 235, + 0, 120, 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_base_pos_llh_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgBasePosLlh, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_base_pos_llh_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBasePosLlh, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + EXPECT_EQ(sbp_msg_base_pos_llh_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_msg_base_pos_llh_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_base_pos_llh_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBasePosLlh, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_llh_t msg{}; + + EXPECT_EQ(sbp_msg_base_pos_llh_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_llh_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_base_pos_llh_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_base_pos_llh_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBasePosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBasePosLlh, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBasePosLlh, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_base_pos_llh_t lesser = info.test_msg; + sbp_msg_base_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.height, greater.height); + comparison_tests(lesser, greater); + } + { + sbp_msg_base_pos_llh_t lesser = info.test_msg; + sbp_msg_base_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lat, greater.lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_base_pos_llh_t lesser = info.test_msg; + sbp_msg_base_pos_llh_t greater = info.test_msg; + make_lesser_greater(lesser.lon, greater.lon); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBasePosLlh); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASE_POS_LLH"); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_base_pos_llh_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_base_pos_llh_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.base_pos_llh, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.base_pos_llh, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_base_pos_llh_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBasePosLlh, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgBasePosLLH0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBasePosLlh, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisBds.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisBds.cc index fd30f33a7b..d0b528246d 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisBds.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisBds.cc @@ -16,66 +16,396 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgEphemerisBds0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisBds0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgEphemerisBds0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgEphemerisBds0() { + assign(test_msg_.af0, -0.0008911322802305222); + assign(test_msg_.af1, 1.2398970739013748e-12); + assign(test_msg_.af2, -7.318364664277155e-19); + assign(test_msg_.c_ic, -6.658956408500671e-08); + assign(test_msg_.c_is, 3.5529956221580505e-07); + assign(test_msg_.c_rc, 234.640625); + assign(test_msg_.c_rs, 224.4375); + assign(test_msg_.c_uc, 7.606577128171921e-06); + assign(test_msg_.c_us, 6.551854312419891e-07); + assign(test_msg_.common.fit_interval, 10800); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 12); + assign(test_msg_.common.sid.sat, 8); + assign(test_msg_.common.toe.tow, 439214); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 1.1296899132622133e-09); + assign(test_msg_.ecc, 0.005184737499803305); + assign(test_msg_.inc, 1.0421769543504915); + assign(test_msg_.inc_dot, 7.507455572801683e-10); + assign(test_msg_.iodc, 5); + assign(test_msg_.iode, 6); + assign(test_msg_.m0, 1.6943958190727237); + assign(test_msg_.omega0, -2.581073762870982); + assign(test_msg_.omegadot, -2.303310227830545e-09); + assign(test_msg_.sqrta, 6493.49845123291); + assign(test_msg_.tgd1, 1.0499999980595476e-08); + assign(test_msg_.tgd2, -1.0999999799921056e-09); + assign(test_msg_.toc.tow, 439214); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, -2.698603205735458); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_bds_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_bds_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisBds, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_bds_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisBds); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_bds, + sizeof(msg->ephemeris_bds)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_bds_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_bds, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisBds); + info.sender_id = 61568; + info.preamble = 0x55; + info.crc = 0xf99d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 147; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_bds_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_bds_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_bds_t &lesser, + const sbp_msg_ephemeris_bds_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_bds_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_bds_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_bds_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_bds_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisBds, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisBds, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisBds, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisBds, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_MsgEphemerisBds0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_ephemeris_bds_t test_msg_{}; + uint8_t encoded_frame_[147 + 8] = { 85, 137, 0, 128, 240, 147, 8, 12, 174, 179, 6, 0, 106, 8, 0, 0, 0, 64, 48, 42, 0, 0, 1, 0, 125, 99, 52, 50, 207, 46, 151, 176, 0, 112, 96, 67, 0, 164, 106, 67, 0, 60, 255, 54, 0, @@ -88,149 +418,601 @@ TEST_F(Test_auto_check_sbp_observation_MsgEphemerisBds0, Test) { 191, 0, 128, 174, 43, 0, 0, 88, 161, 174, 179, 6, 0, 106, 8, 6, 5, 0, 157, 249, }; + uint8_t encoded_payload_[147] = { + 8, 12, 174, 179, 6, 0, 106, 8, 0, 0, 0, 64, 48, 42, 0, + 0, 1, 0, 125, 99, 52, 50, 207, 46, 151, 176, 0, 112, 96, 67, + 0, 164, 106, 67, 0, 60, 255, 54, 0, 224, 47, 53, 0, 0, 143, + 179, 0, 192, 190, 52, 146, 101, 162, 196, 109, 104, 19, 62, 253, 87, + 86, 202, 62, 28, 251, 63, 0, 0, 0, 96, 151, 60, 117, 63, 0, + 0, 128, 154, 127, 93, 185, 64, 151, 193, 64, 0, 10, 166, 4, 192, + 160, 75, 174, 98, 8, 201, 35, 190, 205, 29, 12, 71, 189, 150, 5, + 192, 176, 72, 249, 189, 193, 172, 240, 63, 72, 249, 188, 180, 160, 203, + 9, 62, 0, 0, 0, 0, 92, 51, 77, 191, 0, 128, 174, 43, 0, + 0, 88, 161, 174, 179, 6, 0, 106, 8, 6, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_bds_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEphemerisBds, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[147]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_bds_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 147); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 147), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisBds, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 147); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 147), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[147]; + + EXPECT_EQ(sbp_msg_ephemeris_bds_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 147), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[147]; + + for (uint8_t i = 0; i < 147; i++) { + EXPECT_EQ(sbp_msg_ephemeris_bds_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_bds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_bds_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 147); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisBds, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 147); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_bds_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_bds_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_bds_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_bds_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - sbp_msg_ephemeris_bds_t test_msg{}; - test_msg.af0 = -0.0008911322802305222; - test_msg.af1 = 1.2398970739013748e-12; - test_msg.af2 = -7.318364664277155e-19; - test_msg.c_ic = -6.658956408500671e-08; - test_msg.c_is = 3.5529956221580505e-07; - test_msg.c_rc = 234.640625; - test_msg.c_rs = 224.4375; - test_msg.c_uc = 7.606577128171921e-06; - test_msg.c_us = 6.551854312419891e-07; - test_msg.common.fit_interval = 10800; - test_msg.common.health_bits = 0; - test_msg.common.sid.code = 12; - test_msg.common.sid.sat = 8; - test_msg.common.toe.tow = 439214; - test_msg.common.toe.wn = 2154; - test_msg.common.ura = 2.0; - test_msg.common.valid = 1; - test_msg.dn = 1.1296899132622133e-09; - test_msg.ecc = 0.005184737499803305; - test_msg.inc = 1.0421769543504915; - test_msg.inc_dot = 7.507455572801683e-10; - test_msg.iodc = 5; - test_msg.iode = 6; - test_msg.m0 = 1.6943958190727237; - test_msg.omega0 = -2.581073762870982; - test_msg.omegadot = -2.303310227830545e-09; - test_msg.sqrta = 6493.49845123291; - test_msg.tgd1 = 1.0499999980595476e-08; - test_msg.tgd2 = -1.0999999799921056e-09; - test_msg.toc.tow = 439214; - test_msg.toc.wn = 2154; - test_msg.w = -2.698603205735458; - - EXPECT_EQ(send_message(61568, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61568); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -0.000891132280231 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -0.000891132280231, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - 1.2398970739e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected 1.2398970739e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - -7.31836466428e-19 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected -7.31836466428e-19, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - -6.6589564085e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected -6.6589564085e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - 3.55299562216e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected 3.55299562216e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 234.640625 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 234.640625, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - 224.4375 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected 224.4375, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - 7.60657712817e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected 7.60657712817e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 6.55185431242e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 6.55185431242e-07, is " - << last_msg_.c_us; - EXPECT_EQ(last_msg_.common.fit_interval, 10800) - << "incorrect value for last_msg_.common.fit_interval, expected 10800, " - "is " - << last_msg_.common.fit_interval; - EXPECT_EQ(last_msg_.common.health_bits, 0) - << "incorrect value for last_msg_.common.health_bits, expected 0, is " - << last_msg_.common.health_bits; - EXPECT_EQ(last_msg_.common.sid.code, 12) - << "incorrect value for last_msg_.common.sid.code, expected 12, is " - << last_msg_.common.sid.code; - EXPECT_EQ(last_msg_.common.sid.sat, 8) - << "incorrect value for last_msg_.common.sid.sat, expected 8, is " - << last_msg_.common.sid.sat; - EXPECT_EQ(last_msg_.common.toe.tow, 439214) - << "incorrect value for last_msg_.common.toe.tow, expected 439214, is " - << last_msg_.common.toe.tow; - EXPECT_EQ(last_msg_.common.toe.wn, 2154) - << "incorrect value for last_msg_.common.toe.wn, expected 2154, is " - << last_msg_.common.toe.wn; - EXPECT_LT((last_msg_.common.ura * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.common.ura, expected 2.0, is " - << last_msg_.common.ura; - EXPECT_EQ(last_msg_.common.valid, 1) - << "incorrect value for last_msg_.common.valid, expected 1, is " - << last_msg_.common.valid; - EXPECT_LT((last_msg_.dn * 100 - 1.12968991326e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 1.12968991326e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.0051847374998 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.0051847374998, is " - << last_msg_.ecc; - EXPECT_LT((last_msg_.inc * 100 - 1.04217695435 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 1.04217695435, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - 7.5074555728e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected 7.5074555728e-10, is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iodc, 5) - << "incorrect value for last_msg_.iodc, expected 5, is " - << last_msg_.iodc; - EXPECT_EQ(last_msg_.iode, 6) - << "incorrect value for last_msg_.iode, expected 6, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - 1.69439581907 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected 1.69439581907, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - -2.58107376287 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected -2.58107376287, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -2.30331022783e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -2.30331022783e-09, " - "is " - << last_msg_.omegadot; - EXPECT_LT((last_msg_.sqrta * 100 - 6493.49845123 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 6493.49845123, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd1 * 100 - 1.04999999806e-08 * 100), 0.05) - << "incorrect value for last_msg_.tgd1, expected 1.04999999806e-08, is " - << last_msg_.tgd1; - EXPECT_LT((last_msg_.tgd2 * 100 - -1.09999997999e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd2, expected -1.09999997999e-09, is " - << last_msg_.tgd2; - EXPECT_EQ(last_msg_.toc.tow, 439214) - << "incorrect value for last_msg_.toc.tow, expected 439214, is " - << last_msg_.toc.tow; - EXPECT_EQ(last_msg_.toc.wn, 2154) - << "incorrect value for last_msg_.toc.wn, expected 2154, is " - << last_msg_.toc.wn; - EXPECT_LT((last_msg_.w * 100 - -2.69860320574 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -2.69860320574, is " - << last_msg_.w; + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_bds_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisBds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisBds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisBds, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.tgd1, greater.tgd1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.tgd2, greater.tgd2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_bds_t lesser = info.test_msg; + sbp_msg_ephemeris_bds_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisBds); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_BDS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_bds_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_bds_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_bds, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ephemeris_bds, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[147]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 147); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 147), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_bds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 147); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisBds, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisBds0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisBds, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc new file mode 100644 index 0000000000..e44e9dd814 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc @@ -0,0 +1,985 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisDepA0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.2); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.healthy, 0); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.prn, 22); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc_tow, 446384.2); + assign(test_msg_.toc_wn, 2154); + assign(test_msg_.toe_tow, 446384.2); + assign(test_msg_.toe_wn, 2154); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_a, + sizeof(msg->ephemeris_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x54f2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 175; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_a_t &lesser, + const sbp_msg_ephemeris_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_a_t test_msg_{}; + uint8_t encoded_frame_[175 + 8] = { + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 242, 84, + }; + uint8_t encoded_payload_[175] = { + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, + 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, + 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, + 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, + 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, + 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, 153, 153, + 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 205, 204, 204, + 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[175]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 175); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 175), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 175); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 175), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[175]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 175), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[175]; + + for (uint8_t i = 0; i < 175; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 175); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 175); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[175]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 175); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 175), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 175); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc new file mode 100644 index 0000000000..0192a771bf --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc @@ -0,0 +1,1021 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisDepC0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisDepC0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.2); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.healthy, 0); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.iodc, 45); + assign(test_msg_.iode, 45); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.reserved, 0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 22); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc_tow, 446384.2); + assign(test_msg_.toc_wn, 2154); + assign(test_msg_.toe_tow, 446384.2); + assign(test_msg_.toe_wn, 2154); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_c, + sizeof(msg->ephemeris_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepC); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xaa17; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 185; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_c_t &lesser, + const sbp_msg_ephemeris_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_c_t test_msg_{}; + uint8_t encoded_frame_[185 + 8] = { + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 23, 170, + }; + uint8_t encoded_payload_[185] = { + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, + 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, + 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, + 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, + 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, + 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, 153, 153, + 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 205, 204, 204, + 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, + 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + for (uint8_t i = 0; i < 185; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.reserved, greater.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepC0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc new file mode 100644 index 0000000000..c7eb92ded1 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc @@ -0,0 +1,1021 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisDepD0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisDepD0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.2); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.healthy, 0); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.iodc, 45); + assign(test_msg_.iode, 45); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.reserved, 0); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 22); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc_tow, 446384.2); + assign(test_msg_.toc_wn, 2154); + assign(test_msg_.toe_tow, 446384.2); + assign(test_msg_.toe_wn, 2154); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_d_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_d_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepD, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_d_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepD); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_d, + sizeof(msg->ephemeris_dep_d)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_d_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_d, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepD); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x075f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 185; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_d_t &lesser, + const sbp_msg_ephemeris_dep_d_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_d_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_d_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_d_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepD, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepD, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepD, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepD, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_d_t test_msg_{}; + uint8_t encoded_frame_[185 + 8] = { + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 95, 7, + }; + uint8_t encoded_payload_[185] = { + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, + 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, + 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, + 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, + 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, + 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, 153, 153, + 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 205, 204, 204, + 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, + 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_d_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepD, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepD, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + for (uint8_t i = 0; i < 185; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_d_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_d_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepD, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_d_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_d_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_d_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepD, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepD, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepD, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.reserved, greater.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepD); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_D"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_d_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_d_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_d, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_d, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_d_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepD, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisDepD0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepD, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLO.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLO.cc index 04530b2cf3..fcf2ff0bf0 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLO.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLO.cc @@ -16,66 +16,394 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgEphemerisGLO0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGLO0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgEphemerisGLO0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgEphemerisGLO0() { + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 2400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 3); + assign(test_msg_.common.sid.sat, 4); + assign(test_msg_.common.toe.tow, 443718); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 5.0); + assign(test_msg_.common.valid, 1); + assign(test_msg_.d_tau, -2.7939677238464355e-09); + assign(test_msg_.fcn, 14); + assign(test_msg_.gamma, 9.094947017729282e-13); + assign(test_msg_.iod, 100); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + assign(test_msg_.tau, -8.36281105875969e-05); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_glo_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGlo, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGlo); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_glo, + sizeof(msg->ephemeris_glo)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_glo_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_glo, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGlo); + info.sender_id = 2314; + info.preamble = 0x55; + info.crc = 0x9559; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 92; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_glo_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_glo_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_glo_t &lesser, + const sbp_msg_ephemeris_glo_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_glo_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_glo_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_glo_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_glo_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGlo, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGlo, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisGlo, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisGlo, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGLO0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_glo_t test_msg_{}; + uint8_t encoded_frame_[92 + 8] = { 85, 139, 0, 10, 9, 92, 4, 3, 70, 197, 6, 0, 106, 8, 0, 0, 160, 64, 96, 9, 0, 0, 1, 0, 0, 0, 128, 43, 128, 97, 175, 184, 0, 0, 64, 177, 0, 0, 128, 66, 246, 57, 103, 193, 0, @@ -84,115 +412,547 @@ TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGLO0, Test) { 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 122, 53, 0, 0, 122, 53, 0, 128, 59, 54, 14, 100, 89, 149, }; + uint8_t encoded_payload_[92] = { + 4, 3, 70, 197, 6, 0, 106, 8, 0, 0, 160, 64, 96, 9, + 0, 0, 1, 0, 0, 0, 128, 43, 128, 97, 175, 184, 0, 0, + 64, 177, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 122, 53, 0, 0, + 122, 53, 0, 128, 59, 54, 14, 100, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_glo_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEphemerisGlo, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[92]; + uint8_t n_written; - sbp_msg_ephemeris_glo_t test_msg{}; - - test_msg.acc[0] = 9.313225746154785e-07; - - test_msg.acc[1] = 9.313225746154785e-07; - - test_msg.acc[2] = 2.7939677238464355e-06; - test_msg.common.fit_interval = 2400; - test_msg.common.health_bits = 0; - test_msg.common.sid.code = 3; - test_msg.common.sid.sat = 4; - test_msg.common.toe.tow = 443718; - test_msg.common.toe.wn = 2154; - test_msg.common.ura = 5.0; - test_msg.common.valid = 1; - test_msg.d_tau = -2.7939677238464355e-09; - test_msg.fcn = 14; - test_msg.gamma = 9.094947017729282e-13; - test_msg.iod = 100; - - test_msg.pos[0] = -12177330.078125; - - test_msg.pos[1] = 599893.06640625; - - test_msg.pos[2] = -22373708.49609375; - test_msg.tau = -8.36281105875969e-05; - - test_msg.vel[0] = -1726.506233215332; - - test_msg.vel[1] = -2542.6149368286133; - - test_msg.vel[2] = 869.8177337646484; - - EXPECT_EQ(send_message(2314, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 2314); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) - << "incorrect value for last_msg_.acc[0], expected 9.31322574615e-07, is " - << last_msg_.acc[0]; - EXPECT_LT((last_msg_.acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) - << "incorrect value for last_msg_.acc[1], expected 9.31322574615e-07, is " - << last_msg_.acc[1]; - EXPECT_LT((last_msg_.acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) - << "incorrect value for last_msg_.acc[2], expected 2.79396772385e-06, is " - << last_msg_.acc[2]; - EXPECT_EQ(last_msg_.common.fit_interval, 2400) - << "incorrect value for last_msg_.common.fit_interval, expected 2400, is " - << last_msg_.common.fit_interval; - EXPECT_EQ(last_msg_.common.health_bits, 0) - << "incorrect value for last_msg_.common.health_bits, expected 0, is " - << last_msg_.common.health_bits; - EXPECT_EQ(last_msg_.common.sid.code, 3) - << "incorrect value for last_msg_.common.sid.code, expected 3, is " - << last_msg_.common.sid.code; - EXPECT_EQ(last_msg_.common.sid.sat, 4) - << "incorrect value for last_msg_.common.sid.sat, expected 4, is " - << last_msg_.common.sid.sat; - EXPECT_EQ(last_msg_.common.toe.tow, 443718) - << "incorrect value for last_msg_.common.toe.tow, expected 443718, is " - << last_msg_.common.toe.tow; - EXPECT_EQ(last_msg_.common.toe.wn, 2154) - << "incorrect value for last_msg_.common.toe.wn, expected 2154, is " - << last_msg_.common.toe.wn; - EXPECT_LT((last_msg_.common.ura * 100 - 5.0 * 100), 0.05) - << "incorrect value for last_msg_.common.ura, expected 5.0, is " - << last_msg_.common.ura; - EXPECT_EQ(last_msg_.common.valid, 1) - << "incorrect value for last_msg_.common.valid, expected 1, is " - << last_msg_.common.valid; - EXPECT_LT((last_msg_.d_tau * 100 - -2.79396772385e-09 * 100), 0.05) - << "incorrect value for last_msg_.d_tau, expected -2.79396772385e-09, is " - << last_msg_.d_tau; - EXPECT_EQ(last_msg_.fcn, 14) - << "incorrect value for last_msg_.fcn, expected 14, is " << last_msg_.fcn; - EXPECT_LT((last_msg_.gamma * 100 - 9.09494701773e-13 * 100), 0.05) - << "incorrect value for last_msg_.gamma, expected 9.09494701773e-13, is " - << last_msg_.gamma; - EXPECT_EQ(last_msg_.iod, 100) - << "incorrect value for last_msg_.iod, expected 100, is " - << last_msg_.iod; - EXPECT_LT((last_msg_.pos[0] * 100 - -12177330.0781 * 100), 0.05) - << "incorrect value for last_msg_.pos[0], expected -12177330.0781, is " - << last_msg_.pos[0]; - EXPECT_LT((last_msg_.pos[1] * 100 - 599893.066406 * 100), 0.05) - << "incorrect value for last_msg_.pos[1], expected 599893.066406, is " - << last_msg_.pos[1]; - EXPECT_LT((last_msg_.pos[2] * 100 - -22373708.4961 * 100), 0.05) - << "incorrect value for last_msg_.pos[2], expected -22373708.4961, is " - << last_msg_.pos[2]; - EXPECT_LT((last_msg_.tau * 100 - -8.36281105876e-05 * 100), 0.05) - << "incorrect value for last_msg_.tau, expected -8.36281105876e-05, is " - << last_msg_.tau; - EXPECT_LT((last_msg_.vel[0] * 100 - -1726.50623322 * 100), 0.05) - << "incorrect value for last_msg_.vel[0], expected -1726.50623322, is " - << last_msg_.vel[0]; - EXPECT_LT((last_msg_.vel[1] * 100 - -2542.61493683 * 100), 0.05) - << "incorrect value for last_msg_.vel[1], expected -2542.61493683, is " - << last_msg_.vel[1]; - EXPECT_LT((last_msg_.vel[2] * 100 - 869.817733765 * 100), 0.05) - << "incorrect value for last_msg_.vel[2], expected 869.817733765, is " - << last_msg_.vel[2]; + EXPECT_EQ(sbp_msg_ephemeris_glo_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 92); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 92), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGlo, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 92); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 92), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[92]; + + EXPECT_EQ(sbp_msg_ephemeris_glo_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 92), 0); } +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[92]; + + for (uint8_t i = 0; i < 92; i++) { + EXPECT_EQ(sbp_msg_ephemeris_glo_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_glo_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 92); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGlo, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 92); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_glo_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_glo_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_glo_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGlo, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGlo, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGlo, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.d_tau, greater.d_tau); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.fcn, greater.fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.gamma, greater.gamma); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.iod, greater.iod); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.tau, greater.tau); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGlo); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GLO"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_glo_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_glo_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_glo, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ephemeris_glo, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[92]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 92); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 92), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 92); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGlo, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLO0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGlo, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc new file mode 100644 index 0000000000..6e1f53704c --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc @@ -0,0 +1,962 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGLODepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGLODepA0() { + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 2400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 3); + assign(test_msg_.common.sid.reserved, 0); + assign(test_msg_.common.sid.sat, 4); + assign(test_msg_.common.toe.tow, 443718); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 5.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.gamma, 9.094947017729282e-13); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + assign(test_msg_.tau, -8.36281105875969e-05); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_glo_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGloDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGloDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_glo_dep_a, + sizeof(msg->ephemeris_glo_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_glo_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_glo_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGloDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xeeca; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 112; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_glo_dep_a_t &lesser, + const sbp_msg_ephemeris_glo_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_glo_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_glo_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGloDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGloDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_glo_dep_a_t test_msg_{}; + uint8_t encoded_frame_[112 + 8] = { + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, + 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, + 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, + 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, + 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 202, 238, + }; + uint8_t encoded_payload_[112] = { + 4, 0, 3, 0, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, + 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, + 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, + 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGloDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGloDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + + for (uint8_t i = 0; i < 112; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_glo_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGloDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGloDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.reserved, + greater.common.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.gamma, greater.gamma); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tau, greater.tau); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGloDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GLO_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_glo_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_glo_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_glo_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_glo_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGloDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGloDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc new file mode 100644 index 0000000000..aa1fbacbea --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc @@ -0,0 +1,954 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGLODepB0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGLODepB0() { + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 2400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 3); + assign(test_msg_.common.sid.sat, 4); + assign(test_msg_.common.toe.tow, 443718); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 5.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.gamma, 9.094947017729282e-13); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + assign(test_msg_.tau, -8.36281105875969e-05); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_glo_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGloDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGloDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_glo_dep_b, + sizeof(msg->ephemeris_glo_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_glo_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_glo_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGloDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x7f7a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 110; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_glo_dep_b_t &lesser, + const sbp_msg_ephemeris_glo_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_glo_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_glo_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGloDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGloDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_glo_dep_b_t test_msg_{}; + uint8_t encoded_frame_[110 + 8] = { + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, + 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, + 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, 46, + 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 122, 127, + }; + uint8_t encoded_payload_[110] = { + 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, 64, + 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, + 0, 0, 48, 236, 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, + 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGloDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGloDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + for (uint8_t i = 0; i < 110; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_glo_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGloDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGloDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.gamma, greater.gamma); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tau, greater.tau); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGloDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GLO_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_glo_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_glo_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_glo_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_glo_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGloDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGloDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc new file mode 100644 index 0000000000..e91affbcbc --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc @@ -0,0 +1,970 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGLODepC0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGLODepC0() { + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 2400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 3); + assign(test_msg_.common.sid.sat, 4); + assign(test_msg_.common.toe.tow, 443718); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 5.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.d_tau, -2.7939677238464355e-09); + assign(test_msg_.fcn, 14); + assign(test_msg_.gamma, 9.094947017729282e-13); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + assign(test_msg_.tau, -8.36281105875969e-05); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_glo_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGloDepC, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGloDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_glo_dep_c, + sizeof(msg->ephemeris_glo_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_glo_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_glo_dep_c, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGloDepC); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4197; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 119; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_glo_dep_c_t &lesser, + const sbp_msg_ephemeris_glo_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_glo_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_glo_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepC, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepC, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGloDepC, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGloDepC, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_glo_dep_c_t test_msg_{}; + uint8_t encoded_frame_[119 + 8] = { + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 14, 151, 65, + }; + uint8_t encoded_payload_[119] = { + 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, + 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, + 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, + 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, + 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, + 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGloDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[119]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 119); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 119), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGloDepC, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 119); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 119), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[119]; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 119), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[119]; + + for (uint8_t i = 0; i < 119; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_glo_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 119); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGloDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 119); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_c_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGloDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.d_tau, greater.d_tau); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.fcn, greater.fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.gamma, greater.gamma); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.tau, greater.tau); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_c_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGloDepC); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GLO_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_glo_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_glo_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_glo_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_glo_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[119]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 119); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 119), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 119); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGloDepC, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepC0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGloDepC, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc new file mode 100644 index 0000000000..1091cb94d0 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc @@ -0,0 +1,977 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGLODepD0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGLODepD0() { + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 2400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 3); + assign(test_msg_.common.sid.sat, 4); + assign(test_msg_.common.toe.tow, 443718); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 5.2); + assign(test_msg_.common.valid, 1); + assign(test_msg_.d_tau, -2.7939677238464355e-09); + assign(test_msg_.fcn, 14); + assign(test_msg_.gamma, 9.094947017729282e-13); + assign(test_msg_.iod, 100); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + assign(test_msg_.tau, -8.36281105875969e-05); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_d_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_glo_dep_d_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGloDepD, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_glo_dep_d_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGloDepD); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_glo_dep_d, + sizeof(msg->ephemeris_glo_dep_d)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_glo_dep_d_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_glo_dep_d, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGloDepD); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4052; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 120; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_glo_dep_d_t &lesser, + const sbp_msg_ephemeris_glo_dep_d_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_glo_dep_d_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_glo_dep_d_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepD, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGloDepD, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGloDepD, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGloDepD, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_glo_dep_d_t test_msg_{}; + uint8_t encoded_frame_[120 + 8] = { + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 14, 100, 82, 64, + }; + uint8_t encoded_payload_[120] = { + 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, + 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, + 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, + 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, + 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, + 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, 100, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGloDepD, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[120]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 120); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 120), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGloDepD, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 120); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 120), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[120]; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 120), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[120]; + + for (uint8_t i = 0; i < 120; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_glo_dep_d_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_d_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 120); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGloDepD, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 120); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_d_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_d_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_glo_dep_d_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepD, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGloDepD, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGloDepD, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.d_tau, greater.d_tau); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.fcn, greater.fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.gamma, greater.gamma); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.iod, greater.iod); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.tau, greater.tau); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_glo_dep_d_t lesser = info.test_msg; + sbp_msg_ephemeris_glo_dep_d_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGloDepD); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GLO_DEP_D"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_glo_dep_d_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_glo_dep_d_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_glo_dep_d, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_glo_dep_d, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[120]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 120); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 120), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_glo_dep_d_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 120); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGloDepD, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGLODepD0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGloDepD, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPS.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPS.cc index ffa31e4f74..e63a6a7d5a 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPS.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPS.cc @@ -16,66 +16,395 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgEphemerisGPS0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGPS0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgEphemerisGPS0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgEphemerisGPS0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.iodc, 45); + assign(test_msg_.iode, 45); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc.tow, 446384); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_gps_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGps, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGps); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_gps, + sizeof(msg->ephemeris_gps)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_gps_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_gps, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGps); + info.sender_id = 2314; + info.preamble = 0x55; + info.crc = 0x4aa; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 139; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_gps_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_gps_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_gps_t &lesser, + const sbp_msg_ephemeris_gps_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_gps_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_gps_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_gps_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_gps_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGps, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGps, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisGps, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisGps, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGPS0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_ephemeris_gps_t test_msg_{}; + uint8_t encoded_frame_[139 + 8] = { 85, 138, 0, 10, 9, 139, 22, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, 0, 0, 152, 178, 0, 64, 81, 194, 0, 80, 154, 67, 0, 32, 56, 182, 0, 128, 82, 54, 0, @@ -87,146 +416,595 @@ TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGPS0, Test) { 255, 47, 198, 189, 96, 139, 37, 186, 0, 0, 30, 45, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 170, 4, }; + uint8_t encoded_payload_[139] = { + 22, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 64, 64, 56, + 0, 0, 1, 0, 0, 0, 152, 178, 0, 64, 81, 194, 0, 80, + 154, 67, 0, 32, 56, 182, 0, 128, 82, 54, 0, 0, 0, 50, + 0, 0, 248, 179, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, + 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, + 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, + 100, 224, 255, 47, 198, 189, 96, 139, 37, 186, 0, 0, 30, 45, + 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_gps_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEphemerisGps, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_gps_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGps, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + + EXPECT_EQ(sbp_msg_ephemeris_gps_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + + for (uint8_t i = 0; i < 139; i++) { + EXPECT_EQ(sbp_msg_ephemeris_gps_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_gps_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGps, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_gps_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_gps_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ephemeris_gps_t test_msg{}; - test_msg.af0 = -0.0006315018981695175; - test_msg.af1 = 8.981260180007666e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = 7.450580596923828e-09; - test_msg.c_is = -1.1548399925231934e-07; - test_msg.c_rc = 308.625; - test_msg.c_rs = -52.3125; - test_msg.c_uc = -2.7436763048171997e-06; - test_msg.c_us = 3.1366944313049316e-06; - test_msg.common.fit_interval = 14400; - test_msg.common.health_bits = 0; - test_msg.common.sid.code = 0; - test_msg.common.sid.sat = 22; - test_msg.common.toe.tow = 446384; - test_msg.common.toe.wn = 2154; - test_msg.common.ura = 2.0; - test_msg.common.valid = 1; - test_msg.dn = 5.694522914022375e-09; - test_msg.ecc = 0.007072207052260637; - test_msg.inc = 0.9341514480259797; - test_msg.inc_dot = -4.035882396415757e-11; - test_msg.iodc = 45; - test_msg.iode = 45; - test_msg.m0 = -0.02200078842114688; - test_msg.omega0 = -1.8731818448797617; - test_msg.omegadot = -8.903585155774196e-09; - test_msg.sqrta = 5153.550029754639; - test_msg.tgd = -1.7695128917694092e-08; - test_msg.toc.tow = 446384; - test_msg.toc.wn = 2154; - test_msg.w = -0.9893036629599647; - - EXPECT_EQ(send_message(2314, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 2314); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -0.00063150189817 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -0.00063150189817, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - 8.98126018001e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected 8.98126018001e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - 7.45058059692e-09 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected 7.45058059692e-09, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - -1.15483999252e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected -1.15483999252e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 308.625 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 308.625, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - -52.3125 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected -52.3125, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - -2.74367630482e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected -2.74367630482e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 3.1366944313e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 3.1366944313e-06, is " - << last_msg_.c_us; - EXPECT_EQ(last_msg_.common.fit_interval, 14400) - << "incorrect value for last_msg_.common.fit_interval, expected 14400, " - "is " - << last_msg_.common.fit_interval; - EXPECT_EQ(last_msg_.common.health_bits, 0) - << "incorrect value for last_msg_.common.health_bits, expected 0, is " - << last_msg_.common.health_bits; - EXPECT_EQ(last_msg_.common.sid.code, 0) - << "incorrect value for last_msg_.common.sid.code, expected 0, is " - << last_msg_.common.sid.code; - EXPECT_EQ(last_msg_.common.sid.sat, 22) - << "incorrect value for last_msg_.common.sid.sat, expected 22, is " - << last_msg_.common.sid.sat; - EXPECT_EQ(last_msg_.common.toe.tow, 446384) - << "incorrect value for last_msg_.common.toe.tow, expected 446384, is " - << last_msg_.common.toe.tow; - EXPECT_EQ(last_msg_.common.toe.wn, 2154) - << "incorrect value for last_msg_.common.toe.wn, expected 2154, is " - << last_msg_.common.toe.wn; - EXPECT_LT((last_msg_.common.ura * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.common.ura, expected 2.0, is " - << last_msg_.common.ura; - EXPECT_EQ(last_msg_.common.valid, 1) - << "incorrect value for last_msg_.common.valid, expected 1, is " - << last_msg_.common.valid; - EXPECT_LT((last_msg_.dn * 100 - 5.69452291402e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 5.69452291402e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00707220705226 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00707220705226, is " - << last_msg_.ecc; - EXPECT_LT((last_msg_.inc * 100 - 0.934151448026 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.934151448026, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected -4.03588239642e-11, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iodc, 45) - << "incorrect value for last_msg_.iodc, expected 45, is " - << last_msg_.iodc; - EXPECT_EQ(last_msg_.iode, 45) - << "incorrect value for last_msg_.iode, expected 45, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - -0.0220007884211 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected -0.0220007884211, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - -1.87318184488 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected -1.87318184488, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.90358515577e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.90358515577e-09, " - "is " - << last_msg_.omegadot; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.55002975 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.55002975, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -1.76951289177e-08 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -1.76951289177e-08, is " - << last_msg_.tgd; - EXPECT_EQ(last_msg_.toc.tow, 446384) - << "incorrect value for last_msg_.toc.tow, expected 446384, is " - << last_msg_.toc.tow; - EXPECT_EQ(last_msg_.toc.wn, 2154) - << "incorrect value for last_msg_.toc.wn, expected 2154, is " - << last_msg_.toc.wn; - EXPECT_LT((last_msg_.w * 100 - -0.98930366296 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -0.98930366296, is " - << last_msg_.w; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_gps_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGps, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGps, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGps, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGps); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GPS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_gps_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_gps_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_gps, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ephemeris_gps, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGps, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPS0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGps, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc new file mode 100644 index 0000000000..3160f49fd1 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc @@ -0,0 +1,1040 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGPSDepE0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGPSDepE0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.reserved, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.iodc, 45); + assign(test_msg_.iode, 45); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc.tow, 446384); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_dep_e_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_gps_dep_e_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGpsDepE, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_dep_e_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGpsDepE); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_gps_dep_e, + sizeof(msg->ephemeris_gps_dep_e)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_gps_dep_e_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_gps_dep_e, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGpsDepE); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xee06; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 185; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_gps_dep_e_t &lesser, + const sbp_msg_ephemeris_gps_dep_e_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_gps_dep_e_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_gps_dep_e_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGpsDepE, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGpsDepE, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGpsDepE, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGpsDepE, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_gps_dep_e_t test_msg_{}; + uint8_t encoded_frame_[185 + 8] = { + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, + 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, + 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, + 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, + 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, + 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, + 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + }; + uint8_t encoded_payload_[185] = { + 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, + 0, 0, 64, 64, 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, + 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, + 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, + 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, + 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, + 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, 176, 207, 6, 0, + 106, 8, 45, 45, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGpsDepE, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGpsDepE, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + + for (uint8_t i = 0; i < 185; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_gps_dep_e_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_e_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGpsDepE, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_e_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_e_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_e_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGpsDepE, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGpsDepE, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGpsDepE, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.reserved, + greater.common.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_e_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_e_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGpsDepE); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GPS_DEP_E"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_gps_dep_e_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_gps_dep_e_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_gps_dep_e, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_gps_dep_e, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[185]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 185); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 185), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_e_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 185); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGpsDepE, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepE0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGpsDepE, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc new file mode 100644 index 0000000000..4f4729f4af --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc @@ -0,0 +1,1032 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGPSDepF0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGPSDepF0() { + assign(test_msg_.af0, -0.0006315018981695175); + assign(test_msg_.af1, 8.981260180007666e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 7.450580596923828e-09); + assign(test_msg_.c_is, -1.1548399925231934e-07); + assign(test_msg_.c_rc, 308.625); + assign(test_msg_.c_rs, -52.3125); + assign(test_msg_.c_uc, -2.7436763048171997e-06); + assign(test_msg_.c_us, 3.1366944313049316e-06); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 5.694522914022375e-09); + assign(test_msg_.ecc, 0.007072207052260637); + assign(test_msg_.inc, 0.9341514480259797); + assign(test_msg_.inc_dot, -4.035882396415757e-11); + assign(test_msg_.iodc, 45); + assign(test_msg_.iode, 45); + assign(test_msg_.m0, -0.02200078842114688); + assign(test_msg_.omega0, -1.8731818448797617); + assign(test_msg_.omegadot, -8.903585155774196e-09); + assign(test_msg_.sqrta, 5153.550029754639); + assign(test_msg_.tgd, -1.7695128917694092e-08); + assign(test_msg_.toc.tow, 446384); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, -0.9893036629599647); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_dep_f_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_gps_dep_f_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGpsDepF, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gps_dep_f_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGpsDepF); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_gps_dep_f, + sizeof(msg->ephemeris_gps_dep_f)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_gps_dep_f_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_gps_dep_f, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGpsDepF); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xfe73; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 183; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_gps_dep_f_t &lesser, + const sbp_msg_ephemeris_gps_dep_f_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_gps_dep_f_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_gps_dep_f_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGpsDepF, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGpsDepF, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGpsDepF, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGpsDepF, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_gps_dep_f_t test_msg_{}; + uint8_t encoded_frame_[183 + 8] = { + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, 0, + 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, + 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, + 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, + 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, + 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, + 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, + 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, + 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, + 176, 207, 6, 0, 106, 8, 45, 45, 0, 115, 254, + }; + uint8_t encoded_payload_[183] = { + 22, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, + 64, 64, 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, + 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, + 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, + 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, + 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, + 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, + 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, + 61, 0, 0, 0, 0, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, + 45, 45, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGpsDepF, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[183]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 183); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 183), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGpsDepF, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 183); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 183), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[183]; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 183), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[183]; + + for (uint8_t i = 0; i < 183; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_gps_dep_f_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_f_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 183); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGpsDepF, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 183); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_f_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_f_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_gps_dep_f_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGpsDepF, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGpsDepF, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGpsDepF, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gps_dep_f_t lesser = info.test_msg; + sbp_msg_ephemeris_gps_dep_f_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGpsDepF); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GPS_DEP_F"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_gps_dep_f_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_gps_dep_f_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_gps_dep_f, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_gps_dep_f, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[183]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 183); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 183), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gps_dep_f_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 183); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGpsDepF, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGPSDepF0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGpsDepF, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGal.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGal.cc index e4395163e3..f9ca899f7c 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGal.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGal.cc @@ -16,66 +16,397 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgEphemerisGal0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGal0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgEphemerisGal0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgEphemerisGal0() { + assign(test_msg_.af0, -1.7088896129280325e-05); + assign(test_msg_.af1, -8.185452315956353e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.bgd_e1e5a, 2.0954757928848267e-09); + assign(test_msg_.bgd_e1e5b, 2.0954757928848267e-09); + assign(test_msg_.c_ic, -3.166496753692627e-08); + assign(test_msg_.c_is, -3.166496753692627e-08); + assign(test_msg_.c_rc, 265.4375); + assign(test_msg_.c_rs, 10.125); + assign(test_msg_.c_uc, 5.364418029785156e-07); + assign(test_msg_.c_us, 3.993511199951172e-06); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 14); + assign(test_msg_.common.sid.sat, 27); + assign(test_msg_.common.toe.tow, 448800); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 3.119999885559082); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 3.2262058129932258e-09); + assign(test_msg_.ecc, 0.00017060607206076384); + assign(test_msg_.inc, 0.9777456094977858); + assign(test_msg_.inc_dot, -3.1787038343451465e-10); + assign(test_msg_.iodc, 108); + assign(test_msg_.iode, 108); + assign(test_msg_.m0, -1.8457115744155868); + assign(test_msg_.omega0, 1.16967730598334); + assign(test_msg_.omegadot, -5.757382675240872e-09); + assign(test_msg_.source, 0); + assign(test_msg_.sqrta, 5440.602401733398); + assign(test_msg_.toc.tow, 448800); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, 0.12250912091662625); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gal_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_gal_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGal, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gal_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGal); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_gal, + sizeof(msg->ephemeris_gal)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_gal_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_gal, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGal); + info.sender_id = 61568; + info.preamble = 0x55; + info.crc = 0xd047; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 153; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_gal_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_gal_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_gal_t &lesser, + const sbp_msg_ephemeris_gal_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_gal_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_gal_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_gal_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_gal_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGal, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisGal, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisGal, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisGal, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGal0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_gal_t test_msg_{}; + uint8_t encoded_frame_[153 + 8] = { 85, 141, 0, 128, 240, 153, 27, 14, 32, 217, 6, 0, 106, 8, 20, 174, 71, 64, 64, 56, 0, 0, 1, 0, 0, 0, 16, 49, 0, 0, 16, 49, 0, 0, 34, 65, 0, 184, 132, 67, 0, 0, 16, 53, 0, @@ -88,156 +419,608 @@ TEST_F(Test_auto_check_sbp_observation_MsgEphemerisGal0, Test) { 190, 255, 255, 255, 255, 255, 255, 161, 189, 0, 0, 0, 0, 32, 217, 6, 0, 106, 8, 108, 0, 108, 0, 0, 71, 208, }; + uint8_t encoded_payload_[153] = { + 27, 14, 32, 217, 6, 0, 106, 8, 20, 174, 71, 64, 64, 56, + 0, 0, 1, 0, 0, 0, 16, 49, 0, 0, 16, 49, 0, 0, + 34, 65, 0, 184, 132, 67, 0, 0, 16, 53, 0, 0, 134, 54, + 0, 0, 8, 179, 0, 0, 8, 179, 217, 204, 130, 105, 128, 182, + 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, 0, + 151, 92, 38, 63, 0, 0, 0, 55, 154, 64, 181, 64, 56, 38, + 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, 186, 56, 190, + 80, 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, + 239, 63, 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, + 67, 235, 241, 190, 255, 255, 255, 255, 255, 255, 161, 189, 0, 0, + 0, 0, 32, 217, 6, 0, 106, 8, 108, 0, 108, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_gal_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEphemerisGal, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[153]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_gal_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 153); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 153), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGal, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 153); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 153), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[153]; + + EXPECT_EQ(sbp_msg_ephemeris_gal_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 153), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[153]; - sbp_msg_ephemeris_gal_t test_msg{}; - test_msg.af0 = -1.7088896129280325e-05; - test_msg.af1 = -8.185452315956353e-12; - test_msg.af2 = 0.0; - test_msg.bgd_e1e5a = 2.0954757928848267e-09; - test_msg.bgd_e1e5b = 2.0954757928848267e-09; - test_msg.c_ic = -3.166496753692627e-08; - test_msg.c_is = -3.166496753692627e-08; - test_msg.c_rc = 265.4375; - test_msg.c_rs = 10.125; - test_msg.c_uc = 5.364418029785156e-07; - test_msg.c_us = 3.993511199951172e-06; - test_msg.common.fit_interval = 14400; - test_msg.common.health_bits = 0; - test_msg.common.sid.code = 14; - test_msg.common.sid.sat = 27; - test_msg.common.toe.tow = 448800; - test_msg.common.toe.wn = 2154; - test_msg.common.ura = 3.119999885559082; - test_msg.common.valid = 1; - test_msg.dn = 3.2262058129932258e-09; - test_msg.ecc = 0.00017060607206076384; - test_msg.inc = 0.9777456094977858; - test_msg.inc_dot = -3.1787038343451465e-10; - test_msg.iodc = 108; - test_msg.iode = 108; - test_msg.m0 = -1.8457115744155868; - test_msg.omega0 = 1.16967730598334; - test_msg.omegadot = -5.757382675240872e-09; - test_msg.source = 0; - test_msg.sqrta = 5440.602401733398; - test_msg.toc.tow = 448800; - test_msg.toc.wn = 2154; - test_msg.w = 0.12250912091662625; - - EXPECT_EQ(send_message(61568, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61568); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -1.70888961293e-05 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -1.70888961293e-05, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -8.18545231596e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -8.18545231596e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.bgd_e1e5a * 100 - 2.09547579288e-09 * 100), 0.05) - << "incorrect value for last_msg_.bgd_e1e5a, expected 2.09547579288e-09, " - "is " - << last_msg_.bgd_e1e5a; - EXPECT_LT((last_msg_.bgd_e1e5b * 100 - 2.09547579288e-09 * 100), 0.05) - << "incorrect value for last_msg_.bgd_e1e5b, expected 2.09547579288e-09, " - "is " - << last_msg_.bgd_e1e5b; - EXPECT_LT((last_msg_.c_ic * 100 - -3.16649675369e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected -3.16649675369e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - -3.16649675369e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected -3.16649675369e-08, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 265.4375 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 265.4375, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - 10.125 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected 10.125, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - 5.36441802979e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected 5.36441802979e-07, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 3.99351119995e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 3.99351119995e-06, is " - << last_msg_.c_us; - EXPECT_EQ(last_msg_.common.fit_interval, 14400) - << "incorrect value for last_msg_.common.fit_interval, expected 14400, " - "is " - << last_msg_.common.fit_interval; - EXPECT_EQ(last_msg_.common.health_bits, 0) - << "incorrect value for last_msg_.common.health_bits, expected 0, is " - << last_msg_.common.health_bits; - EXPECT_EQ(last_msg_.common.sid.code, 14) - << "incorrect value for last_msg_.common.sid.code, expected 14, is " - << last_msg_.common.sid.code; - EXPECT_EQ(last_msg_.common.sid.sat, 27) - << "incorrect value for last_msg_.common.sid.sat, expected 27, is " - << last_msg_.common.sid.sat; - EXPECT_EQ(last_msg_.common.toe.tow, 448800) - << "incorrect value for last_msg_.common.toe.tow, expected 448800, is " - << last_msg_.common.toe.tow; - EXPECT_EQ(last_msg_.common.toe.wn, 2154) - << "incorrect value for last_msg_.common.toe.wn, expected 2154, is " - << last_msg_.common.toe.wn; - EXPECT_LT((last_msg_.common.ura * 100 - 3.11999988556 * 100), 0.05) - << "incorrect value for last_msg_.common.ura, expected 3.11999988556, is " - << last_msg_.common.ura; - EXPECT_EQ(last_msg_.common.valid, 1) - << "incorrect value for last_msg_.common.valid, expected 1, is " - << last_msg_.common.valid; - EXPECT_LT((last_msg_.dn * 100 - 3.22620581299e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 3.22620581299e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.000170606072061 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.000170606072061, is " - << last_msg_.ecc; - EXPECT_LT((last_msg_.inc * 100 - 0.977745609498 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.977745609498, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - -3.17870383435e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected -3.17870383435e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iodc, 108) - << "incorrect value for last_msg_.iodc, expected 108, is " - << last_msg_.iodc; - EXPECT_EQ(last_msg_.iode, 108) - << "incorrect value for last_msg_.iode, expected 108, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - -1.84571157442 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected -1.84571157442, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - 1.16967730598 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected 1.16967730598, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -5.75738267524e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -5.75738267524e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.source, 0) - << "incorrect value for last_msg_.source, expected 0, is " - << last_msg_.source; - EXPECT_LT((last_msg_.sqrta * 100 - 5440.60240173 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5440.60240173, is " - << last_msg_.sqrta; - EXPECT_EQ(last_msg_.toc.tow, 448800) - << "incorrect value for last_msg_.toc.tow, expected 448800, is " - << last_msg_.toc.tow; - EXPECT_EQ(last_msg_.toc.wn, 2154) - << "incorrect value for last_msg_.toc.wn, expected 2154, is " - << last_msg_.toc.wn; - EXPECT_LT((last_msg_.w * 100 - 0.122509120917 * 100), 0.05) - << "incorrect value for last_msg_.w, expected 0.122509120917, is " - << last_msg_.w; + for (uint8_t i = 0; i < 153; i++) { + EXPECT_EQ(sbp_msg_ephemeris_gal_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_gal_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 153); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGal, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 153); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_gal_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_gal_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } } + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_gal_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGal, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.bgd_e1e5a, greater.bgd_e1e5a); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.bgd_e1e5b, greater.bgd_e1e5b); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.source, greater.source); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGal); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GAL"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_gal_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_gal_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_gal, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ephemeris_gal, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[153]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 153); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 153), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 153); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGal, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGal0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGal, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc new file mode 100644 index 0000000000..ef84fc207d --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc @@ -0,0 +1,1035 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisGalDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisGalDepA0() { + assign(test_msg_.af0, -1.7088896129280325e-05); + assign(test_msg_.af1, -8.185452315956353e-12); + assign(test_msg_.af2, 0.20000000298023224); + assign(test_msg_.bgd_e1e5a, 1.2000000476837158); + assign(test_msg_.bgd_e1e5b, 2.200000047683716); + assign(test_msg_.c_ic, 3.200000047683716); + assign(test_msg_.c_is, 4.199999809265137); + assign(test_msg_.c_rc, 265.4375); + assign(test_msg_.c_rs, 10.125); + assign(test_msg_.c_uc, 5.199999809265137); + assign(test_msg_.c_us, 6.199999809265137); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 14); + assign(test_msg_.common.sid.sat, 27); + assign(test_msg_.common.toe.tow, 448800); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 7.199999809265137); + assign(test_msg_.common.valid, 1); + assign(test_msg_.dn, 3.2262058129932258e-09); + assign(test_msg_.ecc, 0.00017060607206076384); + assign(test_msg_.inc, 0.9777456094977858); + assign(test_msg_.inc_dot, -3.1787038343451465e-10); + assign(test_msg_.iodc, 108); + assign(test_msg_.iode, 108); + assign(test_msg_.m0, -1.8457115744155868); + assign(test_msg_.omega0, 1.16967730598334); + assign(test_msg_.omegadot, -5.757382675240872e-09); + assign(test_msg_.sqrta, 5440.602401733398); + assign(test_msg_.toc.tow, 448800); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, 0.12250912091662625); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gal_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_gal_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisGalDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_gal_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisGalDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_gal_dep_a, + sizeof(msg->ephemeris_gal_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_gal_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_gal_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisGalDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x31a8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 152; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_gal_dep_a_t &lesser, + const sbp_msg_ephemeris_gal_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_gal_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_gal_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGalDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisGalDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisGalDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisGalDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_gal_dep_a_t test_msg_{}; + uint8_t encoded_frame_[152 + 8] = { + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, 102, + 102, 230, 64, 64, 56, 0, 0, 1, 0, 154, 153, 153, 63, 205, 204, + 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, 166, 64, 102, + 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, 217, 204, 130, 105, + 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, + 0, 151, 92, 38, 63, 0, 0, 0, 55, 154, 64, 181, 64, 56, 38, + 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, 186, 56, 190, 80, + 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, 239, 63, + 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, 67, 235, 241, + 190, 255, 255, 255, 255, 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, + 6, 0, 106, 8, 108, 0, 108, 0, 168, 49, + }; + uint8_t encoded_payload_[152] = { + 27, 14, 32, 217, 6, 0, 106, 8, 102, 102, 230, 64, 64, 56, + 0, 0, 1, 0, 154, 153, 153, 63, 205, 204, 12, 64, 0, 0, + 34, 65, 0, 184, 132, 67, 102, 102, 166, 64, 102, 102, 198, 64, + 205, 204, 76, 64, 102, 102, 134, 64, 217, 204, 130, 105, 128, 182, + 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, 0, + 151, 92, 38, 63, 0, 0, 0, 55, 154, 64, 181, 64, 56, 38, + 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, 186, 56, 190, + 80, 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, + 239, 63, 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, + 67, 235, 241, 190, 255, 255, 255, 255, 255, 255, 161, 189, 205, 204, + 76, 62, 32, 217, 6, 0, 106, 8, 108, 0, 108, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisGalDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[152]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 152); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 152), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisGalDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 152); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 152), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[152]; + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 152), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[152]; + + for (uint8_t i = 0; i < 152; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_gal_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 152); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisGalDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 152); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_gal_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGalDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisGalDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisGalDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.bgd_e1e5a, greater.bgd_e1e5a); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.bgd_e1e5b, greater.bgd_e1e5b); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_gal_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_gal_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisGalDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_GAL_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_gal_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_gal_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_gal_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_gal_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[152]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 152); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 152), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_gal_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 152); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisGalDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisGalDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisGalDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc new file mode 100644 index 0000000000..8491244f4a --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc @@ -0,0 +1,941 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisSbas0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisSbas0() { + assign(test_msg_.a_gf0, -0.0006315018981695175); + assign(test_msg_.a_gf1, 8.981260180007666e-12); + + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 0); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 6); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, -2.7939677238464355e-09); + assign(test_msg_.common.valid, 1); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + + assign(test_msg_.vel[0], -1726.5062255859375); + + assign(test_msg_.vel[1], -2542.614990234375); + + assign(test_msg_.vel[2], 869.8177490234375); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_sbas_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisSbas, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisSbas); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_sbas, + sizeof(msg->ephemeris_sbas)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_sbas_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_sbas, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisSbas); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x93c0; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 74; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_sbas_t &lesser, + const sbp_msg_ephemeris_sbas_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_sbas_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_sbas_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_sbas_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisSbas, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisSbas, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisSbas, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisSbas, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_sbas_t test_msg_{}; + uint8_t encoded_frame_[74 + 8] = { + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, + 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, + 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, 122, 53, 0, 128, + 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + }; + uint8_t encoded_payload_[74] = { + 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 64, 177, 0, 0, 0, + 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 51, 208, 215, + 196, 215, 233, 30, 197, 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, + 122, 53, 0, 128, 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_sbas_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisSbas, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisSbas, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + + for (uint8_t i = 0; i < 74; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_sbas_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisSbas, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbas, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisSbas, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbas, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf0, greater.a_gf0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf1, greater.a_gf1); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisSbas); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_SBAS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_sbas_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_sbas_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_sbas, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_sbas, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisSbas, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbas0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisSbas, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc new file mode 100644 index 0000000000..923cfedb3a --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc @@ -0,0 +1,963 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisSbasDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisSbasDepA0() { + assign(test_msg_.a_gf0, -0.0006315018981695175); + assign(test_msg_.a_gf1, 8.981260180007666e-12); + + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 0); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 6); + assign(test_msg_.common.sid.reserved, 0); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_sbas_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisSbasDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisSbasDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_sbas_dep_a, + sizeof(msg->ephemeris_sbas_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_sbas_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_sbas_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisSbasDepA); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xb4b2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 112; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_sbas_dep_a_t &lesser, + const sbp_msg_ephemeris_sbas_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_sbas_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_sbas_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisSbasDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisSbasDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisSbasDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisSbasDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_sbas_dep_a_t test_msg_{}; + uint8_t encoded_frame_[112 + 8] = { + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, 106, + 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, + 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, + 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, + 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, + 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 178, 180, + }; + uint8_t encoded_payload_[112] = { + 22, 0, 6, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, + 0, 64, 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, + 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, + 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisSbasDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisSbasDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + + for (uint8_t i = 0; i < 112; i++) { + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisSbasDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbasDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisSbasDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbasDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf0, greater.a_gf0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf1, greater.a_gf1); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.reserved, + greater.common.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_a_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisSbasDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_SBAS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_sbas_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_sbas_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_sbas_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_sbas_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[112]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 112); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 112), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 112); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisSbasDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisSbasDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc new file mode 100644 index 0000000000..74286f27d2 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc @@ -0,0 +1,955 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgEphemerisSbasDepB0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgEphemerisSbasDepB0() { + assign(test_msg_.a_gf0, -0.0006315018981695175); + assign(test_msg_.a_gf1, 8.981260180007666e-12); + + assign(test_msg_.acc[0], 9.313225746154785e-07); + + assign(test_msg_.acc[1], 9.313225746154785e-07); + + assign(test_msg_.acc[2], 2.7939677238464355e-06); + assign(test_msg_.common.fit_interval, 0); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 6); + assign(test_msg_.common.sid.sat, 22); + assign(test_msg_.common.toe.tow, 446384); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 1); + + assign(test_msg_.pos[0], -12177330.078125); + + assign(test_msg_.pos[1], 599893.06640625); + + assign(test_msg_.pos[2], -22373708.49609375); + + assign(test_msg_.vel[0], -1726.506233215332); + + assign(test_msg_.vel[1], -2542.6149368286133); + + assign(test_msg_.vel[2], 869.8177337646484); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_sbas_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisSbasDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_sbas_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisSbasDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_sbas_dep_b, + sizeof(msg->ephemeris_sbas_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_sbas_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_sbas_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisSbasDepB); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0x6891; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 110; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_sbas_dep_b_t &lesser, + const sbp_msg_ephemeris_sbas_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_sbas_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_sbas_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisSbasDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisSbasDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEphemerisSbasDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEphemerisSbasDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_sbas_dep_b_t test_msg_{}; + uint8_t encoded_frame_[110 + 8] = { + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, 0, + 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, 0, 0, + 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, + 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, 46, 139, + 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, + 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 145, 104, + }; + uint8_t encoded_payload_[110] = { + 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, + 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, + 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, + 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisSbasDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisSbasDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + for (uint8_t i = 0; i < 110; i++) { + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisSbasDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_sbas_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbasDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisSbasDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisSbasDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf0, greater.a_gf0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.a_gf1, greater.a_gf1); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[0], greater.acc[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[1], greater.acc[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.acc[2], greater.acc[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[0], greater.pos[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[1], greater.pos[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.pos[2], greater.pos[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[0], greater.vel[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[1], greater.vel[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ephemeris_sbas_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_sbas_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.vel[2], greater.vel[2]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisSbasDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_SBAS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_sbas_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_sbas_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ephemeris_sbas_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_sbas_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_sbas_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisSbasDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgEphemerisSbasDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisSbasDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgGloBiases.cc b/c/test/cpp/auto_check_sbp_observation_MsgGloBiases.cc index 7f21221b34..c5fe9402d7 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgGloBiases.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgGloBiases.cc @@ -16,101 +16,784 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgGloBiases0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgGloBiases0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgGloBiases0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgGloBiases0() { + assign(test_msg_.l1ca_bias, 0); + assign(test_msg_.l1p_bias, 0); + assign(test_msg_.l2ca_bias, 0); + assign(test_msg_.l2p_bias, 0); + assign(test_msg_.mask, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_glo_biases_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_glo_biases_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGloBiases, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_glo_biases_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGloBiases); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->glo_biases, sizeof(msg->glo_biases)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_glo_biases_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.glo_biases, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGloBiases); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0xd34d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_glo_biases_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_glo_biases_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_glo_biases_t &lesser, + const sbp_msg_glo_biases_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_glo_biases_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_glo_biases_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_glo_biases_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_glo_biases_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGloBiases, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGloBiases, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGloBiases, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGloBiases, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_observation_MsgGloBiases0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_glo_biases_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { 85, 117, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 211, }; + uint8_t encoded_payload_[9] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; +}; - sbp_msg_glo_biases_t test_msg{}; - test_msg.l1ca_bias = 0; - test_msg.l1p_bias = 0; - test_msg.l2ca_bias = 0; - test_msg.l2p_bias = 0; - test_msg.mask = 0; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.l1ca_bias, 0) - << "incorrect value for last_msg_.l1ca_bias, expected 0, is " - << last_msg_.l1ca_bias; - EXPECT_EQ(last_msg_.l1p_bias, 0) - << "incorrect value for last_msg_.l1p_bias, expected 0, is " - << last_msg_.l1p_bias; - EXPECT_EQ(last_msg_.l2ca_bias, 0) - << "incorrect value for last_msg_.l2ca_bias, expected 0, is " - << last_msg_.l2ca_bias; - EXPECT_EQ(last_msg_.l2p_bias, 0) - << "incorrect value for last_msg_.l2p_bias, expected 0, is " - << last_msg_.l2p_bias; - EXPECT_EQ(last_msg_.mask, 0) - << "incorrect value for last_msg_.mask, expected 0, is " - << last_msg_.mask; +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_glo_biases_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGloBiases, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_glo_biases_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGloBiases, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ( + sbp_msg_glo_biases_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_msg_glo_biases_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_glo_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_glo_biases_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGloBiases, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_glo_biases_t msg{}; + + EXPECT_EQ(sbp_msg_glo_biases_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_glo_biases_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_glo_biases_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_glo_biases_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGloBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGloBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGloBiases, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_glo_biases_t lesser = info.test_msg; + sbp_msg_glo_biases_t greater = info.test_msg; + make_lesser_greater(lesser.l1ca_bias, greater.l1ca_bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_glo_biases_t lesser = info.test_msg; + sbp_msg_glo_biases_t greater = info.test_msg; + make_lesser_greater(lesser.l1p_bias, greater.l1p_bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_glo_biases_t lesser = info.test_msg; + sbp_msg_glo_biases_t greater = info.test_msg; + make_lesser_greater(lesser.l2ca_bias, greater.l2ca_bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_glo_biases_t lesser = info.test_msg; + sbp_msg_glo_biases_t greater = info.test_msg; + make_lesser_greater(lesser.l2p_bias, greater.l2p_bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_glo_biases_t lesser = info.test_msg; + sbp_msg_glo_biases_t greater = info.test_msg; + make_lesser_greater(lesser.mask, greater.mask); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGloBiases); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GLO_BIASES"); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_glo_biases_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_glo_biases_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.glo_biases, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.glo_biases, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_glo_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGloBiases, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGloBiases0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGloBiases, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgGnssCapb.cc b/c/test/cpp/auto_check_sbp_observation_MsgGnssCapb.cc new file mode 100644 index 0000000000..4db46808c5 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgGnssCapb.cc @@ -0,0 +1,892 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgGnssCapb0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgGnssCapb0() { + assign(test_msg_.gc.bds_active, 1929005864); + assign(test_msg_.gc.bds_b2, 33839445); + assign(test_msg_.gc.bds_b2a, 378107113); + assign(test_msg_.gc.bds_d2nav, 1367053175); + assign(test_msg_.gc.gal_active, 1392028637); + assign(test_msg_.gc.gal_e5, 484261628); + assign(test_msg_.gc.glo_active, 13159676); + assign(test_msg_.gc.glo_l2of, 824073421); + assign(test_msg_.gc.glo_l3, 404081648); + assign(test_msg_.gc.gps_active, 1079028506); + assign(test_msg_.gc.gps_l2c, 781233489); + assign(test_msg_.gc.gps_l5, 1818069969); + assign(test_msg_.gc.qzss_active, 198929863); + assign(test_msg_.gc.sbas_active, 548822484); + assign(test_msg_.gc.sbas_l5, 465576041); + assign(test_msg_.t_nmct.tow, 446384); + assign(test_msg_.t_nmct.wn, 2154); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gnss_capb_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gnss_capb_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGnssCapb, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gnss_capb_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGnssCapb); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gnss_capb, sizeof(msg->gnss_capb)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gnss_capb_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gnss_capb, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGnssCapb); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0x5aa3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 110; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gnss_capb_t &lesser, + const sbp_msg_gnss_capb_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gnss_capb_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gnss_capb_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gnss_capb_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gnss_capb_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgGnssCapb, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGnssCapb, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGnssCapb, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGnssCapb, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gnss_capb_t test_msg_{}; + uint8_t encoded_frame_[110 + 8] = { + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, + 64, 0, 0, 0, 0, 81, 173, 144, 46, 0, 0, 0, 0, 209, 139, + 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, 240, + 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, + 0, 0, 0, 0, 40, 75, 250, 114, 0, 0, 0, 0, 119, 147, 123, + 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, 116, + 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, + 0, 0, 0, 252, 62, 221, 28, 0, 0, 0, 0, 163, 90, + }; + uint8_t encoded_payload_[110] = { + 176, 207, 6, 0, 106, 8, 26, 171, 80, 64, 0, 0, 0, 0, + 81, 173, 144, 46, 0, 0, 0, 0, 209, 139, 93, 108, 0, 0, + 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, 240, 203, 21, 24, + 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, 0, 0, + 0, 0, 40, 75, 250, 114, 0, 0, 0, 0, 119, 147, 123, 81, + 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, 116, + 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, + 0, 0, 0, 0, 252, 62, 221, 28, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gnss_capb_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGnssCapb, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gnss_capb_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgGnssCapb, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + EXPECT_EQ( + sbp_msg_gnss_capb_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + + for (uint8_t i = 0; i < 110; i++) { + EXPECT_EQ(sbp_msg_gnss_capb_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gnss_capb_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gnss_capb_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGnssCapb, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gnss_capb_t msg{}; + + EXPECT_EQ(sbp_msg_gnss_capb_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gnss_capb_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_gnss_capb_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gnss_capb_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGnssCapb, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGnssCapb, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGnssCapb, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.bds_active, greater.gc.bds_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.bds_b2, greater.gc.bds_b2); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.bds_b2a, greater.gc.bds_b2a); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.bds_d2nav, greater.gc.bds_d2nav); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.gal_active, greater.gc.gal_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.gal_e5, greater.gc.gal_e5); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.glo_active, greater.gc.glo_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.glo_l2of, greater.gc.glo_l2of); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.glo_l3, greater.gc.glo_l3); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.gps_active, greater.gc.gps_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.gps_l2c, greater.gc.gps_l2c); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.gps_l5, greater.gc.gps_l5); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.qzss_active, greater.gc.qzss_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.sbas_active, greater.gc.sbas_active); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.gc.sbas_l5, greater.gc.sbas_l5); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.tow, greater.t_nmct.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_capb_t lesser = info.test_msg; + sbp_msg_gnss_capb_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.wn, greater.t_nmct.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGnssCapb); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_GNSS_CAPB"); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gnss_capb_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gnss_capb_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gnss_capb, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.gnss_capb, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[110]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 110); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 110), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gnss_capb_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 110); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGnssCapb, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGnssCapb0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgGnssCapb, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgGroupDelay.cc b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelay.cc new file mode 100644 index 0000000000..e344dc25b9 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelay.cc @@ -0,0 +1,823 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgGroupDelay0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgGroupDelay0() { + assign(test_msg_.isc_l1ca, -91); + assign(test_msg_.isc_l2c, 6125); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.sat, 22); + assign(test_msg_.t_op.tow, 446384); + assign(test_msg_.t_op.wn, 2154); + assign(test_msg_.tgd, -514); + assign(test_msg_.valid, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_group_delay_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGroupDelay, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGroupDelay); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->group_delay, sizeof(msg->group_delay)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_group_delay_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.group_delay, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGroupDelay); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xc902; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_group_delay_t &lesser, + const sbp_msg_group_delay_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_group_delay_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_group_delay_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_group_delay_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_group_delay_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupDelay, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupDelay, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGroupDelay, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGroupDelay, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_group_delay_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, + 22, 0, 1, 254, 253, 165, 255, 237, 23, 2, 201, + }; + uint8_t encoded_payload_[15] = { + 176, 207, 6, 0, 106, 8, 22, 0, 1, 254, 253, 165, 255, 237, 23, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_group_delay_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGroupDelay, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_group_delay_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGroupDelay, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ( + sbp_msg_group_delay_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ(sbp_msg_group_delay_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_group_delay_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGroupDelay, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_t msg{}; + + EXPECT_EQ(sbp_msg_group_delay_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_group_delay_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_group_delay_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelay, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGroupDelay, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelay, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l1ca, greater.isc_l1ca); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l2c, greater.isc_l2c); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.tow, greater.t_op.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.wn, greater.t_op.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_t lesser = info.test_msg; + sbp_msg_group_delay_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGroupDelay); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GROUP_DELAY"); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_group_delay_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_group_delay_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.group_delay, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.group_delay, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGroupDelay, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelay0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGroupDelay, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc new file mode 100644 index 0000000000..ade05558a0 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc @@ -0,0 +1,832 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgGroupDelayDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgGroupDelayDepA0() { + assign(test_msg_.isc_l1ca, -91); + assign(test_msg_.isc_l2c, 6125); + assign(test_msg_.prn, 22); + assign(test_msg_.t_op.tow, 446384); + assign(test_msg_.t_op.wn, 2154); + assign(test_msg_.tgd, -514); + assign(test_msg_.valid, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_group_delay_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGroupDelayDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGroupDelayDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->group_delay_dep_a, + sizeof(msg->group_delay_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_group_delay_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.group_delay_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGroupDelayDepA); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0x5ba2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_group_delay_dep_a_t &lesser, + const sbp_msg_group_delay_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_group_delay_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_group_delay_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_group_delay_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_group_delay_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupDelayDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgGroupDelayDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGroupDelayDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGroupDelayDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_group_delay_dep_a_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, + 8, 22, 1, 254, 253, 165, 255, 237, 23, 162, 91, + }; + uint8_t encoded_payload_[14] = { + 176, 207, 6, 0, 106, 8, 22, 1, 254, 253, 165, 255, 237, 23, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_group_delay_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgGroupDelayDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_group_delay_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGroupDelayDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ(sbp_msg_group_delay_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ( + sbp_msg_group_delay_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_group_delay_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGroupDelayDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_group_delay_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_group_delay_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_group_delay_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelayDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGroupDelayDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelayDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l1ca, greater.isc_l1ca); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l2c, greater.isc_l2c); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.tow, greater.t_op.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.wn, greater.t_op.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_a_t lesser = info.test_msg; + sbp_msg_group_delay_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGroupDelayDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GROUP_DELAY_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_group_delay_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_group_delay_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.group_delay_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.group_delay_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGroupDelayDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGroupDelayDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc new file mode 100644 index 0000000000..a45e3e6a65 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc @@ -0,0 +1,846 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgGroupDelayDepB0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgGroupDelayDepB0() { + assign(test_msg_.isc_l1ca, -91); + assign(test_msg_.isc_l2c, 6125); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 22); + assign(test_msg_.t_op.tow, 446384); + assign(test_msg_.t_op.wn, 2154); + assign(test_msg_.tgd, -514); + assign(test_msg_.valid, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_group_delay_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGroupDelayDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_group_delay_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGroupDelayDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->group_delay_dep_b, + sizeof(msg->group_delay_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_group_delay_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.group_delay_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGroupDelayDepB); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xcadd; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 17; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_group_delay_dep_b_t &lesser, + const sbp_msg_group_delay_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_group_delay_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_group_delay_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_group_delay_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_group_delay_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupDelayDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgGroupDelayDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGroupDelayDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGroupDelayDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_group_delay_dep_b_t test_msg_{}; + uint8_t encoded_frame_[17 + 8] = { + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, + 0, 0, 0, 1, 254, 253, 165, 255, 237, 23, 221, 202, + }; + uint8_t encoded_payload_[17] = { + 176, 207, 6, 0, 106, 8, 22, 0, 0, 0, 1, 254, 253, 165, 255, 237, 23, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_group_delay_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgGroupDelayDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_group_delay_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGroupDelayDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + EXPECT_EQ(sbp_msg_group_delay_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ( + sbp_msg_group_delay_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_group_delay_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGroupDelayDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_group_delay_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_group_delay_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_group_delay_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelayDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGroupDelayDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupDelayDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l1ca, greater.isc_l1ca); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.isc_l2c, greater.isc_l2c); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.tow, greater.t_op.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.t_op.wn, greater.t_op.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_delay_dep_b_t lesser = info.test_msg; + sbp_msg_group_delay_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGroupDelayDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GROUP_DELAY_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_group_delay_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_group_delay_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.group_delay_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.group_delay_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_delay_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGroupDelayDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgGroupDelayDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGroupDelayDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgIono.cc b/c/test/cpp/auto_check_sbp_observation_MsgIono.cc new file mode 100644 index 0000000000..a84ce0adeb --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgIono.cc @@ -0,0 +1,829 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgIono0 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgIono0() { + assign(test_msg_.a0, 4.6566128730773926e-09); + assign(test_msg_.a1, 1.4901161193847656e-08); + assign(test_msg_.a2, -5.960464477539063e-08); + assign(test_msg_.a3, -5.960464477539063e-08); + assign(test_msg_.b0, 77824.0); + assign(test_msg_.b1, 49152.0); + assign(test_msg_.b2, -65536.0); + assign(test_msg_.b3, -327680.0); + assign(test_msg_.t_nmct.tow, 0); + assign(test_msg_.t_nmct.wn, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iono_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iono_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIono, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iono_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIono); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iono, sizeof(msg->iono)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iono_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iono, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIono); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0x1f65; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 70; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iono_t &lesser, + const sbp_msg_iono_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iono_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iono_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iono_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iono_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIono, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgIono, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgIono, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgIono, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iono_t test_msg_{}; + uint8_t encoded_frame_[70 + 8] = { + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, 80, 62, 0, 0, 0, 0, + 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, + 0, 0, 243, 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, + 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, 101, 31, + }; + uint8_t encoded_payload_[70] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 62, + 0, 0, 0, 0, 0, 0, 80, 62, 0, 0, 0, 0, 0, 0, + 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, + 0, 0, 243, 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, + 0, 0, 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgIono0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iono_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIono, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_iono_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIono, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + EXPECT_EQ(sbp_msg_iono_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgIono0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + + for (uint8_t i = 0; i < 70; i++) { + EXPECT_EQ(sbp_msg_iono_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iono_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iono_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIono, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iono_t msg{}; + + EXPECT_EQ(sbp_msg_iono_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgIono0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iono_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_iono_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iono_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIono, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIono, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIono, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.a0, greater.a0); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.a1, greater.a1); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.a2, greater.a2); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.a3, greater.a3); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.b0, greater.b0); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.b1, greater.b1); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.b2, greater.b2); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.b3, greater.b3); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.tow, greater.t_nmct.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_iono_t lesser = info.test_msg; + sbp_msg_iono_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.wn, greater.t_nmct.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIono); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IONO"); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iono_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iono_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iono, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iono, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[70]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 70); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 70), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iono_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 70); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIono, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgIono0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIono, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgObs.cc b/c/test/cpp/auto_check_sbp_observation_MsgObs.cc index 76f8240897..dcb729ef91 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgObs.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgObs.cc @@ -16,65 +16,513 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgObs0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgObs0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgObs0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgObs0() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.ns_residual, 0); + assign(test_msg_.header.t.tow, 434293400); + assign(test_msg_.header.t.wn, 2154); + assign(test_msg_.n_obs, 14); + + assign(test_msg_.obs[0].D.f, 172); + assign(test_msg_.obs[0].D.i, -1536); + assign(test_msg_.obs[0].L.f, 146); + assign(test_msg_.obs[0].L.i, 111080057); + assign(test_msg_.obs[0].P, 1056891697); + assign(test_msg_.obs[0].cn0, 182); + assign(test_msg_.obs[0].flags, 15); + assign(test_msg_.obs[0].lock, 10); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.sat, 10); + + assign(test_msg_.obs[1].D.f, 172); + assign(test_msg_.obs[1].D.i, -1197); + assign(test_msg_.obs[1].L.f, 59); + assign(test_msg_.obs[1].L.i, 86555916); + assign(test_msg_.obs[1].P, 1056891934); + assign(test_msg_.obs[1].cn0, 178); + assign(test_msg_.obs[1].flags, 15); + assign(test_msg_.obs[1].lock, 10); + assign(test_msg_.obs[1].sid.code, 1); + assign(test_msg_.obs[1].sid.sat, 10); + + assign(test_msg_.obs[2].D.f, 119); + assign(test_msg_.obs[2].D.i, -3219); + assign(test_msg_.obs[2].L.f, 243); + assign(test_msg_.obs[2].L.i, 127954794); + assign(test_msg_.obs[2].P, 1217449431); + assign(test_msg_.obs[2].cn0, 158); + assign(test_msg_.obs[2].flags, 15); + assign(test_msg_.obs[2].lock, 10); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.sat, 18); + + assign(test_msg_.obs[3].D.f, 27); + assign(test_msg_.obs[3].D.i, -2508); + assign(test_msg_.obs[3].L.f, 12); + assign(test_msg_.obs[3].L.i, 99705055); + assign(test_msg_.obs[3].P, 1217449753); + assign(test_msg_.obs[3].cn0, 125); + assign(test_msg_.obs[3].flags, 11); + assign(test_msg_.obs[3].lock, 9); + assign(test_msg_.obs[3].sid.code, 1); + assign(test_msg_.obs[3].sid.sat, 18); + + assign(test_msg_.obs[4].D.f, 245); + assign(test_msg_.obs[4].D.i, 2829); + assign(test_msg_.obs[4].L.f, 53); + assign(test_msg_.obs[4].L.i, 132024982); + assign(test_msg_.obs[4].P, 1256175650); + assign(test_msg_.obs[4].cn0, 114); + assign(test_msg_.obs[4].flags, 15); + assign(test_msg_.obs[4].lock, 9); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.sat, 22); + + assign(test_msg_.obs[5].D.f, 246); + assign(test_msg_.obs[5].D.i, -2433); + assign(test_msg_.obs[5].L.f, 70); + assign(test_msg_.obs[5].L.i, 121711010); + assign(test_msg_.obs[5].P, 1158041713); + assign(test_msg_.obs[5].cn0, 189); + assign(test_msg_.obs[5].flags, 15); + assign(test_msg_.obs[5].lock, 9); + assign(test_msg_.obs[5].sid.code, 0); + assign(test_msg_.obs[5].sid.sat, 23); + + assign(test_msg_.obs[6].D.f, 231); + assign(test_msg_.obs[6].D.i, -1896); + assign(test_msg_.obs[6].L.f, 221); + assign(test_msg_.obs[6].L.i, 94839765); + assign(test_msg_.obs[6].P, 1158041847); + assign(test_msg_.obs[6].cn0, 158); + assign(test_msg_.obs[6].flags, 11); + assign(test_msg_.obs[6].lock, 9); + assign(test_msg_.obs[6].sid.code, 1); + assign(test_msg_.obs[6].sid.sat, 23); + + assign(test_msg_.obs[7].D.f, 67); + assign(test_msg_.obs[7].D.i, -1997); + assign(test_msg_.obs[7].L.f, 114); + assign(test_msg_.obs[7].L.i, 113998348); + assign(test_msg_.obs[7].P, 1084658184); + assign(test_msg_.obs[7].cn0, 93); + assign(test_msg_.obs[7].flags, 11); + assign(test_msg_.obs[7].lock, 3); + assign(test_msg_.obs[7].sid.code, 0); + assign(test_msg_.obs[7].sid.sat, 27); + + assign(test_msg_.obs[8].D.f, 237); + assign(test_msg_.obs[8].D.i, 3041); + assign(test_msg_.obs[8].L.f, 232); + assign(test_msg_.obs[8].L.i, 133443545); + assign(test_msg_.obs[8].P, 1269673181); + assign(test_msg_.obs[8].cn0, 123); + assign(test_msg_.obs[8].flags, 15); + assign(test_msg_.obs[8].lock, 5); + assign(test_msg_.obs[8].sid.code, 0); + assign(test_msg_.obs[8].sid.sat, 31); + + assign(test_msg_.obs[9].D.f, 62); + assign(test_msg_.obs[9].D.i, 2374); + assign(test_msg_.obs[9].L.f, 40); + assign(test_msg_.obs[9].L.i, 103982040); + assign(test_msg_.obs[9].P, 1269673722); + assign(test_msg_.obs[9].cn0, 120); + assign(test_msg_.obs[9].flags, 11); + assign(test_msg_.obs[9].lock, 3); + assign(test_msg_.obs[9].sid.code, 1); + assign(test_msg_.obs[9].sid.sat, 31); + + assign(test_msg_.obs[10].D.f, 96); + assign(test_msg_.obs[10].D.i, -3446); + assign(test_msg_.obs[10].L.f, 7); + assign(test_msg_.obs[10].L.i, 118217315); + assign(test_msg_.obs[10].P, 1107693703); + assign(test_msg_.obs[10].cn0, 176); + assign(test_msg_.obs[10].flags, 15); + assign(test_msg_.obs[10].lock, 10); + assign(test_msg_.obs[10].sid.code, 3); + assign(test_msg_.obs[10].sid.sat, 2); + + assign(test_msg_.obs[11].D.f, 96); + assign(test_msg_.obs[11].D.i, -1003); + assign(test_msg_.obs[11].L.f, 203); + assign(test_msg_.obs[11].L.i, 104224985); + assign(test_msg_.obs[11].P, 973505172); + assign(test_msg_.obs[11].cn0, 170); + assign(test_msg_.obs[11].flags, 15); + assign(test_msg_.obs[11].lock, 10); + assign(test_msg_.obs[11].sid.code, 3); + assign(test_msg_.obs[11].sid.sat, 3); + + assign(test_msg_.obs[12].D.f, 219); + assign(test_msg_.obs[12].D.i, -3836); + assign(test_msg_.obs[12].L.f, 80); + assign(test_msg_.obs[12].L.i, 114505343); + assign(test_msg_.obs[12].P, 1069903034); + assign(test_msg_.obs[12].cn0, 200); + assign(test_msg_.obs[12].flags, 15); + assign(test_msg_.obs[12].lock, 10); + assign(test_msg_.obs[12].sid.code, 3); + assign(test_msg_.obs[12].sid.sat, 17); + + assign(test_msg_.obs[13].D.f, 182); + assign(test_msg_.obs[13].D.i, -461); + assign(test_msg_.obs[13].L.f, 105); + assign(test_msg_.obs[13].L.i, 102157331); + assign(test_msg_.obs[13].P, 956875687); + assign(test_msg_.obs[13].cn0, 152); + assign(test_msg_.obs[13].flags, 15); + assign(test_msg_.obs[13].lock, 10); + assign(test_msg_.obs[13].sid.code, 3); + assign(test_msg_.obs[13].sid.sat, 18); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, const sbp_msg_obs_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObs, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObs); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs, sizeof(msg->obs)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObs); + info.sender_id = 61569; + info.preamble = 0x55; + info.crc = 0xf8ed; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 249; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_obs_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_obs_t &lesser, + const sbp_msg_obs_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObs, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgObs, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObs, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObs, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_MsgObs0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_obs_t test_msg_{}; + uint8_t encoded_frame_[249 + 8] = { 85, 74, 0, 129, 240, 249, 152, 202, 226, 25, 0, 0, 0, 0, 106, 8, 32, 49, 227, 254, 62, 121, 242, 158, 6, 146, 0, 250, 172, 182, 10, 15, 10, 0, 30, 228, 254, 62, 12, 189, 40, 5, 59, 83, 251, @@ -94,704 +542,2046 @@ TEST_F(Test_auto_check_sbp_observation_MsgObs0, Test) { 8, 57, 19, 204, 22, 6, 105, 51, 254, 182, 152, 10, 15, 18, 3, 237, 248, }; + uint8_t encoded_payload_[249] = { + 152, 202, 226, 25, 0, 0, 0, 0, 106, 8, 32, 49, 227, 254, 62, + 121, 242, 158, 6, 146, 0, 250, 172, 182, 10, 15, 10, 0, 30, 228, + 254, 62, 12, 189, 40, 5, 59, 83, 251, 172, 178, 10, 15, 10, 1, + 215, 205, 144, 72, 106, 111, 160, 7, 243, 109, 243, 119, 158, 10, 15, + 18, 0, 25, 207, 144, 72, 223, 96, 241, 5, 12, 52, 246, 27, 125, + 9, 11, 18, 1, 34, 184, 223, 74, 150, 138, 222, 7, 53, 13, 11, + 245, 114, 9, 15, 22, 0, 113, 80, 6, 69, 162, 41, 65, 7, 70, + 127, 246, 246, 189, 9, 15, 23, 0, 247, 80, 6, 69, 213, 35, 167, + 5, 221, 152, 248, 231, 158, 9, 11, 23, 1, 8, 146, 166, 64, 12, + 122, 203, 6, 114, 51, 248, 67, 93, 3, 11, 27, 0, 221, 172, 173, + 75, 217, 47, 244, 7, 232, 225, 11, 237, 123, 5, 15, 31, 0, 250, + 174, 173, 75, 216, 163, 50, 6, 40, 70, 9, 62, 120, 3, 11, 31, + 1, 135, 16, 6, 66, 99, 218, 11, 7, 7, 138, 242, 96, 176, 10, + 15, 2, 3, 148, 130, 6, 58, 217, 88, 54, 6, 203, 21, 252, 96, + 170, 10, 15, 3, 3, 186, 108, 197, 63, 127, 54, 211, 6, 80, 4, + 241, 219, 200, 10, 15, 17, 3, 167, 195, 8, 57, 19, 204, 22, 6, + 105, 51, 254, 182, 152, 10, 15, 18, 3, + }; +}; - sbp_msg_obs_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.ns_residual = 0; - test_msg.header.t.tow = 434293400; - test_msg.header.t.wn = 2154; - test_msg.n_obs = 14; - - test_msg.obs[0].D.f = 172; - test_msg.obs[0].D.i = -1536; - test_msg.obs[0].L.f = 146; - test_msg.obs[0].L.i = 111080057; - test_msg.obs[0].P = 1056891697; - test_msg.obs[0].cn0 = 182; - test_msg.obs[0].flags = 15; - test_msg.obs[0].lock = 10; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.sat = 10; - - test_msg.obs[1].D.f = 172; - test_msg.obs[1].D.i = -1197; - test_msg.obs[1].L.f = 59; - test_msg.obs[1].L.i = 86555916; - test_msg.obs[1].P = 1056891934; - test_msg.obs[1].cn0 = 178; - test_msg.obs[1].flags = 15; - test_msg.obs[1].lock = 10; - test_msg.obs[1].sid.code = 1; - test_msg.obs[1].sid.sat = 10; - - test_msg.obs[2].D.f = 119; - test_msg.obs[2].D.i = -3219; - test_msg.obs[2].L.f = 243; - test_msg.obs[2].L.i = 127954794; - test_msg.obs[2].P = 1217449431; - test_msg.obs[2].cn0 = 158; - test_msg.obs[2].flags = 15; - test_msg.obs[2].lock = 10; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.sat = 18; - - test_msg.obs[3].D.f = 27; - test_msg.obs[3].D.i = -2508; - test_msg.obs[3].L.f = 12; - test_msg.obs[3].L.i = 99705055; - test_msg.obs[3].P = 1217449753; - test_msg.obs[3].cn0 = 125; - test_msg.obs[3].flags = 11; - test_msg.obs[3].lock = 9; - test_msg.obs[3].sid.code = 1; - test_msg.obs[3].sid.sat = 18; - - test_msg.obs[4].D.f = 245; - test_msg.obs[4].D.i = 2829; - test_msg.obs[4].L.f = 53; - test_msg.obs[4].L.i = 132024982; - test_msg.obs[4].P = 1256175650; - test_msg.obs[4].cn0 = 114; - test_msg.obs[4].flags = 15; - test_msg.obs[4].lock = 9; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.sat = 22; - - test_msg.obs[5].D.f = 246; - test_msg.obs[5].D.i = -2433; - test_msg.obs[5].L.f = 70; - test_msg.obs[5].L.i = 121711010; - test_msg.obs[5].P = 1158041713; - test_msg.obs[5].cn0 = 189; - test_msg.obs[5].flags = 15; - test_msg.obs[5].lock = 9; - test_msg.obs[5].sid.code = 0; - test_msg.obs[5].sid.sat = 23; - - test_msg.obs[6].D.f = 231; - test_msg.obs[6].D.i = -1896; - test_msg.obs[6].L.f = 221; - test_msg.obs[6].L.i = 94839765; - test_msg.obs[6].P = 1158041847; - test_msg.obs[6].cn0 = 158; - test_msg.obs[6].flags = 11; - test_msg.obs[6].lock = 9; - test_msg.obs[6].sid.code = 1; - test_msg.obs[6].sid.sat = 23; - - test_msg.obs[7].D.f = 67; - test_msg.obs[7].D.i = -1997; - test_msg.obs[7].L.f = 114; - test_msg.obs[7].L.i = 113998348; - test_msg.obs[7].P = 1084658184; - test_msg.obs[7].cn0 = 93; - test_msg.obs[7].flags = 11; - test_msg.obs[7].lock = 3; - test_msg.obs[7].sid.code = 0; - test_msg.obs[7].sid.sat = 27; - - test_msg.obs[8].D.f = 237; - test_msg.obs[8].D.i = 3041; - test_msg.obs[8].L.f = 232; - test_msg.obs[8].L.i = 133443545; - test_msg.obs[8].P = 1269673181; - test_msg.obs[8].cn0 = 123; - test_msg.obs[8].flags = 15; - test_msg.obs[8].lock = 5; - test_msg.obs[8].sid.code = 0; - test_msg.obs[8].sid.sat = 31; - - test_msg.obs[9].D.f = 62; - test_msg.obs[9].D.i = 2374; - test_msg.obs[9].L.f = 40; - test_msg.obs[9].L.i = 103982040; - test_msg.obs[9].P = 1269673722; - test_msg.obs[9].cn0 = 120; - test_msg.obs[9].flags = 11; - test_msg.obs[9].lock = 3; - test_msg.obs[9].sid.code = 1; - test_msg.obs[9].sid.sat = 31; - - test_msg.obs[10].D.f = 96; - test_msg.obs[10].D.i = -3446; - test_msg.obs[10].L.f = 7; - test_msg.obs[10].L.i = 118217315; - test_msg.obs[10].P = 1107693703; - test_msg.obs[10].cn0 = 176; - test_msg.obs[10].flags = 15; - test_msg.obs[10].lock = 10; - test_msg.obs[10].sid.code = 3; - test_msg.obs[10].sid.sat = 2; - - test_msg.obs[11].D.f = 96; - test_msg.obs[11].D.i = -1003; - test_msg.obs[11].L.f = 203; - test_msg.obs[11].L.i = 104224985; - test_msg.obs[11].P = 973505172; - test_msg.obs[11].cn0 = 170; - test_msg.obs[11].flags = 15; - test_msg.obs[11].lock = 10; - test_msg.obs[11].sid.code = 3; - test_msg.obs[11].sid.sat = 3; - - test_msg.obs[12].D.f = 219; - test_msg.obs[12].D.i = -3836; - test_msg.obs[12].L.f = 80; - test_msg.obs[12].L.i = 114505343; - test_msg.obs[12].P = 1069903034; - test_msg.obs[12].cn0 = 200; - test_msg.obs[12].flags = 15; - test_msg.obs[12].lock = 10; - test_msg.obs[12].sid.code = 3; - test_msg.obs[12].sid.sat = 17; - - test_msg.obs[13].D.f = 182; - test_msg.obs[13].D.i = -461; - test_msg.obs[13].L.f = 105; - test_msg.obs[13].L.i = 102157331; - test_msg.obs[13].P = 956875687; - test_msg.obs[13].cn0 = 152; - test_msg.obs[13].flags = 15; - test_msg.obs[13].lock = 10; - test_msg.obs[13].sid.code = 3; - test_msg.obs[13].sid.sat = 18; - - EXPECT_EQ(send_message(61569, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61569); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.ns_residual, 0) - << "incorrect value for last_msg_.header.t.ns_residual, expected 0, is " - << last_msg_.header.t.ns_residual; - EXPECT_EQ(last_msg_.header.t.tow, 434293400) - << "incorrect value for last_msg_.header.t.tow, expected 434293400, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 2154) - << "incorrect value for last_msg_.header.t.wn, expected 2154, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 14) - << "incorrect value for last_msg_.n_obs, expected 14, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].D.f, 172) - << "incorrect value for last_msg_.obs[0].D.f, expected 172, is " - << last_msg_.obs[0].D.f; - EXPECT_EQ(last_msg_.obs[0].D.i, -1536) - << "incorrect value for last_msg_.obs[0].D.i, expected -1536, is " - << last_msg_.obs[0].D.i; - EXPECT_EQ(last_msg_.obs[0].L.f, 146) - << "incorrect value for last_msg_.obs[0].L.f, expected 146, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 111080057) - << "incorrect value for last_msg_.obs[0].L.i, expected 111080057, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1056891697) - << "incorrect value for last_msg_.obs[0].P, expected 1056891697, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 182) - << "incorrect value for last_msg_.obs[0].cn0, expected 182, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].flags, 15) - << "incorrect value for last_msg_.obs[0].flags, expected 15, is " - << last_msg_.obs[0].flags; - EXPECT_EQ(last_msg_.obs[0].lock, 10) - << "incorrect value for last_msg_.obs[0].lock, expected 10, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 10) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 10, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].D.f, 172) - << "incorrect value for last_msg_.obs[1].D.f, expected 172, is " - << last_msg_.obs[1].D.f; - EXPECT_EQ(last_msg_.obs[1].D.i, -1197) - << "incorrect value for last_msg_.obs[1].D.i, expected -1197, is " - << last_msg_.obs[1].D.i; - EXPECT_EQ(last_msg_.obs[1].L.f, 59) - << "incorrect value for last_msg_.obs[1].L.f, expected 59, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 86555916) - << "incorrect value for last_msg_.obs[1].L.i, expected 86555916, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1056891934) - << "incorrect value for last_msg_.obs[1].P, expected 1056891934, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 178) - << "incorrect value for last_msg_.obs[1].cn0, expected 178, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].flags, 15) - << "incorrect value for last_msg_.obs[1].flags, expected 15, is " - << last_msg_.obs[1].flags; - EXPECT_EQ(last_msg_.obs[1].lock, 10) - << "incorrect value for last_msg_.obs[1].lock, expected 10, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 1) - << "incorrect value for last_msg_.obs[1].sid.code, expected 1, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 10) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 10, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].D.f, 119) - << "incorrect value for last_msg_.obs[2].D.f, expected 119, is " - << last_msg_.obs[2].D.f; - EXPECT_EQ(last_msg_.obs[2].D.i, -3219) - << "incorrect value for last_msg_.obs[2].D.i, expected -3219, is " - << last_msg_.obs[2].D.i; - EXPECT_EQ(last_msg_.obs[2].L.f, 243) - << "incorrect value for last_msg_.obs[2].L.f, expected 243, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 127954794) - << "incorrect value for last_msg_.obs[2].L.i, expected 127954794, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1217449431) - << "incorrect value for last_msg_.obs[2].P, expected 1217449431, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 158) - << "incorrect value for last_msg_.obs[2].cn0, expected 158, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].flags, 15) - << "incorrect value for last_msg_.obs[2].flags, expected 15, is " - << last_msg_.obs[2].flags; - EXPECT_EQ(last_msg_.obs[2].lock, 10) - << "incorrect value for last_msg_.obs[2].lock, expected 10, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 18) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 18, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].D.f, 27) - << "incorrect value for last_msg_.obs[3].D.f, expected 27, is " - << last_msg_.obs[3].D.f; - EXPECT_EQ(last_msg_.obs[3].D.i, -2508) - << "incorrect value for last_msg_.obs[3].D.i, expected -2508, is " - << last_msg_.obs[3].D.i; - EXPECT_EQ(last_msg_.obs[3].L.f, 12) - << "incorrect value for last_msg_.obs[3].L.f, expected 12, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 99705055) - << "incorrect value for last_msg_.obs[3].L.i, expected 99705055, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 1217449753) - << "incorrect value for last_msg_.obs[3].P, expected 1217449753, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 125) - << "incorrect value for last_msg_.obs[3].cn0, expected 125, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].flags, 11) - << "incorrect value for last_msg_.obs[3].flags, expected 11, is " - << last_msg_.obs[3].flags; - EXPECT_EQ(last_msg_.obs[3].lock, 9) - << "incorrect value for last_msg_.obs[3].lock, expected 9, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 1) - << "incorrect value for last_msg_.obs[3].sid.code, expected 1, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 18) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 18, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].D.f, 245) - << "incorrect value for last_msg_.obs[4].D.f, expected 245, is " - << last_msg_.obs[4].D.f; - EXPECT_EQ(last_msg_.obs[4].D.i, 2829) - << "incorrect value for last_msg_.obs[4].D.i, expected 2829, is " - << last_msg_.obs[4].D.i; - EXPECT_EQ(last_msg_.obs[4].L.f, 53) - << "incorrect value for last_msg_.obs[4].L.f, expected 53, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 132024982) - << "incorrect value for last_msg_.obs[4].L.i, expected 132024982, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1256175650) - << "incorrect value for last_msg_.obs[4].P, expected 1256175650, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 114) - << "incorrect value for last_msg_.obs[4].cn0, expected 114, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].flags, 15) - << "incorrect value for last_msg_.obs[4].flags, expected 15, is " - << last_msg_.obs[4].flags; - EXPECT_EQ(last_msg_.obs[4].lock, 9) - << "incorrect value for last_msg_.obs[4].lock, expected 9, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 22) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 22, is " - << last_msg_.obs[4].sid.sat; - EXPECT_EQ(last_msg_.obs[5].D.f, 246) - << "incorrect value for last_msg_.obs[5].D.f, expected 246, is " - << last_msg_.obs[5].D.f; - EXPECT_EQ(last_msg_.obs[5].D.i, -2433) - << "incorrect value for last_msg_.obs[5].D.i, expected -2433, is " - << last_msg_.obs[5].D.i; - EXPECT_EQ(last_msg_.obs[5].L.f, 70) - << "incorrect value for last_msg_.obs[5].L.f, expected 70, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 121711010) - << "incorrect value for last_msg_.obs[5].L.i, expected 121711010, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 1158041713) - << "incorrect value for last_msg_.obs[5].P, expected 1158041713, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 189) - << "incorrect value for last_msg_.obs[5].cn0, expected 189, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].flags, 15) - << "incorrect value for last_msg_.obs[5].flags, expected 15, is " - << last_msg_.obs[5].flags; - EXPECT_EQ(last_msg_.obs[5].lock, 9) - << "incorrect value for last_msg_.obs[5].lock, expected 9, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].sid.code, 0) - << "incorrect value for last_msg_.obs[5].sid.code, expected 0, is " - << last_msg_.obs[5].sid.code; - EXPECT_EQ(last_msg_.obs[5].sid.sat, 23) - << "incorrect value for last_msg_.obs[5].sid.sat, expected 23, is " - << last_msg_.obs[5].sid.sat; - EXPECT_EQ(last_msg_.obs[6].D.f, 231) - << "incorrect value for last_msg_.obs[6].D.f, expected 231, is " - << last_msg_.obs[6].D.f; - EXPECT_EQ(last_msg_.obs[6].D.i, -1896) - << "incorrect value for last_msg_.obs[6].D.i, expected -1896, is " - << last_msg_.obs[6].D.i; - EXPECT_EQ(last_msg_.obs[6].L.f, 221) - << "incorrect value for last_msg_.obs[6].L.f, expected 221, is " - << last_msg_.obs[6].L.f; - EXPECT_EQ(last_msg_.obs[6].L.i, 94839765) - << "incorrect value for last_msg_.obs[6].L.i, expected 94839765, is " - << last_msg_.obs[6].L.i; - EXPECT_EQ(last_msg_.obs[6].P, 1158041847) - << "incorrect value for last_msg_.obs[6].P, expected 1158041847, is " - << last_msg_.obs[6].P; - EXPECT_EQ(last_msg_.obs[6].cn0, 158) - << "incorrect value for last_msg_.obs[6].cn0, expected 158, is " - << last_msg_.obs[6].cn0; - EXPECT_EQ(last_msg_.obs[6].flags, 11) - << "incorrect value for last_msg_.obs[6].flags, expected 11, is " - << last_msg_.obs[6].flags; - EXPECT_EQ(last_msg_.obs[6].lock, 9) - << "incorrect value for last_msg_.obs[6].lock, expected 9, is " - << last_msg_.obs[6].lock; - EXPECT_EQ(last_msg_.obs[6].sid.code, 1) - << "incorrect value for last_msg_.obs[6].sid.code, expected 1, is " - << last_msg_.obs[6].sid.code; - EXPECT_EQ(last_msg_.obs[6].sid.sat, 23) - << "incorrect value for last_msg_.obs[6].sid.sat, expected 23, is " - << last_msg_.obs[6].sid.sat; - EXPECT_EQ(last_msg_.obs[7].D.f, 67) - << "incorrect value for last_msg_.obs[7].D.f, expected 67, is " - << last_msg_.obs[7].D.f; - EXPECT_EQ(last_msg_.obs[7].D.i, -1997) - << "incorrect value for last_msg_.obs[7].D.i, expected -1997, is " - << last_msg_.obs[7].D.i; - EXPECT_EQ(last_msg_.obs[7].L.f, 114) - << "incorrect value for last_msg_.obs[7].L.f, expected 114, is " - << last_msg_.obs[7].L.f; - EXPECT_EQ(last_msg_.obs[7].L.i, 113998348) - << "incorrect value for last_msg_.obs[7].L.i, expected 113998348, is " - << last_msg_.obs[7].L.i; - EXPECT_EQ(last_msg_.obs[7].P, 1084658184) - << "incorrect value for last_msg_.obs[7].P, expected 1084658184, is " - << last_msg_.obs[7].P; - EXPECT_EQ(last_msg_.obs[7].cn0, 93) - << "incorrect value for last_msg_.obs[7].cn0, expected 93, is " - << last_msg_.obs[7].cn0; - EXPECT_EQ(last_msg_.obs[7].flags, 11) - << "incorrect value for last_msg_.obs[7].flags, expected 11, is " - << last_msg_.obs[7].flags; - EXPECT_EQ(last_msg_.obs[7].lock, 3) - << "incorrect value for last_msg_.obs[7].lock, expected 3, is " - << last_msg_.obs[7].lock; - EXPECT_EQ(last_msg_.obs[7].sid.code, 0) - << "incorrect value for last_msg_.obs[7].sid.code, expected 0, is " - << last_msg_.obs[7].sid.code; - EXPECT_EQ(last_msg_.obs[7].sid.sat, 27) - << "incorrect value for last_msg_.obs[7].sid.sat, expected 27, is " - << last_msg_.obs[7].sid.sat; - EXPECT_EQ(last_msg_.obs[8].D.f, 237) - << "incorrect value for last_msg_.obs[8].D.f, expected 237, is " - << last_msg_.obs[8].D.f; - EXPECT_EQ(last_msg_.obs[8].D.i, 3041) - << "incorrect value for last_msg_.obs[8].D.i, expected 3041, is " - << last_msg_.obs[8].D.i; - EXPECT_EQ(last_msg_.obs[8].L.f, 232) - << "incorrect value for last_msg_.obs[8].L.f, expected 232, is " - << last_msg_.obs[8].L.f; - EXPECT_EQ(last_msg_.obs[8].L.i, 133443545) - << "incorrect value for last_msg_.obs[8].L.i, expected 133443545, is " - << last_msg_.obs[8].L.i; - EXPECT_EQ(last_msg_.obs[8].P, 1269673181) - << "incorrect value for last_msg_.obs[8].P, expected 1269673181, is " - << last_msg_.obs[8].P; - EXPECT_EQ(last_msg_.obs[8].cn0, 123) - << "incorrect value for last_msg_.obs[8].cn0, expected 123, is " - << last_msg_.obs[8].cn0; - EXPECT_EQ(last_msg_.obs[8].flags, 15) - << "incorrect value for last_msg_.obs[8].flags, expected 15, is " - << last_msg_.obs[8].flags; - EXPECT_EQ(last_msg_.obs[8].lock, 5) - << "incorrect value for last_msg_.obs[8].lock, expected 5, is " - << last_msg_.obs[8].lock; - EXPECT_EQ(last_msg_.obs[8].sid.code, 0) - << "incorrect value for last_msg_.obs[8].sid.code, expected 0, is " - << last_msg_.obs[8].sid.code; - EXPECT_EQ(last_msg_.obs[8].sid.sat, 31) - << "incorrect value for last_msg_.obs[8].sid.sat, expected 31, is " - << last_msg_.obs[8].sid.sat; - EXPECT_EQ(last_msg_.obs[9].D.f, 62) - << "incorrect value for last_msg_.obs[9].D.f, expected 62, is " - << last_msg_.obs[9].D.f; - EXPECT_EQ(last_msg_.obs[9].D.i, 2374) - << "incorrect value for last_msg_.obs[9].D.i, expected 2374, is " - << last_msg_.obs[9].D.i; - EXPECT_EQ(last_msg_.obs[9].L.f, 40) - << "incorrect value for last_msg_.obs[9].L.f, expected 40, is " - << last_msg_.obs[9].L.f; - EXPECT_EQ(last_msg_.obs[9].L.i, 103982040) - << "incorrect value for last_msg_.obs[9].L.i, expected 103982040, is " - << last_msg_.obs[9].L.i; - EXPECT_EQ(last_msg_.obs[9].P, 1269673722) - << "incorrect value for last_msg_.obs[9].P, expected 1269673722, is " - << last_msg_.obs[9].P; - EXPECT_EQ(last_msg_.obs[9].cn0, 120) - << "incorrect value for last_msg_.obs[9].cn0, expected 120, is " - << last_msg_.obs[9].cn0; - EXPECT_EQ(last_msg_.obs[9].flags, 11) - << "incorrect value for last_msg_.obs[9].flags, expected 11, is " - << last_msg_.obs[9].flags; - EXPECT_EQ(last_msg_.obs[9].lock, 3) - << "incorrect value for last_msg_.obs[9].lock, expected 3, is " - << last_msg_.obs[9].lock; - EXPECT_EQ(last_msg_.obs[9].sid.code, 1) - << "incorrect value for last_msg_.obs[9].sid.code, expected 1, is " - << last_msg_.obs[9].sid.code; - EXPECT_EQ(last_msg_.obs[9].sid.sat, 31) - << "incorrect value for last_msg_.obs[9].sid.sat, expected 31, is " - << last_msg_.obs[9].sid.sat; - EXPECT_EQ(last_msg_.obs[10].D.f, 96) - << "incorrect value for last_msg_.obs[10].D.f, expected 96, is " - << last_msg_.obs[10].D.f; - EXPECT_EQ(last_msg_.obs[10].D.i, -3446) - << "incorrect value for last_msg_.obs[10].D.i, expected -3446, is " - << last_msg_.obs[10].D.i; - EXPECT_EQ(last_msg_.obs[10].L.f, 7) - << "incorrect value for last_msg_.obs[10].L.f, expected 7, is " - << last_msg_.obs[10].L.f; - EXPECT_EQ(last_msg_.obs[10].L.i, 118217315) - << "incorrect value for last_msg_.obs[10].L.i, expected 118217315, is " - << last_msg_.obs[10].L.i; - EXPECT_EQ(last_msg_.obs[10].P, 1107693703) - << "incorrect value for last_msg_.obs[10].P, expected 1107693703, is " - << last_msg_.obs[10].P; - EXPECT_EQ(last_msg_.obs[10].cn0, 176) - << "incorrect value for last_msg_.obs[10].cn0, expected 176, is " - << last_msg_.obs[10].cn0; - EXPECT_EQ(last_msg_.obs[10].flags, 15) - << "incorrect value for last_msg_.obs[10].flags, expected 15, is " - << last_msg_.obs[10].flags; - EXPECT_EQ(last_msg_.obs[10].lock, 10) - << "incorrect value for last_msg_.obs[10].lock, expected 10, is " - << last_msg_.obs[10].lock; - EXPECT_EQ(last_msg_.obs[10].sid.code, 3) - << "incorrect value for last_msg_.obs[10].sid.code, expected 3, is " - << last_msg_.obs[10].sid.code; - EXPECT_EQ(last_msg_.obs[10].sid.sat, 2) - << "incorrect value for last_msg_.obs[10].sid.sat, expected 2, is " - << last_msg_.obs[10].sid.sat; - EXPECT_EQ(last_msg_.obs[11].D.f, 96) - << "incorrect value for last_msg_.obs[11].D.f, expected 96, is " - << last_msg_.obs[11].D.f; - EXPECT_EQ(last_msg_.obs[11].D.i, -1003) - << "incorrect value for last_msg_.obs[11].D.i, expected -1003, is " - << last_msg_.obs[11].D.i; - EXPECT_EQ(last_msg_.obs[11].L.f, 203) - << "incorrect value for last_msg_.obs[11].L.f, expected 203, is " - << last_msg_.obs[11].L.f; - EXPECT_EQ(last_msg_.obs[11].L.i, 104224985) - << "incorrect value for last_msg_.obs[11].L.i, expected 104224985, is " - << last_msg_.obs[11].L.i; - EXPECT_EQ(last_msg_.obs[11].P, 973505172) - << "incorrect value for last_msg_.obs[11].P, expected 973505172, is " - << last_msg_.obs[11].P; - EXPECT_EQ(last_msg_.obs[11].cn0, 170) - << "incorrect value for last_msg_.obs[11].cn0, expected 170, is " - << last_msg_.obs[11].cn0; - EXPECT_EQ(last_msg_.obs[11].flags, 15) - << "incorrect value for last_msg_.obs[11].flags, expected 15, is " - << last_msg_.obs[11].flags; - EXPECT_EQ(last_msg_.obs[11].lock, 10) - << "incorrect value for last_msg_.obs[11].lock, expected 10, is " - << last_msg_.obs[11].lock; - EXPECT_EQ(last_msg_.obs[11].sid.code, 3) - << "incorrect value for last_msg_.obs[11].sid.code, expected 3, is " - << last_msg_.obs[11].sid.code; - EXPECT_EQ(last_msg_.obs[11].sid.sat, 3) - << "incorrect value for last_msg_.obs[11].sid.sat, expected 3, is " - << last_msg_.obs[11].sid.sat; - EXPECT_EQ(last_msg_.obs[12].D.f, 219) - << "incorrect value for last_msg_.obs[12].D.f, expected 219, is " - << last_msg_.obs[12].D.f; - EXPECT_EQ(last_msg_.obs[12].D.i, -3836) - << "incorrect value for last_msg_.obs[12].D.i, expected -3836, is " - << last_msg_.obs[12].D.i; - EXPECT_EQ(last_msg_.obs[12].L.f, 80) - << "incorrect value for last_msg_.obs[12].L.f, expected 80, is " - << last_msg_.obs[12].L.f; - EXPECT_EQ(last_msg_.obs[12].L.i, 114505343) - << "incorrect value for last_msg_.obs[12].L.i, expected 114505343, is " - << last_msg_.obs[12].L.i; - EXPECT_EQ(last_msg_.obs[12].P, 1069903034) - << "incorrect value for last_msg_.obs[12].P, expected 1069903034, is " - << last_msg_.obs[12].P; - EXPECT_EQ(last_msg_.obs[12].cn0, 200) - << "incorrect value for last_msg_.obs[12].cn0, expected 200, is " - << last_msg_.obs[12].cn0; - EXPECT_EQ(last_msg_.obs[12].flags, 15) - << "incorrect value for last_msg_.obs[12].flags, expected 15, is " - << last_msg_.obs[12].flags; - EXPECT_EQ(last_msg_.obs[12].lock, 10) - << "incorrect value for last_msg_.obs[12].lock, expected 10, is " - << last_msg_.obs[12].lock; - EXPECT_EQ(last_msg_.obs[12].sid.code, 3) - << "incorrect value for last_msg_.obs[12].sid.code, expected 3, is " - << last_msg_.obs[12].sid.code; - EXPECT_EQ(last_msg_.obs[12].sid.sat, 17) - << "incorrect value for last_msg_.obs[12].sid.sat, expected 17, is " - << last_msg_.obs[12].sid.sat; - EXPECT_EQ(last_msg_.obs[13].D.f, 182) - << "incorrect value for last_msg_.obs[13].D.f, expected 182, is " - << last_msg_.obs[13].D.f; - EXPECT_EQ(last_msg_.obs[13].D.i, -461) - << "incorrect value for last_msg_.obs[13].D.i, expected -461, is " - << last_msg_.obs[13].D.i; - EXPECT_EQ(last_msg_.obs[13].L.f, 105) - << "incorrect value for last_msg_.obs[13].L.f, expected 105, is " - << last_msg_.obs[13].L.f; - EXPECT_EQ(last_msg_.obs[13].L.i, 102157331) - << "incorrect value for last_msg_.obs[13].L.i, expected 102157331, is " - << last_msg_.obs[13].L.i; - EXPECT_EQ(last_msg_.obs[13].P, 956875687) - << "incorrect value for last_msg_.obs[13].P, expected 956875687, is " - << last_msg_.obs[13].P; - EXPECT_EQ(last_msg_.obs[13].cn0, 152) - << "incorrect value for last_msg_.obs[13].cn0, expected 152, is " - << last_msg_.obs[13].cn0; - EXPECT_EQ(last_msg_.obs[13].flags, 15) - << "incorrect value for last_msg_.obs[13].flags, expected 15, is " - << last_msg_.obs[13].flags; - EXPECT_EQ(last_msg_.obs[13].lock, 10) - << "incorrect value for last_msg_.obs[13].lock, expected 10, is " - << last_msg_.obs[13].lock; - EXPECT_EQ(last_msg_.obs[13].sid.code, 3) - << "incorrect value for last_msg_.obs[13].sid.code, expected 3, is " - << last_msg_.obs[13].sid.code; - EXPECT_EQ(last_msg_.obs[13].sid.sat, 18) - << "incorrect value for last_msg_.obs[13].sid.sat, expected 18, is " - << last_msg_.obs[13].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObs1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObs1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_observation_MsgObs0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObs, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[249]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_obs_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 249); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 249), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObs, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 249); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 249), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[249]; + + EXPECT_EQ(sbp_msg_obs_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 249), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObs0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[249]; + + for (uint8_t i = 0; i < 249; i++) { + EXPECT_EQ(sbp_msg_obs_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_obs_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObs0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_observation_MsgObs1, Test) { - uint8_t encoded_frame[] = { - 85, 74, 0, 129, 240, 11, 152, 202, 226, 25, - 0, 0, 0, 0, 106, 8, 16, 201, 101, - }; + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 249); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObs, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 249); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObs0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_t t{}; + return sbp_msg_obs_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_t t{}; + t.n_obs = 1; + return sbp_msg_obs_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - sbp_msg_obs_t test_msg{}; - test_msg.header.n_obs = 16; - test_msg.header.t.ns_residual = 0; - test_msg.header.t.tow = 434293400; - test_msg.header.t.wn = 2154; - - EXPECT_EQ(send_message(61569, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61569); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 16) - << "incorrect value for last_msg_.header.n_obs, expected 16, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.ns_residual, 0) - << "incorrect value for last_msg_.header.t.ns_residual, expected 0, is " - << last_msg_.header.t.ns_residual; - EXPECT_EQ(last_msg_.header.t.tow, 434293400) - << "incorrect value for last_msg_.header.t.tow, expected 434293400, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 2154) - << "incorrect value for last_msg_.header.t.wn, expected 2154, is " - << last_msg_.header.t.wn; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } } + +TEST_F(Testauto_check_sbp_observation_MsgObs0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.ns_residual, + greater.header.t.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].D.f, greater.obs[0].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].D.i, greater.obs[0].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].flags, greater.obs[0].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].D.f, greater.obs[1].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].D.i, greater.obs[1].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].flags, greater.obs[1].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].D.f, greater.obs[2].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].D.i, greater.obs[2].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].flags, greater.obs[2].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].D.f, greater.obs[3].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].D.i, greater.obs[3].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].flags, greater.obs[3].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].D.f, greater.obs[4].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].D.i, greater.obs[4].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].flags, greater.obs[4].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].D.f, greater.obs[5].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].D.i, greater.obs[5].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].flags, greater.obs[5].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.code, greater.obs[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.sat, greater.obs[5].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].D.f, greater.obs[6].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].D.i, greater.obs[6].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.f, greater.obs[6].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.i, greater.obs[6].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].P, greater.obs[6].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].cn0, greater.obs[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].flags, greater.obs[6].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].lock, greater.obs[6].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].sid.code, greater.obs[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].sid.sat, greater.obs[6].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].D.f, greater.obs[7].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].D.i, greater.obs[7].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].L.f, greater.obs[7].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].L.i, greater.obs[7].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].P, greater.obs[7].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].cn0, greater.obs[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].flags, greater.obs[7].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].lock, greater.obs[7].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].sid.code, greater.obs[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].sid.sat, greater.obs[7].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].D.f, greater.obs[8].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].D.i, greater.obs[8].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].L.f, greater.obs[8].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].L.i, greater.obs[8].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].P, greater.obs[8].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].cn0, greater.obs[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].flags, greater.obs[8].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].lock, greater.obs[8].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].sid.code, greater.obs[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].sid.sat, greater.obs[8].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].D.f, greater.obs[9].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].D.i, greater.obs[9].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].L.f, greater.obs[9].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].L.i, greater.obs[9].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].P, greater.obs[9].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].cn0, greater.obs[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].flags, greater.obs[9].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].lock, greater.obs[9].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].sid.code, greater.obs[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].sid.sat, greater.obs[9].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].D.f, greater.obs[10].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].D.i, greater.obs[10].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].L.f, greater.obs[10].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].L.i, greater.obs[10].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].P, greater.obs[10].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].cn0, greater.obs[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].flags, greater.obs[10].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].lock, greater.obs[10].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].sid.code, greater.obs[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].sid.sat, greater.obs[10].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].D.f, greater.obs[11].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].D.i, greater.obs[11].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].L.f, greater.obs[11].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].L.i, greater.obs[11].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].P, greater.obs[11].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].cn0, greater.obs[11].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].flags, greater.obs[11].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].lock, greater.obs[11].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].sid.code, greater.obs[11].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].sid.sat, greater.obs[11].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].D.f, greater.obs[12].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].D.i, greater.obs[12].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].L.f, greater.obs[12].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].L.i, greater.obs[12].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].P, greater.obs[12].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].cn0, greater.obs[12].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].flags, greater.obs[12].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].lock, greater.obs[12].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].sid.code, greater.obs[12].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[12].sid.sat, greater.obs[12].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].D.f, greater.obs[13].D.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].D.i, greater.obs[13].D.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].L.f, greater.obs[13].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].L.i, greater.obs[13].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].P, greater.obs[13].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].cn0, greater.obs[13].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].flags, greater.obs[13].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].lock, greater.obs[13].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].sid.code, greater.obs[13].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.obs[13].sid.sat, greater.obs[13].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObs); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[249]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 249); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 249), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 249); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObs, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObs, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObs1 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObs1() { + assign(test_msg_.header.n_obs, 16); + assign(test_msg_.header.t.ns_residual, 0); + assign(test_msg_.header.t.tow, 434293400); + assign(test_msg_.header.t.wn, 2154); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, const sbp_msg_obs_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObs, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObs); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs, sizeof(msg->obs)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObs); + info.sender_id = 61569; + info.preamble = 0x55; + info.crc = 0x65c9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_t &lesser, + const sbp_msg_obs_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObs, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgObs, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObs, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObs, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { + 85, 74, 0, 129, 240, 11, 152, 202, 226, 25, + 0, 0, 0, 0, 106, 8, 16, 201, 101, + }; + uint8_t encoded_payload_[11] = { + 152, 202, 226, 25, 0, 0, 0, 0, 106, 8, 16, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObs1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObs, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_obs_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObs, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_obs_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObs1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_obs_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObs, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObs1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_obs_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObs, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.ns_residual, + greater.header.t.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_t lesser = info.test_msg; + sbp_msg_obs_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObs); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObs, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObs1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObs, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgObsDepB.cc b/c/test/cpp/auto_check_sbp_observation_MsgObsDepB.cc index 735a47afa6..cb55ba6783 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgObsDepB.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgObsDepB.cc @@ -16,66 +16,416 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgObsDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgObsDepB0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgObsDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgObsDepB0() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 2567800); + assign(test_msg_.header.t.wn, 1787); + assign(test_msg_.n_obs, 6); + + assign(test_msg_.obs[0].L.f, 27); + assign(test_msg_.obs[0].L.i, 117913055); + assign(test_msg_.obs[0].P, 2243669940); + assign(test_msg_.obs[0].cn0, 157); + assign(test_msg_.obs[0].lock, 0); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 202); + + assign(test_msg_.obs[1].L.f, 175); + assign(test_msg_.obs[1].L.i, 129899608); + assign(test_msg_.obs[1].P, 2471857210); + assign(test_msg_.obs[1].cn0, 144); + assign(test_msg_.obs[1].lock, 0); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 203); + + assign(test_msg_.obs[2].L.f, 135); + assign(test_msg_.obs[2].L.i, 122531024); + assign(test_msg_.obs[2].P, 2331544796); + assign(test_msg_.obs[2].cn0, 151); + assign(test_msg_.obs[2].lock, 0); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 208); + + assign(test_msg_.obs[3].L.f, 242); + assign(test_msg_.obs[3].L.i, 119280243); + assign(test_msg_.obs[3].P, 2269692589); + assign(test_msg_.obs[3].cn0, 156); + assign(test_msg_.obs[3].lock, 0); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 212); + + assign(test_msg_.obs[4].L.f, 120); + assign(test_msg_.obs[4].L.i, 109691922); + assign(test_msg_.obs[4].P, 2087293092); + assign(test_msg_.obs[4].cn0, 168); + assign(test_msg_.obs[4].lock, 0); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 217); + + assign(test_msg_.obs[5].L.f, 87); + assign(test_msg_.obs[5].L.i, 123340754); + assign(test_msg_.obs[5].P, 2347034654); + assign(test_msg_.obs[5].cn0, 150); + assign(test_msg_.obs[5].lock, 0); + assign(test_msg_.obs[5].sid.code, 0); + assign(test_msg_.obs[5].sid.reserved, 0); + assign(test_msg_.obs[5].sid.sat, 218); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepB, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_b, sizeof(msg->obs_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_b, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x55a9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 103; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_obs_dep_b_t &lesser, + const sbp_msg_obs_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepB0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_b_t test_msg_{}; + uint8_t encoded_frame_[103 + 8] = { 85, 67, 0, 246, 215, 103, 120, 46, 39, 0, 251, 6, 32, 180, 175, 187, 133, 223, 53, 7, 7, 27, 157, 0, 0, 202, 0, 0, 0, 58, 140, 85, 147, 88, 28, 190, 7, 175, 144, 0, 0, 203, 0, 0, 0, 220, 140, 248, @@ -84,1209 +434,4915 @@ TEST_F(Test_auto_check_sbp_observation_MsgObsDepB0, Test) { 124, 18, 196, 137, 6, 120, 168, 0, 0, 217, 0, 0, 0, 30, 232, 228, 139, 210, 7, 90, 7, 87, 150, 0, 0, 218, 0, 0, 0, 169, 85, }; + uint8_t encoded_payload_[103] = { + 120, 46, 39, 0, 251, 6, 32, 180, 175, 187, 133, 223, 53, 7, 7, + 27, 157, 0, 0, 202, 0, 0, 0, 58, 140, 85, 147, 88, 28, 190, + 7, 175, 144, 0, 0, 203, 0, 0, 0, 220, 140, 248, 138, 208, 172, + 77, 7, 135, 151, 0, 0, 208, 0, 0, 0, 173, 194, 72, 135, 115, + 18, 28, 7, 242, 156, 0, 0, 212, 0, 0, 0, 164, 144, 105, 124, + 18, 196, 137, 6, 120, 168, 0, 0, 217, 0, 0, 0, 30, 232, 228, + 139, 210, 7, 90, 7, 87, 150, 0, 0, 218, 0, 0, 0, + }; +}; - sbp_msg_obs_dep_b_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 2567800; - test_msg.header.t.wn = 1787; - test_msg.n_obs = 6; - - test_msg.obs[0].L.f = 27; - test_msg.obs[0].L.i = 117913055; - test_msg.obs[0].P = 2243669940; - test_msg.obs[0].cn0 = 157; - test_msg.obs[0].lock = 0; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 202; - - test_msg.obs[1].L.f = 175; - test_msg.obs[1].L.i = 129899608; - test_msg.obs[1].P = 2471857210; - test_msg.obs[1].cn0 = 144; - test_msg.obs[1].lock = 0; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 203; - - test_msg.obs[2].L.f = 135; - test_msg.obs[2].L.i = 122531024; - test_msg.obs[2].P = 2331544796; - test_msg.obs[2].cn0 = 151; - test_msg.obs[2].lock = 0; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 208; - - test_msg.obs[3].L.f = 242; - test_msg.obs[3].L.i = 119280243; - test_msg.obs[3].P = 2269692589; - test_msg.obs[3].cn0 = 156; - test_msg.obs[3].lock = 0; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 212; - - test_msg.obs[4].L.f = 120; - test_msg.obs[4].L.i = 109691922; - test_msg.obs[4].P = 2087293092; - test_msg.obs[4].cn0 = 168; - test_msg.obs[4].lock = 0; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 217; - - test_msg.obs[5].L.f = 87; - test_msg.obs[5].L.i = 123340754; - test_msg.obs[5].P = 2347034654; - test_msg.obs[5].cn0 = 150; - test_msg.obs[5].lock = 0; - test_msg.obs[5].sid.code = 0; - test_msg.obs[5].sid.reserved = 0; - test_msg.obs[5].sid.sat = 218; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 2567800) - << "incorrect value for last_msg_.header.t.tow, expected 2567800, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1787) - << "incorrect value for last_msg_.header.t.wn, expected 1787, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 6) - << "incorrect value for last_msg_.n_obs, expected 6, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 27) - << "incorrect value for last_msg_.obs[0].L.f, expected 27, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 117913055) - << "incorrect value for last_msg_.obs[0].L.i, expected 117913055, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2243669940) - << "incorrect value for last_msg_.obs[0].P, expected 2243669940, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 157) - << "incorrect value for last_msg_.obs[0].cn0, expected 157, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 0) - << "incorrect value for last_msg_.obs[0].lock, expected 0, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 202) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 202, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 175) - << "incorrect value for last_msg_.obs[1].L.f, expected 175, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 129899608) - << "incorrect value for last_msg_.obs[1].L.i, expected 129899608, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2471857210) - << "incorrect value for last_msg_.obs[1].P, expected 2471857210, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 144) - << "incorrect value for last_msg_.obs[1].cn0, expected 144, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 0) - << "incorrect value for last_msg_.obs[1].lock, expected 0, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 203) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 203, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 135) - << "incorrect value for last_msg_.obs[2].L.f, expected 135, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 122531024) - << "incorrect value for last_msg_.obs[2].L.i, expected 122531024, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2331544796) - << "incorrect value for last_msg_.obs[2].P, expected 2331544796, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 151) - << "incorrect value for last_msg_.obs[2].cn0, expected 151, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 0) - << "incorrect value for last_msg_.obs[2].lock, expected 0, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 208) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 208, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 242) - << "incorrect value for last_msg_.obs[3].L.f, expected 242, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 119280243) - << "incorrect value for last_msg_.obs[3].L.i, expected 119280243, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2269692589) - << "incorrect value for last_msg_.obs[3].P, expected 2269692589, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 156) - << "incorrect value for last_msg_.obs[3].cn0, expected 156, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 0) - << "incorrect value for last_msg_.obs[3].lock, expected 0, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 212) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 212, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 120) - << "incorrect value for last_msg_.obs[4].L.f, expected 120, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 109691922) - << "incorrect value for last_msg_.obs[4].L.i, expected 109691922, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 2087293092) - << "incorrect value for last_msg_.obs[4].P, expected 2087293092, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 168) - << "incorrect value for last_msg_.obs[4].cn0, expected 168, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 0) - << "incorrect value for last_msg_.obs[4].lock, expected 0, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 217) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 217, is " - << last_msg_.obs[4].sid.sat; - EXPECT_EQ(last_msg_.obs[5].L.f, 87) - << "incorrect value for last_msg_.obs[5].L.f, expected 87, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 123340754) - << "incorrect value for last_msg_.obs[5].L.i, expected 123340754, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 2347034654) - << "incorrect value for last_msg_.obs[5].P, expected 2347034654, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 150) - << "incorrect value for last_msg_.obs[5].cn0, expected 150, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].lock, 0) - << "incorrect value for last_msg_.obs[5].lock, expected 0, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].sid.code, 0) - << "incorrect value for last_msg_.obs[5].sid.code, expected 0, is " - << last_msg_.obs[5].sid.code; - EXPECT_EQ(last_msg_.obs[5].sid.reserved, 0) - << "incorrect value for last_msg_.obs[5].sid.reserved, expected 0, is " - << last_msg_.obs[5].sid.reserved; - EXPECT_EQ(last_msg_.obs[5].sid.sat, 218) - << "incorrect value for last_msg_.obs[5].sid.sat, expected 218, is " - << last_msg_.obs[5].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepB1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepB1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_b_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepB, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + EXPECT_EQ( + sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + for (uint8_t i = 0; i < 103; i++) { + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_observation_MsgObsDepB1, Test) { - uint8_t encoded_frame[] = { - 85, 67, 0, 246, 215, 55, 120, 46, 39, 0, 251, 6, 33, 68, 199, 101, - 136, 133, 247, 42, 7, 219, 154, 0, 0, 220, 0, 0, 0, 219, 14, 123, - 133, 96, 215, 3, 7, 235, 156, 0, 0, 222, 0, 0, 0, 87, 166, 81, - 122, 5, 173, 109, 6, 174, 170, 0, 0, 225, 0, 0, 0, 11, 233, - }; + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_obs_dep_b_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 2567800; - test_msg.header.t.wn = 1787; - test_msg.n_obs = 3; - - test_msg.obs[0].L.f = 219; - test_msg.obs[0].L.i = 120256389; - test_msg.obs[0].P = 2288371524; - test_msg.obs[0].cn0 = 154; - test_msg.obs[0].lock = 0; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 220; - - test_msg.obs[1].L.f = 235; - test_msg.obs[1].L.i = 117692256; - test_msg.obs[1].P = 2239434459; - test_msg.obs[1].cn0 = 156; - test_msg.obs[1].lock = 0; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 222; - - test_msg.obs[2].L.f = 174; - test_msg.obs[2].L.i = 107851013; - test_msg.obs[2].P = 2052171351; - test_msg.obs[2].cn0 = 170; - test_msg.obs[2].lock = 0; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 225; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 2567800) - << "incorrect value for last_msg_.header.t.tow, expected 2567800, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1787) - << "incorrect value for last_msg_.header.t.wn, expected 1787, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 3) - << "incorrect value for last_msg_.n_obs, expected 3, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 219) - << "incorrect value for last_msg_.obs[0].L.f, expected 219, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 120256389) - << "incorrect value for last_msg_.obs[0].L.i, expected 120256389, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2288371524) - << "incorrect value for last_msg_.obs[0].P, expected 2288371524, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 154) - << "incorrect value for last_msg_.obs[0].cn0, expected 154, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 0) - << "incorrect value for last_msg_.obs[0].lock, expected 0, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 220) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 220, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 235) - << "incorrect value for last_msg_.obs[1].L.f, expected 235, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 117692256) - << "incorrect value for last_msg_.obs[1].L.i, expected 117692256, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2239434459) - << "incorrect value for last_msg_.obs[1].P, expected 2239434459, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 156) - << "incorrect value for last_msg_.obs[1].cn0, expected 156, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 0) - << "incorrect value for last_msg_.obs[1].lock, expected 0, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 222) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 222, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 174) - << "incorrect value for last_msg_.obs[2].L.f, expected 174, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 107851013) - << "incorrect value for last_msg_.obs[2].L.i, expected 107851013, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2052171351) - << "incorrect value for last_msg_.obs[2].P, expected 2052171351, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 170) - << "incorrect value for last_msg_.obs[2].cn0, expected 170, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 0) - << "incorrect value for last_msg_.obs[2].lock, expected 0, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 225) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 225, is " - << last_msg_.obs[2].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepB2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepB2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + return sbp_msg_obs_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepB2, Test) { - uint8_t encoded_frame[] = { - 85, 67, 0, 246, 215, 103, 64, 47, 39, 0, 251, 6, 32, 100, 132, 187, - 133, 236, 51, 7, 7, 94, 156, 0, 0, 202, 0, 0, 0, 97, 184, 85, - 147, 178, 30, 190, 7, 40, 140, 0, 0, 203, 0, 0, 0, 135, 111, 248, - 138, 90, 171, 77, 7, 2, 150, 0, 0, 208, 0, 0, 0, 180, 238, 72, - 135, 190, 20, 28, 7, 241, 155, 0, 0, 212, 0, 0, 0, 15, 153, 105, - 124, 92, 196, 137, 6, 153, 168, 0, 0, 217, 0, 0, 0, 49, 185, 228, - 139, 144, 5, 90, 7, 41, 150, 0, 0, 218, 0, 0, 0, 241, 98, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_obs_dep_b_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 2568000; - test_msg.header.t.wn = 1787; - test_msg.n_obs = 6; - - test_msg.obs[0].L.f = 94; - test_msg.obs[0].L.i = 117912556; - test_msg.obs[0].P = 2243658852; - test_msg.obs[0].cn0 = 156; - test_msg.obs[0].lock = 0; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 202; - - test_msg.obs[1].L.f = 40; - test_msg.obs[1].L.i = 129900210; - test_msg.obs[1].P = 2471868513; - test_msg.obs[1].cn0 = 140; - test_msg.obs[1].lock = 0; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 203; - - test_msg.obs[2].L.f = 2; - test_msg.obs[2].L.i = 122530650; - test_msg.obs[2].P = 2331537287; - test_msg.obs[2].cn0 = 150; - test_msg.obs[2].lock = 0; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 208; - - test_msg.obs[3].L.f = 241; - test_msg.obs[3].L.i = 119280830; - test_msg.obs[3].P = 2269703860; - test_msg.obs[3].cn0 = 155; - test_msg.obs[3].lock = 0; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 212; - - test_msg.obs[4].L.f = 153; - test_msg.obs[4].L.i = 109691996; - test_msg.obs[4].P = 2087295247; - test_msg.obs[4].cn0 = 168; - test_msg.obs[4].lock = 0; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 217; - - test_msg.obs[5].L.f = 41; - test_msg.obs[5].L.i = 123340176; - test_msg.obs[5].P = 2347022641; - test_msg.obs[5].cn0 = 150; - test_msg.obs[5].lock = 0; - test_msg.obs[5].sid.code = 0; - test_msg.obs[5].sid.reserved = 0; - test_msg.obs[5].sid.sat = 218; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 2568000) - << "incorrect value for last_msg_.header.t.tow, expected 2568000, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1787) - << "incorrect value for last_msg_.header.t.wn, expected 1787, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 6) - << "incorrect value for last_msg_.n_obs, expected 6, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 94) - << "incorrect value for last_msg_.obs[0].L.f, expected 94, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 117912556) - << "incorrect value for last_msg_.obs[0].L.i, expected 117912556, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2243658852) - << "incorrect value for last_msg_.obs[0].P, expected 2243658852, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 156) - << "incorrect value for last_msg_.obs[0].cn0, expected 156, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 0) - << "incorrect value for last_msg_.obs[0].lock, expected 0, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 202) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 202, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 40) - << "incorrect value for last_msg_.obs[1].L.f, expected 40, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 129900210) - << "incorrect value for last_msg_.obs[1].L.i, expected 129900210, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2471868513) - << "incorrect value for last_msg_.obs[1].P, expected 2471868513, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 140) - << "incorrect value for last_msg_.obs[1].cn0, expected 140, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 0) - << "incorrect value for last_msg_.obs[1].lock, expected 0, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 203) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 203, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 2) - << "incorrect value for last_msg_.obs[2].L.f, expected 2, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 122530650) - << "incorrect value for last_msg_.obs[2].L.i, expected 122530650, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2331537287) - << "incorrect value for last_msg_.obs[2].P, expected 2331537287, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 150) - << "incorrect value for last_msg_.obs[2].cn0, expected 150, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 0) - << "incorrect value for last_msg_.obs[2].lock, expected 0, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 208) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 208, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 241) - << "incorrect value for last_msg_.obs[3].L.f, expected 241, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 119280830) - << "incorrect value for last_msg_.obs[3].L.i, expected 119280830, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2269703860) - << "incorrect value for last_msg_.obs[3].P, expected 2269703860, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 155) - << "incorrect value for last_msg_.obs[3].cn0, expected 155, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 0) - << "incorrect value for last_msg_.obs[3].lock, expected 0, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 212) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 212, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 153) - << "incorrect value for last_msg_.obs[4].L.f, expected 153, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 109691996) - << "incorrect value for last_msg_.obs[4].L.i, expected 109691996, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 2087295247) - << "incorrect value for last_msg_.obs[4].P, expected 2087295247, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 168) - << "incorrect value for last_msg_.obs[4].cn0, expected 168, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 0) - << "incorrect value for last_msg_.obs[4].lock, expected 0, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 217) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 217, is " - << last_msg_.obs[4].sid.sat; - EXPECT_EQ(last_msg_.obs[5].L.f, 41) - << "incorrect value for last_msg_.obs[5].L.f, expected 41, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 123340176) - << "incorrect value for last_msg_.obs[5].L.i, expected 123340176, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 2347022641) - << "incorrect value for last_msg_.obs[5].P, expected 2347022641, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 150) - << "incorrect value for last_msg_.obs[5].cn0, expected 150, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].lock, 0) - << "incorrect value for last_msg_.obs[5].lock, expected 0, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].sid.code, 0) - << "incorrect value for last_msg_.obs[5].sid.code, expected 0, is " - << last_msg_.obs[5].sid.code; - EXPECT_EQ(last_msg_.obs[5].sid.reserved, 0) - << "incorrect value for last_msg_.obs[5].sid.reserved, expected 0, is " - << last_msg_.obs[5].sid.reserved; - EXPECT_EQ(last_msg_.obs[5].sid.sat, 218) - << "incorrect value for last_msg_.obs[5].sid.sat, expected 218, is " - << last_msg_.obs[5].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepB3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepB3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_MsgObsDepB3, Test) { - uint8_t encoded_frame[] = { - 85, 67, 0, 246, 215, 55, 64, 47, 39, 0, 251, 6, 33, 234, 148, 101, - 136, 15, 245, 42, 7, 20, 154, 0, 0, 220, 0, 0, 0, 208, 247, 122, - 133, 16, 214, 3, 7, 38, 156, 0, 0, 222, 0, 0, 0, 15, 150, 81, - 122, 22, 172, 109, 6, 7, 172, 0, 0, 225, 0, 0, 0, 201, 13, - }; +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_obs_dep_b_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 2568000; - test_msg.header.t.wn = 1787; - test_msg.n_obs = 3; - - test_msg.obs[0].L.f = 20; - test_msg.obs[0].L.i = 120255759; - test_msg.obs[0].P = 2288358634; - test_msg.obs[0].cn0 = 154; - test_msg.obs[0].lock = 0; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 220; - - test_msg.obs[1].L.f = 38; - test_msg.obs[1].L.i = 117691920; - test_msg.obs[1].P = 2239428560; - test_msg.obs[1].cn0 = 156; - test_msg.obs[1].lock = 0; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 222; - - test_msg.obs[2].L.f = 7; - test_msg.obs[2].L.i = 107850774; - test_msg.obs[2].P = 2052167183; - test_msg.obs[2].cn0 = 172; - test_msg.obs[2].lock = 0; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 225; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 2568000) - << "incorrect value for last_msg_.header.t.tow, expected 2568000, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1787) - << "incorrect value for last_msg_.header.t.wn, expected 1787, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 3) - << "incorrect value for last_msg_.n_obs, expected 3, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 20) - << "incorrect value for last_msg_.obs[0].L.f, expected 20, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 120255759) - << "incorrect value for last_msg_.obs[0].L.i, expected 120255759, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2288358634) - << "incorrect value for last_msg_.obs[0].P, expected 2288358634, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 154) - << "incorrect value for last_msg_.obs[0].cn0, expected 154, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 0) - << "incorrect value for last_msg_.obs[0].lock, expected 0, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 220) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 220, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 38) - << "incorrect value for last_msg_.obs[1].L.f, expected 38, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 117691920) - << "incorrect value for last_msg_.obs[1].L.i, expected 117691920, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2239428560) - << "incorrect value for last_msg_.obs[1].P, expected 2239428560, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 156) - << "incorrect value for last_msg_.obs[1].cn0, expected 156, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 0) - << "incorrect value for last_msg_.obs[1].lock, expected 0, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 222) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 222, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 7) - << "incorrect value for last_msg_.obs[2].L.f, expected 7, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 107850774) - << "incorrect value for last_msg_.obs[2].L.i, expected 107850774, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2052167183) - << "incorrect value for last_msg_.obs[2].P, expected 2052167183, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 172) - << "incorrect value for last_msg_.obs[2].cn0, expected 172, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 0) - << "incorrect value for last_msg_.obs[2].lock, expected 0, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 225) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 225, is " - << last_msg_.obs[2].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepB4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepB4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepB4, Test) { - uint8_t encoded_frame[] = { - 85, 67, 0, 246, 215, 103, 8, 48, 39, 0, 251, 6, 32, 254, 96, 187, - 133, 249, 49, 7, 7, 165, 156, 0, 0, 202, 0, 0, 0, 113, 229, 85, - 147, 11, 33, 190, 7, 106, 143, 0, 0, 203, 0, 0, 0, 182, 85, 248, - 138, 227, 169, 77, 7, 159, 150, 0, 0, 208, 0, 0, 0, 17, 24, 73, - 135, 10, 23, 28, 7, 7, 156, 0, 0, 212, 0, 0, 0, 108, 155, 105, - 124, 166, 196, 137, 6, 186, 170, 0, 0, 217, 0, 0, 0, 214, 142, 228, - 139, 77, 3, 90, 7, 236, 151, 0, 0, 218, 0, 0, 0, 59, 118, - }; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.code, greater.obs[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.reserved, + greater.obs[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.sat, greater.obs[5].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepB); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; - sbp_msg_obs_dep_b_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 2568200; - test_msg.header.t.wn = 1787; - test_msg.n_obs = 6; - - test_msg.obs[0].L.f = 165; - test_msg.obs[0].L.i = 117912057; - test_msg.obs[0].P = 2243649790; - test_msg.obs[0].cn0 = 156; - test_msg.obs[0].lock = 0; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 202; - - test_msg.obs[1].L.f = 106; - test_msg.obs[1].L.i = 129900811; - test_msg.obs[1].P = 2471880049; - test_msg.obs[1].cn0 = 143; - test_msg.obs[1].lock = 0; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 203; - - test_msg.obs[2].L.f = 159; - test_msg.obs[2].L.i = 122530275; - test_msg.obs[2].P = 2331530678; - test_msg.obs[2].cn0 = 150; - test_msg.obs[2].lock = 0; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 208; - - test_msg.obs[3].L.f = 7; - test_msg.obs[3].L.i = 119281418; - test_msg.obs[3].P = 2269714449; - test_msg.obs[3].cn0 = 156; - test_msg.obs[3].lock = 0; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 212; - - test_msg.obs[4].L.f = 186; - test_msg.obs[4].L.i = 109692070; - test_msg.obs[4].P = 2087295852; - test_msg.obs[4].cn0 = 170; - test_msg.obs[4].lock = 0; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 217; - - test_msg.obs[5].L.f = 236; - test_msg.obs[5].L.i = 123339597; - test_msg.obs[5].P = 2347011798; - test_msg.obs[5].cn0 = 151; - test_msg.obs[5].lock = 0; - test_msg.obs[5].sid.code = 0; - test_msg.obs[5].sid.reserved = 0; - test_msg.obs[5].sid.sat = 218; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 2568200) - << "incorrect value for last_msg_.header.t.tow, expected 2568200, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1787) - << "incorrect value for last_msg_.header.t.wn, expected 1787, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 6) - << "incorrect value for last_msg_.n_obs, expected 6, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 165) - << "incorrect value for last_msg_.obs[0].L.f, expected 165, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 117912057) - << "incorrect value for last_msg_.obs[0].L.i, expected 117912057, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2243649790) - << "incorrect value for last_msg_.obs[0].P, expected 2243649790, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 156) - << "incorrect value for last_msg_.obs[0].cn0, expected 156, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 0) - << "incorrect value for last_msg_.obs[0].lock, expected 0, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 202) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 202, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 106) - << "incorrect value for last_msg_.obs[1].L.f, expected 106, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 129900811) - << "incorrect value for last_msg_.obs[1].L.i, expected 129900811, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2471880049) - << "incorrect value for last_msg_.obs[1].P, expected 2471880049, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 143) - << "incorrect value for last_msg_.obs[1].cn0, expected 143, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 0) - << "incorrect value for last_msg_.obs[1].lock, expected 0, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 203) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 203, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 159) - << "incorrect value for last_msg_.obs[2].L.f, expected 159, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 122530275) - << "incorrect value for last_msg_.obs[2].L.i, expected 122530275, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2331530678) - << "incorrect value for last_msg_.obs[2].P, expected 2331530678, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 150) - << "incorrect value for last_msg_.obs[2].cn0, expected 150, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 0) - << "incorrect value for last_msg_.obs[2].lock, expected 0, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 208) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 208, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 7) - << "incorrect value for last_msg_.obs[3].L.f, expected 7, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 119281418) - << "incorrect value for last_msg_.obs[3].L.i, expected 119281418, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2269714449) - << "incorrect value for last_msg_.obs[3].P, expected 2269714449, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 156) - << "incorrect value for last_msg_.obs[3].cn0, expected 156, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 0) - << "incorrect value for last_msg_.obs[3].lock, expected 0, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 212) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 212, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 186) - << "incorrect value for last_msg_.obs[4].L.f, expected 186, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 109692070) - << "incorrect value for last_msg_.obs[4].L.i, expected 109692070, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 2087295852) - << "incorrect value for last_msg_.obs[4].P, expected 2087295852, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 170) - << "incorrect value for last_msg_.obs[4].cn0, expected 170, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 0) - << "incorrect value for last_msg_.obs[4].lock, expected 0, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 217) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 217, is " - << last_msg_.obs[4].sid.sat; - EXPECT_EQ(last_msg_.obs[5].L.f, 236) - << "incorrect value for last_msg_.obs[5].L.f, expected 236, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 123339597) - << "incorrect value for last_msg_.obs[5].L.i, expected 123339597, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 2347011798) - << "incorrect value for last_msg_.obs[5].P, expected 2347011798, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 151) - << "incorrect value for last_msg_.obs[5].cn0, expected 151, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].lock, 0) - << "incorrect value for last_msg_.obs[5].lock, expected 0, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].sid.code, 0) - << "incorrect value for last_msg_.obs[5].sid.code, expected 0, is " - << last_msg_.obs[5].sid.code; - EXPECT_EQ(last_msg_.obs[5].sid.reserved, 0) - << "incorrect value for last_msg_.obs[5].sid.reserved, expected 0, is " - << last_msg_.obs[5].sid.reserved; - EXPECT_EQ(last_msg_.obs[5].sid.sat, 218) - << "incorrect value for last_msg_.obs[5].sid.sat, expected 218, is " - << last_msg_.obs[5].sid.sat; + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); } + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepB, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepB, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepB1 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepB1() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 2567800); + assign(test_msg_.header.t.wn, 1787); + assign(test_msg_.n_obs, 3); + + assign(test_msg_.obs[0].L.f, 219); + assign(test_msg_.obs[0].L.i, 120256389); + assign(test_msg_.obs[0].P, 2288371524); + assign(test_msg_.obs[0].cn0, 154); + assign(test_msg_.obs[0].lock, 0); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 220); + + assign(test_msg_.obs[1].L.f, 235); + assign(test_msg_.obs[1].L.i, 117692256); + assign(test_msg_.obs[1].P, 2239434459); + assign(test_msg_.obs[1].cn0, 156); + assign(test_msg_.obs[1].lock, 0); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 222); + + assign(test_msg_.obs[2].L.f, 174); + assign(test_msg_.obs[2].L.i, 107851013); + assign(test_msg_.obs[2].P, 2052171351); + assign(test_msg_.obs[2].cn0, 170); + assign(test_msg_.obs[2].lock, 0); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 225); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepB, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_b, sizeof(msg->obs_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_b, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xe90b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_b_t &lesser, + const sbp_msg_obs_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_b_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 67, 0, 246, 215, 55, 120, 46, 39, 0, 251, 6, 33, 68, 199, 101, + 136, 133, 247, 42, 7, 219, 154, 0, 0, 220, 0, 0, 0, 219, 14, 123, + 133, 96, 215, 3, 7, 235, 156, 0, 0, 222, 0, 0, 0, 87, 166, 81, + 122, 5, 173, 109, 6, 174, 170, 0, 0, 225, 0, 0, 0, 11, 233, + }; + uint8_t encoded_payload_[55] = { + 120, 46, 39, 0, 251, 6, 33, 68, 199, 101, 136, 133, 247, 42, + 7, 219, 154, 0, 0, 220, 0, 0, 0, 219, 14, 123, 133, 96, + 215, 3, 7, 235, 156, 0, 0, 222, 0, 0, 0, 87, 166, 81, + 122, 5, 173, 109, 6, 174, 170, 0, 0, 225, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_b_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepB, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ( + sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + return sbp_msg_obs_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepB); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepB, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepB, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepB2 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepB2() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 2568000); + assign(test_msg_.header.t.wn, 1787); + assign(test_msg_.n_obs, 6); + + assign(test_msg_.obs[0].L.f, 94); + assign(test_msg_.obs[0].L.i, 117912556); + assign(test_msg_.obs[0].P, 2243658852); + assign(test_msg_.obs[0].cn0, 156); + assign(test_msg_.obs[0].lock, 0); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 202); + + assign(test_msg_.obs[1].L.f, 40); + assign(test_msg_.obs[1].L.i, 129900210); + assign(test_msg_.obs[1].P, 2471868513); + assign(test_msg_.obs[1].cn0, 140); + assign(test_msg_.obs[1].lock, 0); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 203); + + assign(test_msg_.obs[2].L.f, 2); + assign(test_msg_.obs[2].L.i, 122530650); + assign(test_msg_.obs[2].P, 2331537287); + assign(test_msg_.obs[2].cn0, 150); + assign(test_msg_.obs[2].lock, 0); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 208); + + assign(test_msg_.obs[3].L.f, 241); + assign(test_msg_.obs[3].L.i, 119280830); + assign(test_msg_.obs[3].P, 2269703860); + assign(test_msg_.obs[3].cn0, 155); + assign(test_msg_.obs[3].lock, 0); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 212); + + assign(test_msg_.obs[4].L.f, 153); + assign(test_msg_.obs[4].L.i, 109691996); + assign(test_msg_.obs[4].P, 2087295247); + assign(test_msg_.obs[4].cn0, 168); + assign(test_msg_.obs[4].lock, 0); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 217); + + assign(test_msg_.obs[5].L.f, 41); + assign(test_msg_.obs[5].L.i, 123340176); + assign(test_msg_.obs[5].P, 2347022641); + assign(test_msg_.obs[5].cn0, 150); + assign(test_msg_.obs[5].lock, 0); + assign(test_msg_.obs[5].sid.code, 0); + assign(test_msg_.obs[5].sid.reserved, 0); + assign(test_msg_.obs[5].sid.sat, 218); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepB, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_b, sizeof(msg->obs_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_b, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x62f1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 103; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_b_t &lesser, + const sbp_msg_obs_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_b_t test_msg_{}; + uint8_t encoded_frame_[103 + 8] = { + 85, 67, 0, 246, 215, 103, 64, 47, 39, 0, 251, 6, 32, 100, 132, 187, + 133, 236, 51, 7, 7, 94, 156, 0, 0, 202, 0, 0, 0, 97, 184, 85, + 147, 178, 30, 190, 7, 40, 140, 0, 0, 203, 0, 0, 0, 135, 111, 248, + 138, 90, 171, 77, 7, 2, 150, 0, 0, 208, 0, 0, 0, 180, 238, 72, + 135, 190, 20, 28, 7, 241, 155, 0, 0, 212, 0, 0, 0, 15, 153, 105, + 124, 92, 196, 137, 6, 153, 168, 0, 0, 217, 0, 0, 0, 49, 185, 228, + 139, 144, 5, 90, 7, 41, 150, 0, 0, 218, 0, 0, 0, 241, 98, + }; + uint8_t encoded_payload_[103] = { + 64, 47, 39, 0, 251, 6, 32, 100, 132, 187, 133, 236, 51, 7, 7, + 94, 156, 0, 0, 202, 0, 0, 0, 97, 184, 85, 147, 178, 30, 190, + 7, 40, 140, 0, 0, 203, 0, 0, 0, 135, 111, 248, 138, 90, 171, + 77, 7, 2, 150, 0, 0, 208, 0, 0, 0, 180, 238, 72, 135, 190, + 20, 28, 7, 241, 155, 0, 0, 212, 0, 0, 0, 15, 153, 105, 124, + 92, 196, 137, 6, 153, 168, 0, 0, 217, 0, 0, 0, 49, 185, 228, + 139, 144, 5, 90, 7, 41, 150, 0, 0, 218, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_b_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepB, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + EXPECT_EQ( + sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + for (uint8_t i = 0; i < 103; i++) { + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + return sbp_msg_obs_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.code, greater.obs[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.reserved, + greater.obs[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.sat, greater.obs[5].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepB); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepB, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepB, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepB3 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepB3() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 2568000); + assign(test_msg_.header.t.wn, 1787); + assign(test_msg_.n_obs, 3); + + assign(test_msg_.obs[0].L.f, 20); + assign(test_msg_.obs[0].L.i, 120255759); + assign(test_msg_.obs[0].P, 2288358634); + assign(test_msg_.obs[0].cn0, 154); + assign(test_msg_.obs[0].lock, 0); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 220); + + assign(test_msg_.obs[1].L.f, 38); + assign(test_msg_.obs[1].L.i, 117691920); + assign(test_msg_.obs[1].P, 2239428560); + assign(test_msg_.obs[1].cn0, 156); + assign(test_msg_.obs[1].lock, 0); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 222); + + assign(test_msg_.obs[2].L.f, 7); + assign(test_msg_.obs[2].L.i, 107850774); + assign(test_msg_.obs[2].P, 2052167183); + assign(test_msg_.obs[2].cn0, 172); + assign(test_msg_.obs[2].lock, 0); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 225); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepB, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_b, sizeof(msg->obs_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_b, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xdc9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_b_t &lesser, + const sbp_msg_obs_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_b_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 67, 0, 246, 215, 55, 64, 47, 39, 0, 251, 6, 33, 234, 148, 101, + 136, 15, 245, 42, 7, 20, 154, 0, 0, 220, 0, 0, 0, 208, 247, 122, + 133, 16, 214, 3, 7, 38, 156, 0, 0, 222, 0, 0, 0, 15, 150, 81, + 122, 22, 172, 109, 6, 7, 172, 0, 0, 225, 0, 0, 0, 201, 13, + }; + uint8_t encoded_payload_[55] = { + 64, 47, 39, 0, 251, 6, 33, 234, 148, 101, 136, 15, 245, 42, + 7, 20, 154, 0, 0, 220, 0, 0, 0, 208, 247, 122, 133, 16, + 214, 3, 7, 38, 156, 0, 0, 222, 0, 0, 0, 15, 150, 81, + 122, 22, 172, 109, 6, 7, 172, 0, 0, 225, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_b_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepB, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ( + sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + return sbp_msg_obs_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepB); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepB, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepB, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepB4 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepB4() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 2568200); + assign(test_msg_.header.t.wn, 1787); + assign(test_msg_.n_obs, 6); + + assign(test_msg_.obs[0].L.f, 165); + assign(test_msg_.obs[0].L.i, 117912057); + assign(test_msg_.obs[0].P, 2243649790); + assign(test_msg_.obs[0].cn0, 156); + assign(test_msg_.obs[0].lock, 0); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 202); + + assign(test_msg_.obs[1].L.f, 106); + assign(test_msg_.obs[1].L.i, 129900811); + assign(test_msg_.obs[1].P, 2471880049); + assign(test_msg_.obs[1].cn0, 143); + assign(test_msg_.obs[1].lock, 0); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 203); + + assign(test_msg_.obs[2].L.f, 159); + assign(test_msg_.obs[2].L.i, 122530275); + assign(test_msg_.obs[2].P, 2331530678); + assign(test_msg_.obs[2].cn0, 150); + assign(test_msg_.obs[2].lock, 0); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 208); + + assign(test_msg_.obs[3].L.f, 7); + assign(test_msg_.obs[3].L.i, 119281418); + assign(test_msg_.obs[3].P, 2269714449); + assign(test_msg_.obs[3].cn0, 156); + assign(test_msg_.obs[3].lock, 0); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 212); + + assign(test_msg_.obs[4].L.f, 186); + assign(test_msg_.obs[4].L.i, 109692070); + assign(test_msg_.obs[4].P, 2087295852); + assign(test_msg_.obs[4].cn0, 170); + assign(test_msg_.obs[4].lock, 0); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 217); + + assign(test_msg_.obs[5].L.f, 236); + assign(test_msg_.obs[5].L.i, 123339597); + assign(test_msg_.obs[5].P, 2347011798); + assign(test_msg_.obs[5].cn0, 151); + assign(test_msg_.obs[5].lock, 0); + assign(test_msg_.obs[5].sid.code, 0); + assign(test_msg_.obs[5].sid.reserved, 0); + assign(test_msg_.obs[5].sid.sat, 218); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepB, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_b, sizeof(msg->obs_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_b, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x763b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 103; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_b_t &lesser, + const sbp_msg_obs_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_b_t test_msg_{}; + uint8_t encoded_frame_[103 + 8] = { + 85, 67, 0, 246, 215, 103, 8, 48, 39, 0, 251, 6, 32, 254, 96, 187, + 133, 249, 49, 7, 7, 165, 156, 0, 0, 202, 0, 0, 0, 113, 229, 85, + 147, 11, 33, 190, 7, 106, 143, 0, 0, 203, 0, 0, 0, 182, 85, 248, + 138, 227, 169, 77, 7, 159, 150, 0, 0, 208, 0, 0, 0, 17, 24, 73, + 135, 10, 23, 28, 7, 7, 156, 0, 0, 212, 0, 0, 0, 108, 155, 105, + 124, 166, 196, 137, 6, 186, 170, 0, 0, 217, 0, 0, 0, 214, 142, 228, + 139, 77, 3, 90, 7, 236, 151, 0, 0, 218, 0, 0, 0, 59, 118, + }; + uint8_t encoded_payload_[103] = { + 8, 48, 39, 0, 251, 6, 32, 254, 96, 187, 133, 249, 49, 7, 7, + 165, 156, 0, 0, 202, 0, 0, 0, 113, 229, 85, 147, 11, 33, 190, + 7, 106, 143, 0, 0, 203, 0, 0, 0, 182, 85, 248, 138, 227, 169, + 77, 7, 159, 150, 0, 0, 208, 0, 0, 0, 17, 24, 73, 135, 10, + 23, 28, 7, 7, 156, 0, 0, 212, 0, 0, 0, 108, 155, 105, 124, + 166, 196, 137, 6, 186, 170, 0, 0, 217, 0, 0, 0, 214, 142, 228, + 139, 77, 3, 90, 7, 236, 151, 0, 0, 218, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_b_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepB, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + EXPECT_EQ( + sbp_msg_obs_dep_b_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + + for (uint8_t i = 0; i < 103; i++) { + EXPECT_EQ(sbp_msg_obs_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + return sbp_msg_obs_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_b_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_b_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.code, greater.obs[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.reserved, + greater.obs[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_b_t lesser = info.test_msg; + sbp_msg_obs_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.sat, greater.obs[5].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepB); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[103]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 103); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 103), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 103); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepB, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepB4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepB, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgObsDepC.cc b/c/test/cpp/auto_check_sbp_observation_MsgObsDepC.cc index 450c1271b5..8d1861f850 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgObsDepC.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgObsDepC.cc @@ -16,66 +16,407 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgObsDepC0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgObsDepC0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgObsDepC0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgObsDepC0() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 414670600); + assign(test_msg_.header.t.wn, 1898); + assign(test_msg_.n_obs, 5); + + assign(test_msg_.obs[0].L.f, 231); + assign(test_msg_.obs[0].L.i, -565647); + assign(test_msg_.obs[0].P, 1347025534); + assign(test_msg_.obs[0].cn0, 163); + assign(test_msg_.obs[0].lock, 58853); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 4); + + assign(test_msg_.obs[1].L.f, 196); + assign(test_msg_.obs[1].L.i, -355503); + assign(test_msg_.obs[1].P, 1180752956); + assign(test_msg_.obs[1].cn0, 208); + assign(test_msg_.obs[1].lock, 7188); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 6); + + assign(test_msg_.obs[2].L.f, 110); + assign(test_msg_.obs[2].L.i, -902116); + assign(test_msg_.obs[2].P, 1295924728); + assign(test_msg_.obs[2].cn0, 171); + assign(test_msg_.obs[2].lock, 45748); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 7); + + assign(test_msg_.obs[3].L.f, 41); + assign(test_msg_.obs[3].L.i, 861612); + assign(test_msg_.obs[3].P, 1304319213); + assign(test_msg_.obs[3].cn0, 170); + assign(test_msg_.obs[3].lock, 42217); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 10); + + assign(test_msg_.obs[4].L.f, 19); + assign(test_msg_.obs[4].L.i, 1424624); + assign(test_msg_.obs[4].P, 1258902820); + assign(test_msg_.obs[4].cn0, 182); + assign(test_msg_.obs[4].lock, 53700); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 12); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepC, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_c, sizeof(msg->obs_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_c, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepC); + info.sender_id = 38982; + info.preamble = 0x55; + info.crc = 0xafbe; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 87; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_obs_dep_c_t &lesser, + const sbp_msg_obs_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_c_cmp(&greater, &lesser), 0); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepC0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_c_t test_msg_{}; + uint8_t encoded_frame_[87 + 8] = { 85, 73, 0, 70, 152, 87, 8, 95, 183, 24, 106, 7, 32, 126, 250, 73, 80, 113, 94, 247, 255, 231, 163, 229, 229, 4, 0, 0, 0, 60, 220, 96, 70, 81, 147, 250, 255, 196, 208, 20, 28, 6, 0, 0, 0, 248, 61, 62, @@ -83,1108 +424,4742 @@ TEST_F(Test_auto_check_sbp_observation_MsgObsDepC0, Test) { 77, 172, 37, 13, 0, 41, 170, 233, 164, 10, 0, 0, 0, 36, 85, 9, 75, 240, 188, 21, 0, 19, 182, 196, 209, 12, 0, 0, 0, 190, 175, }; + uint8_t encoded_payload_[87] = { + 8, 95, 183, 24, 106, 7, 32, 126, 250, 73, 80, 113, 94, 247, 255, + 231, 163, 229, 229, 4, 0, 0, 0, 60, 220, 96, 70, 81, 147, 250, + 255, 196, 208, 20, 28, 6, 0, 0, 0, 248, 61, 62, 77, 28, 60, + 242, 255, 110, 171, 180, 178, 7, 0, 0, 0, 237, 84, 190, 77, 172, + 37, 13, 0, 41, 170, 233, 164, 10, 0, 0, 0, 36, 85, 9, 75, + 240, 188, 21, 0, 19, 182, 196, 209, 12, 0, 0, 0, + }; +}; - sbp_msg_obs_dep_c_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 414670600; - test_msg.header.t.wn = 1898; - test_msg.n_obs = 5; - - test_msg.obs[0].L.f = 231; - test_msg.obs[0].L.i = -565647; - test_msg.obs[0].P = 1347025534; - test_msg.obs[0].cn0 = 163; - test_msg.obs[0].lock = 58853; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 4; - - test_msg.obs[1].L.f = 196; - test_msg.obs[1].L.i = -355503; - test_msg.obs[1].P = 1180752956; - test_msg.obs[1].cn0 = 208; - test_msg.obs[1].lock = 7188; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 6; - - test_msg.obs[2].L.f = 110; - test_msg.obs[2].L.i = -902116; - test_msg.obs[2].P = 1295924728; - test_msg.obs[2].cn0 = 171; - test_msg.obs[2].lock = 45748; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 7; - - test_msg.obs[3].L.f = 41; - test_msg.obs[3].L.i = 861612; - test_msg.obs[3].P = 1304319213; - test_msg.obs[3].cn0 = 170; - test_msg.obs[3].lock = 42217; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 10; - - test_msg.obs[4].L.f = 19; - test_msg.obs[4].L.i = 1424624; - test_msg.obs[4].P = 1258902820; - test_msg.obs[4].cn0 = 182; - test_msg.obs[4].lock = 53700; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 12; - - EXPECT_EQ(send_message(38982, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 38982); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 414670600) - << "incorrect value for last_msg_.header.t.tow, expected 414670600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1898) - << "incorrect value for last_msg_.header.t.wn, expected 1898, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 5) - << "incorrect value for last_msg_.n_obs, expected 5, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 231) - << "incorrect value for last_msg_.obs[0].L.f, expected 231, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -565647) - << "incorrect value for last_msg_.obs[0].L.i, expected -565647, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1347025534) - << "incorrect value for last_msg_.obs[0].P, expected 1347025534, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 163) - << "incorrect value for last_msg_.obs[0].cn0, expected 163, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 58853) - << "incorrect value for last_msg_.obs[0].lock, expected 58853, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 4) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 4, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 196) - << "incorrect value for last_msg_.obs[1].L.f, expected 196, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, -355503) - << "incorrect value for last_msg_.obs[1].L.i, expected -355503, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1180752956) - << "incorrect value for last_msg_.obs[1].P, expected 1180752956, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 208) - << "incorrect value for last_msg_.obs[1].cn0, expected 208, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 7188) - << "incorrect value for last_msg_.obs[1].lock, expected 7188, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 6) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 6, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 110) - << "incorrect value for last_msg_.obs[2].L.f, expected 110, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -902116) - << "incorrect value for last_msg_.obs[2].L.i, expected -902116, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1295924728) - << "incorrect value for last_msg_.obs[2].P, expected 1295924728, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 171) - << "incorrect value for last_msg_.obs[2].cn0, expected 171, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 45748) - << "incorrect value for last_msg_.obs[2].lock, expected 45748, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 7) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 7, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 41) - << "incorrect value for last_msg_.obs[3].L.f, expected 41, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 861612) - << "incorrect value for last_msg_.obs[3].L.i, expected 861612, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 1304319213) - << "incorrect value for last_msg_.obs[3].P, expected 1304319213, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 170) - << "incorrect value for last_msg_.obs[3].cn0, expected 170, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 42217) - << "incorrect value for last_msg_.obs[3].lock, expected 42217, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 10) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 10, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 19) - << "incorrect value for last_msg_.obs[4].L.f, expected 19, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 1424624) - << "incorrect value for last_msg_.obs[4].L.i, expected 1424624, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1258902820) - << "incorrect value for last_msg_.obs[4].P, expected 1258902820, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 182) - << "incorrect value for last_msg_.obs[4].cn0, expected 182, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 53700) - << "incorrect value for last_msg_.obs[4].lock, expected 53700, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 12) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 12, is " - << last_msg_.obs[4].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepC1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepC1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_c_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepC, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + EXPECT_EQ( + sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + for (uint8_t i = 0; i < 87; i++) { + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_observation_MsgObsDepC1, Test) { - uint8_t encoded_frame[] = { - 85, 73, 0, 70, 152, 55, 8, 95, 183, 24, 106, 7, 33, 68, 166, 75, - 77, 186, 230, 24, 0, 101, 186, 162, 102, 16, 0, 0, 0, 87, 255, 155, - 69, 74, 158, 5, 0, 26, 190, 206, 30, 27, 0, 0, 0, 64, 89, 124, - 68, 26, 22, 3, 0, 114, 217, 225, 73, 29, 0, 0, 0, 37, 179, - }; + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_obs_dep_c_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 414670600; - test_msg.header.t.wn = 1898; - test_msg.n_obs = 3; - - test_msg.obs[0].L.f = 101; - test_msg.obs[0].L.i = 1631930; - test_msg.obs[0].P = 1296803396; - test_msg.obs[0].cn0 = 186; - test_msg.obs[0].lock = 26274; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 16; - - test_msg.obs[1].L.f = 26; - test_msg.obs[1].L.i = 368202; - test_msg.obs[1].P = 1167851351; - test_msg.obs[1].cn0 = 190; - test_msg.obs[1].lock = 7886; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 27; - - test_msg.obs[2].L.f = 114; - test_msg.obs[2].L.i = 202266; - test_msg.obs[2].P = 1149000000; - test_msg.obs[2].cn0 = 217; - test_msg.obs[2].lock = 18913; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 29; - - EXPECT_EQ(send_message(38982, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 38982); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 414670600) - << "incorrect value for last_msg_.header.t.tow, expected 414670600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1898) - << "incorrect value for last_msg_.header.t.wn, expected 1898, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 3) - << "incorrect value for last_msg_.n_obs, expected 3, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 101) - << "incorrect value for last_msg_.obs[0].L.f, expected 101, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 1631930) - << "incorrect value for last_msg_.obs[0].L.i, expected 1631930, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1296803396) - << "incorrect value for last_msg_.obs[0].P, expected 1296803396, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 186) - << "incorrect value for last_msg_.obs[0].cn0, expected 186, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 26274) - << "incorrect value for last_msg_.obs[0].lock, expected 26274, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 16) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 16, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 26) - << "incorrect value for last_msg_.obs[1].L.f, expected 26, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 368202) - << "incorrect value for last_msg_.obs[1].L.i, expected 368202, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1167851351) - << "incorrect value for last_msg_.obs[1].P, expected 1167851351, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 190) - << "incorrect value for last_msg_.obs[1].cn0, expected 190, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 7886) - << "incorrect value for last_msg_.obs[1].lock, expected 7886, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 27) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 27, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 114) - << "incorrect value for last_msg_.obs[2].L.f, expected 114, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 202266) - << "incorrect value for last_msg_.obs[2].L.i, expected 202266, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1149000000) - << "incorrect value for last_msg_.obs[2].P, expected 1149000000, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 217) - << "incorrect value for last_msg_.obs[2].cn0, expected 217, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 18913) - << "incorrect value for last_msg_.obs[2].lock, expected 18913, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 29) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 29, is " - << last_msg_.obs[2].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepC2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepC2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + return sbp_msg_obs_dep_c_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_c_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepC2, Test) { - uint8_t encoded_frame[] = { - 85, 73, 0, 0, 0, 87, 8, 95, 183, 24, 106, 7, 32, 217, 251, 73, - 80, 9, 72, 248, 255, 30, 168, 113, 81, 4, 0, 0, 0, 211, 220, 96, - 70, 198, 107, 251, 255, 115, 195, 53, 144, 6, 0, 0, 0, 77, 61, 62, - 77, 40, 161, 243, 255, 130, 176, 93, 142, 7, 0, 0, 0, 1, 86, 190, - 77, 88, 77, 12, 0, 116, 199, 229, 213, 10, 0, 0, 0, 93, 85, 9, - 75, 64, 139, 20, 0, 120, 177, 196, 194, 12, 0, 0, 0, 141, 161, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_obs_dep_c_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 414670600; - test_msg.header.t.wn = 1898; - test_msg.n_obs = 5; - - test_msg.obs[0].L.f = 30; - test_msg.obs[0].L.i = -505847; - test_msg.obs[0].P = 1347025881; - test_msg.obs[0].cn0 = 168; - test_msg.obs[0].lock = 20849; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 4; - - test_msg.obs[1].L.f = 115; - test_msg.obs[1].L.i = -300090; - test_msg.obs[1].P = 1180753107; - test_msg.obs[1].cn0 = 195; - test_msg.obs[1].lock = 36917; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 6; - - test_msg.obs[2].L.f = 130; - test_msg.obs[2].L.i = -810712; - test_msg.obs[2].P = 1295924557; - test_msg.obs[2].cn0 = 176; - test_msg.obs[2].lock = 36445; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 7; - - test_msg.obs[3].L.f = 116; - test_msg.obs[3].L.i = 806232; - test_msg.obs[3].P = 1304319489; - test_msg.obs[3].cn0 = 199; - test_msg.obs[3].lock = 54757; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 10; - - test_msg.obs[4].L.f = 120; - test_msg.obs[4].L.i = 1346368; - test_msg.obs[4].P = 1258902877; - test_msg.obs[4].cn0 = 177; - test_msg.obs[4].lock = 49860; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 12; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 414670600) - << "incorrect value for last_msg_.header.t.tow, expected 414670600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1898) - << "incorrect value for last_msg_.header.t.wn, expected 1898, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 5) - << "incorrect value for last_msg_.n_obs, expected 5, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 30) - << "incorrect value for last_msg_.obs[0].L.f, expected 30, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -505847) - << "incorrect value for last_msg_.obs[0].L.i, expected -505847, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1347025881) - << "incorrect value for last_msg_.obs[0].P, expected 1347025881, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 168) - << "incorrect value for last_msg_.obs[0].cn0, expected 168, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 20849) - << "incorrect value for last_msg_.obs[0].lock, expected 20849, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 4) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 4, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 115) - << "incorrect value for last_msg_.obs[1].L.f, expected 115, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, -300090) - << "incorrect value for last_msg_.obs[1].L.i, expected -300090, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1180753107) - << "incorrect value for last_msg_.obs[1].P, expected 1180753107, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 195) - << "incorrect value for last_msg_.obs[1].cn0, expected 195, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 36917) - << "incorrect value for last_msg_.obs[1].lock, expected 36917, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 6) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 6, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 130) - << "incorrect value for last_msg_.obs[2].L.f, expected 130, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -810712) - << "incorrect value for last_msg_.obs[2].L.i, expected -810712, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1295924557) - << "incorrect value for last_msg_.obs[2].P, expected 1295924557, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 176) - << "incorrect value for last_msg_.obs[2].cn0, expected 176, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 36445) - << "incorrect value for last_msg_.obs[2].lock, expected 36445, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 7) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 7, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 116) - << "incorrect value for last_msg_.obs[3].L.f, expected 116, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 806232) - << "incorrect value for last_msg_.obs[3].L.i, expected 806232, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 1304319489) - << "incorrect value for last_msg_.obs[3].P, expected 1304319489, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 199) - << "incorrect value for last_msg_.obs[3].cn0, expected 199, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 54757) - << "incorrect value for last_msg_.obs[3].lock, expected 54757, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 10) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 10, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 120) - << "incorrect value for last_msg_.obs[4].L.f, expected 120, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 1346368) - << "incorrect value for last_msg_.obs[4].L.i, expected 1346368, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1258902877) - << "incorrect value for last_msg_.obs[4].P, expected 1258902877, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 177) - << "incorrect value for last_msg_.obs[4].cn0, expected 177, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 49860) - << "incorrect value for last_msg_.obs[4].lock, expected 49860, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 12) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 12, is " - << last_msg_.obs[4].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepC3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepC3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_MsgObsDepC3, Test) { - uint8_t encoded_frame[] = { - 85, 73, 0, 0, 0, 55, 8, 95, 183, 24, 106, 7, 33, 70, 167, 75, - 77, 140, 136, 23, 0, 90, 187, 158, 129, 16, 0, 0, 0, 232, 255, 155, - 69, 45, 175, 5, 0, 17, 208, 175, 56, 27, 0, 0, 0, 64, 89, 124, - 68, 45, 96, 3, 0, 75, 185, 73, 206, 29, 0, 0, 0, 220, 158, - }; +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_obs_dep_c_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 414670600; - test_msg.header.t.wn = 1898; - test_msg.n_obs = 3; - - test_msg.obs[0].L.f = 90; - test_msg.obs[0].L.i = 1542284; - test_msg.obs[0].P = 1296803654; - test_msg.obs[0].cn0 = 187; - test_msg.obs[0].lock = 33182; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 16; - - test_msg.obs[1].L.f = 17; - test_msg.obs[1].L.i = 372525; - test_msg.obs[1].P = 1167851496; - test_msg.obs[1].cn0 = 208; - test_msg.obs[1].lock = 14511; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 27; - - test_msg.obs[2].L.f = 75; - test_msg.obs[2].L.i = 221229; - test_msg.obs[2].P = 1149000000; - test_msg.obs[2].cn0 = 185; - test_msg.obs[2].lock = 52809; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 29; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 414670600) - << "incorrect value for last_msg_.header.t.tow, expected 414670600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1898) - << "incorrect value for last_msg_.header.t.wn, expected 1898, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 3) - << "incorrect value for last_msg_.n_obs, expected 3, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 90) - << "incorrect value for last_msg_.obs[0].L.f, expected 90, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 1542284) - << "incorrect value for last_msg_.obs[0].L.i, expected 1542284, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1296803654) - << "incorrect value for last_msg_.obs[0].P, expected 1296803654, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 187) - << "incorrect value for last_msg_.obs[0].cn0, expected 187, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 33182) - << "incorrect value for last_msg_.obs[0].lock, expected 33182, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 16) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 16, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 17) - << "incorrect value for last_msg_.obs[1].L.f, expected 17, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 372525) - << "incorrect value for last_msg_.obs[1].L.i, expected 372525, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1167851496) - << "incorrect value for last_msg_.obs[1].P, expected 1167851496, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 208) - << "incorrect value for last_msg_.obs[1].cn0, expected 208, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 14511) - << "incorrect value for last_msg_.obs[1].lock, expected 14511, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 27) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 27, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 75) - << "incorrect value for last_msg_.obs[2].L.f, expected 75, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 221229) - << "incorrect value for last_msg_.obs[2].L.i, expected 221229, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1149000000) - << "incorrect value for last_msg_.obs[2].P, expected 1149000000, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 185) - << "incorrect value for last_msg_.obs[2].cn0, expected 185, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 52809) - << "incorrect value for last_msg_.obs[2].lock, expected 52809, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 29) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 29, is " - << last_msg_.obs[2].sid.sat; -} -class Test_auto_check_sbp_observation_MsgObsDepC4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_MsgObsDepC4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_c_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_c_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_MsgObsDepC4, Test) { - uint8_t encoded_frame[] = { - 85, 73, 0, 70, 152, 87, 208, 95, 183, 24, 106, 7, 32, 44, 8, 74, - 80, 86, 93, 247, 255, 57, 158, 229, 229, 4, 0, 0, 0, 224, 229, 96, - 70, 156, 146, 250, 255, 221, 200, 20, 28, 6, 0, 0, 0, 60, 82, 62, - 77, 93, 58, 242, 255, 39, 164, 180, 178, 7, 0, 0, 0, 222, 73, 190, - 77, 46, 39, 13, 0, 202, 181, 233, 164, 10, 0, 0, 0, 149, 64, 9, - 75, 114, 191, 21, 0, 249, 182, 196, 209, 12, 0, 0, 0, 112, 8, - }; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepC); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_obs_dep_c_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 414670800; - test_msg.header.t.wn = 1898; - test_msg.n_obs = 5; - - test_msg.obs[0].L.f = 57; - test_msg.obs[0].L.i = -565930; - test_msg.obs[0].P = 1347029036; - test_msg.obs[0].cn0 = 158; - test_msg.obs[0].lock = 58853; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.reserved = 0; - test_msg.obs[0].sid.sat = 4; - - test_msg.obs[1].L.f = 221; - test_msg.obs[1].L.i = -355684; - test_msg.obs[1].P = 1180755424; - test_msg.obs[1].cn0 = 200; - test_msg.obs[1].lock = 7188; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.reserved = 0; - test_msg.obs[1].sid.sat = 6; - - test_msg.obs[2].L.f = 39; - test_msg.obs[2].L.i = -902563; - test_msg.obs[2].P = 1295929916; - test_msg.obs[2].cn0 = 164; - test_msg.obs[2].lock = 45748; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.reserved = 0; - test_msg.obs[2].sid.sat = 7; - - test_msg.obs[3].L.f = 202; - test_msg.obs[3].L.i = 861998; - test_msg.obs[3].P = 1304316382; - test_msg.obs[3].cn0 = 181; - test_msg.obs[3].lock = 42217; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.reserved = 0; - test_msg.obs[3].sid.sat = 10; - - test_msg.obs[4].L.f = 249; - test_msg.obs[4].L.i = 1425266; - test_msg.obs[4].P = 1258897557; - test_msg.obs[4].cn0 = 182; - test_msg.obs[4].lock = 53700; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.reserved = 0; - test_msg.obs[4].sid.sat = 12; - - EXPECT_EQ(send_message(38982, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 38982); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 414670800) - << "incorrect value for last_msg_.header.t.tow, expected 414670800, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1898) - << "incorrect value for last_msg_.header.t.wn, expected 1898, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 5) - << "incorrect value for last_msg_.n_obs, expected 5, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 57) - << "incorrect value for last_msg_.obs[0].L.f, expected 57, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -565930) - << "incorrect value for last_msg_.obs[0].L.i, expected -565930, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1347029036) - << "incorrect value for last_msg_.obs[0].P, expected 1347029036, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 158) - << "incorrect value for last_msg_.obs[0].cn0, expected 158, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 58853) - << "incorrect value for last_msg_.obs[0].lock, expected 58853, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.reserved, 0) - << "incorrect value for last_msg_.obs[0].sid.reserved, expected 0, is " - << last_msg_.obs[0].sid.reserved; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 4) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 4, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[1].L.f, 221) - << "incorrect value for last_msg_.obs[1].L.f, expected 221, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, -355684) - << "incorrect value for last_msg_.obs[1].L.i, expected -355684, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1180755424) - << "incorrect value for last_msg_.obs[1].P, expected 1180755424, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 200) - << "incorrect value for last_msg_.obs[1].cn0, expected 200, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 7188) - << "incorrect value for last_msg_.obs[1].lock, expected 7188, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.reserved, 0) - << "incorrect value for last_msg_.obs[1].sid.reserved, expected 0, is " - << last_msg_.obs[1].sid.reserved; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 6) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 6, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[2].L.f, 39) - << "incorrect value for last_msg_.obs[2].L.f, expected 39, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -902563) - << "incorrect value for last_msg_.obs[2].L.i, expected -902563, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1295929916) - << "incorrect value for last_msg_.obs[2].P, expected 1295929916, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 164) - << "incorrect value for last_msg_.obs[2].cn0, expected 164, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 45748) - << "incorrect value for last_msg_.obs[2].lock, expected 45748, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.reserved, 0) - << "incorrect value for last_msg_.obs[2].sid.reserved, expected 0, is " - << last_msg_.obs[2].sid.reserved; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 7) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 7, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[3].L.f, 202) - << "incorrect value for last_msg_.obs[3].L.f, expected 202, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 861998) - << "incorrect value for last_msg_.obs[3].L.i, expected 861998, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 1304316382) - << "incorrect value for last_msg_.obs[3].P, expected 1304316382, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 181) - << "incorrect value for last_msg_.obs[3].cn0, expected 181, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 42217) - << "incorrect value for last_msg_.obs[3].lock, expected 42217, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.reserved, 0) - << "incorrect value for last_msg_.obs[3].sid.reserved, expected 0, is " - << last_msg_.obs[3].sid.reserved; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 10) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 10, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[4].L.f, 249) - << "incorrect value for last_msg_.obs[4].L.f, expected 249, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 1425266) - << "incorrect value for last_msg_.obs[4].L.i, expected 1425266, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1258897557) - << "incorrect value for last_msg_.obs[4].P, expected 1258897557, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 182) - << "incorrect value for last_msg_.obs[4].cn0, expected 182, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 53700) - << "incorrect value for last_msg_.obs[4].lock, expected 53700, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.reserved, 0) - << "incorrect value for last_msg_.obs[4].sid.reserved, expected 0, is " - << last_msg_.obs[4].sid.reserved; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 12) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 12, is " - << last_msg_.obs[4].sid.sat; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepC, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepC, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepC1 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepC1() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 414670600); + assign(test_msg_.header.t.wn, 1898); + assign(test_msg_.n_obs, 3); + + assign(test_msg_.obs[0].L.f, 101); + assign(test_msg_.obs[0].L.i, 1631930); + assign(test_msg_.obs[0].P, 1296803396); + assign(test_msg_.obs[0].cn0, 186); + assign(test_msg_.obs[0].lock, 26274); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 16); + + assign(test_msg_.obs[1].L.f, 26); + assign(test_msg_.obs[1].L.i, 368202); + assign(test_msg_.obs[1].P, 1167851351); + assign(test_msg_.obs[1].cn0, 190); + assign(test_msg_.obs[1].lock, 7886); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 27); + + assign(test_msg_.obs[2].L.f, 114); + assign(test_msg_.obs[2].L.i, 202266); + assign(test_msg_.obs[2].P, 1149000000); + assign(test_msg_.obs[2].cn0, 217); + assign(test_msg_.obs[2].lock, 18913); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 29); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepC, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_c, sizeof(msg->obs_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_c, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepC); + info.sender_id = 38982; + info.preamble = 0x55; + info.crc = 0xb325; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_c_t &lesser, + const sbp_msg_obs_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_c_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 73, 0, 70, 152, 55, 8, 95, 183, 24, 106, 7, 33, 68, 166, 75, + 77, 186, 230, 24, 0, 101, 186, 162, 102, 16, 0, 0, 0, 87, 255, 155, + 69, 74, 158, 5, 0, 26, 190, 206, 30, 27, 0, 0, 0, 64, 89, 124, + 68, 26, 22, 3, 0, 114, 217, 225, 73, 29, 0, 0, 0, 37, 179, + }; + uint8_t encoded_payload_[55] = { + 8, 95, 183, 24, 106, 7, 33, 68, 166, 75, 77, 186, 230, 24, + 0, 101, 186, 162, 102, 16, 0, 0, 0, 87, 255, 155, 69, 74, + 158, 5, 0, 26, 190, 206, 30, 27, 0, 0, 0, 64, 89, 124, + 68, 26, 22, 3, 0, 114, 217, 225, 73, 29, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_c_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepC, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ( + sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + return sbp_msg_obs_dep_c_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_c_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepC); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepC, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepC, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepC2 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepC2() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 414670600); + assign(test_msg_.header.t.wn, 1898); + assign(test_msg_.n_obs, 5); + + assign(test_msg_.obs[0].L.f, 30); + assign(test_msg_.obs[0].L.i, -505847); + assign(test_msg_.obs[0].P, 1347025881); + assign(test_msg_.obs[0].cn0, 168); + assign(test_msg_.obs[0].lock, 20849); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 4); + + assign(test_msg_.obs[1].L.f, 115); + assign(test_msg_.obs[1].L.i, -300090); + assign(test_msg_.obs[1].P, 1180753107); + assign(test_msg_.obs[1].cn0, 195); + assign(test_msg_.obs[1].lock, 36917); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 6); + + assign(test_msg_.obs[2].L.f, 130); + assign(test_msg_.obs[2].L.i, -810712); + assign(test_msg_.obs[2].P, 1295924557); + assign(test_msg_.obs[2].cn0, 176); + assign(test_msg_.obs[2].lock, 36445); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 7); + + assign(test_msg_.obs[3].L.f, 116); + assign(test_msg_.obs[3].L.i, 806232); + assign(test_msg_.obs[3].P, 1304319489); + assign(test_msg_.obs[3].cn0, 199); + assign(test_msg_.obs[3].lock, 54757); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 10); + + assign(test_msg_.obs[4].L.f, 120); + assign(test_msg_.obs[4].L.i, 1346368); + assign(test_msg_.obs[4].P, 1258902877); + assign(test_msg_.obs[4].cn0, 177); + assign(test_msg_.obs[4].lock, 49860); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 12); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepC, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_c, sizeof(msg->obs_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_c, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepC); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0xa18d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 87; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_c_t &lesser, + const sbp_msg_obs_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_c_t test_msg_{}; + uint8_t encoded_frame_[87 + 8] = { + 85, 73, 0, 0, 0, 87, 8, 95, 183, 24, 106, 7, 32, 217, 251, 73, + 80, 9, 72, 248, 255, 30, 168, 113, 81, 4, 0, 0, 0, 211, 220, 96, + 70, 198, 107, 251, 255, 115, 195, 53, 144, 6, 0, 0, 0, 77, 61, 62, + 77, 40, 161, 243, 255, 130, 176, 93, 142, 7, 0, 0, 0, 1, 86, 190, + 77, 88, 77, 12, 0, 116, 199, 229, 213, 10, 0, 0, 0, 93, 85, 9, + 75, 64, 139, 20, 0, 120, 177, 196, 194, 12, 0, 0, 0, 141, 161, + }; + uint8_t encoded_payload_[87] = { + 8, 95, 183, 24, 106, 7, 32, 217, 251, 73, 80, 9, 72, 248, 255, + 30, 168, 113, 81, 4, 0, 0, 0, 211, 220, 96, 70, 198, 107, 251, + 255, 115, 195, 53, 144, 6, 0, 0, 0, 77, 61, 62, 77, 40, 161, + 243, 255, 130, 176, 93, 142, 7, 0, 0, 0, 1, 86, 190, 77, 88, + 77, 12, 0, 116, 199, 229, 213, 10, 0, 0, 0, 93, 85, 9, 75, + 64, 139, 20, 0, 120, 177, 196, 194, 12, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_c_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepC, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + EXPECT_EQ( + sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + for (uint8_t i = 0; i < 87; i++) { + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + return sbp_msg_obs_dep_c_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_c_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepC); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepC, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepC, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepC3 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepC3() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 414670600); + assign(test_msg_.header.t.wn, 1898); + assign(test_msg_.n_obs, 3); + + assign(test_msg_.obs[0].L.f, 90); + assign(test_msg_.obs[0].L.i, 1542284); + assign(test_msg_.obs[0].P, 1296803654); + assign(test_msg_.obs[0].cn0, 187); + assign(test_msg_.obs[0].lock, 33182); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 16); + + assign(test_msg_.obs[1].L.f, 17); + assign(test_msg_.obs[1].L.i, 372525); + assign(test_msg_.obs[1].P, 1167851496); + assign(test_msg_.obs[1].cn0, 208); + assign(test_msg_.obs[1].lock, 14511); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 27); + + assign(test_msg_.obs[2].L.f, 75); + assign(test_msg_.obs[2].L.i, 221229); + assign(test_msg_.obs[2].P, 1149000000); + assign(test_msg_.obs[2].cn0, 185); + assign(test_msg_.obs[2].lock, 52809); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 29); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepC, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_c, sizeof(msg->obs_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_c, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepC); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0x9edc; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_c_t &lesser, + const sbp_msg_obs_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_c_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 73, 0, 0, 0, 55, 8, 95, 183, 24, 106, 7, 33, 70, 167, 75, + 77, 140, 136, 23, 0, 90, 187, 158, 129, 16, 0, 0, 0, 232, 255, 155, + 69, 45, 175, 5, 0, 17, 208, 175, 56, 27, 0, 0, 0, 64, 89, 124, + 68, 45, 96, 3, 0, 75, 185, 73, 206, 29, 0, 0, 0, 220, 158, + }; + uint8_t encoded_payload_[55] = { + 8, 95, 183, 24, 106, 7, 33, 70, 167, 75, 77, 140, 136, 23, + 0, 90, 187, 158, 129, 16, 0, 0, 0, 232, 255, 155, 69, 45, + 175, 5, 0, 17, 208, 175, 56, 27, 0, 0, 0, 64, 89, 124, + 68, 45, 96, 3, 0, 75, 185, 73, 206, 29, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_c_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepC, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ( + sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + return sbp_msg_obs_dep_c_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_c_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepC); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepC, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepC, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_MsgObsDepC4 : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgObsDepC4() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 414670800); + assign(test_msg_.header.t.wn, 1898); + assign(test_msg_.n_obs, 5); + + assign(test_msg_.obs[0].L.f, 57); + assign(test_msg_.obs[0].L.i, -565930); + assign(test_msg_.obs[0].P, 1347029036); + assign(test_msg_.obs[0].cn0, 158); + assign(test_msg_.obs[0].lock, 58853); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.reserved, 0); + assign(test_msg_.obs[0].sid.sat, 4); + + assign(test_msg_.obs[1].L.f, 221); + assign(test_msg_.obs[1].L.i, -355684); + assign(test_msg_.obs[1].P, 1180755424); + assign(test_msg_.obs[1].cn0, 200); + assign(test_msg_.obs[1].lock, 7188); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.reserved, 0); + assign(test_msg_.obs[1].sid.sat, 6); + + assign(test_msg_.obs[2].L.f, 39); + assign(test_msg_.obs[2].L.i, -902563); + assign(test_msg_.obs[2].P, 1295929916); + assign(test_msg_.obs[2].cn0, 164); + assign(test_msg_.obs[2].lock, 45748); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.reserved, 0); + assign(test_msg_.obs[2].sid.sat, 7); + + assign(test_msg_.obs[3].L.f, 202); + assign(test_msg_.obs[3].L.i, 861998); + assign(test_msg_.obs[3].P, 1304316382); + assign(test_msg_.obs[3].cn0, 181); + assign(test_msg_.obs[3].lock, 42217); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.reserved, 0); + assign(test_msg_.obs[3].sid.sat, 10); + + assign(test_msg_.obs[4].L.f, 249); + assign(test_msg_.obs[4].L.i, 1425266); + assign(test_msg_.obs[4].P, 1258897557); + assign(test_msg_.obs[4].cn0, 182); + assign(test_msg_.obs[4].lock, 53700); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.reserved, 0); + assign(test_msg_.obs[4].sid.sat, 12); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_c_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepC, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_c_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepC); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_c, sizeof(msg->obs_dep_c)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_c_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_c, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepC); + info.sender_id = 38982; + info.preamble = 0x55; + info.crc = 0x870; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 87; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_c_t &lesser, + const sbp_msg_obs_dep_c_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_c_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_c_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_c_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepC, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepC, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_c_t test_msg_{}; + uint8_t encoded_frame_[87 + 8] = { + 85, 73, 0, 70, 152, 87, 208, 95, 183, 24, 106, 7, 32, 44, 8, 74, + 80, 86, 93, 247, 255, 57, 158, 229, 229, 4, 0, 0, 0, 224, 229, 96, + 70, 156, 146, 250, 255, 221, 200, 20, 28, 6, 0, 0, 0, 60, 82, 62, + 77, 93, 58, 242, 255, 39, 164, 180, 178, 7, 0, 0, 0, 222, 73, 190, + 77, 46, 39, 13, 0, 202, 181, 233, 164, 10, 0, 0, 0, 149, 64, 9, + 75, 114, 191, 21, 0, 249, 182, 196, 209, 12, 0, 0, 0, 112, 8, + }; + uint8_t encoded_payload_[87] = { + 208, 95, 183, 24, 106, 7, 32, 44, 8, 74, 80, 86, 93, 247, 255, + 57, 158, 229, 229, 4, 0, 0, 0, 224, 229, 96, 70, 156, 146, 250, + 255, 221, 200, 20, 28, 6, 0, 0, 0, 60, 82, 62, 77, 93, 58, + 242, 255, 39, 164, 180, 178, 7, 0, 0, 0, 222, 73, 190, 77, 46, + 39, 13, 0, 202, 181, 233, 164, 10, 0, 0, 0, 149, 64, 9, 75, + 114, 191, 21, 0, 249, 182, 196, 209, 12, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_c_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepC, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepC, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + EXPECT_EQ( + sbp_msg_obs_dep_c_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + + for (uint8_t i = 0; i < 87; i++) { + EXPECT_EQ(sbp_msg_obs_dep_c_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepC, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + return sbp_msg_obs_dep_c_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_c_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_c_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_c_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_c_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepC, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.reserved, + greater.obs[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.reserved, + greater.obs[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.reserved, + greater.obs[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.reserved, + greater.obs[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.reserved, + greater.obs[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_c_t lesser = info.test_msg; + sbp_msg_obs_dep_c_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepC); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_C"); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_c_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_c_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_c, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_c, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[87]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 87); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 87), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_c_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 87); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepC, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgObsDepC4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepC, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgOsr.cc b/c/test/cpp/auto_check_sbp_observation_MsgOsr.cc index 40c5b4dd87..0f54b8076f 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgOsr.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgOsr.cc @@ -16,65 +16,491 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgOsr0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgOsr0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgOsr0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgOsr0() { + assign(test_msg_.header.n_obs, 64); + assign(test_msg_.header.t.ns_residual, 0); + assign(test_msg_.header.t.tow, 501867000); + assign(test_msg_.header.t.wn, 2152); + assign(test_msg_.n_obs, 12); + + assign(test_msg_.obs[0].L.f, 66); + assign(test_msg_.obs[0].L.i, 121567974); + assign(test_msg_.obs[0].P, 1156681547); + assign(test_msg_.obs[0].flags, 3); + assign(test_msg_.obs[0].iono_std, 13); + assign(test_msg_.obs[0].lock, 15); + assign(test_msg_.obs[0].range_std, 7); + assign(test_msg_.obs[0].sid.code, 0); + assign(test_msg_.obs[0].sid.sat, 1); + assign(test_msg_.obs[0].tropo_std, 7); + + assign(test_msg_.obs[1].L.f, 75); + assign(test_msg_.obs[1].L.i, 111817196); + assign(test_msg_.obs[1].P, 1063905486); + assign(test_msg_.obs[1].flags, 3); + assign(test_msg_.obs[1].iono_std, 13); + assign(test_msg_.obs[1].lock, 15); + assign(test_msg_.obs[1].range_std, 3); + assign(test_msg_.obs[1].sid.code, 0); + assign(test_msg_.obs[1].sid.sat, 13); + assign(test_msg_.obs[1].tropo_std, 3); + + assign(test_msg_.obs[2].L.f, 128); + assign(test_msg_.obs[2].L.i, 110692129); + assign(test_msg_.obs[2].P, 1053200685); + assign(test_msg_.obs[2].flags, 3); + assign(test_msg_.obs[2].iono_std, 13); + assign(test_msg_.obs[2].lock, 15); + assign(test_msg_.obs[2].range_std, 3); + assign(test_msg_.obs[2].sid.code, 0); + assign(test_msg_.obs[2].sid.sat, 14); + assign(test_msg_.obs[2].tropo_std, 3); + + assign(test_msg_.obs[3].L.f, 127); + assign(test_msg_.obs[3].L.i, 119549583); + assign(test_msg_.obs[3].P, 1137476697); + assign(test_msg_.obs[3].flags, 3); + assign(test_msg_.obs[3].iono_std, 13); + assign(test_msg_.obs[3].lock, 15); + assign(test_msg_.obs[3].range_std, 5); + assign(test_msg_.obs[3].sid.code, 0); + assign(test_msg_.obs[3].sid.sat, 15); + assign(test_msg_.obs[3].tropo_std, 5); + + assign(test_msg_.obs[4].L.f, 55); + assign(test_msg_.obs[4].L.i, 106934294); + assign(test_msg_.obs[4].P, 1017446132); + assign(test_msg_.obs[4].flags, 3); + assign(test_msg_.obs[4].iono_std, 0); + assign(test_msg_.obs[4].lock, 15); + assign(test_msg_.obs[4].range_std, 2); + assign(test_msg_.obs[4].sid.code, 0); + assign(test_msg_.obs[4].sid.sat, 17); + assign(test_msg_.obs[4].tropo_std, 2); + + assign(test_msg_.obs[5].L.f, 108); + assign(test_msg_.obs[5].L.i, 110024343); + assign(test_msg_.obs[5].P, 1046846826); + assign(test_msg_.obs[5].flags, 3); + assign(test_msg_.obs[5].iono_std, 13); + assign(test_msg_.obs[5].lock, 15); + assign(test_msg_.obs[5].range_std, 3); + assign(test_msg_.obs[5].sid.code, 0); + assign(test_msg_.obs[5].sid.sat, 19); + assign(test_msg_.obs[5].tropo_std, 3); + + assign(test_msg_.obs[6].L.f, 206); + assign(test_msg_.obs[6].L.i, 111507381); + assign(test_msg_.obs[6].P, 1060957521); + assign(test_msg_.obs[6].flags, 3); + assign(test_msg_.obs[6].iono_std, 13); + assign(test_msg_.obs[6].lock, 15); + assign(test_msg_.obs[6].range_std, 3); + assign(test_msg_.obs[6].sid.code, 0); + assign(test_msg_.obs[6].sid.sat, 28); + assign(test_msg_.obs[6].tropo_std, 3); + + assign(test_msg_.obs[7].L.f, 200); + assign(test_msg_.obs[7].L.i, 113614775); + assign(test_msg_.obs[7].P, 1081009286); + assign(test_msg_.obs[7].flags, 3); + assign(test_msg_.obs[7].iono_std, 13); + assign(test_msg_.obs[7].lock, 15); + assign(test_msg_.obs[7].range_std, 3); + assign(test_msg_.obs[7].sid.code, 0); + assign(test_msg_.obs[7].sid.sat, 30); + assign(test_msg_.obs[7].tropo_std, 3); + + assign(test_msg_.obs[8].L.f, 170); + assign(test_msg_.obs[8].L.i, 94728270); + assign(test_msg_.obs[8].P, 1156681781); + assign(test_msg_.obs[8].flags, 3); + assign(test_msg_.obs[8].iono_std, 21); + assign(test_msg_.obs[8].lock, 15); + assign(test_msg_.obs[8].range_std, 7); + assign(test_msg_.obs[8].sid.code, 6); + assign(test_msg_.obs[8].sid.sat, 1); + assign(test_msg_.obs[8].tropo_std, 7); + + assign(test_msg_.obs[9].L.f, 129); + assign(test_msg_.obs[9].L.i, 87130275); + assign(test_msg_.obs[9].P, 1063905531); + assign(test_msg_.obs[9].flags, 3); + assign(test_msg_.obs[9].iono_std, 21); + assign(test_msg_.obs[9].lock, 15); + assign(test_msg_.obs[9].range_std, 3); + assign(test_msg_.obs[9].sid.code, 6); + assign(test_msg_.obs[9].sid.sat, 13); + assign(test_msg_.obs[9].tropo_std, 3); + + assign(test_msg_.obs[10].L.f, 46); + assign(test_msg_.obs[10].L.i, 86253605); + assign(test_msg_.obs[10].P, 1053200752); + assign(test_msg_.obs[10].flags, 3); + assign(test_msg_.obs[10].iono_std, 21); + assign(test_msg_.obs[10].lock, 15); + assign(test_msg_.obs[10].range_std, 3); + assign(test_msg_.obs[10].sid.code, 6); + assign(test_msg_.obs[10].sid.sat, 14); + assign(test_msg_.obs[10].tropo_std, 3); + + assign(test_msg_.obs[11].L.f, 95); + assign(test_msg_.obs[11].L.i, 93155512); + assign(test_msg_.obs[11].P, 1137476774); + assign(test_msg_.obs[11].flags, 3); + assign(test_msg_.obs[11].iono_std, 21); + assign(test_msg_.obs[11].lock, 15); + assign(test_msg_.obs[11].range_std, 5); + assign(test_msg_.obs[11].sid.code, 6); + assign(test_msg_.obs[11].sid.sat, 15); + assign(test_msg_.obs[11].tropo_std, 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_osr_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, const sbp_msg_osr_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgOsr, &CHandler::callback_static, this, + &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_osr_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgOsr); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->osr, sizeof(msg->osr)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_osr_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.osr, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgOsr); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0xe379; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 239; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, const sbp_msg_osr_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_osr_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_osr_t &lesser, + const sbp_msg_osr_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_osr_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_osr_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_osr_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_osr_cmp(&greater, &lesser), 0); -TEST_F(Test_auto_check_sbp_observation_MsgOsr0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_message_cmp(SbpMsgOsr, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgOsr, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgOsr, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT(sbp_message_cmp(SbpMsgOsr, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_osr_t test_msg_{}; + uint8_t encoded_frame_[239 + 8] = { 85, 64, 6, 0, 0, 239, 248, 225, 233, 29, 0, 0, 0, 0, 104, 8, 64, 75, 143, 241, 68, 230, 250, 62, 7, 66, 15, 3, 1, 0, 13, 0, 7, 0, 7, 0, 206, 232, 105, 63, 236, 49, 170, 6, 75, @@ -93,531 +519,1175 @@ TEST_F(Test_auto_check_sbp_observation_MsgOsr0, Test) { 0, 166, 132, 204, 67, 184, 112, 141, 5, 95, 15, 3, 15, 6, 21, 0, 5, 0, 5, 0, 121, 227, }; + uint8_t encoded_payload_[239] = { + 248, 225, 233, 29, 0, 0, 0, 0, 104, 8, 64, 75, 143, 241, 68, + 230, 250, 62, 7, 66, 15, 3, 1, 0, 13, 0, 7, 0, 7, 0, + 206, 232, 105, 63, 236, 49, 170, 6, 75, 15, 3, 13, 0, 13, 0, + 3, 0, 3, 0, 45, 145, 198, 62, 33, 7, 153, 6, 128, 15, 3, + 14, 0, 13, 0, 3, 0, 3, 0, 89, 132, 204, 67, 143, 46, 32, + 7, 127, 15, 3, 15, 0, 13, 0, 5, 0, 5, 0, 244, 254, 164, + 60, 22, 176, 95, 6, 55, 15, 3, 17, 0, 0, 0, 2, 0, 2, + 0, 106, 157, 101, 62, 151, 214, 142, 6, 108, 15, 3, 19, 0, 13, + 0, 3, 0, 3, 0, 81, 237, 60, 63, 181, 119, 165, 6, 206, 15, + 3, 28, 0, 13, 0, 3, 0, 3, 0, 134, 228, 110, 64, 183, 159, + 197, 6, 200, 15, 3, 30, 0, 13, 0, 3, 0, 3, 0, 53, 144, + 241, 68, 78, 112, 165, 5, 170, 15, 3, 1, 6, 21, 0, 7, 0, + 7, 0, 251, 232, 105, 63, 163, 128, 49, 5, 129, 15, 3, 13, 6, + 21, 0, 3, 0, 3, 0, 112, 145, 198, 62, 37, 32, 36, 5, 46, + 15, 3, 14, 6, 21, 0, 3, 0, 3, 0, 166, 132, 204, 67, 184, + 112, 141, 5, 95, 15, 3, 15, 6, 21, 0, 5, 0, 5, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_osr_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgOsr, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[239]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_osr_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 239); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 239), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgOsr, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 239); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 239), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[239]; + + EXPECT_EQ(sbp_msg_osr_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 239), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgOsr0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[239]; + + for (uint8_t i = 0; i < 239; i++) { + EXPECT_EQ(sbp_msg_osr_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_osr_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_osr_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 239); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgOsr, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 239); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_osr_t msg{}; + + EXPECT_EQ(sbp_msg_osr_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgOsr0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_osr_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_osr_t t{}; + return sbp_msg_osr_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_osr_t t{}; + t.n_obs = 1; + return sbp_msg_osr_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_osr_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_osr_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOsr, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgOsr, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOsr, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.ns_residual, + greater.header.t.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].flags, greater.obs[0].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].iono_std, greater.obs[0].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].range_std, greater.obs[0].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.code, greater.obs[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].sid.sat, greater.obs[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].tropo_std, greater.obs[0].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].flags, greater.obs[1].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].iono_std, greater.obs[1].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].range_std, greater.obs[1].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.code, greater.obs[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].sid.sat, greater.obs[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].tropo_std, greater.obs[1].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].flags, greater.obs[2].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].iono_std, greater.obs[2].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].range_std, greater.obs[2].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.code, greater.obs[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].sid.sat, greater.obs[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].tropo_std, greater.obs[2].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].flags, greater.obs[3].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].iono_std, greater.obs[3].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].range_std, greater.obs[3].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.code, greater.obs[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].sid.sat, greater.obs[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].tropo_std, greater.obs[3].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].flags, greater.obs[4].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].iono_std, greater.obs[4].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].range_std, greater.obs[4].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.code, greater.obs[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].sid.sat, greater.obs[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].tropo_std, greater.obs[4].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].flags, greater.obs[5].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].iono_std, greater.obs[5].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].range_std, greater.obs[5].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.code, greater.obs[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].sid.sat, greater.obs[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].tropo_std, greater.obs[5].tropo_std); + comparison_tests(lesser, greater); + } - sbp_msg_osr_t test_msg{}; - test_msg.header.n_obs = 64; - test_msg.header.t.ns_residual = 0; - test_msg.header.t.tow = 501867000; - test_msg.header.t.wn = 2152; - test_msg.n_obs = 12; - - test_msg.obs[0].L.f = 66; - test_msg.obs[0].L.i = 121567974; - test_msg.obs[0].P = 1156681547; - test_msg.obs[0].flags = 3; - test_msg.obs[0].iono_std = 13; - test_msg.obs[0].lock = 15; - test_msg.obs[0].range_std = 7; - test_msg.obs[0].sid.code = 0; - test_msg.obs[0].sid.sat = 1; - test_msg.obs[0].tropo_std = 7; - - test_msg.obs[1].L.f = 75; - test_msg.obs[1].L.i = 111817196; - test_msg.obs[1].P = 1063905486; - test_msg.obs[1].flags = 3; - test_msg.obs[1].iono_std = 13; - test_msg.obs[1].lock = 15; - test_msg.obs[1].range_std = 3; - test_msg.obs[1].sid.code = 0; - test_msg.obs[1].sid.sat = 13; - test_msg.obs[1].tropo_std = 3; - - test_msg.obs[2].L.f = 128; - test_msg.obs[2].L.i = 110692129; - test_msg.obs[2].P = 1053200685; - test_msg.obs[2].flags = 3; - test_msg.obs[2].iono_std = 13; - test_msg.obs[2].lock = 15; - test_msg.obs[2].range_std = 3; - test_msg.obs[2].sid.code = 0; - test_msg.obs[2].sid.sat = 14; - test_msg.obs[2].tropo_std = 3; - - test_msg.obs[3].L.f = 127; - test_msg.obs[3].L.i = 119549583; - test_msg.obs[3].P = 1137476697; - test_msg.obs[3].flags = 3; - test_msg.obs[3].iono_std = 13; - test_msg.obs[3].lock = 15; - test_msg.obs[3].range_std = 5; - test_msg.obs[3].sid.code = 0; - test_msg.obs[3].sid.sat = 15; - test_msg.obs[3].tropo_std = 5; - - test_msg.obs[4].L.f = 55; - test_msg.obs[4].L.i = 106934294; - test_msg.obs[4].P = 1017446132; - test_msg.obs[4].flags = 3; - test_msg.obs[4].iono_std = 0; - test_msg.obs[4].lock = 15; - test_msg.obs[4].range_std = 2; - test_msg.obs[4].sid.code = 0; - test_msg.obs[4].sid.sat = 17; - test_msg.obs[4].tropo_std = 2; - - test_msg.obs[5].L.f = 108; - test_msg.obs[5].L.i = 110024343; - test_msg.obs[5].P = 1046846826; - test_msg.obs[5].flags = 3; - test_msg.obs[5].iono_std = 13; - test_msg.obs[5].lock = 15; - test_msg.obs[5].range_std = 3; - test_msg.obs[5].sid.code = 0; - test_msg.obs[5].sid.sat = 19; - test_msg.obs[5].tropo_std = 3; - - test_msg.obs[6].L.f = 206; - test_msg.obs[6].L.i = 111507381; - test_msg.obs[6].P = 1060957521; - test_msg.obs[6].flags = 3; - test_msg.obs[6].iono_std = 13; - test_msg.obs[6].lock = 15; - test_msg.obs[6].range_std = 3; - test_msg.obs[6].sid.code = 0; - test_msg.obs[6].sid.sat = 28; - test_msg.obs[6].tropo_std = 3; - - test_msg.obs[7].L.f = 200; - test_msg.obs[7].L.i = 113614775; - test_msg.obs[7].P = 1081009286; - test_msg.obs[7].flags = 3; - test_msg.obs[7].iono_std = 13; - test_msg.obs[7].lock = 15; - test_msg.obs[7].range_std = 3; - test_msg.obs[7].sid.code = 0; - test_msg.obs[7].sid.sat = 30; - test_msg.obs[7].tropo_std = 3; - - test_msg.obs[8].L.f = 170; - test_msg.obs[8].L.i = 94728270; - test_msg.obs[8].P = 1156681781; - test_msg.obs[8].flags = 3; - test_msg.obs[8].iono_std = 21; - test_msg.obs[8].lock = 15; - test_msg.obs[8].range_std = 7; - test_msg.obs[8].sid.code = 6; - test_msg.obs[8].sid.sat = 1; - test_msg.obs[8].tropo_std = 7; - - test_msg.obs[9].L.f = 129; - test_msg.obs[9].L.i = 87130275; - test_msg.obs[9].P = 1063905531; - test_msg.obs[9].flags = 3; - test_msg.obs[9].iono_std = 21; - test_msg.obs[9].lock = 15; - test_msg.obs[9].range_std = 3; - test_msg.obs[9].sid.code = 6; - test_msg.obs[9].sid.sat = 13; - test_msg.obs[9].tropo_std = 3; - - test_msg.obs[10].L.f = 46; - test_msg.obs[10].L.i = 86253605; - test_msg.obs[10].P = 1053200752; - test_msg.obs[10].flags = 3; - test_msg.obs[10].iono_std = 21; - test_msg.obs[10].lock = 15; - test_msg.obs[10].range_std = 3; - test_msg.obs[10].sid.code = 6; - test_msg.obs[10].sid.sat = 14; - test_msg.obs[10].tropo_std = 3; - - test_msg.obs[11].L.f = 95; - test_msg.obs[11].L.i = 93155512; - test_msg.obs[11].P = 1137476774; - test_msg.obs[11].flags = 3; - test_msg.obs[11].iono_std = 21; - test_msg.obs[11].lock = 15; - test_msg.obs[11].range_std = 5; - test_msg.obs[11].sid.code = 6; - test_msg.obs[11].sid.sat = 15; - test_msg.obs[11].tropo_std = 5; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 64) - << "incorrect value for last_msg_.header.n_obs, expected 64, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.ns_residual, 0) - << "incorrect value for last_msg_.header.t.ns_residual, expected 0, is " - << last_msg_.header.t.ns_residual; - EXPECT_EQ(last_msg_.header.t.tow, 501867000) - << "incorrect value for last_msg_.header.t.tow, expected 501867000, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 2152) - << "incorrect value for last_msg_.header.t.wn, expected 2152, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 12) - << "incorrect value for last_msg_.n_obs, expected 12, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 66) - << "incorrect value for last_msg_.obs[0].L.f, expected 66, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 121567974) - << "incorrect value for last_msg_.obs[0].L.i, expected 121567974, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1156681547) - << "incorrect value for last_msg_.obs[0].P, expected 1156681547, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].flags, 3) - << "incorrect value for last_msg_.obs[0].flags, expected 3, is " - << last_msg_.obs[0].flags; - EXPECT_EQ(last_msg_.obs[0].iono_std, 13) - << "incorrect value for last_msg_.obs[0].iono_std, expected 13, is " - << last_msg_.obs[0].iono_std; - EXPECT_EQ(last_msg_.obs[0].lock, 15) - << "incorrect value for last_msg_.obs[0].lock, expected 15, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].range_std, 7) - << "incorrect value for last_msg_.obs[0].range_std, expected 7, is " - << last_msg_.obs[0].range_std; - EXPECT_EQ(last_msg_.obs[0].sid.code, 0) - << "incorrect value for last_msg_.obs[0].sid.code, expected 0, is " - << last_msg_.obs[0].sid.code; - EXPECT_EQ(last_msg_.obs[0].sid.sat, 1) - << "incorrect value for last_msg_.obs[0].sid.sat, expected 1, is " - << last_msg_.obs[0].sid.sat; - EXPECT_EQ(last_msg_.obs[0].tropo_std, 7) - << "incorrect value for last_msg_.obs[0].tropo_std, expected 7, is " - << last_msg_.obs[0].tropo_std; - EXPECT_EQ(last_msg_.obs[1].L.f, 75) - << "incorrect value for last_msg_.obs[1].L.f, expected 75, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 111817196) - << "incorrect value for last_msg_.obs[1].L.i, expected 111817196, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 1063905486) - << "incorrect value for last_msg_.obs[1].P, expected 1063905486, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].flags, 3) - << "incorrect value for last_msg_.obs[1].flags, expected 3, is " - << last_msg_.obs[1].flags; - EXPECT_EQ(last_msg_.obs[1].iono_std, 13) - << "incorrect value for last_msg_.obs[1].iono_std, expected 13, is " - << last_msg_.obs[1].iono_std; - EXPECT_EQ(last_msg_.obs[1].lock, 15) - << "incorrect value for last_msg_.obs[1].lock, expected 15, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].range_std, 3) - << "incorrect value for last_msg_.obs[1].range_std, expected 3, is " - << last_msg_.obs[1].range_std; - EXPECT_EQ(last_msg_.obs[1].sid.code, 0) - << "incorrect value for last_msg_.obs[1].sid.code, expected 0, is " - << last_msg_.obs[1].sid.code; - EXPECT_EQ(last_msg_.obs[1].sid.sat, 13) - << "incorrect value for last_msg_.obs[1].sid.sat, expected 13, is " - << last_msg_.obs[1].sid.sat; - EXPECT_EQ(last_msg_.obs[1].tropo_std, 3) - << "incorrect value for last_msg_.obs[1].tropo_std, expected 3, is " - << last_msg_.obs[1].tropo_std; - EXPECT_EQ(last_msg_.obs[2].L.f, 128) - << "incorrect value for last_msg_.obs[2].L.f, expected 128, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, 110692129) - << "incorrect value for last_msg_.obs[2].L.i, expected 110692129, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 1053200685) - << "incorrect value for last_msg_.obs[2].P, expected 1053200685, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].flags, 3) - << "incorrect value for last_msg_.obs[2].flags, expected 3, is " - << last_msg_.obs[2].flags; - EXPECT_EQ(last_msg_.obs[2].iono_std, 13) - << "incorrect value for last_msg_.obs[2].iono_std, expected 13, is " - << last_msg_.obs[2].iono_std; - EXPECT_EQ(last_msg_.obs[2].lock, 15) - << "incorrect value for last_msg_.obs[2].lock, expected 15, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].range_std, 3) - << "incorrect value for last_msg_.obs[2].range_std, expected 3, is " - << last_msg_.obs[2].range_std; - EXPECT_EQ(last_msg_.obs[2].sid.code, 0) - << "incorrect value for last_msg_.obs[2].sid.code, expected 0, is " - << last_msg_.obs[2].sid.code; - EXPECT_EQ(last_msg_.obs[2].sid.sat, 14) - << "incorrect value for last_msg_.obs[2].sid.sat, expected 14, is " - << last_msg_.obs[2].sid.sat; - EXPECT_EQ(last_msg_.obs[2].tropo_std, 3) - << "incorrect value for last_msg_.obs[2].tropo_std, expected 3, is " - << last_msg_.obs[2].tropo_std; - EXPECT_EQ(last_msg_.obs[3].L.f, 127) - << "incorrect value for last_msg_.obs[3].L.f, expected 127, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 119549583) - << "incorrect value for last_msg_.obs[3].L.i, expected 119549583, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 1137476697) - << "incorrect value for last_msg_.obs[3].P, expected 1137476697, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].flags, 3) - << "incorrect value for last_msg_.obs[3].flags, expected 3, is " - << last_msg_.obs[3].flags; - EXPECT_EQ(last_msg_.obs[3].iono_std, 13) - << "incorrect value for last_msg_.obs[3].iono_std, expected 13, is " - << last_msg_.obs[3].iono_std; - EXPECT_EQ(last_msg_.obs[3].lock, 15) - << "incorrect value for last_msg_.obs[3].lock, expected 15, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].range_std, 5) - << "incorrect value for last_msg_.obs[3].range_std, expected 5, is " - << last_msg_.obs[3].range_std; - EXPECT_EQ(last_msg_.obs[3].sid.code, 0) - << "incorrect value for last_msg_.obs[3].sid.code, expected 0, is " - << last_msg_.obs[3].sid.code; - EXPECT_EQ(last_msg_.obs[3].sid.sat, 15) - << "incorrect value for last_msg_.obs[3].sid.sat, expected 15, is " - << last_msg_.obs[3].sid.sat; - EXPECT_EQ(last_msg_.obs[3].tropo_std, 5) - << "incorrect value for last_msg_.obs[3].tropo_std, expected 5, is " - << last_msg_.obs[3].tropo_std; - EXPECT_EQ(last_msg_.obs[4].L.f, 55) - << "incorrect value for last_msg_.obs[4].L.f, expected 55, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, 106934294) - << "incorrect value for last_msg_.obs[4].L.i, expected 106934294, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1017446132) - << "incorrect value for last_msg_.obs[4].P, expected 1017446132, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].flags, 3) - << "incorrect value for last_msg_.obs[4].flags, expected 3, is " - << last_msg_.obs[4].flags; - EXPECT_EQ(last_msg_.obs[4].iono_std, 0) - << "incorrect value for last_msg_.obs[4].iono_std, expected 0, is " - << last_msg_.obs[4].iono_std; - EXPECT_EQ(last_msg_.obs[4].lock, 15) - << "incorrect value for last_msg_.obs[4].lock, expected 15, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].range_std, 2) - << "incorrect value for last_msg_.obs[4].range_std, expected 2, is " - << last_msg_.obs[4].range_std; - EXPECT_EQ(last_msg_.obs[4].sid.code, 0) - << "incorrect value for last_msg_.obs[4].sid.code, expected 0, is " - << last_msg_.obs[4].sid.code; - EXPECT_EQ(last_msg_.obs[4].sid.sat, 17) - << "incorrect value for last_msg_.obs[4].sid.sat, expected 17, is " - << last_msg_.obs[4].sid.sat; - EXPECT_EQ(last_msg_.obs[4].tropo_std, 2) - << "incorrect value for last_msg_.obs[4].tropo_std, expected 2, is " - << last_msg_.obs[4].tropo_std; - EXPECT_EQ(last_msg_.obs[5].L.f, 108) - << "incorrect value for last_msg_.obs[5].L.f, expected 108, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 110024343) - << "incorrect value for last_msg_.obs[5].L.i, expected 110024343, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 1046846826) - << "incorrect value for last_msg_.obs[5].P, expected 1046846826, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].flags, 3) - << "incorrect value for last_msg_.obs[5].flags, expected 3, is " - << last_msg_.obs[5].flags; - EXPECT_EQ(last_msg_.obs[5].iono_std, 13) - << "incorrect value for last_msg_.obs[5].iono_std, expected 13, is " - << last_msg_.obs[5].iono_std; - EXPECT_EQ(last_msg_.obs[5].lock, 15) - << "incorrect value for last_msg_.obs[5].lock, expected 15, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].range_std, 3) - << "incorrect value for last_msg_.obs[5].range_std, expected 3, is " - << last_msg_.obs[5].range_std; - EXPECT_EQ(last_msg_.obs[5].sid.code, 0) - << "incorrect value for last_msg_.obs[5].sid.code, expected 0, is " - << last_msg_.obs[5].sid.code; - EXPECT_EQ(last_msg_.obs[5].sid.sat, 19) - << "incorrect value for last_msg_.obs[5].sid.sat, expected 19, is " - << last_msg_.obs[5].sid.sat; - EXPECT_EQ(last_msg_.obs[5].tropo_std, 3) - << "incorrect value for last_msg_.obs[5].tropo_std, expected 3, is " - << last_msg_.obs[5].tropo_std; - EXPECT_EQ(last_msg_.obs[6].L.f, 206) - << "incorrect value for last_msg_.obs[6].L.f, expected 206, is " - << last_msg_.obs[6].L.f; - EXPECT_EQ(last_msg_.obs[6].L.i, 111507381) - << "incorrect value for last_msg_.obs[6].L.i, expected 111507381, is " - << last_msg_.obs[6].L.i; - EXPECT_EQ(last_msg_.obs[6].P, 1060957521) - << "incorrect value for last_msg_.obs[6].P, expected 1060957521, is " - << last_msg_.obs[6].P; - EXPECT_EQ(last_msg_.obs[6].flags, 3) - << "incorrect value for last_msg_.obs[6].flags, expected 3, is " - << last_msg_.obs[6].flags; - EXPECT_EQ(last_msg_.obs[6].iono_std, 13) - << "incorrect value for last_msg_.obs[6].iono_std, expected 13, is " - << last_msg_.obs[6].iono_std; - EXPECT_EQ(last_msg_.obs[6].lock, 15) - << "incorrect value for last_msg_.obs[6].lock, expected 15, is " - << last_msg_.obs[6].lock; - EXPECT_EQ(last_msg_.obs[6].range_std, 3) - << "incorrect value for last_msg_.obs[6].range_std, expected 3, is " - << last_msg_.obs[6].range_std; - EXPECT_EQ(last_msg_.obs[6].sid.code, 0) - << "incorrect value for last_msg_.obs[6].sid.code, expected 0, is " - << last_msg_.obs[6].sid.code; - EXPECT_EQ(last_msg_.obs[6].sid.sat, 28) - << "incorrect value for last_msg_.obs[6].sid.sat, expected 28, is " - << last_msg_.obs[6].sid.sat; - EXPECT_EQ(last_msg_.obs[6].tropo_std, 3) - << "incorrect value for last_msg_.obs[6].tropo_std, expected 3, is " - << last_msg_.obs[6].tropo_std; - EXPECT_EQ(last_msg_.obs[7].L.f, 200) - << "incorrect value for last_msg_.obs[7].L.f, expected 200, is " - << last_msg_.obs[7].L.f; - EXPECT_EQ(last_msg_.obs[7].L.i, 113614775) - << "incorrect value for last_msg_.obs[7].L.i, expected 113614775, is " - << last_msg_.obs[7].L.i; - EXPECT_EQ(last_msg_.obs[7].P, 1081009286) - << "incorrect value for last_msg_.obs[7].P, expected 1081009286, is " - << last_msg_.obs[7].P; - EXPECT_EQ(last_msg_.obs[7].flags, 3) - << "incorrect value for last_msg_.obs[7].flags, expected 3, is " - << last_msg_.obs[7].flags; - EXPECT_EQ(last_msg_.obs[7].iono_std, 13) - << "incorrect value for last_msg_.obs[7].iono_std, expected 13, is " - << last_msg_.obs[7].iono_std; - EXPECT_EQ(last_msg_.obs[7].lock, 15) - << "incorrect value for last_msg_.obs[7].lock, expected 15, is " - << last_msg_.obs[7].lock; - EXPECT_EQ(last_msg_.obs[7].range_std, 3) - << "incorrect value for last_msg_.obs[7].range_std, expected 3, is " - << last_msg_.obs[7].range_std; - EXPECT_EQ(last_msg_.obs[7].sid.code, 0) - << "incorrect value for last_msg_.obs[7].sid.code, expected 0, is " - << last_msg_.obs[7].sid.code; - EXPECT_EQ(last_msg_.obs[7].sid.sat, 30) - << "incorrect value for last_msg_.obs[7].sid.sat, expected 30, is " - << last_msg_.obs[7].sid.sat; - EXPECT_EQ(last_msg_.obs[7].tropo_std, 3) - << "incorrect value for last_msg_.obs[7].tropo_std, expected 3, is " - << last_msg_.obs[7].tropo_std; - EXPECT_EQ(last_msg_.obs[8].L.f, 170) - << "incorrect value for last_msg_.obs[8].L.f, expected 170, is " - << last_msg_.obs[8].L.f; - EXPECT_EQ(last_msg_.obs[8].L.i, 94728270) - << "incorrect value for last_msg_.obs[8].L.i, expected 94728270, is " - << last_msg_.obs[8].L.i; - EXPECT_EQ(last_msg_.obs[8].P, 1156681781) - << "incorrect value for last_msg_.obs[8].P, expected 1156681781, is " - << last_msg_.obs[8].P; - EXPECT_EQ(last_msg_.obs[8].flags, 3) - << "incorrect value for last_msg_.obs[8].flags, expected 3, is " - << last_msg_.obs[8].flags; - EXPECT_EQ(last_msg_.obs[8].iono_std, 21) - << "incorrect value for last_msg_.obs[8].iono_std, expected 21, is " - << last_msg_.obs[8].iono_std; - EXPECT_EQ(last_msg_.obs[8].lock, 15) - << "incorrect value for last_msg_.obs[8].lock, expected 15, is " - << last_msg_.obs[8].lock; - EXPECT_EQ(last_msg_.obs[8].range_std, 7) - << "incorrect value for last_msg_.obs[8].range_std, expected 7, is " - << last_msg_.obs[8].range_std; - EXPECT_EQ(last_msg_.obs[8].sid.code, 6) - << "incorrect value for last_msg_.obs[8].sid.code, expected 6, is " - << last_msg_.obs[8].sid.code; - EXPECT_EQ(last_msg_.obs[8].sid.sat, 1) - << "incorrect value for last_msg_.obs[8].sid.sat, expected 1, is " - << last_msg_.obs[8].sid.sat; - EXPECT_EQ(last_msg_.obs[8].tropo_std, 7) - << "incorrect value for last_msg_.obs[8].tropo_std, expected 7, is " - << last_msg_.obs[8].tropo_std; - EXPECT_EQ(last_msg_.obs[9].L.f, 129) - << "incorrect value for last_msg_.obs[9].L.f, expected 129, is " - << last_msg_.obs[9].L.f; - EXPECT_EQ(last_msg_.obs[9].L.i, 87130275) - << "incorrect value for last_msg_.obs[9].L.i, expected 87130275, is " - << last_msg_.obs[9].L.i; - EXPECT_EQ(last_msg_.obs[9].P, 1063905531) - << "incorrect value for last_msg_.obs[9].P, expected 1063905531, is " - << last_msg_.obs[9].P; - EXPECT_EQ(last_msg_.obs[9].flags, 3) - << "incorrect value for last_msg_.obs[9].flags, expected 3, is " - << last_msg_.obs[9].flags; - EXPECT_EQ(last_msg_.obs[9].iono_std, 21) - << "incorrect value for last_msg_.obs[9].iono_std, expected 21, is " - << last_msg_.obs[9].iono_std; - EXPECT_EQ(last_msg_.obs[9].lock, 15) - << "incorrect value for last_msg_.obs[9].lock, expected 15, is " - << last_msg_.obs[9].lock; - EXPECT_EQ(last_msg_.obs[9].range_std, 3) - << "incorrect value for last_msg_.obs[9].range_std, expected 3, is " - << last_msg_.obs[9].range_std; - EXPECT_EQ(last_msg_.obs[9].sid.code, 6) - << "incorrect value for last_msg_.obs[9].sid.code, expected 6, is " - << last_msg_.obs[9].sid.code; - EXPECT_EQ(last_msg_.obs[9].sid.sat, 13) - << "incorrect value for last_msg_.obs[9].sid.sat, expected 13, is " - << last_msg_.obs[9].sid.sat; - EXPECT_EQ(last_msg_.obs[9].tropo_std, 3) - << "incorrect value for last_msg_.obs[9].tropo_std, expected 3, is " - << last_msg_.obs[9].tropo_std; - EXPECT_EQ(last_msg_.obs[10].L.f, 46) - << "incorrect value for last_msg_.obs[10].L.f, expected 46, is " - << last_msg_.obs[10].L.f; - EXPECT_EQ(last_msg_.obs[10].L.i, 86253605) - << "incorrect value for last_msg_.obs[10].L.i, expected 86253605, is " - << last_msg_.obs[10].L.i; - EXPECT_EQ(last_msg_.obs[10].P, 1053200752) - << "incorrect value for last_msg_.obs[10].P, expected 1053200752, is " - << last_msg_.obs[10].P; - EXPECT_EQ(last_msg_.obs[10].flags, 3) - << "incorrect value for last_msg_.obs[10].flags, expected 3, is " - << last_msg_.obs[10].flags; - EXPECT_EQ(last_msg_.obs[10].iono_std, 21) - << "incorrect value for last_msg_.obs[10].iono_std, expected 21, is " - << last_msg_.obs[10].iono_std; - EXPECT_EQ(last_msg_.obs[10].lock, 15) - << "incorrect value for last_msg_.obs[10].lock, expected 15, is " - << last_msg_.obs[10].lock; - EXPECT_EQ(last_msg_.obs[10].range_std, 3) - << "incorrect value for last_msg_.obs[10].range_std, expected 3, is " - << last_msg_.obs[10].range_std; - EXPECT_EQ(last_msg_.obs[10].sid.code, 6) - << "incorrect value for last_msg_.obs[10].sid.code, expected 6, is " - << last_msg_.obs[10].sid.code; - EXPECT_EQ(last_msg_.obs[10].sid.sat, 14) - << "incorrect value for last_msg_.obs[10].sid.sat, expected 14, is " - << last_msg_.obs[10].sid.sat; - EXPECT_EQ(last_msg_.obs[10].tropo_std, 3) - << "incorrect value for last_msg_.obs[10].tropo_std, expected 3, is " - << last_msg_.obs[10].tropo_std; - EXPECT_EQ(last_msg_.obs[11].L.f, 95) - << "incorrect value for last_msg_.obs[11].L.f, expected 95, is " - << last_msg_.obs[11].L.f; - EXPECT_EQ(last_msg_.obs[11].L.i, 93155512) - << "incorrect value for last_msg_.obs[11].L.i, expected 93155512, is " - << last_msg_.obs[11].L.i; - EXPECT_EQ(last_msg_.obs[11].P, 1137476774) - << "incorrect value for last_msg_.obs[11].P, expected 1137476774, is " - << last_msg_.obs[11].P; - EXPECT_EQ(last_msg_.obs[11].flags, 3) - << "incorrect value for last_msg_.obs[11].flags, expected 3, is " - << last_msg_.obs[11].flags; - EXPECT_EQ(last_msg_.obs[11].iono_std, 21) - << "incorrect value for last_msg_.obs[11].iono_std, expected 21, is " - << last_msg_.obs[11].iono_std; - EXPECT_EQ(last_msg_.obs[11].lock, 15) - << "incorrect value for last_msg_.obs[11].lock, expected 15, is " - << last_msg_.obs[11].lock; - EXPECT_EQ(last_msg_.obs[11].range_std, 5) - << "incorrect value for last_msg_.obs[11].range_std, expected 5, is " - << last_msg_.obs[11].range_std; - EXPECT_EQ(last_msg_.obs[11].sid.code, 6) - << "incorrect value for last_msg_.obs[11].sid.code, expected 6, is " - << last_msg_.obs[11].sid.code; - EXPECT_EQ(last_msg_.obs[11].sid.sat, 15) - << "incorrect value for last_msg_.obs[11].sid.sat, expected 15, is " - << last_msg_.obs[11].sid.sat; - EXPECT_EQ(last_msg_.obs[11].tropo_std, 5) - << "incorrect value for last_msg_.obs[11].tropo_std, expected 5, is " - << last_msg_.obs[11].tropo_std; + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.f, greater.obs[6].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.i, greater.obs[6].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].P, greater.obs[6].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].flags, greater.obs[6].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].iono_std, greater.obs[6].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].lock, greater.obs[6].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].range_std, greater.obs[6].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].sid.code, greater.obs[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].sid.sat, greater.obs[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].tropo_std, greater.obs[6].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].L.f, greater.obs[7].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].L.i, greater.obs[7].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].P, greater.obs[7].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].flags, greater.obs[7].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].iono_std, greater.obs[7].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].lock, greater.obs[7].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].range_std, greater.obs[7].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].sid.code, greater.obs[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].sid.sat, greater.obs[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[7].tropo_std, greater.obs[7].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].L.f, greater.obs[8].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].L.i, greater.obs[8].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].P, greater.obs[8].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].flags, greater.obs[8].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].iono_std, greater.obs[8].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].lock, greater.obs[8].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].range_std, greater.obs[8].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].sid.code, greater.obs[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].sid.sat, greater.obs[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[8].tropo_std, greater.obs[8].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].L.f, greater.obs[9].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].L.i, greater.obs[9].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].P, greater.obs[9].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].flags, greater.obs[9].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].iono_std, greater.obs[9].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].lock, greater.obs[9].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].range_std, greater.obs[9].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].sid.code, greater.obs[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].sid.sat, greater.obs[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[9].tropo_std, greater.obs[9].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].L.f, greater.obs[10].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].L.i, greater.obs[10].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].P, greater.obs[10].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].flags, greater.obs[10].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].iono_std, greater.obs[10].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].lock, greater.obs[10].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].range_std, greater.obs[10].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].sid.code, greater.obs[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].sid.sat, greater.obs[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[10].tropo_std, greater.obs[10].tropo_std); + comparison_tests(lesser, greater); + } + + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].L.f, greater.obs[11].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].L.i, greater.obs[11].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].P, greater.obs[11].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].flags, greater.obs[11].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].iono_std, greater.obs[11].iono_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].lock, greater.obs[11].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].range_std, greater.obs[11].range_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].sid.code, greater.obs[11].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].sid.sat, greater.obs[11].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_osr_t lesser = info.test_msg; + sbp_msg_osr_t greater = info.test_msg; + make_lesser_greater(lesser.obs[11].tropo_std, greater.obs[11].tropo_std); + comparison_tests(lesser, greater); + } } + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgOsr); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OSR"); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_osr_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_osr_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.osr, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.osr, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[239]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 239); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 239), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_osr_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 239); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgOsr, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgOsr0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgOsr, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgSvAzEl.cc b/c/test/cpp/auto_check_sbp_observation_MsgSvAzEl.cc index c436c4012b..1182cd79ee 100644 --- a/c/test/cpp/auto_check_sbp_observation_MsgSvAzEl.cc +++ b/c/test/cpp/auto_check_sbp_observation_MsgSvAzEl.cc @@ -16,66 +16,523 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_MsgSvAzEl0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgSvAzEl0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_MsgSvAzEl0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_MsgSvAzEl0() { + assign(test_msg_.azel[0].az, 160); + assign(test_msg_.azel[0].el, 12); + assign(test_msg_.azel[0].sid.code, 0); + assign(test_msg_.azel[0].sid.sat, 8); + + assign(test_msg_.azel[1].az, 139); + assign(test_msg_.azel[1].el, 66); + assign(test_msg_.azel[1].sid.code, 0); + assign(test_msg_.azel[1].sid.sat, 10); + + assign(test_msg_.azel[2].az, 16); + assign(test_msg_.azel[2].el, 1); + assign(test_msg_.azel[2].sid.code, 0); + assign(test_msg_.azel[2].sid.sat, 13); + + assign(test_msg_.azel[3].az, 24); + assign(test_msg_.azel[3].el, 25); + assign(test_msg_.azel[3].sid.code, 0); + assign(test_msg_.azel[3].sid.sat, 15); + + assign(test_msg_.azel[4].az, 127); + assign(test_msg_.azel[4].el, 18); + assign(test_msg_.azel[4].sid.code, 0); + assign(test_msg_.azel[4].sid.sat, 16); + + assign(test_msg_.azel[5].az, 42); + assign(test_msg_.azel[5].el, 53); + assign(test_msg_.azel[5].sid.code, 0); + assign(test_msg_.azel[5].sid.sat, 18); + + assign(test_msg_.azel[6].az, 31); + assign(test_msg_.azel[6].el, 16); + assign(test_msg_.azel[6].sid.code, 0); + assign(test_msg_.azel[6].sid.sat, 20); + + assign(test_msg_.azel[7].az, 12); + assign(test_msg_.azel[7].el, 67); + assign(test_msg_.azel[7].sid.code, 0); + assign(test_msg_.azel[7].sid.sat, 23); + + assign(test_msg_.azel[8].az, 47); + assign(test_msg_.azel[8].el, 10); + assign(test_msg_.azel[8].sid.code, 0); + assign(test_msg_.azel[8].sid.sat, 24); + + assign(test_msg_.azel[9].az, 116); + assign(test_msg_.azel[9].el, 8); + assign(test_msg_.azel[9].sid.code, 0); + assign(test_msg_.azel[9].sid.sat, 26); + + assign(test_msg_.azel[10].az, 153); + assign(test_msg_.azel[10].el, 43); + assign(test_msg_.azel[10].sid.code, 0); + assign(test_msg_.azel[10].sid.sat, 27); + + assign(test_msg_.azel[11].az, 77); + assign(test_msg_.azel[11].el, 10); + assign(test_msg_.azel[11].sid.code, 0); + assign(test_msg_.azel[11].sid.sat, 29); + + assign(test_msg_.azel[12].az, 94); + assign(test_msg_.azel[12].el, 26); + assign(test_msg_.azel[12].sid.code, 0); + assign(test_msg_.azel[12].sid.sat, 32); + + assign(test_msg_.azel[13].az, 16); + assign(test_msg_.azel[13].el, 58); + assign(test_msg_.azel[13].sid.code, 3); + assign(test_msg_.azel[13].sid.sat, 1); + + assign(test_msg_.azel[14].az, 108); + assign(test_msg_.azel[14].el, 53); + assign(test_msg_.azel[14].sid.code, 3); + assign(test_msg_.azel[14].sid.sat, 2); + + assign(test_msg_.azel[15].az, 17); + assign(test_msg_.azel[15].el, 13); + assign(test_msg_.azel[15].sid.code, 3); + assign(test_msg_.azel[15].sid.sat, 8); + + assign(test_msg_.azel[16].az, 165); + assign(test_msg_.azel[16].el, 40); + assign(test_msg_.azel[16].sid.code, 3); + assign(test_msg_.azel[16].sid.sat, 17); + + assign(test_msg_.azel[17].az, 63); + assign(test_msg_.azel[17].el, 35); + assign(test_msg_.azel[17].sid.code, 3); + assign(test_msg_.azel[17].sid.sat, 23); + + assign(test_msg_.azel[18].az, 41); + assign(test_msg_.azel[18].el, 73); + assign(test_msg_.azel[18].sid.code, 3); + assign(test_msg_.azel[18].sid.sat, 24); + + assign(test_msg_.azel[19].az, 114); + assign(test_msg_.azel[19].el, 26); + assign(test_msg_.azel[19].sid.code, 12); + assign(test_msg_.azel[19].sid.sat, 20); + + assign(test_msg_.azel[20].az, 72); + assign(test_msg_.azel[20].el, 54); + assign(test_msg_.azel[20].sid.code, 12); + assign(test_msg_.azel[20].sid.sat, 27); + + assign(test_msg_.azel[21].az, 69); + assign(test_msg_.azel[21].el, 3); + assign(test_msg_.azel[21].sid.code, 12); + assign(test_msg_.azel[21].sid.sat, 28); + + assign(test_msg_.azel[22].az, 158); + assign(test_msg_.azel[22].el, 14); + assign(test_msg_.azel[22].sid.code, 12); + assign(test_msg_.azel[22].sid.sat, 29); + + assign(test_msg_.azel[23].az, 152); + assign(test_msg_.azel[23].el, 68); + assign(test_msg_.azel[23].sid.code, 12); + assign(test_msg_.azel[23].sid.sat, 30); + + assign(test_msg_.azel[24].az, 120); + assign(test_msg_.azel[24].el, 82); + assign(test_msg_.azel[24].sid.code, 12); + assign(test_msg_.azel[24].sid.sat, 32); + + assign(test_msg_.azel[25].az, 131); + assign(test_msg_.azel[25].el, 6); + assign(test_msg_.azel[25].sid.code, 14); + assign(test_msg_.azel[25].sid.sat, 2); + + assign(test_msg_.azel[26].az, 27); + assign(test_msg_.azel[26].el, 44); + assign(test_msg_.azel[26].sid.code, 14); + assign(test_msg_.azel[26].sid.sat, 4); + + assign(test_msg_.azel[27].az, 101); + assign(test_msg_.azel[27].el, 21); + assign(test_msg_.azel[27].sid.code, 14); + assign(test_msg_.azel[27].sid.sat, 5); + + assign(test_msg_.azel[28].az, 81); + assign(test_msg_.azel[28].el, 65); + assign(test_msg_.azel[28].sid.code, 14); + assign(test_msg_.azel[28].sid.sat, 9); + + assign(test_msg_.azel[29].az, 49); + assign(test_msg_.azel[29].el, 56); + assign(test_msg_.azel[29].sid.code, 14); + assign(test_msg_.azel[29].sid.sat, 11); + + assign(test_msg_.azel[30].az, 59); + assign(test_msg_.azel[30].el, 6); + assign(test_msg_.azel[30].sid.code, 14); + assign(test_msg_.azel[30].sid.sat, 12); + + assign(test_msg_.azel[31].az, 154); + assign(test_msg_.azel[31].el, 4); + assign(test_msg_.azel[31].sid.code, 14); + assign(test_msg_.azel[31].sid.sat, 30); + + assign(test_msg_.azel[32].az, 165); + assign(test_msg_.azel[32].el, 62); + assign(test_msg_.azel[32].sid.code, 14); + assign(test_msg_.azel[32].sid.sat, 36); + assign(test_msg_.n_azel, 33); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_sv_az_el_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_sv_az_el_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSvAzEl, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_sv_az_el_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSvAzEl); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->sv_az_el, sizeof(msg->sv_az_el)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_sv_az_el_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.sv_az_el, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSvAzEl); + info.sender_id = 31183; + info.preamble = 0x55; + info.crc = 0x24A8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 132; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_sv_az_el_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_sv_az_el_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_sv_az_el_t &lesser, + const sbp_msg_sv_az_el_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_sv_az_el_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_sv_az_el_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_sv_az_el_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_sv_az_el_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSvAzEl, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSvAzEl, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSvAzEl, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSvAzEl, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_MsgSvAzEl0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_sv_az_el_t test_msg_{}; + uint8_t encoded_frame_[132 + 8] = { 85, 151, 0, 207, 121, 132, 8, 0, 160, 12, 10, 0, 139, 66, 13, 0, 16, 1, 15, 0, 24, 25, 16, 0, 127, 18, 18, 0, 42, 53, 20, 0, 31, 16, 23, 0, 12, 67, 24, 0, 47, 10, 26, 0, 116, 8, 27, 0, @@ -86,584 +543,1242 @@ TEST_F(Test_auto_check_sbp_observation_MsgSvAzEl0, Test) { 27, 44, 5, 14, 101, 21, 9, 14, 81, 65, 11, 14, 49, 56, 12, 14, 59, 6, 30, 14, 154, 4, 36, 14, 165, 62, 168, 36, }; + uint8_t encoded_payload_[132] = { + 8, 0, 160, 12, 10, 0, 139, 66, 13, 0, 16, 1, 15, 0, 24, + 25, 16, 0, 127, 18, 18, 0, 42, 53, 20, 0, 31, 16, 23, 0, + 12, 67, 24, 0, 47, 10, 26, 0, 116, 8, 27, 0, 153, 43, 29, + 0, 77, 10, 32, 0, 94, 26, 1, 3, 16, 58, 2, 3, 108, 53, + 8, 3, 17, 13, 17, 3, 165, 40, 23, 3, 63, 35, 24, 3, 41, + 73, 20, 12, 114, 26, 27, 12, 72, 54, 28, 12, 69, 3, 29, 12, + 158, 14, 30, 12, 152, 68, 32, 12, 120, 82, 2, 14, 131, 6, 4, + 14, 27, 44, 5, 14, 101, 21, 9, 14, 81, 65, 11, 14, 49, 56, + 12, 14, 59, 6, 30, 14, 154, 4, 36, 14, 165, 62, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_sv_az_el_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSvAzEl, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[132]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_sv_az_el_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 132); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 132), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgSvAzEl, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 132); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 132), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[132]; + + EXPECT_EQ( + sbp_msg_sv_az_el_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 132), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[132]; + + for (uint8_t i = 0; i < 132; i++) { + EXPECT_EQ(sbp_msg_sv_az_el_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sv_az_el_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_sv_az_el_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 132); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSvAzEl, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 132); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_sv_az_el_t msg{}; + + EXPECT_EQ(sbp_msg_sv_az_el_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_sv_az_el_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_sv_az_el_t t{}; + return sbp_msg_sv_az_el_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_sv_az_el_t t{}; + t.n_azel = 1; + return sbp_msg_sv_az_el_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_sv_az_el_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_sv_az_el_t test_msg{}; - - test_msg.azel[0].az = 160; - test_msg.azel[0].el = 12; - test_msg.azel[0].sid.code = 0; - test_msg.azel[0].sid.sat = 8; - - test_msg.azel[1].az = 139; - test_msg.azel[1].el = 66; - test_msg.azel[1].sid.code = 0; - test_msg.azel[1].sid.sat = 10; - - test_msg.azel[2].az = 16; - test_msg.azel[2].el = 1; - test_msg.azel[2].sid.code = 0; - test_msg.azel[2].sid.sat = 13; - - test_msg.azel[3].az = 24; - test_msg.azel[3].el = 25; - test_msg.azel[3].sid.code = 0; - test_msg.azel[3].sid.sat = 15; - - test_msg.azel[4].az = 127; - test_msg.azel[4].el = 18; - test_msg.azel[4].sid.code = 0; - test_msg.azel[4].sid.sat = 16; - - test_msg.azel[5].az = 42; - test_msg.azel[5].el = 53; - test_msg.azel[5].sid.code = 0; - test_msg.azel[5].sid.sat = 18; - - test_msg.azel[6].az = 31; - test_msg.azel[6].el = 16; - test_msg.azel[6].sid.code = 0; - test_msg.azel[6].sid.sat = 20; - - test_msg.azel[7].az = 12; - test_msg.azel[7].el = 67; - test_msg.azel[7].sid.code = 0; - test_msg.azel[7].sid.sat = 23; - - test_msg.azel[8].az = 47; - test_msg.azel[8].el = 10; - test_msg.azel[8].sid.code = 0; - test_msg.azel[8].sid.sat = 24; - - test_msg.azel[9].az = 116; - test_msg.azel[9].el = 8; - test_msg.azel[9].sid.code = 0; - test_msg.azel[9].sid.sat = 26; - - test_msg.azel[10].az = 153; - test_msg.azel[10].el = 43; - test_msg.azel[10].sid.code = 0; - test_msg.azel[10].sid.sat = 27; - - test_msg.azel[11].az = 77; - test_msg.azel[11].el = 10; - test_msg.azel[11].sid.code = 0; - test_msg.azel[11].sid.sat = 29; - - test_msg.azel[12].az = 94; - test_msg.azel[12].el = 26; - test_msg.azel[12].sid.code = 0; - test_msg.azel[12].sid.sat = 32; - - test_msg.azel[13].az = 16; - test_msg.azel[13].el = 58; - test_msg.azel[13].sid.code = 3; - test_msg.azel[13].sid.sat = 1; - - test_msg.azel[14].az = 108; - test_msg.azel[14].el = 53; - test_msg.azel[14].sid.code = 3; - test_msg.azel[14].sid.sat = 2; - - test_msg.azel[15].az = 17; - test_msg.azel[15].el = 13; - test_msg.azel[15].sid.code = 3; - test_msg.azel[15].sid.sat = 8; - - test_msg.azel[16].az = 165; - test_msg.azel[16].el = 40; - test_msg.azel[16].sid.code = 3; - test_msg.azel[16].sid.sat = 17; - - test_msg.azel[17].az = 63; - test_msg.azel[17].el = 35; - test_msg.azel[17].sid.code = 3; - test_msg.azel[17].sid.sat = 23; - - test_msg.azel[18].az = 41; - test_msg.azel[18].el = 73; - test_msg.azel[18].sid.code = 3; - test_msg.azel[18].sid.sat = 24; - - test_msg.azel[19].az = 114; - test_msg.azel[19].el = 26; - test_msg.azel[19].sid.code = 12; - test_msg.azel[19].sid.sat = 20; - - test_msg.azel[20].az = 72; - test_msg.azel[20].el = 54; - test_msg.azel[20].sid.code = 12; - test_msg.azel[20].sid.sat = 27; - - test_msg.azel[21].az = 69; - test_msg.azel[21].el = 3; - test_msg.azel[21].sid.code = 12; - test_msg.azel[21].sid.sat = 28; - - test_msg.azel[22].az = 158; - test_msg.azel[22].el = 14; - test_msg.azel[22].sid.code = 12; - test_msg.azel[22].sid.sat = 29; - - test_msg.azel[23].az = 152; - test_msg.azel[23].el = 68; - test_msg.azel[23].sid.code = 12; - test_msg.azel[23].sid.sat = 30; - - test_msg.azel[24].az = 120; - test_msg.azel[24].el = 82; - test_msg.azel[24].sid.code = 12; - test_msg.azel[24].sid.sat = 32; - - test_msg.azel[25].az = 131; - test_msg.azel[25].el = 6; - test_msg.azel[25].sid.code = 14; - test_msg.azel[25].sid.sat = 2; - - test_msg.azel[26].az = 27; - test_msg.azel[26].el = 44; - test_msg.azel[26].sid.code = 14; - test_msg.azel[26].sid.sat = 4; - - test_msg.azel[27].az = 101; - test_msg.azel[27].el = 21; - test_msg.azel[27].sid.code = 14; - test_msg.azel[27].sid.sat = 5; - - test_msg.azel[28].az = 81; - test_msg.azel[28].el = 65; - test_msg.azel[28].sid.code = 14; - test_msg.azel[28].sid.sat = 9; - - test_msg.azel[29].az = 49; - test_msg.azel[29].el = 56; - test_msg.azel[29].sid.code = 14; - test_msg.azel[29].sid.sat = 11; - - test_msg.azel[30].az = 59; - test_msg.azel[30].el = 6; - test_msg.azel[30].sid.code = 14; - test_msg.azel[30].sid.sat = 12; - - test_msg.azel[31].az = 154; - test_msg.azel[31].el = 4; - test_msg.azel[31].sid.code = 14; - test_msg.azel[31].sid.sat = 30; - - test_msg.azel[32].az = 165; - test_msg.azel[32].el = 62; - test_msg.azel[32].sid.code = 14; - test_msg.azel[32].sid.sat = 36; - test_msg.n_azel = 33; - - EXPECT_EQ(send_message(31183, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 31183); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.azel[0].az, 160) - << "incorrect value for last_msg_.azel[0].az, expected 160, is " - << last_msg_.azel[0].az; - EXPECT_EQ(last_msg_.azel[0].el, 12) - << "incorrect value for last_msg_.azel[0].el, expected 12, is " - << last_msg_.azel[0].el; - EXPECT_EQ(last_msg_.azel[0].sid.code, 0) - << "incorrect value for last_msg_.azel[0].sid.code, expected 0, is " - << last_msg_.azel[0].sid.code; - EXPECT_EQ(last_msg_.azel[0].sid.sat, 8) - << "incorrect value for last_msg_.azel[0].sid.sat, expected 8, is " - << last_msg_.azel[0].sid.sat; - EXPECT_EQ(last_msg_.azel[1].az, 139) - << "incorrect value for last_msg_.azel[1].az, expected 139, is " - << last_msg_.azel[1].az; - EXPECT_EQ(last_msg_.azel[1].el, 66) - << "incorrect value for last_msg_.azel[1].el, expected 66, is " - << last_msg_.azel[1].el; - EXPECT_EQ(last_msg_.azel[1].sid.code, 0) - << "incorrect value for last_msg_.azel[1].sid.code, expected 0, is " - << last_msg_.azel[1].sid.code; - EXPECT_EQ(last_msg_.azel[1].sid.sat, 10) - << "incorrect value for last_msg_.azel[1].sid.sat, expected 10, is " - << last_msg_.azel[1].sid.sat; - EXPECT_EQ(last_msg_.azel[2].az, 16) - << "incorrect value for last_msg_.azel[2].az, expected 16, is " - << last_msg_.azel[2].az; - EXPECT_EQ(last_msg_.azel[2].el, 1) - << "incorrect value for last_msg_.azel[2].el, expected 1, is " - << last_msg_.azel[2].el; - EXPECT_EQ(last_msg_.azel[2].sid.code, 0) - << "incorrect value for last_msg_.azel[2].sid.code, expected 0, is " - << last_msg_.azel[2].sid.code; - EXPECT_EQ(last_msg_.azel[2].sid.sat, 13) - << "incorrect value for last_msg_.azel[2].sid.sat, expected 13, is " - << last_msg_.azel[2].sid.sat; - EXPECT_EQ(last_msg_.azel[3].az, 24) - << "incorrect value for last_msg_.azel[3].az, expected 24, is " - << last_msg_.azel[3].az; - EXPECT_EQ(last_msg_.azel[3].el, 25) - << "incorrect value for last_msg_.azel[3].el, expected 25, is " - << last_msg_.azel[3].el; - EXPECT_EQ(last_msg_.azel[3].sid.code, 0) - << "incorrect value for last_msg_.azel[3].sid.code, expected 0, is " - << last_msg_.azel[3].sid.code; - EXPECT_EQ(last_msg_.azel[3].sid.sat, 15) - << "incorrect value for last_msg_.azel[3].sid.sat, expected 15, is " - << last_msg_.azel[3].sid.sat; - EXPECT_EQ(last_msg_.azel[4].az, 127) - << "incorrect value for last_msg_.azel[4].az, expected 127, is " - << last_msg_.azel[4].az; - EXPECT_EQ(last_msg_.azel[4].el, 18) - << "incorrect value for last_msg_.azel[4].el, expected 18, is " - << last_msg_.azel[4].el; - EXPECT_EQ(last_msg_.azel[4].sid.code, 0) - << "incorrect value for last_msg_.azel[4].sid.code, expected 0, is " - << last_msg_.azel[4].sid.code; - EXPECT_EQ(last_msg_.azel[4].sid.sat, 16) - << "incorrect value for last_msg_.azel[4].sid.sat, expected 16, is " - << last_msg_.azel[4].sid.sat; - EXPECT_EQ(last_msg_.azel[5].az, 42) - << "incorrect value for last_msg_.azel[5].az, expected 42, is " - << last_msg_.azel[5].az; - EXPECT_EQ(last_msg_.azel[5].el, 53) - << "incorrect value for last_msg_.azel[5].el, expected 53, is " - << last_msg_.azel[5].el; - EXPECT_EQ(last_msg_.azel[5].sid.code, 0) - << "incorrect value for last_msg_.azel[5].sid.code, expected 0, is " - << last_msg_.azel[5].sid.code; - EXPECT_EQ(last_msg_.azel[5].sid.sat, 18) - << "incorrect value for last_msg_.azel[5].sid.sat, expected 18, is " - << last_msg_.azel[5].sid.sat; - EXPECT_EQ(last_msg_.azel[6].az, 31) - << "incorrect value for last_msg_.azel[6].az, expected 31, is " - << last_msg_.azel[6].az; - EXPECT_EQ(last_msg_.azel[6].el, 16) - << "incorrect value for last_msg_.azel[6].el, expected 16, is " - << last_msg_.azel[6].el; - EXPECT_EQ(last_msg_.azel[6].sid.code, 0) - << "incorrect value for last_msg_.azel[6].sid.code, expected 0, is " - << last_msg_.azel[6].sid.code; - EXPECT_EQ(last_msg_.azel[6].sid.sat, 20) - << "incorrect value for last_msg_.azel[6].sid.sat, expected 20, is " - << last_msg_.azel[6].sid.sat; - EXPECT_EQ(last_msg_.azel[7].az, 12) - << "incorrect value for last_msg_.azel[7].az, expected 12, is " - << last_msg_.azel[7].az; - EXPECT_EQ(last_msg_.azel[7].el, 67) - << "incorrect value for last_msg_.azel[7].el, expected 67, is " - << last_msg_.azel[7].el; - EXPECT_EQ(last_msg_.azel[7].sid.code, 0) - << "incorrect value for last_msg_.azel[7].sid.code, expected 0, is " - << last_msg_.azel[7].sid.code; - EXPECT_EQ(last_msg_.azel[7].sid.sat, 23) - << "incorrect value for last_msg_.azel[7].sid.sat, expected 23, is " - << last_msg_.azel[7].sid.sat; - EXPECT_EQ(last_msg_.azel[8].az, 47) - << "incorrect value for last_msg_.azel[8].az, expected 47, is " - << last_msg_.azel[8].az; - EXPECT_EQ(last_msg_.azel[8].el, 10) - << "incorrect value for last_msg_.azel[8].el, expected 10, is " - << last_msg_.azel[8].el; - EXPECT_EQ(last_msg_.azel[8].sid.code, 0) - << "incorrect value for last_msg_.azel[8].sid.code, expected 0, is " - << last_msg_.azel[8].sid.code; - EXPECT_EQ(last_msg_.azel[8].sid.sat, 24) - << "incorrect value for last_msg_.azel[8].sid.sat, expected 24, is " - << last_msg_.azel[8].sid.sat; - EXPECT_EQ(last_msg_.azel[9].az, 116) - << "incorrect value for last_msg_.azel[9].az, expected 116, is " - << last_msg_.azel[9].az; - EXPECT_EQ(last_msg_.azel[9].el, 8) - << "incorrect value for last_msg_.azel[9].el, expected 8, is " - << last_msg_.azel[9].el; - EXPECT_EQ(last_msg_.azel[9].sid.code, 0) - << "incorrect value for last_msg_.azel[9].sid.code, expected 0, is " - << last_msg_.azel[9].sid.code; - EXPECT_EQ(last_msg_.azel[9].sid.sat, 26) - << "incorrect value for last_msg_.azel[9].sid.sat, expected 26, is " - << last_msg_.azel[9].sid.sat; - EXPECT_EQ(last_msg_.azel[10].az, 153) - << "incorrect value for last_msg_.azel[10].az, expected 153, is " - << last_msg_.azel[10].az; - EXPECT_EQ(last_msg_.azel[10].el, 43) - << "incorrect value for last_msg_.azel[10].el, expected 43, is " - << last_msg_.azel[10].el; - EXPECT_EQ(last_msg_.azel[10].sid.code, 0) - << "incorrect value for last_msg_.azel[10].sid.code, expected 0, is " - << last_msg_.azel[10].sid.code; - EXPECT_EQ(last_msg_.azel[10].sid.sat, 27) - << "incorrect value for last_msg_.azel[10].sid.sat, expected 27, is " - << last_msg_.azel[10].sid.sat; - EXPECT_EQ(last_msg_.azel[11].az, 77) - << "incorrect value for last_msg_.azel[11].az, expected 77, is " - << last_msg_.azel[11].az; - EXPECT_EQ(last_msg_.azel[11].el, 10) - << "incorrect value for last_msg_.azel[11].el, expected 10, is " - << last_msg_.azel[11].el; - EXPECT_EQ(last_msg_.azel[11].sid.code, 0) - << "incorrect value for last_msg_.azel[11].sid.code, expected 0, is " - << last_msg_.azel[11].sid.code; - EXPECT_EQ(last_msg_.azel[11].sid.sat, 29) - << "incorrect value for last_msg_.azel[11].sid.sat, expected 29, is " - << last_msg_.azel[11].sid.sat; - EXPECT_EQ(last_msg_.azel[12].az, 94) - << "incorrect value for last_msg_.azel[12].az, expected 94, is " - << last_msg_.azel[12].az; - EXPECT_EQ(last_msg_.azel[12].el, 26) - << "incorrect value for last_msg_.azel[12].el, expected 26, is " - << last_msg_.azel[12].el; - EXPECT_EQ(last_msg_.azel[12].sid.code, 0) - << "incorrect value for last_msg_.azel[12].sid.code, expected 0, is " - << last_msg_.azel[12].sid.code; - EXPECT_EQ(last_msg_.azel[12].sid.sat, 32) - << "incorrect value for last_msg_.azel[12].sid.sat, expected 32, is " - << last_msg_.azel[12].sid.sat; - EXPECT_EQ(last_msg_.azel[13].az, 16) - << "incorrect value for last_msg_.azel[13].az, expected 16, is " - << last_msg_.azel[13].az; - EXPECT_EQ(last_msg_.azel[13].el, 58) - << "incorrect value for last_msg_.azel[13].el, expected 58, is " - << last_msg_.azel[13].el; - EXPECT_EQ(last_msg_.azel[13].sid.code, 3) - << "incorrect value for last_msg_.azel[13].sid.code, expected 3, is " - << last_msg_.azel[13].sid.code; - EXPECT_EQ(last_msg_.azel[13].sid.sat, 1) - << "incorrect value for last_msg_.azel[13].sid.sat, expected 1, is " - << last_msg_.azel[13].sid.sat; - EXPECT_EQ(last_msg_.azel[14].az, 108) - << "incorrect value for last_msg_.azel[14].az, expected 108, is " - << last_msg_.azel[14].az; - EXPECT_EQ(last_msg_.azel[14].el, 53) - << "incorrect value for last_msg_.azel[14].el, expected 53, is " - << last_msg_.azel[14].el; - EXPECT_EQ(last_msg_.azel[14].sid.code, 3) - << "incorrect value for last_msg_.azel[14].sid.code, expected 3, is " - << last_msg_.azel[14].sid.code; - EXPECT_EQ(last_msg_.azel[14].sid.sat, 2) - << "incorrect value for last_msg_.azel[14].sid.sat, expected 2, is " - << last_msg_.azel[14].sid.sat; - EXPECT_EQ(last_msg_.azel[15].az, 17) - << "incorrect value for last_msg_.azel[15].az, expected 17, is " - << last_msg_.azel[15].az; - EXPECT_EQ(last_msg_.azel[15].el, 13) - << "incorrect value for last_msg_.azel[15].el, expected 13, is " - << last_msg_.azel[15].el; - EXPECT_EQ(last_msg_.azel[15].sid.code, 3) - << "incorrect value for last_msg_.azel[15].sid.code, expected 3, is " - << last_msg_.azel[15].sid.code; - EXPECT_EQ(last_msg_.azel[15].sid.sat, 8) - << "incorrect value for last_msg_.azel[15].sid.sat, expected 8, is " - << last_msg_.azel[15].sid.sat; - EXPECT_EQ(last_msg_.azel[16].az, 165) - << "incorrect value for last_msg_.azel[16].az, expected 165, is " - << last_msg_.azel[16].az; - EXPECT_EQ(last_msg_.azel[16].el, 40) - << "incorrect value for last_msg_.azel[16].el, expected 40, is " - << last_msg_.azel[16].el; - EXPECT_EQ(last_msg_.azel[16].sid.code, 3) - << "incorrect value for last_msg_.azel[16].sid.code, expected 3, is " - << last_msg_.azel[16].sid.code; - EXPECT_EQ(last_msg_.azel[16].sid.sat, 17) - << "incorrect value for last_msg_.azel[16].sid.sat, expected 17, is " - << last_msg_.azel[16].sid.sat; - EXPECT_EQ(last_msg_.azel[17].az, 63) - << "incorrect value for last_msg_.azel[17].az, expected 63, is " - << last_msg_.azel[17].az; - EXPECT_EQ(last_msg_.azel[17].el, 35) - << "incorrect value for last_msg_.azel[17].el, expected 35, is " - << last_msg_.azel[17].el; - EXPECT_EQ(last_msg_.azel[17].sid.code, 3) - << "incorrect value for last_msg_.azel[17].sid.code, expected 3, is " - << last_msg_.azel[17].sid.code; - EXPECT_EQ(last_msg_.azel[17].sid.sat, 23) - << "incorrect value for last_msg_.azel[17].sid.sat, expected 23, is " - << last_msg_.azel[17].sid.sat; - EXPECT_EQ(last_msg_.azel[18].az, 41) - << "incorrect value for last_msg_.azel[18].az, expected 41, is " - << last_msg_.azel[18].az; - EXPECT_EQ(last_msg_.azel[18].el, 73) - << "incorrect value for last_msg_.azel[18].el, expected 73, is " - << last_msg_.azel[18].el; - EXPECT_EQ(last_msg_.azel[18].sid.code, 3) - << "incorrect value for last_msg_.azel[18].sid.code, expected 3, is " - << last_msg_.azel[18].sid.code; - EXPECT_EQ(last_msg_.azel[18].sid.sat, 24) - << "incorrect value for last_msg_.azel[18].sid.sat, expected 24, is " - << last_msg_.azel[18].sid.sat; - EXPECT_EQ(last_msg_.azel[19].az, 114) - << "incorrect value for last_msg_.azel[19].az, expected 114, is " - << last_msg_.azel[19].az; - EXPECT_EQ(last_msg_.azel[19].el, 26) - << "incorrect value for last_msg_.azel[19].el, expected 26, is " - << last_msg_.azel[19].el; - EXPECT_EQ(last_msg_.azel[19].sid.code, 12) - << "incorrect value for last_msg_.azel[19].sid.code, expected 12, is " - << last_msg_.azel[19].sid.code; - EXPECT_EQ(last_msg_.azel[19].sid.sat, 20) - << "incorrect value for last_msg_.azel[19].sid.sat, expected 20, is " - << last_msg_.azel[19].sid.sat; - EXPECT_EQ(last_msg_.azel[20].az, 72) - << "incorrect value for last_msg_.azel[20].az, expected 72, is " - << last_msg_.azel[20].az; - EXPECT_EQ(last_msg_.azel[20].el, 54) - << "incorrect value for last_msg_.azel[20].el, expected 54, is " - << last_msg_.azel[20].el; - EXPECT_EQ(last_msg_.azel[20].sid.code, 12) - << "incorrect value for last_msg_.azel[20].sid.code, expected 12, is " - << last_msg_.azel[20].sid.code; - EXPECT_EQ(last_msg_.azel[20].sid.sat, 27) - << "incorrect value for last_msg_.azel[20].sid.sat, expected 27, is " - << last_msg_.azel[20].sid.sat; - EXPECT_EQ(last_msg_.azel[21].az, 69) - << "incorrect value for last_msg_.azel[21].az, expected 69, is " - << last_msg_.azel[21].az; - EXPECT_EQ(last_msg_.azel[21].el, 3) - << "incorrect value for last_msg_.azel[21].el, expected 3, is " - << last_msg_.azel[21].el; - EXPECT_EQ(last_msg_.azel[21].sid.code, 12) - << "incorrect value for last_msg_.azel[21].sid.code, expected 12, is " - << last_msg_.azel[21].sid.code; - EXPECT_EQ(last_msg_.azel[21].sid.sat, 28) - << "incorrect value for last_msg_.azel[21].sid.sat, expected 28, is " - << last_msg_.azel[21].sid.sat; - EXPECT_EQ(last_msg_.azel[22].az, 158) - << "incorrect value for last_msg_.azel[22].az, expected 158, is " - << last_msg_.azel[22].az; - EXPECT_EQ(last_msg_.azel[22].el, 14) - << "incorrect value for last_msg_.azel[22].el, expected 14, is " - << last_msg_.azel[22].el; - EXPECT_EQ(last_msg_.azel[22].sid.code, 12) - << "incorrect value for last_msg_.azel[22].sid.code, expected 12, is " - << last_msg_.azel[22].sid.code; - EXPECT_EQ(last_msg_.azel[22].sid.sat, 29) - << "incorrect value for last_msg_.azel[22].sid.sat, expected 29, is " - << last_msg_.azel[22].sid.sat; - EXPECT_EQ(last_msg_.azel[23].az, 152) - << "incorrect value for last_msg_.azel[23].az, expected 152, is " - << last_msg_.azel[23].az; - EXPECT_EQ(last_msg_.azel[23].el, 68) - << "incorrect value for last_msg_.azel[23].el, expected 68, is " - << last_msg_.azel[23].el; - EXPECT_EQ(last_msg_.azel[23].sid.code, 12) - << "incorrect value for last_msg_.azel[23].sid.code, expected 12, is " - << last_msg_.azel[23].sid.code; - EXPECT_EQ(last_msg_.azel[23].sid.sat, 30) - << "incorrect value for last_msg_.azel[23].sid.sat, expected 30, is " - << last_msg_.azel[23].sid.sat; - EXPECT_EQ(last_msg_.azel[24].az, 120) - << "incorrect value for last_msg_.azel[24].az, expected 120, is " - << last_msg_.azel[24].az; - EXPECT_EQ(last_msg_.azel[24].el, 82) - << "incorrect value for last_msg_.azel[24].el, expected 82, is " - << last_msg_.azel[24].el; - EXPECT_EQ(last_msg_.azel[24].sid.code, 12) - << "incorrect value for last_msg_.azel[24].sid.code, expected 12, is " - << last_msg_.azel[24].sid.code; - EXPECT_EQ(last_msg_.azel[24].sid.sat, 32) - << "incorrect value for last_msg_.azel[24].sid.sat, expected 32, is " - << last_msg_.azel[24].sid.sat; - EXPECT_EQ(last_msg_.azel[25].az, 131) - << "incorrect value for last_msg_.azel[25].az, expected 131, is " - << last_msg_.azel[25].az; - EXPECT_EQ(last_msg_.azel[25].el, 6) - << "incorrect value for last_msg_.azel[25].el, expected 6, is " - << last_msg_.azel[25].el; - EXPECT_EQ(last_msg_.azel[25].sid.code, 14) - << "incorrect value for last_msg_.azel[25].sid.code, expected 14, is " - << last_msg_.azel[25].sid.code; - EXPECT_EQ(last_msg_.azel[25].sid.sat, 2) - << "incorrect value for last_msg_.azel[25].sid.sat, expected 2, is " - << last_msg_.azel[25].sid.sat; - EXPECT_EQ(last_msg_.azel[26].az, 27) - << "incorrect value for last_msg_.azel[26].az, expected 27, is " - << last_msg_.azel[26].az; - EXPECT_EQ(last_msg_.azel[26].el, 44) - << "incorrect value for last_msg_.azel[26].el, expected 44, is " - << last_msg_.azel[26].el; - EXPECT_EQ(last_msg_.azel[26].sid.code, 14) - << "incorrect value for last_msg_.azel[26].sid.code, expected 14, is " - << last_msg_.azel[26].sid.code; - EXPECT_EQ(last_msg_.azel[26].sid.sat, 4) - << "incorrect value for last_msg_.azel[26].sid.sat, expected 4, is " - << last_msg_.azel[26].sid.sat; - EXPECT_EQ(last_msg_.azel[27].az, 101) - << "incorrect value for last_msg_.azel[27].az, expected 101, is " - << last_msg_.azel[27].az; - EXPECT_EQ(last_msg_.azel[27].el, 21) - << "incorrect value for last_msg_.azel[27].el, expected 21, is " - << last_msg_.azel[27].el; - EXPECT_EQ(last_msg_.azel[27].sid.code, 14) - << "incorrect value for last_msg_.azel[27].sid.code, expected 14, is " - << last_msg_.azel[27].sid.code; - EXPECT_EQ(last_msg_.azel[27].sid.sat, 5) - << "incorrect value for last_msg_.azel[27].sid.sat, expected 5, is " - << last_msg_.azel[27].sid.sat; - EXPECT_EQ(last_msg_.azel[28].az, 81) - << "incorrect value for last_msg_.azel[28].az, expected 81, is " - << last_msg_.azel[28].az; - EXPECT_EQ(last_msg_.azel[28].el, 65) - << "incorrect value for last_msg_.azel[28].el, expected 65, is " - << last_msg_.azel[28].el; - EXPECT_EQ(last_msg_.azel[28].sid.code, 14) - << "incorrect value for last_msg_.azel[28].sid.code, expected 14, is " - << last_msg_.azel[28].sid.code; - EXPECT_EQ(last_msg_.azel[28].sid.sat, 9) - << "incorrect value for last_msg_.azel[28].sid.sat, expected 9, is " - << last_msg_.azel[28].sid.sat; - EXPECT_EQ(last_msg_.azel[29].az, 49) - << "incorrect value for last_msg_.azel[29].az, expected 49, is " - << last_msg_.azel[29].az; - EXPECT_EQ(last_msg_.azel[29].el, 56) - << "incorrect value for last_msg_.azel[29].el, expected 56, is " - << last_msg_.azel[29].el; - EXPECT_EQ(last_msg_.azel[29].sid.code, 14) - << "incorrect value for last_msg_.azel[29].sid.code, expected 14, is " - << last_msg_.azel[29].sid.code; - EXPECT_EQ(last_msg_.azel[29].sid.sat, 11) - << "incorrect value for last_msg_.azel[29].sid.sat, expected 11, is " - << last_msg_.azel[29].sid.sat; - EXPECT_EQ(last_msg_.azel[30].az, 59) - << "incorrect value for last_msg_.azel[30].az, expected 59, is " - << last_msg_.azel[30].az; - EXPECT_EQ(last_msg_.azel[30].el, 6) - << "incorrect value for last_msg_.azel[30].el, expected 6, is " - << last_msg_.azel[30].el; - EXPECT_EQ(last_msg_.azel[30].sid.code, 14) - << "incorrect value for last_msg_.azel[30].sid.code, expected 14, is " - << last_msg_.azel[30].sid.code; - EXPECT_EQ(last_msg_.azel[30].sid.sat, 12) - << "incorrect value for last_msg_.azel[30].sid.sat, expected 12, is " - << last_msg_.azel[30].sid.sat; - EXPECT_EQ(last_msg_.azel[31].az, 154) - << "incorrect value for last_msg_.azel[31].az, expected 154, is " - << last_msg_.azel[31].az; - EXPECT_EQ(last_msg_.azel[31].el, 4) - << "incorrect value for last_msg_.azel[31].el, expected 4, is " - << last_msg_.azel[31].el; - EXPECT_EQ(last_msg_.azel[31].sid.code, 14) - << "incorrect value for last_msg_.azel[31].sid.code, expected 14, is " - << last_msg_.azel[31].sid.code; - EXPECT_EQ(last_msg_.azel[31].sid.sat, 30) - << "incorrect value for last_msg_.azel[31].sid.sat, expected 30, is " - << last_msg_.azel[31].sid.sat; - EXPECT_EQ(last_msg_.azel[32].az, 165) - << "incorrect value for last_msg_.azel[32].az, expected 165, is " - << last_msg_.azel[32].az; - EXPECT_EQ(last_msg_.azel[32].el, 62) - << "incorrect value for last_msg_.azel[32].el, expected 62, is " - << last_msg_.azel[32].el; - EXPECT_EQ(last_msg_.azel[32].sid.code, 14) - << "incorrect value for last_msg_.azel[32].sid.code, expected 14, is " - << last_msg_.azel[32].sid.code; - EXPECT_EQ(last_msg_.azel[32].sid.sat, 36) - << "incorrect value for last_msg_.azel[32].sid.sat, expected 36, is " - << last_msg_.azel[32].sid.sat; - EXPECT_EQ(last_msg_.n_azel, 33) - << "incorrect value for last_msg_.n_azel, expected 33, is " - << last_msg_.n_azel; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_sv_az_el_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSvAzEl, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSvAzEl, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSvAzEl, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[0].az, greater.azel[0].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[0].el, greater.azel[0].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[0].sid.code, greater.azel[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[0].sid.sat, greater.azel[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[1].az, greater.azel[1].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[1].el, greater.azel[1].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[1].sid.code, greater.azel[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[1].sid.sat, greater.azel[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[2].az, greater.azel[2].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[2].el, greater.azel[2].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[2].sid.code, greater.azel[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[2].sid.sat, greater.azel[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[3].az, greater.azel[3].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[3].el, greater.azel[3].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[3].sid.code, greater.azel[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[3].sid.sat, greater.azel[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[4].az, greater.azel[4].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[4].el, greater.azel[4].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[4].sid.code, greater.azel[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[4].sid.sat, greater.azel[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[5].az, greater.azel[5].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[5].el, greater.azel[5].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[5].sid.code, greater.azel[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[5].sid.sat, greater.azel[5].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[6].az, greater.azel[6].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[6].el, greater.azel[6].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[6].sid.code, greater.azel[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[6].sid.sat, greater.azel[6].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[7].az, greater.azel[7].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[7].el, greater.azel[7].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[7].sid.code, greater.azel[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[7].sid.sat, greater.azel[7].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[8].az, greater.azel[8].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[8].el, greater.azel[8].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[8].sid.code, greater.azel[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[8].sid.sat, greater.azel[8].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[9].az, greater.azel[9].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[9].el, greater.azel[9].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[9].sid.code, greater.azel[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[9].sid.sat, greater.azel[9].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[10].az, greater.azel[10].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[10].el, greater.azel[10].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[10].sid.code, greater.azel[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[10].sid.sat, greater.azel[10].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[11].az, greater.azel[11].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[11].el, greater.azel[11].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[11].sid.code, greater.azel[11].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[11].sid.sat, greater.azel[11].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[12].az, greater.azel[12].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[12].el, greater.azel[12].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[12].sid.code, greater.azel[12].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[12].sid.sat, greater.azel[12].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[13].az, greater.azel[13].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[13].el, greater.azel[13].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[13].sid.code, greater.azel[13].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[13].sid.sat, greater.azel[13].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[14].az, greater.azel[14].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[14].el, greater.azel[14].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[14].sid.code, greater.azel[14].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[14].sid.sat, greater.azel[14].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[15].az, greater.azel[15].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[15].el, greater.azel[15].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[15].sid.code, greater.azel[15].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[15].sid.sat, greater.azel[15].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[16].az, greater.azel[16].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[16].el, greater.azel[16].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[16].sid.code, greater.azel[16].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[16].sid.sat, greater.azel[16].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[17].az, greater.azel[17].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[17].el, greater.azel[17].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[17].sid.code, greater.azel[17].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[17].sid.sat, greater.azel[17].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[18].az, greater.azel[18].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[18].el, greater.azel[18].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[18].sid.code, greater.azel[18].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[18].sid.sat, greater.azel[18].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[19].az, greater.azel[19].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[19].el, greater.azel[19].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[19].sid.code, greater.azel[19].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[19].sid.sat, greater.azel[19].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[20].az, greater.azel[20].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[20].el, greater.azel[20].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[20].sid.code, greater.azel[20].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[20].sid.sat, greater.azel[20].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[21].az, greater.azel[21].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[21].el, greater.azel[21].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[21].sid.code, greater.azel[21].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[21].sid.sat, greater.azel[21].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[22].az, greater.azel[22].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[22].el, greater.azel[22].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[22].sid.code, greater.azel[22].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[22].sid.sat, greater.azel[22].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[23].az, greater.azel[23].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[23].el, greater.azel[23].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[23].sid.code, greater.azel[23].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[23].sid.sat, greater.azel[23].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[24].az, greater.azel[24].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[24].el, greater.azel[24].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[24].sid.code, greater.azel[24].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[24].sid.sat, greater.azel[24].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[25].az, greater.azel[25].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[25].el, greater.azel[25].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[25].sid.code, greater.azel[25].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[25].sid.sat, greater.azel[25].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[26].az, greater.azel[26].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[26].el, greater.azel[26].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[26].sid.code, greater.azel[26].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[26].sid.sat, greater.azel[26].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[27].az, greater.azel[27].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[27].el, greater.azel[27].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[27].sid.code, greater.azel[27].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[27].sid.sat, greater.azel[27].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[28].az, greater.azel[28].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[28].el, greater.azel[28].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[28].sid.code, greater.azel[28].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[28].sid.sat, greater.azel[28].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[29].az, greater.azel[29].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[29].el, greater.azel[29].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[29].sid.code, greater.azel[29].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[29].sid.sat, greater.azel[29].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[30].az, greater.azel[30].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[30].el, greater.azel[30].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[30].sid.code, greater.azel[30].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[30].sid.sat, greater.azel[30].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[31].az, greater.azel[31].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[31].el, greater.azel[31].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[31].sid.code, greater.azel[31].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[31].sid.sat, greater.azel[31].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[32].az, greater.azel[32].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[32].el, greater.azel[32].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[32].sid.code, greater.azel[32].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.azel[32].sid.sat, greater.azel[32].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_az_el_t lesser = info.test_msg; + sbp_msg_sv_az_el_t greater = info.test_msg; + make_lesser_greater(lesser.n_azel, greater.n_azel); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSvAzEl); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_SV_AZ_EL"); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_sv_az_el_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_sv_az_el_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.sv_az_el, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.sv_az_el, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[132]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 132); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 132), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sv_az_el_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 132); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSvAzEl, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvAzEl0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSvAzEl, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc b/c/test/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc new file mode 100644 index 0000000000..59a39af52b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc @@ -0,0 +1,822 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0() { + assign(test_msg_.l2c_mask, 2808462402); + assign(test_msg_.t_nmct.tow, 0); + assign(test_msg_.t_nmct.wn, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_sv_configuration_gps_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_sv_configuration_gps_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_sv_configuration_gps_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSvConfigurationGpsDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_sv_configuration_gps_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSvConfigurationGpsDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->sv_configuration_gps_dep, + sizeof(msg->sv_configuration_gps_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_sv_configuration_gps_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.sv_configuration_gps_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSvConfigurationGpsDep); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0x2a12; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_sv_configuration_gps_dep_t &lesser, + const sbp_msg_sv_configuration_gps_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_sv_configuration_gps_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_sv_configuration_gps_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSvConfigurationGpsDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSvConfigurationGpsDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSvConfigurationGpsDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSvConfigurationGpsDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_sv_configuration_gps_dep_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + }; + uint8_t encoded_payload_[10] = { + 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, + }; +}; + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSvConfigurationGpsDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSvConfigurationGpsDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sv_configuration_gps_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSvConfigurationGpsDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_sv_configuration_gps_dep_t msg{}; + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_sv_configuration_gps_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_sv_configuration_gps_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSvConfigurationGpsDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSvConfigurationGpsDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSvConfigurationGpsDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_sv_configuration_gps_dep_t lesser = info.test_msg; + sbp_msg_sv_configuration_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.l2c_mask, greater.l2c_mask); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_configuration_gps_dep_t lesser = info.test_msg; + sbp_msg_sv_configuration_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.tow, greater.t_nmct.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_sv_configuration_gps_dep_t lesser = info.test_msg; + sbp_msg_sv_configuration_gps_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t_nmct.wn, greater.t_nmct.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSvConfigurationGpsDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SV_CONFIGURATION_GPS_DEP"); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_sv_configuration_gps_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_sv_configuration_gps_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.sv_configuration_gps_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.sv_configuration_gps_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sv_configuration_gps_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSvConfigurationGpsDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_MsgSvConfigurationGpsDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSvConfigurationGpsDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_msgEphemerisDepB.cc b/c/test/cpp/auto_check_sbp_observation_msgEphemerisDepB.cc index 98c5d06bb1..13ab5f66dd 100644 --- a/c/test/cpp/auto_check_sbp_observation_msgEphemerisDepB.cc +++ b/c/test/cpp/auto_check_sbp_observation_msgEphemerisDepB.cc @@ -16,66 +16,393 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_msgEphemerisDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_msgEphemerisDepB0 + : public ::testing::Test { public: - Test_auto_check_sbp_observation_msgEphemerisDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_msgEphemerisDepB0() { + assign(test_msg_.af0, -1.035025343298912e-05); + assign(test_msg_.af1, -9.094947017729282e-13); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 6.332993507385254e-08); + assign(test_msg_.c_is, -1.564621925354004e-07); + assign(test_msg_.c_rc, 234.375); + assign(test_msg_.c_rs, -74.90625); + assign(test_msg_.c_uc, -3.937631845474243e-06); + assign(test_msg_.c_us, 6.9122761487960815e-06); + assign(test_msg_.dn, 4.8884179079418005e-09); + assign(test_msg_.ecc, 0.011132609914056957); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9395524830579087); + assign(test_msg_.inc_dot, -3.296565886629854e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, 2.467348395627239); + assign(test_msg_.omega0, -0.9468985437479658); + assign(test_msg_.omegadot, -8.201055892610478e-09); + assign(test_msg_.prn, 3); + assign(test_msg_.sqrta, 5153.714303970337); + assign(test_msg_.tgd, -6.51925802230835e-09); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, 1.0525047200405302); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x9ce1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 60, 190, 0, 0, 0, 0, 0, 186, 82, 192, 0, 0, 0, 0, 0, 76, 109, 64, 0, 0, 0, 0, 0, 132, 208, 190, 0, 0, 0, 0, 0, 254, 220, @@ -90,1108 +417,5391 @@ TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB0, Test) { 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, 3, 0, 225, 156, }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 0, 60, 190, 0, 0, 0, 0, 0, 186, 82, + 192, 0, 0, 0, 0, 0, 76, 109, 64, 0, 0, 0, 0, 0, 132, + 208, 190, 0, 0, 0, 0, 0, 254, 220, 62, 0, 0, 0, 0, 0, + 0, 113, 62, 0, 0, 0, 0, 0, 0, 133, 190, 28, 36, 25, 81, + 223, 254, 52, 62, 220, 116, 216, 39, 33, 189, 3, 64, 0, 0, 0, + 156, 177, 204, 134, 63, 0, 0, 160, 220, 182, 33, 180, 64, 152, 225, + 192, 44, 254, 76, 238, 191, 41, 150, 24, 2, 148, 156, 65, 190, 252, + 90, 119, 48, 15, 215, 240, 63, 124, 127, 115, 94, 208, 16, 238, 63, + 165, 115, 52, 74, 97, 167, 246, 189, 0, 0, 0, 0, 192, 180, 229, + 190, 0, 0, 0, 0, 0, 0, 112, 189, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 3, 0, + }; +}; - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = -1.035025343298912e-05; - test_msg.af1 = -9.094947017729282e-13; - test_msg.af2 = 0.0; - test_msg.c_ic = 6.332993507385254e-08; - test_msg.c_is = -1.564621925354004e-07; - test_msg.c_rc = 234.375; - test_msg.c_rs = -74.90625; - test_msg.c_uc = -3.937631845474243e-06; - test_msg.c_us = 6.9122761487960815e-06; - test_msg.dn = 4.8884179079418005e-09; - test_msg.ecc = 0.011132609914056957; - test_msg.healthy = 1; - test_msg.inc = 0.9395524830579087; - test_msg.inc_dot = -3.296565886629854e-10; - test_msg.iode = 0; - test_msg.m0 = 2.467348395627239; - test_msg.omega0 = -0.9468985437479658; - test_msg.omegadot = -8.201055892610478e-09; - test_msg.prn = 3; - test_msg.sqrta = 5153.714303970337; - test_msg.tgd = -6.51925802230835e-09; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = 1.0525047200405302; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -1.0350253433e-05 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -1.0350253433e-05, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -9.09494701773e-13 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -9.09494701773e-13, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - 6.33299350739e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected 6.33299350739e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - -1.56462192535e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected -1.56462192535e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 234.375 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 234.375, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - -74.90625 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected -74.90625, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - -3.93763184547e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected -3.93763184547e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 6.9122761488e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 6.9122761488e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 4.88841790794e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 4.88841790794e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.0111326099141 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.0111326099141, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.939552483058 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.939552483058, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - -3.29656588663e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected -3.29656588663e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - 2.46734839563 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected 2.46734839563, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - -0.946898543748 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected -0.946898543748, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.20105589261e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.20105589261e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 3) - << "incorrect value for last_msg_.prn, expected 3, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.71430397 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.71430397, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -6.51925802231e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -6.51925802231e-09, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - 1.05250472004 * 100), 0.05) - << "incorrect value for last_msg_.w, expected 1.05250472004, is " - << last_msg_.w; -} -class Test_auto_check_sbp_observation_msgEphemerisDepB1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgEphemerisDepB1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB1, Test) { - uint8_t encoded_frame[] = { - 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 68, 190, 0, - 0, 0, 0, 0, 72, 66, 64, 0, 0, 0, 0, 128, 188, 115, 64, - 0, 0, 0, 0, 0, 80, 193, 62, 0, 0, 0, 0, 0, 164, 204, - 62, 0, 0, 0, 0, 0, 0, 130, 62, 0, 0, 0, 0, 0, 0, - 128, 62, 72, 181, 127, 6, 208, 225, 52, 62, 158, 174, 129, 91, 27, - 105, 249, 191, 0, 0, 0, 96, 204, 57, 128, 63, 0, 0, 160, 35, - 146, 33, 180, 64, 247, 169, 1, 36, 133, 206, 243, 63, 79, 11, 109, - 92, 156, 208, 65, 190, 103, 78, 3, 253, 223, 147, 255, 191, 164, 214, - 90, 250, 218, 240, 238, 63, 94, 239, 187, 37, 36, 10, 242, 61, 0, - 0, 0, 0, 176, 91, 19, 63, 0, 0, 0, 0, 0, 0, 137, 189, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, - 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, - 13, 0, 180, 21, - }; + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = 7.384549826383591e-05; - test_msg.af1 = -2.8421709430404007e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = 1.341104507446289e-07; - test_msg.c_is = 1.1920928955078125e-07; - test_msg.c_rc = 315.78125; - test_msg.c_rs = 36.5625; - test_msg.c_uc = 2.0638108253479004e-06; - test_msg.c_us = 3.4142285585403442e-06; - test_msg.dn = 4.86198823561129e-09; - test_msg.ecc = 0.007922741584479809; - test_msg.healthy = 1; - test_msg.inc = 0.9669012918227122; - test_msg.inc_dot = 2.6251093463412166e-10; - test_msg.iode = 0; - test_msg.m0 = -1.588160855720083; - test_msg.omega0 = 1.237919941568746; - test_msg.omegadot = -8.295702692172441e-09; - test_msg.prn = 13; - test_msg.sqrta = 5153.57085609436; - test_msg.tgd = -9.313225746154785e-09; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = -1.9736022837941165; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - 7.38454982638e-05 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected 7.38454982638e-05, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -2.84217094304e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -2.84217094304e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - 1.34110450745e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected 1.34110450745e-07, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - 1.19209289551e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected 1.19209289551e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 315.78125 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 315.78125, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - 36.5625 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected 36.5625, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - 2.06381082535e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected 2.06381082535e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 3.41422855854e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 3.41422855854e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 4.86198823561e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 4.86198823561e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00792274158448 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00792274158448, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.966901291823 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.966901291823, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - 2.62510934634e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected 2.62510934634e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - -1.58816085572 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected -1.58816085572, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - 1.23791994157 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected 1.23791994157, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.29570269217e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.29570269217e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 13) - << "incorrect value for last_msg_.prn, expected 13, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.57085609 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.57085609, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -9.31322574615e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -9.31322574615e-09, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - -1.97360228379 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -1.97360228379, is " - << last_msg_.w; -} -class Test_auto_check_sbp_observation_msgEphemerisDepB2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgEphemerisDepB2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB2, Test) { - uint8_t encoded_frame[] = { - 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 56, 62, 0, - 0, 0, 0, 0, 40, 81, 192, 0, 0, 0, 0, 0, 129, 109, 64, - 0, 0, 0, 0, 0, 28, 205, 190, 0, 0, 0, 0, 0, 76, 223, - 62, 0, 0, 0, 0, 0, 0, 105, 190, 0, 0, 0, 0, 0, 0, - 92, 190, 134, 161, 223, 255, 243, 43, 51, 62, 146, 176, 113, 142, 234, - 164, 5, 64, 0, 0, 0, 56, 175, 140, 112, 63, 0, 0, 192, 90, - 171, 33, 180, 64, 36, 38, 237, 255, 200, 160, 237, 191, 204, 92, 63, - 154, 49, 91, 65, 190, 125, 94, 251, 132, 52, 61, 216, 63, 2, 139, - 28, 27, 231, 199, 238, 63, 124, 183, 4, 180, 194, 30, 247, 189, 0, - 0, 0, 0, 0, 104, 222, 190, 0, 0, 0, 0, 0, 0, 96, 61, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, - 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, - 0, 0, 222, 152, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = -7.249414920806885e-06; - test_msg.af1 = 4.547473508864641e-13; - test_msg.af2 = 0.0; - test_msg.c_ic = -4.6566128730773926e-08; - test_msg.c_is = -2.60770320892334e-08; - test_msg.c_rc = 236.03125; - test_msg.c_rs = -68.625; - test_msg.c_uc = -3.470107913017273e-06; - test_msg.c_us = 7.461756467819214e-06; - test_msg.dn = 4.4637573619826565e-09; - test_msg.ecc = 0.004040417145006359; - test_msg.healthy = 1; - test_msg.inc = 0.9619021920701416; - test_msg.inc_dot = -3.3644258561271105e-10; - test_msg.iode = 0; - test_msg.m0 = 2.7055255058713295; - test_msg.omega0 = -0.9258770941316397; - test_msg.omegadot = -8.082122367123182e-09; - test_msg.prn = 0; - test_msg.sqrta = 5153.669353485107; - test_msg.tgd = 5.587935447692871e-09; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = 0.37873566614641857; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -7.24941492081e-06 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -7.24941492081e-06, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - 4.54747350886e-13 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected 4.54747350886e-13, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - -4.65661287308e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected -4.65661287308e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - -2.60770320892e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected -2.60770320892e-08, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 236.03125 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 236.03125, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - -68.625 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected -68.625, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - -3.47010791302e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected -3.47010791302e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 7.46175646782e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 7.46175646782e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 4.46375736198e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 4.46375736198e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00404041714501 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00404041714501, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.96190219207 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.96190219207, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - -3.36442585613e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected -3.36442585613e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - 2.70552550587 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected 2.70552550587, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - -0.925877094132 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected -0.925877094132, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.08212236712e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.08212236712e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 0) - << "incorrect value for last_msg_.prn, expected 0, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.66935349 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.66935349, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - 5.58793544769e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected 5.58793544769e-09, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - 0.378735666146 * 100), 0.05) - << "incorrect value for last_msg_.w, expected 0.378735666146, is " - << last_msg_.w; -} -class Test_auto_check_sbp_observation_msgEphemerisDepB3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgEphemerisDepB3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB3, Test) { - uint8_t encoded_frame[] = { - 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 68, 190, 0, - 0, 0, 0, 0, 72, 66, 64, 0, 0, 0, 0, 128, 188, 115, 64, - 0, 0, 0, 0, 0, 80, 193, 62, 0, 0, 0, 0, 0, 164, 204, - 62, 0, 0, 0, 0, 0, 0, 130, 62, 0, 0, 0, 0, 0, 0, - 128, 62, 72, 181, 127, 6, 208, 225, 52, 62, 158, 174, 129, 91, 27, - 105, 249, 191, 0, 0, 0, 96, 204, 57, 128, 63, 0, 0, 160, 35, - 146, 33, 180, 64, 247, 169, 1, 36, 133, 206, 243, 63, 79, 11, 109, - 92, 156, 208, 65, 190, 103, 78, 3, 253, 223, 147, 255, 191, 164, 214, - 90, 250, 218, 240, 238, 63, 94, 239, 187, 37, 36, 10, 242, 61, 0, - 0, 0, 0, 176, 91, 19, 63, 0, 0, 0, 0, 0, 0, 137, 189, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, - 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, - 13, 0, 180, 21, - }; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = 7.384549826383591e-05; - test_msg.af1 = -2.8421709430404007e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = 1.341104507446289e-07; - test_msg.c_is = 1.1920928955078125e-07; - test_msg.c_rc = 315.78125; - test_msg.c_rs = 36.5625; - test_msg.c_uc = 2.0638108253479004e-06; - test_msg.c_us = 3.4142285585403442e-06; - test_msg.dn = 4.86198823561129e-09; - test_msg.ecc = 0.007922741584479809; - test_msg.healthy = 1; - test_msg.inc = 0.9669012918227122; - test_msg.inc_dot = 2.6251093463412166e-10; - test_msg.iode = 0; - test_msg.m0 = -1.588160855720083; - test_msg.omega0 = 1.237919941568746; - test_msg.omegadot = -8.295702692172441e-09; - test_msg.prn = 13; - test_msg.sqrta = 5153.57085609436; - test_msg.tgd = -9.313225746154785e-09; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = -1.9736022837941165; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - 7.38454982638e-05 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected 7.38454982638e-05, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -2.84217094304e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -2.84217094304e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - 1.34110450745e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected 1.34110450745e-07, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - 1.19209289551e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected 1.19209289551e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 315.78125 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 315.78125, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - 36.5625 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected 36.5625, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - 2.06381082535e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected 2.06381082535e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 3.41422855854e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 3.41422855854e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 4.86198823561e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 4.86198823561e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00792274158448 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00792274158448, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.966901291823 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.966901291823, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - 2.62510934634e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected 2.62510934634e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - -1.58816085572 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected -1.58816085572, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - 1.23791994157 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected 1.23791994157, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.29570269217e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.29570269217e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 13) - << "incorrect value for last_msg_.prn, expected 13, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.57085609 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.57085609, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -9.31322574615e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -9.31322574615e-09, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - -1.97360228379 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -1.97360228379, is " - << last_msg_.w; -} -class Test_auto_check_sbp_observation_msgEphemerisDepB4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgEphemerisDepB4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB4, Test) { - uint8_t encoded_frame[] = { - 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 128, 85, 190, 0, - 0, 0, 0, 0, 156, 69, 64, 0, 0, 0, 0, 128, 19, 115, 64, - 0, 0, 0, 0, 0, 160, 193, 62, 0, 0, 0, 0, 0, 152, 207, - 62, 0, 0, 0, 0, 0, 0, 97, 190, 0, 0, 0, 0, 0, 192, - 139, 190, 26, 26, 13, 149, 16, 152, 54, 62, 104, 7, 46, 214, 75, - 84, 5, 192, 0, 0, 0, 128, 230, 82, 132, 63, 0, 0, 160, 252, - 162, 33, 180, 64, 73, 6, 130, 54, 217, 171, 242, 63, 81, 224, 163, - 123, 238, 42, 66, 190, 206, 43, 141, 67, 243, 157, 5, 192, 113, 179, - 153, 187, 43, 92, 238, 63, 254, 236, 31, 43, 224, 157, 244, 61, 0, - 0, 0, 0, 232, 4, 26, 191, 0, 0, 0, 0, 0, 0, 134, 189, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, - 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, - 22, 0, 99, 61, - }; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = -9.925523772835732e-05; - test_msg.af1 = -2.5011104298755527e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = -3.166496753692627e-08; - test_msg.c_is = -2.0675361156463623e-07; - test_msg.c_rc = 305.21875; - test_msg.c_rs = 43.21875; - test_msg.c_uc = 2.1010637283325195e-06; - test_msg.c_us = 3.766268491744995e-06; - test_msg.dn = 5.26057626697412e-09; - test_msg.ecc = 0.009923744946718216; - test_msg.healthy = 1; - test_msg.inc = 0.9487513221807672; - test_msg.inc_dot = 3.000124967247105e-10; - test_msg.iode = 0; - test_msg.m0 = -2.666160271911327; - test_msg.omega0 = 1.1669551972594425; - test_msg.omegadot = -8.45999524990264e-09; - test_msg.prn = 22; - test_msg.sqrta = 5153.636667251587; - test_msg.tgd = -2.0023435354232788e-08; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = -2.7021241452652935; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -9.92552377284e-05 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -9.92552377284e-05, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -2.50111042988e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -2.50111042988e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - -3.16649675369e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected -3.16649675369e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - -2.06753611565e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected -2.06753611565e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 305.21875 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 305.21875, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - 43.21875 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected 43.21875, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - 2.10106372833e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected 2.10106372833e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 3.76626849174e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 3.76626849174e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 5.26057626697e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 5.26057626697e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00992374494672 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00992374494672, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.948751322181 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.948751322181, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - 3.00012496725e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected 3.00012496725e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - -2.66616027191 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected -2.66616027191, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - 1.16695519726 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected 1.16695519726, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -8.4599952499e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -8.4599952499e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 22) - << "incorrect value for last_msg_.prn, expected 22, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.63666725 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.63666725, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -2.00234353542e-08 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -2.00234353542e-08, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - -2.70212414527 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -2.70212414527, is " - << last_msg_.w; -} -class Test_auto_check_sbp_observation_msgEphemerisDepB5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgEphemerisDepB5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_msgEphemerisDepB5, Test) { - uint8_t encoded_frame[] = { - 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 77, 190, 0, - 0, 0, 0, 0, 122, 83, 192, 0, 0, 0, 0, 0, 233, 110, 64, - 0, 0, 0, 0, 0, 60, 207, 190, 0, 0, 0, 0, 0, 28, 222, - 62, 0, 0, 0, 0, 0, 128, 120, 62, 0, 0, 0, 0, 0, 0, - 108, 62, 10, 230, 183, 140, 214, 230, 50, 62, 54, 86, 196, 164, 252, - 10, 255, 63, 0, 0, 0, 36, 247, 191, 128, 63, 0, 0, 160, 5, - 193, 33, 180, 64, 186, 138, 81, 129, 88, 239, 1, 64, 94, 210, 120, - 170, 106, 25, 65, 190, 103, 213, 32, 155, 227, 194, 224, 191, 156, 47, - 104, 93, 101, 55, 239, 63, 196, 83, 100, 254, 51, 54, 4, 190, 0, - 0, 0, 0, 50, 242, 52, 63, 0, 0, 0, 0, 0, 0, 114, 189, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, - 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, - 30, 0, 170, 33, - }; +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ephemeris_dep_b_t test_msg{}; - test_msg.af0 = 0.0003196117468178272; - test_msg.af1 = -1.0231815394945443e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = 9.12696123123169e-08; - test_msg.c_is = 5.21540641784668e-08; - test_msg.c_rc = 247.28125; - test_msg.c_rs = -77.90625; - test_msg.c_uc = -3.723427653312683e-06; - test_msg.c_us = 7.178634405136108e-06; - test_msg.dn = 4.400897600764146e-09; - test_msg.ecc = 0.008178644930012524; - test_msg.healthy = 1; - test_msg.inc = 0.9755122017245301; - test_msg.inc_dot = -5.882387882209502e-10; - test_msg.iode = 0; - test_msg.m0 = 1.9401823459824192; - test_msg.omega0 = 2.241868028927766; - test_msg.omegadot = -7.962474526167494e-09; - test_msg.prn = 30; - test_msg.sqrta = 5153.7539920806885; - test_msg.tgd = -1.3504177331924438e-08; - test_msg.toc_tow = 410400.0; - test_msg.toc_wn = 1838; - test_msg.toe_tow = 410400.0; - test_msg.toe_wn = 1838; - test_msg.valid = 1; - test_msg.w = -0.5237901716088061; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - 0.000319611746818 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected 0.000319611746818, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -1.02318153949e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -1.02318153949e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - 9.12696123123e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected 9.12696123123e-08, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - 5.21540641785e-08 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected 5.21540641785e-08, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - 247.28125 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected 247.28125, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - -77.90625 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected -77.90625, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - -3.72342765331e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected -3.72342765331e-06, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 7.17863440514e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 7.17863440514e-06, is " - << last_msg_.c_us; - EXPECT_LT((last_msg_.dn * 100 - 4.40089760076e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 4.40089760076e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.00817864493001 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.00817864493001, is " - << last_msg_.ecc; - EXPECT_EQ(last_msg_.healthy, 1) - << "incorrect value for last_msg_.healthy, expected 1, is " - << last_msg_.healthy; - EXPECT_LT((last_msg_.inc * 100 - 0.975512201725 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.975512201725, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - -5.88238788221e-10 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected -5.88238788221e-10, " - "is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iode, 0) - << "incorrect value for last_msg_.iode, expected 0, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - 1.94018234598 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected 1.94018234598, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - 2.24186802893 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected 2.24186802893, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -7.96247452617e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -7.96247452617e-09, " - "is " - << last_msg_.omegadot; - EXPECT_EQ(last_msg_.prn, 30) - << "incorrect value for last_msg_.prn, expected 30, is " << last_msg_.prn; - EXPECT_LT((last_msg_.sqrta * 100 - 5153.75399208 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 5153.75399208, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -1.35041773319e-08 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -1.35041773319e-08, is " - << last_msg_.tgd; - EXPECT_LT((last_msg_.toc_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toc_tow, expected 410400.0, is " - << last_msg_.toc_tow; - EXPECT_EQ(last_msg_.toc_wn, 1838) - << "incorrect value for last_msg_.toc_wn, expected 1838, is " - << last_msg_.toc_wn; - EXPECT_LT((last_msg_.toe_tow * 100 - 410400.0 * 100), 0.05) - << "incorrect value for last_msg_.toe_tow, expected 410400.0, is " - << last_msg_.toe_tow; - EXPECT_EQ(last_msg_.toe_wn, 1838) - << "incorrect value for last_msg_.toe_wn, expected 1838, is " - << last_msg_.toe_wn; - EXPECT_EQ(last_msg_.valid, 1) - << "incorrect value for last_msg_.valid, expected 1, is " - << last_msg_.valid; - EXPECT_LT((last_msg_.w * 100 - -0.523790171609 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -0.523790171609, is " - << last_msg_.w; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); } + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgEphemerisDepB1 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgEphemerisDepB1() { + assign(test_msg_.af0, 7.384549826383591e-05); + assign(test_msg_.af1, -2.8421709430404007e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 1.341104507446289e-07); + assign(test_msg_.c_is, 1.1920928955078125e-07); + assign(test_msg_.c_rc, 315.78125); + assign(test_msg_.c_rs, 36.5625); + assign(test_msg_.c_uc, 2.0638108253479004e-06); + assign(test_msg_.c_us, 3.4142285585403442e-06); + assign(test_msg_.dn, 4.86198823561129e-09); + assign(test_msg_.ecc, 0.007922741584479809); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9669012918227122); + assign(test_msg_.inc_dot, 2.6251093463412166e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, -1.588160855720083); + assign(test_msg_.omega0, 1.237919941568746); + assign(test_msg_.omegadot, -8.295702692172441e-09); + assign(test_msg_.prn, 13); + assign(test_msg_.sqrta, 5153.57085609436); + assign(test_msg_.tgd, -9.313225746154785e-09); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -1.9736022837941165); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x15b4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { + 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 68, 190, 0, + 0, 0, 0, 0, 72, 66, 64, 0, 0, 0, 0, 128, 188, 115, 64, + 0, 0, 0, 0, 0, 80, 193, 62, 0, 0, 0, 0, 0, 164, 204, + 62, 0, 0, 0, 0, 0, 0, 130, 62, 0, 0, 0, 0, 0, 0, + 128, 62, 72, 181, 127, 6, 208, 225, 52, 62, 158, 174, 129, 91, 27, + 105, 249, 191, 0, 0, 0, 96, 204, 57, 128, 63, 0, 0, 160, 35, + 146, 33, 180, 64, 247, 169, 1, 36, 133, 206, 243, 63, 79, 11, 109, + 92, 156, 208, 65, 190, 103, 78, 3, 253, 223, 147, 255, 191, 164, 214, + 90, 250, 218, 240, 238, 63, 94, 239, 187, 37, 36, 10, 242, 61, 0, + 0, 0, 0, 176, 91, 19, 63, 0, 0, 0, 0, 0, 0, 137, 189, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, + 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, + 13, 0, 180, 21, + }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 0, 68, 190, 0, 0, 0, 0, 0, 72, 66, + 64, 0, 0, 0, 0, 128, 188, 115, 64, 0, 0, 0, 0, 0, 80, + 193, 62, 0, 0, 0, 0, 0, 164, 204, 62, 0, 0, 0, 0, 0, + 0, 130, 62, 0, 0, 0, 0, 0, 0, 128, 62, 72, 181, 127, 6, + 208, 225, 52, 62, 158, 174, 129, 91, 27, 105, 249, 191, 0, 0, 0, + 96, 204, 57, 128, 63, 0, 0, 160, 35, 146, 33, 180, 64, 247, 169, + 1, 36, 133, 206, 243, 63, 79, 11, 109, 92, 156, 208, 65, 190, 103, + 78, 3, 253, 223, 147, 255, 191, 164, 214, 90, 250, 218, 240, 238, 63, + 94, 239, 187, 37, 36, 10, 242, 61, 0, 0, 0, 0, 176, 91, 19, + 63, 0, 0, 0, 0, 0, 0, 137, 189, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 13, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgEphemerisDepB2 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgEphemerisDepB2() { + assign(test_msg_.af0, -7.249414920806885e-06); + assign(test_msg_.af1, 4.547473508864641e-13); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, -4.6566128730773926e-08); + assign(test_msg_.c_is, -2.60770320892334e-08); + assign(test_msg_.c_rc, 236.03125); + assign(test_msg_.c_rs, -68.625); + assign(test_msg_.c_uc, -3.470107913017273e-06); + assign(test_msg_.c_us, 7.461756467819214e-06); + assign(test_msg_.dn, 4.4637573619826565e-09); + assign(test_msg_.ecc, 0.004040417145006359); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9619021920701416); + assign(test_msg_.inc_dot, -3.3644258561271105e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, 2.7055255058713295); + assign(test_msg_.omega0, -0.9258770941316397); + assign(test_msg_.omegadot, -8.082122367123182e-09); + assign(test_msg_.prn, 0); + assign(test_msg_.sqrta, 5153.669353485107); + assign(test_msg_.tgd, 5.587935447692871e-09); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, 0.37873566614641857); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x98de; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { + 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 56, 62, 0, + 0, 0, 0, 0, 40, 81, 192, 0, 0, 0, 0, 0, 129, 109, 64, + 0, 0, 0, 0, 0, 28, 205, 190, 0, 0, 0, 0, 0, 76, 223, + 62, 0, 0, 0, 0, 0, 0, 105, 190, 0, 0, 0, 0, 0, 0, + 92, 190, 134, 161, 223, 255, 243, 43, 51, 62, 146, 176, 113, 142, 234, + 164, 5, 64, 0, 0, 0, 56, 175, 140, 112, 63, 0, 0, 192, 90, + 171, 33, 180, 64, 36, 38, 237, 255, 200, 160, 237, 191, 204, 92, 63, + 154, 49, 91, 65, 190, 125, 94, 251, 132, 52, 61, 216, 63, 2, 139, + 28, 27, 231, 199, 238, 63, 124, 183, 4, 180, 194, 30, 247, 189, 0, + 0, 0, 0, 0, 104, 222, 190, 0, 0, 0, 0, 0, 0, 96, 61, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, + 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, + 0, 0, 222, 152, + }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 0, 56, 62, 0, 0, 0, 0, 0, 40, 81, + 192, 0, 0, 0, 0, 0, 129, 109, 64, 0, 0, 0, 0, 0, 28, + 205, 190, 0, 0, 0, 0, 0, 76, 223, 62, 0, 0, 0, 0, 0, + 0, 105, 190, 0, 0, 0, 0, 0, 0, 92, 190, 134, 161, 223, 255, + 243, 43, 51, 62, 146, 176, 113, 142, 234, 164, 5, 64, 0, 0, 0, + 56, 175, 140, 112, 63, 0, 0, 192, 90, 171, 33, 180, 64, 36, 38, + 237, 255, 200, 160, 237, 191, 204, 92, 63, 154, 49, 91, 65, 190, 125, + 94, 251, 132, 52, 61, 216, 63, 2, 139, 28, 27, 231, 199, 238, 63, + 124, 183, 4, 180, 194, 30, 247, 189, 0, 0, 0, 0, 0, 104, 222, + 190, 0, 0, 0, 0, 0, 0, 96, 61, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgEphemerisDepB3 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgEphemerisDepB3() { + assign(test_msg_.af0, 7.384549826383591e-05); + assign(test_msg_.af1, -2.8421709430404007e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 1.341104507446289e-07); + assign(test_msg_.c_is, 1.1920928955078125e-07); + assign(test_msg_.c_rc, 315.78125); + assign(test_msg_.c_rs, 36.5625); + assign(test_msg_.c_uc, 2.0638108253479004e-06); + assign(test_msg_.c_us, 3.4142285585403442e-06); + assign(test_msg_.dn, 4.86198823561129e-09); + assign(test_msg_.ecc, 0.007922741584479809); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9669012918227122); + assign(test_msg_.inc_dot, 2.6251093463412166e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, -1.588160855720083); + assign(test_msg_.omega0, 1.237919941568746); + assign(test_msg_.omegadot, -8.295702692172441e-09); + assign(test_msg_.prn, 13); + assign(test_msg_.sqrta, 5153.57085609436); + assign(test_msg_.tgd, -9.313225746154785e-09); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -1.9736022837941165); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x15b4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { + 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 68, 190, 0, + 0, 0, 0, 0, 72, 66, 64, 0, 0, 0, 0, 128, 188, 115, 64, + 0, 0, 0, 0, 0, 80, 193, 62, 0, 0, 0, 0, 0, 164, 204, + 62, 0, 0, 0, 0, 0, 0, 130, 62, 0, 0, 0, 0, 0, 0, + 128, 62, 72, 181, 127, 6, 208, 225, 52, 62, 158, 174, 129, 91, 27, + 105, 249, 191, 0, 0, 0, 96, 204, 57, 128, 63, 0, 0, 160, 35, + 146, 33, 180, 64, 247, 169, 1, 36, 133, 206, 243, 63, 79, 11, 109, + 92, 156, 208, 65, 190, 103, 78, 3, 253, 223, 147, 255, 191, 164, 214, + 90, 250, 218, 240, 238, 63, 94, 239, 187, 37, 36, 10, 242, 61, 0, + 0, 0, 0, 176, 91, 19, 63, 0, 0, 0, 0, 0, 0, 137, 189, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, + 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, + 13, 0, 180, 21, + }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 0, 68, 190, 0, 0, 0, 0, 0, 72, 66, + 64, 0, 0, 0, 0, 128, 188, 115, 64, 0, 0, 0, 0, 0, 80, + 193, 62, 0, 0, 0, 0, 0, 164, 204, 62, 0, 0, 0, 0, 0, + 0, 130, 62, 0, 0, 0, 0, 0, 0, 128, 62, 72, 181, 127, 6, + 208, 225, 52, 62, 158, 174, 129, 91, 27, 105, 249, 191, 0, 0, 0, + 96, 204, 57, 128, 63, 0, 0, 160, 35, 146, 33, 180, 64, 247, 169, + 1, 36, 133, 206, 243, 63, 79, 11, 109, 92, 156, 208, 65, 190, 103, + 78, 3, 253, 223, 147, 255, 191, 164, 214, 90, 250, 218, 240, 238, 63, + 94, 239, 187, 37, 36, 10, 242, 61, 0, 0, 0, 0, 176, 91, 19, + 63, 0, 0, 0, 0, 0, 0, 137, 189, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 13, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgEphemerisDepB4 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgEphemerisDepB4() { + assign(test_msg_.af0, -9.925523772835732e-05); + assign(test_msg_.af1, -2.5011104298755527e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, -3.166496753692627e-08); + assign(test_msg_.c_is, -2.0675361156463623e-07); + assign(test_msg_.c_rc, 305.21875); + assign(test_msg_.c_rs, 43.21875); + assign(test_msg_.c_uc, 2.1010637283325195e-06); + assign(test_msg_.c_us, 3.766268491744995e-06); + assign(test_msg_.dn, 5.26057626697412e-09); + assign(test_msg_.ecc, 0.009923744946718216); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9487513221807672); + assign(test_msg_.inc_dot, 3.000124967247105e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, -2.666160271911327); + assign(test_msg_.omega0, 1.1669551972594425); + assign(test_msg_.omegadot, -8.45999524990264e-09); + assign(test_msg_.prn, 22); + assign(test_msg_.sqrta, 5153.636667251587); + assign(test_msg_.tgd, -2.0023435354232788e-08); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -2.7021241452652935); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x3d63; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { + 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 128, 85, 190, 0, + 0, 0, 0, 0, 156, 69, 64, 0, 0, 0, 0, 128, 19, 115, 64, + 0, 0, 0, 0, 0, 160, 193, 62, 0, 0, 0, 0, 0, 152, 207, + 62, 0, 0, 0, 0, 0, 0, 97, 190, 0, 0, 0, 0, 0, 192, + 139, 190, 26, 26, 13, 149, 16, 152, 54, 62, 104, 7, 46, 214, 75, + 84, 5, 192, 0, 0, 0, 128, 230, 82, 132, 63, 0, 0, 160, 252, + 162, 33, 180, 64, 73, 6, 130, 54, 217, 171, 242, 63, 81, 224, 163, + 123, 238, 42, 66, 190, 206, 43, 141, 67, 243, 157, 5, 192, 113, 179, + 153, 187, 43, 92, 238, 63, 254, 236, 31, 43, 224, 157, 244, 61, 0, + 0, 0, 0, 232, 4, 26, 191, 0, 0, 0, 0, 0, 0, 134, 189, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, + 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, + 22, 0, 99, 61, + }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 128, 85, 190, 0, 0, 0, 0, 0, 156, 69, + 64, 0, 0, 0, 0, 128, 19, 115, 64, 0, 0, 0, 0, 0, 160, + 193, 62, 0, 0, 0, 0, 0, 152, 207, 62, 0, 0, 0, 0, 0, + 0, 97, 190, 0, 0, 0, 0, 0, 192, 139, 190, 26, 26, 13, 149, + 16, 152, 54, 62, 104, 7, 46, 214, 75, 84, 5, 192, 0, 0, 0, + 128, 230, 82, 132, 63, 0, 0, 160, 252, 162, 33, 180, 64, 73, 6, + 130, 54, 217, 171, 242, 63, 81, 224, 163, 123, 238, 42, 66, 190, 206, + 43, 141, 67, 243, 157, 5, 192, 113, 179, 153, 187, 43, 92, 238, 63, + 254, 236, 31, 43, 224, 157, 244, 61, 0, 0, 0, 0, 232, 4, 26, + 191, 0, 0, 0, 0, 0, 0, 134, 189, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 22, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgEphemerisDepB5 + : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgEphemerisDepB5() { + assign(test_msg_.af0, 0.0003196117468178272); + assign(test_msg_.af1, -1.0231815394945443e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, 9.12696123123169e-08); + assign(test_msg_.c_is, 5.21540641784668e-08); + assign(test_msg_.c_rc, 247.28125); + assign(test_msg_.c_rs, -77.90625); + assign(test_msg_.c_uc, -3.723427653312683e-06); + assign(test_msg_.c_us, 7.178634405136108e-06); + assign(test_msg_.dn, 4.400897600764146e-09); + assign(test_msg_.ecc, 0.008178644930012524); + assign(test_msg_.healthy, 1); + assign(test_msg_.inc, 0.9755122017245301); + assign(test_msg_.inc_dot, -5.882387882209502e-10); + assign(test_msg_.iode, 0); + assign(test_msg_.m0, 1.9401823459824192); + assign(test_msg_.omega0, 2.241868028927766); + assign(test_msg_.omegadot, -7.962474526167494e-09); + assign(test_msg_.prn, 30); + assign(test_msg_.sqrta, 5153.7539920806885); + assign(test_msg_.tgd, -1.3504177331924438e-08); + assign(test_msg_.toc_tow, 410400.0); + assign(test_msg_.toc_wn, 1838); + assign(test_msg_.toe_tow, 410400.0); + assign(test_msg_.toe_wn, 1838); + assign(test_msg_.valid, 1); + assign(test_msg_.w, -0.5237901716088061); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_dep_b, + sizeof(msg->ephemeris_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisDepB); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x21aa; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 176; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ephemeris_dep_b_t &lesser, + const sbp_msg_ephemeris_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisDepB, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ephemeris_dep_b_t test_msg_{}; + uint8_t encoded_frame_[176 + 8] = { + 85, 70, 0, 195, 4, 176, 0, 0, 0, 0, 0, 0, 77, 190, 0, + 0, 0, 0, 0, 122, 83, 192, 0, 0, 0, 0, 0, 233, 110, 64, + 0, 0, 0, 0, 0, 60, 207, 190, 0, 0, 0, 0, 0, 28, 222, + 62, 0, 0, 0, 0, 0, 128, 120, 62, 0, 0, 0, 0, 0, 0, + 108, 62, 10, 230, 183, 140, 214, 230, 50, 62, 54, 86, 196, 164, 252, + 10, 255, 63, 0, 0, 0, 36, 247, 191, 128, 63, 0, 0, 160, 5, + 193, 33, 180, 64, 186, 138, 81, 129, 88, 239, 1, 64, 94, 210, 120, + 170, 106, 25, 65, 190, 103, 213, 32, 155, 227, 194, 224, 191, 156, 47, + 104, 93, 101, 55, 239, 63, 196, 83, 100, 254, 51, 54, 4, 190, 0, + 0, 0, 0, 50, 242, 52, 63, 0, 0, 0, 0, 0, 0, 114, 189, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 12, 25, + 65, 46, 7, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 1, 1, + 30, 0, 170, 33, + }; + uint8_t encoded_payload_[176] = { + 0, 0, 0, 0, 0, 0, 77, 190, 0, 0, 0, 0, 0, 122, 83, + 192, 0, 0, 0, 0, 0, 233, 110, 64, 0, 0, 0, 0, 0, 60, + 207, 190, 0, 0, 0, 0, 0, 28, 222, 62, 0, 0, 0, 0, 0, + 128, 120, 62, 0, 0, 0, 0, 0, 0, 108, 62, 10, 230, 183, 140, + 214, 230, 50, 62, 54, 86, 196, 164, 252, 10, 255, 63, 0, 0, 0, + 36, 247, 191, 128, 63, 0, 0, 160, 5, 193, 33, 180, 64, 186, 138, + 81, 129, 88, 239, 1, 64, 94, 210, 120, 170, 106, 25, 65, 190, 103, + 213, 32, 155, 227, 194, 224, 191, 156, 47, 104, 93, 101, 55, 239, 63, + 196, 83, 100, 254, 51, 54, 4, 190, 0, 0, 0, 0, 50, 242, 52, + 63, 0, 0, 0, 0, 0, 0, 114, 189, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 128, 12, 25, 65, 46, 7, 0, 0, 0, + 0, 128, 12, 25, 65, 46, 7, 1, 1, 30, 0, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + + for (uint8_t i = 0; i < 176; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_dep_b_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.healthy, greater.healthy); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.prn, greater.prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_tow, greater.toc_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toc_wn, greater.toc_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_tow, greater.toe_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.toe_wn, greater.toe_wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.valid, greater.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_dep_b_t lesser = info.test_msg; + sbp_msg_ephemeris_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_DEP_B"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[176]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 176); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 176), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 176); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisDepB5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_msgEphemerisQzss.cc b/c/test/cpp/auto_check_sbp_observation_msgEphemerisQzss.cc index bc667d9f2b..dc87faff57 100644 --- a/c/test/cpp/auto_check_sbp_observation_msgEphemerisQzss.cc +++ b/c/test/cpp/auto_check_sbp_observation_msgEphemerisQzss.cc @@ -16,66 +16,397 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_msgEphemerisQzss0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_msgEphemerisQzss0 + : public ::testing::Test { public: - Test_auto_check_sbp_observation_msgEphemerisQzss0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_msgEphemerisQzss0() { + assign(test_msg_.af0, -0.00036908406764268875); + assign(test_msg_.af1, -4.774847184307873e-12); + assign(test_msg_.af2, 0.0); + assign(test_msg_.c_ic, -1.1753290891647339e-06); + assign(test_msg_.c_is, 1.6205012798309326e-07); + assign(test_msg_.c_rc, -36.90625); + assign(test_msg_.c_rs, -457.8125); + assign(test_msg_.c_uc, -1.6197562217712402e-05); + assign(test_msg_.c_us, 8.247792720794678e-06); + assign(test_msg_.common.fit_interval, 14400); + assign(test_msg_.common.health_bits, 0); + assign(test_msg_.common.sid.code, 31); + assign(test_msg_.common.sid.sat, 193); + assign(test_msg_.common.toe.tow, 450000); + assign(test_msg_.common.toe.wn, 2154); + assign(test_msg_.common.ura, 2.0); + assign(test_msg_.common.valid, 0); + assign(test_msg_.dn, 2.678325848736433e-09); + assign(test_msg_.ecc, 0.07550019584596157); + assign(test_msg_.inc, 0.7309715119432375); + assign(test_msg_.inc_dot, 2.0000833114980698e-11); + assign(test_msg_.iodc, 817); + assign(test_msg_.iode, 49); + assign(test_msg_.m0, 0.30694242158961144); + assign(test_msg_.omega0, -1.1693743795366662); + assign(test_msg_.omegadot, -2.7936877968817684e-09); + assign(test_msg_.sqrta, 6493.172393798828); + assign(test_msg_.tgd, -5.587935447692871e-09); + assign(test_msg_.toc.tow, 450000); + assign(test_msg_.toc.wn, 2154); + assign(test_msg_.w, -1.5662079690885238); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_qzss_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ephemeris_qzss_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEphemerisQzss, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ephemeris_qzss_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEphemerisQzss); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ephemeris_qzss, + sizeof(msg->ephemeris_qzss)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ephemeris_qzss_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ephemeris_qzss, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEphemerisQzss); + info.sender_id = 61568; + info.preamble = 0x55; + info.crc = 0x177e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 139; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ephemeris_qzss_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ephemeris_qzss_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ephemeris_qzss_t &lesser, + const sbp_msg_ephemeris_qzss_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ephemeris_qzss_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ephemeris_qzss_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ephemeris_qzss_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ephemeris_qzss_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEphemerisQzss, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEphemerisQzss, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgEphemerisQzss, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgEphemerisQzss, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_msgEphemerisQzss0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_ephemeris_qzss_t test_msg_{}; + uint8_t encoded_frame_[139 + 8] = { 85, 142, 0, 128, 240, 139, 193, 31, 208, 221, 6, 0, 106, 8, 0, 0, 0, 64, 64, 56, 0, 0, 0, 0, 0, 0, 192, 177, 0, 232, 228, 195, 0, 160, 19, 194, 0, 224, 135, 183, 0, 96, 10, 55, 0, @@ -87,145 +418,599 @@ TEST_F(Test_auto_check_sbp_observation_msgEphemerisQzss0, Test) { 187, 253, 181, 61, 160, 129, 193, 185, 0, 0, 168, 172, 0, 0, 0, 0, 208, 221, 6, 0, 106, 8, 49, 49, 3, 126, 23, }; + uint8_t encoded_payload_[139] = { + 193, 31, 208, 221, 6, 0, 106, 8, 0, 0, 0, 64, 64, 56, + 0, 0, 0, 0, 0, 0, 192, 177, 0, 232, 228, 195, 0, 160, + 19, 194, 0, 224, 135, 183, 0, 96, 10, 55, 0, 192, 157, 181, + 0, 0, 46, 52, 167, 72, 107, 105, 179, 1, 39, 62, 15, 224, + 158, 211, 241, 164, 211, 63, 0, 0, 0, 24, 251, 83, 179, 63, + 0, 0, 0, 34, 44, 93, 185, 64, 143, 62, 206, 232, 193, 181, + 242, 191, 207, 216, 69, 106, 98, 255, 39, 190, 65, 132, 95, 22, + 48, 15, 249, 191, 249, 82, 67, 94, 30, 100, 231, 63, 117, 167, + 187, 233, 187, 253, 181, 61, 160, 129, 193, 185, 0, 0, 168, 172, + 0, 0, 0, 0, 208, 221, 6, 0, 106, 8, 49, 49, 3, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ephemeris_qzss_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEphemerisQzss, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ephemeris_qzss_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEphemerisQzss, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + + EXPECT_EQ(sbp_msg_ephemeris_qzss_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + + for (uint8_t i = 0; i < 139; i++) { + EXPECT_EQ( + sbp_msg_ephemeris_qzss_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_qzss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ephemeris_qzss_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEphemerisQzss, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_qzss_t msg{}; + + EXPECT_EQ(sbp_msg_ephemeris_qzss_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_qzss_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ephemeris_qzss_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ephemeris_qzss_t test_msg{}; - test_msg.af0 = -0.00036908406764268875; - test_msg.af1 = -4.774847184307873e-12; - test_msg.af2 = 0.0; - test_msg.c_ic = -1.1753290891647339e-06; - test_msg.c_is = 1.6205012798309326e-07; - test_msg.c_rc = -36.90625; - test_msg.c_rs = -457.8125; - test_msg.c_uc = -1.6197562217712402e-05; - test_msg.c_us = 8.247792720794678e-06; - test_msg.common.fit_interval = 14400; - test_msg.common.health_bits = 0; - test_msg.common.sid.code = 31; - test_msg.common.sid.sat = 193; - test_msg.common.toe.tow = 450000; - test_msg.common.toe.wn = 2154; - test_msg.common.ura = 2.0; - test_msg.common.valid = 0; - test_msg.dn = 2.678325848736433e-09; - test_msg.ecc = 0.07550019584596157; - test_msg.inc = 0.7309715119432375; - test_msg.inc_dot = 2.0000833114980698e-11; - test_msg.iodc = 817; - test_msg.iode = 49; - test_msg.m0 = 0.30694242158961144; - test_msg.omega0 = -1.1693743795366662; - test_msg.omegadot = -2.7936877968817684e-09; - test_msg.sqrta = 6493.172393798828; - test_msg.tgd = -5.587935447692871e-09; - test_msg.toc.tow = 450000; - test_msg.toc.wn = 2154; - test_msg.w = -1.5662079690885238; - - EXPECT_EQ(send_message(61568, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61568); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_LT((last_msg_.af0 * 100 - -0.000369084067643 * 100), 0.05) - << "incorrect value for last_msg_.af0, expected -0.000369084067643, is " - << last_msg_.af0; - EXPECT_LT((last_msg_.af1 * 100 - -4.77484718431e-12 * 100), 0.05) - << "incorrect value for last_msg_.af1, expected -4.77484718431e-12, is " - << last_msg_.af1; - EXPECT_LT((last_msg_.af2 * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.af2, expected 0.0, is " - << last_msg_.af2; - EXPECT_LT((last_msg_.c_ic * 100 - -1.17532908916e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_ic, expected -1.17532908916e-06, is " - << last_msg_.c_ic; - EXPECT_LT((last_msg_.c_is * 100 - 1.62050127983e-07 * 100), 0.05) - << "incorrect value for last_msg_.c_is, expected 1.62050127983e-07, is " - << last_msg_.c_is; - EXPECT_LT((last_msg_.c_rc * 100 - -36.90625 * 100), 0.05) - << "incorrect value for last_msg_.c_rc, expected -36.90625, is " - << last_msg_.c_rc; - EXPECT_LT((last_msg_.c_rs * 100 - -457.8125 * 100), 0.05) - << "incorrect value for last_msg_.c_rs, expected -457.8125, is " - << last_msg_.c_rs; - EXPECT_LT((last_msg_.c_uc * 100 - -1.61975622177e-05 * 100), 0.05) - << "incorrect value for last_msg_.c_uc, expected -1.61975622177e-05, is " - << last_msg_.c_uc; - EXPECT_LT((last_msg_.c_us * 100 - 8.24779272079e-06 * 100), 0.05) - << "incorrect value for last_msg_.c_us, expected 8.24779272079e-06, is " - << last_msg_.c_us; - EXPECT_EQ(last_msg_.common.fit_interval, 14400) - << "incorrect value for last_msg_.common.fit_interval, expected 14400, " - "is " - << last_msg_.common.fit_interval; - EXPECT_EQ(last_msg_.common.health_bits, 0) - << "incorrect value for last_msg_.common.health_bits, expected 0, is " - << last_msg_.common.health_bits; - EXPECT_EQ(last_msg_.common.sid.code, 31) - << "incorrect value for last_msg_.common.sid.code, expected 31, is " - << last_msg_.common.sid.code; - EXPECT_EQ(last_msg_.common.sid.sat, 193) - << "incorrect value for last_msg_.common.sid.sat, expected 193, is " - << last_msg_.common.sid.sat; - EXPECT_EQ(last_msg_.common.toe.tow, 450000) - << "incorrect value for last_msg_.common.toe.tow, expected 450000, is " - << last_msg_.common.toe.tow; - EXPECT_EQ(last_msg_.common.toe.wn, 2154) - << "incorrect value for last_msg_.common.toe.wn, expected 2154, is " - << last_msg_.common.toe.wn; - EXPECT_LT((last_msg_.common.ura * 100 - 2.0 * 100), 0.05) - << "incorrect value for last_msg_.common.ura, expected 2.0, is " - << last_msg_.common.ura; - EXPECT_EQ(last_msg_.common.valid, 0) - << "incorrect value for last_msg_.common.valid, expected 0, is " - << last_msg_.common.valid; - EXPECT_LT((last_msg_.dn * 100 - 2.67832584874e-09 * 100), 0.05) - << "incorrect value for last_msg_.dn, expected 2.67832584874e-09, is " - << last_msg_.dn; - EXPECT_LT((last_msg_.ecc * 100 - 0.075500195846 * 100), 0.05) - << "incorrect value for last_msg_.ecc, expected 0.075500195846, is " - << last_msg_.ecc; - EXPECT_LT((last_msg_.inc * 100 - 0.730971511943 * 100), 0.05) - << "incorrect value for last_msg_.inc, expected 0.730971511943, is " - << last_msg_.inc; - EXPECT_LT((last_msg_.inc_dot * 100 - 2.0000833115e-11 * 100), 0.05) - << "incorrect value for last_msg_.inc_dot, expected 2.0000833115e-11, is " - << last_msg_.inc_dot; - EXPECT_EQ(last_msg_.iodc, 817) - << "incorrect value for last_msg_.iodc, expected 817, is " - << last_msg_.iodc; - EXPECT_EQ(last_msg_.iode, 49) - << "incorrect value for last_msg_.iode, expected 49, is " - << last_msg_.iode; - EXPECT_LT((last_msg_.m0 * 100 - 0.30694242159 * 100), 0.05) - << "incorrect value for last_msg_.m0, expected 0.30694242159, is " - << last_msg_.m0; - EXPECT_LT((last_msg_.omega0 * 100 - -1.16937437954 * 100), 0.05) - << "incorrect value for last_msg_.omega0, expected -1.16937437954, is " - << last_msg_.omega0; - EXPECT_LT((last_msg_.omegadot * 100 - -2.79368779688e-09 * 100), 0.05) - << "incorrect value for last_msg_.omegadot, expected -2.79368779688e-09, " - "is " - << last_msg_.omegadot; - EXPECT_LT((last_msg_.sqrta * 100 - 6493.1723938 * 100), 0.05) - << "incorrect value for last_msg_.sqrta, expected 6493.1723938, is " - << last_msg_.sqrta; - EXPECT_LT((last_msg_.tgd * 100 - -5.58793544769e-09 * 100), 0.05) - << "incorrect value for last_msg_.tgd, expected -5.58793544769e-09, is " - << last_msg_.tgd; - EXPECT_EQ(last_msg_.toc.tow, 450000) - << "incorrect value for last_msg_.toc.tow, expected 450000, is " - << last_msg_.toc.tow; - EXPECT_EQ(last_msg_.toc.wn, 2154) - << "incorrect value for last_msg_.toc.wn, expected 2154, is " - << last_msg_.toc.wn; - EXPECT_LT((last_msg_.w * 100 - -1.56620796909 * 100), 0.05) - << "incorrect value for last_msg_.w, expected -1.56620796909, is " - << last_msg_.w; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ephemeris_qzss_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisQzss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgEphemerisQzss, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEphemerisQzss, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.af0, greater.af0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.af1, greater.af1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.af2, greater.af2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_ic, greater.c_ic); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_is, greater.c_is); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_rc, greater.c_rc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_rs, greater.c_rs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_uc, greater.c_uc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.c_us, greater.c_us); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.fit_interval, + greater.common.fit_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.health_bits, greater.common.health_bits); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.code, greater.common.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.sid.sat, greater.common.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.tow, greater.common.toe.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.toe.wn, greater.common.toe.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.ura, greater.common.ura); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.common.valid, greater.common.valid); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.dn, greater.dn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.ecc, greater.ecc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.inc, greater.inc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.inc_dot, greater.inc_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.iodc, greater.iodc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.iode, greater.iode); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.m0, greater.m0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.omega0, greater.omega0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.omegadot, greater.omegadot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.sqrta, greater.sqrta); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.tgd, greater.tgd); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.toc.tow, greater.toc.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.toc.wn, greater.toc.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ephemeris_qzss_t lesser = info.test_msg; + sbp_msg_ephemeris_qzss_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEphemerisQzss); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_EPHEMERIS_QZSS"); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ephemeris_qzss_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ephemeris_qzss_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ephemeris_qzss, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ephemeris_qzss, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[139]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 139); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 139), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ephemeris_qzss_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 139); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEphemerisQzss, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgEphemerisQzss0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEphemerisQzss, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_msgObsDepA.cc b/c/test/cpp/auto_check_sbp_observation_msgObsDepA.cc index bd1f0edeed..87f5a6f9e9 100644 --- a/c/test/cpp/auto_check_sbp_observation_msgObsDepA.cc +++ b/c/test/cpp/auto_check_sbp_observation_msgObsDepA.cc @@ -16,66 +16,411 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_observation_msgObsDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_observation_msgObsDepA0 : public ::testing::Test { public: - Test_auto_check_sbp_observation_msgObsDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_observation_msgObsDepA0() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 407084600); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 7); + + assign(test_msg_.obs[0].L.f, 33); + assign(test_msg_.obs[0].L.i, -36108); + assign(test_msg_.obs[0].P, 2046421816); + assign(test_msg_.obs[0].cn0, 46); + assign(test_msg_.obs[0].lock, 55875); + assign(test_msg_.obs[0].prn, 0); + + assign(test_msg_.obs[1].L.f, 98); + assign(test_msg_.obs[1].L.i, 203030); + assign(test_msg_.obs[1].P, 2085014510); + assign(test_msg_.obs[1].cn0, 43); + assign(test_msg_.obs[1].lock, 40376); + assign(test_msg_.obs[1].prn, 2); + + assign(test_msg_.obs[2].L.f, 185); + assign(test_msg_.obs[2].L.i, -178306); + assign(test_msg_.obs[2].P, 2110096816); + assign(test_msg_.obs[2].cn0, 39); + assign(test_msg_.obs[2].lock, 14148); + assign(test_msg_.obs[2].prn, 3); + + assign(test_msg_.obs[3].L.f, 139); + assign(test_msg_.obs[3].L.i, -137374); + assign(test_msg_.obs[3].P, 2208476476); + assign(test_msg_.obs[3].cn0, 30); + assign(test_msg_.obs[3].lock, 4129); + assign(test_msg_.obs[3].prn, 10); + + assign(test_msg_.obs[4].L.f, 40); + assign(test_msg_.obs[4].L.i, -167638); + assign(test_msg_.obs[4].P, 2298000000); + assign(test_msg_.obs[4].cn0, 20); + assign(test_msg_.obs[4].lock, 18218); + assign(test_msg_.obs[4].prn, 13); + + assign(test_msg_.obs[5].L.f, 64); + assign(test_msg_.obs[5].L.i, 209919); + assign(test_msg_.obs[5].P, 2266101494); + assign(test_msg_.obs[5].cn0, 27); + assign(test_msg_.obs[5].lock, 63852); + assign(test_msg_.obs[5].prn, 22); + + assign(test_msg_.obs[6].L.f, 31); + assign(test_msg_.obs[6].L.i, -53117); + assign(test_msg_.obs[6].P, 1987193298); + assign(test_msg_.obs[6].cn0, 52); + assign(test_msg_.obs[6].lock, 15074); + assign(test_msg_.obs[6].prn, 30); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xd917; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 98; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_observation_msgObsDepA0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[98 + 8] = { 85, 69, 0, 195, 4, 98, 56, 158, 67, 24, 46, 7, 32, 56, 235, 249, 121, 244, 114, 255, 255, 33, 46, 67, 218, 0, 238, 203, 70, 124, 22, 25, 3, 0, 98, 43, 184, 157, 2, 176, 133, 197, @@ -85,1159 +430,5418 @@ TEST_F(Test_auto_check_sbp_observation_msgObsDepA0, Test) { 3, 0, 64, 27, 108, 249, 22, 210, 41, 114, 118, 131, 48, 255, 255, 31, 52, 226, 58, 30, 23, 217, }; + uint8_t encoded_payload_[98] = { + 56, 158, 67, 24, 46, 7, 32, 56, 235, 249, 121, 244, 114, 255, + 255, 33, 46, 67, 218, 0, 238, 203, 70, 124, 22, 25, 3, 0, + 98, 43, 184, 157, 2, 176, 133, 197, 125, 126, 71, 253, 255, 185, + 39, 68, 55, 3, 60, 173, 162, 131, 98, 231, 253, 255, 139, 30, + 33, 16, 10, 128, 178, 248, 136, 42, 113, 253, 255, 40, 20, 42, + 71, 13, 246, 246, 17, 135, 255, 51, 3, 0, 64, 27, 108, 249, + 22, 210, 41, 114, 118, 131, 48, 255, 255, 31, 52, 226, 58, 30, + }; +}; - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 407084600; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 7; - - test_msg.obs[0].L.f = 33; - test_msg.obs[0].L.i = -36108; - test_msg.obs[0].P = 2046421816; - test_msg.obs[0].cn0 = 46; - test_msg.obs[0].lock = 55875; - test_msg.obs[0].prn = 0; - - test_msg.obs[1].L.f = 98; - test_msg.obs[1].L.i = 203030; - test_msg.obs[1].P = 2085014510; - test_msg.obs[1].cn0 = 43; - test_msg.obs[1].lock = 40376; - test_msg.obs[1].prn = 2; - - test_msg.obs[2].L.f = 185; - test_msg.obs[2].L.i = -178306; - test_msg.obs[2].P = 2110096816; - test_msg.obs[2].cn0 = 39; - test_msg.obs[2].lock = 14148; - test_msg.obs[2].prn = 3; - - test_msg.obs[3].L.f = 139; - test_msg.obs[3].L.i = -137374; - test_msg.obs[3].P = 2208476476; - test_msg.obs[3].cn0 = 30; - test_msg.obs[3].lock = 4129; - test_msg.obs[3].prn = 10; - - test_msg.obs[4].L.f = 40; - test_msg.obs[4].L.i = -167638; - test_msg.obs[4].P = 2298000000; - test_msg.obs[4].cn0 = 20; - test_msg.obs[4].lock = 18218; - test_msg.obs[4].prn = 13; - - test_msg.obs[5].L.f = 64; - test_msg.obs[5].L.i = 209919; - test_msg.obs[5].P = 2266101494; - test_msg.obs[5].cn0 = 27; - test_msg.obs[5].lock = 63852; - test_msg.obs[5].prn = 22; - - test_msg.obs[6].L.f = 31; - test_msg.obs[6].L.i = -53117; - test_msg.obs[6].P = 1987193298; - test_msg.obs[6].cn0 = 52; - test_msg.obs[6].lock = 15074; - test_msg.obs[6].prn = 30; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407084600) - << "incorrect value for last_msg_.header.t.tow, expected 407084600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 7) - << "incorrect value for last_msg_.n_obs, expected 7, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 33) - << "incorrect value for last_msg_.obs[0].L.f, expected 33, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -36108) - << "incorrect value for last_msg_.obs[0].L.i, expected -36108, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2046421816) - << "incorrect value for last_msg_.obs[0].P, expected 2046421816, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 46) - << "incorrect value for last_msg_.obs[0].cn0, expected 46, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 55875) - << "incorrect value for last_msg_.obs[0].lock, expected 55875, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 0) - << "incorrect value for last_msg_.obs[0].prn, expected 0, is " - << last_msg_.obs[0].prn; - EXPECT_EQ(last_msg_.obs[1].L.f, 98) - << "incorrect value for last_msg_.obs[1].L.f, expected 98, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 203030) - << "incorrect value for last_msg_.obs[1].L.i, expected 203030, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2085014510) - << "incorrect value for last_msg_.obs[1].P, expected 2085014510, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 43) - << "incorrect value for last_msg_.obs[1].cn0, expected 43, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 40376) - << "incorrect value for last_msg_.obs[1].lock, expected 40376, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].prn, 2) - << "incorrect value for last_msg_.obs[1].prn, expected 2, is " - << last_msg_.obs[1].prn; - EXPECT_EQ(last_msg_.obs[2].L.f, 185) - << "incorrect value for last_msg_.obs[2].L.f, expected 185, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -178306) - << "incorrect value for last_msg_.obs[2].L.i, expected -178306, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2110096816) - << "incorrect value for last_msg_.obs[2].P, expected 2110096816, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 39) - << "incorrect value for last_msg_.obs[2].cn0, expected 39, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 14148) - << "incorrect value for last_msg_.obs[2].lock, expected 14148, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].prn, 3) - << "incorrect value for last_msg_.obs[2].prn, expected 3, is " - << last_msg_.obs[2].prn; - EXPECT_EQ(last_msg_.obs[3].L.f, 139) - << "incorrect value for last_msg_.obs[3].L.f, expected 139, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, -137374) - << "incorrect value for last_msg_.obs[3].L.i, expected -137374, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2208476476) - << "incorrect value for last_msg_.obs[3].P, expected 2208476476, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 30) - << "incorrect value for last_msg_.obs[3].cn0, expected 30, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 4129) - << "incorrect value for last_msg_.obs[3].lock, expected 4129, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].prn, 10) - << "incorrect value for last_msg_.obs[3].prn, expected 10, is " - << last_msg_.obs[3].prn; - EXPECT_EQ(last_msg_.obs[4].L.f, 40) - << "incorrect value for last_msg_.obs[4].L.f, expected 40, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, -167638) - << "incorrect value for last_msg_.obs[4].L.i, expected -167638, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 2298000000) - << "incorrect value for last_msg_.obs[4].P, expected 2298000000, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 20) - << "incorrect value for last_msg_.obs[4].cn0, expected 20, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 18218) - << "incorrect value for last_msg_.obs[4].lock, expected 18218, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].prn, 13) - << "incorrect value for last_msg_.obs[4].prn, expected 13, is " - << last_msg_.obs[4].prn; - EXPECT_EQ(last_msg_.obs[5].L.f, 64) - << "incorrect value for last_msg_.obs[5].L.f, expected 64, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 209919) - << "incorrect value for last_msg_.obs[5].L.i, expected 209919, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 2266101494) - << "incorrect value for last_msg_.obs[5].P, expected 2266101494, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 27) - << "incorrect value for last_msg_.obs[5].cn0, expected 27, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].lock, 63852) - << "incorrect value for last_msg_.obs[5].lock, expected 63852, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].prn, 22) - << "incorrect value for last_msg_.obs[5].prn, expected 22, is " - << last_msg_.obs[5].prn; - EXPECT_EQ(last_msg_.obs[6].L.f, 31) - << "incorrect value for last_msg_.obs[6].L.f, expected 31, is " - << last_msg_.obs[6].L.f; - EXPECT_EQ(last_msg_.obs[6].L.i, -53117) - << "incorrect value for last_msg_.obs[6].L.i, expected -53117, is " - << last_msg_.obs[6].L.i; - EXPECT_EQ(last_msg_.obs[6].P, 1987193298) - << "incorrect value for last_msg_.obs[6].P, expected 1987193298, is " - << last_msg_.obs[6].P; - EXPECT_EQ(last_msg_.obs[6].cn0, 52) - << "incorrect value for last_msg_.obs[6].cn0, expected 52, is " - << last_msg_.obs[6].cn0; - EXPECT_EQ(last_msg_.obs[6].lock, 15074) - << "incorrect value for last_msg_.obs[6].lock, expected 15074, is " - << last_msg_.obs[6].lock; - EXPECT_EQ(last_msg_.obs[6].prn, 30) - << "incorrect value for last_msg_.obs[6].prn, expected 30, is " - << last_msg_.obs[6].prn; -} -class Test_auto_check_sbp_observation_msgObsDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgObsDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + + for (uint8_t i = 0; i < 98; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_observation_msgObsDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 69, 0, 195, 4, 20, 56, 158, 67, 24, 46, 7, 33, 84, - 52, 164, 117, 102, 32, 0, 0, 147, 62, 62, 250, 31, 234, 14, - }; + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 407084600; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 1; - - test_msg.obs[0].L.f = 147; - test_msg.obs[0].L.i = 8294; - test_msg.obs[0].P = 1973695572; - test_msg.obs[0].cn0 = 62; - test_msg.obs[0].lock = 64062; - test_msg.obs[0].prn = 31; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407084600) - << "incorrect value for last_msg_.header.t.tow, expected 407084600, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 1) - << "incorrect value for last_msg_.n_obs, expected 1, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 147) - << "incorrect value for last_msg_.obs[0].L.f, expected 147, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 8294) - << "incorrect value for last_msg_.obs[0].L.i, expected 8294, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1973695572) - << "incorrect value for last_msg_.obs[0].P, expected 1973695572, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 62) - << "incorrect value for last_msg_.obs[0].cn0, expected 62, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 64062) - << "incorrect value for last_msg_.obs[0].lock, expected 64062, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 31) - << "incorrect value for last_msg_.obs[0].prn, expected 31, is " - << last_msg_.obs[0].prn; -} -class Test_auto_check_sbp_observation_msgObsDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgObsDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_msgObsDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 69, 0, 195, 4, 98, 0, 159, 67, 24, 46, 7, 32, 32, - 209, 249, 121, 145, 114, 255, 255, 141, 45, 67, 218, 0, 177, 128, - 70, 124, 79, 27, 3, 0, 159, 44, 184, 157, 2, 59, 135, 197, - 125, 175, 69, 253, 255, 77, 40, 68, 55, 3, 211, 172, 162, 131, - 177, 229, 253, 255, 20, 31, 33, 16, 10, 128, 178, 248, 136, 116, - 111, 253, 255, 94, 21, 42, 71, 13, 182, 173, 17, 135, 37, 54, - 3, 0, 214, 27, 108, 249, 22, 91, 20, 114, 118, 240, 47, 255, - 255, 129, 52, 226, 58, 30, 200, 119, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 32; - test_msg.header.t.tow = 407084800; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 7; - - test_msg.obs[0].L.f = 141; - test_msg.obs[0].L.i = -36207; - test_msg.obs[0].P = 2046415136; - test_msg.obs[0].cn0 = 45; - test_msg.obs[0].lock = 55875; - test_msg.obs[0].prn = 0; - - test_msg.obs[1].L.f = 159; - test_msg.obs[1].L.i = 203599; - test_msg.obs[1].P = 2084995249; - test_msg.obs[1].cn0 = 44; - test_msg.obs[1].lock = 40376; - test_msg.obs[1].prn = 2; - - test_msg.obs[2].L.f = 77; - test_msg.obs[2].L.i = -178769; - test_msg.obs[2].P = 2110097211; - test_msg.obs[2].cn0 = 40; - test_msg.obs[2].lock = 14148; - test_msg.obs[2].prn = 3; - - test_msg.obs[3].L.f = 20; - test_msg.obs[3].L.i = -137807; - test_msg.obs[3].P = 2208476371; - test_msg.obs[3].cn0 = 31; - test_msg.obs[3].lock = 4129; - test_msg.obs[3].prn = 10; - - test_msg.obs[4].L.f = 94; - test_msg.obs[4].L.i = -168076; - test_msg.obs[4].P = 2298000000; - test_msg.obs[4].cn0 = 21; - test_msg.obs[4].lock = 18218; - test_msg.obs[4].prn = 13; - - test_msg.obs[5].L.f = 214; - test_msg.obs[5].L.i = 210469; - test_msg.obs[5].P = 2266082742; - test_msg.obs[5].cn0 = 27; - test_msg.obs[5].lock = 63852; - test_msg.obs[5].prn = 22; - - test_msg.obs[6].L.f = 129; - test_msg.obs[6].L.i = -53264; - test_msg.obs[6].P = 1987187803; - test_msg.obs[6].cn0 = 52; - test_msg.obs[6].lock = 15074; - test_msg.obs[6].prn = 30; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 32) - << "incorrect value for last_msg_.header.n_obs, expected 32, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407084800) - << "incorrect value for last_msg_.header.t.tow, expected 407084800, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 7) - << "incorrect value for last_msg_.n_obs, expected 7, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 141) - << "incorrect value for last_msg_.obs[0].L.f, expected 141, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -36207) - << "incorrect value for last_msg_.obs[0].L.i, expected -36207, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2046415136) - << "incorrect value for last_msg_.obs[0].P, expected 2046415136, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 45) - << "incorrect value for last_msg_.obs[0].cn0, expected 45, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 55875) - << "incorrect value for last_msg_.obs[0].lock, expected 55875, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 0) - << "incorrect value for last_msg_.obs[0].prn, expected 0, is " - << last_msg_.obs[0].prn; - EXPECT_EQ(last_msg_.obs[1].L.f, 159) - << "incorrect value for last_msg_.obs[1].L.f, expected 159, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, 203599) - << "incorrect value for last_msg_.obs[1].L.i, expected 203599, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2084995249) - << "incorrect value for last_msg_.obs[1].P, expected 2084995249, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 44) - << "incorrect value for last_msg_.obs[1].cn0, expected 44, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 40376) - << "incorrect value for last_msg_.obs[1].lock, expected 40376, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].prn, 2) - << "incorrect value for last_msg_.obs[1].prn, expected 2, is " - << last_msg_.obs[1].prn; - EXPECT_EQ(last_msg_.obs[2].L.f, 77) - << "incorrect value for last_msg_.obs[2].L.f, expected 77, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -178769) - << "incorrect value for last_msg_.obs[2].L.i, expected -178769, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2110097211) - << "incorrect value for last_msg_.obs[2].P, expected 2110097211, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 40) - << "incorrect value for last_msg_.obs[2].cn0, expected 40, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 14148) - << "incorrect value for last_msg_.obs[2].lock, expected 14148, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].prn, 3) - << "incorrect value for last_msg_.obs[2].prn, expected 3, is " - << last_msg_.obs[2].prn; - EXPECT_EQ(last_msg_.obs[3].L.f, 20) - << "incorrect value for last_msg_.obs[3].L.f, expected 20, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, -137807) - << "incorrect value for last_msg_.obs[3].L.i, expected -137807, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2208476371) - << "incorrect value for last_msg_.obs[3].P, expected 2208476371, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 31) - << "incorrect value for last_msg_.obs[3].cn0, expected 31, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 4129) - << "incorrect value for last_msg_.obs[3].lock, expected 4129, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].prn, 10) - << "incorrect value for last_msg_.obs[3].prn, expected 10, is " - << last_msg_.obs[3].prn; - EXPECT_EQ(last_msg_.obs[4].L.f, 94) - << "incorrect value for last_msg_.obs[4].L.f, expected 94, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, -168076) - << "incorrect value for last_msg_.obs[4].L.i, expected -168076, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 2298000000) - << "incorrect value for last_msg_.obs[4].P, expected 2298000000, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 21) - << "incorrect value for last_msg_.obs[4].cn0, expected 21, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 18218) - << "incorrect value for last_msg_.obs[4].lock, expected 18218, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].prn, 13) - << "incorrect value for last_msg_.obs[4].prn, expected 13, is " - << last_msg_.obs[4].prn; - EXPECT_EQ(last_msg_.obs[5].L.f, 214) - << "incorrect value for last_msg_.obs[5].L.f, expected 214, is " - << last_msg_.obs[5].L.f; - EXPECT_EQ(last_msg_.obs[5].L.i, 210469) - << "incorrect value for last_msg_.obs[5].L.i, expected 210469, is " - << last_msg_.obs[5].L.i; - EXPECT_EQ(last_msg_.obs[5].P, 2266082742) - << "incorrect value for last_msg_.obs[5].P, expected 2266082742, is " - << last_msg_.obs[5].P; - EXPECT_EQ(last_msg_.obs[5].cn0, 27) - << "incorrect value for last_msg_.obs[5].cn0, expected 27, is " - << last_msg_.obs[5].cn0; - EXPECT_EQ(last_msg_.obs[5].lock, 63852) - << "incorrect value for last_msg_.obs[5].lock, expected 63852, is " - << last_msg_.obs[5].lock; - EXPECT_EQ(last_msg_.obs[5].prn, 22) - << "incorrect value for last_msg_.obs[5].prn, expected 22, is " - << last_msg_.obs[5].prn; - EXPECT_EQ(last_msg_.obs[6].L.f, 129) - << "incorrect value for last_msg_.obs[6].L.f, expected 129, is " - << last_msg_.obs[6].L.f; - EXPECT_EQ(last_msg_.obs[6].L.i, -53264) - << "incorrect value for last_msg_.obs[6].L.i, expected -53264, is " - << last_msg_.obs[6].L.i; - EXPECT_EQ(last_msg_.obs[6].P, 1987187803) - << "incorrect value for last_msg_.obs[6].P, expected 1987187803, is " - << last_msg_.obs[6].P; - EXPECT_EQ(last_msg_.obs[6].cn0, 52) - << "incorrect value for last_msg_.obs[6].cn0, expected 52, is " - << last_msg_.obs[6].cn0; - EXPECT_EQ(last_msg_.obs[6].lock, 15074) - << "incorrect value for last_msg_.obs[6].lock, expected 15074, is " - << last_msg_.obs[6].lock; - EXPECT_EQ(last_msg_.obs[6].prn, 30) - << "incorrect value for last_msg_.obs[6].prn, expected 30, is " - << last_msg_.obs[6].prn; -} -class Test_auto_check_sbp_observation_msgObsDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgObsDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_msgObsDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 69, 0, 195, 4, 20, 0, 159, 67, 24, 46, 7, 33, 49, - 19, 164, 117, 120, 32, 0, 0, 222, 63, 62, 250, 31, 11, 231, - }; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 33; - test_msg.header.t.tow = 407084800; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 1; - - test_msg.obs[0].L.f = 222; - test_msg.obs[0].L.i = 8312; - test_msg.obs[0].P = 1973687089; - test_msg.obs[0].cn0 = 63; - test_msg.obs[0].lock = 64062; - test_msg.obs[0].prn = 31; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 33) - << "incorrect value for last_msg_.header.n_obs, expected 33, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407084800) - << "incorrect value for last_msg_.header.t.tow, expected 407084800, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 1) - << "incorrect value for last_msg_.n_obs, expected 1, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 222) - << "incorrect value for last_msg_.obs[0].L.f, expected 222, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, 8312) - << "incorrect value for last_msg_.obs[0].L.i, expected 8312, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 1973687089) - << "incorrect value for last_msg_.obs[0].P, expected 1973687089, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 63) - << "incorrect value for last_msg_.obs[0].cn0, expected 63, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 64062) - << "incorrect value for last_msg_.obs[0].lock, expected 64062, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 31) - << "incorrect value for last_msg_.obs[0].prn, expected 31, is " - << last_msg_.obs[0].prn; -} -class Test_auto_check_sbp_observation_msgObsDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgObsDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_observation_msgObsDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 69, 0, 195, 4, 72, 96, 162, 68, 24, 46, 7, 16, 87, - 132, 217, 121, 121, 148, 255, 255, 189, 43, 175, 147, 0, 132, 64, - 200, 125, 106, 31, 254, 255, 1, 41, 14, 177, 3, 128, 178, 248, - 136, 70, 68, 254, 255, 166, 18, 184, 133, 13, 24, 127, 178, 134, - 6, 25, 2, 0, 249, 28, 33, 96, 22, 170, 104, 86, 118, 67, - 112, 255, 255, 203, 56, 208, 88, 30, 43, 107, - }; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 16; - test_msg.header.t.tow = 407151200; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 5; - - test_msg.obs[0].L.f = 189; - test_msg.obs[0].L.i = -27527; - test_msg.obs[0].P = 2044298327; - test_msg.obs[0].cn0 = 43; - test_msg.obs[0].lock = 37807; - test_msg.obs[0].prn = 0; - - test_msg.obs[1].L.f = 1; - test_msg.obs[1].L.i = -123030; - test_msg.obs[1].P = 2110275716; - test_msg.obs[1].cn0 = 41; - test_msg.obs[1].lock = 45326; - test_msg.obs[1].prn = 3; - - test_msg.obs[2].L.f = 166; - test_msg.obs[2].L.i = -113594; - test_msg.obs[2].P = 2298000000; - test_msg.obs[2].cn0 = 18; - test_msg.obs[2].lock = 34232; - test_msg.obs[2].prn = 13; - - test_msg.obs[3].L.f = 249; - test_msg.obs[3].L.i = 137478; - test_msg.obs[3].P = 2259844888; - test_msg.obs[3].cn0 = 28; - test_msg.obs[3].lock = 24609; - test_msg.obs[3].prn = 22; - - test_msg.obs[4].L.f = 203; - test_msg.obs[4].L.i = -36797; - test_msg.obs[4].P = 1985374378; - test_msg.obs[4].cn0 = 56; - test_msg.obs[4].lock = 22736; - test_msg.obs[4].prn = 30; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 16) - << "incorrect value for last_msg_.header.n_obs, expected 16, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407151200) - << "incorrect value for last_msg_.header.t.tow, expected 407151200, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 5) - << "incorrect value for last_msg_.n_obs, expected 5, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 189) - << "incorrect value for last_msg_.obs[0].L.f, expected 189, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -27527) - << "incorrect value for last_msg_.obs[0].L.i, expected -27527, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2044298327) - << "incorrect value for last_msg_.obs[0].P, expected 2044298327, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 43) - << "incorrect value for last_msg_.obs[0].cn0, expected 43, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 37807) - << "incorrect value for last_msg_.obs[0].lock, expected 37807, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 0) - << "incorrect value for last_msg_.obs[0].prn, expected 0, is " - << last_msg_.obs[0].prn; - EXPECT_EQ(last_msg_.obs[1].L.f, 1) - << "incorrect value for last_msg_.obs[1].L.f, expected 1, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, -123030) - << "incorrect value for last_msg_.obs[1].L.i, expected -123030, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2110275716) - << "incorrect value for last_msg_.obs[1].P, expected 2110275716, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 41) - << "incorrect value for last_msg_.obs[1].cn0, expected 41, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 45326) - << "incorrect value for last_msg_.obs[1].lock, expected 45326, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].prn, 3) - << "incorrect value for last_msg_.obs[1].prn, expected 3, is " - << last_msg_.obs[1].prn; - EXPECT_EQ(last_msg_.obs[2].L.f, 166) - << "incorrect value for last_msg_.obs[2].L.f, expected 166, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -113594) - << "incorrect value for last_msg_.obs[2].L.i, expected -113594, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2298000000) - << "incorrect value for last_msg_.obs[2].P, expected 2298000000, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 18) - << "incorrect value for last_msg_.obs[2].cn0, expected 18, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 34232) - << "incorrect value for last_msg_.obs[2].lock, expected 34232, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].prn, 13) - << "incorrect value for last_msg_.obs[2].prn, expected 13, is " - << last_msg_.obs[2].prn; - EXPECT_EQ(last_msg_.obs[3].L.f, 249) - << "incorrect value for last_msg_.obs[3].L.f, expected 249, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 137478) - << "incorrect value for last_msg_.obs[3].L.i, expected 137478, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2259844888) - << "incorrect value for last_msg_.obs[3].P, expected 2259844888, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 28) - << "incorrect value for last_msg_.obs[3].cn0, expected 28, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 24609) - << "incorrect value for last_msg_.obs[3].lock, expected 24609, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].prn, 22) - << "incorrect value for last_msg_.obs[3].prn, expected 22, is " - << last_msg_.obs[3].prn; - EXPECT_EQ(last_msg_.obs[4].L.f, 203) - << "incorrect value for last_msg_.obs[4].L.f, expected 203, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, -36797) - << "incorrect value for last_msg_.obs[4].L.i, expected -36797, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1985374378) - << "incorrect value for last_msg_.obs[4].P, expected 1985374378, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 56) - << "incorrect value for last_msg_.obs[4].cn0, expected 56, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 22736) - << "incorrect value for last_msg_.obs[4].lock, expected 22736, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].prn, 30) - << "incorrect value for last_msg_.obs[4].prn, expected 30, is " - << last_msg_.obs[4].prn; -} -class Test_auto_check_sbp_observation_msgObsDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_observation_msgObsDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_obs_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_obs_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_observation_msgObsDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 69, 0, 195, 4, 72, 40, 163, 68, 24, 46, 7, 16, 132, - 107, 217, 121, 14, 148, 255, 255, 1, 44, 175, 147, 0, 129, 66, - 200, 125, 148, 29, 254, 255, 153, 41, 14, 177, 3, 128, 178, 248, - 136, 143, 66, 254, 255, 222, 18, 184, 133, 13, 158, 53, 178, 134, - 42, 27, 2, 0, 237, 30, 33, 96, 22, 38, 83, 86, 118, 168, - 111, 255, 255, 45, 56, 208, 88, 30, 1, 175, - }; +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].prn, greater.obs[1].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].prn, greater.obs[2].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].prn, greater.obs[3].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].prn, greater.obs[4].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].prn, greater.obs[5].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.f, greater.obs[6].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.i, greater.obs[6].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].P, greater.obs[6].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].cn0, greater.obs[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].lock, greater.obs[6].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].prn, greater.obs[6].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; - sbp_msg_obs_dep_a_t test_msg{}; - test_msg.header.n_obs = 16; - test_msg.header.t.tow = 407151400; - test_msg.header.t.wn = 1838; - test_msg.n_obs = 5; - - test_msg.obs[0].L.f = 1; - test_msg.obs[0].L.i = -27634; - test_msg.obs[0].P = 2044291972; - test_msg.obs[0].cn0 = 44; - test_msg.obs[0].lock = 37807; - test_msg.obs[0].prn = 0; - - test_msg.obs[1].L.f = 153; - test_msg.obs[1].L.i = -123500; - test_msg.obs[1].P = 2110276225; - test_msg.obs[1].cn0 = 41; - test_msg.obs[1].lock = 45326; - test_msg.obs[1].prn = 3; - - test_msg.obs[2].L.f = 222; - test_msg.obs[2].L.i = -114033; - test_msg.obs[2].P = 2298000000; - test_msg.obs[2].cn0 = 18; - test_msg.obs[2].lock = 34232; - test_msg.obs[2].prn = 13; - - test_msg.obs[3].L.f = 237; - test_msg.obs[3].L.i = 138026; - test_msg.obs[3].P = 2259826078; - test_msg.obs[3].cn0 = 30; - test_msg.obs[3].lock = 24609; - test_msg.obs[3].prn = 22; - - test_msg.obs[4].L.f = 45; - test_msg.obs[4].L.i = -36952; - test_msg.obs[4].P = 1985368870; - test_msg.obs[4].cn0 = 56; - test_msg.obs[4].lock = 22736; - test_msg.obs[4].prn = 30; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.n_obs, 16) - << "incorrect value for last_msg_.header.n_obs, expected 16, is " - << last_msg_.header.n_obs; - EXPECT_EQ(last_msg_.header.t.tow, 407151400) - << "incorrect value for last_msg_.header.t.tow, expected 407151400, is " - << last_msg_.header.t.tow; - EXPECT_EQ(last_msg_.header.t.wn, 1838) - << "incorrect value for last_msg_.header.t.wn, expected 1838, is " - << last_msg_.header.t.wn; - EXPECT_EQ(last_msg_.n_obs, 5) - << "incorrect value for last_msg_.n_obs, expected 5, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.obs[0].L.f, 1) - << "incorrect value for last_msg_.obs[0].L.f, expected 1, is " - << last_msg_.obs[0].L.f; - EXPECT_EQ(last_msg_.obs[0].L.i, -27634) - << "incorrect value for last_msg_.obs[0].L.i, expected -27634, is " - << last_msg_.obs[0].L.i; - EXPECT_EQ(last_msg_.obs[0].P, 2044291972) - << "incorrect value for last_msg_.obs[0].P, expected 2044291972, is " - << last_msg_.obs[0].P; - EXPECT_EQ(last_msg_.obs[0].cn0, 44) - << "incorrect value for last_msg_.obs[0].cn0, expected 44, is " - << last_msg_.obs[0].cn0; - EXPECT_EQ(last_msg_.obs[0].lock, 37807) - << "incorrect value for last_msg_.obs[0].lock, expected 37807, is " - << last_msg_.obs[0].lock; - EXPECT_EQ(last_msg_.obs[0].prn, 0) - << "incorrect value for last_msg_.obs[0].prn, expected 0, is " - << last_msg_.obs[0].prn; - EXPECT_EQ(last_msg_.obs[1].L.f, 153) - << "incorrect value for last_msg_.obs[1].L.f, expected 153, is " - << last_msg_.obs[1].L.f; - EXPECT_EQ(last_msg_.obs[1].L.i, -123500) - << "incorrect value for last_msg_.obs[1].L.i, expected -123500, is " - << last_msg_.obs[1].L.i; - EXPECT_EQ(last_msg_.obs[1].P, 2110276225) - << "incorrect value for last_msg_.obs[1].P, expected 2110276225, is " - << last_msg_.obs[1].P; - EXPECT_EQ(last_msg_.obs[1].cn0, 41) - << "incorrect value for last_msg_.obs[1].cn0, expected 41, is " - << last_msg_.obs[1].cn0; - EXPECT_EQ(last_msg_.obs[1].lock, 45326) - << "incorrect value for last_msg_.obs[1].lock, expected 45326, is " - << last_msg_.obs[1].lock; - EXPECT_EQ(last_msg_.obs[1].prn, 3) - << "incorrect value for last_msg_.obs[1].prn, expected 3, is " - << last_msg_.obs[1].prn; - EXPECT_EQ(last_msg_.obs[2].L.f, 222) - << "incorrect value for last_msg_.obs[2].L.f, expected 222, is " - << last_msg_.obs[2].L.f; - EXPECT_EQ(last_msg_.obs[2].L.i, -114033) - << "incorrect value for last_msg_.obs[2].L.i, expected -114033, is " - << last_msg_.obs[2].L.i; - EXPECT_EQ(last_msg_.obs[2].P, 2298000000) - << "incorrect value for last_msg_.obs[2].P, expected 2298000000, is " - << last_msg_.obs[2].P; - EXPECT_EQ(last_msg_.obs[2].cn0, 18) - << "incorrect value for last_msg_.obs[2].cn0, expected 18, is " - << last_msg_.obs[2].cn0; - EXPECT_EQ(last_msg_.obs[2].lock, 34232) - << "incorrect value for last_msg_.obs[2].lock, expected 34232, is " - << last_msg_.obs[2].lock; - EXPECT_EQ(last_msg_.obs[2].prn, 13) - << "incorrect value for last_msg_.obs[2].prn, expected 13, is " - << last_msg_.obs[2].prn; - EXPECT_EQ(last_msg_.obs[3].L.f, 237) - << "incorrect value for last_msg_.obs[3].L.f, expected 237, is " - << last_msg_.obs[3].L.f; - EXPECT_EQ(last_msg_.obs[3].L.i, 138026) - << "incorrect value for last_msg_.obs[3].L.i, expected 138026, is " - << last_msg_.obs[3].L.i; - EXPECT_EQ(last_msg_.obs[3].P, 2259826078) - << "incorrect value for last_msg_.obs[3].P, expected 2259826078, is " - << last_msg_.obs[3].P; - EXPECT_EQ(last_msg_.obs[3].cn0, 30) - << "incorrect value for last_msg_.obs[3].cn0, expected 30, is " - << last_msg_.obs[3].cn0; - EXPECT_EQ(last_msg_.obs[3].lock, 24609) - << "incorrect value for last_msg_.obs[3].lock, expected 24609, is " - << last_msg_.obs[3].lock; - EXPECT_EQ(last_msg_.obs[3].prn, 22) - << "incorrect value for last_msg_.obs[3].prn, expected 22, is " - << last_msg_.obs[3].prn; - EXPECT_EQ(last_msg_.obs[4].L.f, 45) - << "incorrect value for last_msg_.obs[4].L.f, expected 45, is " - << last_msg_.obs[4].L.f; - EXPECT_EQ(last_msg_.obs[4].L.i, -36952) - << "incorrect value for last_msg_.obs[4].L.i, expected -36952, is " - << last_msg_.obs[4].L.i; - EXPECT_EQ(last_msg_.obs[4].P, 1985368870) - << "incorrect value for last_msg_.obs[4].P, expected 1985368870, is " - << last_msg_.obs[4].P; - EXPECT_EQ(last_msg_.obs[4].cn0, 56) - << "incorrect value for last_msg_.obs[4].cn0, expected 56, is " - << last_msg_.obs[4].cn0; - EXPECT_EQ(last_msg_.obs[4].lock, 22736) - << "incorrect value for last_msg_.obs[4].lock, expected 22736, is " - << last_msg_.obs[4].lock; - EXPECT_EQ(last_msg_.obs[4].prn, 30) - << "incorrect value for last_msg_.obs[4].prn, expected 30, is " - << last_msg_.obs[4].prn; + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); } + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgObsDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgObsDepA1() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 407084600); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 1); + + assign(test_msg_.obs[0].L.f, 147); + assign(test_msg_.obs[0].L.i, 8294); + assign(test_msg_.obs[0].P, 1973695572); + assign(test_msg_.obs[0].cn0, 62); + assign(test_msg_.obs[0].lock, 64062); + assign(test_msg_.obs[0].prn, 31); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xeea; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 69, 0, 195, 4, 20, 56, 158, 67, 24, 46, 7, 33, 84, + 52, 164, 117, 102, 32, 0, 0, 147, 62, 62, 250, 31, 234, 14, + }; + uint8_t encoded_payload_[20] = { + 56, 158, 67, 24, 46, 7, 33, 84, 52, 164, + 117, 102, 32, 0, 0, 147, 62, 62, 250, 31, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgObsDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgObsDepA2() { + assign(test_msg_.header.n_obs, 32); + assign(test_msg_.header.t.tow, 407084800); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 7); + + assign(test_msg_.obs[0].L.f, 141); + assign(test_msg_.obs[0].L.i, -36207); + assign(test_msg_.obs[0].P, 2046415136); + assign(test_msg_.obs[0].cn0, 45); + assign(test_msg_.obs[0].lock, 55875); + assign(test_msg_.obs[0].prn, 0); + + assign(test_msg_.obs[1].L.f, 159); + assign(test_msg_.obs[1].L.i, 203599); + assign(test_msg_.obs[1].P, 2084995249); + assign(test_msg_.obs[1].cn0, 44); + assign(test_msg_.obs[1].lock, 40376); + assign(test_msg_.obs[1].prn, 2); + + assign(test_msg_.obs[2].L.f, 77); + assign(test_msg_.obs[2].L.i, -178769); + assign(test_msg_.obs[2].P, 2110097211); + assign(test_msg_.obs[2].cn0, 40); + assign(test_msg_.obs[2].lock, 14148); + assign(test_msg_.obs[2].prn, 3); + + assign(test_msg_.obs[3].L.f, 20); + assign(test_msg_.obs[3].L.i, -137807); + assign(test_msg_.obs[3].P, 2208476371); + assign(test_msg_.obs[3].cn0, 31); + assign(test_msg_.obs[3].lock, 4129); + assign(test_msg_.obs[3].prn, 10); + + assign(test_msg_.obs[4].L.f, 94); + assign(test_msg_.obs[4].L.i, -168076); + assign(test_msg_.obs[4].P, 2298000000); + assign(test_msg_.obs[4].cn0, 21); + assign(test_msg_.obs[4].lock, 18218); + assign(test_msg_.obs[4].prn, 13); + + assign(test_msg_.obs[5].L.f, 214); + assign(test_msg_.obs[5].L.i, 210469); + assign(test_msg_.obs[5].P, 2266082742); + assign(test_msg_.obs[5].cn0, 27); + assign(test_msg_.obs[5].lock, 63852); + assign(test_msg_.obs[5].prn, 22); + + assign(test_msg_.obs[6].L.f, 129); + assign(test_msg_.obs[6].L.i, -53264); + assign(test_msg_.obs[6].P, 1987187803); + assign(test_msg_.obs[6].cn0, 52); + assign(test_msg_.obs[6].lock, 15074); + assign(test_msg_.obs[6].prn, 30); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x77c8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 98; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[98 + 8] = { + 85, 69, 0, 195, 4, 98, 0, 159, 67, 24, 46, 7, 32, 32, + 209, 249, 121, 145, 114, 255, 255, 141, 45, 67, 218, 0, 177, 128, + 70, 124, 79, 27, 3, 0, 159, 44, 184, 157, 2, 59, 135, 197, + 125, 175, 69, 253, 255, 77, 40, 68, 55, 3, 211, 172, 162, 131, + 177, 229, 253, 255, 20, 31, 33, 16, 10, 128, 178, 248, 136, 116, + 111, 253, 255, 94, 21, 42, 71, 13, 182, 173, 17, 135, 37, 54, + 3, 0, 214, 27, 108, 249, 22, 91, 20, 114, 118, 240, 47, 255, + 255, 129, 52, 226, 58, 30, 200, 119, + }; + uint8_t encoded_payload_[98] = { + 0, 159, 67, 24, 46, 7, 32, 32, 209, 249, 121, 145, 114, 255, + 255, 141, 45, 67, 218, 0, 177, 128, 70, 124, 79, 27, 3, 0, + 159, 44, 184, 157, 2, 59, 135, 197, 125, 175, 69, 253, 255, 77, + 40, 68, 55, 3, 211, 172, 162, 131, 177, 229, 253, 255, 20, 31, + 33, 16, 10, 128, 178, 248, 136, 116, 111, 253, 255, 94, 21, 42, + 71, 13, 182, 173, 17, 135, 37, 54, 3, 0, 214, 27, 108, 249, + 22, 91, 20, 114, 118, 240, 47, 255, 255, 129, 52, 226, 58, 30, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + + for (uint8_t i = 0; i < 98; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].prn, greater.obs[1].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].prn, greater.obs[2].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].prn, greater.obs[3].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].prn, greater.obs[4].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.f, greater.obs[5].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].L.i, greater.obs[5].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].P, greater.obs[5].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].cn0, greater.obs[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].lock, greater.obs[5].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[5].prn, greater.obs[5].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.f, greater.obs[6].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].L.i, greater.obs[6].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].P, greater.obs[6].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].cn0, greater.obs[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].lock, greater.obs[6].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[6].prn, greater.obs[6].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[98]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 98); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 98), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 98); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgObsDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgObsDepA3() { + assign(test_msg_.header.n_obs, 33); + assign(test_msg_.header.t.tow, 407084800); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 1); + + assign(test_msg_.obs[0].L.f, 222); + assign(test_msg_.obs[0].L.i, 8312); + assign(test_msg_.obs[0].P, 1973687089); + assign(test_msg_.obs[0].cn0, 63); + assign(test_msg_.obs[0].lock, 64062); + assign(test_msg_.obs[0].prn, 31); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe70b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 69, 0, 195, 4, 20, 0, 159, 67, 24, 46, 7, 33, 49, + 19, 164, 117, 120, 32, 0, 0, 222, 63, 62, 250, 31, 11, 231, + }; + uint8_t encoded_payload_[20] = { + 0, 159, 67, 24, 46, 7, 33, 49, 19, 164, + 117, 120, 32, 0, 0, 222, 63, 62, 250, 31, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgObsDepA4 : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgObsDepA4() { + assign(test_msg_.header.n_obs, 16); + assign(test_msg_.header.t.tow, 407151200); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 5); + + assign(test_msg_.obs[0].L.f, 189); + assign(test_msg_.obs[0].L.i, -27527); + assign(test_msg_.obs[0].P, 2044298327); + assign(test_msg_.obs[0].cn0, 43); + assign(test_msg_.obs[0].lock, 37807); + assign(test_msg_.obs[0].prn, 0); + + assign(test_msg_.obs[1].L.f, 1); + assign(test_msg_.obs[1].L.i, -123030); + assign(test_msg_.obs[1].P, 2110275716); + assign(test_msg_.obs[1].cn0, 41); + assign(test_msg_.obs[1].lock, 45326); + assign(test_msg_.obs[1].prn, 3); + + assign(test_msg_.obs[2].L.f, 166); + assign(test_msg_.obs[2].L.i, -113594); + assign(test_msg_.obs[2].P, 2298000000); + assign(test_msg_.obs[2].cn0, 18); + assign(test_msg_.obs[2].lock, 34232); + assign(test_msg_.obs[2].prn, 13); + + assign(test_msg_.obs[3].L.f, 249); + assign(test_msg_.obs[3].L.i, 137478); + assign(test_msg_.obs[3].P, 2259844888); + assign(test_msg_.obs[3].cn0, 28); + assign(test_msg_.obs[3].lock, 24609); + assign(test_msg_.obs[3].prn, 22); + + assign(test_msg_.obs[4].L.f, 203); + assign(test_msg_.obs[4].L.i, -36797); + assign(test_msg_.obs[4].P, 1985374378); + assign(test_msg_.obs[4].cn0, 56); + assign(test_msg_.obs[4].lock, 22736); + assign(test_msg_.obs[4].prn, 30); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6b2b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 72; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[72 + 8] = { + 85, 69, 0, 195, 4, 72, 96, 162, 68, 24, 46, 7, 16, 87, + 132, 217, 121, 121, 148, 255, 255, 189, 43, 175, 147, 0, 132, 64, + 200, 125, 106, 31, 254, 255, 1, 41, 14, 177, 3, 128, 178, 248, + 136, 70, 68, 254, 255, 166, 18, 184, 133, 13, 24, 127, 178, 134, + 6, 25, 2, 0, 249, 28, 33, 96, 22, 170, 104, 86, 118, 67, + 112, 255, 255, 203, 56, 208, 88, 30, 43, 107, + }; + uint8_t encoded_payload_[72] = { + 96, 162, 68, 24, 46, 7, 16, 87, 132, 217, 121, 121, 148, 255, 255, + 189, 43, 175, 147, 0, 132, 64, 200, 125, 106, 31, 254, 255, 1, 41, + 14, 177, 3, 128, 178, 248, 136, 70, 68, 254, 255, 166, 18, 184, 133, + 13, 24, 127, 178, 134, 6, 25, 2, 0, 249, 28, 33, 96, 22, 170, + 104, 86, 118, 67, 112, 255, 255, 203, 56, 208, 88, 30, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + for (uint8_t i = 0; i < 72; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].prn, greater.obs[1].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].prn, greater.obs[2].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].prn, greater.obs[3].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].prn, greater.obs[4].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_observation_msgObsDepA5 : public ::testing::Test { + public: + Testauto_check_sbp_observation_msgObsDepA5() { + assign(test_msg_.header.n_obs, 16); + assign(test_msg_.header.t.tow, 407151400); + assign(test_msg_.header.t.wn, 1838); + assign(test_msg_.n_obs, 5); + + assign(test_msg_.obs[0].L.f, 1); + assign(test_msg_.obs[0].L.i, -27634); + assign(test_msg_.obs[0].P, 2044291972); + assign(test_msg_.obs[0].cn0, 44); + assign(test_msg_.obs[0].lock, 37807); + assign(test_msg_.obs[0].prn, 0); + + assign(test_msg_.obs[1].L.f, 153); + assign(test_msg_.obs[1].L.i, -123500); + assign(test_msg_.obs[1].P, 2110276225); + assign(test_msg_.obs[1].cn0, 41); + assign(test_msg_.obs[1].lock, 45326); + assign(test_msg_.obs[1].prn, 3); + + assign(test_msg_.obs[2].L.f, 222); + assign(test_msg_.obs[2].L.i, -114033); + assign(test_msg_.obs[2].P, 2298000000); + assign(test_msg_.obs[2].cn0, 18); + assign(test_msg_.obs[2].lock, 34232); + assign(test_msg_.obs[2].prn, 13); + + assign(test_msg_.obs[3].L.f, 237); + assign(test_msg_.obs[3].L.i, 138026); + assign(test_msg_.obs[3].P, 2259826078); + assign(test_msg_.obs[3].cn0, 30); + assign(test_msg_.obs[3].lock, 24609); + assign(test_msg_.obs[3].prn, 22); + + assign(test_msg_.obs[4].L.f, 45); + assign(test_msg_.obs[4].L.i, -36952); + assign(test_msg_.obs[4].P, 1985368870); + assign(test_msg_.obs[4].cn0, 56); + assign(test_msg_.obs[4].lock, 22736); + assign(test_msg_.obs[4].prn, 30); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_obs_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgObsDepA, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_obs_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgObsDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->obs_dep_a, sizeof(msg->obs_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_obs_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.obs_dep_a, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgObsDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xaf01; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 72; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_obs_dep_a_t &lesser, + const sbp_msg_obs_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_obs_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_obs_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_obs_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgObsDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgObsDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_obs_dep_a_t test_msg_{}; + uint8_t encoded_frame_[72 + 8] = { + 85, 69, 0, 195, 4, 72, 40, 163, 68, 24, 46, 7, 16, 132, + 107, 217, 121, 14, 148, 255, 255, 1, 44, 175, 147, 0, 129, 66, + 200, 125, 148, 29, 254, 255, 153, 41, 14, 177, 3, 128, 178, 248, + 136, 143, 66, 254, 255, 222, 18, 184, 133, 13, 158, 53, 178, 134, + 42, 27, 2, 0, 237, 30, 33, 96, 22, 38, 83, 86, 118, 168, + 111, 255, 255, 45, 56, 208, 88, 30, 1, 175, + }; + uint8_t encoded_payload_[72] = { + 40, 163, 68, 24, 46, 7, 16, 132, 107, 217, 121, 14, 148, 255, 255, + 1, 44, 175, 147, 0, 129, 66, 200, 125, 148, 29, 254, 255, 153, 41, + 14, 177, 3, 128, 178, 248, 136, 143, 66, 254, 255, 222, 18, 184, 133, + 13, 158, 53, 178, 134, 42, 27, 2, 0, 237, 30, 33, 96, 22, 38, + 83, 86, 118, 168, 111, 255, 255, 45, 56, 208, 88, 30, + }; +}; + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_obs_dep_a_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgObsDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgObsDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + EXPECT_EQ( + sbp_msg_obs_dep_a_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + + for (uint8_t i = 0; i < 72; i++) { + EXPECT_EQ(sbp_msg_obs_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgObsDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + return sbp_msg_obs_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_obs_dep_a_t t{}; + t.n_obs = 1; + return sbp_msg_obs_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_obs_dep_a_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_obs_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgObsDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.n_obs, greater.header.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.tow, greater.header.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.t.wn, greater.header.t.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.f, greater.obs[0].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].L.i, greater.obs[0].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].P, greater.obs[0].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].cn0, greater.obs[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].lock, greater.obs[0].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[0].prn, greater.obs[0].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.f, greater.obs[1].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].L.i, greater.obs[1].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].P, greater.obs[1].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].cn0, greater.obs[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].lock, greater.obs[1].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[1].prn, greater.obs[1].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.f, greater.obs[2].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].L.i, greater.obs[2].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].P, greater.obs[2].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].cn0, greater.obs[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].lock, greater.obs[2].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[2].prn, greater.obs[2].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.f, greater.obs[3].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].L.i, greater.obs[3].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].P, greater.obs[3].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].cn0, greater.obs[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].lock, greater.obs[3].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[3].prn, greater.obs[3].prn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.f, greater.obs[4].L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].L.i, greater.obs[4].L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].P, greater.obs[4].P); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].cn0, greater.obs[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].lock, greater.obs[4].lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_obs_dep_a_t lesser = info.test_msg; + sbp_msg_obs_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.obs[4].prn, greater.obs[4].prn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgObsDepA); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_OBS_DEP_A"); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_obs_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_obs_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.obs_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.obs_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[72]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 72); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 72), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_obs_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 72); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgObsDepA, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_observation_msgObsDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgObsDepA, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_observation_observation_structs.cc b/c/test/cpp/auto_check_sbp_observation_observation_structs.cc new file mode 100644 index 0000000000..60ae9115d5 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_observation_observation_structs.cc @@ -0,0 +1,1733 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_observation_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_observation_observation_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs0() { + assign(test_struct_.n_obs, 68); + assign(test_struct_.t.ns_residual, -749915819); + assign(test_struct_.t.tow, 1204421761); + assign(test_struct_.t.wn, 45178); + } + + struct TestStructInfo { + sbp_observation_header_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_observation_header_t test_struct_{}; + uint8_t encoded_data_[11] = { + 129, 4, 202, 71, 85, 49, 77, 211, 122, 176, 68, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_observation_header_encoded_len(&info.test_struct), 11); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[11]; + EXPECT_EQ(sbp_observation_header_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + EXPECT_EQ(sbp_observation_header_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 11), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_observation_header_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_observation_header_t t{}; + EXPECT_EQ(sbp_observation_header_decode(info.encoded_data, 11, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_observation_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_observation_header_t t{}; + EXPECT_EQ(sbp_observation_header_decode(info.encoded_data, 11, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_observation_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_observation_header_t t{}; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_observation_header_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs1() { + assign(test_struct_.f, 185); + assign(test_struct_.i, 9039); + } + + struct TestStructInfo { + sbp_doppler_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_doppler_t test_struct_{}; + uint8_t encoded_data_[3] = { + 79, + 35, + 185, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_doppler_encoded_len(&info.test_struct), 3); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[3]; + EXPECT_EQ( + sbp_doppler_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + EXPECT_EQ( + sbp_doppler_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 3), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_doppler_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_doppler_t t{}; + EXPECT_EQ(sbp_doppler_decode(info.encoded_data, 3, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_doppler_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_doppler_t t{}; + EXPECT_EQ(sbp_doppler_decode(info.encoded_data, 3, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_doppler_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs1, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_doppler_t t{}; + + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_doppler_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs2 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs2() { + assign(test_struct_.D.f, 140); + assign(test_struct_.D.i, 17441); + assign(test_struct_.L.f, 113); + assign(test_struct_.L.i, -1839286973); + assign(test_struct_.P, 4093148394); + assign(test_struct_.cn0, 54); + assign(test_struct_.flags, 65); + assign(test_struct_.lock, 185); + assign(test_struct_.sid.code, 230); + assign(test_struct_.sid.sat, 170); + } + + struct TestStructInfo { + sbp_packed_obs_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_packed_obs_content_t test_struct_{}; + uint8_t encoded_data_[17] = { + 234, 124, 248, 243, 67, 181, 94, 146, 113, + 33, 68, 140, 54, 185, 65, 170, 230, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_packed_obs_content_encoded_len(&info.test_struct), 17); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[17]; + EXPECT_EQ(sbp_packed_obs_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[17]; + EXPECT_EQ(sbp_packed_obs_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 17), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[17]; + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ( + sbp_packed_obs_content_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_packed_obs_content_t t{}; + EXPECT_EQ(sbp_packed_obs_content_decode(info.encoded_data, 17, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_packed_obs_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_t t{}; + EXPECT_EQ(sbp_packed_obs_content_decode(info.encoded_data, 17, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_packed_obs_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs2, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_t t{}; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ(sbp_packed_obs_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs3 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs3() { + assign(test_struct_.L.f, 216); + assign(test_struct_.L.i, 900607277); + assign(test_struct_.P, 4011084941); + assign(test_struct_.flags, 40); + assign(test_struct_.iono_std, 10443); + assign(test_struct_.lock, 230); + assign(test_struct_.range_std, 2340); + assign(test_struct_.sid.code, 189); + assign(test_struct_.sid.sat, 56); + assign(test_struct_.tropo_std, 25355); + } + + struct TestStructInfo { + sbp_packed_osr_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_packed_osr_content_t test_struct_{}; + uint8_t encoded_data_[19] = { + 141, 76, 20, 239, 45, 45, 174, 53, 216, 230, + 40, 56, 189, 203, 40, 11, 99, 36, 9, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_packed_osr_content_encoded_len(&info.test_struct), 19); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[19]; + EXPECT_EQ(sbp_packed_osr_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 19); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[19]; + EXPECT_EQ(sbp_packed_osr_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 19), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[19]; + for (uint8_t i = 0; i < 19; i++) { + EXPECT_EQ( + sbp_packed_osr_content_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_packed_osr_content_t t{}; + EXPECT_EQ(sbp_packed_osr_content_decode(info.encoded_data, 19, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_packed_osr_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_packed_osr_content_t t{}; + EXPECT_EQ(sbp_packed_osr_content_decode(info.encoded_data, 19, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_packed_osr_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs3, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_packed_osr_content_t t{}; + + for (uint8_t i = 0; i < 19; i++) { + EXPECT_EQ(sbp_packed_osr_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs4 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs4() { + assign(test_struct_.fit_interval, 1060346971); + assign(test_struct_.health_bits, 115); + assign(test_struct_.sid.code, 93); + assign(test_struct_.sid.sat, 70); + assign(test_struct_.toe.tow, 1645528456); + assign(test_struct_.toe.wn, 39419); + assign(test_struct_.ura, 3505.199951); + assign(test_struct_.valid, 250); + } + + struct TestStructInfo { + sbp_ephemeris_common_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_ephemeris_common_content_t test_struct_{}; + uint8_t encoded_data_[18] = { + 70, 93, 136, 197, 20, 98, 251, 153, 51, + 19, 91, 69, 91, 156, 51, 63, 250, 115, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_ephemeris_common_content_encoded_len(&info.test_struct), 18); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[18]; + EXPECT_EQ(sbp_ephemeris_common_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 18); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[18]; + EXPECT_EQ(sbp_ephemeris_common_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 18), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[18]; + for (uint8_t i = 0; i < 18; i++) { + EXPECT_EQ(sbp_ephemeris_common_content_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_ephemeris_common_content_t t{}; + EXPECT_EQ( + sbp_ephemeris_common_content_decode(info.encoded_data, 18, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_ephemeris_common_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_t t{}; + EXPECT_EQ( + sbp_ephemeris_common_content_decode(info.encoded_data, 18, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_ephemeris_common_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs4, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_t t{}; + + for (uint8_t i = 0; i < 18; i++) { + EXPECT_EQ( + sbp_ephemeris_common_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs5 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs5() { + assign(test_struct_.fit_interval, 195023785); + assign(test_struct_.health_bits, 96); + assign(test_struct_.sid.code, 162); + assign(test_struct_.sid.sat, 5); + assign(test_struct_.toe.tow, 2868221875); + assign(test_struct_.toe.wn, 459); + assign(test_struct_.ura, 7160.2); + assign(test_struct_.valid, 70); + } + + struct TestStructInfo { + sbp_ephemeris_common_content_dep_b_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_ephemeris_common_content_dep_b_t test_struct_{}; + uint8_t encoded_data_[22] = { + 5, 162, 179, 151, 245, 170, 203, 1, 51, 51, 51, + 51, 51, 248, 187, 64, 169, 211, 159, 11, 70, 96, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_encoded_len(&info.test_struct), + 22); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[22]; + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[22]; + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 22), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[22]; + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_ephemeris_common_content_dep_b_t t{}; + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_decode(info.encoded_data, 22, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_dep_b_t t{}; + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_decode(info.encoded_data, 22, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs5, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_dep_b_t t{}; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_ephemeris_common_content_dep_b_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs6 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs6() { + assign(test_struct_.fit_interval, 3607180585); + assign(test_struct_.health_bits, 113); + assign(test_struct_.sid.code, 225); + assign(test_struct_.sid.sat, 41585); + assign(test_struct_.toe.tow, 1655038953); + assign(test_struct_.toe.wn, 45402); + assign(test_struct_.ura, 3126.2); + assign(test_struct_.valid, 199); + } + + struct TestStructInfo { + sbp_ephemeris_common_content_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_ephemeris_common_content_dep_a_t test_struct_{}; + uint8_t encoded_data_[24] = { + 113, 162, 225, 0, 233, 227, 165, 98, 90, 177, 102, 102, + 102, 102, 102, 108, 168, 64, 41, 53, 1, 215, 199, 113, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_encoded_len(&info.test_struct), + 24); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[24]; + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[24]; + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 24), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[24]; + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_ephemeris_common_content_dep_a_t t{}; + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_decode(info.encoded_data, 24, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_dep_a_t t{}; + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_decode(info.encoded_data, 24, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs6, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_ephemeris_common_content_dep_a_t t{}; + + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_ephemeris_common_content_dep_a_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs7 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs7() { + assign(test_struct_.n_obs, 33); + assign(test_struct_.t.tow, 4166840455); + assign(test_struct_.t.wn, 14864); + } + + struct TestStructInfo { + sbp_observation_header_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_observation_header_dep_t test_struct_{}; + uint8_t encoded_data_[7] = { + 135, 240, 92, 248, 16, 58, 33, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_observation_header_dep_encoded_len(&info.test_struct), 7); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[7]; + EXPECT_EQ(sbp_observation_header_dep_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 7); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[7]; + EXPECT_EQ(sbp_observation_header_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 7), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[7]; + for (uint8_t i = 0; i < 7; i++) { + EXPECT_EQ(sbp_observation_header_dep_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_observation_header_dep_t t{}; + EXPECT_EQ(sbp_observation_header_dep_decode(info.encoded_data, 7, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_observation_header_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_observation_header_dep_t t{}; + EXPECT_EQ( + sbp_observation_header_dep_decode(info.encoded_data, 7, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_observation_header_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs7, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_observation_header_dep_t t{}; + + for (uint8_t i = 0; i < 7; i++) { + EXPECT_EQ( + sbp_observation_header_dep_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs8 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs8() { + assign(test_struct_.f, 217); + assign(test_struct_.i, 1138701703); + } + + struct TestStructInfo { + sbp_carrier_phase_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_carrier_phase_dep_a_t test_struct_{}; + uint8_t encoded_data_[5] = { + 135, 53, 223, 67, 217, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_carrier_phase_dep_a_encoded_len(&info.test_struct), 5); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[5]; + EXPECT_EQ(sbp_carrier_phase_dep_a_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + EXPECT_EQ(sbp_carrier_phase_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 5), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ( + sbp_carrier_phase_dep_a_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_carrier_phase_dep_a_t t{}; + EXPECT_EQ(sbp_carrier_phase_dep_a_decode(info.encoded_data, 5, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_carrier_phase_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_carrier_phase_dep_a_t t{}; + EXPECT_EQ(sbp_carrier_phase_dep_a_decode(info.encoded_data, 5, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_carrier_phase_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs8, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_carrier_phase_dep_a_t t{}; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_carrier_phase_dep_a_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs9 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs9() { + assign(test_struct_.L.f, 211); + assign(test_struct_.L.i, -1008767887); + assign(test_struct_.P, 1469217046); + assign(test_struct_.cn0, 175); + assign(test_struct_.lock, 52050); + assign(test_struct_.prn, 147); + } + + struct TestStructInfo { + sbp_packed_obs_content_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_packed_obs_content_dep_a_t test_struct_{}; + uint8_t encoded_data_[13] = { + 22, 121, 146, 87, 113, 108, 223, 195, 211, 175, 82, 203, 147, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_packed_obs_content_dep_a_encoded_len(&info.test_struct), 13); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[13]; + EXPECT_EQ(sbp_packed_obs_content_dep_a_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[13]; + EXPECT_EQ(sbp_packed_obs_content_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 13), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[13]; + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ(sbp_packed_obs_content_dep_a_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_packed_obs_content_dep_a_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_a_decode(info.encoded_data, 13, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_packed_obs_content_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_a_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_a_decode(info.encoded_data, 13, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_packed_obs_content_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs9, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_a_t t{}; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ( + sbp_packed_obs_content_dep_a_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs10 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs10() { + assign(test_struct_.L.f, 155); + assign(test_struct_.L.i, -351247318); + assign(test_struct_.P, 2918161029); + assign(test_struct_.cn0, 223); + assign(test_struct_.lock, 17054); + assign(test_struct_.sid.code, 103); + assign(test_struct_.sid.reserved, 208); + assign(test_struct_.sid.sat, 42698); + } + + struct TestStructInfo { + sbp_packed_obs_content_dep_b_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_packed_obs_content_dep_b_t test_struct_{}; + uint8_t encoded_data_[16] = { + 133, 154, 239, 173, 42, 100, 16, 235, + 155, 223, 158, 66, 202, 166, 103, 208, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_packed_obs_content_dep_b_encoded_len(&info.test_struct), 16); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[16]; + EXPECT_EQ(sbp_packed_obs_content_dep_b_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + EXPECT_EQ(sbp_packed_obs_content_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 16), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_packed_obs_content_dep_b_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_packed_obs_content_dep_b_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_b_decode(info.encoded_data, 16, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_packed_obs_content_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_b_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_b_decode(info.encoded_data, 16, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_packed_obs_content_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs10, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_b_t t{}; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_packed_obs_content_dep_b_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs11 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs11() { + assign(test_struct_.L.f, 78); + assign(test_struct_.L.i, 1582873968); + assign(test_struct_.P, 3329272896); + assign(test_struct_.cn0, 113); + assign(test_struct_.lock, 26674); + assign(test_struct_.sid.code, 160); + assign(test_struct_.sid.reserved, 90); + assign(test_struct_.sid.sat, 53544); + } + + struct TestStructInfo { + sbp_packed_obs_content_dep_c_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_packed_obs_content_dep_c_t test_struct_{}; + uint8_t encoded_data_[16] = { + 64, 172, 112, 198, 112, 189, 88, 94, 78, 113, 50, 104, 40, 209, 160, 90, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_packed_obs_content_dep_c_encoded_len(&info.test_struct), 16); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[16]; + EXPECT_EQ(sbp_packed_obs_content_dep_c_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + EXPECT_EQ(sbp_packed_obs_content_dep_c_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 16), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_packed_obs_content_dep_c_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_packed_obs_content_dep_c_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_c_decode(info.encoded_data, 16, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_packed_obs_content_dep_c_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_c_t t{}; + EXPECT_EQ( + sbp_packed_obs_content_dep_c_decode(info.encoded_data, 16, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_packed_obs_content_dep_c_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs11, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_packed_obs_content_dep_c_t t{}; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_packed_obs_content_dep_c_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs12 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs12() { + assign(test_struct_.bds_active, 1076821549129); + assign(test_struct_.bds_b2, 878366344419); + assign(test_struct_.bds_b2a, 929021071030); + assign(test_struct_.bds_d2nav, 993705552075); + assign(test_struct_.gal_active, 713683388100); + assign(test_struct_.gal_e5, 82813285742); + assign(test_struct_.glo_active, 3618100845); + assign(test_struct_.glo_l2of, 2612838619); + assign(test_struct_.glo_l3, 1984440581); + assign(test_struct_.gps_active, 836207997107); + assign(test_struct_.gps_l2c, 11856600751); + assign(test_struct_.gps_l5, 410257746729); + assign(test_struct_.qzss_active, 2109335123); + assign(test_struct_.sbas_active, 835833936142); + assign(test_struct_.sbas_l5, 898852327014); + } + + struct TestStructInfo { + sbp_gnss_capb_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gnss_capb_t test_struct_{}; + uint8_t encoded_data_[104] = { + 179, 112, 225, 177, 194, 0, 0, 0, 175, 94, 181, 194, 2, 0, 0, + 0, 41, 107, 68, 133, 95, 0, 0, 0, 109, 214, 167, 215, 219, 192, + 188, 155, 5, 41, 72, 118, 14, 185, 149, 155, 194, 0, 0, 0, 102, + 14, 198, 71, 209, 0, 0, 0, 73, 224, 144, 183, 250, 0, 0, 0, + 203, 104, 119, 93, 231, 0, 0, 0, 227, 196, 182, 130, 204, 0, 0, + 0, 182, 142, 248, 77, 216, 0, 0, 0, 83, 230, 185, 125, 196, 70, + 216, 42, 166, 0, 0, 0, 110, 117, 14, 72, 19, 0, 0, 0, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gnss_capb_encoded_len(&info.test_struct), 104); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[104]; + EXPECT_EQ( + sbp_gnss_capb_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 104); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[104]; + EXPECT_EQ( + sbp_gnss_capb_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 104), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[104]; + for (uint8_t i = 0; i < 104; i++) { + EXPECT_EQ(sbp_gnss_capb_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gnss_capb_t t{}; + EXPECT_EQ(sbp_gnss_capb_decode(info.encoded_data, 104, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gnss_capb_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gnss_capb_t t{}; + EXPECT_EQ(sbp_gnss_capb_decode(info.encoded_data, 104, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_gnss_capb_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs12, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gnss_capb_t t{}; + + for (uint8_t i = 0; i < 104; i++) { + EXPECT_EQ(sbp_gnss_capb_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs13 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs13() { + assign(test_struct_.fit_interval, 3112182001); + assign(test_struct_.health_bits, 24); + assign(test_struct_.sid.code, 181); + assign(test_struct_.sid.sat, 163); + assign(test_struct_.toa.tow, 3325838080); + assign(test_struct_.toa.wn, 15069); + assign(test_struct_.ura, 8042.2); + assign(test_struct_.valid, 64); + } + + struct TestStructInfo { + sbp_almanac_common_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_almanac_common_content_t test_struct_{}; + uint8_t encoded_data_[22] = { + 163, 181, 0, 67, 60, 198, 221, 58, 51, 51, 51, + 51, 51, 106, 191, 64, 241, 32, 128, 185, 64, 24, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_almanac_common_content_encoded_len(&info.test_struct), 22); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[22]; + EXPECT_EQ(sbp_almanac_common_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 22); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[22]; + EXPECT_EQ(sbp_almanac_common_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 22), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[22]; + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ(sbp_almanac_common_content_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_almanac_common_content_t t{}; + EXPECT_EQ( + sbp_almanac_common_content_decode(info.encoded_data, 22, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_almanac_common_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_almanac_common_content_t t{}; + EXPECT_EQ( + sbp_almanac_common_content_decode(info.encoded_data, 22, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_almanac_common_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs13, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_almanac_common_content_t t{}; + + for (uint8_t i = 0; i < 22; i++) { + EXPECT_EQ( + sbp_almanac_common_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs14 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs14() { + assign(test_struct_.fit_interval, 4108237589); + assign(test_struct_.health_bits, 142); + assign(test_struct_.sid.code, 32); + assign(test_struct_.sid.reserved, 10); + assign(test_struct_.sid.sat, 57244); + assign(test_struct_.toa.tow, 1277272173); + assign(test_struct_.toa.wn, 2954); + assign(test_struct_.ura, 6746.2); + assign(test_struct_.valid, 52); + } + + struct TestStructInfo { + sbp_almanac_common_content_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_almanac_common_content_dep_t test_struct_{}; + uint8_t encoded_data_[24] = { + 156, 223, 32, 10, 109, 160, 33, 76, 138, 11, 51, 51, + 51, 51, 51, 90, 186, 64, 21, 187, 222, 244, 52, 142, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_almanac_common_content_dep_encoded_len(&info.test_struct), 24); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[24]; + EXPECT_EQ(sbp_almanac_common_content_dep_encode(&buf[0], sizeof(buf), + &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[24]; + EXPECT_EQ(sbp_almanac_common_content_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 24), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[24]; + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_almanac_common_content_dep_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_almanac_common_content_dep_t t{}; + EXPECT_EQ( + sbp_almanac_common_content_dep_decode(info.encoded_data, 24, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_almanac_common_content_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_almanac_common_content_dep_t t{}; + EXPECT_EQ( + sbp_almanac_common_content_dep_decode(info.encoded_data, 24, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_almanac_common_content_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs14, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_almanac_common_content_dep_t t{}; + + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_almanac_common_content_dep_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_observation_observation_structs15 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_observation_observation_structs15() { + assign(test_struct_.az, 127); + assign(test_struct_.el, 87); + assign(test_struct_.sid.code, 46); + assign(test_struct_.sid.sat, 115); + } + + struct TestStructInfo { + sbp_sv_az_el_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_sv_az_el_t test_struct_{}; + uint8_t encoded_data_[4] = { + 115, + 46, + 127, + 87, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_sv_az_el_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ( + sbp_sv_az_el_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ( + sbp_sv_az_el_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_sv_az_el_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_sv_az_el_t t{}; + EXPECT_EQ(sbp_sv_az_el_decode(info.encoded_data, 4, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_sv_az_el_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_sv_az_el_t t{}; + EXPECT_EQ(sbp_sv_az_el_decode(info.encoded_data, 4, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_sv_az_el_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_observation_observation_structs15, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_sv_az_el_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_sv_az_el_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_orientation_MsgAngularRate.cc b/c/test/cpp/auto_check_sbp_orientation_MsgAngularRate.cc index e878673879..b69614d823 100644 --- a/c/test/cpp/auto_check_sbp_orientation_MsgAngularRate.cc +++ b/c/test/cpp/auto_check_sbp_orientation_MsgAngularRate.cc @@ -16,98 +16,790 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_orientation_MsgAngularRate0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_orientation_MsgAngularRate0 : public ::testing::Test { public: - Test_auto_check_sbp_orientation_MsgAngularRate0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_orientation_MsgAngularRate0() { + assign(test_msg_.flags, 0); + assign(test_msg_.tow, 2); + assign(test_msg_.x, 2); + assign(test_msg_.y, 5); + assign(test_msg_.z, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_angular_rate_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_angular_rate_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAngularRate, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_angular_rate_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAngularRate); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->angular_rate, + sizeof(msg->angular_rate)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_angular_rate_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.angular_rate, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAngularRate); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x4658; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 17; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_angular_rate_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_angular_rate_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_angular_rate_t &lesser, + const sbp_msg_angular_rate_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_angular_rate_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_angular_rate_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_angular_rate_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_angular_rate_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgAngularRate, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAngularRate, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgAngularRate, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgAngularRate, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_orientation_MsgAngularRate0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_angular_rate_t test_msg_{}; + uint8_t encoded_frame_[17 + 8] = { 85, 34, 2, 66, 0, 17, 2, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, 88, 70, }; + uint8_t encoded_payload_[17] = { + 2, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 2, 0, 0, 0, 0, + }; +}; - sbp_msg_angular_rate_t test_msg{}; - test_msg.flags = 0; - test_msg.tow = 2; - test_msg.x = 2; - test_msg.y = 5; - test_msg.z = 2; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.tow, 2) - << "incorrect value for last_msg_.tow, expected 2, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.x, 2) - << "incorrect value for last_msg_.x, expected 2, is " << last_msg_.x; - EXPECT_EQ(last_msg_.y, 5) - << "incorrect value for last_msg_.y, expected 5, is " << last_msg_.y; - EXPECT_EQ(last_msg_.z, 2) - << "incorrect value for last_msg_.z, expected 2, is " << last_msg_.z; +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_angular_rate_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAngularRate, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_angular_rate_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgAngularRate, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + EXPECT_EQ(sbp_msg_angular_rate_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ(sbp_msg_angular_rate_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_angular_rate_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_angular_rate_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAngularRate, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_angular_rate_t msg{}; + + EXPECT_EQ(sbp_msg_angular_rate_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_angular_rate_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_angular_rate_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_angular_rate_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAngularRate, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAngularRate, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAngularRate, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_angular_rate_t lesser = info.test_msg; + sbp_msg_angular_rate_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_angular_rate_t lesser = info.test_msg; + sbp_msg_angular_rate_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_angular_rate_t lesser = info.test_msg; + sbp_msg_angular_rate_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_angular_rate_t lesser = info.test_msg; + sbp_msg_angular_rate_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_angular_rate_t lesser = info.test_msg; + sbp_msg_angular_rate_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgAngularRate); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ANGULAR_RATE"); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_angular_rate_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_angular_rate_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.angular_rate, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.angular_rate, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_angular_rate_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAngularRate, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgAngularRate0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgAngularRate, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc b/c/test/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc new file mode 100644 index 0000000000..7fd73e8895 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc @@ -0,0 +1,815 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_orientation_MsgBaselineHeading0 + : public ::testing::Test { + public: + Testauto_check_sbp_orientation_MsgBaselineHeading0() { + assign(test_msg_.flags, 91); + assign(test_msg_.heading, 1036342316); + assign(test_msg_.n_sats, 91); + assign(test_msg_.tow, 3289197980); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_heading_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_baseline_heading_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgBaselineHeading, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_baseline_heading_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgBaselineHeading); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->baseline_heading, + sizeof(msg->baseline_heading)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_baseline_heading_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.baseline_heading, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgBaselineHeading); + info.sender_id = 24019; + info.preamble = 0x55; + info.crc = 0xfee0; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_baseline_heading_t &lesser, + const sbp_msg_baseline_heading_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_baseline_heading_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_baseline_heading_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_baseline_heading_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_baseline_heading_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineHeading, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgBaselineHeading, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgBaselineHeading, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgBaselineHeading, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_baseline_heading_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 15, 2, 211, 93, 10, 156, 45, 13, + 196, 44, 84, 197, 61, 91, 91, 224, 254, + }; + uint8_t encoded_payload_[10] = { + 156, 45, 13, 196, 44, 84, 197, 61, 91, 91, + }; +}; + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_baseline_heading_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgBaselineHeading, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_baseline_heading_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgBaselineHeading, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_baseline_heading_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_baseline_heading_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_baseline_heading_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgBaselineHeading, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_t msg{}; + + EXPECT_EQ(sbp_msg_baseline_heading_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_baseline_heading_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_baseline_heading_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineHeading, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgBaselineHeading, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgBaselineHeading, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_baseline_heading_t lesser = info.test_msg; + sbp_msg_baseline_heading_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_t lesser = info.test_msg; + sbp_msg_baseline_heading_t greater = info.test_msg; + make_lesser_greater(lesser.heading, greater.heading); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_t lesser = info.test_msg; + sbp_msg_baseline_heading_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_baseline_heading_t lesser = info.test_msg; + sbp_msg_baseline_heading_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgBaselineHeading); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_BASELINE_HEADING"); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_baseline_heading_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_baseline_heading_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.baseline_heading, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.baseline_heading, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_baseline_heading_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgBaselineHeading, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgBaselineHeading0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgBaselineHeading, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_orientation_MsgOrientEuler.cc b/c/test/cpp/auto_check_sbp_orientation_MsgOrientEuler.cc index 7f8b87c3ad..5a79b2eaab 100644 --- a/c/test/cpp/auto_check_sbp_orientation_MsgOrientEuler.cc +++ b/c/test/cpp/auto_check_sbp_orientation_MsgOrientEuler.cc @@ -16,112 +16,812 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_orientation_MsgOrientEuler0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_orientation_MsgOrientEuler0 : public ::testing::Test { public: - Test_auto_check_sbp_orientation_MsgOrientEuler0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_orientation_MsgOrientEuler0() { + assign(test_msg_.flags, 3); + assign(test_msg_.pitch, 2); + assign(test_msg_.pitch_accuracy, 3.0); + assign(test_msg_.roll, 1); + assign(test_msg_.roll_accuracy, 7.0); + assign(test_msg_.tow, 1); + assign(test_msg_.yaw, 8); + assign(test_msg_.yaw_accuracy, 7.0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_orient_euler_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_orient_euler_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgOrientEuler, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_orient_euler_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgOrientEuler); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->orient_euler, + sizeof(msg->orient_euler)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_orient_euler_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.orient_euler, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgOrientEuler); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xe22c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 29; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_orient_euler_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_orient_euler_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_orient_euler_t &lesser, + const sbp_msg_orient_euler_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_orient_euler_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_orient_euler_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_orient_euler_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_orient_euler_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgOrientEuler, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgOrientEuler, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgOrientEuler, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgOrientEuler, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_orientation_MsgOrientEuler0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_orient_euler_t test_msg_{}; + uint8_t encoded_frame_[29 + 8] = { 85, 33, 2, 66, 0, 29, 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 224, 64, 0, 0, 64, 64, 0, 0, 224, 64, 3, 44, 226, }; + uint8_t encoded_payload_[29] = { + 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, + 0, 0, 0, 224, 64, 0, 0, 64, 64, 0, 0, 224, 64, 3, + }; +}; + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_orient_euler_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgOrientEuler, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_orient_euler_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgOrientEuler, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + EXPECT_EQ(sbp_msg_orient_euler_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + for (uint8_t i = 0; i < 29; i++) { + EXPECT_EQ(sbp_msg_orient_euler_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_orient_euler_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_orient_euler_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgOrientEuler, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_orient_euler_t msg{}; + + EXPECT_EQ(sbp_msg_orient_euler_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_orient_euler_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_orient_euler_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_orient_euler_t test_msg{}; - test_msg.flags = 3; - test_msg.pitch = 2; - test_msg.pitch_accuracy = 3.0; - test_msg.roll = 1; - test_msg.roll_accuracy = 7.0; - test_msg.tow = 1; - test_msg.yaw = 8; - test_msg.yaw_accuracy = 7.0; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 3) - << "incorrect value for last_msg_.flags, expected 3, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.pitch, 2) - << "incorrect value for last_msg_.pitch, expected 2, is " - << last_msg_.pitch; - EXPECT_LT((last_msg_.pitch_accuracy * 100 - 3.0 * 100), 0.05) - << "incorrect value for last_msg_.pitch_accuracy, expected 3.0, is " - << last_msg_.pitch_accuracy; - EXPECT_EQ(last_msg_.roll, 1) - << "incorrect value for last_msg_.roll, expected 1, is " - << last_msg_.roll; - EXPECT_LT((last_msg_.roll_accuracy * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.roll_accuracy, expected 7.0, is " - << last_msg_.roll_accuracy; - EXPECT_EQ(last_msg_.tow, 1) - << "incorrect value for last_msg_.tow, expected 1, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.yaw, 8) - << "incorrect value for last_msg_.yaw, expected 8, is " << last_msg_.yaw; - EXPECT_LT((last_msg_.yaw_accuracy * 100 - 7.0 * 100), 0.05) - << "incorrect value for last_msg_.yaw_accuracy, expected 7.0, is " - << last_msg_.yaw_accuracy; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_orient_euler_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOrientEuler, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgOrientEuler, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOrientEuler, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.pitch, greater.pitch); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.pitch_accuracy, greater.pitch_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.roll, greater.roll); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.roll_accuracy, greater.roll_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.yaw, greater.yaw); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_euler_t lesser = info.test_msg; + sbp_msg_orient_euler_t greater = info.test_msg; + make_lesser_greater(lesser.yaw_accuracy, greater.yaw_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgOrientEuler); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ORIENT_EULER"); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_orient_euler_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_orient_euler_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.orient_euler, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.orient_euler, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); } + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_orient_euler_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgOrientEuler, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientEuler0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgOrientEuler, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_orientation_MsgOrientQuat.cc b/c/test/cpp/auto_check_sbp_orientation_MsgOrientQuat.cc index 0223ee72d1..c0ab35c83c 100644 --- a/c/test/cpp/auto_check_sbp_orientation_MsgOrientQuat.cc +++ b/c/test/cpp/auto_check_sbp_orientation_MsgOrientQuat.cc @@ -16,118 +16,824 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_orientation_MsgOrientQuat0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_orientation_MsgOrientQuat0 : public ::testing::Test { public: - Test_auto_check_sbp_orientation_MsgOrientQuat0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_orientation_MsgOrientQuat0() { + assign(test_msg_.flags, 1); + assign(test_msg_.tow, 0); + assign(test_msg_.w, 3); + assign(test_msg_.w_accuracy, 3.0); + assign(test_msg_.x, 7); + assign(test_msg_.x_accuracy, 4.0); + assign(test_msg_.y, 8); + assign(test_msg_.y_accuracy, 8.0); + assign(test_msg_.z, 4); + assign(test_msg_.z_accuracy, 3.0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_orient_quat_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_orient_quat_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgOrientQuat, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_orient_quat_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgOrientQuat); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->orient_quat, sizeof(msg->orient_quat)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_orient_quat_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.orient_quat, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgOrientQuat); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x6ba; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 37; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_orient_quat_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_orient_quat_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_orient_quat_t &lesser, + const sbp_msg_orient_quat_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_orientation_MsgOrientQuat0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_orient_quat_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_orient_quat_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_orient_quat_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_orient_quat_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgOrientQuat, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgOrientQuat, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgOrientQuat, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgOrientQuat, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_orient_quat_t test_msg_{}; + uint8_t encoded_frame_[37 + 8] = { 85, 32, 2, 66, 0, 37, 0, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 4, 0, 0, 0, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 0, 65, 0, 0, 64, 64, 1, 186, 6, }; + uint8_t encoded_payload_[37] = { + 0, 0, 0, 0, 3, 0, 0, 0, 7, 0, 0, 0, 8, 0, 0, 0, 4, 0, 0, + 0, 0, 0, 64, 64, 0, 0, 128, 64, 0, 0, 0, 65, 0, 0, 64, 64, 1, + }; +}; + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_orient_quat_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgOrientQuat, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[37]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_orient_quat_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 37); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 37), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgOrientQuat, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 37); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 37), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[37]; + + EXPECT_EQ( + sbp_msg_orient_quat_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 37), 0); +} +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[37]; + + for (uint8_t i = 0; i < 37; i++) { + EXPECT_EQ(sbp_msg_orient_quat_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_orient_quat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_orient_quat_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 37); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgOrientQuat, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 37); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_orient_quat_t msg{}; + + EXPECT_EQ(sbp_msg_orient_quat_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_orient_quat_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_orient_quat_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_orient_quat_t test_msg{}; - test_msg.flags = 1; - test_msg.tow = 0; - test_msg.w = 3; - test_msg.w_accuracy = 3.0; - test_msg.x = 7; - test_msg.x_accuracy = 4.0; - test_msg.y = 8; - test_msg.y_accuracy = 8.0; - test_msg.z = 4; - test_msg.z_accuracy = 3.0; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.tow, 0) - << "incorrect value for last_msg_.tow, expected 0, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.w, 3) - << "incorrect value for last_msg_.w, expected 3, is " << last_msg_.w; - EXPECT_LT((last_msg_.w_accuracy * 100 - 3.0 * 100), 0.05) - << "incorrect value for last_msg_.w_accuracy, expected 3.0, is " - << last_msg_.w_accuracy; - EXPECT_EQ(last_msg_.x, 7) - << "incorrect value for last_msg_.x, expected 7, is " << last_msg_.x; - EXPECT_LT((last_msg_.x_accuracy * 100 - 4.0 * 100), 0.05) - << "incorrect value for last_msg_.x_accuracy, expected 4.0, is " - << last_msg_.x_accuracy; - EXPECT_EQ(last_msg_.y, 8) - << "incorrect value for last_msg_.y, expected 8, is " << last_msg_.y; - EXPECT_LT((last_msg_.y_accuracy * 100 - 8.0 * 100), 0.05) - << "incorrect value for last_msg_.y_accuracy, expected 8.0, is " - << last_msg_.y_accuracy; - EXPECT_EQ(last_msg_.z, 4) - << "incorrect value for last_msg_.z, expected 4, is " << last_msg_.z; - EXPECT_LT((last_msg_.z_accuracy * 100 - 3.0 * 100), 0.05) - << "incorrect value for last_msg_.z_accuracy, expected 3.0, is " - << last_msg_.z_accuracy; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_orient_quat_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOrientQuat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgOrientQuat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOrientQuat, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.w, greater.w); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.w_accuracy, greater.w_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.x, greater.x); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.x_accuracy, greater.x_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.y, greater.y); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.y_accuracy, greater.y_accuracy); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.z, greater.z); + comparison_tests(lesser, greater); + } + { + sbp_msg_orient_quat_t lesser = info.test_msg; + sbp_msg_orient_quat_t greater = info.test_msg; + make_lesser_greater(lesser.z_accuracy, greater.z_accuracy); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgOrientQuat); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ORIENT_QUAT"); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_orient_quat_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_orient_quat_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.orient_quat, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.orient_quat, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[37]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 37); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 37), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_orient_quat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 37); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgOrientQuat, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_orientation_MsgOrientQuat0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgOrientQuat, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgAlmanac.cc b/c/test/cpp/auto_check_sbp_piksi_MsgAlmanac.cc new file mode 100644 index 0000000000..f7e4d4272e --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgAlmanac.cc @@ -0,0 +1,725 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgAlmanac0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgAlmanac0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_almanac_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgAlmanac, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_almanac_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgAlmanac); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->almanac, sizeof(msg->almanac)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_almanac_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.almanac, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgAlmanac); + info.sender_id = 35436; + info.preamble = 0x55; + info.crc = 0xabf9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_almanac_t &lesser, + const sbp_msg_almanac_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_almanac_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_almanac_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_almanac_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_almanac_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgAlmanac, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgAlmanac, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgAlmanac, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgAlmanac, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_almanac_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 105, 0, 108, 138, 0, 249, 171, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_almanac_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgAlmanac, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_almanac_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgAlmanac, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_almanac_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_almanac_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgAlmanac, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_almanac_t msg{}; + + EXPECT_EQ(sbp_msg_almanac_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_almanac_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanac, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgAlmanac, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgAlmanac, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgAlmanac); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_ALMANAC"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_almanac_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_almanac_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.almanac, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.almanac, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_almanac_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgAlmanac, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgAlmanac0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgAlmanac, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc new file mode 100644 index 0000000000..a9afad4e7b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc @@ -0,0 +1,3094 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCellModemStatus0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCellModemStatus0() { + assign(test_msg_.n_reserved, 250); + + assign(test_msg_.reserved[0], 123); + + assign(test_msg_.reserved[1], 242); + + assign(test_msg_.reserved[2], 46); + + assign(test_msg_.reserved[3], 52); + + assign(test_msg_.reserved[4], 64); + + assign(test_msg_.reserved[5], 176); + + assign(test_msg_.reserved[6], 154); + + assign(test_msg_.reserved[7], 98); + + assign(test_msg_.reserved[8], 43); + + assign(test_msg_.reserved[9], 132); + + assign(test_msg_.reserved[10], 196); + + assign(test_msg_.reserved[11], 89); + + assign(test_msg_.reserved[12], 253); + + assign(test_msg_.reserved[13], 161); + + assign(test_msg_.reserved[14], 250); + + assign(test_msg_.reserved[15], 174); + + assign(test_msg_.reserved[16], 204); + + assign(test_msg_.reserved[17], 110); + + assign(test_msg_.reserved[18], 47); + + assign(test_msg_.reserved[19], 38); + + assign(test_msg_.reserved[20], 187); + + assign(test_msg_.reserved[21], 63); + + assign(test_msg_.reserved[22], 102); + + assign(test_msg_.reserved[23], 177); + + assign(test_msg_.reserved[24], 162); + + assign(test_msg_.reserved[25], 49); + + assign(test_msg_.reserved[26], 80); + + assign(test_msg_.reserved[27], 194); + + assign(test_msg_.reserved[28], 37); + + assign(test_msg_.reserved[29], 107); + + assign(test_msg_.reserved[30], 60); + + assign(test_msg_.reserved[31], 225); + + assign(test_msg_.reserved[32], 52); + + assign(test_msg_.reserved[33], 101); + + assign(test_msg_.reserved[34], 178); + + assign(test_msg_.reserved[35], 142); + + assign(test_msg_.reserved[36], 246); + + assign(test_msg_.reserved[37], 21); + + assign(test_msg_.reserved[38], 17); + + assign(test_msg_.reserved[39], 93); + + assign(test_msg_.reserved[40], 75); + + assign(test_msg_.reserved[41], 169); + + assign(test_msg_.reserved[42], 86); + + assign(test_msg_.reserved[43], 16); + + assign(test_msg_.reserved[44], 209); + + assign(test_msg_.reserved[45], 80); + + assign(test_msg_.reserved[46], 243); + + assign(test_msg_.reserved[47], 30); + + assign(test_msg_.reserved[48], 206); + + assign(test_msg_.reserved[49], 220); + + assign(test_msg_.reserved[50], 206); + + assign(test_msg_.reserved[51], 115); + + assign(test_msg_.reserved[52], 47); + + assign(test_msg_.reserved[53], 154); + + assign(test_msg_.reserved[54], 91); + + assign(test_msg_.reserved[55], 227); + + assign(test_msg_.reserved[56], 88); + + assign(test_msg_.reserved[57], 11); + + assign(test_msg_.reserved[58], 1); + + assign(test_msg_.reserved[59], 85); + + assign(test_msg_.reserved[60], 146); + + assign(test_msg_.reserved[61], 100); + + assign(test_msg_.reserved[62], 190); + + assign(test_msg_.reserved[63], 232); + + assign(test_msg_.reserved[64], 207); + + assign(test_msg_.reserved[65], 61); + + assign(test_msg_.reserved[66], 61); + + assign(test_msg_.reserved[67], 201); + + assign(test_msg_.reserved[68], 220); + + assign(test_msg_.reserved[69], 31); + + assign(test_msg_.reserved[70], 78); + + assign(test_msg_.reserved[71], 34); + + assign(test_msg_.reserved[72], 57); + + assign(test_msg_.reserved[73], 82); + + assign(test_msg_.reserved[74], 59); + + assign(test_msg_.reserved[75], 104); + + assign(test_msg_.reserved[76], 65); + + assign(test_msg_.reserved[77], 221); + + assign(test_msg_.reserved[78], 0); + + assign(test_msg_.reserved[79], 43); + + assign(test_msg_.reserved[80], 210); + + assign(test_msg_.reserved[81], 9); + + assign(test_msg_.reserved[82], 32); + + assign(test_msg_.reserved[83], 122); + + assign(test_msg_.reserved[84], 29); + + assign(test_msg_.reserved[85], 237); + + assign(test_msg_.reserved[86], 11); + + assign(test_msg_.reserved[87], 151); + + assign(test_msg_.reserved[88], 223); + + assign(test_msg_.reserved[89], 18); + + assign(test_msg_.reserved[90], 81); + + assign(test_msg_.reserved[91], 204); + + assign(test_msg_.reserved[92], 172); + + assign(test_msg_.reserved[93], 234); + + assign(test_msg_.reserved[94], 127); + + assign(test_msg_.reserved[95], 3); + + assign(test_msg_.reserved[96], 82); + + assign(test_msg_.reserved[97], 133); + + assign(test_msg_.reserved[98], 169); + + assign(test_msg_.reserved[99], 12); + + assign(test_msg_.reserved[100], 176); + + assign(test_msg_.reserved[101], 193); + + assign(test_msg_.reserved[102], 0); + + assign(test_msg_.reserved[103], 24); + + assign(test_msg_.reserved[104], 121); + + assign(test_msg_.reserved[105], 85); + + assign(test_msg_.reserved[106], 55); + + assign(test_msg_.reserved[107], 214); + + assign(test_msg_.reserved[108], 198); + + assign(test_msg_.reserved[109], 75); + + assign(test_msg_.reserved[110], 234); + + assign(test_msg_.reserved[111], 179); + + assign(test_msg_.reserved[112], 214); + + assign(test_msg_.reserved[113], 85); + + assign(test_msg_.reserved[114], 94); + + assign(test_msg_.reserved[115], 115); + + assign(test_msg_.reserved[116], 21); + + assign(test_msg_.reserved[117], 73); + + assign(test_msg_.reserved[118], 121); + + assign(test_msg_.reserved[119], 75); + + assign(test_msg_.reserved[120], 46); + + assign(test_msg_.reserved[121], 158); + + assign(test_msg_.reserved[122], 63); + + assign(test_msg_.reserved[123], 100); + + assign(test_msg_.reserved[124], 122); + + assign(test_msg_.reserved[125], 213); + + assign(test_msg_.reserved[126], 20); + + assign(test_msg_.reserved[127], 85); + + assign(test_msg_.reserved[128], 212); + + assign(test_msg_.reserved[129], 131); + + assign(test_msg_.reserved[130], 50); + + assign(test_msg_.reserved[131], 224); + + assign(test_msg_.reserved[132], 218); + + assign(test_msg_.reserved[133], 215); + + assign(test_msg_.reserved[134], 215); + + assign(test_msg_.reserved[135], 149); + + assign(test_msg_.reserved[136], 2); + + assign(test_msg_.reserved[137], 19); + + assign(test_msg_.reserved[138], 129); + + assign(test_msg_.reserved[139], 39); + + assign(test_msg_.reserved[140], 164); + + assign(test_msg_.reserved[141], 5); + + assign(test_msg_.reserved[142], 175); + + assign(test_msg_.reserved[143], 6); + + assign(test_msg_.reserved[144], 62); + + assign(test_msg_.reserved[145], 51); + + assign(test_msg_.reserved[146], 78); + + assign(test_msg_.reserved[147], 66); + + assign(test_msg_.reserved[148], 248); + + assign(test_msg_.reserved[149], 116); + + assign(test_msg_.reserved[150], 88); + + assign(test_msg_.reserved[151], 90); + + assign(test_msg_.reserved[152], 128); + + assign(test_msg_.reserved[153], 226); + + assign(test_msg_.reserved[154], 177); + + assign(test_msg_.reserved[155], 0); + + assign(test_msg_.reserved[156], 47); + + assign(test_msg_.reserved[157], 140); + + assign(test_msg_.reserved[158], 33); + + assign(test_msg_.reserved[159], 126); + + assign(test_msg_.reserved[160], 221); + + assign(test_msg_.reserved[161], 110); + + assign(test_msg_.reserved[162], 144); + + assign(test_msg_.reserved[163], 97); + + assign(test_msg_.reserved[164], 74); + + assign(test_msg_.reserved[165], 250); + + assign(test_msg_.reserved[166], 181); + + assign(test_msg_.reserved[167], 199); + + assign(test_msg_.reserved[168], 27); + + assign(test_msg_.reserved[169], 176); + + assign(test_msg_.reserved[170], 65); + + assign(test_msg_.reserved[171], 185); + + assign(test_msg_.reserved[172], 110); + + assign(test_msg_.reserved[173], 92); + + assign(test_msg_.reserved[174], 34); + + assign(test_msg_.reserved[175], 44); + + assign(test_msg_.reserved[176], 131); + + assign(test_msg_.reserved[177], 96); + + assign(test_msg_.reserved[178], 178); + + assign(test_msg_.reserved[179], 40); + + assign(test_msg_.reserved[180], 176); + + assign(test_msg_.reserved[181], 4); + + assign(test_msg_.reserved[182], 90); + + assign(test_msg_.reserved[183], 36); + + assign(test_msg_.reserved[184], 7); + + assign(test_msg_.reserved[185], 180); + + assign(test_msg_.reserved[186], 244); + + assign(test_msg_.reserved[187], 244); + + assign(test_msg_.reserved[188], 23); + + assign(test_msg_.reserved[189], 108); + + assign(test_msg_.reserved[190], 171); + + assign(test_msg_.reserved[191], 204); + + assign(test_msg_.reserved[192], 196); + + assign(test_msg_.reserved[193], 61); + + assign(test_msg_.reserved[194], 51); + + assign(test_msg_.reserved[195], 179); + + assign(test_msg_.reserved[196], 242); + + assign(test_msg_.reserved[197], 156); + + assign(test_msg_.reserved[198], 81); + + assign(test_msg_.reserved[199], 83); + + assign(test_msg_.reserved[200], 16); + + assign(test_msg_.reserved[201], 15); + + assign(test_msg_.reserved[202], 134); + + assign(test_msg_.reserved[203], 40); + + assign(test_msg_.reserved[204], 245); + + assign(test_msg_.reserved[205], 253); + + assign(test_msg_.reserved[206], 150); + + assign(test_msg_.reserved[207], 94); + + assign(test_msg_.reserved[208], 150); + + assign(test_msg_.reserved[209], 144); + + assign(test_msg_.reserved[210], 197); + + assign(test_msg_.reserved[211], 113); + + assign(test_msg_.reserved[212], 5); + + assign(test_msg_.reserved[213], 141); + + assign(test_msg_.reserved[214], 232); + + assign(test_msg_.reserved[215], 33); + + assign(test_msg_.reserved[216], 101); + + assign(test_msg_.reserved[217], 231); + + assign(test_msg_.reserved[218], 38); + + assign(test_msg_.reserved[219], 75); + + assign(test_msg_.reserved[220], 178); + + assign(test_msg_.reserved[221], 243); + + assign(test_msg_.reserved[222], 119); + + assign(test_msg_.reserved[223], 1); + + assign(test_msg_.reserved[224], 248); + + assign(test_msg_.reserved[225], 218); + + assign(test_msg_.reserved[226], 86); + + assign(test_msg_.reserved[227], 7); + + assign(test_msg_.reserved[228], 88); + + assign(test_msg_.reserved[229], 197); + + assign(test_msg_.reserved[230], 148); + + assign(test_msg_.reserved[231], 240); + + assign(test_msg_.reserved[232], 227); + + assign(test_msg_.reserved[233], 2); + + assign(test_msg_.reserved[234], 65); + + assign(test_msg_.reserved[235], 173); + + assign(test_msg_.reserved[236], 122); + + assign(test_msg_.reserved[237], 143); + + assign(test_msg_.reserved[238], 251); + + assign(test_msg_.reserved[239], 156); + + assign(test_msg_.reserved[240], 217); + + assign(test_msg_.reserved[241], 67); + + assign(test_msg_.reserved[242], 239); + + assign(test_msg_.reserved[243], 219); + + assign(test_msg_.reserved[244], 31); + + assign(test_msg_.reserved[245], 224); + + assign(test_msg_.reserved[246], 176); + + assign(test_msg_.reserved[247], 129); + + assign(test_msg_.reserved[248], 81); + + assign(test_msg_.reserved[249], 80); + assign(test_msg_.signal_error_rate, 8588.2001953125); + assign(test_msg_.signal_strength, 103); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_cell_modem_status_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_cell_modem_status_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCellModemStatus, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_cell_modem_status_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCellModemStatus); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->cell_modem_status, + sizeof(msg->cell_modem_status)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_cell_modem_status_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.cell_modem_status, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCellModemStatus); + info.sender_id = 6931; + info.preamble = 0x55; + info.crc = 0xe628; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_cell_modem_status_t &lesser, + const sbp_msg_cell_modem_status_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_cell_modem_status_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_cell_modem_status_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_cell_modem_status_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_cell_modem_status_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgCellModemStatus, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCellModemStatus, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgCellModemStatus, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgCellModemStatus, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_cell_modem_status_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, 52, + 64, 176, 154, 98, 43, 132, 196, 89, 253, 161, 250, 174, 204, 110, 47, + 38, 187, 63, 102, 177, 162, 49, 80, 194, 37, 107, 60, 225, 52, 101, + 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, 80, 243, 30, 206, + 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, 85, 146, 100, 190, 232, + 207, 61, 61, 201, 220, 31, 78, 34, 57, 82, 59, 104, 65, 221, 0, + 43, 210, 9, 32, 122, 29, 237, 11, 151, 223, 18, 81, 204, 172, 234, + 127, 3, 82, 133, 169, 12, 176, 193, 0, 24, 121, 85, 55, 214, 198, + 75, 234, 179, 214, 85, 94, 115, 21, 73, 121, 75, 46, 158, 63, 100, + 122, 213, 20, 85, 212, 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, + 39, 164, 5, 175, 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, + 177, 0, 47, 140, 33, 126, 221, 110, 144, 97, 74, 250, 181, 199, 27, + 176, 65, 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, 4, 90, 36, + 7, 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, + 83, 16, 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, 141, + 232, 33, 101, 231, 38, 75, 178, 243, 119, 1, 248, 218, 86, 7, 88, + 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, 156, 217, 67, 239, 219, + 31, 224, 176, 129, 81, 80, 40, 230, + }; + uint8_t encoded_payload_[255] = { + 103, 205, 48, 6, 70, 123, 242, 46, 52, 64, 176, 154, 98, 43, 132, + 196, 89, 253, 161, 250, 174, 204, 110, 47, 38, 187, 63, 102, 177, 162, + 49, 80, 194, 37, 107, 60, 225, 52, 101, 178, 142, 246, 21, 17, 93, + 75, 169, 86, 16, 209, 80, 243, 30, 206, 220, 206, 115, 47, 154, 91, + 227, 88, 11, 1, 85, 146, 100, 190, 232, 207, 61, 61, 201, 220, 31, + 78, 34, 57, 82, 59, 104, 65, 221, 0, 43, 210, 9, 32, 122, 29, + 237, 11, 151, 223, 18, 81, 204, 172, 234, 127, 3, 82, 133, 169, 12, + 176, 193, 0, 24, 121, 85, 55, 214, 198, 75, 234, 179, 214, 85, 94, + 115, 21, 73, 121, 75, 46, 158, 63, 100, 122, 213, 20, 85, 212, 131, + 50, 224, 218, 215, 215, 149, 2, 19, 129, 39, 164, 5, 175, 6, 62, + 51, 78, 66, 248, 116, 88, 90, 128, 226, 177, 0, 47, 140, 33, 126, + 221, 110, 144, 97, 74, 250, 181, 199, 27, 176, 65, 185, 110, 92, 34, + 44, 131, 96, 178, 40, 176, 4, 90, 36, 7, 180, 244, 244, 23, 108, + 171, 204, 196, 61, 51, 179, 242, 156, 81, 83, 16, 15, 134, 40, 245, + 253, 150, 94, 150, 144, 197, 113, 5, 141, 232, 33, 101, 231, 38, 75, + 178, 243, 119, 1, 248, 218, 86, 7, 88, 197, 148, 240, 227, 2, 65, + 173, 122, 143, 251, 156, 217, 67, 239, 219, 31, 224, 176, 129, 81, 80, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_cell_modem_status_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgCellModemStatus, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_cell_modem_status_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCellModemStatus, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ(sbp_msg_cell_modem_status_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ( + sbp_msg_cell_modem_status_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cell_modem_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_cell_modem_status_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCellModemStatus, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_cell_modem_status_t msg{}; + + EXPECT_EQ(sbp_msg_cell_modem_status_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_cell_modem_status_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_cell_modem_status_t t{}; + return sbp_msg_cell_modem_status_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_cell_modem_status_t t{}; + t.n_reserved = 1; + return sbp_msg_cell_modem_status_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_cell_modem_status_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_cell_modem_status_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCellModemStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCellModemStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCellModemStatus, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.n_reserved, greater.n_reserved); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[0], greater.reserved[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[1], greater.reserved[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[2], greater.reserved[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[3], greater.reserved[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[4], greater.reserved[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[5], greater.reserved[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[6], greater.reserved[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[7], greater.reserved[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[8], greater.reserved[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[9], greater.reserved[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[10], greater.reserved[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[11], greater.reserved[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[12], greater.reserved[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[13], greater.reserved[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[14], greater.reserved[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[15], greater.reserved[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[16], greater.reserved[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[17], greater.reserved[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[18], greater.reserved[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[19], greater.reserved[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[20], greater.reserved[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[21], greater.reserved[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[22], greater.reserved[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[23], greater.reserved[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[24], greater.reserved[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[25], greater.reserved[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[26], greater.reserved[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[27], greater.reserved[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[28], greater.reserved[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[29], greater.reserved[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[30], greater.reserved[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[31], greater.reserved[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[32], greater.reserved[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[33], greater.reserved[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[34], greater.reserved[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[35], greater.reserved[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[36], greater.reserved[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[37], greater.reserved[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[38], greater.reserved[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[39], greater.reserved[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[40], greater.reserved[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[41], greater.reserved[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[42], greater.reserved[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[43], greater.reserved[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[44], greater.reserved[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[45], greater.reserved[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[46], greater.reserved[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[47], greater.reserved[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[48], greater.reserved[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[49], greater.reserved[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[50], greater.reserved[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[51], greater.reserved[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[52], greater.reserved[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[53], greater.reserved[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[54], greater.reserved[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[55], greater.reserved[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[56], greater.reserved[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[57], greater.reserved[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[58], greater.reserved[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[59], greater.reserved[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[60], greater.reserved[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[61], greater.reserved[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[62], greater.reserved[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[63], greater.reserved[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[64], greater.reserved[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[65], greater.reserved[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[66], greater.reserved[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[67], greater.reserved[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[68], greater.reserved[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[69], greater.reserved[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[70], greater.reserved[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[71], greater.reserved[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[72], greater.reserved[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[73], greater.reserved[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[74], greater.reserved[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[75], greater.reserved[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[76], greater.reserved[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[77], greater.reserved[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[78], greater.reserved[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[79], greater.reserved[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[80], greater.reserved[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[81], greater.reserved[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[82], greater.reserved[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[83], greater.reserved[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[84], greater.reserved[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[85], greater.reserved[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[86], greater.reserved[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[87], greater.reserved[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[88], greater.reserved[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[89], greater.reserved[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[90], greater.reserved[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[91], greater.reserved[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[92], greater.reserved[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[93], greater.reserved[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[94], greater.reserved[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[95], greater.reserved[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[96], greater.reserved[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[97], greater.reserved[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[98], greater.reserved[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[99], greater.reserved[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[100], greater.reserved[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[101], greater.reserved[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[102], greater.reserved[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[103], greater.reserved[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[104], greater.reserved[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[105], greater.reserved[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[106], greater.reserved[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[107], greater.reserved[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[108], greater.reserved[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[109], greater.reserved[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[110], greater.reserved[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[111], greater.reserved[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[112], greater.reserved[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[113], greater.reserved[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[114], greater.reserved[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[115], greater.reserved[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[116], greater.reserved[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[117], greater.reserved[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[118], greater.reserved[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[119], greater.reserved[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[120], greater.reserved[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[121], greater.reserved[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[122], greater.reserved[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[123], greater.reserved[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[124], greater.reserved[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[125], greater.reserved[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[126], greater.reserved[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[127], greater.reserved[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[128], greater.reserved[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[129], greater.reserved[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[130], greater.reserved[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[131], greater.reserved[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[132], greater.reserved[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[133], greater.reserved[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[134], greater.reserved[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[135], greater.reserved[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[136], greater.reserved[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[137], greater.reserved[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[138], greater.reserved[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[139], greater.reserved[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[140], greater.reserved[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[141], greater.reserved[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[142], greater.reserved[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[143], greater.reserved[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[144], greater.reserved[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[145], greater.reserved[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[146], greater.reserved[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[147], greater.reserved[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[148], greater.reserved[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[149], greater.reserved[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[150], greater.reserved[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[151], greater.reserved[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[152], greater.reserved[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[153], greater.reserved[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[154], greater.reserved[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[155], greater.reserved[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[156], greater.reserved[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[157], greater.reserved[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[158], greater.reserved[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[159], greater.reserved[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[160], greater.reserved[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[161], greater.reserved[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[162], greater.reserved[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[163], greater.reserved[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[164], greater.reserved[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[165], greater.reserved[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[166], greater.reserved[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[167], greater.reserved[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[168], greater.reserved[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[169], greater.reserved[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[170], greater.reserved[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[171], greater.reserved[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[172], greater.reserved[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[173], greater.reserved[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[174], greater.reserved[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[175], greater.reserved[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[176], greater.reserved[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[177], greater.reserved[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[178], greater.reserved[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[179], greater.reserved[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[180], greater.reserved[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[181], greater.reserved[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[182], greater.reserved[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[183], greater.reserved[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[184], greater.reserved[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[185], greater.reserved[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[186], greater.reserved[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[187], greater.reserved[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[188], greater.reserved[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[189], greater.reserved[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[190], greater.reserved[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[191], greater.reserved[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[192], greater.reserved[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[193], greater.reserved[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[194], greater.reserved[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[195], greater.reserved[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[196], greater.reserved[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[197], greater.reserved[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[198], greater.reserved[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[199], greater.reserved[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[200], greater.reserved[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[201], greater.reserved[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[202], greater.reserved[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[203], greater.reserved[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[204], greater.reserved[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[205], greater.reserved[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[206], greater.reserved[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[207], greater.reserved[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[208], greater.reserved[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[209], greater.reserved[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[210], greater.reserved[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[211], greater.reserved[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[212], greater.reserved[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[213], greater.reserved[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[214], greater.reserved[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[215], greater.reserved[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[216], greater.reserved[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[217], greater.reserved[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[218], greater.reserved[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[219], greater.reserved[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[220], greater.reserved[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[221], greater.reserved[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[222], greater.reserved[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[223], greater.reserved[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[224], greater.reserved[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[225], greater.reserved[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[226], greater.reserved[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[227], greater.reserved[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[228], greater.reserved[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[229], greater.reserved[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[230], greater.reserved[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[231], greater.reserved[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[232], greater.reserved[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[233], greater.reserved[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[234], greater.reserved[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[235], greater.reserved[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[236], greater.reserved[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[237], greater.reserved[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[238], greater.reserved[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[239], greater.reserved[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[240], greater.reserved[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[241], greater.reserved[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[242], greater.reserved[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[243], greater.reserved[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[244], greater.reserved[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[245], greater.reserved[245]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[246], greater.reserved[246]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[247], greater.reserved[247]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[248], greater.reserved[248]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.reserved[249], greater.reserved[249]); + comparison_tests(lesser, greater); + } + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.signal_error_rate, greater.signal_error_rate); + comparison_tests(lesser, greater); + } + { + sbp_msg_cell_modem_status_t lesser = info.test_msg; + sbp_msg_cell_modem_status_t greater = info.test_msg; + make_lesser_greater(lesser.signal_strength, greater.signal_strength); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCellModemStatus); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CELL_MODEM_STATUS"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_cell_modem_status_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_cell_modem_status_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.cell_modem_status, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.cell_modem_status, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cell_modem_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCellModemStatus, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCellModemStatus0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCellModemStatus, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc new file mode 100644 index 0000000000..f1ee1b1e09 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc @@ -0,0 +1,932 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCommandOutput0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCommandOutput0() { + size_t written; + EXPECT_TRUE(sbp_msg_command_output_line_set(&test_msg_, "Some output text", + false, &written)); + EXPECT_EQ(written, strlen("Some output text")); + EXPECT_EQ(sbp_msg_command_output_line_encoded_len(&test_msg_), 16); + assign(test_msg_.sequence, 2507449470); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_command_output_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_command_output_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCommandOutput, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_command_output_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCommandOutput); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->command_output, + sizeof(msg->command_output)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_command_output_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.command_output, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCommandOutput); + info.sender_id = 21554; + info.preamble = 0x55; + info.crc = 0x6d0b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_command_output_t &lesser, + const sbp_msg_command_output_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_command_output_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_command_output_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_command_output_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_command_output_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgCommandOutput, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCommandOutput, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgCommandOutput, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgCommandOutput, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_command_output_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, + 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116, 11, 109, + }; + uint8_t encoded_payload_[20] = { + 126, 164, 116, 149, 83, 111, 109, 101, 32, 111, + 117, 116, 112, 117, 116, 32, 116, 101, 120, 116, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_command_output_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgCommandOutput, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_command_output_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCommandOutput, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ(sbp_msg_command_output_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ( + sbp_msg_command_output_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_output_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_command_output_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCommandOutput, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_command_output_t msg{}; + + EXPECT_EQ(sbp_msg_command_output_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_command_output_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_COMMAND_OUTPUT_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_command_output_t t{}; return + // sbp_msg_command_output_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_command_output_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_command_output_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandOutput, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCommandOutput, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandOutput, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_command_output_t lesser = info.test_msg; + sbp_msg_command_output_t greater = info.test_msg; + make_lesser_greater(lesser.line, greater.line); + comparison_tests(lesser, greater); + } + { + sbp_msg_command_output_t lesser = info.test_msg; + sbp_msg_command_output_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCommandOutput); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_COMMAND_OUTPUT"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_command_output_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_command_output_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.command_output, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.command_output, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_output_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCommandOutput, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCommandOutput, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgCommandOutput0_line + : public Testauto_check_sbp_piksi_MsgCommandOutput0 {}; + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, StringInit) { + sbp_msg_command_output_t t{}; + sbp_msg_command_output_line_init(&t); + EXPECT_TRUE(sbp_msg_command_output_line_valid(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, IsValid) { + sbp_msg_command_output_t t{}; + + size_t written; + EXPECT_TRUE( + sbp_msg_command_output_line_set(&t, "Some output text", false, &written)); + EXPECT_EQ(written, strlen("Some output text")); + EXPECT_EQ(sbp_msg_command_output_line_encoded_len(&t), 16); + EXPECT_TRUE(sbp_msg_command_output_line_valid(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, SpaceRemaining) { + sbp_msg_command_output_t t{}; + size_t empty_space_remaining = + sbp_msg_command_output_line_space_remaining(&t); + + size_t written; + EXPECT_TRUE( + sbp_msg_command_output_line_set(&t, "Some output text", false, &written)); + EXPECT_EQ(written, strlen("Some output text")); + EXPECT_EQ(sbp_msg_command_output_line_encoded_len(&t), 16); + size_t assigned_space_remaining = + sbp_msg_command_output_line_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_command_output_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_command_output_line_set_raw( + &t, info.test_msg.line.data, + sbp_msg_command_output_line_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_command_output_line_encoded_len(&info.test_msg), + sbp_msg_command_output_line_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, Set) { + sbp_msg_command_output_t t{}; + size_t nwritten{}; + const char *text = "Some output text"; + + EXPECT_TRUE(sbp_msg_command_output_line_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, Printf) { + sbp_msg_command_output_t t{}; + size_t nwritten{}; + const char *text = "Some output text"; + + EXPECT_TRUE( + sbp_msg_command_output_line_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, Vprintf) { + sbp_msg_command_output_t t{}; + size_t nwritten{}; + const char *text = "Some output text"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_command_output_line_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, AppendPrintf) { + sbp_msg_command_output_t t{}; + size_t nwritten{}; + char part1[] = "Some output text"; + char part2[] = "Some output text"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_command_output_line_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_command_output_line_append_printf(&t, false, &nwritten, + "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), "Some output text"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandOutput0_line, AppendVprintf) { + sbp_msg_command_output_t t{}; + size_t nwritten{}; + char part1[] = "Some output text"; + char part2[] = "Some output text"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_command_output_line_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_command_output_line_append_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_command_output_line_get(&t), "Some output text"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCommandReq.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCommandReq.cc new file mode 100644 index 0000000000..b97bb9eb12 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCommandReq.cc @@ -0,0 +1,924 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCommandReq0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCommandReq0() { + size_t written; + EXPECT_TRUE(sbp_msg_command_req_command_set( + &test_msg_, "/path/to/command with args", false, &written)); + EXPECT_EQ(written, strlen("/path/to/command with args")); + EXPECT_EQ(sbp_msg_command_req_command_encoded_len(&test_msg_), 27); + assign(test_msg_.sequence, 1755532595); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_command_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_command_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCommandReq, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_command_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCommandReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->command_req, sizeof(msg->command_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_command_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.command_req, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCommandReq); + info.sender_id = 47274; + info.preamble = 0x55; + info.crc = 0x1826; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 31; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_command_req_t &lesser, + const sbp_msg_command_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_command_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_command_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_command_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_command_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgCommandReq, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgCommandReq, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgCommandReq, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgCommandReq, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_command_req_t test_msg_{}; + uint8_t encoded_frame_[31 + 8] = { + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, + 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, 24, + }; + uint8_t encoded_payload_[31] = { + 51, 77, 163, 104, 47, 112, 97, 116, 104, 47, 116, + 111, 47, 99, 111, 109, 109, 97, 110, 100, 32, 119, + 105, 116, 104, 32, 97, 114, 103, 115, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_command_req_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCommandReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_command_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCommandReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + EXPECT_EQ( + sbp_msg_command_req_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + for (uint8_t i = 0; i < 31; i++) { + EXPECT_EQ(sbp_msg_command_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_command_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCommandReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_command_req_t msg{}; + + EXPECT_EQ(sbp_msg_command_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_command_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_COMMAND_REQ_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_command_req_t t{}; return + // sbp_msg_command_req_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_command_req_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_command_req_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCommandReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_command_req_t lesser = info.test_msg; + sbp_msg_command_req_t greater = info.test_msg; + make_lesser_greater(lesser.command, greater.command); + comparison_tests(lesser, greater); + } + { + sbp_msg_command_req_t lesser = info.test_msg; + sbp_msg_command_req_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgCommandReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_COMMAND_REQ"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_command_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_command_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.command_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.command_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCommandReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCommandReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgCommandReq0_command + : public Testauto_check_sbp_piksi_MsgCommandReq0 {}; + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, StringInit) { + sbp_msg_command_req_t t{}; + sbp_msg_command_req_command_init(&t); + EXPECT_TRUE(sbp_msg_command_req_command_valid(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, IsValid) { + sbp_msg_command_req_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_command_req_command_set(&t, "/path/to/command with args", + false, &written)); + EXPECT_EQ(written, strlen("/path/to/command with args")); + EXPECT_EQ(sbp_msg_command_req_command_encoded_len(&t), 27); + EXPECT_TRUE(sbp_msg_command_req_command_valid(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, SpaceRemaining) { + sbp_msg_command_req_t t{}; + size_t empty_space_remaining = + sbp_msg_command_req_command_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_command_req_command_set(&t, "/path/to/command with args", + false, &written)); + EXPECT_EQ(written, strlen("/path/to/command with args")); + EXPECT_EQ(sbp_msg_command_req_command_encoded_len(&t), 27); + size_t assigned_space_remaining = + sbp_msg_command_req_command_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_command_req_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_command_req_command_set_raw( + &t, info.test_msg.command.data, + sbp_msg_command_req_command_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_command_req_command_encoded_len(&info.test_msg), + sbp_msg_command_req_command_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, Set) { + sbp_msg_command_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/command with args"; + + EXPECT_TRUE(sbp_msg_command_req_command_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, Printf) { + sbp_msg_command_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/command with args"; + + EXPECT_TRUE( + sbp_msg_command_req_command_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, Vprintf) { + sbp_msg_command_req_t t{}; + size_t nwritten{}; + const char *text = "/path/to/command with args"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_command_req_command_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), text); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, AppendPrintf) { + sbp_msg_command_req_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/command with args"; + char part2[] = "/path/to/command with args"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_command_req_command_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_command_req_command_append_printf(&t, false, &nwritten, + "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), + "/path/to/command with args"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandReq0_command, AppendVprintf) { + sbp_msg_command_req_t t{}; + size_t nwritten{}; + char part1[] = "/path/to/command with args"; + char part2[] = "/path/to/command with args"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_command_req_command_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_command_req_command_append_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_command_req_command_get(&t), + "/path/to/command with args"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCommandResp.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCommandResp.cc new file mode 100644 index 0000000000..d8c4ad7b14 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCommandResp.cc @@ -0,0 +1,777 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCommandResp0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCommandResp0() { + assign(test_msg_.code, 1737912018); + assign(test_msg_.sequence, 2692994934); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_command_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_command_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCommandResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_command_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCommandResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->command_resp, + sizeof(msg->command_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_command_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.command_resp, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCommandResp); + info.sender_id = 52793; + info.preamble = 0x55; + info.crc = 0xf0a4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 8; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_command_resp_t &lesser, + const sbp_msg_command_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_command_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_command_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_command_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_command_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgCommandResp, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgCommandResp, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgCommandResp, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgCommandResp, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_command_resp_t test_msg_{}; + uint8_t encoded_frame_[8 + 8] = { + 85, 185, 0, 57, 206, 8, 118, 215, 131, 160, 210, 110, 150, 103, 164, 240, + }; + uint8_t encoded_payload_[8] = { + 118, 215, 131, 160, 210, 110, 150, 103, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_command_resp_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCommandResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_command_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCommandResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + + EXPECT_EQ(sbp_msg_command_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_msg_command_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_command_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCommandResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_command_resp_t msg{}; + + EXPECT_EQ(sbp_msg_command_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_command_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_command_resp_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_command_resp_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCommandResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCommandResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_command_resp_t lesser = info.test_msg; + sbp_msg_command_resp_t greater = info.test_msg; + make_lesser_greater(lesser.code, greater.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_command_resp_t lesser = info.test_msg; + sbp_msg_command_resp_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCommandResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_COMMAND_RESP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_command_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_command_resp_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.command_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.command_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[8]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 8), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_command_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 8); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCommandResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCommandResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCommandResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCwResults.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCwResults.cc new file mode 100644 index 0000000000..36b6bf5590 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCwResults.cc @@ -0,0 +1,730 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCwResults0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCwResults0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_cw_results_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_cw_results_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCwResults, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_cw_results_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCwResults); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->cw_results, sizeof(msg->cw_results)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_cw_results_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.cw_results, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCwResults); + info.sender_id = 63075; + info.preamble = 0x55; + info.crc = 0x48e4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_cw_results_t &lesser, + const sbp_msg_cw_results_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_cw_results_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_cw_results_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_cw_results_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_cw_results_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgCwResults, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgCwResults, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgCwResults, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgCwResults, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_cw_results_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 192, 0, 99, 246, 0, 228, 72, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_cw_results_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCwResults, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_cw_results_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCwResults, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_cw_results_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cw_results_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_cw_results_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCwResults, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_cw_results_t msg{}; + + EXPECT_EQ(sbp_msg_cw_results_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_cw_results_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCwResults, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCwResults, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCwResults, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgCwResults); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CW_RESULTS"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_cw_results_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_cw_results_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.cw_results, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.cw_results, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cw_results_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCwResults, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwResults0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCwResults, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgCwStart.cc b/c/test/cpp/auto_check_sbp_piksi_MsgCwStart.cc new file mode 100644 index 0000000000..4e535603ae --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgCwStart.cc @@ -0,0 +1,725 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgCwStart0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgCwStart0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_cw_start_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_cw_start_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCwStart, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_cw_start_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCwStart); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->cw_start, sizeof(msg->cw_start)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_cw_start_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.cw_start, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCwStart); + info.sender_id = 45854; + info.preamble = 0x55; + info.crc = 0x8ad5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_cw_start_t &lesser, + const sbp_msg_cw_start_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_cw_start_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_cw_start_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_cw_start_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_cw_start_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgCwStart, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgCwStart, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgCwStart, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgCwStart, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_cw_start_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 193, 0, 30, 179, 0, 213, 138, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_cw_start_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCwStart, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_cw_start_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgCwStart, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_cw_start_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cw_start_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_cw_start_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCwStart, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_cw_start_t msg{}; + + EXPECT_EQ(sbp_msg_cw_start_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_cw_start_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCwStart, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCwStart, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCwStart, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgCwStart); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_CW_START"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_cw_start_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_cw_start_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.cw_start, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.cw_start, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_cw_start_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCwStart, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgCwStart0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgCwStart, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgDeviceMonitor.cc b/c/test/cpp/auto_check_sbp_piksi_MsgDeviceMonitor.cc index 56233bcd57..3bd0a8105f 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgDeviceMonitor.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgDeviceMonitor.cc @@ -16,486 +16,3909 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgDeviceMonitor0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgDeviceMonitor0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgDeviceMonitor0() { + assign(test_msg_.cpu_temperature, 6165); + assign(test_msg_.cpu_vaux, 1789); + assign(test_msg_.cpu_vint, 987); + assign(test_msg_.dev_vin, -9999); + assign(test_msg_.fe_temperature, 4776); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_device_monitor_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDeviceMonitor, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDeviceMonitor); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->device_monitor, + sizeof(msg->device_monitor)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_device_monitor_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.device_monitor, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDeviceMonitor); + info.sender_id = 16991; + info.preamble = 0x55; + info.crc = 0xe9cf; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_device_monitor_t &lesser, + const sbp_msg_device_monitor_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_device_monitor_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_device_monitor_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_device_monitor_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_device_monitor_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_device_monitor_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 181, 0, 95, 66, 10, 241, 216, 219, + 3, 253, 6, 21, 24, 168, 18, 207, 233, + }; + uint8_t encoded_payload_[10] = { + 241, 216, 219, 3, 253, 6, 21, 24, 168, 18, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_device_monitor_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgDeviceMonitor, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDeviceMonitor, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_device_monitor_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDeviceMonitor, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_device_monitor_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_temperature, greater.cpu_temperature); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vaux, greater.cpu_vaux); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vint, greater.cpu_vint); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.dev_vin, greater.dev_vin); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.fe_temperature, greater.fe_temperature); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDeviceMonitor); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DEVICE_MONITOR"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_device_monitor_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_device_monitor_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.device_monitor, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.device_monitor, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDeviceMonitor, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDeviceMonitor, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgDeviceMonitor1 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgDeviceMonitor1() { + assign(test_msg_.cpu_temperature, 6168); + assign(test_msg_.cpu_vaux, 1790); + assign(test_msg_.cpu_vint, 987); + assign(test_msg_.dev_vin, -9999); + assign(test_msg_.fe_temperature, 4776); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_device_monitor_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDeviceMonitor, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDeviceMonitor); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->device_monitor, + sizeof(msg->device_monitor)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_device_monitor_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.device_monitor, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDeviceMonitor); + info.sender_id = 16991; + info.preamble = 0x55; + info.crc = 0x1ea9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_device_monitor_t &lesser, + const sbp_msg_device_monitor_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_device_monitor_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_device_monitor_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_device_monitor_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_device_monitor_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_device_monitor_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 181, 0, 95, 66, 10, 241, 216, 219, + 3, 254, 6, 24, 24, 168, 18, 169, 30, + }; + uint8_t encoded_payload_[10] = { + 241, 216, 219, 3, 254, 6, 24, 24, 168, 18, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_device_monitor_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgDeviceMonitor, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDeviceMonitor, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_device_monitor_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDeviceMonitor, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_device_monitor_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_temperature, greater.cpu_temperature); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vaux, greater.cpu_vaux); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vint, greater.cpu_vint); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.dev_vin, greater.dev_vin); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.fe_temperature, greater.fe_temperature); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDeviceMonitor); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DEVICE_MONITOR"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_device_monitor_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_device_monitor_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.device_monitor, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.device_monitor, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDeviceMonitor, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDeviceMonitor, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgDeviceMonitor2 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgDeviceMonitor2() { + assign(test_msg_.cpu_temperature, 6166); + assign(test_msg_.cpu_vaux, 1789); + assign(test_msg_.cpu_vint, 987); + assign(test_msg_.dev_vin, -9999); + assign(test_msg_.fe_temperature, 4776); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_device_monitor_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDeviceMonitor, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDeviceMonitor); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->device_monitor, + sizeof(msg->device_monitor)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_device_monitor_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.device_monitor, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDeviceMonitor); + info.sender_id = 16991; + info.preamble = 0x55; + info.crc = 0x7213; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_device_monitor_t &lesser, + const sbp_msg_device_monitor_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_device_monitor_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_device_monitor_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_device_monitor_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_device_monitor_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_device_monitor_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 181, 0, 95, 66, 10, 241, 216, 219, + 3, 253, 6, 22, 24, 168, 18, 19, 114, + }; + uint8_t encoded_payload_[10] = { + 241, 216, 219, 3, 253, 6, 22, 24, 168, 18, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_device_monitor_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgDeviceMonitor, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDeviceMonitor, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_device_monitor_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDeviceMonitor, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_device_monitor_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_temperature, greater.cpu_temperature); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vaux, greater.cpu_vaux); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vint, greater.cpu_vint); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.dev_vin, greater.dev_vin); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.fe_temperature, greater.fe_temperature); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDeviceMonitor); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DEVICE_MONITOR"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_device_monitor_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_device_monitor_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.device_monitor, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.device_monitor, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDeviceMonitor, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDeviceMonitor, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgDeviceMonitor3 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgDeviceMonitor0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgDeviceMonitor3() { + assign(test_msg_.cpu_temperature, 6150); + assign(test_msg_.cpu_vaux, 1788); + assign(test_msg_.cpu_vint, 986); + assign(test_msg_.dev_vin, -9999); + assign(test_msg_.fe_temperature, 4776); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_device_monitor_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDeviceMonitor, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDeviceMonitor); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->device_monitor, + sizeof(msg->device_monitor)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_device_monitor_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.device_monitor, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDeviceMonitor); + info.sender_id = 16991; + info.preamble = 0x55; + info.crc = 0x6bc7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_device_monitor_t &lesser, + const sbp_msg_device_monitor_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_device_monitor_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_device_monitor_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_device_monitor_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_device_monitor_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_device_monitor_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 181, 0, 95, 66, 10, 241, 216, 218, + 3, 252, 6, 6, 24, 168, 18, 199, 107, + }; + uint8_t encoded_payload_[10] = { + 241, 216, 218, 3, 252, 6, 6, 24, 168, 18, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_device_monitor_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgDeviceMonitor, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDeviceMonitor, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_device_monitor_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDeviceMonitor, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_device_monitor_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_device_monitor_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_device_monitor_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_piksi_MsgDeviceMonitor0, Test) { - uint8_t encoded_frame[] = { - 85, 181, 0, 95, 66, 10, 241, 216, 219, - 3, 253, 6, 21, 24, 168, 18, 207, 233, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_device_monitor_t test_msg{}; - test_msg.cpu_temperature = 6165; - test_msg.cpu_vaux = 1789; - test_msg.cpu_vint = 987; - test_msg.dev_vin = -9999; - test_msg.fe_temperature = 4776; - - EXPECT_EQ(send_message(16991, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 16991); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu_temperature, 6165) - << "incorrect value for last_msg_.cpu_temperature, expected 6165, is " - << last_msg_.cpu_temperature; - EXPECT_EQ(last_msg_.cpu_vaux, 1789) - << "incorrect value for last_msg_.cpu_vaux, expected 1789, is " - << last_msg_.cpu_vaux; - EXPECT_EQ(last_msg_.cpu_vint, 987) - << "incorrect value for last_msg_.cpu_vint, expected 987, is " - << last_msg_.cpu_vint; - EXPECT_EQ(last_msg_.dev_vin, -9999) - << "incorrect value for last_msg_.dev_vin, expected -9999, is " - << last_msg_.dev_vin; - EXPECT_EQ(last_msg_.fe_temperature, 4776) - << "incorrect value for last_msg_.fe_temperature, expected 4776, is " - << last_msg_.fe_temperature; -} -class Test_auto_check_sbp_piksi_MsgDeviceMonitor1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgDeviceMonitor1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_temperature, greater.cpu_temperature); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vaux, greater.cpu_vaux); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vint, greater.cpu_vint); + comparison_tests(lesser, greater); } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.dev_vin, greater.dev_vin); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.fe_temperature, greater.fe_temperature); + comparison_tests(lesser, greater); + } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_device_monitor_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_device_monitor_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDeviceMonitor); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DEVICE_MONITOR"); +} -TEST_F(Test_auto_check_sbp_piksi_MsgDeviceMonitor1, Test) { - uint8_t encoded_frame[] = { - 85, 181, 0, 95, 66, 10, 241, 216, 219, - 3, 254, 6, 24, 24, 168, 18, 169, 30, - }; +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_device_monitor_t test_msg{}; - test_msg.cpu_temperature = 6168; - test_msg.cpu_vaux = 1790; - test_msg.cpu_vint = 987; - test_msg.dev_vin = -9999; - test_msg.fe_temperature = 4776; - - EXPECT_EQ(send_message(16991, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 16991); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu_temperature, 6168) - << "incorrect value for last_msg_.cpu_temperature, expected 6168, is " - << last_msg_.cpu_temperature; - EXPECT_EQ(last_msg_.cpu_vaux, 1790) - << "incorrect value for last_msg_.cpu_vaux, expected 1790, is " - << last_msg_.cpu_vaux; - EXPECT_EQ(last_msg_.cpu_vint, 987) - << "incorrect value for last_msg_.cpu_vint, expected 987, is " - << last_msg_.cpu_vint; - EXPECT_EQ(last_msg_.dev_vin, -9999) - << "incorrect value for last_msg_.dev_vin, expected -9999, is " - << last_msg_.dev_vin; - EXPECT_EQ(last_msg_.fe_temperature, 4776) - << "incorrect value for last_msg_.fe_temperature, expected 4776, is " - << last_msg_.fe_temperature; -} -class Test_auto_check_sbp_piksi_MsgDeviceMonitor2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgDeviceMonitor2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_device_monitor_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_device_monitor_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.device_monitor, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.device_monitor, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_device_monitor_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_device_monitor_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_piksi_MsgDeviceMonitor2, Test) { - uint8_t encoded_frame[] = { - 85, 181, 0, 95, 66, 10, 241, 216, 219, - 3, 253, 6, 22, 24, 168, 18, 19, 114, - }; +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDeviceMonitor, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_device_monitor_t test_msg{}; - test_msg.cpu_temperature = 6166; - test_msg.cpu_vaux = 1789; - test_msg.cpu_vint = 987; - test_msg.dev_vin = -9999; - test_msg.fe_temperature = 4776; - - EXPECT_EQ(send_message(16991, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 16991); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu_temperature, 6166) - << "incorrect value for last_msg_.cpu_temperature, expected 6166, is " - << last_msg_.cpu_temperature; - EXPECT_EQ(last_msg_.cpu_vaux, 1789) - << "incorrect value for last_msg_.cpu_vaux, expected 1789, is " - << last_msg_.cpu_vaux; - EXPECT_EQ(last_msg_.cpu_vint, 987) - << "incorrect value for last_msg_.cpu_vint, expected 987, is " - << last_msg_.cpu_vint; - EXPECT_EQ(last_msg_.dev_vin, -9999) - << "incorrect value for last_msg_.dev_vin, expected -9999, is " - << last_msg_.dev_vin; - EXPECT_EQ(last_msg_.fe_temperature, 4776) - << "incorrect value for last_msg_.fe_temperature, expected 4776, is " - << last_msg_.fe_temperature; -} -class Test_auto_check_sbp_piksi_MsgDeviceMonitor3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDeviceMonitor, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgDeviceMonitor4 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgDeviceMonitor3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgDeviceMonitor4() { + assign(test_msg_.cpu_temperature, 6123); + assign(test_msg_.cpu_vaux, 1789); + assign(test_msg_.cpu_vint, 988); + assign(test_msg_.dev_vin, -9999); + assign(test_msg_.fe_temperature, 4776); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_device_monitor_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_device_monitor_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_piksi_MsgDeviceMonitor3, Test) { - uint8_t encoded_frame[] = { - 85, 181, 0, 95, 66, 10, 241, 216, 218, - 3, 252, 6, 6, 24, 168, 18, 199, 107, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_device_monitor_t test_msg{}; - test_msg.cpu_temperature = 6150; - test_msg.cpu_vaux = 1788; - test_msg.cpu_vint = 986; - test_msg.dev_vin = -9999; - test_msg.fe_temperature = 4776; - - EXPECT_EQ(send_message(16991, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 16991); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu_temperature, 6150) - << "incorrect value for last_msg_.cpu_temperature, expected 6150, is " - << last_msg_.cpu_temperature; - EXPECT_EQ(last_msg_.cpu_vaux, 1788) - << "incorrect value for last_msg_.cpu_vaux, expected 1788, is " - << last_msg_.cpu_vaux; - EXPECT_EQ(last_msg_.cpu_vint, 986) - << "incorrect value for last_msg_.cpu_vint, expected 986, is " - << last_msg_.cpu_vint; - EXPECT_EQ(last_msg_.dev_vin, -9999) - << "incorrect value for last_msg_.dev_vin, expected -9999, is " - << last_msg_.dev_vin; - EXPECT_EQ(last_msg_.fe_temperature, 4776) - << "incorrect value for last_msg_.fe_temperature, expected 4776, is " - << last_msg_.fe_temperature; -} -class Test_auto_check_sbp_piksi_MsgDeviceMonitor4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgDeviceMonitor4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_device_monitor_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDeviceMonitor, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_device_monitor_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDeviceMonitor); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->device_monitor, + sizeof(msg->device_monitor)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_device_monitor_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.device_monitor, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDeviceMonitor); + info.sender_id = 16991; + info.preamble = 0x55; + info.crc = 0x3ff1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_device_monitor_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_device_monitor_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_device_monitor_t &lesser, + const sbp_msg_device_monitor_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_device_monitor_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_device_monitor_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_device_monitor_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_device_monitor_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDeviceMonitor, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } -TEST_F(Test_auto_check_sbp_piksi_MsgDeviceMonitor4, Test) { - uint8_t encoded_frame[] = { + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_device_monitor_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { 85, 181, 0, 95, 66, 10, 241, 216, 220, 3, 253, 6, 235, 23, 168, 18, 241, 63, }; + uint8_t encoded_payload_[10] = { + 241, 216, 220, 3, 253, 6, 235, 23, 168, 18, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_device_monitor_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgDeviceMonitor, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDeviceMonitor, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_device_monitor_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_device_monitor_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDeviceMonitor, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_device_monitor_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - sbp_msg_device_monitor_t test_msg{}; - test_msg.cpu_temperature = 6123; - test_msg.cpu_vaux = 1789; - test_msg.cpu_vint = 988; - test_msg.dev_vin = -9999; - test_msg.fe_temperature = 4776; - - EXPECT_EQ(send_message(16991, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 16991); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu_temperature, 6123) - << "incorrect value for last_msg_.cpu_temperature, expected 6123, is " - << last_msg_.cpu_temperature; - EXPECT_EQ(last_msg_.cpu_vaux, 1789) - << "incorrect value for last_msg_.cpu_vaux, expected 1789, is " - << last_msg_.cpu_vaux; - EXPECT_EQ(last_msg_.cpu_vint, 988) - << "incorrect value for last_msg_.cpu_vint, expected 988, is " - << last_msg_.cpu_vint; - EXPECT_EQ(last_msg_.dev_vin, -9999) - << "incorrect value for last_msg_.dev_vin, expected -9999, is " - << last_msg_.dev_vin; - EXPECT_EQ(last_msg_.fe_temperature, 4776) - << "incorrect value for last_msg_.fe_temperature, expected 4776, is " - << last_msg_.fe_temperature; + EXPECT_EQ(sbp_msg_device_monitor_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); } + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDeviceMonitor, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_temperature, greater.cpu_temperature); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vaux, greater.cpu_vaux); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.cpu_vint, greater.cpu_vint); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.dev_vin, greater.dev_vin); + comparison_tests(lesser, greater); + } + { + sbp_msg_device_monitor_t lesser = info.test_msg; + sbp_msg_device_monitor_t greater = info.test_msg; + make_lesser_greater(lesser.fe_temperature, greater.fe_temperature); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDeviceMonitor); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DEVICE_MONITOR"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_device_monitor_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_device_monitor_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.device_monitor, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.device_monitor, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_device_monitor_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDeviceMonitor, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgDeviceMonitor4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDeviceMonitor, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc b/c/test/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc new file mode 100644 index 0000000000..23147f2ffe --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc @@ -0,0 +1,915 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgFrontEndGain0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgFrontEndGain0() { + assign(test_msg_.if_gain[0], -10); + + assign(test_msg_.if_gain[1], -23); + + assign(test_msg_.if_gain[2], -40); + + assign(test_msg_.if_gain[3], 80); + + assign(test_msg_.if_gain[4], -69); + + assign(test_msg_.if_gain[5], -43); + + assign(test_msg_.if_gain[6], 85); + + assign(test_msg_.if_gain[7], 2); + + assign(test_msg_.rf_gain[0], 41); + + assign(test_msg_.rf_gain[1], -123); + + assign(test_msg_.rf_gain[2], -122); + + assign(test_msg_.rf_gain[3], 10); + + assign(test_msg_.rf_gain[4], 105); + + assign(test_msg_.rf_gain[5], 20); + + assign(test_msg_.rf_gain[6], 38); + + assign(test_msg_.rf_gain[7], 38); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_front_end_gain_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_front_end_gain_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgFrontEndGain, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_front_end_gain_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgFrontEndGain); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->front_end_gain, + sizeof(msg->front_end_gain)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_front_end_gain_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.front_end_gain, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgFrontEndGain); + info.sender_id = 62895; + info.preamble = 0x55; + info.crc = 0x87eb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 16; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_front_end_gain_t &lesser, + const sbp_msg_front_end_gain_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_front_end_gain_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_front_end_gain_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_front_end_gain_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_front_end_gain_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgFrontEndGain, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgFrontEndGain, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgFrontEndGain, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgFrontEndGain, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_front_end_gain_t test_msg_{}; + uint8_t encoded_frame_[16 + 8] = { + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, + 38, 38, 246, 233, 216, 80, 187, 213, 85, 2, 235, 135, + }; + uint8_t encoded_payload_[16] = { + 41, 133, 134, 10, 105, 20, 38, 38, 246, 233, 216, 80, 187, 213, 85, 2, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_front_end_gain_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgFrontEndGain, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_front_end_gain_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgFrontEndGain, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + EXPECT_EQ(sbp_msg_front_end_gain_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ( + sbp_msg_front_end_gain_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_front_end_gain_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_front_end_gain_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgFrontEndGain, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_front_end_gain_t msg{}; + + EXPECT_EQ(sbp_msg_front_end_gain_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_front_end_gain_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_front_end_gain_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_front_end_gain_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFrontEndGain, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgFrontEndGain, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgFrontEndGain, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[0], greater.if_gain[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[1], greater.if_gain[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[2], greater.if_gain[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[3], greater.if_gain[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[4], greater.if_gain[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[5], greater.if_gain[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[6], greater.if_gain[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.if_gain[7], greater.if_gain[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[0], greater.rf_gain[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[1], greater.rf_gain[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[2], greater.rf_gain[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[3], greater.rf_gain[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[4], greater.rf_gain[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[5], greater.rf_gain[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[6], greater.rf_gain[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_front_end_gain_t lesser = info.test_msg; + sbp_msg_front_end_gain_t greater = info.test_msg; + make_lesser_greater(lesser.rf_gain[7], greater.rf_gain[7]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgFrontEndGain); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_FRONT_END_GAIN"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_front_end_gain_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_front_end_gain_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.front_end_gain, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.front_end_gain, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[16]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 16), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_front_end_gain_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 16); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgFrontEndGain, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgFrontEndGain0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgFrontEndGain, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgIarState.cc b/c/test/cpp/auto_check_sbp_piksi_MsgIarState.cc index ea30328dbb..d981d6bc16 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgIarState.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgIarState.cc @@ -16,559 +16,5138 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgIarState0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgIarState0 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgIarState0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgIarState0() { assign(test_msg_.num_hyps, 1); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8cd8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_piksi_MsgIarState0, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 246, 215, 4, 1, 0, 0, 0, 216, 140, - }; + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 1; + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); - while (dummy_rd_ < dummy_wr_) { - process(); + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 1) - << "incorrect value for last_msg_.num_hyps, expected 1, is " - << last_msg_.num_hyps; -} -class Test_auto_check_sbp_piksi_MsgIarState1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgIarState1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } -TEST_F(Test_auto_check_sbp_piksi_MsgIarState1, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 0, 0, 0, 0, 18, 176, + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 246, 215, 4, 1, 0, 0, 0, 216, 140, + }; + uint8_t encoded_payload_[4] = { + 1, + 0, + 0, + 0, }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 0; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 0) - << "incorrect value for last_msg_.num_hyps, expected 0, is " - << last_msg_.num_hyps; + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); } -class Test_auto_check_sbp_piksi_MsgIarState2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgIarState2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_piksi_MsgIarState2, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 1, 0, 0, 0, 166, 198, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 1; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CHandler handler{&state}; - while (dummy_rd_ < dummy_wr_) { - process(); + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 1) - << "incorrect value for last_msg_.num_hyps, expected 1, is " - << last_msg_.num_hyps; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } -class Test_auto_check_sbp_piksi_MsgIarState3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgIarState3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 0); +} -TEST_F(Test_auto_check_sbp_piksi_MsgIarState3, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 217, 2, 0, 0, 6, 133, - }; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 729; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - while (dummy_rd_ < dummy_wr_) { - process(); + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 729) - << "incorrect value for last_msg_.num_hyps, expected 729, is " - << last_msg_.num_hyps; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } -class Test_auto_check_sbp_piksi_MsgIarState4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgIarState4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} -TEST_F(Test_auto_check_sbp_piksi_MsgIarState4, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 216, 2, 0, 0, 178, 243, - }; +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 728; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - while (dummy_rd_ < dummy_wr_) { - process(); + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 728) - << "incorrect value for last_msg_.num_hyps, expected 728, is " - << last_msg_.num_hyps; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } -class Test_auto_check_sbp_piksi_MsgIarState5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + +class Testauto_check_sbp_piksi_MsgIarState1 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgIarState5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgIarState1() { assign(test_msg_.num_hyps, 0); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb012; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_piksi_MsgIarState5, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 215, 2, 0, 0, 92, 39, - }; + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 727; + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); - while (dummy_rd_ < dummy_wr_) { - process(); + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 727) - << "incorrect value for last_msg_.num_hyps, expected 727, is " - << last_msg_.num_hyps; -} -class Test_auto_check_sbp_piksi_MsgIarState6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgIarState6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_iar_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_iar_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } -TEST_F(Test_auto_check_sbp_piksi_MsgIarState6, Test) { - uint8_t encoded_frame[] = { - 85, 25, 0, 195, 4, 4, 211, 2, 0, 0, 173, 237, + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 0, 0, 0, 0, 18, 176, + }; + uint8_t encoded_payload_[4] = { + 0, + 0, + 0, + 0, }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} - sbp_msg_iar_state_t test_msg{}; - test_msg.num_hyps = 723; +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.num_hyps, 723) - << "incorrect value for last_msg_.num_hyps, expected 723, is " - << last_msg_.num_hyps; + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgIarState2 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgIarState2() { assign(test_msg_.num_hyps, 1); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xc6a6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 1, 0, 0, 0, 166, 198, + }; + uint8_t encoded_payload_[4] = { + 1, + 0, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgIarState3 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgIarState3() { assign(test_msg_.num_hyps, 729); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x8506; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 217, 2, 0, 0, 6, 133, + }; + uint8_t encoded_payload_[4] = { + 217, + 2, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgIarState4 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgIarState4() { assign(test_msg_.num_hyps, 728); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xf3b2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 216, 2, 0, 0, 178, 243, + }; + uint8_t encoded_payload_[4] = { + 216, + 2, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgIarState5 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgIarState5() { assign(test_msg_.num_hyps, 727); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x275c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 215, 2, 0, 0, 92, 39, + }; + uint8_t encoded_payload_[4] = { + 215, + 2, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgIarState6 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgIarState6() { assign(test_msg_.num_hyps, 723); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_iar_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgIarState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_iar_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgIarState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->iar_state, sizeof(msg->iar_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_iar_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.iar_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgIarState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xedad; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_iar_state_t &lesser, + const sbp_msg_iar_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_iar_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_iar_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_iar_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_iar_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgIarState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgIarState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_iar_state_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 25, 0, 195, 4, 4, 211, 2, 0, 0, 173, 237, + }; + uint8_t encoded_payload_[4] = { + 211, + 2, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_iar_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgIarState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgIarState, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_iar_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_iar_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgIarState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + EXPECT_EQ(sbp_msg_iar_state_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_iar_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_iar_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgIarState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_iar_state_t lesser = info.test_msg; + sbp_msg_iar_state_t greater = info.test_msg; + make_lesser_greater(lesser.num_hyps, greater.num_hyps); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgIarState); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_IAR_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_iar_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_iar_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.iar_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.iar_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_iar_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgIarState, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgIarState6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgIarState, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc b/c/test/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc new file mode 100644 index 0000000000..2380c1af31 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc @@ -0,0 +1,737 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgInitBaseDep0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgInitBaseDep0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_init_base_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_init_base_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgInitBaseDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_init_base_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgInitBaseDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->init_base_dep, + sizeof(msg->init_base_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_init_base_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.init_base_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgInitBaseDep); + info.sender_id = 10680; + info.preamble = 0x55; + info.crc = 0x0d46; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_init_base_dep_t &lesser, + const sbp_msg_init_base_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_init_base_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_init_base_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_init_base_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_init_base_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgInitBaseDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgInitBaseDep, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgInitBaseDep, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgInitBaseDep, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_init_base_dep_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 35, 0, 184, 41, 0, 70, 13, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_init_base_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgInitBaseDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_init_base_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgInitBaseDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_init_base_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_init_base_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_init_base_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgInitBaseDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_init_base_dep_t msg{}; + + EXPECT_EQ(sbp_msg_init_base_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_init_base_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgInitBaseDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgInitBaseDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgInitBaseDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgInitBaseDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_INIT_BASE_DEP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_init_base_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_init_base_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.init_base_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.init_base_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_init_base_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgInitBaseDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgInitBaseDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgInitBaseDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc b/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc new file mode 100644 index 0000000000..7d2c1246db --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc @@ -0,0 +1,795 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgMaskSatellite0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgMaskSatellite0() { + assign(test_msg_.mask, 183); + assign(test_msg_.sid.code, 57); + assign(test_msg_.sid.sat, 87); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_mask_satellite_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_mask_satellite_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgMaskSatellite, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_mask_satellite_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgMaskSatellite); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->mask_satellite, + sizeof(msg->mask_satellite)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_mask_satellite_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.mask_satellite, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgMaskSatellite); + info.sender_id = 38829; + info.preamble = 0x55; + info.crc = 0x9313; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 3; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_mask_satellite_t &lesser, + const sbp_msg_mask_satellite_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_mask_satellite_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_mask_satellite_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_mask_satellite_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_mask_satellite_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgMaskSatellite, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgMaskSatellite, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgMaskSatellite, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgMaskSatellite, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_mask_satellite_t test_msg_{}; + uint8_t encoded_frame_[3 + 8] = { + 85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147, + }; + uint8_t encoded_payload_[3] = { + 183, + 87, + 57, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_mask_satellite_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgMaskSatellite, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[3]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_mask_satellite_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 3), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgMaskSatellite, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 3), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[3]; + + EXPECT_EQ(sbp_msg_mask_satellite_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 3), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[3]; + + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ( + sbp_msg_mask_satellite_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_mask_satellite_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 3); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgMaskSatellite, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 3); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_t msg{}; + + EXPECT_EQ(sbp_msg_mask_satellite_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_mask_satellite_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_mask_satellite_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMaskSatellite, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgMaskSatellite, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMaskSatellite, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_mask_satellite_t lesser = info.test_msg; + sbp_msg_mask_satellite_t greater = info.test_msg; + make_lesser_greater(lesser.mask, greater.mask); + comparison_tests(lesser, greater); + } + { + sbp_msg_mask_satellite_t lesser = info.test_msg; + sbp_msg_mask_satellite_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_mask_satellite_t lesser = info.test_msg; + sbp_msg_mask_satellite_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgMaskSatellite); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_MASK_SATELLITE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_mask_satellite_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_mask_satellite_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.mask_satellite, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.mask_satellite, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[3]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 3), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 3); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgMaskSatellite, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatellite0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgMaskSatellite, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc b/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc new file mode 100644 index 0000000000..2865bc3dd4 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc @@ -0,0 +1,804 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgMaskSatelliteDep0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgMaskSatelliteDep0() { + assign(test_msg_.mask, 33); + assign(test_msg_.sid.code, 95); + assign(test_msg_.sid.reserved, 4); + assign(test_msg_.sid.sat, 39170); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_mask_satellite_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_mask_satellite_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgMaskSatelliteDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_mask_satellite_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgMaskSatelliteDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->mask_satellite_dep, + sizeof(msg->mask_satellite_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_mask_satellite_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.mask_satellite_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgMaskSatelliteDep); + info.sender_id = 34491; + info.preamble = 0x55; + info.crc = 0xbc1d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 5; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_mask_satellite_dep_t &lesser, + const sbp_msg_mask_satellite_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_mask_satellite_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_mask_satellite_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_mask_satellite_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_mask_satellite_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgMaskSatelliteDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgMaskSatelliteDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgMaskSatelliteDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgMaskSatelliteDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_mask_satellite_dep_t test_msg_{}; + uint8_t encoded_frame_[5 + 8] = { + 85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188, + }; + uint8_t encoded_payload_[5] = { + 33, 2, 153, 95, 4, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_mask_satellite_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgMaskSatelliteDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_mask_satellite_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgMaskSatelliteDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + EXPECT_EQ(sbp_msg_mask_satellite_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ( + sbp_msg_mask_satellite_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_mask_satellite_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgMaskSatelliteDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_dep_t msg{}; + + EXPECT_EQ(sbp_msg_mask_satellite_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_mask_satellite_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_mask_satellite_dep_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMaskSatelliteDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgMaskSatelliteDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMaskSatelliteDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_mask_satellite_dep_t lesser = info.test_msg; + sbp_msg_mask_satellite_dep_t greater = info.test_msg; + make_lesser_greater(lesser.mask, greater.mask); + comparison_tests(lesser, greater); + } + { + sbp_msg_mask_satellite_dep_t lesser = info.test_msg; + sbp_msg_mask_satellite_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_mask_satellite_dep_t lesser = info.test_msg; + sbp_msg_mask_satellite_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_mask_satellite_dep_t lesser = info.test_msg; + sbp_msg_mask_satellite_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgMaskSatelliteDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_MASK_SATELLITE_DEP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_mask_satellite_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_mask_satellite_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.mask_satellite_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.mask_satellite_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[5]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 5), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_mask_satellite_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 5); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgMaskSatelliteDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgMaskSatelliteDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgMaskSatelliteDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgNetworkBandwidthUsage.cc b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkBandwidthUsage.cc index 3a2fe789ef..0e8b8b4e68 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgNetworkBandwidthUsage.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkBandwidthUsage.cc @@ -16,66 +16,434 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgNetworkBandwidthUsage0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0 + : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgNetworkBandwidthUsage0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0() { + assign(test_msg_.interfaces[0].duration, 2159176030); + { + const char assign_string[] = {(char)99, (char)97, (char)110, (char)48, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interfaces[0].interface_name, assign_string, + sizeof(assign_string)); + } + assign(test_msg_.interfaces[0].rx_bytes, 0); + assign(test_msg_.interfaces[0].total_bytes, 0); + assign(test_msg_.interfaces[0].tx_bytes, 0); + + assign(test_msg_.interfaces[1].duration, 2159176030); + { + const char assign_string[] = {(char)99, (char)97, (char)110, (char)49, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interfaces[1].interface_name, assign_string, + sizeof(assign_string)); + } + assign(test_msg_.interfaces[1].rx_bytes, 0); + assign(test_msg_.interfaces[1].total_bytes, 0); + assign(test_msg_.interfaces[1].tx_bytes, 0); + + assign(test_msg_.interfaces[2].duration, 2159176030); + { + const char assign_string[] = {(char)101, (char)116, (char)104, (char)48, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interfaces[2].interface_name, assign_string, + sizeof(assign_string)); + } + assign(test_msg_.interfaces[2].rx_bytes, 4036234989); + assign(test_msg_.interfaces[2].total_bytes, 3411995557); + assign(test_msg_.interfaces[2].tx_bytes, 3670727864); + + assign(test_msg_.interfaces[3].duration, 2159176030); + { + const char assign_string[] = {(char)108, (char)111, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interfaces[3].interface_name, assign_string, + sizeof(assign_string)); + } + assign(test_msg_.interfaces[3].rx_bytes, 0); + assign(test_msg_.interfaces[3].total_bytes, 0); + assign(test_msg_.interfaces[3].tx_bytes, 0); + + assign(test_msg_.interfaces[4].duration, 2159176030); + { + const char assign_string[] = {(char)115, (char)105, (char)116, (char)48, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interfaces[4].interface_name, assign_string, + sizeof(assign_string)); + } + assign(test_msg_.interfaces[4].rx_bytes, 0); + assign(test_msg_.interfaces[4].total_bytes, 0); + assign(test_msg_.interfaces[4].tx_bytes, 0); + assign(test_msg_.n_interfaces, 5); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_network_bandwidth_usage_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_network_bandwidth_usage_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_network_bandwidth_usage_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNetworkBandwidthUsage, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_network_bandwidth_usage_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNetworkBandwidthUsage); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->network_bandwidth_usage, + sizeof(msg->network_bandwidth_usage)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_network_bandwidth_usage_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.network_bandwidth_usage, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNetworkBandwidthUsage); + info.sender_id = 31183; + info.preamble = 0x55; + info.crc = 0x851B; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 200; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_network_bandwidth_usage_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_network_bandwidth_usage_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_network_bandwidth_usage_t &lesser, + const sbp_msg_network_bandwidth_usage_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_network_bandwidth_usage_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_network_bandwidth_usage_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_network_bandwidth_usage_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkBandwidthUsage, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkBandwidthUsage, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgNetworkBandwidthUsage, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgNetworkBandwidthUsage, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_piksi_MsgNetworkBandwidthUsage0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_network_bandwidth_usage_t test_msg_{}; + uint8_t encoded_frame_[200 + 8] = { 85, 189, 0, 207, 121, 200, 94, 105, 178, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 97, 110, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -91,225 +459,630 @@ TEST_F(Test_auto_check_sbp_piksi_MsgNetworkBandwidthUsage0, Test) { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 115, 105, 116, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 133, }; + uint8_t encoded_payload_[200] = { + 94, 105, 178, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 99, 97, 110, 48, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 94, 105, 178, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 99, 97, 110, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 94, 105, 178, 128, 0, 0, 0, 0, 165, 235, 94, 203, 0, 0, 0, 0, + 237, 14, 148, 240, 184, 220, 202, 218, 101, 116, 104, 48, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 94, 105, 178, 128, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 108, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 94, 105, 178, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 115, 105, 116, 48, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_network_bandwidth_usage_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgNetworkBandwidthUsage, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[200]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 200); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 200), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgNetworkBandwidthUsage, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 200); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 200), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[200]; + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 200), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[200]; + + for (uint8_t i = 0; i < 200; i++) { + EXPECT_EQ(sbp_msg_network_bandwidth_usage_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_bandwidth_usage_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 200); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgNetworkBandwidthUsage, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 200); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_network_bandwidth_usage_t msg{}; + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_network_bandwidth_usage_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_network_bandwidth_usage_t t{}; + return sbp_msg_network_bandwidth_usage_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_network_bandwidth_usage_t t{}; + t.n_interfaces = 1; + return sbp_msg_network_bandwidth_usage_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_network_bandwidth_usage_t test_msg{}; + CHandler handler{&state}; - test_msg.interfaces[0].duration = 2159176030; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_network_bandwidth_usage_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgNetworkBandwidthUsage, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgNetworkBandwidthUsage, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgNetworkBandwidthUsage, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[0].duration, + greater.interfaces[0].duration); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[0].interface_name, + greater.interfaces[0].interface_name); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[0].rx_bytes, + greater.interfaces[0].rx_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[0].total_bytes, + greater.interfaces[0].total_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[0].tx_bytes, + greater.interfaces[0].tx_bytes); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[1].duration, + greater.interfaces[1].duration); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[1].interface_name, + greater.interfaces[1].interface_name); + comparison_tests(lesser, greater); + } { - const char assign_string[] = {(char)99, (char)97, (char)110, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.interfaces[0].interface_name, assign_string, - sizeof(assign_string)); - } - test_msg.interfaces[0].rx_bytes = 0; - test_msg.interfaces[0].total_bytes = 0; - test_msg.interfaces[0].tx_bytes = 0; - - test_msg.interfaces[1].duration = 2159176030; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[1].rx_bytes, + greater.interfaces[1].rx_bytes); + comparison_tests(lesser, greater); + } { - const char assign_string[] = {(char)99, (char)97, (char)110, (char)49, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.interfaces[1].interface_name, assign_string, - sizeof(assign_string)); - } - test_msg.interfaces[1].rx_bytes = 0; - test_msg.interfaces[1].total_bytes = 0; - test_msg.interfaces[1].tx_bytes = 0; - - test_msg.interfaces[2].duration = 2159176030; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[1].total_bytes, + greater.interfaces[1].total_bytes); + comparison_tests(lesser, greater); + } { - const char assign_string[] = {(char)101, (char)116, (char)104, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.interfaces[2].interface_name, assign_string, - sizeof(assign_string)); - } - test_msg.interfaces[2].rx_bytes = 4036234989; - test_msg.interfaces[2].total_bytes = 3411995557; - test_msg.interfaces[2].tx_bytes = 3670727864; - - test_msg.interfaces[3].duration = 2159176030; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[1].tx_bytes, + greater.interfaces[1].tx_bytes); + comparison_tests(lesser, greater); + } + { - const char assign_string[] = {(char)108, (char)111, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.interfaces[3].interface_name, assign_string, - sizeof(assign_string)); - } - test_msg.interfaces[3].rx_bytes = 0; - test_msg.interfaces[3].total_bytes = 0; - test_msg.interfaces[3].tx_bytes = 0; - - test_msg.interfaces[4].duration = 2159176030; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[2].duration, + greater.interfaces[2].duration); + comparison_tests(lesser, greater); + } { - const char assign_string[] = {(char)115, (char)105, (char)116, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.interfaces[4].interface_name, assign_string, - sizeof(assign_string)); - } - test_msg.interfaces[4].rx_bytes = 0; - test_msg.interfaces[4].total_bytes = 0; - test_msg.interfaces[4].tx_bytes = 0; - test_msg.n_interfaces = 5; - - EXPECT_EQ(send_message(31183, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 31183); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.interfaces[0].duration, 2159176030) - << "incorrect value for last_msg_.interfaces[0].duration, expected " - "2159176030, is " - << last_msg_.interfaces[0].duration; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[2].interface_name, + greater.interfaces[2].interface_name); + comparison_tests(lesser, greater); + } { - const char check_string[] = {(char)99, (char)97, (char)110, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.interfaces[0].interface_name, check_string, - sizeof(check_string)), - 0) - << "incorrect value for last_msg_.interfaces[0].interface_name, " - "expected string '" - << check_string << "', is '" << last_msg_.interfaces[0].interface_name - << "'"; - } - EXPECT_EQ(last_msg_.interfaces[0].rx_bytes, 0) - << "incorrect value for last_msg_.interfaces[0].rx_bytes, expected 0, is " - << last_msg_.interfaces[0].rx_bytes; - EXPECT_EQ(last_msg_.interfaces[0].total_bytes, 0) - << "incorrect value for last_msg_.interfaces[0].total_bytes, expected 0, " - "is " - << last_msg_.interfaces[0].total_bytes; - EXPECT_EQ(last_msg_.interfaces[0].tx_bytes, 0) - << "incorrect value for last_msg_.interfaces[0].tx_bytes, expected 0, is " - << last_msg_.interfaces[0].tx_bytes; - EXPECT_EQ(last_msg_.interfaces[1].duration, 2159176030) - << "incorrect value for last_msg_.interfaces[1].duration, expected " - "2159176030, is " - << last_msg_.interfaces[1].duration; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[2].rx_bytes, + greater.interfaces[2].rx_bytes); + comparison_tests(lesser, greater); + } { - const char check_string[] = {(char)99, (char)97, (char)110, (char)49, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.interfaces[1].interface_name, check_string, - sizeof(check_string)), - 0) - << "incorrect value for last_msg_.interfaces[1].interface_name, " - "expected string '" - << check_string << "', is '" << last_msg_.interfaces[1].interface_name - << "'"; - } - EXPECT_EQ(last_msg_.interfaces[1].rx_bytes, 0) - << "incorrect value for last_msg_.interfaces[1].rx_bytes, expected 0, is " - << last_msg_.interfaces[1].rx_bytes; - EXPECT_EQ(last_msg_.interfaces[1].total_bytes, 0) - << "incorrect value for last_msg_.interfaces[1].total_bytes, expected 0, " - "is " - << last_msg_.interfaces[1].total_bytes; - EXPECT_EQ(last_msg_.interfaces[1].tx_bytes, 0) - << "incorrect value for last_msg_.interfaces[1].tx_bytes, expected 0, is " - << last_msg_.interfaces[1].tx_bytes; - EXPECT_EQ(last_msg_.interfaces[2].duration, 2159176030) - << "incorrect value for last_msg_.interfaces[2].duration, expected " - "2159176030, is " - << last_msg_.interfaces[2].duration; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[2].total_bytes, + greater.interfaces[2].total_bytes); + comparison_tests(lesser, greater); + } { - const char check_string[] = {(char)101, (char)116, (char)104, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.interfaces[2].interface_name, check_string, - sizeof(check_string)), - 0) - << "incorrect value for last_msg_.interfaces[2].interface_name, " - "expected string '" - << check_string << "', is '" << last_msg_.interfaces[2].interface_name - << "'"; - } - EXPECT_EQ(last_msg_.interfaces[2].rx_bytes, 4036234989) - << "incorrect value for last_msg_.interfaces[2].rx_bytes, expected " - "4036234989, is " - << last_msg_.interfaces[2].rx_bytes; - EXPECT_EQ(last_msg_.interfaces[2].total_bytes, 3411995557) - << "incorrect value for last_msg_.interfaces[2].total_bytes, expected " - "3411995557, is " - << last_msg_.interfaces[2].total_bytes; - EXPECT_EQ(last_msg_.interfaces[2].tx_bytes, 3670727864) - << "incorrect value for last_msg_.interfaces[2].tx_bytes, expected " - "3670727864, is " - << last_msg_.interfaces[2].tx_bytes; - EXPECT_EQ(last_msg_.interfaces[3].duration, 2159176030) - << "incorrect value for last_msg_.interfaces[3].duration, expected " - "2159176030, is " - << last_msg_.interfaces[3].duration; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[2].tx_bytes, + greater.interfaces[2].tx_bytes); + comparison_tests(lesser, greater); + } + { - const char check_string[] = {(char)108, (char)111, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.interfaces[3].interface_name, check_string, - sizeof(check_string)), - 0) - << "incorrect value for last_msg_.interfaces[3].interface_name, " - "expected string '" - << check_string << "', is '" << last_msg_.interfaces[3].interface_name - << "'"; - } - EXPECT_EQ(last_msg_.interfaces[3].rx_bytes, 0) - << "incorrect value for last_msg_.interfaces[3].rx_bytes, expected 0, is " - << last_msg_.interfaces[3].rx_bytes; - EXPECT_EQ(last_msg_.interfaces[3].total_bytes, 0) - << "incorrect value for last_msg_.interfaces[3].total_bytes, expected 0, " - "is " - << last_msg_.interfaces[3].total_bytes; - EXPECT_EQ(last_msg_.interfaces[3].tx_bytes, 0) - << "incorrect value for last_msg_.interfaces[3].tx_bytes, expected 0, is " - << last_msg_.interfaces[3].tx_bytes; - EXPECT_EQ(last_msg_.interfaces[4].duration, 2159176030) - << "incorrect value for last_msg_.interfaces[4].duration, expected " - "2159176030, is " - << last_msg_.interfaces[4].duration; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[3].duration, + greater.interfaces[3].duration); + comparison_tests(lesser, greater); + } { - const char check_string[] = {(char)115, (char)105, (char)116, (char)48, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.interfaces[4].interface_name, check_string, - sizeof(check_string)), - 0) - << "incorrect value for last_msg_.interfaces[4].interface_name, " - "expected string '" - << check_string << "', is '" << last_msg_.interfaces[4].interface_name - << "'"; - } - EXPECT_EQ(last_msg_.interfaces[4].rx_bytes, 0) - << "incorrect value for last_msg_.interfaces[4].rx_bytes, expected 0, is " - << last_msg_.interfaces[4].rx_bytes; - EXPECT_EQ(last_msg_.interfaces[4].total_bytes, 0) - << "incorrect value for last_msg_.interfaces[4].total_bytes, expected 0, " - "is " - << last_msg_.interfaces[4].total_bytes; - EXPECT_EQ(last_msg_.interfaces[4].tx_bytes, 0) - << "incorrect value for last_msg_.interfaces[4].tx_bytes, expected 0, is " - << last_msg_.interfaces[4].tx_bytes; - EXPECT_EQ(last_msg_.n_interfaces, 5) - << "incorrect value for last_msg_.n_interfaces, expected 5, is " - << last_msg_.n_interfaces; + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[3].interface_name, + greater.interfaces[3].interface_name); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[3].rx_bytes, + greater.interfaces[3].rx_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[3].total_bytes, + greater.interfaces[3].total_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[3].tx_bytes, + greater.interfaces[3].tx_bytes); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[4].duration, + greater.interfaces[4].duration); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[4].interface_name, + greater.interfaces[4].interface_name); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[4].rx_bytes, + greater.interfaces[4].rx_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[4].total_bytes, + greater.interfaces[4].total_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.interfaces[4].tx_bytes, + greater.interfaces[4].tx_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_bandwidth_usage_t lesser = info.test_msg; + sbp_msg_network_bandwidth_usage_t greater = info.test_msg; + make_lesser_greater(lesser.n_interfaces, greater.n_interfaces); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgNetworkBandwidthUsage); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_NETWORK_BANDWIDTH_USAGE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_network_bandwidth_usage_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_network_bandwidth_usage_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.network_bandwidth_usage, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.network_bandwidth_usage, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); } + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[200]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 200); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 200), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_bandwidth_usage_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 200); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNetworkBandwidthUsage, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkBandwidthUsage0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgNetworkBandwidthUsage, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc new file mode 100644 index 0000000000..6db98e6223 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc @@ -0,0 +1,746 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgNetworkStateReq0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgNetworkStateReq0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_network_state_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_network_state_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNetworkStateReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_network_state_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNetworkStateReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->network_state_req, + sizeof(msg->network_state_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_network_state_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.network_state_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNetworkStateReq); + info.sender_id = 15955; + info.preamble = 0x55; + info.crc = 0x4994; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_network_state_req_t &lesser, + const sbp_msg_network_state_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_network_state_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_network_state_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_network_state_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_network_state_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkStateReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkStateReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgNetworkStateReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgNetworkStateReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_network_state_req_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 186, 0, 83, 62, 0, 148, 73, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_network_state_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgNetworkStateReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_network_state_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgNetworkStateReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_network_state_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_state_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_network_state_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgNetworkStateReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_network_state_req_t msg{}; + + EXPECT_EQ(sbp_msg_network_state_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_network_state_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNetworkStateReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgNetworkStateReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNetworkStateReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgNetworkStateReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_NETWORK_STATE_REQ"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_network_state_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_network_state_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.network_state_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.network_state_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_state_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNetworkStateReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgNetworkStateReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc new file mode 100644 index 0000000000..7fa500166c --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc @@ -0,0 +1,1010 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgNetworkStateResp0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgNetworkStateResp0() { + assign(test_msg_.flags, 2471552451); + { + const char assign_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.interface_name, assign_string, sizeof(assign_string)); + } + + assign(test_msg_.ipv4_address[0], 143); + + assign(test_msg_.ipv4_address[1], 241); + + assign(test_msg_.ipv4_address[2], 84); + + assign(test_msg_.ipv4_address[3], 180); + assign(test_msg_.ipv4_mask_size, 152); + + assign(test_msg_.ipv6_address[0], 194); + + assign(test_msg_.ipv6_address[1], 137); + + assign(test_msg_.ipv6_address[2], 32); + + assign(test_msg_.ipv6_address[3], 44); + + assign(test_msg_.ipv6_address[4], 114); + + assign(test_msg_.ipv6_address[5], 147); + + assign(test_msg_.ipv6_address[6], 68); + + assign(test_msg_.ipv6_address[7], 222); + + assign(test_msg_.ipv6_address[8], 92); + + assign(test_msg_.ipv6_address[9], 192); + + assign(test_msg_.ipv6_address[10], 78); + + assign(test_msg_.ipv6_address[11], 235); + + assign(test_msg_.ipv6_address[12], 63); + + assign(test_msg_.ipv6_address[13], 208); + + assign(test_msg_.ipv6_address[14], 114); + + assign(test_msg_.ipv6_address[15], 53); + assign(test_msg_.ipv6_mask_size, 183); + assign(test_msg_.rx_bytes, 451408920); + assign(test_msg_.tx_bytes, 59251049); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_network_state_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_network_state_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgNetworkStateResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_network_state_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgNetworkStateResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->network_state_resp, + sizeof(msg->network_state_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_network_state_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.network_state_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgNetworkStateResp); + info.sender_id = 3880; + info.preamble = 0x55; + info.crc = 0xc176; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 50; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_network_state_resp_t &lesser, + const sbp_msg_network_state_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_network_state_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_network_state_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_network_state_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_network_state_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkStateResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgNetworkStateResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgNetworkStateResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgNetworkStateResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_network_state_resp_t test_msg_{}; + uint8_t encoded_frame_[50 + 8] = { + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, 137, 32, 44, + 114, 147, 68, 222, 92, 192, 78, 235, 63, 208, 114, 53, 183, 24, 244, + 231, 26, 105, 25, 136, 3, 105, 102, 48, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + }; + uint8_t encoded_payload_[50] = { + 143, 241, 84, 180, 152, 194, 137, 32, 44, 114, 147, 68, 222, + 92, 192, 78, 235, 63, 208, 114, 53, 183, 24, 244, 231, 26, + 105, 25, 136, 3, 105, 102, 48, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 195, 229, 80, 147, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_network_state_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgNetworkStateResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_network_state_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgNetworkStateResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + + EXPECT_EQ(sbp_msg_network_state_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + + for (uint8_t i = 0; i < 50; i++) { + EXPECT_EQ( + sbp_msg_network_state_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_state_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_network_state_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgNetworkStateResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_network_state_resp_t msg{}; + + EXPECT_EQ(sbp_msg_network_state_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_network_state_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_network_state_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_network_state_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNetworkStateResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgNetworkStateResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgNetworkStateResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.interface_name, greater.interface_name); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv4_address[0], greater.ipv4_address[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv4_address[1], greater.ipv4_address[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv4_address[2], greater.ipv4_address[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv4_address[3], greater.ipv4_address[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv4_mask_size, greater.ipv4_mask_size); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[0], greater.ipv6_address[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[1], greater.ipv6_address[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[2], greater.ipv6_address[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[3], greater.ipv6_address[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[4], greater.ipv6_address[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[5], greater.ipv6_address[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[6], greater.ipv6_address[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[7], greater.ipv6_address[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[8], greater.ipv6_address[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[9], greater.ipv6_address[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[10], greater.ipv6_address[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[11], greater.ipv6_address[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[12], greater.ipv6_address[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[13], greater.ipv6_address[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[14], greater.ipv6_address[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_address[15], greater.ipv6_address[15]); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.ipv6_mask_size, greater.ipv6_mask_size); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.rx_bytes, greater.rx_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_network_state_resp_t lesser = info.test_msg; + sbp_msg_network_state_resp_t greater = info.test_msg; + make_lesser_greater(lesser.tx_bytes, greater.tx_bytes); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgNetworkStateResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_NETWORK_STATE_RESP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_network_state_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_network_state_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.network_state_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.network_state_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_network_state_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgNetworkStateResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgNetworkStateResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgNetworkStateResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgReset.cc b/c/test/cpp/auto_check_sbp_piksi_MsgReset.cc new file mode 100644 index 0000000000..a400b9c358 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgReset.cc @@ -0,0 +1,758 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgReset0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgReset0() { assign(test_msg_.flags, 334428248); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_reset_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgReset, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgReset); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->reset, sizeof(msg->reset)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_reset_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.reset, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgReset); + info.sender_id = 53823; + info.preamble = 0x55; + info.crc = 0xcf4a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_reset_t &lesser, + const sbp_msg_reset_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_reset_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_reset_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_reset_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_reset_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgReset, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgReset, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgReset, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgReset, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_reset_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { + 85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207, + }; + uint8_t encoded_payload_[4] = { + 88, + 248, + 238, + 19, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_reset_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgReset, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_reset_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgReset, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ(sbp_msg_reset_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgReset0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_reset_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_reset_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgReset, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_reset_t msg{}; + + EXPECT_EQ(sbp_msg_reset_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgReset0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_reset_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_reset_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_reset_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgReset, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgReset, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgReset, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_reset_t lesser = info.test_msg; + sbp_msg_reset_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgReset); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_RESET"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_reset_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_reset_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.reset, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.reset, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgReset, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgReset0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgReset, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgResetDep.cc b/c/test/cpp/auto_check_sbp_piksi_MsgResetDep.cc new file mode 100644 index 0000000000..cad52869f4 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgResetDep.cc @@ -0,0 +1,725 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgResetDep0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgResetDep0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_reset_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgResetDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgResetDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->reset_dep, sizeof(msg->reset_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_reset_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.reset_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgResetDep); + info.sender_id = 2880; + info.preamble = 0x55; + info.crc = 0xabea; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_reset_dep_t &lesser, + const sbp_msg_reset_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_reset_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_reset_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_reset_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_reset_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgResetDep, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgResetDep, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgResetDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgResetDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_reset_dep_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 178, 0, 64, 11, 0, 234, 171, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_reset_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgResetDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_reset_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgResetDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_reset_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_reset_dep_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgResetDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_reset_dep_t msg{}; + + EXPECT_EQ(sbp_msg_reset_dep_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_reset_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgResetDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgResetDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgResetDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgResetDep); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_RESET_DEP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_reset_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_reset_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.reset_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.reset_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgResetDep, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgResetDep, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgResetFilters.cc b/c/test/cpp/auto_check_sbp_piksi_MsgResetFilters.cc new file mode 100644 index 0000000000..fa6216467b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgResetFilters.cc @@ -0,0 +1,773 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgResetFilters0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgResetFilters0() { assign(test_msg_.filter, 100); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_filters_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_reset_filters_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgResetFilters, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_reset_filters_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgResetFilters); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->reset_filters, + sizeof(msg->reset_filters)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_reset_filters_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.reset_filters, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgResetFilters); + info.sender_id = 51281; + info.preamble = 0x55; + info.crc = 0x2d82; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 1; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_reset_filters_t &lesser, + const sbp_msg_reset_filters_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_reset_filters_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_reset_filters_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_reset_filters_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_reset_filters_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgResetFilters, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgResetFilters, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgResetFilters, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgResetFilters, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_reset_filters_t test_msg_{}; + uint8_t encoded_frame_[1 + 8] = { + 85, 34, 0, 81, 200, 1, 100, 130, 45, + }; + uint8_t encoded_payload_[1] = { + 100, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_reset_filters_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgResetFilters, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_reset_filters_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgResetFilters, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_reset_filters_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_msg_reset_filters_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_filters_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_reset_filters_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgResetFilters, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_reset_filters_t msg{}; + + EXPECT_EQ(sbp_msg_reset_filters_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_reset_filters_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_reset_filters_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_reset_filters_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgResetFilters, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgResetFilters, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgResetFilters, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_reset_filters_t lesser = info.test_msg; + sbp_msg_reset_filters_t greater = info.test_msg; + make_lesser_greater(lesser.filter, greater.filter); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgResetFilters); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_RESET_FILTERS"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_reset_filters_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_reset_filters_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.reset_filters, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.reset_filters, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 1), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_reset_filters_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 1); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgResetFilters, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgResetFilters0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgResetFilters, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgSetTime.cc b/c/test/cpp/auto_check_sbp_piksi_MsgSetTime.cc new file mode 100644 index 0000000000..a79245b9ea --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgSetTime.cc @@ -0,0 +1,725 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgSetTime0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgSetTime0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_set_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_set_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSetTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_set_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSetTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->set_time, sizeof(msg->set_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_set_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.set_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSetTime); + info.sender_id = 43541; + info.preamble = 0x55; + info.crc = 0x41d7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_set_time_t &lesser, + const sbp_msg_set_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_set_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_set_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_set_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_set_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSetTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSetTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSetTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSetTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_set_time_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 104, 0, 21, 170, 0, 215, 65, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_set_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSetTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_set_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgSetTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ( + sbp_msg_set_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_set_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_set_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSetTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_set_time_t msg{}; + + EXPECT_EQ(sbp_msg_set_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_set_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSetTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSetTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSetTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSetTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_SET_TIME"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_set_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_set_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.set_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.set_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_set_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSetTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSetTime0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSetTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgSpecan.cc b/c/test/cpp/auto_check_sbp_piksi_MsgSpecan.cc new file mode 100644 index 0000000000..3cc6eed043 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgSpecan.cc @@ -0,0 +1,3122 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgSpecan0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgSpecan0() { + assign(test_msg_.amplitude_ref, 3780.199951171875); + assign(test_msg_.amplitude_unit, 1329.199951171875); + + assign(test_msg_.amplitude_value[0], 100); + + assign(test_msg_.amplitude_value[1], 179); + + assign(test_msg_.amplitude_value[2], 185); + + assign(test_msg_.amplitude_value[3], 17); + + assign(test_msg_.amplitude_value[4], 175); + + assign(test_msg_.amplitude_value[5], 49); + + assign(test_msg_.amplitude_value[6], 193); + + assign(test_msg_.amplitude_value[7], 228); + + assign(test_msg_.amplitude_value[8], 228); + + assign(test_msg_.amplitude_value[9], 47); + + assign(test_msg_.amplitude_value[10], 33); + + assign(test_msg_.amplitude_value[11], 24); + + assign(test_msg_.amplitude_value[12], 141); + + assign(test_msg_.amplitude_value[13], 177); + + assign(test_msg_.amplitude_value[14], 18); + + assign(test_msg_.amplitude_value[15], 99); + + assign(test_msg_.amplitude_value[16], 246); + + assign(test_msg_.amplitude_value[17], 121); + + assign(test_msg_.amplitude_value[18], 61); + + assign(test_msg_.amplitude_value[19], 40); + + assign(test_msg_.amplitude_value[20], 91); + + assign(test_msg_.amplitude_value[21], 145); + + assign(test_msg_.amplitude_value[22], 223); + + assign(test_msg_.amplitude_value[23], 167); + + assign(test_msg_.amplitude_value[24], 174); + + assign(test_msg_.amplitude_value[25], 9); + + assign(test_msg_.amplitude_value[26], 116); + + assign(test_msg_.amplitude_value[27], 11); + + assign(test_msg_.amplitude_value[28], 247); + + assign(test_msg_.amplitude_value[29], 84); + + assign(test_msg_.amplitude_value[30], 49); + + assign(test_msg_.amplitude_value[31], 153); + + assign(test_msg_.amplitude_value[32], 205); + + assign(test_msg_.amplitude_value[33], 2); + + assign(test_msg_.amplitude_value[34], 230); + + assign(test_msg_.amplitude_value[35], 194); + + assign(test_msg_.amplitude_value[36], 218); + + assign(test_msg_.amplitude_value[37], 241); + + assign(test_msg_.amplitude_value[38], 101); + + assign(test_msg_.amplitude_value[39], 107); + + assign(test_msg_.amplitude_value[40], 45); + + assign(test_msg_.amplitude_value[41], 137); + + assign(test_msg_.amplitude_value[42], 93); + + assign(test_msg_.amplitude_value[43], 114); + + assign(test_msg_.amplitude_value[44], 230); + + assign(test_msg_.amplitude_value[45], 43); + + assign(test_msg_.amplitude_value[46], 224); + + assign(test_msg_.amplitude_value[47], 23); + + assign(test_msg_.amplitude_value[48], 74); + + assign(test_msg_.amplitude_value[49], 209); + + assign(test_msg_.amplitude_value[50], 199); + + assign(test_msg_.amplitude_value[51], 211); + + assign(test_msg_.amplitude_value[52], 130); + + assign(test_msg_.amplitude_value[53], 89); + + assign(test_msg_.amplitude_value[54], 220); + + assign(test_msg_.amplitude_value[55], 163); + + assign(test_msg_.amplitude_value[56], 68); + + assign(test_msg_.amplitude_value[57], 20); + + assign(test_msg_.amplitude_value[58], 253); + + assign(test_msg_.amplitude_value[59], 7); + + assign(test_msg_.amplitude_value[60], 206); + + assign(test_msg_.amplitude_value[61], 50); + + assign(test_msg_.amplitude_value[62], 129); + + assign(test_msg_.amplitude_value[63], 116); + + assign(test_msg_.amplitude_value[64], 194); + + assign(test_msg_.amplitude_value[65], 23); + + assign(test_msg_.amplitude_value[66], 31); + + assign(test_msg_.amplitude_value[67], 226); + + assign(test_msg_.amplitude_value[68], 217); + + assign(test_msg_.amplitude_value[69], 157); + + assign(test_msg_.amplitude_value[70], 205); + + assign(test_msg_.amplitude_value[71], 221); + + assign(test_msg_.amplitude_value[72], 5); + + assign(test_msg_.amplitude_value[73], 224); + + assign(test_msg_.amplitude_value[74], 92); + + assign(test_msg_.amplitude_value[75], 82); + + assign(test_msg_.amplitude_value[76], 109); + + assign(test_msg_.amplitude_value[77], 223); + + assign(test_msg_.amplitude_value[78], 195); + + assign(test_msg_.amplitude_value[79], 233); + + assign(test_msg_.amplitude_value[80], 165); + + assign(test_msg_.amplitude_value[81], 1); + + assign(test_msg_.amplitude_value[82], 82); + + assign(test_msg_.amplitude_value[83], 141); + + assign(test_msg_.amplitude_value[84], 157); + + assign(test_msg_.amplitude_value[85], 177); + + assign(test_msg_.amplitude_value[86], 169); + + assign(test_msg_.amplitude_value[87], 244); + + assign(test_msg_.amplitude_value[88], 131); + + assign(test_msg_.amplitude_value[89], 96); + + assign(test_msg_.amplitude_value[90], 109); + + assign(test_msg_.amplitude_value[91], 111); + + assign(test_msg_.amplitude_value[92], 253); + + assign(test_msg_.amplitude_value[93], 149); + + assign(test_msg_.amplitude_value[94], 28); + + assign(test_msg_.amplitude_value[95], 225); + + assign(test_msg_.amplitude_value[96], 225); + + assign(test_msg_.amplitude_value[97], 72); + + assign(test_msg_.amplitude_value[98], 158); + + assign(test_msg_.amplitude_value[99], 158); + + assign(test_msg_.amplitude_value[100], 210); + + assign(test_msg_.amplitude_value[101], 196); + + assign(test_msg_.amplitude_value[102], 206); + + assign(test_msg_.amplitude_value[103], 70); + + assign(test_msg_.amplitude_value[104], 63); + + assign(test_msg_.amplitude_value[105], 225); + + assign(test_msg_.amplitude_value[106], 184); + + assign(test_msg_.amplitude_value[107], 150); + + assign(test_msg_.amplitude_value[108], 174); + + assign(test_msg_.amplitude_value[109], 240); + + assign(test_msg_.amplitude_value[110], 45); + + assign(test_msg_.amplitude_value[111], 146); + + assign(test_msg_.amplitude_value[112], 59); + + assign(test_msg_.amplitude_value[113], 82); + + assign(test_msg_.amplitude_value[114], 194); + + assign(test_msg_.amplitude_value[115], 4); + + assign(test_msg_.amplitude_value[116], 179); + + assign(test_msg_.amplitude_value[117], 148); + + assign(test_msg_.amplitude_value[118], 66); + + assign(test_msg_.amplitude_value[119], 254); + + assign(test_msg_.amplitude_value[120], 115); + + assign(test_msg_.amplitude_value[121], 77); + + assign(test_msg_.amplitude_value[122], 30); + + assign(test_msg_.amplitude_value[123], 46); + + assign(test_msg_.amplitude_value[124], 4); + + assign(test_msg_.amplitude_value[125], 204); + + assign(test_msg_.amplitude_value[126], 37); + + assign(test_msg_.amplitude_value[127], 200); + + assign(test_msg_.amplitude_value[128], 121); + + assign(test_msg_.amplitude_value[129], 18); + + assign(test_msg_.amplitude_value[130], 17); + + assign(test_msg_.amplitude_value[131], 171); + + assign(test_msg_.amplitude_value[132], 102); + + assign(test_msg_.amplitude_value[133], 163); + + assign(test_msg_.amplitude_value[134], 175); + + assign(test_msg_.amplitude_value[135], 50); + + assign(test_msg_.amplitude_value[136], 66); + + assign(test_msg_.amplitude_value[137], 101); + + assign(test_msg_.amplitude_value[138], 69); + + assign(test_msg_.amplitude_value[139], 13); + + assign(test_msg_.amplitude_value[140], 223); + + assign(test_msg_.amplitude_value[141], 172); + + assign(test_msg_.amplitude_value[142], 160); + + assign(test_msg_.amplitude_value[143], 233); + + assign(test_msg_.amplitude_value[144], 220); + + assign(test_msg_.amplitude_value[145], 101); + + assign(test_msg_.amplitude_value[146], 237); + + assign(test_msg_.amplitude_value[147], 156); + + assign(test_msg_.amplitude_value[148], 62); + + assign(test_msg_.amplitude_value[149], 117); + + assign(test_msg_.amplitude_value[150], 47); + + assign(test_msg_.amplitude_value[151], 143); + + assign(test_msg_.amplitude_value[152], 94); + + assign(test_msg_.amplitude_value[153], 135); + + assign(test_msg_.amplitude_value[154], 22); + + assign(test_msg_.amplitude_value[155], 155); + + assign(test_msg_.amplitude_value[156], 113); + + assign(test_msg_.amplitude_value[157], 110); + + assign(test_msg_.amplitude_value[158], 15); + + assign(test_msg_.amplitude_value[159], 243); + + assign(test_msg_.amplitude_value[160], 141); + + assign(test_msg_.amplitude_value[161], 227); + + assign(test_msg_.amplitude_value[162], 46); + + assign(test_msg_.amplitude_value[163], 143); + + assign(test_msg_.amplitude_value[164], 227); + + assign(test_msg_.amplitude_value[165], 209); + + assign(test_msg_.amplitude_value[166], 249); + + assign(test_msg_.amplitude_value[167], 2); + + assign(test_msg_.amplitude_value[168], 153); + + assign(test_msg_.amplitude_value[169], 168); + + assign(test_msg_.amplitude_value[170], 131); + + assign(test_msg_.amplitude_value[171], 249); + + assign(test_msg_.amplitude_value[172], 160); + + assign(test_msg_.amplitude_value[173], 88); + + assign(test_msg_.amplitude_value[174], 38); + + assign(test_msg_.amplitude_value[175], 117); + + assign(test_msg_.amplitude_value[176], 129); + + assign(test_msg_.amplitude_value[177], 57); + + assign(test_msg_.amplitude_value[178], 40); + + assign(test_msg_.amplitude_value[179], 109); + + assign(test_msg_.amplitude_value[180], 209); + + assign(test_msg_.amplitude_value[181], 177); + + assign(test_msg_.amplitude_value[182], 38); + + assign(test_msg_.amplitude_value[183], 47); + + assign(test_msg_.amplitude_value[184], 12); + + assign(test_msg_.amplitude_value[185], 15); + + assign(test_msg_.amplitude_value[186], 16); + + assign(test_msg_.amplitude_value[187], 9); + + assign(test_msg_.amplitude_value[188], 175); + + assign(test_msg_.amplitude_value[189], 69); + + assign(test_msg_.amplitude_value[190], 70); + + assign(test_msg_.amplitude_value[191], 182); + + assign(test_msg_.amplitude_value[192], 239); + + assign(test_msg_.amplitude_value[193], 117); + + assign(test_msg_.amplitude_value[194], 135); + + assign(test_msg_.amplitude_value[195], 6); + + assign(test_msg_.amplitude_value[196], 71); + + assign(test_msg_.amplitude_value[197], 99); + + assign(test_msg_.amplitude_value[198], 230); + + assign(test_msg_.amplitude_value[199], 115); + + assign(test_msg_.amplitude_value[200], 2); + + assign(test_msg_.amplitude_value[201], 71); + + assign(test_msg_.amplitude_value[202], 165); + + assign(test_msg_.amplitude_value[203], 228); + + assign(test_msg_.amplitude_value[204], 123); + + assign(test_msg_.amplitude_value[205], 210); + + assign(test_msg_.amplitude_value[206], 168); + + assign(test_msg_.amplitude_value[207], 90); + + assign(test_msg_.amplitude_value[208], 124); + + assign(test_msg_.amplitude_value[209], 20); + + assign(test_msg_.amplitude_value[210], 7); + + assign(test_msg_.amplitude_value[211], 220); + + assign(test_msg_.amplitude_value[212], 144); + + assign(test_msg_.amplitude_value[213], 168); + + assign(test_msg_.amplitude_value[214], 69); + + assign(test_msg_.amplitude_value[215], 22); + + assign(test_msg_.amplitude_value[216], 72); + + assign(test_msg_.amplitude_value[217], 162); + + assign(test_msg_.amplitude_value[218], 69); + + assign(test_msg_.amplitude_value[219], 111); + + assign(test_msg_.amplitude_value[220], 91); + + assign(test_msg_.amplitude_value[221], 251); + + assign(test_msg_.amplitude_value[222], 72); + + assign(test_msg_.amplitude_value[223], 220); + + assign(test_msg_.amplitude_value[224], 28); + + assign(test_msg_.amplitude_value[225], 119); + + assign(test_msg_.amplitude_value[226], 150); + assign(test_msg_.channel_tag, 35146); + assign(test_msg_.freq_ref, 7737.2001953125); + assign(test_msg_.freq_step, 8226.2001953125); + assign(test_msg_.n_amplitude_value, 227); + assign(test_msg_.t.ns_residual, -1479025396); + assign(test_msg_.t.tow, 1227027783); + assign(test_msg_.t.wn, 5075); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_specan_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_specan_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSpecan, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_specan_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSpecan); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->specan, sizeof(msg->specan)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_specan_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.specan, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSpecan); + info.sender_id = 54300; + info.preamble = 0x55; + info.crc = 0x025f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_specan_t &lesser, + const sbp_msg_specan_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_specan_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_specan_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_specan_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_specan_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSpecan, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSpecan, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSpecan, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSpecan, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_specan_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, 215, + 167, 211, 19, 154, 201, 241, 69, 205, 136, 0, 70, 51, 67, 108, 69, + 102, 38, 166, 68, 100, 179, 185, 17, 175, 49, 193, 228, 228, 47, 33, + 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, 223, 167, 174, 9, + 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, 218, 241, 101, 107, 45, + 137, 93, 114, 230, 43, 224, 23, 74, 209, 199, 211, 130, 89, 220, 163, + 68, 20, 253, 7, 206, 50, 129, 116, 194, 23, 31, 226, 217, 157, 205, + 221, 5, 224, 92, 82, 109, 223, 195, 233, 165, 1, 82, 141, 157, 177, + 169, 244, 131, 96, 109, 111, 253, 149, 28, 225, 225, 72, 158, 158, 210, + 196, 206, 70, 63, 225, 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, + 179, 148, 66, 254, 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, + 171, 102, 163, 175, 50, 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, + 237, 156, 62, 117, 47, 143, 94, 135, 22, 155, 113, 110, 15, 243, 141, + 227, 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, 88, 38, 117, + 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, 70, + 182, 239, 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, 123, 210, + 168, 90, 124, 20, 7, 220, 144, 168, 69, 22, 72, 162, 69, 111, 91, + 251, 72, 220, 28, 119, 150, 95, 2, + }; + uint8_t encoded_payload_[255] = { + 74, 137, 71, 245, 34, 73, 12, 221, 215, 167, 211, 19, 154, 201, 241, + 69, 205, 136, 0, 70, 51, 67, 108, 69, 102, 38, 166, 68, 100, 179, + 185, 17, 175, 49, 193, 228, 228, 47, 33, 24, 141, 177, 18, 99, 246, + 121, 61, 40, 91, 145, 223, 167, 174, 9, 116, 11, 247, 84, 49, 153, + 205, 2, 230, 194, 218, 241, 101, 107, 45, 137, 93, 114, 230, 43, 224, + 23, 74, 209, 199, 211, 130, 89, 220, 163, 68, 20, 253, 7, 206, 50, + 129, 116, 194, 23, 31, 226, 217, 157, 205, 221, 5, 224, 92, 82, 109, + 223, 195, 233, 165, 1, 82, 141, 157, 177, 169, 244, 131, 96, 109, 111, + 253, 149, 28, 225, 225, 72, 158, 158, 210, 196, 206, 70, 63, 225, 184, + 150, 174, 240, 45, 146, 59, 82, 194, 4, 179, 148, 66, 254, 115, 77, + 30, 46, 4, 204, 37, 200, 121, 18, 17, 171, 102, 163, 175, 50, 66, + 101, 69, 13, 223, 172, 160, 233, 220, 101, 237, 156, 62, 117, 47, 143, + 94, 135, 22, 155, 113, 110, 15, 243, 141, 227, 46, 143, 227, 209, 249, + 2, 153, 168, 131, 249, 160, 88, 38, 117, 129, 57, 40, 109, 209, 177, + 38, 47, 12, 15, 16, 9, 175, 69, 70, 182, 239, 117, 135, 6, 71, + 99, 230, 115, 2, 71, 165, 228, 123, 210, 168, 90, 124, 20, 7, 220, + 144, 168, 69, 22, 72, 162, 69, 111, 91, 251, 72, 220, 28, 119, 150, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_specan_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSpecan, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_specan_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgSpecan, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ( + sbp_msg_specan_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_specan_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_specan_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_specan_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSpecan, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_specan_t msg{}; + + EXPECT_EQ(sbp_msg_specan_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_specan_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_specan_t t{}; + return sbp_msg_specan_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_specan_t t{}; + t.n_amplitude_value = 1; + return sbp_msg_specan_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_specan_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_specan_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSpecan, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSpecan, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSpecan, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_ref, greater.amplitude_ref); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_unit, greater.amplitude_unit); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[0], greater.amplitude_value[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[1], greater.amplitude_value[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[2], greater.amplitude_value[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[3], greater.amplitude_value[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[4], greater.amplitude_value[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[5], greater.amplitude_value[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[6], greater.amplitude_value[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[7], greater.amplitude_value[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[8], greater.amplitude_value[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[9], greater.amplitude_value[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[10], + greater.amplitude_value[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[11], + greater.amplitude_value[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[12], + greater.amplitude_value[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[13], + greater.amplitude_value[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[14], + greater.amplitude_value[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[15], + greater.amplitude_value[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[16], + greater.amplitude_value[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[17], + greater.amplitude_value[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[18], + greater.amplitude_value[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[19], + greater.amplitude_value[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[20], + greater.amplitude_value[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[21], + greater.amplitude_value[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[22], + greater.amplitude_value[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[23], + greater.amplitude_value[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[24], + greater.amplitude_value[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[25], + greater.amplitude_value[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[26], + greater.amplitude_value[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[27], + greater.amplitude_value[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[28], + greater.amplitude_value[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[29], + greater.amplitude_value[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[30], + greater.amplitude_value[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[31], + greater.amplitude_value[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[32], + greater.amplitude_value[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[33], + greater.amplitude_value[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[34], + greater.amplitude_value[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[35], + greater.amplitude_value[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[36], + greater.amplitude_value[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[37], + greater.amplitude_value[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[38], + greater.amplitude_value[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[39], + greater.amplitude_value[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[40], + greater.amplitude_value[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[41], + greater.amplitude_value[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[42], + greater.amplitude_value[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[43], + greater.amplitude_value[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[44], + greater.amplitude_value[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[45], + greater.amplitude_value[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[46], + greater.amplitude_value[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[47], + greater.amplitude_value[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[48], + greater.amplitude_value[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[49], + greater.amplitude_value[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[50], + greater.amplitude_value[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[51], + greater.amplitude_value[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[52], + greater.amplitude_value[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[53], + greater.amplitude_value[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[54], + greater.amplitude_value[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[55], + greater.amplitude_value[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[56], + greater.amplitude_value[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[57], + greater.amplitude_value[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[58], + greater.amplitude_value[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[59], + greater.amplitude_value[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[60], + greater.amplitude_value[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[61], + greater.amplitude_value[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[62], + greater.amplitude_value[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[63], + greater.amplitude_value[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[64], + greater.amplitude_value[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[65], + greater.amplitude_value[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[66], + greater.amplitude_value[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[67], + greater.amplitude_value[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[68], + greater.amplitude_value[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[69], + greater.amplitude_value[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[70], + greater.amplitude_value[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[71], + greater.amplitude_value[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[72], + greater.amplitude_value[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[73], + greater.amplitude_value[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[74], + greater.amplitude_value[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[75], + greater.amplitude_value[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[76], + greater.amplitude_value[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[77], + greater.amplitude_value[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[78], + greater.amplitude_value[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[79], + greater.amplitude_value[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[80], + greater.amplitude_value[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[81], + greater.amplitude_value[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[82], + greater.amplitude_value[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[83], + greater.amplitude_value[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[84], + greater.amplitude_value[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[85], + greater.amplitude_value[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[86], + greater.amplitude_value[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[87], + greater.amplitude_value[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[88], + greater.amplitude_value[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[89], + greater.amplitude_value[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[90], + greater.amplitude_value[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[91], + greater.amplitude_value[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[92], + greater.amplitude_value[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[93], + greater.amplitude_value[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[94], + greater.amplitude_value[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[95], + greater.amplitude_value[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[96], + greater.amplitude_value[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[97], + greater.amplitude_value[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[98], + greater.amplitude_value[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[99], + greater.amplitude_value[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[100], + greater.amplitude_value[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[101], + greater.amplitude_value[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[102], + greater.amplitude_value[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[103], + greater.amplitude_value[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[104], + greater.amplitude_value[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[105], + greater.amplitude_value[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[106], + greater.amplitude_value[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[107], + greater.amplitude_value[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[108], + greater.amplitude_value[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[109], + greater.amplitude_value[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[110], + greater.amplitude_value[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[111], + greater.amplitude_value[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[112], + greater.amplitude_value[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[113], + greater.amplitude_value[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[114], + greater.amplitude_value[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[115], + greater.amplitude_value[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[116], + greater.amplitude_value[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[117], + greater.amplitude_value[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[118], + greater.amplitude_value[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[119], + greater.amplitude_value[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[120], + greater.amplitude_value[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[121], + greater.amplitude_value[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[122], + greater.amplitude_value[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[123], + greater.amplitude_value[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[124], + greater.amplitude_value[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[125], + greater.amplitude_value[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[126], + greater.amplitude_value[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[127], + greater.amplitude_value[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[128], + greater.amplitude_value[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[129], + greater.amplitude_value[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[130], + greater.amplitude_value[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[131], + greater.amplitude_value[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[132], + greater.amplitude_value[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[133], + greater.amplitude_value[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[134], + greater.amplitude_value[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[135], + greater.amplitude_value[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[136], + greater.amplitude_value[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[137], + greater.amplitude_value[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[138], + greater.amplitude_value[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[139], + greater.amplitude_value[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[140], + greater.amplitude_value[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[141], + greater.amplitude_value[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[142], + greater.amplitude_value[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[143], + greater.amplitude_value[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[144], + greater.amplitude_value[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[145], + greater.amplitude_value[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[146], + greater.amplitude_value[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[147], + greater.amplitude_value[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[148], + greater.amplitude_value[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[149], + greater.amplitude_value[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[150], + greater.amplitude_value[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[151], + greater.amplitude_value[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[152], + greater.amplitude_value[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[153], + greater.amplitude_value[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[154], + greater.amplitude_value[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[155], + greater.amplitude_value[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[156], + greater.amplitude_value[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[157], + greater.amplitude_value[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[158], + greater.amplitude_value[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[159], + greater.amplitude_value[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[160], + greater.amplitude_value[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[161], + greater.amplitude_value[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[162], + greater.amplitude_value[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[163], + greater.amplitude_value[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[164], + greater.amplitude_value[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[165], + greater.amplitude_value[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[166], + greater.amplitude_value[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[167], + greater.amplitude_value[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[168], + greater.amplitude_value[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[169], + greater.amplitude_value[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[170], + greater.amplitude_value[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[171], + greater.amplitude_value[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[172], + greater.amplitude_value[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[173], + greater.amplitude_value[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[174], + greater.amplitude_value[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[175], + greater.amplitude_value[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[176], + greater.amplitude_value[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[177], + greater.amplitude_value[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[178], + greater.amplitude_value[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[179], + greater.amplitude_value[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[180], + greater.amplitude_value[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[181], + greater.amplitude_value[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[182], + greater.amplitude_value[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[183], + greater.amplitude_value[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[184], + greater.amplitude_value[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[185], + greater.amplitude_value[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[186], + greater.amplitude_value[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[187], + greater.amplitude_value[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[188], + greater.amplitude_value[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[189], + greater.amplitude_value[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[190], + greater.amplitude_value[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[191], + greater.amplitude_value[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[192], + greater.amplitude_value[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[193], + greater.amplitude_value[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[194], + greater.amplitude_value[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[195], + greater.amplitude_value[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[196], + greater.amplitude_value[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[197], + greater.amplitude_value[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[198], + greater.amplitude_value[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[199], + greater.amplitude_value[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[200], + greater.amplitude_value[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[201], + greater.amplitude_value[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[202], + greater.amplitude_value[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[203], + greater.amplitude_value[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[204], + greater.amplitude_value[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[205], + greater.amplitude_value[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[206], + greater.amplitude_value[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[207], + greater.amplitude_value[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[208], + greater.amplitude_value[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[209], + greater.amplitude_value[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[210], + greater.amplitude_value[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[211], + greater.amplitude_value[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[212], + greater.amplitude_value[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[213], + greater.amplitude_value[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[214], + greater.amplitude_value[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[215], + greater.amplitude_value[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[216], + greater.amplitude_value[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[217], + greater.amplitude_value[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[218], + greater.amplitude_value[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[219], + greater.amplitude_value[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[220], + greater.amplitude_value[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[221], + greater.amplitude_value[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[222], + greater.amplitude_value[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[223], + greater.amplitude_value[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[224], + greater.amplitude_value[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[225], + greater.amplitude_value[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[226], + greater.amplitude_value[226]); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.channel_tag, greater.channel_tag); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.freq_ref, greater.freq_ref); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.freq_step, greater.freq_step); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.n_amplitude_value, greater.n_amplitude_value); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.t.ns_residual, greater.t.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.t.tow, greater.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_t lesser = info.test_msg; + sbp_msg_specan_t greater = info.test_msg; + make_lesser_greater(lesser.t.wn, greater.t.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSpecan); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_SPECAN"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_specan_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_specan_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.specan, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.specan, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_specan_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSpecan, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecan0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSpecan, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc b/c/test/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc new file mode 100644 index 0000000000..63d83d07e3 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc @@ -0,0 +1,3162 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgSpecanDep0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgSpecanDep0() { + assign(test_msg_.amplitude_ref, 9349.2001953125); + assign(test_msg_.amplitude_unit, 3485.199951171875); + + assign(test_msg_.amplitude_value[0], 240); + + assign(test_msg_.amplitude_value[1], 14); + + assign(test_msg_.amplitude_value[2], 179); + + assign(test_msg_.amplitude_value[3], 186); + + assign(test_msg_.amplitude_value[4], 227); + + assign(test_msg_.amplitude_value[5], 244); + + assign(test_msg_.amplitude_value[6], 173); + + assign(test_msg_.amplitude_value[7], 240); + + assign(test_msg_.amplitude_value[8], 182); + + assign(test_msg_.amplitude_value[9], 71); + + assign(test_msg_.amplitude_value[10], 166); + + assign(test_msg_.amplitude_value[11], 117); + + assign(test_msg_.amplitude_value[12], 196); + + assign(test_msg_.amplitude_value[13], 13); + + assign(test_msg_.amplitude_value[14], 44); + + assign(test_msg_.amplitude_value[15], 27); + + assign(test_msg_.amplitude_value[16], 33); + + assign(test_msg_.amplitude_value[17], 28); + + assign(test_msg_.amplitude_value[18], 67); + + assign(test_msg_.amplitude_value[19], 254); + + assign(test_msg_.amplitude_value[20], 3); + + assign(test_msg_.amplitude_value[21], 249); + + assign(test_msg_.amplitude_value[22], 92); + + assign(test_msg_.amplitude_value[23], 44); + + assign(test_msg_.amplitude_value[24], 122); + + assign(test_msg_.amplitude_value[25], 169); + + assign(test_msg_.amplitude_value[26], 77); + + assign(test_msg_.amplitude_value[27], 186); + + assign(test_msg_.amplitude_value[28], 68); + + assign(test_msg_.amplitude_value[29], 135); + + assign(test_msg_.amplitude_value[30], 63); + + assign(test_msg_.amplitude_value[31], 168); + + assign(test_msg_.amplitude_value[32], 162); + + assign(test_msg_.amplitude_value[33], 89); + + assign(test_msg_.amplitude_value[34], 36); + + assign(test_msg_.amplitude_value[35], 186); + + assign(test_msg_.amplitude_value[36], 99); + + assign(test_msg_.amplitude_value[37], 63); + + assign(test_msg_.amplitude_value[38], 105); + + assign(test_msg_.amplitude_value[39], 116); + + assign(test_msg_.amplitude_value[40], 216); + + assign(test_msg_.amplitude_value[41], 44); + + assign(test_msg_.amplitude_value[42], 67); + + assign(test_msg_.amplitude_value[43], 212); + + assign(test_msg_.amplitude_value[44], 156); + + assign(test_msg_.amplitude_value[45], 75); + + assign(test_msg_.amplitude_value[46], 81); + + assign(test_msg_.amplitude_value[47], 53); + + assign(test_msg_.amplitude_value[48], 250); + + assign(test_msg_.amplitude_value[49], 225); + + assign(test_msg_.amplitude_value[50], 23); + + assign(test_msg_.amplitude_value[51], 205); + + assign(test_msg_.amplitude_value[52], 26); + + assign(test_msg_.amplitude_value[53], 34); + + assign(test_msg_.amplitude_value[54], 119); + + assign(test_msg_.amplitude_value[55], 50); + + assign(test_msg_.amplitude_value[56], 101); + + assign(test_msg_.amplitude_value[57], 64); + + assign(test_msg_.amplitude_value[58], 7); + + assign(test_msg_.amplitude_value[59], 231); + + assign(test_msg_.amplitude_value[60], 124); + + assign(test_msg_.amplitude_value[61], 183); + + assign(test_msg_.amplitude_value[62], 203); + + assign(test_msg_.amplitude_value[63], 102); + + assign(test_msg_.amplitude_value[64], 234); + + assign(test_msg_.amplitude_value[65], 84); + + assign(test_msg_.amplitude_value[66], 83); + + assign(test_msg_.amplitude_value[67], 208); + + assign(test_msg_.amplitude_value[68], 23); + + assign(test_msg_.amplitude_value[69], 68); + + assign(test_msg_.amplitude_value[70], 54); + + assign(test_msg_.amplitude_value[71], 179); + + assign(test_msg_.amplitude_value[72], 98); + + assign(test_msg_.amplitude_value[73], 96); + + assign(test_msg_.amplitude_value[74], 116); + + assign(test_msg_.amplitude_value[75], 244); + + assign(test_msg_.amplitude_value[76], 246); + + assign(test_msg_.amplitude_value[77], 94); + + assign(test_msg_.amplitude_value[78], 104); + + assign(test_msg_.amplitude_value[79], 94); + + assign(test_msg_.amplitude_value[80], 13); + + assign(test_msg_.amplitude_value[81], 56); + + assign(test_msg_.amplitude_value[82], 210); + + assign(test_msg_.amplitude_value[83], 18); + + assign(test_msg_.amplitude_value[84], 191); + + assign(test_msg_.amplitude_value[85], 22); + + assign(test_msg_.amplitude_value[86], 133); + + assign(test_msg_.amplitude_value[87], 81); + + assign(test_msg_.amplitude_value[88], 153); + + assign(test_msg_.amplitude_value[89], 159); + + assign(test_msg_.amplitude_value[90], 161); + + assign(test_msg_.amplitude_value[91], 219); + + assign(test_msg_.amplitude_value[92], 59); + + assign(test_msg_.amplitude_value[93], 21); + + assign(test_msg_.amplitude_value[94], 164); + + assign(test_msg_.amplitude_value[95], 121); + + assign(test_msg_.amplitude_value[96], 145); + + assign(test_msg_.amplitude_value[97], 203); + + assign(test_msg_.amplitude_value[98], 171); + + assign(test_msg_.amplitude_value[99], 132); + + assign(test_msg_.amplitude_value[100], 57); + + assign(test_msg_.amplitude_value[101], 180); + + assign(test_msg_.amplitude_value[102], 102); + + assign(test_msg_.amplitude_value[103], 101); + + assign(test_msg_.amplitude_value[104], 11); + + assign(test_msg_.amplitude_value[105], 229); + + assign(test_msg_.amplitude_value[106], 175); + + assign(test_msg_.amplitude_value[107], 145); + + assign(test_msg_.amplitude_value[108], 73); + + assign(test_msg_.amplitude_value[109], 72); + + assign(test_msg_.amplitude_value[110], 124); + + assign(test_msg_.amplitude_value[111], 4); + + assign(test_msg_.amplitude_value[112], 184); + + assign(test_msg_.amplitude_value[113], 228); + + assign(test_msg_.amplitude_value[114], 61); + + assign(test_msg_.amplitude_value[115], 234); + + assign(test_msg_.amplitude_value[116], 218); + + assign(test_msg_.amplitude_value[117], 62); + + assign(test_msg_.amplitude_value[118], 226); + + assign(test_msg_.amplitude_value[119], 217); + + assign(test_msg_.amplitude_value[120], 193); + + assign(test_msg_.amplitude_value[121], 7); + + assign(test_msg_.amplitude_value[122], 109); + + assign(test_msg_.amplitude_value[123], 44); + + assign(test_msg_.amplitude_value[124], 83); + + assign(test_msg_.amplitude_value[125], 201); + + assign(test_msg_.amplitude_value[126], 20); + + assign(test_msg_.amplitude_value[127], 101); + + assign(test_msg_.amplitude_value[128], 9); + + assign(test_msg_.amplitude_value[129], 140); + + assign(test_msg_.amplitude_value[130], 186); + + assign(test_msg_.amplitude_value[131], 162); + + assign(test_msg_.amplitude_value[132], 81); + + assign(test_msg_.amplitude_value[133], 91); + + assign(test_msg_.amplitude_value[134], 30); + + assign(test_msg_.amplitude_value[135], 231); + + assign(test_msg_.amplitude_value[136], 161); + + assign(test_msg_.amplitude_value[137], 81); + + assign(test_msg_.amplitude_value[138], 216); + + assign(test_msg_.amplitude_value[139], 114); + + assign(test_msg_.amplitude_value[140], 60); + + assign(test_msg_.amplitude_value[141], 231); + + assign(test_msg_.amplitude_value[142], 163); + + assign(test_msg_.amplitude_value[143], 163); + + assign(test_msg_.amplitude_value[144], 49); + + assign(test_msg_.amplitude_value[145], 237); + + assign(test_msg_.amplitude_value[146], 244); + + assign(test_msg_.amplitude_value[147], 185); + + assign(test_msg_.amplitude_value[148], 240); + + assign(test_msg_.amplitude_value[149], 89); + + assign(test_msg_.amplitude_value[150], 143); + + assign(test_msg_.amplitude_value[151], 174); + + assign(test_msg_.amplitude_value[152], 165); + + assign(test_msg_.amplitude_value[153], 211); + + assign(test_msg_.amplitude_value[154], 241); + + assign(test_msg_.amplitude_value[155], 13); + + assign(test_msg_.amplitude_value[156], 16); + + assign(test_msg_.amplitude_value[157], 61); + + assign(test_msg_.amplitude_value[158], 141); + + assign(test_msg_.amplitude_value[159], 101); + + assign(test_msg_.amplitude_value[160], 89); + + assign(test_msg_.amplitude_value[161], 37); + + assign(test_msg_.amplitude_value[162], 117); + + assign(test_msg_.amplitude_value[163], 189); + + assign(test_msg_.amplitude_value[164], 86); + + assign(test_msg_.amplitude_value[165], 118); + + assign(test_msg_.amplitude_value[166], 176); + + assign(test_msg_.amplitude_value[167], 228); + + assign(test_msg_.amplitude_value[168], 12); + + assign(test_msg_.amplitude_value[169], 14); + + assign(test_msg_.amplitude_value[170], 119); + + assign(test_msg_.amplitude_value[171], 135); + + assign(test_msg_.amplitude_value[172], 129); + + assign(test_msg_.amplitude_value[173], 243); + + assign(test_msg_.amplitude_value[174], 50); + + assign(test_msg_.amplitude_value[175], 29); + + assign(test_msg_.amplitude_value[176], 207); + + assign(test_msg_.amplitude_value[177], 198); + + assign(test_msg_.amplitude_value[178], 117); + + assign(test_msg_.amplitude_value[179], 100); + + assign(test_msg_.amplitude_value[180], 225); + + assign(test_msg_.amplitude_value[181], 6); + + assign(test_msg_.amplitude_value[182], 139); + + assign(test_msg_.amplitude_value[183], 110); + + assign(test_msg_.amplitude_value[184], 39); + + assign(test_msg_.amplitude_value[185], 210); + + assign(test_msg_.amplitude_value[186], 68); + + assign(test_msg_.amplitude_value[187], 199); + + assign(test_msg_.amplitude_value[188], 43); + + assign(test_msg_.amplitude_value[189], 132); + + assign(test_msg_.amplitude_value[190], 64); + + assign(test_msg_.amplitude_value[191], 17); + + assign(test_msg_.amplitude_value[192], 51); + + assign(test_msg_.amplitude_value[193], 173); + + assign(test_msg_.amplitude_value[194], 181); + + assign(test_msg_.amplitude_value[195], 12); + + assign(test_msg_.amplitude_value[196], 140); + + assign(test_msg_.amplitude_value[197], 16); + + assign(test_msg_.amplitude_value[198], 247); + + assign(test_msg_.amplitude_value[199], 84); + + assign(test_msg_.amplitude_value[200], 183); + + assign(test_msg_.amplitude_value[201], 105); + + assign(test_msg_.amplitude_value[202], 39); + + assign(test_msg_.amplitude_value[203], 157); + + assign(test_msg_.amplitude_value[204], 77); + + assign(test_msg_.amplitude_value[205], 30); + + assign(test_msg_.amplitude_value[206], 205); + + assign(test_msg_.amplitude_value[207], 194); + + assign(test_msg_.amplitude_value[208], 59); + + assign(test_msg_.amplitude_value[209], 64); + + assign(test_msg_.amplitude_value[210], 241); + + assign(test_msg_.amplitude_value[211], 183); + + assign(test_msg_.amplitude_value[212], 238); + + assign(test_msg_.amplitude_value[213], 105); + + assign(test_msg_.amplitude_value[214], 181); + + assign(test_msg_.amplitude_value[215], 170); + + assign(test_msg_.amplitude_value[216], 45); + + assign(test_msg_.amplitude_value[217], 8); + + assign(test_msg_.amplitude_value[218], 166); + + assign(test_msg_.amplitude_value[219], 164); + + assign(test_msg_.amplitude_value[220], 238); + + assign(test_msg_.amplitude_value[221], 83); + + assign(test_msg_.amplitude_value[222], 148); + + assign(test_msg_.amplitude_value[223], 173); + + assign(test_msg_.amplitude_value[224], 108); + + assign(test_msg_.amplitude_value[225], 228); + + assign(test_msg_.amplitude_value[226], 67); + + assign(test_msg_.amplitude_value[227], 89); + + assign(test_msg_.amplitude_value[228], 189); + + assign(test_msg_.amplitude_value[229], 67); + + assign(test_msg_.amplitude_value[230], 26); + assign(test_msg_.channel_tag, 5878); + assign(test_msg_.freq_ref, 6348.2001953125); + assign(test_msg_.freq_step, 4608.2001953125); + assign(test_msg_.n_amplitude_value, 231); + assign(test_msg_.t.tow, 992295133); + assign(test_msg_.t.wn, 6957); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_specan_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_specan_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSpecanDep, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_specan_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSpecanDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->specan_dep, sizeof(msg->specan_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_specan_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.specan_dep, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSpecanDep); + info.sender_id = 55664; + info.preamble = 0x55; + info.crc = 0xd827; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_specan_dep_t &lesser, + const sbp_msg_specan_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_specan_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_specan_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_specan_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_specan_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSpecanDep, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSpecanDep, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSpecanDep, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSpecanDep, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_specan_dep_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, 154, + 97, 198, 69, 154, 1, 144, 69, 205, 20, 18, 70, 51, 211, 89, 69, + 240, 14, 179, 186, 227, 244, 173, 240, 182, 71, 166, 117, 196, 13, 44, + 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, 77, 186, 68, 135, + 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, 216, 44, 67, 212, 156, + 75, 81, 53, 250, 225, 23, 205, 26, 34, 119, 50, 101, 64, 7, 231, + 124, 183, 203, 102, 234, 84, 83, 208, 23, 68, 54, 179, 98, 96, 116, + 244, 246, 94, 104, 94, 13, 56, 210, 18, 191, 22, 133, 81, 153, 159, + 161, 219, 59, 21, 164, 121, 145, 203, 171, 132, 57, 180, 102, 101, 11, + 229, 175, 145, 73, 72, 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, + 193, 7, 109, 44, 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, + 231, 161, 81, 216, 114, 60, 231, 163, 163, 49, 237, 244, 185, 240, 89, + 143, 174, 165, 211, 241, 13, 16, 61, 141, 101, 89, 37, 117, 189, 86, + 118, 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, 100, + 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, 181, + 12, 140, 16, 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, 59, 64, + 241, 183, 238, 105, 181, 170, 45, 8, 166, 164, 238, 83, 148, 173, 108, + 228, 67, 89, 189, 67, 26, 39, 216, + }; + uint8_t encoded_payload_[255] = { + 246, 22, 221, 56, 37, 59, 45, 27, 154, 97, 198, 69, 154, 1, 144, + 69, 205, 20, 18, 70, 51, 211, 89, 69, 240, 14, 179, 186, 227, 244, + 173, 240, 182, 71, 166, 117, 196, 13, 44, 27, 33, 28, 67, 254, 3, + 249, 92, 44, 122, 169, 77, 186, 68, 135, 63, 168, 162, 89, 36, 186, + 99, 63, 105, 116, 216, 44, 67, 212, 156, 75, 81, 53, 250, 225, 23, + 205, 26, 34, 119, 50, 101, 64, 7, 231, 124, 183, 203, 102, 234, 84, + 83, 208, 23, 68, 54, 179, 98, 96, 116, 244, 246, 94, 104, 94, 13, + 56, 210, 18, 191, 22, 133, 81, 153, 159, 161, 219, 59, 21, 164, 121, + 145, 203, 171, 132, 57, 180, 102, 101, 11, 229, 175, 145, 73, 72, 124, + 4, 184, 228, 61, 234, 218, 62, 226, 217, 193, 7, 109, 44, 83, 201, + 20, 101, 9, 140, 186, 162, 81, 91, 30, 231, 161, 81, 216, 114, 60, + 231, 163, 163, 49, 237, 244, 185, 240, 89, 143, 174, 165, 211, 241, 13, + 16, 61, 141, 101, 89, 37, 117, 189, 86, 118, 176, 228, 12, 14, 119, + 135, 129, 243, 50, 29, 207, 198, 117, 100, 225, 6, 139, 110, 39, 210, + 68, 199, 43, 132, 64, 17, 51, 173, 181, 12, 140, 16, 247, 84, 183, + 105, 39, 157, 77, 30, 205, 194, 59, 64, 241, 183, 238, 105, 181, 170, + 45, 8, 166, 164, 238, 83, 148, 173, 108, 228, 67, 89, 189, 67, 26, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_specan_dep_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSpecanDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_specan_dep_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSpecanDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ( + sbp_msg_specan_dep_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_specan_dep_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_specan_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_specan_dep_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSpecanDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_specan_dep_t msg{}; + + EXPECT_EQ(sbp_msg_specan_dep_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_specan_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_specan_dep_t t{}; + return sbp_msg_specan_dep_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_specan_dep_t t{}; + t.n_amplitude_value = 1; + return sbp_msg_specan_dep_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_specan_dep_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_specan_dep_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSpecanDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSpecanDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSpecanDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_ref, greater.amplitude_ref); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_unit, greater.amplitude_unit); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[0], greater.amplitude_value[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[1], greater.amplitude_value[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[2], greater.amplitude_value[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[3], greater.amplitude_value[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[4], greater.amplitude_value[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[5], greater.amplitude_value[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[6], greater.amplitude_value[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[7], greater.amplitude_value[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[8], greater.amplitude_value[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[9], greater.amplitude_value[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[10], + greater.amplitude_value[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[11], + greater.amplitude_value[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[12], + greater.amplitude_value[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[13], + greater.amplitude_value[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[14], + greater.amplitude_value[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[15], + greater.amplitude_value[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[16], + greater.amplitude_value[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[17], + greater.amplitude_value[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[18], + greater.amplitude_value[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[19], + greater.amplitude_value[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[20], + greater.amplitude_value[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[21], + greater.amplitude_value[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[22], + greater.amplitude_value[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[23], + greater.amplitude_value[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[24], + greater.amplitude_value[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[25], + greater.amplitude_value[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[26], + greater.amplitude_value[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[27], + greater.amplitude_value[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[28], + greater.amplitude_value[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[29], + greater.amplitude_value[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[30], + greater.amplitude_value[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[31], + greater.amplitude_value[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[32], + greater.amplitude_value[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[33], + greater.amplitude_value[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[34], + greater.amplitude_value[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[35], + greater.amplitude_value[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[36], + greater.amplitude_value[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[37], + greater.amplitude_value[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[38], + greater.amplitude_value[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[39], + greater.amplitude_value[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[40], + greater.amplitude_value[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[41], + greater.amplitude_value[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[42], + greater.amplitude_value[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[43], + greater.amplitude_value[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[44], + greater.amplitude_value[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[45], + greater.amplitude_value[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[46], + greater.amplitude_value[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[47], + greater.amplitude_value[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[48], + greater.amplitude_value[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[49], + greater.amplitude_value[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[50], + greater.amplitude_value[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[51], + greater.amplitude_value[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[52], + greater.amplitude_value[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[53], + greater.amplitude_value[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[54], + greater.amplitude_value[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[55], + greater.amplitude_value[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[56], + greater.amplitude_value[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[57], + greater.amplitude_value[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[58], + greater.amplitude_value[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[59], + greater.amplitude_value[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[60], + greater.amplitude_value[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[61], + greater.amplitude_value[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[62], + greater.amplitude_value[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[63], + greater.amplitude_value[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[64], + greater.amplitude_value[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[65], + greater.amplitude_value[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[66], + greater.amplitude_value[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[67], + greater.amplitude_value[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[68], + greater.amplitude_value[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[69], + greater.amplitude_value[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[70], + greater.amplitude_value[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[71], + greater.amplitude_value[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[72], + greater.amplitude_value[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[73], + greater.amplitude_value[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[74], + greater.amplitude_value[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[75], + greater.amplitude_value[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[76], + greater.amplitude_value[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[77], + greater.amplitude_value[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[78], + greater.amplitude_value[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[79], + greater.amplitude_value[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[80], + greater.amplitude_value[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[81], + greater.amplitude_value[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[82], + greater.amplitude_value[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[83], + greater.amplitude_value[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[84], + greater.amplitude_value[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[85], + greater.amplitude_value[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[86], + greater.amplitude_value[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[87], + greater.amplitude_value[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[88], + greater.amplitude_value[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[89], + greater.amplitude_value[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[90], + greater.amplitude_value[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[91], + greater.amplitude_value[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[92], + greater.amplitude_value[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[93], + greater.amplitude_value[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[94], + greater.amplitude_value[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[95], + greater.amplitude_value[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[96], + greater.amplitude_value[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[97], + greater.amplitude_value[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[98], + greater.amplitude_value[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[99], + greater.amplitude_value[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[100], + greater.amplitude_value[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[101], + greater.amplitude_value[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[102], + greater.amplitude_value[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[103], + greater.amplitude_value[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[104], + greater.amplitude_value[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[105], + greater.amplitude_value[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[106], + greater.amplitude_value[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[107], + greater.amplitude_value[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[108], + greater.amplitude_value[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[109], + greater.amplitude_value[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[110], + greater.amplitude_value[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[111], + greater.amplitude_value[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[112], + greater.amplitude_value[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[113], + greater.amplitude_value[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[114], + greater.amplitude_value[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[115], + greater.amplitude_value[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[116], + greater.amplitude_value[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[117], + greater.amplitude_value[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[118], + greater.amplitude_value[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[119], + greater.amplitude_value[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[120], + greater.amplitude_value[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[121], + greater.amplitude_value[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[122], + greater.amplitude_value[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[123], + greater.amplitude_value[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[124], + greater.amplitude_value[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[125], + greater.amplitude_value[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[126], + greater.amplitude_value[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[127], + greater.amplitude_value[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[128], + greater.amplitude_value[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[129], + greater.amplitude_value[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[130], + greater.amplitude_value[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[131], + greater.amplitude_value[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[132], + greater.amplitude_value[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[133], + greater.amplitude_value[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[134], + greater.amplitude_value[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[135], + greater.amplitude_value[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[136], + greater.amplitude_value[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[137], + greater.amplitude_value[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[138], + greater.amplitude_value[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[139], + greater.amplitude_value[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[140], + greater.amplitude_value[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[141], + greater.amplitude_value[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[142], + greater.amplitude_value[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[143], + greater.amplitude_value[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[144], + greater.amplitude_value[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[145], + greater.amplitude_value[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[146], + greater.amplitude_value[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[147], + greater.amplitude_value[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[148], + greater.amplitude_value[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[149], + greater.amplitude_value[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[150], + greater.amplitude_value[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[151], + greater.amplitude_value[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[152], + greater.amplitude_value[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[153], + greater.amplitude_value[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[154], + greater.amplitude_value[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[155], + greater.amplitude_value[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[156], + greater.amplitude_value[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[157], + greater.amplitude_value[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[158], + greater.amplitude_value[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[159], + greater.amplitude_value[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[160], + greater.amplitude_value[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[161], + greater.amplitude_value[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[162], + greater.amplitude_value[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[163], + greater.amplitude_value[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[164], + greater.amplitude_value[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[165], + greater.amplitude_value[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[166], + greater.amplitude_value[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[167], + greater.amplitude_value[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[168], + greater.amplitude_value[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[169], + greater.amplitude_value[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[170], + greater.amplitude_value[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[171], + greater.amplitude_value[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[172], + greater.amplitude_value[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[173], + greater.amplitude_value[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[174], + greater.amplitude_value[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[175], + greater.amplitude_value[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[176], + greater.amplitude_value[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[177], + greater.amplitude_value[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[178], + greater.amplitude_value[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[179], + greater.amplitude_value[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[180], + greater.amplitude_value[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[181], + greater.amplitude_value[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[182], + greater.amplitude_value[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[183], + greater.amplitude_value[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[184], + greater.amplitude_value[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[185], + greater.amplitude_value[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[186], + greater.amplitude_value[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[187], + greater.amplitude_value[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[188], + greater.amplitude_value[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[189], + greater.amplitude_value[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[190], + greater.amplitude_value[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[191], + greater.amplitude_value[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[192], + greater.amplitude_value[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[193], + greater.amplitude_value[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[194], + greater.amplitude_value[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[195], + greater.amplitude_value[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[196], + greater.amplitude_value[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[197], + greater.amplitude_value[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[198], + greater.amplitude_value[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[199], + greater.amplitude_value[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[200], + greater.amplitude_value[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[201], + greater.amplitude_value[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[202], + greater.amplitude_value[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[203], + greater.amplitude_value[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[204], + greater.amplitude_value[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[205], + greater.amplitude_value[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[206], + greater.amplitude_value[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[207], + greater.amplitude_value[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[208], + greater.amplitude_value[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[209], + greater.amplitude_value[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[210], + greater.amplitude_value[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[211], + greater.amplitude_value[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[212], + greater.amplitude_value[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[213], + greater.amplitude_value[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[214], + greater.amplitude_value[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[215], + greater.amplitude_value[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[216], + greater.amplitude_value[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[217], + greater.amplitude_value[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[218], + greater.amplitude_value[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[219], + greater.amplitude_value[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[220], + greater.amplitude_value[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[221], + greater.amplitude_value[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[222], + greater.amplitude_value[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[223], + greater.amplitude_value[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[224], + greater.amplitude_value[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[225], + greater.amplitude_value[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[226], + greater.amplitude_value[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[227], + greater.amplitude_value[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[228], + greater.amplitude_value[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[229], + greater.amplitude_value[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.amplitude_value[230], + greater.amplitude_value[230]); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.channel_tag, greater.channel_tag); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.freq_ref, greater.freq_ref); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.freq_step, greater.freq_step); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_amplitude_value, greater.n_amplitude_value); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t.tow, greater.t.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_specan_dep_t lesser = info.test_msg; + sbp_msg_specan_dep_t greater = info.test_msg; + make_lesser_greater(lesser.t.wn, greater.t.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSpecanDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SPECAN_DEP"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_specan_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_specan_dep_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.specan_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.specan_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_specan_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSpecanDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgSpecanDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSpecanDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgThreadState.cc b/c/test/cpp/auto_check_sbp_piksi_MsgThreadState.cc index d73b9c2ea8..80a7bb345b 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgThreadState.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgThreadState.cc @@ -16,1104 +16,8413 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgThreadState0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgThreadState0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState0() { + assign(test_msg_.cpu, 0); + { + const char assign_string[] = { + (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 2460); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x8a49; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 246, 215, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 9, 0, 0, 73, 138, + }; + uint8_t encoded_payload_[26] = { + 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 9, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState1 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState1() { + assign(test_msg_.cpu, 595); + { + const char assign_string[] = { + (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 36); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x1497; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 246, 215, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 2, 36, 0, 0, 0, 151, 20, + }; + uint8_t encoded_payload_[26] = { + 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 83, 2, 36, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState2 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState2() { + assign(test_msg_.cpu, 14); + { + const char assign_string[] = { + (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 1140); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x3ce2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 246, 215, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 116, 4, 0, 0, 226, 60, + }; + uint8_t encoded_payload_[26] = { + 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 14, 0, 116, 4, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState3 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState3() { + assign(test_msg_.cpu, 1); + { + const char assign_string[] = { + (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 5060); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xa95a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 246, 215, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 196, 19, 0, 0, 90, 169, + }; + uint8_t encoded_payload_[26] = { + 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 196, 19, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState4 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState4() { + assign(test_msg_.cpu, 7); + { + const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, + (char)103, (char)101, (char)32, (char)97, + (char)99, (char)113, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 2324); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x4b2f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 246, 215, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 20, 9, 0, 0, 47, 75, + }; + uint8_t encoded_payload_[26] = { + 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 7, 0, 20, 9, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState5 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState5() { + assign(test_msg_.cpu, 0); + { + const char assign_string[] = { + (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 2452); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xd4c3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 9, 0, 0, 195, 212, + }; + uint8_t encoded_payload_[26] = { + 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 9, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState6 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState6() { + assign(test_msg_.cpu, 484); + { + const char assign_string[] = { + (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 36); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x12e1; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 1, 36, 0, 0, 0, 225, 18, + }; + uint8_t encoded_payload_[26] = { + 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 228, 1, 36, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState6, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState7 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState7() { + assign(test_msg_.cpu, 394); + { + const char assign_string[] = { + (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 1884); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x74a6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 1, 92, 7, 0, 0, 166, 116, + }; + uint8_t encoded_payload_[26] = { + 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 138, 1, 92, 7, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState7, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState8 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgThreadState8() { + assign(test_msg_.cpu, 1); + { + const char assign_string[] = { + (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 3076); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xaee5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 12, 0, 0, 229, 174, + }; + uint8_t encoded_payload_[26] = { + 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 12, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState8, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState9 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgThreadState0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgThreadState9() { + assign(test_msg_.cpu, 10); + { + const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, + (char)103, (char)101, (char)32, (char)97, + (char)99, (char)113, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 2428); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x234; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 124, 9, 0, 0, 52, 2, + }; + uint8_t encoded_payload_[26] = { + 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 10, 0, 124, 9, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState0, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 246, 215, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156, 9, 0, 0, 73, 138, - }; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 0; - { - const char assign_string[] = { - (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } - test_msg.stack_free = 2460; +} - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - while (dummy_rd_ < dummy_wr_) { - process(); - } + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 0) - << "incorrect value for last_msg_.cpu, expected 0, is " << last_msg_.cpu; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, Comparison) { + auto info = get_test_msg_info(); { - const char check_string[] = { - (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 2460) - << "incorrect value for last_msg_.stack_free, expected 2460, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState1, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 246, 215, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 2, 36, 0, 0, 0, 151, 20, - }; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 595; - { - const char assign_string[] = { - (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 36; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - while (dummy_rd_ < dummy_wr_) { - process(); + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 595) - << "incorrect value for last_msg_.cpu, expected 595, is " - << last_msg_.cpu; - { - const char check_string[] = { - (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 36) - << "incorrect value for last_msg_.stack_free, expected 36, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState9, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgThreadState10 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgThreadState2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgThreadState10() { + assign(test_msg_.cpu, 0); + { + const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, + (char)103, (char)101, (char)32, (char)116, + (char)114, (char)97, (char)99, (char)107, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg_.name, assign_string, sizeof(assign_string)); + } + assign(test_msg_.stack_free, 2332); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState2, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 246, 215, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 116, 4, 0, 0, 226, 60, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 14; - { - const char assign_string[] = { - (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 1140; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + uint32_t remaining() const noexcept { return len_ - offset_; } - while (dummy_rd_ < dummy_wr_) { - process(); - } + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 14) - << "incorrect value for last_msg_.cpu, expected 14, is " << last_msg_.cpu; - { - const char check_string[] = { - (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 1140) - << "incorrect value for last_msg_.stack_free, expected 1140, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState3, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 246, 215, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 196, 19, 0, 0, 90, 169, + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 1; - { - const char assign_string[] = { - (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 5060; + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + uint32_t remaining() const noexcept { return max_len_ - offset_; } - while (dummy_rd_ < dummy_wr_) { - process(); - } + const uint8_t *data() const noexcept { return buf_; } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 1) - << "incorrect value for last_msg_.cpu, expected 1, is " << last_msg_.cpu; - { - const char check_string[] = { - (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 5060) - << "incorrect value for last_msg_.stack_free, expected 5060, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + uint32_t len() const noexcept { return offset_; } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState4, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 246, 215, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 20, 9, 0, 0, 47, 75, + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 7; - { - const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)97, - (char)99, (char)113, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 2324; + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + std::vector outputs{}; - while (dummy_rd_ < dummy_wr_) { - process(); - } + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_thread_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 7) - << "incorrect value for last_msg_.cpu, expected 7, is " << last_msg_.cpu; - { - const char check_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)97, - (char)99, (char)113, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 2324) - << "incorrect value for last_msg_.stack_free, expected 2324, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgThreadState, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState5, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 109, 97, 105, 110, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 148, 9, 0, 0, 195, 212, + struct Output final { + uint16_t sender_id; + sbp_msg_thread_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgThreadState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->thread_state, + sizeof(msg->thread_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 0; - { - const char assign_string[] = { - (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 2452; + struct TestMsgInfo { + sbp_msg_thread_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } - while (dummy_rd_ < dummy_wr_) { - process(); - } + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 0) - << "incorrect value for last_msg_.cpu, expected 0, is " << last_msg_.cpu; - { - const char check_string[] = { - (char)109, (char)97, (char)105, (char)110, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 2452) - << "incorrect value for last_msg_.stack_free, expected 2452, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState6 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState6() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.thread_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgThreadState); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x367a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_thread_state_t &lesser, + const sbp_msg_thread_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState6, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 105, 100, 108, 101, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 1, 36, 0, 0, 0, 225, 18, - }; + EXPECT_EQ(sbp_msg_thread_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_thread_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_thread_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_thread_state_cmp(&greater, &lesser), 0); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 484; - { - const char assign_string[] = { - (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgThreadState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgThreadState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - test_msg.stack_free = 36; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } - while (dummy_rd_ < dummy_wr_) { - process(); + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 484) - << "incorrect value for last_msg_.cpu, expected 484, is " - << last_msg_.cpu; - { - const char check_string[] = { - (char)105, (char)100, (char)108, (char)101, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 36) - << "incorrect value for last_msg_.stack_free, expected 36, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState7 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState7() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; + private: + sbp_msg_thread_state_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, + 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 9, 0, 0, 122, 54, + }; + uint8_t encoded_payload_[26] = { + 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, 107, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 9, 0, 0, + }; }; -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState7, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 78, 65, 80, 32, 73, 83, 82, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 138, 1, 92, 7, 0, 0, 166, 116, - }; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_thread_state_encoded_len(&info.test_msg), info.payload_len); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 394; - { - const char assign_string[] = { - (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); - } - test_msg.stack_free = 1884; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgThreadState, &info.test_msg_wrapped), + info.payload_len); +} - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); - while (dummy_rd_ < dummy_wr_) { - process(); - } + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgThreadState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 394) - << "incorrect value for last_msg_.cpu, expected 394, is " - << last_msg_.cpu; - { - const char check_string[] = { - (char)78, (char)65, (char)80, (char)32, (char)73, (char)83, (char)82, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 1884) - << "incorrect value for last_msg_.stack_free, expected 1884, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState8 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState8() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ(sbp_msg_thread_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState8, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 83, 66, 80, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 4, 12, 0, 0, 229, 174, - }; + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 1; - { - const char assign_string[] = { - (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgThreadState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + EXPECT_EQ(sbp_msg_thread_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_thread_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); } - test_msg.stack_free = 3076; +} - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 1) - << "incorrect value for last_msg_.cpu, expected 1, is " << last_msg_.cpu; - { - const char check_string[] = { - (char)83, (char)66, (char)80, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 3076) - << "incorrect value for last_msg_.stack_free, expected 3076, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState9 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState9() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState9, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 97, 99, 113, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 124, 9, 0, 0, 52, 2, - }; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 10; - { - const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)97, - (char)99, (char)113, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); } - test_msg.stack_free = 2428; - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + sbp_state_t state; + sbp_state_init(&state); - while (dummy_rd_ < dummy_wr_) { - process(); + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 10) - << "incorrect value for last_msg_.cpu, expected 10, is " << last_msg_.cpu; - { - const char check_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)97, - (char)99, (char)113, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 2428) - << "incorrect value for last_msg_.stack_free, expected 2428, is " - << last_msg_.stack_free; -} -class Test_auto_check_sbp_piksi_MsgThreadState10 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgThreadState10() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_thread_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_thread_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_thread_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_piksi_MsgThreadState10, Test) { - uint8_t encoded_frame[] = { - 85, 23, 0, 195, 4, 26, 109, 97, 110, 97, 103, 101, 32, 116, 114, 97, 99, - 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 9, 0, 0, 122, 54, - }; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgThreadState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_thread_state_t test_msg{}; - test_msg.cpu = 0; +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.cpu, greater.cpu); + comparison_tests(lesser, greater); + } + { + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.name, greater.name); + comparison_tests(lesser, greater); + } { - const char assign_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)116, - (char)114, (char)97, (char)99, (char)107, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - memcpy(test_msg.name, assign_string, sizeof(assign_string)); + sbp_msg_thread_state_t lesser = info.test_msg; + sbp_msg_thread_state_t greater = info.test_msg; + make_lesser_greater(lesser.stack_free, greater.stack_free); + comparison_tests(lesser, greater); } - test_msg.stack_free = 2332; +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgThreadState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_THREAD_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_thread_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_thread_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.thread_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.thread_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_thread_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + sbp::State state{}; + state.set_reader(&reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CppHandler handler{&state}; - while (dummy_rd_ < dummy_wr_) { - process(); + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cpu, 0) - << "incorrect value for last_msg_.cpu, expected 0, is " << last_msg_.cpu; - { - const char check_string[] = {(char)109, (char)97, (char)110, (char)97, - (char)103, (char)101, (char)32, (char)116, - (char)114, (char)97, (char)99, (char)107, - (char)0, (char)0, (char)0, (char)0, - (char)0, (char)0, (char)0, (char)0}; - EXPECT_EQ(memcmp(last_msg_.name, check_string, sizeof(check_string)), 0) - << "incorrect value for last_msg_.name, expected string '" - << check_string << "', is '" << last_msg_.name << "'"; - } - EXPECT_EQ(last_msg_.stack_free, 2332) - << "incorrect value for last_msg_.stack_free, expected 2332, is " - << last_msg_.stack_free; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgThreadState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgThreadState10, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgThreadState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgUartState.cc b/c/test/cpp/auto_check_sbp_piksi_MsgUartState.cc index b5e7f666b1..286cb16b96 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgUartState.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgUartState.cc @@ -16,364 +16,2790 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgUartState0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgUartState0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartState0() { + assign(test_msg_.latency.avg, 319865629); + assign(test_msg_.latency.current, 364253831); + assign(test_msg_.latency.lmax, -611749622); + assign(test_msg_.latency.lmin, 289902239); + assign(test_msg_.obs_period.avg, -1002717658); + assign(test_msg_.obs_period.current, -2080697488); + assign(test_msg_.obs_period.pmax, -1628133123); + assign(test_msg_.obs_period.pmin, 1869323177); + assign(test_msg_.uart_a.crc_error_count, 25177); + assign(test_msg_.uart_a.io_error_count, 47183); + assign(test_msg_.uart_a.rx_buffer_level, 244); + assign(test_msg_.uart_a.rx_throughput, 1853.199951171875); + assign(test_msg_.uart_a.tx_buffer_level, 138); + assign(test_msg_.uart_a.tx_throughput, 7765.2001953125); + assign(test_msg_.uart_b.crc_error_count, 4297); + assign(test_msg_.uart_b.io_error_count, 63847); + assign(test_msg_.uart_b.rx_buffer_level, 161); + assign(test_msg_.uart_b.rx_throughput, 6760.2001953125); + assign(test_msg_.uart_b.tx_buffer_level, 143); + assign(test_msg_.uart_b.tx_throughput, 6441.2001953125); + assign(test_msg_.uart_ftdi.crc_error_count, 38359); + assign(test_msg_.uart_ftdi.io_error_count, 6653); + assign(test_msg_.uart_ftdi.rx_buffer_level, 24); + assign(test_msg_.uart_ftdi.rx_throughput, 2173.199951171875); + assign(test_msg_.uart_ftdi.tx_buffer_level, 218); + assign(test_msg_.uart_ftdi.tx_throughput, 5954.2001953125); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartState, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state, sizeof(msg->uart_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartState); + info.sender_id = 57544; + info.preamble = 0x55; + info.crc = 0xe164; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 74; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_t &lesser, + const sbp_msg_uart_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartState, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartState, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartState, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartState, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_t test_msg_{}; + uint8_t encoded_frame_[74 + 8] = { + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, + 89, 98, 79, 184, 138, 244, 154, 73, 201, 69, 154, 65, 211, 69, + 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, 51, 211, 7, 69, + 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, + 10, 113, 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, + 107, 111, 253, 168, 244, 158, 112, 19, 251, 131, 100, 225, + }; + uint8_t encoded_payload_[74] = { + 154, 169, 242, 69, 102, 166, 231, 68, 89, 98, 79, 184, 138, 244, 154, + 73, 201, 69, 154, 65, 211, 69, 201, 16, 103, 249, 143, 161, 154, 17, + 186, 69, 51, 211, 7, 69, 215, 149, 253, 25, 218, 24, 29, 195, 16, + 19, 159, 142, 71, 17, 10, 113, 137, 219, 135, 18, 182, 21, 38, 190, + 59, 196, 169, 155, 107, 111, 253, 168, 244, 158, 112, 19, 251, 131, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgUartState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + + EXPECT_EQ( + sbp_msg_uart_state_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + + for (uint8_t i = 0; i < 74; i++) { + EXPECT_EQ(sbp_msg_uart_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_uart_state_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.obs_period.avg, greater.obs_period.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.obs_period.current, greater.obs_period.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.obs_period.pmax, greater.obs_period.pmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.obs_period.pmin, greater.obs_period.pmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_t lesser = info.test_msg; + sbp_msg_uart_state_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgUartState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.uart_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[74]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 74); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 74), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 74); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartState1 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartState1() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 24); + assign(test_msg_.uart_a.tx_throughput, 0.8661972284317017); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 40); + assign(test_msg_.uart_b.tx_throughput, 2.9718310832977295); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 1); + assign(test_msg_.uart_ftdi.rx_throughput, 0.035211268812417984); + assign(test_msg_.uart_ftdi.tx_buffer_level, 81); + assign(test_msg_.uart_ftdi.tx_throughput, 5.063380241394043); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x7c47; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 246, 215, 58, 26, 191, 93, 63, 0, 0, 0, 0, + 0, 0, 0, 0, 24, 0, 123, 50, 62, 64, 0, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 54, 7, 162, 64, 177, 57, 16, 61, + 0, 0, 0, 0, 81, 1, 255, 255, 255, 255, 0, 0, 0, 0, + 0, 0, 0, 0, 255, 255, 255, 255, 71, 124, + }; + uint8_t encoded_payload_[58] = { + 26, 191, 93, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 123, + 50, 62, 64, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 54, 7, + 162, 64, 177, 57, 16, 61, 0, 0, 0, 0, 81, 1, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartState2 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgUartState0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgUartState2() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 24); + assign(test_msg_.uart_a.tx_throughput, 0.8746479153633118); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 40); + assign(test_msg_.uart_b.tx_throughput, 2.995774745941162); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 1); + assign(test_msg_.uart_ftdi.rx_throughput, 0.35211268067359924); + assign(test_msg_.uart_ftdi.tx_buffer_level, 85); + assign(test_msg_.uart_ftdi.tx_throughput, 6.7901411056518555); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_piksi_MsgUartState0, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 246, 215, 58, 26, 191, 93, 63, 0, 0, 0, 0, - 0, 0, 0, 0, 24, 0, 123, 50, 62, 64, 0, 0, 0, 0, - 0, 0, 0, 0, 40, 0, 54, 7, 162, 64, 177, 57, 16, 61, - 0, 0, 0, 0, 81, 1, 255, 255, 255, 255, 0, 0, 0, 0, - 0, 0, 0, 0, 255, 255, 255, 255, 71, 124, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 24; - test_msg.uart_a.tx_throughput = 0.8661972284317017; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 40; - test_msg.uart_b.tx_throughput = 2.9718310832977295; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 1; - test_msg.uart_ftdi.rx_throughput = 0.035211268812417984; - test_msg.uart_ftdi.tx_buffer_level = 81; - test_msg.uart_ftdi.tx_throughput = 5.063380241394043; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 24) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 24, " - "is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.866197228432 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected " - "0.866197228432, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 40) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 40, " - "is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 2.9718310833 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected " - "2.9718310833, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 1) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 1, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0352112688124 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected " - "0.0352112688124, is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 81) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "81, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 5.06338024139 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "5.06338024139, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartState1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgUartState1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xf899; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_piksi_MsgUartState1, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { 85, 24, 0, 246, 215, 58, 237, 232, 95, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 198, 186, 63, 64, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 214, 72, 217, 64, 29, 72, 180, 62, 0, 0, 0, 0, 85, 1, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 153, 248, }; + uint8_t encoded_payload_[58] = { + 237, 232, 95, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 198, + 186, 63, 64, 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, 214, 72, + 217, 64, 29, 72, 180, 62, 0, 0, 0, 0, 85, 1, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 24; - test_msg.uart_a.tx_throughput = 0.8746479153633118; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 40; - test_msg.uart_b.tx_throughput = 2.995774745941162; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 1; - test_msg.uart_ftdi.rx_throughput = 0.35211268067359924; - test_msg.uart_ftdi.tx_buffer_level = 85; - test_msg.uart_ftdi.tx_throughput = 6.7901411056518555; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 24) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 24, " - "is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.874647915363 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected " - "0.874647915363, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 40) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 40, " - "is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 2.99577474594 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected " - "2.99577474594, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 1) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 1, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.352112680674 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected " - "0.352112680674, is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 85) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "85, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 6.79014110565 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "6.79014110565, is " - << last_msg_.uart_ftdi.tx_throughput; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); } + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartState2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_MsgUartStateDepA.cc b/c/test/cpp/auto_check_sbp_piksi_MsgUartStateDepA.cc index 141b2283dd..6ea4df737f 100644 --- a/c/test/cpp/auto_check_sbp_piksi_MsgUartStateDepA.cc +++ b/c/test/cpp/auto_check_sbp_piksi_MsgUartStateDepA.cc @@ -16,1053 +16,5542 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_piksi_MsgUartStateDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_piksi_MsgUartStateDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartStateDepA0() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 0); + assign(test_msg_.uart_a.tx_throughput, 0.0); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 0); + assign(test_msg_.uart_b.tx_throughput, 0.0); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 15); + assign(test_msg_.uart_ftdi.tx_throughput, 11.600000381469727); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x5f7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 154, 153, 57, 65, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 247, 5, + }; + uint8_t encoded_payload_[58] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 154, 153, + 57, 65, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartStateDepA1 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartStateDepA1() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 0); + assign(test_msg_.uart_a.tx_throughput, 0.0); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 0); + assign(test_msg_.uart_b.tx_throughput, 0.0); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 0); + assign(test_msg_.uart_ftdi.tx_throughput, 0.06599999964237213); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6e41; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 43, 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 65, 110, + }; + uint8_t encoded_payload_[58] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 43, + 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartStateDepA2 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartStateDepA2() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 0); + assign(test_msg_.uart_a.tx_throughput, 0.0); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 0); + assign(test_msg_.uart_b.tx_throughput, 0.0); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 10); + assign(test_msg_.uart_ftdi.tx_throughput, 0.13899999856948853); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x24c6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 4, 86, 14, 62, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 198, 36, + }; + uint8_t encoded_payload_[58] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 86, + 14, 62, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartStateDepA3 : public ::testing::Test { + public: + Testauto_check_sbp_piksi_MsgUartStateDepA3() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 0); + assign(test_msg_.uart_a.tx_throughput, 0.0); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 0); + assign(test_msg_.uart_b.tx_throughput, 0.0); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 0); + assign(test_msg_.uart_ftdi.tx_throughput, 0.06599999964237213); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6e41; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 2, 43, 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 65, 110, + }; + uint8_t encoded_payload_[58] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 43, + 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartStateDepA4 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgUartStateDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgUartStateDepA4() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.008196720853447914); + assign(test_msg_.uart_a.tx_buffer_level, 0); + assign(test_msg_.uart_a.tx_throughput, 0.0); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 2); + assign(test_msg_.uart_b.tx_throughput, 0.09836065769195557); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 38); + assign(test_msg_.uart_ftdi.tx_throughput, 0.49399998784065247); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6f70; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { + 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 138, 75, 6, 60, + 0, 0, 0, 0, 0, 0, 80, 113, 201, 61, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, 145, 237, 252, 62, 0, 0, 0, 0, + 0, 0, 0, 0, 38, 0, 255, 255, 255, 255, 0, 0, 0, 0, + 0, 0, 0, 0, 255, 255, 255, 255, 112, 111, + }; + uint8_t encoded_payload_[58] = { + 0, 0, 0, 0, 138, 75, 6, 60, 0, 0, 0, 0, 0, 0, 80, + 113, 201, 61, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 145, 237, + 252, 62, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 154, 153, 57, 65, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 255, 255, 255, - 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 247, 5, - }; +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 0; - test_msg.uart_a.tx_throughput = 0.0; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 0; - test_msg.uart_b.tx_throughput = 0.0; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 15; - test_msg.uart_ftdi.tx_throughput = 11.600000381469727; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 0, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected 0.0, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 0, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected 0.0, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 15) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "15, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 11.6000003815 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "11.6000003815, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartStateDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_piksi_MsgUartStateDepA5 : public ::testing::Test { public: - Test_auto_check_sbp_piksi_MsgUartStateDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_piksi_MsgUartStateDepA5() { + assign(test_msg_.latency.avg, -1); + assign(test_msg_.latency.current, -1); + assign(test_msg_.latency.lmax, 0); + assign(test_msg_.latency.lmin, 0); + assign(test_msg_.uart_a.crc_error_count, 0); + assign(test_msg_.uart_a.io_error_count, 0); + assign(test_msg_.uart_a.rx_buffer_level, 0); + assign(test_msg_.uart_a.rx_throughput, 0.0); + assign(test_msg_.uart_a.tx_buffer_level, 2); + assign(test_msg_.uart_a.tx_throughput, 0.012000000104308128); + assign(test_msg_.uart_b.crc_error_count, 0); + assign(test_msg_.uart_b.io_error_count, 0); + assign(test_msg_.uart_b.rx_buffer_level, 0); + assign(test_msg_.uart_b.rx_throughput, 0.0); + assign(test_msg_.uart_b.tx_buffer_level, 2); + assign(test_msg_.uart_b.tx_throughput, 0.012000000104308128); + assign(test_msg_.uart_ftdi.crc_error_count, 0); + assign(test_msg_.uart_ftdi.io_error_count, 0); + assign(test_msg_.uart_ftdi.rx_buffer_level, 0); + assign(test_msg_.uart_ftdi.rx_throughput, 0.0); + assign(test_msg_.uart_ftdi.tx_buffer_level, 50); + assign(test_msg_.uart_ftdi.tx_throughput, 1.315000057220459); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 43, 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, - 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 65, 110, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 0; - test_msg.uart_a.tx_throughput = 0.0; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 0; - test_msg.uart_b.tx_throughput = 0.0; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 0; - test_msg.uart_ftdi.tx_throughput = 0.06599999964237213; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 0, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected 0.0, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 0, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected 0.0, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 0.0659999996424 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "0.0659999996424, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartStateDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgUartStateDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 86, 14, 62, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 255, 255, 255, - 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 198, 36, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 0; - test_msg.uart_a.tx_throughput = 0.0; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 0; - test_msg.uart_b.tx_throughput = 0.0; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 10; - test_msg.uart_ftdi.tx_throughput = 0.13899999856948853; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 0, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected 0.0, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 0, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected 0.0, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 10) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "10, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 0.138999998569 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "0.138999998569, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartStateDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgUartStateDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 43, 135, 61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, - 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 65, 110, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 0; - test_msg.uart_a.tx_throughput = 0.0; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 0; - test_msg.uart_b.tx_throughput = 0.0; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 0; - test_msg.uart_ftdi.tx_throughput = 0.06599999964237213; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 0, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected 0.0, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 0, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected 0.0, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 0.0659999996424 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "0.0659999996424, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartStateDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgUartStateDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 24, 0, 195, 4, 58, 0, 0, 0, 0, 138, 75, 6, 60, - 0, 0, 0, 0, 0, 0, 80, 113, 201, 61, 0, 0, 0, 0, - 0, 0, 0, 0, 2, 0, 145, 237, 252, 62, 0, 0, 0, 0, - 0, 0, 0, 0, 38, 0, 255, 255, 255, 255, 0, 0, 0, 0, - 0, 0, 0, 0, 255, 255, 255, 255, 112, 111, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.008196720853447914; - test_msg.uart_a.tx_buffer_level = 0; - test_msg.uart_a.tx_throughput = 0.0; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 2; - test_msg.uart_b.tx_throughput = 0.09836065769195557; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 38; - test_msg.uart_ftdi.tx_throughput = 0.49399998784065247; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.00819672085345 * 100), - 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected " - "0.00819672085345, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 0, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected 0.0, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 2) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 2, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.098360657692 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected " - "0.098360657692, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 38) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "38, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 0.493999987841 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "0.493999987841, is " - << last_msg_.uart_ftdi.tx_throughput; -} -class Test_auto_check_sbp_piksi_MsgUartStateDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_piksi_MsgUartStateDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_uart_state_depa_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUartStateDepa, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_uart_state_depa_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUartStateDepa); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->uart_state_depa, + sizeof(msg->uart_state_depa)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_uart_state_depa_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.uart_state_depa, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUartStateDepa); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x4816; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 58; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_uart_state_depa_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_uart_state_depa_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_uart_state_depa_t &lesser, + const sbp_msg_uart_state_depa_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_uart_state_depa_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_uart_state_depa_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_uart_state_depa_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUartStateDepa, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_piksi_MsgUartStateDepA5, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_uart_state_depa_t test_msg_{}; + uint8_t encoded_frame_[58 + 8] = { 85, 24, 0, 195, 4, 58, 166, 155, 68, 60, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 166, 155, 68, 60, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 236, 81, 168, 63, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 22, 72, }; + uint8_t encoded_payload_[58] = { + 166, 155, 68, 60, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 166, + 155, 68, 60, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 236, 81, + 168, 63, 0, 0, 0, 0, 0, 0, 0, 0, 50, 0, 255, 255, 255, + 255, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, + }; +}; + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_uart_state_depa_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgUartStateDepa, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgUartStateDepa, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + EXPECT_EQ(sbp_msg_uart_state_depa_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + + for (uint8_t i = 0; i < 58; i++) { + EXPECT_EQ( + sbp_msg_uart_state_depa_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUartStateDepa, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_uart_state_depa_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_uart_state_depa_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUartStateDepa, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.avg, greater.latency.avg); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.current, greater.latency.current); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmax, greater.latency.lmax); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.latency.lmin, greater.latency.lmin); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.crc_error_count, + greater.uart_a.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.io_error_count, + greater.uart_a.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_buffer_level, + greater.uart_a.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.rx_throughput, + greater.uart_a.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_buffer_level, + greater.uart_a.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_a.tx_throughput, + greater.uart_a.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.crc_error_count, + greater.uart_b.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.io_error_count, + greater.uart_b.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_buffer_level, + greater.uart_b.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.rx_throughput, + greater.uart_b.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_buffer_level, + greater.uart_b.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_b.tx_throughput, + greater.uart_b.tx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.crc_error_count, + greater.uart_ftdi.crc_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.io_error_count, + greater.uart_ftdi.io_error_count); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_buffer_level, + greater.uart_ftdi.rx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.rx_throughput, + greater.uart_ftdi.rx_throughput); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_buffer_level, + greater.uart_ftdi.tx_buffer_level); + comparison_tests(lesser, greater); + } + { + sbp_msg_uart_state_depa_t lesser = info.test_msg; + sbp_msg_uart_state_depa_t greater = info.test_msg; + make_lesser_greater(lesser.uart_ftdi.tx_throughput, + greater.uart_ftdi.tx_throughput); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgUartStateDepa); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_UART_STATE_DEPA"); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_uart_state_depa_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_uart_state_depa_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.uart_state_depa, info.test_msg); - sbp_msg_uart_state_depa_t test_msg{}; - test_msg.latency.avg = -1; - test_msg.latency.current = -1; - test_msg.latency.lmax = 0; - test_msg.latency.lmin = 0; - test_msg.uart_a.crc_error_count = 0; - test_msg.uart_a.io_error_count = 0; - test_msg.uart_a.rx_buffer_level = 0; - test_msg.uart_a.rx_throughput = 0.0; - test_msg.uart_a.tx_buffer_level = 2; - test_msg.uart_a.tx_throughput = 0.012000000104308128; - test_msg.uart_b.crc_error_count = 0; - test_msg.uart_b.io_error_count = 0; - test_msg.uart_b.rx_buffer_level = 0; - test_msg.uart_b.rx_throughput = 0.0; - test_msg.uart_b.tx_buffer_level = 2; - test_msg.uart_b.tx_throughput = 0.012000000104308128; - test_msg.uart_ftdi.crc_error_count = 0; - test_msg.uart_ftdi.io_error_count = 0; - test_msg.uart_ftdi.rx_buffer_level = 0; - test_msg.uart_ftdi.rx_throughput = 0.0; - test_msg.uart_ftdi.tx_buffer_level = 50; - test_msg.uart_ftdi.tx_throughput = 1.315000057220459; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.latency.avg, -1) - << "incorrect value for last_msg_.latency.avg, expected -1, is " - << last_msg_.latency.avg; - EXPECT_EQ(last_msg_.latency.current, -1) - << "incorrect value for last_msg_.latency.current, expected -1, is " - << last_msg_.latency.current; - EXPECT_EQ(last_msg_.latency.lmax, 0) - << "incorrect value for last_msg_.latency.lmax, expected 0, is " - << last_msg_.latency.lmax; - EXPECT_EQ(last_msg_.latency.lmin, 0) - << "incorrect value for last_msg_.latency.lmin, expected 0, is " - << last_msg_.latency.lmin; - EXPECT_EQ(last_msg_.uart_a.crc_error_count, 0) - << "incorrect value for last_msg_.uart_a.crc_error_count, expected 0, is " - << last_msg_.uart_a.crc_error_count; - EXPECT_EQ(last_msg_.uart_a.io_error_count, 0) - << "incorrect value for last_msg_.uart_a.io_error_count, expected 0, is " - << last_msg_.uart_a.io_error_count; - EXPECT_EQ(last_msg_.uart_a.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_a.rx_buffer_level, expected 0, is " - << last_msg_.uart_a.rx_buffer_level; - EXPECT_LT((last_msg_.uart_a.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_a.rx_throughput, expected 0.0, is " - << last_msg_.uart_a.rx_throughput; - EXPECT_EQ(last_msg_.uart_a.tx_buffer_level, 2) - << "incorrect value for last_msg_.uart_a.tx_buffer_level, expected 2, is " - << last_msg_.uart_a.tx_buffer_level; - EXPECT_LT((last_msg_.uart_a.tx_throughput * 100 - 0.0120000001043 * 100), - 0.05) - << "incorrect value for last_msg_.uart_a.tx_throughput, expected " - "0.0120000001043, is " - << last_msg_.uart_a.tx_throughput; - EXPECT_EQ(last_msg_.uart_b.crc_error_count, 0) - << "incorrect value for last_msg_.uart_b.crc_error_count, expected 0, is " - << last_msg_.uart_b.crc_error_count; - EXPECT_EQ(last_msg_.uart_b.io_error_count, 0) - << "incorrect value for last_msg_.uart_b.io_error_count, expected 0, is " - << last_msg_.uart_b.io_error_count; - EXPECT_EQ(last_msg_.uart_b.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_b.rx_buffer_level, expected 0, is " - << last_msg_.uart_b.rx_buffer_level; - EXPECT_LT((last_msg_.uart_b.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_b.rx_throughput, expected 0.0, is " - << last_msg_.uart_b.rx_throughput; - EXPECT_EQ(last_msg_.uart_b.tx_buffer_level, 2) - << "incorrect value for last_msg_.uart_b.tx_buffer_level, expected 2, is " - << last_msg_.uart_b.tx_buffer_level; - EXPECT_LT((last_msg_.uart_b.tx_throughput * 100 - 0.0120000001043 * 100), - 0.05) - << "incorrect value for last_msg_.uart_b.tx_throughput, expected " - "0.0120000001043, is " - << last_msg_.uart_b.tx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.crc_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.crc_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.crc_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.io_error_count, 0) - << "incorrect value for last_msg_.uart_ftdi.io_error_count, expected 0, " - "is " - << last_msg_.uart_ftdi.io_error_count; - EXPECT_EQ(last_msg_.uart_ftdi.rx_buffer_level, 0) - << "incorrect value for last_msg_.uart_ftdi.rx_buffer_level, expected 0, " - "is " - << last_msg_.uart_ftdi.rx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.rx_throughput * 100 - 0.0 * 100), 0.05) - << "incorrect value for last_msg_.uart_ftdi.rx_throughput, expected 0.0, " - "is " - << last_msg_.uart_ftdi.rx_throughput; - EXPECT_EQ(last_msg_.uart_ftdi.tx_buffer_level, 50) - << "incorrect value for last_msg_.uart_ftdi.tx_buffer_level, expected " - "50, is " - << last_msg_.uart_ftdi.tx_buffer_level; - EXPECT_LT((last_msg_.uart_ftdi.tx_throughput * 100 - 1.31500005722 * 100), - 0.05) - << "incorrect value for last_msg_.uart_ftdi.tx_throughput, expected " - "1.31500005722, is " - << last_msg_.uart_ftdi.tx_throughput; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.uart_state_depa, info.test_msg); } + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[58]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 58); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 58), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_uart_state_depa_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 58); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUartStateDepa, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_piksi_MsgUartStateDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgUartStateDepa, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_piksi_piksi_structs.cc b/c/test/cpp/auto_check_sbp_piksi_piksi_structs.cc new file mode 100644 index 0000000000..81b6395ba7 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_piksi_piksi_structs.cc @@ -0,0 +1,408 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_piksi_structs.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_piksi_piksi_structs0 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_piksi_piksi_structs0() { + assign(test_struct_.crc_error_count, 4092); + assign(test_struct_.io_error_count, 53609); + assign(test_struct_.rx_buffer_level, 172); + assign(test_struct_.rx_throughput, 1132.199951); + assign(test_struct_.tx_buffer_level, 154); + assign(test_struct_.tx_throughput, 9820.200195); + } + + struct TestStructInfo { + sbp_uart_channel_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_uart_channel_t test_struct_{}; + uint8_t encoded_data_[14] = { + 205, 112, 25, 70, 102, 134, 141, 68, 252, 15, 105, 209, 154, 172, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_uart_channel_encoded_len(&info.test_struct), 14); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[14]; + EXPECT_EQ(sbp_uart_channel_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + EXPECT_EQ( + sbp_uart_channel_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 14), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_uart_channel_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_uart_channel_t t{}; + EXPECT_EQ(sbp_uart_channel_decode(info.encoded_data, 14, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_uart_channel_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_uart_channel_t t{}; + EXPECT_EQ(sbp_uart_channel_decode(info.encoded_data, 14, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_uart_channel_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs0, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_uart_channel_t t{}; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_uart_channel_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_piksi_piksi_structs1 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_piksi_piksi_structs1() { + assign(test_struct_.avg, 983064568); + assign(test_struct_.current, -80492514); + assign(test_struct_.pmax, 1099066158); + assign(test_struct_.pmin, -1233728064); + } + + struct TestStructInfo { + sbp_period_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_period_t test_struct_{}; + uint8_t encoded_data_[16] = { + 248, 95, 152, 58, 192, 205, 118, 182, 46, 107, 130, 65, 30, 200, 51, 251, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_period_encoded_len(&info.test_struct), 16); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[16]; + EXPECT_EQ( + sbp_period_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + EXPECT_EQ(sbp_period_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 16), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_period_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_period_t t{}; + EXPECT_EQ(sbp_period_decode(info.encoded_data, 16, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_period_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_period_t t{}; + EXPECT_EQ(sbp_period_decode(info.encoded_data, 16, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_period_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs1, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_period_t t{}; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_period_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_piksi_piksi_structs2 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_piksi_piksi_structs2() { + assign(test_struct_.avg, -2108990172); + assign(test_struct_.current, 419199087); + assign(test_struct_.lmax, 346613123); + assign(test_struct_.lmin, 700673711); + } + + struct TestStructInfo { + sbp_latency_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_latency_t test_struct_{}; + uint8_t encoded_data_[16] = { + 36, 93, 75, 130, 175, 110, 195, 41, 131, 229, 168, 20, 111, 120, 252, 24, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_latency_encoded_len(&info.test_struct), 16); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[16]; + EXPECT_EQ( + sbp_latency_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 16); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + EXPECT_EQ( + sbp_latency_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 16), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[16]; + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_latency_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_latency_t t{}; + EXPECT_EQ(sbp_latency_decode(info.encoded_data, 16, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_latency_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_latency_t t{}; + EXPECT_EQ(sbp_latency_decode(info.encoded_data, 16, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_latency_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs2, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_latency_t t{}; + + for (uint8_t i = 0; i < 16; i++) { + EXPECT_EQ(sbp_latency_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_piksi_piksi_structs3 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_piksi_piksi_structs3() { + assign(test_struct_.duration, 126555400413); + { + const char assign_string[] = {(char)105, (char)102, (char)48}; + memcpy(test_struct_.interface_name, assign_string, sizeof(assign_string)); + } + assign(test_struct_.rx_bytes, 2785204760); + assign(test_struct_.total_bytes, 149958941973); + assign(test_struct_.tx_bytes, 1462542650); + } + + struct TestStructInfo { + sbp_network_usage_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_network_usage_t test_struct_{}; + uint8_t encoded_data_[40] = { + 221, 40, 74, 119, 29, 0, 0, 0, 21, 221, 63, 234, 34, 0, + 0, 0, 24, 218, 2, 166, 58, 161, 44, 87, 105, 102, 48, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_network_usage_encoded_len(&info.test_struct), 40); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[40]; + EXPECT_EQ(sbp_network_usage_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 40); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[40]; + EXPECT_EQ(sbp_network_usage_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 40), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[40]; + for (uint8_t i = 0; i < 40; i++) { + EXPECT_EQ(sbp_network_usage_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_network_usage_t t{}; + EXPECT_EQ(sbp_network_usage_decode(info.encoded_data, 40, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_network_usage_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_network_usage_t t{}; + EXPECT_EQ(sbp_network_usage_decode(info.encoded_data, 40, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_network_usage_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_piksi_piksi_structs3, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_network_usage_t t{}; + + for (uint8_t i = 0; i < 40; i++) { + EXPECT_EQ(sbp_network_usage_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_sbas_MsgSbasRaw.cc b/c/test/cpp/auto_check_sbp_sbas_MsgSbasRaw.cc index 0349576f51..daf81bdbc5 100644 --- a/c/test/cpp/auto_check_sbp_sbas_MsgSbasRaw.cc +++ b/c/test/cpp/auto_check_sbp_sbas_MsgSbasRaw.cc @@ -16,234 +16,1011 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_sbas_MsgSbasRaw0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_sbas_MsgSbasRaw0 : public ::testing::Test { public: - Test_auto_check_sbp_sbas_MsgSbasRaw0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_sbas_MsgSbasRaw0() { + assign(test_msg_.data[0], 23); + + assign(test_msg_.data[1], 255); + + assign(test_msg_.data[2], 0); + + assign(test_msg_.data[3], 23); + + assign(test_msg_.data[4], 255); + + assign(test_msg_.data[5], 0); + + assign(test_msg_.data[6], 23); + + assign(test_msg_.data[7], 255); + + assign(test_msg_.data[8], 127); + + assign(test_msg_.data[9], 240); + + assign(test_msg_.data[10], 2); + + assign(test_msg_.data[11], 255); + + assign(test_msg_.data[12], 192); + + assign(test_msg_.data[13], 3); + + assign(test_msg_.data[14], 127); + + assign(test_msg_.data[15], 247); + + assign(test_msg_.data[16], 255); + + assign(test_msg_.data[17], 127); + + assign(test_msg_.data[18], 247); + + assign(test_msg_.data[19], 255); + + assign(test_msg_.data[20], 229); + + assign(test_msg_.data[21], 229); + + assign(test_msg_.data[22], 238); + + assign(test_msg_.data[23], 170); + + assign(test_msg_.data[24], 175); + + assign(test_msg_.data[25], 255); + + assign(test_msg_.data[26], 240); + assign(test_msg_.message_type, 4); + assign(test_msg_.sid.code, 2); + assign(test_msg_.sid.sat, 131); + assign(test_msg_.tow, 501867721); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_sbas_raw_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_sbas_raw_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSbasRaw, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_sbas_raw_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSbasRaw); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->sbas_raw, sizeof(msg->sbas_raw)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_sbas_raw_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.sbas_raw, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSbasRaw); + info.sender_id = 51228; + info.preamble = 0x55; + info.crc = 0xea7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 34; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_sbas_raw_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_sbas_raw_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_sbas_raw_t &lesser, + const sbp_msg_sbas_raw_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_sbas_raw_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_sbas_raw_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_sbas_raw_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_sbas_raw_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSbasRaw, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSbasRaw, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSbasRaw, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSbasRaw, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_sbas_MsgSbasRaw0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_sbas_raw_t test_msg_{}; + uint8_t encoded_frame_[34 + 8] = { 85, 119, 119, 28, 200, 34, 131, 2, 201, 228, 233, 29, 4, 23, 255, 0, 23, 255, 0, 23, 255, 127, 240, 2, 255, 192, 3, 127, 247, 255, 127, 247, 255, 229, 229, 238, 170, 175, 255, 240, 167, 14, }; + uint8_t encoded_payload_[34] = { + 131, 2, 201, 228, 233, 29, 4, 23, 255, 0, 23, 255, + 0, 23, 255, 127, 240, 2, 255, 192, 3, 127, 247, 255, + 127, 247, 255, 229, 229, 238, 170, 175, 255, 240, + }; +}; + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_sbas_raw_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSbasRaw, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_sbas_raw_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgSbasRaw, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + EXPECT_EQ( + sbp_msg_sbas_raw_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + + for (uint8_t i = 0; i < 34; i++) { + EXPECT_EQ(sbp_msg_sbas_raw_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} - sbp_msg_sbas_raw_t test_msg{}; +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sbas_raw_t msg{}; + uint8_t n_read; - test_msg.data[0] = 23; + EXPECT_EQ(sbp_msg_sbas_raw_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); - test_msg.data[1] = 255; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSbasRaw, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_sbas_raw_t msg{}; + + EXPECT_EQ(sbp_msg_sbas_raw_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_sbas_raw_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_sbas_raw_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} - test_msg.data[2] = 0; +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.data[3] = 23; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.data[4] = 255; + CHandler handler{&state}; - test_msg.data[5] = 0; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.data[6] = 23; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.data[7] = 255; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.data[8] = 127; + CHandler handler(&state); - test_msg.data[9] = 240; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.data[10] = 2; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.data[11] = 255; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.data[12] = 192; +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.data[13] = 3; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.data[14] = 127; + CHandler handler{&state}; - test_msg.data[15] = 247; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.data[16] = 255; - - test_msg.data[17] = 127; - - test_msg.data[18] = 247; - - test_msg.data[19] = 255; - - test_msg.data[20] = 229; - - test_msg.data[21] = 229; - - test_msg.data[22] = 238; - - test_msg.data[23] = 170; - - test_msg.data[24] = 175; - - test_msg.data[25] = 255; - - test_msg.data[26] = 240; - test_msg.message_type = 4; - test_msg.sid.code = 2; - test_msg.sid.sat = 131; - test_msg.tow = 501867721; - - EXPECT_EQ(send_message(51228, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 51228); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.data[0], 23) - << "incorrect value for last_msg_.data[0], expected 23, is " - << last_msg_.data[0]; - EXPECT_EQ(last_msg_.data[1], 255) - << "incorrect value for last_msg_.data[1], expected 255, is " - << last_msg_.data[1]; - EXPECT_EQ(last_msg_.data[2], 0) - << "incorrect value for last_msg_.data[2], expected 0, is " - << last_msg_.data[2]; - EXPECT_EQ(last_msg_.data[3], 23) - << "incorrect value for last_msg_.data[3], expected 23, is " - << last_msg_.data[3]; - EXPECT_EQ(last_msg_.data[4], 255) - << "incorrect value for last_msg_.data[4], expected 255, is " - << last_msg_.data[4]; - EXPECT_EQ(last_msg_.data[5], 0) - << "incorrect value for last_msg_.data[5], expected 0, is " - << last_msg_.data[5]; - EXPECT_EQ(last_msg_.data[6], 23) - << "incorrect value for last_msg_.data[6], expected 23, is " - << last_msg_.data[6]; - EXPECT_EQ(last_msg_.data[7], 255) - << "incorrect value for last_msg_.data[7], expected 255, is " - << last_msg_.data[7]; - EXPECT_EQ(last_msg_.data[8], 127) - << "incorrect value for last_msg_.data[8], expected 127, is " - << last_msg_.data[8]; - EXPECT_EQ(last_msg_.data[9], 240) - << "incorrect value for last_msg_.data[9], expected 240, is " - << last_msg_.data[9]; - EXPECT_EQ(last_msg_.data[10], 2) - << "incorrect value for last_msg_.data[10], expected 2, is " - << last_msg_.data[10]; - EXPECT_EQ(last_msg_.data[11], 255) - << "incorrect value for last_msg_.data[11], expected 255, is " - << last_msg_.data[11]; - EXPECT_EQ(last_msg_.data[12], 192) - << "incorrect value for last_msg_.data[12], expected 192, is " - << last_msg_.data[12]; - EXPECT_EQ(last_msg_.data[13], 3) - << "incorrect value for last_msg_.data[13], expected 3, is " - << last_msg_.data[13]; - EXPECT_EQ(last_msg_.data[14], 127) - << "incorrect value for last_msg_.data[14], expected 127, is " - << last_msg_.data[14]; - EXPECT_EQ(last_msg_.data[15], 247) - << "incorrect value for last_msg_.data[15], expected 247, is " - << last_msg_.data[15]; - EXPECT_EQ(last_msg_.data[16], 255) - << "incorrect value for last_msg_.data[16], expected 255, is " - << last_msg_.data[16]; - EXPECT_EQ(last_msg_.data[17], 127) - << "incorrect value for last_msg_.data[17], expected 127, is " - << last_msg_.data[17]; - EXPECT_EQ(last_msg_.data[18], 247) - << "incorrect value for last_msg_.data[18], expected 247, is " - << last_msg_.data[18]; - EXPECT_EQ(last_msg_.data[19], 255) - << "incorrect value for last_msg_.data[19], expected 255, is " - << last_msg_.data[19]; - EXPECT_EQ(last_msg_.data[20], 229) - << "incorrect value for last_msg_.data[20], expected 229, is " - << last_msg_.data[20]; - EXPECT_EQ(last_msg_.data[21], 229) - << "incorrect value for last_msg_.data[21], expected 229, is " - << last_msg_.data[21]; - EXPECT_EQ(last_msg_.data[22], 238) - << "incorrect value for last_msg_.data[22], expected 238, is " - << last_msg_.data[22]; - EXPECT_EQ(last_msg_.data[23], 170) - << "incorrect value for last_msg_.data[23], expected 170, is " - << last_msg_.data[23]; - EXPECT_EQ(last_msg_.data[24], 175) - << "incorrect value for last_msg_.data[24], expected 175, is " - << last_msg_.data[24]; - EXPECT_EQ(last_msg_.data[25], 255) - << "incorrect value for last_msg_.data[25], expected 255, is " - << last_msg_.data[25]; - EXPECT_EQ(last_msg_.data[26], 240) - << "incorrect value for last_msg_.data[26], expected 240, is " - << last_msg_.data[26]; - EXPECT_EQ(last_msg_.message_type, 4) - << "incorrect value for last_msg_.message_type, expected 4, is " - << last_msg_.message_type; - EXPECT_EQ(last_msg_.sid.code, 2) - << "incorrect value for last_msg_.sid.code, expected 2, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.sat, 131) - << "incorrect value for last_msg_.sid.sat, expected 131, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.tow, 501867721) - << "incorrect value for last_msg_.tow, expected 501867721, is " - << last_msg_.tow; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_sbas_raw_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSbasRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSbasRaw, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSbasRaw, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[0], greater.data[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[1], greater.data[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[2], greater.data[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[3], greater.data[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[4], greater.data[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[5], greater.data[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[6], greater.data[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[7], greater.data[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[8], greater.data[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[9], greater.data[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[10], greater.data[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[11], greater.data[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[12], greater.data[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[13], greater.data[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[14], greater.data[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[15], greater.data[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[16], greater.data[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[17], greater.data[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[18], greater.data[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[19], greater.data[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[20], greater.data[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[21], greater.data[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[22], greater.data[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[23], greater.data[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[24], greater.data[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[25], greater.data[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.data[26], greater.data[26]); + comparison_tests(lesser, greater); + } + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.message_type, greater.message_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_sbas_raw_t lesser = info.test_msg; + sbp_msg_sbas_raw_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSbasRaw); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_SBAS_RAW"); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_sbas_raw_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_sbas_raw_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.sbas_raw, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.sbas_raw, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[34]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 34); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 34), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sbas_raw_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 34); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSbasRaw, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_sbas_MsgSbasRaw0, SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSbasRaw, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexDone.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexDone.cc index 596be8ccc5..3b14d15a9d 100644 --- a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexDone.cc +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexDone.cc @@ -16,82 +16,755 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexDone0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0 + : public ::testing::Test { public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexDone0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); + Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_done_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_done_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_done_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexDone, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_done_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexDone); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_done, + sizeof(msg->settings_read_by_index_done)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_done_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_done, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexDone); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x3aa3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; } - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_done_t &lesser, + const sbp_msg_settings_read_by_index_done_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_done_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_done_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_done_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexDone, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexDone, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexDone, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexDone, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } } - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_done_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); } - sbp_msg_settings_read_by_index_done_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexDone0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_settings_read_by_index_done_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { 85, 166, 0, 246, 215, 0, 163, 58, }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_done_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexDone, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexDone, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_done_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexDone, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_done_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} - sbp_msg_settings_read_by_index_done_t test_msg{}; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CHandler handler{&state}; - while (dummy_rd_ < dummy_wr_) { - process(); + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_done_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexDone, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexDone, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexDone, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexDone); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_DONE"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_done_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_done_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_done, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_done, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_done_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexDone, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexDone0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexDone, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc new file mode 100644 index 0000000000..1d65eeed34 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc @@ -0,0 +1,809 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0() { + assign(test_msg_.index, 8948); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_req_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_req, + sizeof(msg->settings_read_by_index_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexReq); + info.sender_id = 31610; + info.preamble = 0x55; + info.crc = 0x17eb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 2; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_req_t &lesser, + const sbp_msg_settings_read_by_index_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_req_t test_msg_{}; + uint8_t encoded_frame_[2 + 8] = { + 85, 162, 0, 122, 123, 2, 244, 34, 235, 23, + }; + uint8_t encoded_payload_[2] = { + 244, + 34, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexReq, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[2]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 2), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 2), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[2]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 2), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[2]; + + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_req_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 2); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 2); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_req_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_req_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_req_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_req_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_REQ"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_req_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_req_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[2]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 2), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 2); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexResp.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexResp.cc index fb147e7f3b..336f4a307c 100644 --- a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexResp.cc +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexResp.cc @@ -16,67 +16,381 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0 + : public ::testing::Test { public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0() { + assign(test_msg_.index, 0); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "telemetry_radio")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "configuration_string")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); + EXPECT_EQ( + sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg_), + 76); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_resp, + sizeof(msg->settings_read_by_index_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexResp); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xe9f8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 78; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_settings_read_by_index_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_settings_read_by_index_resp_t &lesser, + const sbp_msg_settings_read_by_index_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_resp_t test_msg_{}; + uint8_t encoded_frame_[78 + 8] = { 85, 167, 0, 246, 215, 78, 0, 0, 116, 101, 108, 101, 109, 101, 116, 114, 121, 95, 114, 97, 100, 105, 111, 0, 99, 111, 110, 102, 105, 103, 117, 114, 97, 116, 105, 111, 110, 95, 115, 116, 114, 105, 110, 103, 0, @@ -84,466 +398,4821 @@ TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp0, Test) { 84, 83, 50, 61, 49, 50, 56, 44, 65, 84, 83, 53, 61, 48, 44, 65, 84, 38, 87, 44, 65, 84, 90, 0, 248, 233, }; + uint8_t encoded_payload_[78] = { + 0, 0, 116, 101, 108, 101, 109, 101, 116, 114, 121, 95, 114, + 97, 100, 105, 111, 0, 99, 111, 110, 102, 105, 103, 117, 114, + 97, 116, 105, 111, 110, 95, 115, 116, 114, 105, 110, 103, 0, + 65, 84, 38, 70, 44, 65, 84, 83, 49, 61, 49, 49, 53, + 44, 65, 84, 83, 50, 61, 49, 50, 56, 44, 65, 84, 83, + 53, 61, 48, 44, 65, 84, 38, 87, 44, 65, 84, 90, 0, + }; +}; - sbp_msg_settings_read_by_index_resp_t test_msg{}; - test_msg.index = 0; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encoded_len(&info.test_msg), + info.payload_len); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "telemetry_radio")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "configuration_string")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg), - 76); - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.index, 0) - << "incorrect value for last_msg_.index, expected 0, is " - << last_msg_.index; - - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&last_msg_), - 76); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 0), - "telemetry_radio"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 1), - "configuration_string"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 2), - "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ"); -} -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + + for (uint8_t i = 0; i < 78; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_settings_read_by_index_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp1, Test) { - uint8_t encoded_frame[] = { - 85, 167, 0, 246, 215, 35, 1, 0, 117, 97, 114, 116, 95, 102, 116, - 100, 105, 0, 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, 117, - 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, 167, 243, - }; + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); - sbp_msg_settings_read_by_index_resp_t test_msg{}; - test_msg.index = 1; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); +} - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "uart_ftdi")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section(&test_msg, - "mode")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section(&test_msg, - "SBP")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "enum:SBP,NMEA")); - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg), - 33); - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.index, 1) - << "incorrect value for last_msg_.index, expected 1, is " - << last_msg_.index; - - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&last_msg_), - 33); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 0), - "uart_ftdi"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 1), - "mode"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 2), - "SBP"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 3), - "enum:SBP,NMEA"); -} -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_by_index_resp_t t{}; + // return sbp_msg_settings_read_by_index_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_settings_read_by_index_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp2, Test) { - uint8_t encoded_frame[] = { - 85, 167, 0, 246, 215, 35, 2, 0, 117, 97, 114, 116, 95, 102, 116, - 100, 105, 0, 115, 98, 112, 95, 109, 101, 115, 115, 97, 103, 101, 95, - 109, 97, 115, 107, 0, 54, 53, 53, 51, 53, 0, 4, 56, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_settings_read_by_index_resp_t test_msg{}; - test_msg.index = 2; + CHandler handler{&state}; - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "uart_ftdi")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "sbp_message_mask")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section(&test_msg, - "65535")); - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg), - 33); - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.index, 2) - << "incorrect value for last_msg_.index, expected 2, is " - << last_msg_.index; - - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&last_msg_), - 33); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 0), - "uart_ftdi"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 1), - "sbp_message_mask"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 2), - "65535"); -} -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_settings_read_by_index_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp3, Test) { - uint8_t encoded_frame[] = { - 85, 167, 0, 246, 215, 29, 3, 0, 117, 97, 114, 116, 95, - 102, 116, 100, 105, 0, 98, 97, 117, 100, 114, 97, 116, 101, - 0, 49, 48, 48, 48, 48, 48, 48, 0, 242, 146, - }; +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[78]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 78); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 78), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 78); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); - sbp_msg_settings_read_by_index_resp_t test_msg{}; - test_msg.index = 3; + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting + : public Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + StringInit) { + sbp_msg_settings_read_by_index_resp_t t{}; + sbp_msg_settings_read_by_index_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + IsValid) { + sbp_msg_settings_read_by_index_resp_t t{}; EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "uart_ftdi")); + &t, "telemetry_radio")); EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "baudrate")); + &t, "configuration_string")); EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "1000000")); - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg), - 27); - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.index, 3) - << "incorrect value for last_msg_.index, expected 3, is " - << last_msg_.index; - - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&last_msg_), - 27); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 0), - "uart_ftdi"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 1), - "baudrate"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 2), - "1000000"); -} -class Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + &t, "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 76); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + SpaceRemaining) { + sbp_msg_settings_read_by_index_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "telemetry_radio")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "configuration_string")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 76); + size_t assigned_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections( + &info.test_msg), + 3); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + AddSectionPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "telemetry_radio")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "configuration_string")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "telemetry_radio"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "configuration_string"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + AddSectionVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "telemetry_radio")); } - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_settings_read_by_index_resp_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_settings_read_by_index_resp_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "configuration_string")); + } -TEST_F(Test_auto_check_sbp_settings_MsgSettingsReadByIndexResp4, Test) { - uint8_t encoded_frame[] = { - 85, 167, 0, 246, 215, 36, 4, 0, 117, 97, 114, 116, 95, 117, 97, - 114, 116, 97, 0, 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, - 117, 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, 22, 4, - }; + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); + } - sbp_msg_settings_read_by_index_resp_t test_msg{}; - test_msg.index = 4; + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "uart_uarta")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section(&test_msg, - "mode")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section(&test_msg, - "SBP")); - EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( - &test_msg, "enum:SBP,NMEA")); - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg), - 34); - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.index, 4) - << "incorrect value for last_msg_.index, expected 4, is " - << last_msg_.index; - - EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&last_msg_), - 34); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 0), - "uart_uarta"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 1), - "mode"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 2), - "SBP"); - EXPECT_STREQ( - sbp_msg_settings_read_by_index_resp_setting_get_section(&last_msg_, 3), - "enum:SBP,NMEA"); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "telemetry_radio"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "configuration_string"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + Append) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "telemetry_radio"; + char part2[] = "telemetry_radio"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "telemetry_radio"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + AppendPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "telemetry_radio"; + char part2[] = "telemetry_radio"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "telemetry_radio"); } + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + AppendVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "telemetry_radio"; + char part2[] = "telemetry_radio"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "telemetry_radio"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp0_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 0), + strlen("telemetry_radio")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 1), + strlen("configuration_string")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 2), + strlen("AT&F,ATS1=115,ATS2=128,ATS5=0,AT&W,ATZ")); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1() { + assign(test_msg_.index, 1); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "uart_ftdi")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "mode")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "enum:SBP,NMEA")); + EXPECT_EQ( + sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg_), + 33); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_resp, + sizeof(msg->settings_read_by_index_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexResp); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xf3a7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 35; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_resp_t &lesser, + const sbp_msg_settings_read_by_index_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_resp_t test_msg_{}; + uint8_t encoded_frame_[35 + 8] = { + 85, 167, 0, 246, 215, 35, 1, 0, 117, 97, 114, 116, 95, 102, 116, + 100, 105, 0, 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, 117, + 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, 167, 243, + }; + uint8_t encoded_payload_[35] = { + 1, 0, 117, 97, 114, 116, 95, 102, 116, 100, 105, 0, + 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, 117, + 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_by_index_resp_t t{}; + // return sbp_msg_settings_read_by_index_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting + : public Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + StringInit) { + sbp_msg_settings_read_by_index_resp_t t{}; + sbp_msg_settings_read_by_index_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + IsValid) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "mode")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "enum:SBP,NMEA")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 33); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + SpaceRemaining) { + sbp_msg_settings_read_by_index_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "mode")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "enum:SBP,NMEA")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 33); + size_t assigned_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections( + &info.test_msg), + 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + AddSectionPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "uart_ftdi")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "mode")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "SBP")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "enum:SBP,NMEA")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "mode"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "SBP"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 3), + "enum:SBP,NMEA"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + AddSectionVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "uart_ftdi")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "mode")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "SBP")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum:SBP,NMEA")); + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "mode"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "SBP"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 3), + "enum:SBP,NMEA"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + Append) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + AppendPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + AppendVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp1_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 0), + strlen("uart_ftdi")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 1), + strlen("mode")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 2), + strlen("SBP")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 3), + strlen("enum:SBP,NMEA")); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2() { + assign(test_msg_.index, 2); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "uart_ftdi")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "sbp_message_mask")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "65535")); + EXPECT_EQ( + sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg_), + 33); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_resp, + sizeof(msg->settings_read_by_index_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexResp); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x3804; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 35; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_resp_t &lesser, + const sbp_msg_settings_read_by_index_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_resp_t test_msg_{}; + uint8_t encoded_frame_[35 + 8] = { + 85, 167, 0, 246, 215, 35, 2, 0, 117, 97, 114, 116, 95, 102, 116, + 100, 105, 0, 115, 98, 112, 95, 109, 101, 115, 115, 97, 103, 101, 95, + 109, 97, 115, 107, 0, 54, 53, 53, 51, 53, 0, 4, 56, + }; + uint8_t encoded_payload_[35] = { + 2, 0, 117, 97, 114, 116, 95, 102, 116, 100, 105, 0, + 115, 98, 112, 95, 109, 101, 115, 115, 97, 103, 101, 95, + 109, 97, 115, 107, 0, 54, 53, 53, 51, 53, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_by_index_resp_t t{}; + // return sbp_msg_settings_read_by_index_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[35]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 35), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 35); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting + : public Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + StringInit) { + sbp_msg_settings_read_by_index_resp_t t{}; + sbp_msg_settings_read_by_index_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + IsValid) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "sbp_message_mask")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "65535")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 33); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + SpaceRemaining) { + sbp_msg_settings_read_by_index_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "sbp_message_mask")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "65535")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 33); + size_t assigned_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections( + &info.test_msg), + 3); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + AddSectionPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "uart_ftdi")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "sbp_message_mask")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "65535")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "sbp_message_mask"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "65535"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + AddSectionVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "uart_ftdi")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "sbp_message_mask")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "65535")); + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "sbp_message_mask"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "65535"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + Append) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + AppendPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + AppendVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp2_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 0), + strlen("uart_ftdi")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 1), + strlen("sbp_message_mask")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 2), + strlen("65535")); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3() { + assign(test_msg_.index, 3); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "uart_ftdi")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "baudrate")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "1000000")); + EXPECT_EQ( + sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg_), + 27); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_resp, + sizeof(msg->settings_read_by_index_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexResp); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x92f2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 29; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_resp_t &lesser, + const sbp_msg_settings_read_by_index_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_resp_t test_msg_{}; + uint8_t encoded_frame_[29 + 8] = { + 85, 167, 0, 246, 215, 29, 3, 0, 117, 97, 114, 116, 95, + 102, 116, 100, 105, 0, 98, 97, 117, 100, 114, 97, 116, 101, + 0, 49, 48, 48, 48, 48, 48, 48, 0, 242, 146, + }; + uint8_t encoded_payload_[29] = { + 3, 0, 117, 97, 114, 116, 95, 102, 116, 100, 105, 0, 98, 97, 117, + 100, 114, 97, 116, 101, 0, 49, 48, 48, 48, 48, 48, 48, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + for (uint8_t i = 0; i < 29; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_by_index_resp_t t{}; + // return sbp_msg_settings_read_by_index_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting + : public Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + StringInit) { + sbp_msg_settings_read_by_index_resp_t t{}; + sbp_msg_settings_read_by_index_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + IsValid) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "baudrate")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "1000000")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 27); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + SpaceRemaining) { + sbp_msg_settings_read_by_index_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "uart_ftdi")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "baudrate")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "1000000")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 27); + size_t assigned_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections( + &info.test_msg), + 3); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + AddSectionPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "uart_ftdi")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "baudrate")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "1000000")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "baudrate"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "1000000"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + AddSectionVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "uart_ftdi")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "baudrate")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "1000000")); + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "baudrate"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "1000000"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + Append) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + AppendPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + AppendVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_ftdi"; + char part2[] = "uart_ftdi"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_ftdi"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp3_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 0), + strlen("uart_ftdi")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 1), + strlen("baudrate")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 2), + strlen("1000000")); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4() { + assign(test_msg_.index, 4); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "uart_uarta")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "mode")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &test_msg_, "enum:SBP,NMEA")); + EXPECT_EQ( + sbp_msg_settings_read_by_index_resp_setting_encoded_len(&test_msg_), + 34); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_settings_read_by_index_resp_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_settings_read_by_index_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadByIndexResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_by_index_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadByIndexResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_by_index_resp, + sizeof(msg->settings_read_by_index_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_by_index_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_by_index_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadByIndexResp); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x416; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 36; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_by_index_resp_t &lesser, + const sbp_msg_settings_read_by_index_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_by_index_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_by_index_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadByIndexResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_by_index_resp_t test_msg_{}; + uint8_t encoded_frame_[36 + 8] = { + 85, 167, 0, 246, 215, 36, 4, 0, 117, 97, 114, 116, 95, 117, 97, + 114, 116, 97, 0, 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, + 117, 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, 22, 4, + }; + uint8_t encoded_payload_[36] = { + 4, 0, 117, 97, 114, 116, 95, 117, 97, 114, 116, 97, + 0, 109, 111, 100, 101, 0, 83, 66, 80, 0, 101, 110, + 117, 109, 58, 83, 66, 80, 44, 78, 77, 69, 65, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[36]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 36); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 36), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadByIndexResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 36); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 36), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[36]; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 36), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[36]; + + for (uint8_t i = 0; i < 36; i++) { + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 36); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsReadByIndexResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 36); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_by_index_resp_t t{}; + // return sbp_msg_settings_read_by_index_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSettingsReadByIndexResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_read_by_index_resp_t lesser = info.test_msg; + sbp_msg_settings_read_by_index_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadByIndexResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_BY_INDEX_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_by_index_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_read_by_index_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_by_index_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_read_by_index_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[36]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 36); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 36), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_by_index_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 36); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadByIndexResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting + : public Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + StringInit) { + sbp_msg_settings_read_by_index_resp_t t{}; + sbp_msg_settings_read_by_index_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + IsValid) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "uart_uarta")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "mode")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "enum:SBP,NMEA")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 34); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + SpaceRemaining) { + sbp_msg_settings_read_by_index_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "uart_uarta")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "mode")); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_add_section(&t, "SBP")); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section( + &t, "enum:SBP,NMEA")); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_encoded_len(&t), 34); + size_t assigned_space_remaining = + sbp_msg_settings_read_by_index_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections( + &info.test_msg), + 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + AddSectionPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "uart_uarta")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "mode")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "SBP")); + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_add_section_printf( + &t, "%s", "enum:SBP,NMEA")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_uarta"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "mode"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "SBP"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 3), + "enum:SBP,NMEA"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + AddSectionVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "uart_uarta")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "mode")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "SBP")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_by_index_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum:SBP,NMEA")); + } + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_uarta"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 1), + "mode"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 2), + "SBP"); + + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 3), + "enum:SBP,NMEA"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + Append) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_uarta"; + char part2[] = "uart_uarta"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE( + sbp_msg_settings_read_by_index_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_uarta"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + AppendPrintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_uarta"; + char part2[] = "uart_uarta"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_read_by_index_resp_setting_append_printf( + &t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_uarta"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + AppendVprintf) { + sbp_msg_settings_read_by_index_resp_t t{}; + + char part1[] = "uart_uarta"; + char part2[] = "uart_uarta"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_by_index_resp_setting_append_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_by_index_resp_setting_get_section(&t, 0), + "uart_uarta"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadByIndexResp4_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 0), + strlen("uart_uarta")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 1), + strlen("mode")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 2), + strlen("SBP")); + + EXPECT_EQ(sbp_msg_settings_read_by_index_resp_setting_section_strlen( + &info.test_msg, 3), + strlen("enum:SBP,NMEA")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc new file mode 100644 index 0000000000..c373addf27 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc @@ -0,0 +1,970 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsReadReq0 : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadReq0() { + EXPECT_TRUE(sbp_msg_settings_read_req_setting_add_section(&test_msg_, + "section-name")); + EXPECT_TRUE(sbp_msg_settings_read_req_setting_add_section(&test_msg_, + "setting-name")); + EXPECT_EQ(sbp_msg_settings_read_req_setting_encoded_len(&test_msg_), 26); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_req_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_read_req_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadReq, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_req_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadReq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_req, + sizeof(msg->settings_read_req)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_req_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_req, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadReq); + info.sender_id = 54936; + info.preamble = 0x55; + info.crc = 0xe4b5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 26; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_req_t &lesser, + const sbp_msg_settings_read_req_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_read_req_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_req_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_req_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_req_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadReq, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadReq, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadReq, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadReq, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_req_t test_msg_{}; + uint8_t encoded_frame_[26 + 8] = { + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + }; + uint8_t encoded_payload_[26] = { + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_req_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSettingsReadReq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_req_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadReq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + EXPECT_EQ(sbp_msg_settings_read_req_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + + for (uint8_t i = 0; i < 26; i++) { + EXPECT_EQ( + sbp_msg_settings_read_req_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_req_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsReadReq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_req_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_req_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_req_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_REQ_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_req_t t{}; return + // sbp_msg_settings_read_req_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_req_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_req_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsReadReq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsReadReq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_req_t lesser = info.test_msg; + sbp_msg_settings_read_req_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadReq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_REQ"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_req_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_read_req_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_req, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.settings_read_req, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[26]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 26); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 26), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_req_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 26); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadReq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadReq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadReq0_setting + : public Testauto_check_sbp_settings_MsgSettingsReadReq0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, StringInit) { + sbp_msg_settings_read_req_t t{}; + sbp_msg_settings_read_req_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_req_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, IsValid) { + sbp_msg_settings_read_req_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_read_req_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_read_req_setting_add_section(&t, "setting-name")); + EXPECT_EQ(sbp_msg_settings_read_req_setting_encoded_len(&t), 26); + EXPECT_TRUE(sbp_msg_settings_read_req_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, + SpaceRemaining) { + sbp_msg_settings_read_req_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_req_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_read_req_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_read_req_setting_add_section(&t, "setting-name")); + EXPECT_EQ(sbp_msg_settings_read_req_setting_encoded_len(&t), 26); + size_t assigned_space_remaining = + sbp_msg_settings_read_req_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_req_setting_count_sections(&info.test_msg), + 2); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, + AddSectionPrintf) { + sbp_msg_settings_read_req_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_req_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_read_req_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_EQ(sbp_msg_settings_read_req_setting_count_sections(&t), 2); + + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 1), + "setting-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, + AddSectionVprintf) { + sbp_msg_settings_read_req_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_req_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_req_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + EXPECT_EQ(sbp_msg_settings_read_req_setting_count_sections(&t), 2); + + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 1), + "setting-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, Append) { + sbp_msg_settings_read_req_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_req_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_settings_read_req_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, AppendPrintf) { + sbp_msg_settings_read_req_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_req_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_settings_read_req_setting_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, AppendVprintf) { + sbp_msg_settings_read_req_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_req_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_req_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_req_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadReq0_setting, SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_read_req_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ(sbp_msg_settings_read_req_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc new file mode 100644 index 0000000000..7de79badba --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc @@ -0,0 +1,1046 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsReadResp0 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsReadResp0() { + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section(&test_msg_, + "section-name")); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section(&test_msg_, + "setting-name")); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section( + &test_msg_, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section( + &test_msg_, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_read_resp_setting_encoded_len(&test_msg_), 66); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_read_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsReadResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_read_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsReadResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_read_resp, + sizeof(msg->settings_read_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_read_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_read_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsReadResp); + info.sender_id = 61576; + info.preamble = 0x55; + info.crc = 0xc7cb; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_read_resp_t &lesser, + const sbp_msg_settings_read_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_read_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_read_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_read_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_read_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsReadResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsReadResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsReadResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_read_resp_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, + 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, + 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, + 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, + 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 203, 199, + }; + uint8_t encoded_payload_[66] = { + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, + 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, + 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, + 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSettingsReadResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_read_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsReadResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_settings_read_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ( + sbp_msg_settings_read_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_read_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsReadResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_read_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_READ_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_read_resp_t t{}; return + // sbp_msg_settings_read_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_read_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_read_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsReadResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsReadResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_read_resp_t lesser = info.test_msg; + sbp_msg_settings_read_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsReadResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_READ_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_read_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_read_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_read_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.settings_read_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_read_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsReadResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsReadResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsReadResp0_setting + : public Testauto_check_sbp_settings_MsgSettingsReadResp0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, StringInit) { + sbp_msg_settings_read_resp_t t{}; + sbp_msg_settings_read_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, IsValid) { + sbp_msg_settings_read_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_read_resp_setting_encoded_len(&t), 66); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + SpaceRemaining) { + sbp_msg_settings_read_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_read_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_read_resp_setting_encoded_len(&t), 66); + size_t assigned_space_remaining = + sbp_msg_settings_read_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_read_resp_setting_count_sections(&info.test_msg), + 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + AddSectionPrintf) { + sbp_msg_settings_read_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section_printf( + &t, "%s", "setting-value")); + + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_add_section_printf( + &t, "%s", "enum;value1,value2,value3")); + + EXPECT_EQ(sbp_msg_settings_read_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + AddSectionVprintf) { + sbp_msg_settings_read_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-value")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_read_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum;value1,value2,value3")); + } + + EXPECT_EQ(sbp_msg_settings_read_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, Append) { + sbp_msg_settings_read_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_settings_read_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, AppendPrintf) { + sbp_msg_settings_read_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_settings_read_resp_setting_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + AppendVprintf) { + sbp_msg_settings_read_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_read_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_read_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsReadResp0_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ( + sbp_msg_settings_read_resp_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ( + sbp_msg_settings_read_resp_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); + + EXPECT_EQ( + sbp_msg_settings_read_resp_setting_section_strlen(&info.test_msg, 2), + strlen("setting-value")); + + EXPECT_EQ( + sbp_msg_settings_read_resp_setting_section_strlen(&info.test_msg, 3), + strlen("enum;value1,value2,value3")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc new file mode 100644 index 0000000000..bc0cfeeead --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc @@ -0,0 +1,1040 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsRegister0 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsRegister0() { + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section(&test_msg_, + "section-name")); + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section(&test_msg_, + "setting-name")); + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section(&test_msg_, + "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section( + &test_msg_, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_setting_encoded_len(&test_msg_), 66); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_register_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_register_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsRegister, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_register_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsRegister); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_register, + sizeof(msg->settings_register)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_register_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_register, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsRegister); + info.sender_id = 1620; + info.preamble = 0x55; + info.crc = 0xeb8e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_register_t &lesser, + const sbp_msg_settings_register_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_register_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_register_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_register_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_register_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsRegister, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsRegister, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsRegister, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsRegister, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_register_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, + 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, + 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, + 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, + 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 142, 235, + }; + uint8_t encoded_payload_[66] = { + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, + 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, + 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, + 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_register_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSettingsRegister, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_register_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsRegister, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_settings_register_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ( + sbp_msg_settings_register_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_register_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsRegister, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_t msg{}; + + EXPECT_EQ(sbp_msg_settings_register_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_REGISTER_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_register_t t{}; return + // sbp_msg_settings_register_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_register_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_register_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsRegister, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsRegister, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsRegister, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_register_t lesser = info.test_msg; + sbp_msg_settings_register_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsRegister); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_REGISTER"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_register_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_register_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_register, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.settings_register, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsRegister, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsRegister, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsRegister0_setting + : public Testauto_check_sbp_settings_MsgSettingsRegister0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, StringInit) { + sbp_msg_settings_register_t t{}; + sbp_msg_settings_register_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_register_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, IsValid) { + sbp_msg_settings_register_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_setting_encoded_len(&t), 66); + EXPECT_TRUE(sbp_msg_settings_register_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + SpaceRemaining) { + sbp_msg_settings_register_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_register_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_register_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_setting_encoded_len(&t), 66); + size_t assigned_space_remaining = + sbp_msg_settings_register_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_register_setting_count_sections(&info.test_msg), + 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + AddSectionPrintf) { + sbp_msg_settings_register_t t{}; + + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section_printf( + &t, "%s", "setting-value")); + + EXPECT_TRUE(sbp_msg_settings_register_setting_add_section_printf( + &t, "%s", "enum;value1,value2,value3")); + + EXPECT_EQ(sbp_msg_settings_register_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + AddSectionVprintf) { + sbp_msg_settings_register_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-value")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum;value1,value2,value3")); + } + + EXPECT_EQ(sbp_msg_settings_register_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, Append) { + sbp_msg_settings_register_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_register_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_settings_register_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, AppendPrintf) { + sbp_msg_settings_register_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_register_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_settings_register_setting_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + AppendVprintf) { + sbp_msg_settings_register_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_register_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegister0_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_register_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ(sbp_msg_settings_register_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); + + EXPECT_EQ(sbp_msg_settings_register_setting_section_strlen(&info.test_msg, 2), + strlen("setting-value")); + + EXPECT_EQ(sbp_msg_settings_register_setting_section_strlen(&info.test_msg, 3), + strlen("enum;value1,value2,value3")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc new file mode 100644 index 0000000000..630401c555 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc @@ -0,0 +1,1074 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsRegisterResp0 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsRegisterResp0() { + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &test_msg_, "section-name")); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &test_msg_, "setting-name")); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &test_msg_, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &test_msg_, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_resp_setting_encoded_len(&test_msg_), + 66); + assign(test_msg_.status, 18); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_register_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_register_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsRegisterResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_register_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsRegisterResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_register_resp, + sizeof(msg->settings_register_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_register_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_register_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsRegisterResp); + info.sender_id = 54569; + info.preamble = 0x55; + info.crc = 0x1052; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 67; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_register_resp_t &lesser, + const sbp_msg_settings_register_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_settings_register_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_register_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_register_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_register_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsRegisterResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsRegisterResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsRegisterResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsRegisterResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_register_resp_t test_msg_{}; + uint8_t encoded_frame_[67 + 8] = { + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, 110, 45, + 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, + 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, + 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, + 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 82, 16, + }; + uint8_t encoded_payload_[67] = { + 18, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, + 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, + 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_register_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsRegisterResp, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_register_resp_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsRegisterResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + EXPECT_EQ(sbp_msg_settings_register_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + for (uint8_t i = 0; i < 67; i++) { + EXPECT_EQ(sbp_msg_settings_register_resp_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_register_resp_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSettingsRegisterResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_register_resp_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_REGISTER_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_register_resp_t t{}; + // return sbp_msg_settings_register_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_register_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_register_resp_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsRegisterResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSettingsRegisterResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsRegisterResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_register_resp_t lesser = info.test_msg; + sbp_msg_settings_register_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_register_resp_t lesser = info.test_msg; + sbp_msg_settings_register_resp_t greater = info.test_msg; + make_lesser_greater(lesser.status, greater.status); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsRegisterResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_REGISTER_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_register_resp_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_settings_register_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_register_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_register_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_register_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsRegisterResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsRegisterResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting + : public Testauto_check_sbp_settings_MsgSettingsRegisterResp0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + StringInit) { + sbp_msg_settings_register_resp_t t{}; + sbp_msg_settings_register_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, IsValid) { + sbp_msg_settings_register_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_resp_setting_encoded_len(&t), 66); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + SpaceRemaining) { + sbp_msg_settings_register_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_register_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_register_resp_setting_encoded_len(&t), 66); + size_t assigned_space_remaining = + sbp_msg_settings_register_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp_msg_settings_register_resp_setting_count_sections(&info.test_msg), 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + AddSectionPrintf) { + sbp_msg_settings_register_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section_printf( + &t, "%s", "setting-value")); + + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_add_section_printf( + &t, "%s", "enum;value1,value2,value3")); + + EXPECT_EQ(sbp_msg_settings_register_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + AddSectionVprintf) { + sbp_msg_settings_register_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_register_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_register_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_register_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-value")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_register_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum;value1,value2,value3")); + } + + EXPECT_EQ(sbp_msg_settings_register_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, Append) { + sbp_msg_settings_register_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + AppendPrintf) { + sbp_msg_settings_register_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_settings_register_resp_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + part1); + EXPECT_TRUE(sbp_msg_settings_register_resp_setting_append_printf(&t, "%s", + &part2[1])); + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + AppendVprintf) { + sbp_msg_settings_register_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_register_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_register_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsRegisterResp0_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ( + sbp_msg_settings_register_resp_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ( + sbp_msg_settings_register_resp_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); + + EXPECT_EQ( + sbp_msg_settings_register_resp_setting_section_strlen(&info.test_msg, 2), + strlen("setting-value")); + + EXPECT_EQ( + sbp_msg_settings_register_resp_setting_section_strlen(&info.test_msg, 3), + strlen("enum;value1,value2,value3")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsSave.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsSave.cc new file mode 100644 index 0000000000..af304eeb83 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsSave.cc @@ -0,0 +1,743 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsSave0 : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsSave0() {} + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_save_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_save_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsSave, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_save_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsSave); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_save, + sizeof(msg->settings_save)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_save_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_save, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsSave); + info.sender_id = 57506; + info.preamble = 0x55; + info.crc = 0x437b; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 0; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_save_t &lesser, + const sbp_msg_settings_save_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_save_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_save_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_save_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_save_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSettingsSave, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSettingsSave, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSettingsSave, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSettingsSave, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_save_t test_msg_{}; + uint8_t encoded_frame_[0 + 8] = { + 85, 161, 0, 162, 224, 0, 123, 67, + }; + uint8_t encoded_payload_[1] = {}; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_save_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSettingsSave, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_save_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsSave, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + + EXPECT_EQ(sbp_msg_settings_save_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_save_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_save_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsSave, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_save_t msg{}; + + EXPECT_EQ(sbp_msg_settings_save_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_save_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsSave, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsSave, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsSave, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsSave); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_SAVE"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_save_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_save_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.settings_save, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.settings_save, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[1]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 0); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 0), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_save_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 0); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsSave, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsSave0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsSave, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc new file mode 100644 index 0000000000..35863633c2 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc @@ -0,0 +1,989 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsWrite0 : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsWrite0() { + EXPECT_TRUE( + sbp_msg_settings_write_setting_add_section(&test_msg_, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_write_setting_add_section(&test_msg_, "setting-name")); + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&test_msg_, + "setting-value")); + EXPECT_EQ(sbp_msg_settings_write_setting_encoded_len(&test_msg_), 40); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_write_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_write_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsWrite, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_write_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsWrite); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_write, + sizeof(msg->settings_write)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_write_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_write, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsWrite); + info.sender_id = 123; + info.preamble = 0x55; + info.crc = 0xaf4; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 40; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_write_t &lesser, + const sbp_msg_settings_write_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_write_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_write_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_write_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_write_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSettingsWrite, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsWrite, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSettingsWrite, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSettingsWrite, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_write_t test_msg_{}; + uint8_t encoded_frame_[40 + 8] = { + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + }; + uint8_t encoded_payload_[40] = { + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, + 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_write_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSettingsWrite, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[40]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_write_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 40); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 40), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsWrite, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 40); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 40), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[40]; + + EXPECT_EQ(sbp_msg_settings_write_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 40), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[40]; + + for (uint8_t i = 0; i < 40; i++) { + EXPECT_EQ( + sbp_msg_settings_write_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_write_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 40); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsWrite, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 40); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_t msg{}; + + EXPECT_EQ(sbp_msg_settings_write_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_WRITE_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_write_t t{}; return + // sbp_msg_settings_write_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_write_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_write_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsWrite, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsWrite, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsWrite, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_write_t lesser = info.test_msg; + sbp_msg_settings_write_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsWrite); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_WRITE"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_write_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_write_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.settings_write, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.settings_write, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[40]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 40); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 40), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 40); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsWrite, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsWrite, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsWrite0_setting + : public Testauto_check_sbp_settings_MsgSettingsWrite0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, StringInit) { + sbp_msg_settings_write_t t{}; + sbp_msg_settings_write_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_write_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, IsValid) { + sbp_msg_settings_write_t t{}; + + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "section-name")); + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "setting-name")); + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "setting-value")); + EXPECT_EQ(sbp_msg_settings_write_setting_encoded_len(&t), 40); + EXPECT_TRUE(sbp_msg_settings_write_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, SpaceRemaining) { + sbp_msg_settings_write_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_write_setting_space_remaining(&t); + + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "section-name")); + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "setting-name")); + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section(&t, "setting-value")); + EXPECT_EQ(sbp_msg_settings_write_setting_encoded_len(&t), 40); + size_t assigned_space_remaining = + sbp_msg_settings_write_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_write_setting_count_sections(&info.test_msg), 3); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, + AddSectionPrintf) { + sbp_msg_settings_write_t t{}; + + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_TRUE(sbp_msg_settings_write_setting_add_section_printf( + &t, "%s", "setting-value")); + + EXPECT_EQ(sbp_msg_settings_write_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 2), + "setting-value"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, + AddSectionVprintf) { + sbp_msg_settings_write_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_write_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_write_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_write_setting_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-value")); + } + + EXPECT_EQ(sbp_msg_settings_write_setting_count_sections(&t), 3); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 2), + "setting-value"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, Append) { + sbp_msg_settings_write_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_write_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_settings_write_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, AppendPrintf) { + sbp_msg_settings_write_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_write_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_settings_write_setting_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, AppendVprintf) { + sbp_msg_settings_write_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_write_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWrite0_setting, SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ(sbp_msg_settings_write_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ(sbp_msg_settings_write_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); + + EXPECT_EQ(sbp_msg_settings_write_setting_section_strlen(&info.test_msg, 2), + strlen("setting-value")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc b/c/test/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc new file mode 100644 index 0000000000..1cf432695a --- /dev/null +++ b/c/test/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc @@ -0,0 +1,1057 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_settings_MsgSettingsWriteResp0 + : public ::testing::Test { + public: + Testauto_check_sbp_settings_MsgSettingsWriteResp0() { + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &test_msg_, "section-name")); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &test_msg_, "setting-name")); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &test_msg_, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &test_msg_, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_write_resp_setting_encoded_len(&test_msg_), 66); + assign(test_msg_.status, 152); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_write_resp_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_settings_write_resp_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSettingsWriteResp, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_settings_write_resp_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSettingsWriteResp); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->settings_write_resp, + sizeof(msg->settings_write_resp)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_settings_write_resp_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.settings_write_resp, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSettingsWriteResp); + info.sender_id = 14171; + info.preamble = 0x55; + info.crc = 0x0036; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 67; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_settings_write_resp_t &lesser, + const sbp_msg_settings_write_resp_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_settings_write_resp_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_settings_write_resp_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_settings_write_resp_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_settings_write_resp_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsWriteResp, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSettingsWriteResp, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSettingsWriteResp, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSettingsWriteResp, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_settings_write_resp_t test_msg_{}; + uint8_t encoded_frame_[67 + 8] = { + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, 110, 45, + 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, + 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, + 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, + 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + }; + uint8_t encoded_payload_[67] = { + 152, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, + 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, + 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, + }; +}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_write_resp_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSettingsWriteResp, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_settings_write_resp_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSettingsWriteResp, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + EXPECT_EQ(sbp_msg_settings_write_resp_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + + for (uint8_t i = 0; i < 67; i++) { + EXPECT_EQ( + sbp_msg_settings_write_resp_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_settings_write_resp_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSettingsWriteResp, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_resp_t msg{}; + + EXPECT_EQ(sbp_msg_settings_write_resp_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_resp_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_SETTINGS_WRITE_RESP_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_settings_write_resp_t t{}; return + // sbp_msg_settings_write_resp_encoded_len(&t); }(); + overhead += 1; + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_settings_write_resp_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_settings_write_resp_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsWriteResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSettingsWriteResp, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSettingsWriteResp, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_settings_write_resp_t lesser = info.test_msg; + sbp_msg_settings_write_resp_t greater = info.test_msg; + make_lesser_greater(lesser.setting, greater.setting); + comparison_tests(lesser, greater); + } + { + sbp_msg_settings_write_resp_t lesser = info.test_msg; + sbp_msg_settings_write_resp_t greater = info.test_msg; + make_lesser_greater(lesser.status, greater.status); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSettingsWriteResp); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SETTINGS_WRITE_RESP"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_settings_write_resp_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_settings_write_resp_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.settings_write_resp, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.settings_write_resp, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[67]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 67); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 67), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_settings_write_resp_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 67); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSettingsWriteResp, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSettingsWriteResp, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting + : public Testauto_check_sbp_settings_MsgSettingsWriteResp0 {}; + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, StringInit) { + sbp_msg_settings_write_resp_t t{}; + sbp_msg_settings_write_resp_setting_init(&t); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, IsValid) { + sbp_msg_settings_write_resp_t t{}; + + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_write_resp_setting_encoded_len(&t), 66); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_valid(&t)); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + SpaceRemaining) { + sbp_msg_settings_write_resp_t t{}; + size_t empty_space_remaining = + sbp_msg_settings_write_resp_setting_space_remaining(&t); + + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "section-name")); + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "setting-name")); + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_add_section(&t, "setting-value")); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section( + &t, "enum;value1,value2,value3")); + EXPECT_EQ(sbp_msg_settings_write_resp_setting_encoded_len(&t), 66); + size_t assigned_space_remaining = + sbp_msg_settings_write_resp_setting_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_settings_write_resp_setting_count_sections(&info.test_msg), + 4); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + AddSectionPrintf) { + sbp_msg_settings_write_resp_t t{}; + + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section_printf( + &t, "%s", "section-name")); + + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section_printf( + &t, "%s", "setting-name")); + + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section_printf( + &t, "%s", "setting-value")); + + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_add_section_printf( + &t, "%s", "enum;value1,value2,value3")); + + EXPECT_EQ(sbp_msg_settings_write_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + AddSectionVprintf) { + sbp_msg_settings_write_resp_t t{}; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "section-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-name")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "setting-value")); + } + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_settings_write_resp_setting_add_section_vprintf( + &t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "enum;value1,value2,value3")); + } + + EXPECT_EQ(sbp_msg_settings_write_resp_setting_count_sections(&t), 4); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), + "section-name"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 1), + "setting-name"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 2), + "setting-value"); + + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 3), + "enum;value1,value2,value3"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, Append) { + sbp_msg_settings_write_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_append(&t, part1)); + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), part1); + EXPECT_TRUE(sbp_msg_settings_write_resp_setting_append(&t, &part2[1])); + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + AppendPrintf) { + sbp_msg_settings_write_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_append_printf(&t, "%s", part1)); + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), part1); + EXPECT_TRUE( + sbp_msg_settings_write_resp_setting_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + AppendVprintf) { + sbp_msg_settings_write_resp_t t{}; + + char part1[] = "section-name"; + char part2[] = "section-name"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_write_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_settings_write_resp_setting_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ(sbp_msg_settings_write_resp_setting_get_section(&t, 0), + "section-name"); +} + +TEST_F(Testauto_check_sbp_settings_MsgSettingsWriteResp0_setting, + SectionStrlen) { + auto info = get_test_msg_info(); + + EXPECT_EQ( + sbp_msg_settings_write_resp_setting_section_strlen(&info.test_msg, 0), + strlen("section-name")); + + EXPECT_EQ( + sbp_msg_settings_write_resp_setting_section_strlen(&info.test_msg, 1), + strlen("setting-name")); + + EXPECT_EQ( + sbp_msg_settings_write_resp_setting_section_strlen(&info.test_msg, 2), + strlen("setting-value")); + + EXPECT_EQ( + sbp_msg_settings_write_resp_setting_section_strlen(&info.test_msg, 3), + strlen("enum;value1,value2,value3")); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgCertificateChain.cc b/c/test/cpp/auto_check_sbp_signing_MsgCertificateChain.cc index 0c11ddad02..0b561105cb 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgCertificateChain.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgCertificateChain.cc @@ -16,66 +16,636 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgCertificateChain0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgCertificateChain0 : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgCertificateChain0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgCertificateChain0() { + assign(test_msg_.corrections_certificate[0], 20); + + assign(test_msg_.corrections_certificate[1], 21); + + assign(test_msg_.corrections_certificate[2], 22); + + assign(test_msg_.corrections_certificate[3], 23); + + assign(test_msg_.corrections_certificate[4], 24); + + assign(test_msg_.corrections_certificate[5], 25); + + assign(test_msg_.corrections_certificate[6], 26); + + assign(test_msg_.corrections_certificate[7], 27); + + assign(test_msg_.corrections_certificate[8], 28); + + assign(test_msg_.corrections_certificate[9], 29); + + assign(test_msg_.corrections_certificate[10], 10); + + assign(test_msg_.corrections_certificate[11], 11); + + assign(test_msg_.corrections_certificate[12], 12); + + assign(test_msg_.corrections_certificate[13], 13); + + assign(test_msg_.corrections_certificate[14], 14); + + assign(test_msg_.corrections_certificate[15], 15); + + assign(test_msg_.corrections_certificate[16], 16); + + assign(test_msg_.corrections_certificate[17], 17); + + assign(test_msg_.corrections_certificate[18], 18); + + assign(test_msg_.corrections_certificate[19], 19); + assign(test_msg_.expiration.day, 30); + assign(test_msg_.expiration.hours, 12); + assign(test_msg_.expiration.minutes, 34); + assign(test_msg_.expiration.month, 3); + assign(test_msg_.expiration.ns, 123456789); + assign(test_msg_.expiration.seconds, 59); + assign(test_msg_.expiration.year, 2024); + + assign(test_msg_.intermediate_certificate[0], 10); + + assign(test_msg_.intermediate_certificate[1], 11); + + assign(test_msg_.intermediate_certificate[2], 12); + + assign(test_msg_.intermediate_certificate[3], 13); + + assign(test_msg_.intermediate_certificate[4], 14); + + assign(test_msg_.intermediate_certificate[5], 15); + + assign(test_msg_.intermediate_certificate[6], 16); + + assign(test_msg_.intermediate_certificate[7], 17); + + assign(test_msg_.intermediate_certificate[8], 18); + + assign(test_msg_.intermediate_certificate[9], 19); + + assign(test_msg_.intermediate_certificate[10], 0); + + assign(test_msg_.intermediate_certificate[11], 1); + + assign(test_msg_.intermediate_certificate[12], 2); + + assign(test_msg_.intermediate_certificate[13], 3); + + assign(test_msg_.intermediate_certificate[14], 4); + + assign(test_msg_.intermediate_certificate[15], 5); + + assign(test_msg_.intermediate_certificate[16], 6); + + assign(test_msg_.intermediate_certificate[17], 7); + + assign(test_msg_.intermediate_certificate[18], 8); + + assign(test_msg_.intermediate_certificate[19], 9); + + assign(test_msg_.root_certificate[0], 0); + + assign(test_msg_.root_certificate[1], 1); + + assign(test_msg_.root_certificate[2], 2); + + assign(test_msg_.root_certificate[3], 3); + + assign(test_msg_.root_certificate[4], 4); + + assign(test_msg_.root_certificate[5], 5); + + assign(test_msg_.root_certificate[6], 6); + + assign(test_msg_.root_certificate[7], 7); + + assign(test_msg_.root_certificate[8], 8); + + assign(test_msg_.root_certificate[9], 9); + + assign(test_msg_.root_certificate[10], 10); + + assign(test_msg_.root_certificate[11], 11); + + assign(test_msg_.root_certificate[12], 12); + + assign(test_msg_.root_certificate[13], 13); + + assign(test_msg_.root_certificate[14], 14); + + assign(test_msg_.root_certificate[15], 15); + + assign(test_msg_.root_certificate[16], 16); + + assign(test_msg_.root_certificate[17], 17); + + assign(test_msg_.root_certificate[18], 18); + + assign(test_msg_.root_certificate[19], 19); + + assign(test_msg_.signature.data[0], 0); + + assign(test_msg_.signature.data[1], 1); + + assign(test_msg_.signature.data[2], 2); + + assign(test_msg_.signature.data[3], 3); + + assign(test_msg_.signature.data[4], 4); + + assign(test_msg_.signature.data[5], 5); + + assign(test_msg_.signature.data[6], 6); + + assign(test_msg_.signature.data[7], 7); + + assign(test_msg_.signature.data[8], 8); + + assign(test_msg_.signature.data[9], 9); + + assign(test_msg_.signature.data[10], 10); + + assign(test_msg_.signature.data[11], 11); + + assign(test_msg_.signature.data[12], 12); + + assign(test_msg_.signature.data[13], 13); + + assign(test_msg_.signature.data[14], 14); + + assign(test_msg_.signature.data[15], 15); + + assign(test_msg_.signature.data[16], 16); + + assign(test_msg_.signature.data[17], 17); + + assign(test_msg_.signature.data[18], 18); + + assign(test_msg_.signature.data[19], 19); + + assign(test_msg_.signature.data[20], 20); + + assign(test_msg_.signature.data[21], 21); + + assign(test_msg_.signature.data[22], 22); + + assign(test_msg_.signature.data[23], 23); + + assign(test_msg_.signature.data[24], 24); + + assign(test_msg_.signature.data[25], 25); + + assign(test_msg_.signature.data[26], 26); + + assign(test_msg_.signature.data[27], 27); + + assign(test_msg_.signature.data[28], 28); + + assign(test_msg_.signature.data[29], 29); + + assign(test_msg_.signature.data[30], 30); + + assign(test_msg_.signature.data[31], 31); + + assign(test_msg_.signature.data[32], 32); + + assign(test_msg_.signature.data[33], 33); + + assign(test_msg_.signature.data[34], 34); + + assign(test_msg_.signature.data[35], 35); + + assign(test_msg_.signature.data[36], 36); + + assign(test_msg_.signature.data[37], 37); + + assign(test_msg_.signature.data[38], 38); + + assign(test_msg_.signature.data[39], 39); + + assign(test_msg_.signature.data[40], 40); + + assign(test_msg_.signature.data[41], 41); + + assign(test_msg_.signature.data[42], 42); + + assign(test_msg_.signature.data[43], 43); + + assign(test_msg_.signature.data[44], 44); + + assign(test_msg_.signature.data[45], 45); + + assign(test_msg_.signature.data[46], 46); + + assign(test_msg_.signature.data[47], 47); + + assign(test_msg_.signature.data[48], 48); + + assign(test_msg_.signature.data[49], 49); + + assign(test_msg_.signature.data[50], 50); + + assign(test_msg_.signature.data[51], 51); + + assign(test_msg_.signature.data[52], 52); + + assign(test_msg_.signature.data[53], 53); + + assign(test_msg_.signature.data[54], 54); + + assign(test_msg_.signature.data[55], 55); + + assign(test_msg_.signature.data[56], 56); + + assign(test_msg_.signature.data[57], 57); + + assign(test_msg_.signature.data[58], 58); + + assign(test_msg_.signature.data[59], 59); + + assign(test_msg_.signature.data[60], 60); + + assign(test_msg_.signature.data[61], 61); + + assign(test_msg_.signature.data[62], 62); + + assign(test_msg_.signature.data[63], 63); + + assign(test_msg_.signature.data[64], 64); + + assign(test_msg_.signature.data[65], 65); + + assign(test_msg_.signature.data[66], 66); + + assign(test_msg_.signature.data[67], 67); + + assign(test_msg_.signature.data[68], 68); + + assign(test_msg_.signature.data[69], 69); + + assign(test_msg_.signature.data[70], 70); + + assign(test_msg_.signature.data[71], 71); + assign(test_msg_.signature.len, 72); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_certificate_chain_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_certificate_chain_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCertificateChain, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_certificate_chain_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCertificateChain); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->certificate_chain, + sizeof(msg->certificate_chain)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_certificate_chain_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.certificate_chain, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCertificateChain); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xE0E3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 144; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_certificate_chain_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_certificate_chain_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_certificate_chain_t &lesser, + const sbp_msg_certificate_chain_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_certificate_chain_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_certificate_chain_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_certificate_chain_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_certificate_chain_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgCertificateChain, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCertificateChain, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgCertificateChain, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgCertificateChain, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_signing_MsgCertificateChain0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_certificate_chain_t test_msg_{}; + uint8_t encoded_frame_[144 + 8] = { 85, 9, 12, 66, 0, 144, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, @@ -86,751 +656,1441 @@ TEST_F(Test_auto_check_sbp_signing_MsgCertificateChain0, Test) { 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 227, 224, }; + uint8_t encoded_payload_[144] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 232, 7, 3, 30, 12, 34, 59, 21, 205, 91, 7, 72, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + }; +}; - sbp_msg_certificate_chain_t test_msg{}; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_certificate_chain_encoded_len(&info.test_msg), + info.payload_len); - test_msg.corrections_certificate[0] = 20; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgCertificateChain, &info.test_msg_wrapped), + info.payload_len); +} - test_msg.corrections_certificate[1] = 21; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[144]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_certificate_chain_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 144); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 144), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCertificateChain, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 144); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 144), 0); +} - test_msg.corrections_certificate[2] = 22; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[144]; - test_msg.corrections_certificate[3] = 23; + EXPECT_EQ(sbp_msg_certificate_chain_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 144), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[144]; + + for (uint8_t i = 0; i < 144; i++) { + EXPECT_EQ( + sbp_msg_certificate_chain_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.corrections_certificate[4] = 24; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_certificate_chain_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 144); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCertificateChain, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 144); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.corrections_certificate[5] = 25; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_t msg{}; - test_msg.corrections_certificate[6] = 26; + EXPECT_EQ(sbp_msg_certificate_chain_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_t msg{}; - test_msg.corrections_certificate[7] = 27; + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - test_msg.corrections_certificate[8] = 28; + EXPECT_EQ(sbp_msg_certificate_chain_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} - test_msg.corrections_certificate[9] = 29; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.corrections_certificate[10] = 10; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.corrections_certificate[11] = 11; + CHandler handler{&state}; - test_msg.corrections_certificate[12] = 12; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - test_msg.corrections_certificate[13] = 13; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.corrections_certificate[14] = 14; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.corrections_certificate[15] = 15; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.corrections_certificate[16] = 16; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.corrections_certificate[17] = 17; + CHandler handler(&state); - test_msg.corrections_certificate[18] = 18; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.corrections_certificate[19] = 19; - test_msg.expiration.day = 30; - test_msg.expiration.hours = 12; - test_msg.expiration.minutes = 34; - test_msg.expiration.month = 3; - test_msg.expiration.ns = 123456789; - test_msg.expiration.seconds = 59; - test_msg.expiration.year = 2024; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.intermediate_certificate[0] = 10; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.intermediate_certificate[1] = 11; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[2] = 12; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.intermediate_certificate[3] = 13; + CHandler handler{&state}; - test_msg.intermediate_certificate[4] = 14; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.intermediate_certificate[5] = 15; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.intermediate_certificate[6] = 16; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.intermediate_certificate[7] = 17; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.intermediate_certificate[8] = 18; + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[9] = 19; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.intermediate_certificate[10] = 0; + CHandler handler{&state}; - test_msg.intermediate_certificate[11] = 1; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.intermediate_certificate[12] = 2; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.intermediate_certificate[13] = 3; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[14] = 4; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.intermediate_certificate[15] = 5; + EXPECT_EQ(sbp_msg_certificate_chain_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.intermediate_certificate[16] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[17] = 7; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.intermediate_certificate[18] = 8; + EXPECT_EQ(sbp_message_send(&state, SbpMsgCertificateChain, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.intermediate_certificate[19] = 9; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.root_certificate[0] = 0; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.root_certificate[1] = 1; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.root_certificate[2] = 2; + EXPECT_NE(sbp_message_send(&state, SbpMsgCertificateChain, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.root_certificate[3] = 3; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.root_certificate[4] = 4; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.root_certificate[5] = 5; + EXPECT_EQ(sbp_message_send(&state, SbpMsgCertificateChain, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.root_certificate[6] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, Comparison) { + auto info = get_test_msg_info(); - test_msg.root_certificate[7] = 7; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[0], + greater.corrections_certificate[0]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[8] = 8; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[1], + greater.corrections_certificate[1]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[9] = 9; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[2], + greater.corrections_certificate[2]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[10] = 10; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[3], + greater.corrections_certificate[3]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[11] = 11; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[4], + greater.corrections_certificate[4]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[12] = 12; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[5], + greater.corrections_certificate[5]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[13] = 13; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[6], + greater.corrections_certificate[6]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[14] = 14; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[7], + greater.corrections_certificate[7]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[15] = 15; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[8], + greater.corrections_certificate[8]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[16] = 16; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[9], + greater.corrections_certificate[9]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[17] = 17; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[10], + greater.corrections_certificate[10]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[18] = 18; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[11], + greater.corrections_certificate[11]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[19] = 19; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[12], + greater.corrections_certificate[12]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[0] = 0; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[13], + greater.corrections_certificate[13]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[1] = 1; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[14], + greater.corrections_certificate[14]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[2] = 2; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[15], + greater.corrections_certificate[15]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[3] = 3; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[16], + greater.corrections_certificate[16]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[4] = 4; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[17], + greater.corrections_certificate[17]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[5] = 5; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[18], + greater.corrections_certificate[18]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[6] = 6; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[19], + greater.corrections_certificate[19]); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.day, greater.expiration.day); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.hours, greater.expiration.hours); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.minutes, greater.expiration.minutes); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.month, greater.expiration.month); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.ns, greater.expiration.ns); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.seconds, greater.expiration.seconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.year, greater.expiration.year); + comparison_tests(lesser, greater); + } - test_msg.signature.data[7] = 7; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[0], + greater.intermediate_certificate[0]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[8] = 8; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[1], + greater.intermediate_certificate[1]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[9] = 9; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[2], + greater.intermediate_certificate[2]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[10] = 10; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[3], + greater.intermediate_certificate[3]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[11] = 11; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[4], + greater.intermediate_certificate[4]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[12] = 12; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[5], + greater.intermediate_certificate[5]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[13] = 13; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[6], + greater.intermediate_certificate[6]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[14] = 14; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[7], + greater.intermediate_certificate[7]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[15] = 15; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[8], + greater.intermediate_certificate[8]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[16] = 16; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[9], + greater.intermediate_certificate[9]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[17] = 17; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[10], + greater.intermediate_certificate[10]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[18] = 18; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[11], + greater.intermediate_certificate[11]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[19] = 19; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[12], + greater.intermediate_certificate[12]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[20] = 20; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[13], + greater.intermediate_certificate[13]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[21] = 21; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[14], + greater.intermediate_certificate[14]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[22] = 22; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[15], + greater.intermediate_certificate[15]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[23] = 23; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[16], + greater.intermediate_certificate[16]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[24] = 24; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[17], + greater.intermediate_certificate[17]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[25] = 25; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[18], + greater.intermediate_certificate[18]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[26] = 26; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[19], + greater.intermediate_certificate[19]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[27] = 27; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[0], + greater.root_certificate[0]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[28] = 28; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[1], + greater.root_certificate[1]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[29] = 29; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[2], + greater.root_certificate[2]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[30] = 30; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[3], + greater.root_certificate[3]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[31] = 31; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[4], + greater.root_certificate[4]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[32] = 32; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[5], + greater.root_certificate[5]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[33] = 33; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[6], + greater.root_certificate[6]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[34] = 34; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[7], + greater.root_certificate[7]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[35] = 35; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[8], + greater.root_certificate[8]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[36] = 36; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[9], + greater.root_certificate[9]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[37] = 37; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[10], + greater.root_certificate[10]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[38] = 38; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[11], + greater.root_certificate[11]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[39] = 39; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[12], + greater.root_certificate[12]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[40] = 40; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[13], + greater.root_certificate[13]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[41] = 41; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[14], + greater.root_certificate[14]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[42] = 42; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[15], + greater.root_certificate[15]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[43] = 43; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[16], + greater.root_certificate[16]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[44] = 44; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[17], + greater.root_certificate[17]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[45] = 45; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[18], + greater.root_certificate[18]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[46] = 46; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[19], + greater.root_certificate[19]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[47] = 47; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[0], greater.signature.data[0]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[48] = 48; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[1], greater.signature.data[1]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[49] = 49; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[2], greater.signature.data[2]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[50] = 50; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[3], greater.signature.data[3]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[51] = 51; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[4], greater.signature.data[4]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[52] = 52; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[5], greater.signature.data[5]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[53] = 53; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[6], greater.signature.data[6]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[54] = 54; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[7], greater.signature.data[7]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[55] = 55; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[8], greater.signature.data[8]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[56] = 56; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[9], greater.signature.data[9]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[57] = 57; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[10], greater.signature.data[10]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[58] = 58; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[11], greater.signature.data[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[12], greater.signature.data[12]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[59] = 59; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[13], greater.signature.data[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[14], greater.signature.data[14]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[60] = 60; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[15], greater.signature.data[15]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[61] = 61; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[16], greater.signature.data[16]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[62] = 62; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[17], greater.signature.data[17]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[63] = 63; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[18], greater.signature.data[18]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[64] = 64; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[19], greater.signature.data[19]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[65] = 65; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[20], greater.signature.data[20]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[66] = 66; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[21], greater.signature.data[21]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[67] = 67; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[22], greater.signature.data[22]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[68] = 68; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[23], greater.signature.data[23]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[69] = 69; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[24], greater.signature.data[24]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[70] = 70; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[25], greater.signature.data[25]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[71] = 71; - test_msg.signature.len = 72; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[26], greater.signature.data[26]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[27], greater.signature.data[27]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[28], greater.signature.data[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[29], greater.signature.data[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[30], greater.signature.data[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[31], greater.signature.data[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[32], greater.signature.data[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[33], greater.signature.data[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[34], greater.signature.data[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[35], greater.signature.data[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[36], greater.signature.data[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[37], greater.signature.data[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[38], greater.signature.data[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[39], greater.signature.data[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[40], greater.signature.data[40]); + comparison_tests(lesser, greater); + } - while (dummy_rd_ < dummy_wr_) { - process(); + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[41], greater.signature.data[41]); + comparison_tests(lesser, greater); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.corrections_certificate[0], 20) - << "incorrect value for last_msg_.corrections_certificate[0], expected " - "20, is " - << last_msg_.corrections_certificate[0]; - EXPECT_EQ(last_msg_.corrections_certificate[1], 21) - << "incorrect value for last_msg_.corrections_certificate[1], expected " - "21, is " - << last_msg_.corrections_certificate[1]; - EXPECT_EQ(last_msg_.corrections_certificate[2], 22) - << "incorrect value for last_msg_.corrections_certificate[2], expected " - "22, is " - << last_msg_.corrections_certificate[2]; - EXPECT_EQ(last_msg_.corrections_certificate[3], 23) - << "incorrect value for last_msg_.corrections_certificate[3], expected " - "23, is " - << last_msg_.corrections_certificate[3]; - EXPECT_EQ(last_msg_.corrections_certificate[4], 24) - << "incorrect value for last_msg_.corrections_certificate[4], expected " - "24, is " - << last_msg_.corrections_certificate[4]; - EXPECT_EQ(last_msg_.corrections_certificate[5], 25) - << "incorrect value for last_msg_.corrections_certificate[5], expected " - "25, is " - << last_msg_.corrections_certificate[5]; - EXPECT_EQ(last_msg_.corrections_certificate[6], 26) - << "incorrect value for last_msg_.corrections_certificate[6], expected " - "26, is " - << last_msg_.corrections_certificate[6]; - EXPECT_EQ(last_msg_.corrections_certificate[7], 27) - << "incorrect value for last_msg_.corrections_certificate[7], expected " - "27, is " - << last_msg_.corrections_certificate[7]; - EXPECT_EQ(last_msg_.corrections_certificate[8], 28) - << "incorrect value for last_msg_.corrections_certificate[8], expected " - "28, is " - << last_msg_.corrections_certificate[8]; - EXPECT_EQ(last_msg_.corrections_certificate[9], 29) - << "incorrect value for last_msg_.corrections_certificate[9], expected " - "29, is " - << last_msg_.corrections_certificate[9]; - EXPECT_EQ(last_msg_.corrections_certificate[10], 10) - << "incorrect value for last_msg_.corrections_certificate[10], expected " - "10, is " - << last_msg_.corrections_certificate[10]; - EXPECT_EQ(last_msg_.corrections_certificate[11], 11) - << "incorrect value for last_msg_.corrections_certificate[11], expected " - "11, is " - << last_msg_.corrections_certificate[11]; - EXPECT_EQ(last_msg_.corrections_certificate[12], 12) - << "incorrect value for last_msg_.corrections_certificate[12], expected " - "12, is " - << last_msg_.corrections_certificate[12]; - EXPECT_EQ(last_msg_.corrections_certificate[13], 13) - << "incorrect value for last_msg_.corrections_certificate[13], expected " - "13, is " - << last_msg_.corrections_certificate[13]; - EXPECT_EQ(last_msg_.corrections_certificate[14], 14) - << "incorrect value for last_msg_.corrections_certificate[14], expected " - "14, is " - << last_msg_.corrections_certificate[14]; - EXPECT_EQ(last_msg_.corrections_certificate[15], 15) - << "incorrect value for last_msg_.corrections_certificate[15], expected " - "15, is " - << last_msg_.corrections_certificate[15]; - EXPECT_EQ(last_msg_.corrections_certificate[16], 16) - << "incorrect value for last_msg_.corrections_certificate[16], expected " - "16, is " - << last_msg_.corrections_certificate[16]; - EXPECT_EQ(last_msg_.corrections_certificate[17], 17) - << "incorrect value for last_msg_.corrections_certificate[17], expected " - "17, is " - << last_msg_.corrections_certificate[17]; - EXPECT_EQ(last_msg_.corrections_certificate[18], 18) - << "incorrect value for last_msg_.corrections_certificate[18], expected " - "18, is " - << last_msg_.corrections_certificate[18]; - EXPECT_EQ(last_msg_.corrections_certificate[19], 19) - << "incorrect value for last_msg_.corrections_certificate[19], expected " - "19, is " - << last_msg_.corrections_certificate[19]; - EXPECT_EQ(last_msg_.expiration.day, 30) - << "incorrect value for last_msg_.expiration.day, expected 30, is " - << last_msg_.expiration.day; - EXPECT_EQ(last_msg_.expiration.hours, 12) - << "incorrect value for last_msg_.expiration.hours, expected 12, is " - << last_msg_.expiration.hours; - EXPECT_EQ(last_msg_.expiration.minutes, 34) - << "incorrect value for last_msg_.expiration.minutes, expected 34, is " - << last_msg_.expiration.minutes; - EXPECT_EQ(last_msg_.expiration.month, 3) - << "incorrect value for last_msg_.expiration.month, expected 3, is " - << last_msg_.expiration.month; - EXPECT_EQ(last_msg_.expiration.ns, 123456789) - << "incorrect value for last_msg_.expiration.ns, expected 123456789, is " - << last_msg_.expiration.ns; - EXPECT_EQ(last_msg_.expiration.seconds, 59) - << "incorrect value for last_msg_.expiration.seconds, expected 59, is " - << last_msg_.expiration.seconds; - EXPECT_EQ(last_msg_.expiration.year, 2024) - << "incorrect value for last_msg_.expiration.year, expected 2024, is " - << last_msg_.expiration.year; - EXPECT_EQ(last_msg_.intermediate_certificate[0], 10) - << "incorrect value for last_msg_.intermediate_certificate[0], expected " - "10, is " - << last_msg_.intermediate_certificate[0]; - EXPECT_EQ(last_msg_.intermediate_certificate[1], 11) - << "incorrect value for last_msg_.intermediate_certificate[1], expected " - "11, is " - << last_msg_.intermediate_certificate[1]; - EXPECT_EQ(last_msg_.intermediate_certificate[2], 12) - << "incorrect value for last_msg_.intermediate_certificate[2], expected " - "12, is " - << last_msg_.intermediate_certificate[2]; - EXPECT_EQ(last_msg_.intermediate_certificate[3], 13) - << "incorrect value for last_msg_.intermediate_certificate[3], expected " - "13, is " - << last_msg_.intermediate_certificate[3]; - EXPECT_EQ(last_msg_.intermediate_certificate[4], 14) - << "incorrect value for last_msg_.intermediate_certificate[4], expected " - "14, is " - << last_msg_.intermediate_certificate[4]; - EXPECT_EQ(last_msg_.intermediate_certificate[5], 15) - << "incorrect value for last_msg_.intermediate_certificate[5], expected " - "15, is " - << last_msg_.intermediate_certificate[5]; - EXPECT_EQ(last_msg_.intermediate_certificate[6], 16) - << "incorrect value for last_msg_.intermediate_certificate[6], expected " - "16, is " - << last_msg_.intermediate_certificate[6]; - EXPECT_EQ(last_msg_.intermediate_certificate[7], 17) - << "incorrect value for last_msg_.intermediate_certificate[7], expected " - "17, is " - << last_msg_.intermediate_certificate[7]; - EXPECT_EQ(last_msg_.intermediate_certificate[8], 18) - << "incorrect value for last_msg_.intermediate_certificate[8], expected " - "18, is " - << last_msg_.intermediate_certificate[8]; - EXPECT_EQ(last_msg_.intermediate_certificate[9], 19) - << "incorrect value for last_msg_.intermediate_certificate[9], expected " - "19, is " - << last_msg_.intermediate_certificate[9]; - EXPECT_EQ(last_msg_.intermediate_certificate[10], 0) - << "incorrect value for last_msg_.intermediate_certificate[10], expected " - "0, is " - << last_msg_.intermediate_certificate[10]; - EXPECT_EQ(last_msg_.intermediate_certificate[11], 1) - << "incorrect value for last_msg_.intermediate_certificate[11], expected " - "1, is " - << last_msg_.intermediate_certificate[11]; - EXPECT_EQ(last_msg_.intermediate_certificate[12], 2) - << "incorrect value for last_msg_.intermediate_certificate[12], expected " - "2, is " - << last_msg_.intermediate_certificate[12]; - EXPECT_EQ(last_msg_.intermediate_certificate[13], 3) - << "incorrect value for last_msg_.intermediate_certificate[13], expected " - "3, is " - << last_msg_.intermediate_certificate[13]; - EXPECT_EQ(last_msg_.intermediate_certificate[14], 4) - << "incorrect value for last_msg_.intermediate_certificate[14], expected " - "4, is " - << last_msg_.intermediate_certificate[14]; - EXPECT_EQ(last_msg_.intermediate_certificate[15], 5) - << "incorrect value for last_msg_.intermediate_certificate[15], expected " - "5, is " - << last_msg_.intermediate_certificate[15]; - EXPECT_EQ(last_msg_.intermediate_certificate[16], 6) - << "incorrect value for last_msg_.intermediate_certificate[16], expected " - "6, is " - << last_msg_.intermediate_certificate[16]; - EXPECT_EQ(last_msg_.intermediate_certificate[17], 7) - << "incorrect value for last_msg_.intermediate_certificate[17], expected " - "7, is " - << last_msg_.intermediate_certificate[17]; - EXPECT_EQ(last_msg_.intermediate_certificate[18], 8) - << "incorrect value for last_msg_.intermediate_certificate[18], expected " - "8, is " - << last_msg_.intermediate_certificate[18]; - EXPECT_EQ(last_msg_.intermediate_certificate[19], 9) - << "incorrect value for last_msg_.intermediate_certificate[19], expected " - "9, is " - << last_msg_.intermediate_certificate[19]; - EXPECT_EQ(last_msg_.root_certificate[0], 0) - << "incorrect value for last_msg_.root_certificate[0], expected 0, is " - << last_msg_.root_certificate[0]; - EXPECT_EQ(last_msg_.root_certificate[1], 1) - << "incorrect value for last_msg_.root_certificate[1], expected 1, is " - << last_msg_.root_certificate[1]; - EXPECT_EQ(last_msg_.root_certificate[2], 2) - << "incorrect value for last_msg_.root_certificate[2], expected 2, is " - << last_msg_.root_certificate[2]; - EXPECT_EQ(last_msg_.root_certificate[3], 3) - << "incorrect value for last_msg_.root_certificate[3], expected 3, is " - << last_msg_.root_certificate[3]; - EXPECT_EQ(last_msg_.root_certificate[4], 4) - << "incorrect value for last_msg_.root_certificate[4], expected 4, is " - << last_msg_.root_certificate[4]; - EXPECT_EQ(last_msg_.root_certificate[5], 5) - << "incorrect value for last_msg_.root_certificate[5], expected 5, is " - << last_msg_.root_certificate[5]; - EXPECT_EQ(last_msg_.root_certificate[6], 6) - << "incorrect value for last_msg_.root_certificate[6], expected 6, is " - << last_msg_.root_certificate[6]; - EXPECT_EQ(last_msg_.root_certificate[7], 7) - << "incorrect value for last_msg_.root_certificate[7], expected 7, is " - << last_msg_.root_certificate[7]; - EXPECT_EQ(last_msg_.root_certificate[8], 8) - << "incorrect value for last_msg_.root_certificate[8], expected 8, is " - << last_msg_.root_certificate[8]; - EXPECT_EQ(last_msg_.root_certificate[9], 9) - << "incorrect value for last_msg_.root_certificate[9], expected 9, is " - << last_msg_.root_certificate[9]; - EXPECT_EQ(last_msg_.root_certificate[10], 10) - << "incorrect value for last_msg_.root_certificate[10], expected 10, is " - << last_msg_.root_certificate[10]; - EXPECT_EQ(last_msg_.root_certificate[11], 11) - << "incorrect value for last_msg_.root_certificate[11], expected 11, is " - << last_msg_.root_certificate[11]; - EXPECT_EQ(last_msg_.root_certificate[12], 12) - << "incorrect value for last_msg_.root_certificate[12], expected 12, is " - << last_msg_.root_certificate[12]; - EXPECT_EQ(last_msg_.root_certificate[13], 13) - << "incorrect value for last_msg_.root_certificate[13], expected 13, is " - << last_msg_.root_certificate[13]; - EXPECT_EQ(last_msg_.root_certificate[14], 14) - << "incorrect value for last_msg_.root_certificate[14], expected 14, is " - << last_msg_.root_certificate[14]; - EXPECT_EQ(last_msg_.root_certificate[15], 15) - << "incorrect value for last_msg_.root_certificate[15], expected 15, is " - << last_msg_.root_certificate[15]; - EXPECT_EQ(last_msg_.root_certificate[16], 16) - << "incorrect value for last_msg_.root_certificate[16], expected 16, is " - << last_msg_.root_certificate[16]; - EXPECT_EQ(last_msg_.root_certificate[17], 17) - << "incorrect value for last_msg_.root_certificate[17], expected 17, is " - << last_msg_.root_certificate[17]; - EXPECT_EQ(last_msg_.root_certificate[18], 18) - << "incorrect value for last_msg_.root_certificate[18], expected 18, is " - << last_msg_.root_certificate[18]; - EXPECT_EQ(last_msg_.root_certificate[19], 19) - << "incorrect value for last_msg_.root_certificate[19], expected 19, is " - << last_msg_.root_certificate[19]; - EXPECT_EQ(last_msg_.signature.data[0], 0) - << "incorrect value for last_msg_.signature.data[0], expected 0, is " - << last_msg_.signature.data[0]; - EXPECT_EQ(last_msg_.signature.data[1], 1) - << "incorrect value for last_msg_.signature.data[1], expected 1, is " - << last_msg_.signature.data[1]; - EXPECT_EQ(last_msg_.signature.data[2], 2) - << "incorrect value for last_msg_.signature.data[2], expected 2, is " - << last_msg_.signature.data[2]; - EXPECT_EQ(last_msg_.signature.data[3], 3) - << "incorrect value for last_msg_.signature.data[3], expected 3, is " - << last_msg_.signature.data[3]; - EXPECT_EQ(last_msg_.signature.data[4], 4) - << "incorrect value for last_msg_.signature.data[4], expected 4, is " - << last_msg_.signature.data[4]; - EXPECT_EQ(last_msg_.signature.data[5], 5) - << "incorrect value for last_msg_.signature.data[5], expected 5, is " - << last_msg_.signature.data[5]; - EXPECT_EQ(last_msg_.signature.data[6], 6) - << "incorrect value for last_msg_.signature.data[6], expected 6, is " - << last_msg_.signature.data[6]; - EXPECT_EQ(last_msg_.signature.data[7], 7) - << "incorrect value for last_msg_.signature.data[7], expected 7, is " - << last_msg_.signature.data[7]; - EXPECT_EQ(last_msg_.signature.data[8], 8) - << "incorrect value for last_msg_.signature.data[8], expected 8, is " - << last_msg_.signature.data[8]; - EXPECT_EQ(last_msg_.signature.data[9], 9) - << "incorrect value for last_msg_.signature.data[9], expected 9, is " - << last_msg_.signature.data[9]; - EXPECT_EQ(last_msg_.signature.data[10], 10) - << "incorrect value for last_msg_.signature.data[10], expected 10, is " - << last_msg_.signature.data[10]; - EXPECT_EQ(last_msg_.signature.data[11], 11) - << "incorrect value for last_msg_.signature.data[11], expected 11, is " - << last_msg_.signature.data[11]; - EXPECT_EQ(last_msg_.signature.data[12], 12) - << "incorrect value for last_msg_.signature.data[12], expected 12, is " - << last_msg_.signature.data[12]; - EXPECT_EQ(last_msg_.signature.data[13], 13) - << "incorrect value for last_msg_.signature.data[13], expected 13, is " - << last_msg_.signature.data[13]; - EXPECT_EQ(last_msg_.signature.data[14], 14) - << "incorrect value for last_msg_.signature.data[14], expected 14, is " - << last_msg_.signature.data[14]; - EXPECT_EQ(last_msg_.signature.data[15], 15) - << "incorrect value for last_msg_.signature.data[15], expected 15, is " - << last_msg_.signature.data[15]; - EXPECT_EQ(last_msg_.signature.data[16], 16) - << "incorrect value for last_msg_.signature.data[16], expected 16, is " - << last_msg_.signature.data[16]; - EXPECT_EQ(last_msg_.signature.data[17], 17) - << "incorrect value for last_msg_.signature.data[17], expected 17, is " - << last_msg_.signature.data[17]; - EXPECT_EQ(last_msg_.signature.data[18], 18) - << "incorrect value for last_msg_.signature.data[18], expected 18, is " - << last_msg_.signature.data[18]; - EXPECT_EQ(last_msg_.signature.data[19], 19) - << "incorrect value for last_msg_.signature.data[19], expected 19, is " - << last_msg_.signature.data[19]; - EXPECT_EQ(last_msg_.signature.data[20], 20) - << "incorrect value for last_msg_.signature.data[20], expected 20, is " - << last_msg_.signature.data[20]; - EXPECT_EQ(last_msg_.signature.data[21], 21) - << "incorrect value for last_msg_.signature.data[21], expected 21, is " - << last_msg_.signature.data[21]; - EXPECT_EQ(last_msg_.signature.data[22], 22) - << "incorrect value for last_msg_.signature.data[22], expected 22, is " - << last_msg_.signature.data[22]; - EXPECT_EQ(last_msg_.signature.data[23], 23) - << "incorrect value for last_msg_.signature.data[23], expected 23, is " - << last_msg_.signature.data[23]; - EXPECT_EQ(last_msg_.signature.data[24], 24) - << "incorrect value for last_msg_.signature.data[24], expected 24, is " - << last_msg_.signature.data[24]; - EXPECT_EQ(last_msg_.signature.data[25], 25) - << "incorrect value for last_msg_.signature.data[25], expected 25, is " - << last_msg_.signature.data[25]; - EXPECT_EQ(last_msg_.signature.data[26], 26) - << "incorrect value for last_msg_.signature.data[26], expected 26, is " - << last_msg_.signature.data[26]; - EXPECT_EQ(last_msg_.signature.data[27], 27) - << "incorrect value for last_msg_.signature.data[27], expected 27, is " - << last_msg_.signature.data[27]; - EXPECT_EQ(last_msg_.signature.data[28], 28) - << "incorrect value for last_msg_.signature.data[28], expected 28, is " - << last_msg_.signature.data[28]; - EXPECT_EQ(last_msg_.signature.data[29], 29) - << "incorrect value for last_msg_.signature.data[29], expected 29, is " - << last_msg_.signature.data[29]; - EXPECT_EQ(last_msg_.signature.data[30], 30) - << "incorrect value for last_msg_.signature.data[30], expected 30, is " - << last_msg_.signature.data[30]; - EXPECT_EQ(last_msg_.signature.data[31], 31) - << "incorrect value for last_msg_.signature.data[31], expected 31, is " - << last_msg_.signature.data[31]; - EXPECT_EQ(last_msg_.signature.data[32], 32) - << "incorrect value for last_msg_.signature.data[32], expected 32, is " - << last_msg_.signature.data[32]; - EXPECT_EQ(last_msg_.signature.data[33], 33) - << "incorrect value for last_msg_.signature.data[33], expected 33, is " - << last_msg_.signature.data[33]; - EXPECT_EQ(last_msg_.signature.data[34], 34) - << "incorrect value for last_msg_.signature.data[34], expected 34, is " - << last_msg_.signature.data[34]; - EXPECT_EQ(last_msg_.signature.data[35], 35) - << "incorrect value for last_msg_.signature.data[35], expected 35, is " - << last_msg_.signature.data[35]; - EXPECT_EQ(last_msg_.signature.data[36], 36) - << "incorrect value for last_msg_.signature.data[36], expected 36, is " - << last_msg_.signature.data[36]; - EXPECT_EQ(last_msg_.signature.data[37], 37) - << "incorrect value for last_msg_.signature.data[37], expected 37, is " - << last_msg_.signature.data[37]; - EXPECT_EQ(last_msg_.signature.data[38], 38) - << "incorrect value for last_msg_.signature.data[38], expected 38, is " - << last_msg_.signature.data[38]; - EXPECT_EQ(last_msg_.signature.data[39], 39) - << "incorrect value for last_msg_.signature.data[39], expected 39, is " - << last_msg_.signature.data[39]; - EXPECT_EQ(last_msg_.signature.data[40], 40) - << "incorrect value for last_msg_.signature.data[40], expected 40, is " - << last_msg_.signature.data[40]; - EXPECT_EQ(last_msg_.signature.data[41], 41) - << "incorrect value for last_msg_.signature.data[41], expected 41, is " - << last_msg_.signature.data[41]; - EXPECT_EQ(last_msg_.signature.data[42], 42) - << "incorrect value for last_msg_.signature.data[42], expected 42, is " - << last_msg_.signature.data[42]; - EXPECT_EQ(last_msg_.signature.data[43], 43) - << "incorrect value for last_msg_.signature.data[43], expected 43, is " - << last_msg_.signature.data[43]; - EXPECT_EQ(last_msg_.signature.data[44], 44) - << "incorrect value for last_msg_.signature.data[44], expected 44, is " - << last_msg_.signature.data[44]; - EXPECT_EQ(last_msg_.signature.data[45], 45) - << "incorrect value for last_msg_.signature.data[45], expected 45, is " - << last_msg_.signature.data[45]; - EXPECT_EQ(last_msg_.signature.data[46], 46) - << "incorrect value for last_msg_.signature.data[46], expected 46, is " - << last_msg_.signature.data[46]; - EXPECT_EQ(last_msg_.signature.data[47], 47) - << "incorrect value for last_msg_.signature.data[47], expected 47, is " - << last_msg_.signature.data[47]; - EXPECT_EQ(last_msg_.signature.data[48], 48) - << "incorrect value for last_msg_.signature.data[48], expected 48, is " - << last_msg_.signature.data[48]; - EXPECT_EQ(last_msg_.signature.data[49], 49) - << "incorrect value for last_msg_.signature.data[49], expected 49, is " - << last_msg_.signature.data[49]; - EXPECT_EQ(last_msg_.signature.data[50], 50) - << "incorrect value for last_msg_.signature.data[50], expected 50, is " - << last_msg_.signature.data[50]; - EXPECT_EQ(last_msg_.signature.data[51], 51) - << "incorrect value for last_msg_.signature.data[51], expected 51, is " - << last_msg_.signature.data[51]; - EXPECT_EQ(last_msg_.signature.data[52], 52) - << "incorrect value for last_msg_.signature.data[52], expected 52, is " - << last_msg_.signature.data[52]; - EXPECT_EQ(last_msg_.signature.data[53], 53) - << "incorrect value for last_msg_.signature.data[53], expected 53, is " - << last_msg_.signature.data[53]; - EXPECT_EQ(last_msg_.signature.data[54], 54) - << "incorrect value for last_msg_.signature.data[54], expected 54, is " - << last_msg_.signature.data[54]; - EXPECT_EQ(last_msg_.signature.data[55], 55) - << "incorrect value for last_msg_.signature.data[55], expected 55, is " - << last_msg_.signature.data[55]; - EXPECT_EQ(last_msg_.signature.data[56], 56) - << "incorrect value for last_msg_.signature.data[56], expected 56, is " - << last_msg_.signature.data[56]; - EXPECT_EQ(last_msg_.signature.data[57], 57) - << "incorrect value for last_msg_.signature.data[57], expected 57, is " - << last_msg_.signature.data[57]; - EXPECT_EQ(last_msg_.signature.data[58], 58) - << "incorrect value for last_msg_.signature.data[58], expected 58, is " - << last_msg_.signature.data[58]; - EXPECT_EQ(last_msg_.signature.data[59], 59) - << "incorrect value for last_msg_.signature.data[59], expected 59, is " - << last_msg_.signature.data[59]; - EXPECT_EQ(last_msg_.signature.data[60], 60) - << "incorrect value for last_msg_.signature.data[60], expected 60, is " - << last_msg_.signature.data[60]; - EXPECT_EQ(last_msg_.signature.data[61], 61) - << "incorrect value for last_msg_.signature.data[61], expected 61, is " - << last_msg_.signature.data[61]; - EXPECT_EQ(last_msg_.signature.data[62], 62) - << "incorrect value for last_msg_.signature.data[62], expected 62, is " - << last_msg_.signature.data[62]; - EXPECT_EQ(last_msg_.signature.data[63], 63) - << "incorrect value for last_msg_.signature.data[63], expected 63, is " - << last_msg_.signature.data[63]; - EXPECT_EQ(last_msg_.signature.data[64], 64) - << "incorrect value for last_msg_.signature.data[64], expected 64, is " - << last_msg_.signature.data[64]; - EXPECT_EQ(last_msg_.signature.data[65], 65) - << "incorrect value for last_msg_.signature.data[65], expected 65, is " - << last_msg_.signature.data[65]; - EXPECT_EQ(last_msg_.signature.data[66], 66) - << "incorrect value for last_msg_.signature.data[66], expected 66, is " - << last_msg_.signature.data[66]; - EXPECT_EQ(last_msg_.signature.data[67], 67) - << "incorrect value for last_msg_.signature.data[67], expected 67, is " - << last_msg_.signature.data[67]; - EXPECT_EQ(last_msg_.signature.data[68], 68) - << "incorrect value for last_msg_.signature.data[68], expected 68, is " - << last_msg_.signature.data[68]; - EXPECT_EQ(last_msg_.signature.data[69], 69) - << "incorrect value for last_msg_.signature.data[69], expected 69, is " - << last_msg_.signature.data[69]; - EXPECT_EQ(last_msg_.signature.data[70], 70) - << "incorrect value for last_msg_.signature.data[70], expected 70, is " - << last_msg_.signature.data[70]; - EXPECT_EQ(last_msg_.signature.data[71], 71) - << "incorrect value for last_msg_.signature.data[71], expected 71, is " - << last_msg_.signature.data[71]; - EXPECT_EQ(last_msg_.signature.len, 72) - << "incorrect value for last_msg_.signature.len, expected 72, is " - << last_msg_.signature.len; + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[42], greater.signature.data[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[43], greater.signature.data[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[44], greater.signature.data[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[45], greater.signature.data[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[46], greater.signature.data[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[47], greater.signature.data[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[48], greater.signature.data[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[49], greater.signature.data[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[50], greater.signature.data[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[51], greater.signature.data[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[52], greater.signature.data[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[53], greater.signature.data[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[54], greater.signature.data[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[55], greater.signature.data[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[56], greater.signature.data[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[57], greater.signature.data[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[58], greater.signature.data[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[59], greater.signature.data[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[60], greater.signature.data[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[61], greater.signature.data[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[62], greater.signature.data[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[63], greater.signature.data[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[64], greater.signature.data[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[65], greater.signature.data[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[66], greater.signature.data[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[67], greater.signature.data[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[68], greater.signature.data[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[69], greater.signature.data[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[70], greater.signature.data[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[71], greater.signature.data[71]); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_t lesser = info.test_msg; + sbp_msg_certificate_chain_t greater = info.test_msg; + make_lesser_greater(lesser.signature.len, greater.signature.len); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCertificateChain); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CERTIFICATE_CHAIN"); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_certificate_chain_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_certificate_chain_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.certificate_chain, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.certificate_chain, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); } + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[144]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 144); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 144), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 144); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCertificateChain, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChain0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCertificateChain, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgCertificateChainDep.cc b/c/test/cpp/auto_check_sbp_signing_MsgCertificateChainDep.cc index d35bc09dad..2c8324597a 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgCertificateChainDep.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgCertificateChainDep.cc @@ -16,66 +16,621 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgCertificateChainDep0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgCertificateChainDep0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgCertificateChainDep0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgCertificateChainDep0() { + assign(test_msg_.corrections_certificate[0], 20); + + assign(test_msg_.corrections_certificate[1], 21); + + assign(test_msg_.corrections_certificate[2], 22); + + assign(test_msg_.corrections_certificate[3], 23); + + assign(test_msg_.corrections_certificate[4], 24); + + assign(test_msg_.corrections_certificate[5], 25); + + assign(test_msg_.corrections_certificate[6], 26); + + assign(test_msg_.corrections_certificate[7], 27); + + assign(test_msg_.corrections_certificate[8], 28); + + assign(test_msg_.corrections_certificate[9], 29); + + assign(test_msg_.corrections_certificate[10], 10); + + assign(test_msg_.corrections_certificate[11], 11); + + assign(test_msg_.corrections_certificate[12], 12); + + assign(test_msg_.corrections_certificate[13], 13); + + assign(test_msg_.corrections_certificate[14], 14); + + assign(test_msg_.corrections_certificate[15], 15); + + assign(test_msg_.corrections_certificate[16], 16); + + assign(test_msg_.corrections_certificate[17], 17); + + assign(test_msg_.corrections_certificate[18], 18); + + assign(test_msg_.corrections_certificate[19], 19); + assign(test_msg_.expiration.day, 30); + assign(test_msg_.expiration.hours, 12); + assign(test_msg_.expiration.minutes, 34); + assign(test_msg_.expiration.month, 3); + assign(test_msg_.expiration.ns, 123456789); + assign(test_msg_.expiration.seconds, 59); + assign(test_msg_.expiration.year, 2024); + + assign(test_msg_.intermediate_certificate[0], 10); + + assign(test_msg_.intermediate_certificate[1], 11); + + assign(test_msg_.intermediate_certificate[2], 12); + + assign(test_msg_.intermediate_certificate[3], 13); + + assign(test_msg_.intermediate_certificate[4], 14); + + assign(test_msg_.intermediate_certificate[5], 15); + + assign(test_msg_.intermediate_certificate[6], 16); + + assign(test_msg_.intermediate_certificate[7], 17); + + assign(test_msg_.intermediate_certificate[8], 18); + + assign(test_msg_.intermediate_certificate[9], 19); + + assign(test_msg_.intermediate_certificate[10], 0); + + assign(test_msg_.intermediate_certificate[11], 1); + + assign(test_msg_.intermediate_certificate[12], 2); + + assign(test_msg_.intermediate_certificate[13], 3); + + assign(test_msg_.intermediate_certificate[14], 4); + + assign(test_msg_.intermediate_certificate[15], 5); + + assign(test_msg_.intermediate_certificate[16], 6); + + assign(test_msg_.intermediate_certificate[17], 7); + + assign(test_msg_.intermediate_certificate[18], 8); + + assign(test_msg_.intermediate_certificate[19], 9); + + assign(test_msg_.root_certificate[0], 0); + + assign(test_msg_.root_certificate[1], 1); + + assign(test_msg_.root_certificate[2], 2); + + assign(test_msg_.root_certificate[3], 3); + + assign(test_msg_.root_certificate[4], 4); + + assign(test_msg_.root_certificate[5], 5); + + assign(test_msg_.root_certificate[6], 6); + + assign(test_msg_.root_certificate[7], 7); + + assign(test_msg_.root_certificate[8], 8); + + assign(test_msg_.root_certificate[9], 9); + + assign(test_msg_.root_certificate[10], 10); + + assign(test_msg_.root_certificate[11], 11); + + assign(test_msg_.root_certificate[12], 12); + + assign(test_msg_.root_certificate[13], 13); + + assign(test_msg_.root_certificate[14], 14); + + assign(test_msg_.root_certificate[15], 15); + + assign(test_msg_.root_certificate[16], 16); + + assign(test_msg_.root_certificate[17], 17); + + assign(test_msg_.root_certificate[18], 18); + + assign(test_msg_.root_certificate[19], 19); + + assign(test_msg_.signature[0], 0); + + assign(test_msg_.signature[1], 1); + + assign(test_msg_.signature[2], 2); + + assign(test_msg_.signature[3], 3); + + assign(test_msg_.signature[4], 4); + + assign(test_msg_.signature[5], 5); + + assign(test_msg_.signature[6], 6); + + assign(test_msg_.signature[7], 7); + + assign(test_msg_.signature[8], 0); + + assign(test_msg_.signature[9], 1); + + assign(test_msg_.signature[10], 2); + + assign(test_msg_.signature[11], 3); + + assign(test_msg_.signature[12], 4); + + assign(test_msg_.signature[13], 5); + + assign(test_msg_.signature[14], 6); + + assign(test_msg_.signature[15], 7); + + assign(test_msg_.signature[16], 0); + + assign(test_msg_.signature[17], 1); + + assign(test_msg_.signature[18], 2); + + assign(test_msg_.signature[19], 3); + + assign(test_msg_.signature[20], 4); + + assign(test_msg_.signature[21], 5); + + assign(test_msg_.signature[22], 6); + + assign(test_msg_.signature[23], 7); + + assign(test_msg_.signature[24], 0); + + assign(test_msg_.signature[25], 1); + + assign(test_msg_.signature[26], 2); + + assign(test_msg_.signature[27], 3); + + assign(test_msg_.signature[28], 4); + + assign(test_msg_.signature[29], 5); + + assign(test_msg_.signature[30], 6); + + assign(test_msg_.signature[31], 7); + + assign(test_msg_.signature[32], 0); + + assign(test_msg_.signature[33], 1); + + assign(test_msg_.signature[34], 2); + + assign(test_msg_.signature[35], 3); + + assign(test_msg_.signature[36], 4); + + assign(test_msg_.signature[37], 5); + + assign(test_msg_.signature[38], 6); + + assign(test_msg_.signature[39], 7); + + assign(test_msg_.signature[40], 0); + + assign(test_msg_.signature[41], 1); + + assign(test_msg_.signature[42], 2); + + assign(test_msg_.signature[43], 3); + + assign(test_msg_.signature[44], 4); + + assign(test_msg_.signature[45], 5); + + assign(test_msg_.signature[46], 6); + + assign(test_msg_.signature[47], 7); + + assign(test_msg_.signature[48], 0); + + assign(test_msg_.signature[49], 1); + + assign(test_msg_.signature[50], 2); + + assign(test_msg_.signature[51], 3); + + assign(test_msg_.signature[52], 4); + + assign(test_msg_.signature[53], 5); + + assign(test_msg_.signature[54], 6); + + assign(test_msg_.signature[55], 7); + + assign(test_msg_.signature[56], 0); + + assign(test_msg_.signature[57], 1); + + assign(test_msg_.signature[58], 2); + + assign(test_msg_.signature[59], 3); + + assign(test_msg_.signature[60], 4); + + assign(test_msg_.signature[61], 5); + + assign(test_msg_.signature[62], 6); + + assign(test_msg_.signature[63], 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_certificate_chain_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_certificate_chain_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCertificateChainDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_certificate_chain_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCertificateChainDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->certificate_chain_dep, + sizeof(msg->certificate_chain_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_certificate_chain_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.certificate_chain_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCertificateChainDep); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x6470; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 135; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_certificate_chain_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_certificate_chain_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_certificate_chain_dep_t &lesser, + const sbp_msg_certificate_chain_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_certificate_chain_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_certificate_chain_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_certificate_chain_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_certificate_chain_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgCertificateChainDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCertificateChainDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgCertificateChainDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgCertificateChainDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_signing_MsgCertificateChainDep0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_certificate_chain_dep_t test_msg_{}; + uint8_t encoded_frame_[135 + 8] = { 85, 5, 12, 66, 0, 135, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, @@ -86,707 +641,1391 @@ TEST_F(Test_auto_check_sbp_signing_MsgCertificateChainDep0, Test) { 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 112, 100, }; + uint8_t encoded_payload_[135] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 232, 7, 3, 30, 12, 34, 59, 21, + 205, 91, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, + 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, + 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, + 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, + }; +}; - sbp_msg_certificate_chain_dep_t test_msg{}; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_certificate_chain_dep_encoded_len(&info.test_msg), + info.payload_len); - test_msg.corrections_certificate[0] = 20; + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCertificateChainDep, + &info.test_msg_wrapped), + info.payload_len); +} - test_msg.corrections_certificate[1] = 21; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[135]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_certificate_chain_dep_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 135); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 135), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCertificateChainDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 135); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 135), 0); +} - test_msg.corrections_certificate[2] = 22; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[135]; - test_msg.corrections_certificate[3] = 23; + EXPECT_EQ(sbp_msg_certificate_chain_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 135), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[135]; + + for (uint8_t i = 0; i < 135; i++) { + EXPECT_EQ(sbp_msg_certificate_chain_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.corrections_certificate[4] = 24; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_certificate_chain_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 135); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgCertificateChainDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 135); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.corrections_certificate[5] = 25; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_dep_t msg{}; - test_msg.corrections_certificate[6] = 26; + EXPECT_EQ(sbp_msg_certificate_chain_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_dep_t msg{}; - test_msg.corrections_certificate[7] = 27; + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - test_msg.corrections_certificate[8] = 28; + EXPECT_EQ(sbp_msg_certificate_chain_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} - test_msg.corrections_certificate[9] = 29; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.corrections_certificate[10] = 10; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.corrections_certificate[11] = 11; + CHandler handler{&state}; - test_msg.corrections_certificate[12] = 12; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - test_msg.corrections_certificate[13] = 13; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.corrections_certificate[14] = 14; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.corrections_certificate[15] = 15; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.corrections_certificate[16] = 16; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.corrections_certificate[17] = 17; + CHandler handler(&state); - test_msg.corrections_certificate[18] = 18; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.corrections_certificate[19] = 19; - test_msg.expiration.day = 30; - test_msg.expiration.hours = 12; - test_msg.expiration.minutes = 34; - test_msg.expiration.month = 3; - test_msg.expiration.ns = 123456789; - test_msg.expiration.seconds = 59; - test_msg.expiration.year = 2024; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.intermediate_certificate[0] = 10; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.intermediate_certificate[1] = 11; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[2] = 12; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.intermediate_certificate[3] = 13; + CHandler handler{&state}; - test_msg.intermediate_certificate[4] = 14; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.intermediate_certificate[5] = 15; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.intermediate_certificate[6] = 16; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.intermediate_certificate[7] = 17; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.intermediate_certificate[8] = 18; + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[9] = 19; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.intermediate_certificate[10] = 0; + CHandler handler{&state}; - test_msg.intermediate_certificate[11] = 1; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.intermediate_certificate[12] = 2; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.intermediate_certificate[13] = 3; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[14] = 4; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.intermediate_certificate[15] = 5; + EXPECT_EQ(sbp_msg_certificate_chain_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.intermediate_certificate[16] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.intermediate_certificate[17] = 7; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.intermediate_certificate[18] = 8; + EXPECT_EQ(sbp_message_send(&state, SbpMsgCertificateChainDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.intermediate_certificate[19] = 9; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.root_certificate[0] = 0; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.root_certificate[1] = 1; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.root_certificate[2] = 2; + EXPECT_NE( + sbp_message_send(&state, SbpMsgCertificateChainDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.root_certificate[3] = 3; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.root_certificate[4] = 4; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.root_certificate[5] = 5; + EXPECT_EQ(sbp_message_send(&state, SbpMsgCertificateChainDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.root_certificate[6] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, Comparison) { + auto info = get_test_msg_info(); - test_msg.root_certificate[7] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[0], + greater.corrections_certificate[0]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[8] = 8; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[1], + greater.corrections_certificate[1]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[9] = 9; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[2], + greater.corrections_certificate[2]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[10] = 10; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[3], + greater.corrections_certificate[3]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[11] = 11; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[4], + greater.corrections_certificate[4]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[12] = 12; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[5], + greater.corrections_certificate[5]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[13] = 13; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[6], + greater.corrections_certificate[6]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[14] = 14; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[7], + greater.corrections_certificate[7]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[15] = 15; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[8], + greater.corrections_certificate[8]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[16] = 16; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[9], + greater.corrections_certificate[9]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[17] = 17; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[10], + greater.corrections_certificate[10]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[18] = 18; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[11], + greater.corrections_certificate[11]); + comparison_tests(lesser, greater); + } - test_msg.root_certificate[19] = 19; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[12], + greater.corrections_certificate[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[0] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[13], + greater.corrections_certificate[13]); + comparison_tests(lesser, greater); + } - test_msg.signature[1] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[14], + greater.corrections_certificate[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[2] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[15], + greater.corrections_certificate[15]); + comparison_tests(lesser, greater); + } - test_msg.signature[3] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[16], + greater.corrections_certificate[16]); + comparison_tests(lesser, greater); + } - test_msg.signature[4] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[17], + greater.corrections_certificate[17]); + comparison_tests(lesser, greater); + } - test_msg.signature[5] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[18], + greater.corrections_certificate[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corrections_certificate[19], + greater.corrections_certificate[19]); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.day, greater.expiration.day); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.hours, greater.expiration.hours); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.minutes, greater.expiration.minutes); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.month, greater.expiration.month); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.ns, greater.expiration.ns); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.seconds, greater.expiration.seconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.expiration.year, greater.expiration.year); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[0], + greater.intermediate_certificate[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[1], + greater.intermediate_certificate[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[2], + greater.intermediate_certificate[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[3], + greater.intermediate_certificate[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[4], + greater.intermediate_certificate[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[5], + greater.intermediate_certificate[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[6], + greater.intermediate_certificate[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[7], + greater.intermediate_certificate[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[8], + greater.intermediate_certificate[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[9], + greater.intermediate_certificate[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[10], + greater.intermediate_certificate[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[11], + greater.intermediate_certificate[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[12], + greater.intermediate_certificate[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[13], + greater.intermediate_certificate[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[14], + greater.intermediate_certificate[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[15], + greater.intermediate_certificate[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[16], + greater.intermediate_certificate[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[17], + greater.intermediate_certificate[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[18], + greater.intermediate_certificate[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.intermediate_certificate[19], + greater.intermediate_certificate[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[0], + greater.root_certificate[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[1], + greater.root_certificate[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[2], + greater.root_certificate[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[3], + greater.root_certificate[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[4], + greater.root_certificate[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[5], + greater.root_certificate[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[6], + greater.root_certificate[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[7], + greater.root_certificate[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[8], + greater.root_certificate[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[9], + greater.root_certificate[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[10], + greater.root_certificate[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[11], + greater.root_certificate[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[12], + greater.root_certificate[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[13], + greater.root_certificate[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[14], + greater.root_certificate[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[15], + greater.root_certificate[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[16], + greater.root_certificate[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[17], + greater.root_certificate[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[18], + greater.root_certificate[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.root_certificate[19], + greater.root_certificate[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[0], greater.signature[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[1], greater.signature[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[2], greater.signature[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[3], greater.signature[3]); + comparison_tests(lesser, greater); + } - test_msg.signature[6] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[4], greater.signature[4]); + comparison_tests(lesser, greater); + } - test_msg.signature[7] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[5], greater.signature[5]); + comparison_tests(lesser, greater); + } - test_msg.signature[8] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[6], greater.signature[6]); + comparison_tests(lesser, greater); + } - test_msg.signature[9] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[7], greater.signature[7]); + comparison_tests(lesser, greater); + } - test_msg.signature[10] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[8], greater.signature[8]); + comparison_tests(lesser, greater); + } - test_msg.signature[11] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[9], greater.signature[9]); + comparison_tests(lesser, greater); + } - test_msg.signature[12] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[10], greater.signature[10]); + comparison_tests(lesser, greater); + } - test_msg.signature[13] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[11], greater.signature[11]); + comparison_tests(lesser, greater); + } - test_msg.signature[14] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[12], greater.signature[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[15] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[13], greater.signature[13]); + comparison_tests(lesser, greater); + } - test_msg.signature[16] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[14], greater.signature[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[17] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[15], greater.signature[15]); + comparison_tests(lesser, greater); + } - test_msg.signature[18] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[16], greater.signature[16]); + comparison_tests(lesser, greater); + } - test_msg.signature[19] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[17], greater.signature[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[18], greater.signature[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[19], greater.signature[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[20], greater.signature[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[21], greater.signature[21]); + comparison_tests(lesser, greater); + } - test_msg.signature[20] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[22], greater.signature[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[23], greater.signature[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[24], greater.signature[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[25], greater.signature[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[26], greater.signature[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[27], greater.signature[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[28], greater.signature[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[29], greater.signature[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[30], greater.signature[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[31], greater.signature[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[32], greater.signature[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[33], greater.signature[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[34], greater.signature[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[35], greater.signature[35]); + comparison_tests(lesser, greater); + } - test_msg.signature[21] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[36], greater.signature[36]); + comparison_tests(lesser, greater); + } - test_msg.signature[22] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[37], greater.signature[37]); + comparison_tests(lesser, greater); + } - test_msg.signature[23] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[38], greater.signature[38]); + comparison_tests(lesser, greater); + } - test_msg.signature[24] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[39], greater.signature[39]); + comparison_tests(lesser, greater); + } - test_msg.signature[25] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[40], greater.signature[40]); + comparison_tests(lesser, greater); + } - test_msg.signature[26] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[41], greater.signature[41]); + comparison_tests(lesser, greater); + } - test_msg.signature[27] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[42], greater.signature[42]); + comparison_tests(lesser, greater); + } - test_msg.signature[28] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[43], greater.signature[43]); + comparison_tests(lesser, greater); + } - test_msg.signature[29] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[44], greater.signature[44]); + comparison_tests(lesser, greater); + } - test_msg.signature[30] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[45], greater.signature[45]); + comparison_tests(lesser, greater); + } - test_msg.signature[31] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[46], greater.signature[46]); + comparison_tests(lesser, greater); + } - test_msg.signature[32] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[47], greater.signature[47]); + comparison_tests(lesser, greater); + } - test_msg.signature[33] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[48], greater.signature[48]); + comparison_tests(lesser, greater); + } - test_msg.signature[34] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[49], greater.signature[49]); + comparison_tests(lesser, greater); + } - test_msg.signature[35] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[50], greater.signature[50]); + comparison_tests(lesser, greater); + } - test_msg.signature[36] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[51], greater.signature[51]); + comparison_tests(lesser, greater); + } - test_msg.signature[37] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[52], greater.signature[52]); + comparison_tests(lesser, greater); + } - test_msg.signature[38] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[53], greater.signature[53]); + comparison_tests(lesser, greater); + } - test_msg.signature[39] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[54], greater.signature[54]); + comparison_tests(lesser, greater); + } - test_msg.signature[40] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[55], greater.signature[55]); + comparison_tests(lesser, greater); + } - test_msg.signature[41] = 1; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[56], greater.signature[56]); + comparison_tests(lesser, greater); + } - test_msg.signature[42] = 2; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[57], greater.signature[57]); + comparison_tests(lesser, greater); + } - test_msg.signature[43] = 3; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[58], greater.signature[58]); + comparison_tests(lesser, greater); + } - test_msg.signature[44] = 4; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[59], greater.signature[59]); + comparison_tests(lesser, greater); + } - test_msg.signature[45] = 5; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[60], greater.signature[60]); + comparison_tests(lesser, greater); + } - test_msg.signature[46] = 6; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[61], greater.signature[61]); + comparison_tests(lesser, greater); + } - test_msg.signature[47] = 7; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[62], greater.signature[62]); + comparison_tests(lesser, greater); + } - test_msg.signature[48] = 0; + { + sbp_msg_certificate_chain_dep_t lesser = info.test_msg; + sbp_msg_certificate_chain_dep_t greater = info.test_msg; + make_lesser_greater(lesser.signature[63], greater.signature[63]); + comparison_tests(lesser, greater); + } +} - test_msg.signature[49] = 1; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCertificateChainDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CERTIFICATE_CHAIN_DEP"); +} - test_msg.signature[50] = 2; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - test_msg.signature[51] = 3; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; - test_msg.signature[52] = 4; + const sbp_msg_certificate_chain_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_certificate_chain_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); - test_msg.signature[53] = 5; + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} - test_msg.signature[54] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); - test_msg.signature[55] = 7; + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.certificate_chain_dep, info.test_msg); - test_msg.signature[56] = 0; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.certificate_chain_dep, info.test_msg); +} - test_msg.signature[57] = 1; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} - test_msg.signature[58] = 2; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[59] = 3; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature[60] = 4; + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.signature[61] = 5; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[135]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 135); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 135), 0); +} - test_msg.signature[62] = 6; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_certificate_chain_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 135); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.signature[63] = 7; +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + sbp::State state{}; + state.set_reader(&reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CppHandler handler{&state}; - while (dummy_rd_ < dummy_wr_) { - process(); + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.corrections_certificate[0], 20) - << "incorrect value for last_msg_.corrections_certificate[0], expected " - "20, is " - << last_msg_.corrections_certificate[0]; - EXPECT_EQ(last_msg_.corrections_certificate[1], 21) - << "incorrect value for last_msg_.corrections_certificate[1], expected " - "21, is " - << last_msg_.corrections_certificate[1]; - EXPECT_EQ(last_msg_.corrections_certificate[2], 22) - << "incorrect value for last_msg_.corrections_certificate[2], expected " - "22, is " - << last_msg_.corrections_certificate[2]; - EXPECT_EQ(last_msg_.corrections_certificate[3], 23) - << "incorrect value for last_msg_.corrections_certificate[3], expected " - "23, is " - << last_msg_.corrections_certificate[3]; - EXPECT_EQ(last_msg_.corrections_certificate[4], 24) - << "incorrect value for last_msg_.corrections_certificate[4], expected " - "24, is " - << last_msg_.corrections_certificate[4]; - EXPECT_EQ(last_msg_.corrections_certificate[5], 25) - << "incorrect value for last_msg_.corrections_certificate[5], expected " - "25, is " - << last_msg_.corrections_certificate[5]; - EXPECT_EQ(last_msg_.corrections_certificate[6], 26) - << "incorrect value for last_msg_.corrections_certificate[6], expected " - "26, is " - << last_msg_.corrections_certificate[6]; - EXPECT_EQ(last_msg_.corrections_certificate[7], 27) - << "incorrect value for last_msg_.corrections_certificate[7], expected " - "27, is " - << last_msg_.corrections_certificate[7]; - EXPECT_EQ(last_msg_.corrections_certificate[8], 28) - << "incorrect value for last_msg_.corrections_certificate[8], expected " - "28, is " - << last_msg_.corrections_certificate[8]; - EXPECT_EQ(last_msg_.corrections_certificate[9], 29) - << "incorrect value for last_msg_.corrections_certificate[9], expected " - "29, is " - << last_msg_.corrections_certificate[9]; - EXPECT_EQ(last_msg_.corrections_certificate[10], 10) - << "incorrect value for last_msg_.corrections_certificate[10], expected " - "10, is " - << last_msg_.corrections_certificate[10]; - EXPECT_EQ(last_msg_.corrections_certificate[11], 11) - << "incorrect value for last_msg_.corrections_certificate[11], expected " - "11, is " - << last_msg_.corrections_certificate[11]; - EXPECT_EQ(last_msg_.corrections_certificate[12], 12) - << "incorrect value for last_msg_.corrections_certificate[12], expected " - "12, is " - << last_msg_.corrections_certificate[12]; - EXPECT_EQ(last_msg_.corrections_certificate[13], 13) - << "incorrect value for last_msg_.corrections_certificate[13], expected " - "13, is " - << last_msg_.corrections_certificate[13]; - EXPECT_EQ(last_msg_.corrections_certificate[14], 14) - << "incorrect value for last_msg_.corrections_certificate[14], expected " - "14, is " - << last_msg_.corrections_certificate[14]; - EXPECT_EQ(last_msg_.corrections_certificate[15], 15) - << "incorrect value for last_msg_.corrections_certificate[15], expected " - "15, is " - << last_msg_.corrections_certificate[15]; - EXPECT_EQ(last_msg_.corrections_certificate[16], 16) - << "incorrect value for last_msg_.corrections_certificate[16], expected " - "16, is " - << last_msg_.corrections_certificate[16]; - EXPECT_EQ(last_msg_.corrections_certificate[17], 17) - << "incorrect value for last_msg_.corrections_certificate[17], expected " - "17, is " - << last_msg_.corrections_certificate[17]; - EXPECT_EQ(last_msg_.corrections_certificate[18], 18) - << "incorrect value for last_msg_.corrections_certificate[18], expected " - "18, is " - << last_msg_.corrections_certificate[18]; - EXPECT_EQ(last_msg_.corrections_certificate[19], 19) - << "incorrect value for last_msg_.corrections_certificate[19], expected " - "19, is " - << last_msg_.corrections_certificate[19]; - EXPECT_EQ(last_msg_.expiration.day, 30) - << "incorrect value for last_msg_.expiration.day, expected 30, is " - << last_msg_.expiration.day; - EXPECT_EQ(last_msg_.expiration.hours, 12) - << "incorrect value for last_msg_.expiration.hours, expected 12, is " - << last_msg_.expiration.hours; - EXPECT_EQ(last_msg_.expiration.minutes, 34) - << "incorrect value for last_msg_.expiration.minutes, expected 34, is " - << last_msg_.expiration.minutes; - EXPECT_EQ(last_msg_.expiration.month, 3) - << "incorrect value for last_msg_.expiration.month, expected 3, is " - << last_msg_.expiration.month; - EXPECT_EQ(last_msg_.expiration.ns, 123456789) - << "incorrect value for last_msg_.expiration.ns, expected 123456789, is " - << last_msg_.expiration.ns; - EXPECT_EQ(last_msg_.expiration.seconds, 59) - << "incorrect value for last_msg_.expiration.seconds, expected 59, is " - << last_msg_.expiration.seconds; - EXPECT_EQ(last_msg_.expiration.year, 2024) - << "incorrect value for last_msg_.expiration.year, expected 2024, is " - << last_msg_.expiration.year; - EXPECT_EQ(last_msg_.intermediate_certificate[0], 10) - << "incorrect value for last_msg_.intermediate_certificate[0], expected " - "10, is " - << last_msg_.intermediate_certificate[0]; - EXPECT_EQ(last_msg_.intermediate_certificate[1], 11) - << "incorrect value for last_msg_.intermediate_certificate[1], expected " - "11, is " - << last_msg_.intermediate_certificate[1]; - EXPECT_EQ(last_msg_.intermediate_certificate[2], 12) - << "incorrect value for last_msg_.intermediate_certificate[2], expected " - "12, is " - << last_msg_.intermediate_certificate[2]; - EXPECT_EQ(last_msg_.intermediate_certificate[3], 13) - << "incorrect value for last_msg_.intermediate_certificate[3], expected " - "13, is " - << last_msg_.intermediate_certificate[3]; - EXPECT_EQ(last_msg_.intermediate_certificate[4], 14) - << "incorrect value for last_msg_.intermediate_certificate[4], expected " - "14, is " - << last_msg_.intermediate_certificate[4]; - EXPECT_EQ(last_msg_.intermediate_certificate[5], 15) - << "incorrect value for last_msg_.intermediate_certificate[5], expected " - "15, is " - << last_msg_.intermediate_certificate[5]; - EXPECT_EQ(last_msg_.intermediate_certificate[6], 16) - << "incorrect value for last_msg_.intermediate_certificate[6], expected " - "16, is " - << last_msg_.intermediate_certificate[6]; - EXPECT_EQ(last_msg_.intermediate_certificate[7], 17) - << "incorrect value for last_msg_.intermediate_certificate[7], expected " - "17, is " - << last_msg_.intermediate_certificate[7]; - EXPECT_EQ(last_msg_.intermediate_certificate[8], 18) - << "incorrect value for last_msg_.intermediate_certificate[8], expected " - "18, is " - << last_msg_.intermediate_certificate[8]; - EXPECT_EQ(last_msg_.intermediate_certificate[9], 19) - << "incorrect value for last_msg_.intermediate_certificate[9], expected " - "19, is " - << last_msg_.intermediate_certificate[9]; - EXPECT_EQ(last_msg_.intermediate_certificate[10], 0) - << "incorrect value for last_msg_.intermediate_certificate[10], expected " - "0, is " - << last_msg_.intermediate_certificate[10]; - EXPECT_EQ(last_msg_.intermediate_certificate[11], 1) - << "incorrect value for last_msg_.intermediate_certificate[11], expected " - "1, is " - << last_msg_.intermediate_certificate[11]; - EXPECT_EQ(last_msg_.intermediate_certificate[12], 2) - << "incorrect value for last_msg_.intermediate_certificate[12], expected " - "2, is " - << last_msg_.intermediate_certificate[12]; - EXPECT_EQ(last_msg_.intermediate_certificate[13], 3) - << "incorrect value for last_msg_.intermediate_certificate[13], expected " - "3, is " - << last_msg_.intermediate_certificate[13]; - EXPECT_EQ(last_msg_.intermediate_certificate[14], 4) - << "incorrect value for last_msg_.intermediate_certificate[14], expected " - "4, is " - << last_msg_.intermediate_certificate[14]; - EXPECT_EQ(last_msg_.intermediate_certificate[15], 5) - << "incorrect value for last_msg_.intermediate_certificate[15], expected " - "5, is " - << last_msg_.intermediate_certificate[15]; - EXPECT_EQ(last_msg_.intermediate_certificate[16], 6) - << "incorrect value for last_msg_.intermediate_certificate[16], expected " - "6, is " - << last_msg_.intermediate_certificate[16]; - EXPECT_EQ(last_msg_.intermediate_certificate[17], 7) - << "incorrect value for last_msg_.intermediate_certificate[17], expected " - "7, is " - << last_msg_.intermediate_certificate[17]; - EXPECT_EQ(last_msg_.intermediate_certificate[18], 8) - << "incorrect value for last_msg_.intermediate_certificate[18], expected " - "8, is " - << last_msg_.intermediate_certificate[18]; - EXPECT_EQ(last_msg_.intermediate_certificate[19], 9) - << "incorrect value for last_msg_.intermediate_certificate[19], expected " - "9, is " - << last_msg_.intermediate_certificate[19]; - EXPECT_EQ(last_msg_.root_certificate[0], 0) - << "incorrect value for last_msg_.root_certificate[0], expected 0, is " - << last_msg_.root_certificate[0]; - EXPECT_EQ(last_msg_.root_certificate[1], 1) - << "incorrect value for last_msg_.root_certificate[1], expected 1, is " - << last_msg_.root_certificate[1]; - EXPECT_EQ(last_msg_.root_certificate[2], 2) - << "incorrect value for last_msg_.root_certificate[2], expected 2, is " - << last_msg_.root_certificate[2]; - EXPECT_EQ(last_msg_.root_certificate[3], 3) - << "incorrect value for last_msg_.root_certificate[3], expected 3, is " - << last_msg_.root_certificate[3]; - EXPECT_EQ(last_msg_.root_certificate[4], 4) - << "incorrect value for last_msg_.root_certificate[4], expected 4, is " - << last_msg_.root_certificate[4]; - EXPECT_EQ(last_msg_.root_certificate[5], 5) - << "incorrect value for last_msg_.root_certificate[5], expected 5, is " - << last_msg_.root_certificate[5]; - EXPECT_EQ(last_msg_.root_certificate[6], 6) - << "incorrect value for last_msg_.root_certificate[6], expected 6, is " - << last_msg_.root_certificate[6]; - EXPECT_EQ(last_msg_.root_certificate[7], 7) - << "incorrect value for last_msg_.root_certificate[7], expected 7, is " - << last_msg_.root_certificate[7]; - EXPECT_EQ(last_msg_.root_certificate[8], 8) - << "incorrect value for last_msg_.root_certificate[8], expected 8, is " - << last_msg_.root_certificate[8]; - EXPECT_EQ(last_msg_.root_certificate[9], 9) - << "incorrect value for last_msg_.root_certificate[9], expected 9, is " - << last_msg_.root_certificate[9]; - EXPECT_EQ(last_msg_.root_certificate[10], 10) - << "incorrect value for last_msg_.root_certificate[10], expected 10, is " - << last_msg_.root_certificate[10]; - EXPECT_EQ(last_msg_.root_certificate[11], 11) - << "incorrect value for last_msg_.root_certificate[11], expected 11, is " - << last_msg_.root_certificate[11]; - EXPECT_EQ(last_msg_.root_certificate[12], 12) - << "incorrect value for last_msg_.root_certificate[12], expected 12, is " - << last_msg_.root_certificate[12]; - EXPECT_EQ(last_msg_.root_certificate[13], 13) - << "incorrect value for last_msg_.root_certificate[13], expected 13, is " - << last_msg_.root_certificate[13]; - EXPECT_EQ(last_msg_.root_certificate[14], 14) - << "incorrect value for last_msg_.root_certificate[14], expected 14, is " - << last_msg_.root_certificate[14]; - EXPECT_EQ(last_msg_.root_certificate[15], 15) - << "incorrect value for last_msg_.root_certificate[15], expected 15, is " - << last_msg_.root_certificate[15]; - EXPECT_EQ(last_msg_.root_certificate[16], 16) - << "incorrect value for last_msg_.root_certificate[16], expected 16, is " - << last_msg_.root_certificate[16]; - EXPECT_EQ(last_msg_.root_certificate[17], 17) - << "incorrect value for last_msg_.root_certificate[17], expected 17, is " - << last_msg_.root_certificate[17]; - EXPECT_EQ(last_msg_.root_certificate[18], 18) - << "incorrect value for last_msg_.root_certificate[18], expected 18, is " - << last_msg_.root_certificate[18]; - EXPECT_EQ(last_msg_.root_certificate[19], 19) - << "incorrect value for last_msg_.root_certificate[19], expected 19, is " - << last_msg_.root_certificate[19]; - EXPECT_EQ(last_msg_.signature[0], 0) - << "incorrect value for last_msg_.signature[0], expected 0, is " - << last_msg_.signature[0]; - EXPECT_EQ(last_msg_.signature[1], 1) - << "incorrect value for last_msg_.signature[1], expected 1, is " - << last_msg_.signature[1]; - EXPECT_EQ(last_msg_.signature[2], 2) - << "incorrect value for last_msg_.signature[2], expected 2, is " - << last_msg_.signature[2]; - EXPECT_EQ(last_msg_.signature[3], 3) - << "incorrect value for last_msg_.signature[3], expected 3, is " - << last_msg_.signature[3]; - EXPECT_EQ(last_msg_.signature[4], 4) - << "incorrect value for last_msg_.signature[4], expected 4, is " - << last_msg_.signature[4]; - EXPECT_EQ(last_msg_.signature[5], 5) - << "incorrect value for last_msg_.signature[5], expected 5, is " - << last_msg_.signature[5]; - EXPECT_EQ(last_msg_.signature[6], 6) - << "incorrect value for last_msg_.signature[6], expected 6, is " - << last_msg_.signature[6]; - EXPECT_EQ(last_msg_.signature[7], 7) - << "incorrect value for last_msg_.signature[7], expected 7, is " - << last_msg_.signature[7]; - EXPECT_EQ(last_msg_.signature[8], 0) - << "incorrect value for last_msg_.signature[8], expected 0, is " - << last_msg_.signature[8]; - EXPECT_EQ(last_msg_.signature[9], 1) - << "incorrect value for last_msg_.signature[9], expected 1, is " - << last_msg_.signature[9]; - EXPECT_EQ(last_msg_.signature[10], 2) - << "incorrect value for last_msg_.signature[10], expected 2, is " - << last_msg_.signature[10]; - EXPECT_EQ(last_msg_.signature[11], 3) - << "incorrect value for last_msg_.signature[11], expected 3, is " - << last_msg_.signature[11]; - EXPECT_EQ(last_msg_.signature[12], 4) - << "incorrect value for last_msg_.signature[12], expected 4, is " - << last_msg_.signature[12]; - EXPECT_EQ(last_msg_.signature[13], 5) - << "incorrect value for last_msg_.signature[13], expected 5, is " - << last_msg_.signature[13]; - EXPECT_EQ(last_msg_.signature[14], 6) - << "incorrect value for last_msg_.signature[14], expected 6, is " - << last_msg_.signature[14]; - EXPECT_EQ(last_msg_.signature[15], 7) - << "incorrect value for last_msg_.signature[15], expected 7, is " - << last_msg_.signature[15]; - EXPECT_EQ(last_msg_.signature[16], 0) - << "incorrect value for last_msg_.signature[16], expected 0, is " - << last_msg_.signature[16]; - EXPECT_EQ(last_msg_.signature[17], 1) - << "incorrect value for last_msg_.signature[17], expected 1, is " - << last_msg_.signature[17]; - EXPECT_EQ(last_msg_.signature[18], 2) - << "incorrect value for last_msg_.signature[18], expected 2, is " - << last_msg_.signature[18]; - EXPECT_EQ(last_msg_.signature[19], 3) - << "incorrect value for last_msg_.signature[19], expected 3, is " - << last_msg_.signature[19]; - EXPECT_EQ(last_msg_.signature[20], 4) - << "incorrect value for last_msg_.signature[20], expected 4, is " - << last_msg_.signature[20]; - EXPECT_EQ(last_msg_.signature[21], 5) - << "incorrect value for last_msg_.signature[21], expected 5, is " - << last_msg_.signature[21]; - EXPECT_EQ(last_msg_.signature[22], 6) - << "incorrect value for last_msg_.signature[22], expected 6, is " - << last_msg_.signature[22]; - EXPECT_EQ(last_msg_.signature[23], 7) - << "incorrect value for last_msg_.signature[23], expected 7, is " - << last_msg_.signature[23]; - EXPECT_EQ(last_msg_.signature[24], 0) - << "incorrect value for last_msg_.signature[24], expected 0, is " - << last_msg_.signature[24]; - EXPECT_EQ(last_msg_.signature[25], 1) - << "incorrect value for last_msg_.signature[25], expected 1, is " - << last_msg_.signature[25]; - EXPECT_EQ(last_msg_.signature[26], 2) - << "incorrect value for last_msg_.signature[26], expected 2, is " - << last_msg_.signature[26]; - EXPECT_EQ(last_msg_.signature[27], 3) - << "incorrect value for last_msg_.signature[27], expected 3, is " - << last_msg_.signature[27]; - EXPECT_EQ(last_msg_.signature[28], 4) - << "incorrect value for last_msg_.signature[28], expected 4, is " - << last_msg_.signature[28]; - EXPECT_EQ(last_msg_.signature[29], 5) - << "incorrect value for last_msg_.signature[29], expected 5, is " - << last_msg_.signature[29]; - EXPECT_EQ(last_msg_.signature[30], 6) - << "incorrect value for last_msg_.signature[30], expected 6, is " - << last_msg_.signature[30]; - EXPECT_EQ(last_msg_.signature[31], 7) - << "incorrect value for last_msg_.signature[31], expected 7, is " - << last_msg_.signature[31]; - EXPECT_EQ(last_msg_.signature[32], 0) - << "incorrect value for last_msg_.signature[32], expected 0, is " - << last_msg_.signature[32]; - EXPECT_EQ(last_msg_.signature[33], 1) - << "incorrect value for last_msg_.signature[33], expected 1, is " - << last_msg_.signature[33]; - EXPECT_EQ(last_msg_.signature[34], 2) - << "incorrect value for last_msg_.signature[34], expected 2, is " - << last_msg_.signature[34]; - EXPECT_EQ(last_msg_.signature[35], 3) - << "incorrect value for last_msg_.signature[35], expected 3, is " - << last_msg_.signature[35]; - EXPECT_EQ(last_msg_.signature[36], 4) - << "incorrect value for last_msg_.signature[36], expected 4, is " - << last_msg_.signature[36]; - EXPECT_EQ(last_msg_.signature[37], 5) - << "incorrect value for last_msg_.signature[37], expected 5, is " - << last_msg_.signature[37]; - EXPECT_EQ(last_msg_.signature[38], 6) - << "incorrect value for last_msg_.signature[38], expected 6, is " - << last_msg_.signature[38]; - EXPECT_EQ(last_msg_.signature[39], 7) - << "incorrect value for last_msg_.signature[39], expected 7, is " - << last_msg_.signature[39]; - EXPECT_EQ(last_msg_.signature[40], 0) - << "incorrect value for last_msg_.signature[40], expected 0, is " - << last_msg_.signature[40]; - EXPECT_EQ(last_msg_.signature[41], 1) - << "incorrect value for last_msg_.signature[41], expected 1, is " - << last_msg_.signature[41]; - EXPECT_EQ(last_msg_.signature[42], 2) - << "incorrect value for last_msg_.signature[42], expected 2, is " - << last_msg_.signature[42]; - EXPECT_EQ(last_msg_.signature[43], 3) - << "incorrect value for last_msg_.signature[43], expected 3, is " - << last_msg_.signature[43]; - EXPECT_EQ(last_msg_.signature[44], 4) - << "incorrect value for last_msg_.signature[44], expected 4, is " - << last_msg_.signature[44]; - EXPECT_EQ(last_msg_.signature[45], 5) - << "incorrect value for last_msg_.signature[45], expected 5, is " - << last_msg_.signature[45]; - EXPECT_EQ(last_msg_.signature[46], 6) - << "incorrect value for last_msg_.signature[46], expected 6, is " - << last_msg_.signature[46]; - EXPECT_EQ(last_msg_.signature[47], 7) - << "incorrect value for last_msg_.signature[47], expected 7, is " - << last_msg_.signature[47]; - EXPECT_EQ(last_msg_.signature[48], 0) - << "incorrect value for last_msg_.signature[48], expected 0, is " - << last_msg_.signature[48]; - EXPECT_EQ(last_msg_.signature[49], 1) - << "incorrect value for last_msg_.signature[49], expected 1, is " - << last_msg_.signature[49]; - EXPECT_EQ(last_msg_.signature[50], 2) - << "incorrect value for last_msg_.signature[50], expected 2, is " - << last_msg_.signature[50]; - EXPECT_EQ(last_msg_.signature[51], 3) - << "incorrect value for last_msg_.signature[51], expected 3, is " - << last_msg_.signature[51]; - EXPECT_EQ(last_msg_.signature[52], 4) - << "incorrect value for last_msg_.signature[52], expected 4, is " - << last_msg_.signature[52]; - EXPECT_EQ(last_msg_.signature[53], 5) - << "incorrect value for last_msg_.signature[53], expected 5, is " - << last_msg_.signature[53]; - EXPECT_EQ(last_msg_.signature[54], 6) - << "incorrect value for last_msg_.signature[54], expected 6, is " - << last_msg_.signature[54]; - EXPECT_EQ(last_msg_.signature[55], 7) - << "incorrect value for last_msg_.signature[55], expected 7, is " - << last_msg_.signature[55]; - EXPECT_EQ(last_msg_.signature[56], 0) - << "incorrect value for last_msg_.signature[56], expected 0, is " - << last_msg_.signature[56]; - EXPECT_EQ(last_msg_.signature[57], 1) - << "incorrect value for last_msg_.signature[57], expected 1, is " - << last_msg_.signature[57]; - EXPECT_EQ(last_msg_.signature[58], 2) - << "incorrect value for last_msg_.signature[58], expected 2, is " - << last_msg_.signature[58]; - EXPECT_EQ(last_msg_.signature[59], 3) - << "incorrect value for last_msg_.signature[59], expected 3, is " - << last_msg_.signature[59]; - EXPECT_EQ(last_msg_.signature[60], 4) - << "incorrect value for last_msg_.signature[60], expected 4, is " - << last_msg_.signature[60]; - EXPECT_EQ(last_msg_.signature[61], 5) - << "incorrect value for last_msg_.signature[61], expected 5, is " - << last_msg_.signature[61]; - EXPECT_EQ(last_msg_.signature[62], 6) - << "incorrect value for last_msg_.signature[62], expected 6, is " - << last_msg_.signature[62]; - EXPECT_EQ(last_msg_.signature[63], 7) - << "incorrect value for last_msg_.signature[63], expected 7, is " - << last_msg_.signature[63]; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCertificateChainDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgCertificateChainDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCertificateChainDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaCertificate.cc b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaCertificate.cc index 3e0102b8ee..18bfb5d03a 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaCertificate.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaCertificate.cc @@ -16,1561 +16,3338 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEcdsaCertificate0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEcdsaCertificate0 : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEcdsaCertificate0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + Testauto_check_sbp_signing_MsgEcdsaCertificate0() { + assign(test_msg_.certificate_bytes[0], 180); - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ecdsa_certificate_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ecdsa_certificate_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + assign(test_msg_.certificate_bytes[1], 160); -TEST_F(Test_auto_check_sbp_signing_MsgEcdsaCertificate0, Test) { - uint8_t encoded_frame[] = { - 85, 4, 12, 66, 0, 253, 48, 10, 11, 12, 13, 2, 180, 160, 116, - 77, 243, 28, 173, 36, 86, 33, 8, 31, 120, 73, 64, 169, 148, 224, - 57, 95, 17, 40, 213, 92, 195, 146, 235, 228, 177, 101, 82, 182, 25, - 172, 170, 250, 236, 7, 119, 4, 201, 10, 14, 208, 47, 126, 49, 210, - 174, 75, 221, 203, 24, 66, 52, 35, 26, 30, 140, 111, 246, 39, 226, - 205, 198, 178, 196, 5, 81, 9, 44, 164, 163, 214, 138, 123, 76, 74, - 237, 121, 13, 137, 186, 97, 193, 189, 200, 124, 69, 115, 230, 159, 185, - 158, 51, 12, 225, 65, 192, 105, 56, 41, 85, 133, 19, 217, 166, 48, - 139, 131, 96, 216, 98, 147, 132, 234, 167, 248, 247, 32, 239, 194, 188, - 254, 114, 117, 83, 25, 251, 191, 104, 240, 118, 68, 42, 93, 18, 16, - 37, 232, 99, 179, 23, 90, 94, 136, 6, 125, 91, 255, 15, 71, 43, - 46, 25, 252, 229, 80, 143, 58, 241, 11, 62, 181, 155, 53, 153, 149, - 152, 227, 150, 87, 112, 165, 2, 128, 231, 25, 157, 244, 204, 108, 253, - 127, 122, 145, 113, 162, 197, 171, 199, 54, 184, 222, 206, 67, 144, 78, - 187, 207, 60, 211, 141, 135, 106, 220, 79, 183, 245, 21, 161, 168, 34, - 129, 50, 176, 1, 218, 20, 130, 59, 249, 109, 219, 0, 100, 103, 55, - 29, 242, 110, 154, 190, 233, 142, 45, 61, 215, 202, 238, 88, 209, 70, - 63, 151, 27, 102, 219, 30, - }; + assign(test_msg_.certificate_bytes[2], 116); + + assign(test_msg_.certificate_bytes[3], 77); + + assign(test_msg_.certificate_bytes[4], 243); + + assign(test_msg_.certificate_bytes[5], 28); + + assign(test_msg_.certificate_bytes[6], 173); + + assign(test_msg_.certificate_bytes[7], 36); + + assign(test_msg_.certificate_bytes[8], 86); + + assign(test_msg_.certificate_bytes[9], 33); + + assign(test_msg_.certificate_bytes[10], 8); + + assign(test_msg_.certificate_bytes[11], 31); + + assign(test_msg_.certificate_bytes[12], 120); + + assign(test_msg_.certificate_bytes[13], 73); + + assign(test_msg_.certificate_bytes[14], 64); + + assign(test_msg_.certificate_bytes[15], 169); + + assign(test_msg_.certificate_bytes[16], 148); + + assign(test_msg_.certificate_bytes[17], 224); + + assign(test_msg_.certificate_bytes[18], 57); + + assign(test_msg_.certificate_bytes[19], 95); + + assign(test_msg_.certificate_bytes[20], 17); + + assign(test_msg_.certificate_bytes[21], 40); + + assign(test_msg_.certificate_bytes[22], 213); + + assign(test_msg_.certificate_bytes[23], 92); + + assign(test_msg_.certificate_bytes[24], 195); + + assign(test_msg_.certificate_bytes[25], 146); + + assign(test_msg_.certificate_bytes[26], 235); + + assign(test_msg_.certificate_bytes[27], 228); + + assign(test_msg_.certificate_bytes[28], 177); + + assign(test_msg_.certificate_bytes[29], 101); + + assign(test_msg_.certificate_bytes[30], 82); + + assign(test_msg_.certificate_bytes[31], 182); + + assign(test_msg_.certificate_bytes[32], 25); + + assign(test_msg_.certificate_bytes[33], 172); + + assign(test_msg_.certificate_bytes[34], 170); + + assign(test_msg_.certificate_bytes[35], 250); + + assign(test_msg_.certificate_bytes[36], 236); + + assign(test_msg_.certificate_bytes[37], 7); + + assign(test_msg_.certificate_bytes[38], 119); + + assign(test_msg_.certificate_bytes[39], 4); + + assign(test_msg_.certificate_bytes[40], 201); + + assign(test_msg_.certificate_bytes[41], 10); - sbp_msg_ecdsa_certificate_t test_msg{}; + assign(test_msg_.certificate_bytes[42], 14); - test_msg.certificate_bytes[0] = 180; + assign(test_msg_.certificate_bytes[43], 208); - test_msg.certificate_bytes[1] = 160; + assign(test_msg_.certificate_bytes[44], 47); - test_msg.certificate_bytes[2] = 116; + assign(test_msg_.certificate_bytes[45], 126); - test_msg.certificate_bytes[3] = 77; + assign(test_msg_.certificate_bytes[46], 49); - test_msg.certificate_bytes[4] = 243; + assign(test_msg_.certificate_bytes[47], 210); - test_msg.certificate_bytes[5] = 28; + assign(test_msg_.certificate_bytes[48], 174); - test_msg.certificate_bytes[6] = 173; + assign(test_msg_.certificate_bytes[49], 75); - test_msg.certificate_bytes[7] = 36; + assign(test_msg_.certificate_bytes[50], 221); - test_msg.certificate_bytes[8] = 86; + assign(test_msg_.certificate_bytes[51], 203); - test_msg.certificate_bytes[9] = 33; + assign(test_msg_.certificate_bytes[52], 24); - test_msg.certificate_bytes[10] = 8; + assign(test_msg_.certificate_bytes[53], 66); - test_msg.certificate_bytes[11] = 31; + assign(test_msg_.certificate_bytes[54], 52); - test_msg.certificate_bytes[12] = 120; + assign(test_msg_.certificate_bytes[55], 35); - test_msg.certificate_bytes[13] = 73; + assign(test_msg_.certificate_bytes[56], 26); - test_msg.certificate_bytes[14] = 64; + assign(test_msg_.certificate_bytes[57], 30); - test_msg.certificate_bytes[15] = 169; + assign(test_msg_.certificate_bytes[58], 140); - test_msg.certificate_bytes[16] = 148; + assign(test_msg_.certificate_bytes[59], 111); - test_msg.certificate_bytes[17] = 224; + assign(test_msg_.certificate_bytes[60], 246); - test_msg.certificate_bytes[18] = 57; + assign(test_msg_.certificate_bytes[61], 39); - test_msg.certificate_bytes[19] = 95; + assign(test_msg_.certificate_bytes[62], 226); - test_msg.certificate_bytes[20] = 17; + assign(test_msg_.certificate_bytes[63], 205); - test_msg.certificate_bytes[21] = 40; + assign(test_msg_.certificate_bytes[64], 198); - test_msg.certificate_bytes[22] = 213; + assign(test_msg_.certificate_bytes[65], 178); - test_msg.certificate_bytes[23] = 92; + assign(test_msg_.certificate_bytes[66], 196); - test_msg.certificate_bytes[24] = 195; + assign(test_msg_.certificate_bytes[67], 5); - test_msg.certificate_bytes[25] = 146; + assign(test_msg_.certificate_bytes[68], 81); - test_msg.certificate_bytes[26] = 235; + assign(test_msg_.certificate_bytes[69], 9); - test_msg.certificate_bytes[27] = 228; + assign(test_msg_.certificate_bytes[70], 44); - test_msg.certificate_bytes[28] = 177; + assign(test_msg_.certificate_bytes[71], 164); - test_msg.certificate_bytes[29] = 101; + assign(test_msg_.certificate_bytes[72], 163); - test_msg.certificate_bytes[30] = 82; + assign(test_msg_.certificate_bytes[73], 214); - test_msg.certificate_bytes[31] = 182; + assign(test_msg_.certificate_bytes[74], 138); - test_msg.certificate_bytes[32] = 25; + assign(test_msg_.certificate_bytes[75], 123); - test_msg.certificate_bytes[33] = 172; + assign(test_msg_.certificate_bytes[76], 76); - test_msg.certificate_bytes[34] = 170; + assign(test_msg_.certificate_bytes[77], 74); - test_msg.certificate_bytes[35] = 250; + assign(test_msg_.certificate_bytes[78], 237); - test_msg.certificate_bytes[36] = 236; + assign(test_msg_.certificate_bytes[79], 121); - test_msg.certificate_bytes[37] = 7; + assign(test_msg_.certificate_bytes[80], 13); - test_msg.certificate_bytes[38] = 119; + assign(test_msg_.certificate_bytes[81], 137); - test_msg.certificate_bytes[39] = 4; + assign(test_msg_.certificate_bytes[82], 186); - test_msg.certificate_bytes[40] = 201; + assign(test_msg_.certificate_bytes[83], 97); - test_msg.certificate_bytes[41] = 10; + assign(test_msg_.certificate_bytes[84], 193); - test_msg.certificate_bytes[42] = 14; + assign(test_msg_.certificate_bytes[85], 189); - test_msg.certificate_bytes[43] = 208; + assign(test_msg_.certificate_bytes[86], 200); - test_msg.certificate_bytes[44] = 47; + assign(test_msg_.certificate_bytes[87], 124); - test_msg.certificate_bytes[45] = 126; + assign(test_msg_.certificate_bytes[88], 69); - test_msg.certificate_bytes[46] = 49; + assign(test_msg_.certificate_bytes[89], 115); - test_msg.certificate_bytes[47] = 210; + assign(test_msg_.certificate_bytes[90], 230); - test_msg.certificate_bytes[48] = 174; + assign(test_msg_.certificate_bytes[91], 159); - test_msg.certificate_bytes[49] = 75; + assign(test_msg_.certificate_bytes[92], 185); - test_msg.certificate_bytes[50] = 221; + assign(test_msg_.certificate_bytes[93], 158); - test_msg.certificate_bytes[51] = 203; + assign(test_msg_.certificate_bytes[94], 51); - test_msg.certificate_bytes[52] = 24; + assign(test_msg_.certificate_bytes[95], 12); - test_msg.certificate_bytes[53] = 66; + assign(test_msg_.certificate_bytes[96], 225); - test_msg.certificate_bytes[54] = 52; + assign(test_msg_.certificate_bytes[97], 65); - test_msg.certificate_bytes[55] = 35; + assign(test_msg_.certificate_bytes[98], 192); - test_msg.certificate_bytes[56] = 26; + assign(test_msg_.certificate_bytes[99], 105); - test_msg.certificate_bytes[57] = 30; + assign(test_msg_.certificate_bytes[100], 56); - test_msg.certificate_bytes[58] = 140; + assign(test_msg_.certificate_bytes[101], 41); - test_msg.certificate_bytes[59] = 111; + assign(test_msg_.certificate_bytes[102], 85); - test_msg.certificate_bytes[60] = 246; + assign(test_msg_.certificate_bytes[103], 133); - test_msg.certificate_bytes[61] = 39; + assign(test_msg_.certificate_bytes[104], 19); - test_msg.certificate_bytes[62] = 226; + assign(test_msg_.certificate_bytes[105], 217); - test_msg.certificate_bytes[63] = 205; + assign(test_msg_.certificate_bytes[106], 166); - test_msg.certificate_bytes[64] = 198; + assign(test_msg_.certificate_bytes[107], 48); - test_msg.certificate_bytes[65] = 178; + assign(test_msg_.certificate_bytes[108], 139); - test_msg.certificate_bytes[66] = 196; + assign(test_msg_.certificate_bytes[109], 131); - test_msg.certificate_bytes[67] = 5; + assign(test_msg_.certificate_bytes[110], 96); - test_msg.certificate_bytes[68] = 81; + assign(test_msg_.certificate_bytes[111], 216); - test_msg.certificate_bytes[69] = 9; + assign(test_msg_.certificate_bytes[112], 98); - test_msg.certificate_bytes[70] = 44; + assign(test_msg_.certificate_bytes[113], 147); - test_msg.certificate_bytes[71] = 164; + assign(test_msg_.certificate_bytes[114], 132); - test_msg.certificate_bytes[72] = 163; + assign(test_msg_.certificate_bytes[115], 234); - test_msg.certificate_bytes[73] = 214; + assign(test_msg_.certificate_bytes[116], 167); - test_msg.certificate_bytes[74] = 138; + assign(test_msg_.certificate_bytes[117], 248); - test_msg.certificate_bytes[75] = 123; + assign(test_msg_.certificate_bytes[118], 247); - test_msg.certificate_bytes[76] = 76; + assign(test_msg_.certificate_bytes[119], 32); - test_msg.certificate_bytes[77] = 74; + assign(test_msg_.certificate_bytes[120], 239); - test_msg.certificate_bytes[78] = 237; + assign(test_msg_.certificate_bytes[121], 194); - test_msg.certificate_bytes[79] = 121; + assign(test_msg_.certificate_bytes[122], 188); - test_msg.certificate_bytes[80] = 13; + assign(test_msg_.certificate_bytes[123], 254); - test_msg.certificate_bytes[81] = 137; + assign(test_msg_.certificate_bytes[124], 114); - test_msg.certificate_bytes[82] = 186; + assign(test_msg_.certificate_bytes[125], 117); - test_msg.certificate_bytes[83] = 97; + assign(test_msg_.certificate_bytes[126], 83); - test_msg.certificate_bytes[84] = 193; + assign(test_msg_.certificate_bytes[127], 25); - test_msg.certificate_bytes[85] = 189; + assign(test_msg_.certificate_bytes[128], 251); - test_msg.certificate_bytes[86] = 200; + assign(test_msg_.certificate_bytes[129], 191); - test_msg.certificate_bytes[87] = 124; + assign(test_msg_.certificate_bytes[130], 104); - test_msg.certificate_bytes[88] = 69; + assign(test_msg_.certificate_bytes[131], 240); - test_msg.certificate_bytes[89] = 115; + assign(test_msg_.certificate_bytes[132], 118); - test_msg.certificate_bytes[90] = 230; + assign(test_msg_.certificate_bytes[133], 68); - test_msg.certificate_bytes[91] = 159; + assign(test_msg_.certificate_bytes[134], 42); - test_msg.certificate_bytes[92] = 185; + assign(test_msg_.certificate_bytes[135], 93); - test_msg.certificate_bytes[93] = 158; + assign(test_msg_.certificate_bytes[136], 18); - test_msg.certificate_bytes[94] = 51; + assign(test_msg_.certificate_bytes[137], 16); - test_msg.certificate_bytes[95] = 12; + assign(test_msg_.certificate_bytes[138], 37); - test_msg.certificate_bytes[96] = 225; + assign(test_msg_.certificate_bytes[139], 232); - test_msg.certificate_bytes[97] = 65; + assign(test_msg_.certificate_bytes[140], 99); - test_msg.certificate_bytes[98] = 192; + assign(test_msg_.certificate_bytes[141], 179); - test_msg.certificate_bytes[99] = 105; + assign(test_msg_.certificate_bytes[142], 23); - test_msg.certificate_bytes[100] = 56; + assign(test_msg_.certificate_bytes[143], 90); - test_msg.certificate_bytes[101] = 41; + assign(test_msg_.certificate_bytes[144], 94); - test_msg.certificate_bytes[102] = 85; + assign(test_msg_.certificate_bytes[145], 136); - test_msg.certificate_bytes[103] = 133; + assign(test_msg_.certificate_bytes[146], 6); - test_msg.certificate_bytes[104] = 19; + assign(test_msg_.certificate_bytes[147], 125); - test_msg.certificate_bytes[105] = 217; + assign(test_msg_.certificate_bytes[148], 91); - test_msg.certificate_bytes[106] = 166; + assign(test_msg_.certificate_bytes[149], 255); - test_msg.certificate_bytes[107] = 48; + assign(test_msg_.certificate_bytes[150], 15); - test_msg.certificate_bytes[108] = 139; + assign(test_msg_.certificate_bytes[151], 71); - test_msg.certificate_bytes[109] = 131; + assign(test_msg_.certificate_bytes[152], 43); - test_msg.certificate_bytes[110] = 96; + assign(test_msg_.certificate_bytes[153], 46); - test_msg.certificate_bytes[111] = 216; + assign(test_msg_.certificate_bytes[154], 25); - test_msg.certificate_bytes[112] = 98; + assign(test_msg_.certificate_bytes[155], 252); - test_msg.certificate_bytes[113] = 147; + assign(test_msg_.certificate_bytes[156], 229); - test_msg.certificate_bytes[114] = 132; + assign(test_msg_.certificate_bytes[157], 80); - test_msg.certificate_bytes[115] = 234; + assign(test_msg_.certificate_bytes[158], 143); - test_msg.certificate_bytes[116] = 167; + assign(test_msg_.certificate_bytes[159], 58); - test_msg.certificate_bytes[117] = 248; + assign(test_msg_.certificate_bytes[160], 241); - test_msg.certificate_bytes[118] = 247; + assign(test_msg_.certificate_bytes[161], 11); - test_msg.certificate_bytes[119] = 32; + assign(test_msg_.certificate_bytes[162], 62); - test_msg.certificate_bytes[120] = 239; + assign(test_msg_.certificate_bytes[163], 181); - test_msg.certificate_bytes[121] = 194; + assign(test_msg_.certificate_bytes[164], 155); - test_msg.certificate_bytes[122] = 188; + assign(test_msg_.certificate_bytes[165], 53); - test_msg.certificate_bytes[123] = 254; + assign(test_msg_.certificate_bytes[166], 153); - test_msg.certificate_bytes[124] = 114; + assign(test_msg_.certificate_bytes[167], 149); - test_msg.certificate_bytes[125] = 117; + assign(test_msg_.certificate_bytes[168], 152); - test_msg.certificate_bytes[126] = 83; + assign(test_msg_.certificate_bytes[169], 227); - test_msg.certificate_bytes[127] = 25; + assign(test_msg_.certificate_bytes[170], 150); - test_msg.certificate_bytes[128] = 251; + assign(test_msg_.certificate_bytes[171], 87); - test_msg.certificate_bytes[129] = 191; + assign(test_msg_.certificate_bytes[172], 112); - test_msg.certificate_bytes[130] = 104; + assign(test_msg_.certificate_bytes[173], 165); - test_msg.certificate_bytes[131] = 240; + assign(test_msg_.certificate_bytes[174], 2); - test_msg.certificate_bytes[132] = 118; + assign(test_msg_.certificate_bytes[175], 128); - test_msg.certificate_bytes[133] = 68; + assign(test_msg_.certificate_bytes[176], 231); - test_msg.certificate_bytes[134] = 42; + assign(test_msg_.certificate_bytes[177], 25); - test_msg.certificate_bytes[135] = 93; + assign(test_msg_.certificate_bytes[178], 157); - test_msg.certificate_bytes[136] = 18; + assign(test_msg_.certificate_bytes[179], 244); - test_msg.certificate_bytes[137] = 16; + assign(test_msg_.certificate_bytes[180], 204); - test_msg.certificate_bytes[138] = 37; + assign(test_msg_.certificate_bytes[181], 108); - test_msg.certificate_bytes[139] = 232; + assign(test_msg_.certificate_bytes[182], 253); - test_msg.certificate_bytes[140] = 99; + assign(test_msg_.certificate_bytes[183], 127); - test_msg.certificate_bytes[141] = 179; + assign(test_msg_.certificate_bytes[184], 122); - test_msg.certificate_bytes[142] = 23; + assign(test_msg_.certificate_bytes[185], 145); - test_msg.certificate_bytes[143] = 90; + assign(test_msg_.certificate_bytes[186], 113); - test_msg.certificate_bytes[144] = 94; + assign(test_msg_.certificate_bytes[187], 162); - test_msg.certificate_bytes[145] = 136; + assign(test_msg_.certificate_bytes[188], 197); - test_msg.certificate_bytes[146] = 6; + assign(test_msg_.certificate_bytes[189], 171); - test_msg.certificate_bytes[147] = 125; + assign(test_msg_.certificate_bytes[190], 199); - test_msg.certificate_bytes[148] = 91; + assign(test_msg_.certificate_bytes[191], 54); - test_msg.certificate_bytes[149] = 255; + assign(test_msg_.certificate_bytes[192], 184); - test_msg.certificate_bytes[150] = 15; + assign(test_msg_.certificate_bytes[193], 222); - test_msg.certificate_bytes[151] = 71; + assign(test_msg_.certificate_bytes[194], 206); - test_msg.certificate_bytes[152] = 43; + assign(test_msg_.certificate_bytes[195], 67); - test_msg.certificate_bytes[153] = 46; + assign(test_msg_.certificate_bytes[196], 144); - test_msg.certificate_bytes[154] = 25; + assign(test_msg_.certificate_bytes[197], 78); - test_msg.certificate_bytes[155] = 252; + assign(test_msg_.certificate_bytes[198], 187); - test_msg.certificate_bytes[156] = 229; + assign(test_msg_.certificate_bytes[199], 207); - test_msg.certificate_bytes[157] = 80; + assign(test_msg_.certificate_bytes[200], 60); - test_msg.certificate_bytes[158] = 143; + assign(test_msg_.certificate_bytes[201], 211); - test_msg.certificate_bytes[159] = 58; + assign(test_msg_.certificate_bytes[202], 141); - test_msg.certificate_bytes[160] = 241; + assign(test_msg_.certificate_bytes[203], 135); - test_msg.certificate_bytes[161] = 11; + assign(test_msg_.certificate_bytes[204], 106); - test_msg.certificate_bytes[162] = 62; + assign(test_msg_.certificate_bytes[205], 220); - test_msg.certificate_bytes[163] = 181; + assign(test_msg_.certificate_bytes[206], 79); - test_msg.certificate_bytes[164] = 155; + assign(test_msg_.certificate_bytes[207], 183); - test_msg.certificate_bytes[165] = 53; + assign(test_msg_.certificate_bytes[208], 245); - test_msg.certificate_bytes[166] = 153; + assign(test_msg_.certificate_bytes[209], 21); - test_msg.certificate_bytes[167] = 149; + assign(test_msg_.certificate_bytes[210], 161); - test_msg.certificate_bytes[168] = 152; + assign(test_msg_.certificate_bytes[211], 168); - test_msg.certificate_bytes[169] = 227; + assign(test_msg_.certificate_bytes[212], 34); - test_msg.certificate_bytes[170] = 150; + assign(test_msg_.certificate_bytes[213], 129); - test_msg.certificate_bytes[171] = 87; + assign(test_msg_.certificate_bytes[214], 50); - test_msg.certificate_bytes[172] = 112; + assign(test_msg_.certificate_bytes[215], 176); - test_msg.certificate_bytes[173] = 165; + assign(test_msg_.certificate_bytes[216], 1); - test_msg.certificate_bytes[174] = 2; + assign(test_msg_.certificate_bytes[217], 218); - test_msg.certificate_bytes[175] = 128; + assign(test_msg_.certificate_bytes[218], 20); - test_msg.certificate_bytes[176] = 231; + assign(test_msg_.certificate_bytes[219], 130); - test_msg.certificate_bytes[177] = 25; + assign(test_msg_.certificate_bytes[220], 59); - test_msg.certificate_bytes[178] = 157; + assign(test_msg_.certificate_bytes[221], 249); - test_msg.certificate_bytes[179] = 244; + assign(test_msg_.certificate_bytes[222], 109); - test_msg.certificate_bytes[180] = 204; + assign(test_msg_.certificate_bytes[223], 219); - test_msg.certificate_bytes[181] = 108; + assign(test_msg_.certificate_bytes[224], 0); - test_msg.certificate_bytes[182] = 253; + assign(test_msg_.certificate_bytes[225], 100); - test_msg.certificate_bytes[183] = 127; + assign(test_msg_.certificate_bytes[226], 103); - test_msg.certificate_bytes[184] = 122; + assign(test_msg_.certificate_bytes[227], 55); - test_msg.certificate_bytes[185] = 145; + assign(test_msg_.certificate_bytes[228], 29); - test_msg.certificate_bytes[186] = 113; + assign(test_msg_.certificate_bytes[229], 242); - test_msg.certificate_bytes[187] = 162; + assign(test_msg_.certificate_bytes[230], 110); - test_msg.certificate_bytes[188] = 197; + assign(test_msg_.certificate_bytes[231], 154); - test_msg.certificate_bytes[189] = 171; + assign(test_msg_.certificate_bytes[232], 190); - test_msg.certificate_bytes[190] = 199; + assign(test_msg_.certificate_bytes[233], 233); - test_msg.certificate_bytes[191] = 54; + assign(test_msg_.certificate_bytes[234], 142); - test_msg.certificate_bytes[192] = 184; + assign(test_msg_.certificate_bytes[235], 45); - test_msg.certificate_bytes[193] = 222; + assign(test_msg_.certificate_bytes[236], 61); - test_msg.certificate_bytes[194] = 206; + assign(test_msg_.certificate_bytes[237], 215); - test_msg.certificate_bytes[195] = 67; + assign(test_msg_.certificate_bytes[238], 202); - test_msg.certificate_bytes[196] = 144; + assign(test_msg_.certificate_bytes[239], 238); - test_msg.certificate_bytes[197] = 78; + assign(test_msg_.certificate_bytes[240], 88); - test_msg.certificate_bytes[198] = 187; + assign(test_msg_.certificate_bytes[241], 209); - test_msg.certificate_bytes[199] = 207; + assign(test_msg_.certificate_bytes[242], 70); - test_msg.certificate_bytes[200] = 60; + assign(test_msg_.certificate_bytes[243], 63); - test_msg.certificate_bytes[201] = 211; + assign(test_msg_.certificate_bytes[244], 151); - test_msg.certificate_bytes[202] = 141; + assign(test_msg_.certificate_bytes[245], 27); - test_msg.certificate_bytes[203] = 135; + assign(test_msg_.certificate_bytes[246], 102); - test_msg.certificate_bytes[204] = 106; + assign(test_msg_.certificate_id[0], 10); - test_msg.certificate_bytes[205] = 220; + assign(test_msg_.certificate_id[1], 11); - test_msg.certificate_bytes[206] = 79; + assign(test_msg_.certificate_id[2], 12); - test_msg.certificate_bytes[207] = 183; + assign(test_msg_.certificate_id[3], 13); + assign(test_msg_.flags, 2); + assign(test_msg_.n_certificate_bytes, 247); + assign(test_msg_.n_msg, 48); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_certificate_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ecdsa_certificate_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEcdsaCertificate, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_certificate_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEcdsaCertificate); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ecdsa_certificate, + sizeof(msg->ecdsa_certificate)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; - test_msg.certificate_bytes[208] = 245; + struct TestMsgInfo { + sbp_msg_ecdsa_certificate_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ecdsa_certificate, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEcdsaCertificate); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x1EDB; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 253; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ecdsa_certificate_t &lesser, + const sbp_msg_ecdsa_certificate_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ecdsa_certificate_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ecdsa_certificate_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ecdsa_certificate_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ecdsa_certificate_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaCertificate, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaCertificate, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEcdsaCertificate, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEcdsaCertificate, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ecdsa_certificate_t test_msg_{}; + uint8_t encoded_frame_[253 + 8] = { + 85, 4, 12, 66, 0, 253, 48, 10, 11, 12, 13, 2, 180, 160, 116, + 77, 243, 28, 173, 36, 86, 33, 8, 31, 120, 73, 64, 169, 148, 224, + 57, 95, 17, 40, 213, 92, 195, 146, 235, 228, 177, 101, 82, 182, 25, + 172, 170, 250, 236, 7, 119, 4, 201, 10, 14, 208, 47, 126, 49, 210, + 174, 75, 221, 203, 24, 66, 52, 35, 26, 30, 140, 111, 246, 39, 226, + 205, 198, 178, 196, 5, 81, 9, 44, 164, 163, 214, 138, 123, 76, 74, + 237, 121, 13, 137, 186, 97, 193, 189, 200, 124, 69, 115, 230, 159, 185, + 158, 51, 12, 225, 65, 192, 105, 56, 41, 85, 133, 19, 217, 166, 48, + 139, 131, 96, 216, 98, 147, 132, 234, 167, 248, 247, 32, 239, 194, 188, + 254, 114, 117, 83, 25, 251, 191, 104, 240, 118, 68, 42, 93, 18, 16, + 37, 232, 99, 179, 23, 90, 94, 136, 6, 125, 91, 255, 15, 71, 43, + 46, 25, 252, 229, 80, 143, 58, 241, 11, 62, 181, 155, 53, 153, 149, + 152, 227, 150, 87, 112, 165, 2, 128, 231, 25, 157, 244, 204, 108, 253, + 127, 122, 145, 113, 162, 197, 171, 199, 54, 184, 222, 206, 67, 144, 78, + 187, 207, 60, 211, 141, 135, 106, 220, 79, 183, 245, 21, 161, 168, 34, + 129, 50, 176, 1, 218, 20, 130, 59, 249, 109, 219, 0, 100, 103, 55, + 29, 242, 110, 154, 190, 233, 142, 45, 61, 215, 202, 238, 88, 209, 70, + 63, 151, 27, 102, 219, 30, + }; + uint8_t encoded_payload_[253] = { + 48, 10, 11, 12, 13, 2, 180, 160, 116, 77, 243, 28, 173, 36, 86, + 33, 8, 31, 120, 73, 64, 169, 148, 224, 57, 95, 17, 40, 213, 92, + 195, 146, 235, 228, 177, 101, 82, 182, 25, 172, 170, 250, 236, 7, 119, + 4, 201, 10, 14, 208, 47, 126, 49, 210, 174, 75, 221, 203, 24, 66, + 52, 35, 26, 30, 140, 111, 246, 39, 226, 205, 198, 178, 196, 5, 81, + 9, 44, 164, 163, 214, 138, 123, 76, 74, 237, 121, 13, 137, 186, 97, + 193, 189, 200, 124, 69, 115, 230, 159, 185, 158, 51, 12, 225, 65, 192, + 105, 56, 41, 85, 133, 19, 217, 166, 48, 139, 131, 96, 216, 98, 147, + 132, 234, 167, 248, 247, 32, 239, 194, 188, 254, 114, 117, 83, 25, 251, + 191, 104, 240, 118, 68, 42, 93, 18, 16, 37, 232, 99, 179, 23, 90, + 94, 136, 6, 125, 91, 255, 15, 71, 43, 46, 25, 252, 229, 80, 143, + 58, 241, 11, 62, 181, 155, 53, 153, 149, 152, 227, 150, 87, 112, 165, + 2, 128, 231, 25, 157, 244, 204, 108, 253, 127, 122, 145, 113, 162, 197, + 171, 199, 54, 184, 222, 206, 67, 144, 78, 187, 207, 60, 211, 141, 135, + 106, 220, 79, 183, 245, 21, 161, 168, 34, 129, 50, 176, 1, 218, 20, + 130, 59, 249, 109, 219, 0, 100, 103, 55, 29, 242, 110, 154, 190, 233, + 142, 45, 61, 215, 202, 238, 88, 209, 70, 63, 151, 27, 102, + }; +}; - test_msg.certificate_bytes[209] = 21; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ecdsa_certificate_encoded_len(&info.test_msg), + info.payload_len); - test_msg.certificate_bytes[210] = 161; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEcdsaCertificate, &info.test_msg_wrapped), + info.payload_len); +} - test_msg.certificate_bytes[211] = 168; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ecdsa_certificate_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEcdsaCertificate, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} - test_msg.certificate_bytes[212] = 34; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[253]; - test_msg.certificate_bytes[213] = 129; + EXPECT_EQ(sbp_msg_ecdsa_certificate_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + + for (uint8_t i = 0; i < 253; i++) { + EXPECT_EQ( + sbp_msg_ecdsa_certificate_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.certificate_bytes[214] = 50; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_certificate_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ecdsa_certificate_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEcdsaCertificate, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.certificate_bytes[215] = 176; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_certificate_t msg{}; - test_msg.certificate_bytes[216] = 1; + EXPECT_EQ(sbp_msg_ecdsa_certificate_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_certificate_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ecdsa_certificate_t t{}; + return sbp_msg_ecdsa_certificate_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ecdsa_certificate_t t{}; + t.n_certificate_bytes = 1; + return sbp_msg_ecdsa_certificate_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ecdsa_certificate_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} - test_msg.certificate_bytes[217] = 218; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[218] = 20; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_bytes[219] = 130; + CHandler handler{&state}; - test_msg.certificate_bytes[220] = 59; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - test_msg.certificate_bytes[221] = 249; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.certificate_bytes[222] = 109; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.certificate_bytes[223] = 219; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[224] = 0; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_bytes[225] = 100; + CHandler handler(&state); - test_msg.certificate_bytes[226] = 103; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.certificate_bytes[227] = 55; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.certificate_bytes[228] = 29; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.certificate_bytes[229] = 242; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[230] = 110; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_bytes[231] = 154; + CHandler handler{&state}; - test_msg.certificate_bytes[232] = 190; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.certificate_bytes[233] = 233; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.certificate_bytes[234] = 142; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.certificate_bytes[235] = 45; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.certificate_bytes[236] = 61; + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[237] = 215; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_bytes[238] = 202; + CHandler handler{&state}; - test_msg.certificate_bytes[239] = 238; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.certificate_bytes[240] = 88; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.certificate_bytes[241] = 209; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[242] = 70; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.certificate_bytes[243] = 63; + EXPECT_EQ(sbp_msg_ecdsa_certificate_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.certificate_bytes[244] = 151; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[245] = 27; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.certificate_bytes[246] = 102; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaCertificate, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.certificate_id[0] = 10; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.certificate_id[1] = 11; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_id[2] = 12; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.certificate_id[3] = 13; - test_msg.flags = 2; - test_msg.n_certificate_bytes = 247; - test_msg.n_msg = 48; + EXPECT_NE(sbp_message_send(&state, SbpMsgEcdsaCertificate, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - EXPECT_EQ(send_message(66, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.certificate_bytes[0], 180) - << "incorrect value for last_msg_.certificate_bytes[0], expected 180, is " - << last_msg_.certificate_bytes[0]; - EXPECT_EQ(last_msg_.certificate_bytes[1], 160) - << "incorrect value for last_msg_.certificate_bytes[1], expected 160, is " - << last_msg_.certificate_bytes[1]; - EXPECT_EQ(last_msg_.certificate_bytes[2], 116) - << "incorrect value for last_msg_.certificate_bytes[2], expected 116, is " - << last_msg_.certificate_bytes[2]; - EXPECT_EQ(last_msg_.certificate_bytes[3], 77) - << "incorrect value for last_msg_.certificate_bytes[3], expected 77, is " - << last_msg_.certificate_bytes[3]; - EXPECT_EQ(last_msg_.certificate_bytes[4], 243) - << "incorrect value for last_msg_.certificate_bytes[4], expected 243, is " - << last_msg_.certificate_bytes[4]; - EXPECT_EQ(last_msg_.certificate_bytes[5], 28) - << "incorrect value for last_msg_.certificate_bytes[5], expected 28, is " - << last_msg_.certificate_bytes[5]; - EXPECT_EQ(last_msg_.certificate_bytes[6], 173) - << "incorrect value for last_msg_.certificate_bytes[6], expected 173, is " - << last_msg_.certificate_bytes[6]; - EXPECT_EQ(last_msg_.certificate_bytes[7], 36) - << "incorrect value for last_msg_.certificate_bytes[7], expected 36, is " - << last_msg_.certificate_bytes[7]; - EXPECT_EQ(last_msg_.certificate_bytes[8], 86) - << "incorrect value for last_msg_.certificate_bytes[8], expected 86, is " - << last_msg_.certificate_bytes[8]; - EXPECT_EQ(last_msg_.certificate_bytes[9], 33) - << "incorrect value for last_msg_.certificate_bytes[9], expected 33, is " - << last_msg_.certificate_bytes[9]; - EXPECT_EQ(last_msg_.certificate_bytes[10], 8) - << "incorrect value for last_msg_.certificate_bytes[10], expected 8, is " - << last_msg_.certificate_bytes[10]; - EXPECT_EQ(last_msg_.certificate_bytes[11], 31) - << "incorrect value for last_msg_.certificate_bytes[11], expected 31, is " - << last_msg_.certificate_bytes[11]; - EXPECT_EQ(last_msg_.certificate_bytes[12], 120) - << "incorrect value for last_msg_.certificate_bytes[12], expected 120, " - "is " - << last_msg_.certificate_bytes[12]; - EXPECT_EQ(last_msg_.certificate_bytes[13], 73) - << "incorrect value for last_msg_.certificate_bytes[13], expected 73, is " - << last_msg_.certificate_bytes[13]; - EXPECT_EQ(last_msg_.certificate_bytes[14], 64) - << "incorrect value for last_msg_.certificate_bytes[14], expected 64, is " - << last_msg_.certificate_bytes[14]; - EXPECT_EQ(last_msg_.certificate_bytes[15], 169) - << "incorrect value for last_msg_.certificate_bytes[15], expected 169, " - "is " - << last_msg_.certificate_bytes[15]; - EXPECT_EQ(last_msg_.certificate_bytes[16], 148) - << "incorrect value for last_msg_.certificate_bytes[16], expected 148, " - "is " - << last_msg_.certificate_bytes[16]; - EXPECT_EQ(last_msg_.certificate_bytes[17], 224) - << "incorrect value for last_msg_.certificate_bytes[17], expected 224, " - "is " - << last_msg_.certificate_bytes[17]; - EXPECT_EQ(last_msg_.certificate_bytes[18], 57) - << "incorrect value for last_msg_.certificate_bytes[18], expected 57, is " - << last_msg_.certificate_bytes[18]; - EXPECT_EQ(last_msg_.certificate_bytes[19], 95) - << "incorrect value for last_msg_.certificate_bytes[19], expected 95, is " - << last_msg_.certificate_bytes[19]; - EXPECT_EQ(last_msg_.certificate_bytes[20], 17) - << "incorrect value for last_msg_.certificate_bytes[20], expected 17, is " - << last_msg_.certificate_bytes[20]; - EXPECT_EQ(last_msg_.certificate_bytes[21], 40) - << "incorrect value for last_msg_.certificate_bytes[21], expected 40, is " - << last_msg_.certificate_bytes[21]; - EXPECT_EQ(last_msg_.certificate_bytes[22], 213) - << "incorrect value for last_msg_.certificate_bytes[22], expected 213, " - "is " - << last_msg_.certificate_bytes[22]; - EXPECT_EQ(last_msg_.certificate_bytes[23], 92) - << "incorrect value for last_msg_.certificate_bytes[23], expected 92, is " - << last_msg_.certificate_bytes[23]; - EXPECT_EQ(last_msg_.certificate_bytes[24], 195) - << "incorrect value for last_msg_.certificate_bytes[24], expected 195, " - "is " - << last_msg_.certificate_bytes[24]; - EXPECT_EQ(last_msg_.certificate_bytes[25], 146) - << "incorrect value for last_msg_.certificate_bytes[25], expected 146, " - "is " - << last_msg_.certificate_bytes[25]; - EXPECT_EQ(last_msg_.certificate_bytes[26], 235) - << "incorrect value for last_msg_.certificate_bytes[26], expected 235, " - "is " - << last_msg_.certificate_bytes[26]; - EXPECT_EQ(last_msg_.certificate_bytes[27], 228) - << "incorrect value for last_msg_.certificate_bytes[27], expected 228, " - "is " - << last_msg_.certificate_bytes[27]; - EXPECT_EQ(last_msg_.certificate_bytes[28], 177) - << "incorrect value for last_msg_.certificate_bytes[28], expected 177, " - "is " - << last_msg_.certificate_bytes[28]; - EXPECT_EQ(last_msg_.certificate_bytes[29], 101) - << "incorrect value for last_msg_.certificate_bytes[29], expected 101, " - "is " - << last_msg_.certificate_bytes[29]; - EXPECT_EQ(last_msg_.certificate_bytes[30], 82) - << "incorrect value for last_msg_.certificate_bytes[30], expected 82, is " - << last_msg_.certificate_bytes[30]; - EXPECT_EQ(last_msg_.certificate_bytes[31], 182) - << "incorrect value for last_msg_.certificate_bytes[31], expected 182, " - "is " - << last_msg_.certificate_bytes[31]; - EXPECT_EQ(last_msg_.certificate_bytes[32], 25) - << "incorrect value for last_msg_.certificate_bytes[32], expected 25, is " - << last_msg_.certificate_bytes[32]; - EXPECT_EQ(last_msg_.certificate_bytes[33], 172) - << "incorrect value for last_msg_.certificate_bytes[33], expected 172, " - "is " - << last_msg_.certificate_bytes[33]; - EXPECT_EQ(last_msg_.certificate_bytes[34], 170) - << "incorrect value for last_msg_.certificate_bytes[34], expected 170, " - "is " - << last_msg_.certificate_bytes[34]; - EXPECT_EQ(last_msg_.certificate_bytes[35], 250) - << "incorrect value for last_msg_.certificate_bytes[35], expected 250, " - "is " - << last_msg_.certificate_bytes[35]; - EXPECT_EQ(last_msg_.certificate_bytes[36], 236) - << "incorrect value for last_msg_.certificate_bytes[36], expected 236, " - "is " - << last_msg_.certificate_bytes[36]; - EXPECT_EQ(last_msg_.certificate_bytes[37], 7) - << "incorrect value for last_msg_.certificate_bytes[37], expected 7, is " - << last_msg_.certificate_bytes[37]; - EXPECT_EQ(last_msg_.certificate_bytes[38], 119) - << "incorrect value for last_msg_.certificate_bytes[38], expected 119, " - "is " - << last_msg_.certificate_bytes[38]; - EXPECT_EQ(last_msg_.certificate_bytes[39], 4) - << "incorrect value for last_msg_.certificate_bytes[39], expected 4, is " - << last_msg_.certificate_bytes[39]; - EXPECT_EQ(last_msg_.certificate_bytes[40], 201) - << "incorrect value for last_msg_.certificate_bytes[40], expected 201, " - "is " - << last_msg_.certificate_bytes[40]; - EXPECT_EQ(last_msg_.certificate_bytes[41], 10) - << "incorrect value for last_msg_.certificate_bytes[41], expected 10, is " - << last_msg_.certificate_bytes[41]; - EXPECT_EQ(last_msg_.certificate_bytes[42], 14) - << "incorrect value for last_msg_.certificate_bytes[42], expected 14, is " - << last_msg_.certificate_bytes[42]; - EXPECT_EQ(last_msg_.certificate_bytes[43], 208) - << "incorrect value for last_msg_.certificate_bytes[43], expected 208, " - "is " - << last_msg_.certificate_bytes[43]; - EXPECT_EQ(last_msg_.certificate_bytes[44], 47) - << "incorrect value for last_msg_.certificate_bytes[44], expected 47, is " - << last_msg_.certificate_bytes[44]; - EXPECT_EQ(last_msg_.certificate_bytes[45], 126) - << "incorrect value for last_msg_.certificate_bytes[45], expected 126, " - "is " - << last_msg_.certificate_bytes[45]; - EXPECT_EQ(last_msg_.certificate_bytes[46], 49) - << "incorrect value for last_msg_.certificate_bytes[46], expected 49, is " - << last_msg_.certificate_bytes[46]; - EXPECT_EQ(last_msg_.certificate_bytes[47], 210) - << "incorrect value for last_msg_.certificate_bytes[47], expected 210, " - "is " - << last_msg_.certificate_bytes[47]; - EXPECT_EQ(last_msg_.certificate_bytes[48], 174) - << "incorrect value for last_msg_.certificate_bytes[48], expected 174, " - "is " - << last_msg_.certificate_bytes[48]; - EXPECT_EQ(last_msg_.certificate_bytes[49], 75) - << "incorrect value for last_msg_.certificate_bytes[49], expected 75, is " - << last_msg_.certificate_bytes[49]; - EXPECT_EQ(last_msg_.certificate_bytes[50], 221) - << "incorrect value for last_msg_.certificate_bytes[50], expected 221, " - "is " - << last_msg_.certificate_bytes[50]; - EXPECT_EQ(last_msg_.certificate_bytes[51], 203) - << "incorrect value for last_msg_.certificate_bytes[51], expected 203, " - "is " - << last_msg_.certificate_bytes[51]; - EXPECT_EQ(last_msg_.certificate_bytes[52], 24) - << "incorrect value for last_msg_.certificate_bytes[52], expected 24, is " - << last_msg_.certificate_bytes[52]; - EXPECT_EQ(last_msg_.certificate_bytes[53], 66) - << "incorrect value for last_msg_.certificate_bytes[53], expected 66, is " - << last_msg_.certificate_bytes[53]; - EXPECT_EQ(last_msg_.certificate_bytes[54], 52) - << "incorrect value for last_msg_.certificate_bytes[54], expected 52, is " - << last_msg_.certificate_bytes[54]; - EXPECT_EQ(last_msg_.certificate_bytes[55], 35) - << "incorrect value for last_msg_.certificate_bytes[55], expected 35, is " - << last_msg_.certificate_bytes[55]; - EXPECT_EQ(last_msg_.certificate_bytes[56], 26) - << "incorrect value for last_msg_.certificate_bytes[56], expected 26, is " - << last_msg_.certificate_bytes[56]; - EXPECT_EQ(last_msg_.certificate_bytes[57], 30) - << "incorrect value for last_msg_.certificate_bytes[57], expected 30, is " - << last_msg_.certificate_bytes[57]; - EXPECT_EQ(last_msg_.certificate_bytes[58], 140) - << "incorrect value for last_msg_.certificate_bytes[58], expected 140, " - "is " - << last_msg_.certificate_bytes[58]; - EXPECT_EQ(last_msg_.certificate_bytes[59], 111) - << "incorrect value for last_msg_.certificate_bytes[59], expected 111, " - "is " - << last_msg_.certificate_bytes[59]; - EXPECT_EQ(last_msg_.certificate_bytes[60], 246) - << "incorrect value for last_msg_.certificate_bytes[60], expected 246, " - "is " - << last_msg_.certificate_bytes[60]; - EXPECT_EQ(last_msg_.certificate_bytes[61], 39) - << "incorrect value for last_msg_.certificate_bytes[61], expected 39, is " - << last_msg_.certificate_bytes[61]; - EXPECT_EQ(last_msg_.certificate_bytes[62], 226) - << "incorrect value for last_msg_.certificate_bytes[62], expected 226, " - "is " - << last_msg_.certificate_bytes[62]; - EXPECT_EQ(last_msg_.certificate_bytes[63], 205) - << "incorrect value for last_msg_.certificate_bytes[63], expected 205, " - "is " - << last_msg_.certificate_bytes[63]; - EXPECT_EQ(last_msg_.certificate_bytes[64], 198) - << "incorrect value for last_msg_.certificate_bytes[64], expected 198, " - "is " - << last_msg_.certificate_bytes[64]; - EXPECT_EQ(last_msg_.certificate_bytes[65], 178) - << "incorrect value for last_msg_.certificate_bytes[65], expected 178, " - "is " - << last_msg_.certificate_bytes[65]; - EXPECT_EQ(last_msg_.certificate_bytes[66], 196) - << "incorrect value for last_msg_.certificate_bytes[66], expected 196, " - "is " - << last_msg_.certificate_bytes[66]; - EXPECT_EQ(last_msg_.certificate_bytes[67], 5) - << "incorrect value for last_msg_.certificate_bytes[67], expected 5, is " - << last_msg_.certificate_bytes[67]; - EXPECT_EQ(last_msg_.certificate_bytes[68], 81) - << "incorrect value for last_msg_.certificate_bytes[68], expected 81, is " - << last_msg_.certificate_bytes[68]; - EXPECT_EQ(last_msg_.certificate_bytes[69], 9) - << "incorrect value for last_msg_.certificate_bytes[69], expected 9, is " - << last_msg_.certificate_bytes[69]; - EXPECT_EQ(last_msg_.certificate_bytes[70], 44) - << "incorrect value for last_msg_.certificate_bytes[70], expected 44, is " - << last_msg_.certificate_bytes[70]; - EXPECT_EQ(last_msg_.certificate_bytes[71], 164) - << "incorrect value for last_msg_.certificate_bytes[71], expected 164, " - "is " - << last_msg_.certificate_bytes[71]; - EXPECT_EQ(last_msg_.certificate_bytes[72], 163) - << "incorrect value for last_msg_.certificate_bytes[72], expected 163, " - "is " - << last_msg_.certificate_bytes[72]; - EXPECT_EQ(last_msg_.certificate_bytes[73], 214) - << "incorrect value for last_msg_.certificate_bytes[73], expected 214, " - "is " - << last_msg_.certificate_bytes[73]; - EXPECT_EQ(last_msg_.certificate_bytes[74], 138) - << "incorrect value for last_msg_.certificate_bytes[74], expected 138, " - "is " - << last_msg_.certificate_bytes[74]; - EXPECT_EQ(last_msg_.certificate_bytes[75], 123) - << "incorrect value for last_msg_.certificate_bytes[75], expected 123, " - "is " - << last_msg_.certificate_bytes[75]; - EXPECT_EQ(last_msg_.certificate_bytes[76], 76) - << "incorrect value for last_msg_.certificate_bytes[76], expected 76, is " - << last_msg_.certificate_bytes[76]; - EXPECT_EQ(last_msg_.certificate_bytes[77], 74) - << "incorrect value for last_msg_.certificate_bytes[77], expected 74, is " - << last_msg_.certificate_bytes[77]; - EXPECT_EQ(last_msg_.certificate_bytes[78], 237) - << "incorrect value for last_msg_.certificate_bytes[78], expected 237, " - "is " - << last_msg_.certificate_bytes[78]; - EXPECT_EQ(last_msg_.certificate_bytes[79], 121) - << "incorrect value for last_msg_.certificate_bytes[79], expected 121, " - "is " - << last_msg_.certificate_bytes[79]; - EXPECT_EQ(last_msg_.certificate_bytes[80], 13) - << "incorrect value for last_msg_.certificate_bytes[80], expected 13, is " - << last_msg_.certificate_bytes[80]; - EXPECT_EQ(last_msg_.certificate_bytes[81], 137) - << "incorrect value for last_msg_.certificate_bytes[81], expected 137, " - "is " - << last_msg_.certificate_bytes[81]; - EXPECT_EQ(last_msg_.certificate_bytes[82], 186) - << "incorrect value for last_msg_.certificate_bytes[82], expected 186, " - "is " - << last_msg_.certificate_bytes[82]; - EXPECT_EQ(last_msg_.certificate_bytes[83], 97) - << "incorrect value for last_msg_.certificate_bytes[83], expected 97, is " - << last_msg_.certificate_bytes[83]; - EXPECT_EQ(last_msg_.certificate_bytes[84], 193) - << "incorrect value for last_msg_.certificate_bytes[84], expected 193, " - "is " - << last_msg_.certificate_bytes[84]; - EXPECT_EQ(last_msg_.certificate_bytes[85], 189) - << "incorrect value for last_msg_.certificate_bytes[85], expected 189, " - "is " - << last_msg_.certificate_bytes[85]; - EXPECT_EQ(last_msg_.certificate_bytes[86], 200) - << "incorrect value for last_msg_.certificate_bytes[86], expected 200, " - "is " - << last_msg_.certificate_bytes[86]; - EXPECT_EQ(last_msg_.certificate_bytes[87], 124) - << "incorrect value for last_msg_.certificate_bytes[87], expected 124, " - "is " - << last_msg_.certificate_bytes[87]; - EXPECT_EQ(last_msg_.certificate_bytes[88], 69) - << "incorrect value for last_msg_.certificate_bytes[88], expected 69, is " - << last_msg_.certificate_bytes[88]; - EXPECT_EQ(last_msg_.certificate_bytes[89], 115) - << "incorrect value for last_msg_.certificate_bytes[89], expected 115, " - "is " - << last_msg_.certificate_bytes[89]; - EXPECT_EQ(last_msg_.certificate_bytes[90], 230) - << "incorrect value for last_msg_.certificate_bytes[90], expected 230, " - "is " - << last_msg_.certificate_bytes[90]; - EXPECT_EQ(last_msg_.certificate_bytes[91], 159) - << "incorrect value for last_msg_.certificate_bytes[91], expected 159, " - "is " - << last_msg_.certificate_bytes[91]; - EXPECT_EQ(last_msg_.certificate_bytes[92], 185) - << "incorrect value for last_msg_.certificate_bytes[92], expected 185, " - "is " - << last_msg_.certificate_bytes[92]; - EXPECT_EQ(last_msg_.certificate_bytes[93], 158) - << "incorrect value for last_msg_.certificate_bytes[93], expected 158, " - "is " - << last_msg_.certificate_bytes[93]; - EXPECT_EQ(last_msg_.certificate_bytes[94], 51) - << "incorrect value for last_msg_.certificate_bytes[94], expected 51, is " - << last_msg_.certificate_bytes[94]; - EXPECT_EQ(last_msg_.certificate_bytes[95], 12) - << "incorrect value for last_msg_.certificate_bytes[95], expected 12, is " - << last_msg_.certificate_bytes[95]; - EXPECT_EQ(last_msg_.certificate_bytes[96], 225) - << "incorrect value for last_msg_.certificate_bytes[96], expected 225, " - "is " - << last_msg_.certificate_bytes[96]; - EXPECT_EQ(last_msg_.certificate_bytes[97], 65) - << "incorrect value for last_msg_.certificate_bytes[97], expected 65, is " - << last_msg_.certificate_bytes[97]; - EXPECT_EQ(last_msg_.certificate_bytes[98], 192) - << "incorrect value for last_msg_.certificate_bytes[98], expected 192, " - "is " - << last_msg_.certificate_bytes[98]; - EXPECT_EQ(last_msg_.certificate_bytes[99], 105) - << "incorrect value for last_msg_.certificate_bytes[99], expected 105, " - "is " - << last_msg_.certificate_bytes[99]; - EXPECT_EQ(last_msg_.certificate_bytes[100], 56) - << "incorrect value for last_msg_.certificate_bytes[100], expected 56, " - "is " - << last_msg_.certificate_bytes[100]; - EXPECT_EQ(last_msg_.certificate_bytes[101], 41) - << "incorrect value for last_msg_.certificate_bytes[101], expected 41, " - "is " - << last_msg_.certificate_bytes[101]; - EXPECT_EQ(last_msg_.certificate_bytes[102], 85) - << "incorrect value for last_msg_.certificate_bytes[102], expected 85, " - "is " - << last_msg_.certificate_bytes[102]; - EXPECT_EQ(last_msg_.certificate_bytes[103], 133) - << "incorrect value for last_msg_.certificate_bytes[103], expected 133, " - "is " - << last_msg_.certificate_bytes[103]; - EXPECT_EQ(last_msg_.certificate_bytes[104], 19) - << "incorrect value for last_msg_.certificate_bytes[104], expected 19, " - "is " - << last_msg_.certificate_bytes[104]; - EXPECT_EQ(last_msg_.certificate_bytes[105], 217) - << "incorrect value for last_msg_.certificate_bytes[105], expected 217, " - "is " - << last_msg_.certificate_bytes[105]; - EXPECT_EQ(last_msg_.certificate_bytes[106], 166) - << "incorrect value for last_msg_.certificate_bytes[106], expected 166, " - "is " - << last_msg_.certificate_bytes[106]; - EXPECT_EQ(last_msg_.certificate_bytes[107], 48) - << "incorrect value for last_msg_.certificate_bytes[107], expected 48, " - "is " - << last_msg_.certificate_bytes[107]; - EXPECT_EQ(last_msg_.certificate_bytes[108], 139) - << "incorrect value for last_msg_.certificate_bytes[108], expected 139, " - "is " - << last_msg_.certificate_bytes[108]; - EXPECT_EQ(last_msg_.certificate_bytes[109], 131) - << "incorrect value for last_msg_.certificate_bytes[109], expected 131, " - "is " - << last_msg_.certificate_bytes[109]; - EXPECT_EQ(last_msg_.certificate_bytes[110], 96) - << "incorrect value for last_msg_.certificate_bytes[110], expected 96, " - "is " - << last_msg_.certificate_bytes[110]; - EXPECT_EQ(last_msg_.certificate_bytes[111], 216) - << "incorrect value for last_msg_.certificate_bytes[111], expected 216, " - "is " - << last_msg_.certificate_bytes[111]; - EXPECT_EQ(last_msg_.certificate_bytes[112], 98) - << "incorrect value for last_msg_.certificate_bytes[112], expected 98, " - "is " - << last_msg_.certificate_bytes[112]; - EXPECT_EQ(last_msg_.certificate_bytes[113], 147) - << "incorrect value for last_msg_.certificate_bytes[113], expected 147, " - "is " - << last_msg_.certificate_bytes[113]; - EXPECT_EQ(last_msg_.certificate_bytes[114], 132) - << "incorrect value for last_msg_.certificate_bytes[114], expected 132, " - "is " - << last_msg_.certificate_bytes[114]; - EXPECT_EQ(last_msg_.certificate_bytes[115], 234) - << "incorrect value for last_msg_.certificate_bytes[115], expected 234, " - "is " - << last_msg_.certificate_bytes[115]; - EXPECT_EQ(last_msg_.certificate_bytes[116], 167) - << "incorrect value for last_msg_.certificate_bytes[116], expected 167, " - "is " - << last_msg_.certificate_bytes[116]; - EXPECT_EQ(last_msg_.certificate_bytes[117], 248) - << "incorrect value for last_msg_.certificate_bytes[117], expected 248, " - "is " - << last_msg_.certificate_bytes[117]; - EXPECT_EQ(last_msg_.certificate_bytes[118], 247) - << "incorrect value for last_msg_.certificate_bytes[118], expected 247, " - "is " - << last_msg_.certificate_bytes[118]; - EXPECT_EQ(last_msg_.certificate_bytes[119], 32) - << "incorrect value for last_msg_.certificate_bytes[119], expected 32, " - "is " - << last_msg_.certificate_bytes[119]; - EXPECT_EQ(last_msg_.certificate_bytes[120], 239) - << "incorrect value for last_msg_.certificate_bytes[120], expected 239, " - "is " - << last_msg_.certificate_bytes[120]; - EXPECT_EQ(last_msg_.certificate_bytes[121], 194) - << "incorrect value for last_msg_.certificate_bytes[121], expected 194, " - "is " - << last_msg_.certificate_bytes[121]; - EXPECT_EQ(last_msg_.certificate_bytes[122], 188) - << "incorrect value for last_msg_.certificate_bytes[122], expected 188, " - "is " - << last_msg_.certificate_bytes[122]; - EXPECT_EQ(last_msg_.certificate_bytes[123], 254) - << "incorrect value for last_msg_.certificate_bytes[123], expected 254, " - "is " - << last_msg_.certificate_bytes[123]; - EXPECT_EQ(last_msg_.certificate_bytes[124], 114) - << "incorrect value for last_msg_.certificate_bytes[124], expected 114, " - "is " - << last_msg_.certificate_bytes[124]; - EXPECT_EQ(last_msg_.certificate_bytes[125], 117) - << "incorrect value for last_msg_.certificate_bytes[125], expected 117, " - "is " - << last_msg_.certificate_bytes[125]; - EXPECT_EQ(last_msg_.certificate_bytes[126], 83) - << "incorrect value for last_msg_.certificate_bytes[126], expected 83, " - "is " - << last_msg_.certificate_bytes[126]; - EXPECT_EQ(last_msg_.certificate_bytes[127], 25) - << "incorrect value for last_msg_.certificate_bytes[127], expected 25, " - "is " - << last_msg_.certificate_bytes[127]; - EXPECT_EQ(last_msg_.certificate_bytes[128], 251) - << "incorrect value for last_msg_.certificate_bytes[128], expected 251, " - "is " - << last_msg_.certificate_bytes[128]; - EXPECT_EQ(last_msg_.certificate_bytes[129], 191) - << "incorrect value for last_msg_.certificate_bytes[129], expected 191, " - "is " - << last_msg_.certificate_bytes[129]; - EXPECT_EQ(last_msg_.certificate_bytes[130], 104) - << "incorrect value for last_msg_.certificate_bytes[130], expected 104, " - "is " - << last_msg_.certificate_bytes[130]; - EXPECT_EQ(last_msg_.certificate_bytes[131], 240) - << "incorrect value for last_msg_.certificate_bytes[131], expected 240, " - "is " - << last_msg_.certificate_bytes[131]; - EXPECT_EQ(last_msg_.certificate_bytes[132], 118) - << "incorrect value for last_msg_.certificate_bytes[132], expected 118, " - "is " - << last_msg_.certificate_bytes[132]; - EXPECT_EQ(last_msg_.certificate_bytes[133], 68) - << "incorrect value for last_msg_.certificate_bytes[133], expected 68, " - "is " - << last_msg_.certificate_bytes[133]; - EXPECT_EQ(last_msg_.certificate_bytes[134], 42) - << "incorrect value for last_msg_.certificate_bytes[134], expected 42, " - "is " - << last_msg_.certificate_bytes[134]; - EXPECT_EQ(last_msg_.certificate_bytes[135], 93) - << "incorrect value for last_msg_.certificate_bytes[135], expected 93, " - "is " - << last_msg_.certificate_bytes[135]; - EXPECT_EQ(last_msg_.certificate_bytes[136], 18) - << "incorrect value for last_msg_.certificate_bytes[136], expected 18, " - "is " - << last_msg_.certificate_bytes[136]; - EXPECT_EQ(last_msg_.certificate_bytes[137], 16) - << "incorrect value for last_msg_.certificate_bytes[137], expected 16, " - "is " - << last_msg_.certificate_bytes[137]; - EXPECT_EQ(last_msg_.certificate_bytes[138], 37) - << "incorrect value for last_msg_.certificate_bytes[138], expected 37, " - "is " - << last_msg_.certificate_bytes[138]; - EXPECT_EQ(last_msg_.certificate_bytes[139], 232) - << "incorrect value for last_msg_.certificate_bytes[139], expected 232, " - "is " - << last_msg_.certificate_bytes[139]; - EXPECT_EQ(last_msg_.certificate_bytes[140], 99) - << "incorrect value for last_msg_.certificate_bytes[140], expected 99, " - "is " - << last_msg_.certificate_bytes[140]; - EXPECT_EQ(last_msg_.certificate_bytes[141], 179) - << "incorrect value for last_msg_.certificate_bytes[141], expected 179, " - "is " - << last_msg_.certificate_bytes[141]; - EXPECT_EQ(last_msg_.certificate_bytes[142], 23) - << "incorrect value for last_msg_.certificate_bytes[142], expected 23, " - "is " - << last_msg_.certificate_bytes[142]; - EXPECT_EQ(last_msg_.certificate_bytes[143], 90) - << "incorrect value for last_msg_.certificate_bytes[143], expected 90, " - "is " - << last_msg_.certificate_bytes[143]; - EXPECT_EQ(last_msg_.certificate_bytes[144], 94) - << "incorrect value for last_msg_.certificate_bytes[144], expected 94, " - "is " - << last_msg_.certificate_bytes[144]; - EXPECT_EQ(last_msg_.certificate_bytes[145], 136) - << "incorrect value for last_msg_.certificate_bytes[145], expected 136, " - "is " - << last_msg_.certificate_bytes[145]; - EXPECT_EQ(last_msg_.certificate_bytes[146], 6) - << "incorrect value for last_msg_.certificate_bytes[146], expected 6, is " - << last_msg_.certificate_bytes[146]; - EXPECT_EQ(last_msg_.certificate_bytes[147], 125) - << "incorrect value for last_msg_.certificate_bytes[147], expected 125, " - "is " - << last_msg_.certificate_bytes[147]; - EXPECT_EQ(last_msg_.certificate_bytes[148], 91) - << "incorrect value for last_msg_.certificate_bytes[148], expected 91, " - "is " - << last_msg_.certificate_bytes[148]; - EXPECT_EQ(last_msg_.certificate_bytes[149], 255) - << "incorrect value for last_msg_.certificate_bytes[149], expected 255, " - "is " - << last_msg_.certificate_bytes[149]; - EXPECT_EQ(last_msg_.certificate_bytes[150], 15) - << "incorrect value for last_msg_.certificate_bytes[150], expected 15, " - "is " - << last_msg_.certificate_bytes[150]; - EXPECT_EQ(last_msg_.certificate_bytes[151], 71) - << "incorrect value for last_msg_.certificate_bytes[151], expected 71, " - "is " - << last_msg_.certificate_bytes[151]; - EXPECT_EQ(last_msg_.certificate_bytes[152], 43) - << "incorrect value for last_msg_.certificate_bytes[152], expected 43, " - "is " - << last_msg_.certificate_bytes[152]; - EXPECT_EQ(last_msg_.certificate_bytes[153], 46) - << "incorrect value for last_msg_.certificate_bytes[153], expected 46, " - "is " - << last_msg_.certificate_bytes[153]; - EXPECT_EQ(last_msg_.certificate_bytes[154], 25) - << "incorrect value for last_msg_.certificate_bytes[154], expected 25, " - "is " - << last_msg_.certificate_bytes[154]; - EXPECT_EQ(last_msg_.certificate_bytes[155], 252) - << "incorrect value for last_msg_.certificate_bytes[155], expected 252, " - "is " - << last_msg_.certificate_bytes[155]; - EXPECT_EQ(last_msg_.certificate_bytes[156], 229) - << "incorrect value for last_msg_.certificate_bytes[156], expected 229, " - "is " - << last_msg_.certificate_bytes[156]; - EXPECT_EQ(last_msg_.certificate_bytes[157], 80) - << "incorrect value for last_msg_.certificate_bytes[157], expected 80, " - "is " - << last_msg_.certificate_bytes[157]; - EXPECT_EQ(last_msg_.certificate_bytes[158], 143) - << "incorrect value for last_msg_.certificate_bytes[158], expected 143, " - "is " - << last_msg_.certificate_bytes[158]; - EXPECT_EQ(last_msg_.certificate_bytes[159], 58) - << "incorrect value for last_msg_.certificate_bytes[159], expected 58, " - "is " - << last_msg_.certificate_bytes[159]; - EXPECT_EQ(last_msg_.certificate_bytes[160], 241) - << "incorrect value for last_msg_.certificate_bytes[160], expected 241, " - "is " - << last_msg_.certificate_bytes[160]; - EXPECT_EQ(last_msg_.certificate_bytes[161], 11) - << "incorrect value for last_msg_.certificate_bytes[161], expected 11, " - "is " - << last_msg_.certificate_bytes[161]; - EXPECT_EQ(last_msg_.certificate_bytes[162], 62) - << "incorrect value for last_msg_.certificate_bytes[162], expected 62, " - "is " - << last_msg_.certificate_bytes[162]; - EXPECT_EQ(last_msg_.certificate_bytes[163], 181) - << "incorrect value for last_msg_.certificate_bytes[163], expected 181, " - "is " - << last_msg_.certificate_bytes[163]; - EXPECT_EQ(last_msg_.certificate_bytes[164], 155) - << "incorrect value for last_msg_.certificate_bytes[164], expected 155, " - "is " - << last_msg_.certificate_bytes[164]; - EXPECT_EQ(last_msg_.certificate_bytes[165], 53) - << "incorrect value for last_msg_.certificate_bytes[165], expected 53, " - "is " - << last_msg_.certificate_bytes[165]; - EXPECT_EQ(last_msg_.certificate_bytes[166], 153) - << "incorrect value for last_msg_.certificate_bytes[166], expected 153, " - "is " - << last_msg_.certificate_bytes[166]; - EXPECT_EQ(last_msg_.certificate_bytes[167], 149) - << "incorrect value for last_msg_.certificate_bytes[167], expected 149, " - "is " - << last_msg_.certificate_bytes[167]; - EXPECT_EQ(last_msg_.certificate_bytes[168], 152) - << "incorrect value for last_msg_.certificate_bytes[168], expected 152, " - "is " - << last_msg_.certificate_bytes[168]; - EXPECT_EQ(last_msg_.certificate_bytes[169], 227) - << "incorrect value for last_msg_.certificate_bytes[169], expected 227, " - "is " - << last_msg_.certificate_bytes[169]; - EXPECT_EQ(last_msg_.certificate_bytes[170], 150) - << "incorrect value for last_msg_.certificate_bytes[170], expected 150, " - "is " - << last_msg_.certificate_bytes[170]; - EXPECT_EQ(last_msg_.certificate_bytes[171], 87) - << "incorrect value for last_msg_.certificate_bytes[171], expected 87, " - "is " - << last_msg_.certificate_bytes[171]; - EXPECT_EQ(last_msg_.certificate_bytes[172], 112) - << "incorrect value for last_msg_.certificate_bytes[172], expected 112, " - "is " - << last_msg_.certificate_bytes[172]; - EXPECT_EQ(last_msg_.certificate_bytes[173], 165) - << "incorrect value for last_msg_.certificate_bytes[173], expected 165, " - "is " - << last_msg_.certificate_bytes[173]; - EXPECT_EQ(last_msg_.certificate_bytes[174], 2) - << "incorrect value for last_msg_.certificate_bytes[174], expected 2, is " - << last_msg_.certificate_bytes[174]; - EXPECT_EQ(last_msg_.certificate_bytes[175], 128) - << "incorrect value for last_msg_.certificate_bytes[175], expected 128, " - "is " - << last_msg_.certificate_bytes[175]; - EXPECT_EQ(last_msg_.certificate_bytes[176], 231) - << "incorrect value for last_msg_.certificate_bytes[176], expected 231, " - "is " - << last_msg_.certificate_bytes[176]; - EXPECT_EQ(last_msg_.certificate_bytes[177], 25) - << "incorrect value for last_msg_.certificate_bytes[177], expected 25, " - "is " - << last_msg_.certificate_bytes[177]; - EXPECT_EQ(last_msg_.certificate_bytes[178], 157) - << "incorrect value for last_msg_.certificate_bytes[178], expected 157, " - "is " - << last_msg_.certificate_bytes[178]; - EXPECT_EQ(last_msg_.certificate_bytes[179], 244) - << "incorrect value for last_msg_.certificate_bytes[179], expected 244, " - "is " - << last_msg_.certificate_bytes[179]; - EXPECT_EQ(last_msg_.certificate_bytes[180], 204) - << "incorrect value for last_msg_.certificate_bytes[180], expected 204, " - "is " - << last_msg_.certificate_bytes[180]; - EXPECT_EQ(last_msg_.certificate_bytes[181], 108) - << "incorrect value for last_msg_.certificate_bytes[181], expected 108, " - "is " - << last_msg_.certificate_bytes[181]; - EXPECT_EQ(last_msg_.certificate_bytes[182], 253) - << "incorrect value for last_msg_.certificate_bytes[182], expected 253, " - "is " - << last_msg_.certificate_bytes[182]; - EXPECT_EQ(last_msg_.certificate_bytes[183], 127) - << "incorrect value for last_msg_.certificate_bytes[183], expected 127, " - "is " - << last_msg_.certificate_bytes[183]; - EXPECT_EQ(last_msg_.certificate_bytes[184], 122) - << "incorrect value for last_msg_.certificate_bytes[184], expected 122, " - "is " - << last_msg_.certificate_bytes[184]; - EXPECT_EQ(last_msg_.certificate_bytes[185], 145) - << "incorrect value for last_msg_.certificate_bytes[185], expected 145, " - "is " - << last_msg_.certificate_bytes[185]; - EXPECT_EQ(last_msg_.certificate_bytes[186], 113) - << "incorrect value for last_msg_.certificate_bytes[186], expected 113, " - "is " - << last_msg_.certificate_bytes[186]; - EXPECT_EQ(last_msg_.certificate_bytes[187], 162) - << "incorrect value for last_msg_.certificate_bytes[187], expected 162, " - "is " - << last_msg_.certificate_bytes[187]; - EXPECT_EQ(last_msg_.certificate_bytes[188], 197) - << "incorrect value for last_msg_.certificate_bytes[188], expected 197, " - "is " - << last_msg_.certificate_bytes[188]; - EXPECT_EQ(last_msg_.certificate_bytes[189], 171) - << "incorrect value for last_msg_.certificate_bytes[189], expected 171, " - "is " - << last_msg_.certificate_bytes[189]; - EXPECT_EQ(last_msg_.certificate_bytes[190], 199) - << "incorrect value for last_msg_.certificate_bytes[190], expected 199, " - "is " - << last_msg_.certificate_bytes[190]; - EXPECT_EQ(last_msg_.certificate_bytes[191], 54) - << "incorrect value for last_msg_.certificate_bytes[191], expected 54, " - "is " - << last_msg_.certificate_bytes[191]; - EXPECT_EQ(last_msg_.certificate_bytes[192], 184) - << "incorrect value for last_msg_.certificate_bytes[192], expected 184, " - "is " - << last_msg_.certificate_bytes[192]; - EXPECT_EQ(last_msg_.certificate_bytes[193], 222) - << "incorrect value for last_msg_.certificate_bytes[193], expected 222, " - "is " - << last_msg_.certificate_bytes[193]; - EXPECT_EQ(last_msg_.certificate_bytes[194], 206) - << "incorrect value for last_msg_.certificate_bytes[194], expected 206, " - "is " - << last_msg_.certificate_bytes[194]; - EXPECT_EQ(last_msg_.certificate_bytes[195], 67) - << "incorrect value for last_msg_.certificate_bytes[195], expected 67, " - "is " - << last_msg_.certificate_bytes[195]; - EXPECT_EQ(last_msg_.certificate_bytes[196], 144) - << "incorrect value for last_msg_.certificate_bytes[196], expected 144, " - "is " - << last_msg_.certificate_bytes[196]; - EXPECT_EQ(last_msg_.certificate_bytes[197], 78) - << "incorrect value for last_msg_.certificate_bytes[197], expected 78, " - "is " - << last_msg_.certificate_bytes[197]; - EXPECT_EQ(last_msg_.certificate_bytes[198], 187) - << "incorrect value for last_msg_.certificate_bytes[198], expected 187, " - "is " - << last_msg_.certificate_bytes[198]; - EXPECT_EQ(last_msg_.certificate_bytes[199], 207) - << "incorrect value for last_msg_.certificate_bytes[199], expected 207, " - "is " - << last_msg_.certificate_bytes[199]; - EXPECT_EQ(last_msg_.certificate_bytes[200], 60) - << "incorrect value for last_msg_.certificate_bytes[200], expected 60, " - "is " - << last_msg_.certificate_bytes[200]; - EXPECT_EQ(last_msg_.certificate_bytes[201], 211) - << "incorrect value for last_msg_.certificate_bytes[201], expected 211, " - "is " - << last_msg_.certificate_bytes[201]; - EXPECT_EQ(last_msg_.certificate_bytes[202], 141) - << "incorrect value for last_msg_.certificate_bytes[202], expected 141, " - "is " - << last_msg_.certificate_bytes[202]; - EXPECT_EQ(last_msg_.certificate_bytes[203], 135) - << "incorrect value for last_msg_.certificate_bytes[203], expected 135, " - "is " - << last_msg_.certificate_bytes[203]; - EXPECT_EQ(last_msg_.certificate_bytes[204], 106) - << "incorrect value for last_msg_.certificate_bytes[204], expected 106, " - "is " - << last_msg_.certificate_bytes[204]; - EXPECT_EQ(last_msg_.certificate_bytes[205], 220) - << "incorrect value for last_msg_.certificate_bytes[205], expected 220, " - "is " - << last_msg_.certificate_bytes[205]; - EXPECT_EQ(last_msg_.certificate_bytes[206], 79) - << "incorrect value for last_msg_.certificate_bytes[206], expected 79, " - "is " - << last_msg_.certificate_bytes[206]; - EXPECT_EQ(last_msg_.certificate_bytes[207], 183) - << "incorrect value for last_msg_.certificate_bytes[207], expected 183, " - "is " - << last_msg_.certificate_bytes[207]; - EXPECT_EQ(last_msg_.certificate_bytes[208], 245) - << "incorrect value for last_msg_.certificate_bytes[208], expected 245, " - "is " - << last_msg_.certificate_bytes[208]; - EXPECT_EQ(last_msg_.certificate_bytes[209], 21) - << "incorrect value for last_msg_.certificate_bytes[209], expected 21, " - "is " - << last_msg_.certificate_bytes[209]; - EXPECT_EQ(last_msg_.certificate_bytes[210], 161) - << "incorrect value for last_msg_.certificate_bytes[210], expected 161, " - "is " - << last_msg_.certificate_bytes[210]; - EXPECT_EQ(last_msg_.certificate_bytes[211], 168) - << "incorrect value for last_msg_.certificate_bytes[211], expected 168, " - "is " - << last_msg_.certificate_bytes[211]; - EXPECT_EQ(last_msg_.certificate_bytes[212], 34) - << "incorrect value for last_msg_.certificate_bytes[212], expected 34, " - "is " - << last_msg_.certificate_bytes[212]; - EXPECT_EQ(last_msg_.certificate_bytes[213], 129) - << "incorrect value for last_msg_.certificate_bytes[213], expected 129, " - "is " - << last_msg_.certificate_bytes[213]; - EXPECT_EQ(last_msg_.certificate_bytes[214], 50) - << "incorrect value for last_msg_.certificate_bytes[214], expected 50, " - "is " - << last_msg_.certificate_bytes[214]; - EXPECT_EQ(last_msg_.certificate_bytes[215], 176) - << "incorrect value for last_msg_.certificate_bytes[215], expected 176, " - "is " - << last_msg_.certificate_bytes[215]; - EXPECT_EQ(last_msg_.certificate_bytes[216], 1) - << "incorrect value for last_msg_.certificate_bytes[216], expected 1, is " - << last_msg_.certificate_bytes[216]; - EXPECT_EQ(last_msg_.certificate_bytes[217], 218) - << "incorrect value for last_msg_.certificate_bytes[217], expected 218, " - "is " - << last_msg_.certificate_bytes[217]; - EXPECT_EQ(last_msg_.certificate_bytes[218], 20) - << "incorrect value for last_msg_.certificate_bytes[218], expected 20, " - "is " - << last_msg_.certificate_bytes[218]; - EXPECT_EQ(last_msg_.certificate_bytes[219], 130) - << "incorrect value for last_msg_.certificate_bytes[219], expected 130, " - "is " - << last_msg_.certificate_bytes[219]; - EXPECT_EQ(last_msg_.certificate_bytes[220], 59) - << "incorrect value for last_msg_.certificate_bytes[220], expected 59, " - "is " - << last_msg_.certificate_bytes[220]; - EXPECT_EQ(last_msg_.certificate_bytes[221], 249) - << "incorrect value for last_msg_.certificate_bytes[221], expected 249, " - "is " - << last_msg_.certificate_bytes[221]; - EXPECT_EQ(last_msg_.certificate_bytes[222], 109) - << "incorrect value for last_msg_.certificate_bytes[222], expected 109, " - "is " - << last_msg_.certificate_bytes[222]; - EXPECT_EQ(last_msg_.certificate_bytes[223], 219) - << "incorrect value for last_msg_.certificate_bytes[223], expected 219, " - "is " - << last_msg_.certificate_bytes[223]; - EXPECT_EQ(last_msg_.certificate_bytes[224], 0) - << "incorrect value for last_msg_.certificate_bytes[224], expected 0, is " - << last_msg_.certificate_bytes[224]; - EXPECT_EQ(last_msg_.certificate_bytes[225], 100) - << "incorrect value for last_msg_.certificate_bytes[225], expected 100, " - "is " - << last_msg_.certificate_bytes[225]; - EXPECT_EQ(last_msg_.certificate_bytes[226], 103) - << "incorrect value for last_msg_.certificate_bytes[226], expected 103, " - "is " - << last_msg_.certificate_bytes[226]; - EXPECT_EQ(last_msg_.certificate_bytes[227], 55) - << "incorrect value for last_msg_.certificate_bytes[227], expected 55, " - "is " - << last_msg_.certificate_bytes[227]; - EXPECT_EQ(last_msg_.certificate_bytes[228], 29) - << "incorrect value for last_msg_.certificate_bytes[228], expected 29, " - "is " - << last_msg_.certificate_bytes[228]; - EXPECT_EQ(last_msg_.certificate_bytes[229], 242) - << "incorrect value for last_msg_.certificate_bytes[229], expected 242, " - "is " - << last_msg_.certificate_bytes[229]; - EXPECT_EQ(last_msg_.certificate_bytes[230], 110) - << "incorrect value for last_msg_.certificate_bytes[230], expected 110, " - "is " - << last_msg_.certificate_bytes[230]; - EXPECT_EQ(last_msg_.certificate_bytes[231], 154) - << "incorrect value for last_msg_.certificate_bytes[231], expected 154, " - "is " - << last_msg_.certificate_bytes[231]; - EXPECT_EQ(last_msg_.certificate_bytes[232], 190) - << "incorrect value for last_msg_.certificate_bytes[232], expected 190, " - "is " - << last_msg_.certificate_bytes[232]; - EXPECT_EQ(last_msg_.certificate_bytes[233], 233) - << "incorrect value for last_msg_.certificate_bytes[233], expected 233, " - "is " - << last_msg_.certificate_bytes[233]; - EXPECT_EQ(last_msg_.certificate_bytes[234], 142) - << "incorrect value for last_msg_.certificate_bytes[234], expected 142, " - "is " - << last_msg_.certificate_bytes[234]; - EXPECT_EQ(last_msg_.certificate_bytes[235], 45) - << "incorrect value for last_msg_.certificate_bytes[235], expected 45, " - "is " - << last_msg_.certificate_bytes[235]; - EXPECT_EQ(last_msg_.certificate_bytes[236], 61) - << "incorrect value for last_msg_.certificate_bytes[236], expected 61, " - "is " - << last_msg_.certificate_bytes[236]; - EXPECT_EQ(last_msg_.certificate_bytes[237], 215) - << "incorrect value for last_msg_.certificate_bytes[237], expected 215, " - "is " - << last_msg_.certificate_bytes[237]; - EXPECT_EQ(last_msg_.certificate_bytes[238], 202) - << "incorrect value for last_msg_.certificate_bytes[238], expected 202, " - "is " - << last_msg_.certificate_bytes[238]; - EXPECT_EQ(last_msg_.certificate_bytes[239], 238) - << "incorrect value for last_msg_.certificate_bytes[239], expected 238, " - "is " - << last_msg_.certificate_bytes[239]; - EXPECT_EQ(last_msg_.certificate_bytes[240], 88) - << "incorrect value for last_msg_.certificate_bytes[240], expected 88, " - "is " - << last_msg_.certificate_bytes[240]; - EXPECT_EQ(last_msg_.certificate_bytes[241], 209) - << "incorrect value for last_msg_.certificate_bytes[241], expected 209, " - "is " - << last_msg_.certificate_bytes[241]; - EXPECT_EQ(last_msg_.certificate_bytes[242], 70) - << "incorrect value for last_msg_.certificate_bytes[242], expected 70, " - "is " - << last_msg_.certificate_bytes[242]; - EXPECT_EQ(last_msg_.certificate_bytes[243], 63) - << "incorrect value for last_msg_.certificate_bytes[243], expected 63, " - "is " - << last_msg_.certificate_bytes[243]; - EXPECT_EQ(last_msg_.certificate_bytes[244], 151) - << "incorrect value for last_msg_.certificate_bytes[244], expected 151, " - "is " - << last_msg_.certificate_bytes[244]; - EXPECT_EQ(last_msg_.certificate_bytes[245], 27) - << "incorrect value for last_msg_.certificate_bytes[245], expected 27, " - "is " - << last_msg_.certificate_bytes[245]; - EXPECT_EQ(last_msg_.certificate_bytes[246], 102) - << "incorrect value for last_msg_.certificate_bytes[246], expected 102, " - "is " - << last_msg_.certificate_bytes[246]; - EXPECT_EQ(last_msg_.certificate_id[0], 10) - << "incorrect value for last_msg_.certificate_id[0], expected 10, is " - << last_msg_.certificate_id[0]; - EXPECT_EQ(last_msg_.certificate_id[1], 11) - << "incorrect value for last_msg_.certificate_id[1], expected 11, is " - << last_msg_.certificate_id[1]; - EXPECT_EQ(last_msg_.certificate_id[2], 12) - << "incorrect value for last_msg_.certificate_id[2], expected 12, is " - << last_msg_.certificate_id[2]; - EXPECT_EQ(last_msg_.certificate_id[3], 13) - << "incorrect value for last_msg_.certificate_id[3], expected 13, is " - << last_msg_.certificate_id[3]; - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_certificate_bytes, 247) - << "incorrect value for last_msg_.n_certificate_bytes, expected 247, is " - << last_msg_.n_certificate_bytes; - EXPECT_EQ(last_msg_.n_msg, 48) - << "incorrect value for last_msg_.n_msg, expected 48, is " - << last_msg_.n_msg; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaCertificate, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[0], + greater.certificate_bytes[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[1], + greater.certificate_bytes[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[2], + greater.certificate_bytes[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[3], + greater.certificate_bytes[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[4], + greater.certificate_bytes[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[5], + greater.certificate_bytes[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[6], + greater.certificate_bytes[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[7], + greater.certificate_bytes[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[8], + greater.certificate_bytes[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[9], + greater.certificate_bytes[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[10], + greater.certificate_bytes[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[11], + greater.certificate_bytes[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[12], + greater.certificate_bytes[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[13], + greater.certificate_bytes[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[14], + greater.certificate_bytes[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[15], + greater.certificate_bytes[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[16], + greater.certificate_bytes[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[17], + greater.certificate_bytes[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[18], + greater.certificate_bytes[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[19], + greater.certificate_bytes[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[20], + greater.certificate_bytes[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[21], + greater.certificate_bytes[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[22], + greater.certificate_bytes[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[23], + greater.certificate_bytes[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[24], + greater.certificate_bytes[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[25], + greater.certificate_bytes[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[26], + greater.certificate_bytes[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[27], + greater.certificate_bytes[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[28], + greater.certificate_bytes[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[29], + greater.certificate_bytes[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[30], + greater.certificate_bytes[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[31], + greater.certificate_bytes[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[32], + greater.certificate_bytes[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[33], + greater.certificate_bytes[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[34], + greater.certificate_bytes[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[35], + greater.certificate_bytes[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[36], + greater.certificate_bytes[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[37], + greater.certificate_bytes[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[38], + greater.certificate_bytes[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[39], + greater.certificate_bytes[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[40], + greater.certificate_bytes[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[41], + greater.certificate_bytes[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[42], + greater.certificate_bytes[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[43], + greater.certificate_bytes[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[44], + greater.certificate_bytes[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[45], + greater.certificate_bytes[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[46], + greater.certificate_bytes[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[47], + greater.certificate_bytes[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[48], + greater.certificate_bytes[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[49], + greater.certificate_bytes[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[50], + greater.certificate_bytes[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[51], + greater.certificate_bytes[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[52], + greater.certificate_bytes[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[53], + greater.certificate_bytes[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[54], + greater.certificate_bytes[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[55], + greater.certificate_bytes[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[56], + greater.certificate_bytes[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[57], + greater.certificate_bytes[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[58], + greater.certificate_bytes[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[59], + greater.certificate_bytes[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[60], + greater.certificate_bytes[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[61], + greater.certificate_bytes[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[62], + greater.certificate_bytes[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[63], + greater.certificate_bytes[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[64], + greater.certificate_bytes[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[65], + greater.certificate_bytes[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[66], + greater.certificate_bytes[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[67], + greater.certificate_bytes[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[68], + greater.certificate_bytes[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[69], + greater.certificate_bytes[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[70], + greater.certificate_bytes[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[71], + greater.certificate_bytes[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[72], + greater.certificate_bytes[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[73], + greater.certificate_bytes[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[74], + greater.certificate_bytes[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[75], + greater.certificate_bytes[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[76], + greater.certificate_bytes[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[77], + greater.certificate_bytes[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[78], + greater.certificate_bytes[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[79], + greater.certificate_bytes[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[80], + greater.certificate_bytes[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[81], + greater.certificate_bytes[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[82], + greater.certificate_bytes[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[83], + greater.certificate_bytes[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[84], + greater.certificate_bytes[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[85], + greater.certificate_bytes[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[86], + greater.certificate_bytes[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[87], + greater.certificate_bytes[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[88], + greater.certificate_bytes[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[89], + greater.certificate_bytes[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[90], + greater.certificate_bytes[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[91], + greater.certificate_bytes[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[92], + greater.certificate_bytes[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[93], + greater.certificate_bytes[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[94], + greater.certificate_bytes[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[95], + greater.certificate_bytes[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[96], + greater.certificate_bytes[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[97], + greater.certificate_bytes[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[98], + greater.certificate_bytes[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[99], + greater.certificate_bytes[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[100], + greater.certificate_bytes[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[101], + greater.certificate_bytes[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[102], + greater.certificate_bytes[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[103], + greater.certificate_bytes[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[104], + greater.certificate_bytes[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[105], + greater.certificate_bytes[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[106], + greater.certificate_bytes[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[107], + greater.certificate_bytes[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[108], + greater.certificate_bytes[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[109], + greater.certificate_bytes[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[110], + greater.certificate_bytes[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[111], + greater.certificate_bytes[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[112], + greater.certificate_bytes[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[113], + greater.certificate_bytes[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[114], + greater.certificate_bytes[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[115], + greater.certificate_bytes[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[116], + greater.certificate_bytes[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[117], + greater.certificate_bytes[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[118], + greater.certificate_bytes[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[119], + greater.certificate_bytes[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[120], + greater.certificate_bytes[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[121], + greater.certificate_bytes[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[122], + greater.certificate_bytes[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[123], + greater.certificate_bytes[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[124], + greater.certificate_bytes[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[125], + greater.certificate_bytes[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[126], + greater.certificate_bytes[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[127], + greater.certificate_bytes[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[128], + greater.certificate_bytes[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[129], + greater.certificate_bytes[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[130], + greater.certificate_bytes[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[131], + greater.certificate_bytes[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[132], + greater.certificate_bytes[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[133], + greater.certificate_bytes[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[134], + greater.certificate_bytes[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[135], + greater.certificate_bytes[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[136], + greater.certificate_bytes[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[137], + greater.certificate_bytes[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[138], + greater.certificate_bytes[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[139], + greater.certificate_bytes[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[140], + greater.certificate_bytes[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[141], + greater.certificate_bytes[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[142], + greater.certificate_bytes[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[143], + greater.certificate_bytes[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[144], + greater.certificate_bytes[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[145], + greater.certificate_bytes[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[146], + greater.certificate_bytes[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[147], + greater.certificate_bytes[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[148], + greater.certificate_bytes[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[149], + greater.certificate_bytes[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[150], + greater.certificate_bytes[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[151], + greater.certificate_bytes[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[152], + greater.certificate_bytes[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[153], + greater.certificate_bytes[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[154], + greater.certificate_bytes[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[155], + greater.certificate_bytes[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[156], + greater.certificate_bytes[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[157], + greater.certificate_bytes[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[158], + greater.certificate_bytes[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[159], + greater.certificate_bytes[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[160], + greater.certificate_bytes[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[161], + greater.certificate_bytes[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[162], + greater.certificate_bytes[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[163], + greater.certificate_bytes[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[164], + greater.certificate_bytes[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[165], + greater.certificate_bytes[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[166], + greater.certificate_bytes[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[167], + greater.certificate_bytes[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[168], + greater.certificate_bytes[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[169], + greater.certificate_bytes[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[170], + greater.certificate_bytes[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[171], + greater.certificate_bytes[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[172], + greater.certificate_bytes[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[173], + greater.certificate_bytes[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[174], + greater.certificate_bytes[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[175], + greater.certificate_bytes[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[176], + greater.certificate_bytes[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[177], + greater.certificate_bytes[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[178], + greater.certificate_bytes[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[179], + greater.certificate_bytes[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[180], + greater.certificate_bytes[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[181], + greater.certificate_bytes[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[182], + greater.certificate_bytes[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[183], + greater.certificate_bytes[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[184], + greater.certificate_bytes[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[185], + greater.certificate_bytes[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[186], + greater.certificate_bytes[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[187], + greater.certificate_bytes[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[188], + greater.certificate_bytes[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[189], + greater.certificate_bytes[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[190], + greater.certificate_bytes[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[191], + greater.certificate_bytes[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[192], + greater.certificate_bytes[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[193], + greater.certificate_bytes[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[194], + greater.certificate_bytes[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[195], + greater.certificate_bytes[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[196], + greater.certificate_bytes[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[197], + greater.certificate_bytes[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[198], + greater.certificate_bytes[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[199], + greater.certificate_bytes[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[200], + greater.certificate_bytes[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[201], + greater.certificate_bytes[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[202], + greater.certificate_bytes[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[203], + greater.certificate_bytes[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[204], + greater.certificate_bytes[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[205], + greater.certificate_bytes[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[206], + greater.certificate_bytes[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[207], + greater.certificate_bytes[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[208], + greater.certificate_bytes[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[209], + greater.certificate_bytes[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[210], + greater.certificate_bytes[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[211], + greater.certificate_bytes[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[212], + greater.certificate_bytes[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[213], + greater.certificate_bytes[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[214], + greater.certificate_bytes[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[215], + greater.certificate_bytes[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[216], + greater.certificate_bytes[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[217], + greater.certificate_bytes[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[218], + greater.certificate_bytes[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[219], + greater.certificate_bytes[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[220], + greater.certificate_bytes[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[221], + greater.certificate_bytes[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[222], + greater.certificate_bytes[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[223], + greater.certificate_bytes[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[224], + greater.certificate_bytes[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[225], + greater.certificate_bytes[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[226], + greater.certificate_bytes[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[227], + greater.certificate_bytes[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[228], + greater.certificate_bytes[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[229], + greater.certificate_bytes[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[230], + greater.certificate_bytes[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[231], + greater.certificate_bytes[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[232], + greater.certificate_bytes[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[233], + greater.certificate_bytes[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[234], + greater.certificate_bytes[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[235], + greater.certificate_bytes[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[236], + greater.certificate_bytes[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[237], + greater.certificate_bytes[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[238], + greater.certificate_bytes[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[239], + greater.certificate_bytes[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[240], + greater.certificate_bytes[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[241], + greater.certificate_bytes[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[242], + greater.certificate_bytes[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[243], + greater.certificate_bytes[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[244], + greater.certificate_bytes[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[245], + greater.certificate_bytes[245]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[246], + greater.certificate_bytes[246]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[0], greater.certificate_id[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[1], greater.certificate_id[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[2], greater.certificate_id[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[3], greater.certificate_id[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.n_certificate_bytes, + greater.n_certificate_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_certificate_t lesser = info.test_msg; + sbp_msg_ecdsa_certificate_t greater = info.test_msg; + make_lesser_greater(lesser.n_msg, greater.n_msg); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEcdsaCertificate); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ECDSA_CERTIFICATE"); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ecdsa_certificate_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ecdsa_certificate_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ecdsa_certificate, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ecdsa_certificate, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_certificate_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEcdsaCertificate, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaCertificate0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEcdsaCertificate, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignature.cc b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignature.cc index c0993550bf..d962a24f6d 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignature.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignature.cc @@ -16,66 +16,527 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEcdsaSignature0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEcdsaSignature0 : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEcdsaSignature0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgEcdsaSignature0() { + assign(test_msg_.certificate_id[0], 1); + + assign(test_msg_.certificate_id[1], 2); + + assign(test_msg_.certificate_id[2], 3); + + assign(test_msg_.certificate_id[3], 4); + assign(test_msg_.flags, 0); + assign(test_msg_.n_signed_messages, 3); + assign(test_msg_.on_demand_counter, 2); + + assign(test_msg_.signature.data[0], 0); + + assign(test_msg_.signature.data[1], 1); + + assign(test_msg_.signature.data[2], 2); + + assign(test_msg_.signature.data[3], 3); + + assign(test_msg_.signature.data[4], 4); + + assign(test_msg_.signature.data[5], 5); + + assign(test_msg_.signature.data[6], 6); + + assign(test_msg_.signature.data[7], 7); + + assign(test_msg_.signature.data[8], 8); + + assign(test_msg_.signature.data[9], 9); + + assign(test_msg_.signature.data[10], 10); + + assign(test_msg_.signature.data[11], 11); + + assign(test_msg_.signature.data[12], 12); + + assign(test_msg_.signature.data[13], 13); + + assign(test_msg_.signature.data[14], 14); + + assign(test_msg_.signature.data[15], 15); + + assign(test_msg_.signature.data[16], 16); + + assign(test_msg_.signature.data[17], 17); + + assign(test_msg_.signature.data[18], 18); + + assign(test_msg_.signature.data[19], 19); + + assign(test_msg_.signature.data[20], 20); + + assign(test_msg_.signature.data[21], 21); + + assign(test_msg_.signature.data[22], 22); + + assign(test_msg_.signature.data[23], 23); + + assign(test_msg_.signature.data[24], 24); + + assign(test_msg_.signature.data[25], 25); + + assign(test_msg_.signature.data[26], 26); + + assign(test_msg_.signature.data[27], 27); + + assign(test_msg_.signature.data[28], 28); + + assign(test_msg_.signature.data[29], 29); + + assign(test_msg_.signature.data[30], 30); + + assign(test_msg_.signature.data[31], 31); + + assign(test_msg_.signature.data[32], 32); + + assign(test_msg_.signature.data[33], 33); + + assign(test_msg_.signature.data[34], 34); + + assign(test_msg_.signature.data[35], 35); + + assign(test_msg_.signature.data[36], 36); + + assign(test_msg_.signature.data[37], 37); + + assign(test_msg_.signature.data[38], 38); + + assign(test_msg_.signature.data[39], 39); + + assign(test_msg_.signature.data[40], 40); + + assign(test_msg_.signature.data[41], 41); + + assign(test_msg_.signature.data[42], 42); + + assign(test_msg_.signature.data[43], 43); + + assign(test_msg_.signature.data[44], 44); + + assign(test_msg_.signature.data[45], 45); + + assign(test_msg_.signature.data[46], 46); + + assign(test_msg_.signature.data[47], 47); + + assign(test_msg_.signature.data[48], 48); + + assign(test_msg_.signature.data[49], 49); + + assign(test_msg_.signature.data[50], 50); + + assign(test_msg_.signature.data[51], 51); + + assign(test_msg_.signature.data[52], 52); + + assign(test_msg_.signature.data[53], 53); + + assign(test_msg_.signature.data[54], 54); + + assign(test_msg_.signature.data[55], 55); + + assign(test_msg_.signature.data[56], 56); + + assign(test_msg_.signature.data[57], 57); + + assign(test_msg_.signature.data[58], 58); + + assign(test_msg_.signature.data[59], 59); + + assign(test_msg_.signature.data[60], 60); + + assign(test_msg_.signature.data[61], 61); + + assign(test_msg_.signature.data[62], 62); + + assign(test_msg_.signature.data[63], 63); + + assign(test_msg_.signature.data[64], 64); + + assign(test_msg_.signature.data[65], 65); + + assign(test_msg_.signature.data[66], 66); + + assign(test_msg_.signature.data[67], 67); + + assign(test_msg_.signature.data[68], 68); + + assign(test_msg_.signature.data[69], 69); + + assign(test_msg_.signature.data[70], 70); + + assign(test_msg_.signature.data[71], 71); + assign(test_msg_.signature.len, 72); + + assign(test_msg_.signed_messages[0], 10); + + assign(test_msg_.signed_messages[1], 21); + + assign(test_msg_.signed_messages[2], 23); + assign(test_msg_.stream_counter, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ecdsa_signature_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEcdsaSignature, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEcdsaSignature); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ecdsa_signature, + sizeof(msg->ecdsa_signature)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ecdsa_signature_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ecdsa_signature, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEcdsaSignature); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x83E8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 83; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ecdsa_signature_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ecdsa_signature_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ecdsa_signature_t &lesser, + const sbp_msg_ecdsa_signature_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ecdsa_signature_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ecdsa_signature_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ecdsa_signature_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ecdsa_signature_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgEcdsaSignature, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaSignature, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEcdsaSignature, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEcdsaSignature, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_signing_MsgEcdsaSignature0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ecdsa_signature_t test_msg_{}; + uint8_t encoded_frame_[83 + 8] = { 85, 8, 12, 66, 0, 83, 0, 1, 2, 1, 2, 3, 4, 72, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, @@ -83,434 +544,1001 @@ TEST_F(Test_auto_check_sbp_signing_MsgEcdsaSignature0, Test) { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 10, 21, 23, 232, 131, }; + uint8_t encoded_payload_[83] = { + 0, 1, 2, 1, 2, 3, 4, 72, 0, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 10, 21, 23, + }; +}; + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ecdsa_signature_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEcdsaSignature, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ecdsa_signature_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEcdsaSignature, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + + EXPECT_EQ(sbp_msg_ecdsa_signature_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + + for (uint8_t i = 0; i < 83; i++) { + EXPECT_EQ( + sbp_msg_ecdsa_signature_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ecdsa_signature_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEcdsaSignature, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_t msg{}; + + EXPECT_EQ(sbp_msg_ecdsa_signature_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ecdsa_signature_t t{}; + return sbp_msg_ecdsa_signature_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ecdsa_signature_t t{}; + t.n_signed_messages = 1; + return sbp_msg_ecdsa_signature_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ecdsa_signature_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - sbp_msg_ecdsa_signature_t test_msg{}; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.certificate_id[0] = 1; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.certificate_id[1] = 2; + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_id[2] = 3; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_id[3] = 4; - test_msg.flags = 0; - test_msg.n_signed_messages = 3; - test_msg.on_demand_counter = 2; + CHandler handler{&state}; - test_msg.signature.data[0] = 0; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.signature.data[1] = 1; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.signature.data[2] = 2; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature.data[3] = 3; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature.data[4] = 4; + EXPECT_EQ(sbp_msg_ecdsa_signature_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.signature.data[5] = 5; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature.data[6] = 6; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature.data[7] = 7; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignature, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signature.data[8] = 8; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.signature.data[9] = 9; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature.data[10] = 10; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.signature.data[11] = 11; + EXPECT_NE(sbp_message_send(&state, SbpMsgEcdsaSignature, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.signature.data[12] = 12; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature.data[13] = 13; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature.data[14] = 14; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignature, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signature.data[15] = 15; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, Comparison) { + auto info = get_test_msg_info(); - test_msg.signature.data[16] = 16; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[0], greater.certificate_id[0]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[17] = 17; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[1], greater.certificate_id[1]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[18] = 18; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[2], greater.certificate_id[2]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[19] = 19; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[3], greater.certificate_id[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.n_signed_messages, greater.n_signed_messages); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.on_demand_counter, greater.on_demand_counter); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[0], greater.signature.data[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[1], greater.signature.data[1]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[20] = 20; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[2], greater.signature.data[2]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[21] = 21; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[3], greater.signature.data[3]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[22] = 22; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[4], greater.signature.data[4]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[23] = 23; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[5], greater.signature.data[5]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[24] = 24; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[6], greater.signature.data[6]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[25] = 25; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[7], greater.signature.data[7]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[26] = 26; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[8], greater.signature.data[8]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[27] = 27; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[9], greater.signature.data[9]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[28] = 28; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[10], greater.signature.data[10]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[29] = 29; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[11], greater.signature.data[11]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[30] = 30; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[12], greater.signature.data[12]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[31] = 31; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[13], greater.signature.data[13]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[32] = 32; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[14], greater.signature.data[14]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[33] = 33; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[15], greater.signature.data[15]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[34] = 34; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[16], greater.signature.data[16]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[35] = 35; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[17], greater.signature.data[17]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[36] = 36; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[18], greater.signature.data[18]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[37] = 37; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[19], greater.signature.data[19]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[38] = 38; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[20], greater.signature.data[20]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[39] = 39; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[21], greater.signature.data[21]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[40] = 40; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[22], greater.signature.data[22]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[41] = 41; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[23], greater.signature.data[23]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[42] = 42; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[24], greater.signature.data[24]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[43] = 43; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[25], greater.signature.data[25]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[44] = 44; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[26], greater.signature.data[26]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[45] = 45; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[27], greater.signature.data[27]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[46] = 46; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[28], greater.signature.data[28]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[47] = 47; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[29], greater.signature.data[29]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[48] = 48; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[30], greater.signature.data[30]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[49] = 49; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[31], greater.signature.data[31]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[50] = 50; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[32], greater.signature.data[32]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[51] = 51; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[33], greater.signature.data[33]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[52] = 52; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[34], greater.signature.data[34]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[53] = 53; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[35], greater.signature.data[35]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[54] = 54; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[36], greater.signature.data[36]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[55] = 55; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[37], greater.signature.data[37]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[56] = 56; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[38], greater.signature.data[38]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[57] = 57; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[39], greater.signature.data[39]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[58] = 58; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[40], greater.signature.data[40]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[59] = 59; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[41], greater.signature.data[41]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[60] = 60; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[42], greater.signature.data[42]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[61] = 61; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[43], greater.signature.data[43]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[62] = 62; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[44], greater.signature.data[44]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[63] = 63; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[45], greater.signature.data[45]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[64] = 64; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[46], greater.signature.data[46]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[65] = 65; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[47], greater.signature.data[47]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[66] = 66; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[48], greater.signature.data[48]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[67] = 67; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[49], greater.signature.data[49]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[68] = 68; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[50], greater.signature.data[50]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[69] = 69; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[51], greater.signature.data[51]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[70] = 70; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[52], greater.signature.data[52]); + comparison_tests(lesser, greater); + } - test_msg.signature.data[71] = 71; - test_msg.signature.len = 72; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[53], greater.signature.data[53]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[0] = 10; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[54], greater.signature.data[54]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[1] = 21; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[55], greater.signature.data[55]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[2] = 23; - test_msg.stream_counter = 1; + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[56], greater.signature.data[56]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[57], greater.signature.data[57]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[58], greater.signature.data[58]); + comparison_tests(lesser, greater); + } - while (dummy_rd_ < dummy_wr_) { - process(); + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[59], greater.signature.data[59]); + comparison_tests(lesser, greater); } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.certificate_id[0], 1) - << "incorrect value for last_msg_.certificate_id[0], expected 1, is " - << last_msg_.certificate_id[0]; - EXPECT_EQ(last_msg_.certificate_id[1], 2) - << "incorrect value for last_msg_.certificate_id[1], expected 2, is " - << last_msg_.certificate_id[1]; - EXPECT_EQ(last_msg_.certificate_id[2], 3) - << "incorrect value for last_msg_.certificate_id[2], expected 3, is " - << last_msg_.certificate_id[2]; - EXPECT_EQ(last_msg_.certificate_id[3], 4) - << "incorrect value for last_msg_.certificate_id[3], expected 4, is " - << last_msg_.certificate_id[3]; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_signed_messages, 3) - << "incorrect value for last_msg_.n_signed_messages, expected 3, is " - << last_msg_.n_signed_messages; - EXPECT_EQ(last_msg_.on_demand_counter, 2) - << "incorrect value for last_msg_.on_demand_counter, expected 2, is " - << last_msg_.on_demand_counter; - EXPECT_EQ(last_msg_.signature.data[0], 0) - << "incorrect value for last_msg_.signature.data[0], expected 0, is " - << last_msg_.signature.data[0]; - EXPECT_EQ(last_msg_.signature.data[1], 1) - << "incorrect value for last_msg_.signature.data[1], expected 1, is " - << last_msg_.signature.data[1]; - EXPECT_EQ(last_msg_.signature.data[2], 2) - << "incorrect value for last_msg_.signature.data[2], expected 2, is " - << last_msg_.signature.data[2]; - EXPECT_EQ(last_msg_.signature.data[3], 3) - << "incorrect value for last_msg_.signature.data[3], expected 3, is " - << last_msg_.signature.data[3]; - EXPECT_EQ(last_msg_.signature.data[4], 4) - << "incorrect value for last_msg_.signature.data[4], expected 4, is " - << last_msg_.signature.data[4]; - EXPECT_EQ(last_msg_.signature.data[5], 5) - << "incorrect value for last_msg_.signature.data[5], expected 5, is " - << last_msg_.signature.data[5]; - EXPECT_EQ(last_msg_.signature.data[6], 6) - << "incorrect value for last_msg_.signature.data[6], expected 6, is " - << last_msg_.signature.data[6]; - EXPECT_EQ(last_msg_.signature.data[7], 7) - << "incorrect value for last_msg_.signature.data[7], expected 7, is " - << last_msg_.signature.data[7]; - EXPECT_EQ(last_msg_.signature.data[8], 8) - << "incorrect value for last_msg_.signature.data[8], expected 8, is " - << last_msg_.signature.data[8]; - EXPECT_EQ(last_msg_.signature.data[9], 9) - << "incorrect value for last_msg_.signature.data[9], expected 9, is " - << last_msg_.signature.data[9]; - EXPECT_EQ(last_msg_.signature.data[10], 10) - << "incorrect value for last_msg_.signature.data[10], expected 10, is " - << last_msg_.signature.data[10]; - EXPECT_EQ(last_msg_.signature.data[11], 11) - << "incorrect value for last_msg_.signature.data[11], expected 11, is " - << last_msg_.signature.data[11]; - EXPECT_EQ(last_msg_.signature.data[12], 12) - << "incorrect value for last_msg_.signature.data[12], expected 12, is " - << last_msg_.signature.data[12]; - EXPECT_EQ(last_msg_.signature.data[13], 13) - << "incorrect value for last_msg_.signature.data[13], expected 13, is " - << last_msg_.signature.data[13]; - EXPECT_EQ(last_msg_.signature.data[14], 14) - << "incorrect value for last_msg_.signature.data[14], expected 14, is " - << last_msg_.signature.data[14]; - EXPECT_EQ(last_msg_.signature.data[15], 15) - << "incorrect value for last_msg_.signature.data[15], expected 15, is " - << last_msg_.signature.data[15]; - EXPECT_EQ(last_msg_.signature.data[16], 16) - << "incorrect value for last_msg_.signature.data[16], expected 16, is " - << last_msg_.signature.data[16]; - EXPECT_EQ(last_msg_.signature.data[17], 17) - << "incorrect value for last_msg_.signature.data[17], expected 17, is " - << last_msg_.signature.data[17]; - EXPECT_EQ(last_msg_.signature.data[18], 18) - << "incorrect value for last_msg_.signature.data[18], expected 18, is " - << last_msg_.signature.data[18]; - EXPECT_EQ(last_msg_.signature.data[19], 19) - << "incorrect value for last_msg_.signature.data[19], expected 19, is " - << last_msg_.signature.data[19]; - EXPECT_EQ(last_msg_.signature.data[20], 20) - << "incorrect value for last_msg_.signature.data[20], expected 20, is " - << last_msg_.signature.data[20]; - EXPECT_EQ(last_msg_.signature.data[21], 21) - << "incorrect value for last_msg_.signature.data[21], expected 21, is " - << last_msg_.signature.data[21]; - EXPECT_EQ(last_msg_.signature.data[22], 22) - << "incorrect value for last_msg_.signature.data[22], expected 22, is " - << last_msg_.signature.data[22]; - EXPECT_EQ(last_msg_.signature.data[23], 23) - << "incorrect value for last_msg_.signature.data[23], expected 23, is " - << last_msg_.signature.data[23]; - EXPECT_EQ(last_msg_.signature.data[24], 24) - << "incorrect value for last_msg_.signature.data[24], expected 24, is " - << last_msg_.signature.data[24]; - EXPECT_EQ(last_msg_.signature.data[25], 25) - << "incorrect value for last_msg_.signature.data[25], expected 25, is " - << last_msg_.signature.data[25]; - EXPECT_EQ(last_msg_.signature.data[26], 26) - << "incorrect value for last_msg_.signature.data[26], expected 26, is " - << last_msg_.signature.data[26]; - EXPECT_EQ(last_msg_.signature.data[27], 27) - << "incorrect value for last_msg_.signature.data[27], expected 27, is " - << last_msg_.signature.data[27]; - EXPECT_EQ(last_msg_.signature.data[28], 28) - << "incorrect value for last_msg_.signature.data[28], expected 28, is " - << last_msg_.signature.data[28]; - EXPECT_EQ(last_msg_.signature.data[29], 29) - << "incorrect value for last_msg_.signature.data[29], expected 29, is " - << last_msg_.signature.data[29]; - EXPECT_EQ(last_msg_.signature.data[30], 30) - << "incorrect value for last_msg_.signature.data[30], expected 30, is " - << last_msg_.signature.data[30]; - EXPECT_EQ(last_msg_.signature.data[31], 31) - << "incorrect value for last_msg_.signature.data[31], expected 31, is " - << last_msg_.signature.data[31]; - EXPECT_EQ(last_msg_.signature.data[32], 32) - << "incorrect value for last_msg_.signature.data[32], expected 32, is " - << last_msg_.signature.data[32]; - EXPECT_EQ(last_msg_.signature.data[33], 33) - << "incorrect value for last_msg_.signature.data[33], expected 33, is " - << last_msg_.signature.data[33]; - EXPECT_EQ(last_msg_.signature.data[34], 34) - << "incorrect value for last_msg_.signature.data[34], expected 34, is " - << last_msg_.signature.data[34]; - EXPECT_EQ(last_msg_.signature.data[35], 35) - << "incorrect value for last_msg_.signature.data[35], expected 35, is " - << last_msg_.signature.data[35]; - EXPECT_EQ(last_msg_.signature.data[36], 36) - << "incorrect value for last_msg_.signature.data[36], expected 36, is " - << last_msg_.signature.data[36]; - EXPECT_EQ(last_msg_.signature.data[37], 37) - << "incorrect value for last_msg_.signature.data[37], expected 37, is " - << last_msg_.signature.data[37]; - EXPECT_EQ(last_msg_.signature.data[38], 38) - << "incorrect value for last_msg_.signature.data[38], expected 38, is " - << last_msg_.signature.data[38]; - EXPECT_EQ(last_msg_.signature.data[39], 39) - << "incorrect value for last_msg_.signature.data[39], expected 39, is " - << last_msg_.signature.data[39]; - EXPECT_EQ(last_msg_.signature.data[40], 40) - << "incorrect value for last_msg_.signature.data[40], expected 40, is " - << last_msg_.signature.data[40]; - EXPECT_EQ(last_msg_.signature.data[41], 41) - << "incorrect value for last_msg_.signature.data[41], expected 41, is " - << last_msg_.signature.data[41]; - EXPECT_EQ(last_msg_.signature.data[42], 42) - << "incorrect value for last_msg_.signature.data[42], expected 42, is " - << last_msg_.signature.data[42]; - EXPECT_EQ(last_msg_.signature.data[43], 43) - << "incorrect value for last_msg_.signature.data[43], expected 43, is " - << last_msg_.signature.data[43]; - EXPECT_EQ(last_msg_.signature.data[44], 44) - << "incorrect value for last_msg_.signature.data[44], expected 44, is " - << last_msg_.signature.data[44]; - EXPECT_EQ(last_msg_.signature.data[45], 45) - << "incorrect value for last_msg_.signature.data[45], expected 45, is " - << last_msg_.signature.data[45]; - EXPECT_EQ(last_msg_.signature.data[46], 46) - << "incorrect value for last_msg_.signature.data[46], expected 46, is " - << last_msg_.signature.data[46]; - EXPECT_EQ(last_msg_.signature.data[47], 47) - << "incorrect value for last_msg_.signature.data[47], expected 47, is " - << last_msg_.signature.data[47]; - EXPECT_EQ(last_msg_.signature.data[48], 48) - << "incorrect value for last_msg_.signature.data[48], expected 48, is " - << last_msg_.signature.data[48]; - EXPECT_EQ(last_msg_.signature.data[49], 49) - << "incorrect value for last_msg_.signature.data[49], expected 49, is " - << last_msg_.signature.data[49]; - EXPECT_EQ(last_msg_.signature.data[50], 50) - << "incorrect value for last_msg_.signature.data[50], expected 50, is " - << last_msg_.signature.data[50]; - EXPECT_EQ(last_msg_.signature.data[51], 51) - << "incorrect value for last_msg_.signature.data[51], expected 51, is " - << last_msg_.signature.data[51]; - EXPECT_EQ(last_msg_.signature.data[52], 52) - << "incorrect value for last_msg_.signature.data[52], expected 52, is " - << last_msg_.signature.data[52]; - EXPECT_EQ(last_msg_.signature.data[53], 53) - << "incorrect value for last_msg_.signature.data[53], expected 53, is " - << last_msg_.signature.data[53]; - EXPECT_EQ(last_msg_.signature.data[54], 54) - << "incorrect value for last_msg_.signature.data[54], expected 54, is " - << last_msg_.signature.data[54]; - EXPECT_EQ(last_msg_.signature.data[55], 55) - << "incorrect value for last_msg_.signature.data[55], expected 55, is " - << last_msg_.signature.data[55]; - EXPECT_EQ(last_msg_.signature.data[56], 56) - << "incorrect value for last_msg_.signature.data[56], expected 56, is " - << last_msg_.signature.data[56]; - EXPECT_EQ(last_msg_.signature.data[57], 57) - << "incorrect value for last_msg_.signature.data[57], expected 57, is " - << last_msg_.signature.data[57]; - EXPECT_EQ(last_msg_.signature.data[58], 58) - << "incorrect value for last_msg_.signature.data[58], expected 58, is " - << last_msg_.signature.data[58]; - EXPECT_EQ(last_msg_.signature.data[59], 59) - << "incorrect value for last_msg_.signature.data[59], expected 59, is " - << last_msg_.signature.data[59]; - EXPECT_EQ(last_msg_.signature.data[60], 60) - << "incorrect value for last_msg_.signature.data[60], expected 60, is " - << last_msg_.signature.data[60]; - EXPECT_EQ(last_msg_.signature.data[61], 61) - << "incorrect value for last_msg_.signature.data[61], expected 61, is " - << last_msg_.signature.data[61]; - EXPECT_EQ(last_msg_.signature.data[62], 62) - << "incorrect value for last_msg_.signature.data[62], expected 62, is " - << last_msg_.signature.data[62]; - EXPECT_EQ(last_msg_.signature.data[63], 63) - << "incorrect value for last_msg_.signature.data[63], expected 63, is " - << last_msg_.signature.data[63]; - EXPECT_EQ(last_msg_.signature.data[64], 64) - << "incorrect value for last_msg_.signature.data[64], expected 64, is " - << last_msg_.signature.data[64]; - EXPECT_EQ(last_msg_.signature.data[65], 65) - << "incorrect value for last_msg_.signature.data[65], expected 65, is " - << last_msg_.signature.data[65]; - EXPECT_EQ(last_msg_.signature.data[66], 66) - << "incorrect value for last_msg_.signature.data[66], expected 66, is " - << last_msg_.signature.data[66]; - EXPECT_EQ(last_msg_.signature.data[67], 67) - << "incorrect value for last_msg_.signature.data[67], expected 67, is " - << last_msg_.signature.data[67]; - EXPECT_EQ(last_msg_.signature.data[68], 68) - << "incorrect value for last_msg_.signature.data[68], expected 68, is " - << last_msg_.signature.data[68]; - EXPECT_EQ(last_msg_.signature.data[69], 69) - << "incorrect value for last_msg_.signature.data[69], expected 69, is " - << last_msg_.signature.data[69]; - EXPECT_EQ(last_msg_.signature.data[70], 70) - << "incorrect value for last_msg_.signature.data[70], expected 70, is " - << last_msg_.signature.data[70]; - EXPECT_EQ(last_msg_.signature.data[71], 71) - << "incorrect value for last_msg_.signature.data[71], expected 71, is " - << last_msg_.signature.data[71]; - EXPECT_EQ(last_msg_.signature.len, 72) - << "incorrect value for last_msg_.signature.len, expected 72, is " - << last_msg_.signature.len; - EXPECT_EQ(last_msg_.signed_messages[0], 10) - << "incorrect value for last_msg_.signed_messages[0], expected 10, is " - << last_msg_.signed_messages[0]; - EXPECT_EQ(last_msg_.signed_messages[1], 21) - << "incorrect value for last_msg_.signed_messages[1], expected 21, is " - << last_msg_.signed_messages[1]; - EXPECT_EQ(last_msg_.signed_messages[2], 23) - << "incorrect value for last_msg_.signed_messages[2], expected 23, is " - << last_msg_.signed_messages[2]; - EXPECT_EQ(last_msg_.stream_counter, 1) - << "incorrect value for last_msg_.stream_counter, expected 1, is " - << last_msg_.stream_counter; + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[60], greater.signature.data[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[61], greater.signature.data[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[62], greater.signature.data[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[63], greater.signature.data[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[64], greater.signature.data[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[65], greater.signature.data[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[66], greater.signature.data[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[67], greater.signature.data[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[68], greater.signature.data[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[69], greater.signature.data[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[70], greater.signature.data[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.data[71], greater.signature.data[71]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signature.len, greater.signature.len); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[0], greater.signed_messages[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[1], greater.signed_messages[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[2], greater.signed_messages[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_t greater = info.test_msg; + make_lesser_greater(lesser.stream_counter, greater.stream_counter); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEcdsaSignature); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ECDSA_SIGNATURE"); } + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ecdsa_signature_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ecdsa_signature_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ecdsa_signature, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ecdsa_signature, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEcdsaSignature, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignature0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEcdsaSignature, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepA.cc b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepA.cc index 3695ed6590..99f84e3419 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepA.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepA.cc @@ -16,1374 +16,3288 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEcdsaSignatureDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEcdsaSignatureDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0() { + assign(test_msg_.certificate_id[0], 1); - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ecdsa_signature_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ecdsa_signature_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + assign(test_msg_.certificate_id[1], 2); -TEST_F(Test_auto_check_sbp_signing_MsgEcdsaSignatureDepA0, Test) { - uint8_t encoded_frame[] = { - 85, 6, 12, 66, 0, 255, 0, 1, 2, 1, 2, 3, 4, 0, 1, - 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, - 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, - 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, - 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, - 6, 7, 10, 21, 23, 63, 140, 37, 130, 106, 28, 40, 165, 179, 73, - 178, 60, 126, 114, 78, 113, 27, 95, 3, 62, 104, 145, 96, 19, 92, - 123, 14, 90, 153, 183, 9, 72, 81, 118, 112, 124, 16, 182, 76, 146, - 115, 58, 144, 17, 105, 66, 31, 135, 54, 100, 84, 181, 103, 11, 88, - 133, 155, 167, 173, 143, 86, 158, 20, 168, 132, 141, 102, 50, 48, 71, - 147, 53, 87, 1, 108, 138, 36, 134, 139, 163, 82, 43, 52, 150, 12, - 30, 110, 156, 107, 120, 91, 122, 69, 164, 170, 116, 25, 94, 5, 22, - 24, 162, 175, 38, 157, 98, 44, 160, 47, 97, 142, 8, 74, 13, 177, - 15, 128, 26, 131, 154, 65, 169, 55, 136, 125, 171, 161, 29, 129, 151, - 68, 166, 51, 70, 45, 56, 79, 149, 99, 42, 101, 152, 39, 89, 180, - 64, 49, 6, 80, 172, 32, 109, 2, 119, 93, 176, 0, 33, 57, 34, - 18, 85, 121, 137, 83, 111, 59, 7, 77, 4, 117, 159, 148, 35, 61, - 41, 67, 46, 127, 75, 174, 97, 172, - }; + assign(test_msg_.certificate_id[2], 3); + + assign(test_msg_.certificate_id[3], 4); + assign(test_msg_.flags, 0); + assign(test_msg_.n_signed_messages, 184); + assign(test_msg_.on_demand_counter, 2); + + assign(test_msg_.signature[0], 0); + + assign(test_msg_.signature[1], 1); + + assign(test_msg_.signature[2], 2); + + assign(test_msg_.signature[3], 3); + + assign(test_msg_.signature[4], 4); + + assign(test_msg_.signature[5], 5); + + assign(test_msg_.signature[6], 6); + + assign(test_msg_.signature[7], 7); + + assign(test_msg_.signature[8], 0); + + assign(test_msg_.signature[9], 1); + + assign(test_msg_.signature[10], 2); + + assign(test_msg_.signature[11], 3); + + assign(test_msg_.signature[12], 4); + + assign(test_msg_.signature[13], 5); + + assign(test_msg_.signature[14], 6); + + assign(test_msg_.signature[15], 7); + + assign(test_msg_.signature[16], 0); + + assign(test_msg_.signature[17], 1); + + assign(test_msg_.signature[18], 2); + + assign(test_msg_.signature[19], 3); + + assign(test_msg_.signature[20], 4); + + assign(test_msg_.signature[21], 5); + + assign(test_msg_.signature[22], 6); + + assign(test_msg_.signature[23], 7); + + assign(test_msg_.signature[24], 0); + + assign(test_msg_.signature[25], 1); + + assign(test_msg_.signature[26], 2); + + assign(test_msg_.signature[27], 3); + + assign(test_msg_.signature[28], 4); + + assign(test_msg_.signature[29], 5); + + assign(test_msg_.signature[30], 6); + + assign(test_msg_.signature[31], 7); + + assign(test_msg_.signature[32], 0); + + assign(test_msg_.signature[33], 1); + + assign(test_msg_.signature[34], 2); + + assign(test_msg_.signature[35], 3); + + assign(test_msg_.signature[36], 4); + + assign(test_msg_.signature[37], 5); - sbp_msg_ecdsa_signature_dep_a_t test_msg{}; + assign(test_msg_.signature[38], 6); - test_msg.certificate_id[0] = 1; + assign(test_msg_.signature[39], 7); - test_msg.certificate_id[1] = 2; + assign(test_msg_.signature[40], 0); - test_msg.certificate_id[2] = 3; + assign(test_msg_.signature[41], 1); - test_msg.certificate_id[3] = 4; - test_msg.flags = 0; - test_msg.n_signed_messages = 184; - test_msg.on_demand_counter = 2; + assign(test_msg_.signature[42], 2); - test_msg.signature[0] = 0; + assign(test_msg_.signature[43], 3); - test_msg.signature[1] = 1; + assign(test_msg_.signature[44], 4); - test_msg.signature[2] = 2; + assign(test_msg_.signature[45], 5); - test_msg.signature[3] = 3; + assign(test_msg_.signature[46], 6); - test_msg.signature[4] = 4; + assign(test_msg_.signature[47], 7); - test_msg.signature[5] = 5; + assign(test_msg_.signature[48], 0); - test_msg.signature[6] = 6; + assign(test_msg_.signature[49], 1); - test_msg.signature[7] = 7; + assign(test_msg_.signature[50], 2); - test_msg.signature[8] = 0; + assign(test_msg_.signature[51], 3); - test_msg.signature[9] = 1; + assign(test_msg_.signature[52], 4); - test_msg.signature[10] = 2; + assign(test_msg_.signature[53], 5); - test_msg.signature[11] = 3; + assign(test_msg_.signature[54], 6); - test_msg.signature[12] = 4; + assign(test_msg_.signature[55], 7); - test_msg.signature[13] = 5; + assign(test_msg_.signature[56], 0); - test_msg.signature[14] = 6; + assign(test_msg_.signature[57], 1); - test_msg.signature[15] = 7; + assign(test_msg_.signature[58], 2); - test_msg.signature[16] = 0; + assign(test_msg_.signature[59], 3); - test_msg.signature[17] = 1; + assign(test_msg_.signature[60], 4); - test_msg.signature[18] = 2; + assign(test_msg_.signature[61], 5); - test_msg.signature[19] = 3; + assign(test_msg_.signature[62], 6); - test_msg.signature[20] = 4; + assign(test_msg_.signature[63], 7); - test_msg.signature[21] = 5; + assign(test_msg_.signed_messages[0], 10); - test_msg.signature[22] = 6; + assign(test_msg_.signed_messages[1], 21); - test_msg.signature[23] = 7; + assign(test_msg_.signed_messages[2], 23); - test_msg.signature[24] = 0; + assign(test_msg_.signed_messages[3], 63); - test_msg.signature[25] = 1; + assign(test_msg_.signed_messages[4], 140); - test_msg.signature[26] = 2; + assign(test_msg_.signed_messages[5], 37); - test_msg.signature[27] = 3; + assign(test_msg_.signed_messages[6], 130); - test_msg.signature[28] = 4; + assign(test_msg_.signed_messages[7], 106); - test_msg.signature[29] = 5; + assign(test_msg_.signed_messages[8], 28); - test_msg.signature[30] = 6; + assign(test_msg_.signed_messages[9], 40); - test_msg.signature[31] = 7; + assign(test_msg_.signed_messages[10], 165); - test_msg.signature[32] = 0; + assign(test_msg_.signed_messages[11], 179); - test_msg.signature[33] = 1; + assign(test_msg_.signed_messages[12], 73); - test_msg.signature[34] = 2; + assign(test_msg_.signed_messages[13], 178); - test_msg.signature[35] = 3; + assign(test_msg_.signed_messages[14], 60); - test_msg.signature[36] = 4; + assign(test_msg_.signed_messages[15], 126); - test_msg.signature[37] = 5; + assign(test_msg_.signed_messages[16], 114); - test_msg.signature[38] = 6; + assign(test_msg_.signed_messages[17], 78); - test_msg.signature[39] = 7; + assign(test_msg_.signed_messages[18], 113); - test_msg.signature[40] = 0; + assign(test_msg_.signed_messages[19], 27); - test_msg.signature[41] = 1; + assign(test_msg_.signed_messages[20], 95); - test_msg.signature[42] = 2; + assign(test_msg_.signed_messages[21], 3); - test_msg.signature[43] = 3; + assign(test_msg_.signed_messages[22], 62); - test_msg.signature[44] = 4; + assign(test_msg_.signed_messages[23], 104); - test_msg.signature[45] = 5; + assign(test_msg_.signed_messages[24], 145); - test_msg.signature[46] = 6; + assign(test_msg_.signed_messages[25], 96); - test_msg.signature[47] = 7; + assign(test_msg_.signed_messages[26], 19); - test_msg.signature[48] = 0; + assign(test_msg_.signed_messages[27], 92); - test_msg.signature[49] = 1; + assign(test_msg_.signed_messages[28], 123); - test_msg.signature[50] = 2; + assign(test_msg_.signed_messages[29], 14); - test_msg.signature[51] = 3; + assign(test_msg_.signed_messages[30], 90); - test_msg.signature[52] = 4; + assign(test_msg_.signed_messages[31], 153); - test_msg.signature[53] = 5; + assign(test_msg_.signed_messages[32], 183); - test_msg.signature[54] = 6; + assign(test_msg_.signed_messages[33], 9); - test_msg.signature[55] = 7; + assign(test_msg_.signed_messages[34], 72); - test_msg.signature[56] = 0; + assign(test_msg_.signed_messages[35], 81); - test_msg.signature[57] = 1; + assign(test_msg_.signed_messages[36], 118); - test_msg.signature[58] = 2; + assign(test_msg_.signed_messages[37], 112); - test_msg.signature[59] = 3; + assign(test_msg_.signed_messages[38], 124); - test_msg.signature[60] = 4; + assign(test_msg_.signed_messages[39], 16); - test_msg.signature[61] = 5; + assign(test_msg_.signed_messages[40], 182); - test_msg.signature[62] = 6; + assign(test_msg_.signed_messages[41], 76); - test_msg.signature[63] = 7; + assign(test_msg_.signed_messages[42], 146); - test_msg.signed_messages[0] = 10; + assign(test_msg_.signed_messages[43], 115); - test_msg.signed_messages[1] = 21; + assign(test_msg_.signed_messages[44], 58); - test_msg.signed_messages[2] = 23; + assign(test_msg_.signed_messages[45], 144); - test_msg.signed_messages[3] = 63; + assign(test_msg_.signed_messages[46], 17); - test_msg.signed_messages[4] = 140; + assign(test_msg_.signed_messages[47], 105); - test_msg.signed_messages[5] = 37; + assign(test_msg_.signed_messages[48], 66); - test_msg.signed_messages[6] = 130; + assign(test_msg_.signed_messages[49], 31); - test_msg.signed_messages[7] = 106; + assign(test_msg_.signed_messages[50], 135); - test_msg.signed_messages[8] = 28; + assign(test_msg_.signed_messages[51], 54); - test_msg.signed_messages[9] = 40; + assign(test_msg_.signed_messages[52], 100); - test_msg.signed_messages[10] = 165; + assign(test_msg_.signed_messages[53], 84); - test_msg.signed_messages[11] = 179; + assign(test_msg_.signed_messages[54], 181); - test_msg.signed_messages[12] = 73; + assign(test_msg_.signed_messages[55], 103); - test_msg.signed_messages[13] = 178; + assign(test_msg_.signed_messages[56], 11); - test_msg.signed_messages[14] = 60; + assign(test_msg_.signed_messages[57], 88); - test_msg.signed_messages[15] = 126; + assign(test_msg_.signed_messages[58], 133); - test_msg.signed_messages[16] = 114; + assign(test_msg_.signed_messages[59], 155); - test_msg.signed_messages[17] = 78; + assign(test_msg_.signed_messages[60], 167); - test_msg.signed_messages[18] = 113; + assign(test_msg_.signed_messages[61], 173); - test_msg.signed_messages[19] = 27; + assign(test_msg_.signed_messages[62], 143); - test_msg.signed_messages[20] = 95; + assign(test_msg_.signed_messages[63], 86); - test_msg.signed_messages[21] = 3; + assign(test_msg_.signed_messages[64], 158); - test_msg.signed_messages[22] = 62; + assign(test_msg_.signed_messages[65], 20); - test_msg.signed_messages[23] = 104; + assign(test_msg_.signed_messages[66], 168); - test_msg.signed_messages[24] = 145; + assign(test_msg_.signed_messages[67], 132); - test_msg.signed_messages[25] = 96; + assign(test_msg_.signed_messages[68], 141); - test_msg.signed_messages[26] = 19; + assign(test_msg_.signed_messages[69], 102); - test_msg.signed_messages[27] = 92; + assign(test_msg_.signed_messages[70], 50); - test_msg.signed_messages[28] = 123; + assign(test_msg_.signed_messages[71], 48); - test_msg.signed_messages[29] = 14; + assign(test_msg_.signed_messages[72], 71); - test_msg.signed_messages[30] = 90; + assign(test_msg_.signed_messages[73], 147); - test_msg.signed_messages[31] = 153; + assign(test_msg_.signed_messages[74], 53); - test_msg.signed_messages[32] = 183; + assign(test_msg_.signed_messages[75], 87); - test_msg.signed_messages[33] = 9; + assign(test_msg_.signed_messages[76], 1); - test_msg.signed_messages[34] = 72; + assign(test_msg_.signed_messages[77], 108); - test_msg.signed_messages[35] = 81; + assign(test_msg_.signed_messages[78], 138); - test_msg.signed_messages[36] = 118; + assign(test_msg_.signed_messages[79], 36); - test_msg.signed_messages[37] = 112; + assign(test_msg_.signed_messages[80], 134); - test_msg.signed_messages[38] = 124; + assign(test_msg_.signed_messages[81], 139); - test_msg.signed_messages[39] = 16; + assign(test_msg_.signed_messages[82], 163); - test_msg.signed_messages[40] = 182; + assign(test_msg_.signed_messages[83], 82); - test_msg.signed_messages[41] = 76; + assign(test_msg_.signed_messages[84], 43); - test_msg.signed_messages[42] = 146; + assign(test_msg_.signed_messages[85], 52); - test_msg.signed_messages[43] = 115; + assign(test_msg_.signed_messages[86], 150); - test_msg.signed_messages[44] = 58; + assign(test_msg_.signed_messages[87], 12); - test_msg.signed_messages[45] = 144; + assign(test_msg_.signed_messages[88], 30); - test_msg.signed_messages[46] = 17; + assign(test_msg_.signed_messages[89], 110); - test_msg.signed_messages[47] = 105; + assign(test_msg_.signed_messages[90], 156); - test_msg.signed_messages[48] = 66; + assign(test_msg_.signed_messages[91], 107); - test_msg.signed_messages[49] = 31; + assign(test_msg_.signed_messages[92], 120); - test_msg.signed_messages[50] = 135; + assign(test_msg_.signed_messages[93], 91); - test_msg.signed_messages[51] = 54; + assign(test_msg_.signed_messages[94], 122); - test_msg.signed_messages[52] = 100; + assign(test_msg_.signed_messages[95], 69); - test_msg.signed_messages[53] = 84; + assign(test_msg_.signed_messages[96], 164); - test_msg.signed_messages[54] = 181; + assign(test_msg_.signed_messages[97], 170); - test_msg.signed_messages[55] = 103; + assign(test_msg_.signed_messages[98], 116); - test_msg.signed_messages[56] = 11; + assign(test_msg_.signed_messages[99], 25); - test_msg.signed_messages[57] = 88; + assign(test_msg_.signed_messages[100], 94); - test_msg.signed_messages[58] = 133; + assign(test_msg_.signed_messages[101], 5); - test_msg.signed_messages[59] = 155; + assign(test_msg_.signed_messages[102], 22); - test_msg.signed_messages[60] = 167; + assign(test_msg_.signed_messages[103], 24); - test_msg.signed_messages[61] = 173; + assign(test_msg_.signed_messages[104], 162); - test_msg.signed_messages[62] = 143; + assign(test_msg_.signed_messages[105], 175); - test_msg.signed_messages[63] = 86; + assign(test_msg_.signed_messages[106], 38); - test_msg.signed_messages[64] = 158; + assign(test_msg_.signed_messages[107], 157); - test_msg.signed_messages[65] = 20; + assign(test_msg_.signed_messages[108], 98); - test_msg.signed_messages[66] = 168; + assign(test_msg_.signed_messages[109], 44); - test_msg.signed_messages[67] = 132; + assign(test_msg_.signed_messages[110], 160); - test_msg.signed_messages[68] = 141; + assign(test_msg_.signed_messages[111], 47); - test_msg.signed_messages[69] = 102; + assign(test_msg_.signed_messages[112], 97); - test_msg.signed_messages[70] = 50; + assign(test_msg_.signed_messages[113], 142); - test_msg.signed_messages[71] = 48; + assign(test_msg_.signed_messages[114], 8); - test_msg.signed_messages[72] = 71; + assign(test_msg_.signed_messages[115], 74); - test_msg.signed_messages[73] = 147; + assign(test_msg_.signed_messages[116], 13); - test_msg.signed_messages[74] = 53; + assign(test_msg_.signed_messages[117], 177); - test_msg.signed_messages[75] = 87; + assign(test_msg_.signed_messages[118], 15); - test_msg.signed_messages[76] = 1; + assign(test_msg_.signed_messages[119], 128); - test_msg.signed_messages[77] = 108; + assign(test_msg_.signed_messages[120], 26); - test_msg.signed_messages[78] = 138; + assign(test_msg_.signed_messages[121], 131); - test_msg.signed_messages[79] = 36; + assign(test_msg_.signed_messages[122], 154); - test_msg.signed_messages[80] = 134; + assign(test_msg_.signed_messages[123], 65); - test_msg.signed_messages[81] = 139; + assign(test_msg_.signed_messages[124], 169); - test_msg.signed_messages[82] = 163; + assign(test_msg_.signed_messages[125], 55); - test_msg.signed_messages[83] = 82; + assign(test_msg_.signed_messages[126], 136); - test_msg.signed_messages[84] = 43; + assign(test_msg_.signed_messages[127], 125); - test_msg.signed_messages[85] = 52; + assign(test_msg_.signed_messages[128], 171); - test_msg.signed_messages[86] = 150; + assign(test_msg_.signed_messages[129], 161); - test_msg.signed_messages[87] = 12; + assign(test_msg_.signed_messages[130], 29); - test_msg.signed_messages[88] = 30; + assign(test_msg_.signed_messages[131], 129); - test_msg.signed_messages[89] = 110; + assign(test_msg_.signed_messages[132], 151); - test_msg.signed_messages[90] = 156; + assign(test_msg_.signed_messages[133], 68); - test_msg.signed_messages[91] = 107; + assign(test_msg_.signed_messages[134], 166); - test_msg.signed_messages[92] = 120; + assign(test_msg_.signed_messages[135], 51); - test_msg.signed_messages[93] = 91; + assign(test_msg_.signed_messages[136], 70); - test_msg.signed_messages[94] = 122; + assign(test_msg_.signed_messages[137], 45); - test_msg.signed_messages[95] = 69; + assign(test_msg_.signed_messages[138], 56); - test_msg.signed_messages[96] = 164; + assign(test_msg_.signed_messages[139], 79); - test_msg.signed_messages[97] = 170; + assign(test_msg_.signed_messages[140], 149); - test_msg.signed_messages[98] = 116; + assign(test_msg_.signed_messages[141], 99); - test_msg.signed_messages[99] = 25; + assign(test_msg_.signed_messages[142], 42); - test_msg.signed_messages[100] = 94; + assign(test_msg_.signed_messages[143], 101); - test_msg.signed_messages[101] = 5; + assign(test_msg_.signed_messages[144], 152); - test_msg.signed_messages[102] = 22; + assign(test_msg_.signed_messages[145], 39); - test_msg.signed_messages[103] = 24; + assign(test_msg_.signed_messages[146], 89); - test_msg.signed_messages[104] = 162; + assign(test_msg_.signed_messages[147], 180); - test_msg.signed_messages[105] = 175; + assign(test_msg_.signed_messages[148], 64); - test_msg.signed_messages[106] = 38; + assign(test_msg_.signed_messages[149], 49); - test_msg.signed_messages[107] = 157; + assign(test_msg_.signed_messages[150], 6); - test_msg.signed_messages[108] = 98; + assign(test_msg_.signed_messages[151], 80); - test_msg.signed_messages[109] = 44; + assign(test_msg_.signed_messages[152], 172); - test_msg.signed_messages[110] = 160; + assign(test_msg_.signed_messages[153], 32); - test_msg.signed_messages[111] = 47; + assign(test_msg_.signed_messages[154], 109); - test_msg.signed_messages[112] = 97; + assign(test_msg_.signed_messages[155], 2); - test_msg.signed_messages[113] = 142; + assign(test_msg_.signed_messages[156], 119); - test_msg.signed_messages[114] = 8; + assign(test_msg_.signed_messages[157], 93); - test_msg.signed_messages[115] = 74; + assign(test_msg_.signed_messages[158], 176); - test_msg.signed_messages[116] = 13; + assign(test_msg_.signed_messages[159], 0); - test_msg.signed_messages[117] = 177; + assign(test_msg_.signed_messages[160], 33); - test_msg.signed_messages[118] = 15; + assign(test_msg_.signed_messages[161], 57); - test_msg.signed_messages[119] = 128; + assign(test_msg_.signed_messages[162], 34); - test_msg.signed_messages[120] = 26; + assign(test_msg_.signed_messages[163], 18); - test_msg.signed_messages[121] = 131; + assign(test_msg_.signed_messages[164], 85); - test_msg.signed_messages[122] = 154; + assign(test_msg_.signed_messages[165], 121); - test_msg.signed_messages[123] = 65; + assign(test_msg_.signed_messages[166], 137); - test_msg.signed_messages[124] = 169; + assign(test_msg_.signed_messages[167], 83); - test_msg.signed_messages[125] = 55; + assign(test_msg_.signed_messages[168], 111); - test_msg.signed_messages[126] = 136; + assign(test_msg_.signed_messages[169], 59); - test_msg.signed_messages[127] = 125; + assign(test_msg_.signed_messages[170], 7); - test_msg.signed_messages[128] = 171; + assign(test_msg_.signed_messages[171], 77); - test_msg.signed_messages[129] = 161; + assign(test_msg_.signed_messages[172], 4); - test_msg.signed_messages[130] = 29; + assign(test_msg_.signed_messages[173], 117); - test_msg.signed_messages[131] = 129; + assign(test_msg_.signed_messages[174], 159); - test_msg.signed_messages[132] = 151; + assign(test_msg_.signed_messages[175], 148); - test_msg.signed_messages[133] = 68; + assign(test_msg_.signed_messages[176], 35); - test_msg.signed_messages[134] = 166; + assign(test_msg_.signed_messages[177], 61); - test_msg.signed_messages[135] = 51; + assign(test_msg_.signed_messages[178], 41); - test_msg.signed_messages[136] = 70; + assign(test_msg_.signed_messages[179], 67); - test_msg.signed_messages[137] = 45; + assign(test_msg_.signed_messages[180], 46); - test_msg.signed_messages[138] = 56; + assign(test_msg_.signed_messages[181], 127); - test_msg.signed_messages[139] = 79; + assign(test_msg_.signed_messages[182], 75); - test_msg.signed_messages[140] = 149; + assign(test_msg_.signed_messages[183], 174); + assign(test_msg_.stream_counter, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ecdsa_signature_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEcdsaSignatureDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEcdsaSignatureDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ecdsa_signature_dep_a, + sizeof(msg->ecdsa_signature_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; - test_msg.signed_messages[141] = 99; + struct TestMsgInfo { + sbp_msg_ecdsa_signature_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ecdsa_signature_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEcdsaSignatureDepA); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xAC61; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ecdsa_signature_dep_a_t &lesser, + const sbp_msg_ecdsa_signature_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ecdsa_signature_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ecdsa_signature_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaSignatureDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaSignatureDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEcdsaSignatureDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEcdsaSignatureDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } - test_msg.signed_messages[142] = 42; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } - test_msg.signed_messages[143] = 101; + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } - test_msg.signed_messages[144] = 152; + private: + sbp_msg_ecdsa_signature_dep_a_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 6, 12, 66, 0, 255, 0, 1, 2, 1, 2, 3, 4, 0, 1, + 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, + 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, + 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, + 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, + 6, 7, 10, 21, 23, 63, 140, 37, 130, 106, 28, 40, 165, 179, 73, + 178, 60, 126, 114, 78, 113, 27, 95, 3, 62, 104, 145, 96, 19, 92, + 123, 14, 90, 153, 183, 9, 72, 81, 118, 112, 124, 16, 182, 76, 146, + 115, 58, 144, 17, 105, 66, 31, 135, 54, 100, 84, 181, 103, 11, 88, + 133, 155, 167, 173, 143, 86, 158, 20, 168, 132, 141, 102, 50, 48, 71, + 147, 53, 87, 1, 108, 138, 36, 134, 139, 163, 82, 43, 52, 150, 12, + 30, 110, 156, 107, 120, 91, 122, 69, 164, 170, 116, 25, 94, 5, 22, + 24, 162, 175, 38, 157, 98, 44, 160, 47, 97, 142, 8, 74, 13, 177, + 15, 128, 26, 131, 154, 65, 169, 55, 136, 125, 171, 161, 29, 129, 151, + 68, 166, 51, 70, 45, 56, 79, 149, 99, 42, 101, 152, 39, 89, 180, + 64, 49, 6, 80, 172, 32, 109, 2, 119, 93, 176, 0, 33, 57, 34, + 18, 85, 121, 137, 83, 111, 59, 7, 77, 4, 117, 159, 148, 35, 61, + 41, 67, 46, 127, 75, 174, 97, 172, + }; + uint8_t encoded_payload_[255] = { + 0, 1, 2, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, + 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, + 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, + 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, + 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 10, 21, 23, 63, + 140, 37, 130, 106, 28, 40, 165, 179, 73, 178, 60, 126, 114, 78, 113, + 27, 95, 3, 62, 104, 145, 96, 19, 92, 123, 14, 90, 153, 183, 9, + 72, 81, 118, 112, 124, 16, 182, 76, 146, 115, 58, 144, 17, 105, 66, + 31, 135, 54, 100, 84, 181, 103, 11, 88, 133, 155, 167, 173, 143, 86, + 158, 20, 168, 132, 141, 102, 50, 48, 71, 147, 53, 87, 1, 108, 138, + 36, 134, 139, 163, 82, 43, 52, 150, 12, 30, 110, 156, 107, 120, 91, + 122, 69, 164, 170, 116, 25, 94, 5, 22, 24, 162, 175, 38, 157, 98, + 44, 160, 47, 97, 142, 8, 74, 13, 177, 15, 128, 26, 131, 154, 65, + 169, 55, 136, 125, 171, 161, 29, 129, 151, 68, 166, 51, 70, 45, 56, + 79, 149, 99, 42, 101, 152, 39, 89, 180, 64, 49, 6, 80, 172, 32, + 109, 2, 119, 93, 176, 0, 33, 57, 34, 18, 85, 121, 137, 83, 111, + 59, 7, 77, 4, 117, 159, 148, 35, 61, 41, 67, 46, 127, 75, 174, + }; +}; - test_msg.signed_messages[145] = 39; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_encoded_len(&info.test_msg), + info.payload_len); - test_msg.signed_messages[146] = 89; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEcdsaSignatureDepA, &info.test_msg_wrapped), + info.payload_len); +} - test_msg.signed_messages[147] = 180; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEcdsaSignatureDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} - test_msg.signed_messages[148] = 64; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; - test_msg.signed_messages[149] = 49; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.signed_messages[150] = 6; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEcdsaSignatureDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.signed_messages[151] = 80; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_a_t msg{}; - test_msg.signed_messages[152] = 172; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ecdsa_signature_dep_a_t t{}; + return sbp_msg_ecdsa_signature_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ecdsa_signature_dep_a_t t{}; + t.n_signed_messages = 1; + return sbp_msg_ecdsa_signature_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} - test_msg.signed_messages[153] = 32; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[154] = 109; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.signed_messages[155] = 2; + CHandler handler{&state}; - test_msg.signed_messages[156] = 119; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - test_msg.signed_messages[157] = 93; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.signed_messages[158] = 176; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.signed_messages[159] = 0; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[160] = 33; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.signed_messages[161] = 57; + CHandler handler(&state); - test_msg.signed_messages[162] = 34; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.signed_messages[163] = 18; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.signed_messages[164] = 85; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.signed_messages[165] = 121; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[166] = 137; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.signed_messages[167] = 83; + CHandler handler{&state}; - test_msg.signed_messages[168] = 111; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.signed_messages[169] = 59; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.signed_messages[170] = 7; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.signed_messages[171] = 77; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.signed_messages[172] = 4; + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[173] = 117; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.signed_messages[174] = 159; + CHandler handler{&state}; - test_msg.signed_messages[175] = 148; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.signed_messages[176] = 35; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.signed_messages[177] = 61; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[178] = 41; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signed_messages[179] = 67; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.signed_messages[180] = 46; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[181] = 127; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signed_messages[182] = 75; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignatureDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signed_messages[183] = 174; - test_msg.stream_counter = 1; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - while (dummy_rd_ < dummy_wr_) { - process(); + EXPECT_NE(sbp_message_send(&state, SbpMsgEcdsaSignatureDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.certificate_id[0], 1) - << "incorrect value for last_msg_.certificate_id[0], expected 1, is " - << last_msg_.certificate_id[0]; - EXPECT_EQ(last_msg_.certificate_id[1], 2) - << "incorrect value for last_msg_.certificate_id[1], expected 2, is " - << last_msg_.certificate_id[1]; - EXPECT_EQ(last_msg_.certificate_id[2], 3) - << "incorrect value for last_msg_.certificate_id[2], expected 3, is " - << last_msg_.certificate_id[2]; - EXPECT_EQ(last_msg_.certificate_id[3], 4) - << "incorrect value for last_msg_.certificate_id[3], expected 4, is " - << last_msg_.certificate_id[3]; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_signed_messages, 184) - << "incorrect value for last_msg_.n_signed_messages, expected 184, is " - << last_msg_.n_signed_messages; - EXPECT_EQ(last_msg_.on_demand_counter, 2) - << "incorrect value for last_msg_.on_demand_counter, expected 2, is " - << last_msg_.on_demand_counter; - EXPECT_EQ(last_msg_.signature[0], 0) - << "incorrect value for last_msg_.signature[0], expected 0, is " - << last_msg_.signature[0]; - EXPECT_EQ(last_msg_.signature[1], 1) - << "incorrect value for last_msg_.signature[1], expected 1, is " - << last_msg_.signature[1]; - EXPECT_EQ(last_msg_.signature[2], 2) - << "incorrect value for last_msg_.signature[2], expected 2, is " - << last_msg_.signature[2]; - EXPECT_EQ(last_msg_.signature[3], 3) - << "incorrect value for last_msg_.signature[3], expected 3, is " - << last_msg_.signature[3]; - EXPECT_EQ(last_msg_.signature[4], 4) - << "incorrect value for last_msg_.signature[4], expected 4, is " - << last_msg_.signature[4]; - EXPECT_EQ(last_msg_.signature[5], 5) - << "incorrect value for last_msg_.signature[5], expected 5, is " - << last_msg_.signature[5]; - EXPECT_EQ(last_msg_.signature[6], 6) - << "incorrect value for last_msg_.signature[6], expected 6, is " - << last_msg_.signature[6]; - EXPECT_EQ(last_msg_.signature[7], 7) - << "incorrect value for last_msg_.signature[7], expected 7, is " - << last_msg_.signature[7]; - EXPECT_EQ(last_msg_.signature[8], 0) - << "incorrect value for last_msg_.signature[8], expected 0, is " - << last_msg_.signature[8]; - EXPECT_EQ(last_msg_.signature[9], 1) - << "incorrect value for last_msg_.signature[9], expected 1, is " - << last_msg_.signature[9]; - EXPECT_EQ(last_msg_.signature[10], 2) - << "incorrect value for last_msg_.signature[10], expected 2, is " - << last_msg_.signature[10]; - EXPECT_EQ(last_msg_.signature[11], 3) - << "incorrect value for last_msg_.signature[11], expected 3, is " - << last_msg_.signature[11]; - EXPECT_EQ(last_msg_.signature[12], 4) - << "incorrect value for last_msg_.signature[12], expected 4, is " - << last_msg_.signature[12]; - EXPECT_EQ(last_msg_.signature[13], 5) - << "incorrect value for last_msg_.signature[13], expected 5, is " - << last_msg_.signature[13]; - EXPECT_EQ(last_msg_.signature[14], 6) - << "incorrect value for last_msg_.signature[14], expected 6, is " - << last_msg_.signature[14]; - EXPECT_EQ(last_msg_.signature[15], 7) - << "incorrect value for last_msg_.signature[15], expected 7, is " - << last_msg_.signature[15]; - EXPECT_EQ(last_msg_.signature[16], 0) - << "incorrect value for last_msg_.signature[16], expected 0, is " - << last_msg_.signature[16]; - EXPECT_EQ(last_msg_.signature[17], 1) - << "incorrect value for last_msg_.signature[17], expected 1, is " - << last_msg_.signature[17]; - EXPECT_EQ(last_msg_.signature[18], 2) - << "incorrect value for last_msg_.signature[18], expected 2, is " - << last_msg_.signature[18]; - EXPECT_EQ(last_msg_.signature[19], 3) - << "incorrect value for last_msg_.signature[19], expected 3, is " - << last_msg_.signature[19]; - EXPECT_EQ(last_msg_.signature[20], 4) - << "incorrect value for last_msg_.signature[20], expected 4, is " - << last_msg_.signature[20]; - EXPECT_EQ(last_msg_.signature[21], 5) - << "incorrect value for last_msg_.signature[21], expected 5, is " - << last_msg_.signature[21]; - EXPECT_EQ(last_msg_.signature[22], 6) - << "incorrect value for last_msg_.signature[22], expected 6, is " - << last_msg_.signature[22]; - EXPECT_EQ(last_msg_.signature[23], 7) - << "incorrect value for last_msg_.signature[23], expected 7, is " - << last_msg_.signature[23]; - EXPECT_EQ(last_msg_.signature[24], 0) - << "incorrect value for last_msg_.signature[24], expected 0, is " - << last_msg_.signature[24]; - EXPECT_EQ(last_msg_.signature[25], 1) - << "incorrect value for last_msg_.signature[25], expected 1, is " - << last_msg_.signature[25]; - EXPECT_EQ(last_msg_.signature[26], 2) - << "incorrect value for last_msg_.signature[26], expected 2, is " - << last_msg_.signature[26]; - EXPECT_EQ(last_msg_.signature[27], 3) - << "incorrect value for last_msg_.signature[27], expected 3, is " - << last_msg_.signature[27]; - EXPECT_EQ(last_msg_.signature[28], 4) - << "incorrect value for last_msg_.signature[28], expected 4, is " - << last_msg_.signature[28]; - EXPECT_EQ(last_msg_.signature[29], 5) - << "incorrect value for last_msg_.signature[29], expected 5, is " - << last_msg_.signature[29]; - EXPECT_EQ(last_msg_.signature[30], 6) - << "incorrect value for last_msg_.signature[30], expected 6, is " - << last_msg_.signature[30]; - EXPECT_EQ(last_msg_.signature[31], 7) - << "incorrect value for last_msg_.signature[31], expected 7, is " - << last_msg_.signature[31]; - EXPECT_EQ(last_msg_.signature[32], 0) - << "incorrect value for last_msg_.signature[32], expected 0, is " - << last_msg_.signature[32]; - EXPECT_EQ(last_msg_.signature[33], 1) - << "incorrect value for last_msg_.signature[33], expected 1, is " - << last_msg_.signature[33]; - EXPECT_EQ(last_msg_.signature[34], 2) - << "incorrect value for last_msg_.signature[34], expected 2, is " - << last_msg_.signature[34]; - EXPECT_EQ(last_msg_.signature[35], 3) - << "incorrect value for last_msg_.signature[35], expected 3, is " - << last_msg_.signature[35]; - EXPECT_EQ(last_msg_.signature[36], 4) - << "incorrect value for last_msg_.signature[36], expected 4, is " - << last_msg_.signature[36]; - EXPECT_EQ(last_msg_.signature[37], 5) - << "incorrect value for last_msg_.signature[37], expected 5, is " - << last_msg_.signature[37]; - EXPECT_EQ(last_msg_.signature[38], 6) - << "incorrect value for last_msg_.signature[38], expected 6, is " - << last_msg_.signature[38]; - EXPECT_EQ(last_msg_.signature[39], 7) - << "incorrect value for last_msg_.signature[39], expected 7, is " - << last_msg_.signature[39]; - EXPECT_EQ(last_msg_.signature[40], 0) - << "incorrect value for last_msg_.signature[40], expected 0, is " - << last_msg_.signature[40]; - EXPECT_EQ(last_msg_.signature[41], 1) - << "incorrect value for last_msg_.signature[41], expected 1, is " - << last_msg_.signature[41]; - EXPECT_EQ(last_msg_.signature[42], 2) - << "incorrect value for last_msg_.signature[42], expected 2, is " - << last_msg_.signature[42]; - EXPECT_EQ(last_msg_.signature[43], 3) - << "incorrect value for last_msg_.signature[43], expected 3, is " - << last_msg_.signature[43]; - EXPECT_EQ(last_msg_.signature[44], 4) - << "incorrect value for last_msg_.signature[44], expected 4, is " - << last_msg_.signature[44]; - EXPECT_EQ(last_msg_.signature[45], 5) - << "incorrect value for last_msg_.signature[45], expected 5, is " - << last_msg_.signature[45]; - EXPECT_EQ(last_msg_.signature[46], 6) - << "incorrect value for last_msg_.signature[46], expected 6, is " - << last_msg_.signature[46]; - EXPECT_EQ(last_msg_.signature[47], 7) - << "incorrect value for last_msg_.signature[47], expected 7, is " - << last_msg_.signature[47]; - EXPECT_EQ(last_msg_.signature[48], 0) - << "incorrect value for last_msg_.signature[48], expected 0, is " - << last_msg_.signature[48]; - EXPECT_EQ(last_msg_.signature[49], 1) - << "incorrect value for last_msg_.signature[49], expected 1, is " - << last_msg_.signature[49]; - EXPECT_EQ(last_msg_.signature[50], 2) - << "incorrect value for last_msg_.signature[50], expected 2, is " - << last_msg_.signature[50]; - EXPECT_EQ(last_msg_.signature[51], 3) - << "incorrect value for last_msg_.signature[51], expected 3, is " - << last_msg_.signature[51]; - EXPECT_EQ(last_msg_.signature[52], 4) - << "incorrect value for last_msg_.signature[52], expected 4, is " - << last_msg_.signature[52]; - EXPECT_EQ(last_msg_.signature[53], 5) - << "incorrect value for last_msg_.signature[53], expected 5, is " - << last_msg_.signature[53]; - EXPECT_EQ(last_msg_.signature[54], 6) - << "incorrect value for last_msg_.signature[54], expected 6, is " - << last_msg_.signature[54]; - EXPECT_EQ(last_msg_.signature[55], 7) - << "incorrect value for last_msg_.signature[55], expected 7, is " - << last_msg_.signature[55]; - EXPECT_EQ(last_msg_.signature[56], 0) - << "incorrect value for last_msg_.signature[56], expected 0, is " - << last_msg_.signature[56]; - EXPECT_EQ(last_msg_.signature[57], 1) - << "incorrect value for last_msg_.signature[57], expected 1, is " - << last_msg_.signature[57]; - EXPECT_EQ(last_msg_.signature[58], 2) - << "incorrect value for last_msg_.signature[58], expected 2, is " - << last_msg_.signature[58]; - EXPECT_EQ(last_msg_.signature[59], 3) - << "incorrect value for last_msg_.signature[59], expected 3, is " - << last_msg_.signature[59]; - EXPECT_EQ(last_msg_.signature[60], 4) - << "incorrect value for last_msg_.signature[60], expected 4, is " - << last_msg_.signature[60]; - EXPECT_EQ(last_msg_.signature[61], 5) - << "incorrect value for last_msg_.signature[61], expected 5, is " - << last_msg_.signature[61]; - EXPECT_EQ(last_msg_.signature[62], 6) - << "incorrect value for last_msg_.signature[62], expected 6, is " - << last_msg_.signature[62]; - EXPECT_EQ(last_msg_.signature[63], 7) - << "incorrect value for last_msg_.signature[63], expected 7, is " - << last_msg_.signature[63]; - EXPECT_EQ(last_msg_.signed_messages[0], 10) - << "incorrect value for last_msg_.signed_messages[0], expected 10, is " - << last_msg_.signed_messages[0]; - EXPECT_EQ(last_msg_.signed_messages[1], 21) - << "incorrect value for last_msg_.signed_messages[1], expected 21, is " - << last_msg_.signed_messages[1]; - EXPECT_EQ(last_msg_.signed_messages[2], 23) - << "incorrect value for last_msg_.signed_messages[2], expected 23, is " - << last_msg_.signed_messages[2]; - EXPECT_EQ(last_msg_.signed_messages[3], 63) - << "incorrect value for last_msg_.signed_messages[3], expected 63, is " - << last_msg_.signed_messages[3]; - EXPECT_EQ(last_msg_.signed_messages[4], 140) - << "incorrect value for last_msg_.signed_messages[4], expected 140, is " - << last_msg_.signed_messages[4]; - EXPECT_EQ(last_msg_.signed_messages[5], 37) - << "incorrect value for last_msg_.signed_messages[5], expected 37, is " - << last_msg_.signed_messages[5]; - EXPECT_EQ(last_msg_.signed_messages[6], 130) - << "incorrect value for last_msg_.signed_messages[6], expected 130, is " - << last_msg_.signed_messages[6]; - EXPECT_EQ(last_msg_.signed_messages[7], 106) - << "incorrect value for last_msg_.signed_messages[7], expected 106, is " - << last_msg_.signed_messages[7]; - EXPECT_EQ(last_msg_.signed_messages[8], 28) - << "incorrect value for last_msg_.signed_messages[8], expected 28, is " - << last_msg_.signed_messages[8]; - EXPECT_EQ(last_msg_.signed_messages[9], 40) - << "incorrect value for last_msg_.signed_messages[9], expected 40, is " - << last_msg_.signed_messages[9]; - EXPECT_EQ(last_msg_.signed_messages[10], 165) - << "incorrect value for last_msg_.signed_messages[10], expected 165, is " - << last_msg_.signed_messages[10]; - EXPECT_EQ(last_msg_.signed_messages[11], 179) - << "incorrect value for last_msg_.signed_messages[11], expected 179, is " - << last_msg_.signed_messages[11]; - EXPECT_EQ(last_msg_.signed_messages[12], 73) - << "incorrect value for last_msg_.signed_messages[12], expected 73, is " - << last_msg_.signed_messages[12]; - EXPECT_EQ(last_msg_.signed_messages[13], 178) - << "incorrect value for last_msg_.signed_messages[13], expected 178, is " - << last_msg_.signed_messages[13]; - EXPECT_EQ(last_msg_.signed_messages[14], 60) - << "incorrect value for last_msg_.signed_messages[14], expected 60, is " - << last_msg_.signed_messages[14]; - EXPECT_EQ(last_msg_.signed_messages[15], 126) - << "incorrect value for last_msg_.signed_messages[15], expected 126, is " - << last_msg_.signed_messages[15]; - EXPECT_EQ(last_msg_.signed_messages[16], 114) - << "incorrect value for last_msg_.signed_messages[16], expected 114, is " - << last_msg_.signed_messages[16]; - EXPECT_EQ(last_msg_.signed_messages[17], 78) - << "incorrect value for last_msg_.signed_messages[17], expected 78, is " - << last_msg_.signed_messages[17]; - EXPECT_EQ(last_msg_.signed_messages[18], 113) - << "incorrect value for last_msg_.signed_messages[18], expected 113, is " - << last_msg_.signed_messages[18]; - EXPECT_EQ(last_msg_.signed_messages[19], 27) - << "incorrect value for last_msg_.signed_messages[19], expected 27, is " - << last_msg_.signed_messages[19]; - EXPECT_EQ(last_msg_.signed_messages[20], 95) - << "incorrect value for last_msg_.signed_messages[20], expected 95, is " - << last_msg_.signed_messages[20]; - EXPECT_EQ(last_msg_.signed_messages[21], 3) - << "incorrect value for last_msg_.signed_messages[21], expected 3, is " - << last_msg_.signed_messages[21]; - EXPECT_EQ(last_msg_.signed_messages[22], 62) - << "incorrect value for last_msg_.signed_messages[22], expected 62, is " - << last_msg_.signed_messages[22]; - EXPECT_EQ(last_msg_.signed_messages[23], 104) - << "incorrect value for last_msg_.signed_messages[23], expected 104, is " - << last_msg_.signed_messages[23]; - EXPECT_EQ(last_msg_.signed_messages[24], 145) - << "incorrect value for last_msg_.signed_messages[24], expected 145, is " - << last_msg_.signed_messages[24]; - EXPECT_EQ(last_msg_.signed_messages[25], 96) - << "incorrect value for last_msg_.signed_messages[25], expected 96, is " - << last_msg_.signed_messages[25]; - EXPECT_EQ(last_msg_.signed_messages[26], 19) - << "incorrect value for last_msg_.signed_messages[26], expected 19, is " - << last_msg_.signed_messages[26]; - EXPECT_EQ(last_msg_.signed_messages[27], 92) - << "incorrect value for last_msg_.signed_messages[27], expected 92, is " - << last_msg_.signed_messages[27]; - EXPECT_EQ(last_msg_.signed_messages[28], 123) - << "incorrect value for last_msg_.signed_messages[28], expected 123, is " - << last_msg_.signed_messages[28]; - EXPECT_EQ(last_msg_.signed_messages[29], 14) - << "incorrect value for last_msg_.signed_messages[29], expected 14, is " - << last_msg_.signed_messages[29]; - EXPECT_EQ(last_msg_.signed_messages[30], 90) - << "incorrect value for last_msg_.signed_messages[30], expected 90, is " - << last_msg_.signed_messages[30]; - EXPECT_EQ(last_msg_.signed_messages[31], 153) - << "incorrect value for last_msg_.signed_messages[31], expected 153, is " - << last_msg_.signed_messages[31]; - EXPECT_EQ(last_msg_.signed_messages[32], 183) - << "incorrect value for last_msg_.signed_messages[32], expected 183, is " - << last_msg_.signed_messages[32]; - EXPECT_EQ(last_msg_.signed_messages[33], 9) - << "incorrect value for last_msg_.signed_messages[33], expected 9, is " - << last_msg_.signed_messages[33]; - EXPECT_EQ(last_msg_.signed_messages[34], 72) - << "incorrect value for last_msg_.signed_messages[34], expected 72, is " - << last_msg_.signed_messages[34]; - EXPECT_EQ(last_msg_.signed_messages[35], 81) - << "incorrect value for last_msg_.signed_messages[35], expected 81, is " - << last_msg_.signed_messages[35]; - EXPECT_EQ(last_msg_.signed_messages[36], 118) - << "incorrect value for last_msg_.signed_messages[36], expected 118, is " - << last_msg_.signed_messages[36]; - EXPECT_EQ(last_msg_.signed_messages[37], 112) - << "incorrect value for last_msg_.signed_messages[37], expected 112, is " - << last_msg_.signed_messages[37]; - EXPECT_EQ(last_msg_.signed_messages[38], 124) - << "incorrect value for last_msg_.signed_messages[38], expected 124, is " - << last_msg_.signed_messages[38]; - EXPECT_EQ(last_msg_.signed_messages[39], 16) - << "incorrect value for last_msg_.signed_messages[39], expected 16, is " - << last_msg_.signed_messages[39]; - EXPECT_EQ(last_msg_.signed_messages[40], 182) - << "incorrect value for last_msg_.signed_messages[40], expected 182, is " - << last_msg_.signed_messages[40]; - EXPECT_EQ(last_msg_.signed_messages[41], 76) - << "incorrect value for last_msg_.signed_messages[41], expected 76, is " - << last_msg_.signed_messages[41]; - EXPECT_EQ(last_msg_.signed_messages[42], 146) - << "incorrect value for last_msg_.signed_messages[42], expected 146, is " - << last_msg_.signed_messages[42]; - EXPECT_EQ(last_msg_.signed_messages[43], 115) - << "incorrect value for last_msg_.signed_messages[43], expected 115, is " - << last_msg_.signed_messages[43]; - EXPECT_EQ(last_msg_.signed_messages[44], 58) - << "incorrect value for last_msg_.signed_messages[44], expected 58, is " - << last_msg_.signed_messages[44]; - EXPECT_EQ(last_msg_.signed_messages[45], 144) - << "incorrect value for last_msg_.signed_messages[45], expected 144, is " - << last_msg_.signed_messages[45]; - EXPECT_EQ(last_msg_.signed_messages[46], 17) - << "incorrect value for last_msg_.signed_messages[46], expected 17, is " - << last_msg_.signed_messages[46]; - EXPECT_EQ(last_msg_.signed_messages[47], 105) - << "incorrect value for last_msg_.signed_messages[47], expected 105, is " - << last_msg_.signed_messages[47]; - EXPECT_EQ(last_msg_.signed_messages[48], 66) - << "incorrect value for last_msg_.signed_messages[48], expected 66, is " - << last_msg_.signed_messages[48]; - EXPECT_EQ(last_msg_.signed_messages[49], 31) - << "incorrect value for last_msg_.signed_messages[49], expected 31, is " - << last_msg_.signed_messages[49]; - EXPECT_EQ(last_msg_.signed_messages[50], 135) - << "incorrect value for last_msg_.signed_messages[50], expected 135, is " - << last_msg_.signed_messages[50]; - EXPECT_EQ(last_msg_.signed_messages[51], 54) - << "incorrect value for last_msg_.signed_messages[51], expected 54, is " - << last_msg_.signed_messages[51]; - EXPECT_EQ(last_msg_.signed_messages[52], 100) - << "incorrect value for last_msg_.signed_messages[52], expected 100, is " - << last_msg_.signed_messages[52]; - EXPECT_EQ(last_msg_.signed_messages[53], 84) - << "incorrect value for last_msg_.signed_messages[53], expected 84, is " - << last_msg_.signed_messages[53]; - EXPECT_EQ(last_msg_.signed_messages[54], 181) - << "incorrect value for last_msg_.signed_messages[54], expected 181, is " - << last_msg_.signed_messages[54]; - EXPECT_EQ(last_msg_.signed_messages[55], 103) - << "incorrect value for last_msg_.signed_messages[55], expected 103, is " - << last_msg_.signed_messages[55]; - EXPECT_EQ(last_msg_.signed_messages[56], 11) - << "incorrect value for last_msg_.signed_messages[56], expected 11, is " - << last_msg_.signed_messages[56]; - EXPECT_EQ(last_msg_.signed_messages[57], 88) - << "incorrect value for last_msg_.signed_messages[57], expected 88, is " - << last_msg_.signed_messages[57]; - EXPECT_EQ(last_msg_.signed_messages[58], 133) - << "incorrect value for last_msg_.signed_messages[58], expected 133, is " - << last_msg_.signed_messages[58]; - EXPECT_EQ(last_msg_.signed_messages[59], 155) - << "incorrect value for last_msg_.signed_messages[59], expected 155, is " - << last_msg_.signed_messages[59]; - EXPECT_EQ(last_msg_.signed_messages[60], 167) - << "incorrect value for last_msg_.signed_messages[60], expected 167, is " - << last_msg_.signed_messages[60]; - EXPECT_EQ(last_msg_.signed_messages[61], 173) - << "incorrect value for last_msg_.signed_messages[61], expected 173, is " - << last_msg_.signed_messages[61]; - EXPECT_EQ(last_msg_.signed_messages[62], 143) - << "incorrect value for last_msg_.signed_messages[62], expected 143, is " - << last_msg_.signed_messages[62]; - EXPECT_EQ(last_msg_.signed_messages[63], 86) - << "incorrect value for last_msg_.signed_messages[63], expected 86, is " - << last_msg_.signed_messages[63]; - EXPECT_EQ(last_msg_.signed_messages[64], 158) - << "incorrect value for last_msg_.signed_messages[64], expected 158, is " - << last_msg_.signed_messages[64]; - EXPECT_EQ(last_msg_.signed_messages[65], 20) - << "incorrect value for last_msg_.signed_messages[65], expected 20, is " - << last_msg_.signed_messages[65]; - EXPECT_EQ(last_msg_.signed_messages[66], 168) - << "incorrect value for last_msg_.signed_messages[66], expected 168, is " - << last_msg_.signed_messages[66]; - EXPECT_EQ(last_msg_.signed_messages[67], 132) - << "incorrect value for last_msg_.signed_messages[67], expected 132, is " - << last_msg_.signed_messages[67]; - EXPECT_EQ(last_msg_.signed_messages[68], 141) - << "incorrect value for last_msg_.signed_messages[68], expected 141, is " - << last_msg_.signed_messages[68]; - EXPECT_EQ(last_msg_.signed_messages[69], 102) - << "incorrect value for last_msg_.signed_messages[69], expected 102, is " - << last_msg_.signed_messages[69]; - EXPECT_EQ(last_msg_.signed_messages[70], 50) - << "incorrect value for last_msg_.signed_messages[70], expected 50, is " - << last_msg_.signed_messages[70]; - EXPECT_EQ(last_msg_.signed_messages[71], 48) - << "incorrect value for last_msg_.signed_messages[71], expected 48, is " - << last_msg_.signed_messages[71]; - EXPECT_EQ(last_msg_.signed_messages[72], 71) - << "incorrect value for last_msg_.signed_messages[72], expected 71, is " - << last_msg_.signed_messages[72]; - EXPECT_EQ(last_msg_.signed_messages[73], 147) - << "incorrect value for last_msg_.signed_messages[73], expected 147, is " - << last_msg_.signed_messages[73]; - EXPECT_EQ(last_msg_.signed_messages[74], 53) - << "incorrect value for last_msg_.signed_messages[74], expected 53, is " - << last_msg_.signed_messages[74]; - EXPECT_EQ(last_msg_.signed_messages[75], 87) - << "incorrect value for last_msg_.signed_messages[75], expected 87, is " - << last_msg_.signed_messages[75]; - EXPECT_EQ(last_msg_.signed_messages[76], 1) - << "incorrect value for last_msg_.signed_messages[76], expected 1, is " - << last_msg_.signed_messages[76]; - EXPECT_EQ(last_msg_.signed_messages[77], 108) - << "incorrect value for last_msg_.signed_messages[77], expected 108, is " - << last_msg_.signed_messages[77]; - EXPECT_EQ(last_msg_.signed_messages[78], 138) - << "incorrect value for last_msg_.signed_messages[78], expected 138, is " - << last_msg_.signed_messages[78]; - EXPECT_EQ(last_msg_.signed_messages[79], 36) - << "incorrect value for last_msg_.signed_messages[79], expected 36, is " - << last_msg_.signed_messages[79]; - EXPECT_EQ(last_msg_.signed_messages[80], 134) - << "incorrect value for last_msg_.signed_messages[80], expected 134, is " - << last_msg_.signed_messages[80]; - EXPECT_EQ(last_msg_.signed_messages[81], 139) - << "incorrect value for last_msg_.signed_messages[81], expected 139, is " - << last_msg_.signed_messages[81]; - EXPECT_EQ(last_msg_.signed_messages[82], 163) - << "incorrect value for last_msg_.signed_messages[82], expected 163, is " - << last_msg_.signed_messages[82]; - EXPECT_EQ(last_msg_.signed_messages[83], 82) - << "incorrect value for last_msg_.signed_messages[83], expected 82, is " - << last_msg_.signed_messages[83]; - EXPECT_EQ(last_msg_.signed_messages[84], 43) - << "incorrect value for last_msg_.signed_messages[84], expected 43, is " - << last_msg_.signed_messages[84]; - EXPECT_EQ(last_msg_.signed_messages[85], 52) - << "incorrect value for last_msg_.signed_messages[85], expected 52, is " - << last_msg_.signed_messages[85]; - EXPECT_EQ(last_msg_.signed_messages[86], 150) - << "incorrect value for last_msg_.signed_messages[86], expected 150, is " - << last_msg_.signed_messages[86]; - EXPECT_EQ(last_msg_.signed_messages[87], 12) - << "incorrect value for last_msg_.signed_messages[87], expected 12, is " - << last_msg_.signed_messages[87]; - EXPECT_EQ(last_msg_.signed_messages[88], 30) - << "incorrect value for last_msg_.signed_messages[88], expected 30, is " - << last_msg_.signed_messages[88]; - EXPECT_EQ(last_msg_.signed_messages[89], 110) - << "incorrect value for last_msg_.signed_messages[89], expected 110, is " - << last_msg_.signed_messages[89]; - EXPECT_EQ(last_msg_.signed_messages[90], 156) - << "incorrect value for last_msg_.signed_messages[90], expected 156, is " - << last_msg_.signed_messages[90]; - EXPECT_EQ(last_msg_.signed_messages[91], 107) - << "incorrect value for last_msg_.signed_messages[91], expected 107, is " - << last_msg_.signed_messages[91]; - EXPECT_EQ(last_msg_.signed_messages[92], 120) - << "incorrect value for last_msg_.signed_messages[92], expected 120, is " - << last_msg_.signed_messages[92]; - EXPECT_EQ(last_msg_.signed_messages[93], 91) - << "incorrect value for last_msg_.signed_messages[93], expected 91, is " - << last_msg_.signed_messages[93]; - EXPECT_EQ(last_msg_.signed_messages[94], 122) - << "incorrect value for last_msg_.signed_messages[94], expected 122, is " - << last_msg_.signed_messages[94]; - EXPECT_EQ(last_msg_.signed_messages[95], 69) - << "incorrect value for last_msg_.signed_messages[95], expected 69, is " - << last_msg_.signed_messages[95]; - EXPECT_EQ(last_msg_.signed_messages[96], 164) - << "incorrect value for last_msg_.signed_messages[96], expected 164, is " - << last_msg_.signed_messages[96]; - EXPECT_EQ(last_msg_.signed_messages[97], 170) - << "incorrect value for last_msg_.signed_messages[97], expected 170, is " - << last_msg_.signed_messages[97]; - EXPECT_EQ(last_msg_.signed_messages[98], 116) - << "incorrect value for last_msg_.signed_messages[98], expected 116, is " - << last_msg_.signed_messages[98]; - EXPECT_EQ(last_msg_.signed_messages[99], 25) - << "incorrect value for last_msg_.signed_messages[99], expected 25, is " - << last_msg_.signed_messages[99]; - EXPECT_EQ(last_msg_.signed_messages[100], 94) - << "incorrect value for last_msg_.signed_messages[100], expected 94, is " - << last_msg_.signed_messages[100]; - EXPECT_EQ(last_msg_.signed_messages[101], 5) - << "incorrect value for last_msg_.signed_messages[101], expected 5, is " - << last_msg_.signed_messages[101]; - EXPECT_EQ(last_msg_.signed_messages[102], 22) - << "incorrect value for last_msg_.signed_messages[102], expected 22, is " - << last_msg_.signed_messages[102]; - EXPECT_EQ(last_msg_.signed_messages[103], 24) - << "incorrect value for last_msg_.signed_messages[103], expected 24, is " - << last_msg_.signed_messages[103]; - EXPECT_EQ(last_msg_.signed_messages[104], 162) - << "incorrect value for last_msg_.signed_messages[104], expected 162, is " - << last_msg_.signed_messages[104]; - EXPECT_EQ(last_msg_.signed_messages[105], 175) - << "incorrect value for last_msg_.signed_messages[105], expected 175, is " - << last_msg_.signed_messages[105]; - EXPECT_EQ(last_msg_.signed_messages[106], 38) - << "incorrect value for last_msg_.signed_messages[106], expected 38, is " - << last_msg_.signed_messages[106]; - EXPECT_EQ(last_msg_.signed_messages[107], 157) - << "incorrect value for last_msg_.signed_messages[107], expected 157, is " - << last_msg_.signed_messages[107]; - EXPECT_EQ(last_msg_.signed_messages[108], 98) - << "incorrect value for last_msg_.signed_messages[108], expected 98, is " - << last_msg_.signed_messages[108]; - EXPECT_EQ(last_msg_.signed_messages[109], 44) - << "incorrect value for last_msg_.signed_messages[109], expected 44, is " - << last_msg_.signed_messages[109]; - EXPECT_EQ(last_msg_.signed_messages[110], 160) - << "incorrect value for last_msg_.signed_messages[110], expected 160, is " - << last_msg_.signed_messages[110]; - EXPECT_EQ(last_msg_.signed_messages[111], 47) - << "incorrect value for last_msg_.signed_messages[111], expected 47, is " - << last_msg_.signed_messages[111]; - EXPECT_EQ(last_msg_.signed_messages[112], 97) - << "incorrect value for last_msg_.signed_messages[112], expected 97, is " - << last_msg_.signed_messages[112]; - EXPECT_EQ(last_msg_.signed_messages[113], 142) - << "incorrect value for last_msg_.signed_messages[113], expected 142, is " - << last_msg_.signed_messages[113]; - EXPECT_EQ(last_msg_.signed_messages[114], 8) - << "incorrect value for last_msg_.signed_messages[114], expected 8, is " - << last_msg_.signed_messages[114]; - EXPECT_EQ(last_msg_.signed_messages[115], 74) - << "incorrect value for last_msg_.signed_messages[115], expected 74, is " - << last_msg_.signed_messages[115]; - EXPECT_EQ(last_msg_.signed_messages[116], 13) - << "incorrect value for last_msg_.signed_messages[116], expected 13, is " - << last_msg_.signed_messages[116]; - EXPECT_EQ(last_msg_.signed_messages[117], 177) - << "incorrect value for last_msg_.signed_messages[117], expected 177, is " - << last_msg_.signed_messages[117]; - EXPECT_EQ(last_msg_.signed_messages[118], 15) - << "incorrect value for last_msg_.signed_messages[118], expected 15, is " - << last_msg_.signed_messages[118]; - EXPECT_EQ(last_msg_.signed_messages[119], 128) - << "incorrect value for last_msg_.signed_messages[119], expected 128, is " - << last_msg_.signed_messages[119]; - EXPECT_EQ(last_msg_.signed_messages[120], 26) - << "incorrect value for last_msg_.signed_messages[120], expected 26, is " - << last_msg_.signed_messages[120]; - EXPECT_EQ(last_msg_.signed_messages[121], 131) - << "incorrect value for last_msg_.signed_messages[121], expected 131, is " - << last_msg_.signed_messages[121]; - EXPECT_EQ(last_msg_.signed_messages[122], 154) - << "incorrect value for last_msg_.signed_messages[122], expected 154, is " - << last_msg_.signed_messages[122]; - EXPECT_EQ(last_msg_.signed_messages[123], 65) - << "incorrect value for last_msg_.signed_messages[123], expected 65, is " - << last_msg_.signed_messages[123]; - EXPECT_EQ(last_msg_.signed_messages[124], 169) - << "incorrect value for last_msg_.signed_messages[124], expected 169, is " - << last_msg_.signed_messages[124]; - EXPECT_EQ(last_msg_.signed_messages[125], 55) - << "incorrect value for last_msg_.signed_messages[125], expected 55, is " - << last_msg_.signed_messages[125]; - EXPECT_EQ(last_msg_.signed_messages[126], 136) - << "incorrect value for last_msg_.signed_messages[126], expected 136, is " - << last_msg_.signed_messages[126]; - EXPECT_EQ(last_msg_.signed_messages[127], 125) - << "incorrect value for last_msg_.signed_messages[127], expected 125, is " - << last_msg_.signed_messages[127]; - EXPECT_EQ(last_msg_.signed_messages[128], 171) - << "incorrect value for last_msg_.signed_messages[128], expected 171, is " - << last_msg_.signed_messages[128]; - EXPECT_EQ(last_msg_.signed_messages[129], 161) - << "incorrect value for last_msg_.signed_messages[129], expected 161, is " - << last_msg_.signed_messages[129]; - EXPECT_EQ(last_msg_.signed_messages[130], 29) - << "incorrect value for last_msg_.signed_messages[130], expected 29, is " - << last_msg_.signed_messages[130]; - EXPECT_EQ(last_msg_.signed_messages[131], 129) - << "incorrect value for last_msg_.signed_messages[131], expected 129, is " - << last_msg_.signed_messages[131]; - EXPECT_EQ(last_msg_.signed_messages[132], 151) - << "incorrect value for last_msg_.signed_messages[132], expected 151, is " - << last_msg_.signed_messages[132]; - EXPECT_EQ(last_msg_.signed_messages[133], 68) - << "incorrect value for last_msg_.signed_messages[133], expected 68, is " - << last_msg_.signed_messages[133]; - EXPECT_EQ(last_msg_.signed_messages[134], 166) - << "incorrect value for last_msg_.signed_messages[134], expected 166, is " - << last_msg_.signed_messages[134]; - EXPECT_EQ(last_msg_.signed_messages[135], 51) - << "incorrect value for last_msg_.signed_messages[135], expected 51, is " - << last_msg_.signed_messages[135]; - EXPECT_EQ(last_msg_.signed_messages[136], 70) - << "incorrect value for last_msg_.signed_messages[136], expected 70, is " - << last_msg_.signed_messages[136]; - EXPECT_EQ(last_msg_.signed_messages[137], 45) - << "incorrect value for last_msg_.signed_messages[137], expected 45, is " - << last_msg_.signed_messages[137]; - EXPECT_EQ(last_msg_.signed_messages[138], 56) - << "incorrect value for last_msg_.signed_messages[138], expected 56, is " - << last_msg_.signed_messages[138]; - EXPECT_EQ(last_msg_.signed_messages[139], 79) - << "incorrect value for last_msg_.signed_messages[139], expected 79, is " - << last_msg_.signed_messages[139]; - EXPECT_EQ(last_msg_.signed_messages[140], 149) - << "incorrect value for last_msg_.signed_messages[140], expected 149, is " - << last_msg_.signed_messages[140]; - EXPECT_EQ(last_msg_.signed_messages[141], 99) - << "incorrect value for last_msg_.signed_messages[141], expected 99, is " - << last_msg_.signed_messages[141]; - EXPECT_EQ(last_msg_.signed_messages[142], 42) - << "incorrect value for last_msg_.signed_messages[142], expected 42, is " - << last_msg_.signed_messages[142]; - EXPECT_EQ(last_msg_.signed_messages[143], 101) - << "incorrect value for last_msg_.signed_messages[143], expected 101, is " - << last_msg_.signed_messages[143]; - EXPECT_EQ(last_msg_.signed_messages[144], 152) - << "incorrect value for last_msg_.signed_messages[144], expected 152, is " - << last_msg_.signed_messages[144]; - EXPECT_EQ(last_msg_.signed_messages[145], 39) - << "incorrect value for last_msg_.signed_messages[145], expected 39, is " - << last_msg_.signed_messages[145]; - EXPECT_EQ(last_msg_.signed_messages[146], 89) - << "incorrect value for last_msg_.signed_messages[146], expected 89, is " - << last_msg_.signed_messages[146]; - EXPECT_EQ(last_msg_.signed_messages[147], 180) - << "incorrect value for last_msg_.signed_messages[147], expected 180, is " - << last_msg_.signed_messages[147]; - EXPECT_EQ(last_msg_.signed_messages[148], 64) - << "incorrect value for last_msg_.signed_messages[148], expected 64, is " - << last_msg_.signed_messages[148]; - EXPECT_EQ(last_msg_.signed_messages[149], 49) - << "incorrect value for last_msg_.signed_messages[149], expected 49, is " - << last_msg_.signed_messages[149]; - EXPECT_EQ(last_msg_.signed_messages[150], 6) - << "incorrect value for last_msg_.signed_messages[150], expected 6, is " - << last_msg_.signed_messages[150]; - EXPECT_EQ(last_msg_.signed_messages[151], 80) - << "incorrect value for last_msg_.signed_messages[151], expected 80, is " - << last_msg_.signed_messages[151]; - EXPECT_EQ(last_msg_.signed_messages[152], 172) - << "incorrect value for last_msg_.signed_messages[152], expected 172, is " - << last_msg_.signed_messages[152]; - EXPECT_EQ(last_msg_.signed_messages[153], 32) - << "incorrect value for last_msg_.signed_messages[153], expected 32, is " - << last_msg_.signed_messages[153]; - EXPECT_EQ(last_msg_.signed_messages[154], 109) - << "incorrect value for last_msg_.signed_messages[154], expected 109, is " - << last_msg_.signed_messages[154]; - EXPECT_EQ(last_msg_.signed_messages[155], 2) - << "incorrect value for last_msg_.signed_messages[155], expected 2, is " - << last_msg_.signed_messages[155]; - EXPECT_EQ(last_msg_.signed_messages[156], 119) - << "incorrect value for last_msg_.signed_messages[156], expected 119, is " - << last_msg_.signed_messages[156]; - EXPECT_EQ(last_msg_.signed_messages[157], 93) - << "incorrect value for last_msg_.signed_messages[157], expected 93, is " - << last_msg_.signed_messages[157]; - EXPECT_EQ(last_msg_.signed_messages[158], 176) - << "incorrect value for last_msg_.signed_messages[158], expected 176, is " - << last_msg_.signed_messages[158]; - EXPECT_EQ(last_msg_.signed_messages[159], 0) - << "incorrect value for last_msg_.signed_messages[159], expected 0, is " - << last_msg_.signed_messages[159]; - EXPECT_EQ(last_msg_.signed_messages[160], 33) - << "incorrect value for last_msg_.signed_messages[160], expected 33, is " - << last_msg_.signed_messages[160]; - EXPECT_EQ(last_msg_.signed_messages[161], 57) - << "incorrect value for last_msg_.signed_messages[161], expected 57, is " - << last_msg_.signed_messages[161]; - EXPECT_EQ(last_msg_.signed_messages[162], 34) - << "incorrect value for last_msg_.signed_messages[162], expected 34, is " - << last_msg_.signed_messages[162]; - EXPECT_EQ(last_msg_.signed_messages[163], 18) - << "incorrect value for last_msg_.signed_messages[163], expected 18, is " - << last_msg_.signed_messages[163]; - EXPECT_EQ(last_msg_.signed_messages[164], 85) - << "incorrect value for last_msg_.signed_messages[164], expected 85, is " - << last_msg_.signed_messages[164]; - EXPECT_EQ(last_msg_.signed_messages[165], 121) - << "incorrect value for last_msg_.signed_messages[165], expected 121, is " - << last_msg_.signed_messages[165]; - EXPECT_EQ(last_msg_.signed_messages[166], 137) - << "incorrect value for last_msg_.signed_messages[166], expected 137, is " - << last_msg_.signed_messages[166]; - EXPECT_EQ(last_msg_.signed_messages[167], 83) - << "incorrect value for last_msg_.signed_messages[167], expected 83, is " - << last_msg_.signed_messages[167]; - EXPECT_EQ(last_msg_.signed_messages[168], 111) - << "incorrect value for last_msg_.signed_messages[168], expected 111, is " - << last_msg_.signed_messages[168]; - EXPECT_EQ(last_msg_.signed_messages[169], 59) - << "incorrect value for last_msg_.signed_messages[169], expected 59, is " - << last_msg_.signed_messages[169]; - EXPECT_EQ(last_msg_.signed_messages[170], 7) - << "incorrect value for last_msg_.signed_messages[170], expected 7, is " - << last_msg_.signed_messages[170]; - EXPECT_EQ(last_msg_.signed_messages[171], 77) - << "incorrect value for last_msg_.signed_messages[171], expected 77, is " - << last_msg_.signed_messages[171]; - EXPECT_EQ(last_msg_.signed_messages[172], 4) - << "incorrect value for last_msg_.signed_messages[172], expected 4, is " - << last_msg_.signed_messages[172]; - EXPECT_EQ(last_msg_.signed_messages[173], 117) - << "incorrect value for last_msg_.signed_messages[173], expected 117, is " - << last_msg_.signed_messages[173]; - EXPECT_EQ(last_msg_.signed_messages[174], 159) - << "incorrect value for last_msg_.signed_messages[174], expected 159, is " - << last_msg_.signed_messages[174]; - EXPECT_EQ(last_msg_.signed_messages[175], 148) - << "incorrect value for last_msg_.signed_messages[175], expected 148, is " - << last_msg_.signed_messages[175]; - EXPECT_EQ(last_msg_.signed_messages[176], 35) - << "incorrect value for last_msg_.signed_messages[176], expected 35, is " - << last_msg_.signed_messages[176]; - EXPECT_EQ(last_msg_.signed_messages[177], 61) - << "incorrect value for last_msg_.signed_messages[177], expected 61, is " - << last_msg_.signed_messages[177]; - EXPECT_EQ(last_msg_.signed_messages[178], 41) - << "incorrect value for last_msg_.signed_messages[178], expected 41, is " - << last_msg_.signed_messages[178]; - EXPECT_EQ(last_msg_.signed_messages[179], 67) - << "incorrect value for last_msg_.signed_messages[179], expected 67, is " - << last_msg_.signed_messages[179]; - EXPECT_EQ(last_msg_.signed_messages[180], 46) - << "incorrect value for last_msg_.signed_messages[180], expected 46, is " - << last_msg_.signed_messages[180]; - EXPECT_EQ(last_msg_.signed_messages[181], 127) - << "incorrect value for last_msg_.signed_messages[181], expected 127, is " - << last_msg_.signed_messages[181]; - EXPECT_EQ(last_msg_.signed_messages[182], 75) - << "incorrect value for last_msg_.signed_messages[182], expected 75, is " - << last_msg_.signed_messages[182]; - EXPECT_EQ(last_msg_.signed_messages[183], 174) - << "incorrect value for last_msg_.signed_messages[183], expected 174, is " - << last_msg_.signed_messages[183]; - EXPECT_EQ(last_msg_.stream_counter, 1) - << "incorrect value for last_msg_.stream_counter, expected 1, is " - << last_msg_.stream_counter; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignatureDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[0], greater.certificate_id[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[1], greater.certificate_id[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[2], greater.certificate_id[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[3], greater.certificate_id[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_signed_messages, greater.n_signed_messages); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.on_demand_counter, greater.on_demand_counter); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[0], greater.signature[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[1], greater.signature[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[2], greater.signature[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[3], greater.signature[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[4], greater.signature[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[5], greater.signature[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[6], greater.signature[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[7], greater.signature[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[8], greater.signature[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[9], greater.signature[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[10], greater.signature[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[11], greater.signature[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[12], greater.signature[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[13], greater.signature[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[14], greater.signature[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[15], greater.signature[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[16], greater.signature[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[17], greater.signature[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[18], greater.signature[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[19], greater.signature[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[20], greater.signature[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[21], greater.signature[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[22], greater.signature[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[23], greater.signature[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[24], greater.signature[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[25], greater.signature[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[26], greater.signature[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[27], greater.signature[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[28], greater.signature[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[29], greater.signature[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[30], greater.signature[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[31], greater.signature[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[32], greater.signature[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[33], greater.signature[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[34], greater.signature[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[35], greater.signature[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[36], greater.signature[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[37], greater.signature[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[38], greater.signature[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[39], greater.signature[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[40], greater.signature[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[41], greater.signature[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[42], greater.signature[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[43], greater.signature[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[44], greater.signature[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[45], greater.signature[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[46], greater.signature[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[47], greater.signature[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[48], greater.signature[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[49], greater.signature[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[50], greater.signature[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[51], greater.signature[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[52], greater.signature[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[53], greater.signature[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[54], greater.signature[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[55], greater.signature[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[56], greater.signature[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[57], greater.signature[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[58], greater.signature[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[59], greater.signature[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[60], greater.signature[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[61], greater.signature[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[62], greater.signature[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[63], greater.signature[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[0], greater.signed_messages[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[1], greater.signed_messages[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[2], greater.signed_messages[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[3], greater.signed_messages[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[4], greater.signed_messages[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[5], greater.signed_messages[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[6], greater.signed_messages[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[7], greater.signed_messages[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[8], greater.signed_messages[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[9], greater.signed_messages[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[10], + greater.signed_messages[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[11], + greater.signed_messages[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[12], + greater.signed_messages[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[13], + greater.signed_messages[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[14], + greater.signed_messages[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[15], + greater.signed_messages[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[16], + greater.signed_messages[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[17], + greater.signed_messages[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[18], + greater.signed_messages[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[19], + greater.signed_messages[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[20], + greater.signed_messages[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[21], + greater.signed_messages[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[22], + greater.signed_messages[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[23], + greater.signed_messages[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[24], + greater.signed_messages[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[25], + greater.signed_messages[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[26], + greater.signed_messages[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[27], + greater.signed_messages[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[28], + greater.signed_messages[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[29], + greater.signed_messages[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[30], + greater.signed_messages[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[31], + greater.signed_messages[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[32], + greater.signed_messages[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[33], + greater.signed_messages[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[34], + greater.signed_messages[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[35], + greater.signed_messages[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[36], + greater.signed_messages[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[37], + greater.signed_messages[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[38], + greater.signed_messages[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[39], + greater.signed_messages[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[40], + greater.signed_messages[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[41], + greater.signed_messages[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[42], + greater.signed_messages[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[43], + greater.signed_messages[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[44], + greater.signed_messages[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[45], + greater.signed_messages[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[46], + greater.signed_messages[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[47], + greater.signed_messages[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[48], + greater.signed_messages[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[49], + greater.signed_messages[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[50], + greater.signed_messages[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[51], + greater.signed_messages[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[52], + greater.signed_messages[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[53], + greater.signed_messages[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[54], + greater.signed_messages[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[55], + greater.signed_messages[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[56], + greater.signed_messages[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[57], + greater.signed_messages[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[58], + greater.signed_messages[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[59], + greater.signed_messages[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[60], + greater.signed_messages[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[61], + greater.signed_messages[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[62], + greater.signed_messages[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[63], + greater.signed_messages[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[64], + greater.signed_messages[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[65], + greater.signed_messages[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[66], + greater.signed_messages[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[67], + greater.signed_messages[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[68], + greater.signed_messages[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[69], + greater.signed_messages[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[70], + greater.signed_messages[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[71], + greater.signed_messages[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[72], + greater.signed_messages[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[73], + greater.signed_messages[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[74], + greater.signed_messages[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[75], + greater.signed_messages[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[76], + greater.signed_messages[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[77], + greater.signed_messages[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[78], + greater.signed_messages[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[79], + greater.signed_messages[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[80], + greater.signed_messages[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[81], + greater.signed_messages[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[82], + greater.signed_messages[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[83], + greater.signed_messages[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[84], + greater.signed_messages[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[85], + greater.signed_messages[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[86], + greater.signed_messages[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[87], + greater.signed_messages[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[88], + greater.signed_messages[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[89], + greater.signed_messages[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[90], + greater.signed_messages[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[91], + greater.signed_messages[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[92], + greater.signed_messages[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[93], + greater.signed_messages[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[94], + greater.signed_messages[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[95], + greater.signed_messages[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[96], + greater.signed_messages[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[97], + greater.signed_messages[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[98], + greater.signed_messages[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[99], + greater.signed_messages[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[100], + greater.signed_messages[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[101], + greater.signed_messages[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[102], + greater.signed_messages[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[103], + greater.signed_messages[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[104], + greater.signed_messages[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[105], + greater.signed_messages[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[106], + greater.signed_messages[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[107], + greater.signed_messages[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[108], + greater.signed_messages[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[109], + greater.signed_messages[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[110], + greater.signed_messages[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[111], + greater.signed_messages[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[112], + greater.signed_messages[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[113], + greater.signed_messages[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[114], + greater.signed_messages[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[115], + greater.signed_messages[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[116], + greater.signed_messages[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[117], + greater.signed_messages[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[118], + greater.signed_messages[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[119], + greater.signed_messages[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[120], + greater.signed_messages[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[121], + greater.signed_messages[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[122], + greater.signed_messages[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[123], + greater.signed_messages[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[124], + greater.signed_messages[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[125], + greater.signed_messages[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[126], + greater.signed_messages[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[127], + greater.signed_messages[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[128], + greater.signed_messages[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[129], + greater.signed_messages[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[130], + greater.signed_messages[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[131], + greater.signed_messages[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[132], + greater.signed_messages[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[133], + greater.signed_messages[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[134], + greater.signed_messages[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[135], + greater.signed_messages[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[136], + greater.signed_messages[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[137], + greater.signed_messages[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[138], + greater.signed_messages[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[139], + greater.signed_messages[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[140], + greater.signed_messages[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[141], + greater.signed_messages[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[142], + greater.signed_messages[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[143], + greater.signed_messages[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[144], + greater.signed_messages[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[145], + greater.signed_messages[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[146], + greater.signed_messages[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[147], + greater.signed_messages[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[148], + greater.signed_messages[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[149], + greater.signed_messages[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[150], + greater.signed_messages[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[151], + greater.signed_messages[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[152], + greater.signed_messages[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[153], + greater.signed_messages[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[154], + greater.signed_messages[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[155], + greater.signed_messages[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[156], + greater.signed_messages[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[157], + greater.signed_messages[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[158], + greater.signed_messages[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[159], + greater.signed_messages[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[160], + greater.signed_messages[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[161], + greater.signed_messages[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[162], + greater.signed_messages[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[163], + greater.signed_messages[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[164], + greater.signed_messages[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[165], + greater.signed_messages[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[166], + greater.signed_messages[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[167], + greater.signed_messages[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[168], + greater.signed_messages[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[169], + greater.signed_messages[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[170], + greater.signed_messages[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[171], + greater.signed_messages[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[172], + greater.signed_messages[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[173], + greater.signed_messages[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[174], + greater.signed_messages[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[175], + greater.signed_messages[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[176], + greater.signed_messages[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[177], + greater.signed_messages[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[178], + greater.signed_messages[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[179], + greater.signed_messages[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[180], + greater.signed_messages[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[181], + greater.signed_messages[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[182], + greater.signed_messages[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[183], + greater.signed_messages[183]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stream_counter, greater.stream_counter); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEcdsaSignatureDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ECDSA_SIGNATURE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ecdsa_signature_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ecdsa_signature_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ecdsa_signature_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ecdsa_signature_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEcdsaSignatureDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEcdsaSignatureDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepB.cc b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepB.cc index 0c90a45514..f8fd775aec 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepB.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEcdsaSignatureDepB.cc @@ -16,66 +16,529 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEcdsaSignatureDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEcdsaSignatureDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0() { + assign(test_msg_.certificate_id[0], 1); + + assign(test_msg_.certificate_id[1], 2); + + assign(test_msg_.certificate_id[2], 3); + + assign(test_msg_.certificate_id[3], 4); + assign(test_msg_.flags, 0); + assign(test_msg_.n_signature_bytes, 72); + assign(test_msg_.n_signed_messages, 3); + assign(test_msg_.on_demand_counter, 2); + + assign(test_msg_.signature[0], 0); + + assign(test_msg_.signature[1], 1); + + assign(test_msg_.signature[2], 2); + + assign(test_msg_.signature[3], 3); + + assign(test_msg_.signature[4], 4); + + assign(test_msg_.signature[5], 5); + + assign(test_msg_.signature[6], 6); + + assign(test_msg_.signature[7], 7); + + assign(test_msg_.signature[8], 8); + + assign(test_msg_.signature[9], 9); + + assign(test_msg_.signature[10], 10); + + assign(test_msg_.signature[11], 11); + + assign(test_msg_.signature[12], 12); + + assign(test_msg_.signature[13], 13); + + assign(test_msg_.signature[14], 14); + + assign(test_msg_.signature[15], 15); + + assign(test_msg_.signature[16], 16); + + assign(test_msg_.signature[17], 17); + + assign(test_msg_.signature[18], 18); + + assign(test_msg_.signature[19], 19); + + assign(test_msg_.signature[20], 20); + + assign(test_msg_.signature[21], 21); + + assign(test_msg_.signature[22], 22); + + assign(test_msg_.signature[23], 23); + + assign(test_msg_.signature[24], 24); + + assign(test_msg_.signature[25], 25); + + assign(test_msg_.signature[26], 26); + + assign(test_msg_.signature[27], 27); + + assign(test_msg_.signature[28], 28); + + assign(test_msg_.signature[29], 29); + + assign(test_msg_.signature[30], 30); + + assign(test_msg_.signature[31], 31); + + assign(test_msg_.signature[32], 32); + + assign(test_msg_.signature[33], 33); + + assign(test_msg_.signature[34], 34); + + assign(test_msg_.signature[35], 35); + + assign(test_msg_.signature[36], 36); + + assign(test_msg_.signature[37], 37); + + assign(test_msg_.signature[38], 38); + + assign(test_msg_.signature[39], 39); + + assign(test_msg_.signature[40], 40); + + assign(test_msg_.signature[41], 41); + + assign(test_msg_.signature[42], 42); + + assign(test_msg_.signature[43], 43); + + assign(test_msg_.signature[44], 44); + + assign(test_msg_.signature[45], 45); + + assign(test_msg_.signature[46], 46); + + assign(test_msg_.signature[47], 47); + + assign(test_msg_.signature[48], 48); + + assign(test_msg_.signature[49], 49); + + assign(test_msg_.signature[50], 50); + + assign(test_msg_.signature[51], 51); + + assign(test_msg_.signature[52], 52); + + assign(test_msg_.signature[53], 53); + + assign(test_msg_.signature[54], 54); + + assign(test_msg_.signature[55], 55); + + assign(test_msg_.signature[56], 56); + + assign(test_msg_.signature[57], 57); + + assign(test_msg_.signature[58], 58); + + assign(test_msg_.signature[59], 59); + + assign(test_msg_.signature[60], 60); + + assign(test_msg_.signature[61], 61); + + assign(test_msg_.signature[62], 62); + + assign(test_msg_.signature[63], 63); + + assign(test_msg_.signature[64], 64); + + assign(test_msg_.signature[65], 65); + + assign(test_msg_.signature[66], 66); + + assign(test_msg_.signature[67], 67); + + assign(test_msg_.signature[68], 68); + + assign(test_msg_.signature[69], 69); + + assign(test_msg_.signature[70], 70); + + assign(test_msg_.signature[71], 71); + + assign(test_msg_.signed_messages[0], 10); + + assign(test_msg_.signed_messages[1], 21); + + assign(test_msg_.signed_messages[2], 23); + assign(test_msg_.stream_counter, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ecdsa_signature_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEcdsaSignatureDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ecdsa_signature_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEcdsaSignatureDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ecdsa_signature_dep_b, + sizeof(msg->ecdsa_signature_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ecdsa_signature_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ecdsa_signature_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEcdsaSignatureDepB); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x9FFE; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 83; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ecdsa_signature_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ecdsa_signature_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ecdsa_signature_dep_b_t &lesser, + const sbp_msg_ecdsa_signature_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ecdsa_signature_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ecdsa_signature_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaSignatureDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEcdsaSignatureDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEcdsaSignatureDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEcdsaSignatureDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_signing_MsgEcdsaSignatureDepB0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ecdsa_signature_dep_b_t test_msg_{}; + uint8_t encoded_frame_[83 + 8] = { 85, 7, 12, 66, 0, 83, 0, 1, 2, 1, 2, 3, 4, 72, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, @@ -83,434 +546,1010 @@ TEST_F(Test_auto_check_sbp_signing_MsgEcdsaSignatureDepB0, Test) { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 10, 21, 23, 254, 159, }; + uint8_t encoded_payload_[83] = { + 0, 1, 2, 1, 2, 3, 4, 72, 0, 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 10, 21, 23, + }; +}; - sbp_msg_ecdsa_signature_dep_b_t test_msg{}; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_encoded_len(&info.test_msg), + info.payload_len); - test_msg.certificate_id[0] = 1; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgEcdsaSignatureDepB, &info.test_msg_wrapped), + info.payload_len); +} - test_msg.certificate_id[1] = 2; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEcdsaSignatureDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} - test_msg.certificate_id[2] = 3; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[83]; - test_msg.certificate_id[3] = 4; - test_msg.flags = 0; - test_msg.n_signature_bytes = 72; - test_msg.n_signed_messages = 3; - test_msg.on_demand_counter = 2; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + + for (uint8_t i = 0; i < 83; i++) { + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.signature[0] = 0; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgEcdsaSignatureDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.signature[1] = 1; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_b_t msg{}; - test_msg.signature[2] = 2; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ecdsa_signature_dep_b_t t{}; + return sbp_msg_ecdsa_signature_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ecdsa_signature_dep_b_t t{}; + t.n_signed_messages = 1; + return sbp_msg_ecdsa_signature_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} - test_msg.signature[3] = 3; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[4] = 4; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.signature[5] = 5; + CHandler handler{&state}; - test_msg.signature[6] = 6; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - test_msg.signature[7] = 7; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.signature[8] = 8; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.signature[9] = 9; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[10] = 10; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.signature[11] = 11; + CHandler handler(&state); - test_msg.signature[12] = 12; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.signature[13] = 13; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.signature[14] = 14; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.signature[15] = 15; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[16] = 16; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.signature[17] = 17; + CHandler handler{&state}; - test_msg.signature[18] = 18; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.signature[19] = 19; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.signature[20] = 20; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.signature[21] = 21; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.signature[22] = 22; + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[23] = 23; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.signature[24] = 24; + CHandler handler{&state}; - test_msg.signature[25] = 25; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.signature[26] = 26; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.signature[27] = 27; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[28] = 28; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature[29] = 29; + EXPECT_EQ(sbp_msg_ecdsa_signature_dep_b_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.signature[30] = 30; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[31] = 31; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature[32] = 32; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignatureDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signature[33] = 33; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.signature[34] = 34; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[35] = 35; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.signature[36] = 36; + EXPECT_NE(sbp_message_send(&state, SbpMsgEcdsaSignatureDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.signature[37] = 37; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signature[38] = 38; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signature[39] = 39; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEcdsaSignatureDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signature[40] = 40; +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, Comparison) { + auto info = get_test_msg_info(); - test_msg.signature[41] = 41; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[0], greater.certificate_id[0]); + comparison_tests(lesser, greater); + } - test_msg.signature[42] = 42; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[1], greater.certificate_id[1]); + comparison_tests(lesser, greater); + } - test_msg.signature[43] = 43; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[2], greater.certificate_id[2]); + comparison_tests(lesser, greater); + } - test_msg.signature[44] = 44; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_id[3], greater.certificate_id[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_signature_bytes, greater.n_signature_bytes); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_signed_messages, greater.n_signed_messages); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.on_demand_counter, greater.on_demand_counter); + comparison_tests(lesser, greater); + } - test_msg.signature[45] = 45; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[0], greater.signature[0]); + comparison_tests(lesser, greater); + } - test_msg.signature[46] = 46; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[1], greater.signature[1]); + comparison_tests(lesser, greater); + } - test_msg.signature[47] = 47; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[2], greater.signature[2]); + comparison_tests(lesser, greater); + } - test_msg.signature[48] = 48; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[3], greater.signature[3]); + comparison_tests(lesser, greater); + } - test_msg.signature[49] = 49; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[4], greater.signature[4]); + comparison_tests(lesser, greater); + } - test_msg.signature[50] = 50; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[5], greater.signature[5]); + comparison_tests(lesser, greater); + } - test_msg.signature[51] = 51; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[6], greater.signature[6]); + comparison_tests(lesser, greater); + } - test_msg.signature[52] = 52; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[7], greater.signature[7]); + comparison_tests(lesser, greater); + } - test_msg.signature[53] = 53; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[8], greater.signature[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[9], greater.signature[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[10], greater.signature[10]); + comparison_tests(lesser, greater); + } - test_msg.signature[54] = 54; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[11], greater.signature[11]); + comparison_tests(lesser, greater); + } - test_msg.signature[55] = 55; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[12], greater.signature[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[56] = 56; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[13], greater.signature[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[14], greater.signature[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[57] = 57; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[15], greater.signature[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[16], greater.signature[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[17], greater.signature[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[18], greater.signature[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[19], greater.signature[19]); + comparison_tests(lesser, greater); + } - test_msg.signature[58] = 58; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[20], greater.signature[20]); + comparison_tests(lesser, greater); + } - test_msg.signature[59] = 59; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[21], greater.signature[21]); + comparison_tests(lesser, greater); + } - test_msg.signature[60] = 60; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[22], greater.signature[22]); + comparison_tests(lesser, greater); + } - test_msg.signature[61] = 61; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[23], greater.signature[23]); + comparison_tests(lesser, greater); + } - test_msg.signature[62] = 62; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[24], greater.signature[24]); + comparison_tests(lesser, greater); + } - test_msg.signature[63] = 63; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[25], greater.signature[25]); + comparison_tests(lesser, greater); + } - test_msg.signature[64] = 64; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[26], greater.signature[26]); + comparison_tests(lesser, greater); + } - test_msg.signature[65] = 65; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[27], greater.signature[27]); + comparison_tests(lesser, greater); + } - test_msg.signature[66] = 66; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[28], greater.signature[28]); + comparison_tests(lesser, greater); + } - test_msg.signature[67] = 67; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[29], greater.signature[29]); + comparison_tests(lesser, greater); + } - test_msg.signature[68] = 68; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[30], greater.signature[30]); + comparison_tests(lesser, greater); + } - test_msg.signature[69] = 69; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[31], greater.signature[31]); + comparison_tests(lesser, greater); + } - test_msg.signature[70] = 70; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[32], greater.signature[32]); + comparison_tests(lesser, greater); + } - test_msg.signature[71] = 71; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[33], greater.signature[33]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[0] = 10; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[34], greater.signature[34]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[1] = 21; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[35], greater.signature[35]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[2] = 23; - test_msg.stream_counter = 1; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[36], greater.signature[36]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[37], greater.signature[37]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[38], greater.signature[38]); + comparison_tests(lesser, greater); + } - while (dummy_rd_ < dummy_wr_) { - process(); + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[39], greater.signature[39]); + comparison_tests(lesser, greater); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.certificate_id[0], 1) - << "incorrect value for last_msg_.certificate_id[0], expected 1, is " - << last_msg_.certificate_id[0]; - EXPECT_EQ(last_msg_.certificate_id[1], 2) - << "incorrect value for last_msg_.certificate_id[1], expected 2, is " - << last_msg_.certificate_id[1]; - EXPECT_EQ(last_msg_.certificate_id[2], 3) - << "incorrect value for last_msg_.certificate_id[2], expected 3, is " - << last_msg_.certificate_id[2]; - EXPECT_EQ(last_msg_.certificate_id[3], 4) - << "incorrect value for last_msg_.certificate_id[3], expected 4, is " - << last_msg_.certificate_id[3]; - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_signature_bytes, 72) - << "incorrect value for last_msg_.n_signature_bytes, expected 72, is " - << last_msg_.n_signature_bytes; - EXPECT_EQ(last_msg_.n_signed_messages, 3) - << "incorrect value for last_msg_.n_signed_messages, expected 3, is " - << last_msg_.n_signed_messages; - EXPECT_EQ(last_msg_.on_demand_counter, 2) - << "incorrect value for last_msg_.on_demand_counter, expected 2, is " - << last_msg_.on_demand_counter; - EXPECT_EQ(last_msg_.signature[0], 0) - << "incorrect value for last_msg_.signature[0], expected 0, is " - << last_msg_.signature[0]; - EXPECT_EQ(last_msg_.signature[1], 1) - << "incorrect value for last_msg_.signature[1], expected 1, is " - << last_msg_.signature[1]; - EXPECT_EQ(last_msg_.signature[2], 2) - << "incorrect value for last_msg_.signature[2], expected 2, is " - << last_msg_.signature[2]; - EXPECT_EQ(last_msg_.signature[3], 3) - << "incorrect value for last_msg_.signature[3], expected 3, is " - << last_msg_.signature[3]; - EXPECT_EQ(last_msg_.signature[4], 4) - << "incorrect value for last_msg_.signature[4], expected 4, is " - << last_msg_.signature[4]; - EXPECT_EQ(last_msg_.signature[5], 5) - << "incorrect value for last_msg_.signature[5], expected 5, is " - << last_msg_.signature[5]; - EXPECT_EQ(last_msg_.signature[6], 6) - << "incorrect value for last_msg_.signature[6], expected 6, is " - << last_msg_.signature[6]; - EXPECT_EQ(last_msg_.signature[7], 7) - << "incorrect value for last_msg_.signature[7], expected 7, is " - << last_msg_.signature[7]; - EXPECT_EQ(last_msg_.signature[8], 8) - << "incorrect value for last_msg_.signature[8], expected 8, is " - << last_msg_.signature[8]; - EXPECT_EQ(last_msg_.signature[9], 9) - << "incorrect value for last_msg_.signature[9], expected 9, is " - << last_msg_.signature[9]; - EXPECT_EQ(last_msg_.signature[10], 10) - << "incorrect value for last_msg_.signature[10], expected 10, is " - << last_msg_.signature[10]; - EXPECT_EQ(last_msg_.signature[11], 11) - << "incorrect value for last_msg_.signature[11], expected 11, is " - << last_msg_.signature[11]; - EXPECT_EQ(last_msg_.signature[12], 12) - << "incorrect value for last_msg_.signature[12], expected 12, is " - << last_msg_.signature[12]; - EXPECT_EQ(last_msg_.signature[13], 13) - << "incorrect value for last_msg_.signature[13], expected 13, is " - << last_msg_.signature[13]; - EXPECT_EQ(last_msg_.signature[14], 14) - << "incorrect value for last_msg_.signature[14], expected 14, is " - << last_msg_.signature[14]; - EXPECT_EQ(last_msg_.signature[15], 15) - << "incorrect value for last_msg_.signature[15], expected 15, is " - << last_msg_.signature[15]; - EXPECT_EQ(last_msg_.signature[16], 16) - << "incorrect value for last_msg_.signature[16], expected 16, is " - << last_msg_.signature[16]; - EXPECT_EQ(last_msg_.signature[17], 17) - << "incorrect value for last_msg_.signature[17], expected 17, is " - << last_msg_.signature[17]; - EXPECT_EQ(last_msg_.signature[18], 18) - << "incorrect value for last_msg_.signature[18], expected 18, is " - << last_msg_.signature[18]; - EXPECT_EQ(last_msg_.signature[19], 19) - << "incorrect value for last_msg_.signature[19], expected 19, is " - << last_msg_.signature[19]; - EXPECT_EQ(last_msg_.signature[20], 20) - << "incorrect value for last_msg_.signature[20], expected 20, is " - << last_msg_.signature[20]; - EXPECT_EQ(last_msg_.signature[21], 21) - << "incorrect value for last_msg_.signature[21], expected 21, is " - << last_msg_.signature[21]; - EXPECT_EQ(last_msg_.signature[22], 22) - << "incorrect value for last_msg_.signature[22], expected 22, is " - << last_msg_.signature[22]; - EXPECT_EQ(last_msg_.signature[23], 23) - << "incorrect value for last_msg_.signature[23], expected 23, is " - << last_msg_.signature[23]; - EXPECT_EQ(last_msg_.signature[24], 24) - << "incorrect value for last_msg_.signature[24], expected 24, is " - << last_msg_.signature[24]; - EXPECT_EQ(last_msg_.signature[25], 25) - << "incorrect value for last_msg_.signature[25], expected 25, is " - << last_msg_.signature[25]; - EXPECT_EQ(last_msg_.signature[26], 26) - << "incorrect value for last_msg_.signature[26], expected 26, is " - << last_msg_.signature[26]; - EXPECT_EQ(last_msg_.signature[27], 27) - << "incorrect value for last_msg_.signature[27], expected 27, is " - << last_msg_.signature[27]; - EXPECT_EQ(last_msg_.signature[28], 28) - << "incorrect value for last_msg_.signature[28], expected 28, is " - << last_msg_.signature[28]; - EXPECT_EQ(last_msg_.signature[29], 29) - << "incorrect value for last_msg_.signature[29], expected 29, is " - << last_msg_.signature[29]; - EXPECT_EQ(last_msg_.signature[30], 30) - << "incorrect value for last_msg_.signature[30], expected 30, is " - << last_msg_.signature[30]; - EXPECT_EQ(last_msg_.signature[31], 31) - << "incorrect value for last_msg_.signature[31], expected 31, is " - << last_msg_.signature[31]; - EXPECT_EQ(last_msg_.signature[32], 32) - << "incorrect value for last_msg_.signature[32], expected 32, is " - << last_msg_.signature[32]; - EXPECT_EQ(last_msg_.signature[33], 33) - << "incorrect value for last_msg_.signature[33], expected 33, is " - << last_msg_.signature[33]; - EXPECT_EQ(last_msg_.signature[34], 34) - << "incorrect value for last_msg_.signature[34], expected 34, is " - << last_msg_.signature[34]; - EXPECT_EQ(last_msg_.signature[35], 35) - << "incorrect value for last_msg_.signature[35], expected 35, is " - << last_msg_.signature[35]; - EXPECT_EQ(last_msg_.signature[36], 36) - << "incorrect value for last_msg_.signature[36], expected 36, is " - << last_msg_.signature[36]; - EXPECT_EQ(last_msg_.signature[37], 37) - << "incorrect value for last_msg_.signature[37], expected 37, is " - << last_msg_.signature[37]; - EXPECT_EQ(last_msg_.signature[38], 38) - << "incorrect value for last_msg_.signature[38], expected 38, is " - << last_msg_.signature[38]; - EXPECT_EQ(last_msg_.signature[39], 39) - << "incorrect value for last_msg_.signature[39], expected 39, is " - << last_msg_.signature[39]; - EXPECT_EQ(last_msg_.signature[40], 40) - << "incorrect value for last_msg_.signature[40], expected 40, is " - << last_msg_.signature[40]; - EXPECT_EQ(last_msg_.signature[41], 41) - << "incorrect value for last_msg_.signature[41], expected 41, is " - << last_msg_.signature[41]; - EXPECT_EQ(last_msg_.signature[42], 42) - << "incorrect value for last_msg_.signature[42], expected 42, is " - << last_msg_.signature[42]; - EXPECT_EQ(last_msg_.signature[43], 43) - << "incorrect value for last_msg_.signature[43], expected 43, is " - << last_msg_.signature[43]; - EXPECT_EQ(last_msg_.signature[44], 44) - << "incorrect value for last_msg_.signature[44], expected 44, is " - << last_msg_.signature[44]; - EXPECT_EQ(last_msg_.signature[45], 45) - << "incorrect value for last_msg_.signature[45], expected 45, is " - << last_msg_.signature[45]; - EXPECT_EQ(last_msg_.signature[46], 46) - << "incorrect value for last_msg_.signature[46], expected 46, is " - << last_msg_.signature[46]; - EXPECT_EQ(last_msg_.signature[47], 47) - << "incorrect value for last_msg_.signature[47], expected 47, is " - << last_msg_.signature[47]; - EXPECT_EQ(last_msg_.signature[48], 48) - << "incorrect value for last_msg_.signature[48], expected 48, is " - << last_msg_.signature[48]; - EXPECT_EQ(last_msg_.signature[49], 49) - << "incorrect value for last_msg_.signature[49], expected 49, is " - << last_msg_.signature[49]; - EXPECT_EQ(last_msg_.signature[50], 50) - << "incorrect value for last_msg_.signature[50], expected 50, is " - << last_msg_.signature[50]; - EXPECT_EQ(last_msg_.signature[51], 51) - << "incorrect value for last_msg_.signature[51], expected 51, is " - << last_msg_.signature[51]; - EXPECT_EQ(last_msg_.signature[52], 52) - << "incorrect value for last_msg_.signature[52], expected 52, is " - << last_msg_.signature[52]; - EXPECT_EQ(last_msg_.signature[53], 53) - << "incorrect value for last_msg_.signature[53], expected 53, is " - << last_msg_.signature[53]; - EXPECT_EQ(last_msg_.signature[54], 54) - << "incorrect value for last_msg_.signature[54], expected 54, is " - << last_msg_.signature[54]; - EXPECT_EQ(last_msg_.signature[55], 55) - << "incorrect value for last_msg_.signature[55], expected 55, is " - << last_msg_.signature[55]; - EXPECT_EQ(last_msg_.signature[56], 56) - << "incorrect value for last_msg_.signature[56], expected 56, is " - << last_msg_.signature[56]; - EXPECT_EQ(last_msg_.signature[57], 57) - << "incorrect value for last_msg_.signature[57], expected 57, is " - << last_msg_.signature[57]; - EXPECT_EQ(last_msg_.signature[58], 58) - << "incorrect value for last_msg_.signature[58], expected 58, is " - << last_msg_.signature[58]; - EXPECT_EQ(last_msg_.signature[59], 59) - << "incorrect value for last_msg_.signature[59], expected 59, is " - << last_msg_.signature[59]; - EXPECT_EQ(last_msg_.signature[60], 60) - << "incorrect value for last_msg_.signature[60], expected 60, is " - << last_msg_.signature[60]; - EXPECT_EQ(last_msg_.signature[61], 61) - << "incorrect value for last_msg_.signature[61], expected 61, is " - << last_msg_.signature[61]; - EXPECT_EQ(last_msg_.signature[62], 62) - << "incorrect value for last_msg_.signature[62], expected 62, is " - << last_msg_.signature[62]; - EXPECT_EQ(last_msg_.signature[63], 63) - << "incorrect value for last_msg_.signature[63], expected 63, is " - << last_msg_.signature[63]; - EXPECT_EQ(last_msg_.signature[64], 64) - << "incorrect value for last_msg_.signature[64], expected 64, is " - << last_msg_.signature[64]; - EXPECT_EQ(last_msg_.signature[65], 65) - << "incorrect value for last_msg_.signature[65], expected 65, is " - << last_msg_.signature[65]; - EXPECT_EQ(last_msg_.signature[66], 66) - << "incorrect value for last_msg_.signature[66], expected 66, is " - << last_msg_.signature[66]; - EXPECT_EQ(last_msg_.signature[67], 67) - << "incorrect value for last_msg_.signature[67], expected 67, is " - << last_msg_.signature[67]; - EXPECT_EQ(last_msg_.signature[68], 68) - << "incorrect value for last_msg_.signature[68], expected 68, is " - << last_msg_.signature[68]; - EXPECT_EQ(last_msg_.signature[69], 69) - << "incorrect value for last_msg_.signature[69], expected 69, is " - << last_msg_.signature[69]; - EXPECT_EQ(last_msg_.signature[70], 70) - << "incorrect value for last_msg_.signature[70], expected 70, is " - << last_msg_.signature[70]; - EXPECT_EQ(last_msg_.signature[71], 71) - << "incorrect value for last_msg_.signature[71], expected 71, is " - << last_msg_.signature[71]; - EXPECT_EQ(last_msg_.signed_messages[0], 10) - << "incorrect value for last_msg_.signed_messages[0], expected 10, is " - << last_msg_.signed_messages[0]; - EXPECT_EQ(last_msg_.signed_messages[1], 21) - << "incorrect value for last_msg_.signed_messages[1], expected 21, is " - << last_msg_.signed_messages[1]; - EXPECT_EQ(last_msg_.signed_messages[2], 23) - << "incorrect value for last_msg_.signed_messages[2], expected 23, is " - << last_msg_.signed_messages[2]; - EXPECT_EQ(last_msg_.stream_counter, 1) - << "incorrect value for last_msg_.stream_counter, expected 1, is " - << last_msg_.stream_counter; + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[40], greater.signature[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[41], greater.signature[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[42], greater.signature[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[43], greater.signature[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[44], greater.signature[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[45], greater.signature[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[46], greater.signature[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[47], greater.signature[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[48], greater.signature[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[49], greater.signature[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[50], greater.signature[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[51], greater.signature[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[52], greater.signature[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[53], greater.signature[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[54], greater.signature[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[55], greater.signature[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[56], greater.signature[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[57], greater.signature[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[58], greater.signature[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[59], greater.signature[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[60], greater.signature[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[61], greater.signature[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[62], greater.signature[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[63], greater.signature[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[64], greater.signature[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[65], greater.signature[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[66], greater.signature[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[67], greater.signature[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[68], greater.signature[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[69], greater.signature[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[70], greater.signature[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[71], greater.signature[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[0], greater.signed_messages[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[1], greater.signed_messages[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[2], greater.signed_messages[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ecdsa_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ecdsa_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.stream_counter, greater.stream_counter); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEcdsaSignatureDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ECDSA_SIGNATURE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ecdsa_signature_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ecdsa_signature_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ecdsa_signature_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ecdsa_signature_dep_b, info.test_msg); } + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[83]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 83); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 83), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ecdsa_signature_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 83); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEcdsaSignatureDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEcdsaSignatureDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEcdsaSignatureDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEd25519CertificateDep.cc b/c/test/cpp/auto_check_sbp_signing_MsgEd25519CertificateDep.cc index 66c25d5718..270454d48b 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEd25519CertificateDep.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEd25519CertificateDep.cc @@ -16,66 +16,580 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEd25519CertificateDep0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEd25519CertificateDep0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEd25519CertificateDep0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgEd25519CertificateDep0() { + assign(test_msg_.certificate_bytes[0], 0); + + assign(test_msg_.certificate_bytes[1], 3); + + assign(test_msg_.certificate_bytes[2], 6); + + assign(test_msg_.certificate_bytes[3], 9); + + assign(test_msg_.certificate_bytes[4], 12); + + assign(test_msg_.certificate_bytes[5], 15); + + assign(test_msg_.certificate_bytes[6], 18); + + assign(test_msg_.certificate_bytes[7], 21); + + assign(test_msg_.certificate_bytes[8], 24); + + assign(test_msg_.certificate_bytes[9], 27); + + assign(test_msg_.certificate_bytes[10], 30); + + assign(test_msg_.certificate_bytes[11], 33); + + assign(test_msg_.certificate_bytes[12], 36); + + assign(test_msg_.certificate_bytes[13], 39); + + assign(test_msg_.certificate_bytes[14], 42); + + assign(test_msg_.certificate_bytes[15], 45); + + assign(test_msg_.certificate_bytes[16], 48); + + assign(test_msg_.certificate_bytes[17], 51); + + assign(test_msg_.certificate_bytes[18], 54); + + assign(test_msg_.certificate_bytes[19], 57); + + assign(test_msg_.certificate_bytes[20], 60); + + assign(test_msg_.certificate_bytes[21], 63); + + assign(test_msg_.certificate_bytes[22], 66); + + assign(test_msg_.certificate_bytes[23], 69); + + assign(test_msg_.certificate_bytes[24], 72); + + assign(test_msg_.certificate_bytes[25], 75); + + assign(test_msg_.certificate_bytes[26], 78); + + assign(test_msg_.certificate_bytes[27], 81); + + assign(test_msg_.certificate_bytes[28], 84); + + assign(test_msg_.certificate_bytes[29], 87); + + assign(test_msg_.certificate_bytes[30], 90); + + assign(test_msg_.certificate_bytes[31], 93); + + assign(test_msg_.certificate_bytes[32], 96); + + assign(test_msg_.certificate_bytes[33], 99); + + assign(test_msg_.certificate_bytes[34], 102); + + assign(test_msg_.certificate_bytes[35], 105); + + assign(test_msg_.certificate_bytes[36], 108); + + assign(test_msg_.certificate_bytes[37], 111); + + assign(test_msg_.certificate_bytes[38], 114); + + assign(test_msg_.certificate_bytes[39], 117); + + assign(test_msg_.certificate_bytes[40], 120); + + assign(test_msg_.certificate_bytes[41], 123); + + assign(test_msg_.certificate_bytes[42], 126); + + assign(test_msg_.certificate_bytes[43], 129); + + assign(test_msg_.certificate_bytes[44], 132); + + assign(test_msg_.certificate_bytes[45], 135); + + assign(test_msg_.certificate_bytes[46], 138); + + assign(test_msg_.certificate_bytes[47], 141); + + assign(test_msg_.certificate_bytes[48], 144); + + assign(test_msg_.certificate_bytes[49], 147); + + assign(test_msg_.certificate_bytes[50], 150); + + assign(test_msg_.certificate_bytes[51], 153); + + assign(test_msg_.certificate_bytes[52], 156); + + assign(test_msg_.certificate_bytes[53], 159); + + assign(test_msg_.certificate_bytes[54], 162); + + assign(test_msg_.certificate_bytes[55], 165); + + assign(test_msg_.certificate_bytes[56], 168); + + assign(test_msg_.certificate_bytes[57], 171); + + assign(test_msg_.certificate_bytes[58], 174); + + assign(test_msg_.certificate_bytes[59], 177); + + assign(test_msg_.certificate_bytes[60], 180); + + assign(test_msg_.certificate_bytes[61], 183); + + assign(test_msg_.certificate_bytes[62], 186); + + assign(test_msg_.certificate_bytes[63], 189); + + assign(test_msg_.certificate_bytes[64], 192); + + assign(test_msg_.certificate_bytes[65], 195); + + assign(test_msg_.certificate_bytes[66], 198); + + assign(test_msg_.certificate_bytes[67], 201); + + assign(test_msg_.certificate_bytes[68], 204); + + assign(test_msg_.certificate_bytes[69], 207); + + assign(test_msg_.certificate_bytes[70], 210); + + assign(test_msg_.certificate_bytes[71], 213); + + assign(test_msg_.certificate_bytes[72], 216); + + assign(test_msg_.certificate_bytes[73], 219); + + assign(test_msg_.certificate_bytes[74], 222); + + assign(test_msg_.certificate_bytes[75], 225); + + assign(test_msg_.certificate_bytes[76], 228); + + assign(test_msg_.certificate_bytes[77], 231); + + assign(test_msg_.certificate_bytes[78], 234); + + assign(test_msg_.certificate_bytes[79], 237); + + assign(test_msg_.certificate_bytes[80], 240); + + assign(test_msg_.certificate_bytes[81], 243); + + assign(test_msg_.certificate_bytes[82], 246); + + assign(test_msg_.certificate_bytes[83], 249); + + assign(test_msg_.certificate_bytes[84], 252); + + assign(test_msg_.fingerprint[0], 100); + + assign(test_msg_.fingerprint[1], 101); + + assign(test_msg_.fingerprint[2], 102); + + assign(test_msg_.fingerprint[3], 103); + + assign(test_msg_.fingerprint[4], 104); + + assign(test_msg_.fingerprint[5], 105); + + assign(test_msg_.fingerprint[6], 106); + + assign(test_msg_.fingerprint[7], 107); + + assign(test_msg_.fingerprint[8], 108); + + assign(test_msg_.fingerprint[9], 109); + + assign(test_msg_.fingerprint[10], 110); + + assign(test_msg_.fingerprint[11], 111); + + assign(test_msg_.fingerprint[12], 112); + + assign(test_msg_.fingerprint[13], 113); + + assign(test_msg_.fingerprint[14], 114); + + assign(test_msg_.fingerprint[15], 115); + + assign(test_msg_.fingerprint[16], 116); + + assign(test_msg_.fingerprint[17], 117); + + assign(test_msg_.fingerprint[18], 118); + + assign(test_msg_.fingerprint[19], 119); + assign(test_msg_.n_certificate_bytes, 85); + assign(test_msg_.n_msg, 16); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ed25519_certificate_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_certificate_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ed25519_certificate_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEd25519CertificateDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_certificate_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEd25519CertificateDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ed25519_certificate_dep, + sizeof(msg->ed25519_certificate_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ed25519_certificate_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ed25519_certificate_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEd25519CertificateDep); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x94DA; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 106; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ed25519_certificate_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ed25519_certificate_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ed25519_certificate_dep_t &lesser, + const sbp_msg_ed25519_certificate_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ed25519_certificate_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ed25519_certificate_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519CertificateDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519CertificateDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEd25519CertificateDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEd25519CertificateDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } -TEST_F(Test_auto_check_sbp_signing_MsgEd25519CertificateDep0, Test) { - uint8_t encoded_frame[] = { + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ed25519_certificate_dep_t test_msg_{}; + uint8_t encoded_frame_[106 + 8] = { 85, 2, 12, 66, 0, 106, 16, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, @@ -85,603 +599,1274 @@ TEST_F(Test_auto_check_sbp_signing_MsgEd25519CertificateDep0, Test) { 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246, 249, 252, 218, 148, }; + uint8_t encoded_payload_[106] = { + 16, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 0, 3, 6, 9, 12, 15, 18, + 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, + 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, + 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, + 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, + 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, + 231, 234, 237, 240, 243, 246, 249, 252, + }; +}; + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEd25519CertificateDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[106]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 106); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 106), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEd25519CertificateDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 106); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 106), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[106]; + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 106), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[106]; + + for (uint8_t i = 0; i < 106; i++) { + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_certificate_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 106); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgEd25519CertificateDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 106); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_certificate_dep_t msg{}; + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_certificate_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ed25519_certificate_dep_t t{}; + return sbp_msg_ed25519_certificate_dep_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ed25519_certificate_dep_t t{}; + t.n_certificate_bytes = 1; + return sbp_msg_ed25519_certificate_dep_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; - sbp_msg_ed25519_certificate_dep_t test_msg{}; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.certificate_bytes[0] = 0; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.certificate_bytes[1] = 3; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.certificate_bytes[2] = 6; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.certificate_bytes[3] = 9; + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[4] = 12; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.certificate_bytes[5] = 15; + CHandler handler{&state}; - test_msg.certificate_bytes[6] = 18; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.certificate_bytes[7] = 21; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.certificate_bytes[8] = 24; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[9] = 27; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.certificate_bytes[10] = 30; + EXPECT_EQ(sbp_msg_ed25519_certificate_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.certificate_bytes[11] = 33; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgEd25519CertificateDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.certificate_bytes[12] = 36; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.certificate_bytes[13] = 39; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.certificate_bytes[14] = 42; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.certificate_bytes[15] = 45; + EXPECT_NE( + sbp_message_send(&state, SbpMsgEd25519CertificateDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.certificate_bytes[16] = 48; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgEd25519CertificateDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.certificate_bytes[17] = 51; +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, Comparison) { + auto info = get_test_msg_info(); - test_msg.certificate_bytes[18] = 54; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[0], + greater.certificate_bytes[0]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[19] = 57; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[1], + greater.certificate_bytes[1]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[20] = 60; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[2], + greater.certificate_bytes[2]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[21] = 63; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[3], + greater.certificate_bytes[3]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[22] = 66; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[4], + greater.certificate_bytes[4]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[23] = 69; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[5], + greater.certificate_bytes[5]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[24] = 72; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[6], + greater.certificate_bytes[6]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[25] = 75; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[7], + greater.certificate_bytes[7]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[26] = 78; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[8], + greater.certificate_bytes[8]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[27] = 81; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[9], + greater.certificate_bytes[9]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[28] = 84; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[10], + greater.certificate_bytes[10]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[29] = 87; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[11], + greater.certificate_bytes[11]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[30] = 90; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[12], + greater.certificate_bytes[12]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[31] = 93; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[13], + greater.certificate_bytes[13]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[32] = 96; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[14], + greater.certificate_bytes[14]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[33] = 99; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[15], + greater.certificate_bytes[15]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[34] = 102; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[16], + greater.certificate_bytes[16]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[35] = 105; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[17], + greater.certificate_bytes[17]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[36] = 108; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[18], + greater.certificate_bytes[18]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[37] = 111; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[19], + greater.certificate_bytes[19]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[38] = 114; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[20], + greater.certificate_bytes[20]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[39] = 117; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[21], + greater.certificate_bytes[21]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[40] = 120; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[22], + greater.certificate_bytes[22]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[41] = 123; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[23], + greater.certificate_bytes[23]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[42] = 126; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[24], + greater.certificate_bytes[24]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[43] = 129; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[25], + greater.certificate_bytes[25]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[44] = 132; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[26], + greater.certificate_bytes[26]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[45] = 135; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[27], + greater.certificate_bytes[27]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[46] = 138; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[28], + greater.certificate_bytes[28]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[47] = 141; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[29], + greater.certificate_bytes[29]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[48] = 144; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[30], + greater.certificate_bytes[30]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[49] = 147; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[31], + greater.certificate_bytes[31]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[50] = 150; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[32], + greater.certificate_bytes[32]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[51] = 153; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[33], + greater.certificate_bytes[33]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[52] = 156; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[34], + greater.certificate_bytes[34]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[53] = 159; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[35], + greater.certificate_bytes[35]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[54] = 162; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[36], + greater.certificate_bytes[36]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[55] = 165; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[37], + greater.certificate_bytes[37]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[56] = 168; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[38], + greater.certificate_bytes[38]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[57] = 171; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[39], + greater.certificate_bytes[39]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[58] = 174; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[40], + greater.certificate_bytes[40]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[59] = 177; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[41], + greater.certificate_bytes[41]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[60] = 180; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[42], + greater.certificate_bytes[42]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[61] = 183; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[43], + greater.certificate_bytes[43]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[62] = 186; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[44], + greater.certificate_bytes[44]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[63] = 189; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[45], + greater.certificate_bytes[45]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[64] = 192; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[46], + greater.certificate_bytes[46]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[65] = 195; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[47], + greater.certificate_bytes[47]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[66] = 198; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[48], + greater.certificate_bytes[48]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[67] = 201; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[49], + greater.certificate_bytes[49]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[68] = 204; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[50], + greater.certificate_bytes[50]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[69] = 207; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[51], + greater.certificate_bytes[51]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[70] = 210; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[52], + greater.certificate_bytes[52]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[71] = 213; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[53], + greater.certificate_bytes[53]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[72] = 216; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[54], + greater.certificate_bytes[54]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[73] = 219; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[55], + greater.certificate_bytes[55]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[74] = 222; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[56], + greater.certificate_bytes[56]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[75] = 225; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[57], + greater.certificate_bytes[57]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[76] = 228; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[58], + greater.certificate_bytes[58]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[77] = 231; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[59], + greater.certificate_bytes[59]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[78] = 234; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[60], + greater.certificate_bytes[60]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[79] = 237; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[61], + greater.certificate_bytes[61]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[80] = 240; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[62], + greater.certificate_bytes[62]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[81] = 243; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[63], + greater.certificate_bytes[63]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[82] = 246; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[64], + greater.certificate_bytes[64]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[83] = 249; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[65], + greater.certificate_bytes[65]); + comparison_tests(lesser, greater); + } - test_msg.certificate_bytes[84] = 252; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[66], + greater.certificate_bytes[66]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[0] = 100; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[67], + greater.certificate_bytes[67]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[1] = 101; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[68], + greater.certificate_bytes[68]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[2] = 102; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[69], + greater.certificate_bytes[69]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[3] = 103; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[70], + greater.certificate_bytes[70]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[4] = 104; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[71], + greater.certificate_bytes[71]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[5] = 105; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[72], + greater.certificate_bytes[72]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[6] = 106; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[73], + greater.certificate_bytes[73]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[7] = 107; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[74], + greater.certificate_bytes[74]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[8] = 108; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[75], + greater.certificate_bytes[75]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[9] = 109; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[76], + greater.certificate_bytes[76]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[10] = 110; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[77], + greater.certificate_bytes[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[78], + greater.certificate_bytes[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[79], + greater.certificate_bytes[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[80], + greater.certificate_bytes[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[81], + greater.certificate_bytes[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[82], + greater.certificate_bytes[82]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[11] = 111; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[83], + greater.certificate_bytes[83]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[12] = 112; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.certificate_bytes[84], + greater.certificate_bytes[84]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[13] = 113; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[0], greater.fingerprint[0]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[14] = 114; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[1], greater.fingerprint[1]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[15] = 115; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[2], greater.fingerprint[2]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[16] = 116; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[3], greater.fingerprint[3]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[17] = 117; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[4], greater.fingerprint[4]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[18] = 118; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[5], greater.fingerprint[5]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[19] = 119; - test_msg.n_certificate_bytes = 85; - test_msg.n_msg = 16; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[6], greater.fingerprint[6]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[7], greater.fingerprint[7]); + comparison_tests(lesser, greater); + } - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[8], greater.fingerprint[8]); + comparison_tests(lesser, greater); + } - while (dummy_rd_ < dummy_wr_) { - process(); + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[9], greater.fingerprint[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[10], greater.fingerprint[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[11], greater.fingerprint[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[12], greater.fingerprint[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[13], greater.fingerprint[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[14], greater.fingerprint[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[15], greater.fingerprint[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[16], greater.fingerprint[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[17], greater.fingerprint[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[18], greater.fingerprint[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[19], greater.fingerprint[19]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_certificate_bytes, + greater.n_certificate_bytes); + comparison_tests(lesser, greater); } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.certificate_bytes[0], 0) - << "incorrect value for last_msg_.certificate_bytes[0], expected 0, is " - << last_msg_.certificate_bytes[0]; - EXPECT_EQ(last_msg_.certificate_bytes[1], 3) - << "incorrect value for last_msg_.certificate_bytes[1], expected 3, is " - << last_msg_.certificate_bytes[1]; - EXPECT_EQ(last_msg_.certificate_bytes[2], 6) - << "incorrect value for last_msg_.certificate_bytes[2], expected 6, is " - << last_msg_.certificate_bytes[2]; - EXPECT_EQ(last_msg_.certificate_bytes[3], 9) - << "incorrect value for last_msg_.certificate_bytes[3], expected 9, is " - << last_msg_.certificate_bytes[3]; - EXPECT_EQ(last_msg_.certificate_bytes[4], 12) - << "incorrect value for last_msg_.certificate_bytes[4], expected 12, is " - << last_msg_.certificate_bytes[4]; - EXPECT_EQ(last_msg_.certificate_bytes[5], 15) - << "incorrect value for last_msg_.certificate_bytes[5], expected 15, is " - << last_msg_.certificate_bytes[5]; - EXPECT_EQ(last_msg_.certificate_bytes[6], 18) - << "incorrect value for last_msg_.certificate_bytes[6], expected 18, is " - << last_msg_.certificate_bytes[6]; - EXPECT_EQ(last_msg_.certificate_bytes[7], 21) - << "incorrect value for last_msg_.certificate_bytes[7], expected 21, is " - << last_msg_.certificate_bytes[7]; - EXPECT_EQ(last_msg_.certificate_bytes[8], 24) - << "incorrect value for last_msg_.certificate_bytes[8], expected 24, is " - << last_msg_.certificate_bytes[8]; - EXPECT_EQ(last_msg_.certificate_bytes[9], 27) - << "incorrect value for last_msg_.certificate_bytes[9], expected 27, is " - << last_msg_.certificate_bytes[9]; - EXPECT_EQ(last_msg_.certificate_bytes[10], 30) - << "incorrect value for last_msg_.certificate_bytes[10], expected 30, is " - << last_msg_.certificate_bytes[10]; - EXPECT_EQ(last_msg_.certificate_bytes[11], 33) - << "incorrect value for last_msg_.certificate_bytes[11], expected 33, is " - << last_msg_.certificate_bytes[11]; - EXPECT_EQ(last_msg_.certificate_bytes[12], 36) - << "incorrect value for last_msg_.certificate_bytes[12], expected 36, is " - << last_msg_.certificate_bytes[12]; - EXPECT_EQ(last_msg_.certificate_bytes[13], 39) - << "incorrect value for last_msg_.certificate_bytes[13], expected 39, is " - << last_msg_.certificate_bytes[13]; - EXPECT_EQ(last_msg_.certificate_bytes[14], 42) - << "incorrect value for last_msg_.certificate_bytes[14], expected 42, is " - << last_msg_.certificate_bytes[14]; - EXPECT_EQ(last_msg_.certificate_bytes[15], 45) - << "incorrect value for last_msg_.certificate_bytes[15], expected 45, is " - << last_msg_.certificate_bytes[15]; - EXPECT_EQ(last_msg_.certificate_bytes[16], 48) - << "incorrect value for last_msg_.certificate_bytes[16], expected 48, is " - << last_msg_.certificate_bytes[16]; - EXPECT_EQ(last_msg_.certificate_bytes[17], 51) - << "incorrect value for last_msg_.certificate_bytes[17], expected 51, is " - << last_msg_.certificate_bytes[17]; - EXPECT_EQ(last_msg_.certificate_bytes[18], 54) - << "incorrect value for last_msg_.certificate_bytes[18], expected 54, is " - << last_msg_.certificate_bytes[18]; - EXPECT_EQ(last_msg_.certificate_bytes[19], 57) - << "incorrect value for last_msg_.certificate_bytes[19], expected 57, is " - << last_msg_.certificate_bytes[19]; - EXPECT_EQ(last_msg_.certificate_bytes[20], 60) - << "incorrect value for last_msg_.certificate_bytes[20], expected 60, is " - << last_msg_.certificate_bytes[20]; - EXPECT_EQ(last_msg_.certificate_bytes[21], 63) - << "incorrect value for last_msg_.certificate_bytes[21], expected 63, is " - << last_msg_.certificate_bytes[21]; - EXPECT_EQ(last_msg_.certificate_bytes[22], 66) - << "incorrect value for last_msg_.certificate_bytes[22], expected 66, is " - << last_msg_.certificate_bytes[22]; - EXPECT_EQ(last_msg_.certificate_bytes[23], 69) - << "incorrect value for last_msg_.certificate_bytes[23], expected 69, is " - << last_msg_.certificate_bytes[23]; - EXPECT_EQ(last_msg_.certificate_bytes[24], 72) - << "incorrect value for last_msg_.certificate_bytes[24], expected 72, is " - << last_msg_.certificate_bytes[24]; - EXPECT_EQ(last_msg_.certificate_bytes[25], 75) - << "incorrect value for last_msg_.certificate_bytes[25], expected 75, is " - << last_msg_.certificate_bytes[25]; - EXPECT_EQ(last_msg_.certificate_bytes[26], 78) - << "incorrect value for last_msg_.certificate_bytes[26], expected 78, is " - << last_msg_.certificate_bytes[26]; - EXPECT_EQ(last_msg_.certificate_bytes[27], 81) - << "incorrect value for last_msg_.certificate_bytes[27], expected 81, is " - << last_msg_.certificate_bytes[27]; - EXPECT_EQ(last_msg_.certificate_bytes[28], 84) - << "incorrect value for last_msg_.certificate_bytes[28], expected 84, is " - << last_msg_.certificate_bytes[28]; - EXPECT_EQ(last_msg_.certificate_bytes[29], 87) - << "incorrect value for last_msg_.certificate_bytes[29], expected 87, is " - << last_msg_.certificate_bytes[29]; - EXPECT_EQ(last_msg_.certificate_bytes[30], 90) - << "incorrect value for last_msg_.certificate_bytes[30], expected 90, is " - << last_msg_.certificate_bytes[30]; - EXPECT_EQ(last_msg_.certificate_bytes[31], 93) - << "incorrect value for last_msg_.certificate_bytes[31], expected 93, is " - << last_msg_.certificate_bytes[31]; - EXPECT_EQ(last_msg_.certificate_bytes[32], 96) - << "incorrect value for last_msg_.certificate_bytes[32], expected 96, is " - << last_msg_.certificate_bytes[32]; - EXPECT_EQ(last_msg_.certificate_bytes[33], 99) - << "incorrect value for last_msg_.certificate_bytes[33], expected 99, is " - << last_msg_.certificate_bytes[33]; - EXPECT_EQ(last_msg_.certificate_bytes[34], 102) - << "incorrect value for last_msg_.certificate_bytes[34], expected 102, " - "is " - << last_msg_.certificate_bytes[34]; - EXPECT_EQ(last_msg_.certificate_bytes[35], 105) - << "incorrect value for last_msg_.certificate_bytes[35], expected 105, " - "is " - << last_msg_.certificate_bytes[35]; - EXPECT_EQ(last_msg_.certificate_bytes[36], 108) - << "incorrect value for last_msg_.certificate_bytes[36], expected 108, " - "is " - << last_msg_.certificate_bytes[36]; - EXPECT_EQ(last_msg_.certificate_bytes[37], 111) - << "incorrect value for last_msg_.certificate_bytes[37], expected 111, " - "is " - << last_msg_.certificate_bytes[37]; - EXPECT_EQ(last_msg_.certificate_bytes[38], 114) - << "incorrect value for last_msg_.certificate_bytes[38], expected 114, " - "is " - << last_msg_.certificate_bytes[38]; - EXPECT_EQ(last_msg_.certificate_bytes[39], 117) - << "incorrect value for last_msg_.certificate_bytes[39], expected 117, " - "is " - << last_msg_.certificate_bytes[39]; - EXPECT_EQ(last_msg_.certificate_bytes[40], 120) - << "incorrect value for last_msg_.certificate_bytes[40], expected 120, " - "is " - << last_msg_.certificate_bytes[40]; - EXPECT_EQ(last_msg_.certificate_bytes[41], 123) - << "incorrect value for last_msg_.certificate_bytes[41], expected 123, " - "is " - << last_msg_.certificate_bytes[41]; - EXPECT_EQ(last_msg_.certificate_bytes[42], 126) - << "incorrect value for last_msg_.certificate_bytes[42], expected 126, " - "is " - << last_msg_.certificate_bytes[42]; - EXPECT_EQ(last_msg_.certificate_bytes[43], 129) - << "incorrect value for last_msg_.certificate_bytes[43], expected 129, " - "is " - << last_msg_.certificate_bytes[43]; - EXPECT_EQ(last_msg_.certificate_bytes[44], 132) - << "incorrect value for last_msg_.certificate_bytes[44], expected 132, " - "is " - << last_msg_.certificate_bytes[44]; - EXPECT_EQ(last_msg_.certificate_bytes[45], 135) - << "incorrect value for last_msg_.certificate_bytes[45], expected 135, " - "is " - << last_msg_.certificate_bytes[45]; - EXPECT_EQ(last_msg_.certificate_bytes[46], 138) - << "incorrect value for last_msg_.certificate_bytes[46], expected 138, " - "is " - << last_msg_.certificate_bytes[46]; - EXPECT_EQ(last_msg_.certificate_bytes[47], 141) - << "incorrect value for last_msg_.certificate_bytes[47], expected 141, " - "is " - << last_msg_.certificate_bytes[47]; - EXPECT_EQ(last_msg_.certificate_bytes[48], 144) - << "incorrect value for last_msg_.certificate_bytes[48], expected 144, " - "is " - << last_msg_.certificate_bytes[48]; - EXPECT_EQ(last_msg_.certificate_bytes[49], 147) - << "incorrect value for last_msg_.certificate_bytes[49], expected 147, " - "is " - << last_msg_.certificate_bytes[49]; - EXPECT_EQ(last_msg_.certificate_bytes[50], 150) - << "incorrect value for last_msg_.certificate_bytes[50], expected 150, " - "is " - << last_msg_.certificate_bytes[50]; - EXPECT_EQ(last_msg_.certificate_bytes[51], 153) - << "incorrect value for last_msg_.certificate_bytes[51], expected 153, " - "is " - << last_msg_.certificate_bytes[51]; - EXPECT_EQ(last_msg_.certificate_bytes[52], 156) - << "incorrect value for last_msg_.certificate_bytes[52], expected 156, " - "is " - << last_msg_.certificate_bytes[52]; - EXPECT_EQ(last_msg_.certificate_bytes[53], 159) - << "incorrect value for last_msg_.certificate_bytes[53], expected 159, " - "is " - << last_msg_.certificate_bytes[53]; - EXPECT_EQ(last_msg_.certificate_bytes[54], 162) - << "incorrect value for last_msg_.certificate_bytes[54], expected 162, " - "is " - << last_msg_.certificate_bytes[54]; - EXPECT_EQ(last_msg_.certificate_bytes[55], 165) - << "incorrect value for last_msg_.certificate_bytes[55], expected 165, " - "is " - << last_msg_.certificate_bytes[55]; - EXPECT_EQ(last_msg_.certificate_bytes[56], 168) - << "incorrect value for last_msg_.certificate_bytes[56], expected 168, " - "is " - << last_msg_.certificate_bytes[56]; - EXPECT_EQ(last_msg_.certificate_bytes[57], 171) - << "incorrect value for last_msg_.certificate_bytes[57], expected 171, " - "is " - << last_msg_.certificate_bytes[57]; - EXPECT_EQ(last_msg_.certificate_bytes[58], 174) - << "incorrect value for last_msg_.certificate_bytes[58], expected 174, " - "is " - << last_msg_.certificate_bytes[58]; - EXPECT_EQ(last_msg_.certificate_bytes[59], 177) - << "incorrect value for last_msg_.certificate_bytes[59], expected 177, " - "is " - << last_msg_.certificate_bytes[59]; - EXPECT_EQ(last_msg_.certificate_bytes[60], 180) - << "incorrect value for last_msg_.certificate_bytes[60], expected 180, " - "is " - << last_msg_.certificate_bytes[60]; - EXPECT_EQ(last_msg_.certificate_bytes[61], 183) - << "incorrect value for last_msg_.certificate_bytes[61], expected 183, " - "is " - << last_msg_.certificate_bytes[61]; - EXPECT_EQ(last_msg_.certificate_bytes[62], 186) - << "incorrect value for last_msg_.certificate_bytes[62], expected 186, " - "is " - << last_msg_.certificate_bytes[62]; - EXPECT_EQ(last_msg_.certificate_bytes[63], 189) - << "incorrect value for last_msg_.certificate_bytes[63], expected 189, " - "is " - << last_msg_.certificate_bytes[63]; - EXPECT_EQ(last_msg_.certificate_bytes[64], 192) - << "incorrect value for last_msg_.certificate_bytes[64], expected 192, " - "is " - << last_msg_.certificate_bytes[64]; - EXPECT_EQ(last_msg_.certificate_bytes[65], 195) - << "incorrect value for last_msg_.certificate_bytes[65], expected 195, " - "is " - << last_msg_.certificate_bytes[65]; - EXPECT_EQ(last_msg_.certificate_bytes[66], 198) - << "incorrect value for last_msg_.certificate_bytes[66], expected 198, " - "is " - << last_msg_.certificate_bytes[66]; - EXPECT_EQ(last_msg_.certificate_bytes[67], 201) - << "incorrect value for last_msg_.certificate_bytes[67], expected 201, " - "is " - << last_msg_.certificate_bytes[67]; - EXPECT_EQ(last_msg_.certificate_bytes[68], 204) - << "incorrect value for last_msg_.certificate_bytes[68], expected 204, " - "is " - << last_msg_.certificate_bytes[68]; - EXPECT_EQ(last_msg_.certificate_bytes[69], 207) - << "incorrect value for last_msg_.certificate_bytes[69], expected 207, " - "is " - << last_msg_.certificate_bytes[69]; - EXPECT_EQ(last_msg_.certificate_bytes[70], 210) - << "incorrect value for last_msg_.certificate_bytes[70], expected 210, " - "is " - << last_msg_.certificate_bytes[70]; - EXPECT_EQ(last_msg_.certificate_bytes[71], 213) - << "incorrect value for last_msg_.certificate_bytes[71], expected 213, " - "is " - << last_msg_.certificate_bytes[71]; - EXPECT_EQ(last_msg_.certificate_bytes[72], 216) - << "incorrect value for last_msg_.certificate_bytes[72], expected 216, " - "is " - << last_msg_.certificate_bytes[72]; - EXPECT_EQ(last_msg_.certificate_bytes[73], 219) - << "incorrect value for last_msg_.certificate_bytes[73], expected 219, " - "is " - << last_msg_.certificate_bytes[73]; - EXPECT_EQ(last_msg_.certificate_bytes[74], 222) - << "incorrect value for last_msg_.certificate_bytes[74], expected 222, " - "is " - << last_msg_.certificate_bytes[74]; - EXPECT_EQ(last_msg_.certificate_bytes[75], 225) - << "incorrect value for last_msg_.certificate_bytes[75], expected 225, " - "is " - << last_msg_.certificate_bytes[75]; - EXPECT_EQ(last_msg_.certificate_bytes[76], 228) - << "incorrect value for last_msg_.certificate_bytes[76], expected 228, " - "is " - << last_msg_.certificate_bytes[76]; - EXPECT_EQ(last_msg_.certificate_bytes[77], 231) - << "incorrect value for last_msg_.certificate_bytes[77], expected 231, " - "is " - << last_msg_.certificate_bytes[77]; - EXPECT_EQ(last_msg_.certificate_bytes[78], 234) - << "incorrect value for last_msg_.certificate_bytes[78], expected 234, " - "is " - << last_msg_.certificate_bytes[78]; - EXPECT_EQ(last_msg_.certificate_bytes[79], 237) - << "incorrect value for last_msg_.certificate_bytes[79], expected 237, " - "is " - << last_msg_.certificate_bytes[79]; - EXPECT_EQ(last_msg_.certificate_bytes[80], 240) - << "incorrect value for last_msg_.certificate_bytes[80], expected 240, " - "is " - << last_msg_.certificate_bytes[80]; - EXPECT_EQ(last_msg_.certificate_bytes[81], 243) - << "incorrect value for last_msg_.certificate_bytes[81], expected 243, " - "is " - << last_msg_.certificate_bytes[81]; - EXPECT_EQ(last_msg_.certificate_bytes[82], 246) - << "incorrect value for last_msg_.certificate_bytes[82], expected 246, " - "is " - << last_msg_.certificate_bytes[82]; - EXPECT_EQ(last_msg_.certificate_bytes[83], 249) - << "incorrect value for last_msg_.certificate_bytes[83], expected 249, " - "is " - << last_msg_.certificate_bytes[83]; - EXPECT_EQ(last_msg_.certificate_bytes[84], 252) - << "incorrect value for last_msg_.certificate_bytes[84], expected 252, " - "is " - << last_msg_.certificate_bytes[84]; - EXPECT_EQ(last_msg_.fingerprint[0], 100) - << "incorrect value for last_msg_.fingerprint[0], expected 100, is " - << last_msg_.fingerprint[0]; - EXPECT_EQ(last_msg_.fingerprint[1], 101) - << "incorrect value for last_msg_.fingerprint[1], expected 101, is " - << last_msg_.fingerprint[1]; - EXPECT_EQ(last_msg_.fingerprint[2], 102) - << "incorrect value for last_msg_.fingerprint[2], expected 102, is " - << last_msg_.fingerprint[2]; - EXPECT_EQ(last_msg_.fingerprint[3], 103) - << "incorrect value for last_msg_.fingerprint[3], expected 103, is " - << last_msg_.fingerprint[3]; - EXPECT_EQ(last_msg_.fingerprint[4], 104) - << "incorrect value for last_msg_.fingerprint[4], expected 104, is " - << last_msg_.fingerprint[4]; - EXPECT_EQ(last_msg_.fingerprint[5], 105) - << "incorrect value for last_msg_.fingerprint[5], expected 105, is " - << last_msg_.fingerprint[5]; - EXPECT_EQ(last_msg_.fingerprint[6], 106) - << "incorrect value for last_msg_.fingerprint[6], expected 106, is " - << last_msg_.fingerprint[6]; - EXPECT_EQ(last_msg_.fingerprint[7], 107) - << "incorrect value for last_msg_.fingerprint[7], expected 107, is " - << last_msg_.fingerprint[7]; - EXPECT_EQ(last_msg_.fingerprint[8], 108) - << "incorrect value for last_msg_.fingerprint[8], expected 108, is " - << last_msg_.fingerprint[8]; - EXPECT_EQ(last_msg_.fingerprint[9], 109) - << "incorrect value for last_msg_.fingerprint[9], expected 109, is " - << last_msg_.fingerprint[9]; - EXPECT_EQ(last_msg_.fingerprint[10], 110) - << "incorrect value for last_msg_.fingerprint[10], expected 110, is " - << last_msg_.fingerprint[10]; - EXPECT_EQ(last_msg_.fingerprint[11], 111) - << "incorrect value for last_msg_.fingerprint[11], expected 111, is " - << last_msg_.fingerprint[11]; - EXPECT_EQ(last_msg_.fingerprint[12], 112) - << "incorrect value for last_msg_.fingerprint[12], expected 112, is " - << last_msg_.fingerprint[12]; - EXPECT_EQ(last_msg_.fingerprint[13], 113) - << "incorrect value for last_msg_.fingerprint[13], expected 113, is " - << last_msg_.fingerprint[13]; - EXPECT_EQ(last_msg_.fingerprint[14], 114) - << "incorrect value for last_msg_.fingerprint[14], expected 114, is " - << last_msg_.fingerprint[14]; - EXPECT_EQ(last_msg_.fingerprint[15], 115) - << "incorrect value for last_msg_.fingerprint[15], expected 115, is " - << last_msg_.fingerprint[15]; - EXPECT_EQ(last_msg_.fingerprint[16], 116) - << "incorrect value for last_msg_.fingerprint[16], expected 116, is " - << last_msg_.fingerprint[16]; - EXPECT_EQ(last_msg_.fingerprint[17], 117) - << "incorrect value for last_msg_.fingerprint[17], expected 117, is " - << last_msg_.fingerprint[17]; - EXPECT_EQ(last_msg_.fingerprint[18], 118) - << "incorrect value for last_msg_.fingerprint[18], expected 118, is " - << last_msg_.fingerprint[18]; - EXPECT_EQ(last_msg_.fingerprint[19], 119) - << "incorrect value for last_msg_.fingerprint[19], expected 119, is " - << last_msg_.fingerprint[19]; - EXPECT_EQ(last_msg_.n_certificate_bytes, 85) - << "incorrect value for last_msg_.n_certificate_bytes, expected 85, is " - << last_msg_.n_certificate_bytes; - EXPECT_EQ(last_msg_.n_msg, 16) - << "incorrect value for last_msg_.n_msg, expected 16, is " - << last_msg_.n_msg; + { + sbp_msg_ed25519_certificate_dep_t lesser = info.test_msg; + sbp_msg_ed25519_certificate_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_msg, greater.n_msg); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEd25519CertificateDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ED25519_CERTIFICATE_DEP"); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ed25519_certificate_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ed25519_certificate_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ed25519_certificate_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ed25519_certificate_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[106]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 106); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 106), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_certificate_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 106); + EXPECT_EQ(msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEd25519CertificateDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519CertificateDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEd25519CertificateDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepA.cc b/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepA.cc index 3457bcc595..a8e012b844 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepA.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepA.cc @@ -16,66 +16,587 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEd25519SignatureDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEd25519SignatureDepA0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEd25519SignatureDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgEd25519SignatureDepA0() { + assign(test_msg_.fingerprint[0], 100); + + assign(test_msg_.fingerprint[1], 101); + + assign(test_msg_.fingerprint[2], 102); + + assign(test_msg_.fingerprint[3], 103); + + assign(test_msg_.fingerprint[4], 104); + + assign(test_msg_.fingerprint[5], 105); + + assign(test_msg_.fingerprint[6], 106); + + assign(test_msg_.fingerprint[7], 107); + + assign(test_msg_.fingerprint[8], 108); + + assign(test_msg_.fingerprint[9], 109); + + assign(test_msg_.fingerprint[10], 110); + + assign(test_msg_.fingerprint[11], 111); + + assign(test_msg_.fingerprint[12], 112); + + assign(test_msg_.fingerprint[13], 113); + + assign(test_msg_.fingerprint[14], 114); + + assign(test_msg_.fingerprint[15], 115); + + assign(test_msg_.fingerprint[16], 116); + + assign(test_msg_.fingerprint[17], 117); + + assign(test_msg_.fingerprint[18], 118); + + assign(test_msg_.fingerprint[19], 119); + assign(test_msg_.n_signed_messages, 25); + + assign(test_msg_.signature[0], 0); + + assign(test_msg_.signature[1], 1); + + assign(test_msg_.signature[2], 2); + + assign(test_msg_.signature[3], 3); + + assign(test_msg_.signature[4], 4); + + assign(test_msg_.signature[5], 5); + + assign(test_msg_.signature[6], 6); + + assign(test_msg_.signature[7], 7); + + assign(test_msg_.signature[8], 8); + + assign(test_msg_.signature[9], 9); + + assign(test_msg_.signature[10], 10); + + assign(test_msg_.signature[11], 11); + + assign(test_msg_.signature[12], 12); + + assign(test_msg_.signature[13], 13); + + assign(test_msg_.signature[14], 14); + + assign(test_msg_.signature[15], 15); + + assign(test_msg_.signature[16], 16); + + assign(test_msg_.signature[17], 17); + + assign(test_msg_.signature[18], 18); + + assign(test_msg_.signature[19], 19); + + assign(test_msg_.signature[20], 20); + + assign(test_msg_.signature[21], 21); + + assign(test_msg_.signature[22], 22); + + assign(test_msg_.signature[23], 23); + + assign(test_msg_.signature[24], 24); + + assign(test_msg_.signature[25], 25); + + assign(test_msg_.signature[26], 26); + + assign(test_msg_.signature[27], 27); + + assign(test_msg_.signature[28], 28); + + assign(test_msg_.signature[29], 29); + + assign(test_msg_.signature[30], 30); + + assign(test_msg_.signature[31], 31); + + assign(test_msg_.signature[32], 32); + + assign(test_msg_.signature[33], 33); + + assign(test_msg_.signature[34], 34); + + assign(test_msg_.signature[35], 35); + + assign(test_msg_.signature[36], 36); + + assign(test_msg_.signature[37], 37); + + assign(test_msg_.signature[38], 38); + + assign(test_msg_.signature[39], 39); + + assign(test_msg_.signature[40], 40); + + assign(test_msg_.signature[41], 41); + + assign(test_msg_.signature[42], 42); + + assign(test_msg_.signature[43], 43); + + assign(test_msg_.signature[44], 44); + + assign(test_msg_.signature[45], 45); + + assign(test_msg_.signature[46], 46); + + assign(test_msg_.signature[47], 47); + + assign(test_msg_.signature[48], 48); + + assign(test_msg_.signature[49], 49); + + assign(test_msg_.signature[50], 50); + + assign(test_msg_.signature[51], 51); + + assign(test_msg_.signature[52], 52); + + assign(test_msg_.signature[53], 53); + + assign(test_msg_.signature[54], 54); + + assign(test_msg_.signature[55], 55); + + assign(test_msg_.signature[56], 56); + + assign(test_msg_.signature[57], 57); + + assign(test_msg_.signature[58], 58); + + assign(test_msg_.signature[59], 59); + + assign(test_msg_.signature[60], 60); + + assign(test_msg_.signature[61], 61); + + assign(test_msg_.signature[62], 62); + + assign(test_msg_.signature[63], 63); + + assign(test_msg_.signed_messages[0], 5000); + + assign(test_msg_.signed_messages[1], 5234); + + assign(test_msg_.signed_messages[2], 5468); + + assign(test_msg_.signed_messages[3], 5702); + + assign(test_msg_.signed_messages[4], 5936); + + assign(test_msg_.signed_messages[5], 6170); + + assign(test_msg_.signed_messages[6], 6404); + + assign(test_msg_.signed_messages[7], 6638); + + assign(test_msg_.signed_messages[8], 6872); + + assign(test_msg_.signed_messages[9], 7106); + + assign(test_msg_.signed_messages[10], 7340); + + assign(test_msg_.signed_messages[11], 7574); + + assign(test_msg_.signed_messages[12], 7808); + + assign(test_msg_.signed_messages[13], 8042); + + assign(test_msg_.signed_messages[14], 8276); + + assign(test_msg_.signed_messages[15], 8510); + + assign(test_msg_.signed_messages[16], 8744); + + assign(test_msg_.signed_messages[17], 8978); + + assign(test_msg_.signed_messages[18], 9212); + + assign(test_msg_.signed_messages[19], 9446); + + assign(test_msg_.signed_messages[20], 9680); + + assign(test_msg_.signed_messages[21], 9914); + + assign(test_msg_.signed_messages[22], 10148); + + assign(test_msg_.signed_messages[23], 10382); + + assign(test_msg_.signed_messages[24], 10616); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ed25519_signature_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_signature_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ed25519_signature_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEd25519SignatureDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_signature_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEd25519SignatureDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ed25519_signature_dep_a, + sizeof(msg->ed25519_signature_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ed25519_signature_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ed25519_signature_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEd25519SignatureDepA); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x6FA9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 184; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ed25519_signature_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ed25519_signature_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ed25519_signature_dep_a_t &lesser, + const sbp_msg_ed25519_signature_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ed25519_signature_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ed25519_signature_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519SignatureDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519SignatureDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEd25519SignatureDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEd25519SignatureDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_signing_MsgEd25519SignatureDepA0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ed25519_signature_dep_a_t test_msg_{}; + uint8_t encoded_frame_[184 + 8] = { 85, 1, 12, 66, 0, 184, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, @@ -90,571 +611,1228 @@ TEST_F(Test_auto_check_sbp_signing_MsgEd25519SignatureDepA0, Test) { 0, 230, 36, 0, 0, 208, 37, 0, 0, 186, 38, 0, 0, 164, 39, 0, 0, 142, 40, 0, 0, 120, 41, 0, 0, 169, 111, }; + uint8_t encoded_payload_[184] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 117, 118, 119, 136, 19, 0, 0, 114, 20, + 0, 0, 92, 21, 0, 0, 70, 22, 0, 0, 48, 23, 0, 0, 26, + 24, 0, 0, 4, 25, 0, 0, 238, 25, 0, 0, 216, 26, 0, 0, + 194, 27, 0, 0, 172, 28, 0, 0, 150, 29, 0, 0, 128, 30, 0, + 0, 106, 31, 0, 0, 84, 32, 0, 0, 62, 33, 0, 0, 40, 34, + 0, 0, 18, 35, 0, 0, 252, 35, 0, 0, 230, 36, 0, 0, 208, + 37, 0, 0, 186, 38, 0, 0, 164, 39, 0, 0, 142, 40, 0, 0, + 120, 41, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEd25519SignatureDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[184]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 184); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 184), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEd25519SignatureDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 184); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 184), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[184]; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 184), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[184]; + + for (uint8_t i = 0; i < 184; i++) { + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 184); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgEd25519SignatureDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 184); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ed25519_signature_dep_a_t t{}; + return sbp_msg_ed25519_signature_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ed25519_signature_dep_a_t t{}; + t.n_signed_messages = 1; + return sbp_msg_ed25519_signature_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEd25519SignatureDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgEd25519SignatureDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgEd25519SignatureDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[0], greater.fingerprint[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[1], greater.fingerprint[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[2], greater.fingerprint[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[3], greater.fingerprint[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[4], greater.fingerprint[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[5], greater.fingerprint[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[6], greater.fingerprint[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[7], greater.fingerprint[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[8], greater.fingerprint[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[9], greater.fingerprint[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[10], greater.fingerprint[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[11], greater.fingerprint[11]); + comparison_tests(lesser, greater); + } - sbp_msg_ed25519_signature_dep_a_t test_msg{}; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[12], greater.fingerprint[12]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[0] = 100; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[13], greater.fingerprint[13]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[1] = 101; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[14], greater.fingerprint[14]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[2] = 102; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[15], greater.fingerprint[15]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[3] = 103; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[16], greater.fingerprint[16]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[4] = 104; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[17], greater.fingerprint[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[18], greater.fingerprint[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[19], greater.fingerprint[19]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_signed_messages, greater.n_signed_messages); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[5] = 105; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[0], greater.signature[0]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[6] = 106; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[1], greater.signature[1]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[7] = 107; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[2], greater.signature[2]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[8] = 108; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[3], greater.signature[3]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[9] = 109; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[4], greater.signature[4]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[10] = 110; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[5], greater.signature[5]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[11] = 111; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[6], greater.signature[6]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[12] = 112; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[7], greater.signature[7]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[13] = 113; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[8], greater.signature[8]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[14] = 114; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[9], greater.signature[9]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[15] = 115; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[10], greater.signature[10]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[16] = 116; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[11], greater.signature[11]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[17] = 117; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[12], greater.signature[12]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[18] = 118; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[13], greater.signature[13]); + comparison_tests(lesser, greater); + } - test_msg.fingerprint[19] = 119; - test_msg.n_signed_messages = 25; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[14], greater.signature[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[0] = 0; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[15], greater.signature[15]); + comparison_tests(lesser, greater); + } - test_msg.signature[1] = 1; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[16], greater.signature[16]); + comparison_tests(lesser, greater); + } - test_msg.signature[2] = 2; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[17], greater.signature[17]); + comparison_tests(lesser, greater); + } - test_msg.signature[3] = 3; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[18], greater.signature[18]); + comparison_tests(lesser, greater); + } - test_msg.signature[4] = 4; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[19], greater.signature[19]); + comparison_tests(lesser, greater); + } - test_msg.signature[5] = 5; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[20], greater.signature[20]); + comparison_tests(lesser, greater); + } - test_msg.signature[6] = 6; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[21], greater.signature[21]); + comparison_tests(lesser, greater); + } - test_msg.signature[7] = 7; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[22], greater.signature[22]); + comparison_tests(lesser, greater); + } - test_msg.signature[8] = 8; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[23], greater.signature[23]); + comparison_tests(lesser, greater); + } - test_msg.signature[9] = 9; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[24], greater.signature[24]); + comparison_tests(lesser, greater); + } - test_msg.signature[10] = 10; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[25], greater.signature[25]); + comparison_tests(lesser, greater); + } - test_msg.signature[11] = 11; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[26], greater.signature[26]); + comparison_tests(lesser, greater); + } - test_msg.signature[12] = 12; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[27], greater.signature[27]); + comparison_tests(lesser, greater); + } - test_msg.signature[13] = 13; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[28], greater.signature[28]); + comparison_tests(lesser, greater); + } - test_msg.signature[14] = 14; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[29], greater.signature[29]); + comparison_tests(lesser, greater); + } - test_msg.signature[15] = 15; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[30], greater.signature[30]); + comparison_tests(lesser, greater); + } - test_msg.signature[16] = 16; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[31], greater.signature[31]); + comparison_tests(lesser, greater); + } - test_msg.signature[17] = 17; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[32], greater.signature[32]); + comparison_tests(lesser, greater); + } - test_msg.signature[18] = 18; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[33], greater.signature[33]); + comparison_tests(lesser, greater); + } - test_msg.signature[19] = 19; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[34], greater.signature[34]); + comparison_tests(lesser, greater); + } - test_msg.signature[20] = 20; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[35], greater.signature[35]); + comparison_tests(lesser, greater); + } - test_msg.signature[21] = 21; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[36], greater.signature[36]); + comparison_tests(lesser, greater); + } - test_msg.signature[22] = 22; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[37], greater.signature[37]); + comparison_tests(lesser, greater); + } - test_msg.signature[23] = 23; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[38], greater.signature[38]); + comparison_tests(lesser, greater); + } - test_msg.signature[24] = 24; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[39], greater.signature[39]); + comparison_tests(lesser, greater); + } - test_msg.signature[25] = 25; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[40], greater.signature[40]); + comparison_tests(lesser, greater); + } - test_msg.signature[26] = 26; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[41], greater.signature[41]); + comparison_tests(lesser, greater); + } - test_msg.signature[27] = 27; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[42], greater.signature[42]); + comparison_tests(lesser, greater); + } - test_msg.signature[28] = 28; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[43], greater.signature[43]); + comparison_tests(lesser, greater); + } - test_msg.signature[29] = 29; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[44], greater.signature[44]); + comparison_tests(lesser, greater); + } - test_msg.signature[30] = 30; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[45], greater.signature[45]); + comparison_tests(lesser, greater); + } - test_msg.signature[31] = 31; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[46], greater.signature[46]); + comparison_tests(lesser, greater); + } - test_msg.signature[32] = 32; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[47], greater.signature[47]); + comparison_tests(lesser, greater); + } - test_msg.signature[33] = 33; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[48], greater.signature[48]); + comparison_tests(lesser, greater); + } - test_msg.signature[34] = 34; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[49], greater.signature[49]); + comparison_tests(lesser, greater); + } - test_msg.signature[35] = 35; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[50], greater.signature[50]); + comparison_tests(lesser, greater); + } - test_msg.signature[36] = 36; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[51], greater.signature[51]); + comparison_tests(lesser, greater); + } - test_msg.signature[37] = 37; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[52], greater.signature[52]); + comparison_tests(lesser, greater); + } - test_msg.signature[38] = 38; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[53], greater.signature[53]); + comparison_tests(lesser, greater); + } - test_msg.signature[39] = 39; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[54], greater.signature[54]); + comparison_tests(lesser, greater); + } - test_msg.signature[40] = 40; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[55], greater.signature[55]); + comparison_tests(lesser, greater); + } - test_msg.signature[41] = 41; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[56], greater.signature[56]); + comparison_tests(lesser, greater); + } - test_msg.signature[42] = 42; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[57], greater.signature[57]); + comparison_tests(lesser, greater); + } - test_msg.signature[43] = 43; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[58], greater.signature[58]); + comparison_tests(lesser, greater); + } - test_msg.signature[44] = 44; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[59], greater.signature[59]); + comparison_tests(lesser, greater); + } - test_msg.signature[45] = 45; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[60], greater.signature[60]); + comparison_tests(lesser, greater); + } - test_msg.signature[46] = 46; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[61], greater.signature[61]); + comparison_tests(lesser, greater); + } - test_msg.signature[47] = 47; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[62], greater.signature[62]); + comparison_tests(lesser, greater); + } - test_msg.signature[48] = 48; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signature[63], greater.signature[63]); + comparison_tests(lesser, greater); + } - test_msg.signature[49] = 49; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[0], greater.signed_messages[0]); + comparison_tests(lesser, greater); + } - test_msg.signature[50] = 50; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[1], greater.signed_messages[1]); + comparison_tests(lesser, greater); + } - test_msg.signature[51] = 51; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[2], greater.signed_messages[2]); + comparison_tests(lesser, greater); + } - test_msg.signature[52] = 52; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[3], greater.signed_messages[3]); + comparison_tests(lesser, greater); + } - test_msg.signature[53] = 53; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[4], greater.signed_messages[4]); + comparison_tests(lesser, greater); + } - test_msg.signature[54] = 54; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[5], greater.signed_messages[5]); + comparison_tests(lesser, greater); + } - test_msg.signature[55] = 55; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[6], greater.signed_messages[6]); + comparison_tests(lesser, greater); + } - test_msg.signature[56] = 56; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[7], greater.signed_messages[7]); + comparison_tests(lesser, greater); + } - test_msg.signature[57] = 57; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[8], greater.signed_messages[8]); + comparison_tests(lesser, greater); + } - test_msg.signature[58] = 58; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[9], greater.signed_messages[9]); + comparison_tests(lesser, greater); + } - test_msg.signature[59] = 59; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[10], + greater.signed_messages[10]); + comparison_tests(lesser, greater); + } - test_msg.signature[60] = 60; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[11], + greater.signed_messages[11]); + comparison_tests(lesser, greater); + } - test_msg.signature[61] = 61; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[12], + greater.signed_messages[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[62] = 62; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[13], + greater.signed_messages[13]); + comparison_tests(lesser, greater); + } - test_msg.signature[63] = 63; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[14], + greater.signed_messages[14]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[0] = 5000; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[15], + greater.signed_messages[15]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[1] = 5234; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[16], + greater.signed_messages[16]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[2] = 5468; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[17], + greater.signed_messages[17]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[3] = 5702; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[18], + greater.signed_messages[18]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[4] = 5936; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[19], + greater.signed_messages[19]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[5] = 6170; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[20], + greater.signed_messages[20]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[6] = 6404; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[21], + greater.signed_messages[21]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[7] = 6638; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[22], + greater.signed_messages[22]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[8] = 6872; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[23], + greater.signed_messages[23]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[9] = 7106; + { + sbp_msg_ed25519_signature_dep_a_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[24], + greater.signed_messages[24]); + comparison_tests(lesser, greater); + } +} - test_msg.signed_messages[10] = 7340; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEd25519SignatureDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ED25519_SIGNATURE_DEP_A"); +} - test_msg.signed_messages[11] = 7574; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); - test_msg.signed_messages[12] = 7808; + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; - test_msg.signed_messages[13] = 8042; + const sbp_msg_ed25519_signature_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ed25519_signature_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); - test_msg.signed_messages[14] = 8276; + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} - test_msg.signed_messages[15] = 8510; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); - test_msg.signed_messages[16] = 8744; + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ed25519_signature_dep_a, info.test_msg); - test_msg.signed_messages[17] = 8978; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ed25519_signature_dep_a, info.test_msg); +} - test_msg.signed_messages[18] = 9212; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} - test_msg.signed_messages[19] = 9446; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[20] = 9680; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signed_messages[21] = 9914; + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.signed_messages[22] = 10148; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[184]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 184); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 184), 0); +} - test_msg.signed_messages[23] = 10382; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 184); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.signed_messages[24] = 10616; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + sbp::State state{}; + state.set_reader(&reader); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + CppHandler handler{&state}; - while (dummy_rd_ < dummy_wr_) { - process(); + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.fingerprint[0], 100) - << "incorrect value for last_msg_.fingerprint[0], expected 100, is " - << last_msg_.fingerprint[0]; - EXPECT_EQ(last_msg_.fingerprint[1], 101) - << "incorrect value for last_msg_.fingerprint[1], expected 101, is " - << last_msg_.fingerprint[1]; - EXPECT_EQ(last_msg_.fingerprint[2], 102) - << "incorrect value for last_msg_.fingerprint[2], expected 102, is " - << last_msg_.fingerprint[2]; - EXPECT_EQ(last_msg_.fingerprint[3], 103) - << "incorrect value for last_msg_.fingerprint[3], expected 103, is " - << last_msg_.fingerprint[3]; - EXPECT_EQ(last_msg_.fingerprint[4], 104) - << "incorrect value for last_msg_.fingerprint[4], expected 104, is " - << last_msg_.fingerprint[4]; - EXPECT_EQ(last_msg_.fingerprint[5], 105) - << "incorrect value for last_msg_.fingerprint[5], expected 105, is " - << last_msg_.fingerprint[5]; - EXPECT_EQ(last_msg_.fingerprint[6], 106) - << "incorrect value for last_msg_.fingerprint[6], expected 106, is " - << last_msg_.fingerprint[6]; - EXPECT_EQ(last_msg_.fingerprint[7], 107) - << "incorrect value for last_msg_.fingerprint[7], expected 107, is " - << last_msg_.fingerprint[7]; - EXPECT_EQ(last_msg_.fingerprint[8], 108) - << "incorrect value for last_msg_.fingerprint[8], expected 108, is " - << last_msg_.fingerprint[8]; - EXPECT_EQ(last_msg_.fingerprint[9], 109) - << "incorrect value for last_msg_.fingerprint[9], expected 109, is " - << last_msg_.fingerprint[9]; - EXPECT_EQ(last_msg_.fingerprint[10], 110) - << "incorrect value for last_msg_.fingerprint[10], expected 110, is " - << last_msg_.fingerprint[10]; - EXPECT_EQ(last_msg_.fingerprint[11], 111) - << "incorrect value for last_msg_.fingerprint[11], expected 111, is " - << last_msg_.fingerprint[11]; - EXPECT_EQ(last_msg_.fingerprint[12], 112) - << "incorrect value for last_msg_.fingerprint[12], expected 112, is " - << last_msg_.fingerprint[12]; - EXPECT_EQ(last_msg_.fingerprint[13], 113) - << "incorrect value for last_msg_.fingerprint[13], expected 113, is " - << last_msg_.fingerprint[13]; - EXPECT_EQ(last_msg_.fingerprint[14], 114) - << "incorrect value for last_msg_.fingerprint[14], expected 114, is " - << last_msg_.fingerprint[14]; - EXPECT_EQ(last_msg_.fingerprint[15], 115) - << "incorrect value for last_msg_.fingerprint[15], expected 115, is " - << last_msg_.fingerprint[15]; - EXPECT_EQ(last_msg_.fingerprint[16], 116) - << "incorrect value for last_msg_.fingerprint[16], expected 116, is " - << last_msg_.fingerprint[16]; - EXPECT_EQ(last_msg_.fingerprint[17], 117) - << "incorrect value for last_msg_.fingerprint[17], expected 117, is " - << last_msg_.fingerprint[17]; - EXPECT_EQ(last_msg_.fingerprint[18], 118) - << "incorrect value for last_msg_.fingerprint[18], expected 118, is " - << last_msg_.fingerprint[18]; - EXPECT_EQ(last_msg_.fingerprint[19], 119) - << "incorrect value for last_msg_.fingerprint[19], expected 119, is " - << last_msg_.fingerprint[19]; - EXPECT_EQ(last_msg_.n_signed_messages, 25) - << "incorrect value for last_msg_.n_signed_messages, expected 25, is " - << last_msg_.n_signed_messages; - EXPECT_EQ(last_msg_.signature[0], 0) - << "incorrect value for last_msg_.signature[0], expected 0, is " - << last_msg_.signature[0]; - EXPECT_EQ(last_msg_.signature[1], 1) - << "incorrect value for last_msg_.signature[1], expected 1, is " - << last_msg_.signature[1]; - EXPECT_EQ(last_msg_.signature[2], 2) - << "incorrect value for last_msg_.signature[2], expected 2, is " - << last_msg_.signature[2]; - EXPECT_EQ(last_msg_.signature[3], 3) - << "incorrect value for last_msg_.signature[3], expected 3, is " - << last_msg_.signature[3]; - EXPECT_EQ(last_msg_.signature[4], 4) - << "incorrect value for last_msg_.signature[4], expected 4, is " - << last_msg_.signature[4]; - EXPECT_EQ(last_msg_.signature[5], 5) - << "incorrect value for last_msg_.signature[5], expected 5, is " - << last_msg_.signature[5]; - EXPECT_EQ(last_msg_.signature[6], 6) - << "incorrect value for last_msg_.signature[6], expected 6, is " - << last_msg_.signature[6]; - EXPECT_EQ(last_msg_.signature[7], 7) - << "incorrect value for last_msg_.signature[7], expected 7, is " - << last_msg_.signature[7]; - EXPECT_EQ(last_msg_.signature[8], 8) - << "incorrect value for last_msg_.signature[8], expected 8, is " - << last_msg_.signature[8]; - EXPECT_EQ(last_msg_.signature[9], 9) - << "incorrect value for last_msg_.signature[9], expected 9, is " - << last_msg_.signature[9]; - EXPECT_EQ(last_msg_.signature[10], 10) - << "incorrect value for last_msg_.signature[10], expected 10, is " - << last_msg_.signature[10]; - EXPECT_EQ(last_msg_.signature[11], 11) - << "incorrect value for last_msg_.signature[11], expected 11, is " - << last_msg_.signature[11]; - EXPECT_EQ(last_msg_.signature[12], 12) - << "incorrect value for last_msg_.signature[12], expected 12, is " - << last_msg_.signature[12]; - EXPECT_EQ(last_msg_.signature[13], 13) - << "incorrect value for last_msg_.signature[13], expected 13, is " - << last_msg_.signature[13]; - EXPECT_EQ(last_msg_.signature[14], 14) - << "incorrect value for last_msg_.signature[14], expected 14, is " - << last_msg_.signature[14]; - EXPECT_EQ(last_msg_.signature[15], 15) - << "incorrect value for last_msg_.signature[15], expected 15, is " - << last_msg_.signature[15]; - EXPECT_EQ(last_msg_.signature[16], 16) - << "incorrect value for last_msg_.signature[16], expected 16, is " - << last_msg_.signature[16]; - EXPECT_EQ(last_msg_.signature[17], 17) - << "incorrect value for last_msg_.signature[17], expected 17, is " - << last_msg_.signature[17]; - EXPECT_EQ(last_msg_.signature[18], 18) - << "incorrect value for last_msg_.signature[18], expected 18, is " - << last_msg_.signature[18]; - EXPECT_EQ(last_msg_.signature[19], 19) - << "incorrect value for last_msg_.signature[19], expected 19, is " - << last_msg_.signature[19]; - EXPECT_EQ(last_msg_.signature[20], 20) - << "incorrect value for last_msg_.signature[20], expected 20, is " - << last_msg_.signature[20]; - EXPECT_EQ(last_msg_.signature[21], 21) - << "incorrect value for last_msg_.signature[21], expected 21, is " - << last_msg_.signature[21]; - EXPECT_EQ(last_msg_.signature[22], 22) - << "incorrect value for last_msg_.signature[22], expected 22, is " - << last_msg_.signature[22]; - EXPECT_EQ(last_msg_.signature[23], 23) - << "incorrect value for last_msg_.signature[23], expected 23, is " - << last_msg_.signature[23]; - EXPECT_EQ(last_msg_.signature[24], 24) - << "incorrect value for last_msg_.signature[24], expected 24, is " - << last_msg_.signature[24]; - EXPECT_EQ(last_msg_.signature[25], 25) - << "incorrect value for last_msg_.signature[25], expected 25, is " - << last_msg_.signature[25]; - EXPECT_EQ(last_msg_.signature[26], 26) - << "incorrect value for last_msg_.signature[26], expected 26, is " - << last_msg_.signature[26]; - EXPECT_EQ(last_msg_.signature[27], 27) - << "incorrect value for last_msg_.signature[27], expected 27, is " - << last_msg_.signature[27]; - EXPECT_EQ(last_msg_.signature[28], 28) - << "incorrect value for last_msg_.signature[28], expected 28, is " - << last_msg_.signature[28]; - EXPECT_EQ(last_msg_.signature[29], 29) - << "incorrect value for last_msg_.signature[29], expected 29, is " - << last_msg_.signature[29]; - EXPECT_EQ(last_msg_.signature[30], 30) - << "incorrect value for last_msg_.signature[30], expected 30, is " - << last_msg_.signature[30]; - EXPECT_EQ(last_msg_.signature[31], 31) - << "incorrect value for last_msg_.signature[31], expected 31, is " - << last_msg_.signature[31]; - EXPECT_EQ(last_msg_.signature[32], 32) - << "incorrect value for last_msg_.signature[32], expected 32, is " - << last_msg_.signature[32]; - EXPECT_EQ(last_msg_.signature[33], 33) - << "incorrect value for last_msg_.signature[33], expected 33, is " - << last_msg_.signature[33]; - EXPECT_EQ(last_msg_.signature[34], 34) - << "incorrect value for last_msg_.signature[34], expected 34, is " - << last_msg_.signature[34]; - EXPECT_EQ(last_msg_.signature[35], 35) - << "incorrect value for last_msg_.signature[35], expected 35, is " - << last_msg_.signature[35]; - EXPECT_EQ(last_msg_.signature[36], 36) - << "incorrect value for last_msg_.signature[36], expected 36, is " - << last_msg_.signature[36]; - EXPECT_EQ(last_msg_.signature[37], 37) - << "incorrect value for last_msg_.signature[37], expected 37, is " - << last_msg_.signature[37]; - EXPECT_EQ(last_msg_.signature[38], 38) - << "incorrect value for last_msg_.signature[38], expected 38, is " - << last_msg_.signature[38]; - EXPECT_EQ(last_msg_.signature[39], 39) - << "incorrect value for last_msg_.signature[39], expected 39, is " - << last_msg_.signature[39]; - EXPECT_EQ(last_msg_.signature[40], 40) - << "incorrect value for last_msg_.signature[40], expected 40, is " - << last_msg_.signature[40]; - EXPECT_EQ(last_msg_.signature[41], 41) - << "incorrect value for last_msg_.signature[41], expected 41, is " - << last_msg_.signature[41]; - EXPECT_EQ(last_msg_.signature[42], 42) - << "incorrect value for last_msg_.signature[42], expected 42, is " - << last_msg_.signature[42]; - EXPECT_EQ(last_msg_.signature[43], 43) - << "incorrect value for last_msg_.signature[43], expected 43, is " - << last_msg_.signature[43]; - EXPECT_EQ(last_msg_.signature[44], 44) - << "incorrect value for last_msg_.signature[44], expected 44, is " - << last_msg_.signature[44]; - EXPECT_EQ(last_msg_.signature[45], 45) - << "incorrect value for last_msg_.signature[45], expected 45, is " - << last_msg_.signature[45]; - EXPECT_EQ(last_msg_.signature[46], 46) - << "incorrect value for last_msg_.signature[46], expected 46, is " - << last_msg_.signature[46]; - EXPECT_EQ(last_msg_.signature[47], 47) - << "incorrect value for last_msg_.signature[47], expected 47, is " - << last_msg_.signature[47]; - EXPECT_EQ(last_msg_.signature[48], 48) - << "incorrect value for last_msg_.signature[48], expected 48, is " - << last_msg_.signature[48]; - EXPECT_EQ(last_msg_.signature[49], 49) - << "incorrect value for last_msg_.signature[49], expected 49, is " - << last_msg_.signature[49]; - EXPECT_EQ(last_msg_.signature[50], 50) - << "incorrect value for last_msg_.signature[50], expected 50, is " - << last_msg_.signature[50]; - EXPECT_EQ(last_msg_.signature[51], 51) - << "incorrect value for last_msg_.signature[51], expected 51, is " - << last_msg_.signature[51]; - EXPECT_EQ(last_msg_.signature[52], 52) - << "incorrect value for last_msg_.signature[52], expected 52, is " - << last_msg_.signature[52]; - EXPECT_EQ(last_msg_.signature[53], 53) - << "incorrect value for last_msg_.signature[53], expected 53, is " - << last_msg_.signature[53]; - EXPECT_EQ(last_msg_.signature[54], 54) - << "incorrect value for last_msg_.signature[54], expected 54, is " - << last_msg_.signature[54]; - EXPECT_EQ(last_msg_.signature[55], 55) - << "incorrect value for last_msg_.signature[55], expected 55, is " - << last_msg_.signature[55]; - EXPECT_EQ(last_msg_.signature[56], 56) - << "incorrect value for last_msg_.signature[56], expected 56, is " - << last_msg_.signature[56]; - EXPECT_EQ(last_msg_.signature[57], 57) - << "incorrect value for last_msg_.signature[57], expected 57, is " - << last_msg_.signature[57]; - EXPECT_EQ(last_msg_.signature[58], 58) - << "incorrect value for last_msg_.signature[58], expected 58, is " - << last_msg_.signature[58]; - EXPECT_EQ(last_msg_.signature[59], 59) - << "incorrect value for last_msg_.signature[59], expected 59, is " - << last_msg_.signature[59]; - EXPECT_EQ(last_msg_.signature[60], 60) - << "incorrect value for last_msg_.signature[60], expected 60, is " - << last_msg_.signature[60]; - EXPECT_EQ(last_msg_.signature[61], 61) - << "incorrect value for last_msg_.signature[61], expected 61, is " - << last_msg_.signature[61]; - EXPECT_EQ(last_msg_.signature[62], 62) - << "incorrect value for last_msg_.signature[62], expected 62, is " - << last_msg_.signature[62]; - EXPECT_EQ(last_msg_.signature[63], 63) - << "incorrect value for last_msg_.signature[63], expected 63, is " - << last_msg_.signature[63]; - EXPECT_EQ(last_msg_.signed_messages[0], 5000) - << "incorrect value for last_msg_.signed_messages[0], expected 5000, is " - << last_msg_.signed_messages[0]; - EXPECT_EQ(last_msg_.signed_messages[1], 5234) - << "incorrect value for last_msg_.signed_messages[1], expected 5234, is " - << last_msg_.signed_messages[1]; - EXPECT_EQ(last_msg_.signed_messages[2], 5468) - << "incorrect value for last_msg_.signed_messages[2], expected 5468, is " - << last_msg_.signed_messages[2]; - EXPECT_EQ(last_msg_.signed_messages[3], 5702) - << "incorrect value for last_msg_.signed_messages[3], expected 5702, is " - << last_msg_.signed_messages[3]; - EXPECT_EQ(last_msg_.signed_messages[4], 5936) - << "incorrect value for last_msg_.signed_messages[4], expected 5936, is " - << last_msg_.signed_messages[4]; - EXPECT_EQ(last_msg_.signed_messages[5], 6170) - << "incorrect value for last_msg_.signed_messages[5], expected 6170, is " - << last_msg_.signed_messages[5]; - EXPECT_EQ(last_msg_.signed_messages[6], 6404) - << "incorrect value for last_msg_.signed_messages[6], expected 6404, is " - << last_msg_.signed_messages[6]; - EXPECT_EQ(last_msg_.signed_messages[7], 6638) - << "incorrect value for last_msg_.signed_messages[7], expected 6638, is " - << last_msg_.signed_messages[7]; - EXPECT_EQ(last_msg_.signed_messages[8], 6872) - << "incorrect value for last_msg_.signed_messages[8], expected 6872, is " - << last_msg_.signed_messages[8]; - EXPECT_EQ(last_msg_.signed_messages[9], 7106) - << "incorrect value for last_msg_.signed_messages[9], expected 7106, is " - << last_msg_.signed_messages[9]; - EXPECT_EQ(last_msg_.signed_messages[10], 7340) - << "incorrect value for last_msg_.signed_messages[10], expected 7340, is " - << last_msg_.signed_messages[10]; - EXPECT_EQ(last_msg_.signed_messages[11], 7574) - << "incorrect value for last_msg_.signed_messages[11], expected 7574, is " - << last_msg_.signed_messages[11]; - EXPECT_EQ(last_msg_.signed_messages[12], 7808) - << "incorrect value for last_msg_.signed_messages[12], expected 7808, is " - << last_msg_.signed_messages[12]; - EXPECT_EQ(last_msg_.signed_messages[13], 8042) - << "incorrect value for last_msg_.signed_messages[13], expected 8042, is " - << last_msg_.signed_messages[13]; - EXPECT_EQ(last_msg_.signed_messages[14], 8276) - << "incorrect value for last_msg_.signed_messages[14], expected 8276, is " - << last_msg_.signed_messages[14]; - EXPECT_EQ(last_msg_.signed_messages[15], 8510) - << "incorrect value for last_msg_.signed_messages[15], expected 8510, is " - << last_msg_.signed_messages[15]; - EXPECT_EQ(last_msg_.signed_messages[16], 8744) - << "incorrect value for last_msg_.signed_messages[16], expected 8744, is " - << last_msg_.signed_messages[16]; - EXPECT_EQ(last_msg_.signed_messages[17], 8978) - << "incorrect value for last_msg_.signed_messages[17], expected 8978, is " - << last_msg_.signed_messages[17]; - EXPECT_EQ(last_msg_.signed_messages[18], 9212) - << "incorrect value for last_msg_.signed_messages[18], expected 9212, is " - << last_msg_.signed_messages[18]; - EXPECT_EQ(last_msg_.signed_messages[19], 9446) - << "incorrect value for last_msg_.signed_messages[19], expected 9446, is " - << last_msg_.signed_messages[19]; - EXPECT_EQ(last_msg_.signed_messages[20], 9680) - << "incorrect value for last_msg_.signed_messages[20], expected 9680, is " - << last_msg_.signed_messages[20]; - EXPECT_EQ(last_msg_.signed_messages[21], 9914) - << "incorrect value for last_msg_.signed_messages[21], expected 9914, is " - << last_msg_.signed_messages[21]; - EXPECT_EQ(last_msg_.signed_messages[22], 10148) - << "incorrect value for last_msg_.signed_messages[22], expected 10148, " - "is " - << last_msg_.signed_messages[22]; - EXPECT_EQ(last_msg_.signed_messages[23], 10382) - << "incorrect value for last_msg_.signed_messages[23], expected 10382, " - "is " - << last_msg_.signed_messages[23]; - EXPECT_EQ(last_msg_.signed_messages[24], 10616) - << "incorrect value for last_msg_.signed_messages[24], expected 10616, " - "is " - << last_msg_.signed_messages[24]; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEd25519SignatureDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEd25519SignatureDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepB.cc b/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepB.cc index 5431af2e45..aed176e0c7 100644 --- a/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepB.cc +++ b/c/test/cpp/auto_check_sbp_signing_MsgEd25519SignatureDepB.cc @@ -16,66 +16,589 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_signing_MsgEd25519SignatureDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_signing_MsgEd25519SignatureDepB0 + : public ::testing::Test { public: - Test_auto_check_sbp_signing_MsgEd25519SignatureDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_signing_MsgEd25519SignatureDepB0() { + assign(test_msg_.fingerprint[0], 100); + + assign(test_msg_.fingerprint[1], 101); + + assign(test_msg_.fingerprint[2], 102); + + assign(test_msg_.fingerprint[3], 103); + + assign(test_msg_.fingerprint[4], 104); + + assign(test_msg_.fingerprint[5], 105); + + assign(test_msg_.fingerprint[6], 106); + + assign(test_msg_.fingerprint[7], 107); + + assign(test_msg_.fingerprint[8], 108); + + assign(test_msg_.fingerprint[9], 109); + + assign(test_msg_.fingerprint[10], 110); + + assign(test_msg_.fingerprint[11], 111); + + assign(test_msg_.fingerprint[12], 112); + + assign(test_msg_.fingerprint[13], 113); + + assign(test_msg_.fingerprint[14], 114); + + assign(test_msg_.fingerprint[15], 115); + + assign(test_msg_.fingerprint[16], 116); + + assign(test_msg_.fingerprint[17], 117); + + assign(test_msg_.fingerprint[18], 118); + + assign(test_msg_.fingerprint[19], 119); + assign(test_msg_.n_signed_messages, 25); + assign(test_msg_.on_demand_counter, 0); + + assign(test_msg_.signature[0], 0); + + assign(test_msg_.signature[1], 1); + + assign(test_msg_.signature[2], 2); + + assign(test_msg_.signature[3], 3); + + assign(test_msg_.signature[4], 4); + + assign(test_msg_.signature[5], 5); + + assign(test_msg_.signature[6], 6); + + assign(test_msg_.signature[7], 7); + + assign(test_msg_.signature[8], 8); + + assign(test_msg_.signature[9], 9); + + assign(test_msg_.signature[10], 10); + + assign(test_msg_.signature[11], 11); + + assign(test_msg_.signature[12], 12); + + assign(test_msg_.signature[13], 13); + + assign(test_msg_.signature[14], 14); + + assign(test_msg_.signature[15], 15); + + assign(test_msg_.signature[16], 16); + + assign(test_msg_.signature[17], 17); + + assign(test_msg_.signature[18], 18); + + assign(test_msg_.signature[19], 19); + + assign(test_msg_.signature[20], 20); + + assign(test_msg_.signature[21], 21); + + assign(test_msg_.signature[22], 22); + + assign(test_msg_.signature[23], 23); + + assign(test_msg_.signature[24], 24); + + assign(test_msg_.signature[25], 25); + + assign(test_msg_.signature[26], 26); + + assign(test_msg_.signature[27], 27); + + assign(test_msg_.signature[28], 28); + + assign(test_msg_.signature[29], 29); + + assign(test_msg_.signature[30], 30); + + assign(test_msg_.signature[31], 31); + + assign(test_msg_.signature[32], 32); + + assign(test_msg_.signature[33], 33); + + assign(test_msg_.signature[34], 34); + + assign(test_msg_.signature[35], 35); + + assign(test_msg_.signature[36], 36); + + assign(test_msg_.signature[37], 37); + + assign(test_msg_.signature[38], 38); + + assign(test_msg_.signature[39], 39); + + assign(test_msg_.signature[40], 40); + + assign(test_msg_.signature[41], 41); + + assign(test_msg_.signature[42], 42); + + assign(test_msg_.signature[43], 43); + + assign(test_msg_.signature[44], 44); + + assign(test_msg_.signature[45], 45); + + assign(test_msg_.signature[46], 46); + + assign(test_msg_.signature[47], 47); + + assign(test_msg_.signature[48], 48); + + assign(test_msg_.signature[49], 49); + + assign(test_msg_.signature[50], 50); + + assign(test_msg_.signature[51], 51); + + assign(test_msg_.signature[52], 52); + + assign(test_msg_.signature[53], 53); + + assign(test_msg_.signature[54], 54); + + assign(test_msg_.signature[55], 55); + + assign(test_msg_.signature[56], 56); + + assign(test_msg_.signature[57], 57); + + assign(test_msg_.signature[58], 58); + + assign(test_msg_.signature[59], 59); + + assign(test_msg_.signature[60], 60); + + assign(test_msg_.signature[61], 61); + + assign(test_msg_.signature[62], 62); + + assign(test_msg_.signature[63], 63); + + assign(test_msg_.signed_messages[0], 5000); + + assign(test_msg_.signed_messages[1], 5234); + + assign(test_msg_.signed_messages[2], 5468); + + assign(test_msg_.signed_messages[3], 5702); + + assign(test_msg_.signed_messages[4], 5936); + + assign(test_msg_.signed_messages[5], 6170); + + assign(test_msg_.signed_messages[6], 6404); + + assign(test_msg_.signed_messages[7], 6638); + + assign(test_msg_.signed_messages[8], 6872); + + assign(test_msg_.signed_messages[9], 7106); + + assign(test_msg_.signed_messages[10], 7340); + + assign(test_msg_.signed_messages[11], 7574); + + assign(test_msg_.signed_messages[12], 7808); + + assign(test_msg_.signed_messages[13], 8042); + + assign(test_msg_.signed_messages[14], 8276); + + assign(test_msg_.signed_messages[15], 8510); + + assign(test_msg_.signed_messages[16], 8744); + + assign(test_msg_.signed_messages[17], 8978); + + assign(test_msg_.signed_messages[18], 9212); + + assign(test_msg_.signed_messages[19], 9446); + + assign(test_msg_.signed_messages[20], 9680); + + assign(test_msg_.signed_messages[21], 9914); + + assign(test_msg_.signed_messages[22], 10148); + + assign(test_msg_.signed_messages[23], 10382); + + assign(test_msg_.signed_messages[24], 10616); + assign(test_msg_.stream_counter, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ed25519_signature_dep_b_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_signature_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ed25519_signature_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgEd25519SignatureDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ed25519_signature_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgEd25519SignatureDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ed25519_signature_dep_b, + sizeof(msg->ed25519_signature_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ed25519_signature_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ed25519_signature_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgEd25519SignatureDepB); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x91EE; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 186; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ed25519_signature_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ed25519_signature_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ed25519_signature_dep_b_t &lesser, + const sbp_msg_ed25519_signature_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ed25519_signature_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ed25519_signature_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519SignatureDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgEd25519SignatureDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgEd25519SignatureDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgEd25519SignatureDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } -TEST_F(Test_auto_check_sbp_signing_MsgEd25519SignatureDepB0, Test) { - uint8_t encoded_frame[] = { + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ed25519_signature_dep_b_t test_msg_{}; + uint8_t encoded_frame_[186 + 8] = { 85, 3, 12, 66, 0, 186, 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, @@ -90,579 +613,1240 @@ TEST_F(Test_auto_check_sbp_signing_MsgEd25519SignatureDepB0, Test) { 35, 0, 0, 230, 36, 0, 0, 208, 37, 0, 0, 186, 38, 0, 0, 164, 39, 0, 0, 142, 40, 0, 0, 120, 41, 0, 0, 238, 145, }; + uint8_t encoded_payload_[186] = { + 1, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 100, 101, 102, 103, 104, 105, 106, 107, 108, + 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 136, 19, 0, 0, + 114, 20, 0, 0, 92, 21, 0, 0, 70, 22, 0, 0, 48, 23, 0, + 0, 26, 24, 0, 0, 4, 25, 0, 0, 238, 25, 0, 0, 216, 26, + 0, 0, 194, 27, 0, 0, 172, 28, 0, 0, 150, 29, 0, 0, 128, + 30, 0, 0, 106, 31, 0, 0, 84, 32, 0, 0, 62, 33, 0, 0, + 40, 34, 0, 0, 18, 35, 0, 0, 252, 35, 0, 0, 230, 36, 0, + 0, 208, 37, 0, 0, 186, 38, 0, 0, 164, 39, 0, 0, 142, 40, + 0, 0, 120, 41, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgEd25519SignatureDepB, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[186]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 186); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 186), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgEd25519SignatureDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 186); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 186), 0); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[186]; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 186), 0); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[186]; + + for (uint8_t i = 0; i < 186; i++) { + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 186); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgEd25519SignatureDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 186); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ed25519_signature_dep_b_t t{}; + return sbp_msg_ed25519_signature_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ed25519_signature_dep_b_t t{}; + t.n_signed_messages = 1; + return sbp_msg_ed25519_signature_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - sbp_msg_ed25519_signature_dep_b_t test_msg{}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.fingerprint[0] = 100; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.fingerprint[1] = 101; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.fingerprint[2] = 102; + sbp_state_t state; + sbp_state_init(&state); - test_msg.fingerprint[3] = 103; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.fingerprint[4] = 104; + CHandler handler{&state}; - test_msg.fingerprint[5] = 105; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.fingerprint[6] = 106; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.fingerprint[7] = 107; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.fingerprint[8] = 108; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.fingerprint[9] = 109; + EXPECT_EQ(sbp_msg_ed25519_signature_dep_b_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.fingerprint[10] = 110; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.fingerprint[11] = 111; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.fingerprint[12] = 112; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEd25519SignatureDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.fingerprint[13] = 113; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.fingerprint[14] = 114; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.fingerprint[15] = 115; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.fingerprint[16] = 116; + EXPECT_NE( + sbp_message_send(&state, SbpMsgEd25519SignatureDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.fingerprint[17] = 117; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.fingerprint[18] = 118; + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.fingerprint[19] = 119; - test_msg.n_signed_messages = 25; - test_msg.on_demand_counter = 0; + EXPECT_EQ(sbp_message_send(&state, SbpMsgEd25519SignatureDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.signature[0] = 0; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, Comparison) { + auto info = get_test_msg_info(); - test_msg.signature[1] = 1; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[0], greater.fingerprint[0]); + comparison_tests(lesser, greater); + } - test_msg.signature[2] = 2; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[1], greater.fingerprint[1]); + comparison_tests(lesser, greater); + } - test_msg.signature[3] = 3; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[2], greater.fingerprint[2]); + comparison_tests(lesser, greater); + } - test_msg.signature[4] = 4; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[3], greater.fingerprint[3]); + comparison_tests(lesser, greater); + } - test_msg.signature[5] = 5; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[4], greater.fingerprint[4]); + comparison_tests(lesser, greater); + } - test_msg.signature[6] = 6; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[5], greater.fingerprint[5]); + comparison_tests(lesser, greater); + } - test_msg.signature[7] = 7; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[6], greater.fingerprint[6]); + comparison_tests(lesser, greater); + } - test_msg.signature[8] = 8; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[7], greater.fingerprint[7]); + comparison_tests(lesser, greater); + } - test_msg.signature[9] = 9; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[8], greater.fingerprint[8]); + comparison_tests(lesser, greater); + } - test_msg.signature[10] = 10; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[9], greater.fingerprint[9]); + comparison_tests(lesser, greater); + } - test_msg.signature[11] = 11; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[10], greater.fingerprint[10]); + comparison_tests(lesser, greater); + } - test_msg.signature[12] = 12; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[11], greater.fingerprint[11]); + comparison_tests(lesser, greater); + } - test_msg.signature[13] = 13; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[12], greater.fingerprint[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[14] = 14; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[13], greater.fingerprint[13]); + comparison_tests(lesser, greater); + } - test_msg.signature[15] = 15; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[14], greater.fingerprint[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[16] = 16; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[15], greater.fingerprint[15]); + comparison_tests(lesser, greater); + } - test_msg.signature[17] = 17; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[16], greater.fingerprint[16]); + comparison_tests(lesser, greater); + } - test_msg.signature[18] = 18; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[17], greater.fingerprint[17]); + comparison_tests(lesser, greater); + } - test_msg.signature[19] = 19; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[18], greater.fingerprint[18]); + comparison_tests(lesser, greater); + } - test_msg.signature[20] = 20; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.fingerprint[19], greater.fingerprint[19]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_signed_messages, greater.n_signed_messages); + comparison_tests(lesser, greater); + } + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.on_demand_counter, greater.on_demand_counter); + comparison_tests(lesser, greater); + } - test_msg.signature[21] = 21; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[0], greater.signature[0]); + comparison_tests(lesser, greater); + } - test_msg.signature[22] = 22; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[1], greater.signature[1]); + comparison_tests(lesser, greater); + } - test_msg.signature[23] = 23; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[2], greater.signature[2]); + comparison_tests(lesser, greater); + } - test_msg.signature[24] = 24; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[3], greater.signature[3]); + comparison_tests(lesser, greater); + } - test_msg.signature[25] = 25; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[4], greater.signature[4]); + comparison_tests(lesser, greater); + } - test_msg.signature[26] = 26; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[5], greater.signature[5]); + comparison_tests(lesser, greater); + } - test_msg.signature[27] = 27; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[6], greater.signature[6]); + comparison_tests(lesser, greater); + } - test_msg.signature[28] = 28; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[7], greater.signature[7]); + comparison_tests(lesser, greater); + } - test_msg.signature[29] = 29; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[8], greater.signature[8]); + comparison_tests(lesser, greater); + } - test_msg.signature[30] = 30; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[9], greater.signature[9]); + comparison_tests(lesser, greater); + } - test_msg.signature[31] = 31; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[10], greater.signature[10]); + comparison_tests(lesser, greater); + } - test_msg.signature[32] = 32; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[11], greater.signature[11]); + comparison_tests(lesser, greater); + } - test_msg.signature[33] = 33; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[12], greater.signature[12]); + comparison_tests(lesser, greater); + } - test_msg.signature[34] = 34; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[13], greater.signature[13]); + comparison_tests(lesser, greater); + } - test_msg.signature[35] = 35; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[14], greater.signature[14]); + comparison_tests(lesser, greater); + } - test_msg.signature[36] = 36; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[15], greater.signature[15]); + comparison_tests(lesser, greater); + } - test_msg.signature[37] = 37; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[16], greater.signature[16]); + comparison_tests(lesser, greater); + } - test_msg.signature[38] = 38; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[17], greater.signature[17]); + comparison_tests(lesser, greater); + } - test_msg.signature[39] = 39; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[18], greater.signature[18]); + comparison_tests(lesser, greater); + } - test_msg.signature[40] = 40; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[19], greater.signature[19]); + comparison_tests(lesser, greater); + } - test_msg.signature[41] = 41; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[20], greater.signature[20]); + comparison_tests(lesser, greater); + } - test_msg.signature[42] = 42; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[21], greater.signature[21]); + comparison_tests(lesser, greater); + } - test_msg.signature[43] = 43; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[22], greater.signature[22]); + comparison_tests(lesser, greater); + } - test_msg.signature[44] = 44; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[23], greater.signature[23]); + comparison_tests(lesser, greater); + } - test_msg.signature[45] = 45; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[24], greater.signature[24]); + comparison_tests(lesser, greater); + } - test_msg.signature[46] = 46; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[25], greater.signature[25]); + comparison_tests(lesser, greater); + } - test_msg.signature[47] = 47; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[26], greater.signature[26]); + comparison_tests(lesser, greater); + } - test_msg.signature[48] = 48; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[27], greater.signature[27]); + comparison_tests(lesser, greater); + } - test_msg.signature[49] = 49; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[28], greater.signature[28]); + comparison_tests(lesser, greater); + } - test_msg.signature[50] = 50; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[29], greater.signature[29]); + comparison_tests(lesser, greater); + } - test_msg.signature[51] = 51; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[30], greater.signature[30]); + comparison_tests(lesser, greater); + } - test_msg.signature[52] = 52; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[31], greater.signature[31]); + comparison_tests(lesser, greater); + } - test_msg.signature[53] = 53; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[32], greater.signature[32]); + comparison_tests(lesser, greater); + } - test_msg.signature[54] = 54; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[33], greater.signature[33]); + comparison_tests(lesser, greater); + } - test_msg.signature[55] = 55; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[34], greater.signature[34]); + comparison_tests(lesser, greater); + } - test_msg.signature[56] = 56; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[35], greater.signature[35]); + comparison_tests(lesser, greater); + } - test_msg.signature[57] = 57; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[36], greater.signature[36]); + comparison_tests(lesser, greater); + } - test_msg.signature[58] = 58; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[37], greater.signature[37]); + comparison_tests(lesser, greater); + } - test_msg.signature[59] = 59; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[38], greater.signature[38]); + comparison_tests(lesser, greater); + } - test_msg.signature[60] = 60; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[39], greater.signature[39]); + comparison_tests(lesser, greater); + } - test_msg.signature[61] = 61; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[40], greater.signature[40]); + comparison_tests(lesser, greater); + } - test_msg.signature[62] = 62; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[41], greater.signature[41]); + comparison_tests(lesser, greater); + } - test_msg.signature[63] = 63; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[42], greater.signature[42]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[0] = 5000; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[43], greater.signature[43]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[1] = 5234; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[44], greater.signature[44]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[2] = 5468; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[45], greater.signature[45]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[3] = 5702; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[46], greater.signature[46]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[4] = 5936; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[47], greater.signature[47]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[5] = 6170; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[48], greater.signature[48]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[6] = 6404; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[49], greater.signature[49]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[7] = 6638; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[50], greater.signature[50]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[8] = 6872; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[51], greater.signature[51]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[9] = 7106; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[52], greater.signature[52]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[10] = 7340; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[53], greater.signature[53]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[11] = 7574; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[54], greater.signature[54]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[12] = 7808; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[55], greater.signature[55]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[13] = 8042; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[56], greater.signature[56]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[14] = 8276; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[57], greater.signature[57]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[15] = 8510; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[58], greater.signature[58]); + comparison_tests(lesser, greater); + } - test_msg.signed_messages[16] = 8744; + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[59], greater.signature[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[60], greater.signature[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[61], greater.signature[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[62], greater.signature[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signature[63], greater.signature[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[0], greater.signed_messages[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[1], greater.signed_messages[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[2], greater.signed_messages[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[3], greater.signed_messages[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[4], greater.signed_messages[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[5], greater.signed_messages[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[6], greater.signed_messages[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[7], greater.signed_messages[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[8], greater.signed_messages[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[9], greater.signed_messages[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[10], + greater.signed_messages[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[11], + greater.signed_messages[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[12], + greater.signed_messages[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[13], + greater.signed_messages[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[14], + greater.signed_messages[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[15], + greater.signed_messages[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[16], + greater.signed_messages[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[17], + greater.signed_messages[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[18], + greater.signed_messages[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[19], + greater.signed_messages[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[20], + greater.signed_messages[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[21], + greater.signed_messages[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[22], + greater.signed_messages[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[23], + greater.signed_messages[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.signed_messages[24], + greater.signed_messages[24]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ed25519_signature_dep_b_t lesser = info.test_msg; + sbp_msg_ed25519_signature_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.stream_counter, greater.stream_counter); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgEd25519SignatureDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_ED25519_SIGNATURE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ed25519_signature_dep_b_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ed25519_signature_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); - test_msg.signed_messages[17] = 8978; + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} - test_msg.signed_messages[18] = 9212; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); - test_msg.signed_messages[19] = 9446; + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ed25519_signature_dep_b, info.test_msg); - test_msg.signed_messages[20] = 9680; + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ed25519_signature_dep_b, info.test_msg); +} - test_msg.signed_messages[21] = 9914; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} - test_msg.signed_messages[22] = 10148; +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.signed_messages[23] = 10382; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.signed_messages[24] = 10616; - test_msg.stream_counter = 1; + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - EXPECT_EQ(send_message(66, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[186]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 186); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 186), 0); +} - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ed25519_signature_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 186); + EXPECT_EQ(msg, info.test_msg); +} - while (dummy_rd_ < dummy_wr_) { - process(); +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.fingerprint[0], 100) - << "incorrect value for last_msg_.fingerprint[0], expected 100, is " - << last_msg_.fingerprint[0]; - EXPECT_EQ(last_msg_.fingerprint[1], 101) - << "incorrect value for last_msg_.fingerprint[1], expected 101, is " - << last_msg_.fingerprint[1]; - EXPECT_EQ(last_msg_.fingerprint[2], 102) - << "incorrect value for last_msg_.fingerprint[2], expected 102, is " - << last_msg_.fingerprint[2]; - EXPECT_EQ(last_msg_.fingerprint[3], 103) - << "incorrect value for last_msg_.fingerprint[3], expected 103, is " - << last_msg_.fingerprint[3]; - EXPECT_EQ(last_msg_.fingerprint[4], 104) - << "incorrect value for last_msg_.fingerprint[4], expected 104, is " - << last_msg_.fingerprint[4]; - EXPECT_EQ(last_msg_.fingerprint[5], 105) - << "incorrect value for last_msg_.fingerprint[5], expected 105, is " - << last_msg_.fingerprint[5]; - EXPECT_EQ(last_msg_.fingerprint[6], 106) - << "incorrect value for last_msg_.fingerprint[6], expected 106, is " - << last_msg_.fingerprint[6]; - EXPECT_EQ(last_msg_.fingerprint[7], 107) - << "incorrect value for last_msg_.fingerprint[7], expected 107, is " - << last_msg_.fingerprint[7]; - EXPECT_EQ(last_msg_.fingerprint[8], 108) - << "incorrect value for last_msg_.fingerprint[8], expected 108, is " - << last_msg_.fingerprint[8]; - EXPECT_EQ(last_msg_.fingerprint[9], 109) - << "incorrect value for last_msg_.fingerprint[9], expected 109, is " - << last_msg_.fingerprint[9]; - EXPECT_EQ(last_msg_.fingerprint[10], 110) - << "incorrect value for last_msg_.fingerprint[10], expected 110, is " - << last_msg_.fingerprint[10]; - EXPECT_EQ(last_msg_.fingerprint[11], 111) - << "incorrect value for last_msg_.fingerprint[11], expected 111, is " - << last_msg_.fingerprint[11]; - EXPECT_EQ(last_msg_.fingerprint[12], 112) - << "incorrect value for last_msg_.fingerprint[12], expected 112, is " - << last_msg_.fingerprint[12]; - EXPECT_EQ(last_msg_.fingerprint[13], 113) - << "incorrect value for last_msg_.fingerprint[13], expected 113, is " - << last_msg_.fingerprint[13]; - EXPECT_EQ(last_msg_.fingerprint[14], 114) - << "incorrect value for last_msg_.fingerprint[14], expected 114, is " - << last_msg_.fingerprint[14]; - EXPECT_EQ(last_msg_.fingerprint[15], 115) - << "incorrect value for last_msg_.fingerprint[15], expected 115, is " - << last_msg_.fingerprint[15]; - EXPECT_EQ(last_msg_.fingerprint[16], 116) - << "incorrect value for last_msg_.fingerprint[16], expected 116, is " - << last_msg_.fingerprint[16]; - EXPECT_EQ(last_msg_.fingerprint[17], 117) - << "incorrect value for last_msg_.fingerprint[17], expected 117, is " - << last_msg_.fingerprint[17]; - EXPECT_EQ(last_msg_.fingerprint[18], 118) - << "incorrect value for last_msg_.fingerprint[18], expected 118, is " - << last_msg_.fingerprint[18]; - EXPECT_EQ(last_msg_.fingerprint[19], 119) - << "incorrect value for last_msg_.fingerprint[19], expected 119, is " - << last_msg_.fingerprint[19]; - EXPECT_EQ(last_msg_.n_signed_messages, 25) - << "incorrect value for last_msg_.n_signed_messages, expected 25, is " - << last_msg_.n_signed_messages; - EXPECT_EQ(last_msg_.on_demand_counter, 0) - << "incorrect value for last_msg_.on_demand_counter, expected 0, is " - << last_msg_.on_demand_counter; - EXPECT_EQ(last_msg_.signature[0], 0) - << "incorrect value for last_msg_.signature[0], expected 0, is " - << last_msg_.signature[0]; - EXPECT_EQ(last_msg_.signature[1], 1) - << "incorrect value for last_msg_.signature[1], expected 1, is " - << last_msg_.signature[1]; - EXPECT_EQ(last_msg_.signature[2], 2) - << "incorrect value for last_msg_.signature[2], expected 2, is " - << last_msg_.signature[2]; - EXPECT_EQ(last_msg_.signature[3], 3) - << "incorrect value for last_msg_.signature[3], expected 3, is " - << last_msg_.signature[3]; - EXPECT_EQ(last_msg_.signature[4], 4) - << "incorrect value for last_msg_.signature[4], expected 4, is " - << last_msg_.signature[4]; - EXPECT_EQ(last_msg_.signature[5], 5) - << "incorrect value for last_msg_.signature[5], expected 5, is " - << last_msg_.signature[5]; - EXPECT_EQ(last_msg_.signature[6], 6) - << "incorrect value for last_msg_.signature[6], expected 6, is " - << last_msg_.signature[6]; - EXPECT_EQ(last_msg_.signature[7], 7) - << "incorrect value for last_msg_.signature[7], expected 7, is " - << last_msg_.signature[7]; - EXPECT_EQ(last_msg_.signature[8], 8) - << "incorrect value for last_msg_.signature[8], expected 8, is " - << last_msg_.signature[8]; - EXPECT_EQ(last_msg_.signature[9], 9) - << "incorrect value for last_msg_.signature[9], expected 9, is " - << last_msg_.signature[9]; - EXPECT_EQ(last_msg_.signature[10], 10) - << "incorrect value for last_msg_.signature[10], expected 10, is " - << last_msg_.signature[10]; - EXPECT_EQ(last_msg_.signature[11], 11) - << "incorrect value for last_msg_.signature[11], expected 11, is " - << last_msg_.signature[11]; - EXPECT_EQ(last_msg_.signature[12], 12) - << "incorrect value for last_msg_.signature[12], expected 12, is " - << last_msg_.signature[12]; - EXPECT_EQ(last_msg_.signature[13], 13) - << "incorrect value for last_msg_.signature[13], expected 13, is " - << last_msg_.signature[13]; - EXPECT_EQ(last_msg_.signature[14], 14) - << "incorrect value for last_msg_.signature[14], expected 14, is " - << last_msg_.signature[14]; - EXPECT_EQ(last_msg_.signature[15], 15) - << "incorrect value for last_msg_.signature[15], expected 15, is " - << last_msg_.signature[15]; - EXPECT_EQ(last_msg_.signature[16], 16) - << "incorrect value for last_msg_.signature[16], expected 16, is " - << last_msg_.signature[16]; - EXPECT_EQ(last_msg_.signature[17], 17) - << "incorrect value for last_msg_.signature[17], expected 17, is " - << last_msg_.signature[17]; - EXPECT_EQ(last_msg_.signature[18], 18) - << "incorrect value for last_msg_.signature[18], expected 18, is " - << last_msg_.signature[18]; - EXPECT_EQ(last_msg_.signature[19], 19) - << "incorrect value for last_msg_.signature[19], expected 19, is " - << last_msg_.signature[19]; - EXPECT_EQ(last_msg_.signature[20], 20) - << "incorrect value for last_msg_.signature[20], expected 20, is " - << last_msg_.signature[20]; - EXPECT_EQ(last_msg_.signature[21], 21) - << "incorrect value for last_msg_.signature[21], expected 21, is " - << last_msg_.signature[21]; - EXPECT_EQ(last_msg_.signature[22], 22) - << "incorrect value for last_msg_.signature[22], expected 22, is " - << last_msg_.signature[22]; - EXPECT_EQ(last_msg_.signature[23], 23) - << "incorrect value for last_msg_.signature[23], expected 23, is " - << last_msg_.signature[23]; - EXPECT_EQ(last_msg_.signature[24], 24) - << "incorrect value for last_msg_.signature[24], expected 24, is " - << last_msg_.signature[24]; - EXPECT_EQ(last_msg_.signature[25], 25) - << "incorrect value for last_msg_.signature[25], expected 25, is " - << last_msg_.signature[25]; - EXPECT_EQ(last_msg_.signature[26], 26) - << "incorrect value for last_msg_.signature[26], expected 26, is " - << last_msg_.signature[26]; - EXPECT_EQ(last_msg_.signature[27], 27) - << "incorrect value for last_msg_.signature[27], expected 27, is " - << last_msg_.signature[27]; - EXPECT_EQ(last_msg_.signature[28], 28) - << "incorrect value for last_msg_.signature[28], expected 28, is " - << last_msg_.signature[28]; - EXPECT_EQ(last_msg_.signature[29], 29) - << "incorrect value for last_msg_.signature[29], expected 29, is " - << last_msg_.signature[29]; - EXPECT_EQ(last_msg_.signature[30], 30) - << "incorrect value for last_msg_.signature[30], expected 30, is " - << last_msg_.signature[30]; - EXPECT_EQ(last_msg_.signature[31], 31) - << "incorrect value for last_msg_.signature[31], expected 31, is " - << last_msg_.signature[31]; - EXPECT_EQ(last_msg_.signature[32], 32) - << "incorrect value for last_msg_.signature[32], expected 32, is " - << last_msg_.signature[32]; - EXPECT_EQ(last_msg_.signature[33], 33) - << "incorrect value for last_msg_.signature[33], expected 33, is " - << last_msg_.signature[33]; - EXPECT_EQ(last_msg_.signature[34], 34) - << "incorrect value for last_msg_.signature[34], expected 34, is " - << last_msg_.signature[34]; - EXPECT_EQ(last_msg_.signature[35], 35) - << "incorrect value for last_msg_.signature[35], expected 35, is " - << last_msg_.signature[35]; - EXPECT_EQ(last_msg_.signature[36], 36) - << "incorrect value for last_msg_.signature[36], expected 36, is " - << last_msg_.signature[36]; - EXPECT_EQ(last_msg_.signature[37], 37) - << "incorrect value for last_msg_.signature[37], expected 37, is " - << last_msg_.signature[37]; - EXPECT_EQ(last_msg_.signature[38], 38) - << "incorrect value for last_msg_.signature[38], expected 38, is " - << last_msg_.signature[38]; - EXPECT_EQ(last_msg_.signature[39], 39) - << "incorrect value for last_msg_.signature[39], expected 39, is " - << last_msg_.signature[39]; - EXPECT_EQ(last_msg_.signature[40], 40) - << "incorrect value for last_msg_.signature[40], expected 40, is " - << last_msg_.signature[40]; - EXPECT_EQ(last_msg_.signature[41], 41) - << "incorrect value for last_msg_.signature[41], expected 41, is " - << last_msg_.signature[41]; - EXPECT_EQ(last_msg_.signature[42], 42) - << "incorrect value for last_msg_.signature[42], expected 42, is " - << last_msg_.signature[42]; - EXPECT_EQ(last_msg_.signature[43], 43) - << "incorrect value for last_msg_.signature[43], expected 43, is " - << last_msg_.signature[43]; - EXPECT_EQ(last_msg_.signature[44], 44) - << "incorrect value for last_msg_.signature[44], expected 44, is " - << last_msg_.signature[44]; - EXPECT_EQ(last_msg_.signature[45], 45) - << "incorrect value for last_msg_.signature[45], expected 45, is " - << last_msg_.signature[45]; - EXPECT_EQ(last_msg_.signature[46], 46) - << "incorrect value for last_msg_.signature[46], expected 46, is " - << last_msg_.signature[46]; - EXPECT_EQ(last_msg_.signature[47], 47) - << "incorrect value for last_msg_.signature[47], expected 47, is " - << last_msg_.signature[47]; - EXPECT_EQ(last_msg_.signature[48], 48) - << "incorrect value for last_msg_.signature[48], expected 48, is " - << last_msg_.signature[48]; - EXPECT_EQ(last_msg_.signature[49], 49) - << "incorrect value for last_msg_.signature[49], expected 49, is " - << last_msg_.signature[49]; - EXPECT_EQ(last_msg_.signature[50], 50) - << "incorrect value for last_msg_.signature[50], expected 50, is " - << last_msg_.signature[50]; - EXPECT_EQ(last_msg_.signature[51], 51) - << "incorrect value for last_msg_.signature[51], expected 51, is " - << last_msg_.signature[51]; - EXPECT_EQ(last_msg_.signature[52], 52) - << "incorrect value for last_msg_.signature[52], expected 52, is " - << last_msg_.signature[52]; - EXPECT_EQ(last_msg_.signature[53], 53) - << "incorrect value for last_msg_.signature[53], expected 53, is " - << last_msg_.signature[53]; - EXPECT_EQ(last_msg_.signature[54], 54) - << "incorrect value for last_msg_.signature[54], expected 54, is " - << last_msg_.signature[54]; - EXPECT_EQ(last_msg_.signature[55], 55) - << "incorrect value for last_msg_.signature[55], expected 55, is " - << last_msg_.signature[55]; - EXPECT_EQ(last_msg_.signature[56], 56) - << "incorrect value for last_msg_.signature[56], expected 56, is " - << last_msg_.signature[56]; - EXPECT_EQ(last_msg_.signature[57], 57) - << "incorrect value for last_msg_.signature[57], expected 57, is " - << last_msg_.signature[57]; - EXPECT_EQ(last_msg_.signature[58], 58) - << "incorrect value for last_msg_.signature[58], expected 58, is " - << last_msg_.signature[58]; - EXPECT_EQ(last_msg_.signature[59], 59) - << "incorrect value for last_msg_.signature[59], expected 59, is " - << last_msg_.signature[59]; - EXPECT_EQ(last_msg_.signature[60], 60) - << "incorrect value for last_msg_.signature[60], expected 60, is " - << last_msg_.signature[60]; - EXPECT_EQ(last_msg_.signature[61], 61) - << "incorrect value for last_msg_.signature[61], expected 61, is " - << last_msg_.signature[61]; - EXPECT_EQ(last_msg_.signature[62], 62) - << "incorrect value for last_msg_.signature[62], expected 62, is " - << last_msg_.signature[62]; - EXPECT_EQ(last_msg_.signature[63], 63) - << "incorrect value for last_msg_.signature[63], expected 63, is " - << last_msg_.signature[63]; - EXPECT_EQ(last_msg_.signed_messages[0], 5000) - << "incorrect value for last_msg_.signed_messages[0], expected 5000, is " - << last_msg_.signed_messages[0]; - EXPECT_EQ(last_msg_.signed_messages[1], 5234) - << "incorrect value for last_msg_.signed_messages[1], expected 5234, is " - << last_msg_.signed_messages[1]; - EXPECT_EQ(last_msg_.signed_messages[2], 5468) - << "incorrect value for last_msg_.signed_messages[2], expected 5468, is " - << last_msg_.signed_messages[2]; - EXPECT_EQ(last_msg_.signed_messages[3], 5702) - << "incorrect value for last_msg_.signed_messages[3], expected 5702, is " - << last_msg_.signed_messages[3]; - EXPECT_EQ(last_msg_.signed_messages[4], 5936) - << "incorrect value for last_msg_.signed_messages[4], expected 5936, is " - << last_msg_.signed_messages[4]; - EXPECT_EQ(last_msg_.signed_messages[5], 6170) - << "incorrect value for last_msg_.signed_messages[5], expected 6170, is " - << last_msg_.signed_messages[5]; - EXPECT_EQ(last_msg_.signed_messages[6], 6404) - << "incorrect value for last_msg_.signed_messages[6], expected 6404, is " - << last_msg_.signed_messages[6]; - EXPECT_EQ(last_msg_.signed_messages[7], 6638) - << "incorrect value for last_msg_.signed_messages[7], expected 6638, is " - << last_msg_.signed_messages[7]; - EXPECT_EQ(last_msg_.signed_messages[8], 6872) - << "incorrect value for last_msg_.signed_messages[8], expected 6872, is " - << last_msg_.signed_messages[8]; - EXPECT_EQ(last_msg_.signed_messages[9], 7106) - << "incorrect value for last_msg_.signed_messages[9], expected 7106, is " - << last_msg_.signed_messages[9]; - EXPECT_EQ(last_msg_.signed_messages[10], 7340) - << "incorrect value for last_msg_.signed_messages[10], expected 7340, is " - << last_msg_.signed_messages[10]; - EXPECT_EQ(last_msg_.signed_messages[11], 7574) - << "incorrect value for last_msg_.signed_messages[11], expected 7574, is " - << last_msg_.signed_messages[11]; - EXPECT_EQ(last_msg_.signed_messages[12], 7808) - << "incorrect value for last_msg_.signed_messages[12], expected 7808, is " - << last_msg_.signed_messages[12]; - EXPECT_EQ(last_msg_.signed_messages[13], 8042) - << "incorrect value for last_msg_.signed_messages[13], expected 8042, is " - << last_msg_.signed_messages[13]; - EXPECT_EQ(last_msg_.signed_messages[14], 8276) - << "incorrect value for last_msg_.signed_messages[14], expected 8276, is " - << last_msg_.signed_messages[14]; - EXPECT_EQ(last_msg_.signed_messages[15], 8510) - << "incorrect value for last_msg_.signed_messages[15], expected 8510, is " - << last_msg_.signed_messages[15]; - EXPECT_EQ(last_msg_.signed_messages[16], 8744) - << "incorrect value for last_msg_.signed_messages[16], expected 8744, is " - << last_msg_.signed_messages[16]; - EXPECT_EQ(last_msg_.signed_messages[17], 8978) - << "incorrect value for last_msg_.signed_messages[17], expected 8978, is " - << last_msg_.signed_messages[17]; - EXPECT_EQ(last_msg_.signed_messages[18], 9212) - << "incorrect value for last_msg_.signed_messages[18], expected 9212, is " - << last_msg_.signed_messages[18]; - EXPECT_EQ(last_msg_.signed_messages[19], 9446) - << "incorrect value for last_msg_.signed_messages[19], expected 9446, is " - << last_msg_.signed_messages[19]; - EXPECT_EQ(last_msg_.signed_messages[20], 9680) - << "incorrect value for last_msg_.signed_messages[20], expected 9680, is " - << last_msg_.signed_messages[20]; - EXPECT_EQ(last_msg_.signed_messages[21], 9914) - << "incorrect value for last_msg_.signed_messages[21], expected 9914, is " - << last_msg_.signed_messages[21]; - EXPECT_EQ(last_msg_.signed_messages[22], 10148) - << "incorrect value for last_msg_.signed_messages[22], expected 10148, " - "is " - << last_msg_.signed_messages[22]; - EXPECT_EQ(last_msg_.signed_messages[23], 10382) - << "incorrect value for last_msg_.signed_messages[23], expected 10382, " - "is " - << last_msg_.signed_messages[23]; - EXPECT_EQ(last_msg_.signed_messages[24], 10616) - << "incorrect value for last_msg_.signed_messages[24], expected 10616, " - "is " - << last_msg_.signed_messages[24]; - EXPECT_EQ(last_msg_.stream_counter, 1) - << "incorrect value for last_msg_.stream_counter, expected 1, is " - << last_msg_.stream_counter; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgEd25519SignatureDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_signing_MsgEd25519SignatureDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgEd25519SignatureDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_signing_signing_structs.cc b/c/test/cpp/auto_check_sbp_signing_signing_structs.cc new file mode 100644 index 0000000000..dbe42d263f --- /dev/null +++ b/c/test/cpp/auto_check_sbp_signing_signing_structs.cc @@ -0,0 +1,370 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/signing/test_signing_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_signing_signing_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_signing_signing_structs0() { + assign(test_struct_.day, 130); + assign(test_struct_.hours, 58); + assign(test_struct_.minutes, 5); + assign(test_struct_.month, 64); + assign(test_struct_.ns, 344202884); + assign(test_struct_.seconds, 121); + assign(test_struct_.year, 31718); + } + + struct TestStructInfo { + sbp_utc_time_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_utc_time_t test_struct_{}; + uint8_t encoded_data_[11] = { + 230, 123, 64, 130, 58, 5, 121, 132, 30, 132, 20, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_utc_time_encoded_len(&info.test_struct), 11); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[11]; + EXPECT_EQ( + sbp_utc_time_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + EXPECT_EQ( + sbp_utc_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 11), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_utc_time_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_utc_time_t t{}; + EXPECT_EQ(sbp_utc_time_decode(info.encoded_data, 11, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_utc_time_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_utc_time_t t{}; + EXPECT_EQ(sbp_utc_time_decode(info.encoded_data, 11, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_utc_time_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_utc_time_t t{}; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_utc_time_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_signing_signing_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_signing_signing_structs1() { + assign(test_struct_.data[0], 189); + + assign(test_struct_.data[1], 249); + + assign(test_struct_.data[2], 166); + + assign(test_struct_.data[3], 211); + + assign(test_struct_.data[4], 246); + + assign(test_struct_.data[5], 7); + + assign(test_struct_.data[6], 83); + + assign(test_struct_.data[7], 222); + + assign(test_struct_.data[8], 182); + + assign(test_struct_.data[9], 121); + + assign(test_struct_.data[10], 22); + + assign(test_struct_.data[11], 64); + + assign(test_struct_.data[12], 18); + + assign(test_struct_.data[13], 190); + + assign(test_struct_.data[14], 156); + + assign(test_struct_.data[15], 212); + + assign(test_struct_.data[16], 23); + + assign(test_struct_.data[17], 15); + + assign(test_struct_.data[18], 222); + + assign(test_struct_.data[19], 41); + + assign(test_struct_.data[20], 5); + + assign(test_struct_.data[21], 208); + + assign(test_struct_.data[22], 49); + + assign(test_struct_.data[23], 127); + + assign(test_struct_.data[24], 30); + + assign(test_struct_.data[25], 82); + + assign(test_struct_.data[26], 214); + + assign(test_struct_.data[27], 253); + + assign(test_struct_.data[28], 4); + + assign(test_struct_.data[29], 151); + + assign(test_struct_.data[30], 122); + + assign(test_struct_.data[31], 254); + + assign(test_struct_.data[32], 58); + + assign(test_struct_.data[33], 23); + + assign(test_struct_.data[34], 117); + + assign(test_struct_.data[35], 155); + + assign(test_struct_.data[36], 233); + + assign(test_struct_.data[37], 180); + + assign(test_struct_.data[38], 118); + + assign(test_struct_.data[39], 207); + + assign(test_struct_.data[40], 160); + + assign(test_struct_.data[41], 84); + + assign(test_struct_.data[42], 117); + + assign(test_struct_.data[43], 57); + + assign(test_struct_.data[44], 46); + + assign(test_struct_.data[45], 232); + + assign(test_struct_.data[46], 206); + + assign(test_struct_.data[47], 68); + + assign(test_struct_.data[48], 155); + + assign(test_struct_.data[49], 175); + + assign(test_struct_.data[50], 51); + + assign(test_struct_.data[51], 186); + + assign(test_struct_.data[52], 111); + + assign(test_struct_.data[53], 240); + + assign(test_struct_.data[54], 33); + + assign(test_struct_.data[55], 20); + + assign(test_struct_.data[56], 107); + + assign(test_struct_.data[57], 63); + + assign(test_struct_.data[58], 114); + + assign(test_struct_.data[59], 204); + + assign(test_struct_.data[60], 115); + + assign(test_struct_.data[61], 64); + + assign(test_struct_.data[62], 241); + + assign(test_struct_.data[63], 145); + + assign(test_struct_.data[64], 216); + + assign(test_struct_.data[65], 160); + + assign(test_struct_.data[66], 96); + + assign(test_struct_.data[67], 214); + + assign(test_struct_.data[68], 53); + + assign(test_struct_.data[69], 181); + + assign(test_struct_.data[70], 120); + + assign(test_struct_.data[71], 132); + assign(test_struct_.len, 166); + } + + struct TestStructInfo { + sbp_ecdsa_signature_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_ecdsa_signature_t test_struct_{}; + uint8_t encoded_data_[73] = { + 166, 189, 249, 166, 211, 246, 7, 83, 222, 182, 121, 22, 64, 18, 190, + 156, 212, 23, 15, 222, 41, 5, 208, 49, 127, 30, 82, 214, 253, 4, + 151, 122, 254, 58, 23, 117, 155, 233, 180, 118, 207, 160, 84, 117, 57, + 46, 232, 206, 68, 155, 175, 51, 186, 111, 240, 33, 20, 107, 63, 114, + 204, 115, 64, 241, 145, 216, 160, 96, 214, 53, 181, 120, 132, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_ecdsa_signature_encoded_len(&info.test_struct), 73); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[73]; + EXPECT_EQ(sbp_ecdsa_signature_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 73); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[73]; + EXPECT_EQ(sbp_ecdsa_signature_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 73), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[73]; + for (uint8_t i = 0; i < 73; i++) { + EXPECT_EQ( + sbp_ecdsa_signature_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_ecdsa_signature_t t{}; + EXPECT_EQ(sbp_ecdsa_signature_decode(info.encoded_data, 73, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_ecdsa_signature_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_ecdsa_signature_t t{}; + EXPECT_EQ(sbp_ecdsa_signature_decode(info.encoded_data, 73, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_ecdsa_signature_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_signing_signing_structs1, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_ecdsa_signature_t t{}; + + for (uint8_t i = 0; i < 73; i++) { + EXPECT_EQ(sbp_ecdsa_signature_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_soln_meta_soln_meta_structs.cc b/c/test/cpp/auto_check_sbp_soln_meta_soln_meta_structs.cc new file mode 100644 index 0000000000..efd0865b63 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_soln_meta_soln_meta_structs.cc @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_soln_meta_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0() { + assign(test_struct_.flags, 237); + assign(test_struct_.sensor_type, 102); + } + + struct TestStructInfo { + sbp_solution_input_type_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_solution_input_type_t test_struct_{}; + uint8_t encoded_data_[2] = { + 102, + 237, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_solution_input_type_encoded_len(&info.test_struct), 2); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[2]; + EXPECT_EQ(sbp_solution_input_type_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 2); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + EXPECT_EQ(sbp_solution_input_type_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 2), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[2]; + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ( + sbp_solution_input_type_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_solution_input_type_t t{}; + EXPECT_EQ(sbp_solution_input_type_decode(info.encoded_data, 2, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_solution_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_solution_input_type_t t{}; + EXPECT_EQ(sbp_solution_input_type_decode(info.encoded_data, 2, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_solution_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_solution_input_type_t t{}; + + for (uint8_t i = 0; i < 2; i++) { + EXPECT_EQ(sbp_solution_input_type_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1() { + assign(test_struct_.flags, 54); + } + + struct TestStructInfo { + sbp_gnss_input_type_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gnss_input_type_t test_struct_{}; + uint8_t encoded_data_[1] = { + 54, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gnss_input_type_encoded_len(&info.test_struct), 1); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[1]; + EXPECT_EQ(sbp_gnss_input_type_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + EXPECT_EQ(sbp_gnss_input_type_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 1), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ( + sbp_gnss_input_type_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gnss_input_type_t t{}; + EXPECT_EQ(sbp_gnss_input_type_decode(info.encoded_data, 1, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gnss_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gnss_input_type_t t{}; + EXPECT_EQ(sbp_gnss_input_type_decode(info.encoded_data, 1, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_gnss_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs1, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gnss_input_type_t t{}; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_gnss_input_type_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2() { + assign(test_struct_.flags, 214); + } + + struct TestStructInfo { + sbp_imu_input_type_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_imu_input_type_t test_struct_{}; + uint8_t encoded_data_[1] = { + 214, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_imu_input_type_encoded_len(&info.test_struct), 1); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[1]; + EXPECT_EQ(sbp_imu_input_type_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + EXPECT_EQ(sbp_imu_input_type_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 1), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_imu_input_type_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_imu_input_type_t t{}; + EXPECT_EQ(sbp_imu_input_type_decode(info.encoded_data, 1, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_imu_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_imu_input_type_t t{}; + EXPECT_EQ(sbp_imu_input_type_decode(info.encoded_data, 1, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_imu_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs2, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_imu_input_type_t t{}; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_imu_input_type_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3() { + assign(test_struct_.flags, 230); + } + + struct TestStructInfo { + sbp_odo_input_type_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_odo_input_type_t test_struct_{}; + uint8_t encoded_data_[1] = { + 230, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_odo_input_type_encoded_len(&info.test_struct), 1); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[1]; + EXPECT_EQ(sbp_odo_input_type_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 1); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + EXPECT_EQ(sbp_odo_input_type_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 1), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[1]; + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_odo_input_type_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_odo_input_type_t t{}; + EXPECT_EQ(sbp_odo_input_type_decode(info.encoded_data, 1, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_odo_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_odo_input_type_t t{}; + EXPECT_EQ(sbp_odo_input_type_decode(info.encoded_data, 1, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_odo_input_type_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_soln_meta_soln_meta_structs3, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_odo_input_type_t t{}; + + for (uint8_t i = 0; i < 1; i++) { + EXPECT_EQ(sbp_odo_input_type_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc b/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc new file mode 100644 index 0000000000..8f7eb46947 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc @@ -0,0 +1,2880 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_solution_meta_MsgSolnMeta0 : public ::testing::Test { + public: + Testauto_check_sbp_solution_meta_MsgSolnMeta0() { + assign(test_msg_.age_corrections, 21256); + assign(test_msg_.age_gnss, 3573765977); + assign(test_msg_.hdop, 41156); + assign(test_msg_.n_sol_in, 119); + assign(test_msg_.pdop, 11642); + + assign(test_msg_.sol_in[0].flags, 109); + assign(test_msg_.sol_in[0].sensor_type, 95); + + assign(test_msg_.sol_in[1].flags, 131); + assign(test_msg_.sol_in[1].sensor_type, 86); + + assign(test_msg_.sol_in[2].flags, 70); + assign(test_msg_.sol_in[2].sensor_type, 71); + + assign(test_msg_.sol_in[3].flags, 73); + assign(test_msg_.sol_in[3].sensor_type, 84); + + assign(test_msg_.sol_in[4].flags, 26); + assign(test_msg_.sol_in[4].sensor_type, 131); + + assign(test_msg_.sol_in[5].flags, 247); + assign(test_msg_.sol_in[5].sensor_type, 82); + + assign(test_msg_.sol_in[6].flags, 97); + assign(test_msg_.sol_in[6].sensor_type, 140); + + assign(test_msg_.sol_in[7].flags, 110); + assign(test_msg_.sol_in[7].sensor_type, 115); + + assign(test_msg_.sol_in[8].flags, 253); + assign(test_msg_.sol_in[8].sensor_type, 118); + + assign(test_msg_.sol_in[9].flags, 122); + assign(test_msg_.sol_in[9].sensor_type, 2); + + assign(test_msg_.sol_in[10].flags, 148); + assign(test_msg_.sol_in[10].sensor_type, 186); + + assign(test_msg_.sol_in[11].flags, 148); + assign(test_msg_.sol_in[11].sensor_type, 122); + + assign(test_msg_.sol_in[12].flags, 231); + assign(test_msg_.sol_in[12].sensor_type, 180); + + assign(test_msg_.sol_in[13].flags, 46); + assign(test_msg_.sol_in[13].sensor_type, 68); + + assign(test_msg_.sol_in[14].flags, 102); + assign(test_msg_.sol_in[14].sensor_type, 190); + + assign(test_msg_.sol_in[15].flags, 48); + assign(test_msg_.sol_in[15].sensor_type, 243); + + assign(test_msg_.sol_in[16].flags, 15); + assign(test_msg_.sol_in[16].sensor_type, 192); + + assign(test_msg_.sol_in[17].flags, 89); + assign(test_msg_.sol_in[17].sensor_type, 208); + + assign(test_msg_.sol_in[18].flags, 10); + assign(test_msg_.sol_in[18].sensor_type, 56); + + assign(test_msg_.sol_in[19].flags, 2); + assign(test_msg_.sol_in[19].sensor_type, 245); + + assign(test_msg_.sol_in[20].flags, 201); + assign(test_msg_.sol_in[20].sensor_type, 254); + + assign(test_msg_.sol_in[21].flags, 32); + assign(test_msg_.sol_in[21].sensor_type, 120); + + assign(test_msg_.sol_in[22].flags, 2); + assign(test_msg_.sol_in[22].sensor_type, 126); + + assign(test_msg_.sol_in[23].flags, 161); + assign(test_msg_.sol_in[23].sensor_type, 83); + + assign(test_msg_.sol_in[24].flags, 123); + assign(test_msg_.sol_in[24].sensor_type, 238); + + assign(test_msg_.sol_in[25].flags, 230); + assign(test_msg_.sol_in[25].sensor_type, 102); + + assign(test_msg_.sol_in[26].flags, 190); + assign(test_msg_.sol_in[26].sensor_type, 76); + + assign(test_msg_.sol_in[27].flags, 182); + assign(test_msg_.sol_in[27].sensor_type, 225); + + assign(test_msg_.sol_in[28].flags, 228); + assign(test_msg_.sol_in[28].sensor_type, 207); + + assign(test_msg_.sol_in[29].flags, 218); + assign(test_msg_.sol_in[29].sensor_type, 7); + + assign(test_msg_.sol_in[30].flags, 89); + assign(test_msg_.sol_in[30].sensor_type, 117); + + assign(test_msg_.sol_in[31].flags, 191); + assign(test_msg_.sol_in[31].sensor_type, 29); + + assign(test_msg_.sol_in[32].flags, 248); + assign(test_msg_.sol_in[32].sensor_type, 56); + + assign(test_msg_.sol_in[33].flags, 255); + assign(test_msg_.sol_in[33].sensor_type, 185); + + assign(test_msg_.sol_in[34].flags, 18); + assign(test_msg_.sol_in[34].sensor_type, 46); + + assign(test_msg_.sol_in[35].flags, 142); + assign(test_msg_.sol_in[35].sensor_type, 72); + + assign(test_msg_.sol_in[36].flags, 113); + assign(test_msg_.sol_in[36].sensor_type, 82); + + assign(test_msg_.sol_in[37].flags, 4); + assign(test_msg_.sol_in[37].sensor_type, 26); + + assign(test_msg_.sol_in[38].flags, 254); + assign(test_msg_.sol_in[38].sensor_type, 172); + + assign(test_msg_.sol_in[39].flags, 136); + assign(test_msg_.sol_in[39].sensor_type, 178); + + assign(test_msg_.sol_in[40].flags, 115); + assign(test_msg_.sol_in[40].sensor_type, 113); + + assign(test_msg_.sol_in[41].flags, 193); + assign(test_msg_.sol_in[41].sensor_type, 58); + + assign(test_msg_.sol_in[42].flags, 227); + assign(test_msg_.sol_in[42].sensor_type, 89); + + assign(test_msg_.sol_in[43].flags, 246); + assign(test_msg_.sol_in[43].sensor_type, 182); + + assign(test_msg_.sol_in[44].flags, 77); + assign(test_msg_.sol_in[44].sensor_type, 76); + + assign(test_msg_.sol_in[45].flags, 245); + assign(test_msg_.sol_in[45].sensor_type, 108); + + assign(test_msg_.sol_in[46].flags, 31); + assign(test_msg_.sol_in[46].sensor_type, 41); + + assign(test_msg_.sol_in[47].flags, 124); + assign(test_msg_.sol_in[47].sensor_type, 70); + + assign(test_msg_.sol_in[48].flags, 145); + assign(test_msg_.sol_in[48].sensor_type, 249); + + assign(test_msg_.sol_in[49].flags, 78); + assign(test_msg_.sol_in[49].sensor_type, 15); + + assign(test_msg_.sol_in[50].flags, 38); + assign(test_msg_.sol_in[50].sensor_type, 228); + + assign(test_msg_.sol_in[51].flags, 129); + assign(test_msg_.sol_in[51].sensor_type, 241); + + assign(test_msg_.sol_in[52].flags, 176); + assign(test_msg_.sol_in[52].sensor_type, 8); + + assign(test_msg_.sol_in[53].flags, 72); + assign(test_msg_.sol_in[53].sensor_type, 251); + + assign(test_msg_.sol_in[54].flags, 80); + assign(test_msg_.sol_in[54].sensor_type, 248); + + assign(test_msg_.sol_in[55].flags, 244); + assign(test_msg_.sol_in[55].sensor_type, 115); + + assign(test_msg_.sol_in[56].flags, 145); + assign(test_msg_.sol_in[56].sensor_type, 231); + + assign(test_msg_.sol_in[57].flags, 190); + assign(test_msg_.sol_in[57].sensor_type, 191); + + assign(test_msg_.sol_in[58].flags, 168); + assign(test_msg_.sol_in[58].sensor_type, 178); + + assign(test_msg_.sol_in[59].flags, 233); + assign(test_msg_.sol_in[59].sensor_type, 89); + + assign(test_msg_.sol_in[60].flags, 176); + assign(test_msg_.sol_in[60].sensor_type, 69); + + assign(test_msg_.sol_in[61].flags, 140); + assign(test_msg_.sol_in[61].sensor_type, 174); + + assign(test_msg_.sol_in[62].flags, 141); + assign(test_msg_.sol_in[62].sensor_type, 182); + + assign(test_msg_.sol_in[63].flags, 82); + assign(test_msg_.sol_in[63].sensor_type, 81); + + assign(test_msg_.sol_in[64].flags, 79); + assign(test_msg_.sol_in[64].sensor_type, 92); + + assign(test_msg_.sol_in[65].flags, 223); + assign(test_msg_.sol_in[65].sensor_type, 101); + + assign(test_msg_.sol_in[66].flags, 64); + assign(test_msg_.sol_in[66].sensor_type, 100); + + assign(test_msg_.sol_in[67].flags, 215); + assign(test_msg_.sol_in[67].sensor_type, 184); + + assign(test_msg_.sol_in[68].flags, 37); + assign(test_msg_.sol_in[68].sensor_type, 124); + + assign(test_msg_.sol_in[69].flags, 227); + assign(test_msg_.sol_in[69].sensor_type, 21); + + assign(test_msg_.sol_in[70].flags, 102); + assign(test_msg_.sol_in[70].sensor_type, 135); + + assign(test_msg_.sol_in[71].flags, 36); + assign(test_msg_.sol_in[71].sensor_type, 72); + + assign(test_msg_.sol_in[72].flags, 56); + assign(test_msg_.sol_in[72].sensor_type, 219); + + assign(test_msg_.sol_in[73].flags, 90); + assign(test_msg_.sol_in[73].sensor_type, 146); + + assign(test_msg_.sol_in[74].flags, 104); + assign(test_msg_.sol_in[74].sensor_type, 219); + + assign(test_msg_.sol_in[75].flags, 102); + assign(test_msg_.sol_in[75].sensor_type, 227); + + assign(test_msg_.sol_in[76].flags, 12); + assign(test_msg_.sol_in[76].sensor_type, 83); + + assign(test_msg_.sol_in[77].flags, 122); + assign(test_msg_.sol_in[77].sensor_type, 41); + + assign(test_msg_.sol_in[78].flags, 94); + assign(test_msg_.sol_in[78].sensor_type, 173); + + assign(test_msg_.sol_in[79].flags, 174); + assign(test_msg_.sol_in[79].sensor_type, 1); + + assign(test_msg_.sol_in[80].flags, 130); + assign(test_msg_.sol_in[80].sensor_type, 134); + + assign(test_msg_.sol_in[81].flags, 237); + assign(test_msg_.sol_in[81].sensor_type, 104); + + assign(test_msg_.sol_in[82].flags, 249); + assign(test_msg_.sol_in[82].sensor_type, 116); + + assign(test_msg_.sol_in[83].flags, 230); + assign(test_msg_.sol_in[83].sensor_type, 107); + + assign(test_msg_.sol_in[84].flags, 123); + assign(test_msg_.sol_in[84].sensor_type, 130); + + assign(test_msg_.sol_in[85].flags, 162); + assign(test_msg_.sol_in[85].sensor_type, 25); + + assign(test_msg_.sol_in[86].flags, 223); + assign(test_msg_.sol_in[86].sensor_type, 57); + + assign(test_msg_.sol_in[87].flags, 174); + assign(test_msg_.sol_in[87].sensor_type, 193); + + assign(test_msg_.sol_in[88].flags, 193); + assign(test_msg_.sol_in[88].sensor_type, 146); + + assign(test_msg_.sol_in[89].flags, 44); + assign(test_msg_.sol_in[89].sensor_type, 239); + + assign(test_msg_.sol_in[90].flags, 197); + assign(test_msg_.sol_in[90].sensor_type, 246); + + assign(test_msg_.sol_in[91].flags, 80); + assign(test_msg_.sol_in[91].sensor_type, 214); + + assign(test_msg_.sol_in[92].flags, 100); + assign(test_msg_.sol_in[92].sensor_type, 83); + + assign(test_msg_.sol_in[93].flags, 72); + assign(test_msg_.sol_in[93].sensor_type, 66); + + assign(test_msg_.sol_in[94].flags, 137); + assign(test_msg_.sol_in[94].sensor_type, 133); + + assign(test_msg_.sol_in[95].flags, 82); + assign(test_msg_.sol_in[95].sensor_type, 140); + + assign(test_msg_.sol_in[96].flags, 2); + assign(test_msg_.sol_in[96].sensor_type, 2); + + assign(test_msg_.sol_in[97].flags, 9); + assign(test_msg_.sol_in[97].sensor_type, 96); + + assign(test_msg_.sol_in[98].flags, 158); + assign(test_msg_.sol_in[98].sensor_type, 96); + + assign(test_msg_.sol_in[99].flags, 97); + assign(test_msg_.sol_in[99].sensor_type, 134); + + assign(test_msg_.sol_in[100].flags, 129); + assign(test_msg_.sol_in[100].sensor_type, 43); + + assign(test_msg_.sol_in[101].flags, 25); + assign(test_msg_.sol_in[101].sensor_type, 141); + + assign(test_msg_.sol_in[102].flags, 200); + assign(test_msg_.sol_in[102].sensor_type, 183); + + assign(test_msg_.sol_in[103].flags, 57); + assign(test_msg_.sol_in[103].sensor_type, 214); + + assign(test_msg_.sol_in[104].flags, 103); + assign(test_msg_.sol_in[104].sensor_type, 248); + + assign(test_msg_.sol_in[105].flags, 65); + assign(test_msg_.sol_in[105].sensor_type, 222); + + assign(test_msg_.sol_in[106].flags, 15); + assign(test_msg_.sol_in[106].sensor_type, 195); + + assign(test_msg_.sol_in[107].flags, 21); + assign(test_msg_.sol_in[107].sensor_type, 244); + + assign(test_msg_.sol_in[108].flags, 46); + assign(test_msg_.sol_in[108].sensor_type, 180); + + assign(test_msg_.sol_in[109].flags, 130); + assign(test_msg_.sol_in[109].sensor_type, 140); + + assign(test_msg_.sol_in[110].flags, 17); + assign(test_msg_.sol_in[110].sensor_type, 36); + + assign(test_msg_.sol_in[111].flags, 209); + assign(test_msg_.sol_in[111].sensor_type, 194); + + assign(test_msg_.sol_in[112].flags, 254); + assign(test_msg_.sol_in[112].sensor_type, 65); + + assign(test_msg_.sol_in[113].flags, 103); + assign(test_msg_.sol_in[113].sensor_type, 115); + + assign(test_msg_.sol_in[114].flags, 129); + assign(test_msg_.sol_in[114].sensor_type, 152); + + assign(test_msg_.sol_in[115].flags, 235); + assign(test_msg_.sol_in[115].sensor_type, 234); + + assign(test_msg_.sol_in[116].flags, 234); + assign(test_msg_.sol_in[116].sensor_type, 194); + + assign(test_msg_.sol_in[117].flags, 201); + assign(test_msg_.sol_in[117].sensor_type, 170); + + assign(test_msg_.sol_in[118].flags, 154); + assign(test_msg_.sol_in[118].sensor_type, 210); + assign(test_msg_.tow, 3628191792); + assign(test_msg_.vdop, 58512); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_soln_meta_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_soln_meta_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSolnMeta, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_soln_meta_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSolnMeta); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->soln_meta, sizeof(msg->soln_meta)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_soln_meta_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.soln_meta, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSolnMeta); + info.sender_id = 15360; + info.preamble = 0x55; + info.crc = 0xf796; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 254; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_soln_meta_t &lesser, + const sbp_msg_soln_meta_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_soln_meta_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_soln_meta_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_soln_meta_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_soln_meta_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSolnMeta, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSolnMeta, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSolnMeta, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSolnMeta, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_soln_meta_t test_msg_{}; + uint8_t encoded_frame_[254 + 8] = { + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, 144, + 228, 8, 83, 89, 87, 3, 213, 95, 109, 86, 131, 71, 70, 84, 73, + 131, 26, 82, 247, 140, 97, 115, 110, 118, 253, 2, 122, 186, 148, 122, + 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, 208, 89, 56, 10, + 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, 238, 123, 102, 230, 76, + 190, 225, 182, 207, 228, 7, 218, 117, 89, 29, 191, 56, 248, 185, 255, + 46, 18, 72, 142, 82, 113, 26, 4, 172, 254, 178, 136, 113, 115, 58, + 193, 89, 227, 182, 246, 76, 77, 108, 245, 41, 31, 70, 124, 249, 145, + 15, 78, 228, 38, 241, 129, 8, 176, 251, 72, 248, 80, 115, 244, 231, + 145, 191, 190, 178, 168, 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, + 92, 79, 101, 223, 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, + 36, 219, 56, 146, 90, 219, 104, 227, 102, 83, 12, 41, 122, 173, 94, + 1, 174, 134, 130, 104, 237, 116, 249, 107, 230, 130, 123, 25, 162, 57, + 223, 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, 100, 66, 72, + 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, 141, + 25, 183, 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, 180, 46, + 140, 130, 36, 17, 194, 209, 65, 254, 115, 103, 152, 129, 234, 235, 194, + 234, 170, 201, 210, 154, 150, 247, + }; + uint8_t encoded_payload_[254] = { + 48, 208, 65, 216, 122, 45, 196, 160, 144, 228, 8, 83, 89, 87, 3, + 213, 95, 109, 86, 131, 71, 70, 84, 73, 131, 26, 82, 247, 140, 97, + 115, 110, 118, 253, 2, 122, 186, 148, 122, 148, 180, 231, 68, 46, 190, + 102, 243, 48, 192, 15, 208, 89, 56, 10, 245, 2, 254, 201, 120, 32, + 126, 2, 83, 161, 238, 123, 102, 230, 76, 190, 225, 182, 207, 228, 7, + 218, 117, 89, 29, 191, 56, 248, 185, 255, 46, 18, 72, 142, 82, 113, + 26, 4, 172, 254, 178, 136, 113, 115, 58, 193, 89, 227, 182, 246, 76, + 77, 108, 245, 41, 31, 70, 124, 249, 145, 15, 78, 228, 38, 241, 129, + 8, 176, 251, 72, 248, 80, 115, 244, 231, 145, 191, 190, 178, 168, 89, + 233, 69, 176, 174, 140, 182, 141, 81, 82, 92, 79, 101, 223, 100, 64, + 184, 215, 124, 37, 21, 227, 135, 102, 72, 36, 219, 56, 146, 90, 219, + 104, 227, 102, 83, 12, 41, 122, 173, 94, 1, 174, 134, 130, 104, 237, + 116, 249, 107, 230, 130, 123, 25, 162, 57, 223, 193, 174, 146, 193, 239, + 44, 246, 197, 214, 80, 83, 100, 66, 72, 133, 137, 140, 82, 2, 2, + 96, 9, 96, 158, 134, 97, 43, 129, 141, 25, 183, 200, 214, 57, 248, + 103, 222, 65, 195, 15, 244, 21, 180, 46, 140, 130, 36, 17, 194, 209, + 65, 254, 115, 103, 152, 129, 234, 235, 194, 234, 170, 201, 210, 154, + }; +}; + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_soln_meta_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSolnMeta, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_soln_meta_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgSolnMeta, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + EXPECT_EQ( + sbp_msg_soln_meta_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + for (uint8_t i = 0; i < 254; i++) { + EXPECT_EQ(sbp_msg_soln_meta_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_soln_meta_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSolnMeta, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_t msg{}; + + EXPECT_EQ(sbp_msg_soln_meta_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_soln_meta_t t{}; + return sbp_msg_soln_meta_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_soln_meta_t t{}; + t.n_sol_in = 1; + return sbp_msg_soln_meta_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_soln_meta_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_soln_meta_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSolnMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSolnMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSolnMeta, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.age_corrections, greater.age_corrections); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.age_gnss, greater.age_gnss); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.n_sol_in, greater.n_sol_in); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[0].flags, greater.sol_in[0].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[0].sensor_type, + greater.sol_in[0].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[1].flags, greater.sol_in[1].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[1].sensor_type, + greater.sol_in[1].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[2].flags, greater.sol_in[2].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[2].sensor_type, + greater.sol_in[2].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[3].flags, greater.sol_in[3].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[3].sensor_type, + greater.sol_in[3].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[4].flags, greater.sol_in[4].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[4].sensor_type, + greater.sol_in[4].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[5].flags, greater.sol_in[5].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[5].sensor_type, + greater.sol_in[5].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[6].flags, greater.sol_in[6].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[6].sensor_type, + greater.sol_in[6].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[7].flags, greater.sol_in[7].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[7].sensor_type, + greater.sol_in[7].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[8].flags, greater.sol_in[8].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[8].sensor_type, + greater.sol_in[8].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[9].flags, greater.sol_in[9].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[9].sensor_type, + greater.sol_in[9].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[10].flags, greater.sol_in[10].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[10].sensor_type, + greater.sol_in[10].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[11].flags, greater.sol_in[11].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[11].sensor_type, + greater.sol_in[11].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[12].flags, greater.sol_in[12].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[12].sensor_type, + greater.sol_in[12].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[13].flags, greater.sol_in[13].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[13].sensor_type, + greater.sol_in[13].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[14].flags, greater.sol_in[14].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[14].sensor_type, + greater.sol_in[14].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[15].flags, greater.sol_in[15].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[15].sensor_type, + greater.sol_in[15].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[16].flags, greater.sol_in[16].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[16].sensor_type, + greater.sol_in[16].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[17].flags, greater.sol_in[17].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[17].sensor_type, + greater.sol_in[17].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[18].flags, greater.sol_in[18].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[18].sensor_type, + greater.sol_in[18].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[19].flags, greater.sol_in[19].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[19].sensor_type, + greater.sol_in[19].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[20].flags, greater.sol_in[20].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[20].sensor_type, + greater.sol_in[20].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[21].flags, greater.sol_in[21].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[21].sensor_type, + greater.sol_in[21].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[22].flags, greater.sol_in[22].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[22].sensor_type, + greater.sol_in[22].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[23].flags, greater.sol_in[23].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[23].sensor_type, + greater.sol_in[23].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[24].flags, greater.sol_in[24].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[24].sensor_type, + greater.sol_in[24].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[25].flags, greater.sol_in[25].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[25].sensor_type, + greater.sol_in[25].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[26].flags, greater.sol_in[26].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[26].sensor_type, + greater.sol_in[26].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[27].flags, greater.sol_in[27].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[27].sensor_type, + greater.sol_in[27].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[28].flags, greater.sol_in[28].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[28].sensor_type, + greater.sol_in[28].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[29].flags, greater.sol_in[29].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[29].sensor_type, + greater.sol_in[29].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[30].flags, greater.sol_in[30].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[30].sensor_type, + greater.sol_in[30].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[31].flags, greater.sol_in[31].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[31].sensor_type, + greater.sol_in[31].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[32].flags, greater.sol_in[32].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[32].sensor_type, + greater.sol_in[32].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[33].flags, greater.sol_in[33].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[33].sensor_type, + greater.sol_in[33].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[34].flags, greater.sol_in[34].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[34].sensor_type, + greater.sol_in[34].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[35].flags, greater.sol_in[35].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[35].sensor_type, + greater.sol_in[35].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[36].flags, greater.sol_in[36].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[36].sensor_type, + greater.sol_in[36].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[37].flags, greater.sol_in[37].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[37].sensor_type, + greater.sol_in[37].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[38].flags, greater.sol_in[38].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[38].sensor_type, + greater.sol_in[38].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[39].flags, greater.sol_in[39].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[39].sensor_type, + greater.sol_in[39].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[40].flags, greater.sol_in[40].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[40].sensor_type, + greater.sol_in[40].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[41].flags, greater.sol_in[41].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[41].sensor_type, + greater.sol_in[41].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[42].flags, greater.sol_in[42].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[42].sensor_type, + greater.sol_in[42].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[43].flags, greater.sol_in[43].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[43].sensor_type, + greater.sol_in[43].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[44].flags, greater.sol_in[44].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[44].sensor_type, + greater.sol_in[44].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[45].flags, greater.sol_in[45].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[45].sensor_type, + greater.sol_in[45].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[46].flags, greater.sol_in[46].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[46].sensor_type, + greater.sol_in[46].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[47].flags, greater.sol_in[47].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[47].sensor_type, + greater.sol_in[47].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[48].flags, greater.sol_in[48].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[48].sensor_type, + greater.sol_in[48].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[49].flags, greater.sol_in[49].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[49].sensor_type, + greater.sol_in[49].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[50].flags, greater.sol_in[50].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[50].sensor_type, + greater.sol_in[50].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[51].flags, greater.sol_in[51].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[51].sensor_type, + greater.sol_in[51].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[52].flags, greater.sol_in[52].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[52].sensor_type, + greater.sol_in[52].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[53].flags, greater.sol_in[53].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[53].sensor_type, + greater.sol_in[53].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[54].flags, greater.sol_in[54].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[54].sensor_type, + greater.sol_in[54].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[55].flags, greater.sol_in[55].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[55].sensor_type, + greater.sol_in[55].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[56].flags, greater.sol_in[56].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[56].sensor_type, + greater.sol_in[56].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[57].flags, greater.sol_in[57].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[57].sensor_type, + greater.sol_in[57].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[58].flags, greater.sol_in[58].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[58].sensor_type, + greater.sol_in[58].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[59].flags, greater.sol_in[59].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[59].sensor_type, + greater.sol_in[59].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[60].flags, greater.sol_in[60].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[60].sensor_type, + greater.sol_in[60].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[61].flags, greater.sol_in[61].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[61].sensor_type, + greater.sol_in[61].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[62].flags, greater.sol_in[62].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[62].sensor_type, + greater.sol_in[62].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[63].flags, greater.sol_in[63].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[63].sensor_type, + greater.sol_in[63].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[64].flags, greater.sol_in[64].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[64].sensor_type, + greater.sol_in[64].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[65].flags, greater.sol_in[65].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[65].sensor_type, + greater.sol_in[65].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[66].flags, greater.sol_in[66].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[66].sensor_type, + greater.sol_in[66].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[67].flags, greater.sol_in[67].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[67].sensor_type, + greater.sol_in[67].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[68].flags, greater.sol_in[68].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[68].sensor_type, + greater.sol_in[68].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[69].flags, greater.sol_in[69].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[69].sensor_type, + greater.sol_in[69].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[70].flags, greater.sol_in[70].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[70].sensor_type, + greater.sol_in[70].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[71].flags, greater.sol_in[71].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[71].sensor_type, + greater.sol_in[71].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[72].flags, greater.sol_in[72].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[72].sensor_type, + greater.sol_in[72].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[73].flags, greater.sol_in[73].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[73].sensor_type, + greater.sol_in[73].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[74].flags, greater.sol_in[74].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[74].sensor_type, + greater.sol_in[74].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[75].flags, greater.sol_in[75].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[75].sensor_type, + greater.sol_in[75].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[76].flags, greater.sol_in[76].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[76].sensor_type, + greater.sol_in[76].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[77].flags, greater.sol_in[77].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[77].sensor_type, + greater.sol_in[77].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[78].flags, greater.sol_in[78].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[78].sensor_type, + greater.sol_in[78].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[79].flags, greater.sol_in[79].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[79].sensor_type, + greater.sol_in[79].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[80].flags, greater.sol_in[80].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[80].sensor_type, + greater.sol_in[80].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[81].flags, greater.sol_in[81].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[81].sensor_type, + greater.sol_in[81].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[82].flags, greater.sol_in[82].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[82].sensor_type, + greater.sol_in[82].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[83].flags, greater.sol_in[83].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[83].sensor_type, + greater.sol_in[83].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[84].flags, greater.sol_in[84].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[84].sensor_type, + greater.sol_in[84].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[85].flags, greater.sol_in[85].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[85].sensor_type, + greater.sol_in[85].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[86].flags, greater.sol_in[86].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[86].sensor_type, + greater.sol_in[86].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[87].flags, greater.sol_in[87].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[87].sensor_type, + greater.sol_in[87].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[88].flags, greater.sol_in[88].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[88].sensor_type, + greater.sol_in[88].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[89].flags, greater.sol_in[89].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[89].sensor_type, + greater.sol_in[89].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[90].flags, greater.sol_in[90].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[90].sensor_type, + greater.sol_in[90].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[91].flags, greater.sol_in[91].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[91].sensor_type, + greater.sol_in[91].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[92].flags, greater.sol_in[92].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[92].sensor_type, + greater.sol_in[92].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[93].flags, greater.sol_in[93].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[93].sensor_type, + greater.sol_in[93].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[94].flags, greater.sol_in[94].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[94].sensor_type, + greater.sol_in[94].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[95].flags, greater.sol_in[95].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[95].sensor_type, + greater.sol_in[95].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[96].flags, greater.sol_in[96].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[96].sensor_type, + greater.sol_in[96].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[97].flags, greater.sol_in[97].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[97].sensor_type, + greater.sol_in[97].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[98].flags, greater.sol_in[98].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[98].sensor_type, + greater.sol_in[98].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[99].flags, greater.sol_in[99].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[99].sensor_type, + greater.sol_in[99].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[100].flags, greater.sol_in[100].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[100].sensor_type, + greater.sol_in[100].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[101].flags, greater.sol_in[101].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[101].sensor_type, + greater.sol_in[101].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[102].flags, greater.sol_in[102].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[102].sensor_type, + greater.sol_in[102].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[103].flags, greater.sol_in[103].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[103].sensor_type, + greater.sol_in[103].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[104].flags, greater.sol_in[104].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[104].sensor_type, + greater.sol_in[104].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[105].flags, greater.sol_in[105].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[105].sensor_type, + greater.sol_in[105].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[106].flags, greater.sol_in[106].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[106].sensor_type, + greater.sol_in[106].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[107].flags, greater.sol_in[107].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[107].sensor_type, + greater.sol_in[107].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[108].flags, greater.sol_in[108].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[108].sensor_type, + greater.sol_in[108].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[109].flags, greater.sol_in[109].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[109].sensor_type, + greater.sol_in[109].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[110].flags, greater.sol_in[110].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[110].sensor_type, + greater.sol_in[110].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[111].flags, greater.sol_in[111].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[111].sensor_type, + greater.sol_in[111].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[112].flags, greater.sol_in[112].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[112].sensor_type, + greater.sol_in[112].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[113].flags, greater.sol_in[113].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[113].sensor_type, + greater.sol_in[113].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[114].flags, greater.sol_in[114].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[114].sensor_type, + greater.sol_in[114].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[115].flags, greater.sol_in[115].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[115].sensor_type, + greater.sol_in[115].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[116].flags, greater.sol_in[116].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[116].sensor_type, + greater.sol_in[116].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[117].flags, greater.sol_in[117].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[117].sensor_type, + greater.sol_in[117].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[118].flags, greater.sol_in[118].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[118].sensor_type, + greater.sol_in[118].sensor_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_t lesser = info.test_msg; + sbp_msg_soln_meta_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgSolnMeta); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_SOLN_META"); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_soln_meta_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_soln_meta_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.soln_meta, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.soln_meta, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSolnMeta, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMeta0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSolnMeta, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc b/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc new file mode 100644 index 0000000000..e8e82ff265 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc @@ -0,0 +1,2900 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0() { + assign(test_msg_.age_corrections, 48671); + assign(test_msg_.alignment_status, 115); + assign(test_msg_.hdop, 31133); + assign(test_msg_.last_used_gnss_pos_tow, 610745181); + assign(test_msg_.last_used_gnss_vel_tow, 782016851); + assign(test_msg_.n_sats, 238); + assign(test_msg_.n_sol_in, 118); + assign(test_msg_.pdop, 57015); + + assign(test_msg_.sol_in[0].flags, 67); + assign(test_msg_.sol_in[0].sensor_type, 253); + + assign(test_msg_.sol_in[1].flags, 200); + assign(test_msg_.sol_in[1].sensor_type, 87); + + assign(test_msg_.sol_in[2].flags, 250); + assign(test_msg_.sol_in[2].sensor_type, 39); + + assign(test_msg_.sol_in[3].flags, 242); + assign(test_msg_.sol_in[3].sensor_type, 245); + + assign(test_msg_.sol_in[4].flags, 72); + assign(test_msg_.sol_in[4].sensor_type, 228); + + assign(test_msg_.sol_in[5].flags, 222); + assign(test_msg_.sol_in[5].sensor_type, 18); + + assign(test_msg_.sol_in[6].flags, 88); + assign(test_msg_.sol_in[6].sensor_type, 11); + + assign(test_msg_.sol_in[7].flags, 218); + assign(test_msg_.sol_in[7].sensor_type, 207); + + assign(test_msg_.sol_in[8].flags, 13); + assign(test_msg_.sol_in[8].sensor_type, 231); + + assign(test_msg_.sol_in[9].flags, 224); + assign(test_msg_.sol_in[9].sensor_type, 226); + + assign(test_msg_.sol_in[10].flags, 196); + assign(test_msg_.sol_in[10].sensor_type, 22); + + assign(test_msg_.sol_in[11].flags, 242); + assign(test_msg_.sol_in[11].sensor_type, 21); + + assign(test_msg_.sol_in[12].flags, 89); + assign(test_msg_.sol_in[12].sensor_type, 12); + + assign(test_msg_.sol_in[13].flags, 219); + assign(test_msg_.sol_in[13].sensor_type, 71); + + assign(test_msg_.sol_in[14].flags, 85); + assign(test_msg_.sol_in[14].sensor_type, 182); + + assign(test_msg_.sol_in[15].flags, 204); + assign(test_msg_.sol_in[15].sensor_type, 145); + + assign(test_msg_.sol_in[16].flags, 40); + assign(test_msg_.sol_in[16].sensor_type, 146); + + assign(test_msg_.sol_in[17].flags, 51); + assign(test_msg_.sol_in[17].sensor_type, 204); + + assign(test_msg_.sol_in[18].flags, 153); + assign(test_msg_.sol_in[18].sensor_type, 21); + + assign(test_msg_.sol_in[19].flags, 44); + assign(test_msg_.sol_in[19].sensor_type, 227); + + assign(test_msg_.sol_in[20].flags, 28); + assign(test_msg_.sol_in[20].sensor_type, 15); + + assign(test_msg_.sol_in[21].flags, 39); + assign(test_msg_.sol_in[21].sensor_type, 255); + + assign(test_msg_.sol_in[22].flags, 216); + assign(test_msg_.sol_in[22].sensor_type, 205); + + assign(test_msg_.sol_in[23].flags, 190); + assign(test_msg_.sol_in[23].sensor_type, 240); + + assign(test_msg_.sol_in[24].flags, 219); + assign(test_msg_.sol_in[24].sensor_type, 93); + + assign(test_msg_.sol_in[25].flags, 42); + assign(test_msg_.sol_in[25].sensor_type, 103); + + assign(test_msg_.sol_in[26].flags, 182); + assign(test_msg_.sol_in[26].sensor_type, 41); + + assign(test_msg_.sol_in[27].flags, 222); + assign(test_msg_.sol_in[27].sensor_type, 76); + + assign(test_msg_.sol_in[28].flags, 23); + assign(test_msg_.sol_in[28].sensor_type, 17); + + assign(test_msg_.sol_in[29].flags, 31); + assign(test_msg_.sol_in[29].sensor_type, 125); + + assign(test_msg_.sol_in[30].flags, 229); + assign(test_msg_.sol_in[30].sensor_type, 18); + + assign(test_msg_.sol_in[31].flags, 47); + assign(test_msg_.sol_in[31].sensor_type, 28); + + assign(test_msg_.sol_in[32].flags, 25); + assign(test_msg_.sol_in[32].sensor_type, 214); + + assign(test_msg_.sol_in[33].flags, 84); + assign(test_msg_.sol_in[33].sensor_type, 100); + + assign(test_msg_.sol_in[34].flags, 72); + assign(test_msg_.sol_in[34].sensor_type, 106); + + assign(test_msg_.sol_in[35].flags, 10); + assign(test_msg_.sol_in[35].sensor_type, 48); + + assign(test_msg_.sol_in[36].flags, 232); + assign(test_msg_.sol_in[36].sensor_type, 222); + + assign(test_msg_.sol_in[37].flags, 73); + assign(test_msg_.sol_in[37].sensor_type, 235); + + assign(test_msg_.sol_in[38].flags, 163); + assign(test_msg_.sol_in[38].sensor_type, 109); + + assign(test_msg_.sol_in[39].flags, 152); + assign(test_msg_.sol_in[39].sensor_type, 51); + + assign(test_msg_.sol_in[40].flags, 235); + assign(test_msg_.sol_in[40].sensor_type, 133); + + assign(test_msg_.sol_in[41].flags, 70); + assign(test_msg_.sol_in[41].sensor_type, 87); + + assign(test_msg_.sol_in[42].flags, 108); + assign(test_msg_.sol_in[42].sensor_type, 2); + + assign(test_msg_.sol_in[43].flags, 101); + assign(test_msg_.sol_in[43].sensor_type, 91); + + assign(test_msg_.sol_in[44].flags, 55); + assign(test_msg_.sol_in[44].sensor_type, 200); + + assign(test_msg_.sol_in[45].flags, 156); + assign(test_msg_.sol_in[45].sensor_type, 24); + + assign(test_msg_.sol_in[46].flags, 73); + assign(test_msg_.sol_in[46].sensor_type, 233); + + assign(test_msg_.sol_in[47].flags, 66); + assign(test_msg_.sol_in[47].sensor_type, 39); + + assign(test_msg_.sol_in[48].flags, 140); + assign(test_msg_.sol_in[48].sensor_type, 97); + + assign(test_msg_.sol_in[49].flags, 227); + assign(test_msg_.sol_in[49].sensor_type, 252); + + assign(test_msg_.sol_in[50].flags, 237); + assign(test_msg_.sol_in[50].sensor_type, 230); + + assign(test_msg_.sol_in[51].flags, 241); + assign(test_msg_.sol_in[51].sensor_type, 135); + + assign(test_msg_.sol_in[52].flags, 205); + assign(test_msg_.sol_in[52].sensor_type, 245); + + assign(test_msg_.sol_in[53].flags, 0); + assign(test_msg_.sol_in[53].sensor_type, 70); + + assign(test_msg_.sol_in[54].flags, 188); + assign(test_msg_.sol_in[54].sensor_type, 219); + + assign(test_msg_.sol_in[55].flags, 136); + assign(test_msg_.sol_in[55].sensor_type, 107); + + assign(test_msg_.sol_in[56].flags, 58); + assign(test_msg_.sol_in[56].sensor_type, 178); + + assign(test_msg_.sol_in[57].flags, 29); + assign(test_msg_.sol_in[57].sensor_type, 1); + + assign(test_msg_.sol_in[58].flags, 213); + assign(test_msg_.sol_in[58].sensor_type, 44); + + assign(test_msg_.sol_in[59].flags, 147); + assign(test_msg_.sol_in[59].sensor_type, 225); + + assign(test_msg_.sol_in[60].flags, 96); + assign(test_msg_.sol_in[60].sensor_type, 190); + + assign(test_msg_.sol_in[61].flags, 108); + assign(test_msg_.sol_in[61].sensor_type, 192); + + assign(test_msg_.sol_in[62].flags, 15); + assign(test_msg_.sol_in[62].sensor_type, 228); + + assign(test_msg_.sol_in[63].flags, 18); + assign(test_msg_.sol_in[63].sensor_type, 203); + + assign(test_msg_.sol_in[64].flags, 222); + assign(test_msg_.sol_in[64].sensor_type, 3); + + assign(test_msg_.sol_in[65].flags, 68); + assign(test_msg_.sol_in[65].sensor_type, 180); + + assign(test_msg_.sol_in[66].flags, 229); + assign(test_msg_.sol_in[66].sensor_type, 101); + + assign(test_msg_.sol_in[67].flags, 203); + assign(test_msg_.sol_in[67].sensor_type, 223); + + assign(test_msg_.sol_in[68].flags, 164); + assign(test_msg_.sol_in[68].sensor_type, 243); + + assign(test_msg_.sol_in[69].flags, 165); + assign(test_msg_.sol_in[69].sensor_type, 92); + + assign(test_msg_.sol_in[70].flags, 159); + assign(test_msg_.sol_in[70].sensor_type, 220); + + assign(test_msg_.sol_in[71].flags, 121); + assign(test_msg_.sol_in[71].sensor_type, 174); + + assign(test_msg_.sol_in[72].flags, 167); + assign(test_msg_.sol_in[72].sensor_type, 112); + + assign(test_msg_.sol_in[73].flags, 40); + assign(test_msg_.sol_in[73].sensor_type, 240); + + assign(test_msg_.sol_in[74].flags, 3); + assign(test_msg_.sol_in[74].sensor_type, 59); + + assign(test_msg_.sol_in[75].flags, 52); + assign(test_msg_.sol_in[75].sensor_type, 230); + + assign(test_msg_.sol_in[76].flags, 148); + assign(test_msg_.sol_in[76].sensor_type, 149); + + assign(test_msg_.sol_in[77].flags, 142); + assign(test_msg_.sol_in[77].sensor_type, 218); + + assign(test_msg_.sol_in[78].flags, 109); + assign(test_msg_.sol_in[78].sensor_type, 212); + + assign(test_msg_.sol_in[79].flags, 71); + assign(test_msg_.sol_in[79].sensor_type, 176); + + assign(test_msg_.sol_in[80].flags, 172); + assign(test_msg_.sol_in[80].sensor_type, 179); + + assign(test_msg_.sol_in[81].flags, 1); + assign(test_msg_.sol_in[81].sensor_type, 77); + + assign(test_msg_.sol_in[82].flags, 70); + assign(test_msg_.sol_in[82].sensor_type, 193); + + assign(test_msg_.sol_in[83].flags, 149); + assign(test_msg_.sol_in[83].sensor_type, 147); + + assign(test_msg_.sol_in[84].flags, 144); + assign(test_msg_.sol_in[84].sensor_type, 23); + + assign(test_msg_.sol_in[85].flags, 239); + assign(test_msg_.sol_in[85].sensor_type, 148); + + assign(test_msg_.sol_in[86].flags, 186); + assign(test_msg_.sol_in[86].sensor_type, 195); + + assign(test_msg_.sol_in[87].flags, 30); + assign(test_msg_.sol_in[87].sensor_type, 86); + + assign(test_msg_.sol_in[88].flags, 143); + assign(test_msg_.sol_in[88].sensor_type, 34); + + assign(test_msg_.sol_in[89].flags, 207); + assign(test_msg_.sol_in[89].sensor_type, 156); + + assign(test_msg_.sol_in[90].flags, 55); + assign(test_msg_.sol_in[90].sensor_type, 63); + + assign(test_msg_.sol_in[91].flags, 255); + assign(test_msg_.sol_in[91].sensor_type, 117); + + assign(test_msg_.sol_in[92].flags, 222); + assign(test_msg_.sol_in[92].sensor_type, 222); + + assign(test_msg_.sol_in[93].flags, 145); + assign(test_msg_.sol_in[93].sensor_type, 219); + + assign(test_msg_.sol_in[94].flags, 191); + assign(test_msg_.sol_in[94].sensor_type, 224); + + assign(test_msg_.sol_in[95].flags, 109); + assign(test_msg_.sol_in[95].sensor_type, 210); + + assign(test_msg_.sol_in[96].flags, 153); + assign(test_msg_.sol_in[96].sensor_type, 86); + + assign(test_msg_.sol_in[97].flags, 32); + assign(test_msg_.sol_in[97].sensor_type, 21); + + assign(test_msg_.sol_in[98].flags, 10); + assign(test_msg_.sol_in[98].sensor_type, 226); + + assign(test_msg_.sol_in[99].flags, 63); + assign(test_msg_.sol_in[99].sensor_type, 60); + + assign(test_msg_.sol_in[100].flags, 236); + assign(test_msg_.sol_in[100].sensor_type, 106); + + assign(test_msg_.sol_in[101].flags, 96); + assign(test_msg_.sol_in[101].sensor_type, 93); + + assign(test_msg_.sol_in[102].flags, 163); + assign(test_msg_.sol_in[102].sensor_type, 30); + + assign(test_msg_.sol_in[103].flags, 238); + assign(test_msg_.sol_in[103].sensor_type, 106); + + assign(test_msg_.sol_in[104].flags, 133); + assign(test_msg_.sol_in[104].sensor_type, 147); + + assign(test_msg_.sol_in[105].flags, 107); + assign(test_msg_.sol_in[105].sensor_type, 132); + + assign(test_msg_.sol_in[106].flags, 214); + assign(test_msg_.sol_in[106].sensor_type, 152); + + assign(test_msg_.sol_in[107].flags, 185); + assign(test_msg_.sol_in[107].sensor_type, 221); + + assign(test_msg_.sol_in[108].flags, 21); + assign(test_msg_.sol_in[108].sensor_type, 202); + + assign(test_msg_.sol_in[109].flags, 51); + assign(test_msg_.sol_in[109].sensor_type, 252); + + assign(test_msg_.sol_in[110].flags, 59); + assign(test_msg_.sol_in[110].sensor_type, 130); + + assign(test_msg_.sol_in[111].flags, 202); + assign(test_msg_.sol_in[111].sensor_type, 166); + + assign(test_msg_.sol_in[112].flags, 170); + assign(test_msg_.sol_in[112].sensor_type, 127); + + assign(test_msg_.sol_in[113].flags, 193); + assign(test_msg_.sol_in[113].sensor_type, 58); + + assign(test_msg_.sol_in[114].flags, 125); + assign(test_msg_.sol_in[114].sensor_type, 215); + + assign(test_msg_.sol_in[115].flags, 58); + assign(test_msg_.sol_in[115].sensor_type, 22); + + assign(test_msg_.sol_in[116].flags, 47); + assign(test_msg_.sol_in[116].sensor_type, 135); + + assign(test_msg_.sol_in[117].flags, 142); + assign(test_msg_.sol_in[117].sensor_type, 88); + assign(test_msg_.vdop, 41989); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_soln_meta_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_soln_meta_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSolnMetaDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_soln_meta_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSolnMetaDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->soln_meta_dep_a, + sizeof(msg->soln_meta_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_soln_meta_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.soln_meta_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSolnMetaDepA); + info.sender_id = 61780; + info.preamble = 0x55; + info.crc = 0xd34d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 254; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_soln_meta_dep_a_t &lesser, + const sbp_msg_soln_meta_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_soln_meta_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_soln_meta_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_soln_meta_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSolnMetaDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgSolnMetaDepA, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSolnMetaDepA, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSolnMetaDepA, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_soln_meta_dep_a_t test_msg_{}; + uint8_t encoded_frame_[254 + 8] = { + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, 190, + 115, 93, 59, 103, 36, 83, 161, 156, 46, 253, 67, 87, 200, 39, 250, + 245, 242, 228, 72, 18, 222, 11, 88, 207, 218, 231, 13, 226, 224, 22, + 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, 146, 40, 204, 51, + 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, 240, 190, 93, 219, 103, + 42, 41, 182, 76, 222, 17, 23, 125, 31, 18, 229, 28, 47, 214, 25, + 100, 84, 106, 72, 48, 10, 222, 232, 235, 73, 109, 163, 51, 152, 133, + 235, 87, 70, 2, 108, 91, 101, 200, 55, 24, 156, 233, 73, 39, 66, + 97, 140, 252, 227, 230, 237, 135, 241, 245, 205, 70, 0, 219, 188, 107, + 136, 178, 58, 1, 29, 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, + 203, 18, 3, 222, 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, + 159, 174, 121, 112, 167, 240, 40, 59, 3, 230, 52, 149, 148, 218, 142, + 212, 109, 176, 71, 179, 172, 77, 1, 193, 70, 147, 149, 23, 144, 148, + 239, 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, 222, 222, + 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, 106, + 236, 93, 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, 221, 185, + 202, 21, 252, 51, 130, 59, 166, 202, 127, 170, 58, 193, 215, 125, 22, + 58, 135, 47, 88, 142, 77, 211, + }; + uint8_t encoded_payload_[254] = { + 183, 222, 157, 121, 5, 164, 238, 31, 190, 115, 93, 59, 103, 36, 83, + 161, 156, 46, 253, 67, 87, 200, 39, 250, 245, 242, 228, 72, 18, 222, + 11, 88, 207, 218, 231, 13, 226, 224, 22, 196, 21, 242, 12, 89, 71, + 219, 182, 85, 145, 204, 146, 40, 204, 51, 21, 153, 227, 44, 15, 28, + 255, 39, 205, 216, 240, 190, 93, 219, 103, 42, 41, 182, 76, 222, 17, + 23, 125, 31, 18, 229, 28, 47, 214, 25, 100, 84, 106, 72, 48, 10, + 222, 232, 235, 73, 109, 163, 51, 152, 133, 235, 87, 70, 2, 108, 91, + 101, 200, 55, 24, 156, 233, 73, 39, 66, 97, 140, 252, 227, 230, 237, + 135, 241, 245, 205, 70, 0, 219, 188, 107, 136, 178, 58, 1, 29, 44, + 213, 225, 147, 190, 96, 192, 108, 228, 15, 203, 18, 3, 222, 180, 68, + 101, 229, 223, 203, 243, 164, 92, 165, 220, 159, 174, 121, 112, 167, 240, + 40, 59, 3, 230, 52, 149, 148, 218, 142, 212, 109, 176, 71, 179, 172, + 77, 1, 193, 70, 147, 149, 23, 144, 148, 239, 195, 186, 86, 30, 34, + 143, 156, 207, 63, 55, 117, 255, 222, 222, 219, 145, 224, 191, 210, 109, + 86, 153, 21, 32, 226, 10, 60, 63, 106, 236, 93, 96, 30, 163, 106, + 238, 147, 133, 132, 107, 152, 214, 221, 185, 202, 21, 252, 51, 130, 59, + 166, 202, 127, 170, 58, 193, 215, 125, 22, 58, 135, 47, 88, 142, + }; +}; + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_soln_meta_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSolnMetaDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSolnMetaDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + for (uint8_t i = 0; i < 254; i++) { + EXPECT_EQ( + sbp_msg_soln_meta_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSolnMetaDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_soln_meta_dep_a_t t{}; + return sbp_msg_soln_meta_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_soln_meta_dep_a_t t{}; + t.n_sol_in = 1; + return sbp_msg_soln_meta_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_soln_meta_dep_a_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSolnMetaDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSolnMetaDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSolnMetaDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.age_corrections, greater.age_corrections); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.alignment_status, greater.alignment_status); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.hdop, greater.hdop); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.last_used_gnss_pos_tow, + greater.last_used_gnss_pos_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.last_used_gnss_vel_tow, + greater.last_used_gnss_vel_tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_sol_in, greater.n_sol_in); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pdop, greater.pdop); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[0].flags, greater.sol_in[0].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[0].sensor_type, + greater.sol_in[0].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[1].flags, greater.sol_in[1].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[1].sensor_type, + greater.sol_in[1].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[2].flags, greater.sol_in[2].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[2].sensor_type, + greater.sol_in[2].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[3].flags, greater.sol_in[3].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[3].sensor_type, + greater.sol_in[3].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[4].flags, greater.sol_in[4].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[4].sensor_type, + greater.sol_in[4].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[5].flags, greater.sol_in[5].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[5].sensor_type, + greater.sol_in[5].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[6].flags, greater.sol_in[6].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[6].sensor_type, + greater.sol_in[6].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[7].flags, greater.sol_in[7].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[7].sensor_type, + greater.sol_in[7].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[8].flags, greater.sol_in[8].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[8].sensor_type, + greater.sol_in[8].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[9].flags, greater.sol_in[9].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[9].sensor_type, + greater.sol_in[9].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[10].flags, greater.sol_in[10].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[10].sensor_type, + greater.sol_in[10].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[11].flags, greater.sol_in[11].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[11].sensor_type, + greater.sol_in[11].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[12].flags, greater.sol_in[12].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[12].sensor_type, + greater.sol_in[12].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[13].flags, greater.sol_in[13].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[13].sensor_type, + greater.sol_in[13].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[14].flags, greater.sol_in[14].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[14].sensor_type, + greater.sol_in[14].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[15].flags, greater.sol_in[15].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[15].sensor_type, + greater.sol_in[15].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[16].flags, greater.sol_in[16].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[16].sensor_type, + greater.sol_in[16].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[17].flags, greater.sol_in[17].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[17].sensor_type, + greater.sol_in[17].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[18].flags, greater.sol_in[18].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[18].sensor_type, + greater.sol_in[18].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[19].flags, greater.sol_in[19].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[19].sensor_type, + greater.sol_in[19].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[20].flags, greater.sol_in[20].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[20].sensor_type, + greater.sol_in[20].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[21].flags, greater.sol_in[21].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[21].sensor_type, + greater.sol_in[21].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[22].flags, greater.sol_in[22].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[22].sensor_type, + greater.sol_in[22].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[23].flags, greater.sol_in[23].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[23].sensor_type, + greater.sol_in[23].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[24].flags, greater.sol_in[24].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[24].sensor_type, + greater.sol_in[24].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[25].flags, greater.sol_in[25].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[25].sensor_type, + greater.sol_in[25].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[26].flags, greater.sol_in[26].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[26].sensor_type, + greater.sol_in[26].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[27].flags, greater.sol_in[27].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[27].sensor_type, + greater.sol_in[27].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[28].flags, greater.sol_in[28].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[28].sensor_type, + greater.sol_in[28].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[29].flags, greater.sol_in[29].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[29].sensor_type, + greater.sol_in[29].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[30].flags, greater.sol_in[30].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[30].sensor_type, + greater.sol_in[30].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[31].flags, greater.sol_in[31].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[31].sensor_type, + greater.sol_in[31].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[32].flags, greater.sol_in[32].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[32].sensor_type, + greater.sol_in[32].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[33].flags, greater.sol_in[33].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[33].sensor_type, + greater.sol_in[33].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[34].flags, greater.sol_in[34].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[34].sensor_type, + greater.sol_in[34].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[35].flags, greater.sol_in[35].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[35].sensor_type, + greater.sol_in[35].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[36].flags, greater.sol_in[36].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[36].sensor_type, + greater.sol_in[36].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[37].flags, greater.sol_in[37].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[37].sensor_type, + greater.sol_in[37].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[38].flags, greater.sol_in[38].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[38].sensor_type, + greater.sol_in[38].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[39].flags, greater.sol_in[39].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[39].sensor_type, + greater.sol_in[39].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[40].flags, greater.sol_in[40].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[40].sensor_type, + greater.sol_in[40].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[41].flags, greater.sol_in[41].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[41].sensor_type, + greater.sol_in[41].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[42].flags, greater.sol_in[42].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[42].sensor_type, + greater.sol_in[42].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[43].flags, greater.sol_in[43].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[43].sensor_type, + greater.sol_in[43].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[44].flags, greater.sol_in[44].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[44].sensor_type, + greater.sol_in[44].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[45].flags, greater.sol_in[45].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[45].sensor_type, + greater.sol_in[45].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[46].flags, greater.sol_in[46].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[46].sensor_type, + greater.sol_in[46].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[47].flags, greater.sol_in[47].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[47].sensor_type, + greater.sol_in[47].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[48].flags, greater.sol_in[48].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[48].sensor_type, + greater.sol_in[48].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[49].flags, greater.sol_in[49].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[49].sensor_type, + greater.sol_in[49].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[50].flags, greater.sol_in[50].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[50].sensor_type, + greater.sol_in[50].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[51].flags, greater.sol_in[51].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[51].sensor_type, + greater.sol_in[51].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[52].flags, greater.sol_in[52].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[52].sensor_type, + greater.sol_in[52].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[53].flags, greater.sol_in[53].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[53].sensor_type, + greater.sol_in[53].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[54].flags, greater.sol_in[54].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[54].sensor_type, + greater.sol_in[54].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[55].flags, greater.sol_in[55].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[55].sensor_type, + greater.sol_in[55].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[56].flags, greater.sol_in[56].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[56].sensor_type, + greater.sol_in[56].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[57].flags, greater.sol_in[57].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[57].sensor_type, + greater.sol_in[57].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[58].flags, greater.sol_in[58].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[58].sensor_type, + greater.sol_in[58].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[59].flags, greater.sol_in[59].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[59].sensor_type, + greater.sol_in[59].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[60].flags, greater.sol_in[60].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[60].sensor_type, + greater.sol_in[60].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[61].flags, greater.sol_in[61].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[61].sensor_type, + greater.sol_in[61].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[62].flags, greater.sol_in[62].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[62].sensor_type, + greater.sol_in[62].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[63].flags, greater.sol_in[63].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[63].sensor_type, + greater.sol_in[63].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[64].flags, greater.sol_in[64].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[64].sensor_type, + greater.sol_in[64].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[65].flags, greater.sol_in[65].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[65].sensor_type, + greater.sol_in[65].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[66].flags, greater.sol_in[66].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[66].sensor_type, + greater.sol_in[66].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[67].flags, greater.sol_in[67].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[67].sensor_type, + greater.sol_in[67].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[68].flags, greater.sol_in[68].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[68].sensor_type, + greater.sol_in[68].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[69].flags, greater.sol_in[69].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[69].sensor_type, + greater.sol_in[69].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[70].flags, greater.sol_in[70].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[70].sensor_type, + greater.sol_in[70].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[71].flags, greater.sol_in[71].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[71].sensor_type, + greater.sol_in[71].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[72].flags, greater.sol_in[72].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[72].sensor_type, + greater.sol_in[72].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[73].flags, greater.sol_in[73].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[73].sensor_type, + greater.sol_in[73].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[74].flags, greater.sol_in[74].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[74].sensor_type, + greater.sol_in[74].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[75].flags, greater.sol_in[75].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[75].sensor_type, + greater.sol_in[75].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[76].flags, greater.sol_in[76].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[76].sensor_type, + greater.sol_in[76].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[77].flags, greater.sol_in[77].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[77].sensor_type, + greater.sol_in[77].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[78].flags, greater.sol_in[78].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[78].sensor_type, + greater.sol_in[78].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[79].flags, greater.sol_in[79].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[79].sensor_type, + greater.sol_in[79].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[80].flags, greater.sol_in[80].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[80].sensor_type, + greater.sol_in[80].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[81].flags, greater.sol_in[81].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[81].sensor_type, + greater.sol_in[81].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[82].flags, greater.sol_in[82].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[82].sensor_type, + greater.sol_in[82].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[83].flags, greater.sol_in[83].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[83].sensor_type, + greater.sol_in[83].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[84].flags, greater.sol_in[84].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[84].sensor_type, + greater.sol_in[84].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[85].flags, greater.sol_in[85].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[85].sensor_type, + greater.sol_in[85].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[86].flags, greater.sol_in[86].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[86].sensor_type, + greater.sol_in[86].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[87].flags, greater.sol_in[87].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[87].sensor_type, + greater.sol_in[87].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[88].flags, greater.sol_in[88].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[88].sensor_type, + greater.sol_in[88].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[89].flags, greater.sol_in[89].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[89].sensor_type, + greater.sol_in[89].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[90].flags, greater.sol_in[90].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[90].sensor_type, + greater.sol_in[90].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[91].flags, greater.sol_in[91].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[91].sensor_type, + greater.sol_in[91].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[92].flags, greater.sol_in[92].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[92].sensor_type, + greater.sol_in[92].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[93].flags, greater.sol_in[93].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[93].sensor_type, + greater.sol_in[93].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[94].flags, greater.sol_in[94].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[94].sensor_type, + greater.sol_in[94].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[95].flags, greater.sol_in[95].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[95].sensor_type, + greater.sol_in[95].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[96].flags, greater.sol_in[96].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[96].sensor_type, + greater.sol_in[96].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[97].flags, greater.sol_in[97].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[97].sensor_type, + greater.sol_in[97].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[98].flags, greater.sol_in[98].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[98].sensor_type, + greater.sol_in[98].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[99].flags, greater.sol_in[99].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[99].sensor_type, + greater.sol_in[99].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[100].flags, greater.sol_in[100].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[100].sensor_type, + greater.sol_in[100].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[101].flags, greater.sol_in[101].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[101].sensor_type, + greater.sol_in[101].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[102].flags, greater.sol_in[102].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[102].sensor_type, + greater.sol_in[102].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[103].flags, greater.sol_in[103].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[103].sensor_type, + greater.sol_in[103].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[104].flags, greater.sol_in[104].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[104].sensor_type, + greater.sol_in[104].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[105].flags, greater.sol_in[105].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[105].sensor_type, + greater.sol_in[105].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[106].flags, greater.sol_in[106].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[106].sensor_type, + greater.sol_in[106].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[107].flags, greater.sol_in[107].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[107].sensor_type, + greater.sol_in[107].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[108].flags, greater.sol_in[108].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[108].sensor_type, + greater.sol_in[108].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[109].flags, greater.sol_in[109].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[109].sensor_type, + greater.sol_in[109].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[110].flags, greater.sol_in[110].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[110].sensor_type, + greater.sol_in[110].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[111].flags, greater.sol_in[111].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[111].sensor_type, + greater.sol_in[111].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[112].flags, greater.sol_in[112].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[112].sensor_type, + greater.sol_in[112].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[113].flags, greater.sol_in[113].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[113].sensor_type, + greater.sol_in[113].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[114].flags, greater.sol_in[114].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[114].sensor_type, + greater.sol_in[114].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[115].flags, greater.sol_in[115].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[115].sensor_type, + greater.sol_in[115].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[116].flags, greater.sol_in[116].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[116].sensor_type, + greater.sol_in[116].sensor_type); + comparison_tests(lesser, greater); + } + + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[117].flags, greater.sol_in[117].flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sol_in[117].sensor_type, + greater.sol_in[117].sensor_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_soln_meta_dep_a_t lesser = info.test_msg; + sbp_msg_soln_meta_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.vdop, greater.vdop); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSolnMetaDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SOLN_META_DEP_A"); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_soln_meta_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_soln_meta_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.soln_meta_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.soln_meta_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_soln_meta_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSolnMetaDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_solution_meta_MsgSolnMetaDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSolnMetaDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc new file mode 100644 index 0000000000..adcf6dc311 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc @@ -0,0 +1,2161 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrCodeBiases0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrCodeBiases0() { + assign(test_msg_.biases[0].code, 51); + assign(test_msg_.biases[0].value, -31996); + + assign(test_msg_.biases[1].code, 240); + assign(test_msg_.biases[1].value, 21368); + + assign(test_msg_.biases[2].code, 148); + assign(test_msg_.biases[2].value, -10799); + + assign(test_msg_.biases[3].code, 62); + assign(test_msg_.biases[3].value, -5916); + + assign(test_msg_.biases[4].code, 71); + assign(test_msg_.biases[4].value, -17342); + + assign(test_msg_.biases[5].code, 210); + assign(test_msg_.biases[5].value, 13952); + + assign(test_msg_.biases[6].code, 131); + assign(test_msg_.biases[6].value, -32360); + + assign(test_msg_.biases[7].code, 111); + assign(test_msg_.biases[7].value, -3445); + + assign(test_msg_.biases[8].code, 177); + assign(test_msg_.biases[8].value, 11409); + + assign(test_msg_.biases[9].code, 9); + assign(test_msg_.biases[9].value, -12299); + + assign(test_msg_.biases[10].code, 241); + assign(test_msg_.biases[10].value, -26934); + + assign(test_msg_.biases[11].code, 141); + assign(test_msg_.biases[11].value, -24782); + + assign(test_msg_.biases[12].code, 220); + assign(test_msg_.biases[12].value, 9611); + + assign(test_msg_.biases[13].code, 187); + assign(test_msg_.biases[13].value, -16542); + + assign(test_msg_.biases[14].code, 23); + assign(test_msg_.biases[14].value, -30592); + + assign(test_msg_.biases[15].code, 167); + assign(test_msg_.biases[15].value, 1736); + + assign(test_msg_.biases[16].code, 211); + assign(test_msg_.biases[16].value, 5978); + + assign(test_msg_.biases[17].code, 244); + assign(test_msg_.biases[17].value, -10358); + + assign(test_msg_.biases[18].code, 209); + assign(test_msg_.biases[18].value, 3467); + + assign(test_msg_.biases[19].code, 101); + assign(test_msg_.biases[19].value, 1824); + + assign(test_msg_.biases[20].code, 18); + assign(test_msg_.biases[20].value, 17949); + + assign(test_msg_.biases[21].code, 250); + assign(test_msg_.biases[21].value, 18797); + + assign(test_msg_.biases[22].code, 202); + assign(test_msg_.biases[22].value, -28593); + + assign(test_msg_.biases[23].code, 9); + assign(test_msg_.biases[23].value, 17810); + + assign(test_msg_.biases[24].code, 241); + assign(test_msg_.biases[24].value, 5684); + + assign(test_msg_.biases[25].code, 99); + assign(test_msg_.biases[25].value, -13214); + + assign(test_msg_.biases[26].code, 3); + assign(test_msg_.biases[26].value, -6485); + + assign(test_msg_.biases[27].code, 180); + assign(test_msg_.biases[27].value, 15947); + + assign(test_msg_.biases[28].code, 145); + assign(test_msg_.biases[28].value, -32170); + + assign(test_msg_.biases[29].code, 31); + assign(test_msg_.biases[29].value, -25826); + + assign(test_msg_.biases[30].code, 37); + assign(test_msg_.biases[30].value, 14098); + + assign(test_msg_.biases[31].code, 210); + assign(test_msg_.biases[31].value, 32551); + + assign(test_msg_.biases[32].code, 242); + assign(test_msg_.biases[32].value, 3394); + + assign(test_msg_.biases[33].code, 237); + assign(test_msg_.biases[33].value, -21864); + + assign(test_msg_.biases[34].code, 212); + assign(test_msg_.biases[34].value, -2545); + + assign(test_msg_.biases[35].code, 59); + assign(test_msg_.biases[35].value, -19362); + + assign(test_msg_.biases[36].code, 195); + assign(test_msg_.biases[36].value, 17821); + + assign(test_msg_.biases[37].code, 100); + assign(test_msg_.biases[37].value, 4215); + + assign(test_msg_.biases[38].code, 68); + assign(test_msg_.biases[38].value, -20557); + + assign(test_msg_.biases[39].code, 144); + assign(test_msg_.biases[39].value, 20849); + + assign(test_msg_.biases[40].code, 82); + assign(test_msg_.biases[40].value, -26850); + + assign(test_msg_.biases[41].code, 21); + assign(test_msg_.biases[41].value, 10605); + + assign(test_msg_.biases[42].code, 225); + assign(test_msg_.biases[42].value, 19720); + + assign(test_msg_.biases[43].code, 164); + assign(test_msg_.biases[43].value, 157); + + assign(test_msg_.biases[44].code, 73); + assign(test_msg_.biases[44].value, 1566); + + assign(test_msg_.biases[45].code, 78); + assign(test_msg_.biases[45].value, -28847); + + assign(test_msg_.biases[46].code, 116); + assign(test_msg_.biases[46].value, -26640); + + assign(test_msg_.biases[47].code, 55); + assign(test_msg_.biases[47].value, -22087); + + assign(test_msg_.biases[48].code, 254); + assign(test_msg_.biases[48].value, 10035); + + assign(test_msg_.biases[49].code, 74); + assign(test_msg_.biases[49].value, -2129); + + assign(test_msg_.biases[50].code, 34); + assign(test_msg_.biases[50].value, 19041); + + assign(test_msg_.biases[51].code, 97); + assign(test_msg_.biases[51].value, 12464); + + assign(test_msg_.biases[52].code, 236); + assign(test_msg_.biases[52].value, 3245); + + assign(test_msg_.biases[53].code, 174); + assign(test_msg_.biases[53].value, -32155); + + assign(test_msg_.biases[54].code, 30); + assign(test_msg_.biases[54].value, -15959); + + assign(test_msg_.biases[55].code, 190); + assign(test_msg_.biases[55].value, -15156); + + assign(test_msg_.biases[56].code, 123); + assign(test_msg_.biases[56].value, 6507); + + assign(test_msg_.biases[57].code, 225); + assign(test_msg_.biases[57].value, 2378); + + assign(test_msg_.biases[58].code, 10); + assign(test_msg_.biases[58].value, 823); + + assign(test_msg_.biases[59].code, 131); + assign(test_msg_.biases[59].value, 25590); + + assign(test_msg_.biases[60].code, 133); + assign(test_msg_.biases[60].value, -7390); + + assign(test_msg_.biases[61].code, 203); + assign(test_msg_.biases[61].value, 4676); + + assign(test_msg_.biases[62].code, 97); + assign(test_msg_.biases[62].value, 23007); + + assign(test_msg_.biases[63].code, 192); + assign(test_msg_.biases[63].value, 13046); + + assign(test_msg_.biases[64].code, 69); + assign(test_msg_.biases[64].value, 2651); + + assign(test_msg_.biases[65].code, 151); + assign(test_msg_.biases[65].value, 30282); + + assign(test_msg_.biases[66].code, 110); + assign(test_msg_.biases[66].value, -22492); + + assign(test_msg_.biases[67].code, 247); + assign(test_msg_.biases[67].value, 19872); + + assign(test_msg_.biases[68].code, 179); + assign(test_msg_.biases[68].value, -19827); + + assign(test_msg_.biases[69].code, 99); + assign(test_msg_.biases[69].value, 30911); + + assign(test_msg_.biases[70].code, 77); + assign(test_msg_.biases[70].value, 23488); + + assign(test_msg_.biases[71].code, 224); + assign(test_msg_.biases[71].value, -7679); + + assign(test_msg_.biases[72].code, 50); + assign(test_msg_.biases[72].value, -28073); + + assign(test_msg_.biases[73].code, 148); + assign(test_msg_.biases[73].value, 25838); + + assign(test_msg_.biases[74].code, 179); + assign(test_msg_.biases[74].value, -7299); + + assign(test_msg_.biases[75].code, 215); + assign(test_msg_.biases[75].value, -18328); + + assign(test_msg_.biases[76].code, 31); + assign(test_msg_.biases[76].value, 23097); + + assign(test_msg_.biases[77].code, 79); + assign(test_msg_.biases[77].value, -25579); + + assign(test_msg_.biases[78].code, 245); + assign(test_msg_.biases[78].value, 15441); + + assign(test_msg_.biases[79].code, 93); + assign(test_msg_.biases[79].value, 15530); + + assign(test_msg_.biases[80].code, 200); + assign(test_msg_.biases[80].value, 3495); + assign(test_msg_.iod_ssr, 132); + assign(test_msg_.n_biases, 81); + assign(test_msg_.sid.code, 241); + assign(test_msg_.sid.sat, 133); + assign(test_msg_.time.tow, 387144400); + assign(test_msg_.time.wn, 16905); + assign(test_msg_.update_interval, 254); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_code_biases_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_code_biases_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrCodeBiases, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_code_biases_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrCodeBiases); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_code_biases, + sizeof(msg->ssr_code_biases)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_code_biases_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_code_biases, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrCodeBiases); + info.sender_id = 22311; + info.preamble = 0x55; + info.crc = 0x847d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 253; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_code_biases_t &lesser, + const sbp_msg_ssr_code_biases_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_code_biases_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_code_biases_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_code_biases_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_code_biases_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSsrCodeBiases, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrCodeBiases, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSsrCodeBiases, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSsrCodeBiases, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_code_biases_t test_msg_{}; + uint8_t encoded_frame_[253 + 8] = { + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, 254, + 132, 51, 4, 131, 240, 120, 83, 148, 209, 213, 62, 228, 232, 71, 66, + 188, 210, 128, 54, 131, 152, 129, 111, 139, 242, 177, 145, 44, 9, 245, + 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, 98, 191, 23, 128, + 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, 209, 139, 13, 101, 32, + 7, 18, 29, 70, 250, 109, 73, 202, 79, 144, 9, 146, 69, 241, 52, + 22, 99, 98, 204, 3, 171, 230, 180, 75, 62, 145, 86, 130, 31, 30, + 155, 37, 18, 55, 210, 39, 127, 242, 66, 13, 237, 152, 170, 212, 15, + 246, 59, 94, 180, 195, 157, 69, 100, 119, 16, 68, 179, 175, 144, 113, + 81, 82, 30, 151, 21, 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, + 6, 78, 81, 143, 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, + 247, 34, 97, 74, 97, 176, 48, 236, 173, 12, 174, 101, 130, 30, 169, + 193, 190, 204, 196, 123, 107, 25, 225, 74, 9, 10, 55, 3, 131, 246, + 99, 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, + 10, 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, 191, + 120, 77, 192, 91, 224, 1, 226, 50, 87, 146, 148, 238, 100, 179, 125, + 227, 215, 104, 184, 31, 57, 90, 79, 21, 156, 245, 81, 60, 93, 170, + 60, 200, 167, 13, 125, 132, + }; + uint8_t encoded_payload_[253] = { + 208, 90, 19, 23, 9, 66, 133, 241, 254, 132, 51, 4, 131, 240, 120, + 83, 148, 209, 213, 62, 228, 232, 71, 66, 188, 210, 128, 54, 131, 152, + 129, 111, 139, 242, 177, 145, 44, 9, 245, 207, 241, 202, 150, 141, 50, + 159, 220, 139, 37, 187, 98, 191, 23, 128, 136, 167, 200, 6, 211, 90, + 23, 244, 138, 215, 209, 139, 13, 101, 32, 7, 18, 29, 70, 250, 109, + 73, 202, 79, 144, 9, 146, 69, 241, 52, 22, 99, 98, 204, 3, 171, + 230, 180, 75, 62, 145, 86, 130, 31, 30, 155, 37, 18, 55, 210, 39, + 127, 242, 66, 13, 237, 152, 170, 212, 15, 246, 59, 94, 180, 195, 157, + 69, 100, 119, 16, 68, 179, 175, 144, 113, 81, 82, 30, 151, 21, 109, + 41, 225, 8, 77, 164, 157, 0, 73, 30, 6, 78, 81, 143, 116, 240, + 151, 55, 185, 169, 254, 51, 39, 74, 175, 247, 34, 97, 74, 97, 176, + 48, 236, 173, 12, 174, 101, 130, 30, 169, 193, 190, 204, 196, 123, 107, + 25, 225, 74, 9, 10, 55, 3, 131, 246, 99, 133, 34, 227, 203, 68, + 18, 97, 223, 89, 192, 246, 50, 69, 91, 10, 151, 74, 118, 110, 36, + 168, 247, 160, 77, 179, 141, 178, 99, 191, 120, 77, 192, 91, 224, 1, + 226, 50, 87, 146, 148, 238, 100, 179, 125, 227, 215, 104, 184, 31, 57, + 90, 79, 21, 156, 245, 81, 60, 93, 170, 60, 200, 167, 13, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_code_biases_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrCodeBiases, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_code_biases_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrCodeBiases, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + + EXPECT_EQ(sbp_msg_ssr_code_biases_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + + for (uint8_t i = 0; i < 253; i++) { + EXPECT_EQ( + sbp_msg_ssr_code_biases_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_code_biases_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrCodeBiases, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_biases_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_code_biases_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_biases_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_code_biases_t t{}; + return sbp_msg_ssr_code_biases_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_code_biases_t t{}; + t.n_biases = 1; + return sbp_msg_ssr_code_biases_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_code_biases_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_code_biases_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrCodeBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrCodeBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrCodeBiases, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].code, greater.biases[0].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].value, greater.biases[0].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].code, greater.biases[1].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].value, greater.biases[1].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].code, greater.biases[2].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].value, greater.biases[2].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].code, greater.biases[3].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].value, greater.biases[3].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].code, greater.biases[4].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].value, greater.biases[4].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].code, greater.biases[5].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].value, greater.biases[5].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].code, greater.biases[6].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].value, greater.biases[6].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].code, greater.biases[7].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].value, greater.biases[7].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].code, greater.biases[8].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].value, greater.biases[8].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].code, greater.biases[9].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].value, greater.biases[9].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].code, greater.biases[10].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].value, greater.biases[10].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].code, greater.biases[11].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].value, greater.biases[11].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].code, greater.biases[12].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].value, greater.biases[12].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].code, greater.biases[13].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].value, greater.biases[13].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].code, greater.biases[14].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].value, greater.biases[14].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].code, greater.biases[15].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].value, greater.biases[15].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].code, greater.biases[16].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].value, greater.biases[16].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].code, greater.biases[17].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].value, greater.biases[17].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].code, greater.biases[18].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].value, greater.biases[18].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].code, greater.biases[19].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].value, greater.biases[19].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].code, greater.biases[20].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].value, greater.biases[20].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].code, greater.biases[21].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].value, greater.biases[21].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].code, greater.biases[22].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].value, greater.biases[22].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].code, greater.biases[23].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].value, greater.biases[23].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].code, greater.biases[24].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].value, greater.biases[24].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].code, greater.biases[25].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].value, greater.biases[25].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].code, greater.biases[26].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].value, greater.biases[26].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].code, greater.biases[27].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].value, greater.biases[27].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].code, greater.biases[28].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].value, greater.biases[28].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].code, greater.biases[29].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].value, greater.biases[29].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[30].code, greater.biases[30].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[30].value, greater.biases[30].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[31].code, greater.biases[31].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[31].value, greater.biases[31].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[32].code, greater.biases[32].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[32].value, greater.biases[32].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[33].code, greater.biases[33].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[33].value, greater.biases[33].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[34].code, greater.biases[34].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[34].value, greater.biases[34].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[35].code, greater.biases[35].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[35].value, greater.biases[35].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[36].code, greater.biases[36].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[36].value, greater.biases[36].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[37].code, greater.biases[37].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[37].value, greater.biases[37].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[38].code, greater.biases[38].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[38].value, greater.biases[38].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[39].code, greater.biases[39].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[39].value, greater.biases[39].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[40].code, greater.biases[40].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[40].value, greater.biases[40].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[41].code, greater.biases[41].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[41].value, greater.biases[41].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[42].code, greater.biases[42].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[42].value, greater.biases[42].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[43].code, greater.biases[43].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[43].value, greater.biases[43].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[44].code, greater.biases[44].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[44].value, greater.biases[44].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[45].code, greater.biases[45].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[45].value, greater.biases[45].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[46].code, greater.biases[46].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[46].value, greater.biases[46].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[47].code, greater.biases[47].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[47].value, greater.biases[47].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[48].code, greater.biases[48].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[48].value, greater.biases[48].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[49].code, greater.biases[49].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[49].value, greater.biases[49].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[50].code, greater.biases[50].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[50].value, greater.biases[50].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[51].code, greater.biases[51].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[51].value, greater.biases[51].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[52].code, greater.biases[52].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[52].value, greater.biases[52].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[53].code, greater.biases[53].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[53].value, greater.biases[53].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[54].code, greater.biases[54].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[54].value, greater.biases[54].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[55].code, greater.biases[55].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[55].value, greater.biases[55].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[56].code, greater.biases[56].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[56].value, greater.biases[56].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[57].code, greater.biases[57].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[57].value, greater.biases[57].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[58].code, greater.biases[58].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[58].value, greater.biases[58].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[59].code, greater.biases[59].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[59].value, greater.biases[59].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[60].code, greater.biases[60].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[60].value, greater.biases[60].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[61].code, greater.biases[61].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[61].value, greater.biases[61].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[62].code, greater.biases[62].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[62].value, greater.biases[62].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[63].code, greater.biases[63].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[63].value, greater.biases[63].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[64].code, greater.biases[64].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[64].value, greater.biases[64].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[65].code, greater.biases[65].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[65].value, greater.biases[65].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[66].code, greater.biases[66].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[66].value, greater.biases[66].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[67].code, greater.biases[67].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[67].value, greater.biases[67].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[68].code, greater.biases[68].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[68].value, greater.biases[68].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[69].code, greater.biases[69].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[69].value, greater.biases[69].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[70].code, greater.biases[70].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[70].value, greater.biases[70].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[71].code, greater.biases[71].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[71].value, greater.biases[71].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[72].code, greater.biases[72].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[72].value, greater.biases[72].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[73].code, greater.biases[73].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[73].value, greater.biases[73].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[74].code, greater.biases[74].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[74].value, greater.biases[74].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[75].code, greater.biases[75].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[75].value, greater.biases[75].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[76].code, greater.biases[76].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[76].value, greater.biases[76].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[77].code, greater.biases[77].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[77].value, greater.biases[77].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[78].code, greater.biases[78].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[78].value, greater.biases[78].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[79].code, greater.biases[79].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[79].value, greater.biases[79].value); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[80].code, greater.biases[80].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[80].value, greater.biases[80].value); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.iod_ssr, greater.iod_ssr); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.n_biases, greater.n_biases); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_biases_t lesser = info.test_msg; + sbp_msg_ssr_code_biases_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrCodeBiases); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_CODE_BIASES"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_code_biases_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_code_biases_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_code_biases, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_code_biases, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrCodeBiases, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodeBiases0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrCodeBiases, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds.cc index 0547f18f26..a0b20ad19c 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds.cc @@ -16,212 +16,1017 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0 + : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0() { + assign(test_msg_.const_id, 1); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.sol_id, 14); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 1); + assign(test_msg_.n_sats_signals, 3); + + assign(test_msg_.satellites_signals[0].code_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[0].code_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[0].phase_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[0].phase_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[0].sat_id, 0); + assign(test_msg_.satellites_signals[0].signal_id, 3); + + assign(test_msg_.satellites_signals[1].code_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[1].code_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[1].phase_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[1].phase_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[1].sat_id, 1); + assign(test_msg_.satellites_signals[1].signal_id, 3); + + assign(test_msg_.satellites_signals[2].code_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[2].code_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[2].phase_bias_bound_mu, 39); + assign(test_msg_.satellites_signals[2].phase_bias_bound_sig, 1); + assign(test_msg_.satellites_signals[2].sat_id, 1); + assign(test_msg_.satellites_signals[2].signal_id, 1); + assign(test_msg_.ssr_iod, 15); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_code_phase_biases_bounds_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_code_phase_biases_bounds_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_code_phase_biases_bounds_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrCodePhaseBiasesBounds, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_code_phase_biases_bounds_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrCodePhaseBiasesBounds); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_code_phase_biases_bounds, + sizeof(msg->ssr_code_phase_biases_bounds)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_code_phase_biases_bounds_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_code_phase_biases_bounds, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrCodePhaseBiasesBounds); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x7117; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 31; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_code_phase_biases_bounds_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_code_phase_biases_bounds_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_code_phase_biases_bounds_t &lesser, + const sbp_msg_ssr_code_phase_biases_bounds_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_code_phase_biases_bounds_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_code_phase_biases_bounds_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrCodePhaseBiasesBounds, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrCodePhaseBiasesBounds, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrCodePhaseBiasesBounds, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrCodePhaseBiasesBounds, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_code_phase_biases_bounds_t test_msg_{}; + uint8_t encoded_frame_[31 + 8] = { 85, 236, 5, 66, 0, 31, 180, 0, 0, 0, 3, 0, 1, 2, 1, 14, 15, 1, 3, 0, 3, 39, 1, 39, 1, 1, 3, 39, 1, 39, 1, 1, 1, 39, 1, 39, 1, 23, 113, }; + uint8_t encoded_payload_[31] = { + 180, 0, 0, 0, 3, 0, 1, 2, 1, 14, 15, 1, 3, 0, 3, 39, + 1, 39, 1, 1, 3, 39, 1, 39, 1, 1, 1, 39, 1, 39, 1, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrCodePhaseBiasesBounds, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrCodePhaseBiasesBounds, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + for (uint8_t i = 0; i < 31; i++) { + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_phase_biases_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrCodePhaseBiasesBounds, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_phase_biases_bounds_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_phase_biases_bounds_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_code_phase_biases_bounds_t t{}; + return sbp_msg_ssr_code_phase_biases_bounds_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_code_phase_biases_bounds_t t{}; + t.n_sats_signals = 1; + return sbp_msg_ssr_code_phase_biases_bounds_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ssr_code_phase_biases_bounds_t test_msg{}; - test_msg.const_id = 1; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 2; - test_msg.header.sol_id = 14; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 1; - test_msg.n_sats_signals = 3; - - test_msg.satellites_signals[0].code_bias_bound_mu = 39; - test_msg.satellites_signals[0].code_bias_bound_sig = 1; - test_msg.satellites_signals[0].phase_bias_bound_mu = 39; - test_msg.satellites_signals[0].phase_bias_bound_sig = 1; - test_msg.satellites_signals[0].sat_id = 0; - test_msg.satellites_signals[0].signal_id = 3; - - test_msg.satellites_signals[1].code_bias_bound_mu = 39; - test_msg.satellites_signals[1].code_bias_bound_sig = 1; - test_msg.satellites_signals[1].phase_bias_bound_mu = 39; - test_msg.satellites_signals[1].phase_bias_bound_sig = 1; - test_msg.satellites_signals[1].sat_id = 1; - test_msg.satellites_signals[1].signal_id = 3; - - test_msg.satellites_signals[2].code_bias_bound_mu = 39; - test_msg.satellites_signals[2].code_bias_bound_sig = 1; - test_msg.satellites_signals[2].phase_bias_bound_mu = 39; - test_msg.satellites_signals[2].phase_bias_bound_sig = 1; - test_msg.satellites_signals[2].sat_id = 1; - test_msg.satellites_signals[2].signal_id = 1; - test_msg.ssr_iod = 15; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.const_id, 1) - << "incorrect value for last_msg_.const_id, expected 1, is " - << last_msg_.const_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 14) - << "incorrect value for last_msg_.header.sol_id, expected 14, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 1) - << "incorrect value for last_msg_.header.update_interval, expected 1, is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.n_sats_signals, 3) - << "incorrect value for last_msg_.n_sats_signals, expected 3, is " - << last_msg_.n_sats_signals; - EXPECT_EQ(last_msg_.satellites_signals[0].code_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[0].code_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[0].code_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[0].code_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[0].code_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[0].code_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[0].phase_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[0].phase_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[0].phase_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[0].phase_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[0].phase_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[0].phase_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[0].sat_id, 0) - << "incorrect value for last_msg_.satellites_signals[0].sat_id, expected " - "0, is " - << last_msg_.satellites_signals[0].sat_id; - EXPECT_EQ(last_msg_.satellites_signals[0].signal_id, 3) - << "incorrect value for last_msg_.satellites_signals[0].signal_id, " - "expected 3, is " - << last_msg_.satellites_signals[0].signal_id; - EXPECT_EQ(last_msg_.satellites_signals[1].code_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[1].code_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[1].code_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[1].code_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[1].code_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[1].code_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[1].phase_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[1].phase_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[1].phase_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[1].phase_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[1].phase_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[1].phase_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[1].sat_id, 1) - << "incorrect value for last_msg_.satellites_signals[1].sat_id, expected " - "1, is " - << last_msg_.satellites_signals[1].sat_id; - EXPECT_EQ(last_msg_.satellites_signals[1].signal_id, 3) - << "incorrect value for last_msg_.satellites_signals[1].signal_id, " - "expected 3, is " - << last_msg_.satellites_signals[1].signal_id; - EXPECT_EQ(last_msg_.satellites_signals[2].code_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[2].code_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[2].code_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[2].code_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[2].code_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[2].code_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[2].phase_bias_bound_mu, 39) - << "incorrect value for " - "last_msg_.satellites_signals[2].phase_bias_bound_mu, expected 39, is " - << last_msg_.satellites_signals[2].phase_bias_bound_mu; - EXPECT_EQ(last_msg_.satellites_signals[2].phase_bias_bound_sig, 1) - << "incorrect value for " - "last_msg_.satellites_signals[2].phase_bias_bound_sig, expected 1, is " - << last_msg_.satellites_signals[2].phase_bias_bound_sig; - EXPECT_EQ(last_msg_.satellites_signals[2].sat_id, 1) - << "incorrect value for last_msg_.satellites_signals[2].sat_id, expected " - "1, is " - << last_msg_.satellites_signals[2].sat_id; - EXPECT_EQ(last_msg_.satellites_signals[2].signal_id, 1) - << "incorrect value for last_msg_.satellites_signals[2].signal_id, " - "expected 1, is " - << last_msg_.satellites_signals[2].signal_id; - EXPECT_EQ(last_msg_.ssr_iod, 15) - << "incorrect value for last_msg_.ssr_iod, expected 15, is " - << last_msg_.ssr_iod; + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_code_phase_biases_bounds_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrCodePhaseBiasesBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrCodePhaseBiasesBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrCodePhaseBiasesBounds, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.const_id, greater.const_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats_signals, greater.n_sats_signals); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].code_bias_bound_mu, + greater.satellites_signals[0].code_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].code_bias_bound_sig, + greater.satellites_signals[0].code_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].phase_bias_bound_mu, + greater.satellites_signals[0].phase_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].phase_bias_bound_sig, + greater.satellites_signals[0].phase_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].sat_id, + greater.satellites_signals[0].sat_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[0].signal_id, + greater.satellites_signals[0].signal_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].code_bias_bound_mu, + greater.satellites_signals[1].code_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].code_bias_bound_sig, + greater.satellites_signals[1].code_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].phase_bias_bound_mu, + greater.satellites_signals[1].phase_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].phase_bias_bound_sig, + greater.satellites_signals[1].phase_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].sat_id, + greater.satellites_signals[1].sat_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[1].signal_id, + greater.satellites_signals[1].signal_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].code_bias_bound_mu, + greater.satellites_signals[2].code_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].code_bias_bound_sig, + greater.satellites_signals[2].code_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].phase_bias_bound_mu, + greater.satellites_signals[2].phase_bias_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].phase_bias_bound_sig, + greater.satellites_signals[2].phase_bias_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].sat_id, + greater.satellites_signals[2].sat_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.satellites_signals[2].signal_id, + greater.satellites_signals[2].signal_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_code_phase_biases_bounds_t lesser = info.test_msg; + sbp_msg_ssr_code_phase_biases_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod, greater.ssr_iod); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrCodePhaseBiasesBounds); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_CODE_PHASE_BIASES_BOUNDS"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_code_phase_biases_bounds_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_code_phase_biases_bounds_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_code_phase_biases_bounds, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_code_phase_biases_bounds, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_code_phase_biases_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrCodePhaseBiasesBounds, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrCodePhaseBiasesBounds0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrCodePhaseBiasesBounds, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc new file mode 100644 index 0000000000..0a8ed2d87f --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc @@ -0,0 +1,3107 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0() { + assign(test_msg_.header.area_width, 43860); + assign(test_msg_.header.lat_nw_corner_enc, 34021); + assign(test_msg_.header.lon_nw_corner_enc, 11919); + assign(test_msg_.header.num_msgs, 204); + assign(test_msg_.header.region_size_inverse, 11); + assign(test_msg_.header.seq_num, 52); + assign(test_msg_.n_rle_list, 246); + + assign(test_msg_.rle_list[0], 92); + + assign(test_msg_.rle_list[1], 104); + + assign(test_msg_.rle_list[2], 25); + + assign(test_msg_.rle_list[3], 204); + + assign(test_msg_.rle_list[4], 182); + + assign(test_msg_.rle_list[5], 22); + + assign(test_msg_.rle_list[6], 98); + + assign(test_msg_.rle_list[7], 203); + + assign(test_msg_.rle_list[8], 123); + + assign(test_msg_.rle_list[9], 211); + + assign(test_msg_.rle_list[10], 38); + + assign(test_msg_.rle_list[11], 13); + + assign(test_msg_.rle_list[12], 253); + + assign(test_msg_.rle_list[13], 129); + + assign(test_msg_.rle_list[14], 173); + + assign(test_msg_.rle_list[15], 171); + + assign(test_msg_.rle_list[16], 235); + + assign(test_msg_.rle_list[17], 253); + + assign(test_msg_.rle_list[18], 26); + + assign(test_msg_.rle_list[19], 203); + + assign(test_msg_.rle_list[20], 3); + + assign(test_msg_.rle_list[21], 120); + + assign(test_msg_.rle_list[22], 126); + + assign(test_msg_.rle_list[23], 42); + + assign(test_msg_.rle_list[24], 44); + + assign(test_msg_.rle_list[25], 39); + + assign(test_msg_.rle_list[26], 87); + + assign(test_msg_.rle_list[27], 69); + + assign(test_msg_.rle_list[28], 154); + + assign(test_msg_.rle_list[29], 13); + + assign(test_msg_.rle_list[30], 28); + + assign(test_msg_.rle_list[31], 179); + + assign(test_msg_.rle_list[32], 32); + + assign(test_msg_.rle_list[33], 47); + + assign(test_msg_.rle_list[34], 36); + + assign(test_msg_.rle_list[35], 195); + + assign(test_msg_.rle_list[36], 39); + + assign(test_msg_.rle_list[37], 198); + + assign(test_msg_.rle_list[38], 134); + + assign(test_msg_.rle_list[39], 235); + + assign(test_msg_.rle_list[40], 134); + + assign(test_msg_.rle_list[41], 57); + + assign(test_msg_.rle_list[42], 120); + + assign(test_msg_.rle_list[43], 243); + + assign(test_msg_.rle_list[44], 151); + + assign(test_msg_.rle_list[45], 35); + + assign(test_msg_.rle_list[46], 17); + + assign(test_msg_.rle_list[47], 201); + + assign(test_msg_.rle_list[48], 211); + + assign(test_msg_.rle_list[49], 125); + + assign(test_msg_.rle_list[50], 117); + + assign(test_msg_.rle_list[51], 164); + + assign(test_msg_.rle_list[52], 142); + + assign(test_msg_.rle_list[53], 101); + + assign(test_msg_.rle_list[54], 239); + + assign(test_msg_.rle_list[55], 144); + + assign(test_msg_.rle_list[56], 158); + + assign(test_msg_.rle_list[57], 239); + + assign(test_msg_.rle_list[58], 90); + + assign(test_msg_.rle_list[59], 56); + + assign(test_msg_.rle_list[60], 71); + + assign(test_msg_.rle_list[61], 120); + + assign(test_msg_.rle_list[62], 67); + + assign(test_msg_.rle_list[63], 221); + + assign(test_msg_.rle_list[64], 114); + + assign(test_msg_.rle_list[65], 10); + + assign(test_msg_.rle_list[66], 190); + + assign(test_msg_.rle_list[67], 4); + + assign(test_msg_.rle_list[68], 230); + + assign(test_msg_.rle_list[69], 164); + + assign(test_msg_.rle_list[70], 171); + + assign(test_msg_.rle_list[71], 78); + + assign(test_msg_.rle_list[72], 185); + + assign(test_msg_.rle_list[73], 90); + + assign(test_msg_.rle_list[74], 46); + + assign(test_msg_.rle_list[75], 177); + + assign(test_msg_.rle_list[76], 82); + + assign(test_msg_.rle_list[77], 228); + + assign(test_msg_.rle_list[78], 123); + + assign(test_msg_.rle_list[79], 222); + + assign(test_msg_.rle_list[80], 227); + + assign(test_msg_.rle_list[81], 145); + + assign(test_msg_.rle_list[82], 195); + + assign(test_msg_.rle_list[83], 219); + + assign(test_msg_.rle_list[84], 27); + + assign(test_msg_.rle_list[85], 56); + + assign(test_msg_.rle_list[86], 227); + + assign(test_msg_.rle_list[87], 246); + + assign(test_msg_.rle_list[88], 215); + + assign(test_msg_.rle_list[89], 144); + + assign(test_msg_.rle_list[90], 158); + + assign(test_msg_.rle_list[91], 31); + + assign(test_msg_.rle_list[92], 214); + + assign(test_msg_.rle_list[93], 241); + + assign(test_msg_.rle_list[94], 254); + + assign(test_msg_.rle_list[95], 200); + + assign(test_msg_.rle_list[96], 86); + + assign(test_msg_.rle_list[97], 142); + + assign(test_msg_.rle_list[98], 89); + + assign(test_msg_.rle_list[99], 12); + + assign(test_msg_.rle_list[100], 121); + + assign(test_msg_.rle_list[101], 29); + + assign(test_msg_.rle_list[102], 124); + + assign(test_msg_.rle_list[103], 9); + + assign(test_msg_.rle_list[104], 19); + + assign(test_msg_.rle_list[105], 153); + + assign(test_msg_.rle_list[106], 44); + + assign(test_msg_.rle_list[107], 35); + + assign(test_msg_.rle_list[108], 126); + + assign(test_msg_.rle_list[109], 14); + + assign(test_msg_.rle_list[110], 217); + + assign(test_msg_.rle_list[111], 65); + + assign(test_msg_.rle_list[112], 116); + + assign(test_msg_.rle_list[113], 26); + + assign(test_msg_.rle_list[114], 139); + + assign(test_msg_.rle_list[115], 122); + + assign(test_msg_.rle_list[116], 114); + + assign(test_msg_.rle_list[117], 90); + + assign(test_msg_.rle_list[118], 124); + + assign(test_msg_.rle_list[119], 81); + + assign(test_msg_.rle_list[120], 0); + + assign(test_msg_.rle_list[121], 186); + + assign(test_msg_.rle_list[122], 246); + + assign(test_msg_.rle_list[123], 46); + + assign(test_msg_.rle_list[124], 98); + + assign(test_msg_.rle_list[125], 179); + + assign(test_msg_.rle_list[126], 243); + + assign(test_msg_.rle_list[127], 198); + + assign(test_msg_.rle_list[128], 217); + + assign(test_msg_.rle_list[129], 36); + + assign(test_msg_.rle_list[130], 30); + + assign(test_msg_.rle_list[131], 202); + + assign(test_msg_.rle_list[132], 12); + + assign(test_msg_.rle_list[133], 135); + + assign(test_msg_.rle_list[134], 61); + + assign(test_msg_.rle_list[135], 42); + + assign(test_msg_.rle_list[136], 150); + + assign(test_msg_.rle_list[137], 221); + + assign(test_msg_.rle_list[138], 102); + + assign(test_msg_.rle_list[139], 83); + + assign(test_msg_.rle_list[140], 179); + + assign(test_msg_.rle_list[141], 43); + + assign(test_msg_.rle_list[142], 252); + + assign(test_msg_.rle_list[143], 81); + + assign(test_msg_.rle_list[144], 62); + + assign(test_msg_.rle_list[145], 126); + + assign(test_msg_.rle_list[146], 204); + + assign(test_msg_.rle_list[147], 195); + + assign(test_msg_.rle_list[148], 238); + + assign(test_msg_.rle_list[149], 18); + + assign(test_msg_.rle_list[150], 128); + + assign(test_msg_.rle_list[151], 193); + + assign(test_msg_.rle_list[152], 53); + + assign(test_msg_.rle_list[153], 94); + + assign(test_msg_.rle_list[154], 99); + + assign(test_msg_.rle_list[155], 63); + + assign(test_msg_.rle_list[156], 182); + + assign(test_msg_.rle_list[157], 2); + + assign(test_msg_.rle_list[158], 186); + + assign(test_msg_.rle_list[159], 220); + + assign(test_msg_.rle_list[160], 77); + + assign(test_msg_.rle_list[161], 186); + + assign(test_msg_.rle_list[162], 224); + + assign(test_msg_.rle_list[163], 220); + + assign(test_msg_.rle_list[164], 13); + + assign(test_msg_.rle_list[165], 212); + + assign(test_msg_.rle_list[166], 182); + + assign(test_msg_.rle_list[167], 88); + + assign(test_msg_.rle_list[168], 15); + + assign(test_msg_.rle_list[169], 151); + + assign(test_msg_.rle_list[170], 5); + + assign(test_msg_.rle_list[171], 93); + + assign(test_msg_.rle_list[172], 251); + + assign(test_msg_.rle_list[173], 164); + + assign(test_msg_.rle_list[174], 18); + + assign(test_msg_.rle_list[175], 228); + + assign(test_msg_.rle_list[176], 168); + + assign(test_msg_.rle_list[177], 226); + + assign(test_msg_.rle_list[178], 195); + + assign(test_msg_.rle_list[179], 44); + + assign(test_msg_.rle_list[180], 170); + + assign(test_msg_.rle_list[181], 145); + + assign(test_msg_.rle_list[182], 36); + + assign(test_msg_.rle_list[183], 58); + + assign(test_msg_.rle_list[184], 96); + + assign(test_msg_.rle_list[185], 107); + + assign(test_msg_.rle_list[186], 144); + + assign(test_msg_.rle_list[187], 11); + + assign(test_msg_.rle_list[188], 228); + + assign(test_msg_.rle_list[189], 12); + + assign(test_msg_.rle_list[190], 163); + + assign(test_msg_.rle_list[191], 238); + + assign(test_msg_.rle_list[192], 247); + + assign(test_msg_.rle_list[193], 159); + + assign(test_msg_.rle_list[194], 189); + + assign(test_msg_.rle_list[195], 1); + + assign(test_msg_.rle_list[196], 115); + + assign(test_msg_.rle_list[197], 65); + + assign(test_msg_.rle_list[198], 202); + + assign(test_msg_.rle_list[199], 121); + + assign(test_msg_.rle_list[200], 47); + + assign(test_msg_.rle_list[201], 193); + + assign(test_msg_.rle_list[202], 11); + + assign(test_msg_.rle_list[203], 96); + + assign(test_msg_.rle_list[204], 93); + + assign(test_msg_.rle_list[205], 72); + + assign(test_msg_.rle_list[206], 81); + + assign(test_msg_.rle_list[207], 207); + + assign(test_msg_.rle_list[208], 121); + + assign(test_msg_.rle_list[209], 19); + + assign(test_msg_.rle_list[210], 151); + + assign(test_msg_.rle_list[211], 136); + + assign(test_msg_.rle_list[212], 233); + + assign(test_msg_.rle_list[213], 51); + + assign(test_msg_.rle_list[214], 133); + + assign(test_msg_.rle_list[215], 195); + + assign(test_msg_.rle_list[216], 77); + + assign(test_msg_.rle_list[217], 44); + + assign(test_msg_.rle_list[218], 147); + + assign(test_msg_.rle_list[219], 206); + + assign(test_msg_.rle_list[220], 120); + + assign(test_msg_.rle_list[221], 252); + + assign(test_msg_.rle_list[222], 77); + + assign(test_msg_.rle_list[223], 212); + + assign(test_msg_.rle_list[224], 68); + + assign(test_msg_.rle_list[225], 60); + + assign(test_msg_.rle_list[226], 206); + + assign(test_msg_.rle_list[227], 106); + + assign(test_msg_.rle_list[228], 207); + + assign(test_msg_.rle_list[229], 243); + + assign(test_msg_.rle_list[230], 158); + + assign(test_msg_.rle_list[231], 94); + + assign(test_msg_.rle_list[232], 6); + + assign(test_msg_.rle_list[233], 3); + + assign(test_msg_.rle_list[234], 205); + + assign(test_msg_.rle_list[235], 92); + + assign(test_msg_.rle_list[236], 84); + + assign(test_msg_.rle_list[237], 2); + + assign(test_msg_.rle_list[238], 220); + + assign(test_msg_.rle_list[239], 50); + + assign(test_msg_.rle_list[240], 61); + + assign(test_msg_.rle_list[241], 38); + + assign(test_msg_.rle_list[242], 141); + + assign(test_msg_.rle_list[243], 117); + + assign(test_msg_.rle_list[244], 108); + + assign(test_msg_.rle_list[245], 101); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_grid_definition_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_grid_definition_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_grid_definition_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGridDefinitionDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_grid_definition_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGridDefinitionDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_grid_definition_dep_a, + sizeof(msg->ssr_grid_definition_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_grid_definition_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_grid_definition_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrGridDefinitionDepA); + info.sender_id = 63413; + info.preamble = 0x55; + info.crc = 0x8b4c; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_grid_definition_dep_a_t &lesser, + const sbp_msg_ssr_grid_definition_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_grid_definition_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_grid_definition_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGridDefinitionDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGridDefinitionDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGridDefinitionDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGridDefinitionDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_grid_definition_dep_a_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, 52, + 92, 104, 25, 204, 182, 22, 98, 203, 123, 211, 38, 13, 253, 129, 173, + 171, 235, 253, 26, 203, 3, 120, 126, 42, 44, 39, 87, 69, 154, 13, + 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, 57, 120, 243, 151, + 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, 144, 158, 239, 90, 56, + 71, 120, 67, 221, 114, 10, 190, 4, 230, 164, 171, 78, 185, 90, 46, + 177, 82, 228, 123, 222, 227, 145, 195, 219, 27, 56, 227, 246, 215, 144, + 158, 31, 214, 241, 254, 200, 86, 142, 89, 12, 121, 29, 124, 9, 19, + 153, 44, 35, 126, 14, 217, 65, 116, 26, 139, 122, 114, 90, 124, 81, + 0, 186, 246, 46, 98, 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, + 42, 150, 221, 102, 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, + 128, 193, 53, 94, 99, 63, 182, 2, 186, 220, 77, 186, 224, 220, 13, + 212, 182, 88, 15, 151, 5, 93, 251, 164, 18, 228, 168, 226, 195, 44, + 170, 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, 159, 189, + 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, 19, + 151, 136, 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, 212, 68, + 60, 206, 106, 207, 243, 158, 94, 6, 3, 205, 92, 84, 2, 220, 50, + 61, 38, 141, 117, 108, 101, 76, 139, + }; + uint8_t encoded_payload_[255] = { + 11, 84, 171, 229, 132, 143, 46, 204, 52, 92, 104, 25, 204, 182, 22, + 98, 203, 123, 211, 38, 13, 253, 129, 173, 171, 235, 253, 26, 203, 3, + 120, 126, 42, 44, 39, 87, 69, 154, 13, 28, 179, 32, 47, 36, 195, + 39, 198, 134, 235, 134, 57, 120, 243, 151, 35, 17, 201, 211, 125, 117, + 164, 142, 101, 239, 144, 158, 239, 90, 56, 71, 120, 67, 221, 114, 10, + 190, 4, 230, 164, 171, 78, 185, 90, 46, 177, 82, 228, 123, 222, 227, + 145, 195, 219, 27, 56, 227, 246, 215, 144, 158, 31, 214, 241, 254, 200, + 86, 142, 89, 12, 121, 29, 124, 9, 19, 153, 44, 35, 126, 14, 217, + 65, 116, 26, 139, 122, 114, 90, 124, 81, 0, 186, 246, 46, 98, 179, + 243, 198, 217, 36, 30, 202, 12, 135, 61, 42, 150, 221, 102, 83, 179, + 43, 252, 81, 62, 126, 204, 195, 238, 18, 128, 193, 53, 94, 99, 63, + 182, 2, 186, 220, 77, 186, 224, 220, 13, 212, 182, 88, 15, 151, 5, + 93, 251, 164, 18, 228, 168, 226, 195, 44, 170, 145, 36, 58, 96, 107, + 144, 11, 228, 12, 163, 238, 247, 159, 189, 1, 115, 65, 202, 121, 47, + 193, 11, 96, 93, 72, 81, 207, 121, 19, 151, 136, 233, 51, 133, 195, + 77, 44, 147, 206, 120, 252, 77, 212, 68, 60, 206, 106, 207, 243, 158, + 94, 6, 3, 205, 92, 84, 2, 220, 50, 61, 38, 141, 117, 108, 101, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGridDefinitionDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGridDefinitionDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_grid_definition_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGridDefinitionDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_grid_definition_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_grid_definition_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_grid_definition_dep_a_t t{}; + return sbp_msg_ssr_grid_definition_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_grid_definition_dep_a_t t{}; + t.n_rle_list = 1; + return sbp_msg_ssr_grid_definition_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_grid_definition_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGridDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrGridDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGridDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.area_width, greater.header.area_width); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.lat_nw_corner_enc, + greater.header.lat_nw_corner_enc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.lon_nw_corner_enc, + greater.header.lon_nw_corner_enc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.region_size_inverse, + greater.header.region_size_inverse); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_rle_list, greater.n_rle_list); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[0], greater.rle_list[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[1], greater.rle_list[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[2], greater.rle_list[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[3], greater.rle_list[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[4], greater.rle_list[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[5], greater.rle_list[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[6], greater.rle_list[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[7], greater.rle_list[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[8], greater.rle_list[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[9], greater.rle_list[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[10], greater.rle_list[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[11], greater.rle_list[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[12], greater.rle_list[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[13], greater.rle_list[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[14], greater.rle_list[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[15], greater.rle_list[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[16], greater.rle_list[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[17], greater.rle_list[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[18], greater.rle_list[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[19], greater.rle_list[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[20], greater.rle_list[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[21], greater.rle_list[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[22], greater.rle_list[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[23], greater.rle_list[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[24], greater.rle_list[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[25], greater.rle_list[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[26], greater.rle_list[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[27], greater.rle_list[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[28], greater.rle_list[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[29], greater.rle_list[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[30], greater.rle_list[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[31], greater.rle_list[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[32], greater.rle_list[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[33], greater.rle_list[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[34], greater.rle_list[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[35], greater.rle_list[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[36], greater.rle_list[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[37], greater.rle_list[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[38], greater.rle_list[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[39], greater.rle_list[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[40], greater.rle_list[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[41], greater.rle_list[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[42], greater.rle_list[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[43], greater.rle_list[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[44], greater.rle_list[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[45], greater.rle_list[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[46], greater.rle_list[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[47], greater.rle_list[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[48], greater.rle_list[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[49], greater.rle_list[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[50], greater.rle_list[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[51], greater.rle_list[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[52], greater.rle_list[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[53], greater.rle_list[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[54], greater.rle_list[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[55], greater.rle_list[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[56], greater.rle_list[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[57], greater.rle_list[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[58], greater.rle_list[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[59], greater.rle_list[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[60], greater.rle_list[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[61], greater.rle_list[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[62], greater.rle_list[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[63], greater.rle_list[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[64], greater.rle_list[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[65], greater.rle_list[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[66], greater.rle_list[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[67], greater.rle_list[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[68], greater.rle_list[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[69], greater.rle_list[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[70], greater.rle_list[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[71], greater.rle_list[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[72], greater.rle_list[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[73], greater.rle_list[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[74], greater.rle_list[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[75], greater.rle_list[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[76], greater.rle_list[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[77], greater.rle_list[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[78], greater.rle_list[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[79], greater.rle_list[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[80], greater.rle_list[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[81], greater.rle_list[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[82], greater.rle_list[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[83], greater.rle_list[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[84], greater.rle_list[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[85], greater.rle_list[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[86], greater.rle_list[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[87], greater.rle_list[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[88], greater.rle_list[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[89], greater.rle_list[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[90], greater.rle_list[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[91], greater.rle_list[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[92], greater.rle_list[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[93], greater.rle_list[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[94], greater.rle_list[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[95], greater.rle_list[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[96], greater.rle_list[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[97], greater.rle_list[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[98], greater.rle_list[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[99], greater.rle_list[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[100], greater.rle_list[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[101], greater.rle_list[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[102], greater.rle_list[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[103], greater.rle_list[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[104], greater.rle_list[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[105], greater.rle_list[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[106], greater.rle_list[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[107], greater.rle_list[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[108], greater.rle_list[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[109], greater.rle_list[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[110], greater.rle_list[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[111], greater.rle_list[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[112], greater.rle_list[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[113], greater.rle_list[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[114], greater.rle_list[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[115], greater.rle_list[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[116], greater.rle_list[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[117], greater.rle_list[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[118], greater.rle_list[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[119], greater.rle_list[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[120], greater.rle_list[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[121], greater.rle_list[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[122], greater.rle_list[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[123], greater.rle_list[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[124], greater.rle_list[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[125], greater.rle_list[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[126], greater.rle_list[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[127], greater.rle_list[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[128], greater.rle_list[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[129], greater.rle_list[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[130], greater.rle_list[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[131], greater.rle_list[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[132], greater.rle_list[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[133], greater.rle_list[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[134], greater.rle_list[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[135], greater.rle_list[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[136], greater.rle_list[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[137], greater.rle_list[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[138], greater.rle_list[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[139], greater.rle_list[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[140], greater.rle_list[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[141], greater.rle_list[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[142], greater.rle_list[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[143], greater.rle_list[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[144], greater.rle_list[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[145], greater.rle_list[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[146], greater.rle_list[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[147], greater.rle_list[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[148], greater.rle_list[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[149], greater.rle_list[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[150], greater.rle_list[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[151], greater.rle_list[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[152], greater.rle_list[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[153], greater.rle_list[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[154], greater.rle_list[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[155], greater.rle_list[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[156], greater.rle_list[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[157], greater.rle_list[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[158], greater.rle_list[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[159], greater.rle_list[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[160], greater.rle_list[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[161], greater.rle_list[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[162], greater.rle_list[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[163], greater.rle_list[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[164], greater.rle_list[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[165], greater.rle_list[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[166], greater.rle_list[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[167], greater.rle_list[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[168], greater.rle_list[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[169], greater.rle_list[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[170], greater.rle_list[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[171], greater.rle_list[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[172], greater.rle_list[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[173], greater.rle_list[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[174], greater.rle_list[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[175], greater.rle_list[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[176], greater.rle_list[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[177], greater.rle_list[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[178], greater.rle_list[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[179], greater.rle_list[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[180], greater.rle_list[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[181], greater.rle_list[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[182], greater.rle_list[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[183], greater.rle_list[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[184], greater.rle_list[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[185], greater.rle_list[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[186], greater.rle_list[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[187], greater.rle_list[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[188], greater.rle_list[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[189], greater.rle_list[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[190], greater.rle_list[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[191], greater.rle_list[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[192], greater.rle_list[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[193], greater.rle_list[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[194], greater.rle_list[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[195], greater.rle_list[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[196], greater.rle_list[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[197], greater.rle_list[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[198], greater.rle_list[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[199], greater.rle_list[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[200], greater.rle_list[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[201], greater.rle_list[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[202], greater.rle_list[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[203], greater.rle_list[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[204], greater.rle_list[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[205], greater.rle_list[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[206], greater.rle_list[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[207], greater.rle_list[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[208], greater.rle_list[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[209], greater.rle_list[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[210], greater.rle_list[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[211], greater.rle_list[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[212], greater.rle_list[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[213], greater.rle_list[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[214], greater.rle_list[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[215], greater.rle_list[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[216], greater.rle_list[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[217], greater.rle_list[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[218], greater.rle_list[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[219], greater.rle_list[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[220], greater.rle_list[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[221], greater.rle_list[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[222], greater.rle_list[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[223], greater.rle_list[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[224], greater.rle_list[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[225], greater.rle_list[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[226], greater.rle_list[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[227], greater.rle_list[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[228], greater.rle_list[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[229], greater.rle_list[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[230], greater.rle_list[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[231], greater.rle_list[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[232], greater.rle_list[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[233], greater.rle_list[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[234], greater.rle_list[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[235], greater.rle_list[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[236], greater.rle_list[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[237], greater.rle_list[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[238], greater.rle_list[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[239], greater.rle_list[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[240], greater.rle_list[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[241], greater.rle_list[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[242], greater.rle_list[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[243], greater.rle_list[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[244], greater.rle_list[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_grid_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_grid_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rle_list[245], greater.rle_list[245]); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGridDefinitionDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_GRID_DEFINITION_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_grid_definition_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_grid_definition_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_grid_definition_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_grid_definition_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_grid_definition_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGridDefinitionDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrGridDefinitionDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc new file mode 100644 index 0000000000..41b7c749ea --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc @@ -0,0 +1,2501 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0() { + assign(test_msg_.header.iod_atmo, 170); + assign(test_msg_.header.num_msgs, 48535); + assign(test_msg_.header.seq_num, 50380); + assign(test_msg_.header.tile_id, 12951); + assign(test_msg_.header.tile_set_id, 3605); + assign(test_msg_.header.time.tow, 2535294328); + assign(test_msg_.header.time.wn, 58798); + assign(test_msg_.header.tropo_quality_indicator, 120); + assign(test_msg_.header.update_interval, 105); + assign(test_msg_.index, 43413); + assign(test_msg_.n_stec_residuals, 46); + + assign(test_msg_.stec_residuals[0].residual, -21246); + assign(test_msg_.stec_residuals[0].stddev, 88); + assign(test_msg_.stec_residuals[0].sv_id.constellation, 101); + assign(test_msg_.stec_residuals[0].sv_id.satId, 140); + + assign(test_msg_.stec_residuals[1].residual, -26570); + assign(test_msg_.stec_residuals[1].stddev, 115); + assign(test_msg_.stec_residuals[1].sv_id.constellation, 180); + assign(test_msg_.stec_residuals[1].sv_id.satId, 70); + + assign(test_msg_.stec_residuals[2].residual, 6049); + assign(test_msg_.stec_residuals[2].stddev, 135); + assign(test_msg_.stec_residuals[2].sv_id.constellation, 201); + assign(test_msg_.stec_residuals[2].sv_id.satId, 78); + + assign(test_msg_.stec_residuals[3].residual, 19261); + assign(test_msg_.stec_residuals[3].stddev, 178); + assign(test_msg_.stec_residuals[3].sv_id.constellation, 98); + assign(test_msg_.stec_residuals[3].sv_id.satId, 152); + + assign(test_msg_.stec_residuals[4].residual, 14226); + assign(test_msg_.stec_residuals[4].stddev, 58); + assign(test_msg_.stec_residuals[4].sv_id.constellation, 229); + assign(test_msg_.stec_residuals[4].sv_id.satId, 120); + + assign(test_msg_.stec_residuals[5].residual, 17894); + assign(test_msg_.stec_residuals[5].stddev, 172); + assign(test_msg_.stec_residuals[5].sv_id.constellation, 234); + assign(test_msg_.stec_residuals[5].sv_id.satId, 169); + + assign(test_msg_.stec_residuals[6].residual, 22930); + assign(test_msg_.stec_residuals[6].stddev, 150); + assign(test_msg_.stec_residuals[6].sv_id.constellation, 127); + assign(test_msg_.stec_residuals[6].sv_id.satId, 191); + + assign(test_msg_.stec_residuals[7].residual, 10721); + assign(test_msg_.stec_residuals[7].stddev, 17); + assign(test_msg_.stec_residuals[7].sv_id.constellation, 111); + assign(test_msg_.stec_residuals[7].sv_id.satId, 91); + + assign(test_msg_.stec_residuals[8].residual, -22874); + assign(test_msg_.stec_residuals[8].stddev, 120); + assign(test_msg_.stec_residuals[8].sv_id.constellation, 52); + assign(test_msg_.stec_residuals[8].sv_id.satId, 119); + + assign(test_msg_.stec_residuals[9].residual, 780); + assign(test_msg_.stec_residuals[9].stddev, 156); + assign(test_msg_.stec_residuals[9].sv_id.constellation, 221); + assign(test_msg_.stec_residuals[9].sv_id.satId, 57); + + assign(test_msg_.stec_residuals[10].residual, 32547); + assign(test_msg_.stec_residuals[10].stddev, 8); + assign(test_msg_.stec_residuals[10].sv_id.constellation, 156); + assign(test_msg_.stec_residuals[10].sv_id.satId, 70); + + assign(test_msg_.stec_residuals[11].residual, 14208); + assign(test_msg_.stec_residuals[11].stddev, 115); + assign(test_msg_.stec_residuals[11].sv_id.constellation, 58); + assign(test_msg_.stec_residuals[11].sv_id.satId, 127); + + assign(test_msg_.stec_residuals[12].residual, -26246); + assign(test_msg_.stec_residuals[12].stddev, 124); + assign(test_msg_.stec_residuals[12].sv_id.constellation, 157); + assign(test_msg_.stec_residuals[12].sv_id.satId, 80); + + assign(test_msg_.stec_residuals[13].residual, 26466); + assign(test_msg_.stec_residuals[13].stddev, 204); + assign(test_msg_.stec_residuals[13].sv_id.constellation, 128); + assign(test_msg_.stec_residuals[13].sv_id.satId, 27); + + assign(test_msg_.stec_residuals[14].residual, -7552); + assign(test_msg_.stec_residuals[14].stddev, 148); + assign(test_msg_.stec_residuals[14].sv_id.constellation, 238); + assign(test_msg_.stec_residuals[14].sv_id.satId, 75); + + assign(test_msg_.stec_residuals[15].residual, -12072); + assign(test_msg_.stec_residuals[15].stddev, 149); + assign(test_msg_.stec_residuals[15].sv_id.constellation, 61); + assign(test_msg_.stec_residuals[15].sv_id.satId, 248); + + assign(test_msg_.stec_residuals[16].residual, -28632); + assign(test_msg_.stec_residuals[16].stddev, 186); + assign(test_msg_.stec_residuals[16].sv_id.constellation, 224); + assign(test_msg_.stec_residuals[16].sv_id.satId, 167); + + assign(test_msg_.stec_residuals[17].residual, -4024); + assign(test_msg_.stec_residuals[17].stddev, 100); + assign(test_msg_.stec_residuals[17].sv_id.constellation, 227); + assign(test_msg_.stec_residuals[17].sv_id.satId, 157); + + assign(test_msg_.stec_residuals[18].residual, 2004); + assign(test_msg_.stec_residuals[18].stddev, 59); + assign(test_msg_.stec_residuals[18].sv_id.constellation, 12); + assign(test_msg_.stec_residuals[18].sv_id.satId, 35); + + assign(test_msg_.stec_residuals[19].residual, 6998); + assign(test_msg_.stec_residuals[19].stddev, 24); + assign(test_msg_.stec_residuals[19].sv_id.constellation, 81); + assign(test_msg_.stec_residuals[19].sv_id.satId, 176); + + assign(test_msg_.stec_residuals[20].residual, -31701); + assign(test_msg_.stec_residuals[20].stddev, 45); + assign(test_msg_.stec_residuals[20].sv_id.constellation, 67); + assign(test_msg_.stec_residuals[20].sv_id.satId, 155); + + assign(test_msg_.stec_residuals[21].residual, 28678); + assign(test_msg_.stec_residuals[21].stddev, 183); + assign(test_msg_.stec_residuals[21].sv_id.constellation, 44); + assign(test_msg_.stec_residuals[21].sv_id.satId, 203); + + assign(test_msg_.stec_residuals[22].residual, -15793); + assign(test_msg_.stec_residuals[22].stddev, 253); + assign(test_msg_.stec_residuals[22].sv_id.constellation, 176); + assign(test_msg_.stec_residuals[22].sv_id.satId, 231); + + assign(test_msg_.stec_residuals[23].residual, -7589); + assign(test_msg_.stec_residuals[23].stddev, 116); + assign(test_msg_.stec_residuals[23].sv_id.constellation, 103); + assign(test_msg_.stec_residuals[23].sv_id.satId, 247); + + assign(test_msg_.stec_residuals[24].residual, -7362); + assign(test_msg_.stec_residuals[24].stddev, 240); + assign(test_msg_.stec_residuals[24].sv_id.constellation, 23); + assign(test_msg_.stec_residuals[24].sv_id.satId, 148); + + assign(test_msg_.stec_residuals[25].residual, 4813); + assign(test_msg_.stec_residuals[25].stddev, 242); + assign(test_msg_.stec_residuals[25].sv_id.constellation, 219); + assign(test_msg_.stec_residuals[25].sv_id.satId, 29); + + assign(test_msg_.stec_residuals[26].residual, 20295); + assign(test_msg_.stec_residuals[26].stddev, 37); + assign(test_msg_.stec_residuals[26].sv_id.constellation, 72); + assign(test_msg_.stec_residuals[26].sv_id.satId, 207); + + assign(test_msg_.stec_residuals[27].residual, -13623); + assign(test_msg_.stec_residuals[27].stddev, 91); + assign(test_msg_.stec_residuals[27].sv_id.constellation, 176); + assign(test_msg_.stec_residuals[27].sv_id.satId, 42); + + assign(test_msg_.stec_residuals[28].residual, 15250); + assign(test_msg_.stec_residuals[28].stddev, 110); + assign(test_msg_.stec_residuals[28].sv_id.constellation, 115); + assign(test_msg_.stec_residuals[28].sv_id.satId, 105); + + assign(test_msg_.stec_residuals[29].residual, -18560); + assign(test_msg_.stec_residuals[29].stddev, 185); + assign(test_msg_.stec_residuals[29].sv_id.constellation, 109); + assign(test_msg_.stec_residuals[29].sv_id.satId, 44); + + assign(test_msg_.stec_residuals[30].residual, 23717); + assign(test_msg_.stec_residuals[30].stddev, 79); + assign(test_msg_.stec_residuals[30].sv_id.constellation, 31); + assign(test_msg_.stec_residuals[30].sv_id.satId, 67); + + assign(test_msg_.stec_residuals[31].residual, 1886); + assign(test_msg_.stec_residuals[31].stddev, 162); + assign(test_msg_.stec_residuals[31].sv_id.constellation, 180); + assign(test_msg_.stec_residuals[31].sv_id.satId, 189); + + assign(test_msg_.stec_residuals[32].residual, 12242); + assign(test_msg_.stec_residuals[32].stddev, 7); + assign(test_msg_.stec_residuals[32].sv_id.constellation, 156); + assign(test_msg_.stec_residuals[32].sv_id.satId, 121); + + assign(test_msg_.stec_residuals[33].residual, 10670); + assign(test_msg_.stec_residuals[33].stddev, 241); + assign(test_msg_.stec_residuals[33].sv_id.constellation, 205); + assign(test_msg_.stec_residuals[33].sv_id.satId, 7); + + assign(test_msg_.stec_residuals[34].residual, 25899); + assign(test_msg_.stec_residuals[34].stddev, 186); + assign(test_msg_.stec_residuals[34].sv_id.constellation, 210); + assign(test_msg_.stec_residuals[34].sv_id.satId, 129); + + assign(test_msg_.stec_residuals[35].residual, -2078); + assign(test_msg_.stec_residuals[35].stddev, 187); + assign(test_msg_.stec_residuals[35].sv_id.constellation, 195); + assign(test_msg_.stec_residuals[35].sv_id.satId, 208); + + assign(test_msg_.stec_residuals[36].residual, -16264); + assign(test_msg_.stec_residuals[36].stddev, 102); + assign(test_msg_.stec_residuals[36].sv_id.constellation, 160); + assign(test_msg_.stec_residuals[36].sv_id.satId, 219); + + assign(test_msg_.stec_residuals[37].residual, -21002); + assign(test_msg_.stec_residuals[37].stddev, 94); + assign(test_msg_.stec_residuals[37].sv_id.constellation, 42); + assign(test_msg_.stec_residuals[37].sv_id.satId, 166); + + assign(test_msg_.stec_residuals[38].residual, 7902); + assign(test_msg_.stec_residuals[38].stddev, 35); + assign(test_msg_.stec_residuals[38].sv_id.constellation, 156); + assign(test_msg_.stec_residuals[38].sv_id.satId, 102); + + assign(test_msg_.stec_residuals[39].residual, -30275); + assign(test_msg_.stec_residuals[39].stddev, 204); + assign(test_msg_.stec_residuals[39].sv_id.constellation, 64); + assign(test_msg_.stec_residuals[39].sv_id.satId, 247); + + assign(test_msg_.stec_residuals[40].residual, -8633); + assign(test_msg_.stec_residuals[40].stddev, 222); + assign(test_msg_.stec_residuals[40].sv_id.constellation, 32); + assign(test_msg_.stec_residuals[40].sv_id.satId, 220); + + assign(test_msg_.stec_residuals[41].residual, 6403); + assign(test_msg_.stec_residuals[41].stddev, 45); + assign(test_msg_.stec_residuals[41].sv_id.constellation, 246); + assign(test_msg_.stec_residuals[41].sv_id.satId, 201); + + assign(test_msg_.stec_residuals[42].residual, 22643); + assign(test_msg_.stec_residuals[42].stddev, 218); + assign(test_msg_.stec_residuals[42].sv_id.constellation, 239); + assign(test_msg_.stec_residuals[42].sv_id.satId, 251); + + assign(test_msg_.stec_residuals[43].residual, 16760); + assign(test_msg_.stec_residuals[43].stddev, 175); + assign(test_msg_.stec_residuals[43].sv_id.constellation, 209); + assign(test_msg_.stec_residuals[43].sv_id.satId, 10); + + assign(test_msg_.stec_residuals[44].residual, -20951); + assign(test_msg_.stec_residuals[44].stddev, 137); + assign(test_msg_.stec_residuals[44].sv_id.constellation, 194); + assign(test_msg_.stec_residuals[44].sv_id.satId, 131); + + assign(test_msg_.stec_residuals[45].residual, -740); + assign(test_msg_.stec_residuals[45].stddev, 42); + assign(test_msg_.stec_residuals[45].sv_id.constellation, 68); + assign(test_msg_.stec_residuals[45].sv_id.satId, 17); + assign(test_msg_.tropo_delay_correction.hydro, -3035); + assign(test_msg_.tropo_delay_correction.stddev, 72); + assign(test_msg_.tropo_delay_correction.wet, 78); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_gridded_correction_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGriddedCorrection, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGriddedCorrection); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_gridded_correction, + sizeof(msg->ssr_gridded_correction)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_gridded_correction_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_gridded_correction, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrGriddedCorrection); + info.sender_id = 63940; + info.preamble = 0x55; + info.crc = 0x23b2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 253; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_gridded_correction_t &lesser, + const sbp_msg_ssr_gridded_correction_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_gridded_correction_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_gridded_correction_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrection, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrection, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGriddedCorrection, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGriddedCorrection, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_gridded_correction_t test_msg_{}; + uint8_t encoded_frame_[253 + 8] = { + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, 174, + 229, 151, 189, 204, 196, 105, 170, 120, 149, 169, 37, 244, 78, 72, 140, + 101, 2, 173, 88, 70, 180, 54, 152, 115, 78, 201, 161, 23, 135, 152, + 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, 230, 69, 172, 191, + 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, 52, 166, 166, 120, 57, + 221, 12, 3, 156, 70, 156, 35, 127, 8, 127, 58, 128, 55, 115, 80, + 157, 122, 153, 124, 27, 128, 98, 103, 204, 75, 238, 128, 226, 148, 248, + 61, 216, 208, 149, 167, 224, 40, 144, 186, 157, 227, 72, 240, 100, 35, + 12, 212, 7, 59, 176, 81, 86, 27, 24, 155, 67, 43, 132, 45, 203, + 44, 6, 112, 183, 231, 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, + 23, 62, 227, 240, 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, + 176, 201, 202, 91, 105, 115, 146, 59, 110, 44, 109, 128, 183, 185, 67, + 31, 165, 92, 79, 189, 180, 94, 7, 162, 121, 156, 210, 47, 7, 7, + 205, 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, 219, + 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, 247, + 64, 189, 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, 45, 251, + 239, 115, 88, 218, 10, 209, 120, 65, 175, 131, 194, 41, 174, 137, 17, + 68, 28, 253, 42, 178, 35, + }; + uint8_t encoded_payload_[253] = { + 21, 14, 151, 50, 120, 133, 29, 151, 174, 229, 151, 189, 204, 196, 105, + 170, 120, 149, 169, 37, 244, 78, 72, 140, 101, 2, 173, 88, 70, 180, + 54, 152, 115, 78, 201, 161, 23, 135, 152, 98, 61, 75, 178, 120, 229, + 146, 55, 58, 169, 234, 230, 69, 172, 191, 127, 146, 89, 150, 91, 111, + 225, 41, 17, 119, 52, 166, 166, 120, 57, 221, 12, 3, 156, 70, 156, + 35, 127, 8, 127, 58, 128, 55, 115, 80, 157, 122, 153, 124, 27, 128, + 98, 103, 204, 75, 238, 128, 226, 148, 248, 61, 216, 208, 149, 167, 224, + 40, 144, 186, 157, 227, 72, 240, 100, 35, 12, 212, 7, 59, 176, 81, + 86, 27, 24, 155, 67, 43, 132, 45, 203, 44, 6, 112, 183, 231, 176, + 79, 194, 253, 247, 103, 91, 226, 116, 148, 23, 62, 227, 240, 29, 219, + 205, 18, 242, 207, 72, 71, 79, 37, 42, 176, 201, 202, 91, 105, 115, + 146, 59, 110, 44, 109, 128, 183, 185, 67, 31, 165, 92, 79, 189, 180, + 94, 7, 162, 121, 156, 210, 47, 7, 7, 205, 174, 41, 241, 129, 210, + 43, 101, 186, 208, 195, 226, 247, 187, 219, 160, 120, 192, 102, 166, 42, + 246, 173, 94, 102, 156, 222, 30, 35, 247, 64, 189, 137, 204, 220, 32, + 71, 222, 222, 201, 246, 3, 25, 45, 251, 239, 115, 88, 218, 10, 209, + 120, 65, 175, 131, 194, 41, 174, 137, 17, 68, 28, 253, 42, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGriddedCorrection, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGriddedCorrection, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + + for (uint8_t i = 0; i < 253; i++) { + EXPECT_EQ(sbp_msg_ssr_gridded_correction_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGriddedCorrection, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_gridded_correction_t t{}; + return sbp_msg_ssr_gridded_correction_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_gridded_correction_t t{}; + t.n_stec_residuals = 1; + return sbp_msg_ssr_gridded_correction_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrGriddedCorrection, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrGriddedCorrection, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrGriddedCorrection, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.iod_atmo, greater.header.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.tropo_quality_indicator, + greater.header.tropo_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.n_stec_residuals, greater.n_stec_residuals); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].residual, + greater.stec_residuals[0].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].stddev, + greater.stec_residuals[0].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.constellation, + greater.stec_residuals[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.satId, + greater.stec_residuals[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].residual, + greater.stec_residuals[1].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].stddev, + greater.stec_residuals[1].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.constellation, + greater.stec_residuals[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.satId, + greater.stec_residuals[1].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].residual, + greater.stec_residuals[2].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].stddev, + greater.stec_residuals[2].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.constellation, + greater.stec_residuals[2].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.satId, + greater.stec_residuals[2].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].residual, + greater.stec_residuals[3].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].stddev, + greater.stec_residuals[3].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.constellation, + greater.stec_residuals[3].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.satId, + greater.stec_residuals[3].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].residual, + greater.stec_residuals[4].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].stddev, + greater.stec_residuals[4].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.constellation, + greater.stec_residuals[4].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.satId, + greater.stec_residuals[4].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].residual, + greater.stec_residuals[5].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].stddev, + greater.stec_residuals[5].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.constellation, + greater.stec_residuals[5].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.satId, + greater.stec_residuals[5].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].residual, + greater.stec_residuals[6].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].stddev, + greater.stec_residuals[6].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.constellation, + greater.stec_residuals[6].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.satId, + greater.stec_residuals[6].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].residual, + greater.stec_residuals[7].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].stddev, + greater.stec_residuals[7].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.constellation, + greater.stec_residuals[7].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.satId, + greater.stec_residuals[7].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].residual, + greater.stec_residuals[8].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].stddev, + greater.stec_residuals[8].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.constellation, + greater.stec_residuals[8].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.satId, + greater.stec_residuals[8].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].residual, + greater.stec_residuals[9].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].stddev, + greater.stec_residuals[9].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.constellation, + greater.stec_residuals[9].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.satId, + greater.stec_residuals[9].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].residual, + greater.stec_residuals[10].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].stddev, + greater.stec_residuals[10].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.constellation, + greater.stec_residuals[10].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.satId, + greater.stec_residuals[10].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].residual, + greater.stec_residuals[11].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].stddev, + greater.stec_residuals[11].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.constellation, + greater.stec_residuals[11].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.satId, + greater.stec_residuals[11].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].residual, + greater.stec_residuals[12].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].stddev, + greater.stec_residuals[12].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.constellation, + greater.stec_residuals[12].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.satId, + greater.stec_residuals[12].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].residual, + greater.stec_residuals[13].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].stddev, + greater.stec_residuals[13].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.constellation, + greater.stec_residuals[13].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.satId, + greater.stec_residuals[13].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].residual, + greater.stec_residuals[14].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].stddev, + greater.stec_residuals[14].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.constellation, + greater.stec_residuals[14].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.satId, + greater.stec_residuals[14].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].residual, + greater.stec_residuals[15].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].stddev, + greater.stec_residuals[15].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.constellation, + greater.stec_residuals[15].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.satId, + greater.stec_residuals[15].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].residual, + greater.stec_residuals[16].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].stddev, + greater.stec_residuals[16].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.constellation, + greater.stec_residuals[16].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.satId, + greater.stec_residuals[16].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].residual, + greater.stec_residuals[17].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].stddev, + greater.stec_residuals[17].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.constellation, + greater.stec_residuals[17].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.satId, + greater.stec_residuals[17].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].residual, + greater.stec_residuals[18].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].stddev, + greater.stec_residuals[18].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.constellation, + greater.stec_residuals[18].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.satId, + greater.stec_residuals[18].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].residual, + greater.stec_residuals[19].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].stddev, + greater.stec_residuals[19].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.constellation, + greater.stec_residuals[19].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.satId, + greater.stec_residuals[19].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].residual, + greater.stec_residuals[20].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].stddev, + greater.stec_residuals[20].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.constellation, + greater.stec_residuals[20].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.satId, + greater.stec_residuals[20].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].residual, + greater.stec_residuals[21].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].stddev, + greater.stec_residuals[21].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.constellation, + greater.stec_residuals[21].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.satId, + greater.stec_residuals[21].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].residual, + greater.stec_residuals[22].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].stddev, + greater.stec_residuals[22].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.constellation, + greater.stec_residuals[22].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.satId, + greater.stec_residuals[22].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].residual, + greater.stec_residuals[23].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].stddev, + greater.stec_residuals[23].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.constellation, + greater.stec_residuals[23].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.satId, + greater.stec_residuals[23].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].residual, + greater.stec_residuals[24].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].stddev, + greater.stec_residuals[24].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.constellation, + greater.stec_residuals[24].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.satId, + greater.stec_residuals[24].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].residual, + greater.stec_residuals[25].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].stddev, + greater.stec_residuals[25].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.constellation, + greater.stec_residuals[25].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.satId, + greater.stec_residuals[25].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].residual, + greater.stec_residuals[26].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].stddev, + greater.stec_residuals[26].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.constellation, + greater.stec_residuals[26].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.satId, + greater.stec_residuals[26].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].residual, + greater.stec_residuals[27].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].stddev, + greater.stec_residuals[27].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.constellation, + greater.stec_residuals[27].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.satId, + greater.stec_residuals[27].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].residual, + greater.stec_residuals[28].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].stddev, + greater.stec_residuals[28].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.constellation, + greater.stec_residuals[28].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.satId, + greater.stec_residuals[28].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].residual, + greater.stec_residuals[29].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].stddev, + greater.stec_residuals[29].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.constellation, + greater.stec_residuals[29].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.satId, + greater.stec_residuals[29].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].residual, + greater.stec_residuals[30].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].stddev, + greater.stec_residuals[30].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.constellation, + greater.stec_residuals[30].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.satId, + greater.stec_residuals[30].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].residual, + greater.stec_residuals[31].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].stddev, + greater.stec_residuals[31].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.constellation, + greater.stec_residuals[31].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.satId, + greater.stec_residuals[31].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].residual, + greater.stec_residuals[32].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].stddev, + greater.stec_residuals[32].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.constellation, + greater.stec_residuals[32].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.satId, + greater.stec_residuals[32].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].residual, + greater.stec_residuals[33].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].stddev, + greater.stec_residuals[33].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.constellation, + greater.stec_residuals[33].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.satId, + greater.stec_residuals[33].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].residual, + greater.stec_residuals[34].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].stddev, + greater.stec_residuals[34].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.constellation, + greater.stec_residuals[34].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.satId, + greater.stec_residuals[34].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].residual, + greater.stec_residuals[35].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].stddev, + greater.stec_residuals[35].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.constellation, + greater.stec_residuals[35].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.satId, + greater.stec_residuals[35].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].residual, + greater.stec_residuals[36].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].stddev, + greater.stec_residuals[36].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.constellation, + greater.stec_residuals[36].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.satId, + greater.stec_residuals[36].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].residual, + greater.stec_residuals[37].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].stddev, + greater.stec_residuals[37].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.constellation, + greater.stec_residuals[37].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.satId, + greater.stec_residuals[37].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].residual, + greater.stec_residuals[38].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].stddev, + greater.stec_residuals[38].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.constellation, + greater.stec_residuals[38].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.satId, + greater.stec_residuals[38].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].residual, + greater.stec_residuals[39].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].stddev, + greater.stec_residuals[39].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.constellation, + greater.stec_residuals[39].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.satId, + greater.stec_residuals[39].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].residual, + greater.stec_residuals[40].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].stddev, + greater.stec_residuals[40].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.constellation, + greater.stec_residuals[40].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.satId, + greater.stec_residuals[40].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].residual, + greater.stec_residuals[41].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].stddev, + greater.stec_residuals[41].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.constellation, + greater.stec_residuals[41].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.satId, + greater.stec_residuals[41].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].residual, + greater.stec_residuals[42].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].stddev, + greater.stec_residuals[42].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.constellation, + greater.stec_residuals[42].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.satId, + greater.stec_residuals[42].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].residual, + greater.stec_residuals[43].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].stddev, + greater.stec_residuals[43].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.constellation, + greater.stec_residuals[43].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.satId, + greater.stec_residuals[43].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].residual, + greater.stec_residuals[44].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].stddev, + greater.stec_residuals[44].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.constellation, + greater.stec_residuals[44].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.satId, + greater.stec_residuals[44].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].residual, + greater.stec_residuals[45].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].stddev, + greater.stec_residuals[45].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.constellation, + greater.stec_residuals[45].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.satId, + greater.stec_residuals[45].sv_id.satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.hydro, + greater.tropo_delay_correction.hydro); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.stddev, + greater.tropo_delay_correction.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.wet, + greater.tropo_delay_correction.wet); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGriddedCorrection); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_GRIDDED_CORRECTION"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_gridded_correction_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_gridded_correction_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_gridded_correction, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_gridded_correction, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[253]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 253); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 253), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 253); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGriddedCorrection, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrection0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrGriddedCorrection, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds.cc index 280a6059de..13ee5492a8 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds.cc @@ -16,413 +16,2003 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0 + : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0() { + assign(test_msg_.grid_point_id, 1000); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 0); + assign(test_msg_.header.sol_id, 0); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 10); + assign(test_msg_.n_sats, 2); + assign(test_msg_.ssr_iod_atmo, 15); + + assign(test_msg_.stec_sat_list[0].stec_bound_mu, 18); + assign(test_msg_.stec_sat_list[0].stec_bound_mu_dot, 20); + assign(test_msg_.stec_sat_list[0].stec_bound_sig, 19); + assign(test_msg_.stec_sat_list[0].stec_bound_sig_dot, 21); + assign(test_msg_.stec_sat_list[0].stec_residual.residual, 16); + assign(test_msg_.stec_sat_list[0].stec_residual.stddev, 17); + assign(test_msg_.stec_sat_list[0].stec_residual.sv_id.constellation, 10); + assign(test_msg_.stec_sat_list[0].stec_residual.sv_id.satId, 5); + + assign(test_msg_.stec_sat_list[1].stec_bound_mu, 24); + assign(test_msg_.stec_sat_list[1].stec_bound_mu_dot, 26); + assign(test_msg_.stec_sat_list[1].stec_bound_sig, 25); + assign(test_msg_.stec_sat_list[1].stec_bound_sig_dot, 27); + assign(test_msg_.stec_sat_list[1].stec_residual.residual, 22); + assign(test_msg_.stec_sat_list[1].stec_residual.stddev, 23); + assign(test_msg_.stec_sat_list[1].stec_residual.sv_id.constellation, 10); + assign(test_msg_.stec_sat_list[1].stec_residual.sv_id.satId, 6); + assign(test_msg_.tile_id, 10); + assign(test_msg_.tile_set_id, 1); + assign(test_msg_.tropo_delay_correction.hydro, 500); + assign(test_msg_.tropo_delay_correction.stddev, 200); + assign(test_msg_.tropo_delay_correction.wet, 100); + assign(test_msg_.tropo_qi, 39); + assign(test_msg_.tropo_v_hydro_bound_mu, 150); + assign(test_msg_.tropo_v_hydro_bound_sig, 100); + assign(test_msg_.tropo_v_wet_bound_mu, 150); + assign(test_msg_.tropo_v_wet_bound_sig, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_gridded_correction_bounds_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_bounds_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_gridded_correction_bounds_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGriddedCorrectionBounds, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_bounds_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGriddedCorrectionBounds); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_gridded_correction_bounds, + sizeof(msg->ssr_gridded_correction_bounds)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_gridded_correction_bounds_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_gridded_correction_bounds, &test_msg_, + sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgSsrGriddedCorrectionBounds); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xB6EC; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 45; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_gridded_correction_bounds_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_gridded_correction_bounds_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests( + const sbp_msg_ssr_gridded_correction_bounds_t &lesser, + const sbp_msg_ssr_gridded_correction_bounds_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_gridded_correction_bounds_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_gridded_correction_bounds_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, + &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, + &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_gridded_correction_bounds_t test_msg_{}; + uint8_t encoded_frame_[45 + 8] = { 85, 254, 5, 66, 0, 45, 180, 0, 0, 0, 3, 0, 1, 0, 10, 0, 15, 1, 0, 10, 0, 39, 232, 3, 244, 1, 100, 200, 150, 100, 150, 100, 2, 5, 10, 16, 0, 17, 18, 19, 20, 21, 6, 10, 22, 0, 23, 24, 25, 26, 27, 236, 182, }; + uint8_t encoded_payload_[45] = { + 180, 0, 0, 0, 3, 0, 1, 0, 10, 0, 15, 1, 0, 10, 0, + 39, 232, 3, 244, 1, 100, 200, 150, 100, 150, 100, 2, 5, 10, 16, + 0, 17, 18, 19, 20, 21, 6, 10, 22, 0, 23, 24, 25, 26, 27, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + + for (uint8_t i = 0; i < 45; i++) { + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGriddedCorrectionBounds, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_gridded_correction_bounds_t t{}; + return sbp_msg_ssr_gridded_correction_bounds_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_gridded_correction_bounds_t t{}; + t.n_sats = 1; + return sbp_msg_ssr_gridded_correction_bounds_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.grid_point_id, greater.grid_point_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod_atmo, greater.ssr_iod_atmo); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_bound_mu, + greater.stec_sat_list[0].stec_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_bound_mu_dot, + greater.stec_sat_list[0].stec_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_bound_sig, + greater.stec_sat_list[0].stec_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_bound_sig_dot, + greater.stec_sat_list[0].stec_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_residual.residual, + greater.stec_sat_list[0].stec_residual.residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_residual.stddev, + greater.stec_sat_list[0].stec_residual.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater( + lesser.stec_sat_list[0].stec_residual.sv_id.constellation, + greater.stec_sat_list[0].stec_residual.sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_residual.sv_id.satId, + greater.stec_sat_list[0].stec_residual.sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_bound_mu, + greater.stec_sat_list[1].stec_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_bound_mu_dot, + greater.stec_sat_list[1].stec_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_bound_sig, + greater.stec_sat_list[1].stec_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_bound_sig_dot, + greater.stec_sat_list[1].stec_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_residual.residual, + greater.stec_sat_list[1].stec_residual.residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_residual.stddev, + greater.stec_sat_list[1].stec_residual.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater( + lesser.stec_sat_list[1].stec_residual.sv_id.constellation, + greater.stec_sat_list[1].stec_residual.sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_residual.sv_id.satId, + greater.stec_sat_list[1].stec_residual.sv_id.satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.hydro, + greater.tropo_delay_correction.hydro); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.stddev, + greater.tropo_delay_correction.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.wet, + greater.tropo_delay_correction.wet); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_qi, greater.tropo_qi); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_hydro_bound_mu, + greater.tropo_v_hydro_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_hydro_bound_sig, + greater.tropo_v_hydro_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_wet_bound_mu, + greater.tropo_v_wet_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_wet_bound_sig, + greater.tropo_v_wet_bound_sig); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGriddedCorrectionBounds); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_SSR_GRIDDED_CORRECTION_BOUNDS"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_gridded_correction_bounds_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_gridded_correction_bounds_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_gridded_correction_bounds, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_gridded_correction_bounds, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[45]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 45); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 45), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 45); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - sbp_msg_ssr_gridded_correction_bounds_t test_msg{}; - test_msg.grid_point_id = 1000; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 0; - test_msg.header.sol_id = 0; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 10; - test_msg.n_sats = 2; - test_msg.ssr_iod_atmo = 15; - - test_msg.stec_sat_list[0].stec_bound_mu = 18; - test_msg.stec_sat_list[0].stec_bound_mu_dot = 20; - test_msg.stec_sat_list[0].stec_bound_sig = 19; - test_msg.stec_sat_list[0].stec_bound_sig_dot = 21; - test_msg.stec_sat_list[0].stec_residual.residual = 16; - test_msg.stec_sat_list[0].stec_residual.stddev = 17; - test_msg.stec_sat_list[0].stec_residual.sv_id.constellation = 10; - test_msg.stec_sat_list[0].stec_residual.sv_id.satId = 5; - - test_msg.stec_sat_list[1].stec_bound_mu = 24; - test_msg.stec_sat_list[1].stec_bound_mu_dot = 26; - test_msg.stec_sat_list[1].stec_bound_sig = 25; - test_msg.stec_sat_list[1].stec_bound_sig_dot = 27; - test_msg.stec_sat_list[1].stec_residual.residual = 22; - test_msg.stec_sat_list[1].stec_residual.stddev = 23; - test_msg.stec_sat_list[1].stec_residual.sv_id.constellation = 10; - test_msg.stec_sat_list[1].stec_residual.sv_id.satId = 6; - test_msg.tile_id = 10; - test_msg.tile_set_id = 1; - test_msg.tropo_delay_correction.hydro = 500; - test_msg.tropo_delay_correction.stddev = 200; - test_msg.tropo_delay_correction.wet = 100; - test_msg.tropo_qi = 39; - test_msg.tropo_v_hydro_bound_mu = 150; - test_msg.tropo_v_hydro_bound_sig = 100; - test_msg.tropo_v_wet_bound_mu = 150; - test_msg.tropo_v_wet_bound_sig = 100; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.grid_point_id, 1000) - << "incorrect value for last_msg_.grid_point_id, expected 1000, is " - << last_msg_.grid_point_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 0) - << "incorrect value for last_msg_.header.seq_num, expected 0, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 0) - << "incorrect value for last_msg_.header.sol_id, expected 0, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 10) - << "incorrect value for last_msg_.header.update_interval, expected 10, " - "is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.n_sats, 2) - << "incorrect value for last_msg_.n_sats, expected 2, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.ssr_iod_atmo, 15) - << "incorrect value for last_msg_.ssr_iod_atmo, expected 15, is " - << last_msg_.ssr_iod_atmo; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_bound_mu, 18) - << "incorrect value for last_msg_.stec_sat_list[0].stec_bound_mu, " - "expected 18, is " - << last_msg_.stec_sat_list[0].stec_bound_mu; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_bound_mu_dot, 20) - << "incorrect value for last_msg_.stec_sat_list[0].stec_bound_mu_dot, " - "expected 20, is " - << last_msg_.stec_sat_list[0].stec_bound_mu_dot; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_bound_sig, 19) - << "incorrect value for last_msg_.stec_sat_list[0].stec_bound_sig, " - "expected 19, is " - << last_msg_.stec_sat_list[0].stec_bound_sig; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_bound_sig_dot, 21) - << "incorrect value for last_msg_.stec_sat_list[0].stec_bound_sig_dot, " - "expected 21, is " - << last_msg_.stec_sat_list[0].stec_bound_sig_dot; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_residual.residual, 16) - << "incorrect value for " - "last_msg_.stec_sat_list[0].stec_residual.residual, expected 16, is " - << last_msg_.stec_sat_list[0].stec_residual.residual; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_residual.stddev, 17) - << "incorrect value for last_msg_.stec_sat_list[0].stec_residual.stddev, " - "expected 17, is " - << last_msg_.stec_sat_list[0].stec_residual.stddev; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_residual.sv_id.constellation, 10) - << "incorrect value for " - "last_msg_.stec_sat_list[0].stec_residual.sv_id.constellation, " - "expected 10, is " - << last_msg_.stec_sat_list[0].stec_residual.sv_id.constellation; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_residual.sv_id.satId, 5) - << "incorrect value for " - "last_msg_.stec_sat_list[0].stec_residual.sv_id.satId, expected 5, is " - << last_msg_.stec_sat_list[0].stec_residual.sv_id.satId; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_bound_mu, 24) - << "incorrect value for last_msg_.stec_sat_list[1].stec_bound_mu, " - "expected 24, is " - << last_msg_.stec_sat_list[1].stec_bound_mu; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_bound_mu_dot, 26) - << "incorrect value for last_msg_.stec_sat_list[1].stec_bound_mu_dot, " - "expected 26, is " - << last_msg_.stec_sat_list[1].stec_bound_mu_dot; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_bound_sig, 25) - << "incorrect value for last_msg_.stec_sat_list[1].stec_bound_sig, " - "expected 25, is " - << last_msg_.stec_sat_list[1].stec_bound_sig; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_bound_sig_dot, 27) - << "incorrect value for last_msg_.stec_sat_list[1].stec_bound_sig_dot, " - "expected 27, is " - << last_msg_.stec_sat_list[1].stec_bound_sig_dot; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_residual.residual, 22) - << "incorrect value for " - "last_msg_.stec_sat_list[1].stec_residual.residual, expected 22, is " - << last_msg_.stec_sat_list[1].stec_residual.residual; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_residual.stddev, 23) - << "incorrect value for last_msg_.stec_sat_list[1].stec_residual.stddev, " - "expected 23, is " - << last_msg_.stec_sat_list[1].stec_residual.stddev; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_residual.sv_id.constellation, 10) - << "incorrect value for " - "last_msg_.stec_sat_list[1].stec_residual.sv_id.constellation, " - "expected 10, is " - << last_msg_.stec_sat_list[1].stec_residual.sv_id.constellation; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_residual.sv_id.satId, 6) - << "incorrect value for " - "last_msg_.stec_sat_list[1].stec_residual.sv_id.satId, expected 6, is " - << last_msg_.stec_sat_list[1].stec_residual.sv_id.satId; - EXPECT_EQ(last_msg_.tile_id, 10) - << "incorrect value for last_msg_.tile_id, expected 10, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 1) - << "incorrect value for last_msg_.tile_set_id, expected 1, is " - << last_msg_.tile_set_id; - EXPECT_EQ(last_msg_.tropo_delay_correction.hydro, 500) - << "incorrect value for last_msg_.tropo_delay_correction.hydro, expected " - "500, is " - << last_msg_.tropo_delay_correction.hydro; - EXPECT_EQ(last_msg_.tropo_delay_correction.stddev, 200) - << "incorrect value for last_msg_.tropo_delay_correction.stddev, " - "expected 200, is " - << last_msg_.tropo_delay_correction.stddev; - EXPECT_EQ(last_msg_.tropo_delay_correction.wet, 100) - << "incorrect value for last_msg_.tropo_delay_correction.wet, expected " - "100, is " - << last_msg_.tropo_delay_correction.wet; - EXPECT_EQ(last_msg_.tropo_qi, 39) - << "incorrect value for last_msg_.tropo_qi, expected 39, is " - << last_msg_.tropo_qi; - EXPECT_EQ(last_msg_.tropo_v_hydro_bound_mu, 150) - << "incorrect value for last_msg_.tropo_v_hydro_bound_mu, expected 150, " - "is " - << last_msg_.tropo_v_hydro_bound_mu; - EXPECT_EQ(last_msg_.tropo_v_hydro_bound_sig, 100) - << "incorrect value for last_msg_.tropo_v_hydro_bound_sig, expected 100, " - "is " - << last_msg_.tropo_v_hydro_bound_sig; - EXPECT_EQ(last_msg_.tropo_v_wet_bound_mu, 150) - << "incorrect value for last_msg_.tropo_v_wet_bound_mu, expected 150, is " - << last_msg_.tropo_v_wet_bound_mu; - EXPECT_EQ(last_msg_.tropo_v_wet_bound_sig, 100) - << "incorrect value for last_msg_.tropo_v_wet_bound_sig, expected 100, " - "is " - << last_msg_.tropo_v_wet_bound_sig; -} -class Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrGriddedCorrectionBounds, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1 + : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1() { + assign(test_msg_.grid_point_id, 1000); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 0); + assign(test_msg_.header.sol_id, 0); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 10); + assign(test_msg_.n_sats, 0); + assign(test_msg_.ssr_iod_atmo, 15); + assign(test_msg_.tile_id, 10); + assign(test_msg_.tile_set_id, 1); + assign(test_msg_.tropo_delay_correction.hydro, 500); + assign(test_msg_.tropo_delay_correction.stddev, 200); + assign(test_msg_.tropo_delay_correction.wet, 100); + assign(test_msg_.tropo_qi, 39); + assign(test_msg_.tropo_v_hydro_bound_mu, 150); + assign(test_msg_.tropo_v_hydro_bound_sig, 100); + assign(test_msg_.tropo_v_wet_bound_mu, 150); + assign(test_msg_.tropo_v_wet_bound_sig, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_gridded_correction_bounds_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_bounds_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_gridded_correction_bounds_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGriddedCorrectionBounds, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_bounds_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGriddedCorrectionBounds); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_gridded_correction_bounds, + sizeof(msg->ssr_gridded_correction_bounds)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_gridded_correction_bounds_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_gridded_correction_bounds, &test_msg_, + sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgSsrGriddedCorrectionBounds); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x249B; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 27; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_gridded_correction_bounds_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_gridded_correction_bounds_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests( + const sbp_msg_ssr_gridded_correction_bounds_t &lesser, + const sbp_msg_ssr_gridded_correction_bounds_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_gridded_correction_bounds_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_gridded_correction_bounds_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, + &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGriddedCorrectionBounds, + &wrapped_greater, &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_gridded_correction_bounds_t test_msg_{}; + uint8_t encoded_frame_[27 + 8] = { 85, 254, 5, 66, 0, 27, 180, 0, 0, 0, 3, 0, 1, 0, 10, 0, 15, 1, 0, 10, 0, 39, 232, 3, 244, 1, 100, 200, 150, 100, 150, 100, 0, 155, 36, }; + uint8_t encoded_payload_[27] = { + 180, 0, 0, 0, 3, 0, 1, 0, 10, 0, 15, 1, 0, 10, + 0, 39, 232, 3, 244, 1, 100, 200, 150, 100, 150, 100, 0, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + + for (uint8_t i = 0; i < 27; i++) { + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGriddedCorrectionBounds, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ssr_gridded_correction_bounds_t test_msg{}; - test_msg.grid_point_id = 1000; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 0; - test_msg.header.sol_id = 0; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 10; - test_msg.n_sats = 0; - test_msg.ssr_iod_atmo = 15; - test_msg.tile_id = 10; - test_msg.tile_set_id = 1; - test_msg.tropo_delay_correction.hydro = 500; - test_msg.tropo_delay_correction.stddev = 200; - test_msg.tropo_delay_correction.wet = 100; - test_msg.tropo_qi = 39; - test_msg.tropo_v_hydro_bound_mu = 150; - test_msg.tropo_v_hydro_bound_sig = 100; - test_msg.tropo_v_wet_bound_mu = 150; - test_msg.tropo_v_wet_bound_sig = 100; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.grid_point_id, 1000) - << "incorrect value for last_msg_.grid_point_id, expected 1000, is " - << last_msg_.grid_point_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 0) - << "incorrect value for last_msg_.header.seq_num, expected 0, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 0) - << "incorrect value for last_msg_.header.sol_id, expected 0, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 10) - << "incorrect value for last_msg_.header.update_interval, expected 10, " - "is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.n_sats, 0) - << "incorrect value for last_msg_.n_sats, expected 0, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.ssr_iod_atmo, 15) - << "incorrect value for last_msg_.ssr_iod_atmo, expected 15, is " - << last_msg_.ssr_iod_atmo; - EXPECT_EQ(last_msg_.tile_id, 10) - << "incorrect value for last_msg_.tile_id, expected 10, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 1) - << "incorrect value for last_msg_.tile_set_id, expected 1, is " - << last_msg_.tile_set_id; - EXPECT_EQ(last_msg_.tropo_delay_correction.hydro, 500) - << "incorrect value for last_msg_.tropo_delay_correction.hydro, expected " - "500, is " - << last_msg_.tropo_delay_correction.hydro; - EXPECT_EQ(last_msg_.tropo_delay_correction.stddev, 200) - << "incorrect value for last_msg_.tropo_delay_correction.stddev, " - "expected 200, is " - << last_msg_.tropo_delay_correction.stddev; - EXPECT_EQ(last_msg_.tropo_delay_correction.wet, 100) - << "incorrect value for last_msg_.tropo_delay_correction.wet, expected " - "100, is " - << last_msg_.tropo_delay_correction.wet; - EXPECT_EQ(last_msg_.tropo_qi, 39) - << "incorrect value for last_msg_.tropo_qi, expected 39, is " - << last_msg_.tropo_qi; - EXPECT_EQ(last_msg_.tropo_v_hydro_bound_mu, 150) - << "incorrect value for last_msg_.tropo_v_hydro_bound_mu, expected 150, " - "is " - << last_msg_.tropo_v_hydro_bound_mu; - EXPECT_EQ(last_msg_.tropo_v_hydro_bound_sig, 100) - << "incorrect value for last_msg_.tropo_v_hydro_bound_sig, expected 100, " - "is " - << last_msg_.tropo_v_hydro_bound_sig; - EXPECT_EQ(last_msg_.tropo_v_wet_bound_mu, 150) - << "incorrect value for last_msg_.tropo_v_wet_bound_mu, expected 150, is " - << last_msg_.tropo_v_wet_bound_mu; - EXPECT_EQ(last_msg_.tropo_v_wet_bound_sig, 100) - << "incorrect value for last_msg_.tropo_v_wet_bound_sig, expected 100, " - "is " - << last_msg_.tropo_v_wet_bound_sig; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_bounds_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionBounds, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.grid_point_id, greater.grid_point_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod_atmo, greater.ssr_iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.hydro, + greater.tropo_delay_correction.hydro); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.stddev, + greater.tropo_delay_correction.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.wet, + greater.tropo_delay_correction.wet); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_qi, greater.tropo_qi); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_hydro_bound_mu, + greater.tropo_v_hydro_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_hydro_bound_sig, + greater.tropo_v_hydro_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_wet_bound_mu, + greater.tropo_v_wet_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_bounds_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_v_wet_bound_sig, + greater.tropo_v_wet_bound_sig); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGriddedCorrectionBounds); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_SSR_GRIDDED_CORRECTION_BOUNDS"); } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_gridded_correction_bounds_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_gridded_correction_bounds_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_gridded_correction_bounds, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_gridded_correction_bounds, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGriddedCorrectionBounds, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionBounds1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrGriddedCorrectionBounds, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc new file mode 100644 index 0000000000..94909969cb --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc @@ -0,0 +1,2536 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0() { + assign(test_msg_.header.iod_atmo, 245); + assign(test_msg_.header.num_msgs, 37695); + assign(test_msg_.header.seq_num, 64616); + assign(test_msg_.header.time.tow, 892131748); + assign(test_msg_.header.time.wn, 23906); + assign(test_msg_.header.tropo_quality_indicator, 28); + assign(test_msg_.header.update_interval, 133); + assign(test_msg_.index, 25695); + assign(test_msg_.n_stec_residuals, 47); + + assign(test_msg_.stec_residuals[0].residual, -26738); + assign(test_msg_.stec_residuals[0].stddev, 74); + assign(test_msg_.stec_residuals[0].sv_id.constellation, 25); + assign(test_msg_.stec_residuals[0].sv_id.satId, 87); + + assign(test_msg_.stec_residuals[1].residual, 1886); + assign(test_msg_.stec_residuals[1].stddev, 146); + assign(test_msg_.stec_residuals[1].sv_id.constellation, 95); + assign(test_msg_.stec_residuals[1].sv_id.satId, 151); + + assign(test_msg_.stec_residuals[2].residual, 22183); + assign(test_msg_.stec_residuals[2].stddev, 42); + assign(test_msg_.stec_residuals[2].sv_id.constellation, 45); + assign(test_msg_.stec_residuals[2].sv_id.satId, 237); + + assign(test_msg_.stec_residuals[3].residual, -5463); + assign(test_msg_.stec_residuals[3].stddev, 220); + assign(test_msg_.stec_residuals[3].sv_id.constellation, 224); + assign(test_msg_.stec_residuals[3].sv_id.satId, 116); + + assign(test_msg_.stec_residuals[4].residual, 3346); + assign(test_msg_.stec_residuals[4].stddev, 178); + assign(test_msg_.stec_residuals[4].sv_id.constellation, 176); + assign(test_msg_.stec_residuals[4].sv_id.satId, 23); + + assign(test_msg_.stec_residuals[5].residual, 28320); + assign(test_msg_.stec_residuals[5].stddev, 15); + assign(test_msg_.stec_residuals[5].sv_id.constellation, 160); + assign(test_msg_.stec_residuals[5].sv_id.satId, 79); + + assign(test_msg_.stec_residuals[6].residual, -24937); + assign(test_msg_.stec_residuals[6].stddev, 22); + assign(test_msg_.stec_residuals[6].sv_id.constellation, 206); + assign(test_msg_.stec_residuals[6].sv_id.satId, 53); + + assign(test_msg_.stec_residuals[7].residual, -21968); + assign(test_msg_.stec_residuals[7].stddev, 82); + assign(test_msg_.stec_residuals[7].sv_id.constellation, 184); + assign(test_msg_.stec_residuals[7].sv_id.satId, 117); + + assign(test_msg_.stec_residuals[8].residual, 17786); + assign(test_msg_.stec_residuals[8].stddev, 180); + assign(test_msg_.stec_residuals[8].sv_id.constellation, 53); + assign(test_msg_.stec_residuals[8].sv_id.satId, 40); + + assign(test_msg_.stec_residuals[9].residual, 26689); + assign(test_msg_.stec_residuals[9].stddev, 244); + assign(test_msg_.stec_residuals[9].sv_id.constellation, 38); + assign(test_msg_.stec_residuals[9].sv_id.satId, 110); + + assign(test_msg_.stec_residuals[10].residual, 22755); + assign(test_msg_.stec_residuals[10].stddev, 169); + assign(test_msg_.stec_residuals[10].sv_id.constellation, 238); + assign(test_msg_.stec_residuals[10].sv_id.satId, 19); + + assign(test_msg_.stec_residuals[11].residual, 9535); + assign(test_msg_.stec_residuals[11].stddev, 183); + assign(test_msg_.stec_residuals[11].sv_id.constellation, 146); + assign(test_msg_.stec_residuals[11].sv_id.satId, 164); + + assign(test_msg_.stec_residuals[12].residual, -22293); + assign(test_msg_.stec_residuals[12].stddev, 114); + assign(test_msg_.stec_residuals[12].sv_id.constellation, 71); + assign(test_msg_.stec_residuals[12].sv_id.satId, 85); + + assign(test_msg_.stec_residuals[13].residual, -25379); + assign(test_msg_.stec_residuals[13].stddev, 60); + assign(test_msg_.stec_residuals[13].sv_id.constellation, 105); + assign(test_msg_.stec_residuals[13].sv_id.satId, 211); + + assign(test_msg_.stec_residuals[14].residual, -29182); + assign(test_msg_.stec_residuals[14].stddev, 172); + assign(test_msg_.stec_residuals[14].sv_id.constellation, 230); + assign(test_msg_.stec_residuals[14].sv_id.satId, 18); + + assign(test_msg_.stec_residuals[15].residual, 32289); + assign(test_msg_.stec_residuals[15].stddev, 106); + assign(test_msg_.stec_residuals[15].sv_id.constellation, 39); + assign(test_msg_.stec_residuals[15].sv_id.satId, 16); + + assign(test_msg_.stec_residuals[16].residual, 10730); + assign(test_msg_.stec_residuals[16].stddev, 162); + assign(test_msg_.stec_residuals[16].sv_id.constellation, 188); + assign(test_msg_.stec_residuals[16].sv_id.satId, 99); + + assign(test_msg_.stec_residuals[17].residual, 20707); + assign(test_msg_.stec_residuals[17].stddev, 12); + assign(test_msg_.stec_residuals[17].sv_id.constellation, 138); + assign(test_msg_.stec_residuals[17].sv_id.satId, 197); + + assign(test_msg_.stec_residuals[18].residual, 1518); + assign(test_msg_.stec_residuals[18].stddev, 93); + assign(test_msg_.stec_residuals[18].sv_id.constellation, 67); + assign(test_msg_.stec_residuals[18].sv_id.satId, 54); + + assign(test_msg_.stec_residuals[19].residual, 3457); + assign(test_msg_.stec_residuals[19].stddev, 46); + assign(test_msg_.stec_residuals[19].sv_id.constellation, 207); + assign(test_msg_.stec_residuals[19].sv_id.satId, 1); + + assign(test_msg_.stec_residuals[20].residual, -18118); + assign(test_msg_.stec_residuals[20].stddev, 127); + assign(test_msg_.stec_residuals[20].sv_id.constellation, 49); + assign(test_msg_.stec_residuals[20].sv_id.satId, 115); + + assign(test_msg_.stec_residuals[21].residual, -9888); + assign(test_msg_.stec_residuals[21].stddev, 202); + assign(test_msg_.stec_residuals[21].sv_id.constellation, 200); + assign(test_msg_.stec_residuals[21].sv_id.satId, 156); + + assign(test_msg_.stec_residuals[22].residual, -14793); + assign(test_msg_.stec_residuals[22].stddev, 81); + assign(test_msg_.stec_residuals[22].sv_id.constellation, 245); + assign(test_msg_.stec_residuals[22].sv_id.satId, 15); + + assign(test_msg_.stec_residuals[23].residual, 18758); + assign(test_msg_.stec_residuals[23].stddev, 82); + assign(test_msg_.stec_residuals[23].sv_id.constellation, 132); + assign(test_msg_.stec_residuals[23].sv_id.satId, 218); + + assign(test_msg_.stec_residuals[24].residual, 3839); + assign(test_msg_.stec_residuals[24].stddev, 134); + assign(test_msg_.stec_residuals[24].sv_id.constellation, 26); + assign(test_msg_.stec_residuals[24].sv_id.satId, 147); + + assign(test_msg_.stec_residuals[25].residual, -10697); + assign(test_msg_.stec_residuals[25].stddev, 83); + assign(test_msg_.stec_residuals[25].sv_id.constellation, 138); + assign(test_msg_.stec_residuals[25].sv_id.satId, 96); + + assign(test_msg_.stec_residuals[26].residual, 20387); + assign(test_msg_.stec_residuals[26].stddev, 173); + assign(test_msg_.stec_residuals[26].sv_id.constellation, 170); + assign(test_msg_.stec_residuals[26].sv_id.satId, 156); + + assign(test_msg_.stec_residuals[27].residual, -3789); + assign(test_msg_.stec_residuals[27].stddev, 107); + assign(test_msg_.stec_residuals[27].sv_id.constellation, 115); + assign(test_msg_.stec_residuals[27].sv_id.satId, 228); + + assign(test_msg_.stec_residuals[28].residual, -11608); + assign(test_msg_.stec_residuals[28].stddev, 10); + assign(test_msg_.stec_residuals[28].sv_id.constellation, 112); + assign(test_msg_.stec_residuals[28].sv_id.satId, 245); + + assign(test_msg_.stec_residuals[29].residual, 14593); + assign(test_msg_.stec_residuals[29].stddev, 108); + assign(test_msg_.stec_residuals[29].sv_id.constellation, 117); + assign(test_msg_.stec_residuals[29].sv_id.satId, 5); + + assign(test_msg_.stec_residuals[30].residual, 30609); + assign(test_msg_.stec_residuals[30].stddev, 226); + assign(test_msg_.stec_residuals[30].sv_id.constellation, 212); + assign(test_msg_.stec_residuals[30].sv_id.satId, 248); + + assign(test_msg_.stec_residuals[31].residual, -13683); + assign(test_msg_.stec_residuals[31].stddev, 106); + assign(test_msg_.stec_residuals[31].sv_id.constellation, 5); + assign(test_msg_.stec_residuals[31].sv_id.satId, 165); + + assign(test_msg_.stec_residuals[32].residual, 15652); + assign(test_msg_.stec_residuals[32].stddev, 243); + assign(test_msg_.stec_residuals[32].sv_id.constellation, 60); + assign(test_msg_.stec_residuals[32].sv_id.satId, 0); + + assign(test_msg_.stec_residuals[33].residual, 3287); + assign(test_msg_.stec_residuals[33].stddev, 137); + assign(test_msg_.stec_residuals[33].sv_id.constellation, 216); + assign(test_msg_.stec_residuals[33].sv_id.satId, 203); + + assign(test_msg_.stec_residuals[34].residual, 29687); + assign(test_msg_.stec_residuals[34].stddev, 152); + assign(test_msg_.stec_residuals[34].sv_id.constellation, 28); + assign(test_msg_.stec_residuals[34].sv_id.satId, 16); + + assign(test_msg_.stec_residuals[35].residual, -6960); + assign(test_msg_.stec_residuals[35].stddev, 203); + assign(test_msg_.stec_residuals[35].sv_id.constellation, 119); + assign(test_msg_.stec_residuals[35].sv_id.satId, 181); + + assign(test_msg_.stec_residuals[36].residual, -15193); + assign(test_msg_.stec_residuals[36].stddev, 32); + assign(test_msg_.stec_residuals[36].sv_id.constellation, 34); + assign(test_msg_.stec_residuals[36].sv_id.satId, 236); + + assign(test_msg_.stec_residuals[37].residual, 25873); + assign(test_msg_.stec_residuals[37].stddev, 200); + assign(test_msg_.stec_residuals[37].sv_id.constellation, 1); + assign(test_msg_.stec_residuals[37].sv_id.satId, 109); + + assign(test_msg_.stec_residuals[38].residual, -22403); + assign(test_msg_.stec_residuals[38].stddev, 137); + assign(test_msg_.stec_residuals[38].sv_id.constellation, 94); + assign(test_msg_.stec_residuals[38].sv_id.satId, 25); + + assign(test_msg_.stec_residuals[39].residual, 7588); + assign(test_msg_.stec_residuals[39].stddev, 31); + assign(test_msg_.stec_residuals[39].sv_id.constellation, 4); + assign(test_msg_.stec_residuals[39].sv_id.satId, 157); + + assign(test_msg_.stec_residuals[40].residual, -6840); + assign(test_msg_.stec_residuals[40].stddev, 126); + assign(test_msg_.stec_residuals[40].sv_id.constellation, 132); + assign(test_msg_.stec_residuals[40].sv_id.satId, 48); + + assign(test_msg_.stec_residuals[41].residual, -31412); + assign(test_msg_.stec_residuals[41].stddev, 21); + assign(test_msg_.stec_residuals[41].sv_id.constellation, 68); + assign(test_msg_.stec_residuals[41].sv_id.satId, 186); + + assign(test_msg_.stec_residuals[42].residual, -23413); + assign(test_msg_.stec_residuals[42].stddev, 148); + assign(test_msg_.stec_residuals[42].sv_id.constellation, 180); + assign(test_msg_.stec_residuals[42].sv_id.satId, 0); + + assign(test_msg_.stec_residuals[43].residual, 30934); + assign(test_msg_.stec_residuals[43].stddev, 177); + assign(test_msg_.stec_residuals[43].sv_id.constellation, 149); + assign(test_msg_.stec_residuals[43].sv_id.satId, 119); + + assign(test_msg_.stec_residuals[44].residual, 26960); + assign(test_msg_.stec_residuals[44].stddev, 10); + assign(test_msg_.stec_residuals[44].sv_id.constellation, 80); + assign(test_msg_.stec_residuals[44].sv_id.satId, 201); + + assign(test_msg_.stec_residuals[45].residual, 11853); + assign(test_msg_.stec_residuals[45].stddev, 233); + assign(test_msg_.stec_residuals[45].sv_id.constellation, 118); + assign(test_msg_.stec_residuals[45].sv_id.satId, 136); + + assign(test_msg_.stec_residuals[46].residual, -25077); + assign(test_msg_.stec_residuals[46].stddev, 103); + assign(test_msg_.stec_residuals[46].sv_id.constellation, 227); + assign(test_msg_.stec_residuals[46].sv_id.satId, 233); + assign(test_msg_.tropo_delay_correction.hydro, 10643); + assign(test_msg_.tropo_delay_correction.stddev, 92); + assign(test_msg_.tropo_delay_correction.wet, 33); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_gridded_correction_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_gridded_correction_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGriddedCorrectionDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGriddedCorrectionDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_gridded_correction_dep_a, + sizeof(msg->ssr_gridded_correction_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_gridded_correction_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_gridded_correction_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrGriddedCorrectionDepA); + info.sender_id = 27244; + info.preamble = 0x55; + info.crc = 0xd8a7; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 254; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_gridded_correction_dep_a_t &lesser, + const sbp_msg_ssr_gridded_correction_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_gridded_correction_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_gridded_correction_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGriddedCorrectionDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGriddedCorrectionDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_gridded_correction_dep_a_t test_msg_{}; + uint8_t encoded_frame_[254 + 8] = { + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, 104, + 252, 133, 245, 28, 95, 100, 147, 41, 33, 92, 87, 25, 142, 151, 74, + 151, 95, 94, 7, 146, 237, 45, 167, 86, 42, 116, 224, 169, 234, 220, + 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, 206, 151, 158, 22, + 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, 110, 38, 65, 104, 244, + 19, 238, 227, 88, 169, 164, 146, 63, 37, 183, 85, 71, 235, 168, 114, + 211, 105, 221, 156, 60, 18, 230, 2, 142, 172, 16, 39, 33, 126, 106, + 99, 188, 234, 41, 162, 197, 138, 227, 80, 12, 54, 67, 238, 5, 93, + 1, 207, 129, 13, 46, 115, 49, 58, 185, 127, 156, 200, 96, 217, 202, + 15, 245, 55, 198, 81, 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, + 96, 138, 55, 214, 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, + 245, 112, 168, 210, 10, 5, 117, 1, 57, 108, 248, 212, 145, 119, 226, + 165, 5, 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, 215, 12, 137, + 16, 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, 31, + 48, 132, 72, 229, 126, 186, 68, 76, 133, 21, 0, 180, 139, 164, 148, + 119, 149, 214, 120, 177, 201, 80, 80, 105, 10, 136, 118, 77, 46, 233, + 233, 227, 11, 158, 103, 167, 216, + }; + uint8_t encoded_payload_[254] = { + 164, 217, 44, 53, 98, 93, 63, 147, 104, 252, 133, 245, 28, 95, 100, + 147, 41, 33, 92, 87, 25, 142, 151, 74, 151, 95, 94, 7, 146, 237, + 45, 167, 86, 42, 116, 224, 169, 234, 220, 23, 176, 18, 13, 178, 79, + 160, 160, 110, 15, 53, 206, 151, 158, 22, 117, 184, 48, 170, 82, 40, + 53, 122, 69, 180, 110, 38, 65, 104, 244, 19, 238, 227, 88, 169, 164, + 146, 63, 37, 183, 85, 71, 235, 168, 114, 211, 105, 221, 156, 60, 18, + 230, 2, 142, 172, 16, 39, 33, 126, 106, 99, 188, 234, 41, 162, 197, + 138, 227, 80, 12, 54, 67, 238, 5, 93, 1, 207, 129, 13, 46, 115, + 49, 58, 185, 127, 156, 200, 96, 217, 202, 15, 245, 55, 198, 81, 218, + 132, 70, 73, 82, 147, 26, 255, 14, 134, 96, 138, 55, 214, 83, 156, + 170, 163, 79, 173, 228, 115, 51, 241, 107, 245, 112, 168, 210, 10, 5, + 117, 1, 57, 108, 248, 212, 145, 119, 226, 165, 5, 141, 202, 106, 0, + 60, 36, 61, 243, 203, 216, 215, 12, 137, 16, 28, 247, 115, 152, 181, + 119, 208, 228, 203, 236, 34, 167, 196, 32, 109, 1, 17, 101, 200, 25, + 94, 125, 168, 137, 157, 4, 164, 29, 31, 48, 132, 72, 229, 126, 186, + 68, 76, 133, 21, 0, 180, 139, 164, 148, 119, 149, 214, 120, 177, 201, + 80, 80, 105, 10, 136, 118, 77, 46, 233, 233, 227, 11, 158, 103, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGriddedCorrectionDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGriddedCorrectionDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + for (uint8_t i = 0; i < 254; i++) { + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGriddedCorrectionDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_gridded_correction_dep_a_t t{}; + return sbp_msg_ssr_gridded_correction_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_gridded_correction_dep_a_t t{}; + t.n_stec_residuals = 1; + return sbp_msg_ssr_gridded_correction_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrGriddedCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.iod_atmo, greater.header.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.tropo_quality_indicator, + greater.header.tropo_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_stec_residuals, greater.n_stec_residuals); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].residual, + greater.stec_residuals[0].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].stddev, + greater.stec_residuals[0].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.constellation, + greater.stec_residuals[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.satId, + greater.stec_residuals[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].residual, + greater.stec_residuals[1].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].stddev, + greater.stec_residuals[1].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.constellation, + greater.stec_residuals[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.satId, + greater.stec_residuals[1].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].residual, + greater.stec_residuals[2].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].stddev, + greater.stec_residuals[2].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.constellation, + greater.stec_residuals[2].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.satId, + greater.stec_residuals[2].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].residual, + greater.stec_residuals[3].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].stddev, + greater.stec_residuals[3].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.constellation, + greater.stec_residuals[3].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.satId, + greater.stec_residuals[3].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].residual, + greater.stec_residuals[4].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].stddev, + greater.stec_residuals[4].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.constellation, + greater.stec_residuals[4].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.satId, + greater.stec_residuals[4].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].residual, + greater.stec_residuals[5].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].stddev, + greater.stec_residuals[5].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.constellation, + greater.stec_residuals[5].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.satId, + greater.stec_residuals[5].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].residual, + greater.stec_residuals[6].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].stddev, + greater.stec_residuals[6].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.constellation, + greater.stec_residuals[6].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.satId, + greater.stec_residuals[6].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].residual, + greater.stec_residuals[7].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].stddev, + greater.stec_residuals[7].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.constellation, + greater.stec_residuals[7].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.satId, + greater.stec_residuals[7].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].residual, + greater.stec_residuals[8].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].stddev, + greater.stec_residuals[8].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.constellation, + greater.stec_residuals[8].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.satId, + greater.stec_residuals[8].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].residual, + greater.stec_residuals[9].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].stddev, + greater.stec_residuals[9].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.constellation, + greater.stec_residuals[9].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.satId, + greater.stec_residuals[9].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].residual, + greater.stec_residuals[10].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].stddev, + greater.stec_residuals[10].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.constellation, + greater.stec_residuals[10].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.satId, + greater.stec_residuals[10].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].residual, + greater.stec_residuals[11].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].stddev, + greater.stec_residuals[11].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.constellation, + greater.stec_residuals[11].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.satId, + greater.stec_residuals[11].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].residual, + greater.stec_residuals[12].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].stddev, + greater.stec_residuals[12].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.constellation, + greater.stec_residuals[12].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.satId, + greater.stec_residuals[12].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].residual, + greater.stec_residuals[13].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].stddev, + greater.stec_residuals[13].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.constellation, + greater.stec_residuals[13].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.satId, + greater.stec_residuals[13].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].residual, + greater.stec_residuals[14].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].stddev, + greater.stec_residuals[14].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.constellation, + greater.stec_residuals[14].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.satId, + greater.stec_residuals[14].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].residual, + greater.stec_residuals[15].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].stddev, + greater.stec_residuals[15].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.constellation, + greater.stec_residuals[15].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.satId, + greater.stec_residuals[15].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].residual, + greater.stec_residuals[16].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].stddev, + greater.stec_residuals[16].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.constellation, + greater.stec_residuals[16].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.satId, + greater.stec_residuals[16].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].residual, + greater.stec_residuals[17].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].stddev, + greater.stec_residuals[17].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.constellation, + greater.stec_residuals[17].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.satId, + greater.stec_residuals[17].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].residual, + greater.stec_residuals[18].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].stddev, + greater.stec_residuals[18].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.constellation, + greater.stec_residuals[18].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.satId, + greater.stec_residuals[18].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].residual, + greater.stec_residuals[19].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].stddev, + greater.stec_residuals[19].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.constellation, + greater.stec_residuals[19].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.satId, + greater.stec_residuals[19].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].residual, + greater.stec_residuals[20].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].stddev, + greater.stec_residuals[20].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.constellation, + greater.stec_residuals[20].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.satId, + greater.stec_residuals[20].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].residual, + greater.stec_residuals[21].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].stddev, + greater.stec_residuals[21].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.constellation, + greater.stec_residuals[21].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.satId, + greater.stec_residuals[21].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].residual, + greater.stec_residuals[22].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].stddev, + greater.stec_residuals[22].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.constellation, + greater.stec_residuals[22].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.satId, + greater.stec_residuals[22].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].residual, + greater.stec_residuals[23].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].stddev, + greater.stec_residuals[23].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.constellation, + greater.stec_residuals[23].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.satId, + greater.stec_residuals[23].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].residual, + greater.stec_residuals[24].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].stddev, + greater.stec_residuals[24].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.constellation, + greater.stec_residuals[24].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.satId, + greater.stec_residuals[24].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].residual, + greater.stec_residuals[25].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].stddev, + greater.stec_residuals[25].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.constellation, + greater.stec_residuals[25].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.satId, + greater.stec_residuals[25].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].residual, + greater.stec_residuals[26].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].stddev, + greater.stec_residuals[26].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.constellation, + greater.stec_residuals[26].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.satId, + greater.stec_residuals[26].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].residual, + greater.stec_residuals[27].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].stddev, + greater.stec_residuals[27].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.constellation, + greater.stec_residuals[27].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.satId, + greater.stec_residuals[27].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].residual, + greater.stec_residuals[28].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].stddev, + greater.stec_residuals[28].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.constellation, + greater.stec_residuals[28].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.satId, + greater.stec_residuals[28].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].residual, + greater.stec_residuals[29].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].stddev, + greater.stec_residuals[29].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.constellation, + greater.stec_residuals[29].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.satId, + greater.stec_residuals[29].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].residual, + greater.stec_residuals[30].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].stddev, + greater.stec_residuals[30].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.constellation, + greater.stec_residuals[30].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.satId, + greater.stec_residuals[30].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].residual, + greater.stec_residuals[31].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].stddev, + greater.stec_residuals[31].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.constellation, + greater.stec_residuals[31].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.satId, + greater.stec_residuals[31].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].residual, + greater.stec_residuals[32].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].stddev, + greater.stec_residuals[32].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.constellation, + greater.stec_residuals[32].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.satId, + greater.stec_residuals[32].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].residual, + greater.stec_residuals[33].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].stddev, + greater.stec_residuals[33].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.constellation, + greater.stec_residuals[33].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.satId, + greater.stec_residuals[33].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].residual, + greater.stec_residuals[34].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].stddev, + greater.stec_residuals[34].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.constellation, + greater.stec_residuals[34].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.satId, + greater.stec_residuals[34].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].residual, + greater.stec_residuals[35].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].stddev, + greater.stec_residuals[35].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.constellation, + greater.stec_residuals[35].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.satId, + greater.stec_residuals[35].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].residual, + greater.stec_residuals[36].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].stddev, + greater.stec_residuals[36].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.constellation, + greater.stec_residuals[36].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.satId, + greater.stec_residuals[36].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].residual, + greater.stec_residuals[37].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].stddev, + greater.stec_residuals[37].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.constellation, + greater.stec_residuals[37].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.satId, + greater.stec_residuals[37].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].residual, + greater.stec_residuals[38].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].stddev, + greater.stec_residuals[38].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.constellation, + greater.stec_residuals[38].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.satId, + greater.stec_residuals[38].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].residual, + greater.stec_residuals[39].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].stddev, + greater.stec_residuals[39].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.constellation, + greater.stec_residuals[39].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.satId, + greater.stec_residuals[39].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].residual, + greater.stec_residuals[40].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].stddev, + greater.stec_residuals[40].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.constellation, + greater.stec_residuals[40].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.satId, + greater.stec_residuals[40].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].residual, + greater.stec_residuals[41].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].stddev, + greater.stec_residuals[41].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.constellation, + greater.stec_residuals[41].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.satId, + greater.stec_residuals[41].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].residual, + greater.stec_residuals[42].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].stddev, + greater.stec_residuals[42].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.constellation, + greater.stec_residuals[42].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.satId, + greater.stec_residuals[42].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].residual, + greater.stec_residuals[43].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].stddev, + greater.stec_residuals[43].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.constellation, + greater.stec_residuals[43].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.satId, + greater.stec_residuals[43].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].residual, + greater.stec_residuals[44].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].stddev, + greater.stec_residuals[44].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.constellation, + greater.stec_residuals[44].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.satId, + greater.stec_residuals[44].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].residual, + greater.stec_residuals[45].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].stddev, + greater.stec_residuals[45].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.constellation, + greater.stec_residuals[45].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.satId, + greater.stec_residuals[45].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].residual, + greater.stec_residuals[46].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].stddev, + greater.stec_residuals[46].stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].sv_id.constellation, + greater.stec_residuals[46].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].sv_id.satId, + greater.stec_residuals[46].sv_id.satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.hydro, + greater.tropo_delay_correction.hydro); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.stddev, + greater.tropo_delay_correction.stddev); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.wet, + greater.tropo_delay_correction.wet); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGriddedCorrectionDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_GRIDDED_CORRECTION_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_gridded_correction_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_gridded_correction_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_gridded_correction_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_gridded_correction_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGriddedCorrectionDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrGriddedCorrectionDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc new file mode 100644 index 0000000000..ef611c3d29 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc @@ -0,0 +1,2473 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0() { + assign(test_msg_.header.iod_atmo, 236); + assign(test_msg_.header.num_msgs, 62837); + assign(test_msg_.header.seq_num, 63555); + assign(test_msg_.header.time.tow, 2837573811); + assign(test_msg_.header.time.wn, 8940); + assign(test_msg_.header.tropo_quality_indicator, 230); + assign(test_msg_.header.update_interval, 233); + assign(test_msg_.index, 26598); + assign(test_msg_.n_stec_residuals, 59); + + assign(test_msg_.stec_residuals[0].residual, -23949); + assign(test_msg_.stec_residuals[0].sv_id.constellation, 157); + assign(test_msg_.stec_residuals[0].sv_id.satId, 231); + + assign(test_msg_.stec_residuals[1].residual, 27427); + assign(test_msg_.stec_residuals[1].sv_id.constellation, 146); + assign(test_msg_.stec_residuals[1].sv_id.satId, 197); + + assign(test_msg_.stec_residuals[2].residual, 10548); + assign(test_msg_.stec_residuals[2].sv_id.constellation, 109); + assign(test_msg_.stec_residuals[2].sv_id.satId, 222); + + assign(test_msg_.stec_residuals[3].residual, -18195); + assign(test_msg_.stec_residuals[3].sv_id.constellation, 12); + assign(test_msg_.stec_residuals[3].sv_id.satId, 86); + + assign(test_msg_.stec_residuals[4].residual, -27511); + assign(test_msg_.stec_residuals[4].sv_id.constellation, 204); + assign(test_msg_.stec_residuals[4].sv_id.satId, 65); + + assign(test_msg_.stec_residuals[5].residual, 11); + assign(test_msg_.stec_residuals[5].sv_id.constellation, 183); + assign(test_msg_.stec_residuals[5].sv_id.satId, 171); + + assign(test_msg_.stec_residuals[6].residual, 13740); + assign(test_msg_.stec_residuals[6].sv_id.constellation, 203); + assign(test_msg_.stec_residuals[6].sv_id.satId, 180); + + assign(test_msg_.stec_residuals[7].residual, 29626); + assign(test_msg_.stec_residuals[7].sv_id.constellation, 85); + assign(test_msg_.stec_residuals[7].sv_id.satId, 196); + + assign(test_msg_.stec_residuals[8].residual, 7846); + assign(test_msg_.stec_residuals[8].sv_id.constellation, 92); + assign(test_msg_.stec_residuals[8].sv_id.satId, 203); + + assign(test_msg_.stec_residuals[9].residual, 18376); + assign(test_msg_.stec_residuals[9].sv_id.constellation, 13); + assign(test_msg_.stec_residuals[9].sv_id.satId, 42); + + assign(test_msg_.stec_residuals[10].residual, -24357); + assign(test_msg_.stec_residuals[10].sv_id.constellation, 137); + assign(test_msg_.stec_residuals[10].sv_id.satId, 98); + + assign(test_msg_.stec_residuals[11].residual, -1441); + assign(test_msg_.stec_residuals[11].sv_id.constellation, 216); + assign(test_msg_.stec_residuals[11].sv_id.satId, 95); + + assign(test_msg_.stec_residuals[12].residual, -10660); + assign(test_msg_.stec_residuals[12].sv_id.constellation, 196); + assign(test_msg_.stec_residuals[12].sv_id.satId, 99); + + assign(test_msg_.stec_residuals[13].residual, -8509); + assign(test_msg_.stec_residuals[13].sv_id.constellation, 253); + assign(test_msg_.stec_residuals[13].sv_id.satId, 159); + + assign(test_msg_.stec_residuals[14].residual, 16361); + assign(test_msg_.stec_residuals[14].sv_id.constellation, 146); + assign(test_msg_.stec_residuals[14].sv_id.satId, 233); + + assign(test_msg_.stec_residuals[15].residual, 10346); + assign(test_msg_.stec_residuals[15].sv_id.constellation, 24); + assign(test_msg_.stec_residuals[15].sv_id.satId, 76); + + assign(test_msg_.stec_residuals[16].residual, -18679); + assign(test_msg_.stec_residuals[16].sv_id.constellation, 65); + assign(test_msg_.stec_residuals[16].sv_id.satId, 253); + + assign(test_msg_.stec_residuals[17].residual, 15292); + assign(test_msg_.stec_residuals[17].sv_id.constellation, 215); + assign(test_msg_.stec_residuals[17].sv_id.satId, 40); + + assign(test_msg_.stec_residuals[18].residual, 29537); + assign(test_msg_.stec_residuals[18].sv_id.constellation, 69); + assign(test_msg_.stec_residuals[18].sv_id.satId, 117); + + assign(test_msg_.stec_residuals[19].residual, -29440); + assign(test_msg_.stec_residuals[19].sv_id.constellation, 56); + assign(test_msg_.stec_residuals[19].sv_id.satId, 60); + + assign(test_msg_.stec_residuals[20].residual, -24266); + assign(test_msg_.stec_residuals[20].sv_id.constellation, 171); + assign(test_msg_.stec_residuals[20].sv_id.satId, 207); + + assign(test_msg_.stec_residuals[21].residual, 22272); + assign(test_msg_.stec_residuals[21].sv_id.constellation, 61); + assign(test_msg_.stec_residuals[21].sv_id.satId, 23); + + assign(test_msg_.stec_residuals[22].residual, 9303); + assign(test_msg_.stec_residuals[22].sv_id.constellation, 123); + assign(test_msg_.stec_residuals[22].sv_id.satId, 230); + + assign(test_msg_.stec_residuals[23].residual, -23794); + assign(test_msg_.stec_residuals[23].sv_id.constellation, 255); + assign(test_msg_.stec_residuals[23].sv_id.satId, 184); + + assign(test_msg_.stec_residuals[24].residual, -26837); + assign(test_msg_.stec_residuals[24].sv_id.constellation, 224); + assign(test_msg_.stec_residuals[24].sv_id.satId, 187); + + assign(test_msg_.stec_residuals[25].residual, 14631); + assign(test_msg_.stec_residuals[25].sv_id.constellation, 104); + assign(test_msg_.stec_residuals[25].sv_id.satId, 151); + + assign(test_msg_.stec_residuals[26].residual, -8144); + assign(test_msg_.stec_residuals[26].sv_id.constellation, 54); + assign(test_msg_.stec_residuals[26].sv_id.satId, 5); + + assign(test_msg_.stec_residuals[27].residual, 23612); + assign(test_msg_.stec_residuals[27].sv_id.constellation, 129); + assign(test_msg_.stec_residuals[27].sv_id.satId, 181); + + assign(test_msg_.stec_residuals[28].residual, 28013); + assign(test_msg_.stec_residuals[28].sv_id.constellation, 114); + assign(test_msg_.stec_residuals[28].sv_id.satId, 171); + + assign(test_msg_.stec_residuals[29].residual, 2166); + assign(test_msg_.stec_residuals[29].sv_id.constellation, 23); + assign(test_msg_.stec_residuals[29].sv_id.satId, 12); + + assign(test_msg_.stec_residuals[30].residual, -10186); + assign(test_msg_.stec_residuals[30].sv_id.constellation, 159); + assign(test_msg_.stec_residuals[30].sv_id.satId, 64); + + assign(test_msg_.stec_residuals[31].residual, 17432); + assign(test_msg_.stec_residuals[31].sv_id.constellation, 20); + assign(test_msg_.stec_residuals[31].sv_id.satId, 33); + + assign(test_msg_.stec_residuals[32].residual, -8666); + assign(test_msg_.stec_residuals[32].sv_id.constellation, 36); + assign(test_msg_.stec_residuals[32].sv_id.satId, 160); + + assign(test_msg_.stec_residuals[33].residual, 25436); + assign(test_msg_.stec_residuals[33].sv_id.constellation, 190); + assign(test_msg_.stec_residuals[33].sv_id.satId, 145); + + assign(test_msg_.stec_residuals[34].residual, -3864); + assign(test_msg_.stec_residuals[34].sv_id.constellation, 159); + assign(test_msg_.stec_residuals[34].sv_id.satId, 108); + + assign(test_msg_.stec_residuals[35].residual, 4093); + assign(test_msg_.stec_residuals[35].sv_id.constellation, 221); + assign(test_msg_.stec_residuals[35].sv_id.satId, 227); + + assign(test_msg_.stec_residuals[36].residual, -18055); + assign(test_msg_.stec_residuals[36].sv_id.constellation, 23); + assign(test_msg_.stec_residuals[36].sv_id.satId, 62); + + assign(test_msg_.stec_residuals[37].residual, -27900); + assign(test_msg_.stec_residuals[37].sv_id.constellation, 116); + assign(test_msg_.stec_residuals[37].sv_id.satId, 168); + + assign(test_msg_.stec_residuals[38].residual, 30687); + assign(test_msg_.stec_residuals[38].sv_id.constellation, 72); + assign(test_msg_.stec_residuals[38].sv_id.satId, 123); + + assign(test_msg_.stec_residuals[39].residual, -13151); + assign(test_msg_.stec_residuals[39].sv_id.constellation, 242); + assign(test_msg_.stec_residuals[39].sv_id.satId, 226); + + assign(test_msg_.stec_residuals[40].residual, -22903); + assign(test_msg_.stec_residuals[40].sv_id.constellation, 202); + assign(test_msg_.stec_residuals[40].sv_id.satId, 180); + + assign(test_msg_.stec_residuals[41].residual, 4988); + assign(test_msg_.stec_residuals[41].sv_id.constellation, 24); + assign(test_msg_.stec_residuals[41].sv_id.satId, 58); + + assign(test_msg_.stec_residuals[42].residual, 27408); + assign(test_msg_.stec_residuals[42].sv_id.constellation, 188); + assign(test_msg_.stec_residuals[42].sv_id.satId, 181); + + assign(test_msg_.stec_residuals[43].residual, 319); + assign(test_msg_.stec_residuals[43].sv_id.constellation, 231); + assign(test_msg_.stec_residuals[43].sv_id.satId, 66); + + assign(test_msg_.stec_residuals[44].residual, 15987); + assign(test_msg_.stec_residuals[44].sv_id.constellation, 252); + assign(test_msg_.stec_residuals[44].sv_id.satId, 64); + + assign(test_msg_.stec_residuals[45].residual, 22266); + assign(test_msg_.stec_residuals[45].sv_id.constellation, 97); + assign(test_msg_.stec_residuals[45].sv_id.satId, 233); + + assign(test_msg_.stec_residuals[46].residual, -19919); + assign(test_msg_.stec_residuals[46].sv_id.constellation, 221); + assign(test_msg_.stec_residuals[46].sv_id.satId, 156); + + assign(test_msg_.stec_residuals[47].residual, 17350); + assign(test_msg_.stec_residuals[47].sv_id.constellation, 73); + assign(test_msg_.stec_residuals[47].sv_id.satId, 32); + + assign(test_msg_.stec_residuals[48].residual, 14410); + assign(test_msg_.stec_residuals[48].sv_id.constellation, 253); + assign(test_msg_.stec_residuals[48].sv_id.satId, 249); + + assign(test_msg_.stec_residuals[49].residual, 23671); + assign(test_msg_.stec_residuals[49].sv_id.constellation, 165); + assign(test_msg_.stec_residuals[49].sv_id.satId, 38); + + assign(test_msg_.stec_residuals[50].residual, -31905); + assign(test_msg_.stec_residuals[50].sv_id.constellation, 44); + assign(test_msg_.stec_residuals[50].sv_id.satId, 99); + + assign(test_msg_.stec_residuals[51].residual, 14305); + assign(test_msg_.stec_residuals[51].sv_id.constellation, 192); + assign(test_msg_.stec_residuals[51].sv_id.satId, 89); + + assign(test_msg_.stec_residuals[52].residual, -12968); + assign(test_msg_.stec_residuals[52].sv_id.constellation, 171); + assign(test_msg_.stec_residuals[52].sv_id.satId, 95); + + assign(test_msg_.stec_residuals[53].residual, 21479); + assign(test_msg_.stec_residuals[53].sv_id.constellation, 116); + assign(test_msg_.stec_residuals[53].sv_id.satId, 21); + + assign(test_msg_.stec_residuals[54].residual, 28260); + assign(test_msg_.stec_residuals[54].sv_id.constellation, 71); + assign(test_msg_.stec_residuals[54].sv_id.satId, 71); + + assign(test_msg_.stec_residuals[55].residual, -11112); + assign(test_msg_.stec_residuals[55].sv_id.constellation, 254); + assign(test_msg_.stec_residuals[55].sv_id.satId, 217); + + assign(test_msg_.stec_residuals[56].residual, -25304); + assign(test_msg_.stec_residuals[56].sv_id.constellation, 8); + assign(test_msg_.stec_residuals[56].sv_id.satId, 18); + + assign(test_msg_.stec_residuals[57].residual, -4024); + assign(test_msg_.stec_residuals[57].sv_id.constellation, 54); + assign(test_msg_.stec_residuals[57].sv_id.satId, 244); + + assign(test_msg_.stec_residuals[58].residual, -15505); + assign(test_msg_.stec_residuals[58].sv_id.constellation, 189); + assign(test_msg_.stec_residuals[58].sv_id.satId, 231); + assign(test_msg_.tropo_delay_correction.hydro, 16250); + assign(test_msg_.tropo_delay_correction.wet, 101); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler< + sbp_msg_ssr_gridded_correction_no_std_dep_a_t> { + using sbp::MessageHandler< + sbp_msg_ssr_gridded_correction_no_std_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_gridded_correction_no_std_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrGriddedCorrectionNoStdDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrGriddedCorrectionNoStdDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_gridded_correction_no_std_dep_a, + sizeof(msg->ssr_gridded_correction_no_std_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_gridded_correction_no_std_dep_a, + &test_msg_, sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgSsrGriddedCorrectionNoStdDepA); + info.sender_id = 7270; + info.preamble = 0x55; + info.crc = 0x51cd; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 254; + + return info; + } + + protected: + void comparison_tests( + const sbp_msg_ssr_gridded_correction_no_std_dep_a_t &lesser, + const sbp_msg_ssr_gridded_correction_no_std_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = sbp::MessageTraits< + sbp_msg_ssr_gridded_correction_no_std_dep_a_t>::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = sbp::MessageTraits< + sbp_msg_ssr_gridded_correction_no_std_dep_a_t>::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_cmp(&lesser, &lesser), + 0); + EXPECT_EQ( + sbp_msg_ssr_gridded_correction_no_std_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE( + sbp_msg_ssr_gridded_correction_no_std_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT( + sbp_msg_ssr_gridded_correction_no_std_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionNoStdDepA, + &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrGriddedCorrectionNoStdDepA, + &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrGriddedCorrectionNoStdDepA, + &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrGriddedCorrectionNoStdDepA, + &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_gridded_correction_no_std_dep_a_t test_msg_{}; + uint8_t encoded_frame_[254 + 8] = { + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, 67, + 248, 233, 236, 230, 230, 103, 122, 63, 101, 231, 157, 115, 162, 197, 146, + 35, 107, 222, 109, 52, 41, 86, 12, 237, 184, 65, 204, 137, 148, 171, + 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, 203, 92, 166, 30, + 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, 95, 250, 99, 196, 92, + 214, 159, 253, 195, 222, 233, 146, 233, 63, 76, 24, 106, 40, 253, 65, + 9, 183, 40, 215, 188, 59, 117, 69, 97, 115, 60, 56, 0, 141, 207, + 171, 54, 161, 23, 61, 0, 87, 230, 123, 87, 36, 184, 255, 14, 163, + 187, 224, 43, 151, 151, 104, 39, 57, 5, 54, 48, 224, 181, 129, 60, + 92, 171, 114, 109, 109, 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, + 24, 68, 160, 36, 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, + 221, 253, 15, 62, 23, 121, 185, 168, 116, 4, 147, 123, 72, 223, 119, + 226, 242, 161, 204, 180, 202, 137, 166, 58, 24, 124, 19, 181, 188, 16, + 107, 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, 221, + 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, 99, + 44, 95, 131, 89, 192, 225, 55, 95, 171, 88, 205, 21, 116, 231, 83, + 71, 71, 100, 110, 217, 254, 152, 212, 18, 8, 40, 157, 244, 54, 72, + 240, 231, 189, 111, 195, 205, 81, + }; + uint8_t encoded_payload_[254] = { + 179, 240, 33, 169, 236, 34, 117, 245, 67, 248, 233, 236, 230, 230, 103, + 122, 63, 101, 231, 157, 115, 162, 197, 146, 35, 107, 222, 109, 52, 41, + 86, 12, 237, 184, 65, 204, 137, 148, 171, 183, 11, 0, 180, 203, 172, + 53, 196, 85, 186, 115, 203, 92, 166, 30, 42, 13, 200, 71, 98, 137, + 219, 160, 95, 216, 95, 250, 99, 196, 92, 214, 159, 253, 195, 222, 233, + 146, 233, 63, 76, 24, 106, 40, 253, 65, 9, 183, 40, 215, 188, 59, + 117, 69, 97, 115, 60, 56, 0, 141, 207, 171, 54, 161, 23, 61, 0, + 87, 230, 123, 87, 36, 184, 255, 14, 163, 187, 224, 43, 151, 151, 104, + 39, 57, 5, 54, 48, 224, 181, 129, 60, 92, 171, 114, 109, 109, 12, + 23, 118, 8, 64, 159, 54, 216, 33, 20, 24, 68, 160, 36, 38, 222, + 145, 190, 92, 99, 108, 159, 232, 240, 227, 221, 253, 15, 62, 23, 121, + 185, 168, 116, 4, 147, 123, 72, 223, 119, 226, 242, 161, 204, 180, 202, + 137, 166, 58, 24, 124, 19, 181, 188, 16, 107, 66, 231, 63, 1, 64, + 252, 115, 62, 233, 97, 250, 86, 156, 221, 49, 178, 32, 73, 198, 67, + 249, 253, 74, 56, 38, 165, 119, 92, 99, 44, 95, 131, 89, 192, 225, + 55, 95, 171, 88, 205, 21, 116, 231, 83, 71, 71, 100, 110, 217, 254, + 152, 212, 18, 8, 40, 157, 244, 54, 72, 240, 231, 189, 111, 195, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp_msg_ssr_gridded_correction_no_std_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrGriddedCorrectionNoStdDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrGriddedCorrectionNoStdDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + + for (uint8_t i = 0; i < 254; i++) { + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_encode( + &buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrGriddedCorrectionNoStdDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t t{}; + return sbp_msg_ssr_gridded_correction_no_std_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t t{}; + t.n_stec_residuals = 1; + return sbp_msg_ssr_gridded_correction_no_std_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_gridded_correction_no_std_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrGriddedCorrectionNoStdDepA, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrGriddedCorrectionNoStdDepA, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrGriddedCorrectionNoStdDepA, + info.sender_id, &info.test_msg_wrapped, + &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.iod_atmo, greater.header.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.tropo_quality_indicator, + greater.header.tropo_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.index, greater.index); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_stec_residuals, greater.n_stec_residuals); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].residual, + greater.stec_residuals[0].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.constellation, + greater.stec_residuals[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[0].sv_id.satId, + greater.stec_residuals[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].residual, + greater.stec_residuals[1].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.constellation, + greater.stec_residuals[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[1].sv_id.satId, + greater.stec_residuals[1].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].residual, + greater.stec_residuals[2].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.constellation, + greater.stec_residuals[2].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[2].sv_id.satId, + greater.stec_residuals[2].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].residual, + greater.stec_residuals[3].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.constellation, + greater.stec_residuals[3].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[3].sv_id.satId, + greater.stec_residuals[3].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].residual, + greater.stec_residuals[4].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.constellation, + greater.stec_residuals[4].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[4].sv_id.satId, + greater.stec_residuals[4].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].residual, + greater.stec_residuals[5].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.constellation, + greater.stec_residuals[5].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[5].sv_id.satId, + greater.stec_residuals[5].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].residual, + greater.stec_residuals[6].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.constellation, + greater.stec_residuals[6].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[6].sv_id.satId, + greater.stec_residuals[6].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].residual, + greater.stec_residuals[7].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.constellation, + greater.stec_residuals[7].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[7].sv_id.satId, + greater.stec_residuals[7].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].residual, + greater.stec_residuals[8].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.constellation, + greater.stec_residuals[8].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[8].sv_id.satId, + greater.stec_residuals[8].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].residual, + greater.stec_residuals[9].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.constellation, + greater.stec_residuals[9].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[9].sv_id.satId, + greater.stec_residuals[9].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].residual, + greater.stec_residuals[10].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.constellation, + greater.stec_residuals[10].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[10].sv_id.satId, + greater.stec_residuals[10].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].residual, + greater.stec_residuals[11].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.constellation, + greater.stec_residuals[11].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[11].sv_id.satId, + greater.stec_residuals[11].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].residual, + greater.stec_residuals[12].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.constellation, + greater.stec_residuals[12].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[12].sv_id.satId, + greater.stec_residuals[12].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].residual, + greater.stec_residuals[13].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.constellation, + greater.stec_residuals[13].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[13].sv_id.satId, + greater.stec_residuals[13].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].residual, + greater.stec_residuals[14].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.constellation, + greater.stec_residuals[14].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[14].sv_id.satId, + greater.stec_residuals[14].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].residual, + greater.stec_residuals[15].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.constellation, + greater.stec_residuals[15].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[15].sv_id.satId, + greater.stec_residuals[15].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].residual, + greater.stec_residuals[16].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.constellation, + greater.stec_residuals[16].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[16].sv_id.satId, + greater.stec_residuals[16].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].residual, + greater.stec_residuals[17].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.constellation, + greater.stec_residuals[17].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[17].sv_id.satId, + greater.stec_residuals[17].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].residual, + greater.stec_residuals[18].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.constellation, + greater.stec_residuals[18].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[18].sv_id.satId, + greater.stec_residuals[18].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].residual, + greater.stec_residuals[19].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.constellation, + greater.stec_residuals[19].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[19].sv_id.satId, + greater.stec_residuals[19].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].residual, + greater.stec_residuals[20].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.constellation, + greater.stec_residuals[20].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[20].sv_id.satId, + greater.stec_residuals[20].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].residual, + greater.stec_residuals[21].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.constellation, + greater.stec_residuals[21].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[21].sv_id.satId, + greater.stec_residuals[21].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].residual, + greater.stec_residuals[22].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.constellation, + greater.stec_residuals[22].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[22].sv_id.satId, + greater.stec_residuals[22].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].residual, + greater.stec_residuals[23].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.constellation, + greater.stec_residuals[23].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[23].sv_id.satId, + greater.stec_residuals[23].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].residual, + greater.stec_residuals[24].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.constellation, + greater.stec_residuals[24].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[24].sv_id.satId, + greater.stec_residuals[24].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].residual, + greater.stec_residuals[25].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.constellation, + greater.stec_residuals[25].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[25].sv_id.satId, + greater.stec_residuals[25].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].residual, + greater.stec_residuals[26].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.constellation, + greater.stec_residuals[26].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[26].sv_id.satId, + greater.stec_residuals[26].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].residual, + greater.stec_residuals[27].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.constellation, + greater.stec_residuals[27].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[27].sv_id.satId, + greater.stec_residuals[27].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].residual, + greater.stec_residuals[28].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.constellation, + greater.stec_residuals[28].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[28].sv_id.satId, + greater.stec_residuals[28].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].residual, + greater.stec_residuals[29].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.constellation, + greater.stec_residuals[29].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[29].sv_id.satId, + greater.stec_residuals[29].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].residual, + greater.stec_residuals[30].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.constellation, + greater.stec_residuals[30].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[30].sv_id.satId, + greater.stec_residuals[30].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].residual, + greater.stec_residuals[31].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.constellation, + greater.stec_residuals[31].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[31].sv_id.satId, + greater.stec_residuals[31].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].residual, + greater.stec_residuals[32].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.constellation, + greater.stec_residuals[32].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[32].sv_id.satId, + greater.stec_residuals[32].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].residual, + greater.stec_residuals[33].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.constellation, + greater.stec_residuals[33].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[33].sv_id.satId, + greater.stec_residuals[33].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].residual, + greater.stec_residuals[34].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.constellation, + greater.stec_residuals[34].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[34].sv_id.satId, + greater.stec_residuals[34].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].residual, + greater.stec_residuals[35].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.constellation, + greater.stec_residuals[35].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[35].sv_id.satId, + greater.stec_residuals[35].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].residual, + greater.stec_residuals[36].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.constellation, + greater.stec_residuals[36].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[36].sv_id.satId, + greater.stec_residuals[36].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].residual, + greater.stec_residuals[37].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.constellation, + greater.stec_residuals[37].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[37].sv_id.satId, + greater.stec_residuals[37].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].residual, + greater.stec_residuals[38].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.constellation, + greater.stec_residuals[38].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[38].sv_id.satId, + greater.stec_residuals[38].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].residual, + greater.stec_residuals[39].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.constellation, + greater.stec_residuals[39].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[39].sv_id.satId, + greater.stec_residuals[39].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].residual, + greater.stec_residuals[40].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.constellation, + greater.stec_residuals[40].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[40].sv_id.satId, + greater.stec_residuals[40].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].residual, + greater.stec_residuals[41].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.constellation, + greater.stec_residuals[41].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[41].sv_id.satId, + greater.stec_residuals[41].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].residual, + greater.stec_residuals[42].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.constellation, + greater.stec_residuals[42].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[42].sv_id.satId, + greater.stec_residuals[42].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].residual, + greater.stec_residuals[43].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.constellation, + greater.stec_residuals[43].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[43].sv_id.satId, + greater.stec_residuals[43].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].residual, + greater.stec_residuals[44].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.constellation, + greater.stec_residuals[44].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[44].sv_id.satId, + greater.stec_residuals[44].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].residual, + greater.stec_residuals[45].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.constellation, + greater.stec_residuals[45].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[45].sv_id.satId, + greater.stec_residuals[45].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].residual, + greater.stec_residuals[46].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].sv_id.constellation, + greater.stec_residuals[46].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[46].sv_id.satId, + greater.stec_residuals[46].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[47].residual, + greater.stec_residuals[47].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[47].sv_id.constellation, + greater.stec_residuals[47].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[47].sv_id.satId, + greater.stec_residuals[47].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[48].residual, + greater.stec_residuals[48].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[48].sv_id.constellation, + greater.stec_residuals[48].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[48].sv_id.satId, + greater.stec_residuals[48].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[49].residual, + greater.stec_residuals[49].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[49].sv_id.constellation, + greater.stec_residuals[49].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[49].sv_id.satId, + greater.stec_residuals[49].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[50].residual, + greater.stec_residuals[50].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[50].sv_id.constellation, + greater.stec_residuals[50].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[50].sv_id.satId, + greater.stec_residuals[50].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[51].residual, + greater.stec_residuals[51].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[51].sv_id.constellation, + greater.stec_residuals[51].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[51].sv_id.satId, + greater.stec_residuals[51].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[52].residual, + greater.stec_residuals[52].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[52].sv_id.constellation, + greater.stec_residuals[52].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[52].sv_id.satId, + greater.stec_residuals[52].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[53].residual, + greater.stec_residuals[53].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[53].sv_id.constellation, + greater.stec_residuals[53].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[53].sv_id.satId, + greater.stec_residuals[53].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[54].residual, + greater.stec_residuals[54].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[54].sv_id.constellation, + greater.stec_residuals[54].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[54].sv_id.satId, + greater.stec_residuals[54].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[55].residual, + greater.stec_residuals[55].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[55].sv_id.constellation, + greater.stec_residuals[55].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[55].sv_id.satId, + greater.stec_residuals[55].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[56].residual, + greater.stec_residuals[56].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[56].sv_id.constellation, + greater.stec_residuals[56].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[56].sv_id.satId, + greater.stec_residuals[56].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[57].residual, + greater.stec_residuals[57].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[57].sv_id.constellation, + greater.stec_residuals[57].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[57].sv_id.satId, + greater.stec_residuals[57].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[58].residual, + greater.stec_residuals[58].residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[58].sv_id.constellation, + greater.stec_residuals[58].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_residuals[58].sv_id.satId, + greater.stec_residuals[58].sv_id.satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.hydro, + greater.tropo_delay_correction.hydro); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_gridded_correction_no_std_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_gridded_correction_no_std_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tropo_delay_correction.wet, + greater.tropo_delay_correction.wet); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrGriddedCorrectionNoStdDepA); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_SSR_GRIDDED_CORRECTION_NO_STD_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_gridded_correction_no_std_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_gridded_correction_no_std_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits< + sbp_msg_ssr_gridded_correction_no_std_dep_a_t>::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_gridded_correction_no_std_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_gridded_correction_no_std_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits:: + encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[254]; + uint8_t n_written; + + EXPECT_EQ( + sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 254); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 254), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_gridded_correction_no_std_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ( + sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 254); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrGriddedCorrectionNoStdDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSsrGriddedCorrectionNoStdDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc new file mode 100644 index 0000000000..9cfea04b77 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc @@ -0,0 +1,887 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrOrbitClock0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrOrbitClock0() { + assign(test_msg_.along, -1334502588); + assign(test_msg_.c0, -174298703); + assign(test_msg_.c1, -630458102); + assign(test_msg_.c2, 1211677201); + assign(test_msg_.cross, -197264530); + assign(test_msg_.dot_along, 169404560); + assign(test_msg_.dot_cross, 1118011173); + assign(test_msg_.dot_radial, 878654074); + assign(test_msg_.iod, 936372632); + assign(test_msg_.iod_ssr, 255); + assign(test_msg_.radial, -2143668642); + assign(test_msg_.sid.code, 212); + assign(test_msg_.sid.sat, 203); + assign(test_msg_.time.tow, 3479621715); + assign(test_msg_.time.wn, 7588); + assign(test_msg_.update_interval, 236); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_orbit_clock_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrOrbitClock, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrOrbitClock); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_orbit_clock, + sizeof(msg->ssr_orbit_clock)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_orbit_clock_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_orbit_clock, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrOrbitClock); + info.sender_id = 58677; + info.preamble = 0x55; + info.crc = 0x160e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 50; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_orbit_clock_t &lesser, + const sbp_msg_ssr_orbit_clock_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_orbit_clock_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_orbit_clock_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSsrOrbitClock, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClock, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgSsrOrbitClock, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgSsrOrbitClock, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_orbit_clock_t test_msg_{}; + uint8_t encoded_frame_[50 + 8] = { + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, 203, 212, 236, + 255, 152, 233, 207, 55, 94, 54, 58, 128, 68, 27, 117, 176, 110, 251, + 61, 244, 122, 50, 95, 52, 144, 232, 24, 10, 37, 127, 163, 66, 177, + 105, 156, 245, 10, 249, 107, 218, 17, 186, 56, 72, 14, 22, + }; + uint8_t encoded_payload_[50] = { + 83, 208, 102, 207, 164, 29, 203, 212, 236, 255, 152, 233, 207, + 55, 94, 54, 58, 128, 68, 27, 117, 176, 110, 251, 61, 244, + 122, 50, 95, 52, 144, 232, 24, 10, 37, 127, 163, 66, 177, + 105, 156, 245, 10, 249, 107, 218, 17, 186, 56, 72, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrOrbitClock, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrOrbitClock, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + + for (uint8_t i = 0; i < 50; i++) { + EXPECT_EQ( + sbp_msg_ssr_orbit_clock_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrOrbitClock, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClock, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrOrbitClock, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClock, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.along, greater.along); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.c0, greater.c0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.c1, greater.c1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.c2, greater.c2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.cross, greater.cross); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.dot_along, greater.dot_along); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.dot_cross, greater.dot_cross); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.dot_radial, greater.dot_radial); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.iod, greater.iod); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.iod_ssr, greater.iod_ssr); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.radial, greater.radial); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrOrbitClock); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_ORBIT_CLOCK"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_orbit_clock_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_orbit_clock_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_orbit_clock, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_orbit_clock, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[50]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 50); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 50), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 50); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrOrbitClock, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClock0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrOrbitClock, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBounds.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBounds.cc index adc02bcbcf..006109223b 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBounds.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBounds.cc @@ -16,211 +16,998 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrOrbitClockBounds0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0 : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrOrbitClockBounds0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0() { + assign(test_msg_.const_id, 1); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.sol_id, 48); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 3); + assign(test_msg_.n_sats, 2); + + assign(test_msg_.orbit_clock_bounds[0].clock_bound_mu, 39); + assign(test_msg_.orbit_clock_bounds[0].clock_bound_sig, 1); + assign(test_msg_.orbit_clock_bounds[0].orb_along_bound_mu, 38); + assign(test_msg_.orbit_clock_bounds[0].orb_along_bound_sig, 2); + assign(test_msg_.orbit_clock_bounds[0].orb_cross_bound_mu, 37); + assign(test_msg_.orbit_clock_bounds[0].orb_cross_bound_sig, 3); + assign(test_msg_.orbit_clock_bounds[0].orb_radial_bound_mu, 39); + assign(test_msg_.orbit_clock_bounds[0].orb_radial_bound_sig, 1); + assign(test_msg_.orbit_clock_bounds[0].sat_id, 24); + + assign(test_msg_.orbit_clock_bounds[1].clock_bound_mu, 39); + assign(test_msg_.orbit_clock_bounds[1].clock_bound_sig, 1); + assign(test_msg_.orbit_clock_bounds[1].orb_along_bound_mu, 38); + assign(test_msg_.orbit_clock_bounds[1].orb_along_bound_sig, 2); + assign(test_msg_.orbit_clock_bounds[1].orb_cross_bound_mu, 37); + assign(test_msg_.orbit_clock_bounds[1].orb_cross_bound_sig, 3); + assign(test_msg_.orbit_clock_bounds[1].orb_radial_bound_mu, 39); + assign(test_msg_.orbit_clock_bounds[1].orb_radial_bound_sig, 1); + assign(test_msg_.orbit_clock_bounds[1].sat_id, 3); + assign(test_msg_.ssr_iod, 15); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_bounds_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_orbit_clock_bounds_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrOrbitClockBounds, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_bounds_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrOrbitClockBounds); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_orbit_clock_bounds, + sizeof(msg->ssr_orbit_clock_bounds)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_orbit_clock_bounds_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_orbit_clock_bounds, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrOrbitClockBounds); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x5515; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 31; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_orbit_clock_bounds_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_orbit_clock_bounds_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_orbit_clock_bounds_t &lesser, + const sbp_msg_ssr_orbit_clock_bounds_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_orbit_clock_bounds_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_orbit_clock_bounds_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockBounds, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockBounds, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrOrbitClockBounds, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrOrbitClockBounds, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_ssr_MsgSsrOrbitClockBounds0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_orbit_clock_bounds_t test_msg_{}; + uint8_t encoded_frame_[31 + 8] = { 85, 222, 5, 66, 0, 31, 180, 0, 0, 0, 3, 0, 1, 2, 3, 48, 15, 1, 2, 24, 39, 38, 37, 1, 2, 3, 39, 1, 3, 39, 38, 37, 1, 2, 3, 39, 1, 21, 85, }; + uint8_t encoded_payload_[31] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 48, 15, 1, 2, 24, 39, 38, + 37, 1, 2, 3, 39, 1, 3, 39, 38, 37, 1, 2, 3, 39, 1, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrOrbitClockBounds, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrOrbitClockBounds, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + for (uint8_t i = 0; i < 31; i++) { + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrOrbitClockBounds, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_orbit_clock_bounds_t t{}; + return sbp_msg_ssr_orbit_clock_bounds_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_orbit_clock_bounds_t t{}; + t.n_sats = 1; + return sbp_msg_ssr_orbit_clock_bounds_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ssr_orbit_clock_bounds_t test_msg{}; - test_msg.const_id = 1; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 2; - test_msg.header.sol_id = 48; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 3; - test_msg.n_sats = 2; - - test_msg.orbit_clock_bounds[0].clock_bound_mu = 39; - test_msg.orbit_clock_bounds[0].clock_bound_sig = 1; - test_msg.orbit_clock_bounds[0].orb_along_bound_mu = 38; - test_msg.orbit_clock_bounds[0].orb_along_bound_sig = 2; - test_msg.orbit_clock_bounds[0].orb_cross_bound_mu = 37; - test_msg.orbit_clock_bounds[0].orb_cross_bound_sig = 3; - test_msg.orbit_clock_bounds[0].orb_radial_bound_mu = 39; - test_msg.orbit_clock_bounds[0].orb_radial_bound_sig = 1; - test_msg.orbit_clock_bounds[0].sat_id = 24; - - test_msg.orbit_clock_bounds[1].clock_bound_mu = 39; - test_msg.orbit_clock_bounds[1].clock_bound_sig = 1; - test_msg.orbit_clock_bounds[1].orb_along_bound_mu = 38; - test_msg.orbit_clock_bounds[1].orb_along_bound_sig = 2; - test_msg.orbit_clock_bounds[1].orb_cross_bound_mu = 37; - test_msg.orbit_clock_bounds[1].orb_cross_bound_sig = 3; - test_msg.orbit_clock_bounds[1].orb_radial_bound_mu = 39; - test_msg.orbit_clock_bounds[1].orb_radial_bound_sig = 1; - test_msg.orbit_clock_bounds[1].sat_id = 3; - test_msg.ssr_iod = 15; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.const_id, 1) - << "incorrect value for last_msg_.const_id, expected 1, is " - << last_msg_.const_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 48) - << "incorrect value for last_msg_.header.sol_id, expected 48, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 3) - << "incorrect value for last_msg_.header.update_interval, expected 3, is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.n_sats, 2) - << "incorrect value for last_msg_.n_sats, expected 2, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].clock_bound_mu, 39) - << "incorrect value for last_msg_.orbit_clock_bounds[0].clock_bound_mu, " - "expected 39, is " - << last_msg_.orbit_clock_bounds[0].clock_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].clock_bound_sig, 1) - << "incorrect value for last_msg_.orbit_clock_bounds[0].clock_bound_sig, " - "expected 1, is " - << last_msg_.orbit_clock_bounds[0].clock_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_along_bound_mu, 38) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_along_bound_mu, expected 38, is " - << last_msg_.orbit_clock_bounds[0].orb_along_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_along_bound_sig, 2) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_along_bound_sig, expected 2, is " - << last_msg_.orbit_clock_bounds[0].orb_along_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_cross_bound_mu, 37) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_cross_bound_mu, expected 37, is " - << last_msg_.orbit_clock_bounds[0].orb_cross_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_cross_bound_sig, 3) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_cross_bound_sig, expected 3, is " - << last_msg_.orbit_clock_bounds[0].orb_cross_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_radial_bound_mu, 39) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_radial_bound_mu, expected 39, is " - << last_msg_.orbit_clock_bounds[0].orb_radial_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].orb_radial_bound_sig, 1) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[0].orb_radial_bound_sig, expected 1, is " - << last_msg_.orbit_clock_bounds[0].orb_radial_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[0].sat_id, 24) - << "incorrect value for last_msg_.orbit_clock_bounds[0].sat_id, expected " - "24, is " - << last_msg_.orbit_clock_bounds[0].sat_id; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].clock_bound_mu, 39) - << "incorrect value for last_msg_.orbit_clock_bounds[1].clock_bound_mu, " - "expected 39, is " - << last_msg_.orbit_clock_bounds[1].clock_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].clock_bound_sig, 1) - << "incorrect value for last_msg_.orbit_clock_bounds[1].clock_bound_sig, " - "expected 1, is " - << last_msg_.orbit_clock_bounds[1].clock_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_along_bound_mu, 38) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_along_bound_mu, expected 38, is " - << last_msg_.orbit_clock_bounds[1].orb_along_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_along_bound_sig, 2) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_along_bound_sig, expected 2, is " - << last_msg_.orbit_clock_bounds[1].orb_along_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_cross_bound_mu, 37) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_cross_bound_mu, expected 37, is " - << last_msg_.orbit_clock_bounds[1].orb_cross_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_cross_bound_sig, 3) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_cross_bound_sig, expected 3, is " - << last_msg_.orbit_clock_bounds[1].orb_cross_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_radial_bound_mu, 39) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_radial_bound_mu, expected 39, is " - << last_msg_.orbit_clock_bounds[1].orb_radial_bound_mu; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].orb_radial_bound_sig, 1) - << "incorrect value for " - "last_msg_.orbit_clock_bounds[1].orb_radial_bound_sig, expected 1, is " - << last_msg_.orbit_clock_bounds[1].orb_radial_bound_sig; - EXPECT_EQ(last_msg_.orbit_clock_bounds[1].sat_id, 3) - << "incorrect value for last_msg_.orbit_clock_bounds[1].sat_id, expected " - "3, is " - << last_msg_.orbit_clock_bounds[1].sat_id; - EXPECT_EQ(last_msg_.ssr_iod, 15) - << "incorrect value for last_msg_.ssr_iod, expected 15, is " - << last_msg_.ssr_iod; + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrOrbitClockBounds, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockBounds, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.const_id, greater.const_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].clock_bound_mu, + greater.orbit_clock_bounds[0].clock_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].clock_bound_sig, + greater.orbit_clock_bounds[0].clock_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_along_bound_mu, + greater.orbit_clock_bounds[0].orb_along_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_along_bound_sig, + greater.orbit_clock_bounds[0].orb_along_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_cross_bound_mu, + greater.orbit_clock_bounds[0].orb_cross_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_cross_bound_sig, + greater.orbit_clock_bounds[0].orb_cross_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_radial_bound_mu, + greater.orbit_clock_bounds[0].orb_radial_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].orb_radial_bound_sig, + greater.orbit_clock_bounds[0].orb_radial_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[0].sat_id, + greater.orbit_clock_bounds[0].sat_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].clock_bound_mu, + greater.orbit_clock_bounds[1].clock_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].clock_bound_sig, + greater.orbit_clock_bounds[1].clock_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_along_bound_mu, + greater.orbit_clock_bounds[1].orb_along_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_along_bound_sig, + greater.orbit_clock_bounds[1].orb_along_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_cross_bound_mu, + greater.orbit_clock_bounds[1].orb_cross_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_cross_bound_sig, + greater.orbit_clock_bounds[1].orb_cross_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_radial_bound_mu, + greater.orbit_clock_bounds[1].orb_radial_bound_mu); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].orb_radial_bound_sig, + greater.orbit_clock_bounds[1].orb_radial_bound_sig); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.orbit_clock_bounds[1].sat_id, + greater.orbit_clock_bounds[1].sat_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod, greater.ssr_iod); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrOrbitClockBounds); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_ORBIT_CLOCK_BOUNDS"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_orbit_clock_bounds_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_orbit_clock_bounds_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_orbit_clock_bounds, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_orbit_clock_bounds, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrOrbitClockBounds, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBounds0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrOrbitClockBounds, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation.cc index eaeb52f6e8..674bab4087 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation.cc @@ -16,174 +16,940 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0 + : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0() { + assign(test_msg_.const_id, 1); + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 2); + assign(test_msg_.header.sol_id, 48); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 3); + assign(test_msg_.orbit_clock_bounds_degradation.clock_bound_mu_dot, 194); + assign(test_msg_.orbit_clock_bounds_degradation.clock_bound_sig_dot, 193); + assign(test_msg_.orbit_clock_bounds_degradation.orb_along_bound_mu_dot, + 199); + assign(test_msg_.orbit_clock_bounds_degradation.orb_along_bound_sig_dot, + 196); + assign(test_msg_.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot, + 198); + assign(test_msg_.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot, + 195); + assign(test_msg_.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot, + 200); + assign(test_msg_.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot, + 197); + assign(test_msg_.sat_bitmask, 10); + assign(test_msg_.ssr_iod, 15); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler< + sbp_msg_ssr_orbit_clock_bounds_degradation_t> { + using sbp::MessageHandler< + sbp_msg_ssr_orbit_clock_bounds_degradation_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_orbit_clock_bounds_degradation_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrOrbitClockBoundsDegradation, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrOrbitClockBoundsDegradation); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_orbit_clock_bounds_degradation, + sizeof(msg->ssr_orbit_clock_bounds_degradation)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_orbit_clock_bounds_degradation_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_orbit_clock_bounds_degradation, + &test_msg_, sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgSsrOrbitClockBoundsDegradation); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x75C8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 28; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_ssr_orbit_clock_bounds_degradation_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_orbit_clock_bounds_degradation_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests( + const sbp_msg_ssr_orbit_clock_bounds_degradation_t &lesser, + const sbp_msg_ssr_orbit_clock_bounds_degradation_t &greater) { + sbp_msg_t wrapped_lesser = sbp::MessageTraits< + sbp_msg_ssr_orbit_clock_bounds_degradation_t>::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = sbp::MessageTraits< + sbp_msg_ssr_orbit_clock_bounds_degradation_t>::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_cmp(&lesser, &lesser), + 0); + EXPECT_EQ( + sbp_msg_ssr_orbit_clock_bounds_degradation_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_orbit_clock_bounds_degradation_cmp(&lesser, &greater), + 0); + EXPECT_GT(sbp_msg_ssr_orbit_clock_bounds_degradation_cmp(&greater, &lesser), + 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockBoundsDegradation, + &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockBoundsDegradation, + &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrOrbitClockBoundsDegradation, + &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrOrbitClockBoundsDegradation, + &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_ssr_orbit_clock_bounds_degradation_t test_msg_{}; + uint8_t encoded_frame_[28 + 8] = { 85, 223, 5, 66, 0, 28, 180, 0, 0, 0, 3, 0, 1, 2, 3, 48, 15, 1, 10, 0, 0, 0, 0, 0, 0, 0, 200, 199, 198, 197, 196, 195, 194, 193, 200, 117, }; + uint8_t encoded_payload_[28] = { + 180, 0, 0, 0, 3, 0, 1, 2, 3, 48, 15, 1, 10, 0, + 0, 0, 0, 0, 0, 0, 200, 199, 198, 197, 196, 195, 194, 193, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp_msg_ssr_orbit_clock_bounds_degradation_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrOrbitClockBoundsDegradation, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + uint8_t n_written; - sbp_msg_ssr_orbit_clock_bounds_degradation_t test_msg{}; - test_msg.const_id = 1; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 2; - test_msg.header.sol_id = 48; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 3; - test_msg.orbit_clock_bounds_degradation.clock_bound_mu_dot = 194; - test_msg.orbit_clock_bounds_degradation.clock_bound_sig_dot = 193; - test_msg.orbit_clock_bounds_degradation.orb_along_bound_mu_dot = 199; - test_msg.orbit_clock_bounds_degradation.orb_along_bound_sig_dot = 196; - test_msg.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot = 198; - test_msg.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot = 195; - test_msg.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot = 200; - test_msg.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot = 197; - test_msg.sat_bitmask = 10; - test_msg.ssr_iod = 15; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.const_id, 1) - << "incorrect value for last_msg_.const_id, expected 1, is " - << last_msg_.const_id; - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 2) - << "incorrect value for last_msg_.header.seq_num, expected 2, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 48) - << "incorrect value for last_msg_.header.sol_id, expected 48, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 3) - << "incorrect value for last_msg_.header.update_interval, expected 3, is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.clock_bound_mu_dot, 194) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.clock_bound_mu_dot, " - "expected 194, is " - << last_msg_.orbit_clock_bounds_degradation.clock_bound_mu_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.clock_bound_sig_dot, 193) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.clock_bound_sig_dot, " - "expected 193, is " - << last_msg_.orbit_clock_bounds_degradation.clock_bound_sig_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_along_bound_mu_dot, - 199) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_along_bound_mu_dot, " - "expected 199, is " - << last_msg_.orbit_clock_bounds_degradation.orb_along_bound_mu_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_along_bound_sig_dot, - 196) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_along_bound_sig_dot, " - "expected 196, is " - << last_msg_.orbit_clock_bounds_degradation.orb_along_bound_sig_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot, - 198) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot, " - "expected 198, is " - << last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot, - 195) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot, " - "expected 195, is " - << last_msg_.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot, - 200) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot, " - "expected 200, is " - << last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot; - EXPECT_EQ(last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot, - 197) - << "incorrect value for " - "last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot, " - "expected 197, is " - << last_msg_.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot; - EXPECT_EQ(last_msg_.sat_bitmask, 10) - << "incorrect value for last_msg_.sat_bitmask, expected 10, is " - << last_msg_.sat_bitmask; - EXPECT_EQ(last_msg_.ssr_iod, 15) - << "incorrect value for last_msg_.ssr_iod, expected 15, is " - << last_msg_.ssr_iod; + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrOrbitClockBoundsDegradation, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + + for (uint8_t i = 0; i < 28; i++) { + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_encode( + &buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrOrbitClockBoundsDegradation, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_bounds_degradation_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockBoundsDegradation, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrOrbitClockBoundsDegradation, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockBoundsDegradation, + info.sender_id, &info.test_msg_wrapped, + &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.const_id, greater.const_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.clock_bound_mu_dot, + greater.orbit_clock_bounds_degradation.clock_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.clock_bound_sig_dot, + greater.orbit_clock_bounds_degradation.clock_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_along_bound_mu_dot, + greater.orbit_clock_bounds_degradation.orb_along_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_along_bound_sig_dot, + greater.orbit_clock_bounds_degradation.orb_along_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot, + greater.orbit_clock_bounds_degradation.orb_cross_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot, + greater.orbit_clock_bounds_degradation.orb_cross_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot, + greater.orbit_clock_bounds_degradation.orb_radial_bound_mu_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater( + lesser.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot, + greater.orbit_clock_bounds_degradation.orb_radial_bound_sig_dot); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.sat_bitmask, greater.sat_bitmask); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_bounds_degradation_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_bounds_degradation_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod, greater.ssr_iod); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrOrbitClockBoundsDegradation); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_SSR_ORBIT_CLOCK_BOUNDS_DEGRADATION"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_orbit_clock_bounds_degradation_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_orbit_clock_bounds_degradation_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits< + sbp_msg_ssr_orbit_clock_bounds_degradation_t>::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_orbit_clock_bounds_degradation, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_orbit_clock_bounds_degradation, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits:: + encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[28]; + uint8_t n_written; + + EXPECT_EQ( + sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 28); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 28), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_bounds_degradation_t msg{}; + uint8_t n_read; + + EXPECT_EQ( + sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 28); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrOrbitClockBoundsDegradation, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockBoundsDegradation0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgSsrOrbitClockBoundsDegradation, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc new file mode 100644 index 0000000000..1967dc14c8 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc @@ -0,0 +1,896 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0() { + assign(test_msg_.along, 132661048); + assign(test_msg_.c0, -970026069); + assign(test_msg_.c1, -503975083); + assign(test_msg_.c2, -759858197); + assign(test_msg_.cross, 1845577176); + assign(test_msg_.dot_along, 72905755); + assign(test_msg_.dot_cross, 311886653); + assign(test_msg_.dot_radial, -1111196507); + assign(test_msg_.iod, 193); + assign(test_msg_.iod_ssr, 211); + assign(test_msg_.radial, -24141393); + assign(test_msg_.sid.code, 30); + assign(test_msg_.sid.sat, 1); + assign(test_msg_.time.tow, 3172954849); + assign(test_msg_.time.wn, 7723); + assign(test_msg_.update_interval, 194); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_orbit_clock_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrOrbitClockDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_orbit_clock_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrOrbitClockDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_orbit_clock_dep_a, + sizeof(msg->ssr_orbit_clock_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_orbit_clock_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_orbit_clock_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrOrbitClockDepA); + info.sender_id = 42529; + info.preamble = 0x55; + info.crc = 0xfc9d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 47; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_orbit_clock_dep_a_t &lesser, + const sbp_msg_ssr_orbit_clock_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_orbit_clock_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_orbit_clock_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrOrbitClockDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrOrbitClockDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrOrbitClockDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_orbit_clock_dep_a_t test_msg_{}; + uint8_t encoded_frame_[47 + 8] = { + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, + 194, 211, 193, 175, 161, 143, 254, 56, 63, 232, 7, 216, 69, 1, + 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, 151, 18, 171, + 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + }; + uint8_t encoded_payload_[47] = { + 225, 114, 31, 189, 43, 30, 1, 30, 194, 211, 193, 175, + 161, 143, 254, 56, 63, 232, 7, 216, 69, 1, 110, 165, + 124, 196, 189, 27, 116, 88, 4, 61, 3, 151, 18, 171, + 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrOrbitClockDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[47]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 47); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 47), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrOrbitClockDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 47); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 47), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[47]; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 47), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[47]; + + for (uint8_t i = 0; i < 47; i++) { + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 47); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrOrbitClockDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 47); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_orbit_clock_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrOrbitClockDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrOrbitClockDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.along, greater.along); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c0, greater.c0); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c1, greater.c1); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.c2, greater.c2); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cross, greater.cross); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.dot_along, greater.dot_along); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.dot_cross, greater.dot_cross); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.dot_radial, greater.dot_radial); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.iod, greater.iod); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.iod_ssr, greater.iod_ssr); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.radial, greater.radial); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_orbit_clock_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_orbit_clock_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrOrbitClockDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_ORBIT_CLOCK_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_orbit_clock_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_orbit_clock_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_orbit_clock_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_orbit_clock_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[47]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 47); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 47), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_orbit_clock_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 47); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrOrbitClockDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrOrbitClockDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrOrbitClockDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc new file mode 100644 index 0000000000..f3c14634a2 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc @@ -0,0 +1,2096 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrPhaseBiases0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrPhaseBiases0() { + assign(test_msg_.biases[0].bias, -1311498533); + assign(test_msg_.biases[0].code, 29); + assign(test_msg_.biases[0].discontinuity_counter, 193); + assign(test_msg_.biases[0].integer_indicator, 250); + assign(test_msg_.biases[0].widelane_integer_indicator, 245); + + assign(test_msg_.biases[1].bias, 1101319226); + assign(test_msg_.biases[1].code, 207); + assign(test_msg_.biases[1].discontinuity_counter, 146); + assign(test_msg_.biases[1].integer_indicator, 187); + assign(test_msg_.biases[1].widelane_integer_indicator, 33); + + assign(test_msg_.biases[2].bias, -64184056); + assign(test_msg_.biases[2].code, 114); + assign(test_msg_.biases[2].discontinuity_counter, 52); + assign(test_msg_.biases[2].integer_indicator, 49); + assign(test_msg_.biases[2].widelane_integer_indicator, 248); + + assign(test_msg_.biases[3].bias, -240298362); + assign(test_msg_.biases[3].code, 166); + assign(test_msg_.biases[3].discontinuity_counter, 124); + assign(test_msg_.biases[3].integer_indicator, 168); + assign(test_msg_.biases[3].widelane_integer_indicator, 232); + + assign(test_msg_.biases[4].bias, -1581740159); + assign(test_msg_.biases[4].code, 174); + assign(test_msg_.biases[4].discontinuity_counter, 155); + assign(test_msg_.biases[4].integer_indicator, 44); + assign(test_msg_.biases[4].widelane_integer_indicator, 142); + + assign(test_msg_.biases[5].bias, -1730297136); + assign(test_msg_.biases[5].code, 211); + assign(test_msg_.biases[5].discontinuity_counter, 189); + assign(test_msg_.biases[5].integer_indicator, 15); + assign(test_msg_.biases[5].widelane_integer_indicator, 36); + + assign(test_msg_.biases[6].bias, -1117221444); + assign(test_msg_.biases[6].code, 16); + assign(test_msg_.biases[6].discontinuity_counter, 34); + assign(test_msg_.biases[6].integer_indicator, 203); + assign(test_msg_.biases[6].widelane_integer_indicator, 87); + + assign(test_msg_.biases[7].bias, -1137604357); + assign(test_msg_.biases[7].code, 102); + assign(test_msg_.biases[7].discontinuity_counter, 22); + assign(test_msg_.biases[7].integer_indicator, 156); + assign(test_msg_.biases[7].widelane_integer_indicator, 252); + + assign(test_msg_.biases[8].bias, -1910370172); + assign(test_msg_.biases[8].code, 157); + assign(test_msg_.biases[8].discontinuity_counter, 49); + assign(test_msg_.biases[8].integer_indicator, 222); + assign(test_msg_.biases[8].widelane_integer_indicator, 245); + + assign(test_msg_.biases[9].bias, 1247996869); + assign(test_msg_.biases[9].code, 228); + assign(test_msg_.biases[9].discontinuity_counter, 221); + assign(test_msg_.biases[9].integer_indicator, 85); + assign(test_msg_.biases[9].widelane_integer_indicator, 139); + + assign(test_msg_.biases[10].bias, -1133446161); + assign(test_msg_.biases[10].code, 107); + assign(test_msg_.biases[10].discontinuity_counter, 38); + assign(test_msg_.biases[10].integer_indicator, 70); + assign(test_msg_.biases[10].widelane_integer_indicator, 36); + + assign(test_msg_.biases[11].bias, -720934762); + assign(test_msg_.biases[11].code, 124); + assign(test_msg_.biases[11].discontinuity_counter, 164); + assign(test_msg_.biases[11].integer_indicator, 246); + assign(test_msg_.biases[11].widelane_integer_indicator, 141); + + assign(test_msg_.biases[12].bias, 706252548); + assign(test_msg_.biases[12].code, 44); + assign(test_msg_.biases[12].discontinuity_counter, 192); + assign(test_msg_.biases[12].integer_indicator, 21); + assign(test_msg_.biases[12].widelane_integer_indicator, 244); + + assign(test_msg_.biases[13].bias, 388855338); + assign(test_msg_.biases[13].code, 21); + assign(test_msg_.biases[13].discontinuity_counter, 7); + assign(test_msg_.biases[13].integer_indicator, 84); + assign(test_msg_.biases[13].widelane_integer_indicator, 136); + + assign(test_msg_.biases[14].bias, 47517353); + assign(test_msg_.biases[14].code, 174); + assign(test_msg_.biases[14].discontinuity_counter, 54); + assign(test_msg_.biases[14].integer_indicator, 175); + assign(test_msg_.biases[14].widelane_integer_indicator, 129); + + assign(test_msg_.biases[15].bias, -2124125745); + assign(test_msg_.biases[15].code, 197); + assign(test_msg_.biases[15].discontinuity_counter, 13); + assign(test_msg_.biases[15].integer_indicator, 98); + assign(test_msg_.biases[15].widelane_integer_indicator, 60); + + assign(test_msg_.biases[16].bias, -1401812607); + assign(test_msg_.biases[16].code, 72); + assign(test_msg_.biases[16].discontinuity_counter, 140); + assign(test_msg_.biases[16].integer_indicator, 136); + assign(test_msg_.biases[16].widelane_integer_indicator, 240); + + assign(test_msg_.biases[17].bias, 60257151); + assign(test_msg_.biases[17].code, 151); + assign(test_msg_.biases[17].discontinuity_counter, 210); + assign(test_msg_.biases[17].integer_indicator, 150); + assign(test_msg_.biases[17].widelane_integer_indicator, 17); + + assign(test_msg_.biases[18].bias, 41820677); + assign(test_msg_.biases[18].code, 242); + assign(test_msg_.biases[18].discontinuity_counter, 14); + assign(test_msg_.biases[18].integer_indicator, 254); + assign(test_msg_.biases[18].widelane_integer_indicator, 215); + + assign(test_msg_.biases[19].bias, 1640616471); + assign(test_msg_.biases[19].code, 215); + assign(test_msg_.biases[19].discontinuity_counter, 176); + assign(test_msg_.biases[19].integer_indicator, 65); + assign(test_msg_.biases[19].widelane_integer_indicator, 38); + + assign(test_msg_.biases[20].bias, -744786918); + assign(test_msg_.biases[20].code, 36); + assign(test_msg_.biases[20].discontinuity_counter, 224); + assign(test_msg_.biases[20].integer_indicator, 207); + assign(test_msg_.biases[20].widelane_integer_indicator, 92); + + assign(test_msg_.biases[21].bias, 1966589763); + assign(test_msg_.biases[21].code, 165); + assign(test_msg_.biases[21].discontinuity_counter, 38); + assign(test_msg_.biases[21].integer_indicator, 47); + assign(test_msg_.biases[21].widelane_integer_indicator, 102); + + assign(test_msg_.biases[22].bias, 364366310); + assign(test_msg_.biases[22].code, 36); + assign(test_msg_.biases[22].discontinuity_counter, 1); + assign(test_msg_.biases[22].integer_indicator, 169); + assign(test_msg_.biases[22].widelane_integer_indicator, 33); + + assign(test_msg_.biases[23].bias, -1839031379); + assign(test_msg_.biases[23].code, 42); + assign(test_msg_.biases[23].discontinuity_counter, 173); + assign(test_msg_.biases[23].integer_indicator, 62); + assign(test_msg_.biases[23].widelane_integer_indicator, 147); + + assign(test_msg_.biases[24].bias, 31817639); + assign(test_msg_.biases[24].code, 231); + assign(test_msg_.biases[24].discontinuity_counter, 82); + assign(test_msg_.biases[24].integer_indicator, 167); + assign(test_msg_.biases[24].widelane_integer_indicator, 138); + + assign(test_msg_.biases[25].bias, -1619830156); + assign(test_msg_.biases[25].code, 2); + assign(test_msg_.biases[25].discontinuity_counter, 207); + assign(test_msg_.biases[25].integer_indicator, 127); + assign(test_msg_.biases[25].widelane_integer_indicator, 237); + + assign(test_msg_.biases[26].bias, -83375622); + assign(test_msg_.biases[26].code, 3); + assign(test_msg_.biases[26].discontinuity_counter, 145); + assign(test_msg_.biases[26].integer_indicator, 42); + assign(test_msg_.biases[26].widelane_integer_indicator, 66); + + assign(test_msg_.biases[27].bias, 1077458389); + assign(test_msg_.biases[27].code, 2); + assign(test_msg_.biases[27].discontinuity_counter, 26); + assign(test_msg_.biases[27].integer_indicator, 75); + assign(test_msg_.biases[27].widelane_integer_indicator, 230); + + assign(test_msg_.biases[28].bias, -883355501); + assign(test_msg_.biases[28].code, 97); + assign(test_msg_.biases[28].discontinuity_counter, 6); + assign(test_msg_.biases[28].integer_indicator, 88); + assign(test_msg_.biases[28].widelane_integer_indicator, 255); + + assign(test_msg_.biases[29].bias, -1448611273); + assign(test_msg_.biases[29].code, 27); + assign(test_msg_.biases[29].discontinuity_counter, 230); + assign(test_msg_.biases[29].integer_indicator, 68); + assign(test_msg_.biases[29].widelane_integer_indicator, 243); + assign(test_msg_.dispersive_bias, 98); + assign(test_msg_.iod_ssr, 230); + assign(test_msg_.mw_consistency, 209); + assign(test_msg_.n_biases, 30); + assign(test_msg_.sid.code, 82); + assign(test_msg_.sid.sat, 169); + assign(test_msg_.time.tow, 210803409); + assign(test_msg_.time.wn, 42197); + assign(test_msg_.update_interval, 177); + assign(test_msg_.yaw, 5881); + assign(test_msg_.yaw_rate, 17); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_phase_biases_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_phase_biases_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrPhaseBiases, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_phase_biases_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrPhaseBiases); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_phase_biases, + sizeof(msg->ssr_phase_biases)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_phase_biases_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_phase_biases, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrPhaseBiases); + info.sender_id = 52955; + info.preamble = 0x55; + info.crc = 0xf0db; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_phase_biases_t &lesser, + const sbp_msg_ssr_phase_biases_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_phase_biases_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_phase_biases_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_phase_biases_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_phase_biases_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSsrPhaseBiases, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrPhaseBiases, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrPhaseBiases, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrPhaseBiases, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_phase_biases_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, 177, + 230, 98, 209, 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, 177, 207, + 187, 33, 146, 58, 204, 164, 65, 114, 49, 248, 52, 8, 161, 44, 252, + 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, 155, 129, 143, 184, + 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, 203, 87, 34, 188, 141, + 104, 189, 102, 156, 252, 22, 251, 136, 49, 188, 157, 222, 245, 49, 132, + 16, 34, 142, 228, 85, 139, 221, 197, 235, 98, 74, 107, 70, 36, 38, + 239, 251, 112, 188, 124, 246, 141, 164, 150, 104, 7, 213, 44, 21, 244, + 192, 4, 143, 24, 42, 21, 84, 136, 7, 42, 118, 45, 23, 174, 175, + 129, 54, 169, 14, 213, 2, 197, 98, 60, 13, 207, 105, 100, 129, 72, + 136, 240, 140, 129, 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, + 242, 254, 215, 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, + 97, 36, 207, 92, 224, 26, 116, 155, 211, 165, 47, 102, 38, 67, 199, + 55, 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, 62, 147, 173, 173, + 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, 207, + 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, 75, 230, + 26, 213, 181, 56, 64, 97, 88, 255, 6, 147, 16, 89, 203, 27, 68, + 243, 230, 55, 242, 167, 169, 219, 240, + }; + uint8_t encoded_payload_[255] = { + 209, 154, 144, 12, 213, 164, 169, 82, 177, 230, 98, 209, 249, 22, 17, + 29, 250, 245, 193, 219, 30, 212, 177, 207, 187, 33, 146, 58, 204, 164, + 65, 114, 49, 248, 52, 8, 161, 44, 252, 166, 168, 232, 124, 134, 86, + 173, 241, 174, 44, 142, 155, 129, 143, 184, 161, 211, 15, 36, 189, 208, + 194, 221, 152, 16, 203, 87, 34, 188, 141, 104, 189, 102, 156, 252, 22, + 251, 136, 49, 188, 157, 222, 245, 49, 132, 16, 34, 142, 228, 85, 139, + 221, 197, 235, 98, 74, 107, 70, 36, 38, 239, 251, 112, 188, 124, 246, + 141, 164, 150, 104, 7, 213, 44, 21, 244, 192, 4, 143, 24, 42, 21, + 84, 136, 7, 42, 118, 45, 23, 174, 175, 129, 54, 169, 14, 213, 2, + 197, 98, 60, 13, 207, 105, 100, 129, 72, 136, 240, 140, 129, 9, 114, + 172, 151, 150, 17, 210, 127, 115, 151, 3, 242, 254, 215, 14, 5, 34, + 126, 2, 215, 65, 38, 176, 23, 210, 201, 97, 36, 207, 92, 224, 26, + 116, 155, 211, 165, 47, 102, 38, 67, 199, 55, 117, 36, 169, 33, 1, + 230, 201, 183, 21, 42, 62, 147, 173, 173, 155, 98, 146, 231, 167, 138, + 82, 167, 127, 229, 1, 2, 127, 237, 207, 116, 90, 115, 159, 3, 42, + 66, 145, 250, 201, 7, 251, 2, 75, 230, 26, 213, 181, 56, 64, 97, + 88, 255, 6, 147, 16, 89, 203, 27, 68, 243, 230, 55, 242, 167, 169, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_phase_biases_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrPhaseBiases, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_phase_biases_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrPhaseBiases, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ(sbp_msg_ssr_phase_biases_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ( + sbp_msg_ssr_phase_biases_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_phase_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_phase_biases_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrPhaseBiases, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_phase_biases_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_phase_biases_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_phase_biases_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_phase_biases_t t{}; + return sbp_msg_ssr_phase_biases_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_phase_biases_t t{}; + t.n_biases = 1; + return sbp_msg_ssr_phase_biases_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_phase_biases_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_phase_biases_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrPhaseBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrPhaseBiases, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrPhaseBiases, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].bias, greater.biases[0].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].code, greater.biases[0].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].discontinuity_counter, + greater.biases[0].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].integer_indicator, + greater.biases[0].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[0].widelane_integer_indicator, + greater.biases[0].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].bias, greater.biases[1].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].code, greater.biases[1].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].discontinuity_counter, + greater.biases[1].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].integer_indicator, + greater.biases[1].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[1].widelane_integer_indicator, + greater.biases[1].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].bias, greater.biases[2].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].code, greater.biases[2].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].discontinuity_counter, + greater.biases[2].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].integer_indicator, + greater.biases[2].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[2].widelane_integer_indicator, + greater.biases[2].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].bias, greater.biases[3].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].code, greater.biases[3].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].discontinuity_counter, + greater.biases[3].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].integer_indicator, + greater.biases[3].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[3].widelane_integer_indicator, + greater.biases[3].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].bias, greater.biases[4].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].code, greater.biases[4].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].discontinuity_counter, + greater.biases[4].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].integer_indicator, + greater.biases[4].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[4].widelane_integer_indicator, + greater.biases[4].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].bias, greater.biases[5].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].code, greater.biases[5].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].discontinuity_counter, + greater.biases[5].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].integer_indicator, + greater.biases[5].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[5].widelane_integer_indicator, + greater.biases[5].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].bias, greater.biases[6].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].code, greater.biases[6].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].discontinuity_counter, + greater.biases[6].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].integer_indicator, + greater.biases[6].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[6].widelane_integer_indicator, + greater.biases[6].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].bias, greater.biases[7].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].code, greater.biases[7].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].discontinuity_counter, + greater.biases[7].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].integer_indicator, + greater.biases[7].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[7].widelane_integer_indicator, + greater.biases[7].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].bias, greater.biases[8].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].code, greater.biases[8].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].discontinuity_counter, + greater.biases[8].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].integer_indicator, + greater.biases[8].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[8].widelane_integer_indicator, + greater.biases[8].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].bias, greater.biases[9].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].code, greater.biases[9].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].discontinuity_counter, + greater.biases[9].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].integer_indicator, + greater.biases[9].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[9].widelane_integer_indicator, + greater.biases[9].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].bias, greater.biases[10].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].code, greater.biases[10].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].discontinuity_counter, + greater.biases[10].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].integer_indicator, + greater.biases[10].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[10].widelane_integer_indicator, + greater.biases[10].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].bias, greater.biases[11].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].code, greater.biases[11].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].discontinuity_counter, + greater.biases[11].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].integer_indicator, + greater.biases[11].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[11].widelane_integer_indicator, + greater.biases[11].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].bias, greater.biases[12].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].code, greater.biases[12].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].discontinuity_counter, + greater.biases[12].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].integer_indicator, + greater.biases[12].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[12].widelane_integer_indicator, + greater.biases[12].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].bias, greater.biases[13].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].code, greater.biases[13].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].discontinuity_counter, + greater.biases[13].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].integer_indicator, + greater.biases[13].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[13].widelane_integer_indicator, + greater.biases[13].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].bias, greater.biases[14].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].code, greater.biases[14].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].discontinuity_counter, + greater.biases[14].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].integer_indicator, + greater.biases[14].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[14].widelane_integer_indicator, + greater.biases[14].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].bias, greater.biases[15].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].code, greater.biases[15].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].discontinuity_counter, + greater.biases[15].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].integer_indicator, + greater.biases[15].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[15].widelane_integer_indicator, + greater.biases[15].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].bias, greater.biases[16].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].code, greater.biases[16].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].discontinuity_counter, + greater.biases[16].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].integer_indicator, + greater.biases[16].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[16].widelane_integer_indicator, + greater.biases[16].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].bias, greater.biases[17].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].code, greater.biases[17].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].discontinuity_counter, + greater.biases[17].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].integer_indicator, + greater.biases[17].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[17].widelane_integer_indicator, + greater.biases[17].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].bias, greater.biases[18].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].code, greater.biases[18].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].discontinuity_counter, + greater.biases[18].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].integer_indicator, + greater.biases[18].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[18].widelane_integer_indicator, + greater.biases[18].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].bias, greater.biases[19].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].code, greater.biases[19].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].discontinuity_counter, + greater.biases[19].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].integer_indicator, + greater.biases[19].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[19].widelane_integer_indicator, + greater.biases[19].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].bias, greater.biases[20].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].code, greater.biases[20].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].discontinuity_counter, + greater.biases[20].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].integer_indicator, + greater.biases[20].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[20].widelane_integer_indicator, + greater.biases[20].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].bias, greater.biases[21].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].code, greater.biases[21].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].discontinuity_counter, + greater.biases[21].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].integer_indicator, + greater.biases[21].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[21].widelane_integer_indicator, + greater.biases[21].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].bias, greater.biases[22].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].code, greater.biases[22].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].discontinuity_counter, + greater.biases[22].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].integer_indicator, + greater.biases[22].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[22].widelane_integer_indicator, + greater.biases[22].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].bias, greater.biases[23].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].code, greater.biases[23].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].discontinuity_counter, + greater.biases[23].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].integer_indicator, + greater.biases[23].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[23].widelane_integer_indicator, + greater.biases[23].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].bias, greater.biases[24].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].code, greater.biases[24].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].discontinuity_counter, + greater.biases[24].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].integer_indicator, + greater.biases[24].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[24].widelane_integer_indicator, + greater.biases[24].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].bias, greater.biases[25].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].code, greater.biases[25].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].discontinuity_counter, + greater.biases[25].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].integer_indicator, + greater.biases[25].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[25].widelane_integer_indicator, + greater.biases[25].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].bias, greater.biases[26].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].code, greater.biases[26].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].discontinuity_counter, + greater.biases[26].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].integer_indicator, + greater.biases[26].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[26].widelane_integer_indicator, + greater.biases[26].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].bias, greater.biases[27].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].code, greater.biases[27].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].discontinuity_counter, + greater.biases[27].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].integer_indicator, + greater.biases[27].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[27].widelane_integer_indicator, + greater.biases[27].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].bias, greater.biases[28].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].code, greater.biases[28].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].discontinuity_counter, + greater.biases[28].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].integer_indicator, + greater.biases[28].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[28].widelane_integer_indicator, + greater.biases[28].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].bias, greater.biases[29].bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].code, greater.biases[29].code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].discontinuity_counter, + greater.biases[29].discontinuity_counter); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].integer_indicator, + greater.biases[29].integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.biases[29].widelane_integer_indicator, + greater.biases[29].widelane_integer_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.dispersive_bias, greater.dispersive_bias); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.iod_ssr, greater.iod_ssr); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.mw_consistency, greater.mw_consistency); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.n_biases, greater.n_biases); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.yaw, greater.yaw); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_phase_biases_t lesser = info.test_msg; + sbp_msg_ssr_phase_biases_t greater = info.test_msg; + make_lesser_greater(lesser.yaw_rate, greater.yaw_rate); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrPhaseBiases); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_PHASE_BIASES"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_phase_biases_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_phase_biases_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ssr_phase_biases, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_phase_biases, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_phase_biases_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrPhaseBiases, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrPhaseBiases0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrPhaseBiases, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApc.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApc.cc index 6090676ff5..1a33663785 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApc.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApc.cc @@ -16,244 +16,1062 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrSatelliteApc0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrSatelliteApc0 : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrSatelliteApc0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrSatelliteApc0() { + assign(test_msg_.apc[0].pco[0], 1); + + assign(test_msg_.apc[0].pco[1], -1); + + assign(test_msg_.apc[0].pco[2], 729); + + assign(test_msg_.apc[0].pcv[0], 11); + + assign(test_msg_.apc[0].pcv[1], 10); + + assign(test_msg_.apc[0].pcv[2], 8); + + assign(test_msg_.apc[0].pcv[3], 5); + + assign(test_msg_.apc[0].pcv[4], 1); + + assign(test_msg_.apc[0].pcv[5], -4); + + assign(test_msg_.apc[0].pcv[6], -8); + + assign(test_msg_.apc[0].pcv[7], -10); + + assign(test_msg_.apc[0].pcv[8], -10); + + assign(test_msg_.apc[0].pcv[9], -10); + + assign(test_msg_.apc[0].pcv[10], -7); + + assign(test_msg_.apc[0].pcv[11], -4); + + assign(test_msg_.apc[0].pcv[12], 0); + + assign(test_msg_.apc[0].pcv[13], 6); + + assign(test_msg_.apc[0].pcv[14], 12); + + assign(test_msg_.apc[0].pcv[15], 22); + + assign(test_msg_.apc[0].pcv[16], 30); + + assign(test_msg_.apc[0].pcv[17], 41); + + assign(test_msg_.apc[0].pcv[18], 41); + + assign(test_msg_.apc[0].pcv[19], 41); + + assign(test_msg_.apc[0].pcv[20], 41); + assign(test_msg_.apc[0].sat_info, 4); + assign(test_msg_.apc[0].sid.code, 0); + assign(test_msg_.apc[0].sid.sat, 2); + assign(test_msg_.apc[0].svn, 61); + assign(test_msg_.iod_ssr, 3); + assign(test_msg_.n_apc, 1); + assign(test_msg_.sol_id, 2); + assign(test_msg_.time.tow, 604799); + assign(test_msg_.time.wn, 2222); + assign(test_msg_.update_interval, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_satellite_apc_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_satellite_apc_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrSatelliteApc, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_satellite_apc_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrSatelliteApc); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_satellite_apc, + sizeof(msg->ssr_satellite_apc)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_satellite_apc_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_satellite_apc, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrSatelliteApc); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0xA190; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 41; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_satellite_apc_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_satellite_apc_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_satellite_apc_t &lesser, + const sbp_msg_ssr_satellite_apc_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_satellite_apc_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_satellite_apc_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_satellite_apc_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrSatelliteApc, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrSatelliteApc, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrSatelliteApc, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrSatelliteApc, &wrapped_greater, + &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_ssr_MsgSsrSatelliteApc0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_satellite_apc_t test_msg_{}; + uint8_t encoded_frame_[41 + 8] = { 85, 5, 6, 0, 0, 41, 127, 58, 9, 0, 174, 8, 1, 2, 3, 2, 0, 4, 61, 0, 1, 0, 255, 255, 217, 2, 11, 10, 8, 5, 1, 252, 248, 246, 246, 246, 249, 252, 0, 6, 12, 22, 30, 41, 41, 41, 41, 144, 161, }; + uint8_t encoded_payload_[41] = { + 127, 58, 9, 0, 174, 8, 1, 2, 3, 2, 0, 4, 61, 0, + 1, 0, 255, 255, 217, 2, 11, 10, 8, 5, 1, 252, 248, 246, + 246, 246, 249, 252, 0, 6, 12, 22, 30, 41, 41, 41, 41, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_satellite_apc_encoded_len(&info.test_msg), + info.payload_len); - sbp_msg_ssr_satellite_apc_t test_msg{}; + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrSatelliteApc, &info.test_msg_wrapped), + info.payload_len); +} - test_msg.apc[0].pco[0] = 1; +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + uint8_t n_written; - test_msg.apc[0].pco[1] = -1; + EXPECT_EQ(sbp_msg_ssr_satellite_apc_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); - test_msg.apc[0].pco[2] = 729; + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrSatelliteApc, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} - test_msg.apc[0].pcv[0] = 11; +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[41]; - test_msg.apc[0].pcv[1] = 10; + EXPECT_EQ(sbp_msg_ssr_satellite_apc_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[41]; - test_msg.apc[0].pcv[2] = 8; + for (uint8_t i = 0; i < 41; i++) { + EXPECT_EQ( + sbp_msg_ssr_satellite_apc_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} - test_msg.apc[0].pcv[3] = 5; +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_t msg{}; + uint8_t n_read; - test_msg.apc[0].pcv[4] = 1; + EXPECT_EQ(sbp_msg_ssr_satellite_apc_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); - test_msg.apc[0].pcv[5] = -4; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrSatelliteApc, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); +} - test_msg.apc[0].pcv[6] = -8; +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_t msg{}; - test_msg.apc[0].pcv[7] = -10; - - test_msg.apc[0].pcv[8] = -10; - - test_msg.apc[0].pcv[9] = -10; - - test_msg.apc[0].pcv[10] = -7; - - test_msg.apc[0].pcv[11] = -4; - - test_msg.apc[0].pcv[12] = 0; - - test_msg.apc[0].pcv[13] = 6; - - test_msg.apc[0].pcv[14] = 12; - - test_msg.apc[0].pcv[15] = 22; - - test_msg.apc[0].pcv[16] = 30; - - test_msg.apc[0].pcv[17] = 41; - - test_msg.apc[0].pcv[18] = 41; - - test_msg.apc[0].pcv[19] = 41; - - test_msg.apc[0].pcv[20] = 41; - test_msg.apc[0].sat_info = 4; - test_msg.apc[0].sid.code = 0; - test_msg.apc[0].sid.sat = 2; - test_msg.apc[0].svn = 61; - test_msg.iod_ssr = 3; - test_msg.n_apc = 1; - test_msg.sol_id = 2; - test_msg.time.tow = 604799; - test_msg.time.wn = 2222; - test_msg.update_interval = 1; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.apc[0].pco[0], 1) - << "incorrect value for last_msg_.apc[0].pco[0], expected 1, is " - << last_msg_.apc[0].pco[0]; - EXPECT_EQ(last_msg_.apc[0].pco[1], -1) - << "incorrect value for last_msg_.apc[0].pco[1], expected -1, is " - << last_msg_.apc[0].pco[1]; - EXPECT_EQ(last_msg_.apc[0].pco[2], 729) - << "incorrect value for last_msg_.apc[0].pco[2], expected 729, is " - << last_msg_.apc[0].pco[2]; - EXPECT_EQ(last_msg_.apc[0].pcv[0], 11) - << "incorrect value for last_msg_.apc[0].pcv[0], expected 11, is " - << last_msg_.apc[0].pcv[0]; - EXPECT_EQ(last_msg_.apc[0].pcv[1], 10) - << "incorrect value for last_msg_.apc[0].pcv[1], expected 10, is " - << last_msg_.apc[0].pcv[1]; - EXPECT_EQ(last_msg_.apc[0].pcv[2], 8) - << "incorrect value for last_msg_.apc[0].pcv[2], expected 8, is " - << last_msg_.apc[0].pcv[2]; - EXPECT_EQ(last_msg_.apc[0].pcv[3], 5) - << "incorrect value for last_msg_.apc[0].pcv[3], expected 5, is " - << last_msg_.apc[0].pcv[3]; - EXPECT_EQ(last_msg_.apc[0].pcv[4], 1) - << "incorrect value for last_msg_.apc[0].pcv[4], expected 1, is " - << last_msg_.apc[0].pcv[4]; - EXPECT_EQ(last_msg_.apc[0].pcv[5], -4) - << "incorrect value for last_msg_.apc[0].pcv[5], expected -4, is " - << last_msg_.apc[0].pcv[5]; - EXPECT_EQ(last_msg_.apc[0].pcv[6], -8) - << "incorrect value for last_msg_.apc[0].pcv[6], expected -8, is " - << last_msg_.apc[0].pcv[6]; - EXPECT_EQ(last_msg_.apc[0].pcv[7], -10) - << "incorrect value for last_msg_.apc[0].pcv[7], expected -10, is " - << last_msg_.apc[0].pcv[7]; - EXPECT_EQ(last_msg_.apc[0].pcv[8], -10) - << "incorrect value for last_msg_.apc[0].pcv[8], expected -10, is " - << last_msg_.apc[0].pcv[8]; - EXPECT_EQ(last_msg_.apc[0].pcv[9], -10) - << "incorrect value for last_msg_.apc[0].pcv[9], expected -10, is " - << last_msg_.apc[0].pcv[9]; - EXPECT_EQ(last_msg_.apc[0].pcv[10], -7) - << "incorrect value for last_msg_.apc[0].pcv[10], expected -7, is " - << last_msg_.apc[0].pcv[10]; - EXPECT_EQ(last_msg_.apc[0].pcv[11], -4) - << "incorrect value for last_msg_.apc[0].pcv[11], expected -4, is " - << last_msg_.apc[0].pcv[11]; - EXPECT_EQ(last_msg_.apc[0].pcv[12], 0) - << "incorrect value for last_msg_.apc[0].pcv[12], expected 0, is " - << last_msg_.apc[0].pcv[12]; - EXPECT_EQ(last_msg_.apc[0].pcv[13], 6) - << "incorrect value for last_msg_.apc[0].pcv[13], expected 6, is " - << last_msg_.apc[0].pcv[13]; - EXPECT_EQ(last_msg_.apc[0].pcv[14], 12) - << "incorrect value for last_msg_.apc[0].pcv[14], expected 12, is " - << last_msg_.apc[0].pcv[14]; - EXPECT_EQ(last_msg_.apc[0].pcv[15], 22) - << "incorrect value for last_msg_.apc[0].pcv[15], expected 22, is " - << last_msg_.apc[0].pcv[15]; - EXPECT_EQ(last_msg_.apc[0].pcv[16], 30) - << "incorrect value for last_msg_.apc[0].pcv[16], expected 30, is " - << last_msg_.apc[0].pcv[16]; - EXPECT_EQ(last_msg_.apc[0].pcv[17], 41) - << "incorrect value for last_msg_.apc[0].pcv[17], expected 41, is " - << last_msg_.apc[0].pcv[17]; - EXPECT_EQ(last_msg_.apc[0].pcv[18], 41) - << "incorrect value for last_msg_.apc[0].pcv[18], expected 41, is " - << last_msg_.apc[0].pcv[18]; - EXPECT_EQ(last_msg_.apc[0].pcv[19], 41) - << "incorrect value for last_msg_.apc[0].pcv[19], expected 41, is " - << last_msg_.apc[0].pcv[19]; - EXPECT_EQ(last_msg_.apc[0].pcv[20], 41) - << "incorrect value for last_msg_.apc[0].pcv[20], expected 41, is " - << last_msg_.apc[0].pcv[20]; - EXPECT_EQ(last_msg_.apc[0].sat_info, 4) - << "incorrect value for last_msg_.apc[0].sat_info, expected 4, is " - << last_msg_.apc[0].sat_info; - EXPECT_EQ(last_msg_.apc[0].sid.code, 0) - << "incorrect value for last_msg_.apc[0].sid.code, expected 0, is " - << last_msg_.apc[0].sid.code; - EXPECT_EQ(last_msg_.apc[0].sid.sat, 2) - << "incorrect value for last_msg_.apc[0].sid.sat, expected 2, is " - << last_msg_.apc[0].sid.sat; - EXPECT_EQ(last_msg_.apc[0].svn, 61) - << "incorrect value for last_msg_.apc[0].svn, expected 61, is " - << last_msg_.apc[0].svn; - EXPECT_EQ(last_msg_.iod_ssr, 3) - << "incorrect value for last_msg_.iod_ssr, expected 3, is " - << last_msg_.iod_ssr; - EXPECT_EQ(last_msg_.n_apc, 1) - << "incorrect value for last_msg_.n_apc, expected 1, is " - << last_msg_.n_apc; - EXPECT_EQ(last_msg_.sol_id, 2) - << "incorrect value for last_msg_.sol_id, expected 2, is " - << last_msg_.sol_id; - EXPECT_EQ(last_msg_.time.tow, 604799) - << "incorrect value for last_msg_.time.tow, expected 604799, is " - << last_msg_.time.tow; - EXPECT_EQ(last_msg_.time.wn, 2222) - << "incorrect value for last_msg_.time.wn, expected 2222, is " - << last_msg_.time.wn; - EXPECT_EQ(last_msg_.update_interval, 1) - << "incorrect value for last_msg_.update_interval, expected 1, is " - << last_msg_.update_interval; + EXPECT_EQ(sbp_msg_ssr_satellite_apc_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); } +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_satellite_apc_t t{}; + return sbp_msg_ssr_satellite_apc_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_satellite_apc_t t{}; + t.n_apc = 1; + return sbp_msg_ssr_satellite_apc_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrSatelliteApc, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrSatelliteApc, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrSatelliteApc, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[0], greater.apc[0].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[1], greater.apc[0].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[2], greater.apc[0].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[0], greater.apc[0].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[1], greater.apc[0].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[2], greater.apc[0].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[3], greater.apc[0].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[4], greater.apc[0].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[5], greater.apc[0].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[6], greater.apc[0].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[7], greater.apc[0].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[8], greater.apc[0].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[9], greater.apc[0].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[10], greater.apc[0].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[11], greater.apc[0].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[12], greater.apc[0].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[13], greater.apc[0].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[14], greater.apc[0].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[15], greater.apc[0].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[16], greater.apc[0].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[17], greater.apc[0].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[18], greater.apc[0].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[19], greater.apc[0].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[20], greater.apc[0].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sat_info, greater.apc[0].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sid.code, greater.apc[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sid.sat, greater.apc[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].svn, greater.apc[0].svn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.iod_ssr, greater.iod_ssr); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.n_apc, greater.n_apc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.sol_id, greater.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrSatelliteApc); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_SATELLITE_APC"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_satellite_apc_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_satellite_apc_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_satellite_apc, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_satellite_apc, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[41]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 41); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 41), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 41); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrSatelliteApc, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApc0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrSatelliteApc, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc new file mode 100644 index 0000000000..cf2d5c433a --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc @@ -0,0 +1,2537 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0() { + assign(test_msg_.apc[0].pco[0], -21547); + + assign(test_msg_.apc[0].pco[1], -10498); + + assign(test_msg_.apc[0].pco[2], 1236); + + assign(test_msg_.apc[0].pcv[0], 8); + + assign(test_msg_.apc[0].pcv[1], 33); + + assign(test_msg_.apc[0].pcv[2], 31); + + assign(test_msg_.apc[0].pcv[3], 80); + + assign(test_msg_.apc[0].pcv[4], 21); + + assign(test_msg_.apc[0].pcv[5], 4); + + assign(test_msg_.apc[0].pcv[6], 105); + + assign(test_msg_.apc[0].pcv[7], -31); + + assign(test_msg_.apc[0].pcv[8], 39); + + assign(test_msg_.apc[0].pcv[9], -117); + + assign(test_msg_.apc[0].pcv[10], 124); + + assign(test_msg_.apc[0].pcv[11], -107); + + assign(test_msg_.apc[0].pcv[12], 48); + + assign(test_msg_.apc[0].pcv[13], 15); + + assign(test_msg_.apc[0].pcv[14], -42); + + assign(test_msg_.apc[0].pcv[15], -59); + + assign(test_msg_.apc[0].pcv[16], -115); + + assign(test_msg_.apc[0].pcv[17], 32); + + assign(test_msg_.apc[0].pcv[18], 33); + + assign(test_msg_.apc[0].pcv[19], -121); + + assign(test_msg_.apc[0].pcv[20], -106); + assign(test_msg_.apc[0].sat_info, 240); + assign(test_msg_.apc[0].sid.code, 169); + assign(test_msg_.apc[0].sid.sat, 203); + assign(test_msg_.apc[0].svn, 1102); + + assign(test_msg_.apc[1].pco[0], 23079); + + assign(test_msg_.apc[1].pco[1], -22252); + + assign(test_msg_.apc[1].pco[2], 12271); + + assign(test_msg_.apc[1].pcv[0], -103); + + assign(test_msg_.apc[1].pcv[1], -81); + + assign(test_msg_.apc[1].pcv[2], 35); + + assign(test_msg_.apc[1].pcv[3], -111); + + assign(test_msg_.apc[1].pcv[4], -111); + + assign(test_msg_.apc[1].pcv[5], 123); + + assign(test_msg_.apc[1].pcv[6], -62); + + assign(test_msg_.apc[1].pcv[7], 2); + + assign(test_msg_.apc[1].pcv[8], 102); + + assign(test_msg_.apc[1].pcv[9], 74); + + assign(test_msg_.apc[1].pcv[10], -107); + + assign(test_msg_.apc[1].pcv[11], 95); + + assign(test_msg_.apc[1].pcv[12], -85); + + assign(test_msg_.apc[1].pcv[13], -18); + + assign(test_msg_.apc[1].pcv[14], -7); + + assign(test_msg_.apc[1].pcv[15], 7); + + assign(test_msg_.apc[1].pcv[16], -19); + + assign(test_msg_.apc[1].pcv[17], -86); + + assign(test_msg_.apc[1].pcv[18], 125); + + assign(test_msg_.apc[1].pcv[19], 106); + + assign(test_msg_.apc[1].pcv[20], -98); + assign(test_msg_.apc[1].sat_info, 49); + assign(test_msg_.apc[1].sid.code, 123); + assign(test_msg_.apc[1].sid.sat, 148); + assign(test_msg_.apc[1].svn, 24967); + + assign(test_msg_.apc[2].pco[0], -7596); + + assign(test_msg_.apc[2].pco[1], 31630); + + assign(test_msg_.apc[2].pco[2], -9907); + + assign(test_msg_.apc[2].pcv[0], -8); + + assign(test_msg_.apc[2].pcv[1], 67); + + assign(test_msg_.apc[2].pcv[2], -41); + + assign(test_msg_.apc[2].pcv[3], -127); + + assign(test_msg_.apc[2].pcv[4], 114); + + assign(test_msg_.apc[2].pcv[5], -118); + + assign(test_msg_.apc[2].pcv[6], 25); + + assign(test_msg_.apc[2].pcv[7], -16); + + assign(test_msg_.apc[2].pcv[8], 10); + + assign(test_msg_.apc[2].pcv[9], 56); + + assign(test_msg_.apc[2].pcv[10], 76); + + assign(test_msg_.apc[2].pcv[11], 61); + + assign(test_msg_.apc[2].pcv[12], -95); + + assign(test_msg_.apc[2].pcv[13], -40); + + assign(test_msg_.apc[2].pcv[14], 22); + + assign(test_msg_.apc[2].pcv[15], -75); + + assign(test_msg_.apc[2].pcv[16], -82); + + assign(test_msg_.apc[2].pcv[17], 33); + + assign(test_msg_.apc[2].pcv[18], 13); + + assign(test_msg_.apc[2].pcv[19], -4); + + assign(test_msg_.apc[2].pcv[20], -20); + assign(test_msg_.apc[2].sat_info, 181); + assign(test_msg_.apc[2].sid.code, 188); + assign(test_msg_.apc[2].sid.sat, 83); + assign(test_msg_.apc[2].svn, 7106); + + assign(test_msg_.apc[3].pco[0], -19478); + + assign(test_msg_.apc[3].pco[1], 11484); + + assign(test_msg_.apc[3].pco[2], 14804); + + assign(test_msg_.apc[3].pcv[0], 44); + + assign(test_msg_.apc[3].pcv[1], -83); + + assign(test_msg_.apc[3].pcv[2], 49); + + assign(test_msg_.apc[3].pcv[3], 36); + + assign(test_msg_.apc[3].pcv[4], -119); + + assign(test_msg_.apc[3].pcv[5], -8); + + assign(test_msg_.apc[3].pcv[6], -21); + + assign(test_msg_.apc[3].pcv[7], 97); + + assign(test_msg_.apc[3].pcv[8], 112); + + assign(test_msg_.apc[3].pcv[9], -99); + + assign(test_msg_.apc[3].pcv[10], -117); + + assign(test_msg_.apc[3].pcv[11], 26); + + assign(test_msg_.apc[3].pcv[12], 115); + + assign(test_msg_.apc[3].pcv[13], -64); + + assign(test_msg_.apc[3].pcv[14], 31); + + assign(test_msg_.apc[3].pcv[15], 85); + + assign(test_msg_.apc[3].pcv[16], 127); + + assign(test_msg_.apc[3].pcv[17], -28); + + assign(test_msg_.apc[3].pcv[18], 81); + + assign(test_msg_.apc[3].pcv[19], -4); + + assign(test_msg_.apc[3].pcv[20], -37); + assign(test_msg_.apc[3].sat_info, 128); + assign(test_msg_.apc[3].sid.code, 196); + assign(test_msg_.apc[3].sid.sat, 230); + assign(test_msg_.apc[3].svn, 61399); + + assign(test_msg_.apc[4].pco[0], -11049); + + assign(test_msg_.apc[4].pco[1], 6580); + + assign(test_msg_.apc[4].pco[2], -28589); + + assign(test_msg_.apc[4].pcv[0], -9); + + assign(test_msg_.apc[4].pcv[1], 12); + + assign(test_msg_.apc[4].pcv[2], 27); + + assign(test_msg_.apc[4].pcv[3], -57); + + assign(test_msg_.apc[4].pcv[4], -83); + + assign(test_msg_.apc[4].pcv[5], 74); + + assign(test_msg_.apc[4].pcv[6], 23); + + assign(test_msg_.apc[4].pcv[7], 4); + + assign(test_msg_.apc[4].pcv[8], -17); + + assign(test_msg_.apc[4].pcv[9], 103); + + assign(test_msg_.apc[4].pcv[10], -33); + + assign(test_msg_.apc[4].pcv[11], -36); + + assign(test_msg_.apc[4].pcv[12], -117); + + assign(test_msg_.apc[4].pcv[13], 91); + + assign(test_msg_.apc[4].pcv[14], 127); + + assign(test_msg_.apc[4].pcv[15], -42); + + assign(test_msg_.apc[4].pcv[16], 86); + + assign(test_msg_.apc[4].pcv[17], 48); + + assign(test_msg_.apc[4].pcv[18], -53); + + assign(test_msg_.apc[4].pcv[19], -28); + + assign(test_msg_.apc[4].pcv[20], 99); + assign(test_msg_.apc[4].sat_info, 147); + assign(test_msg_.apc[4].sid.code, 110); + assign(test_msg_.apc[4].sid.sat, 249); + assign(test_msg_.apc[4].svn, 41224); + + assign(test_msg_.apc[5].pco[0], -21881); + + assign(test_msg_.apc[5].pco[1], -9942); + + assign(test_msg_.apc[5].pco[2], -5689); + + assign(test_msg_.apc[5].pcv[0], 42); + + assign(test_msg_.apc[5].pcv[1], -86); + + assign(test_msg_.apc[5].pcv[2], 78); + + assign(test_msg_.apc[5].pcv[3], -50); + + assign(test_msg_.apc[5].pcv[4], 41); + + assign(test_msg_.apc[5].pcv[5], 43); + + assign(test_msg_.apc[5].pcv[6], 81); + + assign(test_msg_.apc[5].pcv[7], -9); + + assign(test_msg_.apc[5].pcv[8], 99); + + assign(test_msg_.apc[5].pcv[9], -58); + + assign(test_msg_.apc[5].pcv[10], -112); + + assign(test_msg_.apc[5].pcv[11], 2); + + assign(test_msg_.apc[5].pcv[12], -124); + + assign(test_msg_.apc[5].pcv[13], 2); + + assign(test_msg_.apc[5].pcv[14], -32); + + assign(test_msg_.apc[5].pcv[15], -36); + + assign(test_msg_.apc[5].pcv[16], -108); + + assign(test_msg_.apc[5].pcv[17], 58); + + assign(test_msg_.apc[5].pcv[18], 85); + + assign(test_msg_.apc[5].pcv[19], -118); + + assign(test_msg_.apc[5].pcv[20], -46); + assign(test_msg_.apc[5].sat_info, 159); + assign(test_msg_.apc[5].sid.code, 83); + assign(test_msg_.apc[5].sid.sat, 45); + assign(test_msg_.apc[5].svn, 64011); + + assign(test_msg_.apc[6].pco[0], -14290); + + assign(test_msg_.apc[6].pco[1], 30340); + + assign(test_msg_.apc[6].pco[2], 3569); + + assign(test_msg_.apc[6].pcv[0], 37); + + assign(test_msg_.apc[6].pcv[1], 62); + + assign(test_msg_.apc[6].pcv[2], 107); + + assign(test_msg_.apc[6].pcv[3], -3); + + assign(test_msg_.apc[6].pcv[4], -66); + + assign(test_msg_.apc[6].pcv[5], -120); + + assign(test_msg_.apc[6].pcv[6], 66); + + assign(test_msg_.apc[6].pcv[7], 9); + + assign(test_msg_.apc[6].pcv[8], 84); + + assign(test_msg_.apc[6].pcv[9], -101); + + assign(test_msg_.apc[6].pcv[10], 86); + + assign(test_msg_.apc[6].pcv[11], -76); + + assign(test_msg_.apc[6].pcv[12], 41); + + assign(test_msg_.apc[6].pcv[13], -60); + + assign(test_msg_.apc[6].pcv[14], 40); + + assign(test_msg_.apc[6].pcv[15], 119); + + assign(test_msg_.apc[6].pcv[16], 101); + + assign(test_msg_.apc[6].pcv[17], -4); + + assign(test_msg_.apc[6].pcv[18], -33); + + assign(test_msg_.apc[6].pcv[19], -112); + + assign(test_msg_.apc[6].pcv[20], -103); + assign(test_msg_.apc[6].sat_info, 7); + assign(test_msg_.apc[6].sid.code, 158); + assign(test_msg_.apc[6].sid.sat, 200); + assign(test_msg_.apc[6].svn, 17310); + assign(test_msg_.n_apc, 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_satellite_apc_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_satellite_apc_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrSatelliteApcDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_satellite_apc_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrSatelliteApcDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_satellite_apc_dep, + sizeof(msg->ssr_satellite_apc_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_satellite_apc_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_satellite_apc_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrSatelliteApcDep); + info.sender_id = 4920; + info.preamble = 0x55; + info.crc = 0x0d32; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 224; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_satellite_apc_dep_t &lesser, + const sbp_msg_ssr_satellite_apc_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_satellite_apc_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_satellite_apc_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrSatelliteApcDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrSatelliteApcDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrSatelliteApcDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrSatelliteApcDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_satellite_apc_dep_t test_msg_{}; + uint8_t encoded_frame_[224 + 8] = { + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, 214, + 212, 4, 8, 33, 31, 80, 21, 4, 105, 225, 39, 139, 124, 149, 48, + 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, 49, 135, 97, 39, 90, + 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, 2, 102, 74, 149, + 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, 83, 188, 181, 194, 27, + 84, 226, 142, 123, 77, 217, 248, 67, 215, 129, 114, 138, 25, 240, 10, + 56, 76, 61, 161, 216, 22, 181, 174, 33, 13, 252, 236, 230, 196, 128, + 215, 239, 234, 179, 220, 44, 212, 57, 44, 173, 49, 36, 137, 248, 235, + 97, 112, 157, 139, 26, 115, 192, 31, 85, 127, 228, 81, 252, 219, 249, + 110, 147, 8, 161, 215, 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, + 74, 23, 4, 239, 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, + 99, 45, 83, 159, 11, 250, 135, 170, 42, 217, 199, 233, 42, 170, 78, + 206, 41, 43, 81, 247, 99, 198, 144, 2, 132, 2, 224, 220, 148, 58, + 85, 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, 37, + 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, 119, + 101, 252, 223, 144, 153, 50, 13, + }; + uint8_t encoded_payload_[224] = { + 203, 169, 240, 78, 4, 213, 171, 254, 214, 212, 4, 8, 33, 31, 80, + 21, 4, 105, 225, 39, 139, 124, 149, 48, 15, 214, 197, 141, 32, 33, + 135, 150, 148, 123, 49, 135, 97, 39, 90, 20, 169, 239, 47, 153, 175, + 35, 145, 145, 123, 194, 2, 102, 74, 149, 95, 171, 238, 249, 7, 237, + 170, 125, 106, 158, 83, 188, 181, 194, 27, 84, 226, 142, 123, 77, 217, + 248, 67, 215, 129, 114, 138, 25, 240, 10, 56, 76, 61, 161, 216, 22, + 181, 174, 33, 13, 252, 236, 230, 196, 128, 215, 239, 234, 179, 220, 44, + 212, 57, 44, 173, 49, 36, 137, 248, 235, 97, 112, 157, 139, 26, 115, + 192, 31, 85, 127, 228, 81, 252, 219, 249, 110, 147, 8, 161, 215, 212, + 180, 25, 83, 144, 247, 12, 27, 199, 173, 74, 23, 4, 239, 103, 223, + 220, 139, 91, 127, 214, 86, 48, 203, 228, 99, 45, 83, 159, 11, 250, + 135, 170, 42, 217, 199, 233, 42, 170, 78, 206, 41, 43, 81, 247, 99, + 198, 144, 2, 132, 2, 224, 220, 148, 58, 85, 138, 210, 200, 158, 7, + 158, 67, 46, 200, 132, 118, 241, 13, 37, 62, 107, 253, 190, 136, 66, + 9, 84, 155, 86, 180, 41, 196, 40, 119, 101, 252, 223, 144, 153, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrSatelliteApcDep, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[224]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 224); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 224), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrSatelliteApcDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 224); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 224), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[224]; + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 224), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[224]; + + for (uint8_t i = 0; i < 224; i++) { + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 224); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrSatelliteApcDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 224); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_dep_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_satellite_apc_dep_t t{}; + return sbp_msg_ssr_satellite_apc_dep_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_satellite_apc_dep_t t{}; + t.n_apc = 1; + return sbp_msg_ssr_satellite_apc_dep_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_satellite_apc_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrSatelliteApcDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrSatelliteApcDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrSatelliteApcDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[0], greater.apc[0].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[1], greater.apc[0].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pco[2], greater.apc[0].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[0], greater.apc[0].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[1], greater.apc[0].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[2], greater.apc[0].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[3], greater.apc[0].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[4], greater.apc[0].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[5], greater.apc[0].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[6], greater.apc[0].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[7], greater.apc[0].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[8], greater.apc[0].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[9], greater.apc[0].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[10], greater.apc[0].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[11], greater.apc[0].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[12], greater.apc[0].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[13], greater.apc[0].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[14], greater.apc[0].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[15], greater.apc[0].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[16], greater.apc[0].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[17], greater.apc[0].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[18], greater.apc[0].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[19], greater.apc[0].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].pcv[20], greater.apc[0].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sat_info, greater.apc[0].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sid.code, greater.apc[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].sid.sat, greater.apc[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[0].svn, greater.apc[0].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pco[0], greater.apc[1].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pco[1], greater.apc[1].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pco[2], greater.apc[1].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[0], greater.apc[1].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[1], greater.apc[1].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[2], greater.apc[1].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[3], greater.apc[1].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[4], greater.apc[1].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[5], greater.apc[1].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[6], greater.apc[1].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[7], greater.apc[1].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[8], greater.apc[1].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[9], greater.apc[1].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[10], greater.apc[1].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[11], greater.apc[1].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[12], greater.apc[1].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[13], greater.apc[1].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[14], greater.apc[1].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[15], greater.apc[1].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[16], greater.apc[1].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[17], greater.apc[1].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[18], greater.apc[1].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[19], greater.apc[1].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].pcv[20], greater.apc[1].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].sat_info, greater.apc[1].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].sid.code, greater.apc[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].sid.sat, greater.apc[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[1].svn, greater.apc[1].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pco[0], greater.apc[2].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pco[1], greater.apc[2].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pco[2], greater.apc[2].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[0], greater.apc[2].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[1], greater.apc[2].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[2], greater.apc[2].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[3], greater.apc[2].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[4], greater.apc[2].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[5], greater.apc[2].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[6], greater.apc[2].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[7], greater.apc[2].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[8], greater.apc[2].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[9], greater.apc[2].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[10], greater.apc[2].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[11], greater.apc[2].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[12], greater.apc[2].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[13], greater.apc[2].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[14], greater.apc[2].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[15], greater.apc[2].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[16], greater.apc[2].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[17], greater.apc[2].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[18], greater.apc[2].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[19], greater.apc[2].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].pcv[20], greater.apc[2].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].sat_info, greater.apc[2].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].sid.code, greater.apc[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].sid.sat, greater.apc[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[2].svn, greater.apc[2].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pco[0], greater.apc[3].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pco[1], greater.apc[3].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pco[2], greater.apc[3].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[0], greater.apc[3].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[1], greater.apc[3].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[2], greater.apc[3].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[3], greater.apc[3].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[4], greater.apc[3].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[5], greater.apc[3].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[6], greater.apc[3].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[7], greater.apc[3].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[8], greater.apc[3].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[9], greater.apc[3].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[10], greater.apc[3].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[11], greater.apc[3].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[12], greater.apc[3].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[13], greater.apc[3].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[14], greater.apc[3].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[15], greater.apc[3].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[16], greater.apc[3].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[17], greater.apc[3].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[18], greater.apc[3].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[19], greater.apc[3].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].pcv[20], greater.apc[3].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].sat_info, greater.apc[3].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].sid.code, greater.apc[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].sid.sat, greater.apc[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[3].svn, greater.apc[3].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pco[0], greater.apc[4].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pco[1], greater.apc[4].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pco[2], greater.apc[4].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[0], greater.apc[4].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[1], greater.apc[4].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[2], greater.apc[4].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[3], greater.apc[4].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[4], greater.apc[4].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[5], greater.apc[4].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[6], greater.apc[4].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[7], greater.apc[4].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[8], greater.apc[4].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[9], greater.apc[4].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[10], greater.apc[4].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[11], greater.apc[4].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[12], greater.apc[4].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[13], greater.apc[4].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[14], greater.apc[4].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[15], greater.apc[4].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[16], greater.apc[4].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[17], greater.apc[4].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[18], greater.apc[4].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[19], greater.apc[4].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].pcv[20], greater.apc[4].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].sat_info, greater.apc[4].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].sid.code, greater.apc[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].sid.sat, greater.apc[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[4].svn, greater.apc[4].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pco[0], greater.apc[5].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pco[1], greater.apc[5].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pco[2], greater.apc[5].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[0], greater.apc[5].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[1], greater.apc[5].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[2], greater.apc[5].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[3], greater.apc[5].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[4], greater.apc[5].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[5], greater.apc[5].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[6], greater.apc[5].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[7], greater.apc[5].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[8], greater.apc[5].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[9], greater.apc[5].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[10], greater.apc[5].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[11], greater.apc[5].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[12], greater.apc[5].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[13], greater.apc[5].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[14], greater.apc[5].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[15], greater.apc[5].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[16], greater.apc[5].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[17], greater.apc[5].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[18], greater.apc[5].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[19], greater.apc[5].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].pcv[20], greater.apc[5].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].sat_info, greater.apc[5].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].sid.code, greater.apc[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].sid.sat, greater.apc[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[5].svn, greater.apc[5].svn); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pco[0], greater.apc[6].pco[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pco[1], greater.apc[6].pco[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pco[2], greater.apc[6].pco[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[0], greater.apc[6].pcv[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[1], greater.apc[6].pcv[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[2], greater.apc[6].pcv[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[3], greater.apc[6].pcv[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[4], greater.apc[6].pcv[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[5], greater.apc[6].pcv[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[6], greater.apc[6].pcv[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[7], greater.apc[6].pcv[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[8], greater.apc[6].pcv[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[9], greater.apc[6].pcv[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[10], greater.apc[6].pcv[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[11], greater.apc[6].pcv[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[12], greater.apc[6].pcv[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[13], greater.apc[6].pcv[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[14], greater.apc[6].pcv[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[15], greater.apc[6].pcv[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[16], greater.apc[6].pcv[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[17], greater.apc[6].pcv[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[18], greater.apc[6].pcv[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[19], greater.apc[6].pcv[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].pcv[20], greater.apc[6].pcv[20]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].sat_info, greater.apc[6].sat_info); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].sid.code, greater.apc[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].sid.sat, greater.apc[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.apc[6].svn, greater.apc[6].svn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_satellite_apc_dep_t lesser = info.test_msg; + sbp_msg_ssr_satellite_apc_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_apc, greater.n_apc); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrSatelliteApcDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_SATELLITE_APC_DEP"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_satellite_apc_dep_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_satellite_apc_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_satellite_apc_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_satellite_apc_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[224]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 224); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 224), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_satellite_apc_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 224); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrSatelliteApcDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrSatelliteApcDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrection.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrection.cc index 70a61b2b86..8bb1a13b4a 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrection.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrection.cc @@ -16,202 +16,979 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrStecCorrection0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrStecCorrection0 : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrStecCorrection0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrStecCorrection0() { + assign(test_msg_.header.num_msgs, 1); + assign(test_msg_.header.seq_num, 1); + assign(test_msg_.header.sol_id, 0); + assign(test_msg_.header.time.tow, 180); + assign(test_msg_.header.time.wn, 3); + assign(test_msg_.header.update_interval, 10); + assign(test_msg_.n_sats, 2); + assign(test_msg_.ssr_iod_atmo, 15); + + assign(test_msg_.stec_sat_list[0].stec_coeff[0], 63); + + assign(test_msg_.stec_sat_list[0].stec_coeff[1], 62); + + assign(test_msg_.stec_sat_list[0].stec_coeff[2], 61); + + assign(test_msg_.stec_sat_list[0].stec_coeff[3], 60); + assign(test_msg_.stec_sat_list[0].stec_quality_indicator, 1); + assign(test_msg_.stec_sat_list[0].sv_id.constellation, 1); + assign(test_msg_.stec_sat_list[0].sv_id.satId, 1); + + assign(test_msg_.stec_sat_list[1].stec_coeff[0], 63); + + assign(test_msg_.stec_sat_list[1].stec_coeff[1], 64); + + assign(test_msg_.stec_sat_list[1].stec_coeff[2], 65); + + assign(test_msg_.stec_sat_list[1].stec_coeff[3], 66); + assign(test_msg_.stec_sat_list[1].stec_quality_indicator, 5); + assign(test_msg_.stec_sat_list[1].sv_id.constellation, 15); + assign(test_msg_.stec_sat_list[1].sv_id.satId, 31); + assign(test_msg_.tile_id, 10); + assign(test_msg_.tile_set_id, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_stec_correction_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrStecCorrection, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrStecCorrection); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_stec_correction, + sizeof(msg->ssr_stec_correction)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_stec_correction_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_stec_correction, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrStecCorrection); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x3277; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 38; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_stec_correction_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_stec_correction_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_stec_correction_t &lesser, + const sbp_msg_ssr_stec_correction_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_stec_correction_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_stec_correction_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_stec_correction_cmp(&greater, &lesser), 0); -TEST_F(Test_auto_check_sbp_ssr_MsgSsrStecCorrection0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrection, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrection, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrStecCorrection, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrStecCorrection, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_stec_correction_t test_msg_{}; + uint8_t encoded_frame_[38 + 8] = { 85, 253, 5, 66, 0, 38, 180, 0, 0, 0, 3, 0, 1, 1, 10, 0, 15, 1, 0, 10, 0, 2, 1, 1, 1, 63, 0, 62, 0, 61, 0, 60, 0, 31, 15, 5, 63, 0, 64, 0, 65, 0, 66, 0, 119, 50, }; + uint8_t encoded_payload_[38] = { + 180, 0, 0, 0, 3, 0, 1, 1, 10, 0, 15, 1, 0, 10, 0, 2, 1, 1, 1, + 63, 0, 62, 0, 61, 0, 60, 0, 31, 15, 5, 63, 0, 64, 0, 65, 0, 66, 0, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_stec_correction_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrStecCorrection, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[38]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 38); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 38), 0); - sbp_msg_ssr_stec_correction_t test_msg{}; - test_msg.header.num_msgs = 1; - test_msg.header.seq_num = 1; - test_msg.header.sol_id = 0; - test_msg.header.time.tow = 180; - test_msg.header.time.wn = 3; - test_msg.header.update_interval = 10; - test_msg.n_sats = 2; - test_msg.ssr_iod_atmo = 15; - - test_msg.stec_sat_list[0].stec_coeff[0] = 63; - - test_msg.stec_sat_list[0].stec_coeff[1] = 62; - - test_msg.stec_sat_list[0].stec_coeff[2] = 61; - - test_msg.stec_sat_list[0].stec_coeff[3] = 60; - test_msg.stec_sat_list[0].stec_quality_indicator = 1; - test_msg.stec_sat_list[0].sv_id.constellation = 1; - test_msg.stec_sat_list[0].sv_id.satId = 1; - - test_msg.stec_sat_list[1].stec_coeff[0] = 63; - - test_msg.stec_sat_list[1].stec_coeff[1] = 64; - - test_msg.stec_sat_list[1].stec_coeff[2] = 65; - - test_msg.stec_sat_list[1].stec_coeff[3] = 66; - test_msg.stec_sat_list[1].stec_quality_indicator = 5; - test_msg.stec_sat_list[1].sv_id.constellation = 15; - test_msg.stec_sat_list[1].sv_id.satId = 31; - test_msg.tile_id = 10; - test_msg.tile_set_id = 1; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.header.num_msgs, 1) - << "incorrect value for last_msg_.header.num_msgs, expected 1, is " - << last_msg_.header.num_msgs; - EXPECT_EQ(last_msg_.header.seq_num, 1) - << "incorrect value for last_msg_.header.seq_num, expected 1, is " - << last_msg_.header.seq_num; - EXPECT_EQ(last_msg_.header.sol_id, 0) - << "incorrect value for last_msg_.header.sol_id, expected 0, is " - << last_msg_.header.sol_id; - EXPECT_EQ(last_msg_.header.time.tow, 180) - << "incorrect value for last_msg_.header.time.tow, expected 180, is " - << last_msg_.header.time.tow; - EXPECT_EQ(last_msg_.header.time.wn, 3) - << "incorrect value for last_msg_.header.time.wn, expected 3, is " - << last_msg_.header.time.wn; - EXPECT_EQ(last_msg_.header.update_interval, 10) - << "incorrect value for last_msg_.header.update_interval, expected 10, " - "is " - << last_msg_.header.update_interval; - EXPECT_EQ(last_msg_.n_sats, 2) - << "incorrect value for last_msg_.n_sats, expected 2, is " - << last_msg_.n_sats; - EXPECT_EQ(last_msg_.ssr_iod_atmo, 15) - << "incorrect value for last_msg_.ssr_iod_atmo, expected 15, is " - << last_msg_.ssr_iod_atmo; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_coeff[0], 63) - << "incorrect value for last_msg_.stec_sat_list[0].stec_coeff[0], " - "expected 63, is " - << last_msg_.stec_sat_list[0].stec_coeff[0]; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_coeff[1], 62) - << "incorrect value for last_msg_.stec_sat_list[0].stec_coeff[1], " - "expected 62, is " - << last_msg_.stec_sat_list[0].stec_coeff[1]; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_coeff[2], 61) - << "incorrect value for last_msg_.stec_sat_list[0].stec_coeff[2], " - "expected 61, is " - << last_msg_.stec_sat_list[0].stec_coeff[2]; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_coeff[3], 60) - << "incorrect value for last_msg_.stec_sat_list[0].stec_coeff[3], " - "expected 60, is " - << last_msg_.stec_sat_list[0].stec_coeff[3]; - EXPECT_EQ(last_msg_.stec_sat_list[0].stec_quality_indicator, 1) - << "incorrect value for " - "last_msg_.stec_sat_list[0].stec_quality_indicator, expected 1, is " - << last_msg_.stec_sat_list[0].stec_quality_indicator; - EXPECT_EQ(last_msg_.stec_sat_list[0].sv_id.constellation, 1) - << "incorrect value for last_msg_.stec_sat_list[0].sv_id.constellation, " - "expected 1, is " - << last_msg_.stec_sat_list[0].sv_id.constellation; - EXPECT_EQ(last_msg_.stec_sat_list[0].sv_id.satId, 1) - << "incorrect value for last_msg_.stec_sat_list[0].sv_id.satId, expected " - "1, is " - << last_msg_.stec_sat_list[0].sv_id.satId; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_coeff[0], 63) - << "incorrect value for last_msg_.stec_sat_list[1].stec_coeff[0], " - "expected 63, is " - << last_msg_.stec_sat_list[1].stec_coeff[0]; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_coeff[1], 64) - << "incorrect value for last_msg_.stec_sat_list[1].stec_coeff[1], " - "expected 64, is " - << last_msg_.stec_sat_list[1].stec_coeff[1]; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_coeff[2], 65) - << "incorrect value for last_msg_.stec_sat_list[1].stec_coeff[2], " - "expected 65, is " - << last_msg_.stec_sat_list[1].stec_coeff[2]; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_coeff[3], 66) - << "incorrect value for last_msg_.stec_sat_list[1].stec_coeff[3], " - "expected 66, is " - << last_msg_.stec_sat_list[1].stec_coeff[3]; - EXPECT_EQ(last_msg_.stec_sat_list[1].stec_quality_indicator, 5) - << "incorrect value for " - "last_msg_.stec_sat_list[1].stec_quality_indicator, expected 5, is " - << last_msg_.stec_sat_list[1].stec_quality_indicator; - EXPECT_EQ(last_msg_.stec_sat_list[1].sv_id.constellation, 15) - << "incorrect value for last_msg_.stec_sat_list[1].sv_id.constellation, " - "expected 15, is " - << last_msg_.stec_sat_list[1].sv_id.constellation; - EXPECT_EQ(last_msg_.stec_sat_list[1].sv_id.satId, 31) - << "incorrect value for last_msg_.stec_sat_list[1].sv_id.satId, expected " - "31, is " - << last_msg_.stec_sat_list[1].sv_id.satId; - EXPECT_EQ(last_msg_.tile_id, 10) - << "incorrect value for last_msg_.tile_id, expected 10, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 1) - << "incorrect value for last_msg_.tile_set_id, expected 1, is " - << last_msg_.tile_set_id; + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrStecCorrection, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 38); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 38), 0); } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[38]; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 38), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[38]; + + for (uint8_t i = 0; i < 38; i++) { + EXPECT_EQ( + sbp_msg_ssr_stec_correction_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 38); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrStecCorrection, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 38); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_stec_correction_t t{}; + return sbp_msg_ssr_stec_correction_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_stec_correction_t t{}; + t.n_sats = 1; + return sbp_msg_ssr_stec_correction_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_stec_correction_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrStecCorrection, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrStecCorrection, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrStecCorrection, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.sol_id, greater.header.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.n_sats, greater.n_sats); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_iod_atmo, greater.ssr_iod_atmo); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[0], + greater.stec_sat_list[0].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[1], + greater.stec_sat_list[0].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[2], + greater.stec_sat_list[0].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[3], + greater.stec_sat_list[0].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_quality_indicator, + greater.stec_sat_list[0].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.constellation, + greater.stec_sat_list[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.satId, + greater.stec_sat_list[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[0], + greater.stec_sat_list[1].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[1], + greater.stec_sat_list[1].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[2], + greater.stec_sat_list[1].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[3], + greater.stec_sat_list[1].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_quality_indicator, + greater.stec_sat_list[1].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.constellation, + greater.stec_sat_list[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.satId, + greater.stec_sat_list[1].sv_id.satId); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrStecCorrection); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_STEC_CORRECTION"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_stec_correction_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_stec_correction_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_stec_correction, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_stec_correction, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[38]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 38); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 38), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 38); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrStecCorrection, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrection0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrStecCorrection, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc new file mode 100644 index 0000000000..ceedc05dbb --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc @@ -0,0 +1,2242 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0 : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0() { + assign(test_msg_.header.iod_atmo, 60); + assign(test_msg_.header.num_msgs, 157); + assign(test_msg_.header.seq_num, 112); + assign(test_msg_.header.tile_id, 30066); + assign(test_msg_.header.tile_set_id, 58526); + assign(test_msg_.header.time.tow, 714907186); + assign(test_msg_.header.time.wn, 40055); + assign(test_msg_.header.update_interval, 47); + assign(test_msg_.n_stec_sat_list, 21); + + assign(test_msg_.stec_sat_list[0].stec_coeff[0], -5289); + + assign(test_msg_.stec_sat_list[0].stec_coeff[1], -20141); + + assign(test_msg_.stec_sat_list[0].stec_coeff[2], 966); + + assign(test_msg_.stec_sat_list[0].stec_coeff[3], 2062); + assign(test_msg_.stec_sat_list[0].stec_quality_indicator, 70); + assign(test_msg_.stec_sat_list[0].sv_id.constellation, 40); + assign(test_msg_.stec_sat_list[0].sv_id.satId, 132); + + assign(test_msg_.stec_sat_list[1].stec_coeff[0], -19147); + + assign(test_msg_.stec_sat_list[1].stec_coeff[1], -20902); + + assign(test_msg_.stec_sat_list[1].stec_coeff[2], -26889); + + assign(test_msg_.stec_sat_list[1].stec_coeff[3], -21446); + assign(test_msg_.stec_sat_list[1].stec_quality_indicator, 44); + assign(test_msg_.stec_sat_list[1].sv_id.constellation, 12); + assign(test_msg_.stec_sat_list[1].sv_id.satId, 70); + + assign(test_msg_.stec_sat_list[2].stec_coeff[0], 32176); + + assign(test_msg_.stec_sat_list[2].stec_coeff[1], -20220); + + assign(test_msg_.stec_sat_list[2].stec_coeff[2], 29157); + + assign(test_msg_.stec_sat_list[2].stec_coeff[3], 19726); + assign(test_msg_.stec_sat_list[2].stec_quality_indicator, 119); + assign(test_msg_.stec_sat_list[2].sv_id.constellation, 179); + assign(test_msg_.stec_sat_list[2].sv_id.satId, 247); + + assign(test_msg_.stec_sat_list[3].stec_coeff[0], -8651); + + assign(test_msg_.stec_sat_list[3].stec_coeff[1], -27973); + + assign(test_msg_.stec_sat_list[3].stec_coeff[2], 23546); + + assign(test_msg_.stec_sat_list[3].stec_coeff[3], -10284); + assign(test_msg_.stec_sat_list[3].stec_quality_indicator, 23); + assign(test_msg_.stec_sat_list[3].sv_id.constellation, 185); + assign(test_msg_.stec_sat_list[3].sv_id.satId, 153); + + assign(test_msg_.stec_sat_list[4].stec_coeff[0], 27486); + + assign(test_msg_.stec_sat_list[4].stec_coeff[1], 23329); + + assign(test_msg_.stec_sat_list[4].stec_coeff[2], 234); + + assign(test_msg_.stec_sat_list[4].stec_coeff[3], -29739); + assign(test_msg_.stec_sat_list[4].stec_quality_indicator, 250); + assign(test_msg_.stec_sat_list[4].sv_id.constellation, 107); + assign(test_msg_.stec_sat_list[4].sv_id.satId, 14); + + assign(test_msg_.stec_sat_list[5].stec_coeff[0], 18965); + + assign(test_msg_.stec_sat_list[5].stec_coeff[1], -22098); + + assign(test_msg_.stec_sat_list[5].stec_coeff[2], 22077); + + assign(test_msg_.stec_sat_list[5].stec_coeff[3], -29093); + assign(test_msg_.stec_sat_list[5].stec_quality_indicator, 50); + assign(test_msg_.stec_sat_list[5].sv_id.constellation, 179); + assign(test_msg_.stec_sat_list[5].sv_id.satId, 95); + + assign(test_msg_.stec_sat_list[6].stec_coeff[0], -7898); + + assign(test_msg_.stec_sat_list[6].stec_coeff[1], 26002); + + assign(test_msg_.stec_sat_list[6].stec_coeff[2], -29879); + + assign(test_msg_.stec_sat_list[6].stec_coeff[3], 30008); + assign(test_msg_.stec_sat_list[6].stec_quality_indicator, 9); + assign(test_msg_.stec_sat_list[6].sv_id.constellation, 108); + assign(test_msg_.stec_sat_list[6].sv_id.satId, 51); + + assign(test_msg_.stec_sat_list[7].stec_coeff[0], -12948); + + assign(test_msg_.stec_sat_list[7].stec_coeff[1], 4701); + + assign(test_msg_.stec_sat_list[7].stec_coeff[2], -15597); + + assign(test_msg_.stec_sat_list[7].stec_coeff[3], -13791); + assign(test_msg_.stec_sat_list[7].stec_quality_indicator, 213); + assign(test_msg_.stec_sat_list[7].sv_id.constellation, 37); + assign(test_msg_.stec_sat_list[7].sv_id.satId, 82); + + assign(test_msg_.stec_sat_list[8].stec_coeff[0], -17283); + + assign(test_msg_.stec_sat_list[8].stec_coeff[1], 14455); + + assign(test_msg_.stec_sat_list[8].stec_coeff[2], -27067); + + assign(test_msg_.stec_sat_list[8].stec_coeff[3], 19606); + assign(test_msg_.stec_sat_list[8].stec_quality_indicator, 178); + assign(test_msg_.stec_sat_list[8].sv_id.constellation, 206); + assign(test_msg_.stec_sat_list[8].sv_id.satId, 87); + + assign(test_msg_.stec_sat_list[9].stec_coeff[0], -12215); + + assign(test_msg_.stec_sat_list[9].stec_coeff[1], -6072); + + assign(test_msg_.stec_sat_list[9].stec_coeff[2], -1528); + + assign(test_msg_.stec_sat_list[9].stec_coeff[3], -19765); + assign(test_msg_.stec_sat_list[9].stec_quality_indicator, 18); + assign(test_msg_.stec_sat_list[9].sv_id.constellation, 131); + assign(test_msg_.stec_sat_list[9].sv_id.satId, 3); + + assign(test_msg_.stec_sat_list[10].stec_coeff[0], 12630); + + assign(test_msg_.stec_sat_list[10].stec_coeff[1], -19721); + + assign(test_msg_.stec_sat_list[10].stec_coeff[2], 14502); + + assign(test_msg_.stec_sat_list[10].stec_coeff[3], 2591); + assign(test_msg_.stec_sat_list[10].stec_quality_indicator, 252); + assign(test_msg_.stec_sat_list[10].sv_id.constellation, 163); + assign(test_msg_.stec_sat_list[10].sv_id.satId, 170); + + assign(test_msg_.stec_sat_list[11].stec_coeff[0], -23340); + + assign(test_msg_.stec_sat_list[11].stec_coeff[1], -24063); + + assign(test_msg_.stec_sat_list[11].stec_coeff[2], 4650); + + assign(test_msg_.stec_sat_list[11].stec_coeff[3], -22148); + assign(test_msg_.stec_sat_list[11].stec_quality_indicator, 241); + assign(test_msg_.stec_sat_list[11].sv_id.constellation, 213); + assign(test_msg_.stec_sat_list[11].sv_id.satId, 119); + + assign(test_msg_.stec_sat_list[12].stec_coeff[0], 5944); + + assign(test_msg_.stec_sat_list[12].stec_coeff[1], 32142); + + assign(test_msg_.stec_sat_list[12].stec_coeff[2], 30760); + + assign(test_msg_.stec_sat_list[12].stec_coeff[3], 11587); + assign(test_msg_.stec_sat_list[12].stec_quality_indicator, 26); + assign(test_msg_.stec_sat_list[12].sv_id.constellation, 158); + assign(test_msg_.stec_sat_list[12].sv_id.satId, 121); + + assign(test_msg_.stec_sat_list[13].stec_coeff[0], 3095); + + assign(test_msg_.stec_sat_list[13].stec_coeff[1], 22769); + + assign(test_msg_.stec_sat_list[13].stec_coeff[2], -4283); + + assign(test_msg_.stec_sat_list[13].stec_coeff[3], 14844); + assign(test_msg_.stec_sat_list[13].stec_quality_indicator, 110); + assign(test_msg_.stec_sat_list[13].sv_id.constellation, 235); + assign(test_msg_.stec_sat_list[13].sv_id.satId, 126); + + assign(test_msg_.stec_sat_list[14].stec_coeff[0], -21032); + + assign(test_msg_.stec_sat_list[14].stec_coeff[1], -19726); + + assign(test_msg_.stec_sat_list[14].stec_coeff[2], 1297); + + assign(test_msg_.stec_sat_list[14].stec_coeff[3], -22049); + assign(test_msg_.stec_sat_list[14].stec_quality_indicator, 201); + assign(test_msg_.stec_sat_list[14].sv_id.constellation, 44); + assign(test_msg_.stec_sat_list[14].sv_id.satId, 93); + + assign(test_msg_.stec_sat_list[15].stec_coeff[0], 619); + + assign(test_msg_.stec_sat_list[15].stec_coeff[1], -5744); + + assign(test_msg_.stec_sat_list[15].stec_coeff[2], 22542); + + assign(test_msg_.stec_sat_list[15].stec_coeff[3], -12000); + assign(test_msg_.stec_sat_list[15].stec_quality_indicator, 77); + assign(test_msg_.stec_sat_list[15].sv_id.constellation, 3); + assign(test_msg_.stec_sat_list[15].sv_id.satId, 192); + + assign(test_msg_.stec_sat_list[16].stec_coeff[0], 10651); + + assign(test_msg_.stec_sat_list[16].stec_coeff[1], -2889); + + assign(test_msg_.stec_sat_list[16].stec_coeff[2], 21150); + + assign(test_msg_.stec_sat_list[16].stec_coeff[3], 26421); + assign(test_msg_.stec_sat_list[16].stec_quality_indicator, 123); + assign(test_msg_.stec_sat_list[16].sv_id.constellation, 17); + assign(test_msg_.stec_sat_list[16].sv_id.satId, 1); + + assign(test_msg_.stec_sat_list[17].stec_coeff[0], -19165); + + assign(test_msg_.stec_sat_list[17].stec_coeff[1], 30229); + + assign(test_msg_.stec_sat_list[17].stec_coeff[2], -1282); + + assign(test_msg_.stec_sat_list[17].stec_coeff[3], -18382); + assign(test_msg_.stec_sat_list[17].stec_quality_indicator, 185); + assign(test_msg_.stec_sat_list[17].sv_id.constellation, 202); + assign(test_msg_.stec_sat_list[17].sv_id.satId, 14); + + assign(test_msg_.stec_sat_list[18].stec_coeff[0], -23752); + + assign(test_msg_.stec_sat_list[18].stec_coeff[1], 32433); + + assign(test_msg_.stec_sat_list[18].stec_coeff[2], 20441); + + assign(test_msg_.stec_sat_list[18].stec_coeff[3], -4181); + assign(test_msg_.stec_sat_list[18].stec_quality_indicator, 45); + assign(test_msg_.stec_sat_list[18].sv_id.constellation, 31); + assign(test_msg_.stec_sat_list[18].sv_id.satId, 50); + + assign(test_msg_.stec_sat_list[19].stec_coeff[0], -13968); + + assign(test_msg_.stec_sat_list[19].stec_coeff[1], -29322); + + assign(test_msg_.stec_sat_list[19].stec_coeff[2], -23790); + + assign(test_msg_.stec_sat_list[19].stec_coeff[3], 9063); + assign(test_msg_.stec_sat_list[19].stec_quality_indicator, 238); + assign(test_msg_.stec_sat_list[19].sv_id.constellation, 188); + assign(test_msg_.stec_sat_list[19].sv_id.satId, 237); + + assign(test_msg_.stec_sat_list[20].stec_coeff[0], 4737); + + assign(test_msg_.stec_sat_list[20].stec_coeff[1], 21877); + + assign(test_msg_.stec_sat_list[20].stec_coeff[2], 20414); + + assign(test_msg_.stec_sat_list[20].stec_coeff[3], -10286); + assign(test_msg_.stec_sat_list[20].stec_quality_indicator, 82); + assign(test_msg_.stec_sat_list[20].sv_id.constellation, 21); + assign(test_msg_.stec_sat_list[20].sv_id.satId, 63); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_stec_correction_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_stec_correction_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrStecCorrectionDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrStecCorrectionDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_stec_correction_dep, + sizeof(msg->ssr_stec_correction_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_stec_correction_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_stec_correction_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrStecCorrectionDep); + info.sender_id = 38860; + info.preamble = 0x55; + info.crc = 0xb1e3; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 245; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_stec_correction_dep_t &lesser, + const sbp_msg_ssr_stec_correction_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_stec_correction_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_stec_correction_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrectionDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrectionDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrStecCorrectionDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrStecCorrectionDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_stec_correction_dep_t test_msg_{}; + uint8_t encoded_frame_[245 + 8] = { + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, 119, + 156, 157, 112, 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, 3, 14, + 8, 70, 12, 44, 53, 181, 90, 174, 247, 150, 58, 172, 247, 179, 119, + 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, 53, 222, 187, 146, + 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, 91, 234, 0, 213, 139, + 95, 179, 50, 21, 74, 174, 169, 61, 86, 91, 142, 51, 108, 9, 38, + 225, 146, 101, 73, 139, 56, 117, 82, 37, 213, 108, 205, 93, 18, 19, + 195, 33, 202, 87, 206, 178, 125, 188, 119, 56, 69, 150, 150, 76, 3, + 131, 18, 73, 208, 72, 232, 8, 250, 203, 178, 170, 163, 252, 86, 49, + 247, 178, 166, 56, 31, 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, + 124, 169, 121, 158, 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, + 110, 23, 12, 241, 88, 69, 239, 252, 57, 93, 44, 201, 216, 173, 242, + 178, 17, 5, 223, 169, 192, 3, 77, 107, 2, 144, 233, 14, 88, 32, + 209, 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, 126, + 217, 79, 171, 239, 237, 188, 238, 112, 201, 118, 141, 18, 163, 103, 35, + 63, 21, 82, 129, 18, 117, 85, 190, 79, 210, 215, 227, 177, + }; + uint8_t encoded_payload_[245] = { + 158, 228, 114, 117, 50, 158, 156, 42, 119, 156, 157, 112, 47, 60, 132, + 40, 70, 87, 235, 83, 177, 198, 3, 14, 8, 70, 12, 44, 53, 181, + 90, 174, 247, 150, 58, 172, 247, 179, 119, 176, 125, 4, 177, 229, 113, + 14, 77, 153, 185, 23, 53, 222, 187, 146, 250, 91, 212, 215, 14, 107, + 250, 94, 107, 33, 91, 234, 0, 213, 139, 95, 179, 50, 21, 74, 174, + 169, 61, 86, 91, 142, 51, 108, 9, 38, 225, 146, 101, 73, 139, 56, + 117, 82, 37, 213, 108, 205, 93, 18, 19, 195, 33, 202, 87, 206, 178, + 125, 188, 119, 56, 69, 150, 150, 76, 3, 131, 18, 73, 208, 72, 232, + 8, 250, 203, 178, 170, 163, 252, 86, 49, 247, 178, 166, 56, 31, 10, + 119, 213, 241, 212, 164, 1, 162, 42, 18, 124, 169, 121, 158, 26, 56, + 23, 142, 125, 40, 120, 67, 45, 126, 235, 110, 23, 12, 241, 88, 69, + 239, 252, 57, 93, 44, 201, 216, 173, 242, 178, 17, 5, 223, 169, 192, + 3, 77, 107, 2, 144, 233, 14, 88, 32, 209, 1, 17, 123, 155, 41, + 183, 244, 158, 82, 53, 103, 14, 202, 185, 35, 181, 21, 118, 254, 250, + 50, 184, 50, 31, 45, 56, 163, 177, 126, 217, 79, 171, 239, 237, 188, + 238, 112, 201, 118, 141, 18, 163, 103, 35, 63, 21, 82, 129, 18, 117, + 85, 190, 79, 210, 215, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrStecCorrectionDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[245]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 245); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 245), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrStecCorrectionDep, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 245); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 245), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[245]; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 245), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[245]; + + for (uint8_t i = 0; i < 245; i++) { + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 245); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrStecCorrectionDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 245); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_stec_correction_dep_t t{}; + return sbp_msg_ssr_stec_correction_dep_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_stec_correction_dep_t t{}; + t.n_stec_sat_list = 1; + return sbp_msg_ssr_stec_correction_dep_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrStecCorrectionDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrStecCorrectionDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrStecCorrectionDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.iod_atmo, greater.header.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_id, greater.header.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.tile_set_id, greater.header.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.n_stec_sat_list, greater.n_stec_sat_list); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[0], + greater.stec_sat_list[0].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[1], + greater.stec_sat_list[0].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[2], + greater.stec_sat_list[0].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[3], + greater.stec_sat_list[0].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_quality_indicator, + greater.stec_sat_list[0].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.constellation, + greater.stec_sat_list[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.satId, + greater.stec_sat_list[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[0], + greater.stec_sat_list[1].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[1], + greater.stec_sat_list[1].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[2], + greater.stec_sat_list[1].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[3], + greater.stec_sat_list[1].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_quality_indicator, + greater.stec_sat_list[1].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.constellation, + greater.stec_sat_list[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.satId, + greater.stec_sat_list[1].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[0], + greater.stec_sat_list[2].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[1], + greater.stec_sat_list[2].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[2], + greater.stec_sat_list[2].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[3], + greater.stec_sat_list[2].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_quality_indicator, + greater.stec_sat_list[2].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].sv_id.constellation, + greater.stec_sat_list[2].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].sv_id.satId, + greater.stec_sat_list[2].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[0], + greater.stec_sat_list[3].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[1], + greater.stec_sat_list[3].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[2], + greater.stec_sat_list[3].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[3], + greater.stec_sat_list[3].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_quality_indicator, + greater.stec_sat_list[3].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].sv_id.constellation, + greater.stec_sat_list[3].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].sv_id.satId, + greater.stec_sat_list[3].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[0], + greater.stec_sat_list[4].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[1], + greater.stec_sat_list[4].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[2], + greater.stec_sat_list[4].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[3], + greater.stec_sat_list[4].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_quality_indicator, + greater.stec_sat_list[4].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].sv_id.constellation, + greater.stec_sat_list[4].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].sv_id.satId, + greater.stec_sat_list[4].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[0], + greater.stec_sat_list[5].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[1], + greater.stec_sat_list[5].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[2], + greater.stec_sat_list[5].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[3], + greater.stec_sat_list[5].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_quality_indicator, + greater.stec_sat_list[5].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].sv_id.constellation, + greater.stec_sat_list[5].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].sv_id.satId, + greater.stec_sat_list[5].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[0], + greater.stec_sat_list[6].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[1], + greater.stec_sat_list[6].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[2], + greater.stec_sat_list[6].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[3], + greater.stec_sat_list[6].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_quality_indicator, + greater.stec_sat_list[6].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].sv_id.constellation, + greater.stec_sat_list[6].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].sv_id.satId, + greater.stec_sat_list[6].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[0], + greater.stec_sat_list[7].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[1], + greater.stec_sat_list[7].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[2], + greater.stec_sat_list[7].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[3], + greater.stec_sat_list[7].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_quality_indicator, + greater.stec_sat_list[7].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].sv_id.constellation, + greater.stec_sat_list[7].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].sv_id.satId, + greater.stec_sat_list[7].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[0], + greater.stec_sat_list[8].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[1], + greater.stec_sat_list[8].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[2], + greater.stec_sat_list[8].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[3], + greater.stec_sat_list[8].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_quality_indicator, + greater.stec_sat_list[8].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].sv_id.constellation, + greater.stec_sat_list[8].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].sv_id.satId, + greater.stec_sat_list[8].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[0], + greater.stec_sat_list[9].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[1], + greater.stec_sat_list[9].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[2], + greater.stec_sat_list[9].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[3], + greater.stec_sat_list[9].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_quality_indicator, + greater.stec_sat_list[9].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].sv_id.constellation, + greater.stec_sat_list[9].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].sv_id.satId, + greater.stec_sat_list[9].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[0], + greater.stec_sat_list[10].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[1], + greater.stec_sat_list[10].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[2], + greater.stec_sat_list[10].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[3], + greater.stec_sat_list[10].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_quality_indicator, + greater.stec_sat_list[10].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].sv_id.constellation, + greater.stec_sat_list[10].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].sv_id.satId, + greater.stec_sat_list[10].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[0], + greater.stec_sat_list[11].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[1], + greater.stec_sat_list[11].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[2], + greater.stec_sat_list[11].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[3], + greater.stec_sat_list[11].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_quality_indicator, + greater.stec_sat_list[11].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].sv_id.constellation, + greater.stec_sat_list[11].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].sv_id.satId, + greater.stec_sat_list[11].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[0], + greater.stec_sat_list[12].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[1], + greater.stec_sat_list[12].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[2], + greater.stec_sat_list[12].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[3], + greater.stec_sat_list[12].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_quality_indicator, + greater.stec_sat_list[12].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].sv_id.constellation, + greater.stec_sat_list[12].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].sv_id.satId, + greater.stec_sat_list[12].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[0], + greater.stec_sat_list[13].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[1], + greater.stec_sat_list[13].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[2], + greater.stec_sat_list[13].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[3], + greater.stec_sat_list[13].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_quality_indicator, + greater.stec_sat_list[13].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].sv_id.constellation, + greater.stec_sat_list[13].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].sv_id.satId, + greater.stec_sat_list[13].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[0], + greater.stec_sat_list[14].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[1], + greater.stec_sat_list[14].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[2], + greater.stec_sat_list[14].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[3], + greater.stec_sat_list[14].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_quality_indicator, + greater.stec_sat_list[14].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].sv_id.constellation, + greater.stec_sat_list[14].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].sv_id.satId, + greater.stec_sat_list[14].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[0], + greater.stec_sat_list[15].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[1], + greater.stec_sat_list[15].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[2], + greater.stec_sat_list[15].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[3], + greater.stec_sat_list[15].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_quality_indicator, + greater.stec_sat_list[15].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].sv_id.constellation, + greater.stec_sat_list[15].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].sv_id.satId, + greater.stec_sat_list[15].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[0], + greater.stec_sat_list[16].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[1], + greater.stec_sat_list[16].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[2], + greater.stec_sat_list[16].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[3], + greater.stec_sat_list[16].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_quality_indicator, + greater.stec_sat_list[16].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].sv_id.constellation, + greater.stec_sat_list[16].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].sv_id.satId, + greater.stec_sat_list[16].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[0], + greater.stec_sat_list[17].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[1], + greater.stec_sat_list[17].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[2], + greater.stec_sat_list[17].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[3], + greater.stec_sat_list[17].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_quality_indicator, + greater.stec_sat_list[17].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].sv_id.constellation, + greater.stec_sat_list[17].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].sv_id.satId, + greater.stec_sat_list[17].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[0], + greater.stec_sat_list[18].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[1], + greater.stec_sat_list[18].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[2], + greater.stec_sat_list[18].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[3], + greater.stec_sat_list[18].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_quality_indicator, + greater.stec_sat_list[18].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].sv_id.constellation, + greater.stec_sat_list[18].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].sv_id.satId, + greater.stec_sat_list[18].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[0], + greater.stec_sat_list[19].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[1], + greater.stec_sat_list[19].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[2], + greater.stec_sat_list[19].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[3], + greater.stec_sat_list[19].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_quality_indicator, + greater.stec_sat_list[19].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].sv_id.constellation, + greater.stec_sat_list[19].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].sv_id.satId, + greater.stec_sat_list[19].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[0], + greater.stec_sat_list[20].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[1], + greater.stec_sat_list[20].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[2], + greater.stec_sat_list[20].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[3], + greater.stec_sat_list[20].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_quality_indicator, + greater.stec_sat_list[20].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].sv_id.constellation, + greater.stec_sat_list[20].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].sv_id.satId, + greater.stec_sat_list[20].sv_id.satId); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrStecCorrectionDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_STEC_CORRECTION_DEP"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_stec_correction_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_stec_correction_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_stec_correction_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_stec_correction_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[245]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 245); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 245), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 245); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrStecCorrectionDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrStecCorrectionDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc new file mode 100644 index 0000000000..3e9a645428 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc @@ -0,0 +1,2299 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0() { + assign(test_msg_.header.iod_atmo, 4); + assign(test_msg_.header.num_msgs, 147); + assign(test_msg_.header.seq_num, 123); + assign(test_msg_.header.time.tow, 3905179974); + assign(test_msg_.header.time.wn, 11193); + assign(test_msg_.header.update_interval, 39); + assign(test_msg_.n_stec_sat_list, 22); + + assign(test_msg_.stec_sat_list[0].stec_coeff[0], -1951); + + assign(test_msg_.stec_sat_list[0].stec_coeff[1], -9854); + + assign(test_msg_.stec_sat_list[0].stec_coeff[2], 27353); + + assign(test_msg_.stec_sat_list[0].stec_coeff[3], 3130); + assign(test_msg_.stec_sat_list[0].stec_quality_indicator, 111); + assign(test_msg_.stec_sat_list[0].sv_id.constellation, 19); + assign(test_msg_.stec_sat_list[0].sv_id.satId, 126); + + assign(test_msg_.stec_sat_list[1].stec_coeff[0], 24401); + + assign(test_msg_.stec_sat_list[1].stec_coeff[1], 4182); + + assign(test_msg_.stec_sat_list[1].stec_coeff[2], 21543); + + assign(test_msg_.stec_sat_list[1].stec_coeff[3], -12060); + assign(test_msg_.stec_sat_list[1].stec_quality_indicator, 171); + assign(test_msg_.stec_sat_list[1].sv_id.constellation, 230); + assign(test_msg_.stec_sat_list[1].sv_id.satId, 65); + + assign(test_msg_.stec_sat_list[2].stec_coeff[0], -13469); + + assign(test_msg_.stec_sat_list[2].stec_coeff[1], -18883); + + assign(test_msg_.stec_sat_list[2].stec_coeff[2], 32066); + + assign(test_msg_.stec_sat_list[2].stec_coeff[3], 971); + assign(test_msg_.stec_sat_list[2].stec_quality_indicator, 219); + assign(test_msg_.stec_sat_list[2].sv_id.constellation, 81); + assign(test_msg_.stec_sat_list[2].sv_id.satId, 201); + + assign(test_msg_.stec_sat_list[3].stec_coeff[0], 32220); + + assign(test_msg_.stec_sat_list[3].stec_coeff[1], 5436); + + assign(test_msg_.stec_sat_list[3].stec_coeff[2], -9635); + + assign(test_msg_.stec_sat_list[3].stec_coeff[3], -24841); + assign(test_msg_.stec_sat_list[3].stec_quality_indicator, 100); + assign(test_msg_.stec_sat_list[3].sv_id.constellation, 44); + assign(test_msg_.stec_sat_list[3].sv_id.satId, 193); + + assign(test_msg_.stec_sat_list[4].stec_coeff[0], 3718); + + assign(test_msg_.stec_sat_list[4].stec_coeff[1], 12497); + + assign(test_msg_.stec_sat_list[4].stec_coeff[2], -10482); + + assign(test_msg_.stec_sat_list[4].stec_coeff[3], -27495); + assign(test_msg_.stec_sat_list[4].stec_quality_indicator, 129); + assign(test_msg_.stec_sat_list[4].sv_id.constellation, 93); + assign(test_msg_.stec_sat_list[4].sv_id.satId, 207); + + assign(test_msg_.stec_sat_list[5].stec_coeff[0], -4940); + + assign(test_msg_.stec_sat_list[5].stec_coeff[1], -13875); + + assign(test_msg_.stec_sat_list[5].stec_coeff[2], 801); + + assign(test_msg_.stec_sat_list[5].stec_coeff[3], -13066); + assign(test_msg_.stec_sat_list[5].stec_quality_indicator, 225); + assign(test_msg_.stec_sat_list[5].sv_id.constellation, 72); + assign(test_msg_.stec_sat_list[5].sv_id.satId, 147); + + assign(test_msg_.stec_sat_list[6].stec_coeff[0], -15868); + + assign(test_msg_.stec_sat_list[6].stec_coeff[1], -2369); + + assign(test_msg_.stec_sat_list[6].stec_coeff[2], -9396); + + assign(test_msg_.stec_sat_list[6].stec_coeff[3], -16609); + assign(test_msg_.stec_sat_list[6].stec_quality_indicator, 98); + assign(test_msg_.stec_sat_list[6].sv_id.constellation, 3); + assign(test_msg_.stec_sat_list[6].sv_id.satId, 19); + + assign(test_msg_.stec_sat_list[7].stec_coeff[0], -1265); + + assign(test_msg_.stec_sat_list[7].stec_coeff[1], 4897); + + assign(test_msg_.stec_sat_list[7].stec_coeff[2], 13920); + + assign(test_msg_.stec_sat_list[7].stec_coeff[3], -28102); + assign(test_msg_.stec_sat_list[7].stec_quality_indicator, 177); + assign(test_msg_.stec_sat_list[7].sv_id.constellation, 79); + assign(test_msg_.stec_sat_list[7].sv_id.satId, 113); + + assign(test_msg_.stec_sat_list[8].stec_coeff[0], 5448); + + assign(test_msg_.stec_sat_list[8].stec_coeff[1], -11359); + + assign(test_msg_.stec_sat_list[8].stec_coeff[2], 5574); + + assign(test_msg_.stec_sat_list[8].stec_coeff[3], 28654); + assign(test_msg_.stec_sat_list[8].stec_quality_indicator, 249); + assign(test_msg_.stec_sat_list[8].sv_id.constellation, 100); + assign(test_msg_.stec_sat_list[8].sv_id.satId, 210); + + assign(test_msg_.stec_sat_list[9].stec_coeff[0], -10783); + + assign(test_msg_.stec_sat_list[9].stec_coeff[1], 18179); + + assign(test_msg_.stec_sat_list[9].stec_coeff[2], 16371); + + assign(test_msg_.stec_sat_list[9].stec_coeff[3], -5055); + assign(test_msg_.stec_sat_list[9].stec_quality_indicator, 227); + assign(test_msg_.stec_sat_list[9].sv_id.constellation, 36); + assign(test_msg_.stec_sat_list[9].sv_id.satId, 107); + + assign(test_msg_.stec_sat_list[10].stec_coeff[0], 4009); + + assign(test_msg_.stec_sat_list[10].stec_coeff[1], 1462); + + assign(test_msg_.stec_sat_list[10].stec_coeff[2], -19216); + + assign(test_msg_.stec_sat_list[10].stec_coeff[3], 31241); + assign(test_msg_.stec_sat_list[10].stec_quality_indicator, 0); + assign(test_msg_.stec_sat_list[10].sv_id.constellation, 77); + assign(test_msg_.stec_sat_list[10].sv_id.satId, 92); + + assign(test_msg_.stec_sat_list[11].stec_coeff[0], 26727); + + assign(test_msg_.stec_sat_list[11].stec_coeff[1], -16898); + + assign(test_msg_.stec_sat_list[11].stec_coeff[2], 28241); + + assign(test_msg_.stec_sat_list[11].stec_coeff[3], 12546); + assign(test_msg_.stec_sat_list[11].stec_quality_indicator, 6); + assign(test_msg_.stec_sat_list[11].sv_id.constellation, 232); + assign(test_msg_.stec_sat_list[11].sv_id.satId, 86); + + assign(test_msg_.stec_sat_list[12].stec_coeff[0], 12855); + + assign(test_msg_.stec_sat_list[12].stec_coeff[1], 1461); + + assign(test_msg_.stec_sat_list[12].stec_coeff[2], 20603); + + assign(test_msg_.stec_sat_list[12].stec_coeff[3], -3023); + assign(test_msg_.stec_sat_list[12].stec_quality_indicator, 216); + assign(test_msg_.stec_sat_list[12].sv_id.constellation, 84); + assign(test_msg_.stec_sat_list[12].sv_id.satId, 202); + + assign(test_msg_.stec_sat_list[13].stec_coeff[0], -6492); + + assign(test_msg_.stec_sat_list[13].stec_coeff[1], 16952); + + assign(test_msg_.stec_sat_list[13].stec_coeff[2], -22404); + + assign(test_msg_.stec_sat_list[13].stec_coeff[3], -29893); + assign(test_msg_.stec_sat_list[13].stec_quality_indicator, 125); + assign(test_msg_.stec_sat_list[13].sv_id.constellation, 188); + assign(test_msg_.stec_sat_list[13].sv_id.satId, 224); + + assign(test_msg_.stec_sat_list[14].stec_coeff[0], -10053); + + assign(test_msg_.stec_sat_list[14].stec_coeff[1], -24897); + + assign(test_msg_.stec_sat_list[14].stec_coeff[2], 23629); + + assign(test_msg_.stec_sat_list[14].stec_coeff[3], -710); + assign(test_msg_.stec_sat_list[14].stec_quality_indicator, 51); + assign(test_msg_.stec_sat_list[14].sv_id.constellation, 118); + assign(test_msg_.stec_sat_list[14].sv_id.satId, 106); + + assign(test_msg_.stec_sat_list[15].stec_coeff[0], -26103); + + assign(test_msg_.stec_sat_list[15].stec_coeff[1], -9539); + + assign(test_msg_.stec_sat_list[15].stec_coeff[2], -11971); + + assign(test_msg_.stec_sat_list[15].stec_coeff[3], 20993); + assign(test_msg_.stec_sat_list[15].stec_quality_indicator, 165); + assign(test_msg_.stec_sat_list[15].sv_id.constellation, 150); + assign(test_msg_.stec_sat_list[15].sv_id.satId, 132); + + assign(test_msg_.stec_sat_list[16].stec_coeff[0], -18891); + + assign(test_msg_.stec_sat_list[16].stec_coeff[1], -16272); + + assign(test_msg_.stec_sat_list[16].stec_coeff[2], -22578); + + assign(test_msg_.stec_sat_list[16].stec_coeff[3], -2915); + assign(test_msg_.stec_sat_list[16].stec_quality_indicator, 23); + assign(test_msg_.stec_sat_list[16].sv_id.constellation, 196); + assign(test_msg_.stec_sat_list[16].sv_id.satId, 181); + + assign(test_msg_.stec_sat_list[17].stec_coeff[0], 15833); + + assign(test_msg_.stec_sat_list[17].stec_coeff[1], 24920); + + assign(test_msg_.stec_sat_list[17].stec_coeff[2], -13879); + + assign(test_msg_.stec_sat_list[17].stec_coeff[3], -1206); + assign(test_msg_.stec_sat_list[17].stec_quality_indicator, 189); + assign(test_msg_.stec_sat_list[17].sv_id.constellation, 1); + assign(test_msg_.stec_sat_list[17].sv_id.satId, 35); + + assign(test_msg_.stec_sat_list[18].stec_coeff[0], 14008); + + assign(test_msg_.stec_sat_list[18].stec_coeff[1], 18996); + + assign(test_msg_.stec_sat_list[18].stec_coeff[2], 2798); + + assign(test_msg_.stec_sat_list[18].stec_coeff[3], 5761); + assign(test_msg_.stec_sat_list[18].stec_quality_indicator, 104); + assign(test_msg_.stec_sat_list[18].sv_id.constellation, 14); + assign(test_msg_.stec_sat_list[18].sv_id.satId, 217); + + assign(test_msg_.stec_sat_list[19].stec_coeff[0], -25256); + + assign(test_msg_.stec_sat_list[19].stec_coeff[1], -15330); + + assign(test_msg_.stec_sat_list[19].stec_coeff[2], 6831); + + assign(test_msg_.stec_sat_list[19].stec_coeff[3], 8780); + assign(test_msg_.stec_sat_list[19].stec_quality_indicator, 109); + assign(test_msg_.stec_sat_list[19].sv_id.constellation, 226); + assign(test_msg_.stec_sat_list[19].sv_id.satId, 178); + + assign(test_msg_.stec_sat_list[20].stec_coeff[0], 3304); + + assign(test_msg_.stec_sat_list[20].stec_coeff[1], -2893); + + assign(test_msg_.stec_sat_list[20].stec_coeff[2], -25841); + + assign(test_msg_.stec_sat_list[20].stec_coeff[3], -13628); + assign(test_msg_.stec_sat_list[20].stec_quality_indicator, 154); + assign(test_msg_.stec_sat_list[20].sv_id.constellation, 220); + assign(test_msg_.stec_sat_list[20].sv_id.satId, 116); + + assign(test_msg_.stec_sat_list[21].stec_coeff[0], -10742); + + assign(test_msg_.stec_sat_list[21].stec_coeff[1], 10098); + + assign(test_msg_.stec_sat_list[21].stec_coeff[2], 7413); + + assign(test_msg_.stec_sat_list[21].stec_coeff[3], 17645); + assign(test_msg_.stec_sat_list[21].stec_quality_indicator, 115); + assign(test_msg_.stec_sat_list[21].sv_id.constellation, 70); + assign(test_msg_.stec_sat_list[21].sv_id.satId, 72); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_stec_correction_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_stec_correction_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrStecCorrectionDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_stec_correction_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrStecCorrectionDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_stec_correction_dep_a, + sizeof(msg->ssr_stec_correction_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_stec_correction_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_stec_correction_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrStecCorrectionDepA); + info.sender_id = 1831; + info.preamble = 0x55; + info.crc = 0x9b88; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 252; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_stec_correction_dep_a_t &lesser, + const sbp_msg_ssr_stec_correction_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_stec_correction_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_stec_correction_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrectionDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrStecCorrectionDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrStecCorrectionDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrStecCorrectionDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_stec_correction_dep_a_t test_msg_{}; + uint8_t encoded_frame_[252 + 8] = { + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, 39, + 4, 126, 19, 111, 97, 248, 130, 217, 217, 106, 58, 12, 65, 230, 171, + 81, 95, 86, 16, 39, 84, 228, 208, 201, 81, 219, 99, 203, 61, 182, + 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, 93, 218, 247, 158, + 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, 148, 147, 72, 225, 180, + 236, 205, 201, 33, 3, 246, 204, 19, 3, 98, 4, 194, 191, 246, 76, + 219, 31, 191, 113, 79, 177, 15, 251, 33, 19, 96, 54, 58, 146, 210, + 100, 249, 72, 21, 161, 211, 198, 21, 238, 111, 107, 36, 227, 225, 213, + 3, 71, 243, 63, 65, 236, 92, 77, 0, 169, 15, 182, 5, 240, 180, + 9, 122, 86, 232, 6, 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, + 216, 55, 50, 181, 5, 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, + 66, 124, 168, 59, 139, 106, 118, 51, 187, 216, 191, 158, 77, 92, 58, + 253, 132, 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, 181, 196, 23, + 53, 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, + 201, 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, 22, + 178, 226, 109, 88, 157, 30, 196, 175, 26, 76, 34, 116, 220, 154, 232, + 12, 179, 244, 15, 155, 196, 202, 72, 70, 115, 10, 214, 114, 39, 245, + 28, 237, 68, 136, 155, + }; + uint8_t encoded_payload_[252] = { + 70, 81, 196, 232, 185, 43, 147, 123, 39, 4, 126, 19, 111, 97, 248, + 130, 217, 217, 106, 58, 12, 65, 230, 171, 81, 95, 86, 16, 39, 84, + 228, 208, 201, 81, 219, 99, 203, 61, 182, 66, 125, 203, 3, 193, 44, + 100, 220, 125, 60, 21, 93, 218, 247, 158, 207, 93, 129, 134, 14, 209, + 48, 14, 215, 153, 148, 147, 72, 225, 180, 236, 205, 201, 33, 3, 246, + 204, 19, 3, 98, 4, 194, 191, 246, 76, 219, 31, 191, 113, 79, 177, + 15, 251, 33, 19, 96, 54, 58, 146, 210, 100, 249, 72, 21, 161, 211, + 198, 21, 238, 111, 107, 36, 227, 225, 213, 3, 71, 243, 63, 65, 236, + 92, 77, 0, 169, 15, 182, 5, 240, 180, 9, 122, 86, 232, 6, 103, + 104, 254, 189, 81, 110, 2, 49, 202, 84, 216, 55, 50, 181, 5, 123, + 80, 49, 244, 224, 188, 125, 164, 230, 56, 66, 124, 168, 59, 139, 106, + 118, 51, 187, 216, 191, 158, 77, 92, 58, 253, 132, 150, 165, 9, 154, + 189, 218, 61, 209, 1, 82, 181, 196, 23, 53, 182, 112, 192, 206, 167, + 157, 244, 35, 1, 189, 217, 61, 88, 97, 201, 201, 74, 251, 217, 14, + 104, 184, 54, 52, 74, 238, 10, 129, 22, 178, 226, 109, 88, 157, 30, + 196, 175, 26, 76, 34, 116, 220, 154, 232, 12, 179, 244, 15, 155, 196, + 202, 72, 70, 115, 10, 214, 114, 39, 245, 28, 237, 68, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrStecCorrectionDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrStecCorrectionDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + for (uint8_t i = 0; i < 252; i++) { + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrStecCorrectionDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_ssr_stec_correction_dep_a_t t{}; + return sbp_msg_ssr_stec_correction_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_ssr_stec_correction_dep_a_t t{}; + t.n_stec_sat_list = 1; + return sbp_msg_ssr_stec_correction_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_stec_correction_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrStecCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrStecCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrStecCorrectionDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.iod_atmo, greater.header.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.num_msgs, greater.header.num_msgs); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.seq_num, greater.header.seq_num); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.tow, greater.header.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.time.wn, greater.header.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.header.update_interval, + greater.header.update_interval); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_stec_sat_list, greater.n_stec_sat_list); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[0], + greater.stec_sat_list[0].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[1], + greater.stec_sat_list[0].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[2], + greater.stec_sat_list[0].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_coeff[3], + greater.stec_sat_list[0].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].stec_quality_indicator, + greater.stec_sat_list[0].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.constellation, + greater.stec_sat_list[0].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[0].sv_id.satId, + greater.stec_sat_list[0].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[0], + greater.stec_sat_list[1].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[1], + greater.stec_sat_list[1].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[2], + greater.stec_sat_list[1].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_coeff[3], + greater.stec_sat_list[1].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].stec_quality_indicator, + greater.stec_sat_list[1].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.constellation, + greater.stec_sat_list[1].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[1].sv_id.satId, + greater.stec_sat_list[1].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[0], + greater.stec_sat_list[2].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[1], + greater.stec_sat_list[2].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[2], + greater.stec_sat_list[2].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_coeff[3], + greater.stec_sat_list[2].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].stec_quality_indicator, + greater.stec_sat_list[2].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].sv_id.constellation, + greater.stec_sat_list[2].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[2].sv_id.satId, + greater.stec_sat_list[2].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[0], + greater.stec_sat_list[3].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[1], + greater.stec_sat_list[3].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[2], + greater.stec_sat_list[3].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_coeff[3], + greater.stec_sat_list[3].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].stec_quality_indicator, + greater.stec_sat_list[3].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].sv_id.constellation, + greater.stec_sat_list[3].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[3].sv_id.satId, + greater.stec_sat_list[3].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[0], + greater.stec_sat_list[4].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[1], + greater.stec_sat_list[4].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[2], + greater.stec_sat_list[4].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_coeff[3], + greater.stec_sat_list[4].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].stec_quality_indicator, + greater.stec_sat_list[4].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].sv_id.constellation, + greater.stec_sat_list[4].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[4].sv_id.satId, + greater.stec_sat_list[4].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[0], + greater.stec_sat_list[5].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[1], + greater.stec_sat_list[5].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[2], + greater.stec_sat_list[5].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_coeff[3], + greater.stec_sat_list[5].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].stec_quality_indicator, + greater.stec_sat_list[5].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].sv_id.constellation, + greater.stec_sat_list[5].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[5].sv_id.satId, + greater.stec_sat_list[5].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[0], + greater.stec_sat_list[6].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[1], + greater.stec_sat_list[6].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[2], + greater.stec_sat_list[6].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_coeff[3], + greater.stec_sat_list[6].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].stec_quality_indicator, + greater.stec_sat_list[6].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].sv_id.constellation, + greater.stec_sat_list[6].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[6].sv_id.satId, + greater.stec_sat_list[6].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[0], + greater.stec_sat_list[7].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[1], + greater.stec_sat_list[7].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[2], + greater.stec_sat_list[7].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_coeff[3], + greater.stec_sat_list[7].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].stec_quality_indicator, + greater.stec_sat_list[7].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].sv_id.constellation, + greater.stec_sat_list[7].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[7].sv_id.satId, + greater.stec_sat_list[7].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[0], + greater.stec_sat_list[8].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[1], + greater.stec_sat_list[8].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[2], + greater.stec_sat_list[8].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_coeff[3], + greater.stec_sat_list[8].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].stec_quality_indicator, + greater.stec_sat_list[8].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].sv_id.constellation, + greater.stec_sat_list[8].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[8].sv_id.satId, + greater.stec_sat_list[8].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[0], + greater.stec_sat_list[9].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[1], + greater.stec_sat_list[9].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[2], + greater.stec_sat_list[9].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_coeff[3], + greater.stec_sat_list[9].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].stec_quality_indicator, + greater.stec_sat_list[9].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].sv_id.constellation, + greater.stec_sat_list[9].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[9].sv_id.satId, + greater.stec_sat_list[9].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[0], + greater.stec_sat_list[10].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[1], + greater.stec_sat_list[10].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[2], + greater.stec_sat_list[10].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_coeff[3], + greater.stec_sat_list[10].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].stec_quality_indicator, + greater.stec_sat_list[10].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].sv_id.constellation, + greater.stec_sat_list[10].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[10].sv_id.satId, + greater.stec_sat_list[10].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[0], + greater.stec_sat_list[11].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[1], + greater.stec_sat_list[11].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[2], + greater.stec_sat_list[11].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_coeff[3], + greater.stec_sat_list[11].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].stec_quality_indicator, + greater.stec_sat_list[11].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].sv_id.constellation, + greater.stec_sat_list[11].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[11].sv_id.satId, + greater.stec_sat_list[11].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[0], + greater.stec_sat_list[12].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[1], + greater.stec_sat_list[12].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[2], + greater.stec_sat_list[12].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_coeff[3], + greater.stec_sat_list[12].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].stec_quality_indicator, + greater.stec_sat_list[12].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].sv_id.constellation, + greater.stec_sat_list[12].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[12].sv_id.satId, + greater.stec_sat_list[12].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[0], + greater.stec_sat_list[13].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[1], + greater.stec_sat_list[13].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[2], + greater.stec_sat_list[13].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_coeff[3], + greater.stec_sat_list[13].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].stec_quality_indicator, + greater.stec_sat_list[13].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].sv_id.constellation, + greater.stec_sat_list[13].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[13].sv_id.satId, + greater.stec_sat_list[13].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[0], + greater.stec_sat_list[14].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[1], + greater.stec_sat_list[14].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[2], + greater.stec_sat_list[14].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_coeff[3], + greater.stec_sat_list[14].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].stec_quality_indicator, + greater.stec_sat_list[14].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].sv_id.constellation, + greater.stec_sat_list[14].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[14].sv_id.satId, + greater.stec_sat_list[14].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[0], + greater.stec_sat_list[15].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[1], + greater.stec_sat_list[15].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[2], + greater.stec_sat_list[15].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_coeff[3], + greater.stec_sat_list[15].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].stec_quality_indicator, + greater.stec_sat_list[15].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].sv_id.constellation, + greater.stec_sat_list[15].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[15].sv_id.satId, + greater.stec_sat_list[15].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[0], + greater.stec_sat_list[16].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[1], + greater.stec_sat_list[16].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[2], + greater.stec_sat_list[16].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_coeff[3], + greater.stec_sat_list[16].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].stec_quality_indicator, + greater.stec_sat_list[16].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].sv_id.constellation, + greater.stec_sat_list[16].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[16].sv_id.satId, + greater.stec_sat_list[16].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[0], + greater.stec_sat_list[17].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[1], + greater.stec_sat_list[17].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[2], + greater.stec_sat_list[17].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_coeff[3], + greater.stec_sat_list[17].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].stec_quality_indicator, + greater.stec_sat_list[17].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].sv_id.constellation, + greater.stec_sat_list[17].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[17].sv_id.satId, + greater.stec_sat_list[17].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[0], + greater.stec_sat_list[18].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[1], + greater.stec_sat_list[18].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[2], + greater.stec_sat_list[18].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_coeff[3], + greater.stec_sat_list[18].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].stec_quality_indicator, + greater.stec_sat_list[18].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].sv_id.constellation, + greater.stec_sat_list[18].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[18].sv_id.satId, + greater.stec_sat_list[18].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[0], + greater.stec_sat_list[19].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[1], + greater.stec_sat_list[19].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[2], + greater.stec_sat_list[19].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_coeff[3], + greater.stec_sat_list[19].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].stec_quality_indicator, + greater.stec_sat_list[19].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].sv_id.constellation, + greater.stec_sat_list[19].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[19].sv_id.satId, + greater.stec_sat_list[19].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[0], + greater.stec_sat_list[20].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[1], + greater.stec_sat_list[20].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[2], + greater.stec_sat_list[20].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_coeff[3], + greater.stec_sat_list[20].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].stec_quality_indicator, + greater.stec_sat_list[20].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].sv_id.constellation, + greater.stec_sat_list[20].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[20].sv_id.satId, + greater.stec_sat_list[20].sv_id.satId); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].stec_coeff[0], + greater.stec_sat_list[21].stec_coeff[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].stec_coeff[1], + greater.stec_sat_list[21].stec_coeff[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].stec_coeff[2], + greater.stec_sat_list[21].stec_coeff[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].stec_coeff[3], + greater.stec_sat_list[21].stec_coeff[3]); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].stec_quality_indicator, + greater.stec_sat_list[21].stec_quality_indicator); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].sv_id.constellation, + greater.stec_sat_list[21].sv_id.constellation); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_stec_correction_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_stec_correction_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.stec_sat_list[21].sv_id.satId, + greater.stec_sat_list[21].sv_id.satId); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrStecCorrectionDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_STEC_CORRECTION_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_stec_correction_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_stec_correction_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_stec_correction_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_stec_correction_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_stec_correction_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrStecCorrectionDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrStecCorrectionDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinition.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinition.cc index 62178c44ac..d0791ea053 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinition.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinition.cc @@ -16,139 +16,863 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrTileDefinition0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrTileDefinition0 : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrTileDefinition0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrTileDefinition0() { + assign(test_msg_.bitmask, 1234567890); + assign(test_msg_.cols, 6); + assign(test_msg_.corner_nw_lat, 7354); + assign(test_msg_.corner_nw_lon, -22725); + assign(test_msg_.iod_atmo, 3); + assign(test_msg_.rows, 6); + assign(test_msg_.sol_id, 2); + assign(test_msg_.spacing_lat, 100); + assign(test_msg_.spacing_lon, 100); + assign(test_msg_.tile_id, 5); + assign(test_msg_.tile_set_id, 4); + assign(test_msg_.time.tow, 604799); + assign(test_msg_.time.wn, 2222); + assign(test_msg_.update_interval, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ssr_tile_definition_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrTileDefinition, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrTileDefinition); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_tile_definition, + sizeof(msg->ssr_tile_definition)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_tile_definition_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_tile_definition, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrTileDefinition); + info.sender_id = 0; + info.preamble = 0x55; + info.crc = 0x5ECC; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 33; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_tile_definition_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_tile_definition_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_tile_definition_t &lesser, + const sbp_msg_ssr_tile_definition_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ssr_tile_definition_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_tile_definition_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_tile_definition_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_tile_definition_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinition, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinition, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrTileDefinition, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrTileDefinition, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_ssr_MsgSsrTileDefinition0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_tile_definition_t test_msg_{}; + uint8_t encoded_frame_[33 + 8] = { 85, 248, 5, 0, 0, 33, 127, 58, 9, 0, 174, 8, 1, 2, 3, 4, 0, 5, 0, 186, 28, 59, 167, 100, 0, 100, 0, 6, 0, 6, 0, 210, 2, 150, 73, 0, 0, 0, 0, 204, 94, }; + uint8_t encoded_payload_[33] = { + 127, 58, 9, 0, 174, 8, 1, 2, 3, 4, 0, 5, 0, 186, 28, 59, 167, + 100, 0, 100, 0, 6, 0, 6, 0, 210, 2, 150, 73, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_tile_definition_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSsrTileDefinition, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrTileDefinition, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + for (uint8_t i = 0; i < 33; i++) { + EXPECT_EQ( + sbp_msg_ssr_tile_definition_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSsrTileDefinition, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - sbp_msg_ssr_tile_definition_t test_msg{}; - test_msg.bitmask = 1234567890; - test_msg.cols = 6; - test_msg.corner_nw_lat = 7354; - test_msg.corner_nw_lon = -22725; - test_msg.iod_atmo = 3; - test_msg.rows = 6; - test_msg.sol_id = 2; - test_msg.spacing_lat = 100; - test_msg.spacing_lon = 100; - test_msg.tile_id = 5; - test_msg.tile_set_id = 4; - test_msg.time.tow = 604799; - test_msg.time.wn = 2222; - test_msg.update_interval = 1; - - EXPECT_EQ(send_message(0, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 0); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.bitmask, 1234567890) - << "incorrect value for last_msg_.bitmask, expected 1234567890, is " - << last_msg_.bitmask; - EXPECT_EQ(last_msg_.cols, 6) - << "incorrect value for last_msg_.cols, expected 6, is " - << last_msg_.cols; - EXPECT_EQ(last_msg_.corner_nw_lat, 7354) - << "incorrect value for last_msg_.corner_nw_lat, expected 7354, is " - << last_msg_.corner_nw_lat; - EXPECT_EQ(last_msg_.corner_nw_lon, -22725) - << "incorrect value for last_msg_.corner_nw_lon, expected -22725, is " - << last_msg_.corner_nw_lon; - EXPECT_EQ(last_msg_.iod_atmo, 3) - << "incorrect value for last_msg_.iod_atmo, expected 3, is " - << last_msg_.iod_atmo; - EXPECT_EQ(last_msg_.rows, 6) - << "incorrect value for last_msg_.rows, expected 6, is " - << last_msg_.rows; - EXPECT_EQ(last_msg_.sol_id, 2) - << "incorrect value for last_msg_.sol_id, expected 2, is " - << last_msg_.sol_id; - EXPECT_EQ(last_msg_.spacing_lat, 100) - << "incorrect value for last_msg_.spacing_lat, expected 100, is " - << last_msg_.spacing_lat; - EXPECT_EQ(last_msg_.spacing_lon, 100) - << "incorrect value for last_msg_.spacing_lon, expected 100, is " - << last_msg_.spacing_lon; - EXPECT_EQ(last_msg_.tile_id, 5) - << "incorrect value for last_msg_.tile_id, expected 5, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 4) - << "incorrect value for last_msg_.tile_set_id, expected 4, is " - << last_msg_.tile_set_id; - EXPECT_EQ(last_msg_.time.tow, 604799) - << "incorrect value for last_msg_.time.tow, expected 604799, is " - << last_msg_.time.tow; - EXPECT_EQ(last_msg_.time.wn, 2222) - << "incorrect value for last_msg_.time.wn, expected 2222, is " - << last_msg_.time.wn; - EXPECT_EQ(last_msg_.update_interval, 1) - << "incorrect value for last_msg_.update_interval, expected 1, is " - << last_msg_.update_interval; + EXPECT_EQ(handler.outputs.size(), 0); } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_tile_definition_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrTileDefinition, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSsrTileDefinition, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSsrTileDefinition, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.bitmask, greater.bitmask); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.cols, greater.cols); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lat, greater.corner_nw_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lon, greater.corner_nw_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.iod_atmo, greater.iod_atmo); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.rows, greater.rows); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.sol_id, greater.sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lat, greater.spacing_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lon, greater.spacing_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.time.tow, greater.time.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.time.wn, greater.time.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_t greater = info.test_msg; + make_lesser_greater(lesser.update_interval, greater.update_interval); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrTileDefinition); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_TILE_DEFINITION"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_tile_definition_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ssr_tile_definition_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_tile_definition, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.ssr_tile_definition, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrTileDefinition, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinition0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrTileDefinition, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc new file mode 100644 index 0000000000..0ce49d01ec --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc @@ -0,0 +1,858 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0() { + assign(test_msg_.bitmask, 11259375); + assign(test_msg_.cols, 48917); + assign(test_msg_.corner_nw_lat, -18168); + assign(test_msg_.corner_nw_lon, -19191); + assign(test_msg_.rows, 36863); + assign(test_msg_.spacing_lat, 61602); + assign(test_msg_.spacing_lon, 4929); + assign(test_msg_.tile_id, 63410); + assign(test_msg_.tile_set_id, 48697); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_tile_definition_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_tile_definition_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrTileDefinitionDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrTileDefinitionDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_tile_definition_dep_a, + sizeof(msg->ssr_tile_definition_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_tile_definition_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_tile_definition_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrTileDefinitionDepA); + info.sender_id = 34248; + info.preamble = 0x55; + info.crc = 0x9a41; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 24; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_ssr_tile_definition_dep_a_t &lesser, + const sbp_msg_ssr_tile_definition_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_tile_definition_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_tile_definition_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinitionDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinitionDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrTileDefinitionDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrTileDefinitionDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_tile_definition_dep_a_t test_msg_{}; + uint8_t encoded_frame_[24 + 8] = { + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, 185, 9, 181, 162, 240, + 65, 19, 255, 143, 21, 191, 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + }; + uint8_t encoded_payload_[24] = { + 57, 190, 178, 247, 8, 185, 9, 181, 162, 240, 65, 19, + 255, 143, 21, 191, 239, 205, 171, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrTileDefinitionDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrTileDefinitionDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + + for (uint8_t i = 0; i < 24; i++) { + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrTileDefinitionDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.bitmask, greater.bitmask); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cols, greater.cols); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lat, greater.corner_nw_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lon, greater.corner_nw_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.rows, greater.rows); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lat, greater.spacing_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lon, greater.spacing_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_a_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrTileDefinitionDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_TILE_DEFINITION_DEP_A"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_tile_definition_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_tile_definition_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_tile_definition_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_tile_definition_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[24]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 24); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 24), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 24); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrTileDefinitionDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrTileDefinitionDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepB.cc b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepB.cc index 9207819ac1..f79700e50a 100644 --- a/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepB.cc +++ b/c/test/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepB.cc @@ -16,122 +16,850 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_ssr_MsgSsrTileDefinitionDepB0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0 + : public ::testing::Test { public: - Test_auto_check_sbp_ssr_MsgSsrTileDefinitionDepB0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0() { + assign(test_msg_.bitmask, 1234567890); + assign(test_msg_.cols, 32768); + assign(test_msg_.corner_nw_lat, 1024); + assign(test_msg_.corner_nw_lon, 2048); + assign(test_msg_.rows, 16384); + assign(test_msg_.spacing_lat, 4096); + assign(test_msg_.spacing_lon, 8192); + assign(test_msg_.ssr_sol_id, 31); + assign(test_msg_.tile_id, 512); + assign(test_msg_.tile_set_id, 256); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_ssr_tile_definition_dep_b_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_ssr_tile_definition_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSsrTileDefinitionDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ssr_tile_definition_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSsrTileDefinitionDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ssr_tile_definition_dep_b, + sizeof(msg->ssr_tile_definition_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ssr_tile_definition_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ssr_tile_definition_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSsrTileDefinitionDepB); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x47D6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 25; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ssr_tile_definition_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ssr_tile_definition_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ssr_tile_definition_dep_b_t &lesser, + const sbp_msg_ssr_tile_definition_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); -TEST_F(Test_auto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ssr_tile_definition_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ssr_tile_definition_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinitionDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSsrTileDefinitionDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSsrTileDefinitionDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSsrTileDefinitionDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ssr_tile_definition_dep_b_t test_msg_{}; + uint8_t encoded_frame_[25 + 8] = { 85, 247, 5, 66, 0, 25, 31, 0, 1, 0, 2, 0, 4, 0, 8, 0, 16, 0, 32, 0, 64, 0, 128, 210, 2, 150, 73, 0, 0, 0, 0, 214, 71, }; + uint8_t encoded_payload_[25] = { + 31, 0, 1, 0, 2, 0, 4, 0, 8, 0, 16, 0, 32, + 0, 64, 0, 128, 210, 2, 150, 73, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgSsrTileDefinitionDepB, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[25]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 25); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 25), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSsrTileDefinitionDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 25); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 25), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[25]; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 25), 0); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[25]; + + for (uint8_t i = 0; i < 25; i++) { + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 25); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgSsrTileDefinitionDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 25); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_decode(&info.encoded_payload[0], + i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_ssr_tile_definition_dep_b_t test_msg{}; - test_msg.bitmask = 1234567890; - test_msg.cols = 32768; - test_msg.corner_nw_lat = 1024; - test_msg.corner_nw_lon = 2048; - test_msg.rows = 16384; - test_msg.spacing_lat = 4096; - test_msg.spacing_lon = 8192; - test_msg.ssr_sol_id = 31; - test_msg.tile_id = 512; - test_msg.tile_set_id = 256; - - EXPECT_EQ(send_message(66, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.bitmask, 1234567890) - << "incorrect value for last_msg_.bitmask, expected 1234567890, is " - << last_msg_.bitmask; - EXPECT_EQ(last_msg_.cols, 32768) - << "incorrect value for last_msg_.cols, expected 32768, is " - << last_msg_.cols; - EXPECT_EQ(last_msg_.corner_nw_lat, 1024) - << "incorrect value for last_msg_.corner_nw_lat, expected 1024, is " - << last_msg_.corner_nw_lat; - EXPECT_EQ(last_msg_.corner_nw_lon, 2048) - << "incorrect value for last_msg_.corner_nw_lon, expected 2048, is " - << last_msg_.corner_nw_lon; - EXPECT_EQ(last_msg_.rows, 16384) - << "incorrect value for last_msg_.rows, expected 16384, is " - << last_msg_.rows; - EXPECT_EQ(last_msg_.spacing_lat, 4096) - << "incorrect value for last_msg_.spacing_lat, expected 4096, is " - << last_msg_.spacing_lat; - EXPECT_EQ(last_msg_.spacing_lon, 8192) - << "incorrect value for last_msg_.spacing_lon, expected 8192, is " - << last_msg_.spacing_lon; - EXPECT_EQ(last_msg_.ssr_sol_id, 31) - << "incorrect value for last_msg_.ssr_sol_id, expected 31, is " - << last_msg_.ssr_sol_id; - EXPECT_EQ(last_msg_.tile_id, 512) - << "incorrect value for last_msg_.tile_id, expected 512, is " - << last_msg_.tile_id; - EXPECT_EQ(last_msg_.tile_set_id, 256) - << "incorrect value for last_msg_.tile_set_id, expected 256, is " - << last_msg_.tile_set_id; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ssr_tile_definition_dep_b_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgSsrTileDefinitionDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.bitmask, greater.bitmask); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.cols, greater.cols); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lat, greater.corner_nw_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corner_nw_lon, greater.corner_nw_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.rows, greater.rows); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lat, greater.spacing_lat); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.spacing_lon, greater.spacing_lon); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.ssr_sol_id, greater.ssr_sol_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tile_id, greater.tile_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_ssr_tile_definition_dep_b_t lesser = info.test_msg; + sbp_msg_ssr_tile_definition_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.tile_set_id, greater.tile_set_id); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSsrTileDefinitionDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SSR_TILE_DEFINITION_DEP_B"); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ssr_tile_definition_dep_b_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_ssr_tile_definition_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.ssr_tile_definition_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.ssr_tile_definition_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[25]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 25); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 25), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ssr_tile_definition_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 25); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSsrTileDefinitionDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_ssr_MsgSsrTileDefinitionDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSsrTileDefinitionDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_ssr_ssr_structs.cc b/c/test/cpp/auto_check_sbp_ssr_ssr_structs.cc new file mode 100644 index 0000000000..16fc3cfe71 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_ssr_ssr_structs.cc @@ -0,0 +1,1829 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_ssr_structs.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs0 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs0() { + assign(test_struct_.code, 185); + assign(test_struct_.value, -28374); + } + + struct TestStructInfo { + sbp_code_biases_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_code_biases_content_t test_struct_{}; + uint8_t encoded_data_[3] = { + 185, + 42, + 145, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_code_biases_content_encoded_len(&info.test_struct), 3); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[3]; + EXPECT_EQ(sbp_code_biases_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + EXPECT_EQ(sbp_code_biases_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 3), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ( + sbp_code_biases_content_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_code_biases_content_t t{}; + EXPECT_EQ(sbp_code_biases_content_decode(info.encoded_data, 3, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_code_biases_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_code_biases_content_t t{}; + EXPECT_EQ(sbp_code_biases_content_decode(info.encoded_data, 3, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_code_biases_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs0, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_code_biases_content_t t{}; + + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_code_biases_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs1 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs1() { + assign(test_struct_.bias, 193740482); + assign(test_struct_.code, 80); + assign(test_struct_.discontinuity_counter, 250); + assign(test_struct_.integer_indicator, 230); + assign(test_struct_.widelane_integer_indicator, 40); + } + + struct TestStructInfo { + sbp_phase_biases_content_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_phase_biases_content_t test_struct_{}; + uint8_t encoded_data_[8] = { + 80, 230, 40, 250, 194, 62, 140, 11, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_phase_biases_content_encoded_len(&info.test_struct), 8); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[8]; + EXPECT_EQ(sbp_phase_biases_content_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + EXPECT_EQ(sbp_phase_biases_content_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 8), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ( + sbp_phase_biases_content_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_phase_biases_content_t t{}; + EXPECT_EQ(sbp_phase_biases_content_decode(info.encoded_data, 8, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_phase_biases_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_phase_biases_content_t t{}; + EXPECT_EQ(sbp_phase_biases_content_decode(info.encoded_data, 8, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_phase_biases_content_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs1, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_phase_biases_content_t t{}; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ( + sbp_phase_biases_content_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs2 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs2() { + assign(test_struct_.iod_atmo, 195); + assign(test_struct_.num_msgs, 6); + assign(test_struct_.seq_num, 199); + assign(test_struct_.tile_id, 59568); + assign(test_struct_.tile_set_id, 25856); + assign(test_struct_.time.tow, 3053425451); + assign(test_struct_.time.wn, 57417); + assign(test_struct_.update_interval, 87); + } + + struct TestStructInfo { + sbp_stec_header_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_header_t test_struct_{}; + uint8_t encoded_data_[14] = { + 0, 101, 176, 232, 43, 147, 255, 181, 73, 224, 6, 199, 87, 195, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_header_encoded_len(&info.test_struct), 14); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[14]; + EXPECT_EQ(sbp_stec_header_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + EXPECT_EQ( + sbp_stec_header_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 14), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[14]; + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_stec_header_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_header_t t{}; + EXPECT_EQ(sbp_stec_header_decode(info.encoded_data, 14, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_header_t t{}; + EXPECT_EQ(sbp_stec_header_decode(info.encoded_data, 14, nullptr, &t), SBP_OK); + EXPECT_EQ(sbp_stec_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs2, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_header_t t{}; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_stec_header_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs3 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs3() { + assign(test_struct_.iod_atmo, 195); + assign(test_struct_.num_msgs, 2496); + assign(test_struct_.seq_num, 56738); + assign(test_struct_.tile_id, 52781); + assign(test_struct_.tile_set_id, 42009); + assign(test_struct_.time.tow, 4113264812); + assign(test_struct_.time.wn, 63764); + assign(test_struct_.tropo_quality_indicator, 122); + assign(test_struct_.update_interval, 144); + } + + struct TestStructInfo { + sbp_gridded_correction_header_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gridded_correction_header_t test_struct_{}; + uint8_t encoded_data_[17] = { + 25, 164, 45, 206, 172, 112, 43, 245, 20, + 249, 192, 9, 162, 221, 144, 195, 122, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gridded_correction_header_encoded_len(&info.test_struct), 17); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[17]; + EXPECT_EQ(sbp_gridded_correction_header_encode(&buf[0], sizeof(buf), + &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[17]; + EXPECT_EQ(sbp_gridded_correction_header_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 17), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[17]; + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ(sbp_gridded_correction_header_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gridded_correction_header_t t{}; + EXPECT_EQ( + sbp_gridded_correction_header_decode(info.encoded_data, 17, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gridded_correction_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gridded_correction_header_t t{}; + EXPECT_EQ( + sbp_gridded_correction_header_decode(info.encoded_data, 17, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_gridded_correction_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs3, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gridded_correction_header_t t{}; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ( + sbp_gridded_correction_header_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs4 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs4() { + assign(test_struct_.stec_coeff[0], -20543); + assign(test_struct_.stec_coeff[1], -20563); + assign(test_struct_.stec_coeff[2], -31725); + assign(test_struct_.stec_coeff[3], 24164); + assign(test_struct_.stec_quality_indicator, 168); + assign(test_struct_.sv_id.constellation, 193); + assign(test_struct_.sv_id.satId, 96); + } + + struct TestStructInfo { + sbp_stec_sat_element_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_sat_element_t test_struct_{}; + uint8_t encoded_data_[11] = { + 96, 193, 168, 193, 175, 173, 175, 19, 132, 100, 94, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_sat_element_encoded_len(&info.test_struct), 11); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[11]; + EXPECT_EQ(sbp_stec_sat_element_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + EXPECT_EQ(sbp_stec_sat_element_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 11), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[11]; + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ( + sbp_stec_sat_element_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_sat_element_t t{}; + EXPECT_EQ(sbp_stec_sat_element_decode(info.encoded_data, 11, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_sat_element_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_sat_element_t t{}; + EXPECT_EQ(sbp_stec_sat_element_decode(info.encoded_data, 11, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_stec_sat_element_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs4, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_sat_element_t t{}; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_stec_sat_element_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs5 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs5() { + assign(test_struct_.hydro, 15483); + assign(test_struct_.wet, 75); + } + + struct TestStructInfo { + sbp_tropospheric_delay_correction_no_std_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tropospheric_delay_correction_no_std_t test_struct_{}; + uint8_t encoded_data_[3] = { + 123, + 60, + 75, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ( + sbp_tropospheric_delay_correction_no_std_encoded_len(&info.test_struct), + 3); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[3]; + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 3), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_encode( + &buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tropospheric_delay_correction_no_std_t t{}; + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_decode(info.encoded_data, + 3, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_cmp(&t, &info.test_struct), + 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tropospheric_delay_correction_no_std_t t{}; + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_decode(info.encoded_data, + 3, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_cmp(&t, &info.test_struct), + 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs5, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tropospheric_delay_correction_no_std_t t{}; + + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_tropospheric_delay_correction_no_std_decode(info.encoded_data, + i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs6 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs6() { + assign(test_struct_.hydro, 32529); + assign(test_struct_.stddev, 38); + assign(test_struct_.wet, -16); + } + + struct TestStructInfo { + sbp_tropospheric_delay_correction_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tropospheric_delay_correction_t test_struct_{}; + uint8_t encoded_data_[4] = { + 17, + 127, + 240, + 38, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tropospheric_delay_correction_encoded_len(&info.test_struct), + 4); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_tropospheric_delay_correction_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_tropospheric_delay_correction_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_tropospheric_delay_correction_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tropospheric_delay_correction_t t{}; + EXPECT_EQ(sbp_tropospheric_delay_correction_decode(info.encoded_data, 4, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tropospheric_delay_correction_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tropospheric_delay_correction_t t{}; + EXPECT_EQ(sbp_tropospheric_delay_correction_decode(info.encoded_data, 4, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tropospheric_delay_correction_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs6, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tropospheric_delay_correction_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_tropospheric_delay_correction_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs7 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs7() { + assign(test_struct_.residual, -12476); + assign(test_struct_.sv_id.constellation, 103); + assign(test_struct_.sv_id.satId, 101); + } + + struct TestStructInfo { + sbp_stec_residual_no_std_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_residual_no_std_t test_struct_{}; + uint8_t encoded_data_[4] = { + 101, + 103, + 68, + 207, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_residual_no_std_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_stec_residual_no_std_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_stec_residual_no_std_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_stec_residual_no_std_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_residual_no_std_t t{}; + EXPECT_EQ(sbp_stec_residual_no_std_decode(info.encoded_data, 4, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_residual_no_std_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_residual_no_std_t t{}; + EXPECT_EQ(sbp_stec_residual_no_std_decode(info.encoded_data, 4, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_stec_residual_no_std_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs7, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_residual_no_std_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_stec_residual_no_std_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs8 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs8() { + assign(test_struct_.residual, 26158); + assign(test_struct_.stddev, 7); + assign(test_struct_.sv_id.constellation, 245); + assign(test_struct_.sv_id.satId, 169); + } + + struct TestStructInfo { + sbp_stec_residual_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_residual_t test_struct_{}; + uint8_t encoded_data_[5] = { + 169, 245, 46, 102, 7, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_residual_encoded_len(&info.test_struct), 5); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[5]; + EXPECT_EQ(sbp_stec_residual_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 5); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + EXPECT_EQ(sbp_stec_residual_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 5), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[5]; + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_stec_residual_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_residual_t t{}; + EXPECT_EQ(sbp_stec_residual_decode(info.encoded_data, 5, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_residual_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_residual_t t{}; + EXPECT_EQ(sbp_stec_residual_decode(info.encoded_data, 5, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_stec_residual_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs8, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_residual_t t{}; + + for (uint8_t i = 0; i < 5; i++) { + EXPECT_EQ(sbp_stec_residual_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs9 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs9() { + assign(test_struct_.num_msgs, 40); + assign(test_struct_.seq_num, 205); + assign(test_struct_.sol_id, 7); + assign(test_struct_.time.tow, 964634800); + assign(test_struct_.time.wn, 35954); + assign(test_struct_.update_interval, 241); + } + + struct TestStructInfo { + sbp_bounds_header_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_bounds_header_t test_struct_{}; + uint8_t encoded_data_[10] = { + 176, 40, 127, 57, 114, 140, 40, 205, 241, 7, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_bounds_header_encoded_len(&info.test_struct), 10); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[10]; + EXPECT_EQ(sbp_bounds_header_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + EXPECT_EQ(sbp_bounds_header_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 10), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_bounds_header_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_bounds_header_t t{}; + EXPECT_EQ(sbp_bounds_header_decode(info.encoded_data, 10, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_bounds_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_bounds_header_t t{}; + EXPECT_EQ(sbp_bounds_header_decode(info.encoded_data, 10, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_bounds_header_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs9, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_bounds_header_t t{}; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_bounds_header_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs10 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs10() { + assign(test_struct_.stec_bound_mu, 128); + assign(test_struct_.stec_bound_mu_dot, 52); + assign(test_struct_.stec_bound_sig, 167); + assign(test_struct_.stec_bound_sig_dot, 60); + assign(test_struct_.stec_residual.residual, 20646); + assign(test_struct_.stec_residual.stddev, 89); + assign(test_struct_.stec_residual.sv_id.constellation, 88); + assign(test_struct_.stec_residual.sv_id.satId, 83); + } + + struct TestStructInfo { + sbp_stec_sat_element_integrity_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_sat_element_integrity_t test_struct_{}; + uint8_t encoded_data_[9] = { + 83, 88, 166, 80, 89, 128, 167, 52, 60, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_sat_element_integrity_encoded_len(&info.test_struct), 9); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[9]; + EXPECT_EQ(sbp_stec_sat_element_integrity_encode(&buf[0], sizeof(buf), + &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + EXPECT_EQ(sbp_stec_sat_element_integrity_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 9), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_stec_sat_element_integrity_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_sat_element_integrity_t t{}; + EXPECT_EQ( + sbp_stec_sat_element_integrity_decode(info.encoded_data, 9, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_sat_element_integrity_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_sat_element_integrity_t t{}; + EXPECT_EQ( + sbp_stec_sat_element_integrity_decode(info.encoded_data, 9, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_stec_sat_element_integrity_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs10, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_sat_element_integrity_t t{}; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_stec_sat_element_integrity_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs11 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs11() { + assign(test_struct_.pco[0], 8405); + + assign(test_struct_.pco[1], -18163); + + assign(test_struct_.pco[2], 4437); + + assign(test_struct_.pcv[0], 56); + + assign(test_struct_.pcv[1], 113); + + assign(test_struct_.pcv[2], 34); + + assign(test_struct_.pcv[3], -79); + + assign(test_struct_.pcv[4], -54); + + assign(test_struct_.pcv[5], -19); + + assign(test_struct_.pcv[6], -78); + + assign(test_struct_.pcv[7], -18); + + assign(test_struct_.pcv[8], -66); + + assign(test_struct_.pcv[9], 74); + + assign(test_struct_.pcv[10], -64); + + assign(test_struct_.pcv[11], -19); + + assign(test_struct_.pcv[12], -90); + + assign(test_struct_.pcv[13], -108); + + assign(test_struct_.pcv[14], -65); + + assign(test_struct_.pcv[15], 122); + + assign(test_struct_.pcv[16], 111); + + assign(test_struct_.pcv[17], 43); + + assign(test_struct_.pcv[18], -35); + + assign(test_struct_.pcv[19], -15); + + assign(test_struct_.pcv[20], 78); + assign(test_struct_.sat_info, 190); + assign(test_struct_.sid.code, 13); + assign(test_struct_.sid.sat, 207); + assign(test_struct_.svn, 29092); + } + + struct TestStructInfo { + sbp_satellite_apc_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_satellite_apc_t test_struct_{}; + uint8_t encoded_data_[32] = { + 207, 13, 190, 164, 113, 213, 32, 13, 185, 85, 17, + 56, 113, 34, 177, 202, 237, 178, 238, 190, 74, 192, + 237, 166, 148, 191, 122, 111, 43, 221, 241, 78, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_satellite_apc_encoded_len(&info.test_struct), 32); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[32]; + EXPECT_EQ(sbp_satellite_apc_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 32); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[32]; + EXPECT_EQ(sbp_satellite_apc_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 32), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[32]; + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_satellite_apc_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_satellite_apc_t t{}; + EXPECT_EQ(sbp_satellite_apc_decode(info.encoded_data, 32, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_satellite_apc_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_satellite_apc_t t{}; + EXPECT_EQ(sbp_satellite_apc_decode(info.encoded_data, 32, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_satellite_apc_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs11, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_satellite_apc_t t{}; + + for (uint8_t i = 0; i < 32; i++) { + EXPECT_EQ(sbp_satellite_apc_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs12 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs12() { + assign(test_struct_.iod_atmo, 76); + assign(test_struct_.num_msgs, 185); + assign(test_struct_.seq_num, 163); + assign(test_struct_.time.tow, 748938257); + assign(test_struct_.time.wn, 61526); + assign(test_struct_.update_interval, 105); + } + + struct TestStructInfo { + sbp_stec_header_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_stec_header_dep_a_t test_struct_{}; + uint8_t encoded_data_[10] = { + 17, 228, 163, 44, 86, 240, 185, 163, 105, 76, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_stec_header_dep_a_encoded_len(&info.test_struct), 10); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[10]; + EXPECT_EQ(sbp_stec_header_dep_a_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + EXPECT_EQ(sbp_stec_header_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 10), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[10]; + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_stec_header_dep_a_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_stec_header_dep_a_t t{}; + EXPECT_EQ(sbp_stec_header_dep_a_decode(info.encoded_data, 10, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_stec_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_stec_header_dep_a_t t{}; + EXPECT_EQ(sbp_stec_header_dep_a_decode(info.encoded_data, 10, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_stec_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs12, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_stec_header_dep_a_t t{}; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_stec_header_dep_a_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs13 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs13() { + assign(test_struct_.iod_atmo, 199); + assign(test_struct_.num_msgs, 50568); + assign(test_struct_.seq_num, 39205); + assign(test_struct_.time.tow, 3185536009); + assign(test_struct_.time.wn, 31680); + assign(test_struct_.tropo_quality_indicator, 135); + assign(test_struct_.update_interval, 215); + } + + struct TestStructInfo { + sbp_gridded_correction_header_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_gridded_correction_header_dep_a_t test_struct_{}; + uint8_t encoded_data_[13] = { + 9, 108, 223, 189, 192, 123, 136, 197, 37, 153, 215, 199, 135, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_gridded_correction_header_dep_a_encoded_len(&info.test_struct), + 13); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[13]; + EXPECT_EQ(sbp_gridded_correction_header_dep_a_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 13); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[13]; + EXPECT_EQ(sbp_gridded_correction_header_dep_a_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 13), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[13]; + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ(sbp_gridded_correction_header_dep_a_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_gridded_correction_header_dep_a_t t{}; + EXPECT_EQ(sbp_gridded_correction_header_dep_a_decode(info.encoded_data, 13, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_gridded_correction_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_gridded_correction_header_dep_a_t t{}; + EXPECT_EQ(sbp_gridded_correction_header_dep_a_decode(info.encoded_data, 13, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_gridded_correction_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs13, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_gridded_correction_header_dep_a_t t{}; + + for (uint8_t i = 0; i < 13; i++) { + EXPECT_EQ(sbp_gridded_correction_header_dep_a_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs14 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs14() { + assign(test_struct_.area_width, 40934); + assign(test_struct_.lat_nw_corner_enc, 38421); + assign(test_struct_.lon_nw_corner_enc, 25699); + assign(test_struct_.num_msgs, 217); + assign(test_struct_.region_size_inverse, 240); + assign(test_struct_.seq_num, 199); + } + + struct TestStructInfo { + sbp_grid_definition_header_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_grid_definition_header_dep_a_t test_struct_{}; + uint8_t encoded_data_[9] = { + 240, 230, 159, 21, 150, 99, 100, 217, 199, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_grid_definition_header_dep_a_encoded_len(&info.test_struct), 9); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[9]; + EXPECT_EQ(sbp_grid_definition_header_dep_a_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + EXPECT_EQ(sbp_grid_definition_header_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 9), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_grid_definition_header_dep_a_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_grid_definition_header_dep_a_t t{}; + EXPECT_EQ( + sbp_grid_definition_header_dep_a_decode(info.encoded_data, 9, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_grid_definition_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_grid_definition_header_dep_a_t t{}; + EXPECT_EQ(sbp_grid_definition_header_dep_a_decode(info.encoded_data, 9, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_grid_definition_header_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs14, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_grid_definition_header_dep_a_t t{}; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_grid_definition_header_dep_a_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs15 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs15() { + assign(test_struct_.clock_bound_mu, 235); + assign(test_struct_.clock_bound_sig, 237); + assign(test_struct_.orb_along_bound_mu, 210); + assign(test_struct_.orb_along_bound_sig, 60); + assign(test_struct_.orb_cross_bound_mu, 61); + assign(test_struct_.orb_cross_bound_sig, 123); + assign(test_struct_.orb_radial_bound_mu, 54); + assign(test_struct_.orb_radial_bound_sig, 231); + assign(test_struct_.sat_id, 243); + } + + struct TestStructInfo { + sbp_orbit_clock_bound_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_orbit_clock_bound_t test_struct_{}; + uint8_t encoded_data_[9] = { + 243, 54, 210, 61, 231, 60, 123, 235, 237, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_orbit_clock_bound_encoded_len(&info.test_struct), 9); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[9]; + EXPECT_EQ(sbp_orbit_clock_bound_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + EXPECT_EQ(sbp_orbit_clock_bound_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 9), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ( + sbp_orbit_clock_bound_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_orbit_clock_bound_t t{}; + EXPECT_EQ(sbp_orbit_clock_bound_decode(info.encoded_data, 9, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_orbit_clock_bound_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_orbit_clock_bound_t t{}; + EXPECT_EQ(sbp_orbit_clock_bound_decode(info.encoded_data, 9, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_orbit_clock_bound_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs15, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_orbit_clock_bound_t t{}; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_orbit_clock_bound_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs16 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs16() { + assign(test_struct_.code_bias_bound_mu, 0); + assign(test_struct_.code_bias_bound_sig, 87); + assign(test_struct_.phase_bias_bound_mu, 0); + assign(test_struct_.phase_bias_bound_sig, 118); + assign(test_struct_.sat_id, 232); + assign(test_struct_.signal_id, 38); + } + + struct TestStructInfo { + sbp_code_phase_biases_sat_sig_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_code_phase_biases_sat_sig_t test_struct_{}; + uint8_t encoded_data_[6] = { + 232, 38, 0, 87, 0, 118, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_code_phase_biases_sat_sig_encoded_len(&info.test_struct), 6); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[6]; + EXPECT_EQ(sbp_code_phase_biases_sat_sig_encode(&buf[0], sizeof(buf), + &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + EXPECT_EQ(sbp_code_phase_biases_sat_sig_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 6), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_code_phase_biases_sat_sig_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_code_phase_biases_sat_sig_t t{}; + EXPECT_EQ( + sbp_code_phase_biases_sat_sig_decode(info.encoded_data, 6, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_code_phase_biases_sat_sig_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_code_phase_biases_sat_sig_t t{}; + EXPECT_EQ( + sbp_code_phase_biases_sat_sig_decode(info.encoded_data, 6, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_code_phase_biases_sat_sig_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs16, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_code_phase_biases_sat_sig_t t{}; + + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ( + sbp_code_phase_biases_sat_sig_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_ssr_ssr_structs17 : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_ssr_ssr_structs17() { + assign(test_struct_.clock_bound_mu_dot, 69); + assign(test_struct_.clock_bound_sig_dot, 63); + assign(test_struct_.orb_along_bound_mu_dot, 112); + assign(test_struct_.orb_along_bound_sig_dot, 99); + assign(test_struct_.orb_cross_bound_mu_dot, 238); + assign(test_struct_.orb_cross_bound_sig_dot, 82); + assign(test_struct_.orb_radial_bound_mu_dot, 108); + assign(test_struct_.orb_radial_bound_sig_dot, 151); + } + + struct TestStructInfo { + sbp_orbit_clock_bound_degradation_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_orbit_clock_bound_degradation_t test_struct_{}; + uint8_t encoded_data_[8] = { + 108, 112, 238, 151, 99, 82, 69, 63, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_orbit_clock_bound_degradation_encoded_len(&info.test_struct), + 8); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[8]; + EXPECT_EQ(sbp_orbit_clock_bound_degradation_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + EXPECT_EQ(sbp_orbit_clock_bound_degradation_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 8), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_orbit_clock_bound_degradation_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_orbit_clock_bound_degradation_t t{}; + EXPECT_EQ(sbp_orbit_clock_bound_degradation_decode(info.encoded_data, 8, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_orbit_clock_bound_degradation_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_orbit_clock_bound_degradation_t t{}; + EXPECT_EQ(sbp_orbit_clock_bound_degradation_decode(info.encoded_data, 8, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_orbit_clock_bound_degradation_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_ssr_ssr_structs17, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_orbit_clock_bound_degradation_t t{}; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_orbit_clock_bound_degradation_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc b/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc new file mode 100644 index 0000000000..b458114b74 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc @@ -0,0 +1,935 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgCsacTelemetry0 : public ::testing::Test { + public: + Testauto_check_sbp_system_MsgCsacTelemetry0() { + assign(test_msg_.id, 105); + + size_t written; + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_set(&test_msg_, "some data", + false, &written)); + EXPECT_EQ(written, strlen("some data")); + EXPECT_EQ(sbp_msg_csac_telemetry_telemetry_encoded_len(&test_msg_), 9); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_csac_telemetry_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_csac_telemetry_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCsacTelemetry, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_csac_telemetry_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCsacTelemetry); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->csac_telemetry, + sizeof(msg->csac_telemetry)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_csac_telemetry_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.csac_telemetry, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCsacTelemetry); + info.sender_id = 43508; + info.preamble = 0x55; + info.crc = 0x5ee5; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_csac_telemetry_t &lesser, + const sbp_msg_csac_telemetry_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_csac_telemetry_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_csac_telemetry_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_csac_telemetry_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_csac_telemetry_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgCsacTelemetry, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCsacTelemetry, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgCsacTelemetry, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgCsacTelemetry, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_csac_telemetry_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { + 85, 4, 255, 244, 169, 10, 105, 115, 111, + 109, 101, 32, 100, 97, 116, 97, 229, 94, + }; + uint8_t encoded_payload_[10] = { + 105, 115, 111, 109, 101, 32, 100, 97, 116, 97, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_csac_telemetry_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgCsacTelemetry, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_csac_telemetry_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCsacTelemetry, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ(sbp_msg_csac_telemetry_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ( + sbp_msg_csac_telemetry_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_csac_telemetry_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgCsacTelemetry, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_t msg{}; + + EXPECT_EQ(sbp_msg_csac_telemetry_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_CSAC_TELEMETRY_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_csac_telemetry_t t{}; return + // sbp_msg_csac_telemetry_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_csac_telemetry_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_csac_telemetry_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCsacTelemetry, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgCsacTelemetry, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCsacTelemetry, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_csac_telemetry_t lesser = info.test_msg; + sbp_msg_csac_telemetry_t greater = info.test_msg; + make_lesser_greater(lesser.id, greater.id); + comparison_tests(lesser, greater); + } + { + sbp_msg_csac_telemetry_t lesser = info.test_msg; + sbp_msg_csac_telemetry_t greater = info.test_msg; + make_lesser_greater(lesser.telemetry, greater.telemetry); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCsacTelemetry); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CSAC_TELEMETRY"); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_csac_telemetry_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_csac_telemetry_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.csac_telemetry, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.csac_telemetry, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCsacTelemetry, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCsacTelemetry, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry + : public Testauto_check_sbp_system_MsgCsacTelemetry0 {}; + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, StringInit) { + sbp_msg_csac_telemetry_t t{}; + sbp_msg_csac_telemetry_telemetry_init(&t); + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, IsValid) { + sbp_msg_csac_telemetry_t t{}; + + size_t written; + EXPECT_TRUE( + sbp_msg_csac_telemetry_telemetry_set(&t, "some data", false, &written)); + EXPECT_EQ(written, strlen("some data")); + EXPECT_EQ(sbp_msg_csac_telemetry_telemetry_encoded_len(&t), 9); + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, SpaceRemaining) { + sbp_msg_csac_telemetry_t t{}; + size_t empty_space_remaining = + sbp_msg_csac_telemetry_telemetry_space_remaining(&t); + + size_t written; + EXPECT_TRUE( + sbp_msg_csac_telemetry_telemetry_set(&t, "some data", false, &written)); + EXPECT_EQ(written, strlen("some data")); + EXPECT_EQ(sbp_msg_csac_telemetry_telemetry_encoded_len(&t), 9); + size_t assigned_space_remaining = + sbp_msg_csac_telemetry_telemetry_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_set_raw( + &t, info.test_msg.telemetry.data, + sbp_msg_csac_telemetry_telemetry_strlen(&info.test_msg), false, + &nwritten)); + EXPECT_EQ(sbp_msg_csac_telemetry_telemetry_encoded_len(&info.test_msg), + sbp_msg_csac_telemetry_telemetry_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, Set) { + sbp_msg_csac_telemetry_t t{}; + size_t nwritten{}; + const char *text = "some data"; + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, Printf) { + sbp_msg_csac_telemetry_t t{}; + size_t nwritten{}; + const char *text = "some data"; + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_printf(&t, false, &nwritten, + "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, Vprintf) { + sbp_msg_csac_telemetry_t t{}; + size_t nwritten{}; + const char *text = "some data"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_csac_telemetry_telemetry_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, AppendPrintf) { + sbp_msg_csac_telemetry_t t{}; + size_t nwritten{}; + char part1[] = "some data"; + char part2[] = "some data"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), "some data"); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetry0_telemetry, AppendVprintf) { + sbp_msg_csac_telemetry_t t{}; + size_t nwritten{}; + char part1[] = "some data"; + char part2[] = "some data"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_csac_telemetry_telemetry_printf(&t, false, &nwritten, + "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_csac_telemetry_telemetry_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_csac_telemetry_telemetry_get(&t), "some data"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc b/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc new file mode 100644 index 0000000000..5b404466cc --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc @@ -0,0 +1,966 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgCsacTelemetryLabels0 + : public ::testing::Test { + public: + Testauto_check_sbp_system_MsgCsacTelemetryLabels0() { + assign(test_msg_.id, 186); + + size_t written; + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_set( + &test_msg_, "some labels", false, &written)); + EXPECT_EQ(written, strlen("some labels")); + EXPECT_EQ( + sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len(&test_msg_), + 11); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_csac_telemetry_labels_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_csac_telemetry_labels_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgCsacTelemetryLabels, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_csac_telemetry_labels_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgCsacTelemetryLabels); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->csac_telemetry_labels, + sizeof(msg->csac_telemetry_labels)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_csac_telemetry_labels_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.csac_telemetry_labels, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgCsacTelemetryLabels); + info.sender_id = 51291; + info.preamble = 0x55; + info.crc = 0xec56; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 12; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_csac_telemetry_labels_t &lesser, + const sbp_msg_csac_telemetry_labels_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_csac_telemetry_labels_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_csac_telemetry_labels_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_csac_telemetry_labels_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgCsacTelemetryLabels, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgCsacTelemetryLabels, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgCsacTelemetryLabels, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgCsacTelemetryLabels, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_csac_telemetry_labels_t test_msg_{}; + uint8_t encoded_frame_[12 + 8] = { + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, + 101, 32, 108, 97, 98, 101, 108, 115, 86, 236, + }; + uint8_t encoded_payload_[12] = { + 186, 115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_csac_telemetry_labels_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgCsacTelemetryLabels, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ( + sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgCsacTelemetryLabels, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_msg_csac_telemetry_labels_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_labels_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgCsacTelemetryLabels, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_labels_t msg{}; + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_labels_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_CSAC_TELEMETRY_LABELS_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_csac_telemetry_labels_t t{}; + // return sbp_msg_csac_telemetry_labels_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_csac_telemetry_labels_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCsacTelemetryLabels, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgCsacTelemetryLabels, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgCsacTelemetryLabels, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_csac_telemetry_labels_t lesser = info.test_msg; + sbp_msg_csac_telemetry_labels_t greater = info.test_msg; + make_lesser_greater(lesser.id, greater.id); + comparison_tests(lesser, greater); + } + { + sbp_msg_csac_telemetry_labels_t lesser = info.test_msg; + sbp_msg_csac_telemetry_labels_t greater = info.test_msg; + make_lesser_greater(lesser.telemetry_labels, greater.telemetry_labels); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgCsacTelemetryLabels); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_CSAC_TELEMETRY_LABELS"); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_csac_telemetry_labels_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_csac_telemetry_labels_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.csac_telemetry_labels, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.csac_telemetry_labels, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[12]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 12), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_labels_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 12); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgCsacTelemetryLabels, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgCsacTelemetryLabels, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels + : public Testauto_check_sbp_system_MsgCsacTelemetryLabels0 {}; + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + StringInit) { + sbp_msg_csac_telemetry_labels_t t{}; + sbp_msg_csac_telemetry_labels_telemetry_labels_init(&t); + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + IsValid) { + sbp_msg_csac_telemetry_labels_t t{}; + + size_t written; + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_set( + &t, "some labels", false, &written)); + EXPECT_EQ(written, strlen("some labels")); + EXPECT_EQ(sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len(&t), 11); + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + SpaceRemaining) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t empty_space_remaining = + sbp_msg_csac_telemetry_labels_telemetry_labels_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_set( + &t, "some labels", false, &written)); + EXPECT_EQ(written, strlen("some labels")); + EXPECT_EQ(sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len(&t), 11); + size_t assigned_space_remaining = + sbp_msg_csac_telemetry_labels_telemetry_labels_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_csac_telemetry_labels_t t{}; + + size_t nwritten{}; + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_set_raw( + &t, info.test_msg.telemetry_labels.data, + sbp_msg_csac_telemetry_labels_telemetry_labels_strlen(&info.test_msg), + false, &nwritten)); + EXPECT_EQ(sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len( + &info.test_msg), + sbp_msg_csac_telemetry_labels_telemetry_labels_encoded_len(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + Set) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t nwritten{}; + const char *text = "some labels"; + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_set( + &t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + Printf) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t nwritten{}; + const char *text = "some labels"; + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_printf( + &t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + Vprintf) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t nwritten{}; + const char *text = "some labels"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_csac_telemetry_labels_telemetry_labels_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + AppendPrintf) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t nwritten{}; + char part1[] = "some labels"; + char part2[] = "some labels"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), + &part1[0]); + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_append_printf( + &t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), + "some labels"); +} + +TEST_F(Testauto_check_sbp_system_MsgCsacTelemetryLabels0_telemetry_labels, + AppendVprintf) { + sbp_msg_csac_telemetry_labels_t t{}; + size_t nwritten{}; + char part1[] = "some labels"; + char part2[] = "some labels"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_csac_telemetry_labels_telemetry_labels_printf( + &t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), + &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_csac_telemetry_labels_telemetry_labels_append_vprintf( + &t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_csac_telemetry_labels_telemetry_labels_get(&t), + "some labels"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgDgnssStatus.cc b/c/test/cpp/auto_check_sbp_system_MsgDgnssStatus.cc index 2402115447..82b6cd18af 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgDgnssStatus.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgDgnssStatus.cc @@ -16,103 +16,923 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgDgnssStatus0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgDgnssStatus0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgDgnssStatus0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgDgnssStatus0() { + assign(test_msg_.flags, 0); + assign(test_msg_.latency, 50); + assign(test_msg_.num_signals, 12); + + size_t written; + EXPECT_TRUE(sbp_msg_dgnss_status_source_set(&test_msg_, "Skylark", false, + &written)); + EXPECT_EQ(written, strlen("Skylark")); + EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&test_msg_), 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_dgnss_status_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_dgnss_status_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgDgnssStatus, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_dgnss_status_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgDgnssStatus); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->dgnss_status, + sizeof(msg->dgnss_status)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_dgnss_status_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.dgnss_status, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgDgnssStatus); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x1ca; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 11; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_dgnss_status_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_dgnss_status_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_dgnss_status_t &lesser, + const sbp_msg_dgnss_status_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_dgnss_status_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_dgnss_status_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_dgnss_status_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_dgnss_status_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgDgnssStatus, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgDgnssStatus, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgDgnssStatus, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgDgnssStatus, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_system_MsgDgnssStatus0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_dgnss_status_t test_msg_{}; + uint8_t encoded_frame_[11 + 8] = { 85, 2, 255, 66, 0, 11, 0, 50, 0, 12, 83, 107, 121, 108, 97, 114, 107, 202, 1, }; + uint8_t encoded_payload_[11] = { + 0, 50, 0, 12, 83, 107, 121, 108, 97, 114, 107, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_dgnss_status_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgDgnssStatus, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_dgnss_status_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgDgnssStatus, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + EXPECT_EQ(sbp_msg_dgnss_status_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + + for (uint8_t i = 0; i < 11; i++) { + EXPECT_EQ(sbp_msg_dgnss_status_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dgnss_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_dgnss_status_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgDgnssStatus, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_dgnss_status_t msg{}; + + EXPECT_EQ(sbp_msg_dgnss_status_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_dgnss_status_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = SBP_MSG_DGNSS_STATUS_ENCODED_OVERHEAD; + // size_t overhead = []()->size_t{sbp_msg_dgnss_status_t t{}; return + // sbp_msg_dgnss_status_encoded_len(&t); }(); + if (i >= overhead) { + expected_return = SBP_OK; + } + + EXPECT_EQ( + sbp_msg_dgnss_status_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} - sbp_msg_dgnss_status_t test_msg{}; - test_msg.flags = 0; - test_msg.latency = 50; - test_msg.num_signals = 12; +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_dgnss_status_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDgnssStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgDgnssStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgDgnssStatus, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_dgnss_status_t lesser = info.test_msg; + sbp_msg_dgnss_status_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_dgnss_status_t lesser = info.test_msg; + sbp_msg_dgnss_status_t greater = info.test_msg; + make_lesser_greater(lesser.latency, greater.latency); + comparison_tests(lesser, greater); + } + { + sbp_msg_dgnss_status_t lesser = info.test_msg; + sbp_msg_dgnss_status_t greater = info.test_msg; + make_lesser_greater(lesser.num_signals, greater.num_signals); + comparison_tests(lesser, greater); + } + { + sbp_msg_dgnss_status_t lesser = info.test_msg; + sbp_msg_dgnss_status_t greater = info.test_msg; + make_lesser_greater(lesser.source, greater.source); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgDgnssStatus); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_DGNSS_STATUS"); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_dgnss_status_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_dgnss_status_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.dgnss_status, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.dgnss_status, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[11]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 11); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 11), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_dgnss_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 11); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgDgnssStatus, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgDgnssStatus, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_system_MsgDgnssStatus0_source + : public Testauto_check_sbp_system_MsgDgnssStatus0 {}; + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, StringInit) { + sbp_msg_dgnss_status_t t{}; + sbp_msg_dgnss_status_source_init(&t); + EXPECT_TRUE(sbp_msg_dgnss_status_source_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, IsValid) { + sbp_msg_dgnss_status_t t{}; size_t written; - EXPECT_TRUE( - sbp_msg_dgnss_status_source_set(&test_msg, "Skylark", false, &written)); + EXPECT_TRUE(sbp_msg_dgnss_status_source_set(&t, "Skylark", false, &written)); + EXPECT_EQ(written, strlen("Skylark")); + EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&t), 7); + EXPECT_TRUE(sbp_msg_dgnss_status_source_valid(&t)); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, SpaceRemaining) { + sbp_msg_dgnss_status_t t{}; + size_t empty_space_remaining = + sbp_msg_dgnss_status_source_space_remaining(&t); + + size_t written; + EXPECT_TRUE(sbp_msg_dgnss_status_source_set(&t, "Skylark", false, &written)); EXPECT_EQ(written, strlen("Skylark")); - EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&test_msg), 7); + EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&t), 7); + size_t assigned_space_remaining = + sbp_msg_dgnss_status_source_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} - EXPECT_EQ(send_message(66, test_msg), SBP_OK); +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, SetRaw) { + auto info = get_test_msg_info(); + sbp_msg_dgnss_status_t t{}; - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + size_t nwritten{}; - while (dummy_rd_ < dummy_wr_) { - process(); - } + EXPECT_TRUE(sbp_msg_dgnss_status_source_set_raw( + &t, info.test_msg.source.data, + sbp_msg_dgnss_status_source_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&info.test_msg), + sbp_msg_dgnss_status_source_encoded_len(&t)); +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.latency, 50) - << "incorrect value for last_msg_.latency, expected 50, is " - << last_msg_.latency; - EXPECT_EQ(last_msg_.num_signals, 12) - << "incorrect value for last_msg_.num_signals, expected 12, is " - << last_msg_.num_signals; +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, Set) { + sbp_msg_dgnss_status_t t{}; + size_t nwritten{}; + const char *text = "Skylark"; - EXPECT_EQ(sbp_msg_dgnss_status_source_encoded_len(&last_msg_), 7); - EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&last_msg_), "Skylark"); + EXPECT_TRUE(sbp_msg_dgnss_status_source_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), text); } + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, Printf) { + sbp_msg_dgnss_status_t t{}; + size_t nwritten{}; + const char *text = "Skylark"; + + EXPECT_TRUE( + sbp_msg_dgnss_status_source_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, Vprintf) { + sbp_msg_dgnss_status_t t{}; + size_t nwritten{}; + const char *text = "Skylark"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = + sbp_msg_dgnss_status_source_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), text); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, AppendPrintf) { + sbp_msg_dgnss_status_t t{}; + size_t nwritten{}; + char part1[] = "Skylark"; + char part2[] = "Skylark"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_dgnss_status_source_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), &part1[0]); + + EXPECT_TRUE(sbp_msg_dgnss_status_source_append_printf(&t, false, &nwritten, + "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), "Skylark"); +} + +TEST_F(Testauto_check_sbp_system_MsgDgnssStatus0_source, AppendVprintf) { + sbp_msg_dgnss_status_t t{}; + size_t nwritten{}; + char part1[] = "Skylark"; + char part2[] = "Skylark"; + + part1[1] = 0; + + EXPECT_TRUE(sbp_msg_dgnss_status_source_printf(&t, false, &nwritten, "%s", + &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = sbp_msg_dgnss_status_source_append_vprintf(&t, false, &nwritten, + format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ(sbp_msg_dgnss_status_source_get(&t), "Skylark"); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc b/c/test/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc new file mode 100644 index 0000000000..888d51750d --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc @@ -0,0 +1,803 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgGnssTimeOffset0 : public ::testing::Test { + public: + Testauto_check_sbp_system_MsgGnssTimeOffset0() { + assign(test_msg_.flags, 221); + assign(test_msg_.microseconds, 9494); + assign(test_msg_.milliseconds, 1728664402); + assign(test_msg_.weeks, 14857); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_gnss_time_offset_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_gnss_time_offset_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGnssTimeOffset, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_gnss_time_offset_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGnssTimeOffset); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->gnss_time_offset, + sizeof(msg->gnss_time_offset)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_gnss_time_offset_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.gnss_time_offset, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGnssTimeOffset); + info.sender_id = 3862; + info.preamble = 0x55; + info.crc = 0x6454; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_gnss_time_offset_t &lesser, + const sbp_msg_gnss_time_offset_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_gnss_time_offset_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_gnss_time_offset_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_gnss_time_offset_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_gnss_time_offset_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGnssTimeOffset, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgGnssTimeOffset, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgGnssTimeOffset, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgGnssTimeOffset, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_gnss_time_offset_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + }; + uint8_t encoded_payload_[9] = { + 9, 58, 82, 83, 9, 103, 22, 37, 221, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_gnss_time_offset_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgGnssTimeOffset, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_gnss_time_offset_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGnssTimeOffset, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ(sbp_msg_gnss_time_offset_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ( + sbp_msg_gnss_time_offset_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gnss_time_offset_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_gnss_time_offset_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGnssTimeOffset, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_gnss_time_offset_t msg{}; + + EXPECT_EQ(sbp_msg_gnss_time_offset_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_gnss_time_offset_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_gnss_time_offset_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_gnss_time_offset_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGnssTimeOffset, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGnssTimeOffset, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGnssTimeOffset, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_gnss_time_offset_t lesser = info.test_msg; + sbp_msg_gnss_time_offset_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_time_offset_t lesser = info.test_msg; + sbp_msg_gnss_time_offset_t greater = info.test_msg; + make_lesser_greater(lesser.microseconds, greater.microseconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_time_offset_t lesser = info.test_msg; + sbp_msg_gnss_time_offset_t greater = info.test_msg; + make_lesser_greater(lesser.milliseconds, greater.milliseconds); + comparison_tests(lesser, greater); + } + { + sbp_msg_gnss_time_offset_t lesser = info.test_msg; + sbp_msg_gnss_time_offset_t greater = info.test_msg; + make_lesser_greater(lesser.weeks, greater.weeks); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgGnssTimeOffset); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GNSS_TIME_OFFSET"); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_gnss_time_offset_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_gnss_time_offset_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.gnss_time_offset, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.gnss_time_offset, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_gnss_time_offset_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGnssTimeOffset, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGnssTimeOffset0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGnssTimeOffset, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgGroupMeta.cc b/c/test/cpp/auto_check_sbp_system_MsgGroupMeta.cc index 492da6ceb0..c6dafeae00 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgGroupMeta.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgGroupMeta.cc @@ -16,267 +16,1700 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgGroupMeta0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgGroupMeta0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgGroupMeta0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgGroupMeta0() { + assign(test_msg_.flags, 2); + assign(test_msg_.group_id, 1); + + assign(test_msg_.group_msgs[0], 65290); + + assign(test_msg_.group_msgs[1], 522); + + assign(test_msg_.group_msgs[2], 65282); + assign(test_msg_.n_group_msgs, 3); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_group_meta_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_group_meta_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGroupMeta, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_group_meta_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGroupMeta); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->group_meta, sizeof(msg->group_meta)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_group_meta_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.group_meta, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGroupMeta); + info.sender_id = 61166; + info.preamble = 0x55; + info.crc = 0xe02; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_group_meta_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_group_meta_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_group_meta_t &lesser, + const sbp_msg_group_meta_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_group_meta_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_group_meta_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_group_meta_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_group_meta_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgGroupMeta0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_group_meta_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { 85, 10, 255, 238, 238, 9, 1, 2, 3, 10, 255, 10, 2, 2, 255, 2, 14, }; + uint8_t encoded_payload_[9] = { + 1, 2, 3, 10, 255, 10, 2, 2, 255, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_group_meta_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGroupMeta, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_group_meta_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGroupMeta, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ( + sbp_msg_group_meta_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_msg_group_meta_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_group_meta_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGroupMeta, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + + EXPECT_EQ(sbp_msg_group_meta_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_group_meta_t t{}; + return sbp_msg_group_meta_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_group_meta_t t{}; + t.n_group_msgs = 1; + return sbp_msg_group_meta_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_group_meta_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - sbp_msg_group_meta_t test_msg{}; - test_msg.flags = 2; - test_msg.group_id = 1; - - test_msg.group_msgs[0] = 65290; - - test_msg.group_msgs[1] = 522; - - test_msg.group_msgs[2] = 65282; - test_msg.n_group_msgs = 3; - - EXPECT_EQ(send_message(61166, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 61166); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 2) - << "incorrect value for last_msg_.flags, expected 2, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.group_id, 1) - << "incorrect value for last_msg_.group_id, expected 1, is " - << last_msg_.group_id; - EXPECT_EQ(last_msg_.group_msgs[0], 65290) - << "incorrect value for last_msg_.group_msgs[0], expected 65290, is " - << last_msg_.group_msgs[0]; - EXPECT_EQ(last_msg_.group_msgs[1], 522) - << "incorrect value for last_msg_.group_msgs[1], expected 522, is " - << last_msg_.group_msgs[1]; - EXPECT_EQ(last_msg_.group_msgs[2], 65282) - << "incorrect value for last_msg_.group_msgs[2], expected 65282, is " - << last_msg_.group_msgs[2]; - EXPECT_EQ(last_msg_.n_group_msgs, 3) - << "incorrect value for last_msg_.n_group_msgs, expected 3, is " - << last_msg_.n_group_msgs; -} -class Test_auto_check_sbp_system_MsgGroupMeta1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_group_meta_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_id, greater.group_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[0], greater.group_msgs[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[1], greater.group_msgs[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[2], greater.group_msgs[2]); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.n_group_msgs, greater.n_group_msgs); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGroupMeta); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GROUP_META"); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_group_meta_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_group_meta_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.group_meta, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.group_meta, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGroupMeta, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGroupMeta, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_system_MsgGroupMeta1 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgGroupMeta1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgGroupMeta1() { + assign(test_msg_.flags, 1); + assign(test_msg_.group_id, 1); + + assign(test_msg_.group_msgs[0], 258); + + assign(test_msg_.group_msgs[1], 259); + + assign(test_msg_.group_msgs[2], 522); + + assign(test_msg_.group_msgs[3], 529); + + assign(test_msg_.group_msgs[4], 521); + + assign(test_msg_.group_msgs[5], 532); + + assign(test_msg_.group_msgs[6], 526); + + assign(test_msg_.group_msgs[7], 530); + + assign(test_msg_.group_msgs[8], 525); + + assign(test_msg_.group_msgs[9], 533); + + assign(test_msg_.group_msgs[10], 545); + + assign(test_msg_.group_msgs[11], 65283); + + assign(test_msg_.group_msgs[12], 65286); + + assign(test_msg_.group_msgs[13], 65294); + assign(test_msg_.n_group_msgs, 14); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_group_meta_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_group_meta_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgGroupMeta, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_group_meta_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgGroupMeta); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->group_meta, sizeof(msg->group_meta)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_group_meta_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.group_meta, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgGroupMeta); + info.sender_id = 789; + info.preamble = 0x55; + info.crc = 0x9a52; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 31; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_group_meta_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_group_meta_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_group_meta_t &lesser, + const sbp_msg_group_meta_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_group_meta_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_group_meta_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_group_meta_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_group_meta_cmp(&greater, &lesser), 0); -TEST_F(Test_auto_check_sbp_system_MsgGroupMeta1, Test) { - uint8_t encoded_frame[] = { + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgGroupMeta, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_group_meta_t test_msg_{}; + uint8_t encoded_frame_[31 + 8] = { 85, 10, 255, 21, 3, 31, 1, 1, 14, 2, 1, 3, 1, 10, 2, 17, 2, 9, 2, 20, 2, 14, 2, 18, 2, 13, 2, 21, 2, 33, 2, 3, 255, 6, 255, 14, 255, 82, 154, }; + uint8_t encoded_payload_[31] = { + 1, 1, 14, 2, 1, 3, 1, 10, 2, 17, 2, 9, 2, 20, 2, 14, + 2, 18, 2, 13, 2, 21, 2, 33, 2, 3, 255, 6, 255, 14, 255, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_group_meta_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgGroupMeta, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_group_meta_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgGroupMeta, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + EXPECT_EQ( + sbp_msg_group_meta_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + + for (uint8_t i = 0; i < 31; i++) { + EXPECT_EQ(sbp_msg_group_meta_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_group_meta_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgGroupMeta, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + + EXPECT_EQ(sbp_msg_group_meta_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_group_meta_t t{}; + return sbp_msg_group_meta_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_group_meta_t t{}; + t.n_group_msgs = 1; + return sbp_msg_group_meta_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_group_meta_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_group_meta_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgGroupMeta, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_id, greater.group_id); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[0], greater.group_msgs[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[1], greater.group_msgs[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[2], greater.group_msgs[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[3], greater.group_msgs[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[4], greater.group_msgs[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[5], greater.group_msgs[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[6], greater.group_msgs[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[7], greater.group_msgs[7]); + comparison_tests(lesser, greater); + } - sbp_msg_group_meta_t test_msg{}; - test_msg.flags = 1; - test_msg.group_id = 1; - - test_msg.group_msgs[0] = 258; - - test_msg.group_msgs[1] = 259; - - test_msg.group_msgs[2] = 522; - - test_msg.group_msgs[3] = 529; - - test_msg.group_msgs[4] = 521; - - test_msg.group_msgs[5] = 532; - - test_msg.group_msgs[6] = 526; - - test_msg.group_msgs[7] = 530; - - test_msg.group_msgs[8] = 525; - - test_msg.group_msgs[9] = 533; - - test_msg.group_msgs[10] = 545; - - test_msg.group_msgs[11] = 65283; - - test_msg.group_msgs[12] = 65286; - - test_msg.group_msgs[13] = 65294; - test_msg.n_group_msgs = 14; - - EXPECT_EQ(send_message(789, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 789); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.group_id, 1) - << "incorrect value for last_msg_.group_id, expected 1, is " - << last_msg_.group_id; - EXPECT_EQ(last_msg_.group_msgs[0], 258) - << "incorrect value for last_msg_.group_msgs[0], expected 258, is " - << last_msg_.group_msgs[0]; - EXPECT_EQ(last_msg_.group_msgs[1], 259) - << "incorrect value for last_msg_.group_msgs[1], expected 259, is " - << last_msg_.group_msgs[1]; - EXPECT_EQ(last_msg_.group_msgs[2], 522) - << "incorrect value for last_msg_.group_msgs[2], expected 522, is " - << last_msg_.group_msgs[2]; - EXPECT_EQ(last_msg_.group_msgs[3], 529) - << "incorrect value for last_msg_.group_msgs[3], expected 529, is " - << last_msg_.group_msgs[3]; - EXPECT_EQ(last_msg_.group_msgs[4], 521) - << "incorrect value for last_msg_.group_msgs[4], expected 521, is " - << last_msg_.group_msgs[4]; - EXPECT_EQ(last_msg_.group_msgs[5], 532) - << "incorrect value for last_msg_.group_msgs[5], expected 532, is " - << last_msg_.group_msgs[5]; - EXPECT_EQ(last_msg_.group_msgs[6], 526) - << "incorrect value for last_msg_.group_msgs[6], expected 526, is " - << last_msg_.group_msgs[6]; - EXPECT_EQ(last_msg_.group_msgs[7], 530) - << "incorrect value for last_msg_.group_msgs[7], expected 530, is " - << last_msg_.group_msgs[7]; - EXPECT_EQ(last_msg_.group_msgs[8], 525) - << "incorrect value for last_msg_.group_msgs[8], expected 525, is " - << last_msg_.group_msgs[8]; - EXPECT_EQ(last_msg_.group_msgs[9], 533) - << "incorrect value for last_msg_.group_msgs[9], expected 533, is " - << last_msg_.group_msgs[9]; - EXPECT_EQ(last_msg_.group_msgs[10], 545) - << "incorrect value for last_msg_.group_msgs[10], expected 545, is " - << last_msg_.group_msgs[10]; - EXPECT_EQ(last_msg_.group_msgs[11], 65283) - << "incorrect value for last_msg_.group_msgs[11], expected 65283, is " - << last_msg_.group_msgs[11]; - EXPECT_EQ(last_msg_.group_msgs[12], 65286) - << "incorrect value for last_msg_.group_msgs[12], expected 65286, is " - << last_msg_.group_msgs[12]; - EXPECT_EQ(last_msg_.group_msgs[13], 65294) - << "incorrect value for last_msg_.group_msgs[13], expected 65294, is " - << last_msg_.group_msgs[13]; - EXPECT_EQ(last_msg_.n_group_msgs, 14) - << "incorrect value for last_msg_.n_group_msgs, expected 14, is " - << last_msg_.n_group_msgs; + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[8], greater.group_msgs[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[9], greater.group_msgs[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[10], greater.group_msgs[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[11], greater.group_msgs[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[12], greater.group_msgs[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.group_msgs[13], greater.group_msgs[13]); + comparison_tests(lesser, greater); + } + { + sbp_msg_group_meta_t lesser = info.test_msg; + sbp_msg_group_meta_t greater = info.test_msg; + make_lesser_greater(lesser.n_group_msgs, greater.n_group_msgs); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgGroupMeta); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_GROUP_META"); } + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_group_meta_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_group_meta_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.group_meta, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.group_meta, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[31]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 31); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 31), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_group_meta_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 31); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgGroupMeta, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgGroupMeta1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgGroupMeta, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgHeartbeat.cc b/c/test/cpp/auto_check_sbp_system_MsgHeartbeat.cc index ff8cfc339b..f545d744d4 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgHeartbeat.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgHeartbeat.cc @@ -16,164 +16,1484 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgHeartbeat0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgHeartbeat0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgHeartbeat0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgHeartbeat0() { assign(test_msg_.flags, 12800); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_heartbeat_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_heartbeat_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgHeartbeat, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_heartbeat_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgHeartbeat); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->heartbeat, sizeof(msg->heartbeat)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_heartbeat_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.heartbeat, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgHeartbeat); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xd8f9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_heartbeat_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_heartbeat_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_heartbeat_t &lesser, + const sbp_msg_heartbeat_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_heartbeat_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_heartbeat_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_heartbeat_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_heartbeat_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgHeartbeat0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_heartbeat_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 255, 255, 246, 215, 4, 0, 50, 0, 0, 249, 216, }; + uint8_t encoded_payload_[4] = { + 0, + 50, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_heartbeat_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgHeartbeat, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_heartbeat_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgHeartbeat, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_heartbeat_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_heartbeat_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_heartbeat_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgHeartbeat, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + + EXPECT_EQ(sbp_msg_heartbeat_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_heartbeat_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - sbp_msg_heartbeat_t test_msg{}; - test_msg.flags = 12800; +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - while (dummy_rd_ < dummy_wr_) { - process(); + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 12800) - << "incorrect value for last_msg_.flags, expected 12800, is " - << last_msg_.flags; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_heartbeat_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_heartbeat_t lesser = info.test_msg; + sbp_msg_heartbeat_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgHeartbeat); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_HEARTBEAT"); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_heartbeat_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_heartbeat_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.heartbeat, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.heartbeat, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgHeartbeat, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgHeartbeat, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } -class Test_auto_check_sbp_system_MsgHeartbeat1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + +class Testauto_check_sbp_system_MsgHeartbeat1 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgHeartbeat1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgHeartbeat1() { assign(test_msg_.flags, 0); } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_heartbeat_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_heartbeat_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgHeartbeat, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_heartbeat_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgHeartbeat); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->heartbeat, sizeof(msg->heartbeat)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_heartbeat_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.heartbeat, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgHeartbeat); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x3942; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_heartbeat_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_heartbeat_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_heartbeat_t &lesser, + const sbp_msg_heartbeat_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_heartbeat_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_heartbeat_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_heartbeat_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_heartbeat_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgHeartbeat, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgHeartbeat1, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_heartbeat_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 255, 255, 195, 4, 4, 0, 0, 0, 0, 66, 57, }; + uint8_t encoded_payload_[4] = { + 0, + 0, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_heartbeat_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgHeartbeat, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - sbp_msg_heartbeat_t test_msg{}; - test_msg.flags = 0; + EXPECT_EQ(sbp_msg_heartbeat_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgHeartbeat, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ( + sbp_msg_heartbeat_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_heartbeat_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_heartbeat_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgHeartbeat, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); } + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + + EXPECT_EQ(sbp_msg_heartbeat_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_heartbeat_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_heartbeat_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgHeartbeat, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_heartbeat_t lesser = info.test_msg; + sbp_msg_heartbeat_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgHeartbeat); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_HEARTBEAT"); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_heartbeat_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_heartbeat_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.heartbeat, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.heartbeat, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_heartbeat_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgHeartbeat, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgHeartbeat1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgHeartbeat, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgInsStatus.cc b/c/test/cpp/auto_check_sbp_system_MsgInsStatus.cc index c18285413a..a0b6a370fa 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgInsStatus.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgInsStatus.cc @@ -16,85 +16,753 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgInsStatus0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgInsStatus0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgInsStatus0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgInsStatus0() { + assign(test_msg_.flags, 536870921); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ins_status_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ins_status_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgInsStatus, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ins_status_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgInsStatus); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ins_status, sizeof(msg->ins_status)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ins_status_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ins_status, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgInsStatus); + info.sender_id = 789; + info.preamble = 0x55; + info.crc = 0x6724; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ins_status_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ins_status_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ins_status_t &lesser, + const sbp_msg_ins_status_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ins_status_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ins_status_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ins_status_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ins_status_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgInsStatus, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgInsStatus, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgInsStatus, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgInsStatus, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgInsStatus0, Test) { - uint8_t encoded_frame[] = { + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ins_status_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 3, 255, 21, 3, 4, 9, 0, 0, 32, 36, 103, }; + uint8_t encoded_payload_[4] = { + 9, + 0, + 0, + 32, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ins_status_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgInsStatus, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ins_status_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgInsStatus, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_ins_status_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_ins_status_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ins_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ins_status_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgInsStatus, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ins_status_t msg{}; + + EXPECT_EQ(sbp_msg_ins_status_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ins_status_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_ins_status_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ins_status_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgInsStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_ins_status_t test_msg{}; - test_msg.flags = 536870921; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(send_message(789, test_msg), SBP_OK); + EXPECT_NE(sbp_message_send(&state, SbpMsgInsStatus, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - while (dummy_rd_ < dummy_wr_) { - process(); + EXPECT_EQ(sbp_message_send(&state, SbpMsgInsStatus, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ins_status_t lesser = info.test_msg; + sbp_msg_ins_status_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); } +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgInsStatus); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_INS_STATUS"); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ins_status_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ins_status_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ins_status, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ins_status, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 789); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 536870921) - << "incorrect value for last_msg_.flags, expected 536870921, is " - << last_msg_.flags; + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); } + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ins_status_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgInsStatus, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsStatus0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgInsStatus, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgInsUpdates.cc b/c/test/cpp/auto_check_sbp_system_MsgInsUpdates.cc index 52745133bc..50b4124b51 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgInsUpdates.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgInsUpdates.cc @@ -16,108 +16,794 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgInsUpdates0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgInsUpdates0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgInsUpdates0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgInsUpdates0() { + assign(test_msg_.gnsspos, 0); + assign(test_msg_.gnssvel, 0); + assign(test_msg_.nhc, 0); + assign(test_msg_.speed, 0); + assign(test_msg_.tow, 504489300); + assign(test_msg_.wheelticks, 0); + assign(test_msg_.zerovel, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_ins_updates_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_ins_updates_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgInsUpdates, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_ins_updates_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgInsUpdates); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->ins_updates, sizeof(msg->ins_updates)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_ins_updates_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.ins_updates, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgInsUpdates); + info.sender_id = 789; + info.preamble = 0x55; + info.crc = 0x3f51; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 10; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_ins_updates_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_ins_updates_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_ins_updates_t &lesser, + const sbp_msg_ins_updates_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_ins_updates_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_ins_updates_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_ins_updates_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_ins_updates_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgInsUpdates, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgInsUpdates, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgInsUpdates, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgInsUpdates, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_system_MsgInsUpdates0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_ins_updates_t test_msg_{}; + uint8_t encoded_frame_[10 + 8] = { 85, 6, 255, 21, 3, 10, 84, 229, 17, 30, 0, 0, 0, 0, 0, 0, 81, 63, }; + uint8_t encoded_payload_[10] = { + 84, 229, 17, 30, 0, 0, 0, 0, 0, 0, + }; +}; - sbp_msg_ins_updates_t test_msg{}; - test_msg.gnsspos = 0; - test_msg.gnssvel = 0; - test_msg.nhc = 0; - test_msg.speed = 0; - test_msg.tow = 504489300; - test_msg.wheelticks = 0; - test_msg.zerovel = 0; - - EXPECT_EQ(send_message(789, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 789); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.gnsspos, 0) - << "incorrect value for last_msg_.gnsspos, expected 0, is " - << last_msg_.gnsspos; - EXPECT_EQ(last_msg_.gnssvel, 0) - << "incorrect value for last_msg_.gnssvel, expected 0, is " - << last_msg_.gnssvel; - EXPECT_EQ(last_msg_.nhc, 0) - << "incorrect value for last_msg_.nhc, expected 0, is " << last_msg_.nhc; - EXPECT_EQ(last_msg_.speed, 0) - << "incorrect value for last_msg_.speed, expected 0, is " - << last_msg_.speed; - EXPECT_EQ(last_msg_.tow, 504489300) - << "incorrect value for last_msg_.tow, expected 504489300, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wheelticks, 0) - << "incorrect value for last_msg_.wheelticks, expected 0, is " - << last_msg_.wheelticks; - EXPECT_EQ(last_msg_.zerovel, 0) - << "incorrect value for last_msg_.zerovel, expected 0, is " - << last_msg_.zerovel; +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_ins_updates_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgInsUpdates, &info.test_msg_wrapped), + info.payload_len); } + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_ins_updates_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgInsUpdates, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + EXPECT_EQ( + sbp_msg_ins_updates_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + + for (uint8_t i = 0; i < 10; i++) { + EXPECT_EQ(sbp_msg_ins_updates_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ins_updates_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_ins_updates_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgInsUpdates, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_ins_updates_t msg{}; + + EXPECT_EQ(sbp_msg_ins_updates_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_ins_updates_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_ins_updates_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_ins_updates_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgInsUpdates, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgInsUpdates, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgInsUpdates, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.gnsspos, greater.gnsspos); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.gnssvel, greater.gnssvel); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.nhc, greater.nhc); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.speed, greater.speed); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.wheelticks, greater.wheelticks); + comparison_tests(lesser, greater); + } + { + sbp_msg_ins_updates_t lesser = info.test_msg; + sbp_msg_ins_updates_t greater = info.test_msg; + make_lesser_greater(lesser.zerovel, greater.zerovel); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgInsUpdates); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_INS_UPDATES"); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_ins_updates_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_ins_updates_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.ins_updates, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.ins_updates, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[10]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 10); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 10), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_ins_updates_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 10); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgInsUpdates, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgInsUpdates0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgInsUpdates, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgPpsTime.cc b/c/test/cpp/auto_check_sbp_system_MsgPpsTime.cc new file mode 100644 index 0000000000..619eca114b --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_MsgPpsTime.cc @@ -0,0 +1,767 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgPpsTime0 : public ::testing::Test { + public: + Testauto_check_sbp_system_MsgPpsTime0() { + assign(test_msg_.flags, 255); + assign(test_msg_.time, 690508632716); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_pps_time_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_pps_time_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgPpsTime, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_pps_time_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgPpsTime); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->pps_time, sizeof(msg->pps_time)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_pps_time_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.pps_time, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgPpsTime); + info.sender_id = 53726; + info.preamble = 0x55; + info.crc = 0x957d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_pps_time_t &lesser, + const sbp_msg_pps_time_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_pps_time_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_pps_time_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_pps_time_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_pps_time_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgPpsTime, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgPpsTime, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgPpsTime, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgPpsTime, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_pps_time_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { + 85, 8, 255, 222, 209, 9, 140, 146, 133, 197, 160, 0, 0, 0, 255, 125, 149, + }; + uint8_t encoded_payload_[9] = { + 140, 146, 133, 197, 160, 0, 0, 0, 255, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_pps_time_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgPpsTime, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_pps_time_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgPpsTime, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ( + sbp_msg_pps_time_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_msg_pps_time_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_pps_time_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgPpsTime, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_pps_time_t msg{}; + + EXPECT_EQ(sbp_msg_pps_time_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_pps_time_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_pps_time_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_pps_time_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgPpsTime, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgPpsTime, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_pps_time_t lesser = info.test_msg; + sbp_msg_pps_time_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_pps_time_t lesser = info.test_msg; + sbp_msg_pps_time_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgPpsTime); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_PPS_TIME"); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_pps_time_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_pps_time_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.pps_time, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.pps_time, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_pps_time_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgPpsTime, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgPpsTime0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgPpsTime, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgSensorAidEvent.cc b/c/test/cpp/auto_check_sbp_system_MsgSensorAidEvent.cc index f68cae220a..c409553f9b 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgSensorAidEvent.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgSensorAidEvent.cc @@ -16,114 +16,817 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgSensorAidEvent0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgSensorAidEvent0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgSensorAidEvent0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgSensorAidEvent0() { + assign(test_msg_.flags, 0); + assign(test_msg_.n_accepted_meas, 0); + assign(test_msg_.n_attempted_meas, 0); + assign(test_msg_.n_available_meas, 0); + assign(test_msg_.sensor_id, 0); + assign(test_msg_.sensor_state, 0); + assign(test_msg_.sensor_type, 0); + assign(test_msg_.time, 326825520); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_sensor_aid_event_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_sensor_aid_event_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgSensorAidEvent, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_sensor_aid_event_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgSensorAidEvent); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->sensor_aid_event, + sizeof(msg->sensor_aid_event)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_sensor_aid_event_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.sensor_aid_event, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgSensorAidEvent); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0xEC21; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_sensor_aid_event_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_sensor_aid_event_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_sensor_aid_event_t &lesser, + const sbp_msg_sensor_aid_event_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_sensor_aid_event_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_sensor_aid_event_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_sensor_aid_event_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_sensor_aid_event_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgSensorAidEvent, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgSensorAidEvent, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgSensorAidEvent, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgSensorAidEvent, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_system_MsgSensorAidEvent0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_sensor_aid_event_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { 85, 9, 255, 211, 136, 15, 48, 246, 122, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 236, }; + uint8_t encoded_payload_[15] = { + 48, 246, 122, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_sensor_aid_event_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgSensorAidEvent, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_sensor_aid_event_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgSensorAidEvent, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ(sbp_msg_sensor_aid_event_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ( + sbp_msg_sensor_aid_event_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sensor_aid_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_sensor_aid_event_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgSensorAidEvent, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_sensor_aid_event_t msg{}; + + EXPECT_EQ(sbp_msg_sensor_aid_event_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_sensor_aid_event_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_sensor_aid_event_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - sbp_msg_sensor_aid_event_t test_msg{}; - test_msg.flags = 0; - test_msg.n_accepted_meas = 0; - test_msg.n_attempted_meas = 0; - test_msg.n_available_meas = 0; - test_msg.sensor_id = 0; - test_msg.sensor_state = 0; - test_msg.sensor_type = 0; - test_msg.time = 326825520; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 0) - << "incorrect value for last_msg_.flags, expected 0, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.n_accepted_meas, 0) - << "incorrect value for last_msg_.n_accepted_meas, expected 0, is " - << last_msg_.n_accepted_meas; - EXPECT_EQ(last_msg_.n_attempted_meas, 0) - << "incorrect value for last_msg_.n_attempted_meas, expected 0, is " - << last_msg_.n_attempted_meas; - EXPECT_EQ(last_msg_.n_available_meas, 0) - << "incorrect value for last_msg_.n_available_meas, expected 0, is " - << last_msg_.n_available_meas; - EXPECT_EQ(last_msg_.sensor_id, 0) - << "incorrect value for last_msg_.sensor_id, expected 0, is " - << last_msg_.sensor_id; - EXPECT_EQ(last_msg_.sensor_state, 0) - << "incorrect value for last_msg_.sensor_state, expected 0, is " - << last_msg_.sensor_state; - EXPECT_EQ(last_msg_.sensor_type, 0) - << "incorrect value for last_msg_.sensor_type, expected 0, is " - << last_msg_.sensor_type; - EXPECT_EQ(last_msg_.time, 326825520) - << "incorrect value for last_msg_.time, expected 326825520, is " - << last_msg_.time; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_sensor_aid_event_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSensorAidEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgSensorAidEvent, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgSensorAidEvent, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.n_accepted_meas, greater.n_accepted_meas); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.n_attempted_meas, greater.n_attempted_meas); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.n_available_meas, greater.n_available_meas); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.sensor_id, greater.sensor_id); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.sensor_state, greater.sensor_state); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.sensor_type, greater.sensor_type); + comparison_tests(lesser, greater); + } + { + sbp_msg_sensor_aid_event_t lesser = info.test_msg; + sbp_msg_sensor_aid_event_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgSensorAidEvent); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_SENSOR_AID_EVENT"); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_sensor_aid_event_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_sensor_aid_event_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.sensor_aid_event, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.sensor_aid_event, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); } + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_sensor_aid_event_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgSensorAidEvent, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgSensorAidEvent0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgSensorAidEvent, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgStartup.cc b/c/test/cpp/auto_check_sbp_system_MsgStartup.cc index 8661409408..ed16ac2e6f 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgStartup.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgStartup.cc @@ -16,180 +16,1510 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgStartup0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgStartup0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgStartup0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgStartup0() { + assign(test_msg_.cause, 0); + assign(test_msg_.reserved, 0); + assign(test_msg_.startup_type, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_startup_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_startup_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStartup, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_startup_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStartup); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->startup, sizeof(msg->startup)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_startup_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.startup, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStartup); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0xa046; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_startup_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_startup_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_startup_t &lesser, + const sbp_msg_startup_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_startup_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_startup_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_startup_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_startup_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgStartup, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgStartup, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStartup, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStartup, &wrapped_greater, &wrapped_lesser), + 0); -TEST_F(Test_auto_check_sbp_system_MsgStartup0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_startup_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 0, 255, 66, 0, 4, 0, 0, 0, 0, 70, 160, }; + uint8_t encoded_payload_[4] = { + 0, + 0, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgStartup0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_startup_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgStartup, &info.test_msg_wrapped), + info.payload_len); +} - sbp_msg_startup_t test_msg{}; - test_msg.cause = 0; - test_msg.reserved = 0; - test_msg.startup_type = 0; +TEST_F(Testauto_check_sbp_system_MsgStartup0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + EXPECT_EQ( + sbp_msg_startup_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgStartup, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_startup_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_system_MsgStartup0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_startup_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_startup_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStartup, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + + EXPECT_EQ(sbp_msg_startup_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgStartup0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_startup_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_startup_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.cause, greater.cause); + comparison_tests(lesser, greater); + } + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.reserved, greater.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.startup_type, greater.startup_type); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgStartup); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_STARTUP"); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_startup_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_startup_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.startup, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.startup, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStartup, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cause, 0) - << "incorrect value for last_msg_.cause, expected 0, is " - << last_msg_.cause; - EXPECT_EQ(last_msg_.reserved, 0) - << "incorrect value for last_msg_.reserved, expected 0, is " - << last_msg_.reserved; - EXPECT_EQ(last_msg_.startup_type, 0) - << "incorrect value for last_msg_.startup_type, expected 0, is " - << last_msg_.startup_type; + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgStartup, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } -class Test_auto_check_sbp_system_MsgStartup1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + +class Testauto_check_sbp_system_MsgStartup1 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgStartup1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgStartup1() { + assign(test_msg_.cause, 0); + assign(test_msg_.reserved, 0); + assign(test_msg_.startup_type, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_startup_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_startup_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStartup, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_startup_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStartup); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->startup, sizeof(msg->startup)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_startup_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.startup, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStartup); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb57f; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 4; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_startup_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_startup_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_startup_t &lesser, + const sbp_msg_startup_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_startup_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_startup_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_startup_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_startup_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgStartup, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgStartup, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE(sbp_message_cmp(SbpMsgStartup, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgStartup, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgStartup1, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_startup_t test_msg_{}; + uint8_t encoded_frame_[4 + 8] = { 85, 0, 255, 195, 4, 4, 0, 0, 0, 0, 127, 181, }; + uint8_t encoded_payload_[4] = { + 0, + 0, + 0, + 0, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgStartup1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_startup_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgStartup, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_startup_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgStartup, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + EXPECT_EQ( + sbp_msg_startup_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); +} +TEST_F(Testauto_check_sbp_system_MsgStartup1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_msg_startup_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_startup_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStartup, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + + EXPECT_EQ(sbp_msg_startup_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgStartup1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - sbp_msg_startup_t test_msg{}; - test_msg.cause = 0; - test_msg.reserved = 0; - test_msg.startup_type = 0; + EXPECT_EQ( + sbp_msg_startup_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_startup_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ(sbp_message_send(&state, SbpMsgStartup, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - while (dummy_rd_ < dummy_wr_) { - process(); +TEST_F(Testauto_check_sbp_system_MsgStartup1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.cause, greater.cause); + comparison_tests(lesser, greater); } + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.reserved, greater.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_startup_t lesser = info.test_msg; + sbp_msg_startup_t greater = info.test_msg; + make_lesser_greater(lesser.startup_type, greater.startup_type); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgStartup); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_STARTUP"); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_startup_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_startup_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.startup, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.startup, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[4]; + uint8_t n_written; - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.cause, 0) - << "incorrect value for last_msg_.cause, expected 0, is " - << last_msg_.cause; - EXPECT_EQ(last_msg_.reserved, 0) - << "incorrect value for last_msg_.reserved, expected 0, is " - << last_msg_.reserved; - EXPECT_EQ(last_msg_.startup_type, 0) - << "incorrect value for last_msg_.startup_type, expected 0, is " - << last_msg_.startup_type; + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 4), 0); } + +TEST_F(Testauto_check_sbp_system_MsgStartup1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_startup_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 4); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStartup, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStartup1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgStartup, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgStatusJournal.cc b/c/test/cpp/auto_check_sbp_system_MsgStatusJournal.cc index 25e80933c6..906d518006 100644 --- a/c/test/cpp/auto_check_sbp_system_MsgStatusJournal.cc +++ b/c/test/cpp/auto_check_sbp_system_MsgStatusJournal.cc @@ -16,279 +16,1742 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_system_MsgStatusJournal0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgStatusJournal0 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgStatusJournal0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgStatusJournal0() { + assign(test_msg_.journal[0].report.component, 6); + assign(test_msg_.journal[0].report.generic, 1); + assign(test_msg_.journal[0].report.specific, 13); + assign(test_msg_.journal[0].uptime, 4242); + + assign(test_msg_.journal[1].report.component, 6); + assign(test_msg_.journal[1].report.generic, 1); + assign(test_msg_.journal[1].report.specific, 14); + assign(test_msg_.journal[1].uptime, 5050); + + assign(test_msg_.journal[2].report.component, 6); + assign(test_msg_.journal[2].report.generic, 1); + assign(test_msg_.journal[2].report.specific, 15); + assign(test_msg_.journal[2].uptime, 8888); + assign(test_msg_.n_journal, 3); + assign(test_msg_.reporting_system, 1); + assign(test_msg_.sbp_version, 1025); + assign(test_msg_.sequence_descriptor, 16); + assign(test_msg_.total_status_reports, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_status_journal_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_status_journal_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStatusJournal, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_status_journal_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStatusJournal); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->status_journal, + sizeof(msg->status_journal)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_status_journal_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.status_journal, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStatusJournal); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x7771; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 33; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_status_journal_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_status_journal_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_status_journal_t &lesser, + const sbp_msg_status_journal_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_status_journal_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_status_journal_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_status_journal_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_status_journal_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStatusJournal, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); -TEST_F(Test_auto_check_sbp_system_MsgStatusJournal0, Test) { - uint8_t encoded_frame[] = { + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_status_journal_t test_msg_{}; + uint8_t encoded_frame_[33 + 8] = { 85, 253, 255, 211, 136, 33, 1, 0, 1, 4, 100, 0, 0, 0, 16, 146, 16, 0, 0, 6, 0, 1, 13, 186, 19, 0, 0, 6, 0, 1, 14, 184, 34, 0, 0, 6, 0, 1, 15, 113, 119, }; + uint8_t encoded_payload_[33] = { + 1, 0, 1, 4, 100, 0, 0, 0, 16, 146, 16, 0, 0, 6, 0, 1, 13, + 186, 19, 0, 0, 6, 0, 1, 14, 184, 34, 0, 0, 6, 0, 1, 15, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_status_journal_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgStatusJournal, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_status_journal_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStatusJournal, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + EXPECT_EQ(sbp_msg_status_journal_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + + for (uint8_t i = 0; i < 33; i++) { + EXPECT_EQ( + sbp_msg_status_journal_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStatusJournal, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_status_journal_t t{}; + return sbp_msg_status_journal_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_status_journal_t t{}; + t.n_journal = 1; + return sbp_msg_status_journal_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_status_journal_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.component, + greater.journal[0].report.component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.generic, + greater.journal[0].report.generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.specific, + greater.journal[0].report.specific); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].uptime, greater.journal[0].uptime); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[1].report.component, + greater.journal[1].report.component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[1].report.generic, + greater.journal[1].report.generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[1].report.specific, + greater.journal[1].report.specific); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[1].uptime, greater.journal[1].uptime); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[2].report.component, + greater.journal[2].report.component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[2].report.generic, + greater.journal[2].report.generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[2].report.specific, + greater.journal[2].report.specific); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[2].uptime, greater.journal[2].uptime); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.n_journal, greater.n_journal); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.reporting_system, greater.reporting_system); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.sbp_version, greater.sbp_version); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.sequence_descriptor, + greater.sequence_descriptor); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.total_status_reports, + greater.total_status_reports); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStatusJournal); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STATUS_JOURNAL"); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_status_journal_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_status_journal_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.status_journal, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.status_journal, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[33]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 33), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 33); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStatusJournal, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - sbp_msg_status_journal_t test_msg{}; - - test_msg.journal[0].report.component = 6; - test_msg.journal[0].report.generic = 1; - test_msg.journal[0].report.specific = 13; - test_msg.journal[0].uptime = 4242; - - test_msg.journal[1].report.component = 6; - test_msg.journal[1].report.generic = 1; - test_msg.journal[1].report.specific = 14; - test_msg.journal[1].uptime = 5050; - - test_msg.journal[2].report.component = 6; - test_msg.journal[2].report.generic = 1; - test_msg.journal[2].report.specific = 15; - test_msg.journal[2].uptime = 8888; - test_msg.n_journal = 3; - test_msg.reporting_system = 1; - test_msg.sbp_version = 1025; - test_msg.sequence_descriptor = 16; - test_msg.total_status_reports = 100; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.journal[0].report.component, 6) - << "incorrect value for last_msg_.journal[0].report.component, expected " - "6, is " - << last_msg_.journal[0].report.component; - EXPECT_EQ(last_msg_.journal[0].report.generic, 1) - << "incorrect value for last_msg_.journal[0].report.generic, expected 1, " - "is " - << last_msg_.journal[0].report.generic; - EXPECT_EQ(last_msg_.journal[0].report.specific, 13) - << "incorrect value for last_msg_.journal[0].report.specific, expected " - "13, is " - << last_msg_.journal[0].report.specific; - EXPECT_EQ(last_msg_.journal[0].uptime, 4242) - << "incorrect value for last_msg_.journal[0].uptime, expected 4242, is " - << last_msg_.journal[0].uptime; - EXPECT_EQ(last_msg_.journal[1].report.component, 6) - << "incorrect value for last_msg_.journal[1].report.component, expected " - "6, is " - << last_msg_.journal[1].report.component; - EXPECT_EQ(last_msg_.journal[1].report.generic, 1) - << "incorrect value for last_msg_.journal[1].report.generic, expected 1, " - "is " - << last_msg_.journal[1].report.generic; - EXPECT_EQ(last_msg_.journal[1].report.specific, 14) - << "incorrect value for last_msg_.journal[1].report.specific, expected " - "14, is " - << last_msg_.journal[1].report.specific; - EXPECT_EQ(last_msg_.journal[1].uptime, 5050) - << "incorrect value for last_msg_.journal[1].uptime, expected 5050, is " - << last_msg_.journal[1].uptime; - EXPECT_EQ(last_msg_.journal[2].report.component, 6) - << "incorrect value for last_msg_.journal[2].report.component, expected " - "6, is " - << last_msg_.journal[2].report.component; - EXPECT_EQ(last_msg_.journal[2].report.generic, 1) - << "incorrect value for last_msg_.journal[2].report.generic, expected 1, " - "is " - << last_msg_.journal[2].report.generic; - EXPECT_EQ(last_msg_.journal[2].report.specific, 15) - << "incorrect value for last_msg_.journal[2].report.specific, expected " - "15, is " - << last_msg_.journal[2].report.specific; - EXPECT_EQ(last_msg_.journal[2].uptime, 8888) - << "incorrect value for last_msg_.journal[2].uptime, expected 8888, is " - << last_msg_.journal[2].uptime; - EXPECT_EQ(last_msg_.n_journal, 3) - << "incorrect value for last_msg_.n_journal, expected 3, is " - << last_msg_.n_journal; - EXPECT_EQ(last_msg_.reporting_system, 1) - << "incorrect value for last_msg_.reporting_system, expected 1, is " - << last_msg_.reporting_system; - EXPECT_EQ(last_msg_.sbp_version, 1025) - << "incorrect value for last_msg_.sbp_version, expected 1025, is " - << last_msg_.sbp_version; - EXPECT_EQ(last_msg_.sequence_descriptor, 16) - << "incorrect value for last_msg_.sequence_descriptor, expected 16, is " - << last_msg_.sequence_descriptor; - EXPECT_EQ(last_msg_.total_status_reports, 100) - << "incorrect value for last_msg_.total_status_reports, expected 100, is " - << last_msg_.total_status_reports; -} -class Test_auto_check_sbp_system_MsgStatusJournal1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStatusJournal, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_system_MsgStatusJournal1 : public ::testing::Test { public: - Test_auto_check_sbp_system_MsgStatusJournal1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_system_MsgStatusJournal1() { + assign(test_msg_.journal[0].report.component, 6); + assign(test_msg_.journal[0].report.generic, 1); + assign(test_msg_.journal[0].report.specific, 13); + assign(test_msg_.journal[0].uptime, 4242); + assign(test_msg_.n_journal, 1); + assign(test_msg_.reporting_system, 1); + assign(test_msg_.sbp_version, 1025); + assign(test_msg_.sequence_descriptor, 16); + assign(test_msg_.total_status_reports, 100); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_status_journal_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_status_journal_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStatusJournal, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_status_journal_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStatusJournal); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->status_journal, + sizeof(msg->status_journal)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_status_journal_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.status_journal, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStatusJournal); + info.sender_id = 35027; + info.preamble = 0x55; + info.crc = 0x7990; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 17; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_status_journal_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_status_journal_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_status_journal_t &lesser, + const sbp_msg_status_journal_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_status_journal_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_status_journal_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_status_journal_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_status_journal_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgStatusJournal, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgStatusJournal, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_system_MsgStatusJournal1, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_status_journal_t test_msg_{}; + uint8_t encoded_frame_[17 + 8] = { 85, 253, 255, 211, 136, 17, 1, 0, 1, 4, 100, 0, 0, 0, 16, 146, 16, 0, 0, 6, 0, 1, 13, 144, 121, }; + uint8_t encoded_payload_[17] = { + 1, 0, 1, 4, 100, 0, 0, 0, 16, 146, 16, 0, 0, 6, 0, 1, 13, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_status_journal_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgStatusJournal, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_status_journal_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStatusJournal, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + EXPECT_EQ(sbp_msg_status_journal_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + + for (uint8_t i = 0; i < 17; i++) { + EXPECT_EQ( + sbp_msg_status_journal_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStatusJournal, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_status_journal_t t{}; + return sbp_msg_status_journal_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_status_journal_t t{}; + t.n_journal = 1; + return sbp_msg_status_journal_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_status_journal_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_status_journal_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusJournal, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, Comparison) { + auto info = get_test_msg_info(); - sbp_msg_status_journal_t test_msg{}; - - test_msg.journal[0].report.component = 6; - test_msg.journal[0].report.generic = 1; - test_msg.journal[0].report.specific = 13; - test_msg.journal[0].uptime = 4242; - test_msg.n_journal = 1; - test_msg.reporting_system = 1; - test_msg.sbp_version = 1025; - test_msg.sequence_descriptor = 16; - test_msg.total_status_reports = 100; - - EXPECT_EQ(send_message(35027, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 35027); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.journal[0].report.component, 6) - << "incorrect value for last_msg_.journal[0].report.component, expected " - "6, is " - << last_msg_.journal[0].report.component; - EXPECT_EQ(last_msg_.journal[0].report.generic, 1) - << "incorrect value for last_msg_.journal[0].report.generic, expected 1, " - "is " - << last_msg_.journal[0].report.generic; - EXPECT_EQ(last_msg_.journal[0].report.specific, 13) - << "incorrect value for last_msg_.journal[0].report.specific, expected " - "13, is " - << last_msg_.journal[0].report.specific; - EXPECT_EQ(last_msg_.journal[0].uptime, 4242) - << "incorrect value for last_msg_.journal[0].uptime, expected 4242, is " - << last_msg_.journal[0].uptime; - EXPECT_EQ(last_msg_.n_journal, 1) - << "incorrect value for last_msg_.n_journal, expected 1, is " - << last_msg_.n_journal; - EXPECT_EQ(last_msg_.reporting_system, 1) - << "incorrect value for last_msg_.reporting_system, expected 1, is " - << last_msg_.reporting_system; - EXPECT_EQ(last_msg_.sbp_version, 1025) - << "incorrect value for last_msg_.sbp_version, expected 1025, is " - << last_msg_.sbp_version; - EXPECT_EQ(last_msg_.sequence_descriptor, 16) - << "incorrect value for last_msg_.sequence_descriptor, expected 16, is " - << last_msg_.sequence_descriptor; - EXPECT_EQ(last_msg_.total_status_reports, 100) - << "incorrect value for last_msg_.total_status_reports, expected 100, is " - << last_msg_.total_status_reports; + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.component, + greater.journal[0].report.component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.generic, + greater.journal[0].report.generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].report.specific, + greater.journal[0].report.specific); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.journal[0].uptime, greater.journal[0].uptime); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.n_journal, greater.n_journal); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.reporting_system, greater.reporting_system); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.sbp_version, greater.sbp_version); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.sequence_descriptor, + greater.sequence_descriptor); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_journal_t lesser = info.test_msg; + sbp_msg_status_journal_t greater = info.test_msg; + make_lesser_greater(lesser.total_status_reports, + greater.total_status_reports); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStatusJournal); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STATUS_JOURNAL"); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_status_journal_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_status_journal_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.status_journal, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.status_journal, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); } + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[17]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 17); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 17), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_journal_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 17); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStatusJournal, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusJournal1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStatusJournal, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_MsgStatusReport.cc b/c/test/cpp/auto_check_sbp_system_MsgStatusReport.cc new file mode 100644 index 0000000000..6b9bb32528 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_MsgStatusReport.cc @@ -0,0 +1,2341 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_system_MsgStatusReport0 : public ::testing::Test { + public: + Testauto_check_sbp_system_MsgStatusReport0() { + assign(test_msg_.n_status, 60); + assign(test_msg_.reporting_system, 64850); + assign(test_msg_.sbp_version, 24497); + assign(test_msg_.sequence, 1519336451); + + assign(test_msg_.status[0].component, 52215); + assign(test_msg_.status[0].generic, 221); + assign(test_msg_.status[0].specific, 198); + + assign(test_msg_.status[1].component, 53148); + assign(test_msg_.status[1].generic, 217); + assign(test_msg_.status[1].specific, 238); + + assign(test_msg_.status[2].component, 34978); + assign(test_msg_.status[2].generic, 154); + assign(test_msg_.status[2].specific, 11); + + assign(test_msg_.status[3].component, 60530); + assign(test_msg_.status[3].generic, 134); + assign(test_msg_.status[3].specific, 235); + + assign(test_msg_.status[4].component, 34060); + assign(test_msg_.status[4].generic, 9); + assign(test_msg_.status[4].specific, 30); + + assign(test_msg_.status[5].component, 37295); + assign(test_msg_.status[5].generic, 26); + assign(test_msg_.status[5].specific, 114); + + assign(test_msg_.status[6].component, 5335); + assign(test_msg_.status[6].generic, 146); + assign(test_msg_.status[6].specific, 249); + + assign(test_msg_.status[7].component, 13878); + assign(test_msg_.status[7].generic, 133); + assign(test_msg_.status[7].specific, 193); + + assign(test_msg_.status[8].component, 47722); + assign(test_msg_.status[8].generic, 210); + assign(test_msg_.status[8].specific, 183); + + assign(test_msg_.status[9].component, 33024); + assign(test_msg_.status[9].generic, 5); + assign(test_msg_.status[9].specific, 248); + + assign(test_msg_.status[10].component, 38369); + assign(test_msg_.status[10].generic, 135); + assign(test_msg_.status[10].specific, 127); + + assign(test_msg_.status[11].component, 6658); + assign(test_msg_.status[11].generic, 88); + assign(test_msg_.status[11].specific, 92); + + assign(test_msg_.status[12].component, 26378); + assign(test_msg_.status[12].generic, 73); + assign(test_msg_.status[12].specific, 3); + + assign(test_msg_.status[13].component, 17511); + assign(test_msg_.status[13].generic, 76); + assign(test_msg_.status[13].specific, 184); + + assign(test_msg_.status[14].component, 52769); + assign(test_msg_.status[14].generic, 194); + assign(test_msg_.status[14].specific, 163); + + assign(test_msg_.status[15].component, 7803); + assign(test_msg_.status[15].generic, 151); + assign(test_msg_.status[15].specific, 176); + + assign(test_msg_.status[16].component, 44181); + assign(test_msg_.status[16].generic, 184); + assign(test_msg_.status[16].specific, 231); + + assign(test_msg_.status[17].component, 58998); + assign(test_msg_.status[17].generic, 200); + assign(test_msg_.status[17].specific, 168); + + assign(test_msg_.status[18].component, 28004); + assign(test_msg_.status[18].generic, 10); + assign(test_msg_.status[18].specific, 233); + + assign(test_msg_.status[19].component, 15364); + assign(test_msg_.status[19].generic, 247); + assign(test_msg_.status[19].specific, 82); + + assign(test_msg_.status[20].component, 42711); + assign(test_msg_.status[20].generic, 28); + assign(test_msg_.status[20].specific, 138); + + assign(test_msg_.status[21].component, 11630); + assign(test_msg_.status[21].generic, 98); + assign(test_msg_.status[21].specific, 218); + + assign(test_msg_.status[22].component, 46068); + assign(test_msg_.status[22].generic, 126); + assign(test_msg_.status[22].specific, 107); + + assign(test_msg_.status[23].component, 31836); + assign(test_msg_.status[23].generic, 94); + assign(test_msg_.status[23].specific, 157); + + assign(test_msg_.status[24].component, 47914); + assign(test_msg_.status[24].generic, 124); + assign(test_msg_.status[24].specific, 6); + + assign(test_msg_.status[25].component, 63329); + assign(test_msg_.status[25].generic, 160); + assign(test_msg_.status[25].specific, 188); + + assign(test_msg_.status[26].component, 30830); + assign(test_msg_.status[26].generic, 254); + assign(test_msg_.status[26].specific, 214); + + assign(test_msg_.status[27].component, 13166); + assign(test_msg_.status[27].generic, 240); + assign(test_msg_.status[27].specific, 164); + + assign(test_msg_.status[28].component, 4755); + assign(test_msg_.status[28].generic, 74); + assign(test_msg_.status[28].specific, 178); + + assign(test_msg_.status[29].component, 1091); + assign(test_msg_.status[29].generic, 27); + assign(test_msg_.status[29].specific, 73); + + assign(test_msg_.status[30].component, 16574); + assign(test_msg_.status[30].generic, 179); + assign(test_msg_.status[30].specific, 146); + + assign(test_msg_.status[31].component, 39293); + assign(test_msg_.status[31].generic, 192); + assign(test_msg_.status[31].specific, 46); + + assign(test_msg_.status[32].component, 17098); + assign(test_msg_.status[32].generic, 248); + assign(test_msg_.status[32].specific, 46); + + assign(test_msg_.status[33].component, 41256); + assign(test_msg_.status[33].generic, 173); + assign(test_msg_.status[33].specific, 242); + + assign(test_msg_.status[34].component, 982); + assign(test_msg_.status[34].generic, 11); + assign(test_msg_.status[34].specific, 1); + + assign(test_msg_.status[35].component, 18038); + assign(test_msg_.status[35].generic, 162); + assign(test_msg_.status[35].specific, 61); + + assign(test_msg_.status[36].component, 7090); + assign(test_msg_.status[36].generic, 156); + assign(test_msg_.status[36].specific, 40); + + assign(test_msg_.status[37].component, 29119); + assign(test_msg_.status[37].generic, 230); + assign(test_msg_.status[37].specific, 200); + + assign(test_msg_.status[38].component, 2120); + assign(test_msg_.status[38].generic, 215); + assign(test_msg_.status[38].specific, 245); + + assign(test_msg_.status[39].component, 15182); + assign(test_msg_.status[39].generic, 222); + assign(test_msg_.status[39].specific, 250); + + assign(test_msg_.status[40].component, 8307); + assign(test_msg_.status[40].generic, 33); + assign(test_msg_.status[40].specific, 30); + + assign(test_msg_.status[41].component, 43731); + assign(test_msg_.status[41].generic, 145); + assign(test_msg_.status[41].specific, 92); + + assign(test_msg_.status[42].component, 19357); + assign(test_msg_.status[42].generic, 24); + assign(test_msg_.status[42].specific, 169); + + assign(test_msg_.status[43].component, 14086); + assign(test_msg_.status[43].generic, 62); + assign(test_msg_.status[43].specific, 8); + + assign(test_msg_.status[44].component, 21099); + assign(test_msg_.status[44].generic, 140); + assign(test_msg_.status[44].specific, 49); + + assign(test_msg_.status[45].component, 31411); + assign(test_msg_.status[45].generic, 90); + assign(test_msg_.status[45].specific, 71); + + assign(test_msg_.status[46].component, 22556); + assign(test_msg_.status[46].generic, 103); + assign(test_msg_.status[46].specific, 51); + + assign(test_msg_.status[47].component, 18609); + assign(test_msg_.status[47].generic, 93); + assign(test_msg_.status[47].specific, 39); + + assign(test_msg_.status[48].component, 2964); + assign(test_msg_.status[48].generic, 202); + assign(test_msg_.status[48].specific, 42); + + assign(test_msg_.status[49].component, 23586); + assign(test_msg_.status[49].generic, 204); + assign(test_msg_.status[49].specific, 102); + + assign(test_msg_.status[50].component, 25117); + assign(test_msg_.status[50].generic, 249); + assign(test_msg_.status[50].specific, 91); + + assign(test_msg_.status[51].component, 24454); + assign(test_msg_.status[51].generic, 23); + assign(test_msg_.status[51].specific, 248); + + assign(test_msg_.status[52].component, 5312); + assign(test_msg_.status[52].generic, 83); + assign(test_msg_.status[52].specific, 195); + + assign(test_msg_.status[53].component, 46175); + assign(test_msg_.status[53].generic, 54); + assign(test_msg_.status[53].specific, 36); + + assign(test_msg_.status[54].component, 19386); + assign(test_msg_.status[54].generic, 64); + assign(test_msg_.status[54].specific, 20); + + assign(test_msg_.status[55].component, 34205); + assign(test_msg_.status[55].generic, 12); + assign(test_msg_.status[55].specific, 149); + + assign(test_msg_.status[56].component, 3612); + assign(test_msg_.status[56].generic, 185); + assign(test_msg_.status[56].specific, 129); + + assign(test_msg_.status[57].component, 61285); + assign(test_msg_.status[57].generic, 74); + assign(test_msg_.status[57].specific, 248); + + assign(test_msg_.status[58].component, 7925); + assign(test_msg_.status[58].generic, 228); + assign(test_msg_.status[58].specific, 88); + + assign(test_msg_.status[59].component, 54414); + assign(test_msg_.status[59].generic, 53); + assign(test_msg_.status[59].specific, 224); + assign(test_msg_.uptime, 1657804265); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_status_report_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_status_report_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgStatusReport, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_status_report_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgStatusReport); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->status_report, + sizeof(msg->status_report)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_status_report_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.status_report, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgStatusReport); + info.sender_id = 21510; + info.preamble = 0x55; + info.crc = 0xa69e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 252; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_status_report_t &lesser, + const sbp_msg_status_report_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_status_report_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_status_report_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_status_report_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_status_report_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgStatusReport, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgStatusReport, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgStatusReport, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgStatusReport, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_status_report_t test_msg_{}; + uint8_t encoded_frame_[252 + 8] = { + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, 233, + 21, 208, 98, 247, 203, 221, 198, 156, 207, 217, 238, 162, 136, 154, 11, + 114, 236, 134, 235, 12, 133, 9, 30, 175, 145, 26, 114, 215, 20, 146, + 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, 5, 248, 225, 149, + 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, 103, 68, 76, 184, 33, + 206, 194, 163, 123, 30, 151, 176, 149, 172, 184, 231, 118, 230, 200, 168, + 100, 109, 10, 233, 4, 60, 247, 82, 215, 166, 28, 138, 110, 45, 98, + 218, 244, 179, 126, 107, 92, 124, 94, 157, 42, 187, 124, 6, 97, 247, + 160, 188, 110, 120, 254, 214, 110, 51, 240, 164, 147, 18, 74, 178, 67, + 4, 27, 73, 190, 64, 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, + 40, 161, 173, 242, 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, + 40, 191, 113, 230, 200, 72, 8, 215, 245, 78, 59, 222, 250, 115, 32, + 33, 30, 211, 170, 145, 92, 157, 75, 24, 169, 6, 55, 62, 8, 107, + 82, 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, + 148, 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, 23, + 248, 192, 20, 83, 195, 95, 180, 54, 36, 186, 75, 64, 20, 157, 133, + 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, 245, 30, 228, 88, 142, + 212, 53, 224, 158, 166, + }; + uint8_t encoded_payload_[252] = { + 82, 253, 177, 95, 3, 60, 143, 90, 233, 21, 208, 98, 247, 203, 221, + 198, 156, 207, 217, 238, 162, 136, 154, 11, 114, 236, 134, 235, 12, 133, + 9, 30, 175, 145, 26, 114, 215, 20, 146, 249, 54, 54, 133, 193, 106, + 186, 210, 183, 0, 129, 5, 248, 225, 149, 135, 127, 2, 26, 88, 92, + 10, 103, 73, 3, 103, 68, 76, 184, 33, 206, 194, 163, 123, 30, 151, + 176, 149, 172, 184, 231, 118, 230, 200, 168, 100, 109, 10, 233, 4, 60, + 247, 82, 215, 166, 28, 138, 110, 45, 98, 218, 244, 179, 126, 107, 92, + 124, 94, 157, 42, 187, 124, 6, 97, 247, 160, 188, 110, 120, 254, 214, + 110, 51, 240, 164, 147, 18, 74, 178, 67, 4, 27, 73, 190, 64, 179, + 146, 125, 153, 192, 46, 202, 66, 248, 46, 40, 161, 173, 242, 214, 3, + 11, 1, 118, 70, 162, 61, 178, 27, 156, 40, 191, 113, 230, 200, 72, + 8, 215, 245, 78, 59, 222, 250, 115, 32, 33, 30, 211, 170, 145, 92, + 157, 75, 24, 169, 6, 55, 62, 8, 107, 82, 140, 49, 179, 122, 90, + 71, 28, 88, 103, 51, 177, 72, 93, 39, 148, 11, 202, 42, 34, 92, + 204, 102, 29, 98, 249, 91, 134, 95, 23, 248, 192, 20, 83, 195, 95, + 180, 54, 36, 186, 75, 64, 20, 157, 133, 12, 149, 28, 14, 185, 129, + 101, 239, 74, 248, 245, 30, 228, 88, 142, 212, 53, 224, + }; +}; + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_status_report_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgStatusReport, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_status_report_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgStatusReport, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + EXPECT_EQ(sbp_msg_status_report_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + for (uint8_t i = 0; i < 252; i++) { + EXPECT_EQ(sbp_msg_status_report_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_report_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_status_report_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgStatusReport, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_status_report_t msg{}; + + EXPECT_EQ(sbp_msg_status_report_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_status_report_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_status_report_t t{}; + return sbp_msg_status_report_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_status_report_t t{}; + t.n_status = 1; + return sbp_msg_status_report_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_status_report_decode(&info.encoded_payload[0], i, nullptr, + &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_status_report_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusReport, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgStatusReport, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgStatusReport, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.n_status, greater.n_status); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.reporting_system, greater.reporting_system); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.sbp_version, greater.sbp_version); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.sequence, greater.sequence); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[0].component, + greater.status[0].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[0].generic, greater.status[0].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[0].specific, greater.status[0].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[1].component, + greater.status[1].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[1].generic, greater.status[1].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[1].specific, greater.status[1].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[2].component, + greater.status[2].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[2].generic, greater.status[2].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[2].specific, greater.status[2].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[3].component, + greater.status[3].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[3].generic, greater.status[3].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[3].specific, greater.status[3].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[4].component, + greater.status[4].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[4].generic, greater.status[4].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[4].specific, greater.status[4].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[5].component, + greater.status[5].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[5].generic, greater.status[5].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[5].specific, greater.status[5].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[6].component, + greater.status[6].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[6].generic, greater.status[6].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[6].specific, greater.status[6].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[7].component, + greater.status[7].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[7].generic, greater.status[7].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[7].specific, greater.status[7].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[8].component, + greater.status[8].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[8].generic, greater.status[8].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[8].specific, greater.status[8].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[9].component, + greater.status[9].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[9].generic, greater.status[9].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[9].specific, greater.status[9].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[10].component, + greater.status[10].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[10].generic, greater.status[10].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[10].specific, + greater.status[10].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[11].component, + greater.status[11].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[11].generic, greater.status[11].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[11].specific, + greater.status[11].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[12].component, + greater.status[12].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[12].generic, greater.status[12].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[12].specific, + greater.status[12].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[13].component, + greater.status[13].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[13].generic, greater.status[13].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[13].specific, + greater.status[13].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[14].component, + greater.status[14].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[14].generic, greater.status[14].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[14].specific, + greater.status[14].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[15].component, + greater.status[15].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[15].generic, greater.status[15].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[15].specific, + greater.status[15].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[16].component, + greater.status[16].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[16].generic, greater.status[16].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[16].specific, + greater.status[16].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[17].component, + greater.status[17].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[17].generic, greater.status[17].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[17].specific, + greater.status[17].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[18].component, + greater.status[18].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[18].generic, greater.status[18].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[18].specific, + greater.status[18].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[19].component, + greater.status[19].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[19].generic, greater.status[19].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[19].specific, + greater.status[19].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[20].component, + greater.status[20].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[20].generic, greater.status[20].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[20].specific, + greater.status[20].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[21].component, + greater.status[21].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[21].generic, greater.status[21].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[21].specific, + greater.status[21].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[22].component, + greater.status[22].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[22].generic, greater.status[22].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[22].specific, + greater.status[22].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[23].component, + greater.status[23].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[23].generic, greater.status[23].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[23].specific, + greater.status[23].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[24].component, + greater.status[24].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[24].generic, greater.status[24].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[24].specific, + greater.status[24].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[25].component, + greater.status[25].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[25].generic, greater.status[25].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[25].specific, + greater.status[25].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[26].component, + greater.status[26].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[26].generic, greater.status[26].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[26].specific, + greater.status[26].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[27].component, + greater.status[27].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[27].generic, greater.status[27].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[27].specific, + greater.status[27].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[28].component, + greater.status[28].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[28].generic, greater.status[28].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[28].specific, + greater.status[28].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[29].component, + greater.status[29].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[29].generic, greater.status[29].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[29].specific, + greater.status[29].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[30].component, + greater.status[30].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[30].generic, greater.status[30].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[30].specific, + greater.status[30].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[31].component, + greater.status[31].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[31].generic, greater.status[31].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[31].specific, + greater.status[31].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[32].component, + greater.status[32].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[32].generic, greater.status[32].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[32].specific, + greater.status[32].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[33].component, + greater.status[33].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[33].generic, greater.status[33].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[33].specific, + greater.status[33].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[34].component, + greater.status[34].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[34].generic, greater.status[34].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[34].specific, + greater.status[34].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[35].component, + greater.status[35].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[35].generic, greater.status[35].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[35].specific, + greater.status[35].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[36].component, + greater.status[36].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[36].generic, greater.status[36].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[36].specific, + greater.status[36].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[37].component, + greater.status[37].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[37].generic, greater.status[37].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[37].specific, + greater.status[37].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[38].component, + greater.status[38].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[38].generic, greater.status[38].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[38].specific, + greater.status[38].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[39].component, + greater.status[39].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[39].generic, greater.status[39].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[39].specific, + greater.status[39].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[40].component, + greater.status[40].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[40].generic, greater.status[40].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[40].specific, + greater.status[40].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[41].component, + greater.status[41].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[41].generic, greater.status[41].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[41].specific, + greater.status[41].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[42].component, + greater.status[42].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[42].generic, greater.status[42].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[42].specific, + greater.status[42].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[43].component, + greater.status[43].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[43].generic, greater.status[43].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[43].specific, + greater.status[43].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[44].component, + greater.status[44].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[44].generic, greater.status[44].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[44].specific, + greater.status[44].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[45].component, + greater.status[45].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[45].generic, greater.status[45].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[45].specific, + greater.status[45].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[46].component, + greater.status[46].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[46].generic, greater.status[46].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[46].specific, + greater.status[46].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[47].component, + greater.status[47].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[47].generic, greater.status[47].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[47].specific, + greater.status[47].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[48].component, + greater.status[48].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[48].generic, greater.status[48].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[48].specific, + greater.status[48].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[49].component, + greater.status[49].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[49].generic, greater.status[49].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[49].specific, + greater.status[49].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[50].component, + greater.status[50].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[50].generic, greater.status[50].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[50].specific, + greater.status[50].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[51].component, + greater.status[51].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[51].generic, greater.status[51].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[51].specific, + greater.status[51].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[52].component, + greater.status[52].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[52].generic, greater.status[52].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[52].specific, + greater.status[52].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[53].component, + greater.status[53].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[53].generic, greater.status[53].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[53].specific, + greater.status[53].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[54].component, + greater.status[54].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[54].generic, greater.status[54].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[54].specific, + greater.status[54].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[55].component, + greater.status[55].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[55].generic, greater.status[55].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[55].specific, + greater.status[55].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[56].component, + greater.status[56].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[56].generic, greater.status[56].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[56].specific, + greater.status[56].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[57].component, + greater.status[57].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[57].generic, greater.status[57].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[57].specific, + greater.status[57].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[58].component, + greater.status[58].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[58].generic, greater.status[58].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[58].specific, + greater.status[58].specific); + comparison_tests(lesser, greater); + } + + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[59].component, + greater.status[59].component); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[59].generic, greater.status[59].generic); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.status[59].specific, + greater.status[59].specific); + comparison_tests(lesser, greater); + } + { + sbp_msg_status_report_t lesser = info.test_msg; + sbp_msg_status_report_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgStatusReport); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_STATUS_REPORT"); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_status_report_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_status_report_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.status_report, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.status_report, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_status_report_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgStatusReport, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_system_MsgStatusReport0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgStatusReport, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_system_system_structs.cc b/c/test/cpp/auto_check_sbp_system_system_structs.cc new file mode 100644 index 0000000000..cbff87d98f --- /dev/null +++ b/c/test/cpp/auto_check_sbp_system_system_structs.cc @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_system_structs.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_system_system_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_system_system_structs0() { + assign(test_struct_.component, 53869); + assign(test_struct_.generic, 81); + assign(test_struct_.specific, 106); + } + + struct TestStructInfo { + sbp_sub_system_report_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_sub_system_report_t test_struct_{}; + uint8_t encoded_data_[4] = { + 109, + 210, + 81, + 106, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_sub_system_report_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_sub_system_report_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_sub_system_report_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_sub_system_report_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_sub_system_report_t t{}; + EXPECT_EQ(sbp_sub_system_report_decode(info.encoded_data, 4, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_sub_system_report_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_sub_system_report_t t{}; + EXPECT_EQ(sbp_sub_system_report_decode(info.encoded_data, 4, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_sub_system_report_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs0, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_sub_system_report_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_sub_system_report_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_system_system_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_system_system_structs1() { + assign(test_struct_.report.component, 45733); + assign(test_struct_.report.generic, 205); + assign(test_struct_.report.specific, 203); + assign(test_struct_.uptime, 1251193470); + } + + struct TestStructInfo { + sbp_status_journal_item_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_status_journal_item_t test_struct_{}; + uint8_t encoded_data_[8] = { + 126, 178, 147, 74, 165, 178, 205, 203, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_status_journal_item_encoded_len(&info.test_struct), 8); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[8]; + EXPECT_EQ(sbp_status_journal_item_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + EXPECT_EQ(sbp_status_journal_item_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 8), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ( + sbp_status_journal_item_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_status_journal_item_t t{}; + EXPECT_EQ(sbp_status_journal_item_decode(info.encoded_data, 8, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_status_journal_item_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_status_journal_item_t t{}; + EXPECT_EQ(sbp_status_journal_item_decode(info.encoded_data, 8, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_status_journal_item_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_system_system_structs1, FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_status_journal_item_t t{}; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_status_journal_item_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_telemetry_MsgTelSv.cc b/c/test/cpp/auto_check_sbp_telemetry_MsgTelSv.cc index 3b29ba025b..af6209d237 100644 --- a/c/test/cpp/auto_check_sbp_telemetry_MsgTelSv.cc +++ b/c/test/cpp/auto_check_sbp_telemetry_MsgTelSv.cc @@ -16,148 +16,868 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_telemetry_MsgTelSv0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_telemetry_MsgTelSv0 : public ::testing::Test { public: - Test_auto_check_sbp_telemetry_MsgTelSv0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_telemetry_MsgTelSv0() { + assign(test_msg_.n_obs, 16); + assign(test_msg_.n_sv_tel, 1); + assign(test_msg_.origin_flags, 1); + + assign(test_msg_.sv_tel[0].availability_flags, 5); + assign(test_msg_.sv_tel[0].az, 40); + assign(test_msg_.sv_tel[0].correction_flags, 1); + assign(test_msg_.sv_tel[0].el, 50); + assign(test_msg_.sv_tel[0].ephemeris_flags, 1); + assign(test_msg_.sv_tel[0].outlier_flags, 1); + assign(test_msg_.sv_tel[0].phase_residual, 1); + assign(test_msg_.sv_tel[0].pseudorange_residual, -30); + assign(test_msg_.sv_tel[0].sid.code, 12); + assign(test_msg_.sv_tel[0].sid.sat, 33); + assign(test_msg_.tow, 406773200); + assign(test_msg_.wn, 2223); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tel_sv_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tel_sv_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTelSv, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tel_sv_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTelSv); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tel_sv, sizeof(msg->tel_sv)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tel_sv_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tel_sv, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTelSv); + info.sender_id = 9876; + info.preamble = 0x55; + info.crc = 0x6927; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 20; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tel_sv_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tel_sv_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_tel_sv_t &lesser, + const sbp_msg_tel_sv_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tel_sv_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tel_sv_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tel_sv_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tel_sv_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTelSv, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTelSv, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTelSv, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTelSv, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_telemetry_MsgTelSv0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tel_sv_t test_msg_{}; + uint8_t encoded_frame_[20 + 8] = { 85, 32, 1, 148, 38, 20, 175, 8, 208, 221, 62, 24, 16, 1, 40, 50, 5, 226, 255, 1, 0, 1, 1, 1, 33, 12, 39, 105, }; + uint8_t encoded_payload_[20] = { + 175, 8, 208, 221, 62, 24, 16, 1, 40, 50, + 5, 226, 255, 1, 0, 1, 1, 1, 33, 12, + }; +}; + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tel_sv_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTelSv, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_tel_sv_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgTelSv, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + EXPECT_EQ( + sbp_msg_tel_sv_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + + for (uint8_t i = 0; i < 20; i++) { + EXPECT_EQ(sbp_msg_tel_sv_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tel_sv_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tel_sv_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTelSv, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tel_sv_t msg{}; + + EXPECT_EQ(sbp_msg_tel_sv_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tel_sv_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tel_sv_t t{}; + return sbp_msg_tel_sv_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tel_sv_t t{}; + t.n_sv_tel = 1; + return sbp_msg_tel_sv_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tel_sv_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); - sbp_msg_tel_sv_t test_msg{}; - test_msg.n_obs = 16; - test_msg.n_sv_tel = 1; - test_msg.origin_flags = 1; - - test_msg.sv_tel[0].availability_flags = 5; - test_msg.sv_tel[0].az = 40; - test_msg.sv_tel[0].correction_flags = 1; - test_msg.sv_tel[0].el = 50; - test_msg.sv_tel[0].ephemeris_flags = 1; - test_msg.sv_tel[0].outlier_flags = 1; - test_msg.sv_tel[0].phase_residual = 1; - test_msg.sv_tel[0].pseudorange_residual = -30; - test_msg.sv_tel[0].sid.code = 12; - test_msg.sv_tel[0].sid.sat = 33; - test_msg.tow = 406773200; - test_msg.wn = 2223; - - EXPECT_EQ(send_message(9876, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 9876); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_obs, 16) - << "incorrect value for last_msg_.n_obs, expected 16, is " - << last_msg_.n_obs; - EXPECT_EQ(last_msg_.n_sv_tel, 1) - << "incorrect value for last_msg_.n_sv_tel, expected 1, is " - << last_msg_.n_sv_tel; - EXPECT_EQ(last_msg_.origin_flags, 1) - << "incorrect value for last_msg_.origin_flags, expected 1, is " - << last_msg_.origin_flags; - EXPECT_EQ(last_msg_.sv_tel[0].availability_flags, 5) - << "incorrect value for last_msg_.sv_tel[0].availability_flags, expected " - "5, is " - << last_msg_.sv_tel[0].availability_flags; - EXPECT_EQ(last_msg_.sv_tel[0].az, 40) - << "incorrect value for last_msg_.sv_tel[0].az, expected 40, is " - << last_msg_.sv_tel[0].az; - EXPECT_EQ(last_msg_.sv_tel[0].correction_flags, 1) - << "incorrect value for last_msg_.sv_tel[0].correction_flags, expected " - "1, is " - << last_msg_.sv_tel[0].correction_flags; - EXPECT_EQ(last_msg_.sv_tel[0].el, 50) - << "incorrect value for last_msg_.sv_tel[0].el, expected 50, is " - << last_msg_.sv_tel[0].el; - EXPECT_EQ(last_msg_.sv_tel[0].ephemeris_flags, 1) - << "incorrect value for last_msg_.sv_tel[0].ephemeris_flags, expected 1, " - "is " - << last_msg_.sv_tel[0].ephemeris_flags; - EXPECT_EQ(last_msg_.sv_tel[0].outlier_flags, 1) - << "incorrect value for last_msg_.sv_tel[0].outlier_flags, expected 1, " - "is " - << last_msg_.sv_tel[0].outlier_flags; - EXPECT_EQ(last_msg_.sv_tel[0].phase_residual, 1) - << "incorrect value for last_msg_.sv_tel[0].phase_residual, expected 1, " - "is " - << last_msg_.sv_tel[0].phase_residual; - EXPECT_EQ(last_msg_.sv_tel[0].pseudorange_residual, -30) - << "incorrect value for last_msg_.sv_tel[0].pseudorange_residual, " - "expected -30, is " - << last_msg_.sv_tel[0].pseudorange_residual; - EXPECT_EQ(last_msg_.sv_tel[0].sid.code, 12) - << "incorrect value for last_msg_.sv_tel[0].sid.code, expected 12, is " - << last_msg_.sv_tel[0].sid.code; - EXPECT_EQ(last_msg_.sv_tel[0].sid.sat, 33) - << "incorrect value for last_msg_.sv_tel[0].sid.sat, expected 33, is " - << last_msg_.sv_tel[0].sid.sat; - EXPECT_EQ(last_msg_.tow, 406773200) - << "incorrect value for last_msg_.tow, expected 406773200, is " - << last_msg_.tow; - EXPECT_EQ(last_msg_.wn, 2223) - << "incorrect value for last_msg_.wn, expected 2223, is " << last_msg_.wn; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } } + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tel_sv_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTelSv, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTelSv, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTelSv, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.n_obs, greater.n_obs); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.n_sv_tel, greater.n_sv_tel); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.origin_flags, greater.origin_flags); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].availability_flags, + greater.sv_tel[0].availability_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].az, greater.sv_tel[0].az); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].correction_flags, + greater.sv_tel[0].correction_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].el, greater.sv_tel[0].el); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].ephemeris_flags, + greater.sv_tel[0].ephemeris_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].outlier_flags, + greater.sv_tel[0].outlier_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].phase_residual, + greater.sv_tel[0].phase_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].pseudorange_residual, + greater.sv_tel[0].pseudorange_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].sid.code, greater.sv_tel[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.sv_tel[0].sid.sat, greater.sv_tel[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tel_sv_t lesser = info.test_msg; + sbp_msg_tel_sv_t greater = info.test_msg; + make_lesser_greater(lesser.wn, greater.wn); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgTelSv); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_TEL_SV"); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tel_sv_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tel_sv_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.tel_sv, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.tel_sv, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[20]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 20); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 20), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tel_sv_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 20); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTelSv, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_telemetry_MsgTelSv0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgTelSv, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_telemetry_acquisition_structs.cc b/c/test/cpp/auto_check_sbp_telemetry_acquisition_structs.cc new file mode 100644 index 0000000000..4ee2b4dd0d --- /dev/null +++ b/c/test/cpp/auto_check_sbp_telemetry_acquisition_structs.cc @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_acquisition_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_telemetry_acquisition_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_telemetry_acquisition_structs0() { + assign(test_struct_.bin_width, 47800); + assign(test_struct_.cf, 76658289); + assign(test_struct_.cf_max, 1240169926); + assign(test_struct_.cf_min, -1846717559); + assign(test_struct_.cn0, 6092); + assign(test_struct_.cp, 941027232); + assign(test_struct_.int_time, 224); + assign(test_struct_.job_type, 30); + assign(test_struct_.sid.code, 255); + assign(test_struct_.sid.sat, 125); + assign(test_struct_.status, 109); + assign(test_struct_.time_spent, 115890281); + assign(test_struct_.timestamp, 2936122286); + } + + struct TestStructInfo { + sbp_acq_sv_profile_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_acq_sv_profile_t test_struct_{}; + uint8_t encoded_data_[33] = { + 30, 109, 204, 23, 224, 125, 255, 184, 186, 174, 171, + 1, 175, 105, 88, 232, 6, 137, 83, 237, 145, 198, + 125, 235, 73, 113, 182, 145, 4, 160, 239, 22, 56, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_acq_sv_profile_encoded_len(&info.test_struct), 33); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[33]; + EXPECT_EQ(sbp_acq_sv_profile_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 33); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[33]; + EXPECT_EQ(sbp_acq_sv_profile_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 33), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[33]; + for (uint8_t i = 0; i < 33; i++) { + EXPECT_EQ(sbp_acq_sv_profile_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_acq_sv_profile_t t{}; + EXPECT_EQ(sbp_acq_sv_profile_decode(info.encoded_data, 33, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_acq_sv_profile_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_acq_sv_profile_t t{}; + EXPECT_EQ(sbp_acq_sv_profile_decode(info.encoded_data, 33, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_acq_sv_profile_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_acq_sv_profile_t t{}; + + for (uint8_t i = 0; i < 33; i++) { + EXPECT_EQ(sbp_acq_sv_profile_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_telemetry_acquisition_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_telemetry_acquisition_structs1() { + assign(test_struct_.bin_width, 39981); + assign(test_struct_.cf, 657970044); + assign(test_struct_.cf_max, 2142496829); + assign(test_struct_.cf_min, -1962679006); + assign(test_struct_.cn0, 3806); + assign(test_struct_.cp, 2715693981); + assign(test_struct_.int_time, 228); + assign(test_struct_.job_type, 100); + assign(test_struct_.sid.code, 153); + assign(test_struct_.sid.sat, 19540); + assign(test_struct_.status, 114); + assign(test_struct_.time_spent, 3609490020); + assign(test_struct_.timestamp, 3521954072); + } + + struct TestStructInfo { + sbp_acq_sv_profile_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_acq_sv_profile_dep_t test_struct_{}; + uint8_t encoded_data_[35] = { + 100, 114, 222, 14, 228, 84, 76, 153, 0, 45, 156, 24, + 193, 236, 209, 100, 114, 36, 215, 34, 229, 3, 139, 61, + 232, 179, 127, 124, 211, 55, 39, 157, 51, 222, 161, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_acq_sv_profile_dep_encoded_len(&info.test_struct), 35); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[35]; + EXPECT_EQ(sbp_acq_sv_profile_dep_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 35); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[35]; + EXPECT_EQ(sbp_acq_sv_profile_dep_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 35), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[35]; + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ( + sbp_acq_sv_profile_dep_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_acq_sv_profile_dep_t t{}; + EXPECT_EQ(sbp_acq_sv_profile_dep_decode(info.encoded_data, 35, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_acq_sv_profile_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_acq_sv_profile_dep_t t{}; + EXPECT_EQ(sbp_acq_sv_profile_dep_decode(info.encoded_data, 35, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_acq_sv_profile_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_acquisition_structs1, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_acq_sv_profile_dep_t t{}; + + for (uint8_t i = 0; i < 35; i++) { + EXPECT_EQ(sbp_acq_sv_profile_dep_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_telemetry_telemetry_structs.cc b/c/test/cpp/auto_check_sbp_telemetry_telemetry_structs.cc new file mode 100644 index 0000000000..af61d539d0 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_telemetry_telemetry_structs.cc @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/telemetry/test_telemetry_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_telemetry_telemetry_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_telemetry_telemetry_structs0() { + assign(test_struct_.availability_flags, 23); + assign(test_struct_.az, 65); + assign(test_struct_.correction_flags, 6); + assign(test_struct_.el, 96); + assign(test_struct_.ephemeris_flags, 52); + assign(test_struct_.outlier_flags, 37); + assign(test_struct_.phase_residual, -27718); + assign(test_struct_.pseudorange_residual, 17614); + assign(test_struct_.sid.code, 196); + assign(test_struct_.sid.sat, 88); + } + + struct TestStructInfo { + sbp_telemetry_sv_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_telemetry_sv_t test_struct_{}; + uint8_t encoded_data_[12] = { + 65, 96, 23, 206, 68, 186, 147, 37, 52, 6, 88, 196, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_telemetry_sv_encoded_len(&info.test_struct), 12); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[12]; + EXPECT_EQ(sbp_telemetry_sv_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 12); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[12]; + EXPECT_EQ( + sbp_telemetry_sv_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 12), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[12]; + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_telemetry_sv_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_telemetry_sv_t t{}; + EXPECT_EQ(sbp_telemetry_sv_decode(info.encoded_data, 12, &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_telemetry_sv_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_telemetry_sv_t t{}; + EXPECT_EQ(sbp_telemetry_sv_decode(info.encoded_data, 12, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_telemetry_sv_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_telemetry_telemetry_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_telemetry_sv_t t{}; + + for (uint8_t i = 0; i < 12; i++) { + EXPECT_EQ(sbp_telemetry_sv_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgMeasurementState.cc b/c/test/cpp/auto_check_sbp_tracking_MsgMeasurementState.cc index 397c9213cf..d0f3860869 100644 --- a/c/test/cpp/auto_check_sbp_tracking_MsgMeasurementState.cc +++ b/c/test/cpp/auto_check_sbp_tracking_MsgMeasurementState.cc @@ -16,66 +16,683 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_tracking_MsgMeasurementState0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgMeasurementState0 + : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgMeasurementState0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgMeasurementState0() { + assign(test_msg_.n_states, 79); + + assign(test_msg_.states[0].cn0, 162); + assign(test_msg_.states[0].mesid.code, 0); + assign(test_msg_.states[0].mesid.sat, 29); + + assign(test_msg_.states[1].cn0, 0); + assign(test_msg_.states[1].mesid.code, 0); + assign(test_msg_.states[1].mesid.sat, 0); + + assign(test_msg_.states[2].cn0, 0); + assign(test_msg_.states[2].mesid.code, 0); + assign(test_msg_.states[2].mesid.sat, 0); + + assign(test_msg_.states[3].cn0, 201); + assign(test_msg_.states[3].mesid.code, 0); + assign(test_msg_.states[3].mesid.sat, 27); + + assign(test_msg_.states[4].cn0, 168); + assign(test_msg_.states[4].mesid.code, 0); + assign(test_msg_.states[4].mesid.sat, 20); + + assign(test_msg_.states[5].cn0, 184); + assign(test_msg_.states[5].mesid.code, 0); + assign(test_msg_.states[5].mesid.sat, 32); + + assign(test_msg_.states[6].cn0, 187); + assign(test_msg_.states[6].mesid.code, 0); + assign(test_msg_.states[6].mesid.sat, 15); + + assign(test_msg_.states[7].cn0, 0); + assign(test_msg_.states[7].mesid.code, 0); + assign(test_msg_.states[7].mesid.sat, 0); + + assign(test_msg_.states[8].cn0, 210); + assign(test_msg_.states[8].mesid.code, 0); + assign(test_msg_.states[8].mesid.sat, 18); + + assign(test_msg_.states[9].cn0, 167); + assign(test_msg_.states[9].mesid.code, 0); + assign(test_msg_.states[9].mesid.sat, 16); + + assign(test_msg_.states[10].cn0, 0); + assign(test_msg_.states[10].mesid.code, 0); + assign(test_msg_.states[10].mesid.sat, 0); + + assign(test_msg_.states[11].cn0, 213); + assign(test_msg_.states[11].mesid.code, 0); + assign(test_msg_.states[11].mesid.sat, 23); + + assign(test_msg_.states[12].cn0, 223); + assign(test_msg_.states[12].mesid.code, 0); + assign(test_msg_.states[12].mesid.sat, 10); + + assign(test_msg_.states[13].cn0, 0); + assign(test_msg_.states[13].mesid.code, 0); + assign(test_msg_.states[13].mesid.sat, 0); + + assign(test_msg_.states[14].cn0, 0); + assign(test_msg_.states[14].mesid.code, 0); + assign(test_msg_.states[14].mesid.sat, 0); + + assign(test_msg_.states[15].cn0, 0); + assign(test_msg_.states[15].mesid.code, 0); + assign(test_msg_.states[15].mesid.sat, 0); + + assign(test_msg_.states[16].cn0, 0); + assign(test_msg_.states[16].mesid.code, 0); + assign(test_msg_.states[16].mesid.sat, 0); + + assign(test_msg_.states[17].cn0, 202); + assign(test_msg_.states[17].mesid.code, 2); + assign(test_msg_.states[17].mesid.sat, 131); + + assign(test_msg_.states[18].cn0, 192); + assign(test_msg_.states[18].mesid.code, 1); + assign(test_msg_.states[18].mesid.sat, 27); + + assign(test_msg_.states[19].cn0, 165); + assign(test_msg_.states[19].mesid.code, 1); + assign(test_msg_.states[19].mesid.sat, 15); + + assign(test_msg_.states[20].cn0, 146); + assign(test_msg_.states[20].mesid.code, 1); + assign(test_msg_.states[20].mesid.sat, 29); + + assign(test_msg_.states[21].cn0, 170); + assign(test_msg_.states[21].mesid.code, 1); + assign(test_msg_.states[21].mesid.sat, 32); + + assign(test_msg_.states[22].cn0, 201); + assign(test_msg_.states[22].mesid.code, 1); + assign(test_msg_.states[22].mesid.sat, 18); + + assign(test_msg_.states[23].cn0, 0); + assign(test_msg_.states[23].mesid.code, 0); + assign(test_msg_.states[23].mesid.sat, 0); + + assign(test_msg_.states[24].cn0, 0); + assign(test_msg_.states[24].mesid.code, 0); + assign(test_msg_.states[24].mesid.sat, 0); + + assign(test_msg_.states[25].cn0, 0); + assign(test_msg_.states[25].mesid.code, 0); + assign(test_msg_.states[25].mesid.sat, 0); + + assign(test_msg_.states[26].cn0, 212); + assign(test_msg_.states[26].mesid.code, 1); + assign(test_msg_.states[26].mesid.sat, 23); + + assign(test_msg_.states[27].cn0, 205); + assign(test_msg_.states[27].mesid.code, 1); + assign(test_msg_.states[27].mesid.sat, 10); + + assign(test_msg_.states[28].cn0, 0); + assign(test_msg_.states[28].mesid.code, 0); + assign(test_msg_.states[28].mesid.sat, 0); + + assign(test_msg_.states[29].cn0, 230); + assign(test_msg_.states[29].mesid.code, 3); + assign(test_msg_.states[29].mesid.sat, 96); + + assign(test_msg_.states[30].cn0, 0); + assign(test_msg_.states[30].mesid.code, 0); + assign(test_msg_.states[30].mesid.sat, 0); + + assign(test_msg_.states[31].cn0, 214); + assign(test_msg_.states[31].mesid.code, 3); + assign(test_msg_.states[31].mesid.sat, 101); + + assign(test_msg_.states[32].cn0, 212); + assign(test_msg_.states[32].mesid.code, 3); + assign(test_msg_.states[32].mesid.sat, 103); + + assign(test_msg_.states[33].cn0, 209); + assign(test_msg_.states[33].mesid.code, 3); + assign(test_msg_.states[33].mesid.sat, 104); + + assign(test_msg_.states[34].cn0, 157); + assign(test_msg_.states[34].mesid.code, 3); + assign(test_msg_.states[34].mesid.sat, 106); + + assign(test_msg_.states[35].cn0, 230); + assign(test_msg_.states[35].mesid.code, 3); + assign(test_msg_.states[35].mesid.sat, 102); + + assign(test_msg_.states[36].cn0, 0); + assign(test_msg_.states[36].mesid.code, 0); + assign(test_msg_.states[36].mesid.sat, 0); + + assign(test_msg_.states[37].cn0, 0); + assign(test_msg_.states[37].mesid.code, 0); + assign(test_msg_.states[37].mesid.sat, 0); + + assign(test_msg_.states[38].cn0, 189); + assign(test_msg_.states[38].mesid.code, 4); + assign(test_msg_.states[38].mesid.sat, 101); + + assign(test_msg_.states[39].cn0, 207); + assign(test_msg_.states[39].mesid.code, 4); + assign(test_msg_.states[39].mesid.sat, 96); + + assign(test_msg_.states[40].cn0, 164); + assign(test_msg_.states[40].mesid.code, 4); + assign(test_msg_.states[40].mesid.sat, 106); + + assign(test_msg_.states[41].cn0, 193); + assign(test_msg_.states[41].mesid.code, 4); + assign(test_msg_.states[41].mesid.sat, 104); + + assign(test_msg_.states[42].cn0, 0); + assign(test_msg_.states[42].mesid.code, 0); + assign(test_msg_.states[42].mesid.sat, 0); + + assign(test_msg_.states[43].cn0, 208); + assign(test_msg_.states[43].mesid.code, 4); + assign(test_msg_.states[43].mesid.sat, 102); + + assign(test_msg_.states[44].cn0, 0); + assign(test_msg_.states[44].mesid.code, 0); + assign(test_msg_.states[44].mesid.sat, 0); + + assign(test_msg_.states[45].cn0, 212); + assign(test_msg_.states[45].mesid.code, 12); + assign(test_msg_.states[45].mesid.sat, 27); + + assign(test_msg_.states[46].cn0, 161); + assign(test_msg_.states[46].mesid.code, 12); + assign(test_msg_.states[46].mesid.sat, 29); + + assign(test_msg_.states[47].cn0, 216); + assign(test_msg_.states[47].mesid.code, 12); + assign(test_msg_.states[47].mesid.sat, 32); + + assign(test_msg_.states[48].cn0, 216); + assign(test_msg_.states[48].mesid.code, 12); + assign(test_msg_.states[48].mesid.sat, 30); + + assign(test_msg_.states[49].cn0, 178); + assign(test_msg_.states[49].mesid.code, 12); + assign(test_msg_.states[49].mesid.sat, 20); + + assign(test_msg_.states[50].cn0, 0); + assign(test_msg_.states[50].mesid.code, 0); + assign(test_msg_.states[50].mesid.sat, 0); + + assign(test_msg_.states[51].cn0, 0); + assign(test_msg_.states[51].mesid.code, 0); + assign(test_msg_.states[51].mesid.sat, 0); + + assign(test_msg_.states[52].cn0, 0); + assign(test_msg_.states[52].mesid.code, 0); + assign(test_msg_.states[52].mesid.sat, 0); + + assign(test_msg_.states[53].cn0, 0); + assign(test_msg_.states[53].mesid.code, 0); + assign(test_msg_.states[53].mesid.sat, 0); + + assign(test_msg_.states[54].cn0, 0); + assign(test_msg_.states[54].mesid.code, 0); + assign(test_msg_.states[54].mesid.sat, 0); + + assign(test_msg_.states[55].cn0, 0); + assign(test_msg_.states[55].mesid.code, 0); + assign(test_msg_.states[55].mesid.sat, 0); + + assign(test_msg_.states[56].cn0, 0); + assign(test_msg_.states[56].mesid.code, 0); + assign(test_msg_.states[56].mesid.sat, 0); + + assign(test_msg_.states[57].cn0, 0); + assign(test_msg_.states[57].mesid.code, 0); + assign(test_msg_.states[57].mesid.sat, 0); + + assign(test_msg_.states[58].cn0, 0); + assign(test_msg_.states[58].mesid.code, 0); + assign(test_msg_.states[58].mesid.sat, 0); + + assign(test_msg_.states[59].cn0, 0); + assign(test_msg_.states[59].mesid.code, 0); + assign(test_msg_.states[59].mesid.sat, 0); + + assign(test_msg_.states[60].cn0, 0); + assign(test_msg_.states[60].mesid.code, 0); + assign(test_msg_.states[60].mesid.sat, 0); + + assign(test_msg_.states[61].cn0, 0); + assign(test_msg_.states[61].mesid.code, 0); + assign(test_msg_.states[61].mesid.sat, 0); + + assign(test_msg_.states[62].cn0, 0); + assign(test_msg_.states[62].mesid.code, 0); + assign(test_msg_.states[62].mesid.sat, 0); + + assign(test_msg_.states[63].cn0, 203); + assign(test_msg_.states[63].mesid.code, 14); + assign(test_msg_.states[63].mesid.sat, 36); + + assign(test_msg_.states[64].cn0, 0); + assign(test_msg_.states[64].mesid.code, 0); + assign(test_msg_.states[64].mesid.sat, 0); + + assign(test_msg_.states[65].cn0, 158); + assign(test_msg_.states[65].mesid.code, 14); + assign(test_msg_.states[65].mesid.sat, 5); + + assign(test_msg_.states[66].cn0, 194); + assign(test_msg_.states[66].mesid.code, 14); + assign(test_msg_.states[66].mesid.sat, 4); + + assign(test_msg_.states[67].cn0, 192); + assign(test_msg_.states[67].mesid.code, 14); + assign(test_msg_.states[67].mesid.sat, 11); + + assign(test_msg_.states[68].cn0, 207); + assign(test_msg_.states[68].mesid.code, 14); + assign(test_msg_.states[68].mesid.sat, 9); + + assign(test_msg_.states[69].cn0, 0); + assign(test_msg_.states[69].mesid.code, 0); + assign(test_msg_.states[69].mesid.sat, 0); + + assign(test_msg_.states[70].cn0, 0); + assign(test_msg_.states[70].mesid.code, 0); + assign(test_msg_.states[70].mesid.sat, 0); + + assign(test_msg_.states[71].cn0, 0); + assign(test_msg_.states[71].mesid.code, 0); + assign(test_msg_.states[71].mesid.sat, 0); + + assign(test_msg_.states[72].cn0, 218); + assign(test_msg_.states[72].mesid.code, 20); + assign(test_msg_.states[72].mesid.sat, 9); + + assign(test_msg_.states[73].cn0, 176); + assign(test_msg_.states[73].mesid.code, 20); + assign(test_msg_.states[73].mesid.sat, 5); + + assign(test_msg_.states[74].cn0, 217); + assign(test_msg_.states[74].mesid.code, 20); + assign(test_msg_.states[74].mesid.sat, 36); + + assign(test_msg_.states[75].cn0, 200); + assign(test_msg_.states[75].mesid.code, 20); + assign(test_msg_.states[75].mesid.sat, 11); + + assign(test_msg_.states[76].cn0, 205); + assign(test_msg_.states[76].mesid.code, 20); + assign(test_msg_.states[76].mesid.sat, 4); + + assign(test_msg_.states[77].cn0, 0); + assign(test_msg_.states[77].mesid.code, 0); + assign(test_msg_.states[77].mesid.sat, 0); + + assign(test_msg_.states[78].cn0, 0); + assign(test_msg_.states[78].mesid.code, 0); + assign(test_msg_.states[78].mesid.sat, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_measurement_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_measurement_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgMeasurementState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_measurement_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgMeasurementState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->measurement_state, + sizeof(msg->measurement_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_measurement_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.measurement_state, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgMeasurementState); + info.sender_id = 31183; + info.preamble = 0x55; + info.crc = 0x3623; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 237; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_measurement_state_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_measurement_state_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_measurement_state_t &lesser, + const sbp_msg_measurement_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_measurement_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_measurement_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_measurement_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_measurement_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgMeasurementState, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgMeasurementState, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgMeasurementState, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgMeasurementState, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } -TEST_F(Test_auto_check_sbp_tracking_MsgMeasurementState0, Test) { - uint8_t encoded_frame[] = { + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_measurement_state_t test_msg_{}; + uint8_t encoded_frame_[237 + 8] = { 85, 97, 0, 207, 121, 237, 29, 0, 162, 0, 0, 0, 0, 0, 0, 27, 0, 201, 20, 0, 168, 32, 0, 184, 15, 0, 187, 0, 0, 0, 18, 0, 210, 16, 0, 167, 0, 0, 0, 23, 0, 213, 10, 0, 223, @@ -94,1050 +711,2098 @@ TEST_F(Test_auto_check_sbp_tracking_MsgMeasurementState0, Test) { 5, 20, 176, 36, 20, 217, 11, 20, 200, 4, 20, 205, 0, 0, 0, 0, 0, 0, 35, 54, }; + uint8_t encoded_payload_[237] = { + 29, 0, 162, 0, 0, 0, 0, 0, 0, 27, 0, 201, 20, 0, 168, + 32, 0, 184, 15, 0, 187, 0, 0, 0, 18, 0, 210, 16, 0, 167, + 0, 0, 0, 23, 0, 213, 10, 0, 223, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 131, 2, 202, 27, 1, 192, 15, 1, 165, + 29, 1, 146, 32, 1, 170, 18, 1, 201, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 23, 1, 212, 10, 1, 205, 0, 0, 0, 96, 3, 230, + 0, 0, 0, 101, 3, 214, 103, 3, 212, 104, 3, 209, 106, 3, 157, + 102, 3, 230, 0, 0, 0, 0, 0, 0, 101, 4, 189, 96, 4, 207, + 106, 4, 164, 104, 4, 193, 0, 0, 0, 102, 4, 208, 0, 0, 0, + 27, 12, 212, 29, 12, 161, 32, 12, 216, 30, 12, 216, 20, 12, 178, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 14, 203, 0, 0, 0, + 5, 14, 158, 4, 14, 194, 11, 14, 192, 9, 14, 207, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 9, 20, 218, 5, 20, 176, 36, 20, 217, + 11, 20, 200, 4, 20, 205, 0, 0, 0, 0, 0, 0, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_measurement_state_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgMeasurementState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[237]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_measurement_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 237); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 237), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgMeasurementState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 237); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 237), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[237]; + + EXPECT_EQ(sbp_msg_measurement_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 237), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[237]; + + for (uint8_t i = 0; i < 237; i++) { + EXPECT_EQ( + sbp_msg_measurement_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_measurement_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_measurement_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 237); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgMeasurementState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 237); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_measurement_state_t msg{}; + + EXPECT_EQ(sbp_msg_measurement_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_measurement_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_measurement_state_t t{}; + return sbp_msg_measurement_state_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_measurement_state_t t{}; + t.n_states = 1; + return sbp_msg_measurement_state_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_measurement_state_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } - sbp_msg_measurement_state_t test_msg{}; - test_msg.n_states = 79; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.states[0].cn0 = 162; - test_msg.states[0].mesid.code = 0; - test_msg.states[0].mesid.sat = 29; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.states[1].cn0 = 0; - test_msg.states[1].mesid.code = 0; - test_msg.states[1].mesid.sat = 0; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[2].cn0 = 0; - test_msg.states[2].mesid.code = 0; - test_msg.states[2].mesid.sat = 0; + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); - test_msg.states[3].cn0 = 201; - test_msg.states[3].mesid.code = 0; - test_msg.states[3].mesid.sat = 27; + CHandler handler(&state); - test_msg.states[4].cn0 = 168; - test_msg.states[4].mesid.code = 0; - test_msg.states[4].mesid.sat = 20; + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } - test_msg.states[5].cn0 = 184; - test_msg.states[5].mesid.code = 0; - test_msg.states[5].mesid.sat = 32; + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - test_msg.states[6].cn0 = 187; - test_msg.states[6].mesid.code = 0; - test_msg.states[6].mesid.sat = 15; + EXPECT_EQ(handler.outputs.size(), 0); + } +} - test_msg.states[7].cn0 = 0; - test_msg.states[7].mesid.code = 0; - test_msg.states[7].mesid.sat = 0; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[8].cn0 = 210; - test_msg.states[8].mesid.code = 0; - test_msg.states[8].mesid.sat = 18; + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); - test_msg.states[9].cn0 = 167; - test_msg.states[9].mesid.code = 0; - test_msg.states[9].mesid.sat = 16; + CHandler handler{&state}; - test_msg.states[10].cn0 = 0; - test_msg.states[10].mesid.code = 0; - test_msg.states[10].mesid.sat = 0; + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } - test_msg.states[11].cn0 = 213; - test_msg.states[11].mesid.code = 0; - test_msg.states[11].mesid.sat = 23; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} - test_msg.states[12].cn0 = 223; - test_msg.states[12].mesid.code = 0; - test_msg.states[12].mesid.sat = 10; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); - test_msg.states[13].cn0 = 0; - test_msg.states[13].mesid.code = 0; - test_msg.states[13].mesid.sat = 0; + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; - test_msg.states[14].cn0 = 0; - test_msg.states[14].mesid.code = 0; - test_msg.states[14].mesid.sat = 0; + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[15].cn0 = 0; - test_msg.states[15].mesid.code = 0; - test_msg.states[15].mesid.sat = 0; + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); - test_msg.states[16].cn0 = 0; - test_msg.states[16].mesid.code = 0; - test_msg.states[16].mesid.sat = 0; + CHandler handler{&state}; - test_msg.states[17].cn0 = 202; - test_msg.states[17].mesid.code = 2; - test_msg.states[17].mesid.sat = 131; + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } - test_msg.states[18].cn0 = 192; - test_msg.states[18].mesid.code = 1; - test_msg.states[18].mesid.sat = 27; + EXPECT_EQ(handler.outputs.size(), 0); +} - test_msg.states[19].cn0 = 165; - test_msg.states[19].mesid.code = 1; - test_msg.states[19].mesid.sat = 15; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[20].cn0 = 146; - test_msg.states[20].mesid.code = 1; - test_msg.states[20].mesid.sat = 29; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.states[21].cn0 = 170; - test_msg.states[21].mesid.code = 1; - test_msg.states[21].mesid.sat = 32; + EXPECT_EQ(sbp_msg_measurement_state_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} - test_msg.states[22].cn0 = 201; - test_msg.states[22].mesid.code = 1; - test_msg.states[22].mesid.sat = 18; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[23].cn0 = 0; - test_msg.states[23].mesid.code = 0; - test_msg.states[23].mesid.sat = 0; + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - test_msg.states[24].cn0 = 0; - test_msg.states[24].mesid.code = 0; - test_msg.states[24].mesid.sat = 0; + EXPECT_EQ(sbp_message_send(&state, SbpMsgMeasurementState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - test_msg.states[25].cn0 = 0; - test_msg.states[25].mesid.code = 0; - test_msg.states[25].mesid.sat = 0; + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); - test_msg.states[26].cn0 = 212; - test_msg.states[26].mesid.code = 1; - test_msg.states[26].mesid.sat = 23; + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); - test_msg.states[27].cn0 = 205; - test_msg.states[27].mesid.code = 1; - test_msg.states[27].mesid.sat = 10; + EXPECT_NE(sbp_message_send(&state, SbpMsgMeasurementState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} - test_msg.states[28].cn0 = 0; - test_msg.states[28].mesid.code = 0; - test_msg.states[28].mesid.sat = 0; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgMeasurementState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - test_msg.states[29].cn0 = 230; - test_msg.states[29].mesid.code = 3; - test_msg.states[29].mesid.sat = 96; +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } - test_msg.states[30].cn0 = 0; - test_msg.states[30].mesid.code = 0; - test_msg.states[30].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].mesid.code, + greater.states[0].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].mesid.sat, + greater.states[0].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[31].cn0 = 214; - test_msg.states[31].mesid.code = 3; - test_msg.states[31].mesid.sat = 101; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].mesid.code, + greater.states[1].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].mesid.sat, + greater.states[1].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[32].cn0 = 212; - test_msg.states[32].mesid.code = 3; - test_msg.states[32].mesid.sat = 103; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].mesid.code, + greater.states[2].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].mesid.sat, + greater.states[2].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[33].cn0 = 209; - test_msg.states[33].mesid.code = 3; - test_msg.states[33].mesid.sat = 104; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].mesid.code, + greater.states[3].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].mesid.sat, + greater.states[3].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[34].cn0 = 157; - test_msg.states[34].mesid.code = 3; - test_msg.states[34].mesid.sat = 106; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].mesid.code, + greater.states[4].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].mesid.sat, + greater.states[4].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[35].cn0 = 230; - test_msg.states[35].mesid.code = 3; - test_msg.states[35].mesid.sat = 102; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].mesid.code, + greater.states[5].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].mesid.sat, + greater.states[5].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[36].cn0 = 0; - test_msg.states[36].mesid.code = 0; - test_msg.states[36].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].mesid.code, + greater.states[6].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].mesid.sat, + greater.states[6].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[37].cn0 = 0; - test_msg.states[37].mesid.code = 0; - test_msg.states[37].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].mesid.code, + greater.states[7].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].mesid.sat, + greater.states[7].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[38].cn0 = 189; - test_msg.states[38].mesid.code = 4; - test_msg.states[38].mesid.sat = 101; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].mesid.code, + greater.states[8].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].mesid.sat, + greater.states[8].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[39].cn0 = 207; - test_msg.states[39].mesid.code = 4; - test_msg.states[39].mesid.sat = 96; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].mesid.code, + greater.states[9].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].mesid.sat, + greater.states[9].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[40].cn0 = 164; - test_msg.states[40].mesid.code = 4; - test_msg.states[40].mesid.sat = 106; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].mesid.code, + greater.states[10].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].mesid.sat, + greater.states[10].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[41].cn0 = 193; - test_msg.states[41].mesid.code = 4; - test_msg.states[41].mesid.sat = 104; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].cn0, greater.states[11].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].mesid.code, + greater.states[11].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].mesid.sat, + greater.states[11].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[42].cn0 = 0; - test_msg.states[42].mesid.code = 0; - test_msg.states[42].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].cn0, greater.states[12].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].mesid.code, + greater.states[12].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].mesid.sat, + greater.states[12].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[43].cn0 = 208; - test_msg.states[43].mesid.code = 4; - test_msg.states[43].mesid.sat = 102; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].cn0, greater.states[13].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].mesid.code, + greater.states[13].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].mesid.sat, + greater.states[13].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[44].cn0 = 0; - test_msg.states[44].mesid.code = 0; - test_msg.states[44].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].cn0, greater.states[14].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].mesid.code, + greater.states[14].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].mesid.sat, + greater.states[14].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[45].cn0 = 212; - test_msg.states[45].mesid.code = 12; - test_msg.states[45].mesid.sat = 27; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].cn0, greater.states[15].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].mesid.code, + greater.states[15].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].mesid.sat, + greater.states[15].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[46].cn0 = 161; - test_msg.states[46].mesid.code = 12; - test_msg.states[46].mesid.sat = 29; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].cn0, greater.states[16].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].mesid.code, + greater.states[16].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].mesid.sat, + greater.states[16].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[47].cn0 = 216; - test_msg.states[47].mesid.code = 12; - test_msg.states[47].mesid.sat = 32; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].cn0, greater.states[17].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].mesid.code, + greater.states[17].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].mesid.sat, + greater.states[17].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[48].cn0 = 216; - test_msg.states[48].mesid.code = 12; - test_msg.states[48].mesid.sat = 30; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].cn0, greater.states[18].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].mesid.code, + greater.states[18].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].mesid.sat, + greater.states[18].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[49].cn0 = 178; - test_msg.states[49].mesid.code = 12; - test_msg.states[49].mesid.sat = 20; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].cn0, greater.states[19].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].mesid.code, + greater.states[19].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].mesid.sat, + greater.states[19].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[50].cn0 = 0; - test_msg.states[50].mesid.code = 0; - test_msg.states[50].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].cn0, greater.states[20].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].mesid.code, + greater.states[20].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].mesid.sat, + greater.states[20].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[51].cn0 = 0; - test_msg.states[51].mesid.code = 0; - test_msg.states[51].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].cn0, greater.states[21].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].mesid.code, + greater.states[21].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].mesid.sat, + greater.states[21].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[52].cn0 = 0; - test_msg.states[52].mesid.code = 0; - test_msg.states[52].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].cn0, greater.states[22].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].mesid.code, + greater.states[22].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].mesid.sat, + greater.states[22].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[53].cn0 = 0; - test_msg.states[53].mesid.code = 0; - test_msg.states[53].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].cn0, greater.states[23].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].mesid.code, + greater.states[23].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].mesid.sat, + greater.states[23].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[54].cn0 = 0; - test_msg.states[54].mesid.code = 0; - test_msg.states[54].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].cn0, greater.states[24].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].mesid.code, + greater.states[24].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].mesid.sat, + greater.states[24].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[55].cn0 = 0; - test_msg.states[55].mesid.code = 0; - test_msg.states[55].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].cn0, greater.states[25].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].mesid.code, + greater.states[25].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].mesid.sat, + greater.states[25].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[56].cn0 = 0; - test_msg.states[56].mesid.code = 0; - test_msg.states[56].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].cn0, greater.states[26].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].mesid.code, + greater.states[26].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].mesid.sat, + greater.states[26].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[57].cn0 = 0; - test_msg.states[57].mesid.code = 0; - test_msg.states[57].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].cn0, greater.states[27].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].mesid.code, + greater.states[27].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].mesid.sat, + greater.states[27].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[58].cn0 = 0; - test_msg.states[58].mesid.code = 0; - test_msg.states[58].mesid.sat = 0; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].cn0, greater.states[28].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].mesid.code, + greater.states[28].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].mesid.sat, + greater.states[28].mesid.sat); + comparison_tests(lesser, greater); + } - test_msg.states[59].cn0 = 0; - test_msg.states[59].mesid.code = 0; - test_msg.states[59].mesid.sat = 0; - - test_msg.states[60].cn0 = 0; - test_msg.states[60].mesid.code = 0; - test_msg.states[60].mesid.sat = 0; - - test_msg.states[61].cn0 = 0; - test_msg.states[61].mesid.code = 0; - test_msg.states[61].mesid.sat = 0; - - test_msg.states[62].cn0 = 0; - test_msg.states[62].mesid.code = 0; - test_msg.states[62].mesid.sat = 0; - - test_msg.states[63].cn0 = 203; - test_msg.states[63].mesid.code = 14; - test_msg.states[63].mesid.sat = 36; - - test_msg.states[64].cn0 = 0; - test_msg.states[64].mesid.code = 0; - test_msg.states[64].mesid.sat = 0; - - test_msg.states[65].cn0 = 158; - test_msg.states[65].mesid.code = 14; - test_msg.states[65].mesid.sat = 5; - - test_msg.states[66].cn0 = 194; - test_msg.states[66].mesid.code = 14; - test_msg.states[66].mesid.sat = 4; - - test_msg.states[67].cn0 = 192; - test_msg.states[67].mesid.code = 14; - test_msg.states[67].mesid.sat = 11; - - test_msg.states[68].cn0 = 207; - test_msg.states[68].mesid.code = 14; - test_msg.states[68].mesid.sat = 9; - - test_msg.states[69].cn0 = 0; - test_msg.states[69].mesid.code = 0; - test_msg.states[69].mesid.sat = 0; - - test_msg.states[70].cn0 = 0; - test_msg.states[70].mesid.code = 0; - test_msg.states[70].mesid.sat = 0; - - test_msg.states[71].cn0 = 0; - test_msg.states[71].mesid.code = 0; - test_msg.states[71].mesid.sat = 0; - - test_msg.states[72].cn0 = 218; - test_msg.states[72].mesid.code = 20; - test_msg.states[72].mesid.sat = 9; - - test_msg.states[73].cn0 = 176; - test_msg.states[73].mesid.code = 20; - test_msg.states[73].mesid.sat = 5; - - test_msg.states[74].cn0 = 217; - test_msg.states[74].mesid.code = 20; - test_msg.states[74].mesid.sat = 36; - - test_msg.states[75].cn0 = 200; - test_msg.states[75].mesid.code = 20; - test_msg.states[75].mesid.sat = 11; - - test_msg.states[76].cn0 = 205; - test_msg.states[76].mesid.code = 20; - test_msg.states[76].mesid.sat = 4; - - test_msg.states[77].cn0 = 0; - test_msg.states[77].mesid.code = 0; - test_msg.states[77].mesid.sat = 0; - - test_msg.states[78].cn0 = 0; - test_msg.states[78].mesid.code = 0; - test_msg.states[78].mesid.sat = 0; - - EXPECT_EQ(send_message(31183, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 31183); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 79) - << "incorrect value for last_msg_.n_states, expected 79, is " - << last_msg_.n_states; - EXPECT_EQ(last_msg_.states[0].cn0, 162) - << "incorrect value for last_msg_.states[0].cn0, expected 162, is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].mesid.code, 0) - << "incorrect value for last_msg_.states[0].mesid.code, expected 0, is " - << last_msg_.states[0].mesid.code; - EXPECT_EQ(last_msg_.states[0].mesid.sat, 29) - << "incorrect value for last_msg_.states[0].mesid.sat, expected 29, is " - << last_msg_.states[0].mesid.sat; - EXPECT_EQ(last_msg_.states[1].cn0, 0) - << "incorrect value for last_msg_.states[1].cn0, expected 0, is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].mesid.code, 0) - << "incorrect value for last_msg_.states[1].mesid.code, expected 0, is " - << last_msg_.states[1].mesid.code; - EXPECT_EQ(last_msg_.states[1].mesid.sat, 0) - << "incorrect value for last_msg_.states[1].mesid.sat, expected 0, is " - << last_msg_.states[1].mesid.sat; - EXPECT_EQ(last_msg_.states[2].cn0, 0) - << "incorrect value for last_msg_.states[2].cn0, expected 0, is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].mesid.code, 0) - << "incorrect value for last_msg_.states[2].mesid.code, expected 0, is " - << last_msg_.states[2].mesid.code; - EXPECT_EQ(last_msg_.states[2].mesid.sat, 0) - << "incorrect value for last_msg_.states[2].mesid.sat, expected 0, is " - << last_msg_.states[2].mesid.sat; - EXPECT_EQ(last_msg_.states[3].cn0, 201) - << "incorrect value for last_msg_.states[3].cn0, expected 201, is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].mesid.code, 0) - << "incorrect value for last_msg_.states[3].mesid.code, expected 0, is " - << last_msg_.states[3].mesid.code; - EXPECT_EQ(last_msg_.states[3].mesid.sat, 27) - << "incorrect value for last_msg_.states[3].mesid.sat, expected 27, is " - << last_msg_.states[3].mesid.sat; - EXPECT_EQ(last_msg_.states[4].cn0, 168) - << "incorrect value for last_msg_.states[4].cn0, expected 168, is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].mesid.code, 0) - << "incorrect value for last_msg_.states[4].mesid.code, expected 0, is " - << last_msg_.states[4].mesid.code; - EXPECT_EQ(last_msg_.states[4].mesid.sat, 20) - << "incorrect value for last_msg_.states[4].mesid.sat, expected 20, is " - << last_msg_.states[4].mesid.sat; - EXPECT_EQ(last_msg_.states[5].cn0, 184) - << "incorrect value for last_msg_.states[5].cn0, expected 184, is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].mesid.code, 0) - << "incorrect value for last_msg_.states[5].mesid.code, expected 0, is " - << last_msg_.states[5].mesid.code; - EXPECT_EQ(last_msg_.states[5].mesid.sat, 32) - << "incorrect value for last_msg_.states[5].mesid.sat, expected 32, is " - << last_msg_.states[5].mesid.sat; - EXPECT_EQ(last_msg_.states[6].cn0, 187) - << "incorrect value for last_msg_.states[6].cn0, expected 187, is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].mesid.code, 0) - << "incorrect value for last_msg_.states[6].mesid.code, expected 0, is " - << last_msg_.states[6].mesid.code; - EXPECT_EQ(last_msg_.states[6].mesid.sat, 15) - << "incorrect value for last_msg_.states[6].mesid.sat, expected 15, is " - << last_msg_.states[6].mesid.sat; - EXPECT_EQ(last_msg_.states[7].cn0, 0) - << "incorrect value for last_msg_.states[7].cn0, expected 0, is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].mesid.code, 0) - << "incorrect value for last_msg_.states[7].mesid.code, expected 0, is " - << last_msg_.states[7].mesid.code; - EXPECT_EQ(last_msg_.states[7].mesid.sat, 0) - << "incorrect value for last_msg_.states[7].mesid.sat, expected 0, is " - << last_msg_.states[7].mesid.sat; - EXPECT_EQ(last_msg_.states[8].cn0, 210) - << "incorrect value for last_msg_.states[8].cn0, expected 210, is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].mesid.code, 0) - << "incorrect value for last_msg_.states[8].mesid.code, expected 0, is " - << last_msg_.states[8].mesid.code; - EXPECT_EQ(last_msg_.states[8].mesid.sat, 18) - << "incorrect value for last_msg_.states[8].mesid.sat, expected 18, is " - << last_msg_.states[8].mesid.sat; - EXPECT_EQ(last_msg_.states[9].cn0, 167) - << "incorrect value for last_msg_.states[9].cn0, expected 167, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].mesid.code, 0) - << "incorrect value for last_msg_.states[9].mesid.code, expected 0, is " - << last_msg_.states[9].mesid.code; - EXPECT_EQ(last_msg_.states[9].mesid.sat, 16) - << "incorrect value for last_msg_.states[9].mesid.sat, expected 16, is " - << last_msg_.states[9].mesid.sat; - EXPECT_EQ(last_msg_.states[10].cn0, 0) - << "incorrect value for last_msg_.states[10].cn0, expected 0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].mesid.code, 0) - << "incorrect value for last_msg_.states[10].mesid.code, expected 0, is " - << last_msg_.states[10].mesid.code; - EXPECT_EQ(last_msg_.states[10].mesid.sat, 0) - << "incorrect value for last_msg_.states[10].mesid.sat, expected 0, is " - << last_msg_.states[10].mesid.sat; - EXPECT_EQ(last_msg_.states[11].cn0, 213) - << "incorrect value for last_msg_.states[11].cn0, expected 213, is " - << last_msg_.states[11].cn0; - EXPECT_EQ(last_msg_.states[11].mesid.code, 0) - << "incorrect value for last_msg_.states[11].mesid.code, expected 0, is " - << last_msg_.states[11].mesid.code; - EXPECT_EQ(last_msg_.states[11].mesid.sat, 23) - << "incorrect value for last_msg_.states[11].mesid.sat, expected 23, is " - << last_msg_.states[11].mesid.sat; - EXPECT_EQ(last_msg_.states[12].cn0, 223) - << "incorrect value for last_msg_.states[12].cn0, expected 223, is " - << last_msg_.states[12].cn0; - EXPECT_EQ(last_msg_.states[12].mesid.code, 0) - << "incorrect value for last_msg_.states[12].mesid.code, expected 0, is " - << last_msg_.states[12].mesid.code; - EXPECT_EQ(last_msg_.states[12].mesid.sat, 10) - << "incorrect value for last_msg_.states[12].mesid.sat, expected 10, is " - << last_msg_.states[12].mesid.sat; - EXPECT_EQ(last_msg_.states[13].cn0, 0) - << "incorrect value for last_msg_.states[13].cn0, expected 0, is " - << last_msg_.states[13].cn0; - EXPECT_EQ(last_msg_.states[13].mesid.code, 0) - << "incorrect value for last_msg_.states[13].mesid.code, expected 0, is " - << last_msg_.states[13].mesid.code; - EXPECT_EQ(last_msg_.states[13].mesid.sat, 0) - << "incorrect value for last_msg_.states[13].mesid.sat, expected 0, is " - << last_msg_.states[13].mesid.sat; - EXPECT_EQ(last_msg_.states[14].cn0, 0) - << "incorrect value for last_msg_.states[14].cn0, expected 0, is " - << last_msg_.states[14].cn0; - EXPECT_EQ(last_msg_.states[14].mesid.code, 0) - << "incorrect value for last_msg_.states[14].mesid.code, expected 0, is " - << last_msg_.states[14].mesid.code; - EXPECT_EQ(last_msg_.states[14].mesid.sat, 0) - << "incorrect value for last_msg_.states[14].mesid.sat, expected 0, is " - << last_msg_.states[14].mesid.sat; - EXPECT_EQ(last_msg_.states[15].cn0, 0) - << "incorrect value for last_msg_.states[15].cn0, expected 0, is " - << last_msg_.states[15].cn0; - EXPECT_EQ(last_msg_.states[15].mesid.code, 0) - << "incorrect value for last_msg_.states[15].mesid.code, expected 0, is " - << last_msg_.states[15].mesid.code; - EXPECT_EQ(last_msg_.states[15].mesid.sat, 0) - << "incorrect value for last_msg_.states[15].mesid.sat, expected 0, is " - << last_msg_.states[15].mesid.sat; - EXPECT_EQ(last_msg_.states[16].cn0, 0) - << "incorrect value for last_msg_.states[16].cn0, expected 0, is " - << last_msg_.states[16].cn0; - EXPECT_EQ(last_msg_.states[16].mesid.code, 0) - << "incorrect value for last_msg_.states[16].mesid.code, expected 0, is " - << last_msg_.states[16].mesid.code; - EXPECT_EQ(last_msg_.states[16].mesid.sat, 0) - << "incorrect value for last_msg_.states[16].mesid.sat, expected 0, is " - << last_msg_.states[16].mesid.sat; - EXPECT_EQ(last_msg_.states[17].cn0, 202) - << "incorrect value for last_msg_.states[17].cn0, expected 202, is " - << last_msg_.states[17].cn0; - EXPECT_EQ(last_msg_.states[17].mesid.code, 2) - << "incorrect value for last_msg_.states[17].mesid.code, expected 2, is " - << last_msg_.states[17].mesid.code; - EXPECT_EQ(last_msg_.states[17].mesid.sat, 131) - << "incorrect value for last_msg_.states[17].mesid.sat, expected 131, is " - << last_msg_.states[17].mesid.sat; - EXPECT_EQ(last_msg_.states[18].cn0, 192) - << "incorrect value for last_msg_.states[18].cn0, expected 192, is " - << last_msg_.states[18].cn0; - EXPECT_EQ(last_msg_.states[18].mesid.code, 1) - << "incorrect value for last_msg_.states[18].mesid.code, expected 1, is " - << last_msg_.states[18].mesid.code; - EXPECT_EQ(last_msg_.states[18].mesid.sat, 27) - << "incorrect value for last_msg_.states[18].mesid.sat, expected 27, is " - << last_msg_.states[18].mesid.sat; - EXPECT_EQ(last_msg_.states[19].cn0, 165) - << "incorrect value for last_msg_.states[19].cn0, expected 165, is " - << last_msg_.states[19].cn0; - EXPECT_EQ(last_msg_.states[19].mesid.code, 1) - << "incorrect value for last_msg_.states[19].mesid.code, expected 1, is " - << last_msg_.states[19].mesid.code; - EXPECT_EQ(last_msg_.states[19].mesid.sat, 15) - << "incorrect value for last_msg_.states[19].mesid.sat, expected 15, is " - << last_msg_.states[19].mesid.sat; - EXPECT_EQ(last_msg_.states[20].cn0, 146) - << "incorrect value for last_msg_.states[20].cn0, expected 146, is " - << last_msg_.states[20].cn0; - EXPECT_EQ(last_msg_.states[20].mesid.code, 1) - << "incorrect value for last_msg_.states[20].mesid.code, expected 1, is " - << last_msg_.states[20].mesid.code; - EXPECT_EQ(last_msg_.states[20].mesid.sat, 29) - << "incorrect value for last_msg_.states[20].mesid.sat, expected 29, is " - << last_msg_.states[20].mesid.sat; - EXPECT_EQ(last_msg_.states[21].cn0, 170) - << "incorrect value for last_msg_.states[21].cn0, expected 170, is " - << last_msg_.states[21].cn0; - EXPECT_EQ(last_msg_.states[21].mesid.code, 1) - << "incorrect value for last_msg_.states[21].mesid.code, expected 1, is " - << last_msg_.states[21].mesid.code; - EXPECT_EQ(last_msg_.states[21].mesid.sat, 32) - << "incorrect value for last_msg_.states[21].mesid.sat, expected 32, is " - << last_msg_.states[21].mesid.sat; - EXPECT_EQ(last_msg_.states[22].cn0, 201) - << "incorrect value for last_msg_.states[22].cn0, expected 201, is " - << last_msg_.states[22].cn0; - EXPECT_EQ(last_msg_.states[22].mesid.code, 1) - << "incorrect value for last_msg_.states[22].mesid.code, expected 1, is " - << last_msg_.states[22].mesid.code; - EXPECT_EQ(last_msg_.states[22].mesid.sat, 18) - << "incorrect value for last_msg_.states[22].mesid.sat, expected 18, is " - << last_msg_.states[22].mesid.sat; - EXPECT_EQ(last_msg_.states[23].cn0, 0) - << "incorrect value for last_msg_.states[23].cn0, expected 0, is " - << last_msg_.states[23].cn0; - EXPECT_EQ(last_msg_.states[23].mesid.code, 0) - << "incorrect value for last_msg_.states[23].mesid.code, expected 0, is " - << last_msg_.states[23].mesid.code; - EXPECT_EQ(last_msg_.states[23].mesid.sat, 0) - << "incorrect value for last_msg_.states[23].mesid.sat, expected 0, is " - << last_msg_.states[23].mesid.sat; - EXPECT_EQ(last_msg_.states[24].cn0, 0) - << "incorrect value for last_msg_.states[24].cn0, expected 0, is " - << last_msg_.states[24].cn0; - EXPECT_EQ(last_msg_.states[24].mesid.code, 0) - << "incorrect value for last_msg_.states[24].mesid.code, expected 0, is " - << last_msg_.states[24].mesid.code; - EXPECT_EQ(last_msg_.states[24].mesid.sat, 0) - << "incorrect value for last_msg_.states[24].mesid.sat, expected 0, is " - << last_msg_.states[24].mesid.sat; - EXPECT_EQ(last_msg_.states[25].cn0, 0) - << "incorrect value for last_msg_.states[25].cn0, expected 0, is " - << last_msg_.states[25].cn0; - EXPECT_EQ(last_msg_.states[25].mesid.code, 0) - << "incorrect value for last_msg_.states[25].mesid.code, expected 0, is " - << last_msg_.states[25].mesid.code; - EXPECT_EQ(last_msg_.states[25].mesid.sat, 0) - << "incorrect value for last_msg_.states[25].mesid.sat, expected 0, is " - << last_msg_.states[25].mesid.sat; - EXPECT_EQ(last_msg_.states[26].cn0, 212) - << "incorrect value for last_msg_.states[26].cn0, expected 212, is " - << last_msg_.states[26].cn0; - EXPECT_EQ(last_msg_.states[26].mesid.code, 1) - << "incorrect value for last_msg_.states[26].mesid.code, expected 1, is " - << last_msg_.states[26].mesid.code; - EXPECT_EQ(last_msg_.states[26].mesid.sat, 23) - << "incorrect value for last_msg_.states[26].mesid.sat, expected 23, is " - << last_msg_.states[26].mesid.sat; - EXPECT_EQ(last_msg_.states[27].cn0, 205) - << "incorrect value for last_msg_.states[27].cn0, expected 205, is " - << last_msg_.states[27].cn0; - EXPECT_EQ(last_msg_.states[27].mesid.code, 1) - << "incorrect value for last_msg_.states[27].mesid.code, expected 1, is " - << last_msg_.states[27].mesid.code; - EXPECT_EQ(last_msg_.states[27].mesid.sat, 10) - << "incorrect value for last_msg_.states[27].mesid.sat, expected 10, is " - << last_msg_.states[27].mesid.sat; - EXPECT_EQ(last_msg_.states[28].cn0, 0) - << "incorrect value for last_msg_.states[28].cn0, expected 0, is " - << last_msg_.states[28].cn0; - EXPECT_EQ(last_msg_.states[28].mesid.code, 0) - << "incorrect value for last_msg_.states[28].mesid.code, expected 0, is " - << last_msg_.states[28].mesid.code; - EXPECT_EQ(last_msg_.states[28].mesid.sat, 0) - << "incorrect value for last_msg_.states[28].mesid.sat, expected 0, is " - << last_msg_.states[28].mesid.sat; - EXPECT_EQ(last_msg_.states[29].cn0, 230) - << "incorrect value for last_msg_.states[29].cn0, expected 230, is " - << last_msg_.states[29].cn0; - EXPECT_EQ(last_msg_.states[29].mesid.code, 3) - << "incorrect value for last_msg_.states[29].mesid.code, expected 3, is " - << last_msg_.states[29].mesid.code; - EXPECT_EQ(last_msg_.states[29].mesid.sat, 96) - << "incorrect value for last_msg_.states[29].mesid.sat, expected 96, is " - << last_msg_.states[29].mesid.sat; - EXPECT_EQ(last_msg_.states[30].cn0, 0) - << "incorrect value for last_msg_.states[30].cn0, expected 0, is " - << last_msg_.states[30].cn0; - EXPECT_EQ(last_msg_.states[30].mesid.code, 0) - << "incorrect value for last_msg_.states[30].mesid.code, expected 0, is " - << last_msg_.states[30].mesid.code; - EXPECT_EQ(last_msg_.states[30].mesid.sat, 0) - << "incorrect value for last_msg_.states[30].mesid.sat, expected 0, is " - << last_msg_.states[30].mesid.sat; - EXPECT_EQ(last_msg_.states[31].cn0, 214) - << "incorrect value for last_msg_.states[31].cn0, expected 214, is " - << last_msg_.states[31].cn0; - EXPECT_EQ(last_msg_.states[31].mesid.code, 3) - << "incorrect value for last_msg_.states[31].mesid.code, expected 3, is " - << last_msg_.states[31].mesid.code; - EXPECT_EQ(last_msg_.states[31].mesid.sat, 101) - << "incorrect value for last_msg_.states[31].mesid.sat, expected 101, is " - << last_msg_.states[31].mesid.sat; - EXPECT_EQ(last_msg_.states[32].cn0, 212) - << "incorrect value for last_msg_.states[32].cn0, expected 212, is " - << last_msg_.states[32].cn0; - EXPECT_EQ(last_msg_.states[32].mesid.code, 3) - << "incorrect value for last_msg_.states[32].mesid.code, expected 3, is " - << last_msg_.states[32].mesid.code; - EXPECT_EQ(last_msg_.states[32].mesid.sat, 103) - << "incorrect value for last_msg_.states[32].mesid.sat, expected 103, is " - << last_msg_.states[32].mesid.sat; - EXPECT_EQ(last_msg_.states[33].cn0, 209) - << "incorrect value for last_msg_.states[33].cn0, expected 209, is " - << last_msg_.states[33].cn0; - EXPECT_EQ(last_msg_.states[33].mesid.code, 3) - << "incorrect value for last_msg_.states[33].mesid.code, expected 3, is " - << last_msg_.states[33].mesid.code; - EXPECT_EQ(last_msg_.states[33].mesid.sat, 104) - << "incorrect value for last_msg_.states[33].mesid.sat, expected 104, is " - << last_msg_.states[33].mesid.sat; - EXPECT_EQ(last_msg_.states[34].cn0, 157) - << "incorrect value for last_msg_.states[34].cn0, expected 157, is " - << last_msg_.states[34].cn0; - EXPECT_EQ(last_msg_.states[34].mesid.code, 3) - << "incorrect value for last_msg_.states[34].mesid.code, expected 3, is " - << last_msg_.states[34].mesid.code; - EXPECT_EQ(last_msg_.states[34].mesid.sat, 106) - << "incorrect value for last_msg_.states[34].mesid.sat, expected 106, is " - << last_msg_.states[34].mesid.sat; - EXPECT_EQ(last_msg_.states[35].cn0, 230) - << "incorrect value for last_msg_.states[35].cn0, expected 230, is " - << last_msg_.states[35].cn0; - EXPECT_EQ(last_msg_.states[35].mesid.code, 3) - << "incorrect value for last_msg_.states[35].mesid.code, expected 3, is " - << last_msg_.states[35].mesid.code; - EXPECT_EQ(last_msg_.states[35].mesid.sat, 102) - << "incorrect value for last_msg_.states[35].mesid.sat, expected 102, is " - << last_msg_.states[35].mesid.sat; - EXPECT_EQ(last_msg_.states[36].cn0, 0) - << "incorrect value for last_msg_.states[36].cn0, expected 0, is " - << last_msg_.states[36].cn0; - EXPECT_EQ(last_msg_.states[36].mesid.code, 0) - << "incorrect value for last_msg_.states[36].mesid.code, expected 0, is " - << last_msg_.states[36].mesid.code; - EXPECT_EQ(last_msg_.states[36].mesid.sat, 0) - << "incorrect value for last_msg_.states[36].mesid.sat, expected 0, is " - << last_msg_.states[36].mesid.sat; - EXPECT_EQ(last_msg_.states[37].cn0, 0) - << "incorrect value for last_msg_.states[37].cn0, expected 0, is " - << last_msg_.states[37].cn0; - EXPECT_EQ(last_msg_.states[37].mesid.code, 0) - << "incorrect value for last_msg_.states[37].mesid.code, expected 0, is " - << last_msg_.states[37].mesid.code; - EXPECT_EQ(last_msg_.states[37].mesid.sat, 0) - << "incorrect value for last_msg_.states[37].mesid.sat, expected 0, is " - << last_msg_.states[37].mesid.sat; - EXPECT_EQ(last_msg_.states[38].cn0, 189) - << "incorrect value for last_msg_.states[38].cn0, expected 189, is " - << last_msg_.states[38].cn0; - EXPECT_EQ(last_msg_.states[38].mesid.code, 4) - << "incorrect value for last_msg_.states[38].mesid.code, expected 4, is " - << last_msg_.states[38].mesid.code; - EXPECT_EQ(last_msg_.states[38].mesid.sat, 101) - << "incorrect value for last_msg_.states[38].mesid.sat, expected 101, is " - << last_msg_.states[38].mesid.sat; - EXPECT_EQ(last_msg_.states[39].cn0, 207) - << "incorrect value for last_msg_.states[39].cn0, expected 207, is " - << last_msg_.states[39].cn0; - EXPECT_EQ(last_msg_.states[39].mesid.code, 4) - << "incorrect value for last_msg_.states[39].mesid.code, expected 4, is " - << last_msg_.states[39].mesid.code; - EXPECT_EQ(last_msg_.states[39].mesid.sat, 96) - << "incorrect value for last_msg_.states[39].mesid.sat, expected 96, is " - << last_msg_.states[39].mesid.sat; - EXPECT_EQ(last_msg_.states[40].cn0, 164) - << "incorrect value for last_msg_.states[40].cn0, expected 164, is " - << last_msg_.states[40].cn0; - EXPECT_EQ(last_msg_.states[40].mesid.code, 4) - << "incorrect value for last_msg_.states[40].mesid.code, expected 4, is " - << last_msg_.states[40].mesid.code; - EXPECT_EQ(last_msg_.states[40].mesid.sat, 106) - << "incorrect value for last_msg_.states[40].mesid.sat, expected 106, is " - << last_msg_.states[40].mesid.sat; - EXPECT_EQ(last_msg_.states[41].cn0, 193) - << "incorrect value for last_msg_.states[41].cn0, expected 193, is " - << last_msg_.states[41].cn0; - EXPECT_EQ(last_msg_.states[41].mesid.code, 4) - << "incorrect value for last_msg_.states[41].mesid.code, expected 4, is " - << last_msg_.states[41].mesid.code; - EXPECT_EQ(last_msg_.states[41].mesid.sat, 104) - << "incorrect value for last_msg_.states[41].mesid.sat, expected 104, is " - << last_msg_.states[41].mesid.sat; - EXPECT_EQ(last_msg_.states[42].cn0, 0) - << "incorrect value for last_msg_.states[42].cn0, expected 0, is " - << last_msg_.states[42].cn0; - EXPECT_EQ(last_msg_.states[42].mesid.code, 0) - << "incorrect value for last_msg_.states[42].mesid.code, expected 0, is " - << last_msg_.states[42].mesid.code; - EXPECT_EQ(last_msg_.states[42].mesid.sat, 0) - << "incorrect value for last_msg_.states[42].mesid.sat, expected 0, is " - << last_msg_.states[42].mesid.sat; - EXPECT_EQ(last_msg_.states[43].cn0, 208) - << "incorrect value for last_msg_.states[43].cn0, expected 208, is " - << last_msg_.states[43].cn0; - EXPECT_EQ(last_msg_.states[43].mesid.code, 4) - << "incorrect value for last_msg_.states[43].mesid.code, expected 4, is " - << last_msg_.states[43].mesid.code; - EXPECT_EQ(last_msg_.states[43].mesid.sat, 102) - << "incorrect value for last_msg_.states[43].mesid.sat, expected 102, is " - << last_msg_.states[43].mesid.sat; - EXPECT_EQ(last_msg_.states[44].cn0, 0) - << "incorrect value for last_msg_.states[44].cn0, expected 0, is " - << last_msg_.states[44].cn0; - EXPECT_EQ(last_msg_.states[44].mesid.code, 0) - << "incorrect value for last_msg_.states[44].mesid.code, expected 0, is " - << last_msg_.states[44].mesid.code; - EXPECT_EQ(last_msg_.states[44].mesid.sat, 0) - << "incorrect value for last_msg_.states[44].mesid.sat, expected 0, is " - << last_msg_.states[44].mesid.sat; - EXPECT_EQ(last_msg_.states[45].cn0, 212) - << "incorrect value for last_msg_.states[45].cn0, expected 212, is " - << last_msg_.states[45].cn0; - EXPECT_EQ(last_msg_.states[45].mesid.code, 12) - << "incorrect value for last_msg_.states[45].mesid.code, expected 12, is " - << last_msg_.states[45].mesid.code; - EXPECT_EQ(last_msg_.states[45].mesid.sat, 27) - << "incorrect value for last_msg_.states[45].mesid.sat, expected 27, is " - << last_msg_.states[45].mesid.sat; - EXPECT_EQ(last_msg_.states[46].cn0, 161) - << "incorrect value for last_msg_.states[46].cn0, expected 161, is " - << last_msg_.states[46].cn0; - EXPECT_EQ(last_msg_.states[46].mesid.code, 12) - << "incorrect value for last_msg_.states[46].mesid.code, expected 12, is " - << last_msg_.states[46].mesid.code; - EXPECT_EQ(last_msg_.states[46].mesid.sat, 29) - << "incorrect value for last_msg_.states[46].mesid.sat, expected 29, is " - << last_msg_.states[46].mesid.sat; - EXPECT_EQ(last_msg_.states[47].cn0, 216) - << "incorrect value for last_msg_.states[47].cn0, expected 216, is " - << last_msg_.states[47].cn0; - EXPECT_EQ(last_msg_.states[47].mesid.code, 12) - << "incorrect value for last_msg_.states[47].mesid.code, expected 12, is " - << last_msg_.states[47].mesid.code; - EXPECT_EQ(last_msg_.states[47].mesid.sat, 32) - << "incorrect value for last_msg_.states[47].mesid.sat, expected 32, is " - << last_msg_.states[47].mesid.sat; - EXPECT_EQ(last_msg_.states[48].cn0, 216) - << "incorrect value for last_msg_.states[48].cn0, expected 216, is " - << last_msg_.states[48].cn0; - EXPECT_EQ(last_msg_.states[48].mesid.code, 12) - << "incorrect value for last_msg_.states[48].mesid.code, expected 12, is " - << last_msg_.states[48].mesid.code; - EXPECT_EQ(last_msg_.states[48].mesid.sat, 30) - << "incorrect value for last_msg_.states[48].mesid.sat, expected 30, is " - << last_msg_.states[48].mesid.sat; - EXPECT_EQ(last_msg_.states[49].cn0, 178) - << "incorrect value for last_msg_.states[49].cn0, expected 178, is " - << last_msg_.states[49].cn0; - EXPECT_EQ(last_msg_.states[49].mesid.code, 12) - << "incorrect value for last_msg_.states[49].mesid.code, expected 12, is " - << last_msg_.states[49].mesid.code; - EXPECT_EQ(last_msg_.states[49].mesid.sat, 20) - << "incorrect value for last_msg_.states[49].mesid.sat, expected 20, is " - << last_msg_.states[49].mesid.sat; - EXPECT_EQ(last_msg_.states[50].cn0, 0) - << "incorrect value for last_msg_.states[50].cn0, expected 0, is " - << last_msg_.states[50].cn0; - EXPECT_EQ(last_msg_.states[50].mesid.code, 0) - << "incorrect value for last_msg_.states[50].mesid.code, expected 0, is " - << last_msg_.states[50].mesid.code; - EXPECT_EQ(last_msg_.states[50].mesid.sat, 0) - << "incorrect value for last_msg_.states[50].mesid.sat, expected 0, is " - << last_msg_.states[50].mesid.sat; - EXPECT_EQ(last_msg_.states[51].cn0, 0) - << "incorrect value for last_msg_.states[51].cn0, expected 0, is " - << last_msg_.states[51].cn0; - EXPECT_EQ(last_msg_.states[51].mesid.code, 0) - << "incorrect value for last_msg_.states[51].mesid.code, expected 0, is " - << last_msg_.states[51].mesid.code; - EXPECT_EQ(last_msg_.states[51].mesid.sat, 0) - << "incorrect value for last_msg_.states[51].mesid.sat, expected 0, is " - << last_msg_.states[51].mesid.sat; - EXPECT_EQ(last_msg_.states[52].cn0, 0) - << "incorrect value for last_msg_.states[52].cn0, expected 0, is " - << last_msg_.states[52].cn0; - EXPECT_EQ(last_msg_.states[52].mesid.code, 0) - << "incorrect value for last_msg_.states[52].mesid.code, expected 0, is " - << last_msg_.states[52].mesid.code; - EXPECT_EQ(last_msg_.states[52].mesid.sat, 0) - << "incorrect value for last_msg_.states[52].mesid.sat, expected 0, is " - << last_msg_.states[52].mesid.sat; - EXPECT_EQ(last_msg_.states[53].cn0, 0) - << "incorrect value for last_msg_.states[53].cn0, expected 0, is " - << last_msg_.states[53].cn0; - EXPECT_EQ(last_msg_.states[53].mesid.code, 0) - << "incorrect value for last_msg_.states[53].mesid.code, expected 0, is " - << last_msg_.states[53].mesid.code; - EXPECT_EQ(last_msg_.states[53].mesid.sat, 0) - << "incorrect value for last_msg_.states[53].mesid.sat, expected 0, is " - << last_msg_.states[53].mesid.sat; - EXPECT_EQ(last_msg_.states[54].cn0, 0) - << "incorrect value for last_msg_.states[54].cn0, expected 0, is " - << last_msg_.states[54].cn0; - EXPECT_EQ(last_msg_.states[54].mesid.code, 0) - << "incorrect value for last_msg_.states[54].mesid.code, expected 0, is " - << last_msg_.states[54].mesid.code; - EXPECT_EQ(last_msg_.states[54].mesid.sat, 0) - << "incorrect value for last_msg_.states[54].mesid.sat, expected 0, is " - << last_msg_.states[54].mesid.sat; - EXPECT_EQ(last_msg_.states[55].cn0, 0) - << "incorrect value for last_msg_.states[55].cn0, expected 0, is " - << last_msg_.states[55].cn0; - EXPECT_EQ(last_msg_.states[55].mesid.code, 0) - << "incorrect value for last_msg_.states[55].mesid.code, expected 0, is " - << last_msg_.states[55].mesid.code; - EXPECT_EQ(last_msg_.states[55].mesid.sat, 0) - << "incorrect value for last_msg_.states[55].mesid.sat, expected 0, is " - << last_msg_.states[55].mesid.sat; - EXPECT_EQ(last_msg_.states[56].cn0, 0) - << "incorrect value for last_msg_.states[56].cn0, expected 0, is " - << last_msg_.states[56].cn0; - EXPECT_EQ(last_msg_.states[56].mesid.code, 0) - << "incorrect value for last_msg_.states[56].mesid.code, expected 0, is " - << last_msg_.states[56].mesid.code; - EXPECT_EQ(last_msg_.states[56].mesid.sat, 0) - << "incorrect value for last_msg_.states[56].mesid.sat, expected 0, is " - << last_msg_.states[56].mesid.sat; - EXPECT_EQ(last_msg_.states[57].cn0, 0) - << "incorrect value for last_msg_.states[57].cn0, expected 0, is " - << last_msg_.states[57].cn0; - EXPECT_EQ(last_msg_.states[57].mesid.code, 0) - << "incorrect value for last_msg_.states[57].mesid.code, expected 0, is " - << last_msg_.states[57].mesid.code; - EXPECT_EQ(last_msg_.states[57].mesid.sat, 0) - << "incorrect value for last_msg_.states[57].mesid.sat, expected 0, is " - << last_msg_.states[57].mesid.sat; - EXPECT_EQ(last_msg_.states[58].cn0, 0) - << "incorrect value for last_msg_.states[58].cn0, expected 0, is " - << last_msg_.states[58].cn0; - EXPECT_EQ(last_msg_.states[58].mesid.code, 0) - << "incorrect value for last_msg_.states[58].mesid.code, expected 0, is " - << last_msg_.states[58].mesid.code; - EXPECT_EQ(last_msg_.states[58].mesid.sat, 0) - << "incorrect value for last_msg_.states[58].mesid.sat, expected 0, is " - << last_msg_.states[58].mesid.sat; - EXPECT_EQ(last_msg_.states[59].cn0, 0) - << "incorrect value for last_msg_.states[59].cn0, expected 0, is " - << last_msg_.states[59].cn0; - EXPECT_EQ(last_msg_.states[59].mesid.code, 0) - << "incorrect value for last_msg_.states[59].mesid.code, expected 0, is " - << last_msg_.states[59].mesid.code; - EXPECT_EQ(last_msg_.states[59].mesid.sat, 0) - << "incorrect value for last_msg_.states[59].mesid.sat, expected 0, is " - << last_msg_.states[59].mesid.sat; - EXPECT_EQ(last_msg_.states[60].cn0, 0) - << "incorrect value for last_msg_.states[60].cn0, expected 0, is " - << last_msg_.states[60].cn0; - EXPECT_EQ(last_msg_.states[60].mesid.code, 0) - << "incorrect value for last_msg_.states[60].mesid.code, expected 0, is " - << last_msg_.states[60].mesid.code; - EXPECT_EQ(last_msg_.states[60].mesid.sat, 0) - << "incorrect value for last_msg_.states[60].mesid.sat, expected 0, is " - << last_msg_.states[60].mesid.sat; - EXPECT_EQ(last_msg_.states[61].cn0, 0) - << "incorrect value for last_msg_.states[61].cn0, expected 0, is " - << last_msg_.states[61].cn0; - EXPECT_EQ(last_msg_.states[61].mesid.code, 0) - << "incorrect value for last_msg_.states[61].mesid.code, expected 0, is " - << last_msg_.states[61].mesid.code; - EXPECT_EQ(last_msg_.states[61].mesid.sat, 0) - << "incorrect value for last_msg_.states[61].mesid.sat, expected 0, is " - << last_msg_.states[61].mesid.sat; - EXPECT_EQ(last_msg_.states[62].cn0, 0) - << "incorrect value for last_msg_.states[62].cn0, expected 0, is " - << last_msg_.states[62].cn0; - EXPECT_EQ(last_msg_.states[62].mesid.code, 0) - << "incorrect value for last_msg_.states[62].mesid.code, expected 0, is " - << last_msg_.states[62].mesid.code; - EXPECT_EQ(last_msg_.states[62].mesid.sat, 0) - << "incorrect value for last_msg_.states[62].mesid.sat, expected 0, is " - << last_msg_.states[62].mesid.sat; - EXPECT_EQ(last_msg_.states[63].cn0, 203) - << "incorrect value for last_msg_.states[63].cn0, expected 203, is " - << last_msg_.states[63].cn0; - EXPECT_EQ(last_msg_.states[63].mesid.code, 14) - << "incorrect value for last_msg_.states[63].mesid.code, expected 14, is " - << last_msg_.states[63].mesid.code; - EXPECT_EQ(last_msg_.states[63].mesid.sat, 36) - << "incorrect value for last_msg_.states[63].mesid.sat, expected 36, is " - << last_msg_.states[63].mesid.sat; - EXPECT_EQ(last_msg_.states[64].cn0, 0) - << "incorrect value for last_msg_.states[64].cn0, expected 0, is " - << last_msg_.states[64].cn0; - EXPECT_EQ(last_msg_.states[64].mesid.code, 0) - << "incorrect value for last_msg_.states[64].mesid.code, expected 0, is " - << last_msg_.states[64].mesid.code; - EXPECT_EQ(last_msg_.states[64].mesid.sat, 0) - << "incorrect value for last_msg_.states[64].mesid.sat, expected 0, is " - << last_msg_.states[64].mesid.sat; - EXPECT_EQ(last_msg_.states[65].cn0, 158) - << "incorrect value for last_msg_.states[65].cn0, expected 158, is " - << last_msg_.states[65].cn0; - EXPECT_EQ(last_msg_.states[65].mesid.code, 14) - << "incorrect value for last_msg_.states[65].mesid.code, expected 14, is " - << last_msg_.states[65].mesid.code; - EXPECT_EQ(last_msg_.states[65].mesid.sat, 5) - << "incorrect value for last_msg_.states[65].mesid.sat, expected 5, is " - << last_msg_.states[65].mesid.sat; - EXPECT_EQ(last_msg_.states[66].cn0, 194) - << "incorrect value for last_msg_.states[66].cn0, expected 194, is " - << last_msg_.states[66].cn0; - EXPECT_EQ(last_msg_.states[66].mesid.code, 14) - << "incorrect value for last_msg_.states[66].mesid.code, expected 14, is " - << last_msg_.states[66].mesid.code; - EXPECT_EQ(last_msg_.states[66].mesid.sat, 4) - << "incorrect value for last_msg_.states[66].mesid.sat, expected 4, is " - << last_msg_.states[66].mesid.sat; - EXPECT_EQ(last_msg_.states[67].cn0, 192) - << "incorrect value for last_msg_.states[67].cn0, expected 192, is " - << last_msg_.states[67].cn0; - EXPECT_EQ(last_msg_.states[67].mesid.code, 14) - << "incorrect value for last_msg_.states[67].mesid.code, expected 14, is " - << last_msg_.states[67].mesid.code; - EXPECT_EQ(last_msg_.states[67].mesid.sat, 11) - << "incorrect value for last_msg_.states[67].mesid.sat, expected 11, is " - << last_msg_.states[67].mesid.sat; - EXPECT_EQ(last_msg_.states[68].cn0, 207) - << "incorrect value for last_msg_.states[68].cn0, expected 207, is " - << last_msg_.states[68].cn0; - EXPECT_EQ(last_msg_.states[68].mesid.code, 14) - << "incorrect value for last_msg_.states[68].mesid.code, expected 14, is " - << last_msg_.states[68].mesid.code; - EXPECT_EQ(last_msg_.states[68].mesid.sat, 9) - << "incorrect value for last_msg_.states[68].mesid.sat, expected 9, is " - << last_msg_.states[68].mesid.sat; - EXPECT_EQ(last_msg_.states[69].cn0, 0) - << "incorrect value for last_msg_.states[69].cn0, expected 0, is " - << last_msg_.states[69].cn0; - EXPECT_EQ(last_msg_.states[69].mesid.code, 0) - << "incorrect value for last_msg_.states[69].mesid.code, expected 0, is " - << last_msg_.states[69].mesid.code; - EXPECT_EQ(last_msg_.states[69].mesid.sat, 0) - << "incorrect value for last_msg_.states[69].mesid.sat, expected 0, is " - << last_msg_.states[69].mesid.sat; - EXPECT_EQ(last_msg_.states[70].cn0, 0) - << "incorrect value for last_msg_.states[70].cn0, expected 0, is " - << last_msg_.states[70].cn0; - EXPECT_EQ(last_msg_.states[70].mesid.code, 0) - << "incorrect value for last_msg_.states[70].mesid.code, expected 0, is " - << last_msg_.states[70].mesid.code; - EXPECT_EQ(last_msg_.states[70].mesid.sat, 0) - << "incorrect value for last_msg_.states[70].mesid.sat, expected 0, is " - << last_msg_.states[70].mesid.sat; - EXPECT_EQ(last_msg_.states[71].cn0, 0) - << "incorrect value for last_msg_.states[71].cn0, expected 0, is " - << last_msg_.states[71].cn0; - EXPECT_EQ(last_msg_.states[71].mesid.code, 0) - << "incorrect value for last_msg_.states[71].mesid.code, expected 0, is " - << last_msg_.states[71].mesid.code; - EXPECT_EQ(last_msg_.states[71].mesid.sat, 0) - << "incorrect value for last_msg_.states[71].mesid.sat, expected 0, is " - << last_msg_.states[71].mesid.sat; - EXPECT_EQ(last_msg_.states[72].cn0, 218) - << "incorrect value for last_msg_.states[72].cn0, expected 218, is " - << last_msg_.states[72].cn0; - EXPECT_EQ(last_msg_.states[72].mesid.code, 20) - << "incorrect value for last_msg_.states[72].mesid.code, expected 20, is " - << last_msg_.states[72].mesid.code; - EXPECT_EQ(last_msg_.states[72].mesid.sat, 9) - << "incorrect value for last_msg_.states[72].mesid.sat, expected 9, is " - << last_msg_.states[72].mesid.sat; - EXPECT_EQ(last_msg_.states[73].cn0, 176) - << "incorrect value for last_msg_.states[73].cn0, expected 176, is " - << last_msg_.states[73].cn0; - EXPECT_EQ(last_msg_.states[73].mesid.code, 20) - << "incorrect value for last_msg_.states[73].mesid.code, expected 20, is " - << last_msg_.states[73].mesid.code; - EXPECT_EQ(last_msg_.states[73].mesid.sat, 5) - << "incorrect value for last_msg_.states[73].mesid.sat, expected 5, is " - << last_msg_.states[73].mesid.sat; - EXPECT_EQ(last_msg_.states[74].cn0, 217) - << "incorrect value for last_msg_.states[74].cn0, expected 217, is " - << last_msg_.states[74].cn0; - EXPECT_EQ(last_msg_.states[74].mesid.code, 20) - << "incorrect value for last_msg_.states[74].mesid.code, expected 20, is " - << last_msg_.states[74].mesid.code; - EXPECT_EQ(last_msg_.states[74].mesid.sat, 36) - << "incorrect value for last_msg_.states[74].mesid.sat, expected 36, is " - << last_msg_.states[74].mesid.sat; - EXPECT_EQ(last_msg_.states[75].cn0, 200) - << "incorrect value for last_msg_.states[75].cn0, expected 200, is " - << last_msg_.states[75].cn0; - EXPECT_EQ(last_msg_.states[75].mesid.code, 20) - << "incorrect value for last_msg_.states[75].mesid.code, expected 20, is " - << last_msg_.states[75].mesid.code; - EXPECT_EQ(last_msg_.states[75].mesid.sat, 11) - << "incorrect value for last_msg_.states[75].mesid.sat, expected 11, is " - << last_msg_.states[75].mesid.sat; - EXPECT_EQ(last_msg_.states[76].cn0, 205) - << "incorrect value for last_msg_.states[76].cn0, expected 205, is " - << last_msg_.states[76].cn0; - EXPECT_EQ(last_msg_.states[76].mesid.code, 20) - << "incorrect value for last_msg_.states[76].mesid.code, expected 20, is " - << last_msg_.states[76].mesid.code; - EXPECT_EQ(last_msg_.states[76].mesid.sat, 4) - << "incorrect value for last_msg_.states[76].mesid.sat, expected 4, is " - << last_msg_.states[76].mesid.sat; - EXPECT_EQ(last_msg_.states[77].cn0, 0) - << "incorrect value for last_msg_.states[77].cn0, expected 0, is " - << last_msg_.states[77].cn0; - EXPECT_EQ(last_msg_.states[77].mesid.code, 0) - << "incorrect value for last_msg_.states[77].mesid.code, expected 0, is " - << last_msg_.states[77].mesid.code; - EXPECT_EQ(last_msg_.states[77].mesid.sat, 0) - << "incorrect value for last_msg_.states[77].mesid.sat, expected 0, is " - << last_msg_.states[77].mesid.sat; - EXPECT_EQ(last_msg_.states[78].cn0, 0) - << "incorrect value for last_msg_.states[78].cn0, expected 0, is " - << last_msg_.states[78].cn0; - EXPECT_EQ(last_msg_.states[78].mesid.code, 0) - << "incorrect value for last_msg_.states[78].mesid.code, expected 0, is " - << last_msg_.states[78].mesid.code; - EXPECT_EQ(last_msg_.states[78].mesid.sat, 0) - << "incorrect value for last_msg_.states[78].mesid.sat, expected 0, is " - << last_msg_.states[78].mesid.sat; + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].cn0, greater.states[29].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].mesid.code, + greater.states[29].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].mesid.sat, + greater.states[29].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].cn0, greater.states[30].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].mesid.code, + greater.states[30].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].mesid.sat, + greater.states[30].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].cn0, greater.states[31].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].mesid.code, + greater.states[31].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].mesid.sat, + greater.states[31].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].cn0, greater.states[32].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].mesid.code, + greater.states[32].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].mesid.sat, + greater.states[32].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].cn0, greater.states[33].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].mesid.code, + greater.states[33].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].mesid.sat, + greater.states[33].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].cn0, greater.states[34].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].mesid.code, + greater.states[34].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].mesid.sat, + greater.states[34].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].cn0, greater.states[35].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].mesid.code, + greater.states[35].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].mesid.sat, + greater.states[35].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].cn0, greater.states[36].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].mesid.code, + greater.states[36].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].mesid.sat, + greater.states[36].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].cn0, greater.states[37].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].mesid.code, + greater.states[37].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].mesid.sat, + greater.states[37].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].cn0, greater.states[38].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].mesid.code, + greater.states[38].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].mesid.sat, + greater.states[38].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].cn0, greater.states[39].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].mesid.code, + greater.states[39].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].mesid.sat, + greater.states[39].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].cn0, greater.states[40].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].mesid.code, + greater.states[40].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].mesid.sat, + greater.states[40].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].cn0, greater.states[41].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].mesid.code, + greater.states[41].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].mesid.sat, + greater.states[41].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].cn0, greater.states[42].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].mesid.code, + greater.states[42].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].mesid.sat, + greater.states[42].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].cn0, greater.states[43].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].mesid.code, + greater.states[43].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].mesid.sat, + greater.states[43].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].cn0, greater.states[44].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].mesid.code, + greater.states[44].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].mesid.sat, + greater.states[44].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].cn0, greater.states[45].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].mesid.code, + greater.states[45].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].mesid.sat, + greater.states[45].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].cn0, greater.states[46].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].mesid.code, + greater.states[46].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].mesid.sat, + greater.states[46].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].cn0, greater.states[47].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].mesid.code, + greater.states[47].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].mesid.sat, + greater.states[47].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].cn0, greater.states[48].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].mesid.code, + greater.states[48].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].mesid.sat, + greater.states[48].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].cn0, greater.states[49].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].mesid.code, + greater.states[49].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].mesid.sat, + greater.states[49].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].cn0, greater.states[50].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].mesid.code, + greater.states[50].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].mesid.sat, + greater.states[50].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].cn0, greater.states[51].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].mesid.code, + greater.states[51].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].mesid.sat, + greater.states[51].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].cn0, greater.states[52].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].mesid.code, + greater.states[52].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].mesid.sat, + greater.states[52].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].cn0, greater.states[53].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].mesid.code, + greater.states[53].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].mesid.sat, + greater.states[53].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].cn0, greater.states[54].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].mesid.code, + greater.states[54].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].mesid.sat, + greater.states[54].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].cn0, greater.states[55].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].mesid.code, + greater.states[55].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].mesid.sat, + greater.states[55].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].cn0, greater.states[56].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].mesid.code, + greater.states[56].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].mesid.sat, + greater.states[56].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].cn0, greater.states[57].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].mesid.code, + greater.states[57].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].mesid.sat, + greater.states[57].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].cn0, greater.states[58].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].mesid.code, + greater.states[58].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].mesid.sat, + greater.states[58].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].cn0, greater.states[59].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].mesid.code, + greater.states[59].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].mesid.sat, + greater.states[59].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].cn0, greater.states[60].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].mesid.code, + greater.states[60].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].mesid.sat, + greater.states[60].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].cn0, greater.states[61].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].mesid.code, + greater.states[61].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].mesid.sat, + greater.states[61].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].cn0, greater.states[62].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].mesid.code, + greater.states[62].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].mesid.sat, + greater.states[62].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[63].cn0, greater.states[63].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[63].mesid.code, + greater.states[63].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[63].mesid.sat, + greater.states[63].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[64].cn0, greater.states[64].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[64].mesid.code, + greater.states[64].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[64].mesid.sat, + greater.states[64].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[65].cn0, greater.states[65].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[65].mesid.code, + greater.states[65].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[65].mesid.sat, + greater.states[65].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[66].cn0, greater.states[66].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[66].mesid.code, + greater.states[66].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[66].mesid.sat, + greater.states[66].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[67].cn0, greater.states[67].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[67].mesid.code, + greater.states[67].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[67].mesid.sat, + greater.states[67].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[68].cn0, greater.states[68].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[68].mesid.code, + greater.states[68].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[68].mesid.sat, + greater.states[68].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[69].cn0, greater.states[69].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[69].mesid.code, + greater.states[69].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[69].mesid.sat, + greater.states[69].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[70].cn0, greater.states[70].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[70].mesid.code, + greater.states[70].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[70].mesid.sat, + greater.states[70].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[71].cn0, greater.states[71].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[71].mesid.code, + greater.states[71].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[71].mesid.sat, + greater.states[71].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[72].cn0, greater.states[72].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[72].mesid.code, + greater.states[72].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[72].mesid.sat, + greater.states[72].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[73].cn0, greater.states[73].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[73].mesid.code, + greater.states[73].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[73].mesid.sat, + greater.states[73].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[74].cn0, greater.states[74].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[74].mesid.code, + greater.states[74].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[74].mesid.sat, + greater.states[74].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[75].cn0, greater.states[75].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[75].mesid.code, + greater.states[75].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[75].mesid.sat, + greater.states[75].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[76].cn0, greater.states[76].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[76].mesid.code, + greater.states[76].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[76].mesid.sat, + greater.states[76].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[77].cn0, greater.states[77].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[77].mesid.code, + greater.states[77].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[77].mesid.sat, + greater.states[77].mesid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[78].cn0, greater.states[78].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[78].mesid.code, + greater.states[78].mesid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_measurement_state_t lesser = info.test_msg; + sbp_msg_measurement_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[78].mesid.sat, + greater.states[78].mesid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgMeasurementState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_MEASUREMENT_STATE"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_measurement_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_measurement_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.measurement_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.measurement_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); } + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[237]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 237); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 237), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_measurement_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 237); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgMeasurementState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgMeasurementState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgMeasurementState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc new file mode 100644 index 0000000000..4134558fe9 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc @@ -0,0 +1,833 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingIq0 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingIq0() { + assign(test_msg_.channel, 145); + + assign(test_msg_.corrs[0].I, -9937); + assign(test_msg_.corrs[0].Q, 14319); + + assign(test_msg_.corrs[1].I, 9773); + assign(test_msg_.corrs[1].Q, 22717); + + assign(test_msg_.corrs[2].I, 5023); + assign(test_msg_.corrs[2].Q, 3280); + assign(test_msg_.sid.code, 203); + assign(test_msg_.sid.sat, 121); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_iq_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingIq, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingIq); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_iq, sizeof(msg->tracking_iq)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_iq_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_iq, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingIq); + info.sender_id = 20482; + info.preamble = 0x55; + info.crc = 0xa761; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 15; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_iq_t &lesser, + const sbp_msg_tracking_iq_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_iq_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_iq_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_iq_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_iq_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgTrackingIq, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgTrackingIq, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgTrackingIq, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgTrackingIq, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_iq_t test_msg_{}; + uint8_t encoded_frame_[15 + 8] = { + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, + 55, 45, 38, 189, 88, 159, 19, 208, 12, 97, 167, + }; + uint8_t encoded_payload_[15] = { + 145, 121, 203, 47, 217, 239, 55, 45, 38, 189, 88, 159, 19, 208, 12, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_iq_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingIq, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_iq_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingIq, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + EXPECT_EQ( + sbp_msg_tracking_iq_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + + for (uint8_t i = 0; i < 15; i++) { + EXPECT_EQ(sbp_msg_tracking_iq_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_iq_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingIq, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_iq_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_tracking_iq_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_iq_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingIq, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIq, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.channel, greater.channel); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].I, greater.corrs[0].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].Q, greater.corrs[0].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].I, greater.corrs[1].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].Q, greater.corrs[1].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].I, greater.corrs[2].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].Q, greater.corrs[2].Q); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_t lesser = info.test_msg; + sbp_msg_tracking_iq_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgTrackingIq); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_IQ"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_iq_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_iq_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.tracking_iq, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_iq, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[15]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 15); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 15), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 15); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingIq, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIq0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingIq, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc new file mode 100644 index 0000000000..2af689c1d4 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc @@ -0,0 +1,854 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingIqDepA0 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingIqDepA0() { + assign(test_msg_.channel, 139); + + assign(test_msg_.corrs[0].I, 1621776995); + assign(test_msg_.corrs[0].Q, -1591641785); + + assign(test_msg_.corrs[1].I, 1705169716); + assign(test_msg_.corrs[1].Q, 1675764777); + + assign(test_msg_.corrs[2].I, -267498681); + assign(test_msg_.corrs[2].Q, 1403998854); + assign(test_msg_.sid.code, 15); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 64028); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_iq_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingIqDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingIqDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_iq_dep_a, + sizeof(msg->tracking_iq_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_iq_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_iq_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingIqDepA); + info.sender_id = 17336; + info.preamble = 0x55; + info.crc = 0x2211; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 29; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_iq_dep_a_t &lesser, + const sbp_msg_tracking_iq_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_iq_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_iq_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgTrackingIqDepA, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingIqDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingIqDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingIqDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_iq_dep_a_t test_msg_{}; + uint8_t encoded_frame_[29 + 8] = { + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, + 170, 96, 71, 121, 33, 161, 52, 211, 162, 101, 41, 36, 226, + 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + }; + uint8_t encoded_payload_[29] = { + 139, 28, 250, 15, 0, 99, 90, 170, 96, 71, 121, 33, 161, 52, 211, + 162, 101, 41, 36, 226, 99, 71, 75, 14, 240, 134, 82, 175, 83, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingIqDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingIqDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + + for (uint8_t i = 0; i < 29; i++) { + EXPECT_EQ( + sbp_msg_tracking_iq_dep_a_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingIqDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_iq_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIqDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingIqDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIqDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.channel, greater.channel); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].I, greater.corrs[0].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].Q, greater.corrs[0].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].I, greater.corrs[1].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].Q, greater.corrs[1].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].I, greater.corrs[2].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].Q, greater.corrs[2].Q); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingIqDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_IQ_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_iq_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_iq_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_iq_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_iq_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[29]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 29); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 29), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 29); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingIqDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingIqDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc new file mode 100644 index 0000000000..bccf79a467 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc @@ -0,0 +1,847 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingIqDepB0 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingIqDepB0() { + assign(test_msg_.channel, 45); + + assign(test_msg_.corrs[0].I, 261994824); + assign(test_msg_.corrs[0].Q, 409336251); + + assign(test_msg_.corrs[1].I, -525036921); + assign(test_msg_.corrs[1].Q, -795939973); + + assign(test_msg_.corrs[2].I, 353988710); + assign(test_msg_.corrs[2].Q, 1148477617); + assign(test_msg_.sid.code, 183); + assign(test_msg_.sid.sat, 188); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_iq_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingIqDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_iq_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingIqDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_iq_dep_b, + sizeof(msg->tracking_iq_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_iq_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_iq_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingIqDepB); + info.sender_id = 25895; + info.preamble = 0x55; + info.crc = 0x99f6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 27; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_iq_dep_b_t &lesser, + const sbp_msg_tracking_iq_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_iq_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_iq_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgTrackingIqDepB, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingIqDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingIqDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingIqDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_iq_dep_b_t test_msg_{}; + uint8_t encoded_frame_[27 + 8] = { + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, + 15, 187, 249, 101, 24, 135, 146, 180, 224, 123, 235, 142, + 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + }; + uint8_t encoded_payload_[27] = { + 45, 188, 183, 72, 185, 157, 15, 187, 249, 101, 24, 135, 146, 180, + 224, 123, 235, 142, 208, 102, 112, 25, 21, 177, 96, 116, 68, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingIqDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingIqDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + + for (uint8_t i = 0; i < 27; i++) { + EXPECT_EQ( + sbp_msg_tracking_iq_dep_b_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingIqDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_iq_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIqDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingIqDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingIqDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.channel, greater.channel); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].I, greater.corrs[0].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[0].Q, greater.corrs[0].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].I, greater.corrs[1].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[1].Q, greater.corrs[1].Q); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].I, greater.corrs[2].I); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.corrs[2].Q, greater.corrs[2].Q); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_iq_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_iq_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingIqDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_IQ_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_iq_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_iq_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_iq_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_iq_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[27]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 27); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 27), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_iq_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 27); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingIqDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingIqDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingIqDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingState.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingState.cc index 57cdc2a02b..99e71d7d9e 100644 --- a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingState.cc +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingState.cc @@ -16,1374 +16,7980 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_tracking_MsgTrackingState0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingState0 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingState0() { + assign(test_msg_.n_states, 63); + + assign(test_msg_.states[0].cn0, 102); + assign(test_msg_.states[0].fcn, 3); + assign(test_msg_.states[0].sid.code, 184); + assign(test_msg_.states[0].sid.sat, 117); + + assign(test_msg_.states[1].cn0, 141); + assign(test_msg_.states[1].fcn, 140); + assign(test_msg_.states[1].sid.code, 106); + assign(test_msg_.states[1].sid.sat, 38); + + assign(test_msg_.states[2].cn0, 195); + assign(test_msg_.states[2].fcn, 90); + assign(test_msg_.states[2].sid.code, 4); + assign(test_msg_.states[2].sid.sat, 25); + + assign(test_msg_.states[3].cn0, 82); + assign(test_msg_.states[3].fcn, 75); + assign(test_msg_.states[3].sid.code, 108); + assign(test_msg_.states[3].sid.sat, 246); + + assign(test_msg_.states[4].cn0, 163); + assign(test_msg_.states[4].fcn, 45); + assign(test_msg_.states[4].sid.code, 127); + assign(test_msg_.states[4].sid.sat, 137); + + assign(test_msg_.states[5].cn0, 93); + assign(test_msg_.states[5].fcn, 187); + assign(test_msg_.states[5].sid.code, 46); + assign(test_msg_.states[5].sid.sat, 32); + + assign(test_msg_.states[6].cn0, 147); + assign(test_msg_.states[6].fcn, 201); + assign(test_msg_.states[6].sid.code, 60); + assign(test_msg_.states[6].sid.sat, 153); + + assign(test_msg_.states[7].cn0, 208); + assign(test_msg_.states[7].fcn, 5); + assign(test_msg_.states[7].sid.code, 29); + assign(test_msg_.states[7].sid.sat, 23); + + assign(test_msg_.states[8].cn0, 69); + assign(test_msg_.states[8].fcn, 219); + assign(test_msg_.states[8].sid.code, 30); + assign(test_msg_.states[8].sid.sat, 181); + + assign(test_msg_.states[9].cn0, 121); + assign(test_msg_.states[9].fcn, 3); + assign(test_msg_.states[9].sid.code, 136); + assign(test_msg_.states[9].sid.sat, 254); + + assign(test_msg_.states[10].cn0, 215); + assign(test_msg_.states[10].fcn, 144); + assign(test_msg_.states[10].sid.code, 98); + assign(test_msg_.states[10].sid.sat, 33); + + assign(test_msg_.states[11].cn0, 56); + assign(test_msg_.states[11].fcn, 14); + assign(test_msg_.states[11].sid.code, 182); + assign(test_msg_.states[11].sid.sat, 133); + + assign(test_msg_.states[12].cn0, 62); + assign(test_msg_.states[12].fcn, 218); + assign(test_msg_.states[12].sid.code, 77); + assign(test_msg_.states[12].sid.sat, 169); + + assign(test_msg_.states[13].cn0, 249); + assign(test_msg_.states[13].fcn, 171); + assign(test_msg_.states[13].sid.code, 84); + assign(test_msg_.states[13].sid.sat, 242); + + assign(test_msg_.states[14].cn0, 130); + assign(test_msg_.states[14].fcn, 131); + assign(test_msg_.states[14].sid.code, 137); + assign(test_msg_.states[14].sid.sat, 152); + + assign(test_msg_.states[15].cn0, 68); + assign(test_msg_.states[15].fcn, 42); + assign(test_msg_.states[15].sid.code, 21); + assign(test_msg_.states[15].sid.sat, 193); + + assign(test_msg_.states[16].cn0, 227); + assign(test_msg_.states[16].fcn, 216); + assign(test_msg_.states[16].sid.code, 227); + assign(test_msg_.states[16].sid.sat, 253); + + assign(test_msg_.states[17].cn0, 179); + assign(test_msg_.states[17].fcn, 210); + assign(test_msg_.states[17].sid.code, 26); + assign(test_msg_.states[17].sid.sat, 24); + + assign(test_msg_.states[18].cn0, 255); + assign(test_msg_.states[18].fcn, 227); + assign(test_msg_.states[18].sid.code, 15); + assign(test_msg_.states[18].sid.sat, 19); + + assign(test_msg_.states[19].cn0, 200); + assign(test_msg_.states[19].fcn, 187); + assign(test_msg_.states[19].sid.code, 75); + assign(test_msg_.states[19].sid.sat, 122); + + assign(test_msg_.states[20].cn0, 122); + assign(test_msg_.states[20].fcn, 218); + assign(test_msg_.states[20].sid.code, 48); + assign(test_msg_.states[20].sid.sat, 217); + + assign(test_msg_.states[21].cn0, 149); + assign(test_msg_.states[21].fcn, 142); + assign(test_msg_.states[21].sid.code, 238); + assign(test_msg_.states[21].sid.sat, 187); + + assign(test_msg_.states[22].cn0, 212); + assign(test_msg_.states[22].fcn, 251); + assign(test_msg_.states[22].sid.code, 55); + assign(test_msg_.states[22].sid.sat, 238); + + assign(test_msg_.states[23].cn0, 104); + assign(test_msg_.states[23].fcn, 194); + assign(test_msg_.states[23].sid.code, 160); + assign(test_msg_.states[23].sid.sat, 128); + + assign(test_msg_.states[24].cn0, 62); + assign(test_msg_.states[24].fcn, 141); + assign(test_msg_.states[24].sid.code, 255); + assign(test_msg_.states[24].sid.sat, 113); + + assign(test_msg_.states[25].cn0, 39); + assign(test_msg_.states[25].fcn, 245); + assign(test_msg_.states[25].sid.code, 69); + assign(test_msg_.states[25].sid.sat, 43); + + assign(test_msg_.states[26].cn0, 56); + assign(test_msg_.states[26].fcn, 108); + assign(test_msg_.states[26].sid.code, 230); + assign(test_msg_.states[26].sid.sat, 100); + + assign(test_msg_.states[27].cn0, 143); + assign(test_msg_.states[27].fcn, 149); + assign(test_msg_.states[27].sid.code, 68); + assign(test_msg_.states[27].sid.sat, 247); + + assign(test_msg_.states[28].cn0, 70); + assign(test_msg_.states[28].fcn, 233); + assign(test_msg_.states[28].sid.code, 101); + assign(test_msg_.states[28].sid.sat, 137); + + assign(test_msg_.states[29].cn0, 110); + assign(test_msg_.states[29].fcn, 38); + assign(test_msg_.states[29].sid.code, 165); + assign(test_msg_.states[29].sid.sat, 49); + + assign(test_msg_.states[30].cn0, 213); + assign(test_msg_.states[30].fcn, 80); + assign(test_msg_.states[30].sid.code, 230); + assign(test_msg_.states[30].sid.sat, 218); + + assign(test_msg_.states[31].cn0, 128); + assign(test_msg_.states[31].fcn, 139); + assign(test_msg_.states[31].sid.code, 179); + assign(test_msg_.states[31].sid.sat, 196); + + assign(test_msg_.states[32].cn0, 171); + assign(test_msg_.states[32].fcn, 196); + assign(test_msg_.states[32].sid.code, 178); + assign(test_msg_.states[32].sid.sat, 15); + + assign(test_msg_.states[33].cn0, 194); + assign(test_msg_.states[33].fcn, 97); + assign(test_msg_.states[33].sid.code, 212); + assign(test_msg_.states[33].sid.sat, 8); + + assign(test_msg_.states[34].cn0, 99); + assign(test_msg_.states[34].fcn, 79); + assign(test_msg_.states[34].sid.code, 233); + assign(test_msg_.states[34].sid.sat, 83); + + assign(test_msg_.states[35].cn0, 180); + assign(test_msg_.states[35].fcn, 31); + assign(test_msg_.states[35].sid.code, 90); + assign(test_msg_.states[35].sid.sat, 55); + + assign(test_msg_.states[36].cn0, 186); + assign(test_msg_.states[36].fcn, 105); + assign(test_msg_.states[36].sid.code, 25); + assign(test_msg_.states[36].sid.sat, 5); + + assign(test_msg_.states[37].cn0, 111); + assign(test_msg_.states[37].fcn, 80); + assign(test_msg_.states[37].sid.code, 224); + assign(test_msg_.states[37].sid.sat, 22); + + assign(test_msg_.states[38].cn0, 166); + assign(test_msg_.states[38].fcn, 106); + assign(test_msg_.states[38].sid.code, 48); + assign(test_msg_.states[38].sid.sat, 8); + + assign(test_msg_.states[39].cn0, 49); + assign(test_msg_.states[39].fcn, 156); + assign(test_msg_.states[39].sid.code, 48); + assign(test_msg_.states[39].sid.sat, 4); + + assign(test_msg_.states[40].cn0, 146); + assign(test_msg_.states[40].fcn, 142); + assign(test_msg_.states[40].sid.code, 19); + assign(test_msg_.states[40].sid.sat, 86); + + assign(test_msg_.states[41].cn0, 64); + assign(test_msg_.states[41].fcn, 115); + assign(test_msg_.states[41].sid.code, 124); + assign(test_msg_.states[41].sid.sat, 91); + + assign(test_msg_.states[42].cn0, 178); + assign(test_msg_.states[42].fcn, 115); + assign(test_msg_.states[42].sid.code, 230); + assign(test_msg_.states[42].sid.sat, 28); + + assign(test_msg_.states[43].cn0, 242); + assign(test_msg_.states[43].fcn, 16); + assign(test_msg_.states[43].sid.code, 131); + assign(test_msg_.states[43].sid.sat, 190); + + assign(test_msg_.states[44].cn0, 113); + assign(test_msg_.states[44].fcn, 182); + assign(test_msg_.states[44].sid.code, 59); + assign(test_msg_.states[44].sid.sat, 105); + + assign(test_msg_.states[45].cn0, 179); + assign(test_msg_.states[45].fcn, 48); + assign(test_msg_.states[45].sid.code, 180); + assign(test_msg_.states[45].sid.sat, 192); + + assign(test_msg_.states[46].cn0, 211); + assign(test_msg_.states[46].fcn, 172); + assign(test_msg_.states[46].sid.code, 31); + assign(test_msg_.states[46].sid.sat, 166); + + assign(test_msg_.states[47].cn0, 49); + assign(test_msg_.states[47].fcn, 140); + assign(test_msg_.states[47].sid.code, 228); + assign(test_msg_.states[47].sid.sat, 77); + + assign(test_msg_.states[48].cn0, 194); + assign(test_msg_.states[48].fcn, 240); + assign(test_msg_.states[48].sid.code, 77); + assign(test_msg_.states[48].sid.sat, 128); + + assign(test_msg_.states[49].cn0, 58); + assign(test_msg_.states[49].fcn, 41); + assign(test_msg_.states[49].sid.code, 194); + assign(test_msg_.states[49].sid.sat, 134); + + assign(test_msg_.states[50].cn0, 55); + assign(test_msg_.states[50].fcn, 129); + assign(test_msg_.states[50].sid.code, 53); + assign(test_msg_.states[50].sid.sat, 18); + + assign(test_msg_.states[51].cn0, 92); + assign(test_msg_.states[51].fcn, 134); + assign(test_msg_.states[51].sid.code, 72); + assign(test_msg_.states[51].sid.sat, 91); + + assign(test_msg_.states[52].cn0, 56); + assign(test_msg_.states[52].fcn, 157); + assign(test_msg_.states[52].sid.code, 224); + assign(test_msg_.states[52].sid.sat, 33); + + assign(test_msg_.states[53].cn0, 174); + assign(test_msg_.states[53].fcn, 224); + assign(test_msg_.states[53].sid.code, 54); + assign(test_msg_.states[53].sid.sat, 186); + + assign(test_msg_.states[54].cn0, 190); + assign(test_msg_.states[54].fcn, 148); + assign(test_msg_.states[54].sid.code, 84); + assign(test_msg_.states[54].sid.sat, 82); + + assign(test_msg_.states[55].cn0, 67); + assign(test_msg_.states[55].fcn, 62); + assign(test_msg_.states[55].sid.code, 54); + assign(test_msg_.states[55].sid.sat, 236); + + assign(test_msg_.states[56].cn0, 254); + assign(test_msg_.states[56].fcn, 57); + assign(test_msg_.states[56].sid.code, 215); + assign(test_msg_.states[56].sid.sat, 52); + + assign(test_msg_.states[57].cn0, 174); + assign(test_msg_.states[57].fcn, 36); + assign(test_msg_.states[57].sid.code, 133); + assign(test_msg_.states[57].sid.sat, 16); + + assign(test_msg_.states[58].cn0, 17); + assign(test_msg_.states[58].fcn, 145); + assign(test_msg_.states[58].sid.code, 172); + assign(test_msg_.states[58].sid.sat, 219); + + assign(test_msg_.states[59].cn0, 97); + assign(test_msg_.states[59].fcn, 111); + assign(test_msg_.states[59].sid.code, 179); + assign(test_msg_.states[59].sid.sat, 192); + + assign(test_msg_.states[60].cn0, 134); + assign(test_msg_.states[60].fcn, 208); + assign(test_msg_.states[60].sid.code, 56); + assign(test_msg_.states[60].sid.sat, 207); + + assign(test_msg_.states[61].cn0, 226); + assign(test_msg_.states[61].fcn, 43); + assign(test_msg_.states[61].sid.code, 17); + assign(test_msg_.states[61].sid.sat, 180); + + assign(test_msg_.states[62].cn0, 113); + assign(test_msg_.states[62].fcn, 140); + assign(test_msg_.states[62].sid.code, 182); + assign(test_msg_.states[62].sid.sat, 255); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingState, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingState); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state, + sizeof(msg->tracking_state)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingState); + info.sender_id = 33079; + info.preamble = 0x55; + info.crc = 0x6f8d; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 252; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_t &lesser, + const sbp_msg_tracking_state_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgTrackingState, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingState, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgTrackingState, &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgTrackingState, &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_t test_msg_{}; + uint8_t encoded_frame_[252 + 8] = { + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, 25, + 4, 90, 195, 246, 108, 75, 82, 137, 127, 45, 163, 32, 46, 187, 93, + 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, 219, 69, 254, 136, 3, + 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, 218, 62, 242, 84, + 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, 253, 227, 216, 227, 24, + 26, 210, 179, 19, 15, 227, 255, 122, 75, 187, 200, 217, 48, 218, 122, + 187, 238, 142, 149, 238, 55, 251, 212, 128, 160, 194, 104, 113, 255, 141, + 62, 43, 69, 245, 39, 100, 230, 108, 56, 247, 68, 149, 143, 137, 101, + 233, 70, 49, 165, 38, 110, 218, 230, 80, 213, 196, 179, 139, 128, 15, + 178, 196, 171, 8, 212, 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, + 5, 25, 105, 186, 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, + 49, 86, 19, 142, 146, 91, 124, 115, 64, 28, 230, 115, 178, 190, 131, + 16, 242, 105, 59, 182, 113, 192, 180, 48, 179, 166, 31, 172, 211, 77, + 228, 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, 129, 55, + 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, 148, + 190, 236, 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, 219, 172, + 145, 17, 192, 179, 111, 97, 207, 56, 208, 134, 180, 17, 43, 226, 255, + 182, 140, 113, 141, 111, + }; + uint8_t encoded_payload_[252] = { + 117, 184, 3, 102, 38, 106, 140, 141, 25, 4, 90, 195, 246, 108, 75, + 82, 137, 127, 45, 163, 32, 46, 187, 93, 153, 60, 201, 147, 23, 29, + 5, 208, 181, 30, 219, 69, 254, 136, 3, 121, 33, 98, 144, 215, 133, + 182, 14, 56, 169, 77, 218, 62, 242, 84, 171, 249, 152, 137, 131, 130, + 193, 21, 42, 68, 253, 227, 216, 227, 24, 26, 210, 179, 19, 15, 227, + 255, 122, 75, 187, 200, 217, 48, 218, 122, 187, 238, 142, 149, 238, 55, + 251, 212, 128, 160, 194, 104, 113, 255, 141, 62, 43, 69, 245, 39, 100, + 230, 108, 56, 247, 68, 149, 143, 137, 101, 233, 70, 49, 165, 38, 110, + 218, 230, 80, 213, 196, 179, 139, 128, 15, 178, 196, 171, 8, 212, 97, + 194, 83, 233, 79, 99, 55, 90, 31, 180, 5, 25, 105, 186, 22, 224, + 80, 111, 8, 48, 106, 166, 4, 48, 156, 49, 86, 19, 142, 146, 91, + 124, 115, 64, 28, 230, 115, 178, 190, 131, 16, 242, 105, 59, 182, 113, + 192, 180, 48, 179, 166, 31, 172, 211, 77, 228, 140, 49, 128, 77, 240, + 194, 134, 194, 41, 58, 18, 53, 129, 55, 91, 72, 134, 92, 33, 224, + 157, 56, 186, 54, 224, 174, 82, 84, 148, 190, 236, 54, 62, 67, 52, + 215, 57, 254, 16, 133, 36, 174, 219, 172, 145, 17, 192, 179, 111, 97, + 207, 56, 208, 134, 180, 17, 43, 226, 255, 182, 140, 113, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingState, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingState, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + EXPECT_EQ(sbp_msg_tracking_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + for (uint8_t i = 0; i < 252; i++) { + EXPECT_EQ( + sbp_msg_tracking_state_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_decode(&info.encoded_payload[0], + info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingState, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_decode(&info.encoded_payload[0], + info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_t t{}; + return sbp_msg_tracking_state_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingState, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingState, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].fcn, greater.states[0].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].fcn, greater.states[1].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].fcn, greater.states[2].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].fcn, greater.states[3].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].fcn, greater.states[4].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].fcn, greater.states[5].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].fcn, greater.states[6].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].fcn, greater.states[7].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].fcn, greater.states[8].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].fcn, greater.states[9].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].fcn, greater.states[10].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].cn0, greater.states[11].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].fcn, greater.states[11].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].sid.code, + greater.states[11].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].sid.sat, greater.states[11].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].cn0, greater.states[12].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].fcn, greater.states[12].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].sid.code, + greater.states[12].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].sid.sat, greater.states[12].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].cn0, greater.states[13].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].fcn, greater.states[13].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].sid.code, + greater.states[13].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].sid.sat, greater.states[13].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].cn0, greater.states[14].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].fcn, greater.states[14].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].sid.code, + greater.states[14].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].sid.sat, greater.states[14].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].cn0, greater.states[15].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].fcn, greater.states[15].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].sid.code, + greater.states[15].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].sid.sat, greater.states[15].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].cn0, greater.states[16].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].fcn, greater.states[16].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].sid.code, + greater.states[16].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].sid.sat, greater.states[16].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].cn0, greater.states[17].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].fcn, greater.states[17].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].sid.code, + greater.states[17].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].sid.sat, greater.states[17].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].cn0, greater.states[18].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].fcn, greater.states[18].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].sid.code, + greater.states[18].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].sid.sat, greater.states[18].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].cn0, greater.states[19].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].fcn, greater.states[19].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].sid.code, + greater.states[19].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].sid.sat, greater.states[19].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].cn0, greater.states[20].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].fcn, greater.states[20].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].sid.code, + greater.states[20].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].sid.sat, greater.states[20].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].cn0, greater.states[21].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].fcn, greater.states[21].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].sid.code, + greater.states[21].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].sid.sat, greater.states[21].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].cn0, greater.states[22].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].fcn, greater.states[22].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].sid.code, + greater.states[22].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].sid.sat, greater.states[22].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].cn0, greater.states[23].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].fcn, greater.states[23].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].sid.code, + greater.states[23].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].sid.sat, greater.states[23].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].cn0, greater.states[24].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].fcn, greater.states[24].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].sid.code, + greater.states[24].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].sid.sat, greater.states[24].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].cn0, greater.states[25].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].fcn, greater.states[25].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].sid.code, + greater.states[25].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].sid.sat, greater.states[25].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].cn0, greater.states[26].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].fcn, greater.states[26].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].sid.code, + greater.states[26].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].sid.sat, greater.states[26].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].cn0, greater.states[27].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].fcn, greater.states[27].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].sid.code, + greater.states[27].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].sid.sat, greater.states[27].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].cn0, greater.states[28].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].fcn, greater.states[28].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].sid.code, + greater.states[28].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[28].sid.sat, greater.states[28].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].cn0, greater.states[29].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].fcn, greater.states[29].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].sid.code, + greater.states[29].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[29].sid.sat, greater.states[29].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].cn0, greater.states[30].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].fcn, greater.states[30].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].sid.code, + greater.states[30].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[30].sid.sat, greater.states[30].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].cn0, greater.states[31].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].fcn, greater.states[31].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].sid.code, + greater.states[31].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[31].sid.sat, greater.states[31].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].cn0, greater.states[32].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].fcn, greater.states[32].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].sid.code, + greater.states[32].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[32].sid.sat, greater.states[32].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].cn0, greater.states[33].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].fcn, greater.states[33].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].sid.code, + greater.states[33].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[33].sid.sat, greater.states[33].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].cn0, greater.states[34].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].fcn, greater.states[34].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].sid.code, + greater.states[34].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[34].sid.sat, greater.states[34].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].cn0, greater.states[35].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].fcn, greater.states[35].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].sid.code, + greater.states[35].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[35].sid.sat, greater.states[35].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].cn0, greater.states[36].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].fcn, greater.states[36].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].sid.code, + greater.states[36].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[36].sid.sat, greater.states[36].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].cn0, greater.states[37].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].fcn, greater.states[37].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].sid.code, + greater.states[37].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[37].sid.sat, greater.states[37].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].cn0, greater.states[38].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].fcn, greater.states[38].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].sid.code, + greater.states[38].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[38].sid.sat, greater.states[38].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].cn0, greater.states[39].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].fcn, greater.states[39].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].sid.code, + greater.states[39].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[39].sid.sat, greater.states[39].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].cn0, greater.states[40].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].fcn, greater.states[40].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].sid.code, + greater.states[40].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[40].sid.sat, greater.states[40].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].cn0, greater.states[41].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].fcn, greater.states[41].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].sid.code, + greater.states[41].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[41].sid.sat, greater.states[41].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].cn0, greater.states[42].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].fcn, greater.states[42].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].sid.code, + greater.states[42].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[42].sid.sat, greater.states[42].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].cn0, greater.states[43].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].fcn, greater.states[43].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].sid.code, + greater.states[43].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[43].sid.sat, greater.states[43].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].cn0, greater.states[44].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].fcn, greater.states[44].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].sid.code, + greater.states[44].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[44].sid.sat, greater.states[44].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].cn0, greater.states[45].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].fcn, greater.states[45].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].sid.code, + greater.states[45].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[45].sid.sat, greater.states[45].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].cn0, greater.states[46].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].fcn, greater.states[46].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].sid.code, + greater.states[46].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[46].sid.sat, greater.states[46].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].cn0, greater.states[47].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].fcn, greater.states[47].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].sid.code, + greater.states[47].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[47].sid.sat, greater.states[47].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].cn0, greater.states[48].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].fcn, greater.states[48].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].sid.code, + greater.states[48].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[48].sid.sat, greater.states[48].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].cn0, greater.states[49].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].fcn, greater.states[49].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].sid.code, + greater.states[49].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[49].sid.sat, greater.states[49].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].cn0, greater.states[50].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].fcn, greater.states[50].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].sid.code, + greater.states[50].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[50].sid.sat, greater.states[50].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].cn0, greater.states[51].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].fcn, greater.states[51].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].sid.code, + greater.states[51].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[51].sid.sat, greater.states[51].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].cn0, greater.states[52].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].fcn, greater.states[52].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].sid.code, + greater.states[52].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[52].sid.sat, greater.states[52].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].cn0, greater.states[53].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].fcn, greater.states[53].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].sid.code, + greater.states[53].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[53].sid.sat, greater.states[53].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].cn0, greater.states[54].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].fcn, greater.states[54].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].sid.code, + greater.states[54].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[54].sid.sat, greater.states[54].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].cn0, greater.states[55].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].fcn, greater.states[55].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].sid.code, + greater.states[55].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[55].sid.sat, greater.states[55].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].cn0, greater.states[56].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].fcn, greater.states[56].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].sid.code, + greater.states[56].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[56].sid.sat, greater.states[56].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].cn0, greater.states[57].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].fcn, greater.states[57].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].sid.code, + greater.states[57].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[57].sid.sat, greater.states[57].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].cn0, greater.states[58].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].fcn, greater.states[58].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].sid.code, + greater.states[58].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[58].sid.sat, greater.states[58].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].cn0, greater.states[59].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].fcn, greater.states[59].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].sid.code, + greater.states[59].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[59].sid.sat, greater.states[59].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].cn0, greater.states[60].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].fcn, greater.states[60].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].sid.code, + greater.states[60].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[60].sid.sat, greater.states[60].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].cn0, greater.states[61].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].fcn, greater.states[61].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].sid.code, + greater.states[61].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[61].sid.sat, greater.states[61].sid.sat); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].cn0, greater.states[62].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].fcn, greater.states[62].fcn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].sid.code, + greater.states[62].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_t lesser = info.test_msg; + sbp_msg_tracking_state_t greater = info.test_msg; + make_lesser_greater(lesser.states[62].sid.sat, greater.states[62].sid.sat); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingState); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.tracking_state, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingState, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingState, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingState1 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingState1() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 39.24782180786133); + assign(test_msg_.states[0].sid.code, 0); + assign(test_msg_.states[0].sid.reserved, 0); + assign(test_msg_.states[0].sid.sat, 202); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 36.09756088256836); + assign(test_msg_.states[1].sid.code, 0); + assign(test_msg_.states[1].sid.reserved, 0); + assign(test_msg_.states[1].sid.sat, 203); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 37.62678527832031); + assign(test_msg_.states[2].sid.code, 0); + assign(test_msg_.states[2].sid.reserved, 0); + assign(test_msg_.states[2].sid.sat, 208); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 39.020729064941406); + assign(test_msg_.states[3].sid.code, 0); + assign(test_msg_.states[3].sid.reserved, 0); + assign(test_msg_.states[3].sid.sat, 212); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 42.03290557861328); + assign(test_msg_.states[4].sid.code, 0); + assign(test_msg_.states[4].sid.reserved, 0); + assign(test_msg_.states[4].sid.sat, 217); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 37.43546676635742); + assign(test_msg_.states[5].sid.code, 0); + assign(test_msg_.states[5].sid.reserved, 0); + assign(test_msg_.states[5].sid.sat, 218); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 38.4229621887207); + assign(test_msg_.states[6].sid.code, 0); + assign(test_msg_.states[6].sid.reserved, 0); + assign(test_msg_.states[6].sid.sat, 220); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 38.91520309448242); + assign(test_msg_.states[7].sid.code, 0); + assign(test_msg_.states[7].sid.reserved, 0); + assign(test_msg_.states[7].sid.sat, 222); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 42.62259292602539); + assign(test_msg_.states[8].sid.code, 0); + assign(test_msg_.states[8].sid.reserved, 0); + assign(test_msg_.states[8].sid.sat, 225); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].sid.code, 0); + assign(test_msg_.states[9].sid.reserved, 0); + assign(test_msg_.states[9].sid.sat, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].sid.code, 0); + assign(test_msg_.states[10].sid.reserved, 0); + assign(test_msg_.states[10].sid.sat, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x61de; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, + 66, 1, 203, 0, 0, 0, 231, 99, 16, 66, 1, 208, 0, 0, + 0, 212, 129, 22, 66, 1, 212, 0, 0, 0, 58, 21, 28, 66, + 1, 217, 0, 0, 0, 178, 33, 40, 66, 1, 218, 0, 0, 0, + 235, 189, 21, 66, 1, 220, 0, 0, 0, 29, 177, 25, 66, 1, + 222, 0, 0, 0, 43, 169, 27, 66, 1, 225, 0, 0, 0, 137, + 125, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, + 0, 0, 0, 0, 0, 128, 191, 222, 97, + }; + uint8_t encoded_payload_[99] = { + 1, 202, 0, 0, 0, 197, 253, 28, 66, 1, 203, 0, 0, 0, 231, 99, 16, 66, + 1, 208, 0, 0, 0, 212, 129, 22, 66, 1, 212, 0, 0, 0, 58, 21, 28, 66, + 1, 217, 0, 0, 0, 178, 33, 40, 66, 1, 218, 0, 0, 0, 235, 189, 21, 66, + 1, 220, 0, 0, 0, 29, 177, 25, 66, 1, 222, 0, 0, 0, 43, 169, 27, 66, + 1, 225, 0, 0, 0, 137, 125, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingState2 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingState2() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 38.994117736816406); + assign(test_msg_.states[0].sid.code, 0); + assign(test_msg_.states[0].sid.reserved, 0); + assign(test_msg_.states[0].sid.sat, 202); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 34.889801025390625); + assign(test_msg_.states[1].sid.code, 0); + assign(test_msg_.states[1].sid.reserved, 0); + assign(test_msg_.states[1].sid.sat, 203); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 37.44603729248047); + assign(test_msg_.states[2].sid.code, 0); + assign(test_msg_.states[2].sid.reserved, 0); + assign(test_msg_.states[2].sid.sat, 208); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 38.72849655151367); + assign(test_msg_.states[3].sid.code, 0); + assign(test_msg_.states[3].sid.reserved, 0); + assign(test_msg_.states[3].sid.sat, 212); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 41.983219146728516); + assign(test_msg_.states[4].sid.code, 0); + assign(test_msg_.states[4].sid.reserved, 0); + assign(test_msg_.states[4].sid.sat, 217); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 37.46448516845703); + assign(test_msg_.states[5].sid.code, 0); + assign(test_msg_.states[5].sid.reserved, 0); + assign(test_msg_.states[5].sid.sat, 218); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 38.44300079345703); + assign(test_msg_.states[6].sid.code, 0); + assign(test_msg_.states[6].sid.reserved, 0); + assign(test_msg_.states[6].sid.sat, 220); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 39.03423309326172); + assign(test_msg_.states[7].sid.code, 0); + assign(test_msg_.states[7].sid.reserved, 0); + assign(test_msg_.states[7].sid.sat, 222); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 42.89944839477539); + assign(test_msg_.states[8].sid.code, 0); + assign(test_msg_.states[8].sid.reserved, 0); + assign(test_msg_.states[8].sid.sat, 225); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].sid.code, 0); + assign(test_msg_.states[9].sid.reserved, 0); + assign(test_msg_.states[9].sid.sat, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].sid.code, 0); + assign(test_msg_.states[10].sid.reserved, 0); + assign(test_msg_.states[10].sid.sat, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x1f14; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 250, 249, 27, + 66, 1, 203, 0, 0, 0, 40, 143, 11, 66, 1, 208, 0, 0, + 0, 190, 200, 21, 66, 1, 212, 0, 0, 0, 251, 233, 26, 66, + 1, 217, 0, 0, 0, 209, 238, 39, 66, 1, 218, 0, 0, 0, + 162, 219, 21, 66, 1, 220, 0, 0, 0, 162, 197, 25, 66, 1, + 222, 0, 0, 0, 14, 35, 28, 66, 1, 225, 0, 0, 0, 9, + 153, 43, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, + 0, 0, 0, 0, 0, 128, 191, 20, 31, + }; + uint8_t encoded_payload_[99] = { + 1, 202, 0, 0, 0, 250, 249, 27, 66, 1, 203, 0, 0, 0, 40, 143, 11, 66, + 1, 208, 0, 0, 0, 190, 200, 21, 66, 1, 212, 0, 0, 0, 251, 233, 26, 66, + 1, 217, 0, 0, 0, 209, 238, 39, 66, 1, 218, 0, 0, 0, 162, 219, 21, 66, + 1, 220, 0, 0, 0, 162, 197, 25, 66, 1, 222, 0, 0, 0, 14, 35, 28, 66, + 1, 225, 0, 0, 0, 9, 153, 43, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingState3 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingState3() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 38.95457077026367); + assign(test_msg_.states[0].sid.code, 0); + assign(test_msg_.states[0].sid.reserved, 0); + assign(test_msg_.states[0].sid.sat, 202); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 35.813316345214844); + assign(test_msg_.states[1].sid.code, 0); + assign(test_msg_.states[1].sid.reserved, 0); + assign(test_msg_.states[1].sid.sat, 203); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 37.553924560546875); + assign(test_msg_.states[2].sid.code, 0); + assign(test_msg_.states[2].sid.reserved, 0); + assign(test_msg_.states[2].sid.sat, 208); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 38.88901901245117); + assign(test_msg_.states[3].sid.code, 0); + assign(test_msg_.states[3].sid.reserved, 0); + assign(test_msg_.states[3].sid.sat, 212); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 42.4013557434082); + assign(test_msg_.states[4].sid.code, 0); + assign(test_msg_.states[4].sid.reserved, 0); + assign(test_msg_.states[4].sid.sat, 217); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 37.63916015625); + assign(test_msg_.states[5].sid.code, 0); + assign(test_msg_.states[5].sid.reserved, 0); + assign(test_msg_.states[5].sid.sat, 218); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 37.919986724853516); + assign(test_msg_.states[6].sid.code, 0); + assign(test_msg_.states[6].sid.reserved, 0); + assign(test_msg_.states[6].sid.sat, 220); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 39.25254440307617); + assign(test_msg_.states[7].sid.code, 0); + assign(test_msg_.states[7].sid.reserved, 0); + assign(test_msg_.states[7].sid.sat, 222); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 42.59827423095703); + assign(test_msg_.states[8].sid.code, 0); + assign(test_msg_.states[8].sid.reserved, 0); + assign(test_msg_.states[8].sid.sat, 225); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].sid.code, 0); + assign(test_msg_.states[9].sid.reserved, 0); + assign(test_msg_.states[9].sid.sat, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].sid.code, 0); + assign(test_msg_.states[10].sid.reserved, 0); + assign(test_msg_.states[10].sid.sat, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x47e9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 123, 209, 27, + 66, 1, 203, 0, 0, 0, 214, 64, 15, 66, 1, 208, 0, 0, + 0, 56, 55, 22, 66, 1, 212, 0, 0, 0, 91, 142, 27, 66, + 1, 217, 0, 0, 0, 253, 154, 41, 66, 1, 218, 0, 0, 0, + 128, 142, 22, 66, 1, 220, 0, 0, 0, 17, 174, 23, 66, 1, + 222, 0, 0, 0, 155, 2, 29, 66, 1, 225, 0, 0, 0, 162, + 100, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, + 0, 0, 0, 0, 0, 128, 191, 233, 71, + }; + uint8_t encoded_payload_[99] = { + 1, 202, 0, 0, 0, 123, 209, 27, 66, 1, 203, 0, 0, 0, 214, 64, 15, 66, + 1, 208, 0, 0, 0, 56, 55, 22, 66, 1, 212, 0, 0, 0, 91, 142, 27, 66, + 1, 217, 0, 0, 0, 253, 154, 41, 66, 1, 218, 0, 0, 0, 128, 142, 22, 66, + 1, 220, 0, 0, 0, 17, 174, 23, 66, 1, 222, 0, 0, 0, 155, 2, 29, 66, + 1, 225, 0, 0, 0, 162, 100, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingState4 : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingState4() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 39.369598388671875); + assign(test_msg_.states[0].sid.code, 0); + assign(test_msg_.states[0].sid.reserved, 0); + assign(test_msg_.states[0].sid.sat, 202); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 36.52173614501953); + assign(test_msg_.states[1].sid.code, 0); + assign(test_msg_.states[1].sid.reserved, 0); + assign(test_msg_.states[1].sid.sat, 203); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 38.15976333618164); + assign(test_msg_.states[2].sid.code, 0); + assign(test_msg_.states[2].sid.reserved, 0); + assign(test_msg_.states[2].sid.sat, 208); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 39.19989776611328); + assign(test_msg_.states[3].sid.code, 0); + assign(test_msg_.states[3].sid.reserved, 0); + assign(test_msg_.states[3].sid.sat, 212); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 41.55845642089844); + assign(test_msg_.states[4].sid.code, 0); + assign(test_msg_.states[4].sid.reserved, 0); + assign(test_msg_.states[4].sid.sat, 217); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 37.026981353759766); + assign(test_msg_.states[5].sid.code, 0); + assign(test_msg_.states[5].sid.reserved, 0); + assign(test_msg_.states[5].sid.sat, 218); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 38.1049690246582); + assign(test_msg_.states[6].sid.code, 0); + assign(test_msg_.states[6].sid.reserved, 0); + assign(test_msg_.states[6].sid.sat, 220); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 39.04584503173828); + assign(test_msg_.states[7].sid.code, 0); + assign(test_msg_.states[7].sid.reserved, 0); + assign(test_msg_.states[7].sid.sat, 222); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 42.37783432006836); + assign(test_msg_.states[8].sid.code, 0); + assign(test_msg_.states[8].sid.reserved, 0); + assign(test_msg_.states[8].sid.sat, 225); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].sid.code, 0); + assign(test_msg_.states[9].sid.reserved, 0); + assign(test_msg_.states[9].sid.sat, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].sid.code, 0); + assign(test_msg_.states[10].sid.reserved, 0); + assign(test_msg_.states[10].sid.sat, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0xc149; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 120, 122, 29, + 66, 1, 203, 0, 0, 0, 66, 22, 18, 66, 1, 208, 0, 0, + 0, 153, 163, 24, 66, 1, 212, 0, 0, 0, 178, 204, 28, 66, + 1, 217, 0, 0, 0, 220, 59, 38, 66, 1, 218, 0, 0, 0, + 161, 27, 20, 66, 1, 220, 0, 0, 0, 125, 107, 24, 66, 1, + 222, 0, 0, 0, 242, 46, 28, 66, 1, 225, 0, 0, 0, 231, + 130, 41, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, + 0, 0, 0, 0, 0, 128, 191, 73, 193, + }; + uint8_t encoded_payload_[99] = { + 1, 202, 0, 0, 0, 120, 122, 29, 66, 1, 203, 0, 0, 0, 66, 22, 18, 66, + 1, 208, 0, 0, 0, 153, 163, 24, 66, 1, 212, 0, 0, 0, 178, 204, 28, 66, + 1, 217, 0, 0, 0, 220, 59, 38, 66, 1, 218, 0, 0, 0, 161, 27, 20, 66, + 1, 220, 0, 0, 0, 125, 107, 24, 66, 1, 222, 0, 0, 0, 242, 46, 28, 66, + 1, 225, 0, 0, 0, 231, 130, 41, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingState5 : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgTrackingState0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgTrackingState5() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 39.70351791381836); + assign(test_msg_.states[0].sid.code, 0); + assign(test_msg_.states[0].sid.reserved, 0); + assign(test_msg_.states[0].sid.sat, 202); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 36.52388381958008); + assign(test_msg_.states[1].sid.code, 0); + assign(test_msg_.states[1].sid.reserved, 0); + assign(test_msg_.states[1].sid.sat, 203); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 37.169708251953125); + assign(test_msg_.states[2].sid.code, 0); + assign(test_msg_.states[2].sid.reserved, 0); + assign(test_msg_.states[2].sid.sat, 208); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 38.81692886352539); + assign(test_msg_.states[3].sid.code, 0); + assign(test_msg_.states[3].sid.reserved, 0); + assign(test_msg_.states[3].sid.sat, 212); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 42.05073165893555); + assign(test_msg_.states[4].sid.code, 0); + assign(test_msg_.states[4].sid.reserved, 0); + assign(test_msg_.states[4].sid.sat, 217); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 37.807498931884766); + assign(test_msg_.states[5].sid.code, 0); + assign(test_msg_.states[5].sid.reserved, 0); + assign(test_msg_.states[5].sid.sat, 218); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 37.71632385253906); + assign(test_msg_.states[6].sid.code, 0); + assign(test_msg_.states[6].sid.reserved, 0); + assign(test_msg_.states[6].sid.sat, 220); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 38.5289192199707); + assign(test_msg_.states[7].sid.code, 0); + assign(test_msg_.states[7].sid.reserved, 0); + assign(test_msg_.states[7].sid.sat, 222); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 42.27101516723633); + assign(test_msg_.states[8].sid.code, 0); + assign(test_msg_.states[8].sid.reserved, 0); + assign(test_msg_.states[8].sid.sat, 225); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].sid.code, 0); + assign(test_msg_.states[9].sid.reserved, 0); + assign(test_msg_.states[9].sid.sat, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].sid.code, 0); + assign(test_msg_.states[10].sid.reserved, 0); + assign(test_msg_.states[10].sid.sat, 0); + assign(test_msg_.states[10].state, 0); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState0, Test) { - uint8_t encoded_frame[] = { - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, - 66, 1, 203, 0, 0, 0, 231, 99, 16, 66, 1, 208, 0, 0, - 0, 212, 129, 22, 66, 1, 212, 0, 0, 0, 58, 21, 28, 66, - 1, 217, 0, 0, 0, 178, 33, 40, 66, 1, 218, 0, 0, 0, - 235, 189, 21, 66, 1, 220, 0, 0, 0, 29, 177, 25, 66, 1, - 222, 0, 0, 0, 43, 169, 27, 66, 1, 225, 0, 0, 0, 137, - 125, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, - 0, 0, 0, 0, 0, 128, 191, 222, 97, + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } }; - sbp_msg_tracking_state_dep_b_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 39.24782180786133; - test_msg.states[0].sid.code = 0; - test_msg.states[0].sid.reserved = 0; - test_msg.states[0].sid.sat = 202; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 36.09756088256836; - test_msg.states[1].sid.code = 0; - test_msg.states[1].sid.reserved = 0; - test_msg.states[1].sid.sat = 203; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 37.62678527832031; - test_msg.states[2].sid.code = 0; - test_msg.states[2].sid.reserved = 0; - test_msg.states[2].sid.sat = 208; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 39.020729064941406; - test_msg.states[3].sid.code = 0; - test_msg.states[3].sid.reserved = 0; - test_msg.states[3].sid.sat = 212; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 42.03290557861328; - test_msg.states[4].sid.code = 0; - test_msg.states[4].sid.reserved = 0; - test_msg.states[4].sid.sat = 217; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 37.43546676635742; - test_msg.states[5].sid.code = 0; - test_msg.states[5].sid.reserved = 0; - test_msg.states[5].sid.sat = 218; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 38.4229621887207; - test_msg.states[6].sid.code = 0; - test_msg.states[6].sid.reserved = 0; - test_msg.states[6].sid.sat = 220; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 38.91520309448242; - test_msg.states[7].sid.code = 0; - test_msg.states[7].sid.reserved = 0; - test_msg.states[7].sid.sat = 222; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 42.62259292602539; - test_msg.states[8].sid.code = 0; - test_msg.states[8].sid.reserved = 0; - test_msg.states[8].sid.sat = 225; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].sid.code = 0; - test_msg.states[9].sid.reserved = 0; - test_msg.states[9].sid.sat = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].sid.code = 0; - test_msg.states[10].sid.reserved = 0; - test_msg.states[10].sid.sat = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 39.2478218079 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 39.2478218079, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].sid.code, 0) - << "incorrect value for last_msg_.states[0].sid.code, expected 0, is " - << last_msg_.states[0].sid.code; - EXPECT_EQ(last_msg_.states[0].sid.reserved, 0) - << "incorrect value for last_msg_.states[0].sid.reserved, expected 0, is " - << last_msg_.states[0].sid.reserved; - EXPECT_EQ(last_msg_.states[0].sid.sat, 202) - << "incorrect value for last_msg_.states[0].sid.sat, expected 202, is " - << last_msg_.states[0].sid.sat; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 36.0975608826 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 36.0975608826, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].sid.code, 0) - << "incorrect value for last_msg_.states[1].sid.code, expected 0, is " - << last_msg_.states[1].sid.code; - EXPECT_EQ(last_msg_.states[1].sid.reserved, 0) - << "incorrect value for last_msg_.states[1].sid.reserved, expected 0, is " - << last_msg_.states[1].sid.reserved; - EXPECT_EQ(last_msg_.states[1].sid.sat, 203) - << "incorrect value for last_msg_.states[1].sid.sat, expected 203, is " - << last_msg_.states[1].sid.sat; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 37.6267852783 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 37.6267852783, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].sid.code, 0) - << "incorrect value for last_msg_.states[2].sid.code, expected 0, is " - << last_msg_.states[2].sid.code; - EXPECT_EQ(last_msg_.states[2].sid.reserved, 0) - << "incorrect value for last_msg_.states[2].sid.reserved, expected 0, is " - << last_msg_.states[2].sid.reserved; - EXPECT_EQ(last_msg_.states[2].sid.sat, 208) - << "incorrect value for last_msg_.states[2].sid.sat, expected 208, is " - << last_msg_.states[2].sid.sat; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 39.0207290649 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 39.0207290649, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].sid.code, 0) - << "incorrect value for last_msg_.states[3].sid.code, expected 0, is " - << last_msg_.states[3].sid.code; - EXPECT_EQ(last_msg_.states[3].sid.reserved, 0) - << "incorrect value for last_msg_.states[3].sid.reserved, expected 0, is " - << last_msg_.states[3].sid.reserved; - EXPECT_EQ(last_msg_.states[3].sid.sat, 212) - << "incorrect value for last_msg_.states[3].sid.sat, expected 212, is " - << last_msg_.states[3].sid.sat; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 42.0329055786 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 42.0329055786, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].sid.code, 0) - << "incorrect value for last_msg_.states[4].sid.code, expected 0, is " - << last_msg_.states[4].sid.code; - EXPECT_EQ(last_msg_.states[4].sid.reserved, 0) - << "incorrect value for last_msg_.states[4].sid.reserved, expected 0, is " - << last_msg_.states[4].sid.reserved; - EXPECT_EQ(last_msg_.states[4].sid.sat, 217) - << "incorrect value for last_msg_.states[4].sid.sat, expected 217, is " - << last_msg_.states[4].sid.sat; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 37.4354667664 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 37.4354667664, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].sid.code, 0) - << "incorrect value for last_msg_.states[5].sid.code, expected 0, is " - << last_msg_.states[5].sid.code; - EXPECT_EQ(last_msg_.states[5].sid.reserved, 0) - << "incorrect value for last_msg_.states[5].sid.reserved, expected 0, is " - << last_msg_.states[5].sid.reserved; - EXPECT_EQ(last_msg_.states[5].sid.sat, 218) - << "incorrect value for last_msg_.states[5].sid.sat, expected 218, is " - << last_msg_.states[5].sid.sat; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 38.4229621887 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 38.4229621887, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].sid.code, 0) - << "incorrect value for last_msg_.states[6].sid.code, expected 0, is " - << last_msg_.states[6].sid.code; - EXPECT_EQ(last_msg_.states[6].sid.reserved, 0) - << "incorrect value for last_msg_.states[6].sid.reserved, expected 0, is " - << last_msg_.states[6].sid.reserved; - EXPECT_EQ(last_msg_.states[6].sid.sat, 220) - << "incorrect value for last_msg_.states[6].sid.sat, expected 220, is " - << last_msg_.states[6].sid.sat; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 38.9152030945 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 38.9152030945, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].sid.code, 0) - << "incorrect value for last_msg_.states[7].sid.code, expected 0, is " - << last_msg_.states[7].sid.code; - EXPECT_EQ(last_msg_.states[7].sid.reserved, 0) - << "incorrect value for last_msg_.states[7].sid.reserved, expected 0, is " - << last_msg_.states[7].sid.reserved; - EXPECT_EQ(last_msg_.states[7].sid.sat, 222) - << "incorrect value for last_msg_.states[7].sid.sat, expected 222, is " - << last_msg_.states[7].sid.sat; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 42.622592926 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 42.622592926, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].sid.code, 0) - << "incorrect value for last_msg_.states[8].sid.code, expected 0, is " - << last_msg_.states[8].sid.code; - EXPECT_EQ(last_msg_.states[8].sid.reserved, 0) - << "incorrect value for last_msg_.states[8].sid.reserved, expected 0, is " - << last_msg_.states[8].sid.reserved; - EXPECT_EQ(last_msg_.states[8].sid.sat, 225) - << "incorrect value for last_msg_.states[8].sid.sat, expected 225, is " - << last_msg_.states[8].sid.sat; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].sid.code, 0) - << "incorrect value for last_msg_.states[9].sid.code, expected 0, is " - << last_msg_.states[9].sid.code; - EXPECT_EQ(last_msg_.states[9].sid.reserved, 0) - << "incorrect value for last_msg_.states[9].sid.reserved, expected 0, is " - << last_msg_.states[9].sid.reserved; - EXPECT_EQ(last_msg_.states[9].sid.sat, 0) - << "incorrect value for last_msg_.states[9].sid.sat, expected 0, is " - << last_msg_.states[9].sid.sat; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].sid.code, 0) - << "incorrect value for last_msg_.states[10].sid.code, expected 0, is " - << last_msg_.states[10].sid.code; - EXPECT_EQ(last_msg_.states[10].sid.reserved, 0) - << "incorrect value for last_msg_.states[10].sid.reserved, expected 0, " - "is " - << last_msg_.states[10].sid.reserved; - EXPECT_EQ(last_msg_.states[10].sid.sat, 0) - << "incorrect value for last_msg_.states[10].sid.sat, expected 0, is " - << last_msg_.states[10].sid.sat; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgTrackingState1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingState1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + ~CHandler() { sbp_remove_callback(state_, &node_); } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState1, Test) { - uint8_t encoded_frame[] = { - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 250, 249, 27, - 66, 1, 203, 0, 0, 0, 40, 143, 11, 66, 1, 208, 0, 0, - 0, 190, 200, 21, 66, 1, 212, 0, 0, 0, 251, 233, 26, 66, - 1, 217, 0, 0, 0, 209, 238, 39, 66, 1, 218, 0, 0, 0, - 162, 219, 21, 66, 1, 220, 0, 0, 0, 162, 197, 25, 66, 1, - 222, 0, 0, 0, 14, 35, 28, 66, 1, 225, 0, 0, 0, 9, - 153, 43, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, - 0, 0, 0, 0, 0, 128, 191, 20, 31, + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; }; - sbp_msg_tracking_state_dep_b_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 38.994117736816406; - test_msg.states[0].sid.code = 0; - test_msg.states[0].sid.reserved = 0; - test_msg.states[0].sid.sat = 202; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 34.889801025390625; - test_msg.states[1].sid.code = 0; - test_msg.states[1].sid.reserved = 0; - test_msg.states[1].sid.sat = 203; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 37.44603729248047; - test_msg.states[2].sid.code = 0; - test_msg.states[2].sid.reserved = 0; - test_msg.states[2].sid.sat = 208; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 38.72849655151367; - test_msg.states[3].sid.code = 0; - test_msg.states[3].sid.reserved = 0; - test_msg.states[3].sid.sat = 212; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 41.983219146728516; - test_msg.states[4].sid.code = 0; - test_msg.states[4].sid.reserved = 0; - test_msg.states[4].sid.sat = 217; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 37.46448516845703; - test_msg.states[5].sid.code = 0; - test_msg.states[5].sid.reserved = 0; - test_msg.states[5].sid.sat = 218; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 38.44300079345703; - test_msg.states[6].sid.code = 0; - test_msg.states[6].sid.reserved = 0; - test_msg.states[6].sid.sat = 220; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 39.03423309326172; - test_msg.states[7].sid.code = 0; - test_msg.states[7].sid.reserved = 0; - test_msg.states[7].sid.sat = 222; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 42.89944839477539; - test_msg.states[8].sid.code = 0; - test_msg.states[8].sid.reserved = 0; - test_msg.states[8].sid.sat = 225; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].sid.code = 0; - test_msg.states[9].sid.reserved = 0; - test_msg.states[9].sid.sat = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].sid.code = 0; - test_msg.states[10].sid.reserved = 0; - test_msg.states[10].sid.sat = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 38.9941177368 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 38.9941177368, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].sid.code, 0) - << "incorrect value for last_msg_.states[0].sid.code, expected 0, is " - << last_msg_.states[0].sid.code; - EXPECT_EQ(last_msg_.states[0].sid.reserved, 0) - << "incorrect value for last_msg_.states[0].sid.reserved, expected 0, is " - << last_msg_.states[0].sid.reserved; - EXPECT_EQ(last_msg_.states[0].sid.sat, 202) - << "incorrect value for last_msg_.states[0].sid.sat, expected 202, is " - << last_msg_.states[0].sid.sat; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 34.8898010254 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 34.8898010254, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].sid.code, 0) - << "incorrect value for last_msg_.states[1].sid.code, expected 0, is " - << last_msg_.states[1].sid.code; - EXPECT_EQ(last_msg_.states[1].sid.reserved, 0) - << "incorrect value for last_msg_.states[1].sid.reserved, expected 0, is " - << last_msg_.states[1].sid.reserved; - EXPECT_EQ(last_msg_.states[1].sid.sat, 203) - << "incorrect value for last_msg_.states[1].sid.sat, expected 203, is " - << last_msg_.states[1].sid.sat; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 37.4460372925 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 37.4460372925, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].sid.code, 0) - << "incorrect value for last_msg_.states[2].sid.code, expected 0, is " - << last_msg_.states[2].sid.code; - EXPECT_EQ(last_msg_.states[2].sid.reserved, 0) - << "incorrect value for last_msg_.states[2].sid.reserved, expected 0, is " - << last_msg_.states[2].sid.reserved; - EXPECT_EQ(last_msg_.states[2].sid.sat, 208) - << "incorrect value for last_msg_.states[2].sid.sat, expected 208, is " - << last_msg_.states[2].sid.sat; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 38.7284965515 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 38.7284965515, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].sid.code, 0) - << "incorrect value for last_msg_.states[3].sid.code, expected 0, is " - << last_msg_.states[3].sid.code; - EXPECT_EQ(last_msg_.states[3].sid.reserved, 0) - << "incorrect value for last_msg_.states[3].sid.reserved, expected 0, is " - << last_msg_.states[3].sid.reserved; - EXPECT_EQ(last_msg_.states[3].sid.sat, 212) - << "incorrect value for last_msg_.states[3].sid.sat, expected 212, is " - << last_msg_.states[3].sid.sat; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 41.9832191467 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 41.9832191467, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].sid.code, 0) - << "incorrect value for last_msg_.states[4].sid.code, expected 0, is " - << last_msg_.states[4].sid.code; - EXPECT_EQ(last_msg_.states[4].sid.reserved, 0) - << "incorrect value for last_msg_.states[4].sid.reserved, expected 0, is " - << last_msg_.states[4].sid.reserved; - EXPECT_EQ(last_msg_.states[4].sid.sat, 217) - << "incorrect value for last_msg_.states[4].sid.sat, expected 217, is " - << last_msg_.states[4].sid.sat; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 37.4644851685 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 37.4644851685, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].sid.code, 0) - << "incorrect value for last_msg_.states[5].sid.code, expected 0, is " - << last_msg_.states[5].sid.code; - EXPECT_EQ(last_msg_.states[5].sid.reserved, 0) - << "incorrect value for last_msg_.states[5].sid.reserved, expected 0, is " - << last_msg_.states[5].sid.reserved; - EXPECT_EQ(last_msg_.states[5].sid.sat, 218) - << "incorrect value for last_msg_.states[5].sid.sat, expected 218, is " - << last_msg_.states[5].sid.sat; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 38.4430007935 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 38.4430007935, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].sid.code, 0) - << "incorrect value for last_msg_.states[6].sid.code, expected 0, is " - << last_msg_.states[6].sid.code; - EXPECT_EQ(last_msg_.states[6].sid.reserved, 0) - << "incorrect value for last_msg_.states[6].sid.reserved, expected 0, is " - << last_msg_.states[6].sid.reserved; - EXPECT_EQ(last_msg_.states[6].sid.sat, 220) - << "incorrect value for last_msg_.states[6].sid.sat, expected 220, is " - << last_msg_.states[6].sid.sat; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 39.0342330933 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 39.0342330933, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].sid.code, 0) - << "incorrect value for last_msg_.states[7].sid.code, expected 0, is " - << last_msg_.states[7].sid.code; - EXPECT_EQ(last_msg_.states[7].sid.reserved, 0) - << "incorrect value for last_msg_.states[7].sid.reserved, expected 0, is " - << last_msg_.states[7].sid.reserved; - EXPECT_EQ(last_msg_.states[7].sid.sat, 222) - << "incorrect value for last_msg_.states[7].sid.sat, expected 222, is " - << last_msg_.states[7].sid.sat; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 42.8994483948 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 42.8994483948, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].sid.code, 0) - << "incorrect value for last_msg_.states[8].sid.code, expected 0, is " - << last_msg_.states[8].sid.code; - EXPECT_EQ(last_msg_.states[8].sid.reserved, 0) - << "incorrect value for last_msg_.states[8].sid.reserved, expected 0, is " - << last_msg_.states[8].sid.reserved; - EXPECT_EQ(last_msg_.states[8].sid.sat, 225) - << "incorrect value for last_msg_.states[8].sid.sat, expected 225, is " - << last_msg_.states[8].sid.sat; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].sid.code, 0) - << "incorrect value for last_msg_.states[9].sid.code, expected 0, is " - << last_msg_.states[9].sid.code; - EXPECT_EQ(last_msg_.states[9].sid.reserved, 0) - << "incorrect value for last_msg_.states[9].sid.reserved, expected 0, is " - << last_msg_.states[9].sid.reserved; - EXPECT_EQ(last_msg_.states[9].sid.sat, 0) - << "incorrect value for last_msg_.states[9].sid.sat, expected 0, is " - << last_msg_.states[9].sid.sat; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].sid.code, 0) - << "incorrect value for last_msg_.states[10].sid.code, expected 0, is " - << last_msg_.states[10].sid.code; - EXPECT_EQ(last_msg_.states[10].sid.reserved, 0) - << "incorrect value for last_msg_.states[10].sid.reserved, expected 0, " - "is " - << last_msg_.states[10].sid.reserved; - EXPECT_EQ(last_msg_.states[10].sid.sat, 0) - << "incorrect value for last_msg_.states[10].sid.sat, expected 0, is " - << last_msg_.states[10].sid.sat; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgTrackingState2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingState2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState2, Test) { - uint8_t encoded_frame[] = { - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 123, 209, 27, - 66, 1, 203, 0, 0, 0, 214, 64, 15, 66, 1, 208, 0, 0, - 0, 56, 55, 22, 66, 1, 212, 0, 0, 0, 91, 142, 27, 66, - 1, 217, 0, 0, 0, 253, 154, 41, 66, 1, 218, 0, 0, 0, - 128, 142, 22, 66, 1, 220, 0, 0, 0, 17, 174, 23, 66, 1, - 222, 0, 0, 0, 155, 2, 29, 66, 1, 225, 0, 0, 0, 162, - 100, 42, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, - 0, 0, 0, 0, 0, 128, 191, 233, 71, + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } }; - sbp_msg_tracking_state_dep_b_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 38.95457077026367; - test_msg.states[0].sid.code = 0; - test_msg.states[0].sid.reserved = 0; - test_msg.states[0].sid.sat = 202; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 35.813316345214844; - test_msg.states[1].sid.code = 0; - test_msg.states[1].sid.reserved = 0; - test_msg.states[1].sid.sat = 203; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 37.553924560546875; - test_msg.states[2].sid.code = 0; - test_msg.states[2].sid.reserved = 0; - test_msg.states[2].sid.sat = 208; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 38.88901901245117; - test_msg.states[3].sid.code = 0; - test_msg.states[3].sid.reserved = 0; - test_msg.states[3].sid.sat = 212; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 42.4013557434082; - test_msg.states[4].sid.code = 0; - test_msg.states[4].sid.reserved = 0; - test_msg.states[4].sid.sat = 217; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 37.63916015625; - test_msg.states[5].sid.code = 0; - test_msg.states[5].sid.reserved = 0; - test_msg.states[5].sid.sat = 218; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 37.919986724853516; - test_msg.states[6].sid.code = 0; - test_msg.states[6].sid.reserved = 0; - test_msg.states[6].sid.sat = 220; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 39.25254440307617; - test_msg.states[7].sid.code = 0; - test_msg.states[7].sid.reserved = 0; - test_msg.states[7].sid.sat = 222; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 42.59827423095703; - test_msg.states[8].sid.code = 0; - test_msg.states[8].sid.reserved = 0; - test_msg.states[8].sid.sat = 225; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].sid.code = 0; - test_msg.states[9].sid.reserved = 0; - test_msg.states[9].sid.sat = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].sid.code = 0; - test_msg.states[10].sid.reserved = 0; - test_msg.states[10].sid.sat = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 38.9545707703 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 38.9545707703, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].sid.code, 0) - << "incorrect value for last_msg_.states[0].sid.code, expected 0, is " - << last_msg_.states[0].sid.code; - EXPECT_EQ(last_msg_.states[0].sid.reserved, 0) - << "incorrect value for last_msg_.states[0].sid.reserved, expected 0, is " - << last_msg_.states[0].sid.reserved; - EXPECT_EQ(last_msg_.states[0].sid.sat, 202) - << "incorrect value for last_msg_.states[0].sid.sat, expected 202, is " - << last_msg_.states[0].sid.sat; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 35.8133163452 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 35.8133163452, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].sid.code, 0) - << "incorrect value for last_msg_.states[1].sid.code, expected 0, is " - << last_msg_.states[1].sid.code; - EXPECT_EQ(last_msg_.states[1].sid.reserved, 0) - << "incorrect value for last_msg_.states[1].sid.reserved, expected 0, is " - << last_msg_.states[1].sid.reserved; - EXPECT_EQ(last_msg_.states[1].sid.sat, 203) - << "incorrect value for last_msg_.states[1].sid.sat, expected 203, is " - << last_msg_.states[1].sid.sat; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 37.5539245605 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 37.5539245605, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].sid.code, 0) - << "incorrect value for last_msg_.states[2].sid.code, expected 0, is " - << last_msg_.states[2].sid.code; - EXPECT_EQ(last_msg_.states[2].sid.reserved, 0) - << "incorrect value for last_msg_.states[2].sid.reserved, expected 0, is " - << last_msg_.states[2].sid.reserved; - EXPECT_EQ(last_msg_.states[2].sid.sat, 208) - << "incorrect value for last_msg_.states[2].sid.sat, expected 208, is " - << last_msg_.states[2].sid.sat; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 38.8890190125 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 38.8890190125, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].sid.code, 0) - << "incorrect value for last_msg_.states[3].sid.code, expected 0, is " - << last_msg_.states[3].sid.code; - EXPECT_EQ(last_msg_.states[3].sid.reserved, 0) - << "incorrect value for last_msg_.states[3].sid.reserved, expected 0, is " - << last_msg_.states[3].sid.reserved; - EXPECT_EQ(last_msg_.states[3].sid.sat, 212) - << "incorrect value for last_msg_.states[3].sid.sat, expected 212, is " - << last_msg_.states[3].sid.sat; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 42.4013557434 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 42.4013557434, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].sid.code, 0) - << "incorrect value for last_msg_.states[4].sid.code, expected 0, is " - << last_msg_.states[4].sid.code; - EXPECT_EQ(last_msg_.states[4].sid.reserved, 0) - << "incorrect value for last_msg_.states[4].sid.reserved, expected 0, is " - << last_msg_.states[4].sid.reserved; - EXPECT_EQ(last_msg_.states[4].sid.sat, 217) - << "incorrect value for last_msg_.states[4].sid.sat, expected 217, is " - << last_msg_.states[4].sid.sat; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 37.6391601562 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 37.6391601562, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].sid.code, 0) - << "incorrect value for last_msg_.states[5].sid.code, expected 0, is " - << last_msg_.states[5].sid.code; - EXPECT_EQ(last_msg_.states[5].sid.reserved, 0) - << "incorrect value for last_msg_.states[5].sid.reserved, expected 0, is " - << last_msg_.states[5].sid.reserved; - EXPECT_EQ(last_msg_.states[5].sid.sat, 218) - << "incorrect value for last_msg_.states[5].sid.sat, expected 218, is " - << last_msg_.states[5].sid.sat; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 37.9199867249 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 37.9199867249, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].sid.code, 0) - << "incorrect value for last_msg_.states[6].sid.code, expected 0, is " - << last_msg_.states[6].sid.code; - EXPECT_EQ(last_msg_.states[6].sid.reserved, 0) - << "incorrect value for last_msg_.states[6].sid.reserved, expected 0, is " - << last_msg_.states[6].sid.reserved; - EXPECT_EQ(last_msg_.states[6].sid.sat, 220) - << "incorrect value for last_msg_.states[6].sid.sat, expected 220, is " - << last_msg_.states[6].sid.sat; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 39.2525444031 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 39.2525444031, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].sid.code, 0) - << "incorrect value for last_msg_.states[7].sid.code, expected 0, is " - << last_msg_.states[7].sid.code; - EXPECT_EQ(last_msg_.states[7].sid.reserved, 0) - << "incorrect value for last_msg_.states[7].sid.reserved, expected 0, is " - << last_msg_.states[7].sid.reserved; - EXPECT_EQ(last_msg_.states[7].sid.sat, 222) - << "incorrect value for last_msg_.states[7].sid.sat, expected 222, is " - << last_msg_.states[7].sid.sat; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 42.598274231 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 42.598274231, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].sid.code, 0) - << "incorrect value for last_msg_.states[8].sid.code, expected 0, is " - << last_msg_.states[8].sid.code; - EXPECT_EQ(last_msg_.states[8].sid.reserved, 0) - << "incorrect value for last_msg_.states[8].sid.reserved, expected 0, is " - << last_msg_.states[8].sid.reserved; - EXPECT_EQ(last_msg_.states[8].sid.sat, 225) - << "incorrect value for last_msg_.states[8].sid.sat, expected 225, is " - << last_msg_.states[8].sid.sat; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].sid.code, 0) - << "incorrect value for last_msg_.states[9].sid.code, expected 0, is " - << last_msg_.states[9].sid.code; - EXPECT_EQ(last_msg_.states[9].sid.reserved, 0) - << "incorrect value for last_msg_.states[9].sid.reserved, expected 0, is " - << last_msg_.states[9].sid.reserved; - EXPECT_EQ(last_msg_.states[9].sid.sat, 0) - << "incorrect value for last_msg_.states[9].sid.sat, expected 0, is " - << last_msg_.states[9].sid.sat; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].sid.code, 0) - << "incorrect value for last_msg_.states[10].sid.code, expected 0, is " - << last_msg_.states[10].sid.code; - EXPECT_EQ(last_msg_.states[10].sid.reserved, 0) - << "incorrect value for last_msg_.states[10].sid.reserved, expected 0, " - "is " - << last_msg_.states[10].sid.reserved; - EXPECT_EQ(last_msg_.states[10].sid.sat, 0) - << "incorrect value for last_msg_.states[10].sid.sat, expected 0, is " - << last_msg_.states[10].sid.sat; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgTrackingState3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingState3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 55286; + info.preamble = 0x55; + info.crc = 0x2f7e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 99; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState3, Test) { - uint8_t encoded_frame[] = { - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 120, 122, 29, - 66, 1, 203, 0, 0, 0, 66, 22, 18, 66, 1, 208, 0, 0, - 0, 153, 163, 24, 66, 1, 212, 0, 0, 0, 178, 204, 28, 66, - 1, 217, 0, 0, 0, 220, 59, 38, 66, 1, 218, 0, 0, 0, - 161, 27, 20, 66, 1, 220, 0, 0, 0, 125, 107, 24, 66, 1, - 222, 0, 0, 0, 242, 46, 28, 66, 1, 225, 0, 0, 0, 231, - 130, 41, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, - 0, 0, 0, 0, 0, 128, 191, 73, 193, - }; + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); - sbp_msg_tracking_state_dep_b_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 39.369598388671875; - test_msg.states[0].sid.code = 0; - test_msg.states[0].sid.reserved = 0; - test_msg.states[0].sid.sat = 202; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 36.52173614501953; - test_msg.states[1].sid.code = 0; - test_msg.states[1].sid.reserved = 0; - test_msg.states[1].sid.sat = 203; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 38.15976333618164; - test_msg.states[2].sid.code = 0; - test_msg.states[2].sid.reserved = 0; - test_msg.states[2].sid.sat = 208; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 39.19989776611328; - test_msg.states[3].sid.code = 0; - test_msg.states[3].sid.reserved = 0; - test_msg.states[3].sid.sat = 212; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 41.55845642089844; - test_msg.states[4].sid.code = 0; - test_msg.states[4].sid.reserved = 0; - test_msg.states[4].sid.sat = 217; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 37.026981353759766; - test_msg.states[5].sid.code = 0; - test_msg.states[5].sid.reserved = 0; - test_msg.states[5].sid.sat = 218; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 38.1049690246582; - test_msg.states[6].sid.code = 0; - test_msg.states[6].sid.reserved = 0; - test_msg.states[6].sid.sat = 220; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 39.04584503173828; - test_msg.states[7].sid.code = 0; - test_msg.states[7].sid.reserved = 0; - test_msg.states[7].sid.sat = 222; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 42.37783432006836; - test_msg.states[8].sid.code = 0; - test_msg.states[8].sid.reserved = 0; - test_msg.states[8].sid.sat = 225; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].sid.code = 0; - test_msg.states[9].sid.reserved = 0; - test_msg.states[9].sid.sat = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].sid.code = 0; - test_msg.states[10].sid.reserved = 0; - test_msg.states[10].sid.sat = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 39.3695983887 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 39.3695983887, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].sid.code, 0) - << "incorrect value for last_msg_.states[0].sid.code, expected 0, is " - << last_msg_.states[0].sid.code; - EXPECT_EQ(last_msg_.states[0].sid.reserved, 0) - << "incorrect value for last_msg_.states[0].sid.reserved, expected 0, is " - << last_msg_.states[0].sid.reserved; - EXPECT_EQ(last_msg_.states[0].sid.sat, 202) - << "incorrect value for last_msg_.states[0].sid.sat, expected 202, is " - << last_msg_.states[0].sid.sat; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 36.521736145 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 36.521736145, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].sid.code, 0) - << "incorrect value for last_msg_.states[1].sid.code, expected 0, is " - << last_msg_.states[1].sid.code; - EXPECT_EQ(last_msg_.states[1].sid.reserved, 0) - << "incorrect value for last_msg_.states[1].sid.reserved, expected 0, is " - << last_msg_.states[1].sid.reserved; - EXPECT_EQ(last_msg_.states[1].sid.sat, 203) - << "incorrect value for last_msg_.states[1].sid.sat, expected 203, is " - << last_msg_.states[1].sid.sat; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 38.1597633362 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 38.1597633362, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].sid.code, 0) - << "incorrect value for last_msg_.states[2].sid.code, expected 0, is " - << last_msg_.states[2].sid.code; - EXPECT_EQ(last_msg_.states[2].sid.reserved, 0) - << "incorrect value for last_msg_.states[2].sid.reserved, expected 0, is " - << last_msg_.states[2].sid.reserved; - EXPECT_EQ(last_msg_.states[2].sid.sat, 208) - << "incorrect value for last_msg_.states[2].sid.sat, expected 208, is " - << last_msg_.states[2].sid.sat; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 39.1998977661 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 39.1998977661, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].sid.code, 0) - << "incorrect value for last_msg_.states[3].sid.code, expected 0, is " - << last_msg_.states[3].sid.code; - EXPECT_EQ(last_msg_.states[3].sid.reserved, 0) - << "incorrect value for last_msg_.states[3].sid.reserved, expected 0, is " - << last_msg_.states[3].sid.reserved; - EXPECT_EQ(last_msg_.states[3].sid.sat, 212) - << "incorrect value for last_msg_.states[3].sid.sat, expected 212, is " - << last_msg_.states[3].sid.sat; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 41.5584564209 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 41.5584564209, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].sid.code, 0) - << "incorrect value for last_msg_.states[4].sid.code, expected 0, is " - << last_msg_.states[4].sid.code; - EXPECT_EQ(last_msg_.states[4].sid.reserved, 0) - << "incorrect value for last_msg_.states[4].sid.reserved, expected 0, is " - << last_msg_.states[4].sid.reserved; - EXPECT_EQ(last_msg_.states[4].sid.sat, 217) - << "incorrect value for last_msg_.states[4].sid.sat, expected 217, is " - << last_msg_.states[4].sid.sat; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 37.0269813538 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 37.0269813538, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].sid.code, 0) - << "incorrect value for last_msg_.states[5].sid.code, expected 0, is " - << last_msg_.states[5].sid.code; - EXPECT_EQ(last_msg_.states[5].sid.reserved, 0) - << "incorrect value for last_msg_.states[5].sid.reserved, expected 0, is " - << last_msg_.states[5].sid.reserved; - EXPECT_EQ(last_msg_.states[5].sid.sat, 218) - << "incorrect value for last_msg_.states[5].sid.sat, expected 218, is " - << last_msg_.states[5].sid.sat; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 38.1049690247 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 38.1049690247, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].sid.code, 0) - << "incorrect value for last_msg_.states[6].sid.code, expected 0, is " - << last_msg_.states[6].sid.code; - EXPECT_EQ(last_msg_.states[6].sid.reserved, 0) - << "incorrect value for last_msg_.states[6].sid.reserved, expected 0, is " - << last_msg_.states[6].sid.reserved; - EXPECT_EQ(last_msg_.states[6].sid.sat, 220) - << "incorrect value for last_msg_.states[6].sid.sat, expected 220, is " - << last_msg_.states[6].sid.sat; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 39.0458450317 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 39.0458450317, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].sid.code, 0) - << "incorrect value for last_msg_.states[7].sid.code, expected 0, is " - << last_msg_.states[7].sid.code; - EXPECT_EQ(last_msg_.states[7].sid.reserved, 0) - << "incorrect value for last_msg_.states[7].sid.reserved, expected 0, is " - << last_msg_.states[7].sid.reserved; - EXPECT_EQ(last_msg_.states[7].sid.sat, 222) - << "incorrect value for last_msg_.states[7].sid.sat, expected 222, is " - << last_msg_.states[7].sid.sat; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 42.3778343201 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 42.3778343201, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].sid.code, 0) - << "incorrect value for last_msg_.states[8].sid.code, expected 0, is " - << last_msg_.states[8].sid.code; - EXPECT_EQ(last_msg_.states[8].sid.reserved, 0) - << "incorrect value for last_msg_.states[8].sid.reserved, expected 0, is " - << last_msg_.states[8].sid.reserved; - EXPECT_EQ(last_msg_.states[8].sid.sat, 225) - << "incorrect value for last_msg_.states[8].sid.sat, expected 225, is " - << last_msg_.states[8].sid.sat; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].sid.code, 0) - << "incorrect value for last_msg_.states[9].sid.code, expected 0, is " - << last_msg_.states[9].sid.code; - EXPECT_EQ(last_msg_.states[9].sid.reserved, 0) - << "incorrect value for last_msg_.states[9].sid.reserved, expected 0, is " - << last_msg_.states[9].sid.reserved; - EXPECT_EQ(last_msg_.states[9].sid.sat, 0) - << "incorrect value for last_msg_.states[9].sid.sat, expected 0, is " - << last_msg_.states[9].sid.sat; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].sid.code, 0) - << "incorrect value for last_msg_.states[10].sid.code, expected 0, is " - << last_msg_.states[10].sid.code; - EXPECT_EQ(last_msg_.states[10].sid.reserved, 0) - << "incorrect value for last_msg_.states[10].sid.reserved, expected 0, " - "is " - << last_msg_.states[10].sid.reserved; - EXPECT_EQ(last_msg_.states[10].sid.sat, 0) - << "incorrect value for last_msg_.states[10].sid.sat, expected 0, is " - << last_msg_.states[10].sid.sat; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgTrackingState4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingState4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_b_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_b_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[99 + 8] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 103, 208, 30, 66, 1, 203, 0, 0, 0, 117, 24, 18, 66, 1, 208, 0, 0, 0, 200, 173, 20, 66, 1, 212, 0, 0, 0, 137, 68, 27, 66, @@ -1393,264 +7999,780 @@ TEST_F(Test_auto_check_sbp_tracking_MsgTrackingState4, Test) { 21, 41, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 126, 47, }; + uint8_t encoded_payload_[99] = { + 1, 202, 0, 0, 0, 103, 208, 30, 66, 1, 203, 0, 0, 0, 117, 24, 18, 66, + 1, 208, 0, 0, 0, 200, 173, 20, 66, 1, 212, 0, 0, 0, 137, 68, 27, 66, + 1, 217, 0, 0, 0, 243, 51, 40, 66, 1, 218, 0, 0, 0, 225, 58, 23, 66, + 1, 220, 0, 0, 0, 132, 221, 22, 66, 1, 222, 0, 0, 0, 157, 29, 26, 66, + 1, 225, 0, 0, 0, 133, 21, 41, 66, 0, 0, 0, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + + for (uint8_t i = 0; i < 99; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} - sbp_msg_tracking_state_dep_b_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 39.70351791381836; - test_msg.states[0].sid.code = 0; - test_msg.states[0].sid.reserved = 0; - test_msg.states[0].sid.sat = 202; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 36.52388381958008; - test_msg.states[1].sid.code = 0; - test_msg.states[1].sid.reserved = 0; - test_msg.states[1].sid.sat = 203; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 37.169708251953125; - test_msg.states[2].sid.code = 0; - test_msg.states[2].sid.reserved = 0; - test_msg.states[2].sid.sat = 208; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 38.81692886352539; - test_msg.states[3].sid.code = 0; - test_msg.states[3].sid.reserved = 0; - test_msg.states[3].sid.sat = 212; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 42.05073165893555; - test_msg.states[4].sid.code = 0; - test_msg.states[4].sid.reserved = 0; - test_msg.states[4].sid.sat = 217; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 37.807498931884766; - test_msg.states[5].sid.code = 0; - test_msg.states[5].sid.reserved = 0; - test_msg.states[5].sid.sat = 218; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 37.71632385253906; - test_msg.states[6].sid.code = 0; - test_msg.states[6].sid.reserved = 0; - test_msg.states[6].sid.sat = 220; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 38.5289192199707; - test_msg.states[7].sid.code = 0; - test_msg.states[7].sid.reserved = 0; - test_msg.states[7].sid.sat = 222; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 42.27101516723633; - test_msg.states[8].sid.code = 0; - test_msg.states[8].sid.reserved = 0; - test_msg.states[8].sid.sat = 225; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].sid.code = 0; - test_msg.states[9].sid.reserved = 0; - test_msg.states[9].sid.sat = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].sid.code = 0; - test_msg.states[10].sid.reserved = 0; - test_msg.states[10].sid.sat = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(55286, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 55286); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 39.7035179138 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 39.7035179138, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].sid.code, 0) - << "incorrect value for last_msg_.states[0].sid.code, expected 0, is " - << last_msg_.states[0].sid.code; - EXPECT_EQ(last_msg_.states[0].sid.reserved, 0) - << "incorrect value for last_msg_.states[0].sid.reserved, expected 0, is " - << last_msg_.states[0].sid.reserved; - EXPECT_EQ(last_msg_.states[0].sid.sat, 202) - << "incorrect value for last_msg_.states[0].sid.sat, expected 202, is " - << last_msg_.states[0].sid.sat; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 36.5238838196 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 36.5238838196, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].sid.code, 0) - << "incorrect value for last_msg_.states[1].sid.code, expected 0, is " - << last_msg_.states[1].sid.code; - EXPECT_EQ(last_msg_.states[1].sid.reserved, 0) - << "incorrect value for last_msg_.states[1].sid.reserved, expected 0, is " - << last_msg_.states[1].sid.reserved; - EXPECT_EQ(last_msg_.states[1].sid.sat, 203) - << "incorrect value for last_msg_.states[1].sid.sat, expected 203, is " - << last_msg_.states[1].sid.sat; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 37.169708252 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 37.169708252, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].sid.code, 0) - << "incorrect value for last_msg_.states[2].sid.code, expected 0, is " - << last_msg_.states[2].sid.code; - EXPECT_EQ(last_msg_.states[2].sid.reserved, 0) - << "incorrect value for last_msg_.states[2].sid.reserved, expected 0, is " - << last_msg_.states[2].sid.reserved; - EXPECT_EQ(last_msg_.states[2].sid.sat, 208) - << "incorrect value for last_msg_.states[2].sid.sat, expected 208, is " - << last_msg_.states[2].sid.sat; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 38.8169288635 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 38.8169288635, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].sid.code, 0) - << "incorrect value for last_msg_.states[3].sid.code, expected 0, is " - << last_msg_.states[3].sid.code; - EXPECT_EQ(last_msg_.states[3].sid.reserved, 0) - << "incorrect value for last_msg_.states[3].sid.reserved, expected 0, is " - << last_msg_.states[3].sid.reserved; - EXPECT_EQ(last_msg_.states[3].sid.sat, 212) - << "incorrect value for last_msg_.states[3].sid.sat, expected 212, is " - << last_msg_.states[3].sid.sat; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 42.0507316589 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 42.0507316589, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].sid.code, 0) - << "incorrect value for last_msg_.states[4].sid.code, expected 0, is " - << last_msg_.states[4].sid.code; - EXPECT_EQ(last_msg_.states[4].sid.reserved, 0) - << "incorrect value for last_msg_.states[4].sid.reserved, expected 0, is " - << last_msg_.states[4].sid.reserved; - EXPECT_EQ(last_msg_.states[4].sid.sat, 217) - << "incorrect value for last_msg_.states[4].sid.sat, expected 217, is " - << last_msg_.states[4].sid.sat; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 37.8074989319 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 37.8074989319, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].sid.code, 0) - << "incorrect value for last_msg_.states[5].sid.code, expected 0, is " - << last_msg_.states[5].sid.code; - EXPECT_EQ(last_msg_.states[5].sid.reserved, 0) - << "incorrect value for last_msg_.states[5].sid.reserved, expected 0, is " - << last_msg_.states[5].sid.reserved; - EXPECT_EQ(last_msg_.states[5].sid.sat, 218) - << "incorrect value for last_msg_.states[5].sid.sat, expected 218, is " - << last_msg_.states[5].sid.sat; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 37.7163238525 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 37.7163238525, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].sid.code, 0) - << "incorrect value for last_msg_.states[6].sid.code, expected 0, is " - << last_msg_.states[6].sid.code; - EXPECT_EQ(last_msg_.states[6].sid.reserved, 0) - << "incorrect value for last_msg_.states[6].sid.reserved, expected 0, is " - << last_msg_.states[6].sid.reserved; - EXPECT_EQ(last_msg_.states[6].sid.sat, 220) - << "incorrect value for last_msg_.states[6].sid.sat, expected 220, is " - << last_msg_.states[6].sid.sat; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 38.52891922 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 38.52891922, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].sid.code, 0) - << "incorrect value for last_msg_.states[7].sid.code, expected 0, is " - << last_msg_.states[7].sid.code; - EXPECT_EQ(last_msg_.states[7].sid.reserved, 0) - << "incorrect value for last_msg_.states[7].sid.reserved, expected 0, is " - << last_msg_.states[7].sid.reserved; - EXPECT_EQ(last_msg_.states[7].sid.sat, 222) - << "incorrect value for last_msg_.states[7].sid.sat, expected 222, is " - << last_msg_.states[7].sid.sat; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 42.2710151672 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 42.2710151672, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].sid.code, 0) - << "incorrect value for last_msg_.states[8].sid.code, expected 0, is " - << last_msg_.states[8].sid.code; - EXPECT_EQ(last_msg_.states[8].sid.reserved, 0) - << "incorrect value for last_msg_.states[8].sid.reserved, expected 0, is " - << last_msg_.states[8].sid.reserved; - EXPECT_EQ(last_msg_.states[8].sid.sat, 225) - << "incorrect value for last_msg_.states[8].sid.sat, expected 225, is " - << last_msg_.states[8].sid.sat; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].sid.code, 0) - << "incorrect value for last_msg_.states[9].sid.code, expected 0, is " - << last_msg_.states[9].sid.code; - EXPECT_EQ(last_msg_.states[9].sid.reserved, 0) - << "incorrect value for last_msg_.states[9].sid.reserved, expected 0, is " - << last_msg_.states[9].sid.reserved; - EXPECT_EQ(last_msg_.states[9].sid.sat, 0) - << "incorrect value for last_msg_.states[9].sid.sat, expected 0, is " - << last_msg_.states[9].sid.sat; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].sid.code, 0) - << "incorrect value for last_msg_.states[10].sid.code, expected 0, is " - << last_msg_.states[10].sid.code; - EXPECT_EQ(last_msg_.states[10].sid.reserved, 0) - << "incorrect value for last_msg_.states[10].sid.reserved, expected 0, " - "is " - << last_msg_.states[10].sid.reserved; - EXPECT_EQ(last_msg_.states[10].sid.sat, 0) - << "incorrect value for last_msg_.states[10].sid.sat, expected 0, is " - << last_msg_.states[10].sid.sat; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); } + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[99]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 99); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 99), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 99); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingState5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc new file mode 100644 index 0000000000..f3d01804e8 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc @@ -0,0 +1,1921 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingStateDepB0 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingStateDepB0() { + assign(test_msg_.n_states, 28); + + assign(test_msg_.states[0].cn0, 5856.2001953125); + assign(test_msg_.states[0].sid.code, 63); + assign(test_msg_.states[0].sid.reserved, 68); + assign(test_msg_.states[0].sid.sat, 58295); + assign(test_msg_.states[0].state, 115); + + assign(test_msg_.states[1].cn0, 2612.199951171875); + assign(test_msg_.states[1].sid.code, 43); + assign(test_msg_.states[1].sid.reserved, 222); + assign(test_msg_.states[1].sid.sat, 31151); + assign(test_msg_.states[1].state, 255); + + assign(test_msg_.states[2].cn0, 2925.199951171875); + assign(test_msg_.states[2].sid.code, 53); + assign(test_msg_.states[2].sid.reserved, 20); + assign(test_msg_.states[2].sid.sat, 1520); + assign(test_msg_.states[2].state, 78); + + assign(test_msg_.states[3].cn0, 3198.199951171875); + assign(test_msg_.states[3].sid.code, 66); + assign(test_msg_.states[3].sid.reserved, 155); + assign(test_msg_.states[3].sid.sat, 60802); + assign(test_msg_.states[3].state, 153); + + assign(test_msg_.states[4].cn0, 8623.2001953125); + assign(test_msg_.states[4].sid.code, 161); + assign(test_msg_.states[4].sid.reserved, 190); + assign(test_msg_.states[4].sid.sat, 35058); + assign(test_msg_.states[4].state, 53); + + assign(test_msg_.states[5].cn0, 5915.2001953125); + assign(test_msg_.states[5].sid.code, 142); + assign(test_msg_.states[5].sid.reserved, 149); + assign(test_msg_.states[5].sid.sat, 65405); + assign(test_msg_.states[5].state, 153); + + assign(test_msg_.states[6].cn0, 5412.2001953125); + assign(test_msg_.states[6].sid.code, 31); + assign(test_msg_.states[6].sid.reserved, 76); + assign(test_msg_.states[6].sid.sat, 24422); + assign(test_msg_.states[6].state, 248); + + assign(test_msg_.states[7].cn0, 6428.2001953125); + assign(test_msg_.states[7].sid.code, 27); + assign(test_msg_.states[7].sid.reserved, 12); + assign(test_msg_.states[7].sid.sat, 36211); + assign(test_msg_.states[7].state, 131); + + assign(test_msg_.states[8].cn0, 3104.199951171875); + assign(test_msg_.states[8].sid.code, 39); + assign(test_msg_.states[8].sid.reserved, 23); + assign(test_msg_.states[8].sid.sat, 37676); + assign(test_msg_.states[8].state, 208); + + assign(test_msg_.states[9].cn0, 3686.199951171875); + assign(test_msg_.states[9].sid.code, 49); + assign(test_msg_.states[9].sid.reserved, 203); + assign(test_msg_.states[9].sid.sat, 64415); + assign(test_msg_.states[9].state, 237); + + assign(test_msg_.states[10].cn0, 5967.2001953125); + assign(test_msg_.states[10].sid.code, 128); + assign(test_msg_.states[10].sid.reserved, 206); + assign(test_msg_.states[10].sid.sat, 22486); + assign(test_msg_.states[10].state, 70); + + assign(test_msg_.states[11].cn0, 5423.2001953125); + assign(test_msg_.states[11].sid.code, 218); + assign(test_msg_.states[11].sid.reserved, 19); + assign(test_msg_.states[11].sid.sat, 28622); + assign(test_msg_.states[11].state, 14); + + assign(test_msg_.states[12].cn0, 438.20001220703125); + assign(test_msg_.states[12].sid.code, 54); + assign(test_msg_.states[12].sid.reserved, 2); + assign(test_msg_.states[12].sid.sat, 53602); + assign(test_msg_.states[12].state, 216); + + assign(test_msg_.states[13].cn0, 1862.199951171875); + assign(test_msg_.states[13].sid.code, 7); + assign(test_msg_.states[13].sid.reserved, 34); + assign(test_msg_.states[13].sid.sat, 25477); + assign(test_msg_.states[13].state, 200); + + assign(test_msg_.states[14].cn0, 5462.2001953125); + assign(test_msg_.states[14].sid.code, 135); + assign(test_msg_.states[14].sid.reserved, 46); + assign(test_msg_.states[14].sid.sat, 21803); + assign(test_msg_.states[14].state, 155); + + assign(test_msg_.states[15].cn0, 7454.2001953125); + assign(test_msg_.states[15].sid.code, 171); + assign(test_msg_.states[15].sid.reserved, 201); + assign(test_msg_.states[15].sid.sat, 21251); + assign(test_msg_.states[15].state, 155); + + assign(test_msg_.states[16].cn0, 7134.2001953125); + assign(test_msg_.states[16].sid.code, 16); + assign(test_msg_.states[16].sid.reserved, 19); + assign(test_msg_.states[16].sid.sat, 50475); + assign(test_msg_.states[16].state, 121); + + assign(test_msg_.states[17].cn0, 3111.199951171875); + assign(test_msg_.states[17].sid.code, 63); + assign(test_msg_.states[17].sid.reserved, 176); + assign(test_msg_.states[17].sid.sat, 13813); + assign(test_msg_.states[17].state, 128); + + assign(test_msg_.states[18].cn0, 4297.2001953125); + assign(test_msg_.states[18].sid.code, 153); + assign(test_msg_.states[18].sid.reserved, 51); + assign(test_msg_.states[18].sid.sat, 15636); + assign(test_msg_.states[18].state, 36); + + assign(test_msg_.states[19].cn0, 2649.199951171875); + assign(test_msg_.states[19].sid.code, 140); + assign(test_msg_.states[19].sid.reserved, 22); + assign(test_msg_.states[19].sid.sat, 29778); + assign(test_msg_.states[19].state, 46); + + assign(test_msg_.states[20].cn0, 941.2000122070312); + assign(test_msg_.states[20].sid.code, 96); + assign(test_msg_.states[20].sid.reserved, 143); + assign(test_msg_.states[20].sid.sat, 37443); + assign(test_msg_.states[20].state, 177); + + assign(test_msg_.states[21].cn0, 1539.199951171875); + assign(test_msg_.states[21].sid.code, 201); + assign(test_msg_.states[21].sid.reserved, 251); + assign(test_msg_.states[21].sid.sat, 41011); + assign(test_msg_.states[21].state, 220); + + assign(test_msg_.states[22].cn0, 1443.199951171875); + assign(test_msg_.states[22].sid.code, 161); + assign(test_msg_.states[22].sid.reserved, 220); + assign(test_msg_.states[22].sid.sat, 706); + assign(test_msg_.states[22].state, 168); + + assign(test_msg_.states[23].cn0, 1074.199951171875); + assign(test_msg_.states[23].sid.code, 125); + assign(test_msg_.states[23].sid.reserved, 178); + assign(test_msg_.states[23].sid.sat, 2312); + assign(test_msg_.states[23].state, 69); + + assign(test_msg_.states[24].cn0, 2122.199951171875); + assign(test_msg_.states[24].sid.code, 186); + assign(test_msg_.states[24].sid.reserved, 171); + assign(test_msg_.states[24].sid.sat, 34580); + assign(test_msg_.states[24].state, 185); + + assign(test_msg_.states[25].cn0, 9076.2001953125); + assign(test_msg_.states[25].sid.code, 85); + assign(test_msg_.states[25].sid.reserved, 170); + assign(test_msg_.states[25].sid.sat, 39804); + assign(test_msg_.states[25].state, 18); + + assign(test_msg_.states[26].cn0, 4781.2001953125); + assign(test_msg_.states[26].sid.code, 255); + assign(test_msg_.states[26].sid.reserved, 186); + assign(test_msg_.states[26].sid.sat, 52980); + assign(test_msg_.states[26].state, 57); + + assign(test_msg_.states[27].cn0, 3076.199951171875); + assign(test_msg_.states[27].sid.code, 181); + assign(test_msg_.states[27].sid.reserved, 175); + assign(test_msg_.states[27].sid.sat, 24007); + assign(test_msg_.states[27].state, 165); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_b_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepB, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_b_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepB); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_b, + sizeof(msg->tracking_state_dep_b)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_b_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_b, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepB); + info.sender_id = 61938; + info.preamble = 0x55; + info.crc = 0x1c06; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 252; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_b_t &lesser, + const sbp_msg_tracking_state_dep_b_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_b_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_b_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepB, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_b_t test_msg_{}; + uint8_t encoded_frame_[252 + 8] = { + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, 69, + 255, 175, 121, 43, 222, 51, 67, 35, 69, 78, 240, 5, 53, 20, 51, + 211, 54, 69, 153, 130, 237, 66, 155, 51, 227, 71, 69, 53, 242, 136, + 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, 154, 217, 184, 69, + 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, 115, 141, 27, 12, 154, + 225, 200, 69, 208, 44, 147, 39, 23, 51, 3, 66, 69, 237, 159, 251, + 49, 203, 51, 99, 102, 69, 70, 214, 87, 128, 206, 154, 121, 186, 69, + 14, 206, 111, 218, 19, 154, 121, 169, 69, 216, 98, 209, 54, 2, 154, + 25, 219, 67, 200, 133, 99, 7, 34, 102, 198, 232, 68, 155, 43, 85, + 135, 46, 154, 177, 170, 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, + 121, 43, 197, 16, 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, + 115, 66, 69, 36, 20, 61, 153, 51, 154, 73, 134, 69, 46, 82, 116, + 140, 22, 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, 76, 107, 68, + 220, 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, 135, + 186, 171, 51, 163, 4, 69, 18, 124, 155, 85, 170, 205, 208, 13, 70, + 57, 244, 206, 255, 186, 154, 105, 149, 69, 165, 199, 93, 181, 175, 51, + 67, 64, 69, 6, 28, + }; + uint8_t encoded_payload_[252] = { + 115, 183, 227, 63, 68, 154, 1, 183, 69, 255, 175, 121, 43, 222, 51, + 67, 35, 69, 78, 240, 5, 53, 20, 51, 211, 54, 69, 153, 130, 237, + 66, 155, 51, 227, 71, 69, 53, 242, 136, 161, 190, 205, 188, 6, 70, + 153, 125, 255, 142, 149, 154, 217, 184, 69, 248, 102, 95, 31, 76, 154, + 33, 169, 69, 131, 115, 141, 27, 12, 154, 225, 200, 69, 208, 44, 147, + 39, 23, 51, 3, 66, 69, 237, 159, 251, 49, 203, 51, 99, 102, 69, + 70, 214, 87, 128, 206, 154, 121, 186, 69, 14, 206, 111, 218, 19, 154, + 121, 169, 69, 216, 98, 209, 54, 2, 154, 25, 219, 67, 200, 133, 99, + 7, 34, 102, 198, 232, 68, 155, 43, 85, 135, 46, 154, 177, 170, 69, + 155, 3, 83, 171, 201, 154, 241, 232, 69, 121, 43, 197, 16, 19, 154, + 241, 222, 69, 128, 245, 53, 63, 176, 51, 115, 66, 69, 36, 20, 61, + 153, 51, 154, 73, 134, 69, 46, 82, 116, 140, 22, 51, 147, 37, 69, + 177, 67, 146, 96, 143, 205, 76, 107, 68, 220, 51, 160, 201, 251, 102, + 102, 192, 68, 168, 194, 2, 161, 220, 102, 102, 180, 68, 69, 8, 9, + 125, 178, 102, 70, 134, 68, 185, 20, 135, 186, 171, 51, 163, 4, 69, + 18, 124, 155, 85, 170, 205, 208, 13, 70, 57, 244, 206, 255, 186, 154, + 105, 149, 69, 165, 199, 93, 181, 175, 51, 67, 64, 69, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepB, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + + for (uint8_t i = 0; i < 252; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepB, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_b_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_b_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_b_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepB, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.code, greater.states[0].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.reserved, + greater.states[0].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].sid.sat, greater.states[0].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.code, greater.states[1].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.reserved, + greater.states[1].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].sid.sat, greater.states[1].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.code, greater.states[2].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.reserved, + greater.states[2].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].sid.sat, greater.states[2].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.code, greater.states[3].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.reserved, + greater.states[3].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].sid.sat, greater.states[3].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.code, greater.states[4].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.reserved, + greater.states[4].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].sid.sat, greater.states[4].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.code, greater.states[5].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.reserved, + greater.states[5].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].sid.sat, greater.states[5].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.code, greater.states[6].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.reserved, + greater.states[6].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].sid.sat, greater.states[6].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.code, greater.states[7].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.reserved, + greater.states[7].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].sid.sat, greater.states[7].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.code, greater.states[8].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.reserved, + greater.states[8].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].sid.sat, greater.states[8].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.code, greater.states[9].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.reserved, + greater.states[9].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].sid.sat, greater.states[9].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.code, + greater.states[10].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.reserved, + greater.states[10].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].sid.sat, greater.states[10].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].cn0, greater.states[11].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].sid.code, + greater.states[11].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].sid.reserved, + greater.states[11].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].sid.sat, greater.states[11].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[11].state, greater.states[11].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].cn0, greater.states[12].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].sid.code, + greater.states[12].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].sid.reserved, + greater.states[12].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].sid.sat, greater.states[12].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[12].state, greater.states[12].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].cn0, greater.states[13].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].sid.code, + greater.states[13].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].sid.reserved, + greater.states[13].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].sid.sat, greater.states[13].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[13].state, greater.states[13].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].cn0, greater.states[14].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].sid.code, + greater.states[14].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].sid.reserved, + greater.states[14].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].sid.sat, greater.states[14].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[14].state, greater.states[14].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].cn0, greater.states[15].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].sid.code, + greater.states[15].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].sid.reserved, + greater.states[15].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].sid.sat, greater.states[15].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[15].state, greater.states[15].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].cn0, greater.states[16].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].sid.code, + greater.states[16].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].sid.reserved, + greater.states[16].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].sid.sat, greater.states[16].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[16].state, greater.states[16].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].cn0, greater.states[17].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].sid.code, + greater.states[17].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].sid.reserved, + greater.states[17].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].sid.sat, greater.states[17].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[17].state, greater.states[17].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].cn0, greater.states[18].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].sid.code, + greater.states[18].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].sid.reserved, + greater.states[18].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].sid.sat, greater.states[18].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[18].state, greater.states[18].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].cn0, greater.states[19].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].sid.code, + greater.states[19].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].sid.reserved, + greater.states[19].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].sid.sat, greater.states[19].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[19].state, greater.states[19].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].cn0, greater.states[20].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].sid.code, + greater.states[20].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].sid.reserved, + greater.states[20].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].sid.sat, greater.states[20].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[20].state, greater.states[20].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].cn0, greater.states[21].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].sid.code, + greater.states[21].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].sid.reserved, + greater.states[21].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].sid.sat, greater.states[21].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[21].state, greater.states[21].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].cn0, greater.states[22].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].sid.code, + greater.states[22].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].sid.reserved, + greater.states[22].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].sid.sat, greater.states[22].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[22].state, greater.states[22].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].cn0, greater.states[23].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].sid.code, + greater.states[23].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].sid.reserved, + greater.states[23].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].sid.sat, greater.states[23].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[23].state, greater.states[23].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].cn0, greater.states[24].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].sid.code, + greater.states[24].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].sid.reserved, + greater.states[24].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].sid.sat, greater.states[24].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[24].state, greater.states[24].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].cn0, greater.states[25].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].sid.code, + greater.states[25].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].sid.reserved, + greater.states[25].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].sid.sat, greater.states[25].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[25].state, greater.states[25].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].cn0, greater.states[26].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].sid.code, + greater.states[26].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].sid.reserved, + greater.states[26].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].sid.sat, greater.states[26].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[26].state, greater.states[26].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].cn0, greater.states[27].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].sid.code, + greater.states[27].sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].sid.reserved, + greater.states[27].sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].sid.sat, greater.states[27].sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_b_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_b_t greater = info.test_msg; + make_lesser_greater(lesser.states[27].state, greater.states[27].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepB); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_B"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_b_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_b_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_b, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_b, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[252]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 252); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 252), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_b_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 252); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepB, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDepB0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepB, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDep.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDep.cc index a0c3ffd96d..ddd6e0eea9 100644 --- a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDep.cc +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDep.cc @@ -16,893 +16,4781 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0() { + assign(test_msg_.L.f, 169); + assign(test_msg_.L.i, 1319); + assign(test_msg_.P, 0); + assign(test_msg_.P_std, 0); + assign(test_msg_.acceleration, 108); + assign(test_msg_.clock_drift, 0); + assign(test_msg_.clock_offset, 0); + assign(test_msg_.cn0, 177); + assign(test_msg_.corr_spacing, 40); + assign(test_msg_.doppler, 15701); + assign(test_msg_.doppler_std, 39); + assign(test_msg_.lock, 14032); + assign(test_msg_.misc_flags, 9); + assign(test_msg_.nav_flags, 0); + assign(test_msg_.pset_flags, 0); + assign(test_msg_.recv_time, 7909447587); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 15); + assign(test_msg_.sync_flags, 1); + assign(test_msg_.tot.tow, 0); + assign(test_msg_.tot.wn, 0); + assign(test_msg_.tow_flags, 0); + assign(test_msg_.track_flags, 11); + assign(test_msg_.uptime, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep, + sizeof(msg->tracking_state_detailed_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDetailedDep); + info.sender_id = 26427; + info.preamble = 0x55; + info.crc = 0xd6a6; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_detailed_dep_t &lesser, + const sbp_msg_tracking_state_detailed_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_detailed_dep_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 17, 0, 59, 103, 55, 163, 151, 112, 215, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 5, 0, 0, 169, 177, + 208, 54, 15, 0, 0, 0, 85, 61, 0, 0, 39, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 108, 1, 0, 11, 0, 0, 9, 166, 214, + }; + uint8_t encoded_payload_[55] = { + 163, 151, 112, 215, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 39, 5, 0, 0, 169, 177, 208, 54, + 15, 0, 0, 0, 85, 61, 0, 0, 39, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 108, 1, 0, 11, 0, 0, 9, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1() { + assign(test_msg_.L.f, 14); + assign(test_msg_.L.i, 1810); + assign(test_msg_.P, 0); + assign(test_msg_.P_std, 0); + assign(test_msg_.acceleration, -32); + assign(test_msg_.clock_drift, 0); + assign(test_msg_.clock_offset, 0); + assign(test_msg_.cn0, 175); + assign(test_msg_.corr_spacing, 40); + assign(test_msg_.doppler, 15667); + assign(test_msg_.doppler_std, 30); + assign(test_msg_.lock, 14032); + assign(test_msg_.misc_flags, 9); + assign(test_msg_.nav_flags, 0); + assign(test_msg_.pset_flags, 0); + assign(test_msg_.recv_time, 8409447265); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 15); + assign(test_msg_.sync_flags, 1); + assign(test_msg_.tot.tow, 0); + assign(test_msg_.tot.wn, 0); + assign(test_msg_.tow_flags, 0); + assign(test_msg_.track_flags, 11); + assign(test_msg_.uptime, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep, + sizeof(msg->tracking_state_detailed_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDetailedDep); + info.sender_id = 26427; + info.preamble = 0x55; + info.crc = 0xb388; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_detailed_dep_t &lesser, + const sbp_msg_tracking_state_detailed_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_detailed_dep_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 17, 0, 59, 103, 55, 97, 251, 61, 245, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 7, 0, 0, 14, 175, + 208, 54, 15, 0, 0, 0, 51, 61, 0, 0, 30, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 224, 1, 0, 11, 0, 0, 9, 136, 179, + }; + uint8_t encoded_payload_[55] = { + 97, 251, 61, 245, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 18, 7, 0, 0, 14, 175, 208, 54, 15, 0, 0, 0, 51, 61, 0, 0, 30, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 40, 0, 224, 1, 0, 11, 0, 0, 9, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2() { + assign(test_msg_.L.f, 8); + assign(test_msg_.L.i, 2298); + assign(test_msg_.P, 0); + assign(test_msg_.P_std, 0); + assign(test_msg_.acceleration, 27); + assign(test_msg_.clock_drift, 0); + assign(test_msg_.clock_offset, 0); + assign(test_msg_.cn0, 179); + assign(test_msg_.corr_spacing, 40); + assign(test_msg_.doppler, 15683); + assign(test_msg_.doppler_std, 22); + assign(test_msg_.lock, 14032); + assign(test_msg_.misc_flags, 9); + assign(test_msg_.nav_flags, 0); + assign(test_msg_.pset_flags, 2); + assign(test_msg_.recv_time, 8907446923); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 15); + assign(test_msg_.sync_flags, 1); + assign(test_msg_.tot.tow, 0); + assign(test_msg_.tot.wn, 0); + assign(test_msg_.tow_flags, 0); + assign(test_msg_.track_flags, 11); + assign(test_msg_.uptime, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep, + sizeof(msg->tracking_state_detailed_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDetailedDep); + info.sender_id = 26427; + info.preamble = 0x55; + info.crc = 0x9fd9; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_detailed_dep_t &lesser, + const sbp_msg_tracking_state_detailed_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_detailed_dep_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 17, 0, 59, 103, 55, 139, 218, 236, 18, 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250, 8, 0, 0, 8, 179, + 208, 54, 15, 0, 0, 0, 67, 61, 0, 0, 22, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 27, 1, 0, 11, 0, 2, 9, 217, 159, + }; + uint8_t encoded_payload_[55] = { + 139, 218, 236, 18, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 250, 8, 0, 0, 8, 179, 208, 54, 15, 0, 0, 0, 67, 61, 0, 0, 22, 0, + 2, 0, 0, 0, 0, 0, 0, 0, 40, 0, 27, 1, 0, 11, 0, 2, 9, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3 + : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3() { + assign(test_msg_.L.f, 125); + assign(test_msg_.L.i, 2786); + assign(test_msg_.P, 0); + assign(test_msg_.P_std, 0); + assign(test_msg_.acceleration, -36); + assign(test_msg_.clock_drift, 0); + assign(test_msg_.clock_offset, 0); + assign(test_msg_.cn0, 181); + assign(test_msg_.corr_spacing, 40); + assign(test_msg_.doppler, 15645); + assign(test_msg_.doppler_std, 10); + assign(test_msg_.lock, 14032); + assign(test_msg_.misc_flags, 9); + assign(test_msg_.nav_flags, 0); + assign(test_msg_.pset_flags, 3); + assign(test_msg_.recv_time, 9406446591); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 15); + assign(test_msg_.sync_flags, 1); + assign(test_msg_.tot.tow, 0); + assign(test_msg_.tot.wn, 0); + assign(test_msg_.tow_flags, 0); + assign(test_msg_.track_flags, 11); + assign(test_msg_.uptime, 2); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep, + sizeof(msg->tracking_state_detailed_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDetailedDep); + info.sender_id = 26427; + info.preamble = 0x55; + info.crc = 0x5f42; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_detailed_dep_t &lesser, + const sbp_msg_tracking_state_detailed_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_detailed_dep_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { + 85, 17, 0, 59, 103, 55, 255, 251, 170, 48, 2, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 226, 10, 0, 0, 125, 181, + 208, 54, 15, 0, 0, 0, 29, 61, 0, 0, 10, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 220, 1, 0, 11, 0, 3, 9, 66, 95, + }; + uint8_t encoded_payload_[55] = { + 255, 251, 170, 48, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 226, 10, 0, 0, 125, 181, 208, 54, + 15, 0, 0, 0, 29, 61, 0, 0, 10, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 40, 0, 220, 1, 0, 11, 0, 3, 9, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); } - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_tracking_state_detailed_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_detailed_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep0, Test) { - uint8_t encoded_frame[] = { - 85, 17, 0, 59, 103, 55, 163, 151, 112, 215, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 5, 0, 0, 169, 177, - 208, 54, 15, 0, 0, 0, 85, 61, 0, 0, 39, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 40, 0, 108, 1, 0, 11, 0, 0, 9, 166, 214, - }; +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} - sbp_msg_tracking_state_detailed_dep_t test_msg{}; - test_msg.L.f = 169; - test_msg.L.i = 1319; - test_msg.P = 0; - test_msg.P_std = 0; - test_msg.acceleration = 108; - test_msg.clock_drift = 0; - test_msg.clock_offset = 0; - test_msg.cn0 = 177; - test_msg.corr_spacing = 40; - test_msg.doppler = 15701; - test_msg.doppler_std = 39; - test_msg.lock = 14032; - test_msg.misc_flags = 9; - test_msg.nav_flags = 0; - test_msg.pset_flags = 0; - test_msg.recv_time = 7909447587; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 15; - test_msg.sync_flags = 1; - test_msg.tot.tow = 0; - test_msg.tot.wn = 0; - test_msg.tow_flags = 0; - test_msg.track_flags = 11; - test_msg.uptime = 1; - - EXPECT_EQ(send_message(26427, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 26427); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.L.f, 169) - << "incorrect value for last_msg_.L.f, expected 169, is " - << last_msg_.L.f; - EXPECT_EQ(last_msg_.L.i, 1319) - << "incorrect value for last_msg_.L.i, expected 1319, is " - << last_msg_.L.i; - EXPECT_EQ(last_msg_.P, 0) - << "incorrect value for last_msg_.P, expected 0, is " << last_msg_.P; - EXPECT_EQ(last_msg_.P_std, 0) - << "incorrect value for last_msg_.P_std, expected 0, is " - << last_msg_.P_std; - EXPECT_EQ(last_msg_.acceleration, 108) - << "incorrect value for last_msg_.acceleration, expected 108, is " - << last_msg_.acceleration; - EXPECT_EQ(last_msg_.clock_drift, 0) - << "incorrect value for last_msg_.clock_drift, expected 0, is " - << last_msg_.clock_drift; - EXPECT_EQ(last_msg_.clock_offset, 0) - << "incorrect value for last_msg_.clock_offset, expected 0, is " - << last_msg_.clock_offset; - EXPECT_EQ(last_msg_.cn0, 177) - << "incorrect value for last_msg_.cn0, expected 177, is " - << last_msg_.cn0; - EXPECT_EQ(last_msg_.corr_spacing, 40) - << "incorrect value for last_msg_.corr_spacing, expected 40, is " - << last_msg_.corr_spacing; - EXPECT_EQ(last_msg_.doppler, 15701) - << "incorrect value for last_msg_.doppler, expected 15701, is " - << last_msg_.doppler; - EXPECT_EQ(last_msg_.doppler_std, 39) - << "incorrect value for last_msg_.doppler_std, expected 39, is " - << last_msg_.doppler_std; - EXPECT_EQ(last_msg_.lock, 14032) - << "incorrect value for last_msg_.lock, expected 14032, is " - << last_msg_.lock; - EXPECT_EQ(last_msg_.misc_flags, 9) - << "incorrect value for last_msg_.misc_flags, expected 9, is " - << last_msg_.misc_flags; - EXPECT_EQ(last_msg_.nav_flags, 0) - << "incorrect value for last_msg_.nav_flags, expected 0, is " - << last_msg_.nav_flags; - EXPECT_EQ(last_msg_.pset_flags, 0) - << "incorrect value for last_msg_.pset_flags, expected 0, is " - << last_msg_.pset_flags; - EXPECT_EQ(last_msg_.recv_time, 7909447587) - << "incorrect value for last_msg_.recv_time, expected 7909447587, is " - << last_msg_.recv_time; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 15) - << "incorrect value for last_msg_.sid.sat, expected 15, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.sync_flags, 1) - << "incorrect value for last_msg_.sync_flags, expected 1, is " - << last_msg_.sync_flags; - EXPECT_EQ(last_msg_.tot.tow, 0) - << "incorrect value for last_msg_.tot.tow, expected 0, is " - << last_msg_.tot.tow; - EXPECT_EQ(last_msg_.tot.wn, 0) - << "incorrect value for last_msg_.tot.wn, expected 0, is " - << last_msg_.tot.wn; - EXPECT_EQ(last_msg_.tow_flags, 0) - << "incorrect value for last_msg_.tow_flags, expected 0, is " - << last_msg_.tow_flags; - EXPECT_EQ(last_msg_.track_flags, 11) - << "incorrect value for last_msg_.track_flags, expected 11, is " - << last_msg_.track_flags; - EXPECT_EQ(last_msg_.uptime, 1) - << "incorrect value for last_msg_.uptime, expected 1, is " - << last_msg_.uptime; -} -class Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4 + : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4() { + assign(test_msg_.L.f, 64); + assign(test_msg_.L.i, 3275); + assign(test_msg_.P, 0); + assign(test_msg_.P_std, 0); + assign(test_msg_.acceleration, 2); + assign(test_msg_.clock_drift, 0); + assign(test_msg_.clock_offset, 0); + assign(test_msg_.cn0, 184); + assign(test_msg_.corr_spacing, 40); + assign(test_msg_.doppler, 15640); + assign(test_msg_.doppler_std, 4); + assign(test_msg_.lock, 14032); + assign(test_msg_.misc_flags, 9); + assign(test_msg_.nav_flags, 0); + assign(test_msg_.pset_flags, 3); + assign(test_msg_.recv_time, 9906446269); + assign(test_msg_.sid.code, 0); + assign(test_msg_.sid.reserved, 0); + assign(test_msg_.sid.sat, 15); + assign(test_msg_.sync_flags, 1); + assign(test_msg_.tot.tow, 0); + assign(test_msg_.tot.wn, 0); + assign(test_msg_.tow_flags, 0); + assign(test_msg_.track_flags, 11); + assign(test_msg_.uptime, 3); } - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_tracking_state_detailed_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_detailed_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep1, Test) { - uint8_t encoded_frame[] = { - 85, 17, 0, 59, 103, 55, 97, 251, 61, 245, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 7, 0, 0, 14, 175, - 208, 54, 15, 0, 0, 0, 51, 61, 0, 0, 30, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 40, 0, 224, 1, 0, 11, 0, 0, 9, 136, 179, + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; }; - sbp_msg_tracking_state_detailed_dep_t test_msg{}; - test_msg.L.f = 14; - test_msg.L.i = 1810; - test_msg.P = 0; - test_msg.P_std = 0; - test_msg.acceleration = -32; - test_msg.clock_drift = 0; - test_msg.clock_offset = 0; - test_msg.cn0 = 175; - test_msg.corr_spacing = 40; - test_msg.doppler = 15667; - test_msg.doppler_std = 30; - test_msg.lock = 14032; - test_msg.misc_flags = 9; - test_msg.nav_flags = 0; - test_msg.pset_flags = 0; - test_msg.recv_time = 8409447265; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 15; - test_msg.sync_flags = 1; - test_msg.tot.tow = 0; - test_msg.tot.wn = 0; - test_msg.tow_flags = 0; - test_msg.track_flags = 11; - test_msg.uptime = 1; - - EXPECT_EQ(send_message(26427, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 26427); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.L.f, 14) - << "incorrect value for last_msg_.L.f, expected 14, is " << last_msg_.L.f; - EXPECT_EQ(last_msg_.L.i, 1810) - << "incorrect value for last_msg_.L.i, expected 1810, is " - << last_msg_.L.i; - EXPECT_EQ(last_msg_.P, 0) - << "incorrect value for last_msg_.P, expected 0, is " << last_msg_.P; - EXPECT_EQ(last_msg_.P_std, 0) - << "incorrect value for last_msg_.P_std, expected 0, is " - << last_msg_.P_std; - EXPECT_EQ(last_msg_.acceleration, -32) - << "incorrect value for last_msg_.acceleration, expected -32, is " - << last_msg_.acceleration; - EXPECT_EQ(last_msg_.clock_drift, 0) - << "incorrect value for last_msg_.clock_drift, expected 0, is " - << last_msg_.clock_drift; - EXPECT_EQ(last_msg_.clock_offset, 0) - << "incorrect value for last_msg_.clock_offset, expected 0, is " - << last_msg_.clock_offset; - EXPECT_EQ(last_msg_.cn0, 175) - << "incorrect value for last_msg_.cn0, expected 175, is " - << last_msg_.cn0; - EXPECT_EQ(last_msg_.corr_spacing, 40) - << "incorrect value for last_msg_.corr_spacing, expected 40, is " - << last_msg_.corr_spacing; - EXPECT_EQ(last_msg_.doppler, 15667) - << "incorrect value for last_msg_.doppler, expected 15667, is " - << last_msg_.doppler; - EXPECT_EQ(last_msg_.doppler_std, 30) - << "incorrect value for last_msg_.doppler_std, expected 30, is " - << last_msg_.doppler_std; - EXPECT_EQ(last_msg_.lock, 14032) - << "incorrect value for last_msg_.lock, expected 14032, is " - << last_msg_.lock; - EXPECT_EQ(last_msg_.misc_flags, 9) - << "incorrect value for last_msg_.misc_flags, expected 9, is " - << last_msg_.misc_flags; - EXPECT_EQ(last_msg_.nav_flags, 0) - << "incorrect value for last_msg_.nav_flags, expected 0, is " - << last_msg_.nav_flags; - EXPECT_EQ(last_msg_.pset_flags, 0) - << "incorrect value for last_msg_.pset_flags, expected 0, is " - << last_msg_.pset_flags; - EXPECT_EQ(last_msg_.recv_time, 8409447265) - << "incorrect value for last_msg_.recv_time, expected 8409447265, is " - << last_msg_.recv_time; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 15) - << "incorrect value for last_msg_.sid.sat, expected 15, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.sync_flags, 1) - << "incorrect value for last_msg_.sync_flags, expected 1, is " - << last_msg_.sync_flags; - EXPECT_EQ(last_msg_.tot.tow, 0) - << "incorrect value for last_msg_.tot.tow, expected 0, is " - << last_msg_.tot.tow; - EXPECT_EQ(last_msg_.tot.wn, 0) - << "incorrect value for last_msg_.tot.wn, expected 0, is " - << last_msg_.tot.wn; - EXPECT_EQ(last_msg_.tow_flags, 0) - << "incorrect value for last_msg_.tow_flags, expected 0, is " - << last_msg_.tow_flags; - EXPECT_EQ(last_msg_.track_flags, 11) - << "incorrect value for last_msg_.track_flags, expected 11, is " - << last_msg_.track_flags; - EXPECT_EQ(last_msg_.uptime, 1) - << "incorrect value for last_msg_.uptime, expected 1, is " - << last_msg_.uptime; -} -class Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_tracking_state_detailed_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_detailed_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep2, Test) { - uint8_t encoded_frame[] = { - 85, 17, 0, 59, 103, 55, 139, 218, 236, 18, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250, 8, 0, 0, 8, 179, - 208, 54, 15, 0, 0, 0, 67, 61, 0, 0, 22, 0, 2, 0, 0, 0, - 0, 0, 0, 0, 40, 0, 27, 1, 0, 11, 0, 2, 9, 217, 159, + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_tracking_state_detailed_dep_t test_msg{}; - test_msg.L.f = 8; - test_msg.L.i = 2298; - test_msg.P = 0; - test_msg.P_std = 0; - test_msg.acceleration = 27; - test_msg.clock_drift = 0; - test_msg.clock_offset = 0; - test_msg.cn0 = 179; - test_msg.corr_spacing = 40; - test_msg.doppler = 15683; - test_msg.doppler_std = 22; - test_msg.lock = 14032; - test_msg.misc_flags = 9; - test_msg.nav_flags = 0; - test_msg.pset_flags = 2; - test_msg.recv_time = 8907446923; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 15; - test_msg.sync_flags = 1; - test_msg.tot.tow = 0; - test_msg.tot.wn = 0; - test_msg.tow_flags = 0; - test_msg.track_flags = 11; - test_msg.uptime = 2; - - EXPECT_EQ(send_message(26427, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 26427); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.L.f, 8) - << "incorrect value for last_msg_.L.f, expected 8, is " << last_msg_.L.f; - EXPECT_EQ(last_msg_.L.i, 2298) - << "incorrect value for last_msg_.L.i, expected 2298, is " - << last_msg_.L.i; - EXPECT_EQ(last_msg_.P, 0) - << "incorrect value for last_msg_.P, expected 0, is " << last_msg_.P; - EXPECT_EQ(last_msg_.P_std, 0) - << "incorrect value for last_msg_.P_std, expected 0, is " - << last_msg_.P_std; - EXPECT_EQ(last_msg_.acceleration, 27) - << "incorrect value for last_msg_.acceleration, expected 27, is " - << last_msg_.acceleration; - EXPECT_EQ(last_msg_.clock_drift, 0) - << "incorrect value for last_msg_.clock_drift, expected 0, is " - << last_msg_.clock_drift; - EXPECT_EQ(last_msg_.clock_offset, 0) - << "incorrect value for last_msg_.clock_offset, expected 0, is " - << last_msg_.clock_offset; - EXPECT_EQ(last_msg_.cn0, 179) - << "incorrect value for last_msg_.cn0, expected 179, is " - << last_msg_.cn0; - EXPECT_EQ(last_msg_.corr_spacing, 40) - << "incorrect value for last_msg_.corr_spacing, expected 40, is " - << last_msg_.corr_spacing; - EXPECT_EQ(last_msg_.doppler, 15683) - << "incorrect value for last_msg_.doppler, expected 15683, is " - << last_msg_.doppler; - EXPECT_EQ(last_msg_.doppler_std, 22) - << "incorrect value for last_msg_.doppler_std, expected 22, is " - << last_msg_.doppler_std; - EXPECT_EQ(last_msg_.lock, 14032) - << "incorrect value for last_msg_.lock, expected 14032, is " - << last_msg_.lock; - EXPECT_EQ(last_msg_.misc_flags, 9) - << "incorrect value for last_msg_.misc_flags, expected 9, is " - << last_msg_.misc_flags; - EXPECT_EQ(last_msg_.nav_flags, 0) - << "incorrect value for last_msg_.nav_flags, expected 0, is " - << last_msg_.nav_flags; - EXPECT_EQ(last_msg_.pset_flags, 2) - << "incorrect value for last_msg_.pset_flags, expected 2, is " - << last_msg_.pset_flags; - EXPECT_EQ(last_msg_.recv_time, 8907446923) - << "incorrect value for last_msg_.recv_time, expected 8907446923, is " - << last_msg_.recv_time; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 15) - << "incorrect value for last_msg_.sid.sat, expected 15, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.sync_flags, 1) - << "incorrect value for last_msg_.sync_flags, expected 1, is " - << last_msg_.sync_flags; - EXPECT_EQ(last_msg_.tot.tow, 0) - << "incorrect value for last_msg_.tot.tow, expected 0, is " - << last_msg_.tot.tow; - EXPECT_EQ(last_msg_.tot.wn, 0) - << "incorrect value for last_msg_.tot.wn, expected 0, is " - << last_msg_.tot.wn; - EXPECT_EQ(last_msg_.tow_flags, 0) - << "incorrect value for last_msg_.tow_flags, expected 0, is " - << last_msg_.tow_flags; - EXPECT_EQ(last_msg_.track_flags, 11) - << "incorrect value for last_msg_.track_flags, expected 11, is " - << last_msg_.track_flags; - EXPECT_EQ(last_msg_.uptime, 2) - << "incorrect value for last_msg_.uptime, expected 2, is " - << last_msg_.uptime; -} -class Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; - } + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; - protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_tracking_state_detailed_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_detailed_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep3, Test) { - uint8_t encoded_frame[] = { - 85, 17, 0, 59, 103, 55, 255, 251, 170, 48, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 226, 10, 0, 0, 125, 181, - 208, 54, 15, 0, 0, 0, 29, 61, 0, 0, 10, 0, 2, 0, 0, 0, - 0, 0, 0, 0, 40, 0, 220, 1, 0, 11, 0, 3, 9, 66, 95, + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; }; - sbp_msg_tracking_state_detailed_dep_t test_msg{}; - test_msg.L.f = 125; - test_msg.L.i = 2786; - test_msg.P = 0; - test_msg.P_std = 0; - test_msg.acceleration = -36; - test_msg.clock_drift = 0; - test_msg.clock_offset = 0; - test_msg.cn0 = 181; - test_msg.corr_spacing = 40; - test_msg.doppler = 15645; - test_msg.doppler_std = 10; - test_msg.lock = 14032; - test_msg.misc_flags = 9; - test_msg.nav_flags = 0; - test_msg.pset_flags = 3; - test_msg.recv_time = 9406446591; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 15; - test_msg.sync_flags = 1; - test_msg.tot.tow = 0; - test_msg.tot.wn = 0; - test_msg.tow_flags = 0; - test_msg.track_flags = 11; - test_msg.uptime = 2; - - EXPECT_EQ(send_message(26427, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 26427); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.L.f, 125) - << "incorrect value for last_msg_.L.f, expected 125, is " - << last_msg_.L.f; - EXPECT_EQ(last_msg_.L.i, 2786) - << "incorrect value for last_msg_.L.i, expected 2786, is " - << last_msg_.L.i; - EXPECT_EQ(last_msg_.P, 0) - << "incorrect value for last_msg_.P, expected 0, is " << last_msg_.P; - EXPECT_EQ(last_msg_.P_std, 0) - << "incorrect value for last_msg_.P_std, expected 0, is " - << last_msg_.P_std; - EXPECT_EQ(last_msg_.acceleration, -36) - << "incorrect value for last_msg_.acceleration, expected -36, is " - << last_msg_.acceleration; - EXPECT_EQ(last_msg_.clock_drift, 0) - << "incorrect value for last_msg_.clock_drift, expected 0, is " - << last_msg_.clock_drift; - EXPECT_EQ(last_msg_.clock_offset, 0) - << "incorrect value for last_msg_.clock_offset, expected 0, is " - << last_msg_.clock_offset; - EXPECT_EQ(last_msg_.cn0, 181) - << "incorrect value for last_msg_.cn0, expected 181, is " - << last_msg_.cn0; - EXPECT_EQ(last_msg_.corr_spacing, 40) - << "incorrect value for last_msg_.corr_spacing, expected 40, is " - << last_msg_.corr_spacing; - EXPECT_EQ(last_msg_.doppler, 15645) - << "incorrect value for last_msg_.doppler, expected 15645, is " - << last_msg_.doppler; - EXPECT_EQ(last_msg_.doppler_std, 10) - << "incorrect value for last_msg_.doppler_std, expected 10, is " - << last_msg_.doppler_std; - EXPECT_EQ(last_msg_.lock, 14032) - << "incorrect value for last_msg_.lock, expected 14032, is " - << last_msg_.lock; - EXPECT_EQ(last_msg_.misc_flags, 9) - << "incorrect value for last_msg_.misc_flags, expected 9, is " - << last_msg_.misc_flags; - EXPECT_EQ(last_msg_.nav_flags, 0) - << "incorrect value for last_msg_.nav_flags, expected 0, is " - << last_msg_.nav_flags; - EXPECT_EQ(last_msg_.pset_flags, 3) - << "incorrect value for last_msg_.pset_flags, expected 3, is " - << last_msg_.pset_flags; - EXPECT_EQ(last_msg_.recv_time, 9406446591) - << "incorrect value for last_msg_.recv_time, expected 9406446591, is " - << last_msg_.recv_time; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 15) - << "incorrect value for last_msg_.sid.sat, expected 15, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.sync_flags, 1) - << "incorrect value for last_msg_.sync_flags, expected 1, is " - << last_msg_.sync_flags; - EXPECT_EQ(last_msg_.tot.tow, 0) - << "incorrect value for last_msg_.tot.tow, expected 0, is " - << last_msg_.tot.tow; - EXPECT_EQ(last_msg_.tot.wn, 0) - << "incorrect value for last_msg_.tot.wn, expected 0, is " - << last_msg_.tot.wn; - EXPECT_EQ(last_msg_.tow_flags, 0) - << "incorrect value for last_msg_.tow_flags, expected 0, is " - << last_msg_.tow_flags; - EXPECT_EQ(last_msg_.track_flags, 11) - << "incorrect value for last_msg_.track_flags, expected 11, is " - << last_msg_.track_flags; - EXPECT_EQ(last_msg_.uptime, 2) - << "incorrect value for last_msg_.uptime, expected 2, is " - << last_msg_.uptime; -} -class Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDep, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDep); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep, + sizeof(msg->tracking_state_detailed_dep)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDetailedDep); + info.sender_id = 26427; + info.preamble = 0x55; + info.crc = 0xcec2; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 55; + + return info; } protected: - void handle_sbp_msg( - uint16_t sender_id, - const sbp_msg_tracking_state_detailed_dep_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_detailed_dep_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_tracking_state_detailed_dep_t &lesser, + const sbp_msg_tracking_state_detailed_dep_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDep, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_tracking_MsgTrackingStateDetailedDep4, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_tracking_state_detailed_dep_t test_msg_{}; + uint8_t encoded_frame_[55 + 8] = { 85, 17, 0, 59, 103, 55, 189, 95, 120, 78, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 203, 12, 0, 0, 64, 184, 208, 54, 15, 0, 0, 0, 24, 61, 0, 0, 4, 0, 3, 0, 0, 0, 0, 0, 0, 0, 40, 0, 2, 1, 0, 11, 0, 3, 9, 194, 206, }; + uint8_t encoded_payload_[55] = { + 189, 95, 120, 78, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 203, 12, 0, 0, 64, 184, 208, 54, 15, 0, 0, 0, 24, 61, 0, 0, 4, 0, + 3, 0, 0, 0, 0, 0, 0, 0, 40, 0, 2, 1, 0, 11, 0, 3, 9, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], sizeof(buf), + nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + + for (uint8_t i = 0; i < 55; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; - sbp_msg_tracking_state_detailed_dep_t test_msg{}; - test_msg.L.f = 64; - test_msg.L.i = 3275; - test_msg.P = 0; - test_msg.P_std = 0; - test_msg.acceleration = 2; - test_msg.clock_drift = 0; - test_msg.clock_offset = 0; - test_msg.cn0 = 184; - test_msg.corr_spacing = 40; - test_msg.doppler = 15640; - test_msg.doppler_std = 4; - test_msg.lock = 14032; - test_msg.misc_flags = 9; - test_msg.nav_flags = 0; - test_msg.pset_flags = 3; - test_msg.recv_time = 9906446269; - test_msg.sid.code = 0; - test_msg.sid.reserved = 0; - test_msg.sid.sat = 15; - test_msg.sync_flags = 1; - test_msg.tot.tow = 0; - test_msg.tot.wn = 0; - test_msg.tow_flags = 0; - test_msg.track_flags = 11; - test_msg.uptime = 3; - - EXPECT_EQ(send_message(26427, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 26427); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.L.f, 64) - << "incorrect value for last_msg_.L.f, expected 64, is " << last_msg_.L.f; - EXPECT_EQ(last_msg_.L.i, 3275) - << "incorrect value for last_msg_.L.i, expected 3275, is " - << last_msg_.L.i; - EXPECT_EQ(last_msg_.P, 0) - << "incorrect value for last_msg_.P, expected 0, is " << last_msg_.P; - EXPECT_EQ(last_msg_.P_std, 0) - << "incorrect value for last_msg_.P_std, expected 0, is " - << last_msg_.P_std; - EXPECT_EQ(last_msg_.acceleration, 2) - << "incorrect value for last_msg_.acceleration, expected 2, is " - << last_msg_.acceleration; - EXPECT_EQ(last_msg_.clock_drift, 0) - << "incorrect value for last_msg_.clock_drift, expected 0, is " - << last_msg_.clock_drift; - EXPECT_EQ(last_msg_.clock_offset, 0) - << "incorrect value for last_msg_.clock_offset, expected 0, is " - << last_msg_.clock_offset; - EXPECT_EQ(last_msg_.cn0, 184) - << "incorrect value for last_msg_.cn0, expected 184, is " - << last_msg_.cn0; - EXPECT_EQ(last_msg_.corr_spacing, 40) - << "incorrect value for last_msg_.corr_spacing, expected 40, is " - << last_msg_.corr_spacing; - EXPECT_EQ(last_msg_.doppler, 15640) - << "incorrect value for last_msg_.doppler, expected 15640, is " - << last_msg_.doppler; - EXPECT_EQ(last_msg_.doppler_std, 4) - << "incorrect value for last_msg_.doppler_std, expected 4, is " - << last_msg_.doppler_std; - EXPECT_EQ(last_msg_.lock, 14032) - << "incorrect value for last_msg_.lock, expected 14032, is " - << last_msg_.lock; - EXPECT_EQ(last_msg_.misc_flags, 9) - << "incorrect value for last_msg_.misc_flags, expected 9, is " - << last_msg_.misc_flags; - EXPECT_EQ(last_msg_.nav_flags, 0) - << "incorrect value for last_msg_.nav_flags, expected 0, is " - << last_msg_.nav_flags; - EXPECT_EQ(last_msg_.pset_flags, 3) - << "incorrect value for last_msg_.pset_flags, expected 3, is " - << last_msg_.pset_flags; - EXPECT_EQ(last_msg_.recv_time, 9906446269) - << "incorrect value for last_msg_.recv_time, expected 9906446269, is " - << last_msg_.recv_time; - EXPECT_EQ(last_msg_.sid.code, 0) - << "incorrect value for last_msg_.sid.code, expected 0, is " - << last_msg_.sid.code; - EXPECT_EQ(last_msg_.sid.reserved, 0) - << "incorrect value for last_msg_.sid.reserved, expected 0, is " - << last_msg_.sid.reserved; - EXPECT_EQ(last_msg_.sid.sat, 15) - << "incorrect value for last_msg_.sid.sat, expected 15, is " - << last_msg_.sid.sat; - EXPECT_EQ(last_msg_.sync_flags, 1) - << "incorrect value for last_msg_.sync_flags, expected 1, is " - << last_msg_.sync_flags; - EXPECT_EQ(last_msg_.tot.tow, 0) - << "incorrect value for last_msg_.tot.tow, expected 0, is " - << last_msg_.tot.tow; - EXPECT_EQ(last_msg_.tot.wn, 0) - << "incorrect value for last_msg_.tot.wn, expected 0, is " - << last_msg_.tot.wn; - EXPECT_EQ(last_msg_.tow_flags, 0) - << "incorrect value for last_msg_.tow_flags, expected 0, is " - << last_msg_.tow_flags; - EXPECT_EQ(last_msg_.track_flags, 11) - << "incorrect value for last_msg_.track_flags, expected 11, is " - << last_msg_.track_flags; - EXPECT_EQ(last_msg_.uptime, 3) - << "incorrect value for last_msg_.uptime, expected 3, is " - << last_msg_.uptime; + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDep, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDep, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.reserved, greater.sid.reserved); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDep); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep, info.test_msg); } + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[55]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 55); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 55), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 55); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDep4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDep, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc new file mode 100644 index 0000000000..d34bb11671 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc @@ -0,0 +1,987 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0() { + assign(test_msg_.L.f, 204); + assign(test_msg_.L.i, -1601767965); + assign(test_msg_.P, 1044286343); + assign(test_msg_.P_std, 21427); + assign(test_msg_.acceleration, -114); + assign(test_msg_.clock_drift, 23311); + assign(test_msg_.clock_offset, 6012); + assign(test_msg_.cn0, 78); + assign(test_msg_.corr_spacing, 30201); + assign(test_msg_.doppler, 1459556257); + assign(test_msg_.doppler_std, 63677); + assign(test_msg_.lock, 65375); + assign(test_msg_.misc_flags, 62); + assign(test_msg_.nav_flags, 25); + assign(test_msg_.pset_flags, 83); + assign(test_msg_.recv_time, 941247176494); + assign(test_msg_.sid.code, 59); + assign(test_msg_.sid.sat, 38); + assign(test_msg_.sync_flags, 90); + assign(test_msg_.tot.ns_residual, -811597120); + assign(test_msg_.tot.tow, 1581737093); + assign(test_msg_.tot.wn, 65492); + assign(test_msg_.tow_flags, 219); + assign(test_msg_.track_flags, 67); + assign(test_msg_.uptime, 3263741727); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler< + sbp_msg_tracking_state_detailed_dep_a_t>::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg( + uint16_t sender_id, + const sbp_msg_tracking_state_detailed_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDetailedDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_detailed_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDetailedDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_detailed_dep_a, + sizeof(msg->tracking_state_detailed_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_detailed_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_detailed_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = + static_cast(SbpMsgTrackingStateDetailedDepA); + info.sender_id = 28315; + info.preamble = 0x55; + info.crc = 0x647a; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 57; + + return info; + } + + protected: + void comparison_tests( + const sbp_msg_tracking_state_detailed_dep_a_t &lesser, + const sbp_msg_tracking_state_detailed_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg( + lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg( + greater); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_detailed_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_detailed_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDetailedDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDetailedDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDetailedDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_detailed_dep_a_t test_msg_{}; + uint8_t encoded_frame_[57 + 8] = { + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, + 0, 133, 100, 71, 94, 192, 2, 160, 207, 212, 255, 135, 139, + 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, + 59, 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, + 15, 91, 249, 117, 142, 90, 219, 67, 25, 83, 62, 122, 100, + }; + uint8_t encoded_payload_[57] = { + 46, 31, 180, 38, 219, 0, 0, 0, 133, 100, 71, 94, 192, 2, 160, + 207, 212, 255, 135, 139, 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, + 95, 255, 38, 59, 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, + 23, 15, 91, 249, 117, 142, 90, 219, 67, 25, 83, 62, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgTrackingStateDetailedDepA, + &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[57]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_encode( + &buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 57); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 57), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDetailedDepA, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 57); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 57), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[57]; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_encode( + &buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 57), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[57]; + + for (uint8_t i = 0; i < 57; i++) { + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 57); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ( + sbp_message_decode(&info.encoded_payload[0], info.payload_len, &n_read, + SbpMsgTrackingStateDetailedDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 57); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_decode( + &info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_detailed_dep_a_send( + &state, info.sender_id, &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDetailedDepA, + info.sender_id, &info.test_msg_wrapped, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( + sbp_message_send(&state, SbpMsgTrackingStateDetailedDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.L.f, greater.L.f); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.L.i, greater.L.i); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.P, greater.P); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.P_std, greater.P_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.acceleration, greater.acceleration); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.clock_drift, greater.clock_drift); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.clock_offset, greater.clock_offset); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.cn0, greater.cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.corr_spacing, greater.corr_spacing); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.doppler, greater.doppler); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.doppler_std, greater.doppler_std); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.lock, greater.lock); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.misc_flags, greater.misc_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.nav_flags, greater.nav_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.pset_flags, greater.pset_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.recv_time, greater.recv_time); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.code, greater.sid.code); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sid.sat, greater.sid.sat); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.sync_flags, greater.sync_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tot.ns_residual, greater.tot.ns_residual); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tot.tow, greater.tot.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tot.wn, greater.tot.wn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.tow_flags, greater.tow_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.track_flags, greater.track_flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_detailed_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_detailed_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.uptime, greater.uptime); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDetailedDepA); + EXPECT_STREQ( + sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DETAILED_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_detailed_dep_a_t &const_unwrapped = + sbp::MessageTraits::get( + const_sbp_msg_t); + sbp_msg_tracking_state_detailed_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_detailed_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg( + info.test_msg, &msg2); + EXPECT_EQ(msg2.tracking_state_detailed_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( + sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[57]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 57); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 57), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_detailed_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 57); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDetailedDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDetailedDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_MsgtrackingStateDepA.cc b/c/test/cpp/auto_check_sbp_tracking_MsgtrackingStateDepA.cc index 74e63675e6..4055677aeb 100644 --- a/c/test/cpp/auto_check_sbp_tracking_MsgtrackingStateDepA.cc +++ b/c/test/cpp/auto_check_sbp_tracking_MsgtrackingStateDepA.cc @@ -16,1401 +16,6239 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_tracking_MsgtrackingStateDepA0 + : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgtrackingStateDepA0() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 11.230907440185547); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 10.438665390014648); + assign(test_msg_.states[1].prn, 2); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 9.732142448425293); + assign(test_msg_.states[2].prn, 3); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 14.341922760009766); + assign(test_msg_.states[3].prn, 7); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 7.8549017906188965); + assign(test_msg_.states[4].prn, 10); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 5.0982866287231445); + assign(test_msg_.states[5].prn, 13); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 6.741272926330566); + assign(test_msg_.states[6].prn, 22); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 12.700549125671387); + assign(test_msg_.states[7].prn, 30); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 15.893081665039062); + assign(test_msg_.states[8].prn, 31); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, 4.242738723754883); + assign(test_msg_.states[9].prn, 25); + assign(test_msg_.states[9].state, 1); + + assign(test_msg_.states[10].cn0, 6.97599983215332); + assign(test_msg_.states[10].prn, 6); + assign(test_msg_.states[10].state, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xe111; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA0, Test) { - uint8_t encoded_frame[] = { + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { 85, 22, 0, 195, 4, 66, 1, 0, 204, 177, 51, 65, 1, 2, 198, 4, 39, 65, 1, 3, 219, 182, 27, 65, 1, 7, 132, 120, 101, 65, 1, 10, 91, 91, 251, 64, 1, 13, 42, 37, 163, 64, 1, 22, 130, 184, 215, 64, 1, 30, 115, 53, 75, 65, 1, 31, 16, 74, 126, 65, 1, 25, 132, 196, 135, 64, 1, 6, 100, 59, 223, 64, 17, 225, }; + uint8_t encoded_payload_[66] = { + 1, 0, 204, 177, 51, 65, 1, 2, 198, 4, 39, 65, 1, 3, + 219, 182, 27, 65, 1, 7, 132, 120, 101, 65, 1, 10, 91, 91, + 251, 64, 1, 13, 42, 37, 163, 64, 1, 22, 130, 184, 215, 64, + 1, 30, 115, 53, 75, 65, 1, 31, 16, 74, 126, 65, 1, 25, + 132, 196, 135, 64, 1, 6, 100, 59, 223, 64, + }; +}; - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 11.230907440185547; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 10.438665390014648; - test_msg.states[1].prn = 2; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 9.732142448425293; - test_msg.states[2].prn = 3; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 14.341922760009766; - test_msg.states[3].prn = 7; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 7.8549017906188965; - test_msg.states[4].prn = 10; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 5.0982866287231445; - test_msg.states[5].prn = 13; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 6.741272926330566; - test_msg.states[6].prn = 22; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 12.700549125671387; - test_msg.states[7].prn = 30; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 15.893081665039062; - test_msg.states[8].prn = 31; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = 4.242738723754883; - test_msg.states[9].prn = 25; - test_msg.states[9].state = 1; - - test_msg.states[10].cn0 = 6.97599983215332; - test_msg.states[10].prn = 6; - test_msg.states[10].state = 1; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 11.2309074402 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 11.2309074402, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 10.43866539 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 10.43866539, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 2) - << "incorrect value for last_msg_.states[1].prn, expected 2, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 9.73214244843 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 9.73214244843, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 3) - << "incorrect value for last_msg_.states[2].prn, expected 3, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 14.34192276 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 14.34192276, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 7) - << "incorrect value for last_msg_.states[3].prn, expected 7, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 7.85490179062 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 7.85490179062, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 10) - << "incorrect value for last_msg_.states[4].prn, expected 10, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 5.09828662872 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 5.09828662872, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 13) - << "incorrect value for last_msg_.states[5].prn, expected 13, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 6.74127292633 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 6.74127292633, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 22) - << "incorrect value for last_msg_.states[6].prn, expected 22, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 12.7005491257 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 12.7005491257, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 30) - << "incorrect value for last_msg_.states[7].prn, expected 30, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 15.893081665 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 15.893081665, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 31) - << "incorrect value for last_msg_.states[8].prn, expected 31, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - 4.24273872375 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected 4.24273872375, " - "is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 25) - << "incorrect value for last_msg_.states[9].prn, expected 25, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 1) - << "incorrect value for last_msg_.states[9].state, expected 1, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - 6.97599983215 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected " - "6.97599983215, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 6) - << "incorrect value for last_msg_.states[10].prn, expected 6, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 1) - << "incorrect value for last_msg_.states[10].state, expected 1, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA1 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA1() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA1, Test) { - uint8_t encoded_frame[] = { - 85, 22, 0, 195, 4, 66, 1, 0, 216, 57, 48, 65, 1, 2, 145, - 41, 46, 65, 1, 3, 4, 26, 34, 65, 1, 7, 177, 67, 109, 65, - 1, 10, 61, 80, 249, 64, 1, 13, 250, 199, 155, 64, 1, 22, 55, - 19, 215, 64, 1, 30, 138, 138, 79, 65, 1, 31, 214, 179, 119, 65, - 1, 25, 53, 138, 120, 64, 1, 6, 183, 247, 129, 64, 168, 173, - }; +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 11.014122009277344; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 10.885148048400879; - test_msg.states[1].prn = 2; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 10.131351470947266; - test_msg.states[2].prn = 3; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 14.829026222229004; - test_msg.states[3].prn = 7; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 7.79104471206665; - test_msg.states[4].prn = 10; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 4.868161201477051; - test_msg.states[5].prn = 13; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 6.721095561981201; - test_msg.states[6].prn = 22; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 12.971323013305664; - test_msg.states[7].prn = 30; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 15.481405258178711; - test_msg.states[8].prn = 31; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = 3.8834354877471924; - test_msg.states[9].prn = 25; - test_msg.states[9].state = 1; - - test_msg.states[10].cn0 = 4.061488628387451; - test_msg.states[10].prn = 6; - test_msg.states[10].state = 1; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 11.0141220093 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 11.0141220093, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 10.8851480484 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 10.8851480484, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 2) - << "incorrect value for last_msg_.states[1].prn, expected 2, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 10.1313514709 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 10.1313514709, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 3) - << "incorrect value for last_msg_.states[2].prn, expected 3, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 14.8290262222 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 14.8290262222, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 7) - << "incorrect value for last_msg_.states[3].prn, expected 7, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 7.79104471207 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 7.79104471207, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 10) - << "incorrect value for last_msg_.states[4].prn, expected 10, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 4.86816120148 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 4.86816120148, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 13) - << "incorrect value for last_msg_.states[5].prn, expected 13, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 6.72109556198 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 6.72109556198, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 22) - << "incorrect value for last_msg_.states[6].prn, expected 22, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 12.9713230133 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 12.9713230133, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 30) - << "incorrect value for last_msg_.states[7].prn, expected 30, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 15.4814052582 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 15.4814052582, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 31) - << "incorrect value for last_msg_.states[8].prn, expected 31, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - 3.88343548775 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected 3.88343548775, " - "is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 25) - << "incorrect value for last_msg_.states[9].prn, expected 25, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 1) - << "incorrect value for last_msg_.states[9].state, expected 1, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - 4.06148862839 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected " - "4.06148862839, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 6) - << "incorrect value for last_msg_.states[10].prn, expected 6, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 1) - << "incorrect value for last_msg_.states[10].state, expected 1, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA2 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA2() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); } +} - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA2, Test) { - uint8_t encoded_frame[] = { - 85, 22, 0, 195, 4, 66, 1, 0, 141, 76, 60, 65, 1, 2, 69, - 139, 46, 65, 1, 3, 146, 27, 30, 65, 1, 7, 235, 56, 97, 65, - 1, 10, 141, 213, 243, 64, 1, 13, 250, 170, 166, 64, 1, 22, 17, - 101, 201, 64, 1, 30, 172, 183, 83, 65, 1, 31, 238, 193, 120, 65, - 1, 25, 220, 48, 132, 64, 1, 6, 49, 214, 54, 64, 110, 179, - }; + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 11.768689155578613; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 10.909001350402832; - test_msg.states[1].prn = 2; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 9.881731033325195; - test_msg.states[2].prn = 3; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = 14.076395988464355; - test_msg.states[3].prn = 7; - test_msg.states[3].state = 1; - - test_msg.states[4].cn0 = 7.619818210601807; - test_msg.states[4].prn = 10; - test_msg.states[4].state = 1; - - test_msg.states[5].cn0 = 5.208371162414551; - test_msg.states[5].prn = 13; - test_msg.states[5].state = 1; - - test_msg.states[6].cn0 = 6.2935872077941895; - test_msg.states[6].prn = 22; - test_msg.states[6].state = 1; - - test_msg.states[7].cn0 = 13.232341766357422; - test_msg.states[7].prn = 30; - test_msg.states[7].state = 1; - - test_msg.states[8].cn0 = 15.547346115112305; - test_msg.states[8].prn = 31; - test_msg.states[8].state = 1; - - test_msg.states[9].cn0 = 4.130964279174805; - test_msg.states[9].prn = 25; - test_msg.states[9].state = 1; - - test_msg.states[10].cn0 = 2.856823205947876; - test_msg.states[10].prn = 6; - test_msg.states[10].state = 1; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 11.7686891556 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 11.7686891556, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 10.9090013504 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 10.9090013504, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 2) - << "incorrect value for last_msg_.states[1].prn, expected 2, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 9.88173103333 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 9.88173103333, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 3) - << "incorrect value for last_msg_.states[2].prn, expected 3, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - 14.0763959885 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected 14.0763959885, " - "is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 7) - << "incorrect value for last_msg_.states[3].prn, expected 7, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 1) - << "incorrect value for last_msg_.states[3].state, expected 1, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - 7.6198182106 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected 7.6198182106, " - "is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 10) - << "incorrect value for last_msg_.states[4].prn, expected 10, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 1) - << "incorrect value for last_msg_.states[4].state, expected 1, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - 5.20837116241 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected 5.20837116241, " - "is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 13) - << "incorrect value for last_msg_.states[5].prn, expected 13, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 1) - << "incorrect value for last_msg_.states[5].state, expected 1, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - 6.29358720779 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected 6.29358720779, " - "is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 22) - << "incorrect value for last_msg_.states[6].prn, expected 22, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 1) - << "incorrect value for last_msg_.states[6].state, expected 1, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - 13.2323417664 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected 13.2323417664, " - "is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 30) - << "incorrect value for last_msg_.states[7].prn, expected 30, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 1) - << "incorrect value for last_msg_.states[7].state, expected 1, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - 15.5473461151 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected 15.5473461151, " - "is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 31) - << "incorrect value for last_msg_.states[8].prn, expected 31, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 1) - << "incorrect value for last_msg_.states[8].state, expected 1, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - 4.13096427917 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected 4.13096427917, " - "is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 25) - << "incorrect value for last_msg_.states[9].prn, expected 25, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 1) - << "incorrect value for last_msg_.states[9].state, expected 1, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - 2.85682320595 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected " - "2.85682320595, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 6) - << "incorrect value for last_msg_.states[10].prn, expected 6, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 1) - << "incorrect value for last_msg_.states[10].state, expected 1, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA3 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA3() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA3, Test) { - uint8_t encoded_frame[] = { - 85, 22, 0, 195, 4, 66, 1, 0, 55, 143, 120, 66, 0, 0, 0, - 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, - 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 248, 89, - }; +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 62.13985824584961; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = -1.0; - test_msg.states[1].prn = 0; - test_msg.states[1].state = 0; - - test_msg.states[2].cn0 = -1.0; - test_msg.states[2].prn = 0; - test_msg.states[2].state = 0; - - test_msg.states[3].cn0 = -1.0; - test_msg.states[3].prn = 0; - test_msg.states[3].state = 0; - - test_msg.states[4].cn0 = -1.0; - test_msg.states[4].prn = 0; - test_msg.states[4].state = 0; - - test_msg.states[5].cn0 = -1.0; - test_msg.states[5].prn = 0; - test_msg.states[5].state = 0; - - test_msg.states[6].cn0 = -1.0; - test_msg.states[6].prn = 0; - test_msg.states[6].state = 0; - - test_msg.states[7].cn0 = -1.0; - test_msg.states[7].prn = 0; - test_msg.states[7].state = 0; - - test_msg.states[8].cn0 = -1.0; - test_msg.states[8].prn = 0; - test_msg.states[8].state = 0; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].prn = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].prn = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 62.1398582458 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 62.1398582458, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected -1.0, is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 0) - << "incorrect value for last_msg_.states[1].prn, expected 0, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 0) - << "incorrect value for last_msg_.states[1].state, expected 0, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected -1.0, is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 0) - << "incorrect value for last_msg_.states[2].prn, expected 0, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 0) - << "incorrect value for last_msg_.states[2].state, expected 0, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected -1.0, is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 0) - << "incorrect value for last_msg_.states[3].prn, expected 0, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 0) - << "incorrect value for last_msg_.states[3].state, expected 0, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected -1.0, is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 0) - << "incorrect value for last_msg_.states[4].prn, expected 0, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 0) - << "incorrect value for last_msg_.states[4].state, expected 0, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected -1.0, is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 0) - << "incorrect value for last_msg_.states[5].prn, expected 0, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 0) - << "incorrect value for last_msg_.states[5].state, expected 0, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected -1.0, is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 0) - << "incorrect value for last_msg_.states[6].prn, expected 0, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 0) - << "incorrect value for last_msg_.states[6].state, expected 0, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected -1.0, is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 0) - << "incorrect value for last_msg_.states[7].prn, expected 0, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 0) - << "incorrect value for last_msg_.states[7].state, expected 0, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected -1.0, is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 0) - << "incorrect value for last_msg_.states[8].prn, expected 0, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 0) - << "incorrect value for last_msg_.states[8].state, expected 0, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 0) - << "incorrect value for last_msg_.states[9].prn, expected 0, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 0) - << "incorrect value for last_msg_.states[10].prn, expected 0, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA4 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgtrackingStateDepA1 + : public ::testing::Test { public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA4() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_tracking_MsgtrackingStateDepA1() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 11.014122009277344); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 10.885148048400879); + assign(test_msg_.states[1].prn, 2); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 10.131351470947266); + assign(test_msg_.states[2].prn, 3); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 14.829026222229004); + assign(test_msg_.states[3].prn, 7); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 7.79104471206665); + assign(test_msg_.states[4].prn, 10); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 4.868161201477051); + assign(test_msg_.states[5].prn, 13); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 6.721095561981201); + assign(test_msg_.states[6].prn, 22); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 12.971323013305664); + assign(test_msg_.states[7].prn, 30); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 15.481405258178711); + assign(test_msg_.states[8].prn, 31); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, 3.8834354877471924); + assign(test_msg_.states[9].prn, 25); + assign(test_msg_.states[9].state, 1); + + assign(test_msg_.states[10].cn0, 4.061488628387451); + assign(test_msg_.states[10].prn, 6); + assign(test_msg_.states[10].state, 1); } - protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA4, Test) { - uint8_t encoded_frame[] = { - 85, 22, 0, 195, 4, 66, 1, 0, 218, 14, 19, 66, 1, 2, 210, - 3, 21, 65, 1, 3, 234, 214, 134, 65, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, - 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 84, 101, + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; }; - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 36.764503479003906; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 9.313432693481445; - test_msg.states[1].prn = 2; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 16.854938507080078; - test_msg.states[2].prn = 3; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = -1.0; - test_msg.states[3].prn = 0; - test_msg.states[3].state = 0; - - test_msg.states[4].cn0 = -1.0; - test_msg.states[4].prn = 0; - test_msg.states[4].state = 0; - - test_msg.states[5].cn0 = -1.0; - test_msg.states[5].prn = 0; - test_msg.states[5].state = 0; - - test_msg.states[6].cn0 = -1.0; - test_msg.states[6].prn = 0; - test_msg.states[6].state = 0; - - test_msg.states[7].cn0 = -1.0; - test_msg.states[7].prn = 0; - test_msg.states[7].state = 0; - - test_msg.states[8].cn0 = -1.0; - test_msg.states[8].prn = 0; - test_msg.states[8].state = 0; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].prn = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].prn = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 36.764503479 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 36.764503479, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 9.31343269348 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 9.31343269348, " - "is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 2) - << "incorrect value for last_msg_.states[1].prn, expected 2, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 16.8549385071 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 16.8549385071, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 3) - << "incorrect value for last_msg_.states[2].prn, expected 3, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected -1.0, is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 0) - << "incorrect value for last_msg_.states[3].prn, expected 0, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 0) - << "incorrect value for last_msg_.states[3].state, expected 0, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected -1.0, is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 0) - << "incorrect value for last_msg_.states[4].prn, expected 0, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 0) - << "incorrect value for last_msg_.states[4].state, expected 0, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected -1.0, is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 0) - << "incorrect value for last_msg_.states[5].prn, expected 0, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 0) - << "incorrect value for last_msg_.states[5].state, expected 0, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected -1.0, is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 0) - << "incorrect value for last_msg_.states[6].prn, expected 0, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 0) - << "incorrect value for last_msg_.states[6].state, expected 0, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected -1.0, is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 0) - << "incorrect value for last_msg_.states[7].prn, expected 0, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 0) - << "incorrect value for last_msg_.states[7].state, expected 0, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected -1.0, is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 0) - << "incorrect value for last_msg_.states[8].prn, expected 0, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 0) - << "incorrect value for last_msg_.states[8].state, expected 0, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 0) - << "incorrect value for last_msg_.states[9].prn, expected 0, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 0) - << "incorrect value for last_msg_.states[10].prn, expected 0, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; -} -class Test_auto_check_sbp_tracking_MsgtrackingStateDepA5 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { - public: - Test_auto_check_sbp_tracking_MsgtrackingStateDepA5() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xada8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_tracking_state_dep_a_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_tracking_state_dep_a_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } -TEST_F(Test_auto_check_sbp_tracking_MsgtrackingStateDepA5, Test) { - uint8_t encoded_frame[] = { - 85, 22, 0, 195, 4, 66, 1, 0, 98, 39, 219, 65, 1, 2, 0, - 0, 56, 64, 1, 3, 121, 123, 7, 65, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, - 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 37, 123, - }; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } - sbp_msg_tracking_state_dep_a_t test_msg{}; - test_msg.n_states = 11; - - test_msg.states[0].cn0 = 27.394229888916016; - test_msg.states[0].prn = 0; - test_msg.states[0].state = 1; - - test_msg.states[1].cn0 = 2.875; - test_msg.states[1].prn = 2; - test_msg.states[1].state = 1; - - test_msg.states[2].cn0 = 8.467644691467285; - test_msg.states[2].prn = 3; - test_msg.states[2].state = 1; - - test_msg.states[3].cn0 = -1.0; - test_msg.states[3].prn = 0; - test_msg.states[3].state = 0; - - test_msg.states[4].cn0 = -1.0; - test_msg.states[4].prn = 0; - test_msg.states[4].state = 0; - - test_msg.states[5].cn0 = -1.0; - test_msg.states[5].prn = 0; - test_msg.states[5].state = 0; - - test_msg.states[6].cn0 = -1.0; - test_msg.states[6].prn = 0; - test_msg.states[6].state = 0; - - test_msg.states[7].cn0 = -1.0; - test_msg.states[7].prn = 0; - test_msg.states[7].state = 0; - - test_msg.states[8].cn0 = -1.0; - test_msg.states[8].prn = 0; - test_msg.states[8].state = 0; - - test_msg.states[9].cn0 = -1.0; - test_msg.states[9].prn = 0; - test_msg.states[9].state = 0; - - test_msg.states[10].cn0 = -1.0; - test_msg.states[10].prn = 0; - test_msg.states[10].state = 0; - - EXPECT_EQ(send_message(1219, test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); - } - - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 1219); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.n_states, 11) - << "incorrect value for last_msg_.n_states, expected 11, is " - << last_msg_.n_states; - EXPECT_LT((last_msg_.states[0].cn0 * 100 - 27.3942298889 * 100), 0.05) - << "incorrect value for last_msg_.states[0].cn0, expected 27.3942298889, " - "is " - << last_msg_.states[0].cn0; - EXPECT_EQ(last_msg_.states[0].prn, 0) - << "incorrect value for last_msg_.states[0].prn, expected 0, is " - << last_msg_.states[0].prn; - EXPECT_EQ(last_msg_.states[0].state, 1) - << "incorrect value for last_msg_.states[0].state, expected 1, is " - << last_msg_.states[0].state; - EXPECT_LT((last_msg_.states[1].cn0 * 100 - 2.875 * 100), 0.05) - << "incorrect value for last_msg_.states[1].cn0, expected 2.875, is " - << last_msg_.states[1].cn0; - EXPECT_EQ(last_msg_.states[1].prn, 2) - << "incorrect value for last_msg_.states[1].prn, expected 2, is " - << last_msg_.states[1].prn; - EXPECT_EQ(last_msg_.states[1].state, 1) - << "incorrect value for last_msg_.states[1].state, expected 1, is " - << last_msg_.states[1].state; - EXPECT_LT((last_msg_.states[2].cn0 * 100 - 8.46764469147 * 100), 0.05) - << "incorrect value for last_msg_.states[2].cn0, expected 8.46764469147, " - "is " - << last_msg_.states[2].cn0; - EXPECT_EQ(last_msg_.states[2].prn, 3) - << "incorrect value for last_msg_.states[2].prn, expected 3, is " - << last_msg_.states[2].prn; - EXPECT_EQ(last_msg_.states[2].state, 1) - << "incorrect value for last_msg_.states[2].state, expected 1, is " - << last_msg_.states[2].state; - EXPECT_LT((last_msg_.states[3].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[3].cn0, expected -1.0, is " - << last_msg_.states[3].cn0; - EXPECT_EQ(last_msg_.states[3].prn, 0) - << "incorrect value for last_msg_.states[3].prn, expected 0, is " - << last_msg_.states[3].prn; - EXPECT_EQ(last_msg_.states[3].state, 0) - << "incorrect value for last_msg_.states[3].state, expected 0, is " - << last_msg_.states[3].state; - EXPECT_LT((last_msg_.states[4].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[4].cn0, expected -1.0, is " - << last_msg_.states[4].cn0; - EXPECT_EQ(last_msg_.states[4].prn, 0) - << "incorrect value for last_msg_.states[4].prn, expected 0, is " - << last_msg_.states[4].prn; - EXPECT_EQ(last_msg_.states[4].state, 0) - << "incorrect value for last_msg_.states[4].state, expected 0, is " - << last_msg_.states[4].state; - EXPECT_LT((last_msg_.states[5].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[5].cn0, expected -1.0, is " - << last_msg_.states[5].cn0; - EXPECT_EQ(last_msg_.states[5].prn, 0) - << "incorrect value for last_msg_.states[5].prn, expected 0, is " - << last_msg_.states[5].prn; - EXPECT_EQ(last_msg_.states[5].state, 0) - << "incorrect value for last_msg_.states[5].state, expected 0, is " - << last_msg_.states[5].state; - EXPECT_LT((last_msg_.states[6].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[6].cn0, expected -1.0, is " - << last_msg_.states[6].cn0; - EXPECT_EQ(last_msg_.states[6].prn, 0) - << "incorrect value for last_msg_.states[6].prn, expected 0, is " - << last_msg_.states[6].prn; - EXPECT_EQ(last_msg_.states[6].state, 0) - << "incorrect value for last_msg_.states[6].state, expected 0, is " - << last_msg_.states[6].state; - EXPECT_LT((last_msg_.states[7].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[7].cn0, expected -1.0, is " - << last_msg_.states[7].cn0; - EXPECT_EQ(last_msg_.states[7].prn, 0) - << "incorrect value for last_msg_.states[7].prn, expected 0, is " - << last_msg_.states[7].prn; - EXPECT_EQ(last_msg_.states[7].state, 0) - << "incorrect value for last_msg_.states[7].state, expected 0, is " - << last_msg_.states[7].state; - EXPECT_LT((last_msg_.states[8].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[8].cn0, expected -1.0, is " - << last_msg_.states[8].cn0; - EXPECT_EQ(last_msg_.states[8].prn, 0) - << "incorrect value for last_msg_.states[8].prn, expected 0, is " - << last_msg_.states[8].prn; - EXPECT_EQ(last_msg_.states[8].state, 0) - << "incorrect value for last_msg_.states[8].state, expected 0, is " - << last_msg_.states[8].state; - EXPECT_LT((last_msg_.states[9].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[9].cn0, expected -1.0, is " - << last_msg_.states[9].cn0; - EXPECT_EQ(last_msg_.states[9].prn, 0) - << "incorrect value for last_msg_.states[9].prn, expected 0, is " - << last_msg_.states[9].prn; - EXPECT_EQ(last_msg_.states[9].state, 0) - << "incorrect value for last_msg_.states[9].state, expected 0, is " - << last_msg_.states[9].state; - EXPECT_LT((last_msg_.states[10].cn0 * 100 - -1.0 * 100), 0.05) - << "incorrect value for last_msg_.states[10].cn0, expected -1.0, is " - << last_msg_.states[10].cn0; - EXPECT_EQ(last_msg_.states[10].prn, 0) - << "incorrect value for last_msg_.states[10].prn, expected 0, is " - << last_msg_.states[10].prn; - EXPECT_EQ(last_msg_.states[10].state, 0) - << "incorrect value for last_msg_.states[10].state, expected 0, is " - << last_msg_.states[10].state; + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 22, 0, 195, 4, 66, 1, 0, 216, 57, 48, 65, 1, 2, 145, + 41, 46, 65, 1, 3, 4, 26, 34, 65, 1, 7, 177, 67, 109, 65, + 1, 10, 61, 80, 249, 64, 1, 13, 250, 199, 155, 64, 1, 22, 55, + 19, 215, 64, 1, 30, 138, 138, 79, 65, 1, 31, 214, 179, 119, 65, + 1, 25, 53, 138, 120, 64, 1, 6, 183, 247, 129, 64, 168, 173, + }; + uint8_t encoded_payload_[66] = { + 1, 0, 216, 57, 48, 65, 1, 2, 145, 41, 46, 65, 1, 3, + 4, 26, 34, 65, 1, 7, 177, 67, 109, 65, 1, 10, 61, 80, + 249, 64, 1, 13, 250, 199, 155, 64, 1, 22, 55, 19, 215, 64, + 1, 30, 138, 138, 79, 65, 1, 31, 214, 179, 119, 65, 1, 25, + 53, 138, 120, 64, 1, 6, 183, 247, 129, 64, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA1, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgtrackingStateDepA2 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgtrackingStateDepA2() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 11.768689155578613); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 10.909001350402832); + assign(test_msg_.states[1].prn, 2); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 9.881731033325195); + assign(test_msg_.states[2].prn, 3); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, 14.076395988464355); + assign(test_msg_.states[3].prn, 7); + assign(test_msg_.states[3].state, 1); + + assign(test_msg_.states[4].cn0, 7.619818210601807); + assign(test_msg_.states[4].prn, 10); + assign(test_msg_.states[4].state, 1); + + assign(test_msg_.states[5].cn0, 5.208371162414551); + assign(test_msg_.states[5].prn, 13); + assign(test_msg_.states[5].state, 1); + + assign(test_msg_.states[6].cn0, 6.2935872077941895); + assign(test_msg_.states[6].prn, 22); + assign(test_msg_.states[6].state, 1); + + assign(test_msg_.states[7].cn0, 13.232341766357422); + assign(test_msg_.states[7].prn, 30); + assign(test_msg_.states[7].state, 1); + + assign(test_msg_.states[8].cn0, 15.547346115112305); + assign(test_msg_.states[8].prn, 31); + assign(test_msg_.states[8].state, 1); + + assign(test_msg_.states[9].cn0, 4.130964279174805); + assign(test_msg_.states[9].prn, 25); + assign(test_msg_.states[9].state, 1); + + assign(test_msg_.states[10].cn0, 2.856823205947876); + assign(test_msg_.states[10].prn, 6); + assign(test_msg_.states[10].state, 1); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0xb36e; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 22, 0, 195, 4, 66, 1, 0, 141, 76, 60, 65, 1, 2, 69, + 139, 46, 65, 1, 3, 146, 27, 30, 65, 1, 7, 235, 56, 97, 65, + 1, 10, 141, 213, 243, 64, 1, 13, 250, 170, 166, 64, 1, 22, 17, + 101, 201, 64, 1, 30, 172, 183, 83, 65, 1, 31, 238, 193, 120, 65, + 1, 25, 220, 48, 132, 64, 1, 6, 49, 214, 54, 64, 110, 179, + }; + uint8_t encoded_payload_[66] = { + 1, 0, 141, 76, 60, 65, 1, 2, 69, 139, 46, 65, 1, 3, + 146, 27, 30, 65, 1, 7, 235, 56, 97, 65, 1, 10, 141, 213, + 243, 64, 1, 13, 250, 170, 166, 64, 1, 22, 17, 101, 201, 64, + 1, 30, 172, 183, 83, 65, 1, 31, 238, 193, 120, 65, 1, 25, + 220, 48, 132, 64, 1, 6, 49, 214, 54, 64, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA2, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgtrackingStateDepA3 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgtrackingStateDepA3() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 62.13985824584961); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, -1.0); + assign(test_msg_.states[1].prn, 0); + assign(test_msg_.states[1].state, 0); + + assign(test_msg_.states[2].cn0, -1.0); + assign(test_msg_.states[2].prn, 0); + assign(test_msg_.states[2].state, 0); + + assign(test_msg_.states[3].cn0, -1.0); + assign(test_msg_.states[3].prn, 0); + assign(test_msg_.states[3].state, 0); + + assign(test_msg_.states[4].cn0, -1.0); + assign(test_msg_.states[4].prn, 0); + assign(test_msg_.states[4].state, 0); + + assign(test_msg_.states[5].cn0, -1.0); + assign(test_msg_.states[5].prn, 0); + assign(test_msg_.states[5].state, 0); + + assign(test_msg_.states[6].cn0, -1.0); + assign(test_msg_.states[6].prn, 0); + assign(test_msg_.states[6].state, 0); + + assign(test_msg_.states[7].cn0, -1.0); + assign(test_msg_.states[7].prn, 0); + assign(test_msg_.states[7].state, 0); + + assign(test_msg_.states[8].cn0, -1.0); + assign(test_msg_.states[8].prn, 0); + assign(test_msg_.states[8].state, 0); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].prn, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].prn, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x59f8; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 22, 0, 195, 4, 66, 1, 0, 55, 143, 120, 66, 0, 0, 0, + 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, + 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 248, 89, + }; + uint8_t encoded_payload_[66] = { + 1, 0, 55, 143, 120, 66, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA3, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgtrackingStateDepA4 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgtrackingStateDepA4() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 36.764503479003906); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 9.313432693481445); + assign(test_msg_.states[1].prn, 2); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 16.854938507080078); + assign(test_msg_.states[2].prn, 3); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, -1.0); + assign(test_msg_.states[3].prn, 0); + assign(test_msg_.states[3].state, 0); + + assign(test_msg_.states[4].cn0, -1.0); + assign(test_msg_.states[4].prn, 0); + assign(test_msg_.states[4].state, 0); + + assign(test_msg_.states[5].cn0, -1.0); + assign(test_msg_.states[5].prn, 0); + assign(test_msg_.states[5].state, 0); + + assign(test_msg_.states[6].cn0, -1.0); + assign(test_msg_.states[6].prn, 0); + assign(test_msg_.states[6].state, 0); + + assign(test_msg_.states[7].cn0, -1.0); + assign(test_msg_.states[7].prn, 0); + assign(test_msg_.states[7].state, 0); + + assign(test_msg_.states[8].cn0, -1.0); + assign(test_msg_.states[8].prn, 0); + assign(test_msg_.states[8].state, 0); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].prn, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].prn, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x6554; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 22, 0, 195, 4, 66, 1, 0, 218, 14, 19, 66, 1, 2, 210, + 3, 21, 65, 1, 3, 234, 214, 134, 65, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, + 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 84, 101, + }; + uint8_t encoded_payload_[66] = { + 1, 0, 218, 14, 19, 66, 1, 2, 210, 3, 21, 65, 1, 3, 234, 214, 134, 65, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA4, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +class Testauto_check_sbp_tracking_MsgtrackingStateDepA5 + : public ::testing::Test { + public: + Testauto_check_sbp_tracking_MsgtrackingStateDepA5() { + assign(test_msg_.n_states, 11); + + assign(test_msg_.states[0].cn0, 27.394229888916016); + assign(test_msg_.states[0].prn, 0); + assign(test_msg_.states[0].state, 1); + + assign(test_msg_.states[1].cn0, 2.875); + assign(test_msg_.states[1].prn, 2); + assign(test_msg_.states[1].state, 1); + + assign(test_msg_.states[2].cn0, 8.467644691467285); + assign(test_msg_.states[2].prn, 3); + assign(test_msg_.states[2].state, 1); + + assign(test_msg_.states[3].cn0, -1.0); + assign(test_msg_.states[3].prn, 0); + assign(test_msg_.states[3].state, 0); + + assign(test_msg_.states[4].cn0, -1.0); + assign(test_msg_.states[4].prn, 0); + assign(test_msg_.states[4].state, 0); + + assign(test_msg_.states[5].cn0, -1.0); + assign(test_msg_.states[5].prn, 0); + assign(test_msg_.states[5].state, 0); + + assign(test_msg_.states[6].cn0, -1.0); + assign(test_msg_.states[6].prn, 0); + assign(test_msg_.states[6].state, 0); + + assign(test_msg_.states[7].cn0, -1.0); + assign(test_msg_.states[7].prn, 0); + assign(test_msg_.states[7].state, 0); + + assign(test_msg_.states[8].cn0, -1.0); + assign(test_msg_.states[8].prn, 0); + assign(test_msg_.states[8].state, 0); + + assign(test_msg_.states[9].cn0, -1.0); + assign(test_msg_.states[9].prn, 0); + assign(test_msg_.states[9].state, 0); + + assign(test_msg_.states[10].cn0, -1.0); + assign(test_msg_.states[10].prn, 0); + assign(test_msg_.states[10].state, 0); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final + : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_tracking_state_dep_a_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgTrackingStateDepA, + &CHandler::callback_static, this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_tracking_state_dep_a_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgTrackingStateDepA); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->tracking_state_dep_a, + sizeof(msg->tracking_state_dep_a)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_tracking_state_dep_a_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.tracking_state_dep_a, &test_msg_, + sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgTrackingStateDepA); + info.sender_id = 1219; + info.preamble = 0x55; + info.crc = 0x7b25; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 66; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_tracking_state_dep_a_t &lesser, + const sbp_msg_tracking_state_dep_a_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_tracking_state_dep_a_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_tracking_state_dep_a_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_lesser, + &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp(SbpMsgTrackingStateDepA, &wrapped_greater, + &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_tracking_state_dep_a_t test_msg_{}; + uint8_t encoded_frame_[66 + 8] = { + 85, 22, 0, 195, 4, 66, 1, 0, 98, 39, 219, 65, 1, 2, 0, + 0, 56, 64, 1, 3, 121, 123, 7, 65, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, + 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 37, 123, + }; + uint8_t encoded_payload_[66] = { + 1, 0, 98, 39, 219, 65, 1, 2, 0, 0, 56, 64, 1, 3, 121, 123, 7, 65, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 128, 191, + }; +}; + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encoded_len(&info.test_msg), + info.payload_len); + + EXPECT_EQ( + sbp_message_encoded_len(SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), + &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgTrackingStateDepA, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], sizeof(buf), nullptr, + &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + + for (uint8_t i = 0; i < 66; i++) { + EXPECT_EQ(sbp_msg_tracking_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgTrackingStateDepA, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode( + &info.encoded_payload[0], info.payload_len, nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_tracking_state_dep_a_t t{}; + t.n_states = 1; + return sbp_msg_tracking_state_dep_a_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_decode(&info.encoded_payload[0], i, + nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_tracking_state_dep_a_send(&state, info.sender_id, + &info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgTrackingStateDepA, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.n_states, greater.n_states); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].cn0, greater.states[0].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].prn, greater.states[0].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[0].state, greater.states[0].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].cn0, greater.states[1].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].prn, greater.states[1].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[1].state, greater.states[1].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].cn0, greater.states[2].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].prn, greater.states[2].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[2].state, greater.states[2].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].cn0, greater.states[3].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].prn, greater.states[3].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[3].state, greater.states[3].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].cn0, greater.states[4].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].prn, greater.states[4].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[4].state, greater.states[4].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].cn0, greater.states[5].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].prn, greater.states[5].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[5].state, greater.states[5].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].cn0, greater.states[6].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].prn, greater.states[6].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[6].state, greater.states[6].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].cn0, greater.states[7].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].prn, greater.states[7].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[7].state, greater.states[7].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].cn0, greater.states[8].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].prn, greater.states[8].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[8].state, greater.states[8].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].cn0, greater.states[9].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].prn, greater.states[9].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[9].state, greater.states[9].state); + comparison_tests(lesser, greater); + } + + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].cn0, greater.states[10].cn0); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].prn, greater.states[10].prn); + comparison_tests(lesser, greater); + } + { + sbp_msg_tracking_state_dep_a_t lesser = info.test_msg; + sbp_msg_tracking_state_dep_a_t greater = info.test_msg; + make_lesser_greater(lesser.states[10].state, greater.states[10].state); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, + // SbpMsgTrackingStateDepA); + EXPECT_STREQ(sbp::MessageTraits::name, + "MSG_TRACKING_STATE_DEP_A"); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_tracking_state_dep_a_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_tracking_state_dep_a_t &non_const_unwrapped = + sbp::MessageTraits::get( + non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg( + info.test_msg); + EXPECT_EQ(msg1.tracking_state_dep_a, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, + &msg2); + EXPECT_EQ(msg2.tracking_state_dep_a, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len( + info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[66]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 66); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 66), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_tracking_state_dep_a_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 66); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgTrackingStateDepA, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_tracking_MsgtrackingStateDepA5, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgTrackingStateDepA, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_tracking_tracking_structs.cc b/c/test/cpp/auto_check_sbp_tracking_tracking_structs.cc new file mode 100644 index 0000000000..aea18554ee --- /dev/null +++ b/c/test/cpp/auto_check_sbp_tracking_tracking_structs.cc @@ -0,0 +1,635 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_tracking_structs.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs0 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs0() { + assign(test_struct_.cn0, 45); + assign(test_struct_.fcn, 10); + assign(test_struct_.sid.code, 0); + assign(test_struct_.sid.sat, 22); + } + + struct TestStructInfo { + sbp_tracking_channel_state_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tracking_channel_state_t test_struct_{}; + uint8_t encoded_data_[4] = { + 22, + 0, + 10, + 45, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tracking_channel_state_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_tracking_channel_state_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_tracking_channel_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_tracking_channel_state_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tracking_channel_state_t t{}; + EXPECT_EQ(sbp_tracking_channel_state_decode(info.encoded_data, 4, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tracking_channel_state_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_t t{}; + EXPECT_EQ( + sbp_tracking_channel_state_decode(info.encoded_data, 4, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tracking_channel_state_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs0, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ( + sbp_tracking_channel_state_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs1 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs1() { + assign(test_struct_.cn0, 30); + assign(test_struct_.mesid.code, 1); + assign(test_struct_.mesid.sat, 23); + } + + struct TestStructInfo { + sbp_measurement_state_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_measurement_state_t test_struct_{}; + uint8_t encoded_data_[3] = { + 23, + 1, + 30, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_measurement_state_encoded_len(&info.test_struct), 3); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[3]; + EXPECT_EQ(sbp_measurement_state_encode(&buf[0], sizeof(buf), &nwritten, + &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 3); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + EXPECT_EQ(sbp_measurement_state_encode(&buf[0], sizeof(buf), nullptr, + &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 3), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[3]; + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ( + sbp_measurement_state_encode(&buf[0], i, nullptr, &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_measurement_state_t t{}; + EXPECT_EQ(sbp_measurement_state_decode(info.encoded_data, 3, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_measurement_state_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_measurement_state_t t{}; + EXPECT_EQ(sbp_measurement_state_decode(info.encoded_data, 3, nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_measurement_state_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs1, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_measurement_state_t t{}; + + for (uint8_t i = 0; i < 3; i++) { + EXPECT_EQ(sbp_measurement_state_decode(info.encoded_data, i, nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs2 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs2() { + assign(test_struct_.I, 37341); + assign(test_struct_.Q, 8818); + } + + struct TestStructInfo { + sbp_tracking_channel_correlation_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tracking_channel_correlation_t test_struct_{}; + uint8_t encoded_data_[4] = { + 221, + 145, + 114, + 34, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tracking_channel_correlation_encoded_len(&info.test_struct), 4); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[4]; + EXPECT_EQ(sbp_tracking_channel_correlation_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 4); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + EXPECT_EQ(sbp_tracking_channel_correlation_encode(&buf[0], sizeof(buf), + nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 4), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[4]; + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_tracking_channel_correlation_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tracking_channel_correlation_t t{}; + EXPECT_EQ( + sbp_tracking_channel_correlation_decode(info.encoded_data, 4, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tracking_channel_correlation_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tracking_channel_correlation_t t{}; + EXPECT_EQ(sbp_tracking_channel_correlation_decode(info.encoded_data, 4, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tracking_channel_correlation_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs2, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tracking_channel_correlation_t t{}; + + for (uint8_t i = 0; i < 4; i++) { + EXPECT_EQ(sbp_tracking_channel_correlation_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs3 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs3() { + assign(test_struct_.I, 6871523); + assign(test_struct_.Q, 817264192); + } + + struct TestStructInfo { + sbp_tracking_channel_correlation_dep_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tracking_channel_correlation_dep_t test_struct_{}; + uint8_t encoded_data_[8] = { + 227, 217, 104, 0, 64, 118, 182, 48, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tracking_channel_correlation_dep_encoded_len(&info.test_struct), + 8); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[8]; + EXPECT_EQ(sbp_tracking_channel_correlation_dep_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 8); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + EXPECT_EQ(sbp_tracking_channel_correlation_dep_encode( + &buf[0], sizeof(buf), nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 8), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[8]; + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_tracking_channel_correlation_dep_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tracking_channel_correlation_dep_t t{}; + EXPECT_EQ(sbp_tracking_channel_correlation_dep_decode(info.encoded_data, 8, + &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tracking_channel_correlation_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tracking_channel_correlation_dep_t t{}; + EXPECT_EQ(sbp_tracking_channel_correlation_dep_decode(info.encoded_data, 8, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tracking_channel_correlation_dep_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs3, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tracking_channel_correlation_dep_t t{}; + + for (uint8_t i = 0; i < 8; i++) { + EXPECT_EQ(sbp_tracking_channel_correlation_dep_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs4 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs4() { + assign(test_struct_.cn0, 2961.199951); + assign(test_struct_.prn, 195); + assign(test_struct_.state, 19); + } + + struct TestStructInfo { + sbp_tracking_channel_state_dep_a_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tracking_channel_state_dep_a_t test_struct_{}; + uint8_t encoded_data_[6] = { + 19, 195, 51, 19, 57, 69, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tracking_channel_state_dep_a_encoded_len(&info.test_struct), 6); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[6]; + EXPECT_EQ(sbp_tracking_channel_state_dep_a_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 6); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + EXPECT_EQ(sbp_tracking_channel_state_dep_a_encode(&buf[0], sizeof(buf), + nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 6), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[6]; + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_tracking_channel_state_dep_a_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tracking_channel_state_dep_a_t t{}; + EXPECT_EQ( + sbp_tracking_channel_state_dep_a_decode(info.encoded_data, 6, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tracking_channel_state_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_dep_a_t t{}; + EXPECT_EQ(sbp_tracking_channel_state_dep_a_decode(info.encoded_data, 6, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tracking_channel_state_dep_a_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs4, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_dep_a_t t{}; + + for (uint8_t i = 0; i < 6; i++) { + EXPECT_EQ(sbp_tracking_channel_state_dep_a_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +class Test_Struct_auto_check_sbp_tracking_tracking_structs5 + : public ::testing::Test { + public: + Test_Struct_auto_check_sbp_tracking_tracking_structs5() { + assign(test_struct_.cn0, 2357.199951); + assign(test_struct_.sid.code, 236); + assign(test_struct_.sid.sat, 3011); + assign(test_struct_.state, 118); + } + + struct TestStructInfo { + sbp_tracking_channel_state_dep_b_t test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + sbp_tracking_channel_state_dep_b_t test_struct_{}; + uint8_t encoded_data_[9] = { + 118, 195, 11, 236, 0, 51, 83, 19, 69, + }; +}; + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ(sbp_tracking_channel_state_dep_b_encoded_len(&info.test_struct), 9); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[9]; + EXPECT_EQ(sbp_tracking_channel_state_dep_b_encode( + &buf[0], sizeof(buf), &nwritten, &info.test_struct), + SBP_OK); + EXPECT_EQ(nwritten, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, + FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + EXPECT_EQ(sbp_tracking_channel_state_dep_b_encode(&buf[0], sizeof(buf), + nullptr, &info.test_struct), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, 9), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, + FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[9]; + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_tracking_channel_state_dep_b_encode(&buf[0], i, nullptr, + &info.test_struct), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + sbp_tracking_channel_state_dep_b_t t{}; + EXPECT_EQ( + sbp_tracking_channel_state_dep_b_decode(info.encoded_data, 9, &nread, &t), + SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ(sbp_tracking_channel_state_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, + FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_dep_b_t t{}; + EXPECT_EQ(sbp_tracking_channel_state_dep_b_decode(info.encoded_data, 9, + nullptr, &t), + SBP_OK); + EXPECT_EQ(sbp_tracking_channel_state_dep_b_cmp(&t, &info.test_struct), 0); +} + +TEST_F(Test_Struct_auto_check_sbp_tracking_tracking_structs5, + FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + sbp_tracking_channel_state_dep_b_t t{}; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_tracking_channel_state_dep_b_decode(info.encoded_data, i, + nullptr, &t), + SBP_DECODE_ERROR); + } +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_user_MsgUserData.cc b/c/test/cpp/auto_check_sbp_user_MsgUserData.cc new file mode 100644 index 0000000000..635eca2eb5 --- /dev/null +++ b/c/test/cpp/auto_check_sbp_user_MsgUserData.cc @@ -0,0 +1,3102 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_user_MsgUserData0 : public ::testing::Test { + public: + Testauto_check_sbp_user_MsgUserData0() { + assign(test_msg_.contents[0], 53); + + assign(test_msg_.contents[1], 5); + + assign(test_msg_.contents[2], 172); + + assign(test_msg_.contents[3], 138); + + assign(test_msg_.contents[4], 50); + + assign(test_msg_.contents[5], 49); + + assign(test_msg_.contents[6], 206); + + assign(test_msg_.contents[7], 234); + + assign(test_msg_.contents[8], 149); + + assign(test_msg_.contents[9], 204); + + assign(test_msg_.contents[10], 113); + + assign(test_msg_.contents[11], 31); + + assign(test_msg_.contents[12], 108); + + assign(test_msg_.contents[13], 188); + + assign(test_msg_.contents[14], 179); + + assign(test_msg_.contents[15], 154); + + assign(test_msg_.contents[16], 156); + + assign(test_msg_.contents[17], 167); + + assign(test_msg_.contents[18], 145); + + assign(test_msg_.contents[19], 139); + + assign(test_msg_.contents[20], 42); + + assign(test_msg_.contents[21], 207); + + assign(test_msg_.contents[22], 126); + + assign(test_msg_.contents[23], 242); + + assign(test_msg_.contents[24], 193); + + assign(test_msg_.contents[25], 9); + + assign(test_msg_.contents[26], 58); + + assign(test_msg_.contents[27], 75); + + assign(test_msg_.contents[28], 8); + + assign(test_msg_.contents[29], 135); + + assign(test_msg_.contents[30], 11); + + assign(test_msg_.contents[31], 92); + + assign(test_msg_.contents[32], 131); + + assign(test_msg_.contents[33], 245); + + assign(test_msg_.contents[34], 24); + + assign(test_msg_.contents[35], 90); + + assign(test_msg_.contents[36], 255); + + assign(test_msg_.contents[37], 30); + + assign(test_msg_.contents[38], 58); + + assign(test_msg_.contents[39], 31); + + assign(test_msg_.contents[40], 109); + + assign(test_msg_.contents[41], 148); + + assign(test_msg_.contents[42], 56); + + assign(test_msg_.contents[43], 178); + + assign(test_msg_.contents[44], 140); + + assign(test_msg_.contents[45], 30); + + assign(test_msg_.contents[46], 159); + + assign(test_msg_.contents[47], 70); + + assign(test_msg_.contents[48], 17); + + assign(test_msg_.contents[49], 170); + + assign(test_msg_.contents[50], 50); + + assign(test_msg_.contents[51], 148); + + assign(test_msg_.contents[52], 1); + + assign(test_msg_.contents[53], 99); + + assign(test_msg_.contents[54], 112); + + assign(test_msg_.contents[55], 88); + + assign(test_msg_.contents[56], 217); + + assign(test_msg_.contents[57], 36); + + assign(test_msg_.contents[58], 84); + + assign(test_msg_.contents[59], 34); + + assign(test_msg_.contents[60], 234); + + assign(test_msg_.contents[61], 82); + + assign(test_msg_.contents[62], 144); + + assign(test_msg_.contents[63], 144); + + assign(test_msg_.contents[64], 97); + + assign(test_msg_.contents[65], 96); + + assign(test_msg_.contents[66], 75); + + assign(test_msg_.contents[67], 174); + + assign(test_msg_.contents[68], 58); + + assign(test_msg_.contents[69], 219); + + assign(test_msg_.contents[70], 180); + + assign(test_msg_.contents[71], 148); + + assign(test_msg_.contents[72], 247); + + assign(test_msg_.contents[73], 59); + + assign(test_msg_.contents[74], 2); + + assign(test_msg_.contents[75], 116); + + assign(test_msg_.contents[76], 214); + + assign(test_msg_.contents[77], 114); + + assign(test_msg_.contents[78], 55); + + assign(test_msg_.contents[79], 134); + + assign(test_msg_.contents[80], 54); + + assign(test_msg_.contents[81], 119); + + assign(test_msg_.contents[82], 108); + + assign(test_msg_.contents[83], 128); + + assign(test_msg_.contents[84], 73); + + assign(test_msg_.contents[85], 181); + + assign(test_msg_.contents[86], 20); + + assign(test_msg_.contents[87], 233); + + assign(test_msg_.contents[88], 23); + + assign(test_msg_.contents[89], 23); + + assign(test_msg_.contents[90], 73); + + assign(test_msg_.contents[91], 119); + + assign(test_msg_.contents[92], 136); + + assign(test_msg_.contents[93], 231); + + assign(test_msg_.contents[94], 189); + + assign(test_msg_.contents[95], 26); + + assign(test_msg_.contents[96], 174); + + assign(test_msg_.contents[97], 128); + + assign(test_msg_.contents[98], 93); + + assign(test_msg_.contents[99], 30); + + assign(test_msg_.contents[100], 76); + + assign(test_msg_.contents[101], 45); + + assign(test_msg_.contents[102], 109); + + assign(test_msg_.contents[103], 134); + + assign(test_msg_.contents[104], 81); + + assign(test_msg_.contents[105], 0); + + assign(test_msg_.contents[106], 116); + + assign(test_msg_.contents[107], 158); + + assign(test_msg_.contents[108], 127); + + assign(test_msg_.contents[109], 40); + + assign(test_msg_.contents[110], 133); + + assign(test_msg_.contents[111], 208); + + assign(test_msg_.contents[112], 134); + + assign(test_msg_.contents[113], 127); + + assign(test_msg_.contents[114], 140); + + assign(test_msg_.contents[115], 232); + + assign(test_msg_.contents[116], 183); + + assign(test_msg_.contents[117], 184); + + assign(test_msg_.contents[118], 108); + + assign(test_msg_.contents[119], 6); + + assign(test_msg_.contents[120], 228); + + assign(test_msg_.contents[121], 54); + + assign(test_msg_.contents[122], 238); + + assign(test_msg_.contents[123], 59); + + assign(test_msg_.contents[124], 220); + + assign(test_msg_.contents[125], 30); + + assign(test_msg_.contents[126], 228); + + assign(test_msg_.contents[127], 212); + + assign(test_msg_.contents[128], 50); + + assign(test_msg_.contents[129], 182); + + assign(test_msg_.contents[130], 97); + + assign(test_msg_.contents[131], 20); + + assign(test_msg_.contents[132], 41); + + assign(test_msg_.contents[133], 76); + + assign(test_msg_.contents[134], 227); + + assign(test_msg_.contents[135], 88); + + assign(test_msg_.contents[136], 12); + + assign(test_msg_.contents[137], 95); + + assign(test_msg_.contents[138], 112); + + assign(test_msg_.contents[139], 209); + + assign(test_msg_.contents[140], 183); + + assign(test_msg_.contents[141], 127); + + assign(test_msg_.contents[142], 4); + + assign(test_msg_.contents[143], 165); + + assign(test_msg_.contents[144], 189); + + assign(test_msg_.contents[145], 44); + + assign(test_msg_.contents[146], 239); + + assign(test_msg_.contents[147], 232); + + assign(test_msg_.contents[148], 132); + + assign(test_msg_.contents[149], 9); + + assign(test_msg_.contents[150], 114); + + assign(test_msg_.contents[151], 184); + + assign(test_msg_.contents[152], 249); + + assign(test_msg_.contents[153], 208); + + assign(test_msg_.contents[154], 246); + + assign(test_msg_.contents[155], 194); + + assign(test_msg_.contents[156], 250); + + assign(test_msg_.contents[157], 2); + + assign(test_msg_.contents[158], 97); + + assign(test_msg_.contents[159], 173); + + assign(test_msg_.contents[160], 157); + + assign(test_msg_.contents[161], 202); + + assign(test_msg_.contents[162], 172); + + assign(test_msg_.contents[163], 180); + + assign(test_msg_.contents[164], 150); + + assign(test_msg_.contents[165], 213); + + assign(test_msg_.contents[166], 193); + + assign(test_msg_.contents[167], 177); + + assign(test_msg_.contents[168], 209); + + assign(test_msg_.contents[169], 156); + + assign(test_msg_.contents[170], 20); + + assign(test_msg_.contents[171], 174); + + assign(test_msg_.contents[172], 18); + + assign(test_msg_.contents[173], 73); + + assign(test_msg_.contents[174], 132); + + assign(test_msg_.contents[175], 215); + + assign(test_msg_.contents[176], 115); + + assign(test_msg_.contents[177], 128); + + assign(test_msg_.contents[178], 175); + + assign(test_msg_.contents[179], 169); + + assign(test_msg_.contents[180], 116); + + assign(test_msg_.contents[181], 132); + + assign(test_msg_.contents[182], 100); + + assign(test_msg_.contents[183], 72); + + assign(test_msg_.contents[184], 45); + + assign(test_msg_.contents[185], 25); + + assign(test_msg_.contents[186], 14); + + assign(test_msg_.contents[187], 205); + + assign(test_msg_.contents[188], 213); + + assign(test_msg_.contents[189], 145); + + assign(test_msg_.contents[190], 68); + + assign(test_msg_.contents[191], 137); + + assign(test_msg_.contents[192], 249); + + assign(test_msg_.contents[193], 54); + + assign(test_msg_.contents[194], 40); + + assign(test_msg_.contents[195], 174); + + assign(test_msg_.contents[196], 215); + + assign(test_msg_.contents[197], 148); + + assign(test_msg_.contents[198], 166); + + assign(test_msg_.contents[199], 190); + + assign(test_msg_.contents[200], 63); + + assign(test_msg_.contents[201], 118); + + assign(test_msg_.contents[202], 6); + + assign(test_msg_.contents[203], 165); + + assign(test_msg_.contents[204], 212); + + assign(test_msg_.contents[205], 74); + + assign(test_msg_.contents[206], 68); + + assign(test_msg_.contents[207], 200); + + assign(test_msg_.contents[208], 38); + + assign(test_msg_.contents[209], 139); + + assign(test_msg_.contents[210], 212); + + assign(test_msg_.contents[211], 112); + + assign(test_msg_.contents[212], 45); + + assign(test_msg_.contents[213], 167); + + assign(test_msg_.contents[214], 236); + + assign(test_msg_.contents[215], 255); + + assign(test_msg_.contents[216], 106); + + assign(test_msg_.contents[217], 92); + + assign(test_msg_.contents[218], 132); + + assign(test_msg_.contents[219], 59); + + assign(test_msg_.contents[220], 61); + + assign(test_msg_.contents[221], 233); + + assign(test_msg_.contents[222], 3); + + assign(test_msg_.contents[223], 246); + + assign(test_msg_.contents[224], 158); + + assign(test_msg_.contents[225], 83); + + assign(test_msg_.contents[226], 134); + + assign(test_msg_.contents[227], 246); + + assign(test_msg_.contents[228], 154); + + assign(test_msg_.contents[229], 17); + + assign(test_msg_.contents[230], 0); + + assign(test_msg_.contents[231], 6); + + assign(test_msg_.contents[232], 56); + + assign(test_msg_.contents[233], 216); + + assign(test_msg_.contents[234], 19); + + assign(test_msg_.contents[235], 216); + + assign(test_msg_.contents[236], 70); + + assign(test_msg_.contents[237], 71); + + assign(test_msg_.contents[238], 161); + + assign(test_msg_.contents[239], 184); + + assign(test_msg_.contents[240], 5); + + assign(test_msg_.contents[241], 177); + + assign(test_msg_.contents[242], 45); + + assign(test_msg_.contents[243], 37); + + assign(test_msg_.contents[244], 98); + + assign(test_msg_.contents[245], 56); + + assign(test_msg_.contents[246], 149); + + assign(test_msg_.contents[247], 0); + + assign(test_msg_.contents[248], 73); + + assign(test_msg_.contents[249], 221); + + assign(test_msg_.contents[250], 105); + + assign(test_msg_.contents[251], 239); + + assign(test_msg_.contents[252], 168); + + assign(test_msg_.contents[253], 205); + + assign(test_msg_.contents[254], 85); + assign(test_msg_.n_contents, 255); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_user_data_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_user_data_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgUserData, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_user_data_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgUserData); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->user_data, sizeof(msg->user_data)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_user_data_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.user_data, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgUserData); + info.sender_id = 8574; + info.preamble = 0x55; + info.crc = 0xf551; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 255; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_user_data_t &lesser, + const sbp_msg_user_data_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_user_data_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_user_data_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_user_data_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_user_data_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgUserData, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgUserData, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgUserData, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgUserData, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_user_data_t test_msg_{}; + uint8_t encoded_frame_[255 + 8] = { + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, 149, + 204, 113, 31, 108, 188, 179, 154, 156, 167, 145, 139, 42, 207, 126, 242, + 193, 9, 58, 75, 8, 135, 11, 92, 131, 245, 24, 90, 255, 30, 58, + 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, 50, 148, 1, 99, + 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, 97, 96, 75, 174, 58, + 219, 180, 148, 247, 59, 2, 116, 214, 114, 55, 134, 54, 119, 108, 128, + 73, 181, 20, 233, 23, 23, 73, 119, 136, 231, 189, 26, 174, 128, 93, + 30, 76, 45, 109, 134, 81, 0, 116, 158, 127, 40, 133, 208, 134, 127, + 140, 232, 183, 184, 108, 6, 228, 54, 238, 59, 220, 30, 228, 212, 50, + 182, 97, 20, 41, 76, 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, + 189, 44, 239, 232, 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, + 173, 157, 202, 172, 180, 150, 213, 193, 177, 209, 156, 20, 174, 18, 73, + 132, 215, 115, 128, 175, 169, 116, 132, 100, 72, 45, 25, 14, 205, 213, + 145, 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, 6, 165, + 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, 132, + 59, 61, 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, 56, 216, + 19, 216, 70, 71, 161, 184, 5, 177, 45, 37, 98, 56, 149, 0, 73, + 221, 105, 239, 168, 205, 85, 81, 245, + }; + uint8_t encoded_payload_[255] = { + 53, 5, 172, 138, 50, 49, 206, 234, 149, 204, 113, 31, 108, 188, 179, + 154, 156, 167, 145, 139, 42, 207, 126, 242, 193, 9, 58, 75, 8, 135, + 11, 92, 131, 245, 24, 90, 255, 30, 58, 31, 109, 148, 56, 178, 140, + 30, 159, 70, 17, 170, 50, 148, 1, 99, 112, 88, 217, 36, 84, 34, + 234, 82, 144, 144, 97, 96, 75, 174, 58, 219, 180, 148, 247, 59, 2, + 116, 214, 114, 55, 134, 54, 119, 108, 128, 73, 181, 20, 233, 23, 23, + 73, 119, 136, 231, 189, 26, 174, 128, 93, 30, 76, 45, 109, 134, 81, + 0, 116, 158, 127, 40, 133, 208, 134, 127, 140, 232, 183, 184, 108, 6, + 228, 54, 238, 59, 220, 30, 228, 212, 50, 182, 97, 20, 41, 76, 227, + 88, 12, 95, 112, 209, 183, 127, 4, 165, 189, 44, 239, 232, 132, 9, + 114, 184, 249, 208, 246, 194, 250, 2, 97, 173, 157, 202, 172, 180, 150, + 213, 193, 177, 209, 156, 20, 174, 18, 73, 132, 215, 115, 128, 175, 169, + 116, 132, 100, 72, 45, 25, 14, 205, 213, 145, 68, 137, 249, 54, 40, + 174, 215, 148, 166, 190, 63, 118, 6, 165, 212, 74, 68, 200, 38, 139, + 212, 112, 45, 167, 236, 255, 106, 92, 132, 59, 61, 233, 3, 246, 158, + 83, 134, 246, 154, 17, 0, 6, 56, 216, 19, 216, 70, 71, 161, 184, + 5, 177, 45, 37, 98, 56, 149, 0, 73, 221, 105, 239, 168, 205, 85, + }; +}; + +TEST_F(Testauto_check_sbp_user_MsgUserData0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_user_data_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgUserData, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_user_data_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgUserData, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + EXPECT_EQ( + sbp_msg_user_data_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} +TEST_F(Testauto_check_sbp_user_MsgUserData0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + + for (uint8_t i = 0; i < 255; i++) { + EXPECT_EQ(sbp_msg_user_data_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_user_data_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_user_data_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgUserData, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_user_data_t msg{}; + + EXPECT_EQ(sbp_msg_user_data_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_user_MsgUserData0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_user_data_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + size_t overhead = []() -> size_t { + sbp_msg_user_data_t t{}; + return sbp_msg_user_data_encoded_len(&t); + }(); + size_t elem_size = []() -> size_t { + sbp_msg_user_data_t t{}; + t.n_contents = 1; + return sbp_msg_user_data_encoded_len(&t); + }() - overhead; + + if (i >= overhead) { + if (((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + + EXPECT_EQ( + sbp_msg_user_data_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_user_data_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUserData, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgUserData, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgUserData, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, Comparison) { + auto info = get_test_msg_info(); + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[0], greater.contents[0]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[1], greater.contents[1]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[2], greater.contents[2]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[3], greater.contents[3]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[4], greater.contents[4]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[5], greater.contents[5]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[6], greater.contents[6]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[7], greater.contents[7]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[8], greater.contents[8]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[9], greater.contents[9]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[10], greater.contents[10]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[11], greater.contents[11]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[12], greater.contents[12]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[13], greater.contents[13]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[14], greater.contents[14]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[15], greater.contents[15]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[16], greater.contents[16]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[17], greater.contents[17]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[18], greater.contents[18]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[19], greater.contents[19]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[20], greater.contents[20]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[21], greater.contents[21]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[22], greater.contents[22]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[23], greater.contents[23]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[24], greater.contents[24]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[25], greater.contents[25]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[26], greater.contents[26]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[27], greater.contents[27]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[28], greater.contents[28]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[29], greater.contents[29]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[30], greater.contents[30]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[31], greater.contents[31]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[32], greater.contents[32]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[33], greater.contents[33]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[34], greater.contents[34]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[35], greater.contents[35]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[36], greater.contents[36]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[37], greater.contents[37]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[38], greater.contents[38]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[39], greater.contents[39]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[40], greater.contents[40]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[41], greater.contents[41]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[42], greater.contents[42]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[43], greater.contents[43]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[44], greater.contents[44]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[45], greater.contents[45]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[46], greater.contents[46]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[47], greater.contents[47]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[48], greater.contents[48]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[49], greater.contents[49]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[50], greater.contents[50]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[51], greater.contents[51]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[52], greater.contents[52]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[53], greater.contents[53]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[54], greater.contents[54]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[55], greater.contents[55]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[56], greater.contents[56]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[57], greater.contents[57]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[58], greater.contents[58]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[59], greater.contents[59]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[60], greater.contents[60]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[61], greater.contents[61]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[62], greater.contents[62]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[63], greater.contents[63]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[64], greater.contents[64]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[65], greater.contents[65]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[66], greater.contents[66]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[67], greater.contents[67]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[68], greater.contents[68]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[69], greater.contents[69]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[70], greater.contents[70]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[71], greater.contents[71]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[72], greater.contents[72]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[73], greater.contents[73]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[74], greater.contents[74]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[75], greater.contents[75]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[76], greater.contents[76]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[77], greater.contents[77]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[78], greater.contents[78]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[79], greater.contents[79]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[80], greater.contents[80]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[81], greater.contents[81]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[82], greater.contents[82]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[83], greater.contents[83]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[84], greater.contents[84]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[85], greater.contents[85]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[86], greater.contents[86]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[87], greater.contents[87]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[88], greater.contents[88]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[89], greater.contents[89]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[90], greater.contents[90]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[91], greater.contents[91]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[92], greater.contents[92]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[93], greater.contents[93]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[94], greater.contents[94]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[95], greater.contents[95]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[96], greater.contents[96]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[97], greater.contents[97]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[98], greater.contents[98]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[99], greater.contents[99]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[100], greater.contents[100]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[101], greater.contents[101]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[102], greater.contents[102]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[103], greater.contents[103]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[104], greater.contents[104]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[105], greater.contents[105]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[106], greater.contents[106]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[107], greater.contents[107]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[108], greater.contents[108]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[109], greater.contents[109]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[110], greater.contents[110]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[111], greater.contents[111]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[112], greater.contents[112]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[113], greater.contents[113]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[114], greater.contents[114]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[115], greater.contents[115]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[116], greater.contents[116]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[117], greater.contents[117]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[118], greater.contents[118]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[119], greater.contents[119]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[120], greater.contents[120]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[121], greater.contents[121]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[122], greater.contents[122]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[123], greater.contents[123]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[124], greater.contents[124]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[125], greater.contents[125]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[126], greater.contents[126]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[127], greater.contents[127]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[128], greater.contents[128]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[129], greater.contents[129]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[130], greater.contents[130]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[131], greater.contents[131]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[132], greater.contents[132]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[133], greater.contents[133]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[134], greater.contents[134]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[135], greater.contents[135]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[136], greater.contents[136]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[137], greater.contents[137]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[138], greater.contents[138]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[139], greater.contents[139]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[140], greater.contents[140]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[141], greater.contents[141]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[142], greater.contents[142]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[143], greater.contents[143]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[144], greater.contents[144]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[145], greater.contents[145]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[146], greater.contents[146]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[147], greater.contents[147]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[148], greater.contents[148]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[149], greater.contents[149]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[150], greater.contents[150]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[151], greater.contents[151]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[152], greater.contents[152]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[153], greater.contents[153]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[154], greater.contents[154]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[155], greater.contents[155]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[156], greater.contents[156]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[157], greater.contents[157]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[158], greater.contents[158]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[159], greater.contents[159]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[160], greater.contents[160]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[161], greater.contents[161]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[162], greater.contents[162]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[163], greater.contents[163]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[164], greater.contents[164]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[165], greater.contents[165]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[166], greater.contents[166]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[167], greater.contents[167]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[168], greater.contents[168]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[169], greater.contents[169]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[170], greater.contents[170]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[171], greater.contents[171]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[172], greater.contents[172]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[173], greater.contents[173]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[174], greater.contents[174]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[175], greater.contents[175]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[176], greater.contents[176]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[177], greater.contents[177]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[178], greater.contents[178]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[179], greater.contents[179]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[180], greater.contents[180]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[181], greater.contents[181]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[182], greater.contents[182]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[183], greater.contents[183]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[184], greater.contents[184]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[185], greater.contents[185]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[186], greater.contents[186]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[187], greater.contents[187]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[188], greater.contents[188]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[189], greater.contents[189]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[190], greater.contents[190]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[191], greater.contents[191]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[192], greater.contents[192]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[193], greater.contents[193]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[194], greater.contents[194]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[195], greater.contents[195]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[196], greater.contents[196]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[197], greater.contents[197]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[198], greater.contents[198]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[199], greater.contents[199]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[200], greater.contents[200]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[201], greater.contents[201]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[202], greater.contents[202]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[203], greater.contents[203]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[204], greater.contents[204]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[205], greater.contents[205]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[206], greater.contents[206]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[207], greater.contents[207]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[208], greater.contents[208]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[209], greater.contents[209]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[210], greater.contents[210]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[211], greater.contents[211]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[212], greater.contents[212]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[213], greater.contents[213]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[214], greater.contents[214]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[215], greater.contents[215]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[216], greater.contents[216]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[217], greater.contents[217]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[218], greater.contents[218]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[219], greater.contents[219]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[220], greater.contents[220]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[221], greater.contents[221]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[222], greater.contents[222]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[223], greater.contents[223]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[224], greater.contents[224]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[225], greater.contents[225]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[226], greater.contents[226]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[227], greater.contents[227]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[228], greater.contents[228]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[229], greater.contents[229]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[230], greater.contents[230]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[231], greater.contents[231]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[232], greater.contents[232]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[233], greater.contents[233]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[234], greater.contents[234]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[235], greater.contents[235]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[236], greater.contents[236]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[237], greater.contents[237]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[238], greater.contents[238]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[239], greater.contents[239]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[240], greater.contents[240]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[241], greater.contents[241]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[242], greater.contents[242]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[243], greater.contents[243]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[244], greater.contents[244]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[245], greater.contents[245]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[246], greater.contents[246]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[247], greater.contents[247]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[248], greater.contents[248]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[249], greater.contents[249]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[250], greater.contents[250]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[251], greater.contents[251]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[252], greater.contents[252]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[253], greater.contents[253]); + comparison_tests(lesser, greater); + } + + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.contents[254], greater.contents[254]); + comparison_tests(lesser, greater); + } + { + sbp_msg_user_data_t lesser = info.test_msg; + sbp_msg_user_data_t greater = info.test_msg; + make_lesser_greater(lesser.n_contents, greater.n_contents); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgUserData); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_USER_DATA"); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_user_data_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_user_data_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.user_data, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.user_data, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[255]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 255); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 255), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_user_data_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 255); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgUserData, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_user_MsgUserData0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgUserData, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_vehicle_MsgOdometry.cc b/c/test/cpp/auto_check_sbp_vehicle_MsgOdometry.cc index 43d07685f7..dd4f994848 100644 --- a/c/test/cpp/auto_check_sbp_vehicle_MsgOdometry.cc +++ b/c/test/cpp/auto_check_sbp_vehicle_MsgOdometry.cc @@ -16,92 +16,760 @@ #include #include -#include #include -#include -class Test_auto_check_sbp_vehicle_MsgOdometry0 - : public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler { +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_vehicle_MsgOdometry0 : public ::testing::Test { public: - Test_auto_check_sbp_vehicle_MsgOdometry0() - : ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() { - set_reader(this); - set_writer(this); - } - - s32 read(uint8_t *buf, const uint32_t n) override { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; - } - - s32 write(const uint8_t *buf, uint32_t n) override { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; + Testauto_check_sbp_vehicle_MsgOdometry0() { + assign(test_msg_.flags, 1); + assign(test_msg_.tow, 8); + assign(test_msg_.velocity, 7); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_odometry_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_odometry_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgOdometry, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_odometry_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgOdometry); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->odometry, sizeof(msg->odometry)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_odometry_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.odometry, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgOdometry); + info.sender_id = 66; + info.preamble = 0x55; + info.crc = 0x6334; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 9; + + return info; } protected: - void handle_sbp_msg(uint16_t sender_id, - const sbp_msg_odometry_t &msg) override { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - sbp_msg_odometry_t last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; + void comparison_tests(const sbp_msg_odometry_t &lesser, + const sbp_msg_odometry_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_odometry_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_odometry_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_odometry_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_odometry_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp(SbpMsgOdometry, &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgOdometry, &wrapped_greater, &wrapped_greater), 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgOdometry, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgOdometry, &wrapped_greater, &wrapped_lesser), 0); -TEST_F(Test_auto_check_sbp_vehicle_MsgOdometry0, Test) { - uint8_t encoded_frame[] = { + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_odometry_t test_msg_{}; + uint8_t encoded_frame_[9 + 8] = { 85, 3, 9, 66, 0, 9, 8, 0, 0, 0, 7, 0, 0, 0, 1, 52, 99, }; + uint8_t encoded_payload_[9] = { + 8, 0, 0, 0, 7, 0, 0, 0, 1, + }; +}; + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_odometry_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgOdometry, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ( + sbp_msg_odometry_encode(&buf[0], sizeof(buf), &n_written, &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, SbpMsgOdometry, + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + EXPECT_EQ( + sbp_msg_odometry_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + + for (uint8_t i = 0; i < 9; i++) { + EXPECT_EQ(sbp_msg_odometry_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_odometry_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_odometry_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgOdometry, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_odometry_t msg{}; + + EXPECT_EQ(sbp_msg_odometry_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_odometry_t msg{}; - sbp_msg_odometry_t test_msg{}; - test_msg.flags = 1; - test_msg.tow = 8; - test_msg.velocity = 7; + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; - EXPECT_EQ(send_message(66, test_msg), SBP_OK); + EXPECT_EQ( + sbp_msg_odometry_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + EXPECT_EQ(sbp_msg_odometry_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOdometry, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); - while (dummy_rd_ < dummy_wr_) { - process(); + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgOdometry, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); } +} - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 66); - EXPECT_EQ(last_msg_, test_msg); - EXPECT_EQ(last_msg_.flags, 1) - << "incorrect value for last_msg_.flags, expected 1, is " - << last_msg_.flags; - EXPECT_EQ(last_msg_.tow, 8) - << "incorrect value for last_msg_.tow, expected 8, is " << last_msg_.tow; - EXPECT_EQ(last_msg_.velocity, 7) - << "incorrect value for last_msg_.velocity, expected 7, is " - << last_msg_.velocity; +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgOdometry, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); } + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_odometry_t lesser = info.test_msg; + sbp_msg_odometry_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_odometry_t lesser = info.test_msg; + sbp_msg_odometry_t greater = info.test_msg; + make_lesser_greater(lesser.tow, greater.tow); + comparison_tests(lesser, greater); + } + { + sbp_msg_odometry_t lesser = info.test_msg; + sbp_msg_odometry_t greater = info.test_msg; + make_lesser_greater(lesser.velocity, greater.velocity); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgOdometry); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_ODOMETRY"); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_odometry_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_odometry_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.odometry, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.odometry, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[9]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 9); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 9), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_odometry_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 9); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgOdometry, &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgOdometry0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, SbpMsgOdometry, info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc b/c/test/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc new file mode 100644 index 0000000000..10477e60ca --- /dev/null +++ b/c/test/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc @@ -0,0 +1,785 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +#include + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} +class Testauto_check_sbp_vehicle_MsgWheeltick0 : public ::testing::Test { + public: + Testauto_check_sbp_vehicle_MsgWheeltick0() { + assign(test_msg_.flags, 1); + assign(test_msg_.source, 146); + assign(test_msg_.ticks, -771148831); + assign(test_msg_.time, 112414825470); + } + + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler { + using sbp::MessageHandler::MessageHandler; + + struct Output final { + uint16_t sender_id; + sbp_msg_wheeltick_t msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const sbp_msg_wheeltick_t &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, SbpMsgWheeltick, &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + sbp_msg_wheeltick_t msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, SbpMsgWheeltick); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->wheeltick, sizeof(msg->wheeltick)); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + sbp_msg_wheeltick_t test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.wheeltick, &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast(SbpMsgWheeltick); + info.sender_id = 17771; + info.preamble = 0x55; + info.crc = 0x3824; + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = 14; + + return info; + } + + protected: + void comparison_tests(const sbp_msg_wheeltick_t &lesser, + const sbp_msg_wheeltick_t &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits::to_sbp_msg(greater); + + EXPECT_EQ(sbp_msg_wheeltick_cmp(&lesser, &lesser), 0); + EXPECT_EQ(sbp_msg_wheeltick_cmp(&greater, &greater), 0); + EXPECT_LE(sbp_msg_wheeltick_cmp(&lesser, &greater), 0); + EXPECT_GT(sbp_msg_wheeltick_cmp(&greater, &lesser), 0); + + EXPECT_EQ( + sbp_message_cmp(SbpMsgWheeltick, &wrapped_lesser, &wrapped_lesser), 0); + EXPECT_EQ( + sbp_message_cmp(SbpMsgWheeltick, &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE( + sbp_message_cmp(SbpMsgWheeltick, &wrapped_lesser, &wrapped_greater), 0); + EXPECT_GT( + sbp_message_cmp(SbpMsgWheeltick, &wrapped_greater, &wrapped_lesser), 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; + } + } + + template ::value, bool> = true> + void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); + } + + void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } + } + + template + void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } + } + + private: + sbp_msg_wheeltick_t test_msg_{}; + uint8_t encoded_frame_[14 + 8] = { + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, + 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + }; + uint8_t encoded_payload_[14] = { + 254, 27, 114, 44, 26, 0, 0, 0, 1, 146, 225, 51, 9, 210, + }; +}; + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp_msg_wheeltick_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len(SbpMsgWheeltick, &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp_msg_wheeltick_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, + SbpMsgWheeltick, &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + EXPECT_EQ( + sbp_msg_wheeltick_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + + for (uint8_t i = 0; i < 14; i++) { + EXPECT_EQ(sbp_msg_wheeltick_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, DecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_wheeltick_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp_msg_wheeltick_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, SbpMsgWheeltick, &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + sbp_msg_wheeltick_t msg{}; + + EXPECT_EQ(sbp_msg_wheeltick_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + sbp_msg_wheeltick_t msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + EXPECT_EQ( + sbp_msg_wheeltick_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, + ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); + } + + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); + + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_msg_wheeltick_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgWheeltick, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, SbpMsgWheeltick, info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, SbpMsgWheeltick, info.sender_id, + &info.test_msg_wrapped, &SlowWriter::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, Comparison) { + auto info = get_test_msg_info(); + { + sbp_msg_wheeltick_t lesser = info.test_msg; + sbp_msg_wheeltick_t greater = info.test_msg; + make_lesser_greater(lesser.flags, greater.flags); + comparison_tests(lesser, greater); + } + { + sbp_msg_wheeltick_t lesser = info.test_msg; + sbp_msg_wheeltick_t greater = info.test_msg; + make_lesser_greater(lesser.source, greater.source); + comparison_tests(lesser, greater); + } + { + sbp_msg_wheeltick_t lesser = info.test_msg; + sbp_msg_wheeltick_t greater = info.test_msg; + make_lesser_greater(lesser.ticks, greater.ticks); + comparison_tests(lesser, greater); + } + { + sbp_msg_wheeltick_t lesser = info.test_msg; + sbp_msg_wheeltick_t greater = info.test_msg; + make_lesser_greater(lesser.time, greater.time); + comparison_tests(lesser, greater); + } +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits::id, SbpMsgWheeltick); + EXPECT_STREQ(sbp::MessageTraits::name, "MSG_WHEELTICK"); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const sbp_msg_wheeltick_t &const_unwrapped = + sbp::MessageTraits::get(const_sbp_msg_t); + sbp_msg_wheeltick_t &non_const_unwrapped = + sbp::MessageTraits::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.wheeltick, info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.wheeltick, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[14]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, 14); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, 14), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + sbp_msg_wheeltick_t msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, 14); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, + ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, SbpMsgWheeltick, + &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F(Testauto_check_sbp_vehicle_MsgWheeltick0, + SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, SbpMsgWheeltick, + info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +} // namespace \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_acquisition_MsgAcqResult.c b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqResult.c new file mode 100644 index 0000000000..7e20eb9cfc --- /dev/null +++ b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqResult.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_acquisition_MsgAcqResult) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x2f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x2f, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, + 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, 189, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_acq_result_t *test_msg = (msg_acq_result_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->cf = 8241.2001953125; + test_msg->cn0 = 14.5; + test_msg->cp = 72.19999694824219; + test_msg->sid.code = 0; + test_msg->sid.sat = 8; + sbp_payload_send(&sbp_state, 0x2f, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x2f, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_acq_result_t *check_msg = (msg_acq_result_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->cf * 100 - 8241.20019531 * 100) < 0.05, + "incorrect value for cf, expected 8241.20019531, is %f", + check_msg->cf); + ck_assert_msg((check_msg->cn0 * 100 - 14.5 * 100) < 0.05, + "incorrect value for cn0, expected 14.5, is %f", + check_msg->cn0); + ck_assert_msg((check_msg->cp * 100 - 72.1999969482 * 100) < 0.05, + "incorrect value for cp, expected 72.1999969482, is %f", + check_msg->cp); + ck_assert_msg(check_msg->sid.code == 0, + "incorrect value for sid.code, expected 0, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 8, + "incorrect value for sid.sat, expected 8, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_acquisition_MsgAcqResult_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_acquisition_MsgAcqResult"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_acquisition_MsgAcqResult"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_acquisition_MsgAcqResult); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfile.c b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfile.c new file mode 100644 index 0000000000..3a91fb8d45 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfile.c @@ -0,0 +1,418 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x2e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x2e, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, + 0, 52, 0, 0, 0, 49, 0, 0, 0, 61, 0, 0, 0, 147, + 0, 0, 0, 47, 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, + 0, 253, 23, 1, 121, 0, 190, 0, 0, 0, 175, 0, 0, 0, + 175, 0, 0, 0, 142, 0, 0, 0, 237, 0, 0, 0, 12, 0, + 0, 0, 126, 88, 21, 0, 153, 24, 0, 8, 0, 130, 0, 0, + 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, 0, 84, + 0, 0, 0, 82, 0, 0, 0, 168, 177, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_acq_sv_profile_t *test_msg = (msg_acq_sv_profile_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[0].bin_width = 174; + test_msg->acq_sv_profile[0].cf = 47; + test_msg->acq_sv_profile[0].cf_max = 147; + test_msg->acq_sv_profile[0].cf_min = 61; + test_msg->acq_sv_profile[0].cn0 = 38; + test_msg->acq_sv_profile[0].cp = 140; + test_msg->acq_sv_profile[0].int_time = 97; + test_msg->acq_sv_profile[0].job_type = 7; + test_msg->acq_sv_profile[0].sid.code = 0; + test_msg->acq_sv_profile[0].sid.sat = 22; + test_msg->acq_sv_profile[0].status = 13; + test_msg->acq_sv_profile[0].time_spent = 49; + test_msg->acq_sv_profile[0].timestamp = 52; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[1].bin_width = 121; + test_msg->acq_sv_profile[1].cf = 237; + test_msg->acq_sv_profile[1].cf_max = 142; + test_msg->acq_sv_profile[1].cf_min = 175; + test_msg->acq_sv_profile[1].cn0 = 59; + test_msg->acq_sv_profile[1].cp = 12; + test_msg->acq_sv_profile[1].int_time = 253; + test_msg->acq_sv_profile[1].job_type = 166; + test_msg->acq_sv_profile[1].sid.code = 1; + test_msg->acq_sv_profile[1].sid.sat = 23; + test_msg->acq_sv_profile[1].status = 210; + test_msg->acq_sv_profile[1].time_spent = 175; + test_msg->acq_sv_profile[1].timestamp = 190; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[2].bin_width = 8; + test_msg->acq_sv_profile[2].cf = 84; + test_msg->acq_sv_profile[2].cf_max = 191; + test_msg->acq_sv_profile[2].cf_min = 91; + test_msg->acq_sv_profile[2].cn0 = 21; + test_msg->acq_sv_profile[2].cp = 82; + test_msg->acq_sv_profile[2].int_time = 153; + test_msg->acq_sv_profile[2].job_type = 126; + test_msg->acq_sv_profile[2].sid.code = 0; + test_msg->acq_sv_profile[2].sid.sat = 24; + test_msg->acq_sv_profile[2].status = 88; + test_msg->acq_sv_profile[2].time_spent = 172; + test_msg->acq_sv_profile[2].timestamp = 130; + sbp_payload_send(&sbp_state, 0x2e, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x2e, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_acq_sv_profile_t *check_msg = + (msg_acq_sv_profile_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->acq_sv_profile[0].bin_width == 174, + "incorrect value for acq_sv_profile[0].bin_width, expected 174, is %d", + check_msg->acq_sv_profile[0].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf == 47, + "incorrect value for acq_sv_profile[0].cf, expected 47, is %d", + check_msg->acq_sv_profile[0].cf); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf_max == 147, + "incorrect value for acq_sv_profile[0].cf_max, expected 147, is %d", + check_msg->acq_sv_profile[0].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf_min == 61, + "incorrect value for acq_sv_profile[0].cf_min, expected 61, is %d", + check_msg->acq_sv_profile[0].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[0].cn0 == 38, + "incorrect value for acq_sv_profile[0].cn0, expected 38, is %d", + check_msg->acq_sv_profile[0].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[0].cp == 140, + "incorrect value for acq_sv_profile[0].cp, expected 140, is %d", + check_msg->acq_sv_profile[0].cp); + ck_assert_msg( + check_msg->acq_sv_profile[0].int_time == 97, + "incorrect value for acq_sv_profile[0].int_time, expected 97, is %d", + check_msg->acq_sv_profile[0].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[0].job_type == 7, + "incorrect value for acq_sv_profile[0].job_type, expected 7, is %d", + check_msg->acq_sv_profile[0].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[0].sid.code == 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is %d", + check_msg->acq_sv_profile[0].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[0].sid.sat == 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is %d", + check_msg->acq_sv_profile[0].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[0].status == 13, + "incorrect value for acq_sv_profile[0].status, expected 13, is %d", + check_msg->acq_sv_profile[0].status); + ck_assert_msg( + check_msg->acq_sv_profile[0].time_spent == 49, + "incorrect value for acq_sv_profile[0].time_spent, expected 49, is %d", + check_msg->acq_sv_profile[0].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[0].timestamp == 52, + "incorrect value for acq_sv_profile[0].timestamp, expected 52, is %d", + check_msg->acq_sv_profile[0].timestamp); + ck_assert_msg( + check_msg->acq_sv_profile[1].bin_width == 121, + "incorrect value for acq_sv_profile[1].bin_width, expected 121, is %d", + check_msg->acq_sv_profile[1].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf == 237, + "incorrect value for acq_sv_profile[1].cf, expected 237, is %d", + check_msg->acq_sv_profile[1].cf); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf_max == 142, + "incorrect value for acq_sv_profile[1].cf_max, expected 142, is %d", + check_msg->acq_sv_profile[1].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf_min == 175, + "incorrect value for acq_sv_profile[1].cf_min, expected 175, is %d", + check_msg->acq_sv_profile[1].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[1].cn0 == 59, + "incorrect value for acq_sv_profile[1].cn0, expected 59, is %d", + check_msg->acq_sv_profile[1].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[1].cp == 12, + "incorrect value for acq_sv_profile[1].cp, expected 12, is %d", + check_msg->acq_sv_profile[1].cp); + ck_assert_msg( + check_msg->acq_sv_profile[1].int_time == 253, + "incorrect value for acq_sv_profile[1].int_time, expected 253, is %d", + check_msg->acq_sv_profile[1].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[1].job_type == 166, + "incorrect value for acq_sv_profile[1].job_type, expected 166, is %d", + check_msg->acq_sv_profile[1].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[1].sid.code == 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is %d", + check_msg->acq_sv_profile[1].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[1].sid.sat == 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is %d", + check_msg->acq_sv_profile[1].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[1].status == 210, + "incorrect value for acq_sv_profile[1].status, expected 210, is %d", + check_msg->acq_sv_profile[1].status); + ck_assert_msg( + check_msg->acq_sv_profile[1].time_spent == 175, + "incorrect value for acq_sv_profile[1].time_spent, expected 175, is %d", + check_msg->acq_sv_profile[1].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[1].timestamp == 190, + "incorrect value for acq_sv_profile[1].timestamp, expected 190, is %d", + check_msg->acq_sv_profile[1].timestamp); + ck_assert_msg( + check_msg->acq_sv_profile[2].bin_width == 8, + "incorrect value for acq_sv_profile[2].bin_width, expected 8, is %d", + check_msg->acq_sv_profile[2].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf == 84, + "incorrect value for acq_sv_profile[2].cf, expected 84, is %d", + check_msg->acq_sv_profile[2].cf); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf_max == 191, + "incorrect value for acq_sv_profile[2].cf_max, expected 191, is %d", + check_msg->acq_sv_profile[2].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf_min == 91, + "incorrect value for acq_sv_profile[2].cf_min, expected 91, is %d", + check_msg->acq_sv_profile[2].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[2].cn0 == 21, + "incorrect value for acq_sv_profile[2].cn0, expected 21, is %d", + check_msg->acq_sv_profile[2].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[2].cp == 82, + "incorrect value for acq_sv_profile[2].cp, expected 82, is %d", + check_msg->acq_sv_profile[2].cp); + ck_assert_msg( + check_msg->acq_sv_profile[2].int_time == 153, + "incorrect value for acq_sv_profile[2].int_time, expected 153, is %d", + check_msg->acq_sv_profile[2].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[2].job_type == 126, + "incorrect value for acq_sv_profile[2].job_type, expected 126, is %d", + check_msg->acq_sv_profile[2].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[2].sid.code == 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is %d", + check_msg->acq_sv_profile[2].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[2].sid.sat == 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is %d", + check_msg->acq_sv_profile[2].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[2].status == 88, + "incorrect value for acq_sv_profile[2].status, expected 88, is %d", + check_msg->acq_sv_profile[2].status); + ck_assert_msg( + check_msg->acq_sv_profile[2].time_spent == 172, + "incorrect value for acq_sv_profile[2].time_spent, expected 172, is %d", + check_msg->acq_sv_profile[2].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[2].timestamp == 130, + "incorrect value for acq_sv_profile[2].timestamp, expected 130, is %d", + check_msg->acq_sv_profile[2].timestamp); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_acquisition_MsgAcqSvProfile_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_acquisition_MsgAcqSvProfile"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c new file mode 100644 index 0000000000..4fad72d2e1 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_acquisition_MsgAcqSvProfileDep.c @@ -0,0 +1,434 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1e, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, + 187, 0, 91, 0, 0, 0, 75, 0, 0, 0, 132, 0, 0, 0, 36, + 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, + 179, 23, 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, + 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, 247, 0, 0, + 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, + 0, 245, 0, 0, 0, 76, 0, 0, 0, 248, 0, 0, 0, 212, 0, + 0, 0, 101, 0, 0, 0, 67, 132, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_acq_sv_profile_dep_t *test_msg = + (msg_acq_sv_profile_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[0].bin_width = 187; + test_msg->acq_sv_profile[0].cf = 60; + test_msg->acq_sv_profile[0].cf_max = 36; + test_msg->acq_sv_profile[0].cf_min = 132; + test_msg->acq_sv_profile[0].cn0 = 151; + test_msg->acq_sv_profile[0].cp = 241; + test_msg->acq_sv_profile[0].int_time = 12; + test_msg->acq_sv_profile[0].job_type = 67; + test_msg->acq_sv_profile[0].sid.code = 0; + test_msg->acq_sv_profile[0].sid.reserved = 0; + test_msg->acq_sv_profile[0].sid.sat = 22; + test_msg->acq_sv_profile[0].status = 103; + test_msg->acq_sv_profile[0].time_spent = 75; + test_msg->acq_sv_profile[0].timestamp = 91; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[1].bin_width = 176; + test_msg->acq_sv_profile[1].cf = 212; + test_msg->acq_sv_profile[1].cf_max = 24; + test_msg->acq_sv_profile[1].cf_min = 155; + test_msg->acq_sv_profile[1].cn0 = 111; + test_msg->acq_sv_profile[1].cp = 247; + test_msg->acq_sv_profile[1].int_time = 179; + test_msg->acq_sv_profile[1].job_type = 238; + test_msg->acq_sv_profile[1].sid.code = 1; + test_msg->acq_sv_profile[1].sid.reserved = 0; + test_msg->acq_sv_profile[1].sid.sat = 23; + test_msg->acq_sv_profile[1].status = 38; + test_msg->acq_sv_profile[1].time_spent = 234; + test_msg->acq_sv_profile[1].timestamp = 166; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acq_sv_profile[0]); + } + test_msg->acq_sv_profile[2].bin_width = 52; + test_msg->acq_sv_profile[2].cf = 212; + test_msg->acq_sv_profile[2].cf_max = 248; + test_msg->acq_sv_profile[2].cf_min = 76; + test_msg->acq_sv_profile[2].cn0 = 68; + test_msg->acq_sv_profile[2].cp = 101; + test_msg->acq_sv_profile[2].int_time = 53; + test_msg->acq_sv_profile[2].job_type = 142; + test_msg->acq_sv_profile[2].sid.code = 0; + test_msg->acq_sv_profile[2].sid.reserved = 0; + test_msg->acq_sv_profile[2].sid.sat = 24; + test_msg->acq_sv_profile[2].status = 213; + test_msg->acq_sv_profile[2].time_spent = 245; + test_msg->acq_sv_profile[2].timestamp = 49; + sbp_payload_send(&sbp_state, 0x1e, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1e, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_acq_sv_profile_dep_t *check_msg = + (msg_acq_sv_profile_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->acq_sv_profile[0].bin_width == 187, + "incorrect value for acq_sv_profile[0].bin_width, expected 187, is %d", + check_msg->acq_sv_profile[0].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf == 60, + "incorrect value for acq_sv_profile[0].cf, expected 60, is %d", + check_msg->acq_sv_profile[0].cf); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf_max == 36, + "incorrect value for acq_sv_profile[0].cf_max, expected 36, is %d", + check_msg->acq_sv_profile[0].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[0].cf_min == 132, + "incorrect value for acq_sv_profile[0].cf_min, expected 132, is %d", + check_msg->acq_sv_profile[0].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[0].cn0 == 151, + "incorrect value for acq_sv_profile[0].cn0, expected 151, is %d", + check_msg->acq_sv_profile[0].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[0].cp == 241, + "incorrect value for acq_sv_profile[0].cp, expected 241, is %d", + check_msg->acq_sv_profile[0].cp); + ck_assert_msg( + check_msg->acq_sv_profile[0].int_time == 12, + "incorrect value for acq_sv_profile[0].int_time, expected 12, is %d", + check_msg->acq_sv_profile[0].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[0].job_type == 67, + "incorrect value for acq_sv_profile[0].job_type, expected 67, is %d", + check_msg->acq_sv_profile[0].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[0].sid.code == 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is %d", + check_msg->acq_sv_profile[0].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[0].sid.reserved == 0, + "incorrect value for acq_sv_profile[0].sid.reserved, expected 0, is %d", + check_msg->acq_sv_profile[0].sid.reserved); + ck_assert_msg( + check_msg->acq_sv_profile[0].sid.sat == 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is %d", + check_msg->acq_sv_profile[0].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[0].status == 103, + "incorrect value for acq_sv_profile[0].status, expected 103, is %d", + check_msg->acq_sv_profile[0].status); + ck_assert_msg( + check_msg->acq_sv_profile[0].time_spent == 75, + "incorrect value for acq_sv_profile[0].time_spent, expected 75, is %d", + check_msg->acq_sv_profile[0].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[0].timestamp == 91, + "incorrect value for acq_sv_profile[0].timestamp, expected 91, is %d", + check_msg->acq_sv_profile[0].timestamp); + ck_assert_msg( + check_msg->acq_sv_profile[1].bin_width == 176, + "incorrect value for acq_sv_profile[1].bin_width, expected 176, is %d", + check_msg->acq_sv_profile[1].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf == 212, + "incorrect value for acq_sv_profile[1].cf, expected 212, is %d", + check_msg->acq_sv_profile[1].cf); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf_max == 24, + "incorrect value for acq_sv_profile[1].cf_max, expected 24, is %d", + check_msg->acq_sv_profile[1].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[1].cf_min == 155, + "incorrect value for acq_sv_profile[1].cf_min, expected 155, is %d", + check_msg->acq_sv_profile[1].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[1].cn0 == 111, + "incorrect value for acq_sv_profile[1].cn0, expected 111, is %d", + check_msg->acq_sv_profile[1].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[1].cp == 247, + "incorrect value for acq_sv_profile[1].cp, expected 247, is %d", + check_msg->acq_sv_profile[1].cp); + ck_assert_msg( + check_msg->acq_sv_profile[1].int_time == 179, + "incorrect value for acq_sv_profile[1].int_time, expected 179, is %d", + check_msg->acq_sv_profile[1].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[1].job_type == 238, + "incorrect value for acq_sv_profile[1].job_type, expected 238, is %d", + check_msg->acq_sv_profile[1].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[1].sid.code == 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is %d", + check_msg->acq_sv_profile[1].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[1].sid.reserved == 0, + "incorrect value for acq_sv_profile[1].sid.reserved, expected 0, is %d", + check_msg->acq_sv_profile[1].sid.reserved); + ck_assert_msg( + check_msg->acq_sv_profile[1].sid.sat == 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is %d", + check_msg->acq_sv_profile[1].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[1].status == 38, + "incorrect value for acq_sv_profile[1].status, expected 38, is %d", + check_msg->acq_sv_profile[1].status); + ck_assert_msg( + check_msg->acq_sv_profile[1].time_spent == 234, + "incorrect value for acq_sv_profile[1].time_spent, expected 234, is %d", + check_msg->acq_sv_profile[1].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[1].timestamp == 166, + "incorrect value for acq_sv_profile[1].timestamp, expected 166, is %d", + check_msg->acq_sv_profile[1].timestamp); + ck_assert_msg( + check_msg->acq_sv_profile[2].bin_width == 52, + "incorrect value for acq_sv_profile[2].bin_width, expected 52, is %d", + check_msg->acq_sv_profile[2].bin_width); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf == 212, + "incorrect value for acq_sv_profile[2].cf, expected 212, is %d", + check_msg->acq_sv_profile[2].cf); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf_max == 248, + "incorrect value for acq_sv_profile[2].cf_max, expected 248, is %d", + check_msg->acq_sv_profile[2].cf_max); + ck_assert_msg( + check_msg->acq_sv_profile[2].cf_min == 76, + "incorrect value for acq_sv_profile[2].cf_min, expected 76, is %d", + check_msg->acq_sv_profile[2].cf_min); + ck_assert_msg( + check_msg->acq_sv_profile[2].cn0 == 68, + "incorrect value for acq_sv_profile[2].cn0, expected 68, is %d", + check_msg->acq_sv_profile[2].cn0); + ck_assert_msg( + check_msg->acq_sv_profile[2].cp == 101, + "incorrect value for acq_sv_profile[2].cp, expected 101, is %d", + check_msg->acq_sv_profile[2].cp); + ck_assert_msg( + check_msg->acq_sv_profile[2].int_time == 53, + "incorrect value for acq_sv_profile[2].int_time, expected 53, is %d", + check_msg->acq_sv_profile[2].int_time); + ck_assert_msg( + check_msg->acq_sv_profile[2].job_type == 142, + "incorrect value for acq_sv_profile[2].job_type, expected 142, is %d", + check_msg->acq_sv_profile[2].job_type); + ck_assert_msg( + check_msg->acq_sv_profile[2].sid.code == 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is %d", + check_msg->acq_sv_profile[2].sid.code); + ck_assert_msg( + check_msg->acq_sv_profile[2].sid.reserved == 0, + "incorrect value for acq_sv_profile[2].sid.reserved, expected 0, is %d", + check_msg->acq_sv_profile[2].sid.reserved); + ck_assert_msg( + check_msg->acq_sv_profile[2].sid.sat == 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is %d", + check_msg->acq_sv_profile[2].sid.sat); + ck_assert_msg( + check_msg->acq_sv_profile[2].status == 213, + "incorrect value for acq_sv_profile[2].status, expected 213, is %d", + check_msg->acq_sv_profile[2].status); + ck_assert_msg( + check_msg->acq_sv_profile[2].time_spent == 245, + "incorrect value for acq_sv_profile[2].time_spent, expected 245, is %d", + check_msg->acq_sv_profile[2].time_spent); + ck_assert_msg( + check_msg->acq_sv_profile[2].timestamp == 49, + "incorrect value for acq_sv_profile[2].timestamp, expected 49, is %d", + check_msg->acq_sv_profile[2].timestamp); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c b/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c new file mode 100644 index 0000000000..09c52c907c --- /dev/null +++ b/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.c @@ -0,0 +1,199 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb3, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 179, 0, 136, 247, 0, 65, 216, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xb3, 63368, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63368, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 63368, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb3, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_bootload_" + "MsgBootloaderHandshakeReq"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_bootload_MsgBootloaderHandshakeReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c b/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c new file mode 100644 index 0000000000..ec69bb5acd --- /dev/null +++ b/c/test/legacy/auto_check_sbp_bootload_MsgBootloaderJumptoApp.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb1, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 177, 0, 205, 18, 1, 216, 105, 96, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_bootloader_jump_to_app_t *test_msg = + (msg_bootloader_jump_to_app_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->jump = 216; + sbp_payload_send(&sbp_state, 0xb1, 4813, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 4813, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 4813, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb1, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_bootloader_jump_to_app_t *check_msg = + (msg_bootloader_jump_to_app_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->jump == 216, + "incorrect value for jump, expected 216, is %d", + check_msg->jump); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c b/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c new file mode 100644 index 0000000000..8c0e66fc42 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaReq.c @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xde, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xde, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 222, 0, 128, 50, 0, 231, 160, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xde, 12928, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 12928, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 12928, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xde, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c b/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c new file mode 100644 index 0000000000..1ea5fad31f --- /dev/null +++ b/c/test/legacy/auto_check_sbp_bootload_MsgNapDeviceDnaResp.c @@ -0,0 +1,269 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xdd, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xdd, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_nap_device_dna_resp_t *test_msg = + (msg_nap_device_dna_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[0] = 2; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[1] = 187; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[2] = 1; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[3] = 130; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[4] = 173; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[5] = 244; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[6] = 67; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->dna[0]); + } + test_msg->dna[7] = 122; + sbp_payload_send(&sbp_state, 0xdd, 14505, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14505, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 14505, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xdd, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_nap_device_dna_resp_t *check_msg = + (msg_nap_device_dna_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->dna[0] == 2, + "incorrect value for dna[0], expected 2, is %d", + check_msg->dna[0]); + ck_assert_msg(check_msg->dna[1] == 187, + "incorrect value for dna[1], expected 187, is %d", + check_msg->dna[1]); + ck_assert_msg(check_msg->dna[2] == 1, + "incorrect value for dna[2], expected 1, is %d", + check_msg->dna[2]); + ck_assert_msg(check_msg->dna[3] == 130, + "incorrect value for dna[3], expected 130, is %d", + check_msg->dna[3]); + ck_assert_msg(check_msg->dna[4] == 173, + "incorrect value for dna[4], expected 173, is %d", + check_msg->dna[4]); + ck_assert_msg(check_msg->dna[5] == 244, + "incorrect value for dna[5], expected 244, is %d", + check_msg->dna[5]); + ck_assert_msg(check_msg->dna[6] == 67, + "incorrect value for dna[6], expected 67, is %d", + check_msg->dna[6]); + ck_assert_msg(check_msg->dna[7] == 122, + "incorrect value for dna[7], expected 122, is %d", + check_msg->dna[7]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigReq.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigReq.c new file mode 100644 index 0000000000..e373a1ad61 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigReq.c @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioConfigReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1001, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1001, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_config_req_t *test_msg = + (msg_fileio_config_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->sequence = 1514527339; + sbp_payload_send(&sbp_state, 0x1001, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1001, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_config_req_t *check_msg = + (msg_fileio_config_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->sequence == 1514527339, + "incorrect value for sequence, expected 1514527339, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioConfigReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioConfigReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioConfigReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_file_io_MsgFileioConfigReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigResp.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigResp.c new file mode 100644 index 0000000000..1c99e247b5 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioConfigResp.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioConfigResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1002, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1002, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, + 44, 3, 216, 151, 255, 61, 12, 97, 66, 144, 239, 115, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_config_resp_t *test_msg = + (msg_fileio_config_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->batch_size = 1040160728; + test_msg->fileio_version = 2420269324; + test_msg->sequence = 1530154154; + test_msg->window_size = 53262997; + sbp_payload_send(&sbp_state, 0x1002, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1002, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_config_resp_t *check_msg = + (msg_fileio_config_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->batch_size == 1040160728, + "incorrect value for batch_size, expected 1040160728, is %d", + check_msg->batch_size); + ck_assert_msg( + check_msg->fileio_version == 2420269324, + "incorrect value for fileio_version, expected 2420269324, is %d", + check_msg->fileio_version); + ck_assert_msg(check_msg->sequence == 1530154154, + "incorrect value for sequence, expected 1530154154, is %d", + check_msg->sequence); + ck_assert_msg(check_msg->window_size == 53262997, + "incorrect value for window_size, expected 53262997, is %d", + check_msg->window_size); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioConfigResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioConfigResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioConfigResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_file_io_MsgFileioConfigResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirReq.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirReq.c new file mode 100644 index 0000000000..450d570ea7 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirReq.c @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa9, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa9, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, + 47, 134, 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, + 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_read_dir_req_t *test_msg = + (msg_fileio_read_dir_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)115, (char)111, (char)109, (char)101, (char)47, + (char)114, (char)97, (char)110, (char)100, (char)111, (char)109, + (char)47, (char)112, (char)97, (char)116, (char)104, (char)0}; + memcpy(test_msg->dirname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->dirname) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->offset = 2251261636; + test_msg->sequence = 1526720386; + sbp_payload_send(&sbp_state, 0xa9, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa9, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_read_dir_req_t *check_msg = + (msg_fileio_read_dir_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)115, (char)111, (char)109, (char)101, (char)47, + (char)114, (char)97, (char)110, (char)100, (char)111, (char)109, + (char)47, (char)112, (char)97, (char)116, (char)104, (char)0}; + ck_assert_msg( + memcmp(check_msg->dirname, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->dirname, expected string '%s', is " + "'%s'", + check_string, check_msg->dirname); + } + ck_assert_msg(check_msg->offset == 2251261636, + "incorrect value for offset, expected 2251261636, is %d", + check_msg->offset); + ck_assert_msg(check_msg->sequence == 1526720386, + "incorrect value for sequence, expected 1526720386, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioReadDirReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioReadDirReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirResp.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirResp.c new file mode 100644 index 0000000000..f2f521b127 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadDirResp.c @@ -0,0 +1,241 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xaa, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xaa, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, + 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, 108, 101, + 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, 111, + 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_read_dir_resp_t *test_msg = + (msg_fileio_read_dir_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)102, (char)105, (char)108, (char)101, (char)49, (char)0, + (char)97, (char)110, (char)111, (char)116, (char)104, (char)101, + (char)114, (char)32, (char)102, (char)105, (char)108, (char)101, + (char)0, (char)100, (char)101, (char)102, (char)105, (char)110, + (char)105, (char)116, (char)101, (char)108, (char)121, (char)32, + (char)110, (char)111, (char)116, (char)32, (char)97, (char)32, + (char)102, (char)105, (char)108, (char)101, (char)0}; + memcpy(test_msg->contents, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->contents) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->sequence = 3957390670; + sbp_payload_send(&sbp_state, 0xaa, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xaa, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_read_dir_resp_t *check_msg = + (msg_fileio_read_dir_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)102, (char)105, (char)108, (char)101, (char)49, (char)0, + (char)97, (char)110, (char)111, (char)116, (char)104, (char)101, + (char)114, (char)32, (char)102, (char)105, (char)108, (char)101, + (char)0, (char)100, (char)101, (char)102, (char)105, (char)110, + (char)105, (char)116, (char)101, (char)108, (char)121, (char)32, + (char)110, (char)111, (char)116, (char)32, (char)97, (char)32, + (char)102, (char)105, (char)108, (char)101, (char)0}; + ck_assert_msg( + memcmp(check_msg->contents, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->contents, expected string '%s', is " + "'%s'", + check_string, check_msg->contents); + } + ck_assert_msg(check_msg->sequence == 3957390670, + "incorrect value for sequence, expected 3957390670, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioReadDirResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioReadDirResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadReq.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadReq.c new file mode 100644 index 0000000000..ed80673be7 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadReq.c @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioReadReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa8, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, + 190, 23, 53, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_read_req_t *test_msg = (msg_fileio_read_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->chunk_size = 53; + { + const char assign_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)115, (char)111, (char)109, + (char)101, (char)47, (char)102, (char)105, + (char)108, (char)101, (char)0}; + memcpy(test_msg->filename, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->filename) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->offset = 398373474; + test_msg->sequence = 679648290; + sbp_payload_send(&sbp_state, 0xa8, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa8, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_read_req_t *check_msg = + (msg_fileio_read_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->chunk_size == 53, + "incorrect value for chunk_size, expected 53, is %d", + check_msg->chunk_size); + { + const char check_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)115, (char)111, (char)109, + (char)101, (char)47, (char)102, (char)105, + (char)108, (char)101, (char)0}; + ck_assert_msg( + memcmp(check_msg->filename, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->filename, expected string '%s', is " + "'%s'", + check_string, check_msg->filename); + } + ck_assert_msg(check_msg->offset == 398373474, + "incorrect value for offset, expected 398373474, is %d", + check_msg->offset); + ck_assert_msg(check_msg->sequence == 679648290, + "incorrect value for sequence, expected 679648290, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioReadReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioReadReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_file_io_MsgFileioReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadResp.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadResp.c new file mode 100644 index 0000000000..4c16884a9d --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioReadResp.c @@ -0,0 +1,2234 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioReadResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa3, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, + 18, 76, 68, 229, 216, 21, 98, 183, 69, 190, 5, 252, 176, 55, + 32, 78, 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, 46, 79, + 118, 248, 118, 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, + 206, 185, 140, 249, 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, + 77, 224, 124, 238, 205, 65, 103, 35, 104, 209, 5, 191, 47, 249, + 176, 166, 213, 46, 192, 86, 32, 103, 146, 252, 4, 16, 54, 161, + 60, 6, 13, 191, 116, 182, 42, 191, 213, 20, 217, 8, 142, 187, + 238, 120, 184, 250, 31, 151, 37, 51, 177, 130, 190, 155, 71, 68, + 56, 238, 92, 130, 37, 137, 146, 246, 114, 116, 138, 165, 217, 79, + 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, 236, 228, 194, 0, + 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, 3, 240, 205, + 253, 113, 25, 28, 187, 81, 101, 216, 121, 41, 179, 120, 152, 18, + 116, 53, 212, 100, 2, 114, 198, 200, 10, 147, 25, 33, 115, 208, + 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, 133, + 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, + 180, 180, 125, 97, 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, + 65, 4, 64, 19, 74, 223, 111, 109, 52, 43, 167, 186, 202, 111, + 11, 91, 21, 236, 234, 196, 36, 171, 147, 10, 240, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_read_resp_t *test_msg = + (msg_fileio_read_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[0] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[1] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[2] = 227; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[3] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[4] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[5] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[6] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[7] = 229; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[8] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[9] = 21; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[10] = 98; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[11] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[12] = 69; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[13] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[14] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[15] = 252; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[16] = 176; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[17] = 55; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[18] = 32; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[19] = 78; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[20] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[21] = 52; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[22] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[23] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[24] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[25] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[26] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[27] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[28] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[29] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[30] = 46; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[31] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[32] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[33] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[34] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[35] = 207; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[36] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[37] = 210; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[38] = 91; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[39] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[40] = 251; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[41] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[42] = 131; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[43] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[44] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[45] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[46] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[47] = 185; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[48] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[49] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[50] = 163; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[51] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[52] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[53] = 67; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[54] = 94; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[55] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[56] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[57] = 152; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[58] = 95; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[59] = 123; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[60] = 77; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[61] = 224; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[62] = 124; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[63] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[64] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[65] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[66] = 103; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[67] = 35; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[68] = 104; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[69] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[70] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[71] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[72] = 47; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[73] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[74] = 176; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[75] = 166; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[76] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[77] = 46; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[78] = 192; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[79] = 86; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[80] = 32; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[81] = 103; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[82] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[83] = 252; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[84] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[85] = 16; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[86] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[87] = 161; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[88] = 60; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[89] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[90] = 13; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[91] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[92] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[93] = 182; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[94] = 42; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[95] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[96] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[97] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[98] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[99] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[100] = 142; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[101] = 187; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[102] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[103] = 120; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[104] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[105] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[106] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[107] = 151; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[108] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[109] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[110] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[111] = 130; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[112] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[113] = 155; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[114] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[115] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[116] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[117] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[118] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[119] = 130; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[120] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[121] = 137; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[122] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[123] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[124] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[125] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[126] = 138; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[127] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[128] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[129] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[130] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[131] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[132] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[133] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[134] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[135] = 240; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[136] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[137] = 28; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[138] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[139] = 105; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[140] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[141] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[142] = 194; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[143] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[144] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[145] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[146] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[147] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[148] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[149] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[150] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[151] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[152] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[153] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[154] = 27; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[155] = 3; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[156] = 240; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[157] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[158] = 253; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[159] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[160] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[161] = 28; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[162] = 187; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[163] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[164] = 101; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[165] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[166] = 121; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[167] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[168] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[169] = 120; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[170] = 152; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[171] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[172] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[173] = 53; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[174] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[175] = 100; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[176] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[177] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[178] = 198; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[179] = 200; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[180] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[181] = 147; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[182] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[183] = 33; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[184] = 115; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[185] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[186] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[187] = 60; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[188] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[189] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[190] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[191] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[192] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[193] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[194] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[195] = 211; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[196] = 225; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[197] = 142; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[198] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[199] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[200] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[201] = 15; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[202] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[203] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[204] = 66; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[205] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[206] = 244; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[207] = 221; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[208] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[209] = 199; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[210] = 241; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[211] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[212] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[213] = 1; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[214] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[215] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[216] = 125; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[217] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[218] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[219] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[220] = 72; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[221] = 210; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[222] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[223] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[224] = 15; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[225] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[226] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[227] = 38; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[228] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[229] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[230] = 64; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[231] = 19; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[232] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[233] = 223; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[234] = 111; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[235] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[236] = 52; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[237] = 43; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[238] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[239] = 186; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[240] = 202; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[241] = 111; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[242] = 11; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[243] = 91; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[244] = 21; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[245] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[246] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[247] = 196; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[248] = 36; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[249] = 171; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[250] = 147; + test_msg->sequence = 259241795; + sbp_payload_send(&sbp_state, 0xa3, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa3, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_read_resp_t *check_msg = + (msg_fileio_read_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->contents[0] == 73, + "incorrect value for contents[0], expected 73, is %d", + check_msg->contents[0]); + ck_assert_msg(check_msg->contents[1] == 231, + "incorrect value for contents[1], expected 231, is %d", + check_msg->contents[1]); + ck_assert_msg(check_msg->contents[2] == 227, + "incorrect value for contents[2], expected 227, is %d", + check_msg->contents[2]); + ck_assert_msg(check_msg->contents[3] == 179, + "incorrect value for contents[3], expected 179, is %d", + check_msg->contents[3]); + ck_assert_msg(check_msg->contents[4] == 18, + "incorrect value for contents[4], expected 18, is %d", + check_msg->contents[4]); + ck_assert_msg(check_msg->contents[5] == 76, + "incorrect value for contents[5], expected 76, is %d", + check_msg->contents[5]); + ck_assert_msg(check_msg->contents[6] == 68, + "incorrect value for contents[6], expected 68, is %d", + check_msg->contents[6]); + ck_assert_msg(check_msg->contents[7] == 229, + "incorrect value for contents[7], expected 229, is %d", + check_msg->contents[7]); + ck_assert_msg(check_msg->contents[8] == 216, + "incorrect value for contents[8], expected 216, is %d", + check_msg->contents[8]); + ck_assert_msg(check_msg->contents[9] == 21, + "incorrect value for contents[9], expected 21, is %d", + check_msg->contents[9]); + ck_assert_msg(check_msg->contents[10] == 98, + "incorrect value for contents[10], expected 98, is %d", + check_msg->contents[10]); + ck_assert_msg(check_msg->contents[11] == 183, + "incorrect value for contents[11], expected 183, is %d", + check_msg->contents[11]); + ck_assert_msg(check_msg->contents[12] == 69, + "incorrect value for contents[12], expected 69, is %d", + check_msg->contents[12]); + ck_assert_msg(check_msg->contents[13] == 190, + "incorrect value for contents[13], expected 190, is %d", + check_msg->contents[13]); + ck_assert_msg(check_msg->contents[14] == 5, + "incorrect value for contents[14], expected 5, is %d", + check_msg->contents[14]); + ck_assert_msg(check_msg->contents[15] == 252, + "incorrect value for contents[15], expected 252, is %d", + check_msg->contents[15]); + ck_assert_msg(check_msg->contents[16] == 176, + "incorrect value for contents[16], expected 176, is %d", + check_msg->contents[16]); + ck_assert_msg(check_msg->contents[17] == 55, + "incorrect value for contents[17], expected 55, is %d", + check_msg->contents[17]); + ck_assert_msg(check_msg->contents[18] == 32, + "incorrect value for contents[18], expected 32, is %d", + check_msg->contents[18]); + ck_assert_msg(check_msg->contents[19] == 78, + "incorrect value for contents[19], expected 78, is %d", + check_msg->contents[19]); + ck_assert_msg(check_msg->contents[20] == 8, + "incorrect value for contents[20], expected 8, is %d", + check_msg->contents[20]); + ck_assert_msg(check_msg->contents[21] == 52, + "incorrect value for contents[21], expected 52, is %d", + check_msg->contents[21]); + ck_assert_msg(check_msg->contents[22] == 127, + "incorrect value for contents[22], expected 127, is %d", + check_msg->contents[22]); + ck_assert_msg(check_msg->contents[23] == 50, + "incorrect value for contents[23], expected 50, is %d", + check_msg->contents[23]); + ck_assert_msg(check_msg->contents[24] == 71, + "incorrect value for contents[24], expected 71, is %d", + check_msg->contents[24]); + ck_assert_msg(check_msg->contents[25] == 106, + "incorrect value for contents[25], expected 106, is %d", + check_msg->contents[25]); + ck_assert_msg(check_msg->contents[26] == 61, + "incorrect value for contents[26], expected 61, is %d", + check_msg->contents[26]); + ck_assert_msg(check_msg->contents[27] == 79, + "incorrect value for contents[27], expected 79, is %d", + check_msg->contents[27]); + ck_assert_msg(check_msg->contents[28] == 191, + "incorrect value for contents[28], expected 191, is %d", + check_msg->contents[28]); + ck_assert_msg(check_msg->contents[29] == 106, + "incorrect value for contents[29], expected 106, is %d", + check_msg->contents[29]); + ck_assert_msg(check_msg->contents[30] == 46, + "incorrect value for contents[30], expected 46, is %d", + check_msg->contents[30]); + ck_assert_msg(check_msg->contents[31] == 79, + "incorrect value for contents[31], expected 79, is %d", + check_msg->contents[31]); + ck_assert_msg(check_msg->contents[32] == 118, + "incorrect value for contents[32], expected 118, is %d", + check_msg->contents[32]); + ck_assert_msg(check_msg->contents[33] == 248, + "incorrect value for contents[33], expected 248, is %d", + check_msg->contents[33]); + ck_assert_msg(check_msg->contents[34] == 118, + "incorrect value for contents[34], expected 118, is %d", + check_msg->contents[34]); + ck_assert_msg(check_msg->contents[35] == 207, + "incorrect value for contents[35], expected 207, is %d", + check_msg->contents[35]); + ck_assert_msg(check_msg->contents[36] == 206, + "incorrect value for contents[36], expected 206, is %d", + check_msg->contents[36]); + ck_assert_msg(check_msg->contents[37] == 210, + "incorrect value for contents[37], expected 210, is %d", + check_msg->contents[37]); + ck_assert_msg(check_msg->contents[38] == 91, + "incorrect value for contents[38], expected 91, is %d", + check_msg->contents[38]); + ck_assert_msg(check_msg->contents[39] == 73, + "incorrect value for contents[39], expected 73, is %d", + check_msg->contents[39]); + ck_assert_msg(check_msg->contents[40] == 251, + "incorrect value for contents[40], expected 251, is %d", + check_msg->contents[40]); + ck_assert_msg(check_msg->contents[41] == 81, + "incorrect value for contents[41], expected 81, is %d", + check_msg->contents[41]); + ck_assert_msg(check_msg->contents[42] == 131, + "incorrect value for contents[42], expected 131, is %d", + check_msg->contents[42]); + ck_assert_msg(check_msg->contents[43] == 205, + "incorrect value for contents[43], expected 205, is %d", + check_msg->contents[43]); + ck_assert_msg(check_msg->contents[44] == 193, + "incorrect value for contents[44], expected 193, is %d", + check_msg->contents[44]); + ck_assert_msg(check_msg->contents[45] == 146, + "incorrect value for contents[45], expected 146, is %d", + check_msg->contents[45]); + ck_assert_msg(check_msg->contents[46] == 206, + "incorrect value for contents[46], expected 206, is %d", + check_msg->contents[46]); + ck_assert_msg(check_msg->contents[47] == 185, + "incorrect value for contents[47], expected 185, is %d", + check_msg->contents[47]); + ck_assert_msg(check_msg->contents[48] == 140, + "incorrect value for contents[48], expected 140, is %d", + check_msg->contents[48]); + ck_assert_msg(check_msg->contents[49] == 249, + "incorrect value for contents[49], expected 249, is %d", + check_msg->contents[49]); + ck_assert_msg(check_msg->contents[50] == 163, + "incorrect value for contents[50], expected 163, is %d", + check_msg->contents[50]); + ck_assert_msg(check_msg->contents[51] == 231, + "incorrect value for contents[51], expected 231, is %d", + check_msg->contents[51]); + ck_assert_msg(check_msg->contents[52] == 65, + "incorrect value for contents[52], expected 65, is %d", + check_msg->contents[52]); + ck_assert_msg(check_msg->contents[53] == 67, + "incorrect value for contents[53], expected 67, is %d", + check_msg->contents[53]); + ck_assert_msg(check_msg->contents[54] == 94, + "incorrect value for contents[54], expected 94, is %d", + check_msg->contents[54]); + ck_assert_msg(check_msg->contents[55] == 250, + "incorrect value for contents[55], expected 250, is %d", + check_msg->contents[55]); + ck_assert_msg(check_msg->contents[56] == 109, + "incorrect value for contents[56], expected 109, is %d", + check_msg->contents[56]); + ck_assert_msg(check_msg->contents[57] == 152, + "incorrect value for contents[57], expected 152, is %d", + check_msg->contents[57]); + ck_assert_msg(check_msg->contents[58] == 95, + "incorrect value for contents[58], expected 95, is %d", + check_msg->contents[58]); + ck_assert_msg(check_msg->contents[59] == 123, + "incorrect value for contents[59], expected 123, is %d", + check_msg->contents[59]); + ck_assert_msg(check_msg->contents[60] == 77, + "incorrect value for contents[60], expected 77, is %d", + check_msg->contents[60]); + ck_assert_msg(check_msg->contents[61] == 224, + "incorrect value for contents[61], expected 224, is %d", + check_msg->contents[61]); + ck_assert_msg(check_msg->contents[62] == 124, + "incorrect value for contents[62], expected 124, is %d", + check_msg->contents[62]); + ck_assert_msg(check_msg->contents[63] == 238, + "incorrect value for contents[63], expected 238, is %d", + check_msg->contents[63]); + ck_assert_msg(check_msg->contents[64] == 205, + "incorrect value for contents[64], expected 205, is %d", + check_msg->contents[64]); + ck_assert_msg(check_msg->contents[65] == 65, + "incorrect value for contents[65], expected 65, is %d", + check_msg->contents[65]); + ck_assert_msg(check_msg->contents[66] == 103, + "incorrect value for contents[66], expected 103, is %d", + check_msg->contents[66]); + ck_assert_msg(check_msg->contents[67] == 35, + "incorrect value for contents[67], expected 35, is %d", + check_msg->contents[67]); + ck_assert_msg(check_msg->contents[68] == 104, + "incorrect value for contents[68], expected 104, is %d", + check_msg->contents[68]); + ck_assert_msg(check_msg->contents[69] == 209, + "incorrect value for contents[69], expected 209, is %d", + check_msg->contents[69]); + ck_assert_msg(check_msg->contents[70] == 5, + "incorrect value for contents[70], expected 5, is %d", + check_msg->contents[70]); + ck_assert_msg(check_msg->contents[71] == 191, + "incorrect value for contents[71], expected 191, is %d", + check_msg->contents[71]); + ck_assert_msg(check_msg->contents[72] == 47, + "incorrect value for contents[72], expected 47, is %d", + check_msg->contents[72]); + ck_assert_msg(check_msg->contents[73] == 249, + "incorrect value for contents[73], expected 249, is %d", + check_msg->contents[73]); + ck_assert_msg(check_msg->contents[74] == 176, + "incorrect value for contents[74], expected 176, is %d", + check_msg->contents[74]); + ck_assert_msg(check_msg->contents[75] == 166, + "incorrect value for contents[75], expected 166, is %d", + check_msg->contents[75]); + ck_assert_msg(check_msg->contents[76] == 213, + "incorrect value for contents[76], expected 213, is %d", + check_msg->contents[76]); + ck_assert_msg(check_msg->contents[77] == 46, + "incorrect value for contents[77], expected 46, is %d", + check_msg->contents[77]); + ck_assert_msg(check_msg->contents[78] == 192, + "incorrect value for contents[78], expected 192, is %d", + check_msg->contents[78]); + ck_assert_msg(check_msg->contents[79] == 86, + "incorrect value for contents[79], expected 86, is %d", + check_msg->contents[79]); + ck_assert_msg(check_msg->contents[80] == 32, + "incorrect value for contents[80], expected 32, is %d", + check_msg->contents[80]); + ck_assert_msg(check_msg->contents[81] == 103, + "incorrect value for contents[81], expected 103, is %d", + check_msg->contents[81]); + ck_assert_msg(check_msg->contents[82] == 146, + "incorrect value for contents[82], expected 146, is %d", + check_msg->contents[82]); + ck_assert_msg(check_msg->contents[83] == 252, + "incorrect value for contents[83], expected 252, is %d", + check_msg->contents[83]); + ck_assert_msg(check_msg->contents[84] == 4, + "incorrect value for contents[84], expected 4, is %d", + check_msg->contents[84]); + ck_assert_msg(check_msg->contents[85] == 16, + "incorrect value for contents[85], expected 16, is %d", + check_msg->contents[85]); + ck_assert_msg(check_msg->contents[86] == 54, + "incorrect value for contents[86], expected 54, is %d", + check_msg->contents[86]); + ck_assert_msg(check_msg->contents[87] == 161, + "incorrect value for contents[87], expected 161, is %d", + check_msg->contents[87]); + ck_assert_msg(check_msg->contents[88] == 60, + "incorrect value for contents[88], expected 60, is %d", + check_msg->contents[88]); + ck_assert_msg(check_msg->contents[89] == 6, + "incorrect value for contents[89], expected 6, is %d", + check_msg->contents[89]); + ck_assert_msg(check_msg->contents[90] == 13, + "incorrect value for contents[90], expected 13, is %d", + check_msg->contents[90]); + ck_assert_msg(check_msg->contents[91] == 191, + "incorrect value for contents[91], expected 191, is %d", + check_msg->contents[91]); + ck_assert_msg(check_msg->contents[92] == 116, + "incorrect value for contents[92], expected 116, is %d", + check_msg->contents[92]); + ck_assert_msg(check_msg->contents[93] == 182, + "incorrect value for contents[93], expected 182, is %d", + check_msg->contents[93]); + ck_assert_msg(check_msg->contents[94] == 42, + "incorrect value for contents[94], expected 42, is %d", + check_msg->contents[94]); + ck_assert_msg(check_msg->contents[95] == 191, + "incorrect value for contents[95], expected 191, is %d", + check_msg->contents[95]); + ck_assert_msg(check_msg->contents[96] == 213, + "incorrect value for contents[96], expected 213, is %d", + check_msg->contents[96]); + ck_assert_msg(check_msg->contents[97] == 20, + "incorrect value for contents[97], expected 20, is %d", + check_msg->contents[97]); + ck_assert_msg(check_msg->contents[98] == 217, + "incorrect value for contents[98], expected 217, is %d", + check_msg->contents[98]); + ck_assert_msg(check_msg->contents[99] == 8, + "incorrect value for contents[99], expected 8, is %d", + check_msg->contents[99]); + ck_assert_msg(check_msg->contents[100] == 142, + "incorrect value for contents[100], expected 142, is %d", + check_msg->contents[100]); + ck_assert_msg(check_msg->contents[101] == 187, + "incorrect value for contents[101], expected 187, is %d", + check_msg->contents[101]); + ck_assert_msg(check_msg->contents[102] == 238, + "incorrect value for contents[102], expected 238, is %d", + check_msg->contents[102]); + ck_assert_msg(check_msg->contents[103] == 120, + "incorrect value for contents[103], expected 120, is %d", + check_msg->contents[103]); + ck_assert_msg(check_msg->contents[104] == 184, + "incorrect value for contents[104], expected 184, is %d", + check_msg->contents[104]); + ck_assert_msg(check_msg->contents[105] == 250, + "incorrect value for contents[105], expected 250, is %d", + check_msg->contents[105]); + ck_assert_msg(check_msg->contents[106] == 31, + "incorrect value for contents[106], expected 31, is %d", + check_msg->contents[106]); + ck_assert_msg(check_msg->contents[107] == 151, + "incorrect value for contents[107], expected 151, is %d", + check_msg->contents[107]); + ck_assert_msg(check_msg->contents[108] == 37, + "incorrect value for contents[108], expected 37, is %d", + check_msg->contents[108]); + ck_assert_msg(check_msg->contents[109] == 51, + "incorrect value for contents[109], expected 51, is %d", + check_msg->contents[109]); + ck_assert_msg(check_msg->contents[110] == 177, + "incorrect value for contents[110], expected 177, is %d", + check_msg->contents[110]); + ck_assert_msg(check_msg->contents[111] == 130, + "incorrect value for contents[111], expected 130, is %d", + check_msg->contents[111]); + ck_assert_msg(check_msg->contents[112] == 190, + "incorrect value for contents[112], expected 190, is %d", + check_msg->contents[112]); + ck_assert_msg(check_msg->contents[113] == 155, + "incorrect value for contents[113], expected 155, is %d", + check_msg->contents[113]); + ck_assert_msg(check_msg->contents[114] == 71, + "incorrect value for contents[114], expected 71, is %d", + check_msg->contents[114]); + ck_assert_msg(check_msg->contents[115] == 68, + "incorrect value for contents[115], expected 68, is %d", + check_msg->contents[115]); + ck_assert_msg(check_msg->contents[116] == 56, + "incorrect value for contents[116], expected 56, is %d", + check_msg->contents[116]); + ck_assert_msg(check_msg->contents[117] == 238, + "incorrect value for contents[117], expected 238, is %d", + check_msg->contents[117]); + ck_assert_msg(check_msg->contents[118] == 92, + "incorrect value for contents[118], expected 92, is %d", + check_msg->contents[118]); + ck_assert_msg(check_msg->contents[119] == 130, + "incorrect value for contents[119], expected 130, is %d", + check_msg->contents[119]); + ck_assert_msg(check_msg->contents[120] == 37, + "incorrect value for contents[120], expected 37, is %d", + check_msg->contents[120]); + ck_assert_msg(check_msg->contents[121] == 137, + "incorrect value for contents[121], expected 137, is %d", + check_msg->contents[121]); + ck_assert_msg(check_msg->contents[122] == 146, + "incorrect value for contents[122], expected 146, is %d", + check_msg->contents[122]); + ck_assert_msg(check_msg->contents[123] == 246, + "incorrect value for contents[123], expected 246, is %d", + check_msg->contents[123]); + ck_assert_msg(check_msg->contents[124] == 114, + "incorrect value for contents[124], expected 114, is %d", + check_msg->contents[124]); + ck_assert_msg(check_msg->contents[125] == 116, + "incorrect value for contents[125], expected 116, is %d", + check_msg->contents[125]); + ck_assert_msg(check_msg->contents[126] == 138, + "incorrect value for contents[126], expected 138, is %d", + check_msg->contents[126]); + ck_assert_msg(check_msg->contents[127] == 165, + "incorrect value for contents[127], expected 165, is %d", + check_msg->contents[127]); + ck_assert_msg(check_msg->contents[128] == 217, + "incorrect value for contents[128], expected 217, is %d", + check_msg->contents[128]); + ck_assert_msg(check_msg->contents[129] == 79, + "incorrect value for contents[129], expected 79, is %d", + check_msg->contents[129]); + ck_assert_msg(check_msg->contents[130] == 10, + "incorrect value for contents[130], expected 10, is %d", + check_msg->contents[130]); + ck_assert_msg(check_msg->contents[131] == 189, + "incorrect value for contents[131], expected 189, is %d", + check_msg->contents[131]); + ck_assert_msg(check_msg->contents[132] == 128, + "incorrect value for contents[132], expected 128, is %d", + check_msg->contents[132]); + ck_assert_msg(check_msg->contents[133] == 189, + "incorrect value for contents[133], expected 189, is %d", + check_msg->contents[133]); + ck_assert_msg(check_msg->contents[134] == 2, + "incorrect value for contents[134], expected 2, is %d", + check_msg->contents[134]); + ck_assert_msg(check_msg->contents[135] == 240, + "incorrect value for contents[135], expected 240, is %d", + check_msg->contents[135]); + ck_assert_msg(check_msg->contents[136] == 92, + "incorrect value for contents[136], expected 92, is %d", + check_msg->contents[136]); + ck_assert_msg(check_msg->contents[137] == 28, + "incorrect value for contents[137], expected 28, is %d", + check_msg->contents[137]); + ck_assert_msg(check_msg->contents[138] == 126, + "incorrect value for contents[138], expected 126, is %d", + check_msg->contents[138]); + ck_assert_msg(check_msg->contents[139] == 105, + "incorrect value for contents[139], expected 105, is %d", + check_msg->contents[139]); + ck_assert_msg(check_msg->contents[140] == 236, + "incorrect value for contents[140], expected 236, is %d", + check_msg->contents[140]); + ck_assert_msg(check_msg->contents[141] == 228, + "incorrect value for contents[141], expected 228, is %d", + check_msg->contents[141]); + ck_assert_msg(check_msg->contents[142] == 194, + "incorrect value for contents[142], expected 194, is %d", + check_msg->contents[142]); + ck_assert_msg(check_msg->contents[143] == 0, + "incorrect value for contents[143], expected 0, is %d", + check_msg->contents[143]); + ck_assert_msg(check_msg->contents[144] == 51, + "incorrect value for contents[144], expected 51, is %d", + check_msg->contents[144]); + ck_assert_msg(check_msg->contents[145] == 61, + "incorrect value for contents[145], expected 61, is %d", + check_msg->contents[145]); + ck_assert_msg(check_msg->contents[146] == 74, + "incorrect value for contents[146], expected 74, is %d", + check_msg->contents[146]); + ck_assert_msg(check_msg->contents[147] == 41, + "incorrect value for contents[147], expected 41, is %d", + check_msg->contents[147]); + ck_assert_msg(check_msg->contents[148] == 10, + "incorrect value for contents[148], expected 10, is %d", + check_msg->contents[148]); + ck_assert_msg(check_msg->contents[149] == 239, + "incorrect value for contents[149], expected 239, is %d", + check_msg->contents[149]); + ck_assert_msg(check_msg->contents[150] == 133, + "incorrect value for contents[150], expected 133, is %d", + check_msg->contents[150]); + ck_assert_msg(check_msg->contents[151] == 106, + "incorrect value for contents[151], expected 106, is %d", + check_msg->contents[151]); + ck_assert_msg(check_msg->contents[152] == 190, + "incorrect value for contents[152], expected 190, is %d", + check_msg->contents[152]); + ck_assert_msg(check_msg->contents[153] == 30, + "incorrect value for contents[153], expected 30, is %d", + check_msg->contents[153]); + ck_assert_msg(check_msg->contents[154] == 27, + "incorrect value for contents[154], expected 27, is %d", + check_msg->contents[154]); + ck_assert_msg(check_msg->contents[155] == 3, + "incorrect value for contents[155], expected 3, is %d", + check_msg->contents[155]); + ck_assert_msg(check_msg->contents[156] == 240, + "incorrect value for contents[156], expected 240, is %d", + check_msg->contents[156]); + ck_assert_msg(check_msg->contents[157] == 205, + "incorrect value for contents[157], expected 205, is %d", + check_msg->contents[157]); + ck_assert_msg(check_msg->contents[158] == 253, + "incorrect value for contents[158], expected 253, is %d", + check_msg->contents[158]); + ck_assert_msg(check_msg->contents[159] == 113, + "incorrect value for contents[159], expected 113, is %d", + check_msg->contents[159]); + ck_assert_msg(check_msg->contents[160] == 25, + "incorrect value for contents[160], expected 25, is %d", + check_msg->contents[160]); + ck_assert_msg(check_msg->contents[161] == 28, + "incorrect value for contents[161], expected 28, is %d", + check_msg->contents[161]); + ck_assert_msg(check_msg->contents[162] == 187, + "incorrect value for contents[162], expected 187, is %d", + check_msg->contents[162]); + ck_assert_msg(check_msg->contents[163] == 81, + "incorrect value for contents[163], expected 81, is %d", + check_msg->contents[163]); + ck_assert_msg(check_msg->contents[164] == 101, + "incorrect value for contents[164], expected 101, is %d", + check_msg->contents[164]); + ck_assert_msg(check_msg->contents[165] == 216, + "incorrect value for contents[165], expected 216, is %d", + check_msg->contents[165]); + ck_assert_msg(check_msg->contents[166] == 121, + "incorrect value for contents[166], expected 121, is %d", + check_msg->contents[166]); + ck_assert_msg(check_msg->contents[167] == 41, + "incorrect value for contents[167], expected 41, is %d", + check_msg->contents[167]); + ck_assert_msg(check_msg->contents[168] == 179, + "incorrect value for contents[168], expected 179, is %d", + check_msg->contents[168]); + ck_assert_msg(check_msg->contents[169] == 120, + "incorrect value for contents[169], expected 120, is %d", + check_msg->contents[169]); + ck_assert_msg(check_msg->contents[170] == 152, + "incorrect value for contents[170], expected 152, is %d", + check_msg->contents[170]); + ck_assert_msg(check_msg->contents[171] == 18, + "incorrect value for contents[171], expected 18, is %d", + check_msg->contents[171]); + ck_assert_msg(check_msg->contents[172] == 116, + "incorrect value for contents[172], expected 116, is %d", + check_msg->contents[172]); + ck_assert_msg(check_msg->contents[173] == 53, + "incorrect value for contents[173], expected 53, is %d", + check_msg->contents[173]); + ck_assert_msg(check_msg->contents[174] == 212, + "incorrect value for contents[174], expected 212, is %d", + check_msg->contents[174]); + ck_assert_msg(check_msg->contents[175] == 100, + "incorrect value for contents[175], expected 100, is %d", + check_msg->contents[175]); + ck_assert_msg(check_msg->contents[176] == 2, + "incorrect value for contents[176], expected 2, is %d", + check_msg->contents[176]); + ck_assert_msg(check_msg->contents[177] == 114, + "incorrect value for contents[177], expected 114, is %d", + check_msg->contents[177]); + ck_assert_msg(check_msg->contents[178] == 198, + "incorrect value for contents[178], expected 198, is %d", + check_msg->contents[178]); + ck_assert_msg(check_msg->contents[179] == 200, + "incorrect value for contents[179], expected 200, is %d", + check_msg->contents[179]); + ck_assert_msg(check_msg->contents[180] == 10, + "incorrect value for contents[180], expected 10, is %d", + check_msg->contents[180]); + ck_assert_msg(check_msg->contents[181] == 147, + "incorrect value for contents[181], expected 147, is %d", + check_msg->contents[181]); + ck_assert_msg(check_msg->contents[182] == 25, + "incorrect value for contents[182], expected 25, is %d", + check_msg->contents[182]); + ck_assert_msg(check_msg->contents[183] == 33, + "incorrect value for contents[183], expected 33, is %d", + check_msg->contents[183]); + ck_assert_msg(check_msg->contents[184] == 115, + "incorrect value for contents[184], expected 115, is %d", + check_msg->contents[184]); + ck_assert_msg(check_msg->contents[185] == 208, + "incorrect value for contents[185], expected 208, is %d", + check_msg->contents[185]); + ck_assert_msg(check_msg->contents[186] == 113, + "incorrect value for contents[186], expected 113, is %d", + check_msg->contents[186]); + ck_assert_msg(check_msg->contents[187] == 60, + "incorrect value for contents[187], expected 60, is %d", + check_msg->contents[187]); + ck_assert_msg(check_msg->contents[188] == 179, + "incorrect value for contents[188], expected 179, is %d", + check_msg->contents[188]); + ck_assert_msg(check_msg->contents[189] == 183, + "incorrect value for contents[189], expected 183, is %d", + check_msg->contents[189]); + ck_assert_msg(check_msg->contents[190] == 0, + "incorrect value for contents[190], expected 0, is %d", + check_msg->contents[190]); + ck_assert_msg(check_msg->contents[191] == 41, + "incorrect value for contents[191], expected 41, is %d", + check_msg->contents[191]); + ck_assert_msg(check_msg->contents[192] == 217, + "incorrect value for contents[192], expected 217, is %d", + check_msg->contents[192]); + ck_assert_msg(check_msg->contents[193] == 206, + "incorrect value for contents[193], expected 206, is %d", + check_msg->contents[193]); + ck_assert_msg(check_msg->contents[194] == 255, + "incorrect value for contents[194], expected 255, is %d", + check_msg->contents[194]); + ck_assert_msg(check_msg->contents[195] == 211, + "incorrect value for contents[195], expected 211, is %d", + check_msg->contents[195]); + ck_assert_msg(check_msg->contents[196] == 225, + "incorrect value for contents[196], expected 225, is %d", + check_msg->contents[196]); + ck_assert_msg(check_msg->contents[197] == 142, + "incorrect value for contents[197], expected 142, is %d", + check_msg->contents[197]); + ck_assert_msg(check_msg->contents[198] == 191, + "incorrect value for contents[198], expected 191, is %d", + check_msg->contents[198]); + ck_assert_msg(check_msg->contents[199] == 133, + "incorrect value for contents[199], expected 133, is %d", + check_msg->contents[199]); + ck_assert_msg(check_msg->contents[200] == 81, + "incorrect value for contents[200], expected 81, is %d", + check_msg->contents[200]); + ck_assert_msg(check_msg->contents[201] == 15, + "incorrect value for contents[201], expected 15, is %d", + check_msg->contents[201]); + ck_assert_msg(check_msg->contents[202] == 248, + "incorrect value for contents[202], expected 248, is %d", + check_msg->contents[202]); + ck_assert_msg(check_msg->contents[203] == 193, + "incorrect value for contents[203], expected 193, is %d", + check_msg->contents[203]); + ck_assert_msg(check_msg->contents[204] == 66, + "incorrect value for contents[204], expected 66, is %d", + check_msg->contents[204]); + ck_assert_msg(check_msg->contents[205] == 191, + "incorrect value for contents[205], expected 191, is %d", + check_msg->contents[205]); + ck_assert_msg(check_msg->contents[206] == 244, + "incorrect value for contents[206], expected 244, is %d", + check_msg->contents[206]); + ck_assert_msg(check_msg->contents[207] == 221, + "incorrect value for contents[207], expected 221, is %d", + check_msg->contents[207]); + ck_assert_msg(check_msg->contents[208] == 248, + "incorrect value for contents[208], expected 248, is %d", + check_msg->contents[208]); + ck_assert_msg(check_msg->contents[209] == 199, + "incorrect value for contents[209], expected 199, is %d", + check_msg->contents[209]); + ck_assert_msg(check_msg->contents[210] == 241, + "incorrect value for contents[210], expected 241, is %d", + check_msg->contents[210]); + ck_assert_msg(check_msg->contents[211] == 112, + "incorrect value for contents[211], expected 112, is %d", + check_msg->contents[211]); + ck_assert_msg(check_msg->contents[212] == 51, + "incorrect value for contents[212], expected 51, is %d", + check_msg->contents[212]); + ck_assert_msg(check_msg->contents[213] == 1, + "incorrect value for contents[213], expected 1, is %d", + check_msg->contents[213]); + ck_assert_msg(check_msg->contents[214] == 180, + "incorrect value for contents[214], expected 180, is %d", + check_msg->contents[214]); + ck_assert_msg(check_msg->contents[215] == 180, + "incorrect value for contents[215], expected 180, is %d", + check_msg->contents[215]); + ck_assert_msg(check_msg->contents[216] == 125, + "incorrect value for contents[216], expected 125, is %d", + check_msg->contents[216]); + ck_assert_msg(check_msg->contents[217] == 97, + "incorrect value for contents[217], expected 97, is %d", + check_msg->contents[217]); + ck_assert_msg(check_msg->contents[218] == 145, + "incorrect value for contents[218], expected 145, is %d", + check_msg->contents[218]); + ck_assert_msg(check_msg->contents[219] == 25, + "incorrect value for contents[219], expected 25, is %d", + check_msg->contents[219]); + ck_assert_msg(check_msg->contents[220] == 72, + "incorrect value for contents[220], expected 72, is %d", + check_msg->contents[220]); + ck_assert_msg(check_msg->contents[221] == 210, + "incorrect value for contents[221], expected 210, is %d", + check_msg->contents[221]); + ck_assert_msg(check_msg->contents[222] == 215, + "incorrect value for contents[222], expected 215, is %d", + check_msg->contents[222]); + ck_assert_msg(check_msg->contents[223] == 208, + "incorrect value for contents[223], expected 208, is %d", + check_msg->contents[223]); + ck_assert_msg(check_msg->contents[224] == 15, + "incorrect value for contents[224], expected 15, is %d", + check_msg->contents[224]); + ck_assert_msg(check_msg->contents[225] == 126, + "incorrect value for contents[225], expected 126, is %d", + check_msg->contents[225]); + ck_assert_msg(check_msg->contents[226] == 56, + "incorrect value for contents[226], expected 56, is %d", + check_msg->contents[226]); + ck_assert_msg(check_msg->contents[227] == 38, + "incorrect value for contents[227], expected 38, is %d", + check_msg->contents[227]); + ck_assert_msg(check_msg->contents[228] == 65, + "incorrect value for contents[228], expected 65, is %d", + check_msg->contents[228]); + ck_assert_msg(check_msg->contents[229] == 4, + "incorrect value for contents[229], expected 4, is %d", + check_msg->contents[229]); + ck_assert_msg(check_msg->contents[230] == 64, + "incorrect value for contents[230], expected 64, is %d", + check_msg->contents[230]); + ck_assert_msg(check_msg->contents[231] == 19, + "incorrect value for contents[231], expected 19, is %d", + check_msg->contents[231]); + ck_assert_msg(check_msg->contents[232] == 74, + "incorrect value for contents[232], expected 74, is %d", + check_msg->contents[232]); + ck_assert_msg(check_msg->contents[233] == 223, + "incorrect value for contents[233], expected 223, is %d", + check_msg->contents[233]); + ck_assert_msg(check_msg->contents[234] == 111, + "incorrect value for contents[234], expected 111, is %d", + check_msg->contents[234]); + ck_assert_msg(check_msg->contents[235] == 109, + "incorrect value for contents[235], expected 109, is %d", + check_msg->contents[235]); + ck_assert_msg(check_msg->contents[236] == 52, + "incorrect value for contents[236], expected 52, is %d", + check_msg->contents[236]); + ck_assert_msg(check_msg->contents[237] == 43, + "incorrect value for contents[237], expected 43, is %d", + check_msg->contents[237]); + ck_assert_msg(check_msg->contents[238] == 167, + "incorrect value for contents[238], expected 167, is %d", + check_msg->contents[238]); + ck_assert_msg(check_msg->contents[239] == 186, + "incorrect value for contents[239], expected 186, is %d", + check_msg->contents[239]); + ck_assert_msg(check_msg->contents[240] == 202, + "incorrect value for contents[240], expected 202, is %d", + check_msg->contents[240]); + ck_assert_msg(check_msg->contents[241] == 111, + "incorrect value for contents[241], expected 111, is %d", + check_msg->contents[241]); + ck_assert_msg(check_msg->contents[242] == 11, + "incorrect value for contents[242], expected 11, is %d", + check_msg->contents[242]); + ck_assert_msg(check_msg->contents[243] == 91, + "incorrect value for contents[243], expected 91, is %d", + check_msg->contents[243]); + ck_assert_msg(check_msg->contents[244] == 21, + "incorrect value for contents[244], expected 21, is %d", + check_msg->contents[244]); + ck_assert_msg(check_msg->contents[245] == 236, + "incorrect value for contents[245], expected 236, is %d", + check_msg->contents[245]); + ck_assert_msg(check_msg->contents[246] == 234, + "incorrect value for contents[246], expected 234, is %d", + check_msg->contents[246]); + ck_assert_msg(check_msg->contents[247] == 196, + "incorrect value for contents[247], expected 196, is %d", + check_msg->contents[247]); + ck_assert_msg(check_msg->contents[248] == 36, + "incorrect value for contents[248], expected 36, is %d", + check_msg->contents[248]); + ck_assert_msg(check_msg->contents[249] == 171, + "incorrect value for contents[249], expected 171, is %d", + check_msg->contents[249]); + ck_assert_msg(check_msg->contents[250] == 147, + "incorrect value for contents[250], expected 147, is %d", + check_msg->contents[250]); + ck_assert_msg(check_msg->sequence == 259241795, + "incorrect value for sequence, expected 259241795, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioReadResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioReadResp"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_file_io_MsgFileioReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_file_io_MsgFileioRemove.c b/c/test/legacy/auto_check_sbp_file_io_MsgFileioRemove.c new file mode 100644 index 0000000000..2bc8f45508 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_file_io_MsgFileioRemove.c @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_file_io_MsgFileioRemove) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xac, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xac, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 102, 105, 108, 101, 0, 46, 243, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_fileio_remove_t *test_msg = (msg_fileio_remove_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)102, (char)105, (char)108, + (char)101, (char)0}; + memcpy(test_msg->filename, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->filename) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xac, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xac, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_fileio_remove_t *check_msg = + (msg_fileio_remove_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)102, (char)105, (char)108, + (char)101, (char)0}; + ck_assert_msg( + memcmp(check_msg->filename, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->filename, expected string '%s', is " + "'%s'", + check_string, check_msg->filename); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_file_io_MsgFileioRemove_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_file_io_MsgFileioRemove"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_file_io_MsgFileioRemove"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_file_io_MsgFileioRemove); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgFlashDone.c b/c/test/legacy/auto_check_sbp_flash_MsgFlashDone.c new file mode 100644 index 0000000000..64dc52fe6f --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgFlashDone.c @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgFlashDone) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe0, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 224, 0, 195, 4, 1, 82, 6, 54, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_flash_done_t *test_msg = (msg_flash_done_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->response = 82; + sbp_payload_send(&sbp_state, 0xe0, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe0, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_flash_done_t *check_msg = (msg_flash_done_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->response == 82, + "incorrect value for response, expected 82, is %d", + check_msg->response); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgFlashDone_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_flash_MsgFlashDone"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_flash_MsgFlashDone"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgFlashDone); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgFlashErase.c b/c/test/legacy/auto_check_sbp_flash_MsgFlashErase.c new file mode 100644 index 0000000000..9474ba9bac --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgFlashErase.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgFlashErase) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe2, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_flash_erase_t *test_msg = (msg_flash_erase_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->sector_num = 2222371310; + test_msg->target = 74; + sbp_payload_send(&sbp_state, 0xe2, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe2, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_flash_erase_t *check_msg = (msg_flash_erase_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->sector_num == 2222371310, + "incorrect value for sector_num, expected 2222371310, is %d", + check_msg->sector_num); + ck_assert_msg(check_msg->target == 74, + "incorrect value for target, expected 74, is %d", + check_msg->target); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgFlashErase_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_flash_MsgFlashErase"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_flash_MsgFlashErase"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgFlashErase); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgFlashProgram.c b/c/test/legacy/auto_check_sbp_flash_MsgFlashProgram.c new file mode 100644 index 0000000000..787228515e --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgFlashProgram.c @@ -0,0 +1,2252 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgFlashProgram) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe6, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, + 106, 144, 29, 141, 255, 3, 16, 192, 237, 172, 254, 213, 4, 220, + 98, 34, 222, 230, 214, 6, 217, 172, 122, 46, 13, 38, 240, 236, + 60, 121, 47, 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, + 21, 214, 57, 245, 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, + 98, 39, 70, 232, 133, 25, 10, 134, 129, 69, 228, 134, 9, 88, + 183, 133, 171, 255, 166, 100, 152, 231, 92, 9, 196, 106, 246, 29, + 145, 156, 151, 32, 67, 188, 63, 233, 142, 174, 139, 154, 127, 35, + 60, 56, 187, 121, 103, 135, 152, 182, 88, 160, 255, 227, 240, 54, + 100, 91, 31, 141, 102, 130, 254, 54, 227, 229, 62, 53, 225, 143, + 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, 57, 87, 130, 178, + 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, 235, 213, 186, + 159, 221, 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, 13, 50, + 71, 73, 193, 201, 250, 172, 193, 13, 20, 238, 130, 243, 68, 4, + 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, 92, 160, + 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, + 239, 168, 32, 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, + 217, 151, 251, 83, 20, 113, 37, 151, 34, 37, 71, 95, 105, 235, + 144, 164, 83, 197, 254, 183, 223, 91, 19, 45, 227, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_flash_program_t *test_msg = (msg_flash_program_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->addr_len = 250; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[0] = 87; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[1] = 52; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[2] = 244; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[0] = 176; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[1] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[2] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[3] = 106; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[4] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[5] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[6] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[7] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[8] = 3; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[9] = 16; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[10] = 192; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[11] = 237; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[12] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[13] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[14] = 213; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[15] = 4; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[16] = 220; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[17] = 98; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[18] = 34; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[19] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[20] = 230; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[21] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[22] = 6; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[23] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[24] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[25] = 122; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[26] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[27] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[28] = 38; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[29] = 240; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[30] = 236; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[31] = 60; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[32] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[33] = 47; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[34] = 252; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[35] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[36] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[37] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[38] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[39] = 168; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[40] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[41] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[42] = 55; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[43] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[44] = 233; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[45] = 21; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[46] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[47] = 57; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[48] = 245; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[49] = 246; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[50] = 19; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[51] = 3; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[52] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[53] = 49; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[54] = 231; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[55] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[56] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[57] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[58] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[59] = 98; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[60] = 39; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[61] = 70; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[62] = 232; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[63] = 133; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[64] = 25; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[65] = 10; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[66] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[67] = 129; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[68] = 69; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[69] = 228; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[70] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[71] = 9; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[72] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[73] = 183; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[74] = 133; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[75] = 171; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[76] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[77] = 166; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[78] = 100; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[79] = 152; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[80] = 231; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[81] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[82] = 9; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[83] = 196; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[84] = 106; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[85] = 246; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[86] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[87] = 145; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[88] = 156; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[89] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[90] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[91] = 67; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[92] = 188; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[93] = 63; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[94] = 233; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[95] = 142; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[96] = 174; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[97] = 139; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[98] = 154; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[99] = 127; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[100] = 35; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[101] = 60; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[102] = 56; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[103] = 187; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[104] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[105] = 103; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[106] = 135; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[107] = 152; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[108] = 182; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[109] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[110] = 160; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[111] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[112] = 227; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[113] = 240; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[114] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[115] = 100; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[116] = 91; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[117] = 31; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[118] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[119] = 102; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[120] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[121] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[122] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[123] = 227; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[124] = 229; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[125] = 62; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[126] = 53; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[127] = 225; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[128] = 143; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[129] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[130] = 139; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[131] = 126; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[132] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[133] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[134] = 35; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[135] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[136] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[137] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[138] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[139] = 57; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[140] = 87; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[141] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[142] = 178; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[143] = 22; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[144] = 158; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[145] = 18; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[146] = 237; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[147] = 209; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[148] = 187; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[149] = 226; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[150] = 1; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[151] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[152] = 64; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[153] = 226; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[154] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[155] = 213; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[156] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[157] = 159; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[158] = 221; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[159] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[160] = 25; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[161] = 115; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[162] = 84; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[163] = 131; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[164] = 167; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[165] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[166] = 104; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[167] = 1; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[168] = 200; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[169] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[170] = 50; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[171] = 71; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[172] = 73; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[173] = 193; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[174] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[175] = 250; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[176] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[177] = 193; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[178] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[179] = 20; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[180] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[181] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[182] = 243; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[183] = 68; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[184] = 4; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[185] = 72; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[186] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[187] = 194; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[188] = 113; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[189] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[190] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[191] = 15; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[192] = 230; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[193] = 64; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[194] = 178; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[195] = 127; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[196] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[197] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[198] = 160; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[199] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[200] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[201] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[202] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[203] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[204] = 28; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[205] = 174; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[206] = 65; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[207] = 73; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[208] = 45; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[209] = 123; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[210] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[211] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[212] = 107; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[213] = 239; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[214] = 168; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[215] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[216] = 212; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[217] = 191; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[218] = 81; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[219] = 93; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[220] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[221] = 223; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[222] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[223] = 19; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[224] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[225] = 137; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[226] = 72; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[227] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[228] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[229] = 251; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[230] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[231] = 20; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[232] = 113; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[233] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[234] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[235] = 34; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[236] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[237] = 71; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[238] = 95; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[239] = 105; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[240] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[241] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[242] = 164; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[243] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[244] = 197; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[245] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[246] = 183; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[247] = 223; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[248] = 91; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->data[0]); + } + test_msg->data[249] = 19; + test_msg->target = 212; + sbp_payload_send(&sbp_state, 0xe6, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe6, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_flash_program_t *check_msg = + (msg_flash_program_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->addr_len == 250, + "incorrect value for addr_len, expected 250, is %d", + check_msg->addr_len); + ck_assert_msg(check_msg->addr_start[0] == 87, + "incorrect value for addr_start[0], expected 87, is %d", + check_msg->addr_start[0]); + ck_assert_msg(check_msg->addr_start[1] == 52, + "incorrect value for addr_start[1], expected 52, is %d", + check_msg->addr_start[1]); + ck_assert_msg(check_msg->addr_start[2] == 244, + "incorrect value for addr_start[2], expected 244, is %d", + check_msg->addr_start[2]); + ck_assert_msg(check_msg->data[0] == 176, + "incorrect value for data[0], expected 176, is %d", + check_msg->data[0]); + ck_assert_msg(check_msg->data[1] == 222, + "incorrect value for data[1], expected 222, is %d", + check_msg->data[1]); + ck_assert_msg(check_msg->data[2] == 235, + "incorrect value for data[2], expected 235, is %d", + check_msg->data[2]); + ck_assert_msg(check_msg->data[3] == 106, + "incorrect value for data[3], expected 106, is %d", + check_msg->data[3]); + ck_assert_msg(check_msg->data[4] == 144, + "incorrect value for data[4], expected 144, is %d", + check_msg->data[4]); + ck_assert_msg(check_msg->data[5] == 29, + "incorrect value for data[5], expected 29, is %d", + check_msg->data[5]); + ck_assert_msg(check_msg->data[6] == 141, + "incorrect value for data[6], expected 141, is %d", + check_msg->data[6]); + ck_assert_msg(check_msg->data[7] == 255, + "incorrect value for data[7], expected 255, is %d", + check_msg->data[7]); + ck_assert_msg(check_msg->data[8] == 3, + "incorrect value for data[8], expected 3, is %d", + check_msg->data[8]); + ck_assert_msg(check_msg->data[9] == 16, + "incorrect value for data[9], expected 16, is %d", + check_msg->data[9]); + ck_assert_msg(check_msg->data[10] == 192, + "incorrect value for data[10], expected 192, is %d", + check_msg->data[10]); + ck_assert_msg(check_msg->data[11] == 237, + "incorrect value for data[11], expected 237, is %d", + check_msg->data[11]); + ck_assert_msg(check_msg->data[12] == 172, + "incorrect value for data[12], expected 172, is %d", + check_msg->data[12]); + ck_assert_msg(check_msg->data[13] == 254, + "incorrect value for data[13], expected 254, is %d", + check_msg->data[13]); + ck_assert_msg(check_msg->data[14] == 213, + "incorrect value for data[14], expected 213, is %d", + check_msg->data[14]); + ck_assert_msg(check_msg->data[15] == 4, + "incorrect value for data[15], expected 4, is %d", + check_msg->data[15]); + ck_assert_msg(check_msg->data[16] == 220, + "incorrect value for data[16], expected 220, is %d", + check_msg->data[16]); + ck_assert_msg(check_msg->data[17] == 98, + "incorrect value for data[17], expected 98, is %d", + check_msg->data[17]); + ck_assert_msg(check_msg->data[18] == 34, + "incorrect value for data[18], expected 34, is %d", + check_msg->data[18]); + ck_assert_msg(check_msg->data[19] == 222, + "incorrect value for data[19], expected 222, is %d", + check_msg->data[19]); + ck_assert_msg(check_msg->data[20] == 230, + "incorrect value for data[20], expected 230, is %d", + check_msg->data[20]); + ck_assert_msg(check_msg->data[21] == 214, + "incorrect value for data[21], expected 214, is %d", + check_msg->data[21]); + ck_assert_msg(check_msg->data[22] == 6, + "incorrect value for data[22], expected 6, is %d", + check_msg->data[22]); + ck_assert_msg(check_msg->data[23] == 217, + "incorrect value for data[23], expected 217, is %d", + check_msg->data[23]); + ck_assert_msg(check_msg->data[24] == 172, + "incorrect value for data[24], expected 172, is %d", + check_msg->data[24]); + ck_assert_msg(check_msg->data[25] == 122, + "incorrect value for data[25], expected 122, is %d", + check_msg->data[25]); + ck_assert_msg(check_msg->data[26] == 46, + "incorrect value for data[26], expected 46, is %d", + check_msg->data[26]); + ck_assert_msg(check_msg->data[27] == 13, + "incorrect value for data[27], expected 13, is %d", + check_msg->data[27]); + ck_assert_msg(check_msg->data[28] == 38, + "incorrect value for data[28], expected 38, is %d", + check_msg->data[28]); + ck_assert_msg(check_msg->data[29] == 240, + "incorrect value for data[29], expected 240, is %d", + check_msg->data[29]); + ck_assert_msg(check_msg->data[30] == 236, + "incorrect value for data[30], expected 236, is %d", + check_msg->data[30]); + ck_assert_msg(check_msg->data[31] == 60, + "incorrect value for data[31], expected 60, is %d", + check_msg->data[31]); + ck_assert_msg(check_msg->data[32] == 121, + "incorrect value for data[32], expected 121, is %d", + check_msg->data[32]); + ck_assert_msg(check_msg->data[33] == 47, + "incorrect value for data[33], expected 47, is %d", + check_msg->data[33]); + ck_assert_msg(check_msg->data[34] == 252, + "incorrect value for data[34], expected 252, is %d", + check_msg->data[34]); + ck_assert_msg(check_msg->data[35] == 163, + "incorrect value for data[35], expected 163, is %d", + check_msg->data[35]); + ck_assert_msg(check_msg->data[36] == 141, + "incorrect value for data[36], expected 141, is %d", + check_msg->data[36]); + ck_assert_msg(check_msg->data[37] == 222, + "incorrect value for data[37], expected 222, is %d", + check_msg->data[37]); + ck_assert_msg(check_msg->data[38] == 29, + "incorrect value for data[38], expected 29, is %d", + check_msg->data[38]); + ck_assert_msg(check_msg->data[39] == 168, + "incorrect value for data[39], expected 168, is %d", + check_msg->data[39]); + ck_assert_msg(check_msg->data[40] == 214, + "incorrect value for data[40], expected 214, is %d", + check_msg->data[40]); + ck_assert_msg(check_msg->data[41] == 118, + "incorrect value for data[41], expected 118, is %d", + check_msg->data[41]); + ck_assert_msg(check_msg->data[42] == 55, + "incorrect value for data[42], expected 55, is %d", + check_msg->data[42]); + ck_assert_msg(check_msg->data[43] == 201, + "incorrect value for data[43], expected 201, is %d", + check_msg->data[43]); + ck_assert_msg(check_msg->data[44] == 233, + "incorrect value for data[44], expected 233, is %d", + check_msg->data[44]); + ck_assert_msg(check_msg->data[45] == 21, + "incorrect value for data[45], expected 21, is %d", + check_msg->data[45]); + ck_assert_msg(check_msg->data[46] == 214, + "incorrect value for data[46], expected 214, is %d", + check_msg->data[46]); + ck_assert_msg(check_msg->data[47] == 57, + "incorrect value for data[47], expected 57, is %d", + check_msg->data[47]); + ck_assert_msg(check_msg->data[48] == 245, + "incorrect value for data[48], expected 245, is %d", + check_msg->data[48]); + ck_assert_msg(check_msg->data[49] == 246, + "incorrect value for data[49], expected 246, is %d", + check_msg->data[49]); + ck_assert_msg(check_msg->data[50] == 19, + "incorrect value for data[50], expected 19, is %d", + check_msg->data[50]); + ck_assert_msg(check_msg->data[51] == 3, + "incorrect value for data[51], expected 3, is %d", + check_msg->data[51]); + ck_assert_msg(check_msg->data[52] == 121, + "incorrect value for data[52], expected 121, is %d", + check_msg->data[52]); + ck_assert_msg(check_msg->data[53] == 49, + "incorrect value for data[53], expected 49, is %d", + check_msg->data[53]); + ck_assert_msg(check_msg->data[54] == 231, + "incorrect value for data[54], expected 231, is %d", + check_msg->data[54]); + ck_assert_msg(check_msg->data[55] == 37, + "incorrect value for data[55], expected 37, is %d", + check_msg->data[55]); + ck_assert_msg(check_msg->data[56] == 186, + "incorrect value for data[56], expected 186, is %d", + check_msg->data[56]); + ck_assert_msg(check_msg->data[57] == 58, + "incorrect value for data[57], expected 58, is %d", + check_msg->data[57]); + ck_assert_msg(check_msg->data[58] == 238, + "incorrect value for data[58], expected 238, is %d", + check_msg->data[58]); + ck_assert_msg(check_msg->data[59] == 98, + "incorrect value for data[59], expected 98, is %d", + check_msg->data[59]); + ck_assert_msg(check_msg->data[60] == 39, + "incorrect value for data[60], expected 39, is %d", + check_msg->data[60]); + ck_assert_msg(check_msg->data[61] == 70, + "incorrect value for data[61], expected 70, is %d", + check_msg->data[61]); + ck_assert_msg(check_msg->data[62] == 232, + "incorrect value for data[62], expected 232, is %d", + check_msg->data[62]); + ck_assert_msg(check_msg->data[63] == 133, + "incorrect value for data[63], expected 133, is %d", + check_msg->data[63]); + ck_assert_msg(check_msg->data[64] == 25, + "incorrect value for data[64], expected 25, is %d", + check_msg->data[64]); + ck_assert_msg(check_msg->data[65] == 10, + "incorrect value for data[65], expected 10, is %d", + check_msg->data[65]); + ck_assert_msg(check_msg->data[66] == 134, + "incorrect value for data[66], expected 134, is %d", + check_msg->data[66]); + ck_assert_msg(check_msg->data[67] == 129, + "incorrect value for data[67], expected 129, is %d", + check_msg->data[67]); + ck_assert_msg(check_msg->data[68] == 69, + "incorrect value for data[68], expected 69, is %d", + check_msg->data[68]); + ck_assert_msg(check_msg->data[69] == 228, + "incorrect value for data[69], expected 228, is %d", + check_msg->data[69]); + ck_assert_msg(check_msg->data[70] == 134, + "incorrect value for data[70], expected 134, is %d", + check_msg->data[70]); + ck_assert_msg(check_msg->data[71] == 9, + "incorrect value for data[71], expected 9, is %d", + check_msg->data[71]); + ck_assert_msg(check_msg->data[72] == 88, + "incorrect value for data[72], expected 88, is %d", + check_msg->data[72]); + ck_assert_msg(check_msg->data[73] == 183, + "incorrect value for data[73], expected 183, is %d", + check_msg->data[73]); + ck_assert_msg(check_msg->data[74] == 133, + "incorrect value for data[74], expected 133, is %d", + check_msg->data[74]); + ck_assert_msg(check_msg->data[75] == 171, + "incorrect value for data[75], expected 171, is %d", + check_msg->data[75]); + ck_assert_msg(check_msg->data[76] == 255, + "incorrect value for data[76], expected 255, is %d", + check_msg->data[76]); + ck_assert_msg(check_msg->data[77] == 166, + "incorrect value for data[77], expected 166, is %d", + check_msg->data[77]); + ck_assert_msg(check_msg->data[78] == 100, + "incorrect value for data[78], expected 100, is %d", + check_msg->data[78]); + ck_assert_msg(check_msg->data[79] == 152, + "incorrect value for data[79], expected 152, is %d", + check_msg->data[79]); + ck_assert_msg(check_msg->data[80] == 231, + "incorrect value for data[80], expected 231, is %d", + check_msg->data[80]); + ck_assert_msg(check_msg->data[81] == 92, + "incorrect value for data[81], expected 92, is %d", + check_msg->data[81]); + ck_assert_msg(check_msg->data[82] == 9, + "incorrect value for data[82], expected 9, is %d", + check_msg->data[82]); + ck_assert_msg(check_msg->data[83] == 196, + "incorrect value for data[83], expected 196, is %d", + check_msg->data[83]); + ck_assert_msg(check_msg->data[84] == 106, + "incorrect value for data[84], expected 106, is %d", + check_msg->data[84]); + ck_assert_msg(check_msg->data[85] == 246, + "incorrect value for data[85], expected 246, is %d", + check_msg->data[85]); + ck_assert_msg(check_msg->data[86] == 29, + "incorrect value for data[86], expected 29, is %d", + check_msg->data[86]); + ck_assert_msg(check_msg->data[87] == 145, + "incorrect value for data[87], expected 145, is %d", + check_msg->data[87]); + ck_assert_msg(check_msg->data[88] == 156, + "incorrect value for data[88], expected 156, is %d", + check_msg->data[88]); + ck_assert_msg(check_msg->data[89] == 151, + "incorrect value for data[89], expected 151, is %d", + check_msg->data[89]); + ck_assert_msg(check_msg->data[90] == 32, + "incorrect value for data[90], expected 32, is %d", + check_msg->data[90]); + ck_assert_msg(check_msg->data[91] == 67, + "incorrect value for data[91], expected 67, is %d", + check_msg->data[91]); + ck_assert_msg(check_msg->data[92] == 188, + "incorrect value for data[92], expected 188, is %d", + check_msg->data[92]); + ck_assert_msg(check_msg->data[93] == 63, + "incorrect value for data[93], expected 63, is %d", + check_msg->data[93]); + ck_assert_msg(check_msg->data[94] == 233, + "incorrect value for data[94], expected 233, is %d", + check_msg->data[94]); + ck_assert_msg(check_msg->data[95] == 142, + "incorrect value for data[95], expected 142, is %d", + check_msg->data[95]); + ck_assert_msg(check_msg->data[96] == 174, + "incorrect value for data[96], expected 174, is %d", + check_msg->data[96]); + ck_assert_msg(check_msg->data[97] == 139, + "incorrect value for data[97], expected 139, is %d", + check_msg->data[97]); + ck_assert_msg(check_msg->data[98] == 154, + "incorrect value for data[98], expected 154, is %d", + check_msg->data[98]); + ck_assert_msg(check_msg->data[99] == 127, + "incorrect value for data[99], expected 127, is %d", + check_msg->data[99]); + ck_assert_msg(check_msg->data[100] == 35, + "incorrect value for data[100], expected 35, is %d", + check_msg->data[100]); + ck_assert_msg(check_msg->data[101] == 60, + "incorrect value for data[101], expected 60, is %d", + check_msg->data[101]); + ck_assert_msg(check_msg->data[102] == 56, + "incorrect value for data[102], expected 56, is %d", + check_msg->data[102]); + ck_assert_msg(check_msg->data[103] == 187, + "incorrect value for data[103], expected 187, is %d", + check_msg->data[103]); + ck_assert_msg(check_msg->data[104] == 121, + "incorrect value for data[104], expected 121, is %d", + check_msg->data[104]); + ck_assert_msg(check_msg->data[105] == 103, + "incorrect value for data[105], expected 103, is %d", + check_msg->data[105]); + ck_assert_msg(check_msg->data[106] == 135, + "incorrect value for data[106], expected 135, is %d", + check_msg->data[106]); + ck_assert_msg(check_msg->data[107] == 152, + "incorrect value for data[107], expected 152, is %d", + check_msg->data[107]); + ck_assert_msg(check_msg->data[108] == 182, + "incorrect value for data[108], expected 182, is %d", + check_msg->data[108]); + ck_assert_msg(check_msg->data[109] == 88, + "incorrect value for data[109], expected 88, is %d", + check_msg->data[109]); + ck_assert_msg(check_msg->data[110] == 160, + "incorrect value for data[110], expected 160, is %d", + check_msg->data[110]); + ck_assert_msg(check_msg->data[111] == 255, + "incorrect value for data[111], expected 255, is %d", + check_msg->data[111]); + ck_assert_msg(check_msg->data[112] == 227, + "incorrect value for data[112], expected 227, is %d", + check_msg->data[112]); + ck_assert_msg(check_msg->data[113] == 240, + "incorrect value for data[113], expected 240, is %d", + check_msg->data[113]); + ck_assert_msg(check_msg->data[114] == 54, + "incorrect value for data[114], expected 54, is %d", + check_msg->data[114]); + ck_assert_msg(check_msg->data[115] == 100, + "incorrect value for data[115], expected 100, is %d", + check_msg->data[115]); + ck_assert_msg(check_msg->data[116] == 91, + "incorrect value for data[116], expected 91, is %d", + check_msg->data[116]); + ck_assert_msg(check_msg->data[117] == 31, + "incorrect value for data[117], expected 31, is %d", + check_msg->data[117]); + ck_assert_msg(check_msg->data[118] == 141, + "incorrect value for data[118], expected 141, is %d", + check_msg->data[118]); + ck_assert_msg(check_msg->data[119] == 102, + "incorrect value for data[119], expected 102, is %d", + check_msg->data[119]); + ck_assert_msg(check_msg->data[120] == 130, + "incorrect value for data[120], expected 130, is %d", + check_msg->data[120]); + ck_assert_msg(check_msg->data[121] == 254, + "incorrect value for data[121], expected 254, is %d", + check_msg->data[121]); + ck_assert_msg(check_msg->data[122] == 54, + "incorrect value for data[122], expected 54, is %d", + check_msg->data[122]); + ck_assert_msg(check_msg->data[123] == 227, + "incorrect value for data[123], expected 227, is %d", + check_msg->data[123]); + ck_assert_msg(check_msg->data[124] == 229, + "incorrect value for data[124], expected 229, is %d", + check_msg->data[124]); + ck_assert_msg(check_msg->data[125] == 62, + "incorrect value for data[125], expected 62, is %d", + check_msg->data[125]); + ck_assert_msg(check_msg->data[126] == 53, + "incorrect value for data[126], expected 53, is %d", + check_msg->data[126]); + ck_assert_msg(check_msg->data[127] == 225, + "incorrect value for data[127], expected 225, is %d", + check_msg->data[127]); + ck_assert_msg(check_msg->data[128] == 143, + "incorrect value for data[128], expected 143, is %d", + check_msg->data[128]); + ck_assert_msg(check_msg->data[129] == 88, + "incorrect value for data[129], expected 88, is %d", + check_msg->data[129]); + ck_assert_msg(check_msg->data[130] == 139, + "incorrect value for data[130], expected 139, is %d", + check_msg->data[130]); + ck_assert_msg(check_msg->data[131] == 126, + "incorrect value for data[131], expected 126, is %d", + check_msg->data[131]); + ck_assert_msg(check_msg->data[132] == 235, + "incorrect value for data[132], expected 235, is %d", + check_msg->data[132]); + ck_assert_msg(check_msg->data[133] == 235, + "incorrect value for data[133], expected 235, is %d", + check_msg->data[133]); + ck_assert_msg(check_msg->data[134] == 35, + "incorrect value for data[134], expected 35, is %d", + check_msg->data[134]); + ck_assert_msg(check_msg->data[135] == 54, + "incorrect value for data[135], expected 54, is %d", + check_msg->data[135]); + ck_assert_msg(check_msg->data[136] == 134, + "incorrect value for data[136], expected 134, is %d", + check_msg->data[136]); + ck_assert_msg(check_msg->data[137] == 163, + "incorrect value for data[137], expected 163, is %d", + check_msg->data[137]); + ck_assert_msg(check_msg->data[138] == 92, + "incorrect value for data[138], expected 92, is %d", + check_msg->data[138]); + ck_assert_msg(check_msg->data[139] == 57, + "incorrect value for data[139], expected 57, is %d", + check_msg->data[139]); + ck_assert_msg(check_msg->data[140] == 87, + "incorrect value for data[140], expected 87, is %d", + check_msg->data[140]); + ck_assert_msg(check_msg->data[141] == 130, + "incorrect value for data[141], expected 130, is %d", + check_msg->data[141]); + ck_assert_msg(check_msg->data[142] == 178, + "incorrect value for data[142], expected 178, is %d", + check_msg->data[142]); + ck_assert_msg(check_msg->data[143] == 22, + "incorrect value for data[143], expected 22, is %d", + check_msg->data[143]); + ck_assert_msg(check_msg->data[144] == 158, + "incorrect value for data[144], expected 158, is %d", + check_msg->data[144]); + ck_assert_msg(check_msg->data[145] == 18, + "incorrect value for data[145], expected 18, is %d", + check_msg->data[145]); + ck_assert_msg(check_msg->data[146] == 237, + "incorrect value for data[146], expected 237, is %d", + check_msg->data[146]); + ck_assert_msg(check_msg->data[147] == 209, + "incorrect value for data[147], expected 209, is %d", + check_msg->data[147]); + ck_assert_msg(check_msg->data[148] == 187, + "incorrect value for data[148], expected 187, is %d", + check_msg->data[148]); + ck_assert_msg(check_msg->data[149] == 226, + "incorrect value for data[149], expected 226, is %d", + check_msg->data[149]); + ck_assert_msg(check_msg->data[150] == 1, + "incorrect value for data[150], expected 1, is %d", + check_msg->data[150]); + ck_assert_msg(check_msg->data[151] == 46, + "incorrect value for data[151], expected 46, is %d", + check_msg->data[151]); + ck_assert_msg(check_msg->data[152] == 64, + "incorrect value for data[152], expected 64, is %d", + check_msg->data[152]); + ck_assert_msg(check_msg->data[153] == 226, + "incorrect value for data[153], expected 226, is %d", + check_msg->data[153]); + ck_assert_msg(check_msg->data[154] == 235, + "incorrect value for data[154], expected 235, is %d", + check_msg->data[154]); + ck_assert_msg(check_msg->data[155] == 213, + "incorrect value for data[155], expected 213, is %d", + check_msg->data[155]); + ck_assert_msg(check_msg->data[156] == 186, + "incorrect value for data[156], expected 186, is %d", + check_msg->data[156]); + ck_assert_msg(check_msg->data[157] == 159, + "incorrect value for data[157], expected 159, is %d", + check_msg->data[157]); + ck_assert_msg(check_msg->data[158] == 221, + "incorrect value for data[158], expected 221, is %d", + check_msg->data[158]); + ck_assert_msg(check_msg->data[159] == 186, + "incorrect value for data[159], expected 186, is %d", + check_msg->data[159]); + ck_assert_msg(check_msg->data[160] == 25, + "incorrect value for data[160], expected 25, is %d", + check_msg->data[160]); + ck_assert_msg(check_msg->data[161] == 115, + "incorrect value for data[161], expected 115, is %d", + check_msg->data[161]); + ck_assert_msg(check_msg->data[162] == 84, + "incorrect value for data[162], expected 84, is %d", + check_msg->data[162]); + ck_assert_msg(check_msg->data[163] == 131, + "incorrect value for data[163], expected 131, is %d", + check_msg->data[163]); + ck_assert_msg(check_msg->data[164] == 167, + "incorrect value for data[164], expected 167, is %d", + check_msg->data[164]); + ck_assert_msg(check_msg->data[165] == 201, + "incorrect value for data[165], expected 201, is %d", + check_msg->data[165]); + ck_assert_msg(check_msg->data[166] == 104, + "incorrect value for data[166], expected 104, is %d", + check_msg->data[166]); + ck_assert_msg(check_msg->data[167] == 1, + "incorrect value for data[167], expected 1, is %d", + check_msg->data[167]); + ck_assert_msg(check_msg->data[168] == 200, + "incorrect value for data[168], expected 200, is %d", + check_msg->data[168]); + ck_assert_msg(check_msg->data[169] == 13, + "incorrect value for data[169], expected 13, is %d", + check_msg->data[169]); + ck_assert_msg(check_msg->data[170] == 50, + "incorrect value for data[170], expected 50, is %d", + check_msg->data[170]); + ck_assert_msg(check_msg->data[171] == 71, + "incorrect value for data[171], expected 71, is %d", + check_msg->data[171]); + ck_assert_msg(check_msg->data[172] == 73, + "incorrect value for data[172], expected 73, is %d", + check_msg->data[172]); + ck_assert_msg(check_msg->data[173] == 193, + "incorrect value for data[173], expected 193, is %d", + check_msg->data[173]); + ck_assert_msg(check_msg->data[174] == 201, + "incorrect value for data[174], expected 201, is %d", + check_msg->data[174]); + ck_assert_msg(check_msg->data[175] == 250, + "incorrect value for data[175], expected 250, is %d", + check_msg->data[175]); + ck_assert_msg(check_msg->data[176] == 172, + "incorrect value for data[176], expected 172, is %d", + check_msg->data[176]); + ck_assert_msg(check_msg->data[177] == 193, + "incorrect value for data[177], expected 193, is %d", + check_msg->data[177]); + ck_assert_msg(check_msg->data[178] == 13, + "incorrect value for data[178], expected 13, is %d", + check_msg->data[178]); + ck_assert_msg(check_msg->data[179] == 20, + "incorrect value for data[179], expected 20, is %d", + check_msg->data[179]); + ck_assert_msg(check_msg->data[180] == 238, + "incorrect value for data[180], expected 238, is %d", + check_msg->data[180]); + ck_assert_msg(check_msg->data[181] == 130, + "incorrect value for data[181], expected 130, is %d", + check_msg->data[181]); + ck_assert_msg(check_msg->data[182] == 243, + "incorrect value for data[182], expected 243, is %d", + check_msg->data[182]); + ck_assert_msg(check_msg->data[183] == 68, + "incorrect value for data[183], expected 68, is %d", + check_msg->data[183]); + ck_assert_msg(check_msg->data[184] == 4, + "incorrect value for data[184], expected 4, is %d", + check_msg->data[184]); + ck_assert_msg(check_msg->data[185] == 72, + "incorrect value for data[185], expected 72, is %d", + check_msg->data[185]); + ck_assert_msg(check_msg->data[186] == 46, + "incorrect value for data[186], expected 46, is %d", + check_msg->data[186]); + ck_assert_msg(check_msg->data[187] == 194, + "incorrect value for data[187], expected 194, is %d", + check_msg->data[187]); + ck_assert_msg(check_msg->data[188] == 113, + "incorrect value for data[188], expected 113, is %d", + check_msg->data[188]); + ck_assert_msg(check_msg->data[189] == 255, + "incorrect value for data[189], expected 255, is %d", + check_msg->data[189]); + ck_assert_msg(check_msg->data[190] == 238, + "incorrect value for data[190], expected 238, is %d", + check_msg->data[190]); + ck_assert_msg(check_msg->data[191] == 15, + "incorrect value for data[191], expected 15, is %d", + check_msg->data[191]); + ck_assert_msg(check_msg->data[192] == 230, + "incorrect value for data[192], expected 230, is %d", + check_msg->data[192]); + ck_assert_msg(check_msg->data[193] == 64, + "incorrect value for data[193], expected 64, is %d", + check_msg->data[193]); + ck_assert_msg(check_msg->data[194] == 178, + "incorrect value for data[194], expected 178, is %d", + check_msg->data[194]); + ck_assert_msg(check_msg->data[195] == 127, + "incorrect value for data[195], expected 127, is %d", + check_msg->data[195]); + ck_assert_msg(check_msg->data[196] == 217, + "incorrect value for data[196], expected 217, is %d", + check_msg->data[196]); + ck_assert_msg(check_msg->data[197] == 92, + "incorrect value for data[197], expected 92, is %d", + check_msg->data[197]); + ck_assert_msg(check_msg->data[198] == 160, + "incorrect value for data[198], expected 160, is %d", + check_msg->data[198]); + ck_assert_msg(check_msg->data[199] == 201, + "incorrect value for data[199], expected 201, is %d", + check_msg->data[199]); + ck_assert_msg(check_msg->data[200] == 118, + "incorrect value for data[200], expected 118, is %d", + check_msg->data[200]); + ck_assert_msg(check_msg->data[201] == 163, + "incorrect value for data[201], expected 163, is %d", + check_msg->data[201]); + ck_assert_msg(check_msg->data[202] == 144, + "incorrect value for data[202], expected 144, is %d", + check_msg->data[202]); + ck_assert_msg(check_msg->data[203] == 58, + "incorrect value for data[203], expected 58, is %d", + check_msg->data[203]); + ck_assert_msg(check_msg->data[204] == 28, + "incorrect value for data[204], expected 28, is %d", + check_msg->data[204]); + ck_assert_msg(check_msg->data[205] == 174, + "incorrect value for data[205], expected 174, is %d", + check_msg->data[205]); + ck_assert_msg(check_msg->data[206] == 65, + "incorrect value for data[206], expected 65, is %d", + check_msg->data[206]); + ck_assert_msg(check_msg->data[207] == 73, + "incorrect value for data[207], expected 73, is %d", + check_msg->data[207]); + ck_assert_msg(check_msg->data[208] == 45, + "incorrect value for data[208], expected 45, is %d", + check_msg->data[208]); + ck_assert_msg(check_msg->data[209] == 123, + "incorrect value for data[209], expected 123, is %d", + check_msg->data[209]); + ck_assert_msg(check_msg->data[210] == 118, + "incorrect value for data[210], expected 118, is %d", + check_msg->data[210]); + ck_assert_msg(check_msg->data[211] == 83, + "incorrect value for data[211], expected 83, is %d", + check_msg->data[211]); + ck_assert_msg(check_msg->data[212] == 107, + "incorrect value for data[212], expected 107, is %d", + check_msg->data[212]); + ck_assert_msg(check_msg->data[213] == 239, + "incorrect value for data[213], expected 239, is %d", + check_msg->data[213]); + ck_assert_msg(check_msg->data[214] == 168, + "incorrect value for data[214], expected 168, is %d", + check_msg->data[214]); + ck_assert_msg(check_msg->data[215] == 32, + "incorrect value for data[215], expected 32, is %d", + check_msg->data[215]); + ck_assert_msg(check_msg->data[216] == 212, + "incorrect value for data[216], expected 212, is %d", + check_msg->data[216]); + ck_assert_msg(check_msg->data[217] == 191, + "incorrect value for data[217], expected 191, is %d", + check_msg->data[217]); + ck_assert_msg(check_msg->data[218] == 81, + "incorrect value for data[218], expected 81, is %d", + check_msg->data[218]); + ck_assert_msg(check_msg->data[219] == 93, + "incorrect value for data[219], expected 93, is %d", + check_msg->data[219]); + ck_assert_msg(check_msg->data[220] == 186, + "incorrect value for data[220], expected 186, is %d", + check_msg->data[220]); + ck_assert_msg(check_msg->data[221] == 223, + "incorrect value for data[221], expected 223, is %d", + check_msg->data[221]); + ck_assert_msg(check_msg->data[222] == 32, + "incorrect value for data[222], expected 32, is %d", + check_msg->data[222]); + ck_assert_msg(check_msg->data[223] == 19, + "incorrect value for data[223], expected 19, is %d", + check_msg->data[223]); + ck_assert_msg(check_msg->data[224] == 58, + "incorrect value for data[224], expected 58, is %d", + check_msg->data[224]); + ck_assert_msg(check_msg->data[225] == 137, + "incorrect value for data[225], expected 137, is %d", + check_msg->data[225]); + ck_assert_msg(check_msg->data[226] == 72, + "incorrect value for data[226], expected 72, is %d", + check_msg->data[226]); + ck_assert_msg(check_msg->data[227] == 217, + "incorrect value for data[227], expected 217, is %d", + check_msg->data[227]); + ck_assert_msg(check_msg->data[228] == 151, + "incorrect value for data[228], expected 151, is %d", + check_msg->data[228]); + ck_assert_msg(check_msg->data[229] == 251, + "incorrect value for data[229], expected 251, is %d", + check_msg->data[229]); + ck_assert_msg(check_msg->data[230] == 83, + "incorrect value for data[230], expected 83, is %d", + check_msg->data[230]); + ck_assert_msg(check_msg->data[231] == 20, + "incorrect value for data[231], expected 20, is %d", + check_msg->data[231]); + ck_assert_msg(check_msg->data[232] == 113, + "incorrect value for data[232], expected 113, is %d", + check_msg->data[232]); + ck_assert_msg(check_msg->data[233] == 37, + "incorrect value for data[233], expected 37, is %d", + check_msg->data[233]); + ck_assert_msg(check_msg->data[234] == 151, + "incorrect value for data[234], expected 151, is %d", + check_msg->data[234]); + ck_assert_msg(check_msg->data[235] == 34, + "incorrect value for data[235], expected 34, is %d", + check_msg->data[235]); + ck_assert_msg(check_msg->data[236] == 37, + "incorrect value for data[236], expected 37, is %d", + check_msg->data[236]); + ck_assert_msg(check_msg->data[237] == 71, + "incorrect value for data[237], expected 71, is %d", + check_msg->data[237]); + ck_assert_msg(check_msg->data[238] == 95, + "incorrect value for data[238], expected 95, is %d", + check_msg->data[238]); + ck_assert_msg(check_msg->data[239] == 105, + "incorrect value for data[239], expected 105, is %d", + check_msg->data[239]); + ck_assert_msg(check_msg->data[240] == 235, + "incorrect value for data[240], expected 235, is %d", + check_msg->data[240]); + ck_assert_msg(check_msg->data[241] == 144, + "incorrect value for data[241], expected 144, is %d", + check_msg->data[241]); + ck_assert_msg(check_msg->data[242] == 164, + "incorrect value for data[242], expected 164, is %d", + check_msg->data[242]); + ck_assert_msg(check_msg->data[243] == 83, + "incorrect value for data[243], expected 83, is %d", + check_msg->data[243]); + ck_assert_msg(check_msg->data[244] == 197, + "incorrect value for data[244], expected 197, is %d", + check_msg->data[244]); + ck_assert_msg(check_msg->data[245] == 254, + "incorrect value for data[245], expected 254, is %d", + check_msg->data[245]); + ck_assert_msg(check_msg->data[246] == 183, + "incorrect value for data[246], expected 183, is %d", + check_msg->data[246]); + ck_assert_msg(check_msg->data[247] == 223, + "incorrect value for data[247], expected 223, is %d", + check_msg->data[247]); + ck_assert_msg(check_msg->data[248] == 91, + "incorrect value for data[248], expected 91, is %d", + check_msg->data[248]); + ck_assert_msg(check_msg->data[249] == 19, + "incorrect value for data[249], expected 19, is %d", + check_msg->data[249]); + ck_assert_msg(check_msg->target == 212, + "incorrect value for target, expected 212, is %d", + check_msg->target); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgFlashProgram_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_flash_MsgFlashProgram"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgFlashProgram"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgFlashProgram); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgFlashReadReq.c b/c/test/legacy/auto_check_sbp_flash_MsgFlashReadReq.c new file mode 100644 index 0000000000..0d18fa5434 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgFlashReadReq.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgFlashReadReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe7, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe7, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_flash_read_req_t *test_msg = (msg_flash_read_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->addr_len = 71; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[0] = 28; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[1] = 75; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[2] = 244; + test_msg->target = 241; + sbp_payload_send(&sbp_state, 0xe7, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe7, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_flash_read_req_t *check_msg = + (msg_flash_read_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->addr_len == 71, + "incorrect value for addr_len, expected 71, is %d", + check_msg->addr_len); + ck_assert_msg(check_msg->addr_start[0] == 28, + "incorrect value for addr_start[0], expected 28, is %d", + check_msg->addr_start[0]); + ck_assert_msg(check_msg->addr_start[1] == 75, + "incorrect value for addr_start[1], expected 75, is %d", + check_msg->addr_start[1]); + ck_assert_msg(check_msg->addr_start[2] == 244, + "incorrect value for addr_start[2], expected 244, is %d", + check_msg->addr_start[2]); + ck_assert_msg(check_msg->target == 241, + "incorrect value for target, expected 241, is %d", + check_msg->target); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgFlashReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_flash_MsgFlashReadReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgFlashReadReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgFlashReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgFlashReadResp.c b/c/test/legacy/auto_check_sbp_flash_MsgFlashReadResp.c new file mode 100644 index 0000000000..6473ae3f3a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgFlashReadResp.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgFlashReadResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe1, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_flash_read_resp_t *test_msg = (msg_flash_read_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->addr_len = 124; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[0] = 155; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[1] = 52; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->addr_start[0]); + } + test_msg->addr_start[2] = 172; + test_msg->target = 136; + sbp_payload_send(&sbp_state, 0xe1, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe1, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_flash_read_resp_t *check_msg = + (msg_flash_read_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->addr_len == 124, + "incorrect value for addr_len, expected 124, is %d", + check_msg->addr_len); + ck_assert_msg(check_msg->addr_start[0] == 155, + "incorrect value for addr_start[0], expected 155, is %d", + check_msg->addr_start[0]); + ck_assert_msg(check_msg->addr_start[1] == 52, + "incorrect value for addr_start[1], expected 52, is %d", + check_msg->addr_start[1]); + ck_assert_msg(check_msg->addr_start[2] == 172, + "incorrect value for addr_start[2], expected 172, is %d", + check_msg->addr_start[2]); + ck_assert_msg(check_msg->target == 136, + "incorrect value for target, expected 136, is %d", + check_msg->target); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgFlashReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_flash_MsgFlashReadResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgFlashReadResp"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgFlashReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgM25FlashWriteStatus.c b/c/test/legacy/auto_check_sbp_flash_MsgM25FlashWriteStatus.c new file mode 100644 index 0000000000..5cb31947cb --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgM25FlashWriteStatus.c @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xf3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xf3, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 243, 0, 195, 4, 1, 5, 112, 200, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_m25_flash_write_status_t *test_msg = + (msg_m25_flash_write_status_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[0] = 5; + sbp_payload_send(&sbp_state, 0xf3, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xf3, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_m25_flash_write_status_t *check_msg = + (msg_m25_flash_write_status_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->status[0] == 5, + "incorrect value for status[0], expected 5, is %d", + check_msg->status[0]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgStmFlashLockSector.c b/c/test/legacy/auto_check_sbp_flash_MsgStmFlashLockSector.c new file mode 100644 index 0000000000..11461e8394 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgStmFlashLockSector.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgStmFlashLockSector) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe3, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe3, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_stm_flash_lock_sector_t *test_msg = + (msg_stm_flash_lock_sector_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->sector = 1137047457; + sbp_payload_send(&sbp_state, 0xe3, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe3, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_stm_flash_lock_sector_t *check_msg = + (msg_stm_flash_lock_sector_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->sector == 1137047457, + "incorrect value for sector, expected 1137047457, is %d", + check_msg->sector); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgStmFlashLockSector_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_flash_MsgStmFlashLockSector"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgStmFlashLockSector"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_flash_MsgStmFlashLockSector); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgStmFlashUnlockSector.c b/c/test/legacy/auto_check_sbp_flash_MsgStmFlashUnlockSector.c new file mode 100644 index 0000000000..9654fffbc0 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgStmFlashUnlockSector.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe4, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe4, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_stm_flash_unlock_sector_t *test_msg = + (msg_stm_flash_unlock_sector_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->sector = 837226527; + sbp_payload_send(&sbp_state, 0xe4, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe4, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_stm_flash_unlock_sector_t *check_msg = + (msg_stm_flash_unlock_sector_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->sector == 837226527, + "incorrect value for sector, expected 837226527, is %d", + check_msg->sector); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdReq.c b/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdReq.c new file mode 100644 index 0000000000..c8501fa180 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdReq.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgStmUniqueIdReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe8, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 232, 0, 195, 4, 0, 66, 138, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xe8, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe8, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgStmUniqueIdReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_flash_MsgStmUniqueIdReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgStmUniqueIdReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgStmUniqueIdReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdResp.c b/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdResp.c new file mode 100644 index 0000000000..f4641e10f3 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_flash_MsgStmUniqueIdResp.c @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xe5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xe5, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, + 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_stm_unique_id_resp_t *test_msg = + (msg_stm_unique_id_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[0] = 196; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[1] = 16; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[2] = 15; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[3] = 163; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[4] = 85; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[5] = 221; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[6] = 119; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[7] = 102; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[8] = 32; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[9] = 194; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[10] = 56; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stm_id[0]); + } + test_msg->stm_id[11] = 144; + sbp_payload_send(&sbp_state, 0xe5, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xe5, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_stm_unique_id_resp_t *check_msg = + (msg_stm_unique_id_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->stm_id[0] == 196, + "incorrect value for stm_id[0], expected 196, is %d", + check_msg->stm_id[0]); + ck_assert_msg(check_msg->stm_id[1] == 16, + "incorrect value for stm_id[1], expected 16, is %d", + check_msg->stm_id[1]); + ck_assert_msg(check_msg->stm_id[2] == 15, + "incorrect value for stm_id[2], expected 15, is %d", + check_msg->stm_id[2]); + ck_assert_msg(check_msg->stm_id[3] == 163, + "incorrect value for stm_id[3], expected 163, is %d", + check_msg->stm_id[3]); + ck_assert_msg(check_msg->stm_id[4] == 85, + "incorrect value for stm_id[4], expected 85, is %d", + check_msg->stm_id[4]); + ck_assert_msg(check_msg->stm_id[5] == 221, + "incorrect value for stm_id[5], expected 221, is %d", + check_msg->stm_id[5]); + ck_assert_msg(check_msg->stm_id[6] == 119, + "incorrect value for stm_id[6], expected 119, is %d", + check_msg->stm_id[6]); + ck_assert_msg(check_msg->stm_id[7] == 102, + "incorrect value for stm_id[7], expected 102, is %d", + check_msg->stm_id[7]); + ck_assert_msg(check_msg->stm_id[8] == 32, + "incorrect value for stm_id[8], expected 32, is %d", + check_msg->stm_id[8]); + ck_assert_msg(check_msg->stm_id[9] == 194, + "incorrect value for stm_id[9], expected 194, is %d", + check_msg->stm_id[9]); + ck_assert_msg(check_msg->stm_id[10] == 56, + "incorrect value for stm_id[10], expected 56, is %d", + check_msg->stm_id[10]); + ck_assert_msg(check_msg->stm_id[11] == 144, + "incorrect value for stm_id[11], expected 144, is %d", + check_msg->stm_id[11]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_flash_MsgStmUniqueIdResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_flash_MsgStmUniqueIdResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuState.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuState.c new file mode 100644 index 0000000000..af03f57c34 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuState.c @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxCpuState) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f08, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f08, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, + 235, 20, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, 229, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_cpu_state_t *test_msg = (msg_linux_cpu_state_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->flags = 20; + test_msg->index = 101; + test_msg->pcpu = 98; + test_msg->pid = 50042; + test_msg->time = 3948815319; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0x7f08, 34196, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34196, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 34196, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f08, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_cpu_state_t *check_msg = + (msg_linux_cpu_state_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->flags == 20, + "incorrect value for flags, expected 20, is %d", + check_msg->flags); + ck_assert_msg(check_msg->index == 101, + "incorrect value for index, expected 101, is %d", + check_msg->index); + ck_assert_msg(check_msg->pcpu == 98, + "incorrect value for pcpu, expected 98, is %d", + check_msg->pcpu); + ck_assert_msg(check_msg->pid == 50042, + "incorrect value for pid, expected 50042, is %d", + check_msg->pid); + ck_assert_msg(check_msg->time == 3948815319, + "incorrect value for time, expected 3948815319, is %d", + check_msg->time); + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(check_msg->tname, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->tname, expected string '%s', is '%s'", + check_string, check_msg->tname); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxCpuState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_linux_MsgLinuxCpuState"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxCpuState"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxCpuState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c new file mode 100644 index 0000000000..1811d8db5a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxCpuStateDepA.c @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f00, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f00, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, + 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, + 51, 32, 97, 114, 103, 52, 80, 48, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_cpu_state_dep_a_t *test_msg = + (msg_linux_cpu_state_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->index = 51; + test_msg->pcpu = 178; + test_msg->pid = 64240; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0x7f00, 23308, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 23308, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 23308, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f00, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_cpu_state_dep_a_t *check_msg = + (msg_linux_cpu_state_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->index == 51, + "incorrect value for index, expected 51, is %d", + check_msg->index); + ck_assert_msg(check_msg->pcpu == 178, + "incorrect value for pcpu, expected 178, is %d", + check_msg->pcpu); + ck_assert_msg(check_msg->pid == 64240, + "incorrect value for pid, expected 64240, is %d", + check_msg->pid); + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(check_msg->tname, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->tname, expected string '%s', is '%s'", + check_string, check_msg->tname); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemState.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemState.c new file mode 100644 index 0000000000..2ba35128f5 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemState.c @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxMemState) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f09, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f09, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, + 187, 76, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_mem_state_t *test_msg = (msg_linux_mem_state_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->flags = 76; + test_msg->index = 154; + test_msg->pid = 57279; + test_msg->pmem = 19; + test_msg->time = 3139057143; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0x7f09, 64863, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 64863, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 64863, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f09, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_mem_state_t *check_msg = + (msg_linux_mem_state_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->flags == 76, + "incorrect value for flags, expected 76, is %d", + check_msg->flags); + ck_assert_msg(check_msg->index == 154, + "incorrect value for index, expected 154, is %d", + check_msg->index); + ck_assert_msg(check_msg->pid == 57279, + "incorrect value for pid, expected 57279, is %d", + check_msg->pid); + ck_assert_msg(check_msg->pmem == 19, + "incorrect value for pmem, expected 19, is %d", + check_msg->pmem); + ck_assert_msg(check_msg->time == 3139057143, + "incorrect value for time, expected 3139057143, is %d", + check_msg->time); + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(check_msg->tname, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->tname, expected string '%s', is '%s'", + check_string, check_msg->tname); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxMemState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_linux_MsgLinuxMemState"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxMemState"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxMemState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemStateDepA.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemStateDepA.c new file mode 100644 index 0000000000..554892058e --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxMemStateDepA.c @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f01, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f01, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, + 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, + 51, 32, 97, 114, 103, 52, 17, 137, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_mem_state_dep_a_t *test_msg = + (msg_linux_mem_state_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->index = 247; + test_msg->pid = 12381; + test_msg->pmem = 193; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0x7f01, 28089, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 28089, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 28089, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f01, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_mem_state_dep_a_t *check_msg = + (msg_linux_mem_state_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->index == 247, + "incorrect value for index, expected 247, is %d", + check_msg->index); + ck_assert_msg(check_msg->pid == 12381, + "incorrect value for pid, expected 12381, is %d", + check_msg->pid); + ck_assert_msg(check_msg->pmem == 193, + "incorrect value for pmem, expected 193, is %d", + check_msg->pmem); + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + ck_assert_msg( + memcmp(check_msg->tname, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->tname, expected string '%s', is '%s'", + check_string, check_msg->tname); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdCount.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdCount.c new file mode 100644 index 0000000000..a8cd7664c2 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdCount.c @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f06, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f06, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, + 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, + 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 94, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_process_fd_count_t *test_msg = + (msg_linux_process_fd_count_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->fd_count = 35589; + test_msg->index = 164; + test_msg->pid = 42429; + sbp_payload_send(&sbp_state, 0x7f06, 49950, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 49950, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 49950, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f06, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_process_fd_count_t *check_msg = + (msg_linux_process_fd_count_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->fd_count == 35589, + "incorrect value for fd_count, expected 35589, is %d", + check_msg->fd_count); + ck_assert_msg(check_msg->index == 164, + "incorrect value for index, expected 164, is %d", + check_msg->index); + ck_assert_msg(check_msg->pid == 42429, + "incorrect value for pid, expected 42429, is %d", + check_msg->pid); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c new file mode 100644 index 0000000000..de84a37aff --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessFdSummary.c @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f07, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f07, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, + 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, + 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_process_fd_summary_t *test_msg = + (msg_linux_process_fd_summary_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)102, (char)100, (char)49, (char)0, (char)102, + (char)100, (char)50, (char)0, (char)102, (char)100, + (char)51, (char)0, (char)102, (char)100, (char)52, + (char)0, (char)102, (char)100, (char)53, (char)0, + (char)102, (char)100, (char)54, (char)0, (char)0}; + memcpy(test_msg->most_opened, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->most_opened) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->sys_fd_count = 1304986387; + sbp_payload_send(&sbp_state, 0x7f07, 63591, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63591, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 63591, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f07, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_process_fd_summary_t *check_msg = + (msg_linux_process_fd_summary_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)102, (char)100, (char)49, (char)0, (char)102, + (char)100, (char)50, (char)0, (char)102, (char)100, + (char)51, (char)0, (char)102, (char)100, (char)52, + (char)0, (char)102, (char)100, (char)53, (char)0, + (char)102, (char)100, (char)54, (char)0, (char)0}; + ck_assert_msg(memcmp(check_msg->most_opened, check_string, + sizeof(check_string)) == 0, + "incorrect value for check_msg->most_opened, expected " + "string '%s', is '%s'", + check_string, check_msg->most_opened); + } + ck_assert_msg( + check_msg->sys_fd_count == 1304986387, + "incorrect value for sys_fd_count, expected 1304986387, is %d", + check_msg->sys_fd_count); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c new file mode 100644 index 0000000000..8fa2ef9a76 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.c @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f03, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f03, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, + 114, 115, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, + 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 180, 131, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_process_socket_counts_t *test_msg = + (msg_linux_process_socket_counts_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->index = 51; + test_msg->pid = 28553; + test_msg->socket_count = 30287; + test_msg->socket_states = 29554; + test_msg->socket_types = 35843; + sbp_payload_send(&sbp_state, 0x7f03, 2412, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 2412, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 2412, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f03, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_process_socket_counts_t *check_msg = + (msg_linux_process_socket_counts_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->index == 51, + "incorrect value for index, expected 51, is %d", + check_msg->index); + ck_assert_msg(check_msg->pid == 28553, + "incorrect value for pid, expected 28553, is %d", + check_msg->pid); + ck_assert_msg(check_msg->socket_count == 30287, + "incorrect value for socket_count, expected 30287, is %d", + check_msg->socket_count); + ck_assert_msg(check_msg->socket_states == 29554, + "incorrect value for socket_states, expected 29554, is %d", + check_msg->socket_states); + ck_assert_msg(check_msg->socket_types == 35843, + "incorrect value for socket_types, expected 35843, is %d", + check_msg->socket_types); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_" + "MsgLinuxProcessSocketCounts"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c new file mode 100644 index 0000000000..acf9ea4227 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.c @@ -0,0 +1,308 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f04, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f04, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, + 80, 109, 15, 223, 97, 100, 100, 114, 101, 115, 115, 32, 111, + 102, 32, 108, 97, 114, 103, 101, 115, 116, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, + 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, + 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, + 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 247, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_process_socket_queues_t *test_msg = + (msg_linux_process_socket_queues_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg->address_of_largest, assign_string, + sizeof(assign_string)); + if (sizeof(test_msg->address_of_largest) == 0) { + test_msg_len += sizeof(assign_string); + } + } + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->index = 181; + test_msg->pid = 19335; + test_msg->recv_queued = 54265; + test_msg->send_queued = 64547; + test_msg->socket_states = 57103; + test_msg->socket_types = 27984; + sbp_payload_send(&sbp_state, 0x7f04, 59579, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 59579, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 59579, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f04, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_process_socket_queues_t *check_msg = + (msg_linux_process_socket_queues_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + ck_assert_msg(memcmp(check_msg->address_of_largest, check_string, + sizeof(check_string)) == 0, + "incorrect value for check_msg->address_of_largest, " + "expected string '%s', is '%s'", + check_string, check_msg->address_of_largest); + } + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + ck_assert_msg( + memcmp(check_msg->cmdline, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->cmdline, expected string '%s', is " + "'%s'", + check_string, check_msg->cmdline); + } + ck_assert_msg(check_msg->index == 181, + "incorrect value for index, expected 181, is %d", + check_msg->index); + ck_assert_msg(check_msg->pid == 19335, + "incorrect value for pid, expected 19335, is %d", + check_msg->pid); + ck_assert_msg(check_msg->recv_queued == 54265, + "incorrect value for recv_queued, expected 54265, is %d", + check_msg->recv_queued); + ck_assert_msg(check_msg->send_queued == 64547, + "incorrect value for send_queued, expected 64547, is %d", + check_msg->send_queued); + ck_assert_msg(check_msg->socket_states == 57103, + "incorrect value for socket_states, expected 57103, is %d", + check_msg->socket_states); + ck_assert_msg(check_msg->socket_types == 27984, + "incorrect value for socket_types, expected 27984, is %d", + check_msg->socket_types); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_" + "MsgLinuxProcessSocketQueues"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxSocketUsage.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSocketUsage.c new file mode 100644 index 0000000000..c62234686e --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSocketUsage.c @@ -0,0 +1,507 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f05, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f05, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, + 246, 154, 251, 17, 224, 179, 26, 169, 177, 90, 149, 213, 214, 6, + 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, 217, 209, 52, 14, + 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, + 176, 74, 159, 129, 154, 153, 162, 229, 130, 154, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_socket_usage_t *test_msg = + (msg_linux_socket_usage_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->avg_queue_depth = 2907030541; + test_msg->max_queue_depth = 3048922691; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[0] = 39670; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[1] = 4603; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[2] = 46048; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[3] = 43290; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[4] = 23217; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[5] = 54677; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[6] = 1750; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[7] = 16510; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[8] = 47480; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[9] = 33620; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[10] = 28616; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[11] = 36128; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[12] = 53721; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[13] = 3636; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[14] = 37822; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_state_counts[0]); + } + test_msg->socket_state_counts[15] = 63135; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[0] = 31373; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[1] = 30676; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[2] = 7811; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[3] = 12152; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[4] = 27929; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[5] = 16794; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[6] = 42116; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[7] = 7719; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[8] = 44830; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[9] = 11272; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[10] = 28444; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[11] = 61676; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[12] = 19120; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[13] = 33183; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[14] = 39322; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->socket_type_counts[0]); + } + test_msg->socket_type_counts[15] = 58786; + sbp_payload_send(&sbp_state, 0x7f05, 35442, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 35442, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 35442, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f05, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_socket_usage_t *check_msg = + (msg_linux_socket_usage_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->avg_queue_depth == 2907030541, + "incorrect value for avg_queue_depth, expected 2907030541, is %d", + check_msg->avg_queue_depth); + ck_assert_msg( + check_msg->max_queue_depth == 3048922691, + "incorrect value for max_queue_depth, expected 3048922691, is %d", + check_msg->max_queue_depth); + ck_assert_msg( + check_msg->socket_state_counts[0] == 39670, + "incorrect value for socket_state_counts[0], expected 39670, is %d", + check_msg->socket_state_counts[0]); + ck_assert_msg( + check_msg->socket_state_counts[1] == 4603, + "incorrect value for socket_state_counts[1], expected 4603, is %d", + check_msg->socket_state_counts[1]); + ck_assert_msg( + check_msg->socket_state_counts[2] == 46048, + "incorrect value for socket_state_counts[2], expected 46048, is %d", + check_msg->socket_state_counts[2]); + ck_assert_msg( + check_msg->socket_state_counts[3] == 43290, + "incorrect value for socket_state_counts[3], expected 43290, is %d", + check_msg->socket_state_counts[3]); + ck_assert_msg( + check_msg->socket_state_counts[4] == 23217, + "incorrect value for socket_state_counts[4], expected 23217, is %d", + check_msg->socket_state_counts[4]); + ck_assert_msg( + check_msg->socket_state_counts[5] == 54677, + "incorrect value for socket_state_counts[5], expected 54677, is %d", + check_msg->socket_state_counts[5]); + ck_assert_msg( + check_msg->socket_state_counts[6] == 1750, + "incorrect value for socket_state_counts[6], expected 1750, is %d", + check_msg->socket_state_counts[6]); + ck_assert_msg( + check_msg->socket_state_counts[7] == 16510, + "incorrect value for socket_state_counts[7], expected 16510, is %d", + check_msg->socket_state_counts[7]); + ck_assert_msg( + check_msg->socket_state_counts[8] == 47480, + "incorrect value for socket_state_counts[8], expected 47480, is %d", + check_msg->socket_state_counts[8]); + ck_assert_msg( + check_msg->socket_state_counts[9] == 33620, + "incorrect value for socket_state_counts[9], expected 33620, is %d", + check_msg->socket_state_counts[9]); + ck_assert_msg( + check_msg->socket_state_counts[10] == 28616, + "incorrect value for socket_state_counts[10], expected 28616, is %d", + check_msg->socket_state_counts[10]); + ck_assert_msg( + check_msg->socket_state_counts[11] == 36128, + "incorrect value for socket_state_counts[11], expected 36128, is %d", + check_msg->socket_state_counts[11]); + ck_assert_msg( + check_msg->socket_state_counts[12] == 53721, + "incorrect value for socket_state_counts[12], expected 53721, is %d", + check_msg->socket_state_counts[12]); + ck_assert_msg( + check_msg->socket_state_counts[13] == 3636, + "incorrect value for socket_state_counts[13], expected 3636, is %d", + check_msg->socket_state_counts[13]); + ck_assert_msg( + check_msg->socket_state_counts[14] == 37822, + "incorrect value for socket_state_counts[14], expected 37822, is %d", + check_msg->socket_state_counts[14]); + ck_assert_msg( + check_msg->socket_state_counts[15] == 63135, + "incorrect value for socket_state_counts[15], expected 63135, is %d", + check_msg->socket_state_counts[15]); + ck_assert_msg( + check_msg->socket_type_counts[0] == 31373, + "incorrect value for socket_type_counts[0], expected 31373, is %d", + check_msg->socket_type_counts[0]); + ck_assert_msg( + check_msg->socket_type_counts[1] == 30676, + "incorrect value for socket_type_counts[1], expected 30676, is %d", + check_msg->socket_type_counts[1]); + ck_assert_msg( + check_msg->socket_type_counts[2] == 7811, + "incorrect value for socket_type_counts[2], expected 7811, is %d", + check_msg->socket_type_counts[2]); + ck_assert_msg( + check_msg->socket_type_counts[3] == 12152, + "incorrect value for socket_type_counts[3], expected 12152, is %d", + check_msg->socket_type_counts[3]); + ck_assert_msg( + check_msg->socket_type_counts[4] == 27929, + "incorrect value for socket_type_counts[4], expected 27929, is %d", + check_msg->socket_type_counts[4]); + ck_assert_msg( + check_msg->socket_type_counts[5] == 16794, + "incorrect value for socket_type_counts[5], expected 16794, is %d", + check_msg->socket_type_counts[5]); + ck_assert_msg( + check_msg->socket_type_counts[6] == 42116, + "incorrect value for socket_type_counts[6], expected 42116, is %d", + check_msg->socket_type_counts[6]); + ck_assert_msg( + check_msg->socket_type_counts[7] == 7719, + "incorrect value for socket_type_counts[7], expected 7719, is %d", + check_msg->socket_type_counts[7]); + ck_assert_msg( + check_msg->socket_type_counts[8] == 44830, + "incorrect value for socket_type_counts[8], expected 44830, is %d", + check_msg->socket_type_counts[8]); + ck_assert_msg( + check_msg->socket_type_counts[9] == 11272, + "incorrect value for socket_type_counts[9], expected 11272, is %d", + check_msg->socket_type_counts[9]); + ck_assert_msg( + check_msg->socket_type_counts[10] == 28444, + "incorrect value for socket_type_counts[10], expected 28444, is %d", + check_msg->socket_type_counts[10]); + ck_assert_msg( + check_msg->socket_type_counts[11] == 61676, + "incorrect value for socket_type_counts[11], expected 61676, is %d", + check_msg->socket_type_counts[11]); + ck_assert_msg( + check_msg->socket_type_counts[12] == 19120, + "incorrect value for socket_type_counts[12], expected 19120, is %d", + check_msg->socket_type_counts[12]); + ck_assert_msg( + check_msg->socket_type_counts[13] == 33183, + "incorrect value for socket_type_counts[13], expected 33183, is %d", + check_msg->socket_type_counts[13]); + ck_assert_msg( + check_msg->socket_type_counts[14] == 39322, + "incorrect value for socket_type_counts[14], expected 39322, is %d", + check_msg->socket_type_counts[14]); + ck_assert_msg( + check_msg->socket_type_counts[15] == 58786, + "incorrect value for socket_type_counts[15], expected 58786, is %d", + check_msg->socket_type_counts[15]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxSocketUsage_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxSocketUsage"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysState.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysState.c new file mode 100644 index 0000000000..9cbc71cb89 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysState.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxSysState) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f0a, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f0a, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, + 161, 229, 250, 186, 108, 30, 106, 5, 9, 229, 242, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_sys_state_t *test_msg = (msg_linux_sys_state_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 9; + test_msg->mem_total = 53012; + test_msg->pcpu = 125; + test_msg->pid_count = 47866; + test_msg->pmem = 215; + test_msg->procs_starting = 18372; + test_msg->procs_stopping = 58785; + test_msg->time = 90840684; + sbp_payload_send(&sbp_state, 0x7f0a, 42837, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 42837, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 42837, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f0a, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_sys_state_t *check_msg = + (msg_linux_sys_state_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 9, + "incorrect value for flags, expected 9, is %d", + check_msg->flags); + ck_assert_msg(check_msg->mem_total == 53012, + "incorrect value for mem_total, expected 53012, is %d", + check_msg->mem_total); + ck_assert_msg(check_msg->pcpu == 125, + "incorrect value for pcpu, expected 125, is %d", + check_msg->pcpu); + ck_assert_msg(check_msg->pid_count == 47866, + "incorrect value for pid_count, expected 47866, is %d", + check_msg->pid_count); + ck_assert_msg(check_msg->pmem == 215, + "incorrect value for pmem, expected 215, is %d", + check_msg->pmem); + ck_assert_msg(check_msg->procs_starting == 18372, + "incorrect value for procs_starting, expected 18372, is %d", + check_msg->procs_starting); + ck_assert_msg(check_msg->procs_stopping == 58785, + "incorrect value for procs_stopping, expected 58785, is %d", + check_msg->procs_stopping); + ck_assert_msg(check_msg->time == 90840684, + "incorrect value for time, expected 90840684, is %d", + check_msg->time); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxSysState_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_linux_MsgLinuxSysState"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxSysState"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxSysState); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysStateDepA.c b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysStateDepA.c new file mode 100644 index 0000000000..f48b472d46 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_linux_MsgLinuxSysStateDepA.c @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x7f02, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x7f02, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 2, 127, 84, 56, 10, 188, 163, 211, + 194, 115, 71, 101, 103, 124, 201, 223, 223, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_linux_sys_state_dep_a_t *test_msg = + (msg_linux_sys_state_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->mem_total = 41916; + test_msg->pcpu = 211; + test_msg->pid_count = 51580; + test_msg->pmem = 194; + test_msg->procs_starting = 18291; + test_msg->procs_stopping = 26469; + sbp_payload_send(&sbp_state, 0x7f02, 14420, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14420, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 14420, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x7f02, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_linux_sys_state_dep_a_t *check_msg = + (msg_linux_sys_state_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->mem_total == 41916, + "incorrect value for mem_total, expected 41916, is %d", + check_msg->mem_total); + ck_assert_msg(check_msg->pcpu == 211, + "incorrect value for pcpu, expected 211, is %d", + check_msg->pcpu); + ck_assert_msg(check_msg->pid_count == 51580, + "incorrect value for pid_count, expected 51580, is %d", + check_msg->pid_count); + ck_assert_msg(check_msg->pmem == 194, + "incorrect value for pmem, expected 194, is %d", + check_msg->pmem); + ck_assert_msg(check_msg->procs_starting == 18291, + "incorrect value for procs_starting, expected 18291, is %d", + check_msg->procs_starting); + ck_assert_msg(check_msg->procs_stopping == 26469, + "incorrect value for procs_stopping, expected 26469, is %d", + check_msg->procs_stopping); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_mag_MsgMagRaw.c b/c/test/legacy/auto_check_sbp_mag_MsgMagRaw.c new file mode 100644 index 0000000000..8381be544f --- /dev/null +++ b/c/test/legacy/auto_check_sbp_mag_MsgMagRaw.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_mag_MsgMagRaw) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x902, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x902, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, + 206, 98, 3, 230, 2, 110, 229, 159, 23, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_mag_raw_t *test_msg = (msg_mag_raw_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->mag_x = 866; + test_msg->mag_y = 742; + test_msg->mag_z = -6802; + test_msg->tow = 3332301741; + test_msg->tow_f = 206; + sbp_payload_send(&sbp_state, 0x902, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x902, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_mag_raw_t *check_msg = (msg_mag_raw_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->mag_x == 866, + "incorrect value for mag_x, expected 866, is %d", + check_msg->mag_x); + ck_assert_msg(check_msg->mag_y == 742, + "incorrect value for mag_y, expected 742, is %d", + check_msg->mag_y); + ck_assert_msg(check_msg->mag_z == -6802, + "incorrect value for mag_z, expected -6802, is %d", + check_msg->mag_z); + ck_assert_msg(check_msg->tow == 3332301741, + "incorrect value for tow, expected 3332301741, is %d", + check_msg->tow); + ck_assert_msg(check_msg->tow_f == 206, + "incorrect value for tow_f, expected 206, is %d", + check_msg->tow_f); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_mag_MsgMagRaw_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_mag_MsgMagRaw"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_mag_MsgMagRaw"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_mag_MsgMagRaw); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c b/c/test/legacy/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c new file mode 100644 index 0000000000..1e74a5b456 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_navigation_MsgBaselineHeadingDepA.c @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x207, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x207, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 7, 2, 124, 206, 10, 82, 109, 88, + 176, 68, 14, 82, 203, 186, 58, 173, 182, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_baseline_heading_dep_a_t *test_msg = + (msg_baseline_heading_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 58; + test_msg->heading = 3411152452; + test_msg->n_sats = 186; + test_msg->tow = 2958585170; + sbp_payload_send(&sbp_state, 0x207, 52860, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52860, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 52860, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x207, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_baseline_heading_dep_a_t *check_msg = + (msg_baseline_heading_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 58, + "incorrect value for flags, expected 58, is %d", + check_msg->flags); + ck_assert_msg(check_msg->heading == 3411152452, + "incorrect value for heading, expected 3411152452, is %d", + check_msg->heading); + ck_assert_msg(check_msg->n_sats == 186, + "incorrect value for n_sats, expected 186, is %d", + check_msg->n_sats); + ck_assert_msg(check_msg->tow == 2958585170, + "incorrect value for tow, expected 2958585170, is %d", + check_msg->tow); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_navigation_" + "MsgBaselineHeadingDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_navigation_MsgPosLlhAcc.c b/c/test/legacy/auto_check_sbp_navigation_MsgPosLlhAcc.c new file mode 100644 index 0000000000..245322998b --- /dev/null +++ b/c/test/legacy/auto_check_sbp_navigation_MsgPosLlhAcc.c @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_navigation_MsgPosLlhAcc) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x218, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x218, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, + 51, 51, 139, 189, 64, 154, 153, 153, 153, 25, 151, 192, 64, + 51, 51, 51, 51, 51, 161, 176, 64, 51, 51, 51, 51, 51, + 101, 179, 64, 51, 163, 22, 69, 154, 25, 173, 69, 102, 134, + 243, 68, 154, 201, 196, 69, 205, 224, 0, 70, 51, 35, 72, + 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_pos_llh_acc_t *test_msg = (msg_pos_llh_acc_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->at_accuracy = 6297.2001953125; + test_msg->confidence_and_geoid = 95; + test_msg->ct_accuracy = 1948.199951171875; + test_msg->flags = 72; + test_msg->h_accuracy = 2410.199951171875; + test_msg->h_ellipse.orientation = 2550.199951171875; + test_msg->h_ellipse.semi_major = 8248.2001953125; + test_msg->h_ellipse.semi_minor = 3202.199951171875; + test_msg->height = 4257.2; + test_msg->lat = 7563.2; + test_msg->lon = 8494.2; + test_msg->n_sats = 27; + test_msg->orthometric_height = 4965.2; + test_msg->tow = 309229607; + test_msg->v_accuracy = 5539.2001953125; + sbp_payload_send(&sbp_state, 0x218, 7170, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 7170, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 7170, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x218, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_pos_llh_acc_t *check_msg = (msg_pos_llh_acc_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->at_accuracy * 100 - 6297.20019531 * 100) < 0.05, + "incorrect value for at_accuracy, expected 6297.20019531, is %f", + check_msg->at_accuracy); + ck_assert_msg( + check_msg->confidence_and_geoid == 95, + "incorrect value for confidence_and_geoid, expected 95, is %d", + check_msg->confidence_and_geoid); + ck_assert_msg( + (check_msg->ct_accuracy * 100 - 1948.19995117 * 100) < 0.05, + "incorrect value for ct_accuracy, expected 1948.19995117, is %f", + check_msg->ct_accuracy); + ck_assert_msg(check_msg->flags == 72, + "incorrect value for flags, expected 72, is %d", + check_msg->flags); + ck_assert_msg( + (check_msg->h_accuracy * 100 - 2410.19995117 * 100) < 0.05, + "incorrect value for h_accuracy, expected 2410.19995117, is %f", + check_msg->h_accuracy); + ck_assert_msg( + (check_msg->h_ellipse.orientation * 100 - 2550.19995117 * 100) < 0.05, + "incorrect value for h_ellipse.orientation, expected 2550.19995117, is " + "%f", + check_msg->h_ellipse.orientation); + ck_assert_msg( + (check_msg->h_ellipse.semi_major * 100 - 8248.20019531 * 100) < 0.05, + "incorrect value for h_ellipse.semi_major, expected 8248.20019531, is " + "%f", + check_msg->h_ellipse.semi_major); + ck_assert_msg( + (check_msg->h_ellipse.semi_minor * 100 - 3202.19995117 * 100) < 0.05, + "incorrect value for h_ellipse.semi_minor, expected 3202.19995117, is " + "%f", + check_msg->h_ellipse.semi_minor); + ck_assert_msg((check_msg->height * 100 - 4257.2 * 100) < 0.05, + "incorrect value for height, expected 4257.2, is %f", + check_msg->height); + ck_assert_msg((check_msg->lat * 100 - 7563.2 * 100) < 0.05, + "incorrect value for lat, expected 7563.2, is %f", + check_msg->lat); + ck_assert_msg((check_msg->lon * 100 - 8494.2 * 100) < 0.05, + "incorrect value for lon, expected 8494.2, is %f", + check_msg->lon); + ck_assert_msg(check_msg->n_sats == 27, + "incorrect value for n_sats, expected 27, is %d", + check_msg->n_sats); + ck_assert_msg( + (check_msg->orthometric_height * 100 - 4965.2 * 100) < 0.05, + "incorrect value for orthometric_height, expected 4965.2, is %f", + check_msg->orthometric_height); + ck_assert_msg(check_msg->tow == 309229607, + "incorrect value for tow, expected 309229607, is %d", + check_msg->tow); + ck_assert_msg( + (check_msg->v_accuracy * 100 - 5539.20019531 * 100) < 0.05, + "incorrect value for v_accuracy, expected 5539.20019531, is %f", + check_msg->v_accuracy); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_navigation_MsgPosLlhAcc_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_navigation_MsgPosLlhAcc"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_navigation_MsgPosLlhAcc"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_navigation_MsgPosLlhAcc); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevel.c b/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevel.c index 44f53c1a9c..e9c8cc397a 100644 --- a/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevel.c +++ b/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevel.c @@ -116,15 +116,18 @@ START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevel) { logging_reset(); - sbp_payload_callback_register(&sbp_state, 0x216, &msg_callback, + sbp_payload_callback_register(&sbp_state, 0x217, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); - sbp_frame_callback_register(&sbp_state, 0x216, &frame_callback, + sbp_frame_callback_register(&sbp_state, 0x217, &frame_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n2); u8 encoded_frame[] = { - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, + 89, 84, 167, 41, 57, 21, 217, 244, 61, 161, 83, 104, 140, 137, + 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, 153, 153, + 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, + 38, 221, 208, 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, + 235, 227, 183, 160, 187, 93, 116, 224, 105, 40, 32, 33, 133, 188, }; dummy_reset(); @@ -132,17 +135,31 @@ START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevel) { u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; memset(test_msg_storage, 0, sizeof(test_msg_storage)); u8 test_msg_len = 0; - msg_protection_level_dep_a_t *test_msg = - (msg_protection_level_dep_a_t *)test_msg_storage; + msg_protection_level_t *test_msg = + (msg_protection_level_t *)test_msg_storage; test_msg_len = sizeof(*test_msg); - test_msg->flags = 0; - test_msg->height = 0.0; - test_msg->hpl = 0; - test_msg->lat = 0.0; - test_msg->lon = 0.0; - test_msg->tow = 501867400; - test_msg->vpl = 0; - sbp_payload_send(&sbp_state, 0x216, 4096, test_msg_len, test_msg_storage, + test_msg->atpl = 10663; + test_msg->ctpl = 5433; + test_msg->flags = 555755625; + test_msg->heading = -529244741; + test_msg->height = 412.2; + test_msg->hopl = 26707; + test_msg->hpl = 41013; + test_msg->hvpl = 62681; + test_msg->lat = 5290.2; + test_msg->lon = 9904.2; + test_msg->pitch = -1598561301; + test_msg->popl = 35212; + test_msg->roll = 1018834477; + test_msg->ropl = 63066; + test_msg->tow = 4060370030; + test_msg->v_x = -584647705; + test_msg->v_y = 1353168848; + test_msg->v_z = -1537140001; + test_msg->vpl = 21593; + test_msg->vvpl = 41277; + test_msg->wn = 13102; + sbp_payload_send(&sbp_state, 0x217, 813, test_msg_len, test_msg_storage, &dummy_write); ck_assert_msg( @@ -162,7 +179,7 @@ START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevel) { ck_assert_msg(last_msg.n_callbacks_logged == 1, "msg_callback: one callback should have been logged"); - ck_assert_msg(last_msg.sender_id == 4096, + ck_assert_msg(last_msg.sender_id == 813, "msg_callback: sender_id decoded incorrectly"); ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, "msg_callback: len decoded incorrectly"); @@ -174,9 +191,9 @@ START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevel) { ck_assert_msg(last_frame.n_callbacks_logged == 1, "frame_callback: one callback should have been logged"); - ck_assert_msg(last_frame.sender_id == 4096, + ck_assert_msg(last_frame.sender_id == 813, "frame_callback: sender_id decoded incorrectly"); - ck_assert_msg(last_frame.msg_type == 0x216, + ck_assert_msg(last_frame.msg_type == 0x217, "frame_callback: msg_type decoded incorrectly"); ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, "frame_callback: msg_len decoded incorrectly"); @@ -193,29 +210,73 @@ START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevel) { // Cast to expected message type - the +6 byte offset is where the payload // starts - msg_protection_level_dep_a_t *check_msg = - (msg_protection_level_dep_a_t *)((void *)last_msg.msg); + msg_protection_level_t *check_msg = + (msg_protection_level_t *)((void *)last_msg.msg); // Run tests against fields ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); - ck_assert_msg(check_msg->flags == 0, - "incorrect value for flags, expected 0, is %d", + ck_assert_msg(check_msg->atpl == 10663, + "incorrect value for atpl, expected 10663, is %d", + check_msg->atpl); + ck_assert_msg(check_msg->ctpl == 5433, + "incorrect value for ctpl, expected 5433, is %d", + check_msg->ctpl); + ck_assert_msg(check_msg->flags == 555755625, + "incorrect value for flags, expected 555755625, is %d", check_msg->flags); - ck_assert_msg((check_msg->height * 100 - 0.0 * 100) < 0.05, - "incorrect value for height, expected 0.0, is %f", + ck_assert_msg(check_msg->heading == -529244741, + "incorrect value for heading, expected -529244741, is %d", + check_msg->heading); + ck_assert_msg((check_msg->height * 100 - 412.2 * 100) < 0.05, + "incorrect value for height, expected 412.2, is %f", check_msg->height); - ck_assert_msg(check_msg->hpl == 0, - "incorrect value for hpl, expected 0, is %d", check_msg->hpl); - ck_assert_msg((check_msg->lat * 100 - 0.0 * 100) < 0.05, - "incorrect value for lat, expected 0.0, is %f", + ck_assert_msg(check_msg->hopl == 26707, + "incorrect value for hopl, expected 26707, is %d", + check_msg->hopl); + ck_assert_msg(check_msg->hpl == 41013, + "incorrect value for hpl, expected 41013, is %d", + check_msg->hpl); + ck_assert_msg(check_msg->hvpl == 62681, + "incorrect value for hvpl, expected 62681, is %d", + check_msg->hvpl); + ck_assert_msg((check_msg->lat * 100 - 5290.2 * 100) < 0.05, + "incorrect value for lat, expected 5290.2, is %f", check_msg->lat); - ck_assert_msg((check_msg->lon * 100 - 0.0 * 100) < 0.05, - "incorrect value for lon, expected 0.0, is %f", + ck_assert_msg((check_msg->lon * 100 - 9904.2 * 100) < 0.05, + "incorrect value for lon, expected 9904.2, is %f", check_msg->lon); - ck_assert_msg(check_msg->tow == 501867400, - "incorrect value for tow, expected 501867400, is %d", + ck_assert_msg(check_msg->pitch == -1598561301, + "incorrect value for pitch, expected -1598561301, is %d", + check_msg->pitch); + ck_assert_msg(check_msg->popl == 35212, + "incorrect value for popl, expected 35212, is %d", + check_msg->popl); + ck_assert_msg(check_msg->roll == 1018834477, + "incorrect value for roll, expected 1018834477, is %d", + check_msg->roll); + ck_assert_msg(check_msg->ropl == 63066, + "incorrect value for ropl, expected 63066, is %d", + check_msg->ropl); + ck_assert_msg(check_msg->tow == 4060370030, + "incorrect value for tow, expected 4060370030, is %d", check_msg->tow); - ck_assert_msg(check_msg->vpl == 0, - "incorrect value for vpl, expected 0, is %d", check_msg->vpl); + ck_assert_msg(check_msg->v_x == -584647705, + "incorrect value for v_x, expected -584647705, is %d", + check_msg->v_x); + ck_assert_msg(check_msg->v_y == 1353168848, + "incorrect value for v_y, expected 1353168848, is %d", + check_msg->v_y); + ck_assert_msg(check_msg->v_z == -1537140001, + "incorrect value for v_z, expected -1537140001, is %d", + check_msg->v_z); + ck_assert_msg(check_msg->vpl == 21593, + "incorrect value for vpl, expected 21593, is %d", + check_msg->vpl); + ck_assert_msg(check_msg->vvpl == 41277, + "incorrect value for vvpl, expected 41277, is %d", + check_msg->vvpl); + ck_assert_msg(check_msg->wn == 13102, + "incorrect value for wn, expected 13102, is %d", + check_msg->wn); } } END_TEST diff --git a/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevelDepA.c b/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevelDepA.c new file mode 100644 index 0000000000..a71899e553 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_navigation_MsgProtectionLevelDepA.c @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x216, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x216, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, + 51, 51, 51, 51, 51, 244, 190, 64, 102, 102, 102, 102, 102, 204, + 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, 81, 104, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_protection_level_dep_a_t *test_msg = + (msg_protection_level_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 248; + test_msg->height = 8270.2; + test_msg->hpl = 35588; + test_msg->lat = 7924.2; + test_msg->lon = 3174.2; + test_msg->tow = 3108339252; + test_msg->vpl = 21807; + sbp_payload_send(&sbp_state, 0x216, 5780, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 5780, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 5780, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x216, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_protection_level_dep_a_t *check_msg = + (msg_protection_level_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 248, + "incorrect value for flags, expected 248, is %d", + check_msg->flags); + ck_assert_msg((check_msg->height * 100 - 8270.2 * 100) < 0.05, + "incorrect value for height, expected 8270.2, is %f", + check_msg->height); + ck_assert_msg(check_msg->hpl == 35588, + "incorrect value for hpl, expected 35588, is %d", + check_msg->hpl); + ck_assert_msg((check_msg->lat * 100 - 7924.2 * 100) < 0.05, + "incorrect value for lat, expected 7924.2, is %f", + check_msg->lat); + ck_assert_msg((check_msg->lon * 100 - 3174.2 * 100) < 0.05, + "incorrect value for lon, expected 3174.2, is %f", + check_msg->lon); + ck_assert_msg(check_msg->tow == 3108339252, + "incorrect value for tow, expected 3108339252, is %d", + check_msg->tow); + ck_assert_msg(check_msg->vpl == 21807, + "incorrect value for vpl, expected 21807, is %d", + check_msg->vpl); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_navigation_" + "MsgProtectionLevelDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ndb_MsgNdbEvent.c b/c/test/legacy/auto_check_sbp_ndb_MsgNdbEvent.c new file mode 100644 index 0000000000..1f0b0cc013 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ndb_MsgNdbEvent.c @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ndb_MsgNdbEvent) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x400, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x400, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, + 0, 249, 73, 205, 115, 238, 74, 98, 66, 182, 148, 16, 166, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ndb_event_t *test_msg = (msg_ndb_event_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->data_source = 115; + test_msg->event = 249; + test_msg->object_sid.code = 74; + test_msg->object_sid.sat = 238; + test_msg->object_type = 73; + test_msg->original_sender = 38070; + test_msg->recv_time = 299461164286; + test_msg->result = 205; + test_msg->src_sid.code = 66; + test_msg->src_sid.sat = 98; + sbp_payload_send(&sbp_state, 0x400, 44708, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 44708, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 44708, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x400, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ndb_event_t *check_msg = (msg_ndb_event_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->data_source == 115, + "incorrect value for data_source, expected 115, is %d", + check_msg->data_source); + ck_assert_msg(check_msg->event == 249, + "incorrect value for event, expected 249, is %d", + check_msg->event); + ck_assert_msg(check_msg->object_sid.code == 74, + "incorrect value for object_sid.code, expected 74, is %d", + check_msg->object_sid.code); + ck_assert_msg(check_msg->object_sid.sat == 238, + "incorrect value for object_sid.sat, expected 238, is %d", + check_msg->object_sid.sat); + ck_assert_msg(check_msg->object_type == 73, + "incorrect value for object_type, expected 73, is %d", + check_msg->object_type); + ck_assert_msg(check_msg->original_sender == 38070, + "incorrect value for original_sender, expected 38070, is %d", + check_msg->original_sender); + ck_assert_msg(check_msg->recv_time == 299461164286, + "incorrect value for recv_time, expected 299461164286, is %d", + check_msg->recv_time); + ck_assert_msg(check_msg->result == 205, + "incorrect value for result, expected 205, is %d", + check_msg->result); + ck_assert_msg(check_msg->src_sid.code == 66, + "incorrect value for src_sid.code, expected 66, is %d", + check_msg->src_sid.code); + ck_assert_msg(check_msg->src_sid.sat == 98, + "incorrect value for src_sid.sat, expected 98, is %d", + check_msg->src_sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ndb_MsgNdbEvent_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_ndb_MsgNdbEvent"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_ndb_MsgNdbEvent"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ndb_MsgNdbEvent); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLO.c b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLO.c new file mode 100644 index 0000000000..3e4a610130 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLO.c @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgAlmanacGLO) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x73, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x73, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, + 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, + 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, + 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 155, 87, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_almanac_glo_t *test_msg = (msg_almanac_glo_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->epsilon = -0.9893036629599647; + test_msg->i = 5153.550029754639; + test_msg->lambda_na = -0.02200078842114688; + test_msg->omega = 0.9341514480259797; + test_msg->t = -1.8731818448797617; + test_msg->t_dot = -8.903585155774196e-09; + test_msg->t_lambda_na = 0.007072207052260637; + sbp_payload_send(&sbp_state, 0x73, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x73, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_almanac_glo_t *check_msg = (msg_almanac_glo_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toa.tow == 446384, + "incorrect value for common.toa.tow, expected 446384, is %d", + check_msg->common.toa.tow); + ck_assert_msg(check_msg->common.toa.wn == 2154, + "incorrect value for common.toa.wn, expected 2154, is %d", + check_msg->common.toa.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for common.ura, expected 2.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->epsilon * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for epsilon, expected -0.98930366296, is %f", + check_msg->epsilon); + ck_assert_msg((check_msg->i * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for i, expected 5153.55002975, is %f", + check_msg->i); + ck_assert_msg( + (check_msg->lambda_na * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for lambda_na, expected -0.0220007884211, is %f", + check_msg->lambda_na); + ck_assert_msg((check_msg->omega * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for omega, expected 0.934151448026, is %f", + check_msg->omega); + ck_assert_msg((check_msg->t * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for t, expected -1.87318184488, is %f", + check_msg->t); + ck_assert_msg( + (check_msg->t_dot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for t_dot, expected -8.90358515577e-09, is %f", + check_msg->t_dot); + ck_assert_msg( + (check_msg->t_lambda_na * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for t_lambda_na, expected 0.00707220705226, is %f", + check_msg->t_lambda_na); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgAlmanacGLO_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgAlmanacGLO"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgAlmanacGLO"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgAlmanacGLO); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLODep.c b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLODep.c new file mode 100644 index 0000000000..9cc8f4d5fc --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGLODep.c @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgAlmanacGLODep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x71, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x71, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, + 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, + 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, + 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 203, 178, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_almanac_glo_dep_t *test_msg = (msg_almanac_glo_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->epsilon = -0.9893036629599647; + test_msg->i = 5153.550029754639; + test_msg->lambda_na = -0.02200078842114688; + test_msg->omega = 0.9341514480259797; + test_msg->t = -1.8731818448797617; + test_msg->t_dot = -8.903585155774196e-09; + test_msg->t_lambda_na = 0.007072207052260637; + sbp_payload_send(&sbp_state, 0x71, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x71, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_almanac_glo_dep_t *check_msg = + (msg_almanac_glo_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.reserved == 0, + "incorrect value for common.sid.reserved, expected 0, is %d", + check_msg->common.sid.reserved); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toa.tow == 446384, + "incorrect value for common.toa.tow, expected 446384, is %d", + check_msg->common.toa.tow); + ck_assert_msg(check_msg->common.toa.wn == 2154, + "incorrect value for common.toa.wn, expected 2154, is %d", + check_msg->common.toa.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for common.ura, expected 2.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->epsilon * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for epsilon, expected -0.98930366296, is %f", + check_msg->epsilon); + ck_assert_msg((check_msg->i * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for i, expected 5153.55002975, is %f", + check_msg->i); + ck_assert_msg( + (check_msg->lambda_na * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for lambda_na, expected -0.0220007884211, is %f", + check_msg->lambda_na); + ck_assert_msg((check_msg->omega * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for omega, expected 0.934151448026, is %f", + check_msg->omega); + ck_assert_msg((check_msg->t * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for t, expected -1.87318184488, is %f", + check_msg->t); + ck_assert_msg( + (check_msg->t_dot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for t_dot, expected -8.90358515577e-09, is %f", + check_msg->t_dot); + ck_assert_msg( + (check_msg->t_lambda_na * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for t_lambda_na, expected 0.00707220705226, is %f", + check_msg->t_lambda_na); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgAlmanacGLODep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgAlmanacGLODep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgAlmanacGLODep"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgAlmanacGLODep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPS.c b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPS.c new file mode 100644 index 0000000000..be9e21d2b8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPS.c @@ -0,0 +1,279 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgAlmanacGPS) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x72, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x72, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, + 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, + 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, + 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_almanac_gps_t *test_msg = (msg_almanac_gps_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x72, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x72, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_almanac_gps_t *check_msg = (msg_almanac_gps_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toa.tow == 446384, + "incorrect value for common.toa.tow, expected 446384, is %d", + check_msg->common.toa.tow); + ck_assert_msg(check_msg->common.toa.wn == 2154, + "incorrect value for common.toa.wn, expected 2154, is %d", + check_msg->common.toa.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for common.ura, expected 2.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgAlmanacGPS_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgAlmanacGPS"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgAlmanacGPS"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgAlmanacGPS); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPSDep.c b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPSDep.c new file mode 100644 index 0000000000..30954fb3ad --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgAlmanacGPSDep.c @@ -0,0 +1,285 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x70, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x70, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, + 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, + 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, + 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, + 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 144, 232, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_almanac_gps_dep_t *test_msg = (msg_almanac_gps_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x70, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x70, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_almanac_gps_dep_t *check_msg = + (msg_almanac_gps_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.reserved == 0, + "incorrect value for common.sid.reserved, expected 0, is %d", + check_msg->common.sid.reserved); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toa.tow == 446384, + "incorrect value for common.toa.tow, expected 446384, is %d", + check_msg->common.toa.tow); + ck_assert_msg(check_msg->common.toa.wn == 2154, + "incorrect value for common.toa.wn, expected 2154, is %d", + check_msg->common.toa.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.2 * 100) < 0.05, + "incorrect value for common.ura, expected 2.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgAlmanacGPSDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgAlmanacGPSDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgBasePosLLH.c b/c/test/legacy/auto_check_sbp_observation_MsgBasePosLLH.c new file mode 100644 index 0000000000..6dba7c067b --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgBasePosLLH.c @@ -0,0 +1,216 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgBasePosLLH) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x44, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x44, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, + 70, 235, 0, 120, 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_base_pos_llh_t *test_msg = (msg_base_pos_llh_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->height = 37.939512310879216; + test_msg->lat = 37.251292578377395; + test_msg->lon = -121.87505609407974; + sbp_payload_send(&sbp_state, 0x44, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x44, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_base_pos_llh_t *check_msg = + (msg_base_pos_llh_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->height * 100 - 37.9395123109 * 100) < 0.05, + "incorrect value for height, expected 37.9395123109, is %f", + check_msg->height); + ck_assert_msg((check_msg->lat * 100 - 37.2512925784 * 100) < 0.05, + "incorrect value for lat, expected 37.2512925784, is %f", + check_msg->lat); + ck_assert_msg((check_msg->lon * 100 - -121.875056094 * 100) < 0.05, + "incorrect value for lon, expected -121.875056094, is %f", + check_msg->lon); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgBasePosLLH_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgBasePosLLH"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgBasePosLLH"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgBasePosLLH); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepA.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepA.c new file mode 100644 index 0000000000..f32b3d7dda --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepA.c @@ -0,0 +1,325 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1a, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1a, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 242, + 84, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_dep_a_t *test_msg = (msg_ephemeris_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->prn = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x1a, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1a, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_dep_a_t *check_msg = + (msg_ephemeris_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for af2, expected 0.2, is %f", + check_msg->af2); + ck_assert_msg((check_msg->c_ic * 100 - 7.45058059692e-09 * 100) < 0.05, + "incorrect value for c_ic, expected 7.45058059692e-09, is %f", + check_msg->c_ic); + ck_assert_msg( + (check_msg->c_is * 100 - -1.15483999252e-07 * 100) < 0.05, + "incorrect value for c_is, expected -1.15483999252e-07, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for c_rc, expected 308.625, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for c_rs, expected -52.3125, is %f", + check_msg->c_rs); + ck_assert_msg( + (check_msg->c_uc * 100 - -2.74367630482e-06 * 100) < 0.05, + "incorrect value for c_uc, expected -2.74367630482e-06, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 3.1366944313e-06 * 100) < 0.05, + "incorrect value for c_us, expected 3.1366944313e-06, is %f", + check_msg->c_us); + ck_assert_msg((check_msg->dn * 100 - 5.69452291402e-09 * 100) < 0.05, + "incorrect value for dn, expected 5.69452291402e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg(check_msg->healthy == 0, + "incorrect value for healthy, expected 0, is %d", + check_msg->healthy); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -4.03588239642e-11 * 100) < 0.05, + "incorrect value for inc_dot, expected -4.03588239642e-11, is %f", + check_msg->inc_dot); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg(check_msg->prn == 22, + "incorrect value for prn, expected 22, is %d", + check_msg->prn); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->tgd * 100 - -1.76951289177e-08 * 100) < 0.05, + "incorrect value for tgd, expected -1.76951289177e-08, is %f", + check_msg->tgd); + ck_assert_msg((check_msg->toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toc_tow, expected 446384.2, is %f", + check_msg->toc_tow); + ck_assert_msg(check_msg->toc_wn == 2154, + "incorrect value for toc_wn, expected 2154, is %d", + check_msg->toc_wn); + ck_assert_msg((check_msg->toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toe_tow, expected 446384.2, is %f", + check_msg->toe_tow); + ck_assert_msg(check_msg->toe_wn == 2154, + "incorrect value for toe_wn, expected 2154, is %d", + check_msg->toe_wn); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepC.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepC.c new file mode 100644 index 0000000000..91ccdf3af2 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepC.c @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisDepC) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x47, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x47, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, + 0, 0, 45, 45, 0, 0, 0, 0, 0, 23, 170, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_dep_c_t *test_msg = (msg_ephemeris_dep_c_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->reserved = 0; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x47, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x47, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_dep_c_t *check_msg = + (msg_ephemeris_dep_c_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for af2, expected 0.2, is %f", + check_msg->af2); + ck_assert_msg((check_msg->c_ic * 100 - 7.45058059692e-09 * 100) < 0.05, + "incorrect value for c_ic, expected 7.45058059692e-09, is %f", + check_msg->c_ic); + ck_assert_msg( + (check_msg->c_is * 100 - -1.15483999252e-07 * 100) < 0.05, + "incorrect value for c_is, expected -1.15483999252e-07, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for c_rc, expected 308.625, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for c_rs, expected -52.3125, is %f", + check_msg->c_rs); + ck_assert_msg( + (check_msg->c_uc * 100 - -2.74367630482e-06 * 100) < 0.05, + "incorrect value for c_uc, expected -2.74367630482e-06, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 3.1366944313e-06 * 100) < 0.05, + "incorrect value for c_us, expected 3.1366944313e-06, is %f", + check_msg->c_us); + ck_assert_msg((check_msg->dn * 100 - 5.69452291402e-09 * 100) < 0.05, + "incorrect value for dn, expected 5.69452291402e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg(check_msg->healthy == 0, + "incorrect value for healthy, expected 0, is %d", + check_msg->healthy); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -4.03588239642e-11 * 100) < 0.05, + "incorrect value for inc_dot, expected -4.03588239642e-11, is %f", + check_msg->inc_dot); + ck_assert_msg(check_msg->iodc == 45, + "incorrect value for iodc, expected 45, is %d", + check_msg->iodc); + ck_assert_msg(check_msg->iode == 45, + "incorrect value for iode, expected 45, is %d", + check_msg->iode); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg(check_msg->reserved == 0, + "incorrect value for reserved, expected 0, is %d", + check_msg->reserved); + ck_assert_msg(check_msg->sid.code == 0, + "incorrect value for sid.code, expected 0, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.reserved == 0, + "incorrect value for sid.reserved, expected 0, is %d", + check_msg->sid.reserved); + ck_assert_msg(check_msg->sid.sat == 22, + "incorrect value for sid.sat, expected 22, is %d", + check_msg->sid.sat); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->tgd * 100 - -1.76951289177e-08 * 100) < 0.05, + "incorrect value for tgd, expected -1.76951289177e-08, is %f", + check_msg->tgd); + ck_assert_msg((check_msg->toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toc_tow, expected 446384.2, is %f", + check_msg->toc_tow); + ck_assert_msg(check_msg->toc_wn == 2154, + "incorrect value for toc_wn, expected 2154, is %d", + check_msg->toc_wn); + ck_assert_msg((check_msg->toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toe_tow, expected 446384.2, is %f", + check_msg->toe_tow); + ck_assert_msg(check_msg->toe_wn == 2154, + "incorrect value for toe_wn, expected 2154, is %d", + check_msg->toe_wn); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisDepC_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisDepC"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisDepC"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisDepC); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepD.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepD.c new file mode 100644 index 0000000000..7f863a04c8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisDepD.c @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisDepD) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x80, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x80, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, + 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, + 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, + 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, + 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, + 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 154, 153, 153, 153, + 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, + 0, 0, 45, 45, 0, 0, 0, 0, 0, 95, 7, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_dep_d_t *test_msg = (msg_ephemeris_dep_d_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->reserved = 0; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x80, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x80, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_dep_d_t *check_msg = + (msg_ephemeris_dep_d_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.2 * 100) < 0.05, + "incorrect value for af2, expected 0.2, is %f", + check_msg->af2); + ck_assert_msg((check_msg->c_ic * 100 - 7.45058059692e-09 * 100) < 0.05, + "incorrect value for c_ic, expected 7.45058059692e-09, is %f", + check_msg->c_ic); + ck_assert_msg( + (check_msg->c_is * 100 - -1.15483999252e-07 * 100) < 0.05, + "incorrect value for c_is, expected -1.15483999252e-07, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for c_rc, expected 308.625, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for c_rs, expected -52.3125, is %f", + check_msg->c_rs); + ck_assert_msg( + (check_msg->c_uc * 100 - -2.74367630482e-06 * 100) < 0.05, + "incorrect value for c_uc, expected -2.74367630482e-06, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 3.1366944313e-06 * 100) < 0.05, + "incorrect value for c_us, expected 3.1366944313e-06, is %f", + check_msg->c_us); + ck_assert_msg((check_msg->dn * 100 - 5.69452291402e-09 * 100) < 0.05, + "incorrect value for dn, expected 5.69452291402e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg(check_msg->healthy == 0, + "incorrect value for healthy, expected 0, is %d", + check_msg->healthy); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -4.03588239642e-11 * 100) < 0.05, + "incorrect value for inc_dot, expected -4.03588239642e-11, is %f", + check_msg->inc_dot); + ck_assert_msg(check_msg->iodc == 45, + "incorrect value for iodc, expected 45, is %d", + check_msg->iodc); + ck_assert_msg(check_msg->iode == 45, + "incorrect value for iode, expected 45, is %d", + check_msg->iode); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg(check_msg->reserved == 0, + "incorrect value for reserved, expected 0, is %d", + check_msg->reserved); + ck_assert_msg(check_msg->sid.code == 0, + "incorrect value for sid.code, expected 0, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.reserved == 0, + "incorrect value for sid.reserved, expected 0, is %d", + check_msg->sid.reserved); + ck_assert_msg(check_msg->sid.sat == 22, + "incorrect value for sid.sat, expected 22, is %d", + check_msg->sid.sat); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->tgd * 100 - -1.76951289177e-08 * 100) < 0.05, + "incorrect value for tgd, expected -1.76951289177e-08, is %f", + check_msg->tgd); + ck_assert_msg((check_msg->toc_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toc_tow, expected 446384.2, is %f", + check_msg->toc_tow); + ck_assert_msg(check_msg->toc_wn == 2154, + "incorrect value for toc_wn, expected 2154, is %d", + check_msg->toc_wn); + ck_assert_msg((check_msg->toe_tow * 100 - 446384.2 * 100) < 0.05, + "incorrect value for toe_tow, expected 446384.2, is %f", + check_msg->toe_tow); + ck_assert_msg(check_msg->toe_wn == 2154, + "incorrect value for toe_wn, expected 2154, is %d", + check_msg->toe_wn); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisDepD_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisDepD"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisDepD"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisDepD); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepA.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepA.c new file mode 100644 index 0000000000..4787a2187c --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepA.c @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x83, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x83, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, + 106, 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, + 48, 236, 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, + 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, + 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 112, 199, 62, 202, 238, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_glo_dep_a_t *test_msg = + (msg_ephemeris_glo_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x83, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x83, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_glo_dep_a_t *check_msg = + (msg_ephemeris_glo_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg( + check_msg->common.fit_interval == 2400, + "incorrect value for common.fit_interval, expected 2400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 3, + "incorrect value for common.sid.code, expected 3, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.reserved == 0, + "incorrect value for common.sid.reserved, expected 0, is %d", + check_msg->common.sid.reserved); + ck_assert_msg(check_msg->common.sid.sat == 4, + "incorrect value for common.sid.sat, expected 4, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 443718, + "incorrect value for common.toe.tow, expected 443718, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for common.ura, expected 5.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg( + (check_msg->gamma * 100 - 9.09494701773e-13 * 100) < 0.05, + "incorrect value for gamma, expected 9.09494701773e-13, is %f", + check_msg->gamma); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->tau * 100 - -8.36281105876e-05 * 100) < 0.05, + "incorrect value for tau, expected -8.36281105876e-05, is %f", + check_msg->tau); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGLODepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGLODepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepB.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepB.c new file mode 100644 index 0000000000..46f1e54df5 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepB.c @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x85, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x85, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, + 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, + 21, 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 122, 127, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_glo_dep_b_t *test_msg = + (msg_ephemeris_glo_dep_b_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x85, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x85, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_glo_dep_b_t *check_msg = + (msg_ephemeris_glo_dep_b_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg( + check_msg->common.fit_interval == 2400, + "incorrect value for common.fit_interval, expected 2400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 3, + "incorrect value for common.sid.code, expected 3, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 4, + "incorrect value for common.sid.sat, expected 4, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 443718, + "incorrect value for common.toe.tow, expected 443718, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for common.ura, expected 5.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg( + (check_msg->gamma * 100 - 9.09494701773e-13 * 100) < 0.05, + "incorrect value for gamma, expected 9.09494701773e-13, is %f", + check_msg->gamma); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->tau * 100 - -8.36281105876e-05 * 100) < 0.05, + "incorrect value for tau, expected -8.36281105876e-05, is %f", + check_msg->tau); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGLODepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGLODepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepC.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepC.c new file mode 100644 index 0000000000..c58497d0aa --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepC.c @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x87, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x87, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, + 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, 190, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, + 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, + 0, 0, 0, 0, 112, 199, 62, 14, 151, 65, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_glo_dep_c_t *test_msg = + (msg_ephemeris_glo_dep_c_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->d_tau = -2.7939677238464355e-09; + test_msg->fcn = 14; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x87, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x87, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_glo_dep_c_t *check_msg = + (msg_ephemeris_glo_dep_c_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg( + check_msg->common.fit_interval == 2400, + "incorrect value for common.fit_interval, expected 2400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 3, + "incorrect value for common.sid.code, expected 3, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 4, + "incorrect value for common.sid.sat, expected 4, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 443718, + "incorrect value for common.toe.tow, expected 443718, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for common.ura, expected 5.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg( + (check_msg->d_tau * 100 - -2.79396772385e-09 * 100) < 0.05, + "incorrect value for d_tau, expected -2.79396772385e-09, is %f", + check_msg->d_tau); + ck_assert_msg(check_msg->fcn == 14, + "incorrect value for fcn, expected 14, is %d", + check_msg->fcn); + ck_assert_msg( + (check_msg->gamma * 100 - 9.09494701773e-13 * 100) < 0.05, + "incorrect value for gamma, expected 9.09494701773e-13, is %f", + check_msg->gamma); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->tau * 100 - -8.36281105876e-05 * 100) < 0.05, + "incorrect value for tau, expected -8.36281105876e-05, is %f", + check_msg->tau); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGLODepC_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGLODepC"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepD.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepD.c new file mode 100644 index 0000000000..f61c9335b4 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGLODepD.c @@ -0,0 +1,344 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x88, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x88, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, + 0, 48, 236, 21, 191, 0, 0, 0, 0, 0, 0, 40, 190, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, + 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, + 0, 0, 0, 0, 112, 199, 62, 14, 100, 82, 64, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_glo_dep_d_t *test_msg = + (msg_ephemeris_glo_dep_d_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->d_tau = -2.7939677238464355e-09; + test_msg->fcn = 14; + test_msg->gamma = 9.094947017729282e-13; + test_msg->iod = 100; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x88, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x88, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_glo_dep_d_t *check_msg = + (msg_ephemeris_glo_dep_d_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg( + check_msg->common.fit_interval == 2400, + "incorrect value for common.fit_interval, expected 2400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 3, + "incorrect value for common.sid.code, expected 3, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 4, + "incorrect value for common.sid.sat, expected 4, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 443718, + "incorrect value for common.toe.tow, expected 443718, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 5.2 * 100) < 0.05, + "incorrect value for common.ura, expected 5.2, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg( + (check_msg->d_tau * 100 - -2.79396772385e-09 * 100) < 0.05, + "incorrect value for d_tau, expected -2.79396772385e-09, is %f", + check_msg->d_tau); + ck_assert_msg(check_msg->fcn == 14, + "incorrect value for fcn, expected 14, is %d", + check_msg->fcn); + ck_assert_msg( + (check_msg->gamma * 100 - 9.09494701773e-13 * 100) < 0.05, + "incorrect value for gamma, expected 9.09494701773e-13, is %f", + check_msg->gamma); + ck_assert_msg(check_msg->iod == 100, + "incorrect value for iod, expected 100, is %d", + check_msg->iod); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->tau * 100 - -8.36281105876e-05 * 100) < 0.05, + "incorrect value for tau, expected -8.36281105876e-05, is %f", + check_msg->tau); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGLODepD_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGLODepD"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepE.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepE.c new file mode 100644 index 0000000000..eb955407f8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepE.c @@ -0,0 +1,351 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x81, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x81, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, + 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, + 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, + 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, + 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, + 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, + 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, + 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, + 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, + 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_gps_dep_e_t *test_msg = + (msg_ephemeris_gps_dep_e_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.0; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc.tow = 446384; + test_msg->toc.wn = 2154; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x81, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x81, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_gps_dep_e_t *check_msg = + (msg_ephemeris_gps_dep_e_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.0 * 100) < 0.05, + "incorrect value for af2, expected 0.0, is %f", + check_msg->af2); + ck_assert_msg((check_msg->c_ic * 100 - 7.45058059692e-09 * 100) < 0.05, + "incorrect value for c_ic, expected 7.45058059692e-09, is %f", + check_msg->c_ic); + ck_assert_msg( + (check_msg->c_is * 100 - -1.15483999252e-07 * 100) < 0.05, + "incorrect value for c_is, expected -1.15483999252e-07, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for c_rc, expected 308.625, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for c_rs, expected -52.3125, is %f", + check_msg->c_rs); + ck_assert_msg( + (check_msg->c_uc * 100 - -2.74367630482e-06 * 100) < 0.05, + "incorrect value for c_uc, expected -2.74367630482e-06, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 3.1366944313e-06 * 100) < 0.05, + "incorrect value for c_us, expected 3.1366944313e-06, is %f", + check_msg->c_us); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.reserved == 0, + "incorrect value for common.sid.reserved, expected 0, is %d", + check_msg->common.sid.reserved); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 446384, + "incorrect value for common.toe.tow, expected 446384, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for common.ura, expected 2.0, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->dn * 100 - 5.69452291402e-09 * 100) < 0.05, + "incorrect value for dn, expected 5.69452291402e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -4.03588239642e-11 * 100) < 0.05, + "incorrect value for inc_dot, expected -4.03588239642e-11, is %f", + check_msg->inc_dot); + ck_assert_msg(check_msg->iodc == 45, + "incorrect value for iodc, expected 45, is %d", + check_msg->iodc); + ck_assert_msg(check_msg->iode == 45, + "incorrect value for iode, expected 45, is %d", + check_msg->iode); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->tgd * 100 - -1.76951289177e-08 * 100) < 0.05, + "incorrect value for tgd, expected -1.76951289177e-08, is %f", + check_msg->tgd); + ck_assert_msg(check_msg->toc.tow == 446384, + "incorrect value for toc.tow, expected 446384, is %d", + check_msg->toc.tow); + ck_assert_msg(check_msg->toc.wn == 2154, + "incorrect value for toc.wn, expected 2154, is %d", + check_msg->toc.wn); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepF.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepF.c new file mode 100644 index 0000000000..f5eb97a19d --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGPSDepF.c @@ -0,0 +1,347 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x86, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x86, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, + 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, + 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, + 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, + 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, + 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, + 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, + 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, + 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, + 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, 176, 207, + 6, 0, 106, 8, 45, 45, 0, 115, 254, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_gps_dep_f_t *test_msg = + (msg_ephemeris_gps_dep_f_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.0; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc.tow = 446384; + test_msg->toc.wn = 2154; + test_msg->w = -0.9893036629599647; + sbp_payload_send(&sbp_state, 0x86, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x86, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_gps_dep_f_t *check_msg = + (msg_ephemeris_gps_dep_f_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for af0, expected -0.00063150189817, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for af1, expected 8.98126018001e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.0 * 100) < 0.05, + "incorrect value for af2, expected 0.0, is %f", + check_msg->af2); + ck_assert_msg((check_msg->c_ic * 100 - 7.45058059692e-09 * 100) < 0.05, + "incorrect value for c_ic, expected 7.45058059692e-09, is %f", + check_msg->c_ic); + ck_assert_msg( + (check_msg->c_is * 100 - -1.15483999252e-07 * 100) < 0.05, + "incorrect value for c_is, expected -1.15483999252e-07, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 308.625 * 100) < 0.05, + "incorrect value for c_rc, expected 308.625, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - -52.3125 * 100) < 0.05, + "incorrect value for c_rs, expected -52.3125, is %f", + check_msg->c_rs); + ck_assert_msg( + (check_msg->c_uc * 100 - -2.74367630482e-06 * 100) < 0.05, + "incorrect value for c_uc, expected -2.74367630482e-06, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 3.1366944313e-06 * 100) < 0.05, + "incorrect value for c_us, expected 3.1366944313e-06, is %f", + check_msg->c_us); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 0, + "incorrect value for common.sid.code, expected 0, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 446384, + "incorrect value for common.toe.tow, expected 446384, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for common.ura, expected 2.0, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->dn * 100 - 5.69452291402e-09 * 100) < 0.05, + "incorrect value for dn, expected 5.69452291402e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.00707220705226 * 100) < 0.05, + "incorrect value for ecc, expected 0.00707220705226, is %f", + check_msg->ecc); + ck_assert_msg((check_msg->inc * 100 - 0.934151448026 * 100) < 0.05, + "incorrect value for inc, expected 0.934151448026, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -4.03588239642e-11 * 100) < 0.05, + "incorrect value for inc_dot, expected -4.03588239642e-11, is %f", + check_msg->inc_dot); + ck_assert_msg(check_msg->iodc == 45, + "incorrect value for iodc, expected 45, is %d", + check_msg->iodc); + ck_assert_msg(check_msg->iode == 45, + "incorrect value for iode, expected 45, is %d", + check_msg->iode); + ck_assert_msg((check_msg->m0 * 100 - -0.0220007884211 * 100) < 0.05, + "incorrect value for m0, expected -0.0220007884211, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - -1.87318184488 * 100) < 0.05, + "incorrect value for omega0, expected -1.87318184488, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -8.90358515577e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -8.90358515577e-09, is %f", + check_msg->omegadot); + ck_assert_msg((check_msg->sqrta * 100 - 5153.55002975 * 100) < 0.05, + "incorrect value for sqrta, expected 5153.55002975, is %f", + check_msg->sqrta); + ck_assert_msg((check_msg->tgd * 100 - -1.76951289177e-08 * 100) < 0.05, + "incorrect value for tgd, expected -1.76951289177e-08, is %f", + check_msg->tgd); + ck_assert_msg(check_msg->toc.tow == 446384, + "incorrect value for toc.tow, expected 446384, is %d", + check_msg->toc.tow); + ck_assert_msg(check_msg->toc.wn == 2154, + "incorrect value for toc.wn, expected 2154, is %d", + check_msg->toc.wn); + ck_assert_msg((check_msg->w * 100 - -0.98930366296 * 100) < 0.05, + "incorrect value for w, expected -0.98930366296, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGalDepA.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGalDepA.c new file mode 100644 index 0000000000..9f094c07b9 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisGalDepA.c @@ -0,0 +1,350 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x95, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x95, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, + 102, 102, 230, 64, 64, 56, 0, 0, 1, 0, 154, 153, 153, 63, + 205, 204, 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, + 166, 64, 102, 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, + 217, 204, 130, 105, 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, + 253, 191, 0, 0, 0, 0, 151, 92, 38, 63, 0, 0, 0, 55, + 154, 64, 181, 64, 56, 38, 1, 141, 255, 182, 242, 63, 222, 147, + 136, 39, 79, 186, 56, 190, 80, 114, 204, 251, 193, 92, 191, 63, + 237, 55, 19, 41, 177, 73, 239, 63, 49, 65, 189, 240, 8, 216, + 245, 189, 255, 255, 255, 255, 67, 235, 241, 190, 255, 255, 255, 255, + 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, 6, 0, 106, 8, + 108, 0, 108, 0, 168, 49, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_gal_dep_a_t *test_msg = + (msg_ephemeris_gal_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->af0 = -1.7088896129280325e-05; + test_msg->af1 = -8.185452315956353e-12; + test_msg->af2 = 0.20000000298023224; + test_msg->bgd_e1e5a = 1.2000000476837158; + test_msg->bgd_e1e5b = 2.200000047683716; + test_msg->c_ic = 3.200000047683716; + test_msg->c_is = 4.199999809265137; + test_msg->c_rc = 265.4375; + test_msg->c_rs = 10.125; + test_msg->c_uc = 5.199999809265137; + test_msg->c_us = 6.199999809265137; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 14; + test_msg->common.sid.sat = 27; + test_msg->common.toe.tow = 448800; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 7.199999809265137; + test_msg->common.valid = 1; + test_msg->dn = 3.2262058129932258e-09; + test_msg->ecc = 0.00017060607206076384; + test_msg->inc = 0.9777456094977858; + test_msg->inc_dot = -3.1787038343451465e-10; + test_msg->iodc = 108; + test_msg->iode = 108; + test_msg->m0 = -1.8457115744155868; + test_msg->omega0 = 1.16967730598334; + test_msg->omegadot = -5.757382675240872e-09; + test_msg->sqrta = 5440.602401733398; + test_msg->toc.tow = 448800; + test_msg->toc.wn = 2154; + test_msg->w = 0.12250912091662625; + sbp_payload_send(&sbp_state, 0x95, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x95, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_gal_dep_a_t *check_msg = + (msg_ephemeris_gal_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->af0 * 100 - -1.70888961293e-05 * 100) < 0.05, + "incorrect value for af0, expected -1.70888961293e-05, is %f", + check_msg->af0); + ck_assert_msg((check_msg->af1 * 100 - -8.18545231596e-12 * 100) < 0.05, + "incorrect value for af1, expected -8.18545231596e-12, is %f", + check_msg->af1); + ck_assert_msg((check_msg->af2 * 100 - 0.20000000298 * 100) < 0.05, + "incorrect value for af2, expected 0.20000000298, is %f", + check_msg->af2); + ck_assert_msg( + (check_msg->bgd_e1e5a * 100 - 1.20000004768 * 100) < 0.05, + "incorrect value for bgd_e1e5a, expected 1.20000004768, is %f", + check_msg->bgd_e1e5a); + ck_assert_msg( + (check_msg->bgd_e1e5b * 100 - 2.20000004768 * 100) < 0.05, + "incorrect value for bgd_e1e5b, expected 2.20000004768, is %f", + check_msg->bgd_e1e5b); + ck_assert_msg((check_msg->c_ic * 100 - 3.20000004768 * 100) < 0.05, + "incorrect value for c_ic, expected 3.20000004768, is %f", + check_msg->c_ic); + ck_assert_msg((check_msg->c_is * 100 - 4.19999980927 * 100) < 0.05, + "incorrect value for c_is, expected 4.19999980927, is %f", + check_msg->c_is); + ck_assert_msg((check_msg->c_rc * 100 - 265.4375 * 100) < 0.05, + "incorrect value for c_rc, expected 265.4375, is %f", + check_msg->c_rc); + ck_assert_msg((check_msg->c_rs * 100 - 10.125 * 100) < 0.05, + "incorrect value for c_rs, expected 10.125, is %f", + check_msg->c_rs); + ck_assert_msg((check_msg->c_uc * 100 - 5.19999980927 * 100) < 0.05, + "incorrect value for c_uc, expected 5.19999980927, is %f", + check_msg->c_uc); + ck_assert_msg((check_msg->c_us * 100 - 6.19999980927 * 100) < 0.05, + "incorrect value for c_us, expected 6.19999980927, is %f", + check_msg->c_us); + ck_assert_msg( + check_msg->common.fit_interval == 14400, + "incorrect value for common.fit_interval, expected 14400, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 14, + "incorrect value for common.sid.code, expected 14, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 27, + "incorrect value for common.sid.sat, expected 27, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 448800, + "incorrect value for common.toe.tow, expected 448800, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg( + (check_msg->common.ura * 100 - 7.19999980927 * 100) < 0.05, + "incorrect value for common.ura, expected 7.19999980927, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->dn * 100 - 3.22620581299e-09 * 100) < 0.05, + "incorrect value for dn, expected 3.22620581299e-09, is %f", + check_msg->dn); + ck_assert_msg((check_msg->ecc * 100 - 0.000170606072061 * 100) < 0.05, + "incorrect value for ecc, expected 0.000170606072061, is %f", + check_msg->ecc); + ck_assert_msg((check_msg->inc * 100 - 0.977745609498 * 100) < 0.05, + "incorrect value for inc, expected 0.977745609498, is %f", + check_msg->inc); + ck_assert_msg( + (check_msg->inc_dot * 100 - -3.17870383435e-10 * 100) < 0.05, + "incorrect value for inc_dot, expected -3.17870383435e-10, is %f", + check_msg->inc_dot); + ck_assert_msg(check_msg->iodc == 108, + "incorrect value for iodc, expected 108, is %d", + check_msg->iodc); + ck_assert_msg(check_msg->iode == 108, + "incorrect value for iode, expected 108, is %d", + check_msg->iode); + ck_assert_msg((check_msg->m0 * 100 - -1.84571157442 * 100) < 0.05, + "incorrect value for m0, expected -1.84571157442, is %f", + check_msg->m0); + ck_assert_msg((check_msg->omega0 * 100 - 1.16967730598 * 100) < 0.05, + "incorrect value for omega0, expected 1.16967730598, is %f", + check_msg->omega0); + ck_assert_msg( + (check_msg->omegadot * 100 - -5.75738267524e-09 * 100) < 0.05, + "incorrect value for omegadot, expected -5.75738267524e-09, is %f", + check_msg->omegadot); + ck_assert_msg((check_msg->sqrta * 100 - 5440.60240173 * 100) < 0.05, + "incorrect value for sqrta, expected 5440.60240173, is %f", + check_msg->sqrta); + ck_assert_msg(check_msg->toc.tow == 448800, + "incorrect value for toc.tow, expected 448800, is %d", + check_msg->toc.tow); + ck_assert_msg(check_msg->toc.wn == 2154, + "incorrect value for toc.wn, expected 2154, is %d", + check_msg->toc.wn); + ck_assert_msg((check_msg->w * 100 - 0.122509120917 * 100) < 0.05, + "incorrect value for w, expected 0.122509120917, is %f", + check_msg->w); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisGalDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisGalDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbas.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbas.c new file mode 100644 index 0000000000..6fd3be3f96 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbas.c @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisSbas) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x8c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x8c, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, + 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, + 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, 122, 53, 0, 128, + 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_sbas_t *test_msg = (msg_ephemeris_sbas_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = -2.7939677238464355e-09; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.5062255859375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.614990234375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177490234375; + sbp_payload_send(&sbp_state, 0x8c, 1219, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1219, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1219, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x8c, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_sbas_t *check_msg = + (msg_ephemeris_sbas_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->a_gf0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for a_gf0, expected -0.00063150189817, is %f", + check_msg->a_gf0); + ck_assert_msg( + (check_msg->a_gf1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for a_gf1, expected 8.98126018001e-12, is %f", + check_msg->a_gf1); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg(check_msg->common.fit_interval == 0, + "incorrect value for common.fit_interval, expected 0, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 6, + "incorrect value for common.sid.code, expected 6, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 446384, + "incorrect value for common.toe.tow, expected 446384, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg( + (check_msg->common.ura * 100 - -2.79396772385e-09 * 100) < 0.05, + "incorrect value for common.ura, expected -2.79396772385e-09, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50622559 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50622559, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61499023 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61499023, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817749023 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817749023, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisSbas_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisSbas"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisSbas"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisSbas); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepA.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepA.c new file mode 100644 index 0000000000..129262b648 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepA.c @@ -0,0 +1,334 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x82, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x82, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, + 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, + 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, + 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, + 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, + 0, 0, 0, 192, 163, 61, 178, 180, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_sbas_dep_a_t *test_msg = + (msg_ephemeris_sbas_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x82, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x82, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_sbas_dep_a_t *check_msg = + (msg_ephemeris_sbas_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->a_gf0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for a_gf0, expected -0.00063150189817, is %f", + check_msg->a_gf0); + ck_assert_msg( + (check_msg->a_gf1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for a_gf1, expected 8.98126018001e-12, is %f", + check_msg->a_gf1); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg(check_msg->common.fit_interval == 0, + "incorrect value for common.fit_interval, expected 0, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 6, + "incorrect value for common.sid.code, expected 6, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.reserved == 0, + "incorrect value for common.sid.reserved, expected 0, is %d", + check_msg->common.sid.reserved); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 446384, + "incorrect value for common.toe.tow, expected 446384, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for common.ura, expected 2.0, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepB.c b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepB.c new file mode 100644 index 0000000000..93e64597ed --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgEphemerisSbasDepB.c @@ -0,0 +1,330 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x84, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x84, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, + 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, + 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, + 0, 192, 163, 61, 145, 104, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ephemeris_sbas_dep_b_t *test_msg = + (msg_ephemeris_sbas_dep_b_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->acc[0]); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->pos[0]); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->vel[0]); + } + test_msg->vel[2] = 869.8177337646484; + sbp_payload_send(&sbp_state, 0x84, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x84, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ephemeris_sbas_dep_b_t *check_msg = + (msg_ephemeris_sbas_dep_b_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->a_gf0 * 100 - -0.00063150189817 * 100) < 0.05, + "incorrect value for a_gf0, expected -0.00063150189817, is %f", + check_msg->a_gf0); + ck_assert_msg( + (check_msg->a_gf1 * 100 - 8.98126018001e-12 * 100) < 0.05, + "incorrect value for a_gf1, expected 8.98126018001e-12, is %f", + check_msg->a_gf1); + ck_assert_msg( + (check_msg->acc[0] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[0], expected 9.31322574615e-07, is %f", + check_msg->acc[0]); + ck_assert_msg( + (check_msg->acc[1] * 100 - 9.31322574615e-07 * 100) < 0.05, + "incorrect value for acc[1], expected 9.31322574615e-07, is %f", + check_msg->acc[1]); + ck_assert_msg( + (check_msg->acc[2] * 100 - 2.79396772385e-06 * 100) < 0.05, + "incorrect value for acc[2], expected 2.79396772385e-06, is %f", + check_msg->acc[2]); + ck_assert_msg(check_msg->common.fit_interval == 0, + "incorrect value for common.fit_interval, expected 0, is %d", + check_msg->common.fit_interval); + ck_assert_msg(check_msg->common.health_bits == 0, + "incorrect value for common.health_bits, expected 0, is %d", + check_msg->common.health_bits); + ck_assert_msg(check_msg->common.sid.code == 6, + "incorrect value for common.sid.code, expected 6, is %d", + check_msg->common.sid.code); + ck_assert_msg(check_msg->common.sid.sat == 22, + "incorrect value for common.sid.sat, expected 22, is %d", + check_msg->common.sid.sat); + ck_assert_msg(check_msg->common.toe.tow == 446384, + "incorrect value for common.toe.tow, expected 446384, is %d", + check_msg->common.toe.tow); + ck_assert_msg(check_msg->common.toe.wn == 2154, + "incorrect value for common.toe.wn, expected 2154, is %d", + check_msg->common.toe.wn); + ck_assert_msg((check_msg->common.ura * 100 - 2.0 * 100) < 0.05, + "incorrect value for common.ura, expected 2.0, is %f", + check_msg->common.ura); + ck_assert_msg(check_msg->common.valid == 1, + "incorrect value for common.valid, expected 1, is %d", + check_msg->common.valid); + ck_assert_msg((check_msg->pos[0] * 100 - -12177330.0781 * 100) < 0.05, + "incorrect value for pos[0], expected -12177330.0781, is %f", + check_msg->pos[0]); + ck_assert_msg((check_msg->pos[1] * 100 - 599893.066406 * 100) < 0.05, + "incorrect value for pos[1], expected 599893.066406, is %f", + check_msg->pos[1]); + ck_assert_msg((check_msg->pos[2] * 100 - -22373708.4961 * 100) < 0.05, + "incorrect value for pos[2], expected -22373708.4961, is %f", + check_msg->pos[2]); + ck_assert_msg((check_msg->vel[0] * 100 - -1726.50623322 * 100) < 0.05, + "incorrect value for vel[0], expected -1726.50623322, is %f", + check_msg->vel[0]); + ck_assert_msg((check_msg->vel[1] * 100 - -2542.61493683 * 100) < 0.05, + "incorrect value for vel[1], expected -2542.61493683, is %f", + check_msg->vel[1]); + ck_assert_msg((check_msg->vel[2] * 100 - 869.817733765 * 100) < 0.05, + "incorrect value for vel[2], expected 869.817733765, is %f", + check_msg->vel[2]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgGnssCapb.c b/c/test/legacy/auto_check_sbp_observation_MsgGnssCapb.c new file mode 100644 index 0000000000..ab27bfac72 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgGnssCapb.c @@ -0,0 +1,283 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgGnssCapb) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x96, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x96, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, + 64, 0, 0, 0, 0, 81, 173, 144, 46, 0, 0, 0, 0, 209, 139, + 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, 240, + 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, + 0, 0, 0, 0, 40, 75, 250, 114, 0, 0, 0, 0, 119, 147, 123, + 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, 116, + 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, + 0, 0, 0, 252, 62, 221, 28, 0, 0, 0, 0, 163, 90, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_gnss_capb_t *test_msg = (msg_gnss_capb_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->gc.bds_active = 1929005864; + test_msg->gc.bds_b2 = 33839445; + test_msg->gc.bds_b2a = 378107113; + test_msg->gc.bds_d2nav = 1367053175; + test_msg->gc.gal_active = 1392028637; + test_msg->gc.gal_e5 = 484261628; + test_msg->gc.glo_active = 13159676; + test_msg->gc.glo_l2of = 824073421; + test_msg->gc.glo_l3 = 404081648; + test_msg->gc.gps_active = 1079028506; + test_msg->gc.gps_l2c = 781233489; + test_msg->gc.gps_l5 = 1818069969; + test_msg->gc.qzss_active = 198929863; + test_msg->gc.sbas_active = 548822484; + test_msg->gc.sbas_l5 = 465576041; + test_msg->t_nmct.tow = 446384; + test_msg->t_nmct.wn = 2154; + sbp_payload_send(&sbp_state, 0x96, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x96, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_gnss_capb_t *check_msg = (msg_gnss_capb_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->gc.bds_active == 1929005864, + "incorrect value for gc.bds_active, expected 1929005864, is %d", + check_msg->gc.bds_active); + ck_assert_msg(check_msg->gc.bds_b2 == 33839445, + "incorrect value for gc.bds_b2, expected 33839445, is %d", + check_msg->gc.bds_b2); + ck_assert_msg(check_msg->gc.bds_b2a == 378107113, + "incorrect value for gc.bds_b2a, expected 378107113, is %d", + check_msg->gc.bds_b2a); + ck_assert_msg( + check_msg->gc.bds_d2nav == 1367053175, + "incorrect value for gc.bds_d2nav, expected 1367053175, is %d", + check_msg->gc.bds_d2nav); + ck_assert_msg( + check_msg->gc.gal_active == 1392028637, + "incorrect value for gc.gal_active, expected 1392028637, is %d", + check_msg->gc.gal_active); + ck_assert_msg(check_msg->gc.gal_e5 == 484261628, + "incorrect value for gc.gal_e5, expected 484261628, is %d", + check_msg->gc.gal_e5); + ck_assert_msg(check_msg->gc.glo_active == 13159676, + "incorrect value for gc.glo_active, expected 13159676, is %d", + check_msg->gc.glo_active); + ck_assert_msg(check_msg->gc.glo_l2of == 824073421, + "incorrect value for gc.glo_l2of, expected 824073421, is %d", + check_msg->gc.glo_l2of); + ck_assert_msg(check_msg->gc.glo_l3 == 404081648, + "incorrect value for gc.glo_l3, expected 404081648, is %d", + check_msg->gc.glo_l3); + ck_assert_msg( + check_msg->gc.gps_active == 1079028506, + "incorrect value for gc.gps_active, expected 1079028506, is %d", + check_msg->gc.gps_active); + ck_assert_msg(check_msg->gc.gps_l2c == 781233489, + "incorrect value for gc.gps_l2c, expected 781233489, is %d", + check_msg->gc.gps_l2c); + ck_assert_msg(check_msg->gc.gps_l5 == 1818069969, + "incorrect value for gc.gps_l5, expected 1818069969, is %d", + check_msg->gc.gps_l5); + ck_assert_msg( + check_msg->gc.qzss_active == 198929863, + "incorrect value for gc.qzss_active, expected 198929863, is %d", + check_msg->gc.qzss_active); + ck_assert_msg( + check_msg->gc.sbas_active == 548822484, + "incorrect value for gc.sbas_active, expected 548822484, is %d", + check_msg->gc.sbas_active); + ck_assert_msg(check_msg->gc.sbas_l5 == 465576041, + "incorrect value for gc.sbas_l5, expected 465576041, is %d", + check_msg->gc.sbas_l5); + ck_assert_msg(check_msg->t_nmct.tow == 446384, + "incorrect value for t_nmct.tow, expected 446384, is %d", + check_msg->t_nmct.tow); + ck_assert_msg(check_msg->t_nmct.wn == 2154, + "incorrect value for t_nmct.wn, expected 2154, is %d", + check_msg->t_nmct.wn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgGnssCapb_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgGnssCapb"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgGnssCapb"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgGnssCapb); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgGroupDelay.c b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelay.c new file mode 100644 index 0000000000..1f11f70cfa --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelay.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgGroupDelay) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x94, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x94, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, + 22, 0, 1, 254, 253, 165, 255, 237, 23, 2, 201, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_group_delay_t *test_msg = (msg_group_delay_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->sid.code = 0; + test_msg->sid.sat = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + sbp_payload_send(&sbp_state, 0x94, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x94, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_group_delay_t *check_msg = (msg_group_delay_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->isc_l1ca == -91, + "incorrect value for isc_l1ca, expected -91, is %d", + check_msg->isc_l1ca); + ck_assert_msg(check_msg->isc_l2c == 6125, + "incorrect value for isc_l2c, expected 6125, is %d", + check_msg->isc_l2c); + ck_assert_msg(check_msg->sid.code == 0, + "incorrect value for sid.code, expected 0, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 22, + "incorrect value for sid.sat, expected 22, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->t_op.tow == 446384, + "incorrect value for t_op.tow, expected 446384, is %d", + check_msg->t_op.tow); + ck_assert_msg(check_msg->t_op.wn == 2154, + "incorrect value for t_op.wn, expected 2154, is %d", + check_msg->t_op.wn); + ck_assert_msg(check_msg->tgd == -514, + "incorrect value for tgd, expected -514, is %d", + check_msg->tgd); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgGroupDelay_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgGroupDelay"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgGroupDelay"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgGroupDelay); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepA.c b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepA.c new file mode 100644 index 0000000000..f3c34a7538 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepA.c @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgGroupDelayDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x92, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x92, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, + 8, 22, 1, 254, 253, 165, 255, 237, 23, 162, 91, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_group_delay_dep_a_t *test_msg = + (msg_group_delay_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->prn = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + sbp_payload_send(&sbp_state, 0x92, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x92, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_group_delay_dep_a_t *check_msg = + (msg_group_delay_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->isc_l1ca == -91, + "incorrect value for isc_l1ca, expected -91, is %d", + check_msg->isc_l1ca); + ck_assert_msg(check_msg->isc_l2c == 6125, + "incorrect value for isc_l2c, expected 6125, is %d", + check_msg->isc_l2c); + ck_assert_msg(check_msg->prn == 22, + "incorrect value for prn, expected 22, is %d", + check_msg->prn); + ck_assert_msg(check_msg->t_op.tow == 446384, + "incorrect value for t_op.tow, expected 446384, is %d", + check_msg->t_op.tow); + ck_assert_msg(check_msg->t_op.wn == 2154, + "incorrect value for t_op.wn, expected 2154, is %d", + check_msg->t_op.wn); + ck_assert_msg(check_msg->tgd == -514, + "incorrect value for tgd, expected -514, is %d", + check_msg->tgd); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgGroupDelayDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgGroupDelayDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgGroupDelayDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgGroupDelayDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepB.c b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepB.c new file mode 100644 index 0000000000..ee8646240f --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgGroupDelayDepB.c @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgGroupDelayDepB) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x93, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x93, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, + 0, 0, 0, 1, 254, 253, 165, 255, 237, 23, 221, 202, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_group_delay_dep_b_t *test_msg = + (msg_group_delay_dep_b_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + sbp_payload_send(&sbp_state, 0x93, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x93, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_group_delay_dep_b_t *check_msg = + (msg_group_delay_dep_b_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->isc_l1ca == -91, + "incorrect value for isc_l1ca, expected -91, is %d", + check_msg->isc_l1ca); + ck_assert_msg(check_msg->isc_l2c == 6125, + "incorrect value for isc_l2c, expected 6125, is %d", + check_msg->isc_l2c); + ck_assert_msg(check_msg->sid.code == 0, + "incorrect value for sid.code, expected 0, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.reserved == 0, + "incorrect value for sid.reserved, expected 0, is %d", + check_msg->sid.reserved); + ck_assert_msg(check_msg->sid.sat == 22, + "incorrect value for sid.sat, expected 22, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->t_op.tow == 446384, + "incorrect value for t_op.tow, expected 446384, is %d", + check_msg->t_op.tow); + ck_assert_msg(check_msg->t_op.wn == 2154, + "incorrect value for t_op.wn, expected 2154, is %d", + check_msg->t_op.wn); + ck_assert_msg(check_msg->tgd == -514, + "incorrect value for tgd, expected -514, is %d", + check_msg->tgd); + ck_assert_msg(check_msg->valid == 1, + "incorrect value for valid, expected 1, is %d", + check_msg->valid); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgGroupDelayDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgGroupDelayDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_MsgGroupDelayDepB"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_observation_MsgGroupDelayDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgIono.c b/c/test/legacy/auto_check_sbp_observation_MsgIono.c new file mode 100644 index 0000000000..6ce33bd350 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgIono.c @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgIono) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x90, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x90, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, 80, 62, 0, 0, 0, 0, + 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, + 0, 0, 243, 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, + 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, 101, 31, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_iono_t *test_msg = (msg_iono_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->a0 = 4.6566128730773926e-09; + test_msg->a1 = 1.4901161193847656e-08; + test_msg->a2 = -5.960464477539063e-08; + test_msg->a3 = -5.960464477539063e-08; + test_msg->b0 = 77824.0; + test_msg->b1 = 49152.0; + test_msg->b2 = -65536.0; + test_msg->b3 = -327680.0; + test_msg->t_nmct.tow = 0; + test_msg->t_nmct.wn = 0; + sbp_payload_send(&sbp_state, 0x90, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x90, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_iono_t *check_msg = (msg_iono_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg((check_msg->a0 * 100 - 4.65661287308e-09 * 100) < 0.05, + "incorrect value for a0, expected 4.65661287308e-09, is %f", + check_msg->a0); + ck_assert_msg((check_msg->a1 * 100 - 1.49011611938e-08 * 100) < 0.05, + "incorrect value for a1, expected 1.49011611938e-08, is %f", + check_msg->a1); + ck_assert_msg((check_msg->a2 * 100 - -5.96046447754e-08 * 100) < 0.05, + "incorrect value for a2, expected -5.96046447754e-08, is %f", + check_msg->a2); + ck_assert_msg((check_msg->a3 * 100 - -5.96046447754e-08 * 100) < 0.05, + "incorrect value for a3, expected -5.96046447754e-08, is %f", + check_msg->a3); + ck_assert_msg((check_msg->b0 * 100 - 77824.0 * 100) < 0.05, + "incorrect value for b0, expected 77824.0, is %f", + check_msg->b0); + ck_assert_msg((check_msg->b1 * 100 - 49152.0 * 100) < 0.05, + "incorrect value for b1, expected 49152.0, is %f", + check_msg->b1); + ck_assert_msg((check_msg->b2 * 100 - -65536.0 * 100) < 0.05, + "incorrect value for b2, expected -65536.0, is %f", + check_msg->b2); + ck_assert_msg((check_msg->b3 * 100 - -327680.0 * 100) < 0.05, + "incorrect value for b3, expected -327680.0, is %f", + check_msg->b3); + ck_assert_msg(check_msg->t_nmct.tow == 0, + "incorrect value for t_nmct.tow, expected 0, is %d", + check_msg->t_nmct.tow); + ck_assert_msg(check_msg->t_nmct.wn == 0, + "incorrect value for t_nmct.wn, expected 0, is %d", + check_msg->t_nmct.wn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgIono_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_observation_MsgIono"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_observation_MsgIono"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_observation_MsgIono); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c b/c/test/legacy/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c new file mode 100644 index 0000000000..8be7d04903 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_observation_MsgSvConfigurationGpsDep.c @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x91, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x91, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_sv_configuration_gps_dep_t *test_msg = + (msg_sv_configuration_gps_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->l2c_mask = 2808462402; + test_msg->t_nmct.tow = 0; + test_msg->t_nmct.wn = 0; + sbp_payload_send(&sbp_state, 0x91, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x91, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_sv_configuration_gps_dep_t *check_msg = + (msg_sv_configuration_gps_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->l2c_mask == 2808462402, + "incorrect value for l2c_mask, expected 2808462402, is %d", + check_msg->l2c_mask); + ck_assert_msg(check_msg->t_nmct.tow == 0, + "incorrect value for t_nmct.tow, expected 0, is %d", + check_msg->t_nmct.tow); + ck_assert_msg(check_msg->t_nmct.wn == 0, + "incorrect value for t_nmct.wn, expected 0, is %d", + check_msg->t_nmct.wn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_observation_" + "MsgSvConfigurationGpsDep"); + tcase_add_test( + tc_acq, test_legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_orientation_MsgBaselineHeading.c b/c/test/legacy/auto_check_sbp_orientation_MsgBaselineHeading.c new file mode 100644 index 0000000000..beac4b06fa --- /dev/null +++ b/c/test/legacy/auto_check_sbp_orientation_MsgBaselineHeading.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_orientation_MsgBaselineHeading) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x20f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x20f, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 15, 2, 211, 93, 10, 156, 45, 13, + 196, 44, 84, 197, 61, 91, 91, 224, 254, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_baseline_heading_t *test_msg = + (msg_baseline_heading_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 91; + test_msg->heading = 1036342316; + test_msg->n_sats = 91; + test_msg->tow = 3289197980; + sbp_payload_send(&sbp_state, 0x20f, 24019, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 24019, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 24019, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x20f, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_baseline_heading_t *check_msg = + (msg_baseline_heading_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 91, + "incorrect value for flags, expected 91, is %d", + check_msg->flags); + ck_assert_msg(check_msg->heading == 1036342316, + "incorrect value for heading, expected 1036342316, is %d", + check_msg->heading); + ck_assert_msg(check_msg->n_sats == 91, + "incorrect value for n_sats, expected 91, is %d", + check_msg->n_sats); + ck_assert_msg(check_msg->tow == 3289197980, + "incorrect value for tow, expected 3289197980, is %d", + check_msg->tow); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_orientation_MsgBaselineHeading_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_orientation_MsgBaselineHeading"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_orientation_MsgBaselineHeading"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_orientation_MsgBaselineHeading); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgAlmanac.c b/c/test/legacy/auto_check_sbp_piksi_MsgAlmanac.c new file mode 100644 index 0000000000..4d7260842a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgAlmanac.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgAlmanac) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x69, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x69, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 105, 0, 108, 138, 0, 249, 171, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0x69, 35436, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 35436, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 35436, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x69, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgAlmanac_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgAlmanac"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgAlmanac"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgAlmanac); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCellModemStatus.c b/c/test/legacy/auto_check_sbp_piksi_MsgCellModemStatus.c new file mode 100644 index 0000000000..52553e7e8b --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCellModemStatus.c @@ -0,0 +1,2231 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCellModemStatus) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xbe, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xbe, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, + 52, 64, 176, 154, 98, 43, 132, 196, 89, 253, 161, 250, 174, 204, + 110, 47, 38, 187, 63, 102, 177, 162, 49, 80, 194, 37, 107, 60, + 225, 52, 101, 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, + 80, 243, 30, 206, 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, + 85, 146, 100, 190, 232, 207, 61, 61, 201, 220, 31, 78, 34, 57, + 82, 59, 104, 65, 221, 0, 43, 210, 9, 32, 122, 29, 237, 11, + 151, 223, 18, 81, 204, 172, 234, 127, 3, 82, 133, 169, 12, 176, + 193, 0, 24, 121, 85, 55, 214, 198, 75, 234, 179, 214, 85, 94, + 115, 21, 73, 121, 75, 46, 158, 63, 100, 122, 213, 20, 85, 212, + 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, 39, 164, 5, 175, + 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, 177, 0, 47, + 140, 33, 126, 221, 110, 144, 97, 74, 250, 181, 199, 27, 176, 65, + 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, 4, 90, 36, 7, + 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, + 83, 16, 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, + 141, 232, 33, 101, 231, 38, 75, 178, 243, 119, 1, 248, 218, 86, + 7, 88, 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, 156, 217, + 67, 239, 219, 31, 224, 176, 129, 81, 80, 40, 230, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_cell_modem_status_t *test_msg = + (msg_cell_modem_status_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[0] = 123; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[1] = 242; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[2] = 46; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[3] = 52; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[4] = 64; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[5] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[6] = 154; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[7] = 98; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[8] = 43; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[9] = 132; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[10] = 196; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[11] = 89; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[12] = 253; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[13] = 161; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[14] = 250; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[15] = 174; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[16] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[17] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[18] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[19] = 38; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[20] = 187; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[21] = 63; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[22] = 102; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[23] = 177; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[24] = 162; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[25] = 49; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[26] = 80; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[27] = 194; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[28] = 37; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[29] = 107; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[30] = 60; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[31] = 225; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[32] = 52; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[33] = 101; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[34] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[35] = 142; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[36] = 246; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[37] = 21; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[38] = 17; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[39] = 93; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[40] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[41] = 169; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[42] = 86; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[43] = 16; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[44] = 209; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[45] = 80; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[46] = 243; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[47] = 30; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[48] = 206; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[49] = 220; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[50] = 206; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[51] = 115; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[52] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[53] = 154; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[54] = 91; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[55] = 227; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[56] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[57] = 11; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[58] = 1; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[59] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[60] = 146; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[61] = 100; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[62] = 190; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[63] = 232; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[64] = 207; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[65] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[66] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[67] = 201; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[68] = 220; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[69] = 31; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[70] = 78; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[71] = 34; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[72] = 57; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[73] = 82; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[74] = 59; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[75] = 104; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[76] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[77] = 221; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[78] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[79] = 43; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[80] = 210; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[81] = 9; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[82] = 32; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[83] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[84] = 29; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[85] = 237; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[86] = 11; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[87] = 151; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[88] = 223; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[89] = 18; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[90] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[91] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[92] = 172; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[93] = 234; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[94] = 127; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[95] = 3; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[96] = 82; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[97] = 133; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[98] = 169; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[99] = 12; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[100] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[101] = 193; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[102] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[103] = 24; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[104] = 121; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[105] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[106] = 55; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[107] = 214; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[108] = 198; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[109] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[110] = 234; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[111] = 179; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[112] = 214; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[113] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[114] = 94; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[115] = 115; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[116] = 21; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[117] = 73; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[118] = 121; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[119] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[120] = 46; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[121] = 158; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[122] = 63; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[123] = 100; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[124] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[125] = 213; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[126] = 20; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[127] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[128] = 212; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[129] = 131; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[130] = 50; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[131] = 224; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[132] = 218; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[133] = 215; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[134] = 215; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[135] = 149; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[136] = 2; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[137] = 19; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[138] = 129; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[139] = 39; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[140] = 164; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[141] = 5; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[142] = 175; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[143] = 6; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[144] = 62; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[145] = 51; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[146] = 78; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[147] = 66; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[148] = 248; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[149] = 116; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[150] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[151] = 90; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[152] = 128; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[153] = 226; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[154] = 177; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[155] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[156] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[157] = 140; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[158] = 33; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[159] = 126; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[160] = 221; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[161] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[162] = 144; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[163] = 97; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[164] = 74; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[165] = 250; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[166] = 181; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[167] = 199; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[168] = 27; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[169] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[170] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[171] = 185; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[172] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[173] = 92; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[174] = 34; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[175] = 44; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[176] = 131; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[177] = 96; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[178] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[179] = 40; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[180] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[181] = 4; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[182] = 90; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[183] = 36; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[184] = 7; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[185] = 180; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[186] = 244; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[187] = 244; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[188] = 23; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[189] = 108; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[190] = 171; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[191] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[192] = 196; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[193] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[194] = 51; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[195] = 179; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[196] = 242; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[197] = 156; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[198] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[199] = 83; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[200] = 16; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[201] = 15; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[202] = 134; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[203] = 40; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[204] = 245; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[205] = 253; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[206] = 150; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[207] = 94; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[208] = 150; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[209] = 144; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[210] = 197; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[211] = 113; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[212] = 5; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[213] = 141; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[214] = 232; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[215] = 33; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[216] = 101; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[217] = 231; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[218] = 38; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[219] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[220] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[221] = 243; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[222] = 119; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[223] = 1; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[224] = 248; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[225] = 218; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[226] = 86; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[227] = 7; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[228] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[229] = 197; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[230] = 148; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[231] = 240; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[232] = 227; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[233] = 2; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[234] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[235] = 173; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[236] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[237] = 143; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[238] = 251; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[239] = 156; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[240] = 217; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[241] = 67; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[242] = 239; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[243] = 219; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[244] = 31; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[245] = 224; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[246] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[247] = 129; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[248] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->reserved[0]); + } + test_msg->reserved[249] = 80; + test_msg->signal_error_rate = 8588.2001953125; + test_msg->signal_strength = 103; + sbp_payload_send(&sbp_state, 0xbe, 6931, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 6931, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 6931, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xbe, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_cell_modem_status_t *check_msg = + (msg_cell_modem_status_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->reserved[0] == 123, + "incorrect value for reserved[0], expected 123, is %d", + check_msg->reserved[0]); + ck_assert_msg(check_msg->reserved[1] == 242, + "incorrect value for reserved[1], expected 242, is %d", + check_msg->reserved[1]); + ck_assert_msg(check_msg->reserved[2] == 46, + "incorrect value for reserved[2], expected 46, is %d", + check_msg->reserved[2]); + ck_assert_msg(check_msg->reserved[3] == 52, + "incorrect value for reserved[3], expected 52, is %d", + check_msg->reserved[3]); + ck_assert_msg(check_msg->reserved[4] == 64, + "incorrect value for reserved[4], expected 64, is %d", + check_msg->reserved[4]); + ck_assert_msg(check_msg->reserved[5] == 176, + "incorrect value for reserved[5], expected 176, is %d", + check_msg->reserved[5]); + ck_assert_msg(check_msg->reserved[6] == 154, + "incorrect value for reserved[6], expected 154, is %d", + check_msg->reserved[6]); + ck_assert_msg(check_msg->reserved[7] == 98, + "incorrect value for reserved[7], expected 98, is %d", + check_msg->reserved[7]); + ck_assert_msg(check_msg->reserved[8] == 43, + "incorrect value for reserved[8], expected 43, is %d", + check_msg->reserved[8]); + ck_assert_msg(check_msg->reserved[9] == 132, + "incorrect value for reserved[9], expected 132, is %d", + check_msg->reserved[9]); + ck_assert_msg(check_msg->reserved[10] == 196, + "incorrect value for reserved[10], expected 196, is %d", + check_msg->reserved[10]); + ck_assert_msg(check_msg->reserved[11] == 89, + "incorrect value for reserved[11], expected 89, is %d", + check_msg->reserved[11]); + ck_assert_msg(check_msg->reserved[12] == 253, + "incorrect value for reserved[12], expected 253, is %d", + check_msg->reserved[12]); + ck_assert_msg(check_msg->reserved[13] == 161, + "incorrect value for reserved[13], expected 161, is %d", + check_msg->reserved[13]); + ck_assert_msg(check_msg->reserved[14] == 250, + "incorrect value for reserved[14], expected 250, is %d", + check_msg->reserved[14]); + ck_assert_msg(check_msg->reserved[15] == 174, + "incorrect value for reserved[15], expected 174, is %d", + check_msg->reserved[15]); + ck_assert_msg(check_msg->reserved[16] == 204, + "incorrect value for reserved[16], expected 204, is %d", + check_msg->reserved[16]); + ck_assert_msg(check_msg->reserved[17] == 110, + "incorrect value for reserved[17], expected 110, is %d", + check_msg->reserved[17]); + ck_assert_msg(check_msg->reserved[18] == 47, + "incorrect value for reserved[18], expected 47, is %d", + check_msg->reserved[18]); + ck_assert_msg(check_msg->reserved[19] == 38, + "incorrect value for reserved[19], expected 38, is %d", + check_msg->reserved[19]); + ck_assert_msg(check_msg->reserved[20] == 187, + "incorrect value for reserved[20], expected 187, is %d", + check_msg->reserved[20]); + ck_assert_msg(check_msg->reserved[21] == 63, + "incorrect value for reserved[21], expected 63, is %d", + check_msg->reserved[21]); + ck_assert_msg(check_msg->reserved[22] == 102, + "incorrect value for reserved[22], expected 102, is %d", + check_msg->reserved[22]); + ck_assert_msg(check_msg->reserved[23] == 177, + "incorrect value for reserved[23], expected 177, is %d", + check_msg->reserved[23]); + ck_assert_msg(check_msg->reserved[24] == 162, + "incorrect value for reserved[24], expected 162, is %d", + check_msg->reserved[24]); + ck_assert_msg(check_msg->reserved[25] == 49, + "incorrect value for reserved[25], expected 49, is %d", + check_msg->reserved[25]); + ck_assert_msg(check_msg->reserved[26] == 80, + "incorrect value for reserved[26], expected 80, is %d", + check_msg->reserved[26]); + ck_assert_msg(check_msg->reserved[27] == 194, + "incorrect value for reserved[27], expected 194, is %d", + check_msg->reserved[27]); + ck_assert_msg(check_msg->reserved[28] == 37, + "incorrect value for reserved[28], expected 37, is %d", + check_msg->reserved[28]); + ck_assert_msg(check_msg->reserved[29] == 107, + "incorrect value for reserved[29], expected 107, is %d", + check_msg->reserved[29]); + ck_assert_msg(check_msg->reserved[30] == 60, + "incorrect value for reserved[30], expected 60, is %d", + check_msg->reserved[30]); + ck_assert_msg(check_msg->reserved[31] == 225, + "incorrect value for reserved[31], expected 225, is %d", + check_msg->reserved[31]); + ck_assert_msg(check_msg->reserved[32] == 52, + "incorrect value for reserved[32], expected 52, is %d", + check_msg->reserved[32]); + ck_assert_msg(check_msg->reserved[33] == 101, + "incorrect value for reserved[33], expected 101, is %d", + check_msg->reserved[33]); + ck_assert_msg(check_msg->reserved[34] == 178, + "incorrect value for reserved[34], expected 178, is %d", + check_msg->reserved[34]); + ck_assert_msg(check_msg->reserved[35] == 142, + "incorrect value for reserved[35], expected 142, is %d", + check_msg->reserved[35]); + ck_assert_msg(check_msg->reserved[36] == 246, + "incorrect value for reserved[36], expected 246, is %d", + check_msg->reserved[36]); + ck_assert_msg(check_msg->reserved[37] == 21, + "incorrect value for reserved[37], expected 21, is %d", + check_msg->reserved[37]); + ck_assert_msg(check_msg->reserved[38] == 17, + "incorrect value for reserved[38], expected 17, is %d", + check_msg->reserved[38]); + ck_assert_msg(check_msg->reserved[39] == 93, + "incorrect value for reserved[39], expected 93, is %d", + check_msg->reserved[39]); + ck_assert_msg(check_msg->reserved[40] == 75, + "incorrect value for reserved[40], expected 75, is %d", + check_msg->reserved[40]); + ck_assert_msg(check_msg->reserved[41] == 169, + "incorrect value for reserved[41], expected 169, is %d", + check_msg->reserved[41]); + ck_assert_msg(check_msg->reserved[42] == 86, + "incorrect value for reserved[42], expected 86, is %d", + check_msg->reserved[42]); + ck_assert_msg(check_msg->reserved[43] == 16, + "incorrect value for reserved[43], expected 16, is %d", + check_msg->reserved[43]); + ck_assert_msg(check_msg->reserved[44] == 209, + "incorrect value for reserved[44], expected 209, is %d", + check_msg->reserved[44]); + ck_assert_msg(check_msg->reserved[45] == 80, + "incorrect value for reserved[45], expected 80, is %d", + check_msg->reserved[45]); + ck_assert_msg(check_msg->reserved[46] == 243, + "incorrect value for reserved[46], expected 243, is %d", + check_msg->reserved[46]); + ck_assert_msg(check_msg->reserved[47] == 30, + "incorrect value for reserved[47], expected 30, is %d", + check_msg->reserved[47]); + ck_assert_msg(check_msg->reserved[48] == 206, + "incorrect value for reserved[48], expected 206, is %d", + check_msg->reserved[48]); + ck_assert_msg(check_msg->reserved[49] == 220, + "incorrect value for reserved[49], expected 220, is %d", + check_msg->reserved[49]); + ck_assert_msg(check_msg->reserved[50] == 206, + "incorrect value for reserved[50], expected 206, is %d", + check_msg->reserved[50]); + ck_assert_msg(check_msg->reserved[51] == 115, + "incorrect value for reserved[51], expected 115, is %d", + check_msg->reserved[51]); + ck_assert_msg(check_msg->reserved[52] == 47, + "incorrect value for reserved[52], expected 47, is %d", + check_msg->reserved[52]); + ck_assert_msg(check_msg->reserved[53] == 154, + "incorrect value for reserved[53], expected 154, is %d", + check_msg->reserved[53]); + ck_assert_msg(check_msg->reserved[54] == 91, + "incorrect value for reserved[54], expected 91, is %d", + check_msg->reserved[54]); + ck_assert_msg(check_msg->reserved[55] == 227, + "incorrect value for reserved[55], expected 227, is %d", + check_msg->reserved[55]); + ck_assert_msg(check_msg->reserved[56] == 88, + "incorrect value for reserved[56], expected 88, is %d", + check_msg->reserved[56]); + ck_assert_msg(check_msg->reserved[57] == 11, + "incorrect value for reserved[57], expected 11, is %d", + check_msg->reserved[57]); + ck_assert_msg(check_msg->reserved[58] == 1, + "incorrect value for reserved[58], expected 1, is %d", + check_msg->reserved[58]); + ck_assert_msg(check_msg->reserved[59] == 85, + "incorrect value for reserved[59], expected 85, is %d", + check_msg->reserved[59]); + ck_assert_msg(check_msg->reserved[60] == 146, + "incorrect value for reserved[60], expected 146, is %d", + check_msg->reserved[60]); + ck_assert_msg(check_msg->reserved[61] == 100, + "incorrect value for reserved[61], expected 100, is %d", + check_msg->reserved[61]); + ck_assert_msg(check_msg->reserved[62] == 190, + "incorrect value for reserved[62], expected 190, is %d", + check_msg->reserved[62]); + ck_assert_msg(check_msg->reserved[63] == 232, + "incorrect value for reserved[63], expected 232, is %d", + check_msg->reserved[63]); + ck_assert_msg(check_msg->reserved[64] == 207, + "incorrect value for reserved[64], expected 207, is %d", + check_msg->reserved[64]); + ck_assert_msg(check_msg->reserved[65] == 61, + "incorrect value for reserved[65], expected 61, is %d", + check_msg->reserved[65]); + ck_assert_msg(check_msg->reserved[66] == 61, + "incorrect value for reserved[66], expected 61, is %d", + check_msg->reserved[66]); + ck_assert_msg(check_msg->reserved[67] == 201, + "incorrect value for reserved[67], expected 201, is %d", + check_msg->reserved[67]); + ck_assert_msg(check_msg->reserved[68] == 220, + "incorrect value for reserved[68], expected 220, is %d", + check_msg->reserved[68]); + ck_assert_msg(check_msg->reserved[69] == 31, + "incorrect value for reserved[69], expected 31, is %d", + check_msg->reserved[69]); + ck_assert_msg(check_msg->reserved[70] == 78, + "incorrect value for reserved[70], expected 78, is %d", + check_msg->reserved[70]); + ck_assert_msg(check_msg->reserved[71] == 34, + "incorrect value for reserved[71], expected 34, is %d", + check_msg->reserved[71]); + ck_assert_msg(check_msg->reserved[72] == 57, + "incorrect value for reserved[72], expected 57, is %d", + check_msg->reserved[72]); + ck_assert_msg(check_msg->reserved[73] == 82, + "incorrect value for reserved[73], expected 82, is %d", + check_msg->reserved[73]); + ck_assert_msg(check_msg->reserved[74] == 59, + "incorrect value for reserved[74], expected 59, is %d", + check_msg->reserved[74]); + ck_assert_msg(check_msg->reserved[75] == 104, + "incorrect value for reserved[75], expected 104, is %d", + check_msg->reserved[75]); + ck_assert_msg(check_msg->reserved[76] == 65, + "incorrect value for reserved[76], expected 65, is %d", + check_msg->reserved[76]); + ck_assert_msg(check_msg->reserved[77] == 221, + "incorrect value for reserved[77], expected 221, is %d", + check_msg->reserved[77]); + ck_assert_msg(check_msg->reserved[78] == 0, + "incorrect value for reserved[78], expected 0, is %d", + check_msg->reserved[78]); + ck_assert_msg(check_msg->reserved[79] == 43, + "incorrect value for reserved[79], expected 43, is %d", + check_msg->reserved[79]); + ck_assert_msg(check_msg->reserved[80] == 210, + "incorrect value for reserved[80], expected 210, is %d", + check_msg->reserved[80]); + ck_assert_msg(check_msg->reserved[81] == 9, + "incorrect value for reserved[81], expected 9, is %d", + check_msg->reserved[81]); + ck_assert_msg(check_msg->reserved[82] == 32, + "incorrect value for reserved[82], expected 32, is %d", + check_msg->reserved[82]); + ck_assert_msg(check_msg->reserved[83] == 122, + "incorrect value for reserved[83], expected 122, is %d", + check_msg->reserved[83]); + ck_assert_msg(check_msg->reserved[84] == 29, + "incorrect value for reserved[84], expected 29, is %d", + check_msg->reserved[84]); + ck_assert_msg(check_msg->reserved[85] == 237, + "incorrect value for reserved[85], expected 237, is %d", + check_msg->reserved[85]); + ck_assert_msg(check_msg->reserved[86] == 11, + "incorrect value for reserved[86], expected 11, is %d", + check_msg->reserved[86]); + ck_assert_msg(check_msg->reserved[87] == 151, + "incorrect value for reserved[87], expected 151, is %d", + check_msg->reserved[87]); + ck_assert_msg(check_msg->reserved[88] == 223, + "incorrect value for reserved[88], expected 223, is %d", + check_msg->reserved[88]); + ck_assert_msg(check_msg->reserved[89] == 18, + "incorrect value for reserved[89], expected 18, is %d", + check_msg->reserved[89]); + ck_assert_msg(check_msg->reserved[90] == 81, + "incorrect value for reserved[90], expected 81, is %d", + check_msg->reserved[90]); + ck_assert_msg(check_msg->reserved[91] == 204, + "incorrect value for reserved[91], expected 204, is %d", + check_msg->reserved[91]); + ck_assert_msg(check_msg->reserved[92] == 172, + "incorrect value for reserved[92], expected 172, is %d", + check_msg->reserved[92]); + ck_assert_msg(check_msg->reserved[93] == 234, + "incorrect value for reserved[93], expected 234, is %d", + check_msg->reserved[93]); + ck_assert_msg(check_msg->reserved[94] == 127, + "incorrect value for reserved[94], expected 127, is %d", + check_msg->reserved[94]); + ck_assert_msg(check_msg->reserved[95] == 3, + "incorrect value for reserved[95], expected 3, is %d", + check_msg->reserved[95]); + ck_assert_msg(check_msg->reserved[96] == 82, + "incorrect value for reserved[96], expected 82, is %d", + check_msg->reserved[96]); + ck_assert_msg(check_msg->reserved[97] == 133, + "incorrect value for reserved[97], expected 133, is %d", + check_msg->reserved[97]); + ck_assert_msg(check_msg->reserved[98] == 169, + "incorrect value for reserved[98], expected 169, is %d", + check_msg->reserved[98]); + ck_assert_msg(check_msg->reserved[99] == 12, + "incorrect value for reserved[99], expected 12, is %d", + check_msg->reserved[99]); + ck_assert_msg(check_msg->reserved[100] == 176, + "incorrect value for reserved[100], expected 176, is %d", + check_msg->reserved[100]); + ck_assert_msg(check_msg->reserved[101] == 193, + "incorrect value for reserved[101], expected 193, is %d", + check_msg->reserved[101]); + ck_assert_msg(check_msg->reserved[102] == 0, + "incorrect value for reserved[102], expected 0, is %d", + check_msg->reserved[102]); + ck_assert_msg(check_msg->reserved[103] == 24, + "incorrect value for reserved[103], expected 24, is %d", + check_msg->reserved[103]); + ck_assert_msg(check_msg->reserved[104] == 121, + "incorrect value for reserved[104], expected 121, is %d", + check_msg->reserved[104]); + ck_assert_msg(check_msg->reserved[105] == 85, + "incorrect value for reserved[105], expected 85, is %d", + check_msg->reserved[105]); + ck_assert_msg(check_msg->reserved[106] == 55, + "incorrect value for reserved[106], expected 55, is %d", + check_msg->reserved[106]); + ck_assert_msg(check_msg->reserved[107] == 214, + "incorrect value for reserved[107], expected 214, is %d", + check_msg->reserved[107]); + ck_assert_msg(check_msg->reserved[108] == 198, + "incorrect value for reserved[108], expected 198, is %d", + check_msg->reserved[108]); + ck_assert_msg(check_msg->reserved[109] == 75, + "incorrect value for reserved[109], expected 75, is %d", + check_msg->reserved[109]); + ck_assert_msg(check_msg->reserved[110] == 234, + "incorrect value for reserved[110], expected 234, is %d", + check_msg->reserved[110]); + ck_assert_msg(check_msg->reserved[111] == 179, + "incorrect value for reserved[111], expected 179, is %d", + check_msg->reserved[111]); + ck_assert_msg(check_msg->reserved[112] == 214, + "incorrect value for reserved[112], expected 214, is %d", + check_msg->reserved[112]); + ck_assert_msg(check_msg->reserved[113] == 85, + "incorrect value for reserved[113], expected 85, is %d", + check_msg->reserved[113]); + ck_assert_msg(check_msg->reserved[114] == 94, + "incorrect value for reserved[114], expected 94, is %d", + check_msg->reserved[114]); + ck_assert_msg(check_msg->reserved[115] == 115, + "incorrect value for reserved[115], expected 115, is %d", + check_msg->reserved[115]); + ck_assert_msg(check_msg->reserved[116] == 21, + "incorrect value for reserved[116], expected 21, is %d", + check_msg->reserved[116]); + ck_assert_msg(check_msg->reserved[117] == 73, + "incorrect value for reserved[117], expected 73, is %d", + check_msg->reserved[117]); + ck_assert_msg(check_msg->reserved[118] == 121, + "incorrect value for reserved[118], expected 121, is %d", + check_msg->reserved[118]); + ck_assert_msg(check_msg->reserved[119] == 75, + "incorrect value for reserved[119], expected 75, is %d", + check_msg->reserved[119]); + ck_assert_msg(check_msg->reserved[120] == 46, + "incorrect value for reserved[120], expected 46, is %d", + check_msg->reserved[120]); + ck_assert_msg(check_msg->reserved[121] == 158, + "incorrect value for reserved[121], expected 158, is %d", + check_msg->reserved[121]); + ck_assert_msg(check_msg->reserved[122] == 63, + "incorrect value for reserved[122], expected 63, is %d", + check_msg->reserved[122]); + ck_assert_msg(check_msg->reserved[123] == 100, + "incorrect value for reserved[123], expected 100, is %d", + check_msg->reserved[123]); + ck_assert_msg(check_msg->reserved[124] == 122, + "incorrect value for reserved[124], expected 122, is %d", + check_msg->reserved[124]); + ck_assert_msg(check_msg->reserved[125] == 213, + "incorrect value for reserved[125], expected 213, is %d", + check_msg->reserved[125]); + ck_assert_msg(check_msg->reserved[126] == 20, + "incorrect value for reserved[126], expected 20, is %d", + check_msg->reserved[126]); + ck_assert_msg(check_msg->reserved[127] == 85, + "incorrect value for reserved[127], expected 85, is %d", + check_msg->reserved[127]); + ck_assert_msg(check_msg->reserved[128] == 212, + "incorrect value for reserved[128], expected 212, is %d", + check_msg->reserved[128]); + ck_assert_msg(check_msg->reserved[129] == 131, + "incorrect value for reserved[129], expected 131, is %d", + check_msg->reserved[129]); + ck_assert_msg(check_msg->reserved[130] == 50, + "incorrect value for reserved[130], expected 50, is %d", + check_msg->reserved[130]); + ck_assert_msg(check_msg->reserved[131] == 224, + "incorrect value for reserved[131], expected 224, is %d", + check_msg->reserved[131]); + ck_assert_msg(check_msg->reserved[132] == 218, + "incorrect value for reserved[132], expected 218, is %d", + check_msg->reserved[132]); + ck_assert_msg(check_msg->reserved[133] == 215, + "incorrect value for reserved[133], expected 215, is %d", + check_msg->reserved[133]); + ck_assert_msg(check_msg->reserved[134] == 215, + "incorrect value for reserved[134], expected 215, is %d", + check_msg->reserved[134]); + ck_assert_msg(check_msg->reserved[135] == 149, + "incorrect value for reserved[135], expected 149, is %d", + check_msg->reserved[135]); + ck_assert_msg(check_msg->reserved[136] == 2, + "incorrect value for reserved[136], expected 2, is %d", + check_msg->reserved[136]); + ck_assert_msg(check_msg->reserved[137] == 19, + "incorrect value for reserved[137], expected 19, is %d", + check_msg->reserved[137]); + ck_assert_msg(check_msg->reserved[138] == 129, + "incorrect value for reserved[138], expected 129, is %d", + check_msg->reserved[138]); + ck_assert_msg(check_msg->reserved[139] == 39, + "incorrect value for reserved[139], expected 39, is %d", + check_msg->reserved[139]); + ck_assert_msg(check_msg->reserved[140] == 164, + "incorrect value for reserved[140], expected 164, is %d", + check_msg->reserved[140]); + ck_assert_msg(check_msg->reserved[141] == 5, + "incorrect value for reserved[141], expected 5, is %d", + check_msg->reserved[141]); + ck_assert_msg(check_msg->reserved[142] == 175, + "incorrect value for reserved[142], expected 175, is %d", + check_msg->reserved[142]); + ck_assert_msg(check_msg->reserved[143] == 6, + "incorrect value for reserved[143], expected 6, is %d", + check_msg->reserved[143]); + ck_assert_msg(check_msg->reserved[144] == 62, + "incorrect value for reserved[144], expected 62, is %d", + check_msg->reserved[144]); + ck_assert_msg(check_msg->reserved[145] == 51, + "incorrect value for reserved[145], expected 51, is %d", + check_msg->reserved[145]); + ck_assert_msg(check_msg->reserved[146] == 78, + "incorrect value for reserved[146], expected 78, is %d", + check_msg->reserved[146]); + ck_assert_msg(check_msg->reserved[147] == 66, + "incorrect value for reserved[147], expected 66, is %d", + check_msg->reserved[147]); + ck_assert_msg(check_msg->reserved[148] == 248, + "incorrect value for reserved[148], expected 248, is %d", + check_msg->reserved[148]); + ck_assert_msg(check_msg->reserved[149] == 116, + "incorrect value for reserved[149], expected 116, is %d", + check_msg->reserved[149]); + ck_assert_msg(check_msg->reserved[150] == 88, + "incorrect value for reserved[150], expected 88, is %d", + check_msg->reserved[150]); + ck_assert_msg(check_msg->reserved[151] == 90, + "incorrect value for reserved[151], expected 90, is %d", + check_msg->reserved[151]); + ck_assert_msg(check_msg->reserved[152] == 128, + "incorrect value for reserved[152], expected 128, is %d", + check_msg->reserved[152]); + ck_assert_msg(check_msg->reserved[153] == 226, + "incorrect value for reserved[153], expected 226, is %d", + check_msg->reserved[153]); + ck_assert_msg(check_msg->reserved[154] == 177, + "incorrect value for reserved[154], expected 177, is %d", + check_msg->reserved[154]); + ck_assert_msg(check_msg->reserved[155] == 0, + "incorrect value for reserved[155], expected 0, is %d", + check_msg->reserved[155]); + ck_assert_msg(check_msg->reserved[156] == 47, + "incorrect value for reserved[156], expected 47, is %d", + check_msg->reserved[156]); + ck_assert_msg(check_msg->reserved[157] == 140, + "incorrect value for reserved[157], expected 140, is %d", + check_msg->reserved[157]); + ck_assert_msg(check_msg->reserved[158] == 33, + "incorrect value for reserved[158], expected 33, is %d", + check_msg->reserved[158]); + ck_assert_msg(check_msg->reserved[159] == 126, + "incorrect value for reserved[159], expected 126, is %d", + check_msg->reserved[159]); + ck_assert_msg(check_msg->reserved[160] == 221, + "incorrect value for reserved[160], expected 221, is %d", + check_msg->reserved[160]); + ck_assert_msg(check_msg->reserved[161] == 110, + "incorrect value for reserved[161], expected 110, is %d", + check_msg->reserved[161]); + ck_assert_msg(check_msg->reserved[162] == 144, + "incorrect value for reserved[162], expected 144, is %d", + check_msg->reserved[162]); + ck_assert_msg(check_msg->reserved[163] == 97, + "incorrect value for reserved[163], expected 97, is %d", + check_msg->reserved[163]); + ck_assert_msg(check_msg->reserved[164] == 74, + "incorrect value for reserved[164], expected 74, is %d", + check_msg->reserved[164]); + ck_assert_msg(check_msg->reserved[165] == 250, + "incorrect value for reserved[165], expected 250, is %d", + check_msg->reserved[165]); + ck_assert_msg(check_msg->reserved[166] == 181, + "incorrect value for reserved[166], expected 181, is %d", + check_msg->reserved[166]); + ck_assert_msg(check_msg->reserved[167] == 199, + "incorrect value for reserved[167], expected 199, is %d", + check_msg->reserved[167]); + ck_assert_msg(check_msg->reserved[168] == 27, + "incorrect value for reserved[168], expected 27, is %d", + check_msg->reserved[168]); + ck_assert_msg(check_msg->reserved[169] == 176, + "incorrect value for reserved[169], expected 176, is %d", + check_msg->reserved[169]); + ck_assert_msg(check_msg->reserved[170] == 65, + "incorrect value for reserved[170], expected 65, is %d", + check_msg->reserved[170]); + ck_assert_msg(check_msg->reserved[171] == 185, + "incorrect value for reserved[171], expected 185, is %d", + check_msg->reserved[171]); + ck_assert_msg(check_msg->reserved[172] == 110, + "incorrect value for reserved[172], expected 110, is %d", + check_msg->reserved[172]); + ck_assert_msg(check_msg->reserved[173] == 92, + "incorrect value for reserved[173], expected 92, is %d", + check_msg->reserved[173]); + ck_assert_msg(check_msg->reserved[174] == 34, + "incorrect value for reserved[174], expected 34, is %d", + check_msg->reserved[174]); + ck_assert_msg(check_msg->reserved[175] == 44, + "incorrect value for reserved[175], expected 44, is %d", + check_msg->reserved[175]); + ck_assert_msg(check_msg->reserved[176] == 131, + "incorrect value for reserved[176], expected 131, is %d", + check_msg->reserved[176]); + ck_assert_msg(check_msg->reserved[177] == 96, + "incorrect value for reserved[177], expected 96, is %d", + check_msg->reserved[177]); + ck_assert_msg(check_msg->reserved[178] == 178, + "incorrect value for reserved[178], expected 178, is %d", + check_msg->reserved[178]); + ck_assert_msg(check_msg->reserved[179] == 40, + "incorrect value for reserved[179], expected 40, is %d", + check_msg->reserved[179]); + ck_assert_msg(check_msg->reserved[180] == 176, + "incorrect value for reserved[180], expected 176, is %d", + check_msg->reserved[180]); + ck_assert_msg(check_msg->reserved[181] == 4, + "incorrect value for reserved[181], expected 4, is %d", + check_msg->reserved[181]); + ck_assert_msg(check_msg->reserved[182] == 90, + "incorrect value for reserved[182], expected 90, is %d", + check_msg->reserved[182]); + ck_assert_msg(check_msg->reserved[183] == 36, + "incorrect value for reserved[183], expected 36, is %d", + check_msg->reserved[183]); + ck_assert_msg(check_msg->reserved[184] == 7, + "incorrect value for reserved[184], expected 7, is %d", + check_msg->reserved[184]); + ck_assert_msg(check_msg->reserved[185] == 180, + "incorrect value for reserved[185], expected 180, is %d", + check_msg->reserved[185]); + ck_assert_msg(check_msg->reserved[186] == 244, + "incorrect value for reserved[186], expected 244, is %d", + check_msg->reserved[186]); + ck_assert_msg(check_msg->reserved[187] == 244, + "incorrect value for reserved[187], expected 244, is %d", + check_msg->reserved[187]); + ck_assert_msg(check_msg->reserved[188] == 23, + "incorrect value for reserved[188], expected 23, is %d", + check_msg->reserved[188]); + ck_assert_msg(check_msg->reserved[189] == 108, + "incorrect value for reserved[189], expected 108, is %d", + check_msg->reserved[189]); + ck_assert_msg(check_msg->reserved[190] == 171, + "incorrect value for reserved[190], expected 171, is %d", + check_msg->reserved[190]); + ck_assert_msg(check_msg->reserved[191] == 204, + "incorrect value for reserved[191], expected 204, is %d", + check_msg->reserved[191]); + ck_assert_msg(check_msg->reserved[192] == 196, + "incorrect value for reserved[192], expected 196, is %d", + check_msg->reserved[192]); + ck_assert_msg(check_msg->reserved[193] == 61, + "incorrect value for reserved[193], expected 61, is %d", + check_msg->reserved[193]); + ck_assert_msg(check_msg->reserved[194] == 51, + "incorrect value for reserved[194], expected 51, is %d", + check_msg->reserved[194]); + ck_assert_msg(check_msg->reserved[195] == 179, + "incorrect value for reserved[195], expected 179, is %d", + check_msg->reserved[195]); + ck_assert_msg(check_msg->reserved[196] == 242, + "incorrect value for reserved[196], expected 242, is %d", + check_msg->reserved[196]); + ck_assert_msg(check_msg->reserved[197] == 156, + "incorrect value for reserved[197], expected 156, is %d", + check_msg->reserved[197]); + ck_assert_msg(check_msg->reserved[198] == 81, + "incorrect value for reserved[198], expected 81, is %d", + check_msg->reserved[198]); + ck_assert_msg(check_msg->reserved[199] == 83, + "incorrect value for reserved[199], expected 83, is %d", + check_msg->reserved[199]); + ck_assert_msg(check_msg->reserved[200] == 16, + "incorrect value for reserved[200], expected 16, is %d", + check_msg->reserved[200]); + ck_assert_msg(check_msg->reserved[201] == 15, + "incorrect value for reserved[201], expected 15, is %d", + check_msg->reserved[201]); + ck_assert_msg(check_msg->reserved[202] == 134, + "incorrect value for reserved[202], expected 134, is %d", + check_msg->reserved[202]); + ck_assert_msg(check_msg->reserved[203] == 40, + "incorrect value for reserved[203], expected 40, is %d", + check_msg->reserved[203]); + ck_assert_msg(check_msg->reserved[204] == 245, + "incorrect value for reserved[204], expected 245, is %d", + check_msg->reserved[204]); + ck_assert_msg(check_msg->reserved[205] == 253, + "incorrect value for reserved[205], expected 253, is %d", + check_msg->reserved[205]); + ck_assert_msg(check_msg->reserved[206] == 150, + "incorrect value for reserved[206], expected 150, is %d", + check_msg->reserved[206]); + ck_assert_msg(check_msg->reserved[207] == 94, + "incorrect value for reserved[207], expected 94, is %d", + check_msg->reserved[207]); + ck_assert_msg(check_msg->reserved[208] == 150, + "incorrect value for reserved[208], expected 150, is %d", + check_msg->reserved[208]); + ck_assert_msg(check_msg->reserved[209] == 144, + "incorrect value for reserved[209], expected 144, is %d", + check_msg->reserved[209]); + ck_assert_msg(check_msg->reserved[210] == 197, + "incorrect value for reserved[210], expected 197, is %d", + check_msg->reserved[210]); + ck_assert_msg(check_msg->reserved[211] == 113, + "incorrect value for reserved[211], expected 113, is %d", + check_msg->reserved[211]); + ck_assert_msg(check_msg->reserved[212] == 5, + "incorrect value for reserved[212], expected 5, is %d", + check_msg->reserved[212]); + ck_assert_msg(check_msg->reserved[213] == 141, + "incorrect value for reserved[213], expected 141, is %d", + check_msg->reserved[213]); + ck_assert_msg(check_msg->reserved[214] == 232, + "incorrect value for reserved[214], expected 232, is %d", + check_msg->reserved[214]); + ck_assert_msg(check_msg->reserved[215] == 33, + "incorrect value for reserved[215], expected 33, is %d", + check_msg->reserved[215]); + ck_assert_msg(check_msg->reserved[216] == 101, + "incorrect value for reserved[216], expected 101, is %d", + check_msg->reserved[216]); + ck_assert_msg(check_msg->reserved[217] == 231, + "incorrect value for reserved[217], expected 231, is %d", + check_msg->reserved[217]); + ck_assert_msg(check_msg->reserved[218] == 38, + "incorrect value for reserved[218], expected 38, is %d", + check_msg->reserved[218]); + ck_assert_msg(check_msg->reserved[219] == 75, + "incorrect value for reserved[219], expected 75, is %d", + check_msg->reserved[219]); + ck_assert_msg(check_msg->reserved[220] == 178, + "incorrect value for reserved[220], expected 178, is %d", + check_msg->reserved[220]); + ck_assert_msg(check_msg->reserved[221] == 243, + "incorrect value for reserved[221], expected 243, is %d", + check_msg->reserved[221]); + ck_assert_msg(check_msg->reserved[222] == 119, + "incorrect value for reserved[222], expected 119, is %d", + check_msg->reserved[222]); + ck_assert_msg(check_msg->reserved[223] == 1, + "incorrect value for reserved[223], expected 1, is %d", + check_msg->reserved[223]); + ck_assert_msg(check_msg->reserved[224] == 248, + "incorrect value for reserved[224], expected 248, is %d", + check_msg->reserved[224]); + ck_assert_msg(check_msg->reserved[225] == 218, + "incorrect value for reserved[225], expected 218, is %d", + check_msg->reserved[225]); + ck_assert_msg(check_msg->reserved[226] == 86, + "incorrect value for reserved[226], expected 86, is %d", + check_msg->reserved[226]); + ck_assert_msg(check_msg->reserved[227] == 7, + "incorrect value for reserved[227], expected 7, is %d", + check_msg->reserved[227]); + ck_assert_msg(check_msg->reserved[228] == 88, + "incorrect value for reserved[228], expected 88, is %d", + check_msg->reserved[228]); + ck_assert_msg(check_msg->reserved[229] == 197, + "incorrect value for reserved[229], expected 197, is %d", + check_msg->reserved[229]); + ck_assert_msg(check_msg->reserved[230] == 148, + "incorrect value for reserved[230], expected 148, is %d", + check_msg->reserved[230]); + ck_assert_msg(check_msg->reserved[231] == 240, + "incorrect value for reserved[231], expected 240, is %d", + check_msg->reserved[231]); + ck_assert_msg(check_msg->reserved[232] == 227, + "incorrect value for reserved[232], expected 227, is %d", + check_msg->reserved[232]); + ck_assert_msg(check_msg->reserved[233] == 2, + "incorrect value for reserved[233], expected 2, is %d", + check_msg->reserved[233]); + ck_assert_msg(check_msg->reserved[234] == 65, + "incorrect value for reserved[234], expected 65, is %d", + check_msg->reserved[234]); + ck_assert_msg(check_msg->reserved[235] == 173, + "incorrect value for reserved[235], expected 173, is %d", + check_msg->reserved[235]); + ck_assert_msg(check_msg->reserved[236] == 122, + "incorrect value for reserved[236], expected 122, is %d", + check_msg->reserved[236]); + ck_assert_msg(check_msg->reserved[237] == 143, + "incorrect value for reserved[237], expected 143, is %d", + check_msg->reserved[237]); + ck_assert_msg(check_msg->reserved[238] == 251, + "incorrect value for reserved[238], expected 251, is %d", + check_msg->reserved[238]); + ck_assert_msg(check_msg->reserved[239] == 156, + "incorrect value for reserved[239], expected 156, is %d", + check_msg->reserved[239]); + ck_assert_msg(check_msg->reserved[240] == 217, + "incorrect value for reserved[240], expected 217, is %d", + check_msg->reserved[240]); + ck_assert_msg(check_msg->reserved[241] == 67, + "incorrect value for reserved[241], expected 67, is %d", + check_msg->reserved[241]); + ck_assert_msg(check_msg->reserved[242] == 239, + "incorrect value for reserved[242], expected 239, is %d", + check_msg->reserved[242]); + ck_assert_msg(check_msg->reserved[243] == 219, + "incorrect value for reserved[243], expected 219, is %d", + check_msg->reserved[243]); + ck_assert_msg(check_msg->reserved[244] == 31, + "incorrect value for reserved[244], expected 31, is %d", + check_msg->reserved[244]); + ck_assert_msg(check_msg->reserved[245] == 224, + "incorrect value for reserved[245], expected 224, is %d", + check_msg->reserved[245]); + ck_assert_msg(check_msg->reserved[246] == 176, + "incorrect value for reserved[246], expected 176, is %d", + check_msg->reserved[246]); + ck_assert_msg(check_msg->reserved[247] == 129, + "incorrect value for reserved[247], expected 129, is %d", + check_msg->reserved[247]); + ck_assert_msg(check_msg->reserved[248] == 81, + "incorrect value for reserved[248], expected 81, is %d", + check_msg->reserved[248]); + ck_assert_msg(check_msg->reserved[249] == 80, + "incorrect value for reserved[249], expected 80, is %d", + check_msg->reserved[249]); + ck_assert_msg( + (check_msg->signal_error_rate * 100 - 8588.20019531 * 100) < 0.05, + "incorrect value for signal_error_rate, expected 8588.20019531, is %f", + check_msg->signal_error_rate); + ck_assert_msg(check_msg->signal_strength == 103, + "incorrect value for signal_strength, expected 103, is %d", + check_msg->signal_strength); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCellModemStatus_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_piksi_MsgCellModemStatus"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgCellModemStatus"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCellModemStatus); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCommandOutput.c b/c/test/legacy/auto_check_sbp_piksi_MsgCommandOutput.c new file mode 100644 index 0000000000..f0ccc82a57 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCommandOutput.c @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCommandOutput) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xbc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xbc, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, + 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116, 11, 109, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_command_output_t *test_msg = (msg_command_output_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = {(char)83, (char)111, (char)109, (char)101, + (char)32, (char)111, (char)117, (char)116, + (char)112, (char)117, (char)116, (char)32, + (char)116, (char)101, (char)120, (char)116}; + memcpy(test_msg->line, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->line) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->sequence = 2507449470; + sbp_payload_send(&sbp_state, 0xbc, 21554, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 21554, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 21554, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xbc, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_command_output_t *check_msg = + (msg_command_output_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = {(char)83, (char)111, (char)109, (char)101, + (char)32, (char)111, (char)117, (char)116, + (char)112, (char)117, (char)116, (char)32, + (char)116, (char)101, (char)120, (char)116}; + ck_assert_msg( + memcmp(check_msg->line, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->line, expected string '%s', is '%s'", + check_string, check_msg->line); + } + ck_assert_msg(check_msg->sequence == 2507449470, + "incorrect value for sequence, expected 2507449470, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCommandOutput_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgCommandOutput"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgCommandOutput"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCommandOutput); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCommandReq.c b/c/test/legacy/auto_check_sbp_piksi_MsgCommandReq.c new file mode 100644 index 0000000000..5f73bc734b --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCommandReq.c @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCommandReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb8, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb8, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, + 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, 24, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_command_req_t *test_msg = (msg_command_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)99, (char)111, (char)109, + (char)109, (char)97, (char)110, (char)100, (char)32, (char)119, + (char)105, (char)116, (char)104, (char)32, (char)97, (char)114, + (char)103, (char)115, (char)0}; + memcpy(test_msg->command, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->command) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->sequence = 1755532595; + sbp_payload_send(&sbp_state, 0xb8, 47274, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 47274, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 47274, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb8, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_command_req_t *check_msg = (msg_command_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)99, (char)111, (char)109, + (char)109, (char)97, (char)110, (char)100, (char)32, (char)119, + (char)105, (char)116, (char)104, (char)32, (char)97, (char)114, + (char)103, (char)115, (char)0}; + ck_assert_msg( + memcmp(check_msg->command, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->command, expected string '%s', is " + "'%s'", + check_string, check_msg->command); + } + ck_assert_msg(check_msg->sequence == 1755532595, + "incorrect value for sequence, expected 1755532595, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCommandReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgCommandReq"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgCommandReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCommandReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCommandResp.c b/c/test/legacy/auto_check_sbp_piksi_MsgCommandResp.c new file mode 100644 index 0000000000..7f2737f48a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCommandResp.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCommandResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb9, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb9, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 185, 0, 57, 206, 8, 118, 215, + 131, 160, 210, 110, 150, 103, 164, 240, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_command_resp_t *test_msg = (msg_command_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->code = 1737912018; + test_msg->sequence = 2692994934; + sbp_payload_send(&sbp_state, 0xb9, 52793, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52793, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 52793, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb9, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_command_resp_t *check_msg = + (msg_command_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->code == 1737912018, + "incorrect value for code, expected 1737912018, is %d", + check_msg->code); + ck_assert_msg(check_msg->sequence == 2692994934, + "incorrect value for sequence, expected 2692994934, is %d", + check_msg->sequence); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCommandResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgCommandResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgCommandResp"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCommandResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCwResults.c b/c/test/legacy/auto_check_sbp_piksi_MsgCwResults.c new file mode 100644 index 0000000000..db17a469c9 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCwResults.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCwResults) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xc0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xc0, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 192, 0, 99, 246, 0, 228, 72, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xc0, 63075, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63075, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 63075, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xc0, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCwResults_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgCwResults"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgCwResults"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCwResults); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgCwStart.c b/c/test/legacy/auto_check_sbp_piksi_MsgCwStart.c new file mode 100644 index 0000000000..1f5559d8cc --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgCwStart.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgCwStart) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xc1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xc1, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 193, 0, 30, 179, 0, 213, 138, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xc1, 45854, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 45854, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 45854, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xc1, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgCwStart_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgCwStart"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgCwStart"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgCwStart); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgFrontEndGain.c b/c/test/legacy/auto_check_sbp_piksi_MsgFrontEndGain.c new file mode 100644 index 0000000000..3212b289f8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgFrontEndGain.c @@ -0,0 +1,331 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgFrontEndGain) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xbf, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xbf, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, + 38, 38, 246, 233, 216, 80, 187, 213, 85, 2, 235, 135, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_front_end_gain_t *test_msg = (msg_front_end_gain_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[0] = -10; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[1] = -23; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[2] = -40; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[3] = 80; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[4] = -69; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[5] = -43; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[6] = 85; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->if_gain[0]); + } + test_msg->if_gain[7] = 2; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[0] = 41; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[1] = -123; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[2] = -122; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[3] = 10; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[4] = 105; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[5] = 20; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[6] = 38; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rf_gain[0]); + } + test_msg->rf_gain[7] = 38; + sbp_payload_send(&sbp_state, 0xbf, 62895, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 62895, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 62895, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xbf, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_front_end_gain_t *check_msg = + (msg_front_end_gain_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->if_gain[0] == -10, + "incorrect value for if_gain[0], expected -10, is %d", + check_msg->if_gain[0]); + ck_assert_msg(check_msg->if_gain[1] == -23, + "incorrect value for if_gain[1], expected -23, is %d", + check_msg->if_gain[1]); + ck_assert_msg(check_msg->if_gain[2] == -40, + "incorrect value for if_gain[2], expected -40, is %d", + check_msg->if_gain[2]); + ck_assert_msg(check_msg->if_gain[3] == 80, + "incorrect value for if_gain[3], expected 80, is %d", + check_msg->if_gain[3]); + ck_assert_msg(check_msg->if_gain[4] == -69, + "incorrect value for if_gain[4], expected -69, is %d", + check_msg->if_gain[4]); + ck_assert_msg(check_msg->if_gain[5] == -43, + "incorrect value for if_gain[5], expected -43, is %d", + check_msg->if_gain[5]); + ck_assert_msg(check_msg->if_gain[6] == 85, + "incorrect value for if_gain[6], expected 85, is %d", + check_msg->if_gain[6]); + ck_assert_msg(check_msg->if_gain[7] == 2, + "incorrect value for if_gain[7], expected 2, is %d", + check_msg->if_gain[7]); + ck_assert_msg(check_msg->rf_gain[0] == 41, + "incorrect value for rf_gain[0], expected 41, is %d", + check_msg->rf_gain[0]); + ck_assert_msg(check_msg->rf_gain[1] == -123, + "incorrect value for rf_gain[1], expected -123, is %d", + check_msg->rf_gain[1]); + ck_assert_msg(check_msg->rf_gain[2] == -122, + "incorrect value for rf_gain[2], expected -122, is %d", + check_msg->rf_gain[2]); + ck_assert_msg(check_msg->rf_gain[3] == 10, + "incorrect value for rf_gain[3], expected 10, is %d", + check_msg->rf_gain[3]); + ck_assert_msg(check_msg->rf_gain[4] == 105, + "incorrect value for rf_gain[4], expected 105, is %d", + check_msg->rf_gain[4]); + ck_assert_msg(check_msg->rf_gain[5] == 20, + "incorrect value for rf_gain[5], expected 20, is %d", + check_msg->rf_gain[5]); + ck_assert_msg(check_msg->rf_gain[6] == 38, + "incorrect value for rf_gain[6], expected 38, is %d", + check_msg->rf_gain[6]); + ck_assert_msg(check_msg->rf_gain[7] == 38, + "incorrect value for rf_gain[7], expected 38, is %d", + check_msg->rf_gain[7]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgFrontEndGain_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgFrontEndGain"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgFrontEndGain"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgFrontEndGain); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgInitBaseDep.c b/c/test/legacy/auto_check_sbp_piksi_MsgInitBaseDep.c new file mode 100644 index 0000000000..26f9508a70 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgInitBaseDep.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgInitBaseDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x23, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x23, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 35, 0, 184, 41, 0, 70, 13, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0x23, 10680, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 10680, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 10680, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x23, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgInitBaseDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgInitBaseDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgInitBaseDep"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgInitBaseDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatellite.c b/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatellite.c new file mode 100644 index 0000000000..e4f242828a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatellite.c @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgMaskSatellite) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x2b, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x2b, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_mask_satellite_t *test_msg = (msg_mask_satellite_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->mask = 183; + test_msg->sid.code = 57; + test_msg->sid.sat = 87; + sbp_payload_send(&sbp_state, 0x2b, 38829, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 38829, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 38829, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x2b, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_mask_satellite_t *check_msg = + (msg_mask_satellite_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->mask == 183, + "incorrect value for mask, expected 183, is %d", + check_msg->mask); + ck_assert_msg(check_msg->sid.code == 57, + "incorrect value for sid.code, expected 57, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 87, + "incorrect value for sid.sat, expected 87, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgMaskSatellite_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgMaskSatellite"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgMaskSatellite"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgMaskSatellite); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatelliteDep.c b/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatelliteDep.c new file mode 100644 index 0000000000..e327b26d0c --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgMaskSatelliteDep.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1b, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1b, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_mask_satellite_dep_t *test_msg = + (msg_mask_satellite_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->mask = 33; + test_msg->sid.code = 95; + test_msg->sid.reserved = 4; + test_msg->sid.sat = 39170; + sbp_payload_send(&sbp_state, 0x1b, 34491, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34491, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 34491, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1b, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_mask_satellite_dep_t *check_msg = + (msg_mask_satellite_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->mask == 33, + "incorrect value for mask, expected 33, is %d", + check_msg->mask); + ck_assert_msg(check_msg->sid.code == 95, + "incorrect value for sid.code, expected 95, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.reserved == 4, + "incorrect value for sid.reserved, expected 4, is %d", + check_msg->sid.reserved); + ck_assert_msg(check_msg->sid.sat == 39170, + "incorrect value for sid.sat, expected 39170, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateReq.c b/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateReq.c new file mode 100644 index 0000000000..7b92d10e73 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateReq.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgNetworkStateReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xba, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xba, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 186, 0, 83, 62, 0, 148, 73, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xba, 15955, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 15955, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 15955, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xba, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgNetworkStateReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_piksi_MsgNetworkStateReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgNetworkStateReq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgNetworkStateReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateResp.c b/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateResp.c new file mode 100644 index 0000000000..665b4825fd --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgNetworkStateResp.c @@ -0,0 +1,409 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgNetworkStateResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xbb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xbb, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, + 137, 32, 44, 114, 147, 68, 222, 92, 192, 78, 235, 63, + 208, 114, 53, 183, 24, 244, 231, 26, 105, 25, 136, 3, + 105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_network_state_resp_t *test_msg = + (msg_network_state_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 2471552451; + { + const char assign_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg->interface_name, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->interface_name) == 0) { + test_msg_len += sizeof(assign_string); + } + } + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv4_address[0]); + } + test_msg->ipv4_address[0] = 143; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv4_address[0]); + } + test_msg->ipv4_address[1] = 241; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv4_address[0]); + } + test_msg->ipv4_address[2] = 84; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv4_address[0]); + } + test_msg->ipv4_address[3] = 180; + test_msg->ipv4_mask_size = 152; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[0] = 194; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[1] = 137; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[2] = 32; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[3] = 44; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[4] = 114; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[5] = 147; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[6] = 68; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[7] = 222; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[8] = 92; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[9] = 192; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[10] = 78; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[11] = 235; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[12] = 63; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[13] = 208; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[14] = 114; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->ipv6_address[0]); + } + test_msg->ipv6_address[15] = 53; + test_msg->ipv6_mask_size = 183; + test_msg->rx_bytes = 451408920; + test_msg->tx_bytes = 59251049; + sbp_payload_send(&sbp_state, 0xbb, 3880, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 3880, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 3880, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xbb, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_network_state_resp_t *check_msg = + (msg_network_state_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 2471552451, + "incorrect value for flags, expected 2471552451, is %d", + check_msg->flags); + { + const char check_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + ck_assert_msg(memcmp(check_msg->interface_name, check_string, + sizeof(check_string)) == 0, + "incorrect value for check_msg->interface_name, expected " + "string '%s', is '%s'", + check_string, check_msg->interface_name); + } + ck_assert_msg(check_msg->ipv4_address[0] == 143, + "incorrect value for ipv4_address[0], expected 143, is %d", + check_msg->ipv4_address[0]); + ck_assert_msg(check_msg->ipv4_address[1] == 241, + "incorrect value for ipv4_address[1], expected 241, is %d", + check_msg->ipv4_address[1]); + ck_assert_msg(check_msg->ipv4_address[2] == 84, + "incorrect value for ipv4_address[2], expected 84, is %d", + check_msg->ipv4_address[2]); + ck_assert_msg(check_msg->ipv4_address[3] == 180, + "incorrect value for ipv4_address[3], expected 180, is %d", + check_msg->ipv4_address[3]); + ck_assert_msg(check_msg->ipv4_mask_size == 152, + "incorrect value for ipv4_mask_size, expected 152, is %d", + check_msg->ipv4_mask_size); + ck_assert_msg(check_msg->ipv6_address[0] == 194, + "incorrect value for ipv6_address[0], expected 194, is %d", + check_msg->ipv6_address[0]); + ck_assert_msg(check_msg->ipv6_address[1] == 137, + "incorrect value for ipv6_address[1], expected 137, is %d", + check_msg->ipv6_address[1]); + ck_assert_msg(check_msg->ipv6_address[2] == 32, + "incorrect value for ipv6_address[2], expected 32, is %d", + check_msg->ipv6_address[2]); + ck_assert_msg(check_msg->ipv6_address[3] == 44, + "incorrect value for ipv6_address[3], expected 44, is %d", + check_msg->ipv6_address[3]); + ck_assert_msg(check_msg->ipv6_address[4] == 114, + "incorrect value for ipv6_address[4], expected 114, is %d", + check_msg->ipv6_address[4]); + ck_assert_msg(check_msg->ipv6_address[5] == 147, + "incorrect value for ipv6_address[5], expected 147, is %d", + check_msg->ipv6_address[5]); + ck_assert_msg(check_msg->ipv6_address[6] == 68, + "incorrect value for ipv6_address[6], expected 68, is %d", + check_msg->ipv6_address[6]); + ck_assert_msg(check_msg->ipv6_address[7] == 222, + "incorrect value for ipv6_address[7], expected 222, is %d", + check_msg->ipv6_address[7]); + ck_assert_msg(check_msg->ipv6_address[8] == 92, + "incorrect value for ipv6_address[8], expected 92, is %d", + check_msg->ipv6_address[8]); + ck_assert_msg(check_msg->ipv6_address[9] == 192, + "incorrect value for ipv6_address[9], expected 192, is %d", + check_msg->ipv6_address[9]); + ck_assert_msg(check_msg->ipv6_address[10] == 78, + "incorrect value for ipv6_address[10], expected 78, is %d", + check_msg->ipv6_address[10]); + ck_assert_msg(check_msg->ipv6_address[11] == 235, + "incorrect value for ipv6_address[11], expected 235, is %d", + check_msg->ipv6_address[11]); + ck_assert_msg(check_msg->ipv6_address[12] == 63, + "incorrect value for ipv6_address[12], expected 63, is %d", + check_msg->ipv6_address[12]); + ck_assert_msg(check_msg->ipv6_address[13] == 208, + "incorrect value for ipv6_address[13], expected 208, is %d", + check_msg->ipv6_address[13]); + ck_assert_msg(check_msg->ipv6_address[14] == 114, + "incorrect value for ipv6_address[14], expected 114, is %d", + check_msg->ipv6_address[14]); + ck_assert_msg(check_msg->ipv6_address[15] == 53, + "incorrect value for ipv6_address[15], expected 53, is %d", + check_msg->ipv6_address[15]); + ck_assert_msg(check_msg->ipv6_mask_size == 183, + "incorrect value for ipv6_mask_size, expected 183, is %d", + check_msg->ipv6_mask_size); + ck_assert_msg(check_msg->rx_bytes == 451408920, + "incorrect value for rx_bytes, expected 451408920, is %d", + check_msg->rx_bytes); + ck_assert_msg(check_msg->tx_bytes == 59251049, + "incorrect value for tx_bytes, expected 59251049, is %d", + check_msg->tx_bytes); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgNetworkStateResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_piksi_MsgNetworkStateResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgNetworkStateResp"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgNetworkStateResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgReset.c b/c/test/legacy/auto_check_sbp_piksi_MsgReset.c new file mode 100644 index 0000000000..3e0d2bfb1a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgReset.c @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgReset) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb6, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_reset_t *test_msg = (msg_reset_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 334428248; + sbp_payload_send(&sbp_state, 0xb6, 53823, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 53823, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 53823, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb6, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_reset_t *check_msg = (msg_reset_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 334428248, + "incorrect value for flags, expected 334428248, is %d", + check_msg->flags); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgReset_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgReset"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgReset"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgReset); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgResetDep.c b/c/test/legacy/auto_check_sbp_piksi_MsgResetDep.c new file mode 100644 index 0000000000..e57956ccfe --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgResetDep.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgResetDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xb2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xb2, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 178, 0, 64, 11, 0, 234, 171, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xb2, 2880, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 2880, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 2880, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xb2, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgResetDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgResetDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgResetDep"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgResetDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgResetFilters.c b/c/test/legacy/auto_check_sbp_piksi_MsgResetFilters.c new file mode 100644 index 0000000000..e371cc56f2 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgResetFilters.c @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgResetFilters) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x22, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x22, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 34, 0, 81, 200, 1, 100, 130, 45, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_reset_filters_t *test_msg = (msg_reset_filters_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->filter = 100; + sbp_payload_send(&sbp_state, 0x22, 51281, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 51281, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 51281, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x22, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_reset_filters_t *check_msg = + (msg_reset_filters_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->filter == 100, + "incorrect value for filter, expected 100, is %d", + check_msg->filter); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgResetFilters_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgResetFilters"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_piksi_MsgResetFilters"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgResetFilters); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgSetTime.c b/c/test/legacy/auto_check_sbp_piksi_MsgSetTime.c new file mode 100644 index 0000000000..e7b2975013 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgSetTime.c @@ -0,0 +1,196 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgSetTime) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x68, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x68, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 104, 0, 21, 170, 0, 215, 65, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0x68, 43541, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 43541, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 43541, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x68, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgSetTime_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgSetTime"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgSetTime"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgSetTime); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgSpecan.c b/c/test/legacy/auto_check_sbp_piksi_MsgSpecan.c new file mode 100644 index 0000000000..5a09541f60 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgSpecan.c @@ -0,0 +1,2249 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgSpecan) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x51, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x51, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, + 215, 167, 211, 19, 154, 201, 241, 69, 205, 136, 0, 70, 51, 67, + 108, 69, 102, 38, 166, 68, 100, 179, 185, 17, 175, 49, 193, 228, + 228, 47, 33, 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, + 223, 167, 174, 9, 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, + 218, 241, 101, 107, 45, 137, 93, 114, 230, 43, 224, 23, 74, 209, + 199, 211, 130, 89, 220, 163, 68, 20, 253, 7, 206, 50, 129, 116, + 194, 23, 31, 226, 217, 157, 205, 221, 5, 224, 92, 82, 109, 223, + 195, 233, 165, 1, 82, 141, 157, 177, 169, 244, 131, 96, 109, 111, + 253, 149, 28, 225, 225, 72, 158, 158, 210, 196, 206, 70, 63, 225, + 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, 179, 148, 66, 254, + 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, 171, 102, 163, + 175, 50, 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, 237, 156, + 62, 117, 47, 143, 94, 135, 22, 155, 113, 110, 15, 243, 141, 227, + 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, 88, 38, 117, + 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, + 70, 182, 239, 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, + 123, 210, 168, 90, 124, 20, 7, 220, 144, 168, 69, 22, 72, 162, + 69, 111, 91, 251, 72, 220, 28, 119, 150, 95, 2, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_specan_t *test_msg = (msg_specan_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->amplitude_ref = 3780.199951171875; + test_msg->amplitude_unit = 1329.199951171875; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[0] = 100; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[1] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[2] = 185; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[3] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[4] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[5] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[6] = 193; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[7] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[8] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[9] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[10] = 33; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[11] = 24; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[12] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[13] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[14] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[15] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[16] = 246; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[17] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[18] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[19] = 40; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[20] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[21] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[22] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[23] = 167; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[24] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[25] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[26] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[27] = 11; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[28] = 247; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[29] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[30] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[31] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[32] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[33] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[34] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[35] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[36] = 218; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[37] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[38] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[39] = 107; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[40] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[41] = 137; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[42] = 93; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[43] = 114; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[44] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[45] = 43; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[46] = 224; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[47] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[48] = 74; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[49] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[50] = 199; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[51] = 211; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[52] = 130; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[53] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[54] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[55] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[56] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[57] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[58] = 253; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[59] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[60] = 206; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[61] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[62] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[63] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[64] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[65] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[66] = 31; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[67] = 226; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[68] = 217; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[69] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[70] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[71] = 221; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[72] = 5; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[73] = 224; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[74] = 92; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[75] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[76] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[77] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[78] = 195; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[79] = 233; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[80] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[81] = 1; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[82] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[83] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[84] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[85] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[86] = 169; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[87] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[88] = 131; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[89] = 96; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[90] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[91] = 111; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[92] = 253; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[93] = 149; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[94] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[95] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[96] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[97] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[98] = 158; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[99] = 158; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[100] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[101] = 196; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[102] = 206; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[103] = 70; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[104] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[105] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[106] = 184; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[107] = 150; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[108] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[109] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[110] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[111] = 146; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[112] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[113] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[114] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[115] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[116] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[117] = 148; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[118] = 66; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[119] = 254; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[120] = 115; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[121] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[122] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[123] = 46; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[124] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[125] = 204; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[126] = 37; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[127] = 200; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[128] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[129] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[130] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[131] = 171; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[132] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[133] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[134] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[135] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[136] = 66; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[137] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[138] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[139] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[140] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[141] = 172; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[142] = 160; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[143] = 233; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[144] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[145] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[146] = 237; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[147] = 156; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[148] = 62; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[149] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[150] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[151] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[152] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[153] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[154] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[155] = 155; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[156] = 113; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[157] = 110; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[158] = 15; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[159] = 243; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[160] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[161] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[162] = 46; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[163] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[164] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[165] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[166] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[167] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[168] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[169] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[170] = 131; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[171] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[172] = 160; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[173] = 88; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[174] = 38; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[175] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[176] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[177] = 57; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[178] = 40; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[179] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[180] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[181] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[182] = 38; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[183] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[184] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[185] = 15; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[186] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[187] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[188] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[189] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[190] = 70; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[191] = 182; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[192] = 239; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[193] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[194] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[195] = 6; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[196] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[197] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[198] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[199] = 115; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[200] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[201] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[202] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[203] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[204] = 123; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[205] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[206] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[207] = 90; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[208] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[209] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[210] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[211] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[212] = 144; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[213] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[214] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[215] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[216] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[217] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[218] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[219] = 111; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[220] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[221] = 251; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[222] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[223] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[224] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[225] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[226] = 150; + test_msg->channel_tag = 35146; + test_msg->freq_ref = 7737.2001953125; + test_msg->freq_step = 8226.2001953125; + test_msg->t.ns_residual = -1479025396; + test_msg->t.tow = 1227027783; + test_msg->t.wn = 5075; + sbp_payload_send(&sbp_state, 0x51, 54300, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54300, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 54300, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x51, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_specan_t *check_msg = (msg_specan_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->amplitude_ref * 100 - 3780.19995117 * 100) < 0.05, + "incorrect value for amplitude_ref, expected 3780.19995117, is %f", + check_msg->amplitude_ref); + ck_assert_msg( + (check_msg->amplitude_unit * 100 - 1329.19995117 * 100) < 0.05, + "incorrect value for amplitude_unit, expected 1329.19995117, is %f", + check_msg->amplitude_unit); + ck_assert_msg(check_msg->amplitude_value[0] == 100, + "incorrect value for amplitude_value[0], expected 100, is %d", + check_msg->amplitude_value[0]); + ck_assert_msg(check_msg->amplitude_value[1] == 179, + "incorrect value for amplitude_value[1], expected 179, is %d", + check_msg->amplitude_value[1]); + ck_assert_msg(check_msg->amplitude_value[2] == 185, + "incorrect value for amplitude_value[2], expected 185, is %d", + check_msg->amplitude_value[2]); + ck_assert_msg(check_msg->amplitude_value[3] == 17, + "incorrect value for amplitude_value[3], expected 17, is %d", + check_msg->amplitude_value[3]); + ck_assert_msg(check_msg->amplitude_value[4] == 175, + "incorrect value for amplitude_value[4], expected 175, is %d", + check_msg->amplitude_value[4]); + ck_assert_msg(check_msg->amplitude_value[5] == 49, + "incorrect value for amplitude_value[5], expected 49, is %d", + check_msg->amplitude_value[5]); + ck_assert_msg(check_msg->amplitude_value[6] == 193, + "incorrect value for amplitude_value[6], expected 193, is %d", + check_msg->amplitude_value[6]); + ck_assert_msg(check_msg->amplitude_value[7] == 228, + "incorrect value for amplitude_value[7], expected 228, is %d", + check_msg->amplitude_value[7]); + ck_assert_msg(check_msg->amplitude_value[8] == 228, + "incorrect value for amplitude_value[8], expected 228, is %d", + check_msg->amplitude_value[8]); + ck_assert_msg(check_msg->amplitude_value[9] == 47, + "incorrect value for amplitude_value[9], expected 47, is %d", + check_msg->amplitude_value[9]); + ck_assert_msg(check_msg->amplitude_value[10] == 33, + "incorrect value for amplitude_value[10], expected 33, is %d", + check_msg->amplitude_value[10]); + ck_assert_msg(check_msg->amplitude_value[11] == 24, + "incorrect value for amplitude_value[11], expected 24, is %d", + check_msg->amplitude_value[11]); + ck_assert_msg( + check_msg->amplitude_value[12] == 141, + "incorrect value for amplitude_value[12], expected 141, is %d", + check_msg->amplitude_value[12]); + ck_assert_msg( + check_msg->amplitude_value[13] == 177, + "incorrect value for amplitude_value[13], expected 177, is %d", + check_msg->amplitude_value[13]); + ck_assert_msg(check_msg->amplitude_value[14] == 18, + "incorrect value for amplitude_value[14], expected 18, is %d", + check_msg->amplitude_value[14]); + ck_assert_msg(check_msg->amplitude_value[15] == 99, + "incorrect value for amplitude_value[15], expected 99, is %d", + check_msg->amplitude_value[15]); + ck_assert_msg( + check_msg->amplitude_value[16] == 246, + "incorrect value for amplitude_value[16], expected 246, is %d", + check_msg->amplitude_value[16]); + ck_assert_msg( + check_msg->amplitude_value[17] == 121, + "incorrect value for amplitude_value[17], expected 121, is %d", + check_msg->amplitude_value[17]); + ck_assert_msg(check_msg->amplitude_value[18] == 61, + "incorrect value for amplitude_value[18], expected 61, is %d", + check_msg->amplitude_value[18]); + ck_assert_msg(check_msg->amplitude_value[19] == 40, + "incorrect value for amplitude_value[19], expected 40, is %d", + check_msg->amplitude_value[19]); + ck_assert_msg(check_msg->amplitude_value[20] == 91, + "incorrect value for amplitude_value[20], expected 91, is %d", + check_msg->amplitude_value[20]); + ck_assert_msg( + check_msg->amplitude_value[21] == 145, + "incorrect value for amplitude_value[21], expected 145, is %d", + check_msg->amplitude_value[21]); + ck_assert_msg( + check_msg->amplitude_value[22] == 223, + "incorrect value for amplitude_value[22], expected 223, is %d", + check_msg->amplitude_value[22]); + ck_assert_msg( + check_msg->amplitude_value[23] == 167, + "incorrect value for amplitude_value[23], expected 167, is %d", + check_msg->amplitude_value[23]); + ck_assert_msg( + check_msg->amplitude_value[24] == 174, + "incorrect value for amplitude_value[24], expected 174, is %d", + check_msg->amplitude_value[24]); + ck_assert_msg(check_msg->amplitude_value[25] == 9, + "incorrect value for amplitude_value[25], expected 9, is %d", + check_msg->amplitude_value[25]); + ck_assert_msg( + check_msg->amplitude_value[26] == 116, + "incorrect value for amplitude_value[26], expected 116, is %d", + check_msg->amplitude_value[26]); + ck_assert_msg(check_msg->amplitude_value[27] == 11, + "incorrect value for amplitude_value[27], expected 11, is %d", + check_msg->amplitude_value[27]); + ck_assert_msg( + check_msg->amplitude_value[28] == 247, + "incorrect value for amplitude_value[28], expected 247, is %d", + check_msg->amplitude_value[28]); + ck_assert_msg(check_msg->amplitude_value[29] == 84, + "incorrect value for amplitude_value[29], expected 84, is %d", + check_msg->amplitude_value[29]); + ck_assert_msg(check_msg->amplitude_value[30] == 49, + "incorrect value for amplitude_value[30], expected 49, is %d", + check_msg->amplitude_value[30]); + ck_assert_msg( + check_msg->amplitude_value[31] == 153, + "incorrect value for amplitude_value[31], expected 153, is %d", + check_msg->amplitude_value[31]); + ck_assert_msg( + check_msg->amplitude_value[32] == 205, + "incorrect value for amplitude_value[32], expected 205, is %d", + check_msg->amplitude_value[32]); + ck_assert_msg(check_msg->amplitude_value[33] == 2, + "incorrect value for amplitude_value[33], expected 2, is %d", + check_msg->amplitude_value[33]); + ck_assert_msg( + check_msg->amplitude_value[34] == 230, + "incorrect value for amplitude_value[34], expected 230, is %d", + check_msg->amplitude_value[34]); + ck_assert_msg( + check_msg->amplitude_value[35] == 194, + "incorrect value for amplitude_value[35], expected 194, is %d", + check_msg->amplitude_value[35]); + ck_assert_msg( + check_msg->amplitude_value[36] == 218, + "incorrect value for amplitude_value[36], expected 218, is %d", + check_msg->amplitude_value[36]); + ck_assert_msg( + check_msg->amplitude_value[37] == 241, + "incorrect value for amplitude_value[37], expected 241, is %d", + check_msg->amplitude_value[37]); + ck_assert_msg( + check_msg->amplitude_value[38] == 101, + "incorrect value for amplitude_value[38], expected 101, is %d", + check_msg->amplitude_value[38]); + ck_assert_msg( + check_msg->amplitude_value[39] == 107, + "incorrect value for amplitude_value[39], expected 107, is %d", + check_msg->amplitude_value[39]); + ck_assert_msg(check_msg->amplitude_value[40] == 45, + "incorrect value for amplitude_value[40], expected 45, is %d", + check_msg->amplitude_value[40]); + ck_assert_msg( + check_msg->amplitude_value[41] == 137, + "incorrect value for amplitude_value[41], expected 137, is %d", + check_msg->amplitude_value[41]); + ck_assert_msg(check_msg->amplitude_value[42] == 93, + "incorrect value for amplitude_value[42], expected 93, is %d", + check_msg->amplitude_value[42]); + ck_assert_msg( + check_msg->amplitude_value[43] == 114, + "incorrect value for amplitude_value[43], expected 114, is %d", + check_msg->amplitude_value[43]); + ck_assert_msg( + check_msg->amplitude_value[44] == 230, + "incorrect value for amplitude_value[44], expected 230, is %d", + check_msg->amplitude_value[44]); + ck_assert_msg(check_msg->amplitude_value[45] == 43, + "incorrect value for amplitude_value[45], expected 43, is %d", + check_msg->amplitude_value[45]); + ck_assert_msg( + check_msg->amplitude_value[46] == 224, + "incorrect value for amplitude_value[46], expected 224, is %d", + check_msg->amplitude_value[46]); + ck_assert_msg(check_msg->amplitude_value[47] == 23, + "incorrect value for amplitude_value[47], expected 23, is %d", + check_msg->amplitude_value[47]); + ck_assert_msg(check_msg->amplitude_value[48] == 74, + "incorrect value for amplitude_value[48], expected 74, is %d", + check_msg->amplitude_value[48]); + ck_assert_msg( + check_msg->amplitude_value[49] == 209, + "incorrect value for amplitude_value[49], expected 209, is %d", + check_msg->amplitude_value[49]); + ck_assert_msg( + check_msg->amplitude_value[50] == 199, + "incorrect value for amplitude_value[50], expected 199, is %d", + check_msg->amplitude_value[50]); + ck_assert_msg( + check_msg->amplitude_value[51] == 211, + "incorrect value for amplitude_value[51], expected 211, is %d", + check_msg->amplitude_value[51]); + ck_assert_msg( + check_msg->amplitude_value[52] == 130, + "incorrect value for amplitude_value[52], expected 130, is %d", + check_msg->amplitude_value[52]); + ck_assert_msg(check_msg->amplitude_value[53] == 89, + "incorrect value for amplitude_value[53], expected 89, is %d", + check_msg->amplitude_value[53]); + ck_assert_msg( + check_msg->amplitude_value[54] == 220, + "incorrect value for amplitude_value[54], expected 220, is %d", + check_msg->amplitude_value[54]); + ck_assert_msg( + check_msg->amplitude_value[55] == 163, + "incorrect value for amplitude_value[55], expected 163, is %d", + check_msg->amplitude_value[55]); + ck_assert_msg(check_msg->amplitude_value[56] == 68, + "incorrect value for amplitude_value[56], expected 68, is %d", + check_msg->amplitude_value[56]); + ck_assert_msg(check_msg->amplitude_value[57] == 20, + "incorrect value for amplitude_value[57], expected 20, is %d", + check_msg->amplitude_value[57]); + ck_assert_msg( + check_msg->amplitude_value[58] == 253, + "incorrect value for amplitude_value[58], expected 253, is %d", + check_msg->amplitude_value[58]); + ck_assert_msg(check_msg->amplitude_value[59] == 7, + "incorrect value for amplitude_value[59], expected 7, is %d", + check_msg->amplitude_value[59]); + ck_assert_msg( + check_msg->amplitude_value[60] == 206, + "incorrect value for amplitude_value[60], expected 206, is %d", + check_msg->amplitude_value[60]); + ck_assert_msg(check_msg->amplitude_value[61] == 50, + "incorrect value for amplitude_value[61], expected 50, is %d", + check_msg->amplitude_value[61]); + ck_assert_msg( + check_msg->amplitude_value[62] == 129, + "incorrect value for amplitude_value[62], expected 129, is %d", + check_msg->amplitude_value[62]); + ck_assert_msg( + check_msg->amplitude_value[63] == 116, + "incorrect value for amplitude_value[63], expected 116, is %d", + check_msg->amplitude_value[63]); + ck_assert_msg( + check_msg->amplitude_value[64] == 194, + "incorrect value for amplitude_value[64], expected 194, is %d", + check_msg->amplitude_value[64]); + ck_assert_msg(check_msg->amplitude_value[65] == 23, + "incorrect value for amplitude_value[65], expected 23, is %d", + check_msg->amplitude_value[65]); + ck_assert_msg(check_msg->amplitude_value[66] == 31, + "incorrect value for amplitude_value[66], expected 31, is %d", + check_msg->amplitude_value[66]); + ck_assert_msg( + check_msg->amplitude_value[67] == 226, + "incorrect value for amplitude_value[67], expected 226, is %d", + check_msg->amplitude_value[67]); + ck_assert_msg( + check_msg->amplitude_value[68] == 217, + "incorrect value for amplitude_value[68], expected 217, is %d", + check_msg->amplitude_value[68]); + ck_assert_msg( + check_msg->amplitude_value[69] == 157, + "incorrect value for amplitude_value[69], expected 157, is %d", + check_msg->amplitude_value[69]); + ck_assert_msg( + check_msg->amplitude_value[70] == 205, + "incorrect value for amplitude_value[70], expected 205, is %d", + check_msg->amplitude_value[70]); + ck_assert_msg( + check_msg->amplitude_value[71] == 221, + "incorrect value for amplitude_value[71], expected 221, is %d", + check_msg->amplitude_value[71]); + ck_assert_msg(check_msg->amplitude_value[72] == 5, + "incorrect value for amplitude_value[72], expected 5, is %d", + check_msg->amplitude_value[72]); + ck_assert_msg( + check_msg->amplitude_value[73] == 224, + "incorrect value for amplitude_value[73], expected 224, is %d", + check_msg->amplitude_value[73]); + ck_assert_msg(check_msg->amplitude_value[74] == 92, + "incorrect value for amplitude_value[74], expected 92, is %d", + check_msg->amplitude_value[74]); + ck_assert_msg(check_msg->amplitude_value[75] == 82, + "incorrect value for amplitude_value[75], expected 82, is %d", + check_msg->amplitude_value[75]); + ck_assert_msg( + check_msg->amplitude_value[76] == 109, + "incorrect value for amplitude_value[76], expected 109, is %d", + check_msg->amplitude_value[76]); + ck_assert_msg( + check_msg->amplitude_value[77] == 223, + "incorrect value for amplitude_value[77], expected 223, is %d", + check_msg->amplitude_value[77]); + ck_assert_msg( + check_msg->amplitude_value[78] == 195, + "incorrect value for amplitude_value[78], expected 195, is %d", + check_msg->amplitude_value[78]); + ck_assert_msg( + check_msg->amplitude_value[79] == 233, + "incorrect value for amplitude_value[79], expected 233, is %d", + check_msg->amplitude_value[79]); + ck_assert_msg( + check_msg->amplitude_value[80] == 165, + "incorrect value for amplitude_value[80], expected 165, is %d", + check_msg->amplitude_value[80]); + ck_assert_msg(check_msg->amplitude_value[81] == 1, + "incorrect value for amplitude_value[81], expected 1, is %d", + check_msg->amplitude_value[81]); + ck_assert_msg(check_msg->amplitude_value[82] == 82, + "incorrect value for amplitude_value[82], expected 82, is %d", + check_msg->amplitude_value[82]); + ck_assert_msg( + check_msg->amplitude_value[83] == 141, + "incorrect value for amplitude_value[83], expected 141, is %d", + check_msg->amplitude_value[83]); + ck_assert_msg( + check_msg->amplitude_value[84] == 157, + "incorrect value for amplitude_value[84], expected 157, is %d", + check_msg->amplitude_value[84]); + ck_assert_msg( + check_msg->amplitude_value[85] == 177, + "incorrect value for amplitude_value[85], expected 177, is %d", + check_msg->amplitude_value[85]); + ck_assert_msg( + check_msg->amplitude_value[86] == 169, + "incorrect value for amplitude_value[86], expected 169, is %d", + check_msg->amplitude_value[86]); + ck_assert_msg( + check_msg->amplitude_value[87] == 244, + "incorrect value for amplitude_value[87], expected 244, is %d", + check_msg->amplitude_value[87]); + ck_assert_msg( + check_msg->amplitude_value[88] == 131, + "incorrect value for amplitude_value[88], expected 131, is %d", + check_msg->amplitude_value[88]); + ck_assert_msg(check_msg->amplitude_value[89] == 96, + "incorrect value for amplitude_value[89], expected 96, is %d", + check_msg->amplitude_value[89]); + ck_assert_msg( + check_msg->amplitude_value[90] == 109, + "incorrect value for amplitude_value[90], expected 109, is %d", + check_msg->amplitude_value[90]); + ck_assert_msg( + check_msg->amplitude_value[91] == 111, + "incorrect value for amplitude_value[91], expected 111, is %d", + check_msg->amplitude_value[91]); + ck_assert_msg( + check_msg->amplitude_value[92] == 253, + "incorrect value for amplitude_value[92], expected 253, is %d", + check_msg->amplitude_value[92]); + ck_assert_msg( + check_msg->amplitude_value[93] == 149, + "incorrect value for amplitude_value[93], expected 149, is %d", + check_msg->amplitude_value[93]); + ck_assert_msg(check_msg->amplitude_value[94] == 28, + "incorrect value for amplitude_value[94], expected 28, is %d", + check_msg->amplitude_value[94]); + ck_assert_msg( + check_msg->amplitude_value[95] == 225, + "incorrect value for amplitude_value[95], expected 225, is %d", + check_msg->amplitude_value[95]); + ck_assert_msg( + check_msg->amplitude_value[96] == 225, + "incorrect value for amplitude_value[96], expected 225, is %d", + check_msg->amplitude_value[96]); + ck_assert_msg(check_msg->amplitude_value[97] == 72, + "incorrect value for amplitude_value[97], expected 72, is %d", + check_msg->amplitude_value[97]); + ck_assert_msg( + check_msg->amplitude_value[98] == 158, + "incorrect value for amplitude_value[98], expected 158, is %d", + check_msg->amplitude_value[98]); + ck_assert_msg( + check_msg->amplitude_value[99] == 158, + "incorrect value for amplitude_value[99], expected 158, is %d", + check_msg->amplitude_value[99]); + ck_assert_msg( + check_msg->amplitude_value[100] == 210, + "incorrect value for amplitude_value[100], expected 210, is %d", + check_msg->amplitude_value[100]); + ck_assert_msg( + check_msg->amplitude_value[101] == 196, + "incorrect value for amplitude_value[101], expected 196, is %d", + check_msg->amplitude_value[101]); + ck_assert_msg( + check_msg->amplitude_value[102] == 206, + "incorrect value for amplitude_value[102], expected 206, is %d", + check_msg->amplitude_value[102]); + ck_assert_msg( + check_msg->amplitude_value[103] == 70, + "incorrect value for amplitude_value[103], expected 70, is %d", + check_msg->amplitude_value[103]); + ck_assert_msg( + check_msg->amplitude_value[104] == 63, + "incorrect value for amplitude_value[104], expected 63, is %d", + check_msg->amplitude_value[104]); + ck_assert_msg( + check_msg->amplitude_value[105] == 225, + "incorrect value for amplitude_value[105], expected 225, is %d", + check_msg->amplitude_value[105]); + ck_assert_msg( + check_msg->amplitude_value[106] == 184, + "incorrect value for amplitude_value[106], expected 184, is %d", + check_msg->amplitude_value[106]); + ck_assert_msg( + check_msg->amplitude_value[107] == 150, + "incorrect value for amplitude_value[107], expected 150, is %d", + check_msg->amplitude_value[107]); + ck_assert_msg( + check_msg->amplitude_value[108] == 174, + "incorrect value for amplitude_value[108], expected 174, is %d", + check_msg->amplitude_value[108]); + ck_assert_msg( + check_msg->amplitude_value[109] == 240, + "incorrect value for amplitude_value[109], expected 240, is %d", + check_msg->amplitude_value[109]); + ck_assert_msg( + check_msg->amplitude_value[110] == 45, + "incorrect value for amplitude_value[110], expected 45, is %d", + check_msg->amplitude_value[110]); + ck_assert_msg( + check_msg->amplitude_value[111] == 146, + "incorrect value for amplitude_value[111], expected 146, is %d", + check_msg->amplitude_value[111]); + ck_assert_msg( + check_msg->amplitude_value[112] == 59, + "incorrect value for amplitude_value[112], expected 59, is %d", + check_msg->amplitude_value[112]); + ck_assert_msg( + check_msg->amplitude_value[113] == 82, + "incorrect value for amplitude_value[113], expected 82, is %d", + check_msg->amplitude_value[113]); + ck_assert_msg( + check_msg->amplitude_value[114] == 194, + "incorrect value for amplitude_value[114], expected 194, is %d", + check_msg->amplitude_value[114]); + ck_assert_msg(check_msg->amplitude_value[115] == 4, + "incorrect value for amplitude_value[115], expected 4, is %d", + check_msg->amplitude_value[115]); + ck_assert_msg( + check_msg->amplitude_value[116] == 179, + "incorrect value for amplitude_value[116], expected 179, is %d", + check_msg->amplitude_value[116]); + ck_assert_msg( + check_msg->amplitude_value[117] == 148, + "incorrect value for amplitude_value[117], expected 148, is %d", + check_msg->amplitude_value[117]); + ck_assert_msg( + check_msg->amplitude_value[118] == 66, + "incorrect value for amplitude_value[118], expected 66, is %d", + check_msg->amplitude_value[118]); + ck_assert_msg( + check_msg->amplitude_value[119] == 254, + "incorrect value for amplitude_value[119], expected 254, is %d", + check_msg->amplitude_value[119]); + ck_assert_msg( + check_msg->amplitude_value[120] == 115, + "incorrect value for amplitude_value[120], expected 115, is %d", + check_msg->amplitude_value[120]); + ck_assert_msg( + check_msg->amplitude_value[121] == 77, + "incorrect value for amplitude_value[121], expected 77, is %d", + check_msg->amplitude_value[121]); + ck_assert_msg( + check_msg->amplitude_value[122] == 30, + "incorrect value for amplitude_value[122], expected 30, is %d", + check_msg->amplitude_value[122]); + ck_assert_msg( + check_msg->amplitude_value[123] == 46, + "incorrect value for amplitude_value[123], expected 46, is %d", + check_msg->amplitude_value[123]); + ck_assert_msg(check_msg->amplitude_value[124] == 4, + "incorrect value for amplitude_value[124], expected 4, is %d", + check_msg->amplitude_value[124]); + ck_assert_msg( + check_msg->amplitude_value[125] == 204, + "incorrect value for amplitude_value[125], expected 204, is %d", + check_msg->amplitude_value[125]); + ck_assert_msg( + check_msg->amplitude_value[126] == 37, + "incorrect value for amplitude_value[126], expected 37, is %d", + check_msg->amplitude_value[126]); + ck_assert_msg( + check_msg->amplitude_value[127] == 200, + "incorrect value for amplitude_value[127], expected 200, is %d", + check_msg->amplitude_value[127]); + ck_assert_msg( + check_msg->amplitude_value[128] == 121, + "incorrect value for amplitude_value[128], expected 121, is %d", + check_msg->amplitude_value[128]); + ck_assert_msg( + check_msg->amplitude_value[129] == 18, + "incorrect value for amplitude_value[129], expected 18, is %d", + check_msg->amplitude_value[129]); + ck_assert_msg( + check_msg->amplitude_value[130] == 17, + "incorrect value for amplitude_value[130], expected 17, is %d", + check_msg->amplitude_value[130]); + ck_assert_msg( + check_msg->amplitude_value[131] == 171, + "incorrect value for amplitude_value[131], expected 171, is %d", + check_msg->amplitude_value[131]); + ck_assert_msg( + check_msg->amplitude_value[132] == 102, + "incorrect value for amplitude_value[132], expected 102, is %d", + check_msg->amplitude_value[132]); + ck_assert_msg( + check_msg->amplitude_value[133] == 163, + "incorrect value for amplitude_value[133], expected 163, is %d", + check_msg->amplitude_value[133]); + ck_assert_msg( + check_msg->amplitude_value[134] == 175, + "incorrect value for amplitude_value[134], expected 175, is %d", + check_msg->amplitude_value[134]); + ck_assert_msg( + check_msg->amplitude_value[135] == 50, + "incorrect value for amplitude_value[135], expected 50, is %d", + check_msg->amplitude_value[135]); + ck_assert_msg( + check_msg->amplitude_value[136] == 66, + "incorrect value for amplitude_value[136], expected 66, is %d", + check_msg->amplitude_value[136]); + ck_assert_msg( + check_msg->amplitude_value[137] == 101, + "incorrect value for amplitude_value[137], expected 101, is %d", + check_msg->amplitude_value[137]); + ck_assert_msg( + check_msg->amplitude_value[138] == 69, + "incorrect value for amplitude_value[138], expected 69, is %d", + check_msg->amplitude_value[138]); + ck_assert_msg( + check_msg->amplitude_value[139] == 13, + "incorrect value for amplitude_value[139], expected 13, is %d", + check_msg->amplitude_value[139]); + ck_assert_msg( + check_msg->amplitude_value[140] == 223, + "incorrect value for amplitude_value[140], expected 223, is %d", + check_msg->amplitude_value[140]); + ck_assert_msg( + check_msg->amplitude_value[141] == 172, + "incorrect value for amplitude_value[141], expected 172, is %d", + check_msg->amplitude_value[141]); + ck_assert_msg( + check_msg->amplitude_value[142] == 160, + "incorrect value for amplitude_value[142], expected 160, is %d", + check_msg->amplitude_value[142]); + ck_assert_msg( + check_msg->amplitude_value[143] == 233, + "incorrect value for amplitude_value[143], expected 233, is %d", + check_msg->amplitude_value[143]); + ck_assert_msg( + check_msg->amplitude_value[144] == 220, + "incorrect value for amplitude_value[144], expected 220, is %d", + check_msg->amplitude_value[144]); + ck_assert_msg( + check_msg->amplitude_value[145] == 101, + "incorrect value for amplitude_value[145], expected 101, is %d", + check_msg->amplitude_value[145]); + ck_assert_msg( + check_msg->amplitude_value[146] == 237, + "incorrect value for amplitude_value[146], expected 237, is %d", + check_msg->amplitude_value[146]); + ck_assert_msg( + check_msg->amplitude_value[147] == 156, + "incorrect value for amplitude_value[147], expected 156, is %d", + check_msg->amplitude_value[147]); + ck_assert_msg( + check_msg->amplitude_value[148] == 62, + "incorrect value for amplitude_value[148], expected 62, is %d", + check_msg->amplitude_value[148]); + ck_assert_msg( + check_msg->amplitude_value[149] == 117, + "incorrect value for amplitude_value[149], expected 117, is %d", + check_msg->amplitude_value[149]); + ck_assert_msg( + check_msg->amplitude_value[150] == 47, + "incorrect value for amplitude_value[150], expected 47, is %d", + check_msg->amplitude_value[150]); + ck_assert_msg( + check_msg->amplitude_value[151] == 143, + "incorrect value for amplitude_value[151], expected 143, is %d", + check_msg->amplitude_value[151]); + ck_assert_msg( + check_msg->amplitude_value[152] == 94, + "incorrect value for amplitude_value[152], expected 94, is %d", + check_msg->amplitude_value[152]); + ck_assert_msg( + check_msg->amplitude_value[153] == 135, + "incorrect value for amplitude_value[153], expected 135, is %d", + check_msg->amplitude_value[153]); + ck_assert_msg( + check_msg->amplitude_value[154] == 22, + "incorrect value for amplitude_value[154], expected 22, is %d", + check_msg->amplitude_value[154]); + ck_assert_msg( + check_msg->amplitude_value[155] == 155, + "incorrect value for amplitude_value[155], expected 155, is %d", + check_msg->amplitude_value[155]); + ck_assert_msg( + check_msg->amplitude_value[156] == 113, + "incorrect value for amplitude_value[156], expected 113, is %d", + check_msg->amplitude_value[156]); + ck_assert_msg( + check_msg->amplitude_value[157] == 110, + "incorrect value for amplitude_value[157], expected 110, is %d", + check_msg->amplitude_value[157]); + ck_assert_msg( + check_msg->amplitude_value[158] == 15, + "incorrect value for amplitude_value[158], expected 15, is %d", + check_msg->amplitude_value[158]); + ck_assert_msg( + check_msg->amplitude_value[159] == 243, + "incorrect value for amplitude_value[159], expected 243, is %d", + check_msg->amplitude_value[159]); + ck_assert_msg( + check_msg->amplitude_value[160] == 141, + "incorrect value for amplitude_value[160], expected 141, is %d", + check_msg->amplitude_value[160]); + ck_assert_msg( + check_msg->amplitude_value[161] == 227, + "incorrect value for amplitude_value[161], expected 227, is %d", + check_msg->amplitude_value[161]); + ck_assert_msg( + check_msg->amplitude_value[162] == 46, + "incorrect value for amplitude_value[162], expected 46, is %d", + check_msg->amplitude_value[162]); + ck_assert_msg( + check_msg->amplitude_value[163] == 143, + "incorrect value for amplitude_value[163], expected 143, is %d", + check_msg->amplitude_value[163]); + ck_assert_msg( + check_msg->amplitude_value[164] == 227, + "incorrect value for amplitude_value[164], expected 227, is %d", + check_msg->amplitude_value[164]); + ck_assert_msg( + check_msg->amplitude_value[165] == 209, + "incorrect value for amplitude_value[165], expected 209, is %d", + check_msg->amplitude_value[165]); + ck_assert_msg( + check_msg->amplitude_value[166] == 249, + "incorrect value for amplitude_value[166], expected 249, is %d", + check_msg->amplitude_value[166]); + ck_assert_msg(check_msg->amplitude_value[167] == 2, + "incorrect value for amplitude_value[167], expected 2, is %d", + check_msg->amplitude_value[167]); + ck_assert_msg( + check_msg->amplitude_value[168] == 153, + "incorrect value for amplitude_value[168], expected 153, is %d", + check_msg->amplitude_value[168]); + ck_assert_msg( + check_msg->amplitude_value[169] == 168, + "incorrect value for amplitude_value[169], expected 168, is %d", + check_msg->amplitude_value[169]); + ck_assert_msg( + check_msg->amplitude_value[170] == 131, + "incorrect value for amplitude_value[170], expected 131, is %d", + check_msg->amplitude_value[170]); + ck_assert_msg( + check_msg->amplitude_value[171] == 249, + "incorrect value for amplitude_value[171], expected 249, is %d", + check_msg->amplitude_value[171]); + ck_assert_msg( + check_msg->amplitude_value[172] == 160, + "incorrect value for amplitude_value[172], expected 160, is %d", + check_msg->amplitude_value[172]); + ck_assert_msg( + check_msg->amplitude_value[173] == 88, + "incorrect value for amplitude_value[173], expected 88, is %d", + check_msg->amplitude_value[173]); + ck_assert_msg( + check_msg->amplitude_value[174] == 38, + "incorrect value for amplitude_value[174], expected 38, is %d", + check_msg->amplitude_value[174]); + ck_assert_msg( + check_msg->amplitude_value[175] == 117, + "incorrect value for amplitude_value[175], expected 117, is %d", + check_msg->amplitude_value[175]); + ck_assert_msg( + check_msg->amplitude_value[176] == 129, + "incorrect value for amplitude_value[176], expected 129, is %d", + check_msg->amplitude_value[176]); + ck_assert_msg( + check_msg->amplitude_value[177] == 57, + "incorrect value for amplitude_value[177], expected 57, is %d", + check_msg->amplitude_value[177]); + ck_assert_msg( + check_msg->amplitude_value[178] == 40, + "incorrect value for amplitude_value[178], expected 40, is %d", + check_msg->amplitude_value[178]); + ck_assert_msg( + check_msg->amplitude_value[179] == 109, + "incorrect value for amplitude_value[179], expected 109, is %d", + check_msg->amplitude_value[179]); + ck_assert_msg( + check_msg->amplitude_value[180] == 209, + "incorrect value for amplitude_value[180], expected 209, is %d", + check_msg->amplitude_value[180]); + ck_assert_msg( + check_msg->amplitude_value[181] == 177, + "incorrect value for amplitude_value[181], expected 177, is %d", + check_msg->amplitude_value[181]); + ck_assert_msg( + check_msg->amplitude_value[182] == 38, + "incorrect value for amplitude_value[182], expected 38, is %d", + check_msg->amplitude_value[182]); + ck_assert_msg( + check_msg->amplitude_value[183] == 47, + "incorrect value for amplitude_value[183], expected 47, is %d", + check_msg->amplitude_value[183]); + ck_assert_msg( + check_msg->amplitude_value[184] == 12, + "incorrect value for amplitude_value[184], expected 12, is %d", + check_msg->amplitude_value[184]); + ck_assert_msg( + check_msg->amplitude_value[185] == 15, + "incorrect value for amplitude_value[185], expected 15, is %d", + check_msg->amplitude_value[185]); + ck_assert_msg( + check_msg->amplitude_value[186] == 16, + "incorrect value for amplitude_value[186], expected 16, is %d", + check_msg->amplitude_value[186]); + ck_assert_msg(check_msg->amplitude_value[187] == 9, + "incorrect value for amplitude_value[187], expected 9, is %d", + check_msg->amplitude_value[187]); + ck_assert_msg( + check_msg->amplitude_value[188] == 175, + "incorrect value for amplitude_value[188], expected 175, is %d", + check_msg->amplitude_value[188]); + ck_assert_msg( + check_msg->amplitude_value[189] == 69, + "incorrect value for amplitude_value[189], expected 69, is %d", + check_msg->amplitude_value[189]); + ck_assert_msg( + check_msg->amplitude_value[190] == 70, + "incorrect value for amplitude_value[190], expected 70, is %d", + check_msg->amplitude_value[190]); + ck_assert_msg( + check_msg->amplitude_value[191] == 182, + "incorrect value for amplitude_value[191], expected 182, is %d", + check_msg->amplitude_value[191]); + ck_assert_msg( + check_msg->amplitude_value[192] == 239, + "incorrect value for amplitude_value[192], expected 239, is %d", + check_msg->amplitude_value[192]); + ck_assert_msg( + check_msg->amplitude_value[193] == 117, + "incorrect value for amplitude_value[193], expected 117, is %d", + check_msg->amplitude_value[193]); + ck_assert_msg( + check_msg->amplitude_value[194] == 135, + "incorrect value for amplitude_value[194], expected 135, is %d", + check_msg->amplitude_value[194]); + ck_assert_msg(check_msg->amplitude_value[195] == 6, + "incorrect value for amplitude_value[195], expected 6, is %d", + check_msg->amplitude_value[195]); + ck_assert_msg( + check_msg->amplitude_value[196] == 71, + "incorrect value for amplitude_value[196], expected 71, is %d", + check_msg->amplitude_value[196]); + ck_assert_msg( + check_msg->amplitude_value[197] == 99, + "incorrect value for amplitude_value[197], expected 99, is %d", + check_msg->amplitude_value[197]); + ck_assert_msg( + check_msg->amplitude_value[198] == 230, + "incorrect value for amplitude_value[198], expected 230, is %d", + check_msg->amplitude_value[198]); + ck_assert_msg( + check_msg->amplitude_value[199] == 115, + "incorrect value for amplitude_value[199], expected 115, is %d", + check_msg->amplitude_value[199]); + ck_assert_msg(check_msg->amplitude_value[200] == 2, + "incorrect value for amplitude_value[200], expected 2, is %d", + check_msg->amplitude_value[200]); + ck_assert_msg( + check_msg->amplitude_value[201] == 71, + "incorrect value for amplitude_value[201], expected 71, is %d", + check_msg->amplitude_value[201]); + ck_assert_msg( + check_msg->amplitude_value[202] == 165, + "incorrect value for amplitude_value[202], expected 165, is %d", + check_msg->amplitude_value[202]); + ck_assert_msg( + check_msg->amplitude_value[203] == 228, + "incorrect value for amplitude_value[203], expected 228, is %d", + check_msg->amplitude_value[203]); + ck_assert_msg( + check_msg->amplitude_value[204] == 123, + "incorrect value for amplitude_value[204], expected 123, is %d", + check_msg->amplitude_value[204]); + ck_assert_msg( + check_msg->amplitude_value[205] == 210, + "incorrect value for amplitude_value[205], expected 210, is %d", + check_msg->amplitude_value[205]); + ck_assert_msg( + check_msg->amplitude_value[206] == 168, + "incorrect value for amplitude_value[206], expected 168, is %d", + check_msg->amplitude_value[206]); + ck_assert_msg( + check_msg->amplitude_value[207] == 90, + "incorrect value for amplitude_value[207], expected 90, is %d", + check_msg->amplitude_value[207]); + ck_assert_msg( + check_msg->amplitude_value[208] == 124, + "incorrect value for amplitude_value[208], expected 124, is %d", + check_msg->amplitude_value[208]); + ck_assert_msg( + check_msg->amplitude_value[209] == 20, + "incorrect value for amplitude_value[209], expected 20, is %d", + check_msg->amplitude_value[209]); + ck_assert_msg(check_msg->amplitude_value[210] == 7, + "incorrect value for amplitude_value[210], expected 7, is %d", + check_msg->amplitude_value[210]); + ck_assert_msg( + check_msg->amplitude_value[211] == 220, + "incorrect value for amplitude_value[211], expected 220, is %d", + check_msg->amplitude_value[211]); + ck_assert_msg( + check_msg->amplitude_value[212] == 144, + "incorrect value for amplitude_value[212], expected 144, is %d", + check_msg->amplitude_value[212]); + ck_assert_msg( + check_msg->amplitude_value[213] == 168, + "incorrect value for amplitude_value[213], expected 168, is %d", + check_msg->amplitude_value[213]); + ck_assert_msg( + check_msg->amplitude_value[214] == 69, + "incorrect value for amplitude_value[214], expected 69, is %d", + check_msg->amplitude_value[214]); + ck_assert_msg( + check_msg->amplitude_value[215] == 22, + "incorrect value for amplitude_value[215], expected 22, is %d", + check_msg->amplitude_value[215]); + ck_assert_msg( + check_msg->amplitude_value[216] == 72, + "incorrect value for amplitude_value[216], expected 72, is %d", + check_msg->amplitude_value[216]); + ck_assert_msg( + check_msg->amplitude_value[217] == 162, + "incorrect value for amplitude_value[217], expected 162, is %d", + check_msg->amplitude_value[217]); + ck_assert_msg( + check_msg->amplitude_value[218] == 69, + "incorrect value for amplitude_value[218], expected 69, is %d", + check_msg->amplitude_value[218]); + ck_assert_msg( + check_msg->amplitude_value[219] == 111, + "incorrect value for amplitude_value[219], expected 111, is %d", + check_msg->amplitude_value[219]); + ck_assert_msg( + check_msg->amplitude_value[220] == 91, + "incorrect value for amplitude_value[220], expected 91, is %d", + check_msg->amplitude_value[220]); + ck_assert_msg( + check_msg->amplitude_value[221] == 251, + "incorrect value for amplitude_value[221], expected 251, is %d", + check_msg->amplitude_value[221]); + ck_assert_msg( + check_msg->amplitude_value[222] == 72, + "incorrect value for amplitude_value[222], expected 72, is %d", + check_msg->amplitude_value[222]); + ck_assert_msg( + check_msg->amplitude_value[223] == 220, + "incorrect value for amplitude_value[223], expected 220, is %d", + check_msg->amplitude_value[223]); + ck_assert_msg( + check_msg->amplitude_value[224] == 28, + "incorrect value for amplitude_value[224], expected 28, is %d", + check_msg->amplitude_value[224]); + ck_assert_msg( + check_msg->amplitude_value[225] == 119, + "incorrect value for amplitude_value[225], expected 119, is %d", + check_msg->amplitude_value[225]); + ck_assert_msg( + check_msg->amplitude_value[226] == 150, + "incorrect value for amplitude_value[226], expected 150, is %d", + check_msg->amplitude_value[226]); + ck_assert_msg(check_msg->channel_tag == 35146, + "incorrect value for channel_tag, expected 35146, is %d", + check_msg->channel_tag); + ck_assert_msg((check_msg->freq_ref * 100 - 7737.20019531 * 100) < 0.05, + "incorrect value for freq_ref, expected 7737.20019531, is %f", + check_msg->freq_ref); + ck_assert_msg( + (check_msg->freq_step * 100 - 8226.20019531 * 100) < 0.05, + "incorrect value for freq_step, expected 8226.20019531, is %f", + check_msg->freq_step); + ck_assert_msg( + check_msg->t.ns_residual == -1479025396, + "incorrect value for t.ns_residual, expected -1479025396, is %d", + check_msg->t.ns_residual); + ck_assert_msg(check_msg->t.tow == 1227027783, + "incorrect value for t.tow, expected 1227027783, is %d", + check_msg->t.tow); + ck_assert_msg(check_msg->t.wn == 5075, + "incorrect value for t.wn, expected 5075, is %d", + check_msg->t.wn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgSpecan_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgSpecan"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgSpecan"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgSpecan); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgSpecanDep.c b/c/test/legacy/auto_check_sbp_piksi_MsgSpecanDep.c new file mode 100644 index 0000000000..73e3a770ba --- /dev/null +++ b/c/test/legacy/auto_check_sbp_piksi_MsgSpecanDep.c @@ -0,0 +1,2271 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_piksi_MsgSpecanDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x50, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x50, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, + 154, 97, 198, 69, 154, 1, 144, 69, 205, 20, 18, 70, 51, 211, + 89, 69, 240, 14, 179, 186, 227, 244, 173, 240, 182, 71, 166, 117, + 196, 13, 44, 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, + 77, 186, 68, 135, 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, + 216, 44, 67, 212, 156, 75, 81, 53, 250, 225, 23, 205, 26, 34, + 119, 50, 101, 64, 7, 231, 124, 183, 203, 102, 234, 84, 83, 208, + 23, 68, 54, 179, 98, 96, 116, 244, 246, 94, 104, 94, 13, 56, + 210, 18, 191, 22, 133, 81, 153, 159, 161, 219, 59, 21, 164, 121, + 145, 203, 171, 132, 57, 180, 102, 101, 11, 229, 175, 145, 73, 72, + 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, 193, 7, 109, 44, + 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, 231, 161, 81, + 216, 114, 60, 231, 163, 163, 49, 237, 244, 185, 240, 89, 143, 174, + 165, 211, 241, 13, 16, 61, 141, 101, 89, 37, 117, 189, 86, 118, + 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, 100, + 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, + 181, 12, 140, 16, 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, + 59, 64, 241, 183, 238, 105, 181, 170, 45, 8, 166, 164, 238, 83, + 148, 173, 108, 228, 67, 89, 189, 67, 26, 39, 216, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_specan_dep_t *test_msg = (msg_specan_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->amplitude_ref = 9349.2001953125; + test_msg->amplitude_unit = 3485.199951171875; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[0] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[1] = 14; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[2] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[3] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[4] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[5] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[6] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[7] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[8] = 182; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[9] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[10] = 166; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[11] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[12] = 196; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[13] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[14] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[15] = 27; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[16] = 33; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[17] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[18] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[19] = 254; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[20] = 3; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[21] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[22] = 92; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[23] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[24] = 122; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[25] = 169; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[26] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[27] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[28] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[29] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[30] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[31] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[32] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[33] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[34] = 36; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[35] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[36] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[37] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[38] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[39] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[40] = 216; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[41] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[42] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[43] = 212; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[44] = 156; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[45] = 75; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[46] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[47] = 53; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[48] = 250; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[49] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[50] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[51] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[52] = 26; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[53] = 34; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[54] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[55] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[56] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[57] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[58] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[59] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[60] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[61] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[62] = 203; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[63] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[64] = 234; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[65] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[66] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[67] = 208; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[68] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[69] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[70] = 54; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[71] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[72] = 98; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[73] = 96; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[74] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[75] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[76] = 246; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[77] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[78] = 104; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[79] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[80] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[81] = 56; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[82] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[83] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[84] = 191; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[85] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[86] = 133; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[87] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[88] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[89] = 159; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[90] = 161; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[91] = 219; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[92] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[93] = 21; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[94] = 164; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[95] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[96] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[97] = 203; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[98] = 171; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[99] = 132; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[100] = 57; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[101] = 180; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[102] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[103] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[104] = 11; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[105] = 229; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[106] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[107] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[108] = 73; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[109] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[110] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[111] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[112] = 184; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[113] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[114] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[115] = 234; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[116] = 218; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[117] = 62; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[118] = 226; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[119] = 217; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[120] = 193; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[121] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[122] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[123] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[124] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[125] = 201; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[126] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[127] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[128] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[129] = 140; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[130] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[131] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[132] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[133] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[134] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[135] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[136] = 161; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[137] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[138] = 216; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[139] = 114; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[140] = 60; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[141] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[142] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[143] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[144] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[145] = 237; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[146] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[147] = 185; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[148] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[149] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[150] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[151] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[152] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[153] = 211; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[154] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[155] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[156] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[157] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[158] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[159] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[160] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[161] = 37; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[162] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[163] = 189; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[164] = 86; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[165] = 118; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[166] = 176; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[167] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[168] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[169] = 14; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[170] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[171] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[172] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[173] = 243; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[174] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[175] = 29; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[176] = 207; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[177] = 198; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[178] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[179] = 100; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[180] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[181] = 6; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[182] = 139; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[183] = 110; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[184] = 39; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[185] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[186] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[187] = 199; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[188] = 43; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[189] = 132; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[190] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[191] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[192] = 51; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[193] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[194] = 181; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[195] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[196] = 140; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[197] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[198] = 247; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[199] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[200] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[201] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[202] = 39; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[203] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[204] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[205] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[206] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[207] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[208] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[209] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[210] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[211] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[212] = 238; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[213] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[214] = 181; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[215] = 170; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[216] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[217] = 8; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[218] = 166; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[219] = 164; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[220] = 238; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[221] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[222] = 148; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[223] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[224] = 108; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[225] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[226] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[227] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[228] = 189; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[229] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->amplitude_value[0]); + } + test_msg->amplitude_value[230] = 26; + test_msg->channel_tag = 5878; + test_msg->freq_ref = 6348.2001953125; + test_msg->freq_step = 4608.2001953125; + test_msg->t.tow = 992295133; + test_msg->t.wn = 6957; + sbp_payload_send(&sbp_state, 0x50, 55664, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 55664, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 55664, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x50, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_specan_dep_t *check_msg = (msg_specan_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->amplitude_ref * 100 - 9349.20019531 * 100) < 0.05, + "incorrect value for amplitude_ref, expected 9349.20019531, is %f", + check_msg->amplitude_ref); + ck_assert_msg( + (check_msg->amplitude_unit * 100 - 3485.19995117 * 100) < 0.05, + "incorrect value for amplitude_unit, expected 3485.19995117, is %f", + check_msg->amplitude_unit); + ck_assert_msg(check_msg->amplitude_value[0] == 240, + "incorrect value for amplitude_value[0], expected 240, is %d", + check_msg->amplitude_value[0]); + ck_assert_msg(check_msg->amplitude_value[1] == 14, + "incorrect value for amplitude_value[1], expected 14, is %d", + check_msg->amplitude_value[1]); + ck_assert_msg(check_msg->amplitude_value[2] == 179, + "incorrect value for amplitude_value[2], expected 179, is %d", + check_msg->amplitude_value[2]); + ck_assert_msg(check_msg->amplitude_value[3] == 186, + "incorrect value for amplitude_value[3], expected 186, is %d", + check_msg->amplitude_value[3]); + ck_assert_msg(check_msg->amplitude_value[4] == 227, + "incorrect value for amplitude_value[4], expected 227, is %d", + check_msg->amplitude_value[4]); + ck_assert_msg(check_msg->amplitude_value[5] == 244, + "incorrect value for amplitude_value[5], expected 244, is %d", + check_msg->amplitude_value[5]); + ck_assert_msg(check_msg->amplitude_value[6] == 173, + "incorrect value for amplitude_value[6], expected 173, is %d", + check_msg->amplitude_value[6]); + ck_assert_msg(check_msg->amplitude_value[7] == 240, + "incorrect value for amplitude_value[7], expected 240, is %d", + check_msg->amplitude_value[7]); + ck_assert_msg(check_msg->amplitude_value[8] == 182, + "incorrect value for amplitude_value[8], expected 182, is %d", + check_msg->amplitude_value[8]); + ck_assert_msg(check_msg->amplitude_value[9] == 71, + "incorrect value for amplitude_value[9], expected 71, is %d", + check_msg->amplitude_value[9]); + ck_assert_msg( + check_msg->amplitude_value[10] == 166, + "incorrect value for amplitude_value[10], expected 166, is %d", + check_msg->amplitude_value[10]); + ck_assert_msg( + check_msg->amplitude_value[11] == 117, + "incorrect value for amplitude_value[11], expected 117, is %d", + check_msg->amplitude_value[11]); + ck_assert_msg( + check_msg->amplitude_value[12] == 196, + "incorrect value for amplitude_value[12], expected 196, is %d", + check_msg->amplitude_value[12]); + ck_assert_msg(check_msg->amplitude_value[13] == 13, + "incorrect value for amplitude_value[13], expected 13, is %d", + check_msg->amplitude_value[13]); + ck_assert_msg(check_msg->amplitude_value[14] == 44, + "incorrect value for amplitude_value[14], expected 44, is %d", + check_msg->amplitude_value[14]); + ck_assert_msg(check_msg->amplitude_value[15] == 27, + "incorrect value for amplitude_value[15], expected 27, is %d", + check_msg->amplitude_value[15]); + ck_assert_msg(check_msg->amplitude_value[16] == 33, + "incorrect value for amplitude_value[16], expected 33, is %d", + check_msg->amplitude_value[16]); + ck_assert_msg(check_msg->amplitude_value[17] == 28, + "incorrect value for amplitude_value[17], expected 28, is %d", + check_msg->amplitude_value[17]); + ck_assert_msg(check_msg->amplitude_value[18] == 67, + "incorrect value for amplitude_value[18], expected 67, is %d", + check_msg->amplitude_value[18]); + ck_assert_msg( + check_msg->amplitude_value[19] == 254, + "incorrect value for amplitude_value[19], expected 254, is %d", + check_msg->amplitude_value[19]); + ck_assert_msg(check_msg->amplitude_value[20] == 3, + "incorrect value for amplitude_value[20], expected 3, is %d", + check_msg->amplitude_value[20]); + ck_assert_msg( + check_msg->amplitude_value[21] == 249, + "incorrect value for amplitude_value[21], expected 249, is %d", + check_msg->amplitude_value[21]); + ck_assert_msg(check_msg->amplitude_value[22] == 92, + "incorrect value for amplitude_value[22], expected 92, is %d", + check_msg->amplitude_value[22]); + ck_assert_msg(check_msg->amplitude_value[23] == 44, + "incorrect value for amplitude_value[23], expected 44, is %d", + check_msg->amplitude_value[23]); + ck_assert_msg( + check_msg->amplitude_value[24] == 122, + "incorrect value for amplitude_value[24], expected 122, is %d", + check_msg->amplitude_value[24]); + ck_assert_msg( + check_msg->amplitude_value[25] == 169, + "incorrect value for amplitude_value[25], expected 169, is %d", + check_msg->amplitude_value[25]); + ck_assert_msg(check_msg->amplitude_value[26] == 77, + "incorrect value for amplitude_value[26], expected 77, is %d", + check_msg->amplitude_value[26]); + ck_assert_msg( + check_msg->amplitude_value[27] == 186, + "incorrect value for amplitude_value[27], expected 186, is %d", + check_msg->amplitude_value[27]); + ck_assert_msg(check_msg->amplitude_value[28] == 68, + "incorrect value for amplitude_value[28], expected 68, is %d", + check_msg->amplitude_value[28]); + ck_assert_msg( + check_msg->amplitude_value[29] == 135, + "incorrect value for amplitude_value[29], expected 135, is %d", + check_msg->amplitude_value[29]); + ck_assert_msg(check_msg->amplitude_value[30] == 63, + "incorrect value for amplitude_value[30], expected 63, is %d", + check_msg->amplitude_value[30]); + ck_assert_msg( + check_msg->amplitude_value[31] == 168, + "incorrect value for amplitude_value[31], expected 168, is %d", + check_msg->amplitude_value[31]); + ck_assert_msg( + check_msg->amplitude_value[32] == 162, + "incorrect value for amplitude_value[32], expected 162, is %d", + check_msg->amplitude_value[32]); + ck_assert_msg(check_msg->amplitude_value[33] == 89, + "incorrect value for amplitude_value[33], expected 89, is %d", + check_msg->amplitude_value[33]); + ck_assert_msg(check_msg->amplitude_value[34] == 36, + "incorrect value for amplitude_value[34], expected 36, is %d", + check_msg->amplitude_value[34]); + ck_assert_msg( + check_msg->amplitude_value[35] == 186, + "incorrect value for amplitude_value[35], expected 186, is %d", + check_msg->amplitude_value[35]); + ck_assert_msg(check_msg->amplitude_value[36] == 99, + "incorrect value for amplitude_value[36], expected 99, is %d", + check_msg->amplitude_value[36]); + ck_assert_msg(check_msg->amplitude_value[37] == 63, + "incorrect value for amplitude_value[37], expected 63, is %d", + check_msg->amplitude_value[37]); + ck_assert_msg( + check_msg->amplitude_value[38] == 105, + "incorrect value for amplitude_value[38], expected 105, is %d", + check_msg->amplitude_value[38]); + ck_assert_msg( + check_msg->amplitude_value[39] == 116, + "incorrect value for amplitude_value[39], expected 116, is %d", + check_msg->amplitude_value[39]); + ck_assert_msg( + check_msg->amplitude_value[40] == 216, + "incorrect value for amplitude_value[40], expected 216, is %d", + check_msg->amplitude_value[40]); + ck_assert_msg(check_msg->amplitude_value[41] == 44, + "incorrect value for amplitude_value[41], expected 44, is %d", + check_msg->amplitude_value[41]); + ck_assert_msg(check_msg->amplitude_value[42] == 67, + "incorrect value for amplitude_value[42], expected 67, is %d", + check_msg->amplitude_value[42]); + ck_assert_msg( + check_msg->amplitude_value[43] == 212, + "incorrect value for amplitude_value[43], expected 212, is %d", + check_msg->amplitude_value[43]); + ck_assert_msg( + check_msg->amplitude_value[44] == 156, + "incorrect value for amplitude_value[44], expected 156, is %d", + check_msg->amplitude_value[44]); + ck_assert_msg(check_msg->amplitude_value[45] == 75, + "incorrect value for amplitude_value[45], expected 75, is %d", + check_msg->amplitude_value[45]); + ck_assert_msg(check_msg->amplitude_value[46] == 81, + "incorrect value for amplitude_value[46], expected 81, is %d", + check_msg->amplitude_value[46]); + ck_assert_msg(check_msg->amplitude_value[47] == 53, + "incorrect value for amplitude_value[47], expected 53, is %d", + check_msg->amplitude_value[47]); + ck_assert_msg( + check_msg->amplitude_value[48] == 250, + "incorrect value for amplitude_value[48], expected 250, is %d", + check_msg->amplitude_value[48]); + ck_assert_msg( + check_msg->amplitude_value[49] == 225, + "incorrect value for amplitude_value[49], expected 225, is %d", + check_msg->amplitude_value[49]); + ck_assert_msg(check_msg->amplitude_value[50] == 23, + "incorrect value for amplitude_value[50], expected 23, is %d", + check_msg->amplitude_value[50]); + ck_assert_msg( + check_msg->amplitude_value[51] == 205, + "incorrect value for amplitude_value[51], expected 205, is %d", + check_msg->amplitude_value[51]); + ck_assert_msg(check_msg->amplitude_value[52] == 26, + "incorrect value for amplitude_value[52], expected 26, is %d", + check_msg->amplitude_value[52]); + ck_assert_msg(check_msg->amplitude_value[53] == 34, + "incorrect value for amplitude_value[53], expected 34, is %d", + check_msg->amplitude_value[53]); + ck_assert_msg( + check_msg->amplitude_value[54] == 119, + "incorrect value for amplitude_value[54], expected 119, is %d", + check_msg->amplitude_value[54]); + ck_assert_msg(check_msg->amplitude_value[55] == 50, + "incorrect value for amplitude_value[55], expected 50, is %d", + check_msg->amplitude_value[55]); + ck_assert_msg( + check_msg->amplitude_value[56] == 101, + "incorrect value for amplitude_value[56], expected 101, is %d", + check_msg->amplitude_value[56]); + ck_assert_msg(check_msg->amplitude_value[57] == 64, + "incorrect value for amplitude_value[57], expected 64, is %d", + check_msg->amplitude_value[57]); + ck_assert_msg(check_msg->amplitude_value[58] == 7, + "incorrect value for amplitude_value[58], expected 7, is %d", + check_msg->amplitude_value[58]); + ck_assert_msg( + check_msg->amplitude_value[59] == 231, + "incorrect value for amplitude_value[59], expected 231, is %d", + check_msg->amplitude_value[59]); + ck_assert_msg( + check_msg->amplitude_value[60] == 124, + "incorrect value for amplitude_value[60], expected 124, is %d", + check_msg->amplitude_value[60]); + ck_assert_msg( + check_msg->amplitude_value[61] == 183, + "incorrect value for amplitude_value[61], expected 183, is %d", + check_msg->amplitude_value[61]); + ck_assert_msg( + check_msg->amplitude_value[62] == 203, + "incorrect value for amplitude_value[62], expected 203, is %d", + check_msg->amplitude_value[62]); + ck_assert_msg( + check_msg->amplitude_value[63] == 102, + "incorrect value for amplitude_value[63], expected 102, is %d", + check_msg->amplitude_value[63]); + ck_assert_msg( + check_msg->amplitude_value[64] == 234, + "incorrect value for amplitude_value[64], expected 234, is %d", + check_msg->amplitude_value[64]); + ck_assert_msg(check_msg->amplitude_value[65] == 84, + "incorrect value for amplitude_value[65], expected 84, is %d", + check_msg->amplitude_value[65]); + ck_assert_msg(check_msg->amplitude_value[66] == 83, + "incorrect value for amplitude_value[66], expected 83, is %d", + check_msg->amplitude_value[66]); + ck_assert_msg( + check_msg->amplitude_value[67] == 208, + "incorrect value for amplitude_value[67], expected 208, is %d", + check_msg->amplitude_value[67]); + ck_assert_msg(check_msg->amplitude_value[68] == 23, + "incorrect value for amplitude_value[68], expected 23, is %d", + check_msg->amplitude_value[68]); + ck_assert_msg(check_msg->amplitude_value[69] == 68, + "incorrect value for amplitude_value[69], expected 68, is %d", + check_msg->amplitude_value[69]); + ck_assert_msg(check_msg->amplitude_value[70] == 54, + "incorrect value for amplitude_value[70], expected 54, is %d", + check_msg->amplitude_value[70]); + ck_assert_msg( + check_msg->amplitude_value[71] == 179, + "incorrect value for amplitude_value[71], expected 179, is %d", + check_msg->amplitude_value[71]); + ck_assert_msg(check_msg->amplitude_value[72] == 98, + "incorrect value for amplitude_value[72], expected 98, is %d", + check_msg->amplitude_value[72]); + ck_assert_msg(check_msg->amplitude_value[73] == 96, + "incorrect value for amplitude_value[73], expected 96, is %d", + check_msg->amplitude_value[73]); + ck_assert_msg( + check_msg->amplitude_value[74] == 116, + "incorrect value for amplitude_value[74], expected 116, is %d", + check_msg->amplitude_value[74]); + ck_assert_msg( + check_msg->amplitude_value[75] == 244, + "incorrect value for amplitude_value[75], expected 244, is %d", + check_msg->amplitude_value[75]); + ck_assert_msg( + check_msg->amplitude_value[76] == 246, + "incorrect value for amplitude_value[76], expected 246, is %d", + check_msg->amplitude_value[76]); + ck_assert_msg(check_msg->amplitude_value[77] == 94, + "incorrect value for amplitude_value[77], expected 94, is %d", + check_msg->amplitude_value[77]); + ck_assert_msg( + check_msg->amplitude_value[78] == 104, + "incorrect value for amplitude_value[78], expected 104, is %d", + check_msg->amplitude_value[78]); + ck_assert_msg(check_msg->amplitude_value[79] == 94, + "incorrect value for amplitude_value[79], expected 94, is %d", + check_msg->amplitude_value[79]); + ck_assert_msg(check_msg->amplitude_value[80] == 13, + "incorrect value for amplitude_value[80], expected 13, is %d", + check_msg->amplitude_value[80]); + ck_assert_msg(check_msg->amplitude_value[81] == 56, + "incorrect value for amplitude_value[81], expected 56, is %d", + check_msg->amplitude_value[81]); + ck_assert_msg( + check_msg->amplitude_value[82] == 210, + "incorrect value for amplitude_value[82], expected 210, is %d", + check_msg->amplitude_value[82]); + ck_assert_msg(check_msg->amplitude_value[83] == 18, + "incorrect value for amplitude_value[83], expected 18, is %d", + check_msg->amplitude_value[83]); + ck_assert_msg( + check_msg->amplitude_value[84] == 191, + "incorrect value for amplitude_value[84], expected 191, is %d", + check_msg->amplitude_value[84]); + ck_assert_msg(check_msg->amplitude_value[85] == 22, + "incorrect value for amplitude_value[85], expected 22, is %d", + check_msg->amplitude_value[85]); + ck_assert_msg( + check_msg->amplitude_value[86] == 133, + "incorrect value for amplitude_value[86], expected 133, is %d", + check_msg->amplitude_value[86]); + ck_assert_msg(check_msg->amplitude_value[87] == 81, + "incorrect value for amplitude_value[87], expected 81, is %d", + check_msg->amplitude_value[87]); + ck_assert_msg( + check_msg->amplitude_value[88] == 153, + "incorrect value for amplitude_value[88], expected 153, is %d", + check_msg->amplitude_value[88]); + ck_assert_msg( + check_msg->amplitude_value[89] == 159, + "incorrect value for amplitude_value[89], expected 159, is %d", + check_msg->amplitude_value[89]); + ck_assert_msg( + check_msg->amplitude_value[90] == 161, + "incorrect value for amplitude_value[90], expected 161, is %d", + check_msg->amplitude_value[90]); + ck_assert_msg( + check_msg->amplitude_value[91] == 219, + "incorrect value for amplitude_value[91], expected 219, is %d", + check_msg->amplitude_value[91]); + ck_assert_msg(check_msg->amplitude_value[92] == 59, + "incorrect value for amplitude_value[92], expected 59, is %d", + check_msg->amplitude_value[92]); + ck_assert_msg(check_msg->amplitude_value[93] == 21, + "incorrect value for amplitude_value[93], expected 21, is %d", + check_msg->amplitude_value[93]); + ck_assert_msg( + check_msg->amplitude_value[94] == 164, + "incorrect value for amplitude_value[94], expected 164, is %d", + check_msg->amplitude_value[94]); + ck_assert_msg( + check_msg->amplitude_value[95] == 121, + "incorrect value for amplitude_value[95], expected 121, is %d", + check_msg->amplitude_value[95]); + ck_assert_msg( + check_msg->amplitude_value[96] == 145, + "incorrect value for amplitude_value[96], expected 145, is %d", + check_msg->amplitude_value[96]); + ck_assert_msg( + check_msg->amplitude_value[97] == 203, + "incorrect value for amplitude_value[97], expected 203, is %d", + check_msg->amplitude_value[97]); + ck_assert_msg( + check_msg->amplitude_value[98] == 171, + "incorrect value for amplitude_value[98], expected 171, is %d", + check_msg->amplitude_value[98]); + ck_assert_msg( + check_msg->amplitude_value[99] == 132, + "incorrect value for amplitude_value[99], expected 132, is %d", + check_msg->amplitude_value[99]); + ck_assert_msg( + check_msg->amplitude_value[100] == 57, + "incorrect value for amplitude_value[100], expected 57, is %d", + check_msg->amplitude_value[100]); + ck_assert_msg( + check_msg->amplitude_value[101] == 180, + "incorrect value for amplitude_value[101], expected 180, is %d", + check_msg->amplitude_value[101]); + ck_assert_msg( + check_msg->amplitude_value[102] == 102, + "incorrect value for amplitude_value[102], expected 102, is %d", + check_msg->amplitude_value[102]); + ck_assert_msg( + check_msg->amplitude_value[103] == 101, + "incorrect value for amplitude_value[103], expected 101, is %d", + check_msg->amplitude_value[103]); + ck_assert_msg( + check_msg->amplitude_value[104] == 11, + "incorrect value for amplitude_value[104], expected 11, is %d", + check_msg->amplitude_value[104]); + ck_assert_msg( + check_msg->amplitude_value[105] == 229, + "incorrect value for amplitude_value[105], expected 229, is %d", + check_msg->amplitude_value[105]); + ck_assert_msg( + check_msg->amplitude_value[106] == 175, + "incorrect value for amplitude_value[106], expected 175, is %d", + check_msg->amplitude_value[106]); + ck_assert_msg( + check_msg->amplitude_value[107] == 145, + "incorrect value for amplitude_value[107], expected 145, is %d", + check_msg->amplitude_value[107]); + ck_assert_msg( + check_msg->amplitude_value[108] == 73, + "incorrect value for amplitude_value[108], expected 73, is %d", + check_msg->amplitude_value[108]); + ck_assert_msg( + check_msg->amplitude_value[109] == 72, + "incorrect value for amplitude_value[109], expected 72, is %d", + check_msg->amplitude_value[109]); + ck_assert_msg( + check_msg->amplitude_value[110] == 124, + "incorrect value for amplitude_value[110], expected 124, is %d", + check_msg->amplitude_value[110]); + ck_assert_msg(check_msg->amplitude_value[111] == 4, + "incorrect value for amplitude_value[111], expected 4, is %d", + check_msg->amplitude_value[111]); + ck_assert_msg( + check_msg->amplitude_value[112] == 184, + "incorrect value for amplitude_value[112], expected 184, is %d", + check_msg->amplitude_value[112]); + ck_assert_msg( + check_msg->amplitude_value[113] == 228, + "incorrect value for amplitude_value[113], expected 228, is %d", + check_msg->amplitude_value[113]); + ck_assert_msg( + check_msg->amplitude_value[114] == 61, + "incorrect value for amplitude_value[114], expected 61, is %d", + check_msg->amplitude_value[114]); + ck_assert_msg( + check_msg->amplitude_value[115] == 234, + "incorrect value for amplitude_value[115], expected 234, is %d", + check_msg->amplitude_value[115]); + ck_assert_msg( + check_msg->amplitude_value[116] == 218, + "incorrect value for amplitude_value[116], expected 218, is %d", + check_msg->amplitude_value[116]); + ck_assert_msg( + check_msg->amplitude_value[117] == 62, + "incorrect value for amplitude_value[117], expected 62, is %d", + check_msg->amplitude_value[117]); + ck_assert_msg( + check_msg->amplitude_value[118] == 226, + "incorrect value for amplitude_value[118], expected 226, is %d", + check_msg->amplitude_value[118]); + ck_assert_msg( + check_msg->amplitude_value[119] == 217, + "incorrect value for amplitude_value[119], expected 217, is %d", + check_msg->amplitude_value[119]); + ck_assert_msg( + check_msg->amplitude_value[120] == 193, + "incorrect value for amplitude_value[120], expected 193, is %d", + check_msg->amplitude_value[120]); + ck_assert_msg(check_msg->amplitude_value[121] == 7, + "incorrect value for amplitude_value[121], expected 7, is %d", + check_msg->amplitude_value[121]); + ck_assert_msg( + check_msg->amplitude_value[122] == 109, + "incorrect value for amplitude_value[122], expected 109, is %d", + check_msg->amplitude_value[122]); + ck_assert_msg( + check_msg->amplitude_value[123] == 44, + "incorrect value for amplitude_value[123], expected 44, is %d", + check_msg->amplitude_value[123]); + ck_assert_msg( + check_msg->amplitude_value[124] == 83, + "incorrect value for amplitude_value[124], expected 83, is %d", + check_msg->amplitude_value[124]); + ck_assert_msg( + check_msg->amplitude_value[125] == 201, + "incorrect value for amplitude_value[125], expected 201, is %d", + check_msg->amplitude_value[125]); + ck_assert_msg( + check_msg->amplitude_value[126] == 20, + "incorrect value for amplitude_value[126], expected 20, is %d", + check_msg->amplitude_value[126]); + ck_assert_msg( + check_msg->amplitude_value[127] == 101, + "incorrect value for amplitude_value[127], expected 101, is %d", + check_msg->amplitude_value[127]); + ck_assert_msg(check_msg->amplitude_value[128] == 9, + "incorrect value for amplitude_value[128], expected 9, is %d", + check_msg->amplitude_value[128]); + ck_assert_msg( + check_msg->amplitude_value[129] == 140, + "incorrect value for amplitude_value[129], expected 140, is %d", + check_msg->amplitude_value[129]); + ck_assert_msg( + check_msg->amplitude_value[130] == 186, + "incorrect value for amplitude_value[130], expected 186, is %d", + check_msg->amplitude_value[130]); + ck_assert_msg( + check_msg->amplitude_value[131] == 162, + "incorrect value for amplitude_value[131], expected 162, is %d", + check_msg->amplitude_value[131]); + ck_assert_msg( + check_msg->amplitude_value[132] == 81, + "incorrect value for amplitude_value[132], expected 81, is %d", + check_msg->amplitude_value[132]); + ck_assert_msg( + check_msg->amplitude_value[133] == 91, + "incorrect value for amplitude_value[133], expected 91, is %d", + check_msg->amplitude_value[133]); + ck_assert_msg( + check_msg->amplitude_value[134] == 30, + "incorrect value for amplitude_value[134], expected 30, is %d", + check_msg->amplitude_value[134]); + ck_assert_msg( + check_msg->amplitude_value[135] == 231, + "incorrect value for amplitude_value[135], expected 231, is %d", + check_msg->amplitude_value[135]); + ck_assert_msg( + check_msg->amplitude_value[136] == 161, + "incorrect value for amplitude_value[136], expected 161, is %d", + check_msg->amplitude_value[136]); + ck_assert_msg( + check_msg->amplitude_value[137] == 81, + "incorrect value for amplitude_value[137], expected 81, is %d", + check_msg->amplitude_value[137]); + ck_assert_msg( + check_msg->amplitude_value[138] == 216, + "incorrect value for amplitude_value[138], expected 216, is %d", + check_msg->amplitude_value[138]); + ck_assert_msg( + check_msg->amplitude_value[139] == 114, + "incorrect value for amplitude_value[139], expected 114, is %d", + check_msg->amplitude_value[139]); + ck_assert_msg( + check_msg->amplitude_value[140] == 60, + "incorrect value for amplitude_value[140], expected 60, is %d", + check_msg->amplitude_value[140]); + ck_assert_msg( + check_msg->amplitude_value[141] == 231, + "incorrect value for amplitude_value[141], expected 231, is %d", + check_msg->amplitude_value[141]); + ck_assert_msg( + check_msg->amplitude_value[142] == 163, + "incorrect value for amplitude_value[142], expected 163, is %d", + check_msg->amplitude_value[142]); + ck_assert_msg( + check_msg->amplitude_value[143] == 163, + "incorrect value for amplitude_value[143], expected 163, is %d", + check_msg->amplitude_value[143]); + ck_assert_msg( + check_msg->amplitude_value[144] == 49, + "incorrect value for amplitude_value[144], expected 49, is %d", + check_msg->amplitude_value[144]); + ck_assert_msg( + check_msg->amplitude_value[145] == 237, + "incorrect value for amplitude_value[145], expected 237, is %d", + check_msg->amplitude_value[145]); + ck_assert_msg( + check_msg->amplitude_value[146] == 244, + "incorrect value for amplitude_value[146], expected 244, is %d", + check_msg->amplitude_value[146]); + ck_assert_msg( + check_msg->amplitude_value[147] == 185, + "incorrect value for amplitude_value[147], expected 185, is %d", + check_msg->amplitude_value[147]); + ck_assert_msg( + check_msg->amplitude_value[148] == 240, + "incorrect value for amplitude_value[148], expected 240, is %d", + check_msg->amplitude_value[148]); + ck_assert_msg( + check_msg->amplitude_value[149] == 89, + "incorrect value for amplitude_value[149], expected 89, is %d", + check_msg->amplitude_value[149]); + ck_assert_msg( + check_msg->amplitude_value[150] == 143, + "incorrect value for amplitude_value[150], expected 143, is %d", + check_msg->amplitude_value[150]); + ck_assert_msg( + check_msg->amplitude_value[151] == 174, + "incorrect value for amplitude_value[151], expected 174, is %d", + check_msg->amplitude_value[151]); + ck_assert_msg( + check_msg->amplitude_value[152] == 165, + "incorrect value for amplitude_value[152], expected 165, is %d", + check_msg->amplitude_value[152]); + ck_assert_msg( + check_msg->amplitude_value[153] == 211, + "incorrect value for amplitude_value[153], expected 211, is %d", + check_msg->amplitude_value[153]); + ck_assert_msg( + check_msg->amplitude_value[154] == 241, + "incorrect value for amplitude_value[154], expected 241, is %d", + check_msg->amplitude_value[154]); + ck_assert_msg( + check_msg->amplitude_value[155] == 13, + "incorrect value for amplitude_value[155], expected 13, is %d", + check_msg->amplitude_value[155]); + ck_assert_msg( + check_msg->amplitude_value[156] == 16, + "incorrect value for amplitude_value[156], expected 16, is %d", + check_msg->amplitude_value[156]); + ck_assert_msg( + check_msg->amplitude_value[157] == 61, + "incorrect value for amplitude_value[157], expected 61, is %d", + check_msg->amplitude_value[157]); + ck_assert_msg( + check_msg->amplitude_value[158] == 141, + "incorrect value for amplitude_value[158], expected 141, is %d", + check_msg->amplitude_value[158]); + ck_assert_msg( + check_msg->amplitude_value[159] == 101, + "incorrect value for amplitude_value[159], expected 101, is %d", + check_msg->amplitude_value[159]); + ck_assert_msg( + check_msg->amplitude_value[160] == 89, + "incorrect value for amplitude_value[160], expected 89, is %d", + check_msg->amplitude_value[160]); + ck_assert_msg( + check_msg->amplitude_value[161] == 37, + "incorrect value for amplitude_value[161], expected 37, is %d", + check_msg->amplitude_value[161]); + ck_assert_msg( + check_msg->amplitude_value[162] == 117, + "incorrect value for amplitude_value[162], expected 117, is %d", + check_msg->amplitude_value[162]); + ck_assert_msg( + check_msg->amplitude_value[163] == 189, + "incorrect value for amplitude_value[163], expected 189, is %d", + check_msg->amplitude_value[163]); + ck_assert_msg( + check_msg->amplitude_value[164] == 86, + "incorrect value for amplitude_value[164], expected 86, is %d", + check_msg->amplitude_value[164]); + ck_assert_msg( + check_msg->amplitude_value[165] == 118, + "incorrect value for amplitude_value[165], expected 118, is %d", + check_msg->amplitude_value[165]); + ck_assert_msg( + check_msg->amplitude_value[166] == 176, + "incorrect value for amplitude_value[166], expected 176, is %d", + check_msg->amplitude_value[166]); + ck_assert_msg( + check_msg->amplitude_value[167] == 228, + "incorrect value for amplitude_value[167], expected 228, is %d", + check_msg->amplitude_value[167]); + ck_assert_msg( + check_msg->amplitude_value[168] == 12, + "incorrect value for amplitude_value[168], expected 12, is %d", + check_msg->amplitude_value[168]); + ck_assert_msg( + check_msg->amplitude_value[169] == 14, + "incorrect value for amplitude_value[169], expected 14, is %d", + check_msg->amplitude_value[169]); + ck_assert_msg( + check_msg->amplitude_value[170] == 119, + "incorrect value for amplitude_value[170], expected 119, is %d", + check_msg->amplitude_value[170]); + ck_assert_msg( + check_msg->amplitude_value[171] == 135, + "incorrect value for amplitude_value[171], expected 135, is %d", + check_msg->amplitude_value[171]); + ck_assert_msg( + check_msg->amplitude_value[172] == 129, + "incorrect value for amplitude_value[172], expected 129, is %d", + check_msg->amplitude_value[172]); + ck_assert_msg( + check_msg->amplitude_value[173] == 243, + "incorrect value for amplitude_value[173], expected 243, is %d", + check_msg->amplitude_value[173]); + ck_assert_msg( + check_msg->amplitude_value[174] == 50, + "incorrect value for amplitude_value[174], expected 50, is %d", + check_msg->amplitude_value[174]); + ck_assert_msg( + check_msg->amplitude_value[175] == 29, + "incorrect value for amplitude_value[175], expected 29, is %d", + check_msg->amplitude_value[175]); + ck_assert_msg( + check_msg->amplitude_value[176] == 207, + "incorrect value for amplitude_value[176], expected 207, is %d", + check_msg->amplitude_value[176]); + ck_assert_msg( + check_msg->amplitude_value[177] == 198, + "incorrect value for amplitude_value[177], expected 198, is %d", + check_msg->amplitude_value[177]); + ck_assert_msg( + check_msg->amplitude_value[178] == 117, + "incorrect value for amplitude_value[178], expected 117, is %d", + check_msg->amplitude_value[178]); + ck_assert_msg( + check_msg->amplitude_value[179] == 100, + "incorrect value for amplitude_value[179], expected 100, is %d", + check_msg->amplitude_value[179]); + ck_assert_msg( + check_msg->amplitude_value[180] == 225, + "incorrect value for amplitude_value[180], expected 225, is %d", + check_msg->amplitude_value[180]); + ck_assert_msg(check_msg->amplitude_value[181] == 6, + "incorrect value for amplitude_value[181], expected 6, is %d", + check_msg->amplitude_value[181]); + ck_assert_msg( + check_msg->amplitude_value[182] == 139, + "incorrect value for amplitude_value[182], expected 139, is %d", + check_msg->amplitude_value[182]); + ck_assert_msg( + check_msg->amplitude_value[183] == 110, + "incorrect value for amplitude_value[183], expected 110, is %d", + check_msg->amplitude_value[183]); + ck_assert_msg( + check_msg->amplitude_value[184] == 39, + "incorrect value for amplitude_value[184], expected 39, is %d", + check_msg->amplitude_value[184]); + ck_assert_msg( + check_msg->amplitude_value[185] == 210, + "incorrect value for amplitude_value[185], expected 210, is %d", + check_msg->amplitude_value[185]); + ck_assert_msg( + check_msg->amplitude_value[186] == 68, + "incorrect value for amplitude_value[186], expected 68, is %d", + check_msg->amplitude_value[186]); + ck_assert_msg( + check_msg->amplitude_value[187] == 199, + "incorrect value for amplitude_value[187], expected 199, is %d", + check_msg->amplitude_value[187]); + ck_assert_msg( + check_msg->amplitude_value[188] == 43, + "incorrect value for amplitude_value[188], expected 43, is %d", + check_msg->amplitude_value[188]); + ck_assert_msg( + check_msg->amplitude_value[189] == 132, + "incorrect value for amplitude_value[189], expected 132, is %d", + check_msg->amplitude_value[189]); + ck_assert_msg( + check_msg->amplitude_value[190] == 64, + "incorrect value for amplitude_value[190], expected 64, is %d", + check_msg->amplitude_value[190]); + ck_assert_msg( + check_msg->amplitude_value[191] == 17, + "incorrect value for amplitude_value[191], expected 17, is %d", + check_msg->amplitude_value[191]); + ck_assert_msg( + check_msg->amplitude_value[192] == 51, + "incorrect value for amplitude_value[192], expected 51, is %d", + check_msg->amplitude_value[192]); + ck_assert_msg( + check_msg->amplitude_value[193] == 173, + "incorrect value for amplitude_value[193], expected 173, is %d", + check_msg->amplitude_value[193]); + ck_assert_msg( + check_msg->amplitude_value[194] == 181, + "incorrect value for amplitude_value[194], expected 181, is %d", + check_msg->amplitude_value[194]); + ck_assert_msg( + check_msg->amplitude_value[195] == 12, + "incorrect value for amplitude_value[195], expected 12, is %d", + check_msg->amplitude_value[195]); + ck_assert_msg( + check_msg->amplitude_value[196] == 140, + "incorrect value for amplitude_value[196], expected 140, is %d", + check_msg->amplitude_value[196]); + ck_assert_msg( + check_msg->amplitude_value[197] == 16, + "incorrect value for amplitude_value[197], expected 16, is %d", + check_msg->amplitude_value[197]); + ck_assert_msg( + check_msg->amplitude_value[198] == 247, + "incorrect value for amplitude_value[198], expected 247, is %d", + check_msg->amplitude_value[198]); + ck_assert_msg( + check_msg->amplitude_value[199] == 84, + "incorrect value for amplitude_value[199], expected 84, is %d", + check_msg->amplitude_value[199]); + ck_assert_msg( + check_msg->amplitude_value[200] == 183, + "incorrect value for amplitude_value[200], expected 183, is %d", + check_msg->amplitude_value[200]); + ck_assert_msg( + check_msg->amplitude_value[201] == 105, + "incorrect value for amplitude_value[201], expected 105, is %d", + check_msg->amplitude_value[201]); + ck_assert_msg( + check_msg->amplitude_value[202] == 39, + "incorrect value for amplitude_value[202], expected 39, is %d", + check_msg->amplitude_value[202]); + ck_assert_msg( + check_msg->amplitude_value[203] == 157, + "incorrect value for amplitude_value[203], expected 157, is %d", + check_msg->amplitude_value[203]); + ck_assert_msg( + check_msg->amplitude_value[204] == 77, + "incorrect value for amplitude_value[204], expected 77, is %d", + check_msg->amplitude_value[204]); + ck_assert_msg( + check_msg->amplitude_value[205] == 30, + "incorrect value for amplitude_value[205], expected 30, is %d", + check_msg->amplitude_value[205]); + ck_assert_msg( + check_msg->amplitude_value[206] == 205, + "incorrect value for amplitude_value[206], expected 205, is %d", + check_msg->amplitude_value[206]); + ck_assert_msg( + check_msg->amplitude_value[207] == 194, + "incorrect value for amplitude_value[207], expected 194, is %d", + check_msg->amplitude_value[207]); + ck_assert_msg( + check_msg->amplitude_value[208] == 59, + "incorrect value for amplitude_value[208], expected 59, is %d", + check_msg->amplitude_value[208]); + ck_assert_msg( + check_msg->amplitude_value[209] == 64, + "incorrect value for amplitude_value[209], expected 64, is %d", + check_msg->amplitude_value[209]); + ck_assert_msg( + check_msg->amplitude_value[210] == 241, + "incorrect value for amplitude_value[210], expected 241, is %d", + check_msg->amplitude_value[210]); + ck_assert_msg( + check_msg->amplitude_value[211] == 183, + "incorrect value for amplitude_value[211], expected 183, is %d", + check_msg->amplitude_value[211]); + ck_assert_msg( + check_msg->amplitude_value[212] == 238, + "incorrect value for amplitude_value[212], expected 238, is %d", + check_msg->amplitude_value[212]); + ck_assert_msg( + check_msg->amplitude_value[213] == 105, + "incorrect value for amplitude_value[213], expected 105, is %d", + check_msg->amplitude_value[213]); + ck_assert_msg( + check_msg->amplitude_value[214] == 181, + "incorrect value for amplitude_value[214], expected 181, is %d", + check_msg->amplitude_value[214]); + ck_assert_msg( + check_msg->amplitude_value[215] == 170, + "incorrect value for amplitude_value[215], expected 170, is %d", + check_msg->amplitude_value[215]); + ck_assert_msg( + check_msg->amplitude_value[216] == 45, + "incorrect value for amplitude_value[216], expected 45, is %d", + check_msg->amplitude_value[216]); + ck_assert_msg(check_msg->amplitude_value[217] == 8, + "incorrect value for amplitude_value[217], expected 8, is %d", + check_msg->amplitude_value[217]); + ck_assert_msg( + check_msg->amplitude_value[218] == 166, + "incorrect value for amplitude_value[218], expected 166, is %d", + check_msg->amplitude_value[218]); + ck_assert_msg( + check_msg->amplitude_value[219] == 164, + "incorrect value for amplitude_value[219], expected 164, is %d", + check_msg->amplitude_value[219]); + ck_assert_msg( + check_msg->amplitude_value[220] == 238, + "incorrect value for amplitude_value[220], expected 238, is %d", + check_msg->amplitude_value[220]); + ck_assert_msg( + check_msg->amplitude_value[221] == 83, + "incorrect value for amplitude_value[221], expected 83, is %d", + check_msg->amplitude_value[221]); + ck_assert_msg( + check_msg->amplitude_value[222] == 148, + "incorrect value for amplitude_value[222], expected 148, is %d", + check_msg->amplitude_value[222]); + ck_assert_msg( + check_msg->amplitude_value[223] == 173, + "incorrect value for amplitude_value[223], expected 173, is %d", + check_msg->amplitude_value[223]); + ck_assert_msg( + check_msg->amplitude_value[224] == 108, + "incorrect value for amplitude_value[224], expected 108, is %d", + check_msg->amplitude_value[224]); + ck_assert_msg( + check_msg->amplitude_value[225] == 228, + "incorrect value for amplitude_value[225], expected 228, is %d", + check_msg->amplitude_value[225]); + ck_assert_msg( + check_msg->amplitude_value[226] == 67, + "incorrect value for amplitude_value[226], expected 67, is %d", + check_msg->amplitude_value[226]); + ck_assert_msg( + check_msg->amplitude_value[227] == 89, + "incorrect value for amplitude_value[227], expected 89, is %d", + check_msg->amplitude_value[227]); + ck_assert_msg( + check_msg->amplitude_value[228] == 189, + "incorrect value for amplitude_value[228], expected 189, is %d", + check_msg->amplitude_value[228]); + ck_assert_msg( + check_msg->amplitude_value[229] == 67, + "incorrect value for amplitude_value[229], expected 67, is %d", + check_msg->amplitude_value[229]); + ck_assert_msg( + check_msg->amplitude_value[230] == 26, + "incorrect value for amplitude_value[230], expected 26, is %d", + check_msg->amplitude_value[230]); + ck_assert_msg(check_msg->channel_tag == 5878, + "incorrect value for channel_tag, expected 5878, is %d", + check_msg->channel_tag); + ck_assert_msg((check_msg->freq_ref * 100 - 6348.20019531 * 100) < 0.05, + "incorrect value for freq_ref, expected 6348.20019531, is %f", + check_msg->freq_ref); + ck_assert_msg( + (check_msg->freq_step * 100 - 4608.20019531 * 100) < 0.05, + "incorrect value for freq_step, expected 4608.20019531, is %f", + check_msg->freq_step); + ck_assert_msg(check_msg->t.tow == 992295133, + "incorrect value for t.tow, expected 992295133, is %d", + check_msg->t.tow); + ck_assert_msg(check_msg->t.wn == 6957, + "incorrect value for t.wn, expected 6957, is %d", + check_msg->t.wn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_piksi_MsgSpecanDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_piksi_MsgSpecanDep"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_piksi_MsgSpecanDep"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_piksi_MsgSpecanDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_piksi_MsgUartState.c b/c/test/legacy/auto_check_sbp_piksi_MsgUartState.c index c67aef0fdf..b98bf6a535 100644 --- a/c/test/legacy/auto_check_sbp_piksi_MsgUartState.c +++ b/c/test/legacy/auto_check_sbp_piksi_MsgUartState.c @@ -116,6 +116,228 @@ START_TEST(test_legacy_auto_check_sbp_piksi_MsgUartState) { logging_reset(); + sbp_payload_callback_register(&sbp_state, 0x1d, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1d, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, + 89, 98, 79, 184, 138, 244, 154, 73, 201, 69, 154, 65, 211, 69, + 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, 51, 211, 7, 69, + 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, + 10, 113, 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, + 107, 111, 253, 168, 244, 158, 112, 19, 251, 131, 100, 225, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_uart_state_t* test_msg = (msg_uart_state_t*)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->latency.avg = 319865629; + test_msg->latency.current = 364253831; + test_msg->latency.lmax = -611749622; + test_msg->latency.lmin = 289902239; + test_msg->obs_period.avg = -1002717658; + test_msg->obs_period.current = -2080697488; + test_msg->obs_period.pmax = -1628133123; + test_msg->obs_period.pmin = 1869323177; + test_msg->uart_a.crc_error_count = 25177; + test_msg->uart_a.io_error_count = 47183; + test_msg->uart_a.rx_buffer_level = 244; + test_msg->uart_a.rx_throughput = 1853.199951171875; + test_msg->uart_a.tx_buffer_level = 138; + test_msg->uart_a.tx_throughput = 7765.2001953125; + test_msg->uart_b.crc_error_count = 4297; + test_msg->uart_b.io_error_count = 63847; + test_msg->uart_b.rx_buffer_level = 161; + test_msg->uart_b.rx_throughput = 6760.2001953125; + test_msg->uart_b.tx_buffer_level = 143; + test_msg->uart_b.tx_throughput = 6441.2001953125; + test_msg->uart_ftdi.crc_error_count = 38359; + test_msg->uart_ftdi.io_error_count = 6653; + test_msg->uart_ftdi.rx_buffer_level = 24; + test_msg->uart_ftdi.rx_throughput = 2173.199951171875; + test_msg->uart_ftdi.tx_buffer_level = 218; + test_msg->uart_ftdi.tx_throughput = 5954.2001953125; + sbp_payload_send(&sbp_state, 0x1d, 57544, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 57544, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 57544, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1d, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_uart_state_t* check_msg = (msg_uart_state_t*)((void*)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->latency.avg == 319865629, + "incorrect value for latency.avg, expected 319865629, is %d", + check_msg->latency.avg); + ck_assert_msg( + check_msg->latency.current == 364253831, + "incorrect value for latency.current, expected 364253831, is %d", + check_msg->latency.current); + ck_assert_msg( + check_msg->latency.lmax == -611749622, + "incorrect value for latency.lmax, expected -611749622, is %d", + check_msg->latency.lmax); + ck_assert_msg(check_msg->latency.lmin == 289902239, + "incorrect value for latency.lmin, expected 289902239, is %d", + check_msg->latency.lmin); + ck_assert_msg( + check_msg->obs_period.avg == -1002717658, + "incorrect value for obs_period.avg, expected -1002717658, is %d", + check_msg->obs_period.avg); + ck_assert_msg( + check_msg->obs_period.current == -2080697488, + "incorrect value for obs_period.current, expected -2080697488, is %d", + check_msg->obs_period.current); + ck_assert_msg( + check_msg->obs_period.pmax == -1628133123, + "incorrect value for obs_period.pmax, expected -1628133123, is %d", + check_msg->obs_period.pmax); + ck_assert_msg( + check_msg->obs_period.pmin == 1869323177, + "incorrect value for obs_period.pmin, expected 1869323177, is %d", + check_msg->obs_period.pmin); + ck_assert_msg( + check_msg->uart_a.crc_error_count == 25177, + "incorrect value for uart_a.crc_error_count, expected 25177, is %d", + check_msg->uart_a.crc_error_count); + ck_assert_msg( + check_msg->uart_a.io_error_count == 47183, + "incorrect value for uart_a.io_error_count, expected 47183, is %d", + check_msg->uart_a.io_error_count); + ck_assert_msg( + check_msg->uart_a.rx_buffer_level == 244, + "incorrect value for uart_a.rx_buffer_level, expected 244, is %d", + check_msg->uart_a.rx_buffer_level); + ck_assert_msg( + (check_msg->uart_a.rx_throughput * 100 - 1853.19995117 * 100) < 0.05, + "incorrect value for uart_a.rx_throughput, expected 1853.19995117, is " + "%f", + check_msg->uart_a.rx_throughput); + ck_assert_msg( + check_msg->uart_a.tx_buffer_level == 138, + "incorrect value for uart_a.tx_buffer_level, expected 138, is %d", + check_msg->uart_a.tx_buffer_level); + ck_assert_msg( + (check_msg->uart_a.tx_throughput * 100 - 7765.20019531 * 100) < 0.05, + "incorrect value for uart_a.tx_throughput, expected 7765.20019531, is " + "%f", + check_msg->uart_a.tx_throughput); + ck_assert_msg( + check_msg->uart_b.crc_error_count == 4297, + "incorrect value for uart_b.crc_error_count, expected 4297, is %d", + check_msg->uart_b.crc_error_count); + ck_assert_msg( + check_msg->uart_b.io_error_count == 63847, + "incorrect value for uart_b.io_error_count, expected 63847, is %d", + check_msg->uart_b.io_error_count); + ck_assert_msg( + check_msg->uart_b.rx_buffer_level == 161, + "incorrect value for uart_b.rx_buffer_level, expected 161, is %d", + check_msg->uart_b.rx_buffer_level); + ck_assert_msg( + (check_msg->uart_b.rx_throughput * 100 - 6760.20019531 * 100) < 0.05, + "incorrect value for uart_b.rx_throughput, expected 6760.20019531, is " + "%f", + check_msg->uart_b.rx_throughput); + ck_assert_msg( + check_msg->uart_b.tx_buffer_level == 143, + "incorrect value for uart_b.tx_buffer_level, expected 143, is %d", + check_msg->uart_b.tx_buffer_level); + ck_assert_msg( + (check_msg->uart_b.tx_throughput * 100 - 6441.20019531 * 100) < 0.05, + "incorrect value for uart_b.tx_throughput, expected 6441.20019531, is " + "%f", + check_msg->uart_b.tx_throughput); + ck_assert_msg( + check_msg->uart_ftdi.crc_error_count == 38359, + "incorrect value for uart_ftdi.crc_error_count, expected 38359, is %d", + check_msg->uart_ftdi.crc_error_count); + ck_assert_msg( + check_msg->uart_ftdi.io_error_count == 6653, + "incorrect value for uart_ftdi.io_error_count, expected 6653, is %d", + check_msg->uart_ftdi.io_error_count); + ck_assert_msg( + check_msg->uart_ftdi.rx_buffer_level == 24, + "incorrect value for uart_ftdi.rx_buffer_level, expected 24, is %d", + check_msg->uart_ftdi.rx_buffer_level); + ck_assert_msg( + (check_msg->uart_ftdi.rx_throughput * 100 - 2173.19995117 * 100) < 0.05, + "incorrect value for uart_ftdi.rx_throughput, expected 2173.19995117, " + "is %f", + check_msg->uart_ftdi.rx_throughput); + ck_assert_msg( + check_msg->uart_ftdi.tx_buffer_level == 218, + "incorrect value for uart_ftdi.tx_buffer_level, expected 218, is %d", + check_msg->uart_ftdi.tx_buffer_level); + ck_assert_msg( + (check_msg->uart_ftdi.tx_throughput * 100 - 5954.20019531 * 100) < 0.05, + "incorrect value for uart_ftdi.tx_throughput, expected 5954.20019531, " + "is %f", + check_msg->uart_ftdi.tx_throughput); + } + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + sbp_payload_callback_register(&sbp_state, 0x18, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); sbp_frame_callback_register(&sbp_state, 0x18, &frame_callback, diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c new file mode 100644 index 0000000000..9cc153a8f2 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadByIndexReq.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa2, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa2, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 162, 0, 122, 123, 2, 244, 34, 235, 23, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_read_by_index_req_t *test_msg = + (msg_settings_read_by_index_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->index = 8948; + sbp_payload_send(&sbp_state, 0xa2, 31610, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 31610, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 31610, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa2, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_read_by_index_req_t *check_msg = + (msg_settings_read_by_index_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->index == 8948, + "incorrect value for index, expected 8948, is %d", + check_msg->index); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_" + "MsgSettingsReadByIndexReq"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadReq.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadReq.c new file mode 100644 index 0000000000..a3b5789e03 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadReq.c @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsReadReq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa4, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa4, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_read_req_t *test_msg = + (msg_settings_read_req_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xa4, 54936, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54936, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 54936, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa4, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_read_req_t *check_msg = + (msg_settings_read_req_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsReadReq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsReadReq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsReadReq"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsReadReq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadResp.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadResp.c new file mode 100644 index 0000000000..75fcaacfc6 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsReadResp.c @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsReadResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa5, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, + 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, + 118, 97, 108, 117, 101, 51, 0, 203, 199, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_read_resp_t *test_msg = + (msg_settings_read_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xa5, 61576, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61576, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 61576, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa5, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_read_resp_t *check_msg = + (msg_settings_read_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsReadResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsReadResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsReadResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsReadResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegister.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegister.c new file mode 100644 index 0000000000..75d61bda3e --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegister.c @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsRegister) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xae, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xae, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, + 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, + 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, + 118, 97, 108, 117, 101, 51, 0, 142, 235, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_register_t *test_msg = + (msg_settings_register_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xae, 1620, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1620, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1620, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xae, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_register_t *check_msg = + (msg_settings_register_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsRegister_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsRegister"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsRegister"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsRegister); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegisterResp.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegisterResp.c new file mode 100644 index 0000000000..e9a3b0a5d3 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsRegisterResp.c @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1af, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1af, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, + 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, + 44, 118, 97, 108, 117, 101, 51, 0, 82, 16, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_register_resp_t *test_msg = + (msg_settings_register_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->status = 18; + sbp_payload_send(&sbp_state, 0x1af, 54569, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 54569, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 54569, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1af, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_register_resp_t *check_msg = + (msg_settings_register_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + ck_assert_msg(check_msg->status == 18, + "incorrect value for status, expected 18, is %d", + check_msg->status); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsRegisterResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsRegisterResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsSave.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsSave.c new file mode 100644 index 0000000000..39aafad389 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsSave.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsSave) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa1, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 161, 0, 162, 224, 0, 123, 67, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + sbp_payload_send(&sbp_state, 0xa1, 57506, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 57506, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 57506, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa1, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsSave_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsSave"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsSave"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_settings_MsgSettingsSave); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsWrite.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsWrite.c new file mode 100644 index 0000000000..29ed276cf6 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsWrite.c @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsWrite) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xa0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xa0, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_write_t *test_msg = (msg_settings_write_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xa0, 123, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 123, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 123, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xa0, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_write_t *check_msg = + (msg_settings_write_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsWrite_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsWrite"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsWrite"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_settings_MsgSettingsWrite); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_settings_MsgSettingsWriteResp.c b/c/test/legacy/auto_check_sbp_settings_MsgSettingsWriteResp.c new file mode 100644 index 0000000000..b3deae6411 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_settings_MsgSettingsWriteResp.c @@ -0,0 +1,251 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_settings_MsgSettingsWriteResp) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xaf, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xaf, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, + 118, 97, 108, 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, + 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_settings_write_resp_t *test_msg = + (msg_settings_write_resp_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len += sizeof(assign_string); + } + } + test_msg->status = 152; + sbp_payload_send(&sbp_state, 0xaf, 14171, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 14171, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 14171, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xaf, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_settings_write_resp_t *check_msg = + (msg_settings_write_resp_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + ck_assert_msg( + memcmp(check_msg->setting, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->setting, expected string '%s', is " + "'%s'", + check_string, check_msg->setting); + } + ck_assert_msg(check_msg->status == 152, + "incorrect value for status, expected 152, is %d", + check_msg->status); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_settings_MsgSettingsWriteResp_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_settings_MsgSettingsWriteResp"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_settings_MsgSettingsWriteResp"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_settings_MsgSettingsWriteResp); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMeta.c b/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMeta.c new file mode 100644 index 0000000000..ae06b95ef9 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMeta.c @@ -0,0 +1,1791 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_solution_meta_MsgSolnMeta) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff0e, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff0e, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, + 144, 228, 8, 83, 89, 87, 3, 213, 95, 109, 86, 131, 71, 70, + 84, 73, 131, 26, 82, 247, 140, 97, 115, 110, 118, 253, 2, 122, + 186, 148, 122, 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, + 208, 89, 56, 10, 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, + 238, 123, 102, 230, 76, 190, 225, 182, 207, 228, 7, 218, 117, 89, + 29, 191, 56, 248, 185, 255, 46, 18, 72, 142, 82, 113, 26, 4, + 172, 254, 178, 136, 113, 115, 58, 193, 89, 227, 182, 246, 76, 77, + 108, 245, 41, 31, 70, 124, 249, 145, 15, 78, 228, 38, 241, 129, + 8, 176, 251, 72, 248, 80, 115, 244, 231, 145, 191, 190, 178, 168, + 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, 92, 79, 101, 223, + 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, 36, 219, 56, + 146, 90, 219, 104, 227, 102, 83, 12, 41, 122, 173, 94, 1, 174, + 134, 130, 104, 237, 116, 249, 107, 230, 130, 123, 25, 162, 57, 223, + 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, 100, 66, 72, + 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, + 141, 25, 183, 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, + 180, 46, 140, 130, 36, 17, 194, 209, 65, 254, 115, 103, 152, 129, + 234, 235, 194, 234, 170, 201, 210, 154, 150, 247, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_soln_meta_t *test_msg = (msg_soln_meta_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->age_corrections = 21256; + test_msg->age_gnss = 3573765977; + test_msg->hdop = 41156; + test_msg->pdop = 11642; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[0].flags = 109; + test_msg->sol_in[0].sensor_type = 95; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[1].flags = 131; + test_msg->sol_in[1].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[2].flags = 70; + test_msg->sol_in[2].sensor_type = 71; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[3].flags = 73; + test_msg->sol_in[3].sensor_type = 84; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[4].flags = 26; + test_msg->sol_in[4].sensor_type = 131; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[5].flags = 247; + test_msg->sol_in[5].sensor_type = 82; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[6].flags = 97; + test_msg->sol_in[6].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[7].flags = 110; + test_msg->sol_in[7].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[8].flags = 253; + test_msg->sol_in[8].sensor_type = 118; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[9].flags = 122; + test_msg->sol_in[9].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[10].flags = 148; + test_msg->sol_in[10].sensor_type = 186; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[11].flags = 148; + test_msg->sol_in[11].sensor_type = 122; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[12].flags = 231; + test_msg->sol_in[12].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[13].flags = 46; + test_msg->sol_in[13].sensor_type = 68; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[14].flags = 102; + test_msg->sol_in[14].sensor_type = 190; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[15].flags = 48; + test_msg->sol_in[15].sensor_type = 243; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[16].flags = 15; + test_msg->sol_in[16].sensor_type = 192; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[17].flags = 89; + test_msg->sol_in[17].sensor_type = 208; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[18].flags = 10; + test_msg->sol_in[18].sensor_type = 56; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[19].flags = 2; + test_msg->sol_in[19].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[20].flags = 201; + test_msg->sol_in[20].sensor_type = 254; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[21].flags = 32; + test_msg->sol_in[21].sensor_type = 120; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[22].flags = 2; + test_msg->sol_in[22].sensor_type = 126; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[23].flags = 161; + test_msg->sol_in[23].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[24].flags = 123; + test_msg->sol_in[24].sensor_type = 238; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[25].flags = 230; + test_msg->sol_in[25].sensor_type = 102; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[26].flags = 190; + test_msg->sol_in[26].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[27].flags = 182; + test_msg->sol_in[27].sensor_type = 225; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[28].flags = 228; + test_msg->sol_in[28].sensor_type = 207; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[29].flags = 218; + test_msg->sol_in[29].sensor_type = 7; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[30].flags = 89; + test_msg->sol_in[30].sensor_type = 117; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[31].flags = 191; + test_msg->sol_in[31].sensor_type = 29; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[32].flags = 248; + test_msg->sol_in[32].sensor_type = 56; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[33].flags = 255; + test_msg->sol_in[33].sensor_type = 185; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[34].flags = 18; + test_msg->sol_in[34].sensor_type = 46; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[35].flags = 142; + test_msg->sol_in[35].sensor_type = 72; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[36].flags = 113; + test_msg->sol_in[36].sensor_type = 82; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[37].flags = 4; + test_msg->sol_in[37].sensor_type = 26; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[38].flags = 254; + test_msg->sol_in[38].sensor_type = 172; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[39].flags = 136; + test_msg->sol_in[39].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[40].flags = 115; + test_msg->sol_in[40].sensor_type = 113; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[41].flags = 193; + test_msg->sol_in[41].sensor_type = 58; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[42].flags = 227; + test_msg->sol_in[42].sensor_type = 89; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[43].flags = 246; + test_msg->sol_in[43].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[44].flags = 77; + test_msg->sol_in[44].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[45].flags = 245; + test_msg->sol_in[45].sensor_type = 108; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[46].flags = 31; + test_msg->sol_in[46].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[47].flags = 124; + test_msg->sol_in[47].sensor_type = 70; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[48].flags = 145; + test_msg->sol_in[48].sensor_type = 249; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[49].flags = 78; + test_msg->sol_in[49].sensor_type = 15; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[50].flags = 38; + test_msg->sol_in[50].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[51].flags = 129; + test_msg->sol_in[51].sensor_type = 241; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[52].flags = 176; + test_msg->sol_in[52].sensor_type = 8; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[53].flags = 72; + test_msg->sol_in[53].sensor_type = 251; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[54].flags = 80; + test_msg->sol_in[54].sensor_type = 248; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[55].flags = 244; + test_msg->sol_in[55].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[56].flags = 145; + test_msg->sol_in[56].sensor_type = 231; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[57].flags = 190; + test_msg->sol_in[57].sensor_type = 191; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[58].flags = 168; + test_msg->sol_in[58].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[59].flags = 233; + test_msg->sol_in[59].sensor_type = 89; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[60].flags = 176; + test_msg->sol_in[60].sensor_type = 69; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[61].flags = 140; + test_msg->sol_in[61].sensor_type = 174; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[62].flags = 141; + test_msg->sol_in[62].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[63].flags = 82; + test_msg->sol_in[63].sensor_type = 81; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[64].flags = 79; + test_msg->sol_in[64].sensor_type = 92; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[65].flags = 223; + test_msg->sol_in[65].sensor_type = 101; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[66].flags = 64; + test_msg->sol_in[66].sensor_type = 100; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[67].flags = 215; + test_msg->sol_in[67].sensor_type = 184; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[68].flags = 37; + test_msg->sol_in[68].sensor_type = 124; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[69].flags = 227; + test_msg->sol_in[69].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[70].flags = 102; + test_msg->sol_in[70].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[71].flags = 36; + test_msg->sol_in[71].sensor_type = 72; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[72].flags = 56; + test_msg->sol_in[72].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[73].flags = 90; + test_msg->sol_in[73].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[74].flags = 104; + test_msg->sol_in[74].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[75].flags = 102; + test_msg->sol_in[75].sensor_type = 227; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[76].flags = 12; + test_msg->sol_in[76].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[77].flags = 122; + test_msg->sol_in[77].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[78].flags = 94; + test_msg->sol_in[78].sensor_type = 173; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[79].flags = 174; + test_msg->sol_in[79].sensor_type = 1; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[80].flags = 130; + test_msg->sol_in[80].sensor_type = 134; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[81].flags = 237; + test_msg->sol_in[81].sensor_type = 104; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[82].flags = 249; + test_msg->sol_in[82].sensor_type = 116; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[83].flags = 230; + test_msg->sol_in[83].sensor_type = 107; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[84].flags = 123; + test_msg->sol_in[84].sensor_type = 130; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[85].flags = 162; + test_msg->sol_in[85].sensor_type = 25; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[86].flags = 223; + test_msg->sol_in[86].sensor_type = 57; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[87].flags = 174; + test_msg->sol_in[87].sensor_type = 193; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[88].flags = 193; + test_msg->sol_in[88].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[89].flags = 44; + test_msg->sol_in[89].sensor_type = 239; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[90].flags = 197; + test_msg->sol_in[90].sensor_type = 246; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[91].flags = 80; + test_msg->sol_in[91].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[92].flags = 100; + test_msg->sol_in[92].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[93].flags = 72; + test_msg->sol_in[93].sensor_type = 66; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[94].flags = 137; + test_msg->sol_in[94].sensor_type = 133; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[95].flags = 82; + test_msg->sol_in[95].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[96].flags = 2; + test_msg->sol_in[96].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[97].flags = 9; + test_msg->sol_in[97].sensor_type = 96; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[98].flags = 158; + test_msg->sol_in[98].sensor_type = 96; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[99].flags = 97; + test_msg->sol_in[99].sensor_type = 134; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[100].flags = 129; + test_msg->sol_in[100].sensor_type = 43; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[101].flags = 25; + test_msg->sol_in[101].sensor_type = 141; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[102].flags = 200; + test_msg->sol_in[102].sensor_type = 183; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[103].flags = 57; + test_msg->sol_in[103].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[104].flags = 103; + test_msg->sol_in[104].sensor_type = 248; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[105].flags = 65; + test_msg->sol_in[105].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[106].flags = 15; + test_msg->sol_in[106].sensor_type = 195; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[107].flags = 21; + test_msg->sol_in[107].sensor_type = 244; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[108].flags = 46; + test_msg->sol_in[108].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[109].flags = 130; + test_msg->sol_in[109].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[110].flags = 17; + test_msg->sol_in[110].sensor_type = 36; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[111].flags = 209; + test_msg->sol_in[111].sensor_type = 194; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[112].flags = 254; + test_msg->sol_in[112].sensor_type = 65; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[113].flags = 103; + test_msg->sol_in[113].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[114].flags = 129; + test_msg->sol_in[114].sensor_type = 152; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[115].flags = 235; + test_msg->sol_in[115].sensor_type = 234; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[116].flags = 234; + test_msg->sol_in[116].sensor_type = 194; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[117].flags = 201; + test_msg->sol_in[117].sensor_type = 170; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[118].flags = 154; + test_msg->sol_in[118].sensor_type = 210; + test_msg->tow = 3628191792; + test_msg->vdop = 58512; + sbp_payload_send(&sbp_state, 0xff0e, 15360, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 15360, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 15360, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff0e, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_soln_meta_t *check_msg = (msg_soln_meta_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->age_corrections == 21256, + "incorrect value for age_corrections, expected 21256, is %d", + check_msg->age_corrections); + ck_assert_msg(check_msg->age_gnss == 3573765977, + "incorrect value for age_gnss, expected 3573765977, is %d", + check_msg->age_gnss); + ck_assert_msg(check_msg->hdop == 41156, + "incorrect value for hdop, expected 41156, is %d", + check_msg->hdop); + ck_assert_msg(check_msg->pdop == 11642, + "incorrect value for pdop, expected 11642, is %d", + check_msg->pdop); + ck_assert_msg(check_msg->sol_in[0].flags == 109, + "incorrect value for sol_in[0].flags, expected 109, is %d", + check_msg->sol_in[0].flags); + ck_assert_msg( + check_msg->sol_in[0].sensor_type == 95, + "incorrect value for sol_in[0].sensor_type, expected 95, is %d", + check_msg->sol_in[0].sensor_type); + ck_assert_msg(check_msg->sol_in[1].flags == 131, + "incorrect value for sol_in[1].flags, expected 131, is %d", + check_msg->sol_in[1].flags); + ck_assert_msg( + check_msg->sol_in[1].sensor_type == 86, + "incorrect value for sol_in[1].sensor_type, expected 86, is %d", + check_msg->sol_in[1].sensor_type); + ck_assert_msg(check_msg->sol_in[2].flags == 70, + "incorrect value for sol_in[2].flags, expected 70, is %d", + check_msg->sol_in[2].flags); + ck_assert_msg( + check_msg->sol_in[2].sensor_type == 71, + "incorrect value for sol_in[2].sensor_type, expected 71, is %d", + check_msg->sol_in[2].sensor_type); + ck_assert_msg(check_msg->sol_in[3].flags == 73, + "incorrect value for sol_in[3].flags, expected 73, is %d", + check_msg->sol_in[3].flags); + ck_assert_msg( + check_msg->sol_in[3].sensor_type == 84, + "incorrect value for sol_in[3].sensor_type, expected 84, is %d", + check_msg->sol_in[3].sensor_type); + ck_assert_msg(check_msg->sol_in[4].flags == 26, + "incorrect value for sol_in[4].flags, expected 26, is %d", + check_msg->sol_in[4].flags); + ck_assert_msg( + check_msg->sol_in[4].sensor_type == 131, + "incorrect value for sol_in[4].sensor_type, expected 131, is %d", + check_msg->sol_in[4].sensor_type); + ck_assert_msg(check_msg->sol_in[5].flags == 247, + "incorrect value for sol_in[5].flags, expected 247, is %d", + check_msg->sol_in[5].flags); + ck_assert_msg( + check_msg->sol_in[5].sensor_type == 82, + "incorrect value for sol_in[5].sensor_type, expected 82, is %d", + check_msg->sol_in[5].sensor_type); + ck_assert_msg(check_msg->sol_in[6].flags == 97, + "incorrect value for sol_in[6].flags, expected 97, is %d", + check_msg->sol_in[6].flags); + ck_assert_msg( + check_msg->sol_in[6].sensor_type == 140, + "incorrect value for sol_in[6].sensor_type, expected 140, is %d", + check_msg->sol_in[6].sensor_type); + ck_assert_msg(check_msg->sol_in[7].flags == 110, + "incorrect value for sol_in[7].flags, expected 110, is %d", + check_msg->sol_in[7].flags); + ck_assert_msg( + check_msg->sol_in[7].sensor_type == 115, + "incorrect value for sol_in[7].sensor_type, expected 115, is %d", + check_msg->sol_in[7].sensor_type); + ck_assert_msg(check_msg->sol_in[8].flags == 253, + "incorrect value for sol_in[8].flags, expected 253, is %d", + check_msg->sol_in[8].flags); + ck_assert_msg( + check_msg->sol_in[8].sensor_type == 118, + "incorrect value for sol_in[8].sensor_type, expected 118, is %d", + check_msg->sol_in[8].sensor_type); + ck_assert_msg(check_msg->sol_in[9].flags == 122, + "incorrect value for sol_in[9].flags, expected 122, is %d", + check_msg->sol_in[9].flags); + ck_assert_msg( + check_msg->sol_in[9].sensor_type == 2, + "incorrect value for sol_in[9].sensor_type, expected 2, is %d", + check_msg->sol_in[9].sensor_type); + ck_assert_msg(check_msg->sol_in[10].flags == 148, + "incorrect value for sol_in[10].flags, expected 148, is %d", + check_msg->sol_in[10].flags); + ck_assert_msg( + check_msg->sol_in[10].sensor_type == 186, + "incorrect value for sol_in[10].sensor_type, expected 186, is %d", + check_msg->sol_in[10].sensor_type); + ck_assert_msg(check_msg->sol_in[11].flags == 148, + "incorrect value for sol_in[11].flags, expected 148, is %d", + check_msg->sol_in[11].flags); + ck_assert_msg( + check_msg->sol_in[11].sensor_type == 122, + "incorrect value for sol_in[11].sensor_type, expected 122, is %d", + check_msg->sol_in[11].sensor_type); + ck_assert_msg(check_msg->sol_in[12].flags == 231, + "incorrect value for sol_in[12].flags, expected 231, is %d", + check_msg->sol_in[12].flags); + ck_assert_msg( + check_msg->sol_in[12].sensor_type == 180, + "incorrect value for sol_in[12].sensor_type, expected 180, is %d", + check_msg->sol_in[12].sensor_type); + ck_assert_msg(check_msg->sol_in[13].flags == 46, + "incorrect value for sol_in[13].flags, expected 46, is %d", + check_msg->sol_in[13].flags); + ck_assert_msg( + check_msg->sol_in[13].sensor_type == 68, + "incorrect value for sol_in[13].sensor_type, expected 68, is %d", + check_msg->sol_in[13].sensor_type); + ck_assert_msg(check_msg->sol_in[14].flags == 102, + "incorrect value for sol_in[14].flags, expected 102, is %d", + check_msg->sol_in[14].flags); + ck_assert_msg( + check_msg->sol_in[14].sensor_type == 190, + "incorrect value for sol_in[14].sensor_type, expected 190, is %d", + check_msg->sol_in[14].sensor_type); + ck_assert_msg(check_msg->sol_in[15].flags == 48, + "incorrect value for sol_in[15].flags, expected 48, is %d", + check_msg->sol_in[15].flags); + ck_assert_msg( + check_msg->sol_in[15].sensor_type == 243, + "incorrect value for sol_in[15].sensor_type, expected 243, is %d", + check_msg->sol_in[15].sensor_type); + ck_assert_msg(check_msg->sol_in[16].flags == 15, + "incorrect value for sol_in[16].flags, expected 15, is %d", + check_msg->sol_in[16].flags); + ck_assert_msg( + check_msg->sol_in[16].sensor_type == 192, + "incorrect value for sol_in[16].sensor_type, expected 192, is %d", + check_msg->sol_in[16].sensor_type); + ck_assert_msg(check_msg->sol_in[17].flags == 89, + "incorrect value for sol_in[17].flags, expected 89, is %d", + check_msg->sol_in[17].flags); + ck_assert_msg( + check_msg->sol_in[17].sensor_type == 208, + "incorrect value for sol_in[17].sensor_type, expected 208, is %d", + check_msg->sol_in[17].sensor_type); + ck_assert_msg(check_msg->sol_in[18].flags == 10, + "incorrect value for sol_in[18].flags, expected 10, is %d", + check_msg->sol_in[18].flags); + ck_assert_msg( + check_msg->sol_in[18].sensor_type == 56, + "incorrect value for sol_in[18].sensor_type, expected 56, is %d", + check_msg->sol_in[18].sensor_type); + ck_assert_msg(check_msg->sol_in[19].flags == 2, + "incorrect value for sol_in[19].flags, expected 2, is %d", + check_msg->sol_in[19].flags); + ck_assert_msg( + check_msg->sol_in[19].sensor_type == 245, + "incorrect value for sol_in[19].sensor_type, expected 245, is %d", + check_msg->sol_in[19].sensor_type); + ck_assert_msg(check_msg->sol_in[20].flags == 201, + "incorrect value for sol_in[20].flags, expected 201, is %d", + check_msg->sol_in[20].flags); + ck_assert_msg( + check_msg->sol_in[20].sensor_type == 254, + "incorrect value for sol_in[20].sensor_type, expected 254, is %d", + check_msg->sol_in[20].sensor_type); + ck_assert_msg(check_msg->sol_in[21].flags == 32, + "incorrect value for sol_in[21].flags, expected 32, is %d", + check_msg->sol_in[21].flags); + ck_assert_msg( + check_msg->sol_in[21].sensor_type == 120, + "incorrect value for sol_in[21].sensor_type, expected 120, is %d", + check_msg->sol_in[21].sensor_type); + ck_assert_msg(check_msg->sol_in[22].flags == 2, + "incorrect value for sol_in[22].flags, expected 2, is %d", + check_msg->sol_in[22].flags); + ck_assert_msg( + check_msg->sol_in[22].sensor_type == 126, + "incorrect value for sol_in[22].sensor_type, expected 126, is %d", + check_msg->sol_in[22].sensor_type); + ck_assert_msg(check_msg->sol_in[23].flags == 161, + "incorrect value for sol_in[23].flags, expected 161, is %d", + check_msg->sol_in[23].flags); + ck_assert_msg( + check_msg->sol_in[23].sensor_type == 83, + "incorrect value for sol_in[23].sensor_type, expected 83, is %d", + check_msg->sol_in[23].sensor_type); + ck_assert_msg(check_msg->sol_in[24].flags == 123, + "incorrect value for sol_in[24].flags, expected 123, is %d", + check_msg->sol_in[24].flags); + ck_assert_msg( + check_msg->sol_in[24].sensor_type == 238, + "incorrect value for sol_in[24].sensor_type, expected 238, is %d", + check_msg->sol_in[24].sensor_type); + ck_assert_msg(check_msg->sol_in[25].flags == 230, + "incorrect value for sol_in[25].flags, expected 230, is %d", + check_msg->sol_in[25].flags); + ck_assert_msg( + check_msg->sol_in[25].sensor_type == 102, + "incorrect value for sol_in[25].sensor_type, expected 102, is %d", + check_msg->sol_in[25].sensor_type); + ck_assert_msg(check_msg->sol_in[26].flags == 190, + "incorrect value for sol_in[26].flags, expected 190, is %d", + check_msg->sol_in[26].flags); + ck_assert_msg( + check_msg->sol_in[26].sensor_type == 76, + "incorrect value for sol_in[26].sensor_type, expected 76, is %d", + check_msg->sol_in[26].sensor_type); + ck_assert_msg(check_msg->sol_in[27].flags == 182, + "incorrect value for sol_in[27].flags, expected 182, is %d", + check_msg->sol_in[27].flags); + ck_assert_msg( + check_msg->sol_in[27].sensor_type == 225, + "incorrect value for sol_in[27].sensor_type, expected 225, is %d", + check_msg->sol_in[27].sensor_type); + ck_assert_msg(check_msg->sol_in[28].flags == 228, + "incorrect value for sol_in[28].flags, expected 228, is %d", + check_msg->sol_in[28].flags); + ck_assert_msg( + check_msg->sol_in[28].sensor_type == 207, + "incorrect value for sol_in[28].sensor_type, expected 207, is %d", + check_msg->sol_in[28].sensor_type); + ck_assert_msg(check_msg->sol_in[29].flags == 218, + "incorrect value for sol_in[29].flags, expected 218, is %d", + check_msg->sol_in[29].flags); + ck_assert_msg( + check_msg->sol_in[29].sensor_type == 7, + "incorrect value for sol_in[29].sensor_type, expected 7, is %d", + check_msg->sol_in[29].sensor_type); + ck_assert_msg(check_msg->sol_in[30].flags == 89, + "incorrect value for sol_in[30].flags, expected 89, is %d", + check_msg->sol_in[30].flags); + ck_assert_msg( + check_msg->sol_in[30].sensor_type == 117, + "incorrect value for sol_in[30].sensor_type, expected 117, is %d", + check_msg->sol_in[30].sensor_type); + ck_assert_msg(check_msg->sol_in[31].flags == 191, + "incorrect value for sol_in[31].flags, expected 191, is %d", + check_msg->sol_in[31].flags); + ck_assert_msg( + check_msg->sol_in[31].sensor_type == 29, + "incorrect value for sol_in[31].sensor_type, expected 29, is %d", + check_msg->sol_in[31].sensor_type); + ck_assert_msg(check_msg->sol_in[32].flags == 248, + "incorrect value for sol_in[32].flags, expected 248, is %d", + check_msg->sol_in[32].flags); + ck_assert_msg( + check_msg->sol_in[32].sensor_type == 56, + "incorrect value for sol_in[32].sensor_type, expected 56, is %d", + check_msg->sol_in[32].sensor_type); + ck_assert_msg(check_msg->sol_in[33].flags == 255, + "incorrect value for sol_in[33].flags, expected 255, is %d", + check_msg->sol_in[33].flags); + ck_assert_msg( + check_msg->sol_in[33].sensor_type == 185, + "incorrect value for sol_in[33].sensor_type, expected 185, is %d", + check_msg->sol_in[33].sensor_type); + ck_assert_msg(check_msg->sol_in[34].flags == 18, + "incorrect value for sol_in[34].flags, expected 18, is %d", + check_msg->sol_in[34].flags); + ck_assert_msg( + check_msg->sol_in[34].sensor_type == 46, + "incorrect value for sol_in[34].sensor_type, expected 46, is %d", + check_msg->sol_in[34].sensor_type); + ck_assert_msg(check_msg->sol_in[35].flags == 142, + "incorrect value for sol_in[35].flags, expected 142, is %d", + check_msg->sol_in[35].flags); + ck_assert_msg( + check_msg->sol_in[35].sensor_type == 72, + "incorrect value for sol_in[35].sensor_type, expected 72, is %d", + check_msg->sol_in[35].sensor_type); + ck_assert_msg(check_msg->sol_in[36].flags == 113, + "incorrect value for sol_in[36].flags, expected 113, is %d", + check_msg->sol_in[36].flags); + ck_assert_msg( + check_msg->sol_in[36].sensor_type == 82, + "incorrect value for sol_in[36].sensor_type, expected 82, is %d", + check_msg->sol_in[36].sensor_type); + ck_assert_msg(check_msg->sol_in[37].flags == 4, + "incorrect value for sol_in[37].flags, expected 4, is %d", + check_msg->sol_in[37].flags); + ck_assert_msg( + check_msg->sol_in[37].sensor_type == 26, + "incorrect value for sol_in[37].sensor_type, expected 26, is %d", + check_msg->sol_in[37].sensor_type); + ck_assert_msg(check_msg->sol_in[38].flags == 254, + "incorrect value for sol_in[38].flags, expected 254, is %d", + check_msg->sol_in[38].flags); + ck_assert_msg( + check_msg->sol_in[38].sensor_type == 172, + "incorrect value for sol_in[38].sensor_type, expected 172, is %d", + check_msg->sol_in[38].sensor_type); + ck_assert_msg(check_msg->sol_in[39].flags == 136, + "incorrect value for sol_in[39].flags, expected 136, is %d", + check_msg->sol_in[39].flags); + ck_assert_msg( + check_msg->sol_in[39].sensor_type == 178, + "incorrect value for sol_in[39].sensor_type, expected 178, is %d", + check_msg->sol_in[39].sensor_type); + ck_assert_msg(check_msg->sol_in[40].flags == 115, + "incorrect value for sol_in[40].flags, expected 115, is %d", + check_msg->sol_in[40].flags); + ck_assert_msg( + check_msg->sol_in[40].sensor_type == 113, + "incorrect value for sol_in[40].sensor_type, expected 113, is %d", + check_msg->sol_in[40].sensor_type); + ck_assert_msg(check_msg->sol_in[41].flags == 193, + "incorrect value for sol_in[41].flags, expected 193, is %d", + check_msg->sol_in[41].flags); + ck_assert_msg( + check_msg->sol_in[41].sensor_type == 58, + "incorrect value for sol_in[41].sensor_type, expected 58, is %d", + check_msg->sol_in[41].sensor_type); + ck_assert_msg(check_msg->sol_in[42].flags == 227, + "incorrect value for sol_in[42].flags, expected 227, is %d", + check_msg->sol_in[42].flags); + ck_assert_msg( + check_msg->sol_in[42].sensor_type == 89, + "incorrect value for sol_in[42].sensor_type, expected 89, is %d", + check_msg->sol_in[42].sensor_type); + ck_assert_msg(check_msg->sol_in[43].flags == 246, + "incorrect value for sol_in[43].flags, expected 246, is %d", + check_msg->sol_in[43].flags); + ck_assert_msg( + check_msg->sol_in[43].sensor_type == 182, + "incorrect value for sol_in[43].sensor_type, expected 182, is %d", + check_msg->sol_in[43].sensor_type); + ck_assert_msg(check_msg->sol_in[44].flags == 77, + "incorrect value for sol_in[44].flags, expected 77, is %d", + check_msg->sol_in[44].flags); + ck_assert_msg( + check_msg->sol_in[44].sensor_type == 76, + "incorrect value for sol_in[44].sensor_type, expected 76, is %d", + check_msg->sol_in[44].sensor_type); + ck_assert_msg(check_msg->sol_in[45].flags == 245, + "incorrect value for sol_in[45].flags, expected 245, is %d", + check_msg->sol_in[45].flags); + ck_assert_msg( + check_msg->sol_in[45].sensor_type == 108, + "incorrect value for sol_in[45].sensor_type, expected 108, is %d", + check_msg->sol_in[45].sensor_type); + ck_assert_msg(check_msg->sol_in[46].flags == 31, + "incorrect value for sol_in[46].flags, expected 31, is %d", + check_msg->sol_in[46].flags); + ck_assert_msg( + check_msg->sol_in[46].sensor_type == 41, + "incorrect value for sol_in[46].sensor_type, expected 41, is %d", + check_msg->sol_in[46].sensor_type); + ck_assert_msg(check_msg->sol_in[47].flags == 124, + "incorrect value for sol_in[47].flags, expected 124, is %d", + check_msg->sol_in[47].flags); + ck_assert_msg( + check_msg->sol_in[47].sensor_type == 70, + "incorrect value for sol_in[47].sensor_type, expected 70, is %d", + check_msg->sol_in[47].sensor_type); + ck_assert_msg(check_msg->sol_in[48].flags == 145, + "incorrect value for sol_in[48].flags, expected 145, is %d", + check_msg->sol_in[48].flags); + ck_assert_msg( + check_msg->sol_in[48].sensor_type == 249, + "incorrect value for sol_in[48].sensor_type, expected 249, is %d", + check_msg->sol_in[48].sensor_type); + ck_assert_msg(check_msg->sol_in[49].flags == 78, + "incorrect value for sol_in[49].flags, expected 78, is %d", + check_msg->sol_in[49].flags); + ck_assert_msg( + check_msg->sol_in[49].sensor_type == 15, + "incorrect value for sol_in[49].sensor_type, expected 15, is %d", + check_msg->sol_in[49].sensor_type); + ck_assert_msg(check_msg->sol_in[50].flags == 38, + "incorrect value for sol_in[50].flags, expected 38, is %d", + check_msg->sol_in[50].flags); + ck_assert_msg( + check_msg->sol_in[50].sensor_type == 228, + "incorrect value for sol_in[50].sensor_type, expected 228, is %d", + check_msg->sol_in[50].sensor_type); + ck_assert_msg(check_msg->sol_in[51].flags == 129, + "incorrect value for sol_in[51].flags, expected 129, is %d", + check_msg->sol_in[51].flags); + ck_assert_msg( + check_msg->sol_in[51].sensor_type == 241, + "incorrect value for sol_in[51].sensor_type, expected 241, is %d", + check_msg->sol_in[51].sensor_type); + ck_assert_msg(check_msg->sol_in[52].flags == 176, + "incorrect value for sol_in[52].flags, expected 176, is %d", + check_msg->sol_in[52].flags); + ck_assert_msg( + check_msg->sol_in[52].sensor_type == 8, + "incorrect value for sol_in[52].sensor_type, expected 8, is %d", + check_msg->sol_in[52].sensor_type); + ck_assert_msg(check_msg->sol_in[53].flags == 72, + "incorrect value for sol_in[53].flags, expected 72, is %d", + check_msg->sol_in[53].flags); + ck_assert_msg( + check_msg->sol_in[53].sensor_type == 251, + "incorrect value for sol_in[53].sensor_type, expected 251, is %d", + check_msg->sol_in[53].sensor_type); + ck_assert_msg(check_msg->sol_in[54].flags == 80, + "incorrect value for sol_in[54].flags, expected 80, is %d", + check_msg->sol_in[54].flags); + ck_assert_msg( + check_msg->sol_in[54].sensor_type == 248, + "incorrect value for sol_in[54].sensor_type, expected 248, is %d", + check_msg->sol_in[54].sensor_type); + ck_assert_msg(check_msg->sol_in[55].flags == 244, + "incorrect value for sol_in[55].flags, expected 244, is %d", + check_msg->sol_in[55].flags); + ck_assert_msg( + check_msg->sol_in[55].sensor_type == 115, + "incorrect value for sol_in[55].sensor_type, expected 115, is %d", + check_msg->sol_in[55].sensor_type); + ck_assert_msg(check_msg->sol_in[56].flags == 145, + "incorrect value for sol_in[56].flags, expected 145, is %d", + check_msg->sol_in[56].flags); + ck_assert_msg( + check_msg->sol_in[56].sensor_type == 231, + "incorrect value for sol_in[56].sensor_type, expected 231, is %d", + check_msg->sol_in[56].sensor_type); + ck_assert_msg(check_msg->sol_in[57].flags == 190, + "incorrect value for sol_in[57].flags, expected 190, is %d", + check_msg->sol_in[57].flags); + ck_assert_msg( + check_msg->sol_in[57].sensor_type == 191, + "incorrect value for sol_in[57].sensor_type, expected 191, is %d", + check_msg->sol_in[57].sensor_type); + ck_assert_msg(check_msg->sol_in[58].flags == 168, + "incorrect value for sol_in[58].flags, expected 168, is %d", + check_msg->sol_in[58].flags); + ck_assert_msg( + check_msg->sol_in[58].sensor_type == 178, + "incorrect value for sol_in[58].sensor_type, expected 178, is %d", + check_msg->sol_in[58].sensor_type); + ck_assert_msg(check_msg->sol_in[59].flags == 233, + "incorrect value for sol_in[59].flags, expected 233, is %d", + check_msg->sol_in[59].flags); + ck_assert_msg( + check_msg->sol_in[59].sensor_type == 89, + "incorrect value for sol_in[59].sensor_type, expected 89, is %d", + check_msg->sol_in[59].sensor_type); + ck_assert_msg(check_msg->sol_in[60].flags == 176, + "incorrect value for sol_in[60].flags, expected 176, is %d", + check_msg->sol_in[60].flags); + ck_assert_msg( + check_msg->sol_in[60].sensor_type == 69, + "incorrect value for sol_in[60].sensor_type, expected 69, is %d", + check_msg->sol_in[60].sensor_type); + ck_assert_msg(check_msg->sol_in[61].flags == 140, + "incorrect value for sol_in[61].flags, expected 140, is %d", + check_msg->sol_in[61].flags); + ck_assert_msg( + check_msg->sol_in[61].sensor_type == 174, + "incorrect value for sol_in[61].sensor_type, expected 174, is %d", + check_msg->sol_in[61].sensor_type); + ck_assert_msg(check_msg->sol_in[62].flags == 141, + "incorrect value for sol_in[62].flags, expected 141, is %d", + check_msg->sol_in[62].flags); + ck_assert_msg( + check_msg->sol_in[62].sensor_type == 182, + "incorrect value for sol_in[62].sensor_type, expected 182, is %d", + check_msg->sol_in[62].sensor_type); + ck_assert_msg(check_msg->sol_in[63].flags == 82, + "incorrect value for sol_in[63].flags, expected 82, is %d", + check_msg->sol_in[63].flags); + ck_assert_msg( + check_msg->sol_in[63].sensor_type == 81, + "incorrect value for sol_in[63].sensor_type, expected 81, is %d", + check_msg->sol_in[63].sensor_type); + ck_assert_msg(check_msg->sol_in[64].flags == 79, + "incorrect value for sol_in[64].flags, expected 79, is %d", + check_msg->sol_in[64].flags); + ck_assert_msg( + check_msg->sol_in[64].sensor_type == 92, + "incorrect value for sol_in[64].sensor_type, expected 92, is %d", + check_msg->sol_in[64].sensor_type); + ck_assert_msg(check_msg->sol_in[65].flags == 223, + "incorrect value for sol_in[65].flags, expected 223, is %d", + check_msg->sol_in[65].flags); + ck_assert_msg( + check_msg->sol_in[65].sensor_type == 101, + "incorrect value for sol_in[65].sensor_type, expected 101, is %d", + check_msg->sol_in[65].sensor_type); + ck_assert_msg(check_msg->sol_in[66].flags == 64, + "incorrect value for sol_in[66].flags, expected 64, is %d", + check_msg->sol_in[66].flags); + ck_assert_msg( + check_msg->sol_in[66].sensor_type == 100, + "incorrect value for sol_in[66].sensor_type, expected 100, is %d", + check_msg->sol_in[66].sensor_type); + ck_assert_msg(check_msg->sol_in[67].flags == 215, + "incorrect value for sol_in[67].flags, expected 215, is %d", + check_msg->sol_in[67].flags); + ck_assert_msg( + check_msg->sol_in[67].sensor_type == 184, + "incorrect value for sol_in[67].sensor_type, expected 184, is %d", + check_msg->sol_in[67].sensor_type); + ck_assert_msg(check_msg->sol_in[68].flags == 37, + "incorrect value for sol_in[68].flags, expected 37, is %d", + check_msg->sol_in[68].flags); + ck_assert_msg( + check_msg->sol_in[68].sensor_type == 124, + "incorrect value for sol_in[68].sensor_type, expected 124, is %d", + check_msg->sol_in[68].sensor_type); + ck_assert_msg(check_msg->sol_in[69].flags == 227, + "incorrect value for sol_in[69].flags, expected 227, is %d", + check_msg->sol_in[69].flags); + ck_assert_msg( + check_msg->sol_in[69].sensor_type == 21, + "incorrect value for sol_in[69].sensor_type, expected 21, is %d", + check_msg->sol_in[69].sensor_type); + ck_assert_msg(check_msg->sol_in[70].flags == 102, + "incorrect value for sol_in[70].flags, expected 102, is %d", + check_msg->sol_in[70].flags); + ck_assert_msg( + check_msg->sol_in[70].sensor_type == 135, + "incorrect value for sol_in[70].sensor_type, expected 135, is %d", + check_msg->sol_in[70].sensor_type); + ck_assert_msg(check_msg->sol_in[71].flags == 36, + "incorrect value for sol_in[71].flags, expected 36, is %d", + check_msg->sol_in[71].flags); + ck_assert_msg( + check_msg->sol_in[71].sensor_type == 72, + "incorrect value for sol_in[71].sensor_type, expected 72, is %d", + check_msg->sol_in[71].sensor_type); + ck_assert_msg(check_msg->sol_in[72].flags == 56, + "incorrect value for sol_in[72].flags, expected 56, is %d", + check_msg->sol_in[72].flags); + ck_assert_msg( + check_msg->sol_in[72].sensor_type == 219, + "incorrect value for sol_in[72].sensor_type, expected 219, is %d", + check_msg->sol_in[72].sensor_type); + ck_assert_msg(check_msg->sol_in[73].flags == 90, + "incorrect value for sol_in[73].flags, expected 90, is %d", + check_msg->sol_in[73].flags); + ck_assert_msg( + check_msg->sol_in[73].sensor_type == 146, + "incorrect value for sol_in[73].sensor_type, expected 146, is %d", + check_msg->sol_in[73].sensor_type); + ck_assert_msg(check_msg->sol_in[74].flags == 104, + "incorrect value for sol_in[74].flags, expected 104, is %d", + check_msg->sol_in[74].flags); + ck_assert_msg( + check_msg->sol_in[74].sensor_type == 219, + "incorrect value for sol_in[74].sensor_type, expected 219, is %d", + check_msg->sol_in[74].sensor_type); + ck_assert_msg(check_msg->sol_in[75].flags == 102, + "incorrect value for sol_in[75].flags, expected 102, is %d", + check_msg->sol_in[75].flags); + ck_assert_msg( + check_msg->sol_in[75].sensor_type == 227, + "incorrect value for sol_in[75].sensor_type, expected 227, is %d", + check_msg->sol_in[75].sensor_type); + ck_assert_msg(check_msg->sol_in[76].flags == 12, + "incorrect value for sol_in[76].flags, expected 12, is %d", + check_msg->sol_in[76].flags); + ck_assert_msg( + check_msg->sol_in[76].sensor_type == 83, + "incorrect value for sol_in[76].sensor_type, expected 83, is %d", + check_msg->sol_in[76].sensor_type); + ck_assert_msg(check_msg->sol_in[77].flags == 122, + "incorrect value for sol_in[77].flags, expected 122, is %d", + check_msg->sol_in[77].flags); + ck_assert_msg( + check_msg->sol_in[77].sensor_type == 41, + "incorrect value for sol_in[77].sensor_type, expected 41, is %d", + check_msg->sol_in[77].sensor_type); + ck_assert_msg(check_msg->sol_in[78].flags == 94, + "incorrect value for sol_in[78].flags, expected 94, is %d", + check_msg->sol_in[78].flags); + ck_assert_msg( + check_msg->sol_in[78].sensor_type == 173, + "incorrect value for sol_in[78].sensor_type, expected 173, is %d", + check_msg->sol_in[78].sensor_type); + ck_assert_msg(check_msg->sol_in[79].flags == 174, + "incorrect value for sol_in[79].flags, expected 174, is %d", + check_msg->sol_in[79].flags); + ck_assert_msg( + check_msg->sol_in[79].sensor_type == 1, + "incorrect value for sol_in[79].sensor_type, expected 1, is %d", + check_msg->sol_in[79].sensor_type); + ck_assert_msg(check_msg->sol_in[80].flags == 130, + "incorrect value for sol_in[80].flags, expected 130, is %d", + check_msg->sol_in[80].flags); + ck_assert_msg( + check_msg->sol_in[80].sensor_type == 134, + "incorrect value for sol_in[80].sensor_type, expected 134, is %d", + check_msg->sol_in[80].sensor_type); + ck_assert_msg(check_msg->sol_in[81].flags == 237, + "incorrect value for sol_in[81].flags, expected 237, is %d", + check_msg->sol_in[81].flags); + ck_assert_msg( + check_msg->sol_in[81].sensor_type == 104, + "incorrect value for sol_in[81].sensor_type, expected 104, is %d", + check_msg->sol_in[81].sensor_type); + ck_assert_msg(check_msg->sol_in[82].flags == 249, + "incorrect value for sol_in[82].flags, expected 249, is %d", + check_msg->sol_in[82].flags); + ck_assert_msg( + check_msg->sol_in[82].sensor_type == 116, + "incorrect value for sol_in[82].sensor_type, expected 116, is %d", + check_msg->sol_in[82].sensor_type); + ck_assert_msg(check_msg->sol_in[83].flags == 230, + "incorrect value for sol_in[83].flags, expected 230, is %d", + check_msg->sol_in[83].flags); + ck_assert_msg( + check_msg->sol_in[83].sensor_type == 107, + "incorrect value for sol_in[83].sensor_type, expected 107, is %d", + check_msg->sol_in[83].sensor_type); + ck_assert_msg(check_msg->sol_in[84].flags == 123, + "incorrect value for sol_in[84].flags, expected 123, is %d", + check_msg->sol_in[84].flags); + ck_assert_msg( + check_msg->sol_in[84].sensor_type == 130, + "incorrect value for sol_in[84].sensor_type, expected 130, is %d", + check_msg->sol_in[84].sensor_type); + ck_assert_msg(check_msg->sol_in[85].flags == 162, + "incorrect value for sol_in[85].flags, expected 162, is %d", + check_msg->sol_in[85].flags); + ck_assert_msg( + check_msg->sol_in[85].sensor_type == 25, + "incorrect value for sol_in[85].sensor_type, expected 25, is %d", + check_msg->sol_in[85].sensor_type); + ck_assert_msg(check_msg->sol_in[86].flags == 223, + "incorrect value for sol_in[86].flags, expected 223, is %d", + check_msg->sol_in[86].flags); + ck_assert_msg( + check_msg->sol_in[86].sensor_type == 57, + "incorrect value for sol_in[86].sensor_type, expected 57, is %d", + check_msg->sol_in[86].sensor_type); + ck_assert_msg(check_msg->sol_in[87].flags == 174, + "incorrect value for sol_in[87].flags, expected 174, is %d", + check_msg->sol_in[87].flags); + ck_assert_msg( + check_msg->sol_in[87].sensor_type == 193, + "incorrect value for sol_in[87].sensor_type, expected 193, is %d", + check_msg->sol_in[87].sensor_type); + ck_assert_msg(check_msg->sol_in[88].flags == 193, + "incorrect value for sol_in[88].flags, expected 193, is %d", + check_msg->sol_in[88].flags); + ck_assert_msg( + check_msg->sol_in[88].sensor_type == 146, + "incorrect value for sol_in[88].sensor_type, expected 146, is %d", + check_msg->sol_in[88].sensor_type); + ck_assert_msg(check_msg->sol_in[89].flags == 44, + "incorrect value for sol_in[89].flags, expected 44, is %d", + check_msg->sol_in[89].flags); + ck_assert_msg( + check_msg->sol_in[89].sensor_type == 239, + "incorrect value for sol_in[89].sensor_type, expected 239, is %d", + check_msg->sol_in[89].sensor_type); + ck_assert_msg(check_msg->sol_in[90].flags == 197, + "incorrect value for sol_in[90].flags, expected 197, is %d", + check_msg->sol_in[90].flags); + ck_assert_msg( + check_msg->sol_in[90].sensor_type == 246, + "incorrect value for sol_in[90].sensor_type, expected 246, is %d", + check_msg->sol_in[90].sensor_type); + ck_assert_msg(check_msg->sol_in[91].flags == 80, + "incorrect value for sol_in[91].flags, expected 80, is %d", + check_msg->sol_in[91].flags); + ck_assert_msg( + check_msg->sol_in[91].sensor_type == 214, + "incorrect value for sol_in[91].sensor_type, expected 214, is %d", + check_msg->sol_in[91].sensor_type); + ck_assert_msg(check_msg->sol_in[92].flags == 100, + "incorrect value for sol_in[92].flags, expected 100, is %d", + check_msg->sol_in[92].flags); + ck_assert_msg( + check_msg->sol_in[92].sensor_type == 83, + "incorrect value for sol_in[92].sensor_type, expected 83, is %d", + check_msg->sol_in[92].sensor_type); + ck_assert_msg(check_msg->sol_in[93].flags == 72, + "incorrect value for sol_in[93].flags, expected 72, is %d", + check_msg->sol_in[93].flags); + ck_assert_msg( + check_msg->sol_in[93].sensor_type == 66, + "incorrect value for sol_in[93].sensor_type, expected 66, is %d", + check_msg->sol_in[93].sensor_type); + ck_assert_msg(check_msg->sol_in[94].flags == 137, + "incorrect value for sol_in[94].flags, expected 137, is %d", + check_msg->sol_in[94].flags); + ck_assert_msg( + check_msg->sol_in[94].sensor_type == 133, + "incorrect value for sol_in[94].sensor_type, expected 133, is %d", + check_msg->sol_in[94].sensor_type); + ck_assert_msg(check_msg->sol_in[95].flags == 82, + "incorrect value for sol_in[95].flags, expected 82, is %d", + check_msg->sol_in[95].flags); + ck_assert_msg( + check_msg->sol_in[95].sensor_type == 140, + "incorrect value for sol_in[95].sensor_type, expected 140, is %d", + check_msg->sol_in[95].sensor_type); + ck_assert_msg(check_msg->sol_in[96].flags == 2, + "incorrect value for sol_in[96].flags, expected 2, is %d", + check_msg->sol_in[96].flags); + ck_assert_msg( + check_msg->sol_in[96].sensor_type == 2, + "incorrect value for sol_in[96].sensor_type, expected 2, is %d", + check_msg->sol_in[96].sensor_type); + ck_assert_msg(check_msg->sol_in[97].flags == 9, + "incorrect value for sol_in[97].flags, expected 9, is %d", + check_msg->sol_in[97].flags); + ck_assert_msg( + check_msg->sol_in[97].sensor_type == 96, + "incorrect value for sol_in[97].sensor_type, expected 96, is %d", + check_msg->sol_in[97].sensor_type); + ck_assert_msg(check_msg->sol_in[98].flags == 158, + "incorrect value for sol_in[98].flags, expected 158, is %d", + check_msg->sol_in[98].flags); + ck_assert_msg( + check_msg->sol_in[98].sensor_type == 96, + "incorrect value for sol_in[98].sensor_type, expected 96, is %d", + check_msg->sol_in[98].sensor_type); + ck_assert_msg(check_msg->sol_in[99].flags == 97, + "incorrect value for sol_in[99].flags, expected 97, is %d", + check_msg->sol_in[99].flags); + ck_assert_msg( + check_msg->sol_in[99].sensor_type == 134, + "incorrect value for sol_in[99].sensor_type, expected 134, is %d", + check_msg->sol_in[99].sensor_type); + ck_assert_msg(check_msg->sol_in[100].flags == 129, + "incorrect value for sol_in[100].flags, expected 129, is %d", + check_msg->sol_in[100].flags); + ck_assert_msg( + check_msg->sol_in[100].sensor_type == 43, + "incorrect value for sol_in[100].sensor_type, expected 43, is %d", + check_msg->sol_in[100].sensor_type); + ck_assert_msg(check_msg->sol_in[101].flags == 25, + "incorrect value for sol_in[101].flags, expected 25, is %d", + check_msg->sol_in[101].flags); + ck_assert_msg( + check_msg->sol_in[101].sensor_type == 141, + "incorrect value for sol_in[101].sensor_type, expected 141, is %d", + check_msg->sol_in[101].sensor_type); + ck_assert_msg(check_msg->sol_in[102].flags == 200, + "incorrect value for sol_in[102].flags, expected 200, is %d", + check_msg->sol_in[102].flags); + ck_assert_msg( + check_msg->sol_in[102].sensor_type == 183, + "incorrect value for sol_in[102].sensor_type, expected 183, is %d", + check_msg->sol_in[102].sensor_type); + ck_assert_msg(check_msg->sol_in[103].flags == 57, + "incorrect value for sol_in[103].flags, expected 57, is %d", + check_msg->sol_in[103].flags); + ck_assert_msg( + check_msg->sol_in[103].sensor_type == 214, + "incorrect value for sol_in[103].sensor_type, expected 214, is %d", + check_msg->sol_in[103].sensor_type); + ck_assert_msg(check_msg->sol_in[104].flags == 103, + "incorrect value for sol_in[104].flags, expected 103, is %d", + check_msg->sol_in[104].flags); + ck_assert_msg( + check_msg->sol_in[104].sensor_type == 248, + "incorrect value for sol_in[104].sensor_type, expected 248, is %d", + check_msg->sol_in[104].sensor_type); + ck_assert_msg(check_msg->sol_in[105].flags == 65, + "incorrect value for sol_in[105].flags, expected 65, is %d", + check_msg->sol_in[105].flags); + ck_assert_msg( + check_msg->sol_in[105].sensor_type == 222, + "incorrect value for sol_in[105].sensor_type, expected 222, is %d", + check_msg->sol_in[105].sensor_type); + ck_assert_msg(check_msg->sol_in[106].flags == 15, + "incorrect value for sol_in[106].flags, expected 15, is %d", + check_msg->sol_in[106].flags); + ck_assert_msg( + check_msg->sol_in[106].sensor_type == 195, + "incorrect value for sol_in[106].sensor_type, expected 195, is %d", + check_msg->sol_in[106].sensor_type); + ck_assert_msg(check_msg->sol_in[107].flags == 21, + "incorrect value for sol_in[107].flags, expected 21, is %d", + check_msg->sol_in[107].flags); + ck_assert_msg( + check_msg->sol_in[107].sensor_type == 244, + "incorrect value for sol_in[107].sensor_type, expected 244, is %d", + check_msg->sol_in[107].sensor_type); + ck_assert_msg(check_msg->sol_in[108].flags == 46, + "incorrect value for sol_in[108].flags, expected 46, is %d", + check_msg->sol_in[108].flags); + ck_assert_msg( + check_msg->sol_in[108].sensor_type == 180, + "incorrect value for sol_in[108].sensor_type, expected 180, is %d", + check_msg->sol_in[108].sensor_type); + ck_assert_msg(check_msg->sol_in[109].flags == 130, + "incorrect value for sol_in[109].flags, expected 130, is %d", + check_msg->sol_in[109].flags); + ck_assert_msg( + check_msg->sol_in[109].sensor_type == 140, + "incorrect value for sol_in[109].sensor_type, expected 140, is %d", + check_msg->sol_in[109].sensor_type); + ck_assert_msg(check_msg->sol_in[110].flags == 17, + "incorrect value for sol_in[110].flags, expected 17, is %d", + check_msg->sol_in[110].flags); + ck_assert_msg( + check_msg->sol_in[110].sensor_type == 36, + "incorrect value for sol_in[110].sensor_type, expected 36, is %d", + check_msg->sol_in[110].sensor_type); + ck_assert_msg(check_msg->sol_in[111].flags == 209, + "incorrect value for sol_in[111].flags, expected 209, is %d", + check_msg->sol_in[111].flags); + ck_assert_msg( + check_msg->sol_in[111].sensor_type == 194, + "incorrect value for sol_in[111].sensor_type, expected 194, is %d", + check_msg->sol_in[111].sensor_type); + ck_assert_msg(check_msg->sol_in[112].flags == 254, + "incorrect value for sol_in[112].flags, expected 254, is %d", + check_msg->sol_in[112].flags); + ck_assert_msg( + check_msg->sol_in[112].sensor_type == 65, + "incorrect value for sol_in[112].sensor_type, expected 65, is %d", + check_msg->sol_in[112].sensor_type); + ck_assert_msg(check_msg->sol_in[113].flags == 103, + "incorrect value for sol_in[113].flags, expected 103, is %d", + check_msg->sol_in[113].flags); + ck_assert_msg( + check_msg->sol_in[113].sensor_type == 115, + "incorrect value for sol_in[113].sensor_type, expected 115, is %d", + check_msg->sol_in[113].sensor_type); + ck_assert_msg(check_msg->sol_in[114].flags == 129, + "incorrect value for sol_in[114].flags, expected 129, is %d", + check_msg->sol_in[114].flags); + ck_assert_msg( + check_msg->sol_in[114].sensor_type == 152, + "incorrect value for sol_in[114].sensor_type, expected 152, is %d", + check_msg->sol_in[114].sensor_type); + ck_assert_msg(check_msg->sol_in[115].flags == 235, + "incorrect value for sol_in[115].flags, expected 235, is %d", + check_msg->sol_in[115].flags); + ck_assert_msg( + check_msg->sol_in[115].sensor_type == 234, + "incorrect value for sol_in[115].sensor_type, expected 234, is %d", + check_msg->sol_in[115].sensor_type); + ck_assert_msg(check_msg->sol_in[116].flags == 234, + "incorrect value for sol_in[116].flags, expected 234, is %d", + check_msg->sol_in[116].flags); + ck_assert_msg( + check_msg->sol_in[116].sensor_type == 194, + "incorrect value for sol_in[116].sensor_type, expected 194, is %d", + check_msg->sol_in[116].sensor_type); + ck_assert_msg(check_msg->sol_in[117].flags == 201, + "incorrect value for sol_in[117].flags, expected 201, is %d", + check_msg->sol_in[117].flags); + ck_assert_msg( + check_msg->sol_in[117].sensor_type == 170, + "incorrect value for sol_in[117].sensor_type, expected 170, is %d", + check_msg->sol_in[117].sensor_type); + ck_assert_msg(check_msg->sol_in[118].flags == 154, + "incorrect value for sol_in[118].flags, expected 154, is %d", + check_msg->sol_in[118].flags); + ck_assert_msg( + check_msg->sol_in[118].sensor_type == 210, + "incorrect value for sol_in[118].sensor_type, expected 210, is %d", + check_msg->sol_in[118].sensor_type); + ck_assert_msg(check_msg->tow == 3628191792, + "incorrect value for tow, expected 3628191792, is %d", + check_msg->tow); + ck_assert_msg(check_msg->vdop == 58512, + "incorrect value for vdop, expected 58512, is %d", + check_msg->vdop); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_solution_meta_MsgSolnMeta_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_solution_meta_MsgSolnMeta"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_solution_meta_MsgSolnMeta"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_solution_meta_MsgSolnMeta); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c b/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c new file mode 100644 index 0000000000..0b7efbfa52 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_solution_meta_MsgSolnMetaDepA.c @@ -0,0 +1,1790 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff0f, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff0f, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, + 190, 115, 93, 59, 103, 36, 83, 161, 156, 46, 253, 67, 87, 200, + 39, 250, 245, 242, 228, 72, 18, 222, 11, 88, 207, 218, 231, 13, + 226, 224, 22, 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, + 146, 40, 204, 51, 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, + 240, 190, 93, 219, 103, 42, 41, 182, 76, 222, 17, 23, 125, 31, + 18, 229, 28, 47, 214, 25, 100, 84, 106, 72, 48, 10, 222, 232, + 235, 73, 109, 163, 51, 152, 133, 235, 87, 70, 2, 108, 91, 101, + 200, 55, 24, 156, 233, 73, 39, 66, 97, 140, 252, 227, 230, 237, + 135, 241, 245, 205, 70, 0, 219, 188, 107, 136, 178, 58, 1, 29, + 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, 203, 18, 3, 222, + 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, 159, 174, 121, + 112, 167, 240, 40, 59, 3, 230, 52, 149, 148, 218, 142, 212, 109, + 176, 71, 179, 172, 77, 1, 193, 70, 147, 149, 23, 144, 148, 239, + 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, 222, 222, + 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, + 106, 236, 93, 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, + 221, 185, 202, 21, 252, 51, 130, 59, 166, 202, 127, 170, 58, 193, + 215, 125, 22, 58, 135, 47, 88, 142, 77, 211, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_soln_meta_dep_a_t *test_msg = (msg_soln_meta_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->age_corrections = 48671; + test_msg->alignment_status = 115; + test_msg->hdop = 31133; + test_msg->last_used_gnss_pos_tow = 610745181; + test_msg->last_used_gnss_vel_tow = 782016851; + test_msg->n_sats = 238; + test_msg->pdop = 57015; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[0].flags = 67; + test_msg->sol_in[0].sensor_type = 253; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[1].flags = 200; + test_msg->sol_in[1].sensor_type = 87; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[2].flags = 250; + test_msg->sol_in[2].sensor_type = 39; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[3].flags = 242; + test_msg->sol_in[3].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[4].flags = 72; + test_msg->sol_in[4].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[5].flags = 222; + test_msg->sol_in[5].sensor_type = 18; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[6].flags = 88; + test_msg->sol_in[6].sensor_type = 11; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[7].flags = 218; + test_msg->sol_in[7].sensor_type = 207; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[8].flags = 13; + test_msg->sol_in[8].sensor_type = 231; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[9].flags = 224; + test_msg->sol_in[9].sensor_type = 226; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[10].flags = 196; + test_msg->sol_in[10].sensor_type = 22; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[11].flags = 242; + test_msg->sol_in[11].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[12].flags = 89; + test_msg->sol_in[12].sensor_type = 12; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[13].flags = 219; + test_msg->sol_in[13].sensor_type = 71; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[14].flags = 85; + test_msg->sol_in[14].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[15].flags = 204; + test_msg->sol_in[15].sensor_type = 145; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[16].flags = 40; + test_msg->sol_in[16].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[17].flags = 51; + test_msg->sol_in[17].sensor_type = 204; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[18].flags = 153; + test_msg->sol_in[18].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[19].flags = 44; + test_msg->sol_in[19].sensor_type = 227; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[20].flags = 28; + test_msg->sol_in[20].sensor_type = 15; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[21].flags = 39; + test_msg->sol_in[21].sensor_type = 255; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[22].flags = 216; + test_msg->sol_in[22].sensor_type = 205; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[23].flags = 190; + test_msg->sol_in[23].sensor_type = 240; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[24].flags = 219; + test_msg->sol_in[24].sensor_type = 93; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[25].flags = 42; + test_msg->sol_in[25].sensor_type = 103; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[26].flags = 182; + test_msg->sol_in[26].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[27].flags = 222; + test_msg->sol_in[27].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[28].flags = 23; + test_msg->sol_in[28].sensor_type = 17; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[29].flags = 31; + test_msg->sol_in[29].sensor_type = 125; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[30].flags = 229; + test_msg->sol_in[30].sensor_type = 18; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[31].flags = 47; + test_msg->sol_in[31].sensor_type = 28; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[32].flags = 25; + test_msg->sol_in[32].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[33].flags = 84; + test_msg->sol_in[33].sensor_type = 100; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[34].flags = 72; + test_msg->sol_in[34].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[35].flags = 10; + test_msg->sol_in[35].sensor_type = 48; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[36].flags = 232; + test_msg->sol_in[36].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[37].flags = 73; + test_msg->sol_in[37].sensor_type = 235; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[38].flags = 163; + test_msg->sol_in[38].sensor_type = 109; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[39].flags = 152; + test_msg->sol_in[39].sensor_type = 51; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[40].flags = 235; + test_msg->sol_in[40].sensor_type = 133; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[41].flags = 70; + test_msg->sol_in[41].sensor_type = 87; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[42].flags = 108; + test_msg->sol_in[42].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[43].flags = 101; + test_msg->sol_in[43].sensor_type = 91; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[44].flags = 55; + test_msg->sol_in[44].sensor_type = 200; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[45].flags = 156; + test_msg->sol_in[45].sensor_type = 24; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[46].flags = 73; + test_msg->sol_in[46].sensor_type = 233; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[47].flags = 66; + test_msg->sol_in[47].sensor_type = 39; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[48].flags = 140; + test_msg->sol_in[48].sensor_type = 97; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[49].flags = 227; + test_msg->sol_in[49].sensor_type = 252; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[50].flags = 237; + test_msg->sol_in[50].sensor_type = 230; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[51].flags = 241; + test_msg->sol_in[51].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[52].flags = 205; + test_msg->sol_in[52].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[53].flags = 0; + test_msg->sol_in[53].sensor_type = 70; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[54].flags = 188; + test_msg->sol_in[54].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[55].flags = 136; + test_msg->sol_in[55].sensor_type = 107; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[56].flags = 58; + test_msg->sol_in[56].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[57].flags = 29; + test_msg->sol_in[57].sensor_type = 1; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[58].flags = 213; + test_msg->sol_in[58].sensor_type = 44; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[59].flags = 147; + test_msg->sol_in[59].sensor_type = 225; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[60].flags = 96; + test_msg->sol_in[60].sensor_type = 190; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[61].flags = 108; + test_msg->sol_in[61].sensor_type = 192; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[62].flags = 15; + test_msg->sol_in[62].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[63].flags = 18; + test_msg->sol_in[63].sensor_type = 203; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[64].flags = 222; + test_msg->sol_in[64].sensor_type = 3; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[65].flags = 68; + test_msg->sol_in[65].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[66].flags = 229; + test_msg->sol_in[66].sensor_type = 101; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[67].flags = 203; + test_msg->sol_in[67].sensor_type = 223; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[68].flags = 164; + test_msg->sol_in[68].sensor_type = 243; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[69].flags = 165; + test_msg->sol_in[69].sensor_type = 92; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[70].flags = 159; + test_msg->sol_in[70].sensor_type = 220; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[71].flags = 121; + test_msg->sol_in[71].sensor_type = 174; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[72].flags = 167; + test_msg->sol_in[72].sensor_type = 112; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[73].flags = 40; + test_msg->sol_in[73].sensor_type = 240; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[74].flags = 3; + test_msg->sol_in[74].sensor_type = 59; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[75].flags = 52; + test_msg->sol_in[75].sensor_type = 230; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[76].flags = 148; + test_msg->sol_in[76].sensor_type = 149; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[77].flags = 142; + test_msg->sol_in[77].sensor_type = 218; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[78].flags = 109; + test_msg->sol_in[78].sensor_type = 212; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[79].flags = 71; + test_msg->sol_in[79].sensor_type = 176; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[80].flags = 172; + test_msg->sol_in[80].sensor_type = 179; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[81].flags = 1; + test_msg->sol_in[81].sensor_type = 77; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[82].flags = 70; + test_msg->sol_in[82].sensor_type = 193; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[83].flags = 149; + test_msg->sol_in[83].sensor_type = 147; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[84].flags = 144; + test_msg->sol_in[84].sensor_type = 23; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[85].flags = 239; + test_msg->sol_in[85].sensor_type = 148; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[86].flags = 186; + test_msg->sol_in[86].sensor_type = 195; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[87].flags = 30; + test_msg->sol_in[87].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[88].flags = 143; + test_msg->sol_in[88].sensor_type = 34; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[89].flags = 207; + test_msg->sol_in[89].sensor_type = 156; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[90].flags = 55; + test_msg->sol_in[90].sensor_type = 63; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[91].flags = 255; + test_msg->sol_in[91].sensor_type = 117; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[92].flags = 222; + test_msg->sol_in[92].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[93].flags = 145; + test_msg->sol_in[93].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[94].flags = 191; + test_msg->sol_in[94].sensor_type = 224; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[95].flags = 109; + test_msg->sol_in[95].sensor_type = 210; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[96].flags = 153; + test_msg->sol_in[96].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[97].flags = 32; + test_msg->sol_in[97].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[98].flags = 10; + test_msg->sol_in[98].sensor_type = 226; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[99].flags = 63; + test_msg->sol_in[99].sensor_type = 60; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[100].flags = 236; + test_msg->sol_in[100].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[101].flags = 96; + test_msg->sol_in[101].sensor_type = 93; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[102].flags = 163; + test_msg->sol_in[102].sensor_type = 30; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[103].flags = 238; + test_msg->sol_in[103].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[104].flags = 133; + test_msg->sol_in[104].sensor_type = 147; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[105].flags = 107; + test_msg->sol_in[105].sensor_type = 132; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[106].flags = 214; + test_msg->sol_in[106].sensor_type = 152; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[107].flags = 185; + test_msg->sol_in[107].sensor_type = 221; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[108].flags = 21; + test_msg->sol_in[108].sensor_type = 202; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[109].flags = 51; + test_msg->sol_in[109].sensor_type = 252; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[110].flags = 59; + test_msg->sol_in[110].sensor_type = 130; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[111].flags = 202; + test_msg->sol_in[111].sensor_type = 166; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[112].flags = 170; + test_msg->sol_in[112].sensor_type = 127; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[113].flags = 193; + test_msg->sol_in[113].sensor_type = 58; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[114].flags = 125; + test_msg->sol_in[114].sensor_type = 215; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[115].flags = 58; + test_msg->sol_in[115].sensor_type = 22; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[116].flags = 47; + test_msg->sol_in[116].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->sol_in[0]); + } + test_msg->sol_in[117].flags = 142; + test_msg->sol_in[117].sensor_type = 88; + test_msg->vdop = 41989; + sbp_payload_send(&sbp_state, 0xff0f, 61780, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61780, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 61780, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff0f, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_soln_meta_dep_a_t *check_msg = + (msg_soln_meta_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->age_corrections == 48671, + "incorrect value for age_corrections, expected 48671, is %d", + check_msg->age_corrections); + ck_assert_msg(check_msg->alignment_status == 115, + "incorrect value for alignment_status, expected 115, is %d", + check_msg->alignment_status); + ck_assert_msg(check_msg->hdop == 31133, + "incorrect value for hdop, expected 31133, is %d", + check_msg->hdop); + ck_assert_msg( + check_msg->last_used_gnss_pos_tow == 610745181, + "incorrect value for last_used_gnss_pos_tow, expected 610745181, is %d", + check_msg->last_used_gnss_pos_tow); + ck_assert_msg( + check_msg->last_used_gnss_vel_tow == 782016851, + "incorrect value for last_used_gnss_vel_tow, expected 782016851, is %d", + check_msg->last_used_gnss_vel_tow); + ck_assert_msg(check_msg->n_sats == 238, + "incorrect value for n_sats, expected 238, is %d", + check_msg->n_sats); + ck_assert_msg(check_msg->pdop == 57015, + "incorrect value for pdop, expected 57015, is %d", + check_msg->pdop); + ck_assert_msg(check_msg->sol_in[0].flags == 67, + "incorrect value for sol_in[0].flags, expected 67, is %d", + check_msg->sol_in[0].flags); + ck_assert_msg( + check_msg->sol_in[0].sensor_type == 253, + "incorrect value for sol_in[0].sensor_type, expected 253, is %d", + check_msg->sol_in[0].sensor_type); + ck_assert_msg(check_msg->sol_in[1].flags == 200, + "incorrect value for sol_in[1].flags, expected 200, is %d", + check_msg->sol_in[1].flags); + ck_assert_msg( + check_msg->sol_in[1].sensor_type == 87, + "incorrect value for sol_in[1].sensor_type, expected 87, is %d", + check_msg->sol_in[1].sensor_type); + ck_assert_msg(check_msg->sol_in[2].flags == 250, + "incorrect value for sol_in[2].flags, expected 250, is %d", + check_msg->sol_in[2].flags); + ck_assert_msg( + check_msg->sol_in[2].sensor_type == 39, + "incorrect value for sol_in[2].sensor_type, expected 39, is %d", + check_msg->sol_in[2].sensor_type); + ck_assert_msg(check_msg->sol_in[3].flags == 242, + "incorrect value for sol_in[3].flags, expected 242, is %d", + check_msg->sol_in[3].flags); + ck_assert_msg( + check_msg->sol_in[3].sensor_type == 245, + "incorrect value for sol_in[3].sensor_type, expected 245, is %d", + check_msg->sol_in[3].sensor_type); + ck_assert_msg(check_msg->sol_in[4].flags == 72, + "incorrect value for sol_in[4].flags, expected 72, is %d", + check_msg->sol_in[4].flags); + ck_assert_msg( + check_msg->sol_in[4].sensor_type == 228, + "incorrect value for sol_in[4].sensor_type, expected 228, is %d", + check_msg->sol_in[4].sensor_type); + ck_assert_msg(check_msg->sol_in[5].flags == 222, + "incorrect value for sol_in[5].flags, expected 222, is %d", + check_msg->sol_in[5].flags); + ck_assert_msg( + check_msg->sol_in[5].sensor_type == 18, + "incorrect value for sol_in[5].sensor_type, expected 18, is %d", + check_msg->sol_in[5].sensor_type); + ck_assert_msg(check_msg->sol_in[6].flags == 88, + "incorrect value for sol_in[6].flags, expected 88, is %d", + check_msg->sol_in[6].flags); + ck_assert_msg( + check_msg->sol_in[6].sensor_type == 11, + "incorrect value for sol_in[6].sensor_type, expected 11, is %d", + check_msg->sol_in[6].sensor_type); + ck_assert_msg(check_msg->sol_in[7].flags == 218, + "incorrect value for sol_in[7].flags, expected 218, is %d", + check_msg->sol_in[7].flags); + ck_assert_msg( + check_msg->sol_in[7].sensor_type == 207, + "incorrect value for sol_in[7].sensor_type, expected 207, is %d", + check_msg->sol_in[7].sensor_type); + ck_assert_msg(check_msg->sol_in[8].flags == 13, + "incorrect value for sol_in[8].flags, expected 13, is %d", + check_msg->sol_in[8].flags); + ck_assert_msg( + check_msg->sol_in[8].sensor_type == 231, + "incorrect value for sol_in[8].sensor_type, expected 231, is %d", + check_msg->sol_in[8].sensor_type); + ck_assert_msg(check_msg->sol_in[9].flags == 224, + "incorrect value for sol_in[9].flags, expected 224, is %d", + check_msg->sol_in[9].flags); + ck_assert_msg( + check_msg->sol_in[9].sensor_type == 226, + "incorrect value for sol_in[9].sensor_type, expected 226, is %d", + check_msg->sol_in[9].sensor_type); + ck_assert_msg(check_msg->sol_in[10].flags == 196, + "incorrect value for sol_in[10].flags, expected 196, is %d", + check_msg->sol_in[10].flags); + ck_assert_msg( + check_msg->sol_in[10].sensor_type == 22, + "incorrect value for sol_in[10].sensor_type, expected 22, is %d", + check_msg->sol_in[10].sensor_type); + ck_assert_msg(check_msg->sol_in[11].flags == 242, + "incorrect value for sol_in[11].flags, expected 242, is %d", + check_msg->sol_in[11].flags); + ck_assert_msg( + check_msg->sol_in[11].sensor_type == 21, + "incorrect value for sol_in[11].sensor_type, expected 21, is %d", + check_msg->sol_in[11].sensor_type); + ck_assert_msg(check_msg->sol_in[12].flags == 89, + "incorrect value for sol_in[12].flags, expected 89, is %d", + check_msg->sol_in[12].flags); + ck_assert_msg( + check_msg->sol_in[12].sensor_type == 12, + "incorrect value for sol_in[12].sensor_type, expected 12, is %d", + check_msg->sol_in[12].sensor_type); + ck_assert_msg(check_msg->sol_in[13].flags == 219, + "incorrect value for sol_in[13].flags, expected 219, is %d", + check_msg->sol_in[13].flags); + ck_assert_msg( + check_msg->sol_in[13].sensor_type == 71, + "incorrect value for sol_in[13].sensor_type, expected 71, is %d", + check_msg->sol_in[13].sensor_type); + ck_assert_msg(check_msg->sol_in[14].flags == 85, + "incorrect value for sol_in[14].flags, expected 85, is %d", + check_msg->sol_in[14].flags); + ck_assert_msg( + check_msg->sol_in[14].sensor_type == 182, + "incorrect value for sol_in[14].sensor_type, expected 182, is %d", + check_msg->sol_in[14].sensor_type); + ck_assert_msg(check_msg->sol_in[15].flags == 204, + "incorrect value for sol_in[15].flags, expected 204, is %d", + check_msg->sol_in[15].flags); + ck_assert_msg( + check_msg->sol_in[15].sensor_type == 145, + "incorrect value for sol_in[15].sensor_type, expected 145, is %d", + check_msg->sol_in[15].sensor_type); + ck_assert_msg(check_msg->sol_in[16].flags == 40, + "incorrect value for sol_in[16].flags, expected 40, is %d", + check_msg->sol_in[16].flags); + ck_assert_msg( + check_msg->sol_in[16].sensor_type == 146, + "incorrect value for sol_in[16].sensor_type, expected 146, is %d", + check_msg->sol_in[16].sensor_type); + ck_assert_msg(check_msg->sol_in[17].flags == 51, + "incorrect value for sol_in[17].flags, expected 51, is %d", + check_msg->sol_in[17].flags); + ck_assert_msg( + check_msg->sol_in[17].sensor_type == 204, + "incorrect value for sol_in[17].sensor_type, expected 204, is %d", + check_msg->sol_in[17].sensor_type); + ck_assert_msg(check_msg->sol_in[18].flags == 153, + "incorrect value for sol_in[18].flags, expected 153, is %d", + check_msg->sol_in[18].flags); + ck_assert_msg( + check_msg->sol_in[18].sensor_type == 21, + "incorrect value for sol_in[18].sensor_type, expected 21, is %d", + check_msg->sol_in[18].sensor_type); + ck_assert_msg(check_msg->sol_in[19].flags == 44, + "incorrect value for sol_in[19].flags, expected 44, is %d", + check_msg->sol_in[19].flags); + ck_assert_msg( + check_msg->sol_in[19].sensor_type == 227, + "incorrect value for sol_in[19].sensor_type, expected 227, is %d", + check_msg->sol_in[19].sensor_type); + ck_assert_msg(check_msg->sol_in[20].flags == 28, + "incorrect value for sol_in[20].flags, expected 28, is %d", + check_msg->sol_in[20].flags); + ck_assert_msg( + check_msg->sol_in[20].sensor_type == 15, + "incorrect value for sol_in[20].sensor_type, expected 15, is %d", + check_msg->sol_in[20].sensor_type); + ck_assert_msg(check_msg->sol_in[21].flags == 39, + "incorrect value for sol_in[21].flags, expected 39, is %d", + check_msg->sol_in[21].flags); + ck_assert_msg( + check_msg->sol_in[21].sensor_type == 255, + "incorrect value for sol_in[21].sensor_type, expected 255, is %d", + check_msg->sol_in[21].sensor_type); + ck_assert_msg(check_msg->sol_in[22].flags == 216, + "incorrect value for sol_in[22].flags, expected 216, is %d", + check_msg->sol_in[22].flags); + ck_assert_msg( + check_msg->sol_in[22].sensor_type == 205, + "incorrect value for sol_in[22].sensor_type, expected 205, is %d", + check_msg->sol_in[22].sensor_type); + ck_assert_msg(check_msg->sol_in[23].flags == 190, + "incorrect value for sol_in[23].flags, expected 190, is %d", + check_msg->sol_in[23].flags); + ck_assert_msg( + check_msg->sol_in[23].sensor_type == 240, + "incorrect value for sol_in[23].sensor_type, expected 240, is %d", + check_msg->sol_in[23].sensor_type); + ck_assert_msg(check_msg->sol_in[24].flags == 219, + "incorrect value for sol_in[24].flags, expected 219, is %d", + check_msg->sol_in[24].flags); + ck_assert_msg( + check_msg->sol_in[24].sensor_type == 93, + "incorrect value for sol_in[24].sensor_type, expected 93, is %d", + check_msg->sol_in[24].sensor_type); + ck_assert_msg(check_msg->sol_in[25].flags == 42, + "incorrect value for sol_in[25].flags, expected 42, is %d", + check_msg->sol_in[25].flags); + ck_assert_msg( + check_msg->sol_in[25].sensor_type == 103, + "incorrect value for sol_in[25].sensor_type, expected 103, is %d", + check_msg->sol_in[25].sensor_type); + ck_assert_msg(check_msg->sol_in[26].flags == 182, + "incorrect value for sol_in[26].flags, expected 182, is %d", + check_msg->sol_in[26].flags); + ck_assert_msg( + check_msg->sol_in[26].sensor_type == 41, + "incorrect value for sol_in[26].sensor_type, expected 41, is %d", + check_msg->sol_in[26].sensor_type); + ck_assert_msg(check_msg->sol_in[27].flags == 222, + "incorrect value for sol_in[27].flags, expected 222, is %d", + check_msg->sol_in[27].flags); + ck_assert_msg( + check_msg->sol_in[27].sensor_type == 76, + "incorrect value for sol_in[27].sensor_type, expected 76, is %d", + check_msg->sol_in[27].sensor_type); + ck_assert_msg(check_msg->sol_in[28].flags == 23, + "incorrect value for sol_in[28].flags, expected 23, is %d", + check_msg->sol_in[28].flags); + ck_assert_msg( + check_msg->sol_in[28].sensor_type == 17, + "incorrect value for sol_in[28].sensor_type, expected 17, is %d", + check_msg->sol_in[28].sensor_type); + ck_assert_msg(check_msg->sol_in[29].flags == 31, + "incorrect value for sol_in[29].flags, expected 31, is %d", + check_msg->sol_in[29].flags); + ck_assert_msg( + check_msg->sol_in[29].sensor_type == 125, + "incorrect value for sol_in[29].sensor_type, expected 125, is %d", + check_msg->sol_in[29].sensor_type); + ck_assert_msg(check_msg->sol_in[30].flags == 229, + "incorrect value for sol_in[30].flags, expected 229, is %d", + check_msg->sol_in[30].flags); + ck_assert_msg( + check_msg->sol_in[30].sensor_type == 18, + "incorrect value for sol_in[30].sensor_type, expected 18, is %d", + check_msg->sol_in[30].sensor_type); + ck_assert_msg(check_msg->sol_in[31].flags == 47, + "incorrect value for sol_in[31].flags, expected 47, is %d", + check_msg->sol_in[31].flags); + ck_assert_msg( + check_msg->sol_in[31].sensor_type == 28, + "incorrect value for sol_in[31].sensor_type, expected 28, is %d", + check_msg->sol_in[31].sensor_type); + ck_assert_msg(check_msg->sol_in[32].flags == 25, + "incorrect value for sol_in[32].flags, expected 25, is %d", + check_msg->sol_in[32].flags); + ck_assert_msg( + check_msg->sol_in[32].sensor_type == 214, + "incorrect value for sol_in[32].sensor_type, expected 214, is %d", + check_msg->sol_in[32].sensor_type); + ck_assert_msg(check_msg->sol_in[33].flags == 84, + "incorrect value for sol_in[33].flags, expected 84, is %d", + check_msg->sol_in[33].flags); + ck_assert_msg( + check_msg->sol_in[33].sensor_type == 100, + "incorrect value for sol_in[33].sensor_type, expected 100, is %d", + check_msg->sol_in[33].sensor_type); + ck_assert_msg(check_msg->sol_in[34].flags == 72, + "incorrect value for sol_in[34].flags, expected 72, is %d", + check_msg->sol_in[34].flags); + ck_assert_msg( + check_msg->sol_in[34].sensor_type == 106, + "incorrect value for sol_in[34].sensor_type, expected 106, is %d", + check_msg->sol_in[34].sensor_type); + ck_assert_msg(check_msg->sol_in[35].flags == 10, + "incorrect value for sol_in[35].flags, expected 10, is %d", + check_msg->sol_in[35].flags); + ck_assert_msg( + check_msg->sol_in[35].sensor_type == 48, + "incorrect value for sol_in[35].sensor_type, expected 48, is %d", + check_msg->sol_in[35].sensor_type); + ck_assert_msg(check_msg->sol_in[36].flags == 232, + "incorrect value for sol_in[36].flags, expected 232, is %d", + check_msg->sol_in[36].flags); + ck_assert_msg( + check_msg->sol_in[36].sensor_type == 222, + "incorrect value for sol_in[36].sensor_type, expected 222, is %d", + check_msg->sol_in[36].sensor_type); + ck_assert_msg(check_msg->sol_in[37].flags == 73, + "incorrect value for sol_in[37].flags, expected 73, is %d", + check_msg->sol_in[37].flags); + ck_assert_msg( + check_msg->sol_in[37].sensor_type == 235, + "incorrect value for sol_in[37].sensor_type, expected 235, is %d", + check_msg->sol_in[37].sensor_type); + ck_assert_msg(check_msg->sol_in[38].flags == 163, + "incorrect value for sol_in[38].flags, expected 163, is %d", + check_msg->sol_in[38].flags); + ck_assert_msg( + check_msg->sol_in[38].sensor_type == 109, + "incorrect value for sol_in[38].sensor_type, expected 109, is %d", + check_msg->sol_in[38].sensor_type); + ck_assert_msg(check_msg->sol_in[39].flags == 152, + "incorrect value for sol_in[39].flags, expected 152, is %d", + check_msg->sol_in[39].flags); + ck_assert_msg( + check_msg->sol_in[39].sensor_type == 51, + "incorrect value for sol_in[39].sensor_type, expected 51, is %d", + check_msg->sol_in[39].sensor_type); + ck_assert_msg(check_msg->sol_in[40].flags == 235, + "incorrect value for sol_in[40].flags, expected 235, is %d", + check_msg->sol_in[40].flags); + ck_assert_msg( + check_msg->sol_in[40].sensor_type == 133, + "incorrect value for sol_in[40].sensor_type, expected 133, is %d", + check_msg->sol_in[40].sensor_type); + ck_assert_msg(check_msg->sol_in[41].flags == 70, + "incorrect value for sol_in[41].flags, expected 70, is %d", + check_msg->sol_in[41].flags); + ck_assert_msg( + check_msg->sol_in[41].sensor_type == 87, + "incorrect value for sol_in[41].sensor_type, expected 87, is %d", + check_msg->sol_in[41].sensor_type); + ck_assert_msg(check_msg->sol_in[42].flags == 108, + "incorrect value for sol_in[42].flags, expected 108, is %d", + check_msg->sol_in[42].flags); + ck_assert_msg( + check_msg->sol_in[42].sensor_type == 2, + "incorrect value for sol_in[42].sensor_type, expected 2, is %d", + check_msg->sol_in[42].sensor_type); + ck_assert_msg(check_msg->sol_in[43].flags == 101, + "incorrect value for sol_in[43].flags, expected 101, is %d", + check_msg->sol_in[43].flags); + ck_assert_msg( + check_msg->sol_in[43].sensor_type == 91, + "incorrect value for sol_in[43].sensor_type, expected 91, is %d", + check_msg->sol_in[43].sensor_type); + ck_assert_msg(check_msg->sol_in[44].flags == 55, + "incorrect value for sol_in[44].flags, expected 55, is %d", + check_msg->sol_in[44].flags); + ck_assert_msg( + check_msg->sol_in[44].sensor_type == 200, + "incorrect value for sol_in[44].sensor_type, expected 200, is %d", + check_msg->sol_in[44].sensor_type); + ck_assert_msg(check_msg->sol_in[45].flags == 156, + "incorrect value for sol_in[45].flags, expected 156, is %d", + check_msg->sol_in[45].flags); + ck_assert_msg( + check_msg->sol_in[45].sensor_type == 24, + "incorrect value for sol_in[45].sensor_type, expected 24, is %d", + check_msg->sol_in[45].sensor_type); + ck_assert_msg(check_msg->sol_in[46].flags == 73, + "incorrect value for sol_in[46].flags, expected 73, is %d", + check_msg->sol_in[46].flags); + ck_assert_msg( + check_msg->sol_in[46].sensor_type == 233, + "incorrect value for sol_in[46].sensor_type, expected 233, is %d", + check_msg->sol_in[46].sensor_type); + ck_assert_msg(check_msg->sol_in[47].flags == 66, + "incorrect value for sol_in[47].flags, expected 66, is %d", + check_msg->sol_in[47].flags); + ck_assert_msg( + check_msg->sol_in[47].sensor_type == 39, + "incorrect value for sol_in[47].sensor_type, expected 39, is %d", + check_msg->sol_in[47].sensor_type); + ck_assert_msg(check_msg->sol_in[48].flags == 140, + "incorrect value for sol_in[48].flags, expected 140, is %d", + check_msg->sol_in[48].flags); + ck_assert_msg( + check_msg->sol_in[48].sensor_type == 97, + "incorrect value for sol_in[48].sensor_type, expected 97, is %d", + check_msg->sol_in[48].sensor_type); + ck_assert_msg(check_msg->sol_in[49].flags == 227, + "incorrect value for sol_in[49].flags, expected 227, is %d", + check_msg->sol_in[49].flags); + ck_assert_msg( + check_msg->sol_in[49].sensor_type == 252, + "incorrect value for sol_in[49].sensor_type, expected 252, is %d", + check_msg->sol_in[49].sensor_type); + ck_assert_msg(check_msg->sol_in[50].flags == 237, + "incorrect value for sol_in[50].flags, expected 237, is %d", + check_msg->sol_in[50].flags); + ck_assert_msg( + check_msg->sol_in[50].sensor_type == 230, + "incorrect value for sol_in[50].sensor_type, expected 230, is %d", + check_msg->sol_in[50].sensor_type); + ck_assert_msg(check_msg->sol_in[51].flags == 241, + "incorrect value for sol_in[51].flags, expected 241, is %d", + check_msg->sol_in[51].flags); + ck_assert_msg( + check_msg->sol_in[51].sensor_type == 135, + "incorrect value for sol_in[51].sensor_type, expected 135, is %d", + check_msg->sol_in[51].sensor_type); + ck_assert_msg(check_msg->sol_in[52].flags == 205, + "incorrect value for sol_in[52].flags, expected 205, is %d", + check_msg->sol_in[52].flags); + ck_assert_msg( + check_msg->sol_in[52].sensor_type == 245, + "incorrect value for sol_in[52].sensor_type, expected 245, is %d", + check_msg->sol_in[52].sensor_type); + ck_assert_msg(check_msg->sol_in[53].flags == 0, + "incorrect value for sol_in[53].flags, expected 0, is %d", + check_msg->sol_in[53].flags); + ck_assert_msg( + check_msg->sol_in[53].sensor_type == 70, + "incorrect value for sol_in[53].sensor_type, expected 70, is %d", + check_msg->sol_in[53].sensor_type); + ck_assert_msg(check_msg->sol_in[54].flags == 188, + "incorrect value for sol_in[54].flags, expected 188, is %d", + check_msg->sol_in[54].flags); + ck_assert_msg( + check_msg->sol_in[54].sensor_type == 219, + "incorrect value for sol_in[54].sensor_type, expected 219, is %d", + check_msg->sol_in[54].sensor_type); + ck_assert_msg(check_msg->sol_in[55].flags == 136, + "incorrect value for sol_in[55].flags, expected 136, is %d", + check_msg->sol_in[55].flags); + ck_assert_msg( + check_msg->sol_in[55].sensor_type == 107, + "incorrect value for sol_in[55].sensor_type, expected 107, is %d", + check_msg->sol_in[55].sensor_type); + ck_assert_msg(check_msg->sol_in[56].flags == 58, + "incorrect value for sol_in[56].flags, expected 58, is %d", + check_msg->sol_in[56].flags); + ck_assert_msg( + check_msg->sol_in[56].sensor_type == 178, + "incorrect value for sol_in[56].sensor_type, expected 178, is %d", + check_msg->sol_in[56].sensor_type); + ck_assert_msg(check_msg->sol_in[57].flags == 29, + "incorrect value for sol_in[57].flags, expected 29, is %d", + check_msg->sol_in[57].flags); + ck_assert_msg( + check_msg->sol_in[57].sensor_type == 1, + "incorrect value for sol_in[57].sensor_type, expected 1, is %d", + check_msg->sol_in[57].sensor_type); + ck_assert_msg(check_msg->sol_in[58].flags == 213, + "incorrect value for sol_in[58].flags, expected 213, is %d", + check_msg->sol_in[58].flags); + ck_assert_msg( + check_msg->sol_in[58].sensor_type == 44, + "incorrect value for sol_in[58].sensor_type, expected 44, is %d", + check_msg->sol_in[58].sensor_type); + ck_assert_msg(check_msg->sol_in[59].flags == 147, + "incorrect value for sol_in[59].flags, expected 147, is %d", + check_msg->sol_in[59].flags); + ck_assert_msg( + check_msg->sol_in[59].sensor_type == 225, + "incorrect value for sol_in[59].sensor_type, expected 225, is %d", + check_msg->sol_in[59].sensor_type); + ck_assert_msg(check_msg->sol_in[60].flags == 96, + "incorrect value for sol_in[60].flags, expected 96, is %d", + check_msg->sol_in[60].flags); + ck_assert_msg( + check_msg->sol_in[60].sensor_type == 190, + "incorrect value for sol_in[60].sensor_type, expected 190, is %d", + check_msg->sol_in[60].sensor_type); + ck_assert_msg(check_msg->sol_in[61].flags == 108, + "incorrect value for sol_in[61].flags, expected 108, is %d", + check_msg->sol_in[61].flags); + ck_assert_msg( + check_msg->sol_in[61].sensor_type == 192, + "incorrect value for sol_in[61].sensor_type, expected 192, is %d", + check_msg->sol_in[61].sensor_type); + ck_assert_msg(check_msg->sol_in[62].flags == 15, + "incorrect value for sol_in[62].flags, expected 15, is %d", + check_msg->sol_in[62].flags); + ck_assert_msg( + check_msg->sol_in[62].sensor_type == 228, + "incorrect value for sol_in[62].sensor_type, expected 228, is %d", + check_msg->sol_in[62].sensor_type); + ck_assert_msg(check_msg->sol_in[63].flags == 18, + "incorrect value for sol_in[63].flags, expected 18, is %d", + check_msg->sol_in[63].flags); + ck_assert_msg( + check_msg->sol_in[63].sensor_type == 203, + "incorrect value for sol_in[63].sensor_type, expected 203, is %d", + check_msg->sol_in[63].sensor_type); + ck_assert_msg(check_msg->sol_in[64].flags == 222, + "incorrect value for sol_in[64].flags, expected 222, is %d", + check_msg->sol_in[64].flags); + ck_assert_msg( + check_msg->sol_in[64].sensor_type == 3, + "incorrect value for sol_in[64].sensor_type, expected 3, is %d", + check_msg->sol_in[64].sensor_type); + ck_assert_msg(check_msg->sol_in[65].flags == 68, + "incorrect value for sol_in[65].flags, expected 68, is %d", + check_msg->sol_in[65].flags); + ck_assert_msg( + check_msg->sol_in[65].sensor_type == 180, + "incorrect value for sol_in[65].sensor_type, expected 180, is %d", + check_msg->sol_in[65].sensor_type); + ck_assert_msg(check_msg->sol_in[66].flags == 229, + "incorrect value for sol_in[66].flags, expected 229, is %d", + check_msg->sol_in[66].flags); + ck_assert_msg( + check_msg->sol_in[66].sensor_type == 101, + "incorrect value for sol_in[66].sensor_type, expected 101, is %d", + check_msg->sol_in[66].sensor_type); + ck_assert_msg(check_msg->sol_in[67].flags == 203, + "incorrect value for sol_in[67].flags, expected 203, is %d", + check_msg->sol_in[67].flags); + ck_assert_msg( + check_msg->sol_in[67].sensor_type == 223, + "incorrect value for sol_in[67].sensor_type, expected 223, is %d", + check_msg->sol_in[67].sensor_type); + ck_assert_msg(check_msg->sol_in[68].flags == 164, + "incorrect value for sol_in[68].flags, expected 164, is %d", + check_msg->sol_in[68].flags); + ck_assert_msg( + check_msg->sol_in[68].sensor_type == 243, + "incorrect value for sol_in[68].sensor_type, expected 243, is %d", + check_msg->sol_in[68].sensor_type); + ck_assert_msg(check_msg->sol_in[69].flags == 165, + "incorrect value for sol_in[69].flags, expected 165, is %d", + check_msg->sol_in[69].flags); + ck_assert_msg( + check_msg->sol_in[69].sensor_type == 92, + "incorrect value for sol_in[69].sensor_type, expected 92, is %d", + check_msg->sol_in[69].sensor_type); + ck_assert_msg(check_msg->sol_in[70].flags == 159, + "incorrect value for sol_in[70].flags, expected 159, is %d", + check_msg->sol_in[70].flags); + ck_assert_msg( + check_msg->sol_in[70].sensor_type == 220, + "incorrect value for sol_in[70].sensor_type, expected 220, is %d", + check_msg->sol_in[70].sensor_type); + ck_assert_msg(check_msg->sol_in[71].flags == 121, + "incorrect value for sol_in[71].flags, expected 121, is %d", + check_msg->sol_in[71].flags); + ck_assert_msg( + check_msg->sol_in[71].sensor_type == 174, + "incorrect value for sol_in[71].sensor_type, expected 174, is %d", + check_msg->sol_in[71].sensor_type); + ck_assert_msg(check_msg->sol_in[72].flags == 167, + "incorrect value for sol_in[72].flags, expected 167, is %d", + check_msg->sol_in[72].flags); + ck_assert_msg( + check_msg->sol_in[72].sensor_type == 112, + "incorrect value for sol_in[72].sensor_type, expected 112, is %d", + check_msg->sol_in[72].sensor_type); + ck_assert_msg(check_msg->sol_in[73].flags == 40, + "incorrect value for sol_in[73].flags, expected 40, is %d", + check_msg->sol_in[73].flags); + ck_assert_msg( + check_msg->sol_in[73].sensor_type == 240, + "incorrect value for sol_in[73].sensor_type, expected 240, is %d", + check_msg->sol_in[73].sensor_type); + ck_assert_msg(check_msg->sol_in[74].flags == 3, + "incorrect value for sol_in[74].flags, expected 3, is %d", + check_msg->sol_in[74].flags); + ck_assert_msg( + check_msg->sol_in[74].sensor_type == 59, + "incorrect value for sol_in[74].sensor_type, expected 59, is %d", + check_msg->sol_in[74].sensor_type); + ck_assert_msg(check_msg->sol_in[75].flags == 52, + "incorrect value for sol_in[75].flags, expected 52, is %d", + check_msg->sol_in[75].flags); + ck_assert_msg( + check_msg->sol_in[75].sensor_type == 230, + "incorrect value for sol_in[75].sensor_type, expected 230, is %d", + check_msg->sol_in[75].sensor_type); + ck_assert_msg(check_msg->sol_in[76].flags == 148, + "incorrect value for sol_in[76].flags, expected 148, is %d", + check_msg->sol_in[76].flags); + ck_assert_msg( + check_msg->sol_in[76].sensor_type == 149, + "incorrect value for sol_in[76].sensor_type, expected 149, is %d", + check_msg->sol_in[76].sensor_type); + ck_assert_msg(check_msg->sol_in[77].flags == 142, + "incorrect value for sol_in[77].flags, expected 142, is %d", + check_msg->sol_in[77].flags); + ck_assert_msg( + check_msg->sol_in[77].sensor_type == 218, + "incorrect value for sol_in[77].sensor_type, expected 218, is %d", + check_msg->sol_in[77].sensor_type); + ck_assert_msg(check_msg->sol_in[78].flags == 109, + "incorrect value for sol_in[78].flags, expected 109, is %d", + check_msg->sol_in[78].flags); + ck_assert_msg( + check_msg->sol_in[78].sensor_type == 212, + "incorrect value for sol_in[78].sensor_type, expected 212, is %d", + check_msg->sol_in[78].sensor_type); + ck_assert_msg(check_msg->sol_in[79].flags == 71, + "incorrect value for sol_in[79].flags, expected 71, is %d", + check_msg->sol_in[79].flags); + ck_assert_msg( + check_msg->sol_in[79].sensor_type == 176, + "incorrect value for sol_in[79].sensor_type, expected 176, is %d", + check_msg->sol_in[79].sensor_type); + ck_assert_msg(check_msg->sol_in[80].flags == 172, + "incorrect value for sol_in[80].flags, expected 172, is %d", + check_msg->sol_in[80].flags); + ck_assert_msg( + check_msg->sol_in[80].sensor_type == 179, + "incorrect value for sol_in[80].sensor_type, expected 179, is %d", + check_msg->sol_in[80].sensor_type); + ck_assert_msg(check_msg->sol_in[81].flags == 1, + "incorrect value for sol_in[81].flags, expected 1, is %d", + check_msg->sol_in[81].flags); + ck_assert_msg( + check_msg->sol_in[81].sensor_type == 77, + "incorrect value for sol_in[81].sensor_type, expected 77, is %d", + check_msg->sol_in[81].sensor_type); + ck_assert_msg(check_msg->sol_in[82].flags == 70, + "incorrect value for sol_in[82].flags, expected 70, is %d", + check_msg->sol_in[82].flags); + ck_assert_msg( + check_msg->sol_in[82].sensor_type == 193, + "incorrect value for sol_in[82].sensor_type, expected 193, is %d", + check_msg->sol_in[82].sensor_type); + ck_assert_msg(check_msg->sol_in[83].flags == 149, + "incorrect value for sol_in[83].flags, expected 149, is %d", + check_msg->sol_in[83].flags); + ck_assert_msg( + check_msg->sol_in[83].sensor_type == 147, + "incorrect value for sol_in[83].sensor_type, expected 147, is %d", + check_msg->sol_in[83].sensor_type); + ck_assert_msg(check_msg->sol_in[84].flags == 144, + "incorrect value for sol_in[84].flags, expected 144, is %d", + check_msg->sol_in[84].flags); + ck_assert_msg( + check_msg->sol_in[84].sensor_type == 23, + "incorrect value for sol_in[84].sensor_type, expected 23, is %d", + check_msg->sol_in[84].sensor_type); + ck_assert_msg(check_msg->sol_in[85].flags == 239, + "incorrect value for sol_in[85].flags, expected 239, is %d", + check_msg->sol_in[85].flags); + ck_assert_msg( + check_msg->sol_in[85].sensor_type == 148, + "incorrect value for sol_in[85].sensor_type, expected 148, is %d", + check_msg->sol_in[85].sensor_type); + ck_assert_msg(check_msg->sol_in[86].flags == 186, + "incorrect value for sol_in[86].flags, expected 186, is %d", + check_msg->sol_in[86].flags); + ck_assert_msg( + check_msg->sol_in[86].sensor_type == 195, + "incorrect value for sol_in[86].sensor_type, expected 195, is %d", + check_msg->sol_in[86].sensor_type); + ck_assert_msg(check_msg->sol_in[87].flags == 30, + "incorrect value for sol_in[87].flags, expected 30, is %d", + check_msg->sol_in[87].flags); + ck_assert_msg( + check_msg->sol_in[87].sensor_type == 86, + "incorrect value for sol_in[87].sensor_type, expected 86, is %d", + check_msg->sol_in[87].sensor_type); + ck_assert_msg(check_msg->sol_in[88].flags == 143, + "incorrect value for sol_in[88].flags, expected 143, is %d", + check_msg->sol_in[88].flags); + ck_assert_msg( + check_msg->sol_in[88].sensor_type == 34, + "incorrect value for sol_in[88].sensor_type, expected 34, is %d", + check_msg->sol_in[88].sensor_type); + ck_assert_msg(check_msg->sol_in[89].flags == 207, + "incorrect value for sol_in[89].flags, expected 207, is %d", + check_msg->sol_in[89].flags); + ck_assert_msg( + check_msg->sol_in[89].sensor_type == 156, + "incorrect value for sol_in[89].sensor_type, expected 156, is %d", + check_msg->sol_in[89].sensor_type); + ck_assert_msg(check_msg->sol_in[90].flags == 55, + "incorrect value for sol_in[90].flags, expected 55, is %d", + check_msg->sol_in[90].flags); + ck_assert_msg( + check_msg->sol_in[90].sensor_type == 63, + "incorrect value for sol_in[90].sensor_type, expected 63, is %d", + check_msg->sol_in[90].sensor_type); + ck_assert_msg(check_msg->sol_in[91].flags == 255, + "incorrect value for sol_in[91].flags, expected 255, is %d", + check_msg->sol_in[91].flags); + ck_assert_msg( + check_msg->sol_in[91].sensor_type == 117, + "incorrect value for sol_in[91].sensor_type, expected 117, is %d", + check_msg->sol_in[91].sensor_type); + ck_assert_msg(check_msg->sol_in[92].flags == 222, + "incorrect value for sol_in[92].flags, expected 222, is %d", + check_msg->sol_in[92].flags); + ck_assert_msg( + check_msg->sol_in[92].sensor_type == 222, + "incorrect value for sol_in[92].sensor_type, expected 222, is %d", + check_msg->sol_in[92].sensor_type); + ck_assert_msg(check_msg->sol_in[93].flags == 145, + "incorrect value for sol_in[93].flags, expected 145, is %d", + check_msg->sol_in[93].flags); + ck_assert_msg( + check_msg->sol_in[93].sensor_type == 219, + "incorrect value for sol_in[93].sensor_type, expected 219, is %d", + check_msg->sol_in[93].sensor_type); + ck_assert_msg(check_msg->sol_in[94].flags == 191, + "incorrect value for sol_in[94].flags, expected 191, is %d", + check_msg->sol_in[94].flags); + ck_assert_msg( + check_msg->sol_in[94].sensor_type == 224, + "incorrect value for sol_in[94].sensor_type, expected 224, is %d", + check_msg->sol_in[94].sensor_type); + ck_assert_msg(check_msg->sol_in[95].flags == 109, + "incorrect value for sol_in[95].flags, expected 109, is %d", + check_msg->sol_in[95].flags); + ck_assert_msg( + check_msg->sol_in[95].sensor_type == 210, + "incorrect value for sol_in[95].sensor_type, expected 210, is %d", + check_msg->sol_in[95].sensor_type); + ck_assert_msg(check_msg->sol_in[96].flags == 153, + "incorrect value for sol_in[96].flags, expected 153, is %d", + check_msg->sol_in[96].flags); + ck_assert_msg( + check_msg->sol_in[96].sensor_type == 86, + "incorrect value for sol_in[96].sensor_type, expected 86, is %d", + check_msg->sol_in[96].sensor_type); + ck_assert_msg(check_msg->sol_in[97].flags == 32, + "incorrect value for sol_in[97].flags, expected 32, is %d", + check_msg->sol_in[97].flags); + ck_assert_msg( + check_msg->sol_in[97].sensor_type == 21, + "incorrect value for sol_in[97].sensor_type, expected 21, is %d", + check_msg->sol_in[97].sensor_type); + ck_assert_msg(check_msg->sol_in[98].flags == 10, + "incorrect value for sol_in[98].flags, expected 10, is %d", + check_msg->sol_in[98].flags); + ck_assert_msg( + check_msg->sol_in[98].sensor_type == 226, + "incorrect value for sol_in[98].sensor_type, expected 226, is %d", + check_msg->sol_in[98].sensor_type); + ck_assert_msg(check_msg->sol_in[99].flags == 63, + "incorrect value for sol_in[99].flags, expected 63, is %d", + check_msg->sol_in[99].flags); + ck_assert_msg( + check_msg->sol_in[99].sensor_type == 60, + "incorrect value for sol_in[99].sensor_type, expected 60, is %d", + check_msg->sol_in[99].sensor_type); + ck_assert_msg(check_msg->sol_in[100].flags == 236, + "incorrect value for sol_in[100].flags, expected 236, is %d", + check_msg->sol_in[100].flags); + ck_assert_msg( + check_msg->sol_in[100].sensor_type == 106, + "incorrect value for sol_in[100].sensor_type, expected 106, is %d", + check_msg->sol_in[100].sensor_type); + ck_assert_msg(check_msg->sol_in[101].flags == 96, + "incorrect value for sol_in[101].flags, expected 96, is %d", + check_msg->sol_in[101].flags); + ck_assert_msg( + check_msg->sol_in[101].sensor_type == 93, + "incorrect value for sol_in[101].sensor_type, expected 93, is %d", + check_msg->sol_in[101].sensor_type); + ck_assert_msg(check_msg->sol_in[102].flags == 163, + "incorrect value for sol_in[102].flags, expected 163, is %d", + check_msg->sol_in[102].flags); + ck_assert_msg( + check_msg->sol_in[102].sensor_type == 30, + "incorrect value for sol_in[102].sensor_type, expected 30, is %d", + check_msg->sol_in[102].sensor_type); + ck_assert_msg(check_msg->sol_in[103].flags == 238, + "incorrect value for sol_in[103].flags, expected 238, is %d", + check_msg->sol_in[103].flags); + ck_assert_msg( + check_msg->sol_in[103].sensor_type == 106, + "incorrect value for sol_in[103].sensor_type, expected 106, is %d", + check_msg->sol_in[103].sensor_type); + ck_assert_msg(check_msg->sol_in[104].flags == 133, + "incorrect value for sol_in[104].flags, expected 133, is %d", + check_msg->sol_in[104].flags); + ck_assert_msg( + check_msg->sol_in[104].sensor_type == 147, + "incorrect value for sol_in[104].sensor_type, expected 147, is %d", + check_msg->sol_in[104].sensor_type); + ck_assert_msg(check_msg->sol_in[105].flags == 107, + "incorrect value for sol_in[105].flags, expected 107, is %d", + check_msg->sol_in[105].flags); + ck_assert_msg( + check_msg->sol_in[105].sensor_type == 132, + "incorrect value for sol_in[105].sensor_type, expected 132, is %d", + check_msg->sol_in[105].sensor_type); + ck_assert_msg(check_msg->sol_in[106].flags == 214, + "incorrect value for sol_in[106].flags, expected 214, is %d", + check_msg->sol_in[106].flags); + ck_assert_msg( + check_msg->sol_in[106].sensor_type == 152, + "incorrect value for sol_in[106].sensor_type, expected 152, is %d", + check_msg->sol_in[106].sensor_type); + ck_assert_msg(check_msg->sol_in[107].flags == 185, + "incorrect value for sol_in[107].flags, expected 185, is %d", + check_msg->sol_in[107].flags); + ck_assert_msg( + check_msg->sol_in[107].sensor_type == 221, + "incorrect value for sol_in[107].sensor_type, expected 221, is %d", + check_msg->sol_in[107].sensor_type); + ck_assert_msg(check_msg->sol_in[108].flags == 21, + "incorrect value for sol_in[108].flags, expected 21, is %d", + check_msg->sol_in[108].flags); + ck_assert_msg( + check_msg->sol_in[108].sensor_type == 202, + "incorrect value for sol_in[108].sensor_type, expected 202, is %d", + check_msg->sol_in[108].sensor_type); + ck_assert_msg(check_msg->sol_in[109].flags == 51, + "incorrect value for sol_in[109].flags, expected 51, is %d", + check_msg->sol_in[109].flags); + ck_assert_msg( + check_msg->sol_in[109].sensor_type == 252, + "incorrect value for sol_in[109].sensor_type, expected 252, is %d", + check_msg->sol_in[109].sensor_type); + ck_assert_msg(check_msg->sol_in[110].flags == 59, + "incorrect value for sol_in[110].flags, expected 59, is %d", + check_msg->sol_in[110].flags); + ck_assert_msg( + check_msg->sol_in[110].sensor_type == 130, + "incorrect value for sol_in[110].sensor_type, expected 130, is %d", + check_msg->sol_in[110].sensor_type); + ck_assert_msg(check_msg->sol_in[111].flags == 202, + "incorrect value for sol_in[111].flags, expected 202, is %d", + check_msg->sol_in[111].flags); + ck_assert_msg( + check_msg->sol_in[111].sensor_type == 166, + "incorrect value for sol_in[111].sensor_type, expected 166, is %d", + check_msg->sol_in[111].sensor_type); + ck_assert_msg(check_msg->sol_in[112].flags == 170, + "incorrect value for sol_in[112].flags, expected 170, is %d", + check_msg->sol_in[112].flags); + ck_assert_msg( + check_msg->sol_in[112].sensor_type == 127, + "incorrect value for sol_in[112].sensor_type, expected 127, is %d", + check_msg->sol_in[112].sensor_type); + ck_assert_msg(check_msg->sol_in[113].flags == 193, + "incorrect value for sol_in[113].flags, expected 193, is %d", + check_msg->sol_in[113].flags); + ck_assert_msg( + check_msg->sol_in[113].sensor_type == 58, + "incorrect value for sol_in[113].sensor_type, expected 58, is %d", + check_msg->sol_in[113].sensor_type); + ck_assert_msg(check_msg->sol_in[114].flags == 125, + "incorrect value for sol_in[114].flags, expected 125, is %d", + check_msg->sol_in[114].flags); + ck_assert_msg( + check_msg->sol_in[114].sensor_type == 215, + "incorrect value for sol_in[114].sensor_type, expected 215, is %d", + check_msg->sol_in[114].sensor_type); + ck_assert_msg(check_msg->sol_in[115].flags == 58, + "incorrect value for sol_in[115].flags, expected 58, is %d", + check_msg->sol_in[115].flags); + ck_assert_msg( + check_msg->sol_in[115].sensor_type == 22, + "incorrect value for sol_in[115].sensor_type, expected 22, is %d", + check_msg->sol_in[115].sensor_type); + ck_assert_msg(check_msg->sol_in[116].flags == 47, + "incorrect value for sol_in[116].flags, expected 47, is %d", + check_msg->sol_in[116].flags); + ck_assert_msg( + check_msg->sol_in[116].sensor_type == 135, + "incorrect value for sol_in[116].sensor_type, expected 135, is %d", + check_msg->sol_in[116].sensor_type); + ck_assert_msg(check_msg->sol_in[117].flags == 142, + "incorrect value for sol_in[117].flags, expected 142, is %d", + check_msg->sol_in[117].flags); + ck_assert_msg( + check_msg->sol_in[117].sensor_type == 88, + "incorrect value for sol_in[117].sensor_type, expected 88, is %d", + check_msg->sol_in[117].sensor_type); + ck_assert_msg(check_msg->vdop == 41989, + "incorrect value for vdop, expected 41989, is %d", + check_msg->vdop); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrCodeBiases.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrCodeBiases.c new file mode 100644 index 0000000000..8e008a8bfa --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrCodeBiases.c @@ -0,0 +1,1240 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5e1, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5e1, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, + 254, 132, 51, 4, 131, 240, 120, 83, 148, 209, 213, 62, 228, 232, + 71, 66, 188, 210, 128, 54, 131, 152, 129, 111, 139, 242, 177, 145, + 44, 9, 245, 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, + 98, 191, 23, 128, 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, + 209, 139, 13, 101, 32, 7, 18, 29, 70, 250, 109, 73, 202, 79, + 144, 9, 146, 69, 241, 52, 22, 99, 98, 204, 3, 171, 230, 180, + 75, 62, 145, 86, 130, 31, 30, 155, 37, 18, 55, 210, 39, 127, + 242, 66, 13, 237, 152, 170, 212, 15, 246, 59, 94, 180, 195, 157, + 69, 100, 119, 16, 68, 179, 175, 144, 113, 81, 82, 30, 151, 21, + 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, 6, 78, 81, 143, + 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, 247, 34, 97, + 74, 97, 176, 48, 236, 173, 12, 174, 101, 130, 30, 169, 193, 190, + 204, 196, 123, 107, 25, 225, 74, 9, 10, 55, 3, 131, 246, 99, + 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, + 10, 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, + 191, 120, 77, 192, 91, 224, 1, 226, 50, 87, 146, 148, 238, 100, + 179, 125, 227, 215, 104, 184, 31, 57, 90, 79, 21, 156, 245, 81, + 60, 93, 170, 60, 200, 167, 13, 125, 132, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_code_biases_t *test_msg = (msg_ssr_code_biases_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[0].code = 51; + test_msg->biases[0].value = -31996; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[1].code = 240; + test_msg->biases[1].value = 21368; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[2].code = 148; + test_msg->biases[2].value = -10799; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[3].code = 62; + test_msg->biases[3].value = -5916; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[4].code = 71; + test_msg->biases[4].value = -17342; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[5].code = 210; + test_msg->biases[5].value = 13952; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[6].code = 131; + test_msg->biases[6].value = -32360; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[7].code = 111; + test_msg->biases[7].value = -3445; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[8].code = 177; + test_msg->biases[8].value = 11409; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[9].code = 9; + test_msg->biases[9].value = -12299; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[10].code = 241; + test_msg->biases[10].value = -26934; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[11].code = 141; + test_msg->biases[11].value = -24782; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[12].code = 220; + test_msg->biases[12].value = 9611; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[13].code = 187; + test_msg->biases[13].value = -16542; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[14].code = 23; + test_msg->biases[14].value = -30592; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[15].code = 167; + test_msg->biases[15].value = 1736; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[16].code = 211; + test_msg->biases[16].value = 5978; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[17].code = 244; + test_msg->biases[17].value = -10358; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[18].code = 209; + test_msg->biases[18].value = 3467; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[19].code = 101; + test_msg->biases[19].value = 1824; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[20].code = 18; + test_msg->biases[20].value = 17949; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[21].code = 250; + test_msg->biases[21].value = 18797; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[22].code = 202; + test_msg->biases[22].value = -28593; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[23].code = 9; + test_msg->biases[23].value = 17810; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[24].code = 241; + test_msg->biases[24].value = 5684; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[25].code = 99; + test_msg->biases[25].value = -13214; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[26].code = 3; + test_msg->biases[26].value = -6485; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[27].code = 180; + test_msg->biases[27].value = 15947; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[28].code = 145; + test_msg->biases[28].value = -32170; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[29].code = 31; + test_msg->biases[29].value = -25826; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[30].code = 37; + test_msg->biases[30].value = 14098; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[31].code = 210; + test_msg->biases[31].value = 32551; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[32].code = 242; + test_msg->biases[32].value = 3394; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[33].code = 237; + test_msg->biases[33].value = -21864; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[34].code = 212; + test_msg->biases[34].value = -2545; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[35].code = 59; + test_msg->biases[35].value = -19362; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[36].code = 195; + test_msg->biases[36].value = 17821; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[37].code = 100; + test_msg->biases[37].value = 4215; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[38].code = 68; + test_msg->biases[38].value = -20557; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[39].code = 144; + test_msg->biases[39].value = 20849; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[40].code = 82; + test_msg->biases[40].value = -26850; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[41].code = 21; + test_msg->biases[41].value = 10605; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[42].code = 225; + test_msg->biases[42].value = 19720; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[43].code = 164; + test_msg->biases[43].value = 157; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[44].code = 73; + test_msg->biases[44].value = 1566; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[45].code = 78; + test_msg->biases[45].value = -28847; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[46].code = 116; + test_msg->biases[46].value = -26640; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[47].code = 55; + test_msg->biases[47].value = -22087; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[48].code = 254; + test_msg->biases[48].value = 10035; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[49].code = 74; + test_msg->biases[49].value = -2129; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[50].code = 34; + test_msg->biases[50].value = 19041; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[51].code = 97; + test_msg->biases[51].value = 12464; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[52].code = 236; + test_msg->biases[52].value = 3245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[53].code = 174; + test_msg->biases[53].value = -32155; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[54].code = 30; + test_msg->biases[54].value = -15959; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[55].code = 190; + test_msg->biases[55].value = -15156; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[56].code = 123; + test_msg->biases[56].value = 6507; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[57].code = 225; + test_msg->biases[57].value = 2378; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[58].code = 10; + test_msg->biases[58].value = 823; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[59].code = 131; + test_msg->biases[59].value = 25590; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[60].code = 133; + test_msg->biases[60].value = -7390; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[61].code = 203; + test_msg->biases[61].value = 4676; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[62].code = 97; + test_msg->biases[62].value = 23007; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[63].code = 192; + test_msg->biases[63].value = 13046; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[64].code = 69; + test_msg->biases[64].value = 2651; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[65].code = 151; + test_msg->biases[65].value = 30282; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[66].code = 110; + test_msg->biases[66].value = -22492; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[67].code = 247; + test_msg->biases[67].value = 19872; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[68].code = 179; + test_msg->biases[68].value = -19827; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[69].code = 99; + test_msg->biases[69].value = 30911; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[70].code = 77; + test_msg->biases[70].value = 23488; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[71].code = 224; + test_msg->biases[71].value = -7679; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[72].code = 50; + test_msg->biases[72].value = -28073; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[73].code = 148; + test_msg->biases[73].value = 25838; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[74].code = 179; + test_msg->biases[74].value = -7299; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[75].code = 215; + test_msg->biases[75].value = -18328; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[76].code = 31; + test_msg->biases[76].value = 23097; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[77].code = 79; + test_msg->biases[77].value = -25579; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[78].code = 245; + test_msg->biases[78].value = 15441; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[79].code = 93; + test_msg->biases[79].value = 15530; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[80].code = 200; + test_msg->biases[80].value = 3495; + test_msg->iod_ssr = 132; + test_msg->sid.code = 241; + test_msg->sid.sat = 133; + test_msg->time.tow = 387144400; + test_msg->time.wn = 16905; + test_msg->update_interval = 254; + sbp_payload_send(&sbp_state, 0x5e1, 22311, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 22311, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 22311, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5e1, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_code_biases_t *check_msg = + (msg_ssr_code_biases_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->biases[0].code == 51, + "incorrect value for biases[0].code, expected 51, is %d", + check_msg->biases[0].code); + ck_assert_msg(check_msg->biases[0].value == -31996, + "incorrect value for biases[0].value, expected -31996, is %d", + check_msg->biases[0].value); + ck_assert_msg(check_msg->biases[1].code == 240, + "incorrect value for biases[1].code, expected 240, is %d", + check_msg->biases[1].code); + ck_assert_msg(check_msg->biases[1].value == 21368, + "incorrect value for biases[1].value, expected 21368, is %d", + check_msg->biases[1].value); + ck_assert_msg(check_msg->biases[2].code == 148, + "incorrect value for biases[2].code, expected 148, is %d", + check_msg->biases[2].code); + ck_assert_msg(check_msg->biases[2].value == -10799, + "incorrect value for biases[2].value, expected -10799, is %d", + check_msg->biases[2].value); + ck_assert_msg(check_msg->biases[3].code == 62, + "incorrect value for biases[3].code, expected 62, is %d", + check_msg->biases[3].code); + ck_assert_msg(check_msg->biases[3].value == -5916, + "incorrect value for biases[3].value, expected -5916, is %d", + check_msg->biases[3].value); + ck_assert_msg(check_msg->biases[4].code == 71, + "incorrect value for biases[4].code, expected 71, is %d", + check_msg->biases[4].code); + ck_assert_msg(check_msg->biases[4].value == -17342, + "incorrect value for biases[4].value, expected -17342, is %d", + check_msg->biases[4].value); + ck_assert_msg(check_msg->biases[5].code == 210, + "incorrect value for biases[5].code, expected 210, is %d", + check_msg->biases[5].code); + ck_assert_msg(check_msg->biases[5].value == 13952, + "incorrect value for biases[5].value, expected 13952, is %d", + check_msg->biases[5].value); + ck_assert_msg(check_msg->biases[6].code == 131, + "incorrect value for biases[6].code, expected 131, is %d", + check_msg->biases[6].code); + ck_assert_msg(check_msg->biases[6].value == -32360, + "incorrect value for biases[6].value, expected -32360, is %d", + check_msg->biases[6].value); + ck_assert_msg(check_msg->biases[7].code == 111, + "incorrect value for biases[7].code, expected 111, is %d", + check_msg->biases[7].code); + ck_assert_msg(check_msg->biases[7].value == -3445, + "incorrect value for biases[7].value, expected -3445, is %d", + check_msg->biases[7].value); + ck_assert_msg(check_msg->biases[8].code == 177, + "incorrect value for biases[8].code, expected 177, is %d", + check_msg->biases[8].code); + ck_assert_msg(check_msg->biases[8].value == 11409, + "incorrect value for biases[8].value, expected 11409, is %d", + check_msg->biases[8].value); + ck_assert_msg(check_msg->biases[9].code == 9, + "incorrect value for biases[9].code, expected 9, is %d", + check_msg->biases[9].code); + ck_assert_msg(check_msg->biases[9].value == -12299, + "incorrect value for biases[9].value, expected -12299, is %d", + check_msg->biases[9].value); + ck_assert_msg(check_msg->biases[10].code == 241, + "incorrect value for biases[10].code, expected 241, is %d", + check_msg->biases[10].code); + ck_assert_msg( + check_msg->biases[10].value == -26934, + "incorrect value for biases[10].value, expected -26934, is %d", + check_msg->biases[10].value); + ck_assert_msg(check_msg->biases[11].code == 141, + "incorrect value for biases[11].code, expected 141, is %d", + check_msg->biases[11].code); + ck_assert_msg( + check_msg->biases[11].value == -24782, + "incorrect value for biases[11].value, expected -24782, is %d", + check_msg->biases[11].value); + ck_assert_msg(check_msg->biases[12].code == 220, + "incorrect value for biases[12].code, expected 220, is %d", + check_msg->biases[12].code); + ck_assert_msg(check_msg->biases[12].value == 9611, + "incorrect value for biases[12].value, expected 9611, is %d", + check_msg->biases[12].value); + ck_assert_msg(check_msg->biases[13].code == 187, + "incorrect value for biases[13].code, expected 187, is %d", + check_msg->biases[13].code); + ck_assert_msg( + check_msg->biases[13].value == -16542, + "incorrect value for biases[13].value, expected -16542, is %d", + check_msg->biases[13].value); + ck_assert_msg(check_msg->biases[14].code == 23, + "incorrect value for biases[14].code, expected 23, is %d", + check_msg->biases[14].code); + ck_assert_msg( + check_msg->biases[14].value == -30592, + "incorrect value for biases[14].value, expected -30592, is %d", + check_msg->biases[14].value); + ck_assert_msg(check_msg->biases[15].code == 167, + "incorrect value for biases[15].code, expected 167, is %d", + check_msg->biases[15].code); + ck_assert_msg(check_msg->biases[15].value == 1736, + "incorrect value for biases[15].value, expected 1736, is %d", + check_msg->biases[15].value); + ck_assert_msg(check_msg->biases[16].code == 211, + "incorrect value for biases[16].code, expected 211, is %d", + check_msg->biases[16].code); + ck_assert_msg(check_msg->biases[16].value == 5978, + "incorrect value for biases[16].value, expected 5978, is %d", + check_msg->biases[16].value); + ck_assert_msg(check_msg->biases[17].code == 244, + "incorrect value for biases[17].code, expected 244, is %d", + check_msg->biases[17].code); + ck_assert_msg( + check_msg->biases[17].value == -10358, + "incorrect value for biases[17].value, expected -10358, is %d", + check_msg->biases[17].value); + ck_assert_msg(check_msg->biases[18].code == 209, + "incorrect value for biases[18].code, expected 209, is %d", + check_msg->biases[18].code); + ck_assert_msg(check_msg->biases[18].value == 3467, + "incorrect value for biases[18].value, expected 3467, is %d", + check_msg->biases[18].value); + ck_assert_msg(check_msg->biases[19].code == 101, + "incorrect value for biases[19].code, expected 101, is %d", + check_msg->biases[19].code); + ck_assert_msg(check_msg->biases[19].value == 1824, + "incorrect value for biases[19].value, expected 1824, is %d", + check_msg->biases[19].value); + ck_assert_msg(check_msg->biases[20].code == 18, + "incorrect value for biases[20].code, expected 18, is %d", + check_msg->biases[20].code); + ck_assert_msg(check_msg->biases[20].value == 17949, + "incorrect value for biases[20].value, expected 17949, is %d", + check_msg->biases[20].value); + ck_assert_msg(check_msg->biases[21].code == 250, + "incorrect value for biases[21].code, expected 250, is %d", + check_msg->biases[21].code); + ck_assert_msg(check_msg->biases[21].value == 18797, + "incorrect value for biases[21].value, expected 18797, is %d", + check_msg->biases[21].value); + ck_assert_msg(check_msg->biases[22].code == 202, + "incorrect value for biases[22].code, expected 202, is %d", + check_msg->biases[22].code); + ck_assert_msg( + check_msg->biases[22].value == -28593, + "incorrect value for biases[22].value, expected -28593, is %d", + check_msg->biases[22].value); + ck_assert_msg(check_msg->biases[23].code == 9, + "incorrect value for biases[23].code, expected 9, is %d", + check_msg->biases[23].code); + ck_assert_msg(check_msg->biases[23].value == 17810, + "incorrect value for biases[23].value, expected 17810, is %d", + check_msg->biases[23].value); + ck_assert_msg(check_msg->biases[24].code == 241, + "incorrect value for biases[24].code, expected 241, is %d", + check_msg->biases[24].code); + ck_assert_msg(check_msg->biases[24].value == 5684, + "incorrect value for biases[24].value, expected 5684, is %d", + check_msg->biases[24].value); + ck_assert_msg(check_msg->biases[25].code == 99, + "incorrect value for biases[25].code, expected 99, is %d", + check_msg->biases[25].code); + ck_assert_msg( + check_msg->biases[25].value == -13214, + "incorrect value for biases[25].value, expected -13214, is %d", + check_msg->biases[25].value); + ck_assert_msg(check_msg->biases[26].code == 3, + "incorrect value for biases[26].code, expected 3, is %d", + check_msg->biases[26].code); + ck_assert_msg(check_msg->biases[26].value == -6485, + "incorrect value for biases[26].value, expected -6485, is %d", + check_msg->biases[26].value); + ck_assert_msg(check_msg->biases[27].code == 180, + "incorrect value for biases[27].code, expected 180, is %d", + check_msg->biases[27].code); + ck_assert_msg(check_msg->biases[27].value == 15947, + "incorrect value for biases[27].value, expected 15947, is %d", + check_msg->biases[27].value); + ck_assert_msg(check_msg->biases[28].code == 145, + "incorrect value for biases[28].code, expected 145, is %d", + check_msg->biases[28].code); + ck_assert_msg( + check_msg->biases[28].value == -32170, + "incorrect value for biases[28].value, expected -32170, is %d", + check_msg->biases[28].value); + ck_assert_msg(check_msg->biases[29].code == 31, + "incorrect value for biases[29].code, expected 31, is %d", + check_msg->biases[29].code); + ck_assert_msg( + check_msg->biases[29].value == -25826, + "incorrect value for biases[29].value, expected -25826, is %d", + check_msg->biases[29].value); + ck_assert_msg(check_msg->biases[30].code == 37, + "incorrect value for biases[30].code, expected 37, is %d", + check_msg->biases[30].code); + ck_assert_msg(check_msg->biases[30].value == 14098, + "incorrect value for biases[30].value, expected 14098, is %d", + check_msg->biases[30].value); + ck_assert_msg(check_msg->biases[31].code == 210, + "incorrect value for biases[31].code, expected 210, is %d", + check_msg->biases[31].code); + ck_assert_msg(check_msg->biases[31].value == 32551, + "incorrect value for biases[31].value, expected 32551, is %d", + check_msg->biases[31].value); + ck_assert_msg(check_msg->biases[32].code == 242, + "incorrect value for biases[32].code, expected 242, is %d", + check_msg->biases[32].code); + ck_assert_msg(check_msg->biases[32].value == 3394, + "incorrect value for biases[32].value, expected 3394, is %d", + check_msg->biases[32].value); + ck_assert_msg(check_msg->biases[33].code == 237, + "incorrect value for biases[33].code, expected 237, is %d", + check_msg->biases[33].code); + ck_assert_msg( + check_msg->biases[33].value == -21864, + "incorrect value for biases[33].value, expected -21864, is %d", + check_msg->biases[33].value); + ck_assert_msg(check_msg->biases[34].code == 212, + "incorrect value for biases[34].code, expected 212, is %d", + check_msg->biases[34].code); + ck_assert_msg(check_msg->biases[34].value == -2545, + "incorrect value for biases[34].value, expected -2545, is %d", + check_msg->biases[34].value); + ck_assert_msg(check_msg->biases[35].code == 59, + "incorrect value for biases[35].code, expected 59, is %d", + check_msg->biases[35].code); + ck_assert_msg( + check_msg->biases[35].value == -19362, + "incorrect value for biases[35].value, expected -19362, is %d", + check_msg->biases[35].value); + ck_assert_msg(check_msg->biases[36].code == 195, + "incorrect value for biases[36].code, expected 195, is %d", + check_msg->biases[36].code); + ck_assert_msg(check_msg->biases[36].value == 17821, + "incorrect value for biases[36].value, expected 17821, is %d", + check_msg->biases[36].value); + ck_assert_msg(check_msg->biases[37].code == 100, + "incorrect value for biases[37].code, expected 100, is %d", + check_msg->biases[37].code); + ck_assert_msg(check_msg->biases[37].value == 4215, + "incorrect value for biases[37].value, expected 4215, is %d", + check_msg->biases[37].value); + ck_assert_msg(check_msg->biases[38].code == 68, + "incorrect value for biases[38].code, expected 68, is %d", + check_msg->biases[38].code); + ck_assert_msg( + check_msg->biases[38].value == -20557, + "incorrect value for biases[38].value, expected -20557, is %d", + check_msg->biases[38].value); + ck_assert_msg(check_msg->biases[39].code == 144, + "incorrect value for biases[39].code, expected 144, is %d", + check_msg->biases[39].code); + ck_assert_msg(check_msg->biases[39].value == 20849, + "incorrect value for biases[39].value, expected 20849, is %d", + check_msg->biases[39].value); + ck_assert_msg(check_msg->biases[40].code == 82, + "incorrect value for biases[40].code, expected 82, is %d", + check_msg->biases[40].code); + ck_assert_msg( + check_msg->biases[40].value == -26850, + "incorrect value for biases[40].value, expected -26850, is %d", + check_msg->biases[40].value); + ck_assert_msg(check_msg->biases[41].code == 21, + "incorrect value for biases[41].code, expected 21, is %d", + check_msg->biases[41].code); + ck_assert_msg(check_msg->biases[41].value == 10605, + "incorrect value for biases[41].value, expected 10605, is %d", + check_msg->biases[41].value); + ck_assert_msg(check_msg->biases[42].code == 225, + "incorrect value for biases[42].code, expected 225, is %d", + check_msg->biases[42].code); + ck_assert_msg(check_msg->biases[42].value == 19720, + "incorrect value for biases[42].value, expected 19720, is %d", + check_msg->biases[42].value); + ck_assert_msg(check_msg->biases[43].code == 164, + "incorrect value for biases[43].code, expected 164, is %d", + check_msg->biases[43].code); + ck_assert_msg(check_msg->biases[43].value == 157, + "incorrect value for biases[43].value, expected 157, is %d", + check_msg->biases[43].value); + ck_assert_msg(check_msg->biases[44].code == 73, + "incorrect value for biases[44].code, expected 73, is %d", + check_msg->biases[44].code); + ck_assert_msg(check_msg->biases[44].value == 1566, + "incorrect value for biases[44].value, expected 1566, is %d", + check_msg->biases[44].value); + ck_assert_msg(check_msg->biases[45].code == 78, + "incorrect value for biases[45].code, expected 78, is %d", + check_msg->biases[45].code); + ck_assert_msg( + check_msg->biases[45].value == -28847, + "incorrect value for biases[45].value, expected -28847, is %d", + check_msg->biases[45].value); + ck_assert_msg(check_msg->biases[46].code == 116, + "incorrect value for biases[46].code, expected 116, is %d", + check_msg->biases[46].code); + ck_assert_msg( + check_msg->biases[46].value == -26640, + "incorrect value for biases[46].value, expected -26640, is %d", + check_msg->biases[46].value); + ck_assert_msg(check_msg->biases[47].code == 55, + "incorrect value for biases[47].code, expected 55, is %d", + check_msg->biases[47].code); + ck_assert_msg( + check_msg->biases[47].value == -22087, + "incorrect value for biases[47].value, expected -22087, is %d", + check_msg->biases[47].value); + ck_assert_msg(check_msg->biases[48].code == 254, + "incorrect value for biases[48].code, expected 254, is %d", + check_msg->biases[48].code); + ck_assert_msg(check_msg->biases[48].value == 10035, + "incorrect value for biases[48].value, expected 10035, is %d", + check_msg->biases[48].value); + ck_assert_msg(check_msg->biases[49].code == 74, + "incorrect value for biases[49].code, expected 74, is %d", + check_msg->biases[49].code); + ck_assert_msg(check_msg->biases[49].value == -2129, + "incorrect value for biases[49].value, expected -2129, is %d", + check_msg->biases[49].value); + ck_assert_msg(check_msg->biases[50].code == 34, + "incorrect value for biases[50].code, expected 34, is %d", + check_msg->biases[50].code); + ck_assert_msg(check_msg->biases[50].value == 19041, + "incorrect value for biases[50].value, expected 19041, is %d", + check_msg->biases[50].value); + ck_assert_msg(check_msg->biases[51].code == 97, + "incorrect value for biases[51].code, expected 97, is %d", + check_msg->biases[51].code); + ck_assert_msg(check_msg->biases[51].value == 12464, + "incorrect value for biases[51].value, expected 12464, is %d", + check_msg->biases[51].value); + ck_assert_msg(check_msg->biases[52].code == 236, + "incorrect value for biases[52].code, expected 236, is %d", + check_msg->biases[52].code); + ck_assert_msg(check_msg->biases[52].value == 3245, + "incorrect value for biases[52].value, expected 3245, is %d", + check_msg->biases[52].value); + ck_assert_msg(check_msg->biases[53].code == 174, + "incorrect value for biases[53].code, expected 174, is %d", + check_msg->biases[53].code); + ck_assert_msg( + check_msg->biases[53].value == -32155, + "incorrect value for biases[53].value, expected -32155, is %d", + check_msg->biases[53].value); + ck_assert_msg(check_msg->biases[54].code == 30, + "incorrect value for biases[54].code, expected 30, is %d", + check_msg->biases[54].code); + ck_assert_msg( + check_msg->biases[54].value == -15959, + "incorrect value for biases[54].value, expected -15959, is %d", + check_msg->biases[54].value); + ck_assert_msg(check_msg->biases[55].code == 190, + "incorrect value for biases[55].code, expected 190, is %d", + check_msg->biases[55].code); + ck_assert_msg( + check_msg->biases[55].value == -15156, + "incorrect value for biases[55].value, expected -15156, is %d", + check_msg->biases[55].value); + ck_assert_msg(check_msg->biases[56].code == 123, + "incorrect value for biases[56].code, expected 123, is %d", + check_msg->biases[56].code); + ck_assert_msg(check_msg->biases[56].value == 6507, + "incorrect value for biases[56].value, expected 6507, is %d", + check_msg->biases[56].value); + ck_assert_msg(check_msg->biases[57].code == 225, + "incorrect value for biases[57].code, expected 225, is %d", + check_msg->biases[57].code); + ck_assert_msg(check_msg->biases[57].value == 2378, + "incorrect value for biases[57].value, expected 2378, is %d", + check_msg->biases[57].value); + ck_assert_msg(check_msg->biases[58].code == 10, + "incorrect value for biases[58].code, expected 10, is %d", + check_msg->biases[58].code); + ck_assert_msg(check_msg->biases[58].value == 823, + "incorrect value for biases[58].value, expected 823, is %d", + check_msg->biases[58].value); + ck_assert_msg(check_msg->biases[59].code == 131, + "incorrect value for biases[59].code, expected 131, is %d", + check_msg->biases[59].code); + ck_assert_msg(check_msg->biases[59].value == 25590, + "incorrect value for biases[59].value, expected 25590, is %d", + check_msg->biases[59].value); + ck_assert_msg(check_msg->biases[60].code == 133, + "incorrect value for biases[60].code, expected 133, is %d", + check_msg->biases[60].code); + ck_assert_msg(check_msg->biases[60].value == -7390, + "incorrect value for biases[60].value, expected -7390, is %d", + check_msg->biases[60].value); + ck_assert_msg(check_msg->biases[61].code == 203, + "incorrect value for biases[61].code, expected 203, is %d", + check_msg->biases[61].code); + ck_assert_msg(check_msg->biases[61].value == 4676, + "incorrect value for biases[61].value, expected 4676, is %d", + check_msg->biases[61].value); + ck_assert_msg(check_msg->biases[62].code == 97, + "incorrect value for biases[62].code, expected 97, is %d", + check_msg->biases[62].code); + ck_assert_msg(check_msg->biases[62].value == 23007, + "incorrect value for biases[62].value, expected 23007, is %d", + check_msg->biases[62].value); + ck_assert_msg(check_msg->biases[63].code == 192, + "incorrect value for biases[63].code, expected 192, is %d", + check_msg->biases[63].code); + ck_assert_msg(check_msg->biases[63].value == 13046, + "incorrect value for biases[63].value, expected 13046, is %d", + check_msg->biases[63].value); + ck_assert_msg(check_msg->biases[64].code == 69, + "incorrect value for biases[64].code, expected 69, is %d", + check_msg->biases[64].code); + ck_assert_msg(check_msg->biases[64].value == 2651, + "incorrect value for biases[64].value, expected 2651, is %d", + check_msg->biases[64].value); + ck_assert_msg(check_msg->biases[65].code == 151, + "incorrect value for biases[65].code, expected 151, is %d", + check_msg->biases[65].code); + ck_assert_msg(check_msg->biases[65].value == 30282, + "incorrect value for biases[65].value, expected 30282, is %d", + check_msg->biases[65].value); + ck_assert_msg(check_msg->biases[66].code == 110, + "incorrect value for biases[66].code, expected 110, is %d", + check_msg->biases[66].code); + ck_assert_msg( + check_msg->biases[66].value == -22492, + "incorrect value for biases[66].value, expected -22492, is %d", + check_msg->biases[66].value); + ck_assert_msg(check_msg->biases[67].code == 247, + "incorrect value for biases[67].code, expected 247, is %d", + check_msg->biases[67].code); + ck_assert_msg(check_msg->biases[67].value == 19872, + "incorrect value for biases[67].value, expected 19872, is %d", + check_msg->biases[67].value); + ck_assert_msg(check_msg->biases[68].code == 179, + "incorrect value for biases[68].code, expected 179, is %d", + check_msg->biases[68].code); + ck_assert_msg( + check_msg->biases[68].value == -19827, + "incorrect value for biases[68].value, expected -19827, is %d", + check_msg->biases[68].value); + ck_assert_msg(check_msg->biases[69].code == 99, + "incorrect value for biases[69].code, expected 99, is %d", + check_msg->biases[69].code); + ck_assert_msg(check_msg->biases[69].value == 30911, + "incorrect value for biases[69].value, expected 30911, is %d", + check_msg->biases[69].value); + ck_assert_msg(check_msg->biases[70].code == 77, + "incorrect value for biases[70].code, expected 77, is %d", + check_msg->biases[70].code); + ck_assert_msg(check_msg->biases[70].value == 23488, + "incorrect value for biases[70].value, expected 23488, is %d", + check_msg->biases[70].value); + ck_assert_msg(check_msg->biases[71].code == 224, + "incorrect value for biases[71].code, expected 224, is %d", + check_msg->biases[71].code); + ck_assert_msg(check_msg->biases[71].value == -7679, + "incorrect value for biases[71].value, expected -7679, is %d", + check_msg->biases[71].value); + ck_assert_msg(check_msg->biases[72].code == 50, + "incorrect value for biases[72].code, expected 50, is %d", + check_msg->biases[72].code); + ck_assert_msg( + check_msg->biases[72].value == -28073, + "incorrect value for biases[72].value, expected -28073, is %d", + check_msg->biases[72].value); + ck_assert_msg(check_msg->biases[73].code == 148, + "incorrect value for biases[73].code, expected 148, is %d", + check_msg->biases[73].code); + ck_assert_msg(check_msg->biases[73].value == 25838, + "incorrect value for biases[73].value, expected 25838, is %d", + check_msg->biases[73].value); + ck_assert_msg(check_msg->biases[74].code == 179, + "incorrect value for biases[74].code, expected 179, is %d", + check_msg->biases[74].code); + ck_assert_msg(check_msg->biases[74].value == -7299, + "incorrect value for biases[74].value, expected -7299, is %d", + check_msg->biases[74].value); + ck_assert_msg(check_msg->biases[75].code == 215, + "incorrect value for biases[75].code, expected 215, is %d", + check_msg->biases[75].code); + ck_assert_msg( + check_msg->biases[75].value == -18328, + "incorrect value for biases[75].value, expected -18328, is %d", + check_msg->biases[75].value); + ck_assert_msg(check_msg->biases[76].code == 31, + "incorrect value for biases[76].code, expected 31, is %d", + check_msg->biases[76].code); + ck_assert_msg(check_msg->biases[76].value == 23097, + "incorrect value for biases[76].value, expected 23097, is %d", + check_msg->biases[76].value); + ck_assert_msg(check_msg->biases[77].code == 79, + "incorrect value for biases[77].code, expected 79, is %d", + check_msg->biases[77].code); + ck_assert_msg( + check_msg->biases[77].value == -25579, + "incorrect value for biases[77].value, expected -25579, is %d", + check_msg->biases[77].value); + ck_assert_msg(check_msg->biases[78].code == 245, + "incorrect value for biases[78].code, expected 245, is %d", + check_msg->biases[78].code); + ck_assert_msg(check_msg->biases[78].value == 15441, + "incorrect value for biases[78].value, expected 15441, is %d", + check_msg->biases[78].value); + ck_assert_msg(check_msg->biases[79].code == 93, + "incorrect value for biases[79].code, expected 93, is %d", + check_msg->biases[79].code); + ck_assert_msg(check_msg->biases[79].value == 15530, + "incorrect value for biases[79].value, expected 15530, is %d", + check_msg->biases[79].value); + ck_assert_msg(check_msg->biases[80].code == 200, + "incorrect value for biases[80].code, expected 200, is %d", + check_msg->biases[80].code); + ck_assert_msg(check_msg->biases[80].value == 3495, + "incorrect value for biases[80].value, expected 3495, is %d", + check_msg->biases[80].value); + ck_assert_msg(check_msg->iod_ssr == 132, + "incorrect value for iod_ssr, expected 132, is %d", + check_msg->iod_ssr); + ck_assert_msg(check_msg->sid.code == 241, + "incorrect value for sid.code, expected 241, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 133, + "incorrect value for sid.sat, expected 133, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->time.tow == 387144400, + "incorrect value for time.tow, expected 387144400, is %d", + check_msg->time.tow); + ck_assert_msg(check_msg->time.wn == 16905, + "incorrect value for time.wn, expected 16905, is %d", + check_msg->time.wn); + ck_assert_msg(check_msg->update_interval == 254, + "incorrect value for update_interval, expected 254, is %d", + check_msg->update_interval); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrCodeBiases_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_ssr_MsgSsrCodeBiases"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c new file mode 100644 index 0000000000..21541ad35b --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.c @@ -0,0 +1,2219 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5f5, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5f5, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, + 52, 92, 104, 25, 204, 182, 22, 98, 203, 123, 211, 38, 13, 253, + 129, 173, 171, 235, 253, 26, 203, 3, 120, 126, 42, 44, 39, 87, + 69, 154, 13, 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, + 57, 120, 243, 151, 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, + 144, 158, 239, 90, 56, 71, 120, 67, 221, 114, 10, 190, 4, 230, + 164, 171, 78, 185, 90, 46, 177, 82, 228, 123, 222, 227, 145, 195, + 219, 27, 56, 227, 246, 215, 144, 158, 31, 214, 241, 254, 200, 86, + 142, 89, 12, 121, 29, 124, 9, 19, 153, 44, 35, 126, 14, 217, + 65, 116, 26, 139, 122, 114, 90, 124, 81, 0, 186, 246, 46, 98, + 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, 42, 150, 221, 102, + 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, 128, 193, 53, + 94, 99, 63, 182, 2, 186, 220, 77, 186, 224, 220, 13, 212, 182, + 88, 15, 151, 5, 93, 251, 164, 18, 228, 168, 226, 195, 44, 170, + 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, 159, 189, + 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, + 19, 151, 136, 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, + 212, 68, 60, 206, 106, 207, 243, 158, 94, 6, 3, 205, 92, 84, + 2, 220, 50, 61, 38, 141, 117, 108, 101, 76, 139, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_grid_definition_dep_a_t *test_msg = + (msg_ssr_grid_definition_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.area_width = 43860; + test_msg->header.lat_nw_corner_enc = 34021; + test_msg->header.lon_nw_corner_enc = 11919; + test_msg->header.num_msgs = 204; + test_msg->header.region_size_inverse = 11; + test_msg->header.seq_num = 52; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[0] = 92; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[1] = 104; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[2] = 25; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[3] = 204; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[4] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[5] = 22; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[6] = 98; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[7] = 203; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[8] = 123; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[9] = 211; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[10] = 38; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[11] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[12] = 253; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[13] = 129; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[14] = 173; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[15] = 171; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[16] = 235; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[17] = 253; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[18] = 26; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[19] = 203; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[20] = 3; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[21] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[22] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[23] = 42; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[24] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[25] = 39; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[26] = 87; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[27] = 69; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[28] = 154; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[29] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[30] = 28; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[31] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[32] = 32; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[33] = 47; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[34] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[35] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[36] = 39; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[37] = 198; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[38] = 134; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[39] = 235; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[40] = 134; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[41] = 57; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[42] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[43] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[44] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[45] = 35; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[46] = 17; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[47] = 201; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[48] = 211; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[49] = 125; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[50] = 117; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[51] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[52] = 142; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[53] = 101; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[54] = 239; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[55] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[56] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[57] = 239; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[58] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[59] = 56; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[60] = 71; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[61] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[62] = 67; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[63] = 221; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[64] = 114; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[65] = 10; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[66] = 190; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[67] = 4; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[68] = 230; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[69] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[70] = 171; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[71] = 78; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[72] = 185; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[73] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[74] = 46; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[75] = 177; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[76] = 82; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[77] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[78] = 123; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[79] = 222; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[80] = 227; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[81] = 145; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[82] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[83] = 219; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[84] = 27; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[85] = 56; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[86] = 227; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[87] = 246; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[88] = 215; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[89] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[90] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[91] = 31; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[92] = 214; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[93] = 241; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[94] = 254; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[95] = 200; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[96] = 86; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[97] = 142; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[98] = 89; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[99] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[100] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[101] = 29; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[102] = 124; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[103] = 9; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[104] = 19; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[105] = 153; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[106] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[107] = 35; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[108] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[109] = 14; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[110] = 217; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[111] = 65; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[112] = 116; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[113] = 26; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[114] = 139; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[115] = 122; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[116] = 114; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[117] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[118] = 124; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[119] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[120] = 0; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[121] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[122] = 246; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[123] = 46; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[124] = 98; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[125] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[126] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[127] = 198; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[128] = 217; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[129] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[130] = 30; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[131] = 202; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[132] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[133] = 135; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[134] = 61; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[135] = 42; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[136] = 150; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[137] = 221; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[138] = 102; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[139] = 83; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[140] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[141] = 43; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[142] = 252; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[143] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[144] = 62; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[145] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[146] = 204; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[147] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[148] = 238; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[149] = 18; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[150] = 128; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[151] = 193; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[152] = 53; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[153] = 94; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[154] = 99; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[155] = 63; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[156] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[157] = 2; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[158] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[159] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[160] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[161] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[162] = 224; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[163] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[164] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[165] = 212; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[166] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[167] = 88; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[168] = 15; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[169] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[170] = 5; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[171] = 93; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[172] = 251; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[173] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[174] = 18; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[175] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[176] = 168; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[177] = 226; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[178] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[179] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[180] = 170; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[181] = 145; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[182] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[183] = 58; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[184] = 96; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[185] = 107; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[186] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[187] = 11; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[188] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[189] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[190] = 163; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[191] = 238; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[192] = 247; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[193] = 159; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[194] = 189; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[195] = 1; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[196] = 115; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[197] = 65; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[198] = 202; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[199] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[200] = 47; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[201] = 193; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[202] = 11; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[203] = 96; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[204] = 93; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[205] = 72; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[206] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[207] = 207; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[208] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[209] = 19; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[210] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[211] = 136; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[212] = 233; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[213] = 51; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[214] = 133; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[215] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[216] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[217] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[218] = 147; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[219] = 206; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[220] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[221] = 252; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[222] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[223] = 212; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[224] = 68; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[225] = 60; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[226] = 206; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[227] = 106; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[228] = 207; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[229] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[230] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[231] = 94; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[232] = 6; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[233] = 3; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[234] = 205; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[235] = 92; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[236] = 84; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[237] = 2; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[238] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[239] = 50; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[240] = 61; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[241] = 38; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[242] = 141; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[243] = 117; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[244] = 108; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->rle_list[0]); + } + test_msg->rle_list[245] = 101; + sbp_payload_send(&sbp_state, 0x5f5, 63413, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63413, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 63413, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5f5, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_grid_definition_dep_a_t *check_msg = + (msg_ssr_grid_definition_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->header.area_width == 43860, + "incorrect value for header.area_width, expected 43860, is %d", + check_msg->header.area_width); + ck_assert_msg( + check_msg->header.lat_nw_corner_enc == 34021, + "incorrect value for header.lat_nw_corner_enc, expected 34021, is %d", + check_msg->header.lat_nw_corner_enc); + ck_assert_msg( + check_msg->header.lon_nw_corner_enc == 11919, + "incorrect value for header.lon_nw_corner_enc, expected 11919, is %d", + check_msg->header.lon_nw_corner_enc); + ck_assert_msg(check_msg->header.num_msgs == 204, + "incorrect value for header.num_msgs, expected 204, is %d", + check_msg->header.num_msgs); + ck_assert_msg( + check_msg->header.region_size_inverse == 11, + "incorrect value for header.region_size_inverse, expected 11, is %d", + check_msg->header.region_size_inverse); + ck_assert_msg(check_msg->header.seq_num == 52, + "incorrect value for header.seq_num, expected 52, is %d", + check_msg->header.seq_num); + ck_assert_msg(check_msg->rle_list[0] == 92, + "incorrect value for rle_list[0], expected 92, is %d", + check_msg->rle_list[0]); + ck_assert_msg(check_msg->rle_list[1] == 104, + "incorrect value for rle_list[1], expected 104, is %d", + check_msg->rle_list[1]); + ck_assert_msg(check_msg->rle_list[2] == 25, + "incorrect value for rle_list[2], expected 25, is %d", + check_msg->rle_list[2]); + ck_assert_msg(check_msg->rle_list[3] == 204, + "incorrect value for rle_list[3], expected 204, is %d", + check_msg->rle_list[3]); + ck_assert_msg(check_msg->rle_list[4] == 182, + "incorrect value for rle_list[4], expected 182, is %d", + check_msg->rle_list[4]); + ck_assert_msg(check_msg->rle_list[5] == 22, + "incorrect value for rle_list[5], expected 22, is %d", + check_msg->rle_list[5]); + ck_assert_msg(check_msg->rle_list[6] == 98, + "incorrect value for rle_list[6], expected 98, is %d", + check_msg->rle_list[6]); + ck_assert_msg(check_msg->rle_list[7] == 203, + "incorrect value for rle_list[7], expected 203, is %d", + check_msg->rle_list[7]); + ck_assert_msg(check_msg->rle_list[8] == 123, + "incorrect value for rle_list[8], expected 123, is %d", + check_msg->rle_list[8]); + ck_assert_msg(check_msg->rle_list[9] == 211, + "incorrect value for rle_list[9], expected 211, is %d", + check_msg->rle_list[9]); + ck_assert_msg(check_msg->rle_list[10] == 38, + "incorrect value for rle_list[10], expected 38, is %d", + check_msg->rle_list[10]); + ck_assert_msg(check_msg->rle_list[11] == 13, + "incorrect value for rle_list[11], expected 13, is %d", + check_msg->rle_list[11]); + ck_assert_msg(check_msg->rle_list[12] == 253, + "incorrect value for rle_list[12], expected 253, is %d", + check_msg->rle_list[12]); + ck_assert_msg(check_msg->rle_list[13] == 129, + "incorrect value for rle_list[13], expected 129, is %d", + check_msg->rle_list[13]); + ck_assert_msg(check_msg->rle_list[14] == 173, + "incorrect value for rle_list[14], expected 173, is %d", + check_msg->rle_list[14]); + ck_assert_msg(check_msg->rle_list[15] == 171, + "incorrect value for rle_list[15], expected 171, is %d", + check_msg->rle_list[15]); + ck_assert_msg(check_msg->rle_list[16] == 235, + "incorrect value for rle_list[16], expected 235, is %d", + check_msg->rle_list[16]); + ck_assert_msg(check_msg->rle_list[17] == 253, + "incorrect value for rle_list[17], expected 253, is %d", + check_msg->rle_list[17]); + ck_assert_msg(check_msg->rle_list[18] == 26, + "incorrect value for rle_list[18], expected 26, is %d", + check_msg->rle_list[18]); + ck_assert_msg(check_msg->rle_list[19] == 203, + "incorrect value for rle_list[19], expected 203, is %d", + check_msg->rle_list[19]); + ck_assert_msg(check_msg->rle_list[20] == 3, + "incorrect value for rle_list[20], expected 3, is %d", + check_msg->rle_list[20]); + ck_assert_msg(check_msg->rle_list[21] == 120, + "incorrect value for rle_list[21], expected 120, is %d", + check_msg->rle_list[21]); + ck_assert_msg(check_msg->rle_list[22] == 126, + "incorrect value for rle_list[22], expected 126, is %d", + check_msg->rle_list[22]); + ck_assert_msg(check_msg->rle_list[23] == 42, + "incorrect value for rle_list[23], expected 42, is %d", + check_msg->rle_list[23]); + ck_assert_msg(check_msg->rle_list[24] == 44, + "incorrect value for rle_list[24], expected 44, is %d", + check_msg->rle_list[24]); + ck_assert_msg(check_msg->rle_list[25] == 39, + "incorrect value for rle_list[25], expected 39, is %d", + check_msg->rle_list[25]); + ck_assert_msg(check_msg->rle_list[26] == 87, + "incorrect value for rle_list[26], expected 87, is %d", + check_msg->rle_list[26]); + ck_assert_msg(check_msg->rle_list[27] == 69, + "incorrect value for rle_list[27], expected 69, is %d", + check_msg->rle_list[27]); + ck_assert_msg(check_msg->rle_list[28] == 154, + "incorrect value for rle_list[28], expected 154, is %d", + check_msg->rle_list[28]); + ck_assert_msg(check_msg->rle_list[29] == 13, + "incorrect value for rle_list[29], expected 13, is %d", + check_msg->rle_list[29]); + ck_assert_msg(check_msg->rle_list[30] == 28, + "incorrect value for rle_list[30], expected 28, is %d", + check_msg->rle_list[30]); + ck_assert_msg(check_msg->rle_list[31] == 179, + "incorrect value for rle_list[31], expected 179, is %d", + check_msg->rle_list[31]); + ck_assert_msg(check_msg->rle_list[32] == 32, + "incorrect value for rle_list[32], expected 32, is %d", + check_msg->rle_list[32]); + ck_assert_msg(check_msg->rle_list[33] == 47, + "incorrect value for rle_list[33], expected 47, is %d", + check_msg->rle_list[33]); + ck_assert_msg(check_msg->rle_list[34] == 36, + "incorrect value for rle_list[34], expected 36, is %d", + check_msg->rle_list[34]); + ck_assert_msg(check_msg->rle_list[35] == 195, + "incorrect value for rle_list[35], expected 195, is %d", + check_msg->rle_list[35]); + ck_assert_msg(check_msg->rle_list[36] == 39, + "incorrect value for rle_list[36], expected 39, is %d", + check_msg->rle_list[36]); + ck_assert_msg(check_msg->rle_list[37] == 198, + "incorrect value for rle_list[37], expected 198, is %d", + check_msg->rle_list[37]); + ck_assert_msg(check_msg->rle_list[38] == 134, + "incorrect value for rle_list[38], expected 134, is %d", + check_msg->rle_list[38]); + ck_assert_msg(check_msg->rle_list[39] == 235, + "incorrect value for rle_list[39], expected 235, is %d", + check_msg->rle_list[39]); + ck_assert_msg(check_msg->rle_list[40] == 134, + "incorrect value for rle_list[40], expected 134, is %d", + check_msg->rle_list[40]); + ck_assert_msg(check_msg->rle_list[41] == 57, + "incorrect value for rle_list[41], expected 57, is %d", + check_msg->rle_list[41]); + ck_assert_msg(check_msg->rle_list[42] == 120, + "incorrect value for rle_list[42], expected 120, is %d", + check_msg->rle_list[42]); + ck_assert_msg(check_msg->rle_list[43] == 243, + "incorrect value for rle_list[43], expected 243, is %d", + check_msg->rle_list[43]); + ck_assert_msg(check_msg->rle_list[44] == 151, + "incorrect value for rle_list[44], expected 151, is %d", + check_msg->rle_list[44]); + ck_assert_msg(check_msg->rle_list[45] == 35, + "incorrect value for rle_list[45], expected 35, is %d", + check_msg->rle_list[45]); + ck_assert_msg(check_msg->rle_list[46] == 17, + "incorrect value for rle_list[46], expected 17, is %d", + check_msg->rle_list[46]); + ck_assert_msg(check_msg->rle_list[47] == 201, + "incorrect value for rle_list[47], expected 201, is %d", + check_msg->rle_list[47]); + ck_assert_msg(check_msg->rle_list[48] == 211, + "incorrect value for rle_list[48], expected 211, is %d", + check_msg->rle_list[48]); + ck_assert_msg(check_msg->rle_list[49] == 125, + "incorrect value for rle_list[49], expected 125, is %d", + check_msg->rle_list[49]); + ck_assert_msg(check_msg->rle_list[50] == 117, + "incorrect value for rle_list[50], expected 117, is %d", + check_msg->rle_list[50]); + ck_assert_msg(check_msg->rle_list[51] == 164, + "incorrect value for rle_list[51], expected 164, is %d", + check_msg->rle_list[51]); + ck_assert_msg(check_msg->rle_list[52] == 142, + "incorrect value for rle_list[52], expected 142, is %d", + check_msg->rle_list[52]); + ck_assert_msg(check_msg->rle_list[53] == 101, + "incorrect value for rle_list[53], expected 101, is %d", + check_msg->rle_list[53]); + ck_assert_msg(check_msg->rle_list[54] == 239, + "incorrect value for rle_list[54], expected 239, is %d", + check_msg->rle_list[54]); + ck_assert_msg(check_msg->rle_list[55] == 144, + "incorrect value for rle_list[55], expected 144, is %d", + check_msg->rle_list[55]); + ck_assert_msg(check_msg->rle_list[56] == 158, + "incorrect value for rle_list[56], expected 158, is %d", + check_msg->rle_list[56]); + ck_assert_msg(check_msg->rle_list[57] == 239, + "incorrect value for rle_list[57], expected 239, is %d", + check_msg->rle_list[57]); + ck_assert_msg(check_msg->rle_list[58] == 90, + "incorrect value for rle_list[58], expected 90, is %d", + check_msg->rle_list[58]); + ck_assert_msg(check_msg->rle_list[59] == 56, + "incorrect value for rle_list[59], expected 56, is %d", + check_msg->rle_list[59]); + ck_assert_msg(check_msg->rle_list[60] == 71, + "incorrect value for rle_list[60], expected 71, is %d", + check_msg->rle_list[60]); + ck_assert_msg(check_msg->rle_list[61] == 120, + "incorrect value for rle_list[61], expected 120, is %d", + check_msg->rle_list[61]); + ck_assert_msg(check_msg->rle_list[62] == 67, + "incorrect value for rle_list[62], expected 67, is %d", + check_msg->rle_list[62]); + ck_assert_msg(check_msg->rle_list[63] == 221, + "incorrect value for rle_list[63], expected 221, is %d", + check_msg->rle_list[63]); + ck_assert_msg(check_msg->rle_list[64] == 114, + "incorrect value for rle_list[64], expected 114, is %d", + check_msg->rle_list[64]); + ck_assert_msg(check_msg->rle_list[65] == 10, + "incorrect value for rle_list[65], expected 10, is %d", + check_msg->rle_list[65]); + ck_assert_msg(check_msg->rle_list[66] == 190, + "incorrect value for rle_list[66], expected 190, is %d", + check_msg->rle_list[66]); + ck_assert_msg(check_msg->rle_list[67] == 4, + "incorrect value for rle_list[67], expected 4, is %d", + check_msg->rle_list[67]); + ck_assert_msg(check_msg->rle_list[68] == 230, + "incorrect value for rle_list[68], expected 230, is %d", + check_msg->rle_list[68]); + ck_assert_msg(check_msg->rle_list[69] == 164, + "incorrect value for rle_list[69], expected 164, is %d", + check_msg->rle_list[69]); + ck_assert_msg(check_msg->rle_list[70] == 171, + "incorrect value for rle_list[70], expected 171, is %d", + check_msg->rle_list[70]); + ck_assert_msg(check_msg->rle_list[71] == 78, + "incorrect value for rle_list[71], expected 78, is %d", + check_msg->rle_list[71]); + ck_assert_msg(check_msg->rle_list[72] == 185, + "incorrect value for rle_list[72], expected 185, is %d", + check_msg->rle_list[72]); + ck_assert_msg(check_msg->rle_list[73] == 90, + "incorrect value for rle_list[73], expected 90, is %d", + check_msg->rle_list[73]); + ck_assert_msg(check_msg->rle_list[74] == 46, + "incorrect value for rle_list[74], expected 46, is %d", + check_msg->rle_list[74]); + ck_assert_msg(check_msg->rle_list[75] == 177, + "incorrect value for rle_list[75], expected 177, is %d", + check_msg->rle_list[75]); + ck_assert_msg(check_msg->rle_list[76] == 82, + "incorrect value for rle_list[76], expected 82, is %d", + check_msg->rle_list[76]); + ck_assert_msg(check_msg->rle_list[77] == 228, + "incorrect value for rle_list[77], expected 228, is %d", + check_msg->rle_list[77]); + ck_assert_msg(check_msg->rle_list[78] == 123, + "incorrect value for rle_list[78], expected 123, is %d", + check_msg->rle_list[78]); + ck_assert_msg(check_msg->rle_list[79] == 222, + "incorrect value for rle_list[79], expected 222, is %d", + check_msg->rle_list[79]); + ck_assert_msg(check_msg->rle_list[80] == 227, + "incorrect value for rle_list[80], expected 227, is %d", + check_msg->rle_list[80]); + ck_assert_msg(check_msg->rle_list[81] == 145, + "incorrect value for rle_list[81], expected 145, is %d", + check_msg->rle_list[81]); + ck_assert_msg(check_msg->rle_list[82] == 195, + "incorrect value for rle_list[82], expected 195, is %d", + check_msg->rle_list[82]); + ck_assert_msg(check_msg->rle_list[83] == 219, + "incorrect value for rle_list[83], expected 219, is %d", + check_msg->rle_list[83]); + ck_assert_msg(check_msg->rle_list[84] == 27, + "incorrect value for rle_list[84], expected 27, is %d", + check_msg->rle_list[84]); + ck_assert_msg(check_msg->rle_list[85] == 56, + "incorrect value for rle_list[85], expected 56, is %d", + check_msg->rle_list[85]); + ck_assert_msg(check_msg->rle_list[86] == 227, + "incorrect value for rle_list[86], expected 227, is %d", + check_msg->rle_list[86]); + ck_assert_msg(check_msg->rle_list[87] == 246, + "incorrect value for rle_list[87], expected 246, is %d", + check_msg->rle_list[87]); + ck_assert_msg(check_msg->rle_list[88] == 215, + "incorrect value for rle_list[88], expected 215, is %d", + check_msg->rle_list[88]); + ck_assert_msg(check_msg->rle_list[89] == 144, + "incorrect value for rle_list[89], expected 144, is %d", + check_msg->rle_list[89]); + ck_assert_msg(check_msg->rle_list[90] == 158, + "incorrect value for rle_list[90], expected 158, is %d", + check_msg->rle_list[90]); + ck_assert_msg(check_msg->rle_list[91] == 31, + "incorrect value for rle_list[91], expected 31, is %d", + check_msg->rle_list[91]); + ck_assert_msg(check_msg->rle_list[92] == 214, + "incorrect value for rle_list[92], expected 214, is %d", + check_msg->rle_list[92]); + ck_assert_msg(check_msg->rle_list[93] == 241, + "incorrect value for rle_list[93], expected 241, is %d", + check_msg->rle_list[93]); + ck_assert_msg(check_msg->rle_list[94] == 254, + "incorrect value for rle_list[94], expected 254, is %d", + check_msg->rle_list[94]); + ck_assert_msg(check_msg->rle_list[95] == 200, + "incorrect value for rle_list[95], expected 200, is %d", + check_msg->rle_list[95]); + ck_assert_msg(check_msg->rle_list[96] == 86, + "incorrect value for rle_list[96], expected 86, is %d", + check_msg->rle_list[96]); + ck_assert_msg(check_msg->rle_list[97] == 142, + "incorrect value for rle_list[97], expected 142, is %d", + check_msg->rle_list[97]); + ck_assert_msg(check_msg->rle_list[98] == 89, + "incorrect value for rle_list[98], expected 89, is %d", + check_msg->rle_list[98]); + ck_assert_msg(check_msg->rle_list[99] == 12, + "incorrect value for rle_list[99], expected 12, is %d", + check_msg->rle_list[99]); + ck_assert_msg(check_msg->rle_list[100] == 121, + "incorrect value for rle_list[100], expected 121, is %d", + check_msg->rle_list[100]); + ck_assert_msg(check_msg->rle_list[101] == 29, + "incorrect value for rle_list[101], expected 29, is %d", + check_msg->rle_list[101]); + ck_assert_msg(check_msg->rle_list[102] == 124, + "incorrect value for rle_list[102], expected 124, is %d", + check_msg->rle_list[102]); + ck_assert_msg(check_msg->rle_list[103] == 9, + "incorrect value for rle_list[103], expected 9, is %d", + check_msg->rle_list[103]); + ck_assert_msg(check_msg->rle_list[104] == 19, + "incorrect value for rle_list[104], expected 19, is %d", + check_msg->rle_list[104]); + ck_assert_msg(check_msg->rle_list[105] == 153, + "incorrect value for rle_list[105], expected 153, is %d", + check_msg->rle_list[105]); + ck_assert_msg(check_msg->rle_list[106] == 44, + "incorrect value for rle_list[106], expected 44, is %d", + check_msg->rle_list[106]); + ck_assert_msg(check_msg->rle_list[107] == 35, + "incorrect value for rle_list[107], expected 35, is %d", + check_msg->rle_list[107]); + ck_assert_msg(check_msg->rle_list[108] == 126, + "incorrect value for rle_list[108], expected 126, is %d", + check_msg->rle_list[108]); + ck_assert_msg(check_msg->rle_list[109] == 14, + "incorrect value for rle_list[109], expected 14, is %d", + check_msg->rle_list[109]); + ck_assert_msg(check_msg->rle_list[110] == 217, + "incorrect value for rle_list[110], expected 217, is %d", + check_msg->rle_list[110]); + ck_assert_msg(check_msg->rle_list[111] == 65, + "incorrect value for rle_list[111], expected 65, is %d", + check_msg->rle_list[111]); + ck_assert_msg(check_msg->rle_list[112] == 116, + "incorrect value for rle_list[112], expected 116, is %d", + check_msg->rle_list[112]); + ck_assert_msg(check_msg->rle_list[113] == 26, + "incorrect value for rle_list[113], expected 26, is %d", + check_msg->rle_list[113]); + ck_assert_msg(check_msg->rle_list[114] == 139, + "incorrect value for rle_list[114], expected 139, is %d", + check_msg->rle_list[114]); + ck_assert_msg(check_msg->rle_list[115] == 122, + "incorrect value for rle_list[115], expected 122, is %d", + check_msg->rle_list[115]); + ck_assert_msg(check_msg->rle_list[116] == 114, + "incorrect value for rle_list[116], expected 114, is %d", + check_msg->rle_list[116]); + ck_assert_msg(check_msg->rle_list[117] == 90, + "incorrect value for rle_list[117], expected 90, is %d", + check_msg->rle_list[117]); + ck_assert_msg(check_msg->rle_list[118] == 124, + "incorrect value for rle_list[118], expected 124, is %d", + check_msg->rle_list[118]); + ck_assert_msg(check_msg->rle_list[119] == 81, + "incorrect value for rle_list[119], expected 81, is %d", + check_msg->rle_list[119]); + ck_assert_msg(check_msg->rle_list[120] == 0, + "incorrect value for rle_list[120], expected 0, is %d", + check_msg->rle_list[120]); + ck_assert_msg(check_msg->rle_list[121] == 186, + "incorrect value for rle_list[121], expected 186, is %d", + check_msg->rle_list[121]); + ck_assert_msg(check_msg->rle_list[122] == 246, + "incorrect value for rle_list[122], expected 246, is %d", + check_msg->rle_list[122]); + ck_assert_msg(check_msg->rle_list[123] == 46, + "incorrect value for rle_list[123], expected 46, is %d", + check_msg->rle_list[123]); + ck_assert_msg(check_msg->rle_list[124] == 98, + "incorrect value for rle_list[124], expected 98, is %d", + check_msg->rle_list[124]); + ck_assert_msg(check_msg->rle_list[125] == 179, + "incorrect value for rle_list[125], expected 179, is %d", + check_msg->rle_list[125]); + ck_assert_msg(check_msg->rle_list[126] == 243, + "incorrect value for rle_list[126], expected 243, is %d", + check_msg->rle_list[126]); + ck_assert_msg(check_msg->rle_list[127] == 198, + "incorrect value for rle_list[127], expected 198, is %d", + check_msg->rle_list[127]); + ck_assert_msg(check_msg->rle_list[128] == 217, + "incorrect value for rle_list[128], expected 217, is %d", + check_msg->rle_list[128]); + ck_assert_msg(check_msg->rle_list[129] == 36, + "incorrect value for rle_list[129], expected 36, is %d", + check_msg->rle_list[129]); + ck_assert_msg(check_msg->rle_list[130] == 30, + "incorrect value for rle_list[130], expected 30, is %d", + check_msg->rle_list[130]); + ck_assert_msg(check_msg->rle_list[131] == 202, + "incorrect value for rle_list[131], expected 202, is %d", + check_msg->rle_list[131]); + ck_assert_msg(check_msg->rle_list[132] == 12, + "incorrect value for rle_list[132], expected 12, is %d", + check_msg->rle_list[132]); + ck_assert_msg(check_msg->rle_list[133] == 135, + "incorrect value for rle_list[133], expected 135, is %d", + check_msg->rle_list[133]); + ck_assert_msg(check_msg->rle_list[134] == 61, + "incorrect value for rle_list[134], expected 61, is %d", + check_msg->rle_list[134]); + ck_assert_msg(check_msg->rle_list[135] == 42, + "incorrect value for rle_list[135], expected 42, is %d", + check_msg->rle_list[135]); + ck_assert_msg(check_msg->rle_list[136] == 150, + "incorrect value for rle_list[136], expected 150, is %d", + check_msg->rle_list[136]); + ck_assert_msg(check_msg->rle_list[137] == 221, + "incorrect value for rle_list[137], expected 221, is %d", + check_msg->rle_list[137]); + ck_assert_msg(check_msg->rle_list[138] == 102, + "incorrect value for rle_list[138], expected 102, is %d", + check_msg->rle_list[138]); + ck_assert_msg(check_msg->rle_list[139] == 83, + "incorrect value for rle_list[139], expected 83, is %d", + check_msg->rle_list[139]); + ck_assert_msg(check_msg->rle_list[140] == 179, + "incorrect value for rle_list[140], expected 179, is %d", + check_msg->rle_list[140]); + ck_assert_msg(check_msg->rle_list[141] == 43, + "incorrect value for rle_list[141], expected 43, is %d", + check_msg->rle_list[141]); + ck_assert_msg(check_msg->rle_list[142] == 252, + "incorrect value for rle_list[142], expected 252, is %d", + check_msg->rle_list[142]); + ck_assert_msg(check_msg->rle_list[143] == 81, + "incorrect value for rle_list[143], expected 81, is %d", + check_msg->rle_list[143]); + ck_assert_msg(check_msg->rle_list[144] == 62, + "incorrect value for rle_list[144], expected 62, is %d", + check_msg->rle_list[144]); + ck_assert_msg(check_msg->rle_list[145] == 126, + "incorrect value for rle_list[145], expected 126, is %d", + check_msg->rle_list[145]); + ck_assert_msg(check_msg->rle_list[146] == 204, + "incorrect value for rle_list[146], expected 204, is %d", + check_msg->rle_list[146]); + ck_assert_msg(check_msg->rle_list[147] == 195, + "incorrect value for rle_list[147], expected 195, is %d", + check_msg->rle_list[147]); + ck_assert_msg(check_msg->rle_list[148] == 238, + "incorrect value for rle_list[148], expected 238, is %d", + check_msg->rle_list[148]); + ck_assert_msg(check_msg->rle_list[149] == 18, + "incorrect value for rle_list[149], expected 18, is %d", + check_msg->rle_list[149]); + ck_assert_msg(check_msg->rle_list[150] == 128, + "incorrect value for rle_list[150], expected 128, is %d", + check_msg->rle_list[150]); + ck_assert_msg(check_msg->rle_list[151] == 193, + "incorrect value for rle_list[151], expected 193, is %d", + check_msg->rle_list[151]); + ck_assert_msg(check_msg->rle_list[152] == 53, + "incorrect value for rle_list[152], expected 53, is %d", + check_msg->rle_list[152]); + ck_assert_msg(check_msg->rle_list[153] == 94, + "incorrect value for rle_list[153], expected 94, is %d", + check_msg->rle_list[153]); + ck_assert_msg(check_msg->rle_list[154] == 99, + "incorrect value for rle_list[154], expected 99, is %d", + check_msg->rle_list[154]); + ck_assert_msg(check_msg->rle_list[155] == 63, + "incorrect value for rle_list[155], expected 63, is %d", + check_msg->rle_list[155]); + ck_assert_msg(check_msg->rle_list[156] == 182, + "incorrect value for rle_list[156], expected 182, is %d", + check_msg->rle_list[156]); + ck_assert_msg(check_msg->rle_list[157] == 2, + "incorrect value for rle_list[157], expected 2, is %d", + check_msg->rle_list[157]); + ck_assert_msg(check_msg->rle_list[158] == 186, + "incorrect value for rle_list[158], expected 186, is %d", + check_msg->rle_list[158]); + ck_assert_msg(check_msg->rle_list[159] == 220, + "incorrect value for rle_list[159], expected 220, is %d", + check_msg->rle_list[159]); + ck_assert_msg(check_msg->rle_list[160] == 77, + "incorrect value for rle_list[160], expected 77, is %d", + check_msg->rle_list[160]); + ck_assert_msg(check_msg->rle_list[161] == 186, + "incorrect value for rle_list[161], expected 186, is %d", + check_msg->rle_list[161]); + ck_assert_msg(check_msg->rle_list[162] == 224, + "incorrect value for rle_list[162], expected 224, is %d", + check_msg->rle_list[162]); + ck_assert_msg(check_msg->rle_list[163] == 220, + "incorrect value for rle_list[163], expected 220, is %d", + check_msg->rle_list[163]); + ck_assert_msg(check_msg->rle_list[164] == 13, + "incorrect value for rle_list[164], expected 13, is %d", + check_msg->rle_list[164]); + ck_assert_msg(check_msg->rle_list[165] == 212, + "incorrect value for rle_list[165], expected 212, is %d", + check_msg->rle_list[165]); + ck_assert_msg(check_msg->rle_list[166] == 182, + "incorrect value for rle_list[166], expected 182, is %d", + check_msg->rle_list[166]); + ck_assert_msg(check_msg->rle_list[167] == 88, + "incorrect value for rle_list[167], expected 88, is %d", + check_msg->rle_list[167]); + ck_assert_msg(check_msg->rle_list[168] == 15, + "incorrect value for rle_list[168], expected 15, is %d", + check_msg->rle_list[168]); + ck_assert_msg(check_msg->rle_list[169] == 151, + "incorrect value for rle_list[169], expected 151, is %d", + check_msg->rle_list[169]); + ck_assert_msg(check_msg->rle_list[170] == 5, + "incorrect value for rle_list[170], expected 5, is %d", + check_msg->rle_list[170]); + ck_assert_msg(check_msg->rle_list[171] == 93, + "incorrect value for rle_list[171], expected 93, is %d", + check_msg->rle_list[171]); + ck_assert_msg(check_msg->rle_list[172] == 251, + "incorrect value for rle_list[172], expected 251, is %d", + check_msg->rle_list[172]); + ck_assert_msg(check_msg->rle_list[173] == 164, + "incorrect value for rle_list[173], expected 164, is %d", + check_msg->rle_list[173]); + ck_assert_msg(check_msg->rle_list[174] == 18, + "incorrect value for rle_list[174], expected 18, is %d", + check_msg->rle_list[174]); + ck_assert_msg(check_msg->rle_list[175] == 228, + "incorrect value for rle_list[175], expected 228, is %d", + check_msg->rle_list[175]); + ck_assert_msg(check_msg->rle_list[176] == 168, + "incorrect value for rle_list[176], expected 168, is %d", + check_msg->rle_list[176]); + ck_assert_msg(check_msg->rle_list[177] == 226, + "incorrect value for rle_list[177], expected 226, is %d", + check_msg->rle_list[177]); + ck_assert_msg(check_msg->rle_list[178] == 195, + "incorrect value for rle_list[178], expected 195, is %d", + check_msg->rle_list[178]); + ck_assert_msg(check_msg->rle_list[179] == 44, + "incorrect value for rle_list[179], expected 44, is %d", + check_msg->rle_list[179]); + ck_assert_msg(check_msg->rle_list[180] == 170, + "incorrect value for rle_list[180], expected 170, is %d", + check_msg->rle_list[180]); + ck_assert_msg(check_msg->rle_list[181] == 145, + "incorrect value for rle_list[181], expected 145, is %d", + check_msg->rle_list[181]); + ck_assert_msg(check_msg->rle_list[182] == 36, + "incorrect value for rle_list[182], expected 36, is %d", + check_msg->rle_list[182]); + ck_assert_msg(check_msg->rle_list[183] == 58, + "incorrect value for rle_list[183], expected 58, is %d", + check_msg->rle_list[183]); + ck_assert_msg(check_msg->rle_list[184] == 96, + "incorrect value for rle_list[184], expected 96, is %d", + check_msg->rle_list[184]); + ck_assert_msg(check_msg->rle_list[185] == 107, + "incorrect value for rle_list[185], expected 107, is %d", + check_msg->rle_list[185]); + ck_assert_msg(check_msg->rle_list[186] == 144, + "incorrect value for rle_list[186], expected 144, is %d", + check_msg->rle_list[186]); + ck_assert_msg(check_msg->rle_list[187] == 11, + "incorrect value for rle_list[187], expected 11, is %d", + check_msg->rle_list[187]); + ck_assert_msg(check_msg->rle_list[188] == 228, + "incorrect value for rle_list[188], expected 228, is %d", + check_msg->rle_list[188]); + ck_assert_msg(check_msg->rle_list[189] == 12, + "incorrect value for rle_list[189], expected 12, is %d", + check_msg->rle_list[189]); + ck_assert_msg(check_msg->rle_list[190] == 163, + "incorrect value for rle_list[190], expected 163, is %d", + check_msg->rle_list[190]); + ck_assert_msg(check_msg->rle_list[191] == 238, + "incorrect value for rle_list[191], expected 238, is %d", + check_msg->rle_list[191]); + ck_assert_msg(check_msg->rle_list[192] == 247, + "incorrect value for rle_list[192], expected 247, is %d", + check_msg->rle_list[192]); + ck_assert_msg(check_msg->rle_list[193] == 159, + "incorrect value for rle_list[193], expected 159, is %d", + check_msg->rle_list[193]); + ck_assert_msg(check_msg->rle_list[194] == 189, + "incorrect value for rle_list[194], expected 189, is %d", + check_msg->rle_list[194]); + ck_assert_msg(check_msg->rle_list[195] == 1, + "incorrect value for rle_list[195], expected 1, is %d", + check_msg->rle_list[195]); + ck_assert_msg(check_msg->rle_list[196] == 115, + "incorrect value for rle_list[196], expected 115, is %d", + check_msg->rle_list[196]); + ck_assert_msg(check_msg->rle_list[197] == 65, + "incorrect value for rle_list[197], expected 65, is %d", + check_msg->rle_list[197]); + ck_assert_msg(check_msg->rle_list[198] == 202, + "incorrect value for rle_list[198], expected 202, is %d", + check_msg->rle_list[198]); + ck_assert_msg(check_msg->rle_list[199] == 121, + "incorrect value for rle_list[199], expected 121, is %d", + check_msg->rle_list[199]); + ck_assert_msg(check_msg->rle_list[200] == 47, + "incorrect value for rle_list[200], expected 47, is %d", + check_msg->rle_list[200]); + ck_assert_msg(check_msg->rle_list[201] == 193, + "incorrect value for rle_list[201], expected 193, is %d", + check_msg->rle_list[201]); + ck_assert_msg(check_msg->rle_list[202] == 11, + "incorrect value for rle_list[202], expected 11, is %d", + check_msg->rle_list[202]); + ck_assert_msg(check_msg->rle_list[203] == 96, + "incorrect value for rle_list[203], expected 96, is %d", + check_msg->rle_list[203]); + ck_assert_msg(check_msg->rle_list[204] == 93, + "incorrect value for rle_list[204], expected 93, is %d", + check_msg->rle_list[204]); + ck_assert_msg(check_msg->rle_list[205] == 72, + "incorrect value for rle_list[205], expected 72, is %d", + check_msg->rle_list[205]); + ck_assert_msg(check_msg->rle_list[206] == 81, + "incorrect value for rle_list[206], expected 81, is %d", + check_msg->rle_list[206]); + ck_assert_msg(check_msg->rle_list[207] == 207, + "incorrect value for rle_list[207], expected 207, is %d", + check_msg->rle_list[207]); + ck_assert_msg(check_msg->rle_list[208] == 121, + "incorrect value for rle_list[208], expected 121, is %d", + check_msg->rle_list[208]); + ck_assert_msg(check_msg->rle_list[209] == 19, + "incorrect value for rle_list[209], expected 19, is %d", + check_msg->rle_list[209]); + ck_assert_msg(check_msg->rle_list[210] == 151, + "incorrect value for rle_list[210], expected 151, is %d", + check_msg->rle_list[210]); + ck_assert_msg(check_msg->rle_list[211] == 136, + "incorrect value for rle_list[211], expected 136, is %d", + check_msg->rle_list[211]); + ck_assert_msg(check_msg->rle_list[212] == 233, + "incorrect value for rle_list[212], expected 233, is %d", + check_msg->rle_list[212]); + ck_assert_msg(check_msg->rle_list[213] == 51, + "incorrect value for rle_list[213], expected 51, is %d", + check_msg->rle_list[213]); + ck_assert_msg(check_msg->rle_list[214] == 133, + "incorrect value for rle_list[214], expected 133, is %d", + check_msg->rle_list[214]); + ck_assert_msg(check_msg->rle_list[215] == 195, + "incorrect value for rle_list[215], expected 195, is %d", + check_msg->rle_list[215]); + ck_assert_msg(check_msg->rle_list[216] == 77, + "incorrect value for rle_list[216], expected 77, is %d", + check_msg->rle_list[216]); + ck_assert_msg(check_msg->rle_list[217] == 44, + "incorrect value for rle_list[217], expected 44, is %d", + check_msg->rle_list[217]); + ck_assert_msg(check_msg->rle_list[218] == 147, + "incorrect value for rle_list[218], expected 147, is %d", + check_msg->rle_list[218]); + ck_assert_msg(check_msg->rle_list[219] == 206, + "incorrect value for rle_list[219], expected 206, is %d", + check_msg->rle_list[219]); + ck_assert_msg(check_msg->rle_list[220] == 120, + "incorrect value for rle_list[220], expected 120, is %d", + check_msg->rle_list[220]); + ck_assert_msg(check_msg->rle_list[221] == 252, + "incorrect value for rle_list[221], expected 252, is %d", + check_msg->rle_list[221]); + ck_assert_msg(check_msg->rle_list[222] == 77, + "incorrect value for rle_list[222], expected 77, is %d", + check_msg->rle_list[222]); + ck_assert_msg(check_msg->rle_list[223] == 212, + "incorrect value for rle_list[223], expected 212, is %d", + check_msg->rle_list[223]); + ck_assert_msg(check_msg->rle_list[224] == 68, + "incorrect value for rle_list[224], expected 68, is %d", + check_msg->rle_list[224]); + ck_assert_msg(check_msg->rle_list[225] == 60, + "incorrect value for rle_list[225], expected 60, is %d", + check_msg->rle_list[225]); + ck_assert_msg(check_msg->rle_list[226] == 206, + "incorrect value for rle_list[226], expected 206, is %d", + check_msg->rle_list[226]); + ck_assert_msg(check_msg->rle_list[227] == 106, + "incorrect value for rle_list[227], expected 106, is %d", + check_msg->rle_list[227]); + ck_assert_msg(check_msg->rle_list[228] == 207, + "incorrect value for rle_list[228], expected 207, is %d", + check_msg->rle_list[228]); + ck_assert_msg(check_msg->rle_list[229] == 243, + "incorrect value for rle_list[229], expected 243, is %d", + check_msg->rle_list[229]); + ck_assert_msg(check_msg->rle_list[230] == 158, + "incorrect value for rle_list[230], expected 158, is %d", + check_msg->rle_list[230]); + ck_assert_msg(check_msg->rle_list[231] == 94, + "incorrect value for rle_list[231], expected 94, is %d", + check_msg->rle_list[231]); + ck_assert_msg(check_msg->rle_list[232] == 6, + "incorrect value for rle_list[232], expected 6, is %d", + check_msg->rle_list[232]); + ck_assert_msg(check_msg->rle_list[233] == 3, + "incorrect value for rle_list[233], expected 3, is %d", + check_msg->rle_list[233]); + ck_assert_msg(check_msg->rle_list[234] == 205, + "incorrect value for rle_list[234], expected 205, is %d", + check_msg->rle_list[234]); + ck_assert_msg(check_msg->rle_list[235] == 92, + "incorrect value for rle_list[235], expected 92, is %d", + check_msg->rle_list[235]); + ck_assert_msg(check_msg->rle_list[236] == 84, + "incorrect value for rle_list[236], expected 84, is %d", + check_msg->rle_list[236]); + ck_assert_msg(check_msg->rle_list[237] == 2, + "incorrect value for rle_list[237], expected 2, is %d", + check_msg->rle_list[237]); + ck_assert_msg(check_msg->rle_list[238] == 220, + "incorrect value for rle_list[238], expected 220, is %d", + check_msg->rle_list[238]); + ck_assert_msg(check_msg->rle_list[239] == 50, + "incorrect value for rle_list[239], expected 50, is %d", + check_msg->rle_list[239]); + ck_assert_msg(check_msg->rle_list[240] == 61, + "incorrect value for rle_list[240], expected 61, is %d", + check_msg->rle_list[240]); + ck_assert_msg(check_msg->rle_list[241] == 38, + "incorrect value for rle_list[241], expected 38, is %d", + check_msg->rle_list[241]); + ck_assert_msg(check_msg->rle_list[242] == 141, + "incorrect value for rle_list[242], expected 141, is %d", + check_msg->rle_list[242]); + ck_assert_msg(check_msg->rle_list[243] == 117, + "incorrect value for rle_list[243], expected 117, is %d", + check_msg->rle_list[243]); + ck_assert_msg(check_msg->rle_list[244] == 108, + "incorrect value for rle_list[244], expected 108, is %d", + check_msg->rle_list[244]); + ck_assert_msg(check_msg->rle_list[245] == 101, + "incorrect value for rle_list[245], expected 101, is %d", + check_msg->rle_list[245]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c new file mode 100644 index 0000000000..3ffa8a27ed --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrection.c @@ -0,0 +1,1386 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5fc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5fc, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, + 174, 229, 151, 189, 204, 196, 105, 170, 120, 149, 169, 37, 244, 78, + 72, 140, 101, 2, 173, 88, 70, 180, 54, 152, 115, 78, 201, 161, + 23, 135, 152, 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, + 230, 69, 172, 191, 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, + 52, 166, 166, 120, 57, 221, 12, 3, 156, 70, 156, 35, 127, 8, + 127, 58, 128, 55, 115, 80, 157, 122, 153, 124, 27, 128, 98, 103, + 204, 75, 238, 128, 226, 148, 248, 61, 216, 208, 149, 167, 224, 40, + 144, 186, 157, 227, 72, 240, 100, 35, 12, 212, 7, 59, 176, 81, + 86, 27, 24, 155, 67, 43, 132, 45, 203, 44, 6, 112, 183, 231, + 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, 23, 62, 227, 240, + 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, 176, 201, 202, + 91, 105, 115, 146, 59, 110, 44, 109, 128, 183, 185, 67, 31, 165, + 92, 79, 189, 180, 94, 7, 162, 121, 156, 210, 47, 7, 7, 205, + 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, 219, + 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, + 247, 64, 189, 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, + 45, 251, 239, 115, 88, 218, 10, 209, 120, 65, 175, 131, 194, 41, + 174, 137, 17, 68, 28, 253, 42, 178, 35, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_gridded_correction_t *test_msg = + (msg_ssr_gridded_correction_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.iod_atmo = 170; + test_msg->header.num_msgs = 48535; + test_msg->header.seq_num = 50380; + test_msg->header.tile_id = 12951; + test_msg->header.tile_set_id = 3605; + test_msg->header.time.tow = 2535294328; + test_msg->header.time.wn = 58798; + test_msg->header.tropo_quality_indicator = 120; + test_msg->header.update_interval = 105; + test_msg->index = 43413; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[0].residual = -21246; + test_msg->stec_residuals[0].stddev = 88; + test_msg->stec_residuals[0].sv_id.constellation = 101; + test_msg->stec_residuals[0].sv_id.satId = 140; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[1].residual = -26570; + test_msg->stec_residuals[1].stddev = 115; + test_msg->stec_residuals[1].sv_id.constellation = 180; + test_msg->stec_residuals[1].sv_id.satId = 70; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[2].residual = 6049; + test_msg->stec_residuals[2].stddev = 135; + test_msg->stec_residuals[2].sv_id.constellation = 201; + test_msg->stec_residuals[2].sv_id.satId = 78; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[3].residual = 19261; + test_msg->stec_residuals[3].stddev = 178; + test_msg->stec_residuals[3].sv_id.constellation = 98; + test_msg->stec_residuals[3].sv_id.satId = 152; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[4].residual = 14226; + test_msg->stec_residuals[4].stddev = 58; + test_msg->stec_residuals[4].sv_id.constellation = 229; + test_msg->stec_residuals[4].sv_id.satId = 120; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[5].residual = 17894; + test_msg->stec_residuals[5].stddev = 172; + test_msg->stec_residuals[5].sv_id.constellation = 234; + test_msg->stec_residuals[5].sv_id.satId = 169; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[6].residual = 22930; + test_msg->stec_residuals[6].stddev = 150; + test_msg->stec_residuals[6].sv_id.constellation = 127; + test_msg->stec_residuals[6].sv_id.satId = 191; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[7].residual = 10721; + test_msg->stec_residuals[7].stddev = 17; + test_msg->stec_residuals[7].sv_id.constellation = 111; + test_msg->stec_residuals[7].sv_id.satId = 91; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[8].residual = -22874; + test_msg->stec_residuals[8].stddev = 120; + test_msg->stec_residuals[8].sv_id.constellation = 52; + test_msg->stec_residuals[8].sv_id.satId = 119; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[9].residual = 780; + test_msg->stec_residuals[9].stddev = 156; + test_msg->stec_residuals[9].sv_id.constellation = 221; + test_msg->stec_residuals[9].sv_id.satId = 57; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[10].residual = 32547; + test_msg->stec_residuals[10].stddev = 8; + test_msg->stec_residuals[10].sv_id.constellation = 156; + test_msg->stec_residuals[10].sv_id.satId = 70; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[11].residual = 14208; + test_msg->stec_residuals[11].stddev = 115; + test_msg->stec_residuals[11].sv_id.constellation = 58; + test_msg->stec_residuals[11].sv_id.satId = 127; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[12].residual = -26246; + test_msg->stec_residuals[12].stddev = 124; + test_msg->stec_residuals[12].sv_id.constellation = 157; + test_msg->stec_residuals[12].sv_id.satId = 80; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[13].residual = 26466; + test_msg->stec_residuals[13].stddev = 204; + test_msg->stec_residuals[13].sv_id.constellation = 128; + test_msg->stec_residuals[13].sv_id.satId = 27; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[14].residual = -7552; + test_msg->stec_residuals[14].stddev = 148; + test_msg->stec_residuals[14].sv_id.constellation = 238; + test_msg->stec_residuals[14].sv_id.satId = 75; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[15].residual = -12072; + test_msg->stec_residuals[15].stddev = 149; + test_msg->stec_residuals[15].sv_id.constellation = 61; + test_msg->stec_residuals[15].sv_id.satId = 248; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[16].residual = -28632; + test_msg->stec_residuals[16].stddev = 186; + test_msg->stec_residuals[16].sv_id.constellation = 224; + test_msg->stec_residuals[16].sv_id.satId = 167; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[17].residual = -4024; + test_msg->stec_residuals[17].stddev = 100; + test_msg->stec_residuals[17].sv_id.constellation = 227; + test_msg->stec_residuals[17].sv_id.satId = 157; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[18].residual = 2004; + test_msg->stec_residuals[18].stddev = 59; + test_msg->stec_residuals[18].sv_id.constellation = 12; + test_msg->stec_residuals[18].sv_id.satId = 35; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[19].residual = 6998; + test_msg->stec_residuals[19].stddev = 24; + test_msg->stec_residuals[19].sv_id.constellation = 81; + test_msg->stec_residuals[19].sv_id.satId = 176; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[20].residual = -31701; + test_msg->stec_residuals[20].stddev = 45; + test_msg->stec_residuals[20].sv_id.constellation = 67; + test_msg->stec_residuals[20].sv_id.satId = 155; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[21].residual = 28678; + test_msg->stec_residuals[21].stddev = 183; + test_msg->stec_residuals[21].sv_id.constellation = 44; + test_msg->stec_residuals[21].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[22].residual = -15793; + test_msg->stec_residuals[22].stddev = 253; + test_msg->stec_residuals[22].sv_id.constellation = 176; + test_msg->stec_residuals[22].sv_id.satId = 231; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[23].residual = -7589; + test_msg->stec_residuals[23].stddev = 116; + test_msg->stec_residuals[23].sv_id.constellation = 103; + test_msg->stec_residuals[23].sv_id.satId = 247; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[24].residual = -7362; + test_msg->stec_residuals[24].stddev = 240; + test_msg->stec_residuals[24].sv_id.constellation = 23; + test_msg->stec_residuals[24].sv_id.satId = 148; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[25].residual = 4813; + test_msg->stec_residuals[25].stddev = 242; + test_msg->stec_residuals[25].sv_id.constellation = 219; + test_msg->stec_residuals[25].sv_id.satId = 29; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[26].residual = 20295; + test_msg->stec_residuals[26].stddev = 37; + test_msg->stec_residuals[26].sv_id.constellation = 72; + test_msg->stec_residuals[26].sv_id.satId = 207; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[27].residual = -13623; + test_msg->stec_residuals[27].stddev = 91; + test_msg->stec_residuals[27].sv_id.constellation = 176; + test_msg->stec_residuals[27].sv_id.satId = 42; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[28].residual = 15250; + test_msg->stec_residuals[28].stddev = 110; + test_msg->stec_residuals[28].sv_id.constellation = 115; + test_msg->stec_residuals[28].sv_id.satId = 105; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[29].residual = -18560; + test_msg->stec_residuals[29].stddev = 185; + test_msg->stec_residuals[29].sv_id.constellation = 109; + test_msg->stec_residuals[29].sv_id.satId = 44; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[30].residual = 23717; + test_msg->stec_residuals[30].stddev = 79; + test_msg->stec_residuals[30].sv_id.constellation = 31; + test_msg->stec_residuals[30].sv_id.satId = 67; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[31].residual = 1886; + test_msg->stec_residuals[31].stddev = 162; + test_msg->stec_residuals[31].sv_id.constellation = 180; + test_msg->stec_residuals[31].sv_id.satId = 189; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[32].residual = 12242; + test_msg->stec_residuals[32].stddev = 7; + test_msg->stec_residuals[32].sv_id.constellation = 156; + test_msg->stec_residuals[32].sv_id.satId = 121; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[33].residual = 10670; + test_msg->stec_residuals[33].stddev = 241; + test_msg->stec_residuals[33].sv_id.constellation = 205; + test_msg->stec_residuals[33].sv_id.satId = 7; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[34].residual = 25899; + test_msg->stec_residuals[34].stddev = 186; + test_msg->stec_residuals[34].sv_id.constellation = 210; + test_msg->stec_residuals[34].sv_id.satId = 129; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[35].residual = -2078; + test_msg->stec_residuals[35].stddev = 187; + test_msg->stec_residuals[35].sv_id.constellation = 195; + test_msg->stec_residuals[35].sv_id.satId = 208; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[36].residual = -16264; + test_msg->stec_residuals[36].stddev = 102; + test_msg->stec_residuals[36].sv_id.constellation = 160; + test_msg->stec_residuals[36].sv_id.satId = 219; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[37].residual = -21002; + test_msg->stec_residuals[37].stddev = 94; + test_msg->stec_residuals[37].sv_id.constellation = 42; + test_msg->stec_residuals[37].sv_id.satId = 166; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[38].residual = 7902; + test_msg->stec_residuals[38].stddev = 35; + test_msg->stec_residuals[38].sv_id.constellation = 156; + test_msg->stec_residuals[38].sv_id.satId = 102; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[39].residual = -30275; + test_msg->stec_residuals[39].stddev = 204; + test_msg->stec_residuals[39].sv_id.constellation = 64; + test_msg->stec_residuals[39].sv_id.satId = 247; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[40].residual = -8633; + test_msg->stec_residuals[40].stddev = 222; + test_msg->stec_residuals[40].sv_id.constellation = 32; + test_msg->stec_residuals[40].sv_id.satId = 220; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[41].residual = 6403; + test_msg->stec_residuals[41].stddev = 45; + test_msg->stec_residuals[41].sv_id.constellation = 246; + test_msg->stec_residuals[41].sv_id.satId = 201; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[42].residual = 22643; + test_msg->stec_residuals[42].stddev = 218; + test_msg->stec_residuals[42].sv_id.constellation = 239; + test_msg->stec_residuals[42].sv_id.satId = 251; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[43].residual = 16760; + test_msg->stec_residuals[43].stddev = 175; + test_msg->stec_residuals[43].sv_id.constellation = 209; + test_msg->stec_residuals[43].sv_id.satId = 10; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[44].residual = -20951; + test_msg->stec_residuals[44].stddev = 137; + test_msg->stec_residuals[44].sv_id.constellation = 194; + test_msg->stec_residuals[44].sv_id.satId = 131; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[45].residual = -740; + test_msg->stec_residuals[45].stddev = 42; + test_msg->stec_residuals[45].sv_id.constellation = 68; + test_msg->stec_residuals[45].sv_id.satId = 17; + test_msg->tropo_delay_correction.hydro = -3035; + test_msg->tropo_delay_correction.stddev = 72; + test_msg->tropo_delay_correction.wet = 78; + sbp_payload_send(&sbp_state, 0x5fc, 63940, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 63940, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 63940, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5fc, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_gridded_correction_t *check_msg = + (msg_ssr_gridded_correction_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->header.iod_atmo == 170, + "incorrect value for header.iod_atmo, expected 170, is %d", + check_msg->header.iod_atmo); + ck_assert_msg(check_msg->header.num_msgs == 48535, + "incorrect value for header.num_msgs, expected 48535, is %d", + check_msg->header.num_msgs); + ck_assert_msg(check_msg->header.seq_num == 50380, + "incorrect value for header.seq_num, expected 50380, is %d", + check_msg->header.seq_num); + ck_assert_msg(check_msg->header.tile_id == 12951, + "incorrect value for header.tile_id, expected 12951, is %d", + check_msg->header.tile_id); + ck_assert_msg( + check_msg->header.tile_set_id == 3605, + "incorrect value for header.tile_set_id, expected 3605, is %d", + check_msg->header.tile_set_id); + ck_assert_msg( + check_msg->header.time.tow == 2535294328, + "incorrect value for header.time.tow, expected 2535294328, is %d", + check_msg->header.time.tow); + ck_assert_msg(check_msg->header.time.wn == 58798, + "incorrect value for header.time.wn, expected 58798, is %d", + check_msg->header.time.wn); + ck_assert_msg(check_msg->header.tropo_quality_indicator == 120, + "incorrect value for header.tropo_quality_indicator, " + "expected 120, is %d", + check_msg->header.tropo_quality_indicator); + ck_assert_msg( + check_msg->header.update_interval == 105, + "incorrect value for header.update_interval, expected 105, is %d", + check_msg->header.update_interval); + ck_assert_msg(check_msg->index == 43413, + "incorrect value for index, expected 43413, is %d", + check_msg->index); + ck_assert_msg(check_msg->stec_residuals[0].residual == -21246, + "incorrect value for stec_residuals[0].residual, expected " + "-21246, is %d", + check_msg->stec_residuals[0].residual); + ck_assert_msg( + check_msg->stec_residuals[0].stddev == 88, + "incorrect value for stec_residuals[0].stddev, expected 88, is %d", + check_msg->stec_residuals[0].stddev); + ck_assert_msg(check_msg->stec_residuals[0].sv_id.constellation == 101, + "incorrect value for stec_residuals[0].sv_id.constellation, " + "expected 101, is %d", + check_msg->stec_residuals[0].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[0].sv_id.satId == 140, + "incorrect value for stec_residuals[0].sv_id.satId, expected " + "140, is %d", + check_msg->stec_residuals[0].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[1].residual == -26570, + "incorrect value for stec_residuals[1].residual, expected " + "-26570, is %d", + check_msg->stec_residuals[1].residual); + ck_assert_msg( + check_msg->stec_residuals[1].stddev == 115, + "incorrect value for stec_residuals[1].stddev, expected 115, is %d", + check_msg->stec_residuals[1].stddev); + ck_assert_msg(check_msg->stec_residuals[1].sv_id.constellation == 180, + "incorrect value for stec_residuals[1].sv_id.constellation, " + "expected 180, is %d", + check_msg->stec_residuals[1].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[1].sv_id.satId == 70, + "incorrect value for stec_residuals[1].sv_id.satId, expected 70, is %d", + check_msg->stec_residuals[1].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[2].residual == 6049, + "incorrect value for stec_residuals[2].residual, expected 6049, is %d", + check_msg->stec_residuals[2].residual); + ck_assert_msg( + check_msg->stec_residuals[2].stddev == 135, + "incorrect value for stec_residuals[2].stddev, expected 135, is %d", + check_msg->stec_residuals[2].stddev); + ck_assert_msg(check_msg->stec_residuals[2].sv_id.constellation == 201, + "incorrect value for stec_residuals[2].sv_id.constellation, " + "expected 201, is %d", + check_msg->stec_residuals[2].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[2].sv_id.satId == 78, + "incorrect value for stec_residuals[2].sv_id.satId, expected 78, is %d", + check_msg->stec_residuals[2].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[3].residual == 19261, + "incorrect value for stec_residuals[3].residual, expected 19261, is %d", + check_msg->stec_residuals[3].residual); + ck_assert_msg( + check_msg->stec_residuals[3].stddev == 178, + "incorrect value for stec_residuals[3].stddev, expected 178, is %d", + check_msg->stec_residuals[3].stddev); + ck_assert_msg(check_msg->stec_residuals[3].sv_id.constellation == 98, + "incorrect value for stec_residuals[3].sv_id.constellation, " + "expected 98, is %d", + check_msg->stec_residuals[3].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[3].sv_id.satId == 152, + "incorrect value for stec_residuals[3].sv_id.satId, expected " + "152, is %d", + check_msg->stec_residuals[3].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[4].residual == 14226, + "incorrect value for stec_residuals[4].residual, expected 14226, is %d", + check_msg->stec_residuals[4].residual); + ck_assert_msg( + check_msg->stec_residuals[4].stddev == 58, + "incorrect value for stec_residuals[4].stddev, expected 58, is %d", + check_msg->stec_residuals[4].stddev); + ck_assert_msg(check_msg->stec_residuals[4].sv_id.constellation == 229, + "incorrect value for stec_residuals[4].sv_id.constellation, " + "expected 229, is %d", + check_msg->stec_residuals[4].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[4].sv_id.satId == 120, + "incorrect value for stec_residuals[4].sv_id.satId, expected " + "120, is %d", + check_msg->stec_residuals[4].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[5].residual == 17894, + "incorrect value for stec_residuals[5].residual, expected 17894, is %d", + check_msg->stec_residuals[5].residual); + ck_assert_msg( + check_msg->stec_residuals[5].stddev == 172, + "incorrect value for stec_residuals[5].stddev, expected 172, is %d", + check_msg->stec_residuals[5].stddev); + ck_assert_msg(check_msg->stec_residuals[5].sv_id.constellation == 234, + "incorrect value for stec_residuals[5].sv_id.constellation, " + "expected 234, is %d", + check_msg->stec_residuals[5].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[5].sv_id.satId == 169, + "incorrect value for stec_residuals[5].sv_id.satId, expected " + "169, is %d", + check_msg->stec_residuals[5].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[6].residual == 22930, + "incorrect value for stec_residuals[6].residual, expected 22930, is %d", + check_msg->stec_residuals[6].residual); + ck_assert_msg( + check_msg->stec_residuals[6].stddev == 150, + "incorrect value for stec_residuals[6].stddev, expected 150, is %d", + check_msg->stec_residuals[6].stddev); + ck_assert_msg(check_msg->stec_residuals[6].sv_id.constellation == 127, + "incorrect value for stec_residuals[6].sv_id.constellation, " + "expected 127, is %d", + check_msg->stec_residuals[6].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[6].sv_id.satId == 191, + "incorrect value for stec_residuals[6].sv_id.satId, expected " + "191, is %d", + check_msg->stec_residuals[6].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[7].residual == 10721, + "incorrect value for stec_residuals[7].residual, expected 10721, is %d", + check_msg->stec_residuals[7].residual); + ck_assert_msg( + check_msg->stec_residuals[7].stddev == 17, + "incorrect value for stec_residuals[7].stddev, expected 17, is %d", + check_msg->stec_residuals[7].stddev); + ck_assert_msg(check_msg->stec_residuals[7].sv_id.constellation == 111, + "incorrect value for stec_residuals[7].sv_id.constellation, " + "expected 111, is %d", + check_msg->stec_residuals[7].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[7].sv_id.satId == 91, + "incorrect value for stec_residuals[7].sv_id.satId, expected 91, is %d", + check_msg->stec_residuals[7].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[8].residual == -22874, + "incorrect value for stec_residuals[8].residual, expected " + "-22874, is %d", + check_msg->stec_residuals[8].residual); + ck_assert_msg( + check_msg->stec_residuals[8].stddev == 120, + "incorrect value for stec_residuals[8].stddev, expected 120, is %d", + check_msg->stec_residuals[8].stddev); + ck_assert_msg(check_msg->stec_residuals[8].sv_id.constellation == 52, + "incorrect value for stec_residuals[8].sv_id.constellation, " + "expected 52, is %d", + check_msg->stec_residuals[8].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[8].sv_id.satId == 119, + "incorrect value for stec_residuals[8].sv_id.satId, expected " + "119, is %d", + check_msg->stec_residuals[8].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[9].residual == 780, + "incorrect value for stec_residuals[9].residual, expected 780, is %d", + check_msg->stec_residuals[9].residual); + ck_assert_msg( + check_msg->stec_residuals[9].stddev == 156, + "incorrect value for stec_residuals[9].stddev, expected 156, is %d", + check_msg->stec_residuals[9].stddev); + ck_assert_msg(check_msg->stec_residuals[9].sv_id.constellation == 221, + "incorrect value for stec_residuals[9].sv_id.constellation, " + "expected 221, is %d", + check_msg->stec_residuals[9].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[9].sv_id.satId == 57, + "incorrect value for stec_residuals[9].sv_id.satId, expected 57, is %d", + check_msg->stec_residuals[9].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[10].residual == 32547, + "incorrect value for stec_residuals[10].residual, expected " + "32547, is %d", + check_msg->stec_residuals[10].residual); + ck_assert_msg( + check_msg->stec_residuals[10].stddev == 8, + "incorrect value for stec_residuals[10].stddev, expected 8, is %d", + check_msg->stec_residuals[10].stddev); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.constellation == 156, + "incorrect value for stec_residuals[10].sv_id.constellation, " + "expected 156, is %d", + check_msg->stec_residuals[10].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.satId == 70, + "incorrect value for stec_residuals[10].sv_id.satId, " + "expected 70, is %d", + check_msg->stec_residuals[10].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[11].residual == 14208, + "incorrect value for stec_residuals[11].residual, expected " + "14208, is %d", + check_msg->stec_residuals[11].residual); + ck_assert_msg( + check_msg->stec_residuals[11].stddev == 115, + "incorrect value for stec_residuals[11].stddev, expected 115, is %d", + check_msg->stec_residuals[11].stddev); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.constellation == 58, + "incorrect value for stec_residuals[11].sv_id.constellation, " + "expected 58, is %d", + check_msg->stec_residuals[11].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.satId == 127, + "incorrect value for stec_residuals[11].sv_id.satId, " + "expected 127, is %d", + check_msg->stec_residuals[11].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[12].residual == -26246, + "incorrect value for stec_residuals[12].residual, expected " + "-26246, is %d", + check_msg->stec_residuals[12].residual); + ck_assert_msg( + check_msg->stec_residuals[12].stddev == 124, + "incorrect value for stec_residuals[12].stddev, expected 124, is %d", + check_msg->stec_residuals[12].stddev); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.constellation == 157, + "incorrect value for stec_residuals[12].sv_id.constellation, " + "expected 157, is %d", + check_msg->stec_residuals[12].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.satId == 80, + "incorrect value for stec_residuals[12].sv_id.satId, " + "expected 80, is %d", + check_msg->stec_residuals[12].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[13].residual == 26466, + "incorrect value for stec_residuals[13].residual, expected " + "26466, is %d", + check_msg->stec_residuals[13].residual); + ck_assert_msg( + check_msg->stec_residuals[13].stddev == 204, + "incorrect value for stec_residuals[13].stddev, expected 204, is %d", + check_msg->stec_residuals[13].stddev); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.constellation == 128, + "incorrect value for stec_residuals[13].sv_id.constellation, " + "expected 128, is %d", + check_msg->stec_residuals[13].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.satId == 27, + "incorrect value for stec_residuals[13].sv_id.satId, " + "expected 27, is %d", + check_msg->stec_residuals[13].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[14].residual == -7552, + "incorrect value for stec_residuals[14].residual, expected " + "-7552, is %d", + check_msg->stec_residuals[14].residual); + ck_assert_msg( + check_msg->stec_residuals[14].stddev == 148, + "incorrect value for stec_residuals[14].stddev, expected 148, is %d", + check_msg->stec_residuals[14].stddev); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.constellation == 238, + "incorrect value for stec_residuals[14].sv_id.constellation, " + "expected 238, is %d", + check_msg->stec_residuals[14].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.satId == 75, + "incorrect value for stec_residuals[14].sv_id.satId, " + "expected 75, is %d", + check_msg->stec_residuals[14].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[15].residual == -12072, + "incorrect value for stec_residuals[15].residual, expected " + "-12072, is %d", + check_msg->stec_residuals[15].residual); + ck_assert_msg( + check_msg->stec_residuals[15].stddev == 149, + "incorrect value for stec_residuals[15].stddev, expected 149, is %d", + check_msg->stec_residuals[15].stddev); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.constellation == 61, + "incorrect value for stec_residuals[15].sv_id.constellation, " + "expected 61, is %d", + check_msg->stec_residuals[15].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.satId == 248, + "incorrect value for stec_residuals[15].sv_id.satId, " + "expected 248, is %d", + check_msg->stec_residuals[15].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[16].residual == -28632, + "incorrect value for stec_residuals[16].residual, expected " + "-28632, is %d", + check_msg->stec_residuals[16].residual); + ck_assert_msg( + check_msg->stec_residuals[16].stddev == 186, + "incorrect value for stec_residuals[16].stddev, expected 186, is %d", + check_msg->stec_residuals[16].stddev); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.constellation == 224, + "incorrect value for stec_residuals[16].sv_id.constellation, " + "expected 224, is %d", + check_msg->stec_residuals[16].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.satId == 167, + "incorrect value for stec_residuals[16].sv_id.satId, " + "expected 167, is %d", + check_msg->stec_residuals[16].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[17].residual == -4024, + "incorrect value for stec_residuals[17].residual, expected " + "-4024, is %d", + check_msg->stec_residuals[17].residual); + ck_assert_msg( + check_msg->stec_residuals[17].stddev == 100, + "incorrect value for stec_residuals[17].stddev, expected 100, is %d", + check_msg->stec_residuals[17].stddev); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.constellation == 227, + "incorrect value for stec_residuals[17].sv_id.constellation, " + "expected 227, is %d", + check_msg->stec_residuals[17].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.satId == 157, + "incorrect value for stec_residuals[17].sv_id.satId, " + "expected 157, is %d", + check_msg->stec_residuals[17].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[18].residual == 2004, + "incorrect value for stec_residuals[18].residual, expected 2004, is %d", + check_msg->stec_residuals[18].residual); + ck_assert_msg( + check_msg->stec_residuals[18].stddev == 59, + "incorrect value for stec_residuals[18].stddev, expected 59, is %d", + check_msg->stec_residuals[18].stddev); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.constellation == 12, + "incorrect value for stec_residuals[18].sv_id.constellation, " + "expected 12, is %d", + check_msg->stec_residuals[18].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.satId == 35, + "incorrect value for stec_residuals[18].sv_id.satId, " + "expected 35, is %d", + check_msg->stec_residuals[18].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[19].residual == 6998, + "incorrect value for stec_residuals[19].residual, expected 6998, is %d", + check_msg->stec_residuals[19].residual); + ck_assert_msg( + check_msg->stec_residuals[19].stddev == 24, + "incorrect value for stec_residuals[19].stddev, expected 24, is %d", + check_msg->stec_residuals[19].stddev); + ck_assert_msg(check_msg->stec_residuals[19].sv_id.constellation == 81, + "incorrect value for stec_residuals[19].sv_id.constellation, " + "expected 81, is %d", + check_msg->stec_residuals[19].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[19].sv_id.satId == 176, + "incorrect value for stec_residuals[19].sv_id.satId, " + "expected 176, is %d", + check_msg->stec_residuals[19].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[20].residual == -31701, + "incorrect value for stec_residuals[20].residual, expected " + "-31701, is %d", + check_msg->stec_residuals[20].residual); + ck_assert_msg( + check_msg->stec_residuals[20].stddev == 45, + "incorrect value for stec_residuals[20].stddev, expected 45, is %d", + check_msg->stec_residuals[20].stddev); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.constellation == 67, + "incorrect value for stec_residuals[20].sv_id.constellation, " + "expected 67, is %d", + check_msg->stec_residuals[20].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.satId == 155, + "incorrect value for stec_residuals[20].sv_id.satId, " + "expected 155, is %d", + check_msg->stec_residuals[20].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[21].residual == 28678, + "incorrect value for stec_residuals[21].residual, expected " + "28678, is %d", + check_msg->stec_residuals[21].residual); + ck_assert_msg( + check_msg->stec_residuals[21].stddev == 183, + "incorrect value for stec_residuals[21].stddev, expected 183, is %d", + check_msg->stec_residuals[21].stddev); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.constellation == 44, + "incorrect value for stec_residuals[21].sv_id.constellation, " + "expected 44, is %d", + check_msg->stec_residuals[21].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.satId == 203, + "incorrect value for stec_residuals[21].sv_id.satId, " + "expected 203, is %d", + check_msg->stec_residuals[21].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[22].residual == -15793, + "incorrect value for stec_residuals[22].residual, expected " + "-15793, is %d", + check_msg->stec_residuals[22].residual); + ck_assert_msg( + check_msg->stec_residuals[22].stddev == 253, + "incorrect value for stec_residuals[22].stddev, expected 253, is %d", + check_msg->stec_residuals[22].stddev); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.constellation == 176, + "incorrect value for stec_residuals[22].sv_id.constellation, " + "expected 176, is %d", + check_msg->stec_residuals[22].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.satId == 231, + "incorrect value for stec_residuals[22].sv_id.satId, " + "expected 231, is %d", + check_msg->stec_residuals[22].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[23].residual == -7589, + "incorrect value for stec_residuals[23].residual, expected " + "-7589, is %d", + check_msg->stec_residuals[23].residual); + ck_assert_msg( + check_msg->stec_residuals[23].stddev == 116, + "incorrect value for stec_residuals[23].stddev, expected 116, is %d", + check_msg->stec_residuals[23].stddev); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.constellation == 103, + "incorrect value for stec_residuals[23].sv_id.constellation, " + "expected 103, is %d", + check_msg->stec_residuals[23].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.satId == 247, + "incorrect value for stec_residuals[23].sv_id.satId, " + "expected 247, is %d", + check_msg->stec_residuals[23].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[24].residual == -7362, + "incorrect value for stec_residuals[24].residual, expected " + "-7362, is %d", + check_msg->stec_residuals[24].residual); + ck_assert_msg( + check_msg->stec_residuals[24].stddev == 240, + "incorrect value for stec_residuals[24].stddev, expected 240, is %d", + check_msg->stec_residuals[24].stddev); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.constellation == 23, + "incorrect value for stec_residuals[24].sv_id.constellation, " + "expected 23, is %d", + check_msg->stec_residuals[24].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.satId == 148, + "incorrect value for stec_residuals[24].sv_id.satId, " + "expected 148, is %d", + check_msg->stec_residuals[24].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[25].residual == 4813, + "incorrect value for stec_residuals[25].residual, expected 4813, is %d", + check_msg->stec_residuals[25].residual); + ck_assert_msg( + check_msg->stec_residuals[25].stddev == 242, + "incorrect value for stec_residuals[25].stddev, expected 242, is %d", + check_msg->stec_residuals[25].stddev); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.constellation == 219, + "incorrect value for stec_residuals[25].sv_id.constellation, " + "expected 219, is %d", + check_msg->stec_residuals[25].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.satId == 29, + "incorrect value for stec_residuals[25].sv_id.satId, " + "expected 29, is %d", + check_msg->stec_residuals[25].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[26].residual == 20295, + "incorrect value for stec_residuals[26].residual, expected " + "20295, is %d", + check_msg->stec_residuals[26].residual); + ck_assert_msg( + check_msg->stec_residuals[26].stddev == 37, + "incorrect value for stec_residuals[26].stddev, expected 37, is %d", + check_msg->stec_residuals[26].stddev); + ck_assert_msg(check_msg->stec_residuals[26].sv_id.constellation == 72, + "incorrect value for stec_residuals[26].sv_id.constellation, " + "expected 72, is %d", + check_msg->stec_residuals[26].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[26].sv_id.satId == 207, + "incorrect value for stec_residuals[26].sv_id.satId, " + "expected 207, is %d", + check_msg->stec_residuals[26].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[27].residual == -13623, + "incorrect value for stec_residuals[27].residual, expected " + "-13623, is %d", + check_msg->stec_residuals[27].residual); + ck_assert_msg( + check_msg->stec_residuals[27].stddev == 91, + "incorrect value for stec_residuals[27].stddev, expected 91, is %d", + check_msg->stec_residuals[27].stddev); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.constellation == 176, + "incorrect value for stec_residuals[27].sv_id.constellation, " + "expected 176, is %d", + check_msg->stec_residuals[27].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.satId == 42, + "incorrect value for stec_residuals[27].sv_id.satId, " + "expected 42, is %d", + check_msg->stec_residuals[27].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[28].residual == 15250, + "incorrect value for stec_residuals[28].residual, expected " + "15250, is %d", + check_msg->stec_residuals[28].residual); + ck_assert_msg( + check_msg->stec_residuals[28].stddev == 110, + "incorrect value for stec_residuals[28].stddev, expected 110, is %d", + check_msg->stec_residuals[28].stddev); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.constellation == 115, + "incorrect value for stec_residuals[28].sv_id.constellation, " + "expected 115, is %d", + check_msg->stec_residuals[28].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.satId == 105, + "incorrect value for stec_residuals[28].sv_id.satId, " + "expected 105, is %d", + check_msg->stec_residuals[28].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[29].residual == -18560, + "incorrect value for stec_residuals[29].residual, expected " + "-18560, is %d", + check_msg->stec_residuals[29].residual); + ck_assert_msg( + check_msg->stec_residuals[29].stddev == 185, + "incorrect value for stec_residuals[29].stddev, expected 185, is %d", + check_msg->stec_residuals[29].stddev); + ck_assert_msg(check_msg->stec_residuals[29].sv_id.constellation == 109, + "incorrect value for stec_residuals[29].sv_id.constellation, " + "expected 109, is %d", + check_msg->stec_residuals[29].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[29].sv_id.satId == 44, + "incorrect value for stec_residuals[29].sv_id.satId, " + "expected 44, is %d", + check_msg->stec_residuals[29].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[30].residual == 23717, + "incorrect value for stec_residuals[30].residual, expected " + "23717, is %d", + check_msg->stec_residuals[30].residual); + ck_assert_msg( + check_msg->stec_residuals[30].stddev == 79, + "incorrect value for stec_residuals[30].stddev, expected 79, is %d", + check_msg->stec_residuals[30].stddev); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.constellation == 31, + "incorrect value for stec_residuals[30].sv_id.constellation, " + "expected 31, is %d", + check_msg->stec_residuals[30].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.satId == 67, + "incorrect value for stec_residuals[30].sv_id.satId, " + "expected 67, is %d", + check_msg->stec_residuals[30].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[31].residual == 1886, + "incorrect value for stec_residuals[31].residual, expected 1886, is %d", + check_msg->stec_residuals[31].residual); + ck_assert_msg( + check_msg->stec_residuals[31].stddev == 162, + "incorrect value for stec_residuals[31].stddev, expected 162, is %d", + check_msg->stec_residuals[31].stddev); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.constellation == 180, + "incorrect value for stec_residuals[31].sv_id.constellation, " + "expected 180, is %d", + check_msg->stec_residuals[31].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.satId == 189, + "incorrect value for stec_residuals[31].sv_id.satId, " + "expected 189, is %d", + check_msg->stec_residuals[31].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[32].residual == 12242, + "incorrect value for stec_residuals[32].residual, expected " + "12242, is %d", + check_msg->stec_residuals[32].residual); + ck_assert_msg( + check_msg->stec_residuals[32].stddev == 7, + "incorrect value for stec_residuals[32].stddev, expected 7, is %d", + check_msg->stec_residuals[32].stddev); + ck_assert_msg(check_msg->stec_residuals[32].sv_id.constellation == 156, + "incorrect value for stec_residuals[32].sv_id.constellation, " + "expected 156, is %d", + check_msg->stec_residuals[32].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[32].sv_id.satId == 121, + "incorrect value for stec_residuals[32].sv_id.satId, " + "expected 121, is %d", + check_msg->stec_residuals[32].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[33].residual == 10670, + "incorrect value for stec_residuals[33].residual, expected " + "10670, is %d", + check_msg->stec_residuals[33].residual); + ck_assert_msg( + check_msg->stec_residuals[33].stddev == 241, + "incorrect value for stec_residuals[33].stddev, expected 241, is %d", + check_msg->stec_residuals[33].stddev); + ck_assert_msg(check_msg->stec_residuals[33].sv_id.constellation == 205, + "incorrect value for stec_residuals[33].sv_id.constellation, " + "expected 205, is %d", + check_msg->stec_residuals[33].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[33].sv_id.satId == 7, + "incorrect value for stec_residuals[33].sv_id.satId, expected 7, is %d", + check_msg->stec_residuals[33].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[34].residual == 25899, + "incorrect value for stec_residuals[34].residual, expected " + "25899, is %d", + check_msg->stec_residuals[34].residual); + ck_assert_msg( + check_msg->stec_residuals[34].stddev == 186, + "incorrect value for stec_residuals[34].stddev, expected 186, is %d", + check_msg->stec_residuals[34].stddev); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.constellation == 210, + "incorrect value for stec_residuals[34].sv_id.constellation, " + "expected 210, is %d", + check_msg->stec_residuals[34].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.satId == 129, + "incorrect value for stec_residuals[34].sv_id.satId, " + "expected 129, is %d", + check_msg->stec_residuals[34].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[35].residual == -2078, + "incorrect value for stec_residuals[35].residual, expected " + "-2078, is %d", + check_msg->stec_residuals[35].residual); + ck_assert_msg( + check_msg->stec_residuals[35].stddev == 187, + "incorrect value for stec_residuals[35].stddev, expected 187, is %d", + check_msg->stec_residuals[35].stddev); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.constellation == 195, + "incorrect value for stec_residuals[35].sv_id.constellation, " + "expected 195, is %d", + check_msg->stec_residuals[35].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.satId == 208, + "incorrect value for stec_residuals[35].sv_id.satId, " + "expected 208, is %d", + check_msg->stec_residuals[35].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[36].residual == -16264, + "incorrect value for stec_residuals[36].residual, expected " + "-16264, is %d", + check_msg->stec_residuals[36].residual); + ck_assert_msg( + check_msg->stec_residuals[36].stddev == 102, + "incorrect value for stec_residuals[36].stddev, expected 102, is %d", + check_msg->stec_residuals[36].stddev); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.constellation == 160, + "incorrect value for stec_residuals[36].sv_id.constellation, " + "expected 160, is %d", + check_msg->stec_residuals[36].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.satId == 219, + "incorrect value for stec_residuals[36].sv_id.satId, " + "expected 219, is %d", + check_msg->stec_residuals[36].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[37].residual == -21002, + "incorrect value for stec_residuals[37].residual, expected " + "-21002, is %d", + check_msg->stec_residuals[37].residual); + ck_assert_msg( + check_msg->stec_residuals[37].stddev == 94, + "incorrect value for stec_residuals[37].stddev, expected 94, is %d", + check_msg->stec_residuals[37].stddev); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.constellation == 42, + "incorrect value for stec_residuals[37].sv_id.constellation, " + "expected 42, is %d", + check_msg->stec_residuals[37].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.satId == 166, + "incorrect value for stec_residuals[37].sv_id.satId, " + "expected 166, is %d", + check_msg->stec_residuals[37].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[38].residual == 7902, + "incorrect value for stec_residuals[38].residual, expected 7902, is %d", + check_msg->stec_residuals[38].residual); + ck_assert_msg( + check_msg->stec_residuals[38].stddev == 35, + "incorrect value for stec_residuals[38].stddev, expected 35, is %d", + check_msg->stec_residuals[38].stddev); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.constellation == 156, + "incorrect value for stec_residuals[38].sv_id.constellation, " + "expected 156, is %d", + check_msg->stec_residuals[38].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.satId == 102, + "incorrect value for stec_residuals[38].sv_id.satId, " + "expected 102, is %d", + check_msg->stec_residuals[38].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[39].residual == -30275, + "incorrect value for stec_residuals[39].residual, expected " + "-30275, is %d", + check_msg->stec_residuals[39].residual); + ck_assert_msg( + check_msg->stec_residuals[39].stddev == 204, + "incorrect value for stec_residuals[39].stddev, expected 204, is %d", + check_msg->stec_residuals[39].stddev); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.constellation == 64, + "incorrect value for stec_residuals[39].sv_id.constellation, " + "expected 64, is %d", + check_msg->stec_residuals[39].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.satId == 247, + "incorrect value for stec_residuals[39].sv_id.satId, " + "expected 247, is %d", + check_msg->stec_residuals[39].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[40].residual == -8633, + "incorrect value for stec_residuals[40].residual, expected " + "-8633, is %d", + check_msg->stec_residuals[40].residual); + ck_assert_msg( + check_msg->stec_residuals[40].stddev == 222, + "incorrect value for stec_residuals[40].stddev, expected 222, is %d", + check_msg->stec_residuals[40].stddev); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.constellation == 32, + "incorrect value for stec_residuals[40].sv_id.constellation, " + "expected 32, is %d", + check_msg->stec_residuals[40].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.satId == 220, + "incorrect value for stec_residuals[40].sv_id.satId, " + "expected 220, is %d", + check_msg->stec_residuals[40].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[41].residual == 6403, + "incorrect value for stec_residuals[41].residual, expected 6403, is %d", + check_msg->stec_residuals[41].residual); + ck_assert_msg( + check_msg->stec_residuals[41].stddev == 45, + "incorrect value for stec_residuals[41].stddev, expected 45, is %d", + check_msg->stec_residuals[41].stddev); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.constellation == 246, + "incorrect value for stec_residuals[41].sv_id.constellation, " + "expected 246, is %d", + check_msg->stec_residuals[41].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.satId == 201, + "incorrect value for stec_residuals[41].sv_id.satId, " + "expected 201, is %d", + check_msg->stec_residuals[41].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[42].residual == 22643, + "incorrect value for stec_residuals[42].residual, expected " + "22643, is %d", + check_msg->stec_residuals[42].residual); + ck_assert_msg( + check_msg->stec_residuals[42].stddev == 218, + "incorrect value for stec_residuals[42].stddev, expected 218, is %d", + check_msg->stec_residuals[42].stddev); + ck_assert_msg(check_msg->stec_residuals[42].sv_id.constellation == 239, + "incorrect value for stec_residuals[42].sv_id.constellation, " + "expected 239, is %d", + check_msg->stec_residuals[42].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[42].sv_id.satId == 251, + "incorrect value for stec_residuals[42].sv_id.satId, " + "expected 251, is %d", + check_msg->stec_residuals[42].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[43].residual == 16760, + "incorrect value for stec_residuals[43].residual, expected " + "16760, is %d", + check_msg->stec_residuals[43].residual); + ck_assert_msg( + check_msg->stec_residuals[43].stddev == 175, + "incorrect value for stec_residuals[43].stddev, expected 175, is %d", + check_msg->stec_residuals[43].stddev); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.constellation == 209, + "incorrect value for stec_residuals[43].sv_id.constellation, " + "expected 209, is %d", + check_msg->stec_residuals[43].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.satId == 10, + "incorrect value for stec_residuals[43].sv_id.satId, " + "expected 10, is %d", + check_msg->stec_residuals[43].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[44].residual == -20951, + "incorrect value for stec_residuals[44].residual, expected " + "-20951, is %d", + check_msg->stec_residuals[44].residual); + ck_assert_msg( + check_msg->stec_residuals[44].stddev == 137, + "incorrect value for stec_residuals[44].stddev, expected 137, is %d", + check_msg->stec_residuals[44].stddev); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.constellation == 194, + "incorrect value for stec_residuals[44].sv_id.constellation, " + "expected 194, is %d", + check_msg->stec_residuals[44].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.satId == 131, + "incorrect value for stec_residuals[44].sv_id.satId, " + "expected 131, is %d", + check_msg->stec_residuals[44].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[45].residual == -740, + "incorrect value for stec_residuals[45].residual, expected -740, is %d", + check_msg->stec_residuals[45].residual); + ck_assert_msg( + check_msg->stec_residuals[45].stddev == 42, + "incorrect value for stec_residuals[45].stddev, expected 42, is %d", + check_msg->stec_residuals[45].stddev); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.constellation == 68, + "incorrect value for stec_residuals[45].sv_id.constellation, " + "expected 68, is %d", + check_msg->stec_residuals[45].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.satId == 17, + "incorrect value for stec_residuals[45].sv_id.satId, " + "expected 17, is %d", + check_msg->stec_residuals[45].sv_id.satId); + ck_assert_msg(check_msg->tropo_delay_correction.hydro == -3035, + "incorrect value for tropo_delay_correction.hydro, expected " + "-3035, is %d", + check_msg->tropo_delay_correction.hydro); + ck_assert_msg( + check_msg->tropo_delay_correction.stddev == 72, + "incorrect value for tropo_delay_correction.stddev, expected 72, is %d", + check_msg->tropo_delay_correction.stddev); + ck_assert_msg( + check_msg->tropo_delay_correction.wet == 78, + "incorrect value for tropo_delay_correction.wet, expected 78, is %d", + check_msg->tropo_delay_correction.wet); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c new file mode 100644 index 0000000000..feba430fd8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.c @@ -0,0 +1,1401 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5fa, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5fa, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, + 104, 252, 133, 245, 28, 95, 100, 147, 41, 33, 92, 87, 25, 142, + 151, 74, 151, 95, 94, 7, 146, 237, 45, 167, 86, 42, 116, 224, + 169, 234, 220, 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, + 206, 151, 158, 22, 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, + 110, 38, 65, 104, 244, 19, 238, 227, 88, 169, 164, 146, 63, 37, + 183, 85, 71, 235, 168, 114, 211, 105, 221, 156, 60, 18, 230, 2, + 142, 172, 16, 39, 33, 126, 106, 99, 188, 234, 41, 162, 197, 138, + 227, 80, 12, 54, 67, 238, 5, 93, 1, 207, 129, 13, 46, 115, + 49, 58, 185, 127, 156, 200, 96, 217, 202, 15, 245, 55, 198, 81, + 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, 96, 138, 55, 214, + 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, 245, 112, 168, + 210, 10, 5, 117, 1, 57, 108, 248, 212, 145, 119, 226, 165, 5, + 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, 215, 12, 137, 16, + 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, + 31, 48, 132, 72, 229, 126, 186, 68, 76, 133, 21, 0, 180, 139, + 164, 148, 119, 149, 214, 120, 177, 201, 80, 80, 105, 10, 136, 118, + 77, 46, 233, 233, 227, 11, 158, 103, 167, 216, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_gridded_correction_dep_a_t *test_msg = + (msg_ssr_gridded_correction_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.iod_atmo = 245; + test_msg->header.num_msgs = 37695; + test_msg->header.seq_num = 64616; + test_msg->header.time.tow = 892131748; + test_msg->header.time.wn = 23906; + test_msg->header.tropo_quality_indicator = 28; + test_msg->header.update_interval = 133; + test_msg->index = 25695; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[0].residual = -26738; + test_msg->stec_residuals[0].stddev = 74; + test_msg->stec_residuals[0].sv_id.constellation = 25; + test_msg->stec_residuals[0].sv_id.satId = 87; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[1].residual = 1886; + test_msg->stec_residuals[1].stddev = 146; + test_msg->stec_residuals[1].sv_id.constellation = 95; + test_msg->stec_residuals[1].sv_id.satId = 151; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[2].residual = 22183; + test_msg->stec_residuals[2].stddev = 42; + test_msg->stec_residuals[2].sv_id.constellation = 45; + test_msg->stec_residuals[2].sv_id.satId = 237; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[3].residual = -5463; + test_msg->stec_residuals[3].stddev = 220; + test_msg->stec_residuals[3].sv_id.constellation = 224; + test_msg->stec_residuals[3].sv_id.satId = 116; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[4].residual = 3346; + test_msg->stec_residuals[4].stddev = 178; + test_msg->stec_residuals[4].sv_id.constellation = 176; + test_msg->stec_residuals[4].sv_id.satId = 23; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[5].residual = 28320; + test_msg->stec_residuals[5].stddev = 15; + test_msg->stec_residuals[5].sv_id.constellation = 160; + test_msg->stec_residuals[5].sv_id.satId = 79; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[6].residual = -24937; + test_msg->stec_residuals[6].stddev = 22; + test_msg->stec_residuals[6].sv_id.constellation = 206; + test_msg->stec_residuals[6].sv_id.satId = 53; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[7].residual = -21968; + test_msg->stec_residuals[7].stddev = 82; + test_msg->stec_residuals[7].sv_id.constellation = 184; + test_msg->stec_residuals[7].sv_id.satId = 117; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[8].residual = 17786; + test_msg->stec_residuals[8].stddev = 180; + test_msg->stec_residuals[8].sv_id.constellation = 53; + test_msg->stec_residuals[8].sv_id.satId = 40; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[9].residual = 26689; + test_msg->stec_residuals[9].stddev = 244; + test_msg->stec_residuals[9].sv_id.constellation = 38; + test_msg->stec_residuals[9].sv_id.satId = 110; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[10].residual = 22755; + test_msg->stec_residuals[10].stddev = 169; + test_msg->stec_residuals[10].sv_id.constellation = 238; + test_msg->stec_residuals[10].sv_id.satId = 19; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[11].residual = 9535; + test_msg->stec_residuals[11].stddev = 183; + test_msg->stec_residuals[11].sv_id.constellation = 146; + test_msg->stec_residuals[11].sv_id.satId = 164; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[12].residual = -22293; + test_msg->stec_residuals[12].stddev = 114; + test_msg->stec_residuals[12].sv_id.constellation = 71; + test_msg->stec_residuals[12].sv_id.satId = 85; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[13].residual = -25379; + test_msg->stec_residuals[13].stddev = 60; + test_msg->stec_residuals[13].sv_id.constellation = 105; + test_msg->stec_residuals[13].sv_id.satId = 211; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[14].residual = -29182; + test_msg->stec_residuals[14].stddev = 172; + test_msg->stec_residuals[14].sv_id.constellation = 230; + test_msg->stec_residuals[14].sv_id.satId = 18; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[15].residual = 32289; + test_msg->stec_residuals[15].stddev = 106; + test_msg->stec_residuals[15].sv_id.constellation = 39; + test_msg->stec_residuals[15].sv_id.satId = 16; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[16].residual = 10730; + test_msg->stec_residuals[16].stddev = 162; + test_msg->stec_residuals[16].sv_id.constellation = 188; + test_msg->stec_residuals[16].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[17].residual = 20707; + test_msg->stec_residuals[17].stddev = 12; + test_msg->stec_residuals[17].sv_id.constellation = 138; + test_msg->stec_residuals[17].sv_id.satId = 197; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[18].residual = 1518; + test_msg->stec_residuals[18].stddev = 93; + test_msg->stec_residuals[18].sv_id.constellation = 67; + test_msg->stec_residuals[18].sv_id.satId = 54; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[19].residual = 3457; + test_msg->stec_residuals[19].stddev = 46; + test_msg->stec_residuals[19].sv_id.constellation = 207; + test_msg->stec_residuals[19].sv_id.satId = 1; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[20].residual = -18118; + test_msg->stec_residuals[20].stddev = 127; + test_msg->stec_residuals[20].sv_id.constellation = 49; + test_msg->stec_residuals[20].sv_id.satId = 115; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[21].residual = -9888; + test_msg->stec_residuals[21].stddev = 202; + test_msg->stec_residuals[21].sv_id.constellation = 200; + test_msg->stec_residuals[21].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[22].residual = -14793; + test_msg->stec_residuals[22].stddev = 81; + test_msg->stec_residuals[22].sv_id.constellation = 245; + test_msg->stec_residuals[22].sv_id.satId = 15; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[23].residual = 18758; + test_msg->stec_residuals[23].stddev = 82; + test_msg->stec_residuals[23].sv_id.constellation = 132; + test_msg->stec_residuals[23].sv_id.satId = 218; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[24].residual = 3839; + test_msg->stec_residuals[24].stddev = 134; + test_msg->stec_residuals[24].sv_id.constellation = 26; + test_msg->stec_residuals[24].sv_id.satId = 147; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[25].residual = -10697; + test_msg->stec_residuals[25].stddev = 83; + test_msg->stec_residuals[25].sv_id.constellation = 138; + test_msg->stec_residuals[25].sv_id.satId = 96; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[26].residual = 20387; + test_msg->stec_residuals[26].stddev = 173; + test_msg->stec_residuals[26].sv_id.constellation = 170; + test_msg->stec_residuals[26].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[27].residual = -3789; + test_msg->stec_residuals[27].stddev = 107; + test_msg->stec_residuals[27].sv_id.constellation = 115; + test_msg->stec_residuals[27].sv_id.satId = 228; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[28].residual = -11608; + test_msg->stec_residuals[28].stddev = 10; + test_msg->stec_residuals[28].sv_id.constellation = 112; + test_msg->stec_residuals[28].sv_id.satId = 245; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[29].residual = 14593; + test_msg->stec_residuals[29].stddev = 108; + test_msg->stec_residuals[29].sv_id.constellation = 117; + test_msg->stec_residuals[29].sv_id.satId = 5; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[30].residual = 30609; + test_msg->stec_residuals[30].stddev = 226; + test_msg->stec_residuals[30].sv_id.constellation = 212; + test_msg->stec_residuals[30].sv_id.satId = 248; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[31].residual = -13683; + test_msg->stec_residuals[31].stddev = 106; + test_msg->stec_residuals[31].sv_id.constellation = 5; + test_msg->stec_residuals[31].sv_id.satId = 165; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[32].residual = 15652; + test_msg->stec_residuals[32].stddev = 243; + test_msg->stec_residuals[32].sv_id.constellation = 60; + test_msg->stec_residuals[32].sv_id.satId = 0; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[33].residual = 3287; + test_msg->stec_residuals[33].stddev = 137; + test_msg->stec_residuals[33].sv_id.constellation = 216; + test_msg->stec_residuals[33].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[34].residual = 29687; + test_msg->stec_residuals[34].stddev = 152; + test_msg->stec_residuals[34].sv_id.constellation = 28; + test_msg->stec_residuals[34].sv_id.satId = 16; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[35].residual = -6960; + test_msg->stec_residuals[35].stddev = 203; + test_msg->stec_residuals[35].sv_id.constellation = 119; + test_msg->stec_residuals[35].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[36].residual = -15193; + test_msg->stec_residuals[36].stddev = 32; + test_msg->stec_residuals[36].sv_id.constellation = 34; + test_msg->stec_residuals[36].sv_id.satId = 236; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[37].residual = 25873; + test_msg->stec_residuals[37].stddev = 200; + test_msg->stec_residuals[37].sv_id.constellation = 1; + test_msg->stec_residuals[37].sv_id.satId = 109; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[38].residual = -22403; + test_msg->stec_residuals[38].stddev = 137; + test_msg->stec_residuals[38].sv_id.constellation = 94; + test_msg->stec_residuals[38].sv_id.satId = 25; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[39].residual = 7588; + test_msg->stec_residuals[39].stddev = 31; + test_msg->stec_residuals[39].sv_id.constellation = 4; + test_msg->stec_residuals[39].sv_id.satId = 157; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[40].residual = -6840; + test_msg->stec_residuals[40].stddev = 126; + test_msg->stec_residuals[40].sv_id.constellation = 132; + test_msg->stec_residuals[40].sv_id.satId = 48; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[41].residual = -31412; + test_msg->stec_residuals[41].stddev = 21; + test_msg->stec_residuals[41].sv_id.constellation = 68; + test_msg->stec_residuals[41].sv_id.satId = 186; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[42].residual = -23413; + test_msg->stec_residuals[42].stddev = 148; + test_msg->stec_residuals[42].sv_id.constellation = 180; + test_msg->stec_residuals[42].sv_id.satId = 0; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[43].residual = 30934; + test_msg->stec_residuals[43].stddev = 177; + test_msg->stec_residuals[43].sv_id.constellation = 149; + test_msg->stec_residuals[43].sv_id.satId = 119; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[44].residual = 26960; + test_msg->stec_residuals[44].stddev = 10; + test_msg->stec_residuals[44].sv_id.constellation = 80; + test_msg->stec_residuals[44].sv_id.satId = 201; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[45].residual = 11853; + test_msg->stec_residuals[45].stddev = 233; + test_msg->stec_residuals[45].sv_id.constellation = 118; + test_msg->stec_residuals[45].sv_id.satId = 136; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[46].residual = -25077; + test_msg->stec_residuals[46].stddev = 103; + test_msg->stec_residuals[46].sv_id.constellation = 227; + test_msg->stec_residuals[46].sv_id.satId = 233; + test_msg->tropo_delay_correction.hydro = 10643; + test_msg->tropo_delay_correction.stddev = 92; + test_msg->tropo_delay_correction.wet = 33; + sbp_payload_send(&sbp_state, 0x5fa, 27244, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 27244, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 27244, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5fa, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_gridded_correction_dep_a_t *check_msg = + (msg_ssr_gridded_correction_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->header.iod_atmo == 245, + "incorrect value for header.iod_atmo, expected 245, is %d", + check_msg->header.iod_atmo); + ck_assert_msg(check_msg->header.num_msgs == 37695, + "incorrect value for header.num_msgs, expected 37695, is %d", + check_msg->header.num_msgs); + ck_assert_msg(check_msg->header.seq_num == 64616, + "incorrect value for header.seq_num, expected 64616, is %d", + check_msg->header.seq_num); + ck_assert_msg( + check_msg->header.time.tow == 892131748, + "incorrect value for header.time.tow, expected 892131748, is %d", + check_msg->header.time.tow); + ck_assert_msg(check_msg->header.time.wn == 23906, + "incorrect value for header.time.wn, expected 23906, is %d", + check_msg->header.time.wn); + ck_assert_msg(check_msg->header.tropo_quality_indicator == 28, + "incorrect value for header.tropo_quality_indicator, " + "expected 28, is %d", + check_msg->header.tropo_quality_indicator); + ck_assert_msg( + check_msg->header.update_interval == 133, + "incorrect value for header.update_interval, expected 133, is %d", + check_msg->header.update_interval); + ck_assert_msg(check_msg->index == 25695, + "incorrect value for index, expected 25695, is %d", + check_msg->index); + ck_assert_msg(check_msg->stec_residuals[0].residual == -26738, + "incorrect value for stec_residuals[0].residual, expected " + "-26738, is %d", + check_msg->stec_residuals[0].residual); + ck_assert_msg( + check_msg->stec_residuals[0].stddev == 74, + "incorrect value for stec_residuals[0].stddev, expected 74, is %d", + check_msg->stec_residuals[0].stddev); + ck_assert_msg(check_msg->stec_residuals[0].sv_id.constellation == 25, + "incorrect value for stec_residuals[0].sv_id.constellation, " + "expected 25, is %d", + check_msg->stec_residuals[0].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[0].sv_id.satId == 87, + "incorrect value for stec_residuals[0].sv_id.satId, expected 87, is %d", + check_msg->stec_residuals[0].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[1].residual == 1886, + "incorrect value for stec_residuals[1].residual, expected 1886, is %d", + check_msg->stec_residuals[1].residual); + ck_assert_msg( + check_msg->stec_residuals[1].stddev == 146, + "incorrect value for stec_residuals[1].stddev, expected 146, is %d", + check_msg->stec_residuals[1].stddev); + ck_assert_msg(check_msg->stec_residuals[1].sv_id.constellation == 95, + "incorrect value for stec_residuals[1].sv_id.constellation, " + "expected 95, is %d", + check_msg->stec_residuals[1].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[1].sv_id.satId == 151, + "incorrect value for stec_residuals[1].sv_id.satId, expected " + "151, is %d", + check_msg->stec_residuals[1].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[2].residual == 22183, + "incorrect value for stec_residuals[2].residual, expected 22183, is %d", + check_msg->stec_residuals[2].residual); + ck_assert_msg( + check_msg->stec_residuals[2].stddev == 42, + "incorrect value for stec_residuals[2].stddev, expected 42, is %d", + check_msg->stec_residuals[2].stddev); + ck_assert_msg(check_msg->stec_residuals[2].sv_id.constellation == 45, + "incorrect value for stec_residuals[2].sv_id.constellation, " + "expected 45, is %d", + check_msg->stec_residuals[2].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[2].sv_id.satId == 237, + "incorrect value for stec_residuals[2].sv_id.satId, expected " + "237, is %d", + check_msg->stec_residuals[2].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[3].residual == -5463, + "incorrect value for stec_residuals[3].residual, expected -5463, is %d", + check_msg->stec_residuals[3].residual); + ck_assert_msg( + check_msg->stec_residuals[3].stddev == 220, + "incorrect value for stec_residuals[3].stddev, expected 220, is %d", + check_msg->stec_residuals[3].stddev); + ck_assert_msg(check_msg->stec_residuals[3].sv_id.constellation == 224, + "incorrect value for stec_residuals[3].sv_id.constellation, " + "expected 224, is %d", + check_msg->stec_residuals[3].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[3].sv_id.satId == 116, + "incorrect value for stec_residuals[3].sv_id.satId, expected " + "116, is %d", + check_msg->stec_residuals[3].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[4].residual == 3346, + "incorrect value for stec_residuals[4].residual, expected 3346, is %d", + check_msg->stec_residuals[4].residual); + ck_assert_msg( + check_msg->stec_residuals[4].stddev == 178, + "incorrect value for stec_residuals[4].stddev, expected 178, is %d", + check_msg->stec_residuals[4].stddev); + ck_assert_msg(check_msg->stec_residuals[4].sv_id.constellation == 176, + "incorrect value for stec_residuals[4].sv_id.constellation, " + "expected 176, is %d", + check_msg->stec_residuals[4].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[4].sv_id.satId == 23, + "incorrect value for stec_residuals[4].sv_id.satId, expected 23, is %d", + check_msg->stec_residuals[4].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[5].residual == 28320, + "incorrect value for stec_residuals[5].residual, expected 28320, is %d", + check_msg->stec_residuals[5].residual); + ck_assert_msg( + check_msg->stec_residuals[5].stddev == 15, + "incorrect value for stec_residuals[5].stddev, expected 15, is %d", + check_msg->stec_residuals[5].stddev); + ck_assert_msg(check_msg->stec_residuals[5].sv_id.constellation == 160, + "incorrect value for stec_residuals[5].sv_id.constellation, " + "expected 160, is %d", + check_msg->stec_residuals[5].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[5].sv_id.satId == 79, + "incorrect value for stec_residuals[5].sv_id.satId, expected 79, is %d", + check_msg->stec_residuals[5].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[6].residual == -24937, + "incorrect value for stec_residuals[6].residual, expected " + "-24937, is %d", + check_msg->stec_residuals[6].residual); + ck_assert_msg( + check_msg->stec_residuals[6].stddev == 22, + "incorrect value for stec_residuals[6].stddev, expected 22, is %d", + check_msg->stec_residuals[6].stddev); + ck_assert_msg(check_msg->stec_residuals[6].sv_id.constellation == 206, + "incorrect value for stec_residuals[6].sv_id.constellation, " + "expected 206, is %d", + check_msg->stec_residuals[6].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[6].sv_id.satId == 53, + "incorrect value for stec_residuals[6].sv_id.satId, expected 53, is %d", + check_msg->stec_residuals[6].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[7].residual == -21968, + "incorrect value for stec_residuals[7].residual, expected " + "-21968, is %d", + check_msg->stec_residuals[7].residual); + ck_assert_msg( + check_msg->stec_residuals[7].stddev == 82, + "incorrect value for stec_residuals[7].stddev, expected 82, is %d", + check_msg->stec_residuals[7].stddev); + ck_assert_msg(check_msg->stec_residuals[7].sv_id.constellation == 184, + "incorrect value for stec_residuals[7].sv_id.constellation, " + "expected 184, is %d", + check_msg->stec_residuals[7].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[7].sv_id.satId == 117, + "incorrect value for stec_residuals[7].sv_id.satId, expected " + "117, is %d", + check_msg->stec_residuals[7].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[8].residual == 17786, + "incorrect value for stec_residuals[8].residual, expected 17786, is %d", + check_msg->stec_residuals[8].residual); + ck_assert_msg( + check_msg->stec_residuals[8].stddev == 180, + "incorrect value for stec_residuals[8].stddev, expected 180, is %d", + check_msg->stec_residuals[8].stddev); + ck_assert_msg(check_msg->stec_residuals[8].sv_id.constellation == 53, + "incorrect value for stec_residuals[8].sv_id.constellation, " + "expected 53, is %d", + check_msg->stec_residuals[8].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[8].sv_id.satId == 40, + "incorrect value for stec_residuals[8].sv_id.satId, expected 40, is %d", + check_msg->stec_residuals[8].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[9].residual == 26689, + "incorrect value for stec_residuals[9].residual, expected 26689, is %d", + check_msg->stec_residuals[9].residual); + ck_assert_msg( + check_msg->stec_residuals[9].stddev == 244, + "incorrect value for stec_residuals[9].stddev, expected 244, is %d", + check_msg->stec_residuals[9].stddev); + ck_assert_msg(check_msg->stec_residuals[9].sv_id.constellation == 38, + "incorrect value for stec_residuals[9].sv_id.constellation, " + "expected 38, is %d", + check_msg->stec_residuals[9].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[9].sv_id.satId == 110, + "incorrect value for stec_residuals[9].sv_id.satId, expected " + "110, is %d", + check_msg->stec_residuals[9].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[10].residual == 22755, + "incorrect value for stec_residuals[10].residual, expected " + "22755, is %d", + check_msg->stec_residuals[10].residual); + ck_assert_msg( + check_msg->stec_residuals[10].stddev == 169, + "incorrect value for stec_residuals[10].stddev, expected 169, is %d", + check_msg->stec_residuals[10].stddev); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.constellation == 238, + "incorrect value for stec_residuals[10].sv_id.constellation, " + "expected 238, is %d", + check_msg->stec_residuals[10].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.satId == 19, + "incorrect value for stec_residuals[10].sv_id.satId, " + "expected 19, is %d", + check_msg->stec_residuals[10].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[11].residual == 9535, + "incorrect value for stec_residuals[11].residual, expected 9535, is %d", + check_msg->stec_residuals[11].residual); + ck_assert_msg( + check_msg->stec_residuals[11].stddev == 183, + "incorrect value for stec_residuals[11].stddev, expected 183, is %d", + check_msg->stec_residuals[11].stddev); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.constellation == 146, + "incorrect value for stec_residuals[11].sv_id.constellation, " + "expected 146, is %d", + check_msg->stec_residuals[11].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.satId == 164, + "incorrect value for stec_residuals[11].sv_id.satId, " + "expected 164, is %d", + check_msg->stec_residuals[11].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[12].residual == -22293, + "incorrect value for stec_residuals[12].residual, expected " + "-22293, is %d", + check_msg->stec_residuals[12].residual); + ck_assert_msg( + check_msg->stec_residuals[12].stddev == 114, + "incorrect value for stec_residuals[12].stddev, expected 114, is %d", + check_msg->stec_residuals[12].stddev); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.constellation == 71, + "incorrect value for stec_residuals[12].sv_id.constellation, " + "expected 71, is %d", + check_msg->stec_residuals[12].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.satId == 85, + "incorrect value for stec_residuals[12].sv_id.satId, " + "expected 85, is %d", + check_msg->stec_residuals[12].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[13].residual == -25379, + "incorrect value for stec_residuals[13].residual, expected " + "-25379, is %d", + check_msg->stec_residuals[13].residual); + ck_assert_msg( + check_msg->stec_residuals[13].stddev == 60, + "incorrect value for stec_residuals[13].stddev, expected 60, is %d", + check_msg->stec_residuals[13].stddev); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.constellation == 105, + "incorrect value for stec_residuals[13].sv_id.constellation, " + "expected 105, is %d", + check_msg->stec_residuals[13].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.satId == 211, + "incorrect value for stec_residuals[13].sv_id.satId, " + "expected 211, is %d", + check_msg->stec_residuals[13].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[14].residual == -29182, + "incorrect value for stec_residuals[14].residual, expected " + "-29182, is %d", + check_msg->stec_residuals[14].residual); + ck_assert_msg( + check_msg->stec_residuals[14].stddev == 172, + "incorrect value for stec_residuals[14].stddev, expected 172, is %d", + check_msg->stec_residuals[14].stddev); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.constellation == 230, + "incorrect value for stec_residuals[14].sv_id.constellation, " + "expected 230, is %d", + check_msg->stec_residuals[14].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.satId == 18, + "incorrect value for stec_residuals[14].sv_id.satId, " + "expected 18, is %d", + check_msg->stec_residuals[14].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[15].residual == 32289, + "incorrect value for stec_residuals[15].residual, expected " + "32289, is %d", + check_msg->stec_residuals[15].residual); + ck_assert_msg( + check_msg->stec_residuals[15].stddev == 106, + "incorrect value for stec_residuals[15].stddev, expected 106, is %d", + check_msg->stec_residuals[15].stddev); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.constellation == 39, + "incorrect value for stec_residuals[15].sv_id.constellation, " + "expected 39, is %d", + check_msg->stec_residuals[15].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.satId == 16, + "incorrect value for stec_residuals[15].sv_id.satId, " + "expected 16, is %d", + check_msg->stec_residuals[15].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[16].residual == 10730, + "incorrect value for stec_residuals[16].residual, expected " + "10730, is %d", + check_msg->stec_residuals[16].residual); + ck_assert_msg( + check_msg->stec_residuals[16].stddev == 162, + "incorrect value for stec_residuals[16].stddev, expected 162, is %d", + check_msg->stec_residuals[16].stddev); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.constellation == 188, + "incorrect value for stec_residuals[16].sv_id.constellation, " + "expected 188, is %d", + check_msg->stec_residuals[16].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.satId == 99, + "incorrect value for stec_residuals[16].sv_id.satId, " + "expected 99, is %d", + check_msg->stec_residuals[16].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[17].residual == 20707, + "incorrect value for stec_residuals[17].residual, expected " + "20707, is %d", + check_msg->stec_residuals[17].residual); + ck_assert_msg( + check_msg->stec_residuals[17].stddev == 12, + "incorrect value for stec_residuals[17].stddev, expected 12, is %d", + check_msg->stec_residuals[17].stddev); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.constellation == 138, + "incorrect value for stec_residuals[17].sv_id.constellation, " + "expected 138, is %d", + check_msg->stec_residuals[17].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.satId == 197, + "incorrect value for stec_residuals[17].sv_id.satId, " + "expected 197, is %d", + check_msg->stec_residuals[17].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[18].residual == 1518, + "incorrect value for stec_residuals[18].residual, expected 1518, is %d", + check_msg->stec_residuals[18].residual); + ck_assert_msg( + check_msg->stec_residuals[18].stddev == 93, + "incorrect value for stec_residuals[18].stddev, expected 93, is %d", + check_msg->stec_residuals[18].stddev); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.constellation == 67, + "incorrect value for stec_residuals[18].sv_id.constellation, " + "expected 67, is %d", + check_msg->stec_residuals[18].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.satId == 54, + "incorrect value for stec_residuals[18].sv_id.satId, " + "expected 54, is %d", + check_msg->stec_residuals[18].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[19].residual == 3457, + "incorrect value for stec_residuals[19].residual, expected 3457, is %d", + check_msg->stec_residuals[19].residual); + ck_assert_msg( + check_msg->stec_residuals[19].stddev == 46, + "incorrect value for stec_residuals[19].stddev, expected 46, is %d", + check_msg->stec_residuals[19].stddev); + ck_assert_msg(check_msg->stec_residuals[19].sv_id.constellation == 207, + "incorrect value for stec_residuals[19].sv_id.constellation, " + "expected 207, is %d", + check_msg->stec_residuals[19].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[19].sv_id.satId == 1, + "incorrect value for stec_residuals[19].sv_id.satId, expected 1, is %d", + check_msg->stec_residuals[19].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[20].residual == -18118, + "incorrect value for stec_residuals[20].residual, expected " + "-18118, is %d", + check_msg->stec_residuals[20].residual); + ck_assert_msg( + check_msg->stec_residuals[20].stddev == 127, + "incorrect value for stec_residuals[20].stddev, expected 127, is %d", + check_msg->stec_residuals[20].stddev); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.constellation == 49, + "incorrect value for stec_residuals[20].sv_id.constellation, " + "expected 49, is %d", + check_msg->stec_residuals[20].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.satId == 115, + "incorrect value for stec_residuals[20].sv_id.satId, " + "expected 115, is %d", + check_msg->stec_residuals[20].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[21].residual == -9888, + "incorrect value for stec_residuals[21].residual, expected " + "-9888, is %d", + check_msg->stec_residuals[21].residual); + ck_assert_msg( + check_msg->stec_residuals[21].stddev == 202, + "incorrect value for stec_residuals[21].stddev, expected 202, is %d", + check_msg->stec_residuals[21].stddev); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.constellation == 200, + "incorrect value for stec_residuals[21].sv_id.constellation, " + "expected 200, is %d", + check_msg->stec_residuals[21].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.satId == 156, + "incorrect value for stec_residuals[21].sv_id.satId, " + "expected 156, is %d", + check_msg->stec_residuals[21].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[22].residual == -14793, + "incorrect value for stec_residuals[22].residual, expected " + "-14793, is %d", + check_msg->stec_residuals[22].residual); + ck_assert_msg( + check_msg->stec_residuals[22].stddev == 81, + "incorrect value for stec_residuals[22].stddev, expected 81, is %d", + check_msg->stec_residuals[22].stddev); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.constellation == 245, + "incorrect value for stec_residuals[22].sv_id.constellation, " + "expected 245, is %d", + check_msg->stec_residuals[22].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.satId == 15, + "incorrect value for stec_residuals[22].sv_id.satId, " + "expected 15, is %d", + check_msg->stec_residuals[22].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[23].residual == 18758, + "incorrect value for stec_residuals[23].residual, expected " + "18758, is %d", + check_msg->stec_residuals[23].residual); + ck_assert_msg( + check_msg->stec_residuals[23].stddev == 82, + "incorrect value for stec_residuals[23].stddev, expected 82, is %d", + check_msg->stec_residuals[23].stddev); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.constellation == 132, + "incorrect value for stec_residuals[23].sv_id.constellation, " + "expected 132, is %d", + check_msg->stec_residuals[23].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.satId == 218, + "incorrect value for stec_residuals[23].sv_id.satId, " + "expected 218, is %d", + check_msg->stec_residuals[23].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[24].residual == 3839, + "incorrect value for stec_residuals[24].residual, expected 3839, is %d", + check_msg->stec_residuals[24].residual); + ck_assert_msg( + check_msg->stec_residuals[24].stddev == 134, + "incorrect value for stec_residuals[24].stddev, expected 134, is %d", + check_msg->stec_residuals[24].stddev); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.constellation == 26, + "incorrect value for stec_residuals[24].sv_id.constellation, " + "expected 26, is %d", + check_msg->stec_residuals[24].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.satId == 147, + "incorrect value for stec_residuals[24].sv_id.satId, " + "expected 147, is %d", + check_msg->stec_residuals[24].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[25].residual == -10697, + "incorrect value for stec_residuals[25].residual, expected " + "-10697, is %d", + check_msg->stec_residuals[25].residual); + ck_assert_msg( + check_msg->stec_residuals[25].stddev == 83, + "incorrect value for stec_residuals[25].stddev, expected 83, is %d", + check_msg->stec_residuals[25].stddev); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.constellation == 138, + "incorrect value for stec_residuals[25].sv_id.constellation, " + "expected 138, is %d", + check_msg->stec_residuals[25].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.satId == 96, + "incorrect value for stec_residuals[25].sv_id.satId, " + "expected 96, is %d", + check_msg->stec_residuals[25].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[26].residual == 20387, + "incorrect value for stec_residuals[26].residual, expected " + "20387, is %d", + check_msg->stec_residuals[26].residual); + ck_assert_msg( + check_msg->stec_residuals[26].stddev == 173, + "incorrect value for stec_residuals[26].stddev, expected 173, is %d", + check_msg->stec_residuals[26].stddev); + ck_assert_msg(check_msg->stec_residuals[26].sv_id.constellation == 170, + "incorrect value for stec_residuals[26].sv_id.constellation, " + "expected 170, is %d", + check_msg->stec_residuals[26].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[26].sv_id.satId == 156, + "incorrect value for stec_residuals[26].sv_id.satId, " + "expected 156, is %d", + check_msg->stec_residuals[26].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[27].residual == -3789, + "incorrect value for stec_residuals[27].residual, expected " + "-3789, is %d", + check_msg->stec_residuals[27].residual); + ck_assert_msg( + check_msg->stec_residuals[27].stddev == 107, + "incorrect value for stec_residuals[27].stddev, expected 107, is %d", + check_msg->stec_residuals[27].stddev); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.constellation == 115, + "incorrect value for stec_residuals[27].sv_id.constellation, " + "expected 115, is %d", + check_msg->stec_residuals[27].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.satId == 228, + "incorrect value for stec_residuals[27].sv_id.satId, " + "expected 228, is %d", + check_msg->stec_residuals[27].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[28].residual == -11608, + "incorrect value for stec_residuals[28].residual, expected " + "-11608, is %d", + check_msg->stec_residuals[28].residual); + ck_assert_msg( + check_msg->stec_residuals[28].stddev == 10, + "incorrect value for stec_residuals[28].stddev, expected 10, is %d", + check_msg->stec_residuals[28].stddev); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.constellation == 112, + "incorrect value for stec_residuals[28].sv_id.constellation, " + "expected 112, is %d", + check_msg->stec_residuals[28].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.satId == 245, + "incorrect value for stec_residuals[28].sv_id.satId, " + "expected 245, is %d", + check_msg->stec_residuals[28].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[29].residual == 14593, + "incorrect value for stec_residuals[29].residual, expected " + "14593, is %d", + check_msg->stec_residuals[29].residual); + ck_assert_msg( + check_msg->stec_residuals[29].stddev == 108, + "incorrect value for stec_residuals[29].stddev, expected 108, is %d", + check_msg->stec_residuals[29].stddev); + ck_assert_msg(check_msg->stec_residuals[29].sv_id.constellation == 117, + "incorrect value for stec_residuals[29].sv_id.constellation, " + "expected 117, is %d", + check_msg->stec_residuals[29].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[29].sv_id.satId == 5, + "incorrect value for stec_residuals[29].sv_id.satId, expected 5, is %d", + check_msg->stec_residuals[29].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[30].residual == 30609, + "incorrect value for stec_residuals[30].residual, expected " + "30609, is %d", + check_msg->stec_residuals[30].residual); + ck_assert_msg( + check_msg->stec_residuals[30].stddev == 226, + "incorrect value for stec_residuals[30].stddev, expected 226, is %d", + check_msg->stec_residuals[30].stddev); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.constellation == 212, + "incorrect value for stec_residuals[30].sv_id.constellation, " + "expected 212, is %d", + check_msg->stec_residuals[30].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.satId == 248, + "incorrect value for stec_residuals[30].sv_id.satId, " + "expected 248, is %d", + check_msg->stec_residuals[30].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[31].residual == -13683, + "incorrect value for stec_residuals[31].residual, expected " + "-13683, is %d", + check_msg->stec_residuals[31].residual); + ck_assert_msg( + check_msg->stec_residuals[31].stddev == 106, + "incorrect value for stec_residuals[31].stddev, expected 106, is %d", + check_msg->stec_residuals[31].stddev); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.constellation == 5, + "incorrect value for stec_residuals[31].sv_id.constellation, " + "expected 5, is %d", + check_msg->stec_residuals[31].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.satId == 165, + "incorrect value for stec_residuals[31].sv_id.satId, " + "expected 165, is %d", + check_msg->stec_residuals[31].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[32].residual == 15652, + "incorrect value for stec_residuals[32].residual, expected " + "15652, is %d", + check_msg->stec_residuals[32].residual); + ck_assert_msg( + check_msg->stec_residuals[32].stddev == 243, + "incorrect value for stec_residuals[32].stddev, expected 243, is %d", + check_msg->stec_residuals[32].stddev); + ck_assert_msg(check_msg->stec_residuals[32].sv_id.constellation == 60, + "incorrect value for stec_residuals[32].sv_id.constellation, " + "expected 60, is %d", + check_msg->stec_residuals[32].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[32].sv_id.satId == 0, + "incorrect value for stec_residuals[32].sv_id.satId, expected 0, is %d", + check_msg->stec_residuals[32].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[33].residual == 3287, + "incorrect value for stec_residuals[33].residual, expected 3287, is %d", + check_msg->stec_residuals[33].residual); + ck_assert_msg( + check_msg->stec_residuals[33].stddev == 137, + "incorrect value for stec_residuals[33].stddev, expected 137, is %d", + check_msg->stec_residuals[33].stddev); + ck_assert_msg(check_msg->stec_residuals[33].sv_id.constellation == 216, + "incorrect value for stec_residuals[33].sv_id.constellation, " + "expected 216, is %d", + check_msg->stec_residuals[33].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[33].sv_id.satId == 203, + "incorrect value for stec_residuals[33].sv_id.satId, " + "expected 203, is %d", + check_msg->stec_residuals[33].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[34].residual == 29687, + "incorrect value for stec_residuals[34].residual, expected " + "29687, is %d", + check_msg->stec_residuals[34].residual); + ck_assert_msg( + check_msg->stec_residuals[34].stddev == 152, + "incorrect value for stec_residuals[34].stddev, expected 152, is %d", + check_msg->stec_residuals[34].stddev); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.constellation == 28, + "incorrect value for stec_residuals[34].sv_id.constellation, " + "expected 28, is %d", + check_msg->stec_residuals[34].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.satId == 16, + "incorrect value for stec_residuals[34].sv_id.satId, " + "expected 16, is %d", + check_msg->stec_residuals[34].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[35].residual == -6960, + "incorrect value for stec_residuals[35].residual, expected " + "-6960, is %d", + check_msg->stec_residuals[35].residual); + ck_assert_msg( + check_msg->stec_residuals[35].stddev == 203, + "incorrect value for stec_residuals[35].stddev, expected 203, is %d", + check_msg->stec_residuals[35].stddev); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.constellation == 119, + "incorrect value for stec_residuals[35].sv_id.constellation, " + "expected 119, is %d", + check_msg->stec_residuals[35].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.satId == 181, + "incorrect value for stec_residuals[35].sv_id.satId, " + "expected 181, is %d", + check_msg->stec_residuals[35].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[36].residual == -15193, + "incorrect value for stec_residuals[36].residual, expected " + "-15193, is %d", + check_msg->stec_residuals[36].residual); + ck_assert_msg( + check_msg->stec_residuals[36].stddev == 32, + "incorrect value for stec_residuals[36].stddev, expected 32, is %d", + check_msg->stec_residuals[36].stddev); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.constellation == 34, + "incorrect value for stec_residuals[36].sv_id.constellation, " + "expected 34, is %d", + check_msg->stec_residuals[36].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.satId == 236, + "incorrect value for stec_residuals[36].sv_id.satId, " + "expected 236, is %d", + check_msg->stec_residuals[36].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[37].residual == 25873, + "incorrect value for stec_residuals[37].residual, expected " + "25873, is %d", + check_msg->stec_residuals[37].residual); + ck_assert_msg( + check_msg->stec_residuals[37].stddev == 200, + "incorrect value for stec_residuals[37].stddev, expected 200, is %d", + check_msg->stec_residuals[37].stddev); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.constellation == 1, + "incorrect value for stec_residuals[37].sv_id.constellation, " + "expected 1, is %d", + check_msg->stec_residuals[37].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.satId == 109, + "incorrect value for stec_residuals[37].sv_id.satId, " + "expected 109, is %d", + check_msg->stec_residuals[37].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[38].residual == -22403, + "incorrect value for stec_residuals[38].residual, expected " + "-22403, is %d", + check_msg->stec_residuals[38].residual); + ck_assert_msg( + check_msg->stec_residuals[38].stddev == 137, + "incorrect value for stec_residuals[38].stddev, expected 137, is %d", + check_msg->stec_residuals[38].stddev); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.constellation == 94, + "incorrect value for stec_residuals[38].sv_id.constellation, " + "expected 94, is %d", + check_msg->stec_residuals[38].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.satId == 25, + "incorrect value for stec_residuals[38].sv_id.satId, " + "expected 25, is %d", + check_msg->stec_residuals[38].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[39].residual == 7588, + "incorrect value for stec_residuals[39].residual, expected 7588, is %d", + check_msg->stec_residuals[39].residual); + ck_assert_msg( + check_msg->stec_residuals[39].stddev == 31, + "incorrect value for stec_residuals[39].stddev, expected 31, is %d", + check_msg->stec_residuals[39].stddev); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.constellation == 4, + "incorrect value for stec_residuals[39].sv_id.constellation, " + "expected 4, is %d", + check_msg->stec_residuals[39].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.satId == 157, + "incorrect value for stec_residuals[39].sv_id.satId, " + "expected 157, is %d", + check_msg->stec_residuals[39].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[40].residual == -6840, + "incorrect value for stec_residuals[40].residual, expected " + "-6840, is %d", + check_msg->stec_residuals[40].residual); + ck_assert_msg( + check_msg->stec_residuals[40].stddev == 126, + "incorrect value for stec_residuals[40].stddev, expected 126, is %d", + check_msg->stec_residuals[40].stddev); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.constellation == 132, + "incorrect value for stec_residuals[40].sv_id.constellation, " + "expected 132, is %d", + check_msg->stec_residuals[40].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.satId == 48, + "incorrect value for stec_residuals[40].sv_id.satId, " + "expected 48, is %d", + check_msg->stec_residuals[40].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[41].residual == -31412, + "incorrect value for stec_residuals[41].residual, expected " + "-31412, is %d", + check_msg->stec_residuals[41].residual); + ck_assert_msg( + check_msg->stec_residuals[41].stddev == 21, + "incorrect value for stec_residuals[41].stddev, expected 21, is %d", + check_msg->stec_residuals[41].stddev); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.constellation == 68, + "incorrect value for stec_residuals[41].sv_id.constellation, " + "expected 68, is %d", + check_msg->stec_residuals[41].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.satId == 186, + "incorrect value for stec_residuals[41].sv_id.satId, " + "expected 186, is %d", + check_msg->stec_residuals[41].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[42].residual == -23413, + "incorrect value for stec_residuals[42].residual, expected " + "-23413, is %d", + check_msg->stec_residuals[42].residual); + ck_assert_msg( + check_msg->stec_residuals[42].stddev == 148, + "incorrect value for stec_residuals[42].stddev, expected 148, is %d", + check_msg->stec_residuals[42].stddev); + ck_assert_msg(check_msg->stec_residuals[42].sv_id.constellation == 180, + "incorrect value for stec_residuals[42].sv_id.constellation, " + "expected 180, is %d", + check_msg->stec_residuals[42].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[42].sv_id.satId == 0, + "incorrect value for stec_residuals[42].sv_id.satId, expected 0, is %d", + check_msg->stec_residuals[42].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[43].residual == 30934, + "incorrect value for stec_residuals[43].residual, expected " + "30934, is %d", + check_msg->stec_residuals[43].residual); + ck_assert_msg( + check_msg->stec_residuals[43].stddev == 177, + "incorrect value for stec_residuals[43].stddev, expected 177, is %d", + check_msg->stec_residuals[43].stddev); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.constellation == 149, + "incorrect value for stec_residuals[43].sv_id.constellation, " + "expected 149, is %d", + check_msg->stec_residuals[43].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.satId == 119, + "incorrect value for stec_residuals[43].sv_id.satId, " + "expected 119, is %d", + check_msg->stec_residuals[43].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[44].residual == 26960, + "incorrect value for stec_residuals[44].residual, expected " + "26960, is %d", + check_msg->stec_residuals[44].residual); + ck_assert_msg( + check_msg->stec_residuals[44].stddev == 10, + "incorrect value for stec_residuals[44].stddev, expected 10, is %d", + check_msg->stec_residuals[44].stddev); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.constellation == 80, + "incorrect value for stec_residuals[44].sv_id.constellation, " + "expected 80, is %d", + check_msg->stec_residuals[44].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.satId == 201, + "incorrect value for stec_residuals[44].sv_id.satId, " + "expected 201, is %d", + check_msg->stec_residuals[44].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[45].residual == 11853, + "incorrect value for stec_residuals[45].residual, expected " + "11853, is %d", + check_msg->stec_residuals[45].residual); + ck_assert_msg( + check_msg->stec_residuals[45].stddev == 233, + "incorrect value for stec_residuals[45].stddev, expected 233, is %d", + check_msg->stec_residuals[45].stddev); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.constellation == 118, + "incorrect value for stec_residuals[45].sv_id.constellation, " + "expected 118, is %d", + check_msg->stec_residuals[45].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.satId == 136, + "incorrect value for stec_residuals[45].sv_id.satId, " + "expected 136, is %d", + check_msg->stec_residuals[45].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[46].residual == -25077, + "incorrect value for stec_residuals[46].residual, expected " + "-25077, is %d", + check_msg->stec_residuals[46].residual); + ck_assert_msg( + check_msg->stec_residuals[46].stddev == 103, + "incorrect value for stec_residuals[46].stddev, expected 103, is %d", + check_msg->stec_residuals[46].stddev); + ck_assert_msg(check_msg->stec_residuals[46].sv_id.constellation == 227, + "incorrect value for stec_residuals[46].sv_id.constellation, " + "expected 227, is %d", + check_msg->stec_residuals[46].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[46].sv_id.satId == 233, + "incorrect value for stec_residuals[46].sv_id.satId, " + "expected 233, is %d", + check_msg->stec_residuals[46].sv_id.satId); + ck_assert_msg(check_msg->tropo_delay_correction.hydro == 10643, + "incorrect value for tropo_delay_correction.hydro, expected " + "10643, is %d", + check_msg->tropo_delay_correction.hydro); + ck_assert_msg( + check_msg->tropo_delay_correction.stddev == 92, + "incorrect value for tropo_delay_correction.stddev, expected 92, is %d", + check_msg->tropo_delay_correction.stddev); + ck_assert_msg( + check_msg->tropo_delay_correction.wet == 33, + "incorrect value for tropo_delay_correction.wet, expected 33, is %d", + check_msg->tropo_delay_correction.wet); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c new file mode 100644 index 0000000000..4cc108d9d2 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.c @@ -0,0 +1,1390 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5f0, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5f0, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, + 67, 248, 233, 236, 230, 230, 103, 122, 63, 101, 231, 157, 115, 162, + 197, 146, 35, 107, 222, 109, 52, 41, 86, 12, 237, 184, 65, 204, + 137, 148, 171, 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, + 203, 92, 166, 30, 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, + 95, 250, 99, 196, 92, 214, 159, 253, 195, 222, 233, 146, 233, 63, + 76, 24, 106, 40, 253, 65, 9, 183, 40, 215, 188, 59, 117, 69, + 97, 115, 60, 56, 0, 141, 207, 171, 54, 161, 23, 61, 0, 87, + 230, 123, 87, 36, 184, 255, 14, 163, 187, 224, 43, 151, 151, 104, + 39, 57, 5, 54, 48, 224, 181, 129, 60, 92, 171, 114, 109, 109, + 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, 24, 68, 160, 36, + 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, 221, 253, 15, + 62, 23, 121, 185, 168, 116, 4, 147, 123, 72, 223, 119, 226, 242, + 161, 204, 180, 202, 137, 166, 58, 24, 124, 19, 181, 188, 16, 107, + 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, 221, + 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, + 99, 44, 95, 131, 89, 192, 225, 55, 95, 171, 88, 205, 21, 116, + 231, 83, 71, 71, 100, 110, 217, 254, 152, 212, 18, 8, 40, 157, + 244, 54, 72, 240, 231, 189, 111, 195, 205, 81, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_gridded_correction_no_std_dep_a_t *test_msg = + (msg_ssr_gridded_correction_no_std_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.iod_atmo = 236; + test_msg->header.num_msgs = 62837; + test_msg->header.seq_num = 63555; + test_msg->header.time.tow = 2837573811; + test_msg->header.time.wn = 8940; + test_msg->header.tropo_quality_indicator = 230; + test_msg->header.update_interval = 233; + test_msg->index = 26598; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[0].residual = -23949; + test_msg->stec_residuals[0].sv_id.constellation = 157; + test_msg->stec_residuals[0].sv_id.satId = 231; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[1].residual = 27427; + test_msg->stec_residuals[1].sv_id.constellation = 146; + test_msg->stec_residuals[1].sv_id.satId = 197; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[2].residual = 10548; + test_msg->stec_residuals[2].sv_id.constellation = 109; + test_msg->stec_residuals[2].sv_id.satId = 222; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[3].residual = -18195; + test_msg->stec_residuals[3].sv_id.constellation = 12; + test_msg->stec_residuals[3].sv_id.satId = 86; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[4].residual = -27511; + test_msg->stec_residuals[4].sv_id.constellation = 204; + test_msg->stec_residuals[4].sv_id.satId = 65; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[5].residual = 11; + test_msg->stec_residuals[5].sv_id.constellation = 183; + test_msg->stec_residuals[5].sv_id.satId = 171; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[6].residual = 13740; + test_msg->stec_residuals[6].sv_id.constellation = 203; + test_msg->stec_residuals[6].sv_id.satId = 180; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[7].residual = 29626; + test_msg->stec_residuals[7].sv_id.constellation = 85; + test_msg->stec_residuals[7].sv_id.satId = 196; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[8].residual = 7846; + test_msg->stec_residuals[8].sv_id.constellation = 92; + test_msg->stec_residuals[8].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[9].residual = 18376; + test_msg->stec_residuals[9].sv_id.constellation = 13; + test_msg->stec_residuals[9].sv_id.satId = 42; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[10].residual = -24357; + test_msg->stec_residuals[10].sv_id.constellation = 137; + test_msg->stec_residuals[10].sv_id.satId = 98; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[11].residual = -1441; + test_msg->stec_residuals[11].sv_id.constellation = 216; + test_msg->stec_residuals[11].sv_id.satId = 95; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[12].residual = -10660; + test_msg->stec_residuals[12].sv_id.constellation = 196; + test_msg->stec_residuals[12].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[13].residual = -8509; + test_msg->stec_residuals[13].sv_id.constellation = 253; + test_msg->stec_residuals[13].sv_id.satId = 159; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[14].residual = 16361; + test_msg->stec_residuals[14].sv_id.constellation = 146; + test_msg->stec_residuals[14].sv_id.satId = 233; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[15].residual = 10346; + test_msg->stec_residuals[15].sv_id.constellation = 24; + test_msg->stec_residuals[15].sv_id.satId = 76; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[16].residual = -18679; + test_msg->stec_residuals[16].sv_id.constellation = 65; + test_msg->stec_residuals[16].sv_id.satId = 253; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[17].residual = 15292; + test_msg->stec_residuals[17].sv_id.constellation = 215; + test_msg->stec_residuals[17].sv_id.satId = 40; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[18].residual = 29537; + test_msg->stec_residuals[18].sv_id.constellation = 69; + test_msg->stec_residuals[18].sv_id.satId = 117; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[19].residual = -29440; + test_msg->stec_residuals[19].sv_id.constellation = 56; + test_msg->stec_residuals[19].sv_id.satId = 60; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[20].residual = -24266; + test_msg->stec_residuals[20].sv_id.constellation = 171; + test_msg->stec_residuals[20].sv_id.satId = 207; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[21].residual = 22272; + test_msg->stec_residuals[21].sv_id.constellation = 61; + test_msg->stec_residuals[21].sv_id.satId = 23; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[22].residual = 9303; + test_msg->stec_residuals[22].sv_id.constellation = 123; + test_msg->stec_residuals[22].sv_id.satId = 230; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[23].residual = -23794; + test_msg->stec_residuals[23].sv_id.constellation = 255; + test_msg->stec_residuals[23].sv_id.satId = 184; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[24].residual = -26837; + test_msg->stec_residuals[24].sv_id.constellation = 224; + test_msg->stec_residuals[24].sv_id.satId = 187; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[25].residual = 14631; + test_msg->stec_residuals[25].sv_id.constellation = 104; + test_msg->stec_residuals[25].sv_id.satId = 151; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[26].residual = -8144; + test_msg->stec_residuals[26].sv_id.constellation = 54; + test_msg->stec_residuals[26].sv_id.satId = 5; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[27].residual = 23612; + test_msg->stec_residuals[27].sv_id.constellation = 129; + test_msg->stec_residuals[27].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[28].residual = 28013; + test_msg->stec_residuals[28].sv_id.constellation = 114; + test_msg->stec_residuals[28].sv_id.satId = 171; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[29].residual = 2166; + test_msg->stec_residuals[29].sv_id.constellation = 23; + test_msg->stec_residuals[29].sv_id.satId = 12; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[30].residual = -10186; + test_msg->stec_residuals[30].sv_id.constellation = 159; + test_msg->stec_residuals[30].sv_id.satId = 64; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[31].residual = 17432; + test_msg->stec_residuals[31].sv_id.constellation = 20; + test_msg->stec_residuals[31].sv_id.satId = 33; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[32].residual = -8666; + test_msg->stec_residuals[32].sv_id.constellation = 36; + test_msg->stec_residuals[32].sv_id.satId = 160; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[33].residual = 25436; + test_msg->stec_residuals[33].sv_id.constellation = 190; + test_msg->stec_residuals[33].sv_id.satId = 145; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[34].residual = -3864; + test_msg->stec_residuals[34].sv_id.constellation = 159; + test_msg->stec_residuals[34].sv_id.satId = 108; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[35].residual = 4093; + test_msg->stec_residuals[35].sv_id.constellation = 221; + test_msg->stec_residuals[35].sv_id.satId = 227; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[36].residual = -18055; + test_msg->stec_residuals[36].sv_id.constellation = 23; + test_msg->stec_residuals[36].sv_id.satId = 62; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[37].residual = -27900; + test_msg->stec_residuals[37].sv_id.constellation = 116; + test_msg->stec_residuals[37].sv_id.satId = 168; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[38].residual = 30687; + test_msg->stec_residuals[38].sv_id.constellation = 72; + test_msg->stec_residuals[38].sv_id.satId = 123; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[39].residual = -13151; + test_msg->stec_residuals[39].sv_id.constellation = 242; + test_msg->stec_residuals[39].sv_id.satId = 226; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[40].residual = -22903; + test_msg->stec_residuals[40].sv_id.constellation = 202; + test_msg->stec_residuals[40].sv_id.satId = 180; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[41].residual = 4988; + test_msg->stec_residuals[41].sv_id.constellation = 24; + test_msg->stec_residuals[41].sv_id.satId = 58; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[42].residual = 27408; + test_msg->stec_residuals[42].sv_id.constellation = 188; + test_msg->stec_residuals[42].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[43].residual = 319; + test_msg->stec_residuals[43].sv_id.constellation = 231; + test_msg->stec_residuals[43].sv_id.satId = 66; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[44].residual = 15987; + test_msg->stec_residuals[44].sv_id.constellation = 252; + test_msg->stec_residuals[44].sv_id.satId = 64; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[45].residual = 22266; + test_msg->stec_residuals[45].sv_id.constellation = 97; + test_msg->stec_residuals[45].sv_id.satId = 233; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[46].residual = -19919; + test_msg->stec_residuals[46].sv_id.constellation = 221; + test_msg->stec_residuals[46].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[47].residual = 17350; + test_msg->stec_residuals[47].sv_id.constellation = 73; + test_msg->stec_residuals[47].sv_id.satId = 32; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[48].residual = 14410; + test_msg->stec_residuals[48].sv_id.constellation = 253; + test_msg->stec_residuals[48].sv_id.satId = 249; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[49].residual = 23671; + test_msg->stec_residuals[49].sv_id.constellation = 165; + test_msg->stec_residuals[49].sv_id.satId = 38; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[50].residual = -31905; + test_msg->stec_residuals[50].sv_id.constellation = 44; + test_msg->stec_residuals[50].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[51].residual = 14305; + test_msg->stec_residuals[51].sv_id.constellation = 192; + test_msg->stec_residuals[51].sv_id.satId = 89; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[52].residual = -12968; + test_msg->stec_residuals[52].sv_id.constellation = 171; + test_msg->stec_residuals[52].sv_id.satId = 95; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[53].residual = 21479; + test_msg->stec_residuals[53].sv_id.constellation = 116; + test_msg->stec_residuals[53].sv_id.satId = 21; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[54].residual = 28260; + test_msg->stec_residuals[54].sv_id.constellation = 71; + test_msg->stec_residuals[54].sv_id.satId = 71; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[55].residual = -11112; + test_msg->stec_residuals[55].sv_id.constellation = 254; + test_msg->stec_residuals[55].sv_id.satId = 217; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[56].residual = -25304; + test_msg->stec_residuals[56].sv_id.constellation = 8; + test_msg->stec_residuals[56].sv_id.satId = 18; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[57].residual = -4024; + test_msg->stec_residuals[57].sv_id.constellation = 54; + test_msg->stec_residuals[57].sv_id.satId = 244; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_residuals[0]); + } + test_msg->stec_residuals[58].residual = -15505; + test_msg->stec_residuals[58].sv_id.constellation = 189; + test_msg->stec_residuals[58].sv_id.satId = 231; + test_msg->tropo_delay_correction.hydro = 16250; + test_msg->tropo_delay_correction.wet = 101; + sbp_payload_send(&sbp_state, 0x5f0, 7270, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 7270, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 7270, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5f0, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_gridded_correction_no_std_dep_a_t *check_msg = + (msg_ssr_gridded_correction_no_std_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->header.iod_atmo == 236, + "incorrect value for header.iod_atmo, expected 236, is %d", + check_msg->header.iod_atmo); + ck_assert_msg(check_msg->header.num_msgs == 62837, + "incorrect value for header.num_msgs, expected 62837, is %d", + check_msg->header.num_msgs); + ck_assert_msg(check_msg->header.seq_num == 63555, + "incorrect value for header.seq_num, expected 63555, is %d", + check_msg->header.seq_num); + ck_assert_msg( + check_msg->header.time.tow == 2837573811, + "incorrect value for header.time.tow, expected 2837573811, is %d", + check_msg->header.time.tow); + ck_assert_msg(check_msg->header.time.wn == 8940, + "incorrect value for header.time.wn, expected 8940, is %d", + check_msg->header.time.wn); + ck_assert_msg(check_msg->header.tropo_quality_indicator == 230, + "incorrect value for header.tropo_quality_indicator, " + "expected 230, is %d", + check_msg->header.tropo_quality_indicator); + ck_assert_msg( + check_msg->header.update_interval == 233, + "incorrect value for header.update_interval, expected 233, is %d", + check_msg->header.update_interval); + ck_assert_msg(check_msg->index == 26598, + "incorrect value for index, expected 26598, is %d", + check_msg->index); + ck_assert_msg(check_msg->stec_residuals[0].residual == -23949, + "incorrect value for stec_residuals[0].residual, expected " + "-23949, is %d", + check_msg->stec_residuals[0].residual); + ck_assert_msg(check_msg->stec_residuals[0].sv_id.constellation == 157, + "incorrect value for stec_residuals[0].sv_id.constellation, " + "expected 157, is %d", + check_msg->stec_residuals[0].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[0].sv_id.satId == 231, + "incorrect value for stec_residuals[0].sv_id.satId, expected " + "231, is %d", + check_msg->stec_residuals[0].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[1].residual == 27427, + "incorrect value for stec_residuals[1].residual, expected 27427, is %d", + check_msg->stec_residuals[1].residual); + ck_assert_msg(check_msg->stec_residuals[1].sv_id.constellation == 146, + "incorrect value for stec_residuals[1].sv_id.constellation, " + "expected 146, is %d", + check_msg->stec_residuals[1].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[1].sv_id.satId == 197, + "incorrect value for stec_residuals[1].sv_id.satId, expected " + "197, is %d", + check_msg->stec_residuals[1].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[2].residual == 10548, + "incorrect value for stec_residuals[2].residual, expected 10548, is %d", + check_msg->stec_residuals[2].residual); + ck_assert_msg(check_msg->stec_residuals[2].sv_id.constellation == 109, + "incorrect value for stec_residuals[2].sv_id.constellation, " + "expected 109, is %d", + check_msg->stec_residuals[2].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[2].sv_id.satId == 222, + "incorrect value for stec_residuals[2].sv_id.satId, expected " + "222, is %d", + check_msg->stec_residuals[2].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[3].residual == -18195, + "incorrect value for stec_residuals[3].residual, expected " + "-18195, is %d", + check_msg->stec_residuals[3].residual); + ck_assert_msg(check_msg->stec_residuals[3].sv_id.constellation == 12, + "incorrect value for stec_residuals[3].sv_id.constellation, " + "expected 12, is %d", + check_msg->stec_residuals[3].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[3].sv_id.satId == 86, + "incorrect value for stec_residuals[3].sv_id.satId, expected 86, is %d", + check_msg->stec_residuals[3].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[4].residual == -27511, + "incorrect value for stec_residuals[4].residual, expected " + "-27511, is %d", + check_msg->stec_residuals[4].residual); + ck_assert_msg(check_msg->stec_residuals[4].sv_id.constellation == 204, + "incorrect value for stec_residuals[4].sv_id.constellation, " + "expected 204, is %d", + check_msg->stec_residuals[4].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[4].sv_id.satId == 65, + "incorrect value for stec_residuals[4].sv_id.satId, expected 65, is %d", + check_msg->stec_residuals[4].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[5].residual == 11, + "incorrect value for stec_residuals[5].residual, expected 11, is %d", + check_msg->stec_residuals[5].residual); + ck_assert_msg(check_msg->stec_residuals[5].sv_id.constellation == 183, + "incorrect value for stec_residuals[5].sv_id.constellation, " + "expected 183, is %d", + check_msg->stec_residuals[5].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[5].sv_id.satId == 171, + "incorrect value for stec_residuals[5].sv_id.satId, expected " + "171, is %d", + check_msg->stec_residuals[5].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[6].residual == 13740, + "incorrect value for stec_residuals[6].residual, expected 13740, is %d", + check_msg->stec_residuals[6].residual); + ck_assert_msg(check_msg->stec_residuals[6].sv_id.constellation == 203, + "incorrect value for stec_residuals[6].sv_id.constellation, " + "expected 203, is %d", + check_msg->stec_residuals[6].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[6].sv_id.satId == 180, + "incorrect value for stec_residuals[6].sv_id.satId, expected " + "180, is %d", + check_msg->stec_residuals[6].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[7].residual == 29626, + "incorrect value for stec_residuals[7].residual, expected 29626, is %d", + check_msg->stec_residuals[7].residual); + ck_assert_msg(check_msg->stec_residuals[7].sv_id.constellation == 85, + "incorrect value for stec_residuals[7].sv_id.constellation, " + "expected 85, is %d", + check_msg->stec_residuals[7].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[7].sv_id.satId == 196, + "incorrect value for stec_residuals[7].sv_id.satId, expected " + "196, is %d", + check_msg->stec_residuals[7].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[8].residual == 7846, + "incorrect value for stec_residuals[8].residual, expected 7846, is %d", + check_msg->stec_residuals[8].residual); + ck_assert_msg(check_msg->stec_residuals[8].sv_id.constellation == 92, + "incorrect value for stec_residuals[8].sv_id.constellation, " + "expected 92, is %d", + check_msg->stec_residuals[8].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[8].sv_id.satId == 203, + "incorrect value for stec_residuals[8].sv_id.satId, expected " + "203, is %d", + check_msg->stec_residuals[8].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[9].residual == 18376, + "incorrect value for stec_residuals[9].residual, expected 18376, is %d", + check_msg->stec_residuals[9].residual); + ck_assert_msg(check_msg->stec_residuals[9].sv_id.constellation == 13, + "incorrect value for stec_residuals[9].sv_id.constellation, " + "expected 13, is %d", + check_msg->stec_residuals[9].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[9].sv_id.satId == 42, + "incorrect value for stec_residuals[9].sv_id.satId, expected 42, is %d", + check_msg->stec_residuals[9].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[10].residual == -24357, + "incorrect value for stec_residuals[10].residual, expected " + "-24357, is %d", + check_msg->stec_residuals[10].residual); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.constellation == 137, + "incorrect value for stec_residuals[10].sv_id.constellation, " + "expected 137, is %d", + check_msg->stec_residuals[10].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[10].sv_id.satId == 98, + "incorrect value for stec_residuals[10].sv_id.satId, " + "expected 98, is %d", + check_msg->stec_residuals[10].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[11].residual == -1441, + "incorrect value for stec_residuals[11].residual, expected " + "-1441, is %d", + check_msg->stec_residuals[11].residual); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.constellation == 216, + "incorrect value for stec_residuals[11].sv_id.constellation, " + "expected 216, is %d", + check_msg->stec_residuals[11].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[11].sv_id.satId == 95, + "incorrect value for stec_residuals[11].sv_id.satId, " + "expected 95, is %d", + check_msg->stec_residuals[11].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[12].residual == -10660, + "incorrect value for stec_residuals[12].residual, expected " + "-10660, is %d", + check_msg->stec_residuals[12].residual); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.constellation == 196, + "incorrect value for stec_residuals[12].sv_id.constellation, " + "expected 196, is %d", + check_msg->stec_residuals[12].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[12].sv_id.satId == 99, + "incorrect value for stec_residuals[12].sv_id.satId, " + "expected 99, is %d", + check_msg->stec_residuals[12].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[13].residual == -8509, + "incorrect value for stec_residuals[13].residual, expected " + "-8509, is %d", + check_msg->stec_residuals[13].residual); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.constellation == 253, + "incorrect value for stec_residuals[13].sv_id.constellation, " + "expected 253, is %d", + check_msg->stec_residuals[13].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[13].sv_id.satId == 159, + "incorrect value for stec_residuals[13].sv_id.satId, " + "expected 159, is %d", + check_msg->stec_residuals[13].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[14].residual == 16361, + "incorrect value for stec_residuals[14].residual, expected " + "16361, is %d", + check_msg->stec_residuals[14].residual); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.constellation == 146, + "incorrect value for stec_residuals[14].sv_id.constellation, " + "expected 146, is %d", + check_msg->stec_residuals[14].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[14].sv_id.satId == 233, + "incorrect value for stec_residuals[14].sv_id.satId, " + "expected 233, is %d", + check_msg->stec_residuals[14].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[15].residual == 10346, + "incorrect value for stec_residuals[15].residual, expected " + "10346, is %d", + check_msg->stec_residuals[15].residual); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.constellation == 24, + "incorrect value for stec_residuals[15].sv_id.constellation, " + "expected 24, is %d", + check_msg->stec_residuals[15].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[15].sv_id.satId == 76, + "incorrect value for stec_residuals[15].sv_id.satId, " + "expected 76, is %d", + check_msg->stec_residuals[15].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[16].residual == -18679, + "incorrect value for stec_residuals[16].residual, expected " + "-18679, is %d", + check_msg->stec_residuals[16].residual); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.constellation == 65, + "incorrect value for stec_residuals[16].sv_id.constellation, " + "expected 65, is %d", + check_msg->stec_residuals[16].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[16].sv_id.satId == 253, + "incorrect value for stec_residuals[16].sv_id.satId, " + "expected 253, is %d", + check_msg->stec_residuals[16].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[17].residual == 15292, + "incorrect value for stec_residuals[17].residual, expected " + "15292, is %d", + check_msg->stec_residuals[17].residual); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.constellation == 215, + "incorrect value for stec_residuals[17].sv_id.constellation, " + "expected 215, is %d", + check_msg->stec_residuals[17].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[17].sv_id.satId == 40, + "incorrect value for stec_residuals[17].sv_id.satId, " + "expected 40, is %d", + check_msg->stec_residuals[17].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[18].residual == 29537, + "incorrect value for stec_residuals[18].residual, expected " + "29537, is %d", + check_msg->stec_residuals[18].residual); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.constellation == 69, + "incorrect value for stec_residuals[18].sv_id.constellation, " + "expected 69, is %d", + check_msg->stec_residuals[18].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[18].sv_id.satId == 117, + "incorrect value for stec_residuals[18].sv_id.satId, " + "expected 117, is %d", + check_msg->stec_residuals[18].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[19].residual == -29440, + "incorrect value for stec_residuals[19].residual, expected " + "-29440, is %d", + check_msg->stec_residuals[19].residual); + ck_assert_msg(check_msg->stec_residuals[19].sv_id.constellation == 56, + "incorrect value for stec_residuals[19].sv_id.constellation, " + "expected 56, is %d", + check_msg->stec_residuals[19].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[19].sv_id.satId == 60, + "incorrect value for stec_residuals[19].sv_id.satId, " + "expected 60, is %d", + check_msg->stec_residuals[19].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[20].residual == -24266, + "incorrect value for stec_residuals[20].residual, expected " + "-24266, is %d", + check_msg->stec_residuals[20].residual); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.constellation == 171, + "incorrect value for stec_residuals[20].sv_id.constellation, " + "expected 171, is %d", + check_msg->stec_residuals[20].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[20].sv_id.satId == 207, + "incorrect value for stec_residuals[20].sv_id.satId, " + "expected 207, is %d", + check_msg->stec_residuals[20].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[21].residual == 22272, + "incorrect value for stec_residuals[21].residual, expected " + "22272, is %d", + check_msg->stec_residuals[21].residual); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.constellation == 61, + "incorrect value for stec_residuals[21].sv_id.constellation, " + "expected 61, is %d", + check_msg->stec_residuals[21].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[21].sv_id.satId == 23, + "incorrect value for stec_residuals[21].sv_id.satId, " + "expected 23, is %d", + check_msg->stec_residuals[21].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[22].residual == 9303, + "incorrect value for stec_residuals[22].residual, expected 9303, is %d", + check_msg->stec_residuals[22].residual); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.constellation == 123, + "incorrect value for stec_residuals[22].sv_id.constellation, " + "expected 123, is %d", + check_msg->stec_residuals[22].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[22].sv_id.satId == 230, + "incorrect value for stec_residuals[22].sv_id.satId, " + "expected 230, is %d", + check_msg->stec_residuals[22].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[23].residual == -23794, + "incorrect value for stec_residuals[23].residual, expected " + "-23794, is %d", + check_msg->stec_residuals[23].residual); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.constellation == 255, + "incorrect value for stec_residuals[23].sv_id.constellation, " + "expected 255, is %d", + check_msg->stec_residuals[23].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[23].sv_id.satId == 184, + "incorrect value for stec_residuals[23].sv_id.satId, " + "expected 184, is %d", + check_msg->stec_residuals[23].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[24].residual == -26837, + "incorrect value for stec_residuals[24].residual, expected " + "-26837, is %d", + check_msg->stec_residuals[24].residual); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.constellation == 224, + "incorrect value for stec_residuals[24].sv_id.constellation, " + "expected 224, is %d", + check_msg->stec_residuals[24].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[24].sv_id.satId == 187, + "incorrect value for stec_residuals[24].sv_id.satId, " + "expected 187, is %d", + check_msg->stec_residuals[24].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[25].residual == 14631, + "incorrect value for stec_residuals[25].residual, expected " + "14631, is %d", + check_msg->stec_residuals[25].residual); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.constellation == 104, + "incorrect value for stec_residuals[25].sv_id.constellation, " + "expected 104, is %d", + check_msg->stec_residuals[25].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[25].sv_id.satId == 151, + "incorrect value for stec_residuals[25].sv_id.satId, " + "expected 151, is %d", + check_msg->stec_residuals[25].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[26].residual == -8144, + "incorrect value for stec_residuals[26].residual, expected " + "-8144, is %d", + check_msg->stec_residuals[26].residual); + ck_assert_msg(check_msg->stec_residuals[26].sv_id.constellation == 54, + "incorrect value for stec_residuals[26].sv_id.constellation, " + "expected 54, is %d", + check_msg->stec_residuals[26].sv_id.constellation); + ck_assert_msg( + check_msg->stec_residuals[26].sv_id.satId == 5, + "incorrect value for stec_residuals[26].sv_id.satId, expected 5, is %d", + check_msg->stec_residuals[26].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[27].residual == 23612, + "incorrect value for stec_residuals[27].residual, expected " + "23612, is %d", + check_msg->stec_residuals[27].residual); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.constellation == 129, + "incorrect value for stec_residuals[27].sv_id.constellation, " + "expected 129, is %d", + check_msg->stec_residuals[27].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[27].sv_id.satId == 181, + "incorrect value for stec_residuals[27].sv_id.satId, " + "expected 181, is %d", + check_msg->stec_residuals[27].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[28].residual == 28013, + "incorrect value for stec_residuals[28].residual, expected " + "28013, is %d", + check_msg->stec_residuals[28].residual); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.constellation == 114, + "incorrect value for stec_residuals[28].sv_id.constellation, " + "expected 114, is %d", + check_msg->stec_residuals[28].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[28].sv_id.satId == 171, + "incorrect value for stec_residuals[28].sv_id.satId, " + "expected 171, is %d", + check_msg->stec_residuals[28].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[29].residual == 2166, + "incorrect value for stec_residuals[29].residual, expected 2166, is %d", + check_msg->stec_residuals[29].residual); + ck_assert_msg(check_msg->stec_residuals[29].sv_id.constellation == 23, + "incorrect value for stec_residuals[29].sv_id.constellation, " + "expected 23, is %d", + check_msg->stec_residuals[29].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[29].sv_id.satId == 12, + "incorrect value for stec_residuals[29].sv_id.satId, " + "expected 12, is %d", + check_msg->stec_residuals[29].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[30].residual == -10186, + "incorrect value for stec_residuals[30].residual, expected " + "-10186, is %d", + check_msg->stec_residuals[30].residual); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.constellation == 159, + "incorrect value for stec_residuals[30].sv_id.constellation, " + "expected 159, is %d", + check_msg->stec_residuals[30].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[30].sv_id.satId == 64, + "incorrect value for stec_residuals[30].sv_id.satId, " + "expected 64, is %d", + check_msg->stec_residuals[30].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[31].residual == 17432, + "incorrect value for stec_residuals[31].residual, expected " + "17432, is %d", + check_msg->stec_residuals[31].residual); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.constellation == 20, + "incorrect value for stec_residuals[31].sv_id.constellation, " + "expected 20, is %d", + check_msg->stec_residuals[31].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[31].sv_id.satId == 33, + "incorrect value for stec_residuals[31].sv_id.satId, " + "expected 33, is %d", + check_msg->stec_residuals[31].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[32].residual == -8666, + "incorrect value for stec_residuals[32].residual, expected " + "-8666, is %d", + check_msg->stec_residuals[32].residual); + ck_assert_msg(check_msg->stec_residuals[32].sv_id.constellation == 36, + "incorrect value for stec_residuals[32].sv_id.constellation, " + "expected 36, is %d", + check_msg->stec_residuals[32].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[32].sv_id.satId == 160, + "incorrect value for stec_residuals[32].sv_id.satId, " + "expected 160, is %d", + check_msg->stec_residuals[32].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[33].residual == 25436, + "incorrect value for stec_residuals[33].residual, expected " + "25436, is %d", + check_msg->stec_residuals[33].residual); + ck_assert_msg(check_msg->stec_residuals[33].sv_id.constellation == 190, + "incorrect value for stec_residuals[33].sv_id.constellation, " + "expected 190, is %d", + check_msg->stec_residuals[33].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[33].sv_id.satId == 145, + "incorrect value for stec_residuals[33].sv_id.satId, " + "expected 145, is %d", + check_msg->stec_residuals[33].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[34].residual == -3864, + "incorrect value for stec_residuals[34].residual, expected " + "-3864, is %d", + check_msg->stec_residuals[34].residual); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.constellation == 159, + "incorrect value for stec_residuals[34].sv_id.constellation, " + "expected 159, is %d", + check_msg->stec_residuals[34].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[34].sv_id.satId == 108, + "incorrect value for stec_residuals[34].sv_id.satId, " + "expected 108, is %d", + check_msg->stec_residuals[34].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[35].residual == 4093, + "incorrect value for stec_residuals[35].residual, expected 4093, is %d", + check_msg->stec_residuals[35].residual); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.constellation == 221, + "incorrect value for stec_residuals[35].sv_id.constellation, " + "expected 221, is %d", + check_msg->stec_residuals[35].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[35].sv_id.satId == 227, + "incorrect value for stec_residuals[35].sv_id.satId, " + "expected 227, is %d", + check_msg->stec_residuals[35].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[36].residual == -18055, + "incorrect value for stec_residuals[36].residual, expected " + "-18055, is %d", + check_msg->stec_residuals[36].residual); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.constellation == 23, + "incorrect value for stec_residuals[36].sv_id.constellation, " + "expected 23, is %d", + check_msg->stec_residuals[36].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[36].sv_id.satId == 62, + "incorrect value for stec_residuals[36].sv_id.satId, " + "expected 62, is %d", + check_msg->stec_residuals[36].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[37].residual == -27900, + "incorrect value for stec_residuals[37].residual, expected " + "-27900, is %d", + check_msg->stec_residuals[37].residual); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.constellation == 116, + "incorrect value for stec_residuals[37].sv_id.constellation, " + "expected 116, is %d", + check_msg->stec_residuals[37].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[37].sv_id.satId == 168, + "incorrect value for stec_residuals[37].sv_id.satId, " + "expected 168, is %d", + check_msg->stec_residuals[37].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[38].residual == 30687, + "incorrect value for stec_residuals[38].residual, expected " + "30687, is %d", + check_msg->stec_residuals[38].residual); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.constellation == 72, + "incorrect value for stec_residuals[38].sv_id.constellation, " + "expected 72, is %d", + check_msg->stec_residuals[38].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[38].sv_id.satId == 123, + "incorrect value for stec_residuals[38].sv_id.satId, " + "expected 123, is %d", + check_msg->stec_residuals[38].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[39].residual == -13151, + "incorrect value for stec_residuals[39].residual, expected " + "-13151, is %d", + check_msg->stec_residuals[39].residual); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.constellation == 242, + "incorrect value for stec_residuals[39].sv_id.constellation, " + "expected 242, is %d", + check_msg->stec_residuals[39].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[39].sv_id.satId == 226, + "incorrect value for stec_residuals[39].sv_id.satId, " + "expected 226, is %d", + check_msg->stec_residuals[39].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[40].residual == -22903, + "incorrect value for stec_residuals[40].residual, expected " + "-22903, is %d", + check_msg->stec_residuals[40].residual); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.constellation == 202, + "incorrect value for stec_residuals[40].sv_id.constellation, " + "expected 202, is %d", + check_msg->stec_residuals[40].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[40].sv_id.satId == 180, + "incorrect value for stec_residuals[40].sv_id.satId, " + "expected 180, is %d", + check_msg->stec_residuals[40].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[41].residual == 4988, + "incorrect value for stec_residuals[41].residual, expected 4988, is %d", + check_msg->stec_residuals[41].residual); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.constellation == 24, + "incorrect value for stec_residuals[41].sv_id.constellation, " + "expected 24, is %d", + check_msg->stec_residuals[41].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[41].sv_id.satId == 58, + "incorrect value for stec_residuals[41].sv_id.satId, " + "expected 58, is %d", + check_msg->stec_residuals[41].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[42].residual == 27408, + "incorrect value for stec_residuals[42].residual, expected " + "27408, is %d", + check_msg->stec_residuals[42].residual); + ck_assert_msg(check_msg->stec_residuals[42].sv_id.constellation == 188, + "incorrect value for stec_residuals[42].sv_id.constellation, " + "expected 188, is %d", + check_msg->stec_residuals[42].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[42].sv_id.satId == 181, + "incorrect value for stec_residuals[42].sv_id.satId, " + "expected 181, is %d", + check_msg->stec_residuals[42].sv_id.satId); + ck_assert_msg( + check_msg->stec_residuals[43].residual == 319, + "incorrect value for stec_residuals[43].residual, expected 319, is %d", + check_msg->stec_residuals[43].residual); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.constellation == 231, + "incorrect value for stec_residuals[43].sv_id.constellation, " + "expected 231, is %d", + check_msg->stec_residuals[43].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[43].sv_id.satId == 66, + "incorrect value for stec_residuals[43].sv_id.satId, " + "expected 66, is %d", + check_msg->stec_residuals[43].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[44].residual == 15987, + "incorrect value for stec_residuals[44].residual, expected " + "15987, is %d", + check_msg->stec_residuals[44].residual); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.constellation == 252, + "incorrect value for stec_residuals[44].sv_id.constellation, " + "expected 252, is %d", + check_msg->stec_residuals[44].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[44].sv_id.satId == 64, + "incorrect value for stec_residuals[44].sv_id.satId, " + "expected 64, is %d", + check_msg->stec_residuals[44].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[45].residual == 22266, + "incorrect value for stec_residuals[45].residual, expected " + "22266, is %d", + check_msg->stec_residuals[45].residual); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.constellation == 97, + "incorrect value for stec_residuals[45].sv_id.constellation, " + "expected 97, is %d", + check_msg->stec_residuals[45].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[45].sv_id.satId == 233, + "incorrect value for stec_residuals[45].sv_id.satId, " + "expected 233, is %d", + check_msg->stec_residuals[45].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[46].residual == -19919, + "incorrect value for stec_residuals[46].residual, expected " + "-19919, is %d", + check_msg->stec_residuals[46].residual); + ck_assert_msg(check_msg->stec_residuals[46].sv_id.constellation == 221, + "incorrect value for stec_residuals[46].sv_id.constellation, " + "expected 221, is %d", + check_msg->stec_residuals[46].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[46].sv_id.satId == 156, + "incorrect value for stec_residuals[46].sv_id.satId, " + "expected 156, is %d", + check_msg->stec_residuals[46].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[47].residual == 17350, + "incorrect value for stec_residuals[47].residual, expected " + "17350, is %d", + check_msg->stec_residuals[47].residual); + ck_assert_msg(check_msg->stec_residuals[47].sv_id.constellation == 73, + "incorrect value for stec_residuals[47].sv_id.constellation, " + "expected 73, is %d", + check_msg->stec_residuals[47].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[47].sv_id.satId == 32, + "incorrect value for stec_residuals[47].sv_id.satId, " + "expected 32, is %d", + check_msg->stec_residuals[47].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[48].residual == 14410, + "incorrect value for stec_residuals[48].residual, expected " + "14410, is %d", + check_msg->stec_residuals[48].residual); + ck_assert_msg(check_msg->stec_residuals[48].sv_id.constellation == 253, + "incorrect value for stec_residuals[48].sv_id.constellation, " + "expected 253, is %d", + check_msg->stec_residuals[48].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[48].sv_id.satId == 249, + "incorrect value for stec_residuals[48].sv_id.satId, " + "expected 249, is %d", + check_msg->stec_residuals[48].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[49].residual == 23671, + "incorrect value for stec_residuals[49].residual, expected " + "23671, is %d", + check_msg->stec_residuals[49].residual); + ck_assert_msg(check_msg->stec_residuals[49].sv_id.constellation == 165, + "incorrect value for stec_residuals[49].sv_id.constellation, " + "expected 165, is %d", + check_msg->stec_residuals[49].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[49].sv_id.satId == 38, + "incorrect value for stec_residuals[49].sv_id.satId, " + "expected 38, is %d", + check_msg->stec_residuals[49].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[50].residual == -31905, + "incorrect value for stec_residuals[50].residual, expected " + "-31905, is %d", + check_msg->stec_residuals[50].residual); + ck_assert_msg(check_msg->stec_residuals[50].sv_id.constellation == 44, + "incorrect value for stec_residuals[50].sv_id.constellation, " + "expected 44, is %d", + check_msg->stec_residuals[50].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[50].sv_id.satId == 99, + "incorrect value for stec_residuals[50].sv_id.satId, " + "expected 99, is %d", + check_msg->stec_residuals[50].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[51].residual == 14305, + "incorrect value for stec_residuals[51].residual, expected " + "14305, is %d", + check_msg->stec_residuals[51].residual); + ck_assert_msg(check_msg->stec_residuals[51].sv_id.constellation == 192, + "incorrect value for stec_residuals[51].sv_id.constellation, " + "expected 192, is %d", + check_msg->stec_residuals[51].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[51].sv_id.satId == 89, + "incorrect value for stec_residuals[51].sv_id.satId, " + "expected 89, is %d", + check_msg->stec_residuals[51].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[52].residual == -12968, + "incorrect value for stec_residuals[52].residual, expected " + "-12968, is %d", + check_msg->stec_residuals[52].residual); + ck_assert_msg(check_msg->stec_residuals[52].sv_id.constellation == 171, + "incorrect value for stec_residuals[52].sv_id.constellation, " + "expected 171, is %d", + check_msg->stec_residuals[52].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[52].sv_id.satId == 95, + "incorrect value for stec_residuals[52].sv_id.satId, " + "expected 95, is %d", + check_msg->stec_residuals[52].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[53].residual == 21479, + "incorrect value for stec_residuals[53].residual, expected " + "21479, is %d", + check_msg->stec_residuals[53].residual); + ck_assert_msg(check_msg->stec_residuals[53].sv_id.constellation == 116, + "incorrect value for stec_residuals[53].sv_id.constellation, " + "expected 116, is %d", + check_msg->stec_residuals[53].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[53].sv_id.satId == 21, + "incorrect value for stec_residuals[53].sv_id.satId, " + "expected 21, is %d", + check_msg->stec_residuals[53].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[54].residual == 28260, + "incorrect value for stec_residuals[54].residual, expected " + "28260, is %d", + check_msg->stec_residuals[54].residual); + ck_assert_msg(check_msg->stec_residuals[54].sv_id.constellation == 71, + "incorrect value for stec_residuals[54].sv_id.constellation, " + "expected 71, is %d", + check_msg->stec_residuals[54].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[54].sv_id.satId == 71, + "incorrect value for stec_residuals[54].sv_id.satId, " + "expected 71, is %d", + check_msg->stec_residuals[54].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[55].residual == -11112, + "incorrect value for stec_residuals[55].residual, expected " + "-11112, is %d", + check_msg->stec_residuals[55].residual); + ck_assert_msg(check_msg->stec_residuals[55].sv_id.constellation == 254, + "incorrect value for stec_residuals[55].sv_id.constellation, " + "expected 254, is %d", + check_msg->stec_residuals[55].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[55].sv_id.satId == 217, + "incorrect value for stec_residuals[55].sv_id.satId, " + "expected 217, is %d", + check_msg->stec_residuals[55].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[56].residual == -25304, + "incorrect value for stec_residuals[56].residual, expected " + "-25304, is %d", + check_msg->stec_residuals[56].residual); + ck_assert_msg(check_msg->stec_residuals[56].sv_id.constellation == 8, + "incorrect value for stec_residuals[56].sv_id.constellation, " + "expected 8, is %d", + check_msg->stec_residuals[56].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[56].sv_id.satId == 18, + "incorrect value for stec_residuals[56].sv_id.satId, " + "expected 18, is %d", + check_msg->stec_residuals[56].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[57].residual == -4024, + "incorrect value for stec_residuals[57].residual, expected " + "-4024, is %d", + check_msg->stec_residuals[57].residual); + ck_assert_msg(check_msg->stec_residuals[57].sv_id.constellation == 54, + "incorrect value for stec_residuals[57].sv_id.constellation, " + "expected 54, is %d", + check_msg->stec_residuals[57].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[57].sv_id.satId == 244, + "incorrect value for stec_residuals[57].sv_id.satId, " + "expected 244, is %d", + check_msg->stec_residuals[57].sv_id.satId); + ck_assert_msg(check_msg->stec_residuals[58].residual == -15505, + "incorrect value for stec_residuals[58].residual, expected " + "-15505, is %d", + check_msg->stec_residuals[58].residual); + ck_assert_msg(check_msg->stec_residuals[58].sv_id.constellation == 189, + "incorrect value for stec_residuals[58].sv_id.constellation, " + "expected 189, is %d", + check_msg->stec_residuals[58].sv_id.constellation); + ck_assert_msg(check_msg->stec_residuals[58].sv_id.satId == 231, + "incorrect value for stec_residuals[58].sv_id.satId, " + "expected 231, is %d", + check_msg->stec_residuals[58].sv_id.satId); + ck_assert_msg(check_msg->tropo_delay_correction.hydro == 16250, + "incorrect value for tropo_delay_correction.hydro, expected " + "16250, is %d", + check_msg->tropo_delay_correction.hydro); + ck_assert_msg( + check_msg->tropo_delay_correction.wet == 101, + "incorrect value for tropo_delay_correction.wet, expected 101, is %d", + check_msg->tropo_delay_correction.wet); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_" + "MsgSsrGriddedCorrectionNoStdDepA"); + tcase_add_test( + tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClock.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClock.c new file mode 100644 index 0000000000..65cf2145d9 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClock.c @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5dd, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5dd, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, + 203, 212, 236, 255, 152, 233, 207, 55, 94, 54, 58, 128, + 68, 27, 117, 176, 110, 251, 61, 244, 122, 50, 95, 52, + 144, 232, 24, 10, 37, 127, 163, 66, 177, 105, 156, 245, + 10, 249, 107, 218, 17, 186, 56, 72, 14, 22, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_orbit_clock_t *test_msg = (msg_ssr_orbit_clock_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->along = -1334502588; + test_msg->c0 = -174298703; + test_msg->c1 = -630458102; + test_msg->c2 = 1211677201; + test_msg->cross = -197264530; + test_msg->dot_along = 169404560; + test_msg->dot_cross = 1118011173; + test_msg->dot_radial = 878654074; + test_msg->iod = 936372632; + test_msg->iod_ssr = 255; + test_msg->radial = -2143668642; + test_msg->sid.code = 212; + test_msg->sid.sat = 203; + test_msg->time.tow = 3479621715; + test_msg->time.wn = 7588; + test_msg->update_interval = 236; + sbp_payload_send(&sbp_state, 0x5dd, 58677, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 58677, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 58677, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5dd, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_orbit_clock_t *check_msg = + (msg_ssr_orbit_clock_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->along == -1334502588, + "incorrect value for along, expected -1334502588, is %d", + check_msg->along); + ck_assert_msg(check_msg->c0 == -174298703, + "incorrect value for c0, expected -174298703, is %d", + check_msg->c0); + ck_assert_msg(check_msg->c1 == -630458102, + "incorrect value for c1, expected -630458102, is %d", + check_msg->c1); + ck_assert_msg(check_msg->c2 == 1211677201, + "incorrect value for c2, expected 1211677201, is %d", + check_msg->c2); + ck_assert_msg(check_msg->cross == -197264530, + "incorrect value for cross, expected -197264530, is %d", + check_msg->cross); + ck_assert_msg(check_msg->dot_along == 169404560, + "incorrect value for dot_along, expected 169404560, is %d", + check_msg->dot_along); + ck_assert_msg(check_msg->dot_cross == 1118011173, + "incorrect value for dot_cross, expected 1118011173, is %d", + check_msg->dot_cross); + ck_assert_msg(check_msg->dot_radial == 878654074, + "incorrect value for dot_radial, expected 878654074, is %d", + check_msg->dot_radial); + ck_assert_msg(check_msg->iod == 936372632, + "incorrect value for iod, expected 936372632, is %d", + check_msg->iod); + ck_assert_msg(check_msg->iod_ssr == 255, + "incorrect value for iod_ssr, expected 255, is %d", + check_msg->iod_ssr); + ck_assert_msg(check_msg->radial == -2143668642, + "incorrect value for radial, expected -2143668642, is %d", + check_msg->radial); + ck_assert_msg(check_msg->sid.code == 212, + "incorrect value for sid.code, expected 212, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 203, + "incorrect value for sid.sat, expected 203, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->time.tow == 3479621715, + "incorrect value for time.tow, expected 3479621715, is %d", + check_msg->time.tow); + ck_assert_msg(check_msg->time.wn == 7588, + "incorrect value for time.wn, expected 7588, is %d", + check_msg->time.wn); + ck_assert_msg(check_msg->update_interval == 236, + "incorrect value for update_interval, expected 236, is %d", + check_msg->update_interval); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrOrbitClock_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_ssr_MsgSsrOrbitClock"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c new file mode 100644 index 0000000000..1734e9e2a8 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.c @@ -0,0 +1,271 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5dc, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5dc, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, + 194, 211, 193, 175, 161, 143, 254, 56, 63, 232, 7, 216, 69, 1, + 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, 151, 18, 171, + 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_orbit_clock_dep_a_t *test_msg = + (msg_ssr_orbit_clock_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->along = 132661048; + test_msg->c0 = -970026069; + test_msg->c1 = -503975083; + test_msg->c2 = -759858197; + test_msg->cross = 1845577176; + test_msg->dot_along = 72905755; + test_msg->dot_cross = 311886653; + test_msg->dot_radial = -1111196507; + test_msg->iod = 193; + test_msg->iod_ssr = 211; + test_msg->radial = -24141393; + test_msg->sid.code = 30; + test_msg->sid.sat = 1; + test_msg->time.tow = 3172954849; + test_msg->time.wn = 7723; + test_msg->update_interval = 194; + sbp_payload_send(&sbp_state, 0x5dc, 42529, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 42529, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 42529, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5dc, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_orbit_clock_dep_a_t *check_msg = + (msg_ssr_orbit_clock_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->along == 132661048, + "incorrect value for along, expected 132661048, is %d", + check_msg->along); + ck_assert_msg(check_msg->c0 == -970026069, + "incorrect value for c0, expected -970026069, is %d", + check_msg->c0); + ck_assert_msg(check_msg->c1 == -503975083, + "incorrect value for c1, expected -503975083, is %d", + check_msg->c1); + ck_assert_msg(check_msg->c2 == -759858197, + "incorrect value for c2, expected -759858197, is %d", + check_msg->c2); + ck_assert_msg(check_msg->cross == 1845577176, + "incorrect value for cross, expected 1845577176, is %d", + check_msg->cross); + ck_assert_msg(check_msg->dot_along == 72905755, + "incorrect value for dot_along, expected 72905755, is %d", + check_msg->dot_along); + ck_assert_msg(check_msg->dot_cross == 311886653, + "incorrect value for dot_cross, expected 311886653, is %d", + check_msg->dot_cross); + ck_assert_msg(check_msg->dot_radial == -1111196507, + "incorrect value for dot_radial, expected -1111196507, is %d", + check_msg->dot_radial); + ck_assert_msg(check_msg->iod == 193, + "incorrect value for iod, expected 193, is %d", + check_msg->iod); + ck_assert_msg(check_msg->iod_ssr == 211, + "incorrect value for iod_ssr, expected 211, is %d", + check_msg->iod_ssr); + ck_assert_msg(check_msg->radial == -24141393, + "incorrect value for radial, expected -24141393, is %d", + check_msg->radial); + ck_assert_msg(check_msg->sid.code == 30, + "incorrect value for sid.code, expected 30, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 1, + "incorrect value for sid.sat, expected 1, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->time.tow == 3172954849, + "incorrect value for time.tow, expected 3172954849, is %d", + check_msg->time.tow); + ck_assert_msg(check_msg->time.wn == 7723, + "incorrect value for time.wn, expected 7723, is %d", + check_msg->time.wn); + ck_assert_msg(check_msg->update_interval == 194, + "incorrect value for update_interval, expected 194, is %d", + check_msg->update_interval); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrPhaseBiases.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrPhaseBiases.c new file mode 100644 index 0000000000..10fa2f126e --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrPhaseBiases.c @@ -0,0 +1,1101 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5e6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5e6, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, + 177, 230, 98, 209, 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, + 177, 207, 187, 33, 146, 58, 204, 164, 65, 114, 49, 248, 52, 8, + 161, 44, 252, 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, + 155, 129, 143, 184, 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, + 203, 87, 34, 188, 141, 104, 189, 102, 156, 252, 22, 251, 136, 49, + 188, 157, 222, 245, 49, 132, 16, 34, 142, 228, 85, 139, 221, 197, + 235, 98, 74, 107, 70, 36, 38, 239, 251, 112, 188, 124, 246, 141, + 164, 150, 104, 7, 213, 44, 21, 244, 192, 4, 143, 24, 42, 21, + 84, 136, 7, 42, 118, 45, 23, 174, 175, 129, 54, 169, 14, 213, + 2, 197, 98, 60, 13, 207, 105, 100, 129, 72, 136, 240, 140, 129, + 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, 242, 254, 215, + 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, 97, 36, + 207, 92, 224, 26, 116, 155, 211, 165, 47, 102, 38, 67, 199, 55, + 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, 62, 147, 173, 173, + 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, + 207, 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, + 75, 230, 26, 213, 181, 56, 64, 97, 88, 255, 6, 147, 16, 89, + 203, 27, 68, 243, 230, 55, 242, 167, 169, 219, 240, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_phase_biases_t *test_msg = + (msg_ssr_phase_biases_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[0].bias = -1311498533; + test_msg->biases[0].code = 29; + test_msg->biases[0].discontinuity_counter = 193; + test_msg->biases[0].integer_indicator = 250; + test_msg->biases[0].widelane_integer_indicator = 245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[1].bias = 1101319226; + test_msg->biases[1].code = 207; + test_msg->biases[1].discontinuity_counter = 146; + test_msg->biases[1].integer_indicator = 187; + test_msg->biases[1].widelane_integer_indicator = 33; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[2].bias = -64184056; + test_msg->biases[2].code = 114; + test_msg->biases[2].discontinuity_counter = 52; + test_msg->biases[2].integer_indicator = 49; + test_msg->biases[2].widelane_integer_indicator = 248; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[3].bias = -240298362; + test_msg->biases[3].code = 166; + test_msg->biases[3].discontinuity_counter = 124; + test_msg->biases[3].integer_indicator = 168; + test_msg->biases[3].widelane_integer_indicator = 232; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[4].bias = -1581740159; + test_msg->biases[4].code = 174; + test_msg->biases[4].discontinuity_counter = 155; + test_msg->biases[4].integer_indicator = 44; + test_msg->biases[4].widelane_integer_indicator = 142; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[5].bias = -1730297136; + test_msg->biases[5].code = 211; + test_msg->biases[5].discontinuity_counter = 189; + test_msg->biases[5].integer_indicator = 15; + test_msg->biases[5].widelane_integer_indicator = 36; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[6].bias = -1117221444; + test_msg->biases[6].code = 16; + test_msg->biases[6].discontinuity_counter = 34; + test_msg->biases[6].integer_indicator = 203; + test_msg->biases[6].widelane_integer_indicator = 87; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[7].bias = -1137604357; + test_msg->biases[7].code = 102; + test_msg->biases[7].discontinuity_counter = 22; + test_msg->biases[7].integer_indicator = 156; + test_msg->biases[7].widelane_integer_indicator = 252; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[8].bias = -1910370172; + test_msg->biases[8].code = 157; + test_msg->biases[8].discontinuity_counter = 49; + test_msg->biases[8].integer_indicator = 222; + test_msg->biases[8].widelane_integer_indicator = 245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[9].bias = 1247996869; + test_msg->biases[9].code = 228; + test_msg->biases[9].discontinuity_counter = 221; + test_msg->biases[9].integer_indicator = 85; + test_msg->biases[9].widelane_integer_indicator = 139; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[10].bias = -1133446161; + test_msg->biases[10].code = 107; + test_msg->biases[10].discontinuity_counter = 38; + test_msg->biases[10].integer_indicator = 70; + test_msg->biases[10].widelane_integer_indicator = 36; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[11].bias = -720934762; + test_msg->biases[11].code = 124; + test_msg->biases[11].discontinuity_counter = 164; + test_msg->biases[11].integer_indicator = 246; + test_msg->biases[11].widelane_integer_indicator = 141; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[12].bias = 706252548; + test_msg->biases[12].code = 44; + test_msg->biases[12].discontinuity_counter = 192; + test_msg->biases[12].integer_indicator = 21; + test_msg->biases[12].widelane_integer_indicator = 244; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[13].bias = 388855338; + test_msg->biases[13].code = 21; + test_msg->biases[13].discontinuity_counter = 7; + test_msg->biases[13].integer_indicator = 84; + test_msg->biases[13].widelane_integer_indicator = 136; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[14].bias = 47517353; + test_msg->biases[14].code = 174; + test_msg->biases[14].discontinuity_counter = 54; + test_msg->biases[14].integer_indicator = 175; + test_msg->biases[14].widelane_integer_indicator = 129; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[15].bias = -2124125745; + test_msg->biases[15].code = 197; + test_msg->biases[15].discontinuity_counter = 13; + test_msg->biases[15].integer_indicator = 98; + test_msg->biases[15].widelane_integer_indicator = 60; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[16].bias = -1401812607; + test_msg->biases[16].code = 72; + test_msg->biases[16].discontinuity_counter = 140; + test_msg->biases[16].integer_indicator = 136; + test_msg->biases[16].widelane_integer_indicator = 240; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[17].bias = 60257151; + test_msg->biases[17].code = 151; + test_msg->biases[17].discontinuity_counter = 210; + test_msg->biases[17].integer_indicator = 150; + test_msg->biases[17].widelane_integer_indicator = 17; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[18].bias = 41820677; + test_msg->biases[18].code = 242; + test_msg->biases[18].discontinuity_counter = 14; + test_msg->biases[18].integer_indicator = 254; + test_msg->biases[18].widelane_integer_indicator = 215; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[19].bias = 1640616471; + test_msg->biases[19].code = 215; + test_msg->biases[19].discontinuity_counter = 176; + test_msg->biases[19].integer_indicator = 65; + test_msg->biases[19].widelane_integer_indicator = 38; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[20].bias = -744786918; + test_msg->biases[20].code = 36; + test_msg->biases[20].discontinuity_counter = 224; + test_msg->biases[20].integer_indicator = 207; + test_msg->biases[20].widelane_integer_indicator = 92; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[21].bias = 1966589763; + test_msg->biases[21].code = 165; + test_msg->biases[21].discontinuity_counter = 38; + test_msg->biases[21].integer_indicator = 47; + test_msg->biases[21].widelane_integer_indicator = 102; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[22].bias = 364366310; + test_msg->biases[22].code = 36; + test_msg->biases[22].discontinuity_counter = 1; + test_msg->biases[22].integer_indicator = 169; + test_msg->biases[22].widelane_integer_indicator = 33; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[23].bias = -1839031379; + test_msg->biases[23].code = 42; + test_msg->biases[23].discontinuity_counter = 173; + test_msg->biases[23].integer_indicator = 62; + test_msg->biases[23].widelane_integer_indicator = 147; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[24].bias = 31817639; + test_msg->biases[24].code = 231; + test_msg->biases[24].discontinuity_counter = 82; + test_msg->biases[24].integer_indicator = 167; + test_msg->biases[24].widelane_integer_indicator = 138; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[25].bias = -1619830156; + test_msg->biases[25].code = 2; + test_msg->biases[25].discontinuity_counter = 207; + test_msg->biases[25].integer_indicator = 127; + test_msg->biases[25].widelane_integer_indicator = 237; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[26].bias = -83375622; + test_msg->biases[26].code = 3; + test_msg->biases[26].discontinuity_counter = 145; + test_msg->biases[26].integer_indicator = 42; + test_msg->biases[26].widelane_integer_indicator = 66; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[27].bias = 1077458389; + test_msg->biases[27].code = 2; + test_msg->biases[27].discontinuity_counter = 26; + test_msg->biases[27].integer_indicator = 75; + test_msg->biases[27].widelane_integer_indicator = 230; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[28].bias = -883355501; + test_msg->biases[28].code = 97; + test_msg->biases[28].discontinuity_counter = 6; + test_msg->biases[28].integer_indicator = 88; + test_msg->biases[28].widelane_integer_indicator = 255; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->biases[0]); + } + test_msg->biases[29].bias = -1448611273; + test_msg->biases[29].code = 27; + test_msg->biases[29].discontinuity_counter = 230; + test_msg->biases[29].integer_indicator = 68; + test_msg->biases[29].widelane_integer_indicator = 243; + test_msg->dispersive_bias = 98; + test_msg->iod_ssr = 230; + test_msg->mw_consistency = 209; + test_msg->sid.code = 82; + test_msg->sid.sat = 169; + test_msg->time.tow = 210803409; + test_msg->time.wn = 42197; + test_msg->update_interval = 177; + test_msg->yaw = 5881; + test_msg->yaw_rate = 17; + sbp_payload_send(&sbp_state, 0x5e6, 52955, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 52955, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 52955, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5e6, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_phase_biases_t *check_msg = + (msg_ssr_phase_biases_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + check_msg->biases[0].bias == -1311498533, + "incorrect value for biases[0].bias, expected -1311498533, is %d", + check_msg->biases[0].bias); + ck_assert_msg(check_msg->biases[0].code == 29, + "incorrect value for biases[0].code, expected 29, is %d", + check_msg->biases[0].code); + ck_assert_msg(check_msg->biases[0].discontinuity_counter == 193, + "incorrect value for biases[0].discontinuity_counter, " + "expected 193, is %d", + check_msg->biases[0].discontinuity_counter); + ck_assert_msg( + check_msg->biases[0].integer_indicator == 250, + "incorrect value for biases[0].integer_indicator, expected 250, is %d", + check_msg->biases[0].integer_indicator); + ck_assert_msg(check_msg->biases[0].widelane_integer_indicator == 245, + "incorrect value for biases[0].widelane_integer_indicator, " + "expected 245, is %d", + check_msg->biases[0].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[1].bias == 1101319226, + "incorrect value for biases[1].bias, expected 1101319226, is %d", + check_msg->biases[1].bias); + ck_assert_msg(check_msg->biases[1].code == 207, + "incorrect value for biases[1].code, expected 207, is %d", + check_msg->biases[1].code); + ck_assert_msg(check_msg->biases[1].discontinuity_counter == 146, + "incorrect value for biases[1].discontinuity_counter, " + "expected 146, is %d", + check_msg->biases[1].discontinuity_counter); + ck_assert_msg( + check_msg->biases[1].integer_indicator == 187, + "incorrect value for biases[1].integer_indicator, expected 187, is %d", + check_msg->biases[1].integer_indicator); + ck_assert_msg(check_msg->biases[1].widelane_integer_indicator == 33, + "incorrect value for biases[1].widelane_integer_indicator, " + "expected 33, is %d", + check_msg->biases[1].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[2].bias == -64184056, + "incorrect value for biases[2].bias, expected -64184056, is %d", + check_msg->biases[2].bias); + ck_assert_msg(check_msg->biases[2].code == 114, + "incorrect value for biases[2].code, expected 114, is %d", + check_msg->biases[2].code); + ck_assert_msg(check_msg->biases[2].discontinuity_counter == 52, + "incorrect value for biases[2].discontinuity_counter, " + "expected 52, is %d", + check_msg->biases[2].discontinuity_counter); + ck_assert_msg( + check_msg->biases[2].integer_indicator == 49, + "incorrect value for biases[2].integer_indicator, expected 49, is %d", + check_msg->biases[2].integer_indicator); + ck_assert_msg(check_msg->biases[2].widelane_integer_indicator == 248, + "incorrect value for biases[2].widelane_integer_indicator, " + "expected 248, is %d", + check_msg->biases[2].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[3].bias == -240298362, + "incorrect value for biases[3].bias, expected -240298362, is %d", + check_msg->biases[3].bias); + ck_assert_msg(check_msg->biases[3].code == 166, + "incorrect value for biases[3].code, expected 166, is %d", + check_msg->biases[3].code); + ck_assert_msg(check_msg->biases[3].discontinuity_counter == 124, + "incorrect value for biases[3].discontinuity_counter, " + "expected 124, is %d", + check_msg->biases[3].discontinuity_counter); + ck_assert_msg( + check_msg->biases[3].integer_indicator == 168, + "incorrect value for biases[3].integer_indicator, expected 168, is %d", + check_msg->biases[3].integer_indicator); + ck_assert_msg(check_msg->biases[3].widelane_integer_indicator == 232, + "incorrect value for biases[3].widelane_integer_indicator, " + "expected 232, is %d", + check_msg->biases[3].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[4].bias == -1581740159, + "incorrect value for biases[4].bias, expected -1581740159, is %d", + check_msg->biases[4].bias); + ck_assert_msg(check_msg->biases[4].code == 174, + "incorrect value for biases[4].code, expected 174, is %d", + check_msg->biases[4].code); + ck_assert_msg(check_msg->biases[4].discontinuity_counter == 155, + "incorrect value for biases[4].discontinuity_counter, " + "expected 155, is %d", + check_msg->biases[4].discontinuity_counter); + ck_assert_msg( + check_msg->biases[4].integer_indicator == 44, + "incorrect value for biases[4].integer_indicator, expected 44, is %d", + check_msg->biases[4].integer_indicator); + ck_assert_msg(check_msg->biases[4].widelane_integer_indicator == 142, + "incorrect value for biases[4].widelane_integer_indicator, " + "expected 142, is %d", + check_msg->biases[4].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[5].bias == -1730297136, + "incorrect value for biases[5].bias, expected -1730297136, is %d", + check_msg->biases[5].bias); + ck_assert_msg(check_msg->biases[5].code == 211, + "incorrect value for biases[5].code, expected 211, is %d", + check_msg->biases[5].code); + ck_assert_msg(check_msg->biases[5].discontinuity_counter == 189, + "incorrect value for biases[5].discontinuity_counter, " + "expected 189, is %d", + check_msg->biases[5].discontinuity_counter); + ck_assert_msg( + check_msg->biases[5].integer_indicator == 15, + "incorrect value for biases[5].integer_indicator, expected 15, is %d", + check_msg->biases[5].integer_indicator); + ck_assert_msg(check_msg->biases[5].widelane_integer_indicator == 36, + "incorrect value for biases[5].widelane_integer_indicator, " + "expected 36, is %d", + check_msg->biases[5].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[6].bias == -1117221444, + "incorrect value for biases[6].bias, expected -1117221444, is %d", + check_msg->biases[6].bias); + ck_assert_msg(check_msg->biases[6].code == 16, + "incorrect value for biases[6].code, expected 16, is %d", + check_msg->biases[6].code); + ck_assert_msg(check_msg->biases[6].discontinuity_counter == 34, + "incorrect value for biases[6].discontinuity_counter, " + "expected 34, is %d", + check_msg->biases[6].discontinuity_counter); + ck_assert_msg( + check_msg->biases[6].integer_indicator == 203, + "incorrect value for biases[6].integer_indicator, expected 203, is %d", + check_msg->biases[6].integer_indicator); + ck_assert_msg(check_msg->biases[6].widelane_integer_indicator == 87, + "incorrect value for biases[6].widelane_integer_indicator, " + "expected 87, is %d", + check_msg->biases[6].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[7].bias == -1137604357, + "incorrect value for biases[7].bias, expected -1137604357, is %d", + check_msg->biases[7].bias); + ck_assert_msg(check_msg->biases[7].code == 102, + "incorrect value for biases[7].code, expected 102, is %d", + check_msg->biases[7].code); + ck_assert_msg(check_msg->biases[7].discontinuity_counter == 22, + "incorrect value for biases[7].discontinuity_counter, " + "expected 22, is %d", + check_msg->biases[7].discontinuity_counter); + ck_assert_msg( + check_msg->biases[7].integer_indicator == 156, + "incorrect value for biases[7].integer_indicator, expected 156, is %d", + check_msg->biases[7].integer_indicator); + ck_assert_msg(check_msg->biases[7].widelane_integer_indicator == 252, + "incorrect value for biases[7].widelane_integer_indicator, " + "expected 252, is %d", + check_msg->biases[7].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[8].bias == -1910370172, + "incorrect value for biases[8].bias, expected -1910370172, is %d", + check_msg->biases[8].bias); + ck_assert_msg(check_msg->biases[8].code == 157, + "incorrect value for biases[8].code, expected 157, is %d", + check_msg->biases[8].code); + ck_assert_msg(check_msg->biases[8].discontinuity_counter == 49, + "incorrect value for biases[8].discontinuity_counter, " + "expected 49, is %d", + check_msg->biases[8].discontinuity_counter); + ck_assert_msg( + check_msg->biases[8].integer_indicator == 222, + "incorrect value for biases[8].integer_indicator, expected 222, is %d", + check_msg->biases[8].integer_indicator); + ck_assert_msg(check_msg->biases[8].widelane_integer_indicator == 245, + "incorrect value for biases[8].widelane_integer_indicator, " + "expected 245, is %d", + check_msg->biases[8].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[9].bias == 1247996869, + "incorrect value for biases[9].bias, expected 1247996869, is %d", + check_msg->biases[9].bias); + ck_assert_msg(check_msg->biases[9].code == 228, + "incorrect value for biases[9].code, expected 228, is %d", + check_msg->biases[9].code); + ck_assert_msg(check_msg->biases[9].discontinuity_counter == 221, + "incorrect value for biases[9].discontinuity_counter, " + "expected 221, is %d", + check_msg->biases[9].discontinuity_counter); + ck_assert_msg( + check_msg->biases[9].integer_indicator == 85, + "incorrect value for biases[9].integer_indicator, expected 85, is %d", + check_msg->biases[9].integer_indicator); + ck_assert_msg(check_msg->biases[9].widelane_integer_indicator == 139, + "incorrect value for biases[9].widelane_integer_indicator, " + "expected 139, is %d", + check_msg->biases[9].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[10].bias == -1133446161, + "incorrect value for biases[10].bias, expected -1133446161, is %d", + check_msg->biases[10].bias); + ck_assert_msg(check_msg->biases[10].code == 107, + "incorrect value for biases[10].code, expected 107, is %d", + check_msg->biases[10].code); + ck_assert_msg(check_msg->biases[10].discontinuity_counter == 38, + "incorrect value for biases[10].discontinuity_counter, " + "expected 38, is %d", + check_msg->biases[10].discontinuity_counter); + ck_assert_msg( + check_msg->biases[10].integer_indicator == 70, + "incorrect value for biases[10].integer_indicator, expected 70, is %d", + check_msg->biases[10].integer_indicator); + ck_assert_msg(check_msg->biases[10].widelane_integer_indicator == 36, + "incorrect value for biases[10].widelane_integer_indicator, " + "expected 36, is %d", + check_msg->biases[10].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[11].bias == -720934762, + "incorrect value for biases[11].bias, expected -720934762, is %d", + check_msg->biases[11].bias); + ck_assert_msg(check_msg->biases[11].code == 124, + "incorrect value for biases[11].code, expected 124, is %d", + check_msg->biases[11].code); + ck_assert_msg(check_msg->biases[11].discontinuity_counter == 164, + "incorrect value for biases[11].discontinuity_counter, " + "expected 164, is %d", + check_msg->biases[11].discontinuity_counter); + ck_assert_msg( + check_msg->biases[11].integer_indicator == 246, + "incorrect value for biases[11].integer_indicator, expected 246, is %d", + check_msg->biases[11].integer_indicator); + ck_assert_msg(check_msg->biases[11].widelane_integer_indicator == 141, + "incorrect value for biases[11].widelane_integer_indicator, " + "expected 141, is %d", + check_msg->biases[11].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[12].bias == 706252548, + "incorrect value for biases[12].bias, expected 706252548, is %d", + check_msg->biases[12].bias); + ck_assert_msg(check_msg->biases[12].code == 44, + "incorrect value for biases[12].code, expected 44, is %d", + check_msg->biases[12].code); + ck_assert_msg(check_msg->biases[12].discontinuity_counter == 192, + "incorrect value for biases[12].discontinuity_counter, " + "expected 192, is %d", + check_msg->biases[12].discontinuity_counter); + ck_assert_msg( + check_msg->biases[12].integer_indicator == 21, + "incorrect value for biases[12].integer_indicator, expected 21, is %d", + check_msg->biases[12].integer_indicator); + ck_assert_msg(check_msg->biases[12].widelane_integer_indicator == 244, + "incorrect value for biases[12].widelane_integer_indicator, " + "expected 244, is %d", + check_msg->biases[12].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[13].bias == 388855338, + "incorrect value for biases[13].bias, expected 388855338, is %d", + check_msg->biases[13].bias); + ck_assert_msg(check_msg->biases[13].code == 21, + "incorrect value for biases[13].code, expected 21, is %d", + check_msg->biases[13].code); + ck_assert_msg(check_msg->biases[13].discontinuity_counter == 7, + "incorrect value for biases[13].discontinuity_counter, " + "expected 7, is %d", + check_msg->biases[13].discontinuity_counter); + ck_assert_msg( + check_msg->biases[13].integer_indicator == 84, + "incorrect value for biases[13].integer_indicator, expected 84, is %d", + check_msg->biases[13].integer_indicator); + ck_assert_msg(check_msg->biases[13].widelane_integer_indicator == 136, + "incorrect value for biases[13].widelane_integer_indicator, " + "expected 136, is %d", + check_msg->biases[13].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[14].bias == 47517353, + "incorrect value for biases[14].bias, expected 47517353, is %d", + check_msg->biases[14].bias); + ck_assert_msg(check_msg->biases[14].code == 174, + "incorrect value for biases[14].code, expected 174, is %d", + check_msg->biases[14].code); + ck_assert_msg(check_msg->biases[14].discontinuity_counter == 54, + "incorrect value for biases[14].discontinuity_counter, " + "expected 54, is %d", + check_msg->biases[14].discontinuity_counter); + ck_assert_msg( + check_msg->biases[14].integer_indicator == 175, + "incorrect value for biases[14].integer_indicator, expected 175, is %d", + check_msg->biases[14].integer_indicator); + ck_assert_msg(check_msg->biases[14].widelane_integer_indicator == 129, + "incorrect value for biases[14].widelane_integer_indicator, " + "expected 129, is %d", + check_msg->biases[14].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[15].bias == -2124125745, + "incorrect value for biases[15].bias, expected -2124125745, is %d", + check_msg->biases[15].bias); + ck_assert_msg(check_msg->biases[15].code == 197, + "incorrect value for biases[15].code, expected 197, is %d", + check_msg->biases[15].code); + ck_assert_msg(check_msg->biases[15].discontinuity_counter == 13, + "incorrect value for biases[15].discontinuity_counter, " + "expected 13, is %d", + check_msg->biases[15].discontinuity_counter); + ck_assert_msg( + check_msg->biases[15].integer_indicator == 98, + "incorrect value for biases[15].integer_indicator, expected 98, is %d", + check_msg->biases[15].integer_indicator); + ck_assert_msg(check_msg->biases[15].widelane_integer_indicator == 60, + "incorrect value for biases[15].widelane_integer_indicator, " + "expected 60, is %d", + check_msg->biases[15].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[16].bias == -1401812607, + "incorrect value for biases[16].bias, expected -1401812607, is %d", + check_msg->biases[16].bias); + ck_assert_msg(check_msg->biases[16].code == 72, + "incorrect value for biases[16].code, expected 72, is %d", + check_msg->biases[16].code); + ck_assert_msg(check_msg->biases[16].discontinuity_counter == 140, + "incorrect value for biases[16].discontinuity_counter, " + "expected 140, is %d", + check_msg->biases[16].discontinuity_counter); + ck_assert_msg( + check_msg->biases[16].integer_indicator == 136, + "incorrect value for biases[16].integer_indicator, expected 136, is %d", + check_msg->biases[16].integer_indicator); + ck_assert_msg(check_msg->biases[16].widelane_integer_indicator == 240, + "incorrect value for biases[16].widelane_integer_indicator, " + "expected 240, is %d", + check_msg->biases[16].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[17].bias == 60257151, + "incorrect value for biases[17].bias, expected 60257151, is %d", + check_msg->biases[17].bias); + ck_assert_msg(check_msg->biases[17].code == 151, + "incorrect value for biases[17].code, expected 151, is %d", + check_msg->biases[17].code); + ck_assert_msg(check_msg->biases[17].discontinuity_counter == 210, + "incorrect value for biases[17].discontinuity_counter, " + "expected 210, is %d", + check_msg->biases[17].discontinuity_counter); + ck_assert_msg( + check_msg->biases[17].integer_indicator == 150, + "incorrect value for biases[17].integer_indicator, expected 150, is %d", + check_msg->biases[17].integer_indicator); + ck_assert_msg(check_msg->biases[17].widelane_integer_indicator == 17, + "incorrect value for biases[17].widelane_integer_indicator, " + "expected 17, is %d", + check_msg->biases[17].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[18].bias == 41820677, + "incorrect value for biases[18].bias, expected 41820677, is %d", + check_msg->biases[18].bias); + ck_assert_msg(check_msg->biases[18].code == 242, + "incorrect value for biases[18].code, expected 242, is %d", + check_msg->biases[18].code); + ck_assert_msg(check_msg->biases[18].discontinuity_counter == 14, + "incorrect value for biases[18].discontinuity_counter, " + "expected 14, is %d", + check_msg->biases[18].discontinuity_counter); + ck_assert_msg( + check_msg->biases[18].integer_indicator == 254, + "incorrect value for biases[18].integer_indicator, expected 254, is %d", + check_msg->biases[18].integer_indicator); + ck_assert_msg(check_msg->biases[18].widelane_integer_indicator == 215, + "incorrect value for biases[18].widelane_integer_indicator, " + "expected 215, is %d", + check_msg->biases[18].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[19].bias == 1640616471, + "incorrect value for biases[19].bias, expected 1640616471, is %d", + check_msg->biases[19].bias); + ck_assert_msg(check_msg->biases[19].code == 215, + "incorrect value for biases[19].code, expected 215, is %d", + check_msg->biases[19].code); + ck_assert_msg(check_msg->biases[19].discontinuity_counter == 176, + "incorrect value for biases[19].discontinuity_counter, " + "expected 176, is %d", + check_msg->biases[19].discontinuity_counter); + ck_assert_msg( + check_msg->biases[19].integer_indicator == 65, + "incorrect value for biases[19].integer_indicator, expected 65, is %d", + check_msg->biases[19].integer_indicator); + ck_assert_msg(check_msg->biases[19].widelane_integer_indicator == 38, + "incorrect value for biases[19].widelane_integer_indicator, " + "expected 38, is %d", + check_msg->biases[19].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[20].bias == -744786918, + "incorrect value for biases[20].bias, expected -744786918, is %d", + check_msg->biases[20].bias); + ck_assert_msg(check_msg->biases[20].code == 36, + "incorrect value for biases[20].code, expected 36, is %d", + check_msg->biases[20].code); + ck_assert_msg(check_msg->biases[20].discontinuity_counter == 224, + "incorrect value for biases[20].discontinuity_counter, " + "expected 224, is %d", + check_msg->biases[20].discontinuity_counter); + ck_assert_msg( + check_msg->biases[20].integer_indicator == 207, + "incorrect value for biases[20].integer_indicator, expected 207, is %d", + check_msg->biases[20].integer_indicator); + ck_assert_msg(check_msg->biases[20].widelane_integer_indicator == 92, + "incorrect value for biases[20].widelane_integer_indicator, " + "expected 92, is %d", + check_msg->biases[20].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[21].bias == 1966589763, + "incorrect value for biases[21].bias, expected 1966589763, is %d", + check_msg->biases[21].bias); + ck_assert_msg(check_msg->biases[21].code == 165, + "incorrect value for biases[21].code, expected 165, is %d", + check_msg->biases[21].code); + ck_assert_msg(check_msg->biases[21].discontinuity_counter == 38, + "incorrect value for biases[21].discontinuity_counter, " + "expected 38, is %d", + check_msg->biases[21].discontinuity_counter); + ck_assert_msg( + check_msg->biases[21].integer_indicator == 47, + "incorrect value for biases[21].integer_indicator, expected 47, is %d", + check_msg->biases[21].integer_indicator); + ck_assert_msg(check_msg->biases[21].widelane_integer_indicator == 102, + "incorrect value for biases[21].widelane_integer_indicator, " + "expected 102, is %d", + check_msg->biases[21].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[22].bias == 364366310, + "incorrect value for biases[22].bias, expected 364366310, is %d", + check_msg->biases[22].bias); + ck_assert_msg(check_msg->biases[22].code == 36, + "incorrect value for biases[22].code, expected 36, is %d", + check_msg->biases[22].code); + ck_assert_msg(check_msg->biases[22].discontinuity_counter == 1, + "incorrect value for biases[22].discontinuity_counter, " + "expected 1, is %d", + check_msg->biases[22].discontinuity_counter); + ck_assert_msg( + check_msg->biases[22].integer_indicator == 169, + "incorrect value for biases[22].integer_indicator, expected 169, is %d", + check_msg->biases[22].integer_indicator); + ck_assert_msg(check_msg->biases[22].widelane_integer_indicator == 33, + "incorrect value for biases[22].widelane_integer_indicator, " + "expected 33, is %d", + check_msg->biases[22].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[23].bias == -1839031379, + "incorrect value for biases[23].bias, expected -1839031379, is %d", + check_msg->biases[23].bias); + ck_assert_msg(check_msg->biases[23].code == 42, + "incorrect value for biases[23].code, expected 42, is %d", + check_msg->biases[23].code); + ck_assert_msg(check_msg->biases[23].discontinuity_counter == 173, + "incorrect value for biases[23].discontinuity_counter, " + "expected 173, is %d", + check_msg->biases[23].discontinuity_counter); + ck_assert_msg( + check_msg->biases[23].integer_indicator == 62, + "incorrect value for biases[23].integer_indicator, expected 62, is %d", + check_msg->biases[23].integer_indicator); + ck_assert_msg(check_msg->biases[23].widelane_integer_indicator == 147, + "incorrect value for biases[23].widelane_integer_indicator, " + "expected 147, is %d", + check_msg->biases[23].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[24].bias == 31817639, + "incorrect value for biases[24].bias, expected 31817639, is %d", + check_msg->biases[24].bias); + ck_assert_msg(check_msg->biases[24].code == 231, + "incorrect value for biases[24].code, expected 231, is %d", + check_msg->biases[24].code); + ck_assert_msg(check_msg->biases[24].discontinuity_counter == 82, + "incorrect value for biases[24].discontinuity_counter, " + "expected 82, is %d", + check_msg->biases[24].discontinuity_counter); + ck_assert_msg( + check_msg->biases[24].integer_indicator == 167, + "incorrect value for biases[24].integer_indicator, expected 167, is %d", + check_msg->biases[24].integer_indicator); + ck_assert_msg(check_msg->biases[24].widelane_integer_indicator == 138, + "incorrect value for biases[24].widelane_integer_indicator, " + "expected 138, is %d", + check_msg->biases[24].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[25].bias == -1619830156, + "incorrect value for biases[25].bias, expected -1619830156, is %d", + check_msg->biases[25].bias); + ck_assert_msg(check_msg->biases[25].code == 2, + "incorrect value for biases[25].code, expected 2, is %d", + check_msg->biases[25].code); + ck_assert_msg(check_msg->biases[25].discontinuity_counter == 207, + "incorrect value for biases[25].discontinuity_counter, " + "expected 207, is %d", + check_msg->biases[25].discontinuity_counter); + ck_assert_msg( + check_msg->biases[25].integer_indicator == 127, + "incorrect value for biases[25].integer_indicator, expected 127, is %d", + check_msg->biases[25].integer_indicator); + ck_assert_msg(check_msg->biases[25].widelane_integer_indicator == 237, + "incorrect value for biases[25].widelane_integer_indicator, " + "expected 237, is %d", + check_msg->biases[25].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[26].bias == -83375622, + "incorrect value for biases[26].bias, expected -83375622, is %d", + check_msg->biases[26].bias); + ck_assert_msg(check_msg->biases[26].code == 3, + "incorrect value for biases[26].code, expected 3, is %d", + check_msg->biases[26].code); + ck_assert_msg(check_msg->biases[26].discontinuity_counter == 145, + "incorrect value for biases[26].discontinuity_counter, " + "expected 145, is %d", + check_msg->biases[26].discontinuity_counter); + ck_assert_msg( + check_msg->biases[26].integer_indicator == 42, + "incorrect value for biases[26].integer_indicator, expected 42, is %d", + check_msg->biases[26].integer_indicator); + ck_assert_msg(check_msg->biases[26].widelane_integer_indicator == 66, + "incorrect value for biases[26].widelane_integer_indicator, " + "expected 66, is %d", + check_msg->biases[26].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[27].bias == 1077458389, + "incorrect value for biases[27].bias, expected 1077458389, is %d", + check_msg->biases[27].bias); + ck_assert_msg(check_msg->biases[27].code == 2, + "incorrect value for biases[27].code, expected 2, is %d", + check_msg->biases[27].code); + ck_assert_msg(check_msg->biases[27].discontinuity_counter == 26, + "incorrect value for biases[27].discontinuity_counter, " + "expected 26, is %d", + check_msg->biases[27].discontinuity_counter); + ck_assert_msg( + check_msg->biases[27].integer_indicator == 75, + "incorrect value for biases[27].integer_indicator, expected 75, is %d", + check_msg->biases[27].integer_indicator); + ck_assert_msg(check_msg->biases[27].widelane_integer_indicator == 230, + "incorrect value for biases[27].widelane_integer_indicator, " + "expected 230, is %d", + check_msg->biases[27].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[28].bias == -883355501, + "incorrect value for biases[28].bias, expected -883355501, is %d", + check_msg->biases[28].bias); + ck_assert_msg(check_msg->biases[28].code == 97, + "incorrect value for biases[28].code, expected 97, is %d", + check_msg->biases[28].code); + ck_assert_msg(check_msg->biases[28].discontinuity_counter == 6, + "incorrect value for biases[28].discontinuity_counter, " + "expected 6, is %d", + check_msg->biases[28].discontinuity_counter); + ck_assert_msg( + check_msg->biases[28].integer_indicator == 88, + "incorrect value for biases[28].integer_indicator, expected 88, is %d", + check_msg->biases[28].integer_indicator); + ck_assert_msg(check_msg->biases[28].widelane_integer_indicator == 255, + "incorrect value for biases[28].widelane_integer_indicator, " + "expected 255, is %d", + check_msg->biases[28].widelane_integer_indicator); + ck_assert_msg( + check_msg->biases[29].bias == -1448611273, + "incorrect value for biases[29].bias, expected -1448611273, is %d", + check_msg->biases[29].bias); + ck_assert_msg(check_msg->biases[29].code == 27, + "incorrect value for biases[29].code, expected 27, is %d", + check_msg->biases[29].code); + ck_assert_msg(check_msg->biases[29].discontinuity_counter == 230, + "incorrect value for biases[29].discontinuity_counter, " + "expected 230, is %d", + check_msg->biases[29].discontinuity_counter); + ck_assert_msg( + check_msg->biases[29].integer_indicator == 68, + "incorrect value for biases[29].integer_indicator, expected 68, is %d", + check_msg->biases[29].integer_indicator); + ck_assert_msg(check_msg->biases[29].widelane_integer_indicator == 243, + "incorrect value for biases[29].widelane_integer_indicator, " + "expected 243, is %d", + check_msg->biases[29].widelane_integer_indicator); + ck_assert_msg(check_msg->dispersive_bias == 98, + "incorrect value for dispersive_bias, expected 98, is %d", + check_msg->dispersive_bias); + ck_assert_msg(check_msg->iod_ssr == 230, + "incorrect value for iod_ssr, expected 230, is %d", + check_msg->iod_ssr); + ck_assert_msg(check_msg->mw_consistency == 209, + "incorrect value for mw_consistency, expected 209, is %d", + check_msg->mw_consistency); + ck_assert_msg(check_msg->sid.code == 82, + "incorrect value for sid.code, expected 82, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 169, + "incorrect value for sid.sat, expected 169, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->time.tow == 210803409, + "incorrect value for time.tow, expected 210803409, is %d", + check_msg->time.tow); + ck_assert_msg(check_msg->time.wn == 42197, + "incorrect value for time.wn, expected 42197, is %d", + check_msg->time.wn); + ck_assert_msg(check_msg->update_interval == 177, + "incorrect value for update_interval, expected 177, is %d", + check_msg->update_interval); + ck_assert_msg(check_msg->yaw == 5881, + "incorrect value for yaw, expected 5881, is %d", + check_msg->yaw); + ck_assert_msg(check_msg->yaw_rate == 17, + "incorrect value for yaw_rate, expected 17, is %d", + check_msg->yaw_rate); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c new file mode 100644 index 0000000000..7ddaa83e0d --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.c @@ -0,0 +1,1704 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x604, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x604, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, + 214, 212, 4, 8, 33, 31, 80, 21, 4, 105, 225, 39, 139, 124, + 149, 48, 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, 49, 135, + 97, 39, 90, 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, + 2, 102, 74, 149, 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, + 83, 188, 181, 194, 27, 84, 226, 142, 123, 77, 217, 248, 67, 215, + 129, 114, 138, 25, 240, 10, 56, 76, 61, 161, 216, 22, 181, 174, + 33, 13, 252, 236, 230, 196, 128, 215, 239, 234, 179, 220, 44, 212, + 57, 44, 173, 49, 36, 137, 248, 235, 97, 112, 157, 139, 26, 115, + 192, 31, 85, 127, 228, 81, 252, 219, 249, 110, 147, 8, 161, 215, + 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, 74, 23, 4, 239, + 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, 99, 45, 83, + 159, 11, 250, 135, 170, 42, 217, 199, 233, 42, 170, 78, 206, 41, + 43, 81, 247, 99, 198, 144, 2, 132, 2, 224, 220, 148, 58, 85, + 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, 37, + 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, + 119, 101, 252, 223, 144, 153, 50, 13, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_satellite_apc_dep_t *test_msg = + (msg_ssr_satellite_apc_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pco[0]); + } + test_msg->apc[0].pco[0] = -21547; + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pco[0]); + } + test_msg->apc[0].pco[1] = -10498; + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pco[0]); + } + test_msg->apc[0].pco[2] = 1236; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[0] = 8; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[1] = 33; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[2] = 31; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[3] = 80; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[4] = 21; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[5] = 4; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[6] = 105; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[7] = -31; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[8] = 39; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[9] = -117; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[10] = 124; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[11] = -107; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[12] = 48; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[13] = 15; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[14] = -42; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[15] = -59; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[16] = -115; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[17] = 32; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[18] = 33; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[19] = -121; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0].pcv[0]); + } + test_msg->apc[0].pcv[20] = -106; + test_msg->apc[0].sat_info = 240; + test_msg->apc[0].sid.code = 169; + test_msg->apc[0].sid.sat = 203; + test_msg->apc[0].svn = 1102; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pco[0]); + } + test_msg->apc[1].pco[0] = 23079; + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pco[0]); + } + test_msg->apc[1].pco[1] = -22252; + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pco[0]); + } + test_msg->apc[1].pco[2] = 12271; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[0] = -103; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[1] = -81; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[2] = 35; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[3] = -111; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[4] = -111; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[5] = 123; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[6] = -62; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[7] = 2; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[8] = 102; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[9] = 74; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[10] = -107; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[11] = 95; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[12] = -85; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[13] = -18; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[14] = -7; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[15] = 7; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[16] = -19; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[17] = -86; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[18] = 125; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[19] = 106; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[1].pcv[0]); + } + test_msg->apc[1].pcv[20] = -98; + test_msg->apc[1].sat_info = 49; + test_msg->apc[1].sid.code = 123; + test_msg->apc[1].sid.sat = 148; + test_msg->apc[1].svn = 24967; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pco[0]); + } + test_msg->apc[2].pco[0] = -7596; + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pco[0]); + } + test_msg->apc[2].pco[1] = 31630; + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pco[0]); + } + test_msg->apc[2].pco[2] = -9907; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[0] = -8; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[1] = 67; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[2] = -41; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[3] = -127; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[4] = 114; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[5] = -118; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[6] = 25; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[7] = -16; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[8] = 10; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[9] = 56; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[10] = 76; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[11] = 61; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[12] = -95; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[13] = -40; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[14] = 22; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[15] = -75; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[16] = -82; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[17] = 33; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[18] = 13; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[19] = -4; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[2].pcv[0]); + } + test_msg->apc[2].pcv[20] = -20; + test_msg->apc[2].sat_info = 181; + test_msg->apc[2].sid.code = 188; + test_msg->apc[2].sid.sat = 83; + test_msg->apc[2].svn = 7106; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pco[0]); + } + test_msg->apc[3].pco[0] = -19478; + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pco[0]); + } + test_msg->apc[3].pco[1] = 11484; + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pco[0]); + } + test_msg->apc[3].pco[2] = 14804; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[0] = 44; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[1] = -83; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[2] = 49; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[3] = 36; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[4] = -119; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[5] = -8; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[6] = -21; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[7] = 97; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[8] = 112; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[9] = -99; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[10] = -117; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[11] = 26; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[12] = 115; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[13] = -64; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[14] = 31; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[15] = 85; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[16] = 127; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[17] = -28; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[18] = 81; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[19] = -4; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[3].pcv[0]); + } + test_msg->apc[3].pcv[20] = -37; + test_msg->apc[3].sat_info = 128; + test_msg->apc[3].sid.code = 196; + test_msg->apc[3].sid.sat = 230; + test_msg->apc[3].svn = 61399; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pco[0]); + } + test_msg->apc[4].pco[0] = -11049; + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pco[0]); + } + test_msg->apc[4].pco[1] = 6580; + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pco[0]); + } + test_msg->apc[4].pco[2] = -28589; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[0] = -9; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[1] = 12; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[2] = 27; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[3] = -57; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[4] = -83; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[5] = 74; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[6] = 23; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[7] = 4; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[8] = -17; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[9] = 103; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[10] = -33; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[11] = -36; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[12] = -117; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[13] = 91; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[14] = 127; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[15] = -42; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[16] = 86; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[17] = 48; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[18] = -53; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[19] = -28; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[4].pcv[0]); + } + test_msg->apc[4].pcv[20] = 99; + test_msg->apc[4].sat_info = 147; + test_msg->apc[4].sid.code = 110; + test_msg->apc[4].sid.sat = 249; + test_msg->apc[4].svn = 41224; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pco[0]); + } + test_msg->apc[5].pco[0] = -21881; + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pco[0]); + } + test_msg->apc[5].pco[1] = -9942; + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pco[0]); + } + test_msg->apc[5].pco[2] = -5689; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[0] = 42; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[1] = -86; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[2] = 78; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[3] = -50; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[4] = 41; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[5] = 43; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[6] = 81; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[7] = -9; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[8] = 99; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[9] = -58; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[10] = -112; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[11] = 2; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[12] = -124; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[13] = 2; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[14] = -32; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[15] = -36; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[16] = -108; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[17] = 58; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[18] = 85; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[19] = -118; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[5].pcv[0]); + } + test_msg->apc[5].pcv[20] = -46; + test_msg->apc[5].sat_info = 159; + test_msg->apc[5].sid.code = 83; + test_msg->apc[5].sid.sat = 45; + test_msg->apc[5].svn = 64011; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[0]); + } + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pco[0]); + } + test_msg->apc[6].pco[0] = -14290; + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pco[0]); + } + test_msg->apc[6].pco[1] = 30340; + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pco[0]); + } + test_msg->apc[6].pco[2] = 3569; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[0] = 37; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[1] = 62; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[2] = 107; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[3] = -3; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[4] = -66; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[5] = -120; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[6] = 66; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[7] = 9; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[8] = 84; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[9] = -101; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[10] = 86; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[11] = -76; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[12] = 41; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[13] = -60; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[14] = 40; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[15] = 119; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[16] = 101; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[17] = -4; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[18] = -33; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[19] = -112; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->apc[6].pcv[0]); + } + test_msg->apc[6].pcv[20] = -103; + test_msg->apc[6].sat_info = 7; + test_msg->apc[6].sid.code = 158; + test_msg->apc[6].sid.sat = 200; + test_msg->apc[6].svn = 17310; + sbp_payload_send(&sbp_state, 0x604, 4920, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 4920, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 4920, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x604, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_satellite_apc_dep_t *check_msg = + (msg_ssr_satellite_apc_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->apc[0].pco[0] == -21547, + "incorrect value for apc[0].pco[0], expected -21547, is %d", + check_msg->apc[0].pco[0]); + ck_assert_msg(check_msg->apc[0].pco[1] == -10498, + "incorrect value for apc[0].pco[1], expected -10498, is %d", + check_msg->apc[0].pco[1]); + ck_assert_msg(check_msg->apc[0].pco[2] == 1236, + "incorrect value for apc[0].pco[2], expected 1236, is %d", + check_msg->apc[0].pco[2]); + ck_assert_msg(check_msg->apc[0].pcv[0] == 8, + "incorrect value for apc[0].pcv[0], expected 8, is %d", + check_msg->apc[0].pcv[0]); + ck_assert_msg(check_msg->apc[0].pcv[1] == 33, + "incorrect value for apc[0].pcv[1], expected 33, is %d", + check_msg->apc[0].pcv[1]); + ck_assert_msg(check_msg->apc[0].pcv[2] == 31, + "incorrect value for apc[0].pcv[2], expected 31, is %d", + check_msg->apc[0].pcv[2]); + ck_assert_msg(check_msg->apc[0].pcv[3] == 80, + "incorrect value for apc[0].pcv[3], expected 80, is %d", + check_msg->apc[0].pcv[3]); + ck_assert_msg(check_msg->apc[0].pcv[4] == 21, + "incorrect value for apc[0].pcv[4], expected 21, is %d", + check_msg->apc[0].pcv[4]); + ck_assert_msg(check_msg->apc[0].pcv[5] == 4, + "incorrect value for apc[0].pcv[5], expected 4, is %d", + check_msg->apc[0].pcv[5]); + ck_assert_msg(check_msg->apc[0].pcv[6] == 105, + "incorrect value for apc[0].pcv[6], expected 105, is %d", + check_msg->apc[0].pcv[6]); + ck_assert_msg(check_msg->apc[0].pcv[7] == -31, + "incorrect value for apc[0].pcv[7], expected -31, is %d", + check_msg->apc[0].pcv[7]); + ck_assert_msg(check_msg->apc[0].pcv[8] == 39, + "incorrect value for apc[0].pcv[8], expected 39, is %d", + check_msg->apc[0].pcv[8]); + ck_assert_msg(check_msg->apc[0].pcv[9] == -117, + "incorrect value for apc[0].pcv[9], expected -117, is %d", + check_msg->apc[0].pcv[9]); + ck_assert_msg(check_msg->apc[0].pcv[10] == 124, + "incorrect value for apc[0].pcv[10], expected 124, is %d", + check_msg->apc[0].pcv[10]); + ck_assert_msg(check_msg->apc[0].pcv[11] == -107, + "incorrect value for apc[0].pcv[11], expected -107, is %d", + check_msg->apc[0].pcv[11]); + ck_assert_msg(check_msg->apc[0].pcv[12] == 48, + "incorrect value for apc[0].pcv[12], expected 48, is %d", + check_msg->apc[0].pcv[12]); + ck_assert_msg(check_msg->apc[0].pcv[13] == 15, + "incorrect value for apc[0].pcv[13], expected 15, is %d", + check_msg->apc[0].pcv[13]); + ck_assert_msg(check_msg->apc[0].pcv[14] == -42, + "incorrect value for apc[0].pcv[14], expected -42, is %d", + check_msg->apc[0].pcv[14]); + ck_assert_msg(check_msg->apc[0].pcv[15] == -59, + "incorrect value for apc[0].pcv[15], expected -59, is %d", + check_msg->apc[0].pcv[15]); + ck_assert_msg(check_msg->apc[0].pcv[16] == -115, + "incorrect value for apc[0].pcv[16], expected -115, is %d", + check_msg->apc[0].pcv[16]); + ck_assert_msg(check_msg->apc[0].pcv[17] == 32, + "incorrect value for apc[0].pcv[17], expected 32, is %d", + check_msg->apc[0].pcv[17]); + ck_assert_msg(check_msg->apc[0].pcv[18] == 33, + "incorrect value for apc[0].pcv[18], expected 33, is %d", + check_msg->apc[0].pcv[18]); + ck_assert_msg(check_msg->apc[0].pcv[19] == -121, + "incorrect value for apc[0].pcv[19], expected -121, is %d", + check_msg->apc[0].pcv[19]); + ck_assert_msg(check_msg->apc[0].pcv[20] == -106, + "incorrect value for apc[0].pcv[20], expected -106, is %d", + check_msg->apc[0].pcv[20]); + ck_assert_msg(check_msg->apc[0].sat_info == 240, + "incorrect value for apc[0].sat_info, expected 240, is %d", + check_msg->apc[0].sat_info); + ck_assert_msg(check_msg->apc[0].sid.code == 169, + "incorrect value for apc[0].sid.code, expected 169, is %d", + check_msg->apc[0].sid.code); + ck_assert_msg(check_msg->apc[0].sid.sat == 203, + "incorrect value for apc[0].sid.sat, expected 203, is %d", + check_msg->apc[0].sid.sat); + ck_assert_msg(check_msg->apc[0].svn == 1102, + "incorrect value for apc[0].svn, expected 1102, is %d", + check_msg->apc[0].svn); + ck_assert_msg(check_msg->apc[1].pco[0] == 23079, + "incorrect value for apc[1].pco[0], expected 23079, is %d", + check_msg->apc[1].pco[0]); + ck_assert_msg(check_msg->apc[1].pco[1] == -22252, + "incorrect value for apc[1].pco[1], expected -22252, is %d", + check_msg->apc[1].pco[1]); + ck_assert_msg(check_msg->apc[1].pco[2] == 12271, + "incorrect value for apc[1].pco[2], expected 12271, is %d", + check_msg->apc[1].pco[2]); + ck_assert_msg(check_msg->apc[1].pcv[0] == -103, + "incorrect value for apc[1].pcv[0], expected -103, is %d", + check_msg->apc[1].pcv[0]); + ck_assert_msg(check_msg->apc[1].pcv[1] == -81, + "incorrect value for apc[1].pcv[1], expected -81, is %d", + check_msg->apc[1].pcv[1]); + ck_assert_msg(check_msg->apc[1].pcv[2] == 35, + "incorrect value for apc[1].pcv[2], expected 35, is %d", + check_msg->apc[1].pcv[2]); + ck_assert_msg(check_msg->apc[1].pcv[3] == -111, + "incorrect value for apc[1].pcv[3], expected -111, is %d", + check_msg->apc[1].pcv[3]); + ck_assert_msg(check_msg->apc[1].pcv[4] == -111, + "incorrect value for apc[1].pcv[4], expected -111, is %d", + check_msg->apc[1].pcv[4]); + ck_assert_msg(check_msg->apc[1].pcv[5] == 123, + "incorrect value for apc[1].pcv[5], expected 123, is %d", + check_msg->apc[1].pcv[5]); + ck_assert_msg(check_msg->apc[1].pcv[6] == -62, + "incorrect value for apc[1].pcv[6], expected -62, is %d", + check_msg->apc[1].pcv[6]); + ck_assert_msg(check_msg->apc[1].pcv[7] == 2, + "incorrect value for apc[1].pcv[7], expected 2, is %d", + check_msg->apc[1].pcv[7]); + ck_assert_msg(check_msg->apc[1].pcv[8] == 102, + "incorrect value for apc[1].pcv[8], expected 102, is %d", + check_msg->apc[1].pcv[8]); + ck_assert_msg(check_msg->apc[1].pcv[9] == 74, + "incorrect value for apc[1].pcv[9], expected 74, is %d", + check_msg->apc[1].pcv[9]); + ck_assert_msg(check_msg->apc[1].pcv[10] == -107, + "incorrect value for apc[1].pcv[10], expected -107, is %d", + check_msg->apc[1].pcv[10]); + ck_assert_msg(check_msg->apc[1].pcv[11] == 95, + "incorrect value for apc[1].pcv[11], expected 95, is %d", + check_msg->apc[1].pcv[11]); + ck_assert_msg(check_msg->apc[1].pcv[12] == -85, + "incorrect value for apc[1].pcv[12], expected -85, is %d", + check_msg->apc[1].pcv[12]); + ck_assert_msg(check_msg->apc[1].pcv[13] == -18, + "incorrect value for apc[1].pcv[13], expected -18, is %d", + check_msg->apc[1].pcv[13]); + ck_assert_msg(check_msg->apc[1].pcv[14] == -7, + "incorrect value for apc[1].pcv[14], expected -7, is %d", + check_msg->apc[1].pcv[14]); + ck_assert_msg(check_msg->apc[1].pcv[15] == 7, + "incorrect value for apc[1].pcv[15], expected 7, is %d", + check_msg->apc[1].pcv[15]); + ck_assert_msg(check_msg->apc[1].pcv[16] == -19, + "incorrect value for apc[1].pcv[16], expected -19, is %d", + check_msg->apc[1].pcv[16]); + ck_assert_msg(check_msg->apc[1].pcv[17] == -86, + "incorrect value for apc[1].pcv[17], expected -86, is %d", + check_msg->apc[1].pcv[17]); + ck_assert_msg(check_msg->apc[1].pcv[18] == 125, + "incorrect value for apc[1].pcv[18], expected 125, is %d", + check_msg->apc[1].pcv[18]); + ck_assert_msg(check_msg->apc[1].pcv[19] == 106, + "incorrect value for apc[1].pcv[19], expected 106, is %d", + check_msg->apc[1].pcv[19]); + ck_assert_msg(check_msg->apc[1].pcv[20] == -98, + "incorrect value for apc[1].pcv[20], expected -98, is %d", + check_msg->apc[1].pcv[20]); + ck_assert_msg(check_msg->apc[1].sat_info == 49, + "incorrect value for apc[1].sat_info, expected 49, is %d", + check_msg->apc[1].sat_info); + ck_assert_msg(check_msg->apc[1].sid.code == 123, + "incorrect value for apc[1].sid.code, expected 123, is %d", + check_msg->apc[1].sid.code); + ck_assert_msg(check_msg->apc[1].sid.sat == 148, + "incorrect value for apc[1].sid.sat, expected 148, is %d", + check_msg->apc[1].sid.sat); + ck_assert_msg(check_msg->apc[1].svn == 24967, + "incorrect value for apc[1].svn, expected 24967, is %d", + check_msg->apc[1].svn); + ck_assert_msg(check_msg->apc[2].pco[0] == -7596, + "incorrect value for apc[2].pco[0], expected -7596, is %d", + check_msg->apc[2].pco[0]); + ck_assert_msg(check_msg->apc[2].pco[1] == 31630, + "incorrect value for apc[2].pco[1], expected 31630, is %d", + check_msg->apc[2].pco[1]); + ck_assert_msg(check_msg->apc[2].pco[2] == -9907, + "incorrect value for apc[2].pco[2], expected -9907, is %d", + check_msg->apc[2].pco[2]); + ck_assert_msg(check_msg->apc[2].pcv[0] == -8, + "incorrect value for apc[2].pcv[0], expected -8, is %d", + check_msg->apc[2].pcv[0]); + ck_assert_msg(check_msg->apc[2].pcv[1] == 67, + "incorrect value for apc[2].pcv[1], expected 67, is %d", + check_msg->apc[2].pcv[1]); + ck_assert_msg(check_msg->apc[2].pcv[2] == -41, + "incorrect value for apc[2].pcv[2], expected -41, is %d", + check_msg->apc[2].pcv[2]); + ck_assert_msg(check_msg->apc[2].pcv[3] == -127, + "incorrect value for apc[2].pcv[3], expected -127, is %d", + check_msg->apc[2].pcv[3]); + ck_assert_msg(check_msg->apc[2].pcv[4] == 114, + "incorrect value for apc[2].pcv[4], expected 114, is %d", + check_msg->apc[2].pcv[4]); + ck_assert_msg(check_msg->apc[2].pcv[5] == -118, + "incorrect value for apc[2].pcv[5], expected -118, is %d", + check_msg->apc[2].pcv[5]); + ck_assert_msg(check_msg->apc[2].pcv[6] == 25, + "incorrect value for apc[2].pcv[6], expected 25, is %d", + check_msg->apc[2].pcv[6]); + ck_assert_msg(check_msg->apc[2].pcv[7] == -16, + "incorrect value for apc[2].pcv[7], expected -16, is %d", + check_msg->apc[2].pcv[7]); + ck_assert_msg(check_msg->apc[2].pcv[8] == 10, + "incorrect value for apc[2].pcv[8], expected 10, is %d", + check_msg->apc[2].pcv[8]); + ck_assert_msg(check_msg->apc[2].pcv[9] == 56, + "incorrect value for apc[2].pcv[9], expected 56, is %d", + check_msg->apc[2].pcv[9]); + ck_assert_msg(check_msg->apc[2].pcv[10] == 76, + "incorrect value for apc[2].pcv[10], expected 76, is %d", + check_msg->apc[2].pcv[10]); + ck_assert_msg(check_msg->apc[2].pcv[11] == 61, + "incorrect value for apc[2].pcv[11], expected 61, is %d", + check_msg->apc[2].pcv[11]); + ck_assert_msg(check_msg->apc[2].pcv[12] == -95, + "incorrect value for apc[2].pcv[12], expected -95, is %d", + check_msg->apc[2].pcv[12]); + ck_assert_msg(check_msg->apc[2].pcv[13] == -40, + "incorrect value for apc[2].pcv[13], expected -40, is %d", + check_msg->apc[2].pcv[13]); + ck_assert_msg(check_msg->apc[2].pcv[14] == 22, + "incorrect value for apc[2].pcv[14], expected 22, is %d", + check_msg->apc[2].pcv[14]); + ck_assert_msg(check_msg->apc[2].pcv[15] == -75, + "incorrect value for apc[2].pcv[15], expected -75, is %d", + check_msg->apc[2].pcv[15]); + ck_assert_msg(check_msg->apc[2].pcv[16] == -82, + "incorrect value for apc[2].pcv[16], expected -82, is %d", + check_msg->apc[2].pcv[16]); + ck_assert_msg(check_msg->apc[2].pcv[17] == 33, + "incorrect value for apc[2].pcv[17], expected 33, is %d", + check_msg->apc[2].pcv[17]); + ck_assert_msg(check_msg->apc[2].pcv[18] == 13, + "incorrect value for apc[2].pcv[18], expected 13, is %d", + check_msg->apc[2].pcv[18]); + ck_assert_msg(check_msg->apc[2].pcv[19] == -4, + "incorrect value for apc[2].pcv[19], expected -4, is %d", + check_msg->apc[2].pcv[19]); + ck_assert_msg(check_msg->apc[2].pcv[20] == -20, + "incorrect value for apc[2].pcv[20], expected -20, is %d", + check_msg->apc[2].pcv[20]); + ck_assert_msg(check_msg->apc[2].sat_info == 181, + "incorrect value for apc[2].sat_info, expected 181, is %d", + check_msg->apc[2].sat_info); + ck_assert_msg(check_msg->apc[2].sid.code == 188, + "incorrect value for apc[2].sid.code, expected 188, is %d", + check_msg->apc[2].sid.code); + ck_assert_msg(check_msg->apc[2].sid.sat == 83, + "incorrect value for apc[2].sid.sat, expected 83, is %d", + check_msg->apc[2].sid.sat); + ck_assert_msg(check_msg->apc[2].svn == 7106, + "incorrect value for apc[2].svn, expected 7106, is %d", + check_msg->apc[2].svn); + ck_assert_msg(check_msg->apc[3].pco[0] == -19478, + "incorrect value for apc[3].pco[0], expected -19478, is %d", + check_msg->apc[3].pco[0]); + ck_assert_msg(check_msg->apc[3].pco[1] == 11484, + "incorrect value for apc[3].pco[1], expected 11484, is %d", + check_msg->apc[3].pco[1]); + ck_assert_msg(check_msg->apc[3].pco[2] == 14804, + "incorrect value for apc[3].pco[2], expected 14804, is %d", + check_msg->apc[3].pco[2]); + ck_assert_msg(check_msg->apc[3].pcv[0] == 44, + "incorrect value for apc[3].pcv[0], expected 44, is %d", + check_msg->apc[3].pcv[0]); + ck_assert_msg(check_msg->apc[3].pcv[1] == -83, + "incorrect value for apc[3].pcv[1], expected -83, is %d", + check_msg->apc[3].pcv[1]); + ck_assert_msg(check_msg->apc[3].pcv[2] == 49, + "incorrect value for apc[3].pcv[2], expected 49, is %d", + check_msg->apc[3].pcv[2]); + ck_assert_msg(check_msg->apc[3].pcv[3] == 36, + "incorrect value for apc[3].pcv[3], expected 36, is %d", + check_msg->apc[3].pcv[3]); + ck_assert_msg(check_msg->apc[3].pcv[4] == -119, + "incorrect value for apc[3].pcv[4], expected -119, is %d", + check_msg->apc[3].pcv[4]); + ck_assert_msg(check_msg->apc[3].pcv[5] == -8, + "incorrect value for apc[3].pcv[5], expected -8, is %d", + check_msg->apc[3].pcv[5]); + ck_assert_msg(check_msg->apc[3].pcv[6] == -21, + "incorrect value for apc[3].pcv[6], expected -21, is %d", + check_msg->apc[3].pcv[6]); + ck_assert_msg(check_msg->apc[3].pcv[7] == 97, + "incorrect value for apc[3].pcv[7], expected 97, is %d", + check_msg->apc[3].pcv[7]); + ck_assert_msg(check_msg->apc[3].pcv[8] == 112, + "incorrect value for apc[3].pcv[8], expected 112, is %d", + check_msg->apc[3].pcv[8]); + ck_assert_msg(check_msg->apc[3].pcv[9] == -99, + "incorrect value for apc[3].pcv[9], expected -99, is %d", + check_msg->apc[3].pcv[9]); + ck_assert_msg(check_msg->apc[3].pcv[10] == -117, + "incorrect value for apc[3].pcv[10], expected -117, is %d", + check_msg->apc[3].pcv[10]); + ck_assert_msg(check_msg->apc[3].pcv[11] == 26, + "incorrect value for apc[3].pcv[11], expected 26, is %d", + check_msg->apc[3].pcv[11]); + ck_assert_msg(check_msg->apc[3].pcv[12] == 115, + "incorrect value for apc[3].pcv[12], expected 115, is %d", + check_msg->apc[3].pcv[12]); + ck_assert_msg(check_msg->apc[3].pcv[13] == -64, + "incorrect value for apc[3].pcv[13], expected -64, is %d", + check_msg->apc[3].pcv[13]); + ck_assert_msg(check_msg->apc[3].pcv[14] == 31, + "incorrect value for apc[3].pcv[14], expected 31, is %d", + check_msg->apc[3].pcv[14]); + ck_assert_msg(check_msg->apc[3].pcv[15] == 85, + "incorrect value for apc[3].pcv[15], expected 85, is %d", + check_msg->apc[3].pcv[15]); + ck_assert_msg(check_msg->apc[3].pcv[16] == 127, + "incorrect value for apc[3].pcv[16], expected 127, is %d", + check_msg->apc[3].pcv[16]); + ck_assert_msg(check_msg->apc[3].pcv[17] == -28, + "incorrect value for apc[3].pcv[17], expected -28, is %d", + check_msg->apc[3].pcv[17]); + ck_assert_msg(check_msg->apc[3].pcv[18] == 81, + "incorrect value for apc[3].pcv[18], expected 81, is %d", + check_msg->apc[3].pcv[18]); + ck_assert_msg(check_msg->apc[3].pcv[19] == -4, + "incorrect value for apc[3].pcv[19], expected -4, is %d", + check_msg->apc[3].pcv[19]); + ck_assert_msg(check_msg->apc[3].pcv[20] == -37, + "incorrect value for apc[3].pcv[20], expected -37, is %d", + check_msg->apc[3].pcv[20]); + ck_assert_msg(check_msg->apc[3].sat_info == 128, + "incorrect value for apc[3].sat_info, expected 128, is %d", + check_msg->apc[3].sat_info); + ck_assert_msg(check_msg->apc[3].sid.code == 196, + "incorrect value for apc[3].sid.code, expected 196, is %d", + check_msg->apc[3].sid.code); + ck_assert_msg(check_msg->apc[3].sid.sat == 230, + "incorrect value for apc[3].sid.sat, expected 230, is %d", + check_msg->apc[3].sid.sat); + ck_assert_msg(check_msg->apc[3].svn == 61399, + "incorrect value for apc[3].svn, expected 61399, is %d", + check_msg->apc[3].svn); + ck_assert_msg(check_msg->apc[4].pco[0] == -11049, + "incorrect value for apc[4].pco[0], expected -11049, is %d", + check_msg->apc[4].pco[0]); + ck_assert_msg(check_msg->apc[4].pco[1] == 6580, + "incorrect value for apc[4].pco[1], expected 6580, is %d", + check_msg->apc[4].pco[1]); + ck_assert_msg(check_msg->apc[4].pco[2] == -28589, + "incorrect value for apc[4].pco[2], expected -28589, is %d", + check_msg->apc[4].pco[2]); + ck_assert_msg(check_msg->apc[4].pcv[0] == -9, + "incorrect value for apc[4].pcv[0], expected -9, is %d", + check_msg->apc[4].pcv[0]); + ck_assert_msg(check_msg->apc[4].pcv[1] == 12, + "incorrect value for apc[4].pcv[1], expected 12, is %d", + check_msg->apc[4].pcv[1]); + ck_assert_msg(check_msg->apc[4].pcv[2] == 27, + "incorrect value for apc[4].pcv[2], expected 27, is %d", + check_msg->apc[4].pcv[2]); + ck_assert_msg(check_msg->apc[4].pcv[3] == -57, + "incorrect value for apc[4].pcv[3], expected -57, is %d", + check_msg->apc[4].pcv[3]); + ck_assert_msg(check_msg->apc[4].pcv[4] == -83, + "incorrect value for apc[4].pcv[4], expected -83, is %d", + check_msg->apc[4].pcv[4]); + ck_assert_msg(check_msg->apc[4].pcv[5] == 74, + "incorrect value for apc[4].pcv[5], expected 74, is %d", + check_msg->apc[4].pcv[5]); + ck_assert_msg(check_msg->apc[4].pcv[6] == 23, + "incorrect value for apc[4].pcv[6], expected 23, is %d", + check_msg->apc[4].pcv[6]); + ck_assert_msg(check_msg->apc[4].pcv[7] == 4, + "incorrect value for apc[4].pcv[7], expected 4, is %d", + check_msg->apc[4].pcv[7]); + ck_assert_msg(check_msg->apc[4].pcv[8] == -17, + "incorrect value for apc[4].pcv[8], expected -17, is %d", + check_msg->apc[4].pcv[8]); + ck_assert_msg(check_msg->apc[4].pcv[9] == 103, + "incorrect value for apc[4].pcv[9], expected 103, is %d", + check_msg->apc[4].pcv[9]); + ck_assert_msg(check_msg->apc[4].pcv[10] == -33, + "incorrect value for apc[4].pcv[10], expected -33, is %d", + check_msg->apc[4].pcv[10]); + ck_assert_msg(check_msg->apc[4].pcv[11] == -36, + "incorrect value for apc[4].pcv[11], expected -36, is %d", + check_msg->apc[4].pcv[11]); + ck_assert_msg(check_msg->apc[4].pcv[12] == -117, + "incorrect value for apc[4].pcv[12], expected -117, is %d", + check_msg->apc[4].pcv[12]); + ck_assert_msg(check_msg->apc[4].pcv[13] == 91, + "incorrect value for apc[4].pcv[13], expected 91, is %d", + check_msg->apc[4].pcv[13]); + ck_assert_msg(check_msg->apc[4].pcv[14] == 127, + "incorrect value for apc[4].pcv[14], expected 127, is %d", + check_msg->apc[4].pcv[14]); + ck_assert_msg(check_msg->apc[4].pcv[15] == -42, + "incorrect value for apc[4].pcv[15], expected -42, is %d", + check_msg->apc[4].pcv[15]); + ck_assert_msg(check_msg->apc[4].pcv[16] == 86, + "incorrect value for apc[4].pcv[16], expected 86, is %d", + check_msg->apc[4].pcv[16]); + ck_assert_msg(check_msg->apc[4].pcv[17] == 48, + "incorrect value for apc[4].pcv[17], expected 48, is %d", + check_msg->apc[4].pcv[17]); + ck_assert_msg(check_msg->apc[4].pcv[18] == -53, + "incorrect value for apc[4].pcv[18], expected -53, is %d", + check_msg->apc[4].pcv[18]); + ck_assert_msg(check_msg->apc[4].pcv[19] == -28, + "incorrect value for apc[4].pcv[19], expected -28, is %d", + check_msg->apc[4].pcv[19]); + ck_assert_msg(check_msg->apc[4].pcv[20] == 99, + "incorrect value for apc[4].pcv[20], expected 99, is %d", + check_msg->apc[4].pcv[20]); + ck_assert_msg(check_msg->apc[4].sat_info == 147, + "incorrect value for apc[4].sat_info, expected 147, is %d", + check_msg->apc[4].sat_info); + ck_assert_msg(check_msg->apc[4].sid.code == 110, + "incorrect value for apc[4].sid.code, expected 110, is %d", + check_msg->apc[4].sid.code); + ck_assert_msg(check_msg->apc[4].sid.sat == 249, + "incorrect value for apc[4].sid.sat, expected 249, is %d", + check_msg->apc[4].sid.sat); + ck_assert_msg(check_msg->apc[4].svn == 41224, + "incorrect value for apc[4].svn, expected 41224, is %d", + check_msg->apc[4].svn); + ck_assert_msg(check_msg->apc[5].pco[0] == -21881, + "incorrect value for apc[5].pco[0], expected -21881, is %d", + check_msg->apc[5].pco[0]); + ck_assert_msg(check_msg->apc[5].pco[1] == -9942, + "incorrect value for apc[5].pco[1], expected -9942, is %d", + check_msg->apc[5].pco[1]); + ck_assert_msg(check_msg->apc[5].pco[2] == -5689, + "incorrect value for apc[5].pco[2], expected -5689, is %d", + check_msg->apc[5].pco[2]); + ck_assert_msg(check_msg->apc[5].pcv[0] == 42, + "incorrect value for apc[5].pcv[0], expected 42, is %d", + check_msg->apc[5].pcv[0]); + ck_assert_msg(check_msg->apc[5].pcv[1] == -86, + "incorrect value for apc[5].pcv[1], expected -86, is %d", + check_msg->apc[5].pcv[1]); + ck_assert_msg(check_msg->apc[5].pcv[2] == 78, + "incorrect value for apc[5].pcv[2], expected 78, is %d", + check_msg->apc[5].pcv[2]); + ck_assert_msg(check_msg->apc[5].pcv[3] == -50, + "incorrect value for apc[5].pcv[3], expected -50, is %d", + check_msg->apc[5].pcv[3]); + ck_assert_msg(check_msg->apc[5].pcv[4] == 41, + "incorrect value for apc[5].pcv[4], expected 41, is %d", + check_msg->apc[5].pcv[4]); + ck_assert_msg(check_msg->apc[5].pcv[5] == 43, + "incorrect value for apc[5].pcv[5], expected 43, is %d", + check_msg->apc[5].pcv[5]); + ck_assert_msg(check_msg->apc[5].pcv[6] == 81, + "incorrect value for apc[5].pcv[6], expected 81, is %d", + check_msg->apc[5].pcv[6]); + ck_assert_msg(check_msg->apc[5].pcv[7] == -9, + "incorrect value for apc[5].pcv[7], expected -9, is %d", + check_msg->apc[5].pcv[7]); + ck_assert_msg(check_msg->apc[5].pcv[8] == 99, + "incorrect value for apc[5].pcv[8], expected 99, is %d", + check_msg->apc[5].pcv[8]); + ck_assert_msg(check_msg->apc[5].pcv[9] == -58, + "incorrect value for apc[5].pcv[9], expected -58, is %d", + check_msg->apc[5].pcv[9]); + ck_assert_msg(check_msg->apc[5].pcv[10] == -112, + "incorrect value for apc[5].pcv[10], expected -112, is %d", + check_msg->apc[5].pcv[10]); + ck_assert_msg(check_msg->apc[5].pcv[11] == 2, + "incorrect value for apc[5].pcv[11], expected 2, is %d", + check_msg->apc[5].pcv[11]); + ck_assert_msg(check_msg->apc[5].pcv[12] == -124, + "incorrect value for apc[5].pcv[12], expected -124, is %d", + check_msg->apc[5].pcv[12]); + ck_assert_msg(check_msg->apc[5].pcv[13] == 2, + "incorrect value for apc[5].pcv[13], expected 2, is %d", + check_msg->apc[5].pcv[13]); + ck_assert_msg(check_msg->apc[5].pcv[14] == -32, + "incorrect value for apc[5].pcv[14], expected -32, is %d", + check_msg->apc[5].pcv[14]); + ck_assert_msg(check_msg->apc[5].pcv[15] == -36, + "incorrect value for apc[5].pcv[15], expected -36, is %d", + check_msg->apc[5].pcv[15]); + ck_assert_msg(check_msg->apc[5].pcv[16] == -108, + "incorrect value for apc[5].pcv[16], expected -108, is %d", + check_msg->apc[5].pcv[16]); + ck_assert_msg(check_msg->apc[5].pcv[17] == 58, + "incorrect value for apc[5].pcv[17], expected 58, is %d", + check_msg->apc[5].pcv[17]); + ck_assert_msg(check_msg->apc[5].pcv[18] == 85, + "incorrect value for apc[5].pcv[18], expected 85, is %d", + check_msg->apc[5].pcv[18]); + ck_assert_msg(check_msg->apc[5].pcv[19] == -118, + "incorrect value for apc[5].pcv[19], expected -118, is %d", + check_msg->apc[5].pcv[19]); + ck_assert_msg(check_msg->apc[5].pcv[20] == -46, + "incorrect value for apc[5].pcv[20], expected -46, is %d", + check_msg->apc[5].pcv[20]); + ck_assert_msg(check_msg->apc[5].sat_info == 159, + "incorrect value for apc[5].sat_info, expected 159, is %d", + check_msg->apc[5].sat_info); + ck_assert_msg(check_msg->apc[5].sid.code == 83, + "incorrect value for apc[5].sid.code, expected 83, is %d", + check_msg->apc[5].sid.code); + ck_assert_msg(check_msg->apc[5].sid.sat == 45, + "incorrect value for apc[5].sid.sat, expected 45, is %d", + check_msg->apc[5].sid.sat); + ck_assert_msg(check_msg->apc[5].svn == 64011, + "incorrect value for apc[5].svn, expected 64011, is %d", + check_msg->apc[5].svn); + ck_assert_msg(check_msg->apc[6].pco[0] == -14290, + "incorrect value for apc[6].pco[0], expected -14290, is %d", + check_msg->apc[6].pco[0]); + ck_assert_msg(check_msg->apc[6].pco[1] == 30340, + "incorrect value for apc[6].pco[1], expected 30340, is %d", + check_msg->apc[6].pco[1]); + ck_assert_msg(check_msg->apc[6].pco[2] == 3569, + "incorrect value for apc[6].pco[2], expected 3569, is %d", + check_msg->apc[6].pco[2]); + ck_assert_msg(check_msg->apc[6].pcv[0] == 37, + "incorrect value for apc[6].pcv[0], expected 37, is %d", + check_msg->apc[6].pcv[0]); + ck_assert_msg(check_msg->apc[6].pcv[1] == 62, + "incorrect value for apc[6].pcv[1], expected 62, is %d", + check_msg->apc[6].pcv[1]); + ck_assert_msg(check_msg->apc[6].pcv[2] == 107, + "incorrect value for apc[6].pcv[2], expected 107, is %d", + check_msg->apc[6].pcv[2]); + ck_assert_msg(check_msg->apc[6].pcv[3] == -3, + "incorrect value for apc[6].pcv[3], expected -3, is %d", + check_msg->apc[6].pcv[3]); + ck_assert_msg(check_msg->apc[6].pcv[4] == -66, + "incorrect value for apc[6].pcv[4], expected -66, is %d", + check_msg->apc[6].pcv[4]); + ck_assert_msg(check_msg->apc[6].pcv[5] == -120, + "incorrect value for apc[6].pcv[5], expected -120, is %d", + check_msg->apc[6].pcv[5]); + ck_assert_msg(check_msg->apc[6].pcv[6] == 66, + "incorrect value for apc[6].pcv[6], expected 66, is %d", + check_msg->apc[6].pcv[6]); + ck_assert_msg(check_msg->apc[6].pcv[7] == 9, + "incorrect value for apc[6].pcv[7], expected 9, is %d", + check_msg->apc[6].pcv[7]); + ck_assert_msg(check_msg->apc[6].pcv[8] == 84, + "incorrect value for apc[6].pcv[8], expected 84, is %d", + check_msg->apc[6].pcv[8]); + ck_assert_msg(check_msg->apc[6].pcv[9] == -101, + "incorrect value for apc[6].pcv[9], expected -101, is %d", + check_msg->apc[6].pcv[9]); + ck_assert_msg(check_msg->apc[6].pcv[10] == 86, + "incorrect value for apc[6].pcv[10], expected 86, is %d", + check_msg->apc[6].pcv[10]); + ck_assert_msg(check_msg->apc[6].pcv[11] == -76, + "incorrect value for apc[6].pcv[11], expected -76, is %d", + check_msg->apc[6].pcv[11]); + ck_assert_msg(check_msg->apc[6].pcv[12] == 41, + "incorrect value for apc[6].pcv[12], expected 41, is %d", + check_msg->apc[6].pcv[12]); + ck_assert_msg(check_msg->apc[6].pcv[13] == -60, + "incorrect value for apc[6].pcv[13], expected -60, is %d", + check_msg->apc[6].pcv[13]); + ck_assert_msg(check_msg->apc[6].pcv[14] == 40, + "incorrect value for apc[6].pcv[14], expected 40, is %d", + check_msg->apc[6].pcv[14]); + ck_assert_msg(check_msg->apc[6].pcv[15] == 119, + "incorrect value for apc[6].pcv[15], expected 119, is %d", + check_msg->apc[6].pcv[15]); + ck_assert_msg(check_msg->apc[6].pcv[16] == 101, + "incorrect value for apc[6].pcv[16], expected 101, is %d", + check_msg->apc[6].pcv[16]); + ck_assert_msg(check_msg->apc[6].pcv[17] == -4, + "incorrect value for apc[6].pcv[17], expected -4, is %d", + check_msg->apc[6].pcv[17]); + ck_assert_msg(check_msg->apc[6].pcv[18] == -33, + "incorrect value for apc[6].pcv[18], expected -33, is %d", + check_msg->apc[6].pcv[18]); + ck_assert_msg(check_msg->apc[6].pcv[19] == -112, + "incorrect value for apc[6].pcv[19], expected -112, is %d", + check_msg->apc[6].pcv[19]); + ck_assert_msg(check_msg->apc[6].pcv[20] == -103, + "incorrect value for apc[6].pcv[20], expected -103, is %d", + check_msg->apc[6].pcv[20]); + ck_assert_msg(check_msg->apc[6].sat_info == 7, + "incorrect value for apc[6].sat_info, expected 7, is %d", + check_msg->apc[6].sat_info); + ck_assert_msg(check_msg->apc[6].sid.code == 158, + "incorrect value for apc[6].sid.code, expected 158, is %d", + check_msg->apc[6].sid.code); + ck_assert_msg(check_msg->apc[6].sid.sat == 200, + "incorrect value for apc[6].sid.sat, expected 200, is %d", + check_msg->apc[6].sid.sat); + ck_assert_msg(check_msg->apc[6].svn == 17310, + "incorrect value for apc[6].svn, expected 17310, is %d", + check_msg->apc[6].svn); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c new file mode 100644 index 0000000000..cdd24aa0ae --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.c @@ -0,0 +1,1428 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5fb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5fb, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, + 119, 156, 157, 112, 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, + 3, 14, 8, 70, 12, 44, 53, 181, 90, 174, 247, 150, 58, 172, + 247, 179, 119, 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, + 53, 222, 187, 146, 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, + 91, 234, 0, 213, 139, 95, 179, 50, 21, 74, 174, 169, 61, 86, + 91, 142, 51, 108, 9, 38, 225, 146, 101, 73, 139, 56, 117, 82, + 37, 213, 108, 205, 93, 18, 19, 195, 33, 202, 87, 206, 178, 125, + 188, 119, 56, 69, 150, 150, 76, 3, 131, 18, 73, 208, 72, 232, + 8, 250, 203, 178, 170, 163, 252, 86, 49, 247, 178, 166, 56, 31, + 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, 124, 169, 121, 158, + 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, 110, 23, 12, + 241, 88, 69, 239, 252, 57, 93, 44, 201, 216, 173, 242, 178, 17, + 5, 223, 169, 192, 3, 77, 107, 2, 144, 233, 14, 88, 32, 209, + 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, + 126, 217, 79, 171, 239, 237, 188, 238, 112, 201, 118, 141, 18, 163, + 103, 35, 63, 21, 82, 129, 18, 117, 85, 190, 79, 210, 215, 227, + 177, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_stec_correction_dep_t *test_msg = + (msg_ssr_stec_correction_dep_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.iod_atmo = 60; + test_msg->header.num_msgs = 157; + test_msg->header.seq_num = 112; + test_msg->header.tile_id = 30066; + test_msg->header.tile_set_id = 58526; + test_msg->header.time.tow = 714907186; + test_msg->header.time.wn = 40055; + test_msg->header.update_interval = 47; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[0] = -5289; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[1] = -20141; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[2] = 966; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[3] = 2062; + test_msg->stec_sat_list[0].stec_quality_indicator = 70; + test_msg->stec_sat_list[0].sv_id.constellation = 40; + test_msg->stec_sat_list[0].sv_id.satId = 132; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[0] = -19147; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[1] = -20902; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[2] = -26889; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[3] = -21446; + test_msg->stec_sat_list[1].stec_quality_indicator = 44; + test_msg->stec_sat_list[1].sv_id.constellation = 12; + test_msg->stec_sat_list[1].sv_id.satId = 70; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[0] = 32176; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[1] = -20220; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[2] = 29157; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[3] = 19726; + test_msg->stec_sat_list[2].stec_quality_indicator = 119; + test_msg->stec_sat_list[2].sv_id.constellation = 179; + test_msg->stec_sat_list[2].sv_id.satId = 247; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[0] = -8651; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[1] = -27973; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[2] = 23546; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[3] = -10284; + test_msg->stec_sat_list[3].stec_quality_indicator = 23; + test_msg->stec_sat_list[3].sv_id.constellation = 185; + test_msg->stec_sat_list[3].sv_id.satId = 153; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[0] = 27486; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[1] = 23329; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[2] = 234; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[3] = -29739; + test_msg->stec_sat_list[4].stec_quality_indicator = 250; + test_msg->stec_sat_list[4].sv_id.constellation = 107; + test_msg->stec_sat_list[4].sv_id.satId = 14; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[0] = 18965; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[1] = -22098; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[2] = 22077; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[3] = -29093; + test_msg->stec_sat_list[5].stec_quality_indicator = 50; + test_msg->stec_sat_list[5].sv_id.constellation = 179; + test_msg->stec_sat_list[5].sv_id.satId = 95; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[0] = -7898; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[1] = 26002; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[2] = -29879; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[3] = 30008; + test_msg->stec_sat_list[6].stec_quality_indicator = 9; + test_msg->stec_sat_list[6].sv_id.constellation = 108; + test_msg->stec_sat_list[6].sv_id.satId = 51; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[0] = -12948; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[1] = 4701; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[2] = -15597; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[3] = -13791; + test_msg->stec_sat_list[7].stec_quality_indicator = 213; + test_msg->stec_sat_list[7].sv_id.constellation = 37; + test_msg->stec_sat_list[7].sv_id.satId = 82; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[0] = -17283; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[1] = 14455; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[2] = -27067; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[3] = 19606; + test_msg->stec_sat_list[8].stec_quality_indicator = 178; + test_msg->stec_sat_list[8].sv_id.constellation = 206; + test_msg->stec_sat_list[8].sv_id.satId = 87; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[0] = -12215; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[1] = -6072; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[2] = -1528; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[3] = -19765; + test_msg->stec_sat_list[9].stec_quality_indicator = 18; + test_msg->stec_sat_list[9].sv_id.constellation = 131; + test_msg->stec_sat_list[9].sv_id.satId = 3; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[0] = 12630; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[1] = -19721; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[2] = 14502; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[3] = 2591; + test_msg->stec_sat_list[10].stec_quality_indicator = 252; + test_msg->stec_sat_list[10].sv_id.constellation = 163; + test_msg->stec_sat_list[10].sv_id.satId = 170; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[0] = -23340; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[1] = -24063; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[2] = 4650; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[3] = -22148; + test_msg->stec_sat_list[11].stec_quality_indicator = 241; + test_msg->stec_sat_list[11].sv_id.constellation = 213; + test_msg->stec_sat_list[11].sv_id.satId = 119; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[0] = 5944; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[1] = 32142; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[2] = 30760; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[3] = 11587; + test_msg->stec_sat_list[12].stec_quality_indicator = 26; + test_msg->stec_sat_list[12].sv_id.constellation = 158; + test_msg->stec_sat_list[12].sv_id.satId = 121; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[0] = 3095; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[1] = 22769; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[2] = -4283; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[3] = 14844; + test_msg->stec_sat_list[13].stec_quality_indicator = 110; + test_msg->stec_sat_list[13].sv_id.constellation = 235; + test_msg->stec_sat_list[13].sv_id.satId = 126; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[0] = -21032; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[1] = -19726; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[2] = 1297; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[3] = -22049; + test_msg->stec_sat_list[14].stec_quality_indicator = 201; + test_msg->stec_sat_list[14].sv_id.constellation = 44; + test_msg->stec_sat_list[14].sv_id.satId = 93; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[0] = 619; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[1] = -5744; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[2] = 22542; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[3] = -12000; + test_msg->stec_sat_list[15].stec_quality_indicator = 77; + test_msg->stec_sat_list[15].sv_id.constellation = 3; + test_msg->stec_sat_list[15].sv_id.satId = 192; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[0] = 10651; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[1] = -2889; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[2] = 21150; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[3] = 26421; + test_msg->stec_sat_list[16].stec_quality_indicator = 123; + test_msg->stec_sat_list[16].sv_id.constellation = 17; + test_msg->stec_sat_list[16].sv_id.satId = 1; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[0] = -19165; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[1] = 30229; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[2] = -1282; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[3] = -18382; + test_msg->stec_sat_list[17].stec_quality_indicator = 185; + test_msg->stec_sat_list[17].sv_id.constellation = 202; + test_msg->stec_sat_list[17].sv_id.satId = 14; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[0] = -23752; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[1] = 32433; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[2] = 20441; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[3] = -4181; + test_msg->stec_sat_list[18].stec_quality_indicator = 45; + test_msg->stec_sat_list[18].sv_id.constellation = 31; + test_msg->stec_sat_list[18].sv_id.satId = 50; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[0] = -13968; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[1] = -29322; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[2] = -23790; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[3] = 9063; + test_msg->stec_sat_list[19].stec_quality_indicator = 238; + test_msg->stec_sat_list[19].sv_id.constellation = 188; + test_msg->stec_sat_list[19].sv_id.satId = 237; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[0] = 4737; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[1] = 21877; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[2] = 20414; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[3] = -10286; + test_msg->stec_sat_list[20].stec_quality_indicator = 82; + test_msg->stec_sat_list[20].sv_id.constellation = 21; + test_msg->stec_sat_list[20].sv_id.satId = 63; + sbp_payload_send(&sbp_state, 0x5fb, 38860, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 38860, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 38860, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5fb, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_stec_correction_dep_t *check_msg = + (msg_ssr_stec_correction_dep_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->header.iod_atmo == 60, + "incorrect value for header.iod_atmo, expected 60, is %d", + check_msg->header.iod_atmo); + ck_assert_msg(check_msg->header.num_msgs == 157, + "incorrect value for header.num_msgs, expected 157, is %d", + check_msg->header.num_msgs); + ck_assert_msg(check_msg->header.seq_num == 112, + "incorrect value for header.seq_num, expected 112, is %d", + check_msg->header.seq_num); + ck_assert_msg(check_msg->header.tile_id == 30066, + "incorrect value for header.tile_id, expected 30066, is %d", + check_msg->header.tile_id); + ck_assert_msg( + check_msg->header.tile_set_id == 58526, + "incorrect value for header.tile_set_id, expected 58526, is %d", + check_msg->header.tile_set_id); + ck_assert_msg( + check_msg->header.time.tow == 714907186, + "incorrect value for header.time.tow, expected 714907186, is %d", + check_msg->header.time.tow); + ck_assert_msg(check_msg->header.time.wn == 40055, + "incorrect value for header.time.wn, expected 40055, is %d", + check_msg->header.time.wn); + ck_assert_msg( + check_msg->header.update_interval == 47, + "incorrect value for header.update_interval, expected 47, is %d", + check_msg->header.update_interval); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[0] == -5289, + "incorrect value for stec_sat_list[0].stec_coeff[0], " + "expected -5289, is %d", + check_msg->stec_sat_list[0].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[1] == -20141, + "incorrect value for stec_sat_list[0].stec_coeff[1], " + "expected -20141, is %d", + check_msg->stec_sat_list[0].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[2] == 966, + "incorrect value for stec_sat_list[0].stec_coeff[2], " + "expected 966, is %d", + check_msg->stec_sat_list[0].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[3] == 2062, + "incorrect value for stec_sat_list[0].stec_coeff[3], " + "expected 2062, is %d", + check_msg->stec_sat_list[0].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_quality_indicator == 70, + "incorrect value for " + "stec_sat_list[0].stec_quality_indicator, expected 70, is %d", + check_msg->stec_sat_list[0].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[0].sv_id.constellation == 40, + "incorrect value for stec_sat_list[0].sv_id.constellation, " + "expected 40, is %d", + check_msg->stec_sat_list[0].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[0].sv_id.satId == 132, + "incorrect value for stec_sat_list[0].sv_id.satId, expected 132, is %d", + check_msg->stec_sat_list[0].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[0] == -19147, + "incorrect value for stec_sat_list[1].stec_coeff[0], " + "expected -19147, is %d", + check_msg->stec_sat_list[1].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[1] == -20902, + "incorrect value for stec_sat_list[1].stec_coeff[1], " + "expected -20902, is %d", + check_msg->stec_sat_list[1].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[2] == -26889, + "incorrect value for stec_sat_list[1].stec_coeff[2], " + "expected -26889, is %d", + check_msg->stec_sat_list[1].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[3] == -21446, + "incorrect value for stec_sat_list[1].stec_coeff[3], " + "expected -21446, is %d", + check_msg->stec_sat_list[1].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_quality_indicator == 44, + "incorrect value for " + "stec_sat_list[1].stec_quality_indicator, expected 44, is %d", + check_msg->stec_sat_list[1].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[1].sv_id.constellation == 12, + "incorrect value for stec_sat_list[1].sv_id.constellation, " + "expected 12, is %d", + check_msg->stec_sat_list[1].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[1].sv_id.satId == 70, + "incorrect value for stec_sat_list[1].sv_id.satId, expected 70, is %d", + check_msg->stec_sat_list[1].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[0] == 32176, + "incorrect value for stec_sat_list[2].stec_coeff[0], " + "expected 32176, is %d", + check_msg->stec_sat_list[2].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[1] == -20220, + "incorrect value for stec_sat_list[2].stec_coeff[1], " + "expected -20220, is %d", + check_msg->stec_sat_list[2].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[2] == 29157, + "incorrect value for stec_sat_list[2].stec_coeff[2], " + "expected 29157, is %d", + check_msg->stec_sat_list[2].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[3] == 19726, + "incorrect value for stec_sat_list[2].stec_coeff[3], " + "expected 19726, is %d", + check_msg->stec_sat_list[2].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[2].stec_quality_indicator == 119, + "incorrect value for stec_sat_list[2].stec_quality_indicator, expected " + "119, is %d", + check_msg->stec_sat_list[2].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[2].sv_id.constellation == 179, + "incorrect value for stec_sat_list[2].sv_id.constellation, " + "expected 179, is %d", + check_msg->stec_sat_list[2].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[2].sv_id.satId == 247, + "incorrect value for stec_sat_list[2].sv_id.satId, expected 247, is %d", + check_msg->stec_sat_list[2].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[0] == -8651, + "incorrect value for stec_sat_list[3].stec_coeff[0], " + "expected -8651, is %d", + check_msg->stec_sat_list[3].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[1] == -27973, + "incorrect value for stec_sat_list[3].stec_coeff[1], " + "expected -27973, is %d", + check_msg->stec_sat_list[3].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[2] == 23546, + "incorrect value for stec_sat_list[3].stec_coeff[2], " + "expected 23546, is %d", + check_msg->stec_sat_list[3].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[3] == -10284, + "incorrect value for stec_sat_list[3].stec_coeff[3], " + "expected -10284, is %d", + check_msg->stec_sat_list[3].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_quality_indicator == 23, + "incorrect value for " + "stec_sat_list[3].stec_quality_indicator, expected 23, is %d", + check_msg->stec_sat_list[3].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[3].sv_id.constellation == 185, + "incorrect value for stec_sat_list[3].sv_id.constellation, " + "expected 185, is %d", + check_msg->stec_sat_list[3].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[3].sv_id.satId == 153, + "incorrect value for stec_sat_list[3].sv_id.satId, expected 153, is %d", + check_msg->stec_sat_list[3].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[0] == 27486, + "incorrect value for stec_sat_list[4].stec_coeff[0], " + "expected 27486, is %d", + check_msg->stec_sat_list[4].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[1] == 23329, + "incorrect value for stec_sat_list[4].stec_coeff[1], " + "expected 23329, is %d", + check_msg->stec_sat_list[4].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[2] == 234, + "incorrect value for stec_sat_list[4].stec_coeff[2], " + "expected 234, is %d", + check_msg->stec_sat_list[4].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[3] == -29739, + "incorrect value for stec_sat_list[4].stec_coeff[3], " + "expected -29739, is %d", + check_msg->stec_sat_list[4].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[4].stec_quality_indicator == 250, + "incorrect value for stec_sat_list[4].stec_quality_indicator, expected " + "250, is %d", + check_msg->stec_sat_list[4].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[4].sv_id.constellation == 107, + "incorrect value for stec_sat_list[4].sv_id.constellation, " + "expected 107, is %d", + check_msg->stec_sat_list[4].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[4].sv_id.satId == 14, + "incorrect value for stec_sat_list[4].sv_id.satId, expected 14, is %d", + check_msg->stec_sat_list[4].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[0] == 18965, + "incorrect value for stec_sat_list[5].stec_coeff[0], " + "expected 18965, is %d", + check_msg->stec_sat_list[5].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[1] == -22098, + "incorrect value for stec_sat_list[5].stec_coeff[1], " + "expected -22098, is %d", + check_msg->stec_sat_list[5].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[2] == 22077, + "incorrect value for stec_sat_list[5].stec_coeff[2], " + "expected 22077, is %d", + check_msg->stec_sat_list[5].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[3] == -29093, + "incorrect value for stec_sat_list[5].stec_coeff[3], " + "expected -29093, is %d", + check_msg->stec_sat_list[5].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_quality_indicator == 50, + "incorrect value for " + "stec_sat_list[5].stec_quality_indicator, expected 50, is %d", + check_msg->stec_sat_list[5].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[5].sv_id.constellation == 179, + "incorrect value for stec_sat_list[5].sv_id.constellation, " + "expected 179, is %d", + check_msg->stec_sat_list[5].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[5].sv_id.satId == 95, + "incorrect value for stec_sat_list[5].sv_id.satId, expected 95, is %d", + check_msg->stec_sat_list[5].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[0] == -7898, + "incorrect value for stec_sat_list[6].stec_coeff[0], " + "expected -7898, is %d", + check_msg->stec_sat_list[6].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[1] == 26002, + "incorrect value for stec_sat_list[6].stec_coeff[1], " + "expected 26002, is %d", + check_msg->stec_sat_list[6].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[2] == -29879, + "incorrect value for stec_sat_list[6].stec_coeff[2], " + "expected -29879, is %d", + check_msg->stec_sat_list[6].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[3] == 30008, + "incorrect value for stec_sat_list[6].stec_coeff[3], " + "expected 30008, is %d", + check_msg->stec_sat_list[6].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_quality_indicator == 9, + "incorrect value for " + "stec_sat_list[6].stec_quality_indicator, expected 9, is %d", + check_msg->stec_sat_list[6].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[6].sv_id.constellation == 108, + "incorrect value for stec_sat_list[6].sv_id.constellation, " + "expected 108, is %d", + check_msg->stec_sat_list[6].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[6].sv_id.satId == 51, + "incorrect value for stec_sat_list[6].sv_id.satId, expected 51, is %d", + check_msg->stec_sat_list[6].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[0] == -12948, + "incorrect value for stec_sat_list[7].stec_coeff[0], " + "expected -12948, is %d", + check_msg->stec_sat_list[7].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[1] == 4701, + "incorrect value for stec_sat_list[7].stec_coeff[1], " + "expected 4701, is %d", + check_msg->stec_sat_list[7].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[2] == -15597, + "incorrect value for stec_sat_list[7].stec_coeff[2], " + "expected -15597, is %d", + check_msg->stec_sat_list[7].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[3] == -13791, + "incorrect value for stec_sat_list[7].stec_coeff[3], " + "expected -13791, is %d", + check_msg->stec_sat_list[7].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[7].stec_quality_indicator == 213, + "incorrect value for stec_sat_list[7].stec_quality_indicator, expected " + "213, is %d", + check_msg->stec_sat_list[7].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[7].sv_id.constellation == 37, + "incorrect value for stec_sat_list[7].sv_id.constellation, " + "expected 37, is %d", + check_msg->stec_sat_list[7].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[7].sv_id.satId == 82, + "incorrect value for stec_sat_list[7].sv_id.satId, expected 82, is %d", + check_msg->stec_sat_list[7].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[0] == -17283, + "incorrect value for stec_sat_list[8].stec_coeff[0], " + "expected -17283, is %d", + check_msg->stec_sat_list[8].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[1] == 14455, + "incorrect value for stec_sat_list[8].stec_coeff[1], " + "expected 14455, is %d", + check_msg->stec_sat_list[8].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[2] == -27067, + "incorrect value for stec_sat_list[8].stec_coeff[2], " + "expected -27067, is %d", + check_msg->stec_sat_list[8].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[3] == 19606, + "incorrect value for stec_sat_list[8].stec_coeff[3], " + "expected 19606, is %d", + check_msg->stec_sat_list[8].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[8].stec_quality_indicator == 178, + "incorrect value for stec_sat_list[8].stec_quality_indicator, expected " + "178, is %d", + check_msg->stec_sat_list[8].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[8].sv_id.constellation == 206, + "incorrect value for stec_sat_list[8].sv_id.constellation, " + "expected 206, is %d", + check_msg->stec_sat_list[8].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[8].sv_id.satId == 87, + "incorrect value for stec_sat_list[8].sv_id.satId, expected 87, is %d", + check_msg->stec_sat_list[8].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[0] == -12215, + "incorrect value for stec_sat_list[9].stec_coeff[0], " + "expected -12215, is %d", + check_msg->stec_sat_list[9].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[1] == -6072, + "incorrect value for stec_sat_list[9].stec_coeff[1], " + "expected -6072, is %d", + check_msg->stec_sat_list[9].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[2] == -1528, + "incorrect value for stec_sat_list[9].stec_coeff[2], " + "expected -1528, is %d", + check_msg->stec_sat_list[9].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[3] == -19765, + "incorrect value for stec_sat_list[9].stec_coeff[3], " + "expected -19765, is %d", + check_msg->stec_sat_list[9].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_quality_indicator == 18, + "incorrect value for " + "stec_sat_list[9].stec_quality_indicator, expected 18, is %d", + check_msg->stec_sat_list[9].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[9].sv_id.constellation == 131, + "incorrect value for stec_sat_list[9].sv_id.constellation, " + "expected 131, is %d", + check_msg->stec_sat_list[9].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[9].sv_id.satId == 3, + "incorrect value for stec_sat_list[9].sv_id.satId, expected 3, is %d", + check_msg->stec_sat_list[9].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[0] == 12630, + "incorrect value for stec_sat_list[10].stec_coeff[0], " + "expected 12630, is %d", + check_msg->stec_sat_list[10].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[1] == -19721, + "incorrect value for stec_sat_list[10].stec_coeff[1], " + "expected -19721, is %d", + check_msg->stec_sat_list[10].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[2] == 14502, + "incorrect value for stec_sat_list[10].stec_coeff[2], " + "expected 14502, is %d", + check_msg->stec_sat_list[10].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[3] == 2591, + "incorrect value for stec_sat_list[10].stec_coeff[3], " + "expected 2591, is %d", + check_msg->stec_sat_list[10].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[10].stec_quality_indicator == 252, + "incorrect value for stec_sat_list[10].stec_quality_indicator, " + "expected 252, is %d", + check_msg->stec_sat_list[10].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[10].sv_id.constellation == 163, + "incorrect value for stec_sat_list[10].sv_id.constellation, " + "expected 163, is %d", + check_msg->stec_sat_list[10].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[10].sv_id.satId == 170, + "incorrect value for stec_sat_list[10].sv_id.satId, expected " + "170, is %d", + check_msg->stec_sat_list[10].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[0] == -23340, + "incorrect value for stec_sat_list[11].stec_coeff[0], " + "expected -23340, is %d", + check_msg->stec_sat_list[11].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[1] == -24063, + "incorrect value for stec_sat_list[11].stec_coeff[1], " + "expected -24063, is %d", + check_msg->stec_sat_list[11].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[2] == 4650, + "incorrect value for stec_sat_list[11].stec_coeff[2], " + "expected 4650, is %d", + check_msg->stec_sat_list[11].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[3] == -22148, + "incorrect value for stec_sat_list[11].stec_coeff[3], " + "expected -22148, is %d", + check_msg->stec_sat_list[11].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[11].stec_quality_indicator == 241, + "incorrect value for stec_sat_list[11].stec_quality_indicator, " + "expected 241, is %d", + check_msg->stec_sat_list[11].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[11].sv_id.constellation == 213, + "incorrect value for stec_sat_list[11].sv_id.constellation, " + "expected 213, is %d", + check_msg->stec_sat_list[11].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[11].sv_id.satId == 119, + "incorrect value for stec_sat_list[11].sv_id.satId, expected " + "119, is %d", + check_msg->stec_sat_list[11].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[0] == 5944, + "incorrect value for stec_sat_list[12].stec_coeff[0], " + "expected 5944, is %d", + check_msg->stec_sat_list[12].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[1] == 32142, + "incorrect value for stec_sat_list[12].stec_coeff[1], " + "expected 32142, is %d", + check_msg->stec_sat_list[12].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[2] == 30760, + "incorrect value for stec_sat_list[12].stec_coeff[2], " + "expected 30760, is %d", + check_msg->stec_sat_list[12].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[3] == 11587, + "incorrect value for stec_sat_list[12].stec_coeff[3], " + "expected 11587, is %d", + check_msg->stec_sat_list[12].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[12].stec_quality_indicator == 26, + "incorrect value for stec_sat_list[12].stec_quality_indicator, " + "expected 26, is %d", + check_msg->stec_sat_list[12].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[12].sv_id.constellation == 158, + "incorrect value for stec_sat_list[12].sv_id.constellation, " + "expected 158, is %d", + check_msg->stec_sat_list[12].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[12].sv_id.satId == 121, + "incorrect value for stec_sat_list[12].sv_id.satId, expected " + "121, is %d", + check_msg->stec_sat_list[12].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[0] == 3095, + "incorrect value for stec_sat_list[13].stec_coeff[0], " + "expected 3095, is %d", + check_msg->stec_sat_list[13].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[1] == 22769, + "incorrect value for stec_sat_list[13].stec_coeff[1], " + "expected 22769, is %d", + check_msg->stec_sat_list[13].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[2] == -4283, + "incorrect value for stec_sat_list[13].stec_coeff[2], " + "expected -4283, is %d", + check_msg->stec_sat_list[13].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[3] == 14844, + "incorrect value for stec_sat_list[13].stec_coeff[3], " + "expected 14844, is %d", + check_msg->stec_sat_list[13].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[13].stec_quality_indicator == 110, + "incorrect value for stec_sat_list[13].stec_quality_indicator, " + "expected 110, is %d", + check_msg->stec_sat_list[13].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[13].sv_id.constellation == 235, + "incorrect value for stec_sat_list[13].sv_id.constellation, " + "expected 235, is %d", + check_msg->stec_sat_list[13].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[13].sv_id.satId == 126, + "incorrect value for stec_sat_list[13].sv_id.satId, expected " + "126, is %d", + check_msg->stec_sat_list[13].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[0] == -21032, + "incorrect value for stec_sat_list[14].stec_coeff[0], " + "expected -21032, is %d", + check_msg->stec_sat_list[14].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[1] == -19726, + "incorrect value for stec_sat_list[14].stec_coeff[1], " + "expected -19726, is %d", + check_msg->stec_sat_list[14].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[2] == 1297, + "incorrect value for stec_sat_list[14].stec_coeff[2], " + "expected 1297, is %d", + check_msg->stec_sat_list[14].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[3] == -22049, + "incorrect value for stec_sat_list[14].stec_coeff[3], " + "expected -22049, is %d", + check_msg->stec_sat_list[14].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[14].stec_quality_indicator == 201, + "incorrect value for stec_sat_list[14].stec_quality_indicator, " + "expected 201, is %d", + check_msg->stec_sat_list[14].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[14].sv_id.constellation == 44, + "incorrect value for stec_sat_list[14].sv_id.constellation, " + "expected 44, is %d", + check_msg->stec_sat_list[14].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[14].sv_id.satId == 93, + "incorrect value for stec_sat_list[14].sv_id.satId, expected 93, is %d", + check_msg->stec_sat_list[14].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[0] == 619, + "incorrect value for stec_sat_list[15].stec_coeff[0], " + "expected 619, is %d", + check_msg->stec_sat_list[15].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[1] == -5744, + "incorrect value for stec_sat_list[15].stec_coeff[1], " + "expected -5744, is %d", + check_msg->stec_sat_list[15].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[2] == 22542, + "incorrect value for stec_sat_list[15].stec_coeff[2], " + "expected 22542, is %d", + check_msg->stec_sat_list[15].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[3] == -12000, + "incorrect value for stec_sat_list[15].stec_coeff[3], " + "expected -12000, is %d", + check_msg->stec_sat_list[15].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[15].stec_quality_indicator == 77, + "incorrect value for stec_sat_list[15].stec_quality_indicator, " + "expected 77, is %d", + check_msg->stec_sat_list[15].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[15].sv_id.constellation == 3, + "incorrect value for stec_sat_list[15].sv_id.constellation, " + "expected 3, is %d", + check_msg->stec_sat_list[15].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[15].sv_id.satId == 192, + "incorrect value for stec_sat_list[15].sv_id.satId, expected " + "192, is %d", + check_msg->stec_sat_list[15].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[0] == 10651, + "incorrect value for stec_sat_list[16].stec_coeff[0], " + "expected 10651, is %d", + check_msg->stec_sat_list[16].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[1] == -2889, + "incorrect value for stec_sat_list[16].stec_coeff[1], " + "expected -2889, is %d", + check_msg->stec_sat_list[16].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[2] == 21150, + "incorrect value for stec_sat_list[16].stec_coeff[2], " + "expected 21150, is %d", + check_msg->stec_sat_list[16].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[3] == 26421, + "incorrect value for stec_sat_list[16].stec_coeff[3], " + "expected 26421, is %d", + check_msg->stec_sat_list[16].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[16].stec_quality_indicator == 123, + "incorrect value for stec_sat_list[16].stec_quality_indicator, " + "expected 123, is %d", + check_msg->stec_sat_list[16].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[16].sv_id.constellation == 17, + "incorrect value for stec_sat_list[16].sv_id.constellation, " + "expected 17, is %d", + check_msg->stec_sat_list[16].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[16].sv_id.satId == 1, + "incorrect value for stec_sat_list[16].sv_id.satId, expected 1, is %d", + check_msg->stec_sat_list[16].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[0] == -19165, + "incorrect value for stec_sat_list[17].stec_coeff[0], " + "expected -19165, is %d", + check_msg->stec_sat_list[17].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[1] == 30229, + "incorrect value for stec_sat_list[17].stec_coeff[1], " + "expected 30229, is %d", + check_msg->stec_sat_list[17].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[2] == -1282, + "incorrect value for stec_sat_list[17].stec_coeff[2], " + "expected -1282, is %d", + check_msg->stec_sat_list[17].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[3] == -18382, + "incorrect value for stec_sat_list[17].stec_coeff[3], " + "expected -18382, is %d", + check_msg->stec_sat_list[17].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[17].stec_quality_indicator == 185, + "incorrect value for stec_sat_list[17].stec_quality_indicator, " + "expected 185, is %d", + check_msg->stec_sat_list[17].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[17].sv_id.constellation == 202, + "incorrect value for stec_sat_list[17].sv_id.constellation, " + "expected 202, is %d", + check_msg->stec_sat_list[17].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[17].sv_id.satId == 14, + "incorrect value for stec_sat_list[17].sv_id.satId, expected 14, is %d", + check_msg->stec_sat_list[17].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[0] == -23752, + "incorrect value for stec_sat_list[18].stec_coeff[0], " + "expected -23752, is %d", + check_msg->stec_sat_list[18].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[1] == 32433, + "incorrect value for stec_sat_list[18].stec_coeff[1], " + "expected 32433, is %d", + check_msg->stec_sat_list[18].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[2] == 20441, + "incorrect value for stec_sat_list[18].stec_coeff[2], " + "expected 20441, is %d", + check_msg->stec_sat_list[18].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[3] == -4181, + "incorrect value for stec_sat_list[18].stec_coeff[3], " + "expected -4181, is %d", + check_msg->stec_sat_list[18].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[18].stec_quality_indicator == 45, + "incorrect value for stec_sat_list[18].stec_quality_indicator, " + "expected 45, is %d", + check_msg->stec_sat_list[18].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[18].sv_id.constellation == 31, + "incorrect value for stec_sat_list[18].sv_id.constellation, " + "expected 31, is %d", + check_msg->stec_sat_list[18].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[18].sv_id.satId == 50, + "incorrect value for stec_sat_list[18].sv_id.satId, expected 50, is %d", + check_msg->stec_sat_list[18].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[0] == -13968, + "incorrect value for stec_sat_list[19].stec_coeff[0], " + "expected -13968, is %d", + check_msg->stec_sat_list[19].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[1] == -29322, + "incorrect value for stec_sat_list[19].stec_coeff[1], " + "expected -29322, is %d", + check_msg->stec_sat_list[19].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[2] == -23790, + "incorrect value for stec_sat_list[19].stec_coeff[2], " + "expected -23790, is %d", + check_msg->stec_sat_list[19].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[3] == 9063, + "incorrect value for stec_sat_list[19].stec_coeff[3], " + "expected 9063, is %d", + check_msg->stec_sat_list[19].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[19].stec_quality_indicator == 238, + "incorrect value for stec_sat_list[19].stec_quality_indicator, " + "expected 238, is %d", + check_msg->stec_sat_list[19].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[19].sv_id.constellation == 188, + "incorrect value for stec_sat_list[19].sv_id.constellation, " + "expected 188, is %d", + check_msg->stec_sat_list[19].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[19].sv_id.satId == 237, + "incorrect value for stec_sat_list[19].sv_id.satId, expected " + "237, is %d", + check_msg->stec_sat_list[19].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[0] == 4737, + "incorrect value for stec_sat_list[20].stec_coeff[0], " + "expected 4737, is %d", + check_msg->stec_sat_list[20].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[1] == 21877, + "incorrect value for stec_sat_list[20].stec_coeff[1], " + "expected 21877, is %d", + check_msg->stec_sat_list[20].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[2] == 20414, + "incorrect value for stec_sat_list[20].stec_coeff[2], " + "expected 20414, is %d", + check_msg->stec_sat_list[20].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[3] == -10286, + "incorrect value for stec_sat_list[20].stec_coeff[3], " + "expected -10286, is %d", + check_msg->stec_sat_list[20].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[20].stec_quality_indicator == 82, + "incorrect value for stec_sat_list[20].stec_quality_indicator, " + "expected 82, is %d", + check_msg->stec_sat_list[20].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[20].sv_id.constellation == 21, + "incorrect value for stec_sat_list[20].sv_id.constellation, " + "expected 21, is %d", + check_msg->stec_sat_list[20].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[20].sv_id.satId == 63, + "incorrect value for stec_sat_list[20].sv_id.satId, expected 63, is %d", + check_msg->stec_sat_list[20].sv_id.satId); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c new file mode 100644 index 0000000000..f9a4b8baca --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.c @@ -0,0 +1,1478 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5eb, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5eb, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, + 39, 4, 126, 19, 111, 97, 248, 130, 217, 217, 106, 58, 12, 65, + 230, 171, 81, 95, 86, 16, 39, 84, 228, 208, 201, 81, 219, 99, + 203, 61, 182, 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, + 93, 218, 247, 158, 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, + 148, 147, 72, 225, 180, 236, 205, 201, 33, 3, 246, 204, 19, 3, + 98, 4, 194, 191, 246, 76, 219, 31, 191, 113, 79, 177, 15, 251, + 33, 19, 96, 54, 58, 146, 210, 100, 249, 72, 21, 161, 211, 198, + 21, 238, 111, 107, 36, 227, 225, 213, 3, 71, 243, 63, 65, 236, + 92, 77, 0, 169, 15, 182, 5, 240, 180, 9, 122, 86, 232, 6, + 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, 216, 55, 50, 181, + 5, 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, 66, 124, 168, + 59, 139, 106, 118, 51, 187, 216, 191, 158, 77, 92, 58, 253, 132, + 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, 181, 196, 23, 53, + 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, + 201, 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, + 22, 178, 226, 109, 88, 157, 30, 196, 175, 26, 76, 34, 116, 220, + 154, 232, 12, 179, 244, 15, 155, 196, 202, 72, 70, 115, 10, 214, + 114, 39, 245, 28, 237, 68, 136, 155, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_stec_correction_dep_a_t *test_msg = + (msg_ssr_stec_correction_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->header.iod_atmo = 4; + test_msg->header.num_msgs = 147; + test_msg->header.seq_num = 123; + test_msg->header.time.tow = 3905179974; + test_msg->header.time.wn = 11193; + test_msg->header.update_interval = 39; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[0] = -1951; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[1] = -9854; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[2] = 27353; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0].stec_coeff[0]); + } + test_msg->stec_sat_list[0].stec_coeff[3] = 3130; + test_msg->stec_sat_list[0].stec_quality_indicator = 111; + test_msg->stec_sat_list[0].sv_id.constellation = 19; + test_msg->stec_sat_list[0].sv_id.satId = 126; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[0] = 24401; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[1] = 4182; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[2] = 21543; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[1].stec_coeff[0]); + } + test_msg->stec_sat_list[1].stec_coeff[3] = -12060; + test_msg->stec_sat_list[1].stec_quality_indicator = 171; + test_msg->stec_sat_list[1].sv_id.constellation = 230; + test_msg->stec_sat_list[1].sv_id.satId = 65; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[0] = -13469; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[1] = -18883; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[2] = 32066; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[2].stec_coeff[0]); + } + test_msg->stec_sat_list[2].stec_coeff[3] = 971; + test_msg->stec_sat_list[2].stec_quality_indicator = 219; + test_msg->stec_sat_list[2].sv_id.constellation = 81; + test_msg->stec_sat_list[2].sv_id.satId = 201; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[0] = 32220; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[1] = 5436; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[2] = -9635; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[3].stec_coeff[0]); + } + test_msg->stec_sat_list[3].stec_coeff[3] = -24841; + test_msg->stec_sat_list[3].stec_quality_indicator = 100; + test_msg->stec_sat_list[3].sv_id.constellation = 44; + test_msg->stec_sat_list[3].sv_id.satId = 193; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[0] = 3718; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[1] = 12497; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[2] = -10482; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[4].stec_coeff[0]); + } + test_msg->stec_sat_list[4].stec_coeff[3] = -27495; + test_msg->stec_sat_list[4].stec_quality_indicator = 129; + test_msg->stec_sat_list[4].sv_id.constellation = 93; + test_msg->stec_sat_list[4].sv_id.satId = 207; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[0] = -4940; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[1] = -13875; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[2] = 801; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[5].stec_coeff[0]); + } + test_msg->stec_sat_list[5].stec_coeff[3] = -13066; + test_msg->stec_sat_list[5].stec_quality_indicator = 225; + test_msg->stec_sat_list[5].sv_id.constellation = 72; + test_msg->stec_sat_list[5].sv_id.satId = 147; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[0] = -15868; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[1] = -2369; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[2] = -9396; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[6].stec_coeff[0]); + } + test_msg->stec_sat_list[6].stec_coeff[3] = -16609; + test_msg->stec_sat_list[6].stec_quality_indicator = 98; + test_msg->stec_sat_list[6].sv_id.constellation = 3; + test_msg->stec_sat_list[6].sv_id.satId = 19; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[0] = -1265; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[1] = 4897; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[2] = 13920; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[7].stec_coeff[0]); + } + test_msg->stec_sat_list[7].stec_coeff[3] = -28102; + test_msg->stec_sat_list[7].stec_quality_indicator = 177; + test_msg->stec_sat_list[7].sv_id.constellation = 79; + test_msg->stec_sat_list[7].sv_id.satId = 113; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[0] = 5448; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[1] = -11359; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[2] = 5574; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[8].stec_coeff[0]); + } + test_msg->stec_sat_list[8].stec_coeff[3] = 28654; + test_msg->stec_sat_list[8].stec_quality_indicator = 249; + test_msg->stec_sat_list[8].sv_id.constellation = 100; + test_msg->stec_sat_list[8].sv_id.satId = 210; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[0] = -10783; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[1] = 18179; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[2] = 16371; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[9].stec_coeff[0]); + } + test_msg->stec_sat_list[9].stec_coeff[3] = -5055; + test_msg->stec_sat_list[9].stec_quality_indicator = 227; + test_msg->stec_sat_list[9].sv_id.constellation = 36; + test_msg->stec_sat_list[9].sv_id.satId = 107; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[0] = 4009; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[1] = 1462; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[2] = -19216; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[10].stec_coeff[0]); + } + test_msg->stec_sat_list[10].stec_coeff[3] = 31241; + test_msg->stec_sat_list[10].stec_quality_indicator = 0; + test_msg->stec_sat_list[10].sv_id.constellation = 77; + test_msg->stec_sat_list[10].sv_id.satId = 92; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[0] = 26727; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[1] = -16898; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[2] = 28241; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[11].stec_coeff[0]); + } + test_msg->stec_sat_list[11].stec_coeff[3] = 12546; + test_msg->stec_sat_list[11].stec_quality_indicator = 6; + test_msg->stec_sat_list[11].sv_id.constellation = 232; + test_msg->stec_sat_list[11].sv_id.satId = 86; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[0] = 12855; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[1] = 1461; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[2] = 20603; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[12].stec_coeff[0]); + } + test_msg->stec_sat_list[12].stec_coeff[3] = -3023; + test_msg->stec_sat_list[12].stec_quality_indicator = 216; + test_msg->stec_sat_list[12].sv_id.constellation = 84; + test_msg->stec_sat_list[12].sv_id.satId = 202; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[0] = -6492; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[1] = 16952; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[2] = -22404; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[13].stec_coeff[0]); + } + test_msg->stec_sat_list[13].stec_coeff[3] = -29893; + test_msg->stec_sat_list[13].stec_quality_indicator = 125; + test_msg->stec_sat_list[13].sv_id.constellation = 188; + test_msg->stec_sat_list[13].sv_id.satId = 224; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[0] = -10053; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[1] = -24897; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[2] = 23629; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[14].stec_coeff[0]); + } + test_msg->stec_sat_list[14].stec_coeff[3] = -710; + test_msg->stec_sat_list[14].stec_quality_indicator = 51; + test_msg->stec_sat_list[14].sv_id.constellation = 118; + test_msg->stec_sat_list[14].sv_id.satId = 106; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[0] = -26103; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[1] = -9539; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[2] = -11971; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[15].stec_coeff[0]); + } + test_msg->stec_sat_list[15].stec_coeff[3] = 20993; + test_msg->stec_sat_list[15].stec_quality_indicator = 165; + test_msg->stec_sat_list[15].sv_id.constellation = 150; + test_msg->stec_sat_list[15].sv_id.satId = 132; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[0] = -18891; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[1] = -16272; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[2] = -22578; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[16].stec_coeff[0]); + } + test_msg->stec_sat_list[16].stec_coeff[3] = -2915; + test_msg->stec_sat_list[16].stec_quality_indicator = 23; + test_msg->stec_sat_list[16].sv_id.constellation = 196; + test_msg->stec_sat_list[16].sv_id.satId = 181; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[0] = 15833; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[1] = 24920; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[2] = -13879; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[17].stec_coeff[0]); + } + test_msg->stec_sat_list[17].stec_coeff[3] = -1206; + test_msg->stec_sat_list[17].stec_quality_indicator = 189; + test_msg->stec_sat_list[17].sv_id.constellation = 1; + test_msg->stec_sat_list[17].sv_id.satId = 35; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[0] = 14008; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[1] = 18996; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[2] = 2798; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[18].stec_coeff[0]); + } + test_msg->stec_sat_list[18].stec_coeff[3] = 5761; + test_msg->stec_sat_list[18].stec_quality_indicator = 104; + test_msg->stec_sat_list[18].sv_id.constellation = 14; + test_msg->stec_sat_list[18].sv_id.satId = 217; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[0] = -25256; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[1] = -15330; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[2] = 6831; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[19].stec_coeff[0]); + } + test_msg->stec_sat_list[19].stec_coeff[3] = 8780; + test_msg->stec_sat_list[19].stec_quality_indicator = 109; + test_msg->stec_sat_list[19].sv_id.constellation = 226; + test_msg->stec_sat_list[19].sv_id.satId = 178; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[0] = 3304; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[1] = -2893; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[2] = -25841; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[20].stec_coeff[0]); + } + test_msg->stec_sat_list[20].stec_coeff[3] = -13628; + test_msg->stec_sat_list[20].stec_quality_indicator = 154; + test_msg->stec_sat_list[20].sv_id.constellation = 220; + test_msg->stec_sat_list[20].sv_id.satId = 116; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[0]); + } + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[21].stec_coeff[0]); + } + test_msg->stec_sat_list[21].stec_coeff[0] = -10742; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[21].stec_coeff[0]); + } + test_msg->stec_sat_list[21].stec_coeff[1] = 10098; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[21].stec_coeff[0]); + } + test_msg->stec_sat_list[21].stec_coeff[2] = 7413; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->stec_sat_list[21].stec_coeff[0]); + } + test_msg->stec_sat_list[21].stec_coeff[3] = 17645; + test_msg->stec_sat_list[21].stec_quality_indicator = 115; + test_msg->stec_sat_list[21].sv_id.constellation = 70; + test_msg->stec_sat_list[21].sv_id.satId = 72; + sbp_payload_send(&sbp_state, 0x5eb, 1831, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 1831, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 1831, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5eb, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_stec_correction_dep_a_t *check_msg = + (msg_ssr_stec_correction_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->header.iod_atmo == 4, + "incorrect value for header.iod_atmo, expected 4, is %d", + check_msg->header.iod_atmo); + ck_assert_msg(check_msg->header.num_msgs == 147, + "incorrect value for header.num_msgs, expected 147, is %d", + check_msg->header.num_msgs); + ck_assert_msg(check_msg->header.seq_num == 123, + "incorrect value for header.seq_num, expected 123, is %d", + check_msg->header.seq_num); + ck_assert_msg( + check_msg->header.time.tow == 3905179974, + "incorrect value for header.time.tow, expected 3905179974, is %d", + check_msg->header.time.tow); + ck_assert_msg(check_msg->header.time.wn == 11193, + "incorrect value for header.time.wn, expected 11193, is %d", + check_msg->header.time.wn); + ck_assert_msg( + check_msg->header.update_interval == 39, + "incorrect value for header.update_interval, expected 39, is %d", + check_msg->header.update_interval); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[0] == -1951, + "incorrect value for stec_sat_list[0].stec_coeff[0], " + "expected -1951, is %d", + check_msg->stec_sat_list[0].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[1] == -9854, + "incorrect value for stec_sat_list[0].stec_coeff[1], " + "expected -9854, is %d", + check_msg->stec_sat_list[0].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[2] == 27353, + "incorrect value for stec_sat_list[0].stec_coeff[2], " + "expected 27353, is %d", + check_msg->stec_sat_list[0].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[0].stec_coeff[3] == 3130, + "incorrect value for stec_sat_list[0].stec_coeff[3], " + "expected 3130, is %d", + check_msg->stec_sat_list[0].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[0].stec_quality_indicator == 111, + "incorrect value for stec_sat_list[0].stec_quality_indicator, expected " + "111, is %d", + check_msg->stec_sat_list[0].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[0].sv_id.constellation == 19, + "incorrect value for stec_sat_list[0].sv_id.constellation, " + "expected 19, is %d", + check_msg->stec_sat_list[0].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[0].sv_id.satId == 126, + "incorrect value for stec_sat_list[0].sv_id.satId, expected 126, is %d", + check_msg->stec_sat_list[0].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[0] == 24401, + "incorrect value for stec_sat_list[1].stec_coeff[0], " + "expected 24401, is %d", + check_msg->stec_sat_list[1].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[1] == 4182, + "incorrect value for stec_sat_list[1].stec_coeff[1], " + "expected 4182, is %d", + check_msg->stec_sat_list[1].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[2] == 21543, + "incorrect value for stec_sat_list[1].stec_coeff[2], " + "expected 21543, is %d", + check_msg->stec_sat_list[1].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[1].stec_coeff[3] == -12060, + "incorrect value for stec_sat_list[1].stec_coeff[3], " + "expected -12060, is %d", + check_msg->stec_sat_list[1].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[1].stec_quality_indicator == 171, + "incorrect value for stec_sat_list[1].stec_quality_indicator, expected " + "171, is %d", + check_msg->stec_sat_list[1].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[1].sv_id.constellation == 230, + "incorrect value for stec_sat_list[1].sv_id.constellation, " + "expected 230, is %d", + check_msg->stec_sat_list[1].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[1].sv_id.satId == 65, + "incorrect value for stec_sat_list[1].sv_id.satId, expected 65, is %d", + check_msg->stec_sat_list[1].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[0] == -13469, + "incorrect value for stec_sat_list[2].stec_coeff[0], " + "expected -13469, is %d", + check_msg->stec_sat_list[2].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[1] == -18883, + "incorrect value for stec_sat_list[2].stec_coeff[1], " + "expected -18883, is %d", + check_msg->stec_sat_list[2].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[2] == 32066, + "incorrect value for stec_sat_list[2].stec_coeff[2], " + "expected 32066, is %d", + check_msg->stec_sat_list[2].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[2].stec_coeff[3] == 971, + "incorrect value for stec_sat_list[2].stec_coeff[3], " + "expected 971, is %d", + check_msg->stec_sat_list[2].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[2].stec_quality_indicator == 219, + "incorrect value for stec_sat_list[2].stec_quality_indicator, expected " + "219, is %d", + check_msg->stec_sat_list[2].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[2].sv_id.constellation == 81, + "incorrect value for stec_sat_list[2].sv_id.constellation, " + "expected 81, is %d", + check_msg->stec_sat_list[2].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[2].sv_id.satId == 201, + "incorrect value for stec_sat_list[2].sv_id.satId, expected 201, is %d", + check_msg->stec_sat_list[2].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[0] == 32220, + "incorrect value for stec_sat_list[3].stec_coeff[0], " + "expected 32220, is %d", + check_msg->stec_sat_list[3].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[1] == 5436, + "incorrect value for stec_sat_list[3].stec_coeff[1], " + "expected 5436, is %d", + check_msg->stec_sat_list[3].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[2] == -9635, + "incorrect value for stec_sat_list[3].stec_coeff[2], " + "expected -9635, is %d", + check_msg->stec_sat_list[3].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[3].stec_coeff[3] == -24841, + "incorrect value for stec_sat_list[3].stec_coeff[3], " + "expected -24841, is %d", + check_msg->stec_sat_list[3].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[3].stec_quality_indicator == 100, + "incorrect value for stec_sat_list[3].stec_quality_indicator, expected " + "100, is %d", + check_msg->stec_sat_list[3].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[3].sv_id.constellation == 44, + "incorrect value for stec_sat_list[3].sv_id.constellation, " + "expected 44, is %d", + check_msg->stec_sat_list[3].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[3].sv_id.satId == 193, + "incorrect value for stec_sat_list[3].sv_id.satId, expected 193, is %d", + check_msg->stec_sat_list[3].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[0] == 3718, + "incorrect value for stec_sat_list[4].stec_coeff[0], " + "expected 3718, is %d", + check_msg->stec_sat_list[4].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[1] == 12497, + "incorrect value for stec_sat_list[4].stec_coeff[1], " + "expected 12497, is %d", + check_msg->stec_sat_list[4].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[2] == -10482, + "incorrect value for stec_sat_list[4].stec_coeff[2], " + "expected -10482, is %d", + check_msg->stec_sat_list[4].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[4].stec_coeff[3] == -27495, + "incorrect value for stec_sat_list[4].stec_coeff[3], " + "expected -27495, is %d", + check_msg->stec_sat_list[4].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[4].stec_quality_indicator == 129, + "incorrect value for stec_sat_list[4].stec_quality_indicator, expected " + "129, is %d", + check_msg->stec_sat_list[4].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[4].sv_id.constellation == 93, + "incorrect value for stec_sat_list[4].sv_id.constellation, " + "expected 93, is %d", + check_msg->stec_sat_list[4].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[4].sv_id.satId == 207, + "incorrect value for stec_sat_list[4].sv_id.satId, expected 207, is %d", + check_msg->stec_sat_list[4].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[0] == -4940, + "incorrect value for stec_sat_list[5].stec_coeff[0], " + "expected -4940, is %d", + check_msg->stec_sat_list[5].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[1] == -13875, + "incorrect value for stec_sat_list[5].stec_coeff[1], " + "expected -13875, is %d", + check_msg->stec_sat_list[5].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[2] == 801, + "incorrect value for stec_sat_list[5].stec_coeff[2], " + "expected 801, is %d", + check_msg->stec_sat_list[5].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[5].stec_coeff[3] == -13066, + "incorrect value for stec_sat_list[5].stec_coeff[3], " + "expected -13066, is %d", + check_msg->stec_sat_list[5].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[5].stec_quality_indicator == 225, + "incorrect value for stec_sat_list[5].stec_quality_indicator, expected " + "225, is %d", + check_msg->stec_sat_list[5].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[5].sv_id.constellation == 72, + "incorrect value for stec_sat_list[5].sv_id.constellation, " + "expected 72, is %d", + check_msg->stec_sat_list[5].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[5].sv_id.satId == 147, + "incorrect value for stec_sat_list[5].sv_id.satId, expected 147, is %d", + check_msg->stec_sat_list[5].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[0] == -15868, + "incorrect value for stec_sat_list[6].stec_coeff[0], " + "expected -15868, is %d", + check_msg->stec_sat_list[6].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[1] == -2369, + "incorrect value for stec_sat_list[6].stec_coeff[1], " + "expected -2369, is %d", + check_msg->stec_sat_list[6].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[2] == -9396, + "incorrect value for stec_sat_list[6].stec_coeff[2], " + "expected -9396, is %d", + check_msg->stec_sat_list[6].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_coeff[3] == -16609, + "incorrect value for stec_sat_list[6].stec_coeff[3], " + "expected -16609, is %d", + check_msg->stec_sat_list[6].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[6].stec_quality_indicator == 98, + "incorrect value for " + "stec_sat_list[6].stec_quality_indicator, expected 98, is %d", + check_msg->stec_sat_list[6].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[6].sv_id.constellation == 3, + "incorrect value for stec_sat_list[6].sv_id.constellation, " + "expected 3, is %d", + check_msg->stec_sat_list[6].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[6].sv_id.satId == 19, + "incorrect value for stec_sat_list[6].sv_id.satId, expected 19, is %d", + check_msg->stec_sat_list[6].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[0] == -1265, + "incorrect value for stec_sat_list[7].stec_coeff[0], " + "expected -1265, is %d", + check_msg->stec_sat_list[7].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[1] == 4897, + "incorrect value for stec_sat_list[7].stec_coeff[1], " + "expected 4897, is %d", + check_msg->stec_sat_list[7].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[2] == 13920, + "incorrect value for stec_sat_list[7].stec_coeff[2], " + "expected 13920, is %d", + check_msg->stec_sat_list[7].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[7].stec_coeff[3] == -28102, + "incorrect value for stec_sat_list[7].stec_coeff[3], " + "expected -28102, is %d", + check_msg->stec_sat_list[7].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[7].stec_quality_indicator == 177, + "incorrect value for stec_sat_list[7].stec_quality_indicator, expected " + "177, is %d", + check_msg->stec_sat_list[7].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[7].sv_id.constellation == 79, + "incorrect value for stec_sat_list[7].sv_id.constellation, " + "expected 79, is %d", + check_msg->stec_sat_list[7].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[7].sv_id.satId == 113, + "incorrect value for stec_sat_list[7].sv_id.satId, expected 113, is %d", + check_msg->stec_sat_list[7].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[0] == 5448, + "incorrect value for stec_sat_list[8].stec_coeff[0], " + "expected 5448, is %d", + check_msg->stec_sat_list[8].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[1] == -11359, + "incorrect value for stec_sat_list[8].stec_coeff[1], " + "expected -11359, is %d", + check_msg->stec_sat_list[8].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[2] == 5574, + "incorrect value for stec_sat_list[8].stec_coeff[2], " + "expected 5574, is %d", + check_msg->stec_sat_list[8].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[8].stec_coeff[3] == 28654, + "incorrect value for stec_sat_list[8].stec_coeff[3], " + "expected 28654, is %d", + check_msg->stec_sat_list[8].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[8].stec_quality_indicator == 249, + "incorrect value for stec_sat_list[8].stec_quality_indicator, expected " + "249, is %d", + check_msg->stec_sat_list[8].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[8].sv_id.constellation == 100, + "incorrect value for stec_sat_list[8].sv_id.constellation, " + "expected 100, is %d", + check_msg->stec_sat_list[8].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[8].sv_id.satId == 210, + "incorrect value for stec_sat_list[8].sv_id.satId, expected 210, is %d", + check_msg->stec_sat_list[8].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[0] == -10783, + "incorrect value for stec_sat_list[9].stec_coeff[0], " + "expected -10783, is %d", + check_msg->stec_sat_list[9].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[1] == 18179, + "incorrect value for stec_sat_list[9].stec_coeff[1], " + "expected 18179, is %d", + check_msg->stec_sat_list[9].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[2] == 16371, + "incorrect value for stec_sat_list[9].stec_coeff[2], " + "expected 16371, is %d", + check_msg->stec_sat_list[9].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[9].stec_coeff[3] == -5055, + "incorrect value for stec_sat_list[9].stec_coeff[3], " + "expected -5055, is %d", + check_msg->stec_sat_list[9].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[9].stec_quality_indicator == 227, + "incorrect value for stec_sat_list[9].stec_quality_indicator, expected " + "227, is %d", + check_msg->stec_sat_list[9].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[9].sv_id.constellation == 36, + "incorrect value for stec_sat_list[9].sv_id.constellation, " + "expected 36, is %d", + check_msg->stec_sat_list[9].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[9].sv_id.satId == 107, + "incorrect value for stec_sat_list[9].sv_id.satId, expected 107, is %d", + check_msg->stec_sat_list[9].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[0] == 4009, + "incorrect value for stec_sat_list[10].stec_coeff[0], " + "expected 4009, is %d", + check_msg->stec_sat_list[10].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[1] == 1462, + "incorrect value for stec_sat_list[10].stec_coeff[1], " + "expected 1462, is %d", + check_msg->stec_sat_list[10].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[2] == -19216, + "incorrect value for stec_sat_list[10].stec_coeff[2], " + "expected -19216, is %d", + check_msg->stec_sat_list[10].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_coeff[3] == 31241, + "incorrect value for stec_sat_list[10].stec_coeff[3], " + "expected 31241, is %d", + check_msg->stec_sat_list[10].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[10].stec_quality_indicator == 0, + "incorrect value for " + "stec_sat_list[10].stec_quality_indicator, expected 0, is %d", + check_msg->stec_sat_list[10].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[10].sv_id.constellation == 77, + "incorrect value for stec_sat_list[10].sv_id.constellation, " + "expected 77, is %d", + check_msg->stec_sat_list[10].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[10].sv_id.satId == 92, + "incorrect value for stec_sat_list[10].sv_id.satId, expected 92, is %d", + check_msg->stec_sat_list[10].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[0] == 26727, + "incorrect value for stec_sat_list[11].stec_coeff[0], " + "expected 26727, is %d", + check_msg->stec_sat_list[11].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[1] == -16898, + "incorrect value for stec_sat_list[11].stec_coeff[1], " + "expected -16898, is %d", + check_msg->stec_sat_list[11].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[2] == 28241, + "incorrect value for stec_sat_list[11].stec_coeff[2], " + "expected 28241, is %d", + check_msg->stec_sat_list[11].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_coeff[3] == 12546, + "incorrect value for stec_sat_list[11].stec_coeff[3], " + "expected 12546, is %d", + check_msg->stec_sat_list[11].stec_coeff[3]); + ck_assert_msg(check_msg->stec_sat_list[11].stec_quality_indicator == 6, + "incorrect value for " + "stec_sat_list[11].stec_quality_indicator, expected 6, is %d", + check_msg->stec_sat_list[11].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[11].sv_id.constellation == 232, + "incorrect value for stec_sat_list[11].sv_id.constellation, " + "expected 232, is %d", + check_msg->stec_sat_list[11].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[11].sv_id.satId == 86, + "incorrect value for stec_sat_list[11].sv_id.satId, expected 86, is %d", + check_msg->stec_sat_list[11].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[0] == 12855, + "incorrect value for stec_sat_list[12].stec_coeff[0], " + "expected 12855, is %d", + check_msg->stec_sat_list[12].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[1] == 1461, + "incorrect value for stec_sat_list[12].stec_coeff[1], " + "expected 1461, is %d", + check_msg->stec_sat_list[12].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[2] == 20603, + "incorrect value for stec_sat_list[12].stec_coeff[2], " + "expected 20603, is %d", + check_msg->stec_sat_list[12].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[12].stec_coeff[3] == -3023, + "incorrect value for stec_sat_list[12].stec_coeff[3], " + "expected -3023, is %d", + check_msg->stec_sat_list[12].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[12].stec_quality_indicator == 216, + "incorrect value for stec_sat_list[12].stec_quality_indicator, " + "expected 216, is %d", + check_msg->stec_sat_list[12].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[12].sv_id.constellation == 84, + "incorrect value for stec_sat_list[12].sv_id.constellation, " + "expected 84, is %d", + check_msg->stec_sat_list[12].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[12].sv_id.satId == 202, + "incorrect value for stec_sat_list[12].sv_id.satId, expected " + "202, is %d", + check_msg->stec_sat_list[12].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[0] == -6492, + "incorrect value for stec_sat_list[13].stec_coeff[0], " + "expected -6492, is %d", + check_msg->stec_sat_list[13].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[1] == 16952, + "incorrect value for stec_sat_list[13].stec_coeff[1], " + "expected 16952, is %d", + check_msg->stec_sat_list[13].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[2] == -22404, + "incorrect value for stec_sat_list[13].stec_coeff[2], " + "expected -22404, is %d", + check_msg->stec_sat_list[13].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[13].stec_coeff[3] == -29893, + "incorrect value for stec_sat_list[13].stec_coeff[3], " + "expected -29893, is %d", + check_msg->stec_sat_list[13].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[13].stec_quality_indicator == 125, + "incorrect value for stec_sat_list[13].stec_quality_indicator, " + "expected 125, is %d", + check_msg->stec_sat_list[13].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[13].sv_id.constellation == 188, + "incorrect value for stec_sat_list[13].sv_id.constellation, " + "expected 188, is %d", + check_msg->stec_sat_list[13].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[13].sv_id.satId == 224, + "incorrect value for stec_sat_list[13].sv_id.satId, expected " + "224, is %d", + check_msg->stec_sat_list[13].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[0] == -10053, + "incorrect value for stec_sat_list[14].stec_coeff[0], " + "expected -10053, is %d", + check_msg->stec_sat_list[14].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[1] == -24897, + "incorrect value for stec_sat_list[14].stec_coeff[1], " + "expected -24897, is %d", + check_msg->stec_sat_list[14].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[2] == 23629, + "incorrect value for stec_sat_list[14].stec_coeff[2], " + "expected 23629, is %d", + check_msg->stec_sat_list[14].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[14].stec_coeff[3] == -710, + "incorrect value for stec_sat_list[14].stec_coeff[3], " + "expected -710, is %d", + check_msg->stec_sat_list[14].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[14].stec_quality_indicator == 51, + "incorrect value for stec_sat_list[14].stec_quality_indicator, " + "expected 51, is %d", + check_msg->stec_sat_list[14].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[14].sv_id.constellation == 118, + "incorrect value for stec_sat_list[14].sv_id.constellation, " + "expected 118, is %d", + check_msg->stec_sat_list[14].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[14].sv_id.satId == 106, + "incorrect value for stec_sat_list[14].sv_id.satId, expected " + "106, is %d", + check_msg->stec_sat_list[14].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[0] == -26103, + "incorrect value for stec_sat_list[15].stec_coeff[0], " + "expected -26103, is %d", + check_msg->stec_sat_list[15].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[1] == -9539, + "incorrect value for stec_sat_list[15].stec_coeff[1], " + "expected -9539, is %d", + check_msg->stec_sat_list[15].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[2] == -11971, + "incorrect value for stec_sat_list[15].stec_coeff[2], " + "expected -11971, is %d", + check_msg->stec_sat_list[15].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[15].stec_coeff[3] == 20993, + "incorrect value for stec_sat_list[15].stec_coeff[3], " + "expected 20993, is %d", + check_msg->stec_sat_list[15].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[15].stec_quality_indicator == 165, + "incorrect value for stec_sat_list[15].stec_quality_indicator, " + "expected 165, is %d", + check_msg->stec_sat_list[15].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[15].sv_id.constellation == 150, + "incorrect value for stec_sat_list[15].sv_id.constellation, " + "expected 150, is %d", + check_msg->stec_sat_list[15].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[15].sv_id.satId == 132, + "incorrect value for stec_sat_list[15].sv_id.satId, expected " + "132, is %d", + check_msg->stec_sat_list[15].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[0] == -18891, + "incorrect value for stec_sat_list[16].stec_coeff[0], " + "expected -18891, is %d", + check_msg->stec_sat_list[16].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[1] == -16272, + "incorrect value for stec_sat_list[16].stec_coeff[1], " + "expected -16272, is %d", + check_msg->stec_sat_list[16].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[2] == -22578, + "incorrect value for stec_sat_list[16].stec_coeff[2], " + "expected -22578, is %d", + check_msg->stec_sat_list[16].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[16].stec_coeff[3] == -2915, + "incorrect value for stec_sat_list[16].stec_coeff[3], " + "expected -2915, is %d", + check_msg->stec_sat_list[16].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[16].stec_quality_indicator == 23, + "incorrect value for stec_sat_list[16].stec_quality_indicator, " + "expected 23, is %d", + check_msg->stec_sat_list[16].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[16].sv_id.constellation == 196, + "incorrect value for stec_sat_list[16].sv_id.constellation, " + "expected 196, is %d", + check_msg->stec_sat_list[16].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[16].sv_id.satId == 181, + "incorrect value for stec_sat_list[16].sv_id.satId, expected " + "181, is %d", + check_msg->stec_sat_list[16].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[0] == 15833, + "incorrect value for stec_sat_list[17].stec_coeff[0], " + "expected 15833, is %d", + check_msg->stec_sat_list[17].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[1] == 24920, + "incorrect value for stec_sat_list[17].stec_coeff[1], " + "expected 24920, is %d", + check_msg->stec_sat_list[17].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[2] == -13879, + "incorrect value for stec_sat_list[17].stec_coeff[2], " + "expected -13879, is %d", + check_msg->stec_sat_list[17].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[17].stec_coeff[3] == -1206, + "incorrect value for stec_sat_list[17].stec_coeff[3], " + "expected -1206, is %d", + check_msg->stec_sat_list[17].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[17].stec_quality_indicator == 189, + "incorrect value for stec_sat_list[17].stec_quality_indicator, " + "expected 189, is %d", + check_msg->stec_sat_list[17].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[17].sv_id.constellation == 1, + "incorrect value for stec_sat_list[17].sv_id.constellation, " + "expected 1, is %d", + check_msg->stec_sat_list[17].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[17].sv_id.satId == 35, + "incorrect value for stec_sat_list[17].sv_id.satId, expected 35, is %d", + check_msg->stec_sat_list[17].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[0] == 14008, + "incorrect value for stec_sat_list[18].stec_coeff[0], " + "expected 14008, is %d", + check_msg->stec_sat_list[18].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[1] == 18996, + "incorrect value for stec_sat_list[18].stec_coeff[1], " + "expected 18996, is %d", + check_msg->stec_sat_list[18].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[2] == 2798, + "incorrect value for stec_sat_list[18].stec_coeff[2], " + "expected 2798, is %d", + check_msg->stec_sat_list[18].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[18].stec_coeff[3] == 5761, + "incorrect value for stec_sat_list[18].stec_coeff[3], " + "expected 5761, is %d", + check_msg->stec_sat_list[18].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[18].stec_quality_indicator == 104, + "incorrect value for stec_sat_list[18].stec_quality_indicator, " + "expected 104, is %d", + check_msg->stec_sat_list[18].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[18].sv_id.constellation == 14, + "incorrect value for stec_sat_list[18].sv_id.constellation, " + "expected 14, is %d", + check_msg->stec_sat_list[18].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[18].sv_id.satId == 217, + "incorrect value for stec_sat_list[18].sv_id.satId, expected " + "217, is %d", + check_msg->stec_sat_list[18].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[0] == -25256, + "incorrect value for stec_sat_list[19].stec_coeff[0], " + "expected -25256, is %d", + check_msg->stec_sat_list[19].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[1] == -15330, + "incorrect value for stec_sat_list[19].stec_coeff[1], " + "expected -15330, is %d", + check_msg->stec_sat_list[19].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[2] == 6831, + "incorrect value for stec_sat_list[19].stec_coeff[2], " + "expected 6831, is %d", + check_msg->stec_sat_list[19].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[19].stec_coeff[3] == 8780, + "incorrect value for stec_sat_list[19].stec_coeff[3], " + "expected 8780, is %d", + check_msg->stec_sat_list[19].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[19].stec_quality_indicator == 109, + "incorrect value for stec_sat_list[19].stec_quality_indicator, " + "expected 109, is %d", + check_msg->stec_sat_list[19].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[19].sv_id.constellation == 226, + "incorrect value for stec_sat_list[19].sv_id.constellation, " + "expected 226, is %d", + check_msg->stec_sat_list[19].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[19].sv_id.satId == 178, + "incorrect value for stec_sat_list[19].sv_id.satId, expected " + "178, is %d", + check_msg->stec_sat_list[19].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[0] == 3304, + "incorrect value for stec_sat_list[20].stec_coeff[0], " + "expected 3304, is %d", + check_msg->stec_sat_list[20].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[1] == -2893, + "incorrect value for stec_sat_list[20].stec_coeff[1], " + "expected -2893, is %d", + check_msg->stec_sat_list[20].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[2] == -25841, + "incorrect value for stec_sat_list[20].stec_coeff[2], " + "expected -25841, is %d", + check_msg->stec_sat_list[20].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[20].stec_coeff[3] == -13628, + "incorrect value for stec_sat_list[20].stec_coeff[3], " + "expected -13628, is %d", + check_msg->stec_sat_list[20].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[20].stec_quality_indicator == 154, + "incorrect value for stec_sat_list[20].stec_quality_indicator, " + "expected 154, is %d", + check_msg->stec_sat_list[20].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[20].sv_id.constellation == 220, + "incorrect value for stec_sat_list[20].sv_id.constellation, " + "expected 220, is %d", + check_msg->stec_sat_list[20].sv_id.constellation); + ck_assert_msg(check_msg->stec_sat_list[20].sv_id.satId == 116, + "incorrect value for stec_sat_list[20].sv_id.satId, expected " + "116, is %d", + check_msg->stec_sat_list[20].sv_id.satId); + ck_assert_msg(check_msg->stec_sat_list[21].stec_coeff[0] == -10742, + "incorrect value for stec_sat_list[21].stec_coeff[0], " + "expected -10742, is %d", + check_msg->stec_sat_list[21].stec_coeff[0]); + ck_assert_msg(check_msg->stec_sat_list[21].stec_coeff[1] == 10098, + "incorrect value for stec_sat_list[21].stec_coeff[1], " + "expected 10098, is %d", + check_msg->stec_sat_list[21].stec_coeff[1]); + ck_assert_msg(check_msg->stec_sat_list[21].stec_coeff[2] == 7413, + "incorrect value for stec_sat_list[21].stec_coeff[2], " + "expected 7413, is %d", + check_msg->stec_sat_list[21].stec_coeff[2]); + ck_assert_msg(check_msg->stec_sat_list[21].stec_coeff[3] == 17645, + "incorrect value for stec_sat_list[21].stec_coeff[3], " + "expected 17645, is %d", + check_msg->stec_sat_list[21].stec_coeff[3]); + ck_assert_msg( + check_msg->stec_sat_list[21].stec_quality_indicator == 115, + "incorrect value for stec_sat_list[21].stec_quality_indicator, " + "expected 115, is %d", + check_msg->stec_sat_list[21].stec_quality_indicator); + ck_assert_msg(check_msg->stec_sat_list[21].sv_id.constellation == 70, + "incorrect value for stec_sat_list[21].sv_id.constellation, " + "expected 70, is %d", + check_msg->stec_sat_list[21].sv_id.constellation); + ck_assert_msg( + check_msg->stec_sat_list[21].sv_id.satId == 72, + "incorrect value for stec_sat_list[21].sv_id.satId, expected 72, is %d", + check_msg->stec_sat_list[21].sv_id.satId); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c b/c/test/legacy/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c new file mode 100644 index 0000000000..a04a0548c9 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.c @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x5f6, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x5f6, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, + 185, 9, 181, 162, 240, 65, 19, 255, 143, 21, 191, + 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_ssr_tile_definition_dep_a_t *test_msg = + (msg_ssr_tile_definition_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->bitmask = 11259375; + test_msg->cols = 48917; + test_msg->corner_nw_lat = -18168; + test_msg->corner_nw_lon = -19191; + test_msg->rows = 36863; + test_msg->spacing_lat = 61602; + test_msg->spacing_lon = 4929; + test_msg->tile_id = 63410; + test_msg->tile_set_id = 48697; + sbp_payload_send(&sbp_state, 0x5f6, 34248, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 34248, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 34248, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x5f6, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_ssr_tile_definition_dep_a_t *check_msg = + (msg_ssr_tile_definition_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->bitmask == 11259375, + "incorrect value for bitmask, expected 11259375, is %d", + check_msg->bitmask); + ck_assert_msg(check_msg->cols == 48917, + "incorrect value for cols, expected 48917, is %d", + check_msg->cols); + ck_assert_msg(check_msg->corner_nw_lat == -18168, + "incorrect value for corner_nw_lat, expected -18168, is %d", + check_msg->corner_nw_lat); + ck_assert_msg(check_msg->corner_nw_lon == -19191, + "incorrect value for corner_nw_lon, expected -19191, is %d", + check_msg->corner_nw_lon); + ck_assert_msg(check_msg->rows == 36863, + "incorrect value for rows, expected 36863, is %d", + check_msg->rows); + ck_assert_msg(check_msg->spacing_lat == 61602, + "incorrect value for spacing_lat, expected 61602, is %d", + check_msg->spacing_lat); + ck_assert_msg(check_msg->spacing_lon == 4929, + "incorrect value for spacing_lon, expected 4929, is %d", + check_msg->spacing_lon); + ck_assert_msg(check_msg->tile_id == 63410, + "incorrect value for tile_id, expected 63410, is %d", + check_msg->tile_id); + ck_assert_msg(check_msg->tile_set_id == 48697, + "incorrect value for tile_set_id, expected 48697, is %d", + check_msg->tile_set_id); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetry.c b/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetry.c new file mode 100644 index 0000000000..532fe570c0 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetry.c @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_system_MsgCsacTelemetry) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff04, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff04, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 4, 255, 244, 169, 10, 105, 115, 111, + 109, 101, 32, 100, 97, 116, 97, 229, 94, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_csac_telemetry_t *test_msg = (msg_csac_telemetry_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->id = 105; + { + const char assign_string[] = {(char)115, (char)111, (char)109, + (char)101, (char)32, (char)100, + (char)97, (char)116, (char)97}; + memcpy(test_msg->telemetry, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->telemetry) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xff04, 43508, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 43508, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 43508, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff04, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_csac_telemetry_t *check_msg = + (msg_csac_telemetry_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->id == 105, + "incorrect value for id, expected 105, is %d", check_msg->id); + { + const char check_string[] = {(char)115, (char)111, (char)109, + (char)101, (char)32, (char)100, + (char)97, (char)116, (char)97}; + ck_assert_msg( + memcmp(check_msg->telemetry, check_string, sizeof(check_string)) == 0, + "incorrect value for check_msg->telemetry, expected string '%s', is " + "'%s'", + check_string, check_msg->telemetry); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_system_MsgCsacTelemetry_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_system_MsgCsacTelemetry"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_system_MsgCsacTelemetry"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_system_MsgCsacTelemetry); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetryLabels.c b/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetryLabels.c new file mode 100644 index 0000000000..aa4c558c10 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_system_MsgCsacTelemetryLabels.c @@ -0,0 +1,228 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff05, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff05, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, + 101, 32, 108, 97, 98, 101, 108, 115, 86, 236, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_csac_telemetry_labels_t *test_msg = + (msg_csac_telemetry_labels_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->id = 186; + { + const char assign_string[] = {(char)115, (char)111, (char)109, (char)101, + (char)32, (char)108, (char)97, (char)98, + (char)101, (char)108, (char)115}; + memcpy(test_msg->telemetry_labels, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->telemetry_labels) == 0) { + test_msg_len += sizeof(assign_string); + } + } + sbp_payload_send(&sbp_state, 0xff05, 51291, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 51291, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 51291, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff05, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_csac_telemetry_labels_t *check_msg = + (msg_csac_telemetry_labels_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->id == 186, + "incorrect value for id, expected 186, is %d", check_msg->id); + { + const char check_string[] = {(char)115, (char)111, (char)109, (char)101, + (char)32, (char)108, (char)97, (char)98, + (char)101, (char)108, (char)115}; + ck_assert_msg(memcmp(check_msg->telemetry_labels, check_string, + sizeof(check_string)) == 0, + "incorrect value for check_msg->telemetry_labels, expected " + "string '%s', is '%s'", + check_string, check_msg->telemetry_labels); + } + } +} +END_TEST + +Suite *legacy_auto_check_sbp_system_MsgCsacTelemetryLabels_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_system_MsgCsacTelemetryLabels"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_system_MsgGnssTimeOffset.c b/c/test/legacy/auto_check_sbp_system_MsgGnssTimeOffset.c new file mode 100644 index 0000000000..ae41601f9a --- /dev/null +++ b/c/test/legacy/auto_check_sbp_system_MsgGnssTimeOffset.c @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_system_MsgGnssTimeOffset) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff07, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff07, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_gnss_time_offset_t *test_msg = + (msg_gnss_time_offset_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 221; + test_msg->microseconds = 9494; + test_msg->milliseconds = 1728664402; + test_msg->weeks = 14857; + sbp_payload_send(&sbp_state, 0xff07, 3862, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 3862, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 3862, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff07, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_gnss_time_offset_t *check_msg = + (msg_gnss_time_offset_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 221, + "incorrect value for flags, expected 221, is %d", + check_msg->flags); + ck_assert_msg(check_msg->microseconds == 9494, + "incorrect value for microseconds, expected 9494, is %d", + check_msg->microseconds); + ck_assert_msg( + check_msg->milliseconds == 1728664402, + "incorrect value for milliseconds, expected 1728664402, is %d", + check_msg->milliseconds); + ck_assert_msg(check_msg->weeks == 14857, + "incorrect value for weeks, expected 14857, is %d", + check_msg->weeks); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_system_MsgGnssTimeOffset_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_system_MsgGnssTimeOffset"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_system_MsgGnssTimeOffset"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_system_MsgGnssTimeOffset); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_system_MsgPpsTime.c b/c/test/legacy/auto_check_sbp_system_MsgPpsTime.c new file mode 100644 index 0000000000..a172cb7136 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_system_MsgPpsTime.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_system_MsgPpsTime) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xff08, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xff08, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 8, 255, 222, 209, 9, 140, 146, 133, + 197, 160, 0, 0, 0, 255, 125, 149, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_pps_time_t *test_msg = (msg_pps_time_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 255; + test_msg->time = 690508632716; + sbp_payload_send(&sbp_state, 0xff08, 53726, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 53726, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 53726, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xff08, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_pps_time_t *check_msg = (msg_pps_time_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 255, + "incorrect value for flags, expected 255, is %d", + check_msg->flags); + ck_assert_msg(check_msg->time == 690508632716, + "incorrect value for time, expected 690508632716, is %d", + check_msg->time); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_system_MsgPpsTime_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_system_MsgPpsTime"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_system_MsgPpsTime"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_system_MsgPpsTime); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_system_MsgStatusReport.c b/c/test/legacy/auto_check_sbp_system_MsgStatusReport.c new file mode 100644 index 0000000000..57cc584146 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_system_MsgStatusReport.c @@ -0,0 +1,1284 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_system_MsgStatusReport) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0xfffe, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0xfffe, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, + 233, 21, 208, 98, 247, 203, 221, 198, 156, 207, 217, 238, 162, 136, + 154, 11, 114, 236, 134, 235, 12, 133, 9, 30, 175, 145, 26, 114, + 215, 20, 146, 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, + 5, 248, 225, 149, 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, + 103, 68, 76, 184, 33, 206, 194, 163, 123, 30, 151, 176, 149, 172, + 184, 231, 118, 230, 200, 168, 100, 109, 10, 233, 4, 60, 247, 82, + 215, 166, 28, 138, 110, 45, 98, 218, 244, 179, 126, 107, 92, 124, + 94, 157, 42, 187, 124, 6, 97, 247, 160, 188, 110, 120, 254, 214, + 110, 51, 240, 164, 147, 18, 74, 178, 67, 4, 27, 73, 190, 64, + 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, 40, 161, 173, 242, + 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, 40, 191, 113, + 230, 200, 72, 8, 215, 245, 78, 59, 222, 250, 115, 32, 33, 30, + 211, 170, 145, 92, 157, 75, 24, 169, 6, 55, 62, 8, 107, 82, + 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, + 148, 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, + 23, 248, 192, 20, 83, 195, 95, 180, 54, 36, 186, 75, 64, 20, + 157, 133, 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, 245, 30, + 228, 88, 142, 212, 53, 224, 158, 166, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_status_report_t *test_msg = (msg_status_report_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->reporting_system = 64850; + test_msg->sbp_version = 24497; + test_msg->sequence = 1519336451; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[0].component = 52215; + test_msg->status[0].generic = 221; + test_msg->status[0].specific = 198; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[1].component = 53148; + test_msg->status[1].generic = 217; + test_msg->status[1].specific = 238; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[2].component = 34978; + test_msg->status[2].generic = 154; + test_msg->status[2].specific = 11; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[3].component = 60530; + test_msg->status[3].generic = 134; + test_msg->status[3].specific = 235; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[4].component = 34060; + test_msg->status[4].generic = 9; + test_msg->status[4].specific = 30; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[5].component = 37295; + test_msg->status[5].generic = 26; + test_msg->status[5].specific = 114; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[6].component = 5335; + test_msg->status[6].generic = 146; + test_msg->status[6].specific = 249; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[7].component = 13878; + test_msg->status[7].generic = 133; + test_msg->status[7].specific = 193; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[8].component = 47722; + test_msg->status[8].generic = 210; + test_msg->status[8].specific = 183; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[9].component = 33024; + test_msg->status[9].generic = 5; + test_msg->status[9].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[10].component = 38369; + test_msg->status[10].generic = 135; + test_msg->status[10].specific = 127; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[11].component = 6658; + test_msg->status[11].generic = 88; + test_msg->status[11].specific = 92; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[12].component = 26378; + test_msg->status[12].generic = 73; + test_msg->status[12].specific = 3; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[13].component = 17511; + test_msg->status[13].generic = 76; + test_msg->status[13].specific = 184; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[14].component = 52769; + test_msg->status[14].generic = 194; + test_msg->status[14].specific = 163; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[15].component = 7803; + test_msg->status[15].generic = 151; + test_msg->status[15].specific = 176; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[16].component = 44181; + test_msg->status[16].generic = 184; + test_msg->status[16].specific = 231; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[17].component = 58998; + test_msg->status[17].generic = 200; + test_msg->status[17].specific = 168; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[18].component = 28004; + test_msg->status[18].generic = 10; + test_msg->status[18].specific = 233; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[19].component = 15364; + test_msg->status[19].generic = 247; + test_msg->status[19].specific = 82; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[20].component = 42711; + test_msg->status[20].generic = 28; + test_msg->status[20].specific = 138; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[21].component = 11630; + test_msg->status[21].generic = 98; + test_msg->status[21].specific = 218; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[22].component = 46068; + test_msg->status[22].generic = 126; + test_msg->status[22].specific = 107; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[23].component = 31836; + test_msg->status[23].generic = 94; + test_msg->status[23].specific = 157; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[24].component = 47914; + test_msg->status[24].generic = 124; + test_msg->status[24].specific = 6; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[25].component = 63329; + test_msg->status[25].generic = 160; + test_msg->status[25].specific = 188; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[26].component = 30830; + test_msg->status[26].generic = 254; + test_msg->status[26].specific = 214; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[27].component = 13166; + test_msg->status[27].generic = 240; + test_msg->status[27].specific = 164; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[28].component = 4755; + test_msg->status[28].generic = 74; + test_msg->status[28].specific = 178; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[29].component = 1091; + test_msg->status[29].generic = 27; + test_msg->status[29].specific = 73; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[30].component = 16574; + test_msg->status[30].generic = 179; + test_msg->status[30].specific = 146; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[31].component = 39293; + test_msg->status[31].generic = 192; + test_msg->status[31].specific = 46; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[32].component = 17098; + test_msg->status[32].generic = 248; + test_msg->status[32].specific = 46; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[33].component = 41256; + test_msg->status[33].generic = 173; + test_msg->status[33].specific = 242; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[34].component = 982; + test_msg->status[34].generic = 11; + test_msg->status[34].specific = 1; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[35].component = 18038; + test_msg->status[35].generic = 162; + test_msg->status[35].specific = 61; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[36].component = 7090; + test_msg->status[36].generic = 156; + test_msg->status[36].specific = 40; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[37].component = 29119; + test_msg->status[37].generic = 230; + test_msg->status[37].specific = 200; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[38].component = 2120; + test_msg->status[38].generic = 215; + test_msg->status[38].specific = 245; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[39].component = 15182; + test_msg->status[39].generic = 222; + test_msg->status[39].specific = 250; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[40].component = 8307; + test_msg->status[40].generic = 33; + test_msg->status[40].specific = 30; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[41].component = 43731; + test_msg->status[41].generic = 145; + test_msg->status[41].specific = 92; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[42].component = 19357; + test_msg->status[42].generic = 24; + test_msg->status[42].specific = 169; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[43].component = 14086; + test_msg->status[43].generic = 62; + test_msg->status[43].specific = 8; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[44].component = 21099; + test_msg->status[44].generic = 140; + test_msg->status[44].specific = 49; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[45].component = 31411; + test_msg->status[45].generic = 90; + test_msg->status[45].specific = 71; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[46].component = 22556; + test_msg->status[46].generic = 103; + test_msg->status[46].specific = 51; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[47].component = 18609; + test_msg->status[47].generic = 93; + test_msg->status[47].specific = 39; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[48].component = 2964; + test_msg->status[48].generic = 202; + test_msg->status[48].specific = 42; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[49].component = 23586; + test_msg->status[49].generic = 204; + test_msg->status[49].specific = 102; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[50].component = 25117; + test_msg->status[50].generic = 249; + test_msg->status[50].specific = 91; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[51].component = 24454; + test_msg->status[51].generic = 23; + test_msg->status[51].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[52].component = 5312; + test_msg->status[52].generic = 83; + test_msg->status[52].specific = 195; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[53].component = 46175; + test_msg->status[53].generic = 54; + test_msg->status[53].specific = 36; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[54].component = 19386; + test_msg->status[54].generic = 64; + test_msg->status[54].specific = 20; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[55].component = 34205; + test_msg->status[55].generic = 12; + test_msg->status[55].specific = 149; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[56].component = 3612; + test_msg->status[56].generic = 185; + test_msg->status[56].specific = 129; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[57].component = 61285; + test_msg->status[57].generic = 74; + test_msg->status[57].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[58].component = 7925; + test_msg->status[58].generic = 228; + test_msg->status[58].specific = 88; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->status[0]); + } + test_msg->status[59].component = 54414; + test_msg->status[59].generic = 53; + test_msg->status[59].specific = 224; + test_msg->uptime = 1657804265; + sbp_payload_send(&sbp_state, 0xfffe, 21510, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 21510, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 21510, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0xfffe, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_status_report_t *check_msg = + (msg_status_report_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->reporting_system == 64850, + "incorrect value for reporting_system, expected 64850, is %d", + check_msg->reporting_system); + ck_assert_msg(check_msg->sbp_version == 24497, + "incorrect value for sbp_version, expected 24497, is %d", + check_msg->sbp_version); + ck_assert_msg(check_msg->sequence == 1519336451, + "incorrect value for sequence, expected 1519336451, is %d", + check_msg->sequence); + ck_assert_msg( + check_msg->status[0].component == 52215, + "incorrect value for status[0].component, expected 52215, is %d", + check_msg->status[0].component); + ck_assert_msg(check_msg->status[0].generic == 221, + "incorrect value for status[0].generic, expected 221, is %d", + check_msg->status[0].generic); + ck_assert_msg(check_msg->status[0].specific == 198, + "incorrect value for status[0].specific, expected 198, is %d", + check_msg->status[0].specific); + ck_assert_msg( + check_msg->status[1].component == 53148, + "incorrect value for status[1].component, expected 53148, is %d", + check_msg->status[1].component); + ck_assert_msg(check_msg->status[1].generic == 217, + "incorrect value for status[1].generic, expected 217, is %d", + check_msg->status[1].generic); + ck_assert_msg(check_msg->status[1].specific == 238, + "incorrect value for status[1].specific, expected 238, is %d", + check_msg->status[1].specific); + ck_assert_msg( + check_msg->status[2].component == 34978, + "incorrect value for status[2].component, expected 34978, is %d", + check_msg->status[2].component); + ck_assert_msg(check_msg->status[2].generic == 154, + "incorrect value for status[2].generic, expected 154, is %d", + check_msg->status[2].generic); + ck_assert_msg(check_msg->status[2].specific == 11, + "incorrect value for status[2].specific, expected 11, is %d", + check_msg->status[2].specific); + ck_assert_msg( + check_msg->status[3].component == 60530, + "incorrect value for status[3].component, expected 60530, is %d", + check_msg->status[3].component); + ck_assert_msg(check_msg->status[3].generic == 134, + "incorrect value for status[3].generic, expected 134, is %d", + check_msg->status[3].generic); + ck_assert_msg(check_msg->status[3].specific == 235, + "incorrect value for status[3].specific, expected 235, is %d", + check_msg->status[3].specific); + ck_assert_msg( + check_msg->status[4].component == 34060, + "incorrect value for status[4].component, expected 34060, is %d", + check_msg->status[4].component); + ck_assert_msg(check_msg->status[4].generic == 9, + "incorrect value for status[4].generic, expected 9, is %d", + check_msg->status[4].generic); + ck_assert_msg(check_msg->status[4].specific == 30, + "incorrect value for status[4].specific, expected 30, is %d", + check_msg->status[4].specific); + ck_assert_msg( + check_msg->status[5].component == 37295, + "incorrect value for status[5].component, expected 37295, is %d", + check_msg->status[5].component); + ck_assert_msg(check_msg->status[5].generic == 26, + "incorrect value for status[5].generic, expected 26, is %d", + check_msg->status[5].generic); + ck_assert_msg(check_msg->status[5].specific == 114, + "incorrect value for status[5].specific, expected 114, is %d", + check_msg->status[5].specific); + ck_assert_msg( + check_msg->status[6].component == 5335, + "incorrect value for status[6].component, expected 5335, is %d", + check_msg->status[6].component); + ck_assert_msg(check_msg->status[6].generic == 146, + "incorrect value for status[6].generic, expected 146, is %d", + check_msg->status[6].generic); + ck_assert_msg(check_msg->status[6].specific == 249, + "incorrect value for status[6].specific, expected 249, is %d", + check_msg->status[6].specific); + ck_assert_msg( + check_msg->status[7].component == 13878, + "incorrect value for status[7].component, expected 13878, is %d", + check_msg->status[7].component); + ck_assert_msg(check_msg->status[7].generic == 133, + "incorrect value for status[7].generic, expected 133, is %d", + check_msg->status[7].generic); + ck_assert_msg(check_msg->status[7].specific == 193, + "incorrect value for status[7].specific, expected 193, is %d", + check_msg->status[7].specific); + ck_assert_msg( + check_msg->status[8].component == 47722, + "incorrect value for status[8].component, expected 47722, is %d", + check_msg->status[8].component); + ck_assert_msg(check_msg->status[8].generic == 210, + "incorrect value for status[8].generic, expected 210, is %d", + check_msg->status[8].generic); + ck_assert_msg(check_msg->status[8].specific == 183, + "incorrect value for status[8].specific, expected 183, is %d", + check_msg->status[8].specific); + ck_assert_msg( + check_msg->status[9].component == 33024, + "incorrect value for status[9].component, expected 33024, is %d", + check_msg->status[9].component); + ck_assert_msg(check_msg->status[9].generic == 5, + "incorrect value for status[9].generic, expected 5, is %d", + check_msg->status[9].generic); + ck_assert_msg(check_msg->status[9].specific == 248, + "incorrect value for status[9].specific, expected 248, is %d", + check_msg->status[9].specific); + ck_assert_msg( + check_msg->status[10].component == 38369, + "incorrect value for status[10].component, expected 38369, is %d", + check_msg->status[10].component); + ck_assert_msg(check_msg->status[10].generic == 135, + "incorrect value for status[10].generic, expected 135, is %d", + check_msg->status[10].generic); + ck_assert_msg( + check_msg->status[10].specific == 127, + "incorrect value for status[10].specific, expected 127, is %d", + check_msg->status[10].specific); + ck_assert_msg( + check_msg->status[11].component == 6658, + "incorrect value for status[11].component, expected 6658, is %d", + check_msg->status[11].component); + ck_assert_msg(check_msg->status[11].generic == 88, + "incorrect value for status[11].generic, expected 88, is %d", + check_msg->status[11].generic); + ck_assert_msg(check_msg->status[11].specific == 92, + "incorrect value for status[11].specific, expected 92, is %d", + check_msg->status[11].specific); + ck_assert_msg( + check_msg->status[12].component == 26378, + "incorrect value for status[12].component, expected 26378, is %d", + check_msg->status[12].component); + ck_assert_msg(check_msg->status[12].generic == 73, + "incorrect value for status[12].generic, expected 73, is %d", + check_msg->status[12].generic); + ck_assert_msg(check_msg->status[12].specific == 3, + "incorrect value for status[12].specific, expected 3, is %d", + check_msg->status[12].specific); + ck_assert_msg( + check_msg->status[13].component == 17511, + "incorrect value for status[13].component, expected 17511, is %d", + check_msg->status[13].component); + ck_assert_msg(check_msg->status[13].generic == 76, + "incorrect value for status[13].generic, expected 76, is %d", + check_msg->status[13].generic); + ck_assert_msg( + check_msg->status[13].specific == 184, + "incorrect value for status[13].specific, expected 184, is %d", + check_msg->status[13].specific); + ck_assert_msg( + check_msg->status[14].component == 52769, + "incorrect value for status[14].component, expected 52769, is %d", + check_msg->status[14].component); + ck_assert_msg(check_msg->status[14].generic == 194, + "incorrect value for status[14].generic, expected 194, is %d", + check_msg->status[14].generic); + ck_assert_msg( + check_msg->status[14].specific == 163, + "incorrect value for status[14].specific, expected 163, is %d", + check_msg->status[14].specific); + ck_assert_msg( + check_msg->status[15].component == 7803, + "incorrect value for status[15].component, expected 7803, is %d", + check_msg->status[15].component); + ck_assert_msg(check_msg->status[15].generic == 151, + "incorrect value for status[15].generic, expected 151, is %d", + check_msg->status[15].generic); + ck_assert_msg( + check_msg->status[15].specific == 176, + "incorrect value for status[15].specific, expected 176, is %d", + check_msg->status[15].specific); + ck_assert_msg( + check_msg->status[16].component == 44181, + "incorrect value for status[16].component, expected 44181, is %d", + check_msg->status[16].component); + ck_assert_msg(check_msg->status[16].generic == 184, + "incorrect value for status[16].generic, expected 184, is %d", + check_msg->status[16].generic); + ck_assert_msg( + check_msg->status[16].specific == 231, + "incorrect value for status[16].specific, expected 231, is %d", + check_msg->status[16].specific); + ck_assert_msg( + check_msg->status[17].component == 58998, + "incorrect value for status[17].component, expected 58998, is %d", + check_msg->status[17].component); + ck_assert_msg(check_msg->status[17].generic == 200, + "incorrect value for status[17].generic, expected 200, is %d", + check_msg->status[17].generic); + ck_assert_msg( + check_msg->status[17].specific == 168, + "incorrect value for status[17].specific, expected 168, is %d", + check_msg->status[17].specific); + ck_assert_msg( + check_msg->status[18].component == 28004, + "incorrect value for status[18].component, expected 28004, is %d", + check_msg->status[18].component); + ck_assert_msg(check_msg->status[18].generic == 10, + "incorrect value for status[18].generic, expected 10, is %d", + check_msg->status[18].generic); + ck_assert_msg( + check_msg->status[18].specific == 233, + "incorrect value for status[18].specific, expected 233, is %d", + check_msg->status[18].specific); + ck_assert_msg( + check_msg->status[19].component == 15364, + "incorrect value for status[19].component, expected 15364, is %d", + check_msg->status[19].component); + ck_assert_msg(check_msg->status[19].generic == 247, + "incorrect value for status[19].generic, expected 247, is %d", + check_msg->status[19].generic); + ck_assert_msg(check_msg->status[19].specific == 82, + "incorrect value for status[19].specific, expected 82, is %d", + check_msg->status[19].specific); + ck_assert_msg( + check_msg->status[20].component == 42711, + "incorrect value for status[20].component, expected 42711, is %d", + check_msg->status[20].component); + ck_assert_msg(check_msg->status[20].generic == 28, + "incorrect value for status[20].generic, expected 28, is %d", + check_msg->status[20].generic); + ck_assert_msg( + check_msg->status[20].specific == 138, + "incorrect value for status[20].specific, expected 138, is %d", + check_msg->status[20].specific); + ck_assert_msg( + check_msg->status[21].component == 11630, + "incorrect value for status[21].component, expected 11630, is %d", + check_msg->status[21].component); + ck_assert_msg(check_msg->status[21].generic == 98, + "incorrect value for status[21].generic, expected 98, is %d", + check_msg->status[21].generic); + ck_assert_msg( + check_msg->status[21].specific == 218, + "incorrect value for status[21].specific, expected 218, is %d", + check_msg->status[21].specific); + ck_assert_msg( + check_msg->status[22].component == 46068, + "incorrect value for status[22].component, expected 46068, is %d", + check_msg->status[22].component); + ck_assert_msg(check_msg->status[22].generic == 126, + "incorrect value for status[22].generic, expected 126, is %d", + check_msg->status[22].generic); + ck_assert_msg( + check_msg->status[22].specific == 107, + "incorrect value for status[22].specific, expected 107, is %d", + check_msg->status[22].specific); + ck_assert_msg( + check_msg->status[23].component == 31836, + "incorrect value for status[23].component, expected 31836, is %d", + check_msg->status[23].component); + ck_assert_msg(check_msg->status[23].generic == 94, + "incorrect value for status[23].generic, expected 94, is %d", + check_msg->status[23].generic); + ck_assert_msg( + check_msg->status[23].specific == 157, + "incorrect value for status[23].specific, expected 157, is %d", + check_msg->status[23].specific); + ck_assert_msg( + check_msg->status[24].component == 47914, + "incorrect value for status[24].component, expected 47914, is %d", + check_msg->status[24].component); + ck_assert_msg(check_msg->status[24].generic == 124, + "incorrect value for status[24].generic, expected 124, is %d", + check_msg->status[24].generic); + ck_assert_msg(check_msg->status[24].specific == 6, + "incorrect value for status[24].specific, expected 6, is %d", + check_msg->status[24].specific); + ck_assert_msg( + check_msg->status[25].component == 63329, + "incorrect value for status[25].component, expected 63329, is %d", + check_msg->status[25].component); + ck_assert_msg(check_msg->status[25].generic == 160, + "incorrect value for status[25].generic, expected 160, is %d", + check_msg->status[25].generic); + ck_assert_msg( + check_msg->status[25].specific == 188, + "incorrect value for status[25].specific, expected 188, is %d", + check_msg->status[25].specific); + ck_assert_msg( + check_msg->status[26].component == 30830, + "incorrect value for status[26].component, expected 30830, is %d", + check_msg->status[26].component); + ck_assert_msg(check_msg->status[26].generic == 254, + "incorrect value for status[26].generic, expected 254, is %d", + check_msg->status[26].generic); + ck_assert_msg( + check_msg->status[26].specific == 214, + "incorrect value for status[26].specific, expected 214, is %d", + check_msg->status[26].specific); + ck_assert_msg( + check_msg->status[27].component == 13166, + "incorrect value for status[27].component, expected 13166, is %d", + check_msg->status[27].component); + ck_assert_msg(check_msg->status[27].generic == 240, + "incorrect value for status[27].generic, expected 240, is %d", + check_msg->status[27].generic); + ck_assert_msg( + check_msg->status[27].specific == 164, + "incorrect value for status[27].specific, expected 164, is %d", + check_msg->status[27].specific); + ck_assert_msg( + check_msg->status[28].component == 4755, + "incorrect value for status[28].component, expected 4755, is %d", + check_msg->status[28].component); + ck_assert_msg(check_msg->status[28].generic == 74, + "incorrect value for status[28].generic, expected 74, is %d", + check_msg->status[28].generic); + ck_assert_msg( + check_msg->status[28].specific == 178, + "incorrect value for status[28].specific, expected 178, is %d", + check_msg->status[28].specific); + ck_assert_msg( + check_msg->status[29].component == 1091, + "incorrect value for status[29].component, expected 1091, is %d", + check_msg->status[29].component); + ck_assert_msg(check_msg->status[29].generic == 27, + "incorrect value for status[29].generic, expected 27, is %d", + check_msg->status[29].generic); + ck_assert_msg(check_msg->status[29].specific == 73, + "incorrect value for status[29].specific, expected 73, is %d", + check_msg->status[29].specific); + ck_assert_msg( + check_msg->status[30].component == 16574, + "incorrect value for status[30].component, expected 16574, is %d", + check_msg->status[30].component); + ck_assert_msg(check_msg->status[30].generic == 179, + "incorrect value for status[30].generic, expected 179, is %d", + check_msg->status[30].generic); + ck_assert_msg( + check_msg->status[30].specific == 146, + "incorrect value for status[30].specific, expected 146, is %d", + check_msg->status[30].specific); + ck_assert_msg( + check_msg->status[31].component == 39293, + "incorrect value for status[31].component, expected 39293, is %d", + check_msg->status[31].component); + ck_assert_msg(check_msg->status[31].generic == 192, + "incorrect value for status[31].generic, expected 192, is %d", + check_msg->status[31].generic); + ck_assert_msg(check_msg->status[31].specific == 46, + "incorrect value for status[31].specific, expected 46, is %d", + check_msg->status[31].specific); + ck_assert_msg( + check_msg->status[32].component == 17098, + "incorrect value for status[32].component, expected 17098, is %d", + check_msg->status[32].component); + ck_assert_msg(check_msg->status[32].generic == 248, + "incorrect value for status[32].generic, expected 248, is %d", + check_msg->status[32].generic); + ck_assert_msg(check_msg->status[32].specific == 46, + "incorrect value for status[32].specific, expected 46, is %d", + check_msg->status[32].specific); + ck_assert_msg( + check_msg->status[33].component == 41256, + "incorrect value for status[33].component, expected 41256, is %d", + check_msg->status[33].component); + ck_assert_msg(check_msg->status[33].generic == 173, + "incorrect value for status[33].generic, expected 173, is %d", + check_msg->status[33].generic); + ck_assert_msg( + check_msg->status[33].specific == 242, + "incorrect value for status[33].specific, expected 242, is %d", + check_msg->status[33].specific); + ck_assert_msg( + check_msg->status[34].component == 982, + "incorrect value for status[34].component, expected 982, is %d", + check_msg->status[34].component); + ck_assert_msg(check_msg->status[34].generic == 11, + "incorrect value for status[34].generic, expected 11, is %d", + check_msg->status[34].generic); + ck_assert_msg(check_msg->status[34].specific == 1, + "incorrect value for status[34].specific, expected 1, is %d", + check_msg->status[34].specific); + ck_assert_msg( + check_msg->status[35].component == 18038, + "incorrect value for status[35].component, expected 18038, is %d", + check_msg->status[35].component); + ck_assert_msg(check_msg->status[35].generic == 162, + "incorrect value for status[35].generic, expected 162, is %d", + check_msg->status[35].generic); + ck_assert_msg(check_msg->status[35].specific == 61, + "incorrect value for status[35].specific, expected 61, is %d", + check_msg->status[35].specific); + ck_assert_msg( + check_msg->status[36].component == 7090, + "incorrect value for status[36].component, expected 7090, is %d", + check_msg->status[36].component); + ck_assert_msg(check_msg->status[36].generic == 156, + "incorrect value for status[36].generic, expected 156, is %d", + check_msg->status[36].generic); + ck_assert_msg(check_msg->status[36].specific == 40, + "incorrect value for status[36].specific, expected 40, is %d", + check_msg->status[36].specific); + ck_assert_msg( + check_msg->status[37].component == 29119, + "incorrect value for status[37].component, expected 29119, is %d", + check_msg->status[37].component); + ck_assert_msg(check_msg->status[37].generic == 230, + "incorrect value for status[37].generic, expected 230, is %d", + check_msg->status[37].generic); + ck_assert_msg( + check_msg->status[37].specific == 200, + "incorrect value for status[37].specific, expected 200, is %d", + check_msg->status[37].specific); + ck_assert_msg( + check_msg->status[38].component == 2120, + "incorrect value for status[38].component, expected 2120, is %d", + check_msg->status[38].component); + ck_assert_msg(check_msg->status[38].generic == 215, + "incorrect value for status[38].generic, expected 215, is %d", + check_msg->status[38].generic); + ck_assert_msg( + check_msg->status[38].specific == 245, + "incorrect value for status[38].specific, expected 245, is %d", + check_msg->status[38].specific); + ck_assert_msg( + check_msg->status[39].component == 15182, + "incorrect value for status[39].component, expected 15182, is %d", + check_msg->status[39].component); + ck_assert_msg(check_msg->status[39].generic == 222, + "incorrect value for status[39].generic, expected 222, is %d", + check_msg->status[39].generic); + ck_assert_msg( + check_msg->status[39].specific == 250, + "incorrect value for status[39].specific, expected 250, is %d", + check_msg->status[39].specific); + ck_assert_msg( + check_msg->status[40].component == 8307, + "incorrect value for status[40].component, expected 8307, is %d", + check_msg->status[40].component); + ck_assert_msg(check_msg->status[40].generic == 33, + "incorrect value for status[40].generic, expected 33, is %d", + check_msg->status[40].generic); + ck_assert_msg(check_msg->status[40].specific == 30, + "incorrect value for status[40].specific, expected 30, is %d", + check_msg->status[40].specific); + ck_assert_msg( + check_msg->status[41].component == 43731, + "incorrect value for status[41].component, expected 43731, is %d", + check_msg->status[41].component); + ck_assert_msg(check_msg->status[41].generic == 145, + "incorrect value for status[41].generic, expected 145, is %d", + check_msg->status[41].generic); + ck_assert_msg(check_msg->status[41].specific == 92, + "incorrect value for status[41].specific, expected 92, is %d", + check_msg->status[41].specific); + ck_assert_msg( + check_msg->status[42].component == 19357, + "incorrect value for status[42].component, expected 19357, is %d", + check_msg->status[42].component); + ck_assert_msg(check_msg->status[42].generic == 24, + "incorrect value for status[42].generic, expected 24, is %d", + check_msg->status[42].generic); + ck_assert_msg( + check_msg->status[42].specific == 169, + "incorrect value for status[42].specific, expected 169, is %d", + check_msg->status[42].specific); + ck_assert_msg( + check_msg->status[43].component == 14086, + "incorrect value for status[43].component, expected 14086, is %d", + check_msg->status[43].component); + ck_assert_msg(check_msg->status[43].generic == 62, + "incorrect value for status[43].generic, expected 62, is %d", + check_msg->status[43].generic); + ck_assert_msg(check_msg->status[43].specific == 8, + "incorrect value for status[43].specific, expected 8, is %d", + check_msg->status[43].specific); + ck_assert_msg( + check_msg->status[44].component == 21099, + "incorrect value for status[44].component, expected 21099, is %d", + check_msg->status[44].component); + ck_assert_msg(check_msg->status[44].generic == 140, + "incorrect value for status[44].generic, expected 140, is %d", + check_msg->status[44].generic); + ck_assert_msg(check_msg->status[44].specific == 49, + "incorrect value for status[44].specific, expected 49, is %d", + check_msg->status[44].specific); + ck_assert_msg( + check_msg->status[45].component == 31411, + "incorrect value for status[45].component, expected 31411, is %d", + check_msg->status[45].component); + ck_assert_msg(check_msg->status[45].generic == 90, + "incorrect value for status[45].generic, expected 90, is %d", + check_msg->status[45].generic); + ck_assert_msg(check_msg->status[45].specific == 71, + "incorrect value for status[45].specific, expected 71, is %d", + check_msg->status[45].specific); + ck_assert_msg( + check_msg->status[46].component == 22556, + "incorrect value for status[46].component, expected 22556, is %d", + check_msg->status[46].component); + ck_assert_msg(check_msg->status[46].generic == 103, + "incorrect value for status[46].generic, expected 103, is %d", + check_msg->status[46].generic); + ck_assert_msg(check_msg->status[46].specific == 51, + "incorrect value for status[46].specific, expected 51, is %d", + check_msg->status[46].specific); + ck_assert_msg( + check_msg->status[47].component == 18609, + "incorrect value for status[47].component, expected 18609, is %d", + check_msg->status[47].component); + ck_assert_msg(check_msg->status[47].generic == 93, + "incorrect value for status[47].generic, expected 93, is %d", + check_msg->status[47].generic); + ck_assert_msg(check_msg->status[47].specific == 39, + "incorrect value for status[47].specific, expected 39, is %d", + check_msg->status[47].specific); + ck_assert_msg( + check_msg->status[48].component == 2964, + "incorrect value for status[48].component, expected 2964, is %d", + check_msg->status[48].component); + ck_assert_msg(check_msg->status[48].generic == 202, + "incorrect value for status[48].generic, expected 202, is %d", + check_msg->status[48].generic); + ck_assert_msg(check_msg->status[48].specific == 42, + "incorrect value for status[48].specific, expected 42, is %d", + check_msg->status[48].specific); + ck_assert_msg( + check_msg->status[49].component == 23586, + "incorrect value for status[49].component, expected 23586, is %d", + check_msg->status[49].component); + ck_assert_msg(check_msg->status[49].generic == 204, + "incorrect value for status[49].generic, expected 204, is %d", + check_msg->status[49].generic); + ck_assert_msg( + check_msg->status[49].specific == 102, + "incorrect value for status[49].specific, expected 102, is %d", + check_msg->status[49].specific); + ck_assert_msg( + check_msg->status[50].component == 25117, + "incorrect value for status[50].component, expected 25117, is %d", + check_msg->status[50].component); + ck_assert_msg(check_msg->status[50].generic == 249, + "incorrect value for status[50].generic, expected 249, is %d", + check_msg->status[50].generic); + ck_assert_msg(check_msg->status[50].specific == 91, + "incorrect value for status[50].specific, expected 91, is %d", + check_msg->status[50].specific); + ck_assert_msg( + check_msg->status[51].component == 24454, + "incorrect value for status[51].component, expected 24454, is %d", + check_msg->status[51].component); + ck_assert_msg(check_msg->status[51].generic == 23, + "incorrect value for status[51].generic, expected 23, is %d", + check_msg->status[51].generic); + ck_assert_msg( + check_msg->status[51].specific == 248, + "incorrect value for status[51].specific, expected 248, is %d", + check_msg->status[51].specific); + ck_assert_msg( + check_msg->status[52].component == 5312, + "incorrect value for status[52].component, expected 5312, is %d", + check_msg->status[52].component); + ck_assert_msg(check_msg->status[52].generic == 83, + "incorrect value for status[52].generic, expected 83, is %d", + check_msg->status[52].generic); + ck_assert_msg( + check_msg->status[52].specific == 195, + "incorrect value for status[52].specific, expected 195, is %d", + check_msg->status[52].specific); + ck_assert_msg( + check_msg->status[53].component == 46175, + "incorrect value for status[53].component, expected 46175, is %d", + check_msg->status[53].component); + ck_assert_msg(check_msg->status[53].generic == 54, + "incorrect value for status[53].generic, expected 54, is %d", + check_msg->status[53].generic); + ck_assert_msg(check_msg->status[53].specific == 36, + "incorrect value for status[53].specific, expected 36, is %d", + check_msg->status[53].specific); + ck_assert_msg( + check_msg->status[54].component == 19386, + "incorrect value for status[54].component, expected 19386, is %d", + check_msg->status[54].component); + ck_assert_msg(check_msg->status[54].generic == 64, + "incorrect value for status[54].generic, expected 64, is %d", + check_msg->status[54].generic); + ck_assert_msg(check_msg->status[54].specific == 20, + "incorrect value for status[54].specific, expected 20, is %d", + check_msg->status[54].specific); + ck_assert_msg( + check_msg->status[55].component == 34205, + "incorrect value for status[55].component, expected 34205, is %d", + check_msg->status[55].component); + ck_assert_msg(check_msg->status[55].generic == 12, + "incorrect value for status[55].generic, expected 12, is %d", + check_msg->status[55].generic); + ck_assert_msg( + check_msg->status[55].specific == 149, + "incorrect value for status[55].specific, expected 149, is %d", + check_msg->status[55].specific); + ck_assert_msg( + check_msg->status[56].component == 3612, + "incorrect value for status[56].component, expected 3612, is %d", + check_msg->status[56].component); + ck_assert_msg(check_msg->status[56].generic == 185, + "incorrect value for status[56].generic, expected 185, is %d", + check_msg->status[56].generic); + ck_assert_msg( + check_msg->status[56].specific == 129, + "incorrect value for status[56].specific, expected 129, is %d", + check_msg->status[56].specific); + ck_assert_msg( + check_msg->status[57].component == 61285, + "incorrect value for status[57].component, expected 61285, is %d", + check_msg->status[57].component); + ck_assert_msg(check_msg->status[57].generic == 74, + "incorrect value for status[57].generic, expected 74, is %d", + check_msg->status[57].generic); + ck_assert_msg( + check_msg->status[57].specific == 248, + "incorrect value for status[57].specific, expected 248, is %d", + check_msg->status[57].specific); + ck_assert_msg( + check_msg->status[58].component == 7925, + "incorrect value for status[58].component, expected 7925, is %d", + check_msg->status[58].component); + ck_assert_msg(check_msg->status[58].generic == 228, + "incorrect value for status[58].generic, expected 228, is %d", + check_msg->status[58].generic); + ck_assert_msg(check_msg->status[58].specific == 88, + "incorrect value for status[58].specific, expected 88, is %d", + check_msg->status[58].specific); + ck_assert_msg( + check_msg->status[59].component == 54414, + "incorrect value for status[59].component, expected 54414, is %d", + check_msg->status[59].component); + ck_assert_msg(check_msg->status[59].generic == 53, + "incorrect value for status[59].generic, expected 53, is %d", + check_msg->status[59].generic); + ck_assert_msg( + check_msg->status[59].specific == 224, + "incorrect value for status[59].specific, expected 224, is %d", + check_msg->status[59].specific); + ck_assert_msg(check_msg->uptime == 1657804265, + "incorrect value for uptime, expected 1657804265, is %d", + check_msg->uptime); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_system_MsgStatusReport_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_system_MsgStatusReport"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_system_MsgStatusReport"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_system_MsgStatusReport); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIq.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIq.c new file mode 100644 index 0000000000..6abc75f904 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIq.c @@ -0,0 +1,250 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingIq) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x2d, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x2d, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, + 55, 45, 38, 189, 88, 159, 19, 208, 12, 97, 167, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_iq_t *test_msg = (msg_tracking_iq_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->channel = 145; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[0].I = -9937; + test_msg->corrs[0].Q = 14319; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[1].I = 9773; + test_msg->corrs[1].Q = 22717; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[2].I = 5023; + test_msg->corrs[2].Q = 3280; + test_msg->sid.code = 203; + test_msg->sid.sat = 121; + sbp_payload_send(&sbp_state, 0x2d, 20482, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 20482, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 20482, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x2d, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_iq_t *check_msg = (msg_tracking_iq_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->channel == 145, + "incorrect value for channel, expected 145, is %d", + check_msg->channel); + ck_assert_msg(check_msg->corrs[0].I == -9937, + "incorrect value for corrs[0].I, expected -9937, is %d", + check_msg->corrs[0].I); + ck_assert_msg(check_msg->corrs[0].Q == 14319, + "incorrect value for corrs[0].Q, expected 14319, is %d", + check_msg->corrs[0].Q); + ck_assert_msg(check_msg->corrs[1].I == 9773, + "incorrect value for corrs[1].I, expected 9773, is %d", + check_msg->corrs[1].I); + ck_assert_msg(check_msg->corrs[1].Q == 22717, + "incorrect value for corrs[1].Q, expected 22717, is %d", + check_msg->corrs[1].Q); + ck_assert_msg(check_msg->corrs[2].I == 5023, + "incorrect value for corrs[2].I, expected 5023, is %d", + check_msg->corrs[2].I); + ck_assert_msg(check_msg->corrs[2].Q == 3280, + "incorrect value for corrs[2].Q, expected 3280, is %d", + check_msg->corrs[2].Q); + ck_assert_msg(check_msg->sid.code == 203, + "incorrect value for sid.code, expected 203, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 121, + "incorrect value for sid.sat, expected 121, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_tracking_MsgTrackingIq_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_tracking_MsgTrackingIq"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_tracking_MsgTrackingIq"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_tracking_MsgTrackingIq); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepA.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepA.c new file mode 100644 index 0000000000..f5891b4ed3 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepA.c @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x1c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x1c, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, + 170, 96, 71, 121, 33, 161, 52, 211, 162, 101, 41, 36, 226, + 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_iq_dep_a_t *test_msg = + (msg_tracking_iq_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->channel = 139; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[0].I = 1621776995; + test_msg->corrs[0].Q = -1591641785; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[1].I = 1705169716; + test_msg->corrs[1].Q = 1675764777; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[2].I = -267498681; + test_msg->corrs[2].Q = 1403998854; + test_msg->sid.code = 15; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 64028; + sbp_payload_send(&sbp_state, 0x1c, 17336, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 17336, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 17336, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x1c, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_iq_dep_a_t *check_msg = + (msg_tracking_iq_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->channel == 139, + "incorrect value for channel, expected 139, is %d", + check_msg->channel); + ck_assert_msg(check_msg->corrs[0].I == 1621776995, + "incorrect value for corrs[0].I, expected 1621776995, is %d", + check_msg->corrs[0].I); + ck_assert_msg(check_msg->corrs[0].Q == -1591641785, + "incorrect value for corrs[0].Q, expected -1591641785, is %d", + check_msg->corrs[0].Q); + ck_assert_msg(check_msg->corrs[1].I == 1705169716, + "incorrect value for corrs[1].I, expected 1705169716, is %d", + check_msg->corrs[1].I); + ck_assert_msg(check_msg->corrs[1].Q == 1675764777, + "incorrect value for corrs[1].Q, expected 1675764777, is %d", + check_msg->corrs[1].Q); + ck_assert_msg(check_msg->corrs[2].I == -267498681, + "incorrect value for corrs[2].I, expected -267498681, is %d", + check_msg->corrs[2].I); + ck_assert_msg(check_msg->corrs[2].Q == 1403998854, + "incorrect value for corrs[2].Q, expected 1403998854, is %d", + check_msg->corrs[2].Q); + ck_assert_msg(check_msg->sid.code == 15, + "incorrect value for sid.code, expected 15, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.reserved == 0, + "incorrect value for sid.reserved, expected 0, is %d", + check_msg->sid.reserved); + ck_assert_msg(check_msg->sid.sat == 64028, + "incorrect value for sid.sat, expected 64028, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_tracking_MsgTrackingIqDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_tracking_MsgTrackingIqDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepB.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepB.c new file mode 100644 index 0000000000..82b74b2a77 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingIqDepB.c @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x2c, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x2c, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, + 15, 187, 249, 101, 24, 135, 146, 180, 224, 123, 235, 142, + 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_iq_dep_b_t *test_msg = + (msg_tracking_iq_dep_b_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->channel = 45; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[0].I = 261994824; + test_msg->corrs[0].Q = 409336251; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[1].I = -525036921; + test_msg->corrs[1].Q = -795939973; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->corrs[0]); + } + test_msg->corrs[2].I = 353988710; + test_msg->corrs[2].Q = 1148477617; + test_msg->sid.code = 183; + test_msg->sid.sat = 188; + sbp_payload_send(&sbp_state, 0x2c, 25895, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 25895, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 25895, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x2c, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_iq_dep_b_t *check_msg = + (msg_tracking_iq_dep_b_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->channel == 45, + "incorrect value for channel, expected 45, is %d", + check_msg->channel); + ck_assert_msg(check_msg->corrs[0].I == 261994824, + "incorrect value for corrs[0].I, expected 261994824, is %d", + check_msg->corrs[0].I); + ck_assert_msg(check_msg->corrs[0].Q == 409336251, + "incorrect value for corrs[0].Q, expected 409336251, is %d", + check_msg->corrs[0].Q); + ck_assert_msg(check_msg->corrs[1].I == -525036921, + "incorrect value for corrs[1].I, expected -525036921, is %d", + check_msg->corrs[1].I); + ck_assert_msg(check_msg->corrs[1].Q == -795939973, + "incorrect value for corrs[1].Q, expected -795939973, is %d", + check_msg->corrs[1].Q); + ck_assert_msg(check_msg->corrs[2].I == 353988710, + "incorrect value for corrs[2].I, expected 353988710, is %d", + check_msg->corrs[2].I); + ck_assert_msg(check_msg->corrs[2].Q == 1148477617, + "incorrect value for corrs[2].Q, expected 1148477617, is %d", + check_msg->corrs[2].Q); + ck_assert_msg(check_msg->sid.code == 183, + "incorrect value for sid.code, expected 183, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 188, + "incorrect value for sid.sat, expected 188, is %d", + check_msg->sid.sat); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_tracking_MsgTrackingIqDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_tracking_MsgTrackingIqDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingState.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingState.c index ae4097e513..a92234b791 100644 --- a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingState.c +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingState.c @@ -116,6 +116,1395 @@ START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingState) { logging_reset(); + sbp_payload_callback_register(&sbp_state, 0x41, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x41, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, + 25, 4, 90, 195, 246, 108, 75, 82, 137, 127, 45, 163, 32, 46, + 187, 93, 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, 219, 69, + 254, 136, 3, 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, + 218, 62, 242, 84, 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, + 253, 227, 216, 227, 24, 26, 210, 179, 19, 15, 227, 255, 122, 75, + 187, 200, 217, 48, 218, 122, 187, 238, 142, 149, 238, 55, 251, 212, + 128, 160, 194, 104, 113, 255, 141, 62, 43, 69, 245, 39, 100, 230, + 108, 56, 247, 68, 149, 143, 137, 101, 233, 70, 49, 165, 38, 110, + 218, 230, 80, 213, 196, 179, 139, 128, 15, 178, 196, 171, 8, 212, + 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, 5, 25, 105, 186, + 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, 49, 86, 19, + 142, 146, 91, 124, 115, 64, 28, 230, 115, 178, 190, 131, 16, 242, + 105, 59, 182, 113, 192, 180, 48, 179, 166, 31, 172, 211, 77, 228, + 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, 129, 55, + 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, + 148, 190, 236, 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, + 219, 172, 145, 17, 192, 179, 111, 97, 207, 56, 208, 134, 180, 17, + 43, 226, 255, 182, 140, 113, 141, 111, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_state_t* test_msg = (msg_tracking_state_t*)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[0].cn0 = 102; + test_msg->states[0].fcn = 3; + test_msg->states[0].sid.code = 184; + test_msg->states[0].sid.sat = 117; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[1].cn0 = 141; + test_msg->states[1].fcn = 140; + test_msg->states[1].sid.code = 106; + test_msg->states[1].sid.sat = 38; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[2].cn0 = 195; + test_msg->states[2].fcn = 90; + test_msg->states[2].sid.code = 4; + test_msg->states[2].sid.sat = 25; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[3].cn0 = 82; + test_msg->states[3].fcn = 75; + test_msg->states[3].sid.code = 108; + test_msg->states[3].sid.sat = 246; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[4].cn0 = 163; + test_msg->states[4].fcn = 45; + test_msg->states[4].sid.code = 127; + test_msg->states[4].sid.sat = 137; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[5].cn0 = 93; + test_msg->states[5].fcn = 187; + test_msg->states[5].sid.code = 46; + test_msg->states[5].sid.sat = 32; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[6].cn0 = 147; + test_msg->states[6].fcn = 201; + test_msg->states[6].sid.code = 60; + test_msg->states[6].sid.sat = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[7].cn0 = 208; + test_msg->states[7].fcn = 5; + test_msg->states[7].sid.code = 29; + test_msg->states[7].sid.sat = 23; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[8].cn0 = 69; + test_msg->states[8].fcn = 219; + test_msg->states[8].sid.code = 30; + test_msg->states[8].sid.sat = 181; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[9].cn0 = 121; + test_msg->states[9].fcn = 3; + test_msg->states[9].sid.code = 136; + test_msg->states[9].sid.sat = 254; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[10].cn0 = 215; + test_msg->states[10].fcn = 144; + test_msg->states[10].sid.code = 98; + test_msg->states[10].sid.sat = 33; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[11].cn0 = 56; + test_msg->states[11].fcn = 14; + test_msg->states[11].sid.code = 182; + test_msg->states[11].sid.sat = 133; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[12].cn0 = 62; + test_msg->states[12].fcn = 218; + test_msg->states[12].sid.code = 77; + test_msg->states[12].sid.sat = 169; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[13].cn0 = 249; + test_msg->states[13].fcn = 171; + test_msg->states[13].sid.code = 84; + test_msg->states[13].sid.sat = 242; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[14].cn0 = 130; + test_msg->states[14].fcn = 131; + test_msg->states[14].sid.code = 137; + test_msg->states[14].sid.sat = 152; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[15].cn0 = 68; + test_msg->states[15].fcn = 42; + test_msg->states[15].sid.code = 21; + test_msg->states[15].sid.sat = 193; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[16].cn0 = 227; + test_msg->states[16].fcn = 216; + test_msg->states[16].sid.code = 227; + test_msg->states[16].sid.sat = 253; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[17].cn0 = 179; + test_msg->states[17].fcn = 210; + test_msg->states[17].sid.code = 26; + test_msg->states[17].sid.sat = 24; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[18].cn0 = 255; + test_msg->states[18].fcn = 227; + test_msg->states[18].sid.code = 15; + test_msg->states[18].sid.sat = 19; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[19].cn0 = 200; + test_msg->states[19].fcn = 187; + test_msg->states[19].sid.code = 75; + test_msg->states[19].sid.sat = 122; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[20].cn0 = 122; + test_msg->states[20].fcn = 218; + test_msg->states[20].sid.code = 48; + test_msg->states[20].sid.sat = 217; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[21].cn0 = 149; + test_msg->states[21].fcn = 142; + test_msg->states[21].sid.code = 238; + test_msg->states[21].sid.sat = 187; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[22].cn0 = 212; + test_msg->states[22].fcn = 251; + test_msg->states[22].sid.code = 55; + test_msg->states[22].sid.sat = 238; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[23].cn0 = 104; + test_msg->states[23].fcn = 194; + test_msg->states[23].sid.code = 160; + test_msg->states[23].sid.sat = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[24].cn0 = 62; + test_msg->states[24].fcn = 141; + test_msg->states[24].sid.code = 255; + test_msg->states[24].sid.sat = 113; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[25].cn0 = 39; + test_msg->states[25].fcn = 245; + test_msg->states[25].sid.code = 69; + test_msg->states[25].sid.sat = 43; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[26].cn0 = 56; + test_msg->states[26].fcn = 108; + test_msg->states[26].sid.code = 230; + test_msg->states[26].sid.sat = 100; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[27].cn0 = 143; + test_msg->states[27].fcn = 149; + test_msg->states[27].sid.code = 68; + test_msg->states[27].sid.sat = 247; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[28].cn0 = 70; + test_msg->states[28].fcn = 233; + test_msg->states[28].sid.code = 101; + test_msg->states[28].sid.sat = 137; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[29].cn0 = 110; + test_msg->states[29].fcn = 38; + test_msg->states[29].sid.code = 165; + test_msg->states[29].sid.sat = 49; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[30].cn0 = 213; + test_msg->states[30].fcn = 80; + test_msg->states[30].sid.code = 230; + test_msg->states[30].sid.sat = 218; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[31].cn0 = 128; + test_msg->states[31].fcn = 139; + test_msg->states[31].sid.code = 179; + test_msg->states[31].sid.sat = 196; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[32].cn0 = 171; + test_msg->states[32].fcn = 196; + test_msg->states[32].sid.code = 178; + test_msg->states[32].sid.sat = 15; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[33].cn0 = 194; + test_msg->states[33].fcn = 97; + test_msg->states[33].sid.code = 212; + test_msg->states[33].sid.sat = 8; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[34].cn0 = 99; + test_msg->states[34].fcn = 79; + test_msg->states[34].sid.code = 233; + test_msg->states[34].sid.sat = 83; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[35].cn0 = 180; + test_msg->states[35].fcn = 31; + test_msg->states[35].sid.code = 90; + test_msg->states[35].sid.sat = 55; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[36].cn0 = 186; + test_msg->states[36].fcn = 105; + test_msg->states[36].sid.code = 25; + test_msg->states[36].sid.sat = 5; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[37].cn0 = 111; + test_msg->states[37].fcn = 80; + test_msg->states[37].sid.code = 224; + test_msg->states[37].sid.sat = 22; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[38].cn0 = 166; + test_msg->states[38].fcn = 106; + test_msg->states[38].sid.code = 48; + test_msg->states[38].sid.sat = 8; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[39].cn0 = 49; + test_msg->states[39].fcn = 156; + test_msg->states[39].sid.code = 48; + test_msg->states[39].sid.sat = 4; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[40].cn0 = 146; + test_msg->states[40].fcn = 142; + test_msg->states[40].sid.code = 19; + test_msg->states[40].sid.sat = 86; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[41].cn0 = 64; + test_msg->states[41].fcn = 115; + test_msg->states[41].sid.code = 124; + test_msg->states[41].sid.sat = 91; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[42].cn0 = 178; + test_msg->states[42].fcn = 115; + test_msg->states[42].sid.code = 230; + test_msg->states[42].sid.sat = 28; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[43].cn0 = 242; + test_msg->states[43].fcn = 16; + test_msg->states[43].sid.code = 131; + test_msg->states[43].sid.sat = 190; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[44].cn0 = 113; + test_msg->states[44].fcn = 182; + test_msg->states[44].sid.code = 59; + test_msg->states[44].sid.sat = 105; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[45].cn0 = 179; + test_msg->states[45].fcn = 48; + test_msg->states[45].sid.code = 180; + test_msg->states[45].sid.sat = 192; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[46].cn0 = 211; + test_msg->states[46].fcn = 172; + test_msg->states[46].sid.code = 31; + test_msg->states[46].sid.sat = 166; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[47].cn0 = 49; + test_msg->states[47].fcn = 140; + test_msg->states[47].sid.code = 228; + test_msg->states[47].sid.sat = 77; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[48].cn0 = 194; + test_msg->states[48].fcn = 240; + test_msg->states[48].sid.code = 77; + test_msg->states[48].sid.sat = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[49].cn0 = 58; + test_msg->states[49].fcn = 41; + test_msg->states[49].sid.code = 194; + test_msg->states[49].sid.sat = 134; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[50].cn0 = 55; + test_msg->states[50].fcn = 129; + test_msg->states[50].sid.code = 53; + test_msg->states[50].sid.sat = 18; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[51].cn0 = 92; + test_msg->states[51].fcn = 134; + test_msg->states[51].sid.code = 72; + test_msg->states[51].sid.sat = 91; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[52].cn0 = 56; + test_msg->states[52].fcn = 157; + test_msg->states[52].sid.code = 224; + test_msg->states[52].sid.sat = 33; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[53].cn0 = 174; + test_msg->states[53].fcn = 224; + test_msg->states[53].sid.code = 54; + test_msg->states[53].sid.sat = 186; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[54].cn0 = 190; + test_msg->states[54].fcn = 148; + test_msg->states[54].sid.code = 84; + test_msg->states[54].sid.sat = 82; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[55].cn0 = 67; + test_msg->states[55].fcn = 62; + test_msg->states[55].sid.code = 54; + test_msg->states[55].sid.sat = 236; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[56].cn0 = 254; + test_msg->states[56].fcn = 57; + test_msg->states[56].sid.code = 215; + test_msg->states[56].sid.sat = 52; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[57].cn0 = 174; + test_msg->states[57].fcn = 36; + test_msg->states[57].sid.code = 133; + test_msg->states[57].sid.sat = 16; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[58].cn0 = 17; + test_msg->states[58].fcn = 145; + test_msg->states[58].sid.code = 172; + test_msg->states[58].sid.sat = 219; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[59].cn0 = 97; + test_msg->states[59].fcn = 111; + test_msg->states[59].sid.code = 179; + test_msg->states[59].sid.sat = 192; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[60].cn0 = 134; + test_msg->states[60].fcn = 208; + test_msg->states[60].sid.code = 56; + test_msg->states[60].sid.sat = 207; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[61].cn0 = 226; + test_msg->states[61].fcn = 43; + test_msg->states[61].sid.code = 17; + test_msg->states[61].sid.sat = 180; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[62].cn0 = 113; + test_msg->states[62].fcn = 140; + test_msg->states[62].sid.code = 182; + test_msg->states[62].sid.sat = 255; + sbp_payload_send(&sbp_state, 0x41, 33079, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 33079, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 33079, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x41, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_state_t* check_msg = + (msg_tracking_state_t*)((void*)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->states[0].cn0 == 102, + "incorrect value for states[0].cn0, expected 102, is %d", + check_msg->states[0].cn0); + ck_assert_msg(check_msg->states[0].fcn == 3, + "incorrect value for states[0].fcn, expected 3, is %d", + check_msg->states[0].fcn); + ck_assert_msg(check_msg->states[0].sid.code == 184, + "incorrect value for states[0].sid.code, expected 184, is %d", + check_msg->states[0].sid.code); + ck_assert_msg(check_msg->states[0].sid.sat == 117, + "incorrect value for states[0].sid.sat, expected 117, is %d", + check_msg->states[0].sid.sat); + ck_assert_msg(check_msg->states[1].cn0 == 141, + "incorrect value for states[1].cn0, expected 141, is %d", + check_msg->states[1].cn0); + ck_assert_msg(check_msg->states[1].fcn == 140, + "incorrect value for states[1].fcn, expected 140, is %d", + check_msg->states[1].fcn); + ck_assert_msg(check_msg->states[1].sid.code == 106, + "incorrect value for states[1].sid.code, expected 106, is %d", + check_msg->states[1].sid.code); + ck_assert_msg(check_msg->states[1].sid.sat == 38, + "incorrect value for states[1].sid.sat, expected 38, is %d", + check_msg->states[1].sid.sat); + ck_assert_msg(check_msg->states[2].cn0 == 195, + "incorrect value for states[2].cn0, expected 195, is %d", + check_msg->states[2].cn0); + ck_assert_msg(check_msg->states[2].fcn == 90, + "incorrect value for states[2].fcn, expected 90, is %d", + check_msg->states[2].fcn); + ck_assert_msg(check_msg->states[2].sid.code == 4, + "incorrect value for states[2].sid.code, expected 4, is %d", + check_msg->states[2].sid.code); + ck_assert_msg(check_msg->states[2].sid.sat == 25, + "incorrect value for states[2].sid.sat, expected 25, is %d", + check_msg->states[2].sid.sat); + ck_assert_msg(check_msg->states[3].cn0 == 82, + "incorrect value for states[3].cn0, expected 82, is %d", + check_msg->states[3].cn0); + ck_assert_msg(check_msg->states[3].fcn == 75, + "incorrect value for states[3].fcn, expected 75, is %d", + check_msg->states[3].fcn); + ck_assert_msg(check_msg->states[3].sid.code == 108, + "incorrect value for states[3].sid.code, expected 108, is %d", + check_msg->states[3].sid.code); + ck_assert_msg(check_msg->states[3].sid.sat == 246, + "incorrect value for states[3].sid.sat, expected 246, is %d", + check_msg->states[3].sid.sat); + ck_assert_msg(check_msg->states[4].cn0 == 163, + "incorrect value for states[4].cn0, expected 163, is %d", + check_msg->states[4].cn0); + ck_assert_msg(check_msg->states[4].fcn == 45, + "incorrect value for states[4].fcn, expected 45, is %d", + check_msg->states[4].fcn); + ck_assert_msg(check_msg->states[4].sid.code == 127, + "incorrect value for states[4].sid.code, expected 127, is %d", + check_msg->states[4].sid.code); + ck_assert_msg(check_msg->states[4].sid.sat == 137, + "incorrect value for states[4].sid.sat, expected 137, is %d", + check_msg->states[4].sid.sat); + ck_assert_msg(check_msg->states[5].cn0 == 93, + "incorrect value for states[5].cn0, expected 93, is %d", + check_msg->states[5].cn0); + ck_assert_msg(check_msg->states[5].fcn == 187, + "incorrect value for states[5].fcn, expected 187, is %d", + check_msg->states[5].fcn); + ck_assert_msg(check_msg->states[5].sid.code == 46, + "incorrect value for states[5].sid.code, expected 46, is %d", + check_msg->states[5].sid.code); + ck_assert_msg(check_msg->states[5].sid.sat == 32, + "incorrect value for states[5].sid.sat, expected 32, is %d", + check_msg->states[5].sid.sat); + ck_assert_msg(check_msg->states[6].cn0 == 147, + "incorrect value for states[6].cn0, expected 147, is %d", + check_msg->states[6].cn0); + ck_assert_msg(check_msg->states[6].fcn == 201, + "incorrect value for states[6].fcn, expected 201, is %d", + check_msg->states[6].fcn); + ck_assert_msg(check_msg->states[6].sid.code == 60, + "incorrect value for states[6].sid.code, expected 60, is %d", + check_msg->states[6].sid.code); + ck_assert_msg(check_msg->states[6].sid.sat == 153, + "incorrect value for states[6].sid.sat, expected 153, is %d", + check_msg->states[6].sid.sat); + ck_assert_msg(check_msg->states[7].cn0 == 208, + "incorrect value for states[7].cn0, expected 208, is %d", + check_msg->states[7].cn0); + ck_assert_msg(check_msg->states[7].fcn == 5, + "incorrect value for states[7].fcn, expected 5, is %d", + check_msg->states[7].fcn); + ck_assert_msg(check_msg->states[7].sid.code == 29, + "incorrect value for states[7].sid.code, expected 29, is %d", + check_msg->states[7].sid.code); + ck_assert_msg(check_msg->states[7].sid.sat == 23, + "incorrect value for states[7].sid.sat, expected 23, is %d", + check_msg->states[7].sid.sat); + ck_assert_msg(check_msg->states[8].cn0 == 69, + "incorrect value for states[8].cn0, expected 69, is %d", + check_msg->states[8].cn0); + ck_assert_msg(check_msg->states[8].fcn == 219, + "incorrect value for states[8].fcn, expected 219, is %d", + check_msg->states[8].fcn); + ck_assert_msg(check_msg->states[8].sid.code == 30, + "incorrect value for states[8].sid.code, expected 30, is %d", + check_msg->states[8].sid.code); + ck_assert_msg(check_msg->states[8].sid.sat == 181, + "incorrect value for states[8].sid.sat, expected 181, is %d", + check_msg->states[8].sid.sat); + ck_assert_msg(check_msg->states[9].cn0 == 121, + "incorrect value for states[9].cn0, expected 121, is %d", + check_msg->states[9].cn0); + ck_assert_msg(check_msg->states[9].fcn == 3, + "incorrect value for states[9].fcn, expected 3, is %d", + check_msg->states[9].fcn); + ck_assert_msg(check_msg->states[9].sid.code == 136, + "incorrect value for states[9].sid.code, expected 136, is %d", + check_msg->states[9].sid.code); + ck_assert_msg(check_msg->states[9].sid.sat == 254, + "incorrect value for states[9].sid.sat, expected 254, is %d", + check_msg->states[9].sid.sat); + ck_assert_msg(check_msg->states[10].cn0 == 215, + "incorrect value for states[10].cn0, expected 215, is %d", + check_msg->states[10].cn0); + ck_assert_msg(check_msg->states[10].fcn == 144, + "incorrect value for states[10].fcn, expected 144, is %d", + check_msg->states[10].fcn); + ck_assert_msg(check_msg->states[10].sid.code == 98, + "incorrect value for states[10].sid.code, expected 98, is %d", + check_msg->states[10].sid.code); + ck_assert_msg(check_msg->states[10].sid.sat == 33, + "incorrect value for states[10].sid.sat, expected 33, is %d", + check_msg->states[10].sid.sat); + ck_assert_msg(check_msg->states[11].cn0 == 56, + "incorrect value for states[11].cn0, expected 56, is %d", + check_msg->states[11].cn0); + ck_assert_msg(check_msg->states[11].fcn == 14, + "incorrect value for states[11].fcn, expected 14, is %d", + check_msg->states[11].fcn); + ck_assert_msg( + check_msg->states[11].sid.code == 182, + "incorrect value for states[11].sid.code, expected 182, is %d", + check_msg->states[11].sid.code); + ck_assert_msg(check_msg->states[11].sid.sat == 133, + "incorrect value for states[11].sid.sat, expected 133, is %d", + check_msg->states[11].sid.sat); + ck_assert_msg(check_msg->states[12].cn0 == 62, + "incorrect value for states[12].cn0, expected 62, is %d", + check_msg->states[12].cn0); + ck_assert_msg(check_msg->states[12].fcn == 218, + "incorrect value for states[12].fcn, expected 218, is %d", + check_msg->states[12].fcn); + ck_assert_msg(check_msg->states[12].sid.code == 77, + "incorrect value for states[12].sid.code, expected 77, is %d", + check_msg->states[12].sid.code); + ck_assert_msg(check_msg->states[12].sid.sat == 169, + "incorrect value for states[12].sid.sat, expected 169, is %d", + check_msg->states[12].sid.sat); + ck_assert_msg(check_msg->states[13].cn0 == 249, + "incorrect value for states[13].cn0, expected 249, is %d", + check_msg->states[13].cn0); + ck_assert_msg(check_msg->states[13].fcn == 171, + "incorrect value for states[13].fcn, expected 171, is %d", + check_msg->states[13].fcn); + ck_assert_msg(check_msg->states[13].sid.code == 84, + "incorrect value for states[13].sid.code, expected 84, is %d", + check_msg->states[13].sid.code); + ck_assert_msg(check_msg->states[13].sid.sat == 242, + "incorrect value for states[13].sid.sat, expected 242, is %d", + check_msg->states[13].sid.sat); + ck_assert_msg(check_msg->states[14].cn0 == 130, + "incorrect value for states[14].cn0, expected 130, is %d", + check_msg->states[14].cn0); + ck_assert_msg(check_msg->states[14].fcn == 131, + "incorrect value for states[14].fcn, expected 131, is %d", + check_msg->states[14].fcn); + ck_assert_msg( + check_msg->states[14].sid.code == 137, + "incorrect value for states[14].sid.code, expected 137, is %d", + check_msg->states[14].sid.code); + ck_assert_msg(check_msg->states[14].sid.sat == 152, + "incorrect value for states[14].sid.sat, expected 152, is %d", + check_msg->states[14].sid.sat); + ck_assert_msg(check_msg->states[15].cn0 == 68, + "incorrect value for states[15].cn0, expected 68, is %d", + check_msg->states[15].cn0); + ck_assert_msg(check_msg->states[15].fcn == 42, + "incorrect value for states[15].fcn, expected 42, is %d", + check_msg->states[15].fcn); + ck_assert_msg(check_msg->states[15].sid.code == 21, + "incorrect value for states[15].sid.code, expected 21, is %d", + check_msg->states[15].sid.code); + ck_assert_msg(check_msg->states[15].sid.sat == 193, + "incorrect value for states[15].sid.sat, expected 193, is %d", + check_msg->states[15].sid.sat); + ck_assert_msg(check_msg->states[16].cn0 == 227, + "incorrect value for states[16].cn0, expected 227, is %d", + check_msg->states[16].cn0); + ck_assert_msg(check_msg->states[16].fcn == 216, + "incorrect value for states[16].fcn, expected 216, is %d", + check_msg->states[16].fcn); + ck_assert_msg( + check_msg->states[16].sid.code == 227, + "incorrect value for states[16].sid.code, expected 227, is %d", + check_msg->states[16].sid.code); + ck_assert_msg(check_msg->states[16].sid.sat == 253, + "incorrect value for states[16].sid.sat, expected 253, is %d", + check_msg->states[16].sid.sat); + ck_assert_msg(check_msg->states[17].cn0 == 179, + "incorrect value for states[17].cn0, expected 179, is %d", + check_msg->states[17].cn0); + ck_assert_msg(check_msg->states[17].fcn == 210, + "incorrect value for states[17].fcn, expected 210, is %d", + check_msg->states[17].fcn); + ck_assert_msg(check_msg->states[17].sid.code == 26, + "incorrect value for states[17].sid.code, expected 26, is %d", + check_msg->states[17].sid.code); + ck_assert_msg(check_msg->states[17].sid.sat == 24, + "incorrect value for states[17].sid.sat, expected 24, is %d", + check_msg->states[17].sid.sat); + ck_assert_msg(check_msg->states[18].cn0 == 255, + "incorrect value for states[18].cn0, expected 255, is %d", + check_msg->states[18].cn0); + ck_assert_msg(check_msg->states[18].fcn == 227, + "incorrect value for states[18].fcn, expected 227, is %d", + check_msg->states[18].fcn); + ck_assert_msg(check_msg->states[18].sid.code == 15, + "incorrect value for states[18].sid.code, expected 15, is %d", + check_msg->states[18].sid.code); + ck_assert_msg(check_msg->states[18].sid.sat == 19, + "incorrect value for states[18].sid.sat, expected 19, is %d", + check_msg->states[18].sid.sat); + ck_assert_msg(check_msg->states[19].cn0 == 200, + "incorrect value for states[19].cn0, expected 200, is %d", + check_msg->states[19].cn0); + ck_assert_msg(check_msg->states[19].fcn == 187, + "incorrect value for states[19].fcn, expected 187, is %d", + check_msg->states[19].fcn); + ck_assert_msg(check_msg->states[19].sid.code == 75, + "incorrect value for states[19].sid.code, expected 75, is %d", + check_msg->states[19].sid.code); + ck_assert_msg(check_msg->states[19].sid.sat == 122, + "incorrect value for states[19].sid.sat, expected 122, is %d", + check_msg->states[19].sid.sat); + ck_assert_msg(check_msg->states[20].cn0 == 122, + "incorrect value for states[20].cn0, expected 122, is %d", + check_msg->states[20].cn0); + ck_assert_msg(check_msg->states[20].fcn == 218, + "incorrect value for states[20].fcn, expected 218, is %d", + check_msg->states[20].fcn); + ck_assert_msg(check_msg->states[20].sid.code == 48, + "incorrect value for states[20].sid.code, expected 48, is %d", + check_msg->states[20].sid.code); + ck_assert_msg(check_msg->states[20].sid.sat == 217, + "incorrect value for states[20].sid.sat, expected 217, is %d", + check_msg->states[20].sid.sat); + ck_assert_msg(check_msg->states[21].cn0 == 149, + "incorrect value for states[21].cn0, expected 149, is %d", + check_msg->states[21].cn0); + ck_assert_msg(check_msg->states[21].fcn == 142, + "incorrect value for states[21].fcn, expected 142, is %d", + check_msg->states[21].fcn); + ck_assert_msg( + check_msg->states[21].sid.code == 238, + "incorrect value for states[21].sid.code, expected 238, is %d", + check_msg->states[21].sid.code); + ck_assert_msg(check_msg->states[21].sid.sat == 187, + "incorrect value for states[21].sid.sat, expected 187, is %d", + check_msg->states[21].sid.sat); + ck_assert_msg(check_msg->states[22].cn0 == 212, + "incorrect value for states[22].cn0, expected 212, is %d", + check_msg->states[22].cn0); + ck_assert_msg(check_msg->states[22].fcn == 251, + "incorrect value for states[22].fcn, expected 251, is %d", + check_msg->states[22].fcn); + ck_assert_msg(check_msg->states[22].sid.code == 55, + "incorrect value for states[22].sid.code, expected 55, is %d", + check_msg->states[22].sid.code); + ck_assert_msg(check_msg->states[22].sid.sat == 238, + "incorrect value for states[22].sid.sat, expected 238, is %d", + check_msg->states[22].sid.sat); + ck_assert_msg(check_msg->states[23].cn0 == 104, + "incorrect value for states[23].cn0, expected 104, is %d", + check_msg->states[23].cn0); + ck_assert_msg(check_msg->states[23].fcn == 194, + "incorrect value for states[23].fcn, expected 194, is %d", + check_msg->states[23].fcn); + ck_assert_msg( + check_msg->states[23].sid.code == 160, + "incorrect value for states[23].sid.code, expected 160, is %d", + check_msg->states[23].sid.code); + ck_assert_msg(check_msg->states[23].sid.sat == 128, + "incorrect value for states[23].sid.sat, expected 128, is %d", + check_msg->states[23].sid.sat); + ck_assert_msg(check_msg->states[24].cn0 == 62, + "incorrect value for states[24].cn0, expected 62, is %d", + check_msg->states[24].cn0); + ck_assert_msg(check_msg->states[24].fcn == 141, + "incorrect value for states[24].fcn, expected 141, is %d", + check_msg->states[24].fcn); + ck_assert_msg( + check_msg->states[24].sid.code == 255, + "incorrect value for states[24].sid.code, expected 255, is %d", + check_msg->states[24].sid.code); + ck_assert_msg(check_msg->states[24].sid.sat == 113, + "incorrect value for states[24].sid.sat, expected 113, is %d", + check_msg->states[24].sid.sat); + ck_assert_msg(check_msg->states[25].cn0 == 39, + "incorrect value for states[25].cn0, expected 39, is %d", + check_msg->states[25].cn0); + ck_assert_msg(check_msg->states[25].fcn == 245, + "incorrect value for states[25].fcn, expected 245, is %d", + check_msg->states[25].fcn); + ck_assert_msg(check_msg->states[25].sid.code == 69, + "incorrect value for states[25].sid.code, expected 69, is %d", + check_msg->states[25].sid.code); + ck_assert_msg(check_msg->states[25].sid.sat == 43, + "incorrect value for states[25].sid.sat, expected 43, is %d", + check_msg->states[25].sid.sat); + ck_assert_msg(check_msg->states[26].cn0 == 56, + "incorrect value for states[26].cn0, expected 56, is %d", + check_msg->states[26].cn0); + ck_assert_msg(check_msg->states[26].fcn == 108, + "incorrect value for states[26].fcn, expected 108, is %d", + check_msg->states[26].fcn); + ck_assert_msg( + check_msg->states[26].sid.code == 230, + "incorrect value for states[26].sid.code, expected 230, is %d", + check_msg->states[26].sid.code); + ck_assert_msg(check_msg->states[26].sid.sat == 100, + "incorrect value for states[26].sid.sat, expected 100, is %d", + check_msg->states[26].sid.sat); + ck_assert_msg(check_msg->states[27].cn0 == 143, + "incorrect value for states[27].cn0, expected 143, is %d", + check_msg->states[27].cn0); + ck_assert_msg(check_msg->states[27].fcn == 149, + "incorrect value for states[27].fcn, expected 149, is %d", + check_msg->states[27].fcn); + ck_assert_msg(check_msg->states[27].sid.code == 68, + "incorrect value for states[27].sid.code, expected 68, is %d", + check_msg->states[27].sid.code); + ck_assert_msg(check_msg->states[27].sid.sat == 247, + "incorrect value for states[27].sid.sat, expected 247, is %d", + check_msg->states[27].sid.sat); + ck_assert_msg(check_msg->states[28].cn0 == 70, + "incorrect value for states[28].cn0, expected 70, is %d", + check_msg->states[28].cn0); + ck_assert_msg(check_msg->states[28].fcn == 233, + "incorrect value for states[28].fcn, expected 233, is %d", + check_msg->states[28].fcn); + ck_assert_msg( + check_msg->states[28].sid.code == 101, + "incorrect value for states[28].sid.code, expected 101, is %d", + check_msg->states[28].sid.code); + ck_assert_msg(check_msg->states[28].sid.sat == 137, + "incorrect value for states[28].sid.sat, expected 137, is %d", + check_msg->states[28].sid.sat); + ck_assert_msg(check_msg->states[29].cn0 == 110, + "incorrect value for states[29].cn0, expected 110, is %d", + check_msg->states[29].cn0); + ck_assert_msg(check_msg->states[29].fcn == 38, + "incorrect value for states[29].fcn, expected 38, is %d", + check_msg->states[29].fcn); + ck_assert_msg( + check_msg->states[29].sid.code == 165, + "incorrect value for states[29].sid.code, expected 165, is %d", + check_msg->states[29].sid.code); + ck_assert_msg(check_msg->states[29].sid.sat == 49, + "incorrect value for states[29].sid.sat, expected 49, is %d", + check_msg->states[29].sid.sat); + ck_assert_msg(check_msg->states[30].cn0 == 213, + "incorrect value for states[30].cn0, expected 213, is %d", + check_msg->states[30].cn0); + ck_assert_msg(check_msg->states[30].fcn == 80, + "incorrect value for states[30].fcn, expected 80, is %d", + check_msg->states[30].fcn); + ck_assert_msg( + check_msg->states[30].sid.code == 230, + "incorrect value for states[30].sid.code, expected 230, is %d", + check_msg->states[30].sid.code); + ck_assert_msg(check_msg->states[30].sid.sat == 218, + "incorrect value for states[30].sid.sat, expected 218, is %d", + check_msg->states[30].sid.sat); + ck_assert_msg(check_msg->states[31].cn0 == 128, + "incorrect value for states[31].cn0, expected 128, is %d", + check_msg->states[31].cn0); + ck_assert_msg(check_msg->states[31].fcn == 139, + "incorrect value for states[31].fcn, expected 139, is %d", + check_msg->states[31].fcn); + ck_assert_msg( + check_msg->states[31].sid.code == 179, + "incorrect value for states[31].sid.code, expected 179, is %d", + check_msg->states[31].sid.code); + ck_assert_msg(check_msg->states[31].sid.sat == 196, + "incorrect value for states[31].sid.sat, expected 196, is %d", + check_msg->states[31].sid.sat); + ck_assert_msg(check_msg->states[32].cn0 == 171, + "incorrect value for states[32].cn0, expected 171, is %d", + check_msg->states[32].cn0); + ck_assert_msg(check_msg->states[32].fcn == 196, + "incorrect value for states[32].fcn, expected 196, is %d", + check_msg->states[32].fcn); + ck_assert_msg( + check_msg->states[32].sid.code == 178, + "incorrect value for states[32].sid.code, expected 178, is %d", + check_msg->states[32].sid.code); + ck_assert_msg(check_msg->states[32].sid.sat == 15, + "incorrect value for states[32].sid.sat, expected 15, is %d", + check_msg->states[32].sid.sat); + ck_assert_msg(check_msg->states[33].cn0 == 194, + "incorrect value for states[33].cn0, expected 194, is %d", + check_msg->states[33].cn0); + ck_assert_msg(check_msg->states[33].fcn == 97, + "incorrect value for states[33].fcn, expected 97, is %d", + check_msg->states[33].fcn); + ck_assert_msg( + check_msg->states[33].sid.code == 212, + "incorrect value for states[33].sid.code, expected 212, is %d", + check_msg->states[33].sid.code); + ck_assert_msg(check_msg->states[33].sid.sat == 8, + "incorrect value for states[33].sid.sat, expected 8, is %d", + check_msg->states[33].sid.sat); + ck_assert_msg(check_msg->states[34].cn0 == 99, + "incorrect value for states[34].cn0, expected 99, is %d", + check_msg->states[34].cn0); + ck_assert_msg(check_msg->states[34].fcn == 79, + "incorrect value for states[34].fcn, expected 79, is %d", + check_msg->states[34].fcn); + ck_assert_msg( + check_msg->states[34].sid.code == 233, + "incorrect value for states[34].sid.code, expected 233, is %d", + check_msg->states[34].sid.code); + ck_assert_msg(check_msg->states[34].sid.sat == 83, + "incorrect value for states[34].sid.sat, expected 83, is %d", + check_msg->states[34].sid.sat); + ck_assert_msg(check_msg->states[35].cn0 == 180, + "incorrect value for states[35].cn0, expected 180, is %d", + check_msg->states[35].cn0); + ck_assert_msg(check_msg->states[35].fcn == 31, + "incorrect value for states[35].fcn, expected 31, is %d", + check_msg->states[35].fcn); + ck_assert_msg(check_msg->states[35].sid.code == 90, + "incorrect value for states[35].sid.code, expected 90, is %d", + check_msg->states[35].sid.code); + ck_assert_msg(check_msg->states[35].sid.sat == 55, + "incorrect value for states[35].sid.sat, expected 55, is %d", + check_msg->states[35].sid.sat); + ck_assert_msg(check_msg->states[36].cn0 == 186, + "incorrect value for states[36].cn0, expected 186, is %d", + check_msg->states[36].cn0); + ck_assert_msg(check_msg->states[36].fcn == 105, + "incorrect value for states[36].fcn, expected 105, is %d", + check_msg->states[36].fcn); + ck_assert_msg(check_msg->states[36].sid.code == 25, + "incorrect value for states[36].sid.code, expected 25, is %d", + check_msg->states[36].sid.code); + ck_assert_msg(check_msg->states[36].sid.sat == 5, + "incorrect value for states[36].sid.sat, expected 5, is %d", + check_msg->states[36].sid.sat); + ck_assert_msg(check_msg->states[37].cn0 == 111, + "incorrect value for states[37].cn0, expected 111, is %d", + check_msg->states[37].cn0); + ck_assert_msg(check_msg->states[37].fcn == 80, + "incorrect value for states[37].fcn, expected 80, is %d", + check_msg->states[37].fcn); + ck_assert_msg( + check_msg->states[37].sid.code == 224, + "incorrect value for states[37].sid.code, expected 224, is %d", + check_msg->states[37].sid.code); + ck_assert_msg(check_msg->states[37].sid.sat == 22, + "incorrect value for states[37].sid.sat, expected 22, is %d", + check_msg->states[37].sid.sat); + ck_assert_msg(check_msg->states[38].cn0 == 166, + "incorrect value for states[38].cn0, expected 166, is %d", + check_msg->states[38].cn0); + ck_assert_msg(check_msg->states[38].fcn == 106, + "incorrect value for states[38].fcn, expected 106, is %d", + check_msg->states[38].fcn); + ck_assert_msg(check_msg->states[38].sid.code == 48, + "incorrect value for states[38].sid.code, expected 48, is %d", + check_msg->states[38].sid.code); + ck_assert_msg(check_msg->states[38].sid.sat == 8, + "incorrect value for states[38].sid.sat, expected 8, is %d", + check_msg->states[38].sid.sat); + ck_assert_msg(check_msg->states[39].cn0 == 49, + "incorrect value for states[39].cn0, expected 49, is %d", + check_msg->states[39].cn0); + ck_assert_msg(check_msg->states[39].fcn == 156, + "incorrect value for states[39].fcn, expected 156, is %d", + check_msg->states[39].fcn); + ck_assert_msg(check_msg->states[39].sid.code == 48, + "incorrect value for states[39].sid.code, expected 48, is %d", + check_msg->states[39].sid.code); + ck_assert_msg(check_msg->states[39].sid.sat == 4, + "incorrect value for states[39].sid.sat, expected 4, is %d", + check_msg->states[39].sid.sat); + ck_assert_msg(check_msg->states[40].cn0 == 146, + "incorrect value for states[40].cn0, expected 146, is %d", + check_msg->states[40].cn0); + ck_assert_msg(check_msg->states[40].fcn == 142, + "incorrect value for states[40].fcn, expected 142, is %d", + check_msg->states[40].fcn); + ck_assert_msg(check_msg->states[40].sid.code == 19, + "incorrect value for states[40].sid.code, expected 19, is %d", + check_msg->states[40].sid.code); + ck_assert_msg(check_msg->states[40].sid.sat == 86, + "incorrect value for states[40].sid.sat, expected 86, is %d", + check_msg->states[40].sid.sat); + ck_assert_msg(check_msg->states[41].cn0 == 64, + "incorrect value for states[41].cn0, expected 64, is %d", + check_msg->states[41].cn0); + ck_assert_msg(check_msg->states[41].fcn == 115, + "incorrect value for states[41].fcn, expected 115, is %d", + check_msg->states[41].fcn); + ck_assert_msg( + check_msg->states[41].sid.code == 124, + "incorrect value for states[41].sid.code, expected 124, is %d", + check_msg->states[41].sid.code); + ck_assert_msg(check_msg->states[41].sid.sat == 91, + "incorrect value for states[41].sid.sat, expected 91, is %d", + check_msg->states[41].sid.sat); + ck_assert_msg(check_msg->states[42].cn0 == 178, + "incorrect value for states[42].cn0, expected 178, is %d", + check_msg->states[42].cn0); + ck_assert_msg(check_msg->states[42].fcn == 115, + "incorrect value for states[42].fcn, expected 115, is %d", + check_msg->states[42].fcn); + ck_assert_msg( + check_msg->states[42].sid.code == 230, + "incorrect value for states[42].sid.code, expected 230, is %d", + check_msg->states[42].sid.code); + ck_assert_msg(check_msg->states[42].sid.sat == 28, + "incorrect value for states[42].sid.sat, expected 28, is %d", + check_msg->states[42].sid.sat); + ck_assert_msg(check_msg->states[43].cn0 == 242, + "incorrect value for states[43].cn0, expected 242, is %d", + check_msg->states[43].cn0); + ck_assert_msg(check_msg->states[43].fcn == 16, + "incorrect value for states[43].fcn, expected 16, is %d", + check_msg->states[43].fcn); + ck_assert_msg( + check_msg->states[43].sid.code == 131, + "incorrect value for states[43].sid.code, expected 131, is %d", + check_msg->states[43].sid.code); + ck_assert_msg(check_msg->states[43].sid.sat == 190, + "incorrect value for states[43].sid.sat, expected 190, is %d", + check_msg->states[43].sid.sat); + ck_assert_msg(check_msg->states[44].cn0 == 113, + "incorrect value for states[44].cn0, expected 113, is %d", + check_msg->states[44].cn0); + ck_assert_msg(check_msg->states[44].fcn == 182, + "incorrect value for states[44].fcn, expected 182, is %d", + check_msg->states[44].fcn); + ck_assert_msg(check_msg->states[44].sid.code == 59, + "incorrect value for states[44].sid.code, expected 59, is %d", + check_msg->states[44].sid.code); + ck_assert_msg(check_msg->states[44].sid.sat == 105, + "incorrect value for states[44].sid.sat, expected 105, is %d", + check_msg->states[44].sid.sat); + ck_assert_msg(check_msg->states[45].cn0 == 179, + "incorrect value for states[45].cn0, expected 179, is %d", + check_msg->states[45].cn0); + ck_assert_msg(check_msg->states[45].fcn == 48, + "incorrect value for states[45].fcn, expected 48, is %d", + check_msg->states[45].fcn); + ck_assert_msg( + check_msg->states[45].sid.code == 180, + "incorrect value for states[45].sid.code, expected 180, is %d", + check_msg->states[45].sid.code); + ck_assert_msg(check_msg->states[45].sid.sat == 192, + "incorrect value for states[45].sid.sat, expected 192, is %d", + check_msg->states[45].sid.sat); + ck_assert_msg(check_msg->states[46].cn0 == 211, + "incorrect value for states[46].cn0, expected 211, is %d", + check_msg->states[46].cn0); + ck_assert_msg(check_msg->states[46].fcn == 172, + "incorrect value for states[46].fcn, expected 172, is %d", + check_msg->states[46].fcn); + ck_assert_msg(check_msg->states[46].sid.code == 31, + "incorrect value for states[46].sid.code, expected 31, is %d", + check_msg->states[46].sid.code); + ck_assert_msg(check_msg->states[46].sid.sat == 166, + "incorrect value for states[46].sid.sat, expected 166, is %d", + check_msg->states[46].sid.sat); + ck_assert_msg(check_msg->states[47].cn0 == 49, + "incorrect value for states[47].cn0, expected 49, is %d", + check_msg->states[47].cn0); + ck_assert_msg(check_msg->states[47].fcn == 140, + "incorrect value for states[47].fcn, expected 140, is %d", + check_msg->states[47].fcn); + ck_assert_msg( + check_msg->states[47].sid.code == 228, + "incorrect value for states[47].sid.code, expected 228, is %d", + check_msg->states[47].sid.code); + ck_assert_msg(check_msg->states[47].sid.sat == 77, + "incorrect value for states[47].sid.sat, expected 77, is %d", + check_msg->states[47].sid.sat); + ck_assert_msg(check_msg->states[48].cn0 == 194, + "incorrect value for states[48].cn0, expected 194, is %d", + check_msg->states[48].cn0); + ck_assert_msg(check_msg->states[48].fcn == 240, + "incorrect value for states[48].fcn, expected 240, is %d", + check_msg->states[48].fcn); + ck_assert_msg(check_msg->states[48].sid.code == 77, + "incorrect value for states[48].sid.code, expected 77, is %d", + check_msg->states[48].sid.code); + ck_assert_msg(check_msg->states[48].sid.sat == 128, + "incorrect value for states[48].sid.sat, expected 128, is %d", + check_msg->states[48].sid.sat); + ck_assert_msg(check_msg->states[49].cn0 == 58, + "incorrect value for states[49].cn0, expected 58, is %d", + check_msg->states[49].cn0); + ck_assert_msg(check_msg->states[49].fcn == 41, + "incorrect value for states[49].fcn, expected 41, is %d", + check_msg->states[49].fcn); + ck_assert_msg( + check_msg->states[49].sid.code == 194, + "incorrect value for states[49].sid.code, expected 194, is %d", + check_msg->states[49].sid.code); + ck_assert_msg(check_msg->states[49].sid.sat == 134, + "incorrect value for states[49].sid.sat, expected 134, is %d", + check_msg->states[49].sid.sat); + ck_assert_msg(check_msg->states[50].cn0 == 55, + "incorrect value for states[50].cn0, expected 55, is %d", + check_msg->states[50].cn0); + ck_assert_msg(check_msg->states[50].fcn == 129, + "incorrect value for states[50].fcn, expected 129, is %d", + check_msg->states[50].fcn); + ck_assert_msg(check_msg->states[50].sid.code == 53, + "incorrect value for states[50].sid.code, expected 53, is %d", + check_msg->states[50].sid.code); + ck_assert_msg(check_msg->states[50].sid.sat == 18, + "incorrect value for states[50].sid.sat, expected 18, is %d", + check_msg->states[50].sid.sat); + ck_assert_msg(check_msg->states[51].cn0 == 92, + "incorrect value for states[51].cn0, expected 92, is %d", + check_msg->states[51].cn0); + ck_assert_msg(check_msg->states[51].fcn == 134, + "incorrect value for states[51].fcn, expected 134, is %d", + check_msg->states[51].fcn); + ck_assert_msg(check_msg->states[51].sid.code == 72, + "incorrect value for states[51].sid.code, expected 72, is %d", + check_msg->states[51].sid.code); + ck_assert_msg(check_msg->states[51].sid.sat == 91, + "incorrect value for states[51].sid.sat, expected 91, is %d", + check_msg->states[51].sid.sat); + ck_assert_msg(check_msg->states[52].cn0 == 56, + "incorrect value for states[52].cn0, expected 56, is %d", + check_msg->states[52].cn0); + ck_assert_msg(check_msg->states[52].fcn == 157, + "incorrect value for states[52].fcn, expected 157, is %d", + check_msg->states[52].fcn); + ck_assert_msg( + check_msg->states[52].sid.code == 224, + "incorrect value for states[52].sid.code, expected 224, is %d", + check_msg->states[52].sid.code); + ck_assert_msg(check_msg->states[52].sid.sat == 33, + "incorrect value for states[52].sid.sat, expected 33, is %d", + check_msg->states[52].sid.sat); + ck_assert_msg(check_msg->states[53].cn0 == 174, + "incorrect value for states[53].cn0, expected 174, is %d", + check_msg->states[53].cn0); + ck_assert_msg(check_msg->states[53].fcn == 224, + "incorrect value for states[53].fcn, expected 224, is %d", + check_msg->states[53].fcn); + ck_assert_msg(check_msg->states[53].sid.code == 54, + "incorrect value for states[53].sid.code, expected 54, is %d", + check_msg->states[53].sid.code); + ck_assert_msg(check_msg->states[53].sid.sat == 186, + "incorrect value for states[53].sid.sat, expected 186, is %d", + check_msg->states[53].sid.sat); + ck_assert_msg(check_msg->states[54].cn0 == 190, + "incorrect value for states[54].cn0, expected 190, is %d", + check_msg->states[54].cn0); + ck_assert_msg(check_msg->states[54].fcn == 148, + "incorrect value for states[54].fcn, expected 148, is %d", + check_msg->states[54].fcn); + ck_assert_msg(check_msg->states[54].sid.code == 84, + "incorrect value for states[54].sid.code, expected 84, is %d", + check_msg->states[54].sid.code); + ck_assert_msg(check_msg->states[54].sid.sat == 82, + "incorrect value for states[54].sid.sat, expected 82, is %d", + check_msg->states[54].sid.sat); + ck_assert_msg(check_msg->states[55].cn0 == 67, + "incorrect value for states[55].cn0, expected 67, is %d", + check_msg->states[55].cn0); + ck_assert_msg(check_msg->states[55].fcn == 62, + "incorrect value for states[55].fcn, expected 62, is %d", + check_msg->states[55].fcn); + ck_assert_msg(check_msg->states[55].sid.code == 54, + "incorrect value for states[55].sid.code, expected 54, is %d", + check_msg->states[55].sid.code); + ck_assert_msg(check_msg->states[55].sid.sat == 236, + "incorrect value for states[55].sid.sat, expected 236, is %d", + check_msg->states[55].sid.sat); + ck_assert_msg(check_msg->states[56].cn0 == 254, + "incorrect value for states[56].cn0, expected 254, is %d", + check_msg->states[56].cn0); + ck_assert_msg(check_msg->states[56].fcn == 57, + "incorrect value for states[56].fcn, expected 57, is %d", + check_msg->states[56].fcn); + ck_assert_msg( + check_msg->states[56].sid.code == 215, + "incorrect value for states[56].sid.code, expected 215, is %d", + check_msg->states[56].sid.code); + ck_assert_msg(check_msg->states[56].sid.sat == 52, + "incorrect value for states[56].sid.sat, expected 52, is %d", + check_msg->states[56].sid.sat); + ck_assert_msg(check_msg->states[57].cn0 == 174, + "incorrect value for states[57].cn0, expected 174, is %d", + check_msg->states[57].cn0); + ck_assert_msg(check_msg->states[57].fcn == 36, + "incorrect value for states[57].fcn, expected 36, is %d", + check_msg->states[57].fcn); + ck_assert_msg( + check_msg->states[57].sid.code == 133, + "incorrect value for states[57].sid.code, expected 133, is %d", + check_msg->states[57].sid.code); + ck_assert_msg(check_msg->states[57].sid.sat == 16, + "incorrect value for states[57].sid.sat, expected 16, is %d", + check_msg->states[57].sid.sat); + ck_assert_msg(check_msg->states[58].cn0 == 17, + "incorrect value for states[58].cn0, expected 17, is %d", + check_msg->states[58].cn0); + ck_assert_msg(check_msg->states[58].fcn == 145, + "incorrect value for states[58].fcn, expected 145, is %d", + check_msg->states[58].fcn); + ck_assert_msg( + check_msg->states[58].sid.code == 172, + "incorrect value for states[58].sid.code, expected 172, is %d", + check_msg->states[58].sid.code); + ck_assert_msg(check_msg->states[58].sid.sat == 219, + "incorrect value for states[58].sid.sat, expected 219, is %d", + check_msg->states[58].sid.sat); + ck_assert_msg(check_msg->states[59].cn0 == 97, + "incorrect value for states[59].cn0, expected 97, is %d", + check_msg->states[59].cn0); + ck_assert_msg(check_msg->states[59].fcn == 111, + "incorrect value for states[59].fcn, expected 111, is %d", + check_msg->states[59].fcn); + ck_assert_msg( + check_msg->states[59].sid.code == 179, + "incorrect value for states[59].sid.code, expected 179, is %d", + check_msg->states[59].sid.code); + ck_assert_msg(check_msg->states[59].sid.sat == 192, + "incorrect value for states[59].sid.sat, expected 192, is %d", + check_msg->states[59].sid.sat); + ck_assert_msg(check_msg->states[60].cn0 == 134, + "incorrect value for states[60].cn0, expected 134, is %d", + check_msg->states[60].cn0); + ck_assert_msg(check_msg->states[60].fcn == 208, + "incorrect value for states[60].fcn, expected 208, is %d", + check_msg->states[60].fcn); + ck_assert_msg(check_msg->states[60].sid.code == 56, + "incorrect value for states[60].sid.code, expected 56, is %d", + check_msg->states[60].sid.code); + ck_assert_msg(check_msg->states[60].sid.sat == 207, + "incorrect value for states[60].sid.sat, expected 207, is %d", + check_msg->states[60].sid.sat); + ck_assert_msg(check_msg->states[61].cn0 == 226, + "incorrect value for states[61].cn0, expected 226, is %d", + check_msg->states[61].cn0); + ck_assert_msg(check_msg->states[61].fcn == 43, + "incorrect value for states[61].fcn, expected 43, is %d", + check_msg->states[61].fcn); + ck_assert_msg(check_msg->states[61].sid.code == 17, + "incorrect value for states[61].sid.code, expected 17, is %d", + check_msg->states[61].sid.code); + ck_assert_msg(check_msg->states[61].sid.sat == 180, + "incorrect value for states[61].sid.sat, expected 180, is %d", + check_msg->states[61].sid.sat); + ck_assert_msg(check_msg->states[62].cn0 == 113, + "incorrect value for states[62].cn0, expected 113, is %d", + check_msg->states[62].cn0); + ck_assert_msg(check_msg->states[62].fcn == 140, + "incorrect value for states[62].fcn, expected 140, is %d", + check_msg->states[62].fcn); + ck_assert_msg( + check_msg->states[62].sid.code == 182, + "incorrect value for states[62].sid.code, expected 182, is %d", + check_msg->states[62].sid.code); + ck_assert_msg(check_msg->states[62].sid.sat == 255, + "incorrect value for states[62].sid.sat, expected 255, is %d", + check_msg->states[62].sid.sat); + } + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + sbp_payload_callback_register(&sbp_state, 0x13, &msg_callback, &DUMMY_MEMORY_FOR_CALLBACKS, &n); sbp_frame_callback_register(&sbp_state, 0x13, &frame_callback, diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDepB.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDepB.c new file mode 100644 index 0000000000..84bd4cdbd4 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDepB.c @@ -0,0 +1,989 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x13, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x13, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, + 69, 255, 175, 121, 43, 222, 51, 67, 35, 69, 78, 240, 5, 53, + 20, 51, 211, 54, 69, 153, 130, 237, 66, 155, 51, 227, 71, 69, + 53, 242, 136, 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, + 154, 217, 184, 69, 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, + 115, 141, 27, 12, 154, 225, 200, 69, 208, 44, 147, 39, 23, 51, + 3, 66, 69, 237, 159, 251, 49, 203, 51, 99, 102, 69, 70, 214, + 87, 128, 206, 154, 121, 186, 69, 14, 206, 111, 218, 19, 154, 121, + 169, 69, 216, 98, 209, 54, 2, 154, 25, 219, 67, 200, 133, 99, + 7, 34, 102, 198, 232, 68, 155, 43, 85, 135, 46, 154, 177, 170, + 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, 121, 43, 197, 16, + 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, 115, 66, 69, + 36, 20, 61, 153, 51, 154, 73, 134, 69, 46, 82, 116, 140, 22, + 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, 76, 107, 68, 220, + 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, + 135, 186, 171, 51, 163, 4, 69, 18, 124, 155, 85, 170, 205, 208, + 13, 70, 57, 244, 206, 255, 186, 154, 105, 149, 69, 165, 199, 93, + 181, 175, 51, 67, 64, 69, 6, 28, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_state_dep_b_t *test_msg = + (msg_tracking_state_dep_b_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[0].cn0 = 5856.2001953125; + test_msg->states[0].sid.code = 63; + test_msg->states[0].sid.reserved = 68; + test_msg->states[0].sid.sat = 58295; + test_msg->states[0].state = 115; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[1].cn0 = 2612.199951171875; + test_msg->states[1].sid.code = 43; + test_msg->states[1].sid.reserved = 222; + test_msg->states[1].sid.sat = 31151; + test_msg->states[1].state = 255; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[2].cn0 = 2925.199951171875; + test_msg->states[2].sid.code = 53; + test_msg->states[2].sid.reserved = 20; + test_msg->states[2].sid.sat = 1520; + test_msg->states[2].state = 78; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[3].cn0 = 3198.199951171875; + test_msg->states[3].sid.code = 66; + test_msg->states[3].sid.reserved = 155; + test_msg->states[3].sid.sat = 60802; + test_msg->states[3].state = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[4].cn0 = 8623.2001953125; + test_msg->states[4].sid.code = 161; + test_msg->states[4].sid.reserved = 190; + test_msg->states[4].sid.sat = 35058; + test_msg->states[4].state = 53; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[5].cn0 = 5915.2001953125; + test_msg->states[5].sid.code = 142; + test_msg->states[5].sid.reserved = 149; + test_msg->states[5].sid.sat = 65405; + test_msg->states[5].state = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[6].cn0 = 5412.2001953125; + test_msg->states[6].sid.code = 31; + test_msg->states[6].sid.reserved = 76; + test_msg->states[6].sid.sat = 24422; + test_msg->states[6].state = 248; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[7].cn0 = 6428.2001953125; + test_msg->states[7].sid.code = 27; + test_msg->states[7].sid.reserved = 12; + test_msg->states[7].sid.sat = 36211; + test_msg->states[7].state = 131; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[8].cn0 = 3104.199951171875; + test_msg->states[8].sid.code = 39; + test_msg->states[8].sid.reserved = 23; + test_msg->states[8].sid.sat = 37676; + test_msg->states[8].state = 208; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[9].cn0 = 3686.199951171875; + test_msg->states[9].sid.code = 49; + test_msg->states[9].sid.reserved = 203; + test_msg->states[9].sid.sat = 64415; + test_msg->states[9].state = 237; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[10].cn0 = 5967.2001953125; + test_msg->states[10].sid.code = 128; + test_msg->states[10].sid.reserved = 206; + test_msg->states[10].sid.sat = 22486; + test_msg->states[10].state = 70; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[11].cn0 = 5423.2001953125; + test_msg->states[11].sid.code = 218; + test_msg->states[11].sid.reserved = 19; + test_msg->states[11].sid.sat = 28622; + test_msg->states[11].state = 14; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[12].cn0 = 438.20001220703125; + test_msg->states[12].sid.code = 54; + test_msg->states[12].sid.reserved = 2; + test_msg->states[12].sid.sat = 53602; + test_msg->states[12].state = 216; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[13].cn0 = 1862.199951171875; + test_msg->states[13].sid.code = 7; + test_msg->states[13].sid.reserved = 34; + test_msg->states[13].sid.sat = 25477; + test_msg->states[13].state = 200; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[14].cn0 = 5462.2001953125; + test_msg->states[14].sid.code = 135; + test_msg->states[14].sid.reserved = 46; + test_msg->states[14].sid.sat = 21803; + test_msg->states[14].state = 155; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[15].cn0 = 7454.2001953125; + test_msg->states[15].sid.code = 171; + test_msg->states[15].sid.reserved = 201; + test_msg->states[15].sid.sat = 21251; + test_msg->states[15].state = 155; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[16].cn0 = 7134.2001953125; + test_msg->states[16].sid.code = 16; + test_msg->states[16].sid.reserved = 19; + test_msg->states[16].sid.sat = 50475; + test_msg->states[16].state = 121; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[17].cn0 = 3111.199951171875; + test_msg->states[17].sid.code = 63; + test_msg->states[17].sid.reserved = 176; + test_msg->states[17].sid.sat = 13813; + test_msg->states[17].state = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[18].cn0 = 4297.2001953125; + test_msg->states[18].sid.code = 153; + test_msg->states[18].sid.reserved = 51; + test_msg->states[18].sid.sat = 15636; + test_msg->states[18].state = 36; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[19].cn0 = 2649.199951171875; + test_msg->states[19].sid.code = 140; + test_msg->states[19].sid.reserved = 22; + test_msg->states[19].sid.sat = 29778; + test_msg->states[19].state = 46; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[20].cn0 = 941.2000122070312; + test_msg->states[20].sid.code = 96; + test_msg->states[20].sid.reserved = 143; + test_msg->states[20].sid.sat = 37443; + test_msg->states[20].state = 177; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[21].cn0 = 1539.199951171875; + test_msg->states[21].sid.code = 201; + test_msg->states[21].sid.reserved = 251; + test_msg->states[21].sid.sat = 41011; + test_msg->states[21].state = 220; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[22].cn0 = 1443.199951171875; + test_msg->states[22].sid.code = 161; + test_msg->states[22].sid.reserved = 220; + test_msg->states[22].sid.sat = 706; + test_msg->states[22].state = 168; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[23].cn0 = 1074.199951171875; + test_msg->states[23].sid.code = 125; + test_msg->states[23].sid.reserved = 178; + test_msg->states[23].sid.sat = 2312; + test_msg->states[23].state = 69; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[24].cn0 = 2122.199951171875; + test_msg->states[24].sid.code = 186; + test_msg->states[24].sid.reserved = 171; + test_msg->states[24].sid.sat = 34580; + test_msg->states[24].state = 185; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[25].cn0 = 9076.2001953125; + test_msg->states[25].sid.code = 85; + test_msg->states[25].sid.reserved = 170; + test_msg->states[25].sid.sat = 39804; + test_msg->states[25].state = 18; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[26].cn0 = 4781.2001953125; + test_msg->states[26].sid.code = 255; + test_msg->states[26].sid.reserved = 186; + test_msg->states[26].sid.sat = 52980; + test_msg->states[26].state = 57; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->states[0]); + } + test_msg->states[27].cn0 = 3076.199951171875; + test_msg->states[27].sid.code = 181; + test_msg->states[27].sid.reserved = 175; + test_msg->states[27].sid.sat = 24007; + test_msg->states[27].state = 165; + sbp_payload_send(&sbp_state, 0x13, 61938, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 61938, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 61938, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x13, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_state_dep_b_t *check_msg = + (msg_tracking_state_dep_b_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg( + (check_msg->states[0].cn0 * 100 - 5856.20019531 * 100) < 0.05, + "incorrect value for states[0].cn0, expected 5856.20019531, is %f", + check_msg->states[0].cn0); + ck_assert_msg(check_msg->states[0].sid.code == 63, + "incorrect value for states[0].sid.code, expected 63, is %d", + check_msg->states[0].sid.code); + ck_assert_msg( + check_msg->states[0].sid.reserved == 68, + "incorrect value for states[0].sid.reserved, expected 68, is %d", + check_msg->states[0].sid.reserved); + ck_assert_msg( + check_msg->states[0].sid.sat == 58295, + "incorrect value for states[0].sid.sat, expected 58295, is %d", + check_msg->states[0].sid.sat); + ck_assert_msg(check_msg->states[0].state == 115, + "incorrect value for states[0].state, expected 115, is %d", + check_msg->states[0].state); + ck_assert_msg( + (check_msg->states[1].cn0 * 100 - 2612.19995117 * 100) < 0.05, + "incorrect value for states[1].cn0, expected 2612.19995117, is %f", + check_msg->states[1].cn0); + ck_assert_msg(check_msg->states[1].sid.code == 43, + "incorrect value for states[1].sid.code, expected 43, is %d", + check_msg->states[1].sid.code); + ck_assert_msg( + check_msg->states[1].sid.reserved == 222, + "incorrect value for states[1].sid.reserved, expected 222, is %d", + check_msg->states[1].sid.reserved); + ck_assert_msg( + check_msg->states[1].sid.sat == 31151, + "incorrect value for states[1].sid.sat, expected 31151, is %d", + check_msg->states[1].sid.sat); + ck_assert_msg(check_msg->states[1].state == 255, + "incorrect value for states[1].state, expected 255, is %d", + check_msg->states[1].state); + ck_assert_msg( + (check_msg->states[2].cn0 * 100 - 2925.19995117 * 100) < 0.05, + "incorrect value for states[2].cn0, expected 2925.19995117, is %f", + check_msg->states[2].cn0); + ck_assert_msg(check_msg->states[2].sid.code == 53, + "incorrect value for states[2].sid.code, expected 53, is %d", + check_msg->states[2].sid.code); + ck_assert_msg( + check_msg->states[2].sid.reserved == 20, + "incorrect value for states[2].sid.reserved, expected 20, is %d", + check_msg->states[2].sid.reserved); + ck_assert_msg(check_msg->states[2].sid.sat == 1520, + "incorrect value for states[2].sid.sat, expected 1520, is %d", + check_msg->states[2].sid.sat); + ck_assert_msg(check_msg->states[2].state == 78, + "incorrect value for states[2].state, expected 78, is %d", + check_msg->states[2].state); + ck_assert_msg( + (check_msg->states[3].cn0 * 100 - 3198.19995117 * 100) < 0.05, + "incorrect value for states[3].cn0, expected 3198.19995117, is %f", + check_msg->states[3].cn0); + ck_assert_msg(check_msg->states[3].sid.code == 66, + "incorrect value for states[3].sid.code, expected 66, is %d", + check_msg->states[3].sid.code); + ck_assert_msg( + check_msg->states[3].sid.reserved == 155, + "incorrect value for states[3].sid.reserved, expected 155, is %d", + check_msg->states[3].sid.reserved); + ck_assert_msg( + check_msg->states[3].sid.sat == 60802, + "incorrect value for states[3].sid.sat, expected 60802, is %d", + check_msg->states[3].sid.sat); + ck_assert_msg(check_msg->states[3].state == 153, + "incorrect value for states[3].state, expected 153, is %d", + check_msg->states[3].state); + ck_assert_msg( + (check_msg->states[4].cn0 * 100 - 8623.20019531 * 100) < 0.05, + "incorrect value for states[4].cn0, expected 8623.20019531, is %f", + check_msg->states[4].cn0); + ck_assert_msg(check_msg->states[4].sid.code == 161, + "incorrect value for states[4].sid.code, expected 161, is %d", + check_msg->states[4].sid.code); + ck_assert_msg( + check_msg->states[4].sid.reserved == 190, + "incorrect value for states[4].sid.reserved, expected 190, is %d", + check_msg->states[4].sid.reserved); + ck_assert_msg( + check_msg->states[4].sid.sat == 35058, + "incorrect value for states[4].sid.sat, expected 35058, is %d", + check_msg->states[4].sid.sat); + ck_assert_msg(check_msg->states[4].state == 53, + "incorrect value for states[4].state, expected 53, is %d", + check_msg->states[4].state); + ck_assert_msg( + (check_msg->states[5].cn0 * 100 - 5915.20019531 * 100) < 0.05, + "incorrect value for states[5].cn0, expected 5915.20019531, is %f", + check_msg->states[5].cn0); + ck_assert_msg(check_msg->states[5].sid.code == 142, + "incorrect value for states[5].sid.code, expected 142, is %d", + check_msg->states[5].sid.code); + ck_assert_msg( + check_msg->states[5].sid.reserved == 149, + "incorrect value for states[5].sid.reserved, expected 149, is %d", + check_msg->states[5].sid.reserved); + ck_assert_msg( + check_msg->states[5].sid.sat == 65405, + "incorrect value for states[5].sid.sat, expected 65405, is %d", + check_msg->states[5].sid.sat); + ck_assert_msg(check_msg->states[5].state == 153, + "incorrect value for states[5].state, expected 153, is %d", + check_msg->states[5].state); + ck_assert_msg( + (check_msg->states[6].cn0 * 100 - 5412.20019531 * 100) < 0.05, + "incorrect value for states[6].cn0, expected 5412.20019531, is %f", + check_msg->states[6].cn0); + ck_assert_msg(check_msg->states[6].sid.code == 31, + "incorrect value for states[6].sid.code, expected 31, is %d", + check_msg->states[6].sid.code); + ck_assert_msg( + check_msg->states[6].sid.reserved == 76, + "incorrect value for states[6].sid.reserved, expected 76, is %d", + check_msg->states[6].sid.reserved); + ck_assert_msg( + check_msg->states[6].sid.sat == 24422, + "incorrect value for states[6].sid.sat, expected 24422, is %d", + check_msg->states[6].sid.sat); + ck_assert_msg(check_msg->states[6].state == 248, + "incorrect value for states[6].state, expected 248, is %d", + check_msg->states[6].state); + ck_assert_msg( + (check_msg->states[7].cn0 * 100 - 6428.20019531 * 100) < 0.05, + "incorrect value for states[7].cn0, expected 6428.20019531, is %f", + check_msg->states[7].cn0); + ck_assert_msg(check_msg->states[7].sid.code == 27, + "incorrect value for states[7].sid.code, expected 27, is %d", + check_msg->states[7].sid.code); + ck_assert_msg( + check_msg->states[7].sid.reserved == 12, + "incorrect value for states[7].sid.reserved, expected 12, is %d", + check_msg->states[7].sid.reserved); + ck_assert_msg( + check_msg->states[7].sid.sat == 36211, + "incorrect value for states[7].sid.sat, expected 36211, is %d", + check_msg->states[7].sid.sat); + ck_assert_msg(check_msg->states[7].state == 131, + "incorrect value for states[7].state, expected 131, is %d", + check_msg->states[7].state); + ck_assert_msg( + (check_msg->states[8].cn0 * 100 - 3104.19995117 * 100) < 0.05, + "incorrect value for states[8].cn0, expected 3104.19995117, is %f", + check_msg->states[8].cn0); + ck_assert_msg(check_msg->states[8].sid.code == 39, + "incorrect value for states[8].sid.code, expected 39, is %d", + check_msg->states[8].sid.code); + ck_assert_msg( + check_msg->states[8].sid.reserved == 23, + "incorrect value for states[8].sid.reserved, expected 23, is %d", + check_msg->states[8].sid.reserved); + ck_assert_msg( + check_msg->states[8].sid.sat == 37676, + "incorrect value for states[8].sid.sat, expected 37676, is %d", + check_msg->states[8].sid.sat); + ck_assert_msg(check_msg->states[8].state == 208, + "incorrect value for states[8].state, expected 208, is %d", + check_msg->states[8].state); + ck_assert_msg( + (check_msg->states[9].cn0 * 100 - 3686.19995117 * 100) < 0.05, + "incorrect value for states[9].cn0, expected 3686.19995117, is %f", + check_msg->states[9].cn0); + ck_assert_msg(check_msg->states[9].sid.code == 49, + "incorrect value for states[9].sid.code, expected 49, is %d", + check_msg->states[9].sid.code); + ck_assert_msg( + check_msg->states[9].sid.reserved == 203, + "incorrect value for states[9].sid.reserved, expected 203, is %d", + check_msg->states[9].sid.reserved); + ck_assert_msg( + check_msg->states[9].sid.sat == 64415, + "incorrect value for states[9].sid.sat, expected 64415, is %d", + check_msg->states[9].sid.sat); + ck_assert_msg(check_msg->states[9].state == 237, + "incorrect value for states[9].state, expected 237, is %d", + check_msg->states[9].state); + ck_assert_msg( + (check_msg->states[10].cn0 * 100 - 5967.20019531 * 100) < 0.05, + "incorrect value for states[10].cn0, expected 5967.20019531, is %f", + check_msg->states[10].cn0); + ck_assert_msg( + check_msg->states[10].sid.code == 128, + "incorrect value for states[10].sid.code, expected 128, is %d", + check_msg->states[10].sid.code); + ck_assert_msg( + check_msg->states[10].sid.reserved == 206, + "incorrect value for states[10].sid.reserved, expected 206, is %d", + check_msg->states[10].sid.reserved); + ck_assert_msg( + check_msg->states[10].sid.sat == 22486, + "incorrect value for states[10].sid.sat, expected 22486, is %d", + check_msg->states[10].sid.sat); + ck_assert_msg(check_msg->states[10].state == 70, + "incorrect value for states[10].state, expected 70, is %d", + check_msg->states[10].state); + ck_assert_msg( + (check_msg->states[11].cn0 * 100 - 5423.20019531 * 100) < 0.05, + "incorrect value for states[11].cn0, expected 5423.20019531, is %f", + check_msg->states[11].cn0); + ck_assert_msg( + check_msg->states[11].sid.code == 218, + "incorrect value for states[11].sid.code, expected 218, is %d", + check_msg->states[11].sid.code); + ck_assert_msg( + check_msg->states[11].sid.reserved == 19, + "incorrect value for states[11].sid.reserved, expected 19, is %d", + check_msg->states[11].sid.reserved); + ck_assert_msg( + check_msg->states[11].sid.sat == 28622, + "incorrect value for states[11].sid.sat, expected 28622, is %d", + check_msg->states[11].sid.sat); + ck_assert_msg(check_msg->states[11].state == 14, + "incorrect value for states[11].state, expected 14, is %d", + check_msg->states[11].state); + ck_assert_msg( + (check_msg->states[12].cn0 * 100 - 438.200012207 * 100) < 0.05, + "incorrect value for states[12].cn0, expected 438.200012207, is %f", + check_msg->states[12].cn0); + ck_assert_msg(check_msg->states[12].sid.code == 54, + "incorrect value for states[12].sid.code, expected 54, is %d", + check_msg->states[12].sid.code); + ck_assert_msg( + check_msg->states[12].sid.reserved == 2, + "incorrect value for states[12].sid.reserved, expected 2, is %d", + check_msg->states[12].sid.reserved); + ck_assert_msg( + check_msg->states[12].sid.sat == 53602, + "incorrect value for states[12].sid.sat, expected 53602, is %d", + check_msg->states[12].sid.sat); + ck_assert_msg(check_msg->states[12].state == 216, + "incorrect value for states[12].state, expected 216, is %d", + check_msg->states[12].state); + ck_assert_msg( + (check_msg->states[13].cn0 * 100 - 1862.19995117 * 100) < 0.05, + "incorrect value for states[13].cn0, expected 1862.19995117, is %f", + check_msg->states[13].cn0); + ck_assert_msg(check_msg->states[13].sid.code == 7, + "incorrect value for states[13].sid.code, expected 7, is %d", + check_msg->states[13].sid.code); + ck_assert_msg( + check_msg->states[13].sid.reserved == 34, + "incorrect value for states[13].sid.reserved, expected 34, is %d", + check_msg->states[13].sid.reserved); + ck_assert_msg( + check_msg->states[13].sid.sat == 25477, + "incorrect value for states[13].sid.sat, expected 25477, is %d", + check_msg->states[13].sid.sat); + ck_assert_msg(check_msg->states[13].state == 200, + "incorrect value for states[13].state, expected 200, is %d", + check_msg->states[13].state); + ck_assert_msg( + (check_msg->states[14].cn0 * 100 - 5462.20019531 * 100) < 0.05, + "incorrect value for states[14].cn0, expected 5462.20019531, is %f", + check_msg->states[14].cn0); + ck_assert_msg( + check_msg->states[14].sid.code == 135, + "incorrect value for states[14].sid.code, expected 135, is %d", + check_msg->states[14].sid.code); + ck_assert_msg( + check_msg->states[14].sid.reserved == 46, + "incorrect value for states[14].sid.reserved, expected 46, is %d", + check_msg->states[14].sid.reserved); + ck_assert_msg( + check_msg->states[14].sid.sat == 21803, + "incorrect value for states[14].sid.sat, expected 21803, is %d", + check_msg->states[14].sid.sat); + ck_assert_msg(check_msg->states[14].state == 155, + "incorrect value for states[14].state, expected 155, is %d", + check_msg->states[14].state); + ck_assert_msg( + (check_msg->states[15].cn0 * 100 - 7454.20019531 * 100) < 0.05, + "incorrect value for states[15].cn0, expected 7454.20019531, is %f", + check_msg->states[15].cn0); + ck_assert_msg( + check_msg->states[15].sid.code == 171, + "incorrect value for states[15].sid.code, expected 171, is %d", + check_msg->states[15].sid.code); + ck_assert_msg( + check_msg->states[15].sid.reserved == 201, + "incorrect value for states[15].sid.reserved, expected 201, is %d", + check_msg->states[15].sid.reserved); + ck_assert_msg( + check_msg->states[15].sid.sat == 21251, + "incorrect value for states[15].sid.sat, expected 21251, is %d", + check_msg->states[15].sid.sat); + ck_assert_msg(check_msg->states[15].state == 155, + "incorrect value for states[15].state, expected 155, is %d", + check_msg->states[15].state); + ck_assert_msg( + (check_msg->states[16].cn0 * 100 - 7134.20019531 * 100) < 0.05, + "incorrect value for states[16].cn0, expected 7134.20019531, is %f", + check_msg->states[16].cn0); + ck_assert_msg(check_msg->states[16].sid.code == 16, + "incorrect value for states[16].sid.code, expected 16, is %d", + check_msg->states[16].sid.code); + ck_assert_msg( + check_msg->states[16].sid.reserved == 19, + "incorrect value for states[16].sid.reserved, expected 19, is %d", + check_msg->states[16].sid.reserved); + ck_assert_msg( + check_msg->states[16].sid.sat == 50475, + "incorrect value for states[16].sid.sat, expected 50475, is %d", + check_msg->states[16].sid.sat); + ck_assert_msg(check_msg->states[16].state == 121, + "incorrect value for states[16].state, expected 121, is %d", + check_msg->states[16].state); + ck_assert_msg( + (check_msg->states[17].cn0 * 100 - 3111.19995117 * 100) < 0.05, + "incorrect value for states[17].cn0, expected 3111.19995117, is %f", + check_msg->states[17].cn0); + ck_assert_msg(check_msg->states[17].sid.code == 63, + "incorrect value for states[17].sid.code, expected 63, is %d", + check_msg->states[17].sid.code); + ck_assert_msg( + check_msg->states[17].sid.reserved == 176, + "incorrect value for states[17].sid.reserved, expected 176, is %d", + check_msg->states[17].sid.reserved); + ck_assert_msg( + check_msg->states[17].sid.sat == 13813, + "incorrect value for states[17].sid.sat, expected 13813, is %d", + check_msg->states[17].sid.sat); + ck_assert_msg(check_msg->states[17].state == 128, + "incorrect value for states[17].state, expected 128, is %d", + check_msg->states[17].state); + ck_assert_msg( + (check_msg->states[18].cn0 * 100 - 4297.20019531 * 100) < 0.05, + "incorrect value for states[18].cn0, expected 4297.20019531, is %f", + check_msg->states[18].cn0); + ck_assert_msg( + check_msg->states[18].sid.code == 153, + "incorrect value for states[18].sid.code, expected 153, is %d", + check_msg->states[18].sid.code); + ck_assert_msg( + check_msg->states[18].sid.reserved == 51, + "incorrect value for states[18].sid.reserved, expected 51, is %d", + check_msg->states[18].sid.reserved); + ck_assert_msg( + check_msg->states[18].sid.sat == 15636, + "incorrect value for states[18].sid.sat, expected 15636, is %d", + check_msg->states[18].sid.sat); + ck_assert_msg(check_msg->states[18].state == 36, + "incorrect value for states[18].state, expected 36, is %d", + check_msg->states[18].state); + ck_assert_msg( + (check_msg->states[19].cn0 * 100 - 2649.19995117 * 100) < 0.05, + "incorrect value for states[19].cn0, expected 2649.19995117, is %f", + check_msg->states[19].cn0); + ck_assert_msg( + check_msg->states[19].sid.code == 140, + "incorrect value for states[19].sid.code, expected 140, is %d", + check_msg->states[19].sid.code); + ck_assert_msg( + check_msg->states[19].sid.reserved == 22, + "incorrect value for states[19].sid.reserved, expected 22, is %d", + check_msg->states[19].sid.reserved); + ck_assert_msg( + check_msg->states[19].sid.sat == 29778, + "incorrect value for states[19].sid.sat, expected 29778, is %d", + check_msg->states[19].sid.sat); + ck_assert_msg(check_msg->states[19].state == 46, + "incorrect value for states[19].state, expected 46, is %d", + check_msg->states[19].state); + ck_assert_msg( + (check_msg->states[20].cn0 * 100 - 941.200012207 * 100) < 0.05, + "incorrect value for states[20].cn0, expected 941.200012207, is %f", + check_msg->states[20].cn0); + ck_assert_msg(check_msg->states[20].sid.code == 96, + "incorrect value for states[20].sid.code, expected 96, is %d", + check_msg->states[20].sid.code); + ck_assert_msg( + check_msg->states[20].sid.reserved == 143, + "incorrect value for states[20].sid.reserved, expected 143, is %d", + check_msg->states[20].sid.reserved); + ck_assert_msg( + check_msg->states[20].sid.sat == 37443, + "incorrect value for states[20].sid.sat, expected 37443, is %d", + check_msg->states[20].sid.sat); + ck_assert_msg(check_msg->states[20].state == 177, + "incorrect value for states[20].state, expected 177, is %d", + check_msg->states[20].state); + ck_assert_msg( + (check_msg->states[21].cn0 * 100 - 1539.19995117 * 100) < 0.05, + "incorrect value for states[21].cn0, expected 1539.19995117, is %f", + check_msg->states[21].cn0); + ck_assert_msg( + check_msg->states[21].sid.code == 201, + "incorrect value for states[21].sid.code, expected 201, is %d", + check_msg->states[21].sid.code); + ck_assert_msg( + check_msg->states[21].sid.reserved == 251, + "incorrect value for states[21].sid.reserved, expected 251, is %d", + check_msg->states[21].sid.reserved); + ck_assert_msg( + check_msg->states[21].sid.sat == 41011, + "incorrect value for states[21].sid.sat, expected 41011, is %d", + check_msg->states[21].sid.sat); + ck_assert_msg(check_msg->states[21].state == 220, + "incorrect value for states[21].state, expected 220, is %d", + check_msg->states[21].state); + ck_assert_msg( + (check_msg->states[22].cn0 * 100 - 1443.19995117 * 100) < 0.05, + "incorrect value for states[22].cn0, expected 1443.19995117, is %f", + check_msg->states[22].cn0); + ck_assert_msg( + check_msg->states[22].sid.code == 161, + "incorrect value for states[22].sid.code, expected 161, is %d", + check_msg->states[22].sid.code); + ck_assert_msg( + check_msg->states[22].sid.reserved == 220, + "incorrect value for states[22].sid.reserved, expected 220, is %d", + check_msg->states[22].sid.reserved); + ck_assert_msg(check_msg->states[22].sid.sat == 706, + "incorrect value for states[22].sid.sat, expected 706, is %d", + check_msg->states[22].sid.sat); + ck_assert_msg(check_msg->states[22].state == 168, + "incorrect value for states[22].state, expected 168, is %d", + check_msg->states[22].state); + ck_assert_msg( + (check_msg->states[23].cn0 * 100 - 1074.19995117 * 100) < 0.05, + "incorrect value for states[23].cn0, expected 1074.19995117, is %f", + check_msg->states[23].cn0); + ck_assert_msg( + check_msg->states[23].sid.code == 125, + "incorrect value for states[23].sid.code, expected 125, is %d", + check_msg->states[23].sid.code); + ck_assert_msg( + check_msg->states[23].sid.reserved == 178, + "incorrect value for states[23].sid.reserved, expected 178, is %d", + check_msg->states[23].sid.reserved); + ck_assert_msg( + check_msg->states[23].sid.sat == 2312, + "incorrect value for states[23].sid.sat, expected 2312, is %d", + check_msg->states[23].sid.sat); + ck_assert_msg(check_msg->states[23].state == 69, + "incorrect value for states[23].state, expected 69, is %d", + check_msg->states[23].state); + ck_assert_msg( + (check_msg->states[24].cn0 * 100 - 2122.19995117 * 100) < 0.05, + "incorrect value for states[24].cn0, expected 2122.19995117, is %f", + check_msg->states[24].cn0); + ck_assert_msg( + check_msg->states[24].sid.code == 186, + "incorrect value for states[24].sid.code, expected 186, is %d", + check_msg->states[24].sid.code); + ck_assert_msg( + check_msg->states[24].sid.reserved == 171, + "incorrect value for states[24].sid.reserved, expected 171, is %d", + check_msg->states[24].sid.reserved); + ck_assert_msg( + check_msg->states[24].sid.sat == 34580, + "incorrect value for states[24].sid.sat, expected 34580, is %d", + check_msg->states[24].sid.sat); + ck_assert_msg(check_msg->states[24].state == 185, + "incorrect value for states[24].state, expected 185, is %d", + check_msg->states[24].state); + ck_assert_msg( + (check_msg->states[25].cn0 * 100 - 9076.20019531 * 100) < 0.05, + "incorrect value for states[25].cn0, expected 9076.20019531, is %f", + check_msg->states[25].cn0); + ck_assert_msg(check_msg->states[25].sid.code == 85, + "incorrect value for states[25].sid.code, expected 85, is %d", + check_msg->states[25].sid.code); + ck_assert_msg( + check_msg->states[25].sid.reserved == 170, + "incorrect value for states[25].sid.reserved, expected 170, is %d", + check_msg->states[25].sid.reserved); + ck_assert_msg( + check_msg->states[25].sid.sat == 39804, + "incorrect value for states[25].sid.sat, expected 39804, is %d", + check_msg->states[25].sid.sat); + ck_assert_msg(check_msg->states[25].state == 18, + "incorrect value for states[25].state, expected 18, is %d", + check_msg->states[25].state); + ck_assert_msg( + (check_msg->states[26].cn0 * 100 - 4781.20019531 * 100) < 0.05, + "incorrect value for states[26].cn0, expected 4781.20019531, is %f", + check_msg->states[26].cn0); + ck_assert_msg( + check_msg->states[26].sid.code == 255, + "incorrect value for states[26].sid.code, expected 255, is %d", + check_msg->states[26].sid.code); + ck_assert_msg( + check_msg->states[26].sid.reserved == 186, + "incorrect value for states[26].sid.reserved, expected 186, is %d", + check_msg->states[26].sid.reserved); + ck_assert_msg( + check_msg->states[26].sid.sat == 52980, + "incorrect value for states[26].sid.sat, expected 52980, is %d", + check_msg->states[26].sid.sat); + ck_assert_msg(check_msg->states[26].state == 57, + "incorrect value for states[26].state, expected 57, is %d", + check_msg->states[26].state); + ck_assert_msg( + (check_msg->states[27].cn0 * 100 - 3076.19995117 * 100) < 0.05, + "incorrect value for states[27].cn0, expected 3076.19995117, is %f", + check_msg->states[27].cn0); + ck_assert_msg( + check_msg->states[27].sid.code == 181, + "incorrect value for states[27].sid.code, expected 181, is %d", + check_msg->states[27].sid.code); + ck_assert_msg( + check_msg->states[27].sid.reserved == 175, + "incorrect value for states[27].sid.reserved, expected 175, is %d", + check_msg->states[27].sid.reserved); + ck_assert_msg( + check_msg->states[27].sid.sat == 24007, + "incorrect value for states[27].sid.sat, expected 24007, is %d", + check_msg->states[27].sid.sat); + ck_assert_msg(check_msg->states[27].state == 165, + "incorrect value for states[27].state, expected 165, is %d", + check_msg->states[27].state); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_tracking_MsgTrackingStateDepB_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_tracking_MsgTrackingStateDepB"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB"); + tcase_add_test(tc_acq, + test_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c new file mode 100644 index 0000000000..6a229ee322 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.c @@ -0,0 +1,311 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x21, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x21, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, + 0, 133, 100, 71, 94, 192, 2, 160, 207, 212, 255, 135, 139, + 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, + 59, 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, + 15, 91, 249, 117, 142, 90, 219, 67, 25, 83, 62, 122, 100, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_tracking_state_detailed_dep_a_t *test_msg = + (msg_tracking_state_detailed_dep_a_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->L.f = 204; + test_msg->L.i = -1601767965; + test_msg->P = 1044286343; + test_msg->P_std = 21427; + test_msg->acceleration = -114; + test_msg->clock_drift = 23311; + test_msg->clock_offset = 6012; + test_msg->cn0 = 78; + test_msg->corr_spacing = 30201; + test_msg->doppler = 1459556257; + test_msg->doppler_std = 63677; + test_msg->lock = 65375; + test_msg->misc_flags = 62; + test_msg->nav_flags = 25; + test_msg->pset_flags = 83; + test_msg->recv_time = 941247176494; + test_msg->sid.code = 59; + test_msg->sid.sat = 38; + test_msg->sync_flags = 90; + test_msg->tot.ns_residual = -811597120; + test_msg->tot.tow = 1581737093; + test_msg->tot.wn = 65492; + test_msg->tow_flags = 219; + test_msg->track_flags = 67; + test_msg->uptime = 3263741727; + sbp_payload_send(&sbp_state, 0x21, 28315, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 28315, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 28315, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x21, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_tracking_state_detailed_dep_a_t *check_msg = + (msg_tracking_state_detailed_dep_a_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->L.f == 204, + "incorrect value for L.f, expected 204, is %d", + check_msg->L.f); + ck_assert_msg(check_msg->L.i == -1601767965, + "incorrect value for L.i, expected -1601767965, is %d", + check_msg->L.i); + ck_assert_msg(check_msg->P == 1044286343, + "incorrect value for P, expected 1044286343, is %d", + check_msg->P); + ck_assert_msg(check_msg->P_std == 21427, + "incorrect value for P_std, expected 21427, is %d", + check_msg->P_std); + ck_assert_msg(check_msg->acceleration == -114, + "incorrect value for acceleration, expected -114, is %d", + check_msg->acceleration); + ck_assert_msg(check_msg->clock_drift == 23311, + "incorrect value for clock_drift, expected 23311, is %d", + check_msg->clock_drift); + ck_assert_msg(check_msg->clock_offset == 6012, + "incorrect value for clock_offset, expected 6012, is %d", + check_msg->clock_offset); + ck_assert_msg(check_msg->cn0 == 78, + "incorrect value for cn0, expected 78, is %d", + check_msg->cn0); + ck_assert_msg(check_msg->corr_spacing == 30201, + "incorrect value for corr_spacing, expected 30201, is %d", + check_msg->corr_spacing); + ck_assert_msg(check_msg->doppler == 1459556257, + "incorrect value for doppler, expected 1459556257, is %d", + check_msg->doppler); + ck_assert_msg(check_msg->doppler_std == 63677, + "incorrect value for doppler_std, expected 63677, is %d", + check_msg->doppler_std); + ck_assert_msg(check_msg->lock == 65375, + "incorrect value for lock, expected 65375, is %d", + check_msg->lock); + ck_assert_msg(check_msg->misc_flags == 62, + "incorrect value for misc_flags, expected 62, is %d", + check_msg->misc_flags); + ck_assert_msg(check_msg->nav_flags == 25, + "incorrect value for nav_flags, expected 25, is %d", + check_msg->nav_flags); + ck_assert_msg(check_msg->pset_flags == 83, + "incorrect value for pset_flags, expected 83, is %d", + check_msg->pset_flags); + ck_assert_msg(check_msg->recv_time == 941247176494, + "incorrect value for recv_time, expected 941247176494, is %d", + check_msg->recv_time); + ck_assert_msg(check_msg->sid.code == 59, + "incorrect value for sid.code, expected 59, is %d", + check_msg->sid.code); + ck_assert_msg(check_msg->sid.sat == 38, + "incorrect value for sid.sat, expected 38, is %d", + check_msg->sid.sat); + ck_assert_msg(check_msg->sync_flags == 90, + "incorrect value for sync_flags, expected 90, is %d", + check_msg->sync_flags); + ck_assert_msg( + check_msg->tot.ns_residual == -811597120, + "incorrect value for tot.ns_residual, expected -811597120, is %d", + check_msg->tot.ns_residual); + ck_assert_msg(check_msg->tot.tow == 1581737093, + "incorrect value for tot.tow, expected 1581737093, is %d", + check_msg->tot.tow); + ck_assert_msg(check_msg->tot.wn == 65492, + "incorrect value for tot.wn, expected 65492, is %d", + check_msg->tot.wn); + ck_assert_msg(check_msg->tow_flags == 219, + "incorrect value for tow_flags, expected 219, is %d", + check_msg->tow_flags); + ck_assert_msg(check_msg->track_flags == 67, + "incorrect value for track_flags, expected 67, is %d", + check_msg->track_flags); + ck_assert_msg(check_msg->uptime == 3263741727, + "incorrect value for uptime, expected 3263741727, is %d", + check_msg->uptime); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: " + "legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_tracking_" + "MsgTrackingStateDetailedDepA"); + tcase_add_test( + tc_acq, test_legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_user_MsgUserData.c b/c/test/legacy/auto_check_sbp_user_MsgUserData.c new file mode 100644 index 0000000000..193a838b50 --- /dev/null +++ b/c/test/legacy/auto_check_sbp_user_MsgUserData.c @@ -0,0 +1,2259 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_user_MsgUserData) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x800, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x800, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, + 149, 204, 113, 31, 108, 188, 179, 154, 156, 167, 145, 139, 42, 207, + 126, 242, 193, 9, 58, 75, 8, 135, 11, 92, 131, 245, 24, 90, + 255, 30, 58, 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, + 50, 148, 1, 99, 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, + 97, 96, 75, 174, 58, 219, 180, 148, 247, 59, 2, 116, 214, 114, + 55, 134, 54, 119, 108, 128, 73, 181, 20, 233, 23, 23, 73, 119, + 136, 231, 189, 26, 174, 128, 93, 30, 76, 45, 109, 134, 81, 0, + 116, 158, 127, 40, 133, 208, 134, 127, 140, 232, 183, 184, 108, 6, + 228, 54, 238, 59, 220, 30, 228, 212, 50, 182, 97, 20, 41, 76, + 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, 189, 44, 239, 232, + 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, 173, 157, 202, + 172, 180, 150, 213, 193, 177, 209, 156, 20, 174, 18, 73, 132, 215, + 115, 128, 175, 169, 116, 132, 100, 72, 45, 25, 14, 205, 213, 145, + 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, 6, 165, + 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, + 132, 59, 61, 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, + 56, 216, 19, 216, 70, 71, 161, 184, 5, 177, 45, 37, 98, 56, + 149, 0, 73, 221, 105, 239, 168, 205, 85, 81, 245, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_user_data_t *test_msg = (msg_user_data_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[0] = 53; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[1] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[2] = 172; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[3] = 138; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[4] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[5] = 49; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[6] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[7] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[8] = 149; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[9] = 204; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[10] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[11] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[12] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[13] = 188; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[14] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[15] = 154; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[16] = 156; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[17] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[18] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[19] = 139; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[20] = 42; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[21] = 207; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[22] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[23] = 242; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[24] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[25] = 9; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[26] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[27] = 75; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[28] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[29] = 135; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[30] = 11; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[31] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[32] = 131; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[33] = 245; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[34] = 24; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[35] = 90; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[36] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[37] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[38] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[39] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[40] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[41] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[42] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[43] = 178; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[44] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[45] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[46] = 159; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[47] = 70; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[48] = 17; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[49] = 170; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[50] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[51] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[52] = 1; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[53] = 99; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[54] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[55] = 88; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[56] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[57] = 36; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[58] = 84; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[59] = 34; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[60] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[61] = 82; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[62] = 144; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[63] = 144; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[64] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[65] = 96; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[66] = 75; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[67] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[68] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[69] = 219; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[70] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[71] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[72] = 247; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[73] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[74] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[75] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[76] = 214; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[77] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[78] = 55; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[79] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[80] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[81] = 119; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[82] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[83] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[84] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[85] = 181; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[86] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[87] = 233; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[88] = 23; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[89] = 23; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[90] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[91] = 119; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[92] = 136; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[93] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[94] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[95] = 26; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[96] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[97] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[98] = 93; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[99] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[100] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[101] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[102] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[103] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[104] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[105] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[106] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[107] = 158; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[108] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[109] = 40; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[110] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[111] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[112] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[113] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[114] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[115] = 232; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[116] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[117] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[118] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[119] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[120] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[121] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[122] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[123] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[124] = 220; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[125] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[126] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[127] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[128] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[129] = 182; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[130] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[131] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[132] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[133] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[134] = 227; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[135] = 88; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[136] = 12; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[137] = 95; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[138] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[139] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[140] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[141] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[142] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[143] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[144] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[145] = 44; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[146] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[147] = 232; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[148] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[149] = 9; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[150] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[151] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[152] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[153] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[154] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[155] = 194; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[156] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[157] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[158] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[159] = 173; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[160] = 157; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[161] = 202; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[162] = 172; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[163] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[164] = 150; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[165] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[166] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[167] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[168] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[169] = 156; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[170] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[171] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[172] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[173] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[174] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[175] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[176] = 115; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[177] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[178] = 175; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[179] = 169; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[180] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[181] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[182] = 100; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[183] = 72; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[184] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[185] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[186] = 14; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[187] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[188] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[189] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[190] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[191] = 137; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[192] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[193] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[194] = 40; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[195] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[196] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[197] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[198] = 166; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[199] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[200] = 63; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[201] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[202] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[203] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[204] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[205] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[206] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[207] = 200; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[208] = 38; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[209] = 139; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[210] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[211] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[212] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[213] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[214] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[215] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[216] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[217] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[218] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[219] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[220] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[221] = 233; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[222] = 3; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[223] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[224] = 158; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[225] = 83; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[226] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[227] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[228] = 154; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[229] = 17; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[230] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[231] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[232] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[233] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[234] = 19; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[235] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[236] = 70; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[237] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[238] = 161; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[239] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[240] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[241] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[242] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[243] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[244] = 98; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[245] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[246] = 149; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[247] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[248] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[249] = 221; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[250] = 105; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[251] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[252] = 168; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[253] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len += sizeof(test_msg->contents[0]); + } + test_msg->contents[254] = 85; + sbp_payload_send(&sbp_state, 0x800, 8574, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 8574, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 8574, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x800, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_user_data_t *check_msg = (msg_user_data_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->contents[0] == 53, + "incorrect value for contents[0], expected 53, is %d", + check_msg->contents[0]); + ck_assert_msg(check_msg->contents[1] == 5, + "incorrect value for contents[1], expected 5, is %d", + check_msg->contents[1]); + ck_assert_msg(check_msg->contents[2] == 172, + "incorrect value for contents[2], expected 172, is %d", + check_msg->contents[2]); + ck_assert_msg(check_msg->contents[3] == 138, + "incorrect value for contents[3], expected 138, is %d", + check_msg->contents[3]); + ck_assert_msg(check_msg->contents[4] == 50, + "incorrect value for contents[4], expected 50, is %d", + check_msg->contents[4]); + ck_assert_msg(check_msg->contents[5] == 49, + "incorrect value for contents[5], expected 49, is %d", + check_msg->contents[5]); + ck_assert_msg(check_msg->contents[6] == 206, + "incorrect value for contents[6], expected 206, is %d", + check_msg->contents[6]); + ck_assert_msg(check_msg->contents[7] == 234, + "incorrect value for contents[7], expected 234, is %d", + check_msg->contents[7]); + ck_assert_msg(check_msg->contents[8] == 149, + "incorrect value for contents[8], expected 149, is %d", + check_msg->contents[8]); + ck_assert_msg(check_msg->contents[9] == 204, + "incorrect value for contents[9], expected 204, is %d", + check_msg->contents[9]); + ck_assert_msg(check_msg->contents[10] == 113, + "incorrect value for contents[10], expected 113, is %d", + check_msg->contents[10]); + ck_assert_msg(check_msg->contents[11] == 31, + "incorrect value for contents[11], expected 31, is %d", + check_msg->contents[11]); + ck_assert_msg(check_msg->contents[12] == 108, + "incorrect value for contents[12], expected 108, is %d", + check_msg->contents[12]); + ck_assert_msg(check_msg->contents[13] == 188, + "incorrect value for contents[13], expected 188, is %d", + check_msg->contents[13]); + ck_assert_msg(check_msg->contents[14] == 179, + "incorrect value for contents[14], expected 179, is %d", + check_msg->contents[14]); + ck_assert_msg(check_msg->contents[15] == 154, + "incorrect value for contents[15], expected 154, is %d", + check_msg->contents[15]); + ck_assert_msg(check_msg->contents[16] == 156, + "incorrect value for contents[16], expected 156, is %d", + check_msg->contents[16]); + ck_assert_msg(check_msg->contents[17] == 167, + "incorrect value for contents[17], expected 167, is %d", + check_msg->contents[17]); + ck_assert_msg(check_msg->contents[18] == 145, + "incorrect value for contents[18], expected 145, is %d", + check_msg->contents[18]); + ck_assert_msg(check_msg->contents[19] == 139, + "incorrect value for contents[19], expected 139, is %d", + check_msg->contents[19]); + ck_assert_msg(check_msg->contents[20] == 42, + "incorrect value for contents[20], expected 42, is %d", + check_msg->contents[20]); + ck_assert_msg(check_msg->contents[21] == 207, + "incorrect value for contents[21], expected 207, is %d", + check_msg->contents[21]); + ck_assert_msg(check_msg->contents[22] == 126, + "incorrect value for contents[22], expected 126, is %d", + check_msg->contents[22]); + ck_assert_msg(check_msg->contents[23] == 242, + "incorrect value for contents[23], expected 242, is %d", + check_msg->contents[23]); + ck_assert_msg(check_msg->contents[24] == 193, + "incorrect value for contents[24], expected 193, is %d", + check_msg->contents[24]); + ck_assert_msg(check_msg->contents[25] == 9, + "incorrect value for contents[25], expected 9, is %d", + check_msg->contents[25]); + ck_assert_msg(check_msg->contents[26] == 58, + "incorrect value for contents[26], expected 58, is %d", + check_msg->contents[26]); + ck_assert_msg(check_msg->contents[27] == 75, + "incorrect value for contents[27], expected 75, is %d", + check_msg->contents[27]); + ck_assert_msg(check_msg->contents[28] == 8, + "incorrect value for contents[28], expected 8, is %d", + check_msg->contents[28]); + ck_assert_msg(check_msg->contents[29] == 135, + "incorrect value for contents[29], expected 135, is %d", + check_msg->contents[29]); + ck_assert_msg(check_msg->contents[30] == 11, + "incorrect value for contents[30], expected 11, is %d", + check_msg->contents[30]); + ck_assert_msg(check_msg->contents[31] == 92, + "incorrect value for contents[31], expected 92, is %d", + check_msg->contents[31]); + ck_assert_msg(check_msg->contents[32] == 131, + "incorrect value for contents[32], expected 131, is %d", + check_msg->contents[32]); + ck_assert_msg(check_msg->contents[33] == 245, + "incorrect value for contents[33], expected 245, is %d", + check_msg->contents[33]); + ck_assert_msg(check_msg->contents[34] == 24, + "incorrect value for contents[34], expected 24, is %d", + check_msg->contents[34]); + ck_assert_msg(check_msg->contents[35] == 90, + "incorrect value for contents[35], expected 90, is %d", + check_msg->contents[35]); + ck_assert_msg(check_msg->contents[36] == 255, + "incorrect value for contents[36], expected 255, is %d", + check_msg->contents[36]); + ck_assert_msg(check_msg->contents[37] == 30, + "incorrect value for contents[37], expected 30, is %d", + check_msg->contents[37]); + ck_assert_msg(check_msg->contents[38] == 58, + "incorrect value for contents[38], expected 58, is %d", + check_msg->contents[38]); + ck_assert_msg(check_msg->contents[39] == 31, + "incorrect value for contents[39], expected 31, is %d", + check_msg->contents[39]); + ck_assert_msg(check_msg->contents[40] == 109, + "incorrect value for contents[40], expected 109, is %d", + check_msg->contents[40]); + ck_assert_msg(check_msg->contents[41] == 148, + "incorrect value for contents[41], expected 148, is %d", + check_msg->contents[41]); + ck_assert_msg(check_msg->contents[42] == 56, + "incorrect value for contents[42], expected 56, is %d", + check_msg->contents[42]); + ck_assert_msg(check_msg->contents[43] == 178, + "incorrect value for contents[43], expected 178, is %d", + check_msg->contents[43]); + ck_assert_msg(check_msg->contents[44] == 140, + "incorrect value for contents[44], expected 140, is %d", + check_msg->contents[44]); + ck_assert_msg(check_msg->contents[45] == 30, + "incorrect value for contents[45], expected 30, is %d", + check_msg->contents[45]); + ck_assert_msg(check_msg->contents[46] == 159, + "incorrect value for contents[46], expected 159, is %d", + check_msg->contents[46]); + ck_assert_msg(check_msg->contents[47] == 70, + "incorrect value for contents[47], expected 70, is %d", + check_msg->contents[47]); + ck_assert_msg(check_msg->contents[48] == 17, + "incorrect value for contents[48], expected 17, is %d", + check_msg->contents[48]); + ck_assert_msg(check_msg->contents[49] == 170, + "incorrect value for contents[49], expected 170, is %d", + check_msg->contents[49]); + ck_assert_msg(check_msg->contents[50] == 50, + "incorrect value for contents[50], expected 50, is %d", + check_msg->contents[50]); + ck_assert_msg(check_msg->contents[51] == 148, + "incorrect value for contents[51], expected 148, is %d", + check_msg->contents[51]); + ck_assert_msg(check_msg->contents[52] == 1, + "incorrect value for contents[52], expected 1, is %d", + check_msg->contents[52]); + ck_assert_msg(check_msg->contents[53] == 99, + "incorrect value for contents[53], expected 99, is %d", + check_msg->contents[53]); + ck_assert_msg(check_msg->contents[54] == 112, + "incorrect value for contents[54], expected 112, is %d", + check_msg->contents[54]); + ck_assert_msg(check_msg->contents[55] == 88, + "incorrect value for contents[55], expected 88, is %d", + check_msg->contents[55]); + ck_assert_msg(check_msg->contents[56] == 217, + "incorrect value for contents[56], expected 217, is %d", + check_msg->contents[56]); + ck_assert_msg(check_msg->contents[57] == 36, + "incorrect value for contents[57], expected 36, is %d", + check_msg->contents[57]); + ck_assert_msg(check_msg->contents[58] == 84, + "incorrect value for contents[58], expected 84, is %d", + check_msg->contents[58]); + ck_assert_msg(check_msg->contents[59] == 34, + "incorrect value for contents[59], expected 34, is %d", + check_msg->contents[59]); + ck_assert_msg(check_msg->contents[60] == 234, + "incorrect value for contents[60], expected 234, is %d", + check_msg->contents[60]); + ck_assert_msg(check_msg->contents[61] == 82, + "incorrect value for contents[61], expected 82, is %d", + check_msg->contents[61]); + ck_assert_msg(check_msg->contents[62] == 144, + "incorrect value for contents[62], expected 144, is %d", + check_msg->contents[62]); + ck_assert_msg(check_msg->contents[63] == 144, + "incorrect value for contents[63], expected 144, is %d", + check_msg->contents[63]); + ck_assert_msg(check_msg->contents[64] == 97, + "incorrect value for contents[64], expected 97, is %d", + check_msg->contents[64]); + ck_assert_msg(check_msg->contents[65] == 96, + "incorrect value for contents[65], expected 96, is %d", + check_msg->contents[65]); + ck_assert_msg(check_msg->contents[66] == 75, + "incorrect value for contents[66], expected 75, is %d", + check_msg->contents[66]); + ck_assert_msg(check_msg->contents[67] == 174, + "incorrect value for contents[67], expected 174, is %d", + check_msg->contents[67]); + ck_assert_msg(check_msg->contents[68] == 58, + "incorrect value for contents[68], expected 58, is %d", + check_msg->contents[68]); + ck_assert_msg(check_msg->contents[69] == 219, + "incorrect value for contents[69], expected 219, is %d", + check_msg->contents[69]); + ck_assert_msg(check_msg->contents[70] == 180, + "incorrect value for contents[70], expected 180, is %d", + check_msg->contents[70]); + ck_assert_msg(check_msg->contents[71] == 148, + "incorrect value for contents[71], expected 148, is %d", + check_msg->contents[71]); + ck_assert_msg(check_msg->contents[72] == 247, + "incorrect value for contents[72], expected 247, is %d", + check_msg->contents[72]); + ck_assert_msg(check_msg->contents[73] == 59, + "incorrect value for contents[73], expected 59, is %d", + check_msg->contents[73]); + ck_assert_msg(check_msg->contents[74] == 2, + "incorrect value for contents[74], expected 2, is %d", + check_msg->contents[74]); + ck_assert_msg(check_msg->contents[75] == 116, + "incorrect value for contents[75], expected 116, is %d", + check_msg->contents[75]); + ck_assert_msg(check_msg->contents[76] == 214, + "incorrect value for contents[76], expected 214, is %d", + check_msg->contents[76]); + ck_assert_msg(check_msg->contents[77] == 114, + "incorrect value for contents[77], expected 114, is %d", + check_msg->contents[77]); + ck_assert_msg(check_msg->contents[78] == 55, + "incorrect value for contents[78], expected 55, is %d", + check_msg->contents[78]); + ck_assert_msg(check_msg->contents[79] == 134, + "incorrect value for contents[79], expected 134, is %d", + check_msg->contents[79]); + ck_assert_msg(check_msg->contents[80] == 54, + "incorrect value for contents[80], expected 54, is %d", + check_msg->contents[80]); + ck_assert_msg(check_msg->contents[81] == 119, + "incorrect value for contents[81], expected 119, is %d", + check_msg->contents[81]); + ck_assert_msg(check_msg->contents[82] == 108, + "incorrect value for contents[82], expected 108, is %d", + check_msg->contents[82]); + ck_assert_msg(check_msg->contents[83] == 128, + "incorrect value for contents[83], expected 128, is %d", + check_msg->contents[83]); + ck_assert_msg(check_msg->contents[84] == 73, + "incorrect value for contents[84], expected 73, is %d", + check_msg->contents[84]); + ck_assert_msg(check_msg->contents[85] == 181, + "incorrect value for contents[85], expected 181, is %d", + check_msg->contents[85]); + ck_assert_msg(check_msg->contents[86] == 20, + "incorrect value for contents[86], expected 20, is %d", + check_msg->contents[86]); + ck_assert_msg(check_msg->contents[87] == 233, + "incorrect value for contents[87], expected 233, is %d", + check_msg->contents[87]); + ck_assert_msg(check_msg->contents[88] == 23, + "incorrect value for contents[88], expected 23, is %d", + check_msg->contents[88]); + ck_assert_msg(check_msg->contents[89] == 23, + "incorrect value for contents[89], expected 23, is %d", + check_msg->contents[89]); + ck_assert_msg(check_msg->contents[90] == 73, + "incorrect value for contents[90], expected 73, is %d", + check_msg->contents[90]); + ck_assert_msg(check_msg->contents[91] == 119, + "incorrect value for contents[91], expected 119, is %d", + check_msg->contents[91]); + ck_assert_msg(check_msg->contents[92] == 136, + "incorrect value for contents[92], expected 136, is %d", + check_msg->contents[92]); + ck_assert_msg(check_msg->contents[93] == 231, + "incorrect value for contents[93], expected 231, is %d", + check_msg->contents[93]); + ck_assert_msg(check_msg->contents[94] == 189, + "incorrect value for contents[94], expected 189, is %d", + check_msg->contents[94]); + ck_assert_msg(check_msg->contents[95] == 26, + "incorrect value for contents[95], expected 26, is %d", + check_msg->contents[95]); + ck_assert_msg(check_msg->contents[96] == 174, + "incorrect value for contents[96], expected 174, is %d", + check_msg->contents[96]); + ck_assert_msg(check_msg->contents[97] == 128, + "incorrect value for contents[97], expected 128, is %d", + check_msg->contents[97]); + ck_assert_msg(check_msg->contents[98] == 93, + "incorrect value for contents[98], expected 93, is %d", + check_msg->contents[98]); + ck_assert_msg(check_msg->contents[99] == 30, + "incorrect value for contents[99], expected 30, is %d", + check_msg->contents[99]); + ck_assert_msg(check_msg->contents[100] == 76, + "incorrect value for contents[100], expected 76, is %d", + check_msg->contents[100]); + ck_assert_msg(check_msg->contents[101] == 45, + "incorrect value for contents[101], expected 45, is %d", + check_msg->contents[101]); + ck_assert_msg(check_msg->contents[102] == 109, + "incorrect value for contents[102], expected 109, is %d", + check_msg->contents[102]); + ck_assert_msg(check_msg->contents[103] == 134, + "incorrect value for contents[103], expected 134, is %d", + check_msg->contents[103]); + ck_assert_msg(check_msg->contents[104] == 81, + "incorrect value for contents[104], expected 81, is %d", + check_msg->contents[104]); + ck_assert_msg(check_msg->contents[105] == 0, + "incorrect value for contents[105], expected 0, is %d", + check_msg->contents[105]); + ck_assert_msg(check_msg->contents[106] == 116, + "incorrect value for contents[106], expected 116, is %d", + check_msg->contents[106]); + ck_assert_msg(check_msg->contents[107] == 158, + "incorrect value for contents[107], expected 158, is %d", + check_msg->contents[107]); + ck_assert_msg(check_msg->contents[108] == 127, + "incorrect value for contents[108], expected 127, is %d", + check_msg->contents[108]); + ck_assert_msg(check_msg->contents[109] == 40, + "incorrect value for contents[109], expected 40, is %d", + check_msg->contents[109]); + ck_assert_msg(check_msg->contents[110] == 133, + "incorrect value for contents[110], expected 133, is %d", + check_msg->contents[110]); + ck_assert_msg(check_msg->contents[111] == 208, + "incorrect value for contents[111], expected 208, is %d", + check_msg->contents[111]); + ck_assert_msg(check_msg->contents[112] == 134, + "incorrect value for contents[112], expected 134, is %d", + check_msg->contents[112]); + ck_assert_msg(check_msg->contents[113] == 127, + "incorrect value for contents[113], expected 127, is %d", + check_msg->contents[113]); + ck_assert_msg(check_msg->contents[114] == 140, + "incorrect value for contents[114], expected 140, is %d", + check_msg->contents[114]); + ck_assert_msg(check_msg->contents[115] == 232, + "incorrect value for contents[115], expected 232, is %d", + check_msg->contents[115]); + ck_assert_msg(check_msg->contents[116] == 183, + "incorrect value for contents[116], expected 183, is %d", + check_msg->contents[116]); + ck_assert_msg(check_msg->contents[117] == 184, + "incorrect value for contents[117], expected 184, is %d", + check_msg->contents[117]); + ck_assert_msg(check_msg->contents[118] == 108, + "incorrect value for contents[118], expected 108, is %d", + check_msg->contents[118]); + ck_assert_msg(check_msg->contents[119] == 6, + "incorrect value for contents[119], expected 6, is %d", + check_msg->contents[119]); + ck_assert_msg(check_msg->contents[120] == 228, + "incorrect value for contents[120], expected 228, is %d", + check_msg->contents[120]); + ck_assert_msg(check_msg->contents[121] == 54, + "incorrect value for contents[121], expected 54, is %d", + check_msg->contents[121]); + ck_assert_msg(check_msg->contents[122] == 238, + "incorrect value for contents[122], expected 238, is %d", + check_msg->contents[122]); + ck_assert_msg(check_msg->contents[123] == 59, + "incorrect value for contents[123], expected 59, is %d", + check_msg->contents[123]); + ck_assert_msg(check_msg->contents[124] == 220, + "incorrect value for contents[124], expected 220, is %d", + check_msg->contents[124]); + ck_assert_msg(check_msg->contents[125] == 30, + "incorrect value for contents[125], expected 30, is %d", + check_msg->contents[125]); + ck_assert_msg(check_msg->contents[126] == 228, + "incorrect value for contents[126], expected 228, is %d", + check_msg->contents[126]); + ck_assert_msg(check_msg->contents[127] == 212, + "incorrect value for contents[127], expected 212, is %d", + check_msg->contents[127]); + ck_assert_msg(check_msg->contents[128] == 50, + "incorrect value for contents[128], expected 50, is %d", + check_msg->contents[128]); + ck_assert_msg(check_msg->contents[129] == 182, + "incorrect value for contents[129], expected 182, is %d", + check_msg->contents[129]); + ck_assert_msg(check_msg->contents[130] == 97, + "incorrect value for contents[130], expected 97, is %d", + check_msg->contents[130]); + ck_assert_msg(check_msg->contents[131] == 20, + "incorrect value for contents[131], expected 20, is %d", + check_msg->contents[131]); + ck_assert_msg(check_msg->contents[132] == 41, + "incorrect value for contents[132], expected 41, is %d", + check_msg->contents[132]); + ck_assert_msg(check_msg->contents[133] == 76, + "incorrect value for contents[133], expected 76, is %d", + check_msg->contents[133]); + ck_assert_msg(check_msg->contents[134] == 227, + "incorrect value for contents[134], expected 227, is %d", + check_msg->contents[134]); + ck_assert_msg(check_msg->contents[135] == 88, + "incorrect value for contents[135], expected 88, is %d", + check_msg->contents[135]); + ck_assert_msg(check_msg->contents[136] == 12, + "incorrect value for contents[136], expected 12, is %d", + check_msg->contents[136]); + ck_assert_msg(check_msg->contents[137] == 95, + "incorrect value for contents[137], expected 95, is %d", + check_msg->contents[137]); + ck_assert_msg(check_msg->contents[138] == 112, + "incorrect value for contents[138], expected 112, is %d", + check_msg->contents[138]); + ck_assert_msg(check_msg->contents[139] == 209, + "incorrect value for contents[139], expected 209, is %d", + check_msg->contents[139]); + ck_assert_msg(check_msg->contents[140] == 183, + "incorrect value for contents[140], expected 183, is %d", + check_msg->contents[140]); + ck_assert_msg(check_msg->contents[141] == 127, + "incorrect value for contents[141], expected 127, is %d", + check_msg->contents[141]); + ck_assert_msg(check_msg->contents[142] == 4, + "incorrect value for contents[142], expected 4, is %d", + check_msg->contents[142]); + ck_assert_msg(check_msg->contents[143] == 165, + "incorrect value for contents[143], expected 165, is %d", + check_msg->contents[143]); + ck_assert_msg(check_msg->contents[144] == 189, + "incorrect value for contents[144], expected 189, is %d", + check_msg->contents[144]); + ck_assert_msg(check_msg->contents[145] == 44, + "incorrect value for contents[145], expected 44, is %d", + check_msg->contents[145]); + ck_assert_msg(check_msg->contents[146] == 239, + "incorrect value for contents[146], expected 239, is %d", + check_msg->contents[146]); + ck_assert_msg(check_msg->contents[147] == 232, + "incorrect value for contents[147], expected 232, is %d", + check_msg->contents[147]); + ck_assert_msg(check_msg->contents[148] == 132, + "incorrect value for contents[148], expected 132, is %d", + check_msg->contents[148]); + ck_assert_msg(check_msg->contents[149] == 9, + "incorrect value for contents[149], expected 9, is %d", + check_msg->contents[149]); + ck_assert_msg(check_msg->contents[150] == 114, + "incorrect value for contents[150], expected 114, is %d", + check_msg->contents[150]); + ck_assert_msg(check_msg->contents[151] == 184, + "incorrect value for contents[151], expected 184, is %d", + check_msg->contents[151]); + ck_assert_msg(check_msg->contents[152] == 249, + "incorrect value for contents[152], expected 249, is %d", + check_msg->contents[152]); + ck_assert_msg(check_msg->contents[153] == 208, + "incorrect value for contents[153], expected 208, is %d", + check_msg->contents[153]); + ck_assert_msg(check_msg->contents[154] == 246, + "incorrect value for contents[154], expected 246, is %d", + check_msg->contents[154]); + ck_assert_msg(check_msg->contents[155] == 194, + "incorrect value for contents[155], expected 194, is %d", + check_msg->contents[155]); + ck_assert_msg(check_msg->contents[156] == 250, + "incorrect value for contents[156], expected 250, is %d", + check_msg->contents[156]); + ck_assert_msg(check_msg->contents[157] == 2, + "incorrect value for contents[157], expected 2, is %d", + check_msg->contents[157]); + ck_assert_msg(check_msg->contents[158] == 97, + "incorrect value for contents[158], expected 97, is %d", + check_msg->contents[158]); + ck_assert_msg(check_msg->contents[159] == 173, + "incorrect value for contents[159], expected 173, is %d", + check_msg->contents[159]); + ck_assert_msg(check_msg->contents[160] == 157, + "incorrect value for contents[160], expected 157, is %d", + check_msg->contents[160]); + ck_assert_msg(check_msg->contents[161] == 202, + "incorrect value for contents[161], expected 202, is %d", + check_msg->contents[161]); + ck_assert_msg(check_msg->contents[162] == 172, + "incorrect value for contents[162], expected 172, is %d", + check_msg->contents[162]); + ck_assert_msg(check_msg->contents[163] == 180, + "incorrect value for contents[163], expected 180, is %d", + check_msg->contents[163]); + ck_assert_msg(check_msg->contents[164] == 150, + "incorrect value for contents[164], expected 150, is %d", + check_msg->contents[164]); + ck_assert_msg(check_msg->contents[165] == 213, + "incorrect value for contents[165], expected 213, is %d", + check_msg->contents[165]); + ck_assert_msg(check_msg->contents[166] == 193, + "incorrect value for contents[166], expected 193, is %d", + check_msg->contents[166]); + ck_assert_msg(check_msg->contents[167] == 177, + "incorrect value for contents[167], expected 177, is %d", + check_msg->contents[167]); + ck_assert_msg(check_msg->contents[168] == 209, + "incorrect value for contents[168], expected 209, is %d", + check_msg->contents[168]); + ck_assert_msg(check_msg->contents[169] == 156, + "incorrect value for contents[169], expected 156, is %d", + check_msg->contents[169]); + ck_assert_msg(check_msg->contents[170] == 20, + "incorrect value for contents[170], expected 20, is %d", + check_msg->contents[170]); + ck_assert_msg(check_msg->contents[171] == 174, + "incorrect value for contents[171], expected 174, is %d", + check_msg->contents[171]); + ck_assert_msg(check_msg->contents[172] == 18, + "incorrect value for contents[172], expected 18, is %d", + check_msg->contents[172]); + ck_assert_msg(check_msg->contents[173] == 73, + "incorrect value for contents[173], expected 73, is %d", + check_msg->contents[173]); + ck_assert_msg(check_msg->contents[174] == 132, + "incorrect value for contents[174], expected 132, is %d", + check_msg->contents[174]); + ck_assert_msg(check_msg->contents[175] == 215, + "incorrect value for contents[175], expected 215, is %d", + check_msg->contents[175]); + ck_assert_msg(check_msg->contents[176] == 115, + "incorrect value for contents[176], expected 115, is %d", + check_msg->contents[176]); + ck_assert_msg(check_msg->contents[177] == 128, + "incorrect value for contents[177], expected 128, is %d", + check_msg->contents[177]); + ck_assert_msg(check_msg->contents[178] == 175, + "incorrect value for contents[178], expected 175, is %d", + check_msg->contents[178]); + ck_assert_msg(check_msg->contents[179] == 169, + "incorrect value for contents[179], expected 169, is %d", + check_msg->contents[179]); + ck_assert_msg(check_msg->contents[180] == 116, + "incorrect value for contents[180], expected 116, is %d", + check_msg->contents[180]); + ck_assert_msg(check_msg->contents[181] == 132, + "incorrect value for contents[181], expected 132, is %d", + check_msg->contents[181]); + ck_assert_msg(check_msg->contents[182] == 100, + "incorrect value for contents[182], expected 100, is %d", + check_msg->contents[182]); + ck_assert_msg(check_msg->contents[183] == 72, + "incorrect value for contents[183], expected 72, is %d", + check_msg->contents[183]); + ck_assert_msg(check_msg->contents[184] == 45, + "incorrect value for contents[184], expected 45, is %d", + check_msg->contents[184]); + ck_assert_msg(check_msg->contents[185] == 25, + "incorrect value for contents[185], expected 25, is %d", + check_msg->contents[185]); + ck_assert_msg(check_msg->contents[186] == 14, + "incorrect value for contents[186], expected 14, is %d", + check_msg->contents[186]); + ck_assert_msg(check_msg->contents[187] == 205, + "incorrect value for contents[187], expected 205, is %d", + check_msg->contents[187]); + ck_assert_msg(check_msg->contents[188] == 213, + "incorrect value for contents[188], expected 213, is %d", + check_msg->contents[188]); + ck_assert_msg(check_msg->contents[189] == 145, + "incorrect value for contents[189], expected 145, is %d", + check_msg->contents[189]); + ck_assert_msg(check_msg->contents[190] == 68, + "incorrect value for contents[190], expected 68, is %d", + check_msg->contents[190]); + ck_assert_msg(check_msg->contents[191] == 137, + "incorrect value for contents[191], expected 137, is %d", + check_msg->contents[191]); + ck_assert_msg(check_msg->contents[192] == 249, + "incorrect value for contents[192], expected 249, is %d", + check_msg->contents[192]); + ck_assert_msg(check_msg->contents[193] == 54, + "incorrect value for contents[193], expected 54, is %d", + check_msg->contents[193]); + ck_assert_msg(check_msg->contents[194] == 40, + "incorrect value for contents[194], expected 40, is %d", + check_msg->contents[194]); + ck_assert_msg(check_msg->contents[195] == 174, + "incorrect value for contents[195], expected 174, is %d", + check_msg->contents[195]); + ck_assert_msg(check_msg->contents[196] == 215, + "incorrect value for contents[196], expected 215, is %d", + check_msg->contents[196]); + ck_assert_msg(check_msg->contents[197] == 148, + "incorrect value for contents[197], expected 148, is %d", + check_msg->contents[197]); + ck_assert_msg(check_msg->contents[198] == 166, + "incorrect value for contents[198], expected 166, is %d", + check_msg->contents[198]); + ck_assert_msg(check_msg->contents[199] == 190, + "incorrect value for contents[199], expected 190, is %d", + check_msg->contents[199]); + ck_assert_msg(check_msg->contents[200] == 63, + "incorrect value for contents[200], expected 63, is %d", + check_msg->contents[200]); + ck_assert_msg(check_msg->contents[201] == 118, + "incorrect value for contents[201], expected 118, is %d", + check_msg->contents[201]); + ck_assert_msg(check_msg->contents[202] == 6, + "incorrect value for contents[202], expected 6, is %d", + check_msg->contents[202]); + ck_assert_msg(check_msg->contents[203] == 165, + "incorrect value for contents[203], expected 165, is %d", + check_msg->contents[203]); + ck_assert_msg(check_msg->contents[204] == 212, + "incorrect value for contents[204], expected 212, is %d", + check_msg->contents[204]); + ck_assert_msg(check_msg->contents[205] == 74, + "incorrect value for contents[205], expected 74, is %d", + check_msg->contents[205]); + ck_assert_msg(check_msg->contents[206] == 68, + "incorrect value for contents[206], expected 68, is %d", + check_msg->contents[206]); + ck_assert_msg(check_msg->contents[207] == 200, + "incorrect value for contents[207], expected 200, is %d", + check_msg->contents[207]); + ck_assert_msg(check_msg->contents[208] == 38, + "incorrect value for contents[208], expected 38, is %d", + check_msg->contents[208]); + ck_assert_msg(check_msg->contents[209] == 139, + "incorrect value for contents[209], expected 139, is %d", + check_msg->contents[209]); + ck_assert_msg(check_msg->contents[210] == 212, + "incorrect value for contents[210], expected 212, is %d", + check_msg->contents[210]); + ck_assert_msg(check_msg->contents[211] == 112, + "incorrect value for contents[211], expected 112, is %d", + check_msg->contents[211]); + ck_assert_msg(check_msg->contents[212] == 45, + "incorrect value for contents[212], expected 45, is %d", + check_msg->contents[212]); + ck_assert_msg(check_msg->contents[213] == 167, + "incorrect value for contents[213], expected 167, is %d", + check_msg->contents[213]); + ck_assert_msg(check_msg->contents[214] == 236, + "incorrect value for contents[214], expected 236, is %d", + check_msg->contents[214]); + ck_assert_msg(check_msg->contents[215] == 255, + "incorrect value for contents[215], expected 255, is %d", + check_msg->contents[215]); + ck_assert_msg(check_msg->contents[216] == 106, + "incorrect value for contents[216], expected 106, is %d", + check_msg->contents[216]); + ck_assert_msg(check_msg->contents[217] == 92, + "incorrect value for contents[217], expected 92, is %d", + check_msg->contents[217]); + ck_assert_msg(check_msg->contents[218] == 132, + "incorrect value for contents[218], expected 132, is %d", + check_msg->contents[218]); + ck_assert_msg(check_msg->contents[219] == 59, + "incorrect value for contents[219], expected 59, is %d", + check_msg->contents[219]); + ck_assert_msg(check_msg->contents[220] == 61, + "incorrect value for contents[220], expected 61, is %d", + check_msg->contents[220]); + ck_assert_msg(check_msg->contents[221] == 233, + "incorrect value for contents[221], expected 233, is %d", + check_msg->contents[221]); + ck_assert_msg(check_msg->contents[222] == 3, + "incorrect value for contents[222], expected 3, is %d", + check_msg->contents[222]); + ck_assert_msg(check_msg->contents[223] == 246, + "incorrect value for contents[223], expected 246, is %d", + check_msg->contents[223]); + ck_assert_msg(check_msg->contents[224] == 158, + "incorrect value for contents[224], expected 158, is %d", + check_msg->contents[224]); + ck_assert_msg(check_msg->contents[225] == 83, + "incorrect value for contents[225], expected 83, is %d", + check_msg->contents[225]); + ck_assert_msg(check_msg->contents[226] == 134, + "incorrect value for contents[226], expected 134, is %d", + check_msg->contents[226]); + ck_assert_msg(check_msg->contents[227] == 246, + "incorrect value for contents[227], expected 246, is %d", + check_msg->contents[227]); + ck_assert_msg(check_msg->contents[228] == 154, + "incorrect value for contents[228], expected 154, is %d", + check_msg->contents[228]); + ck_assert_msg(check_msg->contents[229] == 17, + "incorrect value for contents[229], expected 17, is %d", + check_msg->contents[229]); + ck_assert_msg(check_msg->contents[230] == 0, + "incorrect value for contents[230], expected 0, is %d", + check_msg->contents[230]); + ck_assert_msg(check_msg->contents[231] == 6, + "incorrect value for contents[231], expected 6, is %d", + check_msg->contents[231]); + ck_assert_msg(check_msg->contents[232] == 56, + "incorrect value for contents[232], expected 56, is %d", + check_msg->contents[232]); + ck_assert_msg(check_msg->contents[233] == 216, + "incorrect value for contents[233], expected 216, is %d", + check_msg->contents[233]); + ck_assert_msg(check_msg->contents[234] == 19, + "incorrect value for contents[234], expected 19, is %d", + check_msg->contents[234]); + ck_assert_msg(check_msg->contents[235] == 216, + "incorrect value for contents[235], expected 216, is %d", + check_msg->contents[235]); + ck_assert_msg(check_msg->contents[236] == 70, + "incorrect value for contents[236], expected 70, is %d", + check_msg->contents[236]); + ck_assert_msg(check_msg->contents[237] == 71, + "incorrect value for contents[237], expected 71, is %d", + check_msg->contents[237]); + ck_assert_msg(check_msg->contents[238] == 161, + "incorrect value for contents[238], expected 161, is %d", + check_msg->contents[238]); + ck_assert_msg(check_msg->contents[239] == 184, + "incorrect value for contents[239], expected 184, is %d", + check_msg->contents[239]); + ck_assert_msg(check_msg->contents[240] == 5, + "incorrect value for contents[240], expected 5, is %d", + check_msg->contents[240]); + ck_assert_msg(check_msg->contents[241] == 177, + "incorrect value for contents[241], expected 177, is %d", + check_msg->contents[241]); + ck_assert_msg(check_msg->contents[242] == 45, + "incorrect value for contents[242], expected 45, is %d", + check_msg->contents[242]); + ck_assert_msg(check_msg->contents[243] == 37, + "incorrect value for contents[243], expected 37, is %d", + check_msg->contents[243]); + ck_assert_msg(check_msg->contents[244] == 98, + "incorrect value for contents[244], expected 98, is %d", + check_msg->contents[244]); + ck_assert_msg(check_msg->contents[245] == 56, + "incorrect value for contents[245], expected 56, is %d", + check_msg->contents[245]); + ck_assert_msg(check_msg->contents[246] == 149, + "incorrect value for contents[246], expected 149, is %d", + check_msg->contents[246]); + ck_assert_msg(check_msg->contents[247] == 0, + "incorrect value for contents[247], expected 0, is %d", + check_msg->contents[247]); + ck_assert_msg(check_msg->contents[248] == 73, + "incorrect value for contents[248], expected 73, is %d", + check_msg->contents[248]); + ck_assert_msg(check_msg->contents[249] == 221, + "incorrect value for contents[249], expected 221, is %d", + check_msg->contents[249]); + ck_assert_msg(check_msg->contents[250] == 105, + "incorrect value for contents[250], expected 105, is %d", + check_msg->contents[250]); + ck_assert_msg(check_msg->contents[251] == 239, + "incorrect value for contents[251], expected 239, is %d", + check_msg->contents[251]); + ck_assert_msg(check_msg->contents[252] == 168, + "incorrect value for contents[252], expected 168, is %d", + check_msg->contents[252]); + ck_assert_msg(check_msg->contents[253] == 205, + "incorrect value for contents[253], expected 205, is %d", + check_msg->contents[253]); + ck_assert_msg(check_msg->contents[254] == 85, + "incorrect value for contents[254], expected 85, is %d", + check_msg->contents[254]); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_user_MsgUserData_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_user_MsgUserData"); + TCase *tc_acq = + tcase_create("Automated_Suite_legacy_auto_check_sbp_user_MsgUserData"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_user_MsgUserData); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/auto_check_sbp_vehicle_MsgWheeltick.c b/c/test/legacy/auto_check_sbp_vehicle_MsgWheeltick.c new file mode 100644 index 0000000000..f4141acf6f --- /dev/null +++ b/c/test/legacy/auto_check_sbp_vehicle_MsgWheeltick.c @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include // for debugging +#include // for malloc + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u8 len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + void *context; +} last_msg; + +static struct { + u32 n_callbacks_logged; + u16 sender_id; + u16 msg_type; + u8 msg_len; + u8 msg[SBP_MAX_PAYLOAD_LEN]; + u16 frame_len; + u8 frame[SBP_MAX_FRAME_LEN]; + void *context; +} last_frame; + +static u32 dummy_wr = 0; +static u32 dummy_rd = 0; +static u8 dummy_buff[1024]; +static void *last_io_context; + +static int DUMMY_MEMORY_FOR_CALLBACKS = 0xdeadbeef; +static int DUMMY_MEMORY_FOR_IO = 0xdead0000; + +static void dummy_reset() { + dummy_rd = dummy_wr = 0; + memset(dummy_buff, 0, sizeof(dummy_buff)); +} + +static s32 dummy_write(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(dummy_buff + dummy_wr, buff, real_n); + dummy_wr += real_n; + return real_n; +} + +static s32 dummy_read(u8 *buff, u32 n, void *context) { + last_io_context = context; + u32 real_n = n; //(dummy_n > n) ? n : dummy_n; + memcpy(buff, dummy_buff + dummy_rd, real_n); + dummy_rd += real_n; + return real_n; +} + +static void logging_reset() { + memset(&last_msg, 0, sizeof(last_msg)); + memset(&last_frame, 0, sizeof(last_frame)); +} + +static void msg_callback(u16 sender_id, u8 len, u8 msg[], void *context) { + last_msg.n_callbacks_logged++; + last_msg.sender_id = sender_id; + last_msg.len = len; + last_msg.context = context; + memcpy(last_msg.msg, msg, len); +} + +static void frame_callback(u16 sender_id, u16 msg_type, u8 msg_len, u8 msg[], + u16 frame_len, u8 frame[], void *context) { + last_frame.n_callbacks_logged++; + last_frame.sender_id = sender_id; + last_frame.msg_type = msg_type; + last_frame.msg_len = msg_len; + memcpy(last_frame.msg, msg, msg_len); + last_frame.frame_len = frame_len; + memcpy(last_frame.frame, frame, frame_len); + last_frame.context = context; +} + +START_TEST(test_legacy_auto_check_sbp_vehicle_MsgWheeltick) { + static sbp_msg_callbacks_node_t n; + static sbp_msg_callbacks_node_t n2; + + // State of the SBP message parser. + // Must be statically allocated. + sbp_state_t sbp_state; + + // + // Run tests: + // + // Test successful parsing of a message + { + // SBP parser state must be initialized before sbp_process is called. + // We re-initialize before every test so that callbacks for the same message + // types can be + // allocated multiple times across different tests. + sbp_state_init(&sbp_state); + + sbp_state_set_io_context(&sbp_state, &DUMMY_MEMORY_FOR_IO); + + logging_reset(); + + sbp_payload_callback_register(&sbp_state, 0x904, &msg_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n); + sbp_frame_callback_register(&sbp_state, 0x904, &frame_callback, + &DUMMY_MEMORY_FOR_CALLBACKS, &n2); + + u8 encoded_frame[] = { + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, + 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + }; + + dummy_reset(); + + u8 test_msg_storage[SBP_MAX_PAYLOAD_LEN]; + memset(test_msg_storage, 0, sizeof(test_msg_storage)); + u8 test_msg_len = 0; + msg_wheeltick_t *test_msg = (msg_wheeltick_t *)test_msg_storage; + test_msg_len = sizeof(*test_msg); + test_msg->flags = 1; + test_msg->source = 146; + test_msg->ticks = -771148831; + test_msg->time = 112414825470; + sbp_payload_send(&sbp_state, 0x904, 17771, test_msg_len, test_msg_storage, + &dummy_write); + + ck_assert_msg( + test_msg_len == sizeof(encoded_frame) - 8, + "Test message has not been generated correctly, or the encoded frame " + "from the spec is badly defined. Check your test spec"); + + ck_assert_msg(dummy_wr == sizeof(encoded_frame), + "not enough data was written to dummy_buff"); + ck_assert_msg(memcmp(dummy_buff, encoded_frame, sizeof(encoded_frame)) == 0, + "frame was not encoded properly"); + + while (dummy_rd < dummy_wr) { + ck_assert_msg(sbp_process(&sbp_state, &dummy_read) >= SBP_OK, + "sbp_process threw an error!"); + } + + ck_assert_msg(last_msg.n_callbacks_logged == 1, + "msg_callback: one callback should have been logged"); + ck_assert_msg(last_msg.sender_id == 17771, + "msg_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_msg.len == sizeof(encoded_frame) - 8, + "msg_callback: len decoded incorrectly"); + ck_assert_msg( + memcmp(last_msg.msg, encoded_frame + 6, sizeof(encoded_frame) - 8) == 0, + "msg_callback: test data decoded incorrectly"); + ck_assert_msg(last_msg.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + ck_assert_msg(last_frame.n_callbacks_logged == 1, + "frame_callback: one callback should have been logged"); + ck_assert_msg(last_frame.sender_id == 17771, + "frame_callback: sender_id decoded incorrectly"); + ck_assert_msg(last_frame.msg_type == 0x904, + "frame_callback: msg_type decoded incorrectly"); + ck_assert_msg(last_frame.msg_len == sizeof(encoded_frame) - 8, + "frame_callback: msg_len decoded incorrectly"); + ck_assert_msg(memcmp(last_frame.msg, encoded_frame + 6, + sizeof(encoded_frame) - 8) == 0, + "frame_callback: test data decoded incorrectly"); + ck_assert_msg(last_frame.frame_len == sizeof(encoded_frame), + "frame_callback: frame_len decoded incorrectly"); + ck_assert_msg( + memcmp(last_frame.frame, encoded_frame, sizeof(encoded_frame)) == 0, + "frame_callback: frame decoded incorrectly"); + ck_assert_msg(last_frame.context == &DUMMY_MEMORY_FOR_CALLBACKS, + "frame_callback: context pointer incorrectly passed"); + + // Cast to expected message type - the +6 byte offset is where the payload + // starts + msg_wheeltick_t *check_msg = (msg_wheeltick_t *)((void *)last_msg.msg); + // Run tests against fields + ck_assert_msg(check_msg != 0, "stub to prevent warnings if msg isn't used"); + ck_assert_msg(check_msg->flags == 1, + "incorrect value for flags, expected 1, is %d", + check_msg->flags); + ck_assert_msg(check_msg->source == 146, + "incorrect value for source, expected 146, is %d", + check_msg->source); + ck_assert_msg(check_msg->ticks == -771148831, + "incorrect value for ticks, expected -771148831, is %d", + check_msg->ticks); + ck_assert_msg(check_msg->time == 112414825470, + "incorrect value for time, expected 112414825470, is %d", + check_msg->time); + } +} +END_TEST + +Suite *legacy_auto_check_sbp_vehicle_MsgWheeltick_suite(void) { + Suite *s = suite_create( + "SBP generated test suite: legacy_auto_check_sbp_vehicle_MsgWheeltick"); + TCase *tc_acq = tcase_create( + "Automated_Suite_legacy_auto_check_sbp_vehicle_MsgWheeltick"); + tcase_add_test(tc_acq, test_legacy_auto_check_sbp_vehicle_MsgWheeltick); + suite_add_tcase(s, tc_acq); + return s; +} \ No newline at end of file diff --git a/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc new file mode 100644 index 0000000000..40ada2f6b3 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqResult.cc @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_acquisition_MsgAcqResult0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_acquisition_MsgAcqResult0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_acq_result_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_acq_result_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_acquisition_MsgAcqResult0, Test) { + uint8_t encoded_frame[] = { + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, + 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, 189, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_acq_result_t *test_msg = (msg_acq_result_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->cf = 8241.2001953125; + test_msg->cn0 = 14.5; + test_msg->cp = 72.19999694824219; + test_msg->sid.code = 0; + test_msg->sid.sat = 8; + + EXPECT_EQ(send_message(0x2f, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->cf * 100 - 8241.20019531 * 100), 0.05) + << "incorrect value for cf, expected 8241.20019531, is " << last_msg_->cf; + EXPECT_LT((last_msg_->cn0 * 100 - 14.5 * 100), 0.05) + << "incorrect value for cn0, expected 14.5, is " << last_msg_->cn0; + EXPECT_LT((last_msg_->cp * 100 - 72.1999969482 * 100), 0.05) + << "incorrect value for cp, expected 72.1999969482, is " << last_msg_->cp; + EXPECT_EQ(last_msg_->sid.code, 0) + << "incorrect value for sid.code, expected 0, is " << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 8) + << "incorrect value for sid.sat, expected 8, is " << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc new file mode 100644 index 0000000000..b411472d3a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfile.cc @@ -0,0 +1,278 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_acq_sv_profile_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_acq_sv_profile_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfile0, Test) { + uint8_t encoded_frame[] = { + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, 0, 52, + 0, 0, 0, 49, 0, 0, 0, 61, 0, 0, 0, 147, 0, 0, 0, 47, + 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, 0, 253, 23, 1, 121, 0, + 190, 0, 0, 0, 175, 0, 0, 0, 175, 0, 0, 0, 142, 0, 0, 0, + 237, 0, 0, 0, 12, 0, 0, 0, 126, 88, 21, 0, 153, 24, 0, 8, + 0, 130, 0, 0, 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, + 0, 84, 0, 0, 0, 82, 0, 0, 0, 168, 177, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_acq_sv_profile_t *test_msg = (msg_acq_sv_profile_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[0].bin_width = 174; + test_msg->acq_sv_profile[0].cf = 47; + test_msg->acq_sv_profile[0].cf_max = 147; + test_msg->acq_sv_profile[0].cf_min = 61; + test_msg->acq_sv_profile[0].cn0 = 38; + test_msg->acq_sv_profile[0].cp = 140; + test_msg->acq_sv_profile[0].int_time = 97; + test_msg->acq_sv_profile[0].job_type = 7; + test_msg->acq_sv_profile[0].sid.code = 0; + test_msg->acq_sv_profile[0].sid.sat = 22; + test_msg->acq_sv_profile[0].status = 13; + test_msg->acq_sv_profile[0].time_spent = 49; + test_msg->acq_sv_profile[0].timestamp = 52; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[1].bin_width = 121; + test_msg->acq_sv_profile[1].cf = 237; + test_msg->acq_sv_profile[1].cf_max = 142; + test_msg->acq_sv_profile[1].cf_min = 175; + test_msg->acq_sv_profile[1].cn0 = 59; + test_msg->acq_sv_profile[1].cp = 12; + test_msg->acq_sv_profile[1].int_time = 253; + test_msg->acq_sv_profile[1].job_type = 166; + test_msg->acq_sv_profile[1].sid.code = 1; + test_msg->acq_sv_profile[1].sid.sat = 23; + test_msg->acq_sv_profile[1].status = 210; + test_msg->acq_sv_profile[1].time_spent = 175; + test_msg->acq_sv_profile[1].timestamp = 190; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[2].bin_width = 8; + test_msg->acq_sv_profile[2].cf = 84; + test_msg->acq_sv_profile[2].cf_max = 191; + test_msg->acq_sv_profile[2].cf_min = 91; + test_msg->acq_sv_profile[2].cn0 = 21; + test_msg->acq_sv_profile[2].cp = 82; + test_msg->acq_sv_profile[2].int_time = 153; + test_msg->acq_sv_profile[2].job_type = 126; + test_msg->acq_sv_profile[2].sid.code = 0; + test_msg->acq_sv_profile[2].sid.sat = 24; + test_msg->acq_sv_profile[2].status = 88; + test_msg->acq_sv_profile[2].time_spent = 172; + test_msg->acq_sv_profile[2].timestamp = 130; + + EXPECT_EQ(send_message(0x2e, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->acq_sv_profile[0].bin_width, 174) + << "incorrect value for acq_sv_profile[0].bin_width, expected 174, is " + << last_msg_->acq_sv_profile[0].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf, 47) + << "incorrect value for acq_sv_profile[0].cf, expected 47, is " + << last_msg_->acq_sv_profile[0].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf_max, 147) + << "incorrect value for acq_sv_profile[0].cf_max, expected 147, is " + << last_msg_->acq_sv_profile[0].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf_min, 61) + << "incorrect value for acq_sv_profile[0].cf_min, expected 61, is " + << last_msg_->acq_sv_profile[0].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cn0, 38) + << "incorrect value for acq_sv_profile[0].cn0, expected 38, is " + << last_msg_->acq_sv_profile[0].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cp, 140) + << "incorrect value for acq_sv_profile[0].cp, expected 140, is " + << last_msg_->acq_sv_profile[0].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[0].int_time, 97) + << "incorrect value for acq_sv_profile[0].int_time, expected 97, is " + << last_msg_->acq_sv_profile[0].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[0].job_type, 7) + << "incorrect value for acq_sv_profile[0].job_type, expected 7, is " + << last_msg_->acq_sv_profile[0].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[0].sid.code, 0) + << "incorrect value for acq_sv_profile[0].sid.code, expected 0, is " + << last_msg_->acq_sv_profile[0].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[0].sid.sat, 22) + << "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is " + << last_msg_->acq_sv_profile[0].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[0].status, 13) + << "incorrect value for acq_sv_profile[0].status, expected 13, is " + << last_msg_->acq_sv_profile[0].status; + EXPECT_EQ(last_msg_->acq_sv_profile[0].time_spent, 49) + << "incorrect value for acq_sv_profile[0].time_spent, expected 49, is " + << last_msg_->acq_sv_profile[0].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[0].timestamp, 52) + << "incorrect value for acq_sv_profile[0].timestamp, expected 52, is " + << last_msg_->acq_sv_profile[0].timestamp; + EXPECT_EQ(last_msg_->acq_sv_profile[1].bin_width, 121) + << "incorrect value for acq_sv_profile[1].bin_width, expected 121, is " + << last_msg_->acq_sv_profile[1].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf, 237) + << "incorrect value for acq_sv_profile[1].cf, expected 237, is " + << last_msg_->acq_sv_profile[1].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf_max, 142) + << "incorrect value for acq_sv_profile[1].cf_max, expected 142, is " + << last_msg_->acq_sv_profile[1].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf_min, 175) + << "incorrect value for acq_sv_profile[1].cf_min, expected 175, is " + << last_msg_->acq_sv_profile[1].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cn0, 59) + << "incorrect value for acq_sv_profile[1].cn0, expected 59, is " + << last_msg_->acq_sv_profile[1].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cp, 12) + << "incorrect value for acq_sv_profile[1].cp, expected 12, is " + << last_msg_->acq_sv_profile[1].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[1].int_time, 253) + << "incorrect value for acq_sv_profile[1].int_time, expected 253, is " + << last_msg_->acq_sv_profile[1].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[1].job_type, 166) + << "incorrect value for acq_sv_profile[1].job_type, expected 166, is " + << last_msg_->acq_sv_profile[1].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[1].sid.code, 1) + << "incorrect value for acq_sv_profile[1].sid.code, expected 1, is " + << last_msg_->acq_sv_profile[1].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[1].sid.sat, 23) + << "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is " + << last_msg_->acq_sv_profile[1].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[1].status, 210) + << "incorrect value for acq_sv_profile[1].status, expected 210, is " + << last_msg_->acq_sv_profile[1].status; + EXPECT_EQ(last_msg_->acq_sv_profile[1].time_spent, 175) + << "incorrect value for acq_sv_profile[1].time_spent, expected 175, is " + << last_msg_->acq_sv_profile[1].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[1].timestamp, 190) + << "incorrect value for acq_sv_profile[1].timestamp, expected 190, is " + << last_msg_->acq_sv_profile[1].timestamp; + EXPECT_EQ(last_msg_->acq_sv_profile[2].bin_width, 8) + << "incorrect value for acq_sv_profile[2].bin_width, expected 8, is " + << last_msg_->acq_sv_profile[2].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf, 84) + << "incorrect value for acq_sv_profile[2].cf, expected 84, is " + << last_msg_->acq_sv_profile[2].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf_max, 191) + << "incorrect value for acq_sv_profile[2].cf_max, expected 191, is " + << last_msg_->acq_sv_profile[2].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf_min, 91) + << "incorrect value for acq_sv_profile[2].cf_min, expected 91, is " + << last_msg_->acq_sv_profile[2].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cn0, 21) + << "incorrect value for acq_sv_profile[2].cn0, expected 21, is " + << last_msg_->acq_sv_profile[2].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cp, 82) + << "incorrect value for acq_sv_profile[2].cp, expected 82, is " + << last_msg_->acq_sv_profile[2].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[2].int_time, 153) + << "incorrect value for acq_sv_profile[2].int_time, expected 153, is " + << last_msg_->acq_sv_profile[2].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[2].job_type, 126) + << "incorrect value for acq_sv_profile[2].job_type, expected 126, is " + << last_msg_->acq_sv_profile[2].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[2].sid.code, 0) + << "incorrect value for acq_sv_profile[2].sid.code, expected 0, is " + << last_msg_->acq_sv_profile[2].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[2].sid.sat, 24) + << "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is " + << last_msg_->acq_sv_profile[2].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[2].status, 88) + << "incorrect value for acq_sv_profile[2].status, expected 88, is " + << last_msg_->acq_sv_profile[2].status; + EXPECT_EQ(last_msg_->acq_sv_profile[2].time_spent, 172) + << "incorrect value for acq_sv_profile[2].time_spent, expected 172, is " + << last_msg_->acq_sv_profile[2].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[2].timestamp, 130) + << "incorrect value for acq_sv_profile[2].timestamp, expected 130, is " + << last_msg_->acq_sv_profile[2].timestamp; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc new file mode 100644 index 0000000000..be682851fa --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_acquisition_MsgAcqSvProfileDep.cc @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_acq_sv_profile_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_acq_sv_profile_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_acquisition_MsgAcqSvProfileDep0, Test) { + uint8_t encoded_frame[] = { + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, + 187, 0, 91, 0, 0, 0, 75, 0, 0, 0, 132, 0, 0, 0, 36, + 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, + 179, 23, 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, + 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, 247, 0, 0, + 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, + 0, 245, 0, 0, 0, 76, 0, 0, 0, 248, 0, 0, 0, 212, 0, + 0, 0, 101, 0, 0, 0, 67, 132, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_acq_sv_profile_dep_t *test_msg = + (msg_acq_sv_profile_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[0].bin_width = 187; + test_msg->acq_sv_profile[0].cf = 60; + test_msg->acq_sv_profile[0].cf_max = 36; + test_msg->acq_sv_profile[0].cf_min = 132; + test_msg->acq_sv_profile[0].cn0 = 151; + test_msg->acq_sv_profile[0].cp = 241; + test_msg->acq_sv_profile[0].int_time = 12; + test_msg->acq_sv_profile[0].job_type = 67; + test_msg->acq_sv_profile[0].sid.code = 0; + test_msg->acq_sv_profile[0].sid.reserved = 0; + test_msg->acq_sv_profile[0].sid.sat = 22; + test_msg->acq_sv_profile[0].status = 103; + test_msg->acq_sv_profile[0].time_spent = 75; + test_msg->acq_sv_profile[0].timestamp = 91; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[1].bin_width = 176; + test_msg->acq_sv_profile[1].cf = 212; + test_msg->acq_sv_profile[1].cf_max = 24; + test_msg->acq_sv_profile[1].cf_min = 155; + test_msg->acq_sv_profile[1].cn0 = 111; + test_msg->acq_sv_profile[1].cp = 247; + test_msg->acq_sv_profile[1].int_time = 179; + test_msg->acq_sv_profile[1].job_type = 238; + test_msg->acq_sv_profile[1].sid.code = 1; + test_msg->acq_sv_profile[1].sid.reserved = 0; + test_msg->acq_sv_profile[1].sid.sat = 23; + test_msg->acq_sv_profile[1].status = 38; + test_msg->acq_sv_profile[1].time_spent = 234; + test_msg->acq_sv_profile[1].timestamp = 166; + if (sizeof(test_msg->acq_sv_profile) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->acq_sv_profile[0])); + } + test_msg->acq_sv_profile[2].bin_width = 52; + test_msg->acq_sv_profile[2].cf = 212; + test_msg->acq_sv_profile[2].cf_max = 248; + test_msg->acq_sv_profile[2].cf_min = 76; + test_msg->acq_sv_profile[2].cn0 = 68; + test_msg->acq_sv_profile[2].cp = 101; + test_msg->acq_sv_profile[2].int_time = 53; + test_msg->acq_sv_profile[2].job_type = 142; + test_msg->acq_sv_profile[2].sid.code = 0; + test_msg->acq_sv_profile[2].sid.reserved = 0; + test_msg->acq_sv_profile[2].sid.sat = 24; + test_msg->acq_sv_profile[2].status = 213; + test_msg->acq_sv_profile[2].time_spent = 245; + test_msg->acq_sv_profile[2].timestamp = 49; + + EXPECT_EQ(send_message(0x1e, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->acq_sv_profile[0].bin_width, 187) + << "incorrect value for acq_sv_profile[0].bin_width, expected 187, is " + << last_msg_->acq_sv_profile[0].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf, 60) + << "incorrect value for acq_sv_profile[0].cf, expected 60, is " + << last_msg_->acq_sv_profile[0].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf_max, 36) + << "incorrect value for acq_sv_profile[0].cf_max, expected 36, is " + << last_msg_->acq_sv_profile[0].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cf_min, 132) + << "incorrect value for acq_sv_profile[0].cf_min, expected 132, is " + << last_msg_->acq_sv_profile[0].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cn0, 151) + << "incorrect value for acq_sv_profile[0].cn0, expected 151, is " + << last_msg_->acq_sv_profile[0].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[0].cp, 241) + << "incorrect value for acq_sv_profile[0].cp, expected 241, is " + << last_msg_->acq_sv_profile[0].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[0].int_time, 12) + << "incorrect value for acq_sv_profile[0].int_time, expected 12, is " + << last_msg_->acq_sv_profile[0].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[0].job_type, 67) + << "incorrect value for acq_sv_profile[0].job_type, expected 67, is " + << last_msg_->acq_sv_profile[0].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[0].sid.code, 0) + << "incorrect value for acq_sv_profile[0].sid.code, expected 0, is " + << last_msg_->acq_sv_profile[0].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[0].sid.reserved, 0) + << "incorrect value for acq_sv_profile[0].sid.reserved, expected 0, is " + << last_msg_->acq_sv_profile[0].sid.reserved; + EXPECT_EQ(last_msg_->acq_sv_profile[0].sid.sat, 22) + << "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is " + << last_msg_->acq_sv_profile[0].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[0].status, 103) + << "incorrect value for acq_sv_profile[0].status, expected 103, is " + << last_msg_->acq_sv_profile[0].status; + EXPECT_EQ(last_msg_->acq_sv_profile[0].time_spent, 75) + << "incorrect value for acq_sv_profile[0].time_spent, expected 75, is " + << last_msg_->acq_sv_profile[0].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[0].timestamp, 91) + << "incorrect value for acq_sv_profile[0].timestamp, expected 91, is " + << last_msg_->acq_sv_profile[0].timestamp; + EXPECT_EQ(last_msg_->acq_sv_profile[1].bin_width, 176) + << "incorrect value for acq_sv_profile[1].bin_width, expected 176, is " + << last_msg_->acq_sv_profile[1].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf, 212) + << "incorrect value for acq_sv_profile[1].cf, expected 212, is " + << last_msg_->acq_sv_profile[1].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf_max, 24) + << "incorrect value for acq_sv_profile[1].cf_max, expected 24, is " + << last_msg_->acq_sv_profile[1].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cf_min, 155) + << "incorrect value for acq_sv_profile[1].cf_min, expected 155, is " + << last_msg_->acq_sv_profile[1].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cn0, 111) + << "incorrect value for acq_sv_profile[1].cn0, expected 111, is " + << last_msg_->acq_sv_profile[1].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[1].cp, 247) + << "incorrect value for acq_sv_profile[1].cp, expected 247, is " + << last_msg_->acq_sv_profile[1].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[1].int_time, 179) + << "incorrect value for acq_sv_profile[1].int_time, expected 179, is " + << last_msg_->acq_sv_profile[1].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[1].job_type, 238) + << "incorrect value for acq_sv_profile[1].job_type, expected 238, is " + << last_msg_->acq_sv_profile[1].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[1].sid.code, 1) + << "incorrect value for acq_sv_profile[1].sid.code, expected 1, is " + << last_msg_->acq_sv_profile[1].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[1].sid.reserved, 0) + << "incorrect value for acq_sv_profile[1].sid.reserved, expected 0, is " + << last_msg_->acq_sv_profile[1].sid.reserved; + EXPECT_EQ(last_msg_->acq_sv_profile[1].sid.sat, 23) + << "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is " + << last_msg_->acq_sv_profile[1].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[1].status, 38) + << "incorrect value for acq_sv_profile[1].status, expected 38, is " + << last_msg_->acq_sv_profile[1].status; + EXPECT_EQ(last_msg_->acq_sv_profile[1].time_spent, 234) + << "incorrect value for acq_sv_profile[1].time_spent, expected 234, is " + << last_msg_->acq_sv_profile[1].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[1].timestamp, 166) + << "incorrect value for acq_sv_profile[1].timestamp, expected 166, is " + << last_msg_->acq_sv_profile[1].timestamp; + EXPECT_EQ(last_msg_->acq_sv_profile[2].bin_width, 52) + << "incorrect value for acq_sv_profile[2].bin_width, expected 52, is " + << last_msg_->acq_sv_profile[2].bin_width; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf, 212) + << "incorrect value for acq_sv_profile[2].cf, expected 212, is " + << last_msg_->acq_sv_profile[2].cf; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf_max, 248) + << "incorrect value for acq_sv_profile[2].cf_max, expected 248, is " + << last_msg_->acq_sv_profile[2].cf_max; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cf_min, 76) + << "incorrect value for acq_sv_profile[2].cf_min, expected 76, is " + << last_msg_->acq_sv_profile[2].cf_min; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cn0, 68) + << "incorrect value for acq_sv_profile[2].cn0, expected 68, is " + << last_msg_->acq_sv_profile[2].cn0; + EXPECT_EQ(last_msg_->acq_sv_profile[2].cp, 101) + << "incorrect value for acq_sv_profile[2].cp, expected 101, is " + << last_msg_->acq_sv_profile[2].cp; + EXPECT_EQ(last_msg_->acq_sv_profile[2].int_time, 53) + << "incorrect value for acq_sv_profile[2].int_time, expected 53, is " + << last_msg_->acq_sv_profile[2].int_time; + EXPECT_EQ(last_msg_->acq_sv_profile[2].job_type, 142) + << "incorrect value for acq_sv_profile[2].job_type, expected 142, is " + << last_msg_->acq_sv_profile[2].job_type; + EXPECT_EQ(last_msg_->acq_sv_profile[2].sid.code, 0) + << "incorrect value for acq_sv_profile[2].sid.code, expected 0, is " + << last_msg_->acq_sv_profile[2].sid.code; + EXPECT_EQ(last_msg_->acq_sv_profile[2].sid.reserved, 0) + << "incorrect value for acq_sv_profile[2].sid.reserved, expected 0, is " + << last_msg_->acq_sv_profile[2].sid.reserved; + EXPECT_EQ(last_msg_->acq_sv_profile[2].sid.sat, 24) + << "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is " + << last_msg_->acq_sv_profile[2].sid.sat; + EXPECT_EQ(last_msg_->acq_sv_profile[2].status, 213) + << "incorrect value for acq_sv_profile[2].status, expected 213, is " + << last_msg_->acq_sv_profile[2].status; + EXPECT_EQ(last_msg_->acq_sv_profile[2].time_spent, 245) + << "incorrect value for acq_sv_profile[2].time_spent, expected 245, is " + << last_msg_->acq_sv_profile[2].time_spent; + EXPECT_EQ(last_msg_->acq_sv_profile[2].timestamp, 49) + << "incorrect value for acq_sv_profile[2].timestamp, expected 49, is " + << last_msg_->acq_sv_profile[2].timestamp; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc new file mode 100644 index 0000000000..95e21b1e37 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderHandshakeReq.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc new file mode 100644 index 0000000000..5a2c098d36 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgBootloaderJumptoApp.cc @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_bootloader_jump_to_app_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_bootloader_jump_to_app_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_bootload_MsgBootloaderJumptoApp0, Test) { + uint8_t encoded_frame[] = { + 85, 177, 0, 205, 18, 1, 216, 105, 96, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_bootloader_jump_to_app_t *test_msg = + (msg_bootloader_jump_to_app_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->jump = 216; + + EXPECT_EQ(send_message(0xb1, 4813, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 4813); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->jump, 216) + << "incorrect value for jump, expected 216, is " << last_msg_->jump; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc new file mode 100644 index 0000000000..de12108473 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaReq.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc new file mode 100644 index 0000000000..56dcacb0b6 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_bootload_MsgNapDeviceDnaResp.cc @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_nap_device_dna_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_nap_device_dna_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_bootload_MsgNapDeviceDnaResp0, Test) { + uint8_t encoded_frame[] = { + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_nap_device_dna_resp_t *test_msg = + (msg_nap_device_dna_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[0] = 2; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[1] = 187; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[2] = 1; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[3] = 130; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[4] = 173; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[5] = 244; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[6] = 67; + if (sizeof(test_msg->dna) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->dna[0])); + } + test_msg->dna[7] = 122; + + EXPECT_EQ(send_message(0xdd, 14505, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 14505); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->dna[0], 2) + << "incorrect value for dna[0], expected 2, is " << last_msg_->dna[0]; + EXPECT_EQ(last_msg_->dna[1], 187) + << "incorrect value for dna[1], expected 187, is " << last_msg_->dna[1]; + EXPECT_EQ(last_msg_->dna[2], 1) + << "incorrect value for dna[2], expected 1, is " << last_msg_->dna[2]; + EXPECT_EQ(last_msg_->dna[3], 130) + << "incorrect value for dna[3], expected 130, is " << last_msg_->dna[3]; + EXPECT_EQ(last_msg_->dna[4], 173) + << "incorrect value for dna[4], expected 173, is " << last_msg_->dna[4]; + EXPECT_EQ(last_msg_->dna[5], 244) + << "incorrect value for dna[5], expected 244, is " << last_msg_->dna[5]; + EXPECT_EQ(last_msg_->dna[6], 67) + << "incorrect value for dna[6], expected 67, is " << last_msg_->dna[6]; + EXPECT_EQ(last_msg_->dna[7], 122) + << "incorrect value for dna[7], expected 122, is " << last_msg_->dna[7]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc new file mode 100644 index 0000000000..237550bfab --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigReq.cc @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioConfigReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioConfigReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_config_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_config_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioConfigReq0, Test) { + uint8_t encoded_frame[] = { + 85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_config_req_t *test_msg = + (msg_fileio_config_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->sequence = 1514527339; + + EXPECT_EQ(send_message(0x1001, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->sequence, 1514527339) + << "incorrect value for sequence, expected 1514527339, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc new file mode 100644 index 0000000000..83a52e2c98 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioConfigResp.cc @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioConfigResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioConfigResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_config_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_config_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioConfigResp0, Test) { + uint8_t encoded_frame[] = { + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, + 44, 3, 216, 151, 255, 61, 12, 97, 66, 144, 239, 115, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_config_resp_t *test_msg = + (msg_fileio_config_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->batch_size = 1040160728; + test_msg->fileio_version = 2420269324; + test_msg->sequence = 1530154154; + test_msg->window_size = 53262997; + + EXPECT_EQ(send_message(0x1002, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->batch_size, 1040160728) + << "incorrect value for batch_size, expected 1040160728, is " + << last_msg_->batch_size; + EXPECT_EQ(last_msg_->fileio_version, 2420269324) + << "incorrect value for fileio_version, expected 2420269324, is " + << last_msg_->fileio_version; + EXPECT_EQ(last_msg_->sequence, 1530154154) + << "incorrect value for sequence, expected 1530154154, is " + << last_msg_->sequence; + EXPECT_EQ(last_msg_->window_size, 53262997) + << "incorrect value for window_size, expected 53262997, is " + << last_msg_->window_size; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc new file mode 100644 index 0000000000..72b4e358c1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirReq.cc @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_read_dir_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_read_dir_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirReq0, Test) { + uint8_t encoded_frame[] = { + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, + 47, 134, 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, + 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_read_dir_req_t *test_msg = + (msg_fileio_read_dir_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)115, (char)111, (char)109, (char)101, (char)47, + (char)114, (char)97, (char)110, (char)100, (char)111, (char)109, + (char)47, (char)112, (char)97, (char)116, (char)104, (char)0}; + memcpy(test_msg->dirname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->dirname) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->offset = 2251261636; + test_msg->sequence = 1526720386; + + EXPECT_EQ(send_message(0xa9, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)115, (char)111, (char)109, (char)101, (char)47, + (char)114, (char)97, (char)110, (char)100, (char)111, (char)109, + (char)47, (char)112, (char)97, (char)116, (char)104, (char)0}; + EXPECT_EQ(memcmp(last_msg_->dirname, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->dirname, expected string '" + << check_string << "', is '" << last_msg_->dirname << "'"; + } + EXPECT_EQ(last_msg_->offset, 2251261636) + << "incorrect value for offset, expected 2251261636, is " + << last_msg_->offset; + EXPECT_EQ(last_msg_->sequence, 1526720386) + << "incorrect value for sequence, expected 1526720386, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc new file mode 100644 index 0000000000..ec3545c252 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadDirResp.cc @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_read_dir_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_read_dir_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioReadDirResp0, Test) { + uint8_t encoded_frame[] = { + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, + 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, 108, 101, + 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, 111, + 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_read_dir_resp_t *test_msg = + (msg_fileio_read_dir_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)102, (char)105, (char)108, (char)101, (char)49, (char)0, + (char)97, (char)110, (char)111, (char)116, (char)104, (char)101, + (char)114, (char)32, (char)102, (char)105, (char)108, (char)101, + (char)0, (char)100, (char)101, (char)102, (char)105, (char)110, + (char)105, (char)116, (char)101, (char)108, (char)121, (char)32, + (char)110, (char)111, (char)116, (char)32, (char)97, (char)32, + (char)102, (char)105, (char)108, (char)101, (char)0}; + memcpy(test_msg->contents, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->contents) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->sequence = 3957390670; + + EXPECT_EQ(send_message(0xaa, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)102, (char)105, (char)108, (char)101, (char)49, (char)0, + (char)97, (char)110, (char)111, (char)116, (char)104, (char)101, + (char)114, (char)32, (char)102, (char)105, (char)108, (char)101, + (char)0, (char)100, (char)101, (char)102, (char)105, (char)110, + (char)105, (char)116, (char)101, (char)108, (char)121, (char)32, + (char)110, (char)111, (char)116, (char)32, (char)97, (char)32, + (char)102, (char)105, (char)108, (char)101, (char)0}; + EXPECT_EQ(memcmp(last_msg_->contents, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->contents, expected string '" + << check_string << "', is '" << last_msg_->contents << "'"; + } + EXPECT_EQ(last_msg_->sequence, 3957390670) + << "incorrect value for sequence, expected 3957390670, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc new file mode 100644 index 0000000000..c24aa972dc --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadReq.cc @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioReadReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioReadReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_read_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_read_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioReadReq0, Test) { + uint8_t encoded_frame[] = { + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, + 190, 23, 53, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_read_req_t *test_msg = (msg_fileio_read_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->chunk_size = 53; + { + const char assign_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)115, (char)111, (char)109, + (char)101, (char)47, (char)102, (char)105, + (char)108, (char)101, (char)0}; + memcpy(test_msg->filename, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->filename) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->offset = 398373474; + test_msg->sequence = 679648290; + + EXPECT_EQ(send_message(0xa8, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->chunk_size, 53) + << "incorrect value for chunk_size, expected 53, is " + << last_msg_->chunk_size; + { + const char check_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)115, (char)111, (char)109, + (char)101, (char)47, (char)102, (char)105, + (char)108, (char)101, (char)0}; + EXPECT_EQ(memcmp(last_msg_->filename, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->filename, expected string '" + << check_string << "', is '" << last_msg_->filename << "'"; + } + EXPECT_EQ(last_msg_->offset, 398373474) + << "incorrect value for offset, expected 398373474, is " + << last_msg_->offset; + EXPECT_EQ(last_msg_->sequence, 679648290) + << "incorrect value for sequence, expected 679648290, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc new file mode 100644 index 0000000000..963c8c5dcf --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioReadResp.cc @@ -0,0 +1,2131 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioReadResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioReadResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_read_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_read_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioReadResp0, Test) { + uint8_t encoded_frame[] = { + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, 18, + 76, 68, 229, 216, 21, 98, 183, 69, 190, 5, 252, 176, 55, 32, 78, + 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, 46, 79, 118, 248, 118, + 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, 206, 185, 140, 249, + 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, 77, 224, 124, 238, 205, + 65, 103, 35, 104, 209, 5, 191, 47, 249, 176, 166, 213, 46, 192, 86, + 32, 103, 146, 252, 4, 16, 54, 161, 60, 6, 13, 191, 116, 182, 42, + 191, 213, 20, 217, 8, 142, 187, 238, 120, 184, 250, 31, 151, 37, 51, + 177, 130, 190, 155, 71, 68, 56, 238, 92, 130, 37, 137, 146, 246, 114, + 116, 138, 165, 217, 79, 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, + 236, 228, 194, 0, 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, + 3, 240, 205, 253, 113, 25, 28, 187, 81, 101, 216, 121, 41, 179, 120, + 152, 18, 116, 53, 212, 100, 2, 114, 198, 200, 10, 147, 25, 33, 115, + 208, 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, 133, + 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, 180, + 180, 125, 97, 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, 65, 4, + 64, 19, 74, 223, 111, 109, 52, 43, 167, 186, 202, 111, 11, 91, 21, + 236, 234, 196, 36, 171, 147, 10, 240, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_read_resp_t *test_msg = (msg_fileio_read_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[0] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[1] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[2] = 227; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[3] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[4] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[5] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[6] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[7] = 229; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[8] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[9] = 21; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[10] = 98; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[11] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[12] = 69; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[13] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[14] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[15] = 252; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[16] = 176; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[17] = 55; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[18] = 32; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[19] = 78; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[20] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[21] = 52; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[22] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[23] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[24] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[25] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[26] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[27] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[28] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[29] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[30] = 46; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[31] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[32] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[33] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[34] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[35] = 207; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[36] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[37] = 210; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[38] = 91; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[39] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[40] = 251; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[41] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[42] = 131; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[43] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[44] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[45] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[46] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[47] = 185; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[48] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[49] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[50] = 163; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[51] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[52] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[53] = 67; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[54] = 94; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[55] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[56] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[57] = 152; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[58] = 95; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[59] = 123; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[60] = 77; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[61] = 224; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[62] = 124; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[63] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[64] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[65] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[66] = 103; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[67] = 35; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[68] = 104; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[69] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[70] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[71] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[72] = 47; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[73] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[74] = 176; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[75] = 166; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[76] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[77] = 46; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[78] = 192; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[79] = 86; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[80] = 32; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[81] = 103; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[82] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[83] = 252; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[84] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[85] = 16; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[86] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[87] = 161; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[88] = 60; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[89] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[90] = 13; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[91] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[92] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[93] = 182; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[94] = 42; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[95] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[96] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[97] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[98] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[99] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[100] = 142; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[101] = 187; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[102] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[103] = 120; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[104] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[105] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[106] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[107] = 151; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[108] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[109] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[110] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[111] = 130; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[112] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[113] = 155; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[114] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[115] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[116] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[117] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[118] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[119] = 130; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[120] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[121] = 137; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[122] = 146; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[123] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[124] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[125] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[126] = 138; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[127] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[128] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[129] = 79; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[130] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[131] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[132] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[133] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[134] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[135] = 240; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[136] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[137] = 28; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[138] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[139] = 105; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[140] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[141] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[142] = 194; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[143] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[144] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[145] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[146] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[147] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[148] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[149] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[150] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[151] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[152] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[153] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[154] = 27; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[155] = 3; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[156] = 240; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[157] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[158] = 253; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[159] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[160] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[161] = 28; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[162] = 187; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[163] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[164] = 101; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[165] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[166] = 121; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[167] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[168] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[169] = 120; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[170] = 152; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[171] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[172] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[173] = 53; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[174] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[175] = 100; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[176] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[177] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[178] = 198; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[179] = 200; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[180] = 10; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[181] = 147; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[182] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[183] = 33; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[184] = 115; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[185] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[186] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[187] = 60; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[188] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[189] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[190] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[191] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[192] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[193] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[194] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[195] = 211; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[196] = 225; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[197] = 142; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[198] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[199] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[200] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[201] = 15; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[202] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[203] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[204] = 66; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[205] = 191; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[206] = 244; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[207] = 221; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[208] = 248; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[209] = 199; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[210] = 241; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[211] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[212] = 51; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[213] = 1; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[214] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[215] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[216] = 125; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[217] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[218] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[219] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[220] = 72; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[221] = 210; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[222] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[223] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[224] = 15; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[225] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[226] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[227] = 38; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[228] = 65; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[229] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[230] = 64; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[231] = 19; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[232] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[233] = 223; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[234] = 111; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[235] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[236] = 52; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[237] = 43; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[238] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[239] = 186; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[240] = 202; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[241] = 111; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[242] = 11; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[243] = 91; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[244] = 21; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[245] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[246] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[247] = 196; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[248] = 36; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[249] = 171; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[250] = 147; + test_msg->sequence = 259241795; + + EXPECT_EQ(send_message(0xa3, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->contents[0], 73) + << "incorrect value for contents[0], expected 73, is " + << last_msg_->contents[0]; + EXPECT_EQ(last_msg_->contents[1], 231) + << "incorrect value for contents[1], expected 231, is " + << last_msg_->contents[1]; + EXPECT_EQ(last_msg_->contents[2], 227) + << "incorrect value for contents[2], expected 227, is " + << last_msg_->contents[2]; + EXPECT_EQ(last_msg_->contents[3], 179) + << "incorrect value for contents[3], expected 179, is " + << last_msg_->contents[3]; + EXPECT_EQ(last_msg_->contents[4], 18) + << "incorrect value for contents[4], expected 18, is " + << last_msg_->contents[4]; + EXPECT_EQ(last_msg_->contents[5], 76) + << "incorrect value for contents[5], expected 76, is " + << last_msg_->contents[5]; + EXPECT_EQ(last_msg_->contents[6], 68) + << "incorrect value for contents[6], expected 68, is " + << last_msg_->contents[6]; + EXPECT_EQ(last_msg_->contents[7], 229) + << "incorrect value for contents[7], expected 229, is " + << last_msg_->contents[7]; + EXPECT_EQ(last_msg_->contents[8], 216) + << "incorrect value for contents[8], expected 216, is " + << last_msg_->contents[8]; + EXPECT_EQ(last_msg_->contents[9], 21) + << "incorrect value for contents[9], expected 21, is " + << last_msg_->contents[9]; + EXPECT_EQ(last_msg_->contents[10], 98) + << "incorrect value for contents[10], expected 98, is " + << last_msg_->contents[10]; + EXPECT_EQ(last_msg_->contents[11], 183) + << "incorrect value for contents[11], expected 183, is " + << last_msg_->contents[11]; + EXPECT_EQ(last_msg_->contents[12], 69) + << "incorrect value for contents[12], expected 69, is " + << last_msg_->contents[12]; + EXPECT_EQ(last_msg_->contents[13], 190) + << "incorrect value for contents[13], expected 190, is " + << last_msg_->contents[13]; + EXPECT_EQ(last_msg_->contents[14], 5) + << "incorrect value for contents[14], expected 5, is " + << last_msg_->contents[14]; + EXPECT_EQ(last_msg_->contents[15], 252) + << "incorrect value for contents[15], expected 252, is " + << last_msg_->contents[15]; + EXPECT_EQ(last_msg_->contents[16], 176) + << "incorrect value for contents[16], expected 176, is " + << last_msg_->contents[16]; + EXPECT_EQ(last_msg_->contents[17], 55) + << "incorrect value for contents[17], expected 55, is " + << last_msg_->contents[17]; + EXPECT_EQ(last_msg_->contents[18], 32) + << "incorrect value for contents[18], expected 32, is " + << last_msg_->contents[18]; + EXPECT_EQ(last_msg_->contents[19], 78) + << "incorrect value for contents[19], expected 78, is " + << last_msg_->contents[19]; + EXPECT_EQ(last_msg_->contents[20], 8) + << "incorrect value for contents[20], expected 8, is " + << last_msg_->contents[20]; + EXPECT_EQ(last_msg_->contents[21], 52) + << "incorrect value for contents[21], expected 52, is " + << last_msg_->contents[21]; + EXPECT_EQ(last_msg_->contents[22], 127) + << "incorrect value for contents[22], expected 127, is " + << last_msg_->contents[22]; + EXPECT_EQ(last_msg_->contents[23], 50) + << "incorrect value for contents[23], expected 50, is " + << last_msg_->contents[23]; + EXPECT_EQ(last_msg_->contents[24], 71) + << "incorrect value for contents[24], expected 71, is " + << last_msg_->contents[24]; + EXPECT_EQ(last_msg_->contents[25], 106) + << "incorrect value for contents[25], expected 106, is " + << last_msg_->contents[25]; + EXPECT_EQ(last_msg_->contents[26], 61) + << "incorrect value for contents[26], expected 61, is " + << last_msg_->contents[26]; + EXPECT_EQ(last_msg_->contents[27], 79) + << "incorrect value for contents[27], expected 79, is " + << last_msg_->contents[27]; + EXPECT_EQ(last_msg_->contents[28], 191) + << "incorrect value for contents[28], expected 191, is " + << last_msg_->contents[28]; + EXPECT_EQ(last_msg_->contents[29], 106) + << "incorrect value for contents[29], expected 106, is " + << last_msg_->contents[29]; + EXPECT_EQ(last_msg_->contents[30], 46) + << "incorrect value for contents[30], expected 46, is " + << last_msg_->contents[30]; + EXPECT_EQ(last_msg_->contents[31], 79) + << "incorrect value for contents[31], expected 79, is " + << last_msg_->contents[31]; + EXPECT_EQ(last_msg_->contents[32], 118) + << "incorrect value for contents[32], expected 118, is " + << last_msg_->contents[32]; + EXPECT_EQ(last_msg_->contents[33], 248) + << "incorrect value for contents[33], expected 248, is " + << last_msg_->contents[33]; + EXPECT_EQ(last_msg_->contents[34], 118) + << "incorrect value for contents[34], expected 118, is " + << last_msg_->contents[34]; + EXPECT_EQ(last_msg_->contents[35], 207) + << "incorrect value for contents[35], expected 207, is " + << last_msg_->contents[35]; + EXPECT_EQ(last_msg_->contents[36], 206) + << "incorrect value for contents[36], expected 206, is " + << last_msg_->contents[36]; + EXPECT_EQ(last_msg_->contents[37], 210) + << "incorrect value for contents[37], expected 210, is " + << last_msg_->contents[37]; + EXPECT_EQ(last_msg_->contents[38], 91) + << "incorrect value for contents[38], expected 91, is " + << last_msg_->contents[38]; + EXPECT_EQ(last_msg_->contents[39], 73) + << "incorrect value for contents[39], expected 73, is " + << last_msg_->contents[39]; + EXPECT_EQ(last_msg_->contents[40], 251) + << "incorrect value for contents[40], expected 251, is " + << last_msg_->contents[40]; + EXPECT_EQ(last_msg_->contents[41], 81) + << "incorrect value for contents[41], expected 81, is " + << last_msg_->contents[41]; + EXPECT_EQ(last_msg_->contents[42], 131) + << "incorrect value for contents[42], expected 131, is " + << last_msg_->contents[42]; + EXPECT_EQ(last_msg_->contents[43], 205) + << "incorrect value for contents[43], expected 205, is " + << last_msg_->contents[43]; + EXPECT_EQ(last_msg_->contents[44], 193) + << "incorrect value for contents[44], expected 193, is " + << last_msg_->contents[44]; + EXPECT_EQ(last_msg_->contents[45], 146) + << "incorrect value for contents[45], expected 146, is " + << last_msg_->contents[45]; + EXPECT_EQ(last_msg_->contents[46], 206) + << "incorrect value for contents[46], expected 206, is " + << last_msg_->contents[46]; + EXPECT_EQ(last_msg_->contents[47], 185) + << "incorrect value for contents[47], expected 185, is " + << last_msg_->contents[47]; + EXPECT_EQ(last_msg_->contents[48], 140) + << "incorrect value for contents[48], expected 140, is " + << last_msg_->contents[48]; + EXPECT_EQ(last_msg_->contents[49], 249) + << "incorrect value for contents[49], expected 249, is " + << last_msg_->contents[49]; + EXPECT_EQ(last_msg_->contents[50], 163) + << "incorrect value for contents[50], expected 163, is " + << last_msg_->contents[50]; + EXPECT_EQ(last_msg_->contents[51], 231) + << "incorrect value for contents[51], expected 231, is " + << last_msg_->contents[51]; + EXPECT_EQ(last_msg_->contents[52], 65) + << "incorrect value for contents[52], expected 65, is " + << last_msg_->contents[52]; + EXPECT_EQ(last_msg_->contents[53], 67) + << "incorrect value for contents[53], expected 67, is " + << last_msg_->contents[53]; + EXPECT_EQ(last_msg_->contents[54], 94) + << "incorrect value for contents[54], expected 94, is " + << last_msg_->contents[54]; + EXPECT_EQ(last_msg_->contents[55], 250) + << "incorrect value for contents[55], expected 250, is " + << last_msg_->contents[55]; + EXPECT_EQ(last_msg_->contents[56], 109) + << "incorrect value for contents[56], expected 109, is " + << last_msg_->contents[56]; + EXPECT_EQ(last_msg_->contents[57], 152) + << "incorrect value for contents[57], expected 152, is " + << last_msg_->contents[57]; + EXPECT_EQ(last_msg_->contents[58], 95) + << "incorrect value for contents[58], expected 95, is " + << last_msg_->contents[58]; + EXPECT_EQ(last_msg_->contents[59], 123) + << "incorrect value for contents[59], expected 123, is " + << last_msg_->contents[59]; + EXPECT_EQ(last_msg_->contents[60], 77) + << "incorrect value for contents[60], expected 77, is " + << last_msg_->contents[60]; + EXPECT_EQ(last_msg_->contents[61], 224) + << "incorrect value for contents[61], expected 224, is " + << last_msg_->contents[61]; + EXPECT_EQ(last_msg_->contents[62], 124) + << "incorrect value for contents[62], expected 124, is " + << last_msg_->contents[62]; + EXPECT_EQ(last_msg_->contents[63], 238) + << "incorrect value for contents[63], expected 238, is " + << last_msg_->contents[63]; + EXPECT_EQ(last_msg_->contents[64], 205) + << "incorrect value for contents[64], expected 205, is " + << last_msg_->contents[64]; + EXPECT_EQ(last_msg_->contents[65], 65) + << "incorrect value for contents[65], expected 65, is " + << last_msg_->contents[65]; + EXPECT_EQ(last_msg_->contents[66], 103) + << "incorrect value for contents[66], expected 103, is " + << last_msg_->contents[66]; + EXPECT_EQ(last_msg_->contents[67], 35) + << "incorrect value for contents[67], expected 35, is " + << last_msg_->contents[67]; + EXPECT_EQ(last_msg_->contents[68], 104) + << "incorrect value for contents[68], expected 104, is " + << last_msg_->contents[68]; + EXPECT_EQ(last_msg_->contents[69], 209) + << "incorrect value for contents[69], expected 209, is " + << last_msg_->contents[69]; + EXPECT_EQ(last_msg_->contents[70], 5) + << "incorrect value for contents[70], expected 5, is " + << last_msg_->contents[70]; + EXPECT_EQ(last_msg_->contents[71], 191) + << "incorrect value for contents[71], expected 191, is " + << last_msg_->contents[71]; + EXPECT_EQ(last_msg_->contents[72], 47) + << "incorrect value for contents[72], expected 47, is " + << last_msg_->contents[72]; + EXPECT_EQ(last_msg_->contents[73], 249) + << "incorrect value for contents[73], expected 249, is " + << last_msg_->contents[73]; + EXPECT_EQ(last_msg_->contents[74], 176) + << "incorrect value for contents[74], expected 176, is " + << last_msg_->contents[74]; + EXPECT_EQ(last_msg_->contents[75], 166) + << "incorrect value for contents[75], expected 166, is " + << last_msg_->contents[75]; + EXPECT_EQ(last_msg_->contents[76], 213) + << "incorrect value for contents[76], expected 213, is " + << last_msg_->contents[76]; + EXPECT_EQ(last_msg_->contents[77], 46) + << "incorrect value for contents[77], expected 46, is " + << last_msg_->contents[77]; + EXPECT_EQ(last_msg_->contents[78], 192) + << "incorrect value for contents[78], expected 192, is " + << last_msg_->contents[78]; + EXPECT_EQ(last_msg_->contents[79], 86) + << "incorrect value for contents[79], expected 86, is " + << last_msg_->contents[79]; + EXPECT_EQ(last_msg_->contents[80], 32) + << "incorrect value for contents[80], expected 32, is " + << last_msg_->contents[80]; + EXPECT_EQ(last_msg_->contents[81], 103) + << "incorrect value for contents[81], expected 103, is " + << last_msg_->contents[81]; + EXPECT_EQ(last_msg_->contents[82], 146) + << "incorrect value for contents[82], expected 146, is " + << last_msg_->contents[82]; + EXPECT_EQ(last_msg_->contents[83], 252) + << "incorrect value for contents[83], expected 252, is " + << last_msg_->contents[83]; + EXPECT_EQ(last_msg_->contents[84], 4) + << "incorrect value for contents[84], expected 4, is " + << last_msg_->contents[84]; + EXPECT_EQ(last_msg_->contents[85], 16) + << "incorrect value for contents[85], expected 16, is " + << last_msg_->contents[85]; + EXPECT_EQ(last_msg_->contents[86], 54) + << "incorrect value for contents[86], expected 54, is " + << last_msg_->contents[86]; + EXPECT_EQ(last_msg_->contents[87], 161) + << "incorrect value for contents[87], expected 161, is " + << last_msg_->contents[87]; + EXPECT_EQ(last_msg_->contents[88], 60) + << "incorrect value for contents[88], expected 60, is " + << last_msg_->contents[88]; + EXPECT_EQ(last_msg_->contents[89], 6) + << "incorrect value for contents[89], expected 6, is " + << last_msg_->contents[89]; + EXPECT_EQ(last_msg_->contents[90], 13) + << "incorrect value for contents[90], expected 13, is " + << last_msg_->contents[90]; + EXPECT_EQ(last_msg_->contents[91], 191) + << "incorrect value for contents[91], expected 191, is " + << last_msg_->contents[91]; + EXPECT_EQ(last_msg_->contents[92], 116) + << "incorrect value for contents[92], expected 116, is " + << last_msg_->contents[92]; + EXPECT_EQ(last_msg_->contents[93], 182) + << "incorrect value for contents[93], expected 182, is " + << last_msg_->contents[93]; + EXPECT_EQ(last_msg_->contents[94], 42) + << "incorrect value for contents[94], expected 42, is " + << last_msg_->contents[94]; + EXPECT_EQ(last_msg_->contents[95], 191) + << "incorrect value for contents[95], expected 191, is " + << last_msg_->contents[95]; + EXPECT_EQ(last_msg_->contents[96], 213) + << "incorrect value for contents[96], expected 213, is " + << last_msg_->contents[96]; + EXPECT_EQ(last_msg_->contents[97], 20) + << "incorrect value for contents[97], expected 20, is " + << last_msg_->contents[97]; + EXPECT_EQ(last_msg_->contents[98], 217) + << "incorrect value for contents[98], expected 217, is " + << last_msg_->contents[98]; + EXPECT_EQ(last_msg_->contents[99], 8) + << "incorrect value for contents[99], expected 8, is " + << last_msg_->contents[99]; + EXPECT_EQ(last_msg_->contents[100], 142) + << "incorrect value for contents[100], expected 142, is " + << last_msg_->contents[100]; + EXPECT_EQ(last_msg_->contents[101], 187) + << "incorrect value for contents[101], expected 187, is " + << last_msg_->contents[101]; + EXPECT_EQ(last_msg_->contents[102], 238) + << "incorrect value for contents[102], expected 238, is " + << last_msg_->contents[102]; + EXPECT_EQ(last_msg_->contents[103], 120) + << "incorrect value for contents[103], expected 120, is " + << last_msg_->contents[103]; + EXPECT_EQ(last_msg_->contents[104], 184) + << "incorrect value for contents[104], expected 184, is " + << last_msg_->contents[104]; + EXPECT_EQ(last_msg_->contents[105], 250) + << "incorrect value for contents[105], expected 250, is " + << last_msg_->contents[105]; + EXPECT_EQ(last_msg_->contents[106], 31) + << "incorrect value for contents[106], expected 31, is " + << last_msg_->contents[106]; + EXPECT_EQ(last_msg_->contents[107], 151) + << "incorrect value for contents[107], expected 151, is " + << last_msg_->contents[107]; + EXPECT_EQ(last_msg_->contents[108], 37) + << "incorrect value for contents[108], expected 37, is " + << last_msg_->contents[108]; + EXPECT_EQ(last_msg_->contents[109], 51) + << "incorrect value for contents[109], expected 51, is " + << last_msg_->contents[109]; + EXPECT_EQ(last_msg_->contents[110], 177) + << "incorrect value for contents[110], expected 177, is " + << last_msg_->contents[110]; + EXPECT_EQ(last_msg_->contents[111], 130) + << "incorrect value for contents[111], expected 130, is " + << last_msg_->contents[111]; + EXPECT_EQ(last_msg_->contents[112], 190) + << "incorrect value for contents[112], expected 190, is " + << last_msg_->contents[112]; + EXPECT_EQ(last_msg_->contents[113], 155) + << "incorrect value for contents[113], expected 155, is " + << last_msg_->contents[113]; + EXPECT_EQ(last_msg_->contents[114], 71) + << "incorrect value for contents[114], expected 71, is " + << last_msg_->contents[114]; + EXPECT_EQ(last_msg_->contents[115], 68) + << "incorrect value for contents[115], expected 68, is " + << last_msg_->contents[115]; + EXPECT_EQ(last_msg_->contents[116], 56) + << "incorrect value for contents[116], expected 56, is " + << last_msg_->contents[116]; + EXPECT_EQ(last_msg_->contents[117], 238) + << "incorrect value for contents[117], expected 238, is " + << last_msg_->contents[117]; + EXPECT_EQ(last_msg_->contents[118], 92) + << "incorrect value for contents[118], expected 92, is " + << last_msg_->contents[118]; + EXPECT_EQ(last_msg_->contents[119], 130) + << "incorrect value for contents[119], expected 130, is " + << last_msg_->contents[119]; + EXPECT_EQ(last_msg_->contents[120], 37) + << "incorrect value for contents[120], expected 37, is " + << last_msg_->contents[120]; + EXPECT_EQ(last_msg_->contents[121], 137) + << "incorrect value for contents[121], expected 137, is " + << last_msg_->contents[121]; + EXPECT_EQ(last_msg_->contents[122], 146) + << "incorrect value for contents[122], expected 146, is " + << last_msg_->contents[122]; + EXPECT_EQ(last_msg_->contents[123], 246) + << "incorrect value for contents[123], expected 246, is " + << last_msg_->contents[123]; + EXPECT_EQ(last_msg_->contents[124], 114) + << "incorrect value for contents[124], expected 114, is " + << last_msg_->contents[124]; + EXPECT_EQ(last_msg_->contents[125], 116) + << "incorrect value for contents[125], expected 116, is " + << last_msg_->contents[125]; + EXPECT_EQ(last_msg_->contents[126], 138) + << "incorrect value for contents[126], expected 138, is " + << last_msg_->contents[126]; + EXPECT_EQ(last_msg_->contents[127], 165) + << "incorrect value for contents[127], expected 165, is " + << last_msg_->contents[127]; + EXPECT_EQ(last_msg_->contents[128], 217) + << "incorrect value for contents[128], expected 217, is " + << last_msg_->contents[128]; + EXPECT_EQ(last_msg_->contents[129], 79) + << "incorrect value for contents[129], expected 79, is " + << last_msg_->contents[129]; + EXPECT_EQ(last_msg_->contents[130], 10) + << "incorrect value for contents[130], expected 10, is " + << last_msg_->contents[130]; + EXPECT_EQ(last_msg_->contents[131], 189) + << "incorrect value for contents[131], expected 189, is " + << last_msg_->contents[131]; + EXPECT_EQ(last_msg_->contents[132], 128) + << "incorrect value for contents[132], expected 128, is " + << last_msg_->contents[132]; + EXPECT_EQ(last_msg_->contents[133], 189) + << "incorrect value for contents[133], expected 189, is " + << last_msg_->contents[133]; + EXPECT_EQ(last_msg_->contents[134], 2) + << "incorrect value for contents[134], expected 2, is " + << last_msg_->contents[134]; + EXPECT_EQ(last_msg_->contents[135], 240) + << "incorrect value for contents[135], expected 240, is " + << last_msg_->contents[135]; + EXPECT_EQ(last_msg_->contents[136], 92) + << "incorrect value for contents[136], expected 92, is " + << last_msg_->contents[136]; + EXPECT_EQ(last_msg_->contents[137], 28) + << "incorrect value for contents[137], expected 28, is " + << last_msg_->contents[137]; + EXPECT_EQ(last_msg_->contents[138], 126) + << "incorrect value for contents[138], expected 126, is " + << last_msg_->contents[138]; + EXPECT_EQ(last_msg_->contents[139], 105) + << "incorrect value for contents[139], expected 105, is " + << last_msg_->contents[139]; + EXPECT_EQ(last_msg_->contents[140], 236) + << "incorrect value for contents[140], expected 236, is " + << last_msg_->contents[140]; + EXPECT_EQ(last_msg_->contents[141], 228) + << "incorrect value for contents[141], expected 228, is " + << last_msg_->contents[141]; + EXPECT_EQ(last_msg_->contents[142], 194) + << "incorrect value for contents[142], expected 194, is " + << last_msg_->contents[142]; + EXPECT_EQ(last_msg_->contents[143], 0) + << "incorrect value for contents[143], expected 0, is " + << last_msg_->contents[143]; + EXPECT_EQ(last_msg_->contents[144], 51) + << "incorrect value for contents[144], expected 51, is " + << last_msg_->contents[144]; + EXPECT_EQ(last_msg_->contents[145], 61) + << "incorrect value for contents[145], expected 61, is " + << last_msg_->contents[145]; + EXPECT_EQ(last_msg_->contents[146], 74) + << "incorrect value for contents[146], expected 74, is " + << last_msg_->contents[146]; + EXPECT_EQ(last_msg_->contents[147], 41) + << "incorrect value for contents[147], expected 41, is " + << last_msg_->contents[147]; + EXPECT_EQ(last_msg_->contents[148], 10) + << "incorrect value for contents[148], expected 10, is " + << last_msg_->contents[148]; + EXPECT_EQ(last_msg_->contents[149], 239) + << "incorrect value for contents[149], expected 239, is " + << last_msg_->contents[149]; + EXPECT_EQ(last_msg_->contents[150], 133) + << "incorrect value for contents[150], expected 133, is " + << last_msg_->contents[150]; + EXPECT_EQ(last_msg_->contents[151], 106) + << "incorrect value for contents[151], expected 106, is " + << last_msg_->contents[151]; + EXPECT_EQ(last_msg_->contents[152], 190) + << "incorrect value for contents[152], expected 190, is " + << last_msg_->contents[152]; + EXPECT_EQ(last_msg_->contents[153], 30) + << "incorrect value for contents[153], expected 30, is " + << last_msg_->contents[153]; + EXPECT_EQ(last_msg_->contents[154], 27) + << "incorrect value for contents[154], expected 27, is " + << last_msg_->contents[154]; + EXPECT_EQ(last_msg_->contents[155], 3) + << "incorrect value for contents[155], expected 3, is " + << last_msg_->contents[155]; + EXPECT_EQ(last_msg_->contents[156], 240) + << "incorrect value for contents[156], expected 240, is " + << last_msg_->contents[156]; + EXPECT_EQ(last_msg_->contents[157], 205) + << "incorrect value for contents[157], expected 205, is " + << last_msg_->contents[157]; + EXPECT_EQ(last_msg_->contents[158], 253) + << "incorrect value for contents[158], expected 253, is " + << last_msg_->contents[158]; + EXPECT_EQ(last_msg_->contents[159], 113) + << "incorrect value for contents[159], expected 113, is " + << last_msg_->contents[159]; + EXPECT_EQ(last_msg_->contents[160], 25) + << "incorrect value for contents[160], expected 25, is " + << last_msg_->contents[160]; + EXPECT_EQ(last_msg_->contents[161], 28) + << "incorrect value for contents[161], expected 28, is " + << last_msg_->contents[161]; + EXPECT_EQ(last_msg_->contents[162], 187) + << "incorrect value for contents[162], expected 187, is " + << last_msg_->contents[162]; + EXPECT_EQ(last_msg_->contents[163], 81) + << "incorrect value for contents[163], expected 81, is " + << last_msg_->contents[163]; + EXPECT_EQ(last_msg_->contents[164], 101) + << "incorrect value for contents[164], expected 101, is " + << last_msg_->contents[164]; + EXPECT_EQ(last_msg_->contents[165], 216) + << "incorrect value for contents[165], expected 216, is " + << last_msg_->contents[165]; + EXPECT_EQ(last_msg_->contents[166], 121) + << "incorrect value for contents[166], expected 121, is " + << last_msg_->contents[166]; + EXPECT_EQ(last_msg_->contents[167], 41) + << "incorrect value for contents[167], expected 41, is " + << last_msg_->contents[167]; + EXPECT_EQ(last_msg_->contents[168], 179) + << "incorrect value for contents[168], expected 179, is " + << last_msg_->contents[168]; + EXPECT_EQ(last_msg_->contents[169], 120) + << "incorrect value for contents[169], expected 120, is " + << last_msg_->contents[169]; + EXPECT_EQ(last_msg_->contents[170], 152) + << "incorrect value for contents[170], expected 152, is " + << last_msg_->contents[170]; + EXPECT_EQ(last_msg_->contents[171], 18) + << "incorrect value for contents[171], expected 18, is " + << last_msg_->contents[171]; + EXPECT_EQ(last_msg_->contents[172], 116) + << "incorrect value for contents[172], expected 116, is " + << last_msg_->contents[172]; + EXPECT_EQ(last_msg_->contents[173], 53) + << "incorrect value for contents[173], expected 53, is " + << last_msg_->contents[173]; + EXPECT_EQ(last_msg_->contents[174], 212) + << "incorrect value for contents[174], expected 212, is " + << last_msg_->contents[174]; + EXPECT_EQ(last_msg_->contents[175], 100) + << "incorrect value for contents[175], expected 100, is " + << last_msg_->contents[175]; + EXPECT_EQ(last_msg_->contents[176], 2) + << "incorrect value for contents[176], expected 2, is " + << last_msg_->contents[176]; + EXPECT_EQ(last_msg_->contents[177], 114) + << "incorrect value for contents[177], expected 114, is " + << last_msg_->contents[177]; + EXPECT_EQ(last_msg_->contents[178], 198) + << "incorrect value for contents[178], expected 198, is " + << last_msg_->contents[178]; + EXPECT_EQ(last_msg_->contents[179], 200) + << "incorrect value for contents[179], expected 200, is " + << last_msg_->contents[179]; + EXPECT_EQ(last_msg_->contents[180], 10) + << "incorrect value for contents[180], expected 10, is " + << last_msg_->contents[180]; + EXPECT_EQ(last_msg_->contents[181], 147) + << "incorrect value for contents[181], expected 147, is " + << last_msg_->contents[181]; + EXPECT_EQ(last_msg_->contents[182], 25) + << "incorrect value for contents[182], expected 25, is " + << last_msg_->contents[182]; + EXPECT_EQ(last_msg_->contents[183], 33) + << "incorrect value for contents[183], expected 33, is " + << last_msg_->contents[183]; + EXPECT_EQ(last_msg_->contents[184], 115) + << "incorrect value for contents[184], expected 115, is " + << last_msg_->contents[184]; + EXPECT_EQ(last_msg_->contents[185], 208) + << "incorrect value for contents[185], expected 208, is " + << last_msg_->contents[185]; + EXPECT_EQ(last_msg_->contents[186], 113) + << "incorrect value for contents[186], expected 113, is " + << last_msg_->contents[186]; + EXPECT_EQ(last_msg_->contents[187], 60) + << "incorrect value for contents[187], expected 60, is " + << last_msg_->contents[187]; + EXPECT_EQ(last_msg_->contents[188], 179) + << "incorrect value for contents[188], expected 179, is " + << last_msg_->contents[188]; + EXPECT_EQ(last_msg_->contents[189], 183) + << "incorrect value for contents[189], expected 183, is " + << last_msg_->contents[189]; + EXPECT_EQ(last_msg_->contents[190], 0) + << "incorrect value for contents[190], expected 0, is " + << last_msg_->contents[190]; + EXPECT_EQ(last_msg_->contents[191], 41) + << "incorrect value for contents[191], expected 41, is " + << last_msg_->contents[191]; + EXPECT_EQ(last_msg_->contents[192], 217) + << "incorrect value for contents[192], expected 217, is " + << last_msg_->contents[192]; + EXPECT_EQ(last_msg_->contents[193], 206) + << "incorrect value for contents[193], expected 206, is " + << last_msg_->contents[193]; + EXPECT_EQ(last_msg_->contents[194], 255) + << "incorrect value for contents[194], expected 255, is " + << last_msg_->contents[194]; + EXPECT_EQ(last_msg_->contents[195], 211) + << "incorrect value for contents[195], expected 211, is " + << last_msg_->contents[195]; + EXPECT_EQ(last_msg_->contents[196], 225) + << "incorrect value for contents[196], expected 225, is " + << last_msg_->contents[196]; + EXPECT_EQ(last_msg_->contents[197], 142) + << "incorrect value for contents[197], expected 142, is " + << last_msg_->contents[197]; + EXPECT_EQ(last_msg_->contents[198], 191) + << "incorrect value for contents[198], expected 191, is " + << last_msg_->contents[198]; + EXPECT_EQ(last_msg_->contents[199], 133) + << "incorrect value for contents[199], expected 133, is " + << last_msg_->contents[199]; + EXPECT_EQ(last_msg_->contents[200], 81) + << "incorrect value for contents[200], expected 81, is " + << last_msg_->contents[200]; + EXPECT_EQ(last_msg_->contents[201], 15) + << "incorrect value for contents[201], expected 15, is " + << last_msg_->contents[201]; + EXPECT_EQ(last_msg_->contents[202], 248) + << "incorrect value for contents[202], expected 248, is " + << last_msg_->contents[202]; + EXPECT_EQ(last_msg_->contents[203], 193) + << "incorrect value for contents[203], expected 193, is " + << last_msg_->contents[203]; + EXPECT_EQ(last_msg_->contents[204], 66) + << "incorrect value for contents[204], expected 66, is " + << last_msg_->contents[204]; + EXPECT_EQ(last_msg_->contents[205], 191) + << "incorrect value for contents[205], expected 191, is " + << last_msg_->contents[205]; + EXPECT_EQ(last_msg_->contents[206], 244) + << "incorrect value for contents[206], expected 244, is " + << last_msg_->contents[206]; + EXPECT_EQ(last_msg_->contents[207], 221) + << "incorrect value for contents[207], expected 221, is " + << last_msg_->contents[207]; + EXPECT_EQ(last_msg_->contents[208], 248) + << "incorrect value for contents[208], expected 248, is " + << last_msg_->contents[208]; + EXPECT_EQ(last_msg_->contents[209], 199) + << "incorrect value for contents[209], expected 199, is " + << last_msg_->contents[209]; + EXPECT_EQ(last_msg_->contents[210], 241) + << "incorrect value for contents[210], expected 241, is " + << last_msg_->contents[210]; + EXPECT_EQ(last_msg_->contents[211], 112) + << "incorrect value for contents[211], expected 112, is " + << last_msg_->contents[211]; + EXPECT_EQ(last_msg_->contents[212], 51) + << "incorrect value for contents[212], expected 51, is " + << last_msg_->contents[212]; + EXPECT_EQ(last_msg_->contents[213], 1) + << "incorrect value for contents[213], expected 1, is " + << last_msg_->contents[213]; + EXPECT_EQ(last_msg_->contents[214], 180) + << "incorrect value for contents[214], expected 180, is " + << last_msg_->contents[214]; + EXPECT_EQ(last_msg_->contents[215], 180) + << "incorrect value for contents[215], expected 180, is " + << last_msg_->contents[215]; + EXPECT_EQ(last_msg_->contents[216], 125) + << "incorrect value for contents[216], expected 125, is " + << last_msg_->contents[216]; + EXPECT_EQ(last_msg_->contents[217], 97) + << "incorrect value for contents[217], expected 97, is " + << last_msg_->contents[217]; + EXPECT_EQ(last_msg_->contents[218], 145) + << "incorrect value for contents[218], expected 145, is " + << last_msg_->contents[218]; + EXPECT_EQ(last_msg_->contents[219], 25) + << "incorrect value for contents[219], expected 25, is " + << last_msg_->contents[219]; + EXPECT_EQ(last_msg_->contents[220], 72) + << "incorrect value for contents[220], expected 72, is " + << last_msg_->contents[220]; + EXPECT_EQ(last_msg_->contents[221], 210) + << "incorrect value for contents[221], expected 210, is " + << last_msg_->contents[221]; + EXPECT_EQ(last_msg_->contents[222], 215) + << "incorrect value for contents[222], expected 215, is " + << last_msg_->contents[222]; + EXPECT_EQ(last_msg_->contents[223], 208) + << "incorrect value for contents[223], expected 208, is " + << last_msg_->contents[223]; + EXPECT_EQ(last_msg_->contents[224], 15) + << "incorrect value for contents[224], expected 15, is " + << last_msg_->contents[224]; + EXPECT_EQ(last_msg_->contents[225], 126) + << "incorrect value for contents[225], expected 126, is " + << last_msg_->contents[225]; + EXPECT_EQ(last_msg_->contents[226], 56) + << "incorrect value for contents[226], expected 56, is " + << last_msg_->contents[226]; + EXPECT_EQ(last_msg_->contents[227], 38) + << "incorrect value for contents[227], expected 38, is " + << last_msg_->contents[227]; + EXPECT_EQ(last_msg_->contents[228], 65) + << "incorrect value for contents[228], expected 65, is " + << last_msg_->contents[228]; + EXPECT_EQ(last_msg_->contents[229], 4) + << "incorrect value for contents[229], expected 4, is " + << last_msg_->contents[229]; + EXPECT_EQ(last_msg_->contents[230], 64) + << "incorrect value for contents[230], expected 64, is " + << last_msg_->contents[230]; + EXPECT_EQ(last_msg_->contents[231], 19) + << "incorrect value for contents[231], expected 19, is " + << last_msg_->contents[231]; + EXPECT_EQ(last_msg_->contents[232], 74) + << "incorrect value for contents[232], expected 74, is " + << last_msg_->contents[232]; + EXPECT_EQ(last_msg_->contents[233], 223) + << "incorrect value for contents[233], expected 223, is " + << last_msg_->contents[233]; + EXPECT_EQ(last_msg_->contents[234], 111) + << "incorrect value for contents[234], expected 111, is " + << last_msg_->contents[234]; + EXPECT_EQ(last_msg_->contents[235], 109) + << "incorrect value for contents[235], expected 109, is " + << last_msg_->contents[235]; + EXPECT_EQ(last_msg_->contents[236], 52) + << "incorrect value for contents[236], expected 52, is " + << last_msg_->contents[236]; + EXPECT_EQ(last_msg_->contents[237], 43) + << "incorrect value for contents[237], expected 43, is " + << last_msg_->contents[237]; + EXPECT_EQ(last_msg_->contents[238], 167) + << "incorrect value for contents[238], expected 167, is " + << last_msg_->contents[238]; + EXPECT_EQ(last_msg_->contents[239], 186) + << "incorrect value for contents[239], expected 186, is " + << last_msg_->contents[239]; + EXPECT_EQ(last_msg_->contents[240], 202) + << "incorrect value for contents[240], expected 202, is " + << last_msg_->contents[240]; + EXPECT_EQ(last_msg_->contents[241], 111) + << "incorrect value for contents[241], expected 111, is " + << last_msg_->contents[241]; + EXPECT_EQ(last_msg_->contents[242], 11) + << "incorrect value for contents[242], expected 11, is " + << last_msg_->contents[242]; + EXPECT_EQ(last_msg_->contents[243], 91) + << "incorrect value for contents[243], expected 91, is " + << last_msg_->contents[243]; + EXPECT_EQ(last_msg_->contents[244], 21) + << "incorrect value for contents[244], expected 21, is " + << last_msg_->contents[244]; + EXPECT_EQ(last_msg_->contents[245], 236) + << "incorrect value for contents[245], expected 236, is " + << last_msg_->contents[245]; + EXPECT_EQ(last_msg_->contents[246], 234) + << "incorrect value for contents[246], expected 234, is " + << last_msg_->contents[246]; + EXPECT_EQ(last_msg_->contents[247], 196) + << "incorrect value for contents[247], expected 196, is " + << last_msg_->contents[247]; + EXPECT_EQ(last_msg_->contents[248], 36) + << "incorrect value for contents[248], expected 36, is " + << last_msg_->contents[248]; + EXPECT_EQ(last_msg_->contents[249], 171) + << "incorrect value for contents[249], expected 171, is " + << last_msg_->contents[249]; + EXPECT_EQ(last_msg_->contents[250], 147) + << "incorrect value for contents[250], expected 147, is " + << last_msg_->contents[250]; + EXPECT_EQ(last_msg_->sequence, 259241795) + << "incorrect value for sequence, expected 259241795, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc new file mode 100644 index 0000000000..2d7a2cd32e --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_file_io_MsgFileioRemove.cc @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_file_io_MsgFileioRemove0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_file_io_MsgFileioRemove0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_fileio_remove_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_fileio_remove_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_file_io_MsgFileioRemove0, Test) { + uint8_t encoded_frame[] = { + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 102, 105, 108, 101, 0, 46, 243, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_fileio_remove_t *test_msg = (msg_fileio_remove_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)102, (char)105, (char)108, + (char)101, (char)0}; + memcpy(test_msg->filename, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->filename) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xac, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = {(char)47, (char)112, (char)97, (char)116, + (char)104, (char)47, (char)116, (char)111, + (char)47, (char)102, (char)105, (char)108, + (char)101, (char)0}; + EXPECT_EQ(memcmp(last_msg_->filename, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->filename, expected string '" + << check_string << "', is '" << last_msg_->filename << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashDone.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashDone.cc new file mode 100644 index 0000000000..6b2f9e03e4 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashDone.cc @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgFlashDone0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgFlashDone0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_flash_done_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_flash_done_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgFlashDone0, Test) { + uint8_t encoded_frame[] = { + 85, 224, 0, 195, 4, 1, 82, 6, 54, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_flash_done_t *test_msg = (msg_flash_done_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->response = 82; + + EXPECT_EQ(send_message(0xe0, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->response, 82) + << "incorrect value for response, expected 82, is " + << last_msg_->response; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashErase.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashErase.cc new file mode 100644 index 0000000000..c74a254f22 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashErase.cc @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgFlashErase0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgFlashErase0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_flash_erase_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_flash_erase_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgFlashErase0, Test) { + uint8_t encoded_frame[] = { + 85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_flash_erase_t *test_msg = (msg_flash_erase_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->sector_num = 2222371310; + test_msg->target = 74; + + EXPECT_EQ(send_message(0xe2, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->sector_num, 2222371310) + << "incorrect value for sector_num, expected 2222371310, is " + << last_msg_->sector_num; + EXPECT_EQ(last_msg_->target, 74) + << "incorrect value for target, expected 74, is " << last_msg_->target; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashProgram.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashProgram.cc new file mode 100644 index 0000000000..f57574e5b5 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashProgram.cc @@ -0,0 +1,2134 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgFlashProgram0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgFlashProgram0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_flash_program_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_flash_program_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgFlashProgram0, Test) { + uint8_t encoded_frame[] = { + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, 106, + 144, 29, 141, 255, 3, 16, 192, 237, 172, 254, 213, 4, 220, 98, 34, + 222, 230, 214, 6, 217, 172, 122, 46, 13, 38, 240, 236, 60, 121, 47, + 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, 21, 214, 57, 245, + 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, 98, 39, 70, 232, 133, + 25, 10, 134, 129, 69, 228, 134, 9, 88, 183, 133, 171, 255, 166, 100, + 152, 231, 92, 9, 196, 106, 246, 29, 145, 156, 151, 32, 67, 188, 63, + 233, 142, 174, 139, 154, 127, 35, 60, 56, 187, 121, 103, 135, 152, 182, + 88, 160, 255, 227, 240, 54, 100, 91, 31, 141, 102, 130, 254, 54, 227, + 229, 62, 53, 225, 143, 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, + 57, 87, 130, 178, 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, + 235, 213, 186, 159, 221, 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, + 13, 50, 71, 73, 193, 201, 250, 172, 193, 13, 20, 238, 130, 243, 68, + 4, 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, 92, 160, + 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, 239, + 168, 32, 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, 217, 151, + 251, 83, 20, 113, 37, 151, 34, 37, 71, 95, 105, 235, 144, 164, 83, + 197, 254, 183, 223, 91, 19, 45, 227, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_flash_program_t *test_msg = (msg_flash_program_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->addr_len = 250; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[0] = 87; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[1] = 52; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[2] = 244; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[0] = 176; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[1] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[2] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[3] = 106; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[4] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[5] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[6] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[7] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[8] = 3; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[9] = 16; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[10] = 192; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[11] = 237; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[12] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[13] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[14] = 213; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[15] = 4; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[16] = 220; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[17] = 98; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[18] = 34; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[19] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[20] = 230; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[21] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[22] = 6; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[23] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[24] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[25] = 122; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[26] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[27] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[28] = 38; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[29] = 240; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[30] = 236; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[31] = 60; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[32] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[33] = 47; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[34] = 252; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[35] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[36] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[37] = 222; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[38] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[39] = 168; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[40] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[41] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[42] = 55; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[43] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[44] = 233; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[45] = 21; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[46] = 214; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[47] = 57; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[48] = 245; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[49] = 246; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[50] = 19; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[51] = 3; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[52] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[53] = 49; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[54] = 231; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[55] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[56] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[57] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[58] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[59] = 98; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[60] = 39; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[61] = 70; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[62] = 232; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[63] = 133; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[64] = 25; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[65] = 10; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[66] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[67] = 129; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[68] = 69; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[69] = 228; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[70] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[71] = 9; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[72] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[73] = 183; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[74] = 133; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[75] = 171; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[76] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[77] = 166; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[78] = 100; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[79] = 152; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[80] = 231; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[81] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[82] = 9; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[83] = 196; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[84] = 106; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[85] = 246; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[86] = 29; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[87] = 145; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[88] = 156; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[89] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[90] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[91] = 67; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[92] = 188; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[93] = 63; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[94] = 233; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[95] = 142; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[96] = 174; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[97] = 139; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[98] = 154; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[99] = 127; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[100] = 35; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[101] = 60; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[102] = 56; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[103] = 187; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[104] = 121; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[105] = 103; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[106] = 135; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[107] = 152; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[108] = 182; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[109] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[110] = 160; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[111] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[112] = 227; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[113] = 240; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[114] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[115] = 100; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[116] = 91; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[117] = 31; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[118] = 141; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[119] = 102; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[120] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[121] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[122] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[123] = 227; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[124] = 229; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[125] = 62; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[126] = 53; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[127] = 225; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[128] = 143; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[129] = 88; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[130] = 139; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[131] = 126; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[132] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[133] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[134] = 35; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[135] = 54; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[136] = 134; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[137] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[138] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[139] = 57; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[140] = 87; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[141] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[142] = 178; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[143] = 22; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[144] = 158; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[145] = 18; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[146] = 237; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[147] = 209; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[148] = 187; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[149] = 226; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[150] = 1; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[151] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[152] = 64; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[153] = 226; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[154] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[155] = 213; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[156] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[157] = 159; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[158] = 221; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[159] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[160] = 25; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[161] = 115; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[162] = 84; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[163] = 131; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[164] = 167; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[165] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[166] = 104; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[167] = 1; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[168] = 200; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[169] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[170] = 50; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[171] = 71; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[172] = 73; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[173] = 193; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[174] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[175] = 250; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[176] = 172; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[177] = 193; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[178] = 13; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[179] = 20; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[180] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[181] = 130; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[182] = 243; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[183] = 68; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[184] = 4; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[185] = 72; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[186] = 46; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[187] = 194; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[188] = 113; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[189] = 255; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[190] = 238; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[191] = 15; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[192] = 230; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[193] = 64; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[194] = 178; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[195] = 127; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[196] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[197] = 92; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[198] = 160; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[199] = 201; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[200] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[201] = 163; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[202] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[203] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[204] = 28; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[205] = 174; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[206] = 65; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[207] = 73; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[208] = 45; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[209] = 123; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[210] = 118; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[211] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[212] = 107; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[213] = 239; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[214] = 168; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[215] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[216] = 212; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[217] = 191; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[218] = 81; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[219] = 93; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[220] = 186; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[221] = 223; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[222] = 32; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[223] = 19; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[224] = 58; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[225] = 137; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[226] = 72; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[227] = 217; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[228] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[229] = 251; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[230] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[231] = 20; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[232] = 113; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[233] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[234] = 151; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[235] = 34; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[236] = 37; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[237] = 71; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[238] = 95; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[239] = 105; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[240] = 235; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[241] = 144; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[242] = 164; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[243] = 83; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[244] = 197; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[245] = 254; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[246] = 183; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[247] = 223; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[248] = 91; + if (sizeof(test_msg->data) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->data[0])); + } + test_msg->data[249] = 19; + test_msg->target = 212; + + EXPECT_EQ(send_message(0xe6, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->addr_len, 250) + << "incorrect value for addr_len, expected 250, is " + << last_msg_->addr_len; + EXPECT_EQ(last_msg_->addr_start[0], 87) + << "incorrect value for addr_start[0], expected 87, is " + << last_msg_->addr_start[0]; + EXPECT_EQ(last_msg_->addr_start[1], 52) + << "incorrect value for addr_start[1], expected 52, is " + << last_msg_->addr_start[1]; + EXPECT_EQ(last_msg_->addr_start[2], 244) + << "incorrect value for addr_start[2], expected 244, is " + << last_msg_->addr_start[2]; + EXPECT_EQ(last_msg_->data[0], 176) + << "incorrect value for data[0], expected 176, is " << last_msg_->data[0]; + EXPECT_EQ(last_msg_->data[1], 222) + << "incorrect value for data[1], expected 222, is " << last_msg_->data[1]; + EXPECT_EQ(last_msg_->data[2], 235) + << "incorrect value for data[2], expected 235, is " << last_msg_->data[2]; + EXPECT_EQ(last_msg_->data[3], 106) + << "incorrect value for data[3], expected 106, is " << last_msg_->data[3]; + EXPECT_EQ(last_msg_->data[4], 144) + << "incorrect value for data[4], expected 144, is " << last_msg_->data[4]; + EXPECT_EQ(last_msg_->data[5], 29) + << "incorrect value for data[5], expected 29, is " << last_msg_->data[5]; + EXPECT_EQ(last_msg_->data[6], 141) + << "incorrect value for data[6], expected 141, is " << last_msg_->data[6]; + EXPECT_EQ(last_msg_->data[7], 255) + << "incorrect value for data[7], expected 255, is " << last_msg_->data[7]; + EXPECT_EQ(last_msg_->data[8], 3) + << "incorrect value for data[8], expected 3, is " << last_msg_->data[8]; + EXPECT_EQ(last_msg_->data[9], 16) + << "incorrect value for data[9], expected 16, is " << last_msg_->data[9]; + EXPECT_EQ(last_msg_->data[10], 192) + << "incorrect value for data[10], expected 192, is " + << last_msg_->data[10]; + EXPECT_EQ(last_msg_->data[11], 237) + << "incorrect value for data[11], expected 237, is " + << last_msg_->data[11]; + EXPECT_EQ(last_msg_->data[12], 172) + << "incorrect value for data[12], expected 172, is " + << last_msg_->data[12]; + EXPECT_EQ(last_msg_->data[13], 254) + << "incorrect value for data[13], expected 254, is " + << last_msg_->data[13]; + EXPECT_EQ(last_msg_->data[14], 213) + << "incorrect value for data[14], expected 213, is " + << last_msg_->data[14]; + EXPECT_EQ(last_msg_->data[15], 4) + << "incorrect value for data[15], expected 4, is " << last_msg_->data[15]; + EXPECT_EQ(last_msg_->data[16], 220) + << "incorrect value for data[16], expected 220, is " + << last_msg_->data[16]; + EXPECT_EQ(last_msg_->data[17], 98) + << "incorrect value for data[17], expected 98, is " + << last_msg_->data[17]; + EXPECT_EQ(last_msg_->data[18], 34) + << "incorrect value for data[18], expected 34, is " + << last_msg_->data[18]; + EXPECT_EQ(last_msg_->data[19], 222) + << "incorrect value for data[19], expected 222, is " + << last_msg_->data[19]; + EXPECT_EQ(last_msg_->data[20], 230) + << "incorrect value for data[20], expected 230, is " + << last_msg_->data[20]; + EXPECT_EQ(last_msg_->data[21], 214) + << "incorrect value for data[21], expected 214, is " + << last_msg_->data[21]; + EXPECT_EQ(last_msg_->data[22], 6) + << "incorrect value for data[22], expected 6, is " << last_msg_->data[22]; + EXPECT_EQ(last_msg_->data[23], 217) + << "incorrect value for data[23], expected 217, is " + << last_msg_->data[23]; + EXPECT_EQ(last_msg_->data[24], 172) + << "incorrect value for data[24], expected 172, is " + << last_msg_->data[24]; + EXPECT_EQ(last_msg_->data[25], 122) + << "incorrect value for data[25], expected 122, is " + << last_msg_->data[25]; + EXPECT_EQ(last_msg_->data[26], 46) + << "incorrect value for data[26], expected 46, is " + << last_msg_->data[26]; + EXPECT_EQ(last_msg_->data[27], 13) + << "incorrect value for data[27], expected 13, is " + << last_msg_->data[27]; + EXPECT_EQ(last_msg_->data[28], 38) + << "incorrect value for data[28], expected 38, is " + << last_msg_->data[28]; + EXPECT_EQ(last_msg_->data[29], 240) + << "incorrect value for data[29], expected 240, is " + << last_msg_->data[29]; + EXPECT_EQ(last_msg_->data[30], 236) + << "incorrect value for data[30], expected 236, is " + << last_msg_->data[30]; + EXPECT_EQ(last_msg_->data[31], 60) + << "incorrect value for data[31], expected 60, is " + << last_msg_->data[31]; + EXPECT_EQ(last_msg_->data[32], 121) + << "incorrect value for data[32], expected 121, is " + << last_msg_->data[32]; + EXPECT_EQ(last_msg_->data[33], 47) + << "incorrect value for data[33], expected 47, is " + << last_msg_->data[33]; + EXPECT_EQ(last_msg_->data[34], 252) + << "incorrect value for data[34], expected 252, is " + << last_msg_->data[34]; + EXPECT_EQ(last_msg_->data[35], 163) + << "incorrect value for data[35], expected 163, is " + << last_msg_->data[35]; + EXPECT_EQ(last_msg_->data[36], 141) + << "incorrect value for data[36], expected 141, is " + << last_msg_->data[36]; + EXPECT_EQ(last_msg_->data[37], 222) + << "incorrect value for data[37], expected 222, is " + << last_msg_->data[37]; + EXPECT_EQ(last_msg_->data[38], 29) + << "incorrect value for data[38], expected 29, is " + << last_msg_->data[38]; + EXPECT_EQ(last_msg_->data[39], 168) + << "incorrect value for data[39], expected 168, is " + << last_msg_->data[39]; + EXPECT_EQ(last_msg_->data[40], 214) + << "incorrect value for data[40], expected 214, is " + << last_msg_->data[40]; + EXPECT_EQ(last_msg_->data[41], 118) + << "incorrect value for data[41], expected 118, is " + << last_msg_->data[41]; + EXPECT_EQ(last_msg_->data[42], 55) + << "incorrect value for data[42], expected 55, is " + << last_msg_->data[42]; + EXPECT_EQ(last_msg_->data[43], 201) + << "incorrect value for data[43], expected 201, is " + << last_msg_->data[43]; + EXPECT_EQ(last_msg_->data[44], 233) + << "incorrect value for data[44], expected 233, is " + << last_msg_->data[44]; + EXPECT_EQ(last_msg_->data[45], 21) + << "incorrect value for data[45], expected 21, is " + << last_msg_->data[45]; + EXPECT_EQ(last_msg_->data[46], 214) + << "incorrect value for data[46], expected 214, is " + << last_msg_->data[46]; + EXPECT_EQ(last_msg_->data[47], 57) + << "incorrect value for data[47], expected 57, is " + << last_msg_->data[47]; + EXPECT_EQ(last_msg_->data[48], 245) + << "incorrect value for data[48], expected 245, is " + << last_msg_->data[48]; + EXPECT_EQ(last_msg_->data[49], 246) + << "incorrect value for data[49], expected 246, is " + << last_msg_->data[49]; + EXPECT_EQ(last_msg_->data[50], 19) + << "incorrect value for data[50], expected 19, is " + << last_msg_->data[50]; + EXPECT_EQ(last_msg_->data[51], 3) + << "incorrect value for data[51], expected 3, is " << last_msg_->data[51]; + EXPECT_EQ(last_msg_->data[52], 121) + << "incorrect value for data[52], expected 121, is " + << last_msg_->data[52]; + EXPECT_EQ(last_msg_->data[53], 49) + << "incorrect value for data[53], expected 49, is " + << last_msg_->data[53]; + EXPECT_EQ(last_msg_->data[54], 231) + << "incorrect value for data[54], expected 231, is " + << last_msg_->data[54]; + EXPECT_EQ(last_msg_->data[55], 37) + << "incorrect value for data[55], expected 37, is " + << last_msg_->data[55]; + EXPECT_EQ(last_msg_->data[56], 186) + << "incorrect value for data[56], expected 186, is " + << last_msg_->data[56]; + EXPECT_EQ(last_msg_->data[57], 58) + << "incorrect value for data[57], expected 58, is " + << last_msg_->data[57]; + EXPECT_EQ(last_msg_->data[58], 238) + << "incorrect value for data[58], expected 238, is " + << last_msg_->data[58]; + EXPECT_EQ(last_msg_->data[59], 98) + << "incorrect value for data[59], expected 98, is " + << last_msg_->data[59]; + EXPECT_EQ(last_msg_->data[60], 39) + << "incorrect value for data[60], expected 39, is " + << last_msg_->data[60]; + EXPECT_EQ(last_msg_->data[61], 70) + << "incorrect value for data[61], expected 70, is " + << last_msg_->data[61]; + EXPECT_EQ(last_msg_->data[62], 232) + << "incorrect value for data[62], expected 232, is " + << last_msg_->data[62]; + EXPECT_EQ(last_msg_->data[63], 133) + << "incorrect value for data[63], expected 133, is " + << last_msg_->data[63]; + EXPECT_EQ(last_msg_->data[64], 25) + << "incorrect value for data[64], expected 25, is " + << last_msg_->data[64]; + EXPECT_EQ(last_msg_->data[65], 10) + << "incorrect value for data[65], expected 10, is " + << last_msg_->data[65]; + EXPECT_EQ(last_msg_->data[66], 134) + << "incorrect value for data[66], expected 134, is " + << last_msg_->data[66]; + EXPECT_EQ(last_msg_->data[67], 129) + << "incorrect value for data[67], expected 129, is " + << last_msg_->data[67]; + EXPECT_EQ(last_msg_->data[68], 69) + << "incorrect value for data[68], expected 69, is " + << last_msg_->data[68]; + EXPECT_EQ(last_msg_->data[69], 228) + << "incorrect value for data[69], expected 228, is " + << last_msg_->data[69]; + EXPECT_EQ(last_msg_->data[70], 134) + << "incorrect value for data[70], expected 134, is " + << last_msg_->data[70]; + EXPECT_EQ(last_msg_->data[71], 9) + << "incorrect value for data[71], expected 9, is " << last_msg_->data[71]; + EXPECT_EQ(last_msg_->data[72], 88) + << "incorrect value for data[72], expected 88, is " + << last_msg_->data[72]; + EXPECT_EQ(last_msg_->data[73], 183) + << "incorrect value for data[73], expected 183, is " + << last_msg_->data[73]; + EXPECT_EQ(last_msg_->data[74], 133) + << "incorrect value for data[74], expected 133, is " + << last_msg_->data[74]; + EXPECT_EQ(last_msg_->data[75], 171) + << "incorrect value for data[75], expected 171, is " + << last_msg_->data[75]; + EXPECT_EQ(last_msg_->data[76], 255) + << "incorrect value for data[76], expected 255, is " + << last_msg_->data[76]; + EXPECT_EQ(last_msg_->data[77], 166) + << "incorrect value for data[77], expected 166, is " + << last_msg_->data[77]; + EXPECT_EQ(last_msg_->data[78], 100) + << "incorrect value for data[78], expected 100, is " + << last_msg_->data[78]; + EXPECT_EQ(last_msg_->data[79], 152) + << "incorrect value for data[79], expected 152, is " + << last_msg_->data[79]; + EXPECT_EQ(last_msg_->data[80], 231) + << "incorrect value for data[80], expected 231, is " + << last_msg_->data[80]; + EXPECT_EQ(last_msg_->data[81], 92) + << "incorrect value for data[81], expected 92, is " + << last_msg_->data[81]; + EXPECT_EQ(last_msg_->data[82], 9) + << "incorrect value for data[82], expected 9, is " << last_msg_->data[82]; + EXPECT_EQ(last_msg_->data[83], 196) + << "incorrect value for data[83], expected 196, is " + << last_msg_->data[83]; + EXPECT_EQ(last_msg_->data[84], 106) + << "incorrect value for data[84], expected 106, is " + << last_msg_->data[84]; + EXPECT_EQ(last_msg_->data[85], 246) + << "incorrect value for data[85], expected 246, is " + << last_msg_->data[85]; + EXPECT_EQ(last_msg_->data[86], 29) + << "incorrect value for data[86], expected 29, is " + << last_msg_->data[86]; + EXPECT_EQ(last_msg_->data[87], 145) + << "incorrect value for data[87], expected 145, is " + << last_msg_->data[87]; + EXPECT_EQ(last_msg_->data[88], 156) + << "incorrect value for data[88], expected 156, is " + << last_msg_->data[88]; + EXPECT_EQ(last_msg_->data[89], 151) + << "incorrect value for data[89], expected 151, is " + << last_msg_->data[89]; + EXPECT_EQ(last_msg_->data[90], 32) + << "incorrect value for data[90], expected 32, is " + << last_msg_->data[90]; + EXPECT_EQ(last_msg_->data[91], 67) + << "incorrect value for data[91], expected 67, is " + << last_msg_->data[91]; + EXPECT_EQ(last_msg_->data[92], 188) + << "incorrect value for data[92], expected 188, is " + << last_msg_->data[92]; + EXPECT_EQ(last_msg_->data[93], 63) + << "incorrect value for data[93], expected 63, is " + << last_msg_->data[93]; + EXPECT_EQ(last_msg_->data[94], 233) + << "incorrect value for data[94], expected 233, is " + << last_msg_->data[94]; + EXPECT_EQ(last_msg_->data[95], 142) + << "incorrect value for data[95], expected 142, is " + << last_msg_->data[95]; + EXPECT_EQ(last_msg_->data[96], 174) + << "incorrect value for data[96], expected 174, is " + << last_msg_->data[96]; + EXPECT_EQ(last_msg_->data[97], 139) + << "incorrect value for data[97], expected 139, is " + << last_msg_->data[97]; + EXPECT_EQ(last_msg_->data[98], 154) + << "incorrect value for data[98], expected 154, is " + << last_msg_->data[98]; + EXPECT_EQ(last_msg_->data[99], 127) + << "incorrect value for data[99], expected 127, is " + << last_msg_->data[99]; + EXPECT_EQ(last_msg_->data[100], 35) + << "incorrect value for data[100], expected 35, is " + << last_msg_->data[100]; + EXPECT_EQ(last_msg_->data[101], 60) + << "incorrect value for data[101], expected 60, is " + << last_msg_->data[101]; + EXPECT_EQ(last_msg_->data[102], 56) + << "incorrect value for data[102], expected 56, is " + << last_msg_->data[102]; + EXPECT_EQ(last_msg_->data[103], 187) + << "incorrect value for data[103], expected 187, is " + << last_msg_->data[103]; + EXPECT_EQ(last_msg_->data[104], 121) + << "incorrect value for data[104], expected 121, is " + << last_msg_->data[104]; + EXPECT_EQ(last_msg_->data[105], 103) + << "incorrect value for data[105], expected 103, is " + << last_msg_->data[105]; + EXPECT_EQ(last_msg_->data[106], 135) + << "incorrect value for data[106], expected 135, is " + << last_msg_->data[106]; + EXPECT_EQ(last_msg_->data[107], 152) + << "incorrect value for data[107], expected 152, is " + << last_msg_->data[107]; + EXPECT_EQ(last_msg_->data[108], 182) + << "incorrect value for data[108], expected 182, is " + << last_msg_->data[108]; + EXPECT_EQ(last_msg_->data[109], 88) + << "incorrect value for data[109], expected 88, is " + << last_msg_->data[109]; + EXPECT_EQ(last_msg_->data[110], 160) + << "incorrect value for data[110], expected 160, is " + << last_msg_->data[110]; + EXPECT_EQ(last_msg_->data[111], 255) + << "incorrect value for data[111], expected 255, is " + << last_msg_->data[111]; + EXPECT_EQ(last_msg_->data[112], 227) + << "incorrect value for data[112], expected 227, is " + << last_msg_->data[112]; + EXPECT_EQ(last_msg_->data[113], 240) + << "incorrect value for data[113], expected 240, is " + << last_msg_->data[113]; + EXPECT_EQ(last_msg_->data[114], 54) + << "incorrect value for data[114], expected 54, is " + << last_msg_->data[114]; + EXPECT_EQ(last_msg_->data[115], 100) + << "incorrect value for data[115], expected 100, is " + << last_msg_->data[115]; + EXPECT_EQ(last_msg_->data[116], 91) + << "incorrect value for data[116], expected 91, is " + << last_msg_->data[116]; + EXPECT_EQ(last_msg_->data[117], 31) + << "incorrect value for data[117], expected 31, is " + << last_msg_->data[117]; + EXPECT_EQ(last_msg_->data[118], 141) + << "incorrect value for data[118], expected 141, is " + << last_msg_->data[118]; + EXPECT_EQ(last_msg_->data[119], 102) + << "incorrect value for data[119], expected 102, is " + << last_msg_->data[119]; + EXPECT_EQ(last_msg_->data[120], 130) + << "incorrect value for data[120], expected 130, is " + << last_msg_->data[120]; + EXPECT_EQ(last_msg_->data[121], 254) + << "incorrect value for data[121], expected 254, is " + << last_msg_->data[121]; + EXPECT_EQ(last_msg_->data[122], 54) + << "incorrect value for data[122], expected 54, is " + << last_msg_->data[122]; + EXPECT_EQ(last_msg_->data[123], 227) + << "incorrect value for data[123], expected 227, is " + << last_msg_->data[123]; + EXPECT_EQ(last_msg_->data[124], 229) + << "incorrect value for data[124], expected 229, is " + << last_msg_->data[124]; + EXPECT_EQ(last_msg_->data[125], 62) + << "incorrect value for data[125], expected 62, is " + << last_msg_->data[125]; + EXPECT_EQ(last_msg_->data[126], 53) + << "incorrect value for data[126], expected 53, is " + << last_msg_->data[126]; + EXPECT_EQ(last_msg_->data[127], 225) + << "incorrect value for data[127], expected 225, is " + << last_msg_->data[127]; + EXPECT_EQ(last_msg_->data[128], 143) + << "incorrect value for data[128], expected 143, is " + << last_msg_->data[128]; + EXPECT_EQ(last_msg_->data[129], 88) + << "incorrect value for data[129], expected 88, is " + << last_msg_->data[129]; + EXPECT_EQ(last_msg_->data[130], 139) + << "incorrect value for data[130], expected 139, is " + << last_msg_->data[130]; + EXPECT_EQ(last_msg_->data[131], 126) + << "incorrect value for data[131], expected 126, is " + << last_msg_->data[131]; + EXPECT_EQ(last_msg_->data[132], 235) + << "incorrect value for data[132], expected 235, is " + << last_msg_->data[132]; + EXPECT_EQ(last_msg_->data[133], 235) + << "incorrect value for data[133], expected 235, is " + << last_msg_->data[133]; + EXPECT_EQ(last_msg_->data[134], 35) + << "incorrect value for data[134], expected 35, is " + << last_msg_->data[134]; + EXPECT_EQ(last_msg_->data[135], 54) + << "incorrect value for data[135], expected 54, is " + << last_msg_->data[135]; + EXPECT_EQ(last_msg_->data[136], 134) + << "incorrect value for data[136], expected 134, is " + << last_msg_->data[136]; + EXPECT_EQ(last_msg_->data[137], 163) + << "incorrect value for data[137], expected 163, is " + << last_msg_->data[137]; + EXPECT_EQ(last_msg_->data[138], 92) + << "incorrect value for data[138], expected 92, is " + << last_msg_->data[138]; + EXPECT_EQ(last_msg_->data[139], 57) + << "incorrect value for data[139], expected 57, is " + << last_msg_->data[139]; + EXPECT_EQ(last_msg_->data[140], 87) + << "incorrect value for data[140], expected 87, is " + << last_msg_->data[140]; + EXPECT_EQ(last_msg_->data[141], 130) + << "incorrect value for data[141], expected 130, is " + << last_msg_->data[141]; + EXPECT_EQ(last_msg_->data[142], 178) + << "incorrect value for data[142], expected 178, is " + << last_msg_->data[142]; + EXPECT_EQ(last_msg_->data[143], 22) + << "incorrect value for data[143], expected 22, is " + << last_msg_->data[143]; + EXPECT_EQ(last_msg_->data[144], 158) + << "incorrect value for data[144], expected 158, is " + << last_msg_->data[144]; + EXPECT_EQ(last_msg_->data[145], 18) + << "incorrect value for data[145], expected 18, is " + << last_msg_->data[145]; + EXPECT_EQ(last_msg_->data[146], 237) + << "incorrect value for data[146], expected 237, is " + << last_msg_->data[146]; + EXPECT_EQ(last_msg_->data[147], 209) + << "incorrect value for data[147], expected 209, is " + << last_msg_->data[147]; + EXPECT_EQ(last_msg_->data[148], 187) + << "incorrect value for data[148], expected 187, is " + << last_msg_->data[148]; + EXPECT_EQ(last_msg_->data[149], 226) + << "incorrect value for data[149], expected 226, is " + << last_msg_->data[149]; + EXPECT_EQ(last_msg_->data[150], 1) + << "incorrect value for data[150], expected 1, is " + << last_msg_->data[150]; + EXPECT_EQ(last_msg_->data[151], 46) + << "incorrect value for data[151], expected 46, is " + << last_msg_->data[151]; + EXPECT_EQ(last_msg_->data[152], 64) + << "incorrect value for data[152], expected 64, is " + << last_msg_->data[152]; + EXPECT_EQ(last_msg_->data[153], 226) + << "incorrect value for data[153], expected 226, is " + << last_msg_->data[153]; + EXPECT_EQ(last_msg_->data[154], 235) + << "incorrect value for data[154], expected 235, is " + << last_msg_->data[154]; + EXPECT_EQ(last_msg_->data[155], 213) + << "incorrect value for data[155], expected 213, is " + << last_msg_->data[155]; + EXPECT_EQ(last_msg_->data[156], 186) + << "incorrect value for data[156], expected 186, is " + << last_msg_->data[156]; + EXPECT_EQ(last_msg_->data[157], 159) + << "incorrect value for data[157], expected 159, is " + << last_msg_->data[157]; + EXPECT_EQ(last_msg_->data[158], 221) + << "incorrect value for data[158], expected 221, is " + << last_msg_->data[158]; + EXPECT_EQ(last_msg_->data[159], 186) + << "incorrect value for data[159], expected 186, is " + << last_msg_->data[159]; + EXPECT_EQ(last_msg_->data[160], 25) + << "incorrect value for data[160], expected 25, is " + << last_msg_->data[160]; + EXPECT_EQ(last_msg_->data[161], 115) + << "incorrect value for data[161], expected 115, is " + << last_msg_->data[161]; + EXPECT_EQ(last_msg_->data[162], 84) + << "incorrect value for data[162], expected 84, is " + << last_msg_->data[162]; + EXPECT_EQ(last_msg_->data[163], 131) + << "incorrect value for data[163], expected 131, is " + << last_msg_->data[163]; + EXPECT_EQ(last_msg_->data[164], 167) + << "incorrect value for data[164], expected 167, is " + << last_msg_->data[164]; + EXPECT_EQ(last_msg_->data[165], 201) + << "incorrect value for data[165], expected 201, is " + << last_msg_->data[165]; + EXPECT_EQ(last_msg_->data[166], 104) + << "incorrect value for data[166], expected 104, is " + << last_msg_->data[166]; + EXPECT_EQ(last_msg_->data[167], 1) + << "incorrect value for data[167], expected 1, is " + << last_msg_->data[167]; + EXPECT_EQ(last_msg_->data[168], 200) + << "incorrect value for data[168], expected 200, is " + << last_msg_->data[168]; + EXPECT_EQ(last_msg_->data[169], 13) + << "incorrect value for data[169], expected 13, is " + << last_msg_->data[169]; + EXPECT_EQ(last_msg_->data[170], 50) + << "incorrect value for data[170], expected 50, is " + << last_msg_->data[170]; + EXPECT_EQ(last_msg_->data[171], 71) + << "incorrect value for data[171], expected 71, is " + << last_msg_->data[171]; + EXPECT_EQ(last_msg_->data[172], 73) + << "incorrect value for data[172], expected 73, is " + << last_msg_->data[172]; + EXPECT_EQ(last_msg_->data[173], 193) + << "incorrect value for data[173], expected 193, is " + << last_msg_->data[173]; + EXPECT_EQ(last_msg_->data[174], 201) + << "incorrect value for data[174], expected 201, is " + << last_msg_->data[174]; + EXPECT_EQ(last_msg_->data[175], 250) + << "incorrect value for data[175], expected 250, is " + << last_msg_->data[175]; + EXPECT_EQ(last_msg_->data[176], 172) + << "incorrect value for data[176], expected 172, is " + << last_msg_->data[176]; + EXPECT_EQ(last_msg_->data[177], 193) + << "incorrect value for data[177], expected 193, is " + << last_msg_->data[177]; + EXPECT_EQ(last_msg_->data[178], 13) + << "incorrect value for data[178], expected 13, is " + << last_msg_->data[178]; + EXPECT_EQ(last_msg_->data[179], 20) + << "incorrect value for data[179], expected 20, is " + << last_msg_->data[179]; + EXPECT_EQ(last_msg_->data[180], 238) + << "incorrect value for data[180], expected 238, is " + << last_msg_->data[180]; + EXPECT_EQ(last_msg_->data[181], 130) + << "incorrect value for data[181], expected 130, is " + << last_msg_->data[181]; + EXPECT_EQ(last_msg_->data[182], 243) + << "incorrect value for data[182], expected 243, is " + << last_msg_->data[182]; + EXPECT_EQ(last_msg_->data[183], 68) + << "incorrect value for data[183], expected 68, is " + << last_msg_->data[183]; + EXPECT_EQ(last_msg_->data[184], 4) + << "incorrect value for data[184], expected 4, is " + << last_msg_->data[184]; + EXPECT_EQ(last_msg_->data[185], 72) + << "incorrect value for data[185], expected 72, is " + << last_msg_->data[185]; + EXPECT_EQ(last_msg_->data[186], 46) + << "incorrect value for data[186], expected 46, is " + << last_msg_->data[186]; + EXPECT_EQ(last_msg_->data[187], 194) + << "incorrect value for data[187], expected 194, is " + << last_msg_->data[187]; + EXPECT_EQ(last_msg_->data[188], 113) + << "incorrect value for data[188], expected 113, is " + << last_msg_->data[188]; + EXPECT_EQ(last_msg_->data[189], 255) + << "incorrect value for data[189], expected 255, is " + << last_msg_->data[189]; + EXPECT_EQ(last_msg_->data[190], 238) + << "incorrect value for data[190], expected 238, is " + << last_msg_->data[190]; + EXPECT_EQ(last_msg_->data[191], 15) + << "incorrect value for data[191], expected 15, is " + << last_msg_->data[191]; + EXPECT_EQ(last_msg_->data[192], 230) + << "incorrect value for data[192], expected 230, is " + << last_msg_->data[192]; + EXPECT_EQ(last_msg_->data[193], 64) + << "incorrect value for data[193], expected 64, is " + << last_msg_->data[193]; + EXPECT_EQ(last_msg_->data[194], 178) + << "incorrect value for data[194], expected 178, is " + << last_msg_->data[194]; + EXPECT_EQ(last_msg_->data[195], 127) + << "incorrect value for data[195], expected 127, is " + << last_msg_->data[195]; + EXPECT_EQ(last_msg_->data[196], 217) + << "incorrect value for data[196], expected 217, is " + << last_msg_->data[196]; + EXPECT_EQ(last_msg_->data[197], 92) + << "incorrect value for data[197], expected 92, is " + << last_msg_->data[197]; + EXPECT_EQ(last_msg_->data[198], 160) + << "incorrect value for data[198], expected 160, is " + << last_msg_->data[198]; + EXPECT_EQ(last_msg_->data[199], 201) + << "incorrect value for data[199], expected 201, is " + << last_msg_->data[199]; + EXPECT_EQ(last_msg_->data[200], 118) + << "incorrect value for data[200], expected 118, is " + << last_msg_->data[200]; + EXPECT_EQ(last_msg_->data[201], 163) + << "incorrect value for data[201], expected 163, is " + << last_msg_->data[201]; + EXPECT_EQ(last_msg_->data[202], 144) + << "incorrect value for data[202], expected 144, is " + << last_msg_->data[202]; + EXPECT_EQ(last_msg_->data[203], 58) + << "incorrect value for data[203], expected 58, is " + << last_msg_->data[203]; + EXPECT_EQ(last_msg_->data[204], 28) + << "incorrect value for data[204], expected 28, is " + << last_msg_->data[204]; + EXPECT_EQ(last_msg_->data[205], 174) + << "incorrect value for data[205], expected 174, is " + << last_msg_->data[205]; + EXPECT_EQ(last_msg_->data[206], 65) + << "incorrect value for data[206], expected 65, is " + << last_msg_->data[206]; + EXPECT_EQ(last_msg_->data[207], 73) + << "incorrect value for data[207], expected 73, is " + << last_msg_->data[207]; + EXPECT_EQ(last_msg_->data[208], 45) + << "incorrect value for data[208], expected 45, is " + << last_msg_->data[208]; + EXPECT_EQ(last_msg_->data[209], 123) + << "incorrect value for data[209], expected 123, is " + << last_msg_->data[209]; + EXPECT_EQ(last_msg_->data[210], 118) + << "incorrect value for data[210], expected 118, is " + << last_msg_->data[210]; + EXPECT_EQ(last_msg_->data[211], 83) + << "incorrect value for data[211], expected 83, is " + << last_msg_->data[211]; + EXPECT_EQ(last_msg_->data[212], 107) + << "incorrect value for data[212], expected 107, is " + << last_msg_->data[212]; + EXPECT_EQ(last_msg_->data[213], 239) + << "incorrect value for data[213], expected 239, is " + << last_msg_->data[213]; + EXPECT_EQ(last_msg_->data[214], 168) + << "incorrect value for data[214], expected 168, is " + << last_msg_->data[214]; + EXPECT_EQ(last_msg_->data[215], 32) + << "incorrect value for data[215], expected 32, is " + << last_msg_->data[215]; + EXPECT_EQ(last_msg_->data[216], 212) + << "incorrect value for data[216], expected 212, is " + << last_msg_->data[216]; + EXPECT_EQ(last_msg_->data[217], 191) + << "incorrect value for data[217], expected 191, is " + << last_msg_->data[217]; + EXPECT_EQ(last_msg_->data[218], 81) + << "incorrect value for data[218], expected 81, is " + << last_msg_->data[218]; + EXPECT_EQ(last_msg_->data[219], 93) + << "incorrect value for data[219], expected 93, is " + << last_msg_->data[219]; + EXPECT_EQ(last_msg_->data[220], 186) + << "incorrect value for data[220], expected 186, is " + << last_msg_->data[220]; + EXPECT_EQ(last_msg_->data[221], 223) + << "incorrect value for data[221], expected 223, is " + << last_msg_->data[221]; + EXPECT_EQ(last_msg_->data[222], 32) + << "incorrect value for data[222], expected 32, is " + << last_msg_->data[222]; + EXPECT_EQ(last_msg_->data[223], 19) + << "incorrect value for data[223], expected 19, is " + << last_msg_->data[223]; + EXPECT_EQ(last_msg_->data[224], 58) + << "incorrect value for data[224], expected 58, is " + << last_msg_->data[224]; + EXPECT_EQ(last_msg_->data[225], 137) + << "incorrect value for data[225], expected 137, is " + << last_msg_->data[225]; + EXPECT_EQ(last_msg_->data[226], 72) + << "incorrect value for data[226], expected 72, is " + << last_msg_->data[226]; + EXPECT_EQ(last_msg_->data[227], 217) + << "incorrect value for data[227], expected 217, is " + << last_msg_->data[227]; + EXPECT_EQ(last_msg_->data[228], 151) + << "incorrect value for data[228], expected 151, is " + << last_msg_->data[228]; + EXPECT_EQ(last_msg_->data[229], 251) + << "incorrect value for data[229], expected 251, is " + << last_msg_->data[229]; + EXPECT_EQ(last_msg_->data[230], 83) + << "incorrect value for data[230], expected 83, is " + << last_msg_->data[230]; + EXPECT_EQ(last_msg_->data[231], 20) + << "incorrect value for data[231], expected 20, is " + << last_msg_->data[231]; + EXPECT_EQ(last_msg_->data[232], 113) + << "incorrect value for data[232], expected 113, is " + << last_msg_->data[232]; + EXPECT_EQ(last_msg_->data[233], 37) + << "incorrect value for data[233], expected 37, is " + << last_msg_->data[233]; + EXPECT_EQ(last_msg_->data[234], 151) + << "incorrect value for data[234], expected 151, is " + << last_msg_->data[234]; + EXPECT_EQ(last_msg_->data[235], 34) + << "incorrect value for data[235], expected 34, is " + << last_msg_->data[235]; + EXPECT_EQ(last_msg_->data[236], 37) + << "incorrect value for data[236], expected 37, is " + << last_msg_->data[236]; + EXPECT_EQ(last_msg_->data[237], 71) + << "incorrect value for data[237], expected 71, is " + << last_msg_->data[237]; + EXPECT_EQ(last_msg_->data[238], 95) + << "incorrect value for data[238], expected 95, is " + << last_msg_->data[238]; + EXPECT_EQ(last_msg_->data[239], 105) + << "incorrect value for data[239], expected 105, is " + << last_msg_->data[239]; + EXPECT_EQ(last_msg_->data[240], 235) + << "incorrect value for data[240], expected 235, is " + << last_msg_->data[240]; + EXPECT_EQ(last_msg_->data[241], 144) + << "incorrect value for data[241], expected 144, is " + << last_msg_->data[241]; + EXPECT_EQ(last_msg_->data[242], 164) + << "incorrect value for data[242], expected 164, is " + << last_msg_->data[242]; + EXPECT_EQ(last_msg_->data[243], 83) + << "incorrect value for data[243], expected 83, is " + << last_msg_->data[243]; + EXPECT_EQ(last_msg_->data[244], 197) + << "incorrect value for data[244], expected 197, is " + << last_msg_->data[244]; + EXPECT_EQ(last_msg_->data[245], 254) + << "incorrect value for data[245], expected 254, is " + << last_msg_->data[245]; + EXPECT_EQ(last_msg_->data[246], 183) + << "incorrect value for data[246], expected 183, is " + << last_msg_->data[246]; + EXPECT_EQ(last_msg_->data[247], 223) + << "incorrect value for data[247], expected 223, is " + << last_msg_->data[247]; + EXPECT_EQ(last_msg_->data[248], 91) + << "incorrect value for data[248], expected 91, is " + << last_msg_->data[248]; + EXPECT_EQ(last_msg_->data[249], 19) + << "incorrect value for data[249], expected 19, is " + << last_msg_->data[249]; + EXPECT_EQ(last_msg_->target, 212) + << "incorrect value for target, expected 212, is " << last_msg_->target; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc new file mode 100644 index 0000000000..62d3751fe2 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadReq.cc @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgFlashReadReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgFlashReadReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_flash_read_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_flash_read_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgFlashReadReq0, Test) { + uint8_t encoded_frame[] = { + 85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_flash_read_req_t *test_msg = (msg_flash_read_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->addr_len = 71; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[0] = 28; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[1] = 75; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[2] = 244; + test_msg->target = 241; + + EXPECT_EQ(send_message(0xe7, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->addr_len, 71) + << "incorrect value for addr_len, expected 71, is " + << last_msg_->addr_len; + EXPECT_EQ(last_msg_->addr_start[0], 28) + << "incorrect value for addr_start[0], expected 28, is " + << last_msg_->addr_start[0]; + EXPECT_EQ(last_msg_->addr_start[1], 75) + << "incorrect value for addr_start[1], expected 75, is " + << last_msg_->addr_start[1]; + EXPECT_EQ(last_msg_->addr_start[2], 244) + << "incorrect value for addr_start[2], expected 244, is " + << last_msg_->addr_start[2]; + EXPECT_EQ(last_msg_->target, 241) + << "incorrect value for target, expected 241, is " << last_msg_->target; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc new file mode 100644 index 0000000000..807c6d59b1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgFlashReadResp.cc @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgFlashReadResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgFlashReadResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_flash_read_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_flash_read_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgFlashReadResp0, Test) { + uint8_t encoded_frame[] = { + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_flash_read_resp_t *test_msg = (msg_flash_read_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->addr_len = 124; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[0] = 155; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[1] = 52; + if (sizeof(test_msg->addr_start) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->addr_start[0])); + } + test_msg->addr_start[2] = 172; + test_msg->target = 136; + + EXPECT_EQ(send_message(0xe1, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->addr_len, 124) + << "incorrect value for addr_len, expected 124, is " + << last_msg_->addr_len; + EXPECT_EQ(last_msg_->addr_start[0], 155) + << "incorrect value for addr_start[0], expected 155, is " + << last_msg_->addr_start[0]; + EXPECT_EQ(last_msg_->addr_start[1], 52) + << "incorrect value for addr_start[1], expected 52, is " + << last_msg_->addr_start[1]; + EXPECT_EQ(last_msg_->addr_start[2], 172) + << "incorrect value for addr_start[2], expected 172, is " + << last_msg_->addr_start[2]; + EXPECT_EQ(last_msg_->target, 136) + << "incorrect value for target, expected 136, is " << last_msg_->target; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc new file mode 100644 index 0000000000..02fc16516b --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgM25FlashWriteStatus.cc @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_m25_flash_write_status_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_m25_flash_write_status_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgM25FlashWriteStatus0, Test) { + uint8_t encoded_frame[] = { + 85, 243, 0, 195, 4, 1, 5, 112, 200, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_m25_flash_write_status_t *test_msg = + (msg_m25_flash_write_status_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[0] = 5; + + EXPECT_EQ(send_message(0xf3, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->status[0], 5) + << "incorrect value for status[0], expected 5, is " + << last_msg_->status[0]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc new file mode 100644 index 0000000000..45550167a7 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashLockSector.cc @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgStmFlashLockSector0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgStmFlashLockSector0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_stm_flash_lock_sector_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_stm_flash_lock_sector_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgStmFlashLockSector0, Test) { + uint8_t encoded_frame[] = { + 85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_stm_flash_lock_sector_t *test_msg = + (msg_stm_flash_lock_sector_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->sector = 1137047457; + + EXPECT_EQ(send_message(0xe3, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->sector, 1137047457) + << "incorrect value for sector, expected 1137047457, is " + << last_msg_->sector; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc new file mode 100644 index 0000000000..3705c2a915 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmFlashUnlockSector.cc @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_stm_flash_unlock_sector_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_stm_flash_unlock_sector_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgStmFlashUnlockSector0, Test) { + uint8_t encoded_frame[] = { + 85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_stm_flash_unlock_sector_t *test_msg = + (msg_stm_flash_unlock_sector_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->sector = 837226527; + + EXPECT_EQ(send_message(0xe4, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->sector, 837226527) + << "incorrect value for sector, expected 837226527, is " + << last_msg_->sector; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc new file mode 100644 index 0000000000..039b0be426 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdReq.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc new file mode 100644 index 0000000000..6c9fcff604 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_flash_MsgStmUniqueIdResp.cc @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_stm_unique_id_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_stm_unique_id_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_flash_MsgStmUniqueIdResp0, Test) { + uint8_t encoded_frame[] = { + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, + 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_stm_unique_id_resp_t *test_msg = + (msg_stm_unique_id_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[0] = 196; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[1] = 16; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[2] = 15; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[3] = 163; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[4] = 85; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[5] = 221; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[6] = 119; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[7] = 102; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[8] = 32; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[9] = 194; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[10] = 56; + if (sizeof(test_msg->stm_id) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stm_id[0])); + } + test_msg->stm_id[11] = 144; + + EXPECT_EQ(send_message(0xe5, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->stm_id[0], 196) + << "incorrect value for stm_id[0], expected 196, is " + << last_msg_->stm_id[0]; + EXPECT_EQ(last_msg_->stm_id[1], 16) + << "incorrect value for stm_id[1], expected 16, is " + << last_msg_->stm_id[1]; + EXPECT_EQ(last_msg_->stm_id[2], 15) + << "incorrect value for stm_id[2], expected 15, is " + << last_msg_->stm_id[2]; + EXPECT_EQ(last_msg_->stm_id[3], 163) + << "incorrect value for stm_id[3], expected 163, is " + << last_msg_->stm_id[3]; + EXPECT_EQ(last_msg_->stm_id[4], 85) + << "incorrect value for stm_id[4], expected 85, is " + << last_msg_->stm_id[4]; + EXPECT_EQ(last_msg_->stm_id[5], 221) + << "incorrect value for stm_id[5], expected 221, is " + << last_msg_->stm_id[5]; + EXPECT_EQ(last_msg_->stm_id[6], 119) + << "incorrect value for stm_id[6], expected 119, is " + << last_msg_->stm_id[6]; + EXPECT_EQ(last_msg_->stm_id[7], 102) + << "incorrect value for stm_id[7], expected 102, is " + << last_msg_->stm_id[7]; + EXPECT_EQ(last_msg_->stm_id[8], 32) + << "incorrect value for stm_id[8], expected 32, is " + << last_msg_->stm_id[8]; + EXPECT_EQ(last_msg_->stm_id[9], 194) + << "incorrect value for stm_id[9], expected 194, is " + << last_msg_->stm_id[9]; + EXPECT_EQ(last_msg_->stm_id[10], 56) + << "incorrect value for stm_id[10], expected 56, is " + << last_msg_->stm_id[10]; + EXPECT_EQ(last_msg_->stm_id[11], 144) + << "incorrect value for stm_id[11], expected 144, is " + << last_msg_->stm_id[11]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc new file mode 100644 index 0000000000..846a1eaaac --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuState.cc @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxCpuState0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxCpuState0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_cpu_state_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_cpu_state_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxCpuState0, Test) { + uint8_t encoded_frame[] = { + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, + 235, 20, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, 229, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_cpu_state_t *test_msg = (msg_linux_cpu_state_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->flags = 20; + test_msg->index = 101; + test_msg->pcpu = 98; + test_msg->pid = 50042; + test_msg->time = 3948815319; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0x7f08, 34196, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 34196); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->flags, 20) + << "incorrect value for flags, expected 20, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->index, 101) + << "incorrect value for index, expected 101, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pcpu, 98) + << "incorrect value for pcpu, expected 98, is " << last_msg_->pcpu; + EXPECT_EQ(last_msg_->pid, 50042) + << "incorrect value for pid, expected 50042, is " << last_msg_->pid; + EXPECT_EQ(last_msg_->time, 3948815319) + << "incorrect value for time, expected 3948815319, is " + << last_msg_->time; + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + EXPECT_EQ(memcmp(last_msg_->tname, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->tname, expected string '" + << check_string << "', is '" << last_msg_->tname << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc new file mode 100644 index 0000000000..c489c96e30 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxCpuStateDepA.cc @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_cpu_state_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_cpu_state_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxCpuStateDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 80, 48, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_cpu_state_dep_a_t *test_msg = + (msg_linux_cpu_state_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->index = 51; + test_msg->pcpu = 178; + test_msg->pid = 64240; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0x7f00, 23308, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 23308); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->index, 51) + << "incorrect value for index, expected 51, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pcpu, 178) + << "incorrect value for pcpu, expected 178, is " << last_msg_->pcpu; + EXPECT_EQ(last_msg_->pid, 64240) + << "incorrect value for pid, expected 64240, is " << last_msg_->pid; + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + EXPECT_EQ(memcmp(last_msg_->tname, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->tname, expected string '" + << check_string << "', is '" << last_msg_->tname << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc new file mode 100644 index 0000000000..36dcc407d2 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemState.cc @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxMemState0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxMemState0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_mem_state_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_mem_state_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxMemState0, Test) { + uint8_t encoded_frame[] = { + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, + 187, 76, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, + 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_mem_state_t *test_msg = (msg_linux_mem_state_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->flags = 76; + test_msg->index = 154; + test_msg->pid = 57279; + test_msg->pmem = 19; + test_msg->time = 3139057143; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0x7f09, 64863, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 64863); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->flags, 76) + << "incorrect value for flags, expected 76, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->index, 154) + << "incorrect value for index, expected 154, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pid, 57279) + << "incorrect value for pid, expected 57279, is " << last_msg_->pid; + EXPECT_EQ(last_msg_->pmem, 19) + << "incorrect value for pmem, expected 19, is " << last_msg_->pmem; + EXPECT_EQ(last_msg_->time, 3139057143) + << "incorrect value for time, expected 3139057143, is " + << last_msg_->time; + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + EXPECT_EQ(memcmp(last_msg_->tname, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->tname, expected string '" + << check_string << "', is '" << last_msg_->tname << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc new file mode 100644 index 0000000000..3d5738c181 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxMemStateDepA.cc @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_mem_state_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_mem_state_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxMemStateDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, + 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, + 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 17, 137, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_mem_state_dep_a_t *test_msg = + (msg_linux_mem_state_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->index = 247; + test_msg->pid = 12381; + test_msg->pmem = 193; + { + const char assign_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + memcpy(test_msg->tname, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->tname) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0x7f01, 28089, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 28089); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->index, 247) + << "incorrect value for index, expected 247, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pid, 12381) + << "incorrect value for pid, expected 12381, is " << last_msg_->pid; + EXPECT_EQ(last_msg_->pmem, 193) + << "incorrect value for pmem, expected 193, is " << last_msg_->pmem; + { + const char check_string[] = {(char)112, (char)114, (char)111, (char)99, + (char)101, (char)115, (char)115, (char)45, + (char)110, (char)97, (char)109, (char)101, + (char)0, (char)0, (char)0}; + EXPECT_EQ(memcmp(last_msg_->tname, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->tname, expected string '" + << check_string << "', is '" << last_msg_->tname << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc new file mode 100644 index 0000000000..c55d034f73 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdCount.cc @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_process_fd_count_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_process_fd_count_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdCount0, Test) { + uint8_t encoded_frame[] = { + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, 112, 97, 116, + 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, + 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, + 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 94, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_process_fd_count_t *test_msg = + (msg_linux_process_fd_count_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->fd_count = 35589; + test_msg->index = 164; + test_msg->pid = 42429; + + EXPECT_EQ(send_message(0x7f06, 49950, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 49950); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->fd_count, 35589) + << "incorrect value for fd_count, expected 35589, is " + << last_msg_->fd_count; + EXPECT_EQ(last_msg_->index, 164) + << "incorrect value for index, expected 164, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pid, 42429) + << "incorrect value for pid, expected 42429, is " << last_msg_->pid; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc new file mode 100644 index 0000000000..d55370edea --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessFdSummary.cc @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_process_fd_summary_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_process_fd_summary_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxProcessFdSummary0, Test) { + uint8_t encoded_frame[] = { + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, + 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, + 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_process_fd_summary_t *test_msg = + (msg_linux_process_fd_summary_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)102, (char)100, (char)49, (char)0, (char)102, + (char)100, (char)50, (char)0, (char)102, (char)100, + (char)51, (char)0, (char)102, (char)100, (char)52, + (char)0, (char)102, (char)100, (char)53, (char)0, + (char)102, (char)100, (char)54, (char)0, (char)0}; + memcpy(test_msg->most_opened, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->most_opened) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->sys_fd_count = 1304986387; + + EXPECT_EQ(send_message(0x7f07, 63591, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 63591); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)102, (char)100, (char)49, (char)0, (char)102, + (char)100, (char)50, (char)0, (char)102, (char)100, + (char)51, (char)0, (char)102, (char)100, (char)52, + (char)0, (char)102, (char)100, (char)53, (char)0, + (char)102, (char)100, (char)54, (char)0, (char)0}; + EXPECT_EQ( + memcmp(last_msg_->most_opened, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->most_opened, expected string '" + << check_string << "', is '" << last_msg_->most_opened << "'"; + } + EXPECT_EQ(last_msg_->sys_fd_count, 1304986387) + << "incorrect value for sys_fd_count, expected 1304986387, is " + << last_msg_->sys_fd_count; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc new file mode 100644 index 0000000000..5a56c387cc --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketCounts.cc @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_process_socket_counts_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_process_socket_counts_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketCounts0, Test) { + uint8_t encoded_frame[] = { + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, + 114, 115, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, + 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, + 97, 114, 103, 51, 32, 97, 114, 103, 52, 180, 131, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_process_socket_counts_t *test_msg = + (msg_linux_process_socket_counts_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->index = 51; + test_msg->pid = 28553; + test_msg->socket_count = 30287; + test_msg->socket_states = 29554; + test_msg->socket_types = 35843; + + EXPECT_EQ(send_message(0x7f03, 2412, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 2412); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->index, 51) + << "incorrect value for index, expected 51, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pid, 28553) + << "incorrect value for pid, expected 28553, is " << last_msg_->pid; + EXPECT_EQ(last_msg_->socket_count, 30287) + << "incorrect value for socket_count, expected 30287, is " + << last_msg_->socket_count; + EXPECT_EQ(last_msg_->socket_states, 29554) + << "incorrect value for socket_states, expected 29554, is " + << last_msg_->socket_states; + EXPECT_EQ(last_msg_->socket_types, 35843) + << "incorrect value for socket_types, expected 35843, is " + << last_msg_->socket_types; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc new file mode 100644 index 0000000000..bef3207f7a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxProcessSocketQueues.cc @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_process_socket_queues_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_process_socket_queues_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxProcessSocketQueues0, Test) { + uint8_t encoded_frame[] = { + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, 80, 109, + 15, 223, 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, + 114, 103, 101, 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, + 103, 51, 32, 97, 114, 103, 52, 2, 247, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_process_socket_queues_t *test_msg = + (msg_linux_process_socket_queues_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg->address_of_largest, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->address_of_largest) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + memcpy(test_msg->cmdline, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->cmdline) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->index = 181; + test_msg->pid = 19335; + test_msg->recv_queued = 54265; + test_msg->send_queued = 64547; + test_msg->socket_states = 57103; + test_msg->socket_types = 27984; + + EXPECT_EQ(send_message(0x7f04, 59579, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 59579); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)97, (char)100, (char)100, (char)114, (char)101, (char)115, + (char)115, (char)32, (char)111, (char)102, (char)32, (char)108, + (char)97, (char)114, (char)103, (char)101, (char)115, (char)116, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + EXPECT_EQ(memcmp(last_msg_->address_of_largest, check_string, + sizeof(check_string)), + 0) + << "incorrect value for last_msg_->address_of_largest, expected string " + "'" + << check_string << "', is '" << last_msg_->address_of_largest << "'"; + } + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)112, (char)114, (char)111, + (char)99, (char)101, (char)115, (char)115, (char)45, (char)110, + (char)97, (char)109, (char)101, (char)32, (char)97, (char)114, + (char)103, (char)48, (char)32, (char)97, (char)114, (char)103, + (char)49, (char)32, (char)97, (char)114, (char)103, (char)50, + (char)32, (char)97, (char)114, (char)103, (char)51, (char)32, + (char)97, (char)114, (char)103, (char)52}; + EXPECT_EQ(memcmp(last_msg_->cmdline, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->cmdline, expected string '" + << check_string << "', is '" << last_msg_->cmdline << "'"; + } + EXPECT_EQ(last_msg_->index, 181) + << "incorrect value for index, expected 181, is " << last_msg_->index; + EXPECT_EQ(last_msg_->pid, 19335) + << "incorrect value for pid, expected 19335, is " << last_msg_->pid; + EXPECT_EQ(last_msg_->recv_queued, 54265) + << "incorrect value for recv_queued, expected 54265, is " + << last_msg_->recv_queued; + EXPECT_EQ(last_msg_->send_queued, 64547) + << "incorrect value for send_queued, expected 64547, is " + << last_msg_->send_queued; + EXPECT_EQ(last_msg_->socket_states, 57103) + << "incorrect value for socket_states, expected 57103, is " + << last_msg_->socket_states; + EXPECT_EQ(last_msg_->socket_types, 27984) + << "incorrect value for socket_types, expected 27984, is " + << last_msg_->socket_types; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc new file mode 100644 index 0000000000..31c3fd1dc0 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSocketUsage.cc @@ -0,0 +1,405 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_socket_usage_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_socket_usage_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxSocketUsage0, Test) { + uint8_t encoded_frame[] = { + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, + 246, 154, 251, 17, 224, 179, 26, 169, 177, 90, 149, 213, 214, 6, + 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, 217, 209, 52, 14, + 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, + 176, 74, 159, 129, 154, 153, 162, 229, 130, 154, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_socket_usage_t *test_msg = + (msg_linux_socket_usage_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->avg_queue_depth = 2907030541; + test_msg->max_queue_depth = 3048922691; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[0] = 39670; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[1] = 4603; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[2] = 46048; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[3] = 43290; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[4] = 23217; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[5] = 54677; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[6] = 1750; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[7] = 16510; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[8] = 47480; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[9] = 33620; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[10] = 28616; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[11] = 36128; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[12] = 53721; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[13] = 3636; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[14] = 37822; + if (sizeof(test_msg->socket_state_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_state_counts[0])); + } + test_msg->socket_state_counts[15] = 63135; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[0] = 31373; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[1] = 30676; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[2] = 7811; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[3] = 12152; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[4] = 27929; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[5] = 16794; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[6] = 42116; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[7] = 7719; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[8] = 44830; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[9] = 11272; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[10] = 28444; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[11] = 61676; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[12] = 19120; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[13] = 33183; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[14] = 39322; + if (sizeof(test_msg->socket_type_counts) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->socket_type_counts[0])); + } + test_msg->socket_type_counts[15] = 58786; + + EXPECT_EQ(send_message(0x7f05, 35442, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 35442); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->avg_queue_depth, 2907030541) + << "incorrect value for avg_queue_depth, expected 2907030541, is " + << last_msg_->avg_queue_depth; + EXPECT_EQ(last_msg_->max_queue_depth, 3048922691) + << "incorrect value for max_queue_depth, expected 3048922691, is " + << last_msg_->max_queue_depth; + EXPECT_EQ(last_msg_->socket_state_counts[0], 39670) + << "incorrect value for socket_state_counts[0], expected 39670, is " + << last_msg_->socket_state_counts[0]; + EXPECT_EQ(last_msg_->socket_state_counts[1], 4603) + << "incorrect value for socket_state_counts[1], expected 4603, is " + << last_msg_->socket_state_counts[1]; + EXPECT_EQ(last_msg_->socket_state_counts[2], 46048) + << "incorrect value for socket_state_counts[2], expected 46048, is " + << last_msg_->socket_state_counts[2]; + EXPECT_EQ(last_msg_->socket_state_counts[3], 43290) + << "incorrect value for socket_state_counts[3], expected 43290, is " + << last_msg_->socket_state_counts[3]; + EXPECT_EQ(last_msg_->socket_state_counts[4], 23217) + << "incorrect value for socket_state_counts[4], expected 23217, is " + << last_msg_->socket_state_counts[4]; + EXPECT_EQ(last_msg_->socket_state_counts[5], 54677) + << "incorrect value for socket_state_counts[5], expected 54677, is " + << last_msg_->socket_state_counts[5]; + EXPECT_EQ(last_msg_->socket_state_counts[6], 1750) + << "incorrect value for socket_state_counts[6], expected 1750, is " + << last_msg_->socket_state_counts[6]; + EXPECT_EQ(last_msg_->socket_state_counts[7], 16510) + << "incorrect value for socket_state_counts[7], expected 16510, is " + << last_msg_->socket_state_counts[7]; + EXPECT_EQ(last_msg_->socket_state_counts[8], 47480) + << "incorrect value for socket_state_counts[8], expected 47480, is " + << last_msg_->socket_state_counts[8]; + EXPECT_EQ(last_msg_->socket_state_counts[9], 33620) + << "incorrect value for socket_state_counts[9], expected 33620, is " + << last_msg_->socket_state_counts[9]; + EXPECT_EQ(last_msg_->socket_state_counts[10], 28616) + << "incorrect value for socket_state_counts[10], expected 28616, is " + << last_msg_->socket_state_counts[10]; + EXPECT_EQ(last_msg_->socket_state_counts[11], 36128) + << "incorrect value for socket_state_counts[11], expected 36128, is " + << last_msg_->socket_state_counts[11]; + EXPECT_EQ(last_msg_->socket_state_counts[12], 53721) + << "incorrect value for socket_state_counts[12], expected 53721, is " + << last_msg_->socket_state_counts[12]; + EXPECT_EQ(last_msg_->socket_state_counts[13], 3636) + << "incorrect value for socket_state_counts[13], expected 3636, is " + << last_msg_->socket_state_counts[13]; + EXPECT_EQ(last_msg_->socket_state_counts[14], 37822) + << "incorrect value for socket_state_counts[14], expected 37822, is " + << last_msg_->socket_state_counts[14]; + EXPECT_EQ(last_msg_->socket_state_counts[15], 63135) + << "incorrect value for socket_state_counts[15], expected 63135, is " + << last_msg_->socket_state_counts[15]; + EXPECT_EQ(last_msg_->socket_type_counts[0], 31373) + << "incorrect value for socket_type_counts[0], expected 31373, is " + << last_msg_->socket_type_counts[0]; + EXPECT_EQ(last_msg_->socket_type_counts[1], 30676) + << "incorrect value for socket_type_counts[1], expected 30676, is " + << last_msg_->socket_type_counts[1]; + EXPECT_EQ(last_msg_->socket_type_counts[2], 7811) + << "incorrect value for socket_type_counts[2], expected 7811, is " + << last_msg_->socket_type_counts[2]; + EXPECT_EQ(last_msg_->socket_type_counts[3], 12152) + << "incorrect value for socket_type_counts[3], expected 12152, is " + << last_msg_->socket_type_counts[3]; + EXPECT_EQ(last_msg_->socket_type_counts[4], 27929) + << "incorrect value for socket_type_counts[4], expected 27929, is " + << last_msg_->socket_type_counts[4]; + EXPECT_EQ(last_msg_->socket_type_counts[5], 16794) + << "incorrect value for socket_type_counts[5], expected 16794, is " + << last_msg_->socket_type_counts[5]; + EXPECT_EQ(last_msg_->socket_type_counts[6], 42116) + << "incorrect value for socket_type_counts[6], expected 42116, is " + << last_msg_->socket_type_counts[6]; + EXPECT_EQ(last_msg_->socket_type_counts[7], 7719) + << "incorrect value for socket_type_counts[7], expected 7719, is " + << last_msg_->socket_type_counts[7]; + EXPECT_EQ(last_msg_->socket_type_counts[8], 44830) + << "incorrect value for socket_type_counts[8], expected 44830, is " + << last_msg_->socket_type_counts[8]; + EXPECT_EQ(last_msg_->socket_type_counts[9], 11272) + << "incorrect value for socket_type_counts[9], expected 11272, is " + << last_msg_->socket_type_counts[9]; + EXPECT_EQ(last_msg_->socket_type_counts[10], 28444) + << "incorrect value for socket_type_counts[10], expected 28444, is " + << last_msg_->socket_type_counts[10]; + EXPECT_EQ(last_msg_->socket_type_counts[11], 61676) + << "incorrect value for socket_type_counts[11], expected 61676, is " + << last_msg_->socket_type_counts[11]; + EXPECT_EQ(last_msg_->socket_type_counts[12], 19120) + << "incorrect value for socket_type_counts[12], expected 19120, is " + << last_msg_->socket_type_counts[12]; + EXPECT_EQ(last_msg_->socket_type_counts[13], 33183) + << "incorrect value for socket_type_counts[13], expected 33183, is " + << last_msg_->socket_type_counts[13]; + EXPECT_EQ(last_msg_->socket_type_counts[14], 39322) + << "incorrect value for socket_type_counts[14], expected 39322, is " + << last_msg_->socket_type_counts[14]; + EXPECT_EQ(last_msg_->socket_type_counts[15], 58786) + << "incorrect value for socket_type_counts[15], expected 58786, is " + << last_msg_->socket_type_counts[15]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc new file mode 100644 index 0000000000..667bf5dea2 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysState.cc @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxSysState0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxSysState0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_sys_state_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_sys_state_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxSysState0, Test) { + uint8_t encoded_frame[] = { + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, + 161, 229, 250, 186, 108, 30, 106, 5, 9, 229, 242, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_sys_state_t *test_msg = (msg_linux_sys_state_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 9; + test_msg->mem_total = 53012; + test_msg->pcpu = 125; + test_msg->pid_count = 47866; + test_msg->pmem = 215; + test_msg->procs_starting = 18372; + test_msg->procs_stopping = 58785; + test_msg->time = 90840684; + + EXPECT_EQ(send_message(0x7f0a, 42837, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 42837); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 9) + << "incorrect value for flags, expected 9, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->mem_total, 53012) + << "incorrect value for mem_total, expected 53012, is " + << last_msg_->mem_total; + EXPECT_EQ(last_msg_->pcpu, 125) + << "incorrect value for pcpu, expected 125, is " << last_msg_->pcpu; + EXPECT_EQ(last_msg_->pid_count, 47866) + << "incorrect value for pid_count, expected 47866, is " + << last_msg_->pid_count; + EXPECT_EQ(last_msg_->pmem, 215) + << "incorrect value for pmem, expected 215, is " << last_msg_->pmem; + EXPECT_EQ(last_msg_->procs_starting, 18372) + << "incorrect value for procs_starting, expected 18372, is " + << last_msg_->procs_starting; + EXPECT_EQ(last_msg_->procs_stopping, 58785) + << "incorrect value for procs_stopping, expected 58785, is " + << last_msg_->procs_stopping; + EXPECT_EQ(last_msg_->time, 90840684) + << "incorrect value for time, expected 90840684, is " << last_msg_->time; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc new file mode 100644 index 0000000000..5151ce0992 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_linux_MsgLinuxSysStateDepA.cc @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_linux_sys_state_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_linux_sys_state_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_linux_MsgLinuxSysStateDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 2, 127, 84, 56, 10, 188, 163, 211, + 194, 115, 71, 101, 103, 124, 201, 223, 223, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_linux_sys_state_dep_a_t *test_msg = + (msg_linux_sys_state_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->mem_total = 41916; + test_msg->pcpu = 211; + test_msg->pid_count = 51580; + test_msg->pmem = 194; + test_msg->procs_starting = 18291; + test_msg->procs_stopping = 26469; + + EXPECT_EQ(send_message(0x7f02, 14420, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 14420); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->mem_total, 41916) + << "incorrect value for mem_total, expected 41916, is " + << last_msg_->mem_total; + EXPECT_EQ(last_msg_->pcpu, 211) + << "incorrect value for pcpu, expected 211, is " << last_msg_->pcpu; + EXPECT_EQ(last_msg_->pid_count, 51580) + << "incorrect value for pid_count, expected 51580, is " + << last_msg_->pid_count; + EXPECT_EQ(last_msg_->pmem, 194) + << "incorrect value for pmem, expected 194, is " << last_msg_->pmem; + EXPECT_EQ(last_msg_->procs_starting, 18291) + << "incorrect value for procs_starting, expected 18291, is " + << last_msg_->procs_starting; + EXPECT_EQ(last_msg_->procs_stopping, 26469) + << "incorrect value for procs_stopping, expected 26469, is " + << last_msg_->procs_stopping; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_mag_MsgMagRaw.cc b/c/test/legacy/cpp/auto_check_sbp_mag_MsgMagRaw.cc new file mode 100644 index 0000000000..0bc22684c6 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_mag_MsgMagRaw.cc @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_mag_MsgMagRaw0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_mag_MsgMagRaw0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_mag_raw_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_mag_raw_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_mag_MsgMagRaw0, Test) { + uint8_t encoded_frame[] = { + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, + 206, 98, 3, 230, 2, 110, 229, 159, 23, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_mag_raw_t *test_msg = (msg_mag_raw_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->mag_x = 866; + test_msg->mag_y = 742; + test_msg->mag_z = -6802; + test_msg->tow = 3332301741; + test_msg->tow_f = 206; + + EXPECT_EQ(send_message(0x902, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->mag_x, 866) + << "incorrect value for mag_x, expected 866, is " << last_msg_->mag_x; + EXPECT_EQ(last_msg_->mag_y, 742) + << "incorrect value for mag_y, expected 742, is " << last_msg_->mag_y; + EXPECT_EQ(last_msg_->mag_z, -6802) + << "incorrect value for mag_z, expected -6802, is " << last_msg_->mag_z; + EXPECT_EQ(last_msg_->tow, 3332301741) + << "incorrect value for tow, expected 3332301741, is " << last_msg_->tow; + EXPECT_EQ(last_msg_->tow_f, 206) + << "incorrect value for tow_f, expected 206, is " << last_msg_->tow_f; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc new file mode 100644 index 0000000000..5154f47942 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgBaselineHeadingDepA.cc @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_baseline_heading_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_baseline_heading_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_navigation_MsgBaselineHeadingDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 7, 2, 124, 206, 10, 82, 109, 88, + 176, 68, 14, 82, 203, 186, 58, 173, 182, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_baseline_heading_dep_a_t *test_msg = + (msg_baseline_heading_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 58; + test_msg->heading = 3411152452; + test_msg->n_sats = 186; + test_msg->tow = 2958585170; + + EXPECT_EQ(send_message(0x207, 52860, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 52860); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 58) + << "incorrect value for flags, expected 58, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->heading, 3411152452) + << "incorrect value for heading, expected 3411152452, is " + << last_msg_->heading; + EXPECT_EQ(last_msg_->n_sats, 186) + << "incorrect value for n_sats, expected 186, is " << last_msg_->n_sats; + EXPECT_EQ(last_msg_->tow, 2958585170) + << "incorrect value for tow, expected 2958585170, is " << last_msg_->tow; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc new file mode 100644 index 0000000000..8390514db0 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgPosLlhAcc.cc @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_navigation_MsgPosLlhAcc0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_navigation_MsgPosLlhAcc0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_pos_llh_acc_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_pos_llh_acc_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_navigation_MsgPosLlhAcc0, Test) { + uint8_t encoded_frame[] = { + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, 51, 51, + 139, 189, 64, 154, 153, 153, 153, 25, 151, 192, 64, 51, 51, 51, 51, + 51, 161, 176, 64, 51, 51, 51, 51, 51, 101, 179, 64, 51, 163, 22, + 69, 154, 25, 173, 69, 102, 134, 243, 68, 154, 201, 196, 69, 205, 224, + 0, 70, 51, 35, 72, 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_pos_llh_acc_t *test_msg = (msg_pos_llh_acc_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->at_accuracy = 6297.2001953125; + test_msg->confidence_and_geoid = 95; + test_msg->ct_accuracy = 1948.199951171875; + test_msg->flags = 72; + test_msg->h_accuracy = 2410.199951171875; + test_msg->h_ellipse.orientation = 2550.199951171875; + test_msg->h_ellipse.semi_major = 8248.2001953125; + test_msg->h_ellipse.semi_minor = 3202.199951171875; + test_msg->height = 4257.2; + test_msg->lat = 7563.2; + test_msg->lon = 8494.2; + test_msg->n_sats = 27; + test_msg->orthometric_height = 4965.2; + test_msg->tow = 309229607; + test_msg->v_accuracy = 5539.2001953125; + + EXPECT_EQ(send_message(0x218, 7170, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 7170); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->at_accuracy * 100 - 6297.20019531 * 100), 0.05) + << "incorrect value for at_accuracy, expected 6297.20019531, is " + << last_msg_->at_accuracy; + EXPECT_EQ(last_msg_->confidence_and_geoid, 95) + << "incorrect value for confidence_and_geoid, expected 95, is " + << last_msg_->confidence_and_geoid; + EXPECT_LT((last_msg_->ct_accuracy * 100 - 1948.19995117 * 100), 0.05) + << "incorrect value for ct_accuracy, expected 1948.19995117, is " + << last_msg_->ct_accuracy; + EXPECT_EQ(last_msg_->flags, 72) + << "incorrect value for flags, expected 72, is " << last_msg_->flags; + EXPECT_LT((last_msg_->h_accuracy * 100 - 2410.19995117 * 100), 0.05) + << "incorrect value for h_accuracy, expected 2410.19995117, is " + << last_msg_->h_accuracy; + EXPECT_LT((last_msg_->h_ellipse.orientation * 100 - 2550.19995117 * 100), + 0.05) + << "incorrect value for h_ellipse.orientation, expected 2550.19995117, " + "is " + << last_msg_->h_ellipse.orientation; + EXPECT_LT((last_msg_->h_ellipse.semi_major * 100 - 8248.20019531 * 100), 0.05) + << "incorrect value for h_ellipse.semi_major, expected 8248.20019531, is " + << last_msg_->h_ellipse.semi_major; + EXPECT_LT((last_msg_->h_ellipse.semi_minor * 100 - 3202.19995117 * 100), 0.05) + << "incorrect value for h_ellipse.semi_minor, expected 3202.19995117, is " + << last_msg_->h_ellipse.semi_minor; + EXPECT_LT((last_msg_->height * 100 - 4257.2 * 100), 0.05) + << "incorrect value for height, expected 4257.2, is " + << last_msg_->height; + EXPECT_LT((last_msg_->lat * 100 - 7563.2 * 100), 0.05) + << "incorrect value for lat, expected 7563.2, is " << last_msg_->lat; + EXPECT_LT((last_msg_->lon * 100 - 8494.2 * 100), 0.05) + << "incorrect value for lon, expected 8494.2, is " << last_msg_->lon; + EXPECT_EQ(last_msg_->n_sats, 27) + << "incorrect value for n_sats, expected 27, is " << last_msg_->n_sats; + EXPECT_LT((last_msg_->orthometric_height * 100 - 4965.2 * 100), 0.05) + << "incorrect value for orthometric_height, expected 4965.2, is " + << last_msg_->orthometric_height; + EXPECT_EQ(last_msg_->tow, 309229607) + << "incorrect value for tow, expected 309229607, is " << last_msg_->tow; + EXPECT_LT((last_msg_->v_accuracy * 100 - 5539.20019531 * 100), 0.05) + << "incorrect value for v_accuracy, expected 5539.20019531, is " + << last_msg_->v_accuracy; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc index 5081f44b8b..1084956596 100644 --- a/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc +++ b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevel.cc @@ -23,17 +23,17 @@ class Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0 public sbp::State, public sbp::IReader, public sbp::IWriter, - sbp::PayloadHandler { + sbp::PayloadHandler { public: Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0() : ::testing::Test(), sbp::State(), sbp::IReader(), sbp::IWriter(), - sbp::PayloadHandler(this), + sbp::PayloadHandler(this), last_msg_storage_(), - last_msg_(reinterpret_cast( - last_msg_storage_)), + last_msg_( + reinterpret_cast(last_msg_storage_)), last_msg_len_(), last_sender_id_(), n_callbacks_logged_(), @@ -60,7 +60,7 @@ class Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0 protected: void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, - const msg_protection_level_dep_a_t &msg) override { + const msg_protection_level_t &msg) override { memcpy(last_msg_storage_, &msg, message_length); last_msg_len_ = message_length; last_sender_id_ = sender_id; @@ -68,7 +68,7 @@ class Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0 } uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; - msg_protection_level_dep_a_t *last_msg_; + msg_protection_level_t *last_msg_; uint8_t last_msg_len_; uint16_t last_sender_id_; size_t n_callbacks_logged_; @@ -79,25 +79,41 @@ class Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0 TEST_F(Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0, Test) { uint8_t encoded_frame[] = { - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, + 89, 84, 167, 41, 57, 21, 217, 244, 61, 161, 83, 104, 140, 137, + 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, 153, 153, + 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, + 38, 221, 208, 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, + 235, 227, 183, 160, 187, 93, 116, 224, 105, 40, 32, 33, 133, 188, }; uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; uint8_t test_msg_len = 0; - msg_protection_level_dep_a_t *test_msg = - (msg_protection_level_dep_a_t *)test_msg_storage; + msg_protection_level_t *test_msg = (msg_protection_level_t *)test_msg_storage; test_msg_len = (uint8_t)sizeof(*test_msg); - test_msg->flags = 0; - test_msg->height = 0.0; - test_msg->hpl = 0; - test_msg->lat = 0.0; - test_msg->lon = 0.0; - test_msg->tow = 501867400; - test_msg->vpl = 0; + test_msg->atpl = 10663; + test_msg->ctpl = 5433; + test_msg->flags = 555755625; + test_msg->heading = -529244741; + test_msg->height = 412.2; + test_msg->hopl = 26707; + test_msg->hpl = 41013; + test_msg->hvpl = 62681; + test_msg->lat = 5290.2; + test_msg->lon = 9904.2; + test_msg->pitch = -1598561301; + test_msg->popl = 35212; + test_msg->roll = 1018834477; + test_msg->ropl = 63066; + test_msg->tow = 4060370030; + test_msg->v_x = -584647705; + test_msg->v_y = 1353168848; + test_msg->v_z = -1537140001; + test_msg->vpl = 21593; + test_msg->vvpl = 41277; + test_msg->wn = 13102; - EXPECT_EQ(send_message(0x216, 4096, test_msg_len, test_msg_storage), SBP_OK); + EXPECT_EQ(send_message(0x217, 813, test_msg_len, test_msg_storage), SBP_OK); EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); @@ -107,20 +123,52 @@ TEST_F(Test_legacy_auto_check_sbp_navigation_MsgProtectionLevel0, Test) { } EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, 4096); + EXPECT_EQ(last_sender_id_, 813); EXPECT_EQ(last_msg_len_, test_msg_len); - EXPECT_EQ(last_msg_->flags, 0) - << "incorrect value for flags, expected 0, is " << last_msg_->flags; - EXPECT_LT((last_msg_->height * 100 - 0.0 * 100), 0.05) - << "incorrect value for height, expected 0.0, is " << last_msg_->height; - EXPECT_EQ(last_msg_->hpl, 0) - << "incorrect value for hpl, expected 0, is " << last_msg_->hpl; - EXPECT_LT((last_msg_->lat * 100 - 0.0 * 100), 0.05) - << "incorrect value for lat, expected 0.0, is " << last_msg_->lat; - EXPECT_LT((last_msg_->lon * 100 - 0.0 * 100), 0.05) - << "incorrect value for lon, expected 0.0, is " << last_msg_->lon; - EXPECT_EQ(last_msg_->tow, 501867400) - << "incorrect value for tow, expected 501867400, is " << last_msg_->tow; - EXPECT_EQ(last_msg_->vpl, 0) - << "incorrect value for vpl, expected 0, is " << last_msg_->vpl; + EXPECT_EQ(last_msg_->atpl, 10663) + << "incorrect value for atpl, expected 10663, is " << last_msg_->atpl; + EXPECT_EQ(last_msg_->ctpl, 5433) + << "incorrect value for ctpl, expected 5433, is " << last_msg_->ctpl; + EXPECT_EQ(last_msg_->flags, 555755625) + << "incorrect value for flags, expected 555755625, is " + << last_msg_->flags; + EXPECT_EQ(last_msg_->heading, -529244741) + << "incorrect value for heading, expected -529244741, is " + << last_msg_->heading; + EXPECT_LT((last_msg_->height * 100 - 412.2 * 100), 0.05) + << "incorrect value for height, expected 412.2, is " << last_msg_->height; + EXPECT_EQ(last_msg_->hopl, 26707) + << "incorrect value for hopl, expected 26707, is " << last_msg_->hopl; + EXPECT_EQ(last_msg_->hpl, 41013) + << "incorrect value for hpl, expected 41013, is " << last_msg_->hpl; + EXPECT_EQ(last_msg_->hvpl, 62681) + << "incorrect value for hvpl, expected 62681, is " << last_msg_->hvpl; + EXPECT_LT((last_msg_->lat * 100 - 5290.2 * 100), 0.05) + << "incorrect value for lat, expected 5290.2, is " << last_msg_->lat; + EXPECT_LT((last_msg_->lon * 100 - 9904.2 * 100), 0.05) + << "incorrect value for lon, expected 9904.2, is " << last_msg_->lon; + EXPECT_EQ(last_msg_->pitch, -1598561301) + << "incorrect value for pitch, expected -1598561301, is " + << last_msg_->pitch; + EXPECT_EQ(last_msg_->popl, 35212) + << "incorrect value for popl, expected 35212, is " << last_msg_->popl; + EXPECT_EQ(last_msg_->roll, 1018834477) + << "incorrect value for roll, expected 1018834477, is " + << last_msg_->roll; + EXPECT_EQ(last_msg_->ropl, 63066) + << "incorrect value for ropl, expected 63066, is " << last_msg_->ropl; + EXPECT_EQ(last_msg_->tow, 4060370030) + << "incorrect value for tow, expected 4060370030, is " << last_msg_->tow; + EXPECT_EQ(last_msg_->v_x, -584647705) + << "incorrect value for v_x, expected -584647705, is " << last_msg_->v_x; + EXPECT_EQ(last_msg_->v_y, 1353168848) + << "incorrect value for v_y, expected 1353168848, is " << last_msg_->v_y; + EXPECT_EQ(last_msg_->v_z, -1537140001) + << "incorrect value for v_z, expected -1537140001, is " << last_msg_->v_z; + EXPECT_EQ(last_msg_->vpl, 21593) + << "incorrect value for vpl, expected 21593, is " << last_msg_->vpl; + EXPECT_EQ(last_msg_->vvpl, 41277) + << "incorrect value for vvpl, expected 41277, is " << last_msg_->vvpl; + EXPECT_EQ(last_msg_->wn, 13102) + << "incorrect value for wn, expected 13102, is " << last_msg_->wn; } diff --git a/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc new file mode 100644 index 0000000000..05ee4d54ff --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_navigation_MsgProtectionLevelDepA.cc @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_protection_level_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_protection_level_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_navigation_MsgProtectionLevelDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, + 51, 51, 51, 51, 51, 244, 190, 64, 102, 102, 102, 102, 102, 204, + 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, 81, 104, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_protection_level_dep_a_t *test_msg = + (msg_protection_level_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 248; + test_msg->height = 8270.2; + test_msg->hpl = 35588; + test_msg->lat = 7924.2; + test_msg->lon = 3174.2; + test_msg->tow = 3108339252; + test_msg->vpl = 21807; + + EXPECT_EQ(send_message(0x216, 5780, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 5780); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 248) + << "incorrect value for flags, expected 248, is " << last_msg_->flags; + EXPECT_LT((last_msg_->height * 100 - 8270.2 * 100), 0.05) + << "incorrect value for height, expected 8270.2, is " + << last_msg_->height; + EXPECT_EQ(last_msg_->hpl, 35588) + << "incorrect value for hpl, expected 35588, is " << last_msg_->hpl; + EXPECT_LT((last_msg_->lat * 100 - 7924.2 * 100), 0.05) + << "incorrect value for lat, expected 7924.2, is " << last_msg_->lat; + EXPECT_LT((last_msg_->lon * 100 - 3174.2 * 100), 0.05) + << "incorrect value for lon, expected 3174.2, is " << last_msg_->lon; + EXPECT_EQ(last_msg_->tow, 3108339252) + << "incorrect value for tow, expected 3108339252, is " << last_msg_->tow; + EXPECT_EQ(last_msg_->vpl, 21807) + << "incorrect value for vpl, expected 21807, is " << last_msg_->vpl; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc b/c/test/legacy/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc new file mode 100644 index 0000000000..d3d3c9cdfb --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ndb_MsgNdbEvent.cc @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ndb_MsgNdbEvent0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ndb_MsgNdbEvent0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ndb_event_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ndb_event_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ndb_MsgNdbEvent0, Test) { + uint8_t encoded_frame[] = { + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, + 0, 249, 73, 205, 115, 238, 74, 98, 66, 182, 148, 16, 166, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ndb_event_t *test_msg = (msg_ndb_event_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->data_source = 115; + test_msg->event = 249; + test_msg->object_sid.code = 74; + test_msg->object_sid.sat = 238; + test_msg->object_type = 73; + test_msg->original_sender = 38070; + test_msg->recv_time = 299461164286; + test_msg->result = 205; + test_msg->src_sid.code = 66; + test_msg->src_sid.sat = 98; + + EXPECT_EQ(send_message(0x400, 44708, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 44708); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->data_source, 115) + << "incorrect value for data_source, expected 115, is " + << last_msg_->data_source; + EXPECT_EQ(last_msg_->event, 249) + << "incorrect value for event, expected 249, is " << last_msg_->event; + EXPECT_EQ(last_msg_->object_sid.code, 74) + << "incorrect value for object_sid.code, expected 74, is " + << last_msg_->object_sid.code; + EXPECT_EQ(last_msg_->object_sid.sat, 238) + << "incorrect value for object_sid.sat, expected 238, is " + << last_msg_->object_sid.sat; + EXPECT_EQ(last_msg_->object_type, 73) + << "incorrect value for object_type, expected 73, is " + << last_msg_->object_type; + EXPECT_EQ(last_msg_->original_sender, 38070) + << "incorrect value for original_sender, expected 38070, is " + << last_msg_->original_sender; + EXPECT_EQ(last_msg_->recv_time, 299461164286) + << "incorrect value for recv_time, expected 299461164286, is " + << last_msg_->recv_time; + EXPECT_EQ(last_msg_->result, 205) + << "incorrect value for result, expected 205, is " << last_msg_->result; + EXPECT_EQ(last_msg_->src_sid.code, 66) + << "incorrect value for src_sid.code, expected 66, is " + << last_msg_->src_sid.code; + EXPECT_EQ(last_msg_->src_sid.sat, 98) + << "incorrect value for src_sid.sat, expected 98, is " + << last_msg_->src_sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc new file mode 100644 index 0000000000..ad4deb21b1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLO.cc @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgAlmanacGLO0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgAlmanacGLO0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_almanac_glo_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_almanac_glo_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgAlmanacGLO0, Test) { + uint8_t encoded_frame[] = { + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, 8, 154, + 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, + 191, 71, 11, 217, 147, 145, 228, 237, 63, 155, 87, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_almanac_glo_t *test_msg = (msg_almanac_glo_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->epsilon = -0.9893036629599647; + test_msg->i = 5153.550029754639; + test_msg->lambda_na = -0.02200078842114688; + test_msg->omega = 0.9341514480259797; + test_msg->t = -1.8731818448797617; + test_msg->t_dot = -8.903585155774196e-09; + test_msg->t_lambda_na = 0.007072207052260637; + + EXPECT_EQ(send_message(0x73, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toa.tow, 446384) + << "incorrect value for common.toa.tow, expected 446384, is " + << last_msg_->common.toa.tow; + EXPECT_EQ(last_msg_->common.toa.wn, 2154) + << "incorrect value for common.toa.wn, expected 2154, is " + << last_msg_->common.toa.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.2 * 100), 0.05) + << "incorrect value for common.ura, expected 2.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->epsilon * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for epsilon, expected -0.98930366296, is " + << last_msg_->epsilon; + EXPECT_LT((last_msg_->i * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for i, expected 5153.55002975, is " << last_msg_->i; + EXPECT_LT((last_msg_->lambda_na * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for lambda_na, expected -0.0220007884211, is " + << last_msg_->lambda_na; + EXPECT_LT((last_msg_->omega * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for omega, expected 0.934151448026, is " + << last_msg_->omega; + EXPECT_LT((last_msg_->t * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for t, expected -1.87318184488, is " << last_msg_->t; + EXPECT_LT((last_msg_->t_dot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for t_dot, expected -8.90358515577e-09, is " + << last_msg_->t_dot; + EXPECT_LT((last_msg_->t_lambda_na * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for t_lambda_na, expected 0.00707220705226, is " + << last_msg_->t_lambda_na; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc new file mode 100644 index 0000000000..c8959406c6 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGLODep.cc @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgAlmanacGLODep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgAlmanacGLODep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_almanac_glo_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_almanac_glo_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgAlmanacGLODep0, Test) { + uint8_t encoded_frame[] = { + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, + 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 203, 178, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_almanac_glo_dep_t *test_msg = (msg_almanac_glo_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->epsilon = -0.9893036629599647; + test_msg->i = 5153.550029754639; + test_msg->lambda_na = -0.02200078842114688; + test_msg->omega = 0.9341514480259797; + test_msg->t = -1.8731818448797617; + test_msg->t_dot = -8.903585155774196e-09; + test_msg->t_lambda_na = 0.007072207052260637; + + EXPECT_EQ(send_message(0x71, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.reserved, 0) + << "incorrect value for common.sid.reserved, expected 0, is " + << last_msg_->common.sid.reserved; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toa.tow, 446384) + << "incorrect value for common.toa.tow, expected 446384, is " + << last_msg_->common.toa.tow; + EXPECT_EQ(last_msg_->common.toa.wn, 2154) + << "incorrect value for common.toa.wn, expected 2154, is " + << last_msg_->common.toa.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.2 * 100), 0.05) + << "incorrect value for common.ura, expected 2.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->epsilon * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for epsilon, expected -0.98930366296, is " + << last_msg_->epsilon; + EXPECT_LT((last_msg_->i * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for i, expected 5153.55002975, is " << last_msg_->i; + EXPECT_LT((last_msg_->lambda_na * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for lambda_na, expected -0.0220007884211, is " + << last_msg_->lambda_na; + EXPECT_LT((last_msg_->omega * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for omega, expected 0.934151448026, is " + << last_msg_->omega; + EXPECT_LT((last_msg_->t * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for t, expected -1.87318184488, is " << last_msg_->t; + EXPECT_LT((last_msg_->t_dot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for t_dot, expected -8.90358515577e-09, is " + << last_msg_->t_dot; + EXPECT_LT((last_msg_->t_lambda_na * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for t_lambda_na, expected 0.00707220705226, is " + << last_msg_->t_lambda_na; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc new file mode 100644 index 0000000000..7be8a24e4b --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPS.cc @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgAlmanacGPS0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgAlmanacGPS0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_almanac_gps_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_almanac_gps_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgAlmanacGPS0, Test) { + uint8_t encoded_frame[] = { + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, 8, 154, + 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, + 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, + 191, 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, + 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_almanac_gps_t *test_msg = (msg_almanac_gps_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x72, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toa.tow, 446384) + << "incorrect value for common.toa.tow, expected 446384, is " + << last_msg_->common.toa.tow; + EXPECT_EQ(last_msg_->common.toa.wn, 2154) + << "incorrect value for common.toa.wn, expected 2154, is " + << last_msg_->common.toa.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.2 * 100), 0.05) + << "incorrect value for common.ura, expected 2.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc new file mode 100644 index 0000000000..890d21b7ef --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgAlmanacGPSDep.cc @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_almanac_gps_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_almanac_gps_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgAlmanacGPSDep0, Test) { + uint8_t encoded_frame[] = { + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 154, 153, 153, 153, 153, 153, 1, 64, 64, 56, 0, 0, 1, 0, + 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, + 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, + 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 0, 0, 0, 0, + 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 144, 232, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_almanac_gps_dep_t *test_msg = (msg_almanac_gps_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toa.tow = 446384; + test_msg->common.toa.wn = 2154; + test_msg->common.ura = 2.2; + test_msg->common.valid = 1; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x70, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.reserved, 0) + << "incorrect value for common.sid.reserved, expected 0, is " + << last_msg_->common.sid.reserved; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toa.tow, 446384) + << "incorrect value for common.toa.tow, expected 446384, is " + << last_msg_->common.toa.tow; + EXPECT_EQ(last_msg_->common.toa.wn, 2154) + << "incorrect value for common.toa.wn, expected 2154, is " + << last_msg_->common.toa.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.2 * 100), 0.05) + << "incorrect value for common.ura, expected 2.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc new file mode 100644 index 0000000000..02c74832c9 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgBasePosLLH.cc @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgBasePosLLH0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgBasePosLLH0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_base_pos_llh_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_base_pos_llh_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgBasePosLLH0, Test) { + uint8_t encoded_frame[] = { + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, + 70, 235, 0, 120, 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_base_pos_llh_t *test_msg = (msg_base_pos_llh_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->height = 37.939512310879216; + test_msg->lat = 37.251292578377395; + test_msg->lon = -121.87505609407974; + + EXPECT_EQ(send_message(0x44, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->height * 100 - 37.9395123109 * 100), 0.05) + << "incorrect value for height, expected 37.9395123109, is " + << last_msg_->height; + EXPECT_LT((last_msg_->lat * 100 - 37.2512925784 * 100), 0.05) + << "incorrect value for lat, expected 37.2512925784, is " + << last_msg_->lat; + EXPECT_LT((last_msg_->lon * 100 - -121.875056094 * 100), 0.05) + << "incorrect value for lon, expected -121.875056094, is " + << last_msg_->lon; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc new file mode 100644 index 0000000000..2d1b6c3b3b --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepA.cc @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 242, 84, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_dep_a_t *test_msg = (msg_ephemeris_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->prn = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x1a, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.2 * 100), 0.05) + << "incorrect value for af2, expected 0.2, is " << last_msg_->af2; + EXPECT_LT((last_msg_->c_ic * 100 - 7.45058059692e-09 * 100), 0.05) + << "incorrect value for c_ic, expected 7.45058059692e-09, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - -1.15483999252e-07 * 100), 0.05) + << "incorrect value for c_is, expected -1.15483999252e-07, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 308.625 * 100), 0.05) + << "incorrect value for c_rc, expected 308.625, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - -52.3125 * 100), 0.05) + << "incorrect value for c_rs, expected -52.3125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - -2.74367630482e-06 * 100), 0.05) + << "incorrect value for c_uc, expected -2.74367630482e-06, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 3.1366944313e-06 * 100), 0.05) + << "incorrect value for c_us, expected 3.1366944313e-06, is " + << last_msg_->c_us; + EXPECT_LT((last_msg_->dn * 100 - 5.69452291402e-09 * 100), 0.05) + << "incorrect value for dn, expected 5.69452291402e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_EQ(last_msg_->healthy, 0) + << "incorrect value for healthy, expected 0, is " << last_msg_->healthy; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) + << "incorrect value for inc_dot, expected -4.03588239642e-11, is " + << last_msg_->inc_dot; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_EQ(last_msg_->prn, 22) + << "incorrect value for prn, expected 22, is " << last_msg_->prn; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->tgd * 100 - -1.76951289177e-08 * 100), 0.05) + << "incorrect value for tgd, expected -1.76951289177e-08, is " + << last_msg_->tgd; + EXPECT_LT((last_msg_->toc_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toc_tow, expected 446384.2, is " + << last_msg_->toc_tow; + EXPECT_EQ(last_msg_->toc_wn, 2154) + << "incorrect value for toc_wn, expected 2154, is " << last_msg_->toc_wn; + EXPECT_LT((last_msg_->toe_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toe_tow, expected 446384.2, is " + << last_msg_->toe_tow; + EXPECT_EQ(last_msg_->toe_wn, 2154) + << "incorrect value for toe_wn, expected 2154, is " << last_msg_->toe_wn; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc new file mode 100644 index 0000000000..4c79a32f9a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepC.cc @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisDepC0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisDepC0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_dep_c_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_dep_c_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisDepC0, Test) { + uint8_t encoded_frame[] = { + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 23, 170, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_dep_c_t *test_msg = (msg_ephemeris_dep_c_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->reserved = 0; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x47, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.2 * 100), 0.05) + << "incorrect value for af2, expected 0.2, is " << last_msg_->af2; + EXPECT_LT((last_msg_->c_ic * 100 - 7.45058059692e-09 * 100), 0.05) + << "incorrect value for c_ic, expected 7.45058059692e-09, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - -1.15483999252e-07 * 100), 0.05) + << "incorrect value for c_is, expected -1.15483999252e-07, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 308.625 * 100), 0.05) + << "incorrect value for c_rc, expected 308.625, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - -52.3125 * 100), 0.05) + << "incorrect value for c_rs, expected -52.3125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - -2.74367630482e-06 * 100), 0.05) + << "incorrect value for c_uc, expected -2.74367630482e-06, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 3.1366944313e-06 * 100), 0.05) + << "incorrect value for c_us, expected 3.1366944313e-06, is " + << last_msg_->c_us; + EXPECT_LT((last_msg_->dn * 100 - 5.69452291402e-09 * 100), 0.05) + << "incorrect value for dn, expected 5.69452291402e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_EQ(last_msg_->healthy, 0) + << "incorrect value for healthy, expected 0, is " << last_msg_->healthy; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) + << "incorrect value for inc_dot, expected -4.03588239642e-11, is " + << last_msg_->inc_dot; + EXPECT_EQ(last_msg_->iodc, 45) + << "incorrect value for iodc, expected 45, is " << last_msg_->iodc; + EXPECT_EQ(last_msg_->iode, 45) + << "incorrect value for iode, expected 45, is " << last_msg_->iode; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_EQ(last_msg_->reserved, 0) + << "incorrect value for reserved, expected 0, is " << last_msg_->reserved; + EXPECT_EQ(last_msg_->sid.code, 0) + << "incorrect value for sid.code, expected 0, is " << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.reserved, 0) + << "incorrect value for sid.reserved, expected 0, is " + << last_msg_->sid.reserved; + EXPECT_EQ(last_msg_->sid.sat, 22) + << "incorrect value for sid.sat, expected 22, is " << last_msg_->sid.sat; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->tgd * 100 - -1.76951289177e-08 * 100), 0.05) + << "incorrect value for tgd, expected -1.76951289177e-08, is " + << last_msg_->tgd; + EXPECT_LT((last_msg_->toc_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toc_tow, expected 446384.2, is " + << last_msg_->toc_tow; + EXPECT_EQ(last_msg_->toc_wn, 2154) + << "incorrect value for toc_wn, expected 2154, is " << last_msg_->toc_wn; + EXPECT_LT((last_msg_->toe_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toe_tow, expected 446384.2, is " + << last_msg_->toe_tow; + EXPECT_EQ(last_msg_->toe_wn, 2154) + << "incorrect value for toe_wn, expected 2154, is " << last_msg_->toe_wn; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc new file mode 100644 index 0000000000..993b81f423 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisDepD.cc @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisDepD0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisDepD0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_dep_d_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_dep_d_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisDepD0, Test) { + uint8_t encoded_frame[] = { + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, + 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, 74, 115, 64, + 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, + 62, 0, 0, 0, 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, + 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, 235, 95, + 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, + 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, + 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, + 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, 255, 47, 198, 189, 0, + 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, + 65, 106, 8, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, + 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, 95, 7, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_dep_d_t *test_msg = (msg_ephemeris_dep_d_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.2; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->healthy = 0; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->reserved = 0; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc_tow = 446384.2; + test_msg->toc_wn = 2154; + test_msg->toe_tow = 446384.2; + test_msg->toe_wn = 2154; + test_msg->valid = 1; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x80, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.2 * 100), 0.05) + << "incorrect value for af2, expected 0.2, is " << last_msg_->af2; + EXPECT_LT((last_msg_->c_ic * 100 - 7.45058059692e-09 * 100), 0.05) + << "incorrect value for c_ic, expected 7.45058059692e-09, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - -1.15483999252e-07 * 100), 0.05) + << "incorrect value for c_is, expected -1.15483999252e-07, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 308.625 * 100), 0.05) + << "incorrect value for c_rc, expected 308.625, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - -52.3125 * 100), 0.05) + << "incorrect value for c_rs, expected -52.3125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - -2.74367630482e-06 * 100), 0.05) + << "incorrect value for c_uc, expected -2.74367630482e-06, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 3.1366944313e-06 * 100), 0.05) + << "incorrect value for c_us, expected 3.1366944313e-06, is " + << last_msg_->c_us; + EXPECT_LT((last_msg_->dn * 100 - 5.69452291402e-09 * 100), 0.05) + << "incorrect value for dn, expected 5.69452291402e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_EQ(last_msg_->healthy, 0) + << "incorrect value for healthy, expected 0, is " << last_msg_->healthy; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) + << "incorrect value for inc_dot, expected -4.03588239642e-11, is " + << last_msg_->inc_dot; + EXPECT_EQ(last_msg_->iodc, 45) + << "incorrect value for iodc, expected 45, is " << last_msg_->iodc; + EXPECT_EQ(last_msg_->iode, 45) + << "incorrect value for iode, expected 45, is " << last_msg_->iode; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_EQ(last_msg_->reserved, 0) + << "incorrect value for reserved, expected 0, is " << last_msg_->reserved; + EXPECT_EQ(last_msg_->sid.code, 0) + << "incorrect value for sid.code, expected 0, is " << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.reserved, 0) + << "incorrect value for sid.reserved, expected 0, is " + << last_msg_->sid.reserved; + EXPECT_EQ(last_msg_->sid.sat, 22) + << "incorrect value for sid.sat, expected 22, is " << last_msg_->sid.sat; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->tgd * 100 - -1.76951289177e-08 * 100), 0.05) + << "incorrect value for tgd, expected -1.76951289177e-08, is " + << last_msg_->tgd; + EXPECT_LT((last_msg_->toc_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toc_tow, expected 446384.2, is " + << last_msg_->toc_tow; + EXPECT_EQ(last_msg_->toc_wn, 2154) + << "incorrect value for toc_wn, expected 2154, is " << last_msg_->toc_wn; + EXPECT_LT((last_msg_->toe_tow * 100 - 446384.2 * 100), 0.05) + << "incorrect value for toe_tow, expected 446384.2, is " + << last_msg_->toe_tow; + EXPECT_EQ(last_msg_->toe_wn, 2154) + << "incorrect value for toe_wn, expected 2154, is " << last_msg_->toe_wn; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc new file mode 100644 index 0000000000..d66faac051 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepA.cc @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_glo_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_glo_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepA0, Test) { + uint8_t encoded_frame[] = { + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, 106, + 8, 205, 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, + 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, + 34, 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, + 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, + 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, + 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 202, 238, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_glo_dep_a_t *test_msg = + (msg_ephemeris_glo_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x83, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 2400) + << "incorrect value for common.fit_interval, expected 2400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 3) + << "incorrect value for common.sid.code, expected 3, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.reserved, 0) + << "incorrect value for common.sid.reserved, expected 0, is " + << last_msg_->common.sid.reserved; + EXPECT_EQ(last_msg_->common.sid.sat, 4) + << "incorrect value for common.sid.sat, expected 4, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 443718) + << "incorrect value for common.toe.tow, expected 443718, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 5.2 * 100), 0.05) + << "incorrect value for common.ura, expected 5.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->gamma * 100 - 9.09494701773e-13 * 100), 0.05) + << "incorrect value for gamma, expected 9.09494701773e-13, is " + << last_msg_->gamma; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->tau * 100 - -8.36281105876e-05 * 100), 0.05) + << "incorrect value for tau, expected -8.36281105876e-05, is " + << last_msg_->tau; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc new file mode 100644 index 0000000000..ac88b0656a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepB.cc @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_glo_dep_b_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_glo_dep_b_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepB0, Test) { + uint8_t encoded_frame[] = { + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, + 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, + 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, 46, + 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 122, 127, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_glo_dep_b_t *test_msg = + (msg_ephemeris_glo_dep_b_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x85, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 2400) + << "incorrect value for common.fit_interval, expected 2400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 3) + << "incorrect value for common.sid.code, expected 3, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 4) + << "incorrect value for common.sid.sat, expected 4, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 443718) + << "incorrect value for common.toe.tow, expected 443718, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 5.2 * 100), 0.05) + << "incorrect value for common.ura, expected 5.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->gamma * 100 - 9.09494701773e-13 * 100), 0.05) + << "incorrect value for gamma, expected 9.09494701773e-13, is " + << last_msg_->gamma; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->tau * 100 - -8.36281105876e-05 * 100), 0.05) + << "incorrect value for tau, expected -8.36281105876e-05, is " + << last_msg_->tau; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc new file mode 100644 index 0000000000..1d4f0fedc8 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepC.cc @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_glo_dep_c_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_glo_dep_c_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepC0, Test) { + uint8_t encoded_frame[] = { + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 14, 151, 65, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_glo_dep_c_t *test_msg = + (msg_ephemeris_glo_dep_c_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->d_tau = -2.7939677238464355e-09; + test_msg->fcn = 14; + test_msg->gamma = 9.094947017729282e-13; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x87, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 2400) + << "incorrect value for common.fit_interval, expected 2400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 3) + << "incorrect value for common.sid.code, expected 3, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 4) + << "incorrect value for common.sid.sat, expected 4, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 443718) + << "incorrect value for common.toe.tow, expected 443718, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 5.2 * 100), 0.05) + << "incorrect value for common.ura, expected 5.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->d_tau * 100 - -2.79396772385e-09 * 100), 0.05) + << "incorrect value for d_tau, expected -2.79396772385e-09, is " + << last_msg_->d_tau; + EXPECT_EQ(last_msg_->fcn, 14) + << "incorrect value for fcn, expected 14, is " << last_msg_->fcn; + EXPECT_LT((last_msg_->gamma * 100 - 9.09494701773e-13 * 100), 0.05) + << "incorrect value for gamma, expected 9.09494701773e-13, is " + << last_msg_->gamma; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->tau * 100 - -8.36281105876e-05 * 100), 0.05) + << "incorrect value for tau, expected -8.36281105876e-05, is " + << last_msg_->tau; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc new file mode 100644 index 0000000000..5934d0e409 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGLODepD.cc @@ -0,0 +1,233 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_glo_dep_d_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_glo_dep_d_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGLODepD0, Test) { + uint8_t encoded_frame[] = { + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, 8, 205, + 204, 204, 204, 204, 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, + 0, 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, + 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 112, 199, 62, 14, 100, 82, 64, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_glo_dep_d_t *test_msg = + (msg_ephemeris_glo_dep_d_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 2400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 3; + test_msg->common.sid.sat = 4; + test_msg->common.toe.tow = 443718; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 5.2; + test_msg->common.valid = 1; + test_msg->d_tau = -2.7939677238464355e-09; + test_msg->fcn = 14; + test_msg->gamma = 9.094947017729282e-13; + test_msg->iod = 100; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + test_msg->tau = -8.36281105875969e-05; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x88, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 2400) + << "incorrect value for common.fit_interval, expected 2400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 3) + << "incorrect value for common.sid.code, expected 3, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 4) + << "incorrect value for common.sid.sat, expected 4, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 443718) + << "incorrect value for common.toe.tow, expected 443718, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 5.2 * 100), 0.05) + << "incorrect value for common.ura, expected 5.2, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->d_tau * 100 - -2.79396772385e-09 * 100), 0.05) + << "incorrect value for d_tau, expected -2.79396772385e-09, is " + << last_msg_->d_tau; + EXPECT_EQ(last_msg_->fcn, 14) + << "incorrect value for fcn, expected 14, is " << last_msg_->fcn; + EXPECT_LT((last_msg_->gamma * 100 - 9.09494701773e-13 * 100), 0.05) + << "incorrect value for gamma, expected 9.09494701773e-13, is " + << last_msg_->gamma; + EXPECT_EQ(last_msg_->iod, 100) + << "incorrect value for iod, expected 100, is " << last_msg_->iod; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->tau * 100 - -8.36281105876e-05 * 100), 0.05) + << "incorrect value for tau, expected -8.36281105876e-05, is " + << last_msg_->tau; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc new file mode 100644 index 0000000000..5f06daff2b --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepE.cc @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_gps_dep_e_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_gps_dep_e_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepE0, Test) { + uint8_t encoded_frame[] = { + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, 106, + 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, + 192, 0, 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, + 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, + 49, 117, 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, + 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, + 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, + 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, + 221, 47, 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, + 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, + 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_gps_dep_e_t *test_msg = + (msg_ephemeris_gps_dep_e_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.0; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc.tow = 446384; + test_msg->toc.wn = 2154; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x81, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.0 * 100), 0.05) + << "incorrect value for af2, expected 0.0, is " << last_msg_->af2; + EXPECT_LT((last_msg_->c_ic * 100 - 7.45058059692e-09 * 100), 0.05) + << "incorrect value for c_ic, expected 7.45058059692e-09, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - -1.15483999252e-07 * 100), 0.05) + << "incorrect value for c_is, expected -1.15483999252e-07, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 308.625 * 100), 0.05) + << "incorrect value for c_rc, expected 308.625, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - -52.3125 * 100), 0.05) + << "incorrect value for c_rs, expected -52.3125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - -2.74367630482e-06 * 100), 0.05) + << "incorrect value for c_uc, expected -2.74367630482e-06, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 3.1366944313e-06 * 100), 0.05) + << "incorrect value for c_us, expected 3.1366944313e-06, is " + << last_msg_->c_us; + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.reserved, 0) + << "incorrect value for common.sid.reserved, expected 0, is " + << last_msg_->common.sid.reserved; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 446384) + << "incorrect value for common.toe.tow, expected 446384, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.0 * 100), 0.05) + << "incorrect value for common.ura, expected 2.0, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->dn * 100 - 5.69452291402e-09 * 100), 0.05) + << "incorrect value for dn, expected 5.69452291402e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) + << "incorrect value for inc_dot, expected -4.03588239642e-11, is " + << last_msg_->inc_dot; + EXPECT_EQ(last_msg_->iodc, 45) + << "incorrect value for iodc, expected 45, is " << last_msg_->iodc; + EXPECT_EQ(last_msg_->iode, 45) + << "incorrect value for iode, expected 45, is " << last_msg_->iode; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->tgd * 100 - -1.76951289177e-08 * 100), 0.05) + << "incorrect value for tgd, expected -1.76951289177e-08, is " + << last_msg_->tgd; + EXPECT_EQ(last_msg_->toc.tow, 446384) + << "incorrect value for toc.tow, expected 446384, is " + << last_msg_->toc.tow; + EXPECT_EQ(last_msg_->toc.wn, 2154) + << "incorrect value for toc.wn, expected 2154, is " << last_msg_->toc.wn; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc new file mode 100644 index 0000000000..7fa51091d5 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGPSDepF.cc @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_gps_dep_f_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_gps_dep_f_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGPSDepF0, Test) { + uint8_t encoded_frame[] = { + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, 0, + 0, 0, 0, 0, 0, 0, 64, 64, 56, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, + 0, 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, + 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, 64, + 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, + 56, 62, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, + 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, + 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, + 100, 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, + 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, 0, 0, 0, 0, 0, + 176, 207, 6, 0, 106, 8, 45, 45, 0, 115, 254, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_gps_dep_f_t *test_msg = + (msg_ephemeris_gps_dep_f_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -0.0006315018981695175; + test_msg->af1 = 8.981260180007666e-12; + test_msg->af2 = 0.0; + test_msg->c_ic = 7.450580596923828e-09; + test_msg->c_is = -1.1548399925231934e-07; + test_msg->c_rc = 308.625; + test_msg->c_rs = -52.3125; + test_msg->c_uc = -2.7436763048171997e-06; + test_msg->c_us = 3.1366944313049316e-06; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + test_msg->dn = 5.694522914022375e-09; + test_msg->ecc = 0.007072207052260637; + test_msg->inc = 0.9341514480259797; + test_msg->inc_dot = -4.035882396415757e-11; + test_msg->iodc = 45; + test_msg->iode = 45; + test_msg->m0 = -0.02200078842114688; + test_msg->omega0 = -1.8731818448797617; + test_msg->omegadot = -8.903585155774196e-09; + test_msg->sqrta = 5153.550029754639; + test_msg->tgd = -1.7695128917694092e-08; + test_msg->toc.tow = 446384; + test_msg->toc.wn = 2154; + test_msg->w = -0.9893036629599647; + + EXPECT_EQ(send_message(0x86, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for af0, expected -0.00063150189817, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for af1, expected 8.98126018001e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.0 * 100), 0.05) + << "incorrect value for af2, expected 0.0, is " << last_msg_->af2; + EXPECT_LT((last_msg_->c_ic * 100 - 7.45058059692e-09 * 100), 0.05) + << "incorrect value for c_ic, expected 7.45058059692e-09, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - -1.15483999252e-07 * 100), 0.05) + << "incorrect value for c_is, expected -1.15483999252e-07, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 308.625 * 100), 0.05) + << "incorrect value for c_rc, expected 308.625, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - -52.3125 * 100), 0.05) + << "incorrect value for c_rs, expected -52.3125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - -2.74367630482e-06 * 100), 0.05) + << "incorrect value for c_uc, expected -2.74367630482e-06, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 3.1366944313e-06 * 100), 0.05) + << "incorrect value for c_us, expected 3.1366944313e-06, is " + << last_msg_->c_us; + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 0) + << "incorrect value for common.sid.code, expected 0, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 446384) + << "incorrect value for common.toe.tow, expected 446384, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.0 * 100), 0.05) + << "incorrect value for common.ura, expected 2.0, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->dn * 100 - 5.69452291402e-09 * 100), 0.05) + << "incorrect value for dn, expected 5.69452291402e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.00707220705226 * 100), 0.05) + << "incorrect value for ecc, expected 0.00707220705226, is " + << last_msg_->ecc; + EXPECT_LT((last_msg_->inc * 100 - 0.934151448026 * 100), 0.05) + << "incorrect value for inc, expected 0.934151448026, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -4.03588239642e-11 * 100), 0.05) + << "incorrect value for inc_dot, expected -4.03588239642e-11, is " + << last_msg_->inc_dot; + EXPECT_EQ(last_msg_->iodc, 45) + << "incorrect value for iodc, expected 45, is " << last_msg_->iodc; + EXPECT_EQ(last_msg_->iode, 45) + << "incorrect value for iode, expected 45, is " << last_msg_->iode; + EXPECT_LT((last_msg_->m0 * 100 - -0.0220007884211 * 100), 0.05) + << "incorrect value for m0, expected -0.0220007884211, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - -1.87318184488 * 100), 0.05) + << "incorrect value for omega0, expected -1.87318184488, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -8.90358515577e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -8.90358515577e-09, is " + << last_msg_->omegadot; + EXPECT_LT((last_msg_->sqrta * 100 - 5153.55002975 * 100), 0.05) + << "incorrect value for sqrta, expected 5153.55002975, is " + << last_msg_->sqrta; + EXPECT_LT((last_msg_->tgd * 100 - -1.76951289177e-08 * 100), 0.05) + << "incorrect value for tgd, expected -1.76951289177e-08, is " + << last_msg_->tgd; + EXPECT_EQ(last_msg_->toc.tow, 446384) + << "incorrect value for toc.tow, expected 446384, is " + << last_msg_->toc.tow; + EXPECT_EQ(last_msg_->toc.wn, 2154) + << "incorrect value for toc.wn, expected 2154, is " << last_msg_->toc.wn; + EXPECT_LT((last_msg_->w * 100 - -0.98930366296 * 100), 0.05) + << "incorrect value for w, expected -0.98930366296, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc new file mode 100644 index 0000000000..18c6bb285e --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisGalDepA.cc @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_gal_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_gal_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisGalDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, 102, + 102, 230, 64, 64, 56, 0, 0, 1, 0, 154, 153, 153, 63, 205, 204, + 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, 166, 64, 102, + 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, 217, 204, 130, 105, + 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, + 0, 151, 92, 38, 63, 0, 0, 0, 55, 154, 64, 181, 64, 56, 38, + 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, 186, 56, 190, 80, + 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, 239, 63, + 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, 67, 235, 241, + 190, 255, 255, 255, 255, 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, + 6, 0, 106, 8, 108, 0, 108, 0, 168, 49, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_gal_dep_a_t *test_msg = + (msg_ephemeris_gal_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->af0 = -1.7088896129280325e-05; + test_msg->af1 = -8.185452315956353e-12; + test_msg->af2 = 0.20000000298023224; + test_msg->bgd_e1e5a = 1.2000000476837158; + test_msg->bgd_e1e5b = 2.200000047683716; + test_msg->c_ic = 3.200000047683716; + test_msg->c_is = 4.199999809265137; + test_msg->c_rc = 265.4375; + test_msg->c_rs = 10.125; + test_msg->c_uc = 5.199999809265137; + test_msg->c_us = 6.199999809265137; + test_msg->common.fit_interval = 14400; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 14; + test_msg->common.sid.sat = 27; + test_msg->common.toe.tow = 448800; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 7.199999809265137; + test_msg->common.valid = 1; + test_msg->dn = 3.2262058129932258e-09; + test_msg->ecc = 0.00017060607206076384; + test_msg->inc = 0.9777456094977858; + test_msg->inc_dot = -3.1787038343451465e-10; + test_msg->iodc = 108; + test_msg->iode = 108; + test_msg->m0 = -1.8457115744155868; + test_msg->omega0 = 1.16967730598334; + test_msg->omegadot = -5.757382675240872e-09; + test_msg->sqrta = 5440.602401733398; + test_msg->toc.tow = 448800; + test_msg->toc.wn = 2154; + test_msg->w = 0.12250912091662625; + + EXPECT_EQ(send_message(0x95, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->af0 * 100 - -1.70888961293e-05 * 100), 0.05) + << "incorrect value for af0, expected -1.70888961293e-05, is " + << last_msg_->af0; + EXPECT_LT((last_msg_->af1 * 100 - -8.18545231596e-12 * 100), 0.05) + << "incorrect value for af1, expected -8.18545231596e-12, is " + << last_msg_->af1; + EXPECT_LT((last_msg_->af2 * 100 - 0.20000000298 * 100), 0.05) + << "incorrect value for af2, expected 0.20000000298, is " + << last_msg_->af2; + EXPECT_LT((last_msg_->bgd_e1e5a * 100 - 1.20000004768 * 100), 0.05) + << "incorrect value for bgd_e1e5a, expected 1.20000004768, is " + << last_msg_->bgd_e1e5a; + EXPECT_LT((last_msg_->bgd_e1e5b * 100 - 2.20000004768 * 100), 0.05) + << "incorrect value for bgd_e1e5b, expected 2.20000004768, is " + << last_msg_->bgd_e1e5b; + EXPECT_LT((last_msg_->c_ic * 100 - 3.20000004768 * 100), 0.05) + << "incorrect value for c_ic, expected 3.20000004768, is " + << last_msg_->c_ic; + EXPECT_LT((last_msg_->c_is * 100 - 4.19999980927 * 100), 0.05) + << "incorrect value for c_is, expected 4.19999980927, is " + << last_msg_->c_is; + EXPECT_LT((last_msg_->c_rc * 100 - 265.4375 * 100), 0.05) + << "incorrect value for c_rc, expected 265.4375, is " << last_msg_->c_rc; + EXPECT_LT((last_msg_->c_rs * 100 - 10.125 * 100), 0.05) + << "incorrect value for c_rs, expected 10.125, is " << last_msg_->c_rs; + EXPECT_LT((last_msg_->c_uc * 100 - 5.19999980927 * 100), 0.05) + << "incorrect value for c_uc, expected 5.19999980927, is " + << last_msg_->c_uc; + EXPECT_LT((last_msg_->c_us * 100 - 6.19999980927 * 100), 0.05) + << "incorrect value for c_us, expected 6.19999980927, is " + << last_msg_->c_us; + EXPECT_EQ(last_msg_->common.fit_interval, 14400) + << "incorrect value for common.fit_interval, expected 14400, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 14) + << "incorrect value for common.sid.code, expected 14, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 27) + << "incorrect value for common.sid.sat, expected 27, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 448800) + << "incorrect value for common.toe.tow, expected 448800, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 7.19999980927 * 100), 0.05) + << "incorrect value for common.ura, expected 7.19999980927, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->dn * 100 - 3.22620581299e-09 * 100), 0.05) + << "incorrect value for dn, expected 3.22620581299e-09, is " + << last_msg_->dn; + EXPECT_LT((last_msg_->ecc * 100 - 0.000170606072061 * 100), 0.05) + << "incorrect value for ecc, expected 0.000170606072061, is " + << last_msg_->ecc; + EXPECT_LT((last_msg_->inc * 100 - 0.977745609498 * 100), 0.05) + << "incorrect value for inc, expected 0.977745609498, is " + << last_msg_->inc; + EXPECT_LT((last_msg_->inc_dot * 100 - -3.17870383435e-10 * 100), 0.05) + << "incorrect value for inc_dot, expected -3.17870383435e-10, is " + << last_msg_->inc_dot; + EXPECT_EQ(last_msg_->iodc, 108) + << "incorrect value for iodc, expected 108, is " << last_msg_->iodc; + EXPECT_EQ(last_msg_->iode, 108) + << "incorrect value for iode, expected 108, is " << last_msg_->iode; + EXPECT_LT((last_msg_->m0 * 100 - -1.84571157442 * 100), 0.05) + << "incorrect value for m0, expected -1.84571157442, is " + << last_msg_->m0; + EXPECT_LT((last_msg_->omega0 * 100 - 1.16967730598 * 100), 0.05) + << "incorrect value for omega0, expected 1.16967730598, is " + << last_msg_->omega0; + EXPECT_LT((last_msg_->omegadot * 100 - -5.75738267524e-09 * 100), 0.05) + << "incorrect value for omegadot, expected -5.75738267524e-09, is " + << last_msg_->omegadot; + EXPECT_LT((last_msg_->sqrta * 100 - 5440.60240173 * 100), 0.05) + << "incorrect value for sqrta, expected 5440.60240173, is " + << last_msg_->sqrta; + EXPECT_EQ(last_msg_->toc.tow, 448800) + << "incorrect value for toc.tow, expected 448800, is " + << last_msg_->toc.tow; + EXPECT_EQ(last_msg_->toc.wn, 2154) + << "incorrect value for toc.wn, expected 2154, is " << last_msg_->toc.wn; + EXPECT_LT((last_msg_->w * 100 - 0.122509120917 * 100), 0.05) + << "incorrect value for w, expected 0.122509120917, is " << last_msg_->w; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc new file mode 100644 index 0000000000..c1b6a95b69 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbas.cc @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisSbas0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisSbas0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_sbas_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_sbas_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisSbas0, Test) { + uint8_t encoded_frame[] = { + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, + 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, + 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, + 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, 122, 53, 0, 128, + 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_sbas_t *test_msg = (msg_ephemeris_sbas_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = -2.7939677238464355e-09; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.5062255859375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.614990234375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177490234375; + + EXPECT_EQ(send_message(0x8c, 1219, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1219); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->a_gf0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for a_gf0, expected -0.00063150189817, is " + << last_msg_->a_gf0; + EXPECT_LT((last_msg_->a_gf1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for a_gf1, expected 8.98126018001e-12, is " + << last_msg_->a_gf1; + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 0) + << "incorrect value for common.fit_interval, expected 0, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 6) + << "incorrect value for common.sid.code, expected 6, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 446384) + << "incorrect value for common.toe.tow, expected 446384, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - -2.79396772385e-09 * 100), 0.05) + << "incorrect value for common.ura, expected -2.79396772385e-09, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50622559 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50622559, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61499023 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61499023, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817749023 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817749023, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc new file mode 100644 index 0000000000..3249339ae6 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepA.cc @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_sbas_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_sbas_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, 106, + 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, + 65, 0, 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, + 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, + 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, + 0, 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, + 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 178, 180, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_sbas_dep_a_t *test_msg = + (msg_ephemeris_sbas_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.reserved = 0; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x82, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->a_gf0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for a_gf0, expected -0.00063150189817, is " + << last_msg_->a_gf0; + EXPECT_LT((last_msg_->a_gf1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for a_gf1, expected 8.98126018001e-12, is " + << last_msg_->a_gf1; + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 0) + << "incorrect value for common.fit_interval, expected 0, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 6) + << "incorrect value for common.sid.code, expected 6, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.reserved, 0) + << "incorrect value for common.sid.reserved, expected 0, is " + << last_msg_->common.sid.reserved; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 446384) + << "incorrect value for common.toe.tow, expected 446384, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.0 * 100), 0.05) + << "incorrect value for common.ura, expected 2.0, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc new file mode 100644 index 0000000000..7cc2b1fa3a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgEphemerisSbasDepB.cc @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ephemeris_sbas_dep_b_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ephemeris_sbas_dep_b_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgEphemerisSbasDepB0, Test) { + uint8_t encoded_frame[] = { + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, 0, + 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 1, 0, 0, 0, + 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, + 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, 46, 139, + 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, + 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 145, 104, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ephemeris_sbas_dep_b_t *test_msg = + (msg_ephemeris_sbas_dep_b_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->a_gf0 = -0.0006315018981695175; + test_msg->a_gf1 = 8.981260180007666e-12; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[0] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[1] = 9.313225746154785e-07; + if (sizeof(test_msg->acc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->acc[0])); + } + test_msg->acc[2] = 2.7939677238464355e-06; + test_msg->common.fit_interval = 0; + test_msg->common.health_bits = 0; + test_msg->common.sid.code = 6; + test_msg->common.sid.sat = 22; + test_msg->common.toe.tow = 446384; + test_msg->common.toe.wn = 2154; + test_msg->common.ura = 2.0; + test_msg->common.valid = 1; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[0] = -12177330.078125; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[1] = 599893.06640625; + if (sizeof(test_msg->pos) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->pos[0])); + } + test_msg->pos[2] = -22373708.49609375; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[0] = -1726.506233215332; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[1] = -2542.6149368286133; + if (sizeof(test_msg->vel) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->vel[0])); + } + test_msg->vel[2] = 869.8177337646484; + + EXPECT_EQ(send_message(0x84, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->a_gf0 * 100 - -0.00063150189817 * 100), 0.05) + << "incorrect value for a_gf0, expected -0.00063150189817, is " + << last_msg_->a_gf0; + EXPECT_LT((last_msg_->a_gf1 * 100 - 8.98126018001e-12 * 100), 0.05) + << "incorrect value for a_gf1, expected 8.98126018001e-12, is " + << last_msg_->a_gf1; + EXPECT_LT((last_msg_->acc[0] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[0], expected 9.31322574615e-07, is " + << last_msg_->acc[0]; + EXPECT_LT((last_msg_->acc[1] * 100 - 9.31322574615e-07 * 100), 0.05) + << "incorrect value for acc[1], expected 9.31322574615e-07, is " + << last_msg_->acc[1]; + EXPECT_LT((last_msg_->acc[2] * 100 - 2.79396772385e-06 * 100), 0.05) + << "incorrect value for acc[2], expected 2.79396772385e-06, is " + << last_msg_->acc[2]; + EXPECT_EQ(last_msg_->common.fit_interval, 0) + << "incorrect value for common.fit_interval, expected 0, is " + << last_msg_->common.fit_interval; + EXPECT_EQ(last_msg_->common.health_bits, 0) + << "incorrect value for common.health_bits, expected 0, is " + << last_msg_->common.health_bits; + EXPECT_EQ(last_msg_->common.sid.code, 6) + << "incorrect value for common.sid.code, expected 6, is " + << last_msg_->common.sid.code; + EXPECT_EQ(last_msg_->common.sid.sat, 22) + << "incorrect value for common.sid.sat, expected 22, is " + << last_msg_->common.sid.sat; + EXPECT_EQ(last_msg_->common.toe.tow, 446384) + << "incorrect value for common.toe.tow, expected 446384, is " + << last_msg_->common.toe.tow; + EXPECT_EQ(last_msg_->common.toe.wn, 2154) + << "incorrect value for common.toe.wn, expected 2154, is " + << last_msg_->common.toe.wn; + EXPECT_LT((last_msg_->common.ura * 100 - 2.0 * 100), 0.05) + << "incorrect value for common.ura, expected 2.0, is " + << last_msg_->common.ura; + EXPECT_EQ(last_msg_->common.valid, 1) + << "incorrect value for common.valid, expected 1, is " + << last_msg_->common.valid; + EXPECT_LT((last_msg_->pos[0] * 100 - -12177330.0781 * 100), 0.05) + << "incorrect value for pos[0], expected -12177330.0781, is " + << last_msg_->pos[0]; + EXPECT_LT((last_msg_->pos[1] * 100 - 599893.066406 * 100), 0.05) + << "incorrect value for pos[1], expected 599893.066406, is " + << last_msg_->pos[1]; + EXPECT_LT((last_msg_->pos[2] * 100 - -22373708.4961 * 100), 0.05) + << "incorrect value for pos[2], expected -22373708.4961, is " + << last_msg_->pos[2]; + EXPECT_LT((last_msg_->vel[0] * 100 - -1726.50623322 * 100), 0.05) + << "incorrect value for vel[0], expected -1726.50623322, is " + << last_msg_->vel[0]; + EXPECT_LT((last_msg_->vel[1] * 100 - -2542.61493683 * 100), 0.05) + << "incorrect value for vel[1], expected -2542.61493683, is " + << last_msg_->vel[1]; + EXPECT_LT((last_msg_->vel[2] * 100 - 869.817733765 * 100), 0.05) + << "incorrect value for vel[2], expected 869.817733765, is " + << last_msg_->vel[2]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgGnssCapb.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGnssCapb.cc new file mode 100644 index 0000000000..f241d8fe32 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGnssCapb.cc @@ -0,0 +1,176 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgGnssCapb0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgGnssCapb0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_gnss_capb_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_gnss_capb_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgGnssCapb0, Test) { + uint8_t encoded_frame[] = { + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, + 64, 0, 0, 0, 0, 81, 173, 144, 46, 0, 0, 0, 0, 209, 139, + 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, 240, + 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, + 0, 0, 0, 0, 40, 75, 250, 114, 0, 0, 0, 0, 119, 147, 123, + 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, 116, + 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, + 0, 0, 0, 252, 62, 221, 28, 0, 0, 0, 0, 163, 90, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_gnss_capb_t *test_msg = (msg_gnss_capb_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->gc.bds_active = 1929005864; + test_msg->gc.bds_b2 = 33839445; + test_msg->gc.bds_b2a = 378107113; + test_msg->gc.bds_d2nav = 1367053175; + test_msg->gc.gal_active = 1392028637; + test_msg->gc.gal_e5 = 484261628; + test_msg->gc.glo_active = 13159676; + test_msg->gc.glo_l2of = 824073421; + test_msg->gc.glo_l3 = 404081648; + test_msg->gc.gps_active = 1079028506; + test_msg->gc.gps_l2c = 781233489; + test_msg->gc.gps_l5 = 1818069969; + test_msg->gc.qzss_active = 198929863; + test_msg->gc.sbas_active = 548822484; + test_msg->gc.sbas_l5 = 465576041; + test_msg->t_nmct.tow = 446384; + test_msg->t_nmct.wn = 2154; + + EXPECT_EQ(send_message(0x96, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->gc.bds_active, 1929005864) + << "incorrect value for gc.bds_active, expected 1929005864, is " + << last_msg_->gc.bds_active; + EXPECT_EQ(last_msg_->gc.bds_b2, 33839445) + << "incorrect value for gc.bds_b2, expected 33839445, is " + << last_msg_->gc.bds_b2; + EXPECT_EQ(last_msg_->gc.bds_b2a, 378107113) + << "incorrect value for gc.bds_b2a, expected 378107113, is " + << last_msg_->gc.bds_b2a; + EXPECT_EQ(last_msg_->gc.bds_d2nav, 1367053175) + << "incorrect value for gc.bds_d2nav, expected 1367053175, is " + << last_msg_->gc.bds_d2nav; + EXPECT_EQ(last_msg_->gc.gal_active, 1392028637) + << "incorrect value for gc.gal_active, expected 1392028637, is " + << last_msg_->gc.gal_active; + EXPECT_EQ(last_msg_->gc.gal_e5, 484261628) + << "incorrect value for gc.gal_e5, expected 484261628, is " + << last_msg_->gc.gal_e5; + EXPECT_EQ(last_msg_->gc.glo_active, 13159676) + << "incorrect value for gc.glo_active, expected 13159676, is " + << last_msg_->gc.glo_active; + EXPECT_EQ(last_msg_->gc.glo_l2of, 824073421) + << "incorrect value for gc.glo_l2of, expected 824073421, is " + << last_msg_->gc.glo_l2of; + EXPECT_EQ(last_msg_->gc.glo_l3, 404081648) + << "incorrect value for gc.glo_l3, expected 404081648, is " + << last_msg_->gc.glo_l3; + EXPECT_EQ(last_msg_->gc.gps_active, 1079028506) + << "incorrect value for gc.gps_active, expected 1079028506, is " + << last_msg_->gc.gps_active; + EXPECT_EQ(last_msg_->gc.gps_l2c, 781233489) + << "incorrect value for gc.gps_l2c, expected 781233489, is " + << last_msg_->gc.gps_l2c; + EXPECT_EQ(last_msg_->gc.gps_l5, 1818069969) + << "incorrect value for gc.gps_l5, expected 1818069969, is " + << last_msg_->gc.gps_l5; + EXPECT_EQ(last_msg_->gc.qzss_active, 198929863) + << "incorrect value for gc.qzss_active, expected 198929863, is " + << last_msg_->gc.qzss_active; + EXPECT_EQ(last_msg_->gc.sbas_active, 548822484) + << "incorrect value for gc.sbas_active, expected 548822484, is " + << last_msg_->gc.sbas_active; + EXPECT_EQ(last_msg_->gc.sbas_l5, 465576041) + << "incorrect value for gc.sbas_l5, expected 465576041, is " + << last_msg_->gc.sbas_l5; + EXPECT_EQ(last_msg_->t_nmct.tow, 446384) + << "incorrect value for t_nmct.tow, expected 446384, is " + << last_msg_->t_nmct.tow; + EXPECT_EQ(last_msg_->t_nmct.wn, 2154) + << "incorrect value for t_nmct.wn, expected 2154, is " + << last_msg_->t_nmct.wn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelay.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelay.cc new file mode 100644 index 0000000000..db91586c25 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelay.cc @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgGroupDelay0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgGroupDelay0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_group_delay_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_group_delay_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgGroupDelay0, Test) { + uint8_t encoded_frame[] = { + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, + 22, 0, 1, 254, 253, 165, 255, 237, 23, 2, 201, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_group_delay_t *test_msg = (msg_group_delay_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->sid.code = 0; + test_msg->sid.sat = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + + EXPECT_EQ(send_message(0x94, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->isc_l1ca, -91) + << "incorrect value for isc_l1ca, expected -91, is " + << last_msg_->isc_l1ca; + EXPECT_EQ(last_msg_->isc_l2c, 6125) + << "incorrect value for isc_l2c, expected 6125, is " + << last_msg_->isc_l2c; + EXPECT_EQ(last_msg_->sid.code, 0) + << "incorrect value for sid.code, expected 0, is " << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 22) + << "incorrect value for sid.sat, expected 22, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->t_op.tow, 446384) + << "incorrect value for t_op.tow, expected 446384, is " + << last_msg_->t_op.tow; + EXPECT_EQ(last_msg_->t_op.wn, 2154) + << "incorrect value for t_op.wn, expected 2154, is " + << last_msg_->t_op.wn; + EXPECT_EQ(last_msg_->tgd, -514) + << "incorrect value for tgd, expected -514, is " << last_msg_->tgd; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc new file mode 100644 index 0000000000..ad0a067e6f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepA.cc @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_group_delay_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_group_delay_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, + 8, 22, 1, 254, 253, 165, 255, 237, 23, 162, 91, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_group_delay_dep_a_t *test_msg = + (msg_group_delay_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->prn = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + + EXPECT_EQ(send_message(0x92, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->isc_l1ca, -91) + << "incorrect value for isc_l1ca, expected -91, is " + << last_msg_->isc_l1ca; + EXPECT_EQ(last_msg_->isc_l2c, 6125) + << "incorrect value for isc_l2c, expected 6125, is " + << last_msg_->isc_l2c; + EXPECT_EQ(last_msg_->prn, 22) + << "incorrect value for prn, expected 22, is " << last_msg_->prn; + EXPECT_EQ(last_msg_->t_op.tow, 446384) + << "incorrect value for t_op.tow, expected 446384, is " + << last_msg_->t_op.tow; + EXPECT_EQ(last_msg_->t_op.wn, 2154) + << "incorrect value for t_op.wn, expected 2154, is " + << last_msg_->t_op.wn; + EXPECT_EQ(last_msg_->tgd, -514) + << "incorrect value for tgd, expected -514, is " << last_msg_->tgd; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc new file mode 100644 index 0000000000..06f694f245 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgGroupDelayDepB.cc @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepB0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepB0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_group_delay_dep_b_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_group_delay_dep_b_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgGroupDelayDepB0, Test) { + uint8_t encoded_frame[] = { + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, + 0, 0, 0, 1, 254, 253, 165, 255, 237, 23, 221, 202, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_group_delay_dep_b_t *test_msg = + (msg_group_delay_dep_b_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->isc_l1ca = -91; + test_msg->isc_l2c = 6125; + test_msg->sid.code = 0; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 22; + test_msg->t_op.tow = 446384; + test_msg->t_op.wn = 2154; + test_msg->tgd = -514; + test_msg->valid = 1; + + EXPECT_EQ(send_message(0x93, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->isc_l1ca, -91) + << "incorrect value for isc_l1ca, expected -91, is " + << last_msg_->isc_l1ca; + EXPECT_EQ(last_msg_->isc_l2c, 6125) + << "incorrect value for isc_l2c, expected 6125, is " + << last_msg_->isc_l2c; + EXPECT_EQ(last_msg_->sid.code, 0) + << "incorrect value for sid.code, expected 0, is " << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.reserved, 0) + << "incorrect value for sid.reserved, expected 0, is " + << last_msg_->sid.reserved; + EXPECT_EQ(last_msg_->sid.sat, 22) + << "incorrect value for sid.sat, expected 22, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->t_op.tow, 446384) + << "incorrect value for t_op.tow, expected 446384, is " + << last_msg_->t_op.tow; + EXPECT_EQ(last_msg_->t_op.wn, 2154) + << "incorrect value for t_op.wn, expected 2154, is " + << last_msg_->t_op.wn; + EXPECT_EQ(last_msg_->tgd, -514) + << "incorrect value for tgd, expected -514, is " << last_msg_->tgd; + EXPECT_EQ(last_msg_->valid, 1) + << "incorrect value for valid, expected 1, is " << last_msg_->valid; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgIono.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgIono.cc new file mode 100644 index 0000000000..4ff2f3808f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgIono.cc @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgIono0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgIono0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_iono_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_iono_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgIono0, Test) { + uint8_t encoded_frame[] = { + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, 80, 62, 0, 0, 0, 0, + 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, + 0, 0, 243, 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, + 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, 101, 31, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_iono_t *test_msg = (msg_iono_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->a0 = 4.6566128730773926e-09; + test_msg->a1 = 1.4901161193847656e-08; + test_msg->a2 = -5.960464477539063e-08; + test_msg->a3 = -5.960464477539063e-08; + test_msg->b0 = 77824.0; + test_msg->b1 = 49152.0; + test_msg->b2 = -65536.0; + test_msg->b3 = -327680.0; + test_msg->t_nmct.tow = 0; + test_msg->t_nmct.wn = 0; + + EXPECT_EQ(send_message(0x90, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->a0 * 100 - 4.65661287308e-09 * 100), 0.05) + << "incorrect value for a0, expected 4.65661287308e-09, is " + << last_msg_->a0; + EXPECT_LT((last_msg_->a1 * 100 - 1.49011611938e-08 * 100), 0.05) + << "incorrect value for a1, expected 1.49011611938e-08, is " + << last_msg_->a1; + EXPECT_LT((last_msg_->a2 * 100 - -5.96046447754e-08 * 100), 0.05) + << "incorrect value for a2, expected -5.96046447754e-08, is " + << last_msg_->a2; + EXPECT_LT((last_msg_->a3 * 100 - -5.96046447754e-08 * 100), 0.05) + << "incorrect value for a3, expected -5.96046447754e-08, is " + << last_msg_->a3; + EXPECT_LT((last_msg_->b0 * 100 - 77824.0 * 100), 0.05) + << "incorrect value for b0, expected 77824.0, is " << last_msg_->b0; + EXPECT_LT((last_msg_->b1 * 100 - 49152.0 * 100), 0.05) + << "incorrect value for b1, expected 49152.0, is " << last_msg_->b1; + EXPECT_LT((last_msg_->b2 * 100 - -65536.0 * 100), 0.05) + << "incorrect value for b2, expected -65536.0, is " << last_msg_->b2; + EXPECT_LT((last_msg_->b3 * 100 - -327680.0 * 100), 0.05) + << "incorrect value for b3, expected -327680.0, is " << last_msg_->b3; + EXPECT_EQ(last_msg_->t_nmct.tow, 0) + << "incorrect value for t_nmct.tow, expected 0, is " + << last_msg_->t_nmct.tow; + EXPECT_EQ(last_msg_->t_nmct.wn, 0) + << "incorrect value for t_nmct.wn, expected 0, is " + << last_msg_->t_nmct.wn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc b/c/test/legacy/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc new file mode 100644 index 0000000000..1832697c45 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_observation_MsgSvConfigurationGpsDep.cc @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_sv_configuration_gps_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_sv_configuration_gps_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_observation_MsgSvConfigurationGpsDep0, Test) { + uint8_t encoded_frame[] = { + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_sv_configuration_gps_dep_t *test_msg = + (msg_sv_configuration_gps_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->l2c_mask = 2808462402; + test_msg->t_nmct.tow = 0; + test_msg->t_nmct.wn = 0; + + EXPECT_EQ(send_message(0x91, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->l2c_mask, 2808462402) + << "incorrect value for l2c_mask, expected 2808462402, is " + << last_msg_->l2c_mask; + EXPECT_EQ(last_msg_->t_nmct.tow, 0) + << "incorrect value for t_nmct.tow, expected 0, is " + << last_msg_->t_nmct.tow; + EXPECT_EQ(last_msg_->t_nmct.wn, 0) + << "incorrect value for t_nmct.wn, expected 0, is " + << last_msg_->t_nmct.wn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc b/c/test/legacy/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc new file mode 100644 index 0000000000..897662bb54 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_orientation_MsgBaselineHeading.cc @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_orientation_MsgBaselineHeading0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_orientation_MsgBaselineHeading0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_baseline_heading_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_baseline_heading_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_orientation_MsgBaselineHeading0, Test) { + uint8_t encoded_frame[] = { + 85, 15, 2, 211, 93, 10, 156, 45, 13, + 196, 44, 84, 197, 61, 91, 91, 224, 254, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_baseline_heading_t *test_msg = (msg_baseline_heading_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 91; + test_msg->heading = 1036342316; + test_msg->n_sats = 91; + test_msg->tow = 3289197980; + + EXPECT_EQ(send_message(0x20f, 24019, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 24019); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 91) + << "incorrect value for flags, expected 91, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->heading, 1036342316) + << "incorrect value for heading, expected 1036342316, is " + << last_msg_->heading; + EXPECT_EQ(last_msg_->n_sats, 91) + << "incorrect value for n_sats, expected 91, is " << last_msg_->n_sats; + EXPECT_EQ(last_msg_->tow, 3289197980) + << "incorrect value for tow, expected 3289197980, is " << last_msg_->tow; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgAlmanac.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgAlmanac.cc new file mode 100644 index 0000000000..1f96674098 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgAlmanac.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc new file mode 100644 index 0000000000..5ce988e0ce --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCellModemStatus.cc @@ -0,0 +1,2128 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgCellModemStatus0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgCellModemStatus0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_cell_modem_status_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_cell_modem_status_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgCellModemStatus0, Test) { + uint8_t encoded_frame[] = { + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, 52, + 64, 176, 154, 98, 43, 132, 196, 89, 253, 161, 250, 174, 204, 110, 47, + 38, 187, 63, 102, 177, 162, 49, 80, 194, 37, 107, 60, 225, 52, 101, + 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, 80, 243, 30, 206, + 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, 85, 146, 100, 190, 232, + 207, 61, 61, 201, 220, 31, 78, 34, 57, 82, 59, 104, 65, 221, 0, + 43, 210, 9, 32, 122, 29, 237, 11, 151, 223, 18, 81, 204, 172, 234, + 127, 3, 82, 133, 169, 12, 176, 193, 0, 24, 121, 85, 55, 214, 198, + 75, 234, 179, 214, 85, 94, 115, 21, 73, 121, 75, 46, 158, 63, 100, + 122, 213, 20, 85, 212, 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, + 39, 164, 5, 175, 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, + 177, 0, 47, 140, 33, 126, 221, 110, 144, 97, 74, 250, 181, 199, 27, + 176, 65, 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, 4, 90, 36, + 7, 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, + 83, 16, 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, 141, + 232, 33, 101, 231, 38, 75, 178, 243, 119, 1, 248, 218, 86, 7, 88, + 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, 156, 217, 67, 239, 219, + 31, 224, 176, 129, 81, 80, 40, 230, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_cell_modem_status_t *test_msg = + (msg_cell_modem_status_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[0] = 123; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[1] = 242; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[2] = 46; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[3] = 52; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[4] = 64; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[5] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[6] = 154; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[7] = 98; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[8] = 43; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[9] = 132; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[10] = 196; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[11] = 89; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[12] = 253; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[13] = 161; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[14] = 250; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[15] = 174; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[16] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[17] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[18] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[19] = 38; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[20] = 187; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[21] = 63; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[22] = 102; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[23] = 177; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[24] = 162; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[25] = 49; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[26] = 80; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[27] = 194; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[28] = 37; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[29] = 107; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[30] = 60; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[31] = 225; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[32] = 52; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[33] = 101; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[34] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[35] = 142; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[36] = 246; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[37] = 21; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[38] = 17; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[39] = 93; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[40] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[41] = 169; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[42] = 86; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[43] = 16; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[44] = 209; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[45] = 80; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[46] = 243; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[47] = 30; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[48] = 206; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[49] = 220; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[50] = 206; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[51] = 115; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[52] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[53] = 154; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[54] = 91; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[55] = 227; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[56] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[57] = 11; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[58] = 1; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[59] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[60] = 146; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[61] = 100; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[62] = 190; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[63] = 232; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[64] = 207; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[65] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[66] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[67] = 201; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[68] = 220; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[69] = 31; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[70] = 78; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[71] = 34; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[72] = 57; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[73] = 82; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[74] = 59; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[75] = 104; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[76] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[77] = 221; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[78] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[79] = 43; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[80] = 210; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[81] = 9; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[82] = 32; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[83] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[84] = 29; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[85] = 237; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[86] = 11; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[87] = 151; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[88] = 223; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[89] = 18; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[90] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[91] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[92] = 172; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[93] = 234; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[94] = 127; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[95] = 3; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[96] = 82; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[97] = 133; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[98] = 169; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[99] = 12; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[100] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[101] = 193; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[102] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[103] = 24; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[104] = 121; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[105] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[106] = 55; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[107] = 214; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[108] = 198; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[109] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[110] = 234; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[111] = 179; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[112] = 214; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[113] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[114] = 94; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[115] = 115; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[116] = 21; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[117] = 73; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[118] = 121; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[119] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[120] = 46; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[121] = 158; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[122] = 63; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[123] = 100; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[124] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[125] = 213; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[126] = 20; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[127] = 85; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[128] = 212; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[129] = 131; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[130] = 50; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[131] = 224; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[132] = 218; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[133] = 215; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[134] = 215; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[135] = 149; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[136] = 2; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[137] = 19; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[138] = 129; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[139] = 39; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[140] = 164; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[141] = 5; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[142] = 175; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[143] = 6; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[144] = 62; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[145] = 51; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[146] = 78; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[147] = 66; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[148] = 248; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[149] = 116; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[150] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[151] = 90; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[152] = 128; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[153] = 226; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[154] = 177; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[155] = 0; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[156] = 47; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[157] = 140; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[158] = 33; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[159] = 126; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[160] = 221; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[161] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[162] = 144; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[163] = 97; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[164] = 74; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[165] = 250; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[166] = 181; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[167] = 199; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[168] = 27; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[169] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[170] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[171] = 185; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[172] = 110; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[173] = 92; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[174] = 34; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[175] = 44; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[176] = 131; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[177] = 96; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[178] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[179] = 40; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[180] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[181] = 4; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[182] = 90; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[183] = 36; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[184] = 7; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[185] = 180; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[186] = 244; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[187] = 244; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[188] = 23; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[189] = 108; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[190] = 171; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[191] = 204; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[192] = 196; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[193] = 61; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[194] = 51; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[195] = 179; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[196] = 242; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[197] = 156; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[198] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[199] = 83; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[200] = 16; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[201] = 15; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[202] = 134; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[203] = 40; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[204] = 245; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[205] = 253; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[206] = 150; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[207] = 94; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[208] = 150; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[209] = 144; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[210] = 197; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[211] = 113; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[212] = 5; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[213] = 141; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[214] = 232; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[215] = 33; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[216] = 101; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[217] = 231; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[218] = 38; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[219] = 75; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[220] = 178; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[221] = 243; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[222] = 119; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[223] = 1; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[224] = 248; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[225] = 218; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[226] = 86; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[227] = 7; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[228] = 88; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[229] = 197; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[230] = 148; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[231] = 240; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[232] = 227; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[233] = 2; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[234] = 65; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[235] = 173; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[236] = 122; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[237] = 143; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[238] = 251; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[239] = 156; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[240] = 217; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[241] = 67; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[242] = 239; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[243] = 219; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[244] = 31; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[245] = 224; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[246] = 176; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[247] = 129; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[248] = 81; + if (sizeof(test_msg->reserved) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->reserved[0])); + } + test_msg->reserved[249] = 80; + test_msg->signal_error_rate = 8588.2001953125; + test_msg->signal_strength = 103; + + EXPECT_EQ(send_message(0xbe, 6931, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 6931); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->reserved[0], 123) + << "incorrect value for reserved[0], expected 123, is " + << last_msg_->reserved[0]; + EXPECT_EQ(last_msg_->reserved[1], 242) + << "incorrect value for reserved[1], expected 242, is " + << last_msg_->reserved[1]; + EXPECT_EQ(last_msg_->reserved[2], 46) + << "incorrect value for reserved[2], expected 46, is " + << last_msg_->reserved[2]; + EXPECT_EQ(last_msg_->reserved[3], 52) + << "incorrect value for reserved[3], expected 52, is " + << last_msg_->reserved[3]; + EXPECT_EQ(last_msg_->reserved[4], 64) + << "incorrect value for reserved[4], expected 64, is " + << last_msg_->reserved[4]; + EXPECT_EQ(last_msg_->reserved[5], 176) + << "incorrect value for reserved[5], expected 176, is " + << last_msg_->reserved[5]; + EXPECT_EQ(last_msg_->reserved[6], 154) + << "incorrect value for reserved[6], expected 154, is " + << last_msg_->reserved[6]; + EXPECT_EQ(last_msg_->reserved[7], 98) + << "incorrect value for reserved[7], expected 98, is " + << last_msg_->reserved[7]; + EXPECT_EQ(last_msg_->reserved[8], 43) + << "incorrect value for reserved[8], expected 43, is " + << last_msg_->reserved[8]; + EXPECT_EQ(last_msg_->reserved[9], 132) + << "incorrect value for reserved[9], expected 132, is " + << last_msg_->reserved[9]; + EXPECT_EQ(last_msg_->reserved[10], 196) + << "incorrect value for reserved[10], expected 196, is " + << last_msg_->reserved[10]; + EXPECT_EQ(last_msg_->reserved[11], 89) + << "incorrect value for reserved[11], expected 89, is " + << last_msg_->reserved[11]; + EXPECT_EQ(last_msg_->reserved[12], 253) + << "incorrect value for reserved[12], expected 253, is " + << last_msg_->reserved[12]; + EXPECT_EQ(last_msg_->reserved[13], 161) + << "incorrect value for reserved[13], expected 161, is " + << last_msg_->reserved[13]; + EXPECT_EQ(last_msg_->reserved[14], 250) + << "incorrect value for reserved[14], expected 250, is " + << last_msg_->reserved[14]; + EXPECT_EQ(last_msg_->reserved[15], 174) + << "incorrect value for reserved[15], expected 174, is " + << last_msg_->reserved[15]; + EXPECT_EQ(last_msg_->reserved[16], 204) + << "incorrect value for reserved[16], expected 204, is " + << last_msg_->reserved[16]; + EXPECT_EQ(last_msg_->reserved[17], 110) + << "incorrect value for reserved[17], expected 110, is " + << last_msg_->reserved[17]; + EXPECT_EQ(last_msg_->reserved[18], 47) + << "incorrect value for reserved[18], expected 47, is " + << last_msg_->reserved[18]; + EXPECT_EQ(last_msg_->reserved[19], 38) + << "incorrect value for reserved[19], expected 38, is " + << last_msg_->reserved[19]; + EXPECT_EQ(last_msg_->reserved[20], 187) + << "incorrect value for reserved[20], expected 187, is " + << last_msg_->reserved[20]; + EXPECT_EQ(last_msg_->reserved[21], 63) + << "incorrect value for reserved[21], expected 63, is " + << last_msg_->reserved[21]; + EXPECT_EQ(last_msg_->reserved[22], 102) + << "incorrect value for reserved[22], expected 102, is " + << last_msg_->reserved[22]; + EXPECT_EQ(last_msg_->reserved[23], 177) + << "incorrect value for reserved[23], expected 177, is " + << last_msg_->reserved[23]; + EXPECT_EQ(last_msg_->reserved[24], 162) + << "incorrect value for reserved[24], expected 162, is " + << last_msg_->reserved[24]; + EXPECT_EQ(last_msg_->reserved[25], 49) + << "incorrect value for reserved[25], expected 49, is " + << last_msg_->reserved[25]; + EXPECT_EQ(last_msg_->reserved[26], 80) + << "incorrect value for reserved[26], expected 80, is " + << last_msg_->reserved[26]; + EXPECT_EQ(last_msg_->reserved[27], 194) + << "incorrect value for reserved[27], expected 194, is " + << last_msg_->reserved[27]; + EXPECT_EQ(last_msg_->reserved[28], 37) + << "incorrect value for reserved[28], expected 37, is " + << last_msg_->reserved[28]; + EXPECT_EQ(last_msg_->reserved[29], 107) + << "incorrect value for reserved[29], expected 107, is " + << last_msg_->reserved[29]; + EXPECT_EQ(last_msg_->reserved[30], 60) + << "incorrect value for reserved[30], expected 60, is " + << last_msg_->reserved[30]; + EXPECT_EQ(last_msg_->reserved[31], 225) + << "incorrect value for reserved[31], expected 225, is " + << last_msg_->reserved[31]; + EXPECT_EQ(last_msg_->reserved[32], 52) + << "incorrect value for reserved[32], expected 52, is " + << last_msg_->reserved[32]; + EXPECT_EQ(last_msg_->reserved[33], 101) + << "incorrect value for reserved[33], expected 101, is " + << last_msg_->reserved[33]; + EXPECT_EQ(last_msg_->reserved[34], 178) + << "incorrect value for reserved[34], expected 178, is " + << last_msg_->reserved[34]; + EXPECT_EQ(last_msg_->reserved[35], 142) + << "incorrect value for reserved[35], expected 142, is " + << last_msg_->reserved[35]; + EXPECT_EQ(last_msg_->reserved[36], 246) + << "incorrect value for reserved[36], expected 246, is " + << last_msg_->reserved[36]; + EXPECT_EQ(last_msg_->reserved[37], 21) + << "incorrect value for reserved[37], expected 21, is " + << last_msg_->reserved[37]; + EXPECT_EQ(last_msg_->reserved[38], 17) + << "incorrect value for reserved[38], expected 17, is " + << last_msg_->reserved[38]; + EXPECT_EQ(last_msg_->reserved[39], 93) + << "incorrect value for reserved[39], expected 93, is " + << last_msg_->reserved[39]; + EXPECT_EQ(last_msg_->reserved[40], 75) + << "incorrect value for reserved[40], expected 75, is " + << last_msg_->reserved[40]; + EXPECT_EQ(last_msg_->reserved[41], 169) + << "incorrect value for reserved[41], expected 169, is " + << last_msg_->reserved[41]; + EXPECT_EQ(last_msg_->reserved[42], 86) + << "incorrect value for reserved[42], expected 86, is " + << last_msg_->reserved[42]; + EXPECT_EQ(last_msg_->reserved[43], 16) + << "incorrect value for reserved[43], expected 16, is " + << last_msg_->reserved[43]; + EXPECT_EQ(last_msg_->reserved[44], 209) + << "incorrect value for reserved[44], expected 209, is " + << last_msg_->reserved[44]; + EXPECT_EQ(last_msg_->reserved[45], 80) + << "incorrect value for reserved[45], expected 80, is " + << last_msg_->reserved[45]; + EXPECT_EQ(last_msg_->reserved[46], 243) + << "incorrect value for reserved[46], expected 243, is " + << last_msg_->reserved[46]; + EXPECT_EQ(last_msg_->reserved[47], 30) + << "incorrect value for reserved[47], expected 30, is " + << last_msg_->reserved[47]; + EXPECT_EQ(last_msg_->reserved[48], 206) + << "incorrect value for reserved[48], expected 206, is " + << last_msg_->reserved[48]; + EXPECT_EQ(last_msg_->reserved[49], 220) + << "incorrect value for reserved[49], expected 220, is " + << last_msg_->reserved[49]; + EXPECT_EQ(last_msg_->reserved[50], 206) + << "incorrect value for reserved[50], expected 206, is " + << last_msg_->reserved[50]; + EXPECT_EQ(last_msg_->reserved[51], 115) + << "incorrect value for reserved[51], expected 115, is " + << last_msg_->reserved[51]; + EXPECT_EQ(last_msg_->reserved[52], 47) + << "incorrect value for reserved[52], expected 47, is " + << last_msg_->reserved[52]; + EXPECT_EQ(last_msg_->reserved[53], 154) + << "incorrect value for reserved[53], expected 154, is " + << last_msg_->reserved[53]; + EXPECT_EQ(last_msg_->reserved[54], 91) + << "incorrect value for reserved[54], expected 91, is " + << last_msg_->reserved[54]; + EXPECT_EQ(last_msg_->reserved[55], 227) + << "incorrect value for reserved[55], expected 227, is " + << last_msg_->reserved[55]; + EXPECT_EQ(last_msg_->reserved[56], 88) + << "incorrect value for reserved[56], expected 88, is " + << last_msg_->reserved[56]; + EXPECT_EQ(last_msg_->reserved[57], 11) + << "incorrect value for reserved[57], expected 11, is " + << last_msg_->reserved[57]; + EXPECT_EQ(last_msg_->reserved[58], 1) + << "incorrect value for reserved[58], expected 1, is " + << last_msg_->reserved[58]; + EXPECT_EQ(last_msg_->reserved[59], 85) + << "incorrect value for reserved[59], expected 85, is " + << last_msg_->reserved[59]; + EXPECT_EQ(last_msg_->reserved[60], 146) + << "incorrect value for reserved[60], expected 146, is " + << last_msg_->reserved[60]; + EXPECT_EQ(last_msg_->reserved[61], 100) + << "incorrect value for reserved[61], expected 100, is " + << last_msg_->reserved[61]; + EXPECT_EQ(last_msg_->reserved[62], 190) + << "incorrect value for reserved[62], expected 190, is " + << last_msg_->reserved[62]; + EXPECT_EQ(last_msg_->reserved[63], 232) + << "incorrect value for reserved[63], expected 232, is " + << last_msg_->reserved[63]; + EXPECT_EQ(last_msg_->reserved[64], 207) + << "incorrect value for reserved[64], expected 207, is " + << last_msg_->reserved[64]; + EXPECT_EQ(last_msg_->reserved[65], 61) + << "incorrect value for reserved[65], expected 61, is " + << last_msg_->reserved[65]; + EXPECT_EQ(last_msg_->reserved[66], 61) + << "incorrect value for reserved[66], expected 61, is " + << last_msg_->reserved[66]; + EXPECT_EQ(last_msg_->reserved[67], 201) + << "incorrect value for reserved[67], expected 201, is " + << last_msg_->reserved[67]; + EXPECT_EQ(last_msg_->reserved[68], 220) + << "incorrect value for reserved[68], expected 220, is " + << last_msg_->reserved[68]; + EXPECT_EQ(last_msg_->reserved[69], 31) + << "incorrect value for reserved[69], expected 31, is " + << last_msg_->reserved[69]; + EXPECT_EQ(last_msg_->reserved[70], 78) + << "incorrect value for reserved[70], expected 78, is " + << last_msg_->reserved[70]; + EXPECT_EQ(last_msg_->reserved[71], 34) + << "incorrect value for reserved[71], expected 34, is " + << last_msg_->reserved[71]; + EXPECT_EQ(last_msg_->reserved[72], 57) + << "incorrect value for reserved[72], expected 57, is " + << last_msg_->reserved[72]; + EXPECT_EQ(last_msg_->reserved[73], 82) + << "incorrect value for reserved[73], expected 82, is " + << last_msg_->reserved[73]; + EXPECT_EQ(last_msg_->reserved[74], 59) + << "incorrect value for reserved[74], expected 59, is " + << last_msg_->reserved[74]; + EXPECT_EQ(last_msg_->reserved[75], 104) + << "incorrect value for reserved[75], expected 104, is " + << last_msg_->reserved[75]; + EXPECT_EQ(last_msg_->reserved[76], 65) + << "incorrect value for reserved[76], expected 65, is " + << last_msg_->reserved[76]; + EXPECT_EQ(last_msg_->reserved[77], 221) + << "incorrect value for reserved[77], expected 221, is " + << last_msg_->reserved[77]; + EXPECT_EQ(last_msg_->reserved[78], 0) + << "incorrect value for reserved[78], expected 0, is " + << last_msg_->reserved[78]; + EXPECT_EQ(last_msg_->reserved[79], 43) + << "incorrect value for reserved[79], expected 43, is " + << last_msg_->reserved[79]; + EXPECT_EQ(last_msg_->reserved[80], 210) + << "incorrect value for reserved[80], expected 210, is " + << last_msg_->reserved[80]; + EXPECT_EQ(last_msg_->reserved[81], 9) + << "incorrect value for reserved[81], expected 9, is " + << last_msg_->reserved[81]; + EXPECT_EQ(last_msg_->reserved[82], 32) + << "incorrect value for reserved[82], expected 32, is " + << last_msg_->reserved[82]; + EXPECT_EQ(last_msg_->reserved[83], 122) + << "incorrect value for reserved[83], expected 122, is " + << last_msg_->reserved[83]; + EXPECT_EQ(last_msg_->reserved[84], 29) + << "incorrect value for reserved[84], expected 29, is " + << last_msg_->reserved[84]; + EXPECT_EQ(last_msg_->reserved[85], 237) + << "incorrect value for reserved[85], expected 237, is " + << last_msg_->reserved[85]; + EXPECT_EQ(last_msg_->reserved[86], 11) + << "incorrect value for reserved[86], expected 11, is " + << last_msg_->reserved[86]; + EXPECT_EQ(last_msg_->reserved[87], 151) + << "incorrect value for reserved[87], expected 151, is " + << last_msg_->reserved[87]; + EXPECT_EQ(last_msg_->reserved[88], 223) + << "incorrect value for reserved[88], expected 223, is " + << last_msg_->reserved[88]; + EXPECT_EQ(last_msg_->reserved[89], 18) + << "incorrect value for reserved[89], expected 18, is " + << last_msg_->reserved[89]; + EXPECT_EQ(last_msg_->reserved[90], 81) + << "incorrect value for reserved[90], expected 81, is " + << last_msg_->reserved[90]; + EXPECT_EQ(last_msg_->reserved[91], 204) + << "incorrect value for reserved[91], expected 204, is " + << last_msg_->reserved[91]; + EXPECT_EQ(last_msg_->reserved[92], 172) + << "incorrect value for reserved[92], expected 172, is " + << last_msg_->reserved[92]; + EXPECT_EQ(last_msg_->reserved[93], 234) + << "incorrect value for reserved[93], expected 234, is " + << last_msg_->reserved[93]; + EXPECT_EQ(last_msg_->reserved[94], 127) + << "incorrect value for reserved[94], expected 127, is " + << last_msg_->reserved[94]; + EXPECT_EQ(last_msg_->reserved[95], 3) + << "incorrect value for reserved[95], expected 3, is " + << last_msg_->reserved[95]; + EXPECT_EQ(last_msg_->reserved[96], 82) + << "incorrect value for reserved[96], expected 82, is " + << last_msg_->reserved[96]; + EXPECT_EQ(last_msg_->reserved[97], 133) + << "incorrect value for reserved[97], expected 133, is " + << last_msg_->reserved[97]; + EXPECT_EQ(last_msg_->reserved[98], 169) + << "incorrect value for reserved[98], expected 169, is " + << last_msg_->reserved[98]; + EXPECT_EQ(last_msg_->reserved[99], 12) + << "incorrect value for reserved[99], expected 12, is " + << last_msg_->reserved[99]; + EXPECT_EQ(last_msg_->reserved[100], 176) + << "incorrect value for reserved[100], expected 176, is " + << last_msg_->reserved[100]; + EXPECT_EQ(last_msg_->reserved[101], 193) + << "incorrect value for reserved[101], expected 193, is " + << last_msg_->reserved[101]; + EXPECT_EQ(last_msg_->reserved[102], 0) + << "incorrect value for reserved[102], expected 0, is " + << last_msg_->reserved[102]; + EXPECT_EQ(last_msg_->reserved[103], 24) + << "incorrect value for reserved[103], expected 24, is " + << last_msg_->reserved[103]; + EXPECT_EQ(last_msg_->reserved[104], 121) + << "incorrect value for reserved[104], expected 121, is " + << last_msg_->reserved[104]; + EXPECT_EQ(last_msg_->reserved[105], 85) + << "incorrect value for reserved[105], expected 85, is " + << last_msg_->reserved[105]; + EXPECT_EQ(last_msg_->reserved[106], 55) + << "incorrect value for reserved[106], expected 55, is " + << last_msg_->reserved[106]; + EXPECT_EQ(last_msg_->reserved[107], 214) + << "incorrect value for reserved[107], expected 214, is " + << last_msg_->reserved[107]; + EXPECT_EQ(last_msg_->reserved[108], 198) + << "incorrect value for reserved[108], expected 198, is " + << last_msg_->reserved[108]; + EXPECT_EQ(last_msg_->reserved[109], 75) + << "incorrect value for reserved[109], expected 75, is " + << last_msg_->reserved[109]; + EXPECT_EQ(last_msg_->reserved[110], 234) + << "incorrect value for reserved[110], expected 234, is " + << last_msg_->reserved[110]; + EXPECT_EQ(last_msg_->reserved[111], 179) + << "incorrect value for reserved[111], expected 179, is " + << last_msg_->reserved[111]; + EXPECT_EQ(last_msg_->reserved[112], 214) + << "incorrect value for reserved[112], expected 214, is " + << last_msg_->reserved[112]; + EXPECT_EQ(last_msg_->reserved[113], 85) + << "incorrect value for reserved[113], expected 85, is " + << last_msg_->reserved[113]; + EXPECT_EQ(last_msg_->reserved[114], 94) + << "incorrect value for reserved[114], expected 94, is " + << last_msg_->reserved[114]; + EXPECT_EQ(last_msg_->reserved[115], 115) + << "incorrect value for reserved[115], expected 115, is " + << last_msg_->reserved[115]; + EXPECT_EQ(last_msg_->reserved[116], 21) + << "incorrect value for reserved[116], expected 21, is " + << last_msg_->reserved[116]; + EXPECT_EQ(last_msg_->reserved[117], 73) + << "incorrect value for reserved[117], expected 73, is " + << last_msg_->reserved[117]; + EXPECT_EQ(last_msg_->reserved[118], 121) + << "incorrect value for reserved[118], expected 121, is " + << last_msg_->reserved[118]; + EXPECT_EQ(last_msg_->reserved[119], 75) + << "incorrect value for reserved[119], expected 75, is " + << last_msg_->reserved[119]; + EXPECT_EQ(last_msg_->reserved[120], 46) + << "incorrect value for reserved[120], expected 46, is " + << last_msg_->reserved[120]; + EXPECT_EQ(last_msg_->reserved[121], 158) + << "incorrect value for reserved[121], expected 158, is " + << last_msg_->reserved[121]; + EXPECT_EQ(last_msg_->reserved[122], 63) + << "incorrect value for reserved[122], expected 63, is " + << last_msg_->reserved[122]; + EXPECT_EQ(last_msg_->reserved[123], 100) + << "incorrect value for reserved[123], expected 100, is " + << last_msg_->reserved[123]; + EXPECT_EQ(last_msg_->reserved[124], 122) + << "incorrect value for reserved[124], expected 122, is " + << last_msg_->reserved[124]; + EXPECT_EQ(last_msg_->reserved[125], 213) + << "incorrect value for reserved[125], expected 213, is " + << last_msg_->reserved[125]; + EXPECT_EQ(last_msg_->reserved[126], 20) + << "incorrect value for reserved[126], expected 20, is " + << last_msg_->reserved[126]; + EXPECT_EQ(last_msg_->reserved[127], 85) + << "incorrect value for reserved[127], expected 85, is " + << last_msg_->reserved[127]; + EXPECT_EQ(last_msg_->reserved[128], 212) + << "incorrect value for reserved[128], expected 212, is " + << last_msg_->reserved[128]; + EXPECT_EQ(last_msg_->reserved[129], 131) + << "incorrect value for reserved[129], expected 131, is " + << last_msg_->reserved[129]; + EXPECT_EQ(last_msg_->reserved[130], 50) + << "incorrect value for reserved[130], expected 50, is " + << last_msg_->reserved[130]; + EXPECT_EQ(last_msg_->reserved[131], 224) + << "incorrect value for reserved[131], expected 224, is " + << last_msg_->reserved[131]; + EXPECT_EQ(last_msg_->reserved[132], 218) + << "incorrect value for reserved[132], expected 218, is " + << last_msg_->reserved[132]; + EXPECT_EQ(last_msg_->reserved[133], 215) + << "incorrect value for reserved[133], expected 215, is " + << last_msg_->reserved[133]; + EXPECT_EQ(last_msg_->reserved[134], 215) + << "incorrect value for reserved[134], expected 215, is " + << last_msg_->reserved[134]; + EXPECT_EQ(last_msg_->reserved[135], 149) + << "incorrect value for reserved[135], expected 149, is " + << last_msg_->reserved[135]; + EXPECT_EQ(last_msg_->reserved[136], 2) + << "incorrect value for reserved[136], expected 2, is " + << last_msg_->reserved[136]; + EXPECT_EQ(last_msg_->reserved[137], 19) + << "incorrect value for reserved[137], expected 19, is " + << last_msg_->reserved[137]; + EXPECT_EQ(last_msg_->reserved[138], 129) + << "incorrect value for reserved[138], expected 129, is " + << last_msg_->reserved[138]; + EXPECT_EQ(last_msg_->reserved[139], 39) + << "incorrect value for reserved[139], expected 39, is " + << last_msg_->reserved[139]; + EXPECT_EQ(last_msg_->reserved[140], 164) + << "incorrect value for reserved[140], expected 164, is " + << last_msg_->reserved[140]; + EXPECT_EQ(last_msg_->reserved[141], 5) + << "incorrect value for reserved[141], expected 5, is " + << last_msg_->reserved[141]; + EXPECT_EQ(last_msg_->reserved[142], 175) + << "incorrect value for reserved[142], expected 175, is " + << last_msg_->reserved[142]; + EXPECT_EQ(last_msg_->reserved[143], 6) + << "incorrect value for reserved[143], expected 6, is " + << last_msg_->reserved[143]; + EXPECT_EQ(last_msg_->reserved[144], 62) + << "incorrect value for reserved[144], expected 62, is " + << last_msg_->reserved[144]; + EXPECT_EQ(last_msg_->reserved[145], 51) + << "incorrect value for reserved[145], expected 51, is " + << last_msg_->reserved[145]; + EXPECT_EQ(last_msg_->reserved[146], 78) + << "incorrect value for reserved[146], expected 78, is " + << last_msg_->reserved[146]; + EXPECT_EQ(last_msg_->reserved[147], 66) + << "incorrect value for reserved[147], expected 66, is " + << last_msg_->reserved[147]; + EXPECT_EQ(last_msg_->reserved[148], 248) + << "incorrect value for reserved[148], expected 248, is " + << last_msg_->reserved[148]; + EXPECT_EQ(last_msg_->reserved[149], 116) + << "incorrect value for reserved[149], expected 116, is " + << last_msg_->reserved[149]; + EXPECT_EQ(last_msg_->reserved[150], 88) + << "incorrect value for reserved[150], expected 88, is " + << last_msg_->reserved[150]; + EXPECT_EQ(last_msg_->reserved[151], 90) + << "incorrect value for reserved[151], expected 90, is " + << last_msg_->reserved[151]; + EXPECT_EQ(last_msg_->reserved[152], 128) + << "incorrect value for reserved[152], expected 128, is " + << last_msg_->reserved[152]; + EXPECT_EQ(last_msg_->reserved[153], 226) + << "incorrect value for reserved[153], expected 226, is " + << last_msg_->reserved[153]; + EXPECT_EQ(last_msg_->reserved[154], 177) + << "incorrect value for reserved[154], expected 177, is " + << last_msg_->reserved[154]; + EXPECT_EQ(last_msg_->reserved[155], 0) + << "incorrect value for reserved[155], expected 0, is " + << last_msg_->reserved[155]; + EXPECT_EQ(last_msg_->reserved[156], 47) + << "incorrect value for reserved[156], expected 47, is " + << last_msg_->reserved[156]; + EXPECT_EQ(last_msg_->reserved[157], 140) + << "incorrect value for reserved[157], expected 140, is " + << last_msg_->reserved[157]; + EXPECT_EQ(last_msg_->reserved[158], 33) + << "incorrect value for reserved[158], expected 33, is " + << last_msg_->reserved[158]; + EXPECT_EQ(last_msg_->reserved[159], 126) + << "incorrect value for reserved[159], expected 126, is " + << last_msg_->reserved[159]; + EXPECT_EQ(last_msg_->reserved[160], 221) + << "incorrect value for reserved[160], expected 221, is " + << last_msg_->reserved[160]; + EXPECT_EQ(last_msg_->reserved[161], 110) + << "incorrect value for reserved[161], expected 110, is " + << last_msg_->reserved[161]; + EXPECT_EQ(last_msg_->reserved[162], 144) + << "incorrect value for reserved[162], expected 144, is " + << last_msg_->reserved[162]; + EXPECT_EQ(last_msg_->reserved[163], 97) + << "incorrect value for reserved[163], expected 97, is " + << last_msg_->reserved[163]; + EXPECT_EQ(last_msg_->reserved[164], 74) + << "incorrect value for reserved[164], expected 74, is " + << last_msg_->reserved[164]; + EXPECT_EQ(last_msg_->reserved[165], 250) + << "incorrect value for reserved[165], expected 250, is " + << last_msg_->reserved[165]; + EXPECT_EQ(last_msg_->reserved[166], 181) + << "incorrect value for reserved[166], expected 181, is " + << last_msg_->reserved[166]; + EXPECT_EQ(last_msg_->reserved[167], 199) + << "incorrect value for reserved[167], expected 199, is " + << last_msg_->reserved[167]; + EXPECT_EQ(last_msg_->reserved[168], 27) + << "incorrect value for reserved[168], expected 27, is " + << last_msg_->reserved[168]; + EXPECT_EQ(last_msg_->reserved[169], 176) + << "incorrect value for reserved[169], expected 176, is " + << last_msg_->reserved[169]; + EXPECT_EQ(last_msg_->reserved[170], 65) + << "incorrect value for reserved[170], expected 65, is " + << last_msg_->reserved[170]; + EXPECT_EQ(last_msg_->reserved[171], 185) + << "incorrect value for reserved[171], expected 185, is " + << last_msg_->reserved[171]; + EXPECT_EQ(last_msg_->reserved[172], 110) + << "incorrect value for reserved[172], expected 110, is " + << last_msg_->reserved[172]; + EXPECT_EQ(last_msg_->reserved[173], 92) + << "incorrect value for reserved[173], expected 92, is " + << last_msg_->reserved[173]; + EXPECT_EQ(last_msg_->reserved[174], 34) + << "incorrect value for reserved[174], expected 34, is " + << last_msg_->reserved[174]; + EXPECT_EQ(last_msg_->reserved[175], 44) + << "incorrect value for reserved[175], expected 44, is " + << last_msg_->reserved[175]; + EXPECT_EQ(last_msg_->reserved[176], 131) + << "incorrect value for reserved[176], expected 131, is " + << last_msg_->reserved[176]; + EXPECT_EQ(last_msg_->reserved[177], 96) + << "incorrect value for reserved[177], expected 96, is " + << last_msg_->reserved[177]; + EXPECT_EQ(last_msg_->reserved[178], 178) + << "incorrect value for reserved[178], expected 178, is " + << last_msg_->reserved[178]; + EXPECT_EQ(last_msg_->reserved[179], 40) + << "incorrect value for reserved[179], expected 40, is " + << last_msg_->reserved[179]; + EXPECT_EQ(last_msg_->reserved[180], 176) + << "incorrect value for reserved[180], expected 176, is " + << last_msg_->reserved[180]; + EXPECT_EQ(last_msg_->reserved[181], 4) + << "incorrect value for reserved[181], expected 4, is " + << last_msg_->reserved[181]; + EXPECT_EQ(last_msg_->reserved[182], 90) + << "incorrect value for reserved[182], expected 90, is " + << last_msg_->reserved[182]; + EXPECT_EQ(last_msg_->reserved[183], 36) + << "incorrect value for reserved[183], expected 36, is " + << last_msg_->reserved[183]; + EXPECT_EQ(last_msg_->reserved[184], 7) + << "incorrect value for reserved[184], expected 7, is " + << last_msg_->reserved[184]; + EXPECT_EQ(last_msg_->reserved[185], 180) + << "incorrect value for reserved[185], expected 180, is " + << last_msg_->reserved[185]; + EXPECT_EQ(last_msg_->reserved[186], 244) + << "incorrect value for reserved[186], expected 244, is " + << last_msg_->reserved[186]; + EXPECT_EQ(last_msg_->reserved[187], 244) + << "incorrect value for reserved[187], expected 244, is " + << last_msg_->reserved[187]; + EXPECT_EQ(last_msg_->reserved[188], 23) + << "incorrect value for reserved[188], expected 23, is " + << last_msg_->reserved[188]; + EXPECT_EQ(last_msg_->reserved[189], 108) + << "incorrect value for reserved[189], expected 108, is " + << last_msg_->reserved[189]; + EXPECT_EQ(last_msg_->reserved[190], 171) + << "incorrect value for reserved[190], expected 171, is " + << last_msg_->reserved[190]; + EXPECT_EQ(last_msg_->reserved[191], 204) + << "incorrect value for reserved[191], expected 204, is " + << last_msg_->reserved[191]; + EXPECT_EQ(last_msg_->reserved[192], 196) + << "incorrect value for reserved[192], expected 196, is " + << last_msg_->reserved[192]; + EXPECT_EQ(last_msg_->reserved[193], 61) + << "incorrect value for reserved[193], expected 61, is " + << last_msg_->reserved[193]; + EXPECT_EQ(last_msg_->reserved[194], 51) + << "incorrect value for reserved[194], expected 51, is " + << last_msg_->reserved[194]; + EXPECT_EQ(last_msg_->reserved[195], 179) + << "incorrect value for reserved[195], expected 179, is " + << last_msg_->reserved[195]; + EXPECT_EQ(last_msg_->reserved[196], 242) + << "incorrect value for reserved[196], expected 242, is " + << last_msg_->reserved[196]; + EXPECT_EQ(last_msg_->reserved[197], 156) + << "incorrect value for reserved[197], expected 156, is " + << last_msg_->reserved[197]; + EXPECT_EQ(last_msg_->reserved[198], 81) + << "incorrect value for reserved[198], expected 81, is " + << last_msg_->reserved[198]; + EXPECT_EQ(last_msg_->reserved[199], 83) + << "incorrect value for reserved[199], expected 83, is " + << last_msg_->reserved[199]; + EXPECT_EQ(last_msg_->reserved[200], 16) + << "incorrect value for reserved[200], expected 16, is " + << last_msg_->reserved[200]; + EXPECT_EQ(last_msg_->reserved[201], 15) + << "incorrect value for reserved[201], expected 15, is " + << last_msg_->reserved[201]; + EXPECT_EQ(last_msg_->reserved[202], 134) + << "incorrect value for reserved[202], expected 134, is " + << last_msg_->reserved[202]; + EXPECT_EQ(last_msg_->reserved[203], 40) + << "incorrect value for reserved[203], expected 40, is " + << last_msg_->reserved[203]; + EXPECT_EQ(last_msg_->reserved[204], 245) + << "incorrect value for reserved[204], expected 245, is " + << last_msg_->reserved[204]; + EXPECT_EQ(last_msg_->reserved[205], 253) + << "incorrect value for reserved[205], expected 253, is " + << last_msg_->reserved[205]; + EXPECT_EQ(last_msg_->reserved[206], 150) + << "incorrect value for reserved[206], expected 150, is " + << last_msg_->reserved[206]; + EXPECT_EQ(last_msg_->reserved[207], 94) + << "incorrect value for reserved[207], expected 94, is " + << last_msg_->reserved[207]; + EXPECT_EQ(last_msg_->reserved[208], 150) + << "incorrect value for reserved[208], expected 150, is " + << last_msg_->reserved[208]; + EXPECT_EQ(last_msg_->reserved[209], 144) + << "incorrect value for reserved[209], expected 144, is " + << last_msg_->reserved[209]; + EXPECT_EQ(last_msg_->reserved[210], 197) + << "incorrect value for reserved[210], expected 197, is " + << last_msg_->reserved[210]; + EXPECT_EQ(last_msg_->reserved[211], 113) + << "incorrect value for reserved[211], expected 113, is " + << last_msg_->reserved[211]; + EXPECT_EQ(last_msg_->reserved[212], 5) + << "incorrect value for reserved[212], expected 5, is " + << last_msg_->reserved[212]; + EXPECT_EQ(last_msg_->reserved[213], 141) + << "incorrect value for reserved[213], expected 141, is " + << last_msg_->reserved[213]; + EXPECT_EQ(last_msg_->reserved[214], 232) + << "incorrect value for reserved[214], expected 232, is " + << last_msg_->reserved[214]; + EXPECT_EQ(last_msg_->reserved[215], 33) + << "incorrect value for reserved[215], expected 33, is " + << last_msg_->reserved[215]; + EXPECT_EQ(last_msg_->reserved[216], 101) + << "incorrect value for reserved[216], expected 101, is " + << last_msg_->reserved[216]; + EXPECT_EQ(last_msg_->reserved[217], 231) + << "incorrect value for reserved[217], expected 231, is " + << last_msg_->reserved[217]; + EXPECT_EQ(last_msg_->reserved[218], 38) + << "incorrect value for reserved[218], expected 38, is " + << last_msg_->reserved[218]; + EXPECT_EQ(last_msg_->reserved[219], 75) + << "incorrect value for reserved[219], expected 75, is " + << last_msg_->reserved[219]; + EXPECT_EQ(last_msg_->reserved[220], 178) + << "incorrect value for reserved[220], expected 178, is " + << last_msg_->reserved[220]; + EXPECT_EQ(last_msg_->reserved[221], 243) + << "incorrect value for reserved[221], expected 243, is " + << last_msg_->reserved[221]; + EXPECT_EQ(last_msg_->reserved[222], 119) + << "incorrect value for reserved[222], expected 119, is " + << last_msg_->reserved[222]; + EXPECT_EQ(last_msg_->reserved[223], 1) + << "incorrect value for reserved[223], expected 1, is " + << last_msg_->reserved[223]; + EXPECT_EQ(last_msg_->reserved[224], 248) + << "incorrect value for reserved[224], expected 248, is " + << last_msg_->reserved[224]; + EXPECT_EQ(last_msg_->reserved[225], 218) + << "incorrect value for reserved[225], expected 218, is " + << last_msg_->reserved[225]; + EXPECT_EQ(last_msg_->reserved[226], 86) + << "incorrect value for reserved[226], expected 86, is " + << last_msg_->reserved[226]; + EXPECT_EQ(last_msg_->reserved[227], 7) + << "incorrect value for reserved[227], expected 7, is " + << last_msg_->reserved[227]; + EXPECT_EQ(last_msg_->reserved[228], 88) + << "incorrect value for reserved[228], expected 88, is " + << last_msg_->reserved[228]; + EXPECT_EQ(last_msg_->reserved[229], 197) + << "incorrect value for reserved[229], expected 197, is " + << last_msg_->reserved[229]; + EXPECT_EQ(last_msg_->reserved[230], 148) + << "incorrect value for reserved[230], expected 148, is " + << last_msg_->reserved[230]; + EXPECT_EQ(last_msg_->reserved[231], 240) + << "incorrect value for reserved[231], expected 240, is " + << last_msg_->reserved[231]; + EXPECT_EQ(last_msg_->reserved[232], 227) + << "incorrect value for reserved[232], expected 227, is " + << last_msg_->reserved[232]; + EXPECT_EQ(last_msg_->reserved[233], 2) + << "incorrect value for reserved[233], expected 2, is " + << last_msg_->reserved[233]; + EXPECT_EQ(last_msg_->reserved[234], 65) + << "incorrect value for reserved[234], expected 65, is " + << last_msg_->reserved[234]; + EXPECT_EQ(last_msg_->reserved[235], 173) + << "incorrect value for reserved[235], expected 173, is " + << last_msg_->reserved[235]; + EXPECT_EQ(last_msg_->reserved[236], 122) + << "incorrect value for reserved[236], expected 122, is " + << last_msg_->reserved[236]; + EXPECT_EQ(last_msg_->reserved[237], 143) + << "incorrect value for reserved[237], expected 143, is " + << last_msg_->reserved[237]; + EXPECT_EQ(last_msg_->reserved[238], 251) + << "incorrect value for reserved[238], expected 251, is " + << last_msg_->reserved[238]; + EXPECT_EQ(last_msg_->reserved[239], 156) + << "incorrect value for reserved[239], expected 156, is " + << last_msg_->reserved[239]; + EXPECT_EQ(last_msg_->reserved[240], 217) + << "incorrect value for reserved[240], expected 217, is " + << last_msg_->reserved[240]; + EXPECT_EQ(last_msg_->reserved[241], 67) + << "incorrect value for reserved[241], expected 67, is " + << last_msg_->reserved[241]; + EXPECT_EQ(last_msg_->reserved[242], 239) + << "incorrect value for reserved[242], expected 239, is " + << last_msg_->reserved[242]; + EXPECT_EQ(last_msg_->reserved[243], 219) + << "incorrect value for reserved[243], expected 219, is " + << last_msg_->reserved[243]; + EXPECT_EQ(last_msg_->reserved[244], 31) + << "incorrect value for reserved[244], expected 31, is " + << last_msg_->reserved[244]; + EXPECT_EQ(last_msg_->reserved[245], 224) + << "incorrect value for reserved[245], expected 224, is " + << last_msg_->reserved[245]; + EXPECT_EQ(last_msg_->reserved[246], 176) + << "incorrect value for reserved[246], expected 176, is " + << last_msg_->reserved[246]; + EXPECT_EQ(last_msg_->reserved[247], 129) + << "incorrect value for reserved[247], expected 129, is " + << last_msg_->reserved[247]; + EXPECT_EQ(last_msg_->reserved[248], 81) + << "incorrect value for reserved[248], expected 81, is " + << last_msg_->reserved[248]; + EXPECT_EQ(last_msg_->reserved[249], 80) + << "incorrect value for reserved[249], expected 80, is " + << last_msg_->reserved[249]; + EXPECT_LT((last_msg_->signal_error_rate * 100 - 8588.20019531 * 100), 0.05) + << "incorrect value for signal_error_rate, expected 8588.20019531, is " + << last_msg_->signal_error_rate; + EXPECT_EQ(last_msg_->signal_strength, 103) + << "incorrect value for signal_strength, expected 103, is " + << last_msg_->signal_strength; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc new file mode 100644 index 0000000000..097644cd47 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandOutput.cc @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgCommandOutput0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgCommandOutput0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_command_output_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_command_output_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgCommandOutput0, Test) { + uint8_t encoded_frame[] = { + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, + 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116, 11, 109, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_command_output_t *test_msg = (msg_command_output_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = {(char)83, (char)111, (char)109, (char)101, + (char)32, (char)111, (char)117, (char)116, + (char)112, (char)117, (char)116, (char)32, + (char)116, (char)101, (char)120, (char)116}; + memcpy(test_msg->line, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->line) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->sequence = 2507449470; + + EXPECT_EQ(send_message(0xbc, 21554, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 21554); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = {(char)83, (char)111, (char)109, (char)101, + (char)32, (char)111, (char)117, (char)116, + (char)112, (char)117, (char)116, (char)32, + (char)116, (char)101, (char)120, (char)116}; + EXPECT_EQ(memcmp(last_msg_->line, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->line, expected string '" + << check_string << "', is '" << last_msg_->line << "'"; + } + EXPECT_EQ(last_msg_->sequence, 2507449470) + << "incorrect value for sequence, expected 2507449470, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandReq.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandReq.cc new file mode 100644 index 0000000000..826a279230 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandReq.cc @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgCommandReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgCommandReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_command_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_command_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgCommandReq0, Test) { + uint8_t encoded_frame[] = { + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, + 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, 24, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_command_req_t *test_msg = (msg_command_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)99, (char)111, (char)109, + (char)109, (char)97, (char)110, (char)100, (char)32, (char)119, + (char)105, (char)116, (char)104, (char)32, (char)97, (char)114, + (char)103, (char)115, (char)0}; + memcpy(test_msg->command, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->command) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->sequence = 1755532595; + + EXPECT_EQ(send_message(0xb8, 47274, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 47274); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)47, (char)112, (char)97, (char)116, (char)104, (char)47, + (char)116, (char)111, (char)47, (char)99, (char)111, (char)109, + (char)109, (char)97, (char)110, (char)100, (char)32, (char)119, + (char)105, (char)116, (char)104, (char)32, (char)97, (char)114, + (char)103, (char)115, (char)0}; + EXPECT_EQ(memcmp(last_msg_->command, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->command, expected string '" + << check_string << "', is '" << last_msg_->command << "'"; + } + EXPECT_EQ(last_msg_->sequence, 1755532595) + << "incorrect value for sequence, expected 1755532595, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandResp.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandResp.cc new file mode 100644 index 0000000000..7b478f20e5 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCommandResp.cc @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgCommandResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgCommandResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_command_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_command_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgCommandResp0, Test) { + uint8_t encoded_frame[] = { + 85, 185, 0, 57, 206, 8, 118, 215, 131, 160, 210, 110, 150, 103, 164, 240, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_command_resp_t *test_msg = (msg_command_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->code = 1737912018; + test_msg->sequence = 2692994934; + + EXPECT_EQ(send_message(0xb9, 52793, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 52793); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->code, 1737912018) + << "incorrect value for code, expected 1737912018, is " + << last_msg_->code; + EXPECT_EQ(last_msg_->sequence, 2692994934) + << "incorrect value for sequence, expected 2692994934, is " + << last_msg_->sequence; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwResults.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwResults.cc new file mode 100644 index 0000000000..2d0e661723 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwResults.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwStart.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwStart.cc new file mode 100644 index 0000000000..8b0869d145 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgCwStart.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc new file mode 100644 index 0000000000..f703c5c5f3 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgFrontEndGain.cc @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgFrontEndGain0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgFrontEndGain0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_front_end_gain_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_front_end_gain_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgFrontEndGain0, Test) { + uint8_t encoded_frame[] = { + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, + 38, 38, 246, 233, 216, 80, 187, 213, 85, 2, 235, 135, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_front_end_gain_t *test_msg = (msg_front_end_gain_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[0] = -10; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[1] = -23; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[2] = -40; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[3] = 80; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[4] = -69; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[5] = -43; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[6] = 85; + if (sizeof(test_msg->if_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->if_gain[0])); + } + test_msg->if_gain[7] = 2; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[0] = 41; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[1] = -123; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[2] = -122; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[3] = 10; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[4] = 105; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[5] = 20; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[6] = 38; + if (sizeof(test_msg->rf_gain) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rf_gain[0])); + } + test_msg->rf_gain[7] = 38; + + EXPECT_EQ(send_message(0xbf, 62895, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 62895); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->if_gain[0], -10) + << "incorrect value for if_gain[0], expected -10, is " + << last_msg_->if_gain[0]; + EXPECT_EQ(last_msg_->if_gain[1], -23) + << "incorrect value for if_gain[1], expected -23, is " + << last_msg_->if_gain[1]; + EXPECT_EQ(last_msg_->if_gain[2], -40) + << "incorrect value for if_gain[2], expected -40, is " + << last_msg_->if_gain[2]; + EXPECT_EQ(last_msg_->if_gain[3], 80) + << "incorrect value for if_gain[3], expected 80, is " + << last_msg_->if_gain[3]; + EXPECT_EQ(last_msg_->if_gain[4], -69) + << "incorrect value for if_gain[4], expected -69, is " + << last_msg_->if_gain[4]; + EXPECT_EQ(last_msg_->if_gain[5], -43) + << "incorrect value for if_gain[5], expected -43, is " + << last_msg_->if_gain[5]; + EXPECT_EQ(last_msg_->if_gain[6], 85) + << "incorrect value for if_gain[6], expected 85, is " + << last_msg_->if_gain[6]; + EXPECT_EQ(last_msg_->if_gain[7], 2) + << "incorrect value for if_gain[7], expected 2, is " + << last_msg_->if_gain[7]; + EXPECT_EQ(last_msg_->rf_gain[0], 41) + << "incorrect value for rf_gain[0], expected 41, is " + << last_msg_->rf_gain[0]; + EXPECT_EQ(last_msg_->rf_gain[1], -123) + << "incorrect value for rf_gain[1], expected -123, is " + << last_msg_->rf_gain[1]; + EXPECT_EQ(last_msg_->rf_gain[2], -122) + << "incorrect value for rf_gain[2], expected -122, is " + << last_msg_->rf_gain[2]; + EXPECT_EQ(last_msg_->rf_gain[3], 10) + << "incorrect value for rf_gain[3], expected 10, is " + << last_msg_->rf_gain[3]; + EXPECT_EQ(last_msg_->rf_gain[4], 105) + << "incorrect value for rf_gain[4], expected 105, is " + << last_msg_->rf_gain[4]; + EXPECT_EQ(last_msg_->rf_gain[5], 20) + << "incorrect value for rf_gain[5], expected 20, is " + << last_msg_->rf_gain[5]; + EXPECT_EQ(last_msg_->rf_gain[6], 38) + << "incorrect value for rf_gain[6], expected 38, is " + << last_msg_->rf_gain[6]; + EXPECT_EQ(last_msg_->rf_gain[7], 38) + << "incorrect value for rf_gain[7], expected 38, is " + << last_msg_->rf_gain[7]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc new file mode 100644 index 0000000000..1234f713c2 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgInitBaseDep.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc new file mode 100644 index 0000000000..8367826463 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatellite.cc @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgMaskSatellite0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgMaskSatellite0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_mask_satellite_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_mask_satellite_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgMaskSatellite0, Test) { + uint8_t encoded_frame[] = { + 85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_mask_satellite_t *test_msg = (msg_mask_satellite_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->mask = 183; + test_msg->sid.code = 57; + test_msg->sid.sat = 87; + + EXPECT_EQ(send_message(0x2b, 38829, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 38829); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->mask, 183) + << "incorrect value for mask, expected 183, is " << last_msg_->mask; + EXPECT_EQ(last_msg_->sid.code, 57) + << "incorrect value for sid.code, expected 57, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 87) + << "incorrect value for sid.sat, expected 87, is " << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc new file mode 100644 index 0000000000..e19a963fd1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgMaskSatelliteDep.cc @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_mask_satellite_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_mask_satellite_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgMaskSatelliteDep0, Test) { + uint8_t encoded_frame[] = { + 85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_mask_satellite_dep_t *test_msg = + (msg_mask_satellite_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->mask = 33; + test_msg->sid.code = 95; + test_msg->sid.reserved = 4; + test_msg->sid.sat = 39170; + + EXPECT_EQ(send_message(0x1b, 34491, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 34491); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->mask, 33) + << "incorrect value for mask, expected 33, is " << last_msg_->mask; + EXPECT_EQ(last_msg_->sid.code, 95) + << "incorrect value for sid.code, expected 95, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.reserved, 4) + << "incorrect value for sid.reserved, expected 4, is " + << last_msg_->sid.reserved; + EXPECT_EQ(last_msg_->sid.sat, 39170) + << "incorrect value for sid.sat, expected 39170, is " + << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc new file mode 100644 index 0000000000..dde04080bd --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateReq.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc new file mode 100644 index 0000000000..421aab73e2 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgNetworkStateResp.cc @@ -0,0 +1,307 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgNetworkStateResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgNetworkStateResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_network_state_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_network_state_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgNetworkStateResp0, Test) { + uint8_t encoded_frame[] = { + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, 137, 32, 44, + 114, 147, 68, 222, 92, 192, 78, 235, 63, 208, 114, 53, 183, 24, 244, + 231, 26, 105, 25, 136, 3, 105, 102, 48, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_network_state_resp_t *test_msg = + (msg_network_state_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 2471552451; + { + const char assign_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + memcpy(test_msg->interface_name, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->interface_name) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv4_address[0])); + } + test_msg->ipv4_address[0] = 143; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv4_address[0])); + } + test_msg->ipv4_address[1] = 241; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv4_address[0])); + } + test_msg->ipv4_address[2] = 84; + if (sizeof(test_msg->ipv4_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv4_address[0])); + } + test_msg->ipv4_address[3] = 180; + test_msg->ipv4_mask_size = 152; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[0] = 194; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[1] = 137; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[2] = 32; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[3] = 44; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[4] = 114; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[5] = 147; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[6] = 68; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[7] = 222; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[8] = 92; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[9] = 192; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[10] = 78; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[11] = 235; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[12] = 63; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[13] = 208; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[14] = 114; + if (sizeof(test_msg->ipv6_address) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->ipv6_address[0])); + } + test_msg->ipv6_address[15] = 53; + test_msg->ipv6_mask_size = 183; + test_msg->rx_bytes = 451408920; + test_msg->tx_bytes = 59251049; + + EXPECT_EQ(send_message(0xbb, 3880, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 3880); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 2471552451) + << "incorrect value for flags, expected 2471552451, is " + << last_msg_->flags; + { + const char check_string[] = {(char)105, (char)102, (char)48, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0, + (char)0, (char)0, (char)0, (char)0}; + EXPECT_EQ( + memcmp(last_msg_->interface_name, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->interface_name, expected string '" + << check_string << "', is '" << last_msg_->interface_name << "'"; + } + EXPECT_EQ(last_msg_->ipv4_address[0], 143) + << "incorrect value for ipv4_address[0], expected 143, is " + << last_msg_->ipv4_address[0]; + EXPECT_EQ(last_msg_->ipv4_address[1], 241) + << "incorrect value for ipv4_address[1], expected 241, is " + << last_msg_->ipv4_address[1]; + EXPECT_EQ(last_msg_->ipv4_address[2], 84) + << "incorrect value for ipv4_address[2], expected 84, is " + << last_msg_->ipv4_address[2]; + EXPECT_EQ(last_msg_->ipv4_address[3], 180) + << "incorrect value for ipv4_address[3], expected 180, is " + << last_msg_->ipv4_address[3]; + EXPECT_EQ(last_msg_->ipv4_mask_size, 152) + << "incorrect value for ipv4_mask_size, expected 152, is " + << last_msg_->ipv4_mask_size; + EXPECT_EQ(last_msg_->ipv6_address[0], 194) + << "incorrect value for ipv6_address[0], expected 194, is " + << last_msg_->ipv6_address[0]; + EXPECT_EQ(last_msg_->ipv6_address[1], 137) + << "incorrect value for ipv6_address[1], expected 137, is " + << last_msg_->ipv6_address[1]; + EXPECT_EQ(last_msg_->ipv6_address[2], 32) + << "incorrect value for ipv6_address[2], expected 32, is " + << last_msg_->ipv6_address[2]; + EXPECT_EQ(last_msg_->ipv6_address[3], 44) + << "incorrect value for ipv6_address[3], expected 44, is " + << last_msg_->ipv6_address[3]; + EXPECT_EQ(last_msg_->ipv6_address[4], 114) + << "incorrect value for ipv6_address[4], expected 114, is " + << last_msg_->ipv6_address[4]; + EXPECT_EQ(last_msg_->ipv6_address[5], 147) + << "incorrect value for ipv6_address[5], expected 147, is " + << last_msg_->ipv6_address[5]; + EXPECT_EQ(last_msg_->ipv6_address[6], 68) + << "incorrect value for ipv6_address[6], expected 68, is " + << last_msg_->ipv6_address[6]; + EXPECT_EQ(last_msg_->ipv6_address[7], 222) + << "incorrect value for ipv6_address[7], expected 222, is " + << last_msg_->ipv6_address[7]; + EXPECT_EQ(last_msg_->ipv6_address[8], 92) + << "incorrect value for ipv6_address[8], expected 92, is " + << last_msg_->ipv6_address[8]; + EXPECT_EQ(last_msg_->ipv6_address[9], 192) + << "incorrect value for ipv6_address[9], expected 192, is " + << last_msg_->ipv6_address[9]; + EXPECT_EQ(last_msg_->ipv6_address[10], 78) + << "incorrect value for ipv6_address[10], expected 78, is " + << last_msg_->ipv6_address[10]; + EXPECT_EQ(last_msg_->ipv6_address[11], 235) + << "incorrect value for ipv6_address[11], expected 235, is " + << last_msg_->ipv6_address[11]; + EXPECT_EQ(last_msg_->ipv6_address[12], 63) + << "incorrect value for ipv6_address[12], expected 63, is " + << last_msg_->ipv6_address[12]; + EXPECT_EQ(last_msg_->ipv6_address[13], 208) + << "incorrect value for ipv6_address[13], expected 208, is " + << last_msg_->ipv6_address[13]; + EXPECT_EQ(last_msg_->ipv6_address[14], 114) + << "incorrect value for ipv6_address[14], expected 114, is " + << last_msg_->ipv6_address[14]; + EXPECT_EQ(last_msg_->ipv6_address[15], 53) + << "incorrect value for ipv6_address[15], expected 53, is " + << last_msg_->ipv6_address[15]; + EXPECT_EQ(last_msg_->ipv6_mask_size, 183) + << "incorrect value for ipv6_mask_size, expected 183, is " + << last_msg_->ipv6_mask_size; + EXPECT_EQ(last_msg_->rx_bytes, 451408920) + << "incorrect value for rx_bytes, expected 451408920, is " + << last_msg_->rx_bytes; + EXPECT_EQ(last_msg_->tx_bytes, 59251049) + << "incorrect value for tx_bytes, expected 59251049, is " + << last_msg_->tx_bytes; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgReset.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgReset.cc new file mode 100644 index 0000000000..3a1c7db560 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgReset.cc @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgReset0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgReset0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_reset_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_reset_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgReset0, Test) { + uint8_t encoded_frame[] = { + 85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_reset_t *test_msg = (msg_reset_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 334428248; + + EXPECT_EQ(send_message(0xb6, 53823, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 53823); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 334428248) + << "incorrect value for flags, expected 334428248, is " + << last_msg_->flags; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetDep.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetDep.cc new file mode 100644 index 0000000000..99a27d8006 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetDep.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetFilters.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetFilters.cc new file mode 100644 index 0000000000..65355e379e --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgResetFilters.cc @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgResetFilters0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgResetFilters0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_reset_filters_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_reset_filters_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgResetFilters0, Test) { + uint8_t encoded_frame[] = { + 85, 34, 0, 81, 200, 1, 100, 130, 45, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_reset_filters_t *test_msg = (msg_reset_filters_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->filter = 100; + + EXPECT_EQ(send_message(0x22, 51281, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 51281); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->filter, 100) + << "incorrect value for filter, expected 100, is " << last_msg_->filter; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSetTime.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSetTime.cc new file mode 100644 index 0000000000..ecaba9f99a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSetTime.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecan.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecan.cc new file mode 100644 index 0000000000..ab5581dd2f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecan.cc @@ -0,0 +1,2192 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml by generate.py. Do not +// modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgSpecan0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgSpecan0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_specan_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_specan_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgSpecan0, Test) { + uint8_t encoded_frame[] = { + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, 215, + 167, 211, 19, 154, 201, 241, 69, 205, 136, 0, 70, 51, 67, 108, 69, + 102, 38, 166, 68, 100, 179, 185, 17, 175, 49, 193, 228, 228, 47, 33, + 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, 223, 167, 174, 9, + 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, 218, 241, 101, 107, 45, + 137, 93, 114, 230, 43, 224, 23, 74, 209, 199, 211, 130, 89, 220, 163, + 68, 20, 253, 7, 206, 50, 129, 116, 194, 23, 31, 226, 217, 157, 205, + 221, 5, 224, 92, 82, 109, 223, 195, 233, 165, 1, 82, 141, 157, 177, + 169, 244, 131, 96, 109, 111, 253, 149, 28, 225, 225, 72, 158, 158, 210, + 196, 206, 70, 63, 225, 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, + 179, 148, 66, 254, 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, + 171, 102, 163, 175, 50, 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, + 237, 156, 62, 117, 47, 143, 94, 135, 22, 155, 113, 110, 15, 243, 141, + 227, 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, 88, 38, 117, + 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, 70, + 182, 239, 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, 123, 210, + 168, 90, 124, 20, 7, 220, 144, 168, 69, 22, 72, 162, 69, 111, 91, + 251, 72, 220, 28, 119, 150, 95, 2, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_specan_t *test_msg = (msg_specan_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->amplitude_ref = 3780.199951171875; + test_msg->amplitude_unit = 1329.199951171875; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[0] = 100; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[1] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[2] = 185; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[3] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[4] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[5] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[6] = 193; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[7] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[8] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[9] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[10] = 33; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[11] = 24; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[12] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[13] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[14] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[15] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[16] = 246; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[17] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[18] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[19] = 40; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[20] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[21] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[22] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[23] = 167; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[24] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[25] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[26] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[27] = 11; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[28] = 247; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[29] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[30] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[31] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[32] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[33] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[34] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[35] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[36] = 218; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[37] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[38] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[39] = 107; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[40] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[41] = 137; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[42] = 93; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[43] = 114; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[44] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[45] = 43; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[46] = 224; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[47] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[48] = 74; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[49] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[50] = 199; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[51] = 211; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[52] = 130; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[53] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[54] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[55] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[56] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[57] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[58] = 253; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[59] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[60] = 206; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[61] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[62] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[63] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[64] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[65] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[66] = 31; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[67] = 226; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[68] = 217; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[69] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[70] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[71] = 221; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[72] = 5; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[73] = 224; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[74] = 92; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[75] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[76] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[77] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[78] = 195; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[79] = 233; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[80] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[81] = 1; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[82] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[83] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[84] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[85] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[86] = 169; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[87] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[88] = 131; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[89] = 96; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[90] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[91] = 111; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[92] = 253; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[93] = 149; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[94] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[95] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[96] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[97] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[98] = 158; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[99] = 158; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[100] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[101] = 196; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[102] = 206; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[103] = 70; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[104] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[105] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[106] = 184; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[107] = 150; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[108] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[109] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[110] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[111] = 146; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[112] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[113] = 82; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[114] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[115] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[116] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[117] = 148; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[118] = 66; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[119] = 254; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[120] = 115; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[121] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[122] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[123] = 46; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[124] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[125] = 204; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[126] = 37; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[127] = 200; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[128] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[129] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[130] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[131] = 171; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[132] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[133] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[134] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[135] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[136] = 66; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[137] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[138] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[139] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[140] = 223; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[141] = 172; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[142] = 160; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[143] = 233; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[144] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[145] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[146] = 237; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[147] = 156; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[148] = 62; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[149] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[150] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[151] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[152] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[153] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[154] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[155] = 155; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[156] = 113; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[157] = 110; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[158] = 15; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[159] = 243; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[160] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[161] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[162] = 46; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[163] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[164] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[165] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[166] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[167] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[168] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[169] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[170] = 131; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[171] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[172] = 160; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[173] = 88; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[174] = 38; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[175] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[176] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[177] = 57; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[178] = 40; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[179] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[180] = 209; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[181] = 177; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[182] = 38; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[183] = 47; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[184] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[185] = 15; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[186] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[187] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[188] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[189] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[190] = 70; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[191] = 182; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[192] = 239; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[193] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[194] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[195] = 6; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[196] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[197] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[198] = 230; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[199] = 115; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[200] = 2; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[201] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[202] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[203] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[204] = 123; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[205] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[206] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[207] = 90; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[208] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[209] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[210] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[211] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[212] = 144; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[213] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[214] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[215] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[216] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[217] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[218] = 69; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[219] = 111; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[220] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[221] = 251; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[222] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[223] = 220; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[224] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[225] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[226] = 150; + test_msg->channel_tag = 35146; + test_msg->freq_ref = 7737.2001953125; + test_msg->freq_step = 8226.2001953125; + test_msg->t.ns_residual = -1479025396; + test_msg->t.tow = 1227027783; + test_msg->t.wn = 5075; + + EXPECT_EQ(send_message(0x51, 54300, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 54300); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->amplitude_ref * 100 - 3780.19995117 * 100), 0.05) + << "incorrect value for amplitude_ref, expected 3780.19995117, is " + << last_msg_->amplitude_ref; + EXPECT_LT((last_msg_->amplitude_unit * 100 - 1329.19995117 * 100), 0.05) + << "incorrect value for amplitude_unit, expected 1329.19995117, is " + << last_msg_->amplitude_unit; + EXPECT_EQ(last_msg_->amplitude_value[0], 100) + << "incorrect value for amplitude_value[0], expected 100, is " + << last_msg_->amplitude_value[0]; + EXPECT_EQ(last_msg_->amplitude_value[1], 179) + << "incorrect value for amplitude_value[1], expected 179, is " + << last_msg_->amplitude_value[1]; + EXPECT_EQ(last_msg_->amplitude_value[2], 185) + << "incorrect value for amplitude_value[2], expected 185, is " + << last_msg_->amplitude_value[2]; + EXPECT_EQ(last_msg_->amplitude_value[3], 17) + << "incorrect value for amplitude_value[3], expected 17, is " + << last_msg_->amplitude_value[3]; + EXPECT_EQ(last_msg_->amplitude_value[4], 175) + << "incorrect value for amplitude_value[4], expected 175, is " + << last_msg_->amplitude_value[4]; + EXPECT_EQ(last_msg_->amplitude_value[5], 49) + << "incorrect value for amplitude_value[5], expected 49, is " + << last_msg_->amplitude_value[5]; + EXPECT_EQ(last_msg_->amplitude_value[6], 193) + << "incorrect value for amplitude_value[6], expected 193, is " + << last_msg_->amplitude_value[6]; + EXPECT_EQ(last_msg_->amplitude_value[7], 228) + << "incorrect value for amplitude_value[7], expected 228, is " + << last_msg_->amplitude_value[7]; + EXPECT_EQ(last_msg_->amplitude_value[8], 228) + << "incorrect value for amplitude_value[8], expected 228, is " + << last_msg_->amplitude_value[8]; + EXPECT_EQ(last_msg_->amplitude_value[9], 47) + << "incorrect value for amplitude_value[9], expected 47, is " + << last_msg_->amplitude_value[9]; + EXPECT_EQ(last_msg_->amplitude_value[10], 33) + << "incorrect value for amplitude_value[10], expected 33, is " + << last_msg_->amplitude_value[10]; + EXPECT_EQ(last_msg_->amplitude_value[11], 24) + << "incorrect value for amplitude_value[11], expected 24, is " + << last_msg_->amplitude_value[11]; + EXPECT_EQ(last_msg_->amplitude_value[12], 141) + << "incorrect value for amplitude_value[12], expected 141, is " + << last_msg_->amplitude_value[12]; + EXPECT_EQ(last_msg_->amplitude_value[13], 177) + << "incorrect value for amplitude_value[13], expected 177, is " + << last_msg_->amplitude_value[13]; + EXPECT_EQ(last_msg_->amplitude_value[14], 18) + << "incorrect value for amplitude_value[14], expected 18, is " + << last_msg_->amplitude_value[14]; + EXPECT_EQ(last_msg_->amplitude_value[15], 99) + << "incorrect value for amplitude_value[15], expected 99, is " + << last_msg_->amplitude_value[15]; + EXPECT_EQ(last_msg_->amplitude_value[16], 246) + << "incorrect value for amplitude_value[16], expected 246, is " + << last_msg_->amplitude_value[16]; + EXPECT_EQ(last_msg_->amplitude_value[17], 121) + << "incorrect value for amplitude_value[17], expected 121, is " + << last_msg_->amplitude_value[17]; + EXPECT_EQ(last_msg_->amplitude_value[18], 61) + << "incorrect value for amplitude_value[18], expected 61, is " + << last_msg_->amplitude_value[18]; + EXPECT_EQ(last_msg_->amplitude_value[19], 40) + << "incorrect value for amplitude_value[19], expected 40, is " + << last_msg_->amplitude_value[19]; + EXPECT_EQ(last_msg_->amplitude_value[20], 91) + << "incorrect value for amplitude_value[20], expected 91, is " + << last_msg_->amplitude_value[20]; + EXPECT_EQ(last_msg_->amplitude_value[21], 145) + << "incorrect value for amplitude_value[21], expected 145, is " + << last_msg_->amplitude_value[21]; + EXPECT_EQ(last_msg_->amplitude_value[22], 223) + << "incorrect value for amplitude_value[22], expected 223, is " + << last_msg_->amplitude_value[22]; + EXPECT_EQ(last_msg_->amplitude_value[23], 167) + << "incorrect value for amplitude_value[23], expected 167, is " + << last_msg_->amplitude_value[23]; + EXPECT_EQ(last_msg_->amplitude_value[24], 174) + << "incorrect value for amplitude_value[24], expected 174, is " + << last_msg_->amplitude_value[24]; + EXPECT_EQ(last_msg_->amplitude_value[25], 9) + << "incorrect value for amplitude_value[25], expected 9, is " + << last_msg_->amplitude_value[25]; + EXPECT_EQ(last_msg_->amplitude_value[26], 116) + << "incorrect value for amplitude_value[26], expected 116, is " + << last_msg_->amplitude_value[26]; + EXPECT_EQ(last_msg_->amplitude_value[27], 11) + << "incorrect value for amplitude_value[27], expected 11, is " + << last_msg_->amplitude_value[27]; + EXPECT_EQ(last_msg_->amplitude_value[28], 247) + << "incorrect value for amplitude_value[28], expected 247, is " + << last_msg_->amplitude_value[28]; + EXPECT_EQ(last_msg_->amplitude_value[29], 84) + << "incorrect value for amplitude_value[29], expected 84, is " + << last_msg_->amplitude_value[29]; + EXPECT_EQ(last_msg_->amplitude_value[30], 49) + << "incorrect value for amplitude_value[30], expected 49, is " + << last_msg_->amplitude_value[30]; + EXPECT_EQ(last_msg_->amplitude_value[31], 153) + << "incorrect value for amplitude_value[31], expected 153, is " + << last_msg_->amplitude_value[31]; + EXPECT_EQ(last_msg_->amplitude_value[32], 205) + << "incorrect value for amplitude_value[32], expected 205, is " + << last_msg_->amplitude_value[32]; + EXPECT_EQ(last_msg_->amplitude_value[33], 2) + << "incorrect value for amplitude_value[33], expected 2, is " + << last_msg_->amplitude_value[33]; + EXPECT_EQ(last_msg_->amplitude_value[34], 230) + << "incorrect value for amplitude_value[34], expected 230, is " + << last_msg_->amplitude_value[34]; + EXPECT_EQ(last_msg_->amplitude_value[35], 194) + << "incorrect value for amplitude_value[35], expected 194, is " + << last_msg_->amplitude_value[35]; + EXPECT_EQ(last_msg_->amplitude_value[36], 218) + << "incorrect value for amplitude_value[36], expected 218, is " + << last_msg_->amplitude_value[36]; + EXPECT_EQ(last_msg_->amplitude_value[37], 241) + << "incorrect value for amplitude_value[37], expected 241, is " + << last_msg_->amplitude_value[37]; + EXPECT_EQ(last_msg_->amplitude_value[38], 101) + << "incorrect value for amplitude_value[38], expected 101, is " + << last_msg_->amplitude_value[38]; + EXPECT_EQ(last_msg_->amplitude_value[39], 107) + << "incorrect value for amplitude_value[39], expected 107, is " + << last_msg_->amplitude_value[39]; + EXPECT_EQ(last_msg_->amplitude_value[40], 45) + << "incorrect value for amplitude_value[40], expected 45, is " + << last_msg_->amplitude_value[40]; + EXPECT_EQ(last_msg_->amplitude_value[41], 137) + << "incorrect value for amplitude_value[41], expected 137, is " + << last_msg_->amplitude_value[41]; + EXPECT_EQ(last_msg_->amplitude_value[42], 93) + << "incorrect value for amplitude_value[42], expected 93, is " + << last_msg_->amplitude_value[42]; + EXPECT_EQ(last_msg_->amplitude_value[43], 114) + << "incorrect value for amplitude_value[43], expected 114, is " + << last_msg_->amplitude_value[43]; + EXPECT_EQ(last_msg_->amplitude_value[44], 230) + << "incorrect value for amplitude_value[44], expected 230, is " + << last_msg_->amplitude_value[44]; + EXPECT_EQ(last_msg_->amplitude_value[45], 43) + << "incorrect value for amplitude_value[45], expected 43, is " + << last_msg_->amplitude_value[45]; + EXPECT_EQ(last_msg_->amplitude_value[46], 224) + << "incorrect value for amplitude_value[46], expected 224, is " + << last_msg_->amplitude_value[46]; + EXPECT_EQ(last_msg_->amplitude_value[47], 23) + << "incorrect value for amplitude_value[47], expected 23, is " + << last_msg_->amplitude_value[47]; + EXPECT_EQ(last_msg_->amplitude_value[48], 74) + << "incorrect value for amplitude_value[48], expected 74, is " + << last_msg_->amplitude_value[48]; + EXPECT_EQ(last_msg_->amplitude_value[49], 209) + << "incorrect value for amplitude_value[49], expected 209, is " + << last_msg_->amplitude_value[49]; + EXPECT_EQ(last_msg_->amplitude_value[50], 199) + << "incorrect value for amplitude_value[50], expected 199, is " + << last_msg_->amplitude_value[50]; + EXPECT_EQ(last_msg_->amplitude_value[51], 211) + << "incorrect value for amplitude_value[51], expected 211, is " + << last_msg_->amplitude_value[51]; + EXPECT_EQ(last_msg_->amplitude_value[52], 130) + << "incorrect value for amplitude_value[52], expected 130, is " + << last_msg_->amplitude_value[52]; + EXPECT_EQ(last_msg_->amplitude_value[53], 89) + << "incorrect value for amplitude_value[53], expected 89, is " + << last_msg_->amplitude_value[53]; + EXPECT_EQ(last_msg_->amplitude_value[54], 220) + << "incorrect value for amplitude_value[54], expected 220, is " + << last_msg_->amplitude_value[54]; + EXPECT_EQ(last_msg_->amplitude_value[55], 163) + << "incorrect value for amplitude_value[55], expected 163, is " + << last_msg_->amplitude_value[55]; + EXPECT_EQ(last_msg_->amplitude_value[56], 68) + << "incorrect value for amplitude_value[56], expected 68, is " + << last_msg_->amplitude_value[56]; + EXPECT_EQ(last_msg_->amplitude_value[57], 20) + << "incorrect value for amplitude_value[57], expected 20, is " + << last_msg_->amplitude_value[57]; + EXPECT_EQ(last_msg_->amplitude_value[58], 253) + << "incorrect value for amplitude_value[58], expected 253, is " + << last_msg_->amplitude_value[58]; + EXPECT_EQ(last_msg_->amplitude_value[59], 7) + << "incorrect value for amplitude_value[59], expected 7, is " + << last_msg_->amplitude_value[59]; + EXPECT_EQ(last_msg_->amplitude_value[60], 206) + << "incorrect value for amplitude_value[60], expected 206, is " + << last_msg_->amplitude_value[60]; + EXPECT_EQ(last_msg_->amplitude_value[61], 50) + << "incorrect value for amplitude_value[61], expected 50, is " + << last_msg_->amplitude_value[61]; + EXPECT_EQ(last_msg_->amplitude_value[62], 129) + << "incorrect value for amplitude_value[62], expected 129, is " + << last_msg_->amplitude_value[62]; + EXPECT_EQ(last_msg_->amplitude_value[63], 116) + << "incorrect value for amplitude_value[63], expected 116, is " + << last_msg_->amplitude_value[63]; + EXPECT_EQ(last_msg_->amplitude_value[64], 194) + << "incorrect value for amplitude_value[64], expected 194, is " + << last_msg_->amplitude_value[64]; + EXPECT_EQ(last_msg_->amplitude_value[65], 23) + << "incorrect value for amplitude_value[65], expected 23, is " + << last_msg_->amplitude_value[65]; + EXPECT_EQ(last_msg_->amplitude_value[66], 31) + << "incorrect value for amplitude_value[66], expected 31, is " + << last_msg_->amplitude_value[66]; + EXPECT_EQ(last_msg_->amplitude_value[67], 226) + << "incorrect value for amplitude_value[67], expected 226, is " + << last_msg_->amplitude_value[67]; + EXPECT_EQ(last_msg_->amplitude_value[68], 217) + << "incorrect value for amplitude_value[68], expected 217, is " + << last_msg_->amplitude_value[68]; + EXPECT_EQ(last_msg_->amplitude_value[69], 157) + << "incorrect value for amplitude_value[69], expected 157, is " + << last_msg_->amplitude_value[69]; + EXPECT_EQ(last_msg_->amplitude_value[70], 205) + << "incorrect value for amplitude_value[70], expected 205, is " + << last_msg_->amplitude_value[70]; + EXPECT_EQ(last_msg_->amplitude_value[71], 221) + << "incorrect value for amplitude_value[71], expected 221, is " + << last_msg_->amplitude_value[71]; + EXPECT_EQ(last_msg_->amplitude_value[72], 5) + << "incorrect value for amplitude_value[72], expected 5, is " + << last_msg_->amplitude_value[72]; + EXPECT_EQ(last_msg_->amplitude_value[73], 224) + << "incorrect value for amplitude_value[73], expected 224, is " + << last_msg_->amplitude_value[73]; + EXPECT_EQ(last_msg_->amplitude_value[74], 92) + << "incorrect value for amplitude_value[74], expected 92, is " + << last_msg_->amplitude_value[74]; + EXPECT_EQ(last_msg_->amplitude_value[75], 82) + << "incorrect value for amplitude_value[75], expected 82, is " + << last_msg_->amplitude_value[75]; + EXPECT_EQ(last_msg_->amplitude_value[76], 109) + << "incorrect value for amplitude_value[76], expected 109, is " + << last_msg_->amplitude_value[76]; + EXPECT_EQ(last_msg_->amplitude_value[77], 223) + << "incorrect value for amplitude_value[77], expected 223, is " + << last_msg_->amplitude_value[77]; + EXPECT_EQ(last_msg_->amplitude_value[78], 195) + << "incorrect value for amplitude_value[78], expected 195, is " + << last_msg_->amplitude_value[78]; + EXPECT_EQ(last_msg_->amplitude_value[79], 233) + << "incorrect value for amplitude_value[79], expected 233, is " + << last_msg_->amplitude_value[79]; + EXPECT_EQ(last_msg_->amplitude_value[80], 165) + << "incorrect value for amplitude_value[80], expected 165, is " + << last_msg_->amplitude_value[80]; + EXPECT_EQ(last_msg_->amplitude_value[81], 1) + << "incorrect value for amplitude_value[81], expected 1, is " + << last_msg_->amplitude_value[81]; + EXPECT_EQ(last_msg_->amplitude_value[82], 82) + << "incorrect value for amplitude_value[82], expected 82, is " + << last_msg_->amplitude_value[82]; + EXPECT_EQ(last_msg_->amplitude_value[83], 141) + << "incorrect value for amplitude_value[83], expected 141, is " + << last_msg_->amplitude_value[83]; + EXPECT_EQ(last_msg_->amplitude_value[84], 157) + << "incorrect value for amplitude_value[84], expected 157, is " + << last_msg_->amplitude_value[84]; + EXPECT_EQ(last_msg_->amplitude_value[85], 177) + << "incorrect value for amplitude_value[85], expected 177, is " + << last_msg_->amplitude_value[85]; + EXPECT_EQ(last_msg_->amplitude_value[86], 169) + << "incorrect value for amplitude_value[86], expected 169, is " + << last_msg_->amplitude_value[86]; + EXPECT_EQ(last_msg_->amplitude_value[87], 244) + << "incorrect value for amplitude_value[87], expected 244, is " + << last_msg_->amplitude_value[87]; + EXPECT_EQ(last_msg_->amplitude_value[88], 131) + << "incorrect value for amplitude_value[88], expected 131, is " + << last_msg_->amplitude_value[88]; + EXPECT_EQ(last_msg_->amplitude_value[89], 96) + << "incorrect value for amplitude_value[89], expected 96, is " + << last_msg_->amplitude_value[89]; + EXPECT_EQ(last_msg_->amplitude_value[90], 109) + << "incorrect value for amplitude_value[90], expected 109, is " + << last_msg_->amplitude_value[90]; + EXPECT_EQ(last_msg_->amplitude_value[91], 111) + << "incorrect value for amplitude_value[91], expected 111, is " + << last_msg_->amplitude_value[91]; + EXPECT_EQ(last_msg_->amplitude_value[92], 253) + << "incorrect value for amplitude_value[92], expected 253, is " + << last_msg_->amplitude_value[92]; + EXPECT_EQ(last_msg_->amplitude_value[93], 149) + << "incorrect value for amplitude_value[93], expected 149, is " + << last_msg_->amplitude_value[93]; + EXPECT_EQ(last_msg_->amplitude_value[94], 28) + << "incorrect value for amplitude_value[94], expected 28, is " + << last_msg_->amplitude_value[94]; + EXPECT_EQ(last_msg_->amplitude_value[95], 225) + << "incorrect value for amplitude_value[95], expected 225, is " + << last_msg_->amplitude_value[95]; + EXPECT_EQ(last_msg_->amplitude_value[96], 225) + << "incorrect value for amplitude_value[96], expected 225, is " + << last_msg_->amplitude_value[96]; + EXPECT_EQ(last_msg_->amplitude_value[97], 72) + << "incorrect value for amplitude_value[97], expected 72, is " + << last_msg_->amplitude_value[97]; + EXPECT_EQ(last_msg_->amplitude_value[98], 158) + << "incorrect value for amplitude_value[98], expected 158, is " + << last_msg_->amplitude_value[98]; + EXPECT_EQ(last_msg_->amplitude_value[99], 158) + << "incorrect value for amplitude_value[99], expected 158, is " + << last_msg_->amplitude_value[99]; + EXPECT_EQ(last_msg_->amplitude_value[100], 210) + << "incorrect value for amplitude_value[100], expected 210, is " + << last_msg_->amplitude_value[100]; + EXPECT_EQ(last_msg_->amplitude_value[101], 196) + << "incorrect value for amplitude_value[101], expected 196, is " + << last_msg_->amplitude_value[101]; + EXPECT_EQ(last_msg_->amplitude_value[102], 206) + << "incorrect value for amplitude_value[102], expected 206, is " + << last_msg_->amplitude_value[102]; + EXPECT_EQ(last_msg_->amplitude_value[103], 70) + << "incorrect value for amplitude_value[103], expected 70, is " + << last_msg_->amplitude_value[103]; + EXPECT_EQ(last_msg_->amplitude_value[104], 63) + << "incorrect value for amplitude_value[104], expected 63, is " + << last_msg_->amplitude_value[104]; + EXPECT_EQ(last_msg_->amplitude_value[105], 225) + << "incorrect value for amplitude_value[105], expected 225, is " + << last_msg_->amplitude_value[105]; + EXPECT_EQ(last_msg_->amplitude_value[106], 184) + << "incorrect value for amplitude_value[106], expected 184, is " + << last_msg_->amplitude_value[106]; + EXPECT_EQ(last_msg_->amplitude_value[107], 150) + << "incorrect value for amplitude_value[107], expected 150, is " + << last_msg_->amplitude_value[107]; + EXPECT_EQ(last_msg_->amplitude_value[108], 174) + << "incorrect value for amplitude_value[108], expected 174, is " + << last_msg_->amplitude_value[108]; + EXPECT_EQ(last_msg_->amplitude_value[109], 240) + << "incorrect value for amplitude_value[109], expected 240, is " + << last_msg_->amplitude_value[109]; + EXPECT_EQ(last_msg_->amplitude_value[110], 45) + << "incorrect value for amplitude_value[110], expected 45, is " + << last_msg_->amplitude_value[110]; + EXPECT_EQ(last_msg_->amplitude_value[111], 146) + << "incorrect value for amplitude_value[111], expected 146, is " + << last_msg_->amplitude_value[111]; + EXPECT_EQ(last_msg_->amplitude_value[112], 59) + << "incorrect value for amplitude_value[112], expected 59, is " + << last_msg_->amplitude_value[112]; + EXPECT_EQ(last_msg_->amplitude_value[113], 82) + << "incorrect value for amplitude_value[113], expected 82, is " + << last_msg_->amplitude_value[113]; + EXPECT_EQ(last_msg_->amplitude_value[114], 194) + << "incorrect value for amplitude_value[114], expected 194, is " + << last_msg_->amplitude_value[114]; + EXPECT_EQ(last_msg_->amplitude_value[115], 4) + << "incorrect value for amplitude_value[115], expected 4, is " + << last_msg_->amplitude_value[115]; + EXPECT_EQ(last_msg_->amplitude_value[116], 179) + << "incorrect value for amplitude_value[116], expected 179, is " + << last_msg_->amplitude_value[116]; + EXPECT_EQ(last_msg_->amplitude_value[117], 148) + << "incorrect value for amplitude_value[117], expected 148, is " + << last_msg_->amplitude_value[117]; + EXPECT_EQ(last_msg_->amplitude_value[118], 66) + << "incorrect value for amplitude_value[118], expected 66, is " + << last_msg_->amplitude_value[118]; + EXPECT_EQ(last_msg_->amplitude_value[119], 254) + << "incorrect value for amplitude_value[119], expected 254, is " + << last_msg_->amplitude_value[119]; + EXPECT_EQ(last_msg_->amplitude_value[120], 115) + << "incorrect value for amplitude_value[120], expected 115, is " + << last_msg_->amplitude_value[120]; + EXPECT_EQ(last_msg_->amplitude_value[121], 77) + << "incorrect value for amplitude_value[121], expected 77, is " + << last_msg_->amplitude_value[121]; + EXPECT_EQ(last_msg_->amplitude_value[122], 30) + << "incorrect value for amplitude_value[122], expected 30, is " + << last_msg_->amplitude_value[122]; + EXPECT_EQ(last_msg_->amplitude_value[123], 46) + << "incorrect value for amplitude_value[123], expected 46, is " + << last_msg_->amplitude_value[123]; + EXPECT_EQ(last_msg_->amplitude_value[124], 4) + << "incorrect value for amplitude_value[124], expected 4, is " + << last_msg_->amplitude_value[124]; + EXPECT_EQ(last_msg_->amplitude_value[125], 204) + << "incorrect value for amplitude_value[125], expected 204, is " + << last_msg_->amplitude_value[125]; + EXPECT_EQ(last_msg_->amplitude_value[126], 37) + << "incorrect value for amplitude_value[126], expected 37, is " + << last_msg_->amplitude_value[126]; + EXPECT_EQ(last_msg_->amplitude_value[127], 200) + << "incorrect value for amplitude_value[127], expected 200, is " + << last_msg_->amplitude_value[127]; + EXPECT_EQ(last_msg_->amplitude_value[128], 121) + << "incorrect value for amplitude_value[128], expected 121, is " + << last_msg_->amplitude_value[128]; + EXPECT_EQ(last_msg_->amplitude_value[129], 18) + << "incorrect value for amplitude_value[129], expected 18, is " + << last_msg_->amplitude_value[129]; + EXPECT_EQ(last_msg_->amplitude_value[130], 17) + << "incorrect value for amplitude_value[130], expected 17, is " + << last_msg_->amplitude_value[130]; + EXPECT_EQ(last_msg_->amplitude_value[131], 171) + << "incorrect value for amplitude_value[131], expected 171, is " + << last_msg_->amplitude_value[131]; + EXPECT_EQ(last_msg_->amplitude_value[132], 102) + << "incorrect value for amplitude_value[132], expected 102, is " + << last_msg_->amplitude_value[132]; + EXPECT_EQ(last_msg_->amplitude_value[133], 163) + << "incorrect value for amplitude_value[133], expected 163, is " + << last_msg_->amplitude_value[133]; + EXPECT_EQ(last_msg_->amplitude_value[134], 175) + << "incorrect value for amplitude_value[134], expected 175, is " + << last_msg_->amplitude_value[134]; + EXPECT_EQ(last_msg_->amplitude_value[135], 50) + << "incorrect value for amplitude_value[135], expected 50, is " + << last_msg_->amplitude_value[135]; + EXPECT_EQ(last_msg_->amplitude_value[136], 66) + << "incorrect value for amplitude_value[136], expected 66, is " + << last_msg_->amplitude_value[136]; + EXPECT_EQ(last_msg_->amplitude_value[137], 101) + << "incorrect value for amplitude_value[137], expected 101, is " + << last_msg_->amplitude_value[137]; + EXPECT_EQ(last_msg_->amplitude_value[138], 69) + << "incorrect value for amplitude_value[138], expected 69, is " + << last_msg_->amplitude_value[138]; + EXPECT_EQ(last_msg_->amplitude_value[139], 13) + << "incorrect value for amplitude_value[139], expected 13, is " + << last_msg_->amplitude_value[139]; + EXPECT_EQ(last_msg_->amplitude_value[140], 223) + << "incorrect value for amplitude_value[140], expected 223, is " + << last_msg_->amplitude_value[140]; + EXPECT_EQ(last_msg_->amplitude_value[141], 172) + << "incorrect value for amplitude_value[141], expected 172, is " + << last_msg_->amplitude_value[141]; + EXPECT_EQ(last_msg_->amplitude_value[142], 160) + << "incorrect value for amplitude_value[142], expected 160, is " + << last_msg_->amplitude_value[142]; + EXPECT_EQ(last_msg_->amplitude_value[143], 233) + << "incorrect value for amplitude_value[143], expected 233, is " + << last_msg_->amplitude_value[143]; + EXPECT_EQ(last_msg_->amplitude_value[144], 220) + << "incorrect value for amplitude_value[144], expected 220, is " + << last_msg_->amplitude_value[144]; + EXPECT_EQ(last_msg_->amplitude_value[145], 101) + << "incorrect value for amplitude_value[145], expected 101, is " + << last_msg_->amplitude_value[145]; + EXPECT_EQ(last_msg_->amplitude_value[146], 237) + << "incorrect value for amplitude_value[146], expected 237, is " + << last_msg_->amplitude_value[146]; + EXPECT_EQ(last_msg_->amplitude_value[147], 156) + << "incorrect value for amplitude_value[147], expected 156, is " + << last_msg_->amplitude_value[147]; + EXPECT_EQ(last_msg_->amplitude_value[148], 62) + << "incorrect value for amplitude_value[148], expected 62, is " + << last_msg_->amplitude_value[148]; + EXPECT_EQ(last_msg_->amplitude_value[149], 117) + << "incorrect value for amplitude_value[149], expected 117, is " + << last_msg_->amplitude_value[149]; + EXPECT_EQ(last_msg_->amplitude_value[150], 47) + << "incorrect value for amplitude_value[150], expected 47, is " + << last_msg_->amplitude_value[150]; + EXPECT_EQ(last_msg_->amplitude_value[151], 143) + << "incorrect value for amplitude_value[151], expected 143, is " + << last_msg_->amplitude_value[151]; + EXPECT_EQ(last_msg_->amplitude_value[152], 94) + << "incorrect value for amplitude_value[152], expected 94, is " + << last_msg_->amplitude_value[152]; + EXPECT_EQ(last_msg_->amplitude_value[153], 135) + << "incorrect value for amplitude_value[153], expected 135, is " + << last_msg_->amplitude_value[153]; + EXPECT_EQ(last_msg_->amplitude_value[154], 22) + << "incorrect value for amplitude_value[154], expected 22, is " + << last_msg_->amplitude_value[154]; + EXPECT_EQ(last_msg_->amplitude_value[155], 155) + << "incorrect value for amplitude_value[155], expected 155, is " + << last_msg_->amplitude_value[155]; + EXPECT_EQ(last_msg_->amplitude_value[156], 113) + << "incorrect value for amplitude_value[156], expected 113, is " + << last_msg_->amplitude_value[156]; + EXPECT_EQ(last_msg_->amplitude_value[157], 110) + << "incorrect value for amplitude_value[157], expected 110, is " + << last_msg_->amplitude_value[157]; + EXPECT_EQ(last_msg_->amplitude_value[158], 15) + << "incorrect value for amplitude_value[158], expected 15, is " + << last_msg_->amplitude_value[158]; + EXPECT_EQ(last_msg_->amplitude_value[159], 243) + << "incorrect value for amplitude_value[159], expected 243, is " + << last_msg_->amplitude_value[159]; + EXPECT_EQ(last_msg_->amplitude_value[160], 141) + << "incorrect value for amplitude_value[160], expected 141, is " + << last_msg_->amplitude_value[160]; + EXPECT_EQ(last_msg_->amplitude_value[161], 227) + << "incorrect value for amplitude_value[161], expected 227, is " + << last_msg_->amplitude_value[161]; + EXPECT_EQ(last_msg_->amplitude_value[162], 46) + << "incorrect value for amplitude_value[162], expected 46, is " + << last_msg_->amplitude_value[162]; + EXPECT_EQ(last_msg_->amplitude_value[163], 143) + << "incorrect value for amplitude_value[163], expected 143, is " + << last_msg_->amplitude_value[163]; + EXPECT_EQ(last_msg_->amplitude_value[164], 227) + << "incorrect value for amplitude_value[164], expected 227, is " + << last_msg_->amplitude_value[164]; + EXPECT_EQ(last_msg_->amplitude_value[165], 209) + << "incorrect value for amplitude_value[165], expected 209, is " + << last_msg_->amplitude_value[165]; + EXPECT_EQ(last_msg_->amplitude_value[166], 249) + << "incorrect value for amplitude_value[166], expected 249, is " + << last_msg_->amplitude_value[166]; + EXPECT_EQ(last_msg_->amplitude_value[167], 2) + << "incorrect value for amplitude_value[167], expected 2, is " + << last_msg_->amplitude_value[167]; + EXPECT_EQ(last_msg_->amplitude_value[168], 153) + << "incorrect value for amplitude_value[168], expected 153, is " + << last_msg_->amplitude_value[168]; + EXPECT_EQ(last_msg_->amplitude_value[169], 168) + << "incorrect value for amplitude_value[169], expected 168, is " + << last_msg_->amplitude_value[169]; + EXPECT_EQ(last_msg_->amplitude_value[170], 131) + << "incorrect value for amplitude_value[170], expected 131, is " + << last_msg_->amplitude_value[170]; + EXPECT_EQ(last_msg_->amplitude_value[171], 249) + << "incorrect value for amplitude_value[171], expected 249, is " + << last_msg_->amplitude_value[171]; + EXPECT_EQ(last_msg_->amplitude_value[172], 160) + << "incorrect value for amplitude_value[172], expected 160, is " + << last_msg_->amplitude_value[172]; + EXPECT_EQ(last_msg_->amplitude_value[173], 88) + << "incorrect value for amplitude_value[173], expected 88, is " + << last_msg_->amplitude_value[173]; + EXPECT_EQ(last_msg_->amplitude_value[174], 38) + << "incorrect value for amplitude_value[174], expected 38, is " + << last_msg_->amplitude_value[174]; + EXPECT_EQ(last_msg_->amplitude_value[175], 117) + << "incorrect value for amplitude_value[175], expected 117, is " + << last_msg_->amplitude_value[175]; + EXPECT_EQ(last_msg_->amplitude_value[176], 129) + << "incorrect value for amplitude_value[176], expected 129, is " + << last_msg_->amplitude_value[176]; + EXPECT_EQ(last_msg_->amplitude_value[177], 57) + << "incorrect value for amplitude_value[177], expected 57, is " + << last_msg_->amplitude_value[177]; + EXPECT_EQ(last_msg_->amplitude_value[178], 40) + << "incorrect value for amplitude_value[178], expected 40, is " + << last_msg_->amplitude_value[178]; + EXPECT_EQ(last_msg_->amplitude_value[179], 109) + << "incorrect value for amplitude_value[179], expected 109, is " + << last_msg_->amplitude_value[179]; + EXPECT_EQ(last_msg_->amplitude_value[180], 209) + << "incorrect value for amplitude_value[180], expected 209, is " + << last_msg_->amplitude_value[180]; + EXPECT_EQ(last_msg_->amplitude_value[181], 177) + << "incorrect value for amplitude_value[181], expected 177, is " + << last_msg_->amplitude_value[181]; + EXPECT_EQ(last_msg_->amplitude_value[182], 38) + << "incorrect value for amplitude_value[182], expected 38, is " + << last_msg_->amplitude_value[182]; + EXPECT_EQ(last_msg_->amplitude_value[183], 47) + << "incorrect value for amplitude_value[183], expected 47, is " + << last_msg_->amplitude_value[183]; + EXPECT_EQ(last_msg_->amplitude_value[184], 12) + << "incorrect value for amplitude_value[184], expected 12, is " + << last_msg_->amplitude_value[184]; + EXPECT_EQ(last_msg_->amplitude_value[185], 15) + << "incorrect value for amplitude_value[185], expected 15, is " + << last_msg_->amplitude_value[185]; + EXPECT_EQ(last_msg_->amplitude_value[186], 16) + << "incorrect value for amplitude_value[186], expected 16, is " + << last_msg_->amplitude_value[186]; + EXPECT_EQ(last_msg_->amplitude_value[187], 9) + << "incorrect value for amplitude_value[187], expected 9, is " + << last_msg_->amplitude_value[187]; + EXPECT_EQ(last_msg_->amplitude_value[188], 175) + << "incorrect value for amplitude_value[188], expected 175, is " + << last_msg_->amplitude_value[188]; + EXPECT_EQ(last_msg_->amplitude_value[189], 69) + << "incorrect value for amplitude_value[189], expected 69, is " + << last_msg_->amplitude_value[189]; + EXPECT_EQ(last_msg_->amplitude_value[190], 70) + << "incorrect value for amplitude_value[190], expected 70, is " + << last_msg_->amplitude_value[190]; + EXPECT_EQ(last_msg_->amplitude_value[191], 182) + << "incorrect value for amplitude_value[191], expected 182, is " + << last_msg_->amplitude_value[191]; + EXPECT_EQ(last_msg_->amplitude_value[192], 239) + << "incorrect value for amplitude_value[192], expected 239, is " + << last_msg_->amplitude_value[192]; + EXPECT_EQ(last_msg_->amplitude_value[193], 117) + << "incorrect value for amplitude_value[193], expected 117, is " + << last_msg_->amplitude_value[193]; + EXPECT_EQ(last_msg_->amplitude_value[194], 135) + << "incorrect value for amplitude_value[194], expected 135, is " + << last_msg_->amplitude_value[194]; + EXPECT_EQ(last_msg_->amplitude_value[195], 6) + << "incorrect value for amplitude_value[195], expected 6, is " + << last_msg_->amplitude_value[195]; + EXPECT_EQ(last_msg_->amplitude_value[196], 71) + << "incorrect value for amplitude_value[196], expected 71, is " + << last_msg_->amplitude_value[196]; + EXPECT_EQ(last_msg_->amplitude_value[197], 99) + << "incorrect value for amplitude_value[197], expected 99, is " + << last_msg_->amplitude_value[197]; + EXPECT_EQ(last_msg_->amplitude_value[198], 230) + << "incorrect value for amplitude_value[198], expected 230, is " + << last_msg_->amplitude_value[198]; + EXPECT_EQ(last_msg_->amplitude_value[199], 115) + << "incorrect value for amplitude_value[199], expected 115, is " + << last_msg_->amplitude_value[199]; + EXPECT_EQ(last_msg_->amplitude_value[200], 2) + << "incorrect value for amplitude_value[200], expected 2, is " + << last_msg_->amplitude_value[200]; + EXPECT_EQ(last_msg_->amplitude_value[201], 71) + << "incorrect value for amplitude_value[201], expected 71, is " + << last_msg_->amplitude_value[201]; + EXPECT_EQ(last_msg_->amplitude_value[202], 165) + << "incorrect value for amplitude_value[202], expected 165, is " + << last_msg_->amplitude_value[202]; + EXPECT_EQ(last_msg_->amplitude_value[203], 228) + << "incorrect value for amplitude_value[203], expected 228, is " + << last_msg_->amplitude_value[203]; + EXPECT_EQ(last_msg_->amplitude_value[204], 123) + << "incorrect value for amplitude_value[204], expected 123, is " + << last_msg_->amplitude_value[204]; + EXPECT_EQ(last_msg_->amplitude_value[205], 210) + << "incorrect value for amplitude_value[205], expected 210, is " + << last_msg_->amplitude_value[205]; + EXPECT_EQ(last_msg_->amplitude_value[206], 168) + << "incorrect value for amplitude_value[206], expected 168, is " + << last_msg_->amplitude_value[206]; + EXPECT_EQ(last_msg_->amplitude_value[207], 90) + << "incorrect value for amplitude_value[207], expected 90, is " + << last_msg_->amplitude_value[207]; + EXPECT_EQ(last_msg_->amplitude_value[208], 124) + << "incorrect value for amplitude_value[208], expected 124, is " + << last_msg_->amplitude_value[208]; + EXPECT_EQ(last_msg_->amplitude_value[209], 20) + << "incorrect value for amplitude_value[209], expected 20, is " + << last_msg_->amplitude_value[209]; + EXPECT_EQ(last_msg_->amplitude_value[210], 7) + << "incorrect value for amplitude_value[210], expected 7, is " + << last_msg_->amplitude_value[210]; + EXPECT_EQ(last_msg_->amplitude_value[211], 220) + << "incorrect value for amplitude_value[211], expected 220, is " + << last_msg_->amplitude_value[211]; + EXPECT_EQ(last_msg_->amplitude_value[212], 144) + << "incorrect value for amplitude_value[212], expected 144, is " + << last_msg_->amplitude_value[212]; + EXPECT_EQ(last_msg_->amplitude_value[213], 168) + << "incorrect value for amplitude_value[213], expected 168, is " + << last_msg_->amplitude_value[213]; + EXPECT_EQ(last_msg_->amplitude_value[214], 69) + << "incorrect value for amplitude_value[214], expected 69, is " + << last_msg_->amplitude_value[214]; + EXPECT_EQ(last_msg_->amplitude_value[215], 22) + << "incorrect value for amplitude_value[215], expected 22, is " + << last_msg_->amplitude_value[215]; + EXPECT_EQ(last_msg_->amplitude_value[216], 72) + << "incorrect value for amplitude_value[216], expected 72, is " + << last_msg_->amplitude_value[216]; + EXPECT_EQ(last_msg_->amplitude_value[217], 162) + << "incorrect value for amplitude_value[217], expected 162, is " + << last_msg_->amplitude_value[217]; + EXPECT_EQ(last_msg_->amplitude_value[218], 69) + << "incorrect value for amplitude_value[218], expected 69, is " + << last_msg_->amplitude_value[218]; + EXPECT_EQ(last_msg_->amplitude_value[219], 111) + << "incorrect value for amplitude_value[219], expected 111, is " + << last_msg_->amplitude_value[219]; + EXPECT_EQ(last_msg_->amplitude_value[220], 91) + << "incorrect value for amplitude_value[220], expected 91, is " + << last_msg_->amplitude_value[220]; + EXPECT_EQ(last_msg_->amplitude_value[221], 251) + << "incorrect value for amplitude_value[221], expected 251, is " + << last_msg_->amplitude_value[221]; + EXPECT_EQ(last_msg_->amplitude_value[222], 72) + << "incorrect value for amplitude_value[222], expected 72, is " + << last_msg_->amplitude_value[222]; + EXPECT_EQ(last_msg_->amplitude_value[223], 220) + << "incorrect value for amplitude_value[223], expected 220, is " + << last_msg_->amplitude_value[223]; + EXPECT_EQ(last_msg_->amplitude_value[224], 28) + << "incorrect value for amplitude_value[224], expected 28, is " + << last_msg_->amplitude_value[224]; + EXPECT_EQ(last_msg_->amplitude_value[225], 119) + << "incorrect value for amplitude_value[225], expected 119, is " + << last_msg_->amplitude_value[225]; + EXPECT_EQ(last_msg_->amplitude_value[226], 150) + << "incorrect value for amplitude_value[226], expected 150, is " + << last_msg_->amplitude_value[226]; + EXPECT_EQ(last_msg_->channel_tag, 35146) + << "incorrect value for channel_tag, expected 35146, is " + << last_msg_->channel_tag; + EXPECT_LT((last_msg_->freq_ref * 100 - 7737.20019531 * 100), 0.05) + << "incorrect value for freq_ref, expected 7737.20019531, is " + << last_msg_->freq_ref; + EXPECT_LT((last_msg_->freq_step * 100 - 8226.20019531 * 100), 0.05) + << "incorrect value for freq_step, expected 8226.20019531, is " + << last_msg_->freq_step; + EXPECT_EQ(last_msg_->t.ns_residual, -1479025396) + << "incorrect value for t.ns_residual, expected -1479025396, is " + << last_msg_->t.ns_residual; + EXPECT_EQ(last_msg_->t.tow, 1227027783) + << "incorrect value for t.tow, expected 1227027783, is " + << last_msg_->t.tow; + EXPECT_EQ(last_msg_->t.wn, 5075) + << "incorrect value for t.wn, expected 5075, is " << last_msg_->t.wn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc new file mode 100644 index 0000000000..1340182b1f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgSpecanDep.cc @@ -0,0 +1,2224 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_piksi_MsgSpecanDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgSpecanDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_specan_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_specan_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgSpecanDep0, Test) { + uint8_t encoded_frame[] = { + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, 154, + 97, 198, 69, 154, 1, 144, 69, 205, 20, 18, 70, 51, 211, 89, 69, + 240, 14, 179, 186, 227, 244, 173, 240, 182, 71, 166, 117, 196, 13, 44, + 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, 77, 186, 68, 135, + 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, 216, 44, 67, 212, 156, + 75, 81, 53, 250, 225, 23, 205, 26, 34, 119, 50, 101, 64, 7, 231, + 124, 183, 203, 102, 234, 84, 83, 208, 23, 68, 54, 179, 98, 96, 116, + 244, 246, 94, 104, 94, 13, 56, 210, 18, 191, 22, 133, 81, 153, 159, + 161, 219, 59, 21, 164, 121, 145, 203, 171, 132, 57, 180, 102, 101, 11, + 229, 175, 145, 73, 72, 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, + 193, 7, 109, 44, 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, + 231, 161, 81, 216, 114, 60, 231, 163, 163, 49, 237, 244, 185, 240, 89, + 143, 174, 165, 211, 241, 13, 16, 61, 141, 101, 89, 37, 117, 189, 86, + 118, 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, 100, + 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, 181, + 12, 140, 16, 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, 59, 64, + 241, 183, 238, 105, 181, 170, 45, 8, 166, 164, 238, 83, 148, 173, 108, + 228, 67, 89, 189, 67, 26, 39, 216, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_specan_dep_t *test_msg = (msg_specan_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->amplitude_ref = 9349.2001953125; + test_msg->amplitude_unit = 3485.199951171875; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[0] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[1] = 14; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[2] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[3] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[4] = 227; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[5] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[6] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[7] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[8] = 182; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[9] = 71; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[10] = 166; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[11] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[12] = 196; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[13] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[14] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[15] = 27; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[16] = 33; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[17] = 28; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[18] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[19] = 254; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[20] = 3; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[21] = 249; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[22] = 92; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[23] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[24] = 122; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[25] = 169; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[26] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[27] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[28] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[29] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[30] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[31] = 168; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[32] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[33] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[34] = 36; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[35] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[36] = 99; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[37] = 63; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[38] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[39] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[40] = 216; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[41] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[42] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[43] = 212; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[44] = 156; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[45] = 75; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[46] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[47] = 53; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[48] = 250; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[49] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[50] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[51] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[52] = 26; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[53] = 34; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[54] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[55] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[56] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[57] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[58] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[59] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[60] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[61] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[62] = 203; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[63] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[64] = 234; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[65] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[66] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[67] = 208; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[68] = 23; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[69] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[70] = 54; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[71] = 179; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[72] = 98; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[73] = 96; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[74] = 116; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[75] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[76] = 246; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[77] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[78] = 104; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[79] = 94; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[80] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[81] = 56; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[82] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[83] = 18; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[84] = 191; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[85] = 22; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[86] = 133; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[87] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[88] = 153; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[89] = 159; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[90] = 161; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[91] = 219; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[92] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[93] = 21; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[94] = 164; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[95] = 121; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[96] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[97] = 203; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[98] = 171; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[99] = 132; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[100] = 57; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[101] = 180; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[102] = 102; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[103] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[104] = 11; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[105] = 229; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[106] = 175; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[107] = 145; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[108] = 73; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[109] = 72; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[110] = 124; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[111] = 4; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[112] = 184; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[113] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[114] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[115] = 234; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[116] = 218; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[117] = 62; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[118] = 226; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[119] = 217; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[120] = 193; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[121] = 7; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[122] = 109; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[123] = 44; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[124] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[125] = 201; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[126] = 20; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[127] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[128] = 9; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[129] = 140; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[130] = 186; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[131] = 162; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[132] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[133] = 91; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[134] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[135] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[136] = 161; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[137] = 81; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[138] = 216; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[139] = 114; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[140] = 60; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[141] = 231; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[142] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[143] = 163; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[144] = 49; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[145] = 237; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[146] = 244; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[147] = 185; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[148] = 240; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[149] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[150] = 143; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[151] = 174; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[152] = 165; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[153] = 211; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[154] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[155] = 13; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[156] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[157] = 61; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[158] = 141; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[159] = 101; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[160] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[161] = 37; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[162] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[163] = 189; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[164] = 86; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[165] = 118; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[166] = 176; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[167] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[168] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[169] = 14; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[170] = 119; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[171] = 135; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[172] = 129; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[173] = 243; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[174] = 50; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[175] = 29; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[176] = 207; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[177] = 198; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[178] = 117; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[179] = 100; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[180] = 225; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[181] = 6; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[182] = 139; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[183] = 110; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[184] = 39; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[185] = 210; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[186] = 68; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[187] = 199; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[188] = 43; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[189] = 132; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[190] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[191] = 17; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[192] = 51; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[193] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[194] = 181; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[195] = 12; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[196] = 140; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[197] = 16; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[198] = 247; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[199] = 84; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[200] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[201] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[202] = 39; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[203] = 157; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[204] = 77; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[205] = 30; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[206] = 205; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[207] = 194; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[208] = 59; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[209] = 64; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[210] = 241; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[211] = 183; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[212] = 238; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[213] = 105; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[214] = 181; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[215] = 170; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[216] = 45; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[217] = 8; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[218] = 166; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[219] = 164; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[220] = 238; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[221] = 83; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[222] = 148; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[223] = 173; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[224] = 108; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[225] = 228; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[226] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[227] = 89; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[228] = 189; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[229] = 67; + if (sizeof(test_msg->amplitude_value) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->amplitude_value[0])); + } + test_msg->amplitude_value[230] = 26; + test_msg->channel_tag = 5878; + test_msg->freq_ref = 6348.2001953125; + test_msg->freq_step = 4608.2001953125; + test_msg->t.tow = 992295133; + test_msg->t.wn = 6957; + + EXPECT_EQ(send_message(0x50, 55664, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 55664); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->amplitude_ref * 100 - 9349.20019531 * 100), 0.05) + << "incorrect value for amplitude_ref, expected 9349.20019531, is " + << last_msg_->amplitude_ref; + EXPECT_LT((last_msg_->amplitude_unit * 100 - 3485.19995117 * 100), 0.05) + << "incorrect value for amplitude_unit, expected 3485.19995117, is " + << last_msg_->amplitude_unit; + EXPECT_EQ(last_msg_->amplitude_value[0], 240) + << "incorrect value for amplitude_value[0], expected 240, is " + << last_msg_->amplitude_value[0]; + EXPECT_EQ(last_msg_->amplitude_value[1], 14) + << "incorrect value for amplitude_value[1], expected 14, is " + << last_msg_->amplitude_value[1]; + EXPECT_EQ(last_msg_->amplitude_value[2], 179) + << "incorrect value for amplitude_value[2], expected 179, is " + << last_msg_->amplitude_value[2]; + EXPECT_EQ(last_msg_->amplitude_value[3], 186) + << "incorrect value for amplitude_value[3], expected 186, is " + << last_msg_->amplitude_value[3]; + EXPECT_EQ(last_msg_->amplitude_value[4], 227) + << "incorrect value for amplitude_value[4], expected 227, is " + << last_msg_->amplitude_value[4]; + EXPECT_EQ(last_msg_->amplitude_value[5], 244) + << "incorrect value for amplitude_value[5], expected 244, is " + << last_msg_->amplitude_value[5]; + EXPECT_EQ(last_msg_->amplitude_value[6], 173) + << "incorrect value for amplitude_value[6], expected 173, is " + << last_msg_->amplitude_value[6]; + EXPECT_EQ(last_msg_->amplitude_value[7], 240) + << "incorrect value for amplitude_value[7], expected 240, is " + << last_msg_->amplitude_value[7]; + EXPECT_EQ(last_msg_->amplitude_value[8], 182) + << "incorrect value for amplitude_value[8], expected 182, is " + << last_msg_->amplitude_value[8]; + EXPECT_EQ(last_msg_->amplitude_value[9], 71) + << "incorrect value for amplitude_value[9], expected 71, is " + << last_msg_->amplitude_value[9]; + EXPECT_EQ(last_msg_->amplitude_value[10], 166) + << "incorrect value for amplitude_value[10], expected 166, is " + << last_msg_->amplitude_value[10]; + EXPECT_EQ(last_msg_->amplitude_value[11], 117) + << "incorrect value for amplitude_value[11], expected 117, is " + << last_msg_->amplitude_value[11]; + EXPECT_EQ(last_msg_->amplitude_value[12], 196) + << "incorrect value for amplitude_value[12], expected 196, is " + << last_msg_->amplitude_value[12]; + EXPECT_EQ(last_msg_->amplitude_value[13], 13) + << "incorrect value for amplitude_value[13], expected 13, is " + << last_msg_->amplitude_value[13]; + EXPECT_EQ(last_msg_->amplitude_value[14], 44) + << "incorrect value for amplitude_value[14], expected 44, is " + << last_msg_->amplitude_value[14]; + EXPECT_EQ(last_msg_->amplitude_value[15], 27) + << "incorrect value for amplitude_value[15], expected 27, is " + << last_msg_->amplitude_value[15]; + EXPECT_EQ(last_msg_->amplitude_value[16], 33) + << "incorrect value for amplitude_value[16], expected 33, is " + << last_msg_->amplitude_value[16]; + EXPECT_EQ(last_msg_->amplitude_value[17], 28) + << "incorrect value for amplitude_value[17], expected 28, is " + << last_msg_->amplitude_value[17]; + EXPECT_EQ(last_msg_->amplitude_value[18], 67) + << "incorrect value for amplitude_value[18], expected 67, is " + << last_msg_->amplitude_value[18]; + EXPECT_EQ(last_msg_->amplitude_value[19], 254) + << "incorrect value for amplitude_value[19], expected 254, is " + << last_msg_->amplitude_value[19]; + EXPECT_EQ(last_msg_->amplitude_value[20], 3) + << "incorrect value for amplitude_value[20], expected 3, is " + << last_msg_->amplitude_value[20]; + EXPECT_EQ(last_msg_->amplitude_value[21], 249) + << "incorrect value for amplitude_value[21], expected 249, is " + << last_msg_->amplitude_value[21]; + EXPECT_EQ(last_msg_->amplitude_value[22], 92) + << "incorrect value for amplitude_value[22], expected 92, is " + << last_msg_->amplitude_value[22]; + EXPECT_EQ(last_msg_->amplitude_value[23], 44) + << "incorrect value for amplitude_value[23], expected 44, is " + << last_msg_->amplitude_value[23]; + EXPECT_EQ(last_msg_->amplitude_value[24], 122) + << "incorrect value for amplitude_value[24], expected 122, is " + << last_msg_->amplitude_value[24]; + EXPECT_EQ(last_msg_->amplitude_value[25], 169) + << "incorrect value for amplitude_value[25], expected 169, is " + << last_msg_->amplitude_value[25]; + EXPECT_EQ(last_msg_->amplitude_value[26], 77) + << "incorrect value for amplitude_value[26], expected 77, is " + << last_msg_->amplitude_value[26]; + EXPECT_EQ(last_msg_->amplitude_value[27], 186) + << "incorrect value for amplitude_value[27], expected 186, is " + << last_msg_->amplitude_value[27]; + EXPECT_EQ(last_msg_->amplitude_value[28], 68) + << "incorrect value for amplitude_value[28], expected 68, is " + << last_msg_->amplitude_value[28]; + EXPECT_EQ(last_msg_->amplitude_value[29], 135) + << "incorrect value for amplitude_value[29], expected 135, is " + << last_msg_->amplitude_value[29]; + EXPECT_EQ(last_msg_->amplitude_value[30], 63) + << "incorrect value for amplitude_value[30], expected 63, is " + << last_msg_->amplitude_value[30]; + EXPECT_EQ(last_msg_->amplitude_value[31], 168) + << "incorrect value for amplitude_value[31], expected 168, is " + << last_msg_->amplitude_value[31]; + EXPECT_EQ(last_msg_->amplitude_value[32], 162) + << "incorrect value for amplitude_value[32], expected 162, is " + << last_msg_->amplitude_value[32]; + EXPECT_EQ(last_msg_->amplitude_value[33], 89) + << "incorrect value for amplitude_value[33], expected 89, is " + << last_msg_->amplitude_value[33]; + EXPECT_EQ(last_msg_->amplitude_value[34], 36) + << "incorrect value for amplitude_value[34], expected 36, is " + << last_msg_->amplitude_value[34]; + EXPECT_EQ(last_msg_->amplitude_value[35], 186) + << "incorrect value for amplitude_value[35], expected 186, is " + << last_msg_->amplitude_value[35]; + EXPECT_EQ(last_msg_->amplitude_value[36], 99) + << "incorrect value for amplitude_value[36], expected 99, is " + << last_msg_->amplitude_value[36]; + EXPECT_EQ(last_msg_->amplitude_value[37], 63) + << "incorrect value for amplitude_value[37], expected 63, is " + << last_msg_->amplitude_value[37]; + EXPECT_EQ(last_msg_->amplitude_value[38], 105) + << "incorrect value for amplitude_value[38], expected 105, is " + << last_msg_->amplitude_value[38]; + EXPECT_EQ(last_msg_->amplitude_value[39], 116) + << "incorrect value for amplitude_value[39], expected 116, is " + << last_msg_->amplitude_value[39]; + EXPECT_EQ(last_msg_->amplitude_value[40], 216) + << "incorrect value for amplitude_value[40], expected 216, is " + << last_msg_->amplitude_value[40]; + EXPECT_EQ(last_msg_->amplitude_value[41], 44) + << "incorrect value for amplitude_value[41], expected 44, is " + << last_msg_->amplitude_value[41]; + EXPECT_EQ(last_msg_->amplitude_value[42], 67) + << "incorrect value for amplitude_value[42], expected 67, is " + << last_msg_->amplitude_value[42]; + EXPECT_EQ(last_msg_->amplitude_value[43], 212) + << "incorrect value for amplitude_value[43], expected 212, is " + << last_msg_->amplitude_value[43]; + EXPECT_EQ(last_msg_->amplitude_value[44], 156) + << "incorrect value for amplitude_value[44], expected 156, is " + << last_msg_->amplitude_value[44]; + EXPECT_EQ(last_msg_->amplitude_value[45], 75) + << "incorrect value for amplitude_value[45], expected 75, is " + << last_msg_->amplitude_value[45]; + EXPECT_EQ(last_msg_->amplitude_value[46], 81) + << "incorrect value for amplitude_value[46], expected 81, is " + << last_msg_->amplitude_value[46]; + EXPECT_EQ(last_msg_->amplitude_value[47], 53) + << "incorrect value for amplitude_value[47], expected 53, is " + << last_msg_->amplitude_value[47]; + EXPECT_EQ(last_msg_->amplitude_value[48], 250) + << "incorrect value for amplitude_value[48], expected 250, is " + << last_msg_->amplitude_value[48]; + EXPECT_EQ(last_msg_->amplitude_value[49], 225) + << "incorrect value for amplitude_value[49], expected 225, is " + << last_msg_->amplitude_value[49]; + EXPECT_EQ(last_msg_->amplitude_value[50], 23) + << "incorrect value for amplitude_value[50], expected 23, is " + << last_msg_->amplitude_value[50]; + EXPECT_EQ(last_msg_->amplitude_value[51], 205) + << "incorrect value for amplitude_value[51], expected 205, is " + << last_msg_->amplitude_value[51]; + EXPECT_EQ(last_msg_->amplitude_value[52], 26) + << "incorrect value for amplitude_value[52], expected 26, is " + << last_msg_->amplitude_value[52]; + EXPECT_EQ(last_msg_->amplitude_value[53], 34) + << "incorrect value for amplitude_value[53], expected 34, is " + << last_msg_->amplitude_value[53]; + EXPECT_EQ(last_msg_->amplitude_value[54], 119) + << "incorrect value for amplitude_value[54], expected 119, is " + << last_msg_->amplitude_value[54]; + EXPECT_EQ(last_msg_->amplitude_value[55], 50) + << "incorrect value for amplitude_value[55], expected 50, is " + << last_msg_->amplitude_value[55]; + EXPECT_EQ(last_msg_->amplitude_value[56], 101) + << "incorrect value for amplitude_value[56], expected 101, is " + << last_msg_->amplitude_value[56]; + EXPECT_EQ(last_msg_->amplitude_value[57], 64) + << "incorrect value for amplitude_value[57], expected 64, is " + << last_msg_->amplitude_value[57]; + EXPECT_EQ(last_msg_->amplitude_value[58], 7) + << "incorrect value for amplitude_value[58], expected 7, is " + << last_msg_->amplitude_value[58]; + EXPECT_EQ(last_msg_->amplitude_value[59], 231) + << "incorrect value for amplitude_value[59], expected 231, is " + << last_msg_->amplitude_value[59]; + EXPECT_EQ(last_msg_->amplitude_value[60], 124) + << "incorrect value for amplitude_value[60], expected 124, is " + << last_msg_->amplitude_value[60]; + EXPECT_EQ(last_msg_->amplitude_value[61], 183) + << "incorrect value for amplitude_value[61], expected 183, is " + << last_msg_->amplitude_value[61]; + EXPECT_EQ(last_msg_->amplitude_value[62], 203) + << "incorrect value for amplitude_value[62], expected 203, is " + << last_msg_->amplitude_value[62]; + EXPECT_EQ(last_msg_->amplitude_value[63], 102) + << "incorrect value for amplitude_value[63], expected 102, is " + << last_msg_->amplitude_value[63]; + EXPECT_EQ(last_msg_->amplitude_value[64], 234) + << "incorrect value for amplitude_value[64], expected 234, is " + << last_msg_->amplitude_value[64]; + EXPECT_EQ(last_msg_->amplitude_value[65], 84) + << "incorrect value for amplitude_value[65], expected 84, is " + << last_msg_->amplitude_value[65]; + EXPECT_EQ(last_msg_->amplitude_value[66], 83) + << "incorrect value for amplitude_value[66], expected 83, is " + << last_msg_->amplitude_value[66]; + EXPECT_EQ(last_msg_->amplitude_value[67], 208) + << "incorrect value for amplitude_value[67], expected 208, is " + << last_msg_->amplitude_value[67]; + EXPECT_EQ(last_msg_->amplitude_value[68], 23) + << "incorrect value for amplitude_value[68], expected 23, is " + << last_msg_->amplitude_value[68]; + EXPECT_EQ(last_msg_->amplitude_value[69], 68) + << "incorrect value for amplitude_value[69], expected 68, is " + << last_msg_->amplitude_value[69]; + EXPECT_EQ(last_msg_->amplitude_value[70], 54) + << "incorrect value for amplitude_value[70], expected 54, is " + << last_msg_->amplitude_value[70]; + EXPECT_EQ(last_msg_->amplitude_value[71], 179) + << "incorrect value for amplitude_value[71], expected 179, is " + << last_msg_->amplitude_value[71]; + EXPECT_EQ(last_msg_->amplitude_value[72], 98) + << "incorrect value for amplitude_value[72], expected 98, is " + << last_msg_->amplitude_value[72]; + EXPECT_EQ(last_msg_->amplitude_value[73], 96) + << "incorrect value for amplitude_value[73], expected 96, is " + << last_msg_->amplitude_value[73]; + EXPECT_EQ(last_msg_->amplitude_value[74], 116) + << "incorrect value for amplitude_value[74], expected 116, is " + << last_msg_->amplitude_value[74]; + EXPECT_EQ(last_msg_->amplitude_value[75], 244) + << "incorrect value for amplitude_value[75], expected 244, is " + << last_msg_->amplitude_value[75]; + EXPECT_EQ(last_msg_->amplitude_value[76], 246) + << "incorrect value for amplitude_value[76], expected 246, is " + << last_msg_->amplitude_value[76]; + EXPECT_EQ(last_msg_->amplitude_value[77], 94) + << "incorrect value for amplitude_value[77], expected 94, is " + << last_msg_->amplitude_value[77]; + EXPECT_EQ(last_msg_->amplitude_value[78], 104) + << "incorrect value for amplitude_value[78], expected 104, is " + << last_msg_->amplitude_value[78]; + EXPECT_EQ(last_msg_->amplitude_value[79], 94) + << "incorrect value for amplitude_value[79], expected 94, is " + << last_msg_->amplitude_value[79]; + EXPECT_EQ(last_msg_->amplitude_value[80], 13) + << "incorrect value for amplitude_value[80], expected 13, is " + << last_msg_->amplitude_value[80]; + EXPECT_EQ(last_msg_->amplitude_value[81], 56) + << "incorrect value for amplitude_value[81], expected 56, is " + << last_msg_->amplitude_value[81]; + EXPECT_EQ(last_msg_->amplitude_value[82], 210) + << "incorrect value for amplitude_value[82], expected 210, is " + << last_msg_->amplitude_value[82]; + EXPECT_EQ(last_msg_->amplitude_value[83], 18) + << "incorrect value for amplitude_value[83], expected 18, is " + << last_msg_->amplitude_value[83]; + EXPECT_EQ(last_msg_->amplitude_value[84], 191) + << "incorrect value for amplitude_value[84], expected 191, is " + << last_msg_->amplitude_value[84]; + EXPECT_EQ(last_msg_->amplitude_value[85], 22) + << "incorrect value for amplitude_value[85], expected 22, is " + << last_msg_->amplitude_value[85]; + EXPECT_EQ(last_msg_->amplitude_value[86], 133) + << "incorrect value for amplitude_value[86], expected 133, is " + << last_msg_->amplitude_value[86]; + EXPECT_EQ(last_msg_->amplitude_value[87], 81) + << "incorrect value for amplitude_value[87], expected 81, is " + << last_msg_->amplitude_value[87]; + EXPECT_EQ(last_msg_->amplitude_value[88], 153) + << "incorrect value for amplitude_value[88], expected 153, is " + << last_msg_->amplitude_value[88]; + EXPECT_EQ(last_msg_->amplitude_value[89], 159) + << "incorrect value for amplitude_value[89], expected 159, is " + << last_msg_->amplitude_value[89]; + EXPECT_EQ(last_msg_->amplitude_value[90], 161) + << "incorrect value for amplitude_value[90], expected 161, is " + << last_msg_->amplitude_value[90]; + EXPECT_EQ(last_msg_->amplitude_value[91], 219) + << "incorrect value for amplitude_value[91], expected 219, is " + << last_msg_->amplitude_value[91]; + EXPECT_EQ(last_msg_->amplitude_value[92], 59) + << "incorrect value for amplitude_value[92], expected 59, is " + << last_msg_->amplitude_value[92]; + EXPECT_EQ(last_msg_->amplitude_value[93], 21) + << "incorrect value for amplitude_value[93], expected 21, is " + << last_msg_->amplitude_value[93]; + EXPECT_EQ(last_msg_->amplitude_value[94], 164) + << "incorrect value for amplitude_value[94], expected 164, is " + << last_msg_->amplitude_value[94]; + EXPECT_EQ(last_msg_->amplitude_value[95], 121) + << "incorrect value for amplitude_value[95], expected 121, is " + << last_msg_->amplitude_value[95]; + EXPECT_EQ(last_msg_->amplitude_value[96], 145) + << "incorrect value for amplitude_value[96], expected 145, is " + << last_msg_->amplitude_value[96]; + EXPECT_EQ(last_msg_->amplitude_value[97], 203) + << "incorrect value for amplitude_value[97], expected 203, is " + << last_msg_->amplitude_value[97]; + EXPECT_EQ(last_msg_->amplitude_value[98], 171) + << "incorrect value for amplitude_value[98], expected 171, is " + << last_msg_->amplitude_value[98]; + EXPECT_EQ(last_msg_->amplitude_value[99], 132) + << "incorrect value for amplitude_value[99], expected 132, is " + << last_msg_->amplitude_value[99]; + EXPECT_EQ(last_msg_->amplitude_value[100], 57) + << "incorrect value for amplitude_value[100], expected 57, is " + << last_msg_->amplitude_value[100]; + EXPECT_EQ(last_msg_->amplitude_value[101], 180) + << "incorrect value for amplitude_value[101], expected 180, is " + << last_msg_->amplitude_value[101]; + EXPECT_EQ(last_msg_->amplitude_value[102], 102) + << "incorrect value for amplitude_value[102], expected 102, is " + << last_msg_->amplitude_value[102]; + EXPECT_EQ(last_msg_->amplitude_value[103], 101) + << "incorrect value for amplitude_value[103], expected 101, is " + << last_msg_->amplitude_value[103]; + EXPECT_EQ(last_msg_->amplitude_value[104], 11) + << "incorrect value for amplitude_value[104], expected 11, is " + << last_msg_->amplitude_value[104]; + EXPECT_EQ(last_msg_->amplitude_value[105], 229) + << "incorrect value for amplitude_value[105], expected 229, is " + << last_msg_->amplitude_value[105]; + EXPECT_EQ(last_msg_->amplitude_value[106], 175) + << "incorrect value for amplitude_value[106], expected 175, is " + << last_msg_->amplitude_value[106]; + EXPECT_EQ(last_msg_->amplitude_value[107], 145) + << "incorrect value for amplitude_value[107], expected 145, is " + << last_msg_->amplitude_value[107]; + EXPECT_EQ(last_msg_->amplitude_value[108], 73) + << "incorrect value for amplitude_value[108], expected 73, is " + << last_msg_->amplitude_value[108]; + EXPECT_EQ(last_msg_->amplitude_value[109], 72) + << "incorrect value for amplitude_value[109], expected 72, is " + << last_msg_->amplitude_value[109]; + EXPECT_EQ(last_msg_->amplitude_value[110], 124) + << "incorrect value for amplitude_value[110], expected 124, is " + << last_msg_->amplitude_value[110]; + EXPECT_EQ(last_msg_->amplitude_value[111], 4) + << "incorrect value for amplitude_value[111], expected 4, is " + << last_msg_->amplitude_value[111]; + EXPECT_EQ(last_msg_->amplitude_value[112], 184) + << "incorrect value for amplitude_value[112], expected 184, is " + << last_msg_->amplitude_value[112]; + EXPECT_EQ(last_msg_->amplitude_value[113], 228) + << "incorrect value for amplitude_value[113], expected 228, is " + << last_msg_->amplitude_value[113]; + EXPECT_EQ(last_msg_->amplitude_value[114], 61) + << "incorrect value for amplitude_value[114], expected 61, is " + << last_msg_->amplitude_value[114]; + EXPECT_EQ(last_msg_->amplitude_value[115], 234) + << "incorrect value for amplitude_value[115], expected 234, is " + << last_msg_->amplitude_value[115]; + EXPECT_EQ(last_msg_->amplitude_value[116], 218) + << "incorrect value for amplitude_value[116], expected 218, is " + << last_msg_->amplitude_value[116]; + EXPECT_EQ(last_msg_->amplitude_value[117], 62) + << "incorrect value for amplitude_value[117], expected 62, is " + << last_msg_->amplitude_value[117]; + EXPECT_EQ(last_msg_->amplitude_value[118], 226) + << "incorrect value for amplitude_value[118], expected 226, is " + << last_msg_->amplitude_value[118]; + EXPECT_EQ(last_msg_->amplitude_value[119], 217) + << "incorrect value for amplitude_value[119], expected 217, is " + << last_msg_->amplitude_value[119]; + EXPECT_EQ(last_msg_->amplitude_value[120], 193) + << "incorrect value for amplitude_value[120], expected 193, is " + << last_msg_->amplitude_value[120]; + EXPECT_EQ(last_msg_->amplitude_value[121], 7) + << "incorrect value for amplitude_value[121], expected 7, is " + << last_msg_->amplitude_value[121]; + EXPECT_EQ(last_msg_->amplitude_value[122], 109) + << "incorrect value for amplitude_value[122], expected 109, is " + << last_msg_->amplitude_value[122]; + EXPECT_EQ(last_msg_->amplitude_value[123], 44) + << "incorrect value for amplitude_value[123], expected 44, is " + << last_msg_->amplitude_value[123]; + EXPECT_EQ(last_msg_->amplitude_value[124], 83) + << "incorrect value for amplitude_value[124], expected 83, is " + << last_msg_->amplitude_value[124]; + EXPECT_EQ(last_msg_->amplitude_value[125], 201) + << "incorrect value for amplitude_value[125], expected 201, is " + << last_msg_->amplitude_value[125]; + EXPECT_EQ(last_msg_->amplitude_value[126], 20) + << "incorrect value for amplitude_value[126], expected 20, is " + << last_msg_->amplitude_value[126]; + EXPECT_EQ(last_msg_->amplitude_value[127], 101) + << "incorrect value for amplitude_value[127], expected 101, is " + << last_msg_->amplitude_value[127]; + EXPECT_EQ(last_msg_->amplitude_value[128], 9) + << "incorrect value for amplitude_value[128], expected 9, is " + << last_msg_->amplitude_value[128]; + EXPECT_EQ(last_msg_->amplitude_value[129], 140) + << "incorrect value for amplitude_value[129], expected 140, is " + << last_msg_->amplitude_value[129]; + EXPECT_EQ(last_msg_->amplitude_value[130], 186) + << "incorrect value for amplitude_value[130], expected 186, is " + << last_msg_->amplitude_value[130]; + EXPECT_EQ(last_msg_->amplitude_value[131], 162) + << "incorrect value for amplitude_value[131], expected 162, is " + << last_msg_->amplitude_value[131]; + EXPECT_EQ(last_msg_->amplitude_value[132], 81) + << "incorrect value for amplitude_value[132], expected 81, is " + << last_msg_->amplitude_value[132]; + EXPECT_EQ(last_msg_->amplitude_value[133], 91) + << "incorrect value for amplitude_value[133], expected 91, is " + << last_msg_->amplitude_value[133]; + EXPECT_EQ(last_msg_->amplitude_value[134], 30) + << "incorrect value for amplitude_value[134], expected 30, is " + << last_msg_->amplitude_value[134]; + EXPECT_EQ(last_msg_->amplitude_value[135], 231) + << "incorrect value for amplitude_value[135], expected 231, is " + << last_msg_->amplitude_value[135]; + EXPECT_EQ(last_msg_->amplitude_value[136], 161) + << "incorrect value for amplitude_value[136], expected 161, is " + << last_msg_->amplitude_value[136]; + EXPECT_EQ(last_msg_->amplitude_value[137], 81) + << "incorrect value for amplitude_value[137], expected 81, is " + << last_msg_->amplitude_value[137]; + EXPECT_EQ(last_msg_->amplitude_value[138], 216) + << "incorrect value for amplitude_value[138], expected 216, is " + << last_msg_->amplitude_value[138]; + EXPECT_EQ(last_msg_->amplitude_value[139], 114) + << "incorrect value for amplitude_value[139], expected 114, is " + << last_msg_->amplitude_value[139]; + EXPECT_EQ(last_msg_->amplitude_value[140], 60) + << "incorrect value for amplitude_value[140], expected 60, is " + << last_msg_->amplitude_value[140]; + EXPECT_EQ(last_msg_->amplitude_value[141], 231) + << "incorrect value for amplitude_value[141], expected 231, is " + << last_msg_->amplitude_value[141]; + EXPECT_EQ(last_msg_->amplitude_value[142], 163) + << "incorrect value for amplitude_value[142], expected 163, is " + << last_msg_->amplitude_value[142]; + EXPECT_EQ(last_msg_->amplitude_value[143], 163) + << "incorrect value for amplitude_value[143], expected 163, is " + << last_msg_->amplitude_value[143]; + EXPECT_EQ(last_msg_->amplitude_value[144], 49) + << "incorrect value for amplitude_value[144], expected 49, is " + << last_msg_->amplitude_value[144]; + EXPECT_EQ(last_msg_->amplitude_value[145], 237) + << "incorrect value for amplitude_value[145], expected 237, is " + << last_msg_->amplitude_value[145]; + EXPECT_EQ(last_msg_->amplitude_value[146], 244) + << "incorrect value for amplitude_value[146], expected 244, is " + << last_msg_->amplitude_value[146]; + EXPECT_EQ(last_msg_->amplitude_value[147], 185) + << "incorrect value for amplitude_value[147], expected 185, is " + << last_msg_->amplitude_value[147]; + EXPECT_EQ(last_msg_->amplitude_value[148], 240) + << "incorrect value for amplitude_value[148], expected 240, is " + << last_msg_->amplitude_value[148]; + EXPECT_EQ(last_msg_->amplitude_value[149], 89) + << "incorrect value for amplitude_value[149], expected 89, is " + << last_msg_->amplitude_value[149]; + EXPECT_EQ(last_msg_->amplitude_value[150], 143) + << "incorrect value for amplitude_value[150], expected 143, is " + << last_msg_->amplitude_value[150]; + EXPECT_EQ(last_msg_->amplitude_value[151], 174) + << "incorrect value for amplitude_value[151], expected 174, is " + << last_msg_->amplitude_value[151]; + EXPECT_EQ(last_msg_->amplitude_value[152], 165) + << "incorrect value for amplitude_value[152], expected 165, is " + << last_msg_->amplitude_value[152]; + EXPECT_EQ(last_msg_->amplitude_value[153], 211) + << "incorrect value for amplitude_value[153], expected 211, is " + << last_msg_->amplitude_value[153]; + EXPECT_EQ(last_msg_->amplitude_value[154], 241) + << "incorrect value for amplitude_value[154], expected 241, is " + << last_msg_->amplitude_value[154]; + EXPECT_EQ(last_msg_->amplitude_value[155], 13) + << "incorrect value for amplitude_value[155], expected 13, is " + << last_msg_->amplitude_value[155]; + EXPECT_EQ(last_msg_->amplitude_value[156], 16) + << "incorrect value for amplitude_value[156], expected 16, is " + << last_msg_->amplitude_value[156]; + EXPECT_EQ(last_msg_->amplitude_value[157], 61) + << "incorrect value for amplitude_value[157], expected 61, is " + << last_msg_->amplitude_value[157]; + EXPECT_EQ(last_msg_->amplitude_value[158], 141) + << "incorrect value for amplitude_value[158], expected 141, is " + << last_msg_->amplitude_value[158]; + EXPECT_EQ(last_msg_->amplitude_value[159], 101) + << "incorrect value for amplitude_value[159], expected 101, is " + << last_msg_->amplitude_value[159]; + EXPECT_EQ(last_msg_->amplitude_value[160], 89) + << "incorrect value for amplitude_value[160], expected 89, is " + << last_msg_->amplitude_value[160]; + EXPECT_EQ(last_msg_->amplitude_value[161], 37) + << "incorrect value for amplitude_value[161], expected 37, is " + << last_msg_->amplitude_value[161]; + EXPECT_EQ(last_msg_->amplitude_value[162], 117) + << "incorrect value for amplitude_value[162], expected 117, is " + << last_msg_->amplitude_value[162]; + EXPECT_EQ(last_msg_->amplitude_value[163], 189) + << "incorrect value for amplitude_value[163], expected 189, is " + << last_msg_->amplitude_value[163]; + EXPECT_EQ(last_msg_->amplitude_value[164], 86) + << "incorrect value for amplitude_value[164], expected 86, is " + << last_msg_->amplitude_value[164]; + EXPECT_EQ(last_msg_->amplitude_value[165], 118) + << "incorrect value for amplitude_value[165], expected 118, is " + << last_msg_->amplitude_value[165]; + EXPECT_EQ(last_msg_->amplitude_value[166], 176) + << "incorrect value for amplitude_value[166], expected 176, is " + << last_msg_->amplitude_value[166]; + EXPECT_EQ(last_msg_->amplitude_value[167], 228) + << "incorrect value for amplitude_value[167], expected 228, is " + << last_msg_->amplitude_value[167]; + EXPECT_EQ(last_msg_->amplitude_value[168], 12) + << "incorrect value for amplitude_value[168], expected 12, is " + << last_msg_->amplitude_value[168]; + EXPECT_EQ(last_msg_->amplitude_value[169], 14) + << "incorrect value for amplitude_value[169], expected 14, is " + << last_msg_->amplitude_value[169]; + EXPECT_EQ(last_msg_->amplitude_value[170], 119) + << "incorrect value for amplitude_value[170], expected 119, is " + << last_msg_->amplitude_value[170]; + EXPECT_EQ(last_msg_->amplitude_value[171], 135) + << "incorrect value for amplitude_value[171], expected 135, is " + << last_msg_->amplitude_value[171]; + EXPECT_EQ(last_msg_->amplitude_value[172], 129) + << "incorrect value for amplitude_value[172], expected 129, is " + << last_msg_->amplitude_value[172]; + EXPECT_EQ(last_msg_->amplitude_value[173], 243) + << "incorrect value for amplitude_value[173], expected 243, is " + << last_msg_->amplitude_value[173]; + EXPECT_EQ(last_msg_->amplitude_value[174], 50) + << "incorrect value for amplitude_value[174], expected 50, is " + << last_msg_->amplitude_value[174]; + EXPECT_EQ(last_msg_->amplitude_value[175], 29) + << "incorrect value for amplitude_value[175], expected 29, is " + << last_msg_->amplitude_value[175]; + EXPECT_EQ(last_msg_->amplitude_value[176], 207) + << "incorrect value for amplitude_value[176], expected 207, is " + << last_msg_->amplitude_value[176]; + EXPECT_EQ(last_msg_->amplitude_value[177], 198) + << "incorrect value for amplitude_value[177], expected 198, is " + << last_msg_->amplitude_value[177]; + EXPECT_EQ(last_msg_->amplitude_value[178], 117) + << "incorrect value for amplitude_value[178], expected 117, is " + << last_msg_->amplitude_value[178]; + EXPECT_EQ(last_msg_->amplitude_value[179], 100) + << "incorrect value for amplitude_value[179], expected 100, is " + << last_msg_->amplitude_value[179]; + EXPECT_EQ(last_msg_->amplitude_value[180], 225) + << "incorrect value for amplitude_value[180], expected 225, is " + << last_msg_->amplitude_value[180]; + EXPECT_EQ(last_msg_->amplitude_value[181], 6) + << "incorrect value for amplitude_value[181], expected 6, is " + << last_msg_->amplitude_value[181]; + EXPECT_EQ(last_msg_->amplitude_value[182], 139) + << "incorrect value for amplitude_value[182], expected 139, is " + << last_msg_->amplitude_value[182]; + EXPECT_EQ(last_msg_->amplitude_value[183], 110) + << "incorrect value for amplitude_value[183], expected 110, is " + << last_msg_->amplitude_value[183]; + EXPECT_EQ(last_msg_->amplitude_value[184], 39) + << "incorrect value for amplitude_value[184], expected 39, is " + << last_msg_->amplitude_value[184]; + EXPECT_EQ(last_msg_->amplitude_value[185], 210) + << "incorrect value for amplitude_value[185], expected 210, is " + << last_msg_->amplitude_value[185]; + EXPECT_EQ(last_msg_->amplitude_value[186], 68) + << "incorrect value for amplitude_value[186], expected 68, is " + << last_msg_->amplitude_value[186]; + EXPECT_EQ(last_msg_->amplitude_value[187], 199) + << "incorrect value for amplitude_value[187], expected 199, is " + << last_msg_->amplitude_value[187]; + EXPECT_EQ(last_msg_->amplitude_value[188], 43) + << "incorrect value for amplitude_value[188], expected 43, is " + << last_msg_->amplitude_value[188]; + EXPECT_EQ(last_msg_->amplitude_value[189], 132) + << "incorrect value for amplitude_value[189], expected 132, is " + << last_msg_->amplitude_value[189]; + EXPECT_EQ(last_msg_->amplitude_value[190], 64) + << "incorrect value for amplitude_value[190], expected 64, is " + << last_msg_->amplitude_value[190]; + EXPECT_EQ(last_msg_->amplitude_value[191], 17) + << "incorrect value for amplitude_value[191], expected 17, is " + << last_msg_->amplitude_value[191]; + EXPECT_EQ(last_msg_->amplitude_value[192], 51) + << "incorrect value for amplitude_value[192], expected 51, is " + << last_msg_->amplitude_value[192]; + EXPECT_EQ(last_msg_->amplitude_value[193], 173) + << "incorrect value for amplitude_value[193], expected 173, is " + << last_msg_->amplitude_value[193]; + EXPECT_EQ(last_msg_->amplitude_value[194], 181) + << "incorrect value for amplitude_value[194], expected 181, is " + << last_msg_->amplitude_value[194]; + EXPECT_EQ(last_msg_->amplitude_value[195], 12) + << "incorrect value for amplitude_value[195], expected 12, is " + << last_msg_->amplitude_value[195]; + EXPECT_EQ(last_msg_->amplitude_value[196], 140) + << "incorrect value for amplitude_value[196], expected 140, is " + << last_msg_->amplitude_value[196]; + EXPECT_EQ(last_msg_->amplitude_value[197], 16) + << "incorrect value for amplitude_value[197], expected 16, is " + << last_msg_->amplitude_value[197]; + EXPECT_EQ(last_msg_->amplitude_value[198], 247) + << "incorrect value for amplitude_value[198], expected 247, is " + << last_msg_->amplitude_value[198]; + EXPECT_EQ(last_msg_->amplitude_value[199], 84) + << "incorrect value for amplitude_value[199], expected 84, is " + << last_msg_->amplitude_value[199]; + EXPECT_EQ(last_msg_->amplitude_value[200], 183) + << "incorrect value for amplitude_value[200], expected 183, is " + << last_msg_->amplitude_value[200]; + EXPECT_EQ(last_msg_->amplitude_value[201], 105) + << "incorrect value for amplitude_value[201], expected 105, is " + << last_msg_->amplitude_value[201]; + EXPECT_EQ(last_msg_->amplitude_value[202], 39) + << "incorrect value for amplitude_value[202], expected 39, is " + << last_msg_->amplitude_value[202]; + EXPECT_EQ(last_msg_->amplitude_value[203], 157) + << "incorrect value for amplitude_value[203], expected 157, is " + << last_msg_->amplitude_value[203]; + EXPECT_EQ(last_msg_->amplitude_value[204], 77) + << "incorrect value for amplitude_value[204], expected 77, is " + << last_msg_->amplitude_value[204]; + EXPECT_EQ(last_msg_->amplitude_value[205], 30) + << "incorrect value for amplitude_value[205], expected 30, is " + << last_msg_->amplitude_value[205]; + EXPECT_EQ(last_msg_->amplitude_value[206], 205) + << "incorrect value for amplitude_value[206], expected 205, is " + << last_msg_->amplitude_value[206]; + EXPECT_EQ(last_msg_->amplitude_value[207], 194) + << "incorrect value for amplitude_value[207], expected 194, is " + << last_msg_->amplitude_value[207]; + EXPECT_EQ(last_msg_->amplitude_value[208], 59) + << "incorrect value for amplitude_value[208], expected 59, is " + << last_msg_->amplitude_value[208]; + EXPECT_EQ(last_msg_->amplitude_value[209], 64) + << "incorrect value for amplitude_value[209], expected 64, is " + << last_msg_->amplitude_value[209]; + EXPECT_EQ(last_msg_->amplitude_value[210], 241) + << "incorrect value for amplitude_value[210], expected 241, is " + << last_msg_->amplitude_value[210]; + EXPECT_EQ(last_msg_->amplitude_value[211], 183) + << "incorrect value for amplitude_value[211], expected 183, is " + << last_msg_->amplitude_value[211]; + EXPECT_EQ(last_msg_->amplitude_value[212], 238) + << "incorrect value for amplitude_value[212], expected 238, is " + << last_msg_->amplitude_value[212]; + EXPECT_EQ(last_msg_->amplitude_value[213], 105) + << "incorrect value for amplitude_value[213], expected 105, is " + << last_msg_->amplitude_value[213]; + EXPECT_EQ(last_msg_->amplitude_value[214], 181) + << "incorrect value for amplitude_value[214], expected 181, is " + << last_msg_->amplitude_value[214]; + EXPECT_EQ(last_msg_->amplitude_value[215], 170) + << "incorrect value for amplitude_value[215], expected 170, is " + << last_msg_->amplitude_value[215]; + EXPECT_EQ(last_msg_->amplitude_value[216], 45) + << "incorrect value for amplitude_value[216], expected 45, is " + << last_msg_->amplitude_value[216]; + EXPECT_EQ(last_msg_->amplitude_value[217], 8) + << "incorrect value for amplitude_value[217], expected 8, is " + << last_msg_->amplitude_value[217]; + EXPECT_EQ(last_msg_->amplitude_value[218], 166) + << "incorrect value for amplitude_value[218], expected 166, is " + << last_msg_->amplitude_value[218]; + EXPECT_EQ(last_msg_->amplitude_value[219], 164) + << "incorrect value for amplitude_value[219], expected 164, is " + << last_msg_->amplitude_value[219]; + EXPECT_EQ(last_msg_->amplitude_value[220], 238) + << "incorrect value for amplitude_value[220], expected 238, is " + << last_msg_->amplitude_value[220]; + EXPECT_EQ(last_msg_->amplitude_value[221], 83) + << "incorrect value for amplitude_value[221], expected 83, is " + << last_msg_->amplitude_value[221]; + EXPECT_EQ(last_msg_->amplitude_value[222], 148) + << "incorrect value for amplitude_value[222], expected 148, is " + << last_msg_->amplitude_value[222]; + EXPECT_EQ(last_msg_->amplitude_value[223], 173) + << "incorrect value for amplitude_value[223], expected 173, is " + << last_msg_->amplitude_value[223]; + EXPECT_EQ(last_msg_->amplitude_value[224], 108) + << "incorrect value for amplitude_value[224], expected 108, is " + << last_msg_->amplitude_value[224]; + EXPECT_EQ(last_msg_->amplitude_value[225], 228) + << "incorrect value for amplitude_value[225], expected 228, is " + << last_msg_->amplitude_value[225]; + EXPECT_EQ(last_msg_->amplitude_value[226], 67) + << "incorrect value for amplitude_value[226], expected 67, is " + << last_msg_->amplitude_value[226]; + EXPECT_EQ(last_msg_->amplitude_value[227], 89) + << "incorrect value for amplitude_value[227], expected 89, is " + << last_msg_->amplitude_value[227]; + EXPECT_EQ(last_msg_->amplitude_value[228], 189) + << "incorrect value for amplitude_value[228], expected 189, is " + << last_msg_->amplitude_value[228]; + EXPECT_EQ(last_msg_->amplitude_value[229], 67) + << "incorrect value for amplitude_value[229], expected 67, is " + << last_msg_->amplitude_value[229]; + EXPECT_EQ(last_msg_->amplitude_value[230], 26) + << "incorrect value for amplitude_value[230], expected 26, is " + << last_msg_->amplitude_value[230]; + EXPECT_EQ(last_msg_->channel_tag, 5878) + << "incorrect value for channel_tag, expected 5878, is " + << last_msg_->channel_tag; + EXPECT_LT((last_msg_->freq_ref * 100 - 6348.20019531 * 100), 0.05) + << "incorrect value for freq_ref, expected 6348.20019531, is " + << last_msg_->freq_ref; + EXPECT_LT((last_msg_->freq_step * 100 - 4608.20019531 * 100), 0.05) + << "incorrect value for freq_step, expected 4608.20019531, is " + << last_msg_->freq_step; + EXPECT_EQ(last_msg_->t.tow, 992295133) + << "incorrect value for t.tow, expected 992295133, is " + << last_msg_->t.tow; + EXPECT_EQ(last_msg_->t.wn, 6957) + << "incorrect value for t.wn, expected 6957, is " << last_msg_->t.wn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgUartState.cc b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgUartState.cc index 9df408440c..42641a0565 100644 --- a/c/test/legacy/cpp/auto_check_sbp_piksi_MsgUartState.cc +++ b/c/test/legacy/cpp/auto_check_sbp_piksi_MsgUartState.cc @@ -23,9 +23,203 @@ class Test_legacy_auto_check_sbp_piksi_MsgUartState0 public sbp::State, public sbp::IReader, public sbp::IWriter, - sbp::PayloadHandler { + sbp::PayloadHandler { public: Test_legacy_auto_check_sbp_piksi_MsgUartState0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_uart_state_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_uart_state_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState0, Test) { + uint8_t encoded_frame[] = { + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, + 89, 98, 79, 184, 138, 244, 154, 73, 201, 69, 154, 65, 211, 69, + 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, 51, 211, 7, 69, + 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, + 10, 113, 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, + 107, 111, 253, 168, 244, 158, 112, 19, 251, 131, 100, 225, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_uart_state_t *test_msg = (msg_uart_state_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->latency.avg = 319865629; + test_msg->latency.current = 364253831; + test_msg->latency.lmax = -611749622; + test_msg->latency.lmin = 289902239; + test_msg->obs_period.avg = -1002717658; + test_msg->obs_period.current = -2080697488; + test_msg->obs_period.pmax = -1628133123; + test_msg->obs_period.pmin = 1869323177; + test_msg->uart_a.crc_error_count = 25177; + test_msg->uart_a.io_error_count = 47183; + test_msg->uart_a.rx_buffer_level = 244; + test_msg->uart_a.rx_throughput = 1853.199951171875; + test_msg->uart_a.tx_buffer_level = 138; + test_msg->uart_a.tx_throughput = 7765.2001953125; + test_msg->uart_b.crc_error_count = 4297; + test_msg->uart_b.io_error_count = 63847; + test_msg->uart_b.rx_buffer_level = 161; + test_msg->uart_b.rx_throughput = 6760.2001953125; + test_msg->uart_b.tx_buffer_level = 143; + test_msg->uart_b.tx_throughput = 6441.2001953125; + test_msg->uart_ftdi.crc_error_count = 38359; + test_msg->uart_ftdi.io_error_count = 6653; + test_msg->uart_ftdi.rx_buffer_level = 24; + test_msg->uart_ftdi.rx_throughput = 2173.199951171875; + test_msg->uart_ftdi.tx_buffer_level = 218; + test_msg->uart_ftdi.tx_throughput = 5954.2001953125; + + EXPECT_EQ(send_message(0x1d, 57544, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 57544); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->latency.avg, 319865629) + << "incorrect value for latency.avg, expected 319865629, is " + << last_msg_->latency.avg; + EXPECT_EQ(last_msg_->latency.current, 364253831) + << "incorrect value for latency.current, expected 364253831, is " + << last_msg_->latency.current; + EXPECT_EQ(last_msg_->latency.lmax, -611749622) + << "incorrect value for latency.lmax, expected -611749622, is " + << last_msg_->latency.lmax; + EXPECT_EQ(last_msg_->latency.lmin, 289902239) + << "incorrect value for latency.lmin, expected 289902239, is " + << last_msg_->latency.lmin; + EXPECT_EQ(last_msg_->obs_period.avg, -1002717658) + << "incorrect value for obs_period.avg, expected -1002717658, is " + << last_msg_->obs_period.avg; + EXPECT_EQ(last_msg_->obs_period.current, -2080697488) + << "incorrect value for obs_period.current, expected -2080697488, is " + << last_msg_->obs_period.current; + EXPECT_EQ(last_msg_->obs_period.pmax, -1628133123) + << "incorrect value for obs_period.pmax, expected -1628133123, is " + << last_msg_->obs_period.pmax; + EXPECT_EQ(last_msg_->obs_period.pmin, 1869323177) + << "incorrect value for obs_period.pmin, expected 1869323177, is " + << last_msg_->obs_period.pmin; + EXPECT_EQ(last_msg_->uart_a.crc_error_count, 25177) + << "incorrect value for uart_a.crc_error_count, expected 25177, is " + << last_msg_->uart_a.crc_error_count; + EXPECT_EQ(last_msg_->uart_a.io_error_count, 47183) + << "incorrect value for uart_a.io_error_count, expected 47183, is " + << last_msg_->uart_a.io_error_count; + EXPECT_EQ(last_msg_->uart_a.rx_buffer_level, 244) + << "incorrect value for uart_a.rx_buffer_level, expected 244, is " + << last_msg_->uart_a.rx_buffer_level; + EXPECT_LT((last_msg_->uart_a.rx_throughput * 100 - 1853.19995117 * 100), 0.05) + << "incorrect value for uart_a.rx_throughput, expected 1853.19995117, is " + << last_msg_->uart_a.rx_throughput; + EXPECT_EQ(last_msg_->uart_a.tx_buffer_level, 138) + << "incorrect value for uart_a.tx_buffer_level, expected 138, is " + << last_msg_->uart_a.tx_buffer_level; + EXPECT_LT((last_msg_->uart_a.tx_throughput * 100 - 7765.20019531 * 100), 0.05) + << "incorrect value for uart_a.tx_throughput, expected 7765.20019531, is " + << last_msg_->uart_a.tx_throughput; + EXPECT_EQ(last_msg_->uart_b.crc_error_count, 4297) + << "incorrect value for uart_b.crc_error_count, expected 4297, is " + << last_msg_->uart_b.crc_error_count; + EXPECT_EQ(last_msg_->uart_b.io_error_count, 63847) + << "incorrect value for uart_b.io_error_count, expected 63847, is " + << last_msg_->uart_b.io_error_count; + EXPECT_EQ(last_msg_->uart_b.rx_buffer_level, 161) + << "incorrect value for uart_b.rx_buffer_level, expected 161, is " + << last_msg_->uart_b.rx_buffer_level; + EXPECT_LT((last_msg_->uart_b.rx_throughput * 100 - 6760.20019531 * 100), 0.05) + << "incorrect value for uart_b.rx_throughput, expected 6760.20019531, is " + << last_msg_->uart_b.rx_throughput; + EXPECT_EQ(last_msg_->uart_b.tx_buffer_level, 143) + << "incorrect value for uart_b.tx_buffer_level, expected 143, is " + << last_msg_->uart_b.tx_buffer_level; + EXPECT_LT((last_msg_->uart_b.tx_throughput * 100 - 6441.20019531 * 100), 0.05) + << "incorrect value for uart_b.tx_throughput, expected 6441.20019531, is " + << last_msg_->uart_b.tx_throughput; + EXPECT_EQ(last_msg_->uart_ftdi.crc_error_count, 38359) + << "incorrect value for uart_ftdi.crc_error_count, expected 38359, is " + << last_msg_->uart_ftdi.crc_error_count; + EXPECT_EQ(last_msg_->uart_ftdi.io_error_count, 6653) + << "incorrect value for uart_ftdi.io_error_count, expected 6653, is " + << last_msg_->uart_ftdi.io_error_count; + EXPECT_EQ(last_msg_->uart_ftdi.rx_buffer_level, 24) + << "incorrect value for uart_ftdi.rx_buffer_level, expected 24, is " + << last_msg_->uart_ftdi.rx_buffer_level; + EXPECT_LT((last_msg_->uart_ftdi.rx_throughput * 100 - 2173.19995117 * 100), + 0.05) + << "incorrect value for uart_ftdi.rx_throughput, expected 2173.19995117, " + "is " + << last_msg_->uart_ftdi.rx_throughput; + EXPECT_EQ(last_msg_->uart_ftdi.tx_buffer_level, 218) + << "incorrect value for uart_ftdi.tx_buffer_level, expected 218, is " + << last_msg_->uart_ftdi.tx_buffer_level; + EXPECT_LT((last_msg_->uart_ftdi.tx_throughput * 100 - 5954.20019531 * 100), + 0.05) + << "incorrect value for uart_ftdi.tx_throughput, expected 5954.20019531, " + "is " + << last_msg_->uart_ftdi.tx_throughput; +} +class Test_legacy_auto_check_sbp_piksi_MsgUartState1 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_piksi_MsgUartState1() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -76,7 +270,7 @@ class Test_legacy_auto_check_sbp_piksi_MsgUartState0 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState0, Test) { +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState1, Test) { uint8_t encoded_frame[] = { 85, 24, 0, 246, 215, 58, 26, 191, 93, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 123, 50, 62, 64, 0, 0, 0, 0, @@ -197,14 +391,14 @@ TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState0, Test) { "is " << last_msg_->uart_ftdi.tx_throughput; } -class Test_legacy_auto_check_sbp_piksi_MsgUartState1 +class Test_legacy_auto_check_sbp_piksi_MsgUartState2 : public ::testing::Test, public sbp::State, public sbp::IReader, public sbp::IWriter, sbp::PayloadHandler { public: - Test_legacy_auto_check_sbp_piksi_MsgUartState1() + Test_legacy_auto_check_sbp_piksi_MsgUartState2() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -255,7 +449,7 @@ class Test_legacy_auto_check_sbp_piksi_MsgUartState1 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState1, Test) { +TEST_F(Test_legacy_auto_check_sbp_piksi_MsgUartState2, Test) { uint8_t encoded_frame[] = { 85, 24, 0, 246, 215, 58, 237, 232, 95, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 198, 186, 63, 64, 0, 0, 0, 0, diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc new file mode 100644 index 0000000000..f69d2b70e1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadByIndexReq.cc @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_read_by_index_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_read_by_index_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsReadByIndexReq0, Test) { + uint8_t encoded_frame[] = { + 85, 162, 0, 122, 123, 2, 244, 34, 235, 23, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_read_by_index_req_t *test_msg = + (msg_settings_read_by_index_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->index = 8948; + + EXPECT_EQ(send_message(0xa2, 31610, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 31610); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->index, 8948) + << "incorrect value for index, expected 8948, is " << last_msg_->index; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc new file mode 100644 index 0000000000..a7c00160e5 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadReq.cc @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsReadReq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsReadReq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_read_req_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_read_req_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsReadReq0, Test) { + uint8_t encoded_frame[] = { + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_read_req_t *test_msg = + (msg_settings_read_req_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xa4, 54936, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 54936); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc new file mode 100644 index 0000000000..76e73e270a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsReadResp.cc @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsReadResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsReadResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_read_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_read_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsReadResp0, Test) { + uint8_t encoded_frame[] = { + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, + 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, + 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, + 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, + 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 203, 199, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_read_resp_t *test_msg = + (msg_settings_read_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xa5, 61576, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 61576); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc new file mode 100644 index 0000000000..3c6ce5e1b9 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegister.cc @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsRegister0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsRegister0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_register_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_register_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsRegister0, Test) { + uint8_t encoded_frame[] = { + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, + 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, + 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, 101, + 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, 97, + 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 142, 235, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_register_t *test_msg = + (msg_settings_register_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xae, 1620, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1620); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc new file mode 100644 index 0000000000..33daab26bc --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsRegisterResp.cc @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_register_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_register_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsRegisterResp0, Test) { + uint8_t encoded_frame[] = { + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, 110, 45, + 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, + 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, + 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, + 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 82, 16, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_register_resp_t *test_msg = + (msg_settings_register_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->status = 18; + + EXPECT_EQ(send_message(0x1af, 54569, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 54569); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } + EXPECT_EQ(last_msg_->status, 18) + << "incorrect value for status, expected 18, is " << last_msg_->status; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsSave.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsSave.cc new file mode 100644 index 0000000000..c8b4acc7e6 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsSave.cc @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc new file mode 100644 index 0000000000..0ed876462d --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWrite.cc @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsWrite0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsWrite0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_write_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_write_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsWrite0, Test) { + uint8_t encoded_frame[] = { + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, + 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_write_t *test_msg = (msg_settings_write_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xa0, 123, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 123); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc new file mode 100644 index 0000000000..6a050b6b1c --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_settings_MsgSettingsWriteResp.cc @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_settings_MsgSettingsWriteResp0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_settings_MsgSettingsWriteResp0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_settings_write_resp_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_settings_write_resp_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_settings_MsgSettingsWriteResp0, Test) { + uint8_t encoded_frame[] = { + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, 110, 45, + 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, + 109, 101, 0, 115, 101, 116, 116, 105, 110, 103, 45, 118, 97, 108, 117, + 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, 44, 118, + 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_settings_write_resp_t *test_msg = + (msg_settings_write_resp_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + { + const char assign_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + memcpy(test_msg->setting, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->setting) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + test_msg->status = 152; + + EXPECT_EQ(send_message(0xaf, 14171, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 14171); + EXPECT_EQ(last_msg_len_, test_msg_len); + { + const char check_string[] = { + (char)115, (char)101, (char)99, (char)116, (char)105, (char)111, + (char)110, (char)45, (char)110, (char)97, (char)109, (char)101, + (char)0, (char)115, (char)101, (char)116, (char)116, (char)105, + (char)110, (char)103, (char)45, (char)110, (char)97, (char)109, + (char)101, (char)0, (char)115, (char)101, (char)116, (char)116, + (char)105, (char)110, (char)103, (char)45, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)0, (char)101, (char)110, + (char)117, (char)109, (char)59, (char)118, (char)97, (char)108, + (char)117, (char)101, (char)49, (char)44, (char)118, (char)97, + (char)108, (char)117, (char)101, (char)50, (char)44, (char)118, + (char)97, (char)108, (char)117, (char)101, (char)51, (char)0}; + EXPECT_EQ(memcmp(last_msg_->setting, check_string, sizeof(check_string)), 0) + << "incorrect value for last_msg_->setting, expected string '" + << check_string << "', is '" << last_msg_->setting << "'"; + } + EXPECT_EQ(last_msg_->status, 152) + << "incorrect value for status, expected 152, is " << last_msg_->status; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc b/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc new file mode 100644 index 0000000000..7e5c1c50f1 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMeta.cc @@ -0,0 +1,1567 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_solution_meta_MsgSolnMeta0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_solution_meta_MsgSolnMeta0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_soln_meta_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_soln_meta_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_solution_meta_MsgSolnMeta0, Test) { + uint8_t encoded_frame[] = { + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, 144, + 228, 8, 83, 89, 87, 3, 213, 95, 109, 86, 131, 71, 70, 84, 73, + 131, 26, 82, 247, 140, 97, 115, 110, 118, 253, 2, 122, 186, 148, 122, + 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, 208, 89, 56, 10, + 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, 238, 123, 102, 230, 76, + 190, 225, 182, 207, 228, 7, 218, 117, 89, 29, 191, 56, 248, 185, 255, + 46, 18, 72, 142, 82, 113, 26, 4, 172, 254, 178, 136, 113, 115, 58, + 193, 89, 227, 182, 246, 76, 77, 108, 245, 41, 31, 70, 124, 249, 145, + 15, 78, 228, 38, 241, 129, 8, 176, 251, 72, 248, 80, 115, 244, 231, + 145, 191, 190, 178, 168, 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, + 92, 79, 101, 223, 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, + 36, 219, 56, 146, 90, 219, 104, 227, 102, 83, 12, 41, 122, 173, 94, + 1, 174, 134, 130, 104, 237, 116, 249, 107, 230, 130, 123, 25, 162, 57, + 223, 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, 100, 66, 72, + 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, 141, + 25, 183, 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, 180, 46, + 140, 130, 36, 17, 194, 209, 65, 254, 115, 103, 152, 129, 234, 235, 194, + 234, 170, 201, 210, 154, 150, 247, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_soln_meta_t *test_msg = (msg_soln_meta_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->age_corrections = 21256; + test_msg->age_gnss = 3573765977; + test_msg->hdop = 41156; + test_msg->pdop = 11642; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[0].flags = 109; + test_msg->sol_in[0].sensor_type = 95; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[1].flags = 131; + test_msg->sol_in[1].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[2].flags = 70; + test_msg->sol_in[2].sensor_type = 71; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[3].flags = 73; + test_msg->sol_in[3].sensor_type = 84; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[4].flags = 26; + test_msg->sol_in[4].sensor_type = 131; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[5].flags = 247; + test_msg->sol_in[5].sensor_type = 82; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[6].flags = 97; + test_msg->sol_in[6].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[7].flags = 110; + test_msg->sol_in[7].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[8].flags = 253; + test_msg->sol_in[8].sensor_type = 118; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[9].flags = 122; + test_msg->sol_in[9].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[10].flags = 148; + test_msg->sol_in[10].sensor_type = 186; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[11].flags = 148; + test_msg->sol_in[11].sensor_type = 122; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[12].flags = 231; + test_msg->sol_in[12].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[13].flags = 46; + test_msg->sol_in[13].sensor_type = 68; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[14].flags = 102; + test_msg->sol_in[14].sensor_type = 190; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[15].flags = 48; + test_msg->sol_in[15].sensor_type = 243; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[16].flags = 15; + test_msg->sol_in[16].sensor_type = 192; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[17].flags = 89; + test_msg->sol_in[17].sensor_type = 208; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[18].flags = 10; + test_msg->sol_in[18].sensor_type = 56; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[19].flags = 2; + test_msg->sol_in[19].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[20].flags = 201; + test_msg->sol_in[20].sensor_type = 254; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[21].flags = 32; + test_msg->sol_in[21].sensor_type = 120; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[22].flags = 2; + test_msg->sol_in[22].sensor_type = 126; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[23].flags = 161; + test_msg->sol_in[23].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[24].flags = 123; + test_msg->sol_in[24].sensor_type = 238; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[25].flags = 230; + test_msg->sol_in[25].sensor_type = 102; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[26].flags = 190; + test_msg->sol_in[26].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[27].flags = 182; + test_msg->sol_in[27].sensor_type = 225; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[28].flags = 228; + test_msg->sol_in[28].sensor_type = 207; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[29].flags = 218; + test_msg->sol_in[29].sensor_type = 7; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[30].flags = 89; + test_msg->sol_in[30].sensor_type = 117; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[31].flags = 191; + test_msg->sol_in[31].sensor_type = 29; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[32].flags = 248; + test_msg->sol_in[32].sensor_type = 56; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[33].flags = 255; + test_msg->sol_in[33].sensor_type = 185; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[34].flags = 18; + test_msg->sol_in[34].sensor_type = 46; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[35].flags = 142; + test_msg->sol_in[35].sensor_type = 72; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[36].flags = 113; + test_msg->sol_in[36].sensor_type = 82; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[37].flags = 4; + test_msg->sol_in[37].sensor_type = 26; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[38].flags = 254; + test_msg->sol_in[38].sensor_type = 172; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[39].flags = 136; + test_msg->sol_in[39].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[40].flags = 115; + test_msg->sol_in[40].sensor_type = 113; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[41].flags = 193; + test_msg->sol_in[41].sensor_type = 58; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[42].flags = 227; + test_msg->sol_in[42].sensor_type = 89; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[43].flags = 246; + test_msg->sol_in[43].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[44].flags = 77; + test_msg->sol_in[44].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[45].flags = 245; + test_msg->sol_in[45].sensor_type = 108; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[46].flags = 31; + test_msg->sol_in[46].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[47].flags = 124; + test_msg->sol_in[47].sensor_type = 70; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[48].flags = 145; + test_msg->sol_in[48].sensor_type = 249; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[49].flags = 78; + test_msg->sol_in[49].sensor_type = 15; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[50].flags = 38; + test_msg->sol_in[50].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[51].flags = 129; + test_msg->sol_in[51].sensor_type = 241; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[52].flags = 176; + test_msg->sol_in[52].sensor_type = 8; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[53].flags = 72; + test_msg->sol_in[53].sensor_type = 251; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[54].flags = 80; + test_msg->sol_in[54].sensor_type = 248; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[55].flags = 244; + test_msg->sol_in[55].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[56].flags = 145; + test_msg->sol_in[56].sensor_type = 231; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[57].flags = 190; + test_msg->sol_in[57].sensor_type = 191; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[58].flags = 168; + test_msg->sol_in[58].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[59].flags = 233; + test_msg->sol_in[59].sensor_type = 89; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[60].flags = 176; + test_msg->sol_in[60].sensor_type = 69; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[61].flags = 140; + test_msg->sol_in[61].sensor_type = 174; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[62].flags = 141; + test_msg->sol_in[62].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[63].flags = 82; + test_msg->sol_in[63].sensor_type = 81; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[64].flags = 79; + test_msg->sol_in[64].sensor_type = 92; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[65].flags = 223; + test_msg->sol_in[65].sensor_type = 101; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[66].flags = 64; + test_msg->sol_in[66].sensor_type = 100; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[67].flags = 215; + test_msg->sol_in[67].sensor_type = 184; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[68].flags = 37; + test_msg->sol_in[68].sensor_type = 124; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[69].flags = 227; + test_msg->sol_in[69].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[70].flags = 102; + test_msg->sol_in[70].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[71].flags = 36; + test_msg->sol_in[71].sensor_type = 72; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[72].flags = 56; + test_msg->sol_in[72].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[73].flags = 90; + test_msg->sol_in[73].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[74].flags = 104; + test_msg->sol_in[74].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[75].flags = 102; + test_msg->sol_in[75].sensor_type = 227; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[76].flags = 12; + test_msg->sol_in[76].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[77].flags = 122; + test_msg->sol_in[77].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[78].flags = 94; + test_msg->sol_in[78].sensor_type = 173; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[79].flags = 174; + test_msg->sol_in[79].sensor_type = 1; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[80].flags = 130; + test_msg->sol_in[80].sensor_type = 134; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[81].flags = 237; + test_msg->sol_in[81].sensor_type = 104; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[82].flags = 249; + test_msg->sol_in[82].sensor_type = 116; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[83].flags = 230; + test_msg->sol_in[83].sensor_type = 107; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[84].flags = 123; + test_msg->sol_in[84].sensor_type = 130; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[85].flags = 162; + test_msg->sol_in[85].sensor_type = 25; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[86].flags = 223; + test_msg->sol_in[86].sensor_type = 57; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[87].flags = 174; + test_msg->sol_in[87].sensor_type = 193; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[88].flags = 193; + test_msg->sol_in[88].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[89].flags = 44; + test_msg->sol_in[89].sensor_type = 239; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[90].flags = 197; + test_msg->sol_in[90].sensor_type = 246; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[91].flags = 80; + test_msg->sol_in[91].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[92].flags = 100; + test_msg->sol_in[92].sensor_type = 83; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[93].flags = 72; + test_msg->sol_in[93].sensor_type = 66; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[94].flags = 137; + test_msg->sol_in[94].sensor_type = 133; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[95].flags = 82; + test_msg->sol_in[95].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[96].flags = 2; + test_msg->sol_in[96].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[97].flags = 9; + test_msg->sol_in[97].sensor_type = 96; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[98].flags = 158; + test_msg->sol_in[98].sensor_type = 96; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[99].flags = 97; + test_msg->sol_in[99].sensor_type = 134; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[100].flags = 129; + test_msg->sol_in[100].sensor_type = 43; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[101].flags = 25; + test_msg->sol_in[101].sensor_type = 141; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[102].flags = 200; + test_msg->sol_in[102].sensor_type = 183; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[103].flags = 57; + test_msg->sol_in[103].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[104].flags = 103; + test_msg->sol_in[104].sensor_type = 248; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[105].flags = 65; + test_msg->sol_in[105].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[106].flags = 15; + test_msg->sol_in[106].sensor_type = 195; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[107].flags = 21; + test_msg->sol_in[107].sensor_type = 244; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[108].flags = 46; + test_msg->sol_in[108].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[109].flags = 130; + test_msg->sol_in[109].sensor_type = 140; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[110].flags = 17; + test_msg->sol_in[110].sensor_type = 36; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[111].flags = 209; + test_msg->sol_in[111].sensor_type = 194; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[112].flags = 254; + test_msg->sol_in[112].sensor_type = 65; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[113].flags = 103; + test_msg->sol_in[113].sensor_type = 115; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[114].flags = 129; + test_msg->sol_in[114].sensor_type = 152; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[115].flags = 235; + test_msg->sol_in[115].sensor_type = 234; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[116].flags = 234; + test_msg->sol_in[116].sensor_type = 194; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[117].flags = 201; + test_msg->sol_in[117].sensor_type = 170; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[118].flags = 154; + test_msg->sol_in[118].sensor_type = 210; + test_msg->tow = 3628191792; + test_msg->vdop = 58512; + + EXPECT_EQ(send_message(0xff0e, 15360, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 15360); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->age_corrections, 21256) + << "incorrect value for age_corrections, expected 21256, is " + << last_msg_->age_corrections; + EXPECT_EQ(last_msg_->age_gnss, 3573765977) + << "incorrect value for age_gnss, expected 3573765977, is " + << last_msg_->age_gnss; + EXPECT_EQ(last_msg_->hdop, 41156) + << "incorrect value for hdop, expected 41156, is " << last_msg_->hdop; + EXPECT_EQ(last_msg_->pdop, 11642) + << "incorrect value for pdop, expected 11642, is " << last_msg_->pdop; + EXPECT_EQ(last_msg_->sol_in[0].flags, 109) + << "incorrect value for sol_in[0].flags, expected 109, is " + << last_msg_->sol_in[0].flags; + EXPECT_EQ(last_msg_->sol_in[0].sensor_type, 95) + << "incorrect value for sol_in[0].sensor_type, expected 95, is " + << last_msg_->sol_in[0].sensor_type; + EXPECT_EQ(last_msg_->sol_in[1].flags, 131) + << "incorrect value for sol_in[1].flags, expected 131, is " + << last_msg_->sol_in[1].flags; + EXPECT_EQ(last_msg_->sol_in[1].sensor_type, 86) + << "incorrect value for sol_in[1].sensor_type, expected 86, is " + << last_msg_->sol_in[1].sensor_type; + EXPECT_EQ(last_msg_->sol_in[2].flags, 70) + << "incorrect value for sol_in[2].flags, expected 70, is " + << last_msg_->sol_in[2].flags; + EXPECT_EQ(last_msg_->sol_in[2].sensor_type, 71) + << "incorrect value for sol_in[2].sensor_type, expected 71, is " + << last_msg_->sol_in[2].sensor_type; + EXPECT_EQ(last_msg_->sol_in[3].flags, 73) + << "incorrect value for sol_in[3].flags, expected 73, is " + << last_msg_->sol_in[3].flags; + EXPECT_EQ(last_msg_->sol_in[3].sensor_type, 84) + << "incorrect value for sol_in[3].sensor_type, expected 84, is " + << last_msg_->sol_in[3].sensor_type; + EXPECT_EQ(last_msg_->sol_in[4].flags, 26) + << "incorrect value for sol_in[4].flags, expected 26, is " + << last_msg_->sol_in[4].flags; + EXPECT_EQ(last_msg_->sol_in[4].sensor_type, 131) + << "incorrect value for sol_in[4].sensor_type, expected 131, is " + << last_msg_->sol_in[4].sensor_type; + EXPECT_EQ(last_msg_->sol_in[5].flags, 247) + << "incorrect value for sol_in[5].flags, expected 247, is " + << last_msg_->sol_in[5].flags; + EXPECT_EQ(last_msg_->sol_in[5].sensor_type, 82) + << "incorrect value for sol_in[5].sensor_type, expected 82, is " + << last_msg_->sol_in[5].sensor_type; + EXPECT_EQ(last_msg_->sol_in[6].flags, 97) + << "incorrect value for sol_in[6].flags, expected 97, is " + << last_msg_->sol_in[6].flags; + EXPECT_EQ(last_msg_->sol_in[6].sensor_type, 140) + << "incorrect value for sol_in[6].sensor_type, expected 140, is " + << last_msg_->sol_in[6].sensor_type; + EXPECT_EQ(last_msg_->sol_in[7].flags, 110) + << "incorrect value for sol_in[7].flags, expected 110, is " + << last_msg_->sol_in[7].flags; + EXPECT_EQ(last_msg_->sol_in[7].sensor_type, 115) + << "incorrect value for sol_in[7].sensor_type, expected 115, is " + << last_msg_->sol_in[7].sensor_type; + EXPECT_EQ(last_msg_->sol_in[8].flags, 253) + << "incorrect value for sol_in[8].flags, expected 253, is " + << last_msg_->sol_in[8].flags; + EXPECT_EQ(last_msg_->sol_in[8].sensor_type, 118) + << "incorrect value for sol_in[8].sensor_type, expected 118, is " + << last_msg_->sol_in[8].sensor_type; + EXPECT_EQ(last_msg_->sol_in[9].flags, 122) + << "incorrect value for sol_in[9].flags, expected 122, is " + << last_msg_->sol_in[9].flags; + EXPECT_EQ(last_msg_->sol_in[9].sensor_type, 2) + << "incorrect value for sol_in[9].sensor_type, expected 2, is " + << last_msg_->sol_in[9].sensor_type; + EXPECT_EQ(last_msg_->sol_in[10].flags, 148) + << "incorrect value for sol_in[10].flags, expected 148, is " + << last_msg_->sol_in[10].flags; + EXPECT_EQ(last_msg_->sol_in[10].sensor_type, 186) + << "incorrect value for sol_in[10].sensor_type, expected 186, is " + << last_msg_->sol_in[10].sensor_type; + EXPECT_EQ(last_msg_->sol_in[11].flags, 148) + << "incorrect value for sol_in[11].flags, expected 148, is " + << last_msg_->sol_in[11].flags; + EXPECT_EQ(last_msg_->sol_in[11].sensor_type, 122) + << "incorrect value for sol_in[11].sensor_type, expected 122, is " + << last_msg_->sol_in[11].sensor_type; + EXPECT_EQ(last_msg_->sol_in[12].flags, 231) + << "incorrect value for sol_in[12].flags, expected 231, is " + << last_msg_->sol_in[12].flags; + EXPECT_EQ(last_msg_->sol_in[12].sensor_type, 180) + << "incorrect value for sol_in[12].sensor_type, expected 180, is " + << last_msg_->sol_in[12].sensor_type; + EXPECT_EQ(last_msg_->sol_in[13].flags, 46) + << "incorrect value for sol_in[13].flags, expected 46, is " + << last_msg_->sol_in[13].flags; + EXPECT_EQ(last_msg_->sol_in[13].sensor_type, 68) + << "incorrect value for sol_in[13].sensor_type, expected 68, is " + << last_msg_->sol_in[13].sensor_type; + EXPECT_EQ(last_msg_->sol_in[14].flags, 102) + << "incorrect value for sol_in[14].flags, expected 102, is " + << last_msg_->sol_in[14].flags; + EXPECT_EQ(last_msg_->sol_in[14].sensor_type, 190) + << "incorrect value for sol_in[14].sensor_type, expected 190, is " + << last_msg_->sol_in[14].sensor_type; + EXPECT_EQ(last_msg_->sol_in[15].flags, 48) + << "incorrect value for sol_in[15].flags, expected 48, is " + << last_msg_->sol_in[15].flags; + EXPECT_EQ(last_msg_->sol_in[15].sensor_type, 243) + << "incorrect value for sol_in[15].sensor_type, expected 243, is " + << last_msg_->sol_in[15].sensor_type; + EXPECT_EQ(last_msg_->sol_in[16].flags, 15) + << "incorrect value for sol_in[16].flags, expected 15, is " + << last_msg_->sol_in[16].flags; + EXPECT_EQ(last_msg_->sol_in[16].sensor_type, 192) + << "incorrect value for sol_in[16].sensor_type, expected 192, is " + << last_msg_->sol_in[16].sensor_type; + EXPECT_EQ(last_msg_->sol_in[17].flags, 89) + << "incorrect value for sol_in[17].flags, expected 89, is " + << last_msg_->sol_in[17].flags; + EXPECT_EQ(last_msg_->sol_in[17].sensor_type, 208) + << "incorrect value for sol_in[17].sensor_type, expected 208, is " + << last_msg_->sol_in[17].sensor_type; + EXPECT_EQ(last_msg_->sol_in[18].flags, 10) + << "incorrect value for sol_in[18].flags, expected 10, is " + << last_msg_->sol_in[18].flags; + EXPECT_EQ(last_msg_->sol_in[18].sensor_type, 56) + << "incorrect value for sol_in[18].sensor_type, expected 56, is " + << last_msg_->sol_in[18].sensor_type; + EXPECT_EQ(last_msg_->sol_in[19].flags, 2) + << "incorrect value for sol_in[19].flags, expected 2, is " + << last_msg_->sol_in[19].flags; + EXPECT_EQ(last_msg_->sol_in[19].sensor_type, 245) + << "incorrect value for sol_in[19].sensor_type, expected 245, is " + << last_msg_->sol_in[19].sensor_type; + EXPECT_EQ(last_msg_->sol_in[20].flags, 201) + << "incorrect value for sol_in[20].flags, expected 201, is " + << last_msg_->sol_in[20].flags; + EXPECT_EQ(last_msg_->sol_in[20].sensor_type, 254) + << "incorrect value for sol_in[20].sensor_type, expected 254, is " + << last_msg_->sol_in[20].sensor_type; + EXPECT_EQ(last_msg_->sol_in[21].flags, 32) + << "incorrect value for sol_in[21].flags, expected 32, is " + << last_msg_->sol_in[21].flags; + EXPECT_EQ(last_msg_->sol_in[21].sensor_type, 120) + << "incorrect value for sol_in[21].sensor_type, expected 120, is " + << last_msg_->sol_in[21].sensor_type; + EXPECT_EQ(last_msg_->sol_in[22].flags, 2) + << "incorrect value for sol_in[22].flags, expected 2, is " + << last_msg_->sol_in[22].flags; + EXPECT_EQ(last_msg_->sol_in[22].sensor_type, 126) + << "incorrect value for sol_in[22].sensor_type, expected 126, is " + << last_msg_->sol_in[22].sensor_type; + EXPECT_EQ(last_msg_->sol_in[23].flags, 161) + << "incorrect value for sol_in[23].flags, expected 161, is " + << last_msg_->sol_in[23].flags; + EXPECT_EQ(last_msg_->sol_in[23].sensor_type, 83) + << "incorrect value for sol_in[23].sensor_type, expected 83, is " + << last_msg_->sol_in[23].sensor_type; + EXPECT_EQ(last_msg_->sol_in[24].flags, 123) + << "incorrect value for sol_in[24].flags, expected 123, is " + << last_msg_->sol_in[24].flags; + EXPECT_EQ(last_msg_->sol_in[24].sensor_type, 238) + << "incorrect value for sol_in[24].sensor_type, expected 238, is " + << last_msg_->sol_in[24].sensor_type; + EXPECT_EQ(last_msg_->sol_in[25].flags, 230) + << "incorrect value for sol_in[25].flags, expected 230, is " + << last_msg_->sol_in[25].flags; + EXPECT_EQ(last_msg_->sol_in[25].sensor_type, 102) + << "incorrect value for sol_in[25].sensor_type, expected 102, is " + << last_msg_->sol_in[25].sensor_type; + EXPECT_EQ(last_msg_->sol_in[26].flags, 190) + << "incorrect value for sol_in[26].flags, expected 190, is " + << last_msg_->sol_in[26].flags; + EXPECT_EQ(last_msg_->sol_in[26].sensor_type, 76) + << "incorrect value for sol_in[26].sensor_type, expected 76, is " + << last_msg_->sol_in[26].sensor_type; + EXPECT_EQ(last_msg_->sol_in[27].flags, 182) + << "incorrect value for sol_in[27].flags, expected 182, is " + << last_msg_->sol_in[27].flags; + EXPECT_EQ(last_msg_->sol_in[27].sensor_type, 225) + << "incorrect value for sol_in[27].sensor_type, expected 225, is " + << last_msg_->sol_in[27].sensor_type; + EXPECT_EQ(last_msg_->sol_in[28].flags, 228) + << "incorrect value for sol_in[28].flags, expected 228, is " + << last_msg_->sol_in[28].flags; + EXPECT_EQ(last_msg_->sol_in[28].sensor_type, 207) + << "incorrect value for sol_in[28].sensor_type, expected 207, is " + << last_msg_->sol_in[28].sensor_type; + EXPECT_EQ(last_msg_->sol_in[29].flags, 218) + << "incorrect value for sol_in[29].flags, expected 218, is " + << last_msg_->sol_in[29].flags; + EXPECT_EQ(last_msg_->sol_in[29].sensor_type, 7) + << "incorrect value for sol_in[29].sensor_type, expected 7, is " + << last_msg_->sol_in[29].sensor_type; + EXPECT_EQ(last_msg_->sol_in[30].flags, 89) + << "incorrect value for sol_in[30].flags, expected 89, is " + << last_msg_->sol_in[30].flags; + EXPECT_EQ(last_msg_->sol_in[30].sensor_type, 117) + << "incorrect value for sol_in[30].sensor_type, expected 117, is " + << last_msg_->sol_in[30].sensor_type; + EXPECT_EQ(last_msg_->sol_in[31].flags, 191) + << "incorrect value for sol_in[31].flags, expected 191, is " + << last_msg_->sol_in[31].flags; + EXPECT_EQ(last_msg_->sol_in[31].sensor_type, 29) + << "incorrect value for sol_in[31].sensor_type, expected 29, is " + << last_msg_->sol_in[31].sensor_type; + EXPECT_EQ(last_msg_->sol_in[32].flags, 248) + << "incorrect value for sol_in[32].flags, expected 248, is " + << last_msg_->sol_in[32].flags; + EXPECT_EQ(last_msg_->sol_in[32].sensor_type, 56) + << "incorrect value for sol_in[32].sensor_type, expected 56, is " + << last_msg_->sol_in[32].sensor_type; + EXPECT_EQ(last_msg_->sol_in[33].flags, 255) + << "incorrect value for sol_in[33].flags, expected 255, is " + << last_msg_->sol_in[33].flags; + EXPECT_EQ(last_msg_->sol_in[33].sensor_type, 185) + << "incorrect value for sol_in[33].sensor_type, expected 185, is " + << last_msg_->sol_in[33].sensor_type; + EXPECT_EQ(last_msg_->sol_in[34].flags, 18) + << "incorrect value for sol_in[34].flags, expected 18, is " + << last_msg_->sol_in[34].flags; + EXPECT_EQ(last_msg_->sol_in[34].sensor_type, 46) + << "incorrect value for sol_in[34].sensor_type, expected 46, is " + << last_msg_->sol_in[34].sensor_type; + EXPECT_EQ(last_msg_->sol_in[35].flags, 142) + << "incorrect value for sol_in[35].flags, expected 142, is " + << last_msg_->sol_in[35].flags; + EXPECT_EQ(last_msg_->sol_in[35].sensor_type, 72) + << "incorrect value for sol_in[35].sensor_type, expected 72, is " + << last_msg_->sol_in[35].sensor_type; + EXPECT_EQ(last_msg_->sol_in[36].flags, 113) + << "incorrect value for sol_in[36].flags, expected 113, is " + << last_msg_->sol_in[36].flags; + EXPECT_EQ(last_msg_->sol_in[36].sensor_type, 82) + << "incorrect value for sol_in[36].sensor_type, expected 82, is " + << last_msg_->sol_in[36].sensor_type; + EXPECT_EQ(last_msg_->sol_in[37].flags, 4) + << "incorrect value for sol_in[37].flags, expected 4, is " + << last_msg_->sol_in[37].flags; + EXPECT_EQ(last_msg_->sol_in[37].sensor_type, 26) + << "incorrect value for sol_in[37].sensor_type, expected 26, is " + << last_msg_->sol_in[37].sensor_type; + EXPECT_EQ(last_msg_->sol_in[38].flags, 254) + << "incorrect value for sol_in[38].flags, expected 254, is " + << last_msg_->sol_in[38].flags; + EXPECT_EQ(last_msg_->sol_in[38].sensor_type, 172) + << "incorrect value for sol_in[38].sensor_type, expected 172, is " + << last_msg_->sol_in[38].sensor_type; + EXPECT_EQ(last_msg_->sol_in[39].flags, 136) + << "incorrect value for sol_in[39].flags, expected 136, is " + << last_msg_->sol_in[39].flags; + EXPECT_EQ(last_msg_->sol_in[39].sensor_type, 178) + << "incorrect value for sol_in[39].sensor_type, expected 178, is " + << last_msg_->sol_in[39].sensor_type; + EXPECT_EQ(last_msg_->sol_in[40].flags, 115) + << "incorrect value for sol_in[40].flags, expected 115, is " + << last_msg_->sol_in[40].flags; + EXPECT_EQ(last_msg_->sol_in[40].sensor_type, 113) + << "incorrect value for sol_in[40].sensor_type, expected 113, is " + << last_msg_->sol_in[40].sensor_type; + EXPECT_EQ(last_msg_->sol_in[41].flags, 193) + << "incorrect value for sol_in[41].flags, expected 193, is " + << last_msg_->sol_in[41].flags; + EXPECT_EQ(last_msg_->sol_in[41].sensor_type, 58) + << "incorrect value for sol_in[41].sensor_type, expected 58, is " + << last_msg_->sol_in[41].sensor_type; + EXPECT_EQ(last_msg_->sol_in[42].flags, 227) + << "incorrect value for sol_in[42].flags, expected 227, is " + << last_msg_->sol_in[42].flags; + EXPECT_EQ(last_msg_->sol_in[42].sensor_type, 89) + << "incorrect value for sol_in[42].sensor_type, expected 89, is " + << last_msg_->sol_in[42].sensor_type; + EXPECT_EQ(last_msg_->sol_in[43].flags, 246) + << "incorrect value for sol_in[43].flags, expected 246, is " + << last_msg_->sol_in[43].flags; + EXPECT_EQ(last_msg_->sol_in[43].sensor_type, 182) + << "incorrect value for sol_in[43].sensor_type, expected 182, is " + << last_msg_->sol_in[43].sensor_type; + EXPECT_EQ(last_msg_->sol_in[44].flags, 77) + << "incorrect value for sol_in[44].flags, expected 77, is " + << last_msg_->sol_in[44].flags; + EXPECT_EQ(last_msg_->sol_in[44].sensor_type, 76) + << "incorrect value for sol_in[44].sensor_type, expected 76, is " + << last_msg_->sol_in[44].sensor_type; + EXPECT_EQ(last_msg_->sol_in[45].flags, 245) + << "incorrect value for sol_in[45].flags, expected 245, is " + << last_msg_->sol_in[45].flags; + EXPECT_EQ(last_msg_->sol_in[45].sensor_type, 108) + << "incorrect value for sol_in[45].sensor_type, expected 108, is " + << last_msg_->sol_in[45].sensor_type; + EXPECT_EQ(last_msg_->sol_in[46].flags, 31) + << "incorrect value for sol_in[46].flags, expected 31, is " + << last_msg_->sol_in[46].flags; + EXPECT_EQ(last_msg_->sol_in[46].sensor_type, 41) + << "incorrect value for sol_in[46].sensor_type, expected 41, is " + << last_msg_->sol_in[46].sensor_type; + EXPECT_EQ(last_msg_->sol_in[47].flags, 124) + << "incorrect value for sol_in[47].flags, expected 124, is " + << last_msg_->sol_in[47].flags; + EXPECT_EQ(last_msg_->sol_in[47].sensor_type, 70) + << "incorrect value for sol_in[47].sensor_type, expected 70, is " + << last_msg_->sol_in[47].sensor_type; + EXPECT_EQ(last_msg_->sol_in[48].flags, 145) + << "incorrect value for sol_in[48].flags, expected 145, is " + << last_msg_->sol_in[48].flags; + EXPECT_EQ(last_msg_->sol_in[48].sensor_type, 249) + << "incorrect value for sol_in[48].sensor_type, expected 249, is " + << last_msg_->sol_in[48].sensor_type; + EXPECT_EQ(last_msg_->sol_in[49].flags, 78) + << "incorrect value for sol_in[49].flags, expected 78, is " + << last_msg_->sol_in[49].flags; + EXPECT_EQ(last_msg_->sol_in[49].sensor_type, 15) + << "incorrect value for sol_in[49].sensor_type, expected 15, is " + << last_msg_->sol_in[49].sensor_type; + EXPECT_EQ(last_msg_->sol_in[50].flags, 38) + << "incorrect value for sol_in[50].flags, expected 38, is " + << last_msg_->sol_in[50].flags; + EXPECT_EQ(last_msg_->sol_in[50].sensor_type, 228) + << "incorrect value for sol_in[50].sensor_type, expected 228, is " + << last_msg_->sol_in[50].sensor_type; + EXPECT_EQ(last_msg_->sol_in[51].flags, 129) + << "incorrect value for sol_in[51].flags, expected 129, is " + << last_msg_->sol_in[51].flags; + EXPECT_EQ(last_msg_->sol_in[51].sensor_type, 241) + << "incorrect value for sol_in[51].sensor_type, expected 241, is " + << last_msg_->sol_in[51].sensor_type; + EXPECT_EQ(last_msg_->sol_in[52].flags, 176) + << "incorrect value for sol_in[52].flags, expected 176, is " + << last_msg_->sol_in[52].flags; + EXPECT_EQ(last_msg_->sol_in[52].sensor_type, 8) + << "incorrect value for sol_in[52].sensor_type, expected 8, is " + << last_msg_->sol_in[52].sensor_type; + EXPECT_EQ(last_msg_->sol_in[53].flags, 72) + << "incorrect value for sol_in[53].flags, expected 72, is " + << last_msg_->sol_in[53].flags; + EXPECT_EQ(last_msg_->sol_in[53].sensor_type, 251) + << "incorrect value for sol_in[53].sensor_type, expected 251, is " + << last_msg_->sol_in[53].sensor_type; + EXPECT_EQ(last_msg_->sol_in[54].flags, 80) + << "incorrect value for sol_in[54].flags, expected 80, is " + << last_msg_->sol_in[54].flags; + EXPECT_EQ(last_msg_->sol_in[54].sensor_type, 248) + << "incorrect value for sol_in[54].sensor_type, expected 248, is " + << last_msg_->sol_in[54].sensor_type; + EXPECT_EQ(last_msg_->sol_in[55].flags, 244) + << "incorrect value for sol_in[55].flags, expected 244, is " + << last_msg_->sol_in[55].flags; + EXPECT_EQ(last_msg_->sol_in[55].sensor_type, 115) + << "incorrect value for sol_in[55].sensor_type, expected 115, is " + << last_msg_->sol_in[55].sensor_type; + EXPECT_EQ(last_msg_->sol_in[56].flags, 145) + << "incorrect value for sol_in[56].flags, expected 145, is " + << last_msg_->sol_in[56].flags; + EXPECT_EQ(last_msg_->sol_in[56].sensor_type, 231) + << "incorrect value for sol_in[56].sensor_type, expected 231, is " + << last_msg_->sol_in[56].sensor_type; + EXPECT_EQ(last_msg_->sol_in[57].flags, 190) + << "incorrect value for sol_in[57].flags, expected 190, is " + << last_msg_->sol_in[57].flags; + EXPECT_EQ(last_msg_->sol_in[57].sensor_type, 191) + << "incorrect value for sol_in[57].sensor_type, expected 191, is " + << last_msg_->sol_in[57].sensor_type; + EXPECT_EQ(last_msg_->sol_in[58].flags, 168) + << "incorrect value for sol_in[58].flags, expected 168, is " + << last_msg_->sol_in[58].flags; + EXPECT_EQ(last_msg_->sol_in[58].sensor_type, 178) + << "incorrect value for sol_in[58].sensor_type, expected 178, is " + << last_msg_->sol_in[58].sensor_type; + EXPECT_EQ(last_msg_->sol_in[59].flags, 233) + << "incorrect value for sol_in[59].flags, expected 233, is " + << last_msg_->sol_in[59].flags; + EXPECT_EQ(last_msg_->sol_in[59].sensor_type, 89) + << "incorrect value for sol_in[59].sensor_type, expected 89, is " + << last_msg_->sol_in[59].sensor_type; + EXPECT_EQ(last_msg_->sol_in[60].flags, 176) + << "incorrect value for sol_in[60].flags, expected 176, is " + << last_msg_->sol_in[60].flags; + EXPECT_EQ(last_msg_->sol_in[60].sensor_type, 69) + << "incorrect value for sol_in[60].sensor_type, expected 69, is " + << last_msg_->sol_in[60].sensor_type; + EXPECT_EQ(last_msg_->sol_in[61].flags, 140) + << "incorrect value for sol_in[61].flags, expected 140, is " + << last_msg_->sol_in[61].flags; + EXPECT_EQ(last_msg_->sol_in[61].sensor_type, 174) + << "incorrect value for sol_in[61].sensor_type, expected 174, is " + << last_msg_->sol_in[61].sensor_type; + EXPECT_EQ(last_msg_->sol_in[62].flags, 141) + << "incorrect value for sol_in[62].flags, expected 141, is " + << last_msg_->sol_in[62].flags; + EXPECT_EQ(last_msg_->sol_in[62].sensor_type, 182) + << "incorrect value for sol_in[62].sensor_type, expected 182, is " + << last_msg_->sol_in[62].sensor_type; + EXPECT_EQ(last_msg_->sol_in[63].flags, 82) + << "incorrect value for sol_in[63].flags, expected 82, is " + << last_msg_->sol_in[63].flags; + EXPECT_EQ(last_msg_->sol_in[63].sensor_type, 81) + << "incorrect value for sol_in[63].sensor_type, expected 81, is " + << last_msg_->sol_in[63].sensor_type; + EXPECT_EQ(last_msg_->sol_in[64].flags, 79) + << "incorrect value for sol_in[64].flags, expected 79, is " + << last_msg_->sol_in[64].flags; + EXPECT_EQ(last_msg_->sol_in[64].sensor_type, 92) + << "incorrect value for sol_in[64].sensor_type, expected 92, is " + << last_msg_->sol_in[64].sensor_type; + EXPECT_EQ(last_msg_->sol_in[65].flags, 223) + << "incorrect value for sol_in[65].flags, expected 223, is " + << last_msg_->sol_in[65].flags; + EXPECT_EQ(last_msg_->sol_in[65].sensor_type, 101) + << "incorrect value for sol_in[65].sensor_type, expected 101, is " + << last_msg_->sol_in[65].sensor_type; + EXPECT_EQ(last_msg_->sol_in[66].flags, 64) + << "incorrect value for sol_in[66].flags, expected 64, is " + << last_msg_->sol_in[66].flags; + EXPECT_EQ(last_msg_->sol_in[66].sensor_type, 100) + << "incorrect value for sol_in[66].sensor_type, expected 100, is " + << last_msg_->sol_in[66].sensor_type; + EXPECT_EQ(last_msg_->sol_in[67].flags, 215) + << "incorrect value for sol_in[67].flags, expected 215, is " + << last_msg_->sol_in[67].flags; + EXPECT_EQ(last_msg_->sol_in[67].sensor_type, 184) + << "incorrect value for sol_in[67].sensor_type, expected 184, is " + << last_msg_->sol_in[67].sensor_type; + EXPECT_EQ(last_msg_->sol_in[68].flags, 37) + << "incorrect value for sol_in[68].flags, expected 37, is " + << last_msg_->sol_in[68].flags; + EXPECT_EQ(last_msg_->sol_in[68].sensor_type, 124) + << "incorrect value for sol_in[68].sensor_type, expected 124, is " + << last_msg_->sol_in[68].sensor_type; + EXPECT_EQ(last_msg_->sol_in[69].flags, 227) + << "incorrect value for sol_in[69].flags, expected 227, is " + << last_msg_->sol_in[69].flags; + EXPECT_EQ(last_msg_->sol_in[69].sensor_type, 21) + << "incorrect value for sol_in[69].sensor_type, expected 21, is " + << last_msg_->sol_in[69].sensor_type; + EXPECT_EQ(last_msg_->sol_in[70].flags, 102) + << "incorrect value for sol_in[70].flags, expected 102, is " + << last_msg_->sol_in[70].flags; + EXPECT_EQ(last_msg_->sol_in[70].sensor_type, 135) + << "incorrect value for sol_in[70].sensor_type, expected 135, is " + << last_msg_->sol_in[70].sensor_type; + EXPECT_EQ(last_msg_->sol_in[71].flags, 36) + << "incorrect value for sol_in[71].flags, expected 36, is " + << last_msg_->sol_in[71].flags; + EXPECT_EQ(last_msg_->sol_in[71].sensor_type, 72) + << "incorrect value for sol_in[71].sensor_type, expected 72, is " + << last_msg_->sol_in[71].sensor_type; + EXPECT_EQ(last_msg_->sol_in[72].flags, 56) + << "incorrect value for sol_in[72].flags, expected 56, is " + << last_msg_->sol_in[72].flags; + EXPECT_EQ(last_msg_->sol_in[72].sensor_type, 219) + << "incorrect value for sol_in[72].sensor_type, expected 219, is " + << last_msg_->sol_in[72].sensor_type; + EXPECT_EQ(last_msg_->sol_in[73].flags, 90) + << "incorrect value for sol_in[73].flags, expected 90, is " + << last_msg_->sol_in[73].flags; + EXPECT_EQ(last_msg_->sol_in[73].sensor_type, 146) + << "incorrect value for sol_in[73].sensor_type, expected 146, is " + << last_msg_->sol_in[73].sensor_type; + EXPECT_EQ(last_msg_->sol_in[74].flags, 104) + << "incorrect value for sol_in[74].flags, expected 104, is " + << last_msg_->sol_in[74].flags; + EXPECT_EQ(last_msg_->sol_in[74].sensor_type, 219) + << "incorrect value for sol_in[74].sensor_type, expected 219, is " + << last_msg_->sol_in[74].sensor_type; + EXPECT_EQ(last_msg_->sol_in[75].flags, 102) + << "incorrect value for sol_in[75].flags, expected 102, is " + << last_msg_->sol_in[75].flags; + EXPECT_EQ(last_msg_->sol_in[75].sensor_type, 227) + << "incorrect value for sol_in[75].sensor_type, expected 227, is " + << last_msg_->sol_in[75].sensor_type; + EXPECT_EQ(last_msg_->sol_in[76].flags, 12) + << "incorrect value for sol_in[76].flags, expected 12, is " + << last_msg_->sol_in[76].flags; + EXPECT_EQ(last_msg_->sol_in[76].sensor_type, 83) + << "incorrect value for sol_in[76].sensor_type, expected 83, is " + << last_msg_->sol_in[76].sensor_type; + EXPECT_EQ(last_msg_->sol_in[77].flags, 122) + << "incorrect value for sol_in[77].flags, expected 122, is " + << last_msg_->sol_in[77].flags; + EXPECT_EQ(last_msg_->sol_in[77].sensor_type, 41) + << "incorrect value for sol_in[77].sensor_type, expected 41, is " + << last_msg_->sol_in[77].sensor_type; + EXPECT_EQ(last_msg_->sol_in[78].flags, 94) + << "incorrect value for sol_in[78].flags, expected 94, is " + << last_msg_->sol_in[78].flags; + EXPECT_EQ(last_msg_->sol_in[78].sensor_type, 173) + << "incorrect value for sol_in[78].sensor_type, expected 173, is " + << last_msg_->sol_in[78].sensor_type; + EXPECT_EQ(last_msg_->sol_in[79].flags, 174) + << "incorrect value for sol_in[79].flags, expected 174, is " + << last_msg_->sol_in[79].flags; + EXPECT_EQ(last_msg_->sol_in[79].sensor_type, 1) + << "incorrect value for sol_in[79].sensor_type, expected 1, is " + << last_msg_->sol_in[79].sensor_type; + EXPECT_EQ(last_msg_->sol_in[80].flags, 130) + << "incorrect value for sol_in[80].flags, expected 130, is " + << last_msg_->sol_in[80].flags; + EXPECT_EQ(last_msg_->sol_in[80].sensor_type, 134) + << "incorrect value for sol_in[80].sensor_type, expected 134, is " + << last_msg_->sol_in[80].sensor_type; + EXPECT_EQ(last_msg_->sol_in[81].flags, 237) + << "incorrect value for sol_in[81].flags, expected 237, is " + << last_msg_->sol_in[81].flags; + EXPECT_EQ(last_msg_->sol_in[81].sensor_type, 104) + << "incorrect value for sol_in[81].sensor_type, expected 104, is " + << last_msg_->sol_in[81].sensor_type; + EXPECT_EQ(last_msg_->sol_in[82].flags, 249) + << "incorrect value for sol_in[82].flags, expected 249, is " + << last_msg_->sol_in[82].flags; + EXPECT_EQ(last_msg_->sol_in[82].sensor_type, 116) + << "incorrect value for sol_in[82].sensor_type, expected 116, is " + << last_msg_->sol_in[82].sensor_type; + EXPECT_EQ(last_msg_->sol_in[83].flags, 230) + << "incorrect value for sol_in[83].flags, expected 230, is " + << last_msg_->sol_in[83].flags; + EXPECT_EQ(last_msg_->sol_in[83].sensor_type, 107) + << "incorrect value for sol_in[83].sensor_type, expected 107, is " + << last_msg_->sol_in[83].sensor_type; + EXPECT_EQ(last_msg_->sol_in[84].flags, 123) + << "incorrect value for sol_in[84].flags, expected 123, is " + << last_msg_->sol_in[84].flags; + EXPECT_EQ(last_msg_->sol_in[84].sensor_type, 130) + << "incorrect value for sol_in[84].sensor_type, expected 130, is " + << last_msg_->sol_in[84].sensor_type; + EXPECT_EQ(last_msg_->sol_in[85].flags, 162) + << "incorrect value for sol_in[85].flags, expected 162, is " + << last_msg_->sol_in[85].flags; + EXPECT_EQ(last_msg_->sol_in[85].sensor_type, 25) + << "incorrect value for sol_in[85].sensor_type, expected 25, is " + << last_msg_->sol_in[85].sensor_type; + EXPECT_EQ(last_msg_->sol_in[86].flags, 223) + << "incorrect value for sol_in[86].flags, expected 223, is " + << last_msg_->sol_in[86].flags; + EXPECT_EQ(last_msg_->sol_in[86].sensor_type, 57) + << "incorrect value for sol_in[86].sensor_type, expected 57, is " + << last_msg_->sol_in[86].sensor_type; + EXPECT_EQ(last_msg_->sol_in[87].flags, 174) + << "incorrect value for sol_in[87].flags, expected 174, is " + << last_msg_->sol_in[87].flags; + EXPECT_EQ(last_msg_->sol_in[87].sensor_type, 193) + << "incorrect value for sol_in[87].sensor_type, expected 193, is " + << last_msg_->sol_in[87].sensor_type; + EXPECT_EQ(last_msg_->sol_in[88].flags, 193) + << "incorrect value for sol_in[88].flags, expected 193, is " + << last_msg_->sol_in[88].flags; + EXPECT_EQ(last_msg_->sol_in[88].sensor_type, 146) + << "incorrect value for sol_in[88].sensor_type, expected 146, is " + << last_msg_->sol_in[88].sensor_type; + EXPECT_EQ(last_msg_->sol_in[89].flags, 44) + << "incorrect value for sol_in[89].flags, expected 44, is " + << last_msg_->sol_in[89].flags; + EXPECT_EQ(last_msg_->sol_in[89].sensor_type, 239) + << "incorrect value for sol_in[89].sensor_type, expected 239, is " + << last_msg_->sol_in[89].sensor_type; + EXPECT_EQ(last_msg_->sol_in[90].flags, 197) + << "incorrect value for sol_in[90].flags, expected 197, is " + << last_msg_->sol_in[90].flags; + EXPECT_EQ(last_msg_->sol_in[90].sensor_type, 246) + << "incorrect value for sol_in[90].sensor_type, expected 246, is " + << last_msg_->sol_in[90].sensor_type; + EXPECT_EQ(last_msg_->sol_in[91].flags, 80) + << "incorrect value for sol_in[91].flags, expected 80, is " + << last_msg_->sol_in[91].flags; + EXPECT_EQ(last_msg_->sol_in[91].sensor_type, 214) + << "incorrect value for sol_in[91].sensor_type, expected 214, is " + << last_msg_->sol_in[91].sensor_type; + EXPECT_EQ(last_msg_->sol_in[92].flags, 100) + << "incorrect value for sol_in[92].flags, expected 100, is " + << last_msg_->sol_in[92].flags; + EXPECT_EQ(last_msg_->sol_in[92].sensor_type, 83) + << "incorrect value for sol_in[92].sensor_type, expected 83, is " + << last_msg_->sol_in[92].sensor_type; + EXPECT_EQ(last_msg_->sol_in[93].flags, 72) + << "incorrect value for sol_in[93].flags, expected 72, is " + << last_msg_->sol_in[93].flags; + EXPECT_EQ(last_msg_->sol_in[93].sensor_type, 66) + << "incorrect value for sol_in[93].sensor_type, expected 66, is " + << last_msg_->sol_in[93].sensor_type; + EXPECT_EQ(last_msg_->sol_in[94].flags, 137) + << "incorrect value for sol_in[94].flags, expected 137, is " + << last_msg_->sol_in[94].flags; + EXPECT_EQ(last_msg_->sol_in[94].sensor_type, 133) + << "incorrect value for sol_in[94].sensor_type, expected 133, is " + << last_msg_->sol_in[94].sensor_type; + EXPECT_EQ(last_msg_->sol_in[95].flags, 82) + << "incorrect value for sol_in[95].flags, expected 82, is " + << last_msg_->sol_in[95].flags; + EXPECT_EQ(last_msg_->sol_in[95].sensor_type, 140) + << "incorrect value for sol_in[95].sensor_type, expected 140, is " + << last_msg_->sol_in[95].sensor_type; + EXPECT_EQ(last_msg_->sol_in[96].flags, 2) + << "incorrect value for sol_in[96].flags, expected 2, is " + << last_msg_->sol_in[96].flags; + EXPECT_EQ(last_msg_->sol_in[96].sensor_type, 2) + << "incorrect value for sol_in[96].sensor_type, expected 2, is " + << last_msg_->sol_in[96].sensor_type; + EXPECT_EQ(last_msg_->sol_in[97].flags, 9) + << "incorrect value for sol_in[97].flags, expected 9, is " + << last_msg_->sol_in[97].flags; + EXPECT_EQ(last_msg_->sol_in[97].sensor_type, 96) + << "incorrect value for sol_in[97].sensor_type, expected 96, is " + << last_msg_->sol_in[97].sensor_type; + EXPECT_EQ(last_msg_->sol_in[98].flags, 158) + << "incorrect value for sol_in[98].flags, expected 158, is " + << last_msg_->sol_in[98].flags; + EXPECT_EQ(last_msg_->sol_in[98].sensor_type, 96) + << "incorrect value for sol_in[98].sensor_type, expected 96, is " + << last_msg_->sol_in[98].sensor_type; + EXPECT_EQ(last_msg_->sol_in[99].flags, 97) + << "incorrect value for sol_in[99].flags, expected 97, is " + << last_msg_->sol_in[99].flags; + EXPECT_EQ(last_msg_->sol_in[99].sensor_type, 134) + << "incorrect value for sol_in[99].sensor_type, expected 134, is " + << last_msg_->sol_in[99].sensor_type; + EXPECT_EQ(last_msg_->sol_in[100].flags, 129) + << "incorrect value for sol_in[100].flags, expected 129, is " + << last_msg_->sol_in[100].flags; + EXPECT_EQ(last_msg_->sol_in[100].sensor_type, 43) + << "incorrect value for sol_in[100].sensor_type, expected 43, is " + << last_msg_->sol_in[100].sensor_type; + EXPECT_EQ(last_msg_->sol_in[101].flags, 25) + << "incorrect value for sol_in[101].flags, expected 25, is " + << last_msg_->sol_in[101].flags; + EXPECT_EQ(last_msg_->sol_in[101].sensor_type, 141) + << "incorrect value for sol_in[101].sensor_type, expected 141, is " + << last_msg_->sol_in[101].sensor_type; + EXPECT_EQ(last_msg_->sol_in[102].flags, 200) + << "incorrect value for sol_in[102].flags, expected 200, is " + << last_msg_->sol_in[102].flags; + EXPECT_EQ(last_msg_->sol_in[102].sensor_type, 183) + << "incorrect value for sol_in[102].sensor_type, expected 183, is " + << last_msg_->sol_in[102].sensor_type; + EXPECT_EQ(last_msg_->sol_in[103].flags, 57) + << "incorrect value for sol_in[103].flags, expected 57, is " + << last_msg_->sol_in[103].flags; + EXPECT_EQ(last_msg_->sol_in[103].sensor_type, 214) + << "incorrect value for sol_in[103].sensor_type, expected 214, is " + << last_msg_->sol_in[103].sensor_type; + EXPECT_EQ(last_msg_->sol_in[104].flags, 103) + << "incorrect value for sol_in[104].flags, expected 103, is " + << last_msg_->sol_in[104].flags; + EXPECT_EQ(last_msg_->sol_in[104].sensor_type, 248) + << "incorrect value for sol_in[104].sensor_type, expected 248, is " + << last_msg_->sol_in[104].sensor_type; + EXPECT_EQ(last_msg_->sol_in[105].flags, 65) + << "incorrect value for sol_in[105].flags, expected 65, is " + << last_msg_->sol_in[105].flags; + EXPECT_EQ(last_msg_->sol_in[105].sensor_type, 222) + << "incorrect value for sol_in[105].sensor_type, expected 222, is " + << last_msg_->sol_in[105].sensor_type; + EXPECT_EQ(last_msg_->sol_in[106].flags, 15) + << "incorrect value for sol_in[106].flags, expected 15, is " + << last_msg_->sol_in[106].flags; + EXPECT_EQ(last_msg_->sol_in[106].sensor_type, 195) + << "incorrect value for sol_in[106].sensor_type, expected 195, is " + << last_msg_->sol_in[106].sensor_type; + EXPECT_EQ(last_msg_->sol_in[107].flags, 21) + << "incorrect value for sol_in[107].flags, expected 21, is " + << last_msg_->sol_in[107].flags; + EXPECT_EQ(last_msg_->sol_in[107].sensor_type, 244) + << "incorrect value for sol_in[107].sensor_type, expected 244, is " + << last_msg_->sol_in[107].sensor_type; + EXPECT_EQ(last_msg_->sol_in[108].flags, 46) + << "incorrect value for sol_in[108].flags, expected 46, is " + << last_msg_->sol_in[108].flags; + EXPECT_EQ(last_msg_->sol_in[108].sensor_type, 180) + << "incorrect value for sol_in[108].sensor_type, expected 180, is " + << last_msg_->sol_in[108].sensor_type; + EXPECT_EQ(last_msg_->sol_in[109].flags, 130) + << "incorrect value for sol_in[109].flags, expected 130, is " + << last_msg_->sol_in[109].flags; + EXPECT_EQ(last_msg_->sol_in[109].sensor_type, 140) + << "incorrect value for sol_in[109].sensor_type, expected 140, is " + << last_msg_->sol_in[109].sensor_type; + EXPECT_EQ(last_msg_->sol_in[110].flags, 17) + << "incorrect value for sol_in[110].flags, expected 17, is " + << last_msg_->sol_in[110].flags; + EXPECT_EQ(last_msg_->sol_in[110].sensor_type, 36) + << "incorrect value for sol_in[110].sensor_type, expected 36, is " + << last_msg_->sol_in[110].sensor_type; + EXPECT_EQ(last_msg_->sol_in[111].flags, 209) + << "incorrect value for sol_in[111].flags, expected 209, is " + << last_msg_->sol_in[111].flags; + EXPECT_EQ(last_msg_->sol_in[111].sensor_type, 194) + << "incorrect value for sol_in[111].sensor_type, expected 194, is " + << last_msg_->sol_in[111].sensor_type; + EXPECT_EQ(last_msg_->sol_in[112].flags, 254) + << "incorrect value for sol_in[112].flags, expected 254, is " + << last_msg_->sol_in[112].flags; + EXPECT_EQ(last_msg_->sol_in[112].sensor_type, 65) + << "incorrect value for sol_in[112].sensor_type, expected 65, is " + << last_msg_->sol_in[112].sensor_type; + EXPECT_EQ(last_msg_->sol_in[113].flags, 103) + << "incorrect value for sol_in[113].flags, expected 103, is " + << last_msg_->sol_in[113].flags; + EXPECT_EQ(last_msg_->sol_in[113].sensor_type, 115) + << "incorrect value for sol_in[113].sensor_type, expected 115, is " + << last_msg_->sol_in[113].sensor_type; + EXPECT_EQ(last_msg_->sol_in[114].flags, 129) + << "incorrect value for sol_in[114].flags, expected 129, is " + << last_msg_->sol_in[114].flags; + EXPECT_EQ(last_msg_->sol_in[114].sensor_type, 152) + << "incorrect value for sol_in[114].sensor_type, expected 152, is " + << last_msg_->sol_in[114].sensor_type; + EXPECT_EQ(last_msg_->sol_in[115].flags, 235) + << "incorrect value for sol_in[115].flags, expected 235, is " + << last_msg_->sol_in[115].flags; + EXPECT_EQ(last_msg_->sol_in[115].sensor_type, 234) + << "incorrect value for sol_in[115].sensor_type, expected 234, is " + << last_msg_->sol_in[115].sensor_type; + EXPECT_EQ(last_msg_->sol_in[116].flags, 234) + << "incorrect value for sol_in[116].flags, expected 234, is " + << last_msg_->sol_in[116].flags; + EXPECT_EQ(last_msg_->sol_in[116].sensor_type, 194) + << "incorrect value for sol_in[116].sensor_type, expected 194, is " + << last_msg_->sol_in[116].sensor_type; + EXPECT_EQ(last_msg_->sol_in[117].flags, 201) + << "incorrect value for sol_in[117].flags, expected 201, is " + << last_msg_->sol_in[117].flags; + EXPECT_EQ(last_msg_->sol_in[117].sensor_type, 170) + << "incorrect value for sol_in[117].sensor_type, expected 170, is " + << last_msg_->sol_in[117].sensor_type; + EXPECT_EQ(last_msg_->sol_in[118].flags, 154) + << "incorrect value for sol_in[118].flags, expected 154, is " + << last_msg_->sol_in[118].flags; + EXPECT_EQ(last_msg_->sol_in[118].sensor_type, 210) + << "incorrect value for sol_in[118].sensor_type, expected 210, is " + << last_msg_->sol_in[118].sensor_type; + EXPECT_EQ(last_msg_->tow, 3628191792) + << "incorrect value for tow, expected 3628191792, is " << last_msg_->tow; + EXPECT_EQ(last_msg_->vdop, 58512) + << "incorrect value for vdop, expected 58512, is " << last_msg_->vdop; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc b/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc new file mode 100644 index 0000000000..269a8226bc --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_solution_meta_MsgSolnMetaDepA.cc @@ -0,0 +1,1563 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_soln_meta_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_soln_meta_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_solution_meta_MsgSolnMetaDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, 190, + 115, 93, 59, 103, 36, 83, 161, 156, 46, 253, 67, 87, 200, 39, 250, + 245, 242, 228, 72, 18, 222, 11, 88, 207, 218, 231, 13, 226, 224, 22, + 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, 146, 40, 204, 51, + 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, 240, 190, 93, 219, 103, + 42, 41, 182, 76, 222, 17, 23, 125, 31, 18, 229, 28, 47, 214, 25, + 100, 84, 106, 72, 48, 10, 222, 232, 235, 73, 109, 163, 51, 152, 133, + 235, 87, 70, 2, 108, 91, 101, 200, 55, 24, 156, 233, 73, 39, 66, + 97, 140, 252, 227, 230, 237, 135, 241, 245, 205, 70, 0, 219, 188, 107, + 136, 178, 58, 1, 29, 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, + 203, 18, 3, 222, 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, + 159, 174, 121, 112, 167, 240, 40, 59, 3, 230, 52, 149, 148, 218, 142, + 212, 109, 176, 71, 179, 172, 77, 1, 193, 70, 147, 149, 23, 144, 148, + 239, 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, 222, 222, + 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, 106, + 236, 93, 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, 221, 185, + 202, 21, 252, 51, 130, 59, 166, 202, 127, 170, 58, 193, 215, 125, 22, + 58, 135, 47, 88, 142, 77, 211, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_soln_meta_dep_a_t *test_msg = (msg_soln_meta_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->age_corrections = 48671; + test_msg->alignment_status = 115; + test_msg->hdop = 31133; + test_msg->last_used_gnss_pos_tow = 610745181; + test_msg->last_used_gnss_vel_tow = 782016851; + test_msg->n_sats = 238; + test_msg->pdop = 57015; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[0].flags = 67; + test_msg->sol_in[0].sensor_type = 253; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[1].flags = 200; + test_msg->sol_in[1].sensor_type = 87; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[2].flags = 250; + test_msg->sol_in[2].sensor_type = 39; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[3].flags = 242; + test_msg->sol_in[3].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[4].flags = 72; + test_msg->sol_in[4].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[5].flags = 222; + test_msg->sol_in[5].sensor_type = 18; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[6].flags = 88; + test_msg->sol_in[6].sensor_type = 11; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[7].flags = 218; + test_msg->sol_in[7].sensor_type = 207; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[8].flags = 13; + test_msg->sol_in[8].sensor_type = 231; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[9].flags = 224; + test_msg->sol_in[9].sensor_type = 226; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[10].flags = 196; + test_msg->sol_in[10].sensor_type = 22; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[11].flags = 242; + test_msg->sol_in[11].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[12].flags = 89; + test_msg->sol_in[12].sensor_type = 12; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[13].flags = 219; + test_msg->sol_in[13].sensor_type = 71; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[14].flags = 85; + test_msg->sol_in[14].sensor_type = 182; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[15].flags = 204; + test_msg->sol_in[15].sensor_type = 145; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[16].flags = 40; + test_msg->sol_in[16].sensor_type = 146; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[17].flags = 51; + test_msg->sol_in[17].sensor_type = 204; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[18].flags = 153; + test_msg->sol_in[18].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[19].flags = 44; + test_msg->sol_in[19].sensor_type = 227; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[20].flags = 28; + test_msg->sol_in[20].sensor_type = 15; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[21].flags = 39; + test_msg->sol_in[21].sensor_type = 255; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[22].flags = 216; + test_msg->sol_in[22].sensor_type = 205; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[23].flags = 190; + test_msg->sol_in[23].sensor_type = 240; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[24].flags = 219; + test_msg->sol_in[24].sensor_type = 93; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[25].flags = 42; + test_msg->sol_in[25].sensor_type = 103; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[26].flags = 182; + test_msg->sol_in[26].sensor_type = 41; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[27].flags = 222; + test_msg->sol_in[27].sensor_type = 76; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[28].flags = 23; + test_msg->sol_in[28].sensor_type = 17; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[29].flags = 31; + test_msg->sol_in[29].sensor_type = 125; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[30].flags = 229; + test_msg->sol_in[30].sensor_type = 18; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[31].flags = 47; + test_msg->sol_in[31].sensor_type = 28; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[32].flags = 25; + test_msg->sol_in[32].sensor_type = 214; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[33].flags = 84; + test_msg->sol_in[33].sensor_type = 100; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[34].flags = 72; + test_msg->sol_in[34].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[35].flags = 10; + test_msg->sol_in[35].sensor_type = 48; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[36].flags = 232; + test_msg->sol_in[36].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[37].flags = 73; + test_msg->sol_in[37].sensor_type = 235; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[38].flags = 163; + test_msg->sol_in[38].sensor_type = 109; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[39].flags = 152; + test_msg->sol_in[39].sensor_type = 51; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[40].flags = 235; + test_msg->sol_in[40].sensor_type = 133; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[41].flags = 70; + test_msg->sol_in[41].sensor_type = 87; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[42].flags = 108; + test_msg->sol_in[42].sensor_type = 2; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[43].flags = 101; + test_msg->sol_in[43].sensor_type = 91; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[44].flags = 55; + test_msg->sol_in[44].sensor_type = 200; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[45].flags = 156; + test_msg->sol_in[45].sensor_type = 24; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[46].flags = 73; + test_msg->sol_in[46].sensor_type = 233; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[47].flags = 66; + test_msg->sol_in[47].sensor_type = 39; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[48].flags = 140; + test_msg->sol_in[48].sensor_type = 97; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[49].flags = 227; + test_msg->sol_in[49].sensor_type = 252; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[50].flags = 237; + test_msg->sol_in[50].sensor_type = 230; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[51].flags = 241; + test_msg->sol_in[51].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[52].flags = 205; + test_msg->sol_in[52].sensor_type = 245; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[53].flags = 0; + test_msg->sol_in[53].sensor_type = 70; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[54].flags = 188; + test_msg->sol_in[54].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[55].flags = 136; + test_msg->sol_in[55].sensor_type = 107; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[56].flags = 58; + test_msg->sol_in[56].sensor_type = 178; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[57].flags = 29; + test_msg->sol_in[57].sensor_type = 1; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[58].flags = 213; + test_msg->sol_in[58].sensor_type = 44; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[59].flags = 147; + test_msg->sol_in[59].sensor_type = 225; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[60].flags = 96; + test_msg->sol_in[60].sensor_type = 190; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[61].flags = 108; + test_msg->sol_in[61].sensor_type = 192; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[62].flags = 15; + test_msg->sol_in[62].sensor_type = 228; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[63].flags = 18; + test_msg->sol_in[63].sensor_type = 203; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[64].flags = 222; + test_msg->sol_in[64].sensor_type = 3; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[65].flags = 68; + test_msg->sol_in[65].sensor_type = 180; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[66].flags = 229; + test_msg->sol_in[66].sensor_type = 101; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[67].flags = 203; + test_msg->sol_in[67].sensor_type = 223; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[68].flags = 164; + test_msg->sol_in[68].sensor_type = 243; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[69].flags = 165; + test_msg->sol_in[69].sensor_type = 92; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[70].flags = 159; + test_msg->sol_in[70].sensor_type = 220; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[71].flags = 121; + test_msg->sol_in[71].sensor_type = 174; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[72].flags = 167; + test_msg->sol_in[72].sensor_type = 112; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[73].flags = 40; + test_msg->sol_in[73].sensor_type = 240; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[74].flags = 3; + test_msg->sol_in[74].sensor_type = 59; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[75].flags = 52; + test_msg->sol_in[75].sensor_type = 230; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[76].flags = 148; + test_msg->sol_in[76].sensor_type = 149; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[77].flags = 142; + test_msg->sol_in[77].sensor_type = 218; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[78].flags = 109; + test_msg->sol_in[78].sensor_type = 212; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[79].flags = 71; + test_msg->sol_in[79].sensor_type = 176; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[80].flags = 172; + test_msg->sol_in[80].sensor_type = 179; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[81].flags = 1; + test_msg->sol_in[81].sensor_type = 77; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[82].flags = 70; + test_msg->sol_in[82].sensor_type = 193; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[83].flags = 149; + test_msg->sol_in[83].sensor_type = 147; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[84].flags = 144; + test_msg->sol_in[84].sensor_type = 23; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[85].flags = 239; + test_msg->sol_in[85].sensor_type = 148; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[86].flags = 186; + test_msg->sol_in[86].sensor_type = 195; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[87].flags = 30; + test_msg->sol_in[87].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[88].flags = 143; + test_msg->sol_in[88].sensor_type = 34; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[89].flags = 207; + test_msg->sol_in[89].sensor_type = 156; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[90].flags = 55; + test_msg->sol_in[90].sensor_type = 63; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[91].flags = 255; + test_msg->sol_in[91].sensor_type = 117; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[92].flags = 222; + test_msg->sol_in[92].sensor_type = 222; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[93].flags = 145; + test_msg->sol_in[93].sensor_type = 219; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[94].flags = 191; + test_msg->sol_in[94].sensor_type = 224; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[95].flags = 109; + test_msg->sol_in[95].sensor_type = 210; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[96].flags = 153; + test_msg->sol_in[96].sensor_type = 86; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[97].flags = 32; + test_msg->sol_in[97].sensor_type = 21; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[98].flags = 10; + test_msg->sol_in[98].sensor_type = 226; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[99].flags = 63; + test_msg->sol_in[99].sensor_type = 60; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[100].flags = 236; + test_msg->sol_in[100].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[101].flags = 96; + test_msg->sol_in[101].sensor_type = 93; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[102].flags = 163; + test_msg->sol_in[102].sensor_type = 30; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[103].flags = 238; + test_msg->sol_in[103].sensor_type = 106; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[104].flags = 133; + test_msg->sol_in[104].sensor_type = 147; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[105].flags = 107; + test_msg->sol_in[105].sensor_type = 132; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[106].flags = 214; + test_msg->sol_in[106].sensor_type = 152; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[107].flags = 185; + test_msg->sol_in[107].sensor_type = 221; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[108].flags = 21; + test_msg->sol_in[108].sensor_type = 202; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[109].flags = 51; + test_msg->sol_in[109].sensor_type = 252; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[110].flags = 59; + test_msg->sol_in[110].sensor_type = 130; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[111].flags = 202; + test_msg->sol_in[111].sensor_type = 166; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[112].flags = 170; + test_msg->sol_in[112].sensor_type = 127; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[113].flags = 193; + test_msg->sol_in[113].sensor_type = 58; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[114].flags = 125; + test_msg->sol_in[114].sensor_type = 215; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[115].flags = 58; + test_msg->sol_in[115].sensor_type = 22; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[116].flags = 47; + test_msg->sol_in[116].sensor_type = 135; + if (sizeof(test_msg->sol_in) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->sol_in[0])); + } + test_msg->sol_in[117].flags = 142; + test_msg->sol_in[117].sensor_type = 88; + test_msg->vdop = 41989; + + EXPECT_EQ(send_message(0xff0f, 61780, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 61780); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->age_corrections, 48671) + << "incorrect value for age_corrections, expected 48671, is " + << last_msg_->age_corrections; + EXPECT_EQ(last_msg_->alignment_status, 115) + << "incorrect value for alignment_status, expected 115, is " + << last_msg_->alignment_status; + EXPECT_EQ(last_msg_->hdop, 31133) + << "incorrect value for hdop, expected 31133, is " << last_msg_->hdop; + EXPECT_EQ(last_msg_->last_used_gnss_pos_tow, 610745181) + << "incorrect value for last_used_gnss_pos_tow, expected 610745181, is " + << last_msg_->last_used_gnss_pos_tow; + EXPECT_EQ(last_msg_->last_used_gnss_vel_tow, 782016851) + << "incorrect value for last_used_gnss_vel_tow, expected 782016851, is " + << last_msg_->last_used_gnss_vel_tow; + EXPECT_EQ(last_msg_->n_sats, 238) + << "incorrect value for n_sats, expected 238, is " << last_msg_->n_sats; + EXPECT_EQ(last_msg_->pdop, 57015) + << "incorrect value for pdop, expected 57015, is " << last_msg_->pdop; + EXPECT_EQ(last_msg_->sol_in[0].flags, 67) + << "incorrect value for sol_in[0].flags, expected 67, is " + << last_msg_->sol_in[0].flags; + EXPECT_EQ(last_msg_->sol_in[0].sensor_type, 253) + << "incorrect value for sol_in[0].sensor_type, expected 253, is " + << last_msg_->sol_in[0].sensor_type; + EXPECT_EQ(last_msg_->sol_in[1].flags, 200) + << "incorrect value for sol_in[1].flags, expected 200, is " + << last_msg_->sol_in[1].flags; + EXPECT_EQ(last_msg_->sol_in[1].sensor_type, 87) + << "incorrect value for sol_in[1].sensor_type, expected 87, is " + << last_msg_->sol_in[1].sensor_type; + EXPECT_EQ(last_msg_->sol_in[2].flags, 250) + << "incorrect value for sol_in[2].flags, expected 250, is " + << last_msg_->sol_in[2].flags; + EXPECT_EQ(last_msg_->sol_in[2].sensor_type, 39) + << "incorrect value for sol_in[2].sensor_type, expected 39, is " + << last_msg_->sol_in[2].sensor_type; + EXPECT_EQ(last_msg_->sol_in[3].flags, 242) + << "incorrect value for sol_in[3].flags, expected 242, is " + << last_msg_->sol_in[3].flags; + EXPECT_EQ(last_msg_->sol_in[3].sensor_type, 245) + << "incorrect value for sol_in[3].sensor_type, expected 245, is " + << last_msg_->sol_in[3].sensor_type; + EXPECT_EQ(last_msg_->sol_in[4].flags, 72) + << "incorrect value for sol_in[4].flags, expected 72, is " + << last_msg_->sol_in[4].flags; + EXPECT_EQ(last_msg_->sol_in[4].sensor_type, 228) + << "incorrect value for sol_in[4].sensor_type, expected 228, is " + << last_msg_->sol_in[4].sensor_type; + EXPECT_EQ(last_msg_->sol_in[5].flags, 222) + << "incorrect value for sol_in[5].flags, expected 222, is " + << last_msg_->sol_in[5].flags; + EXPECT_EQ(last_msg_->sol_in[5].sensor_type, 18) + << "incorrect value for sol_in[5].sensor_type, expected 18, is " + << last_msg_->sol_in[5].sensor_type; + EXPECT_EQ(last_msg_->sol_in[6].flags, 88) + << "incorrect value for sol_in[6].flags, expected 88, is " + << last_msg_->sol_in[6].flags; + EXPECT_EQ(last_msg_->sol_in[6].sensor_type, 11) + << "incorrect value for sol_in[6].sensor_type, expected 11, is " + << last_msg_->sol_in[6].sensor_type; + EXPECT_EQ(last_msg_->sol_in[7].flags, 218) + << "incorrect value for sol_in[7].flags, expected 218, is " + << last_msg_->sol_in[7].flags; + EXPECT_EQ(last_msg_->sol_in[7].sensor_type, 207) + << "incorrect value for sol_in[7].sensor_type, expected 207, is " + << last_msg_->sol_in[7].sensor_type; + EXPECT_EQ(last_msg_->sol_in[8].flags, 13) + << "incorrect value for sol_in[8].flags, expected 13, is " + << last_msg_->sol_in[8].flags; + EXPECT_EQ(last_msg_->sol_in[8].sensor_type, 231) + << "incorrect value for sol_in[8].sensor_type, expected 231, is " + << last_msg_->sol_in[8].sensor_type; + EXPECT_EQ(last_msg_->sol_in[9].flags, 224) + << "incorrect value for sol_in[9].flags, expected 224, is " + << last_msg_->sol_in[9].flags; + EXPECT_EQ(last_msg_->sol_in[9].sensor_type, 226) + << "incorrect value for sol_in[9].sensor_type, expected 226, is " + << last_msg_->sol_in[9].sensor_type; + EXPECT_EQ(last_msg_->sol_in[10].flags, 196) + << "incorrect value for sol_in[10].flags, expected 196, is " + << last_msg_->sol_in[10].flags; + EXPECT_EQ(last_msg_->sol_in[10].sensor_type, 22) + << "incorrect value for sol_in[10].sensor_type, expected 22, is " + << last_msg_->sol_in[10].sensor_type; + EXPECT_EQ(last_msg_->sol_in[11].flags, 242) + << "incorrect value for sol_in[11].flags, expected 242, is " + << last_msg_->sol_in[11].flags; + EXPECT_EQ(last_msg_->sol_in[11].sensor_type, 21) + << "incorrect value for sol_in[11].sensor_type, expected 21, is " + << last_msg_->sol_in[11].sensor_type; + EXPECT_EQ(last_msg_->sol_in[12].flags, 89) + << "incorrect value for sol_in[12].flags, expected 89, is " + << last_msg_->sol_in[12].flags; + EXPECT_EQ(last_msg_->sol_in[12].sensor_type, 12) + << "incorrect value for sol_in[12].sensor_type, expected 12, is " + << last_msg_->sol_in[12].sensor_type; + EXPECT_EQ(last_msg_->sol_in[13].flags, 219) + << "incorrect value for sol_in[13].flags, expected 219, is " + << last_msg_->sol_in[13].flags; + EXPECT_EQ(last_msg_->sol_in[13].sensor_type, 71) + << "incorrect value for sol_in[13].sensor_type, expected 71, is " + << last_msg_->sol_in[13].sensor_type; + EXPECT_EQ(last_msg_->sol_in[14].flags, 85) + << "incorrect value for sol_in[14].flags, expected 85, is " + << last_msg_->sol_in[14].flags; + EXPECT_EQ(last_msg_->sol_in[14].sensor_type, 182) + << "incorrect value for sol_in[14].sensor_type, expected 182, is " + << last_msg_->sol_in[14].sensor_type; + EXPECT_EQ(last_msg_->sol_in[15].flags, 204) + << "incorrect value for sol_in[15].flags, expected 204, is " + << last_msg_->sol_in[15].flags; + EXPECT_EQ(last_msg_->sol_in[15].sensor_type, 145) + << "incorrect value for sol_in[15].sensor_type, expected 145, is " + << last_msg_->sol_in[15].sensor_type; + EXPECT_EQ(last_msg_->sol_in[16].flags, 40) + << "incorrect value for sol_in[16].flags, expected 40, is " + << last_msg_->sol_in[16].flags; + EXPECT_EQ(last_msg_->sol_in[16].sensor_type, 146) + << "incorrect value for sol_in[16].sensor_type, expected 146, is " + << last_msg_->sol_in[16].sensor_type; + EXPECT_EQ(last_msg_->sol_in[17].flags, 51) + << "incorrect value for sol_in[17].flags, expected 51, is " + << last_msg_->sol_in[17].flags; + EXPECT_EQ(last_msg_->sol_in[17].sensor_type, 204) + << "incorrect value for sol_in[17].sensor_type, expected 204, is " + << last_msg_->sol_in[17].sensor_type; + EXPECT_EQ(last_msg_->sol_in[18].flags, 153) + << "incorrect value for sol_in[18].flags, expected 153, is " + << last_msg_->sol_in[18].flags; + EXPECT_EQ(last_msg_->sol_in[18].sensor_type, 21) + << "incorrect value for sol_in[18].sensor_type, expected 21, is " + << last_msg_->sol_in[18].sensor_type; + EXPECT_EQ(last_msg_->sol_in[19].flags, 44) + << "incorrect value for sol_in[19].flags, expected 44, is " + << last_msg_->sol_in[19].flags; + EXPECT_EQ(last_msg_->sol_in[19].sensor_type, 227) + << "incorrect value for sol_in[19].sensor_type, expected 227, is " + << last_msg_->sol_in[19].sensor_type; + EXPECT_EQ(last_msg_->sol_in[20].flags, 28) + << "incorrect value for sol_in[20].flags, expected 28, is " + << last_msg_->sol_in[20].flags; + EXPECT_EQ(last_msg_->sol_in[20].sensor_type, 15) + << "incorrect value for sol_in[20].sensor_type, expected 15, is " + << last_msg_->sol_in[20].sensor_type; + EXPECT_EQ(last_msg_->sol_in[21].flags, 39) + << "incorrect value for sol_in[21].flags, expected 39, is " + << last_msg_->sol_in[21].flags; + EXPECT_EQ(last_msg_->sol_in[21].sensor_type, 255) + << "incorrect value for sol_in[21].sensor_type, expected 255, is " + << last_msg_->sol_in[21].sensor_type; + EXPECT_EQ(last_msg_->sol_in[22].flags, 216) + << "incorrect value for sol_in[22].flags, expected 216, is " + << last_msg_->sol_in[22].flags; + EXPECT_EQ(last_msg_->sol_in[22].sensor_type, 205) + << "incorrect value for sol_in[22].sensor_type, expected 205, is " + << last_msg_->sol_in[22].sensor_type; + EXPECT_EQ(last_msg_->sol_in[23].flags, 190) + << "incorrect value for sol_in[23].flags, expected 190, is " + << last_msg_->sol_in[23].flags; + EXPECT_EQ(last_msg_->sol_in[23].sensor_type, 240) + << "incorrect value for sol_in[23].sensor_type, expected 240, is " + << last_msg_->sol_in[23].sensor_type; + EXPECT_EQ(last_msg_->sol_in[24].flags, 219) + << "incorrect value for sol_in[24].flags, expected 219, is " + << last_msg_->sol_in[24].flags; + EXPECT_EQ(last_msg_->sol_in[24].sensor_type, 93) + << "incorrect value for sol_in[24].sensor_type, expected 93, is " + << last_msg_->sol_in[24].sensor_type; + EXPECT_EQ(last_msg_->sol_in[25].flags, 42) + << "incorrect value for sol_in[25].flags, expected 42, is " + << last_msg_->sol_in[25].flags; + EXPECT_EQ(last_msg_->sol_in[25].sensor_type, 103) + << "incorrect value for sol_in[25].sensor_type, expected 103, is " + << last_msg_->sol_in[25].sensor_type; + EXPECT_EQ(last_msg_->sol_in[26].flags, 182) + << "incorrect value for sol_in[26].flags, expected 182, is " + << last_msg_->sol_in[26].flags; + EXPECT_EQ(last_msg_->sol_in[26].sensor_type, 41) + << "incorrect value for sol_in[26].sensor_type, expected 41, is " + << last_msg_->sol_in[26].sensor_type; + EXPECT_EQ(last_msg_->sol_in[27].flags, 222) + << "incorrect value for sol_in[27].flags, expected 222, is " + << last_msg_->sol_in[27].flags; + EXPECT_EQ(last_msg_->sol_in[27].sensor_type, 76) + << "incorrect value for sol_in[27].sensor_type, expected 76, is " + << last_msg_->sol_in[27].sensor_type; + EXPECT_EQ(last_msg_->sol_in[28].flags, 23) + << "incorrect value for sol_in[28].flags, expected 23, is " + << last_msg_->sol_in[28].flags; + EXPECT_EQ(last_msg_->sol_in[28].sensor_type, 17) + << "incorrect value for sol_in[28].sensor_type, expected 17, is " + << last_msg_->sol_in[28].sensor_type; + EXPECT_EQ(last_msg_->sol_in[29].flags, 31) + << "incorrect value for sol_in[29].flags, expected 31, is " + << last_msg_->sol_in[29].flags; + EXPECT_EQ(last_msg_->sol_in[29].sensor_type, 125) + << "incorrect value for sol_in[29].sensor_type, expected 125, is " + << last_msg_->sol_in[29].sensor_type; + EXPECT_EQ(last_msg_->sol_in[30].flags, 229) + << "incorrect value for sol_in[30].flags, expected 229, is " + << last_msg_->sol_in[30].flags; + EXPECT_EQ(last_msg_->sol_in[30].sensor_type, 18) + << "incorrect value for sol_in[30].sensor_type, expected 18, is " + << last_msg_->sol_in[30].sensor_type; + EXPECT_EQ(last_msg_->sol_in[31].flags, 47) + << "incorrect value for sol_in[31].flags, expected 47, is " + << last_msg_->sol_in[31].flags; + EXPECT_EQ(last_msg_->sol_in[31].sensor_type, 28) + << "incorrect value for sol_in[31].sensor_type, expected 28, is " + << last_msg_->sol_in[31].sensor_type; + EXPECT_EQ(last_msg_->sol_in[32].flags, 25) + << "incorrect value for sol_in[32].flags, expected 25, is " + << last_msg_->sol_in[32].flags; + EXPECT_EQ(last_msg_->sol_in[32].sensor_type, 214) + << "incorrect value for sol_in[32].sensor_type, expected 214, is " + << last_msg_->sol_in[32].sensor_type; + EXPECT_EQ(last_msg_->sol_in[33].flags, 84) + << "incorrect value for sol_in[33].flags, expected 84, is " + << last_msg_->sol_in[33].flags; + EXPECT_EQ(last_msg_->sol_in[33].sensor_type, 100) + << "incorrect value for sol_in[33].sensor_type, expected 100, is " + << last_msg_->sol_in[33].sensor_type; + EXPECT_EQ(last_msg_->sol_in[34].flags, 72) + << "incorrect value for sol_in[34].flags, expected 72, is " + << last_msg_->sol_in[34].flags; + EXPECT_EQ(last_msg_->sol_in[34].sensor_type, 106) + << "incorrect value for sol_in[34].sensor_type, expected 106, is " + << last_msg_->sol_in[34].sensor_type; + EXPECT_EQ(last_msg_->sol_in[35].flags, 10) + << "incorrect value for sol_in[35].flags, expected 10, is " + << last_msg_->sol_in[35].flags; + EXPECT_EQ(last_msg_->sol_in[35].sensor_type, 48) + << "incorrect value for sol_in[35].sensor_type, expected 48, is " + << last_msg_->sol_in[35].sensor_type; + EXPECT_EQ(last_msg_->sol_in[36].flags, 232) + << "incorrect value for sol_in[36].flags, expected 232, is " + << last_msg_->sol_in[36].flags; + EXPECT_EQ(last_msg_->sol_in[36].sensor_type, 222) + << "incorrect value for sol_in[36].sensor_type, expected 222, is " + << last_msg_->sol_in[36].sensor_type; + EXPECT_EQ(last_msg_->sol_in[37].flags, 73) + << "incorrect value for sol_in[37].flags, expected 73, is " + << last_msg_->sol_in[37].flags; + EXPECT_EQ(last_msg_->sol_in[37].sensor_type, 235) + << "incorrect value for sol_in[37].sensor_type, expected 235, is " + << last_msg_->sol_in[37].sensor_type; + EXPECT_EQ(last_msg_->sol_in[38].flags, 163) + << "incorrect value for sol_in[38].flags, expected 163, is " + << last_msg_->sol_in[38].flags; + EXPECT_EQ(last_msg_->sol_in[38].sensor_type, 109) + << "incorrect value for sol_in[38].sensor_type, expected 109, is " + << last_msg_->sol_in[38].sensor_type; + EXPECT_EQ(last_msg_->sol_in[39].flags, 152) + << "incorrect value for sol_in[39].flags, expected 152, is " + << last_msg_->sol_in[39].flags; + EXPECT_EQ(last_msg_->sol_in[39].sensor_type, 51) + << "incorrect value for sol_in[39].sensor_type, expected 51, is " + << last_msg_->sol_in[39].sensor_type; + EXPECT_EQ(last_msg_->sol_in[40].flags, 235) + << "incorrect value for sol_in[40].flags, expected 235, is " + << last_msg_->sol_in[40].flags; + EXPECT_EQ(last_msg_->sol_in[40].sensor_type, 133) + << "incorrect value for sol_in[40].sensor_type, expected 133, is " + << last_msg_->sol_in[40].sensor_type; + EXPECT_EQ(last_msg_->sol_in[41].flags, 70) + << "incorrect value for sol_in[41].flags, expected 70, is " + << last_msg_->sol_in[41].flags; + EXPECT_EQ(last_msg_->sol_in[41].sensor_type, 87) + << "incorrect value for sol_in[41].sensor_type, expected 87, is " + << last_msg_->sol_in[41].sensor_type; + EXPECT_EQ(last_msg_->sol_in[42].flags, 108) + << "incorrect value for sol_in[42].flags, expected 108, is " + << last_msg_->sol_in[42].flags; + EXPECT_EQ(last_msg_->sol_in[42].sensor_type, 2) + << "incorrect value for sol_in[42].sensor_type, expected 2, is " + << last_msg_->sol_in[42].sensor_type; + EXPECT_EQ(last_msg_->sol_in[43].flags, 101) + << "incorrect value for sol_in[43].flags, expected 101, is " + << last_msg_->sol_in[43].flags; + EXPECT_EQ(last_msg_->sol_in[43].sensor_type, 91) + << "incorrect value for sol_in[43].sensor_type, expected 91, is " + << last_msg_->sol_in[43].sensor_type; + EXPECT_EQ(last_msg_->sol_in[44].flags, 55) + << "incorrect value for sol_in[44].flags, expected 55, is " + << last_msg_->sol_in[44].flags; + EXPECT_EQ(last_msg_->sol_in[44].sensor_type, 200) + << "incorrect value for sol_in[44].sensor_type, expected 200, is " + << last_msg_->sol_in[44].sensor_type; + EXPECT_EQ(last_msg_->sol_in[45].flags, 156) + << "incorrect value for sol_in[45].flags, expected 156, is " + << last_msg_->sol_in[45].flags; + EXPECT_EQ(last_msg_->sol_in[45].sensor_type, 24) + << "incorrect value for sol_in[45].sensor_type, expected 24, is " + << last_msg_->sol_in[45].sensor_type; + EXPECT_EQ(last_msg_->sol_in[46].flags, 73) + << "incorrect value for sol_in[46].flags, expected 73, is " + << last_msg_->sol_in[46].flags; + EXPECT_EQ(last_msg_->sol_in[46].sensor_type, 233) + << "incorrect value for sol_in[46].sensor_type, expected 233, is " + << last_msg_->sol_in[46].sensor_type; + EXPECT_EQ(last_msg_->sol_in[47].flags, 66) + << "incorrect value for sol_in[47].flags, expected 66, is " + << last_msg_->sol_in[47].flags; + EXPECT_EQ(last_msg_->sol_in[47].sensor_type, 39) + << "incorrect value for sol_in[47].sensor_type, expected 39, is " + << last_msg_->sol_in[47].sensor_type; + EXPECT_EQ(last_msg_->sol_in[48].flags, 140) + << "incorrect value for sol_in[48].flags, expected 140, is " + << last_msg_->sol_in[48].flags; + EXPECT_EQ(last_msg_->sol_in[48].sensor_type, 97) + << "incorrect value for sol_in[48].sensor_type, expected 97, is " + << last_msg_->sol_in[48].sensor_type; + EXPECT_EQ(last_msg_->sol_in[49].flags, 227) + << "incorrect value for sol_in[49].flags, expected 227, is " + << last_msg_->sol_in[49].flags; + EXPECT_EQ(last_msg_->sol_in[49].sensor_type, 252) + << "incorrect value for sol_in[49].sensor_type, expected 252, is " + << last_msg_->sol_in[49].sensor_type; + EXPECT_EQ(last_msg_->sol_in[50].flags, 237) + << "incorrect value for sol_in[50].flags, expected 237, is " + << last_msg_->sol_in[50].flags; + EXPECT_EQ(last_msg_->sol_in[50].sensor_type, 230) + << "incorrect value for sol_in[50].sensor_type, expected 230, is " + << last_msg_->sol_in[50].sensor_type; + EXPECT_EQ(last_msg_->sol_in[51].flags, 241) + << "incorrect value for sol_in[51].flags, expected 241, is " + << last_msg_->sol_in[51].flags; + EXPECT_EQ(last_msg_->sol_in[51].sensor_type, 135) + << "incorrect value for sol_in[51].sensor_type, expected 135, is " + << last_msg_->sol_in[51].sensor_type; + EXPECT_EQ(last_msg_->sol_in[52].flags, 205) + << "incorrect value for sol_in[52].flags, expected 205, is " + << last_msg_->sol_in[52].flags; + EXPECT_EQ(last_msg_->sol_in[52].sensor_type, 245) + << "incorrect value for sol_in[52].sensor_type, expected 245, is " + << last_msg_->sol_in[52].sensor_type; + EXPECT_EQ(last_msg_->sol_in[53].flags, 0) + << "incorrect value for sol_in[53].flags, expected 0, is " + << last_msg_->sol_in[53].flags; + EXPECT_EQ(last_msg_->sol_in[53].sensor_type, 70) + << "incorrect value for sol_in[53].sensor_type, expected 70, is " + << last_msg_->sol_in[53].sensor_type; + EXPECT_EQ(last_msg_->sol_in[54].flags, 188) + << "incorrect value for sol_in[54].flags, expected 188, is " + << last_msg_->sol_in[54].flags; + EXPECT_EQ(last_msg_->sol_in[54].sensor_type, 219) + << "incorrect value for sol_in[54].sensor_type, expected 219, is " + << last_msg_->sol_in[54].sensor_type; + EXPECT_EQ(last_msg_->sol_in[55].flags, 136) + << "incorrect value for sol_in[55].flags, expected 136, is " + << last_msg_->sol_in[55].flags; + EXPECT_EQ(last_msg_->sol_in[55].sensor_type, 107) + << "incorrect value for sol_in[55].sensor_type, expected 107, is " + << last_msg_->sol_in[55].sensor_type; + EXPECT_EQ(last_msg_->sol_in[56].flags, 58) + << "incorrect value for sol_in[56].flags, expected 58, is " + << last_msg_->sol_in[56].flags; + EXPECT_EQ(last_msg_->sol_in[56].sensor_type, 178) + << "incorrect value for sol_in[56].sensor_type, expected 178, is " + << last_msg_->sol_in[56].sensor_type; + EXPECT_EQ(last_msg_->sol_in[57].flags, 29) + << "incorrect value for sol_in[57].flags, expected 29, is " + << last_msg_->sol_in[57].flags; + EXPECT_EQ(last_msg_->sol_in[57].sensor_type, 1) + << "incorrect value for sol_in[57].sensor_type, expected 1, is " + << last_msg_->sol_in[57].sensor_type; + EXPECT_EQ(last_msg_->sol_in[58].flags, 213) + << "incorrect value for sol_in[58].flags, expected 213, is " + << last_msg_->sol_in[58].flags; + EXPECT_EQ(last_msg_->sol_in[58].sensor_type, 44) + << "incorrect value for sol_in[58].sensor_type, expected 44, is " + << last_msg_->sol_in[58].sensor_type; + EXPECT_EQ(last_msg_->sol_in[59].flags, 147) + << "incorrect value for sol_in[59].flags, expected 147, is " + << last_msg_->sol_in[59].flags; + EXPECT_EQ(last_msg_->sol_in[59].sensor_type, 225) + << "incorrect value for sol_in[59].sensor_type, expected 225, is " + << last_msg_->sol_in[59].sensor_type; + EXPECT_EQ(last_msg_->sol_in[60].flags, 96) + << "incorrect value for sol_in[60].flags, expected 96, is " + << last_msg_->sol_in[60].flags; + EXPECT_EQ(last_msg_->sol_in[60].sensor_type, 190) + << "incorrect value for sol_in[60].sensor_type, expected 190, is " + << last_msg_->sol_in[60].sensor_type; + EXPECT_EQ(last_msg_->sol_in[61].flags, 108) + << "incorrect value for sol_in[61].flags, expected 108, is " + << last_msg_->sol_in[61].flags; + EXPECT_EQ(last_msg_->sol_in[61].sensor_type, 192) + << "incorrect value for sol_in[61].sensor_type, expected 192, is " + << last_msg_->sol_in[61].sensor_type; + EXPECT_EQ(last_msg_->sol_in[62].flags, 15) + << "incorrect value for sol_in[62].flags, expected 15, is " + << last_msg_->sol_in[62].flags; + EXPECT_EQ(last_msg_->sol_in[62].sensor_type, 228) + << "incorrect value for sol_in[62].sensor_type, expected 228, is " + << last_msg_->sol_in[62].sensor_type; + EXPECT_EQ(last_msg_->sol_in[63].flags, 18) + << "incorrect value for sol_in[63].flags, expected 18, is " + << last_msg_->sol_in[63].flags; + EXPECT_EQ(last_msg_->sol_in[63].sensor_type, 203) + << "incorrect value for sol_in[63].sensor_type, expected 203, is " + << last_msg_->sol_in[63].sensor_type; + EXPECT_EQ(last_msg_->sol_in[64].flags, 222) + << "incorrect value for sol_in[64].flags, expected 222, is " + << last_msg_->sol_in[64].flags; + EXPECT_EQ(last_msg_->sol_in[64].sensor_type, 3) + << "incorrect value for sol_in[64].sensor_type, expected 3, is " + << last_msg_->sol_in[64].sensor_type; + EXPECT_EQ(last_msg_->sol_in[65].flags, 68) + << "incorrect value for sol_in[65].flags, expected 68, is " + << last_msg_->sol_in[65].flags; + EXPECT_EQ(last_msg_->sol_in[65].sensor_type, 180) + << "incorrect value for sol_in[65].sensor_type, expected 180, is " + << last_msg_->sol_in[65].sensor_type; + EXPECT_EQ(last_msg_->sol_in[66].flags, 229) + << "incorrect value for sol_in[66].flags, expected 229, is " + << last_msg_->sol_in[66].flags; + EXPECT_EQ(last_msg_->sol_in[66].sensor_type, 101) + << "incorrect value for sol_in[66].sensor_type, expected 101, is " + << last_msg_->sol_in[66].sensor_type; + EXPECT_EQ(last_msg_->sol_in[67].flags, 203) + << "incorrect value for sol_in[67].flags, expected 203, is " + << last_msg_->sol_in[67].flags; + EXPECT_EQ(last_msg_->sol_in[67].sensor_type, 223) + << "incorrect value for sol_in[67].sensor_type, expected 223, is " + << last_msg_->sol_in[67].sensor_type; + EXPECT_EQ(last_msg_->sol_in[68].flags, 164) + << "incorrect value for sol_in[68].flags, expected 164, is " + << last_msg_->sol_in[68].flags; + EXPECT_EQ(last_msg_->sol_in[68].sensor_type, 243) + << "incorrect value for sol_in[68].sensor_type, expected 243, is " + << last_msg_->sol_in[68].sensor_type; + EXPECT_EQ(last_msg_->sol_in[69].flags, 165) + << "incorrect value for sol_in[69].flags, expected 165, is " + << last_msg_->sol_in[69].flags; + EXPECT_EQ(last_msg_->sol_in[69].sensor_type, 92) + << "incorrect value for sol_in[69].sensor_type, expected 92, is " + << last_msg_->sol_in[69].sensor_type; + EXPECT_EQ(last_msg_->sol_in[70].flags, 159) + << "incorrect value for sol_in[70].flags, expected 159, is " + << last_msg_->sol_in[70].flags; + EXPECT_EQ(last_msg_->sol_in[70].sensor_type, 220) + << "incorrect value for sol_in[70].sensor_type, expected 220, is " + << last_msg_->sol_in[70].sensor_type; + EXPECT_EQ(last_msg_->sol_in[71].flags, 121) + << "incorrect value for sol_in[71].flags, expected 121, is " + << last_msg_->sol_in[71].flags; + EXPECT_EQ(last_msg_->sol_in[71].sensor_type, 174) + << "incorrect value for sol_in[71].sensor_type, expected 174, is " + << last_msg_->sol_in[71].sensor_type; + EXPECT_EQ(last_msg_->sol_in[72].flags, 167) + << "incorrect value for sol_in[72].flags, expected 167, is " + << last_msg_->sol_in[72].flags; + EXPECT_EQ(last_msg_->sol_in[72].sensor_type, 112) + << "incorrect value for sol_in[72].sensor_type, expected 112, is " + << last_msg_->sol_in[72].sensor_type; + EXPECT_EQ(last_msg_->sol_in[73].flags, 40) + << "incorrect value for sol_in[73].flags, expected 40, is " + << last_msg_->sol_in[73].flags; + EXPECT_EQ(last_msg_->sol_in[73].sensor_type, 240) + << "incorrect value for sol_in[73].sensor_type, expected 240, is " + << last_msg_->sol_in[73].sensor_type; + EXPECT_EQ(last_msg_->sol_in[74].flags, 3) + << "incorrect value for sol_in[74].flags, expected 3, is " + << last_msg_->sol_in[74].flags; + EXPECT_EQ(last_msg_->sol_in[74].sensor_type, 59) + << "incorrect value for sol_in[74].sensor_type, expected 59, is " + << last_msg_->sol_in[74].sensor_type; + EXPECT_EQ(last_msg_->sol_in[75].flags, 52) + << "incorrect value for sol_in[75].flags, expected 52, is " + << last_msg_->sol_in[75].flags; + EXPECT_EQ(last_msg_->sol_in[75].sensor_type, 230) + << "incorrect value for sol_in[75].sensor_type, expected 230, is " + << last_msg_->sol_in[75].sensor_type; + EXPECT_EQ(last_msg_->sol_in[76].flags, 148) + << "incorrect value for sol_in[76].flags, expected 148, is " + << last_msg_->sol_in[76].flags; + EXPECT_EQ(last_msg_->sol_in[76].sensor_type, 149) + << "incorrect value for sol_in[76].sensor_type, expected 149, is " + << last_msg_->sol_in[76].sensor_type; + EXPECT_EQ(last_msg_->sol_in[77].flags, 142) + << "incorrect value for sol_in[77].flags, expected 142, is " + << last_msg_->sol_in[77].flags; + EXPECT_EQ(last_msg_->sol_in[77].sensor_type, 218) + << "incorrect value for sol_in[77].sensor_type, expected 218, is " + << last_msg_->sol_in[77].sensor_type; + EXPECT_EQ(last_msg_->sol_in[78].flags, 109) + << "incorrect value for sol_in[78].flags, expected 109, is " + << last_msg_->sol_in[78].flags; + EXPECT_EQ(last_msg_->sol_in[78].sensor_type, 212) + << "incorrect value for sol_in[78].sensor_type, expected 212, is " + << last_msg_->sol_in[78].sensor_type; + EXPECT_EQ(last_msg_->sol_in[79].flags, 71) + << "incorrect value for sol_in[79].flags, expected 71, is " + << last_msg_->sol_in[79].flags; + EXPECT_EQ(last_msg_->sol_in[79].sensor_type, 176) + << "incorrect value for sol_in[79].sensor_type, expected 176, is " + << last_msg_->sol_in[79].sensor_type; + EXPECT_EQ(last_msg_->sol_in[80].flags, 172) + << "incorrect value for sol_in[80].flags, expected 172, is " + << last_msg_->sol_in[80].flags; + EXPECT_EQ(last_msg_->sol_in[80].sensor_type, 179) + << "incorrect value for sol_in[80].sensor_type, expected 179, is " + << last_msg_->sol_in[80].sensor_type; + EXPECT_EQ(last_msg_->sol_in[81].flags, 1) + << "incorrect value for sol_in[81].flags, expected 1, is " + << last_msg_->sol_in[81].flags; + EXPECT_EQ(last_msg_->sol_in[81].sensor_type, 77) + << "incorrect value for sol_in[81].sensor_type, expected 77, is " + << last_msg_->sol_in[81].sensor_type; + EXPECT_EQ(last_msg_->sol_in[82].flags, 70) + << "incorrect value for sol_in[82].flags, expected 70, is " + << last_msg_->sol_in[82].flags; + EXPECT_EQ(last_msg_->sol_in[82].sensor_type, 193) + << "incorrect value for sol_in[82].sensor_type, expected 193, is " + << last_msg_->sol_in[82].sensor_type; + EXPECT_EQ(last_msg_->sol_in[83].flags, 149) + << "incorrect value for sol_in[83].flags, expected 149, is " + << last_msg_->sol_in[83].flags; + EXPECT_EQ(last_msg_->sol_in[83].sensor_type, 147) + << "incorrect value for sol_in[83].sensor_type, expected 147, is " + << last_msg_->sol_in[83].sensor_type; + EXPECT_EQ(last_msg_->sol_in[84].flags, 144) + << "incorrect value for sol_in[84].flags, expected 144, is " + << last_msg_->sol_in[84].flags; + EXPECT_EQ(last_msg_->sol_in[84].sensor_type, 23) + << "incorrect value for sol_in[84].sensor_type, expected 23, is " + << last_msg_->sol_in[84].sensor_type; + EXPECT_EQ(last_msg_->sol_in[85].flags, 239) + << "incorrect value for sol_in[85].flags, expected 239, is " + << last_msg_->sol_in[85].flags; + EXPECT_EQ(last_msg_->sol_in[85].sensor_type, 148) + << "incorrect value for sol_in[85].sensor_type, expected 148, is " + << last_msg_->sol_in[85].sensor_type; + EXPECT_EQ(last_msg_->sol_in[86].flags, 186) + << "incorrect value for sol_in[86].flags, expected 186, is " + << last_msg_->sol_in[86].flags; + EXPECT_EQ(last_msg_->sol_in[86].sensor_type, 195) + << "incorrect value for sol_in[86].sensor_type, expected 195, is " + << last_msg_->sol_in[86].sensor_type; + EXPECT_EQ(last_msg_->sol_in[87].flags, 30) + << "incorrect value for sol_in[87].flags, expected 30, is " + << last_msg_->sol_in[87].flags; + EXPECT_EQ(last_msg_->sol_in[87].sensor_type, 86) + << "incorrect value for sol_in[87].sensor_type, expected 86, is " + << last_msg_->sol_in[87].sensor_type; + EXPECT_EQ(last_msg_->sol_in[88].flags, 143) + << "incorrect value for sol_in[88].flags, expected 143, is " + << last_msg_->sol_in[88].flags; + EXPECT_EQ(last_msg_->sol_in[88].sensor_type, 34) + << "incorrect value for sol_in[88].sensor_type, expected 34, is " + << last_msg_->sol_in[88].sensor_type; + EXPECT_EQ(last_msg_->sol_in[89].flags, 207) + << "incorrect value for sol_in[89].flags, expected 207, is " + << last_msg_->sol_in[89].flags; + EXPECT_EQ(last_msg_->sol_in[89].sensor_type, 156) + << "incorrect value for sol_in[89].sensor_type, expected 156, is " + << last_msg_->sol_in[89].sensor_type; + EXPECT_EQ(last_msg_->sol_in[90].flags, 55) + << "incorrect value for sol_in[90].flags, expected 55, is " + << last_msg_->sol_in[90].flags; + EXPECT_EQ(last_msg_->sol_in[90].sensor_type, 63) + << "incorrect value for sol_in[90].sensor_type, expected 63, is " + << last_msg_->sol_in[90].sensor_type; + EXPECT_EQ(last_msg_->sol_in[91].flags, 255) + << "incorrect value for sol_in[91].flags, expected 255, is " + << last_msg_->sol_in[91].flags; + EXPECT_EQ(last_msg_->sol_in[91].sensor_type, 117) + << "incorrect value for sol_in[91].sensor_type, expected 117, is " + << last_msg_->sol_in[91].sensor_type; + EXPECT_EQ(last_msg_->sol_in[92].flags, 222) + << "incorrect value for sol_in[92].flags, expected 222, is " + << last_msg_->sol_in[92].flags; + EXPECT_EQ(last_msg_->sol_in[92].sensor_type, 222) + << "incorrect value for sol_in[92].sensor_type, expected 222, is " + << last_msg_->sol_in[92].sensor_type; + EXPECT_EQ(last_msg_->sol_in[93].flags, 145) + << "incorrect value for sol_in[93].flags, expected 145, is " + << last_msg_->sol_in[93].flags; + EXPECT_EQ(last_msg_->sol_in[93].sensor_type, 219) + << "incorrect value for sol_in[93].sensor_type, expected 219, is " + << last_msg_->sol_in[93].sensor_type; + EXPECT_EQ(last_msg_->sol_in[94].flags, 191) + << "incorrect value for sol_in[94].flags, expected 191, is " + << last_msg_->sol_in[94].flags; + EXPECT_EQ(last_msg_->sol_in[94].sensor_type, 224) + << "incorrect value for sol_in[94].sensor_type, expected 224, is " + << last_msg_->sol_in[94].sensor_type; + EXPECT_EQ(last_msg_->sol_in[95].flags, 109) + << "incorrect value for sol_in[95].flags, expected 109, is " + << last_msg_->sol_in[95].flags; + EXPECT_EQ(last_msg_->sol_in[95].sensor_type, 210) + << "incorrect value for sol_in[95].sensor_type, expected 210, is " + << last_msg_->sol_in[95].sensor_type; + EXPECT_EQ(last_msg_->sol_in[96].flags, 153) + << "incorrect value for sol_in[96].flags, expected 153, is " + << last_msg_->sol_in[96].flags; + EXPECT_EQ(last_msg_->sol_in[96].sensor_type, 86) + << "incorrect value for sol_in[96].sensor_type, expected 86, is " + << last_msg_->sol_in[96].sensor_type; + EXPECT_EQ(last_msg_->sol_in[97].flags, 32) + << "incorrect value for sol_in[97].flags, expected 32, is " + << last_msg_->sol_in[97].flags; + EXPECT_EQ(last_msg_->sol_in[97].sensor_type, 21) + << "incorrect value for sol_in[97].sensor_type, expected 21, is " + << last_msg_->sol_in[97].sensor_type; + EXPECT_EQ(last_msg_->sol_in[98].flags, 10) + << "incorrect value for sol_in[98].flags, expected 10, is " + << last_msg_->sol_in[98].flags; + EXPECT_EQ(last_msg_->sol_in[98].sensor_type, 226) + << "incorrect value for sol_in[98].sensor_type, expected 226, is " + << last_msg_->sol_in[98].sensor_type; + EXPECT_EQ(last_msg_->sol_in[99].flags, 63) + << "incorrect value for sol_in[99].flags, expected 63, is " + << last_msg_->sol_in[99].flags; + EXPECT_EQ(last_msg_->sol_in[99].sensor_type, 60) + << "incorrect value for sol_in[99].sensor_type, expected 60, is " + << last_msg_->sol_in[99].sensor_type; + EXPECT_EQ(last_msg_->sol_in[100].flags, 236) + << "incorrect value for sol_in[100].flags, expected 236, is " + << last_msg_->sol_in[100].flags; + EXPECT_EQ(last_msg_->sol_in[100].sensor_type, 106) + << "incorrect value for sol_in[100].sensor_type, expected 106, is " + << last_msg_->sol_in[100].sensor_type; + EXPECT_EQ(last_msg_->sol_in[101].flags, 96) + << "incorrect value for sol_in[101].flags, expected 96, is " + << last_msg_->sol_in[101].flags; + EXPECT_EQ(last_msg_->sol_in[101].sensor_type, 93) + << "incorrect value for sol_in[101].sensor_type, expected 93, is " + << last_msg_->sol_in[101].sensor_type; + EXPECT_EQ(last_msg_->sol_in[102].flags, 163) + << "incorrect value for sol_in[102].flags, expected 163, is " + << last_msg_->sol_in[102].flags; + EXPECT_EQ(last_msg_->sol_in[102].sensor_type, 30) + << "incorrect value for sol_in[102].sensor_type, expected 30, is " + << last_msg_->sol_in[102].sensor_type; + EXPECT_EQ(last_msg_->sol_in[103].flags, 238) + << "incorrect value for sol_in[103].flags, expected 238, is " + << last_msg_->sol_in[103].flags; + EXPECT_EQ(last_msg_->sol_in[103].sensor_type, 106) + << "incorrect value for sol_in[103].sensor_type, expected 106, is " + << last_msg_->sol_in[103].sensor_type; + EXPECT_EQ(last_msg_->sol_in[104].flags, 133) + << "incorrect value for sol_in[104].flags, expected 133, is " + << last_msg_->sol_in[104].flags; + EXPECT_EQ(last_msg_->sol_in[104].sensor_type, 147) + << "incorrect value for sol_in[104].sensor_type, expected 147, is " + << last_msg_->sol_in[104].sensor_type; + EXPECT_EQ(last_msg_->sol_in[105].flags, 107) + << "incorrect value for sol_in[105].flags, expected 107, is " + << last_msg_->sol_in[105].flags; + EXPECT_EQ(last_msg_->sol_in[105].sensor_type, 132) + << "incorrect value for sol_in[105].sensor_type, expected 132, is " + << last_msg_->sol_in[105].sensor_type; + EXPECT_EQ(last_msg_->sol_in[106].flags, 214) + << "incorrect value for sol_in[106].flags, expected 214, is " + << last_msg_->sol_in[106].flags; + EXPECT_EQ(last_msg_->sol_in[106].sensor_type, 152) + << "incorrect value for sol_in[106].sensor_type, expected 152, is " + << last_msg_->sol_in[106].sensor_type; + EXPECT_EQ(last_msg_->sol_in[107].flags, 185) + << "incorrect value for sol_in[107].flags, expected 185, is " + << last_msg_->sol_in[107].flags; + EXPECT_EQ(last_msg_->sol_in[107].sensor_type, 221) + << "incorrect value for sol_in[107].sensor_type, expected 221, is " + << last_msg_->sol_in[107].sensor_type; + EXPECT_EQ(last_msg_->sol_in[108].flags, 21) + << "incorrect value for sol_in[108].flags, expected 21, is " + << last_msg_->sol_in[108].flags; + EXPECT_EQ(last_msg_->sol_in[108].sensor_type, 202) + << "incorrect value for sol_in[108].sensor_type, expected 202, is " + << last_msg_->sol_in[108].sensor_type; + EXPECT_EQ(last_msg_->sol_in[109].flags, 51) + << "incorrect value for sol_in[109].flags, expected 51, is " + << last_msg_->sol_in[109].flags; + EXPECT_EQ(last_msg_->sol_in[109].sensor_type, 252) + << "incorrect value for sol_in[109].sensor_type, expected 252, is " + << last_msg_->sol_in[109].sensor_type; + EXPECT_EQ(last_msg_->sol_in[110].flags, 59) + << "incorrect value for sol_in[110].flags, expected 59, is " + << last_msg_->sol_in[110].flags; + EXPECT_EQ(last_msg_->sol_in[110].sensor_type, 130) + << "incorrect value for sol_in[110].sensor_type, expected 130, is " + << last_msg_->sol_in[110].sensor_type; + EXPECT_EQ(last_msg_->sol_in[111].flags, 202) + << "incorrect value for sol_in[111].flags, expected 202, is " + << last_msg_->sol_in[111].flags; + EXPECT_EQ(last_msg_->sol_in[111].sensor_type, 166) + << "incorrect value for sol_in[111].sensor_type, expected 166, is " + << last_msg_->sol_in[111].sensor_type; + EXPECT_EQ(last_msg_->sol_in[112].flags, 170) + << "incorrect value for sol_in[112].flags, expected 170, is " + << last_msg_->sol_in[112].flags; + EXPECT_EQ(last_msg_->sol_in[112].sensor_type, 127) + << "incorrect value for sol_in[112].sensor_type, expected 127, is " + << last_msg_->sol_in[112].sensor_type; + EXPECT_EQ(last_msg_->sol_in[113].flags, 193) + << "incorrect value for sol_in[113].flags, expected 193, is " + << last_msg_->sol_in[113].flags; + EXPECT_EQ(last_msg_->sol_in[113].sensor_type, 58) + << "incorrect value for sol_in[113].sensor_type, expected 58, is " + << last_msg_->sol_in[113].sensor_type; + EXPECT_EQ(last_msg_->sol_in[114].flags, 125) + << "incorrect value for sol_in[114].flags, expected 125, is " + << last_msg_->sol_in[114].flags; + EXPECT_EQ(last_msg_->sol_in[114].sensor_type, 215) + << "incorrect value for sol_in[114].sensor_type, expected 215, is " + << last_msg_->sol_in[114].sensor_type; + EXPECT_EQ(last_msg_->sol_in[115].flags, 58) + << "incorrect value for sol_in[115].flags, expected 58, is " + << last_msg_->sol_in[115].flags; + EXPECT_EQ(last_msg_->sol_in[115].sensor_type, 22) + << "incorrect value for sol_in[115].sensor_type, expected 22, is " + << last_msg_->sol_in[115].sensor_type; + EXPECT_EQ(last_msg_->sol_in[116].flags, 47) + << "incorrect value for sol_in[116].flags, expected 47, is " + << last_msg_->sol_in[116].flags; + EXPECT_EQ(last_msg_->sol_in[116].sensor_type, 135) + << "incorrect value for sol_in[116].sensor_type, expected 135, is " + << last_msg_->sol_in[116].sensor_type; + EXPECT_EQ(last_msg_->sol_in[117].flags, 142) + << "incorrect value for sol_in[117].flags, expected 142, is " + << last_msg_->sol_in[117].flags; + EXPECT_EQ(last_msg_->sol_in[117].sensor_type, 88) + << "incorrect value for sol_in[117].sensor_type, expected 88, is " + << last_msg_->sol_in[117].sensor_type; + EXPECT_EQ(last_msg_->vdop, 41989) + << "incorrect value for vdop, expected 41989, is " << last_msg_->vdop; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc new file mode 100644 index 0000000000..7c8669c852 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrCodeBiases.cc @@ -0,0 +1,1112 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_code_biases_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_code_biases_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrCodeBiases0, Test) { + uint8_t encoded_frame[] = { + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, 254, + 132, 51, 4, 131, 240, 120, 83, 148, 209, 213, 62, 228, 232, 71, 66, + 188, 210, 128, 54, 131, 152, 129, 111, 139, 242, 177, 145, 44, 9, 245, + 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, 98, 191, 23, 128, + 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, 209, 139, 13, 101, 32, + 7, 18, 29, 70, 250, 109, 73, 202, 79, 144, 9, 146, 69, 241, 52, + 22, 99, 98, 204, 3, 171, 230, 180, 75, 62, 145, 86, 130, 31, 30, + 155, 37, 18, 55, 210, 39, 127, 242, 66, 13, 237, 152, 170, 212, 15, + 246, 59, 94, 180, 195, 157, 69, 100, 119, 16, 68, 179, 175, 144, 113, + 81, 82, 30, 151, 21, 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, + 6, 78, 81, 143, 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, + 247, 34, 97, 74, 97, 176, 48, 236, 173, 12, 174, 101, 130, 30, 169, + 193, 190, 204, 196, 123, 107, 25, 225, 74, 9, 10, 55, 3, 131, 246, + 99, 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, + 10, 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, 191, + 120, 77, 192, 91, 224, 1, 226, 50, 87, 146, 148, 238, 100, 179, 125, + 227, 215, 104, 184, 31, 57, 90, 79, 21, 156, 245, 81, 60, 93, 170, + 60, 200, 167, 13, 125, 132, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_code_biases_t *test_msg = (msg_ssr_code_biases_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[0].code = 51; + test_msg->biases[0].value = -31996; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[1].code = 240; + test_msg->biases[1].value = 21368; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[2].code = 148; + test_msg->biases[2].value = -10799; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[3].code = 62; + test_msg->biases[3].value = -5916; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[4].code = 71; + test_msg->biases[4].value = -17342; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[5].code = 210; + test_msg->biases[5].value = 13952; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[6].code = 131; + test_msg->biases[6].value = -32360; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[7].code = 111; + test_msg->biases[7].value = -3445; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[8].code = 177; + test_msg->biases[8].value = 11409; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[9].code = 9; + test_msg->biases[9].value = -12299; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[10].code = 241; + test_msg->biases[10].value = -26934; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[11].code = 141; + test_msg->biases[11].value = -24782; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[12].code = 220; + test_msg->biases[12].value = 9611; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[13].code = 187; + test_msg->biases[13].value = -16542; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[14].code = 23; + test_msg->biases[14].value = -30592; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[15].code = 167; + test_msg->biases[15].value = 1736; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[16].code = 211; + test_msg->biases[16].value = 5978; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[17].code = 244; + test_msg->biases[17].value = -10358; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[18].code = 209; + test_msg->biases[18].value = 3467; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[19].code = 101; + test_msg->biases[19].value = 1824; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[20].code = 18; + test_msg->biases[20].value = 17949; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[21].code = 250; + test_msg->biases[21].value = 18797; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[22].code = 202; + test_msg->biases[22].value = -28593; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[23].code = 9; + test_msg->biases[23].value = 17810; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[24].code = 241; + test_msg->biases[24].value = 5684; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[25].code = 99; + test_msg->biases[25].value = -13214; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[26].code = 3; + test_msg->biases[26].value = -6485; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[27].code = 180; + test_msg->biases[27].value = 15947; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[28].code = 145; + test_msg->biases[28].value = -32170; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[29].code = 31; + test_msg->biases[29].value = -25826; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[30].code = 37; + test_msg->biases[30].value = 14098; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[31].code = 210; + test_msg->biases[31].value = 32551; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[32].code = 242; + test_msg->biases[32].value = 3394; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[33].code = 237; + test_msg->biases[33].value = -21864; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[34].code = 212; + test_msg->biases[34].value = -2545; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[35].code = 59; + test_msg->biases[35].value = -19362; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[36].code = 195; + test_msg->biases[36].value = 17821; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[37].code = 100; + test_msg->biases[37].value = 4215; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[38].code = 68; + test_msg->biases[38].value = -20557; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[39].code = 144; + test_msg->biases[39].value = 20849; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[40].code = 82; + test_msg->biases[40].value = -26850; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[41].code = 21; + test_msg->biases[41].value = 10605; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[42].code = 225; + test_msg->biases[42].value = 19720; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[43].code = 164; + test_msg->biases[43].value = 157; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[44].code = 73; + test_msg->biases[44].value = 1566; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[45].code = 78; + test_msg->biases[45].value = -28847; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[46].code = 116; + test_msg->biases[46].value = -26640; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[47].code = 55; + test_msg->biases[47].value = -22087; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[48].code = 254; + test_msg->biases[48].value = 10035; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[49].code = 74; + test_msg->biases[49].value = -2129; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[50].code = 34; + test_msg->biases[50].value = 19041; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[51].code = 97; + test_msg->biases[51].value = 12464; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[52].code = 236; + test_msg->biases[52].value = 3245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[53].code = 174; + test_msg->biases[53].value = -32155; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[54].code = 30; + test_msg->biases[54].value = -15959; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[55].code = 190; + test_msg->biases[55].value = -15156; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[56].code = 123; + test_msg->biases[56].value = 6507; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[57].code = 225; + test_msg->biases[57].value = 2378; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[58].code = 10; + test_msg->biases[58].value = 823; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[59].code = 131; + test_msg->biases[59].value = 25590; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[60].code = 133; + test_msg->biases[60].value = -7390; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[61].code = 203; + test_msg->biases[61].value = 4676; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[62].code = 97; + test_msg->biases[62].value = 23007; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[63].code = 192; + test_msg->biases[63].value = 13046; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[64].code = 69; + test_msg->biases[64].value = 2651; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[65].code = 151; + test_msg->biases[65].value = 30282; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[66].code = 110; + test_msg->biases[66].value = -22492; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[67].code = 247; + test_msg->biases[67].value = 19872; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[68].code = 179; + test_msg->biases[68].value = -19827; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[69].code = 99; + test_msg->biases[69].value = 30911; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[70].code = 77; + test_msg->biases[70].value = 23488; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[71].code = 224; + test_msg->biases[71].value = -7679; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[72].code = 50; + test_msg->biases[72].value = -28073; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[73].code = 148; + test_msg->biases[73].value = 25838; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[74].code = 179; + test_msg->biases[74].value = -7299; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[75].code = 215; + test_msg->biases[75].value = -18328; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[76].code = 31; + test_msg->biases[76].value = 23097; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[77].code = 79; + test_msg->biases[77].value = -25579; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[78].code = 245; + test_msg->biases[78].value = 15441; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[79].code = 93; + test_msg->biases[79].value = 15530; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[80].code = 200; + test_msg->biases[80].value = 3495; + test_msg->iod_ssr = 132; + test_msg->sid.code = 241; + test_msg->sid.sat = 133; + test_msg->time.tow = 387144400; + test_msg->time.wn = 16905; + test_msg->update_interval = 254; + + EXPECT_EQ(send_message(0x5e1, 22311, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 22311); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->biases[0].code, 51) + << "incorrect value for biases[0].code, expected 51, is " + << last_msg_->biases[0].code; + EXPECT_EQ(last_msg_->biases[0].value, -31996) + << "incorrect value for biases[0].value, expected -31996, is " + << last_msg_->biases[0].value; + EXPECT_EQ(last_msg_->biases[1].code, 240) + << "incorrect value for biases[1].code, expected 240, is " + << last_msg_->biases[1].code; + EXPECT_EQ(last_msg_->biases[1].value, 21368) + << "incorrect value for biases[1].value, expected 21368, is " + << last_msg_->biases[1].value; + EXPECT_EQ(last_msg_->biases[2].code, 148) + << "incorrect value for biases[2].code, expected 148, is " + << last_msg_->biases[2].code; + EXPECT_EQ(last_msg_->biases[2].value, -10799) + << "incorrect value for biases[2].value, expected -10799, is " + << last_msg_->biases[2].value; + EXPECT_EQ(last_msg_->biases[3].code, 62) + << "incorrect value for biases[3].code, expected 62, is " + << last_msg_->biases[3].code; + EXPECT_EQ(last_msg_->biases[3].value, -5916) + << "incorrect value for biases[3].value, expected -5916, is " + << last_msg_->biases[3].value; + EXPECT_EQ(last_msg_->biases[4].code, 71) + << "incorrect value for biases[4].code, expected 71, is " + << last_msg_->biases[4].code; + EXPECT_EQ(last_msg_->biases[4].value, -17342) + << "incorrect value for biases[4].value, expected -17342, is " + << last_msg_->biases[4].value; + EXPECT_EQ(last_msg_->biases[5].code, 210) + << "incorrect value for biases[5].code, expected 210, is " + << last_msg_->biases[5].code; + EXPECT_EQ(last_msg_->biases[5].value, 13952) + << "incorrect value for biases[5].value, expected 13952, is " + << last_msg_->biases[5].value; + EXPECT_EQ(last_msg_->biases[6].code, 131) + << "incorrect value for biases[6].code, expected 131, is " + << last_msg_->biases[6].code; + EXPECT_EQ(last_msg_->biases[6].value, -32360) + << "incorrect value for biases[6].value, expected -32360, is " + << last_msg_->biases[6].value; + EXPECT_EQ(last_msg_->biases[7].code, 111) + << "incorrect value for biases[7].code, expected 111, is " + << last_msg_->biases[7].code; + EXPECT_EQ(last_msg_->biases[7].value, -3445) + << "incorrect value for biases[7].value, expected -3445, is " + << last_msg_->biases[7].value; + EXPECT_EQ(last_msg_->biases[8].code, 177) + << "incorrect value for biases[8].code, expected 177, is " + << last_msg_->biases[8].code; + EXPECT_EQ(last_msg_->biases[8].value, 11409) + << "incorrect value for biases[8].value, expected 11409, is " + << last_msg_->biases[8].value; + EXPECT_EQ(last_msg_->biases[9].code, 9) + << "incorrect value for biases[9].code, expected 9, is " + << last_msg_->biases[9].code; + EXPECT_EQ(last_msg_->biases[9].value, -12299) + << "incorrect value for biases[9].value, expected -12299, is " + << last_msg_->biases[9].value; + EXPECT_EQ(last_msg_->biases[10].code, 241) + << "incorrect value for biases[10].code, expected 241, is " + << last_msg_->biases[10].code; + EXPECT_EQ(last_msg_->biases[10].value, -26934) + << "incorrect value for biases[10].value, expected -26934, is " + << last_msg_->biases[10].value; + EXPECT_EQ(last_msg_->biases[11].code, 141) + << "incorrect value for biases[11].code, expected 141, is " + << last_msg_->biases[11].code; + EXPECT_EQ(last_msg_->biases[11].value, -24782) + << "incorrect value for biases[11].value, expected -24782, is " + << last_msg_->biases[11].value; + EXPECT_EQ(last_msg_->biases[12].code, 220) + << "incorrect value for biases[12].code, expected 220, is " + << last_msg_->biases[12].code; + EXPECT_EQ(last_msg_->biases[12].value, 9611) + << "incorrect value for biases[12].value, expected 9611, is " + << last_msg_->biases[12].value; + EXPECT_EQ(last_msg_->biases[13].code, 187) + << "incorrect value for biases[13].code, expected 187, is " + << last_msg_->biases[13].code; + EXPECT_EQ(last_msg_->biases[13].value, -16542) + << "incorrect value for biases[13].value, expected -16542, is " + << last_msg_->biases[13].value; + EXPECT_EQ(last_msg_->biases[14].code, 23) + << "incorrect value for biases[14].code, expected 23, is " + << last_msg_->biases[14].code; + EXPECT_EQ(last_msg_->biases[14].value, -30592) + << "incorrect value for biases[14].value, expected -30592, is " + << last_msg_->biases[14].value; + EXPECT_EQ(last_msg_->biases[15].code, 167) + << "incorrect value for biases[15].code, expected 167, is " + << last_msg_->biases[15].code; + EXPECT_EQ(last_msg_->biases[15].value, 1736) + << "incorrect value for biases[15].value, expected 1736, is " + << last_msg_->biases[15].value; + EXPECT_EQ(last_msg_->biases[16].code, 211) + << "incorrect value for biases[16].code, expected 211, is " + << last_msg_->biases[16].code; + EXPECT_EQ(last_msg_->biases[16].value, 5978) + << "incorrect value for biases[16].value, expected 5978, is " + << last_msg_->biases[16].value; + EXPECT_EQ(last_msg_->biases[17].code, 244) + << "incorrect value for biases[17].code, expected 244, is " + << last_msg_->biases[17].code; + EXPECT_EQ(last_msg_->biases[17].value, -10358) + << "incorrect value for biases[17].value, expected -10358, is " + << last_msg_->biases[17].value; + EXPECT_EQ(last_msg_->biases[18].code, 209) + << "incorrect value for biases[18].code, expected 209, is " + << last_msg_->biases[18].code; + EXPECT_EQ(last_msg_->biases[18].value, 3467) + << "incorrect value for biases[18].value, expected 3467, is " + << last_msg_->biases[18].value; + EXPECT_EQ(last_msg_->biases[19].code, 101) + << "incorrect value for biases[19].code, expected 101, is " + << last_msg_->biases[19].code; + EXPECT_EQ(last_msg_->biases[19].value, 1824) + << "incorrect value for biases[19].value, expected 1824, is " + << last_msg_->biases[19].value; + EXPECT_EQ(last_msg_->biases[20].code, 18) + << "incorrect value for biases[20].code, expected 18, is " + << last_msg_->biases[20].code; + EXPECT_EQ(last_msg_->biases[20].value, 17949) + << "incorrect value for biases[20].value, expected 17949, is " + << last_msg_->biases[20].value; + EXPECT_EQ(last_msg_->biases[21].code, 250) + << "incorrect value for biases[21].code, expected 250, is " + << last_msg_->biases[21].code; + EXPECT_EQ(last_msg_->biases[21].value, 18797) + << "incorrect value for biases[21].value, expected 18797, is " + << last_msg_->biases[21].value; + EXPECT_EQ(last_msg_->biases[22].code, 202) + << "incorrect value for biases[22].code, expected 202, is " + << last_msg_->biases[22].code; + EXPECT_EQ(last_msg_->biases[22].value, -28593) + << "incorrect value for biases[22].value, expected -28593, is " + << last_msg_->biases[22].value; + EXPECT_EQ(last_msg_->biases[23].code, 9) + << "incorrect value for biases[23].code, expected 9, is " + << last_msg_->biases[23].code; + EXPECT_EQ(last_msg_->biases[23].value, 17810) + << "incorrect value for biases[23].value, expected 17810, is " + << last_msg_->biases[23].value; + EXPECT_EQ(last_msg_->biases[24].code, 241) + << "incorrect value for biases[24].code, expected 241, is " + << last_msg_->biases[24].code; + EXPECT_EQ(last_msg_->biases[24].value, 5684) + << "incorrect value for biases[24].value, expected 5684, is " + << last_msg_->biases[24].value; + EXPECT_EQ(last_msg_->biases[25].code, 99) + << "incorrect value for biases[25].code, expected 99, is " + << last_msg_->biases[25].code; + EXPECT_EQ(last_msg_->biases[25].value, -13214) + << "incorrect value for biases[25].value, expected -13214, is " + << last_msg_->biases[25].value; + EXPECT_EQ(last_msg_->biases[26].code, 3) + << "incorrect value for biases[26].code, expected 3, is " + << last_msg_->biases[26].code; + EXPECT_EQ(last_msg_->biases[26].value, -6485) + << "incorrect value for biases[26].value, expected -6485, is " + << last_msg_->biases[26].value; + EXPECT_EQ(last_msg_->biases[27].code, 180) + << "incorrect value for biases[27].code, expected 180, is " + << last_msg_->biases[27].code; + EXPECT_EQ(last_msg_->biases[27].value, 15947) + << "incorrect value for biases[27].value, expected 15947, is " + << last_msg_->biases[27].value; + EXPECT_EQ(last_msg_->biases[28].code, 145) + << "incorrect value for biases[28].code, expected 145, is " + << last_msg_->biases[28].code; + EXPECT_EQ(last_msg_->biases[28].value, -32170) + << "incorrect value for biases[28].value, expected -32170, is " + << last_msg_->biases[28].value; + EXPECT_EQ(last_msg_->biases[29].code, 31) + << "incorrect value for biases[29].code, expected 31, is " + << last_msg_->biases[29].code; + EXPECT_EQ(last_msg_->biases[29].value, -25826) + << "incorrect value for biases[29].value, expected -25826, is " + << last_msg_->biases[29].value; + EXPECT_EQ(last_msg_->biases[30].code, 37) + << "incorrect value for biases[30].code, expected 37, is " + << last_msg_->biases[30].code; + EXPECT_EQ(last_msg_->biases[30].value, 14098) + << "incorrect value for biases[30].value, expected 14098, is " + << last_msg_->biases[30].value; + EXPECT_EQ(last_msg_->biases[31].code, 210) + << "incorrect value for biases[31].code, expected 210, is " + << last_msg_->biases[31].code; + EXPECT_EQ(last_msg_->biases[31].value, 32551) + << "incorrect value for biases[31].value, expected 32551, is " + << last_msg_->biases[31].value; + EXPECT_EQ(last_msg_->biases[32].code, 242) + << "incorrect value for biases[32].code, expected 242, is " + << last_msg_->biases[32].code; + EXPECT_EQ(last_msg_->biases[32].value, 3394) + << "incorrect value for biases[32].value, expected 3394, is " + << last_msg_->biases[32].value; + EXPECT_EQ(last_msg_->biases[33].code, 237) + << "incorrect value for biases[33].code, expected 237, is " + << last_msg_->biases[33].code; + EXPECT_EQ(last_msg_->biases[33].value, -21864) + << "incorrect value for biases[33].value, expected -21864, is " + << last_msg_->biases[33].value; + EXPECT_EQ(last_msg_->biases[34].code, 212) + << "incorrect value for biases[34].code, expected 212, is " + << last_msg_->biases[34].code; + EXPECT_EQ(last_msg_->biases[34].value, -2545) + << "incorrect value for biases[34].value, expected -2545, is " + << last_msg_->biases[34].value; + EXPECT_EQ(last_msg_->biases[35].code, 59) + << "incorrect value for biases[35].code, expected 59, is " + << last_msg_->biases[35].code; + EXPECT_EQ(last_msg_->biases[35].value, -19362) + << "incorrect value for biases[35].value, expected -19362, is " + << last_msg_->biases[35].value; + EXPECT_EQ(last_msg_->biases[36].code, 195) + << "incorrect value for biases[36].code, expected 195, is " + << last_msg_->biases[36].code; + EXPECT_EQ(last_msg_->biases[36].value, 17821) + << "incorrect value for biases[36].value, expected 17821, is " + << last_msg_->biases[36].value; + EXPECT_EQ(last_msg_->biases[37].code, 100) + << "incorrect value for biases[37].code, expected 100, is " + << last_msg_->biases[37].code; + EXPECT_EQ(last_msg_->biases[37].value, 4215) + << "incorrect value for biases[37].value, expected 4215, is " + << last_msg_->biases[37].value; + EXPECT_EQ(last_msg_->biases[38].code, 68) + << "incorrect value for biases[38].code, expected 68, is " + << last_msg_->biases[38].code; + EXPECT_EQ(last_msg_->biases[38].value, -20557) + << "incorrect value for biases[38].value, expected -20557, is " + << last_msg_->biases[38].value; + EXPECT_EQ(last_msg_->biases[39].code, 144) + << "incorrect value for biases[39].code, expected 144, is " + << last_msg_->biases[39].code; + EXPECT_EQ(last_msg_->biases[39].value, 20849) + << "incorrect value for biases[39].value, expected 20849, is " + << last_msg_->biases[39].value; + EXPECT_EQ(last_msg_->biases[40].code, 82) + << "incorrect value for biases[40].code, expected 82, is " + << last_msg_->biases[40].code; + EXPECT_EQ(last_msg_->biases[40].value, -26850) + << "incorrect value for biases[40].value, expected -26850, is " + << last_msg_->biases[40].value; + EXPECT_EQ(last_msg_->biases[41].code, 21) + << "incorrect value for biases[41].code, expected 21, is " + << last_msg_->biases[41].code; + EXPECT_EQ(last_msg_->biases[41].value, 10605) + << "incorrect value for biases[41].value, expected 10605, is " + << last_msg_->biases[41].value; + EXPECT_EQ(last_msg_->biases[42].code, 225) + << "incorrect value for biases[42].code, expected 225, is " + << last_msg_->biases[42].code; + EXPECT_EQ(last_msg_->biases[42].value, 19720) + << "incorrect value for biases[42].value, expected 19720, is " + << last_msg_->biases[42].value; + EXPECT_EQ(last_msg_->biases[43].code, 164) + << "incorrect value for biases[43].code, expected 164, is " + << last_msg_->biases[43].code; + EXPECT_EQ(last_msg_->biases[43].value, 157) + << "incorrect value for biases[43].value, expected 157, is " + << last_msg_->biases[43].value; + EXPECT_EQ(last_msg_->biases[44].code, 73) + << "incorrect value for biases[44].code, expected 73, is " + << last_msg_->biases[44].code; + EXPECT_EQ(last_msg_->biases[44].value, 1566) + << "incorrect value for biases[44].value, expected 1566, is " + << last_msg_->biases[44].value; + EXPECT_EQ(last_msg_->biases[45].code, 78) + << "incorrect value for biases[45].code, expected 78, is " + << last_msg_->biases[45].code; + EXPECT_EQ(last_msg_->biases[45].value, -28847) + << "incorrect value for biases[45].value, expected -28847, is " + << last_msg_->biases[45].value; + EXPECT_EQ(last_msg_->biases[46].code, 116) + << "incorrect value for biases[46].code, expected 116, is " + << last_msg_->biases[46].code; + EXPECT_EQ(last_msg_->biases[46].value, -26640) + << "incorrect value for biases[46].value, expected -26640, is " + << last_msg_->biases[46].value; + EXPECT_EQ(last_msg_->biases[47].code, 55) + << "incorrect value for biases[47].code, expected 55, is " + << last_msg_->biases[47].code; + EXPECT_EQ(last_msg_->biases[47].value, -22087) + << "incorrect value for biases[47].value, expected -22087, is " + << last_msg_->biases[47].value; + EXPECT_EQ(last_msg_->biases[48].code, 254) + << "incorrect value for biases[48].code, expected 254, is " + << last_msg_->biases[48].code; + EXPECT_EQ(last_msg_->biases[48].value, 10035) + << "incorrect value for biases[48].value, expected 10035, is " + << last_msg_->biases[48].value; + EXPECT_EQ(last_msg_->biases[49].code, 74) + << "incorrect value for biases[49].code, expected 74, is " + << last_msg_->biases[49].code; + EXPECT_EQ(last_msg_->biases[49].value, -2129) + << "incorrect value for biases[49].value, expected -2129, is " + << last_msg_->biases[49].value; + EXPECT_EQ(last_msg_->biases[50].code, 34) + << "incorrect value for biases[50].code, expected 34, is " + << last_msg_->biases[50].code; + EXPECT_EQ(last_msg_->biases[50].value, 19041) + << "incorrect value for biases[50].value, expected 19041, is " + << last_msg_->biases[50].value; + EXPECT_EQ(last_msg_->biases[51].code, 97) + << "incorrect value for biases[51].code, expected 97, is " + << last_msg_->biases[51].code; + EXPECT_EQ(last_msg_->biases[51].value, 12464) + << "incorrect value for biases[51].value, expected 12464, is " + << last_msg_->biases[51].value; + EXPECT_EQ(last_msg_->biases[52].code, 236) + << "incorrect value for biases[52].code, expected 236, is " + << last_msg_->biases[52].code; + EXPECT_EQ(last_msg_->biases[52].value, 3245) + << "incorrect value for biases[52].value, expected 3245, is " + << last_msg_->biases[52].value; + EXPECT_EQ(last_msg_->biases[53].code, 174) + << "incorrect value for biases[53].code, expected 174, is " + << last_msg_->biases[53].code; + EXPECT_EQ(last_msg_->biases[53].value, -32155) + << "incorrect value for biases[53].value, expected -32155, is " + << last_msg_->biases[53].value; + EXPECT_EQ(last_msg_->biases[54].code, 30) + << "incorrect value for biases[54].code, expected 30, is " + << last_msg_->biases[54].code; + EXPECT_EQ(last_msg_->biases[54].value, -15959) + << "incorrect value for biases[54].value, expected -15959, is " + << last_msg_->biases[54].value; + EXPECT_EQ(last_msg_->biases[55].code, 190) + << "incorrect value for biases[55].code, expected 190, is " + << last_msg_->biases[55].code; + EXPECT_EQ(last_msg_->biases[55].value, -15156) + << "incorrect value for biases[55].value, expected -15156, is " + << last_msg_->biases[55].value; + EXPECT_EQ(last_msg_->biases[56].code, 123) + << "incorrect value for biases[56].code, expected 123, is " + << last_msg_->biases[56].code; + EXPECT_EQ(last_msg_->biases[56].value, 6507) + << "incorrect value for biases[56].value, expected 6507, is " + << last_msg_->biases[56].value; + EXPECT_EQ(last_msg_->biases[57].code, 225) + << "incorrect value for biases[57].code, expected 225, is " + << last_msg_->biases[57].code; + EXPECT_EQ(last_msg_->biases[57].value, 2378) + << "incorrect value for biases[57].value, expected 2378, is " + << last_msg_->biases[57].value; + EXPECT_EQ(last_msg_->biases[58].code, 10) + << "incorrect value for biases[58].code, expected 10, is " + << last_msg_->biases[58].code; + EXPECT_EQ(last_msg_->biases[58].value, 823) + << "incorrect value for biases[58].value, expected 823, is " + << last_msg_->biases[58].value; + EXPECT_EQ(last_msg_->biases[59].code, 131) + << "incorrect value for biases[59].code, expected 131, is " + << last_msg_->biases[59].code; + EXPECT_EQ(last_msg_->biases[59].value, 25590) + << "incorrect value for biases[59].value, expected 25590, is " + << last_msg_->biases[59].value; + EXPECT_EQ(last_msg_->biases[60].code, 133) + << "incorrect value for biases[60].code, expected 133, is " + << last_msg_->biases[60].code; + EXPECT_EQ(last_msg_->biases[60].value, -7390) + << "incorrect value for biases[60].value, expected -7390, is " + << last_msg_->biases[60].value; + EXPECT_EQ(last_msg_->biases[61].code, 203) + << "incorrect value for biases[61].code, expected 203, is " + << last_msg_->biases[61].code; + EXPECT_EQ(last_msg_->biases[61].value, 4676) + << "incorrect value for biases[61].value, expected 4676, is " + << last_msg_->biases[61].value; + EXPECT_EQ(last_msg_->biases[62].code, 97) + << "incorrect value for biases[62].code, expected 97, is " + << last_msg_->biases[62].code; + EXPECT_EQ(last_msg_->biases[62].value, 23007) + << "incorrect value for biases[62].value, expected 23007, is " + << last_msg_->biases[62].value; + EXPECT_EQ(last_msg_->biases[63].code, 192) + << "incorrect value for biases[63].code, expected 192, is " + << last_msg_->biases[63].code; + EXPECT_EQ(last_msg_->biases[63].value, 13046) + << "incorrect value for biases[63].value, expected 13046, is " + << last_msg_->biases[63].value; + EXPECT_EQ(last_msg_->biases[64].code, 69) + << "incorrect value for biases[64].code, expected 69, is " + << last_msg_->biases[64].code; + EXPECT_EQ(last_msg_->biases[64].value, 2651) + << "incorrect value for biases[64].value, expected 2651, is " + << last_msg_->biases[64].value; + EXPECT_EQ(last_msg_->biases[65].code, 151) + << "incorrect value for biases[65].code, expected 151, is " + << last_msg_->biases[65].code; + EXPECT_EQ(last_msg_->biases[65].value, 30282) + << "incorrect value for biases[65].value, expected 30282, is " + << last_msg_->biases[65].value; + EXPECT_EQ(last_msg_->biases[66].code, 110) + << "incorrect value for biases[66].code, expected 110, is " + << last_msg_->biases[66].code; + EXPECT_EQ(last_msg_->biases[66].value, -22492) + << "incorrect value for biases[66].value, expected -22492, is " + << last_msg_->biases[66].value; + EXPECT_EQ(last_msg_->biases[67].code, 247) + << "incorrect value for biases[67].code, expected 247, is " + << last_msg_->biases[67].code; + EXPECT_EQ(last_msg_->biases[67].value, 19872) + << "incorrect value for biases[67].value, expected 19872, is " + << last_msg_->biases[67].value; + EXPECT_EQ(last_msg_->biases[68].code, 179) + << "incorrect value for biases[68].code, expected 179, is " + << last_msg_->biases[68].code; + EXPECT_EQ(last_msg_->biases[68].value, -19827) + << "incorrect value for biases[68].value, expected -19827, is " + << last_msg_->biases[68].value; + EXPECT_EQ(last_msg_->biases[69].code, 99) + << "incorrect value for biases[69].code, expected 99, is " + << last_msg_->biases[69].code; + EXPECT_EQ(last_msg_->biases[69].value, 30911) + << "incorrect value for biases[69].value, expected 30911, is " + << last_msg_->biases[69].value; + EXPECT_EQ(last_msg_->biases[70].code, 77) + << "incorrect value for biases[70].code, expected 77, is " + << last_msg_->biases[70].code; + EXPECT_EQ(last_msg_->biases[70].value, 23488) + << "incorrect value for biases[70].value, expected 23488, is " + << last_msg_->biases[70].value; + EXPECT_EQ(last_msg_->biases[71].code, 224) + << "incorrect value for biases[71].code, expected 224, is " + << last_msg_->biases[71].code; + EXPECT_EQ(last_msg_->biases[71].value, -7679) + << "incorrect value for biases[71].value, expected -7679, is " + << last_msg_->biases[71].value; + EXPECT_EQ(last_msg_->biases[72].code, 50) + << "incorrect value for biases[72].code, expected 50, is " + << last_msg_->biases[72].code; + EXPECT_EQ(last_msg_->biases[72].value, -28073) + << "incorrect value for biases[72].value, expected -28073, is " + << last_msg_->biases[72].value; + EXPECT_EQ(last_msg_->biases[73].code, 148) + << "incorrect value for biases[73].code, expected 148, is " + << last_msg_->biases[73].code; + EXPECT_EQ(last_msg_->biases[73].value, 25838) + << "incorrect value for biases[73].value, expected 25838, is " + << last_msg_->biases[73].value; + EXPECT_EQ(last_msg_->biases[74].code, 179) + << "incorrect value for biases[74].code, expected 179, is " + << last_msg_->biases[74].code; + EXPECT_EQ(last_msg_->biases[74].value, -7299) + << "incorrect value for biases[74].value, expected -7299, is " + << last_msg_->biases[74].value; + EXPECT_EQ(last_msg_->biases[75].code, 215) + << "incorrect value for biases[75].code, expected 215, is " + << last_msg_->biases[75].code; + EXPECT_EQ(last_msg_->biases[75].value, -18328) + << "incorrect value for biases[75].value, expected -18328, is " + << last_msg_->biases[75].value; + EXPECT_EQ(last_msg_->biases[76].code, 31) + << "incorrect value for biases[76].code, expected 31, is " + << last_msg_->biases[76].code; + EXPECT_EQ(last_msg_->biases[76].value, 23097) + << "incorrect value for biases[76].value, expected 23097, is " + << last_msg_->biases[76].value; + EXPECT_EQ(last_msg_->biases[77].code, 79) + << "incorrect value for biases[77].code, expected 79, is " + << last_msg_->biases[77].code; + EXPECT_EQ(last_msg_->biases[77].value, -25579) + << "incorrect value for biases[77].value, expected -25579, is " + << last_msg_->biases[77].value; + EXPECT_EQ(last_msg_->biases[78].code, 245) + << "incorrect value for biases[78].code, expected 245, is " + << last_msg_->biases[78].code; + EXPECT_EQ(last_msg_->biases[78].value, 15441) + << "incorrect value for biases[78].value, expected 15441, is " + << last_msg_->biases[78].value; + EXPECT_EQ(last_msg_->biases[79].code, 93) + << "incorrect value for biases[79].code, expected 93, is " + << last_msg_->biases[79].code; + EXPECT_EQ(last_msg_->biases[79].value, 15530) + << "incorrect value for biases[79].value, expected 15530, is " + << last_msg_->biases[79].value; + EXPECT_EQ(last_msg_->biases[80].code, 200) + << "incorrect value for biases[80].code, expected 200, is " + << last_msg_->biases[80].code; + EXPECT_EQ(last_msg_->biases[80].value, 3495) + << "incorrect value for biases[80].value, expected 3495, is " + << last_msg_->biases[80].value; + EXPECT_EQ(last_msg_->iod_ssr, 132) + << "incorrect value for iod_ssr, expected 132, is " << last_msg_->iod_ssr; + EXPECT_EQ(last_msg_->sid.code, 241) + << "incorrect value for sid.code, expected 241, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 133) + << "incorrect value for sid.sat, expected 133, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->time.tow, 387144400) + << "incorrect value for time.tow, expected 387144400, is " + << last_msg_->time.tow; + EXPECT_EQ(last_msg_->time.wn, 16905) + << "incorrect value for time.wn, expected 16905, is " + << last_msg_->time.wn; + EXPECT_EQ(last_msg_->update_interval, 254) + << "incorrect value for update_interval, expected 254, is " + << last_msg_->update_interval; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc new file mode 100644 index 0000000000..d22a0befdf --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGridDefinitionDepA.cc @@ -0,0 +1,2112 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_grid_definition_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_grid_definition_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrGridDefinitionDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, 52, + 92, 104, 25, 204, 182, 22, 98, 203, 123, 211, 38, 13, 253, 129, 173, + 171, 235, 253, 26, 203, 3, 120, 126, 42, 44, 39, 87, 69, 154, 13, + 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, 57, 120, 243, 151, + 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, 144, 158, 239, 90, 56, + 71, 120, 67, 221, 114, 10, 190, 4, 230, 164, 171, 78, 185, 90, 46, + 177, 82, 228, 123, 222, 227, 145, 195, 219, 27, 56, 227, 246, 215, 144, + 158, 31, 214, 241, 254, 200, 86, 142, 89, 12, 121, 29, 124, 9, 19, + 153, 44, 35, 126, 14, 217, 65, 116, 26, 139, 122, 114, 90, 124, 81, + 0, 186, 246, 46, 98, 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, + 42, 150, 221, 102, 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, + 128, 193, 53, 94, 99, 63, 182, 2, 186, 220, 77, 186, 224, 220, 13, + 212, 182, 88, 15, 151, 5, 93, 251, 164, 18, 228, 168, 226, 195, 44, + 170, 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, 159, 189, + 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, 19, + 151, 136, 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, 212, 68, + 60, 206, 106, 207, 243, 158, 94, 6, 3, 205, 92, 84, 2, 220, 50, + 61, 38, 141, 117, 108, 101, 76, 139, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_grid_definition_dep_a_t *test_msg = + (msg_ssr_grid_definition_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.area_width = 43860; + test_msg->header.lat_nw_corner_enc = 34021; + test_msg->header.lon_nw_corner_enc = 11919; + test_msg->header.num_msgs = 204; + test_msg->header.region_size_inverse = 11; + test_msg->header.seq_num = 52; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[0] = 92; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[1] = 104; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[2] = 25; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[3] = 204; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[4] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[5] = 22; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[6] = 98; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[7] = 203; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[8] = 123; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[9] = 211; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[10] = 38; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[11] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[12] = 253; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[13] = 129; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[14] = 173; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[15] = 171; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[16] = 235; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[17] = 253; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[18] = 26; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[19] = 203; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[20] = 3; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[21] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[22] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[23] = 42; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[24] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[25] = 39; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[26] = 87; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[27] = 69; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[28] = 154; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[29] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[30] = 28; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[31] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[32] = 32; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[33] = 47; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[34] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[35] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[36] = 39; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[37] = 198; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[38] = 134; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[39] = 235; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[40] = 134; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[41] = 57; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[42] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[43] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[44] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[45] = 35; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[46] = 17; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[47] = 201; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[48] = 211; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[49] = 125; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[50] = 117; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[51] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[52] = 142; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[53] = 101; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[54] = 239; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[55] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[56] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[57] = 239; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[58] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[59] = 56; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[60] = 71; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[61] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[62] = 67; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[63] = 221; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[64] = 114; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[65] = 10; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[66] = 190; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[67] = 4; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[68] = 230; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[69] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[70] = 171; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[71] = 78; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[72] = 185; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[73] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[74] = 46; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[75] = 177; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[76] = 82; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[77] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[78] = 123; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[79] = 222; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[80] = 227; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[81] = 145; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[82] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[83] = 219; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[84] = 27; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[85] = 56; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[86] = 227; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[87] = 246; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[88] = 215; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[89] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[90] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[91] = 31; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[92] = 214; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[93] = 241; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[94] = 254; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[95] = 200; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[96] = 86; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[97] = 142; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[98] = 89; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[99] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[100] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[101] = 29; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[102] = 124; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[103] = 9; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[104] = 19; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[105] = 153; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[106] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[107] = 35; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[108] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[109] = 14; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[110] = 217; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[111] = 65; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[112] = 116; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[113] = 26; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[114] = 139; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[115] = 122; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[116] = 114; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[117] = 90; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[118] = 124; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[119] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[120] = 0; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[121] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[122] = 246; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[123] = 46; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[124] = 98; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[125] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[126] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[127] = 198; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[128] = 217; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[129] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[130] = 30; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[131] = 202; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[132] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[133] = 135; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[134] = 61; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[135] = 42; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[136] = 150; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[137] = 221; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[138] = 102; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[139] = 83; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[140] = 179; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[141] = 43; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[142] = 252; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[143] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[144] = 62; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[145] = 126; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[146] = 204; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[147] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[148] = 238; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[149] = 18; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[150] = 128; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[151] = 193; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[152] = 53; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[153] = 94; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[154] = 99; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[155] = 63; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[156] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[157] = 2; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[158] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[159] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[160] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[161] = 186; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[162] = 224; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[163] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[164] = 13; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[165] = 212; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[166] = 182; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[167] = 88; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[168] = 15; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[169] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[170] = 5; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[171] = 93; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[172] = 251; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[173] = 164; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[174] = 18; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[175] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[176] = 168; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[177] = 226; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[178] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[179] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[180] = 170; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[181] = 145; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[182] = 36; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[183] = 58; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[184] = 96; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[185] = 107; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[186] = 144; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[187] = 11; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[188] = 228; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[189] = 12; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[190] = 163; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[191] = 238; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[192] = 247; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[193] = 159; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[194] = 189; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[195] = 1; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[196] = 115; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[197] = 65; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[198] = 202; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[199] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[200] = 47; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[201] = 193; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[202] = 11; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[203] = 96; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[204] = 93; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[205] = 72; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[206] = 81; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[207] = 207; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[208] = 121; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[209] = 19; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[210] = 151; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[211] = 136; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[212] = 233; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[213] = 51; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[214] = 133; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[215] = 195; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[216] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[217] = 44; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[218] = 147; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[219] = 206; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[220] = 120; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[221] = 252; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[222] = 77; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[223] = 212; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[224] = 68; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[225] = 60; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[226] = 206; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[227] = 106; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[228] = 207; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[229] = 243; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[230] = 158; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[231] = 94; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[232] = 6; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[233] = 3; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[234] = 205; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[235] = 92; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[236] = 84; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[237] = 2; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[238] = 220; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[239] = 50; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[240] = 61; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[241] = 38; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[242] = 141; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[243] = 117; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[244] = 108; + if (sizeof(test_msg->rle_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->rle_list[0])); + } + test_msg->rle_list[245] = 101; + + EXPECT_EQ(send_message(0x5f5, 63413, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 63413); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.area_width, 43860) + << "incorrect value for header.area_width, expected 43860, is " + << last_msg_->header.area_width; + EXPECT_EQ(last_msg_->header.lat_nw_corner_enc, 34021) + << "incorrect value for header.lat_nw_corner_enc, expected 34021, is " + << last_msg_->header.lat_nw_corner_enc; + EXPECT_EQ(last_msg_->header.lon_nw_corner_enc, 11919) + << "incorrect value for header.lon_nw_corner_enc, expected 11919, is " + << last_msg_->header.lon_nw_corner_enc; + EXPECT_EQ(last_msg_->header.num_msgs, 204) + << "incorrect value for header.num_msgs, expected 204, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.region_size_inverse, 11) + << "incorrect value for header.region_size_inverse, expected 11, is " + << last_msg_->header.region_size_inverse; + EXPECT_EQ(last_msg_->header.seq_num, 52) + << "incorrect value for header.seq_num, expected 52, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->rle_list[0], 92) + << "incorrect value for rle_list[0], expected 92, is " + << last_msg_->rle_list[0]; + EXPECT_EQ(last_msg_->rle_list[1], 104) + << "incorrect value for rle_list[1], expected 104, is " + << last_msg_->rle_list[1]; + EXPECT_EQ(last_msg_->rle_list[2], 25) + << "incorrect value for rle_list[2], expected 25, is " + << last_msg_->rle_list[2]; + EXPECT_EQ(last_msg_->rle_list[3], 204) + << "incorrect value for rle_list[3], expected 204, is " + << last_msg_->rle_list[3]; + EXPECT_EQ(last_msg_->rle_list[4], 182) + << "incorrect value for rle_list[4], expected 182, is " + << last_msg_->rle_list[4]; + EXPECT_EQ(last_msg_->rle_list[5], 22) + << "incorrect value for rle_list[5], expected 22, is " + << last_msg_->rle_list[5]; + EXPECT_EQ(last_msg_->rle_list[6], 98) + << "incorrect value for rle_list[6], expected 98, is " + << last_msg_->rle_list[6]; + EXPECT_EQ(last_msg_->rle_list[7], 203) + << "incorrect value for rle_list[7], expected 203, is " + << last_msg_->rle_list[7]; + EXPECT_EQ(last_msg_->rle_list[8], 123) + << "incorrect value for rle_list[8], expected 123, is " + << last_msg_->rle_list[8]; + EXPECT_EQ(last_msg_->rle_list[9], 211) + << "incorrect value for rle_list[9], expected 211, is " + << last_msg_->rle_list[9]; + EXPECT_EQ(last_msg_->rle_list[10], 38) + << "incorrect value for rle_list[10], expected 38, is " + << last_msg_->rle_list[10]; + EXPECT_EQ(last_msg_->rle_list[11], 13) + << "incorrect value for rle_list[11], expected 13, is " + << last_msg_->rle_list[11]; + EXPECT_EQ(last_msg_->rle_list[12], 253) + << "incorrect value for rle_list[12], expected 253, is " + << last_msg_->rle_list[12]; + EXPECT_EQ(last_msg_->rle_list[13], 129) + << "incorrect value for rle_list[13], expected 129, is " + << last_msg_->rle_list[13]; + EXPECT_EQ(last_msg_->rle_list[14], 173) + << "incorrect value for rle_list[14], expected 173, is " + << last_msg_->rle_list[14]; + EXPECT_EQ(last_msg_->rle_list[15], 171) + << "incorrect value for rle_list[15], expected 171, is " + << last_msg_->rle_list[15]; + EXPECT_EQ(last_msg_->rle_list[16], 235) + << "incorrect value for rle_list[16], expected 235, is " + << last_msg_->rle_list[16]; + EXPECT_EQ(last_msg_->rle_list[17], 253) + << "incorrect value for rle_list[17], expected 253, is " + << last_msg_->rle_list[17]; + EXPECT_EQ(last_msg_->rle_list[18], 26) + << "incorrect value for rle_list[18], expected 26, is " + << last_msg_->rle_list[18]; + EXPECT_EQ(last_msg_->rle_list[19], 203) + << "incorrect value for rle_list[19], expected 203, is " + << last_msg_->rle_list[19]; + EXPECT_EQ(last_msg_->rle_list[20], 3) + << "incorrect value for rle_list[20], expected 3, is " + << last_msg_->rle_list[20]; + EXPECT_EQ(last_msg_->rle_list[21], 120) + << "incorrect value for rle_list[21], expected 120, is " + << last_msg_->rle_list[21]; + EXPECT_EQ(last_msg_->rle_list[22], 126) + << "incorrect value for rle_list[22], expected 126, is " + << last_msg_->rle_list[22]; + EXPECT_EQ(last_msg_->rle_list[23], 42) + << "incorrect value for rle_list[23], expected 42, is " + << last_msg_->rle_list[23]; + EXPECT_EQ(last_msg_->rle_list[24], 44) + << "incorrect value for rle_list[24], expected 44, is " + << last_msg_->rle_list[24]; + EXPECT_EQ(last_msg_->rle_list[25], 39) + << "incorrect value for rle_list[25], expected 39, is " + << last_msg_->rle_list[25]; + EXPECT_EQ(last_msg_->rle_list[26], 87) + << "incorrect value for rle_list[26], expected 87, is " + << last_msg_->rle_list[26]; + EXPECT_EQ(last_msg_->rle_list[27], 69) + << "incorrect value for rle_list[27], expected 69, is " + << last_msg_->rle_list[27]; + EXPECT_EQ(last_msg_->rle_list[28], 154) + << "incorrect value for rle_list[28], expected 154, is " + << last_msg_->rle_list[28]; + EXPECT_EQ(last_msg_->rle_list[29], 13) + << "incorrect value for rle_list[29], expected 13, is " + << last_msg_->rle_list[29]; + EXPECT_EQ(last_msg_->rle_list[30], 28) + << "incorrect value for rle_list[30], expected 28, is " + << last_msg_->rle_list[30]; + EXPECT_EQ(last_msg_->rle_list[31], 179) + << "incorrect value for rle_list[31], expected 179, is " + << last_msg_->rle_list[31]; + EXPECT_EQ(last_msg_->rle_list[32], 32) + << "incorrect value for rle_list[32], expected 32, is " + << last_msg_->rle_list[32]; + EXPECT_EQ(last_msg_->rle_list[33], 47) + << "incorrect value for rle_list[33], expected 47, is " + << last_msg_->rle_list[33]; + EXPECT_EQ(last_msg_->rle_list[34], 36) + << "incorrect value for rle_list[34], expected 36, is " + << last_msg_->rle_list[34]; + EXPECT_EQ(last_msg_->rle_list[35], 195) + << "incorrect value for rle_list[35], expected 195, is " + << last_msg_->rle_list[35]; + EXPECT_EQ(last_msg_->rle_list[36], 39) + << "incorrect value for rle_list[36], expected 39, is " + << last_msg_->rle_list[36]; + EXPECT_EQ(last_msg_->rle_list[37], 198) + << "incorrect value for rle_list[37], expected 198, is " + << last_msg_->rle_list[37]; + EXPECT_EQ(last_msg_->rle_list[38], 134) + << "incorrect value for rle_list[38], expected 134, is " + << last_msg_->rle_list[38]; + EXPECT_EQ(last_msg_->rle_list[39], 235) + << "incorrect value for rle_list[39], expected 235, is " + << last_msg_->rle_list[39]; + EXPECT_EQ(last_msg_->rle_list[40], 134) + << "incorrect value for rle_list[40], expected 134, is " + << last_msg_->rle_list[40]; + EXPECT_EQ(last_msg_->rle_list[41], 57) + << "incorrect value for rle_list[41], expected 57, is " + << last_msg_->rle_list[41]; + EXPECT_EQ(last_msg_->rle_list[42], 120) + << "incorrect value for rle_list[42], expected 120, is " + << last_msg_->rle_list[42]; + EXPECT_EQ(last_msg_->rle_list[43], 243) + << "incorrect value for rle_list[43], expected 243, is " + << last_msg_->rle_list[43]; + EXPECT_EQ(last_msg_->rle_list[44], 151) + << "incorrect value for rle_list[44], expected 151, is " + << last_msg_->rle_list[44]; + EXPECT_EQ(last_msg_->rle_list[45], 35) + << "incorrect value for rle_list[45], expected 35, is " + << last_msg_->rle_list[45]; + EXPECT_EQ(last_msg_->rle_list[46], 17) + << "incorrect value for rle_list[46], expected 17, is " + << last_msg_->rle_list[46]; + EXPECT_EQ(last_msg_->rle_list[47], 201) + << "incorrect value for rle_list[47], expected 201, is " + << last_msg_->rle_list[47]; + EXPECT_EQ(last_msg_->rle_list[48], 211) + << "incorrect value for rle_list[48], expected 211, is " + << last_msg_->rle_list[48]; + EXPECT_EQ(last_msg_->rle_list[49], 125) + << "incorrect value for rle_list[49], expected 125, is " + << last_msg_->rle_list[49]; + EXPECT_EQ(last_msg_->rle_list[50], 117) + << "incorrect value for rle_list[50], expected 117, is " + << last_msg_->rle_list[50]; + EXPECT_EQ(last_msg_->rle_list[51], 164) + << "incorrect value for rle_list[51], expected 164, is " + << last_msg_->rle_list[51]; + EXPECT_EQ(last_msg_->rle_list[52], 142) + << "incorrect value for rle_list[52], expected 142, is " + << last_msg_->rle_list[52]; + EXPECT_EQ(last_msg_->rle_list[53], 101) + << "incorrect value for rle_list[53], expected 101, is " + << last_msg_->rle_list[53]; + EXPECT_EQ(last_msg_->rle_list[54], 239) + << "incorrect value for rle_list[54], expected 239, is " + << last_msg_->rle_list[54]; + EXPECT_EQ(last_msg_->rle_list[55], 144) + << "incorrect value for rle_list[55], expected 144, is " + << last_msg_->rle_list[55]; + EXPECT_EQ(last_msg_->rle_list[56], 158) + << "incorrect value for rle_list[56], expected 158, is " + << last_msg_->rle_list[56]; + EXPECT_EQ(last_msg_->rle_list[57], 239) + << "incorrect value for rle_list[57], expected 239, is " + << last_msg_->rle_list[57]; + EXPECT_EQ(last_msg_->rle_list[58], 90) + << "incorrect value for rle_list[58], expected 90, is " + << last_msg_->rle_list[58]; + EXPECT_EQ(last_msg_->rle_list[59], 56) + << "incorrect value for rle_list[59], expected 56, is " + << last_msg_->rle_list[59]; + EXPECT_EQ(last_msg_->rle_list[60], 71) + << "incorrect value for rle_list[60], expected 71, is " + << last_msg_->rle_list[60]; + EXPECT_EQ(last_msg_->rle_list[61], 120) + << "incorrect value for rle_list[61], expected 120, is " + << last_msg_->rle_list[61]; + EXPECT_EQ(last_msg_->rle_list[62], 67) + << "incorrect value for rle_list[62], expected 67, is " + << last_msg_->rle_list[62]; + EXPECT_EQ(last_msg_->rle_list[63], 221) + << "incorrect value for rle_list[63], expected 221, is " + << last_msg_->rle_list[63]; + EXPECT_EQ(last_msg_->rle_list[64], 114) + << "incorrect value for rle_list[64], expected 114, is " + << last_msg_->rle_list[64]; + EXPECT_EQ(last_msg_->rle_list[65], 10) + << "incorrect value for rle_list[65], expected 10, is " + << last_msg_->rle_list[65]; + EXPECT_EQ(last_msg_->rle_list[66], 190) + << "incorrect value for rle_list[66], expected 190, is " + << last_msg_->rle_list[66]; + EXPECT_EQ(last_msg_->rle_list[67], 4) + << "incorrect value for rle_list[67], expected 4, is " + << last_msg_->rle_list[67]; + EXPECT_EQ(last_msg_->rle_list[68], 230) + << "incorrect value for rle_list[68], expected 230, is " + << last_msg_->rle_list[68]; + EXPECT_EQ(last_msg_->rle_list[69], 164) + << "incorrect value for rle_list[69], expected 164, is " + << last_msg_->rle_list[69]; + EXPECT_EQ(last_msg_->rle_list[70], 171) + << "incorrect value for rle_list[70], expected 171, is " + << last_msg_->rle_list[70]; + EXPECT_EQ(last_msg_->rle_list[71], 78) + << "incorrect value for rle_list[71], expected 78, is " + << last_msg_->rle_list[71]; + EXPECT_EQ(last_msg_->rle_list[72], 185) + << "incorrect value for rle_list[72], expected 185, is " + << last_msg_->rle_list[72]; + EXPECT_EQ(last_msg_->rle_list[73], 90) + << "incorrect value for rle_list[73], expected 90, is " + << last_msg_->rle_list[73]; + EXPECT_EQ(last_msg_->rle_list[74], 46) + << "incorrect value for rle_list[74], expected 46, is " + << last_msg_->rle_list[74]; + EXPECT_EQ(last_msg_->rle_list[75], 177) + << "incorrect value for rle_list[75], expected 177, is " + << last_msg_->rle_list[75]; + EXPECT_EQ(last_msg_->rle_list[76], 82) + << "incorrect value for rle_list[76], expected 82, is " + << last_msg_->rle_list[76]; + EXPECT_EQ(last_msg_->rle_list[77], 228) + << "incorrect value for rle_list[77], expected 228, is " + << last_msg_->rle_list[77]; + EXPECT_EQ(last_msg_->rle_list[78], 123) + << "incorrect value for rle_list[78], expected 123, is " + << last_msg_->rle_list[78]; + EXPECT_EQ(last_msg_->rle_list[79], 222) + << "incorrect value for rle_list[79], expected 222, is " + << last_msg_->rle_list[79]; + EXPECT_EQ(last_msg_->rle_list[80], 227) + << "incorrect value for rle_list[80], expected 227, is " + << last_msg_->rle_list[80]; + EXPECT_EQ(last_msg_->rle_list[81], 145) + << "incorrect value for rle_list[81], expected 145, is " + << last_msg_->rle_list[81]; + EXPECT_EQ(last_msg_->rle_list[82], 195) + << "incorrect value for rle_list[82], expected 195, is " + << last_msg_->rle_list[82]; + EXPECT_EQ(last_msg_->rle_list[83], 219) + << "incorrect value for rle_list[83], expected 219, is " + << last_msg_->rle_list[83]; + EXPECT_EQ(last_msg_->rle_list[84], 27) + << "incorrect value for rle_list[84], expected 27, is " + << last_msg_->rle_list[84]; + EXPECT_EQ(last_msg_->rle_list[85], 56) + << "incorrect value for rle_list[85], expected 56, is " + << last_msg_->rle_list[85]; + EXPECT_EQ(last_msg_->rle_list[86], 227) + << "incorrect value for rle_list[86], expected 227, is " + << last_msg_->rle_list[86]; + EXPECT_EQ(last_msg_->rle_list[87], 246) + << "incorrect value for rle_list[87], expected 246, is " + << last_msg_->rle_list[87]; + EXPECT_EQ(last_msg_->rle_list[88], 215) + << "incorrect value for rle_list[88], expected 215, is " + << last_msg_->rle_list[88]; + EXPECT_EQ(last_msg_->rle_list[89], 144) + << "incorrect value for rle_list[89], expected 144, is " + << last_msg_->rle_list[89]; + EXPECT_EQ(last_msg_->rle_list[90], 158) + << "incorrect value for rle_list[90], expected 158, is " + << last_msg_->rle_list[90]; + EXPECT_EQ(last_msg_->rle_list[91], 31) + << "incorrect value for rle_list[91], expected 31, is " + << last_msg_->rle_list[91]; + EXPECT_EQ(last_msg_->rle_list[92], 214) + << "incorrect value for rle_list[92], expected 214, is " + << last_msg_->rle_list[92]; + EXPECT_EQ(last_msg_->rle_list[93], 241) + << "incorrect value for rle_list[93], expected 241, is " + << last_msg_->rle_list[93]; + EXPECT_EQ(last_msg_->rle_list[94], 254) + << "incorrect value for rle_list[94], expected 254, is " + << last_msg_->rle_list[94]; + EXPECT_EQ(last_msg_->rle_list[95], 200) + << "incorrect value for rle_list[95], expected 200, is " + << last_msg_->rle_list[95]; + EXPECT_EQ(last_msg_->rle_list[96], 86) + << "incorrect value for rle_list[96], expected 86, is " + << last_msg_->rle_list[96]; + EXPECT_EQ(last_msg_->rle_list[97], 142) + << "incorrect value for rle_list[97], expected 142, is " + << last_msg_->rle_list[97]; + EXPECT_EQ(last_msg_->rle_list[98], 89) + << "incorrect value for rle_list[98], expected 89, is " + << last_msg_->rle_list[98]; + EXPECT_EQ(last_msg_->rle_list[99], 12) + << "incorrect value for rle_list[99], expected 12, is " + << last_msg_->rle_list[99]; + EXPECT_EQ(last_msg_->rle_list[100], 121) + << "incorrect value for rle_list[100], expected 121, is " + << last_msg_->rle_list[100]; + EXPECT_EQ(last_msg_->rle_list[101], 29) + << "incorrect value for rle_list[101], expected 29, is " + << last_msg_->rle_list[101]; + EXPECT_EQ(last_msg_->rle_list[102], 124) + << "incorrect value for rle_list[102], expected 124, is " + << last_msg_->rle_list[102]; + EXPECT_EQ(last_msg_->rle_list[103], 9) + << "incorrect value for rle_list[103], expected 9, is " + << last_msg_->rle_list[103]; + EXPECT_EQ(last_msg_->rle_list[104], 19) + << "incorrect value for rle_list[104], expected 19, is " + << last_msg_->rle_list[104]; + EXPECT_EQ(last_msg_->rle_list[105], 153) + << "incorrect value for rle_list[105], expected 153, is " + << last_msg_->rle_list[105]; + EXPECT_EQ(last_msg_->rle_list[106], 44) + << "incorrect value for rle_list[106], expected 44, is " + << last_msg_->rle_list[106]; + EXPECT_EQ(last_msg_->rle_list[107], 35) + << "incorrect value for rle_list[107], expected 35, is " + << last_msg_->rle_list[107]; + EXPECT_EQ(last_msg_->rle_list[108], 126) + << "incorrect value for rle_list[108], expected 126, is " + << last_msg_->rle_list[108]; + EXPECT_EQ(last_msg_->rle_list[109], 14) + << "incorrect value for rle_list[109], expected 14, is " + << last_msg_->rle_list[109]; + EXPECT_EQ(last_msg_->rle_list[110], 217) + << "incorrect value for rle_list[110], expected 217, is " + << last_msg_->rle_list[110]; + EXPECT_EQ(last_msg_->rle_list[111], 65) + << "incorrect value for rle_list[111], expected 65, is " + << last_msg_->rle_list[111]; + EXPECT_EQ(last_msg_->rle_list[112], 116) + << "incorrect value for rle_list[112], expected 116, is " + << last_msg_->rle_list[112]; + EXPECT_EQ(last_msg_->rle_list[113], 26) + << "incorrect value for rle_list[113], expected 26, is " + << last_msg_->rle_list[113]; + EXPECT_EQ(last_msg_->rle_list[114], 139) + << "incorrect value for rle_list[114], expected 139, is " + << last_msg_->rle_list[114]; + EXPECT_EQ(last_msg_->rle_list[115], 122) + << "incorrect value for rle_list[115], expected 122, is " + << last_msg_->rle_list[115]; + EXPECT_EQ(last_msg_->rle_list[116], 114) + << "incorrect value for rle_list[116], expected 114, is " + << last_msg_->rle_list[116]; + EXPECT_EQ(last_msg_->rle_list[117], 90) + << "incorrect value for rle_list[117], expected 90, is " + << last_msg_->rle_list[117]; + EXPECT_EQ(last_msg_->rle_list[118], 124) + << "incorrect value for rle_list[118], expected 124, is " + << last_msg_->rle_list[118]; + EXPECT_EQ(last_msg_->rle_list[119], 81) + << "incorrect value for rle_list[119], expected 81, is " + << last_msg_->rle_list[119]; + EXPECT_EQ(last_msg_->rle_list[120], 0) + << "incorrect value for rle_list[120], expected 0, is " + << last_msg_->rle_list[120]; + EXPECT_EQ(last_msg_->rle_list[121], 186) + << "incorrect value for rle_list[121], expected 186, is " + << last_msg_->rle_list[121]; + EXPECT_EQ(last_msg_->rle_list[122], 246) + << "incorrect value for rle_list[122], expected 246, is " + << last_msg_->rle_list[122]; + EXPECT_EQ(last_msg_->rle_list[123], 46) + << "incorrect value for rle_list[123], expected 46, is " + << last_msg_->rle_list[123]; + EXPECT_EQ(last_msg_->rle_list[124], 98) + << "incorrect value for rle_list[124], expected 98, is " + << last_msg_->rle_list[124]; + EXPECT_EQ(last_msg_->rle_list[125], 179) + << "incorrect value for rle_list[125], expected 179, is " + << last_msg_->rle_list[125]; + EXPECT_EQ(last_msg_->rle_list[126], 243) + << "incorrect value for rle_list[126], expected 243, is " + << last_msg_->rle_list[126]; + EXPECT_EQ(last_msg_->rle_list[127], 198) + << "incorrect value for rle_list[127], expected 198, is " + << last_msg_->rle_list[127]; + EXPECT_EQ(last_msg_->rle_list[128], 217) + << "incorrect value for rle_list[128], expected 217, is " + << last_msg_->rle_list[128]; + EXPECT_EQ(last_msg_->rle_list[129], 36) + << "incorrect value for rle_list[129], expected 36, is " + << last_msg_->rle_list[129]; + EXPECT_EQ(last_msg_->rle_list[130], 30) + << "incorrect value for rle_list[130], expected 30, is " + << last_msg_->rle_list[130]; + EXPECT_EQ(last_msg_->rle_list[131], 202) + << "incorrect value for rle_list[131], expected 202, is " + << last_msg_->rle_list[131]; + EXPECT_EQ(last_msg_->rle_list[132], 12) + << "incorrect value for rle_list[132], expected 12, is " + << last_msg_->rle_list[132]; + EXPECT_EQ(last_msg_->rle_list[133], 135) + << "incorrect value for rle_list[133], expected 135, is " + << last_msg_->rle_list[133]; + EXPECT_EQ(last_msg_->rle_list[134], 61) + << "incorrect value for rle_list[134], expected 61, is " + << last_msg_->rle_list[134]; + EXPECT_EQ(last_msg_->rle_list[135], 42) + << "incorrect value for rle_list[135], expected 42, is " + << last_msg_->rle_list[135]; + EXPECT_EQ(last_msg_->rle_list[136], 150) + << "incorrect value for rle_list[136], expected 150, is " + << last_msg_->rle_list[136]; + EXPECT_EQ(last_msg_->rle_list[137], 221) + << "incorrect value for rle_list[137], expected 221, is " + << last_msg_->rle_list[137]; + EXPECT_EQ(last_msg_->rle_list[138], 102) + << "incorrect value for rle_list[138], expected 102, is " + << last_msg_->rle_list[138]; + EXPECT_EQ(last_msg_->rle_list[139], 83) + << "incorrect value for rle_list[139], expected 83, is " + << last_msg_->rle_list[139]; + EXPECT_EQ(last_msg_->rle_list[140], 179) + << "incorrect value for rle_list[140], expected 179, is " + << last_msg_->rle_list[140]; + EXPECT_EQ(last_msg_->rle_list[141], 43) + << "incorrect value for rle_list[141], expected 43, is " + << last_msg_->rle_list[141]; + EXPECT_EQ(last_msg_->rle_list[142], 252) + << "incorrect value for rle_list[142], expected 252, is " + << last_msg_->rle_list[142]; + EXPECT_EQ(last_msg_->rle_list[143], 81) + << "incorrect value for rle_list[143], expected 81, is " + << last_msg_->rle_list[143]; + EXPECT_EQ(last_msg_->rle_list[144], 62) + << "incorrect value for rle_list[144], expected 62, is " + << last_msg_->rle_list[144]; + EXPECT_EQ(last_msg_->rle_list[145], 126) + << "incorrect value for rle_list[145], expected 126, is " + << last_msg_->rle_list[145]; + EXPECT_EQ(last_msg_->rle_list[146], 204) + << "incorrect value for rle_list[146], expected 204, is " + << last_msg_->rle_list[146]; + EXPECT_EQ(last_msg_->rle_list[147], 195) + << "incorrect value for rle_list[147], expected 195, is " + << last_msg_->rle_list[147]; + EXPECT_EQ(last_msg_->rle_list[148], 238) + << "incorrect value for rle_list[148], expected 238, is " + << last_msg_->rle_list[148]; + EXPECT_EQ(last_msg_->rle_list[149], 18) + << "incorrect value for rle_list[149], expected 18, is " + << last_msg_->rle_list[149]; + EXPECT_EQ(last_msg_->rle_list[150], 128) + << "incorrect value for rle_list[150], expected 128, is " + << last_msg_->rle_list[150]; + EXPECT_EQ(last_msg_->rle_list[151], 193) + << "incorrect value for rle_list[151], expected 193, is " + << last_msg_->rle_list[151]; + EXPECT_EQ(last_msg_->rle_list[152], 53) + << "incorrect value for rle_list[152], expected 53, is " + << last_msg_->rle_list[152]; + EXPECT_EQ(last_msg_->rle_list[153], 94) + << "incorrect value for rle_list[153], expected 94, is " + << last_msg_->rle_list[153]; + EXPECT_EQ(last_msg_->rle_list[154], 99) + << "incorrect value for rle_list[154], expected 99, is " + << last_msg_->rle_list[154]; + EXPECT_EQ(last_msg_->rle_list[155], 63) + << "incorrect value for rle_list[155], expected 63, is " + << last_msg_->rle_list[155]; + EXPECT_EQ(last_msg_->rle_list[156], 182) + << "incorrect value for rle_list[156], expected 182, is " + << last_msg_->rle_list[156]; + EXPECT_EQ(last_msg_->rle_list[157], 2) + << "incorrect value for rle_list[157], expected 2, is " + << last_msg_->rle_list[157]; + EXPECT_EQ(last_msg_->rle_list[158], 186) + << "incorrect value for rle_list[158], expected 186, is " + << last_msg_->rle_list[158]; + EXPECT_EQ(last_msg_->rle_list[159], 220) + << "incorrect value for rle_list[159], expected 220, is " + << last_msg_->rle_list[159]; + EXPECT_EQ(last_msg_->rle_list[160], 77) + << "incorrect value for rle_list[160], expected 77, is " + << last_msg_->rle_list[160]; + EXPECT_EQ(last_msg_->rle_list[161], 186) + << "incorrect value for rle_list[161], expected 186, is " + << last_msg_->rle_list[161]; + EXPECT_EQ(last_msg_->rle_list[162], 224) + << "incorrect value for rle_list[162], expected 224, is " + << last_msg_->rle_list[162]; + EXPECT_EQ(last_msg_->rle_list[163], 220) + << "incorrect value for rle_list[163], expected 220, is " + << last_msg_->rle_list[163]; + EXPECT_EQ(last_msg_->rle_list[164], 13) + << "incorrect value for rle_list[164], expected 13, is " + << last_msg_->rle_list[164]; + EXPECT_EQ(last_msg_->rle_list[165], 212) + << "incorrect value for rle_list[165], expected 212, is " + << last_msg_->rle_list[165]; + EXPECT_EQ(last_msg_->rle_list[166], 182) + << "incorrect value for rle_list[166], expected 182, is " + << last_msg_->rle_list[166]; + EXPECT_EQ(last_msg_->rle_list[167], 88) + << "incorrect value for rle_list[167], expected 88, is " + << last_msg_->rle_list[167]; + EXPECT_EQ(last_msg_->rle_list[168], 15) + << "incorrect value for rle_list[168], expected 15, is " + << last_msg_->rle_list[168]; + EXPECT_EQ(last_msg_->rle_list[169], 151) + << "incorrect value for rle_list[169], expected 151, is " + << last_msg_->rle_list[169]; + EXPECT_EQ(last_msg_->rle_list[170], 5) + << "incorrect value for rle_list[170], expected 5, is " + << last_msg_->rle_list[170]; + EXPECT_EQ(last_msg_->rle_list[171], 93) + << "incorrect value for rle_list[171], expected 93, is " + << last_msg_->rle_list[171]; + EXPECT_EQ(last_msg_->rle_list[172], 251) + << "incorrect value for rle_list[172], expected 251, is " + << last_msg_->rle_list[172]; + EXPECT_EQ(last_msg_->rle_list[173], 164) + << "incorrect value for rle_list[173], expected 164, is " + << last_msg_->rle_list[173]; + EXPECT_EQ(last_msg_->rle_list[174], 18) + << "incorrect value for rle_list[174], expected 18, is " + << last_msg_->rle_list[174]; + EXPECT_EQ(last_msg_->rle_list[175], 228) + << "incorrect value for rle_list[175], expected 228, is " + << last_msg_->rle_list[175]; + EXPECT_EQ(last_msg_->rle_list[176], 168) + << "incorrect value for rle_list[176], expected 168, is " + << last_msg_->rle_list[176]; + EXPECT_EQ(last_msg_->rle_list[177], 226) + << "incorrect value for rle_list[177], expected 226, is " + << last_msg_->rle_list[177]; + EXPECT_EQ(last_msg_->rle_list[178], 195) + << "incorrect value for rle_list[178], expected 195, is " + << last_msg_->rle_list[178]; + EXPECT_EQ(last_msg_->rle_list[179], 44) + << "incorrect value for rle_list[179], expected 44, is " + << last_msg_->rle_list[179]; + EXPECT_EQ(last_msg_->rle_list[180], 170) + << "incorrect value for rle_list[180], expected 170, is " + << last_msg_->rle_list[180]; + EXPECT_EQ(last_msg_->rle_list[181], 145) + << "incorrect value for rle_list[181], expected 145, is " + << last_msg_->rle_list[181]; + EXPECT_EQ(last_msg_->rle_list[182], 36) + << "incorrect value for rle_list[182], expected 36, is " + << last_msg_->rle_list[182]; + EXPECT_EQ(last_msg_->rle_list[183], 58) + << "incorrect value for rle_list[183], expected 58, is " + << last_msg_->rle_list[183]; + EXPECT_EQ(last_msg_->rle_list[184], 96) + << "incorrect value for rle_list[184], expected 96, is " + << last_msg_->rle_list[184]; + EXPECT_EQ(last_msg_->rle_list[185], 107) + << "incorrect value for rle_list[185], expected 107, is " + << last_msg_->rle_list[185]; + EXPECT_EQ(last_msg_->rle_list[186], 144) + << "incorrect value for rle_list[186], expected 144, is " + << last_msg_->rle_list[186]; + EXPECT_EQ(last_msg_->rle_list[187], 11) + << "incorrect value for rle_list[187], expected 11, is " + << last_msg_->rle_list[187]; + EXPECT_EQ(last_msg_->rle_list[188], 228) + << "incorrect value for rle_list[188], expected 228, is " + << last_msg_->rle_list[188]; + EXPECT_EQ(last_msg_->rle_list[189], 12) + << "incorrect value for rle_list[189], expected 12, is " + << last_msg_->rle_list[189]; + EXPECT_EQ(last_msg_->rle_list[190], 163) + << "incorrect value for rle_list[190], expected 163, is " + << last_msg_->rle_list[190]; + EXPECT_EQ(last_msg_->rle_list[191], 238) + << "incorrect value for rle_list[191], expected 238, is " + << last_msg_->rle_list[191]; + EXPECT_EQ(last_msg_->rle_list[192], 247) + << "incorrect value for rle_list[192], expected 247, is " + << last_msg_->rle_list[192]; + EXPECT_EQ(last_msg_->rle_list[193], 159) + << "incorrect value for rle_list[193], expected 159, is " + << last_msg_->rle_list[193]; + EXPECT_EQ(last_msg_->rle_list[194], 189) + << "incorrect value for rle_list[194], expected 189, is " + << last_msg_->rle_list[194]; + EXPECT_EQ(last_msg_->rle_list[195], 1) + << "incorrect value for rle_list[195], expected 1, is " + << last_msg_->rle_list[195]; + EXPECT_EQ(last_msg_->rle_list[196], 115) + << "incorrect value for rle_list[196], expected 115, is " + << last_msg_->rle_list[196]; + EXPECT_EQ(last_msg_->rle_list[197], 65) + << "incorrect value for rle_list[197], expected 65, is " + << last_msg_->rle_list[197]; + EXPECT_EQ(last_msg_->rle_list[198], 202) + << "incorrect value for rle_list[198], expected 202, is " + << last_msg_->rle_list[198]; + EXPECT_EQ(last_msg_->rle_list[199], 121) + << "incorrect value for rle_list[199], expected 121, is " + << last_msg_->rle_list[199]; + EXPECT_EQ(last_msg_->rle_list[200], 47) + << "incorrect value for rle_list[200], expected 47, is " + << last_msg_->rle_list[200]; + EXPECT_EQ(last_msg_->rle_list[201], 193) + << "incorrect value for rle_list[201], expected 193, is " + << last_msg_->rle_list[201]; + EXPECT_EQ(last_msg_->rle_list[202], 11) + << "incorrect value for rle_list[202], expected 11, is " + << last_msg_->rle_list[202]; + EXPECT_EQ(last_msg_->rle_list[203], 96) + << "incorrect value for rle_list[203], expected 96, is " + << last_msg_->rle_list[203]; + EXPECT_EQ(last_msg_->rle_list[204], 93) + << "incorrect value for rle_list[204], expected 93, is " + << last_msg_->rle_list[204]; + EXPECT_EQ(last_msg_->rle_list[205], 72) + << "incorrect value for rle_list[205], expected 72, is " + << last_msg_->rle_list[205]; + EXPECT_EQ(last_msg_->rle_list[206], 81) + << "incorrect value for rle_list[206], expected 81, is " + << last_msg_->rle_list[206]; + EXPECT_EQ(last_msg_->rle_list[207], 207) + << "incorrect value for rle_list[207], expected 207, is " + << last_msg_->rle_list[207]; + EXPECT_EQ(last_msg_->rle_list[208], 121) + << "incorrect value for rle_list[208], expected 121, is " + << last_msg_->rle_list[208]; + EXPECT_EQ(last_msg_->rle_list[209], 19) + << "incorrect value for rle_list[209], expected 19, is " + << last_msg_->rle_list[209]; + EXPECT_EQ(last_msg_->rle_list[210], 151) + << "incorrect value for rle_list[210], expected 151, is " + << last_msg_->rle_list[210]; + EXPECT_EQ(last_msg_->rle_list[211], 136) + << "incorrect value for rle_list[211], expected 136, is " + << last_msg_->rle_list[211]; + EXPECT_EQ(last_msg_->rle_list[212], 233) + << "incorrect value for rle_list[212], expected 233, is " + << last_msg_->rle_list[212]; + EXPECT_EQ(last_msg_->rle_list[213], 51) + << "incorrect value for rle_list[213], expected 51, is " + << last_msg_->rle_list[213]; + EXPECT_EQ(last_msg_->rle_list[214], 133) + << "incorrect value for rle_list[214], expected 133, is " + << last_msg_->rle_list[214]; + EXPECT_EQ(last_msg_->rle_list[215], 195) + << "incorrect value for rle_list[215], expected 195, is " + << last_msg_->rle_list[215]; + EXPECT_EQ(last_msg_->rle_list[216], 77) + << "incorrect value for rle_list[216], expected 77, is " + << last_msg_->rle_list[216]; + EXPECT_EQ(last_msg_->rle_list[217], 44) + << "incorrect value for rle_list[217], expected 44, is " + << last_msg_->rle_list[217]; + EXPECT_EQ(last_msg_->rle_list[218], 147) + << "incorrect value for rle_list[218], expected 147, is " + << last_msg_->rle_list[218]; + EXPECT_EQ(last_msg_->rle_list[219], 206) + << "incorrect value for rle_list[219], expected 206, is " + << last_msg_->rle_list[219]; + EXPECT_EQ(last_msg_->rle_list[220], 120) + << "incorrect value for rle_list[220], expected 120, is " + << last_msg_->rle_list[220]; + EXPECT_EQ(last_msg_->rle_list[221], 252) + << "incorrect value for rle_list[221], expected 252, is " + << last_msg_->rle_list[221]; + EXPECT_EQ(last_msg_->rle_list[222], 77) + << "incorrect value for rle_list[222], expected 77, is " + << last_msg_->rle_list[222]; + EXPECT_EQ(last_msg_->rle_list[223], 212) + << "incorrect value for rle_list[223], expected 212, is " + << last_msg_->rle_list[223]; + EXPECT_EQ(last_msg_->rle_list[224], 68) + << "incorrect value for rle_list[224], expected 68, is " + << last_msg_->rle_list[224]; + EXPECT_EQ(last_msg_->rle_list[225], 60) + << "incorrect value for rle_list[225], expected 60, is " + << last_msg_->rle_list[225]; + EXPECT_EQ(last_msg_->rle_list[226], 206) + << "incorrect value for rle_list[226], expected 206, is " + << last_msg_->rle_list[226]; + EXPECT_EQ(last_msg_->rle_list[227], 106) + << "incorrect value for rle_list[227], expected 106, is " + << last_msg_->rle_list[227]; + EXPECT_EQ(last_msg_->rle_list[228], 207) + << "incorrect value for rle_list[228], expected 207, is " + << last_msg_->rle_list[228]; + EXPECT_EQ(last_msg_->rle_list[229], 243) + << "incorrect value for rle_list[229], expected 243, is " + << last_msg_->rle_list[229]; + EXPECT_EQ(last_msg_->rle_list[230], 158) + << "incorrect value for rle_list[230], expected 158, is " + << last_msg_->rle_list[230]; + EXPECT_EQ(last_msg_->rle_list[231], 94) + << "incorrect value for rle_list[231], expected 94, is " + << last_msg_->rle_list[231]; + EXPECT_EQ(last_msg_->rle_list[232], 6) + << "incorrect value for rle_list[232], expected 6, is " + << last_msg_->rle_list[232]; + EXPECT_EQ(last_msg_->rle_list[233], 3) + << "incorrect value for rle_list[233], expected 3, is " + << last_msg_->rle_list[233]; + EXPECT_EQ(last_msg_->rle_list[234], 205) + << "incorrect value for rle_list[234], expected 205, is " + << last_msg_->rle_list[234]; + EXPECT_EQ(last_msg_->rle_list[235], 92) + << "incorrect value for rle_list[235], expected 92, is " + << last_msg_->rle_list[235]; + EXPECT_EQ(last_msg_->rle_list[236], 84) + << "incorrect value for rle_list[236], expected 84, is " + << last_msg_->rle_list[236]; + EXPECT_EQ(last_msg_->rle_list[237], 2) + << "incorrect value for rle_list[237], expected 2, is " + << last_msg_->rle_list[237]; + EXPECT_EQ(last_msg_->rle_list[238], 220) + << "incorrect value for rle_list[238], expected 220, is " + << last_msg_->rle_list[238]; + EXPECT_EQ(last_msg_->rle_list[239], 50) + << "incorrect value for rle_list[239], expected 50, is " + << last_msg_->rle_list[239]; + EXPECT_EQ(last_msg_->rle_list[240], 61) + << "incorrect value for rle_list[240], expected 61, is " + << last_msg_->rle_list[240]; + EXPECT_EQ(last_msg_->rle_list[241], 38) + << "incorrect value for rle_list[241], expected 38, is " + << last_msg_->rle_list[241]; + EXPECT_EQ(last_msg_->rle_list[242], 141) + << "incorrect value for rle_list[242], expected 141, is " + << last_msg_->rle_list[242]; + EXPECT_EQ(last_msg_->rle_list[243], 117) + << "incorrect value for rle_list[243], expected 117, is " + << last_msg_->rle_list[243]; + EXPECT_EQ(last_msg_->rle_list[244], 108) + << "incorrect value for rle_list[244], expected 108, is " + << last_msg_->rle_list[244]; + EXPECT_EQ(last_msg_->rle_list[245], 101) + << "incorrect value for rle_list[245], expected 101, is " + << last_msg_->rle_list[245]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc new file mode 100644 index 0000000000..73a257363e --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrection.cc @@ -0,0 +1,1183 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_gridded_correction_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_gridded_correction_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrection0, Test) { + uint8_t encoded_frame[] = { + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, 174, + 229, 151, 189, 204, 196, 105, 170, 120, 149, 169, 37, 244, 78, 72, 140, + 101, 2, 173, 88, 70, 180, 54, 152, 115, 78, 201, 161, 23, 135, 152, + 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, 230, 69, 172, 191, + 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, 52, 166, 166, 120, 57, + 221, 12, 3, 156, 70, 156, 35, 127, 8, 127, 58, 128, 55, 115, 80, + 157, 122, 153, 124, 27, 128, 98, 103, 204, 75, 238, 128, 226, 148, 248, + 61, 216, 208, 149, 167, 224, 40, 144, 186, 157, 227, 72, 240, 100, 35, + 12, 212, 7, 59, 176, 81, 86, 27, 24, 155, 67, 43, 132, 45, 203, + 44, 6, 112, 183, 231, 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, + 23, 62, 227, 240, 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, + 176, 201, 202, 91, 105, 115, 146, 59, 110, 44, 109, 128, 183, 185, 67, + 31, 165, 92, 79, 189, 180, 94, 7, 162, 121, 156, 210, 47, 7, 7, + 205, 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, 219, + 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, 247, + 64, 189, 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, 45, 251, + 239, 115, 88, 218, 10, 209, 120, 65, 175, 131, 194, 41, 174, 137, 17, + 68, 28, 253, 42, 178, 35, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_gridded_correction_t *test_msg = + (msg_ssr_gridded_correction_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.iod_atmo = 170; + test_msg->header.num_msgs = 48535; + test_msg->header.seq_num = 50380; + test_msg->header.tile_id = 12951; + test_msg->header.tile_set_id = 3605; + test_msg->header.time.tow = 2535294328; + test_msg->header.time.wn = 58798; + test_msg->header.tropo_quality_indicator = 120; + test_msg->header.update_interval = 105; + test_msg->index = 43413; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[0].residual = -21246; + test_msg->stec_residuals[0].stddev = 88; + test_msg->stec_residuals[0].sv_id.constellation = 101; + test_msg->stec_residuals[0].sv_id.satId = 140; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[1].residual = -26570; + test_msg->stec_residuals[1].stddev = 115; + test_msg->stec_residuals[1].sv_id.constellation = 180; + test_msg->stec_residuals[1].sv_id.satId = 70; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[2].residual = 6049; + test_msg->stec_residuals[2].stddev = 135; + test_msg->stec_residuals[2].sv_id.constellation = 201; + test_msg->stec_residuals[2].sv_id.satId = 78; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[3].residual = 19261; + test_msg->stec_residuals[3].stddev = 178; + test_msg->stec_residuals[3].sv_id.constellation = 98; + test_msg->stec_residuals[3].sv_id.satId = 152; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[4].residual = 14226; + test_msg->stec_residuals[4].stddev = 58; + test_msg->stec_residuals[4].sv_id.constellation = 229; + test_msg->stec_residuals[4].sv_id.satId = 120; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[5].residual = 17894; + test_msg->stec_residuals[5].stddev = 172; + test_msg->stec_residuals[5].sv_id.constellation = 234; + test_msg->stec_residuals[5].sv_id.satId = 169; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[6].residual = 22930; + test_msg->stec_residuals[6].stddev = 150; + test_msg->stec_residuals[6].sv_id.constellation = 127; + test_msg->stec_residuals[6].sv_id.satId = 191; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[7].residual = 10721; + test_msg->stec_residuals[7].stddev = 17; + test_msg->stec_residuals[7].sv_id.constellation = 111; + test_msg->stec_residuals[7].sv_id.satId = 91; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[8].residual = -22874; + test_msg->stec_residuals[8].stddev = 120; + test_msg->stec_residuals[8].sv_id.constellation = 52; + test_msg->stec_residuals[8].sv_id.satId = 119; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[9].residual = 780; + test_msg->stec_residuals[9].stddev = 156; + test_msg->stec_residuals[9].sv_id.constellation = 221; + test_msg->stec_residuals[9].sv_id.satId = 57; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[10].residual = 32547; + test_msg->stec_residuals[10].stddev = 8; + test_msg->stec_residuals[10].sv_id.constellation = 156; + test_msg->stec_residuals[10].sv_id.satId = 70; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[11].residual = 14208; + test_msg->stec_residuals[11].stddev = 115; + test_msg->stec_residuals[11].sv_id.constellation = 58; + test_msg->stec_residuals[11].sv_id.satId = 127; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[12].residual = -26246; + test_msg->stec_residuals[12].stddev = 124; + test_msg->stec_residuals[12].sv_id.constellation = 157; + test_msg->stec_residuals[12].sv_id.satId = 80; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[13].residual = 26466; + test_msg->stec_residuals[13].stddev = 204; + test_msg->stec_residuals[13].sv_id.constellation = 128; + test_msg->stec_residuals[13].sv_id.satId = 27; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[14].residual = -7552; + test_msg->stec_residuals[14].stddev = 148; + test_msg->stec_residuals[14].sv_id.constellation = 238; + test_msg->stec_residuals[14].sv_id.satId = 75; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[15].residual = -12072; + test_msg->stec_residuals[15].stddev = 149; + test_msg->stec_residuals[15].sv_id.constellation = 61; + test_msg->stec_residuals[15].sv_id.satId = 248; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[16].residual = -28632; + test_msg->stec_residuals[16].stddev = 186; + test_msg->stec_residuals[16].sv_id.constellation = 224; + test_msg->stec_residuals[16].sv_id.satId = 167; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[17].residual = -4024; + test_msg->stec_residuals[17].stddev = 100; + test_msg->stec_residuals[17].sv_id.constellation = 227; + test_msg->stec_residuals[17].sv_id.satId = 157; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[18].residual = 2004; + test_msg->stec_residuals[18].stddev = 59; + test_msg->stec_residuals[18].sv_id.constellation = 12; + test_msg->stec_residuals[18].sv_id.satId = 35; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[19].residual = 6998; + test_msg->stec_residuals[19].stddev = 24; + test_msg->stec_residuals[19].sv_id.constellation = 81; + test_msg->stec_residuals[19].sv_id.satId = 176; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[20].residual = -31701; + test_msg->stec_residuals[20].stddev = 45; + test_msg->stec_residuals[20].sv_id.constellation = 67; + test_msg->stec_residuals[20].sv_id.satId = 155; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[21].residual = 28678; + test_msg->stec_residuals[21].stddev = 183; + test_msg->stec_residuals[21].sv_id.constellation = 44; + test_msg->stec_residuals[21].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[22].residual = -15793; + test_msg->stec_residuals[22].stddev = 253; + test_msg->stec_residuals[22].sv_id.constellation = 176; + test_msg->stec_residuals[22].sv_id.satId = 231; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[23].residual = -7589; + test_msg->stec_residuals[23].stddev = 116; + test_msg->stec_residuals[23].sv_id.constellation = 103; + test_msg->stec_residuals[23].sv_id.satId = 247; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[24].residual = -7362; + test_msg->stec_residuals[24].stddev = 240; + test_msg->stec_residuals[24].sv_id.constellation = 23; + test_msg->stec_residuals[24].sv_id.satId = 148; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[25].residual = 4813; + test_msg->stec_residuals[25].stddev = 242; + test_msg->stec_residuals[25].sv_id.constellation = 219; + test_msg->stec_residuals[25].sv_id.satId = 29; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[26].residual = 20295; + test_msg->stec_residuals[26].stddev = 37; + test_msg->stec_residuals[26].sv_id.constellation = 72; + test_msg->stec_residuals[26].sv_id.satId = 207; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[27].residual = -13623; + test_msg->stec_residuals[27].stddev = 91; + test_msg->stec_residuals[27].sv_id.constellation = 176; + test_msg->stec_residuals[27].sv_id.satId = 42; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[28].residual = 15250; + test_msg->stec_residuals[28].stddev = 110; + test_msg->stec_residuals[28].sv_id.constellation = 115; + test_msg->stec_residuals[28].sv_id.satId = 105; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[29].residual = -18560; + test_msg->stec_residuals[29].stddev = 185; + test_msg->stec_residuals[29].sv_id.constellation = 109; + test_msg->stec_residuals[29].sv_id.satId = 44; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[30].residual = 23717; + test_msg->stec_residuals[30].stddev = 79; + test_msg->stec_residuals[30].sv_id.constellation = 31; + test_msg->stec_residuals[30].sv_id.satId = 67; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[31].residual = 1886; + test_msg->stec_residuals[31].stddev = 162; + test_msg->stec_residuals[31].sv_id.constellation = 180; + test_msg->stec_residuals[31].sv_id.satId = 189; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[32].residual = 12242; + test_msg->stec_residuals[32].stddev = 7; + test_msg->stec_residuals[32].sv_id.constellation = 156; + test_msg->stec_residuals[32].sv_id.satId = 121; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[33].residual = 10670; + test_msg->stec_residuals[33].stddev = 241; + test_msg->stec_residuals[33].sv_id.constellation = 205; + test_msg->stec_residuals[33].sv_id.satId = 7; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[34].residual = 25899; + test_msg->stec_residuals[34].stddev = 186; + test_msg->stec_residuals[34].sv_id.constellation = 210; + test_msg->stec_residuals[34].sv_id.satId = 129; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[35].residual = -2078; + test_msg->stec_residuals[35].stddev = 187; + test_msg->stec_residuals[35].sv_id.constellation = 195; + test_msg->stec_residuals[35].sv_id.satId = 208; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[36].residual = -16264; + test_msg->stec_residuals[36].stddev = 102; + test_msg->stec_residuals[36].sv_id.constellation = 160; + test_msg->stec_residuals[36].sv_id.satId = 219; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[37].residual = -21002; + test_msg->stec_residuals[37].stddev = 94; + test_msg->stec_residuals[37].sv_id.constellation = 42; + test_msg->stec_residuals[37].sv_id.satId = 166; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[38].residual = 7902; + test_msg->stec_residuals[38].stddev = 35; + test_msg->stec_residuals[38].sv_id.constellation = 156; + test_msg->stec_residuals[38].sv_id.satId = 102; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[39].residual = -30275; + test_msg->stec_residuals[39].stddev = 204; + test_msg->stec_residuals[39].sv_id.constellation = 64; + test_msg->stec_residuals[39].sv_id.satId = 247; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[40].residual = -8633; + test_msg->stec_residuals[40].stddev = 222; + test_msg->stec_residuals[40].sv_id.constellation = 32; + test_msg->stec_residuals[40].sv_id.satId = 220; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[41].residual = 6403; + test_msg->stec_residuals[41].stddev = 45; + test_msg->stec_residuals[41].sv_id.constellation = 246; + test_msg->stec_residuals[41].sv_id.satId = 201; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[42].residual = 22643; + test_msg->stec_residuals[42].stddev = 218; + test_msg->stec_residuals[42].sv_id.constellation = 239; + test_msg->stec_residuals[42].sv_id.satId = 251; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[43].residual = 16760; + test_msg->stec_residuals[43].stddev = 175; + test_msg->stec_residuals[43].sv_id.constellation = 209; + test_msg->stec_residuals[43].sv_id.satId = 10; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[44].residual = -20951; + test_msg->stec_residuals[44].stddev = 137; + test_msg->stec_residuals[44].sv_id.constellation = 194; + test_msg->stec_residuals[44].sv_id.satId = 131; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[45].residual = -740; + test_msg->stec_residuals[45].stddev = 42; + test_msg->stec_residuals[45].sv_id.constellation = 68; + test_msg->stec_residuals[45].sv_id.satId = 17; + test_msg->tropo_delay_correction.hydro = -3035; + test_msg->tropo_delay_correction.stddev = 72; + test_msg->tropo_delay_correction.wet = 78; + + EXPECT_EQ(send_message(0x5fc, 63940, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 63940); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.iod_atmo, 170) + << "incorrect value for header.iod_atmo, expected 170, is " + << last_msg_->header.iod_atmo; + EXPECT_EQ(last_msg_->header.num_msgs, 48535) + << "incorrect value for header.num_msgs, expected 48535, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.seq_num, 50380) + << "incorrect value for header.seq_num, expected 50380, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->header.tile_id, 12951) + << "incorrect value for header.tile_id, expected 12951, is " + << last_msg_->header.tile_id; + EXPECT_EQ(last_msg_->header.tile_set_id, 3605) + << "incorrect value for header.tile_set_id, expected 3605, is " + << last_msg_->header.tile_set_id; + EXPECT_EQ(last_msg_->header.time.tow, 2535294328) + << "incorrect value for header.time.tow, expected 2535294328, is " + << last_msg_->header.time.tow; + EXPECT_EQ(last_msg_->header.time.wn, 58798) + << "incorrect value for header.time.wn, expected 58798, is " + << last_msg_->header.time.wn; + EXPECT_EQ(last_msg_->header.tropo_quality_indicator, 120) + << "incorrect value for header.tropo_quality_indicator, expected 120, is " + << last_msg_->header.tropo_quality_indicator; + EXPECT_EQ(last_msg_->header.update_interval, 105) + << "incorrect value for header.update_interval, expected 105, is " + << last_msg_->header.update_interval; + EXPECT_EQ(last_msg_->index, 43413) + << "incorrect value for index, expected 43413, is " << last_msg_->index; + EXPECT_EQ(last_msg_->stec_residuals[0].residual, -21246) + << "incorrect value for stec_residuals[0].residual, expected -21246, is " + << last_msg_->stec_residuals[0].residual; + EXPECT_EQ(last_msg_->stec_residuals[0].stddev, 88) + << "incorrect value for stec_residuals[0].stddev, expected 88, is " + << last_msg_->stec_residuals[0].stddev; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.constellation, 101) + << "incorrect value for stec_residuals[0].sv_id.constellation, expected " + "101, is " + << last_msg_->stec_residuals[0].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.satId, 140) + << "incorrect value for stec_residuals[0].sv_id.satId, expected 140, is " + << last_msg_->stec_residuals[0].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[1].residual, -26570) + << "incorrect value for stec_residuals[1].residual, expected -26570, is " + << last_msg_->stec_residuals[1].residual; + EXPECT_EQ(last_msg_->stec_residuals[1].stddev, 115) + << "incorrect value for stec_residuals[1].stddev, expected 115, is " + << last_msg_->stec_residuals[1].stddev; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.constellation, 180) + << "incorrect value for stec_residuals[1].sv_id.constellation, expected " + "180, is " + << last_msg_->stec_residuals[1].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.satId, 70) + << "incorrect value for stec_residuals[1].sv_id.satId, expected 70, is " + << last_msg_->stec_residuals[1].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[2].residual, 6049) + << "incorrect value for stec_residuals[2].residual, expected 6049, is " + << last_msg_->stec_residuals[2].residual; + EXPECT_EQ(last_msg_->stec_residuals[2].stddev, 135) + << "incorrect value for stec_residuals[2].stddev, expected 135, is " + << last_msg_->stec_residuals[2].stddev; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.constellation, 201) + << "incorrect value for stec_residuals[2].sv_id.constellation, expected " + "201, is " + << last_msg_->stec_residuals[2].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.satId, 78) + << "incorrect value for stec_residuals[2].sv_id.satId, expected 78, is " + << last_msg_->stec_residuals[2].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[3].residual, 19261) + << "incorrect value for stec_residuals[3].residual, expected 19261, is " + << last_msg_->stec_residuals[3].residual; + EXPECT_EQ(last_msg_->stec_residuals[3].stddev, 178) + << "incorrect value for stec_residuals[3].stddev, expected 178, is " + << last_msg_->stec_residuals[3].stddev; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.constellation, 98) + << "incorrect value for stec_residuals[3].sv_id.constellation, expected " + "98, is " + << last_msg_->stec_residuals[3].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.satId, 152) + << "incorrect value for stec_residuals[3].sv_id.satId, expected 152, is " + << last_msg_->stec_residuals[3].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[4].residual, 14226) + << "incorrect value for stec_residuals[4].residual, expected 14226, is " + << last_msg_->stec_residuals[4].residual; + EXPECT_EQ(last_msg_->stec_residuals[4].stddev, 58) + << "incorrect value for stec_residuals[4].stddev, expected 58, is " + << last_msg_->stec_residuals[4].stddev; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.constellation, 229) + << "incorrect value for stec_residuals[4].sv_id.constellation, expected " + "229, is " + << last_msg_->stec_residuals[4].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.satId, 120) + << "incorrect value for stec_residuals[4].sv_id.satId, expected 120, is " + << last_msg_->stec_residuals[4].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[5].residual, 17894) + << "incorrect value for stec_residuals[5].residual, expected 17894, is " + << last_msg_->stec_residuals[5].residual; + EXPECT_EQ(last_msg_->stec_residuals[5].stddev, 172) + << "incorrect value for stec_residuals[5].stddev, expected 172, is " + << last_msg_->stec_residuals[5].stddev; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.constellation, 234) + << "incorrect value for stec_residuals[5].sv_id.constellation, expected " + "234, is " + << last_msg_->stec_residuals[5].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.satId, 169) + << "incorrect value for stec_residuals[5].sv_id.satId, expected 169, is " + << last_msg_->stec_residuals[5].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[6].residual, 22930) + << "incorrect value for stec_residuals[6].residual, expected 22930, is " + << last_msg_->stec_residuals[6].residual; + EXPECT_EQ(last_msg_->stec_residuals[6].stddev, 150) + << "incorrect value for stec_residuals[6].stddev, expected 150, is " + << last_msg_->stec_residuals[6].stddev; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.constellation, 127) + << "incorrect value for stec_residuals[6].sv_id.constellation, expected " + "127, is " + << last_msg_->stec_residuals[6].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.satId, 191) + << "incorrect value for stec_residuals[6].sv_id.satId, expected 191, is " + << last_msg_->stec_residuals[6].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[7].residual, 10721) + << "incorrect value for stec_residuals[7].residual, expected 10721, is " + << last_msg_->stec_residuals[7].residual; + EXPECT_EQ(last_msg_->stec_residuals[7].stddev, 17) + << "incorrect value for stec_residuals[7].stddev, expected 17, is " + << last_msg_->stec_residuals[7].stddev; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.constellation, 111) + << "incorrect value for stec_residuals[7].sv_id.constellation, expected " + "111, is " + << last_msg_->stec_residuals[7].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.satId, 91) + << "incorrect value for stec_residuals[7].sv_id.satId, expected 91, is " + << last_msg_->stec_residuals[7].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[8].residual, -22874) + << "incorrect value for stec_residuals[8].residual, expected -22874, is " + << last_msg_->stec_residuals[8].residual; + EXPECT_EQ(last_msg_->stec_residuals[8].stddev, 120) + << "incorrect value for stec_residuals[8].stddev, expected 120, is " + << last_msg_->stec_residuals[8].stddev; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.constellation, 52) + << "incorrect value for stec_residuals[8].sv_id.constellation, expected " + "52, is " + << last_msg_->stec_residuals[8].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.satId, 119) + << "incorrect value for stec_residuals[8].sv_id.satId, expected 119, is " + << last_msg_->stec_residuals[8].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[9].residual, 780) + << "incorrect value for stec_residuals[9].residual, expected 780, is " + << last_msg_->stec_residuals[9].residual; + EXPECT_EQ(last_msg_->stec_residuals[9].stddev, 156) + << "incorrect value for stec_residuals[9].stddev, expected 156, is " + << last_msg_->stec_residuals[9].stddev; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.constellation, 221) + << "incorrect value for stec_residuals[9].sv_id.constellation, expected " + "221, is " + << last_msg_->stec_residuals[9].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.satId, 57) + << "incorrect value for stec_residuals[9].sv_id.satId, expected 57, is " + << last_msg_->stec_residuals[9].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[10].residual, 32547) + << "incorrect value for stec_residuals[10].residual, expected 32547, is " + << last_msg_->stec_residuals[10].residual; + EXPECT_EQ(last_msg_->stec_residuals[10].stddev, 8) + << "incorrect value for stec_residuals[10].stddev, expected 8, is " + << last_msg_->stec_residuals[10].stddev; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.constellation, 156) + << "incorrect value for stec_residuals[10].sv_id.constellation, expected " + "156, is " + << last_msg_->stec_residuals[10].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.satId, 70) + << "incorrect value for stec_residuals[10].sv_id.satId, expected 70, is " + << last_msg_->stec_residuals[10].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[11].residual, 14208) + << "incorrect value for stec_residuals[11].residual, expected 14208, is " + << last_msg_->stec_residuals[11].residual; + EXPECT_EQ(last_msg_->stec_residuals[11].stddev, 115) + << "incorrect value for stec_residuals[11].stddev, expected 115, is " + << last_msg_->stec_residuals[11].stddev; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.constellation, 58) + << "incorrect value for stec_residuals[11].sv_id.constellation, expected " + "58, is " + << last_msg_->stec_residuals[11].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.satId, 127) + << "incorrect value for stec_residuals[11].sv_id.satId, expected 127, is " + << last_msg_->stec_residuals[11].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[12].residual, -26246) + << "incorrect value for stec_residuals[12].residual, expected -26246, is " + << last_msg_->stec_residuals[12].residual; + EXPECT_EQ(last_msg_->stec_residuals[12].stddev, 124) + << "incorrect value for stec_residuals[12].stddev, expected 124, is " + << last_msg_->stec_residuals[12].stddev; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.constellation, 157) + << "incorrect value for stec_residuals[12].sv_id.constellation, expected " + "157, is " + << last_msg_->stec_residuals[12].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.satId, 80) + << "incorrect value for stec_residuals[12].sv_id.satId, expected 80, is " + << last_msg_->stec_residuals[12].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[13].residual, 26466) + << "incorrect value for stec_residuals[13].residual, expected 26466, is " + << last_msg_->stec_residuals[13].residual; + EXPECT_EQ(last_msg_->stec_residuals[13].stddev, 204) + << "incorrect value for stec_residuals[13].stddev, expected 204, is " + << last_msg_->stec_residuals[13].stddev; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.constellation, 128) + << "incorrect value for stec_residuals[13].sv_id.constellation, expected " + "128, is " + << last_msg_->stec_residuals[13].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.satId, 27) + << "incorrect value for stec_residuals[13].sv_id.satId, expected 27, is " + << last_msg_->stec_residuals[13].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[14].residual, -7552) + << "incorrect value for stec_residuals[14].residual, expected -7552, is " + << last_msg_->stec_residuals[14].residual; + EXPECT_EQ(last_msg_->stec_residuals[14].stddev, 148) + << "incorrect value for stec_residuals[14].stddev, expected 148, is " + << last_msg_->stec_residuals[14].stddev; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.constellation, 238) + << "incorrect value for stec_residuals[14].sv_id.constellation, expected " + "238, is " + << last_msg_->stec_residuals[14].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.satId, 75) + << "incorrect value for stec_residuals[14].sv_id.satId, expected 75, is " + << last_msg_->stec_residuals[14].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[15].residual, -12072) + << "incorrect value for stec_residuals[15].residual, expected -12072, is " + << last_msg_->stec_residuals[15].residual; + EXPECT_EQ(last_msg_->stec_residuals[15].stddev, 149) + << "incorrect value for stec_residuals[15].stddev, expected 149, is " + << last_msg_->stec_residuals[15].stddev; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.constellation, 61) + << "incorrect value for stec_residuals[15].sv_id.constellation, expected " + "61, is " + << last_msg_->stec_residuals[15].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.satId, 248) + << "incorrect value for stec_residuals[15].sv_id.satId, expected 248, is " + << last_msg_->stec_residuals[15].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[16].residual, -28632) + << "incorrect value for stec_residuals[16].residual, expected -28632, is " + << last_msg_->stec_residuals[16].residual; + EXPECT_EQ(last_msg_->stec_residuals[16].stddev, 186) + << "incorrect value for stec_residuals[16].stddev, expected 186, is " + << last_msg_->stec_residuals[16].stddev; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.constellation, 224) + << "incorrect value for stec_residuals[16].sv_id.constellation, expected " + "224, is " + << last_msg_->stec_residuals[16].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.satId, 167) + << "incorrect value for stec_residuals[16].sv_id.satId, expected 167, is " + << last_msg_->stec_residuals[16].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[17].residual, -4024) + << "incorrect value for stec_residuals[17].residual, expected -4024, is " + << last_msg_->stec_residuals[17].residual; + EXPECT_EQ(last_msg_->stec_residuals[17].stddev, 100) + << "incorrect value for stec_residuals[17].stddev, expected 100, is " + << last_msg_->stec_residuals[17].stddev; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.constellation, 227) + << "incorrect value for stec_residuals[17].sv_id.constellation, expected " + "227, is " + << last_msg_->stec_residuals[17].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.satId, 157) + << "incorrect value for stec_residuals[17].sv_id.satId, expected 157, is " + << last_msg_->stec_residuals[17].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[18].residual, 2004) + << "incorrect value for stec_residuals[18].residual, expected 2004, is " + << last_msg_->stec_residuals[18].residual; + EXPECT_EQ(last_msg_->stec_residuals[18].stddev, 59) + << "incorrect value for stec_residuals[18].stddev, expected 59, is " + << last_msg_->stec_residuals[18].stddev; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.constellation, 12) + << "incorrect value for stec_residuals[18].sv_id.constellation, expected " + "12, is " + << last_msg_->stec_residuals[18].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.satId, 35) + << "incorrect value for stec_residuals[18].sv_id.satId, expected 35, is " + << last_msg_->stec_residuals[18].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[19].residual, 6998) + << "incorrect value for stec_residuals[19].residual, expected 6998, is " + << last_msg_->stec_residuals[19].residual; + EXPECT_EQ(last_msg_->stec_residuals[19].stddev, 24) + << "incorrect value for stec_residuals[19].stddev, expected 24, is " + << last_msg_->stec_residuals[19].stddev; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.constellation, 81) + << "incorrect value for stec_residuals[19].sv_id.constellation, expected " + "81, is " + << last_msg_->stec_residuals[19].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.satId, 176) + << "incorrect value for stec_residuals[19].sv_id.satId, expected 176, is " + << last_msg_->stec_residuals[19].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[20].residual, -31701) + << "incorrect value for stec_residuals[20].residual, expected -31701, is " + << last_msg_->stec_residuals[20].residual; + EXPECT_EQ(last_msg_->stec_residuals[20].stddev, 45) + << "incorrect value for stec_residuals[20].stddev, expected 45, is " + << last_msg_->stec_residuals[20].stddev; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.constellation, 67) + << "incorrect value for stec_residuals[20].sv_id.constellation, expected " + "67, is " + << last_msg_->stec_residuals[20].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.satId, 155) + << "incorrect value for stec_residuals[20].sv_id.satId, expected 155, is " + << last_msg_->stec_residuals[20].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[21].residual, 28678) + << "incorrect value for stec_residuals[21].residual, expected 28678, is " + << last_msg_->stec_residuals[21].residual; + EXPECT_EQ(last_msg_->stec_residuals[21].stddev, 183) + << "incorrect value for stec_residuals[21].stddev, expected 183, is " + << last_msg_->stec_residuals[21].stddev; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.constellation, 44) + << "incorrect value for stec_residuals[21].sv_id.constellation, expected " + "44, is " + << last_msg_->stec_residuals[21].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.satId, 203) + << "incorrect value for stec_residuals[21].sv_id.satId, expected 203, is " + << last_msg_->stec_residuals[21].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[22].residual, -15793) + << "incorrect value for stec_residuals[22].residual, expected -15793, is " + << last_msg_->stec_residuals[22].residual; + EXPECT_EQ(last_msg_->stec_residuals[22].stddev, 253) + << "incorrect value for stec_residuals[22].stddev, expected 253, is " + << last_msg_->stec_residuals[22].stddev; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.constellation, 176) + << "incorrect value for stec_residuals[22].sv_id.constellation, expected " + "176, is " + << last_msg_->stec_residuals[22].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.satId, 231) + << "incorrect value for stec_residuals[22].sv_id.satId, expected 231, is " + << last_msg_->stec_residuals[22].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[23].residual, -7589) + << "incorrect value for stec_residuals[23].residual, expected -7589, is " + << last_msg_->stec_residuals[23].residual; + EXPECT_EQ(last_msg_->stec_residuals[23].stddev, 116) + << "incorrect value for stec_residuals[23].stddev, expected 116, is " + << last_msg_->stec_residuals[23].stddev; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.constellation, 103) + << "incorrect value for stec_residuals[23].sv_id.constellation, expected " + "103, is " + << last_msg_->stec_residuals[23].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.satId, 247) + << "incorrect value for stec_residuals[23].sv_id.satId, expected 247, is " + << last_msg_->stec_residuals[23].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[24].residual, -7362) + << "incorrect value for stec_residuals[24].residual, expected -7362, is " + << last_msg_->stec_residuals[24].residual; + EXPECT_EQ(last_msg_->stec_residuals[24].stddev, 240) + << "incorrect value for stec_residuals[24].stddev, expected 240, is " + << last_msg_->stec_residuals[24].stddev; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.constellation, 23) + << "incorrect value for stec_residuals[24].sv_id.constellation, expected " + "23, is " + << last_msg_->stec_residuals[24].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.satId, 148) + << "incorrect value for stec_residuals[24].sv_id.satId, expected 148, is " + << last_msg_->stec_residuals[24].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[25].residual, 4813) + << "incorrect value for stec_residuals[25].residual, expected 4813, is " + << last_msg_->stec_residuals[25].residual; + EXPECT_EQ(last_msg_->stec_residuals[25].stddev, 242) + << "incorrect value for stec_residuals[25].stddev, expected 242, is " + << last_msg_->stec_residuals[25].stddev; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.constellation, 219) + << "incorrect value for stec_residuals[25].sv_id.constellation, expected " + "219, is " + << last_msg_->stec_residuals[25].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.satId, 29) + << "incorrect value for stec_residuals[25].sv_id.satId, expected 29, is " + << last_msg_->stec_residuals[25].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[26].residual, 20295) + << "incorrect value for stec_residuals[26].residual, expected 20295, is " + << last_msg_->stec_residuals[26].residual; + EXPECT_EQ(last_msg_->stec_residuals[26].stddev, 37) + << "incorrect value for stec_residuals[26].stddev, expected 37, is " + << last_msg_->stec_residuals[26].stddev; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.constellation, 72) + << "incorrect value for stec_residuals[26].sv_id.constellation, expected " + "72, is " + << last_msg_->stec_residuals[26].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.satId, 207) + << "incorrect value for stec_residuals[26].sv_id.satId, expected 207, is " + << last_msg_->stec_residuals[26].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[27].residual, -13623) + << "incorrect value for stec_residuals[27].residual, expected -13623, is " + << last_msg_->stec_residuals[27].residual; + EXPECT_EQ(last_msg_->stec_residuals[27].stddev, 91) + << "incorrect value for stec_residuals[27].stddev, expected 91, is " + << last_msg_->stec_residuals[27].stddev; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.constellation, 176) + << "incorrect value for stec_residuals[27].sv_id.constellation, expected " + "176, is " + << last_msg_->stec_residuals[27].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.satId, 42) + << "incorrect value for stec_residuals[27].sv_id.satId, expected 42, is " + << last_msg_->stec_residuals[27].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[28].residual, 15250) + << "incorrect value for stec_residuals[28].residual, expected 15250, is " + << last_msg_->stec_residuals[28].residual; + EXPECT_EQ(last_msg_->stec_residuals[28].stddev, 110) + << "incorrect value for stec_residuals[28].stddev, expected 110, is " + << last_msg_->stec_residuals[28].stddev; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.constellation, 115) + << "incorrect value for stec_residuals[28].sv_id.constellation, expected " + "115, is " + << last_msg_->stec_residuals[28].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.satId, 105) + << "incorrect value for stec_residuals[28].sv_id.satId, expected 105, is " + << last_msg_->stec_residuals[28].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[29].residual, -18560) + << "incorrect value for stec_residuals[29].residual, expected -18560, is " + << last_msg_->stec_residuals[29].residual; + EXPECT_EQ(last_msg_->stec_residuals[29].stddev, 185) + << "incorrect value for stec_residuals[29].stddev, expected 185, is " + << last_msg_->stec_residuals[29].stddev; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.constellation, 109) + << "incorrect value for stec_residuals[29].sv_id.constellation, expected " + "109, is " + << last_msg_->stec_residuals[29].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.satId, 44) + << "incorrect value for stec_residuals[29].sv_id.satId, expected 44, is " + << last_msg_->stec_residuals[29].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[30].residual, 23717) + << "incorrect value for stec_residuals[30].residual, expected 23717, is " + << last_msg_->stec_residuals[30].residual; + EXPECT_EQ(last_msg_->stec_residuals[30].stddev, 79) + << "incorrect value for stec_residuals[30].stddev, expected 79, is " + << last_msg_->stec_residuals[30].stddev; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.constellation, 31) + << "incorrect value for stec_residuals[30].sv_id.constellation, expected " + "31, is " + << last_msg_->stec_residuals[30].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.satId, 67) + << "incorrect value for stec_residuals[30].sv_id.satId, expected 67, is " + << last_msg_->stec_residuals[30].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[31].residual, 1886) + << "incorrect value for stec_residuals[31].residual, expected 1886, is " + << last_msg_->stec_residuals[31].residual; + EXPECT_EQ(last_msg_->stec_residuals[31].stddev, 162) + << "incorrect value for stec_residuals[31].stddev, expected 162, is " + << last_msg_->stec_residuals[31].stddev; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.constellation, 180) + << "incorrect value for stec_residuals[31].sv_id.constellation, expected " + "180, is " + << last_msg_->stec_residuals[31].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.satId, 189) + << "incorrect value for stec_residuals[31].sv_id.satId, expected 189, is " + << last_msg_->stec_residuals[31].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[32].residual, 12242) + << "incorrect value for stec_residuals[32].residual, expected 12242, is " + << last_msg_->stec_residuals[32].residual; + EXPECT_EQ(last_msg_->stec_residuals[32].stddev, 7) + << "incorrect value for stec_residuals[32].stddev, expected 7, is " + << last_msg_->stec_residuals[32].stddev; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.constellation, 156) + << "incorrect value for stec_residuals[32].sv_id.constellation, expected " + "156, is " + << last_msg_->stec_residuals[32].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.satId, 121) + << "incorrect value for stec_residuals[32].sv_id.satId, expected 121, is " + << last_msg_->stec_residuals[32].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[33].residual, 10670) + << "incorrect value for stec_residuals[33].residual, expected 10670, is " + << last_msg_->stec_residuals[33].residual; + EXPECT_EQ(last_msg_->stec_residuals[33].stddev, 241) + << "incorrect value for stec_residuals[33].stddev, expected 241, is " + << last_msg_->stec_residuals[33].stddev; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.constellation, 205) + << "incorrect value for stec_residuals[33].sv_id.constellation, expected " + "205, is " + << last_msg_->stec_residuals[33].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.satId, 7) + << "incorrect value for stec_residuals[33].sv_id.satId, expected 7, is " + << last_msg_->stec_residuals[33].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[34].residual, 25899) + << "incorrect value for stec_residuals[34].residual, expected 25899, is " + << last_msg_->stec_residuals[34].residual; + EXPECT_EQ(last_msg_->stec_residuals[34].stddev, 186) + << "incorrect value for stec_residuals[34].stddev, expected 186, is " + << last_msg_->stec_residuals[34].stddev; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.constellation, 210) + << "incorrect value for stec_residuals[34].sv_id.constellation, expected " + "210, is " + << last_msg_->stec_residuals[34].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.satId, 129) + << "incorrect value for stec_residuals[34].sv_id.satId, expected 129, is " + << last_msg_->stec_residuals[34].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[35].residual, -2078) + << "incorrect value for stec_residuals[35].residual, expected -2078, is " + << last_msg_->stec_residuals[35].residual; + EXPECT_EQ(last_msg_->stec_residuals[35].stddev, 187) + << "incorrect value for stec_residuals[35].stddev, expected 187, is " + << last_msg_->stec_residuals[35].stddev; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.constellation, 195) + << "incorrect value for stec_residuals[35].sv_id.constellation, expected " + "195, is " + << last_msg_->stec_residuals[35].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.satId, 208) + << "incorrect value for stec_residuals[35].sv_id.satId, expected 208, is " + << last_msg_->stec_residuals[35].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[36].residual, -16264) + << "incorrect value for stec_residuals[36].residual, expected -16264, is " + << last_msg_->stec_residuals[36].residual; + EXPECT_EQ(last_msg_->stec_residuals[36].stddev, 102) + << "incorrect value for stec_residuals[36].stddev, expected 102, is " + << last_msg_->stec_residuals[36].stddev; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.constellation, 160) + << "incorrect value for stec_residuals[36].sv_id.constellation, expected " + "160, is " + << last_msg_->stec_residuals[36].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.satId, 219) + << "incorrect value for stec_residuals[36].sv_id.satId, expected 219, is " + << last_msg_->stec_residuals[36].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[37].residual, -21002) + << "incorrect value for stec_residuals[37].residual, expected -21002, is " + << last_msg_->stec_residuals[37].residual; + EXPECT_EQ(last_msg_->stec_residuals[37].stddev, 94) + << "incorrect value for stec_residuals[37].stddev, expected 94, is " + << last_msg_->stec_residuals[37].stddev; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.constellation, 42) + << "incorrect value for stec_residuals[37].sv_id.constellation, expected " + "42, is " + << last_msg_->stec_residuals[37].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.satId, 166) + << "incorrect value for stec_residuals[37].sv_id.satId, expected 166, is " + << last_msg_->stec_residuals[37].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[38].residual, 7902) + << "incorrect value for stec_residuals[38].residual, expected 7902, is " + << last_msg_->stec_residuals[38].residual; + EXPECT_EQ(last_msg_->stec_residuals[38].stddev, 35) + << "incorrect value for stec_residuals[38].stddev, expected 35, is " + << last_msg_->stec_residuals[38].stddev; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.constellation, 156) + << "incorrect value for stec_residuals[38].sv_id.constellation, expected " + "156, is " + << last_msg_->stec_residuals[38].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.satId, 102) + << "incorrect value for stec_residuals[38].sv_id.satId, expected 102, is " + << last_msg_->stec_residuals[38].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[39].residual, -30275) + << "incorrect value for stec_residuals[39].residual, expected -30275, is " + << last_msg_->stec_residuals[39].residual; + EXPECT_EQ(last_msg_->stec_residuals[39].stddev, 204) + << "incorrect value for stec_residuals[39].stddev, expected 204, is " + << last_msg_->stec_residuals[39].stddev; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.constellation, 64) + << "incorrect value for stec_residuals[39].sv_id.constellation, expected " + "64, is " + << last_msg_->stec_residuals[39].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.satId, 247) + << "incorrect value for stec_residuals[39].sv_id.satId, expected 247, is " + << last_msg_->stec_residuals[39].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[40].residual, -8633) + << "incorrect value for stec_residuals[40].residual, expected -8633, is " + << last_msg_->stec_residuals[40].residual; + EXPECT_EQ(last_msg_->stec_residuals[40].stddev, 222) + << "incorrect value for stec_residuals[40].stddev, expected 222, is " + << last_msg_->stec_residuals[40].stddev; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.constellation, 32) + << "incorrect value for stec_residuals[40].sv_id.constellation, expected " + "32, is " + << last_msg_->stec_residuals[40].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.satId, 220) + << "incorrect value for stec_residuals[40].sv_id.satId, expected 220, is " + << last_msg_->stec_residuals[40].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[41].residual, 6403) + << "incorrect value for stec_residuals[41].residual, expected 6403, is " + << last_msg_->stec_residuals[41].residual; + EXPECT_EQ(last_msg_->stec_residuals[41].stddev, 45) + << "incorrect value for stec_residuals[41].stddev, expected 45, is " + << last_msg_->stec_residuals[41].stddev; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.constellation, 246) + << "incorrect value for stec_residuals[41].sv_id.constellation, expected " + "246, is " + << last_msg_->stec_residuals[41].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.satId, 201) + << "incorrect value for stec_residuals[41].sv_id.satId, expected 201, is " + << last_msg_->stec_residuals[41].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[42].residual, 22643) + << "incorrect value for stec_residuals[42].residual, expected 22643, is " + << last_msg_->stec_residuals[42].residual; + EXPECT_EQ(last_msg_->stec_residuals[42].stddev, 218) + << "incorrect value for stec_residuals[42].stddev, expected 218, is " + << last_msg_->stec_residuals[42].stddev; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.constellation, 239) + << "incorrect value for stec_residuals[42].sv_id.constellation, expected " + "239, is " + << last_msg_->stec_residuals[42].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.satId, 251) + << "incorrect value for stec_residuals[42].sv_id.satId, expected 251, is " + << last_msg_->stec_residuals[42].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[43].residual, 16760) + << "incorrect value for stec_residuals[43].residual, expected 16760, is " + << last_msg_->stec_residuals[43].residual; + EXPECT_EQ(last_msg_->stec_residuals[43].stddev, 175) + << "incorrect value for stec_residuals[43].stddev, expected 175, is " + << last_msg_->stec_residuals[43].stddev; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.constellation, 209) + << "incorrect value for stec_residuals[43].sv_id.constellation, expected " + "209, is " + << last_msg_->stec_residuals[43].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.satId, 10) + << "incorrect value for stec_residuals[43].sv_id.satId, expected 10, is " + << last_msg_->stec_residuals[43].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[44].residual, -20951) + << "incorrect value for stec_residuals[44].residual, expected -20951, is " + << last_msg_->stec_residuals[44].residual; + EXPECT_EQ(last_msg_->stec_residuals[44].stddev, 137) + << "incorrect value for stec_residuals[44].stddev, expected 137, is " + << last_msg_->stec_residuals[44].stddev; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.constellation, 194) + << "incorrect value for stec_residuals[44].sv_id.constellation, expected " + "194, is " + << last_msg_->stec_residuals[44].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.satId, 131) + << "incorrect value for stec_residuals[44].sv_id.satId, expected 131, is " + << last_msg_->stec_residuals[44].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[45].residual, -740) + << "incorrect value for stec_residuals[45].residual, expected -740, is " + << last_msg_->stec_residuals[45].residual; + EXPECT_EQ(last_msg_->stec_residuals[45].stddev, 42) + << "incorrect value for stec_residuals[45].stddev, expected 42, is " + << last_msg_->stec_residuals[45].stddev; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.constellation, 68) + << "incorrect value for stec_residuals[45].sv_id.constellation, expected " + "68, is " + << last_msg_->stec_residuals[45].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.satId, 17) + << "incorrect value for stec_residuals[45].sv_id.satId, expected 17, is " + << last_msg_->stec_residuals[45].sv_id.satId; + EXPECT_EQ(last_msg_->tropo_delay_correction.hydro, -3035) + << "incorrect value for tropo_delay_correction.hydro, expected -3035, is " + << last_msg_->tropo_delay_correction.hydro; + EXPECT_EQ(last_msg_->tropo_delay_correction.stddev, 72) + << "incorrect value for tropo_delay_correction.stddev, expected 72, is " + << last_msg_->tropo_delay_correction.stddev; + EXPECT_EQ(last_msg_->tropo_delay_correction.wet, 78) + << "incorrect value for tropo_delay_correction.wet, expected 78, is " + << last_msg_->tropo_delay_correction.wet; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc new file mode 100644 index 0000000000..8b61459328 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA.cc @@ -0,0 +1,1197 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_gridded_correction_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_gridded_correction_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, 104, + 252, 133, 245, 28, 95, 100, 147, 41, 33, 92, 87, 25, 142, 151, 74, + 151, 95, 94, 7, 146, 237, 45, 167, 86, 42, 116, 224, 169, 234, 220, + 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, 206, 151, 158, 22, + 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, 110, 38, 65, 104, 244, + 19, 238, 227, 88, 169, 164, 146, 63, 37, 183, 85, 71, 235, 168, 114, + 211, 105, 221, 156, 60, 18, 230, 2, 142, 172, 16, 39, 33, 126, 106, + 99, 188, 234, 41, 162, 197, 138, 227, 80, 12, 54, 67, 238, 5, 93, + 1, 207, 129, 13, 46, 115, 49, 58, 185, 127, 156, 200, 96, 217, 202, + 15, 245, 55, 198, 81, 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, + 96, 138, 55, 214, 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, + 245, 112, 168, 210, 10, 5, 117, 1, 57, 108, 248, 212, 145, 119, 226, + 165, 5, 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, 215, 12, 137, + 16, 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, 31, + 48, 132, 72, 229, 126, 186, 68, 76, 133, 21, 0, 180, 139, 164, 148, + 119, 149, 214, 120, 177, 201, 80, 80, 105, 10, 136, 118, 77, 46, 233, + 233, 227, 11, 158, 103, 167, 216, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_gridded_correction_dep_a_t *test_msg = + (msg_ssr_gridded_correction_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.iod_atmo = 245; + test_msg->header.num_msgs = 37695; + test_msg->header.seq_num = 64616; + test_msg->header.time.tow = 892131748; + test_msg->header.time.wn = 23906; + test_msg->header.tropo_quality_indicator = 28; + test_msg->header.update_interval = 133; + test_msg->index = 25695; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[0].residual = -26738; + test_msg->stec_residuals[0].stddev = 74; + test_msg->stec_residuals[0].sv_id.constellation = 25; + test_msg->stec_residuals[0].sv_id.satId = 87; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[1].residual = 1886; + test_msg->stec_residuals[1].stddev = 146; + test_msg->stec_residuals[1].sv_id.constellation = 95; + test_msg->stec_residuals[1].sv_id.satId = 151; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[2].residual = 22183; + test_msg->stec_residuals[2].stddev = 42; + test_msg->stec_residuals[2].sv_id.constellation = 45; + test_msg->stec_residuals[2].sv_id.satId = 237; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[3].residual = -5463; + test_msg->stec_residuals[3].stddev = 220; + test_msg->stec_residuals[3].sv_id.constellation = 224; + test_msg->stec_residuals[3].sv_id.satId = 116; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[4].residual = 3346; + test_msg->stec_residuals[4].stddev = 178; + test_msg->stec_residuals[4].sv_id.constellation = 176; + test_msg->stec_residuals[4].sv_id.satId = 23; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[5].residual = 28320; + test_msg->stec_residuals[5].stddev = 15; + test_msg->stec_residuals[5].sv_id.constellation = 160; + test_msg->stec_residuals[5].sv_id.satId = 79; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[6].residual = -24937; + test_msg->stec_residuals[6].stddev = 22; + test_msg->stec_residuals[6].sv_id.constellation = 206; + test_msg->stec_residuals[6].sv_id.satId = 53; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[7].residual = -21968; + test_msg->stec_residuals[7].stddev = 82; + test_msg->stec_residuals[7].sv_id.constellation = 184; + test_msg->stec_residuals[7].sv_id.satId = 117; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[8].residual = 17786; + test_msg->stec_residuals[8].stddev = 180; + test_msg->stec_residuals[8].sv_id.constellation = 53; + test_msg->stec_residuals[8].sv_id.satId = 40; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[9].residual = 26689; + test_msg->stec_residuals[9].stddev = 244; + test_msg->stec_residuals[9].sv_id.constellation = 38; + test_msg->stec_residuals[9].sv_id.satId = 110; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[10].residual = 22755; + test_msg->stec_residuals[10].stddev = 169; + test_msg->stec_residuals[10].sv_id.constellation = 238; + test_msg->stec_residuals[10].sv_id.satId = 19; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[11].residual = 9535; + test_msg->stec_residuals[11].stddev = 183; + test_msg->stec_residuals[11].sv_id.constellation = 146; + test_msg->stec_residuals[11].sv_id.satId = 164; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[12].residual = -22293; + test_msg->stec_residuals[12].stddev = 114; + test_msg->stec_residuals[12].sv_id.constellation = 71; + test_msg->stec_residuals[12].sv_id.satId = 85; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[13].residual = -25379; + test_msg->stec_residuals[13].stddev = 60; + test_msg->stec_residuals[13].sv_id.constellation = 105; + test_msg->stec_residuals[13].sv_id.satId = 211; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[14].residual = -29182; + test_msg->stec_residuals[14].stddev = 172; + test_msg->stec_residuals[14].sv_id.constellation = 230; + test_msg->stec_residuals[14].sv_id.satId = 18; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[15].residual = 32289; + test_msg->stec_residuals[15].stddev = 106; + test_msg->stec_residuals[15].sv_id.constellation = 39; + test_msg->stec_residuals[15].sv_id.satId = 16; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[16].residual = 10730; + test_msg->stec_residuals[16].stddev = 162; + test_msg->stec_residuals[16].sv_id.constellation = 188; + test_msg->stec_residuals[16].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[17].residual = 20707; + test_msg->stec_residuals[17].stddev = 12; + test_msg->stec_residuals[17].sv_id.constellation = 138; + test_msg->stec_residuals[17].sv_id.satId = 197; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[18].residual = 1518; + test_msg->stec_residuals[18].stddev = 93; + test_msg->stec_residuals[18].sv_id.constellation = 67; + test_msg->stec_residuals[18].sv_id.satId = 54; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[19].residual = 3457; + test_msg->stec_residuals[19].stddev = 46; + test_msg->stec_residuals[19].sv_id.constellation = 207; + test_msg->stec_residuals[19].sv_id.satId = 1; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[20].residual = -18118; + test_msg->stec_residuals[20].stddev = 127; + test_msg->stec_residuals[20].sv_id.constellation = 49; + test_msg->stec_residuals[20].sv_id.satId = 115; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[21].residual = -9888; + test_msg->stec_residuals[21].stddev = 202; + test_msg->stec_residuals[21].sv_id.constellation = 200; + test_msg->stec_residuals[21].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[22].residual = -14793; + test_msg->stec_residuals[22].stddev = 81; + test_msg->stec_residuals[22].sv_id.constellation = 245; + test_msg->stec_residuals[22].sv_id.satId = 15; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[23].residual = 18758; + test_msg->stec_residuals[23].stddev = 82; + test_msg->stec_residuals[23].sv_id.constellation = 132; + test_msg->stec_residuals[23].sv_id.satId = 218; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[24].residual = 3839; + test_msg->stec_residuals[24].stddev = 134; + test_msg->stec_residuals[24].sv_id.constellation = 26; + test_msg->stec_residuals[24].sv_id.satId = 147; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[25].residual = -10697; + test_msg->stec_residuals[25].stddev = 83; + test_msg->stec_residuals[25].sv_id.constellation = 138; + test_msg->stec_residuals[25].sv_id.satId = 96; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[26].residual = 20387; + test_msg->stec_residuals[26].stddev = 173; + test_msg->stec_residuals[26].sv_id.constellation = 170; + test_msg->stec_residuals[26].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[27].residual = -3789; + test_msg->stec_residuals[27].stddev = 107; + test_msg->stec_residuals[27].sv_id.constellation = 115; + test_msg->stec_residuals[27].sv_id.satId = 228; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[28].residual = -11608; + test_msg->stec_residuals[28].stddev = 10; + test_msg->stec_residuals[28].sv_id.constellation = 112; + test_msg->stec_residuals[28].sv_id.satId = 245; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[29].residual = 14593; + test_msg->stec_residuals[29].stddev = 108; + test_msg->stec_residuals[29].sv_id.constellation = 117; + test_msg->stec_residuals[29].sv_id.satId = 5; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[30].residual = 30609; + test_msg->stec_residuals[30].stddev = 226; + test_msg->stec_residuals[30].sv_id.constellation = 212; + test_msg->stec_residuals[30].sv_id.satId = 248; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[31].residual = -13683; + test_msg->stec_residuals[31].stddev = 106; + test_msg->stec_residuals[31].sv_id.constellation = 5; + test_msg->stec_residuals[31].sv_id.satId = 165; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[32].residual = 15652; + test_msg->stec_residuals[32].stddev = 243; + test_msg->stec_residuals[32].sv_id.constellation = 60; + test_msg->stec_residuals[32].sv_id.satId = 0; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[33].residual = 3287; + test_msg->stec_residuals[33].stddev = 137; + test_msg->stec_residuals[33].sv_id.constellation = 216; + test_msg->stec_residuals[33].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[34].residual = 29687; + test_msg->stec_residuals[34].stddev = 152; + test_msg->stec_residuals[34].sv_id.constellation = 28; + test_msg->stec_residuals[34].sv_id.satId = 16; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[35].residual = -6960; + test_msg->stec_residuals[35].stddev = 203; + test_msg->stec_residuals[35].sv_id.constellation = 119; + test_msg->stec_residuals[35].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[36].residual = -15193; + test_msg->stec_residuals[36].stddev = 32; + test_msg->stec_residuals[36].sv_id.constellation = 34; + test_msg->stec_residuals[36].sv_id.satId = 236; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[37].residual = 25873; + test_msg->stec_residuals[37].stddev = 200; + test_msg->stec_residuals[37].sv_id.constellation = 1; + test_msg->stec_residuals[37].sv_id.satId = 109; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[38].residual = -22403; + test_msg->stec_residuals[38].stddev = 137; + test_msg->stec_residuals[38].sv_id.constellation = 94; + test_msg->stec_residuals[38].sv_id.satId = 25; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[39].residual = 7588; + test_msg->stec_residuals[39].stddev = 31; + test_msg->stec_residuals[39].sv_id.constellation = 4; + test_msg->stec_residuals[39].sv_id.satId = 157; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[40].residual = -6840; + test_msg->stec_residuals[40].stddev = 126; + test_msg->stec_residuals[40].sv_id.constellation = 132; + test_msg->stec_residuals[40].sv_id.satId = 48; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[41].residual = -31412; + test_msg->stec_residuals[41].stddev = 21; + test_msg->stec_residuals[41].sv_id.constellation = 68; + test_msg->stec_residuals[41].sv_id.satId = 186; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[42].residual = -23413; + test_msg->stec_residuals[42].stddev = 148; + test_msg->stec_residuals[42].sv_id.constellation = 180; + test_msg->stec_residuals[42].sv_id.satId = 0; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[43].residual = 30934; + test_msg->stec_residuals[43].stddev = 177; + test_msg->stec_residuals[43].sv_id.constellation = 149; + test_msg->stec_residuals[43].sv_id.satId = 119; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[44].residual = 26960; + test_msg->stec_residuals[44].stddev = 10; + test_msg->stec_residuals[44].sv_id.constellation = 80; + test_msg->stec_residuals[44].sv_id.satId = 201; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[45].residual = 11853; + test_msg->stec_residuals[45].stddev = 233; + test_msg->stec_residuals[45].sv_id.constellation = 118; + test_msg->stec_residuals[45].sv_id.satId = 136; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[46].residual = -25077; + test_msg->stec_residuals[46].stddev = 103; + test_msg->stec_residuals[46].sv_id.constellation = 227; + test_msg->stec_residuals[46].sv_id.satId = 233; + test_msg->tropo_delay_correction.hydro = 10643; + test_msg->tropo_delay_correction.stddev = 92; + test_msg->tropo_delay_correction.wet = 33; + + EXPECT_EQ(send_message(0x5fa, 27244, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 27244); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.iod_atmo, 245) + << "incorrect value for header.iod_atmo, expected 245, is " + << last_msg_->header.iod_atmo; + EXPECT_EQ(last_msg_->header.num_msgs, 37695) + << "incorrect value for header.num_msgs, expected 37695, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.seq_num, 64616) + << "incorrect value for header.seq_num, expected 64616, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->header.time.tow, 892131748) + << "incorrect value for header.time.tow, expected 892131748, is " + << last_msg_->header.time.tow; + EXPECT_EQ(last_msg_->header.time.wn, 23906) + << "incorrect value for header.time.wn, expected 23906, is " + << last_msg_->header.time.wn; + EXPECT_EQ(last_msg_->header.tropo_quality_indicator, 28) + << "incorrect value for header.tropo_quality_indicator, expected 28, is " + << last_msg_->header.tropo_quality_indicator; + EXPECT_EQ(last_msg_->header.update_interval, 133) + << "incorrect value for header.update_interval, expected 133, is " + << last_msg_->header.update_interval; + EXPECT_EQ(last_msg_->index, 25695) + << "incorrect value for index, expected 25695, is " << last_msg_->index; + EXPECT_EQ(last_msg_->stec_residuals[0].residual, -26738) + << "incorrect value for stec_residuals[0].residual, expected -26738, is " + << last_msg_->stec_residuals[0].residual; + EXPECT_EQ(last_msg_->stec_residuals[0].stddev, 74) + << "incorrect value for stec_residuals[0].stddev, expected 74, is " + << last_msg_->stec_residuals[0].stddev; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.constellation, 25) + << "incorrect value for stec_residuals[0].sv_id.constellation, expected " + "25, is " + << last_msg_->stec_residuals[0].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.satId, 87) + << "incorrect value for stec_residuals[0].sv_id.satId, expected 87, is " + << last_msg_->stec_residuals[0].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[1].residual, 1886) + << "incorrect value for stec_residuals[1].residual, expected 1886, is " + << last_msg_->stec_residuals[1].residual; + EXPECT_EQ(last_msg_->stec_residuals[1].stddev, 146) + << "incorrect value for stec_residuals[1].stddev, expected 146, is " + << last_msg_->stec_residuals[1].stddev; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.constellation, 95) + << "incorrect value for stec_residuals[1].sv_id.constellation, expected " + "95, is " + << last_msg_->stec_residuals[1].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.satId, 151) + << "incorrect value for stec_residuals[1].sv_id.satId, expected 151, is " + << last_msg_->stec_residuals[1].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[2].residual, 22183) + << "incorrect value for stec_residuals[2].residual, expected 22183, is " + << last_msg_->stec_residuals[2].residual; + EXPECT_EQ(last_msg_->stec_residuals[2].stddev, 42) + << "incorrect value for stec_residuals[2].stddev, expected 42, is " + << last_msg_->stec_residuals[2].stddev; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.constellation, 45) + << "incorrect value for stec_residuals[2].sv_id.constellation, expected " + "45, is " + << last_msg_->stec_residuals[2].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.satId, 237) + << "incorrect value for stec_residuals[2].sv_id.satId, expected 237, is " + << last_msg_->stec_residuals[2].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[3].residual, -5463) + << "incorrect value for stec_residuals[3].residual, expected -5463, is " + << last_msg_->stec_residuals[3].residual; + EXPECT_EQ(last_msg_->stec_residuals[3].stddev, 220) + << "incorrect value for stec_residuals[3].stddev, expected 220, is " + << last_msg_->stec_residuals[3].stddev; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.constellation, 224) + << "incorrect value for stec_residuals[3].sv_id.constellation, expected " + "224, is " + << last_msg_->stec_residuals[3].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.satId, 116) + << "incorrect value for stec_residuals[3].sv_id.satId, expected 116, is " + << last_msg_->stec_residuals[3].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[4].residual, 3346) + << "incorrect value for stec_residuals[4].residual, expected 3346, is " + << last_msg_->stec_residuals[4].residual; + EXPECT_EQ(last_msg_->stec_residuals[4].stddev, 178) + << "incorrect value for stec_residuals[4].stddev, expected 178, is " + << last_msg_->stec_residuals[4].stddev; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.constellation, 176) + << "incorrect value for stec_residuals[4].sv_id.constellation, expected " + "176, is " + << last_msg_->stec_residuals[4].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.satId, 23) + << "incorrect value for stec_residuals[4].sv_id.satId, expected 23, is " + << last_msg_->stec_residuals[4].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[5].residual, 28320) + << "incorrect value for stec_residuals[5].residual, expected 28320, is " + << last_msg_->stec_residuals[5].residual; + EXPECT_EQ(last_msg_->stec_residuals[5].stddev, 15) + << "incorrect value for stec_residuals[5].stddev, expected 15, is " + << last_msg_->stec_residuals[5].stddev; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.constellation, 160) + << "incorrect value for stec_residuals[5].sv_id.constellation, expected " + "160, is " + << last_msg_->stec_residuals[5].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.satId, 79) + << "incorrect value for stec_residuals[5].sv_id.satId, expected 79, is " + << last_msg_->stec_residuals[5].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[6].residual, -24937) + << "incorrect value for stec_residuals[6].residual, expected -24937, is " + << last_msg_->stec_residuals[6].residual; + EXPECT_EQ(last_msg_->stec_residuals[6].stddev, 22) + << "incorrect value for stec_residuals[6].stddev, expected 22, is " + << last_msg_->stec_residuals[6].stddev; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.constellation, 206) + << "incorrect value for stec_residuals[6].sv_id.constellation, expected " + "206, is " + << last_msg_->stec_residuals[6].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.satId, 53) + << "incorrect value for stec_residuals[6].sv_id.satId, expected 53, is " + << last_msg_->stec_residuals[6].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[7].residual, -21968) + << "incorrect value for stec_residuals[7].residual, expected -21968, is " + << last_msg_->stec_residuals[7].residual; + EXPECT_EQ(last_msg_->stec_residuals[7].stddev, 82) + << "incorrect value for stec_residuals[7].stddev, expected 82, is " + << last_msg_->stec_residuals[7].stddev; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.constellation, 184) + << "incorrect value for stec_residuals[7].sv_id.constellation, expected " + "184, is " + << last_msg_->stec_residuals[7].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.satId, 117) + << "incorrect value for stec_residuals[7].sv_id.satId, expected 117, is " + << last_msg_->stec_residuals[7].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[8].residual, 17786) + << "incorrect value for stec_residuals[8].residual, expected 17786, is " + << last_msg_->stec_residuals[8].residual; + EXPECT_EQ(last_msg_->stec_residuals[8].stddev, 180) + << "incorrect value for stec_residuals[8].stddev, expected 180, is " + << last_msg_->stec_residuals[8].stddev; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.constellation, 53) + << "incorrect value for stec_residuals[8].sv_id.constellation, expected " + "53, is " + << last_msg_->stec_residuals[8].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.satId, 40) + << "incorrect value for stec_residuals[8].sv_id.satId, expected 40, is " + << last_msg_->stec_residuals[8].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[9].residual, 26689) + << "incorrect value for stec_residuals[9].residual, expected 26689, is " + << last_msg_->stec_residuals[9].residual; + EXPECT_EQ(last_msg_->stec_residuals[9].stddev, 244) + << "incorrect value for stec_residuals[9].stddev, expected 244, is " + << last_msg_->stec_residuals[9].stddev; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.constellation, 38) + << "incorrect value for stec_residuals[9].sv_id.constellation, expected " + "38, is " + << last_msg_->stec_residuals[9].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.satId, 110) + << "incorrect value for stec_residuals[9].sv_id.satId, expected 110, is " + << last_msg_->stec_residuals[9].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[10].residual, 22755) + << "incorrect value for stec_residuals[10].residual, expected 22755, is " + << last_msg_->stec_residuals[10].residual; + EXPECT_EQ(last_msg_->stec_residuals[10].stddev, 169) + << "incorrect value for stec_residuals[10].stddev, expected 169, is " + << last_msg_->stec_residuals[10].stddev; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.constellation, 238) + << "incorrect value for stec_residuals[10].sv_id.constellation, expected " + "238, is " + << last_msg_->stec_residuals[10].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.satId, 19) + << "incorrect value for stec_residuals[10].sv_id.satId, expected 19, is " + << last_msg_->stec_residuals[10].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[11].residual, 9535) + << "incorrect value for stec_residuals[11].residual, expected 9535, is " + << last_msg_->stec_residuals[11].residual; + EXPECT_EQ(last_msg_->stec_residuals[11].stddev, 183) + << "incorrect value for stec_residuals[11].stddev, expected 183, is " + << last_msg_->stec_residuals[11].stddev; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.constellation, 146) + << "incorrect value for stec_residuals[11].sv_id.constellation, expected " + "146, is " + << last_msg_->stec_residuals[11].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.satId, 164) + << "incorrect value for stec_residuals[11].sv_id.satId, expected 164, is " + << last_msg_->stec_residuals[11].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[12].residual, -22293) + << "incorrect value for stec_residuals[12].residual, expected -22293, is " + << last_msg_->stec_residuals[12].residual; + EXPECT_EQ(last_msg_->stec_residuals[12].stddev, 114) + << "incorrect value for stec_residuals[12].stddev, expected 114, is " + << last_msg_->stec_residuals[12].stddev; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.constellation, 71) + << "incorrect value for stec_residuals[12].sv_id.constellation, expected " + "71, is " + << last_msg_->stec_residuals[12].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.satId, 85) + << "incorrect value for stec_residuals[12].sv_id.satId, expected 85, is " + << last_msg_->stec_residuals[12].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[13].residual, -25379) + << "incorrect value for stec_residuals[13].residual, expected -25379, is " + << last_msg_->stec_residuals[13].residual; + EXPECT_EQ(last_msg_->stec_residuals[13].stddev, 60) + << "incorrect value for stec_residuals[13].stddev, expected 60, is " + << last_msg_->stec_residuals[13].stddev; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.constellation, 105) + << "incorrect value for stec_residuals[13].sv_id.constellation, expected " + "105, is " + << last_msg_->stec_residuals[13].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.satId, 211) + << "incorrect value for stec_residuals[13].sv_id.satId, expected 211, is " + << last_msg_->stec_residuals[13].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[14].residual, -29182) + << "incorrect value for stec_residuals[14].residual, expected -29182, is " + << last_msg_->stec_residuals[14].residual; + EXPECT_EQ(last_msg_->stec_residuals[14].stddev, 172) + << "incorrect value for stec_residuals[14].stddev, expected 172, is " + << last_msg_->stec_residuals[14].stddev; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.constellation, 230) + << "incorrect value for stec_residuals[14].sv_id.constellation, expected " + "230, is " + << last_msg_->stec_residuals[14].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.satId, 18) + << "incorrect value for stec_residuals[14].sv_id.satId, expected 18, is " + << last_msg_->stec_residuals[14].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[15].residual, 32289) + << "incorrect value for stec_residuals[15].residual, expected 32289, is " + << last_msg_->stec_residuals[15].residual; + EXPECT_EQ(last_msg_->stec_residuals[15].stddev, 106) + << "incorrect value for stec_residuals[15].stddev, expected 106, is " + << last_msg_->stec_residuals[15].stddev; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.constellation, 39) + << "incorrect value for stec_residuals[15].sv_id.constellation, expected " + "39, is " + << last_msg_->stec_residuals[15].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.satId, 16) + << "incorrect value for stec_residuals[15].sv_id.satId, expected 16, is " + << last_msg_->stec_residuals[15].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[16].residual, 10730) + << "incorrect value for stec_residuals[16].residual, expected 10730, is " + << last_msg_->stec_residuals[16].residual; + EXPECT_EQ(last_msg_->stec_residuals[16].stddev, 162) + << "incorrect value for stec_residuals[16].stddev, expected 162, is " + << last_msg_->stec_residuals[16].stddev; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.constellation, 188) + << "incorrect value for stec_residuals[16].sv_id.constellation, expected " + "188, is " + << last_msg_->stec_residuals[16].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.satId, 99) + << "incorrect value for stec_residuals[16].sv_id.satId, expected 99, is " + << last_msg_->stec_residuals[16].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[17].residual, 20707) + << "incorrect value for stec_residuals[17].residual, expected 20707, is " + << last_msg_->stec_residuals[17].residual; + EXPECT_EQ(last_msg_->stec_residuals[17].stddev, 12) + << "incorrect value for stec_residuals[17].stddev, expected 12, is " + << last_msg_->stec_residuals[17].stddev; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.constellation, 138) + << "incorrect value for stec_residuals[17].sv_id.constellation, expected " + "138, is " + << last_msg_->stec_residuals[17].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.satId, 197) + << "incorrect value for stec_residuals[17].sv_id.satId, expected 197, is " + << last_msg_->stec_residuals[17].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[18].residual, 1518) + << "incorrect value for stec_residuals[18].residual, expected 1518, is " + << last_msg_->stec_residuals[18].residual; + EXPECT_EQ(last_msg_->stec_residuals[18].stddev, 93) + << "incorrect value for stec_residuals[18].stddev, expected 93, is " + << last_msg_->stec_residuals[18].stddev; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.constellation, 67) + << "incorrect value for stec_residuals[18].sv_id.constellation, expected " + "67, is " + << last_msg_->stec_residuals[18].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.satId, 54) + << "incorrect value for stec_residuals[18].sv_id.satId, expected 54, is " + << last_msg_->stec_residuals[18].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[19].residual, 3457) + << "incorrect value for stec_residuals[19].residual, expected 3457, is " + << last_msg_->stec_residuals[19].residual; + EXPECT_EQ(last_msg_->stec_residuals[19].stddev, 46) + << "incorrect value for stec_residuals[19].stddev, expected 46, is " + << last_msg_->stec_residuals[19].stddev; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.constellation, 207) + << "incorrect value for stec_residuals[19].sv_id.constellation, expected " + "207, is " + << last_msg_->stec_residuals[19].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.satId, 1) + << "incorrect value for stec_residuals[19].sv_id.satId, expected 1, is " + << last_msg_->stec_residuals[19].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[20].residual, -18118) + << "incorrect value for stec_residuals[20].residual, expected -18118, is " + << last_msg_->stec_residuals[20].residual; + EXPECT_EQ(last_msg_->stec_residuals[20].stddev, 127) + << "incorrect value for stec_residuals[20].stddev, expected 127, is " + << last_msg_->stec_residuals[20].stddev; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.constellation, 49) + << "incorrect value for stec_residuals[20].sv_id.constellation, expected " + "49, is " + << last_msg_->stec_residuals[20].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.satId, 115) + << "incorrect value for stec_residuals[20].sv_id.satId, expected 115, is " + << last_msg_->stec_residuals[20].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[21].residual, -9888) + << "incorrect value for stec_residuals[21].residual, expected -9888, is " + << last_msg_->stec_residuals[21].residual; + EXPECT_EQ(last_msg_->stec_residuals[21].stddev, 202) + << "incorrect value for stec_residuals[21].stddev, expected 202, is " + << last_msg_->stec_residuals[21].stddev; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.constellation, 200) + << "incorrect value for stec_residuals[21].sv_id.constellation, expected " + "200, is " + << last_msg_->stec_residuals[21].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.satId, 156) + << "incorrect value for stec_residuals[21].sv_id.satId, expected 156, is " + << last_msg_->stec_residuals[21].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[22].residual, -14793) + << "incorrect value for stec_residuals[22].residual, expected -14793, is " + << last_msg_->stec_residuals[22].residual; + EXPECT_EQ(last_msg_->stec_residuals[22].stddev, 81) + << "incorrect value for stec_residuals[22].stddev, expected 81, is " + << last_msg_->stec_residuals[22].stddev; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.constellation, 245) + << "incorrect value for stec_residuals[22].sv_id.constellation, expected " + "245, is " + << last_msg_->stec_residuals[22].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.satId, 15) + << "incorrect value for stec_residuals[22].sv_id.satId, expected 15, is " + << last_msg_->stec_residuals[22].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[23].residual, 18758) + << "incorrect value for stec_residuals[23].residual, expected 18758, is " + << last_msg_->stec_residuals[23].residual; + EXPECT_EQ(last_msg_->stec_residuals[23].stddev, 82) + << "incorrect value for stec_residuals[23].stddev, expected 82, is " + << last_msg_->stec_residuals[23].stddev; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.constellation, 132) + << "incorrect value for stec_residuals[23].sv_id.constellation, expected " + "132, is " + << last_msg_->stec_residuals[23].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.satId, 218) + << "incorrect value for stec_residuals[23].sv_id.satId, expected 218, is " + << last_msg_->stec_residuals[23].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[24].residual, 3839) + << "incorrect value for stec_residuals[24].residual, expected 3839, is " + << last_msg_->stec_residuals[24].residual; + EXPECT_EQ(last_msg_->stec_residuals[24].stddev, 134) + << "incorrect value for stec_residuals[24].stddev, expected 134, is " + << last_msg_->stec_residuals[24].stddev; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.constellation, 26) + << "incorrect value for stec_residuals[24].sv_id.constellation, expected " + "26, is " + << last_msg_->stec_residuals[24].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.satId, 147) + << "incorrect value for stec_residuals[24].sv_id.satId, expected 147, is " + << last_msg_->stec_residuals[24].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[25].residual, -10697) + << "incorrect value for stec_residuals[25].residual, expected -10697, is " + << last_msg_->stec_residuals[25].residual; + EXPECT_EQ(last_msg_->stec_residuals[25].stddev, 83) + << "incorrect value for stec_residuals[25].stddev, expected 83, is " + << last_msg_->stec_residuals[25].stddev; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.constellation, 138) + << "incorrect value for stec_residuals[25].sv_id.constellation, expected " + "138, is " + << last_msg_->stec_residuals[25].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.satId, 96) + << "incorrect value for stec_residuals[25].sv_id.satId, expected 96, is " + << last_msg_->stec_residuals[25].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[26].residual, 20387) + << "incorrect value for stec_residuals[26].residual, expected 20387, is " + << last_msg_->stec_residuals[26].residual; + EXPECT_EQ(last_msg_->stec_residuals[26].stddev, 173) + << "incorrect value for stec_residuals[26].stddev, expected 173, is " + << last_msg_->stec_residuals[26].stddev; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.constellation, 170) + << "incorrect value for stec_residuals[26].sv_id.constellation, expected " + "170, is " + << last_msg_->stec_residuals[26].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.satId, 156) + << "incorrect value for stec_residuals[26].sv_id.satId, expected 156, is " + << last_msg_->stec_residuals[26].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[27].residual, -3789) + << "incorrect value for stec_residuals[27].residual, expected -3789, is " + << last_msg_->stec_residuals[27].residual; + EXPECT_EQ(last_msg_->stec_residuals[27].stddev, 107) + << "incorrect value for stec_residuals[27].stddev, expected 107, is " + << last_msg_->stec_residuals[27].stddev; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.constellation, 115) + << "incorrect value for stec_residuals[27].sv_id.constellation, expected " + "115, is " + << last_msg_->stec_residuals[27].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.satId, 228) + << "incorrect value for stec_residuals[27].sv_id.satId, expected 228, is " + << last_msg_->stec_residuals[27].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[28].residual, -11608) + << "incorrect value for stec_residuals[28].residual, expected -11608, is " + << last_msg_->stec_residuals[28].residual; + EXPECT_EQ(last_msg_->stec_residuals[28].stddev, 10) + << "incorrect value for stec_residuals[28].stddev, expected 10, is " + << last_msg_->stec_residuals[28].stddev; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.constellation, 112) + << "incorrect value for stec_residuals[28].sv_id.constellation, expected " + "112, is " + << last_msg_->stec_residuals[28].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.satId, 245) + << "incorrect value for stec_residuals[28].sv_id.satId, expected 245, is " + << last_msg_->stec_residuals[28].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[29].residual, 14593) + << "incorrect value for stec_residuals[29].residual, expected 14593, is " + << last_msg_->stec_residuals[29].residual; + EXPECT_EQ(last_msg_->stec_residuals[29].stddev, 108) + << "incorrect value for stec_residuals[29].stddev, expected 108, is " + << last_msg_->stec_residuals[29].stddev; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.constellation, 117) + << "incorrect value for stec_residuals[29].sv_id.constellation, expected " + "117, is " + << last_msg_->stec_residuals[29].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.satId, 5) + << "incorrect value for stec_residuals[29].sv_id.satId, expected 5, is " + << last_msg_->stec_residuals[29].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[30].residual, 30609) + << "incorrect value for stec_residuals[30].residual, expected 30609, is " + << last_msg_->stec_residuals[30].residual; + EXPECT_EQ(last_msg_->stec_residuals[30].stddev, 226) + << "incorrect value for stec_residuals[30].stddev, expected 226, is " + << last_msg_->stec_residuals[30].stddev; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.constellation, 212) + << "incorrect value for stec_residuals[30].sv_id.constellation, expected " + "212, is " + << last_msg_->stec_residuals[30].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.satId, 248) + << "incorrect value for stec_residuals[30].sv_id.satId, expected 248, is " + << last_msg_->stec_residuals[30].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[31].residual, -13683) + << "incorrect value for stec_residuals[31].residual, expected -13683, is " + << last_msg_->stec_residuals[31].residual; + EXPECT_EQ(last_msg_->stec_residuals[31].stddev, 106) + << "incorrect value for stec_residuals[31].stddev, expected 106, is " + << last_msg_->stec_residuals[31].stddev; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.constellation, 5) + << "incorrect value for stec_residuals[31].sv_id.constellation, expected " + "5, is " + << last_msg_->stec_residuals[31].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.satId, 165) + << "incorrect value for stec_residuals[31].sv_id.satId, expected 165, is " + << last_msg_->stec_residuals[31].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[32].residual, 15652) + << "incorrect value for stec_residuals[32].residual, expected 15652, is " + << last_msg_->stec_residuals[32].residual; + EXPECT_EQ(last_msg_->stec_residuals[32].stddev, 243) + << "incorrect value for stec_residuals[32].stddev, expected 243, is " + << last_msg_->stec_residuals[32].stddev; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.constellation, 60) + << "incorrect value for stec_residuals[32].sv_id.constellation, expected " + "60, is " + << last_msg_->stec_residuals[32].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.satId, 0) + << "incorrect value for stec_residuals[32].sv_id.satId, expected 0, is " + << last_msg_->stec_residuals[32].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[33].residual, 3287) + << "incorrect value for stec_residuals[33].residual, expected 3287, is " + << last_msg_->stec_residuals[33].residual; + EXPECT_EQ(last_msg_->stec_residuals[33].stddev, 137) + << "incorrect value for stec_residuals[33].stddev, expected 137, is " + << last_msg_->stec_residuals[33].stddev; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.constellation, 216) + << "incorrect value for stec_residuals[33].sv_id.constellation, expected " + "216, is " + << last_msg_->stec_residuals[33].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.satId, 203) + << "incorrect value for stec_residuals[33].sv_id.satId, expected 203, is " + << last_msg_->stec_residuals[33].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[34].residual, 29687) + << "incorrect value for stec_residuals[34].residual, expected 29687, is " + << last_msg_->stec_residuals[34].residual; + EXPECT_EQ(last_msg_->stec_residuals[34].stddev, 152) + << "incorrect value for stec_residuals[34].stddev, expected 152, is " + << last_msg_->stec_residuals[34].stddev; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.constellation, 28) + << "incorrect value for stec_residuals[34].sv_id.constellation, expected " + "28, is " + << last_msg_->stec_residuals[34].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.satId, 16) + << "incorrect value for stec_residuals[34].sv_id.satId, expected 16, is " + << last_msg_->stec_residuals[34].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[35].residual, -6960) + << "incorrect value for stec_residuals[35].residual, expected -6960, is " + << last_msg_->stec_residuals[35].residual; + EXPECT_EQ(last_msg_->stec_residuals[35].stddev, 203) + << "incorrect value for stec_residuals[35].stddev, expected 203, is " + << last_msg_->stec_residuals[35].stddev; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.constellation, 119) + << "incorrect value for stec_residuals[35].sv_id.constellation, expected " + "119, is " + << last_msg_->stec_residuals[35].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.satId, 181) + << "incorrect value for stec_residuals[35].sv_id.satId, expected 181, is " + << last_msg_->stec_residuals[35].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[36].residual, -15193) + << "incorrect value for stec_residuals[36].residual, expected -15193, is " + << last_msg_->stec_residuals[36].residual; + EXPECT_EQ(last_msg_->stec_residuals[36].stddev, 32) + << "incorrect value for stec_residuals[36].stddev, expected 32, is " + << last_msg_->stec_residuals[36].stddev; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.constellation, 34) + << "incorrect value for stec_residuals[36].sv_id.constellation, expected " + "34, is " + << last_msg_->stec_residuals[36].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.satId, 236) + << "incorrect value for stec_residuals[36].sv_id.satId, expected 236, is " + << last_msg_->stec_residuals[36].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[37].residual, 25873) + << "incorrect value for stec_residuals[37].residual, expected 25873, is " + << last_msg_->stec_residuals[37].residual; + EXPECT_EQ(last_msg_->stec_residuals[37].stddev, 200) + << "incorrect value for stec_residuals[37].stddev, expected 200, is " + << last_msg_->stec_residuals[37].stddev; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.constellation, 1) + << "incorrect value for stec_residuals[37].sv_id.constellation, expected " + "1, is " + << last_msg_->stec_residuals[37].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.satId, 109) + << "incorrect value for stec_residuals[37].sv_id.satId, expected 109, is " + << last_msg_->stec_residuals[37].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[38].residual, -22403) + << "incorrect value for stec_residuals[38].residual, expected -22403, is " + << last_msg_->stec_residuals[38].residual; + EXPECT_EQ(last_msg_->stec_residuals[38].stddev, 137) + << "incorrect value for stec_residuals[38].stddev, expected 137, is " + << last_msg_->stec_residuals[38].stddev; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.constellation, 94) + << "incorrect value for stec_residuals[38].sv_id.constellation, expected " + "94, is " + << last_msg_->stec_residuals[38].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.satId, 25) + << "incorrect value for stec_residuals[38].sv_id.satId, expected 25, is " + << last_msg_->stec_residuals[38].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[39].residual, 7588) + << "incorrect value for stec_residuals[39].residual, expected 7588, is " + << last_msg_->stec_residuals[39].residual; + EXPECT_EQ(last_msg_->stec_residuals[39].stddev, 31) + << "incorrect value for stec_residuals[39].stddev, expected 31, is " + << last_msg_->stec_residuals[39].stddev; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.constellation, 4) + << "incorrect value for stec_residuals[39].sv_id.constellation, expected " + "4, is " + << last_msg_->stec_residuals[39].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.satId, 157) + << "incorrect value for stec_residuals[39].sv_id.satId, expected 157, is " + << last_msg_->stec_residuals[39].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[40].residual, -6840) + << "incorrect value for stec_residuals[40].residual, expected -6840, is " + << last_msg_->stec_residuals[40].residual; + EXPECT_EQ(last_msg_->stec_residuals[40].stddev, 126) + << "incorrect value for stec_residuals[40].stddev, expected 126, is " + << last_msg_->stec_residuals[40].stddev; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.constellation, 132) + << "incorrect value for stec_residuals[40].sv_id.constellation, expected " + "132, is " + << last_msg_->stec_residuals[40].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.satId, 48) + << "incorrect value for stec_residuals[40].sv_id.satId, expected 48, is " + << last_msg_->stec_residuals[40].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[41].residual, -31412) + << "incorrect value for stec_residuals[41].residual, expected -31412, is " + << last_msg_->stec_residuals[41].residual; + EXPECT_EQ(last_msg_->stec_residuals[41].stddev, 21) + << "incorrect value for stec_residuals[41].stddev, expected 21, is " + << last_msg_->stec_residuals[41].stddev; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.constellation, 68) + << "incorrect value for stec_residuals[41].sv_id.constellation, expected " + "68, is " + << last_msg_->stec_residuals[41].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.satId, 186) + << "incorrect value for stec_residuals[41].sv_id.satId, expected 186, is " + << last_msg_->stec_residuals[41].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[42].residual, -23413) + << "incorrect value for stec_residuals[42].residual, expected -23413, is " + << last_msg_->stec_residuals[42].residual; + EXPECT_EQ(last_msg_->stec_residuals[42].stddev, 148) + << "incorrect value for stec_residuals[42].stddev, expected 148, is " + << last_msg_->stec_residuals[42].stddev; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.constellation, 180) + << "incorrect value for stec_residuals[42].sv_id.constellation, expected " + "180, is " + << last_msg_->stec_residuals[42].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.satId, 0) + << "incorrect value for stec_residuals[42].sv_id.satId, expected 0, is " + << last_msg_->stec_residuals[42].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[43].residual, 30934) + << "incorrect value for stec_residuals[43].residual, expected 30934, is " + << last_msg_->stec_residuals[43].residual; + EXPECT_EQ(last_msg_->stec_residuals[43].stddev, 177) + << "incorrect value for stec_residuals[43].stddev, expected 177, is " + << last_msg_->stec_residuals[43].stddev; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.constellation, 149) + << "incorrect value for stec_residuals[43].sv_id.constellation, expected " + "149, is " + << last_msg_->stec_residuals[43].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.satId, 119) + << "incorrect value for stec_residuals[43].sv_id.satId, expected 119, is " + << last_msg_->stec_residuals[43].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[44].residual, 26960) + << "incorrect value for stec_residuals[44].residual, expected 26960, is " + << last_msg_->stec_residuals[44].residual; + EXPECT_EQ(last_msg_->stec_residuals[44].stddev, 10) + << "incorrect value for stec_residuals[44].stddev, expected 10, is " + << last_msg_->stec_residuals[44].stddev; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.constellation, 80) + << "incorrect value for stec_residuals[44].sv_id.constellation, expected " + "80, is " + << last_msg_->stec_residuals[44].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.satId, 201) + << "incorrect value for stec_residuals[44].sv_id.satId, expected 201, is " + << last_msg_->stec_residuals[44].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[45].residual, 11853) + << "incorrect value for stec_residuals[45].residual, expected 11853, is " + << last_msg_->stec_residuals[45].residual; + EXPECT_EQ(last_msg_->stec_residuals[45].stddev, 233) + << "incorrect value for stec_residuals[45].stddev, expected 233, is " + << last_msg_->stec_residuals[45].stddev; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.constellation, 118) + << "incorrect value for stec_residuals[45].sv_id.constellation, expected " + "118, is " + << last_msg_->stec_residuals[45].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.satId, 136) + << "incorrect value for stec_residuals[45].sv_id.satId, expected 136, is " + << last_msg_->stec_residuals[45].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[46].residual, -25077) + << "incorrect value for stec_residuals[46].residual, expected -25077, is " + << last_msg_->stec_residuals[46].residual; + EXPECT_EQ(last_msg_->stec_residuals[46].stddev, 103) + << "incorrect value for stec_residuals[46].stddev, expected 103, is " + << last_msg_->stec_residuals[46].stddev; + EXPECT_EQ(last_msg_->stec_residuals[46].sv_id.constellation, 227) + << "incorrect value for stec_residuals[46].sv_id.constellation, expected " + "227, is " + << last_msg_->stec_residuals[46].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[46].sv_id.satId, 233) + << "incorrect value for stec_residuals[46].sv_id.satId, expected 233, is " + << last_msg_->stec_residuals[46].sv_id.satId; + EXPECT_EQ(last_msg_->tropo_delay_correction.hydro, 10643) + << "incorrect value for tropo_delay_correction.hydro, expected 10643, is " + << last_msg_->tropo_delay_correction.hydro; + EXPECT_EQ(last_msg_->tropo_delay_correction.stddev, 92) + << "incorrect value for tropo_delay_correction.stddev, expected 92, is " + << last_msg_->tropo_delay_correction.stddev; + EXPECT_EQ(last_msg_->tropo_delay_correction.wet, 33) + << "incorrect value for tropo_delay_correction.wet, expected 33, is " + << last_msg_->tropo_delay_correction.wet; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc new file mode 100644 index 0000000000..b2f5ed9974 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA.cc @@ -0,0 +1,1222 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg( + uint16_t sender_id, uint8_t message_length, + const msg_ssr_gridded_correction_no_std_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_gridded_correction_no_std_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrGriddedCorrectionNoStdDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, 67, + 248, 233, 236, 230, 230, 103, 122, 63, 101, 231, 157, 115, 162, 197, 146, + 35, 107, 222, 109, 52, 41, 86, 12, 237, 184, 65, 204, 137, 148, 171, + 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, 203, 92, 166, 30, + 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, 95, 250, 99, 196, 92, + 214, 159, 253, 195, 222, 233, 146, 233, 63, 76, 24, 106, 40, 253, 65, + 9, 183, 40, 215, 188, 59, 117, 69, 97, 115, 60, 56, 0, 141, 207, + 171, 54, 161, 23, 61, 0, 87, 230, 123, 87, 36, 184, 255, 14, 163, + 187, 224, 43, 151, 151, 104, 39, 57, 5, 54, 48, 224, 181, 129, 60, + 92, 171, 114, 109, 109, 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, + 24, 68, 160, 36, 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, + 221, 253, 15, 62, 23, 121, 185, 168, 116, 4, 147, 123, 72, 223, 119, + 226, 242, 161, 204, 180, 202, 137, 166, 58, 24, 124, 19, 181, 188, 16, + 107, 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, 221, + 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, 99, + 44, 95, 131, 89, 192, 225, 55, 95, 171, 88, 205, 21, 116, 231, 83, + 71, 71, 100, 110, 217, 254, 152, 212, 18, 8, 40, 157, 244, 54, 72, + 240, 231, 189, 111, 195, 205, 81, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_gridded_correction_no_std_dep_a_t *test_msg = + (msg_ssr_gridded_correction_no_std_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.iod_atmo = 236; + test_msg->header.num_msgs = 62837; + test_msg->header.seq_num = 63555; + test_msg->header.time.tow = 2837573811; + test_msg->header.time.wn = 8940; + test_msg->header.tropo_quality_indicator = 230; + test_msg->header.update_interval = 233; + test_msg->index = 26598; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[0].residual = -23949; + test_msg->stec_residuals[0].sv_id.constellation = 157; + test_msg->stec_residuals[0].sv_id.satId = 231; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[1].residual = 27427; + test_msg->stec_residuals[1].sv_id.constellation = 146; + test_msg->stec_residuals[1].sv_id.satId = 197; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[2].residual = 10548; + test_msg->stec_residuals[2].sv_id.constellation = 109; + test_msg->stec_residuals[2].sv_id.satId = 222; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[3].residual = -18195; + test_msg->stec_residuals[3].sv_id.constellation = 12; + test_msg->stec_residuals[3].sv_id.satId = 86; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[4].residual = -27511; + test_msg->stec_residuals[4].sv_id.constellation = 204; + test_msg->stec_residuals[4].sv_id.satId = 65; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[5].residual = 11; + test_msg->stec_residuals[5].sv_id.constellation = 183; + test_msg->stec_residuals[5].sv_id.satId = 171; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[6].residual = 13740; + test_msg->stec_residuals[6].sv_id.constellation = 203; + test_msg->stec_residuals[6].sv_id.satId = 180; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[7].residual = 29626; + test_msg->stec_residuals[7].sv_id.constellation = 85; + test_msg->stec_residuals[7].sv_id.satId = 196; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[8].residual = 7846; + test_msg->stec_residuals[8].sv_id.constellation = 92; + test_msg->stec_residuals[8].sv_id.satId = 203; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[9].residual = 18376; + test_msg->stec_residuals[9].sv_id.constellation = 13; + test_msg->stec_residuals[9].sv_id.satId = 42; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[10].residual = -24357; + test_msg->stec_residuals[10].sv_id.constellation = 137; + test_msg->stec_residuals[10].sv_id.satId = 98; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[11].residual = -1441; + test_msg->stec_residuals[11].sv_id.constellation = 216; + test_msg->stec_residuals[11].sv_id.satId = 95; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[12].residual = -10660; + test_msg->stec_residuals[12].sv_id.constellation = 196; + test_msg->stec_residuals[12].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[13].residual = -8509; + test_msg->stec_residuals[13].sv_id.constellation = 253; + test_msg->stec_residuals[13].sv_id.satId = 159; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[14].residual = 16361; + test_msg->stec_residuals[14].sv_id.constellation = 146; + test_msg->stec_residuals[14].sv_id.satId = 233; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[15].residual = 10346; + test_msg->stec_residuals[15].sv_id.constellation = 24; + test_msg->stec_residuals[15].sv_id.satId = 76; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[16].residual = -18679; + test_msg->stec_residuals[16].sv_id.constellation = 65; + test_msg->stec_residuals[16].sv_id.satId = 253; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[17].residual = 15292; + test_msg->stec_residuals[17].sv_id.constellation = 215; + test_msg->stec_residuals[17].sv_id.satId = 40; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[18].residual = 29537; + test_msg->stec_residuals[18].sv_id.constellation = 69; + test_msg->stec_residuals[18].sv_id.satId = 117; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[19].residual = -29440; + test_msg->stec_residuals[19].sv_id.constellation = 56; + test_msg->stec_residuals[19].sv_id.satId = 60; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[20].residual = -24266; + test_msg->stec_residuals[20].sv_id.constellation = 171; + test_msg->stec_residuals[20].sv_id.satId = 207; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[21].residual = 22272; + test_msg->stec_residuals[21].sv_id.constellation = 61; + test_msg->stec_residuals[21].sv_id.satId = 23; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[22].residual = 9303; + test_msg->stec_residuals[22].sv_id.constellation = 123; + test_msg->stec_residuals[22].sv_id.satId = 230; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[23].residual = -23794; + test_msg->stec_residuals[23].sv_id.constellation = 255; + test_msg->stec_residuals[23].sv_id.satId = 184; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[24].residual = -26837; + test_msg->stec_residuals[24].sv_id.constellation = 224; + test_msg->stec_residuals[24].sv_id.satId = 187; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[25].residual = 14631; + test_msg->stec_residuals[25].sv_id.constellation = 104; + test_msg->stec_residuals[25].sv_id.satId = 151; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[26].residual = -8144; + test_msg->stec_residuals[26].sv_id.constellation = 54; + test_msg->stec_residuals[26].sv_id.satId = 5; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[27].residual = 23612; + test_msg->stec_residuals[27].sv_id.constellation = 129; + test_msg->stec_residuals[27].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[28].residual = 28013; + test_msg->stec_residuals[28].sv_id.constellation = 114; + test_msg->stec_residuals[28].sv_id.satId = 171; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[29].residual = 2166; + test_msg->stec_residuals[29].sv_id.constellation = 23; + test_msg->stec_residuals[29].sv_id.satId = 12; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[30].residual = -10186; + test_msg->stec_residuals[30].sv_id.constellation = 159; + test_msg->stec_residuals[30].sv_id.satId = 64; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[31].residual = 17432; + test_msg->stec_residuals[31].sv_id.constellation = 20; + test_msg->stec_residuals[31].sv_id.satId = 33; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[32].residual = -8666; + test_msg->stec_residuals[32].sv_id.constellation = 36; + test_msg->stec_residuals[32].sv_id.satId = 160; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[33].residual = 25436; + test_msg->stec_residuals[33].sv_id.constellation = 190; + test_msg->stec_residuals[33].sv_id.satId = 145; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[34].residual = -3864; + test_msg->stec_residuals[34].sv_id.constellation = 159; + test_msg->stec_residuals[34].sv_id.satId = 108; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[35].residual = 4093; + test_msg->stec_residuals[35].sv_id.constellation = 221; + test_msg->stec_residuals[35].sv_id.satId = 227; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[36].residual = -18055; + test_msg->stec_residuals[36].sv_id.constellation = 23; + test_msg->stec_residuals[36].sv_id.satId = 62; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[37].residual = -27900; + test_msg->stec_residuals[37].sv_id.constellation = 116; + test_msg->stec_residuals[37].sv_id.satId = 168; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[38].residual = 30687; + test_msg->stec_residuals[38].sv_id.constellation = 72; + test_msg->stec_residuals[38].sv_id.satId = 123; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[39].residual = -13151; + test_msg->stec_residuals[39].sv_id.constellation = 242; + test_msg->stec_residuals[39].sv_id.satId = 226; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[40].residual = -22903; + test_msg->stec_residuals[40].sv_id.constellation = 202; + test_msg->stec_residuals[40].sv_id.satId = 180; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[41].residual = 4988; + test_msg->stec_residuals[41].sv_id.constellation = 24; + test_msg->stec_residuals[41].sv_id.satId = 58; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[42].residual = 27408; + test_msg->stec_residuals[42].sv_id.constellation = 188; + test_msg->stec_residuals[42].sv_id.satId = 181; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[43].residual = 319; + test_msg->stec_residuals[43].sv_id.constellation = 231; + test_msg->stec_residuals[43].sv_id.satId = 66; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[44].residual = 15987; + test_msg->stec_residuals[44].sv_id.constellation = 252; + test_msg->stec_residuals[44].sv_id.satId = 64; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[45].residual = 22266; + test_msg->stec_residuals[45].sv_id.constellation = 97; + test_msg->stec_residuals[45].sv_id.satId = 233; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[46].residual = -19919; + test_msg->stec_residuals[46].sv_id.constellation = 221; + test_msg->stec_residuals[46].sv_id.satId = 156; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[47].residual = 17350; + test_msg->stec_residuals[47].sv_id.constellation = 73; + test_msg->stec_residuals[47].sv_id.satId = 32; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[48].residual = 14410; + test_msg->stec_residuals[48].sv_id.constellation = 253; + test_msg->stec_residuals[48].sv_id.satId = 249; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[49].residual = 23671; + test_msg->stec_residuals[49].sv_id.constellation = 165; + test_msg->stec_residuals[49].sv_id.satId = 38; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[50].residual = -31905; + test_msg->stec_residuals[50].sv_id.constellation = 44; + test_msg->stec_residuals[50].sv_id.satId = 99; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[51].residual = 14305; + test_msg->stec_residuals[51].sv_id.constellation = 192; + test_msg->stec_residuals[51].sv_id.satId = 89; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[52].residual = -12968; + test_msg->stec_residuals[52].sv_id.constellation = 171; + test_msg->stec_residuals[52].sv_id.satId = 95; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[53].residual = 21479; + test_msg->stec_residuals[53].sv_id.constellation = 116; + test_msg->stec_residuals[53].sv_id.satId = 21; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[54].residual = 28260; + test_msg->stec_residuals[54].sv_id.constellation = 71; + test_msg->stec_residuals[54].sv_id.satId = 71; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[55].residual = -11112; + test_msg->stec_residuals[55].sv_id.constellation = 254; + test_msg->stec_residuals[55].sv_id.satId = 217; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[56].residual = -25304; + test_msg->stec_residuals[56].sv_id.constellation = 8; + test_msg->stec_residuals[56].sv_id.satId = 18; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[57].residual = -4024; + test_msg->stec_residuals[57].sv_id.constellation = 54; + test_msg->stec_residuals[57].sv_id.satId = 244; + if (sizeof(test_msg->stec_residuals) == 0) { + // Cope with variable length arrays + test_msg_len = + (uint8_t)(test_msg_len + sizeof(test_msg->stec_residuals[0])); + } + test_msg->stec_residuals[58].residual = -15505; + test_msg->stec_residuals[58].sv_id.constellation = 189; + test_msg->stec_residuals[58].sv_id.satId = 231; + test_msg->tropo_delay_correction.hydro = 16250; + test_msg->tropo_delay_correction.wet = 101; + + EXPECT_EQ(send_message(0x5f0, 7270, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 7270); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.iod_atmo, 236) + << "incorrect value for header.iod_atmo, expected 236, is " + << last_msg_->header.iod_atmo; + EXPECT_EQ(last_msg_->header.num_msgs, 62837) + << "incorrect value for header.num_msgs, expected 62837, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.seq_num, 63555) + << "incorrect value for header.seq_num, expected 63555, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->header.time.tow, 2837573811) + << "incorrect value for header.time.tow, expected 2837573811, is " + << last_msg_->header.time.tow; + EXPECT_EQ(last_msg_->header.time.wn, 8940) + << "incorrect value for header.time.wn, expected 8940, is " + << last_msg_->header.time.wn; + EXPECT_EQ(last_msg_->header.tropo_quality_indicator, 230) + << "incorrect value for header.tropo_quality_indicator, expected 230, is " + << last_msg_->header.tropo_quality_indicator; + EXPECT_EQ(last_msg_->header.update_interval, 233) + << "incorrect value for header.update_interval, expected 233, is " + << last_msg_->header.update_interval; + EXPECT_EQ(last_msg_->index, 26598) + << "incorrect value for index, expected 26598, is " << last_msg_->index; + EXPECT_EQ(last_msg_->stec_residuals[0].residual, -23949) + << "incorrect value for stec_residuals[0].residual, expected -23949, is " + << last_msg_->stec_residuals[0].residual; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.constellation, 157) + << "incorrect value for stec_residuals[0].sv_id.constellation, expected " + "157, is " + << last_msg_->stec_residuals[0].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[0].sv_id.satId, 231) + << "incorrect value for stec_residuals[0].sv_id.satId, expected 231, is " + << last_msg_->stec_residuals[0].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[1].residual, 27427) + << "incorrect value for stec_residuals[1].residual, expected 27427, is " + << last_msg_->stec_residuals[1].residual; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.constellation, 146) + << "incorrect value for stec_residuals[1].sv_id.constellation, expected " + "146, is " + << last_msg_->stec_residuals[1].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[1].sv_id.satId, 197) + << "incorrect value for stec_residuals[1].sv_id.satId, expected 197, is " + << last_msg_->stec_residuals[1].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[2].residual, 10548) + << "incorrect value for stec_residuals[2].residual, expected 10548, is " + << last_msg_->stec_residuals[2].residual; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.constellation, 109) + << "incorrect value for stec_residuals[2].sv_id.constellation, expected " + "109, is " + << last_msg_->stec_residuals[2].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[2].sv_id.satId, 222) + << "incorrect value for stec_residuals[2].sv_id.satId, expected 222, is " + << last_msg_->stec_residuals[2].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[3].residual, -18195) + << "incorrect value for stec_residuals[3].residual, expected -18195, is " + << last_msg_->stec_residuals[3].residual; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.constellation, 12) + << "incorrect value for stec_residuals[3].sv_id.constellation, expected " + "12, is " + << last_msg_->stec_residuals[3].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[3].sv_id.satId, 86) + << "incorrect value for stec_residuals[3].sv_id.satId, expected 86, is " + << last_msg_->stec_residuals[3].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[4].residual, -27511) + << "incorrect value for stec_residuals[4].residual, expected -27511, is " + << last_msg_->stec_residuals[4].residual; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.constellation, 204) + << "incorrect value for stec_residuals[4].sv_id.constellation, expected " + "204, is " + << last_msg_->stec_residuals[4].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[4].sv_id.satId, 65) + << "incorrect value for stec_residuals[4].sv_id.satId, expected 65, is " + << last_msg_->stec_residuals[4].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[5].residual, 11) + << "incorrect value for stec_residuals[5].residual, expected 11, is " + << last_msg_->stec_residuals[5].residual; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.constellation, 183) + << "incorrect value for stec_residuals[5].sv_id.constellation, expected " + "183, is " + << last_msg_->stec_residuals[5].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[5].sv_id.satId, 171) + << "incorrect value for stec_residuals[5].sv_id.satId, expected 171, is " + << last_msg_->stec_residuals[5].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[6].residual, 13740) + << "incorrect value for stec_residuals[6].residual, expected 13740, is " + << last_msg_->stec_residuals[6].residual; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.constellation, 203) + << "incorrect value for stec_residuals[6].sv_id.constellation, expected " + "203, is " + << last_msg_->stec_residuals[6].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[6].sv_id.satId, 180) + << "incorrect value for stec_residuals[6].sv_id.satId, expected 180, is " + << last_msg_->stec_residuals[6].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[7].residual, 29626) + << "incorrect value for stec_residuals[7].residual, expected 29626, is " + << last_msg_->stec_residuals[7].residual; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.constellation, 85) + << "incorrect value for stec_residuals[7].sv_id.constellation, expected " + "85, is " + << last_msg_->stec_residuals[7].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[7].sv_id.satId, 196) + << "incorrect value for stec_residuals[7].sv_id.satId, expected 196, is " + << last_msg_->stec_residuals[7].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[8].residual, 7846) + << "incorrect value for stec_residuals[8].residual, expected 7846, is " + << last_msg_->stec_residuals[8].residual; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.constellation, 92) + << "incorrect value for stec_residuals[8].sv_id.constellation, expected " + "92, is " + << last_msg_->stec_residuals[8].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[8].sv_id.satId, 203) + << "incorrect value for stec_residuals[8].sv_id.satId, expected 203, is " + << last_msg_->stec_residuals[8].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[9].residual, 18376) + << "incorrect value for stec_residuals[9].residual, expected 18376, is " + << last_msg_->stec_residuals[9].residual; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.constellation, 13) + << "incorrect value for stec_residuals[9].sv_id.constellation, expected " + "13, is " + << last_msg_->stec_residuals[9].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[9].sv_id.satId, 42) + << "incorrect value for stec_residuals[9].sv_id.satId, expected 42, is " + << last_msg_->stec_residuals[9].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[10].residual, -24357) + << "incorrect value for stec_residuals[10].residual, expected -24357, is " + << last_msg_->stec_residuals[10].residual; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.constellation, 137) + << "incorrect value for stec_residuals[10].sv_id.constellation, expected " + "137, is " + << last_msg_->stec_residuals[10].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[10].sv_id.satId, 98) + << "incorrect value for stec_residuals[10].sv_id.satId, expected 98, is " + << last_msg_->stec_residuals[10].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[11].residual, -1441) + << "incorrect value for stec_residuals[11].residual, expected -1441, is " + << last_msg_->stec_residuals[11].residual; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.constellation, 216) + << "incorrect value for stec_residuals[11].sv_id.constellation, expected " + "216, is " + << last_msg_->stec_residuals[11].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[11].sv_id.satId, 95) + << "incorrect value for stec_residuals[11].sv_id.satId, expected 95, is " + << last_msg_->stec_residuals[11].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[12].residual, -10660) + << "incorrect value for stec_residuals[12].residual, expected -10660, is " + << last_msg_->stec_residuals[12].residual; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.constellation, 196) + << "incorrect value for stec_residuals[12].sv_id.constellation, expected " + "196, is " + << last_msg_->stec_residuals[12].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[12].sv_id.satId, 99) + << "incorrect value for stec_residuals[12].sv_id.satId, expected 99, is " + << last_msg_->stec_residuals[12].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[13].residual, -8509) + << "incorrect value for stec_residuals[13].residual, expected -8509, is " + << last_msg_->stec_residuals[13].residual; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.constellation, 253) + << "incorrect value for stec_residuals[13].sv_id.constellation, expected " + "253, is " + << last_msg_->stec_residuals[13].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[13].sv_id.satId, 159) + << "incorrect value for stec_residuals[13].sv_id.satId, expected 159, is " + << last_msg_->stec_residuals[13].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[14].residual, 16361) + << "incorrect value for stec_residuals[14].residual, expected 16361, is " + << last_msg_->stec_residuals[14].residual; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.constellation, 146) + << "incorrect value for stec_residuals[14].sv_id.constellation, expected " + "146, is " + << last_msg_->stec_residuals[14].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[14].sv_id.satId, 233) + << "incorrect value for stec_residuals[14].sv_id.satId, expected 233, is " + << last_msg_->stec_residuals[14].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[15].residual, 10346) + << "incorrect value for stec_residuals[15].residual, expected 10346, is " + << last_msg_->stec_residuals[15].residual; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.constellation, 24) + << "incorrect value for stec_residuals[15].sv_id.constellation, expected " + "24, is " + << last_msg_->stec_residuals[15].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[15].sv_id.satId, 76) + << "incorrect value for stec_residuals[15].sv_id.satId, expected 76, is " + << last_msg_->stec_residuals[15].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[16].residual, -18679) + << "incorrect value for stec_residuals[16].residual, expected -18679, is " + << last_msg_->stec_residuals[16].residual; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.constellation, 65) + << "incorrect value for stec_residuals[16].sv_id.constellation, expected " + "65, is " + << last_msg_->stec_residuals[16].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[16].sv_id.satId, 253) + << "incorrect value for stec_residuals[16].sv_id.satId, expected 253, is " + << last_msg_->stec_residuals[16].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[17].residual, 15292) + << "incorrect value for stec_residuals[17].residual, expected 15292, is " + << last_msg_->stec_residuals[17].residual; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.constellation, 215) + << "incorrect value for stec_residuals[17].sv_id.constellation, expected " + "215, is " + << last_msg_->stec_residuals[17].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[17].sv_id.satId, 40) + << "incorrect value for stec_residuals[17].sv_id.satId, expected 40, is " + << last_msg_->stec_residuals[17].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[18].residual, 29537) + << "incorrect value for stec_residuals[18].residual, expected 29537, is " + << last_msg_->stec_residuals[18].residual; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.constellation, 69) + << "incorrect value for stec_residuals[18].sv_id.constellation, expected " + "69, is " + << last_msg_->stec_residuals[18].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[18].sv_id.satId, 117) + << "incorrect value for stec_residuals[18].sv_id.satId, expected 117, is " + << last_msg_->stec_residuals[18].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[19].residual, -29440) + << "incorrect value for stec_residuals[19].residual, expected -29440, is " + << last_msg_->stec_residuals[19].residual; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.constellation, 56) + << "incorrect value for stec_residuals[19].sv_id.constellation, expected " + "56, is " + << last_msg_->stec_residuals[19].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[19].sv_id.satId, 60) + << "incorrect value for stec_residuals[19].sv_id.satId, expected 60, is " + << last_msg_->stec_residuals[19].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[20].residual, -24266) + << "incorrect value for stec_residuals[20].residual, expected -24266, is " + << last_msg_->stec_residuals[20].residual; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.constellation, 171) + << "incorrect value for stec_residuals[20].sv_id.constellation, expected " + "171, is " + << last_msg_->stec_residuals[20].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[20].sv_id.satId, 207) + << "incorrect value for stec_residuals[20].sv_id.satId, expected 207, is " + << last_msg_->stec_residuals[20].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[21].residual, 22272) + << "incorrect value for stec_residuals[21].residual, expected 22272, is " + << last_msg_->stec_residuals[21].residual; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.constellation, 61) + << "incorrect value for stec_residuals[21].sv_id.constellation, expected " + "61, is " + << last_msg_->stec_residuals[21].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[21].sv_id.satId, 23) + << "incorrect value for stec_residuals[21].sv_id.satId, expected 23, is " + << last_msg_->stec_residuals[21].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[22].residual, 9303) + << "incorrect value for stec_residuals[22].residual, expected 9303, is " + << last_msg_->stec_residuals[22].residual; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.constellation, 123) + << "incorrect value for stec_residuals[22].sv_id.constellation, expected " + "123, is " + << last_msg_->stec_residuals[22].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[22].sv_id.satId, 230) + << "incorrect value for stec_residuals[22].sv_id.satId, expected 230, is " + << last_msg_->stec_residuals[22].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[23].residual, -23794) + << "incorrect value for stec_residuals[23].residual, expected -23794, is " + << last_msg_->stec_residuals[23].residual; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.constellation, 255) + << "incorrect value for stec_residuals[23].sv_id.constellation, expected " + "255, is " + << last_msg_->stec_residuals[23].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[23].sv_id.satId, 184) + << "incorrect value for stec_residuals[23].sv_id.satId, expected 184, is " + << last_msg_->stec_residuals[23].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[24].residual, -26837) + << "incorrect value for stec_residuals[24].residual, expected -26837, is " + << last_msg_->stec_residuals[24].residual; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.constellation, 224) + << "incorrect value for stec_residuals[24].sv_id.constellation, expected " + "224, is " + << last_msg_->stec_residuals[24].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[24].sv_id.satId, 187) + << "incorrect value for stec_residuals[24].sv_id.satId, expected 187, is " + << last_msg_->stec_residuals[24].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[25].residual, 14631) + << "incorrect value for stec_residuals[25].residual, expected 14631, is " + << last_msg_->stec_residuals[25].residual; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.constellation, 104) + << "incorrect value for stec_residuals[25].sv_id.constellation, expected " + "104, is " + << last_msg_->stec_residuals[25].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[25].sv_id.satId, 151) + << "incorrect value for stec_residuals[25].sv_id.satId, expected 151, is " + << last_msg_->stec_residuals[25].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[26].residual, -8144) + << "incorrect value for stec_residuals[26].residual, expected -8144, is " + << last_msg_->stec_residuals[26].residual; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.constellation, 54) + << "incorrect value for stec_residuals[26].sv_id.constellation, expected " + "54, is " + << last_msg_->stec_residuals[26].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[26].sv_id.satId, 5) + << "incorrect value for stec_residuals[26].sv_id.satId, expected 5, is " + << last_msg_->stec_residuals[26].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[27].residual, 23612) + << "incorrect value for stec_residuals[27].residual, expected 23612, is " + << last_msg_->stec_residuals[27].residual; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.constellation, 129) + << "incorrect value for stec_residuals[27].sv_id.constellation, expected " + "129, is " + << last_msg_->stec_residuals[27].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[27].sv_id.satId, 181) + << "incorrect value for stec_residuals[27].sv_id.satId, expected 181, is " + << last_msg_->stec_residuals[27].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[28].residual, 28013) + << "incorrect value for stec_residuals[28].residual, expected 28013, is " + << last_msg_->stec_residuals[28].residual; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.constellation, 114) + << "incorrect value for stec_residuals[28].sv_id.constellation, expected " + "114, is " + << last_msg_->stec_residuals[28].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[28].sv_id.satId, 171) + << "incorrect value for stec_residuals[28].sv_id.satId, expected 171, is " + << last_msg_->stec_residuals[28].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[29].residual, 2166) + << "incorrect value for stec_residuals[29].residual, expected 2166, is " + << last_msg_->stec_residuals[29].residual; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.constellation, 23) + << "incorrect value for stec_residuals[29].sv_id.constellation, expected " + "23, is " + << last_msg_->stec_residuals[29].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[29].sv_id.satId, 12) + << "incorrect value for stec_residuals[29].sv_id.satId, expected 12, is " + << last_msg_->stec_residuals[29].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[30].residual, -10186) + << "incorrect value for stec_residuals[30].residual, expected -10186, is " + << last_msg_->stec_residuals[30].residual; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.constellation, 159) + << "incorrect value for stec_residuals[30].sv_id.constellation, expected " + "159, is " + << last_msg_->stec_residuals[30].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[30].sv_id.satId, 64) + << "incorrect value for stec_residuals[30].sv_id.satId, expected 64, is " + << last_msg_->stec_residuals[30].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[31].residual, 17432) + << "incorrect value for stec_residuals[31].residual, expected 17432, is " + << last_msg_->stec_residuals[31].residual; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.constellation, 20) + << "incorrect value for stec_residuals[31].sv_id.constellation, expected " + "20, is " + << last_msg_->stec_residuals[31].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[31].sv_id.satId, 33) + << "incorrect value for stec_residuals[31].sv_id.satId, expected 33, is " + << last_msg_->stec_residuals[31].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[32].residual, -8666) + << "incorrect value for stec_residuals[32].residual, expected -8666, is " + << last_msg_->stec_residuals[32].residual; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.constellation, 36) + << "incorrect value for stec_residuals[32].sv_id.constellation, expected " + "36, is " + << last_msg_->stec_residuals[32].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[32].sv_id.satId, 160) + << "incorrect value for stec_residuals[32].sv_id.satId, expected 160, is " + << last_msg_->stec_residuals[32].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[33].residual, 25436) + << "incorrect value for stec_residuals[33].residual, expected 25436, is " + << last_msg_->stec_residuals[33].residual; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.constellation, 190) + << "incorrect value for stec_residuals[33].sv_id.constellation, expected " + "190, is " + << last_msg_->stec_residuals[33].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[33].sv_id.satId, 145) + << "incorrect value for stec_residuals[33].sv_id.satId, expected 145, is " + << last_msg_->stec_residuals[33].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[34].residual, -3864) + << "incorrect value for stec_residuals[34].residual, expected -3864, is " + << last_msg_->stec_residuals[34].residual; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.constellation, 159) + << "incorrect value for stec_residuals[34].sv_id.constellation, expected " + "159, is " + << last_msg_->stec_residuals[34].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[34].sv_id.satId, 108) + << "incorrect value for stec_residuals[34].sv_id.satId, expected 108, is " + << last_msg_->stec_residuals[34].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[35].residual, 4093) + << "incorrect value for stec_residuals[35].residual, expected 4093, is " + << last_msg_->stec_residuals[35].residual; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.constellation, 221) + << "incorrect value for stec_residuals[35].sv_id.constellation, expected " + "221, is " + << last_msg_->stec_residuals[35].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[35].sv_id.satId, 227) + << "incorrect value for stec_residuals[35].sv_id.satId, expected 227, is " + << last_msg_->stec_residuals[35].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[36].residual, -18055) + << "incorrect value for stec_residuals[36].residual, expected -18055, is " + << last_msg_->stec_residuals[36].residual; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.constellation, 23) + << "incorrect value for stec_residuals[36].sv_id.constellation, expected " + "23, is " + << last_msg_->stec_residuals[36].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[36].sv_id.satId, 62) + << "incorrect value for stec_residuals[36].sv_id.satId, expected 62, is " + << last_msg_->stec_residuals[36].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[37].residual, -27900) + << "incorrect value for stec_residuals[37].residual, expected -27900, is " + << last_msg_->stec_residuals[37].residual; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.constellation, 116) + << "incorrect value for stec_residuals[37].sv_id.constellation, expected " + "116, is " + << last_msg_->stec_residuals[37].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[37].sv_id.satId, 168) + << "incorrect value for stec_residuals[37].sv_id.satId, expected 168, is " + << last_msg_->stec_residuals[37].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[38].residual, 30687) + << "incorrect value for stec_residuals[38].residual, expected 30687, is " + << last_msg_->stec_residuals[38].residual; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.constellation, 72) + << "incorrect value for stec_residuals[38].sv_id.constellation, expected " + "72, is " + << last_msg_->stec_residuals[38].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[38].sv_id.satId, 123) + << "incorrect value for stec_residuals[38].sv_id.satId, expected 123, is " + << last_msg_->stec_residuals[38].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[39].residual, -13151) + << "incorrect value for stec_residuals[39].residual, expected -13151, is " + << last_msg_->stec_residuals[39].residual; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.constellation, 242) + << "incorrect value for stec_residuals[39].sv_id.constellation, expected " + "242, is " + << last_msg_->stec_residuals[39].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[39].sv_id.satId, 226) + << "incorrect value for stec_residuals[39].sv_id.satId, expected 226, is " + << last_msg_->stec_residuals[39].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[40].residual, -22903) + << "incorrect value for stec_residuals[40].residual, expected -22903, is " + << last_msg_->stec_residuals[40].residual; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.constellation, 202) + << "incorrect value for stec_residuals[40].sv_id.constellation, expected " + "202, is " + << last_msg_->stec_residuals[40].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[40].sv_id.satId, 180) + << "incorrect value for stec_residuals[40].sv_id.satId, expected 180, is " + << last_msg_->stec_residuals[40].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[41].residual, 4988) + << "incorrect value for stec_residuals[41].residual, expected 4988, is " + << last_msg_->stec_residuals[41].residual; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.constellation, 24) + << "incorrect value for stec_residuals[41].sv_id.constellation, expected " + "24, is " + << last_msg_->stec_residuals[41].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[41].sv_id.satId, 58) + << "incorrect value for stec_residuals[41].sv_id.satId, expected 58, is " + << last_msg_->stec_residuals[41].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[42].residual, 27408) + << "incorrect value for stec_residuals[42].residual, expected 27408, is " + << last_msg_->stec_residuals[42].residual; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.constellation, 188) + << "incorrect value for stec_residuals[42].sv_id.constellation, expected " + "188, is " + << last_msg_->stec_residuals[42].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[42].sv_id.satId, 181) + << "incorrect value for stec_residuals[42].sv_id.satId, expected 181, is " + << last_msg_->stec_residuals[42].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[43].residual, 319) + << "incorrect value for stec_residuals[43].residual, expected 319, is " + << last_msg_->stec_residuals[43].residual; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.constellation, 231) + << "incorrect value for stec_residuals[43].sv_id.constellation, expected " + "231, is " + << last_msg_->stec_residuals[43].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[43].sv_id.satId, 66) + << "incorrect value for stec_residuals[43].sv_id.satId, expected 66, is " + << last_msg_->stec_residuals[43].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[44].residual, 15987) + << "incorrect value for stec_residuals[44].residual, expected 15987, is " + << last_msg_->stec_residuals[44].residual; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.constellation, 252) + << "incorrect value for stec_residuals[44].sv_id.constellation, expected " + "252, is " + << last_msg_->stec_residuals[44].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[44].sv_id.satId, 64) + << "incorrect value for stec_residuals[44].sv_id.satId, expected 64, is " + << last_msg_->stec_residuals[44].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[45].residual, 22266) + << "incorrect value for stec_residuals[45].residual, expected 22266, is " + << last_msg_->stec_residuals[45].residual; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.constellation, 97) + << "incorrect value for stec_residuals[45].sv_id.constellation, expected " + "97, is " + << last_msg_->stec_residuals[45].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[45].sv_id.satId, 233) + << "incorrect value for stec_residuals[45].sv_id.satId, expected 233, is " + << last_msg_->stec_residuals[45].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[46].residual, -19919) + << "incorrect value for stec_residuals[46].residual, expected -19919, is " + << last_msg_->stec_residuals[46].residual; + EXPECT_EQ(last_msg_->stec_residuals[46].sv_id.constellation, 221) + << "incorrect value for stec_residuals[46].sv_id.constellation, expected " + "221, is " + << last_msg_->stec_residuals[46].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[46].sv_id.satId, 156) + << "incorrect value for stec_residuals[46].sv_id.satId, expected 156, is " + << last_msg_->stec_residuals[46].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[47].residual, 17350) + << "incorrect value for stec_residuals[47].residual, expected 17350, is " + << last_msg_->stec_residuals[47].residual; + EXPECT_EQ(last_msg_->stec_residuals[47].sv_id.constellation, 73) + << "incorrect value for stec_residuals[47].sv_id.constellation, expected " + "73, is " + << last_msg_->stec_residuals[47].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[47].sv_id.satId, 32) + << "incorrect value for stec_residuals[47].sv_id.satId, expected 32, is " + << last_msg_->stec_residuals[47].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[48].residual, 14410) + << "incorrect value for stec_residuals[48].residual, expected 14410, is " + << last_msg_->stec_residuals[48].residual; + EXPECT_EQ(last_msg_->stec_residuals[48].sv_id.constellation, 253) + << "incorrect value for stec_residuals[48].sv_id.constellation, expected " + "253, is " + << last_msg_->stec_residuals[48].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[48].sv_id.satId, 249) + << "incorrect value for stec_residuals[48].sv_id.satId, expected 249, is " + << last_msg_->stec_residuals[48].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[49].residual, 23671) + << "incorrect value for stec_residuals[49].residual, expected 23671, is " + << last_msg_->stec_residuals[49].residual; + EXPECT_EQ(last_msg_->stec_residuals[49].sv_id.constellation, 165) + << "incorrect value for stec_residuals[49].sv_id.constellation, expected " + "165, is " + << last_msg_->stec_residuals[49].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[49].sv_id.satId, 38) + << "incorrect value for stec_residuals[49].sv_id.satId, expected 38, is " + << last_msg_->stec_residuals[49].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[50].residual, -31905) + << "incorrect value for stec_residuals[50].residual, expected -31905, is " + << last_msg_->stec_residuals[50].residual; + EXPECT_EQ(last_msg_->stec_residuals[50].sv_id.constellation, 44) + << "incorrect value for stec_residuals[50].sv_id.constellation, expected " + "44, is " + << last_msg_->stec_residuals[50].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[50].sv_id.satId, 99) + << "incorrect value for stec_residuals[50].sv_id.satId, expected 99, is " + << last_msg_->stec_residuals[50].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[51].residual, 14305) + << "incorrect value for stec_residuals[51].residual, expected 14305, is " + << last_msg_->stec_residuals[51].residual; + EXPECT_EQ(last_msg_->stec_residuals[51].sv_id.constellation, 192) + << "incorrect value for stec_residuals[51].sv_id.constellation, expected " + "192, is " + << last_msg_->stec_residuals[51].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[51].sv_id.satId, 89) + << "incorrect value for stec_residuals[51].sv_id.satId, expected 89, is " + << last_msg_->stec_residuals[51].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[52].residual, -12968) + << "incorrect value for stec_residuals[52].residual, expected -12968, is " + << last_msg_->stec_residuals[52].residual; + EXPECT_EQ(last_msg_->stec_residuals[52].sv_id.constellation, 171) + << "incorrect value for stec_residuals[52].sv_id.constellation, expected " + "171, is " + << last_msg_->stec_residuals[52].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[52].sv_id.satId, 95) + << "incorrect value for stec_residuals[52].sv_id.satId, expected 95, is " + << last_msg_->stec_residuals[52].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[53].residual, 21479) + << "incorrect value for stec_residuals[53].residual, expected 21479, is " + << last_msg_->stec_residuals[53].residual; + EXPECT_EQ(last_msg_->stec_residuals[53].sv_id.constellation, 116) + << "incorrect value for stec_residuals[53].sv_id.constellation, expected " + "116, is " + << last_msg_->stec_residuals[53].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[53].sv_id.satId, 21) + << "incorrect value for stec_residuals[53].sv_id.satId, expected 21, is " + << last_msg_->stec_residuals[53].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[54].residual, 28260) + << "incorrect value for stec_residuals[54].residual, expected 28260, is " + << last_msg_->stec_residuals[54].residual; + EXPECT_EQ(last_msg_->stec_residuals[54].sv_id.constellation, 71) + << "incorrect value for stec_residuals[54].sv_id.constellation, expected " + "71, is " + << last_msg_->stec_residuals[54].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[54].sv_id.satId, 71) + << "incorrect value for stec_residuals[54].sv_id.satId, expected 71, is " + << last_msg_->stec_residuals[54].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[55].residual, -11112) + << "incorrect value for stec_residuals[55].residual, expected -11112, is " + << last_msg_->stec_residuals[55].residual; + EXPECT_EQ(last_msg_->stec_residuals[55].sv_id.constellation, 254) + << "incorrect value for stec_residuals[55].sv_id.constellation, expected " + "254, is " + << last_msg_->stec_residuals[55].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[55].sv_id.satId, 217) + << "incorrect value for stec_residuals[55].sv_id.satId, expected 217, is " + << last_msg_->stec_residuals[55].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[56].residual, -25304) + << "incorrect value for stec_residuals[56].residual, expected -25304, is " + << last_msg_->stec_residuals[56].residual; + EXPECT_EQ(last_msg_->stec_residuals[56].sv_id.constellation, 8) + << "incorrect value for stec_residuals[56].sv_id.constellation, expected " + "8, is " + << last_msg_->stec_residuals[56].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[56].sv_id.satId, 18) + << "incorrect value for stec_residuals[56].sv_id.satId, expected 18, is " + << last_msg_->stec_residuals[56].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[57].residual, -4024) + << "incorrect value for stec_residuals[57].residual, expected -4024, is " + << last_msg_->stec_residuals[57].residual; + EXPECT_EQ(last_msg_->stec_residuals[57].sv_id.constellation, 54) + << "incorrect value for stec_residuals[57].sv_id.constellation, expected " + "54, is " + << last_msg_->stec_residuals[57].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[57].sv_id.satId, 244) + << "incorrect value for stec_residuals[57].sv_id.satId, expected 244, is " + << last_msg_->stec_residuals[57].sv_id.satId; + EXPECT_EQ(last_msg_->stec_residuals[58].residual, -15505) + << "incorrect value for stec_residuals[58].residual, expected -15505, is " + << last_msg_->stec_residuals[58].residual; + EXPECT_EQ(last_msg_->stec_residuals[58].sv_id.constellation, 189) + << "incorrect value for stec_residuals[58].sv_id.constellation, expected " + "189, is " + << last_msg_->stec_residuals[58].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_residuals[58].sv_id.satId, 231) + << "incorrect value for stec_residuals[58].sv_id.satId, expected 231, is " + << last_msg_->stec_residuals[58].sv_id.satId; + EXPECT_EQ(last_msg_->tropo_delay_correction.hydro, 16250) + << "incorrect value for tropo_delay_correction.hydro, expected 16250, is " + << last_msg_->tropo_delay_correction.hydro; + EXPECT_EQ(last_msg_->tropo_delay_correction.wet, 101) + << "incorrect value for tropo_delay_correction.wet, expected 101, is " + << last_msg_->tropo_delay_correction.wet; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc new file mode 100644 index 0000000000..7f7adc0598 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClock.cc @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_orbit_clock_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_orbit_clock_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClock0, Test) { + uint8_t encoded_frame[] = { + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, 203, 212, 236, + 255, 152, 233, 207, 55, 94, 54, 58, 128, 68, 27, 117, 176, 110, 251, + 61, 244, 122, 50, 95, 52, 144, 232, 24, 10, 37, 127, 163, 66, 177, + 105, 156, 245, 10, 249, 107, 218, 17, 186, 56, 72, 14, 22, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_orbit_clock_t *test_msg = (msg_ssr_orbit_clock_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->along = -1334502588; + test_msg->c0 = -174298703; + test_msg->c1 = -630458102; + test_msg->c2 = 1211677201; + test_msg->cross = -197264530; + test_msg->dot_along = 169404560; + test_msg->dot_cross = 1118011173; + test_msg->dot_radial = 878654074; + test_msg->iod = 936372632; + test_msg->iod_ssr = 255; + test_msg->radial = -2143668642; + test_msg->sid.code = 212; + test_msg->sid.sat = 203; + test_msg->time.tow = 3479621715; + test_msg->time.wn = 7588; + test_msg->update_interval = 236; + + EXPECT_EQ(send_message(0x5dd, 58677, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 58677); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->along, -1334502588) + << "incorrect value for along, expected -1334502588, is " + << last_msg_->along; + EXPECT_EQ(last_msg_->c0, -174298703) + << "incorrect value for c0, expected -174298703, is " << last_msg_->c0; + EXPECT_EQ(last_msg_->c1, -630458102) + << "incorrect value for c1, expected -630458102, is " << last_msg_->c1; + EXPECT_EQ(last_msg_->c2, 1211677201) + << "incorrect value for c2, expected 1211677201, is " << last_msg_->c2; + EXPECT_EQ(last_msg_->cross, -197264530) + << "incorrect value for cross, expected -197264530, is " + << last_msg_->cross; + EXPECT_EQ(last_msg_->dot_along, 169404560) + << "incorrect value for dot_along, expected 169404560, is " + << last_msg_->dot_along; + EXPECT_EQ(last_msg_->dot_cross, 1118011173) + << "incorrect value for dot_cross, expected 1118011173, is " + << last_msg_->dot_cross; + EXPECT_EQ(last_msg_->dot_radial, 878654074) + << "incorrect value for dot_radial, expected 878654074, is " + << last_msg_->dot_radial; + EXPECT_EQ(last_msg_->iod, 936372632) + << "incorrect value for iod, expected 936372632, is " << last_msg_->iod; + EXPECT_EQ(last_msg_->iod_ssr, 255) + << "incorrect value for iod_ssr, expected 255, is " << last_msg_->iod_ssr; + EXPECT_EQ(last_msg_->radial, -2143668642) + << "incorrect value for radial, expected -2143668642, is " + << last_msg_->radial; + EXPECT_EQ(last_msg_->sid.code, 212) + << "incorrect value for sid.code, expected 212, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 203) + << "incorrect value for sid.sat, expected 203, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->time.tow, 3479621715) + << "incorrect value for time.tow, expected 3479621715, is " + << last_msg_->time.tow; + EXPECT_EQ(last_msg_->time.wn, 7588) + << "incorrect value for time.wn, expected 7588, is " + << last_msg_->time.wn; + EXPECT_EQ(last_msg_->update_interval, 236) + << "incorrect value for update_interval, expected 236, is " + << last_msg_->update_interval; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc new file mode 100644 index 0000000000..4472780ba9 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrOrbitClockDepA.cc @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_orbit_clock_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_orbit_clock_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrOrbitClockDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, + 194, 211, 193, 175, 161, 143, 254, 56, 63, 232, 7, 216, 69, 1, + 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, 151, 18, 171, + 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_orbit_clock_dep_a_t *test_msg = + (msg_ssr_orbit_clock_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->along = 132661048; + test_msg->c0 = -970026069; + test_msg->c1 = -503975083; + test_msg->c2 = -759858197; + test_msg->cross = 1845577176; + test_msg->dot_along = 72905755; + test_msg->dot_cross = 311886653; + test_msg->dot_radial = -1111196507; + test_msg->iod = 193; + test_msg->iod_ssr = 211; + test_msg->radial = -24141393; + test_msg->sid.code = 30; + test_msg->sid.sat = 1; + test_msg->time.tow = 3172954849; + test_msg->time.wn = 7723; + test_msg->update_interval = 194; + + EXPECT_EQ(send_message(0x5dc, 42529, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 42529); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->along, 132661048) + << "incorrect value for along, expected 132661048, is " + << last_msg_->along; + EXPECT_EQ(last_msg_->c0, -970026069) + << "incorrect value for c0, expected -970026069, is " << last_msg_->c0; + EXPECT_EQ(last_msg_->c1, -503975083) + << "incorrect value for c1, expected -503975083, is " << last_msg_->c1; + EXPECT_EQ(last_msg_->c2, -759858197) + << "incorrect value for c2, expected -759858197, is " << last_msg_->c2; + EXPECT_EQ(last_msg_->cross, 1845577176) + << "incorrect value for cross, expected 1845577176, is " + << last_msg_->cross; + EXPECT_EQ(last_msg_->dot_along, 72905755) + << "incorrect value for dot_along, expected 72905755, is " + << last_msg_->dot_along; + EXPECT_EQ(last_msg_->dot_cross, 311886653) + << "incorrect value for dot_cross, expected 311886653, is " + << last_msg_->dot_cross; + EXPECT_EQ(last_msg_->dot_radial, -1111196507) + << "incorrect value for dot_radial, expected -1111196507, is " + << last_msg_->dot_radial; + EXPECT_EQ(last_msg_->iod, 193) + << "incorrect value for iod, expected 193, is " << last_msg_->iod; + EXPECT_EQ(last_msg_->iod_ssr, 211) + << "incorrect value for iod_ssr, expected 211, is " << last_msg_->iod_ssr; + EXPECT_EQ(last_msg_->radial, -24141393) + << "incorrect value for radial, expected -24141393, is " + << last_msg_->radial; + EXPECT_EQ(last_msg_->sid.code, 30) + << "incorrect value for sid.code, expected 30, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 1) + << "incorrect value for sid.sat, expected 1, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->time.tow, 3172954849) + << "incorrect value for time.tow, expected 3172954849, is " + << last_msg_->time.tow; + EXPECT_EQ(last_msg_->time.wn, 7723) + << "incorrect value for time.wn, expected 7723, is " + << last_msg_->time.wn; + EXPECT_EQ(last_msg_->update_interval, 194) + << "incorrect value for update_interval, expected 194, is " + << last_msg_->update_interval; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc new file mode 100644 index 0000000000..1fb1b77329 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrPhaseBiases.cc @@ -0,0 +1,929 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_phase_biases_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_phase_biases_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrPhaseBiases0, Test) { + uint8_t encoded_frame[] = { + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, 177, + 230, 98, 209, 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, 177, 207, + 187, 33, 146, 58, 204, 164, 65, 114, 49, 248, 52, 8, 161, 44, 252, + 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, 155, 129, 143, 184, + 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, 203, 87, 34, 188, 141, + 104, 189, 102, 156, 252, 22, 251, 136, 49, 188, 157, 222, 245, 49, 132, + 16, 34, 142, 228, 85, 139, 221, 197, 235, 98, 74, 107, 70, 36, 38, + 239, 251, 112, 188, 124, 246, 141, 164, 150, 104, 7, 213, 44, 21, 244, + 192, 4, 143, 24, 42, 21, 84, 136, 7, 42, 118, 45, 23, 174, 175, + 129, 54, 169, 14, 213, 2, 197, 98, 60, 13, 207, 105, 100, 129, 72, + 136, 240, 140, 129, 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, + 242, 254, 215, 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, + 97, 36, 207, 92, 224, 26, 116, 155, 211, 165, 47, 102, 38, 67, 199, + 55, 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, 62, 147, 173, 173, + 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, 207, + 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, 75, 230, + 26, 213, 181, 56, 64, 97, 88, 255, 6, 147, 16, 89, 203, 27, 68, + 243, 230, 55, 242, 167, 169, 219, 240, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_phase_biases_t *test_msg = (msg_ssr_phase_biases_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[0].bias = -1311498533; + test_msg->biases[0].code = 29; + test_msg->biases[0].discontinuity_counter = 193; + test_msg->biases[0].integer_indicator = 250; + test_msg->biases[0].widelane_integer_indicator = 245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[1].bias = 1101319226; + test_msg->biases[1].code = 207; + test_msg->biases[1].discontinuity_counter = 146; + test_msg->biases[1].integer_indicator = 187; + test_msg->biases[1].widelane_integer_indicator = 33; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[2].bias = -64184056; + test_msg->biases[2].code = 114; + test_msg->biases[2].discontinuity_counter = 52; + test_msg->biases[2].integer_indicator = 49; + test_msg->biases[2].widelane_integer_indicator = 248; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[3].bias = -240298362; + test_msg->biases[3].code = 166; + test_msg->biases[3].discontinuity_counter = 124; + test_msg->biases[3].integer_indicator = 168; + test_msg->biases[3].widelane_integer_indicator = 232; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[4].bias = -1581740159; + test_msg->biases[4].code = 174; + test_msg->biases[4].discontinuity_counter = 155; + test_msg->biases[4].integer_indicator = 44; + test_msg->biases[4].widelane_integer_indicator = 142; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[5].bias = -1730297136; + test_msg->biases[5].code = 211; + test_msg->biases[5].discontinuity_counter = 189; + test_msg->biases[5].integer_indicator = 15; + test_msg->biases[5].widelane_integer_indicator = 36; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[6].bias = -1117221444; + test_msg->biases[6].code = 16; + test_msg->biases[6].discontinuity_counter = 34; + test_msg->biases[6].integer_indicator = 203; + test_msg->biases[6].widelane_integer_indicator = 87; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[7].bias = -1137604357; + test_msg->biases[7].code = 102; + test_msg->biases[7].discontinuity_counter = 22; + test_msg->biases[7].integer_indicator = 156; + test_msg->biases[7].widelane_integer_indicator = 252; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[8].bias = -1910370172; + test_msg->biases[8].code = 157; + test_msg->biases[8].discontinuity_counter = 49; + test_msg->biases[8].integer_indicator = 222; + test_msg->biases[8].widelane_integer_indicator = 245; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[9].bias = 1247996869; + test_msg->biases[9].code = 228; + test_msg->biases[9].discontinuity_counter = 221; + test_msg->biases[9].integer_indicator = 85; + test_msg->biases[9].widelane_integer_indicator = 139; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[10].bias = -1133446161; + test_msg->biases[10].code = 107; + test_msg->biases[10].discontinuity_counter = 38; + test_msg->biases[10].integer_indicator = 70; + test_msg->biases[10].widelane_integer_indicator = 36; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[11].bias = -720934762; + test_msg->biases[11].code = 124; + test_msg->biases[11].discontinuity_counter = 164; + test_msg->biases[11].integer_indicator = 246; + test_msg->biases[11].widelane_integer_indicator = 141; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[12].bias = 706252548; + test_msg->biases[12].code = 44; + test_msg->biases[12].discontinuity_counter = 192; + test_msg->biases[12].integer_indicator = 21; + test_msg->biases[12].widelane_integer_indicator = 244; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[13].bias = 388855338; + test_msg->biases[13].code = 21; + test_msg->biases[13].discontinuity_counter = 7; + test_msg->biases[13].integer_indicator = 84; + test_msg->biases[13].widelane_integer_indicator = 136; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[14].bias = 47517353; + test_msg->biases[14].code = 174; + test_msg->biases[14].discontinuity_counter = 54; + test_msg->biases[14].integer_indicator = 175; + test_msg->biases[14].widelane_integer_indicator = 129; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[15].bias = -2124125745; + test_msg->biases[15].code = 197; + test_msg->biases[15].discontinuity_counter = 13; + test_msg->biases[15].integer_indicator = 98; + test_msg->biases[15].widelane_integer_indicator = 60; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[16].bias = -1401812607; + test_msg->biases[16].code = 72; + test_msg->biases[16].discontinuity_counter = 140; + test_msg->biases[16].integer_indicator = 136; + test_msg->biases[16].widelane_integer_indicator = 240; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[17].bias = 60257151; + test_msg->biases[17].code = 151; + test_msg->biases[17].discontinuity_counter = 210; + test_msg->biases[17].integer_indicator = 150; + test_msg->biases[17].widelane_integer_indicator = 17; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[18].bias = 41820677; + test_msg->biases[18].code = 242; + test_msg->biases[18].discontinuity_counter = 14; + test_msg->biases[18].integer_indicator = 254; + test_msg->biases[18].widelane_integer_indicator = 215; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[19].bias = 1640616471; + test_msg->biases[19].code = 215; + test_msg->biases[19].discontinuity_counter = 176; + test_msg->biases[19].integer_indicator = 65; + test_msg->biases[19].widelane_integer_indicator = 38; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[20].bias = -744786918; + test_msg->biases[20].code = 36; + test_msg->biases[20].discontinuity_counter = 224; + test_msg->biases[20].integer_indicator = 207; + test_msg->biases[20].widelane_integer_indicator = 92; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[21].bias = 1966589763; + test_msg->biases[21].code = 165; + test_msg->biases[21].discontinuity_counter = 38; + test_msg->biases[21].integer_indicator = 47; + test_msg->biases[21].widelane_integer_indicator = 102; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[22].bias = 364366310; + test_msg->biases[22].code = 36; + test_msg->biases[22].discontinuity_counter = 1; + test_msg->biases[22].integer_indicator = 169; + test_msg->biases[22].widelane_integer_indicator = 33; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[23].bias = -1839031379; + test_msg->biases[23].code = 42; + test_msg->biases[23].discontinuity_counter = 173; + test_msg->biases[23].integer_indicator = 62; + test_msg->biases[23].widelane_integer_indicator = 147; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[24].bias = 31817639; + test_msg->biases[24].code = 231; + test_msg->biases[24].discontinuity_counter = 82; + test_msg->biases[24].integer_indicator = 167; + test_msg->biases[24].widelane_integer_indicator = 138; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[25].bias = -1619830156; + test_msg->biases[25].code = 2; + test_msg->biases[25].discontinuity_counter = 207; + test_msg->biases[25].integer_indicator = 127; + test_msg->biases[25].widelane_integer_indicator = 237; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[26].bias = -83375622; + test_msg->biases[26].code = 3; + test_msg->biases[26].discontinuity_counter = 145; + test_msg->biases[26].integer_indicator = 42; + test_msg->biases[26].widelane_integer_indicator = 66; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[27].bias = 1077458389; + test_msg->biases[27].code = 2; + test_msg->biases[27].discontinuity_counter = 26; + test_msg->biases[27].integer_indicator = 75; + test_msg->biases[27].widelane_integer_indicator = 230; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[28].bias = -883355501; + test_msg->biases[28].code = 97; + test_msg->biases[28].discontinuity_counter = 6; + test_msg->biases[28].integer_indicator = 88; + test_msg->biases[28].widelane_integer_indicator = 255; + if (sizeof(test_msg->biases) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->biases[0])); + } + test_msg->biases[29].bias = -1448611273; + test_msg->biases[29].code = 27; + test_msg->biases[29].discontinuity_counter = 230; + test_msg->biases[29].integer_indicator = 68; + test_msg->biases[29].widelane_integer_indicator = 243; + test_msg->dispersive_bias = 98; + test_msg->iod_ssr = 230; + test_msg->mw_consistency = 209; + test_msg->sid.code = 82; + test_msg->sid.sat = 169; + test_msg->time.tow = 210803409; + test_msg->time.wn = 42197; + test_msg->update_interval = 177; + test_msg->yaw = 5881; + test_msg->yaw_rate = 17; + + EXPECT_EQ(send_message(0x5e6, 52955, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 52955); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->biases[0].bias, -1311498533) + << "incorrect value for biases[0].bias, expected -1311498533, is " + << last_msg_->biases[0].bias; + EXPECT_EQ(last_msg_->biases[0].code, 29) + << "incorrect value for biases[0].code, expected 29, is " + << last_msg_->biases[0].code; + EXPECT_EQ(last_msg_->biases[0].discontinuity_counter, 193) + << "incorrect value for biases[0].discontinuity_counter, expected 193, " + "is " + << last_msg_->biases[0].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[0].integer_indicator, 250) + << "incorrect value for biases[0].integer_indicator, expected 250, is " + << last_msg_->biases[0].integer_indicator; + EXPECT_EQ(last_msg_->biases[0].widelane_integer_indicator, 245) + << "incorrect value for biases[0].widelane_integer_indicator, expected " + "245, is " + << last_msg_->biases[0].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[1].bias, 1101319226) + << "incorrect value for biases[1].bias, expected 1101319226, is " + << last_msg_->biases[1].bias; + EXPECT_EQ(last_msg_->biases[1].code, 207) + << "incorrect value for biases[1].code, expected 207, is " + << last_msg_->biases[1].code; + EXPECT_EQ(last_msg_->biases[1].discontinuity_counter, 146) + << "incorrect value for biases[1].discontinuity_counter, expected 146, " + "is " + << last_msg_->biases[1].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[1].integer_indicator, 187) + << "incorrect value for biases[1].integer_indicator, expected 187, is " + << last_msg_->biases[1].integer_indicator; + EXPECT_EQ(last_msg_->biases[1].widelane_integer_indicator, 33) + << "incorrect value for biases[1].widelane_integer_indicator, expected " + "33, is " + << last_msg_->biases[1].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[2].bias, -64184056) + << "incorrect value for biases[2].bias, expected -64184056, is " + << last_msg_->biases[2].bias; + EXPECT_EQ(last_msg_->biases[2].code, 114) + << "incorrect value for biases[2].code, expected 114, is " + << last_msg_->biases[2].code; + EXPECT_EQ(last_msg_->biases[2].discontinuity_counter, 52) + << "incorrect value for biases[2].discontinuity_counter, expected 52, is " + << last_msg_->biases[2].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[2].integer_indicator, 49) + << "incorrect value for biases[2].integer_indicator, expected 49, is " + << last_msg_->biases[2].integer_indicator; + EXPECT_EQ(last_msg_->biases[2].widelane_integer_indicator, 248) + << "incorrect value for biases[2].widelane_integer_indicator, expected " + "248, is " + << last_msg_->biases[2].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[3].bias, -240298362) + << "incorrect value for biases[3].bias, expected -240298362, is " + << last_msg_->biases[3].bias; + EXPECT_EQ(last_msg_->biases[3].code, 166) + << "incorrect value for biases[3].code, expected 166, is " + << last_msg_->biases[3].code; + EXPECT_EQ(last_msg_->biases[3].discontinuity_counter, 124) + << "incorrect value for biases[3].discontinuity_counter, expected 124, " + "is " + << last_msg_->biases[3].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[3].integer_indicator, 168) + << "incorrect value for biases[3].integer_indicator, expected 168, is " + << last_msg_->biases[3].integer_indicator; + EXPECT_EQ(last_msg_->biases[3].widelane_integer_indicator, 232) + << "incorrect value for biases[3].widelane_integer_indicator, expected " + "232, is " + << last_msg_->biases[3].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[4].bias, -1581740159) + << "incorrect value for biases[4].bias, expected -1581740159, is " + << last_msg_->biases[4].bias; + EXPECT_EQ(last_msg_->biases[4].code, 174) + << "incorrect value for biases[4].code, expected 174, is " + << last_msg_->biases[4].code; + EXPECT_EQ(last_msg_->biases[4].discontinuity_counter, 155) + << "incorrect value for biases[4].discontinuity_counter, expected 155, " + "is " + << last_msg_->biases[4].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[4].integer_indicator, 44) + << "incorrect value for biases[4].integer_indicator, expected 44, is " + << last_msg_->biases[4].integer_indicator; + EXPECT_EQ(last_msg_->biases[4].widelane_integer_indicator, 142) + << "incorrect value for biases[4].widelane_integer_indicator, expected " + "142, is " + << last_msg_->biases[4].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[5].bias, -1730297136) + << "incorrect value for biases[5].bias, expected -1730297136, is " + << last_msg_->biases[5].bias; + EXPECT_EQ(last_msg_->biases[5].code, 211) + << "incorrect value for biases[5].code, expected 211, is " + << last_msg_->biases[5].code; + EXPECT_EQ(last_msg_->biases[5].discontinuity_counter, 189) + << "incorrect value for biases[5].discontinuity_counter, expected 189, " + "is " + << last_msg_->biases[5].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[5].integer_indicator, 15) + << "incorrect value for biases[5].integer_indicator, expected 15, is " + << last_msg_->biases[5].integer_indicator; + EXPECT_EQ(last_msg_->biases[5].widelane_integer_indicator, 36) + << "incorrect value for biases[5].widelane_integer_indicator, expected " + "36, is " + << last_msg_->biases[5].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[6].bias, -1117221444) + << "incorrect value for biases[6].bias, expected -1117221444, is " + << last_msg_->biases[6].bias; + EXPECT_EQ(last_msg_->biases[6].code, 16) + << "incorrect value for biases[6].code, expected 16, is " + << last_msg_->biases[6].code; + EXPECT_EQ(last_msg_->biases[6].discontinuity_counter, 34) + << "incorrect value for biases[6].discontinuity_counter, expected 34, is " + << last_msg_->biases[6].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[6].integer_indicator, 203) + << "incorrect value for biases[6].integer_indicator, expected 203, is " + << last_msg_->biases[6].integer_indicator; + EXPECT_EQ(last_msg_->biases[6].widelane_integer_indicator, 87) + << "incorrect value for biases[6].widelane_integer_indicator, expected " + "87, is " + << last_msg_->biases[6].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[7].bias, -1137604357) + << "incorrect value for biases[7].bias, expected -1137604357, is " + << last_msg_->biases[7].bias; + EXPECT_EQ(last_msg_->biases[7].code, 102) + << "incorrect value for biases[7].code, expected 102, is " + << last_msg_->biases[7].code; + EXPECT_EQ(last_msg_->biases[7].discontinuity_counter, 22) + << "incorrect value for biases[7].discontinuity_counter, expected 22, is " + << last_msg_->biases[7].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[7].integer_indicator, 156) + << "incorrect value for biases[7].integer_indicator, expected 156, is " + << last_msg_->biases[7].integer_indicator; + EXPECT_EQ(last_msg_->biases[7].widelane_integer_indicator, 252) + << "incorrect value for biases[7].widelane_integer_indicator, expected " + "252, is " + << last_msg_->biases[7].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[8].bias, -1910370172) + << "incorrect value for biases[8].bias, expected -1910370172, is " + << last_msg_->biases[8].bias; + EXPECT_EQ(last_msg_->biases[8].code, 157) + << "incorrect value for biases[8].code, expected 157, is " + << last_msg_->biases[8].code; + EXPECT_EQ(last_msg_->biases[8].discontinuity_counter, 49) + << "incorrect value for biases[8].discontinuity_counter, expected 49, is " + << last_msg_->biases[8].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[8].integer_indicator, 222) + << "incorrect value for biases[8].integer_indicator, expected 222, is " + << last_msg_->biases[8].integer_indicator; + EXPECT_EQ(last_msg_->biases[8].widelane_integer_indicator, 245) + << "incorrect value for biases[8].widelane_integer_indicator, expected " + "245, is " + << last_msg_->biases[8].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[9].bias, 1247996869) + << "incorrect value for biases[9].bias, expected 1247996869, is " + << last_msg_->biases[9].bias; + EXPECT_EQ(last_msg_->biases[9].code, 228) + << "incorrect value for biases[9].code, expected 228, is " + << last_msg_->biases[9].code; + EXPECT_EQ(last_msg_->biases[9].discontinuity_counter, 221) + << "incorrect value for biases[9].discontinuity_counter, expected 221, " + "is " + << last_msg_->biases[9].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[9].integer_indicator, 85) + << "incorrect value for biases[9].integer_indicator, expected 85, is " + << last_msg_->biases[9].integer_indicator; + EXPECT_EQ(last_msg_->biases[9].widelane_integer_indicator, 139) + << "incorrect value for biases[9].widelane_integer_indicator, expected " + "139, is " + << last_msg_->biases[9].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[10].bias, -1133446161) + << "incorrect value for biases[10].bias, expected -1133446161, is " + << last_msg_->biases[10].bias; + EXPECT_EQ(last_msg_->biases[10].code, 107) + << "incorrect value for biases[10].code, expected 107, is " + << last_msg_->biases[10].code; + EXPECT_EQ(last_msg_->biases[10].discontinuity_counter, 38) + << "incorrect value for biases[10].discontinuity_counter, expected 38, " + "is " + << last_msg_->biases[10].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[10].integer_indicator, 70) + << "incorrect value for biases[10].integer_indicator, expected 70, is " + << last_msg_->biases[10].integer_indicator; + EXPECT_EQ(last_msg_->biases[10].widelane_integer_indicator, 36) + << "incorrect value for biases[10].widelane_integer_indicator, expected " + "36, is " + << last_msg_->biases[10].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[11].bias, -720934762) + << "incorrect value for biases[11].bias, expected -720934762, is " + << last_msg_->biases[11].bias; + EXPECT_EQ(last_msg_->biases[11].code, 124) + << "incorrect value for biases[11].code, expected 124, is " + << last_msg_->biases[11].code; + EXPECT_EQ(last_msg_->biases[11].discontinuity_counter, 164) + << "incorrect value for biases[11].discontinuity_counter, expected 164, " + "is " + << last_msg_->biases[11].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[11].integer_indicator, 246) + << "incorrect value for biases[11].integer_indicator, expected 246, is " + << last_msg_->biases[11].integer_indicator; + EXPECT_EQ(last_msg_->biases[11].widelane_integer_indicator, 141) + << "incorrect value for biases[11].widelane_integer_indicator, expected " + "141, is " + << last_msg_->biases[11].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[12].bias, 706252548) + << "incorrect value for biases[12].bias, expected 706252548, is " + << last_msg_->biases[12].bias; + EXPECT_EQ(last_msg_->biases[12].code, 44) + << "incorrect value for biases[12].code, expected 44, is " + << last_msg_->biases[12].code; + EXPECT_EQ(last_msg_->biases[12].discontinuity_counter, 192) + << "incorrect value for biases[12].discontinuity_counter, expected 192, " + "is " + << last_msg_->biases[12].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[12].integer_indicator, 21) + << "incorrect value for biases[12].integer_indicator, expected 21, is " + << last_msg_->biases[12].integer_indicator; + EXPECT_EQ(last_msg_->biases[12].widelane_integer_indicator, 244) + << "incorrect value for biases[12].widelane_integer_indicator, expected " + "244, is " + << last_msg_->biases[12].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[13].bias, 388855338) + << "incorrect value for biases[13].bias, expected 388855338, is " + << last_msg_->biases[13].bias; + EXPECT_EQ(last_msg_->biases[13].code, 21) + << "incorrect value for biases[13].code, expected 21, is " + << last_msg_->biases[13].code; + EXPECT_EQ(last_msg_->biases[13].discontinuity_counter, 7) + << "incorrect value for biases[13].discontinuity_counter, expected 7, is " + << last_msg_->biases[13].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[13].integer_indicator, 84) + << "incorrect value for biases[13].integer_indicator, expected 84, is " + << last_msg_->biases[13].integer_indicator; + EXPECT_EQ(last_msg_->biases[13].widelane_integer_indicator, 136) + << "incorrect value for biases[13].widelane_integer_indicator, expected " + "136, is " + << last_msg_->biases[13].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[14].bias, 47517353) + << "incorrect value for biases[14].bias, expected 47517353, is " + << last_msg_->biases[14].bias; + EXPECT_EQ(last_msg_->biases[14].code, 174) + << "incorrect value for biases[14].code, expected 174, is " + << last_msg_->biases[14].code; + EXPECT_EQ(last_msg_->biases[14].discontinuity_counter, 54) + << "incorrect value for biases[14].discontinuity_counter, expected 54, " + "is " + << last_msg_->biases[14].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[14].integer_indicator, 175) + << "incorrect value for biases[14].integer_indicator, expected 175, is " + << last_msg_->biases[14].integer_indicator; + EXPECT_EQ(last_msg_->biases[14].widelane_integer_indicator, 129) + << "incorrect value for biases[14].widelane_integer_indicator, expected " + "129, is " + << last_msg_->biases[14].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[15].bias, -2124125745) + << "incorrect value for biases[15].bias, expected -2124125745, is " + << last_msg_->biases[15].bias; + EXPECT_EQ(last_msg_->biases[15].code, 197) + << "incorrect value for biases[15].code, expected 197, is " + << last_msg_->biases[15].code; + EXPECT_EQ(last_msg_->biases[15].discontinuity_counter, 13) + << "incorrect value for biases[15].discontinuity_counter, expected 13, " + "is " + << last_msg_->biases[15].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[15].integer_indicator, 98) + << "incorrect value for biases[15].integer_indicator, expected 98, is " + << last_msg_->biases[15].integer_indicator; + EXPECT_EQ(last_msg_->biases[15].widelane_integer_indicator, 60) + << "incorrect value for biases[15].widelane_integer_indicator, expected " + "60, is " + << last_msg_->biases[15].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[16].bias, -1401812607) + << "incorrect value for biases[16].bias, expected -1401812607, is " + << last_msg_->biases[16].bias; + EXPECT_EQ(last_msg_->biases[16].code, 72) + << "incorrect value for biases[16].code, expected 72, is " + << last_msg_->biases[16].code; + EXPECT_EQ(last_msg_->biases[16].discontinuity_counter, 140) + << "incorrect value for biases[16].discontinuity_counter, expected 140, " + "is " + << last_msg_->biases[16].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[16].integer_indicator, 136) + << "incorrect value for biases[16].integer_indicator, expected 136, is " + << last_msg_->biases[16].integer_indicator; + EXPECT_EQ(last_msg_->biases[16].widelane_integer_indicator, 240) + << "incorrect value for biases[16].widelane_integer_indicator, expected " + "240, is " + << last_msg_->biases[16].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[17].bias, 60257151) + << "incorrect value for biases[17].bias, expected 60257151, is " + << last_msg_->biases[17].bias; + EXPECT_EQ(last_msg_->biases[17].code, 151) + << "incorrect value for biases[17].code, expected 151, is " + << last_msg_->biases[17].code; + EXPECT_EQ(last_msg_->biases[17].discontinuity_counter, 210) + << "incorrect value for biases[17].discontinuity_counter, expected 210, " + "is " + << last_msg_->biases[17].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[17].integer_indicator, 150) + << "incorrect value for biases[17].integer_indicator, expected 150, is " + << last_msg_->biases[17].integer_indicator; + EXPECT_EQ(last_msg_->biases[17].widelane_integer_indicator, 17) + << "incorrect value for biases[17].widelane_integer_indicator, expected " + "17, is " + << last_msg_->biases[17].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[18].bias, 41820677) + << "incorrect value for biases[18].bias, expected 41820677, is " + << last_msg_->biases[18].bias; + EXPECT_EQ(last_msg_->biases[18].code, 242) + << "incorrect value for biases[18].code, expected 242, is " + << last_msg_->biases[18].code; + EXPECT_EQ(last_msg_->biases[18].discontinuity_counter, 14) + << "incorrect value for biases[18].discontinuity_counter, expected 14, " + "is " + << last_msg_->biases[18].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[18].integer_indicator, 254) + << "incorrect value for biases[18].integer_indicator, expected 254, is " + << last_msg_->biases[18].integer_indicator; + EXPECT_EQ(last_msg_->biases[18].widelane_integer_indicator, 215) + << "incorrect value for biases[18].widelane_integer_indicator, expected " + "215, is " + << last_msg_->biases[18].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[19].bias, 1640616471) + << "incorrect value for biases[19].bias, expected 1640616471, is " + << last_msg_->biases[19].bias; + EXPECT_EQ(last_msg_->biases[19].code, 215) + << "incorrect value for biases[19].code, expected 215, is " + << last_msg_->biases[19].code; + EXPECT_EQ(last_msg_->biases[19].discontinuity_counter, 176) + << "incorrect value for biases[19].discontinuity_counter, expected 176, " + "is " + << last_msg_->biases[19].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[19].integer_indicator, 65) + << "incorrect value for biases[19].integer_indicator, expected 65, is " + << last_msg_->biases[19].integer_indicator; + EXPECT_EQ(last_msg_->biases[19].widelane_integer_indicator, 38) + << "incorrect value for biases[19].widelane_integer_indicator, expected " + "38, is " + << last_msg_->biases[19].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[20].bias, -744786918) + << "incorrect value for biases[20].bias, expected -744786918, is " + << last_msg_->biases[20].bias; + EXPECT_EQ(last_msg_->biases[20].code, 36) + << "incorrect value for biases[20].code, expected 36, is " + << last_msg_->biases[20].code; + EXPECT_EQ(last_msg_->biases[20].discontinuity_counter, 224) + << "incorrect value for biases[20].discontinuity_counter, expected 224, " + "is " + << last_msg_->biases[20].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[20].integer_indicator, 207) + << "incorrect value for biases[20].integer_indicator, expected 207, is " + << last_msg_->biases[20].integer_indicator; + EXPECT_EQ(last_msg_->biases[20].widelane_integer_indicator, 92) + << "incorrect value for biases[20].widelane_integer_indicator, expected " + "92, is " + << last_msg_->biases[20].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[21].bias, 1966589763) + << "incorrect value for biases[21].bias, expected 1966589763, is " + << last_msg_->biases[21].bias; + EXPECT_EQ(last_msg_->biases[21].code, 165) + << "incorrect value for biases[21].code, expected 165, is " + << last_msg_->biases[21].code; + EXPECT_EQ(last_msg_->biases[21].discontinuity_counter, 38) + << "incorrect value for biases[21].discontinuity_counter, expected 38, " + "is " + << last_msg_->biases[21].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[21].integer_indicator, 47) + << "incorrect value for biases[21].integer_indicator, expected 47, is " + << last_msg_->biases[21].integer_indicator; + EXPECT_EQ(last_msg_->biases[21].widelane_integer_indicator, 102) + << "incorrect value for biases[21].widelane_integer_indicator, expected " + "102, is " + << last_msg_->biases[21].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[22].bias, 364366310) + << "incorrect value for biases[22].bias, expected 364366310, is " + << last_msg_->biases[22].bias; + EXPECT_EQ(last_msg_->biases[22].code, 36) + << "incorrect value for biases[22].code, expected 36, is " + << last_msg_->biases[22].code; + EXPECT_EQ(last_msg_->biases[22].discontinuity_counter, 1) + << "incorrect value for biases[22].discontinuity_counter, expected 1, is " + << last_msg_->biases[22].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[22].integer_indicator, 169) + << "incorrect value for biases[22].integer_indicator, expected 169, is " + << last_msg_->biases[22].integer_indicator; + EXPECT_EQ(last_msg_->biases[22].widelane_integer_indicator, 33) + << "incorrect value for biases[22].widelane_integer_indicator, expected " + "33, is " + << last_msg_->biases[22].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[23].bias, -1839031379) + << "incorrect value for biases[23].bias, expected -1839031379, is " + << last_msg_->biases[23].bias; + EXPECT_EQ(last_msg_->biases[23].code, 42) + << "incorrect value for biases[23].code, expected 42, is " + << last_msg_->biases[23].code; + EXPECT_EQ(last_msg_->biases[23].discontinuity_counter, 173) + << "incorrect value for biases[23].discontinuity_counter, expected 173, " + "is " + << last_msg_->biases[23].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[23].integer_indicator, 62) + << "incorrect value for biases[23].integer_indicator, expected 62, is " + << last_msg_->biases[23].integer_indicator; + EXPECT_EQ(last_msg_->biases[23].widelane_integer_indicator, 147) + << "incorrect value for biases[23].widelane_integer_indicator, expected " + "147, is " + << last_msg_->biases[23].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[24].bias, 31817639) + << "incorrect value for biases[24].bias, expected 31817639, is " + << last_msg_->biases[24].bias; + EXPECT_EQ(last_msg_->biases[24].code, 231) + << "incorrect value for biases[24].code, expected 231, is " + << last_msg_->biases[24].code; + EXPECT_EQ(last_msg_->biases[24].discontinuity_counter, 82) + << "incorrect value for biases[24].discontinuity_counter, expected 82, " + "is " + << last_msg_->biases[24].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[24].integer_indicator, 167) + << "incorrect value for biases[24].integer_indicator, expected 167, is " + << last_msg_->biases[24].integer_indicator; + EXPECT_EQ(last_msg_->biases[24].widelane_integer_indicator, 138) + << "incorrect value for biases[24].widelane_integer_indicator, expected " + "138, is " + << last_msg_->biases[24].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[25].bias, -1619830156) + << "incorrect value for biases[25].bias, expected -1619830156, is " + << last_msg_->biases[25].bias; + EXPECT_EQ(last_msg_->biases[25].code, 2) + << "incorrect value for biases[25].code, expected 2, is " + << last_msg_->biases[25].code; + EXPECT_EQ(last_msg_->biases[25].discontinuity_counter, 207) + << "incorrect value for biases[25].discontinuity_counter, expected 207, " + "is " + << last_msg_->biases[25].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[25].integer_indicator, 127) + << "incorrect value for biases[25].integer_indicator, expected 127, is " + << last_msg_->biases[25].integer_indicator; + EXPECT_EQ(last_msg_->biases[25].widelane_integer_indicator, 237) + << "incorrect value for biases[25].widelane_integer_indicator, expected " + "237, is " + << last_msg_->biases[25].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[26].bias, -83375622) + << "incorrect value for biases[26].bias, expected -83375622, is " + << last_msg_->biases[26].bias; + EXPECT_EQ(last_msg_->biases[26].code, 3) + << "incorrect value for biases[26].code, expected 3, is " + << last_msg_->biases[26].code; + EXPECT_EQ(last_msg_->biases[26].discontinuity_counter, 145) + << "incorrect value for biases[26].discontinuity_counter, expected 145, " + "is " + << last_msg_->biases[26].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[26].integer_indicator, 42) + << "incorrect value for biases[26].integer_indicator, expected 42, is " + << last_msg_->biases[26].integer_indicator; + EXPECT_EQ(last_msg_->biases[26].widelane_integer_indicator, 66) + << "incorrect value for biases[26].widelane_integer_indicator, expected " + "66, is " + << last_msg_->biases[26].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[27].bias, 1077458389) + << "incorrect value for biases[27].bias, expected 1077458389, is " + << last_msg_->biases[27].bias; + EXPECT_EQ(last_msg_->biases[27].code, 2) + << "incorrect value for biases[27].code, expected 2, is " + << last_msg_->biases[27].code; + EXPECT_EQ(last_msg_->biases[27].discontinuity_counter, 26) + << "incorrect value for biases[27].discontinuity_counter, expected 26, " + "is " + << last_msg_->biases[27].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[27].integer_indicator, 75) + << "incorrect value for biases[27].integer_indicator, expected 75, is " + << last_msg_->biases[27].integer_indicator; + EXPECT_EQ(last_msg_->biases[27].widelane_integer_indicator, 230) + << "incorrect value for biases[27].widelane_integer_indicator, expected " + "230, is " + << last_msg_->biases[27].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[28].bias, -883355501) + << "incorrect value for biases[28].bias, expected -883355501, is " + << last_msg_->biases[28].bias; + EXPECT_EQ(last_msg_->biases[28].code, 97) + << "incorrect value for biases[28].code, expected 97, is " + << last_msg_->biases[28].code; + EXPECT_EQ(last_msg_->biases[28].discontinuity_counter, 6) + << "incorrect value for biases[28].discontinuity_counter, expected 6, is " + << last_msg_->biases[28].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[28].integer_indicator, 88) + << "incorrect value for biases[28].integer_indicator, expected 88, is " + << last_msg_->biases[28].integer_indicator; + EXPECT_EQ(last_msg_->biases[28].widelane_integer_indicator, 255) + << "incorrect value for biases[28].widelane_integer_indicator, expected " + "255, is " + << last_msg_->biases[28].widelane_integer_indicator; + EXPECT_EQ(last_msg_->biases[29].bias, -1448611273) + << "incorrect value for biases[29].bias, expected -1448611273, is " + << last_msg_->biases[29].bias; + EXPECT_EQ(last_msg_->biases[29].code, 27) + << "incorrect value for biases[29].code, expected 27, is " + << last_msg_->biases[29].code; + EXPECT_EQ(last_msg_->biases[29].discontinuity_counter, 230) + << "incorrect value for biases[29].discontinuity_counter, expected 230, " + "is " + << last_msg_->biases[29].discontinuity_counter; + EXPECT_EQ(last_msg_->biases[29].integer_indicator, 68) + << "incorrect value for biases[29].integer_indicator, expected 68, is " + << last_msg_->biases[29].integer_indicator; + EXPECT_EQ(last_msg_->biases[29].widelane_integer_indicator, 243) + << "incorrect value for biases[29].widelane_integer_indicator, expected " + "243, is " + << last_msg_->biases[29].widelane_integer_indicator; + EXPECT_EQ(last_msg_->dispersive_bias, 98) + << "incorrect value for dispersive_bias, expected 98, is " + << last_msg_->dispersive_bias; + EXPECT_EQ(last_msg_->iod_ssr, 230) + << "incorrect value for iod_ssr, expected 230, is " << last_msg_->iod_ssr; + EXPECT_EQ(last_msg_->mw_consistency, 209) + << "incorrect value for mw_consistency, expected 209, is " + << last_msg_->mw_consistency; + EXPECT_EQ(last_msg_->sid.code, 82) + << "incorrect value for sid.code, expected 82, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 169) + << "incorrect value for sid.sat, expected 169, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->time.tow, 210803409) + << "incorrect value for time.tow, expected 210803409, is " + << last_msg_->time.tow; + EXPECT_EQ(last_msg_->time.wn, 42197) + << "incorrect value for time.wn, expected 42197, is " + << last_msg_->time.wn; + EXPECT_EQ(last_msg_->update_interval, 177) + << "incorrect value for update_interval, expected 177, is " + << last_msg_->update_interval; + EXPECT_EQ(last_msg_->yaw, 5881) + << "incorrect value for yaw, expected 5881, is " << last_msg_->yaw; + EXPECT_EQ(last_msg_->yaw_rate, 17) + << "incorrect value for yaw_rate, expected 17, is " + << last_msg_->yaw_rate; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc new file mode 100644 index 0000000000..2bb41591ab --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrSatelliteApcDepA.cc @@ -0,0 +1,1602 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_satellite_apc_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_satellite_apc_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrSatelliteApcDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, 214, + 212, 4, 8, 33, 31, 80, 21, 4, 105, 225, 39, 139, 124, 149, 48, + 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, 49, 135, 97, 39, 90, + 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, 2, 102, 74, 149, + 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, 83, 188, 181, 194, 27, + 84, 226, 142, 123, 77, 217, 248, 67, 215, 129, 114, 138, 25, 240, 10, + 56, 76, 61, 161, 216, 22, 181, 174, 33, 13, 252, 236, 230, 196, 128, + 215, 239, 234, 179, 220, 44, 212, 57, 44, 173, 49, 36, 137, 248, 235, + 97, 112, 157, 139, 26, 115, 192, 31, 85, 127, 228, 81, 252, 219, 249, + 110, 147, 8, 161, 215, 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, + 74, 23, 4, 239, 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, + 99, 45, 83, 159, 11, 250, 135, 170, 42, 217, 199, 233, 42, 170, 78, + 206, 41, 43, 81, 247, 99, 198, 144, 2, 132, 2, 224, 220, 148, 58, + 85, 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, 37, + 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, 119, + 101, 252, 223, 144, 153, 50, 13, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_satellite_apc_dep_t *test_msg = + (msg_ssr_satellite_apc_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pco[0])); + } + test_msg->apc[0].pco[0] = -21547; + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pco[0])); + } + test_msg->apc[0].pco[1] = -10498; + if (sizeof(test_msg->apc[0].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pco[0])); + } + test_msg->apc[0].pco[2] = 1236; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[0] = 8; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[1] = 33; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[2] = 31; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[3] = 80; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[4] = 21; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[5] = 4; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[6] = 105; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[7] = -31; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[8] = 39; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[9] = -117; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[10] = 124; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[11] = -107; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[12] = 48; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[13] = 15; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[14] = -42; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[15] = -59; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[16] = -115; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[17] = 32; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[18] = 33; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[19] = -121; + if (sizeof(test_msg->apc[0].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0].pcv[0])); + } + test_msg->apc[0].pcv[20] = -106; + test_msg->apc[0].sat_info = 240; + test_msg->apc[0].sid.code = 169; + test_msg->apc[0].sid.sat = 203; + test_msg->apc[0].svn = 1102; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pco[0])); + } + test_msg->apc[1].pco[0] = 23079; + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pco[0])); + } + test_msg->apc[1].pco[1] = -22252; + if (sizeof(test_msg->apc[1].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pco[0])); + } + test_msg->apc[1].pco[2] = 12271; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[0] = -103; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[1] = -81; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[2] = 35; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[3] = -111; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[4] = -111; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[5] = 123; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[6] = -62; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[7] = 2; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[8] = 102; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[9] = 74; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[10] = -107; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[11] = 95; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[12] = -85; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[13] = -18; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[14] = -7; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[15] = 7; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[16] = -19; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[17] = -86; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[18] = 125; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[19] = 106; + if (sizeof(test_msg->apc[1].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[1].pcv[0])); + } + test_msg->apc[1].pcv[20] = -98; + test_msg->apc[1].sat_info = 49; + test_msg->apc[1].sid.code = 123; + test_msg->apc[1].sid.sat = 148; + test_msg->apc[1].svn = 24967; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pco[0])); + } + test_msg->apc[2].pco[0] = -7596; + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pco[0])); + } + test_msg->apc[2].pco[1] = 31630; + if (sizeof(test_msg->apc[2].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pco[0])); + } + test_msg->apc[2].pco[2] = -9907; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[0] = -8; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[1] = 67; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[2] = -41; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[3] = -127; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[4] = 114; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[5] = -118; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[6] = 25; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[7] = -16; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[8] = 10; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[9] = 56; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[10] = 76; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[11] = 61; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[12] = -95; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[13] = -40; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[14] = 22; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[15] = -75; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[16] = -82; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[17] = 33; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[18] = 13; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[19] = -4; + if (sizeof(test_msg->apc[2].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[2].pcv[0])); + } + test_msg->apc[2].pcv[20] = -20; + test_msg->apc[2].sat_info = 181; + test_msg->apc[2].sid.code = 188; + test_msg->apc[2].sid.sat = 83; + test_msg->apc[2].svn = 7106; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pco[0])); + } + test_msg->apc[3].pco[0] = -19478; + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pco[0])); + } + test_msg->apc[3].pco[1] = 11484; + if (sizeof(test_msg->apc[3].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pco[0])); + } + test_msg->apc[3].pco[2] = 14804; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[0] = 44; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[1] = -83; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[2] = 49; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[3] = 36; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[4] = -119; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[5] = -8; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[6] = -21; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[7] = 97; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[8] = 112; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[9] = -99; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[10] = -117; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[11] = 26; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[12] = 115; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[13] = -64; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[14] = 31; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[15] = 85; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[16] = 127; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[17] = -28; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[18] = 81; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[19] = -4; + if (sizeof(test_msg->apc[3].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[3].pcv[0])); + } + test_msg->apc[3].pcv[20] = -37; + test_msg->apc[3].sat_info = 128; + test_msg->apc[3].sid.code = 196; + test_msg->apc[3].sid.sat = 230; + test_msg->apc[3].svn = 61399; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pco[0])); + } + test_msg->apc[4].pco[0] = -11049; + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pco[0])); + } + test_msg->apc[4].pco[1] = 6580; + if (sizeof(test_msg->apc[4].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pco[0])); + } + test_msg->apc[4].pco[2] = -28589; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[0] = -9; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[1] = 12; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[2] = 27; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[3] = -57; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[4] = -83; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[5] = 74; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[6] = 23; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[7] = 4; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[8] = -17; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[9] = 103; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[10] = -33; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[11] = -36; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[12] = -117; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[13] = 91; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[14] = 127; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[15] = -42; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[16] = 86; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[17] = 48; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[18] = -53; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[19] = -28; + if (sizeof(test_msg->apc[4].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[4].pcv[0])); + } + test_msg->apc[4].pcv[20] = 99; + test_msg->apc[4].sat_info = 147; + test_msg->apc[4].sid.code = 110; + test_msg->apc[4].sid.sat = 249; + test_msg->apc[4].svn = 41224; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pco[0])); + } + test_msg->apc[5].pco[0] = -21881; + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pco[0])); + } + test_msg->apc[5].pco[1] = -9942; + if (sizeof(test_msg->apc[5].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pco[0])); + } + test_msg->apc[5].pco[2] = -5689; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[0] = 42; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[1] = -86; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[2] = 78; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[3] = -50; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[4] = 41; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[5] = 43; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[6] = 81; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[7] = -9; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[8] = 99; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[9] = -58; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[10] = -112; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[11] = 2; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[12] = -124; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[13] = 2; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[14] = -32; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[15] = -36; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[16] = -108; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[17] = 58; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[18] = 85; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[19] = -118; + if (sizeof(test_msg->apc[5].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[5].pcv[0])); + } + test_msg->apc[5].pcv[20] = -46; + test_msg->apc[5].sat_info = 159; + test_msg->apc[5].sid.code = 83; + test_msg->apc[5].sid.sat = 45; + test_msg->apc[5].svn = 64011; + if (sizeof(test_msg->apc) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[0])); + } + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pco[0])); + } + test_msg->apc[6].pco[0] = -14290; + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pco[0])); + } + test_msg->apc[6].pco[1] = 30340; + if (sizeof(test_msg->apc[6].pco) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pco[0])); + } + test_msg->apc[6].pco[2] = 3569; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[0] = 37; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[1] = 62; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[2] = 107; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[3] = -3; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[4] = -66; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[5] = -120; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[6] = 66; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[7] = 9; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[8] = 84; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[9] = -101; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[10] = 86; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[11] = -76; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[12] = 41; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[13] = -60; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[14] = 40; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[15] = 119; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[16] = 101; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[17] = -4; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[18] = -33; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[19] = -112; + if (sizeof(test_msg->apc[6].pcv) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->apc[6].pcv[0])); + } + test_msg->apc[6].pcv[20] = -103; + test_msg->apc[6].sat_info = 7; + test_msg->apc[6].sid.code = 158; + test_msg->apc[6].sid.sat = 200; + test_msg->apc[6].svn = 17310; + + EXPECT_EQ(send_message(0x604, 4920, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 4920); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->apc[0].pco[0], -21547) + << "incorrect value for apc[0].pco[0], expected -21547, is " + << last_msg_->apc[0].pco[0]; + EXPECT_EQ(last_msg_->apc[0].pco[1], -10498) + << "incorrect value for apc[0].pco[1], expected -10498, is " + << last_msg_->apc[0].pco[1]; + EXPECT_EQ(last_msg_->apc[0].pco[2], 1236) + << "incorrect value for apc[0].pco[2], expected 1236, is " + << last_msg_->apc[0].pco[2]; + EXPECT_EQ(last_msg_->apc[0].pcv[0], 8) + << "incorrect value for apc[0].pcv[0], expected 8, is " + << last_msg_->apc[0].pcv[0]; + EXPECT_EQ(last_msg_->apc[0].pcv[1], 33) + << "incorrect value for apc[0].pcv[1], expected 33, is " + << last_msg_->apc[0].pcv[1]; + EXPECT_EQ(last_msg_->apc[0].pcv[2], 31) + << "incorrect value for apc[0].pcv[2], expected 31, is " + << last_msg_->apc[0].pcv[2]; + EXPECT_EQ(last_msg_->apc[0].pcv[3], 80) + << "incorrect value for apc[0].pcv[3], expected 80, is " + << last_msg_->apc[0].pcv[3]; + EXPECT_EQ(last_msg_->apc[0].pcv[4], 21) + << "incorrect value for apc[0].pcv[4], expected 21, is " + << last_msg_->apc[0].pcv[4]; + EXPECT_EQ(last_msg_->apc[0].pcv[5], 4) + << "incorrect value for apc[0].pcv[5], expected 4, is " + << last_msg_->apc[0].pcv[5]; + EXPECT_EQ(last_msg_->apc[0].pcv[6], 105) + << "incorrect value for apc[0].pcv[6], expected 105, is " + << last_msg_->apc[0].pcv[6]; + EXPECT_EQ(last_msg_->apc[0].pcv[7], -31) + << "incorrect value for apc[0].pcv[7], expected -31, is " + << last_msg_->apc[0].pcv[7]; + EXPECT_EQ(last_msg_->apc[0].pcv[8], 39) + << "incorrect value for apc[0].pcv[8], expected 39, is " + << last_msg_->apc[0].pcv[8]; + EXPECT_EQ(last_msg_->apc[0].pcv[9], -117) + << "incorrect value for apc[0].pcv[9], expected -117, is " + << last_msg_->apc[0].pcv[9]; + EXPECT_EQ(last_msg_->apc[0].pcv[10], 124) + << "incorrect value for apc[0].pcv[10], expected 124, is " + << last_msg_->apc[0].pcv[10]; + EXPECT_EQ(last_msg_->apc[0].pcv[11], -107) + << "incorrect value for apc[0].pcv[11], expected -107, is " + << last_msg_->apc[0].pcv[11]; + EXPECT_EQ(last_msg_->apc[0].pcv[12], 48) + << "incorrect value for apc[0].pcv[12], expected 48, is " + << last_msg_->apc[0].pcv[12]; + EXPECT_EQ(last_msg_->apc[0].pcv[13], 15) + << "incorrect value for apc[0].pcv[13], expected 15, is " + << last_msg_->apc[0].pcv[13]; + EXPECT_EQ(last_msg_->apc[0].pcv[14], -42) + << "incorrect value for apc[0].pcv[14], expected -42, is " + << last_msg_->apc[0].pcv[14]; + EXPECT_EQ(last_msg_->apc[0].pcv[15], -59) + << "incorrect value for apc[0].pcv[15], expected -59, is " + << last_msg_->apc[0].pcv[15]; + EXPECT_EQ(last_msg_->apc[0].pcv[16], -115) + << "incorrect value for apc[0].pcv[16], expected -115, is " + << last_msg_->apc[0].pcv[16]; + EXPECT_EQ(last_msg_->apc[0].pcv[17], 32) + << "incorrect value for apc[0].pcv[17], expected 32, is " + << last_msg_->apc[0].pcv[17]; + EXPECT_EQ(last_msg_->apc[0].pcv[18], 33) + << "incorrect value for apc[0].pcv[18], expected 33, is " + << last_msg_->apc[0].pcv[18]; + EXPECT_EQ(last_msg_->apc[0].pcv[19], -121) + << "incorrect value for apc[0].pcv[19], expected -121, is " + << last_msg_->apc[0].pcv[19]; + EXPECT_EQ(last_msg_->apc[0].pcv[20], -106) + << "incorrect value for apc[0].pcv[20], expected -106, is " + << last_msg_->apc[0].pcv[20]; + EXPECT_EQ(last_msg_->apc[0].sat_info, 240) + << "incorrect value for apc[0].sat_info, expected 240, is " + << last_msg_->apc[0].sat_info; + EXPECT_EQ(last_msg_->apc[0].sid.code, 169) + << "incorrect value for apc[0].sid.code, expected 169, is " + << last_msg_->apc[0].sid.code; + EXPECT_EQ(last_msg_->apc[0].sid.sat, 203) + << "incorrect value for apc[0].sid.sat, expected 203, is " + << last_msg_->apc[0].sid.sat; + EXPECT_EQ(last_msg_->apc[0].svn, 1102) + << "incorrect value for apc[0].svn, expected 1102, is " + << last_msg_->apc[0].svn; + EXPECT_EQ(last_msg_->apc[1].pco[0], 23079) + << "incorrect value for apc[1].pco[0], expected 23079, is " + << last_msg_->apc[1].pco[0]; + EXPECT_EQ(last_msg_->apc[1].pco[1], -22252) + << "incorrect value for apc[1].pco[1], expected -22252, is " + << last_msg_->apc[1].pco[1]; + EXPECT_EQ(last_msg_->apc[1].pco[2], 12271) + << "incorrect value for apc[1].pco[2], expected 12271, is " + << last_msg_->apc[1].pco[2]; + EXPECT_EQ(last_msg_->apc[1].pcv[0], -103) + << "incorrect value for apc[1].pcv[0], expected -103, is " + << last_msg_->apc[1].pcv[0]; + EXPECT_EQ(last_msg_->apc[1].pcv[1], -81) + << "incorrect value for apc[1].pcv[1], expected -81, is " + << last_msg_->apc[1].pcv[1]; + EXPECT_EQ(last_msg_->apc[1].pcv[2], 35) + << "incorrect value for apc[1].pcv[2], expected 35, is " + << last_msg_->apc[1].pcv[2]; + EXPECT_EQ(last_msg_->apc[1].pcv[3], -111) + << "incorrect value for apc[1].pcv[3], expected -111, is " + << last_msg_->apc[1].pcv[3]; + EXPECT_EQ(last_msg_->apc[1].pcv[4], -111) + << "incorrect value for apc[1].pcv[4], expected -111, is " + << last_msg_->apc[1].pcv[4]; + EXPECT_EQ(last_msg_->apc[1].pcv[5], 123) + << "incorrect value for apc[1].pcv[5], expected 123, is " + << last_msg_->apc[1].pcv[5]; + EXPECT_EQ(last_msg_->apc[1].pcv[6], -62) + << "incorrect value for apc[1].pcv[6], expected -62, is " + << last_msg_->apc[1].pcv[6]; + EXPECT_EQ(last_msg_->apc[1].pcv[7], 2) + << "incorrect value for apc[1].pcv[7], expected 2, is " + << last_msg_->apc[1].pcv[7]; + EXPECT_EQ(last_msg_->apc[1].pcv[8], 102) + << "incorrect value for apc[1].pcv[8], expected 102, is " + << last_msg_->apc[1].pcv[8]; + EXPECT_EQ(last_msg_->apc[1].pcv[9], 74) + << "incorrect value for apc[1].pcv[9], expected 74, is " + << last_msg_->apc[1].pcv[9]; + EXPECT_EQ(last_msg_->apc[1].pcv[10], -107) + << "incorrect value for apc[1].pcv[10], expected -107, is " + << last_msg_->apc[1].pcv[10]; + EXPECT_EQ(last_msg_->apc[1].pcv[11], 95) + << "incorrect value for apc[1].pcv[11], expected 95, is " + << last_msg_->apc[1].pcv[11]; + EXPECT_EQ(last_msg_->apc[1].pcv[12], -85) + << "incorrect value for apc[1].pcv[12], expected -85, is " + << last_msg_->apc[1].pcv[12]; + EXPECT_EQ(last_msg_->apc[1].pcv[13], -18) + << "incorrect value for apc[1].pcv[13], expected -18, is " + << last_msg_->apc[1].pcv[13]; + EXPECT_EQ(last_msg_->apc[1].pcv[14], -7) + << "incorrect value for apc[1].pcv[14], expected -7, is " + << last_msg_->apc[1].pcv[14]; + EXPECT_EQ(last_msg_->apc[1].pcv[15], 7) + << "incorrect value for apc[1].pcv[15], expected 7, is " + << last_msg_->apc[1].pcv[15]; + EXPECT_EQ(last_msg_->apc[1].pcv[16], -19) + << "incorrect value for apc[1].pcv[16], expected -19, is " + << last_msg_->apc[1].pcv[16]; + EXPECT_EQ(last_msg_->apc[1].pcv[17], -86) + << "incorrect value for apc[1].pcv[17], expected -86, is " + << last_msg_->apc[1].pcv[17]; + EXPECT_EQ(last_msg_->apc[1].pcv[18], 125) + << "incorrect value for apc[1].pcv[18], expected 125, is " + << last_msg_->apc[1].pcv[18]; + EXPECT_EQ(last_msg_->apc[1].pcv[19], 106) + << "incorrect value for apc[1].pcv[19], expected 106, is " + << last_msg_->apc[1].pcv[19]; + EXPECT_EQ(last_msg_->apc[1].pcv[20], -98) + << "incorrect value for apc[1].pcv[20], expected -98, is " + << last_msg_->apc[1].pcv[20]; + EXPECT_EQ(last_msg_->apc[1].sat_info, 49) + << "incorrect value for apc[1].sat_info, expected 49, is " + << last_msg_->apc[1].sat_info; + EXPECT_EQ(last_msg_->apc[1].sid.code, 123) + << "incorrect value for apc[1].sid.code, expected 123, is " + << last_msg_->apc[1].sid.code; + EXPECT_EQ(last_msg_->apc[1].sid.sat, 148) + << "incorrect value for apc[1].sid.sat, expected 148, is " + << last_msg_->apc[1].sid.sat; + EXPECT_EQ(last_msg_->apc[1].svn, 24967) + << "incorrect value for apc[1].svn, expected 24967, is " + << last_msg_->apc[1].svn; + EXPECT_EQ(last_msg_->apc[2].pco[0], -7596) + << "incorrect value for apc[2].pco[0], expected -7596, is " + << last_msg_->apc[2].pco[0]; + EXPECT_EQ(last_msg_->apc[2].pco[1], 31630) + << "incorrect value for apc[2].pco[1], expected 31630, is " + << last_msg_->apc[2].pco[1]; + EXPECT_EQ(last_msg_->apc[2].pco[2], -9907) + << "incorrect value for apc[2].pco[2], expected -9907, is " + << last_msg_->apc[2].pco[2]; + EXPECT_EQ(last_msg_->apc[2].pcv[0], -8) + << "incorrect value for apc[2].pcv[0], expected -8, is " + << last_msg_->apc[2].pcv[0]; + EXPECT_EQ(last_msg_->apc[2].pcv[1], 67) + << "incorrect value for apc[2].pcv[1], expected 67, is " + << last_msg_->apc[2].pcv[1]; + EXPECT_EQ(last_msg_->apc[2].pcv[2], -41) + << "incorrect value for apc[2].pcv[2], expected -41, is " + << last_msg_->apc[2].pcv[2]; + EXPECT_EQ(last_msg_->apc[2].pcv[3], -127) + << "incorrect value for apc[2].pcv[3], expected -127, is " + << last_msg_->apc[2].pcv[3]; + EXPECT_EQ(last_msg_->apc[2].pcv[4], 114) + << "incorrect value for apc[2].pcv[4], expected 114, is " + << last_msg_->apc[2].pcv[4]; + EXPECT_EQ(last_msg_->apc[2].pcv[5], -118) + << "incorrect value for apc[2].pcv[5], expected -118, is " + << last_msg_->apc[2].pcv[5]; + EXPECT_EQ(last_msg_->apc[2].pcv[6], 25) + << "incorrect value for apc[2].pcv[6], expected 25, is " + << last_msg_->apc[2].pcv[6]; + EXPECT_EQ(last_msg_->apc[2].pcv[7], -16) + << "incorrect value for apc[2].pcv[7], expected -16, is " + << last_msg_->apc[2].pcv[7]; + EXPECT_EQ(last_msg_->apc[2].pcv[8], 10) + << "incorrect value for apc[2].pcv[8], expected 10, is " + << last_msg_->apc[2].pcv[8]; + EXPECT_EQ(last_msg_->apc[2].pcv[9], 56) + << "incorrect value for apc[2].pcv[9], expected 56, is " + << last_msg_->apc[2].pcv[9]; + EXPECT_EQ(last_msg_->apc[2].pcv[10], 76) + << "incorrect value for apc[2].pcv[10], expected 76, is " + << last_msg_->apc[2].pcv[10]; + EXPECT_EQ(last_msg_->apc[2].pcv[11], 61) + << "incorrect value for apc[2].pcv[11], expected 61, is " + << last_msg_->apc[2].pcv[11]; + EXPECT_EQ(last_msg_->apc[2].pcv[12], -95) + << "incorrect value for apc[2].pcv[12], expected -95, is " + << last_msg_->apc[2].pcv[12]; + EXPECT_EQ(last_msg_->apc[2].pcv[13], -40) + << "incorrect value for apc[2].pcv[13], expected -40, is " + << last_msg_->apc[2].pcv[13]; + EXPECT_EQ(last_msg_->apc[2].pcv[14], 22) + << "incorrect value for apc[2].pcv[14], expected 22, is " + << last_msg_->apc[2].pcv[14]; + EXPECT_EQ(last_msg_->apc[2].pcv[15], -75) + << "incorrect value for apc[2].pcv[15], expected -75, is " + << last_msg_->apc[2].pcv[15]; + EXPECT_EQ(last_msg_->apc[2].pcv[16], -82) + << "incorrect value for apc[2].pcv[16], expected -82, is " + << last_msg_->apc[2].pcv[16]; + EXPECT_EQ(last_msg_->apc[2].pcv[17], 33) + << "incorrect value for apc[2].pcv[17], expected 33, is " + << last_msg_->apc[2].pcv[17]; + EXPECT_EQ(last_msg_->apc[2].pcv[18], 13) + << "incorrect value for apc[2].pcv[18], expected 13, is " + << last_msg_->apc[2].pcv[18]; + EXPECT_EQ(last_msg_->apc[2].pcv[19], -4) + << "incorrect value for apc[2].pcv[19], expected -4, is " + << last_msg_->apc[2].pcv[19]; + EXPECT_EQ(last_msg_->apc[2].pcv[20], -20) + << "incorrect value for apc[2].pcv[20], expected -20, is " + << last_msg_->apc[2].pcv[20]; + EXPECT_EQ(last_msg_->apc[2].sat_info, 181) + << "incorrect value for apc[2].sat_info, expected 181, is " + << last_msg_->apc[2].sat_info; + EXPECT_EQ(last_msg_->apc[2].sid.code, 188) + << "incorrect value for apc[2].sid.code, expected 188, is " + << last_msg_->apc[2].sid.code; + EXPECT_EQ(last_msg_->apc[2].sid.sat, 83) + << "incorrect value for apc[2].sid.sat, expected 83, is " + << last_msg_->apc[2].sid.sat; + EXPECT_EQ(last_msg_->apc[2].svn, 7106) + << "incorrect value for apc[2].svn, expected 7106, is " + << last_msg_->apc[2].svn; + EXPECT_EQ(last_msg_->apc[3].pco[0], -19478) + << "incorrect value for apc[3].pco[0], expected -19478, is " + << last_msg_->apc[3].pco[0]; + EXPECT_EQ(last_msg_->apc[3].pco[1], 11484) + << "incorrect value for apc[3].pco[1], expected 11484, is " + << last_msg_->apc[3].pco[1]; + EXPECT_EQ(last_msg_->apc[3].pco[2], 14804) + << "incorrect value for apc[3].pco[2], expected 14804, is " + << last_msg_->apc[3].pco[2]; + EXPECT_EQ(last_msg_->apc[3].pcv[0], 44) + << "incorrect value for apc[3].pcv[0], expected 44, is " + << last_msg_->apc[3].pcv[0]; + EXPECT_EQ(last_msg_->apc[3].pcv[1], -83) + << "incorrect value for apc[3].pcv[1], expected -83, is " + << last_msg_->apc[3].pcv[1]; + EXPECT_EQ(last_msg_->apc[3].pcv[2], 49) + << "incorrect value for apc[3].pcv[2], expected 49, is " + << last_msg_->apc[3].pcv[2]; + EXPECT_EQ(last_msg_->apc[3].pcv[3], 36) + << "incorrect value for apc[3].pcv[3], expected 36, is " + << last_msg_->apc[3].pcv[3]; + EXPECT_EQ(last_msg_->apc[3].pcv[4], -119) + << "incorrect value for apc[3].pcv[4], expected -119, is " + << last_msg_->apc[3].pcv[4]; + EXPECT_EQ(last_msg_->apc[3].pcv[5], -8) + << "incorrect value for apc[3].pcv[5], expected -8, is " + << last_msg_->apc[3].pcv[5]; + EXPECT_EQ(last_msg_->apc[3].pcv[6], -21) + << "incorrect value for apc[3].pcv[6], expected -21, is " + << last_msg_->apc[3].pcv[6]; + EXPECT_EQ(last_msg_->apc[3].pcv[7], 97) + << "incorrect value for apc[3].pcv[7], expected 97, is " + << last_msg_->apc[3].pcv[7]; + EXPECT_EQ(last_msg_->apc[3].pcv[8], 112) + << "incorrect value for apc[3].pcv[8], expected 112, is " + << last_msg_->apc[3].pcv[8]; + EXPECT_EQ(last_msg_->apc[3].pcv[9], -99) + << "incorrect value for apc[3].pcv[9], expected -99, is " + << last_msg_->apc[3].pcv[9]; + EXPECT_EQ(last_msg_->apc[3].pcv[10], -117) + << "incorrect value for apc[3].pcv[10], expected -117, is " + << last_msg_->apc[3].pcv[10]; + EXPECT_EQ(last_msg_->apc[3].pcv[11], 26) + << "incorrect value for apc[3].pcv[11], expected 26, is " + << last_msg_->apc[3].pcv[11]; + EXPECT_EQ(last_msg_->apc[3].pcv[12], 115) + << "incorrect value for apc[3].pcv[12], expected 115, is " + << last_msg_->apc[3].pcv[12]; + EXPECT_EQ(last_msg_->apc[3].pcv[13], -64) + << "incorrect value for apc[3].pcv[13], expected -64, is " + << last_msg_->apc[3].pcv[13]; + EXPECT_EQ(last_msg_->apc[3].pcv[14], 31) + << "incorrect value for apc[3].pcv[14], expected 31, is " + << last_msg_->apc[3].pcv[14]; + EXPECT_EQ(last_msg_->apc[3].pcv[15], 85) + << "incorrect value for apc[3].pcv[15], expected 85, is " + << last_msg_->apc[3].pcv[15]; + EXPECT_EQ(last_msg_->apc[3].pcv[16], 127) + << "incorrect value for apc[3].pcv[16], expected 127, is " + << last_msg_->apc[3].pcv[16]; + EXPECT_EQ(last_msg_->apc[3].pcv[17], -28) + << "incorrect value for apc[3].pcv[17], expected -28, is " + << last_msg_->apc[3].pcv[17]; + EXPECT_EQ(last_msg_->apc[3].pcv[18], 81) + << "incorrect value for apc[3].pcv[18], expected 81, is " + << last_msg_->apc[3].pcv[18]; + EXPECT_EQ(last_msg_->apc[3].pcv[19], -4) + << "incorrect value for apc[3].pcv[19], expected -4, is " + << last_msg_->apc[3].pcv[19]; + EXPECT_EQ(last_msg_->apc[3].pcv[20], -37) + << "incorrect value for apc[3].pcv[20], expected -37, is " + << last_msg_->apc[3].pcv[20]; + EXPECT_EQ(last_msg_->apc[3].sat_info, 128) + << "incorrect value for apc[3].sat_info, expected 128, is " + << last_msg_->apc[3].sat_info; + EXPECT_EQ(last_msg_->apc[3].sid.code, 196) + << "incorrect value for apc[3].sid.code, expected 196, is " + << last_msg_->apc[3].sid.code; + EXPECT_EQ(last_msg_->apc[3].sid.sat, 230) + << "incorrect value for apc[3].sid.sat, expected 230, is " + << last_msg_->apc[3].sid.sat; + EXPECT_EQ(last_msg_->apc[3].svn, 61399) + << "incorrect value for apc[3].svn, expected 61399, is " + << last_msg_->apc[3].svn; + EXPECT_EQ(last_msg_->apc[4].pco[0], -11049) + << "incorrect value for apc[4].pco[0], expected -11049, is " + << last_msg_->apc[4].pco[0]; + EXPECT_EQ(last_msg_->apc[4].pco[1], 6580) + << "incorrect value for apc[4].pco[1], expected 6580, is " + << last_msg_->apc[4].pco[1]; + EXPECT_EQ(last_msg_->apc[4].pco[2], -28589) + << "incorrect value for apc[4].pco[2], expected -28589, is " + << last_msg_->apc[4].pco[2]; + EXPECT_EQ(last_msg_->apc[4].pcv[0], -9) + << "incorrect value for apc[4].pcv[0], expected -9, is " + << last_msg_->apc[4].pcv[0]; + EXPECT_EQ(last_msg_->apc[4].pcv[1], 12) + << "incorrect value for apc[4].pcv[1], expected 12, is " + << last_msg_->apc[4].pcv[1]; + EXPECT_EQ(last_msg_->apc[4].pcv[2], 27) + << "incorrect value for apc[4].pcv[2], expected 27, is " + << last_msg_->apc[4].pcv[2]; + EXPECT_EQ(last_msg_->apc[4].pcv[3], -57) + << "incorrect value for apc[4].pcv[3], expected -57, is " + << last_msg_->apc[4].pcv[3]; + EXPECT_EQ(last_msg_->apc[4].pcv[4], -83) + << "incorrect value for apc[4].pcv[4], expected -83, is " + << last_msg_->apc[4].pcv[4]; + EXPECT_EQ(last_msg_->apc[4].pcv[5], 74) + << "incorrect value for apc[4].pcv[5], expected 74, is " + << last_msg_->apc[4].pcv[5]; + EXPECT_EQ(last_msg_->apc[4].pcv[6], 23) + << "incorrect value for apc[4].pcv[6], expected 23, is " + << last_msg_->apc[4].pcv[6]; + EXPECT_EQ(last_msg_->apc[4].pcv[7], 4) + << "incorrect value for apc[4].pcv[7], expected 4, is " + << last_msg_->apc[4].pcv[7]; + EXPECT_EQ(last_msg_->apc[4].pcv[8], -17) + << "incorrect value for apc[4].pcv[8], expected -17, is " + << last_msg_->apc[4].pcv[8]; + EXPECT_EQ(last_msg_->apc[4].pcv[9], 103) + << "incorrect value for apc[4].pcv[9], expected 103, is " + << last_msg_->apc[4].pcv[9]; + EXPECT_EQ(last_msg_->apc[4].pcv[10], -33) + << "incorrect value for apc[4].pcv[10], expected -33, is " + << last_msg_->apc[4].pcv[10]; + EXPECT_EQ(last_msg_->apc[4].pcv[11], -36) + << "incorrect value for apc[4].pcv[11], expected -36, is " + << last_msg_->apc[4].pcv[11]; + EXPECT_EQ(last_msg_->apc[4].pcv[12], -117) + << "incorrect value for apc[4].pcv[12], expected -117, is " + << last_msg_->apc[4].pcv[12]; + EXPECT_EQ(last_msg_->apc[4].pcv[13], 91) + << "incorrect value for apc[4].pcv[13], expected 91, is " + << last_msg_->apc[4].pcv[13]; + EXPECT_EQ(last_msg_->apc[4].pcv[14], 127) + << "incorrect value for apc[4].pcv[14], expected 127, is " + << last_msg_->apc[4].pcv[14]; + EXPECT_EQ(last_msg_->apc[4].pcv[15], -42) + << "incorrect value for apc[4].pcv[15], expected -42, is " + << last_msg_->apc[4].pcv[15]; + EXPECT_EQ(last_msg_->apc[4].pcv[16], 86) + << "incorrect value for apc[4].pcv[16], expected 86, is " + << last_msg_->apc[4].pcv[16]; + EXPECT_EQ(last_msg_->apc[4].pcv[17], 48) + << "incorrect value for apc[4].pcv[17], expected 48, is " + << last_msg_->apc[4].pcv[17]; + EXPECT_EQ(last_msg_->apc[4].pcv[18], -53) + << "incorrect value for apc[4].pcv[18], expected -53, is " + << last_msg_->apc[4].pcv[18]; + EXPECT_EQ(last_msg_->apc[4].pcv[19], -28) + << "incorrect value for apc[4].pcv[19], expected -28, is " + << last_msg_->apc[4].pcv[19]; + EXPECT_EQ(last_msg_->apc[4].pcv[20], 99) + << "incorrect value for apc[4].pcv[20], expected 99, is " + << last_msg_->apc[4].pcv[20]; + EXPECT_EQ(last_msg_->apc[4].sat_info, 147) + << "incorrect value for apc[4].sat_info, expected 147, is " + << last_msg_->apc[4].sat_info; + EXPECT_EQ(last_msg_->apc[4].sid.code, 110) + << "incorrect value for apc[4].sid.code, expected 110, is " + << last_msg_->apc[4].sid.code; + EXPECT_EQ(last_msg_->apc[4].sid.sat, 249) + << "incorrect value for apc[4].sid.sat, expected 249, is " + << last_msg_->apc[4].sid.sat; + EXPECT_EQ(last_msg_->apc[4].svn, 41224) + << "incorrect value for apc[4].svn, expected 41224, is " + << last_msg_->apc[4].svn; + EXPECT_EQ(last_msg_->apc[5].pco[0], -21881) + << "incorrect value for apc[5].pco[0], expected -21881, is " + << last_msg_->apc[5].pco[0]; + EXPECT_EQ(last_msg_->apc[5].pco[1], -9942) + << "incorrect value for apc[5].pco[1], expected -9942, is " + << last_msg_->apc[5].pco[1]; + EXPECT_EQ(last_msg_->apc[5].pco[2], -5689) + << "incorrect value for apc[5].pco[2], expected -5689, is " + << last_msg_->apc[5].pco[2]; + EXPECT_EQ(last_msg_->apc[5].pcv[0], 42) + << "incorrect value for apc[5].pcv[0], expected 42, is " + << last_msg_->apc[5].pcv[0]; + EXPECT_EQ(last_msg_->apc[5].pcv[1], -86) + << "incorrect value for apc[5].pcv[1], expected -86, is " + << last_msg_->apc[5].pcv[1]; + EXPECT_EQ(last_msg_->apc[5].pcv[2], 78) + << "incorrect value for apc[5].pcv[2], expected 78, is " + << last_msg_->apc[5].pcv[2]; + EXPECT_EQ(last_msg_->apc[5].pcv[3], -50) + << "incorrect value for apc[5].pcv[3], expected -50, is " + << last_msg_->apc[5].pcv[3]; + EXPECT_EQ(last_msg_->apc[5].pcv[4], 41) + << "incorrect value for apc[5].pcv[4], expected 41, is " + << last_msg_->apc[5].pcv[4]; + EXPECT_EQ(last_msg_->apc[5].pcv[5], 43) + << "incorrect value for apc[5].pcv[5], expected 43, is " + << last_msg_->apc[5].pcv[5]; + EXPECT_EQ(last_msg_->apc[5].pcv[6], 81) + << "incorrect value for apc[5].pcv[6], expected 81, is " + << last_msg_->apc[5].pcv[6]; + EXPECT_EQ(last_msg_->apc[5].pcv[7], -9) + << "incorrect value for apc[5].pcv[7], expected -9, is " + << last_msg_->apc[5].pcv[7]; + EXPECT_EQ(last_msg_->apc[5].pcv[8], 99) + << "incorrect value for apc[5].pcv[8], expected 99, is " + << last_msg_->apc[5].pcv[8]; + EXPECT_EQ(last_msg_->apc[5].pcv[9], -58) + << "incorrect value for apc[5].pcv[9], expected -58, is " + << last_msg_->apc[5].pcv[9]; + EXPECT_EQ(last_msg_->apc[5].pcv[10], -112) + << "incorrect value for apc[5].pcv[10], expected -112, is " + << last_msg_->apc[5].pcv[10]; + EXPECT_EQ(last_msg_->apc[5].pcv[11], 2) + << "incorrect value for apc[5].pcv[11], expected 2, is " + << last_msg_->apc[5].pcv[11]; + EXPECT_EQ(last_msg_->apc[5].pcv[12], -124) + << "incorrect value for apc[5].pcv[12], expected -124, is " + << last_msg_->apc[5].pcv[12]; + EXPECT_EQ(last_msg_->apc[5].pcv[13], 2) + << "incorrect value for apc[5].pcv[13], expected 2, is " + << last_msg_->apc[5].pcv[13]; + EXPECT_EQ(last_msg_->apc[5].pcv[14], -32) + << "incorrect value for apc[5].pcv[14], expected -32, is " + << last_msg_->apc[5].pcv[14]; + EXPECT_EQ(last_msg_->apc[5].pcv[15], -36) + << "incorrect value for apc[5].pcv[15], expected -36, is " + << last_msg_->apc[5].pcv[15]; + EXPECT_EQ(last_msg_->apc[5].pcv[16], -108) + << "incorrect value for apc[5].pcv[16], expected -108, is " + << last_msg_->apc[5].pcv[16]; + EXPECT_EQ(last_msg_->apc[5].pcv[17], 58) + << "incorrect value for apc[5].pcv[17], expected 58, is " + << last_msg_->apc[5].pcv[17]; + EXPECT_EQ(last_msg_->apc[5].pcv[18], 85) + << "incorrect value for apc[5].pcv[18], expected 85, is " + << last_msg_->apc[5].pcv[18]; + EXPECT_EQ(last_msg_->apc[5].pcv[19], -118) + << "incorrect value for apc[5].pcv[19], expected -118, is " + << last_msg_->apc[5].pcv[19]; + EXPECT_EQ(last_msg_->apc[5].pcv[20], -46) + << "incorrect value for apc[5].pcv[20], expected -46, is " + << last_msg_->apc[5].pcv[20]; + EXPECT_EQ(last_msg_->apc[5].sat_info, 159) + << "incorrect value for apc[5].sat_info, expected 159, is " + << last_msg_->apc[5].sat_info; + EXPECT_EQ(last_msg_->apc[5].sid.code, 83) + << "incorrect value for apc[5].sid.code, expected 83, is " + << last_msg_->apc[5].sid.code; + EXPECT_EQ(last_msg_->apc[5].sid.sat, 45) + << "incorrect value for apc[5].sid.sat, expected 45, is " + << last_msg_->apc[5].sid.sat; + EXPECT_EQ(last_msg_->apc[5].svn, 64011) + << "incorrect value for apc[5].svn, expected 64011, is " + << last_msg_->apc[5].svn; + EXPECT_EQ(last_msg_->apc[6].pco[0], -14290) + << "incorrect value for apc[6].pco[0], expected -14290, is " + << last_msg_->apc[6].pco[0]; + EXPECT_EQ(last_msg_->apc[6].pco[1], 30340) + << "incorrect value for apc[6].pco[1], expected 30340, is " + << last_msg_->apc[6].pco[1]; + EXPECT_EQ(last_msg_->apc[6].pco[2], 3569) + << "incorrect value for apc[6].pco[2], expected 3569, is " + << last_msg_->apc[6].pco[2]; + EXPECT_EQ(last_msg_->apc[6].pcv[0], 37) + << "incorrect value for apc[6].pcv[0], expected 37, is " + << last_msg_->apc[6].pcv[0]; + EXPECT_EQ(last_msg_->apc[6].pcv[1], 62) + << "incorrect value for apc[6].pcv[1], expected 62, is " + << last_msg_->apc[6].pcv[1]; + EXPECT_EQ(last_msg_->apc[6].pcv[2], 107) + << "incorrect value for apc[6].pcv[2], expected 107, is " + << last_msg_->apc[6].pcv[2]; + EXPECT_EQ(last_msg_->apc[6].pcv[3], -3) + << "incorrect value for apc[6].pcv[3], expected -3, is " + << last_msg_->apc[6].pcv[3]; + EXPECT_EQ(last_msg_->apc[6].pcv[4], -66) + << "incorrect value for apc[6].pcv[4], expected -66, is " + << last_msg_->apc[6].pcv[4]; + EXPECT_EQ(last_msg_->apc[6].pcv[5], -120) + << "incorrect value for apc[6].pcv[5], expected -120, is " + << last_msg_->apc[6].pcv[5]; + EXPECT_EQ(last_msg_->apc[6].pcv[6], 66) + << "incorrect value for apc[6].pcv[6], expected 66, is " + << last_msg_->apc[6].pcv[6]; + EXPECT_EQ(last_msg_->apc[6].pcv[7], 9) + << "incorrect value for apc[6].pcv[7], expected 9, is " + << last_msg_->apc[6].pcv[7]; + EXPECT_EQ(last_msg_->apc[6].pcv[8], 84) + << "incorrect value for apc[6].pcv[8], expected 84, is " + << last_msg_->apc[6].pcv[8]; + EXPECT_EQ(last_msg_->apc[6].pcv[9], -101) + << "incorrect value for apc[6].pcv[9], expected -101, is " + << last_msg_->apc[6].pcv[9]; + EXPECT_EQ(last_msg_->apc[6].pcv[10], 86) + << "incorrect value for apc[6].pcv[10], expected 86, is " + << last_msg_->apc[6].pcv[10]; + EXPECT_EQ(last_msg_->apc[6].pcv[11], -76) + << "incorrect value for apc[6].pcv[11], expected -76, is " + << last_msg_->apc[6].pcv[11]; + EXPECT_EQ(last_msg_->apc[6].pcv[12], 41) + << "incorrect value for apc[6].pcv[12], expected 41, is " + << last_msg_->apc[6].pcv[12]; + EXPECT_EQ(last_msg_->apc[6].pcv[13], -60) + << "incorrect value for apc[6].pcv[13], expected -60, is " + << last_msg_->apc[6].pcv[13]; + EXPECT_EQ(last_msg_->apc[6].pcv[14], 40) + << "incorrect value for apc[6].pcv[14], expected 40, is " + << last_msg_->apc[6].pcv[14]; + EXPECT_EQ(last_msg_->apc[6].pcv[15], 119) + << "incorrect value for apc[6].pcv[15], expected 119, is " + << last_msg_->apc[6].pcv[15]; + EXPECT_EQ(last_msg_->apc[6].pcv[16], 101) + << "incorrect value for apc[6].pcv[16], expected 101, is " + << last_msg_->apc[6].pcv[16]; + EXPECT_EQ(last_msg_->apc[6].pcv[17], -4) + << "incorrect value for apc[6].pcv[17], expected -4, is " + << last_msg_->apc[6].pcv[17]; + EXPECT_EQ(last_msg_->apc[6].pcv[18], -33) + << "incorrect value for apc[6].pcv[18], expected -33, is " + << last_msg_->apc[6].pcv[18]; + EXPECT_EQ(last_msg_->apc[6].pcv[19], -112) + << "incorrect value for apc[6].pcv[19], expected -112, is " + << last_msg_->apc[6].pcv[19]; + EXPECT_EQ(last_msg_->apc[6].pcv[20], -103) + << "incorrect value for apc[6].pcv[20], expected -103, is " + << last_msg_->apc[6].pcv[20]; + EXPECT_EQ(last_msg_->apc[6].sat_info, 7) + << "incorrect value for apc[6].sat_info, expected 7, is " + << last_msg_->apc[6].sat_info; + EXPECT_EQ(last_msg_->apc[6].sid.code, 158) + << "incorrect value for apc[6].sid.code, expected 158, is " + << last_msg_->apc[6].sid.code; + EXPECT_EQ(last_msg_->apc[6].sid.sat, 200) + << "incorrect value for apc[6].sid.sat, expected 200, is " + << last_msg_->apc[6].sid.sat; + EXPECT_EQ(last_msg_->apc[6].svn, 17310) + << "incorrect value for apc[6].svn, expected 17310, is " + << last_msg_->apc[6].svn; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc new file mode 100644 index 0000000000..b9e80fe81f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDep.cc @@ -0,0 +1,1367 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_stec_correction_dep_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_stec_correction_dep_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDep0, Test) { + uint8_t encoded_frame[] = { + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, 119, + 156, 157, 112, 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, 3, 14, + 8, 70, 12, 44, 53, 181, 90, 174, 247, 150, 58, 172, 247, 179, 119, + 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, 53, 222, 187, 146, + 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, 91, 234, 0, 213, 139, + 95, 179, 50, 21, 74, 174, 169, 61, 86, 91, 142, 51, 108, 9, 38, + 225, 146, 101, 73, 139, 56, 117, 82, 37, 213, 108, 205, 93, 18, 19, + 195, 33, 202, 87, 206, 178, 125, 188, 119, 56, 69, 150, 150, 76, 3, + 131, 18, 73, 208, 72, 232, 8, 250, 203, 178, 170, 163, 252, 86, 49, + 247, 178, 166, 56, 31, 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, + 124, 169, 121, 158, 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, + 110, 23, 12, 241, 88, 69, 239, 252, 57, 93, 44, 201, 216, 173, 242, + 178, 17, 5, 223, 169, 192, 3, 77, 107, 2, 144, 233, 14, 88, 32, + 209, 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, 126, + 217, 79, 171, 239, 237, 188, 238, 112, 201, 118, 141, 18, 163, 103, 35, + 63, 21, 82, 129, 18, 117, 85, 190, 79, 210, 215, 227, 177, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_stec_correction_dep_t *test_msg = + (msg_ssr_stec_correction_dep_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.iod_atmo = 60; + test_msg->header.num_msgs = 157; + test_msg->header.seq_num = 112; + test_msg->header.tile_id = 30066; + test_msg->header.tile_set_id = 58526; + test_msg->header.time.tow = 714907186; + test_msg->header.time.wn = 40055; + test_msg->header.update_interval = 47; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[0] = -5289; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[1] = -20141; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[2] = 966; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[3] = 2062; + test_msg->stec_sat_list[0].stec_quality_indicator = 70; + test_msg->stec_sat_list[0].sv_id.constellation = 40; + test_msg->stec_sat_list[0].sv_id.satId = 132; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[0] = -19147; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[1] = -20902; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[2] = -26889; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[3] = -21446; + test_msg->stec_sat_list[1].stec_quality_indicator = 44; + test_msg->stec_sat_list[1].sv_id.constellation = 12; + test_msg->stec_sat_list[1].sv_id.satId = 70; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[0] = 32176; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[1] = -20220; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[2] = 29157; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[3] = 19726; + test_msg->stec_sat_list[2].stec_quality_indicator = 119; + test_msg->stec_sat_list[2].sv_id.constellation = 179; + test_msg->stec_sat_list[2].sv_id.satId = 247; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[0] = -8651; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[1] = -27973; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[2] = 23546; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[3] = -10284; + test_msg->stec_sat_list[3].stec_quality_indicator = 23; + test_msg->stec_sat_list[3].sv_id.constellation = 185; + test_msg->stec_sat_list[3].sv_id.satId = 153; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[0] = 27486; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[1] = 23329; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[2] = 234; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[3] = -29739; + test_msg->stec_sat_list[4].stec_quality_indicator = 250; + test_msg->stec_sat_list[4].sv_id.constellation = 107; + test_msg->stec_sat_list[4].sv_id.satId = 14; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[0] = 18965; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[1] = -22098; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[2] = 22077; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[3] = -29093; + test_msg->stec_sat_list[5].stec_quality_indicator = 50; + test_msg->stec_sat_list[5].sv_id.constellation = 179; + test_msg->stec_sat_list[5].sv_id.satId = 95; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[0] = -7898; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[1] = 26002; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[2] = -29879; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[3] = 30008; + test_msg->stec_sat_list[6].stec_quality_indicator = 9; + test_msg->stec_sat_list[6].sv_id.constellation = 108; + test_msg->stec_sat_list[6].sv_id.satId = 51; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[0] = -12948; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[1] = 4701; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[2] = -15597; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[3] = -13791; + test_msg->stec_sat_list[7].stec_quality_indicator = 213; + test_msg->stec_sat_list[7].sv_id.constellation = 37; + test_msg->stec_sat_list[7].sv_id.satId = 82; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[0] = -17283; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[1] = 14455; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[2] = -27067; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[3] = 19606; + test_msg->stec_sat_list[8].stec_quality_indicator = 178; + test_msg->stec_sat_list[8].sv_id.constellation = 206; + test_msg->stec_sat_list[8].sv_id.satId = 87; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[0] = -12215; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[1] = -6072; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[2] = -1528; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[3] = -19765; + test_msg->stec_sat_list[9].stec_quality_indicator = 18; + test_msg->stec_sat_list[9].sv_id.constellation = 131; + test_msg->stec_sat_list[9].sv_id.satId = 3; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[0] = 12630; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[1] = -19721; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[2] = 14502; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[3] = 2591; + test_msg->stec_sat_list[10].stec_quality_indicator = 252; + test_msg->stec_sat_list[10].sv_id.constellation = 163; + test_msg->stec_sat_list[10].sv_id.satId = 170; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[0] = -23340; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[1] = -24063; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[2] = 4650; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[3] = -22148; + test_msg->stec_sat_list[11].stec_quality_indicator = 241; + test_msg->stec_sat_list[11].sv_id.constellation = 213; + test_msg->stec_sat_list[11].sv_id.satId = 119; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[0] = 5944; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[1] = 32142; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[2] = 30760; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[3] = 11587; + test_msg->stec_sat_list[12].stec_quality_indicator = 26; + test_msg->stec_sat_list[12].sv_id.constellation = 158; + test_msg->stec_sat_list[12].sv_id.satId = 121; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[0] = 3095; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[1] = 22769; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[2] = -4283; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[3] = 14844; + test_msg->stec_sat_list[13].stec_quality_indicator = 110; + test_msg->stec_sat_list[13].sv_id.constellation = 235; + test_msg->stec_sat_list[13].sv_id.satId = 126; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[0] = -21032; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[1] = -19726; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[2] = 1297; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[3] = -22049; + test_msg->stec_sat_list[14].stec_quality_indicator = 201; + test_msg->stec_sat_list[14].sv_id.constellation = 44; + test_msg->stec_sat_list[14].sv_id.satId = 93; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[0] = 619; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[1] = -5744; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[2] = 22542; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[3] = -12000; + test_msg->stec_sat_list[15].stec_quality_indicator = 77; + test_msg->stec_sat_list[15].sv_id.constellation = 3; + test_msg->stec_sat_list[15].sv_id.satId = 192; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[0] = 10651; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[1] = -2889; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[2] = 21150; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[3] = 26421; + test_msg->stec_sat_list[16].stec_quality_indicator = 123; + test_msg->stec_sat_list[16].sv_id.constellation = 17; + test_msg->stec_sat_list[16].sv_id.satId = 1; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[0] = -19165; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[1] = 30229; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[2] = -1282; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[3] = -18382; + test_msg->stec_sat_list[17].stec_quality_indicator = 185; + test_msg->stec_sat_list[17].sv_id.constellation = 202; + test_msg->stec_sat_list[17].sv_id.satId = 14; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[0] = -23752; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[1] = 32433; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[2] = 20441; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[3] = -4181; + test_msg->stec_sat_list[18].stec_quality_indicator = 45; + test_msg->stec_sat_list[18].sv_id.constellation = 31; + test_msg->stec_sat_list[18].sv_id.satId = 50; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[0] = -13968; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[1] = -29322; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[2] = -23790; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[3] = 9063; + test_msg->stec_sat_list[19].stec_quality_indicator = 238; + test_msg->stec_sat_list[19].sv_id.constellation = 188; + test_msg->stec_sat_list[19].sv_id.satId = 237; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[0] = 4737; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[1] = 21877; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[2] = 20414; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[3] = -10286; + test_msg->stec_sat_list[20].stec_quality_indicator = 82; + test_msg->stec_sat_list[20].sv_id.constellation = 21; + test_msg->stec_sat_list[20].sv_id.satId = 63; + + EXPECT_EQ(send_message(0x5fb, 38860, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 38860); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.iod_atmo, 60) + << "incorrect value for header.iod_atmo, expected 60, is " + << last_msg_->header.iod_atmo; + EXPECT_EQ(last_msg_->header.num_msgs, 157) + << "incorrect value for header.num_msgs, expected 157, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.seq_num, 112) + << "incorrect value for header.seq_num, expected 112, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->header.tile_id, 30066) + << "incorrect value for header.tile_id, expected 30066, is " + << last_msg_->header.tile_id; + EXPECT_EQ(last_msg_->header.tile_set_id, 58526) + << "incorrect value for header.tile_set_id, expected 58526, is " + << last_msg_->header.tile_set_id; + EXPECT_EQ(last_msg_->header.time.tow, 714907186) + << "incorrect value for header.time.tow, expected 714907186, is " + << last_msg_->header.time.tow; + EXPECT_EQ(last_msg_->header.time.wn, 40055) + << "incorrect value for header.time.wn, expected 40055, is " + << last_msg_->header.time.wn; + EXPECT_EQ(last_msg_->header.update_interval, 47) + << "incorrect value for header.update_interval, expected 47, is " + << last_msg_->header.update_interval; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[0], -5289) + << "incorrect value for stec_sat_list[0].stec_coeff[0], expected -5289, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[1], -20141) + << "incorrect value for stec_sat_list[0].stec_coeff[1], expected -20141, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[2], 966) + << "incorrect value for stec_sat_list[0].stec_coeff[2], expected 966, is " + << last_msg_->stec_sat_list[0].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[3], 2062) + << "incorrect value for stec_sat_list[0].stec_coeff[3], expected 2062, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_quality_indicator, 70) + << "incorrect value for stec_sat_list[0].stec_quality_indicator, " + "expected 70, is " + << last_msg_->stec_sat_list[0].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[0].sv_id.constellation, 40) + << "incorrect value for stec_sat_list[0].sv_id.constellation, expected " + "40, is " + << last_msg_->stec_sat_list[0].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[0].sv_id.satId, 132) + << "incorrect value for stec_sat_list[0].sv_id.satId, expected 132, is " + << last_msg_->stec_sat_list[0].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[0], -19147) + << "incorrect value for stec_sat_list[1].stec_coeff[0], expected -19147, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[1], -20902) + << "incorrect value for stec_sat_list[1].stec_coeff[1], expected -20902, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[2], -26889) + << "incorrect value for stec_sat_list[1].stec_coeff[2], expected -26889, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[3], -21446) + << "incorrect value for stec_sat_list[1].stec_coeff[3], expected -21446, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_quality_indicator, 44) + << "incorrect value for stec_sat_list[1].stec_quality_indicator, " + "expected 44, is " + << last_msg_->stec_sat_list[1].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[1].sv_id.constellation, 12) + << "incorrect value for stec_sat_list[1].sv_id.constellation, expected " + "12, is " + << last_msg_->stec_sat_list[1].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[1].sv_id.satId, 70) + << "incorrect value for stec_sat_list[1].sv_id.satId, expected 70, is " + << last_msg_->stec_sat_list[1].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[0], 32176) + << "incorrect value for stec_sat_list[2].stec_coeff[0], expected 32176, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[1], -20220) + << "incorrect value for stec_sat_list[2].stec_coeff[1], expected -20220, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[2], 29157) + << "incorrect value for stec_sat_list[2].stec_coeff[2], expected 29157, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[3], 19726) + << "incorrect value for stec_sat_list[2].stec_coeff[3], expected 19726, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_quality_indicator, 119) + << "incorrect value for stec_sat_list[2].stec_quality_indicator, " + "expected 119, is " + << last_msg_->stec_sat_list[2].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[2].sv_id.constellation, 179) + << "incorrect value for stec_sat_list[2].sv_id.constellation, expected " + "179, is " + << last_msg_->stec_sat_list[2].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[2].sv_id.satId, 247) + << "incorrect value for stec_sat_list[2].sv_id.satId, expected 247, is " + << last_msg_->stec_sat_list[2].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[0], -8651) + << "incorrect value for stec_sat_list[3].stec_coeff[0], expected -8651, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[1], -27973) + << "incorrect value for stec_sat_list[3].stec_coeff[1], expected -27973, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[2], 23546) + << "incorrect value for stec_sat_list[3].stec_coeff[2], expected 23546, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[3], -10284) + << "incorrect value for stec_sat_list[3].stec_coeff[3], expected -10284, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_quality_indicator, 23) + << "incorrect value for stec_sat_list[3].stec_quality_indicator, " + "expected 23, is " + << last_msg_->stec_sat_list[3].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[3].sv_id.constellation, 185) + << "incorrect value for stec_sat_list[3].sv_id.constellation, expected " + "185, is " + << last_msg_->stec_sat_list[3].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[3].sv_id.satId, 153) + << "incorrect value for stec_sat_list[3].sv_id.satId, expected 153, is " + << last_msg_->stec_sat_list[3].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[0], 27486) + << "incorrect value for stec_sat_list[4].stec_coeff[0], expected 27486, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[1], 23329) + << "incorrect value for stec_sat_list[4].stec_coeff[1], expected 23329, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[2], 234) + << "incorrect value for stec_sat_list[4].stec_coeff[2], expected 234, is " + << last_msg_->stec_sat_list[4].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[3], -29739) + << "incorrect value for stec_sat_list[4].stec_coeff[3], expected -29739, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_quality_indicator, 250) + << "incorrect value for stec_sat_list[4].stec_quality_indicator, " + "expected 250, is " + << last_msg_->stec_sat_list[4].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[4].sv_id.constellation, 107) + << "incorrect value for stec_sat_list[4].sv_id.constellation, expected " + "107, is " + << last_msg_->stec_sat_list[4].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[4].sv_id.satId, 14) + << "incorrect value for stec_sat_list[4].sv_id.satId, expected 14, is " + << last_msg_->stec_sat_list[4].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[0], 18965) + << "incorrect value for stec_sat_list[5].stec_coeff[0], expected 18965, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[1], -22098) + << "incorrect value for stec_sat_list[5].stec_coeff[1], expected -22098, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[2], 22077) + << "incorrect value for stec_sat_list[5].stec_coeff[2], expected 22077, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[3], -29093) + << "incorrect value for stec_sat_list[5].stec_coeff[3], expected -29093, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_quality_indicator, 50) + << "incorrect value for stec_sat_list[5].stec_quality_indicator, " + "expected 50, is " + << last_msg_->stec_sat_list[5].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[5].sv_id.constellation, 179) + << "incorrect value for stec_sat_list[5].sv_id.constellation, expected " + "179, is " + << last_msg_->stec_sat_list[5].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[5].sv_id.satId, 95) + << "incorrect value for stec_sat_list[5].sv_id.satId, expected 95, is " + << last_msg_->stec_sat_list[5].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[0], -7898) + << "incorrect value for stec_sat_list[6].stec_coeff[0], expected -7898, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[1], 26002) + << "incorrect value for stec_sat_list[6].stec_coeff[1], expected 26002, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[2], -29879) + << "incorrect value for stec_sat_list[6].stec_coeff[2], expected -29879, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[3], 30008) + << "incorrect value for stec_sat_list[6].stec_coeff[3], expected 30008, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_quality_indicator, 9) + << "incorrect value for stec_sat_list[6].stec_quality_indicator, " + "expected 9, is " + << last_msg_->stec_sat_list[6].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[6].sv_id.constellation, 108) + << "incorrect value for stec_sat_list[6].sv_id.constellation, expected " + "108, is " + << last_msg_->stec_sat_list[6].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[6].sv_id.satId, 51) + << "incorrect value for stec_sat_list[6].sv_id.satId, expected 51, is " + << last_msg_->stec_sat_list[6].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[0], -12948) + << "incorrect value for stec_sat_list[7].stec_coeff[0], expected -12948, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[1], 4701) + << "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4701, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[2], -15597) + << "incorrect value for stec_sat_list[7].stec_coeff[2], expected -15597, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[3], -13791) + << "incorrect value for stec_sat_list[7].stec_coeff[3], expected -13791, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_quality_indicator, 213) + << "incorrect value for stec_sat_list[7].stec_quality_indicator, " + "expected 213, is " + << last_msg_->stec_sat_list[7].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[7].sv_id.constellation, 37) + << "incorrect value for stec_sat_list[7].sv_id.constellation, expected " + "37, is " + << last_msg_->stec_sat_list[7].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[7].sv_id.satId, 82) + << "incorrect value for stec_sat_list[7].sv_id.satId, expected 82, is " + << last_msg_->stec_sat_list[7].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[0], -17283) + << "incorrect value for stec_sat_list[8].stec_coeff[0], expected -17283, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[1], 14455) + << "incorrect value for stec_sat_list[8].stec_coeff[1], expected 14455, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[2], -27067) + << "incorrect value for stec_sat_list[8].stec_coeff[2], expected -27067, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[3], 19606) + << "incorrect value for stec_sat_list[8].stec_coeff[3], expected 19606, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_quality_indicator, 178) + << "incorrect value for stec_sat_list[8].stec_quality_indicator, " + "expected 178, is " + << last_msg_->stec_sat_list[8].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[8].sv_id.constellation, 206) + << "incorrect value for stec_sat_list[8].sv_id.constellation, expected " + "206, is " + << last_msg_->stec_sat_list[8].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[8].sv_id.satId, 87) + << "incorrect value for stec_sat_list[8].sv_id.satId, expected 87, is " + << last_msg_->stec_sat_list[8].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[0], -12215) + << "incorrect value for stec_sat_list[9].stec_coeff[0], expected -12215, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[1], -6072) + << "incorrect value for stec_sat_list[9].stec_coeff[1], expected -6072, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[2], -1528) + << "incorrect value for stec_sat_list[9].stec_coeff[2], expected -1528, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[3], -19765) + << "incorrect value for stec_sat_list[9].stec_coeff[3], expected -19765, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_quality_indicator, 18) + << "incorrect value for stec_sat_list[9].stec_quality_indicator, " + "expected 18, is " + << last_msg_->stec_sat_list[9].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[9].sv_id.constellation, 131) + << "incorrect value for stec_sat_list[9].sv_id.constellation, expected " + "131, is " + << last_msg_->stec_sat_list[9].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[9].sv_id.satId, 3) + << "incorrect value for stec_sat_list[9].sv_id.satId, expected 3, is " + << last_msg_->stec_sat_list[9].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[0], 12630) + << "incorrect value for stec_sat_list[10].stec_coeff[0], expected 12630, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[1], -19721) + << "incorrect value for stec_sat_list[10].stec_coeff[1], expected " + "-19721, is " + << last_msg_->stec_sat_list[10].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[2], 14502) + << "incorrect value for stec_sat_list[10].stec_coeff[2], expected 14502, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[3], 2591) + << "incorrect value for stec_sat_list[10].stec_coeff[3], expected 2591, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_quality_indicator, 252) + << "incorrect value for stec_sat_list[10].stec_quality_indicator, " + "expected 252, is " + << last_msg_->stec_sat_list[10].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[10].sv_id.constellation, 163) + << "incorrect value for stec_sat_list[10].sv_id.constellation, expected " + "163, is " + << last_msg_->stec_sat_list[10].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[10].sv_id.satId, 170) + << "incorrect value for stec_sat_list[10].sv_id.satId, expected 170, is " + << last_msg_->stec_sat_list[10].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[0], -23340) + << "incorrect value for stec_sat_list[11].stec_coeff[0], expected " + "-23340, is " + << last_msg_->stec_sat_list[11].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[1], -24063) + << "incorrect value for stec_sat_list[11].stec_coeff[1], expected " + "-24063, is " + << last_msg_->stec_sat_list[11].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[2], 4650) + << "incorrect value for stec_sat_list[11].stec_coeff[2], expected 4650, " + "is " + << last_msg_->stec_sat_list[11].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[3], -22148) + << "incorrect value for stec_sat_list[11].stec_coeff[3], expected " + "-22148, is " + << last_msg_->stec_sat_list[11].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_quality_indicator, 241) + << "incorrect value for stec_sat_list[11].stec_quality_indicator, " + "expected 241, is " + << last_msg_->stec_sat_list[11].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[11].sv_id.constellation, 213) + << "incorrect value for stec_sat_list[11].sv_id.constellation, expected " + "213, is " + << last_msg_->stec_sat_list[11].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[11].sv_id.satId, 119) + << "incorrect value for stec_sat_list[11].sv_id.satId, expected 119, is " + << last_msg_->stec_sat_list[11].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[0], 5944) + << "incorrect value for stec_sat_list[12].stec_coeff[0], expected 5944, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[1], 32142) + << "incorrect value for stec_sat_list[12].stec_coeff[1], expected 32142, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[2], 30760) + << "incorrect value for stec_sat_list[12].stec_coeff[2], expected 30760, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[3], 11587) + << "incorrect value for stec_sat_list[12].stec_coeff[3], expected 11587, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_quality_indicator, 26) + << "incorrect value for stec_sat_list[12].stec_quality_indicator, " + "expected 26, is " + << last_msg_->stec_sat_list[12].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[12].sv_id.constellation, 158) + << "incorrect value for stec_sat_list[12].sv_id.constellation, expected " + "158, is " + << last_msg_->stec_sat_list[12].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[12].sv_id.satId, 121) + << "incorrect value for stec_sat_list[12].sv_id.satId, expected 121, is " + << last_msg_->stec_sat_list[12].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[0], 3095) + << "incorrect value for stec_sat_list[13].stec_coeff[0], expected 3095, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[1], 22769) + << "incorrect value for stec_sat_list[13].stec_coeff[1], expected 22769, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[2], -4283) + << "incorrect value for stec_sat_list[13].stec_coeff[2], expected -4283, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[3], 14844) + << "incorrect value for stec_sat_list[13].stec_coeff[3], expected 14844, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_quality_indicator, 110) + << "incorrect value for stec_sat_list[13].stec_quality_indicator, " + "expected 110, is " + << last_msg_->stec_sat_list[13].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[13].sv_id.constellation, 235) + << "incorrect value for stec_sat_list[13].sv_id.constellation, expected " + "235, is " + << last_msg_->stec_sat_list[13].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[13].sv_id.satId, 126) + << "incorrect value for stec_sat_list[13].sv_id.satId, expected 126, is " + << last_msg_->stec_sat_list[13].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[0], -21032) + << "incorrect value for stec_sat_list[14].stec_coeff[0], expected " + "-21032, is " + << last_msg_->stec_sat_list[14].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[1], -19726) + << "incorrect value for stec_sat_list[14].stec_coeff[1], expected " + "-19726, is " + << last_msg_->stec_sat_list[14].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[2], 1297) + << "incorrect value for stec_sat_list[14].stec_coeff[2], expected 1297, " + "is " + << last_msg_->stec_sat_list[14].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[3], -22049) + << "incorrect value for stec_sat_list[14].stec_coeff[3], expected " + "-22049, is " + << last_msg_->stec_sat_list[14].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_quality_indicator, 201) + << "incorrect value for stec_sat_list[14].stec_quality_indicator, " + "expected 201, is " + << last_msg_->stec_sat_list[14].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[14].sv_id.constellation, 44) + << "incorrect value for stec_sat_list[14].sv_id.constellation, expected " + "44, is " + << last_msg_->stec_sat_list[14].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[14].sv_id.satId, 93) + << "incorrect value for stec_sat_list[14].sv_id.satId, expected 93, is " + << last_msg_->stec_sat_list[14].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[0], 619) + << "incorrect value for stec_sat_list[15].stec_coeff[0], expected 619, " + "is " + << last_msg_->stec_sat_list[15].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[1], -5744) + << "incorrect value for stec_sat_list[15].stec_coeff[1], expected -5744, " + "is " + << last_msg_->stec_sat_list[15].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[2], 22542) + << "incorrect value for stec_sat_list[15].stec_coeff[2], expected 22542, " + "is " + << last_msg_->stec_sat_list[15].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[3], -12000) + << "incorrect value for stec_sat_list[15].stec_coeff[3], expected " + "-12000, is " + << last_msg_->stec_sat_list[15].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_quality_indicator, 77) + << "incorrect value for stec_sat_list[15].stec_quality_indicator, " + "expected 77, is " + << last_msg_->stec_sat_list[15].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[15].sv_id.constellation, 3) + << "incorrect value for stec_sat_list[15].sv_id.constellation, expected " + "3, is " + << last_msg_->stec_sat_list[15].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[15].sv_id.satId, 192) + << "incorrect value for stec_sat_list[15].sv_id.satId, expected 192, is " + << last_msg_->stec_sat_list[15].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[0], 10651) + << "incorrect value for stec_sat_list[16].stec_coeff[0], expected 10651, " + "is " + << last_msg_->stec_sat_list[16].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[1], -2889) + << "incorrect value for stec_sat_list[16].stec_coeff[1], expected -2889, " + "is " + << last_msg_->stec_sat_list[16].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[2], 21150) + << "incorrect value for stec_sat_list[16].stec_coeff[2], expected 21150, " + "is " + << last_msg_->stec_sat_list[16].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[3], 26421) + << "incorrect value for stec_sat_list[16].stec_coeff[3], expected 26421, " + "is " + << last_msg_->stec_sat_list[16].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_quality_indicator, 123) + << "incorrect value for stec_sat_list[16].stec_quality_indicator, " + "expected 123, is " + << last_msg_->stec_sat_list[16].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[16].sv_id.constellation, 17) + << "incorrect value for stec_sat_list[16].sv_id.constellation, expected " + "17, is " + << last_msg_->stec_sat_list[16].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[16].sv_id.satId, 1) + << "incorrect value for stec_sat_list[16].sv_id.satId, expected 1, is " + << last_msg_->stec_sat_list[16].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[0], -19165) + << "incorrect value for stec_sat_list[17].stec_coeff[0], expected " + "-19165, is " + << last_msg_->stec_sat_list[17].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[1], 30229) + << "incorrect value for stec_sat_list[17].stec_coeff[1], expected 30229, " + "is " + << last_msg_->stec_sat_list[17].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[2], -1282) + << "incorrect value for stec_sat_list[17].stec_coeff[2], expected -1282, " + "is " + << last_msg_->stec_sat_list[17].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[3], -18382) + << "incorrect value for stec_sat_list[17].stec_coeff[3], expected " + "-18382, is " + << last_msg_->stec_sat_list[17].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_quality_indicator, 185) + << "incorrect value for stec_sat_list[17].stec_quality_indicator, " + "expected 185, is " + << last_msg_->stec_sat_list[17].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[17].sv_id.constellation, 202) + << "incorrect value for stec_sat_list[17].sv_id.constellation, expected " + "202, is " + << last_msg_->stec_sat_list[17].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[17].sv_id.satId, 14) + << "incorrect value for stec_sat_list[17].sv_id.satId, expected 14, is " + << last_msg_->stec_sat_list[17].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[0], -23752) + << "incorrect value for stec_sat_list[18].stec_coeff[0], expected " + "-23752, is " + << last_msg_->stec_sat_list[18].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[1], 32433) + << "incorrect value for stec_sat_list[18].stec_coeff[1], expected 32433, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[2], 20441) + << "incorrect value for stec_sat_list[18].stec_coeff[2], expected 20441, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[3], -4181) + << "incorrect value for stec_sat_list[18].stec_coeff[3], expected -4181, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_quality_indicator, 45) + << "incorrect value for stec_sat_list[18].stec_quality_indicator, " + "expected 45, is " + << last_msg_->stec_sat_list[18].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[18].sv_id.constellation, 31) + << "incorrect value for stec_sat_list[18].sv_id.constellation, expected " + "31, is " + << last_msg_->stec_sat_list[18].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[18].sv_id.satId, 50) + << "incorrect value for stec_sat_list[18].sv_id.satId, expected 50, is " + << last_msg_->stec_sat_list[18].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[0], -13968) + << "incorrect value for stec_sat_list[19].stec_coeff[0], expected " + "-13968, is " + << last_msg_->stec_sat_list[19].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[1], -29322) + << "incorrect value for stec_sat_list[19].stec_coeff[1], expected " + "-29322, is " + << last_msg_->stec_sat_list[19].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[2], -23790) + << "incorrect value for stec_sat_list[19].stec_coeff[2], expected " + "-23790, is " + << last_msg_->stec_sat_list[19].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[3], 9063) + << "incorrect value for stec_sat_list[19].stec_coeff[3], expected 9063, " + "is " + << last_msg_->stec_sat_list[19].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_quality_indicator, 238) + << "incorrect value for stec_sat_list[19].stec_quality_indicator, " + "expected 238, is " + << last_msg_->stec_sat_list[19].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[19].sv_id.constellation, 188) + << "incorrect value for stec_sat_list[19].sv_id.constellation, expected " + "188, is " + << last_msg_->stec_sat_list[19].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[19].sv_id.satId, 237) + << "incorrect value for stec_sat_list[19].sv_id.satId, expected 237, is " + << last_msg_->stec_sat_list[19].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[0], 4737) + << "incorrect value for stec_sat_list[20].stec_coeff[0], expected 4737, " + "is " + << last_msg_->stec_sat_list[20].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[1], 21877) + << "incorrect value for stec_sat_list[20].stec_coeff[1], expected 21877, " + "is " + << last_msg_->stec_sat_list[20].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[2], 20414) + << "incorrect value for stec_sat_list[20].stec_coeff[2], expected 20414, " + "is " + << last_msg_->stec_sat_list[20].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[3], -10286) + << "incorrect value for stec_sat_list[20].stec_coeff[3], expected " + "-10286, is " + << last_msg_->stec_sat_list[20].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_quality_indicator, 82) + << "incorrect value for stec_sat_list[20].stec_quality_indicator, " + "expected 82, is " + << last_msg_->stec_sat_list[20].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[20].sv_id.constellation, 21) + << "incorrect value for stec_sat_list[20].sv_id.constellation, expected " + "21, is " + << last_msg_->stec_sat_list[20].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[20].sv_id.satId, 63) + << "incorrect value for stec_sat_list[20].sv_id.satId, expected 63, is " + << last_msg_->stec_sat_list[20].sv_id.satId; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc new file mode 100644 index 0000000000..fa2858e47f --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrStecCorrectionDepA.cc @@ -0,0 +1,1418 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_stec_correction_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_stec_correction_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrStecCorrectionDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, 39, + 4, 126, 19, 111, 97, 248, 130, 217, 217, 106, 58, 12, 65, 230, 171, + 81, 95, 86, 16, 39, 84, 228, 208, 201, 81, 219, 99, 203, 61, 182, + 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, 93, 218, 247, 158, + 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, 148, 147, 72, 225, 180, + 236, 205, 201, 33, 3, 246, 204, 19, 3, 98, 4, 194, 191, 246, 76, + 219, 31, 191, 113, 79, 177, 15, 251, 33, 19, 96, 54, 58, 146, 210, + 100, 249, 72, 21, 161, 211, 198, 21, 238, 111, 107, 36, 227, 225, 213, + 3, 71, 243, 63, 65, 236, 92, 77, 0, 169, 15, 182, 5, 240, 180, + 9, 122, 86, 232, 6, 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, + 216, 55, 50, 181, 5, 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, + 66, 124, 168, 59, 139, 106, 118, 51, 187, 216, 191, 158, 77, 92, 58, + 253, 132, 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, 181, 196, 23, + 53, 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, + 201, 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, 22, + 178, 226, 109, 88, 157, 30, 196, 175, 26, 76, 34, 116, 220, 154, 232, + 12, 179, 244, 15, 155, 196, 202, 72, 70, 115, 10, 214, 114, 39, 245, + 28, 237, 68, 136, 155, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_stec_correction_dep_a_t *test_msg = + (msg_ssr_stec_correction_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->header.iod_atmo = 4; + test_msg->header.num_msgs = 147; + test_msg->header.seq_num = 123; + test_msg->header.time.tow = 3905179974; + test_msg->header.time.wn = 11193; + test_msg->header.update_interval = 39; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[0] = -1951; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[1] = -9854; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[2] = 27353; + if (sizeof(test_msg->stec_sat_list[0].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[0].stec_coeff[0])); + } + test_msg->stec_sat_list[0].stec_coeff[3] = 3130; + test_msg->stec_sat_list[0].stec_quality_indicator = 111; + test_msg->stec_sat_list[0].sv_id.constellation = 19; + test_msg->stec_sat_list[0].sv_id.satId = 126; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[0] = 24401; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[1] = 4182; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[2] = 21543; + if (sizeof(test_msg->stec_sat_list[1].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[1].stec_coeff[0])); + } + test_msg->stec_sat_list[1].stec_coeff[3] = -12060; + test_msg->stec_sat_list[1].stec_quality_indicator = 171; + test_msg->stec_sat_list[1].sv_id.constellation = 230; + test_msg->stec_sat_list[1].sv_id.satId = 65; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[0] = -13469; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[1] = -18883; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[2] = 32066; + if (sizeof(test_msg->stec_sat_list[2].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[2].stec_coeff[0])); + } + test_msg->stec_sat_list[2].stec_coeff[3] = 971; + test_msg->stec_sat_list[2].stec_quality_indicator = 219; + test_msg->stec_sat_list[2].sv_id.constellation = 81; + test_msg->stec_sat_list[2].sv_id.satId = 201; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[0] = 32220; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[1] = 5436; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[2] = -9635; + if (sizeof(test_msg->stec_sat_list[3].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[3].stec_coeff[0])); + } + test_msg->stec_sat_list[3].stec_coeff[3] = -24841; + test_msg->stec_sat_list[3].stec_quality_indicator = 100; + test_msg->stec_sat_list[3].sv_id.constellation = 44; + test_msg->stec_sat_list[3].sv_id.satId = 193; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[0] = 3718; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[1] = 12497; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[2] = -10482; + if (sizeof(test_msg->stec_sat_list[4].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[4].stec_coeff[0])); + } + test_msg->stec_sat_list[4].stec_coeff[3] = -27495; + test_msg->stec_sat_list[4].stec_quality_indicator = 129; + test_msg->stec_sat_list[4].sv_id.constellation = 93; + test_msg->stec_sat_list[4].sv_id.satId = 207; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[0] = -4940; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[1] = -13875; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[2] = 801; + if (sizeof(test_msg->stec_sat_list[5].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[5].stec_coeff[0])); + } + test_msg->stec_sat_list[5].stec_coeff[3] = -13066; + test_msg->stec_sat_list[5].stec_quality_indicator = 225; + test_msg->stec_sat_list[5].sv_id.constellation = 72; + test_msg->stec_sat_list[5].sv_id.satId = 147; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[0] = -15868; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[1] = -2369; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[2] = -9396; + if (sizeof(test_msg->stec_sat_list[6].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[6].stec_coeff[0])); + } + test_msg->stec_sat_list[6].stec_coeff[3] = -16609; + test_msg->stec_sat_list[6].stec_quality_indicator = 98; + test_msg->stec_sat_list[6].sv_id.constellation = 3; + test_msg->stec_sat_list[6].sv_id.satId = 19; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[0] = -1265; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[1] = 4897; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[2] = 13920; + if (sizeof(test_msg->stec_sat_list[7].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[7].stec_coeff[0])); + } + test_msg->stec_sat_list[7].stec_coeff[3] = -28102; + test_msg->stec_sat_list[7].stec_quality_indicator = 177; + test_msg->stec_sat_list[7].sv_id.constellation = 79; + test_msg->stec_sat_list[7].sv_id.satId = 113; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[0] = 5448; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[1] = -11359; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[2] = 5574; + if (sizeof(test_msg->stec_sat_list[8].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[8].stec_coeff[0])); + } + test_msg->stec_sat_list[8].stec_coeff[3] = 28654; + test_msg->stec_sat_list[8].stec_quality_indicator = 249; + test_msg->stec_sat_list[8].sv_id.constellation = 100; + test_msg->stec_sat_list[8].sv_id.satId = 210; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[0] = -10783; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[1] = 18179; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[2] = 16371; + if (sizeof(test_msg->stec_sat_list[9].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[9].stec_coeff[0])); + } + test_msg->stec_sat_list[9].stec_coeff[3] = -5055; + test_msg->stec_sat_list[9].stec_quality_indicator = 227; + test_msg->stec_sat_list[9].sv_id.constellation = 36; + test_msg->stec_sat_list[9].sv_id.satId = 107; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[0] = 4009; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[1] = 1462; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[2] = -19216; + if (sizeof(test_msg->stec_sat_list[10].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[10].stec_coeff[0])); + } + test_msg->stec_sat_list[10].stec_coeff[3] = 31241; + test_msg->stec_sat_list[10].stec_quality_indicator = 0; + test_msg->stec_sat_list[10].sv_id.constellation = 77; + test_msg->stec_sat_list[10].sv_id.satId = 92; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[0] = 26727; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[1] = -16898; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[2] = 28241; + if (sizeof(test_msg->stec_sat_list[11].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[11].stec_coeff[0])); + } + test_msg->stec_sat_list[11].stec_coeff[3] = 12546; + test_msg->stec_sat_list[11].stec_quality_indicator = 6; + test_msg->stec_sat_list[11].sv_id.constellation = 232; + test_msg->stec_sat_list[11].sv_id.satId = 86; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[0] = 12855; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[1] = 1461; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[2] = 20603; + if (sizeof(test_msg->stec_sat_list[12].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[12].stec_coeff[0])); + } + test_msg->stec_sat_list[12].stec_coeff[3] = -3023; + test_msg->stec_sat_list[12].stec_quality_indicator = 216; + test_msg->stec_sat_list[12].sv_id.constellation = 84; + test_msg->stec_sat_list[12].sv_id.satId = 202; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[0] = -6492; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[1] = 16952; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[2] = -22404; + if (sizeof(test_msg->stec_sat_list[13].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[13].stec_coeff[0])); + } + test_msg->stec_sat_list[13].stec_coeff[3] = -29893; + test_msg->stec_sat_list[13].stec_quality_indicator = 125; + test_msg->stec_sat_list[13].sv_id.constellation = 188; + test_msg->stec_sat_list[13].sv_id.satId = 224; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[0] = -10053; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[1] = -24897; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[2] = 23629; + if (sizeof(test_msg->stec_sat_list[14].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[14].stec_coeff[0])); + } + test_msg->stec_sat_list[14].stec_coeff[3] = -710; + test_msg->stec_sat_list[14].stec_quality_indicator = 51; + test_msg->stec_sat_list[14].sv_id.constellation = 118; + test_msg->stec_sat_list[14].sv_id.satId = 106; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[0] = -26103; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[1] = -9539; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[2] = -11971; + if (sizeof(test_msg->stec_sat_list[15].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[15].stec_coeff[0])); + } + test_msg->stec_sat_list[15].stec_coeff[3] = 20993; + test_msg->stec_sat_list[15].stec_quality_indicator = 165; + test_msg->stec_sat_list[15].sv_id.constellation = 150; + test_msg->stec_sat_list[15].sv_id.satId = 132; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[0] = -18891; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[1] = -16272; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[2] = -22578; + if (sizeof(test_msg->stec_sat_list[16].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[16].stec_coeff[0])); + } + test_msg->stec_sat_list[16].stec_coeff[3] = -2915; + test_msg->stec_sat_list[16].stec_quality_indicator = 23; + test_msg->stec_sat_list[16].sv_id.constellation = 196; + test_msg->stec_sat_list[16].sv_id.satId = 181; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[0] = 15833; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[1] = 24920; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[2] = -13879; + if (sizeof(test_msg->stec_sat_list[17].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[17].stec_coeff[0])); + } + test_msg->stec_sat_list[17].stec_coeff[3] = -1206; + test_msg->stec_sat_list[17].stec_quality_indicator = 189; + test_msg->stec_sat_list[17].sv_id.constellation = 1; + test_msg->stec_sat_list[17].sv_id.satId = 35; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[0] = 14008; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[1] = 18996; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[2] = 2798; + if (sizeof(test_msg->stec_sat_list[18].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[18].stec_coeff[0])); + } + test_msg->stec_sat_list[18].stec_coeff[3] = 5761; + test_msg->stec_sat_list[18].stec_quality_indicator = 104; + test_msg->stec_sat_list[18].sv_id.constellation = 14; + test_msg->stec_sat_list[18].sv_id.satId = 217; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[0] = -25256; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[1] = -15330; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[2] = 6831; + if (sizeof(test_msg->stec_sat_list[19].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[19].stec_coeff[0])); + } + test_msg->stec_sat_list[19].stec_coeff[3] = 8780; + test_msg->stec_sat_list[19].stec_quality_indicator = 109; + test_msg->stec_sat_list[19].sv_id.constellation = 226; + test_msg->stec_sat_list[19].sv_id.satId = 178; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[0] = 3304; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[1] = -2893; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[2] = -25841; + if (sizeof(test_msg->stec_sat_list[20].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[20].stec_coeff[0])); + } + test_msg->stec_sat_list[20].stec_coeff[3] = -13628; + test_msg->stec_sat_list[20].stec_quality_indicator = 154; + test_msg->stec_sat_list[20].sv_id.constellation = 220; + test_msg->stec_sat_list[20].sv_id.satId = 116; + if (sizeof(test_msg->stec_sat_list) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->stec_sat_list[0])); + } + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[21].stec_coeff[0])); + } + test_msg->stec_sat_list[21].stec_coeff[0] = -10742; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[21].stec_coeff[0])); + } + test_msg->stec_sat_list[21].stec_coeff[1] = 10098; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[21].stec_coeff[0])); + } + test_msg->stec_sat_list[21].stec_coeff[2] = 7413; + if (sizeof(test_msg->stec_sat_list[21].stec_coeff) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + + sizeof(test_msg->stec_sat_list[21].stec_coeff[0])); + } + test_msg->stec_sat_list[21].stec_coeff[3] = 17645; + test_msg->stec_sat_list[21].stec_quality_indicator = 115; + test_msg->stec_sat_list[21].sv_id.constellation = 70; + test_msg->stec_sat_list[21].sv_id.satId = 72; + + EXPECT_EQ(send_message(0x5eb, 1831, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 1831); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->header.iod_atmo, 4) + << "incorrect value for header.iod_atmo, expected 4, is " + << last_msg_->header.iod_atmo; + EXPECT_EQ(last_msg_->header.num_msgs, 147) + << "incorrect value for header.num_msgs, expected 147, is " + << last_msg_->header.num_msgs; + EXPECT_EQ(last_msg_->header.seq_num, 123) + << "incorrect value for header.seq_num, expected 123, is " + << last_msg_->header.seq_num; + EXPECT_EQ(last_msg_->header.time.tow, 3905179974) + << "incorrect value for header.time.tow, expected 3905179974, is " + << last_msg_->header.time.tow; + EXPECT_EQ(last_msg_->header.time.wn, 11193) + << "incorrect value for header.time.wn, expected 11193, is " + << last_msg_->header.time.wn; + EXPECT_EQ(last_msg_->header.update_interval, 39) + << "incorrect value for header.update_interval, expected 39, is " + << last_msg_->header.update_interval; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[0], -1951) + << "incorrect value for stec_sat_list[0].stec_coeff[0], expected -1951, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[1], -9854) + << "incorrect value for stec_sat_list[0].stec_coeff[1], expected -9854, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[2], 27353) + << "incorrect value for stec_sat_list[0].stec_coeff[2], expected 27353, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_coeff[3], 3130) + << "incorrect value for stec_sat_list[0].stec_coeff[3], expected 3130, " + "is " + << last_msg_->stec_sat_list[0].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[0].stec_quality_indicator, 111) + << "incorrect value for stec_sat_list[0].stec_quality_indicator, " + "expected 111, is " + << last_msg_->stec_sat_list[0].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[0].sv_id.constellation, 19) + << "incorrect value for stec_sat_list[0].sv_id.constellation, expected " + "19, is " + << last_msg_->stec_sat_list[0].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[0].sv_id.satId, 126) + << "incorrect value for stec_sat_list[0].sv_id.satId, expected 126, is " + << last_msg_->stec_sat_list[0].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[0], 24401) + << "incorrect value for stec_sat_list[1].stec_coeff[0], expected 24401, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[1], 4182) + << "incorrect value for stec_sat_list[1].stec_coeff[1], expected 4182, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[2], 21543) + << "incorrect value for stec_sat_list[1].stec_coeff[2], expected 21543, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_coeff[3], -12060) + << "incorrect value for stec_sat_list[1].stec_coeff[3], expected -12060, " + "is " + << last_msg_->stec_sat_list[1].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[1].stec_quality_indicator, 171) + << "incorrect value for stec_sat_list[1].stec_quality_indicator, " + "expected 171, is " + << last_msg_->stec_sat_list[1].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[1].sv_id.constellation, 230) + << "incorrect value for stec_sat_list[1].sv_id.constellation, expected " + "230, is " + << last_msg_->stec_sat_list[1].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[1].sv_id.satId, 65) + << "incorrect value for stec_sat_list[1].sv_id.satId, expected 65, is " + << last_msg_->stec_sat_list[1].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[0], -13469) + << "incorrect value for stec_sat_list[2].stec_coeff[0], expected -13469, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[1], -18883) + << "incorrect value for stec_sat_list[2].stec_coeff[1], expected -18883, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[2], 32066) + << "incorrect value for stec_sat_list[2].stec_coeff[2], expected 32066, " + "is " + << last_msg_->stec_sat_list[2].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_coeff[3], 971) + << "incorrect value for stec_sat_list[2].stec_coeff[3], expected 971, is " + << last_msg_->stec_sat_list[2].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[2].stec_quality_indicator, 219) + << "incorrect value for stec_sat_list[2].stec_quality_indicator, " + "expected 219, is " + << last_msg_->stec_sat_list[2].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[2].sv_id.constellation, 81) + << "incorrect value for stec_sat_list[2].sv_id.constellation, expected " + "81, is " + << last_msg_->stec_sat_list[2].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[2].sv_id.satId, 201) + << "incorrect value for stec_sat_list[2].sv_id.satId, expected 201, is " + << last_msg_->stec_sat_list[2].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[0], 32220) + << "incorrect value for stec_sat_list[3].stec_coeff[0], expected 32220, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[1], 5436) + << "incorrect value for stec_sat_list[3].stec_coeff[1], expected 5436, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[2], -9635) + << "incorrect value for stec_sat_list[3].stec_coeff[2], expected -9635, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_coeff[3], -24841) + << "incorrect value for stec_sat_list[3].stec_coeff[3], expected -24841, " + "is " + << last_msg_->stec_sat_list[3].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[3].stec_quality_indicator, 100) + << "incorrect value for stec_sat_list[3].stec_quality_indicator, " + "expected 100, is " + << last_msg_->stec_sat_list[3].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[3].sv_id.constellation, 44) + << "incorrect value for stec_sat_list[3].sv_id.constellation, expected " + "44, is " + << last_msg_->stec_sat_list[3].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[3].sv_id.satId, 193) + << "incorrect value for stec_sat_list[3].sv_id.satId, expected 193, is " + << last_msg_->stec_sat_list[3].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[0], 3718) + << "incorrect value for stec_sat_list[4].stec_coeff[0], expected 3718, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[1], 12497) + << "incorrect value for stec_sat_list[4].stec_coeff[1], expected 12497, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[2], -10482) + << "incorrect value for stec_sat_list[4].stec_coeff[2], expected -10482, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_coeff[3], -27495) + << "incorrect value for stec_sat_list[4].stec_coeff[3], expected -27495, " + "is " + << last_msg_->stec_sat_list[4].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[4].stec_quality_indicator, 129) + << "incorrect value for stec_sat_list[4].stec_quality_indicator, " + "expected 129, is " + << last_msg_->stec_sat_list[4].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[4].sv_id.constellation, 93) + << "incorrect value for stec_sat_list[4].sv_id.constellation, expected " + "93, is " + << last_msg_->stec_sat_list[4].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[4].sv_id.satId, 207) + << "incorrect value for stec_sat_list[4].sv_id.satId, expected 207, is " + << last_msg_->stec_sat_list[4].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[0], -4940) + << "incorrect value for stec_sat_list[5].stec_coeff[0], expected -4940, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[1], -13875) + << "incorrect value for stec_sat_list[5].stec_coeff[1], expected -13875, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[2], 801) + << "incorrect value for stec_sat_list[5].stec_coeff[2], expected 801, is " + << last_msg_->stec_sat_list[5].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_coeff[3], -13066) + << "incorrect value for stec_sat_list[5].stec_coeff[3], expected -13066, " + "is " + << last_msg_->stec_sat_list[5].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[5].stec_quality_indicator, 225) + << "incorrect value for stec_sat_list[5].stec_quality_indicator, " + "expected 225, is " + << last_msg_->stec_sat_list[5].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[5].sv_id.constellation, 72) + << "incorrect value for stec_sat_list[5].sv_id.constellation, expected " + "72, is " + << last_msg_->stec_sat_list[5].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[5].sv_id.satId, 147) + << "incorrect value for stec_sat_list[5].sv_id.satId, expected 147, is " + << last_msg_->stec_sat_list[5].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[0], -15868) + << "incorrect value for stec_sat_list[6].stec_coeff[0], expected -15868, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[1], -2369) + << "incorrect value for stec_sat_list[6].stec_coeff[1], expected -2369, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[2], -9396) + << "incorrect value for stec_sat_list[6].stec_coeff[2], expected -9396, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_coeff[3], -16609) + << "incorrect value for stec_sat_list[6].stec_coeff[3], expected -16609, " + "is " + << last_msg_->stec_sat_list[6].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[6].stec_quality_indicator, 98) + << "incorrect value for stec_sat_list[6].stec_quality_indicator, " + "expected 98, is " + << last_msg_->stec_sat_list[6].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[6].sv_id.constellation, 3) + << "incorrect value for stec_sat_list[6].sv_id.constellation, expected " + "3, is " + << last_msg_->stec_sat_list[6].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[6].sv_id.satId, 19) + << "incorrect value for stec_sat_list[6].sv_id.satId, expected 19, is " + << last_msg_->stec_sat_list[6].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[0], -1265) + << "incorrect value for stec_sat_list[7].stec_coeff[0], expected -1265, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[1], 4897) + << "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4897, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[2], 13920) + << "incorrect value for stec_sat_list[7].stec_coeff[2], expected 13920, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_coeff[3], -28102) + << "incorrect value for stec_sat_list[7].stec_coeff[3], expected -28102, " + "is " + << last_msg_->stec_sat_list[7].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[7].stec_quality_indicator, 177) + << "incorrect value for stec_sat_list[7].stec_quality_indicator, " + "expected 177, is " + << last_msg_->stec_sat_list[7].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[7].sv_id.constellation, 79) + << "incorrect value for stec_sat_list[7].sv_id.constellation, expected " + "79, is " + << last_msg_->stec_sat_list[7].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[7].sv_id.satId, 113) + << "incorrect value for stec_sat_list[7].sv_id.satId, expected 113, is " + << last_msg_->stec_sat_list[7].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[0], 5448) + << "incorrect value for stec_sat_list[8].stec_coeff[0], expected 5448, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[1], -11359) + << "incorrect value for stec_sat_list[8].stec_coeff[1], expected -11359, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[2], 5574) + << "incorrect value for stec_sat_list[8].stec_coeff[2], expected 5574, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_coeff[3], 28654) + << "incorrect value for stec_sat_list[8].stec_coeff[3], expected 28654, " + "is " + << last_msg_->stec_sat_list[8].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[8].stec_quality_indicator, 249) + << "incorrect value for stec_sat_list[8].stec_quality_indicator, " + "expected 249, is " + << last_msg_->stec_sat_list[8].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[8].sv_id.constellation, 100) + << "incorrect value for stec_sat_list[8].sv_id.constellation, expected " + "100, is " + << last_msg_->stec_sat_list[8].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[8].sv_id.satId, 210) + << "incorrect value for stec_sat_list[8].sv_id.satId, expected 210, is " + << last_msg_->stec_sat_list[8].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[0], -10783) + << "incorrect value for stec_sat_list[9].stec_coeff[0], expected -10783, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[1], 18179) + << "incorrect value for stec_sat_list[9].stec_coeff[1], expected 18179, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[2], 16371) + << "incorrect value for stec_sat_list[9].stec_coeff[2], expected 16371, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_coeff[3], -5055) + << "incorrect value for stec_sat_list[9].stec_coeff[3], expected -5055, " + "is " + << last_msg_->stec_sat_list[9].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[9].stec_quality_indicator, 227) + << "incorrect value for stec_sat_list[9].stec_quality_indicator, " + "expected 227, is " + << last_msg_->stec_sat_list[9].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[9].sv_id.constellation, 36) + << "incorrect value for stec_sat_list[9].sv_id.constellation, expected " + "36, is " + << last_msg_->stec_sat_list[9].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[9].sv_id.satId, 107) + << "incorrect value for stec_sat_list[9].sv_id.satId, expected 107, is " + << last_msg_->stec_sat_list[9].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[0], 4009) + << "incorrect value for stec_sat_list[10].stec_coeff[0], expected 4009, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[1], 1462) + << "incorrect value for stec_sat_list[10].stec_coeff[1], expected 1462, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[2], -19216) + << "incorrect value for stec_sat_list[10].stec_coeff[2], expected " + "-19216, is " + << last_msg_->stec_sat_list[10].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_coeff[3], 31241) + << "incorrect value for stec_sat_list[10].stec_coeff[3], expected 31241, " + "is " + << last_msg_->stec_sat_list[10].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[10].stec_quality_indicator, 0) + << "incorrect value for stec_sat_list[10].stec_quality_indicator, " + "expected 0, is " + << last_msg_->stec_sat_list[10].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[10].sv_id.constellation, 77) + << "incorrect value for stec_sat_list[10].sv_id.constellation, expected " + "77, is " + << last_msg_->stec_sat_list[10].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[10].sv_id.satId, 92) + << "incorrect value for stec_sat_list[10].sv_id.satId, expected 92, is " + << last_msg_->stec_sat_list[10].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[0], 26727) + << "incorrect value for stec_sat_list[11].stec_coeff[0], expected 26727, " + "is " + << last_msg_->stec_sat_list[11].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[1], -16898) + << "incorrect value for stec_sat_list[11].stec_coeff[1], expected " + "-16898, is " + << last_msg_->stec_sat_list[11].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[2], 28241) + << "incorrect value for stec_sat_list[11].stec_coeff[2], expected 28241, " + "is " + << last_msg_->stec_sat_list[11].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_coeff[3], 12546) + << "incorrect value for stec_sat_list[11].stec_coeff[3], expected 12546, " + "is " + << last_msg_->stec_sat_list[11].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[11].stec_quality_indicator, 6) + << "incorrect value for stec_sat_list[11].stec_quality_indicator, " + "expected 6, is " + << last_msg_->stec_sat_list[11].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[11].sv_id.constellation, 232) + << "incorrect value for stec_sat_list[11].sv_id.constellation, expected " + "232, is " + << last_msg_->stec_sat_list[11].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[11].sv_id.satId, 86) + << "incorrect value for stec_sat_list[11].sv_id.satId, expected 86, is " + << last_msg_->stec_sat_list[11].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[0], 12855) + << "incorrect value for stec_sat_list[12].stec_coeff[0], expected 12855, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[1], 1461) + << "incorrect value for stec_sat_list[12].stec_coeff[1], expected 1461, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[2], 20603) + << "incorrect value for stec_sat_list[12].stec_coeff[2], expected 20603, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_coeff[3], -3023) + << "incorrect value for stec_sat_list[12].stec_coeff[3], expected -3023, " + "is " + << last_msg_->stec_sat_list[12].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[12].stec_quality_indicator, 216) + << "incorrect value for stec_sat_list[12].stec_quality_indicator, " + "expected 216, is " + << last_msg_->stec_sat_list[12].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[12].sv_id.constellation, 84) + << "incorrect value for stec_sat_list[12].sv_id.constellation, expected " + "84, is " + << last_msg_->stec_sat_list[12].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[12].sv_id.satId, 202) + << "incorrect value for stec_sat_list[12].sv_id.satId, expected 202, is " + << last_msg_->stec_sat_list[12].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[0], -6492) + << "incorrect value for stec_sat_list[13].stec_coeff[0], expected -6492, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[1], 16952) + << "incorrect value for stec_sat_list[13].stec_coeff[1], expected 16952, " + "is " + << last_msg_->stec_sat_list[13].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[2], -22404) + << "incorrect value for stec_sat_list[13].stec_coeff[2], expected " + "-22404, is " + << last_msg_->stec_sat_list[13].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_coeff[3], -29893) + << "incorrect value for stec_sat_list[13].stec_coeff[3], expected " + "-29893, is " + << last_msg_->stec_sat_list[13].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[13].stec_quality_indicator, 125) + << "incorrect value for stec_sat_list[13].stec_quality_indicator, " + "expected 125, is " + << last_msg_->stec_sat_list[13].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[13].sv_id.constellation, 188) + << "incorrect value for stec_sat_list[13].sv_id.constellation, expected " + "188, is " + << last_msg_->stec_sat_list[13].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[13].sv_id.satId, 224) + << "incorrect value for stec_sat_list[13].sv_id.satId, expected 224, is " + << last_msg_->stec_sat_list[13].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[0], -10053) + << "incorrect value for stec_sat_list[14].stec_coeff[0], expected " + "-10053, is " + << last_msg_->stec_sat_list[14].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[1], -24897) + << "incorrect value for stec_sat_list[14].stec_coeff[1], expected " + "-24897, is " + << last_msg_->stec_sat_list[14].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[2], 23629) + << "incorrect value for stec_sat_list[14].stec_coeff[2], expected 23629, " + "is " + << last_msg_->stec_sat_list[14].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_coeff[3], -710) + << "incorrect value for stec_sat_list[14].stec_coeff[3], expected -710, " + "is " + << last_msg_->stec_sat_list[14].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[14].stec_quality_indicator, 51) + << "incorrect value for stec_sat_list[14].stec_quality_indicator, " + "expected 51, is " + << last_msg_->stec_sat_list[14].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[14].sv_id.constellation, 118) + << "incorrect value for stec_sat_list[14].sv_id.constellation, expected " + "118, is " + << last_msg_->stec_sat_list[14].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[14].sv_id.satId, 106) + << "incorrect value for stec_sat_list[14].sv_id.satId, expected 106, is " + << last_msg_->stec_sat_list[14].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[0], -26103) + << "incorrect value for stec_sat_list[15].stec_coeff[0], expected " + "-26103, is " + << last_msg_->stec_sat_list[15].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[1], -9539) + << "incorrect value for stec_sat_list[15].stec_coeff[1], expected -9539, " + "is " + << last_msg_->stec_sat_list[15].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[2], -11971) + << "incorrect value for stec_sat_list[15].stec_coeff[2], expected " + "-11971, is " + << last_msg_->stec_sat_list[15].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_coeff[3], 20993) + << "incorrect value for stec_sat_list[15].stec_coeff[3], expected 20993, " + "is " + << last_msg_->stec_sat_list[15].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[15].stec_quality_indicator, 165) + << "incorrect value for stec_sat_list[15].stec_quality_indicator, " + "expected 165, is " + << last_msg_->stec_sat_list[15].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[15].sv_id.constellation, 150) + << "incorrect value for stec_sat_list[15].sv_id.constellation, expected " + "150, is " + << last_msg_->stec_sat_list[15].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[15].sv_id.satId, 132) + << "incorrect value for stec_sat_list[15].sv_id.satId, expected 132, is " + << last_msg_->stec_sat_list[15].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[0], -18891) + << "incorrect value for stec_sat_list[16].stec_coeff[0], expected " + "-18891, is " + << last_msg_->stec_sat_list[16].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[1], -16272) + << "incorrect value for stec_sat_list[16].stec_coeff[1], expected " + "-16272, is " + << last_msg_->stec_sat_list[16].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[2], -22578) + << "incorrect value for stec_sat_list[16].stec_coeff[2], expected " + "-22578, is " + << last_msg_->stec_sat_list[16].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_coeff[3], -2915) + << "incorrect value for stec_sat_list[16].stec_coeff[3], expected -2915, " + "is " + << last_msg_->stec_sat_list[16].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[16].stec_quality_indicator, 23) + << "incorrect value for stec_sat_list[16].stec_quality_indicator, " + "expected 23, is " + << last_msg_->stec_sat_list[16].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[16].sv_id.constellation, 196) + << "incorrect value for stec_sat_list[16].sv_id.constellation, expected " + "196, is " + << last_msg_->stec_sat_list[16].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[16].sv_id.satId, 181) + << "incorrect value for stec_sat_list[16].sv_id.satId, expected 181, is " + << last_msg_->stec_sat_list[16].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[0], 15833) + << "incorrect value for stec_sat_list[17].stec_coeff[0], expected 15833, " + "is " + << last_msg_->stec_sat_list[17].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[1], 24920) + << "incorrect value for stec_sat_list[17].stec_coeff[1], expected 24920, " + "is " + << last_msg_->stec_sat_list[17].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[2], -13879) + << "incorrect value for stec_sat_list[17].stec_coeff[2], expected " + "-13879, is " + << last_msg_->stec_sat_list[17].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_coeff[3], -1206) + << "incorrect value for stec_sat_list[17].stec_coeff[3], expected -1206, " + "is " + << last_msg_->stec_sat_list[17].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[17].stec_quality_indicator, 189) + << "incorrect value for stec_sat_list[17].stec_quality_indicator, " + "expected 189, is " + << last_msg_->stec_sat_list[17].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[17].sv_id.constellation, 1) + << "incorrect value for stec_sat_list[17].sv_id.constellation, expected " + "1, is " + << last_msg_->stec_sat_list[17].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[17].sv_id.satId, 35) + << "incorrect value for stec_sat_list[17].sv_id.satId, expected 35, is " + << last_msg_->stec_sat_list[17].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[0], 14008) + << "incorrect value for stec_sat_list[18].stec_coeff[0], expected 14008, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[1], 18996) + << "incorrect value for stec_sat_list[18].stec_coeff[1], expected 18996, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[2], 2798) + << "incorrect value for stec_sat_list[18].stec_coeff[2], expected 2798, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_coeff[3], 5761) + << "incorrect value for stec_sat_list[18].stec_coeff[3], expected 5761, " + "is " + << last_msg_->stec_sat_list[18].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[18].stec_quality_indicator, 104) + << "incorrect value for stec_sat_list[18].stec_quality_indicator, " + "expected 104, is " + << last_msg_->stec_sat_list[18].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[18].sv_id.constellation, 14) + << "incorrect value for stec_sat_list[18].sv_id.constellation, expected " + "14, is " + << last_msg_->stec_sat_list[18].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[18].sv_id.satId, 217) + << "incorrect value for stec_sat_list[18].sv_id.satId, expected 217, is " + << last_msg_->stec_sat_list[18].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[0], -25256) + << "incorrect value for stec_sat_list[19].stec_coeff[0], expected " + "-25256, is " + << last_msg_->stec_sat_list[19].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[1], -15330) + << "incorrect value for stec_sat_list[19].stec_coeff[1], expected " + "-15330, is " + << last_msg_->stec_sat_list[19].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[2], 6831) + << "incorrect value for stec_sat_list[19].stec_coeff[2], expected 6831, " + "is " + << last_msg_->stec_sat_list[19].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_coeff[3], 8780) + << "incorrect value for stec_sat_list[19].stec_coeff[3], expected 8780, " + "is " + << last_msg_->stec_sat_list[19].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[19].stec_quality_indicator, 109) + << "incorrect value for stec_sat_list[19].stec_quality_indicator, " + "expected 109, is " + << last_msg_->stec_sat_list[19].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[19].sv_id.constellation, 226) + << "incorrect value for stec_sat_list[19].sv_id.constellation, expected " + "226, is " + << last_msg_->stec_sat_list[19].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[19].sv_id.satId, 178) + << "incorrect value for stec_sat_list[19].sv_id.satId, expected 178, is " + << last_msg_->stec_sat_list[19].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[0], 3304) + << "incorrect value for stec_sat_list[20].stec_coeff[0], expected 3304, " + "is " + << last_msg_->stec_sat_list[20].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[1], -2893) + << "incorrect value for stec_sat_list[20].stec_coeff[1], expected -2893, " + "is " + << last_msg_->stec_sat_list[20].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[2], -25841) + << "incorrect value for stec_sat_list[20].stec_coeff[2], expected " + "-25841, is " + << last_msg_->stec_sat_list[20].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_coeff[3], -13628) + << "incorrect value for stec_sat_list[20].stec_coeff[3], expected " + "-13628, is " + << last_msg_->stec_sat_list[20].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[20].stec_quality_indicator, 154) + << "incorrect value for stec_sat_list[20].stec_quality_indicator, " + "expected 154, is " + << last_msg_->stec_sat_list[20].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[20].sv_id.constellation, 220) + << "incorrect value for stec_sat_list[20].sv_id.constellation, expected " + "220, is " + << last_msg_->stec_sat_list[20].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[20].sv_id.satId, 116) + << "incorrect value for stec_sat_list[20].sv_id.satId, expected 116, is " + << last_msg_->stec_sat_list[20].sv_id.satId; + EXPECT_EQ(last_msg_->stec_sat_list[21].stec_coeff[0], -10742) + << "incorrect value for stec_sat_list[21].stec_coeff[0], expected " + "-10742, is " + << last_msg_->stec_sat_list[21].stec_coeff[0]; + EXPECT_EQ(last_msg_->stec_sat_list[21].stec_coeff[1], 10098) + << "incorrect value for stec_sat_list[21].stec_coeff[1], expected 10098, " + "is " + << last_msg_->stec_sat_list[21].stec_coeff[1]; + EXPECT_EQ(last_msg_->stec_sat_list[21].stec_coeff[2], 7413) + << "incorrect value for stec_sat_list[21].stec_coeff[2], expected 7413, " + "is " + << last_msg_->stec_sat_list[21].stec_coeff[2]; + EXPECT_EQ(last_msg_->stec_sat_list[21].stec_coeff[3], 17645) + << "incorrect value for stec_sat_list[21].stec_coeff[3], expected 17645, " + "is " + << last_msg_->stec_sat_list[21].stec_coeff[3]; + EXPECT_EQ(last_msg_->stec_sat_list[21].stec_quality_indicator, 115) + << "incorrect value for stec_sat_list[21].stec_quality_indicator, " + "expected 115, is " + << last_msg_->stec_sat_list[21].stec_quality_indicator; + EXPECT_EQ(last_msg_->stec_sat_list[21].sv_id.constellation, 70) + << "incorrect value for stec_sat_list[21].sv_id.constellation, expected " + "70, is " + << last_msg_->stec_sat_list[21].sv_id.constellation; + EXPECT_EQ(last_msg_->stec_sat_list[21].sv_id.satId, 72) + << "incorrect value for stec_sat_list[21].sv_id.satId, expected 72, is " + << last_msg_->stec_sat_list[21].sv_id.satId; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc new file mode 100644 index 0000000000..17176901ec --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_ssr_MsgSsrTileDefinitionDepA.cc @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_ssr_tile_definition_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_ssr_tile_definition_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_ssr_MsgSsrTileDefinitionDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, 185, 9, 181, 162, 240, + 65, 19, 255, 143, 21, 191, 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_ssr_tile_definition_dep_a_t *test_msg = + (msg_ssr_tile_definition_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->bitmask = 11259375; + test_msg->cols = 48917; + test_msg->corner_nw_lat = -18168; + test_msg->corner_nw_lon = -19191; + test_msg->rows = 36863; + test_msg->spacing_lat = 61602; + test_msg->spacing_lon = 4929; + test_msg->tile_id = 63410; + test_msg->tile_set_id = 48697; + + EXPECT_EQ(send_message(0x5f6, 34248, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 34248); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->bitmask, 11259375) + << "incorrect value for bitmask, expected 11259375, is " + << last_msg_->bitmask; + EXPECT_EQ(last_msg_->cols, 48917) + << "incorrect value for cols, expected 48917, is " << last_msg_->cols; + EXPECT_EQ(last_msg_->corner_nw_lat, -18168) + << "incorrect value for corner_nw_lat, expected -18168, is " + << last_msg_->corner_nw_lat; + EXPECT_EQ(last_msg_->corner_nw_lon, -19191) + << "incorrect value for corner_nw_lon, expected -19191, is " + << last_msg_->corner_nw_lon; + EXPECT_EQ(last_msg_->rows, 36863) + << "incorrect value for rows, expected 36863, is " << last_msg_->rows; + EXPECT_EQ(last_msg_->spacing_lat, 61602) + << "incorrect value for spacing_lat, expected 61602, is " + << last_msg_->spacing_lat; + EXPECT_EQ(last_msg_->spacing_lon, 4929) + << "incorrect value for spacing_lon, expected 4929, is " + << last_msg_->spacing_lon; + EXPECT_EQ(last_msg_->tile_id, 63410) + << "incorrect value for tile_id, expected 63410, is " + << last_msg_->tile_id; + EXPECT_EQ(last_msg_->tile_set_id, 48697) + << "incorrect value for tile_set_id, expected 48697, is " + << last_msg_->tile_set_id; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc b/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc new file mode 100644 index 0000000000..2f8f963c49 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetry.cc @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_system_MsgCsacTelemetry0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_system_MsgCsacTelemetry0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_csac_telemetry_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_csac_telemetry_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_system_MsgCsacTelemetry0, Test) { + uint8_t encoded_frame[] = { + 85, 4, 255, 244, 169, 10, 105, 115, 111, + 109, 101, 32, 100, 97, 116, 97, 229, 94, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_csac_telemetry_t *test_msg = (msg_csac_telemetry_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->id = 105; + { + const char assign_string[] = {(char)115, (char)111, (char)109, + (char)101, (char)32, (char)100, + (char)97, (char)116, (char)97}; + memcpy(test_msg->telemetry, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->telemetry) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xff04, 43508, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 43508); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->id, 105) + << "incorrect value for id, expected 105, is " << last_msg_->id; + { + const char check_string[] = {(char)115, (char)111, (char)109, + (char)101, (char)32, (char)100, + (char)97, (char)116, (char)97}; + EXPECT_EQ(memcmp(last_msg_->telemetry, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->telemetry, expected string '" + << check_string << "', is '" << last_msg_->telemetry << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc b/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc new file mode 100644 index 0000000000..a0cd92fe4d --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_system_MsgCsacTelemetryLabels.cc @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_csac_telemetry_labels_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_csac_telemetry_labels_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_system_MsgCsacTelemetryLabels0, Test) { + uint8_t encoded_frame[] = { + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, + 101, 32, 108, 97, 98, 101, 108, 115, 86, 236, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_csac_telemetry_labels_t *test_msg = + (msg_csac_telemetry_labels_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->id = 186; + { + const char assign_string[] = {(char)115, (char)111, (char)109, (char)101, + (char)32, (char)108, (char)97, (char)98, + (char)101, (char)108, (char)115}; + memcpy(test_msg->telemetry_labels, assign_string, sizeof(assign_string)); + if (sizeof(test_msg->telemetry_labels) == 0) { + test_msg_len = (uint8_t)(test_msg_len + sizeof(assign_string)); + } + } + + EXPECT_EQ(send_message(0xff05, 51291, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 51291); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->id, 186) + << "incorrect value for id, expected 186, is " << last_msg_->id; + { + const char check_string[] = {(char)115, (char)111, (char)109, (char)101, + (char)32, (char)108, (char)97, (char)98, + (char)101, (char)108, (char)115}; + EXPECT_EQ( + memcmp(last_msg_->telemetry_labels, check_string, sizeof(check_string)), + 0) + << "incorrect value for last_msg_->telemetry_labels, expected string '" + << check_string << "', is '" << last_msg_->telemetry_labels << "'"; + } +} diff --git a/c/test/legacy/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc b/c/test/legacy/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc new file mode 100644 index 0000000000..76c289cb7a --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_system_MsgGnssTimeOffset.cc @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_system_MsgGnssTimeOffset0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_system_MsgGnssTimeOffset0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_gnss_time_offset_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_gnss_time_offset_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_system_MsgGnssTimeOffset0, Test) { + uint8_t encoded_frame[] = { + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_gnss_time_offset_t *test_msg = (msg_gnss_time_offset_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 221; + test_msg->microseconds = 9494; + test_msg->milliseconds = 1728664402; + test_msg->weeks = 14857; + + EXPECT_EQ(send_message(0xff07, 3862, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 3862); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 221) + << "incorrect value for flags, expected 221, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->microseconds, 9494) + << "incorrect value for microseconds, expected 9494, is " + << last_msg_->microseconds; + EXPECT_EQ(last_msg_->milliseconds, 1728664402) + << "incorrect value for milliseconds, expected 1728664402, is " + << last_msg_->milliseconds; + EXPECT_EQ(last_msg_->weeks, 14857) + << "incorrect value for weeks, expected 14857, is " << last_msg_->weeks; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_system_MsgPpsTime.cc b/c/test/legacy/cpp/auto_check_sbp_system_MsgPpsTime.cc new file mode 100644 index 0000000000..1242ed6337 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_system_MsgPpsTime.cc @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_system_MsgPpsTime0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_system_MsgPpsTime0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_pps_time_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_pps_time_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_system_MsgPpsTime0, Test) { + uint8_t encoded_frame[] = { + 85, 8, 255, 222, 209, 9, 140, 146, 133, 197, 160, 0, 0, 0, 255, 125, 149, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_pps_time_t *test_msg = (msg_pps_time_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 255; + test_msg->time = 690508632716; + + EXPECT_EQ(send_message(0xff08, 53726, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 53726); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 255) + << "incorrect value for flags, expected 255, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->time, 690508632716) + << "incorrect value for time, expected 690508632716, is " + << last_msg_->time; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_system_MsgStatusReport.cc b/c/test/legacy/cpp/auto_check_sbp_system_MsgStatusReport.cc new file mode 100644 index 0000000000..bf8fe574e9 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_system_MsgStatusReport.cc @@ -0,0 +1,1095 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_system_MsgStatusReport0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_system_MsgStatusReport0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_status_report_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_status_report_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_system_MsgStatusReport0, Test) { + uint8_t encoded_frame[] = { + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, 233, + 21, 208, 98, 247, 203, 221, 198, 156, 207, 217, 238, 162, 136, 154, 11, + 114, 236, 134, 235, 12, 133, 9, 30, 175, 145, 26, 114, 215, 20, 146, + 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, 5, 248, 225, 149, + 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, 103, 68, 76, 184, 33, + 206, 194, 163, 123, 30, 151, 176, 149, 172, 184, 231, 118, 230, 200, 168, + 100, 109, 10, 233, 4, 60, 247, 82, 215, 166, 28, 138, 110, 45, 98, + 218, 244, 179, 126, 107, 92, 124, 94, 157, 42, 187, 124, 6, 97, 247, + 160, 188, 110, 120, 254, 214, 110, 51, 240, 164, 147, 18, 74, 178, 67, + 4, 27, 73, 190, 64, 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, + 40, 161, 173, 242, 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, + 40, 191, 113, 230, 200, 72, 8, 215, 245, 78, 59, 222, 250, 115, 32, + 33, 30, 211, 170, 145, 92, 157, 75, 24, 169, 6, 55, 62, 8, 107, + 82, 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, + 148, 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, 23, + 248, 192, 20, 83, 195, 95, 180, 54, 36, 186, 75, 64, 20, 157, 133, + 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, 245, 30, 228, 88, 142, + 212, 53, 224, 158, 166, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_status_report_t *test_msg = (msg_status_report_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->reporting_system = 64850; + test_msg->sbp_version = 24497; + test_msg->sequence = 1519336451; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[0].component = 52215; + test_msg->status[0].generic = 221; + test_msg->status[0].specific = 198; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[1].component = 53148; + test_msg->status[1].generic = 217; + test_msg->status[1].specific = 238; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[2].component = 34978; + test_msg->status[2].generic = 154; + test_msg->status[2].specific = 11; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[3].component = 60530; + test_msg->status[3].generic = 134; + test_msg->status[3].specific = 235; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[4].component = 34060; + test_msg->status[4].generic = 9; + test_msg->status[4].specific = 30; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[5].component = 37295; + test_msg->status[5].generic = 26; + test_msg->status[5].specific = 114; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[6].component = 5335; + test_msg->status[6].generic = 146; + test_msg->status[6].specific = 249; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[7].component = 13878; + test_msg->status[7].generic = 133; + test_msg->status[7].specific = 193; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[8].component = 47722; + test_msg->status[8].generic = 210; + test_msg->status[8].specific = 183; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[9].component = 33024; + test_msg->status[9].generic = 5; + test_msg->status[9].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[10].component = 38369; + test_msg->status[10].generic = 135; + test_msg->status[10].specific = 127; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[11].component = 6658; + test_msg->status[11].generic = 88; + test_msg->status[11].specific = 92; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[12].component = 26378; + test_msg->status[12].generic = 73; + test_msg->status[12].specific = 3; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[13].component = 17511; + test_msg->status[13].generic = 76; + test_msg->status[13].specific = 184; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[14].component = 52769; + test_msg->status[14].generic = 194; + test_msg->status[14].specific = 163; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[15].component = 7803; + test_msg->status[15].generic = 151; + test_msg->status[15].specific = 176; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[16].component = 44181; + test_msg->status[16].generic = 184; + test_msg->status[16].specific = 231; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[17].component = 58998; + test_msg->status[17].generic = 200; + test_msg->status[17].specific = 168; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[18].component = 28004; + test_msg->status[18].generic = 10; + test_msg->status[18].specific = 233; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[19].component = 15364; + test_msg->status[19].generic = 247; + test_msg->status[19].specific = 82; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[20].component = 42711; + test_msg->status[20].generic = 28; + test_msg->status[20].specific = 138; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[21].component = 11630; + test_msg->status[21].generic = 98; + test_msg->status[21].specific = 218; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[22].component = 46068; + test_msg->status[22].generic = 126; + test_msg->status[22].specific = 107; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[23].component = 31836; + test_msg->status[23].generic = 94; + test_msg->status[23].specific = 157; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[24].component = 47914; + test_msg->status[24].generic = 124; + test_msg->status[24].specific = 6; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[25].component = 63329; + test_msg->status[25].generic = 160; + test_msg->status[25].specific = 188; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[26].component = 30830; + test_msg->status[26].generic = 254; + test_msg->status[26].specific = 214; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[27].component = 13166; + test_msg->status[27].generic = 240; + test_msg->status[27].specific = 164; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[28].component = 4755; + test_msg->status[28].generic = 74; + test_msg->status[28].specific = 178; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[29].component = 1091; + test_msg->status[29].generic = 27; + test_msg->status[29].specific = 73; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[30].component = 16574; + test_msg->status[30].generic = 179; + test_msg->status[30].specific = 146; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[31].component = 39293; + test_msg->status[31].generic = 192; + test_msg->status[31].specific = 46; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[32].component = 17098; + test_msg->status[32].generic = 248; + test_msg->status[32].specific = 46; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[33].component = 41256; + test_msg->status[33].generic = 173; + test_msg->status[33].specific = 242; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[34].component = 982; + test_msg->status[34].generic = 11; + test_msg->status[34].specific = 1; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[35].component = 18038; + test_msg->status[35].generic = 162; + test_msg->status[35].specific = 61; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[36].component = 7090; + test_msg->status[36].generic = 156; + test_msg->status[36].specific = 40; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[37].component = 29119; + test_msg->status[37].generic = 230; + test_msg->status[37].specific = 200; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[38].component = 2120; + test_msg->status[38].generic = 215; + test_msg->status[38].specific = 245; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[39].component = 15182; + test_msg->status[39].generic = 222; + test_msg->status[39].specific = 250; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[40].component = 8307; + test_msg->status[40].generic = 33; + test_msg->status[40].specific = 30; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[41].component = 43731; + test_msg->status[41].generic = 145; + test_msg->status[41].specific = 92; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[42].component = 19357; + test_msg->status[42].generic = 24; + test_msg->status[42].specific = 169; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[43].component = 14086; + test_msg->status[43].generic = 62; + test_msg->status[43].specific = 8; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[44].component = 21099; + test_msg->status[44].generic = 140; + test_msg->status[44].specific = 49; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[45].component = 31411; + test_msg->status[45].generic = 90; + test_msg->status[45].specific = 71; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[46].component = 22556; + test_msg->status[46].generic = 103; + test_msg->status[46].specific = 51; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[47].component = 18609; + test_msg->status[47].generic = 93; + test_msg->status[47].specific = 39; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[48].component = 2964; + test_msg->status[48].generic = 202; + test_msg->status[48].specific = 42; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[49].component = 23586; + test_msg->status[49].generic = 204; + test_msg->status[49].specific = 102; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[50].component = 25117; + test_msg->status[50].generic = 249; + test_msg->status[50].specific = 91; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[51].component = 24454; + test_msg->status[51].generic = 23; + test_msg->status[51].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[52].component = 5312; + test_msg->status[52].generic = 83; + test_msg->status[52].specific = 195; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[53].component = 46175; + test_msg->status[53].generic = 54; + test_msg->status[53].specific = 36; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[54].component = 19386; + test_msg->status[54].generic = 64; + test_msg->status[54].specific = 20; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[55].component = 34205; + test_msg->status[55].generic = 12; + test_msg->status[55].specific = 149; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[56].component = 3612; + test_msg->status[56].generic = 185; + test_msg->status[56].specific = 129; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[57].component = 61285; + test_msg->status[57].generic = 74; + test_msg->status[57].specific = 248; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[58].component = 7925; + test_msg->status[58].generic = 228; + test_msg->status[58].specific = 88; + if (sizeof(test_msg->status) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->status[0])); + } + test_msg->status[59].component = 54414; + test_msg->status[59].generic = 53; + test_msg->status[59].specific = 224; + test_msg->uptime = 1657804265; + + EXPECT_EQ(send_message(0xfffe, 21510, test_msg_len, test_msg_storage), + SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 21510); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->reporting_system, 64850) + << "incorrect value for reporting_system, expected 64850, is " + << last_msg_->reporting_system; + EXPECT_EQ(last_msg_->sbp_version, 24497) + << "incorrect value for sbp_version, expected 24497, is " + << last_msg_->sbp_version; + EXPECT_EQ(last_msg_->sequence, 1519336451) + << "incorrect value for sequence, expected 1519336451, is " + << last_msg_->sequence; + EXPECT_EQ(last_msg_->status[0].component, 52215) + << "incorrect value for status[0].component, expected 52215, is " + << last_msg_->status[0].component; + EXPECT_EQ(last_msg_->status[0].generic, 221) + << "incorrect value for status[0].generic, expected 221, is " + << last_msg_->status[0].generic; + EXPECT_EQ(last_msg_->status[0].specific, 198) + << "incorrect value for status[0].specific, expected 198, is " + << last_msg_->status[0].specific; + EXPECT_EQ(last_msg_->status[1].component, 53148) + << "incorrect value for status[1].component, expected 53148, is " + << last_msg_->status[1].component; + EXPECT_EQ(last_msg_->status[1].generic, 217) + << "incorrect value for status[1].generic, expected 217, is " + << last_msg_->status[1].generic; + EXPECT_EQ(last_msg_->status[1].specific, 238) + << "incorrect value for status[1].specific, expected 238, is " + << last_msg_->status[1].specific; + EXPECT_EQ(last_msg_->status[2].component, 34978) + << "incorrect value for status[2].component, expected 34978, is " + << last_msg_->status[2].component; + EXPECT_EQ(last_msg_->status[2].generic, 154) + << "incorrect value for status[2].generic, expected 154, is " + << last_msg_->status[2].generic; + EXPECT_EQ(last_msg_->status[2].specific, 11) + << "incorrect value for status[2].specific, expected 11, is " + << last_msg_->status[2].specific; + EXPECT_EQ(last_msg_->status[3].component, 60530) + << "incorrect value for status[3].component, expected 60530, is " + << last_msg_->status[3].component; + EXPECT_EQ(last_msg_->status[3].generic, 134) + << "incorrect value for status[3].generic, expected 134, is " + << last_msg_->status[3].generic; + EXPECT_EQ(last_msg_->status[3].specific, 235) + << "incorrect value for status[3].specific, expected 235, is " + << last_msg_->status[3].specific; + EXPECT_EQ(last_msg_->status[4].component, 34060) + << "incorrect value for status[4].component, expected 34060, is " + << last_msg_->status[4].component; + EXPECT_EQ(last_msg_->status[4].generic, 9) + << "incorrect value for status[4].generic, expected 9, is " + << last_msg_->status[4].generic; + EXPECT_EQ(last_msg_->status[4].specific, 30) + << "incorrect value for status[4].specific, expected 30, is " + << last_msg_->status[4].specific; + EXPECT_EQ(last_msg_->status[5].component, 37295) + << "incorrect value for status[5].component, expected 37295, is " + << last_msg_->status[5].component; + EXPECT_EQ(last_msg_->status[5].generic, 26) + << "incorrect value for status[5].generic, expected 26, is " + << last_msg_->status[5].generic; + EXPECT_EQ(last_msg_->status[5].specific, 114) + << "incorrect value for status[5].specific, expected 114, is " + << last_msg_->status[5].specific; + EXPECT_EQ(last_msg_->status[6].component, 5335) + << "incorrect value for status[6].component, expected 5335, is " + << last_msg_->status[6].component; + EXPECT_EQ(last_msg_->status[6].generic, 146) + << "incorrect value for status[6].generic, expected 146, is " + << last_msg_->status[6].generic; + EXPECT_EQ(last_msg_->status[6].specific, 249) + << "incorrect value for status[6].specific, expected 249, is " + << last_msg_->status[6].specific; + EXPECT_EQ(last_msg_->status[7].component, 13878) + << "incorrect value for status[7].component, expected 13878, is " + << last_msg_->status[7].component; + EXPECT_EQ(last_msg_->status[7].generic, 133) + << "incorrect value for status[7].generic, expected 133, is " + << last_msg_->status[7].generic; + EXPECT_EQ(last_msg_->status[7].specific, 193) + << "incorrect value for status[7].specific, expected 193, is " + << last_msg_->status[7].specific; + EXPECT_EQ(last_msg_->status[8].component, 47722) + << "incorrect value for status[8].component, expected 47722, is " + << last_msg_->status[8].component; + EXPECT_EQ(last_msg_->status[8].generic, 210) + << "incorrect value for status[8].generic, expected 210, is " + << last_msg_->status[8].generic; + EXPECT_EQ(last_msg_->status[8].specific, 183) + << "incorrect value for status[8].specific, expected 183, is " + << last_msg_->status[8].specific; + EXPECT_EQ(last_msg_->status[9].component, 33024) + << "incorrect value for status[9].component, expected 33024, is " + << last_msg_->status[9].component; + EXPECT_EQ(last_msg_->status[9].generic, 5) + << "incorrect value for status[9].generic, expected 5, is " + << last_msg_->status[9].generic; + EXPECT_EQ(last_msg_->status[9].specific, 248) + << "incorrect value for status[9].specific, expected 248, is " + << last_msg_->status[9].specific; + EXPECT_EQ(last_msg_->status[10].component, 38369) + << "incorrect value for status[10].component, expected 38369, is " + << last_msg_->status[10].component; + EXPECT_EQ(last_msg_->status[10].generic, 135) + << "incorrect value for status[10].generic, expected 135, is " + << last_msg_->status[10].generic; + EXPECT_EQ(last_msg_->status[10].specific, 127) + << "incorrect value for status[10].specific, expected 127, is " + << last_msg_->status[10].specific; + EXPECT_EQ(last_msg_->status[11].component, 6658) + << "incorrect value for status[11].component, expected 6658, is " + << last_msg_->status[11].component; + EXPECT_EQ(last_msg_->status[11].generic, 88) + << "incorrect value for status[11].generic, expected 88, is " + << last_msg_->status[11].generic; + EXPECT_EQ(last_msg_->status[11].specific, 92) + << "incorrect value for status[11].specific, expected 92, is " + << last_msg_->status[11].specific; + EXPECT_EQ(last_msg_->status[12].component, 26378) + << "incorrect value for status[12].component, expected 26378, is " + << last_msg_->status[12].component; + EXPECT_EQ(last_msg_->status[12].generic, 73) + << "incorrect value for status[12].generic, expected 73, is " + << last_msg_->status[12].generic; + EXPECT_EQ(last_msg_->status[12].specific, 3) + << "incorrect value for status[12].specific, expected 3, is " + << last_msg_->status[12].specific; + EXPECT_EQ(last_msg_->status[13].component, 17511) + << "incorrect value for status[13].component, expected 17511, is " + << last_msg_->status[13].component; + EXPECT_EQ(last_msg_->status[13].generic, 76) + << "incorrect value for status[13].generic, expected 76, is " + << last_msg_->status[13].generic; + EXPECT_EQ(last_msg_->status[13].specific, 184) + << "incorrect value for status[13].specific, expected 184, is " + << last_msg_->status[13].specific; + EXPECT_EQ(last_msg_->status[14].component, 52769) + << "incorrect value for status[14].component, expected 52769, is " + << last_msg_->status[14].component; + EXPECT_EQ(last_msg_->status[14].generic, 194) + << "incorrect value for status[14].generic, expected 194, is " + << last_msg_->status[14].generic; + EXPECT_EQ(last_msg_->status[14].specific, 163) + << "incorrect value for status[14].specific, expected 163, is " + << last_msg_->status[14].specific; + EXPECT_EQ(last_msg_->status[15].component, 7803) + << "incorrect value for status[15].component, expected 7803, is " + << last_msg_->status[15].component; + EXPECT_EQ(last_msg_->status[15].generic, 151) + << "incorrect value for status[15].generic, expected 151, is " + << last_msg_->status[15].generic; + EXPECT_EQ(last_msg_->status[15].specific, 176) + << "incorrect value for status[15].specific, expected 176, is " + << last_msg_->status[15].specific; + EXPECT_EQ(last_msg_->status[16].component, 44181) + << "incorrect value for status[16].component, expected 44181, is " + << last_msg_->status[16].component; + EXPECT_EQ(last_msg_->status[16].generic, 184) + << "incorrect value for status[16].generic, expected 184, is " + << last_msg_->status[16].generic; + EXPECT_EQ(last_msg_->status[16].specific, 231) + << "incorrect value for status[16].specific, expected 231, is " + << last_msg_->status[16].specific; + EXPECT_EQ(last_msg_->status[17].component, 58998) + << "incorrect value for status[17].component, expected 58998, is " + << last_msg_->status[17].component; + EXPECT_EQ(last_msg_->status[17].generic, 200) + << "incorrect value for status[17].generic, expected 200, is " + << last_msg_->status[17].generic; + EXPECT_EQ(last_msg_->status[17].specific, 168) + << "incorrect value for status[17].specific, expected 168, is " + << last_msg_->status[17].specific; + EXPECT_EQ(last_msg_->status[18].component, 28004) + << "incorrect value for status[18].component, expected 28004, is " + << last_msg_->status[18].component; + EXPECT_EQ(last_msg_->status[18].generic, 10) + << "incorrect value for status[18].generic, expected 10, is " + << last_msg_->status[18].generic; + EXPECT_EQ(last_msg_->status[18].specific, 233) + << "incorrect value for status[18].specific, expected 233, is " + << last_msg_->status[18].specific; + EXPECT_EQ(last_msg_->status[19].component, 15364) + << "incorrect value for status[19].component, expected 15364, is " + << last_msg_->status[19].component; + EXPECT_EQ(last_msg_->status[19].generic, 247) + << "incorrect value for status[19].generic, expected 247, is " + << last_msg_->status[19].generic; + EXPECT_EQ(last_msg_->status[19].specific, 82) + << "incorrect value for status[19].specific, expected 82, is " + << last_msg_->status[19].specific; + EXPECT_EQ(last_msg_->status[20].component, 42711) + << "incorrect value for status[20].component, expected 42711, is " + << last_msg_->status[20].component; + EXPECT_EQ(last_msg_->status[20].generic, 28) + << "incorrect value for status[20].generic, expected 28, is " + << last_msg_->status[20].generic; + EXPECT_EQ(last_msg_->status[20].specific, 138) + << "incorrect value for status[20].specific, expected 138, is " + << last_msg_->status[20].specific; + EXPECT_EQ(last_msg_->status[21].component, 11630) + << "incorrect value for status[21].component, expected 11630, is " + << last_msg_->status[21].component; + EXPECT_EQ(last_msg_->status[21].generic, 98) + << "incorrect value for status[21].generic, expected 98, is " + << last_msg_->status[21].generic; + EXPECT_EQ(last_msg_->status[21].specific, 218) + << "incorrect value for status[21].specific, expected 218, is " + << last_msg_->status[21].specific; + EXPECT_EQ(last_msg_->status[22].component, 46068) + << "incorrect value for status[22].component, expected 46068, is " + << last_msg_->status[22].component; + EXPECT_EQ(last_msg_->status[22].generic, 126) + << "incorrect value for status[22].generic, expected 126, is " + << last_msg_->status[22].generic; + EXPECT_EQ(last_msg_->status[22].specific, 107) + << "incorrect value for status[22].specific, expected 107, is " + << last_msg_->status[22].specific; + EXPECT_EQ(last_msg_->status[23].component, 31836) + << "incorrect value for status[23].component, expected 31836, is " + << last_msg_->status[23].component; + EXPECT_EQ(last_msg_->status[23].generic, 94) + << "incorrect value for status[23].generic, expected 94, is " + << last_msg_->status[23].generic; + EXPECT_EQ(last_msg_->status[23].specific, 157) + << "incorrect value for status[23].specific, expected 157, is " + << last_msg_->status[23].specific; + EXPECT_EQ(last_msg_->status[24].component, 47914) + << "incorrect value for status[24].component, expected 47914, is " + << last_msg_->status[24].component; + EXPECT_EQ(last_msg_->status[24].generic, 124) + << "incorrect value for status[24].generic, expected 124, is " + << last_msg_->status[24].generic; + EXPECT_EQ(last_msg_->status[24].specific, 6) + << "incorrect value for status[24].specific, expected 6, is " + << last_msg_->status[24].specific; + EXPECT_EQ(last_msg_->status[25].component, 63329) + << "incorrect value for status[25].component, expected 63329, is " + << last_msg_->status[25].component; + EXPECT_EQ(last_msg_->status[25].generic, 160) + << "incorrect value for status[25].generic, expected 160, is " + << last_msg_->status[25].generic; + EXPECT_EQ(last_msg_->status[25].specific, 188) + << "incorrect value for status[25].specific, expected 188, is " + << last_msg_->status[25].specific; + EXPECT_EQ(last_msg_->status[26].component, 30830) + << "incorrect value for status[26].component, expected 30830, is " + << last_msg_->status[26].component; + EXPECT_EQ(last_msg_->status[26].generic, 254) + << "incorrect value for status[26].generic, expected 254, is " + << last_msg_->status[26].generic; + EXPECT_EQ(last_msg_->status[26].specific, 214) + << "incorrect value for status[26].specific, expected 214, is " + << last_msg_->status[26].specific; + EXPECT_EQ(last_msg_->status[27].component, 13166) + << "incorrect value for status[27].component, expected 13166, is " + << last_msg_->status[27].component; + EXPECT_EQ(last_msg_->status[27].generic, 240) + << "incorrect value for status[27].generic, expected 240, is " + << last_msg_->status[27].generic; + EXPECT_EQ(last_msg_->status[27].specific, 164) + << "incorrect value for status[27].specific, expected 164, is " + << last_msg_->status[27].specific; + EXPECT_EQ(last_msg_->status[28].component, 4755) + << "incorrect value for status[28].component, expected 4755, is " + << last_msg_->status[28].component; + EXPECT_EQ(last_msg_->status[28].generic, 74) + << "incorrect value for status[28].generic, expected 74, is " + << last_msg_->status[28].generic; + EXPECT_EQ(last_msg_->status[28].specific, 178) + << "incorrect value for status[28].specific, expected 178, is " + << last_msg_->status[28].specific; + EXPECT_EQ(last_msg_->status[29].component, 1091) + << "incorrect value for status[29].component, expected 1091, is " + << last_msg_->status[29].component; + EXPECT_EQ(last_msg_->status[29].generic, 27) + << "incorrect value for status[29].generic, expected 27, is " + << last_msg_->status[29].generic; + EXPECT_EQ(last_msg_->status[29].specific, 73) + << "incorrect value for status[29].specific, expected 73, is " + << last_msg_->status[29].specific; + EXPECT_EQ(last_msg_->status[30].component, 16574) + << "incorrect value for status[30].component, expected 16574, is " + << last_msg_->status[30].component; + EXPECT_EQ(last_msg_->status[30].generic, 179) + << "incorrect value for status[30].generic, expected 179, is " + << last_msg_->status[30].generic; + EXPECT_EQ(last_msg_->status[30].specific, 146) + << "incorrect value for status[30].specific, expected 146, is " + << last_msg_->status[30].specific; + EXPECT_EQ(last_msg_->status[31].component, 39293) + << "incorrect value for status[31].component, expected 39293, is " + << last_msg_->status[31].component; + EXPECT_EQ(last_msg_->status[31].generic, 192) + << "incorrect value for status[31].generic, expected 192, is " + << last_msg_->status[31].generic; + EXPECT_EQ(last_msg_->status[31].specific, 46) + << "incorrect value for status[31].specific, expected 46, is " + << last_msg_->status[31].specific; + EXPECT_EQ(last_msg_->status[32].component, 17098) + << "incorrect value for status[32].component, expected 17098, is " + << last_msg_->status[32].component; + EXPECT_EQ(last_msg_->status[32].generic, 248) + << "incorrect value for status[32].generic, expected 248, is " + << last_msg_->status[32].generic; + EXPECT_EQ(last_msg_->status[32].specific, 46) + << "incorrect value for status[32].specific, expected 46, is " + << last_msg_->status[32].specific; + EXPECT_EQ(last_msg_->status[33].component, 41256) + << "incorrect value for status[33].component, expected 41256, is " + << last_msg_->status[33].component; + EXPECT_EQ(last_msg_->status[33].generic, 173) + << "incorrect value for status[33].generic, expected 173, is " + << last_msg_->status[33].generic; + EXPECT_EQ(last_msg_->status[33].specific, 242) + << "incorrect value for status[33].specific, expected 242, is " + << last_msg_->status[33].specific; + EXPECT_EQ(last_msg_->status[34].component, 982) + << "incorrect value for status[34].component, expected 982, is " + << last_msg_->status[34].component; + EXPECT_EQ(last_msg_->status[34].generic, 11) + << "incorrect value for status[34].generic, expected 11, is " + << last_msg_->status[34].generic; + EXPECT_EQ(last_msg_->status[34].specific, 1) + << "incorrect value for status[34].specific, expected 1, is " + << last_msg_->status[34].specific; + EXPECT_EQ(last_msg_->status[35].component, 18038) + << "incorrect value for status[35].component, expected 18038, is " + << last_msg_->status[35].component; + EXPECT_EQ(last_msg_->status[35].generic, 162) + << "incorrect value for status[35].generic, expected 162, is " + << last_msg_->status[35].generic; + EXPECT_EQ(last_msg_->status[35].specific, 61) + << "incorrect value for status[35].specific, expected 61, is " + << last_msg_->status[35].specific; + EXPECT_EQ(last_msg_->status[36].component, 7090) + << "incorrect value for status[36].component, expected 7090, is " + << last_msg_->status[36].component; + EXPECT_EQ(last_msg_->status[36].generic, 156) + << "incorrect value for status[36].generic, expected 156, is " + << last_msg_->status[36].generic; + EXPECT_EQ(last_msg_->status[36].specific, 40) + << "incorrect value for status[36].specific, expected 40, is " + << last_msg_->status[36].specific; + EXPECT_EQ(last_msg_->status[37].component, 29119) + << "incorrect value for status[37].component, expected 29119, is " + << last_msg_->status[37].component; + EXPECT_EQ(last_msg_->status[37].generic, 230) + << "incorrect value for status[37].generic, expected 230, is " + << last_msg_->status[37].generic; + EXPECT_EQ(last_msg_->status[37].specific, 200) + << "incorrect value for status[37].specific, expected 200, is " + << last_msg_->status[37].specific; + EXPECT_EQ(last_msg_->status[38].component, 2120) + << "incorrect value for status[38].component, expected 2120, is " + << last_msg_->status[38].component; + EXPECT_EQ(last_msg_->status[38].generic, 215) + << "incorrect value for status[38].generic, expected 215, is " + << last_msg_->status[38].generic; + EXPECT_EQ(last_msg_->status[38].specific, 245) + << "incorrect value for status[38].specific, expected 245, is " + << last_msg_->status[38].specific; + EXPECT_EQ(last_msg_->status[39].component, 15182) + << "incorrect value for status[39].component, expected 15182, is " + << last_msg_->status[39].component; + EXPECT_EQ(last_msg_->status[39].generic, 222) + << "incorrect value for status[39].generic, expected 222, is " + << last_msg_->status[39].generic; + EXPECT_EQ(last_msg_->status[39].specific, 250) + << "incorrect value for status[39].specific, expected 250, is " + << last_msg_->status[39].specific; + EXPECT_EQ(last_msg_->status[40].component, 8307) + << "incorrect value for status[40].component, expected 8307, is " + << last_msg_->status[40].component; + EXPECT_EQ(last_msg_->status[40].generic, 33) + << "incorrect value for status[40].generic, expected 33, is " + << last_msg_->status[40].generic; + EXPECT_EQ(last_msg_->status[40].specific, 30) + << "incorrect value for status[40].specific, expected 30, is " + << last_msg_->status[40].specific; + EXPECT_EQ(last_msg_->status[41].component, 43731) + << "incorrect value for status[41].component, expected 43731, is " + << last_msg_->status[41].component; + EXPECT_EQ(last_msg_->status[41].generic, 145) + << "incorrect value for status[41].generic, expected 145, is " + << last_msg_->status[41].generic; + EXPECT_EQ(last_msg_->status[41].specific, 92) + << "incorrect value for status[41].specific, expected 92, is " + << last_msg_->status[41].specific; + EXPECT_EQ(last_msg_->status[42].component, 19357) + << "incorrect value for status[42].component, expected 19357, is " + << last_msg_->status[42].component; + EXPECT_EQ(last_msg_->status[42].generic, 24) + << "incorrect value for status[42].generic, expected 24, is " + << last_msg_->status[42].generic; + EXPECT_EQ(last_msg_->status[42].specific, 169) + << "incorrect value for status[42].specific, expected 169, is " + << last_msg_->status[42].specific; + EXPECT_EQ(last_msg_->status[43].component, 14086) + << "incorrect value for status[43].component, expected 14086, is " + << last_msg_->status[43].component; + EXPECT_EQ(last_msg_->status[43].generic, 62) + << "incorrect value for status[43].generic, expected 62, is " + << last_msg_->status[43].generic; + EXPECT_EQ(last_msg_->status[43].specific, 8) + << "incorrect value for status[43].specific, expected 8, is " + << last_msg_->status[43].specific; + EXPECT_EQ(last_msg_->status[44].component, 21099) + << "incorrect value for status[44].component, expected 21099, is " + << last_msg_->status[44].component; + EXPECT_EQ(last_msg_->status[44].generic, 140) + << "incorrect value for status[44].generic, expected 140, is " + << last_msg_->status[44].generic; + EXPECT_EQ(last_msg_->status[44].specific, 49) + << "incorrect value for status[44].specific, expected 49, is " + << last_msg_->status[44].specific; + EXPECT_EQ(last_msg_->status[45].component, 31411) + << "incorrect value for status[45].component, expected 31411, is " + << last_msg_->status[45].component; + EXPECT_EQ(last_msg_->status[45].generic, 90) + << "incorrect value for status[45].generic, expected 90, is " + << last_msg_->status[45].generic; + EXPECT_EQ(last_msg_->status[45].specific, 71) + << "incorrect value for status[45].specific, expected 71, is " + << last_msg_->status[45].specific; + EXPECT_EQ(last_msg_->status[46].component, 22556) + << "incorrect value for status[46].component, expected 22556, is " + << last_msg_->status[46].component; + EXPECT_EQ(last_msg_->status[46].generic, 103) + << "incorrect value for status[46].generic, expected 103, is " + << last_msg_->status[46].generic; + EXPECT_EQ(last_msg_->status[46].specific, 51) + << "incorrect value for status[46].specific, expected 51, is " + << last_msg_->status[46].specific; + EXPECT_EQ(last_msg_->status[47].component, 18609) + << "incorrect value for status[47].component, expected 18609, is " + << last_msg_->status[47].component; + EXPECT_EQ(last_msg_->status[47].generic, 93) + << "incorrect value for status[47].generic, expected 93, is " + << last_msg_->status[47].generic; + EXPECT_EQ(last_msg_->status[47].specific, 39) + << "incorrect value for status[47].specific, expected 39, is " + << last_msg_->status[47].specific; + EXPECT_EQ(last_msg_->status[48].component, 2964) + << "incorrect value for status[48].component, expected 2964, is " + << last_msg_->status[48].component; + EXPECT_EQ(last_msg_->status[48].generic, 202) + << "incorrect value for status[48].generic, expected 202, is " + << last_msg_->status[48].generic; + EXPECT_EQ(last_msg_->status[48].specific, 42) + << "incorrect value for status[48].specific, expected 42, is " + << last_msg_->status[48].specific; + EXPECT_EQ(last_msg_->status[49].component, 23586) + << "incorrect value for status[49].component, expected 23586, is " + << last_msg_->status[49].component; + EXPECT_EQ(last_msg_->status[49].generic, 204) + << "incorrect value for status[49].generic, expected 204, is " + << last_msg_->status[49].generic; + EXPECT_EQ(last_msg_->status[49].specific, 102) + << "incorrect value for status[49].specific, expected 102, is " + << last_msg_->status[49].specific; + EXPECT_EQ(last_msg_->status[50].component, 25117) + << "incorrect value for status[50].component, expected 25117, is " + << last_msg_->status[50].component; + EXPECT_EQ(last_msg_->status[50].generic, 249) + << "incorrect value for status[50].generic, expected 249, is " + << last_msg_->status[50].generic; + EXPECT_EQ(last_msg_->status[50].specific, 91) + << "incorrect value for status[50].specific, expected 91, is " + << last_msg_->status[50].specific; + EXPECT_EQ(last_msg_->status[51].component, 24454) + << "incorrect value for status[51].component, expected 24454, is " + << last_msg_->status[51].component; + EXPECT_EQ(last_msg_->status[51].generic, 23) + << "incorrect value for status[51].generic, expected 23, is " + << last_msg_->status[51].generic; + EXPECT_EQ(last_msg_->status[51].specific, 248) + << "incorrect value for status[51].specific, expected 248, is " + << last_msg_->status[51].specific; + EXPECT_EQ(last_msg_->status[52].component, 5312) + << "incorrect value for status[52].component, expected 5312, is " + << last_msg_->status[52].component; + EXPECT_EQ(last_msg_->status[52].generic, 83) + << "incorrect value for status[52].generic, expected 83, is " + << last_msg_->status[52].generic; + EXPECT_EQ(last_msg_->status[52].specific, 195) + << "incorrect value for status[52].specific, expected 195, is " + << last_msg_->status[52].specific; + EXPECT_EQ(last_msg_->status[53].component, 46175) + << "incorrect value for status[53].component, expected 46175, is " + << last_msg_->status[53].component; + EXPECT_EQ(last_msg_->status[53].generic, 54) + << "incorrect value for status[53].generic, expected 54, is " + << last_msg_->status[53].generic; + EXPECT_EQ(last_msg_->status[53].specific, 36) + << "incorrect value for status[53].specific, expected 36, is " + << last_msg_->status[53].specific; + EXPECT_EQ(last_msg_->status[54].component, 19386) + << "incorrect value for status[54].component, expected 19386, is " + << last_msg_->status[54].component; + EXPECT_EQ(last_msg_->status[54].generic, 64) + << "incorrect value for status[54].generic, expected 64, is " + << last_msg_->status[54].generic; + EXPECT_EQ(last_msg_->status[54].specific, 20) + << "incorrect value for status[54].specific, expected 20, is " + << last_msg_->status[54].specific; + EXPECT_EQ(last_msg_->status[55].component, 34205) + << "incorrect value for status[55].component, expected 34205, is " + << last_msg_->status[55].component; + EXPECT_EQ(last_msg_->status[55].generic, 12) + << "incorrect value for status[55].generic, expected 12, is " + << last_msg_->status[55].generic; + EXPECT_EQ(last_msg_->status[55].specific, 149) + << "incorrect value for status[55].specific, expected 149, is " + << last_msg_->status[55].specific; + EXPECT_EQ(last_msg_->status[56].component, 3612) + << "incorrect value for status[56].component, expected 3612, is " + << last_msg_->status[56].component; + EXPECT_EQ(last_msg_->status[56].generic, 185) + << "incorrect value for status[56].generic, expected 185, is " + << last_msg_->status[56].generic; + EXPECT_EQ(last_msg_->status[56].specific, 129) + << "incorrect value for status[56].specific, expected 129, is " + << last_msg_->status[56].specific; + EXPECT_EQ(last_msg_->status[57].component, 61285) + << "incorrect value for status[57].component, expected 61285, is " + << last_msg_->status[57].component; + EXPECT_EQ(last_msg_->status[57].generic, 74) + << "incorrect value for status[57].generic, expected 74, is " + << last_msg_->status[57].generic; + EXPECT_EQ(last_msg_->status[57].specific, 248) + << "incorrect value for status[57].specific, expected 248, is " + << last_msg_->status[57].specific; + EXPECT_EQ(last_msg_->status[58].component, 7925) + << "incorrect value for status[58].component, expected 7925, is " + << last_msg_->status[58].component; + EXPECT_EQ(last_msg_->status[58].generic, 228) + << "incorrect value for status[58].generic, expected 228, is " + << last_msg_->status[58].generic; + EXPECT_EQ(last_msg_->status[58].specific, 88) + << "incorrect value for status[58].specific, expected 88, is " + << last_msg_->status[58].specific; + EXPECT_EQ(last_msg_->status[59].component, 54414) + << "incorrect value for status[59].component, expected 54414, is " + << last_msg_->status[59].component; + EXPECT_EQ(last_msg_->status[59].generic, 53) + << "incorrect value for status[59].generic, expected 53, is " + << last_msg_->status[59].generic; + EXPECT_EQ(last_msg_->status[59].specific, 224) + << "incorrect value for status[59].specific, expected 224, is " + << last_msg_->status[59].specific; + EXPECT_EQ(last_msg_->uptime, 1657804265) + << "incorrect value for uptime, expected 1657804265, is " + << last_msg_->uptime; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc new file mode 100644 index 0000000000..a085c5e43d --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIq.cc @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_tracking_MsgTrackingIq0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingIq0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_iq_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_iq_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingIq0, Test) { + uint8_t encoded_frame[] = { + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, + 55, 45, 38, 189, 88, 159, 19, 208, 12, 97, 167, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_iq_t *test_msg = (msg_tracking_iq_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->channel = 145; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[0].I = -9937; + test_msg->corrs[0].Q = 14319; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[1].I = 9773; + test_msg->corrs[1].Q = 22717; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[2].I = 5023; + test_msg->corrs[2].Q = 3280; + test_msg->sid.code = 203; + test_msg->sid.sat = 121; + + EXPECT_EQ(send_message(0x2d, 20482, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 20482); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->channel, 145) + << "incorrect value for channel, expected 145, is " << last_msg_->channel; + EXPECT_EQ(last_msg_->corrs[0].I, -9937) + << "incorrect value for corrs[0].I, expected -9937, is " + << last_msg_->corrs[0].I; + EXPECT_EQ(last_msg_->corrs[0].Q, 14319) + << "incorrect value for corrs[0].Q, expected 14319, is " + << last_msg_->corrs[0].Q; + EXPECT_EQ(last_msg_->corrs[1].I, 9773) + << "incorrect value for corrs[1].I, expected 9773, is " + << last_msg_->corrs[1].I; + EXPECT_EQ(last_msg_->corrs[1].Q, 22717) + << "incorrect value for corrs[1].Q, expected 22717, is " + << last_msg_->corrs[1].Q; + EXPECT_EQ(last_msg_->corrs[2].I, 5023) + << "incorrect value for corrs[2].I, expected 5023, is " + << last_msg_->corrs[2].I; + EXPECT_EQ(last_msg_->corrs[2].Q, 3280) + << "incorrect value for corrs[2].Q, expected 3280, is " + << last_msg_->corrs[2].Q; + EXPECT_EQ(last_msg_->sid.code, 203) + << "incorrect value for sid.code, expected 203, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 121) + << "incorrect value for sid.sat, expected 121, is " << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc new file mode 100644 index 0000000000..b77824a640 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepA.cc @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_iq_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_iq_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepA0, Test) { + uint8_t encoded_frame[] = { + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, + 170, 96, 71, 121, 33, 161, 52, 211, 162, 101, 41, 36, 226, + 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_iq_dep_a_t *test_msg = + (msg_tracking_iq_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->channel = 139; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[0].I = 1621776995; + test_msg->corrs[0].Q = -1591641785; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[1].I = 1705169716; + test_msg->corrs[1].Q = 1675764777; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[2].I = -267498681; + test_msg->corrs[2].Q = 1403998854; + test_msg->sid.code = 15; + test_msg->sid.reserved = 0; + test_msg->sid.sat = 64028; + + EXPECT_EQ(send_message(0x1c, 17336, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 17336); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->channel, 139) + << "incorrect value for channel, expected 139, is " << last_msg_->channel; + EXPECT_EQ(last_msg_->corrs[0].I, 1621776995) + << "incorrect value for corrs[0].I, expected 1621776995, is " + << last_msg_->corrs[0].I; + EXPECT_EQ(last_msg_->corrs[0].Q, -1591641785) + << "incorrect value for corrs[0].Q, expected -1591641785, is " + << last_msg_->corrs[0].Q; + EXPECT_EQ(last_msg_->corrs[1].I, 1705169716) + << "incorrect value for corrs[1].I, expected 1705169716, is " + << last_msg_->corrs[1].I; + EXPECT_EQ(last_msg_->corrs[1].Q, 1675764777) + << "incorrect value for corrs[1].Q, expected 1675764777, is " + << last_msg_->corrs[1].Q; + EXPECT_EQ(last_msg_->corrs[2].I, -267498681) + << "incorrect value for corrs[2].I, expected -267498681, is " + << last_msg_->corrs[2].I; + EXPECT_EQ(last_msg_->corrs[2].Q, 1403998854) + << "incorrect value for corrs[2].Q, expected 1403998854, is " + << last_msg_->corrs[2].Q; + EXPECT_EQ(last_msg_->sid.code, 15) + << "incorrect value for sid.code, expected 15, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.reserved, 0) + << "incorrect value for sid.reserved, expected 0, is " + << last_msg_->sid.reserved; + EXPECT_EQ(last_msg_->sid.sat, 64028) + << "incorrect value for sid.sat, expected 64028, is " + << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc new file mode 100644 index 0000000000..9065a319b9 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingIqDepB.cc @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_iq_dep_b_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_iq_dep_b_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingIqDepB0, Test) { + uint8_t encoded_frame[] = { + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, + 15, 187, 249, 101, 24, 135, 146, 180, 224, 123, 235, 142, + 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_iq_dep_b_t *test_msg = + (msg_tracking_iq_dep_b_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->channel = 45; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[0].I = 261994824; + test_msg->corrs[0].Q = 409336251; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[1].I = -525036921; + test_msg->corrs[1].Q = -795939973; + if (sizeof(test_msg->corrs) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->corrs[0])); + } + test_msg->corrs[2].I = 353988710; + test_msg->corrs[2].Q = 1148477617; + test_msg->sid.code = 183; + test_msg->sid.sat = 188; + + EXPECT_EQ(send_message(0x2c, 25895, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 25895); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->channel, 45) + << "incorrect value for channel, expected 45, is " << last_msg_->channel; + EXPECT_EQ(last_msg_->corrs[0].I, 261994824) + << "incorrect value for corrs[0].I, expected 261994824, is " + << last_msg_->corrs[0].I; + EXPECT_EQ(last_msg_->corrs[0].Q, 409336251) + << "incorrect value for corrs[0].Q, expected 409336251, is " + << last_msg_->corrs[0].Q; + EXPECT_EQ(last_msg_->corrs[1].I, -525036921) + << "incorrect value for corrs[1].I, expected -525036921, is " + << last_msg_->corrs[1].I; + EXPECT_EQ(last_msg_->corrs[1].Q, -795939973) + << "incorrect value for corrs[1].Q, expected -795939973, is " + << last_msg_->corrs[1].Q; + EXPECT_EQ(last_msg_->corrs[2].I, 353988710) + << "incorrect value for corrs[2].I, expected 353988710, is " + << last_msg_->corrs[2].I; + EXPECT_EQ(last_msg_->corrs[2].Q, 1148477617) + << "incorrect value for corrs[2].Q, expected 1148477617, is " + << last_msg_->corrs[2].Q; + EXPECT_EQ(last_msg_->sid.code, 183) + << "incorrect value for sid.code, expected 183, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 188) + << "incorrect value for sid.sat, expected 188, is " << last_msg_->sid.sat; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingState.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingState.cc index 5191b90434..f11b8a68a7 100644 --- a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingState.cc +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingState.cc @@ -23,9 +23,1367 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState0 public sbp::State, public sbp::IReader, public sbp::IWriter, - sbp::PayloadHandler { + sbp::PayloadHandler { public: Test_legacy_auto_check_sbp_tracking_MsgTrackingState0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_state_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_state_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState0, Test) { + uint8_t encoded_frame[] = { + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, 25, + 4, 90, 195, 246, 108, 75, 82, 137, 127, 45, 163, 32, 46, 187, 93, + 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, 219, 69, 254, 136, 3, + 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, 218, 62, 242, 84, + 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, 253, 227, 216, 227, 24, + 26, 210, 179, 19, 15, 227, 255, 122, 75, 187, 200, 217, 48, 218, 122, + 187, 238, 142, 149, 238, 55, 251, 212, 128, 160, 194, 104, 113, 255, 141, + 62, 43, 69, 245, 39, 100, 230, 108, 56, 247, 68, 149, 143, 137, 101, + 233, 70, 49, 165, 38, 110, 218, 230, 80, 213, 196, 179, 139, 128, 15, + 178, 196, 171, 8, 212, 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, + 5, 25, 105, 186, 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, + 49, 86, 19, 142, 146, 91, 124, 115, 64, 28, 230, 115, 178, 190, 131, + 16, 242, 105, 59, 182, 113, 192, 180, 48, 179, 166, 31, 172, 211, 77, + 228, 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, 129, 55, + 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, 148, + 190, 236, 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, 219, 172, + 145, 17, 192, 179, 111, 97, 207, 56, 208, 134, 180, 17, 43, 226, 255, + 182, 140, 113, 141, 111, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_state_t *test_msg = (msg_tracking_state_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[0].cn0 = 102; + test_msg->states[0].fcn = 3; + test_msg->states[0].sid.code = 184; + test_msg->states[0].sid.sat = 117; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[1].cn0 = 141; + test_msg->states[1].fcn = 140; + test_msg->states[1].sid.code = 106; + test_msg->states[1].sid.sat = 38; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[2].cn0 = 195; + test_msg->states[2].fcn = 90; + test_msg->states[2].sid.code = 4; + test_msg->states[2].sid.sat = 25; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[3].cn0 = 82; + test_msg->states[3].fcn = 75; + test_msg->states[3].sid.code = 108; + test_msg->states[3].sid.sat = 246; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[4].cn0 = 163; + test_msg->states[4].fcn = 45; + test_msg->states[4].sid.code = 127; + test_msg->states[4].sid.sat = 137; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[5].cn0 = 93; + test_msg->states[5].fcn = 187; + test_msg->states[5].sid.code = 46; + test_msg->states[5].sid.sat = 32; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[6].cn0 = 147; + test_msg->states[6].fcn = 201; + test_msg->states[6].sid.code = 60; + test_msg->states[6].sid.sat = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[7].cn0 = 208; + test_msg->states[7].fcn = 5; + test_msg->states[7].sid.code = 29; + test_msg->states[7].sid.sat = 23; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[8].cn0 = 69; + test_msg->states[8].fcn = 219; + test_msg->states[8].sid.code = 30; + test_msg->states[8].sid.sat = 181; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[9].cn0 = 121; + test_msg->states[9].fcn = 3; + test_msg->states[9].sid.code = 136; + test_msg->states[9].sid.sat = 254; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[10].cn0 = 215; + test_msg->states[10].fcn = 144; + test_msg->states[10].sid.code = 98; + test_msg->states[10].sid.sat = 33; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[11].cn0 = 56; + test_msg->states[11].fcn = 14; + test_msg->states[11].sid.code = 182; + test_msg->states[11].sid.sat = 133; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[12].cn0 = 62; + test_msg->states[12].fcn = 218; + test_msg->states[12].sid.code = 77; + test_msg->states[12].sid.sat = 169; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[13].cn0 = 249; + test_msg->states[13].fcn = 171; + test_msg->states[13].sid.code = 84; + test_msg->states[13].sid.sat = 242; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[14].cn0 = 130; + test_msg->states[14].fcn = 131; + test_msg->states[14].sid.code = 137; + test_msg->states[14].sid.sat = 152; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[15].cn0 = 68; + test_msg->states[15].fcn = 42; + test_msg->states[15].sid.code = 21; + test_msg->states[15].sid.sat = 193; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[16].cn0 = 227; + test_msg->states[16].fcn = 216; + test_msg->states[16].sid.code = 227; + test_msg->states[16].sid.sat = 253; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[17].cn0 = 179; + test_msg->states[17].fcn = 210; + test_msg->states[17].sid.code = 26; + test_msg->states[17].sid.sat = 24; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[18].cn0 = 255; + test_msg->states[18].fcn = 227; + test_msg->states[18].sid.code = 15; + test_msg->states[18].sid.sat = 19; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[19].cn0 = 200; + test_msg->states[19].fcn = 187; + test_msg->states[19].sid.code = 75; + test_msg->states[19].sid.sat = 122; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[20].cn0 = 122; + test_msg->states[20].fcn = 218; + test_msg->states[20].sid.code = 48; + test_msg->states[20].sid.sat = 217; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[21].cn0 = 149; + test_msg->states[21].fcn = 142; + test_msg->states[21].sid.code = 238; + test_msg->states[21].sid.sat = 187; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[22].cn0 = 212; + test_msg->states[22].fcn = 251; + test_msg->states[22].sid.code = 55; + test_msg->states[22].sid.sat = 238; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[23].cn0 = 104; + test_msg->states[23].fcn = 194; + test_msg->states[23].sid.code = 160; + test_msg->states[23].sid.sat = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[24].cn0 = 62; + test_msg->states[24].fcn = 141; + test_msg->states[24].sid.code = 255; + test_msg->states[24].sid.sat = 113; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[25].cn0 = 39; + test_msg->states[25].fcn = 245; + test_msg->states[25].sid.code = 69; + test_msg->states[25].sid.sat = 43; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[26].cn0 = 56; + test_msg->states[26].fcn = 108; + test_msg->states[26].sid.code = 230; + test_msg->states[26].sid.sat = 100; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[27].cn0 = 143; + test_msg->states[27].fcn = 149; + test_msg->states[27].sid.code = 68; + test_msg->states[27].sid.sat = 247; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[28].cn0 = 70; + test_msg->states[28].fcn = 233; + test_msg->states[28].sid.code = 101; + test_msg->states[28].sid.sat = 137; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[29].cn0 = 110; + test_msg->states[29].fcn = 38; + test_msg->states[29].sid.code = 165; + test_msg->states[29].sid.sat = 49; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[30].cn0 = 213; + test_msg->states[30].fcn = 80; + test_msg->states[30].sid.code = 230; + test_msg->states[30].sid.sat = 218; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[31].cn0 = 128; + test_msg->states[31].fcn = 139; + test_msg->states[31].sid.code = 179; + test_msg->states[31].sid.sat = 196; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[32].cn0 = 171; + test_msg->states[32].fcn = 196; + test_msg->states[32].sid.code = 178; + test_msg->states[32].sid.sat = 15; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[33].cn0 = 194; + test_msg->states[33].fcn = 97; + test_msg->states[33].sid.code = 212; + test_msg->states[33].sid.sat = 8; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[34].cn0 = 99; + test_msg->states[34].fcn = 79; + test_msg->states[34].sid.code = 233; + test_msg->states[34].sid.sat = 83; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[35].cn0 = 180; + test_msg->states[35].fcn = 31; + test_msg->states[35].sid.code = 90; + test_msg->states[35].sid.sat = 55; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[36].cn0 = 186; + test_msg->states[36].fcn = 105; + test_msg->states[36].sid.code = 25; + test_msg->states[36].sid.sat = 5; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[37].cn0 = 111; + test_msg->states[37].fcn = 80; + test_msg->states[37].sid.code = 224; + test_msg->states[37].sid.sat = 22; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[38].cn0 = 166; + test_msg->states[38].fcn = 106; + test_msg->states[38].sid.code = 48; + test_msg->states[38].sid.sat = 8; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[39].cn0 = 49; + test_msg->states[39].fcn = 156; + test_msg->states[39].sid.code = 48; + test_msg->states[39].sid.sat = 4; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[40].cn0 = 146; + test_msg->states[40].fcn = 142; + test_msg->states[40].sid.code = 19; + test_msg->states[40].sid.sat = 86; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[41].cn0 = 64; + test_msg->states[41].fcn = 115; + test_msg->states[41].sid.code = 124; + test_msg->states[41].sid.sat = 91; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[42].cn0 = 178; + test_msg->states[42].fcn = 115; + test_msg->states[42].sid.code = 230; + test_msg->states[42].sid.sat = 28; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[43].cn0 = 242; + test_msg->states[43].fcn = 16; + test_msg->states[43].sid.code = 131; + test_msg->states[43].sid.sat = 190; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[44].cn0 = 113; + test_msg->states[44].fcn = 182; + test_msg->states[44].sid.code = 59; + test_msg->states[44].sid.sat = 105; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[45].cn0 = 179; + test_msg->states[45].fcn = 48; + test_msg->states[45].sid.code = 180; + test_msg->states[45].sid.sat = 192; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[46].cn0 = 211; + test_msg->states[46].fcn = 172; + test_msg->states[46].sid.code = 31; + test_msg->states[46].sid.sat = 166; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[47].cn0 = 49; + test_msg->states[47].fcn = 140; + test_msg->states[47].sid.code = 228; + test_msg->states[47].sid.sat = 77; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[48].cn0 = 194; + test_msg->states[48].fcn = 240; + test_msg->states[48].sid.code = 77; + test_msg->states[48].sid.sat = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[49].cn0 = 58; + test_msg->states[49].fcn = 41; + test_msg->states[49].sid.code = 194; + test_msg->states[49].sid.sat = 134; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[50].cn0 = 55; + test_msg->states[50].fcn = 129; + test_msg->states[50].sid.code = 53; + test_msg->states[50].sid.sat = 18; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[51].cn0 = 92; + test_msg->states[51].fcn = 134; + test_msg->states[51].sid.code = 72; + test_msg->states[51].sid.sat = 91; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[52].cn0 = 56; + test_msg->states[52].fcn = 157; + test_msg->states[52].sid.code = 224; + test_msg->states[52].sid.sat = 33; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[53].cn0 = 174; + test_msg->states[53].fcn = 224; + test_msg->states[53].sid.code = 54; + test_msg->states[53].sid.sat = 186; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[54].cn0 = 190; + test_msg->states[54].fcn = 148; + test_msg->states[54].sid.code = 84; + test_msg->states[54].sid.sat = 82; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[55].cn0 = 67; + test_msg->states[55].fcn = 62; + test_msg->states[55].sid.code = 54; + test_msg->states[55].sid.sat = 236; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[56].cn0 = 254; + test_msg->states[56].fcn = 57; + test_msg->states[56].sid.code = 215; + test_msg->states[56].sid.sat = 52; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[57].cn0 = 174; + test_msg->states[57].fcn = 36; + test_msg->states[57].sid.code = 133; + test_msg->states[57].sid.sat = 16; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[58].cn0 = 17; + test_msg->states[58].fcn = 145; + test_msg->states[58].sid.code = 172; + test_msg->states[58].sid.sat = 219; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[59].cn0 = 97; + test_msg->states[59].fcn = 111; + test_msg->states[59].sid.code = 179; + test_msg->states[59].sid.sat = 192; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[60].cn0 = 134; + test_msg->states[60].fcn = 208; + test_msg->states[60].sid.code = 56; + test_msg->states[60].sid.sat = 207; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[61].cn0 = 226; + test_msg->states[61].fcn = 43; + test_msg->states[61].sid.code = 17; + test_msg->states[61].sid.sat = 180; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[62].cn0 = 113; + test_msg->states[62].fcn = 140; + test_msg->states[62].sid.code = 182; + test_msg->states[62].sid.sat = 255; + + EXPECT_EQ(send_message(0x41, 33079, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 33079); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->states[0].cn0, 102) + << "incorrect value for states[0].cn0, expected 102, is " + << last_msg_->states[0].cn0; + EXPECT_EQ(last_msg_->states[0].fcn, 3) + << "incorrect value for states[0].fcn, expected 3, is " + << last_msg_->states[0].fcn; + EXPECT_EQ(last_msg_->states[0].sid.code, 184) + << "incorrect value for states[0].sid.code, expected 184, is " + << last_msg_->states[0].sid.code; + EXPECT_EQ(last_msg_->states[0].sid.sat, 117) + << "incorrect value for states[0].sid.sat, expected 117, is " + << last_msg_->states[0].sid.sat; + EXPECT_EQ(last_msg_->states[1].cn0, 141) + << "incorrect value for states[1].cn0, expected 141, is " + << last_msg_->states[1].cn0; + EXPECT_EQ(last_msg_->states[1].fcn, 140) + << "incorrect value for states[1].fcn, expected 140, is " + << last_msg_->states[1].fcn; + EXPECT_EQ(last_msg_->states[1].sid.code, 106) + << "incorrect value for states[1].sid.code, expected 106, is " + << last_msg_->states[1].sid.code; + EXPECT_EQ(last_msg_->states[1].sid.sat, 38) + << "incorrect value for states[1].sid.sat, expected 38, is " + << last_msg_->states[1].sid.sat; + EXPECT_EQ(last_msg_->states[2].cn0, 195) + << "incorrect value for states[2].cn0, expected 195, is " + << last_msg_->states[2].cn0; + EXPECT_EQ(last_msg_->states[2].fcn, 90) + << "incorrect value for states[2].fcn, expected 90, is " + << last_msg_->states[2].fcn; + EXPECT_EQ(last_msg_->states[2].sid.code, 4) + << "incorrect value for states[2].sid.code, expected 4, is " + << last_msg_->states[2].sid.code; + EXPECT_EQ(last_msg_->states[2].sid.sat, 25) + << "incorrect value for states[2].sid.sat, expected 25, is " + << last_msg_->states[2].sid.sat; + EXPECT_EQ(last_msg_->states[3].cn0, 82) + << "incorrect value for states[3].cn0, expected 82, is " + << last_msg_->states[3].cn0; + EXPECT_EQ(last_msg_->states[3].fcn, 75) + << "incorrect value for states[3].fcn, expected 75, is " + << last_msg_->states[3].fcn; + EXPECT_EQ(last_msg_->states[3].sid.code, 108) + << "incorrect value for states[3].sid.code, expected 108, is " + << last_msg_->states[3].sid.code; + EXPECT_EQ(last_msg_->states[3].sid.sat, 246) + << "incorrect value for states[3].sid.sat, expected 246, is " + << last_msg_->states[3].sid.sat; + EXPECT_EQ(last_msg_->states[4].cn0, 163) + << "incorrect value for states[4].cn0, expected 163, is " + << last_msg_->states[4].cn0; + EXPECT_EQ(last_msg_->states[4].fcn, 45) + << "incorrect value for states[4].fcn, expected 45, is " + << last_msg_->states[4].fcn; + EXPECT_EQ(last_msg_->states[4].sid.code, 127) + << "incorrect value for states[4].sid.code, expected 127, is " + << last_msg_->states[4].sid.code; + EXPECT_EQ(last_msg_->states[4].sid.sat, 137) + << "incorrect value for states[4].sid.sat, expected 137, is " + << last_msg_->states[4].sid.sat; + EXPECT_EQ(last_msg_->states[5].cn0, 93) + << "incorrect value for states[5].cn0, expected 93, is " + << last_msg_->states[5].cn0; + EXPECT_EQ(last_msg_->states[5].fcn, 187) + << "incorrect value for states[5].fcn, expected 187, is " + << last_msg_->states[5].fcn; + EXPECT_EQ(last_msg_->states[5].sid.code, 46) + << "incorrect value for states[5].sid.code, expected 46, is " + << last_msg_->states[5].sid.code; + EXPECT_EQ(last_msg_->states[5].sid.sat, 32) + << "incorrect value for states[5].sid.sat, expected 32, is " + << last_msg_->states[5].sid.sat; + EXPECT_EQ(last_msg_->states[6].cn0, 147) + << "incorrect value for states[6].cn0, expected 147, is " + << last_msg_->states[6].cn0; + EXPECT_EQ(last_msg_->states[6].fcn, 201) + << "incorrect value for states[6].fcn, expected 201, is " + << last_msg_->states[6].fcn; + EXPECT_EQ(last_msg_->states[6].sid.code, 60) + << "incorrect value for states[6].sid.code, expected 60, is " + << last_msg_->states[6].sid.code; + EXPECT_EQ(last_msg_->states[6].sid.sat, 153) + << "incorrect value for states[6].sid.sat, expected 153, is " + << last_msg_->states[6].sid.sat; + EXPECT_EQ(last_msg_->states[7].cn0, 208) + << "incorrect value for states[7].cn0, expected 208, is " + << last_msg_->states[7].cn0; + EXPECT_EQ(last_msg_->states[7].fcn, 5) + << "incorrect value for states[7].fcn, expected 5, is " + << last_msg_->states[7].fcn; + EXPECT_EQ(last_msg_->states[7].sid.code, 29) + << "incorrect value for states[7].sid.code, expected 29, is " + << last_msg_->states[7].sid.code; + EXPECT_EQ(last_msg_->states[7].sid.sat, 23) + << "incorrect value for states[7].sid.sat, expected 23, is " + << last_msg_->states[7].sid.sat; + EXPECT_EQ(last_msg_->states[8].cn0, 69) + << "incorrect value for states[8].cn0, expected 69, is " + << last_msg_->states[8].cn0; + EXPECT_EQ(last_msg_->states[8].fcn, 219) + << "incorrect value for states[8].fcn, expected 219, is " + << last_msg_->states[8].fcn; + EXPECT_EQ(last_msg_->states[8].sid.code, 30) + << "incorrect value for states[8].sid.code, expected 30, is " + << last_msg_->states[8].sid.code; + EXPECT_EQ(last_msg_->states[8].sid.sat, 181) + << "incorrect value for states[8].sid.sat, expected 181, is " + << last_msg_->states[8].sid.sat; + EXPECT_EQ(last_msg_->states[9].cn0, 121) + << "incorrect value for states[9].cn0, expected 121, is " + << last_msg_->states[9].cn0; + EXPECT_EQ(last_msg_->states[9].fcn, 3) + << "incorrect value for states[9].fcn, expected 3, is " + << last_msg_->states[9].fcn; + EXPECT_EQ(last_msg_->states[9].sid.code, 136) + << "incorrect value for states[9].sid.code, expected 136, is " + << last_msg_->states[9].sid.code; + EXPECT_EQ(last_msg_->states[9].sid.sat, 254) + << "incorrect value for states[9].sid.sat, expected 254, is " + << last_msg_->states[9].sid.sat; + EXPECT_EQ(last_msg_->states[10].cn0, 215) + << "incorrect value for states[10].cn0, expected 215, is " + << last_msg_->states[10].cn0; + EXPECT_EQ(last_msg_->states[10].fcn, 144) + << "incorrect value for states[10].fcn, expected 144, is " + << last_msg_->states[10].fcn; + EXPECT_EQ(last_msg_->states[10].sid.code, 98) + << "incorrect value for states[10].sid.code, expected 98, is " + << last_msg_->states[10].sid.code; + EXPECT_EQ(last_msg_->states[10].sid.sat, 33) + << "incorrect value for states[10].sid.sat, expected 33, is " + << last_msg_->states[10].sid.sat; + EXPECT_EQ(last_msg_->states[11].cn0, 56) + << "incorrect value for states[11].cn0, expected 56, is " + << last_msg_->states[11].cn0; + EXPECT_EQ(last_msg_->states[11].fcn, 14) + << "incorrect value for states[11].fcn, expected 14, is " + << last_msg_->states[11].fcn; + EXPECT_EQ(last_msg_->states[11].sid.code, 182) + << "incorrect value for states[11].sid.code, expected 182, is " + << last_msg_->states[11].sid.code; + EXPECT_EQ(last_msg_->states[11].sid.sat, 133) + << "incorrect value for states[11].sid.sat, expected 133, is " + << last_msg_->states[11].sid.sat; + EXPECT_EQ(last_msg_->states[12].cn0, 62) + << "incorrect value for states[12].cn0, expected 62, is " + << last_msg_->states[12].cn0; + EXPECT_EQ(last_msg_->states[12].fcn, 218) + << "incorrect value for states[12].fcn, expected 218, is " + << last_msg_->states[12].fcn; + EXPECT_EQ(last_msg_->states[12].sid.code, 77) + << "incorrect value for states[12].sid.code, expected 77, is " + << last_msg_->states[12].sid.code; + EXPECT_EQ(last_msg_->states[12].sid.sat, 169) + << "incorrect value for states[12].sid.sat, expected 169, is " + << last_msg_->states[12].sid.sat; + EXPECT_EQ(last_msg_->states[13].cn0, 249) + << "incorrect value for states[13].cn0, expected 249, is " + << last_msg_->states[13].cn0; + EXPECT_EQ(last_msg_->states[13].fcn, 171) + << "incorrect value for states[13].fcn, expected 171, is " + << last_msg_->states[13].fcn; + EXPECT_EQ(last_msg_->states[13].sid.code, 84) + << "incorrect value for states[13].sid.code, expected 84, is " + << last_msg_->states[13].sid.code; + EXPECT_EQ(last_msg_->states[13].sid.sat, 242) + << "incorrect value for states[13].sid.sat, expected 242, is " + << last_msg_->states[13].sid.sat; + EXPECT_EQ(last_msg_->states[14].cn0, 130) + << "incorrect value for states[14].cn0, expected 130, is " + << last_msg_->states[14].cn0; + EXPECT_EQ(last_msg_->states[14].fcn, 131) + << "incorrect value for states[14].fcn, expected 131, is " + << last_msg_->states[14].fcn; + EXPECT_EQ(last_msg_->states[14].sid.code, 137) + << "incorrect value for states[14].sid.code, expected 137, is " + << last_msg_->states[14].sid.code; + EXPECT_EQ(last_msg_->states[14].sid.sat, 152) + << "incorrect value for states[14].sid.sat, expected 152, is " + << last_msg_->states[14].sid.sat; + EXPECT_EQ(last_msg_->states[15].cn0, 68) + << "incorrect value for states[15].cn0, expected 68, is " + << last_msg_->states[15].cn0; + EXPECT_EQ(last_msg_->states[15].fcn, 42) + << "incorrect value for states[15].fcn, expected 42, is " + << last_msg_->states[15].fcn; + EXPECT_EQ(last_msg_->states[15].sid.code, 21) + << "incorrect value for states[15].sid.code, expected 21, is " + << last_msg_->states[15].sid.code; + EXPECT_EQ(last_msg_->states[15].sid.sat, 193) + << "incorrect value for states[15].sid.sat, expected 193, is " + << last_msg_->states[15].sid.sat; + EXPECT_EQ(last_msg_->states[16].cn0, 227) + << "incorrect value for states[16].cn0, expected 227, is " + << last_msg_->states[16].cn0; + EXPECT_EQ(last_msg_->states[16].fcn, 216) + << "incorrect value for states[16].fcn, expected 216, is " + << last_msg_->states[16].fcn; + EXPECT_EQ(last_msg_->states[16].sid.code, 227) + << "incorrect value for states[16].sid.code, expected 227, is " + << last_msg_->states[16].sid.code; + EXPECT_EQ(last_msg_->states[16].sid.sat, 253) + << "incorrect value for states[16].sid.sat, expected 253, is " + << last_msg_->states[16].sid.sat; + EXPECT_EQ(last_msg_->states[17].cn0, 179) + << "incorrect value for states[17].cn0, expected 179, is " + << last_msg_->states[17].cn0; + EXPECT_EQ(last_msg_->states[17].fcn, 210) + << "incorrect value for states[17].fcn, expected 210, is " + << last_msg_->states[17].fcn; + EXPECT_EQ(last_msg_->states[17].sid.code, 26) + << "incorrect value for states[17].sid.code, expected 26, is " + << last_msg_->states[17].sid.code; + EXPECT_EQ(last_msg_->states[17].sid.sat, 24) + << "incorrect value for states[17].sid.sat, expected 24, is " + << last_msg_->states[17].sid.sat; + EXPECT_EQ(last_msg_->states[18].cn0, 255) + << "incorrect value for states[18].cn0, expected 255, is " + << last_msg_->states[18].cn0; + EXPECT_EQ(last_msg_->states[18].fcn, 227) + << "incorrect value for states[18].fcn, expected 227, is " + << last_msg_->states[18].fcn; + EXPECT_EQ(last_msg_->states[18].sid.code, 15) + << "incorrect value for states[18].sid.code, expected 15, is " + << last_msg_->states[18].sid.code; + EXPECT_EQ(last_msg_->states[18].sid.sat, 19) + << "incorrect value for states[18].sid.sat, expected 19, is " + << last_msg_->states[18].sid.sat; + EXPECT_EQ(last_msg_->states[19].cn0, 200) + << "incorrect value for states[19].cn0, expected 200, is " + << last_msg_->states[19].cn0; + EXPECT_EQ(last_msg_->states[19].fcn, 187) + << "incorrect value for states[19].fcn, expected 187, is " + << last_msg_->states[19].fcn; + EXPECT_EQ(last_msg_->states[19].sid.code, 75) + << "incorrect value for states[19].sid.code, expected 75, is " + << last_msg_->states[19].sid.code; + EXPECT_EQ(last_msg_->states[19].sid.sat, 122) + << "incorrect value for states[19].sid.sat, expected 122, is " + << last_msg_->states[19].sid.sat; + EXPECT_EQ(last_msg_->states[20].cn0, 122) + << "incorrect value for states[20].cn0, expected 122, is " + << last_msg_->states[20].cn0; + EXPECT_EQ(last_msg_->states[20].fcn, 218) + << "incorrect value for states[20].fcn, expected 218, is " + << last_msg_->states[20].fcn; + EXPECT_EQ(last_msg_->states[20].sid.code, 48) + << "incorrect value for states[20].sid.code, expected 48, is " + << last_msg_->states[20].sid.code; + EXPECT_EQ(last_msg_->states[20].sid.sat, 217) + << "incorrect value for states[20].sid.sat, expected 217, is " + << last_msg_->states[20].sid.sat; + EXPECT_EQ(last_msg_->states[21].cn0, 149) + << "incorrect value for states[21].cn0, expected 149, is " + << last_msg_->states[21].cn0; + EXPECT_EQ(last_msg_->states[21].fcn, 142) + << "incorrect value for states[21].fcn, expected 142, is " + << last_msg_->states[21].fcn; + EXPECT_EQ(last_msg_->states[21].sid.code, 238) + << "incorrect value for states[21].sid.code, expected 238, is " + << last_msg_->states[21].sid.code; + EXPECT_EQ(last_msg_->states[21].sid.sat, 187) + << "incorrect value for states[21].sid.sat, expected 187, is " + << last_msg_->states[21].sid.sat; + EXPECT_EQ(last_msg_->states[22].cn0, 212) + << "incorrect value for states[22].cn0, expected 212, is " + << last_msg_->states[22].cn0; + EXPECT_EQ(last_msg_->states[22].fcn, 251) + << "incorrect value for states[22].fcn, expected 251, is " + << last_msg_->states[22].fcn; + EXPECT_EQ(last_msg_->states[22].sid.code, 55) + << "incorrect value for states[22].sid.code, expected 55, is " + << last_msg_->states[22].sid.code; + EXPECT_EQ(last_msg_->states[22].sid.sat, 238) + << "incorrect value for states[22].sid.sat, expected 238, is " + << last_msg_->states[22].sid.sat; + EXPECT_EQ(last_msg_->states[23].cn0, 104) + << "incorrect value for states[23].cn0, expected 104, is " + << last_msg_->states[23].cn0; + EXPECT_EQ(last_msg_->states[23].fcn, 194) + << "incorrect value for states[23].fcn, expected 194, is " + << last_msg_->states[23].fcn; + EXPECT_EQ(last_msg_->states[23].sid.code, 160) + << "incorrect value for states[23].sid.code, expected 160, is " + << last_msg_->states[23].sid.code; + EXPECT_EQ(last_msg_->states[23].sid.sat, 128) + << "incorrect value for states[23].sid.sat, expected 128, is " + << last_msg_->states[23].sid.sat; + EXPECT_EQ(last_msg_->states[24].cn0, 62) + << "incorrect value for states[24].cn0, expected 62, is " + << last_msg_->states[24].cn0; + EXPECT_EQ(last_msg_->states[24].fcn, 141) + << "incorrect value for states[24].fcn, expected 141, is " + << last_msg_->states[24].fcn; + EXPECT_EQ(last_msg_->states[24].sid.code, 255) + << "incorrect value for states[24].sid.code, expected 255, is " + << last_msg_->states[24].sid.code; + EXPECT_EQ(last_msg_->states[24].sid.sat, 113) + << "incorrect value for states[24].sid.sat, expected 113, is " + << last_msg_->states[24].sid.sat; + EXPECT_EQ(last_msg_->states[25].cn0, 39) + << "incorrect value for states[25].cn0, expected 39, is " + << last_msg_->states[25].cn0; + EXPECT_EQ(last_msg_->states[25].fcn, 245) + << "incorrect value for states[25].fcn, expected 245, is " + << last_msg_->states[25].fcn; + EXPECT_EQ(last_msg_->states[25].sid.code, 69) + << "incorrect value for states[25].sid.code, expected 69, is " + << last_msg_->states[25].sid.code; + EXPECT_EQ(last_msg_->states[25].sid.sat, 43) + << "incorrect value for states[25].sid.sat, expected 43, is " + << last_msg_->states[25].sid.sat; + EXPECT_EQ(last_msg_->states[26].cn0, 56) + << "incorrect value for states[26].cn0, expected 56, is " + << last_msg_->states[26].cn0; + EXPECT_EQ(last_msg_->states[26].fcn, 108) + << "incorrect value for states[26].fcn, expected 108, is " + << last_msg_->states[26].fcn; + EXPECT_EQ(last_msg_->states[26].sid.code, 230) + << "incorrect value for states[26].sid.code, expected 230, is " + << last_msg_->states[26].sid.code; + EXPECT_EQ(last_msg_->states[26].sid.sat, 100) + << "incorrect value for states[26].sid.sat, expected 100, is " + << last_msg_->states[26].sid.sat; + EXPECT_EQ(last_msg_->states[27].cn0, 143) + << "incorrect value for states[27].cn0, expected 143, is " + << last_msg_->states[27].cn0; + EXPECT_EQ(last_msg_->states[27].fcn, 149) + << "incorrect value for states[27].fcn, expected 149, is " + << last_msg_->states[27].fcn; + EXPECT_EQ(last_msg_->states[27].sid.code, 68) + << "incorrect value for states[27].sid.code, expected 68, is " + << last_msg_->states[27].sid.code; + EXPECT_EQ(last_msg_->states[27].sid.sat, 247) + << "incorrect value for states[27].sid.sat, expected 247, is " + << last_msg_->states[27].sid.sat; + EXPECT_EQ(last_msg_->states[28].cn0, 70) + << "incorrect value for states[28].cn0, expected 70, is " + << last_msg_->states[28].cn0; + EXPECT_EQ(last_msg_->states[28].fcn, 233) + << "incorrect value for states[28].fcn, expected 233, is " + << last_msg_->states[28].fcn; + EXPECT_EQ(last_msg_->states[28].sid.code, 101) + << "incorrect value for states[28].sid.code, expected 101, is " + << last_msg_->states[28].sid.code; + EXPECT_EQ(last_msg_->states[28].sid.sat, 137) + << "incorrect value for states[28].sid.sat, expected 137, is " + << last_msg_->states[28].sid.sat; + EXPECT_EQ(last_msg_->states[29].cn0, 110) + << "incorrect value for states[29].cn0, expected 110, is " + << last_msg_->states[29].cn0; + EXPECT_EQ(last_msg_->states[29].fcn, 38) + << "incorrect value for states[29].fcn, expected 38, is " + << last_msg_->states[29].fcn; + EXPECT_EQ(last_msg_->states[29].sid.code, 165) + << "incorrect value for states[29].sid.code, expected 165, is " + << last_msg_->states[29].sid.code; + EXPECT_EQ(last_msg_->states[29].sid.sat, 49) + << "incorrect value for states[29].sid.sat, expected 49, is " + << last_msg_->states[29].sid.sat; + EXPECT_EQ(last_msg_->states[30].cn0, 213) + << "incorrect value for states[30].cn0, expected 213, is " + << last_msg_->states[30].cn0; + EXPECT_EQ(last_msg_->states[30].fcn, 80) + << "incorrect value for states[30].fcn, expected 80, is " + << last_msg_->states[30].fcn; + EXPECT_EQ(last_msg_->states[30].sid.code, 230) + << "incorrect value for states[30].sid.code, expected 230, is " + << last_msg_->states[30].sid.code; + EXPECT_EQ(last_msg_->states[30].sid.sat, 218) + << "incorrect value for states[30].sid.sat, expected 218, is " + << last_msg_->states[30].sid.sat; + EXPECT_EQ(last_msg_->states[31].cn0, 128) + << "incorrect value for states[31].cn0, expected 128, is " + << last_msg_->states[31].cn0; + EXPECT_EQ(last_msg_->states[31].fcn, 139) + << "incorrect value for states[31].fcn, expected 139, is " + << last_msg_->states[31].fcn; + EXPECT_EQ(last_msg_->states[31].sid.code, 179) + << "incorrect value for states[31].sid.code, expected 179, is " + << last_msg_->states[31].sid.code; + EXPECT_EQ(last_msg_->states[31].sid.sat, 196) + << "incorrect value for states[31].sid.sat, expected 196, is " + << last_msg_->states[31].sid.sat; + EXPECT_EQ(last_msg_->states[32].cn0, 171) + << "incorrect value for states[32].cn0, expected 171, is " + << last_msg_->states[32].cn0; + EXPECT_EQ(last_msg_->states[32].fcn, 196) + << "incorrect value for states[32].fcn, expected 196, is " + << last_msg_->states[32].fcn; + EXPECT_EQ(last_msg_->states[32].sid.code, 178) + << "incorrect value for states[32].sid.code, expected 178, is " + << last_msg_->states[32].sid.code; + EXPECT_EQ(last_msg_->states[32].sid.sat, 15) + << "incorrect value for states[32].sid.sat, expected 15, is " + << last_msg_->states[32].sid.sat; + EXPECT_EQ(last_msg_->states[33].cn0, 194) + << "incorrect value for states[33].cn0, expected 194, is " + << last_msg_->states[33].cn0; + EXPECT_EQ(last_msg_->states[33].fcn, 97) + << "incorrect value for states[33].fcn, expected 97, is " + << last_msg_->states[33].fcn; + EXPECT_EQ(last_msg_->states[33].sid.code, 212) + << "incorrect value for states[33].sid.code, expected 212, is " + << last_msg_->states[33].sid.code; + EXPECT_EQ(last_msg_->states[33].sid.sat, 8) + << "incorrect value for states[33].sid.sat, expected 8, is " + << last_msg_->states[33].sid.sat; + EXPECT_EQ(last_msg_->states[34].cn0, 99) + << "incorrect value for states[34].cn0, expected 99, is " + << last_msg_->states[34].cn0; + EXPECT_EQ(last_msg_->states[34].fcn, 79) + << "incorrect value for states[34].fcn, expected 79, is " + << last_msg_->states[34].fcn; + EXPECT_EQ(last_msg_->states[34].sid.code, 233) + << "incorrect value for states[34].sid.code, expected 233, is " + << last_msg_->states[34].sid.code; + EXPECT_EQ(last_msg_->states[34].sid.sat, 83) + << "incorrect value for states[34].sid.sat, expected 83, is " + << last_msg_->states[34].sid.sat; + EXPECT_EQ(last_msg_->states[35].cn0, 180) + << "incorrect value for states[35].cn0, expected 180, is " + << last_msg_->states[35].cn0; + EXPECT_EQ(last_msg_->states[35].fcn, 31) + << "incorrect value for states[35].fcn, expected 31, is " + << last_msg_->states[35].fcn; + EXPECT_EQ(last_msg_->states[35].sid.code, 90) + << "incorrect value for states[35].sid.code, expected 90, is " + << last_msg_->states[35].sid.code; + EXPECT_EQ(last_msg_->states[35].sid.sat, 55) + << "incorrect value for states[35].sid.sat, expected 55, is " + << last_msg_->states[35].sid.sat; + EXPECT_EQ(last_msg_->states[36].cn0, 186) + << "incorrect value for states[36].cn0, expected 186, is " + << last_msg_->states[36].cn0; + EXPECT_EQ(last_msg_->states[36].fcn, 105) + << "incorrect value for states[36].fcn, expected 105, is " + << last_msg_->states[36].fcn; + EXPECT_EQ(last_msg_->states[36].sid.code, 25) + << "incorrect value for states[36].sid.code, expected 25, is " + << last_msg_->states[36].sid.code; + EXPECT_EQ(last_msg_->states[36].sid.sat, 5) + << "incorrect value for states[36].sid.sat, expected 5, is " + << last_msg_->states[36].sid.sat; + EXPECT_EQ(last_msg_->states[37].cn0, 111) + << "incorrect value for states[37].cn0, expected 111, is " + << last_msg_->states[37].cn0; + EXPECT_EQ(last_msg_->states[37].fcn, 80) + << "incorrect value for states[37].fcn, expected 80, is " + << last_msg_->states[37].fcn; + EXPECT_EQ(last_msg_->states[37].sid.code, 224) + << "incorrect value for states[37].sid.code, expected 224, is " + << last_msg_->states[37].sid.code; + EXPECT_EQ(last_msg_->states[37].sid.sat, 22) + << "incorrect value for states[37].sid.sat, expected 22, is " + << last_msg_->states[37].sid.sat; + EXPECT_EQ(last_msg_->states[38].cn0, 166) + << "incorrect value for states[38].cn0, expected 166, is " + << last_msg_->states[38].cn0; + EXPECT_EQ(last_msg_->states[38].fcn, 106) + << "incorrect value for states[38].fcn, expected 106, is " + << last_msg_->states[38].fcn; + EXPECT_EQ(last_msg_->states[38].sid.code, 48) + << "incorrect value for states[38].sid.code, expected 48, is " + << last_msg_->states[38].sid.code; + EXPECT_EQ(last_msg_->states[38].sid.sat, 8) + << "incorrect value for states[38].sid.sat, expected 8, is " + << last_msg_->states[38].sid.sat; + EXPECT_EQ(last_msg_->states[39].cn0, 49) + << "incorrect value for states[39].cn0, expected 49, is " + << last_msg_->states[39].cn0; + EXPECT_EQ(last_msg_->states[39].fcn, 156) + << "incorrect value for states[39].fcn, expected 156, is " + << last_msg_->states[39].fcn; + EXPECT_EQ(last_msg_->states[39].sid.code, 48) + << "incorrect value for states[39].sid.code, expected 48, is " + << last_msg_->states[39].sid.code; + EXPECT_EQ(last_msg_->states[39].sid.sat, 4) + << "incorrect value for states[39].sid.sat, expected 4, is " + << last_msg_->states[39].sid.sat; + EXPECT_EQ(last_msg_->states[40].cn0, 146) + << "incorrect value for states[40].cn0, expected 146, is " + << last_msg_->states[40].cn0; + EXPECT_EQ(last_msg_->states[40].fcn, 142) + << "incorrect value for states[40].fcn, expected 142, is " + << last_msg_->states[40].fcn; + EXPECT_EQ(last_msg_->states[40].sid.code, 19) + << "incorrect value for states[40].sid.code, expected 19, is " + << last_msg_->states[40].sid.code; + EXPECT_EQ(last_msg_->states[40].sid.sat, 86) + << "incorrect value for states[40].sid.sat, expected 86, is " + << last_msg_->states[40].sid.sat; + EXPECT_EQ(last_msg_->states[41].cn0, 64) + << "incorrect value for states[41].cn0, expected 64, is " + << last_msg_->states[41].cn0; + EXPECT_EQ(last_msg_->states[41].fcn, 115) + << "incorrect value for states[41].fcn, expected 115, is " + << last_msg_->states[41].fcn; + EXPECT_EQ(last_msg_->states[41].sid.code, 124) + << "incorrect value for states[41].sid.code, expected 124, is " + << last_msg_->states[41].sid.code; + EXPECT_EQ(last_msg_->states[41].sid.sat, 91) + << "incorrect value for states[41].sid.sat, expected 91, is " + << last_msg_->states[41].sid.sat; + EXPECT_EQ(last_msg_->states[42].cn0, 178) + << "incorrect value for states[42].cn0, expected 178, is " + << last_msg_->states[42].cn0; + EXPECT_EQ(last_msg_->states[42].fcn, 115) + << "incorrect value for states[42].fcn, expected 115, is " + << last_msg_->states[42].fcn; + EXPECT_EQ(last_msg_->states[42].sid.code, 230) + << "incorrect value for states[42].sid.code, expected 230, is " + << last_msg_->states[42].sid.code; + EXPECT_EQ(last_msg_->states[42].sid.sat, 28) + << "incorrect value for states[42].sid.sat, expected 28, is " + << last_msg_->states[42].sid.sat; + EXPECT_EQ(last_msg_->states[43].cn0, 242) + << "incorrect value for states[43].cn0, expected 242, is " + << last_msg_->states[43].cn0; + EXPECT_EQ(last_msg_->states[43].fcn, 16) + << "incorrect value for states[43].fcn, expected 16, is " + << last_msg_->states[43].fcn; + EXPECT_EQ(last_msg_->states[43].sid.code, 131) + << "incorrect value for states[43].sid.code, expected 131, is " + << last_msg_->states[43].sid.code; + EXPECT_EQ(last_msg_->states[43].sid.sat, 190) + << "incorrect value for states[43].sid.sat, expected 190, is " + << last_msg_->states[43].sid.sat; + EXPECT_EQ(last_msg_->states[44].cn0, 113) + << "incorrect value for states[44].cn0, expected 113, is " + << last_msg_->states[44].cn0; + EXPECT_EQ(last_msg_->states[44].fcn, 182) + << "incorrect value for states[44].fcn, expected 182, is " + << last_msg_->states[44].fcn; + EXPECT_EQ(last_msg_->states[44].sid.code, 59) + << "incorrect value for states[44].sid.code, expected 59, is " + << last_msg_->states[44].sid.code; + EXPECT_EQ(last_msg_->states[44].sid.sat, 105) + << "incorrect value for states[44].sid.sat, expected 105, is " + << last_msg_->states[44].sid.sat; + EXPECT_EQ(last_msg_->states[45].cn0, 179) + << "incorrect value for states[45].cn0, expected 179, is " + << last_msg_->states[45].cn0; + EXPECT_EQ(last_msg_->states[45].fcn, 48) + << "incorrect value for states[45].fcn, expected 48, is " + << last_msg_->states[45].fcn; + EXPECT_EQ(last_msg_->states[45].sid.code, 180) + << "incorrect value for states[45].sid.code, expected 180, is " + << last_msg_->states[45].sid.code; + EXPECT_EQ(last_msg_->states[45].sid.sat, 192) + << "incorrect value for states[45].sid.sat, expected 192, is " + << last_msg_->states[45].sid.sat; + EXPECT_EQ(last_msg_->states[46].cn0, 211) + << "incorrect value for states[46].cn0, expected 211, is " + << last_msg_->states[46].cn0; + EXPECT_EQ(last_msg_->states[46].fcn, 172) + << "incorrect value for states[46].fcn, expected 172, is " + << last_msg_->states[46].fcn; + EXPECT_EQ(last_msg_->states[46].sid.code, 31) + << "incorrect value for states[46].sid.code, expected 31, is " + << last_msg_->states[46].sid.code; + EXPECT_EQ(last_msg_->states[46].sid.sat, 166) + << "incorrect value for states[46].sid.sat, expected 166, is " + << last_msg_->states[46].sid.sat; + EXPECT_EQ(last_msg_->states[47].cn0, 49) + << "incorrect value for states[47].cn0, expected 49, is " + << last_msg_->states[47].cn0; + EXPECT_EQ(last_msg_->states[47].fcn, 140) + << "incorrect value for states[47].fcn, expected 140, is " + << last_msg_->states[47].fcn; + EXPECT_EQ(last_msg_->states[47].sid.code, 228) + << "incorrect value for states[47].sid.code, expected 228, is " + << last_msg_->states[47].sid.code; + EXPECT_EQ(last_msg_->states[47].sid.sat, 77) + << "incorrect value for states[47].sid.sat, expected 77, is " + << last_msg_->states[47].sid.sat; + EXPECT_EQ(last_msg_->states[48].cn0, 194) + << "incorrect value for states[48].cn0, expected 194, is " + << last_msg_->states[48].cn0; + EXPECT_EQ(last_msg_->states[48].fcn, 240) + << "incorrect value for states[48].fcn, expected 240, is " + << last_msg_->states[48].fcn; + EXPECT_EQ(last_msg_->states[48].sid.code, 77) + << "incorrect value for states[48].sid.code, expected 77, is " + << last_msg_->states[48].sid.code; + EXPECT_EQ(last_msg_->states[48].sid.sat, 128) + << "incorrect value for states[48].sid.sat, expected 128, is " + << last_msg_->states[48].sid.sat; + EXPECT_EQ(last_msg_->states[49].cn0, 58) + << "incorrect value for states[49].cn0, expected 58, is " + << last_msg_->states[49].cn0; + EXPECT_EQ(last_msg_->states[49].fcn, 41) + << "incorrect value for states[49].fcn, expected 41, is " + << last_msg_->states[49].fcn; + EXPECT_EQ(last_msg_->states[49].sid.code, 194) + << "incorrect value for states[49].sid.code, expected 194, is " + << last_msg_->states[49].sid.code; + EXPECT_EQ(last_msg_->states[49].sid.sat, 134) + << "incorrect value for states[49].sid.sat, expected 134, is " + << last_msg_->states[49].sid.sat; + EXPECT_EQ(last_msg_->states[50].cn0, 55) + << "incorrect value for states[50].cn0, expected 55, is " + << last_msg_->states[50].cn0; + EXPECT_EQ(last_msg_->states[50].fcn, 129) + << "incorrect value for states[50].fcn, expected 129, is " + << last_msg_->states[50].fcn; + EXPECT_EQ(last_msg_->states[50].sid.code, 53) + << "incorrect value for states[50].sid.code, expected 53, is " + << last_msg_->states[50].sid.code; + EXPECT_EQ(last_msg_->states[50].sid.sat, 18) + << "incorrect value for states[50].sid.sat, expected 18, is " + << last_msg_->states[50].sid.sat; + EXPECT_EQ(last_msg_->states[51].cn0, 92) + << "incorrect value for states[51].cn0, expected 92, is " + << last_msg_->states[51].cn0; + EXPECT_EQ(last_msg_->states[51].fcn, 134) + << "incorrect value for states[51].fcn, expected 134, is " + << last_msg_->states[51].fcn; + EXPECT_EQ(last_msg_->states[51].sid.code, 72) + << "incorrect value for states[51].sid.code, expected 72, is " + << last_msg_->states[51].sid.code; + EXPECT_EQ(last_msg_->states[51].sid.sat, 91) + << "incorrect value for states[51].sid.sat, expected 91, is " + << last_msg_->states[51].sid.sat; + EXPECT_EQ(last_msg_->states[52].cn0, 56) + << "incorrect value for states[52].cn0, expected 56, is " + << last_msg_->states[52].cn0; + EXPECT_EQ(last_msg_->states[52].fcn, 157) + << "incorrect value for states[52].fcn, expected 157, is " + << last_msg_->states[52].fcn; + EXPECT_EQ(last_msg_->states[52].sid.code, 224) + << "incorrect value for states[52].sid.code, expected 224, is " + << last_msg_->states[52].sid.code; + EXPECT_EQ(last_msg_->states[52].sid.sat, 33) + << "incorrect value for states[52].sid.sat, expected 33, is " + << last_msg_->states[52].sid.sat; + EXPECT_EQ(last_msg_->states[53].cn0, 174) + << "incorrect value for states[53].cn0, expected 174, is " + << last_msg_->states[53].cn0; + EXPECT_EQ(last_msg_->states[53].fcn, 224) + << "incorrect value for states[53].fcn, expected 224, is " + << last_msg_->states[53].fcn; + EXPECT_EQ(last_msg_->states[53].sid.code, 54) + << "incorrect value for states[53].sid.code, expected 54, is " + << last_msg_->states[53].sid.code; + EXPECT_EQ(last_msg_->states[53].sid.sat, 186) + << "incorrect value for states[53].sid.sat, expected 186, is " + << last_msg_->states[53].sid.sat; + EXPECT_EQ(last_msg_->states[54].cn0, 190) + << "incorrect value for states[54].cn0, expected 190, is " + << last_msg_->states[54].cn0; + EXPECT_EQ(last_msg_->states[54].fcn, 148) + << "incorrect value for states[54].fcn, expected 148, is " + << last_msg_->states[54].fcn; + EXPECT_EQ(last_msg_->states[54].sid.code, 84) + << "incorrect value for states[54].sid.code, expected 84, is " + << last_msg_->states[54].sid.code; + EXPECT_EQ(last_msg_->states[54].sid.sat, 82) + << "incorrect value for states[54].sid.sat, expected 82, is " + << last_msg_->states[54].sid.sat; + EXPECT_EQ(last_msg_->states[55].cn0, 67) + << "incorrect value for states[55].cn0, expected 67, is " + << last_msg_->states[55].cn0; + EXPECT_EQ(last_msg_->states[55].fcn, 62) + << "incorrect value for states[55].fcn, expected 62, is " + << last_msg_->states[55].fcn; + EXPECT_EQ(last_msg_->states[55].sid.code, 54) + << "incorrect value for states[55].sid.code, expected 54, is " + << last_msg_->states[55].sid.code; + EXPECT_EQ(last_msg_->states[55].sid.sat, 236) + << "incorrect value for states[55].sid.sat, expected 236, is " + << last_msg_->states[55].sid.sat; + EXPECT_EQ(last_msg_->states[56].cn0, 254) + << "incorrect value for states[56].cn0, expected 254, is " + << last_msg_->states[56].cn0; + EXPECT_EQ(last_msg_->states[56].fcn, 57) + << "incorrect value for states[56].fcn, expected 57, is " + << last_msg_->states[56].fcn; + EXPECT_EQ(last_msg_->states[56].sid.code, 215) + << "incorrect value for states[56].sid.code, expected 215, is " + << last_msg_->states[56].sid.code; + EXPECT_EQ(last_msg_->states[56].sid.sat, 52) + << "incorrect value for states[56].sid.sat, expected 52, is " + << last_msg_->states[56].sid.sat; + EXPECT_EQ(last_msg_->states[57].cn0, 174) + << "incorrect value for states[57].cn0, expected 174, is " + << last_msg_->states[57].cn0; + EXPECT_EQ(last_msg_->states[57].fcn, 36) + << "incorrect value for states[57].fcn, expected 36, is " + << last_msg_->states[57].fcn; + EXPECT_EQ(last_msg_->states[57].sid.code, 133) + << "incorrect value for states[57].sid.code, expected 133, is " + << last_msg_->states[57].sid.code; + EXPECT_EQ(last_msg_->states[57].sid.sat, 16) + << "incorrect value for states[57].sid.sat, expected 16, is " + << last_msg_->states[57].sid.sat; + EXPECT_EQ(last_msg_->states[58].cn0, 17) + << "incorrect value for states[58].cn0, expected 17, is " + << last_msg_->states[58].cn0; + EXPECT_EQ(last_msg_->states[58].fcn, 145) + << "incorrect value for states[58].fcn, expected 145, is " + << last_msg_->states[58].fcn; + EXPECT_EQ(last_msg_->states[58].sid.code, 172) + << "incorrect value for states[58].sid.code, expected 172, is " + << last_msg_->states[58].sid.code; + EXPECT_EQ(last_msg_->states[58].sid.sat, 219) + << "incorrect value for states[58].sid.sat, expected 219, is " + << last_msg_->states[58].sid.sat; + EXPECT_EQ(last_msg_->states[59].cn0, 97) + << "incorrect value for states[59].cn0, expected 97, is " + << last_msg_->states[59].cn0; + EXPECT_EQ(last_msg_->states[59].fcn, 111) + << "incorrect value for states[59].fcn, expected 111, is " + << last_msg_->states[59].fcn; + EXPECT_EQ(last_msg_->states[59].sid.code, 179) + << "incorrect value for states[59].sid.code, expected 179, is " + << last_msg_->states[59].sid.code; + EXPECT_EQ(last_msg_->states[59].sid.sat, 192) + << "incorrect value for states[59].sid.sat, expected 192, is " + << last_msg_->states[59].sid.sat; + EXPECT_EQ(last_msg_->states[60].cn0, 134) + << "incorrect value for states[60].cn0, expected 134, is " + << last_msg_->states[60].cn0; + EXPECT_EQ(last_msg_->states[60].fcn, 208) + << "incorrect value for states[60].fcn, expected 208, is " + << last_msg_->states[60].fcn; + EXPECT_EQ(last_msg_->states[60].sid.code, 56) + << "incorrect value for states[60].sid.code, expected 56, is " + << last_msg_->states[60].sid.code; + EXPECT_EQ(last_msg_->states[60].sid.sat, 207) + << "incorrect value for states[60].sid.sat, expected 207, is " + << last_msg_->states[60].sid.sat; + EXPECT_EQ(last_msg_->states[61].cn0, 226) + << "incorrect value for states[61].cn0, expected 226, is " + << last_msg_->states[61].cn0; + EXPECT_EQ(last_msg_->states[61].fcn, 43) + << "incorrect value for states[61].fcn, expected 43, is " + << last_msg_->states[61].fcn; + EXPECT_EQ(last_msg_->states[61].sid.code, 17) + << "incorrect value for states[61].sid.code, expected 17, is " + << last_msg_->states[61].sid.code; + EXPECT_EQ(last_msg_->states[61].sid.sat, 180) + << "incorrect value for states[61].sid.sat, expected 180, is " + << last_msg_->states[61].sid.sat; + EXPECT_EQ(last_msg_->states[62].cn0, 113) + << "incorrect value for states[62].cn0, expected 113, is " + << last_msg_->states[62].cn0; + EXPECT_EQ(last_msg_->states[62].fcn, 140) + << "incorrect value for states[62].fcn, expected 140, is " + << last_msg_->states[62].fcn; + EXPECT_EQ(last_msg_->states[62].sid.code, 182) + << "incorrect value for states[62].sid.code, expected 182, is " + << last_msg_->states[62].sid.code; + EXPECT_EQ(last_msg_->states[62].sid.sat, 255) + << "incorrect value for states[62].sid.sat, expected 255, is " + << last_msg_->states[62].sid.sat; +} +class Test_legacy_auto_check_sbp_tracking_MsgTrackingState1 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingState1() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -77,7 +1435,7 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState0 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState0, Test) { +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState1, Test) { uint8_t encoded_frame[] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, 66, 1, 203, 0, 0, 0, 231, 99, 16, 66, 1, 208, 0, 0, @@ -372,14 +1730,14 @@ TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState0, Test) { << "incorrect value for states[10].state, expected 0, is " << last_msg_->states[10].state; } -class Test_legacy_auto_check_sbp_tracking_MsgTrackingState1 +class Test_legacy_auto_check_sbp_tracking_MsgTrackingState2 : public ::testing::Test, public sbp::State, public sbp::IReader, public sbp::IWriter, sbp::PayloadHandler { public: - Test_legacy_auto_check_sbp_tracking_MsgTrackingState1() + Test_legacy_auto_check_sbp_tracking_MsgTrackingState2() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -431,7 +1789,7 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState1 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState1, Test) { +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState2, Test) { uint8_t encoded_frame[] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 250, 249, 27, 66, 1, 203, 0, 0, 0, 40, 143, 11, 66, 1, 208, 0, 0, @@ -726,14 +2084,14 @@ TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState1, Test) { << "incorrect value for states[10].state, expected 0, is " << last_msg_->states[10].state; } -class Test_legacy_auto_check_sbp_tracking_MsgTrackingState2 +class Test_legacy_auto_check_sbp_tracking_MsgTrackingState3 : public ::testing::Test, public sbp::State, public sbp::IReader, public sbp::IWriter, sbp::PayloadHandler { public: - Test_legacy_auto_check_sbp_tracking_MsgTrackingState2() + Test_legacy_auto_check_sbp_tracking_MsgTrackingState3() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -785,7 +2143,7 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState2 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState2, Test) { +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState3, Test) { uint8_t encoded_frame[] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 123, 209, 27, 66, 1, 203, 0, 0, 0, 214, 64, 15, 66, 1, 208, 0, 0, @@ -1080,14 +2438,14 @@ TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState2, Test) { << "incorrect value for states[10].state, expected 0, is " << last_msg_->states[10].state; } -class Test_legacy_auto_check_sbp_tracking_MsgTrackingState3 +class Test_legacy_auto_check_sbp_tracking_MsgTrackingState4 : public ::testing::Test, public sbp::State, public sbp::IReader, public sbp::IWriter, sbp::PayloadHandler { public: - Test_legacy_auto_check_sbp_tracking_MsgTrackingState3() + Test_legacy_auto_check_sbp_tracking_MsgTrackingState4() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -1139,7 +2497,7 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState3 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState3, Test) { +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState4, Test) { uint8_t encoded_frame[] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 120, 122, 29, 66, 1, 203, 0, 0, 0, 66, 22, 18, 66, 1, 208, 0, 0, @@ -1434,14 +2792,14 @@ TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState3, Test) { << "incorrect value for states[10].state, expected 0, is " << last_msg_->states[10].state; } -class Test_legacy_auto_check_sbp_tracking_MsgTrackingState4 +class Test_legacy_auto_check_sbp_tracking_MsgTrackingState5 : public ::testing::Test, public sbp::State, public sbp::IReader, public sbp::IWriter, sbp::PayloadHandler { public: - Test_legacy_auto_check_sbp_tracking_MsgTrackingState4() + Test_legacy_auto_check_sbp_tracking_MsgTrackingState5() : ::testing::Test(), sbp::State(), sbp::IReader(), @@ -1493,7 +2851,7 @@ class Test_legacy_auto_check_sbp_tracking_MsgTrackingState4 uint8_t dummy_buff_[1024]; }; -TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState4, Test) { +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingState5, Test) { uint8_t encoded_frame[] = { 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 103, 208, 30, 66, 1, 203, 0, 0, 0, 117, 24, 18, 66, 1, 208, 0, 0, diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc new file mode 100644 index 0000000000..283a8216ef --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDepB.cc @@ -0,0 +1,792 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml by +// generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_( + reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_state_dep_b_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_state_dep_b_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDepB0, Test) { + uint8_t encoded_frame[] = { + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, 69, + 255, 175, 121, 43, 222, 51, 67, 35, 69, 78, 240, 5, 53, 20, 51, + 211, 54, 69, 153, 130, 237, 66, 155, 51, 227, 71, 69, 53, 242, 136, + 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, 154, 217, 184, 69, + 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, 115, 141, 27, 12, 154, + 225, 200, 69, 208, 44, 147, 39, 23, 51, 3, 66, 69, 237, 159, 251, + 49, 203, 51, 99, 102, 69, 70, 214, 87, 128, 206, 154, 121, 186, 69, + 14, 206, 111, 218, 19, 154, 121, 169, 69, 216, 98, 209, 54, 2, 154, + 25, 219, 67, 200, 133, 99, 7, 34, 102, 198, 232, 68, 155, 43, 85, + 135, 46, 154, 177, 170, 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, + 121, 43, 197, 16, 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, + 115, 66, 69, 36, 20, 61, 153, 51, 154, 73, 134, 69, 46, 82, 116, + 140, 22, 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, 76, 107, 68, + 220, 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, 135, + 186, 171, 51, 163, 4, 69, 18, 124, 155, 85, 170, 205, 208, 13, 70, + 57, 244, 206, 255, 186, 154, 105, 149, 69, 165, 199, 93, 181, 175, 51, + 67, 64, 69, 6, 28, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_state_dep_b_t *test_msg = + (msg_tracking_state_dep_b_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[0].cn0 = 5856.2001953125; + test_msg->states[0].sid.code = 63; + test_msg->states[0].sid.reserved = 68; + test_msg->states[0].sid.sat = 58295; + test_msg->states[0].state = 115; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[1].cn0 = 2612.199951171875; + test_msg->states[1].sid.code = 43; + test_msg->states[1].sid.reserved = 222; + test_msg->states[1].sid.sat = 31151; + test_msg->states[1].state = 255; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[2].cn0 = 2925.199951171875; + test_msg->states[2].sid.code = 53; + test_msg->states[2].sid.reserved = 20; + test_msg->states[2].sid.sat = 1520; + test_msg->states[2].state = 78; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[3].cn0 = 3198.199951171875; + test_msg->states[3].sid.code = 66; + test_msg->states[3].sid.reserved = 155; + test_msg->states[3].sid.sat = 60802; + test_msg->states[3].state = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[4].cn0 = 8623.2001953125; + test_msg->states[4].sid.code = 161; + test_msg->states[4].sid.reserved = 190; + test_msg->states[4].sid.sat = 35058; + test_msg->states[4].state = 53; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[5].cn0 = 5915.2001953125; + test_msg->states[5].sid.code = 142; + test_msg->states[5].sid.reserved = 149; + test_msg->states[5].sid.sat = 65405; + test_msg->states[5].state = 153; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[6].cn0 = 5412.2001953125; + test_msg->states[6].sid.code = 31; + test_msg->states[6].sid.reserved = 76; + test_msg->states[6].sid.sat = 24422; + test_msg->states[6].state = 248; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[7].cn0 = 6428.2001953125; + test_msg->states[7].sid.code = 27; + test_msg->states[7].sid.reserved = 12; + test_msg->states[7].sid.sat = 36211; + test_msg->states[7].state = 131; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[8].cn0 = 3104.199951171875; + test_msg->states[8].sid.code = 39; + test_msg->states[8].sid.reserved = 23; + test_msg->states[8].sid.sat = 37676; + test_msg->states[8].state = 208; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[9].cn0 = 3686.199951171875; + test_msg->states[9].sid.code = 49; + test_msg->states[9].sid.reserved = 203; + test_msg->states[9].sid.sat = 64415; + test_msg->states[9].state = 237; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[10].cn0 = 5967.2001953125; + test_msg->states[10].sid.code = 128; + test_msg->states[10].sid.reserved = 206; + test_msg->states[10].sid.sat = 22486; + test_msg->states[10].state = 70; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[11].cn0 = 5423.2001953125; + test_msg->states[11].sid.code = 218; + test_msg->states[11].sid.reserved = 19; + test_msg->states[11].sid.sat = 28622; + test_msg->states[11].state = 14; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[12].cn0 = 438.20001220703125; + test_msg->states[12].sid.code = 54; + test_msg->states[12].sid.reserved = 2; + test_msg->states[12].sid.sat = 53602; + test_msg->states[12].state = 216; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[13].cn0 = 1862.199951171875; + test_msg->states[13].sid.code = 7; + test_msg->states[13].sid.reserved = 34; + test_msg->states[13].sid.sat = 25477; + test_msg->states[13].state = 200; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[14].cn0 = 5462.2001953125; + test_msg->states[14].sid.code = 135; + test_msg->states[14].sid.reserved = 46; + test_msg->states[14].sid.sat = 21803; + test_msg->states[14].state = 155; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[15].cn0 = 7454.2001953125; + test_msg->states[15].sid.code = 171; + test_msg->states[15].sid.reserved = 201; + test_msg->states[15].sid.sat = 21251; + test_msg->states[15].state = 155; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[16].cn0 = 7134.2001953125; + test_msg->states[16].sid.code = 16; + test_msg->states[16].sid.reserved = 19; + test_msg->states[16].sid.sat = 50475; + test_msg->states[16].state = 121; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[17].cn0 = 3111.199951171875; + test_msg->states[17].sid.code = 63; + test_msg->states[17].sid.reserved = 176; + test_msg->states[17].sid.sat = 13813; + test_msg->states[17].state = 128; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[18].cn0 = 4297.2001953125; + test_msg->states[18].sid.code = 153; + test_msg->states[18].sid.reserved = 51; + test_msg->states[18].sid.sat = 15636; + test_msg->states[18].state = 36; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[19].cn0 = 2649.199951171875; + test_msg->states[19].sid.code = 140; + test_msg->states[19].sid.reserved = 22; + test_msg->states[19].sid.sat = 29778; + test_msg->states[19].state = 46; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[20].cn0 = 941.2000122070312; + test_msg->states[20].sid.code = 96; + test_msg->states[20].sid.reserved = 143; + test_msg->states[20].sid.sat = 37443; + test_msg->states[20].state = 177; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[21].cn0 = 1539.199951171875; + test_msg->states[21].sid.code = 201; + test_msg->states[21].sid.reserved = 251; + test_msg->states[21].sid.sat = 41011; + test_msg->states[21].state = 220; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[22].cn0 = 1443.199951171875; + test_msg->states[22].sid.code = 161; + test_msg->states[22].sid.reserved = 220; + test_msg->states[22].sid.sat = 706; + test_msg->states[22].state = 168; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[23].cn0 = 1074.199951171875; + test_msg->states[23].sid.code = 125; + test_msg->states[23].sid.reserved = 178; + test_msg->states[23].sid.sat = 2312; + test_msg->states[23].state = 69; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[24].cn0 = 2122.199951171875; + test_msg->states[24].sid.code = 186; + test_msg->states[24].sid.reserved = 171; + test_msg->states[24].sid.sat = 34580; + test_msg->states[24].state = 185; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[25].cn0 = 9076.2001953125; + test_msg->states[25].sid.code = 85; + test_msg->states[25].sid.reserved = 170; + test_msg->states[25].sid.sat = 39804; + test_msg->states[25].state = 18; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[26].cn0 = 4781.2001953125; + test_msg->states[26].sid.code = 255; + test_msg->states[26].sid.reserved = 186; + test_msg->states[26].sid.sat = 52980; + test_msg->states[26].state = 57; + if (sizeof(test_msg->states) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->states[0])); + } + test_msg->states[27].cn0 = 3076.199951171875; + test_msg->states[27].sid.code = 181; + test_msg->states[27].sid.reserved = 175; + test_msg->states[27].sid.sat = 24007; + test_msg->states[27].state = 165; + + EXPECT_EQ(send_message(0x13, 61938, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 61938); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_LT((last_msg_->states[0].cn0 * 100 - 5856.20019531 * 100), 0.05) + << "incorrect value for states[0].cn0, expected 5856.20019531, is " + << last_msg_->states[0].cn0; + EXPECT_EQ(last_msg_->states[0].sid.code, 63) + << "incorrect value for states[0].sid.code, expected 63, is " + << last_msg_->states[0].sid.code; + EXPECT_EQ(last_msg_->states[0].sid.reserved, 68) + << "incorrect value for states[0].sid.reserved, expected 68, is " + << last_msg_->states[0].sid.reserved; + EXPECT_EQ(last_msg_->states[0].sid.sat, 58295) + << "incorrect value for states[0].sid.sat, expected 58295, is " + << last_msg_->states[0].sid.sat; + EXPECT_EQ(last_msg_->states[0].state, 115) + << "incorrect value for states[0].state, expected 115, is " + << last_msg_->states[0].state; + EXPECT_LT((last_msg_->states[1].cn0 * 100 - 2612.19995117 * 100), 0.05) + << "incorrect value for states[1].cn0, expected 2612.19995117, is " + << last_msg_->states[1].cn0; + EXPECT_EQ(last_msg_->states[1].sid.code, 43) + << "incorrect value for states[1].sid.code, expected 43, is " + << last_msg_->states[1].sid.code; + EXPECT_EQ(last_msg_->states[1].sid.reserved, 222) + << "incorrect value for states[1].sid.reserved, expected 222, is " + << last_msg_->states[1].sid.reserved; + EXPECT_EQ(last_msg_->states[1].sid.sat, 31151) + << "incorrect value for states[1].sid.sat, expected 31151, is " + << last_msg_->states[1].sid.sat; + EXPECT_EQ(last_msg_->states[1].state, 255) + << "incorrect value for states[1].state, expected 255, is " + << last_msg_->states[1].state; + EXPECT_LT((last_msg_->states[2].cn0 * 100 - 2925.19995117 * 100), 0.05) + << "incorrect value for states[2].cn0, expected 2925.19995117, is " + << last_msg_->states[2].cn0; + EXPECT_EQ(last_msg_->states[2].sid.code, 53) + << "incorrect value for states[2].sid.code, expected 53, is " + << last_msg_->states[2].sid.code; + EXPECT_EQ(last_msg_->states[2].sid.reserved, 20) + << "incorrect value for states[2].sid.reserved, expected 20, is " + << last_msg_->states[2].sid.reserved; + EXPECT_EQ(last_msg_->states[2].sid.sat, 1520) + << "incorrect value for states[2].sid.sat, expected 1520, is " + << last_msg_->states[2].sid.sat; + EXPECT_EQ(last_msg_->states[2].state, 78) + << "incorrect value for states[2].state, expected 78, is " + << last_msg_->states[2].state; + EXPECT_LT((last_msg_->states[3].cn0 * 100 - 3198.19995117 * 100), 0.05) + << "incorrect value for states[3].cn0, expected 3198.19995117, is " + << last_msg_->states[3].cn0; + EXPECT_EQ(last_msg_->states[3].sid.code, 66) + << "incorrect value for states[3].sid.code, expected 66, is " + << last_msg_->states[3].sid.code; + EXPECT_EQ(last_msg_->states[3].sid.reserved, 155) + << "incorrect value for states[3].sid.reserved, expected 155, is " + << last_msg_->states[3].sid.reserved; + EXPECT_EQ(last_msg_->states[3].sid.sat, 60802) + << "incorrect value for states[3].sid.sat, expected 60802, is " + << last_msg_->states[3].sid.sat; + EXPECT_EQ(last_msg_->states[3].state, 153) + << "incorrect value for states[3].state, expected 153, is " + << last_msg_->states[3].state; + EXPECT_LT((last_msg_->states[4].cn0 * 100 - 8623.20019531 * 100), 0.05) + << "incorrect value for states[4].cn0, expected 8623.20019531, is " + << last_msg_->states[4].cn0; + EXPECT_EQ(last_msg_->states[4].sid.code, 161) + << "incorrect value for states[4].sid.code, expected 161, is " + << last_msg_->states[4].sid.code; + EXPECT_EQ(last_msg_->states[4].sid.reserved, 190) + << "incorrect value for states[4].sid.reserved, expected 190, is " + << last_msg_->states[4].sid.reserved; + EXPECT_EQ(last_msg_->states[4].sid.sat, 35058) + << "incorrect value for states[4].sid.sat, expected 35058, is " + << last_msg_->states[4].sid.sat; + EXPECT_EQ(last_msg_->states[4].state, 53) + << "incorrect value for states[4].state, expected 53, is " + << last_msg_->states[4].state; + EXPECT_LT((last_msg_->states[5].cn0 * 100 - 5915.20019531 * 100), 0.05) + << "incorrect value for states[5].cn0, expected 5915.20019531, is " + << last_msg_->states[5].cn0; + EXPECT_EQ(last_msg_->states[5].sid.code, 142) + << "incorrect value for states[5].sid.code, expected 142, is " + << last_msg_->states[5].sid.code; + EXPECT_EQ(last_msg_->states[5].sid.reserved, 149) + << "incorrect value for states[5].sid.reserved, expected 149, is " + << last_msg_->states[5].sid.reserved; + EXPECT_EQ(last_msg_->states[5].sid.sat, 65405) + << "incorrect value for states[5].sid.sat, expected 65405, is " + << last_msg_->states[5].sid.sat; + EXPECT_EQ(last_msg_->states[5].state, 153) + << "incorrect value for states[5].state, expected 153, is " + << last_msg_->states[5].state; + EXPECT_LT((last_msg_->states[6].cn0 * 100 - 5412.20019531 * 100), 0.05) + << "incorrect value for states[6].cn0, expected 5412.20019531, is " + << last_msg_->states[6].cn0; + EXPECT_EQ(last_msg_->states[6].sid.code, 31) + << "incorrect value for states[6].sid.code, expected 31, is " + << last_msg_->states[6].sid.code; + EXPECT_EQ(last_msg_->states[6].sid.reserved, 76) + << "incorrect value for states[6].sid.reserved, expected 76, is " + << last_msg_->states[6].sid.reserved; + EXPECT_EQ(last_msg_->states[6].sid.sat, 24422) + << "incorrect value for states[6].sid.sat, expected 24422, is " + << last_msg_->states[6].sid.sat; + EXPECT_EQ(last_msg_->states[6].state, 248) + << "incorrect value for states[6].state, expected 248, is " + << last_msg_->states[6].state; + EXPECT_LT((last_msg_->states[7].cn0 * 100 - 6428.20019531 * 100), 0.05) + << "incorrect value for states[7].cn0, expected 6428.20019531, is " + << last_msg_->states[7].cn0; + EXPECT_EQ(last_msg_->states[7].sid.code, 27) + << "incorrect value for states[7].sid.code, expected 27, is " + << last_msg_->states[7].sid.code; + EXPECT_EQ(last_msg_->states[7].sid.reserved, 12) + << "incorrect value for states[7].sid.reserved, expected 12, is " + << last_msg_->states[7].sid.reserved; + EXPECT_EQ(last_msg_->states[7].sid.sat, 36211) + << "incorrect value for states[7].sid.sat, expected 36211, is " + << last_msg_->states[7].sid.sat; + EXPECT_EQ(last_msg_->states[7].state, 131) + << "incorrect value for states[7].state, expected 131, is " + << last_msg_->states[7].state; + EXPECT_LT((last_msg_->states[8].cn0 * 100 - 3104.19995117 * 100), 0.05) + << "incorrect value for states[8].cn0, expected 3104.19995117, is " + << last_msg_->states[8].cn0; + EXPECT_EQ(last_msg_->states[8].sid.code, 39) + << "incorrect value for states[8].sid.code, expected 39, is " + << last_msg_->states[8].sid.code; + EXPECT_EQ(last_msg_->states[8].sid.reserved, 23) + << "incorrect value for states[8].sid.reserved, expected 23, is " + << last_msg_->states[8].sid.reserved; + EXPECT_EQ(last_msg_->states[8].sid.sat, 37676) + << "incorrect value for states[8].sid.sat, expected 37676, is " + << last_msg_->states[8].sid.sat; + EXPECT_EQ(last_msg_->states[8].state, 208) + << "incorrect value for states[8].state, expected 208, is " + << last_msg_->states[8].state; + EXPECT_LT((last_msg_->states[9].cn0 * 100 - 3686.19995117 * 100), 0.05) + << "incorrect value for states[9].cn0, expected 3686.19995117, is " + << last_msg_->states[9].cn0; + EXPECT_EQ(last_msg_->states[9].sid.code, 49) + << "incorrect value for states[9].sid.code, expected 49, is " + << last_msg_->states[9].sid.code; + EXPECT_EQ(last_msg_->states[9].sid.reserved, 203) + << "incorrect value for states[9].sid.reserved, expected 203, is " + << last_msg_->states[9].sid.reserved; + EXPECT_EQ(last_msg_->states[9].sid.sat, 64415) + << "incorrect value for states[9].sid.sat, expected 64415, is " + << last_msg_->states[9].sid.sat; + EXPECT_EQ(last_msg_->states[9].state, 237) + << "incorrect value for states[9].state, expected 237, is " + << last_msg_->states[9].state; + EXPECT_LT((last_msg_->states[10].cn0 * 100 - 5967.20019531 * 100), 0.05) + << "incorrect value for states[10].cn0, expected 5967.20019531, is " + << last_msg_->states[10].cn0; + EXPECT_EQ(last_msg_->states[10].sid.code, 128) + << "incorrect value for states[10].sid.code, expected 128, is " + << last_msg_->states[10].sid.code; + EXPECT_EQ(last_msg_->states[10].sid.reserved, 206) + << "incorrect value for states[10].sid.reserved, expected 206, is " + << last_msg_->states[10].sid.reserved; + EXPECT_EQ(last_msg_->states[10].sid.sat, 22486) + << "incorrect value for states[10].sid.sat, expected 22486, is " + << last_msg_->states[10].sid.sat; + EXPECT_EQ(last_msg_->states[10].state, 70) + << "incorrect value for states[10].state, expected 70, is " + << last_msg_->states[10].state; + EXPECT_LT((last_msg_->states[11].cn0 * 100 - 5423.20019531 * 100), 0.05) + << "incorrect value for states[11].cn0, expected 5423.20019531, is " + << last_msg_->states[11].cn0; + EXPECT_EQ(last_msg_->states[11].sid.code, 218) + << "incorrect value for states[11].sid.code, expected 218, is " + << last_msg_->states[11].sid.code; + EXPECT_EQ(last_msg_->states[11].sid.reserved, 19) + << "incorrect value for states[11].sid.reserved, expected 19, is " + << last_msg_->states[11].sid.reserved; + EXPECT_EQ(last_msg_->states[11].sid.sat, 28622) + << "incorrect value for states[11].sid.sat, expected 28622, is " + << last_msg_->states[11].sid.sat; + EXPECT_EQ(last_msg_->states[11].state, 14) + << "incorrect value for states[11].state, expected 14, is " + << last_msg_->states[11].state; + EXPECT_LT((last_msg_->states[12].cn0 * 100 - 438.200012207 * 100), 0.05) + << "incorrect value for states[12].cn0, expected 438.200012207, is " + << last_msg_->states[12].cn0; + EXPECT_EQ(last_msg_->states[12].sid.code, 54) + << "incorrect value for states[12].sid.code, expected 54, is " + << last_msg_->states[12].sid.code; + EXPECT_EQ(last_msg_->states[12].sid.reserved, 2) + << "incorrect value for states[12].sid.reserved, expected 2, is " + << last_msg_->states[12].sid.reserved; + EXPECT_EQ(last_msg_->states[12].sid.sat, 53602) + << "incorrect value for states[12].sid.sat, expected 53602, is " + << last_msg_->states[12].sid.sat; + EXPECT_EQ(last_msg_->states[12].state, 216) + << "incorrect value for states[12].state, expected 216, is " + << last_msg_->states[12].state; + EXPECT_LT((last_msg_->states[13].cn0 * 100 - 1862.19995117 * 100), 0.05) + << "incorrect value for states[13].cn0, expected 1862.19995117, is " + << last_msg_->states[13].cn0; + EXPECT_EQ(last_msg_->states[13].sid.code, 7) + << "incorrect value for states[13].sid.code, expected 7, is " + << last_msg_->states[13].sid.code; + EXPECT_EQ(last_msg_->states[13].sid.reserved, 34) + << "incorrect value for states[13].sid.reserved, expected 34, is " + << last_msg_->states[13].sid.reserved; + EXPECT_EQ(last_msg_->states[13].sid.sat, 25477) + << "incorrect value for states[13].sid.sat, expected 25477, is " + << last_msg_->states[13].sid.sat; + EXPECT_EQ(last_msg_->states[13].state, 200) + << "incorrect value for states[13].state, expected 200, is " + << last_msg_->states[13].state; + EXPECT_LT((last_msg_->states[14].cn0 * 100 - 5462.20019531 * 100), 0.05) + << "incorrect value for states[14].cn0, expected 5462.20019531, is " + << last_msg_->states[14].cn0; + EXPECT_EQ(last_msg_->states[14].sid.code, 135) + << "incorrect value for states[14].sid.code, expected 135, is " + << last_msg_->states[14].sid.code; + EXPECT_EQ(last_msg_->states[14].sid.reserved, 46) + << "incorrect value for states[14].sid.reserved, expected 46, is " + << last_msg_->states[14].sid.reserved; + EXPECT_EQ(last_msg_->states[14].sid.sat, 21803) + << "incorrect value for states[14].sid.sat, expected 21803, is " + << last_msg_->states[14].sid.sat; + EXPECT_EQ(last_msg_->states[14].state, 155) + << "incorrect value for states[14].state, expected 155, is " + << last_msg_->states[14].state; + EXPECT_LT((last_msg_->states[15].cn0 * 100 - 7454.20019531 * 100), 0.05) + << "incorrect value for states[15].cn0, expected 7454.20019531, is " + << last_msg_->states[15].cn0; + EXPECT_EQ(last_msg_->states[15].sid.code, 171) + << "incorrect value for states[15].sid.code, expected 171, is " + << last_msg_->states[15].sid.code; + EXPECT_EQ(last_msg_->states[15].sid.reserved, 201) + << "incorrect value for states[15].sid.reserved, expected 201, is " + << last_msg_->states[15].sid.reserved; + EXPECT_EQ(last_msg_->states[15].sid.sat, 21251) + << "incorrect value for states[15].sid.sat, expected 21251, is " + << last_msg_->states[15].sid.sat; + EXPECT_EQ(last_msg_->states[15].state, 155) + << "incorrect value for states[15].state, expected 155, is " + << last_msg_->states[15].state; + EXPECT_LT((last_msg_->states[16].cn0 * 100 - 7134.20019531 * 100), 0.05) + << "incorrect value for states[16].cn0, expected 7134.20019531, is " + << last_msg_->states[16].cn0; + EXPECT_EQ(last_msg_->states[16].sid.code, 16) + << "incorrect value for states[16].sid.code, expected 16, is " + << last_msg_->states[16].sid.code; + EXPECT_EQ(last_msg_->states[16].sid.reserved, 19) + << "incorrect value for states[16].sid.reserved, expected 19, is " + << last_msg_->states[16].sid.reserved; + EXPECT_EQ(last_msg_->states[16].sid.sat, 50475) + << "incorrect value for states[16].sid.sat, expected 50475, is " + << last_msg_->states[16].sid.sat; + EXPECT_EQ(last_msg_->states[16].state, 121) + << "incorrect value for states[16].state, expected 121, is " + << last_msg_->states[16].state; + EXPECT_LT((last_msg_->states[17].cn0 * 100 - 3111.19995117 * 100), 0.05) + << "incorrect value for states[17].cn0, expected 3111.19995117, is " + << last_msg_->states[17].cn0; + EXPECT_EQ(last_msg_->states[17].sid.code, 63) + << "incorrect value for states[17].sid.code, expected 63, is " + << last_msg_->states[17].sid.code; + EXPECT_EQ(last_msg_->states[17].sid.reserved, 176) + << "incorrect value for states[17].sid.reserved, expected 176, is " + << last_msg_->states[17].sid.reserved; + EXPECT_EQ(last_msg_->states[17].sid.sat, 13813) + << "incorrect value for states[17].sid.sat, expected 13813, is " + << last_msg_->states[17].sid.sat; + EXPECT_EQ(last_msg_->states[17].state, 128) + << "incorrect value for states[17].state, expected 128, is " + << last_msg_->states[17].state; + EXPECT_LT((last_msg_->states[18].cn0 * 100 - 4297.20019531 * 100), 0.05) + << "incorrect value for states[18].cn0, expected 4297.20019531, is " + << last_msg_->states[18].cn0; + EXPECT_EQ(last_msg_->states[18].sid.code, 153) + << "incorrect value for states[18].sid.code, expected 153, is " + << last_msg_->states[18].sid.code; + EXPECT_EQ(last_msg_->states[18].sid.reserved, 51) + << "incorrect value for states[18].sid.reserved, expected 51, is " + << last_msg_->states[18].sid.reserved; + EXPECT_EQ(last_msg_->states[18].sid.sat, 15636) + << "incorrect value for states[18].sid.sat, expected 15636, is " + << last_msg_->states[18].sid.sat; + EXPECT_EQ(last_msg_->states[18].state, 36) + << "incorrect value for states[18].state, expected 36, is " + << last_msg_->states[18].state; + EXPECT_LT((last_msg_->states[19].cn0 * 100 - 2649.19995117 * 100), 0.05) + << "incorrect value for states[19].cn0, expected 2649.19995117, is " + << last_msg_->states[19].cn0; + EXPECT_EQ(last_msg_->states[19].sid.code, 140) + << "incorrect value for states[19].sid.code, expected 140, is " + << last_msg_->states[19].sid.code; + EXPECT_EQ(last_msg_->states[19].sid.reserved, 22) + << "incorrect value for states[19].sid.reserved, expected 22, is " + << last_msg_->states[19].sid.reserved; + EXPECT_EQ(last_msg_->states[19].sid.sat, 29778) + << "incorrect value for states[19].sid.sat, expected 29778, is " + << last_msg_->states[19].sid.sat; + EXPECT_EQ(last_msg_->states[19].state, 46) + << "incorrect value for states[19].state, expected 46, is " + << last_msg_->states[19].state; + EXPECT_LT((last_msg_->states[20].cn0 * 100 - 941.200012207 * 100), 0.05) + << "incorrect value for states[20].cn0, expected 941.200012207, is " + << last_msg_->states[20].cn0; + EXPECT_EQ(last_msg_->states[20].sid.code, 96) + << "incorrect value for states[20].sid.code, expected 96, is " + << last_msg_->states[20].sid.code; + EXPECT_EQ(last_msg_->states[20].sid.reserved, 143) + << "incorrect value for states[20].sid.reserved, expected 143, is " + << last_msg_->states[20].sid.reserved; + EXPECT_EQ(last_msg_->states[20].sid.sat, 37443) + << "incorrect value for states[20].sid.sat, expected 37443, is " + << last_msg_->states[20].sid.sat; + EXPECT_EQ(last_msg_->states[20].state, 177) + << "incorrect value for states[20].state, expected 177, is " + << last_msg_->states[20].state; + EXPECT_LT((last_msg_->states[21].cn0 * 100 - 1539.19995117 * 100), 0.05) + << "incorrect value for states[21].cn0, expected 1539.19995117, is " + << last_msg_->states[21].cn0; + EXPECT_EQ(last_msg_->states[21].sid.code, 201) + << "incorrect value for states[21].sid.code, expected 201, is " + << last_msg_->states[21].sid.code; + EXPECT_EQ(last_msg_->states[21].sid.reserved, 251) + << "incorrect value for states[21].sid.reserved, expected 251, is " + << last_msg_->states[21].sid.reserved; + EXPECT_EQ(last_msg_->states[21].sid.sat, 41011) + << "incorrect value for states[21].sid.sat, expected 41011, is " + << last_msg_->states[21].sid.sat; + EXPECT_EQ(last_msg_->states[21].state, 220) + << "incorrect value for states[21].state, expected 220, is " + << last_msg_->states[21].state; + EXPECT_LT((last_msg_->states[22].cn0 * 100 - 1443.19995117 * 100), 0.05) + << "incorrect value for states[22].cn0, expected 1443.19995117, is " + << last_msg_->states[22].cn0; + EXPECT_EQ(last_msg_->states[22].sid.code, 161) + << "incorrect value for states[22].sid.code, expected 161, is " + << last_msg_->states[22].sid.code; + EXPECT_EQ(last_msg_->states[22].sid.reserved, 220) + << "incorrect value for states[22].sid.reserved, expected 220, is " + << last_msg_->states[22].sid.reserved; + EXPECT_EQ(last_msg_->states[22].sid.sat, 706) + << "incorrect value for states[22].sid.sat, expected 706, is " + << last_msg_->states[22].sid.sat; + EXPECT_EQ(last_msg_->states[22].state, 168) + << "incorrect value for states[22].state, expected 168, is " + << last_msg_->states[22].state; + EXPECT_LT((last_msg_->states[23].cn0 * 100 - 1074.19995117 * 100), 0.05) + << "incorrect value for states[23].cn0, expected 1074.19995117, is " + << last_msg_->states[23].cn0; + EXPECT_EQ(last_msg_->states[23].sid.code, 125) + << "incorrect value for states[23].sid.code, expected 125, is " + << last_msg_->states[23].sid.code; + EXPECT_EQ(last_msg_->states[23].sid.reserved, 178) + << "incorrect value for states[23].sid.reserved, expected 178, is " + << last_msg_->states[23].sid.reserved; + EXPECT_EQ(last_msg_->states[23].sid.sat, 2312) + << "incorrect value for states[23].sid.sat, expected 2312, is " + << last_msg_->states[23].sid.sat; + EXPECT_EQ(last_msg_->states[23].state, 69) + << "incorrect value for states[23].state, expected 69, is " + << last_msg_->states[23].state; + EXPECT_LT((last_msg_->states[24].cn0 * 100 - 2122.19995117 * 100), 0.05) + << "incorrect value for states[24].cn0, expected 2122.19995117, is " + << last_msg_->states[24].cn0; + EXPECT_EQ(last_msg_->states[24].sid.code, 186) + << "incorrect value for states[24].sid.code, expected 186, is " + << last_msg_->states[24].sid.code; + EXPECT_EQ(last_msg_->states[24].sid.reserved, 171) + << "incorrect value for states[24].sid.reserved, expected 171, is " + << last_msg_->states[24].sid.reserved; + EXPECT_EQ(last_msg_->states[24].sid.sat, 34580) + << "incorrect value for states[24].sid.sat, expected 34580, is " + << last_msg_->states[24].sid.sat; + EXPECT_EQ(last_msg_->states[24].state, 185) + << "incorrect value for states[24].state, expected 185, is " + << last_msg_->states[24].state; + EXPECT_LT((last_msg_->states[25].cn0 * 100 - 9076.20019531 * 100), 0.05) + << "incorrect value for states[25].cn0, expected 9076.20019531, is " + << last_msg_->states[25].cn0; + EXPECT_EQ(last_msg_->states[25].sid.code, 85) + << "incorrect value for states[25].sid.code, expected 85, is " + << last_msg_->states[25].sid.code; + EXPECT_EQ(last_msg_->states[25].sid.reserved, 170) + << "incorrect value for states[25].sid.reserved, expected 170, is " + << last_msg_->states[25].sid.reserved; + EXPECT_EQ(last_msg_->states[25].sid.sat, 39804) + << "incorrect value for states[25].sid.sat, expected 39804, is " + << last_msg_->states[25].sid.sat; + EXPECT_EQ(last_msg_->states[25].state, 18) + << "incorrect value for states[25].state, expected 18, is " + << last_msg_->states[25].state; + EXPECT_LT((last_msg_->states[26].cn0 * 100 - 4781.20019531 * 100), 0.05) + << "incorrect value for states[26].cn0, expected 4781.20019531, is " + << last_msg_->states[26].cn0; + EXPECT_EQ(last_msg_->states[26].sid.code, 255) + << "incorrect value for states[26].sid.code, expected 255, is " + << last_msg_->states[26].sid.code; + EXPECT_EQ(last_msg_->states[26].sid.reserved, 186) + << "incorrect value for states[26].sid.reserved, expected 186, is " + << last_msg_->states[26].sid.reserved; + EXPECT_EQ(last_msg_->states[26].sid.sat, 52980) + << "incorrect value for states[26].sid.sat, expected 52980, is " + << last_msg_->states[26].sid.sat; + EXPECT_EQ(last_msg_->states[26].state, 57) + << "incorrect value for states[26].state, expected 57, is " + << last_msg_->states[26].state; + EXPECT_LT((last_msg_->states[27].cn0 * 100 - 3076.19995117 * 100), 0.05) + << "incorrect value for states[27].cn0, expected 3076.19995117, is " + << last_msg_->states[27].cn0; + EXPECT_EQ(last_msg_->states[27].sid.code, 181) + << "incorrect value for states[27].sid.code, expected 181, is " + << last_msg_->states[27].sid.code; + EXPECT_EQ(last_msg_->states[27].sid.reserved, 175) + << "incorrect value for states[27].sid.reserved, expected 175, is " + << last_msg_->states[27].sid.reserved; + EXPECT_EQ(last_msg_->states[27].sid.sat, 24007) + << "incorrect value for states[27].sid.sat, expected 24007, is " + << last_msg_->states[27].sid.sat; + EXPECT_EQ(last_msg_->states[27].state, 165) + << "incorrect value for states[27].state, expected 165, is " + << last_msg_->states[27].state; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc new file mode 100644 index 0000000000..de70f2359b --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_tracking_MsgTrackingStateDetailedDepA.cc @@ -0,0 +1,200 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml +// by generate.py. Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast( + last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_tracking_state_detailed_dep_a_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_tracking_state_detailed_dep_a_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_tracking_MsgTrackingStateDetailedDepA0, + Test) { + uint8_t encoded_frame[] = { + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, + 0, 133, 100, 71, 94, 192, 2, 160, 207, 212, 255, 135, 139, + 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, + 59, 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, + 15, 91, 249, 117, 142, 90, 219, 67, 25, 83, 62, 122, 100, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_tracking_state_detailed_dep_a_t *test_msg = + (msg_tracking_state_detailed_dep_a_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->L.f = 204; + test_msg->L.i = -1601767965; + test_msg->P = 1044286343; + test_msg->P_std = 21427; + test_msg->acceleration = -114; + test_msg->clock_drift = 23311; + test_msg->clock_offset = 6012; + test_msg->cn0 = 78; + test_msg->corr_spacing = 30201; + test_msg->doppler = 1459556257; + test_msg->doppler_std = 63677; + test_msg->lock = 65375; + test_msg->misc_flags = 62; + test_msg->nav_flags = 25; + test_msg->pset_flags = 83; + test_msg->recv_time = 941247176494; + test_msg->sid.code = 59; + test_msg->sid.sat = 38; + test_msg->sync_flags = 90; + test_msg->tot.ns_residual = -811597120; + test_msg->tot.tow = 1581737093; + test_msg->tot.wn = 65492; + test_msg->tow_flags = 219; + test_msg->track_flags = 67; + test_msg->uptime = 3263741727; + + EXPECT_EQ(send_message(0x21, 28315, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 28315); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->L.f, 204) + << "incorrect value for L.f, expected 204, is " << last_msg_->L.f; + EXPECT_EQ(last_msg_->L.i, -1601767965) + << "incorrect value for L.i, expected -1601767965, is " << last_msg_->L.i; + EXPECT_EQ(last_msg_->P, 1044286343) + << "incorrect value for P, expected 1044286343, is " << last_msg_->P; + EXPECT_EQ(last_msg_->P_std, 21427) + << "incorrect value for P_std, expected 21427, is " << last_msg_->P_std; + EXPECT_EQ(last_msg_->acceleration, -114) + << "incorrect value for acceleration, expected -114, is " + << last_msg_->acceleration; + EXPECT_EQ(last_msg_->clock_drift, 23311) + << "incorrect value for clock_drift, expected 23311, is " + << last_msg_->clock_drift; + EXPECT_EQ(last_msg_->clock_offset, 6012) + << "incorrect value for clock_offset, expected 6012, is " + << last_msg_->clock_offset; + EXPECT_EQ(last_msg_->cn0, 78) + << "incorrect value for cn0, expected 78, is " << last_msg_->cn0; + EXPECT_EQ(last_msg_->corr_spacing, 30201) + << "incorrect value for corr_spacing, expected 30201, is " + << last_msg_->corr_spacing; + EXPECT_EQ(last_msg_->doppler, 1459556257) + << "incorrect value for doppler, expected 1459556257, is " + << last_msg_->doppler; + EXPECT_EQ(last_msg_->doppler_std, 63677) + << "incorrect value for doppler_std, expected 63677, is " + << last_msg_->doppler_std; + EXPECT_EQ(last_msg_->lock, 65375) + << "incorrect value for lock, expected 65375, is " << last_msg_->lock; + EXPECT_EQ(last_msg_->misc_flags, 62) + << "incorrect value for misc_flags, expected 62, is " + << last_msg_->misc_flags; + EXPECT_EQ(last_msg_->nav_flags, 25) + << "incorrect value for nav_flags, expected 25, is " + << last_msg_->nav_flags; + EXPECT_EQ(last_msg_->pset_flags, 83) + << "incorrect value for pset_flags, expected 83, is " + << last_msg_->pset_flags; + EXPECT_EQ(last_msg_->recv_time, 941247176494) + << "incorrect value for recv_time, expected 941247176494, is " + << last_msg_->recv_time; + EXPECT_EQ(last_msg_->sid.code, 59) + << "incorrect value for sid.code, expected 59, is " + << last_msg_->sid.code; + EXPECT_EQ(last_msg_->sid.sat, 38) + << "incorrect value for sid.sat, expected 38, is " << last_msg_->sid.sat; + EXPECT_EQ(last_msg_->sync_flags, 90) + << "incorrect value for sync_flags, expected 90, is " + << last_msg_->sync_flags; + EXPECT_EQ(last_msg_->tot.ns_residual, -811597120) + << "incorrect value for tot.ns_residual, expected -811597120, is " + << last_msg_->tot.ns_residual; + EXPECT_EQ(last_msg_->tot.tow, 1581737093) + << "incorrect value for tot.tow, expected 1581737093, is " + << last_msg_->tot.tow; + EXPECT_EQ(last_msg_->tot.wn, 65492) + << "incorrect value for tot.wn, expected 65492, is " << last_msg_->tot.wn; + EXPECT_EQ(last_msg_->tow_flags, 219) + << "incorrect value for tow_flags, expected 219, is " + << last_msg_->tow_flags; + EXPECT_EQ(last_msg_->track_flags, 67) + << "incorrect value for track_flags, expected 67, is " + << last_msg_->track_flags; + EXPECT_EQ(last_msg_->uptime, 3263741727) + << "incorrect value for uptime, expected 3263741727, is " + << last_msg_->uptime; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_user_MsgUserData.cc b/c/test/legacy/cpp/auto_check_sbp_user_MsgUserData.cc new file mode 100644 index 0000000000..dafc79dcb8 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_user_MsgUserData.cc @@ -0,0 +1,2158 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml by generate.py. Do +// not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_user_MsgUserData0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_user_MsgUserData0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_user_data_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_user_data_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_user_MsgUserData0, Test) { + uint8_t encoded_frame[] = { + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, 149, + 204, 113, 31, 108, 188, 179, 154, 156, 167, 145, 139, 42, 207, 126, 242, + 193, 9, 58, 75, 8, 135, 11, 92, 131, 245, 24, 90, 255, 30, 58, + 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, 50, 148, 1, 99, + 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, 97, 96, 75, 174, 58, + 219, 180, 148, 247, 59, 2, 116, 214, 114, 55, 134, 54, 119, 108, 128, + 73, 181, 20, 233, 23, 23, 73, 119, 136, 231, 189, 26, 174, 128, 93, + 30, 76, 45, 109, 134, 81, 0, 116, 158, 127, 40, 133, 208, 134, 127, + 140, 232, 183, 184, 108, 6, 228, 54, 238, 59, 220, 30, 228, 212, 50, + 182, 97, 20, 41, 76, 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, + 189, 44, 239, 232, 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, + 173, 157, 202, 172, 180, 150, 213, 193, 177, 209, 156, 20, 174, 18, 73, + 132, 215, 115, 128, 175, 169, 116, 132, 100, 72, 45, 25, 14, 205, 213, + 145, 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, 6, 165, + 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, 132, + 59, 61, 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, 56, 216, + 19, 216, 70, 71, 161, 184, 5, 177, 45, 37, 98, 56, 149, 0, 73, + 221, 105, 239, 168, 205, 85, 81, 245, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_user_data_t *test_msg = (msg_user_data_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[0] = 53; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[1] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[2] = 172; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[3] = 138; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[4] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[5] = 49; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[6] = 206; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[7] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[8] = 149; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[9] = 204; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[10] = 113; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[11] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[12] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[13] = 188; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[14] = 179; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[15] = 154; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[16] = 156; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[17] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[18] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[19] = 139; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[20] = 42; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[21] = 207; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[22] = 126; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[23] = 242; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[24] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[25] = 9; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[26] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[27] = 75; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[28] = 8; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[29] = 135; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[30] = 11; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[31] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[32] = 131; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[33] = 245; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[34] = 24; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[35] = 90; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[36] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[37] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[38] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[39] = 31; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[40] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[41] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[42] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[43] = 178; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[44] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[45] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[46] = 159; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[47] = 70; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[48] = 17; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[49] = 170; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[50] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[51] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[52] = 1; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[53] = 99; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[54] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[55] = 88; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[56] = 217; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[57] = 36; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[58] = 84; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[59] = 34; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[60] = 234; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[61] = 82; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[62] = 144; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[63] = 144; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[64] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[65] = 96; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[66] = 75; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[67] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[68] = 58; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[69] = 219; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[70] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[71] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[72] = 247; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[73] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[74] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[75] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[76] = 214; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[77] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[78] = 55; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[79] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[80] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[81] = 119; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[82] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[83] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[84] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[85] = 181; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[86] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[87] = 233; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[88] = 23; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[89] = 23; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[90] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[91] = 119; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[92] = 136; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[93] = 231; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[94] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[95] = 26; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[96] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[97] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[98] = 93; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[99] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[100] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[101] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[102] = 109; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[103] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[104] = 81; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[105] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[106] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[107] = 158; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[108] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[109] = 40; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[110] = 133; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[111] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[112] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[113] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[114] = 140; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[115] = 232; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[116] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[117] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[118] = 108; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[119] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[120] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[121] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[122] = 238; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[123] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[124] = 220; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[125] = 30; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[126] = 228; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[127] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[128] = 50; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[129] = 182; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[130] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[131] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[132] = 41; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[133] = 76; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[134] = 227; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[135] = 88; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[136] = 12; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[137] = 95; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[138] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[139] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[140] = 183; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[141] = 127; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[142] = 4; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[143] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[144] = 189; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[145] = 44; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[146] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[147] = 232; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[148] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[149] = 9; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[150] = 114; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[151] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[152] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[153] = 208; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[154] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[155] = 194; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[156] = 250; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[157] = 2; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[158] = 97; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[159] = 173; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[160] = 157; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[161] = 202; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[162] = 172; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[163] = 180; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[164] = 150; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[165] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[166] = 193; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[167] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[168] = 209; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[169] = 156; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[170] = 20; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[171] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[172] = 18; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[173] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[174] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[175] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[176] = 115; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[177] = 128; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[178] = 175; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[179] = 169; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[180] = 116; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[181] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[182] = 100; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[183] = 72; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[184] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[185] = 25; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[186] = 14; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[187] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[188] = 213; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[189] = 145; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[190] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[191] = 137; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[192] = 249; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[193] = 54; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[194] = 40; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[195] = 174; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[196] = 215; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[197] = 148; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[198] = 166; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[199] = 190; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[200] = 63; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[201] = 118; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[202] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[203] = 165; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[204] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[205] = 74; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[206] = 68; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[207] = 200; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[208] = 38; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[209] = 139; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[210] = 212; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[211] = 112; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[212] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[213] = 167; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[214] = 236; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[215] = 255; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[216] = 106; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[217] = 92; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[218] = 132; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[219] = 59; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[220] = 61; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[221] = 233; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[222] = 3; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[223] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[224] = 158; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[225] = 83; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[226] = 134; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[227] = 246; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[228] = 154; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[229] = 17; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[230] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[231] = 6; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[232] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[233] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[234] = 19; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[235] = 216; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[236] = 70; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[237] = 71; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[238] = 161; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[239] = 184; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[240] = 5; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[241] = 177; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[242] = 45; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[243] = 37; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[244] = 98; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[245] = 56; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[246] = 149; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[247] = 0; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[248] = 73; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[249] = 221; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[250] = 105; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[251] = 239; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[252] = 168; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[253] = 205; + if (sizeof(test_msg->contents) == 0) { + // Cope with variable length arrays + test_msg_len = (uint8_t)(test_msg_len + sizeof(test_msg->contents[0])); + } + test_msg->contents[254] = 85; + + EXPECT_EQ(send_message(0x800, 8574, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 8574); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->contents[0], 53) + << "incorrect value for contents[0], expected 53, is " + << last_msg_->contents[0]; + EXPECT_EQ(last_msg_->contents[1], 5) + << "incorrect value for contents[1], expected 5, is " + << last_msg_->contents[1]; + EXPECT_EQ(last_msg_->contents[2], 172) + << "incorrect value for contents[2], expected 172, is " + << last_msg_->contents[2]; + EXPECT_EQ(last_msg_->contents[3], 138) + << "incorrect value for contents[3], expected 138, is " + << last_msg_->contents[3]; + EXPECT_EQ(last_msg_->contents[4], 50) + << "incorrect value for contents[4], expected 50, is " + << last_msg_->contents[4]; + EXPECT_EQ(last_msg_->contents[5], 49) + << "incorrect value for contents[5], expected 49, is " + << last_msg_->contents[5]; + EXPECT_EQ(last_msg_->contents[6], 206) + << "incorrect value for contents[6], expected 206, is " + << last_msg_->contents[6]; + EXPECT_EQ(last_msg_->contents[7], 234) + << "incorrect value for contents[7], expected 234, is " + << last_msg_->contents[7]; + EXPECT_EQ(last_msg_->contents[8], 149) + << "incorrect value for contents[8], expected 149, is " + << last_msg_->contents[8]; + EXPECT_EQ(last_msg_->contents[9], 204) + << "incorrect value for contents[9], expected 204, is " + << last_msg_->contents[9]; + EXPECT_EQ(last_msg_->contents[10], 113) + << "incorrect value for contents[10], expected 113, is " + << last_msg_->contents[10]; + EXPECT_EQ(last_msg_->contents[11], 31) + << "incorrect value for contents[11], expected 31, is " + << last_msg_->contents[11]; + EXPECT_EQ(last_msg_->contents[12], 108) + << "incorrect value for contents[12], expected 108, is " + << last_msg_->contents[12]; + EXPECT_EQ(last_msg_->contents[13], 188) + << "incorrect value for contents[13], expected 188, is " + << last_msg_->contents[13]; + EXPECT_EQ(last_msg_->contents[14], 179) + << "incorrect value for contents[14], expected 179, is " + << last_msg_->contents[14]; + EXPECT_EQ(last_msg_->contents[15], 154) + << "incorrect value for contents[15], expected 154, is " + << last_msg_->contents[15]; + EXPECT_EQ(last_msg_->contents[16], 156) + << "incorrect value for contents[16], expected 156, is " + << last_msg_->contents[16]; + EXPECT_EQ(last_msg_->contents[17], 167) + << "incorrect value for contents[17], expected 167, is " + << last_msg_->contents[17]; + EXPECT_EQ(last_msg_->contents[18], 145) + << "incorrect value for contents[18], expected 145, is " + << last_msg_->contents[18]; + EXPECT_EQ(last_msg_->contents[19], 139) + << "incorrect value for contents[19], expected 139, is " + << last_msg_->contents[19]; + EXPECT_EQ(last_msg_->contents[20], 42) + << "incorrect value for contents[20], expected 42, is " + << last_msg_->contents[20]; + EXPECT_EQ(last_msg_->contents[21], 207) + << "incorrect value for contents[21], expected 207, is " + << last_msg_->contents[21]; + EXPECT_EQ(last_msg_->contents[22], 126) + << "incorrect value for contents[22], expected 126, is " + << last_msg_->contents[22]; + EXPECT_EQ(last_msg_->contents[23], 242) + << "incorrect value for contents[23], expected 242, is " + << last_msg_->contents[23]; + EXPECT_EQ(last_msg_->contents[24], 193) + << "incorrect value for contents[24], expected 193, is " + << last_msg_->contents[24]; + EXPECT_EQ(last_msg_->contents[25], 9) + << "incorrect value for contents[25], expected 9, is " + << last_msg_->contents[25]; + EXPECT_EQ(last_msg_->contents[26], 58) + << "incorrect value for contents[26], expected 58, is " + << last_msg_->contents[26]; + EXPECT_EQ(last_msg_->contents[27], 75) + << "incorrect value for contents[27], expected 75, is " + << last_msg_->contents[27]; + EXPECT_EQ(last_msg_->contents[28], 8) + << "incorrect value for contents[28], expected 8, is " + << last_msg_->contents[28]; + EXPECT_EQ(last_msg_->contents[29], 135) + << "incorrect value for contents[29], expected 135, is " + << last_msg_->contents[29]; + EXPECT_EQ(last_msg_->contents[30], 11) + << "incorrect value for contents[30], expected 11, is " + << last_msg_->contents[30]; + EXPECT_EQ(last_msg_->contents[31], 92) + << "incorrect value for contents[31], expected 92, is " + << last_msg_->contents[31]; + EXPECT_EQ(last_msg_->contents[32], 131) + << "incorrect value for contents[32], expected 131, is " + << last_msg_->contents[32]; + EXPECT_EQ(last_msg_->contents[33], 245) + << "incorrect value for contents[33], expected 245, is " + << last_msg_->contents[33]; + EXPECT_EQ(last_msg_->contents[34], 24) + << "incorrect value for contents[34], expected 24, is " + << last_msg_->contents[34]; + EXPECT_EQ(last_msg_->contents[35], 90) + << "incorrect value for contents[35], expected 90, is " + << last_msg_->contents[35]; + EXPECT_EQ(last_msg_->contents[36], 255) + << "incorrect value for contents[36], expected 255, is " + << last_msg_->contents[36]; + EXPECT_EQ(last_msg_->contents[37], 30) + << "incorrect value for contents[37], expected 30, is " + << last_msg_->contents[37]; + EXPECT_EQ(last_msg_->contents[38], 58) + << "incorrect value for contents[38], expected 58, is " + << last_msg_->contents[38]; + EXPECT_EQ(last_msg_->contents[39], 31) + << "incorrect value for contents[39], expected 31, is " + << last_msg_->contents[39]; + EXPECT_EQ(last_msg_->contents[40], 109) + << "incorrect value for contents[40], expected 109, is " + << last_msg_->contents[40]; + EXPECT_EQ(last_msg_->contents[41], 148) + << "incorrect value for contents[41], expected 148, is " + << last_msg_->contents[41]; + EXPECT_EQ(last_msg_->contents[42], 56) + << "incorrect value for contents[42], expected 56, is " + << last_msg_->contents[42]; + EXPECT_EQ(last_msg_->contents[43], 178) + << "incorrect value for contents[43], expected 178, is " + << last_msg_->contents[43]; + EXPECT_EQ(last_msg_->contents[44], 140) + << "incorrect value for contents[44], expected 140, is " + << last_msg_->contents[44]; + EXPECT_EQ(last_msg_->contents[45], 30) + << "incorrect value for contents[45], expected 30, is " + << last_msg_->contents[45]; + EXPECT_EQ(last_msg_->contents[46], 159) + << "incorrect value for contents[46], expected 159, is " + << last_msg_->contents[46]; + EXPECT_EQ(last_msg_->contents[47], 70) + << "incorrect value for contents[47], expected 70, is " + << last_msg_->contents[47]; + EXPECT_EQ(last_msg_->contents[48], 17) + << "incorrect value for contents[48], expected 17, is " + << last_msg_->contents[48]; + EXPECT_EQ(last_msg_->contents[49], 170) + << "incorrect value for contents[49], expected 170, is " + << last_msg_->contents[49]; + EXPECT_EQ(last_msg_->contents[50], 50) + << "incorrect value for contents[50], expected 50, is " + << last_msg_->contents[50]; + EXPECT_EQ(last_msg_->contents[51], 148) + << "incorrect value for contents[51], expected 148, is " + << last_msg_->contents[51]; + EXPECT_EQ(last_msg_->contents[52], 1) + << "incorrect value for contents[52], expected 1, is " + << last_msg_->contents[52]; + EXPECT_EQ(last_msg_->contents[53], 99) + << "incorrect value for contents[53], expected 99, is " + << last_msg_->contents[53]; + EXPECT_EQ(last_msg_->contents[54], 112) + << "incorrect value for contents[54], expected 112, is " + << last_msg_->contents[54]; + EXPECT_EQ(last_msg_->contents[55], 88) + << "incorrect value for contents[55], expected 88, is " + << last_msg_->contents[55]; + EXPECT_EQ(last_msg_->contents[56], 217) + << "incorrect value for contents[56], expected 217, is " + << last_msg_->contents[56]; + EXPECT_EQ(last_msg_->contents[57], 36) + << "incorrect value for contents[57], expected 36, is " + << last_msg_->contents[57]; + EXPECT_EQ(last_msg_->contents[58], 84) + << "incorrect value for contents[58], expected 84, is " + << last_msg_->contents[58]; + EXPECT_EQ(last_msg_->contents[59], 34) + << "incorrect value for contents[59], expected 34, is " + << last_msg_->contents[59]; + EXPECT_EQ(last_msg_->contents[60], 234) + << "incorrect value for contents[60], expected 234, is " + << last_msg_->contents[60]; + EXPECT_EQ(last_msg_->contents[61], 82) + << "incorrect value for contents[61], expected 82, is " + << last_msg_->contents[61]; + EXPECT_EQ(last_msg_->contents[62], 144) + << "incorrect value for contents[62], expected 144, is " + << last_msg_->contents[62]; + EXPECT_EQ(last_msg_->contents[63], 144) + << "incorrect value for contents[63], expected 144, is " + << last_msg_->contents[63]; + EXPECT_EQ(last_msg_->contents[64], 97) + << "incorrect value for contents[64], expected 97, is " + << last_msg_->contents[64]; + EXPECT_EQ(last_msg_->contents[65], 96) + << "incorrect value for contents[65], expected 96, is " + << last_msg_->contents[65]; + EXPECT_EQ(last_msg_->contents[66], 75) + << "incorrect value for contents[66], expected 75, is " + << last_msg_->contents[66]; + EXPECT_EQ(last_msg_->contents[67], 174) + << "incorrect value for contents[67], expected 174, is " + << last_msg_->contents[67]; + EXPECT_EQ(last_msg_->contents[68], 58) + << "incorrect value for contents[68], expected 58, is " + << last_msg_->contents[68]; + EXPECT_EQ(last_msg_->contents[69], 219) + << "incorrect value for contents[69], expected 219, is " + << last_msg_->contents[69]; + EXPECT_EQ(last_msg_->contents[70], 180) + << "incorrect value for contents[70], expected 180, is " + << last_msg_->contents[70]; + EXPECT_EQ(last_msg_->contents[71], 148) + << "incorrect value for contents[71], expected 148, is " + << last_msg_->contents[71]; + EXPECT_EQ(last_msg_->contents[72], 247) + << "incorrect value for contents[72], expected 247, is " + << last_msg_->contents[72]; + EXPECT_EQ(last_msg_->contents[73], 59) + << "incorrect value for contents[73], expected 59, is " + << last_msg_->contents[73]; + EXPECT_EQ(last_msg_->contents[74], 2) + << "incorrect value for contents[74], expected 2, is " + << last_msg_->contents[74]; + EXPECT_EQ(last_msg_->contents[75], 116) + << "incorrect value for contents[75], expected 116, is " + << last_msg_->contents[75]; + EXPECT_EQ(last_msg_->contents[76], 214) + << "incorrect value for contents[76], expected 214, is " + << last_msg_->contents[76]; + EXPECT_EQ(last_msg_->contents[77], 114) + << "incorrect value for contents[77], expected 114, is " + << last_msg_->contents[77]; + EXPECT_EQ(last_msg_->contents[78], 55) + << "incorrect value for contents[78], expected 55, is " + << last_msg_->contents[78]; + EXPECT_EQ(last_msg_->contents[79], 134) + << "incorrect value for contents[79], expected 134, is " + << last_msg_->contents[79]; + EXPECT_EQ(last_msg_->contents[80], 54) + << "incorrect value for contents[80], expected 54, is " + << last_msg_->contents[80]; + EXPECT_EQ(last_msg_->contents[81], 119) + << "incorrect value for contents[81], expected 119, is " + << last_msg_->contents[81]; + EXPECT_EQ(last_msg_->contents[82], 108) + << "incorrect value for contents[82], expected 108, is " + << last_msg_->contents[82]; + EXPECT_EQ(last_msg_->contents[83], 128) + << "incorrect value for contents[83], expected 128, is " + << last_msg_->contents[83]; + EXPECT_EQ(last_msg_->contents[84], 73) + << "incorrect value for contents[84], expected 73, is " + << last_msg_->contents[84]; + EXPECT_EQ(last_msg_->contents[85], 181) + << "incorrect value for contents[85], expected 181, is " + << last_msg_->contents[85]; + EXPECT_EQ(last_msg_->contents[86], 20) + << "incorrect value for contents[86], expected 20, is " + << last_msg_->contents[86]; + EXPECT_EQ(last_msg_->contents[87], 233) + << "incorrect value for contents[87], expected 233, is " + << last_msg_->contents[87]; + EXPECT_EQ(last_msg_->contents[88], 23) + << "incorrect value for contents[88], expected 23, is " + << last_msg_->contents[88]; + EXPECT_EQ(last_msg_->contents[89], 23) + << "incorrect value for contents[89], expected 23, is " + << last_msg_->contents[89]; + EXPECT_EQ(last_msg_->contents[90], 73) + << "incorrect value for contents[90], expected 73, is " + << last_msg_->contents[90]; + EXPECT_EQ(last_msg_->contents[91], 119) + << "incorrect value for contents[91], expected 119, is " + << last_msg_->contents[91]; + EXPECT_EQ(last_msg_->contents[92], 136) + << "incorrect value for contents[92], expected 136, is " + << last_msg_->contents[92]; + EXPECT_EQ(last_msg_->contents[93], 231) + << "incorrect value for contents[93], expected 231, is " + << last_msg_->contents[93]; + EXPECT_EQ(last_msg_->contents[94], 189) + << "incorrect value for contents[94], expected 189, is " + << last_msg_->contents[94]; + EXPECT_EQ(last_msg_->contents[95], 26) + << "incorrect value for contents[95], expected 26, is " + << last_msg_->contents[95]; + EXPECT_EQ(last_msg_->contents[96], 174) + << "incorrect value for contents[96], expected 174, is " + << last_msg_->contents[96]; + EXPECT_EQ(last_msg_->contents[97], 128) + << "incorrect value for contents[97], expected 128, is " + << last_msg_->contents[97]; + EXPECT_EQ(last_msg_->contents[98], 93) + << "incorrect value for contents[98], expected 93, is " + << last_msg_->contents[98]; + EXPECT_EQ(last_msg_->contents[99], 30) + << "incorrect value for contents[99], expected 30, is " + << last_msg_->contents[99]; + EXPECT_EQ(last_msg_->contents[100], 76) + << "incorrect value for contents[100], expected 76, is " + << last_msg_->contents[100]; + EXPECT_EQ(last_msg_->contents[101], 45) + << "incorrect value for contents[101], expected 45, is " + << last_msg_->contents[101]; + EXPECT_EQ(last_msg_->contents[102], 109) + << "incorrect value for contents[102], expected 109, is " + << last_msg_->contents[102]; + EXPECT_EQ(last_msg_->contents[103], 134) + << "incorrect value for contents[103], expected 134, is " + << last_msg_->contents[103]; + EXPECT_EQ(last_msg_->contents[104], 81) + << "incorrect value for contents[104], expected 81, is " + << last_msg_->contents[104]; + EXPECT_EQ(last_msg_->contents[105], 0) + << "incorrect value for contents[105], expected 0, is " + << last_msg_->contents[105]; + EXPECT_EQ(last_msg_->contents[106], 116) + << "incorrect value for contents[106], expected 116, is " + << last_msg_->contents[106]; + EXPECT_EQ(last_msg_->contents[107], 158) + << "incorrect value for contents[107], expected 158, is " + << last_msg_->contents[107]; + EXPECT_EQ(last_msg_->contents[108], 127) + << "incorrect value for contents[108], expected 127, is " + << last_msg_->contents[108]; + EXPECT_EQ(last_msg_->contents[109], 40) + << "incorrect value for contents[109], expected 40, is " + << last_msg_->contents[109]; + EXPECT_EQ(last_msg_->contents[110], 133) + << "incorrect value for contents[110], expected 133, is " + << last_msg_->contents[110]; + EXPECT_EQ(last_msg_->contents[111], 208) + << "incorrect value for contents[111], expected 208, is " + << last_msg_->contents[111]; + EXPECT_EQ(last_msg_->contents[112], 134) + << "incorrect value for contents[112], expected 134, is " + << last_msg_->contents[112]; + EXPECT_EQ(last_msg_->contents[113], 127) + << "incorrect value for contents[113], expected 127, is " + << last_msg_->contents[113]; + EXPECT_EQ(last_msg_->contents[114], 140) + << "incorrect value for contents[114], expected 140, is " + << last_msg_->contents[114]; + EXPECT_EQ(last_msg_->contents[115], 232) + << "incorrect value for contents[115], expected 232, is " + << last_msg_->contents[115]; + EXPECT_EQ(last_msg_->contents[116], 183) + << "incorrect value for contents[116], expected 183, is " + << last_msg_->contents[116]; + EXPECT_EQ(last_msg_->contents[117], 184) + << "incorrect value for contents[117], expected 184, is " + << last_msg_->contents[117]; + EXPECT_EQ(last_msg_->contents[118], 108) + << "incorrect value for contents[118], expected 108, is " + << last_msg_->contents[118]; + EXPECT_EQ(last_msg_->contents[119], 6) + << "incorrect value for contents[119], expected 6, is " + << last_msg_->contents[119]; + EXPECT_EQ(last_msg_->contents[120], 228) + << "incorrect value for contents[120], expected 228, is " + << last_msg_->contents[120]; + EXPECT_EQ(last_msg_->contents[121], 54) + << "incorrect value for contents[121], expected 54, is " + << last_msg_->contents[121]; + EXPECT_EQ(last_msg_->contents[122], 238) + << "incorrect value for contents[122], expected 238, is " + << last_msg_->contents[122]; + EXPECT_EQ(last_msg_->contents[123], 59) + << "incorrect value for contents[123], expected 59, is " + << last_msg_->contents[123]; + EXPECT_EQ(last_msg_->contents[124], 220) + << "incorrect value for contents[124], expected 220, is " + << last_msg_->contents[124]; + EXPECT_EQ(last_msg_->contents[125], 30) + << "incorrect value for contents[125], expected 30, is " + << last_msg_->contents[125]; + EXPECT_EQ(last_msg_->contents[126], 228) + << "incorrect value for contents[126], expected 228, is " + << last_msg_->contents[126]; + EXPECT_EQ(last_msg_->contents[127], 212) + << "incorrect value for contents[127], expected 212, is " + << last_msg_->contents[127]; + EXPECT_EQ(last_msg_->contents[128], 50) + << "incorrect value for contents[128], expected 50, is " + << last_msg_->contents[128]; + EXPECT_EQ(last_msg_->contents[129], 182) + << "incorrect value for contents[129], expected 182, is " + << last_msg_->contents[129]; + EXPECT_EQ(last_msg_->contents[130], 97) + << "incorrect value for contents[130], expected 97, is " + << last_msg_->contents[130]; + EXPECT_EQ(last_msg_->contents[131], 20) + << "incorrect value for contents[131], expected 20, is " + << last_msg_->contents[131]; + EXPECT_EQ(last_msg_->contents[132], 41) + << "incorrect value for contents[132], expected 41, is " + << last_msg_->contents[132]; + EXPECT_EQ(last_msg_->contents[133], 76) + << "incorrect value for contents[133], expected 76, is " + << last_msg_->contents[133]; + EXPECT_EQ(last_msg_->contents[134], 227) + << "incorrect value for contents[134], expected 227, is " + << last_msg_->contents[134]; + EXPECT_EQ(last_msg_->contents[135], 88) + << "incorrect value for contents[135], expected 88, is " + << last_msg_->contents[135]; + EXPECT_EQ(last_msg_->contents[136], 12) + << "incorrect value for contents[136], expected 12, is " + << last_msg_->contents[136]; + EXPECT_EQ(last_msg_->contents[137], 95) + << "incorrect value for contents[137], expected 95, is " + << last_msg_->contents[137]; + EXPECT_EQ(last_msg_->contents[138], 112) + << "incorrect value for contents[138], expected 112, is " + << last_msg_->contents[138]; + EXPECT_EQ(last_msg_->contents[139], 209) + << "incorrect value for contents[139], expected 209, is " + << last_msg_->contents[139]; + EXPECT_EQ(last_msg_->contents[140], 183) + << "incorrect value for contents[140], expected 183, is " + << last_msg_->contents[140]; + EXPECT_EQ(last_msg_->contents[141], 127) + << "incorrect value for contents[141], expected 127, is " + << last_msg_->contents[141]; + EXPECT_EQ(last_msg_->contents[142], 4) + << "incorrect value for contents[142], expected 4, is " + << last_msg_->contents[142]; + EXPECT_EQ(last_msg_->contents[143], 165) + << "incorrect value for contents[143], expected 165, is " + << last_msg_->contents[143]; + EXPECT_EQ(last_msg_->contents[144], 189) + << "incorrect value for contents[144], expected 189, is " + << last_msg_->contents[144]; + EXPECT_EQ(last_msg_->contents[145], 44) + << "incorrect value for contents[145], expected 44, is " + << last_msg_->contents[145]; + EXPECT_EQ(last_msg_->contents[146], 239) + << "incorrect value for contents[146], expected 239, is " + << last_msg_->contents[146]; + EXPECT_EQ(last_msg_->contents[147], 232) + << "incorrect value for contents[147], expected 232, is " + << last_msg_->contents[147]; + EXPECT_EQ(last_msg_->contents[148], 132) + << "incorrect value for contents[148], expected 132, is " + << last_msg_->contents[148]; + EXPECT_EQ(last_msg_->contents[149], 9) + << "incorrect value for contents[149], expected 9, is " + << last_msg_->contents[149]; + EXPECT_EQ(last_msg_->contents[150], 114) + << "incorrect value for contents[150], expected 114, is " + << last_msg_->contents[150]; + EXPECT_EQ(last_msg_->contents[151], 184) + << "incorrect value for contents[151], expected 184, is " + << last_msg_->contents[151]; + EXPECT_EQ(last_msg_->contents[152], 249) + << "incorrect value for contents[152], expected 249, is " + << last_msg_->contents[152]; + EXPECT_EQ(last_msg_->contents[153], 208) + << "incorrect value for contents[153], expected 208, is " + << last_msg_->contents[153]; + EXPECT_EQ(last_msg_->contents[154], 246) + << "incorrect value for contents[154], expected 246, is " + << last_msg_->contents[154]; + EXPECT_EQ(last_msg_->contents[155], 194) + << "incorrect value for contents[155], expected 194, is " + << last_msg_->contents[155]; + EXPECT_EQ(last_msg_->contents[156], 250) + << "incorrect value for contents[156], expected 250, is " + << last_msg_->contents[156]; + EXPECT_EQ(last_msg_->contents[157], 2) + << "incorrect value for contents[157], expected 2, is " + << last_msg_->contents[157]; + EXPECT_EQ(last_msg_->contents[158], 97) + << "incorrect value for contents[158], expected 97, is " + << last_msg_->contents[158]; + EXPECT_EQ(last_msg_->contents[159], 173) + << "incorrect value for contents[159], expected 173, is " + << last_msg_->contents[159]; + EXPECT_EQ(last_msg_->contents[160], 157) + << "incorrect value for contents[160], expected 157, is " + << last_msg_->contents[160]; + EXPECT_EQ(last_msg_->contents[161], 202) + << "incorrect value for contents[161], expected 202, is " + << last_msg_->contents[161]; + EXPECT_EQ(last_msg_->contents[162], 172) + << "incorrect value for contents[162], expected 172, is " + << last_msg_->contents[162]; + EXPECT_EQ(last_msg_->contents[163], 180) + << "incorrect value for contents[163], expected 180, is " + << last_msg_->contents[163]; + EXPECT_EQ(last_msg_->contents[164], 150) + << "incorrect value for contents[164], expected 150, is " + << last_msg_->contents[164]; + EXPECT_EQ(last_msg_->contents[165], 213) + << "incorrect value for contents[165], expected 213, is " + << last_msg_->contents[165]; + EXPECT_EQ(last_msg_->contents[166], 193) + << "incorrect value for contents[166], expected 193, is " + << last_msg_->contents[166]; + EXPECT_EQ(last_msg_->contents[167], 177) + << "incorrect value for contents[167], expected 177, is " + << last_msg_->contents[167]; + EXPECT_EQ(last_msg_->contents[168], 209) + << "incorrect value for contents[168], expected 209, is " + << last_msg_->contents[168]; + EXPECT_EQ(last_msg_->contents[169], 156) + << "incorrect value for contents[169], expected 156, is " + << last_msg_->contents[169]; + EXPECT_EQ(last_msg_->contents[170], 20) + << "incorrect value for contents[170], expected 20, is " + << last_msg_->contents[170]; + EXPECT_EQ(last_msg_->contents[171], 174) + << "incorrect value for contents[171], expected 174, is " + << last_msg_->contents[171]; + EXPECT_EQ(last_msg_->contents[172], 18) + << "incorrect value for contents[172], expected 18, is " + << last_msg_->contents[172]; + EXPECT_EQ(last_msg_->contents[173], 73) + << "incorrect value for contents[173], expected 73, is " + << last_msg_->contents[173]; + EXPECT_EQ(last_msg_->contents[174], 132) + << "incorrect value for contents[174], expected 132, is " + << last_msg_->contents[174]; + EXPECT_EQ(last_msg_->contents[175], 215) + << "incorrect value for contents[175], expected 215, is " + << last_msg_->contents[175]; + EXPECT_EQ(last_msg_->contents[176], 115) + << "incorrect value for contents[176], expected 115, is " + << last_msg_->contents[176]; + EXPECT_EQ(last_msg_->contents[177], 128) + << "incorrect value for contents[177], expected 128, is " + << last_msg_->contents[177]; + EXPECT_EQ(last_msg_->contents[178], 175) + << "incorrect value for contents[178], expected 175, is " + << last_msg_->contents[178]; + EXPECT_EQ(last_msg_->contents[179], 169) + << "incorrect value for contents[179], expected 169, is " + << last_msg_->contents[179]; + EXPECT_EQ(last_msg_->contents[180], 116) + << "incorrect value for contents[180], expected 116, is " + << last_msg_->contents[180]; + EXPECT_EQ(last_msg_->contents[181], 132) + << "incorrect value for contents[181], expected 132, is " + << last_msg_->contents[181]; + EXPECT_EQ(last_msg_->contents[182], 100) + << "incorrect value for contents[182], expected 100, is " + << last_msg_->contents[182]; + EXPECT_EQ(last_msg_->contents[183], 72) + << "incorrect value for contents[183], expected 72, is " + << last_msg_->contents[183]; + EXPECT_EQ(last_msg_->contents[184], 45) + << "incorrect value for contents[184], expected 45, is " + << last_msg_->contents[184]; + EXPECT_EQ(last_msg_->contents[185], 25) + << "incorrect value for contents[185], expected 25, is " + << last_msg_->contents[185]; + EXPECT_EQ(last_msg_->contents[186], 14) + << "incorrect value for contents[186], expected 14, is " + << last_msg_->contents[186]; + EXPECT_EQ(last_msg_->contents[187], 205) + << "incorrect value for contents[187], expected 205, is " + << last_msg_->contents[187]; + EXPECT_EQ(last_msg_->contents[188], 213) + << "incorrect value for contents[188], expected 213, is " + << last_msg_->contents[188]; + EXPECT_EQ(last_msg_->contents[189], 145) + << "incorrect value for contents[189], expected 145, is " + << last_msg_->contents[189]; + EXPECT_EQ(last_msg_->contents[190], 68) + << "incorrect value for contents[190], expected 68, is " + << last_msg_->contents[190]; + EXPECT_EQ(last_msg_->contents[191], 137) + << "incorrect value for contents[191], expected 137, is " + << last_msg_->contents[191]; + EXPECT_EQ(last_msg_->contents[192], 249) + << "incorrect value for contents[192], expected 249, is " + << last_msg_->contents[192]; + EXPECT_EQ(last_msg_->contents[193], 54) + << "incorrect value for contents[193], expected 54, is " + << last_msg_->contents[193]; + EXPECT_EQ(last_msg_->contents[194], 40) + << "incorrect value for contents[194], expected 40, is " + << last_msg_->contents[194]; + EXPECT_EQ(last_msg_->contents[195], 174) + << "incorrect value for contents[195], expected 174, is " + << last_msg_->contents[195]; + EXPECT_EQ(last_msg_->contents[196], 215) + << "incorrect value for contents[196], expected 215, is " + << last_msg_->contents[196]; + EXPECT_EQ(last_msg_->contents[197], 148) + << "incorrect value for contents[197], expected 148, is " + << last_msg_->contents[197]; + EXPECT_EQ(last_msg_->contents[198], 166) + << "incorrect value for contents[198], expected 166, is " + << last_msg_->contents[198]; + EXPECT_EQ(last_msg_->contents[199], 190) + << "incorrect value for contents[199], expected 190, is " + << last_msg_->contents[199]; + EXPECT_EQ(last_msg_->contents[200], 63) + << "incorrect value for contents[200], expected 63, is " + << last_msg_->contents[200]; + EXPECT_EQ(last_msg_->contents[201], 118) + << "incorrect value for contents[201], expected 118, is " + << last_msg_->contents[201]; + EXPECT_EQ(last_msg_->contents[202], 6) + << "incorrect value for contents[202], expected 6, is " + << last_msg_->contents[202]; + EXPECT_EQ(last_msg_->contents[203], 165) + << "incorrect value for contents[203], expected 165, is " + << last_msg_->contents[203]; + EXPECT_EQ(last_msg_->contents[204], 212) + << "incorrect value for contents[204], expected 212, is " + << last_msg_->contents[204]; + EXPECT_EQ(last_msg_->contents[205], 74) + << "incorrect value for contents[205], expected 74, is " + << last_msg_->contents[205]; + EXPECT_EQ(last_msg_->contents[206], 68) + << "incorrect value for contents[206], expected 68, is " + << last_msg_->contents[206]; + EXPECT_EQ(last_msg_->contents[207], 200) + << "incorrect value for contents[207], expected 200, is " + << last_msg_->contents[207]; + EXPECT_EQ(last_msg_->contents[208], 38) + << "incorrect value for contents[208], expected 38, is " + << last_msg_->contents[208]; + EXPECT_EQ(last_msg_->contents[209], 139) + << "incorrect value for contents[209], expected 139, is " + << last_msg_->contents[209]; + EXPECT_EQ(last_msg_->contents[210], 212) + << "incorrect value for contents[210], expected 212, is " + << last_msg_->contents[210]; + EXPECT_EQ(last_msg_->contents[211], 112) + << "incorrect value for contents[211], expected 112, is " + << last_msg_->contents[211]; + EXPECT_EQ(last_msg_->contents[212], 45) + << "incorrect value for contents[212], expected 45, is " + << last_msg_->contents[212]; + EXPECT_EQ(last_msg_->contents[213], 167) + << "incorrect value for contents[213], expected 167, is " + << last_msg_->contents[213]; + EXPECT_EQ(last_msg_->contents[214], 236) + << "incorrect value for contents[214], expected 236, is " + << last_msg_->contents[214]; + EXPECT_EQ(last_msg_->contents[215], 255) + << "incorrect value for contents[215], expected 255, is " + << last_msg_->contents[215]; + EXPECT_EQ(last_msg_->contents[216], 106) + << "incorrect value for contents[216], expected 106, is " + << last_msg_->contents[216]; + EXPECT_EQ(last_msg_->contents[217], 92) + << "incorrect value for contents[217], expected 92, is " + << last_msg_->contents[217]; + EXPECT_EQ(last_msg_->contents[218], 132) + << "incorrect value for contents[218], expected 132, is " + << last_msg_->contents[218]; + EXPECT_EQ(last_msg_->contents[219], 59) + << "incorrect value for contents[219], expected 59, is " + << last_msg_->contents[219]; + EXPECT_EQ(last_msg_->contents[220], 61) + << "incorrect value for contents[220], expected 61, is " + << last_msg_->contents[220]; + EXPECT_EQ(last_msg_->contents[221], 233) + << "incorrect value for contents[221], expected 233, is " + << last_msg_->contents[221]; + EXPECT_EQ(last_msg_->contents[222], 3) + << "incorrect value for contents[222], expected 3, is " + << last_msg_->contents[222]; + EXPECT_EQ(last_msg_->contents[223], 246) + << "incorrect value for contents[223], expected 246, is " + << last_msg_->contents[223]; + EXPECT_EQ(last_msg_->contents[224], 158) + << "incorrect value for contents[224], expected 158, is " + << last_msg_->contents[224]; + EXPECT_EQ(last_msg_->contents[225], 83) + << "incorrect value for contents[225], expected 83, is " + << last_msg_->contents[225]; + EXPECT_EQ(last_msg_->contents[226], 134) + << "incorrect value for contents[226], expected 134, is " + << last_msg_->contents[226]; + EXPECT_EQ(last_msg_->contents[227], 246) + << "incorrect value for contents[227], expected 246, is " + << last_msg_->contents[227]; + EXPECT_EQ(last_msg_->contents[228], 154) + << "incorrect value for contents[228], expected 154, is " + << last_msg_->contents[228]; + EXPECT_EQ(last_msg_->contents[229], 17) + << "incorrect value for contents[229], expected 17, is " + << last_msg_->contents[229]; + EXPECT_EQ(last_msg_->contents[230], 0) + << "incorrect value for contents[230], expected 0, is " + << last_msg_->contents[230]; + EXPECT_EQ(last_msg_->contents[231], 6) + << "incorrect value for contents[231], expected 6, is " + << last_msg_->contents[231]; + EXPECT_EQ(last_msg_->contents[232], 56) + << "incorrect value for contents[232], expected 56, is " + << last_msg_->contents[232]; + EXPECT_EQ(last_msg_->contents[233], 216) + << "incorrect value for contents[233], expected 216, is " + << last_msg_->contents[233]; + EXPECT_EQ(last_msg_->contents[234], 19) + << "incorrect value for contents[234], expected 19, is " + << last_msg_->contents[234]; + EXPECT_EQ(last_msg_->contents[235], 216) + << "incorrect value for contents[235], expected 216, is " + << last_msg_->contents[235]; + EXPECT_EQ(last_msg_->contents[236], 70) + << "incorrect value for contents[236], expected 70, is " + << last_msg_->contents[236]; + EXPECT_EQ(last_msg_->contents[237], 71) + << "incorrect value for contents[237], expected 71, is " + << last_msg_->contents[237]; + EXPECT_EQ(last_msg_->contents[238], 161) + << "incorrect value for contents[238], expected 161, is " + << last_msg_->contents[238]; + EXPECT_EQ(last_msg_->contents[239], 184) + << "incorrect value for contents[239], expected 184, is " + << last_msg_->contents[239]; + EXPECT_EQ(last_msg_->contents[240], 5) + << "incorrect value for contents[240], expected 5, is " + << last_msg_->contents[240]; + EXPECT_EQ(last_msg_->contents[241], 177) + << "incorrect value for contents[241], expected 177, is " + << last_msg_->contents[241]; + EXPECT_EQ(last_msg_->contents[242], 45) + << "incorrect value for contents[242], expected 45, is " + << last_msg_->contents[242]; + EXPECT_EQ(last_msg_->contents[243], 37) + << "incorrect value for contents[243], expected 37, is " + << last_msg_->contents[243]; + EXPECT_EQ(last_msg_->contents[244], 98) + << "incorrect value for contents[244], expected 98, is " + << last_msg_->contents[244]; + EXPECT_EQ(last_msg_->contents[245], 56) + << "incorrect value for contents[245], expected 56, is " + << last_msg_->contents[245]; + EXPECT_EQ(last_msg_->contents[246], 149) + << "incorrect value for contents[246], expected 149, is " + << last_msg_->contents[246]; + EXPECT_EQ(last_msg_->contents[247], 0) + << "incorrect value for contents[247], expected 0, is " + << last_msg_->contents[247]; + EXPECT_EQ(last_msg_->contents[248], 73) + << "incorrect value for contents[248], expected 73, is " + << last_msg_->contents[248]; + EXPECT_EQ(last_msg_->contents[249], 221) + << "incorrect value for contents[249], expected 221, is " + << last_msg_->contents[249]; + EXPECT_EQ(last_msg_->contents[250], 105) + << "incorrect value for contents[250], expected 105, is " + << last_msg_->contents[250]; + EXPECT_EQ(last_msg_->contents[251], 239) + << "incorrect value for contents[251], expected 239, is " + << last_msg_->contents[251]; + EXPECT_EQ(last_msg_->contents[252], 168) + << "incorrect value for contents[252], expected 168, is " + << last_msg_->contents[252]; + EXPECT_EQ(last_msg_->contents[253], 205) + << "incorrect value for contents[253], expected 205, is " + << last_msg_->contents[253]; + EXPECT_EQ(last_msg_->contents[254], 85) + << "incorrect value for contents[254], expected 85, is " + << last_msg_->contents[254]; +} diff --git a/c/test/legacy/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc b/c/test/legacy/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc new file mode 100644 index 0000000000..986af36590 --- /dev/null +++ b/c/test/legacy/cpp/auto_check_sbp_vehicle_MsgWheeltick.cc @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015-2021 Swift Navigation Inc. + * Contact: https://support.swiftnav.com + * + * This source is subject to the license found in the file 'LICENSE' which must + * be be distributed together with this source. All other rights reserved. + * + * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, + * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + */ + +// This file was auto-generated from +// spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml by generate.py. +// Do not modify by hand! + +#include +#include +#include +#include +class Test_legacy_auto_check_sbp_vehicle_MsgWheeltick0 + : public ::testing::Test, + public sbp::State, + public sbp::IReader, + public sbp::IWriter, + sbp::PayloadHandler { + public: + Test_legacy_auto_check_sbp_vehicle_MsgWheeltick0() + : ::testing::Test(), + sbp::State(), + sbp::IReader(), + sbp::IWriter(), + sbp::PayloadHandler(this), + last_msg_storage_(), + last_msg_(reinterpret_cast(last_msg_storage_)), + last_msg_len_(), + last_sender_id_(), + n_callbacks_logged_(), + dummy_wr_(), + dummy_rd_(), + dummy_buff_() { + set_reader(this); + set_writer(this); + } + + s32 read(uint8_t *buf, const uint32_t n) override { + uint32_t real_n = n; + memcpy(buf, dummy_buff_ + dummy_rd_, real_n); + dummy_rd_ += real_n; + return (s32)real_n; + } + + s32 write(const uint8_t *buf, uint32_t n) override { + uint32_t real_n = n; + memcpy(dummy_buff_ + dummy_wr_, buf, real_n); + dummy_wr_ += real_n; + return (s32)real_n; + } + + protected: + void handle_sbp_msg(uint16_t sender_id, uint8_t message_length, + const msg_wheeltick_t &msg) override { + memcpy(last_msg_storage_, &msg, message_length); + last_msg_len_ = message_length; + last_sender_id_ = sender_id; + n_callbacks_logged_++; + } + + uint8_t last_msg_storage_[SBP_MAX_PAYLOAD_LEN]; + msg_wheeltick_t *last_msg_; + uint8_t last_msg_len_; + uint16_t last_sender_id_; + size_t n_callbacks_logged_; + uint32_t dummy_wr_; + uint32_t dummy_rd_; + uint8_t dummy_buff_[1024]; +}; + +TEST_F(Test_legacy_auto_check_sbp_vehicle_MsgWheeltick0, Test) { + uint8_t encoded_frame[] = { + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, + 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + }; + + uint8_t test_msg_storage[SBP_MAX_PAYLOAD_LEN]{}; + uint8_t test_msg_len = 0; + msg_wheeltick_t *test_msg = (msg_wheeltick_t *)test_msg_storage; + test_msg_len = (uint8_t)sizeof(*test_msg); + test_msg->flags = 1; + test_msg->source = 146; + test_msg->ticks = -771148831; + test_msg->time = 112414825470; + + EXPECT_EQ(send_message(0x904, 17771, test_msg_len, test_msg_storage), SBP_OK); + + EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); + EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); + + while (dummy_rd_ < dummy_wr_) { + process(); + } + + EXPECT_EQ(n_callbacks_logged_, 1); + EXPECT_EQ(last_sender_id_, 17771); + EXPECT_EQ(last_msg_len_, test_msg_len); + EXPECT_EQ(last_msg_->flags, 1) + << "incorrect value for flags, expected 1, is " << last_msg_->flags; + EXPECT_EQ(last_msg_->source, 146) + << "incorrect value for source, expected 146, is " << last_msg_->source; + EXPECT_EQ(last_msg_->ticks, -771148831) + << "incorrect value for ticks, expected -771148831, is " + << last_msg_->ticks; + EXPECT_EQ(last_msg_->time, 112414825470) + << "incorrect value for time, expected 112414825470, is " + << last_msg_->time; +} diff --git a/c/third_party/googletest b/c/third_party/googletest index 703bd9caab..b796f7d446 160000 --- a/c/third_party/googletest +++ b/c/third_party/googletest @@ -1 +1 @@ -Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e +Subproject commit b796f7d44681514f58a683a3a71ff17c94edb0c1 diff --git a/generator/sbpg/specs/yaml2.py b/generator/sbpg/specs/yaml2.py index 60e4a8e29d..842bfe5379 100755 --- a/generator/sbpg/specs/yaml2.py +++ b/generator/sbpg/specs/yaml2.py @@ -191,6 +191,8 @@ def mk_package_test_suite(fname, contents, spec_no): generated_on = contents.get('generated_on', None) tests = contents.get('tests', []) resolved = [mk_test(test) for test in tests] + test_structs = contents.get('struct_tests', []) + resolved_structs = [mk_test_struct(test) for test in test_structs] # Get current directory, root directory, and then strip root directory from test suite filename curr_file_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) @@ -202,7 +204,8 @@ def mk_package_test_suite(fname, contents, spec_no): suite_no=spec_no, description=description, generated_on=generated_on, - tests=resolved) + tests=resolved, + test_structs=resolved_structs) def mk_test(test): """Instantiates a test for a particular SBP message. @@ -215,6 +218,13 @@ def mk_test(test): msg=test.get('msg', None), sbp=test.get('sbp', None)) +def mk_test_struct(spec): + """Instantiates a test for a particular SBP struct. + + """ + assert len(spec) == 4 + return sbp_test.TestStructSpecification(spec) + def mk_package(contents): """Instantiates a package specification from a parsed "AST" of a package. diff --git a/generator/sbpg/specs/yaml_test_schema.py b/generator/sbpg/specs/yaml_test_schema.py index f6145b73a9..10c63bfeff 100644 --- a/generator/sbpg/specs/yaml_test_schema.py +++ b/generator/sbpg/specs/yaml_test_schema.py @@ -29,12 +29,22 @@ 'sbp': Schema({ Coerce(str): Coerce(str) }), }) +struct_test = Schema({ + 'encoded': Coerce(str), + 'fields': Any(Schema({ Coerce(str): Coerce(str) }), IsFalse), + 'c_decoded_fields': Any(Schema({ Coerce(str): Coerce(str) }), IsFalse), + 'module': Coerce(str), + 'name': Coerce(str) +}) + tests = Schema([test]) +struct_tests = Schema([struct_test]) test_schema = Schema({ 'package': Schema(str), 'description': Schema(str), 'version': Coerce(str), 'generated_on': Coerce(str), - 'tests': tests + 'tests': tests, + 'struct_tests': struct_tests }) diff --git a/generator/sbpg/targets/resources/c/test/sbp_c_main.c.j2 b/generator/sbpg/targets/resources/c/test/sbp_c_main.c.j2 index 5122a9de26..59cb4af1f0 100644 --- a/generator/sbpg/targets/resources/c/test/sbp_c_main.c.j2 +++ b/generator/sbpg/targets/resources/c/test/sbp_c_main.c.j2 @@ -32,11 +32,13 @@ int main(void) // auto-generated tests: ((*- for s in package_suites *)) + ((*- if s.tests|length > 0 *)) ((*- if test_type == 'legacy' *)) srunner_add_suite(sr, legacy_(((s.suite_name)))_suite()); ((*- else *)) srunner_add_suite(sr, (((s.suite_name)))_suite()); ((*- endif *)) + ((*- endif *)) ((*- endfor *)) srunner_set_fork_status(sr, CK_NOFORK); diff --git a/generator/sbpg/targets/resources/c/test/sbp_c_suites.h.j2 b/generator/sbpg/targets/resources/c/test/sbp_c_suites.h.j2 index 327e03f521..65afcf1aeb 100644 --- a/generator/sbpg/targets/resources/c/test/sbp_c_suites.h.j2 +++ b/generator/sbpg/targets/resources/c/test/sbp_c_suites.h.j2 @@ -20,11 +20,13 @@ Suite* sbp_suite(void); Suite* bitfield_macros_suite(void); ((*- for s in package_suites *)) +((*- if s.tests|length > 0 *)) ((*- if test_type == 'legacy' *)) Suite* legacy_(((s.suite_name)))_suite(void); ((*- else *)) Suite* (((s.suite_name)))_suite(void); ((*- endif *)) +((*- endif *)) ((*- endfor *)) #endif /* CHECK_SUITES_H */ diff --git a/generator/sbpg/targets/resources/c/test/v4/sbp_c_test.c.j2 b/generator/sbpg/targets/resources/c/test/v4/sbp_c_test.c.j2 index 7098809e06..e5d5a2ed94 100644 --- a/generator/sbpg/targets/resources/c/test/v4/sbp_c_test.c.j2 +++ b/generator/sbpg/targets/resources/c/test/v4/sbp_c_test.c.j2 @@ -106,6 +106,8 @@ START_TEST( test_(((s.suite_name))) ) ((*- elif value is dict_type *)) ((*- if value.handle_as and value.handle_as == "encoded-string" *)) (((compare_string(root_path, value)))) + ((*- elif value.handle_as and value.handle_as == "vararray-len" *)) + ck_assert_msg( (((-path))) == (((value.value))), "incorrect value for (((path))), expected (((value.value))), is %d", (((path)))); ((*- else *)) ((*- for k in value|sorted *)) (((compare_value(root_path, path + '.' + k, value[k])))) @@ -146,6 +148,8 @@ START_TEST( test_(((s.suite_name))) ) ((*- elif value is dict_type *)) ((*- if value.handle_as and value.handle_as == "encoded-string" *)) (((assign_string(root_path, value)))) + ((*- elif value.handle_as and value.handle_as == "vararray-len" *)) + (((path))) = (((value.value))); ((*- else *)) ((*- for k in (((value|sorted))) *)) (((assign_value(root_path, path + '.' + k, value[k])))) diff --git a/generator/sbpg/targets/resources/c/test/v4/sbp_cpp_test.cc.j2 b/generator/sbpg/targets/resources/c/test/v4/sbp_cpp_test.cc.j2 index 8410dd27a4..a7b3320278 100644 --- a/generator/sbpg/targets/resources/c/test/v4/sbp_cpp_test.cc.j2 +++ b/generator/sbpg/targets/resources/c/test/v4/sbp_cpp_test.cc.j2 @@ -12,166 +12,1150 @@ // This file was auto-generated from (((s.src_filename))) by generate.py. Do not modify by hand! -#include +#include #include -#include -#include #include +#include +#include -((*- for t in s.tests *)) -((*- set msg_type = t.msg_type_name|convert_unpacked *)) -class Test_(((s.suite_name)))(((loop.index0))) : - public ::testing::Test, - public sbp::State, - public sbp::IReader, - public sbp::IWriter, - sbp::MessageHandler<(((msg_type)))> +((*- macro assign_string(root_path, value) *)) +((*- if value.sections *)) +((*- for s in value.sections *)) +EXPECT_TRUE( (((- value.fn_prefix)))_add_section(&(((root_path))), "(((value.sections[loop.index0])))")); +((*- endfor *)) +((*- else *)) +size_t written; +EXPECT_TRUE( (((- value.fn_prefix)))_set(&(((root_path))), "(((value.text)))", false, &written)); +EXPECT_EQ(written, strlen("(((value.text)))")); +((*- endif *)) +EXPECT_EQ( (((- value.fn_prefix)))_encoded_len(&(((root_path)))), (((value.encoded_len)))); +((*- endmacro *)) + + + +((*- macro assign_value(root_path, path, value) *)) +((*- if value is string_type *)) { + const char assign_string[] = { (((value|str_escape))) }; + memcpy( (((-path))), assign_string, sizeof(assign_string)); +} +((*- elif value is array_type *)) +((*- for ff in value *)) +((( assign_value(root_path, path ~ '[' ~ loop.index0 ~ ']', ff) ))) +((*- endfor *)) +((*- elif value is dict_type *)) +((*- if value.handle_as and value.handle_as == "encoded-string" *)) +((( assign_string(root_path, value) ))) +((*- elif value.handle_as and value.handle_as == "vararray-len" *)) +assign( (((path))) , (((value.value)))); +((*- else *)) +((*- for k in value|sorted *))((( assign_value(root_path, path + "." + k, value[k]) )))((*- endfor *)) +((*- endif *)) +((*- else *)) +assign( (((path))) , (((value)))); +((*- endif *)) +((*- endmacro *)) + +namespace { + +template +void assign(T &dest, const U &source) { + dest = static_cast(source); +} + +((*- for t in s.tests *)) +((*- set fixture_name = "Test" ~ s.suite_name ~ loop.index0 *)) +class ((( fixture_name ))) : public ::testing::Test { public: - Test_(((s.suite_name)))(((loop.index0)))() : - ::testing::Test(), - sbp::State(), - sbp::IReader(), - sbp::IWriter(), - sbp::MessageHandler<(((msg_type)))>(this), - last_msg_(), - last_msg_len_(), - last_sender_id_(), - n_callbacks_logged_(), - dummy_wr_(), - dummy_rd_(), - dummy_buff_() - { - set_reader(this); - set_writer(this); + ((( fixture_name ))) () { + ((*- if t.c_decoded_fields *)) + ((*- for f in t.c_decoded_fieldskeys *))(((assign_value("test_msg_", "test_msg_." + f, t.c_decoded_fields[f]))))((*- endfor *)) + ((*- endif *)) } - s32 read(uint8_t *buf, const uint32_t n) override - { - uint32_t real_n = n; - memcpy(buf, dummy_buff_ + dummy_rd_, real_n); - dummy_rd_ += real_n; - return (s32)real_n; + class SlowReader final : public sbp::IReader { + public: + SlowReader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + if (remaining() == 0) { + return -1; + } + skip_next_read = !skip_next_read; + if (skip_next_read) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + bool skip_next_read{}; + }; + + class Reader final : public sbp::IReader { + public: + Reader(const uint8_t *buf, uint32_t len) + : sbp::IReader(), buf_{buf}, len_{len} {} + + s32 read(uint8_t *buf, const uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf, buf_ + offset_, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return len_ - offset_; } + + static s32 read_static(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->read(buf, len); + } + + private: + const uint8_t *buf_; + uint32_t len_; + uint32_t offset_{}; + }; + + class SlowWriter final : public sbp::IWriter { + public: + explicit SlowWriter(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, 1u); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + class Writer final : public sbp::IWriter { + public: + explicit Writer(uint32_t max_len = cMaxLen) + : IWriter(), max_len_{max_len} {} + static constexpr uint32_t cMaxLen = SBP_MAX_FRAME_LEN; + + s32 write(const uint8_t *buf, uint32_t n) override { + if (n == 0) { + return 0; + } + uint32_t real_n = std::min(n, remaining()); + if (real_n == 0) { + return -1; + } + memcpy(buf_ + offset_, buf, real_n); + offset_ += real_n; + return static_cast(real_n); + } + + uint32_t remaining() const noexcept { return max_len_ - offset_; } + + const uint8_t *data() const noexcept { return buf_; } + + uint32_t len() const noexcept { return offset_; } + + static s32 write_static(const uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + static s32 write_c(uint8_t *buf, uint32_t len, void *ctx) { + return static_cast(ctx)->write(buf, len); + } + + private: + uint8_t buf_[cMaxLen]; + uint32_t max_len_; + uint32_t offset_{}; + }; + + struct CppHandler final : public sbp::MessageHandler<((( t.struct_name )))> { + using sbp::MessageHandler<((( t.struct_name )))>::MessageHandler; + + struct Output final { + uint16_t sender_id; + ((( t.struct_name ))) msg; + }; + + std::vector outputs{}; + + protected: + void handle_sbp_msg(uint16_t sender_id, + const ((( t.struct_name ))) &msg) override { + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg, sizeof(msg)); + } + }; + + struct CHandler final { + explicit CHandler(sbp_state_t *state) : state_{state} { + sbp_callback_register(state, ((( t.enum_value ))), &CHandler::callback_static, + this, &node_); + } + + ~CHandler() { sbp_remove_callback(state_, &node_); } + + struct Output final { + uint16_t sender_id; + ((( t.struct_name ))) msg; + }; + + std::vector outputs{}; + + private: + void callback(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg) { + ASSERT_EQ(msg_type, ((( t.enum_value )))); + outputs.emplace_back(); + outputs.back().sender_id = sender_id; + memcpy(&outputs.back().msg, &msg->(((t.name_in_sbp_msg_t))), sizeof(msg->(((t.name_in_sbp_msg_t))))); + } + + static void callback_static(uint16_t sender_id, sbp_msg_type_t msg_type, + const sbp_msg_t *msg, void *ctx) { + static_cast(ctx)->callback(sender_id, msg_type, msg); + } + + sbp_msg_callbacks_node_t node_{}; + sbp_state_t *state_; + }; + + struct TestMsgInfo { + ((( t.struct_name ))) test_msg; + sbp_msg_t test_msg_wrapped; + sbp_msg_type_t msg_type; + uint16_t sender_id; + uint8_t preamble; + uint16_t crc; + const uint8_t *encoded_frame; + uint32_t frame_len; + const uint8_t *encoded_payload; + uint8_t payload_len; + + Reader get_frame_reader() const noexcept { + return Reader{encoded_frame, frame_len}; + } + + Reader get_frame_reader(uint32_t max) const noexcept { + assert(max <= frame_len); + return Reader{encoded_frame, max}; + } + + SlowReader get_slow_frame_reader() const noexcept { + return SlowReader{encoded_frame, frame_len}; + } + + Writer get_frame_writer() const noexcept { return Writer{frame_len}; } + + Writer get_frame_writer(uint32_t max) const noexcept { return Writer{max}; } + + SlowWriter get_slow_frame_writer() const noexcept { + return SlowWriter{frame_len}; + } + }; + + TestMsgInfo get_test_msg_info() const noexcept { + TestMsgInfo info; + memcpy(&info.test_msg, &test_msg_, sizeof(test_msg_)); + memcpy(&info.test_msg_wrapped.(((t.name_in_sbp_msg_t))), &test_msg_, sizeof(test_msg_)); + info.msg_type = static_cast( (((t.enum_value))) ); + info.sender_id = (((t.raw_json_obj.sender))); + info.preamble = 0x55; + info.crc = (((t.sbp.crc))); + info.encoded_frame = encoded_frame_; + info.frame_len = sizeof(encoded_frame_); + info.encoded_payload = encoded_payload_; + info.payload_len = (((t.sbp.length))); + + return info; } - s32 write(const uint8_t *buf, uint32_t n) override - { - uint32_t real_n = n; - memcpy(dummy_buff_ + dummy_wr_, buf, real_n); - dummy_wr_ += real_n; - return (s32)real_n; +protected: +void comparison_tests(const (((t.struct_name))) &lesser, + const (((t.struct_name))) &greater) { + sbp_msg_t wrapped_lesser = + sbp::MessageTraits<(((t.struct_name)))>::to_sbp_msg(lesser); + sbp_msg_t wrapped_greater = + sbp::MessageTraits<(((t.struct_name)))>::to_sbp_msg(greater); + + EXPECT_EQ( (((t.fn_prefix)))_cmp(&lesser, &lesser), 0); + EXPECT_EQ( (((t.fn_prefix)))_cmp(&greater, &greater), 0); + EXPECT_LE( (((t.fn_prefix)))_cmp(&lesser, &greater), 0); + EXPECT_GT( (((t.fn_prefix)))_cmp(&greater, &lesser), 0); + + EXPECT_EQ(sbp_message_cmp( (((t.enum_value))), &wrapped_lesser, &wrapped_lesser), + 0); + EXPECT_EQ(sbp_message_cmp( (((t.enum_value))), &wrapped_greater, &wrapped_greater), + 0); + EXPECT_LE(sbp_message_cmp( (((t.enum_value))), &wrapped_lesser, &wrapped_greater), + 0); + EXPECT_GT(sbp_message_cmp( (((t.enum_value))), &wrapped_greater, &wrapped_lesser), + 0); + + // lesser vs lesser + EXPECT_TRUE(lesser == lesser); + EXPECT_FALSE(lesser != lesser); + EXPECT_FALSE(lesser < lesser); + EXPECT_TRUE(lesser <= lesser); + EXPECT_FALSE(lesser > lesser); + EXPECT_TRUE(lesser >= lesser); + + // greater vs greater + EXPECT_TRUE(greater == greater); + EXPECT_FALSE(greater != greater); + EXPECT_FALSE(greater < greater); + EXPECT_TRUE(greater <= greater); + EXPECT_FALSE(greater > greater); + EXPECT_TRUE(greater >= greater); + + // lesser vs greater + EXPECT_FALSE(lesser == greater); + EXPECT_TRUE(lesser != greater); + EXPECT_TRUE(lesser < greater); + EXPECT_TRUE(lesser <= greater); + EXPECT_FALSE(lesser > greater); + EXPECT_FALSE(lesser >= greater); + + // greater vs lesser + EXPECT_FALSE(greater == lesser); + EXPECT_TRUE(greater != lesser); + EXPECT_FALSE(greater < lesser); + EXPECT_FALSE(greater <= lesser); + EXPECT_TRUE(greater > lesser); + EXPECT_TRUE(greater >= lesser); +} + +template ::value, bool> = true> +void make_lesser_greater(T &lesser, T &greater) { + if (greater == std::numeric_limits::max()) { + lesser--; + } else { + greater++; } +} +template::value, bool> = true> +void make_lesser_greater(T &lesser, T &greater) { + (void)lesser; + greater += static_cast(1.0); +} -protected: +void make_lesser_greater(sbp_string_t &lesser, sbp_string_t &greater) { + if (greater.data[0] == 'z') { + lesser.data[0]--; + } else { + greater.data[0]++; + } +} - void handle_sbp_msg(uint16_t sender_id, const (((msg_type))) &msg) override - { - last_msg_ = msg; - last_sender_id_ = sender_id; - n_callbacks_logged_++; - } - - (((msg_type))) last_msg_; - uint8_t last_msg_len_; - uint16_t last_sender_id_; - size_t n_callbacks_logged_; - uint32_t dummy_wr_; - uint32_t dummy_rd_; - uint8_t dummy_buff_[1024]; -}; - -TEST_F(Test_(((s.suite_name)))(((loop.index0))), Test) -{ - ((*- macro compare_string(root_path, value) *)) - EXPECT_EQ( (((- value.fn_prefix)))_encoded_len(&(((root_path)))), (((value.encoded_len)))); - ((*- if value.sections *)) - ((*- for s in value.sections *)) - EXPECT_STREQ( (((- value.fn_prefix)))_get_section(&(((root_path))), (((loop.index0)))), "(((value.sections[loop.index0])))"); - ((*- endfor *)) - ((*- else *)) - EXPECT_STREQ( (((- value.fn_prefix)))_get(&(((root_path)))), "(((value.text)))"); - ((*- endif *)) - ((*- endmacro *)) - - ((*- macro compare_value(root_path, path, value) *)) - ((*- if value is string_type *)) - { - const char check_string[] = { (((value|str_escape))) }; - EXPECT_EQ(memcmp( (((-path))), check_string, sizeof(check_string)), 0) << "incorrect value for (((path))), expected string '" << check_string << "', is '" << (((path))) << "'"; - } - ((*- elif value is array_type *)) - ((*- for ff in value *))(((compare_value(root_path, path + '[' + loop.index0|to_str + ']', ff))))((*- endfor *)) - ((*- elif value is dict_type *)) - ((*- if value.handle_as and value.handle_as == "encoded-string" *)) - (((compare_string(root_path, value)))) - ((*- else *)) - ((*- for k in value|sorted *))(((compare_value(root_path, path + '.' + k, value[k]))))((*- endfor *)) - ((*- endif *)) - ((*- elif value is float_type *))((= - Note: the ("%.12g"|format(value)|float) filter is intended to keep float - literal precision unchanged whether generated under Python 2.7 or 3.x. =)) - EXPECT_LT(( (((-path))) * 100 - ((("%.12g"|format(value)|float))) * 100), 0.05) << "incorrect value for (((path))), expected ((("%.12g"|format(value)|float))), is " << (((path))); - ((*- else *)) - EXPECT_EQ( (((-path))), (((value)))) << "incorrect value for (((path))), expected (((value))), is " << (((path))); - ((*- endif *)) - ((*- endmacro *)) +template +void make_lesser_greater(char (&lesser)[N], char (&greater)[N]) { + if (lesser[0] == 'z') { + lesser[0]--; + } else { + greater[0]++; + } +} - ((*- macro assign_string(root_path, value) *)) - ((*- if value.sections *)) - ((*- for s in value.sections *)) - EXPECT_TRUE( (((- value.fn_prefix)))_add_section(&(((root_path))), "(((value.sections[loop.index0])))")); - ((*- endfor *)) - ((*- else *)) - size_t written; - EXPECT_TRUE( (((- value.fn_prefix)))_set(&(((root_path))), "(((value.text)))", false, &written)); - EXPECT_EQ( written, strlen("(((value.text)))")); +private: + ((( t.struct_name ))) test_msg_{}; + uint8_t encoded_frame_[(((t.sbp.length))) + 8] = { + ((*- for p in t.packet_as_byte_array *))(((p))),((*- endfor *)) +}; + uint8_t encoded_payload_[((* if t.sbp.length == 0 *))1((* else *))(((t.sbp.length)))((* endif *))] = { + ((*- for p in t.payload_as_byte_array *))(((p))),((*- endfor *)) + }; +}; + +TEST_F( ((( fixture_name ))), EncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ( ((( t.fn_prefix )))_encoded_len(&info.test_msg), info.payload_len); + + EXPECT_EQ(sbp_message_encoded_len( (((t.enum_value))), &info.test_msg_wrapped), + info.payload_len); +} + +TEST_F( ((( fixture_name ))), EncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[(((t.payload_len_for_encoding_buf)))]; + uint8_t n_written; + + EXPECT_EQ( ((( t.fn_prefix )))_encode(&buf[0], sizeof(buf), &n_written, + &info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, (((t.sbp.length)))); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, (((t.sbp.length)))), 0); + + memset(&buf[0], 0, sizeof(buf)); + EXPECT_EQ(sbp_message_encode(&buf[0], sizeof(buf), &n_written, (((t.enum_value))), + &info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(n_written, (((t.sbp.length)))); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, (((t.sbp.length)))), 0); +} + +TEST_F( ((( fixture_name ))), EncodeToBufWithoutNwritten) { + auto info = get_test_msg_info(); + uint8_t buf[(((t.payload_len_for_encoding_buf)))]; + + EXPECT_EQ( + ((( t.fn_prefix )))_encode(&buf[0], sizeof(buf), nullptr, &info.test_msg), + SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, (((t.sbp.length)))), 0); +} + +((*- if t.fields|length > 0 *)) +TEST_F( ((( fixture_name ))), EncodedToBufUnderflow) { + auto info = get_test_msg_info(); + uint8_t buf[(((t.payload_len_for_encoding_buf)))]; + + for (uint8_t i = 0; i < (((t.sbp.length))); i++) { + EXPECT_EQ( ((( t.fn_prefix )))_encode(&buf[0], i, nullptr, &info.test_msg), + SBP_ENCODE_ERROR); + } +} +((*- endif *)) + +TEST_F( ((( fixture_name ))), DecodeFromBuf) { + auto info = get_test_msg_info(); + ((( t.struct_name ))) msg{}; + uint8_t n_read; + + EXPECT_EQ( (((t.fn_prefix)))_decode(&info.encoded_payload[0], info.payload_len, + &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, (((t.sbp.length)))); + EXPECT_EQ(msg, info.test_msg); + + sbp_msg_t wrapped_msg{}; + EXPECT_EQ(sbp_message_decode(&info.encoded_payload[0], info.payload_len, + &n_read, (((t.enum_value))), &wrapped_msg), + SBP_OK); + EXPECT_EQ(n_read, (((t.sbp.length)))); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F( ((( fixture_name ))), DecodeFromBufWithoutNread) { + auto info = get_test_msg_info(); + ((( t.struct_name ))) msg{}; + + EXPECT_EQ( (((t.fn_prefix)))_decode(&info.encoded_payload[0], info.payload_len, + nullptr, &msg), + SBP_OK); + EXPECT_EQ(msg, info.test_msg); +} + +((*- if t.fields|length > 0 *)) +TEST_F( ((( fixture_name ))), DecodeFromBufUnderflow) { + auto info = get_test_msg_info(); + ((( t.struct_name ))) msg{}; + + for (uint8_t i = 0; i < info.payload_len; i++) { + int expected_return = SBP_DECODE_ERROR; + + ((*- for f in t.c_decoded_fieldskeys *)) + ((*- set ff = t.c_decoded_fields[f] *)) + ((*- if ff is dict_type *)) + ((*- if ff.handle_as and ff.handle_as == "vararray-len" *)) + ((*- set relates_to = ff.relates_to *)) + size_t overhead = []()->size_t{(((t.struct_name))) t{}; return (((t.fn_prefix)))_encoded_len(&t); }(); + size_t elem_size = []()->size_t{(((t.struct_name))) t{}; t.(((f))) = 1; return (((t.fn_prefix)))_encoded_len(&t); }() - overhead; + + if (i >= overhead) { + if ( ((i - overhead) % elem_size) == 0) { + expected_return = SBP_OK; + } + } + ((*- elif ff.handle_as and ff.handle_as == "encoded-string" *)) + size_t overhead = SBP_(((t.canonical_name)))_ENCODED_OVERHEAD; + //size_t overhead = []()->size_t{(((t.struct_name))) t{}; return (((t.fn_prefix)))_encoded_len(&t); }(); + ((*- if ff.min_len *)) + overhead += (((ff.min_len))); ((*- endif *)) - EXPECT_EQ( (((- value.fn_prefix)))_encoded_len(&(((root_path)))), (((value.encoded_len)))); - ((*- endmacro *)) - - ((*- macro assign_value(root_path, path, value) *)) - ((*- if value is string_type *)) - { - const char assign_string[] = { (((value|str_escape))) }; - memcpy( (((-path))), assign_string, sizeof(assign_string)); - } - ((*- elif value is array_type *)) - ((*- for ff in value *)) - (((assign_value(root_path, path + '[' + loop.index0|to_str + ']', ff)))) - ((*- endfor *)) - ((*- elif value is dict_type *)) - ((*- if value.handle_as and value.handle_as == "encoded-string" *)) - (((assign_string(root_path, value)))) - ((*- else *)) - ((*- for k in value|sorted *))(((assign_value(root_path, path + '.' + k, value[k]))))((*- endfor *)) + if (i >= overhead) { + expected_return = SBP_OK; + } ((*- endif *)) - ((*- else *)) - (((path))) = (((value))); ((*- endif *)) - ((*- endmacro *)) + ((*- endfor *)) - uint8_t encoded_frame[] = { ((*- for p in t.packet_as_byte_array *))(((p))),((*- endfor *)) }; + EXPECT_EQ( + ((( t.fn_prefix )))_decode(&info.encoded_payload[0], i, nullptr, &msg), + expected_return); + } +} +((*- endif *)) - (((msg_type))) test_msg{}; - ((*- if t.c_decoded_fields *)) - ((*- for f in t.c_decoded_fieldskeys *))(((assign_value("test_msg", "test_msg." + f, t.c_decoded_fields[f]))))((*- endfor *)) - ((*- endif *)) - - EXPECT_EQ(send_message( (((t.raw_json_obj.sender))), test_msg), SBP_OK); - - EXPECT_EQ(dummy_wr_, sizeof(encoded_frame)); - EXPECT_EQ(memcmp(dummy_buff_, encoded_frame, sizeof(encoded_frame)), 0); - - while (dummy_rd_ < dummy_wr_) { - process(); +TEST_F( ((( fixture_name ))), ReceiveThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &Reader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F( ((( fixture_name ))), ReceiveThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_frame_reader(i); + sbp_state_set_io_context(&state, &reader); + + CHandler handler(&state); + + int most_recent_return = sbp_process(&state, &Reader::read_static); + while (most_recent_return == SBP_OK || reader.remaining() > 0) { + most_recent_return = sbp_process(&state, &Reader::read_static); } - EXPECT_EQ(n_callbacks_logged_, 1); - EXPECT_EQ(last_sender_id_, (((t.raw_json_obj.sender)))); - EXPECT_EQ(last_msg_, test_msg); + EXPECT_NE(most_recent_return, SBP_OK); + EXPECT_EQ(reader.remaining(), 0); - ((*- for f in t.c_decoded_fieldskeys *))(((compare_value("last_msg_", "last_msg_." + f, t.c_decoded_fields[f]))))((*- endfor *)) + EXPECT_EQ(handler.outputs.size(), 0); + } +} + +TEST_F( (((fixture_name))), SlowRead) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto reader = info.get_slow_frame_reader(); + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(sbp_process(&state, &SlowReader::read_static), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); } -((*- endfor *)) +TEST_F( (((fixture_name))), BadCRC) { + auto info = get_test_msg_info(); + uint8_t buf[SBP_MAX_FRAME_LEN]; + memcpy(&buf[0], info.encoded_frame, info.frame_len); + + // Introduce a CRC error which should cause an error return and no callback + buf[info.frame_len - 1]++; + + sbp_state_t state; + sbp_state_init(&state); + + Reader reader{buf, info.frame_len}; + sbp_state_set_io_context(&state, &reader); + + CHandler handler{&state}; + + while (reader.remaining() > 0) { + int res = sbp_process(&state, &Reader::read_static); + EXPECT_EQ(res, reader.remaining() == 0 ? SBP_CRC_ERROR : SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 0); +} + +TEST_F( ((( fixture_name ))), SendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ( (((t.fn_prefix)))_send(&state, info.sender_id, &info.test_msg, + &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F( ((( fixture_name ))), SendWrappedThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, (((t.enum_value))), info.sender_id, + &info.test_msg_wrapped, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F( ((( fixture_name ))), SendThroughSbpStateUnderflow) { + auto info = get_test_msg_info(); + + for (uint32_t i = 0; i < info.frame_len; i++) { + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(i); + sbp_state_set_io_context(&state, &writer); + + EXPECT_NE(sbp_message_send(&state, ((( t.enum_value ))), info.sender_id, &info.test_msg_wrapped, &Writer::write_c), SBP_OK); + EXPECT_EQ(writer.len(), i); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, i), 0); + } +} + +TEST_F( ((( fixture_name ))), DISABLED_SlowWrite) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer= info.get_slow_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp_message_send(&state, (((t.enum_value))), info.sender_id, &info.test_msg_wrapped, &SlowWriter::write_c), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +((* if t.c_decoded_fields|length > 0 *)) +TEST_F( ((( fixture_name ))), Comparison) { + auto info = get_test_msg_info(); + + ((*- macro compare_field(root_path, path, value) *)) + ((*- if value is array_type *)) + ((*- for ff in value *)) + ((( compare_field(root_path, path ~ '[' ~ loop.index0 ~ ']', ff) ))) + ((*- endfor *)) + ((*- elif value is dict_type and not value.handle_as *)) + ((*- for k in value|sorted *))(((compare_field(root_path, path + "." + k, value[k]))))((*- endfor *)) + ((*- else *)) + { + (((t.struct_name))) lesser = info.test_msg; + (((t.struct_name))) greater = info.test_msg; + make_lesser_greater(lesser.(((path))), greater.(((path)))); + comparison_tests(lesser, greater); + } + ((*- endif *)) + ((*- endmacro *)) + + ((*- if t.c_decoded_fields *)) + ((*- for f in t.c_decoded_fieldskeys *))(((compare_field("", "" ~ f, t.c_decoded_fields[f]))))((*- endfor *)) + ((*- endif *)) +} +((*- endif *)) + +TEST_F( ((( fixture_name ))), CppTraitsProperties) { + // EXPECT_EQ(sbp::MessageTraits<(((t.struct_name)))>::id, (((t.enum_value)))); + EXPECT_STREQ(sbp::MessageTraits<(((t.struct_name)))>::name, "(((t.canonical_name)))"); +} + +TEST_F( ((( fixture_name ))), CppTraitsFromSbpMsgT) { + auto info = get_test_msg_info(); + + const sbp_msg_t &const_sbp_msg_t = info.test_msg_wrapped; + sbp_msg_t &non_const_sbp_msg_t = info.test_msg_wrapped; + + const (((t.struct_name))) &const_unwrapped = + sbp::MessageTraits<(((t.struct_name)))>::get(const_sbp_msg_t); + (((t.struct_name))) &non_const_unwrapped = + sbp::MessageTraits<(((t.struct_name)))>::get(non_const_sbp_msg_t); + + EXPECT_EQ((const void *)&const_sbp_msg_t, (const void *)&const_unwrapped); + EXPECT_EQ((void *)&non_const_sbp_msg_t, (void *)&non_const_unwrapped); +} + +TEST_F( ((( fixture_name ))), CppTraitsToSbpMsgT) { + auto info = get_test_msg_info(); + + sbp_msg_t msg1 = + sbp::MessageTraits<(((t.struct_name)))>::to_sbp_msg(info.test_msg); + EXPECT_EQ(msg1.(((t.name_in_sbp_msg_t))), info.test_msg); + + sbp_msg_t msg2; + sbp::MessageTraits<(((t.struct_name)))>::to_sbp_msg(info.test_msg, &msg2); + EXPECT_EQ(msg2.(((t.name_in_sbp_msg_t))), info.test_msg); +} + +TEST_F( ((( fixture_name ))), CppTraitsEncodedLen) { + auto info = get_test_msg_info(); + EXPECT_EQ(sbp::MessageTraits<(((t.struct_name)))>::encoded_len(info.test_msg), + info.payload_len); +} + +TEST_F( ((( fixture_name ))), CppTraitsSendThroughSbpState) { + auto info = get_test_msg_info(); + sbp_state_t state; + sbp_state_init(&state); + + auto writer = info.get_frame_writer(); + sbp_state_set_io_context(&state, &writer); + + EXPECT_EQ(sbp::MessageTraits<(((t.struct_name)))>::send( + &state, info.sender_id, info.test_msg, &Writer::write_c), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), &info.encoded_frame[0], writer.len()), 0); +} + +TEST_F( ((( fixture_name ))), CppTraitsEncodeToBuf) { + auto info = get_test_msg_info(); + uint8_t buf[(((t.payload_len_for_encoding_buf)))]; + uint8_t n_written; + + EXPECT_EQ(sbp::MessageTraits<(((t.struct_name)))>::encode( + &buf[0], sizeof(buf), &n_written, info.test_msg), + SBP_OK); + EXPECT_EQ(n_written, (((t.sbp.length)))); + EXPECT_EQ(memcmp(&buf[0], info.encoded_payload, (((t.sbp.length)))), 0); +} + +TEST_F( ((( fixture_name ))), CppTraitsDecodeFromBuf) { + auto info = get_test_msg_info(); + (((t.struct_name))) msg{}; + uint8_t n_read; + + EXPECT_EQ(sbp::MessageTraits<(((t.struct_name)))>::decode( + &info.encoded_payload[0], info.payload_len, &n_read, &msg), + SBP_OK); + EXPECT_EQ(n_read, (((t.sbp.length)))); + EXPECT_EQ(msg, info.test_msg); +} + +TEST_F( ((( fixture_name ))), ReceiveThroughMessageHandler) { + auto info = get_test_msg_info(); + auto reader = info.get_frame_reader(); + + sbp::State state{}; + state.set_reader(&reader); + + CppHandler handler{&state}; + + while (reader.remaining() > 0) { + EXPECT_GE(state.process(), SBP_OK); + } + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F( ((( fixture_name ))), ProcessSbpMsgTThroughMessageHandler) { + auto info = get_test_msg_info(); + sbp::State state{}; + CppHandler handler(&state); + + state.process_message(info.sender_id, (((t.enum_value))), &info.test_msg_wrapped); + + EXPECT_EQ(handler.outputs.size(), 1); + EXPECT_EQ(handler.outputs[0].sender_id, info.sender_id); + EXPECT_EQ(handler.outputs[0].msg, info.test_msg); +} + +TEST_F( ((( fixture_name ))), SendThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ(state.send_message(info.sender_id, info.test_msg), SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +TEST_F( ((( fixture_name ))), SendWrappedSbpMsgTThroughCppState) { + auto info = get_test_msg_info(); + auto writer = info.get_frame_writer(); + + sbp::State state{}; + state.set_writer(&writer); + + EXPECT_EQ( + state.send_message(info.sender_id, (((t.enum_value))), info.test_msg_wrapped), + SBP_OK); + EXPECT_EQ(writer.len(), info.frame_len); + EXPECT_EQ(memcmp(writer.data(), info.encoded_frame, info.frame_len), 0); +} + +((* for f in t.c_decoded_fieldskeys *)) +((* if t.c_decoded_fields[f].handle_as and t.c_decoded_fields[f].handle_as == "encoded-string" *)) +((* set s = t.c_decoded_fields[f] *)) +((* set is_simple_string = True *)) +((* if s.sections *))((* set is_simple_string = False *))((* endif *)) +class ((( fixture_name )))_((( f ))) : public ((( fixture_name ))) {}; + +TEST_F( ((( fixture_name)))_((( f ))), StringInit) { + ((( t.struct_name ))) t{}; + ((( s.fn_prefix )))_init(&t); + EXPECT_TRUE( ((( s.fn_prefix )))_valid(&t) ); +} + + TEST_F( ((( fixture_name)))_((( f ))), IsValid) { + ((( t.struct_name ))) t{}; + ((( assign_string('t', s) ))) + EXPECT_TRUE( ((( s.fn_prefix)))_valid(&t) ); + } + +TEST_F( ((( fixture_name)))_((( f))), SpaceRemaining) { + ((( t.struct_name ))) t{}; + size_t empty_space_remaining = ((( s.fn_prefix )))_space_remaining(&t); + ((( assign_string('t', s) ))) + size_t assigned_space_remaining = ((( s.fn_prefix )))_space_remaining(&t); + EXPECT_LT(assigned_space_remaining, empty_space_remaining); +} + +((* if is_simple_string *)) +TEST_F( ((( fixture_name)))_((( f ))), SetRaw) { + auto info = get_test_msg_info(); + ((( t.struct_name ))) t{}; + + size_t nwritten{}; + + EXPECT_TRUE( (((s.fn_prefix)))_set_raw(&t, info.test_msg.((( f ))).data, + ((( s.fn_prefix )))_strlen(&info.test_msg), false, &nwritten)); + EXPECT_EQ( (((s.fn_prefix)))_encoded_len(&info.test_msg), (((s.fn_prefix)))_encoded_len(&t)); +} + +TEST_F( ((( fixture_name)))_((( f ))), Set) { + ((( t.struct_name ))) t{}; + size_t nwritten {}; + const char *text = "(((s.text)))"; + + EXPECT_TRUE( (((s.fn_prefix)))_set(&t, text, false, &nwritten)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), text); +} + +TEST_F( ((( fixture_name)))_(((f))), Printf) { + ((( t.struct_name ))) t{}; + size_t nwritten {}; + const char *text = "(((s.text)))"; + + EXPECT_TRUE( (((s.fn_prefix)))_printf(&t, false, &nwritten, "%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), text); +} + +TEST_F( ((( fixture_name)))_(((f))), Vprintf) { + ((( t.struct_name ))) t{}; + size_t nwritten {}; + const char *text = "(((s.text)))"; + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = (((s.fn_prefix)))_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", text)); + EXPECT_EQ(nwritten, strlen(text)); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), text); +} + +TEST_F( ((( fixture_name)))_(((f))), AppendPrintf) { + ((( t.struct_name))) t{}; + size_t nwritten{}; + char part1[] = "(((s.text)))"; + char part2[] = "(((s.text)))"; + + part1[1] = 0; + + EXPECT_TRUE( (((s.fn_prefix)))_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), &part1[0]); + + EXPECT_TRUE( (((s.fn_prefix)))_append_printf(&t, false, &nwritten, "%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), "(((s.text)))"); +} + +TEST_F( ((( fixture_name)))_(((f))), AppendVprintf) { + ((( t.struct_name))) t{}; + size_t nwritten{}; + char part1[] = "(((s.text)))"; + char part2[] = "(((s.text)))"; + + part1[1] = 0; + + EXPECT_TRUE( (((s.fn_prefix)))_printf(&t, false, &nwritten, "%s", &part1[0])); + EXPECT_EQ(nwritten, 1); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), &part1[0]); + + auto lambda = [&t, &nwritten](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = (((s.fn_prefix)))_append_vprintf(&t, false, &nwritten, format, ap); + va_end(ap); + return ret; + }; + + EXPECT_TRUE(lambda("%s", &part2[1])); + EXPECT_EQ(nwritten, strlen(&part2[1])); + EXPECT_STREQ( (((s.fn_prefix)))_get(&t), "(((s.text)))"); +} + +((* else *)) +TEST_F( ((( fixture_name)))_(((f))), CountSections) { + auto info = get_test_msg_info(); + EXPECT_EQ( (((s.fn_prefix)))_count_sections(&info.test_msg), ((( s.sections|length ))) ); +} + +TEST_F( ((( fixture_name)))_(((f))), AddSectionPrintf) { + ((( t.struct_name))) t{}; + + ((* for i in s.sections *)) + EXPECT_TRUE( (((s.fn_prefix)))_add_section_printf(&t, "%s", "(((i)))")); + ((* endfor *)) + + EXPECT_EQ( (((s.fn_prefix)))_count_sections(&t), (((s.sections|length)))); + ((* for i in s.sections *)) + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, (((loop.index0)))), "(((i)))"); + ((* endfor *)) +} + +TEST_F( ((( fixture_name)))_(((f))), AddSectionVprintf) { + ((( t.struct_name))) t{}; + + ((* for i in s.sections *)) + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = (((s.fn_prefix)))_add_section_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", "(((i)))")); + } + ((* endfor *)) + + EXPECT_EQ( (((s.fn_prefix)))_count_sections(&t), (((s.sections|length)))); + ((* for i in s.sections *)) + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, (((loop.index0)))), "(((i)))"); + ((* endfor *)) +} + +TEST_F( ((( fixture_name)))_(((f))), Append) { + ((( t.struct_name))) t{}; + + char part1[] = "(((s.sections[0])))"; + char part2[] = "(((s.sections[0])))"; + part1[1] = 0; + + EXPECT_TRUE( (((s.fn_prefix)))_append(&t, part1)); + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), part1); + EXPECT_TRUE( (((s.fn_prefix)))_append(&t, &part2[1])); + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), "(((s.sections[0])))"); +} + +TEST_F( (((fixture_name)))_(((f))), AppendPrintf) { + (((t.struct_name))) t{}; + + char part1[] = "(((s.sections[0])))"; + char part2[] = "(((s.sections[0])))"; + part1[1] = 0; + + EXPECT_TRUE( (((s.fn_prefix)))_append_printf(&t, "%s", part1)); + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), part1); + EXPECT_TRUE( (((s.fn_prefix)))_append_printf(&t, "%s", &part2[1])); + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), "(((s.sections[0])))"); +} + +TEST_F( (((fixture_name)))_(((f))), AppendVprintf) { + (((t.struct_name))) t{}; + + char part1[] = "(((s.sections[0])))"; + char part2[] = "(((s.sections[0])))"; + part1[1] = 0; + + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = (((s.fn_prefix)))_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", part1)); + } + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), part1); + { + auto lambda = [&t](const char *format, ...) -> bool { + va_list ap; + va_start(ap, format); + bool ret = (((s.fn_prefix)))_append_vprintf(&t, format, ap); + va_end(ap); + return ret; + }; + EXPECT_TRUE(lambda("%s", &part2[1])); + } + EXPECT_STREQ( (((s.fn_prefix)))_get_section(&t, 0), "(((s.sections[0])))"); +} + +TEST_F( (((fixture_name)))_(((f))), SectionStrlen) { + auto info = get_test_msg_info(); + + ((* for i in s.sections *)) + EXPECT_EQ( (((s.fn_prefix)))_section_strlen(&info.test_msg, (((loop.index0)))), strlen("(((i)))")); + ((* endfor *)) +} + +((* endif *)) + +((* endif *)) +((* endfor *)) + +((* endfor *)) + +((* for t in s.test_structs *)) +((*- set fixture_name = "Test_Struct_" ~ s.suite_name ~ loop.index0 *)) + class ((( fixture_name ))) : public ::testing::Test { + public: + (((fixture_name))) () { + ((*- for f in t.c_decoded_fieldskeys *))(((assign_value("test_struct_", "test_struct_." + f, t.c_decoded_fields[f]))))((*- endfor *)) + } + + struct TestStructInfo { + (((t.struct_name))) test_struct; + const uint8_t *encoded_data; + uint32_t encoded_len; + }; + + TestStructInfo get_test_struct_info() const noexcept { + TestStructInfo info; + memcpy(&info.test_struct, &test_struct_, sizeof(test_struct_)); + info.encoded_data = encoded_data_; + info.encoded_len = sizeof(encoded_data_); + return info; + } + + private: + ((( t.struct_name ))) test_struct_{}; + uint8_t encoded_data_[(((t.encoded_len)))] = { + ((*- for p in t.encoded_data_as_byte_array *))(((p))),((*- endfor *)) + }; +}; + + TEST_F( (((fixture_name))), EncodedLen) { + auto info = get_test_struct_info(); + EXPECT_EQ( (((t.fn_prefix)))_encoded_len(&info.test_struct), (((t.encoded_len)))); + } + + TEST_F( (((fixture_name))), FreeEncode) { + auto info = get_test_struct_info(); + uint8_t nwritten = 0; + uint8_t buf[(((t.encoded_len_for_buf)))]; + EXPECT_EQ( (((t.fn_prefix)))_encode(&buf[0], sizeof(buf), &nwritten, &info.test_struct), SBP_OK); + EXPECT_EQ(nwritten, (((t.encoded_len)))); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, nwritten), 0); + } + + TEST_F( (((fixture_name))), FreeEncodeWithoutNwritten) { + auto info = get_test_struct_info(); + uint8_t buf[(((t.encoded_len_for_buf)))]; + EXPECT_EQ( (((t.fn_prefix)))_encode(&buf[0], sizeof(buf), nullptr, &info.test_struct), SBP_OK); + EXPECT_EQ(memcmp(&buf[0], info.encoded_data, (((t.encoded_len)))), 0); + } + + TEST_F( (((fixture_name))), FreeEncodeUnderflow) { + auto info = get_test_struct_info(); + uint8_t buf[(((t.encoded_len)))]; + for (uint8_t i = 0; i < (((t.encoded_len))); i++) { + EXPECT_EQ( (((t.fn_prefix)))_encode(&buf[0], i, nullptr, &info.test_struct), SBP_ENCODE_ERROR); +} + } + + TEST_F( (((fixture_name))), FreeDecode) { + auto info = get_test_struct_info(); + uint8_t nread = 0; + (((t.struct_name))) t{}; + EXPECT_EQ( (((t.fn_prefix)))_decode(info.encoded_data, (((t.encoded_len))), &nread, &t), SBP_OK); + EXPECT_EQ(nread, info.encoded_len); + EXPECT_EQ( (((t.fn_prefix)))_cmp(&t, &info.test_struct), 0); + } + + TEST_F( (((fixture_name))), FreeDecodeWithoutNread) { + auto info = get_test_struct_info(); + (((t.struct_name))) t{}; + EXPECT_EQ( (((t.fn_prefix)))_decode(info.encoded_data, (((t.encoded_len))), nullptr, &t), SBP_OK); + EXPECT_EQ( (((t.fn_prefix)))_cmp(&t, &info.test_struct), 0); + } + +TEST_F( (((fixture_name))), FreeDecodeUnderflow) { + auto info = get_test_struct_info(); + (((t.struct_name))) t{}; + +for (uint8_t i = 0; i < (((t.encoded_len))); i++) { + EXPECT_EQ( (((t.fn_prefix)))_decode(info.encoded_data, i, nullptr, &t), SBP_DECODE_ERROR); + } +} + +((* endfor *)) + +} diff --git a/generator/sbpg/targets/test_c.py b/generator/sbpg/targets/test_c.py index b8dff5d69d..947eba58cb 100644 --- a/generator/sbpg/targets/test_c.py +++ b/generator/sbpg/targets/test_c.py @@ -70,18 +70,21 @@ def render_source(output_dir, package_spec): Render and output to a directory given a package specification. """ path, name = package_spec.filepath - destination_filename = "%s/%s.c" % (output_dir, name) - py_template = JENV.get_template(TEST_TEMPLATE_NAME) - with open(destination_filename, "w") as f: - f.write( - py_template.render( - s=package_spec, - description=package_spec.description, - pkg_name=package_spec.package, - include=package_spec.package.split(".")[1], - filepath="/".join(package_spec.filepath) + ".yaml", + + # The older templates require at least 1 message test, they don't work with specifications which only test structs + if len(package_spec.tests) > 0: + destination_filename = "%s/%s.c" % (output_dir, name) + py_template = JENV.get_template(TEST_TEMPLATE_NAME) + with open(destination_filename, "w") as f: + f.write( + py_template.render( + s=package_spec, + description=package_spec.description, + pkg_name=package_spec.package, + include=package_spec.package.split(".")[1], + filepath="/".join(package_spec.filepath) + ".yaml", + ) ) - ) destination_filename = "%s/cpp/%s.cc" % (output_dir, name) py_template = JENV.get_template(CPP_TEST_TEMPLATE_NAME) with open(destination_filename, "w") as f: diff --git a/generator/sbpg/targets/test_legacy_c.py b/generator/sbpg/targets/test_legacy_c.py index adad6931f2..b0956c7c26 100644 --- a/generator/sbpg/targets/test_legacy_c.py +++ b/generator/sbpg/targets/test_legacy_c.py @@ -38,6 +38,10 @@ def render_source(output_dir, package_spec): """ Render and output to a directory given a package specification. """ + + # Test cases solely for structs are not supported in the legacy templates + if len(package_spec.tests) == 0: + return path, name = package_spec.filepath destination_filename = "%s/legacy/%s.c" % (output_dir, name) py_template = JENV.get_template(TEST_TEMPLATE_NAME) diff --git a/generator/sbpg/test_structs.py b/generator/sbpg/test_structs.py index 62fe09de05..84b12c9a73 100644 --- a/generator/sbpg/test_structs.py +++ b/generator/sbpg/test_structs.py @@ -18,8 +18,10 @@ import base64 import json import os.path +import re from binascii import unhexlify +from sbpg.targets.templating import ACRONYMS, LOWER_ACRONYMS import yaml @@ -36,13 +38,14 @@ class PackageTestSpecification(object): """ - def __init__(self, src_filename=None, package="", suite_no=0, description=None, generated_on=None, tests=None): + def __init__(self, src_filename=None, package="", suite_no=0, description=None, generated_on=None, tests=None, test_structs=None): self.src_filename = src_filename self.package = package self.suite_no = suite_no self.description = description self.generated_on = generated_on self.tests = tests or [] + self.test_structs = test_structs or [] self.render_source = True def __lt__(self, other): @@ -93,6 +96,18 @@ def __init__(self, raw_packet, msg_type, raw_json, msg, sbp, test_msg_data=None) self.msg = msg self.sbp = sbp self.test_msg_data = test_msg_data + self.payload = base64.standard_b64decode(self.sbp['payload']) + self.payload_as_byte_array = list(bytearray(self.payload)) + self.payload_len_for_encoding_buf = len(self.payload) if len(self.payload) > 0 else 1 + msg_name = msg['name'] + for i in range(0, len(ACRONYMS)): + msg_name = re.sub(ACRONYMS[i], LOWER_ACRONYMS[i], msg_name) + self.enum_value = "Sbp" + msg_name + self.msg_type_value = msg_type + self.struct_name = "sbp_" + re.sub(r"(? 1) + self.encoded_data = base64.standard_b64decode(spec['encoded']) + self.encoded_len = len(self.encoded_data) + self.encoded_len_for_buf = self.encoded_len if self.encoded_len != 0 else 1 + self.encoded_data_as_byte_array = list(bytearray(self.encoded_data)) + self.canonical_name = spec['name'] + self.struct_name = "sbp_" + re.sub(r"(? 0, "No message definitions found in %s" % ROOTPATH diff --git a/python/tests/sbp/utils.py b/python/tests/sbp/utils.py index bb3e102a6b..14df7b37d6 100755 --- a/python/tests/sbp/utils.py +++ b/python/tests/sbp/utils.py @@ -238,7 +238,12 @@ def _assert_sane_package(pkg_name, pkg): Parsed contents of YAML file. """ - assert len(pkg['tests']) > 0, "Package has no tests!" + total_tests = 0 + if 'tests' in pkg: + total_tests = total_tests + len(pkg['tests']) + if 'struct_tests' in pkg: + total_tests = total_tests + len(pkg['struct_tests']) + assert total_tests > 0, "Package has no tests!" def load_test_package(test_filename): """ @@ -266,6 +271,8 @@ def load_test_package(test_filename): def assert_package(test_filename): pkg = load_test_package(test_filename) + if 'tests' not in pkg: + return for test_case in pkg['tests']: sbp = SBP.unpack(base64.standard_b64decode(test_case['raw_packet'])) _assert_sbp(sbp, test_case['sbp']) diff --git a/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_result.rs b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_result.rs new file mode 100644 index 0000000000..15b8abb424 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_result.rs @@ -0,0 +1,244 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_acquisition_msg_acq_result() { + { + let mut payload = Cursor::new(vec![ + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, + 189, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqResult(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2f, + "Incorrect message type, expected 0x2f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.cf.almost_eq(8.24120019531250000e+03), + "incorrect value for cf, expected 8.24120019531250000e+03, is {:e}", + msg.cf + ); + assert!( + msg.cn0.almost_eq(1.45000000000000000e+01), + "incorrect value for cn0, expected 1.45000000000000000e+01, is {:e}", + msg.cn0 + ); + assert!( + msg.cp.almost_eq(7.21999969482421875e+01), + "incorrect value for cp, expected 7.21999969482421875e+01, is {:e}", + msg.cp + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 8, + "incorrect value for sid.sat, expected 8, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqResult"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_result() { + { + let json_input = r#"{"preamble":85,"msg_type":47,"sender":1219,"length":14,"payload":"AABoQWZmkELNxABGCAA=","crc":48591,"cn0":14.5,"cp":72.19999694824219,"cf":8241.2001953125,"sid":{"sat":8,"code":0}}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqResult(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2f, + "Incorrect message type, expected 0x2f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.cf.almost_eq(8.24120019531250000e+03), + "incorrect value for cf, expected 8.24120019531250000e+03, is {:e}", + msg.cf + ); + assert!( + msg.cn0.almost_eq(1.45000000000000000e+01), + "incorrect value for cn0, expected 1.45000000000000000e+01, is {:e}", + msg.cn0 + ); + assert!( + msg.cp.almost_eq(7.21999969482421875e+01), + "incorrect value for cp, expected 7.21999969482421875e+01, is {:e}", + msg.cp + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 8, + "incorrect value for sid.sat, expected 8, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqResult"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_acquisition_msg_acq_result`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_result() { + { + let mut payload = Cursor::new(vec![ + 85, 47, 0, 195, 4, 14, 0, 0, 104, 65, 102, 102, 144, 66, 205, 196, 0, 70, 8, 0, 207, + 189, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAcqResult( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAcqResult(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2f, + "Incorrect message type, expected 0x2f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.cf.almost_eq(8.24120019531250000e+03), + "incorrect value for cf, expected 8.24120019531250000e+03, is {:e}", + msg.cf + ); + assert!( + msg.cn0.almost_eq(1.45000000000000000e+01), + "incorrect value for cn0, expected 1.45000000000000000e+01, is {:e}", + msg.cn0 + ); + assert!( + msg.cp.almost_eq(7.21999969482421875e+01), + "incorrect value for cp, expected 7.21999969482421875e+01, is {:e}", + msg.cp + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 8, + "incorrect value for sid.sat, expected 8, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqResult"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile.rs b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile.rs new file mode 100644 index 0000000000..731f7515e2 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile.rs @@ -0,0 +1,760 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_acquisition_msg_acq_sv_profile() { + { + let mut payload = Cursor::new(vec![ + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, 0, 52, 0, 0, 0, 49, 0, 0, 0, 61, + 0, 0, 0, 147, 0, 0, 0, 47, 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, 0, 253, 23, 1, 121, 0, + 190, 0, 0, 0, 175, 0, 0, 0, 175, 0, 0, 0, 142, 0, 0, 0, 237, 0, 0, 0, 12, 0, 0, 0, 126, + 88, 21, 0, 153, 24, 0, 8, 0, 130, 0, 0, 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, 0, 84, + 0, 0, 0, 82, 0, 0, 0, 168, 177, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfile(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2e, + "Incorrect message type, expected 0x2e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 174, + "incorrect value for acq_sv_profile[0].bin_width, expected 174, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 47, + "incorrect value for acq_sv_profile[0].cf, expected 47, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 147, + "incorrect value for acq_sv_profile[0].cf_max, expected 147, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 61, + "incorrect value for acq_sv_profile[0].cf_min, expected 61, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 38, + "incorrect value for acq_sv_profile[0].cn0, expected 38, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 140, + "incorrect value for acq_sv_profile[0].cp, expected 140, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 97, + "incorrect value for acq_sv_profile[0].int_time, expected 97, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 7, + "incorrect value for acq_sv_profile[0].job_type, expected 7, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 13, + "incorrect value for acq_sv_profile[0].status, expected 13, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 49, + "incorrect value for acq_sv_profile[0].time_spent, expected 49, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 52, + "incorrect value for acq_sv_profile[0].timestamp, expected 52, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 121, + "incorrect value for acq_sv_profile[1].bin_width, expected 121, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 237, + "incorrect value for acq_sv_profile[1].cf, expected 237, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 142, + "incorrect value for acq_sv_profile[1].cf_max, expected 142, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 175, + "incorrect value for acq_sv_profile[1].cf_min, expected 175, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 59, + "incorrect value for acq_sv_profile[1].cn0, expected 59, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 12, + "incorrect value for acq_sv_profile[1].cp, expected 12, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 253, + "incorrect value for acq_sv_profile[1].int_time, expected 253, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 166, + "incorrect value for acq_sv_profile[1].job_type, expected 166, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 210, + "incorrect value for acq_sv_profile[1].status, expected 210, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 175, + "incorrect value for acq_sv_profile[1].time_spent, expected 175, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 190, + "incorrect value for acq_sv_profile[1].timestamp, expected 190, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 8, + "incorrect value for acq_sv_profile[2].bin_width, expected 8, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 84, + "incorrect value for acq_sv_profile[2].cf, expected 84, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 191, + "incorrect value for acq_sv_profile[2].cf_max, expected 191, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 91, + "incorrect value for acq_sv_profile[2].cf_min, expected 91, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 21, + "incorrect value for acq_sv_profile[2].cn0, expected 21, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 82, + "incorrect value for acq_sv_profile[2].cp, expected 82, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 153, + "incorrect value for acq_sv_profile[2].int_time, expected 153, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 126, + "incorrect value for acq_sv_profile[2].job_type, expected 126, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 88, + "incorrect value for acq_sv_profile[2].status, expected 88, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 172, + "incorrect value for acq_sv_profile[2].time_spent, expected 172, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 130, + "incorrect value for acq_sv_profile[2].timestamp, expected 130, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfile"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_sv_profile() { + { + let json_input = r#"{"crc":45480,"length":99,"msg_type":46,"payload":"Bw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAA","preamble":85,"sender":1219,"acq_sv_profile":[{"job_type":7,"status":13,"cn0":38,"int_time":97,"sid":{"sat":22,"code":0},"bin_width":174,"timestamp":52,"time_spent":49,"cf_min":61,"cf_max":147,"cf":47,"cp":140},{"job_type":166,"status":210,"cn0":59,"int_time":253,"sid":{"sat":23,"code":1},"bin_width":121,"timestamp":190,"time_spent":175,"cf_min":175,"cf_max":142,"cf":237,"cp":12},{"job_type":126,"status":88,"cn0":21,"int_time":153,"sid":{"sat":24,"code":0},"bin_width":8,"timestamp":130,"time_spent":172,"cf_min":91,"cf_max":191,"cf":84,"cp":82}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfile(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2e, + "Incorrect message type, expected 0x2e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 174, + "incorrect value for acq_sv_profile[0].bin_width, expected 174, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 47, + "incorrect value for acq_sv_profile[0].cf, expected 47, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 147, + "incorrect value for acq_sv_profile[0].cf_max, expected 147, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 61, + "incorrect value for acq_sv_profile[0].cf_min, expected 61, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 38, + "incorrect value for acq_sv_profile[0].cn0, expected 38, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 140, + "incorrect value for acq_sv_profile[0].cp, expected 140, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 97, + "incorrect value for acq_sv_profile[0].int_time, expected 97, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 7, + "incorrect value for acq_sv_profile[0].job_type, expected 7, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 13, + "incorrect value for acq_sv_profile[0].status, expected 13, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 49, + "incorrect value for acq_sv_profile[0].time_spent, expected 49, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 52, + "incorrect value for acq_sv_profile[0].timestamp, expected 52, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 121, + "incorrect value for acq_sv_profile[1].bin_width, expected 121, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 237, + "incorrect value for acq_sv_profile[1].cf, expected 237, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 142, + "incorrect value for acq_sv_profile[1].cf_max, expected 142, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 175, + "incorrect value for acq_sv_profile[1].cf_min, expected 175, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 59, + "incorrect value for acq_sv_profile[1].cn0, expected 59, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 12, + "incorrect value for acq_sv_profile[1].cp, expected 12, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 253, + "incorrect value for acq_sv_profile[1].int_time, expected 253, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 166, + "incorrect value for acq_sv_profile[1].job_type, expected 166, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 210, + "incorrect value for acq_sv_profile[1].status, expected 210, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 175, + "incorrect value for acq_sv_profile[1].time_spent, expected 175, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 190, + "incorrect value for acq_sv_profile[1].timestamp, expected 190, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 8, + "incorrect value for acq_sv_profile[2].bin_width, expected 8, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 84, + "incorrect value for acq_sv_profile[2].cf, expected 84, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 191, + "incorrect value for acq_sv_profile[2].cf_max, expected 191, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 91, + "incorrect value for acq_sv_profile[2].cf_min, expected 91, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 21, + "incorrect value for acq_sv_profile[2].cn0, expected 21, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 82, + "incorrect value for acq_sv_profile[2].cp, expected 82, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 153, + "incorrect value for acq_sv_profile[2].int_time, expected 153, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 126, + "incorrect value for acq_sv_profile[2].job_type, expected 126, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 88, + "incorrect value for acq_sv_profile[2].status, expected 88, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 172, + "incorrect value for acq_sv_profile[2].time_spent, expected 172, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 130, + "incorrect value for acq_sv_profile[2].timestamp, expected 130, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfile"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_acquisition_msg_acq_sv_profile`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_sv_profile() { + { + let mut payload = Cursor::new(vec![ + 85, 46, 0, 195, 4, 99, 7, 13, 38, 0, 97, 22, 0, 174, 0, 52, 0, 0, 0, 49, 0, 0, 0, 61, + 0, 0, 0, 147, 0, 0, 0, 47, 0, 0, 0, 140, 0, 0, 0, 166, 210, 59, 0, 253, 23, 1, 121, 0, + 190, 0, 0, 0, 175, 0, 0, 0, 175, 0, 0, 0, 142, 0, 0, 0, 237, 0, 0, 0, 12, 0, 0, 0, 126, + 88, 21, 0, 153, 24, 0, 8, 0, 130, 0, 0, 0, 172, 0, 0, 0, 91, 0, 0, 0, 191, 0, 0, 0, 84, + 0, 0, 0, 82, 0, 0, 0, 168, 177, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAcqSvProfile( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfile(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2e, + "Incorrect message type, expected 0x2e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 174, + "incorrect value for acq_sv_profile[0].bin_width, expected 174, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 47, + "incorrect value for acq_sv_profile[0].cf, expected 47, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 147, + "incorrect value for acq_sv_profile[0].cf_max, expected 147, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 61, + "incorrect value for acq_sv_profile[0].cf_min, expected 61, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 38, + "incorrect value for acq_sv_profile[0].cn0, expected 38, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 140, + "incorrect value for acq_sv_profile[0].cp, expected 140, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 97, + "incorrect value for acq_sv_profile[0].int_time, expected 97, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 7, + "incorrect value for acq_sv_profile[0].job_type, expected 7, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 13, + "incorrect value for acq_sv_profile[0].status, expected 13, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 49, + "incorrect value for acq_sv_profile[0].time_spent, expected 49, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 52, + "incorrect value for acq_sv_profile[0].timestamp, expected 52, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 121, + "incorrect value for acq_sv_profile[1].bin_width, expected 121, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 237, + "incorrect value for acq_sv_profile[1].cf, expected 237, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 142, + "incorrect value for acq_sv_profile[1].cf_max, expected 142, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 175, + "incorrect value for acq_sv_profile[1].cf_min, expected 175, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 59, + "incorrect value for acq_sv_profile[1].cn0, expected 59, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 12, + "incorrect value for acq_sv_profile[1].cp, expected 12, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 253, + "incorrect value for acq_sv_profile[1].int_time, expected 253, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 166, + "incorrect value for acq_sv_profile[1].job_type, expected 166, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 210, + "incorrect value for acq_sv_profile[1].status, expected 210, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 175, + "incorrect value for acq_sv_profile[1].time_spent, expected 175, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 190, + "incorrect value for acq_sv_profile[1].timestamp, expected 190, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 8, + "incorrect value for acq_sv_profile[2].bin_width, expected 8, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 84, + "incorrect value for acq_sv_profile[2].cf, expected 84, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 191, + "incorrect value for acq_sv_profile[2].cf_max, expected 191, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 91, + "incorrect value for acq_sv_profile[2].cf_min, expected 91, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 21, + "incorrect value for acq_sv_profile[2].cn0, expected 21, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 82, + "incorrect value for acq_sv_profile[2].cp, expected 82, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 153, + "incorrect value for acq_sv_profile[2].int_time, expected 153, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 126, + "incorrect value for acq_sv_profile[2].job_type, expected 126, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 88, + "incorrect value for acq_sv_profile[2].status, expected 88, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 172, + "incorrect value for acq_sv_profile[2].time_spent, expected 172, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 130, + "incorrect value for acq_sv_profile[2].timestamp, expected 130, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfile"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile_dep.rs new file mode 100644 index 0000000000..89b3eced1a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_acquisition_msg_acq_sv_profile_dep.rs @@ -0,0 +1,805 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_acquisition_msg_acq_sv_profile_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, 187, 0, 91, 0, 0, 0, 75, 0, + 0, 0, 132, 0, 0, 0, 36, 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, 179, 23, + 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, + 247, 0, 0, 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, 0, 245, 0, 0, 0, 76, + 0, 0, 0, 248, 0, 0, 0, 212, 0, 0, 0, 101, 0, 0, 0, 67, 132, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfileDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1e, + "Incorrect message type, expected 0x1e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 187, + "incorrect value for acq_sv_profile[0].bin_width, expected 187, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 60, + "incorrect value for acq_sv_profile[0].cf, expected 60, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 36, + "incorrect value for acq_sv_profile[0].cf_max, expected 36, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 132, + "incorrect value for acq_sv_profile[0].cf_min, expected 132, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 151, + "incorrect value for acq_sv_profile[0].cn0, expected 151, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 241, + "incorrect value for acq_sv_profile[0].cp, expected 241, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 12, + "incorrect value for acq_sv_profile[0].int_time, expected 12, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 67, + "incorrect value for acq_sv_profile[0].job_type, expected 67, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.reserved, 0, + "incorrect value for acq_sv_profile[0].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[0].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 103, + "incorrect value for acq_sv_profile[0].status, expected 103, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 75, + "incorrect value for acq_sv_profile[0].time_spent, expected 75, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 91, + "incorrect value for acq_sv_profile[0].timestamp, expected 91, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 176, + "incorrect value for acq_sv_profile[1].bin_width, expected 176, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 212, + "incorrect value for acq_sv_profile[1].cf, expected 212, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 24, + "incorrect value for acq_sv_profile[1].cf_max, expected 24, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 155, + "incorrect value for acq_sv_profile[1].cf_min, expected 155, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 111, + "incorrect value for acq_sv_profile[1].cn0, expected 111, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 247, + "incorrect value for acq_sv_profile[1].cp, expected 247, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 179, + "incorrect value for acq_sv_profile[1].int_time, expected 179, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 238, + "incorrect value for acq_sv_profile[1].job_type, expected 238, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.reserved, 0, + "incorrect value for acq_sv_profile[1].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[1].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 38, + "incorrect value for acq_sv_profile[1].status, expected 38, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 234, + "incorrect value for acq_sv_profile[1].time_spent, expected 234, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 166, + "incorrect value for acq_sv_profile[1].timestamp, expected 166, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 52, + "incorrect value for acq_sv_profile[2].bin_width, expected 52, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 212, + "incorrect value for acq_sv_profile[2].cf, expected 212, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 248, + "incorrect value for acq_sv_profile[2].cf_max, expected 248, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 76, + "incorrect value for acq_sv_profile[2].cf_min, expected 76, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 68, + "incorrect value for acq_sv_profile[2].cn0, expected 68, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 101, + "incorrect value for acq_sv_profile[2].cp, expected 101, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 53, + "incorrect value for acq_sv_profile[2].int_time, expected 53, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 142, + "incorrect value for acq_sv_profile[2].job_type, expected 142, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.reserved, 0, + "incorrect value for acq_sv_profile[2].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[2].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 213, + "incorrect value for acq_sv_profile[2].status, expected 213, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 245, + "incorrect value for acq_sv_profile[2].time_spent, expected 245, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 49, + "incorrect value for acq_sv_profile[2].timestamp, expected 49, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfileDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_acquisition_msg_acq_sv_profile_dep() { + { + let json_input = r#"{"crc":33859,"length":105,"msg_type":30,"payload":"Q2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAA","preamble":85,"sender":1219,"acq_sv_profile":[{"job_type":67,"status":103,"cn0":151,"int_time":12,"sid":{"sat":22,"code":0,"reserved":0},"bin_width":187,"timestamp":91,"time_spent":75,"cf_min":132,"cf_max":36,"cf":60,"cp":241},{"job_type":238,"status":38,"cn0":111,"int_time":179,"sid":{"sat":23,"code":1,"reserved":0},"bin_width":176,"timestamp":166,"time_spent":234,"cf_min":155,"cf_max":24,"cf":212,"cp":247},{"job_type":142,"status":213,"cn0":68,"int_time":53,"sid":{"sat":24,"code":0,"reserved":0},"bin_width":52,"timestamp":49,"time_spent":245,"cf_min":76,"cf_max":248,"cf":212,"cp":101}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfileDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1e, + "Incorrect message type, expected 0x1e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 187, + "incorrect value for acq_sv_profile[0].bin_width, expected 187, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 60, + "incorrect value for acq_sv_profile[0].cf, expected 60, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 36, + "incorrect value for acq_sv_profile[0].cf_max, expected 36, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 132, + "incorrect value for acq_sv_profile[0].cf_min, expected 132, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 151, + "incorrect value for acq_sv_profile[0].cn0, expected 151, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 241, + "incorrect value for acq_sv_profile[0].cp, expected 241, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 12, + "incorrect value for acq_sv_profile[0].int_time, expected 12, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 67, + "incorrect value for acq_sv_profile[0].job_type, expected 67, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.reserved, 0, + "incorrect value for acq_sv_profile[0].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[0].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 103, + "incorrect value for acq_sv_profile[0].status, expected 103, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 75, + "incorrect value for acq_sv_profile[0].time_spent, expected 75, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 91, + "incorrect value for acq_sv_profile[0].timestamp, expected 91, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 176, + "incorrect value for acq_sv_profile[1].bin_width, expected 176, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 212, + "incorrect value for acq_sv_profile[1].cf, expected 212, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 24, + "incorrect value for acq_sv_profile[1].cf_max, expected 24, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 155, + "incorrect value for acq_sv_profile[1].cf_min, expected 155, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 111, + "incorrect value for acq_sv_profile[1].cn0, expected 111, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 247, + "incorrect value for acq_sv_profile[1].cp, expected 247, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 179, + "incorrect value for acq_sv_profile[1].int_time, expected 179, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 238, + "incorrect value for acq_sv_profile[1].job_type, expected 238, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.reserved, 0, + "incorrect value for acq_sv_profile[1].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[1].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 38, + "incorrect value for acq_sv_profile[1].status, expected 38, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 234, + "incorrect value for acq_sv_profile[1].time_spent, expected 234, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 166, + "incorrect value for acq_sv_profile[1].timestamp, expected 166, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 52, + "incorrect value for acq_sv_profile[2].bin_width, expected 52, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 212, + "incorrect value for acq_sv_profile[2].cf, expected 212, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 248, + "incorrect value for acq_sv_profile[2].cf_max, expected 248, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 76, + "incorrect value for acq_sv_profile[2].cf_min, expected 76, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 68, + "incorrect value for acq_sv_profile[2].cn0, expected 68, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 101, + "incorrect value for acq_sv_profile[2].cp, expected 101, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 53, + "incorrect value for acq_sv_profile[2].int_time, expected 53, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 142, + "incorrect value for acq_sv_profile[2].job_type, expected 142, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.reserved, 0, + "incorrect value for acq_sv_profile[2].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[2].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 213, + "incorrect value for acq_sv_profile[2].status, expected 213, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 245, + "incorrect value for acq_sv_profile[2].time_spent, expected 245, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 49, + "incorrect value for acq_sv_profile[2].timestamp, expected 49, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfileDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_acquisition_msg_acq_sv_profile_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_acquisition_msg_acq_sv_profile_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 30, 0, 195, 4, 105, 67, 103, 151, 0, 12, 22, 0, 0, 0, 187, 0, 91, 0, 0, 0, 75, 0, + 0, 0, 132, 0, 0, 0, 36, 0, 0, 0, 60, 0, 0, 0, 241, 0, 0, 0, 238, 38, 111, 0, 179, 23, + 0, 1, 0, 176, 0, 166, 0, 0, 0, 234, 0, 0, 0, 155, 0, 0, 0, 24, 0, 0, 0, 212, 0, 0, 0, + 247, 0, 0, 0, 142, 213, 68, 0, 53, 24, 0, 0, 0, 52, 0, 49, 0, 0, 0, 245, 0, 0, 0, 76, + 0, 0, 0, 248, 0, 0, 0, 212, 0, 0, 0, 101, 0, 0, 0, 67, 132, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAcqSvProfileDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAcqSvProfileDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1e, + "Incorrect message type, expected 0x1e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.acq_sv_profile[0].bin_width, 187, + "incorrect value for acq_sv_profile[0].bin_width, expected 187, is {}", + msg.acq_sv_profile[0].bin_width + ); + assert_eq!( + msg.acq_sv_profile[0].cf, 60, + "incorrect value for acq_sv_profile[0].cf, expected 60, is {}", + msg.acq_sv_profile[0].cf + ); + assert_eq!( + msg.acq_sv_profile[0].cf_max, 36, + "incorrect value for acq_sv_profile[0].cf_max, expected 36, is {}", + msg.acq_sv_profile[0].cf_max + ); + assert_eq!( + msg.acq_sv_profile[0].cf_min, 132, + "incorrect value for acq_sv_profile[0].cf_min, expected 132, is {}", + msg.acq_sv_profile[0].cf_min + ); + assert_eq!( + msg.acq_sv_profile[0].cn0, 151, + "incorrect value for acq_sv_profile[0].cn0, expected 151, is {}", + msg.acq_sv_profile[0].cn0 + ); + assert_eq!( + msg.acq_sv_profile[0].cp, 241, + "incorrect value for acq_sv_profile[0].cp, expected 241, is {}", + msg.acq_sv_profile[0].cp + ); + assert_eq!( + msg.acq_sv_profile[0].int_time, 12, + "incorrect value for acq_sv_profile[0].int_time, expected 12, is {}", + msg.acq_sv_profile[0].int_time + ); + assert_eq!( + msg.acq_sv_profile[0].job_type, 67, + "incorrect value for acq_sv_profile[0].job_type, expected 67, is {}", + msg.acq_sv_profile[0].job_type + ); + assert_eq!( + msg.acq_sv_profile[0].sid.code, 0, + "incorrect value for acq_sv_profile[0].sid.code, expected 0, is {}", + msg.acq_sv_profile[0].sid.code + ); + assert_eq!( + msg.acq_sv_profile[0].sid.reserved, 0, + "incorrect value for acq_sv_profile[0].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[0].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[0].sid.sat, 22, + "incorrect value for acq_sv_profile[0].sid.sat, expected 22, is {}", + msg.acq_sv_profile[0].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[0].status, 103, + "incorrect value for acq_sv_profile[0].status, expected 103, is {}", + msg.acq_sv_profile[0].status + ); + assert_eq!( + msg.acq_sv_profile[0].time_spent, 75, + "incorrect value for acq_sv_profile[0].time_spent, expected 75, is {}", + msg.acq_sv_profile[0].time_spent + ); + assert_eq!( + msg.acq_sv_profile[0].timestamp, 91, + "incorrect value for acq_sv_profile[0].timestamp, expected 91, is {}", + msg.acq_sv_profile[0].timestamp + ); + assert_eq!( + msg.acq_sv_profile[1].bin_width, 176, + "incorrect value for acq_sv_profile[1].bin_width, expected 176, is {}", + msg.acq_sv_profile[1].bin_width + ); + assert_eq!( + msg.acq_sv_profile[1].cf, 212, + "incorrect value for acq_sv_profile[1].cf, expected 212, is {}", + msg.acq_sv_profile[1].cf + ); + assert_eq!( + msg.acq_sv_profile[1].cf_max, 24, + "incorrect value for acq_sv_profile[1].cf_max, expected 24, is {}", + msg.acq_sv_profile[1].cf_max + ); + assert_eq!( + msg.acq_sv_profile[1].cf_min, 155, + "incorrect value for acq_sv_profile[1].cf_min, expected 155, is {}", + msg.acq_sv_profile[1].cf_min + ); + assert_eq!( + msg.acq_sv_profile[1].cn0, 111, + "incorrect value for acq_sv_profile[1].cn0, expected 111, is {}", + msg.acq_sv_profile[1].cn0 + ); + assert_eq!( + msg.acq_sv_profile[1].cp, 247, + "incorrect value for acq_sv_profile[1].cp, expected 247, is {}", + msg.acq_sv_profile[1].cp + ); + assert_eq!( + msg.acq_sv_profile[1].int_time, 179, + "incorrect value for acq_sv_profile[1].int_time, expected 179, is {}", + msg.acq_sv_profile[1].int_time + ); + assert_eq!( + msg.acq_sv_profile[1].job_type, 238, + "incorrect value for acq_sv_profile[1].job_type, expected 238, is {}", + msg.acq_sv_profile[1].job_type + ); + assert_eq!( + msg.acq_sv_profile[1].sid.code, 1, + "incorrect value for acq_sv_profile[1].sid.code, expected 1, is {}", + msg.acq_sv_profile[1].sid.code + ); + assert_eq!( + msg.acq_sv_profile[1].sid.reserved, 0, + "incorrect value for acq_sv_profile[1].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[1].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[1].sid.sat, 23, + "incorrect value for acq_sv_profile[1].sid.sat, expected 23, is {}", + msg.acq_sv_profile[1].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[1].status, 38, + "incorrect value for acq_sv_profile[1].status, expected 38, is {}", + msg.acq_sv_profile[1].status + ); + assert_eq!( + msg.acq_sv_profile[1].time_spent, 234, + "incorrect value for acq_sv_profile[1].time_spent, expected 234, is {}", + msg.acq_sv_profile[1].time_spent + ); + assert_eq!( + msg.acq_sv_profile[1].timestamp, 166, + "incorrect value for acq_sv_profile[1].timestamp, expected 166, is {}", + msg.acq_sv_profile[1].timestamp + ); + assert_eq!( + msg.acq_sv_profile[2].bin_width, 52, + "incorrect value for acq_sv_profile[2].bin_width, expected 52, is {}", + msg.acq_sv_profile[2].bin_width + ); + assert_eq!( + msg.acq_sv_profile[2].cf, 212, + "incorrect value for acq_sv_profile[2].cf, expected 212, is {}", + msg.acq_sv_profile[2].cf + ); + assert_eq!( + msg.acq_sv_profile[2].cf_max, 248, + "incorrect value for acq_sv_profile[2].cf_max, expected 248, is {}", + msg.acq_sv_profile[2].cf_max + ); + assert_eq!( + msg.acq_sv_profile[2].cf_min, 76, + "incorrect value for acq_sv_profile[2].cf_min, expected 76, is {}", + msg.acq_sv_profile[2].cf_min + ); + assert_eq!( + msg.acq_sv_profile[2].cn0, 68, + "incorrect value for acq_sv_profile[2].cn0, expected 68, is {}", + msg.acq_sv_profile[2].cn0 + ); + assert_eq!( + msg.acq_sv_profile[2].cp, 101, + "incorrect value for acq_sv_profile[2].cp, expected 101, is {}", + msg.acq_sv_profile[2].cp + ); + assert_eq!( + msg.acq_sv_profile[2].int_time, 53, + "incorrect value for acq_sv_profile[2].int_time, expected 53, is {}", + msg.acq_sv_profile[2].int_time + ); + assert_eq!( + msg.acq_sv_profile[2].job_type, 142, + "incorrect value for acq_sv_profile[2].job_type, expected 142, is {}", + msg.acq_sv_profile[2].job_type + ); + assert_eq!( + msg.acq_sv_profile[2].sid.code, 0, + "incorrect value for acq_sv_profile[2].sid.code, expected 0, is {}", + msg.acq_sv_profile[2].sid.code + ); + assert_eq!( + msg.acq_sv_profile[2].sid.reserved, 0, + "incorrect value for acq_sv_profile[2].sid.reserved, expected 0, is {}", + msg.acq_sv_profile[2].sid.reserved + ); + assert_eq!( + msg.acq_sv_profile[2].sid.sat, 24, + "incorrect value for acq_sv_profile[2].sid.sat, expected 24, is {}", + msg.acq_sv_profile[2].sid.sat + ); + assert_eq!( + msg.acq_sv_profile[2].status, 213, + "incorrect value for acq_sv_profile[2].status, expected 213, is {}", + msg.acq_sv_profile[2].status + ); + assert_eq!( + msg.acq_sv_profile[2].time_spent, 245, + "incorrect value for acq_sv_profile[2].time_spent, expected 245, is {}", + msg.acq_sv_profile[2].time_spent + ); + assert_eq!( + msg.acq_sv_profile[2].timestamp, 49, + "incorrect value for acq_sv_profile[2].timestamp, expected 49, is {}", + msg.acq_sv_profile[2].timestamp + ); + } + _ => panic!("Invalid message type! Expected a MsgAcqSvProfileDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_handshake_req.rs b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_handshake_req.rs new file mode 100644 index 0000000000..322aa4ad28 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_handshake_req.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_bootload_msg_bootloader_handshake_req() { + { + let mut payload = Cursor::new(vec![85, 179, 0, 136, 247, 0, 65, 216]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderHandshakeReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb3, + "Incorrect message type, expected 0xb3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf788, + "incorrect sender id, expected 0xf788, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderHandshakeReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_bootload_msg_bootloader_handshake_req() { + { + let json_input = + r#"{"crc":55361,"length":0,"msg_type":179,"payload":"","preamble":85,"sender":63368}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderHandshakeReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb3, + "Incorrect message type, expected 0xb3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf788, + "incorrect sender id, expected 0xf788, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderHandshakeReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_bootload_msg_bootloader_handshake_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_bootload_msg_bootloader_handshake_req() { + { + let mut payload = Cursor::new(vec![85, 179, 0, 136, 247, 0, 65, 216]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgBootloaderHandshakeReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderHandshakeReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb3, + "Incorrect message type, expected 0xb3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf788, + "incorrect sender id, expected 0xf788, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderHandshakeReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_jumpto_app.rs b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_jumpto_app.rs new file mode 100644 index 0000000000..2257d06ac6 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_bootloader_jumpto_app.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_bootload_msg_bootloader_jumpto_app() { + { + let mut payload = Cursor::new(vec![85, 177, 0, 205, 18, 1, 216, 105, 96]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderJumpToApp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb1, + "Incorrect message type, expected 0xb1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x12cd, + "incorrect sender id, expected 0x12cd, is {sender_id}" + ); + assert_eq!( + msg.jump, 216, + "incorrect value for jump, expected 216, is {}", + msg.jump + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderJumpToApp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_bootload_msg_bootloader_jumpto_app() { + { + let json_input = r#"{"crc":24681,"length":1,"msg_type":177,"payload":"2A==","preamble":85,"sender":4813,"jump":216}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderJumpToApp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb1, + "Incorrect message type, expected 0xb1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x12cd, + "incorrect sender id, expected 0x12cd, is {sender_id}" + ); + assert_eq!( + msg.jump, 216, + "incorrect value for jump, expected 216, is {}", + msg.jump + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderJumpToApp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_bootload_msg_bootloader_jumpto_app`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_bootload_msg_bootloader_jumpto_app() { + { + let mut payload = Cursor::new(vec![85, 177, 0, 205, 18, 1, 216, 105, 96]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgBootloaderJumpToApp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgBootloaderJumpToApp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb1, + "Incorrect message type, expected 0xb1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x12cd, + "incorrect sender id, expected 0x12cd, is {sender_id}" + ); + assert_eq!( + msg.jump, 216, + "incorrect value for jump, expected 216, is {}", + msg.jump + ); + } + _ => panic!("Invalid message type! Expected a MsgBootloaderJumpToApp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_req.rs b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_req.rs new file mode 100644 index 0000000000..b96d9450d3 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_req.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_bootload_msg_nap_device_dna_req() { + { + let mut payload = Cursor::new(vec![85, 222, 0, 128, 50, 0, 231, 160]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xde, + "Incorrect message type, expected 0xde, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3280, + "incorrect sender id, expected 0x3280, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_bootload_msg_nap_device_dna_req() { + { + let json_input = + r#"{"crc":41191,"length":0,"msg_type":222,"payload":"","preamble":85,"sender":12928}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xde, + "Incorrect message type, expected 0xde, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3280, + "incorrect sender id, expected 0x3280, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_bootload_msg_nap_device_dna_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_bootload_msg_nap_device_dna_req() { + { + let mut payload = Cursor::new(vec![85, 222, 0, 128, 50, 0, 231, 160]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgNapDeviceDnaReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xde, + "Incorrect message type, expected 0xde, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3280, + "incorrect sender id, expected 0x3280, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_resp.rs new file mode 100644 index 0000000000..39948ed50a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_bootload_msg_nap_device_dna_resp.rs @@ -0,0 +1,287 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_bootload_msg_nap_device_dna_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xdd, + "Incorrect message type, expected 0xdd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x38a9, + "incorrect sender id, expected 0x38a9, is {sender_id}" + ); + assert_eq!( + msg.dna[0], 2, + "incorrect value for dna[0], expected 2, is {}", + msg.dna[0] + ); + assert_eq!( + msg.dna[1], 187, + "incorrect value for dna[1], expected 187, is {}", + msg.dna[1] + ); + assert_eq!( + msg.dna[2], 1, + "incorrect value for dna[2], expected 1, is {}", + msg.dna[2] + ); + assert_eq!( + msg.dna[3], 130, + "incorrect value for dna[3], expected 130, is {}", + msg.dna[3] + ); + assert_eq!( + msg.dna[4], 173, + "incorrect value for dna[4], expected 173, is {}", + msg.dna[4] + ); + assert_eq!( + msg.dna[5], 244, + "incorrect value for dna[5], expected 244, is {}", + msg.dna[5] + ); + assert_eq!( + msg.dna[6], 67, + "incorrect value for dna[6], expected 67, is {}", + msg.dna[6] + ); + assert_eq!( + msg.dna[7], 122, + "incorrect value for dna[7], expected 122, is {}", + msg.dna[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_bootload_msg_nap_device_dna_resp() { + { + let json_input = r#"{"crc":23366,"length":8,"msg_type":221,"payload":"ArsBgq30Q3o=","preamble":85,"sender":14505,"dna":[2,187,1,130,173,244,67,122]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xdd, + "Incorrect message type, expected 0xdd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x38a9, + "incorrect sender id, expected 0x38a9, is {sender_id}" + ); + assert_eq!( + msg.dna[0], 2, + "incorrect value for dna[0], expected 2, is {}", + msg.dna[0] + ); + assert_eq!( + msg.dna[1], 187, + "incorrect value for dna[1], expected 187, is {}", + msg.dna[1] + ); + assert_eq!( + msg.dna[2], 1, + "incorrect value for dna[2], expected 1, is {}", + msg.dna[2] + ); + assert_eq!( + msg.dna[3], 130, + "incorrect value for dna[3], expected 130, is {}", + msg.dna[3] + ); + assert_eq!( + msg.dna[4], 173, + "incorrect value for dna[4], expected 173, is {}", + msg.dna[4] + ); + assert_eq!( + msg.dna[5], 244, + "incorrect value for dna[5], expected 244, is {}", + msg.dna[5] + ); + assert_eq!( + msg.dna[6], 67, + "incorrect value for dna[6], expected 67, is {}", + msg.dna[6] + ); + assert_eq!( + msg.dna[7], 122, + "incorrect value for dna[7], expected 122, is {}", + msg.dna[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_bootload_msg_nap_device_dna_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_bootload_msg_nap_device_dna_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 221, 0, 169, 56, 8, 2, 187, 1, 130, 173, 244, 67, 122, 70, 91, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgNapDeviceDnaResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgNapDeviceDnaResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xdd, + "Incorrect message type, expected 0xdd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x38a9, + "incorrect sender id, expected 0x38a9, is {sender_id}" + ); + assert_eq!( + msg.dna[0], 2, + "incorrect value for dna[0], expected 2, is {}", + msg.dna[0] + ); + assert_eq!( + msg.dna[1], 187, + "incorrect value for dna[1], expected 187, is {}", + msg.dna[1] + ); + assert_eq!( + msg.dna[2], 1, + "incorrect value for dna[2], expected 1, is {}", + msg.dna[2] + ); + assert_eq!( + msg.dna[3], 130, + "incorrect value for dna[3], expected 130, is {}", + msg.dna[3] + ); + assert_eq!( + msg.dna[4], 173, + "incorrect value for dna[4], expected 173, is {}", + msg.dna[4] + ); + assert_eq!( + msg.dna[5], 244, + "incorrect value for dna[5], expected 244, is {}", + msg.dna[5] + ); + assert_eq!( + msg.dna[6], 67, + "incorrect value for dna[6], expected 67, is {}", + msg.dna[6] + ); + assert_eq!( + msg.dna[7], 122, + "incorrect value for dna[7], expected 122, is {}", + msg.dna[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgNapDeviceDnaResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_req.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_req.rs new file mode 100644 index 0000000000..3bc13da59c --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_req.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_config_req() { + { + let mut payload = Cursor::new(vec![85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1001, + "Incorrect message type, expected 0x1001, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sequence, 1514527339, + "incorrect value for sequence, expected 1514527339, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_config_req() { + { + let json_input = r#"{"preamble":85,"msg_type":4097,"sender":1219,"length":4,"payload":"a9pFWg==","crc":7097,"sequence":1514527339}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1001, + "Incorrect message type, expected 0x1001, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sequence, 1514527339, + "incorrect value for sequence, expected 1514527339, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_config_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_config_req() { + { + let mut payload = Cursor::new(vec![85, 1, 16, 195, 4, 4, 107, 218, 69, 90, 185, 27]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioConfigReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1001, + "Incorrect message type, expected 0x1001, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sequence, 1514527339, + "incorrect value for sequence, expected 1514527339, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_resp.rs new file mode 100644 index 0000000000..05bc47c424 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_config_resp.rs @@ -0,0 +1,229 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_config_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, 44, 3, 216, 151, 255, 61, 12, 97, 66, + 144, 239, 115, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1002, + "Incorrect message type, expected 0x1002, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.batch_size, 1040160728, + "incorrect value for batch_size, expected 1040160728, is {}", + msg.batch_size + ); + assert_eq!( + msg.fileio_version, 2420269324, + "incorrect value for fileio_version, expected 2420269324, is {}", + msg.fileio_version + ); + assert_eq!( + msg.sequence, 1530154154, + "incorrect value for sequence, expected 1530154154, is {}", + msg.sequence + ); + assert_eq!( + msg.window_size, 53262997, + "incorrect value for window_size, expected 53262997, is {}", + msg.window_size + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_config_resp() { + { + let json_input = r#"{"preamble":85,"msg_type":4098,"sender":1219,"length":16,"payload":"qkw0W5W6LAPYl/89DGFCkA==","crc":29679,"sequence":1530154154,"window_size":53262997,"batch_size":1040160728,"fileio_version":2420269324}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1002, + "Incorrect message type, expected 0x1002, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.batch_size, 1040160728, + "incorrect value for batch_size, expected 1040160728, is {}", + msg.batch_size + ); + assert_eq!( + msg.fileio_version, 2420269324, + "incorrect value for fileio_version, expected 2420269324, is {}", + msg.fileio_version + ); + assert_eq!( + msg.sequence, 1530154154, + "incorrect value for sequence, expected 1530154154, is {}", + msg.sequence + ); + assert_eq!( + msg.window_size, 53262997, + "incorrect value for window_size, expected 53262997, is {}", + msg.window_size + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_config_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_config_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 16, 195, 4, 16, 170, 76, 52, 91, 149, 186, 44, 3, 216, 151, 255, 61, 12, 97, 66, + 144, 239, 115, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioConfigResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioConfigResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1002, + "Incorrect message type, expected 0x1002, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.batch_size, 1040160728, + "incorrect value for batch_size, expected 1040160728, is {}", + msg.batch_size + ); + assert_eq!( + msg.fileio_version, 2420269324, + "incorrect value for fileio_version, expected 2420269324, is {}", + msg.fileio_version + ); + assert_eq!( + msg.sequence, 1530154154, + "incorrect value for sequence, expected 1530154154, is {}", + msg.sequence + ); + assert_eq!( + msg.window_size, 53262997, + "incorrect value for window_size, expected 53262997, is {}", + msg.window_size + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioConfigResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_req.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_req.rs new file mode 100644 index 0000000000..579f17e4c1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_req.rs @@ -0,0 +1,238 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_read_dir_req() { + { + let mut payload = Cursor::new(vec![ + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, 47, 134, 47, 115, 111, 109, 101, + 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa9, + "Incorrect message type, expected 0xa9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.dirname.as_bytes(), + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + "incorrect value for msg.dirname, expected string '{:?}', is '{:?}'", + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + msg.dirname.as_bytes() + ); + assert_eq!( + msg.offset, 2251261636, + "incorrect value for offset, expected 2251261636, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 1526720386, + "incorrect value for sequence, expected 1526720386, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_read_dir_req() { + { + let json_input = r#"{"preamble":85,"msg_type":169,"sender":1219,"length":26,"payload":"guf/WsSGL4Yvc29tZS9yYW5kb20vcGF0aAA=","crc":47642,"sequence":1526720386,"offset":2251261636,"dirname":"/some/random/path\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa9, + "Incorrect message type, expected 0xa9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.dirname.as_bytes(), + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + "incorrect value for msg.dirname, expected string '{:?}', is '{:?}'", + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + msg.dirname.as_bytes() + ); + assert_eq!( + msg.offset, 2251261636, + "incorrect value for offset, expected 2251261636, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 1526720386, + "incorrect value for sequence, expected 1526720386, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_read_dir_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_read_dir_req() { + { + let mut payload = Cursor::new(vec![ + 85, 169, 0, 195, 4, 26, 130, 231, 255, 90, 196, 134, 47, 134, 47, 115, 111, 109, 101, + 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, 104, 0, 26, 186, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioReadDirReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa9, + "Incorrect message type, expected 0xa9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.dirname.as_bytes(), + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + "incorrect value for msg.dirname, expected string '{:?}', is '{:?}'", + &[ + 47, 115, 111, 109, 101, 47, 114, 97, 110, 100, 111, 109, 47, 112, 97, 116, + 104, 0 + ], + msg.dirname.as_bytes() + ); + assert_eq!( + msg.offset, 2251261636, + "incorrect value for offset, expected 2251261636, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 1526720386, + "incorrect value for sequence, expected 1526720386, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_resp.rs new file mode 100644 index 0000000000..c01176b31d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_dir_resp.rs @@ -0,0 +1,231 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_read_dir_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, 49, 0, 97, 110, 111, + 116, 104, 101, 114, 32, 102, 105, 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, + 108, 121, 32, 110, 111, 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaa, + "Incorrect message type, expected 0xaa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents.as_bytes(), + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + "incorrect value for msg.contents, expected string '{:?}', is '{:?}'", + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + msg.contents.as_bytes() + ); + assert_eq!( + msg.sequence, 3957390670, + "incorrect value for sequence, expected 3957390670, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_read_dir_resp() { + { + let json_input = r#"{"preamble":85,"msg_type":170,"sender":1219,"length":45,"payload":"Tv3g62ZpbGUxAGFub3RoZXIgZmlsZQBkZWZpbml0ZWx5IG5vdCBhIGZpbGUA","crc":35258,"sequence":3957390670,"contents":"file1\u0000another file\u0000definitely not a file\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaa, + "Incorrect message type, expected 0xaa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents.as_bytes(), + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + "incorrect value for msg.contents, expected string '{:?}', is '{:?}'", + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + msg.contents.as_bytes() + ); + assert_eq!( + msg.sequence, 3957390670, + "incorrect value for sequence, expected 3957390670, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_read_dir_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_read_dir_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 170, 0, 195, 4, 45, 78, 253, 224, 235, 102, 105, 108, 101, 49, 0, 97, 110, 111, + 116, 104, 101, 114, 32, 102, 105, 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, + 108, 121, 32, 110, 111, 116, 32, 97, 32, 102, 105, 108, 101, 0, 186, 137, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioReadDirResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadDirResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaa, + "Incorrect message type, expected 0xaa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents.as_bytes(), + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + "incorrect value for msg.contents, expected string '{:?}', is '{:?}'", + &[ + 102, 105, 108, 101, 49, 0, 97, 110, 111, 116, 104, 101, 114, 32, 102, 105, + 108, 101, 0, 100, 101, 102, 105, 110, 105, 116, 101, 108, 121, 32, 110, + 111, 116, 32, 97, 32, 102, 105, 108, 101, 0 + ], + msg.contents.as_bytes() + ); + assert_eq!( + msg.sequence, 3957390670, + "incorrect value for sequence, expected 3957390670, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadDirResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_req.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_req.rs new file mode 100644 index 0000000000..220e0a98a0 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_req.rs @@ -0,0 +1,253 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_read_req() { + { + let mut payload = Cursor::new(vec![ + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, 190, 23, 53, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa8, + "Incorrect message type, expected 0xa8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.chunk_size, 53, + "incorrect value for chunk_size, expected 53, is {}", + msg.chunk_size + ); + assert_eq!( + msg.filename.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + msg.filename.as_bytes() + ); + assert_eq!( + msg.offset, 398373474, + "incorrect value for offset, expected 398373474, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 679648290, + "incorrect value for sequence, expected 679648290, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_read_req() { + { + let json_input = r#"{"crc":25686,"length":28,"msg_type":168,"payload":"IpyCKGKyvhc1L3BhdGgvdG8vc29tZS9maWxlAA==","preamble":85,"sender":1219,"sequence":679648290,"offset":398373474,"chunk_size":53,"filename":"/path/to/some/file\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa8, + "Incorrect message type, expected 0xa8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.chunk_size, 53, + "incorrect value for chunk_size, expected 53, is {}", + msg.chunk_size + ); + assert_eq!( + msg.filename.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + msg.filename.as_bytes() + ); + assert_eq!( + msg.offset, 398373474, + "incorrect value for offset, expected 398373474, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 679648290, + "incorrect value for sequence, expected 679648290, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_read_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_read_req() { + { + let mut payload = Cursor::new(vec![ + 85, 168, 0, 195, 4, 28, 34, 156, 130, 40, 98, 178, 190, 23, 53, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, 108, 101, 0, 86, 100, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioReadReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa8, + "Incorrect message type, expected 0xa8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.chunk_size, 53, + "incorrect value for chunk_size, expected 53, is {}", + msg.chunk_size + ); + assert_eq!( + msg.filename.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 115, 111, 109, 101, 47, 102, 105, + 108, 101, 0 + ], + msg.filename.as_bytes() + ); + assert_eq!( + msg.offset, 398373474, + "incorrect value for offset, expected 398373474, is {}", + msg.offset + ); + assert_eq!( + msg.sequence, 679648290, + "incorrect value for sequence, expected 679648290, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_resp.rs new file mode 100644 index 0000000000..ca353dc406 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_read_resp.rs @@ -0,0 +1,3973 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, 18, 76, 68, 229, 216, 21, + 98, 183, 69, 190, 5, 252, 176, 55, 32, 78, 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, + 46, 79, 118, 248, 118, 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, 206, 185, + 140, 249, 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, 77, 224, 124, 238, 205, 65, + 103, 35, 104, 209, 5, 191, 47, 249, 176, 166, 213, 46, 192, 86, 32, 103, 146, 252, 4, + 16, 54, 161, 60, 6, 13, 191, 116, 182, 42, 191, 213, 20, 217, 8, 142, 187, 238, 120, + 184, 250, 31, 151, 37, 51, 177, 130, 190, 155, 71, 68, 56, 238, 92, 130, 37, 137, 146, + 246, 114, 116, 138, 165, 217, 79, 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, 236, + 228, 194, 0, 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, 3, 240, 205, 253, 113, 25, + 28, 187, 81, 101, 216, 121, 41, 179, 120, 152, 18, 116, 53, 212, 100, 2, 114, 198, 200, + 10, 147, 25, 33, 115, 208, 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, + 133, 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, 180, 180, 125, 97, + 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, 65, 4, 64, 19, 74, 223, 111, 109, 52, 43, + 167, 186, 202, 111, 11, 91, 21, 236, 234, 196, 36, 171, 147, 10, 240, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa3, + "Incorrect message type, expected 0xa3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 73, + "incorrect value for contents[0], expected 73, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 231, + "incorrect value for contents[1], expected 231, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 227, + "incorrect value for contents[2], expected 227, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 179, + "incorrect value for contents[3], expected 179, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 18, + "incorrect value for contents[4], expected 18, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 76, + "incorrect value for contents[5], expected 76, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 68, + "incorrect value for contents[6], expected 68, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 229, + "incorrect value for contents[7], expected 229, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 216, + "incorrect value for contents[8], expected 216, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 21, + "incorrect value for contents[9], expected 21, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 98, + "incorrect value for contents[10], expected 98, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 183, + "incorrect value for contents[11], expected 183, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 69, + "incorrect value for contents[12], expected 69, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 190, + "incorrect value for contents[13], expected 190, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 5, + "incorrect value for contents[14], expected 5, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 252, + "incorrect value for contents[15], expected 252, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 176, + "incorrect value for contents[16], expected 176, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 55, + "incorrect value for contents[17], expected 55, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 32, + "incorrect value for contents[18], expected 32, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 78, + "incorrect value for contents[19], expected 78, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 8, + "incorrect value for contents[20], expected 8, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 52, + "incorrect value for contents[21], expected 52, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 127, + "incorrect value for contents[22], expected 127, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 50, + "incorrect value for contents[23], expected 50, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 71, + "incorrect value for contents[24], expected 71, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 106, + "incorrect value for contents[25], expected 106, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 61, + "incorrect value for contents[26], expected 61, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 79, + "incorrect value for contents[27], expected 79, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 191, + "incorrect value for contents[28], expected 191, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 106, + "incorrect value for contents[29], expected 106, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 46, + "incorrect value for contents[30], expected 46, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 79, + "incorrect value for contents[31], expected 79, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 118, + "incorrect value for contents[32], expected 118, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 248, + "incorrect value for contents[33], expected 248, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 118, + "incorrect value for contents[34], expected 118, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 207, + "incorrect value for contents[35], expected 207, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 206, + "incorrect value for contents[36], expected 206, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 210, + "incorrect value for contents[37], expected 210, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 91, + "incorrect value for contents[38], expected 91, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 73, + "incorrect value for contents[39], expected 73, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 251, + "incorrect value for contents[40], expected 251, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 81, + "incorrect value for contents[41], expected 81, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 131, + "incorrect value for contents[42], expected 131, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 205, + "incorrect value for contents[43], expected 205, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 193, + "incorrect value for contents[44], expected 193, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 146, + "incorrect value for contents[45], expected 146, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 206, + "incorrect value for contents[46], expected 206, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 185, + "incorrect value for contents[47], expected 185, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 140, + "incorrect value for contents[48], expected 140, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 249, + "incorrect value for contents[49], expected 249, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 163, + "incorrect value for contents[50], expected 163, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 231, + "incorrect value for contents[51], expected 231, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 65, + "incorrect value for contents[52], expected 65, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 67, + "incorrect value for contents[53], expected 67, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 94, + "incorrect value for contents[54], expected 94, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 250, + "incorrect value for contents[55], expected 250, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 109, + "incorrect value for contents[56], expected 109, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 152, + "incorrect value for contents[57], expected 152, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 95, + "incorrect value for contents[58], expected 95, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 123, + "incorrect value for contents[59], expected 123, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 77, + "incorrect value for contents[60], expected 77, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 224, + "incorrect value for contents[61], expected 224, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 124, + "incorrect value for contents[62], expected 124, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 238, + "incorrect value for contents[63], expected 238, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 205, + "incorrect value for contents[64], expected 205, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 65, + "incorrect value for contents[65], expected 65, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 103, + "incorrect value for contents[66], expected 103, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 35, + "incorrect value for contents[67], expected 35, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 104, + "incorrect value for contents[68], expected 104, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 209, + "incorrect value for contents[69], expected 209, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 5, + "incorrect value for contents[70], expected 5, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 191, + "incorrect value for contents[71], expected 191, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 47, + "incorrect value for contents[72], expected 47, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 249, + "incorrect value for contents[73], expected 249, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 176, + "incorrect value for contents[74], expected 176, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 166, + "incorrect value for contents[75], expected 166, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 213, + "incorrect value for contents[76], expected 213, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 46, + "incorrect value for contents[77], expected 46, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 192, + "incorrect value for contents[78], expected 192, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 86, + "incorrect value for contents[79], expected 86, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 32, + "incorrect value for contents[80], expected 32, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 103, + "incorrect value for contents[81], expected 103, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 146, + "incorrect value for contents[82], expected 146, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 252, + "incorrect value for contents[83], expected 252, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 4, + "incorrect value for contents[84], expected 4, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 16, + "incorrect value for contents[85], expected 16, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 54, + "incorrect value for contents[86], expected 54, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 161, + "incorrect value for contents[87], expected 161, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 60, + "incorrect value for contents[88], expected 60, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 6, + "incorrect value for contents[89], expected 6, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 13, + "incorrect value for contents[90], expected 13, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 191, + "incorrect value for contents[91], expected 191, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 116, + "incorrect value for contents[92], expected 116, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 182, + "incorrect value for contents[93], expected 182, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 42, + "incorrect value for contents[94], expected 42, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 191, + "incorrect value for contents[95], expected 191, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 213, + "incorrect value for contents[96], expected 213, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 20, + "incorrect value for contents[97], expected 20, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 217, + "incorrect value for contents[98], expected 217, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 8, + "incorrect value for contents[99], expected 8, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 142, + "incorrect value for contents[100], expected 142, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 187, + "incorrect value for contents[101], expected 187, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 238, + "incorrect value for contents[102], expected 238, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 120, + "incorrect value for contents[103], expected 120, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 184, + "incorrect value for contents[104], expected 184, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 250, + "incorrect value for contents[105], expected 250, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 31, + "incorrect value for contents[106], expected 31, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 151, + "incorrect value for contents[107], expected 151, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 37, + "incorrect value for contents[108], expected 37, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 51, + "incorrect value for contents[109], expected 51, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 177, + "incorrect value for contents[110], expected 177, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 130, + "incorrect value for contents[111], expected 130, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 190, + "incorrect value for contents[112], expected 190, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 155, + "incorrect value for contents[113], expected 155, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 71, + "incorrect value for contents[114], expected 71, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 68, + "incorrect value for contents[115], expected 68, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 56, + "incorrect value for contents[116], expected 56, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 238, + "incorrect value for contents[117], expected 238, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 92, + "incorrect value for contents[118], expected 92, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 130, + "incorrect value for contents[119], expected 130, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 37, + "incorrect value for contents[120], expected 37, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 137, + "incorrect value for contents[121], expected 137, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 146, + "incorrect value for contents[122], expected 146, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 246, + "incorrect value for contents[123], expected 246, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 114, + "incorrect value for contents[124], expected 114, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 116, + "incorrect value for contents[125], expected 116, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 138, + "incorrect value for contents[126], expected 138, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 165, + "incorrect value for contents[127], expected 165, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 217, + "incorrect value for contents[128], expected 217, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 79, + "incorrect value for contents[129], expected 79, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 10, + "incorrect value for contents[130], expected 10, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 189, + "incorrect value for contents[131], expected 189, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 128, + "incorrect value for contents[132], expected 128, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 189, + "incorrect value for contents[133], expected 189, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 2, + "incorrect value for contents[134], expected 2, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 240, + "incorrect value for contents[135], expected 240, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 92, + "incorrect value for contents[136], expected 92, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 28, + "incorrect value for contents[137], expected 28, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 126, + "incorrect value for contents[138], expected 126, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 105, + "incorrect value for contents[139], expected 105, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 236, + "incorrect value for contents[140], expected 236, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 228, + "incorrect value for contents[141], expected 228, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 194, + "incorrect value for contents[142], expected 194, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 0, + "incorrect value for contents[143], expected 0, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 51, + "incorrect value for contents[144], expected 51, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 61, + "incorrect value for contents[145], expected 61, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 74, + "incorrect value for contents[146], expected 74, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 41, + "incorrect value for contents[147], expected 41, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 10, + "incorrect value for contents[148], expected 10, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 239, + "incorrect value for contents[149], expected 239, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 133, + "incorrect value for contents[150], expected 133, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 106, + "incorrect value for contents[151], expected 106, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 190, + "incorrect value for contents[152], expected 190, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 30, + "incorrect value for contents[153], expected 30, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 27, + "incorrect value for contents[154], expected 27, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 3, + "incorrect value for contents[155], expected 3, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 240, + "incorrect value for contents[156], expected 240, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 205, + "incorrect value for contents[157], expected 205, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 253, + "incorrect value for contents[158], expected 253, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 113, + "incorrect value for contents[159], expected 113, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 25, + "incorrect value for contents[160], expected 25, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 28, + "incorrect value for contents[161], expected 28, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 187, + "incorrect value for contents[162], expected 187, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 81, + "incorrect value for contents[163], expected 81, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 101, + "incorrect value for contents[164], expected 101, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 216, + "incorrect value for contents[165], expected 216, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 121, + "incorrect value for contents[166], expected 121, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 41, + "incorrect value for contents[167], expected 41, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 179, + "incorrect value for contents[168], expected 179, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 120, + "incorrect value for contents[169], expected 120, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 152, + "incorrect value for contents[170], expected 152, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 18, + "incorrect value for contents[171], expected 18, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 116, + "incorrect value for contents[172], expected 116, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 53, + "incorrect value for contents[173], expected 53, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 212, + "incorrect value for contents[174], expected 212, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 100, + "incorrect value for contents[175], expected 100, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 2, + "incorrect value for contents[176], expected 2, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 114, + "incorrect value for contents[177], expected 114, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 198, + "incorrect value for contents[178], expected 198, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 200, + "incorrect value for contents[179], expected 200, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 10, + "incorrect value for contents[180], expected 10, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 147, + "incorrect value for contents[181], expected 147, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 25, + "incorrect value for contents[182], expected 25, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 33, + "incorrect value for contents[183], expected 33, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 115, + "incorrect value for contents[184], expected 115, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 208, + "incorrect value for contents[185], expected 208, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 113, + "incorrect value for contents[186], expected 113, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 60, + "incorrect value for contents[187], expected 60, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 179, + "incorrect value for contents[188], expected 179, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 183, + "incorrect value for contents[189], expected 183, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 0, + "incorrect value for contents[190], expected 0, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 41, + "incorrect value for contents[191], expected 41, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 217, + "incorrect value for contents[192], expected 217, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 206, + "incorrect value for contents[193], expected 206, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 255, + "incorrect value for contents[194], expected 255, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 211, + "incorrect value for contents[195], expected 211, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 225, + "incorrect value for contents[196], expected 225, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 142, + "incorrect value for contents[197], expected 142, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 191, + "incorrect value for contents[198], expected 191, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 133, + "incorrect value for contents[199], expected 133, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 81, + "incorrect value for contents[200], expected 81, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 15, + "incorrect value for contents[201], expected 15, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 248, + "incorrect value for contents[202], expected 248, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 193, + "incorrect value for contents[203], expected 193, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 66, + "incorrect value for contents[204], expected 66, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 191, + "incorrect value for contents[205], expected 191, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 244, + "incorrect value for contents[206], expected 244, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 221, + "incorrect value for contents[207], expected 221, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 248, + "incorrect value for contents[208], expected 248, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 199, + "incorrect value for contents[209], expected 199, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 241, + "incorrect value for contents[210], expected 241, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 51, + "incorrect value for contents[212], expected 51, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 1, + "incorrect value for contents[213], expected 1, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 180, + "incorrect value for contents[214], expected 180, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 180, + "incorrect value for contents[215], expected 180, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 125, + "incorrect value for contents[216], expected 125, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 97, + "incorrect value for contents[217], expected 97, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 145, + "incorrect value for contents[218], expected 145, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 25, + "incorrect value for contents[219], expected 25, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 72, + "incorrect value for contents[220], expected 72, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 210, + "incorrect value for contents[221], expected 210, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 215, + "incorrect value for contents[222], expected 215, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 208, + "incorrect value for contents[223], expected 208, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 15, + "incorrect value for contents[224], expected 15, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 126, + "incorrect value for contents[225], expected 126, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 56, + "incorrect value for contents[226], expected 56, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 38, + "incorrect value for contents[227], expected 38, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 65, + "incorrect value for contents[228], expected 65, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 4, + "incorrect value for contents[229], expected 4, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 64, + "incorrect value for contents[230], expected 64, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 19, + "incorrect value for contents[231], expected 19, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 74, + "incorrect value for contents[232], expected 74, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 223, + "incorrect value for contents[233], expected 223, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 111, + "incorrect value for contents[234], expected 111, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 109, + "incorrect value for contents[235], expected 109, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 52, + "incorrect value for contents[236], expected 52, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 43, + "incorrect value for contents[237], expected 43, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 167, + "incorrect value for contents[238], expected 167, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 186, + "incorrect value for contents[239], expected 186, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 202, + "incorrect value for contents[240], expected 202, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 111, + "incorrect value for contents[241], expected 111, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 11, + "incorrect value for contents[242], expected 11, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 91, + "incorrect value for contents[243], expected 91, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 21, + "incorrect value for contents[244], expected 21, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 236, + "incorrect value for contents[245], expected 236, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 234, + "incorrect value for contents[246], expected 234, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 196, + "incorrect value for contents[247], expected 196, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 36, + "incorrect value for contents[248], expected 36, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 171, + "incorrect value for contents[249], expected 171, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 147, + "incorrect value for contents[250], expected 147, is {}", + msg.contents[250] + ); + assert_eq!( + msg.sequence, 259241795, + "incorrect value for sequence, expected 259241795, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_read_resp() { + { + let json_input = r#"{"crc":61450,"length":255,"msg_type":163,"payload":"Q7dzD0nn47MSTETl2BVit0W+BfywNyBOCDR/MkdqPU+/ai5Pdvh2z87SW0n7UYPNwZLOuYz5o+dBQ176bZhfe03gfO7NQWcjaNEFvy/5sKbVLsBWIGeS/AQQNqE8Bg2/dLYqv9UU2QiOu+54uPoflyUzsYK+m0dEOO5cgiWJkvZydIql2U8KvYC9AvBcHH5p7OTCADM9SikK74Vqvh4bA/DN/XEZHLtRZdh5KbN4mBJ0NdRkAnLGyAqTGSFz0HE8s7cAKdnO/9Phjr+FUQ/4wUK/9N34x/FwMwG0tH1hkRlI0tfQD344JkEEQBNK329tNCunuspvC1sV7OrEJKuT","preamble":85,"sender":1219,"sequence":259241795,"contents":[73,231,227,179,18,76,68,229,216,21,98,183,69,190,5,252,176,55,32,78,8,52,127,50,71,106,61,79,191,106,46,79,118,248,118,207,206,210,91,73,251,81,131,205,193,146,206,185,140,249,163,231,65,67,94,250,109,152,95,123,77,224,124,238,205,65,103,35,104,209,5,191,47,249,176,166,213,46,192,86,32,103,146,252,4,16,54,161,60,6,13,191,116,182,42,191,213,20,217,8,142,187,238,120,184,250,31,151,37,51,177,130,190,155,71,68,56,238,92,130,37,137,146,246,114,116,138,165,217,79,10,189,128,189,2,240,92,28,126,105,236,228,194,0,51,61,74,41,10,239,133,106,190,30,27,3,240,205,253,113,25,28,187,81,101,216,121,41,179,120,152,18,116,53,212,100,2,114,198,200,10,147,25,33,115,208,113,60,179,183,0,41,217,206,255,211,225,142,191,133,81,15,248,193,66,191,244,221,248,199,241,112,51,1,180,180,125,97,145,25,72,210,215,208,15,126,56,38,65,4,64,19,74,223,111,109,52,43,167,186,202,111,11,91,21,236,234,196,36,171,147]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa3, + "Incorrect message type, expected 0xa3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 73, + "incorrect value for contents[0], expected 73, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 231, + "incorrect value for contents[1], expected 231, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 227, + "incorrect value for contents[2], expected 227, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 179, + "incorrect value for contents[3], expected 179, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 18, + "incorrect value for contents[4], expected 18, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 76, + "incorrect value for contents[5], expected 76, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 68, + "incorrect value for contents[6], expected 68, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 229, + "incorrect value for contents[7], expected 229, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 216, + "incorrect value for contents[8], expected 216, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 21, + "incorrect value for contents[9], expected 21, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 98, + "incorrect value for contents[10], expected 98, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 183, + "incorrect value for contents[11], expected 183, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 69, + "incorrect value for contents[12], expected 69, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 190, + "incorrect value for contents[13], expected 190, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 5, + "incorrect value for contents[14], expected 5, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 252, + "incorrect value for contents[15], expected 252, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 176, + "incorrect value for contents[16], expected 176, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 55, + "incorrect value for contents[17], expected 55, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 32, + "incorrect value for contents[18], expected 32, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 78, + "incorrect value for contents[19], expected 78, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 8, + "incorrect value for contents[20], expected 8, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 52, + "incorrect value for contents[21], expected 52, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 127, + "incorrect value for contents[22], expected 127, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 50, + "incorrect value for contents[23], expected 50, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 71, + "incorrect value for contents[24], expected 71, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 106, + "incorrect value for contents[25], expected 106, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 61, + "incorrect value for contents[26], expected 61, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 79, + "incorrect value for contents[27], expected 79, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 191, + "incorrect value for contents[28], expected 191, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 106, + "incorrect value for contents[29], expected 106, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 46, + "incorrect value for contents[30], expected 46, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 79, + "incorrect value for contents[31], expected 79, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 118, + "incorrect value for contents[32], expected 118, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 248, + "incorrect value for contents[33], expected 248, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 118, + "incorrect value for contents[34], expected 118, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 207, + "incorrect value for contents[35], expected 207, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 206, + "incorrect value for contents[36], expected 206, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 210, + "incorrect value for contents[37], expected 210, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 91, + "incorrect value for contents[38], expected 91, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 73, + "incorrect value for contents[39], expected 73, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 251, + "incorrect value for contents[40], expected 251, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 81, + "incorrect value for contents[41], expected 81, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 131, + "incorrect value for contents[42], expected 131, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 205, + "incorrect value for contents[43], expected 205, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 193, + "incorrect value for contents[44], expected 193, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 146, + "incorrect value for contents[45], expected 146, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 206, + "incorrect value for contents[46], expected 206, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 185, + "incorrect value for contents[47], expected 185, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 140, + "incorrect value for contents[48], expected 140, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 249, + "incorrect value for contents[49], expected 249, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 163, + "incorrect value for contents[50], expected 163, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 231, + "incorrect value for contents[51], expected 231, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 65, + "incorrect value for contents[52], expected 65, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 67, + "incorrect value for contents[53], expected 67, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 94, + "incorrect value for contents[54], expected 94, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 250, + "incorrect value for contents[55], expected 250, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 109, + "incorrect value for contents[56], expected 109, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 152, + "incorrect value for contents[57], expected 152, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 95, + "incorrect value for contents[58], expected 95, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 123, + "incorrect value for contents[59], expected 123, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 77, + "incorrect value for contents[60], expected 77, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 224, + "incorrect value for contents[61], expected 224, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 124, + "incorrect value for contents[62], expected 124, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 238, + "incorrect value for contents[63], expected 238, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 205, + "incorrect value for contents[64], expected 205, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 65, + "incorrect value for contents[65], expected 65, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 103, + "incorrect value for contents[66], expected 103, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 35, + "incorrect value for contents[67], expected 35, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 104, + "incorrect value for contents[68], expected 104, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 209, + "incorrect value for contents[69], expected 209, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 5, + "incorrect value for contents[70], expected 5, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 191, + "incorrect value for contents[71], expected 191, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 47, + "incorrect value for contents[72], expected 47, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 249, + "incorrect value for contents[73], expected 249, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 176, + "incorrect value for contents[74], expected 176, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 166, + "incorrect value for contents[75], expected 166, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 213, + "incorrect value for contents[76], expected 213, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 46, + "incorrect value for contents[77], expected 46, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 192, + "incorrect value for contents[78], expected 192, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 86, + "incorrect value for contents[79], expected 86, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 32, + "incorrect value for contents[80], expected 32, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 103, + "incorrect value for contents[81], expected 103, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 146, + "incorrect value for contents[82], expected 146, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 252, + "incorrect value for contents[83], expected 252, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 4, + "incorrect value for contents[84], expected 4, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 16, + "incorrect value for contents[85], expected 16, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 54, + "incorrect value for contents[86], expected 54, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 161, + "incorrect value for contents[87], expected 161, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 60, + "incorrect value for contents[88], expected 60, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 6, + "incorrect value for contents[89], expected 6, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 13, + "incorrect value for contents[90], expected 13, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 191, + "incorrect value for contents[91], expected 191, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 116, + "incorrect value for contents[92], expected 116, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 182, + "incorrect value for contents[93], expected 182, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 42, + "incorrect value for contents[94], expected 42, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 191, + "incorrect value for contents[95], expected 191, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 213, + "incorrect value for contents[96], expected 213, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 20, + "incorrect value for contents[97], expected 20, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 217, + "incorrect value for contents[98], expected 217, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 8, + "incorrect value for contents[99], expected 8, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 142, + "incorrect value for contents[100], expected 142, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 187, + "incorrect value for contents[101], expected 187, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 238, + "incorrect value for contents[102], expected 238, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 120, + "incorrect value for contents[103], expected 120, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 184, + "incorrect value for contents[104], expected 184, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 250, + "incorrect value for contents[105], expected 250, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 31, + "incorrect value for contents[106], expected 31, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 151, + "incorrect value for contents[107], expected 151, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 37, + "incorrect value for contents[108], expected 37, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 51, + "incorrect value for contents[109], expected 51, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 177, + "incorrect value for contents[110], expected 177, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 130, + "incorrect value for contents[111], expected 130, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 190, + "incorrect value for contents[112], expected 190, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 155, + "incorrect value for contents[113], expected 155, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 71, + "incorrect value for contents[114], expected 71, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 68, + "incorrect value for contents[115], expected 68, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 56, + "incorrect value for contents[116], expected 56, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 238, + "incorrect value for contents[117], expected 238, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 92, + "incorrect value for contents[118], expected 92, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 130, + "incorrect value for contents[119], expected 130, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 37, + "incorrect value for contents[120], expected 37, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 137, + "incorrect value for contents[121], expected 137, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 146, + "incorrect value for contents[122], expected 146, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 246, + "incorrect value for contents[123], expected 246, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 114, + "incorrect value for contents[124], expected 114, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 116, + "incorrect value for contents[125], expected 116, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 138, + "incorrect value for contents[126], expected 138, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 165, + "incorrect value for contents[127], expected 165, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 217, + "incorrect value for contents[128], expected 217, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 79, + "incorrect value for contents[129], expected 79, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 10, + "incorrect value for contents[130], expected 10, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 189, + "incorrect value for contents[131], expected 189, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 128, + "incorrect value for contents[132], expected 128, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 189, + "incorrect value for contents[133], expected 189, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 2, + "incorrect value for contents[134], expected 2, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 240, + "incorrect value for contents[135], expected 240, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 92, + "incorrect value for contents[136], expected 92, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 28, + "incorrect value for contents[137], expected 28, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 126, + "incorrect value for contents[138], expected 126, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 105, + "incorrect value for contents[139], expected 105, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 236, + "incorrect value for contents[140], expected 236, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 228, + "incorrect value for contents[141], expected 228, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 194, + "incorrect value for contents[142], expected 194, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 0, + "incorrect value for contents[143], expected 0, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 51, + "incorrect value for contents[144], expected 51, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 61, + "incorrect value for contents[145], expected 61, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 74, + "incorrect value for contents[146], expected 74, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 41, + "incorrect value for contents[147], expected 41, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 10, + "incorrect value for contents[148], expected 10, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 239, + "incorrect value for contents[149], expected 239, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 133, + "incorrect value for contents[150], expected 133, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 106, + "incorrect value for contents[151], expected 106, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 190, + "incorrect value for contents[152], expected 190, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 30, + "incorrect value for contents[153], expected 30, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 27, + "incorrect value for contents[154], expected 27, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 3, + "incorrect value for contents[155], expected 3, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 240, + "incorrect value for contents[156], expected 240, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 205, + "incorrect value for contents[157], expected 205, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 253, + "incorrect value for contents[158], expected 253, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 113, + "incorrect value for contents[159], expected 113, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 25, + "incorrect value for contents[160], expected 25, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 28, + "incorrect value for contents[161], expected 28, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 187, + "incorrect value for contents[162], expected 187, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 81, + "incorrect value for contents[163], expected 81, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 101, + "incorrect value for contents[164], expected 101, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 216, + "incorrect value for contents[165], expected 216, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 121, + "incorrect value for contents[166], expected 121, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 41, + "incorrect value for contents[167], expected 41, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 179, + "incorrect value for contents[168], expected 179, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 120, + "incorrect value for contents[169], expected 120, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 152, + "incorrect value for contents[170], expected 152, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 18, + "incorrect value for contents[171], expected 18, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 116, + "incorrect value for contents[172], expected 116, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 53, + "incorrect value for contents[173], expected 53, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 212, + "incorrect value for contents[174], expected 212, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 100, + "incorrect value for contents[175], expected 100, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 2, + "incorrect value for contents[176], expected 2, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 114, + "incorrect value for contents[177], expected 114, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 198, + "incorrect value for contents[178], expected 198, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 200, + "incorrect value for contents[179], expected 200, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 10, + "incorrect value for contents[180], expected 10, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 147, + "incorrect value for contents[181], expected 147, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 25, + "incorrect value for contents[182], expected 25, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 33, + "incorrect value for contents[183], expected 33, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 115, + "incorrect value for contents[184], expected 115, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 208, + "incorrect value for contents[185], expected 208, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 113, + "incorrect value for contents[186], expected 113, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 60, + "incorrect value for contents[187], expected 60, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 179, + "incorrect value for contents[188], expected 179, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 183, + "incorrect value for contents[189], expected 183, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 0, + "incorrect value for contents[190], expected 0, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 41, + "incorrect value for contents[191], expected 41, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 217, + "incorrect value for contents[192], expected 217, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 206, + "incorrect value for contents[193], expected 206, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 255, + "incorrect value for contents[194], expected 255, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 211, + "incorrect value for contents[195], expected 211, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 225, + "incorrect value for contents[196], expected 225, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 142, + "incorrect value for contents[197], expected 142, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 191, + "incorrect value for contents[198], expected 191, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 133, + "incorrect value for contents[199], expected 133, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 81, + "incorrect value for contents[200], expected 81, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 15, + "incorrect value for contents[201], expected 15, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 248, + "incorrect value for contents[202], expected 248, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 193, + "incorrect value for contents[203], expected 193, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 66, + "incorrect value for contents[204], expected 66, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 191, + "incorrect value for contents[205], expected 191, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 244, + "incorrect value for contents[206], expected 244, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 221, + "incorrect value for contents[207], expected 221, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 248, + "incorrect value for contents[208], expected 248, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 199, + "incorrect value for contents[209], expected 199, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 241, + "incorrect value for contents[210], expected 241, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 51, + "incorrect value for contents[212], expected 51, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 1, + "incorrect value for contents[213], expected 1, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 180, + "incorrect value for contents[214], expected 180, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 180, + "incorrect value for contents[215], expected 180, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 125, + "incorrect value for contents[216], expected 125, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 97, + "incorrect value for contents[217], expected 97, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 145, + "incorrect value for contents[218], expected 145, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 25, + "incorrect value for contents[219], expected 25, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 72, + "incorrect value for contents[220], expected 72, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 210, + "incorrect value for contents[221], expected 210, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 215, + "incorrect value for contents[222], expected 215, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 208, + "incorrect value for contents[223], expected 208, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 15, + "incorrect value for contents[224], expected 15, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 126, + "incorrect value for contents[225], expected 126, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 56, + "incorrect value for contents[226], expected 56, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 38, + "incorrect value for contents[227], expected 38, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 65, + "incorrect value for contents[228], expected 65, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 4, + "incorrect value for contents[229], expected 4, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 64, + "incorrect value for contents[230], expected 64, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 19, + "incorrect value for contents[231], expected 19, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 74, + "incorrect value for contents[232], expected 74, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 223, + "incorrect value for contents[233], expected 223, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 111, + "incorrect value for contents[234], expected 111, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 109, + "incorrect value for contents[235], expected 109, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 52, + "incorrect value for contents[236], expected 52, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 43, + "incorrect value for contents[237], expected 43, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 167, + "incorrect value for contents[238], expected 167, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 186, + "incorrect value for contents[239], expected 186, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 202, + "incorrect value for contents[240], expected 202, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 111, + "incorrect value for contents[241], expected 111, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 11, + "incorrect value for contents[242], expected 11, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 91, + "incorrect value for contents[243], expected 91, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 21, + "incorrect value for contents[244], expected 21, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 236, + "incorrect value for contents[245], expected 236, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 234, + "incorrect value for contents[246], expected 234, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 196, + "incorrect value for contents[247], expected 196, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 36, + "incorrect value for contents[248], expected 36, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 171, + "incorrect value for contents[249], expected 171, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 147, + "incorrect value for contents[250], expected 147, is {}", + msg.contents[250] + ); + assert_eq!( + msg.sequence, 259241795, + "incorrect value for sequence, expected 259241795, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_read_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 163, 0, 195, 4, 255, 67, 183, 115, 15, 73, 231, 227, 179, 18, 76, 68, 229, 216, 21, + 98, 183, 69, 190, 5, 252, 176, 55, 32, 78, 8, 52, 127, 50, 71, 106, 61, 79, 191, 106, + 46, 79, 118, 248, 118, 207, 206, 210, 91, 73, 251, 81, 131, 205, 193, 146, 206, 185, + 140, 249, 163, 231, 65, 67, 94, 250, 109, 152, 95, 123, 77, 224, 124, 238, 205, 65, + 103, 35, 104, 209, 5, 191, 47, 249, 176, 166, 213, 46, 192, 86, 32, 103, 146, 252, 4, + 16, 54, 161, 60, 6, 13, 191, 116, 182, 42, 191, 213, 20, 217, 8, 142, 187, 238, 120, + 184, 250, 31, 151, 37, 51, 177, 130, 190, 155, 71, 68, 56, 238, 92, 130, 37, 137, 146, + 246, 114, 116, 138, 165, 217, 79, 10, 189, 128, 189, 2, 240, 92, 28, 126, 105, 236, + 228, 194, 0, 51, 61, 74, 41, 10, 239, 133, 106, 190, 30, 27, 3, 240, 205, 253, 113, 25, + 28, 187, 81, 101, 216, 121, 41, 179, 120, 152, 18, 116, 53, 212, 100, 2, 114, 198, 200, + 10, 147, 25, 33, 115, 208, 113, 60, 179, 183, 0, 41, 217, 206, 255, 211, 225, 142, 191, + 133, 81, 15, 248, 193, 66, 191, 244, 221, 248, 199, 241, 112, 51, 1, 180, 180, 125, 97, + 145, 25, 72, 210, 215, 208, 15, 126, 56, 38, 65, 4, 64, 19, 74, 223, 111, 109, 52, 43, + 167, 186, 202, 111, 11, 91, 21, 236, 234, 196, 36, 171, 147, 10, 240, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioReadResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa3, + "Incorrect message type, expected 0xa3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 73, + "incorrect value for contents[0], expected 73, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 231, + "incorrect value for contents[1], expected 231, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 227, + "incorrect value for contents[2], expected 227, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 179, + "incorrect value for contents[3], expected 179, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 18, + "incorrect value for contents[4], expected 18, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 76, + "incorrect value for contents[5], expected 76, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 68, + "incorrect value for contents[6], expected 68, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 229, + "incorrect value for contents[7], expected 229, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 216, + "incorrect value for contents[8], expected 216, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 21, + "incorrect value for contents[9], expected 21, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 98, + "incorrect value for contents[10], expected 98, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 183, + "incorrect value for contents[11], expected 183, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 69, + "incorrect value for contents[12], expected 69, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 190, + "incorrect value for contents[13], expected 190, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 5, + "incorrect value for contents[14], expected 5, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 252, + "incorrect value for contents[15], expected 252, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 176, + "incorrect value for contents[16], expected 176, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 55, + "incorrect value for contents[17], expected 55, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 32, + "incorrect value for contents[18], expected 32, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 78, + "incorrect value for contents[19], expected 78, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 8, + "incorrect value for contents[20], expected 8, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 52, + "incorrect value for contents[21], expected 52, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 127, + "incorrect value for contents[22], expected 127, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 50, + "incorrect value for contents[23], expected 50, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 71, + "incorrect value for contents[24], expected 71, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 106, + "incorrect value for contents[25], expected 106, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 61, + "incorrect value for contents[26], expected 61, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 79, + "incorrect value for contents[27], expected 79, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 191, + "incorrect value for contents[28], expected 191, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 106, + "incorrect value for contents[29], expected 106, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 46, + "incorrect value for contents[30], expected 46, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 79, + "incorrect value for contents[31], expected 79, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 118, + "incorrect value for contents[32], expected 118, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 248, + "incorrect value for contents[33], expected 248, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 118, + "incorrect value for contents[34], expected 118, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 207, + "incorrect value for contents[35], expected 207, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 206, + "incorrect value for contents[36], expected 206, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 210, + "incorrect value for contents[37], expected 210, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 91, + "incorrect value for contents[38], expected 91, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 73, + "incorrect value for contents[39], expected 73, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 251, + "incorrect value for contents[40], expected 251, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 81, + "incorrect value for contents[41], expected 81, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 131, + "incorrect value for contents[42], expected 131, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 205, + "incorrect value for contents[43], expected 205, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 193, + "incorrect value for contents[44], expected 193, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 146, + "incorrect value for contents[45], expected 146, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 206, + "incorrect value for contents[46], expected 206, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 185, + "incorrect value for contents[47], expected 185, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 140, + "incorrect value for contents[48], expected 140, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 249, + "incorrect value for contents[49], expected 249, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 163, + "incorrect value for contents[50], expected 163, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 231, + "incorrect value for contents[51], expected 231, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 65, + "incorrect value for contents[52], expected 65, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 67, + "incorrect value for contents[53], expected 67, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 94, + "incorrect value for contents[54], expected 94, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 250, + "incorrect value for contents[55], expected 250, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 109, + "incorrect value for contents[56], expected 109, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 152, + "incorrect value for contents[57], expected 152, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 95, + "incorrect value for contents[58], expected 95, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 123, + "incorrect value for contents[59], expected 123, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 77, + "incorrect value for contents[60], expected 77, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 224, + "incorrect value for contents[61], expected 224, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 124, + "incorrect value for contents[62], expected 124, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 238, + "incorrect value for contents[63], expected 238, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 205, + "incorrect value for contents[64], expected 205, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 65, + "incorrect value for contents[65], expected 65, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 103, + "incorrect value for contents[66], expected 103, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 35, + "incorrect value for contents[67], expected 35, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 104, + "incorrect value for contents[68], expected 104, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 209, + "incorrect value for contents[69], expected 209, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 5, + "incorrect value for contents[70], expected 5, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 191, + "incorrect value for contents[71], expected 191, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 47, + "incorrect value for contents[72], expected 47, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 249, + "incorrect value for contents[73], expected 249, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 176, + "incorrect value for contents[74], expected 176, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 166, + "incorrect value for contents[75], expected 166, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 213, + "incorrect value for contents[76], expected 213, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 46, + "incorrect value for contents[77], expected 46, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 192, + "incorrect value for contents[78], expected 192, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 86, + "incorrect value for contents[79], expected 86, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 32, + "incorrect value for contents[80], expected 32, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 103, + "incorrect value for contents[81], expected 103, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 146, + "incorrect value for contents[82], expected 146, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 252, + "incorrect value for contents[83], expected 252, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 4, + "incorrect value for contents[84], expected 4, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 16, + "incorrect value for contents[85], expected 16, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 54, + "incorrect value for contents[86], expected 54, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 161, + "incorrect value for contents[87], expected 161, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 60, + "incorrect value for contents[88], expected 60, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 6, + "incorrect value for contents[89], expected 6, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 13, + "incorrect value for contents[90], expected 13, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 191, + "incorrect value for contents[91], expected 191, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 116, + "incorrect value for contents[92], expected 116, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 182, + "incorrect value for contents[93], expected 182, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 42, + "incorrect value for contents[94], expected 42, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 191, + "incorrect value for contents[95], expected 191, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 213, + "incorrect value for contents[96], expected 213, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 20, + "incorrect value for contents[97], expected 20, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 217, + "incorrect value for contents[98], expected 217, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 8, + "incorrect value for contents[99], expected 8, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 142, + "incorrect value for contents[100], expected 142, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 187, + "incorrect value for contents[101], expected 187, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 238, + "incorrect value for contents[102], expected 238, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 120, + "incorrect value for contents[103], expected 120, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 184, + "incorrect value for contents[104], expected 184, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 250, + "incorrect value for contents[105], expected 250, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 31, + "incorrect value for contents[106], expected 31, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 151, + "incorrect value for contents[107], expected 151, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 37, + "incorrect value for contents[108], expected 37, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 51, + "incorrect value for contents[109], expected 51, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 177, + "incorrect value for contents[110], expected 177, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 130, + "incorrect value for contents[111], expected 130, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 190, + "incorrect value for contents[112], expected 190, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 155, + "incorrect value for contents[113], expected 155, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 71, + "incorrect value for contents[114], expected 71, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 68, + "incorrect value for contents[115], expected 68, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 56, + "incorrect value for contents[116], expected 56, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 238, + "incorrect value for contents[117], expected 238, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 92, + "incorrect value for contents[118], expected 92, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 130, + "incorrect value for contents[119], expected 130, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 37, + "incorrect value for contents[120], expected 37, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 137, + "incorrect value for contents[121], expected 137, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 146, + "incorrect value for contents[122], expected 146, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 246, + "incorrect value for contents[123], expected 246, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 114, + "incorrect value for contents[124], expected 114, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 116, + "incorrect value for contents[125], expected 116, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 138, + "incorrect value for contents[126], expected 138, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 165, + "incorrect value for contents[127], expected 165, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 217, + "incorrect value for contents[128], expected 217, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 79, + "incorrect value for contents[129], expected 79, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 10, + "incorrect value for contents[130], expected 10, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 189, + "incorrect value for contents[131], expected 189, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 128, + "incorrect value for contents[132], expected 128, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 189, + "incorrect value for contents[133], expected 189, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 2, + "incorrect value for contents[134], expected 2, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 240, + "incorrect value for contents[135], expected 240, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 92, + "incorrect value for contents[136], expected 92, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 28, + "incorrect value for contents[137], expected 28, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 126, + "incorrect value for contents[138], expected 126, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 105, + "incorrect value for contents[139], expected 105, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 236, + "incorrect value for contents[140], expected 236, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 228, + "incorrect value for contents[141], expected 228, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 194, + "incorrect value for contents[142], expected 194, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 0, + "incorrect value for contents[143], expected 0, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 51, + "incorrect value for contents[144], expected 51, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 61, + "incorrect value for contents[145], expected 61, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 74, + "incorrect value for contents[146], expected 74, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 41, + "incorrect value for contents[147], expected 41, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 10, + "incorrect value for contents[148], expected 10, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 239, + "incorrect value for contents[149], expected 239, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 133, + "incorrect value for contents[150], expected 133, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 106, + "incorrect value for contents[151], expected 106, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 190, + "incorrect value for contents[152], expected 190, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 30, + "incorrect value for contents[153], expected 30, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 27, + "incorrect value for contents[154], expected 27, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 3, + "incorrect value for contents[155], expected 3, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 240, + "incorrect value for contents[156], expected 240, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 205, + "incorrect value for contents[157], expected 205, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 253, + "incorrect value for contents[158], expected 253, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 113, + "incorrect value for contents[159], expected 113, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 25, + "incorrect value for contents[160], expected 25, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 28, + "incorrect value for contents[161], expected 28, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 187, + "incorrect value for contents[162], expected 187, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 81, + "incorrect value for contents[163], expected 81, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 101, + "incorrect value for contents[164], expected 101, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 216, + "incorrect value for contents[165], expected 216, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 121, + "incorrect value for contents[166], expected 121, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 41, + "incorrect value for contents[167], expected 41, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 179, + "incorrect value for contents[168], expected 179, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 120, + "incorrect value for contents[169], expected 120, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 152, + "incorrect value for contents[170], expected 152, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 18, + "incorrect value for contents[171], expected 18, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 116, + "incorrect value for contents[172], expected 116, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 53, + "incorrect value for contents[173], expected 53, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 212, + "incorrect value for contents[174], expected 212, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 100, + "incorrect value for contents[175], expected 100, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 2, + "incorrect value for contents[176], expected 2, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 114, + "incorrect value for contents[177], expected 114, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 198, + "incorrect value for contents[178], expected 198, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 200, + "incorrect value for contents[179], expected 200, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 10, + "incorrect value for contents[180], expected 10, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 147, + "incorrect value for contents[181], expected 147, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 25, + "incorrect value for contents[182], expected 25, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 33, + "incorrect value for contents[183], expected 33, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 115, + "incorrect value for contents[184], expected 115, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 208, + "incorrect value for contents[185], expected 208, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 113, + "incorrect value for contents[186], expected 113, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 60, + "incorrect value for contents[187], expected 60, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 179, + "incorrect value for contents[188], expected 179, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 183, + "incorrect value for contents[189], expected 183, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 0, + "incorrect value for contents[190], expected 0, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 41, + "incorrect value for contents[191], expected 41, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 217, + "incorrect value for contents[192], expected 217, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 206, + "incorrect value for contents[193], expected 206, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 255, + "incorrect value for contents[194], expected 255, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 211, + "incorrect value for contents[195], expected 211, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 225, + "incorrect value for contents[196], expected 225, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 142, + "incorrect value for contents[197], expected 142, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 191, + "incorrect value for contents[198], expected 191, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 133, + "incorrect value for contents[199], expected 133, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 81, + "incorrect value for contents[200], expected 81, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 15, + "incorrect value for contents[201], expected 15, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 248, + "incorrect value for contents[202], expected 248, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 193, + "incorrect value for contents[203], expected 193, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 66, + "incorrect value for contents[204], expected 66, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 191, + "incorrect value for contents[205], expected 191, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 244, + "incorrect value for contents[206], expected 244, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 221, + "incorrect value for contents[207], expected 221, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 248, + "incorrect value for contents[208], expected 248, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 199, + "incorrect value for contents[209], expected 199, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 241, + "incorrect value for contents[210], expected 241, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 51, + "incorrect value for contents[212], expected 51, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 1, + "incorrect value for contents[213], expected 1, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 180, + "incorrect value for contents[214], expected 180, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 180, + "incorrect value for contents[215], expected 180, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 125, + "incorrect value for contents[216], expected 125, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 97, + "incorrect value for contents[217], expected 97, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 145, + "incorrect value for contents[218], expected 145, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 25, + "incorrect value for contents[219], expected 25, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 72, + "incorrect value for contents[220], expected 72, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 210, + "incorrect value for contents[221], expected 210, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 215, + "incorrect value for contents[222], expected 215, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 208, + "incorrect value for contents[223], expected 208, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 15, + "incorrect value for contents[224], expected 15, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 126, + "incorrect value for contents[225], expected 126, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 56, + "incorrect value for contents[226], expected 56, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 38, + "incorrect value for contents[227], expected 38, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 65, + "incorrect value for contents[228], expected 65, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 4, + "incorrect value for contents[229], expected 4, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 64, + "incorrect value for contents[230], expected 64, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 19, + "incorrect value for contents[231], expected 19, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 74, + "incorrect value for contents[232], expected 74, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 223, + "incorrect value for contents[233], expected 223, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 111, + "incorrect value for contents[234], expected 111, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 109, + "incorrect value for contents[235], expected 109, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 52, + "incorrect value for contents[236], expected 52, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 43, + "incorrect value for contents[237], expected 43, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 167, + "incorrect value for contents[238], expected 167, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 186, + "incorrect value for contents[239], expected 186, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 202, + "incorrect value for contents[240], expected 202, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 111, + "incorrect value for contents[241], expected 111, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 11, + "incorrect value for contents[242], expected 11, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 91, + "incorrect value for contents[243], expected 91, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 21, + "incorrect value for contents[244], expected 21, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 236, + "incorrect value for contents[245], expected 236, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 234, + "incorrect value for contents[246], expected 234, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 196, + "incorrect value for contents[247], expected 196, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 36, + "incorrect value for contents[248], expected 36, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 171, + "incorrect value for contents[249], expected 171, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 147, + "incorrect value for contents[250], expected 147, is {}", + msg.contents[250] + ); + assert_eq!( + msg.sequence, 259241795, + "incorrect value for sequence, expected 259241795, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioReadResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_remove.rs b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_remove.rs new file mode 100644 index 0000000000..abdd1eb54f --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_file_io_msg_fileio_remove.rs @@ -0,0 +1,190 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_file_io_msg_fileio_remove() { + { + let mut payload = Cursor::new(vec![ + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0, + 46, 243, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioRemove(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xac, + "Incorrect message type, expected 0xac, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.filename.as_bytes(), + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + msg.filename.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioRemove"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_file_io_msg_fileio_remove() { + { + let json_input = r#"{"crc":62254,"length":14,"msg_type":172,"payload":"L3BhdGgvdG8vZmlsZQA=","preamble":85,"sender":1219,"filename":"/path/to/file\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFileioRemove(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xac, + "Incorrect message type, expected 0xac, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.filename.as_bytes(), + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + msg.filename.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioRemove"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_file_io_msg_fileio_remove`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_file_io_msg_fileio_remove() { + { + let mut payload = Cursor::new(vec![ + 85, 172, 0, 195, 4, 14, 47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0, + 46, 243, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFileioRemove( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFileioRemove(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xac, + "Incorrect message type, expected 0xac, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.filename.as_bytes(), + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + "incorrect value for msg.filename, expected string '{:?}', is '{:?}'", + &[47, 112, 97, 116, 104, 47, 116, 111, 47, 102, 105, 108, 101, 0], + msg.filename.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgFileioRemove"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_done.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_done.rs new file mode 100644 index 0000000000..20e9bc8664 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_done.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_flash_done() { + { + let mut payload = Cursor::new(vec![85, 224, 0, 195, 4, 1, 82, 6, 54]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashDone(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe0, + "Incorrect message type, expected 0xe0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.response, 82, + "incorrect value for response, expected 82, is {}", + msg.response + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashDone"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_flash_done() { + { + let json_input = r#"{"crc":13830,"length":1,"msg_type":224,"payload":"Ug==","preamble":85,"sender":1219,"response":82}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashDone(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe0, + "Incorrect message type, expected 0xe0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.response, 82, + "incorrect value for response, expected 82, is {}", + msg.response + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashDone"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_flash_done`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_flash_done() { + { + let mut payload = Cursor::new(vec![85, 224, 0, 195, 4, 1, 82, 6, 54]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFlashDone( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFlashDone(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe0, + "Incorrect message type, expected 0xe0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.response, 82, + "incorrect value for response, expected 82, is {}", + msg.response + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashDone"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_erase.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_erase.rs new file mode 100644 index 0000000000..9388b1bcdf --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_erase.rs @@ -0,0 +1,193 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_flash_erase() { + { + let mut payload = Cursor::new(vec![85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashErase(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe2, + "Incorrect message type, expected 0xe2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector_num, 2222371310, + "incorrect value for sector_num, expected 2222371310, is {}", + msg.sector_num + ); + assert_eq!( + msg.target, 74, + "incorrect value for target, expected 74, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashErase"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_flash_erase() { + { + let json_input = r#"{"crc":64256,"length":5,"msg_type":226,"payload":"Su6xdoQ=","preamble":85,"sender":1219,"target":74,"sector_num":2222371310}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashErase(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe2, + "Incorrect message type, expected 0xe2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector_num, 2222371310, + "incorrect value for sector_num, expected 2222371310, is {}", + msg.sector_num + ); + assert_eq!( + msg.target, 74, + "incorrect value for target, expected 74, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashErase"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_flash_erase`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_flash_erase() { + { + let mut payload = Cursor::new(vec![85, 226, 0, 195, 4, 5, 74, 238, 177, 118, 132, 0, 251]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFlashErase( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFlashErase(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe2, + "Incorrect message type, expected 0xe2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector_num, 2222371310, + "incorrect value for sector_num, expected 2222371310, is {}", + msg.sector_num + ); + assert_eq!( + msg.target, 74, + "incorrect value for target, expected 74, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashErase"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_program.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_program.rs new file mode 100644 index 0000000000..26be29c88e --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_program.rs @@ -0,0 +1,4018 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_flash_program() { + { + let mut payload = Cursor::new(vec![ + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, 106, 144, 29, 141, 255, + 3, 16, 192, 237, 172, 254, 213, 4, 220, 98, 34, 222, 230, 214, 6, 217, 172, 122, 46, + 13, 38, 240, 236, 60, 121, 47, 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, 21, + 214, 57, 245, 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, 98, 39, 70, 232, 133, 25, 10, + 134, 129, 69, 228, 134, 9, 88, 183, 133, 171, 255, 166, 100, 152, 231, 92, 9, 196, 106, + 246, 29, 145, 156, 151, 32, 67, 188, 63, 233, 142, 174, 139, 154, 127, 35, 60, 56, 187, + 121, 103, 135, 152, 182, 88, 160, 255, 227, 240, 54, 100, 91, 31, 141, 102, 130, 254, + 54, 227, 229, 62, 53, 225, 143, 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, 57, 87, + 130, 178, 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, 235, 213, 186, 159, 221, + 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, 13, 50, 71, 73, 193, 201, 250, 172, 193, + 13, 20, 238, 130, 243, 68, 4, 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, + 92, 160, 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, 239, 168, 32, + 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, 217, 151, 251, 83, 20, 113, 37, 151, + 34, 37, 71, 95, 105, 235, 144, 164, 83, 197, 254, 183, 223, 91, 19, 45, 227, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashProgram(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe6, + "Incorrect message type, expected 0xe6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 250, + "incorrect value for addr_len, expected 250, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 87, + "incorrect value for addr_start[0], expected 87, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.data[0], 176, + "incorrect value for data[0], expected 176, is {}", + msg.data[0] + ); + assert_eq!( + msg.data[1], 222, + "incorrect value for data[1], expected 222, is {}", + msg.data[1] + ); + assert_eq!( + msg.data[2], 235, + "incorrect value for data[2], expected 235, is {}", + msg.data[2] + ); + assert_eq!( + msg.data[3], 106, + "incorrect value for data[3], expected 106, is {}", + msg.data[3] + ); + assert_eq!( + msg.data[4], 144, + "incorrect value for data[4], expected 144, is {}", + msg.data[4] + ); + assert_eq!( + msg.data[5], 29, + "incorrect value for data[5], expected 29, is {}", + msg.data[5] + ); + assert_eq!( + msg.data[6], 141, + "incorrect value for data[6], expected 141, is {}", + msg.data[6] + ); + assert_eq!( + msg.data[7], 255, + "incorrect value for data[7], expected 255, is {}", + msg.data[7] + ); + assert_eq!( + msg.data[8], 3, + "incorrect value for data[8], expected 3, is {}", + msg.data[8] + ); + assert_eq!( + msg.data[9], 16, + "incorrect value for data[9], expected 16, is {}", + msg.data[9] + ); + assert_eq!( + msg.data[10], 192, + "incorrect value for data[10], expected 192, is {}", + msg.data[10] + ); + assert_eq!( + msg.data[11], 237, + "incorrect value for data[11], expected 237, is {}", + msg.data[11] + ); + assert_eq!( + msg.data[12], 172, + "incorrect value for data[12], expected 172, is {}", + msg.data[12] + ); + assert_eq!( + msg.data[13], 254, + "incorrect value for data[13], expected 254, is {}", + msg.data[13] + ); + assert_eq!( + msg.data[14], 213, + "incorrect value for data[14], expected 213, is {}", + msg.data[14] + ); + assert_eq!( + msg.data[15], 4, + "incorrect value for data[15], expected 4, is {}", + msg.data[15] + ); + assert_eq!( + msg.data[16], 220, + "incorrect value for data[16], expected 220, is {}", + msg.data[16] + ); + assert_eq!( + msg.data[17], 98, + "incorrect value for data[17], expected 98, is {}", + msg.data[17] + ); + assert_eq!( + msg.data[18], 34, + "incorrect value for data[18], expected 34, is {}", + msg.data[18] + ); + assert_eq!( + msg.data[19], 222, + "incorrect value for data[19], expected 222, is {}", + msg.data[19] + ); + assert_eq!( + msg.data[20], 230, + "incorrect value for data[20], expected 230, is {}", + msg.data[20] + ); + assert_eq!( + msg.data[21], 214, + "incorrect value for data[21], expected 214, is {}", + msg.data[21] + ); + assert_eq!( + msg.data[22], 6, + "incorrect value for data[22], expected 6, is {}", + msg.data[22] + ); + assert_eq!( + msg.data[23], 217, + "incorrect value for data[23], expected 217, is {}", + msg.data[23] + ); + assert_eq!( + msg.data[24], 172, + "incorrect value for data[24], expected 172, is {}", + msg.data[24] + ); + assert_eq!( + msg.data[25], 122, + "incorrect value for data[25], expected 122, is {}", + msg.data[25] + ); + assert_eq!( + msg.data[26], 46, + "incorrect value for data[26], expected 46, is {}", + msg.data[26] + ); + assert_eq!( + msg.data[27], 13, + "incorrect value for data[27], expected 13, is {}", + msg.data[27] + ); + assert_eq!( + msg.data[28], 38, + "incorrect value for data[28], expected 38, is {}", + msg.data[28] + ); + assert_eq!( + msg.data[29], 240, + "incorrect value for data[29], expected 240, is {}", + msg.data[29] + ); + assert_eq!( + msg.data[30], 236, + "incorrect value for data[30], expected 236, is {}", + msg.data[30] + ); + assert_eq!( + msg.data[31], 60, + "incorrect value for data[31], expected 60, is {}", + msg.data[31] + ); + assert_eq!( + msg.data[32], 121, + "incorrect value for data[32], expected 121, is {}", + msg.data[32] + ); + assert_eq!( + msg.data[33], 47, + "incorrect value for data[33], expected 47, is {}", + msg.data[33] + ); + assert_eq!( + msg.data[34], 252, + "incorrect value for data[34], expected 252, is {}", + msg.data[34] + ); + assert_eq!( + msg.data[35], 163, + "incorrect value for data[35], expected 163, is {}", + msg.data[35] + ); + assert_eq!( + msg.data[36], 141, + "incorrect value for data[36], expected 141, is {}", + msg.data[36] + ); + assert_eq!( + msg.data[37], 222, + "incorrect value for data[37], expected 222, is {}", + msg.data[37] + ); + assert_eq!( + msg.data[38], 29, + "incorrect value for data[38], expected 29, is {}", + msg.data[38] + ); + assert_eq!( + msg.data[39], 168, + "incorrect value for data[39], expected 168, is {}", + msg.data[39] + ); + assert_eq!( + msg.data[40], 214, + "incorrect value for data[40], expected 214, is {}", + msg.data[40] + ); + assert_eq!( + msg.data[41], 118, + "incorrect value for data[41], expected 118, is {}", + msg.data[41] + ); + assert_eq!( + msg.data[42], 55, + "incorrect value for data[42], expected 55, is {}", + msg.data[42] + ); + assert_eq!( + msg.data[43], 201, + "incorrect value for data[43], expected 201, is {}", + msg.data[43] + ); + assert_eq!( + msg.data[44], 233, + "incorrect value for data[44], expected 233, is {}", + msg.data[44] + ); + assert_eq!( + msg.data[45], 21, + "incorrect value for data[45], expected 21, is {}", + msg.data[45] + ); + assert_eq!( + msg.data[46], 214, + "incorrect value for data[46], expected 214, is {}", + msg.data[46] + ); + assert_eq!( + msg.data[47], 57, + "incorrect value for data[47], expected 57, is {}", + msg.data[47] + ); + assert_eq!( + msg.data[48], 245, + "incorrect value for data[48], expected 245, is {}", + msg.data[48] + ); + assert_eq!( + msg.data[49], 246, + "incorrect value for data[49], expected 246, is {}", + msg.data[49] + ); + assert_eq!( + msg.data[50], 19, + "incorrect value for data[50], expected 19, is {}", + msg.data[50] + ); + assert_eq!( + msg.data[51], 3, + "incorrect value for data[51], expected 3, is {}", + msg.data[51] + ); + assert_eq!( + msg.data[52], 121, + "incorrect value for data[52], expected 121, is {}", + msg.data[52] + ); + assert_eq!( + msg.data[53], 49, + "incorrect value for data[53], expected 49, is {}", + msg.data[53] + ); + assert_eq!( + msg.data[54], 231, + "incorrect value for data[54], expected 231, is {}", + msg.data[54] + ); + assert_eq!( + msg.data[55], 37, + "incorrect value for data[55], expected 37, is {}", + msg.data[55] + ); + assert_eq!( + msg.data[56], 186, + "incorrect value for data[56], expected 186, is {}", + msg.data[56] + ); + assert_eq!( + msg.data[57], 58, + "incorrect value for data[57], expected 58, is {}", + msg.data[57] + ); + assert_eq!( + msg.data[58], 238, + "incorrect value for data[58], expected 238, is {}", + msg.data[58] + ); + assert_eq!( + msg.data[59], 98, + "incorrect value for data[59], expected 98, is {}", + msg.data[59] + ); + assert_eq!( + msg.data[60], 39, + "incorrect value for data[60], expected 39, is {}", + msg.data[60] + ); + assert_eq!( + msg.data[61], 70, + "incorrect value for data[61], expected 70, is {}", + msg.data[61] + ); + assert_eq!( + msg.data[62], 232, + "incorrect value for data[62], expected 232, is {}", + msg.data[62] + ); + assert_eq!( + msg.data[63], 133, + "incorrect value for data[63], expected 133, is {}", + msg.data[63] + ); + assert_eq!( + msg.data[64], 25, + "incorrect value for data[64], expected 25, is {}", + msg.data[64] + ); + assert_eq!( + msg.data[65], 10, + "incorrect value for data[65], expected 10, is {}", + msg.data[65] + ); + assert_eq!( + msg.data[66], 134, + "incorrect value for data[66], expected 134, is {}", + msg.data[66] + ); + assert_eq!( + msg.data[67], 129, + "incorrect value for data[67], expected 129, is {}", + msg.data[67] + ); + assert_eq!( + msg.data[68], 69, + "incorrect value for data[68], expected 69, is {}", + msg.data[68] + ); + assert_eq!( + msg.data[69], 228, + "incorrect value for data[69], expected 228, is {}", + msg.data[69] + ); + assert_eq!( + msg.data[70], 134, + "incorrect value for data[70], expected 134, is {}", + msg.data[70] + ); + assert_eq!( + msg.data[71], 9, + "incorrect value for data[71], expected 9, is {}", + msg.data[71] + ); + assert_eq!( + msg.data[72], 88, + "incorrect value for data[72], expected 88, is {}", + msg.data[72] + ); + assert_eq!( + msg.data[73], 183, + "incorrect value for data[73], expected 183, is {}", + msg.data[73] + ); + assert_eq!( + msg.data[74], 133, + "incorrect value for data[74], expected 133, is {}", + msg.data[74] + ); + assert_eq!( + msg.data[75], 171, + "incorrect value for data[75], expected 171, is {}", + msg.data[75] + ); + assert_eq!( + msg.data[76], 255, + "incorrect value for data[76], expected 255, is {}", + msg.data[76] + ); + assert_eq!( + msg.data[77], 166, + "incorrect value for data[77], expected 166, is {}", + msg.data[77] + ); + assert_eq!( + msg.data[78], 100, + "incorrect value for data[78], expected 100, is {}", + msg.data[78] + ); + assert_eq!( + msg.data[79], 152, + "incorrect value for data[79], expected 152, is {}", + msg.data[79] + ); + assert_eq!( + msg.data[80], 231, + "incorrect value for data[80], expected 231, is {}", + msg.data[80] + ); + assert_eq!( + msg.data[81], 92, + "incorrect value for data[81], expected 92, is {}", + msg.data[81] + ); + assert_eq!( + msg.data[82], 9, + "incorrect value for data[82], expected 9, is {}", + msg.data[82] + ); + assert_eq!( + msg.data[83], 196, + "incorrect value for data[83], expected 196, is {}", + msg.data[83] + ); + assert_eq!( + msg.data[84], 106, + "incorrect value for data[84], expected 106, is {}", + msg.data[84] + ); + assert_eq!( + msg.data[85], 246, + "incorrect value for data[85], expected 246, is {}", + msg.data[85] + ); + assert_eq!( + msg.data[86], 29, + "incorrect value for data[86], expected 29, is {}", + msg.data[86] + ); + assert_eq!( + msg.data[87], 145, + "incorrect value for data[87], expected 145, is {}", + msg.data[87] + ); + assert_eq!( + msg.data[88], 156, + "incorrect value for data[88], expected 156, is {}", + msg.data[88] + ); + assert_eq!( + msg.data[89], 151, + "incorrect value for data[89], expected 151, is {}", + msg.data[89] + ); + assert_eq!( + msg.data[90], 32, + "incorrect value for data[90], expected 32, is {}", + msg.data[90] + ); + assert_eq!( + msg.data[91], 67, + "incorrect value for data[91], expected 67, is {}", + msg.data[91] + ); + assert_eq!( + msg.data[92], 188, + "incorrect value for data[92], expected 188, is {}", + msg.data[92] + ); + assert_eq!( + msg.data[93], 63, + "incorrect value for data[93], expected 63, is {}", + msg.data[93] + ); + assert_eq!( + msg.data[94], 233, + "incorrect value for data[94], expected 233, is {}", + msg.data[94] + ); + assert_eq!( + msg.data[95], 142, + "incorrect value for data[95], expected 142, is {}", + msg.data[95] + ); + assert_eq!( + msg.data[96], 174, + "incorrect value for data[96], expected 174, is {}", + msg.data[96] + ); + assert_eq!( + msg.data[97], 139, + "incorrect value for data[97], expected 139, is {}", + msg.data[97] + ); + assert_eq!( + msg.data[98], 154, + "incorrect value for data[98], expected 154, is {}", + msg.data[98] + ); + assert_eq!( + msg.data[99], 127, + "incorrect value for data[99], expected 127, is {}", + msg.data[99] + ); + assert_eq!( + msg.data[100], 35, + "incorrect value for data[100], expected 35, is {}", + msg.data[100] + ); + assert_eq!( + msg.data[101], 60, + "incorrect value for data[101], expected 60, is {}", + msg.data[101] + ); + assert_eq!( + msg.data[102], 56, + "incorrect value for data[102], expected 56, is {}", + msg.data[102] + ); + assert_eq!( + msg.data[103], 187, + "incorrect value for data[103], expected 187, is {}", + msg.data[103] + ); + assert_eq!( + msg.data[104], 121, + "incorrect value for data[104], expected 121, is {}", + msg.data[104] + ); + assert_eq!( + msg.data[105], 103, + "incorrect value for data[105], expected 103, is {}", + msg.data[105] + ); + assert_eq!( + msg.data[106], 135, + "incorrect value for data[106], expected 135, is {}", + msg.data[106] + ); + assert_eq!( + msg.data[107], 152, + "incorrect value for data[107], expected 152, is {}", + msg.data[107] + ); + assert_eq!( + msg.data[108], 182, + "incorrect value for data[108], expected 182, is {}", + msg.data[108] + ); + assert_eq!( + msg.data[109], 88, + "incorrect value for data[109], expected 88, is {}", + msg.data[109] + ); + assert_eq!( + msg.data[110], 160, + "incorrect value for data[110], expected 160, is {}", + msg.data[110] + ); + assert_eq!( + msg.data[111], 255, + "incorrect value for data[111], expected 255, is {}", + msg.data[111] + ); + assert_eq!( + msg.data[112], 227, + "incorrect value for data[112], expected 227, is {}", + msg.data[112] + ); + assert_eq!( + msg.data[113], 240, + "incorrect value for data[113], expected 240, is {}", + msg.data[113] + ); + assert_eq!( + msg.data[114], 54, + "incorrect value for data[114], expected 54, is {}", + msg.data[114] + ); + assert_eq!( + msg.data[115], 100, + "incorrect value for data[115], expected 100, is {}", + msg.data[115] + ); + assert_eq!( + msg.data[116], 91, + "incorrect value for data[116], expected 91, is {}", + msg.data[116] + ); + assert_eq!( + msg.data[117], 31, + "incorrect value for data[117], expected 31, is {}", + msg.data[117] + ); + assert_eq!( + msg.data[118], 141, + "incorrect value for data[118], expected 141, is {}", + msg.data[118] + ); + assert_eq!( + msg.data[119], 102, + "incorrect value for data[119], expected 102, is {}", + msg.data[119] + ); + assert_eq!( + msg.data[120], 130, + "incorrect value for data[120], expected 130, is {}", + msg.data[120] + ); + assert_eq!( + msg.data[121], 254, + "incorrect value for data[121], expected 254, is {}", + msg.data[121] + ); + assert_eq!( + msg.data[122], 54, + "incorrect value for data[122], expected 54, is {}", + msg.data[122] + ); + assert_eq!( + msg.data[123], 227, + "incorrect value for data[123], expected 227, is {}", + msg.data[123] + ); + assert_eq!( + msg.data[124], 229, + "incorrect value for data[124], expected 229, is {}", + msg.data[124] + ); + assert_eq!( + msg.data[125], 62, + "incorrect value for data[125], expected 62, is {}", + msg.data[125] + ); + assert_eq!( + msg.data[126], 53, + "incorrect value for data[126], expected 53, is {}", + msg.data[126] + ); + assert_eq!( + msg.data[127], 225, + "incorrect value for data[127], expected 225, is {}", + msg.data[127] + ); + assert_eq!( + msg.data[128], 143, + "incorrect value for data[128], expected 143, is {}", + msg.data[128] + ); + assert_eq!( + msg.data[129], 88, + "incorrect value for data[129], expected 88, is {}", + msg.data[129] + ); + assert_eq!( + msg.data[130], 139, + "incorrect value for data[130], expected 139, is {}", + msg.data[130] + ); + assert_eq!( + msg.data[131], 126, + "incorrect value for data[131], expected 126, is {}", + msg.data[131] + ); + assert_eq!( + msg.data[132], 235, + "incorrect value for data[132], expected 235, is {}", + msg.data[132] + ); + assert_eq!( + msg.data[133], 235, + "incorrect value for data[133], expected 235, is {}", + msg.data[133] + ); + assert_eq!( + msg.data[134], 35, + "incorrect value for data[134], expected 35, is {}", + msg.data[134] + ); + assert_eq!( + msg.data[135], 54, + "incorrect value for data[135], expected 54, is {}", + msg.data[135] + ); + assert_eq!( + msg.data[136], 134, + "incorrect value for data[136], expected 134, is {}", + msg.data[136] + ); + assert_eq!( + msg.data[137], 163, + "incorrect value for data[137], expected 163, is {}", + msg.data[137] + ); + assert_eq!( + msg.data[138], 92, + "incorrect value for data[138], expected 92, is {}", + msg.data[138] + ); + assert_eq!( + msg.data[139], 57, + "incorrect value for data[139], expected 57, is {}", + msg.data[139] + ); + assert_eq!( + msg.data[140], 87, + "incorrect value for data[140], expected 87, is {}", + msg.data[140] + ); + assert_eq!( + msg.data[141], 130, + "incorrect value for data[141], expected 130, is {}", + msg.data[141] + ); + assert_eq!( + msg.data[142], 178, + "incorrect value for data[142], expected 178, is {}", + msg.data[142] + ); + assert_eq!( + msg.data[143], 22, + "incorrect value for data[143], expected 22, is {}", + msg.data[143] + ); + assert_eq!( + msg.data[144], 158, + "incorrect value for data[144], expected 158, is {}", + msg.data[144] + ); + assert_eq!( + msg.data[145], 18, + "incorrect value for data[145], expected 18, is {}", + msg.data[145] + ); + assert_eq!( + msg.data[146], 237, + "incorrect value for data[146], expected 237, is {}", + msg.data[146] + ); + assert_eq!( + msg.data[147], 209, + "incorrect value for data[147], expected 209, is {}", + msg.data[147] + ); + assert_eq!( + msg.data[148], 187, + "incorrect value for data[148], expected 187, is {}", + msg.data[148] + ); + assert_eq!( + msg.data[149], 226, + "incorrect value for data[149], expected 226, is {}", + msg.data[149] + ); + assert_eq!( + msg.data[150], 1, + "incorrect value for data[150], expected 1, is {}", + msg.data[150] + ); + assert_eq!( + msg.data[151], 46, + "incorrect value for data[151], expected 46, is {}", + msg.data[151] + ); + assert_eq!( + msg.data[152], 64, + "incorrect value for data[152], expected 64, is {}", + msg.data[152] + ); + assert_eq!( + msg.data[153], 226, + "incorrect value for data[153], expected 226, is {}", + msg.data[153] + ); + assert_eq!( + msg.data[154], 235, + "incorrect value for data[154], expected 235, is {}", + msg.data[154] + ); + assert_eq!( + msg.data[155], 213, + "incorrect value for data[155], expected 213, is {}", + msg.data[155] + ); + assert_eq!( + msg.data[156], 186, + "incorrect value for data[156], expected 186, is {}", + msg.data[156] + ); + assert_eq!( + msg.data[157], 159, + "incorrect value for data[157], expected 159, is {}", + msg.data[157] + ); + assert_eq!( + msg.data[158], 221, + "incorrect value for data[158], expected 221, is {}", + msg.data[158] + ); + assert_eq!( + msg.data[159], 186, + "incorrect value for data[159], expected 186, is {}", + msg.data[159] + ); + assert_eq!( + msg.data[160], 25, + "incorrect value for data[160], expected 25, is {}", + msg.data[160] + ); + assert_eq!( + msg.data[161], 115, + "incorrect value for data[161], expected 115, is {}", + msg.data[161] + ); + assert_eq!( + msg.data[162], 84, + "incorrect value for data[162], expected 84, is {}", + msg.data[162] + ); + assert_eq!( + msg.data[163], 131, + "incorrect value for data[163], expected 131, is {}", + msg.data[163] + ); + assert_eq!( + msg.data[164], 167, + "incorrect value for data[164], expected 167, is {}", + msg.data[164] + ); + assert_eq!( + msg.data[165], 201, + "incorrect value for data[165], expected 201, is {}", + msg.data[165] + ); + assert_eq!( + msg.data[166], 104, + "incorrect value for data[166], expected 104, is {}", + msg.data[166] + ); + assert_eq!( + msg.data[167], 1, + "incorrect value for data[167], expected 1, is {}", + msg.data[167] + ); + assert_eq!( + msg.data[168], 200, + "incorrect value for data[168], expected 200, is {}", + msg.data[168] + ); + assert_eq!( + msg.data[169], 13, + "incorrect value for data[169], expected 13, is {}", + msg.data[169] + ); + assert_eq!( + msg.data[170], 50, + "incorrect value for data[170], expected 50, is {}", + msg.data[170] + ); + assert_eq!( + msg.data[171], 71, + "incorrect value for data[171], expected 71, is {}", + msg.data[171] + ); + assert_eq!( + msg.data[172], 73, + "incorrect value for data[172], expected 73, is {}", + msg.data[172] + ); + assert_eq!( + msg.data[173], 193, + "incorrect value for data[173], expected 193, is {}", + msg.data[173] + ); + assert_eq!( + msg.data[174], 201, + "incorrect value for data[174], expected 201, is {}", + msg.data[174] + ); + assert_eq!( + msg.data[175], 250, + "incorrect value for data[175], expected 250, is {}", + msg.data[175] + ); + assert_eq!( + msg.data[176], 172, + "incorrect value for data[176], expected 172, is {}", + msg.data[176] + ); + assert_eq!( + msg.data[177], 193, + "incorrect value for data[177], expected 193, is {}", + msg.data[177] + ); + assert_eq!( + msg.data[178], 13, + "incorrect value for data[178], expected 13, is {}", + msg.data[178] + ); + assert_eq!( + msg.data[179], 20, + "incorrect value for data[179], expected 20, is {}", + msg.data[179] + ); + assert_eq!( + msg.data[180], 238, + "incorrect value for data[180], expected 238, is {}", + msg.data[180] + ); + assert_eq!( + msg.data[181], 130, + "incorrect value for data[181], expected 130, is {}", + msg.data[181] + ); + assert_eq!( + msg.data[182], 243, + "incorrect value for data[182], expected 243, is {}", + msg.data[182] + ); + assert_eq!( + msg.data[183], 68, + "incorrect value for data[183], expected 68, is {}", + msg.data[183] + ); + assert_eq!( + msg.data[184], 4, + "incorrect value for data[184], expected 4, is {}", + msg.data[184] + ); + assert_eq!( + msg.data[185], 72, + "incorrect value for data[185], expected 72, is {}", + msg.data[185] + ); + assert_eq!( + msg.data[186], 46, + "incorrect value for data[186], expected 46, is {}", + msg.data[186] + ); + assert_eq!( + msg.data[187], 194, + "incorrect value for data[187], expected 194, is {}", + msg.data[187] + ); + assert_eq!( + msg.data[188], 113, + "incorrect value for data[188], expected 113, is {}", + msg.data[188] + ); + assert_eq!( + msg.data[189], 255, + "incorrect value for data[189], expected 255, is {}", + msg.data[189] + ); + assert_eq!( + msg.data[190], 238, + "incorrect value for data[190], expected 238, is {}", + msg.data[190] + ); + assert_eq!( + msg.data[191], 15, + "incorrect value for data[191], expected 15, is {}", + msg.data[191] + ); + assert_eq!( + msg.data[192], 230, + "incorrect value for data[192], expected 230, is {}", + msg.data[192] + ); + assert_eq!( + msg.data[193], 64, + "incorrect value for data[193], expected 64, is {}", + msg.data[193] + ); + assert_eq!( + msg.data[194], 178, + "incorrect value for data[194], expected 178, is {}", + msg.data[194] + ); + assert_eq!( + msg.data[195], 127, + "incorrect value for data[195], expected 127, is {}", + msg.data[195] + ); + assert_eq!( + msg.data[196], 217, + "incorrect value for data[196], expected 217, is {}", + msg.data[196] + ); + assert_eq!( + msg.data[197], 92, + "incorrect value for data[197], expected 92, is {}", + msg.data[197] + ); + assert_eq!( + msg.data[198], 160, + "incorrect value for data[198], expected 160, is {}", + msg.data[198] + ); + assert_eq!( + msg.data[199], 201, + "incorrect value for data[199], expected 201, is {}", + msg.data[199] + ); + assert_eq!( + msg.data[200], 118, + "incorrect value for data[200], expected 118, is {}", + msg.data[200] + ); + assert_eq!( + msg.data[201], 163, + "incorrect value for data[201], expected 163, is {}", + msg.data[201] + ); + assert_eq!( + msg.data[202], 144, + "incorrect value for data[202], expected 144, is {}", + msg.data[202] + ); + assert_eq!( + msg.data[203], 58, + "incorrect value for data[203], expected 58, is {}", + msg.data[203] + ); + assert_eq!( + msg.data[204], 28, + "incorrect value for data[204], expected 28, is {}", + msg.data[204] + ); + assert_eq!( + msg.data[205], 174, + "incorrect value for data[205], expected 174, is {}", + msg.data[205] + ); + assert_eq!( + msg.data[206], 65, + "incorrect value for data[206], expected 65, is {}", + msg.data[206] + ); + assert_eq!( + msg.data[207], 73, + "incorrect value for data[207], expected 73, is {}", + msg.data[207] + ); + assert_eq!( + msg.data[208], 45, + "incorrect value for data[208], expected 45, is {}", + msg.data[208] + ); + assert_eq!( + msg.data[209], 123, + "incorrect value for data[209], expected 123, is {}", + msg.data[209] + ); + assert_eq!( + msg.data[210], 118, + "incorrect value for data[210], expected 118, is {}", + msg.data[210] + ); + assert_eq!( + msg.data[211], 83, + "incorrect value for data[211], expected 83, is {}", + msg.data[211] + ); + assert_eq!( + msg.data[212], 107, + "incorrect value for data[212], expected 107, is {}", + msg.data[212] + ); + assert_eq!( + msg.data[213], 239, + "incorrect value for data[213], expected 239, is {}", + msg.data[213] + ); + assert_eq!( + msg.data[214], 168, + "incorrect value for data[214], expected 168, is {}", + msg.data[214] + ); + assert_eq!( + msg.data[215], 32, + "incorrect value for data[215], expected 32, is {}", + msg.data[215] + ); + assert_eq!( + msg.data[216], 212, + "incorrect value for data[216], expected 212, is {}", + msg.data[216] + ); + assert_eq!( + msg.data[217], 191, + "incorrect value for data[217], expected 191, is {}", + msg.data[217] + ); + assert_eq!( + msg.data[218], 81, + "incorrect value for data[218], expected 81, is {}", + msg.data[218] + ); + assert_eq!( + msg.data[219], 93, + "incorrect value for data[219], expected 93, is {}", + msg.data[219] + ); + assert_eq!( + msg.data[220], 186, + "incorrect value for data[220], expected 186, is {}", + msg.data[220] + ); + assert_eq!( + msg.data[221], 223, + "incorrect value for data[221], expected 223, is {}", + msg.data[221] + ); + assert_eq!( + msg.data[222], 32, + "incorrect value for data[222], expected 32, is {}", + msg.data[222] + ); + assert_eq!( + msg.data[223], 19, + "incorrect value for data[223], expected 19, is {}", + msg.data[223] + ); + assert_eq!( + msg.data[224], 58, + "incorrect value for data[224], expected 58, is {}", + msg.data[224] + ); + assert_eq!( + msg.data[225], 137, + "incorrect value for data[225], expected 137, is {}", + msg.data[225] + ); + assert_eq!( + msg.data[226], 72, + "incorrect value for data[226], expected 72, is {}", + msg.data[226] + ); + assert_eq!( + msg.data[227], 217, + "incorrect value for data[227], expected 217, is {}", + msg.data[227] + ); + assert_eq!( + msg.data[228], 151, + "incorrect value for data[228], expected 151, is {}", + msg.data[228] + ); + assert_eq!( + msg.data[229], 251, + "incorrect value for data[229], expected 251, is {}", + msg.data[229] + ); + assert_eq!( + msg.data[230], 83, + "incorrect value for data[230], expected 83, is {}", + msg.data[230] + ); + assert_eq!( + msg.data[231], 20, + "incorrect value for data[231], expected 20, is {}", + msg.data[231] + ); + assert_eq!( + msg.data[232], 113, + "incorrect value for data[232], expected 113, is {}", + msg.data[232] + ); + assert_eq!( + msg.data[233], 37, + "incorrect value for data[233], expected 37, is {}", + msg.data[233] + ); + assert_eq!( + msg.data[234], 151, + "incorrect value for data[234], expected 151, is {}", + msg.data[234] + ); + assert_eq!( + msg.data[235], 34, + "incorrect value for data[235], expected 34, is {}", + msg.data[235] + ); + assert_eq!( + msg.data[236], 37, + "incorrect value for data[236], expected 37, is {}", + msg.data[236] + ); + assert_eq!( + msg.data[237], 71, + "incorrect value for data[237], expected 71, is {}", + msg.data[237] + ); + assert_eq!( + msg.data[238], 95, + "incorrect value for data[238], expected 95, is {}", + msg.data[238] + ); + assert_eq!( + msg.data[239], 105, + "incorrect value for data[239], expected 105, is {}", + msg.data[239] + ); + assert_eq!( + msg.data[240], 235, + "incorrect value for data[240], expected 235, is {}", + msg.data[240] + ); + assert_eq!( + msg.data[241], 144, + "incorrect value for data[241], expected 144, is {}", + msg.data[241] + ); + assert_eq!( + msg.data[242], 164, + "incorrect value for data[242], expected 164, is {}", + msg.data[242] + ); + assert_eq!( + msg.data[243], 83, + "incorrect value for data[243], expected 83, is {}", + msg.data[243] + ); + assert_eq!( + msg.data[244], 197, + "incorrect value for data[244], expected 197, is {}", + msg.data[244] + ); + assert_eq!( + msg.data[245], 254, + "incorrect value for data[245], expected 254, is {}", + msg.data[245] + ); + assert_eq!( + msg.data[246], 183, + "incorrect value for data[246], expected 183, is {}", + msg.data[246] + ); + assert_eq!( + msg.data[247], 223, + "incorrect value for data[247], expected 223, is {}", + msg.data[247] + ); + assert_eq!( + msg.data[248], 91, + "incorrect value for data[248], expected 91, is {}", + msg.data[248] + ); + assert_eq!( + msg.data[249], 19, + "incorrect value for data[249], expected 19, is {}", + msg.data[249] + ); + assert_eq!( + msg.target, 212, + "incorrect value for target, expected 212, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashProgram"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_flash_program() { + { + let json_input = r#"{"crc":58157,"length":255,"msg_type":230,"payload":"1Fc09Pqw3utqkB2N/wMQwO2s/tUE3GIi3ubWBtmsei4NJvDsPHkv/KON3h2o1nY3yekV1jn19hMDeTHnJbo67mInRuiFGQqGgUXkhglYt4Wr/6ZkmOdcCcRq9h2RnJcgQ7w/6Y6ui5p/Izw4u3lnh5i2WKD/4/A2ZFsfjWaC/jbj5T414Y9Yi37r6yM2hqNcOVeCshaeEu3Ru+IBLkDi69W6n926GXNUg6fJaAHIDTJHScHJ+qzBDRTugvNEBEguwnH/7g/mQLJ/2VygyXajkDocrkFJLXt2U2vvqCDUv1Fdut8gEzqJSNmX+1MUcSWXIiVHX2nrkKRTxf6331sT","preamble":85,"sender":1219,"target":212,"addr_start":[87,52,244],"addr_len":250,"data":[176,222,235,106,144,29,141,255,3,16,192,237,172,254,213,4,220,98,34,222,230,214,6,217,172,122,46,13,38,240,236,60,121,47,252,163,141,222,29,168,214,118,55,201,233,21,214,57,245,246,19,3,121,49,231,37,186,58,238,98,39,70,232,133,25,10,134,129,69,228,134,9,88,183,133,171,255,166,100,152,231,92,9,196,106,246,29,145,156,151,32,67,188,63,233,142,174,139,154,127,35,60,56,187,121,103,135,152,182,88,160,255,227,240,54,100,91,31,141,102,130,254,54,227,229,62,53,225,143,88,139,126,235,235,35,54,134,163,92,57,87,130,178,22,158,18,237,209,187,226,1,46,64,226,235,213,186,159,221,186,25,115,84,131,167,201,104,1,200,13,50,71,73,193,201,250,172,193,13,20,238,130,243,68,4,72,46,194,113,255,238,15,230,64,178,127,217,92,160,201,118,163,144,58,28,174,65,73,45,123,118,83,107,239,168,32,212,191,81,93,186,223,32,19,58,137,72,217,151,251,83,20,113,37,151,34,37,71,95,105,235,144,164,83,197,254,183,223,91,19]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashProgram(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe6, + "Incorrect message type, expected 0xe6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 250, + "incorrect value for addr_len, expected 250, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 87, + "incorrect value for addr_start[0], expected 87, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.data[0], 176, + "incorrect value for data[0], expected 176, is {}", + msg.data[0] + ); + assert_eq!( + msg.data[1], 222, + "incorrect value for data[1], expected 222, is {}", + msg.data[1] + ); + assert_eq!( + msg.data[2], 235, + "incorrect value for data[2], expected 235, is {}", + msg.data[2] + ); + assert_eq!( + msg.data[3], 106, + "incorrect value for data[3], expected 106, is {}", + msg.data[3] + ); + assert_eq!( + msg.data[4], 144, + "incorrect value for data[4], expected 144, is {}", + msg.data[4] + ); + assert_eq!( + msg.data[5], 29, + "incorrect value for data[5], expected 29, is {}", + msg.data[5] + ); + assert_eq!( + msg.data[6], 141, + "incorrect value for data[6], expected 141, is {}", + msg.data[6] + ); + assert_eq!( + msg.data[7], 255, + "incorrect value for data[7], expected 255, is {}", + msg.data[7] + ); + assert_eq!( + msg.data[8], 3, + "incorrect value for data[8], expected 3, is {}", + msg.data[8] + ); + assert_eq!( + msg.data[9], 16, + "incorrect value for data[9], expected 16, is {}", + msg.data[9] + ); + assert_eq!( + msg.data[10], 192, + "incorrect value for data[10], expected 192, is {}", + msg.data[10] + ); + assert_eq!( + msg.data[11], 237, + "incorrect value for data[11], expected 237, is {}", + msg.data[11] + ); + assert_eq!( + msg.data[12], 172, + "incorrect value for data[12], expected 172, is {}", + msg.data[12] + ); + assert_eq!( + msg.data[13], 254, + "incorrect value for data[13], expected 254, is {}", + msg.data[13] + ); + assert_eq!( + msg.data[14], 213, + "incorrect value for data[14], expected 213, is {}", + msg.data[14] + ); + assert_eq!( + msg.data[15], 4, + "incorrect value for data[15], expected 4, is {}", + msg.data[15] + ); + assert_eq!( + msg.data[16], 220, + "incorrect value for data[16], expected 220, is {}", + msg.data[16] + ); + assert_eq!( + msg.data[17], 98, + "incorrect value for data[17], expected 98, is {}", + msg.data[17] + ); + assert_eq!( + msg.data[18], 34, + "incorrect value for data[18], expected 34, is {}", + msg.data[18] + ); + assert_eq!( + msg.data[19], 222, + "incorrect value for data[19], expected 222, is {}", + msg.data[19] + ); + assert_eq!( + msg.data[20], 230, + "incorrect value for data[20], expected 230, is {}", + msg.data[20] + ); + assert_eq!( + msg.data[21], 214, + "incorrect value for data[21], expected 214, is {}", + msg.data[21] + ); + assert_eq!( + msg.data[22], 6, + "incorrect value for data[22], expected 6, is {}", + msg.data[22] + ); + assert_eq!( + msg.data[23], 217, + "incorrect value for data[23], expected 217, is {}", + msg.data[23] + ); + assert_eq!( + msg.data[24], 172, + "incorrect value for data[24], expected 172, is {}", + msg.data[24] + ); + assert_eq!( + msg.data[25], 122, + "incorrect value for data[25], expected 122, is {}", + msg.data[25] + ); + assert_eq!( + msg.data[26], 46, + "incorrect value for data[26], expected 46, is {}", + msg.data[26] + ); + assert_eq!( + msg.data[27], 13, + "incorrect value for data[27], expected 13, is {}", + msg.data[27] + ); + assert_eq!( + msg.data[28], 38, + "incorrect value for data[28], expected 38, is {}", + msg.data[28] + ); + assert_eq!( + msg.data[29], 240, + "incorrect value for data[29], expected 240, is {}", + msg.data[29] + ); + assert_eq!( + msg.data[30], 236, + "incorrect value for data[30], expected 236, is {}", + msg.data[30] + ); + assert_eq!( + msg.data[31], 60, + "incorrect value for data[31], expected 60, is {}", + msg.data[31] + ); + assert_eq!( + msg.data[32], 121, + "incorrect value for data[32], expected 121, is {}", + msg.data[32] + ); + assert_eq!( + msg.data[33], 47, + "incorrect value for data[33], expected 47, is {}", + msg.data[33] + ); + assert_eq!( + msg.data[34], 252, + "incorrect value for data[34], expected 252, is {}", + msg.data[34] + ); + assert_eq!( + msg.data[35], 163, + "incorrect value for data[35], expected 163, is {}", + msg.data[35] + ); + assert_eq!( + msg.data[36], 141, + "incorrect value for data[36], expected 141, is {}", + msg.data[36] + ); + assert_eq!( + msg.data[37], 222, + "incorrect value for data[37], expected 222, is {}", + msg.data[37] + ); + assert_eq!( + msg.data[38], 29, + "incorrect value for data[38], expected 29, is {}", + msg.data[38] + ); + assert_eq!( + msg.data[39], 168, + "incorrect value for data[39], expected 168, is {}", + msg.data[39] + ); + assert_eq!( + msg.data[40], 214, + "incorrect value for data[40], expected 214, is {}", + msg.data[40] + ); + assert_eq!( + msg.data[41], 118, + "incorrect value for data[41], expected 118, is {}", + msg.data[41] + ); + assert_eq!( + msg.data[42], 55, + "incorrect value for data[42], expected 55, is {}", + msg.data[42] + ); + assert_eq!( + msg.data[43], 201, + "incorrect value for data[43], expected 201, is {}", + msg.data[43] + ); + assert_eq!( + msg.data[44], 233, + "incorrect value for data[44], expected 233, is {}", + msg.data[44] + ); + assert_eq!( + msg.data[45], 21, + "incorrect value for data[45], expected 21, is {}", + msg.data[45] + ); + assert_eq!( + msg.data[46], 214, + "incorrect value for data[46], expected 214, is {}", + msg.data[46] + ); + assert_eq!( + msg.data[47], 57, + "incorrect value for data[47], expected 57, is {}", + msg.data[47] + ); + assert_eq!( + msg.data[48], 245, + "incorrect value for data[48], expected 245, is {}", + msg.data[48] + ); + assert_eq!( + msg.data[49], 246, + "incorrect value for data[49], expected 246, is {}", + msg.data[49] + ); + assert_eq!( + msg.data[50], 19, + "incorrect value for data[50], expected 19, is {}", + msg.data[50] + ); + assert_eq!( + msg.data[51], 3, + "incorrect value for data[51], expected 3, is {}", + msg.data[51] + ); + assert_eq!( + msg.data[52], 121, + "incorrect value for data[52], expected 121, is {}", + msg.data[52] + ); + assert_eq!( + msg.data[53], 49, + "incorrect value for data[53], expected 49, is {}", + msg.data[53] + ); + assert_eq!( + msg.data[54], 231, + "incorrect value for data[54], expected 231, is {}", + msg.data[54] + ); + assert_eq!( + msg.data[55], 37, + "incorrect value for data[55], expected 37, is {}", + msg.data[55] + ); + assert_eq!( + msg.data[56], 186, + "incorrect value for data[56], expected 186, is {}", + msg.data[56] + ); + assert_eq!( + msg.data[57], 58, + "incorrect value for data[57], expected 58, is {}", + msg.data[57] + ); + assert_eq!( + msg.data[58], 238, + "incorrect value for data[58], expected 238, is {}", + msg.data[58] + ); + assert_eq!( + msg.data[59], 98, + "incorrect value for data[59], expected 98, is {}", + msg.data[59] + ); + assert_eq!( + msg.data[60], 39, + "incorrect value for data[60], expected 39, is {}", + msg.data[60] + ); + assert_eq!( + msg.data[61], 70, + "incorrect value for data[61], expected 70, is {}", + msg.data[61] + ); + assert_eq!( + msg.data[62], 232, + "incorrect value for data[62], expected 232, is {}", + msg.data[62] + ); + assert_eq!( + msg.data[63], 133, + "incorrect value for data[63], expected 133, is {}", + msg.data[63] + ); + assert_eq!( + msg.data[64], 25, + "incorrect value for data[64], expected 25, is {}", + msg.data[64] + ); + assert_eq!( + msg.data[65], 10, + "incorrect value for data[65], expected 10, is {}", + msg.data[65] + ); + assert_eq!( + msg.data[66], 134, + "incorrect value for data[66], expected 134, is {}", + msg.data[66] + ); + assert_eq!( + msg.data[67], 129, + "incorrect value for data[67], expected 129, is {}", + msg.data[67] + ); + assert_eq!( + msg.data[68], 69, + "incorrect value for data[68], expected 69, is {}", + msg.data[68] + ); + assert_eq!( + msg.data[69], 228, + "incorrect value for data[69], expected 228, is {}", + msg.data[69] + ); + assert_eq!( + msg.data[70], 134, + "incorrect value for data[70], expected 134, is {}", + msg.data[70] + ); + assert_eq!( + msg.data[71], 9, + "incorrect value for data[71], expected 9, is {}", + msg.data[71] + ); + assert_eq!( + msg.data[72], 88, + "incorrect value for data[72], expected 88, is {}", + msg.data[72] + ); + assert_eq!( + msg.data[73], 183, + "incorrect value for data[73], expected 183, is {}", + msg.data[73] + ); + assert_eq!( + msg.data[74], 133, + "incorrect value for data[74], expected 133, is {}", + msg.data[74] + ); + assert_eq!( + msg.data[75], 171, + "incorrect value for data[75], expected 171, is {}", + msg.data[75] + ); + assert_eq!( + msg.data[76], 255, + "incorrect value for data[76], expected 255, is {}", + msg.data[76] + ); + assert_eq!( + msg.data[77], 166, + "incorrect value for data[77], expected 166, is {}", + msg.data[77] + ); + assert_eq!( + msg.data[78], 100, + "incorrect value for data[78], expected 100, is {}", + msg.data[78] + ); + assert_eq!( + msg.data[79], 152, + "incorrect value for data[79], expected 152, is {}", + msg.data[79] + ); + assert_eq!( + msg.data[80], 231, + "incorrect value for data[80], expected 231, is {}", + msg.data[80] + ); + assert_eq!( + msg.data[81], 92, + "incorrect value for data[81], expected 92, is {}", + msg.data[81] + ); + assert_eq!( + msg.data[82], 9, + "incorrect value for data[82], expected 9, is {}", + msg.data[82] + ); + assert_eq!( + msg.data[83], 196, + "incorrect value for data[83], expected 196, is {}", + msg.data[83] + ); + assert_eq!( + msg.data[84], 106, + "incorrect value for data[84], expected 106, is {}", + msg.data[84] + ); + assert_eq!( + msg.data[85], 246, + "incorrect value for data[85], expected 246, is {}", + msg.data[85] + ); + assert_eq!( + msg.data[86], 29, + "incorrect value for data[86], expected 29, is {}", + msg.data[86] + ); + assert_eq!( + msg.data[87], 145, + "incorrect value for data[87], expected 145, is {}", + msg.data[87] + ); + assert_eq!( + msg.data[88], 156, + "incorrect value for data[88], expected 156, is {}", + msg.data[88] + ); + assert_eq!( + msg.data[89], 151, + "incorrect value for data[89], expected 151, is {}", + msg.data[89] + ); + assert_eq!( + msg.data[90], 32, + "incorrect value for data[90], expected 32, is {}", + msg.data[90] + ); + assert_eq!( + msg.data[91], 67, + "incorrect value for data[91], expected 67, is {}", + msg.data[91] + ); + assert_eq!( + msg.data[92], 188, + "incorrect value for data[92], expected 188, is {}", + msg.data[92] + ); + assert_eq!( + msg.data[93], 63, + "incorrect value for data[93], expected 63, is {}", + msg.data[93] + ); + assert_eq!( + msg.data[94], 233, + "incorrect value for data[94], expected 233, is {}", + msg.data[94] + ); + assert_eq!( + msg.data[95], 142, + "incorrect value for data[95], expected 142, is {}", + msg.data[95] + ); + assert_eq!( + msg.data[96], 174, + "incorrect value for data[96], expected 174, is {}", + msg.data[96] + ); + assert_eq!( + msg.data[97], 139, + "incorrect value for data[97], expected 139, is {}", + msg.data[97] + ); + assert_eq!( + msg.data[98], 154, + "incorrect value for data[98], expected 154, is {}", + msg.data[98] + ); + assert_eq!( + msg.data[99], 127, + "incorrect value for data[99], expected 127, is {}", + msg.data[99] + ); + assert_eq!( + msg.data[100], 35, + "incorrect value for data[100], expected 35, is {}", + msg.data[100] + ); + assert_eq!( + msg.data[101], 60, + "incorrect value for data[101], expected 60, is {}", + msg.data[101] + ); + assert_eq!( + msg.data[102], 56, + "incorrect value for data[102], expected 56, is {}", + msg.data[102] + ); + assert_eq!( + msg.data[103], 187, + "incorrect value for data[103], expected 187, is {}", + msg.data[103] + ); + assert_eq!( + msg.data[104], 121, + "incorrect value for data[104], expected 121, is {}", + msg.data[104] + ); + assert_eq!( + msg.data[105], 103, + "incorrect value for data[105], expected 103, is {}", + msg.data[105] + ); + assert_eq!( + msg.data[106], 135, + "incorrect value for data[106], expected 135, is {}", + msg.data[106] + ); + assert_eq!( + msg.data[107], 152, + "incorrect value for data[107], expected 152, is {}", + msg.data[107] + ); + assert_eq!( + msg.data[108], 182, + "incorrect value for data[108], expected 182, is {}", + msg.data[108] + ); + assert_eq!( + msg.data[109], 88, + "incorrect value for data[109], expected 88, is {}", + msg.data[109] + ); + assert_eq!( + msg.data[110], 160, + "incorrect value for data[110], expected 160, is {}", + msg.data[110] + ); + assert_eq!( + msg.data[111], 255, + "incorrect value for data[111], expected 255, is {}", + msg.data[111] + ); + assert_eq!( + msg.data[112], 227, + "incorrect value for data[112], expected 227, is {}", + msg.data[112] + ); + assert_eq!( + msg.data[113], 240, + "incorrect value for data[113], expected 240, is {}", + msg.data[113] + ); + assert_eq!( + msg.data[114], 54, + "incorrect value for data[114], expected 54, is {}", + msg.data[114] + ); + assert_eq!( + msg.data[115], 100, + "incorrect value for data[115], expected 100, is {}", + msg.data[115] + ); + assert_eq!( + msg.data[116], 91, + "incorrect value for data[116], expected 91, is {}", + msg.data[116] + ); + assert_eq!( + msg.data[117], 31, + "incorrect value for data[117], expected 31, is {}", + msg.data[117] + ); + assert_eq!( + msg.data[118], 141, + "incorrect value for data[118], expected 141, is {}", + msg.data[118] + ); + assert_eq!( + msg.data[119], 102, + "incorrect value for data[119], expected 102, is {}", + msg.data[119] + ); + assert_eq!( + msg.data[120], 130, + "incorrect value for data[120], expected 130, is {}", + msg.data[120] + ); + assert_eq!( + msg.data[121], 254, + "incorrect value for data[121], expected 254, is {}", + msg.data[121] + ); + assert_eq!( + msg.data[122], 54, + "incorrect value for data[122], expected 54, is {}", + msg.data[122] + ); + assert_eq!( + msg.data[123], 227, + "incorrect value for data[123], expected 227, is {}", + msg.data[123] + ); + assert_eq!( + msg.data[124], 229, + "incorrect value for data[124], expected 229, is {}", + msg.data[124] + ); + assert_eq!( + msg.data[125], 62, + "incorrect value for data[125], expected 62, is {}", + msg.data[125] + ); + assert_eq!( + msg.data[126], 53, + "incorrect value for data[126], expected 53, is {}", + msg.data[126] + ); + assert_eq!( + msg.data[127], 225, + "incorrect value for data[127], expected 225, is {}", + msg.data[127] + ); + assert_eq!( + msg.data[128], 143, + "incorrect value for data[128], expected 143, is {}", + msg.data[128] + ); + assert_eq!( + msg.data[129], 88, + "incorrect value for data[129], expected 88, is {}", + msg.data[129] + ); + assert_eq!( + msg.data[130], 139, + "incorrect value for data[130], expected 139, is {}", + msg.data[130] + ); + assert_eq!( + msg.data[131], 126, + "incorrect value for data[131], expected 126, is {}", + msg.data[131] + ); + assert_eq!( + msg.data[132], 235, + "incorrect value for data[132], expected 235, is {}", + msg.data[132] + ); + assert_eq!( + msg.data[133], 235, + "incorrect value for data[133], expected 235, is {}", + msg.data[133] + ); + assert_eq!( + msg.data[134], 35, + "incorrect value for data[134], expected 35, is {}", + msg.data[134] + ); + assert_eq!( + msg.data[135], 54, + "incorrect value for data[135], expected 54, is {}", + msg.data[135] + ); + assert_eq!( + msg.data[136], 134, + "incorrect value for data[136], expected 134, is {}", + msg.data[136] + ); + assert_eq!( + msg.data[137], 163, + "incorrect value for data[137], expected 163, is {}", + msg.data[137] + ); + assert_eq!( + msg.data[138], 92, + "incorrect value for data[138], expected 92, is {}", + msg.data[138] + ); + assert_eq!( + msg.data[139], 57, + "incorrect value for data[139], expected 57, is {}", + msg.data[139] + ); + assert_eq!( + msg.data[140], 87, + "incorrect value for data[140], expected 87, is {}", + msg.data[140] + ); + assert_eq!( + msg.data[141], 130, + "incorrect value for data[141], expected 130, is {}", + msg.data[141] + ); + assert_eq!( + msg.data[142], 178, + "incorrect value for data[142], expected 178, is {}", + msg.data[142] + ); + assert_eq!( + msg.data[143], 22, + "incorrect value for data[143], expected 22, is {}", + msg.data[143] + ); + assert_eq!( + msg.data[144], 158, + "incorrect value for data[144], expected 158, is {}", + msg.data[144] + ); + assert_eq!( + msg.data[145], 18, + "incorrect value for data[145], expected 18, is {}", + msg.data[145] + ); + assert_eq!( + msg.data[146], 237, + "incorrect value for data[146], expected 237, is {}", + msg.data[146] + ); + assert_eq!( + msg.data[147], 209, + "incorrect value for data[147], expected 209, is {}", + msg.data[147] + ); + assert_eq!( + msg.data[148], 187, + "incorrect value for data[148], expected 187, is {}", + msg.data[148] + ); + assert_eq!( + msg.data[149], 226, + "incorrect value for data[149], expected 226, is {}", + msg.data[149] + ); + assert_eq!( + msg.data[150], 1, + "incorrect value for data[150], expected 1, is {}", + msg.data[150] + ); + assert_eq!( + msg.data[151], 46, + "incorrect value for data[151], expected 46, is {}", + msg.data[151] + ); + assert_eq!( + msg.data[152], 64, + "incorrect value for data[152], expected 64, is {}", + msg.data[152] + ); + assert_eq!( + msg.data[153], 226, + "incorrect value for data[153], expected 226, is {}", + msg.data[153] + ); + assert_eq!( + msg.data[154], 235, + "incorrect value for data[154], expected 235, is {}", + msg.data[154] + ); + assert_eq!( + msg.data[155], 213, + "incorrect value for data[155], expected 213, is {}", + msg.data[155] + ); + assert_eq!( + msg.data[156], 186, + "incorrect value for data[156], expected 186, is {}", + msg.data[156] + ); + assert_eq!( + msg.data[157], 159, + "incorrect value for data[157], expected 159, is {}", + msg.data[157] + ); + assert_eq!( + msg.data[158], 221, + "incorrect value for data[158], expected 221, is {}", + msg.data[158] + ); + assert_eq!( + msg.data[159], 186, + "incorrect value for data[159], expected 186, is {}", + msg.data[159] + ); + assert_eq!( + msg.data[160], 25, + "incorrect value for data[160], expected 25, is {}", + msg.data[160] + ); + assert_eq!( + msg.data[161], 115, + "incorrect value for data[161], expected 115, is {}", + msg.data[161] + ); + assert_eq!( + msg.data[162], 84, + "incorrect value for data[162], expected 84, is {}", + msg.data[162] + ); + assert_eq!( + msg.data[163], 131, + "incorrect value for data[163], expected 131, is {}", + msg.data[163] + ); + assert_eq!( + msg.data[164], 167, + "incorrect value for data[164], expected 167, is {}", + msg.data[164] + ); + assert_eq!( + msg.data[165], 201, + "incorrect value for data[165], expected 201, is {}", + msg.data[165] + ); + assert_eq!( + msg.data[166], 104, + "incorrect value for data[166], expected 104, is {}", + msg.data[166] + ); + assert_eq!( + msg.data[167], 1, + "incorrect value for data[167], expected 1, is {}", + msg.data[167] + ); + assert_eq!( + msg.data[168], 200, + "incorrect value for data[168], expected 200, is {}", + msg.data[168] + ); + assert_eq!( + msg.data[169], 13, + "incorrect value for data[169], expected 13, is {}", + msg.data[169] + ); + assert_eq!( + msg.data[170], 50, + "incorrect value for data[170], expected 50, is {}", + msg.data[170] + ); + assert_eq!( + msg.data[171], 71, + "incorrect value for data[171], expected 71, is {}", + msg.data[171] + ); + assert_eq!( + msg.data[172], 73, + "incorrect value for data[172], expected 73, is {}", + msg.data[172] + ); + assert_eq!( + msg.data[173], 193, + "incorrect value for data[173], expected 193, is {}", + msg.data[173] + ); + assert_eq!( + msg.data[174], 201, + "incorrect value for data[174], expected 201, is {}", + msg.data[174] + ); + assert_eq!( + msg.data[175], 250, + "incorrect value for data[175], expected 250, is {}", + msg.data[175] + ); + assert_eq!( + msg.data[176], 172, + "incorrect value for data[176], expected 172, is {}", + msg.data[176] + ); + assert_eq!( + msg.data[177], 193, + "incorrect value for data[177], expected 193, is {}", + msg.data[177] + ); + assert_eq!( + msg.data[178], 13, + "incorrect value for data[178], expected 13, is {}", + msg.data[178] + ); + assert_eq!( + msg.data[179], 20, + "incorrect value for data[179], expected 20, is {}", + msg.data[179] + ); + assert_eq!( + msg.data[180], 238, + "incorrect value for data[180], expected 238, is {}", + msg.data[180] + ); + assert_eq!( + msg.data[181], 130, + "incorrect value for data[181], expected 130, is {}", + msg.data[181] + ); + assert_eq!( + msg.data[182], 243, + "incorrect value for data[182], expected 243, is {}", + msg.data[182] + ); + assert_eq!( + msg.data[183], 68, + "incorrect value for data[183], expected 68, is {}", + msg.data[183] + ); + assert_eq!( + msg.data[184], 4, + "incorrect value for data[184], expected 4, is {}", + msg.data[184] + ); + assert_eq!( + msg.data[185], 72, + "incorrect value for data[185], expected 72, is {}", + msg.data[185] + ); + assert_eq!( + msg.data[186], 46, + "incorrect value for data[186], expected 46, is {}", + msg.data[186] + ); + assert_eq!( + msg.data[187], 194, + "incorrect value for data[187], expected 194, is {}", + msg.data[187] + ); + assert_eq!( + msg.data[188], 113, + "incorrect value for data[188], expected 113, is {}", + msg.data[188] + ); + assert_eq!( + msg.data[189], 255, + "incorrect value for data[189], expected 255, is {}", + msg.data[189] + ); + assert_eq!( + msg.data[190], 238, + "incorrect value for data[190], expected 238, is {}", + msg.data[190] + ); + assert_eq!( + msg.data[191], 15, + "incorrect value for data[191], expected 15, is {}", + msg.data[191] + ); + assert_eq!( + msg.data[192], 230, + "incorrect value for data[192], expected 230, is {}", + msg.data[192] + ); + assert_eq!( + msg.data[193], 64, + "incorrect value for data[193], expected 64, is {}", + msg.data[193] + ); + assert_eq!( + msg.data[194], 178, + "incorrect value for data[194], expected 178, is {}", + msg.data[194] + ); + assert_eq!( + msg.data[195], 127, + "incorrect value for data[195], expected 127, is {}", + msg.data[195] + ); + assert_eq!( + msg.data[196], 217, + "incorrect value for data[196], expected 217, is {}", + msg.data[196] + ); + assert_eq!( + msg.data[197], 92, + "incorrect value for data[197], expected 92, is {}", + msg.data[197] + ); + assert_eq!( + msg.data[198], 160, + "incorrect value for data[198], expected 160, is {}", + msg.data[198] + ); + assert_eq!( + msg.data[199], 201, + "incorrect value for data[199], expected 201, is {}", + msg.data[199] + ); + assert_eq!( + msg.data[200], 118, + "incorrect value for data[200], expected 118, is {}", + msg.data[200] + ); + assert_eq!( + msg.data[201], 163, + "incorrect value for data[201], expected 163, is {}", + msg.data[201] + ); + assert_eq!( + msg.data[202], 144, + "incorrect value for data[202], expected 144, is {}", + msg.data[202] + ); + assert_eq!( + msg.data[203], 58, + "incorrect value for data[203], expected 58, is {}", + msg.data[203] + ); + assert_eq!( + msg.data[204], 28, + "incorrect value for data[204], expected 28, is {}", + msg.data[204] + ); + assert_eq!( + msg.data[205], 174, + "incorrect value for data[205], expected 174, is {}", + msg.data[205] + ); + assert_eq!( + msg.data[206], 65, + "incorrect value for data[206], expected 65, is {}", + msg.data[206] + ); + assert_eq!( + msg.data[207], 73, + "incorrect value for data[207], expected 73, is {}", + msg.data[207] + ); + assert_eq!( + msg.data[208], 45, + "incorrect value for data[208], expected 45, is {}", + msg.data[208] + ); + assert_eq!( + msg.data[209], 123, + "incorrect value for data[209], expected 123, is {}", + msg.data[209] + ); + assert_eq!( + msg.data[210], 118, + "incorrect value for data[210], expected 118, is {}", + msg.data[210] + ); + assert_eq!( + msg.data[211], 83, + "incorrect value for data[211], expected 83, is {}", + msg.data[211] + ); + assert_eq!( + msg.data[212], 107, + "incorrect value for data[212], expected 107, is {}", + msg.data[212] + ); + assert_eq!( + msg.data[213], 239, + "incorrect value for data[213], expected 239, is {}", + msg.data[213] + ); + assert_eq!( + msg.data[214], 168, + "incorrect value for data[214], expected 168, is {}", + msg.data[214] + ); + assert_eq!( + msg.data[215], 32, + "incorrect value for data[215], expected 32, is {}", + msg.data[215] + ); + assert_eq!( + msg.data[216], 212, + "incorrect value for data[216], expected 212, is {}", + msg.data[216] + ); + assert_eq!( + msg.data[217], 191, + "incorrect value for data[217], expected 191, is {}", + msg.data[217] + ); + assert_eq!( + msg.data[218], 81, + "incorrect value for data[218], expected 81, is {}", + msg.data[218] + ); + assert_eq!( + msg.data[219], 93, + "incorrect value for data[219], expected 93, is {}", + msg.data[219] + ); + assert_eq!( + msg.data[220], 186, + "incorrect value for data[220], expected 186, is {}", + msg.data[220] + ); + assert_eq!( + msg.data[221], 223, + "incorrect value for data[221], expected 223, is {}", + msg.data[221] + ); + assert_eq!( + msg.data[222], 32, + "incorrect value for data[222], expected 32, is {}", + msg.data[222] + ); + assert_eq!( + msg.data[223], 19, + "incorrect value for data[223], expected 19, is {}", + msg.data[223] + ); + assert_eq!( + msg.data[224], 58, + "incorrect value for data[224], expected 58, is {}", + msg.data[224] + ); + assert_eq!( + msg.data[225], 137, + "incorrect value for data[225], expected 137, is {}", + msg.data[225] + ); + assert_eq!( + msg.data[226], 72, + "incorrect value for data[226], expected 72, is {}", + msg.data[226] + ); + assert_eq!( + msg.data[227], 217, + "incorrect value for data[227], expected 217, is {}", + msg.data[227] + ); + assert_eq!( + msg.data[228], 151, + "incorrect value for data[228], expected 151, is {}", + msg.data[228] + ); + assert_eq!( + msg.data[229], 251, + "incorrect value for data[229], expected 251, is {}", + msg.data[229] + ); + assert_eq!( + msg.data[230], 83, + "incorrect value for data[230], expected 83, is {}", + msg.data[230] + ); + assert_eq!( + msg.data[231], 20, + "incorrect value for data[231], expected 20, is {}", + msg.data[231] + ); + assert_eq!( + msg.data[232], 113, + "incorrect value for data[232], expected 113, is {}", + msg.data[232] + ); + assert_eq!( + msg.data[233], 37, + "incorrect value for data[233], expected 37, is {}", + msg.data[233] + ); + assert_eq!( + msg.data[234], 151, + "incorrect value for data[234], expected 151, is {}", + msg.data[234] + ); + assert_eq!( + msg.data[235], 34, + "incorrect value for data[235], expected 34, is {}", + msg.data[235] + ); + assert_eq!( + msg.data[236], 37, + "incorrect value for data[236], expected 37, is {}", + msg.data[236] + ); + assert_eq!( + msg.data[237], 71, + "incorrect value for data[237], expected 71, is {}", + msg.data[237] + ); + assert_eq!( + msg.data[238], 95, + "incorrect value for data[238], expected 95, is {}", + msg.data[238] + ); + assert_eq!( + msg.data[239], 105, + "incorrect value for data[239], expected 105, is {}", + msg.data[239] + ); + assert_eq!( + msg.data[240], 235, + "incorrect value for data[240], expected 235, is {}", + msg.data[240] + ); + assert_eq!( + msg.data[241], 144, + "incorrect value for data[241], expected 144, is {}", + msg.data[241] + ); + assert_eq!( + msg.data[242], 164, + "incorrect value for data[242], expected 164, is {}", + msg.data[242] + ); + assert_eq!( + msg.data[243], 83, + "incorrect value for data[243], expected 83, is {}", + msg.data[243] + ); + assert_eq!( + msg.data[244], 197, + "incorrect value for data[244], expected 197, is {}", + msg.data[244] + ); + assert_eq!( + msg.data[245], 254, + "incorrect value for data[245], expected 254, is {}", + msg.data[245] + ); + assert_eq!( + msg.data[246], 183, + "incorrect value for data[246], expected 183, is {}", + msg.data[246] + ); + assert_eq!( + msg.data[247], 223, + "incorrect value for data[247], expected 223, is {}", + msg.data[247] + ); + assert_eq!( + msg.data[248], 91, + "incorrect value for data[248], expected 91, is {}", + msg.data[248] + ); + assert_eq!( + msg.data[249], 19, + "incorrect value for data[249], expected 19, is {}", + msg.data[249] + ); + assert_eq!( + msg.target, 212, + "incorrect value for target, expected 212, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashProgram"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_flash_program`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_flash_program() { + { + let mut payload = Cursor::new(vec![ + 85, 230, 0, 195, 4, 255, 212, 87, 52, 244, 250, 176, 222, 235, 106, 144, 29, 141, 255, + 3, 16, 192, 237, 172, 254, 213, 4, 220, 98, 34, 222, 230, 214, 6, 217, 172, 122, 46, + 13, 38, 240, 236, 60, 121, 47, 252, 163, 141, 222, 29, 168, 214, 118, 55, 201, 233, 21, + 214, 57, 245, 246, 19, 3, 121, 49, 231, 37, 186, 58, 238, 98, 39, 70, 232, 133, 25, 10, + 134, 129, 69, 228, 134, 9, 88, 183, 133, 171, 255, 166, 100, 152, 231, 92, 9, 196, 106, + 246, 29, 145, 156, 151, 32, 67, 188, 63, 233, 142, 174, 139, 154, 127, 35, 60, 56, 187, + 121, 103, 135, 152, 182, 88, 160, 255, 227, 240, 54, 100, 91, 31, 141, 102, 130, 254, + 54, 227, 229, 62, 53, 225, 143, 88, 139, 126, 235, 235, 35, 54, 134, 163, 92, 57, 87, + 130, 178, 22, 158, 18, 237, 209, 187, 226, 1, 46, 64, 226, 235, 213, 186, 159, 221, + 186, 25, 115, 84, 131, 167, 201, 104, 1, 200, 13, 50, 71, 73, 193, 201, 250, 172, 193, + 13, 20, 238, 130, 243, 68, 4, 72, 46, 194, 113, 255, 238, 15, 230, 64, 178, 127, 217, + 92, 160, 201, 118, 163, 144, 58, 28, 174, 65, 73, 45, 123, 118, 83, 107, 239, 168, 32, + 212, 191, 81, 93, 186, 223, 32, 19, 58, 137, 72, 217, 151, 251, 83, 20, 113, 37, 151, + 34, 37, 71, 95, 105, 235, 144, 164, 83, 197, 254, 183, 223, 91, 19, 45, 227, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFlashProgram( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFlashProgram(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe6, + "Incorrect message type, expected 0xe6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 250, + "incorrect value for addr_len, expected 250, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 87, + "incorrect value for addr_start[0], expected 87, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.data[0], 176, + "incorrect value for data[0], expected 176, is {}", + msg.data[0] + ); + assert_eq!( + msg.data[1], 222, + "incorrect value for data[1], expected 222, is {}", + msg.data[1] + ); + assert_eq!( + msg.data[2], 235, + "incorrect value for data[2], expected 235, is {}", + msg.data[2] + ); + assert_eq!( + msg.data[3], 106, + "incorrect value for data[3], expected 106, is {}", + msg.data[3] + ); + assert_eq!( + msg.data[4], 144, + "incorrect value for data[4], expected 144, is {}", + msg.data[4] + ); + assert_eq!( + msg.data[5], 29, + "incorrect value for data[5], expected 29, is {}", + msg.data[5] + ); + assert_eq!( + msg.data[6], 141, + "incorrect value for data[6], expected 141, is {}", + msg.data[6] + ); + assert_eq!( + msg.data[7], 255, + "incorrect value for data[7], expected 255, is {}", + msg.data[7] + ); + assert_eq!( + msg.data[8], 3, + "incorrect value for data[8], expected 3, is {}", + msg.data[8] + ); + assert_eq!( + msg.data[9], 16, + "incorrect value for data[9], expected 16, is {}", + msg.data[9] + ); + assert_eq!( + msg.data[10], 192, + "incorrect value for data[10], expected 192, is {}", + msg.data[10] + ); + assert_eq!( + msg.data[11], 237, + "incorrect value for data[11], expected 237, is {}", + msg.data[11] + ); + assert_eq!( + msg.data[12], 172, + "incorrect value for data[12], expected 172, is {}", + msg.data[12] + ); + assert_eq!( + msg.data[13], 254, + "incorrect value for data[13], expected 254, is {}", + msg.data[13] + ); + assert_eq!( + msg.data[14], 213, + "incorrect value for data[14], expected 213, is {}", + msg.data[14] + ); + assert_eq!( + msg.data[15], 4, + "incorrect value for data[15], expected 4, is {}", + msg.data[15] + ); + assert_eq!( + msg.data[16], 220, + "incorrect value for data[16], expected 220, is {}", + msg.data[16] + ); + assert_eq!( + msg.data[17], 98, + "incorrect value for data[17], expected 98, is {}", + msg.data[17] + ); + assert_eq!( + msg.data[18], 34, + "incorrect value for data[18], expected 34, is {}", + msg.data[18] + ); + assert_eq!( + msg.data[19], 222, + "incorrect value for data[19], expected 222, is {}", + msg.data[19] + ); + assert_eq!( + msg.data[20], 230, + "incorrect value for data[20], expected 230, is {}", + msg.data[20] + ); + assert_eq!( + msg.data[21], 214, + "incorrect value for data[21], expected 214, is {}", + msg.data[21] + ); + assert_eq!( + msg.data[22], 6, + "incorrect value for data[22], expected 6, is {}", + msg.data[22] + ); + assert_eq!( + msg.data[23], 217, + "incorrect value for data[23], expected 217, is {}", + msg.data[23] + ); + assert_eq!( + msg.data[24], 172, + "incorrect value for data[24], expected 172, is {}", + msg.data[24] + ); + assert_eq!( + msg.data[25], 122, + "incorrect value for data[25], expected 122, is {}", + msg.data[25] + ); + assert_eq!( + msg.data[26], 46, + "incorrect value for data[26], expected 46, is {}", + msg.data[26] + ); + assert_eq!( + msg.data[27], 13, + "incorrect value for data[27], expected 13, is {}", + msg.data[27] + ); + assert_eq!( + msg.data[28], 38, + "incorrect value for data[28], expected 38, is {}", + msg.data[28] + ); + assert_eq!( + msg.data[29], 240, + "incorrect value for data[29], expected 240, is {}", + msg.data[29] + ); + assert_eq!( + msg.data[30], 236, + "incorrect value for data[30], expected 236, is {}", + msg.data[30] + ); + assert_eq!( + msg.data[31], 60, + "incorrect value for data[31], expected 60, is {}", + msg.data[31] + ); + assert_eq!( + msg.data[32], 121, + "incorrect value for data[32], expected 121, is {}", + msg.data[32] + ); + assert_eq!( + msg.data[33], 47, + "incorrect value for data[33], expected 47, is {}", + msg.data[33] + ); + assert_eq!( + msg.data[34], 252, + "incorrect value for data[34], expected 252, is {}", + msg.data[34] + ); + assert_eq!( + msg.data[35], 163, + "incorrect value for data[35], expected 163, is {}", + msg.data[35] + ); + assert_eq!( + msg.data[36], 141, + "incorrect value for data[36], expected 141, is {}", + msg.data[36] + ); + assert_eq!( + msg.data[37], 222, + "incorrect value for data[37], expected 222, is {}", + msg.data[37] + ); + assert_eq!( + msg.data[38], 29, + "incorrect value for data[38], expected 29, is {}", + msg.data[38] + ); + assert_eq!( + msg.data[39], 168, + "incorrect value for data[39], expected 168, is {}", + msg.data[39] + ); + assert_eq!( + msg.data[40], 214, + "incorrect value for data[40], expected 214, is {}", + msg.data[40] + ); + assert_eq!( + msg.data[41], 118, + "incorrect value for data[41], expected 118, is {}", + msg.data[41] + ); + assert_eq!( + msg.data[42], 55, + "incorrect value for data[42], expected 55, is {}", + msg.data[42] + ); + assert_eq!( + msg.data[43], 201, + "incorrect value for data[43], expected 201, is {}", + msg.data[43] + ); + assert_eq!( + msg.data[44], 233, + "incorrect value for data[44], expected 233, is {}", + msg.data[44] + ); + assert_eq!( + msg.data[45], 21, + "incorrect value for data[45], expected 21, is {}", + msg.data[45] + ); + assert_eq!( + msg.data[46], 214, + "incorrect value for data[46], expected 214, is {}", + msg.data[46] + ); + assert_eq!( + msg.data[47], 57, + "incorrect value for data[47], expected 57, is {}", + msg.data[47] + ); + assert_eq!( + msg.data[48], 245, + "incorrect value for data[48], expected 245, is {}", + msg.data[48] + ); + assert_eq!( + msg.data[49], 246, + "incorrect value for data[49], expected 246, is {}", + msg.data[49] + ); + assert_eq!( + msg.data[50], 19, + "incorrect value for data[50], expected 19, is {}", + msg.data[50] + ); + assert_eq!( + msg.data[51], 3, + "incorrect value for data[51], expected 3, is {}", + msg.data[51] + ); + assert_eq!( + msg.data[52], 121, + "incorrect value for data[52], expected 121, is {}", + msg.data[52] + ); + assert_eq!( + msg.data[53], 49, + "incorrect value for data[53], expected 49, is {}", + msg.data[53] + ); + assert_eq!( + msg.data[54], 231, + "incorrect value for data[54], expected 231, is {}", + msg.data[54] + ); + assert_eq!( + msg.data[55], 37, + "incorrect value for data[55], expected 37, is {}", + msg.data[55] + ); + assert_eq!( + msg.data[56], 186, + "incorrect value for data[56], expected 186, is {}", + msg.data[56] + ); + assert_eq!( + msg.data[57], 58, + "incorrect value for data[57], expected 58, is {}", + msg.data[57] + ); + assert_eq!( + msg.data[58], 238, + "incorrect value for data[58], expected 238, is {}", + msg.data[58] + ); + assert_eq!( + msg.data[59], 98, + "incorrect value for data[59], expected 98, is {}", + msg.data[59] + ); + assert_eq!( + msg.data[60], 39, + "incorrect value for data[60], expected 39, is {}", + msg.data[60] + ); + assert_eq!( + msg.data[61], 70, + "incorrect value for data[61], expected 70, is {}", + msg.data[61] + ); + assert_eq!( + msg.data[62], 232, + "incorrect value for data[62], expected 232, is {}", + msg.data[62] + ); + assert_eq!( + msg.data[63], 133, + "incorrect value for data[63], expected 133, is {}", + msg.data[63] + ); + assert_eq!( + msg.data[64], 25, + "incorrect value for data[64], expected 25, is {}", + msg.data[64] + ); + assert_eq!( + msg.data[65], 10, + "incorrect value for data[65], expected 10, is {}", + msg.data[65] + ); + assert_eq!( + msg.data[66], 134, + "incorrect value for data[66], expected 134, is {}", + msg.data[66] + ); + assert_eq!( + msg.data[67], 129, + "incorrect value for data[67], expected 129, is {}", + msg.data[67] + ); + assert_eq!( + msg.data[68], 69, + "incorrect value for data[68], expected 69, is {}", + msg.data[68] + ); + assert_eq!( + msg.data[69], 228, + "incorrect value for data[69], expected 228, is {}", + msg.data[69] + ); + assert_eq!( + msg.data[70], 134, + "incorrect value for data[70], expected 134, is {}", + msg.data[70] + ); + assert_eq!( + msg.data[71], 9, + "incorrect value for data[71], expected 9, is {}", + msg.data[71] + ); + assert_eq!( + msg.data[72], 88, + "incorrect value for data[72], expected 88, is {}", + msg.data[72] + ); + assert_eq!( + msg.data[73], 183, + "incorrect value for data[73], expected 183, is {}", + msg.data[73] + ); + assert_eq!( + msg.data[74], 133, + "incorrect value for data[74], expected 133, is {}", + msg.data[74] + ); + assert_eq!( + msg.data[75], 171, + "incorrect value for data[75], expected 171, is {}", + msg.data[75] + ); + assert_eq!( + msg.data[76], 255, + "incorrect value for data[76], expected 255, is {}", + msg.data[76] + ); + assert_eq!( + msg.data[77], 166, + "incorrect value for data[77], expected 166, is {}", + msg.data[77] + ); + assert_eq!( + msg.data[78], 100, + "incorrect value for data[78], expected 100, is {}", + msg.data[78] + ); + assert_eq!( + msg.data[79], 152, + "incorrect value for data[79], expected 152, is {}", + msg.data[79] + ); + assert_eq!( + msg.data[80], 231, + "incorrect value for data[80], expected 231, is {}", + msg.data[80] + ); + assert_eq!( + msg.data[81], 92, + "incorrect value for data[81], expected 92, is {}", + msg.data[81] + ); + assert_eq!( + msg.data[82], 9, + "incorrect value for data[82], expected 9, is {}", + msg.data[82] + ); + assert_eq!( + msg.data[83], 196, + "incorrect value for data[83], expected 196, is {}", + msg.data[83] + ); + assert_eq!( + msg.data[84], 106, + "incorrect value for data[84], expected 106, is {}", + msg.data[84] + ); + assert_eq!( + msg.data[85], 246, + "incorrect value for data[85], expected 246, is {}", + msg.data[85] + ); + assert_eq!( + msg.data[86], 29, + "incorrect value for data[86], expected 29, is {}", + msg.data[86] + ); + assert_eq!( + msg.data[87], 145, + "incorrect value for data[87], expected 145, is {}", + msg.data[87] + ); + assert_eq!( + msg.data[88], 156, + "incorrect value for data[88], expected 156, is {}", + msg.data[88] + ); + assert_eq!( + msg.data[89], 151, + "incorrect value for data[89], expected 151, is {}", + msg.data[89] + ); + assert_eq!( + msg.data[90], 32, + "incorrect value for data[90], expected 32, is {}", + msg.data[90] + ); + assert_eq!( + msg.data[91], 67, + "incorrect value for data[91], expected 67, is {}", + msg.data[91] + ); + assert_eq!( + msg.data[92], 188, + "incorrect value for data[92], expected 188, is {}", + msg.data[92] + ); + assert_eq!( + msg.data[93], 63, + "incorrect value for data[93], expected 63, is {}", + msg.data[93] + ); + assert_eq!( + msg.data[94], 233, + "incorrect value for data[94], expected 233, is {}", + msg.data[94] + ); + assert_eq!( + msg.data[95], 142, + "incorrect value for data[95], expected 142, is {}", + msg.data[95] + ); + assert_eq!( + msg.data[96], 174, + "incorrect value for data[96], expected 174, is {}", + msg.data[96] + ); + assert_eq!( + msg.data[97], 139, + "incorrect value for data[97], expected 139, is {}", + msg.data[97] + ); + assert_eq!( + msg.data[98], 154, + "incorrect value for data[98], expected 154, is {}", + msg.data[98] + ); + assert_eq!( + msg.data[99], 127, + "incorrect value for data[99], expected 127, is {}", + msg.data[99] + ); + assert_eq!( + msg.data[100], 35, + "incorrect value for data[100], expected 35, is {}", + msg.data[100] + ); + assert_eq!( + msg.data[101], 60, + "incorrect value for data[101], expected 60, is {}", + msg.data[101] + ); + assert_eq!( + msg.data[102], 56, + "incorrect value for data[102], expected 56, is {}", + msg.data[102] + ); + assert_eq!( + msg.data[103], 187, + "incorrect value for data[103], expected 187, is {}", + msg.data[103] + ); + assert_eq!( + msg.data[104], 121, + "incorrect value for data[104], expected 121, is {}", + msg.data[104] + ); + assert_eq!( + msg.data[105], 103, + "incorrect value for data[105], expected 103, is {}", + msg.data[105] + ); + assert_eq!( + msg.data[106], 135, + "incorrect value for data[106], expected 135, is {}", + msg.data[106] + ); + assert_eq!( + msg.data[107], 152, + "incorrect value for data[107], expected 152, is {}", + msg.data[107] + ); + assert_eq!( + msg.data[108], 182, + "incorrect value for data[108], expected 182, is {}", + msg.data[108] + ); + assert_eq!( + msg.data[109], 88, + "incorrect value for data[109], expected 88, is {}", + msg.data[109] + ); + assert_eq!( + msg.data[110], 160, + "incorrect value for data[110], expected 160, is {}", + msg.data[110] + ); + assert_eq!( + msg.data[111], 255, + "incorrect value for data[111], expected 255, is {}", + msg.data[111] + ); + assert_eq!( + msg.data[112], 227, + "incorrect value for data[112], expected 227, is {}", + msg.data[112] + ); + assert_eq!( + msg.data[113], 240, + "incorrect value for data[113], expected 240, is {}", + msg.data[113] + ); + assert_eq!( + msg.data[114], 54, + "incorrect value for data[114], expected 54, is {}", + msg.data[114] + ); + assert_eq!( + msg.data[115], 100, + "incorrect value for data[115], expected 100, is {}", + msg.data[115] + ); + assert_eq!( + msg.data[116], 91, + "incorrect value for data[116], expected 91, is {}", + msg.data[116] + ); + assert_eq!( + msg.data[117], 31, + "incorrect value for data[117], expected 31, is {}", + msg.data[117] + ); + assert_eq!( + msg.data[118], 141, + "incorrect value for data[118], expected 141, is {}", + msg.data[118] + ); + assert_eq!( + msg.data[119], 102, + "incorrect value for data[119], expected 102, is {}", + msg.data[119] + ); + assert_eq!( + msg.data[120], 130, + "incorrect value for data[120], expected 130, is {}", + msg.data[120] + ); + assert_eq!( + msg.data[121], 254, + "incorrect value for data[121], expected 254, is {}", + msg.data[121] + ); + assert_eq!( + msg.data[122], 54, + "incorrect value for data[122], expected 54, is {}", + msg.data[122] + ); + assert_eq!( + msg.data[123], 227, + "incorrect value for data[123], expected 227, is {}", + msg.data[123] + ); + assert_eq!( + msg.data[124], 229, + "incorrect value for data[124], expected 229, is {}", + msg.data[124] + ); + assert_eq!( + msg.data[125], 62, + "incorrect value for data[125], expected 62, is {}", + msg.data[125] + ); + assert_eq!( + msg.data[126], 53, + "incorrect value for data[126], expected 53, is {}", + msg.data[126] + ); + assert_eq!( + msg.data[127], 225, + "incorrect value for data[127], expected 225, is {}", + msg.data[127] + ); + assert_eq!( + msg.data[128], 143, + "incorrect value for data[128], expected 143, is {}", + msg.data[128] + ); + assert_eq!( + msg.data[129], 88, + "incorrect value for data[129], expected 88, is {}", + msg.data[129] + ); + assert_eq!( + msg.data[130], 139, + "incorrect value for data[130], expected 139, is {}", + msg.data[130] + ); + assert_eq!( + msg.data[131], 126, + "incorrect value for data[131], expected 126, is {}", + msg.data[131] + ); + assert_eq!( + msg.data[132], 235, + "incorrect value for data[132], expected 235, is {}", + msg.data[132] + ); + assert_eq!( + msg.data[133], 235, + "incorrect value for data[133], expected 235, is {}", + msg.data[133] + ); + assert_eq!( + msg.data[134], 35, + "incorrect value for data[134], expected 35, is {}", + msg.data[134] + ); + assert_eq!( + msg.data[135], 54, + "incorrect value for data[135], expected 54, is {}", + msg.data[135] + ); + assert_eq!( + msg.data[136], 134, + "incorrect value for data[136], expected 134, is {}", + msg.data[136] + ); + assert_eq!( + msg.data[137], 163, + "incorrect value for data[137], expected 163, is {}", + msg.data[137] + ); + assert_eq!( + msg.data[138], 92, + "incorrect value for data[138], expected 92, is {}", + msg.data[138] + ); + assert_eq!( + msg.data[139], 57, + "incorrect value for data[139], expected 57, is {}", + msg.data[139] + ); + assert_eq!( + msg.data[140], 87, + "incorrect value for data[140], expected 87, is {}", + msg.data[140] + ); + assert_eq!( + msg.data[141], 130, + "incorrect value for data[141], expected 130, is {}", + msg.data[141] + ); + assert_eq!( + msg.data[142], 178, + "incorrect value for data[142], expected 178, is {}", + msg.data[142] + ); + assert_eq!( + msg.data[143], 22, + "incorrect value for data[143], expected 22, is {}", + msg.data[143] + ); + assert_eq!( + msg.data[144], 158, + "incorrect value for data[144], expected 158, is {}", + msg.data[144] + ); + assert_eq!( + msg.data[145], 18, + "incorrect value for data[145], expected 18, is {}", + msg.data[145] + ); + assert_eq!( + msg.data[146], 237, + "incorrect value for data[146], expected 237, is {}", + msg.data[146] + ); + assert_eq!( + msg.data[147], 209, + "incorrect value for data[147], expected 209, is {}", + msg.data[147] + ); + assert_eq!( + msg.data[148], 187, + "incorrect value for data[148], expected 187, is {}", + msg.data[148] + ); + assert_eq!( + msg.data[149], 226, + "incorrect value for data[149], expected 226, is {}", + msg.data[149] + ); + assert_eq!( + msg.data[150], 1, + "incorrect value for data[150], expected 1, is {}", + msg.data[150] + ); + assert_eq!( + msg.data[151], 46, + "incorrect value for data[151], expected 46, is {}", + msg.data[151] + ); + assert_eq!( + msg.data[152], 64, + "incorrect value for data[152], expected 64, is {}", + msg.data[152] + ); + assert_eq!( + msg.data[153], 226, + "incorrect value for data[153], expected 226, is {}", + msg.data[153] + ); + assert_eq!( + msg.data[154], 235, + "incorrect value for data[154], expected 235, is {}", + msg.data[154] + ); + assert_eq!( + msg.data[155], 213, + "incorrect value for data[155], expected 213, is {}", + msg.data[155] + ); + assert_eq!( + msg.data[156], 186, + "incorrect value for data[156], expected 186, is {}", + msg.data[156] + ); + assert_eq!( + msg.data[157], 159, + "incorrect value for data[157], expected 159, is {}", + msg.data[157] + ); + assert_eq!( + msg.data[158], 221, + "incorrect value for data[158], expected 221, is {}", + msg.data[158] + ); + assert_eq!( + msg.data[159], 186, + "incorrect value for data[159], expected 186, is {}", + msg.data[159] + ); + assert_eq!( + msg.data[160], 25, + "incorrect value for data[160], expected 25, is {}", + msg.data[160] + ); + assert_eq!( + msg.data[161], 115, + "incorrect value for data[161], expected 115, is {}", + msg.data[161] + ); + assert_eq!( + msg.data[162], 84, + "incorrect value for data[162], expected 84, is {}", + msg.data[162] + ); + assert_eq!( + msg.data[163], 131, + "incorrect value for data[163], expected 131, is {}", + msg.data[163] + ); + assert_eq!( + msg.data[164], 167, + "incorrect value for data[164], expected 167, is {}", + msg.data[164] + ); + assert_eq!( + msg.data[165], 201, + "incorrect value for data[165], expected 201, is {}", + msg.data[165] + ); + assert_eq!( + msg.data[166], 104, + "incorrect value for data[166], expected 104, is {}", + msg.data[166] + ); + assert_eq!( + msg.data[167], 1, + "incorrect value for data[167], expected 1, is {}", + msg.data[167] + ); + assert_eq!( + msg.data[168], 200, + "incorrect value for data[168], expected 200, is {}", + msg.data[168] + ); + assert_eq!( + msg.data[169], 13, + "incorrect value for data[169], expected 13, is {}", + msg.data[169] + ); + assert_eq!( + msg.data[170], 50, + "incorrect value for data[170], expected 50, is {}", + msg.data[170] + ); + assert_eq!( + msg.data[171], 71, + "incorrect value for data[171], expected 71, is {}", + msg.data[171] + ); + assert_eq!( + msg.data[172], 73, + "incorrect value for data[172], expected 73, is {}", + msg.data[172] + ); + assert_eq!( + msg.data[173], 193, + "incorrect value for data[173], expected 193, is {}", + msg.data[173] + ); + assert_eq!( + msg.data[174], 201, + "incorrect value for data[174], expected 201, is {}", + msg.data[174] + ); + assert_eq!( + msg.data[175], 250, + "incorrect value for data[175], expected 250, is {}", + msg.data[175] + ); + assert_eq!( + msg.data[176], 172, + "incorrect value for data[176], expected 172, is {}", + msg.data[176] + ); + assert_eq!( + msg.data[177], 193, + "incorrect value for data[177], expected 193, is {}", + msg.data[177] + ); + assert_eq!( + msg.data[178], 13, + "incorrect value for data[178], expected 13, is {}", + msg.data[178] + ); + assert_eq!( + msg.data[179], 20, + "incorrect value for data[179], expected 20, is {}", + msg.data[179] + ); + assert_eq!( + msg.data[180], 238, + "incorrect value for data[180], expected 238, is {}", + msg.data[180] + ); + assert_eq!( + msg.data[181], 130, + "incorrect value for data[181], expected 130, is {}", + msg.data[181] + ); + assert_eq!( + msg.data[182], 243, + "incorrect value for data[182], expected 243, is {}", + msg.data[182] + ); + assert_eq!( + msg.data[183], 68, + "incorrect value for data[183], expected 68, is {}", + msg.data[183] + ); + assert_eq!( + msg.data[184], 4, + "incorrect value for data[184], expected 4, is {}", + msg.data[184] + ); + assert_eq!( + msg.data[185], 72, + "incorrect value for data[185], expected 72, is {}", + msg.data[185] + ); + assert_eq!( + msg.data[186], 46, + "incorrect value for data[186], expected 46, is {}", + msg.data[186] + ); + assert_eq!( + msg.data[187], 194, + "incorrect value for data[187], expected 194, is {}", + msg.data[187] + ); + assert_eq!( + msg.data[188], 113, + "incorrect value for data[188], expected 113, is {}", + msg.data[188] + ); + assert_eq!( + msg.data[189], 255, + "incorrect value for data[189], expected 255, is {}", + msg.data[189] + ); + assert_eq!( + msg.data[190], 238, + "incorrect value for data[190], expected 238, is {}", + msg.data[190] + ); + assert_eq!( + msg.data[191], 15, + "incorrect value for data[191], expected 15, is {}", + msg.data[191] + ); + assert_eq!( + msg.data[192], 230, + "incorrect value for data[192], expected 230, is {}", + msg.data[192] + ); + assert_eq!( + msg.data[193], 64, + "incorrect value for data[193], expected 64, is {}", + msg.data[193] + ); + assert_eq!( + msg.data[194], 178, + "incorrect value for data[194], expected 178, is {}", + msg.data[194] + ); + assert_eq!( + msg.data[195], 127, + "incorrect value for data[195], expected 127, is {}", + msg.data[195] + ); + assert_eq!( + msg.data[196], 217, + "incorrect value for data[196], expected 217, is {}", + msg.data[196] + ); + assert_eq!( + msg.data[197], 92, + "incorrect value for data[197], expected 92, is {}", + msg.data[197] + ); + assert_eq!( + msg.data[198], 160, + "incorrect value for data[198], expected 160, is {}", + msg.data[198] + ); + assert_eq!( + msg.data[199], 201, + "incorrect value for data[199], expected 201, is {}", + msg.data[199] + ); + assert_eq!( + msg.data[200], 118, + "incorrect value for data[200], expected 118, is {}", + msg.data[200] + ); + assert_eq!( + msg.data[201], 163, + "incorrect value for data[201], expected 163, is {}", + msg.data[201] + ); + assert_eq!( + msg.data[202], 144, + "incorrect value for data[202], expected 144, is {}", + msg.data[202] + ); + assert_eq!( + msg.data[203], 58, + "incorrect value for data[203], expected 58, is {}", + msg.data[203] + ); + assert_eq!( + msg.data[204], 28, + "incorrect value for data[204], expected 28, is {}", + msg.data[204] + ); + assert_eq!( + msg.data[205], 174, + "incorrect value for data[205], expected 174, is {}", + msg.data[205] + ); + assert_eq!( + msg.data[206], 65, + "incorrect value for data[206], expected 65, is {}", + msg.data[206] + ); + assert_eq!( + msg.data[207], 73, + "incorrect value for data[207], expected 73, is {}", + msg.data[207] + ); + assert_eq!( + msg.data[208], 45, + "incorrect value for data[208], expected 45, is {}", + msg.data[208] + ); + assert_eq!( + msg.data[209], 123, + "incorrect value for data[209], expected 123, is {}", + msg.data[209] + ); + assert_eq!( + msg.data[210], 118, + "incorrect value for data[210], expected 118, is {}", + msg.data[210] + ); + assert_eq!( + msg.data[211], 83, + "incorrect value for data[211], expected 83, is {}", + msg.data[211] + ); + assert_eq!( + msg.data[212], 107, + "incorrect value for data[212], expected 107, is {}", + msg.data[212] + ); + assert_eq!( + msg.data[213], 239, + "incorrect value for data[213], expected 239, is {}", + msg.data[213] + ); + assert_eq!( + msg.data[214], 168, + "incorrect value for data[214], expected 168, is {}", + msg.data[214] + ); + assert_eq!( + msg.data[215], 32, + "incorrect value for data[215], expected 32, is {}", + msg.data[215] + ); + assert_eq!( + msg.data[216], 212, + "incorrect value for data[216], expected 212, is {}", + msg.data[216] + ); + assert_eq!( + msg.data[217], 191, + "incorrect value for data[217], expected 191, is {}", + msg.data[217] + ); + assert_eq!( + msg.data[218], 81, + "incorrect value for data[218], expected 81, is {}", + msg.data[218] + ); + assert_eq!( + msg.data[219], 93, + "incorrect value for data[219], expected 93, is {}", + msg.data[219] + ); + assert_eq!( + msg.data[220], 186, + "incorrect value for data[220], expected 186, is {}", + msg.data[220] + ); + assert_eq!( + msg.data[221], 223, + "incorrect value for data[221], expected 223, is {}", + msg.data[221] + ); + assert_eq!( + msg.data[222], 32, + "incorrect value for data[222], expected 32, is {}", + msg.data[222] + ); + assert_eq!( + msg.data[223], 19, + "incorrect value for data[223], expected 19, is {}", + msg.data[223] + ); + assert_eq!( + msg.data[224], 58, + "incorrect value for data[224], expected 58, is {}", + msg.data[224] + ); + assert_eq!( + msg.data[225], 137, + "incorrect value for data[225], expected 137, is {}", + msg.data[225] + ); + assert_eq!( + msg.data[226], 72, + "incorrect value for data[226], expected 72, is {}", + msg.data[226] + ); + assert_eq!( + msg.data[227], 217, + "incorrect value for data[227], expected 217, is {}", + msg.data[227] + ); + assert_eq!( + msg.data[228], 151, + "incorrect value for data[228], expected 151, is {}", + msg.data[228] + ); + assert_eq!( + msg.data[229], 251, + "incorrect value for data[229], expected 251, is {}", + msg.data[229] + ); + assert_eq!( + msg.data[230], 83, + "incorrect value for data[230], expected 83, is {}", + msg.data[230] + ); + assert_eq!( + msg.data[231], 20, + "incorrect value for data[231], expected 20, is {}", + msg.data[231] + ); + assert_eq!( + msg.data[232], 113, + "incorrect value for data[232], expected 113, is {}", + msg.data[232] + ); + assert_eq!( + msg.data[233], 37, + "incorrect value for data[233], expected 37, is {}", + msg.data[233] + ); + assert_eq!( + msg.data[234], 151, + "incorrect value for data[234], expected 151, is {}", + msg.data[234] + ); + assert_eq!( + msg.data[235], 34, + "incorrect value for data[235], expected 34, is {}", + msg.data[235] + ); + assert_eq!( + msg.data[236], 37, + "incorrect value for data[236], expected 37, is {}", + msg.data[236] + ); + assert_eq!( + msg.data[237], 71, + "incorrect value for data[237], expected 71, is {}", + msg.data[237] + ); + assert_eq!( + msg.data[238], 95, + "incorrect value for data[238], expected 95, is {}", + msg.data[238] + ); + assert_eq!( + msg.data[239], 105, + "incorrect value for data[239], expected 105, is {}", + msg.data[239] + ); + assert_eq!( + msg.data[240], 235, + "incorrect value for data[240], expected 235, is {}", + msg.data[240] + ); + assert_eq!( + msg.data[241], 144, + "incorrect value for data[241], expected 144, is {}", + msg.data[241] + ); + assert_eq!( + msg.data[242], 164, + "incorrect value for data[242], expected 164, is {}", + msg.data[242] + ); + assert_eq!( + msg.data[243], 83, + "incorrect value for data[243], expected 83, is {}", + msg.data[243] + ); + assert_eq!( + msg.data[244], 197, + "incorrect value for data[244], expected 197, is {}", + msg.data[244] + ); + assert_eq!( + msg.data[245], 254, + "incorrect value for data[245], expected 254, is {}", + msg.data[245] + ); + assert_eq!( + msg.data[246], 183, + "incorrect value for data[246], expected 183, is {}", + msg.data[246] + ); + assert_eq!( + msg.data[247], 223, + "incorrect value for data[247], expected 223, is {}", + msg.data[247] + ); + assert_eq!( + msg.data[248], 91, + "incorrect value for data[248], expected 91, is {}", + msg.data[248] + ); + assert_eq!( + msg.data[249], 19, + "incorrect value for data[249], expected 19, is {}", + msg.data[249] + ); + assert_eq!( + msg.target, 212, + "incorrect value for target, expected 212, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashProgram"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_req.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_req.rs new file mode 100644 index 0000000000..6ccda22ff1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_req.rs @@ -0,0 +1,238 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_flash_read_req() { + { + let mut payload = Cursor::new(vec![85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe7, + "Incorrect message type, expected 0xe7, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 71, + "incorrect value for addr_len, expected 71, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 28, + "incorrect value for addr_start[0], expected 28, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 75, + "incorrect value for addr_start[1], expected 75, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 241, + "incorrect value for target, expected 241, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_flash_read_req() { + { + let json_input = r#"{"crc":14802,"length":5,"msg_type":231,"payload":"8RxL9Ec=","preamble":85,"sender":1219,"target":241,"addr_start":[28,75,244],"addr_len":71}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe7, + "Incorrect message type, expected 0xe7, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 71, + "incorrect value for addr_len, expected 71, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 28, + "incorrect value for addr_start[0], expected 28, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 75, + "incorrect value for addr_start[1], expected 75, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 241, + "incorrect value for target, expected 241, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_flash_read_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_flash_read_req() { + { + let mut payload = Cursor::new(vec![85, 231, 0, 195, 4, 5, 241, 28, 75, 244, 71, 210, 57]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFlashReadReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe7, + "Incorrect message type, expected 0xe7, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 71, + "incorrect value for addr_len, expected 71, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 28, + "incorrect value for addr_start[0], expected 28, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 75, + "incorrect value for addr_start[1], expected 75, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 244, + "incorrect value for addr_start[2], expected 244, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 241, + "incorrect value for target, expected 241, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_resp.rs new file mode 100644 index 0000000000..fb2cb999da --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_flash_read_resp.rs @@ -0,0 +1,242 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_flash_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe1, + "Incorrect message type, expected 0xe1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 124, + "incorrect value for addr_len, expected 124, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 155, + "incorrect value for addr_start[0], expected 155, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 172, + "incorrect value for addr_start[2], expected 172, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 136, + "incorrect value for target, expected 136, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_flash_read_resp() { + { + let json_input = r#"{"crc":34709,"length":5,"msg_type":225,"payload":"iJs0rHw=","preamble":85,"sender":1219,"target":136,"addr_start":[155,52,172],"addr_len":124}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe1, + "Incorrect message type, expected 0xe1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 124, + "incorrect value for addr_len, expected 124, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 155, + "incorrect value for addr_start[0], expected 155, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 172, + "incorrect value for addr_start[2], expected 172, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 136, + "incorrect value for target, expected 136, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_flash_read_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_flash_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 225, 0, 195, 4, 5, 136, 155, 52, 172, 124, 149, 135, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFlashReadResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFlashReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe1, + "Incorrect message type, expected 0xe1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.addr_len, 124, + "incorrect value for addr_len, expected 124, is {}", + msg.addr_len + ); + assert_eq!( + msg.addr_start[0], 155, + "incorrect value for addr_start[0], expected 155, is {}", + msg.addr_start[0] + ); + assert_eq!( + msg.addr_start[1], 52, + "incorrect value for addr_start[1], expected 52, is {}", + msg.addr_start[1] + ); + assert_eq!( + msg.addr_start[2], 172, + "incorrect value for addr_start[2], expected 172, is {}", + msg.addr_start[2] + ); + assert_eq!( + msg.target, 136, + "incorrect value for target, expected 136, is {}", + msg.target + ); + } + _ => panic!("Invalid message type! Expected a MsgFlashReadResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_m25_flash_write_status.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_m25_flash_write_status.rs new file mode 100644 index 0000000000..c1b1ed693f --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_m25_flash_write_status.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_m25_flash_write_status() { + { + let mut payload = Cursor::new(vec![85, 243, 0, 195, 4, 1, 5, 112, 200]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgM25FlashWriteStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xf3, + "Incorrect message type, expected 0xf3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.status[0], 5, + "incorrect value for status[0], expected 5, is {}", + msg.status[0] + ); + } + _ => panic!("Invalid message type! Expected a MsgM25FlashWriteStatus"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_m25_flash_write_status() { + { + let json_input = r#"{"crc":51312,"length":1,"msg_type":243,"payload":"BQ==","preamble":85,"sender":1219,"status":[5]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgM25FlashWriteStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xf3, + "Incorrect message type, expected 0xf3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.status[0], 5, + "incorrect value for status[0], expected 5, is {}", + msg.status[0] + ); + } + _ => panic!("Invalid message type! Expected a MsgM25FlashWriteStatus"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_m25_flash_write_status`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_m25_flash_write_status() { + { + let mut payload = Cursor::new(vec![85, 243, 0, 195, 4, 1, 5, 112, 200]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgM25FlashWriteStatus( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgM25FlashWriteStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xf3, + "Incorrect message type, expected 0xf3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.status[0], 5, + "incorrect value for status[0], expected 5, is {}", + msg.status[0] + ); + } + _ => panic!("Invalid message type! Expected a MsgM25FlashWriteStatus"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_lock_sector.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_lock_sector.rs new file mode 100644 index 0000000000..a1dddc3362 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_lock_sector.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_stm_flash_lock_sector() { + { + let mut payload = Cursor::new(vec![85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashLockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe3, + "Incorrect message type, expected 0xe3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 1137047457, + "incorrect value for sector, expected 1137047457, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashLockSector"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_stm_flash_lock_sector() { + { + let json_input = r#"{"crc":8421,"length":4,"msg_type":227,"payload":"offFQw==","preamble":85,"sender":1219,"sector":1137047457}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashLockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe3, + "Incorrect message type, expected 0xe3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 1137047457, + "incorrect value for sector, expected 1137047457, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashLockSector"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_stm_flash_lock_sector`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_stm_flash_lock_sector() { + { + let mut payload = Cursor::new(vec![85, 227, 0, 195, 4, 4, 161, 247, 197, 67, 229, 32]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgStmFlashLockSector( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashLockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe3, + "Incorrect message type, expected 0xe3, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 1137047457, + "incorrect value for sector, expected 1137047457, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashLockSector"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_unlock_sector.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_unlock_sector.rs new file mode 100644 index 0000000000..8157ed1fb8 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_flash_unlock_sector.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_stm_flash_unlock_sector() { + { + let mut payload = Cursor::new(vec![85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashUnlockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe4, + "Incorrect message type, expected 0xe4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 837226527, + "incorrect value for sector, expected 837226527, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashUnlockSector"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_stm_flash_unlock_sector() { + { + let json_input = r#"{"crc":55605,"length":4,"msg_type":228,"payload":"HxDnMQ==","preamble":85,"sender":1219,"sector":837226527}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashUnlockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe4, + "Incorrect message type, expected 0xe4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 837226527, + "incorrect value for sector, expected 837226527, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashUnlockSector"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_stm_flash_unlock_sector`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_stm_flash_unlock_sector() { + { + let mut payload = Cursor::new(vec![85, 228, 0, 195, 4, 4, 31, 16, 231, 49, 53, 217]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgStmFlashUnlockSector( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgStmFlashUnlockSector(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe4, + "Incorrect message type, expected 0xe4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.sector, 837226527, + "incorrect value for sector, expected 837226527, is {}", + msg.sector + ); + } + _ => panic!("Invalid message type! Expected a MsgStmFlashUnlockSector"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_req.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_req.rs new file mode 100644 index 0000000000..f464d767d1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_req.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_stm_unique_id_req() { + { + let mut payload = Cursor::new(vec![85, 232, 0, 195, 4, 0, 66, 138]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe8, + "Incorrect message type, expected 0xe8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_stm_unique_id_req() { + { + let json_input = + r#"{"crc":35394,"length":0,"msg_type":232,"payload":"","preamble":85,"sender":1219}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe8, + "Incorrect message type, expected 0xe8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_stm_unique_id_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_stm_unique_id_req() { + { + let mut payload = Cursor::new(vec![85, 232, 0, 195, 4, 0, 66, 138]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgStmUniqueIdReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe8, + "Incorrect message type, expected 0xe8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_resp.rs new file mode 100644 index 0000000000..bced47465a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_flash_msg_stm_unique_id_resp.rs @@ -0,0 +1,347 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_flash_msg_stm_unique_id_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe5, + "Incorrect message type, expected 0xe5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.stm_id[0], 196, + "incorrect value for stm_id[0], expected 196, is {}", + msg.stm_id[0] + ); + assert_eq!( + msg.stm_id[1], 16, + "incorrect value for stm_id[1], expected 16, is {}", + msg.stm_id[1] + ); + assert_eq!( + msg.stm_id[2], 15, + "incorrect value for stm_id[2], expected 15, is {}", + msg.stm_id[2] + ); + assert_eq!( + msg.stm_id[3], 163, + "incorrect value for stm_id[3], expected 163, is {}", + msg.stm_id[3] + ); + assert_eq!( + msg.stm_id[4], 85, + "incorrect value for stm_id[4], expected 85, is {}", + msg.stm_id[4] + ); + assert_eq!( + msg.stm_id[5], 221, + "incorrect value for stm_id[5], expected 221, is {}", + msg.stm_id[5] + ); + assert_eq!( + msg.stm_id[6], 119, + "incorrect value for stm_id[6], expected 119, is {}", + msg.stm_id[6] + ); + assert_eq!( + msg.stm_id[7], 102, + "incorrect value for stm_id[7], expected 102, is {}", + msg.stm_id[7] + ); + assert_eq!( + msg.stm_id[8], 32, + "incorrect value for stm_id[8], expected 32, is {}", + msg.stm_id[8] + ); + assert_eq!( + msg.stm_id[9], 194, + "incorrect value for stm_id[9], expected 194, is {}", + msg.stm_id[9] + ); + assert_eq!( + msg.stm_id[10], 56, + "incorrect value for stm_id[10], expected 56, is {}", + msg.stm_id[10] + ); + assert_eq!( + msg.stm_id[11], 144, + "incorrect value for stm_id[11], expected 144, is {}", + msg.stm_id[11] + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_flash_msg_stm_unique_id_resp() { + { + let json_input = r#"{"crc":50397,"length":12,"msg_type":229,"payload":"xBAPo1Xdd2YgwjiQ","preamble":85,"sender":1219,"stm_id":[196,16,15,163,85,221,119,102,32,194,56,144]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe5, + "Incorrect message type, expected 0xe5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.stm_id[0], 196, + "incorrect value for stm_id[0], expected 196, is {}", + msg.stm_id[0] + ); + assert_eq!( + msg.stm_id[1], 16, + "incorrect value for stm_id[1], expected 16, is {}", + msg.stm_id[1] + ); + assert_eq!( + msg.stm_id[2], 15, + "incorrect value for stm_id[2], expected 15, is {}", + msg.stm_id[2] + ); + assert_eq!( + msg.stm_id[3], 163, + "incorrect value for stm_id[3], expected 163, is {}", + msg.stm_id[3] + ); + assert_eq!( + msg.stm_id[4], 85, + "incorrect value for stm_id[4], expected 85, is {}", + msg.stm_id[4] + ); + assert_eq!( + msg.stm_id[5], 221, + "incorrect value for stm_id[5], expected 221, is {}", + msg.stm_id[5] + ); + assert_eq!( + msg.stm_id[6], 119, + "incorrect value for stm_id[6], expected 119, is {}", + msg.stm_id[6] + ); + assert_eq!( + msg.stm_id[7], 102, + "incorrect value for stm_id[7], expected 102, is {}", + msg.stm_id[7] + ); + assert_eq!( + msg.stm_id[8], 32, + "incorrect value for stm_id[8], expected 32, is {}", + msg.stm_id[8] + ); + assert_eq!( + msg.stm_id[9], 194, + "incorrect value for stm_id[9], expected 194, is {}", + msg.stm_id[9] + ); + assert_eq!( + msg.stm_id[10], 56, + "incorrect value for stm_id[10], expected 56, is {}", + msg.stm_id[10] + ); + assert_eq!( + msg.stm_id[11], 144, + "incorrect value for stm_id[11], expected 144, is {}", + msg.stm_id[11] + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_flash_msg_stm_unique_id_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_flash_msg_stm_unique_id_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 229, 0, 195, 4, 12, 196, 16, 15, 163, 85, 221, 119, 102, 32, 194, 56, 144, 221, 196, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgStmUniqueIdResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgStmUniqueIdResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xe5, + "Incorrect message type, expected 0xe5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.stm_id[0], 196, + "incorrect value for stm_id[0], expected 196, is {}", + msg.stm_id[0] + ); + assert_eq!( + msg.stm_id[1], 16, + "incorrect value for stm_id[1], expected 16, is {}", + msg.stm_id[1] + ); + assert_eq!( + msg.stm_id[2], 15, + "incorrect value for stm_id[2], expected 15, is {}", + msg.stm_id[2] + ); + assert_eq!( + msg.stm_id[3], 163, + "incorrect value for stm_id[3], expected 163, is {}", + msg.stm_id[3] + ); + assert_eq!( + msg.stm_id[4], 85, + "incorrect value for stm_id[4], expected 85, is {}", + msg.stm_id[4] + ); + assert_eq!( + msg.stm_id[5], 221, + "incorrect value for stm_id[5], expected 221, is {}", + msg.stm_id[5] + ); + assert_eq!( + msg.stm_id[6], 119, + "incorrect value for stm_id[6], expected 119, is {}", + msg.stm_id[6] + ); + assert_eq!( + msg.stm_id[7], 102, + "incorrect value for stm_id[7], expected 102, is {}", + msg.stm_id[7] + ); + assert_eq!( + msg.stm_id[8], 32, + "incorrect value for stm_id[8], expected 32, is {}", + msg.stm_id[8] + ); + assert_eq!( + msg.stm_id[9], 194, + "incorrect value for stm_id[9], expected 194, is {}", + msg.stm_id[9] + ); + assert_eq!( + msg.stm_id[10], 56, + "incorrect value for stm_id[10], expected 56, is {}", + msg.stm_id[10] + ); + assert_eq!( + msg.stm_id[11], 144, + "incorrect value for stm_id[11], expected 144, is {}", + msg.stm_id[11] + ); + } + _ => panic!("Invalid message type! Expected a MsgStmUniqueIdResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_gnss_gnss_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_gnss_gnss_structs.rs new file mode 100644 index 0000000000..86c59f5da5 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_gnss_gnss_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/gnss/test_gnss_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_gnss_gnss_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_gnss_gnss_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_gnss_gnss_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_gnss_gnss_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_integrity_integrity_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_integrity_integrity_structs.rs new file mode 100644 index 0000000000..c74111fb62 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_integrity_integrity_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/integrity/test_integrity_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_integrity_integrity_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_integrity_integrity_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_integrity_integrity_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_integrity_integrity_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state.rs new file mode 100644 index 0000000000..417c2b493d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state.rs @@ -0,0 +1,316 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_cpu_state() { + { + let mut payload = Cursor::new(vec![ + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, 235, 20, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, + 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, + 229, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f08, + "Incorrect message type, expected 0x7f08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8594, + "incorrect sender id, expected 0x8594, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 20, + "incorrect value for flags, expected 20, is {}", + msg.flags + ); + assert_eq!( + msg.index, 101, + "incorrect value for index, expected 101, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 98, + "incorrect value for pcpu, expected 98, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 50042, + "incorrect value for pid, expected 50042, is {}", + msg.pid + ); + assert_eq!( + msg.time, 3948815319, + "incorrect value for time, expected 3948815319, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuState"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_cpu_state() { + { + let json_input = r#"{"crc":58692,"length":70,"msg_type":32520,"payload":"ZXrDYtcjXusUcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":34196,"index":101,"pid":50042,"pcpu":98,"time":3948815319,"flags":20,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f08, + "Incorrect message type, expected 0x7f08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8594, + "incorrect sender id, expected 0x8594, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 20, + "incorrect value for flags, expected 20, is {}", + msg.flags + ); + assert_eq!( + msg.index, 101, + "incorrect value for index, expected 101, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 98, + "incorrect value for pcpu, expected 98, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 50042, + "incorrect value for pid, expected 50042, is {}", + msg.pid + ); + assert_eq!( + msg.time, 3948815319, + "incorrect value for time, expected 3948815319, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuState"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_cpu_state`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_cpu_state() { + { + let mut payload = Cursor::new(vec![ + 85, 8, 127, 148, 133, 70, 101, 122, 195, 98, 215, 35, 94, 235, 20, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, + 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 68, + 229, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxCpuState( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f08, + "Incorrect message type, expected 0x7f08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8594, + "incorrect sender id, expected 0x8594, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 20, + "incorrect value for flags, expected 20, is {}", + msg.flags + ); + assert_eq!( + msg.index, 101, + "incorrect value for index, expected 101, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 98, + "incorrect value for pcpu, expected 98, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 50042, + "incorrect value for pid, expected 50042, is {}", + msg.pid + ); + assert_eq!( + msg.time, 3948815319, + "incorrect value for time, expected 3948815319, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuState"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state_dep_a.rs new file mode 100644 index 0000000000..548a701a2a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_cpu_state_dep_a.rs @@ -0,0 +1,284 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_cpu_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 80, 48, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f00, + "Incorrect message type, expected 0x7f00, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5b0c, + "incorrect sender id, expected 0x5b0c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 178, + "incorrect value for pcpu, expected 178, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 64240, + "incorrect value for pid, expected 64240, is {}", + msg.pid + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuStateDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_cpu_state_dep_a() { + { + let json_input = r#"{"crc":12368,"length":65,"msg_type":32512,"payload":"M/D6snByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ=","preamble":85,"sender":23308,"index":51,"pid":64240,"pcpu":178,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f00, + "Incorrect message type, expected 0x7f00, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5b0c, + "incorrect sender id, expected 0x5b0c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 178, + "incorrect value for pcpu, expected 178, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 64240, + "incorrect value for pid, expected 64240, is {}", + msg.pid + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuStateDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_cpu_state_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_cpu_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 127, 12, 91, 65, 51, 240, 250, 178, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 80, 48, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxCpuStateDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxCpuStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f00, + "Incorrect message type, expected 0x7f00, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5b0c, + "incorrect sender id, expected 0x5b0c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pcpu, 178, + "incorrect value for pcpu, expected 178, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid, 64240, + "incorrect value for pid, expected 64240, is {}", + msg.pid + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxCpuStateDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state.rs new file mode 100644 index 0000000000..65e2a69342 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state.rs @@ -0,0 +1,314 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_mem_state() { + { + let mut payload = Cursor::new(vec![ + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, 187, 76, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, + 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f09, + "Incorrect message type, expected 0x7f09, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xfd5f, + "incorrect sender id, expected 0xfd5f, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 76, + "incorrect value for flags, expected 76, is {}", + msg.flags + ); + assert_eq!( + msg.index, 154, + "incorrect value for index, expected 154, is {}", + msg.index + ); + assert_eq!( + msg.pid, 57279, + "incorrect value for pid, expected 57279, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 19, + "incorrect value for pmem, expected 19, is {}", + msg.pmem + ); + assert_eq!( + msg.time, 3139057143, + "incorrect value for time, expected 3139057143, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemState"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_mem_state() { + { + let json_input = r#"{"crc":46339,"length":70,"msg_type":32521,"payload":"mr/fE/c1GrtMcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":64863,"index":154,"pid":57279,"pmem":19,"time":3139057143,"flags":76,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f09, + "Incorrect message type, expected 0x7f09, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xfd5f, + "incorrect sender id, expected 0xfd5f, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 76, + "incorrect value for flags, expected 76, is {}", + msg.flags + ); + assert_eq!( + msg.index, 154, + "incorrect value for index, expected 154, is {}", + msg.index + ); + assert_eq!( + msg.pid, 57279, + "incorrect value for pid, expected 57279, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 19, + "incorrect value for pmem, expected 19, is {}", + msg.pmem + ); + assert_eq!( + msg.time, 3139057143, + "incorrect value for time, expected 3139057143, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemState"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_mem_state`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_mem_state() { + { + let mut payload = Cursor::new(vec![ + 85, 9, 127, 95, 253, 70, 154, 191, 223, 19, 247, 53, 26, 187, 76, 112, 114, 111, 99, + 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, + 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 3, 181, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxMemState( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f09, + "Incorrect message type, expected 0x7f09, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xfd5f, + "incorrect sender id, expected 0xfd5f, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.flags, 76, + "incorrect value for flags, expected 76, is {}", + msg.flags + ); + assert_eq!( + msg.index, 154, + "incorrect value for index, expected 154, is {}", + msg.index + ); + assert_eq!( + msg.pid, 57279, + "incorrect value for pid, expected 57279, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 19, + "incorrect value for pmem, expected 19, is {}", + msg.pmem + ); + assert_eq!( + msg.time, 3139057143, + "incorrect value for time, expected 3139057143, is {}", + msg.time + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemState"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state_dep_a.rs new file mode 100644 index 0000000000..9de42f2a85 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_mem_state_dep_a.rs @@ -0,0 +1,284 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_mem_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 17, 137, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f01, + "Incorrect message type, expected 0x7f01, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6db9, + "incorrect sender id, expected 0x6db9, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 247, + "incorrect value for index, expected 247, is {}", + msg.index + ); + assert_eq!( + msg.pid, 12381, + "incorrect value for pid, expected 12381, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 193, + "incorrect value for pmem, expected 193, is {}", + msg.pmem + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemStateDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_mem_state_dep_a() { + { + let json_input = r#"{"crc":35089,"length":65,"msg_type":32513,"payload":"910wwXByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ=","preamble":85,"sender":28089,"index":247,"pid":12381,"pmem":193,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f01, + "Incorrect message type, expected 0x7f01, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6db9, + "incorrect sender id, expected 0x6db9, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 247, + "incorrect value for index, expected 247, is {}", + msg.index + ); + assert_eq!( + msg.pid, 12381, + "incorrect value for pid, expected 12381, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 193, + "incorrect value for pmem, expected 193, is {}", + msg.pmem + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemStateDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_mem_state_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_mem_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 1, 127, 185, 109, 65, 247, 93, 48, 193, 112, 114, 111, 99, 101, 115, 115, 45, 110, + 97, 109, 101, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, + 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 17, 137, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxMemStateDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxMemStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f01, + "Incorrect message type, expected 0x7f01, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6db9, + "incorrect sender id, expected 0x6db9, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 247, + "incorrect value for index, expected 247, is {}", + msg.index + ); + assert_eq!( + msg.pid, 12381, + "incorrect value for pid, expected 12381, is {}", + msg.pid + ); + assert_eq!( + msg.pmem, 193, + "incorrect value for pmem, expected 193, is {}", + msg.pmem + ); + assert_eq!( + msg.tname.as_bytes(), + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + "incorrect value for msg.tname, expected string '{:?}', is '{:?}'", + &[112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 0, 0, 0], + msg.tname.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxMemStateDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_count.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_count.rs new file mode 100644 index 0000000000..f45324f21f --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_count.rs @@ -0,0 +1,263 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_process_fd_count() { + { + let mut payload = Cursor::new(vec![ + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, 112, 97, 116, 104, 47, 116, 111, + 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, + 94, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdCount(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f06, + "Incorrect message type, expected 0x7f06, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc31e, + "incorrect sender id, expected 0xc31e, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.fd_count, 35589, + "incorrect value for fd_count, expected 35589, is {}", + msg.fd_count + ); + assert_eq!( + msg.index, 164, + "incorrect value for index, expected 164, is {}", + msg.index + ); + assert_eq!( + msg.pid, 42429, + "incorrect value for pid, expected 42429, is {}", + msg.pid + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdCount"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_process_fd_count() { + { + let json_input = r#"{"crc":24066,"length":51,"msg_type":32518,"payload":"pL2lBYsvcGF0aC90by9wcm9jZXNzLW5hbWUgYXJnMCBhcmcxIGFyZzIgYXJnMyBhcmc0","preamble":85,"sender":49950,"index":164,"pid":42429,"fd_count":35589,"cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdCount(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f06, + "Incorrect message type, expected 0x7f06, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc31e, + "incorrect sender id, expected 0xc31e, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.fd_count, 35589, + "incorrect value for fd_count, expected 35589, is {}", + msg.fd_count + ); + assert_eq!( + msg.index, 164, + "incorrect value for index, expected 164, is {}", + msg.index + ); + assert_eq!( + msg.pid, 42429, + "incorrect value for pid, expected 42429, is {}", + msg.pid + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdCount"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_process_fd_count`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_process_fd_count() { + { + let mut payload = Cursor::new(vec![ + 85, 6, 127, 30, 195, 51, 164, 189, 165, 5, 139, 47, 112, 97, 116, 104, 47, 116, 111, + 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, + 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, + 94, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxProcessFdCount( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdCount(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f06, + "Incorrect message type, expected 0x7f06, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc31e, + "incorrect sender id, expected 0xc31e, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.fd_count, 35589, + "incorrect value for fd_count, expected 35589, is {}", + msg.fd_count + ); + assert_eq!( + msg.index, 164, + "incorrect value for index, expected 164, is {}", + msg.index + ); + assert_eq!( + msg.pid, 42429, + "incorrect value for pid, expected 42429, is {}", + msg.pid + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdCount"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_summary.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_summary.rs new file mode 100644 index 0000000000..e1fe6313a0 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_fd_summary.rs @@ -0,0 +1,223 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_process_fd_summary() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, + 51, 0, 102, 100, 52, 0, 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdSummary(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f07, + "Incorrect message type, expected 0x7f07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf867, + "incorrect sender id, expected 0xf867, is {sender_id}" + ); + assert_eq!( + msg.most_opened.as_bytes(), + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + "incorrect value for msg.most_opened, expected string '{:?}', is '{:?}'", + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + msg.most_opened.as_bytes() + ); + assert_eq!( + msg.sys_fd_count, 1304986387, + "incorrect value for sys_fd_count, expected 1304986387, is {}", + msg.sys_fd_count + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdSummary"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_process_fd_summary() { + { + let json_input = r#"{"crc":20609,"length":29,"msg_type":32519,"payload":"E4PITWZkMQBmZDIAZmQzAGZkNABmZDUAZmQ2AAA=","preamble":85,"sender":63591,"sys_fd_count":1304986387,"most_opened":"fd1\u0000fd2\u0000fd3\u0000fd4\u0000fd5\u0000fd6\u0000\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdSummary(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f07, + "Incorrect message type, expected 0x7f07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf867, + "incorrect sender id, expected 0xf867, is {sender_id}" + ); + assert_eq!( + msg.most_opened.as_bytes(), + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + "incorrect value for msg.most_opened, expected string '{:?}', is '{:?}'", + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + msg.most_opened.as_bytes() + ); + assert_eq!( + msg.sys_fd_count, 1304986387, + "incorrect value for sys_fd_count, expected 1304986387, is {}", + msg.sys_fd_count + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdSummary"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_process_fd_summary`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_process_fd_summary() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 127, 103, 248, 29, 19, 131, 200, 77, 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, + 51, 0, 102, 100, 52, 0, 102, 100, 53, 0, 102, 100, 54, 0, 0, 129, 80, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxProcessFdSummary( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessFdSummary(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f07, + "Incorrect message type, expected 0x7f07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf867, + "incorrect sender id, expected 0xf867, is {sender_id}" + ); + assert_eq!( + msg.most_opened.as_bytes(), + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + "incorrect value for msg.most_opened, expected string '{:?}', is '{:?}'", + &[ + 102, 100, 49, 0, 102, 100, 50, 0, 102, 100, 51, 0, 102, 100, 52, 0, 102, + 100, 53, 0, 102, 100, 54, 0, 0 + ], + msg.most_opened.as_bytes() + ); + assert_eq!( + msg.sys_fd_count, 1304986387, + "incorrect value for sys_fd_count, expected 1304986387, is {}", + msg.sys_fd_count + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessFdSummary"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_counts.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_counts.rs new file mode 100644 index 0000000000..09cb8bb018 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_counts.rs @@ -0,0 +1,293 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_process_socket_counts() { + { + let mut payload = Cursor::new(vec![ + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, 114, 115, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, + 103, 52, 180, 131, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketCounts(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f03, + "Incorrect message type, expected 0x7f03, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x096c, + "incorrect sender id, expected 0x096c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pid, 28553, + "incorrect value for pid, expected 28553, is {}", + msg.pid + ); + assert_eq!( + msg.socket_count, 30287, + "incorrect value for socket_count, expected 30287, is {}", + msg.socket_count + ); + assert_eq!( + msg.socket_states, 29554, + "incorrect value for socket_states, expected 29554, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 35843, + "incorrect value for socket_types, expected 35843, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketCounts"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_process_socket_counts() { + { + let json_input = r#"{"crc":33716,"length":55,"msg_type":32515,"payload":"M4lvT3YDjHJzL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":2412,"index":51,"pid":28553,"socket_count":30287,"socket_types":35843,"socket_states":29554,"cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketCounts(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f03, + "Incorrect message type, expected 0x7f03, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x096c, + "incorrect sender id, expected 0x096c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pid, 28553, + "incorrect value for pid, expected 28553, is {}", + msg.pid + ); + assert_eq!( + msg.socket_count, 30287, + "incorrect value for socket_count, expected 30287, is {}", + msg.socket_count + ); + assert_eq!( + msg.socket_states, 29554, + "incorrect value for socket_states, expected 29554, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 35843, + "incorrect value for socket_types, expected 35843, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketCounts"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_process_socket_counts`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_process_socket_counts() { + { + let mut payload = Cursor::new(vec![ + 85, 3, 127, 108, 9, 55, 51, 137, 111, 79, 118, 3, 140, 114, 115, 47, 112, 97, 116, 104, + 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, + 103, 48, 32, 97, 114, 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, + 103, 52, 180, 131, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxProcessSocketCounts( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketCounts(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f03, + "Incorrect message type, expected 0x7f03, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x096c, + "incorrect sender id, expected 0x096c, is {sender_id}" + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 51, + "incorrect value for index, expected 51, is {}", + msg.index + ); + assert_eq!( + msg.pid, 28553, + "incorrect value for pid, expected 28553, is {}", + msg.pid + ); + assert_eq!( + msg.socket_count, 30287, + "incorrect value for socket_count, expected 30287, is {}", + msg.socket_count + ); + assert_eq!( + msg.socket_states, 29554, + "incorrect value for socket_states, expected 29554, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 35843, + "incorrect value for socket_types, expected 35843, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketCounts"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_queues.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_queues.rs new file mode 100644 index 0000000000..8deed780c9 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_process_socket_queues.rs @@ -0,0 +1,357 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_process_socket_queues() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, 80, 109, 15, 223, 97, 100, + 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, 115, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, + 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, + 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 247, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketQueues(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f04, + "Incorrect message type, expected 0x7f04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe8bb, + "incorrect sender id, expected 0xe8bb, is {sender_id}" + ); + assert_eq!( + msg.address_of_largest.as_bytes(), + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + "incorrect value for msg.address_of_largest, expected string '{:?}', is '{:?}'", + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + msg.address_of_largest.as_bytes() + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 181, + "incorrect value for index, expected 181, is {}", + msg.index + ); + assert_eq!( + msg.pid, 19335, + "incorrect value for pid, expected 19335, is {}", + msg.pid + ); + assert_eq!( + msg.recv_queued, 54265, + "incorrect value for recv_queued, expected 54265, is {}", + msg.recv_queued + ); + assert_eq!( + msg.send_queued, 64547, + "incorrect value for send_queued, expected 64547, is {}", + msg.send_queued + ); + assert_eq!( + msg.socket_states, 57103, + "incorrect value for socket_states, expected 57103, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 27984, + "incorrect value for socket_types, expected 27984, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketQueues"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_process_socket_queues() { + { + let json_input = r#"{"crc":63234,"length":121,"msg_type":32516,"payload":"tYdL+dMj/FBtD99hZGRyZXNzIG9mIGxhcmdlc3QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":59579,"index":181,"pid":19335,"recv_queued":54265,"send_queued":64547,"socket_types":27984,"socket_states":57103,"address_of_largest":"address of largest\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketQueues(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f04, + "Incorrect message type, expected 0x7f04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe8bb, + "incorrect sender id, expected 0xe8bb, is {sender_id}" + ); + assert_eq!( + msg.address_of_largest.as_bytes(), + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + "incorrect value for msg.address_of_largest, expected string '{:?}', is '{:?}'", + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + msg.address_of_largest.as_bytes() + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 181, + "incorrect value for index, expected 181, is {}", + msg.index + ); + assert_eq!( + msg.pid, 19335, + "incorrect value for pid, expected 19335, is {}", + msg.pid + ); + assert_eq!( + msg.recv_queued, 54265, + "incorrect value for recv_queued, expected 54265, is {}", + msg.recv_queued + ); + assert_eq!( + msg.send_queued, 64547, + "incorrect value for send_queued, expected 64547, is {}", + msg.send_queued + ); + assert_eq!( + msg.socket_states, 57103, + "incorrect value for socket_states, expected 57103, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 27984, + "incorrect value for socket_types, expected 27984, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketQueues"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_process_socket_queues`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_process_socket_queues() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 127, 187, 232, 121, 181, 135, 75, 249, 211, 35, 252, 80, 109, 15, 223, 97, 100, + 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, 115, 116, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, + 114, 111, 99, 101, 115, 115, 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, + 103, 49, 32, 97, 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52, 2, 247, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxProcessSocketQueues( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxProcessSocketQueues(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f04, + "Incorrect message type, expected 0x7f04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe8bb, + "incorrect sender id, expected 0xe8bb, is {sender_id}" + ); + assert_eq!( + msg.address_of_largest.as_bytes(), + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + "incorrect value for msg.address_of_largest, expected string '{:?}', is '{:?}'", + &[ + 97, 100, 100, 114, 101, 115, 115, 32, 111, 102, 32, 108, 97, 114, 103, 101, + 115, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ], + msg.address_of_largest.as_bytes() + ); + assert_eq!( + msg.cmdline.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + "incorrect value for msg.cmdline, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 112, 114, 111, 99, 101, 115, 115, + 45, 110, 97, 109, 101, 32, 97, 114, 103, 48, 32, 97, 114, 103, 49, 32, 97, + 114, 103, 50, 32, 97, 114, 103, 51, 32, 97, 114, 103, 52 + ], + msg.cmdline.as_bytes() + ); + assert_eq!( + msg.index, 181, + "incorrect value for index, expected 181, is {}", + msg.index + ); + assert_eq!( + msg.pid, 19335, + "incorrect value for pid, expected 19335, is {}", + msg.pid + ); + assert_eq!( + msg.recv_queued, 54265, + "incorrect value for recv_queued, expected 54265, is {}", + msg.recv_queued + ); + assert_eq!( + msg.send_queued, 64547, + "incorrect value for send_queued, expected 64547, is {}", + msg.send_queued + ); + assert_eq!( + msg.socket_states, 57103, + "incorrect value for socket_states, expected 57103, is {}", + msg.socket_states + ); + assert_eq!( + msg.socket_types, 27984, + "incorrect value for socket_types, expected 27984, is {}", + msg.socket_types + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxProcessSocketQueues"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_socket_usage.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_socket_usage.rs new file mode 100644 index 0000000000..15b36efa32 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_socket_usage.rs @@ -0,0 +1,685 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_socket_usage() { + { + let mut payload = Cursor::new(vec![ + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, 246, 154, 251, 17, 224, + 179, 26, 169, 177, 90, 149, 213, 214, 6, 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, + 217, 209, 52, 14, 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, 176, 74, 159, 129, 154, + 153, 162, 229, 130, 154, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSocketUsage(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f05, + "Incorrect message type, expected 0x7f05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a72, + "incorrect sender id, expected 0x8a72, is {sender_id}" + ); + assert_eq!( + msg.avg_queue_depth, 2907030541, + "incorrect value for avg_queue_depth, expected 2907030541, is {}", + msg.avg_queue_depth + ); + assert_eq!( + msg.max_queue_depth, 3048922691, + "incorrect value for max_queue_depth, expected 3048922691, is {}", + msg.max_queue_depth + ); + assert_eq!( + msg.socket_state_counts[0], 39670, + "incorrect value for socket_state_counts[0], expected 39670, is {}", + msg.socket_state_counts[0] + ); + assert_eq!( + msg.socket_state_counts[1], 4603, + "incorrect value for socket_state_counts[1], expected 4603, is {}", + msg.socket_state_counts[1] + ); + assert_eq!( + msg.socket_state_counts[2], 46048, + "incorrect value for socket_state_counts[2], expected 46048, is {}", + msg.socket_state_counts[2] + ); + assert_eq!( + msg.socket_state_counts[3], 43290, + "incorrect value for socket_state_counts[3], expected 43290, is {}", + msg.socket_state_counts[3] + ); + assert_eq!( + msg.socket_state_counts[4], 23217, + "incorrect value for socket_state_counts[4], expected 23217, is {}", + msg.socket_state_counts[4] + ); + assert_eq!( + msg.socket_state_counts[5], 54677, + "incorrect value for socket_state_counts[5], expected 54677, is {}", + msg.socket_state_counts[5] + ); + assert_eq!( + msg.socket_state_counts[6], 1750, + "incorrect value for socket_state_counts[6], expected 1750, is {}", + msg.socket_state_counts[6] + ); + assert_eq!( + msg.socket_state_counts[7], 16510, + "incorrect value for socket_state_counts[7], expected 16510, is {}", + msg.socket_state_counts[7] + ); + assert_eq!( + msg.socket_state_counts[8], 47480, + "incorrect value for socket_state_counts[8], expected 47480, is {}", + msg.socket_state_counts[8] + ); + assert_eq!( + msg.socket_state_counts[9], 33620, + "incorrect value for socket_state_counts[9], expected 33620, is {}", + msg.socket_state_counts[9] + ); + assert_eq!( + msg.socket_state_counts[10], 28616, + "incorrect value for socket_state_counts[10], expected 28616, is {}", + msg.socket_state_counts[10] + ); + assert_eq!( + msg.socket_state_counts[11], 36128, + "incorrect value for socket_state_counts[11], expected 36128, is {}", + msg.socket_state_counts[11] + ); + assert_eq!( + msg.socket_state_counts[12], 53721, + "incorrect value for socket_state_counts[12], expected 53721, is {}", + msg.socket_state_counts[12] + ); + assert_eq!( + msg.socket_state_counts[13], 3636, + "incorrect value for socket_state_counts[13], expected 3636, is {}", + msg.socket_state_counts[13] + ); + assert_eq!( + msg.socket_state_counts[14], 37822, + "incorrect value for socket_state_counts[14], expected 37822, is {}", + msg.socket_state_counts[14] + ); + assert_eq!( + msg.socket_state_counts[15], 63135, + "incorrect value for socket_state_counts[15], expected 63135, is {}", + msg.socket_state_counts[15] + ); + assert_eq!( + msg.socket_type_counts[0], 31373, + "incorrect value for socket_type_counts[0], expected 31373, is {}", + msg.socket_type_counts[0] + ); + assert_eq!( + msg.socket_type_counts[1], 30676, + "incorrect value for socket_type_counts[1], expected 30676, is {}", + msg.socket_type_counts[1] + ); + assert_eq!( + msg.socket_type_counts[2], 7811, + "incorrect value for socket_type_counts[2], expected 7811, is {}", + msg.socket_type_counts[2] + ); + assert_eq!( + msg.socket_type_counts[3], 12152, + "incorrect value for socket_type_counts[3], expected 12152, is {}", + msg.socket_type_counts[3] + ); + assert_eq!( + msg.socket_type_counts[4], 27929, + "incorrect value for socket_type_counts[4], expected 27929, is {}", + msg.socket_type_counts[4] + ); + assert_eq!( + msg.socket_type_counts[5], 16794, + "incorrect value for socket_type_counts[5], expected 16794, is {}", + msg.socket_type_counts[5] + ); + assert_eq!( + msg.socket_type_counts[6], 42116, + "incorrect value for socket_type_counts[6], expected 42116, is {}", + msg.socket_type_counts[6] + ); + assert_eq!( + msg.socket_type_counts[7], 7719, + "incorrect value for socket_type_counts[7], expected 7719, is {}", + msg.socket_type_counts[7] + ); + assert_eq!( + msg.socket_type_counts[8], 44830, + "incorrect value for socket_type_counts[8], expected 44830, is {}", + msg.socket_type_counts[8] + ); + assert_eq!( + msg.socket_type_counts[9], 11272, + "incorrect value for socket_type_counts[9], expected 11272, is {}", + msg.socket_type_counts[9] + ); + assert_eq!( + msg.socket_type_counts[10], 28444, + "incorrect value for socket_type_counts[10], expected 28444, is {}", + msg.socket_type_counts[10] + ); + assert_eq!( + msg.socket_type_counts[11], 61676, + "incorrect value for socket_type_counts[11], expected 61676, is {}", + msg.socket_type_counts[11] + ); + assert_eq!( + msg.socket_type_counts[12], 19120, + "incorrect value for socket_type_counts[12], expected 19120, is {}", + msg.socket_type_counts[12] + ); + assert_eq!( + msg.socket_type_counts[13], 33183, + "incorrect value for socket_type_counts[13], expected 33183, is {}", + msg.socket_type_counts[13] + ); + assert_eq!( + msg.socket_type_counts[14], 39322, + "incorrect value for socket_type_counts[14], expected 39322, is {}", + msg.socket_type_counts[14] + ); + assert_eq!( + msg.socket_type_counts[15], 58786, + "incorrect value for socket_type_counts[15], expected 58786, is {}", + msg.socket_type_counts[15] + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSocketUsage"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_socket_usage() { + { + let json_input = r#"{"crc":39554,"length":72,"msg_type":32517,"payload":"DcRFrUPeurX2mvsR4LMaqbFaldXWBn5AeLlUg8hvII3Z0TQOvpOf9o161HeDHngvGW2aQYSkJx4erwgsHG/s8LBKn4GamaLl","preamble":85,"sender":35442,"avg_queue_depth":2907030541,"max_queue_depth":3048922691,"socket_state_counts":[39670,4603,46048,43290,23217,54677,1750,16510,47480,33620,28616,36128,53721,3636,37822,63135],"socket_type_counts":[31373,30676,7811,12152,27929,16794,42116,7719,44830,11272,28444,61676,19120,33183,39322,58786]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSocketUsage(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f05, + "Incorrect message type, expected 0x7f05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a72, + "incorrect sender id, expected 0x8a72, is {sender_id}" + ); + assert_eq!( + msg.avg_queue_depth, 2907030541, + "incorrect value for avg_queue_depth, expected 2907030541, is {}", + msg.avg_queue_depth + ); + assert_eq!( + msg.max_queue_depth, 3048922691, + "incorrect value for max_queue_depth, expected 3048922691, is {}", + msg.max_queue_depth + ); + assert_eq!( + msg.socket_state_counts[0], 39670, + "incorrect value for socket_state_counts[0], expected 39670, is {}", + msg.socket_state_counts[0] + ); + assert_eq!( + msg.socket_state_counts[1], 4603, + "incorrect value for socket_state_counts[1], expected 4603, is {}", + msg.socket_state_counts[1] + ); + assert_eq!( + msg.socket_state_counts[2], 46048, + "incorrect value for socket_state_counts[2], expected 46048, is {}", + msg.socket_state_counts[2] + ); + assert_eq!( + msg.socket_state_counts[3], 43290, + "incorrect value for socket_state_counts[3], expected 43290, is {}", + msg.socket_state_counts[3] + ); + assert_eq!( + msg.socket_state_counts[4], 23217, + "incorrect value for socket_state_counts[4], expected 23217, is {}", + msg.socket_state_counts[4] + ); + assert_eq!( + msg.socket_state_counts[5], 54677, + "incorrect value for socket_state_counts[5], expected 54677, is {}", + msg.socket_state_counts[5] + ); + assert_eq!( + msg.socket_state_counts[6], 1750, + "incorrect value for socket_state_counts[6], expected 1750, is {}", + msg.socket_state_counts[6] + ); + assert_eq!( + msg.socket_state_counts[7], 16510, + "incorrect value for socket_state_counts[7], expected 16510, is {}", + msg.socket_state_counts[7] + ); + assert_eq!( + msg.socket_state_counts[8], 47480, + "incorrect value for socket_state_counts[8], expected 47480, is {}", + msg.socket_state_counts[8] + ); + assert_eq!( + msg.socket_state_counts[9], 33620, + "incorrect value for socket_state_counts[9], expected 33620, is {}", + msg.socket_state_counts[9] + ); + assert_eq!( + msg.socket_state_counts[10], 28616, + "incorrect value for socket_state_counts[10], expected 28616, is {}", + msg.socket_state_counts[10] + ); + assert_eq!( + msg.socket_state_counts[11], 36128, + "incorrect value for socket_state_counts[11], expected 36128, is {}", + msg.socket_state_counts[11] + ); + assert_eq!( + msg.socket_state_counts[12], 53721, + "incorrect value for socket_state_counts[12], expected 53721, is {}", + msg.socket_state_counts[12] + ); + assert_eq!( + msg.socket_state_counts[13], 3636, + "incorrect value for socket_state_counts[13], expected 3636, is {}", + msg.socket_state_counts[13] + ); + assert_eq!( + msg.socket_state_counts[14], 37822, + "incorrect value for socket_state_counts[14], expected 37822, is {}", + msg.socket_state_counts[14] + ); + assert_eq!( + msg.socket_state_counts[15], 63135, + "incorrect value for socket_state_counts[15], expected 63135, is {}", + msg.socket_state_counts[15] + ); + assert_eq!( + msg.socket_type_counts[0], 31373, + "incorrect value for socket_type_counts[0], expected 31373, is {}", + msg.socket_type_counts[0] + ); + assert_eq!( + msg.socket_type_counts[1], 30676, + "incorrect value for socket_type_counts[1], expected 30676, is {}", + msg.socket_type_counts[1] + ); + assert_eq!( + msg.socket_type_counts[2], 7811, + "incorrect value for socket_type_counts[2], expected 7811, is {}", + msg.socket_type_counts[2] + ); + assert_eq!( + msg.socket_type_counts[3], 12152, + "incorrect value for socket_type_counts[3], expected 12152, is {}", + msg.socket_type_counts[3] + ); + assert_eq!( + msg.socket_type_counts[4], 27929, + "incorrect value for socket_type_counts[4], expected 27929, is {}", + msg.socket_type_counts[4] + ); + assert_eq!( + msg.socket_type_counts[5], 16794, + "incorrect value for socket_type_counts[5], expected 16794, is {}", + msg.socket_type_counts[5] + ); + assert_eq!( + msg.socket_type_counts[6], 42116, + "incorrect value for socket_type_counts[6], expected 42116, is {}", + msg.socket_type_counts[6] + ); + assert_eq!( + msg.socket_type_counts[7], 7719, + "incorrect value for socket_type_counts[7], expected 7719, is {}", + msg.socket_type_counts[7] + ); + assert_eq!( + msg.socket_type_counts[8], 44830, + "incorrect value for socket_type_counts[8], expected 44830, is {}", + msg.socket_type_counts[8] + ); + assert_eq!( + msg.socket_type_counts[9], 11272, + "incorrect value for socket_type_counts[9], expected 11272, is {}", + msg.socket_type_counts[9] + ); + assert_eq!( + msg.socket_type_counts[10], 28444, + "incorrect value for socket_type_counts[10], expected 28444, is {}", + msg.socket_type_counts[10] + ); + assert_eq!( + msg.socket_type_counts[11], 61676, + "incorrect value for socket_type_counts[11], expected 61676, is {}", + msg.socket_type_counts[11] + ); + assert_eq!( + msg.socket_type_counts[12], 19120, + "incorrect value for socket_type_counts[12], expected 19120, is {}", + msg.socket_type_counts[12] + ); + assert_eq!( + msg.socket_type_counts[13], 33183, + "incorrect value for socket_type_counts[13], expected 33183, is {}", + msg.socket_type_counts[13] + ); + assert_eq!( + msg.socket_type_counts[14], 39322, + "incorrect value for socket_type_counts[14], expected 39322, is {}", + msg.socket_type_counts[14] + ); + assert_eq!( + msg.socket_type_counts[15], 58786, + "incorrect value for socket_type_counts[15], expected 58786, is {}", + msg.socket_type_counts[15] + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSocketUsage"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_socket_usage`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_socket_usage() { + { + let mut payload = Cursor::new(vec![ + 85, 5, 127, 114, 138, 72, 13, 196, 69, 173, 67, 222, 186, 181, 246, 154, 251, 17, 224, + 179, 26, 169, 177, 90, 149, 213, 214, 6, 126, 64, 120, 185, 84, 131, 200, 111, 32, 141, + 217, 209, 52, 14, 190, 147, 159, 246, 141, 122, 212, 119, 131, 30, 120, 47, 25, 109, + 154, 65, 132, 164, 39, 30, 30, 175, 8, 44, 28, 111, 236, 240, 176, 74, 159, 129, 154, + 153, 162, 229, 130, 154, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxSocketUsage( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSocketUsage(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f05, + "Incorrect message type, expected 0x7f05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a72, + "incorrect sender id, expected 0x8a72, is {sender_id}" + ); + assert_eq!( + msg.avg_queue_depth, 2907030541, + "incorrect value for avg_queue_depth, expected 2907030541, is {}", + msg.avg_queue_depth + ); + assert_eq!( + msg.max_queue_depth, 3048922691, + "incorrect value for max_queue_depth, expected 3048922691, is {}", + msg.max_queue_depth + ); + assert_eq!( + msg.socket_state_counts[0], 39670, + "incorrect value for socket_state_counts[0], expected 39670, is {}", + msg.socket_state_counts[0] + ); + assert_eq!( + msg.socket_state_counts[1], 4603, + "incorrect value for socket_state_counts[1], expected 4603, is {}", + msg.socket_state_counts[1] + ); + assert_eq!( + msg.socket_state_counts[2], 46048, + "incorrect value for socket_state_counts[2], expected 46048, is {}", + msg.socket_state_counts[2] + ); + assert_eq!( + msg.socket_state_counts[3], 43290, + "incorrect value for socket_state_counts[3], expected 43290, is {}", + msg.socket_state_counts[3] + ); + assert_eq!( + msg.socket_state_counts[4], 23217, + "incorrect value for socket_state_counts[4], expected 23217, is {}", + msg.socket_state_counts[4] + ); + assert_eq!( + msg.socket_state_counts[5], 54677, + "incorrect value for socket_state_counts[5], expected 54677, is {}", + msg.socket_state_counts[5] + ); + assert_eq!( + msg.socket_state_counts[6], 1750, + "incorrect value for socket_state_counts[6], expected 1750, is {}", + msg.socket_state_counts[6] + ); + assert_eq!( + msg.socket_state_counts[7], 16510, + "incorrect value for socket_state_counts[7], expected 16510, is {}", + msg.socket_state_counts[7] + ); + assert_eq!( + msg.socket_state_counts[8], 47480, + "incorrect value for socket_state_counts[8], expected 47480, is {}", + msg.socket_state_counts[8] + ); + assert_eq!( + msg.socket_state_counts[9], 33620, + "incorrect value for socket_state_counts[9], expected 33620, is {}", + msg.socket_state_counts[9] + ); + assert_eq!( + msg.socket_state_counts[10], 28616, + "incorrect value for socket_state_counts[10], expected 28616, is {}", + msg.socket_state_counts[10] + ); + assert_eq!( + msg.socket_state_counts[11], 36128, + "incorrect value for socket_state_counts[11], expected 36128, is {}", + msg.socket_state_counts[11] + ); + assert_eq!( + msg.socket_state_counts[12], 53721, + "incorrect value for socket_state_counts[12], expected 53721, is {}", + msg.socket_state_counts[12] + ); + assert_eq!( + msg.socket_state_counts[13], 3636, + "incorrect value for socket_state_counts[13], expected 3636, is {}", + msg.socket_state_counts[13] + ); + assert_eq!( + msg.socket_state_counts[14], 37822, + "incorrect value for socket_state_counts[14], expected 37822, is {}", + msg.socket_state_counts[14] + ); + assert_eq!( + msg.socket_state_counts[15], 63135, + "incorrect value for socket_state_counts[15], expected 63135, is {}", + msg.socket_state_counts[15] + ); + assert_eq!( + msg.socket_type_counts[0], 31373, + "incorrect value for socket_type_counts[0], expected 31373, is {}", + msg.socket_type_counts[0] + ); + assert_eq!( + msg.socket_type_counts[1], 30676, + "incorrect value for socket_type_counts[1], expected 30676, is {}", + msg.socket_type_counts[1] + ); + assert_eq!( + msg.socket_type_counts[2], 7811, + "incorrect value for socket_type_counts[2], expected 7811, is {}", + msg.socket_type_counts[2] + ); + assert_eq!( + msg.socket_type_counts[3], 12152, + "incorrect value for socket_type_counts[3], expected 12152, is {}", + msg.socket_type_counts[3] + ); + assert_eq!( + msg.socket_type_counts[4], 27929, + "incorrect value for socket_type_counts[4], expected 27929, is {}", + msg.socket_type_counts[4] + ); + assert_eq!( + msg.socket_type_counts[5], 16794, + "incorrect value for socket_type_counts[5], expected 16794, is {}", + msg.socket_type_counts[5] + ); + assert_eq!( + msg.socket_type_counts[6], 42116, + "incorrect value for socket_type_counts[6], expected 42116, is {}", + msg.socket_type_counts[6] + ); + assert_eq!( + msg.socket_type_counts[7], 7719, + "incorrect value for socket_type_counts[7], expected 7719, is {}", + msg.socket_type_counts[7] + ); + assert_eq!( + msg.socket_type_counts[8], 44830, + "incorrect value for socket_type_counts[8], expected 44830, is {}", + msg.socket_type_counts[8] + ); + assert_eq!( + msg.socket_type_counts[9], 11272, + "incorrect value for socket_type_counts[9], expected 11272, is {}", + msg.socket_type_counts[9] + ); + assert_eq!( + msg.socket_type_counts[10], 28444, + "incorrect value for socket_type_counts[10], expected 28444, is {}", + msg.socket_type_counts[10] + ); + assert_eq!( + msg.socket_type_counts[11], 61676, + "incorrect value for socket_type_counts[11], expected 61676, is {}", + msg.socket_type_counts[11] + ); + assert_eq!( + msg.socket_type_counts[12], 19120, + "incorrect value for socket_type_counts[12], expected 19120, is {}", + msg.socket_type_counts[12] + ); + assert_eq!( + msg.socket_type_counts[13], 33183, + "incorrect value for socket_type_counts[13], expected 33183, is {}", + msg.socket_type_counts[13] + ); + assert_eq!( + msg.socket_type_counts[14], 39322, + "incorrect value for socket_type_counts[14], expected 39322, is {}", + msg.socket_type_counts[14] + ); + assert_eq!( + msg.socket_type_counts[15], 58786, + "incorrect value for socket_type_counts[15], expected 58786, is {}", + msg.socket_type_counts[15] + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSocketUsage"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state.rs new file mode 100644 index 0000000000..bc8b1abbfe --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state.rs @@ -0,0 +1,289 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_sys_state() { + { + let mut payload = Cursor::new(vec![ + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, 161, 229, 250, 186, 108, 30, 106, + 5, 9, 229, 242, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f0a, + "Incorrect message type, expected 0x7f0a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa755, + "incorrect sender id, expected 0xa755, is {sender_id}" + ); + assert_eq!( + msg.flags, 9, + "incorrect value for flags, expected 9, is {}", + msg.flags + ); + assert_eq!( + msg.mem_total, 53012, + "incorrect value for mem_total, expected 53012, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 125, + "incorrect value for pcpu, expected 125, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 47866, + "incorrect value for pid_count, expected 47866, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 215, + "incorrect value for pmem, expected 215, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18372, + "incorrect value for procs_starting, expected 18372, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 58785, + "incorrect value for procs_stopping, expected 58785, is {}", + msg.procs_stopping + ); + assert_eq!( + msg.time, 90840684, + "incorrect value for time, expected 90840684, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysState"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_sys_state() { + { + let json_input = r#"{"crc":62181,"length":15,"msg_type":32522,"payload":"FM9918RHoeX6umweagUJ","preamble":85,"sender":42837,"mem_total":53012,"pcpu":125,"pmem":215,"procs_starting":18372,"procs_stopping":58785,"pid_count":47866,"time":90840684,"flags":9}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f0a, + "Incorrect message type, expected 0x7f0a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa755, + "incorrect sender id, expected 0xa755, is {sender_id}" + ); + assert_eq!( + msg.flags, 9, + "incorrect value for flags, expected 9, is {}", + msg.flags + ); + assert_eq!( + msg.mem_total, 53012, + "incorrect value for mem_total, expected 53012, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 125, + "incorrect value for pcpu, expected 125, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 47866, + "incorrect value for pid_count, expected 47866, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 215, + "incorrect value for pmem, expected 215, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18372, + "incorrect value for procs_starting, expected 18372, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 58785, + "incorrect value for procs_stopping, expected 58785, is {}", + msg.procs_stopping + ); + assert_eq!( + msg.time, 90840684, + "incorrect value for time, expected 90840684, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysState"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_sys_state`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_sys_state() { + { + let mut payload = Cursor::new(vec![ + 85, 10, 127, 85, 167, 15, 20, 207, 125, 215, 196, 71, 161, 229, 250, 186, 108, 30, 106, + 5, 9, 229, 242, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxSysState( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f0a, + "Incorrect message type, expected 0x7f0a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa755, + "incorrect sender id, expected 0xa755, is {sender_id}" + ); + assert_eq!( + msg.flags, 9, + "incorrect value for flags, expected 9, is {}", + msg.flags + ); + assert_eq!( + msg.mem_total, 53012, + "incorrect value for mem_total, expected 53012, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 125, + "incorrect value for pcpu, expected 125, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 47866, + "incorrect value for pid_count, expected 47866, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 215, + "incorrect value for pmem, expected 215, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18372, + "incorrect value for procs_starting, expected 18372, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 58785, + "incorrect value for procs_stopping, expected 58785, is {}", + msg.procs_stopping + ); + assert_eq!( + msg.time, 90840684, + "incorrect value for time, expected 90840684, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysState"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state_dep_a.rs new file mode 100644 index 0000000000..5d888a50a9 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_linux_msg_linux_sys_state_dep_a.rs @@ -0,0 +1,257 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_linux_msg_linux_sys_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 127, 84, 56, 10, 188, 163, 211, 194, 115, 71, 101, 103, 124, 201, 223, 223, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f02, + "Incorrect message type, expected 0x7f02, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3854, + "incorrect sender id, expected 0x3854, is {sender_id}" + ); + assert_eq!( + msg.mem_total, 41916, + "incorrect value for mem_total, expected 41916, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 211, + "incorrect value for pcpu, expected 211, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 51580, + "incorrect value for pid_count, expected 51580, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 194, + "incorrect value for pmem, expected 194, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18291, + "incorrect value for procs_starting, expected 18291, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 26469, + "incorrect value for procs_stopping, expected 26469, is {}", + msg.procs_stopping + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysStateDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_linux_msg_linux_sys_state_dep_a() { + { + let json_input = r#"{"crc":57311,"length":10,"msg_type":32514,"payload":"vKPTwnNHZWd8yQ==","preamble":85,"sender":14420,"mem_total":41916,"pcpu":211,"pmem":194,"procs_starting":18291,"procs_stopping":26469,"pid_count":51580}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f02, + "Incorrect message type, expected 0x7f02, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3854, + "incorrect sender id, expected 0x3854, is {sender_id}" + ); + assert_eq!( + msg.mem_total, 41916, + "incorrect value for mem_total, expected 41916, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 211, + "incorrect value for pcpu, expected 211, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 51580, + "incorrect value for pid_count, expected 51580, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 194, + "incorrect value for pmem, expected 194, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18291, + "incorrect value for procs_starting, expected 18291, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 26469, + "incorrect value for procs_stopping, expected 26469, is {}", + msg.procs_stopping + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysStateDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_linux_msg_linux_sys_state_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_linux_msg_linux_sys_state_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 127, 84, 56, 10, 188, 163, 211, 194, 115, 71, 101, 103, 124, 201, 223, 223, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgLinuxSysStateDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgLinuxSysStateDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x7f02, + "Incorrect message type, expected 0x7f02, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3854, + "incorrect sender id, expected 0x3854, is {sender_id}" + ); + assert_eq!( + msg.mem_total, 41916, + "incorrect value for mem_total, expected 41916, is {}", + msg.mem_total + ); + assert_eq!( + msg.pcpu, 211, + "incorrect value for pcpu, expected 211, is {}", + msg.pcpu + ); + assert_eq!( + msg.pid_count, 51580, + "incorrect value for pid_count, expected 51580, is {}", + msg.pid_count + ); + assert_eq!( + msg.pmem, 194, + "incorrect value for pmem, expected 194, is {}", + msg.pmem + ); + assert_eq!( + msg.procs_starting, 18291, + "incorrect value for procs_starting, expected 18291, is {}", + msg.procs_starting + ); + assert_eq!( + msg.procs_stopping, 26469, + "incorrect value for procs_stopping, expected 26469, is {}", + msg.procs_stopping + ); + } + _ => panic!("Invalid message type! Expected a MsgLinuxSysStateDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_mag_msg_mag_raw.rs b/rust/sbp/tests/integration/auto_check_sbp_mag_msg_mag_raw.rs new file mode 100644 index 0000000000..b8c34df79d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_mag_msg_mag_raw.rs @@ -0,0 +1,242 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_mag_msg_mag_raw() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, 206, 98, 3, 230, 2, 110, 229, 159, 23, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMagRaw(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x902, + "Incorrect message type, expected 0x902, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.mag_x, 866, + "incorrect value for mag_x, expected 866, is {}", + msg.mag_x + ); + assert_eq!( + msg.mag_y, 742, + "incorrect value for mag_y, expected 742, is {}", + msg.mag_y + ); + assert_eq!( + msg.mag_z, -6802, + "incorrect value for mag_z, expected -6802, is {}", + msg.mag_z + ); + assert_eq!( + msg.tow, 3332301741, + "incorrect value for tow, expected 3332301741, is {}", + msg.tow + ); + assert_eq!( + msg.tow_f, 206, + "incorrect value for tow_f, expected 206, is {}", + msg.tow_f + ); + } + _ => panic!("Invalid message type! Expected a MsgMagRaw"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_mag_msg_mag_raw() { + { + let json_input = r#"{"preamble":85,"msg_type":2306,"sender":1219,"length":11,"payload":"reOexs5iA+YCbuU=","crc":6047,"tow":3332301741,"tow_f":206,"mag_x":866,"mag_y":742,"mag_z":-6802}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMagRaw(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x902, + "Incorrect message type, expected 0x902, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.mag_x, 866, + "incorrect value for mag_x, expected 866, is {}", + msg.mag_x + ); + assert_eq!( + msg.mag_y, 742, + "incorrect value for mag_y, expected 742, is {}", + msg.mag_y + ); + assert_eq!( + msg.mag_z, -6802, + "incorrect value for mag_z, expected -6802, is {}", + msg.mag_z + ); + assert_eq!( + msg.tow, 3332301741, + "incorrect value for tow, expected 3332301741, is {}", + msg.tow + ); + assert_eq!( + msg.tow_f, 206, + "incorrect value for tow_f, expected 206, is {}", + msg.tow_f + ); + } + _ => panic!("Invalid message type! Expected a MsgMagRaw"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_mag_msg_mag_raw`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_mag_msg_mag_raw() { + { + let mut payload = Cursor::new(vec![ + 85, 2, 9, 195, 4, 11, 173, 227, 158, 198, 206, 98, 3, 230, 2, 110, 229, 159, 23, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgMagRaw( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgMagRaw(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x902, + "Incorrect message type, expected 0x902, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.mag_x, 866, + "incorrect value for mag_x, expected 866, is {}", + msg.mag_x + ); + assert_eq!( + msg.mag_y, 742, + "incorrect value for mag_y, expected 742, is {}", + msg.mag_y + ); + assert_eq!( + msg.mag_z, -6802, + "incorrect value for mag_z, expected -6802, is {}", + msg.mag_z + ); + assert_eq!( + msg.tow, 3332301741, + "incorrect value for tow, expected 3332301741, is {}", + msg.tow + ); + assert_eq!( + msg.tow_f, 206, + "incorrect value for tow_f, expected 206, is {}", + msg.tow_f + ); + } + _ => panic!("Invalid message type! Expected a MsgMagRaw"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_baseline_heading_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_baseline_heading_dep_a.rs new file mode 100644 index 0000000000..d30052e257 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_baseline_heading_dep_a.rs @@ -0,0 +1,227 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_navigation_msg_baseline_heading_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 2, 124, 206, 10, 82, 109, 88, 176, 68, 14, 82, 203, 186, 58, 173, 182, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeadingDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x207, + "Incorrect message type, expected 0x207, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce7c, + "incorrect sender id, expected 0xce7c, is {sender_id}" + ); + assert_eq!( + msg.flags, 58, + "incorrect value for flags, expected 58, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 3411152452, + "incorrect value for heading, expected 3411152452, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 186, + "incorrect value for n_sats, expected 186, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 2958585170, + "incorrect value for tow, expected 2958585170, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeadingDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_navigation_msg_baseline_heading_dep_a() { + { + let json_input = r#"{"crc":46765,"length":10,"msg_type":519,"payload":"Um1YsEQOUsu6Og==","preamble":85,"sender":52860,"tow":2958585170,"heading":3411152452,"n_sats":186,"flags":58}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeadingDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x207, + "Incorrect message type, expected 0x207, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce7c, + "incorrect sender id, expected 0xce7c, is {sender_id}" + ); + assert_eq!( + msg.flags, 58, + "incorrect value for flags, expected 58, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 3411152452, + "incorrect value for heading, expected 3411152452, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 186, + "incorrect value for n_sats, expected 186, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 2958585170, + "incorrect value for tow, expected 2958585170, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeadingDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_navigation_msg_baseline_heading_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_navigation_msg_baseline_heading_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 2, 124, 206, 10, 82, 109, 88, 176, 68, 14, 82, 203, 186, 58, 173, 182, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgBaselineHeadingDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeadingDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x207, + "Incorrect message type, expected 0x207, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce7c, + "incorrect sender id, expected 0xce7c, is {sender_id}" + ); + assert_eq!( + msg.flags, 58, + "incorrect value for flags, expected 58, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 3411152452, + "incorrect value for heading, expected 3411152452, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 186, + "incorrect value for n_sats, expected 186, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 2958585170, + "incorrect value for tow, expected 2958585170, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeadingDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_pos_llh_acc.rs b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_pos_llh_acc.rs new file mode 100644 index 0000000000..c037c07179 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_pos_llh_acc.rs @@ -0,0 +1,350 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_navigation_msg_pos_llh_acc() { + { + let mut payload = Cursor::new(vec![ + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, 51, 51, 139, 189, 64, 154, 153, + 153, 153, 25, 151, 192, 64, 51, 51, 51, 51, 51, 161, 176, 64, 51, 51, 51, 51, 51, 101, + 179, 64, 51, 163, 22, 69, 154, 25, 173, 69, 102, 134, 243, 68, 154, 201, 196, 69, 205, + 224, 0, 70, 51, 35, 72, 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgPosLlhAcc(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x218, + "Incorrect message type, expected 0x218, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c02, + "incorrect sender id, expected 0x1c02, is {sender_id}" + ); + assert!( + msg.at_accuracy.almost_eq(6.29720019531250000e+03), + "incorrect value for at_accuracy, expected 6.29720019531250000e+03, is {:e}", + msg.at_accuracy + ); + assert_eq!( + msg.confidence_and_geoid, 95, + "incorrect value for confidence_and_geoid, expected 95, is {}", + msg.confidence_and_geoid + ); + assert!( + msg.ct_accuracy.almost_eq(1.94819995117187500e+03), + "incorrect value for ct_accuracy, expected 1.94819995117187500e+03, is {:e}", + msg.ct_accuracy + ); + assert_eq!( + msg.flags, 72, + "incorrect value for flags, expected 72, is {}", + msg.flags + ); + assert!( + msg.h_accuracy.almost_eq(2.41019995117187500e+03), + "incorrect value for h_accuracy, expected 2.41019995117187500e+03, is {:e}", + msg.h_accuracy + ); + assert!(msg.h_ellipse.orientation.almost_eq( 2.55019995117187500e+03 ), "incorrect value for h_ellipse.orientation, expected 2.55019995117187500e+03, is {:e}", msg.h_ellipse.orientation); + assert!(msg.h_ellipse.semi_major.almost_eq( 8.24820019531250000e+03 ), "incorrect value for h_ellipse.semi_major, expected 8.24820019531250000e+03, is {:e}", msg.h_ellipse.semi_major); + assert!(msg.h_ellipse.semi_minor.almost_eq( 3.20219995117187500e+03 ), "incorrect value for h_ellipse.semi_minor, expected 3.20219995117187500e+03, is {:e}", msg.h_ellipse.semi_minor); + assert!( + msg.height.almost_eq(4.25719999999999982e+03), + "incorrect value for height, expected 4.25719999999999982e+03, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(7.56319999999999982e+03), + "incorrect value for lat, expected 7.56319999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(8.49420000000000073e+03), + "incorrect value for lon, expected 8.49420000000000073e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.n_sats, 27, + "incorrect value for n_sats, expected 27, is {}", + msg.n_sats + ); + assert!(msg.orthometric_height.almost_eq( 4.96519999999999982e+03 ), "incorrect value for orthometric_height, expected 4.96519999999999982e+03, is {:e}", msg.orthometric_height); + assert_eq!( + msg.tow, 309229607, + "incorrect value for tow, expected 309229607, is {}", + msg.tow + ); + assert!( + msg.v_accuracy.almost_eq(5.53920019531250000e+03), + "incorrect value for v_accuracy, expected 5.53920019531250000e+03, is {:e}", + msg.v_accuracy + ); + } + _ => panic!("Invalid message type! Expected a MsgPosLLHAcc"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_navigation_msg_pos_llh_acc() { + { + let json_input = r#"{"preamble":85,"msg_type":536,"sender":7170,"length":67,"payload":"J3huEjMzMzMzi71AmpmZmRmXwEAzMzMzM6GwQDMzMzMzZbNAM6MWRZoZrUVmhvNEmsnERc3gAEYzI0hFM2MfRV8bSA==","crc":45532,"tow":309229607,"lat":7563.2,"lon":8494.2,"height":4257.2,"orthometric_height":4965.2,"h_accuracy":2410.199951171875,"v_accuracy":5539.2001953125,"ct_accuracy":1948.199951171875,"at_accuracy":6297.2001953125,"h_ellipse":{"semi_major":8248.2001953125,"semi_minor":3202.199951171875,"orientation":2550.199951171875},"confidence_and_geoid":95,"n_sats":27,"flags":72}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgPosLlhAcc(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x218, + "Incorrect message type, expected 0x218, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c02, + "incorrect sender id, expected 0x1c02, is {sender_id}" + ); + assert!( + msg.at_accuracy.almost_eq(6.29720019531250000e+03), + "incorrect value for at_accuracy, expected 6.29720019531250000e+03, is {:e}", + msg.at_accuracy + ); + assert_eq!( + msg.confidence_and_geoid, 95, + "incorrect value for confidence_and_geoid, expected 95, is {}", + msg.confidence_and_geoid + ); + assert!( + msg.ct_accuracy.almost_eq(1.94819995117187500e+03), + "incorrect value for ct_accuracy, expected 1.94819995117187500e+03, is {:e}", + msg.ct_accuracy + ); + assert_eq!( + msg.flags, 72, + "incorrect value for flags, expected 72, is {}", + msg.flags + ); + assert!( + msg.h_accuracy.almost_eq(2.41019995117187500e+03), + "incorrect value for h_accuracy, expected 2.41019995117187500e+03, is {:e}", + msg.h_accuracy + ); + assert!(msg.h_ellipse.orientation.almost_eq( 2.55019995117187500e+03 ), "incorrect value for h_ellipse.orientation, expected 2.55019995117187500e+03, is {:e}", msg.h_ellipse.orientation); + assert!(msg.h_ellipse.semi_major.almost_eq( 8.24820019531250000e+03 ), "incorrect value for h_ellipse.semi_major, expected 8.24820019531250000e+03, is {:e}", msg.h_ellipse.semi_major); + assert!(msg.h_ellipse.semi_minor.almost_eq( 3.20219995117187500e+03 ), "incorrect value for h_ellipse.semi_minor, expected 3.20219995117187500e+03, is {:e}", msg.h_ellipse.semi_minor); + assert!( + msg.height.almost_eq(4.25719999999999982e+03), + "incorrect value for height, expected 4.25719999999999982e+03, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(7.56319999999999982e+03), + "incorrect value for lat, expected 7.56319999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(8.49420000000000073e+03), + "incorrect value for lon, expected 8.49420000000000073e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.n_sats, 27, + "incorrect value for n_sats, expected 27, is {}", + msg.n_sats + ); + assert!(msg.orthometric_height.almost_eq( 4.96519999999999982e+03 ), "incorrect value for orthometric_height, expected 4.96519999999999982e+03, is {:e}", msg.orthometric_height); + assert_eq!( + msg.tow, 309229607, + "incorrect value for tow, expected 309229607, is {}", + msg.tow + ); + assert!( + msg.v_accuracy.almost_eq(5.53920019531250000e+03), + "incorrect value for v_accuracy, expected 5.53920019531250000e+03, is {:e}", + msg.v_accuracy + ); + } + _ => panic!("Invalid message type! Expected a MsgPosLLHAcc"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_navigation_msg_pos_llh_acc`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_navigation_msg_pos_llh_acc() { + { + let mut payload = Cursor::new(vec![ + 85, 24, 2, 2, 28, 67, 39, 120, 110, 18, 51, 51, 51, 51, 51, 139, 189, 64, 154, 153, + 153, 153, 25, 151, 192, 64, 51, 51, 51, 51, 51, 161, 176, 64, 51, 51, 51, 51, 51, 101, + 179, 64, 51, 163, 22, 69, 154, 25, 173, 69, 102, 134, 243, 68, 154, 201, 196, 69, 205, + 224, 0, 70, 51, 35, 72, 69, 51, 99, 31, 69, 95, 27, 72, 220, 177, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgPosLlhAcc( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgPosLlhAcc(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x218, + "Incorrect message type, expected 0x218, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c02, + "incorrect sender id, expected 0x1c02, is {sender_id}" + ); + assert!( + msg.at_accuracy.almost_eq(6.29720019531250000e+03), + "incorrect value for at_accuracy, expected 6.29720019531250000e+03, is {:e}", + msg.at_accuracy + ); + assert_eq!( + msg.confidence_and_geoid, 95, + "incorrect value for confidence_and_geoid, expected 95, is {}", + msg.confidence_and_geoid + ); + assert!( + msg.ct_accuracy.almost_eq(1.94819995117187500e+03), + "incorrect value for ct_accuracy, expected 1.94819995117187500e+03, is {:e}", + msg.ct_accuracy + ); + assert_eq!( + msg.flags, 72, + "incorrect value for flags, expected 72, is {}", + msg.flags + ); + assert!( + msg.h_accuracy.almost_eq(2.41019995117187500e+03), + "incorrect value for h_accuracy, expected 2.41019995117187500e+03, is {:e}", + msg.h_accuracy + ); + assert!(msg.h_ellipse.orientation.almost_eq( 2.55019995117187500e+03 ), "incorrect value for h_ellipse.orientation, expected 2.55019995117187500e+03, is {:e}", msg.h_ellipse.orientation); + assert!(msg.h_ellipse.semi_major.almost_eq( 8.24820019531250000e+03 ), "incorrect value for h_ellipse.semi_major, expected 8.24820019531250000e+03, is {:e}", msg.h_ellipse.semi_major); + assert!(msg.h_ellipse.semi_minor.almost_eq( 3.20219995117187500e+03 ), "incorrect value for h_ellipse.semi_minor, expected 3.20219995117187500e+03, is {:e}", msg.h_ellipse.semi_minor); + assert!( + msg.height.almost_eq(4.25719999999999982e+03), + "incorrect value for height, expected 4.25719999999999982e+03, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(7.56319999999999982e+03), + "incorrect value for lat, expected 7.56319999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(8.49420000000000073e+03), + "incorrect value for lon, expected 8.49420000000000073e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.n_sats, 27, + "incorrect value for n_sats, expected 27, is {}", + msg.n_sats + ); + assert!(msg.orthometric_height.almost_eq( 4.96519999999999982e+03 ), "incorrect value for orthometric_height, expected 4.96519999999999982e+03, is {:e}", msg.orthometric_height); + assert_eq!( + msg.tow, 309229607, + "incorrect value for tow, expected 309229607, is {}", + msg.tow + ); + assert!( + msg.v_accuracy.almost_eq(5.53920019531250000e+03), + "incorrect value for v_accuracy, expected 5.53920019531250000e+03, is {:e}", + msg.v_accuracy + ); + } + _ => panic!("Invalid message type! Expected a MsgPosLLHAcc"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level.rs b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level.rs index ec99fce1d7..d2225d3e16 100644 --- a/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level.rs +++ b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level.rs @@ -22,8 +22,11 @@ use crate::*; fn test_auto_check_sbp_navigation_msg_protection_level() { { let mut payload = Cursor::new(vec![ - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, 89, 84, 167, 41, 57, 21, 217, + 244, 61, 161, 83, 104, 140, 137, 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, + 153, 153, 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, 38, 221, 208, + 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, 235, 227, 183, 160, 187, 93, 116, 224, + 105, 40, 32, 33, 133, 188, ]); // Test the round trip payload parsing @@ -34,55 +37,125 @@ fn test_auto_check_sbp_navigation_msg_protection_level() { .expect("failed to parse message") }; match &sbp_msg { - sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + sbp::messages::Sbp::MsgProtectionLevel(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x216, - "Incorrect message type, expected 0x216, is {}", + msg_type, 0x217, + "Incorrect message type, expected 0x217, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0x1000, - "incorrect sender id, expected 0x1000, is {sender_id}" + sender_id, 0x032d, + "incorrect sender id, expected 0x032d, is {sender_id}" ); assert_eq!( - msg.flags, 0, - "incorrect value for flags, expected 0, is {}", + msg.atpl, 10663, + "incorrect value for atpl, expected 10663, is {}", + msg.atpl + ); + assert_eq!( + msg.ctpl, 5433, + "incorrect value for ctpl, expected 5433, is {}", + msg.ctpl + ); + assert_eq!( + msg.flags, 555755625, + "incorrect value for flags, expected 555755625, is {}", msg.flags ); + assert_eq!( + msg.heading, -529244741, + "incorrect value for heading, expected -529244741, is {}", + msg.heading + ); assert!( - msg.height.almost_eq(0.00000000000000000e+00), - "incorrect value for height, expected 0.00000000000000000e+00, is {:e}", + msg.height.almost_eq(4.12199999999999989e+02), + "incorrect value for height, expected 4.12199999999999989e+02, is {:e}", msg.height ); assert_eq!( - msg.hpl, 0, - "incorrect value for hpl, expected 0, is {}", + msg.hopl, 26707, + "incorrect value for hopl, expected 26707, is {}", + msg.hopl + ); + assert_eq!( + msg.hpl, 41013, + "incorrect value for hpl, expected 41013, is {}", msg.hpl ); + assert_eq!( + msg.hvpl, 62681, + "incorrect value for hvpl, expected 62681, is {}", + msg.hvpl + ); assert!( - msg.lat.almost_eq(0.00000000000000000e+00), - "incorrect value for lat, expected 0.00000000000000000e+00, is {:e}", + msg.lat.almost_eq(5.29019999999999982e+03), + "incorrect value for lat, expected 5.29019999999999982e+03, is {:e}", msg.lat ); assert!( - msg.lon.almost_eq(0.00000000000000000e+00), - "incorrect value for lon, expected 0.00000000000000000e+00, is {:e}", + msg.lon.almost_eq(9.90420000000000073e+03), + "incorrect value for lon, expected 9.90420000000000073e+03, is {:e}", msg.lon ); assert_eq!( - msg.tow, 501867400, - "incorrect value for tow, expected 501867400, is {}", + msg.pitch, -1598561301, + "incorrect value for pitch, expected -1598561301, is {}", + msg.pitch + ); + assert_eq!( + msg.popl, 35212, + "incorrect value for popl, expected 35212, is {}", + msg.popl + ); + assert_eq!( + msg.roll, 1018834477, + "incorrect value for roll, expected 1018834477, is {}", + msg.roll + ); + assert_eq!( + msg.ropl, 63066, + "incorrect value for ropl, expected 63066, is {}", + msg.ropl + ); + assert_eq!( + msg.tow, 4060370030, + "incorrect value for tow, expected 4060370030, is {}", msg.tow ); assert_eq!( - msg.vpl, 0, - "incorrect value for vpl, expected 0, is {}", + msg.v_x, -584647705, + "incorrect value for v_x, expected -584647705, is {}", + msg.v_x + ); + assert_eq!( + msg.v_y, 1353168848, + "incorrect value for v_y, expected 1353168848, is {}", + msg.v_y + ); + assert_eq!( + msg.v_z, -1537140001, + "incorrect value for v_z, expected -1537140001, is {}", + msg.v_z + ); + assert_eq!( + msg.vpl, 21593, + "incorrect value for vpl, expected 21593, is {}", msg.vpl ); + assert_eq!( + msg.vvpl, 41277, + "incorrect value for vvpl, expected 41277, is {}", + msg.vvpl + ); + assert_eq!( + msg.wn, 13102, + "incorrect value for wn, expected 13102, is {}", + msg.wn + ); } - _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + _ => panic!("Invalid message type! Expected a MsgProtectionLevel"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); @@ -100,7 +173,7 @@ fn test_auto_check_sbp_navigation_msg_protection_level() { #[cfg(feature = "json")] fn test_json2sbp_auto_check_sbp_navigation_msg_protection_level() { { - let json_input = r#"{"tow":501867400,"vpl":0,"hpl":0,"lat":0.0,"lon":0.0,"height":0.0,"flags":0,"preamble":85,"msg_type":534,"sender":4096,"payload":"iOPpHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","crc":50002,"length":33}"#.as_bytes(); + let json_input = r#"{"preamble":85,"msg_type":535,"sender":813,"length":76,"payload":"blQE8i4zNaBZVKcpORXZ9D2hU2iMiVr2MzMzMzOqtECamZmZGVjDQDMzMzMzw3lA5/sm3dC3p1DfGmGkLS66POvjt6C7XXTgaSggIQ==","crc":48261,"tow":4060370030,"wn":13102,"hpl":41013,"vpl":21593,"atpl":10663,"ctpl":5433,"hvpl":62681,"vvpl":41277,"hopl":26707,"popl":35212,"ropl":63066,"lat":5290.2,"lon":9904.2,"height":412.2,"v_x":-584647705,"v_y":1353168848,"v_z":-1537140001,"roll":1018834477,"pitch":-1598561301,"heading":-529244741,"flags":555755625}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload @@ -121,55 +194,125 @@ fn test_json2sbp_auto_check_sbp_navigation_msg_protection_level() { from_fields }; match &sbp_msg { - sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + sbp::messages::Sbp::MsgProtectionLevel(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x216, - "Incorrect message type, expected 0x216, is {}", + msg_type, 0x217, + "Incorrect message type, expected 0x217, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0x1000, - "incorrect sender id, expected 0x1000, is {sender_id}" + sender_id, 0x032d, + "incorrect sender id, expected 0x032d, is {sender_id}" + ); + assert_eq!( + msg.atpl, 10663, + "incorrect value for atpl, expected 10663, is {}", + msg.atpl + ); + assert_eq!( + msg.ctpl, 5433, + "incorrect value for ctpl, expected 5433, is {}", + msg.ctpl ); assert_eq!( - msg.flags, 0, - "incorrect value for flags, expected 0, is {}", + msg.flags, 555755625, + "incorrect value for flags, expected 555755625, is {}", msg.flags ); + assert_eq!( + msg.heading, -529244741, + "incorrect value for heading, expected -529244741, is {}", + msg.heading + ); assert!( - msg.height.almost_eq(0.00000000000000000e+00), - "incorrect value for height, expected 0.00000000000000000e+00, is {:e}", + msg.height.almost_eq(4.12199999999999989e+02), + "incorrect value for height, expected 4.12199999999999989e+02, is {:e}", msg.height ); assert_eq!( - msg.hpl, 0, - "incorrect value for hpl, expected 0, is {}", + msg.hopl, 26707, + "incorrect value for hopl, expected 26707, is {}", + msg.hopl + ); + assert_eq!( + msg.hpl, 41013, + "incorrect value for hpl, expected 41013, is {}", msg.hpl ); + assert_eq!( + msg.hvpl, 62681, + "incorrect value for hvpl, expected 62681, is {}", + msg.hvpl + ); assert!( - msg.lat.almost_eq(0.00000000000000000e+00), - "incorrect value for lat, expected 0.00000000000000000e+00, is {:e}", + msg.lat.almost_eq(5.29019999999999982e+03), + "incorrect value for lat, expected 5.29019999999999982e+03, is {:e}", msg.lat ); assert!( - msg.lon.almost_eq(0.00000000000000000e+00), - "incorrect value for lon, expected 0.00000000000000000e+00, is {:e}", + msg.lon.almost_eq(9.90420000000000073e+03), + "incorrect value for lon, expected 9.90420000000000073e+03, is {:e}", msg.lon ); assert_eq!( - msg.tow, 501867400, - "incorrect value for tow, expected 501867400, is {}", + msg.pitch, -1598561301, + "incorrect value for pitch, expected -1598561301, is {}", + msg.pitch + ); + assert_eq!( + msg.popl, 35212, + "incorrect value for popl, expected 35212, is {}", + msg.popl + ); + assert_eq!( + msg.roll, 1018834477, + "incorrect value for roll, expected 1018834477, is {}", + msg.roll + ); + assert_eq!( + msg.ropl, 63066, + "incorrect value for ropl, expected 63066, is {}", + msg.ropl + ); + assert_eq!( + msg.tow, 4060370030, + "incorrect value for tow, expected 4060370030, is {}", msg.tow ); assert_eq!( - msg.vpl, 0, - "incorrect value for vpl, expected 0, is {}", + msg.v_x, -584647705, + "incorrect value for v_x, expected -584647705, is {}", + msg.v_x + ); + assert_eq!( + msg.v_y, 1353168848, + "incorrect value for v_y, expected 1353168848, is {}", + msg.v_y + ); + assert_eq!( + msg.v_z, -1537140001, + "incorrect value for v_z, expected -1537140001, is {}", + msg.v_z + ); + assert_eq!( + msg.vpl, 21593, + "incorrect value for vpl, expected 21593, is {}", msg.vpl ); + assert_eq!( + msg.vvpl, 41277, + "incorrect value for vvpl, expected 41277, is {}", + msg.vvpl + ); + assert_eq!( + msg.wn, 13102, + "incorrect value for wn, expected 13102, is {}", + msg.wn + ); } - _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + _ => panic!("Invalid message type! Expected a MsgProtectionLevel"), }; } } @@ -187,8 +330,11 @@ fn test_json2sbp_auto_check_sbp_navigation_msg_protection_level() { fn test_sbp2json_auto_check_sbp_navigation_msg_protection_level() { { let mut payload = Cursor::new(vec![ - 85, 22, 2, 0, 16, 33, 136, 227, 233, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 82, 195, + 85, 23, 2, 45, 3, 76, 110, 84, 4, 242, 46, 51, 53, 160, 89, 84, 167, 41, 57, 21, 217, + 244, 61, 161, 83, 104, 140, 137, 90, 246, 51, 51, 51, 51, 51, 170, 180, 64, 154, 153, + 153, 153, 25, 88, 195, 64, 51, 51, 51, 51, 51, 195, 121, 64, 231, 251, 38, 221, 208, + 183, 167, 80, 223, 26, 97, 164, 45, 46, 186, 60, 235, 227, 183, 160, 187, 93, 116, 224, + 105, 40, 32, 33, 133, 188, ]); // Construct sbp message @@ -206,7 +352,7 @@ fn test_sbp2json_auto_check_sbp_navigation_msg_protection_level() { .unwrap(); // Reconstruct Sbp message from json fields, roundtrip - let sbp_msg = sbp::messages::Sbp::MsgProtectionLevelDepA( + let sbp_msg = sbp::messages::Sbp::MsgProtectionLevel( serde_json::from_str( std::str::from_utf8(json_buffer.as_slice()) .unwrap() @@ -216,55 +362,125 @@ fn test_sbp2json_auto_check_sbp_navigation_msg_protection_level() { .unwrap(), ); match &sbp_msg { - sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + sbp::messages::Sbp::MsgProtectionLevel(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x216, - "Incorrect message type, expected 0x216, is {}", + msg_type, 0x217, + "Incorrect message type, expected 0x217, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0x1000, - "incorrect sender id, expected 0x1000, is {sender_id}" + sender_id, 0x032d, + "incorrect sender id, expected 0x032d, is {sender_id}" + ); + assert_eq!( + msg.atpl, 10663, + "incorrect value for atpl, expected 10663, is {}", + msg.atpl ); assert_eq!( - msg.flags, 0, - "incorrect value for flags, expected 0, is {}", + msg.ctpl, 5433, + "incorrect value for ctpl, expected 5433, is {}", + msg.ctpl + ); + assert_eq!( + msg.flags, 555755625, + "incorrect value for flags, expected 555755625, is {}", msg.flags ); + assert_eq!( + msg.heading, -529244741, + "incorrect value for heading, expected -529244741, is {}", + msg.heading + ); assert!( - msg.height.almost_eq(0.00000000000000000e+00), - "incorrect value for height, expected 0.00000000000000000e+00, is {:e}", + msg.height.almost_eq(4.12199999999999989e+02), + "incorrect value for height, expected 4.12199999999999989e+02, is {:e}", msg.height ); assert_eq!( - msg.hpl, 0, - "incorrect value for hpl, expected 0, is {}", + msg.hopl, 26707, + "incorrect value for hopl, expected 26707, is {}", + msg.hopl + ); + assert_eq!( + msg.hpl, 41013, + "incorrect value for hpl, expected 41013, is {}", msg.hpl ); + assert_eq!( + msg.hvpl, 62681, + "incorrect value for hvpl, expected 62681, is {}", + msg.hvpl + ); assert!( - msg.lat.almost_eq(0.00000000000000000e+00), - "incorrect value for lat, expected 0.00000000000000000e+00, is {:e}", + msg.lat.almost_eq(5.29019999999999982e+03), + "incorrect value for lat, expected 5.29019999999999982e+03, is {:e}", msg.lat ); assert!( - msg.lon.almost_eq(0.00000000000000000e+00), - "incorrect value for lon, expected 0.00000000000000000e+00, is {:e}", + msg.lon.almost_eq(9.90420000000000073e+03), + "incorrect value for lon, expected 9.90420000000000073e+03, is {:e}", msg.lon ); assert_eq!( - msg.tow, 501867400, - "incorrect value for tow, expected 501867400, is {}", + msg.pitch, -1598561301, + "incorrect value for pitch, expected -1598561301, is {}", + msg.pitch + ); + assert_eq!( + msg.popl, 35212, + "incorrect value for popl, expected 35212, is {}", + msg.popl + ); + assert_eq!( + msg.roll, 1018834477, + "incorrect value for roll, expected 1018834477, is {}", + msg.roll + ); + assert_eq!( + msg.ropl, 63066, + "incorrect value for ropl, expected 63066, is {}", + msg.ropl + ); + assert_eq!( + msg.tow, 4060370030, + "incorrect value for tow, expected 4060370030, is {}", msg.tow ); assert_eq!( - msg.vpl, 0, - "incorrect value for vpl, expected 0, is {}", + msg.v_x, -584647705, + "incorrect value for v_x, expected -584647705, is {}", + msg.v_x + ); + assert_eq!( + msg.v_y, 1353168848, + "incorrect value for v_y, expected 1353168848, is {}", + msg.v_y + ); + assert_eq!( + msg.v_z, -1537140001, + "incorrect value for v_z, expected -1537140001, is {}", + msg.v_z + ); + assert_eq!( + msg.vpl, 21593, + "incorrect value for vpl, expected 21593, is {}", msg.vpl ); + assert_eq!( + msg.vvpl, 41277, + "incorrect value for vvpl, expected 41277, is {}", + msg.vvpl + ); + assert_eq!( + msg.wn, 13102, + "incorrect value for wn, expected 13102, is {}", + msg.wn + ); } - _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + _ => panic!("Invalid message type! Expected a MsgProtectionLevel"), }; // Check payload is still identical diff --git a/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level_dep_a.rs new file mode 100644 index 0000000000..e9e249d7f2 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_navigation_msg_protection_level_dep_a.rs @@ -0,0 +1,276 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_navigation_msg_protection_level_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, 51, 51, 51, 51, 51, 244, 190, + 64, 102, 102, 102, 102, 102, 204, 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, + 81, 104, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x216, + "Incorrect message type, expected 0x216, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1694, + "incorrect sender id, expected 0x1694, is {sender_id}" + ); + assert_eq!( + msg.flags, 248, + "incorrect value for flags, expected 248, is {}", + msg.flags + ); + assert!( + msg.height.almost_eq(8.27020000000000073e+03), + "incorrect value for height, expected 8.27020000000000073e+03, is {:e}", + msg.height + ); + assert_eq!( + msg.hpl, 35588, + "incorrect value for hpl, expected 35588, is {}", + msg.hpl + ); + assert!( + msg.lat.almost_eq(7.92419999999999982e+03), + "incorrect value for lat, expected 7.92419999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(3.17419999999999982e+03), + "incorrect value for lon, expected 3.17419999999999982e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.tow, 3108339252, + "incorrect value for tow, expected 3108339252, is {}", + msg.tow + ); + assert_eq!( + msg.vpl, 21807, + "incorrect value for vpl, expected 21807, is {}", + msg.vpl + ); + } + _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_navigation_msg_protection_level_dep_a() { + { + let json_input = r#"{"crc":26705,"length":33,"msg_type":534,"payload":"NH5FuS9VBIszMzMzM/S+QGZmZmZmzKhAmpmZmRknwED4","preamble":85,"sender":5780,"tow":3108339252,"vpl":21807,"hpl":35588,"lat":7924.2,"lon":3174.2,"height":8270.2,"flags":248}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x216, + "Incorrect message type, expected 0x216, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1694, + "incorrect sender id, expected 0x1694, is {sender_id}" + ); + assert_eq!( + msg.flags, 248, + "incorrect value for flags, expected 248, is {}", + msg.flags + ); + assert!( + msg.height.almost_eq(8.27020000000000073e+03), + "incorrect value for height, expected 8.27020000000000073e+03, is {:e}", + msg.height + ); + assert_eq!( + msg.hpl, 35588, + "incorrect value for hpl, expected 35588, is {}", + msg.hpl + ); + assert!( + msg.lat.almost_eq(7.92419999999999982e+03), + "incorrect value for lat, expected 7.92419999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(3.17419999999999982e+03), + "incorrect value for lon, expected 3.17419999999999982e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.tow, 3108339252, + "incorrect value for tow, expected 3108339252, is {}", + msg.tow + ); + assert_eq!( + msg.vpl, 21807, + "incorrect value for vpl, expected 21807, is {}", + msg.vpl + ); + } + _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_navigation_msg_protection_level_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_navigation_msg_protection_level_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 22, 2, 148, 22, 33, 52, 126, 69, 185, 47, 85, 4, 139, 51, 51, 51, 51, 51, 244, 190, + 64, 102, 102, 102, 102, 102, 204, 168, 64, 154, 153, 153, 153, 25, 39, 192, 64, 248, + 81, 104, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgProtectionLevelDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgProtectionLevelDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x216, + "Incorrect message type, expected 0x216, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1694, + "incorrect sender id, expected 0x1694, is {sender_id}" + ); + assert_eq!( + msg.flags, 248, + "incorrect value for flags, expected 248, is {}", + msg.flags + ); + assert!( + msg.height.almost_eq(8.27020000000000073e+03), + "incorrect value for height, expected 8.27020000000000073e+03, is {:e}", + msg.height + ); + assert_eq!( + msg.hpl, 35588, + "incorrect value for hpl, expected 35588, is {}", + msg.hpl + ); + assert!( + msg.lat.almost_eq(7.92419999999999982e+03), + "incorrect value for lat, expected 7.92419999999999982e+03, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(3.17419999999999982e+03), + "incorrect value for lon, expected 3.17419999999999982e+03, is {:e}", + msg.lon + ); + assert_eq!( + msg.tow, 3108339252, + "incorrect value for tow, expected 3108339252, is {}", + msg.tow + ); + assert_eq!( + msg.vpl, 21807, + "incorrect value for vpl, expected 21807, is {}", + msg.vpl + ); + } + _ => panic!("Invalid message type! Expected a MsgProtectionLevelDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_navigation_navigation_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_navigation_navigation_structs.rs new file mode 100644 index 0000000000..b0448021e4 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_navigation_navigation_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/navigation/test_navigation_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_navigation_navigation_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_navigation_navigation_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_navigation_navigation_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_navigation_navigation_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ndb_msg_ndb_event.rs b/rust/sbp/tests/integration/auto_check_sbp_ndb_msg_ndb_event.rs new file mode 100644 index 0000000000..f7002ca5c1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ndb_msg_ndb_event.rs @@ -0,0 +1,319 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ndb_msg_ndb_event() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, 0, 249, 73, 205, 115, 238, 74, 98, + 66, 182, 148, 16, 166, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNdbEvent(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x400, + "Incorrect message type, expected 0x400, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaea4, + "incorrect sender id, expected 0xaea4, is {sender_id}" + ); + assert_eq!( + msg.data_source, 115, + "incorrect value for data_source, expected 115, is {}", + msg.data_source + ); + assert_eq!( + msg.event, 249, + "incorrect value for event, expected 249, is {}", + msg.event + ); + assert_eq!( + msg.object_sid.code, 74, + "incorrect value for object_sid.code, expected 74, is {}", + msg.object_sid.code + ); + assert_eq!( + msg.object_sid.sat, 238, + "incorrect value for object_sid.sat, expected 238, is {}", + msg.object_sid.sat + ); + assert_eq!( + msg.object_type, 73, + "incorrect value for object_type, expected 73, is {}", + msg.object_type + ); + assert_eq!( + msg.original_sender, 38070, + "incorrect value for original_sender, expected 38070, is {}", + msg.original_sender + ); + assert_eq!( + msg.recv_time, 299461164286, + "incorrect value for recv_time, expected 299461164286, is {}", + msg.recv_time + ); + assert_eq!( + msg.result, 205, + "incorrect value for result, expected 205, is {}", + msg.result + ); + assert_eq!( + msg.src_sid.code, 66, + "incorrect value for src_sid.code, expected 66, is {}", + msg.src_sid.code + ); + assert_eq!( + msg.src_sid.sat, 98, + "incorrect value for src_sid.sat, expected 98, is {}", + msg.src_sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgNdbEvent"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ndb_msg_ndb_event() { + { + let json_input = r#"{"preamble":85,"msg_type":1024,"sender":44708,"length":18,"payload":"/rxGuUUAAAD5Sc1z7kpiQraU","crc":42512,"recv_time":299461164286,"event":249,"object_type":73,"result":205,"data_source":115,"object_sid":{"sat":238,"code":74},"src_sid":{"sat":98,"code":66},"original_sender":38070}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNdbEvent(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x400, + "Incorrect message type, expected 0x400, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaea4, + "incorrect sender id, expected 0xaea4, is {sender_id}" + ); + assert_eq!( + msg.data_source, 115, + "incorrect value for data_source, expected 115, is {}", + msg.data_source + ); + assert_eq!( + msg.event, 249, + "incorrect value for event, expected 249, is {}", + msg.event + ); + assert_eq!( + msg.object_sid.code, 74, + "incorrect value for object_sid.code, expected 74, is {}", + msg.object_sid.code + ); + assert_eq!( + msg.object_sid.sat, 238, + "incorrect value for object_sid.sat, expected 238, is {}", + msg.object_sid.sat + ); + assert_eq!( + msg.object_type, 73, + "incorrect value for object_type, expected 73, is {}", + msg.object_type + ); + assert_eq!( + msg.original_sender, 38070, + "incorrect value for original_sender, expected 38070, is {}", + msg.original_sender + ); + assert_eq!( + msg.recv_time, 299461164286, + "incorrect value for recv_time, expected 299461164286, is {}", + msg.recv_time + ); + assert_eq!( + msg.result, 205, + "incorrect value for result, expected 205, is {}", + msg.result + ); + assert_eq!( + msg.src_sid.code, 66, + "incorrect value for src_sid.code, expected 66, is {}", + msg.src_sid.code + ); + assert_eq!( + msg.src_sid.sat, 98, + "incorrect value for src_sid.sat, expected 98, is {}", + msg.src_sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgNdbEvent"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ndb_msg_ndb_event`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ndb_msg_ndb_event() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 4, 164, 174, 18, 254, 188, 70, 185, 69, 0, 0, 0, 249, 73, 205, 115, 238, 74, 98, + 66, 182, 148, 16, 166, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgNdbEvent( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgNdbEvent(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x400, + "Incorrect message type, expected 0x400, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaea4, + "incorrect sender id, expected 0xaea4, is {sender_id}" + ); + assert_eq!( + msg.data_source, 115, + "incorrect value for data_source, expected 115, is {}", + msg.data_source + ); + assert_eq!( + msg.event, 249, + "incorrect value for event, expected 249, is {}", + msg.event + ); + assert_eq!( + msg.object_sid.code, 74, + "incorrect value for object_sid.code, expected 74, is {}", + msg.object_sid.code + ); + assert_eq!( + msg.object_sid.sat, 238, + "incorrect value for object_sid.sat, expected 238, is {}", + msg.object_sid.sat + ); + assert_eq!( + msg.object_type, 73, + "incorrect value for object_type, expected 73, is {}", + msg.object_type + ); + assert_eq!( + msg.original_sender, 38070, + "incorrect value for original_sender, expected 38070, is {}", + msg.original_sender + ); + assert_eq!( + msg.recv_time, 299461164286, + "incorrect value for recv_time, expected 299461164286, is {}", + msg.recv_time + ); + assert_eq!( + msg.result, 205, + "incorrect value for result, expected 205, is {}", + msg.result + ); + assert_eq!( + msg.src_sid.code, 66, + "incorrect value for src_sid.code, expected 66, is {}", + msg.src_sid.code + ); + assert_eq!( + msg.src_sid.sat, 98, + "incorrect value for src_sid.sat, expected 98, is {}", + msg.src_sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgNdbEvent"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo.rs new file mode 100644 index 0000000000..e8096ac1ce --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo.rs @@ -0,0 +1,400 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_almanac_glo() { + { + let mut payload = Cursor::new(vec![ + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, + 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, + 228, 237, 63, 155, 87, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGlo(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x73, + "Incorrect message type, expected 0x73, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGlo"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_almanac_glo() { + { + let json_input = r#"{"preamble":85,"msg_type":115,"sender":1219,"length":78,"payload":"FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/","crc":22427,"common":{"sid":{"sat":22,"code":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"lambda_na":-0.02200078842114688,"t_lambda_na":0.007072207052260637,"i":5153.550029754639,"t":-1.8731818448797617,"t_dot":-8.903585155774196e-09,"epsilon":-0.9893036629599647,"omega":0.9341514480259797}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGlo(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x73, + "Incorrect message type, expected 0x73, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGlo"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_almanac_glo`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_almanac_glo() { + { + let mut payload = Cursor::new(vec![ + 85, 115, 0, 195, 4, 78, 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, + 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, + 228, 237, 63, 155, 87, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAlmanacGlo( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGlo(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x73, + "Incorrect message type, expected 0x73, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGlo"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo_dep.rs new file mode 100644 index 0000000000..786dd19704 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_glo_dep.rs @@ -0,0 +1,415 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_almanac_glo_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, + 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, + 147, 145, 228, 237, 63, 203, 178, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGloDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x71, + "Incorrect message type, expected 0x71, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGloDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_almanac_glo_dep() { + { + let json_input = r#"{"preamble":85,"msg_type":113,"sender":1219,"length":80,"payload":"FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8=","crc":45771,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"lambda_na":-0.02200078842114688,"t_lambda_na":0.007072207052260637,"i":5153.550029754639,"t":-1.8731818448797617,"t_dot":-8.903585155774196e-09,"epsilon":-0.9893036629599647,"omega":0.9341514480259797}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGloDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x71, + "Incorrect message type, expected 0x71, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGloDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_almanac_glo_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_almanac_glo_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 113, 0, 195, 4, 80, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, + 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, + 147, 145, 228, 237, 63, 203, 178, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAlmanacGloDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGloDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x71, + "Incorrect message type, expected 0x71, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.epsilon.almost_eq(-9.89303662959964747e-01), + "incorrect value for epsilon, expected -9.89303662959964747e-01, is {:e}", + msg.epsilon + ); + assert!( + msg.i.almost_eq(5.15355002975463867e+03), + "incorrect value for i, expected 5.15355002975463867e+03, is {:e}", + msg.i + ); + assert!( + msg.lambda_na.almost_eq(-2.20007884211468815e-02), + "incorrect value for lambda_na, expected -2.20007884211468815e-02, is {:e}", + msg.lambda_na + ); + assert!( + msg.omega.almost_eq(9.34151448025979714e-01), + "incorrect value for omega, expected 9.34151448025979714e-01, is {:e}", + msg.omega + ); + assert!( + msg.t.almost_eq(-1.87318184487976169e+00), + "incorrect value for t, expected -1.87318184487976169e+00, is {:e}", + msg.t + ); + assert!( + msg.t_dot.almost_eq(-8.90358515577419627e-09), + "incorrect value for t_dot, expected -8.90358515577419627e-09, is {:e}", + msg.t_dot + ); + assert!( + msg.t_lambda_na.almost_eq(7.07220705226063728e-03), + "incorrect value for t_lambda_na, expected 7.07220705226063728e-03, is {:e}", + msg.t_lambda_na + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGloDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps.rs new file mode 100644 index 0000000000..9704e9718d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps.rs @@ -0,0 +1,430 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_almanac_gps() { + { + let mut payload = Cursor::new(vec![ + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, + 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, + 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGps(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x72, + "Incorrect message type, expected 0x72, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPS"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_almanac_gps() { + { + let json_input = r#"{"preamble":85,"msg_type":114,"sender":1219,"length":94,"payload":"FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/AAAAAGyxRL8AAAAAAMCjPQ==","crc":11710,"common":{"sid":{"sat":22,"code":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGps(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x72, + "Incorrect message type, expected 0x72, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPS"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_almanac_gps`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_almanac_gps() { + { + let mut payload = Cursor::new(vec![ + 85, 114, 0, 195, 4, 94, 22, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, 153, 1, + 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, + 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, + 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, + 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 190, 45, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAlmanacGps( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGps(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x72, + "Incorrect message type, expected 0x72, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPS"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps_dep.rs new file mode 100644 index 0000000000..d6fbef071d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_almanac_gps_dep.rs @@ -0,0 +1,447 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_almanac_gps_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, + 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, + 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 144, 232, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x70, + "Incorrect message type, expected 0x70, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPSDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_almanac_gps_dep() { + { + let json_input = r#"{"preamble":85,"msg_type":112,"sender":1219,"length":96,"payload":"FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8AAAAAbLFEvwAAAAAAwKM9","crc":59536,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x70, + "Incorrect message type, expected 0x70, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPSDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_almanac_gps_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_almanac_gps_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 112, 0, 195, 4, 96, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 154, 153, 153, 153, 153, + 153, 1, 64, 64, 56, 0, 0, 1, 0, 142, 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, + 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, + 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, + 147, 145, 228, 237, 63, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 144, 232, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAlmanacGpsDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanacGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x70, + "Incorrect message type, expected 0x70, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toa.tow, 446384, + "incorrect value for common.toa.tow, expected 446384, is {}", + msg.common.toa.tow + ); + assert_eq!( + msg.common.toa.wn, 2154, + "incorrect value for common.toa.wn, expected 2154, is {}", + msg.common.toa.wn + ); + assert!( + msg.common.ura.almost_eq(2.20000000000000018e+00), + "incorrect value for common.ura, expected 2.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanacGPSDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_base_pos_llh.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_base_pos_llh.rs new file mode 100644 index 0000000000..61b9eb8b40 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_base_pos_llh.rs @@ -0,0 +1,214 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_base_pos_llh() { + { + let mut payload = Cursor::new(vec![ + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, 70, 235, 0, 120, + 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBasePosLlh(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x44, + "Incorrect message type, expected 0x44, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.height.almost_eq(3.79395123108792163e+01), + "incorrect value for height, expected 3.79395123108792163e+01, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(3.72512925783773952e+01), + "incorrect value for lat, expected 3.72512925783773952e+01, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(-1.21875056094079739e+02), + "incorrect value for lon, expected -1.21875056094079739e+02, is {:e}", + msg.lon + ); + } + _ => panic!("Invalid message type! Expected a MsgBasePosLLH"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_base_pos_llh() { + { + let json_input = r#"{"crc":58962,"length":24,"msg_type":68,"payload":"4e3uWiqgQkA7j0brAHhewDO1fPBB+EJA","preamble":85,"sender":123,"lat":37.251292578377395,"lon":-121.87505609407974,"height":37.939512310879216}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBasePosLlh(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x44, + "Incorrect message type, expected 0x44, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.height.almost_eq(3.79395123108792163e+01), + "incorrect value for height, expected 3.79395123108792163e+01, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(3.72512925783773952e+01), + "incorrect value for lat, expected 3.72512925783773952e+01, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(-1.21875056094079739e+02), + "incorrect value for lon, expected -1.21875056094079739e+02, is {:e}", + msg.lon + ); + } + _ => panic!("Invalid message type! Expected a MsgBasePosLLH"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_base_pos_llh`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_base_pos_llh() { + { + let mut payload = Cursor::new(vec![ + 85, 68, 0, 123, 0, 24, 225, 237, 238, 90, 42, 160, 66, 64, 59, 143, 70, 235, 0, 120, + 94, 192, 51, 181, 124, 240, 65, 248, 66, 64, 82, 230, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgBasePosLlh( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgBasePosLlh(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x44, + "Incorrect message type, expected 0x44, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.height.almost_eq(3.79395123108792163e+01), + "incorrect value for height, expected 3.79395123108792163e+01, is {:e}", + msg.height + ); + assert!( + msg.lat.almost_eq(3.72512925783773952e+01), + "incorrect value for lat, expected 3.72512925783773952e+01, is {:e}", + msg.lat + ); + assert!( + msg.lon.almost_eq(-1.21875056094079739e+02), + "incorrect value for lon, expected -1.21875056094079739e+02, is {:e}", + msg.lon + ); + } + _ => panic!("Invalid message type! Expected a MsgBasePosLLH"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_a.rs new file mode 100644 index 0000000000..011ad5d0d6 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_a.rs @@ -0,0 +1,573 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, + 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, + 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 242, 84, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1a, + "Incorrect message type, expected 0x1a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_dep_a() { + { + let json_input = r#"{"preamble":85,"msg_type":26,"sender":1219,"length":175,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFg==","crc":21746,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"prn":22}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1a, + "Incorrect message type, expected 0x1a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 26, 0, 195, 4, 175, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, + 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, + 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 242, 84, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1a, + "Incorrect message type, expected 0x1a, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_c.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_c.rs new file mode 100644 index 0000000000..03d9abfe2b --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_c.rs @@ -0,0 +1,650 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_dep_c() { + { + let mut payload = Cursor::new(vec![ + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, + 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, + 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, + 23, 170, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x47, + "Incorrect message type, expected 0x47, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepC"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_dep_c() { + { + let json_input = r#"{"preamble":85,"msg_type":71,"sender":1219,"length":185,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA=","crc":43543,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"sid":{"sat":22,"code":0,"reserved":0},"iode":45,"iodc":45,"reserved":0}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x47, + "Incorrect message type, expected 0x47, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepC"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_dep_c`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_dep_c() { + { + let mut payload = Cursor::new(vec![ + 85, 71, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, + 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, + 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, + 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, + 23, 170, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisDepC( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x47, + "Incorrect message type, expected 0x47, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepC"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_d.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_d.rs new file mode 100644 index 0000000000..6e61f4d008 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_dep_d.rs @@ -0,0 +1,650 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_dep_d() { + { + let mut payload = Cursor::new(vec![ + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, + 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, + 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, + 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, + 95, 7, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x80, + "Incorrect message type, expected 0x80, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepD"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_dep_d() { + { + let json_input = r#"{"preamble":85,"msg_type":128,"sender":1219,"length":185,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA=","crc":1887,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"sid":{"sat":22,"code":0,"reserved":0},"iode":45,"iodc":45,"reserved":0}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x80, + "Incorrect message type, expected 0x80, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepD"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_dep_d`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_dep_d() { + { + let mut payload = Cursor::new(vec![ + 85, 128, 0, 195, 4, 185, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, + 0, 0, 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, + 0, 0, 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, + 41, 5, 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, + 180, 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, + 216, 59, 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, + 224, 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, + 154, 153, 153, 153, 153, 153, 201, 63, 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, + 205, 204, 204, 204, 192, 62, 27, 65, 106, 8, 1, 0, 22, 0, 0, 0, 45, 45, 0, 0, 0, 0, 0, + 95, 7, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisDepD( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x80, + "Incorrect message type, expected 0x80, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000000000000011e-01), + "incorrect value for af2, expected 2.00000000000000011e-01, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert_eq!( + msg.healthy, 0, + "incorrect value for healthy, expected 0, is {}", + msg.healthy + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert_eq!( + msg.reserved, 0, + "incorrect value for reserved, expected 0, is {}", + msg.reserved + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert!( + msg.toc_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toc_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toc_tow + ); + assert_eq!( + msg.toc_wn, 2154, + "incorrect value for toc_wn, expected 2154, is {}", + msg.toc_wn + ); + assert!( + msg.toe_tow.almost_eq(4.46384200000000012e+05), + "incorrect value for toe_tow, expected 4.46384200000000012e+05, is {:e}", + msg.toe_tow + ); + assert_eq!( + msg.toe_wn, 2154, + "incorrect value for toe_wn, expected 2154, is {}", + msg.toe_wn + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisDepD"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gal_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gal_dep_a.rs new file mode 100644 index 0000000000..b7f9b1b9e4 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gal_dep_a.rs @@ -0,0 +1,663 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_gal_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, 102, 102, 230, 64, 64, 56, 0, + 0, 1, 0, 154, 153, 153, 63, 205, 204, 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, + 166, 64, 102, 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, 217, 204, 130, 105, + 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, 0, 151, 92, 38, 63, 0, + 0, 0, 55, 154, 64, 181, 64, 56, 38, 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, + 186, 56, 190, 80, 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, 239, 63, + 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, 67, 235, 241, 190, 255, 255, + 255, 255, 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, 6, 0, 106, 8, 108, 0, 108, 0, + 168, 49, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGalDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x95, + "Incorrect message type, expected 0x95, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-1.70888961292803254e-05), + "incorrect value for af0, expected -1.70888961292803254e-05, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(-8.18545231595635253e-12), + "incorrect value for af1, expected -8.18545231595635253e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000002980232239e-01), + "incorrect value for af2, expected 2.00000002980232239e-01, is {:e}", + msg.af2 + ); + assert!( + msg.bgd_e1e5a.almost_eq(1.20000004768371582e+00), + "incorrect value for bgd_e1e5a, expected 1.20000004768371582e+00, is {:e}", + msg.bgd_e1e5a + ); + assert!( + msg.bgd_e1e5b.almost_eq(2.20000004768371582e+00), + "incorrect value for bgd_e1e5b, expected 2.20000004768371582e+00, is {:e}", + msg.bgd_e1e5b + ); + assert!( + msg.c_ic.almost_eq(3.20000004768371582e+00), + "incorrect value for c_ic, expected 3.20000004768371582e+00, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(4.19999980926513672e+00), + "incorrect value for c_is, expected 4.19999980926513672e+00, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(2.65437500000000000e+02), + "incorrect value for c_rc, expected 2.65437500000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(1.01250000000000000e+01), + "incorrect value for c_rs, expected 1.01250000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(5.19999980926513672e+00), + "incorrect value for c_uc, expected 5.19999980926513672e+00, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(6.19999980926513672e+00), + "incorrect value for c_us, expected 6.19999980926513672e+00, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 14, + "incorrect value for common.sid.code, expected 14, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 27, + "incorrect value for common.sid.sat, expected 27, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 448800, + "incorrect value for common.toe.tow, expected 448800, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(7.19999980926513672e+00), + "incorrect value for common.ura, expected 7.19999980926513672e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(3.22620581299322575e-09), + "incorrect value for dn, expected 3.22620581299322575e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(1.70606072060763836e-04), + "incorrect value for ecc, expected 1.70606072060763836e-04, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.77745609497785773e-01), + "incorrect value for inc, expected 9.77745609497785773e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-3.17870383434514646e-10), + "incorrect value for inc_dot, expected -3.17870383434514646e-10, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 108, + "incorrect value for iodc, expected 108, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 108, + "incorrect value for iode, expected 108, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-1.84571157441558675e+00), + "incorrect value for m0, expected -1.84571157441558675e+00, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(1.16967730598334008e+00), + "incorrect value for omega0, expected 1.16967730598334008e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-5.75738267524087236e-09), + "incorrect value for omegadot, expected -5.75738267524087236e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.44060240173339844e+03), + "incorrect value for sqrta, expected 5.44060240173339844e+03, is {:e}", + msg.sqrta + ); + assert_eq!( + msg.toc.tow, 448800, + "incorrect value for toc.tow, expected 448800, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(1.22509120916626246e-01), + "incorrect value for w, expected 1.22509120916626246e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGalDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_gal_dep_a() { + { + let json_input = r#"{"preamble":85,"msg_type":149,"sender":1219,"length":152,"payload":"Gw4g2QYAaghmZuZAQDgAAAEAmpmZP83MDEAAACJBALiEQ2ZmpkBmZsZAzcxMQGZmhkDZzIJpgLYrPvhqH9wIiP2/AAAAAJdcJj8AAAA3mkC1QDgmAY3/tvI/3pOIJ0+6OL5Qcsz7wVy/P+03EymxSe8/MUG98AjY9b3/////Q+vxvv///////6G9zcxMPiDZBgBqCGwAbAA=","crc":12712,"common":{"sid":{"sat":27,"code":14},"toe":{"tow":448800,"wn":2154},"ura":7.199999809265137,"fit_interval":14400,"valid":1,"health_bits":0},"bgd_e1e5a":1.2000000476837158,"bgd_e1e5b":2.200000047683716,"c_rs":10.125,"c_rc":265.4375,"c_uc":5.199999809265137,"c_us":6.199999809265137,"c_ic":3.200000047683716,"c_is":4.199999809265137,"dn":3.2262058129932258e-09,"m0":-1.8457115744155868,"ecc":0.00017060607206076384,"sqrta":5440.602401733398,"omega0":1.16967730598334,"omegadot":-5.757382675240872e-09,"w":0.12250912091662625,"inc":0.9777456094977858,"inc_dot":-3.1787038343451465e-10,"af0":-1.7088896129280325e-05,"af1":-8.185452315956353e-12,"af2":0.20000000298023224,"toc":{"tow":448800,"wn":2154},"iode":108,"iodc":108}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGalDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x95, + "Incorrect message type, expected 0x95, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-1.70888961292803254e-05), + "incorrect value for af0, expected -1.70888961292803254e-05, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(-8.18545231595635253e-12), + "incorrect value for af1, expected -8.18545231595635253e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000002980232239e-01), + "incorrect value for af2, expected 2.00000002980232239e-01, is {:e}", + msg.af2 + ); + assert!( + msg.bgd_e1e5a.almost_eq(1.20000004768371582e+00), + "incorrect value for bgd_e1e5a, expected 1.20000004768371582e+00, is {:e}", + msg.bgd_e1e5a + ); + assert!( + msg.bgd_e1e5b.almost_eq(2.20000004768371582e+00), + "incorrect value for bgd_e1e5b, expected 2.20000004768371582e+00, is {:e}", + msg.bgd_e1e5b + ); + assert!( + msg.c_ic.almost_eq(3.20000004768371582e+00), + "incorrect value for c_ic, expected 3.20000004768371582e+00, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(4.19999980926513672e+00), + "incorrect value for c_is, expected 4.19999980926513672e+00, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(2.65437500000000000e+02), + "incorrect value for c_rc, expected 2.65437500000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(1.01250000000000000e+01), + "incorrect value for c_rs, expected 1.01250000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(5.19999980926513672e+00), + "incorrect value for c_uc, expected 5.19999980926513672e+00, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(6.19999980926513672e+00), + "incorrect value for c_us, expected 6.19999980926513672e+00, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 14, + "incorrect value for common.sid.code, expected 14, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 27, + "incorrect value for common.sid.sat, expected 27, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 448800, + "incorrect value for common.toe.tow, expected 448800, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(7.19999980926513672e+00), + "incorrect value for common.ura, expected 7.19999980926513672e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(3.22620581299322575e-09), + "incorrect value for dn, expected 3.22620581299322575e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(1.70606072060763836e-04), + "incorrect value for ecc, expected 1.70606072060763836e-04, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.77745609497785773e-01), + "incorrect value for inc, expected 9.77745609497785773e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-3.17870383434514646e-10), + "incorrect value for inc_dot, expected -3.17870383434514646e-10, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 108, + "incorrect value for iodc, expected 108, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 108, + "incorrect value for iode, expected 108, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-1.84571157441558675e+00), + "incorrect value for m0, expected -1.84571157441558675e+00, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(1.16967730598334008e+00), + "incorrect value for omega0, expected 1.16967730598334008e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-5.75738267524087236e-09), + "incorrect value for omegadot, expected -5.75738267524087236e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.44060240173339844e+03), + "incorrect value for sqrta, expected 5.44060240173339844e+03, is {:e}", + msg.sqrta + ); + assert_eq!( + msg.toc.tow, 448800, + "incorrect value for toc.tow, expected 448800, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(1.22509120916626246e-01), + "incorrect value for w, expected 1.22509120916626246e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGalDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_gal_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_gal_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 149, 0, 195, 4, 152, 27, 14, 32, 217, 6, 0, 106, 8, 102, 102, 230, 64, 64, 56, 0, + 0, 1, 0, 154, 153, 153, 63, 205, 204, 12, 64, 0, 0, 34, 65, 0, 184, 132, 67, 102, 102, + 166, 64, 102, 102, 198, 64, 205, 204, 76, 64, 102, 102, 134, 64, 217, 204, 130, 105, + 128, 182, 43, 62, 248, 106, 31, 220, 8, 136, 253, 191, 0, 0, 0, 0, 151, 92, 38, 63, 0, + 0, 0, 55, 154, 64, 181, 64, 56, 38, 1, 141, 255, 182, 242, 63, 222, 147, 136, 39, 79, + 186, 56, 190, 80, 114, 204, 251, 193, 92, 191, 63, 237, 55, 19, 41, 177, 73, 239, 63, + 49, 65, 189, 240, 8, 216, 245, 189, 255, 255, 255, 255, 67, 235, 241, 190, 255, 255, + 255, 255, 255, 255, 161, 189, 205, 204, 76, 62, 32, 217, 6, 0, 106, 8, 108, 0, 108, 0, + 168, 49, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGalDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGalDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x95, + "Incorrect message type, expected 0x95, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-1.70888961292803254e-05), + "incorrect value for af0, expected -1.70888961292803254e-05, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(-8.18545231595635253e-12), + "incorrect value for af1, expected -8.18545231595635253e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(2.00000002980232239e-01), + "incorrect value for af2, expected 2.00000002980232239e-01, is {:e}", + msg.af2 + ); + assert!( + msg.bgd_e1e5a.almost_eq(1.20000004768371582e+00), + "incorrect value for bgd_e1e5a, expected 1.20000004768371582e+00, is {:e}", + msg.bgd_e1e5a + ); + assert!( + msg.bgd_e1e5b.almost_eq(2.20000004768371582e+00), + "incorrect value for bgd_e1e5b, expected 2.20000004768371582e+00, is {:e}", + msg.bgd_e1e5b + ); + assert!( + msg.c_ic.almost_eq(3.20000004768371582e+00), + "incorrect value for c_ic, expected 3.20000004768371582e+00, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(4.19999980926513672e+00), + "incorrect value for c_is, expected 4.19999980926513672e+00, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(2.65437500000000000e+02), + "incorrect value for c_rc, expected 2.65437500000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(1.01250000000000000e+01), + "incorrect value for c_rs, expected 1.01250000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(5.19999980926513672e+00), + "incorrect value for c_uc, expected 5.19999980926513672e+00, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(6.19999980926513672e+00), + "incorrect value for c_us, expected 6.19999980926513672e+00, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 14, + "incorrect value for common.sid.code, expected 14, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 27, + "incorrect value for common.sid.sat, expected 27, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 448800, + "incorrect value for common.toe.tow, expected 448800, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(7.19999980926513672e+00), + "incorrect value for common.ura, expected 7.19999980926513672e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(3.22620581299322575e-09), + "incorrect value for dn, expected 3.22620581299322575e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(1.70606072060763836e-04), + "incorrect value for ecc, expected 1.70606072060763836e-04, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.77745609497785773e-01), + "incorrect value for inc, expected 9.77745609497785773e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-3.17870383434514646e-10), + "incorrect value for inc_dot, expected -3.17870383434514646e-10, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 108, + "incorrect value for iodc, expected 108, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 108, + "incorrect value for iode, expected 108, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-1.84571157441558675e+00), + "incorrect value for m0, expected -1.84571157441558675e+00, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(1.16967730598334008e+00), + "incorrect value for omega0, expected 1.16967730598334008e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-5.75738267524087236e-09), + "incorrect value for omegadot, expected -5.75738267524087236e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.44060240173339844e+03), + "incorrect value for sqrta, expected 5.44060240173339844e+03, is {:e}", + msg.sqrta + ); + assert_eq!( + msg.toc.tow, 448800, + "incorrect value for toc.tow, expected 448800, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(1.22509120916626246e-01), + "incorrect value for w, expected 1.22509120916626246e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGalDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_a.rs new file mode 100644 index 0000000000..c64c763445 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_a.rs @@ -0,0 +1,477 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_glo_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, + 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, + 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, + 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 112, 199, 62, 202, 238, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x83, + "Incorrect message type, expected 0x83, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_glo_dep_a() { + { + let json_input = r#"{"preamble":85,"msg_type":131,"sender":1219,"length":112,"payload":"BAADAEbFBgBqCM3MzMzMzBRAYAkAAAEAAAAAAAAAcD0AAAAAMOwVvwAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg==","crc":61130,"common":{"sid":{"sat":4,"code":3,"reserved":0},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x83, + "Incorrect message type, expected 0x83, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_glo_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_glo_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 131, 0, 195, 4, 112, 4, 0, 3, 0, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, + 204, 20, 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, + 191, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, + 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, + 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, + 0, 0, 0, 112, 199, 62, 202, 238, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGloDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x83, + "Incorrect message type, expected 0x83, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_b.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_b.rs new file mode 100644 index 0000000000..b7327e736f --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_b.rs @@ -0,0 +1,462 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_glo_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, + 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 112, 199, 62, 122, 127, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x85, + "Incorrect message type, expected 0x85, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepB"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_glo_dep_b() { + { + let json_input = r#"{"preamble":85,"msg_type":133,"sender":1219,"length":110,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAIBC9jlnwQAAACKqTiJBAADwx1RWdcEAAABiBvqawAAAANk63aPAAAAAuIoui0AAAAAAAECvPgAAAAAAQK8+AAAAAABwxz4=","crc":32634,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x85, + "Incorrect message type, expected 0x85, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_glo_dep_b`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_glo_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 133, 0, 195, 4, 110, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, 117, + 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, 0, 0, 0, 184, 138, + 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 112, 199, 62, 122, 127, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGloDepB( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x85, + "Incorrect message type, expected 0x85, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepB"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_c.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_c.rs new file mode 100644 index 0000000000..3c6c3d3d31 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_c.rs @@ -0,0 +1,492 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_glo_dep_c() { + { + let mut payload = Cursor::new(vec![ + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, 151, 65, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x87, + "Incorrect message type, expected 0x87, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepC"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_glo_dep_c() { + { + let json_input = r#"{"preamble":85,"msg_type":135,"sender":1219,"length":119,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg4=","crc":16791,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"d_tau":-2.7939677238464355e-09,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"fcn":14}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x87, + "Incorrect message type, expected 0x87, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepC"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_glo_dep_c`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_glo_dep_c() { + { + let mut payload = Cursor::new(vec![ + 85, 135, 0, 195, 4, 119, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, 151, 65, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGloDepC( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepC(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x87, + "Incorrect message type, expected 0x87, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepC"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_d.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_d.rs new file mode 100644 index 0000000000..2fae37ca0c --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_glo_dep_d.rs @@ -0,0 +1,507 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_glo_dep_d() { + { + let mut payload = Cursor::new(vec![ + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, 100, 82, 64, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x88, + "Incorrect message type, expected 0x88, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert_eq!( + msg.iod, 100, + "incorrect value for iod, expected 100, is {}", + msg.iod + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepD"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_glo_dep_d() { + { + let json_input = r#"{"preamble":85,"msg_type":136,"sender":1219,"length":120,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg5k","crc":16466,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"d_tau":-2.7939677238464355e-09,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"fcn":14,"iod":100}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x88, + "Incorrect message type, expected 0x88, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert_eq!( + msg.iod, 100, + "incorrect value for iod, expected 100, is {}", + msg.iod + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepD"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_glo_dep_d`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_glo_dep_d() { + { + let mut payload = Cursor::new(vec![ + 85, 136, 0, 195, 4, 120, 4, 3, 70, 197, 6, 0, 106, 8, 205, 204, 204, 204, 204, 204, 20, + 64, 96, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 112, 61, 0, 0, 0, 0, 48, 236, 21, 191, 0, 0, + 0, 0, 0, 0, 40, 190, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, + 0, 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, + 163, 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, + 64, 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 14, 100, 82, 64, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGloDepD( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGloDepD(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x88, + "Incorrect message type, expected 0x88, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 2400, + "incorrect value for common.fit_interval, expected 2400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 3, + "incorrect value for common.sid.code, expected 3, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 4, + "incorrect value for common.sid.sat, expected 4, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 443718, + "incorrect value for common.toe.tow, expected 443718, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(5.20000000000000018e+00), + "incorrect value for common.ura, expected 5.20000000000000018e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.d_tau.almost_eq(-2.79396772384643555e-09), + "incorrect value for d_tau, expected -2.79396772384643555e-09, is {:e}", + msg.d_tau + ); + assert_eq!( + msg.fcn, 14, + "incorrect value for fcn, expected 14, is {}", + msg.fcn + ); + assert!( + msg.gamma.almost_eq(9.09494701772928238e-13), + "incorrect value for gamma, expected 9.09494701772928238e-13, is {:e}", + msg.gamma + ); + assert_eq!( + msg.iod, 100, + "incorrect value for iod, expected 100, is {}", + msg.iod + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.tau.almost_eq(-8.36281105875968933e-05), + "incorrect value for tau, expected -8.36281105875968933e-05, is {:e}", + msg.tau + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGloDepD"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_e.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_e.rs new file mode 100644 index 0000000000..06fbd605f5 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_e.rs @@ -0,0 +1,663 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_gps_dep_e() { + { + let mut payload = Cursor::new(vec![ + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, + 64, 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, + 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, + 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, + 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, + 0, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepE(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x81, + "Incorrect message type, expected 0x81, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepE"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_gps_dep_e() { + { + let json_input = r#"{"crc":60934,"length":185,"msg_type":129,"payload":"FgAAALDPBgBqCAAAAAAAAABAQDgAAAEAAAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9AAAAAAAAAACwzwYAaggtLQA=","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":14400,"valid":1,"health_bits":0},"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0,"toc":{"tow":446384,"wn":2154},"iode":45,"iodc":45}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepE(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x81, + "Incorrect message type, expected 0x81, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepE"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_gps_dep_e`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_gps_dep_e() { + { + let mut payload = Cursor::new(vec![ + 85, 129, 0, 123, 0, 185, 22, 0, 0, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, + 64, 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, + 0, 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, + 0, 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, + 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, + 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, + 0, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 6, 238, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGpsDepE( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepE(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x81, + "Incorrect message type, expected 0x81, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepE"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_f.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_f.rs new file mode 100644 index 0000000000..6bcf53dad8 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_gps_dep_f.rs @@ -0,0 +1,648 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_gps_dep_f() { + { + let mut payload = Cursor::new(vec![ + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, + 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, + 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, + 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, + 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, + 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, + 0, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 115, 254, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepF(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x86, + "Incorrect message type, expected 0x86, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepF"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_gps_dep_f() { + { + let json_input = r#"{"crc":65139,"length":183,"msg_type":134,"payload":"FgCwzwYAaggAAAAAAAAAQEA4AAABAAAAAAAAAFO+AAAAAAAoSsAAAAAAAEpzQAAAAAAABMe+AAAAAABQyj4AAAAAAABAPgAAAAAAAH++cthgtDF1OD6OKQXrX4eWvwAAACC/93w/AADAzowhtEApg7OGjfj9v+OFUTbMHkO+2DvHJ2Co779HC9mTkeTtP90vZOD/L8a9AAAAAGyxRL8AAAAAAMCjPQAAAAAAAAAAsM8GAGoILS0A","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":14400,"valid":1,"health_bits":0},"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0,"toc":{"tow":446384,"wn":2154},"iode":45,"iodc":45}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepF(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x86, + "Incorrect message type, expected 0x86, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepF"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_gps_dep_f`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_gps_dep_f() { + { + let mut payload = Cursor::new(vec![ + 85, 134, 0, 123, 0, 183, 22, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 64, + 56, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 83, 190, 0, 0, 0, 0, 0, 40, 74, 192, 0, 0, 0, 0, 0, + 74, 115, 64, 0, 0, 0, 0, 0, 4, 199, 190, 0, 0, 0, 0, 0, 80, 202, 62, 0, 0, 0, 0, 0, 0, + 64, 62, 0, 0, 0, 0, 0, 0, 127, 190, 114, 216, 96, 180, 49, 117, 56, 62, 142, 41, 5, + 235, 95, 135, 150, 191, 0, 0, 0, 32, 191, 247, 124, 63, 0, 0, 192, 206, 140, 33, 180, + 64, 41, 131, 179, 134, 141, 248, 253, 191, 227, 133, 81, 54, 204, 30, 67, 190, 216, 59, + 199, 39, 96, 168, 239, 191, 71, 11, 217, 147, 145, 228, 237, 63, 221, 47, 100, 224, + 255, 47, 198, 189, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, 61, 0, 0, 0, + 0, 0, 0, 0, 0, 176, 207, 6, 0, 106, 8, 45, 45, 0, 115, 254, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisGpsDepF( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisGpsDepF(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x86, + "Incorrect message type, expected 0x86, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.af0.almost_eq(-6.31501898169517517e-04), + "incorrect value for af0, expected -6.31501898169517517e-04, is {:e}", + msg.af0 + ); + assert!( + msg.af1.almost_eq(8.98126018000766635e-12), + "incorrect value for af1, expected 8.98126018000766635e-12, is {:e}", + msg.af1 + ); + assert!( + msg.af2.almost_eq(0.00000000000000000e+00), + "incorrect value for af2, expected 0.00000000000000000e+00, is {:e}", + msg.af2 + ); + assert!( + msg.c_ic.almost_eq(7.45058059692382812e-09), + "incorrect value for c_ic, expected 7.45058059692382812e-09, is {:e}", + msg.c_ic + ); + assert!( + msg.c_is.almost_eq(-1.15483999252319336e-07), + "incorrect value for c_is, expected -1.15483999252319336e-07, is {:e}", + msg.c_is + ); + assert!( + msg.c_rc.almost_eq(3.08625000000000000e+02), + "incorrect value for c_rc, expected 3.08625000000000000e+02, is {:e}", + msg.c_rc + ); + assert!( + msg.c_rs.almost_eq(-5.23125000000000000e+01), + "incorrect value for c_rs, expected -5.23125000000000000e+01, is {:e}", + msg.c_rs + ); + assert!( + msg.c_uc.almost_eq(-2.74367630481719971e-06), + "incorrect value for c_uc, expected -2.74367630481719971e-06, is {:e}", + msg.c_uc + ); + assert!( + msg.c_us.almost_eq(3.13669443130493164e-06), + "incorrect value for c_us, expected 3.13669443130493164e-06, is {:e}", + msg.c_us + ); + assert_eq!( + msg.common.fit_interval, 14400, + "incorrect value for common.fit_interval, expected 14400, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 0, + "incorrect value for common.sid.code, expected 0, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.dn.almost_eq(5.69452291402237483e-09), + "incorrect value for dn, expected 5.69452291402237483e-09, is {:e}", + msg.dn + ); + assert!( + msg.ecc.almost_eq(7.07220705226063728e-03), + "incorrect value for ecc, expected 7.07220705226063728e-03, is {:e}", + msg.ecc + ); + assert!( + msg.inc.almost_eq(9.34151448025979714e-01), + "incorrect value for inc, expected 9.34151448025979714e-01, is {:e}", + msg.inc + ); + assert!( + msg.inc_dot.almost_eq(-4.03588239641575691e-11), + "incorrect value for inc_dot, expected -4.03588239641575691e-11, is {:e}", + msg.inc_dot + ); + assert_eq!( + msg.iodc, 45, + "incorrect value for iodc, expected 45, is {}", + msg.iodc + ); + assert_eq!( + msg.iode, 45, + "incorrect value for iode, expected 45, is {}", + msg.iode + ); + assert!( + msg.m0.almost_eq(-2.20007884211468815e-02), + "incorrect value for m0, expected -2.20007884211468815e-02, is {:e}", + msg.m0 + ); + assert!( + msg.omega0.almost_eq(-1.87318184487976169e+00), + "incorrect value for omega0, expected -1.87318184487976169e+00, is {:e}", + msg.omega0 + ); + assert!( + msg.omegadot.almost_eq(-8.90358515577419627e-09), + "incorrect value for omegadot, expected -8.90358515577419627e-09, is {:e}", + msg.omegadot + ); + assert!( + msg.sqrta.almost_eq(5.15355002975463867e+03), + "incorrect value for sqrta, expected 5.15355002975463867e+03, is {:e}", + msg.sqrta + ); + assert!( + msg.tgd.almost_eq(-1.76951289176940918e-08), + "incorrect value for tgd, expected -1.76951289176940918e-08, is {:e}", + msg.tgd + ); + assert_eq!( + msg.toc.tow, 446384, + "incorrect value for toc.tow, expected 446384, is {}", + msg.toc.tow + ); + assert_eq!( + msg.toc.wn, 2154, + "incorrect value for toc.wn, expected 2154, is {}", + msg.toc.wn + ); + assert!( + msg.w.almost_eq(-9.89303662959964747e-01), + "incorrect value for w, expected -9.89303662959964747e-01, is {:e}", + msg.w + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisGPSDepF"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas.rs new file mode 100644 index 0000000000..e84bffcddb --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas.rs @@ -0,0 +1,458 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_sbas() { + { + let mut payload = Cursor::new(vec![ + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, + 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, + 122, 53, 0, 128, 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbas(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x8c, + "Incorrect message type, expected 0x8c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(-2.79396772384643555e-09), + "incorrect value for common.ura, expected -2.79396772384643555e-09, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650622558593750e+03), + "incorrect value for vel[0], expected -1.72650622558593750e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261499023437500e+03), + "incorrect value for vel[1], expected -2.54261499023437500e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817749023437500e+02), + "incorrect value for vel[2], expected 8.69817749023437500e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbas"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_sbas() { + { + let json_input = r#"{"crc":37824,"length":74,"msg_type":140,"payload":"FgawzwYAaggAAECxAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBM9DXxNfpHsVWdFlEAAB6NQAAejUAgDs2YIslugAAHi0=","preamble":85,"sender":1219,"common":{"sid":{"sat":22,"code":6},"toe":{"tow":446384,"wn":2154},"ura":-2.7939677238464355e-09,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.5062255859375,-2542.614990234375,869.8177490234375],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbas(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x8c, + "Incorrect message type, expected 0x8c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(-2.79396772384643555e-09), + "incorrect value for common.ura, expected -2.79396772384643555e-09, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650622558593750e+03), + "incorrect value for vel[0], expected -1.72650622558593750e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261499023437500e+03), + "incorrect value for vel[1], expected -2.54261499023437500e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817749023437500e+02), + "incorrect value for vel[2], expected 8.69817749023437500e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbas"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_sbas`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_sbas() { + { + let mut payload = Cursor::new(vec![ + 85, 140, 0, 195, 4, 74, 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 64, 177, 0, 0, 0, 0, 1, 0, + 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, 199, 84, 86, + 117, 193, 51, 208, 215, 196, 215, 233, 30, 197, 86, 116, 89, 68, 0, 0, 122, 53, 0, 0, + 122, 53, 0, 128, 59, 54, 96, 139, 37, 186, 0, 0, 30, 45, 192, 147, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisSbas( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbas(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x8c, + "Incorrect message type, expected 0x8c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x04c3, + "incorrect sender id, expected 0x04c3, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(-2.79396772384643555e-09), + "incorrect value for common.ura, expected -2.79396772384643555e-09, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650622558593750e+03), + "incorrect value for vel[0], expected -1.72650622558593750e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261499023437500e+03), + "incorrect value for vel[1], expected -2.54261499023437500e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817749023437500e+02), + "incorrect value for vel[2], expected 8.69817749023437500e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbas"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_a.rs new file mode 100644 index 0000000000..c92c1b0bf1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_a.rs @@ -0,0 +1,477 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_sbas_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, + 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, + 192, 163, 61, 178, 180, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x82, + "Incorrect message type, expected 0x82, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_sbas_dep_a() { + { + let json_input = r#"{"crc":46258,"length":112,"msg_type":130,"payload":"FgAGALDPBgBqCAAAAAAAAABAAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBAAAAYgb6msAAAADZOt2jwAAAALiKLotAAAAAAABArz4AAAAAAECvPgAAAAAAcMc+AAAAAGyxRL8AAAAAAMCjPQ==","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":6,"reserved":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x82, + "Incorrect message type, expected 0x82, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_sbas_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_sbas_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 130, 0, 123, 0, 112, 22, 0, 6, 0, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, + 0, 0, 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, + 240, 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, + 192, 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, + 175, 62, 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, + 192, 163, 61, 178, 180, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisSbasDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x82, + "Incorrect message type, expected 0x82, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.reserved, 0, + "incorrect value for common.sid.reserved, expected 0, is {}", + msg.common.sid.reserved + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_b.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_b.rs new file mode 100644 index 0000000000..2406199447 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_ephemeris_sbas_dep_b.rs @@ -0,0 +1,462 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_ephemeris_sbas_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, + 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, + 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, + 61, 145, 104, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x84, + "Incorrect message type, expected 0x84, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepB"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_ephemeris_sbas_dep_b() { + { + let json_input = r#"{"crc":26769,"length":110,"msg_type":132,"payload":"FgawzwYAaggAAAAAAAAAQAAAAAABAAAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPgAAAABssUS/AAAAAADAoz0=","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":6},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x84, + "Incorrect message type, expected 0x84, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_ephemeris_sbas_dep_b`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_ephemeris_sbas_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 132, 0, 123, 0, 110, 22, 6, 176, 207, 6, 0, 106, 8, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, + 0, 0, 1, 0, 0, 0, 128, 66, 246, 57, 103, 193, 0, 0, 0, 34, 170, 78, 34, 65, 0, 0, 240, + 199, 84, 86, 117, 193, 0, 0, 0, 98, 6, 250, 154, 192, 0, 0, 0, 217, 58, 221, 163, 192, + 0, 0, 0, 184, 138, 46, 139, 64, 0, 0, 0, 0, 0, 64, 175, 62, 0, 0, 0, 0, 0, 64, 175, 62, + 0, 0, 0, 0, 0, 112, 199, 62, 0, 0, 0, 0, 108, 177, 68, 191, 0, 0, 0, 0, 0, 192, 163, + 61, 145, 104, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgEphemerisSbasDepB( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgEphemerisSbasDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x84, + "Incorrect message type, expected 0x84, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a_gf0.almost_eq(-6.31501898169517517e-04), + "incorrect value for a_gf0, expected -6.31501898169517517e-04, is {:e}", + msg.a_gf0 + ); + assert!( + msg.a_gf1.almost_eq(8.98126018000766635e-12), + "incorrect value for a_gf1, expected 8.98126018000766635e-12, is {:e}", + msg.a_gf1 + ); + assert!( + msg.acc[0].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[0], expected 9.31322574615478516e-07, is {:e}", + msg.acc[0] + ); + assert!( + msg.acc[1].almost_eq(9.31322574615478516e-07), + "incorrect value for acc[1], expected 9.31322574615478516e-07, is {:e}", + msg.acc[1] + ); + assert!( + msg.acc[2].almost_eq(2.79396772384643555e-06), + "incorrect value for acc[2], expected 2.79396772384643555e-06, is {:e}", + msg.acc[2] + ); + assert_eq!( + msg.common.fit_interval, 0, + "incorrect value for common.fit_interval, expected 0, is {}", + msg.common.fit_interval + ); + assert_eq!( + msg.common.health_bits, 0, + "incorrect value for common.health_bits, expected 0, is {}", + msg.common.health_bits + ); + assert_eq!( + msg.common.sid.code, 6, + "incorrect value for common.sid.code, expected 6, is {}", + msg.common.sid.code + ); + assert_eq!( + msg.common.sid.sat, 22, + "incorrect value for common.sid.sat, expected 22, is {}", + msg.common.sid.sat + ); + assert_eq!( + msg.common.toe.tow, 446384, + "incorrect value for common.toe.tow, expected 446384, is {}", + msg.common.toe.tow + ); + assert_eq!( + msg.common.toe.wn, 2154, + "incorrect value for common.toe.wn, expected 2154, is {}", + msg.common.toe.wn + ); + assert!( + msg.common.ura.almost_eq(2.00000000000000000e+00), + "incorrect value for common.ura, expected 2.00000000000000000e+00, is {:e}", + msg.common.ura + ); + assert_eq!( + msg.common.valid, 1, + "incorrect value for common.valid, expected 1, is {}", + msg.common.valid + ); + assert!( + msg.pos[0].almost_eq(-1.21773300781250000e+07), + "incorrect value for pos[0], expected -1.21773300781250000e+07, is {:e}", + msg.pos[0] + ); + assert!( + msg.pos[1].almost_eq(5.99893066406250000e+05), + "incorrect value for pos[1], expected 5.99893066406250000e+05, is {:e}", + msg.pos[1] + ); + assert!( + msg.pos[2].almost_eq(-2.23737084960937500e+07), + "incorrect value for pos[2], expected -2.23737084960937500e+07, is {:e}", + msg.pos[2] + ); + assert!( + msg.vel[0].almost_eq(-1.72650623321533203e+03), + "incorrect value for vel[0], expected -1.72650623321533203e+03, is {:e}", + msg.vel[0] + ); + assert!( + msg.vel[1].almost_eq(-2.54261493682861328e+03), + "incorrect value for vel[1], expected -2.54261493682861328e+03, is {:e}", + msg.vel[1] + ); + assert!( + msg.vel[2].almost_eq(8.69817733764648438e+02), + "incorrect value for vel[2], expected 8.69817733764648438e+02, is {:e}", + msg.vel[2] + ); + } + _ => panic!("Invalid message type! Expected a MsgEphemerisSbasDepB"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_gnss_capb.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_gnss_capb.rs new file mode 100644 index 0000000000..8c8c62b877 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_gnss_capb.rs @@ -0,0 +1,432 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_gnss_capb() { + { + let mut payload = Cursor::new(vec![ + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, 64, 0, 0, 0, 0, 81, 173, + 144, 46, 0, 0, 0, 0, 209, 139, 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, + 240, 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, 0, 0, 0, 0, 40, 75, + 250, 114, 0, 0, 0, 0, 119, 147, 123, 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, + 116, 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, 0, 0, 0, 252, 62, + 221, 28, 0, 0, 0, 0, 163, 90, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGnssCapb(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x96, + "Incorrect message type, expected 0x96, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.gc.bds_active, 1929005864, + "incorrect value for gc.bds_active, expected 1929005864, is {}", + msg.gc.bds_active + ); + assert_eq!( + msg.gc.bds_b2, 33839445, + "incorrect value for gc.bds_b2, expected 33839445, is {}", + msg.gc.bds_b2 + ); + assert_eq!( + msg.gc.bds_b2a, 378107113, + "incorrect value for gc.bds_b2a, expected 378107113, is {}", + msg.gc.bds_b2a + ); + assert_eq!( + msg.gc.bds_d2nav, 1367053175, + "incorrect value for gc.bds_d2nav, expected 1367053175, is {}", + msg.gc.bds_d2nav + ); + assert_eq!( + msg.gc.gal_active, 1392028637, + "incorrect value for gc.gal_active, expected 1392028637, is {}", + msg.gc.gal_active + ); + assert_eq!( + msg.gc.gal_e5, 484261628, + "incorrect value for gc.gal_e5, expected 484261628, is {}", + msg.gc.gal_e5 + ); + assert_eq!( + msg.gc.glo_active, 13159676, + "incorrect value for gc.glo_active, expected 13159676, is {}", + msg.gc.glo_active + ); + assert_eq!( + msg.gc.glo_l2of, 824073421, + "incorrect value for gc.glo_l2of, expected 824073421, is {}", + msg.gc.glo_l2of + ); + assert_eq!( + msg.gc.glo_l3, 404081648, + "incorrect value for gc.glo_l3, expected 404081648, is {}", + msg.gc.glo_l3 + ); + assert_eq!( + msg.gc.gps_active, 1079028506, + "incorrect value for gc.gps_active, expected 1079028506, is {}", + msg.gc.gps_active + ); + assert_eq!( + msg.gc.gps_l2c, 781233489, + "incorrect value for gc.gps_l2c, expected 781233489, is {}", + msg.gc.gps_l2c + ); + assert_eq!( + msg.gc.gps_l5, 1818069969, + "incorrect value for gc.gps_l5, expected 1818069969, is {}", + msg.gc.gps_l5 + ); + assert_eq!( + msg.gc.qzss_active, 198929863, + "incorrect value for gc.qzss_active, expected 198929863, is {}", + msg.gc.qzss_active + ); + assert_eq!( + msg.gc.sbas_active, 548822484, + "incorrect value for gc.sbas_active, expected 548822484, is {}", + msg.gc.sbas_active + ); + assert_eq!( + msg.gc.sbas_l5, 465576041, + "incorrect value for gc.sbas_l5, expected 465576041, is {}", + msg.gc.sbas_l5 + ); + assert_eq!( + msg.t_nmct.tow, 446384, + "incorrect value for t_nmct.tow, expected 446384, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 2154, + "incorrect value for t_nmct.wn, expected 2154, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssCapb"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_gnss_capb() { + { + let json_input = r#"{"crc":23203,"length":110,"msg_type":150,"payload":"sM8GAGoIGqtQQAAAAABRrZAuAAAAANGLXWwAAAAA/MzIAM1cHjHwyxUY1F22IAAAAABpIMAbAAAAAChL+nIAAAAAd5N7UQAAAABVWQQCAAAAAOl0iRYAAAAAx23bC92r+FIAAAAA/D7dHAAAAAA=","preamble":85,"sender":123,"t_nmct":{"tow":446384,"wn":2154},"gc":{"gps_active":1079028506,"gps_l2c":781233489,"gps_l5":1818069969,"glo_active":13159676,"glo_l2of":824073421,"glo_l3":404081648,"sbas_active":548822484,"sbas_l5":465576041,"bds_active":1929005864,"bds_d2nav":1367053175,"bds_b2":33839445,"bds_b2a":378107113,"qzss_active":198929863,"gal_active":1392028637,"gal_e5":484261628}}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGnssCapb(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x96, + "Incorrect message type, expected 0x96, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.gc.bds_active, 1929005864, + "incorrect value for gc.bds_active, expected 1929005864, is {}", + msg.gc.bds_active + ); + assert_eq!( + msg.gc.bds_b2, 33839445, + "incorrect value for gc.bds_b2, expected 33839445, is {}", + msg.gc.bds_b2 + ); + assert_eq!( + msg.gc.bds_b2a, 378107113, + "incorrect value for gc.bds_b2a, expected 378107113, is {}", + msg.gc.bds_b2a + ); + assert_eq!( + msg.gc.bds_d2nav, 1367053175, + "incorrect value for gc.bds_d2nav, expected 1367053175, is {}", + msg.gc.bds_d2nav + ); + assert_eq!( + msg.gc.gal_active, 1392028637, + "incorrect value for gc.gal_active, expected 1392028637, is {}", + msg.gc.gal_active + ); + assert_eq!( + msg.gc.gal_e5, 484261628, + "incorrect value for gc.gal_e5, expected 484261628, is {}", + msg.gc.gal_e5 + ); + assert_eq!( + msg.gc.glo_active, 13159676, + "incorrect value for gc.glo_active, expected 13159676, is {}", + msg.gc.glo_active + ); + assert_eq!( + msg.gc.glo_l2of, 824073421, + "incorrect value for gc.glo_l2of, expected 824073421, is {}", + msg.gc.glo_l2of + ); + assert_eq!( + msg.gc.glo_l3, 404081648, + "incorrect value for gc.glo_l3, expected 404081648, is {}", + msg.gc.glo_l3 + ); + assert_eq!( + msg.gc.gps_active, 1079028506, + "incorrect value for gc.gps_active, expected 1079028506, is {}", + msg.gc.gps_active + ); + assert_eq!( + msg.gc.gps_l2c, 781233489, + "incorrect value for gc.gps_l2c, expected 781233489, is {}", + msg.gc.gps_l2c + ); + assert_eq!( + msg.gc.gps_l5, 1818069969, + "incorrect value for gc.gps_l5, expected 1818069969, is {}", + msg.gc.gps_l5 + ); + assert_eq!( + msg.gc.qzss_active, 198929863, + "incorrect value for gc.qzss_active, expected 198929863, is {}", + msg.gc.qzss_active + ); + assert_eq!( + msg.gc.sbas_active, 548822484, + "incorrect value for gc.sbas_active, expected 548822484, is {}", + msg.gc.sbas_active + ); + assert_eq!( + msg.gc.sbas_l5, 465576041, + "incorrect value for gc.sbas_l5, expected 465576041, is {}", + msg.gc.sbas_l5 + ); + assert_eq!( + msg.t_nmct.tow, 446384, + "incorrect value for t_nmct.tow, expected 446384, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 2154, + "incorrect value for t_nmct.wn, expected 2154, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssCapb"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_gnss_capb`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_gnss_capb() { + { + let mut payload = Cursor::new(vec![ + 85, 150, 0, 123, 0, 110, 176, 207, 6, 0, 106, 8, 26, 171, 80, 64, 0, 0, 0, 0, 81, 173, + 144, 46, 0, 0, 0, 0, 209, 139, 93, 108, 0, 0, 0, 0, 252, 204, 200, 0, 205, 92, 30, 49, + 240, 203, 21, 24, 212, 93, 182, 32, 0, 0, 0, 0, 105, 32, 192, 27, 0, 0, 0, 0, 40, 75, + 250, 114, 0, 0, 0, 0, 119, 147, 123, 81, 0, 0, 0, 0, 85, 89, 4, 2, 0, 0, 0, 0, 233, + 116, 137, 22, 0, 0, 0, 0, 199, 109, 219, 11, 221, 171, 248, 82, 0, 0, 0, 0, 252, 62, + 221, 28, 0, 0, 0, 0, 163, 90, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgGnssCapb( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgGnssCapb(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x96, + "Incorrect message type, expected 0x96, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.gc.bds_active, 1929005864, + "incorrect value for gc.bds_active, expected 1929005864, is {}", + msg.gc.bds_active + ); + assert_eq!( + msg.gc.bds_b2, 33839445, + "incorrect value for gc.bds_b2, expected 33839445, is {}", + msg.gc.bds_b2 + ); + assert_eq!( + msg.gc.bds_b2a, 378107113, + "incorrect value for gc.bds_b2a, expected 378107113, is {}", + msg.gc.bds_b2a + ); + assert_eq!( + msg.gc.bds_d2nav, 1367053175, + "incorrect value for gc.bds_d2nav, expected 1367053175, is {}", + msg.gc.bds_d2nav + ); + assert_eq!( + msg.gc.gal_active, 1392028637, + "incorrect value for gc.gal_active, expected 1392028637, is {}", + msg.gc.gal_active + ); + assert_eq!( + msg.gc.gal_e5, 484261628, + "incorrect value for gc.gal_e5, expected 484261628, is {}", + msg.gc.gal_e5 + ); + assert_eq!( + msg.gc.glo_active, 13159676, + "incorrect value for gc.glo_active, expected 13159676, is {}", + msg.gc.glo_active + ); + assert_eq!( + msg.gc.glo_l2of, 824073421, + "incorrect value for gc.glo_l2of, expected 824073421, is {}", + msg.gc.glo_l2of + ); + assert_eq!( + msg.gc.glo_l3, 404081648, + "incorrect value for gc.glo_l3, expected 404081648, is {}", + msg.gc.glo_l3 + ); + assert_eq!( + msg.gc.gps_active, 1079028506, + "incorrect value for gc.gps_active, expected 1079028506, is {}", + msg.gc.gps_active + ); + assert_eq!( + msg.gc.gps_l2c, 781233489, + "incorrect value for gc.gps_l2c, expected 781233489, is {}", + msg.gc.gps_l2c + ); + assert_eq!( + msg.gc.gps_l5, 1818069969, + "incorrect value for gc.gps_l5, expected 1818069969, is {}", + msg.gc.gps_l5 + ); + assert_eq!( + msg.gc.qzss_active, 198929863, + "incorrect value for gc.qzss_active, expected 198929863, is {}", + msg.gc.qzss_active + ); + assert_eq!( + msg.gc.sbas_active, 548822484, + "incorrect value for gc.sbas_active, expected 548822484, is {}", + msg.gc.sbas_active + ); + assert_eq!( + msg.gc.sbas_l5, 465576041, + "incorrect value for gc.sbas_l5, expected 465576041, is {}", + msg.gc.sbas_l5 + ); + assert_eq!( + msg.t_nmct.tow, 446384, + "incorrect value for t_nmct.tow, expected 446384, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 2154, + "incorrect value for t_nmct.wn, expected 2154, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssCapb"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay.rs new file mode 100644 index 0000000000..525798a3ac --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay.rs @@ -0,0 +1,289 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_group_delay() { + { + let mut payload = Cursor::new(vec![ + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, 22, 0, 1, 254, 253, 165, 255, 237, 23, + 2, 201, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelay(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x94, + "Incorrect message type, expected 0x94, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelay"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_group_delay() { + { + let json_input = r#"{"crc":51458,"length":15,"msg_type":148,"payload":"sM8GAGoIFgAB/v2l/+0X","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"sid":{"sat":22,"code":0},"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelay(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x94, + "Incorrect message type, expected 0x94, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelay"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_group_delay`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_group_delay() { + { + let mut payload = Cursor::new(vec![ + 85, 148, 0, 123, 0, 15, 176, 207, 6, 0, 106, 8, 22, 0, 1, 254, 253, 165, 255, 237, 23, + 2, 201, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgGroupDelay( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelay(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x94, + "Incorrect message type, expected 0x94, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelay"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_a.rs new file mode 100644 index 0000000000..f81561c581 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_a.rs @@ -0,0 +1,274 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_group_delay_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, 8, 22, 1, 254, 253, 165, 255, 237, 23, + 162, 91, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x92, + "Incorrect message type, expected 0x92, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_group_delay_dep_a() { + { + let json_input = r#"{"crc":23458,"length":14,"msg_type":146,"payload":"sM8GAGoIFgH+/aX/7Rc=","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"prn":22,"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x92, + "Incorrect message type, expected 0x92, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_group_delay_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_group_delay_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 146, 0, 123, 0, 14, 176, 207, 6, 0, 106, 8, 22, 1, 254, 253, 165, 255, 237, 23, + 162, 91, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgGroupDelayDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x92, + "Incorrect message type, expected 0x92, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.prn, 22, + "incorrect value for prn, expected 22, is {}", + msg.prn + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_b.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_b.rs new file mode 100644 index 0000000000..602aaa0590 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_group_delay_dep_b.rs @@ -0,0 +1,304 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_group_delay_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, 0, 0, 0, 1, 254, 253, 165, 255, + 237, 23, 221, 202, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x93, + "Incorrect message type, expected 0x93, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepB"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_group_delay_dep_b() { + { + let json_input = r#"{"crc":51933,"length":17,"msg_type":147,"payload":"sM8GAGoIFgAAAAH+/aX/7Rc=","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"sid":{"sat":22,"code":0,"reserved":0},"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x93, + "Incorrect message type, expected 0x93, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_group_delay_dep_b`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_group_delay_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 147, 0, 123, 0, 17, 176, 207, 6, 0, 106, 8, 22, 0, 0, 0, 1, 254, 253, 165, 255, + 237, 23, 221, 202, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgGroupDelayDepB( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgGroupDelayDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x93, + "Incorrect message type, expected 0x93, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.isc_l1ca, -91, + "incorrect value for isc_l1ca, expected -91, is {}", + msg.isc_l1ca + ); + assert_eq!( + msg.isc_l2c, 6125, + "incorrect value for isc_l2c, expected 6125, is {}", + msg.isc_l2c + ); + assert_eq!( + msg.sid.code, 0, + "incorrect value for sid.code, expected 0, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 22, + "incorrect value for sid.sat, expected 22, is {}", + msg.sid.sat + ); + assert_eq!( + msg.t_op.tow, 446384, + "incorrect value for t_op.tow, expected 446384, is {}", + msg.t_op.tow + ); + assert_eq!( + msg.t_op.wn, 2154, + "incorrect value for t_op.wn, expected 2154, is {}", + msg.t_op.wn + ); + assert_eq!( + msg.tgd, -514, + "incorrect value for tgd, expected -514, is {}", + msg.tgd + ); + assert_eq!( + msg.valid, 1, + "incorrect value for valid, expected 1, is {}", + msg.valid + ); + } + _ => panic!("Invalid message type! Expected a MsgGroupDelayDepB"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_iono.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_iono.rs new file mode 100644 index 0000000000..30e4d4eee6 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_iono.rs @@ -0,0 +1,323 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_iono() { + { + let mut payload = Cursor::new(vec![ + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, + 80, 62, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 243, + 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, + 101, 31, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgIono(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x90, + "Incorrect message type, expected 0x90, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a0.almost_eq(4.65661287307739258e-09), + "incorrect value for a0, expected 4.65661287307739258e-09, is {:e}", + msg.a0 + ); + assert!( + msg.a1.almost_eq(1.49011611938476562e-08), + "incorrect value for a1, expected 1.49011611938476562e-08, is {:e}", + msg.a1 + ); + assert!( + msg.a2.almost_eq(-5.96046447753906250e-08), + "incorrect value for a2, expected -5.96046447753906250e-08, is {:e}", + msg.a2 + ); + assert!( + msg.a3.almost_eq(-5.96046447753906250e-08), + "incorrect value for a3, expected -5.96046447753906250e-08, is {:e}", + msg.a3 + ); + assert!( + msg.b0.almost_eq(7.78240000000000000e+04), + "incorrect value for b0, expected 7.78240000000000000e+04, is {:e}", + msg.b0 + ); + assert!( + msg.b1.almost_eq(4.91520000000000000e+04), + "incorrect value for b1, expected 4.91520000000000000e+04, is {:e}", + msg.b1 + ); + assert!( + msg.b2.almost_eq(-6.55360000000000000e+04), + "incorrect value for b2, expected -6.55360000000000000e+04, is {:e}", + msg.b2 + ); + assert!( + msg.b3.almost_eq(-3.27680000000000000e+05), + "incorrect value for b3, expected -3.27680000000000000e+05, is {:e}", + msg.b3 + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgIono"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_iono() { + { + let json_input = r#"{"crc":8037,"length":70,"msg_type":144,"payload":"AAAAAAAAAAAAAAAAND4AAAAAAABQPgAAAAAAAHC+AAAAAAAAcL4AAAAAAADzQAAAAAAAAOhAAAAAAAAA8MAAAAAAAAAUwQ==","preamble":85,"sender":123,"t_nmct":{"tow":0,"wn":0},"a0":4.6566128730773926e-09,"a1":1.4901161193847656e-08,"a2":-5.960464477539063e-08,"a3":-5.960464477539063e-08,"b0":77824,"b1":49152,"b2":-65536,"b3":-327680}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgIono(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x90, + "Incorrect message type, expected 0x90, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a0.almost_eq(4.65661287307739258e-09), + "incorrect value for a0, expected 4.65661287307739258e-09, is {:e}", + msg.a0 + ); + assert!( + msg.a1.almost_eq(1.49011611938476562e-08), + "incorrect value for a1, expected 1.49011611938476562e-08, is {:e}", + msg.a1 + ); + assert!( + msg.a2.almost_eq(-5.96046447753906250e-08), + "incorrect value for a2, expected -5.96046447753906250e-08, is {:e}", + msg.a2 + ); + assert!( + msg.a3.almost_eq(-5.96046447753906250e-08), + "incorrect value for a3, expected -5.96046447753906250e-08, is {:e}", + msg.a3 + ); + assert!( + msg.b0.almost_eq(7.78240000000000000e+04), + "incorrect value for b0, expected 7.78240000000000000e+04, is {:e}", + msg.b0 + ); + assert!( + msg.b1.almost_eq(4.91520000000000000e+04), + "incorrect value for b1, expected 4.91520000000000000e+04, is {:e}", + msg.b1 + ); + assert!( + msg.b2.almost_eq(-6.55360000000000000e+04), + "incorrect value for b2, expected -6.55360000000000000e+04, is {:e}", + msg.b2 + ); + assert!( + msg.b3.almost_eq(-3.27680000000000000e+05), + "incorrect value for b3, expected -3.27680000000000000e+05, is {:e}", + msg.b3 + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgIono"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_iono`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_iono() { + { + let mut payload = Cursor::new(vec![ + 85, 144, 0, 123, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 62, 0, 0, 0, 0, 0, 0, + 80, 62, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 112, 190, 0, 0, 0, 0, 0, 0, 243, + 64, 0, 0, 0, 0, 0, 0, 232, 64, 0, 0, 0, 0, 0, 0, 240, 192, 0, 0, 0, 0, 0, 0, 20, 193, + 101, 31, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgIono( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgIono(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x90, + "Incorrect message type, expected 0x90, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert!( + msg.a0.almost_eq(4.65661287307739258e-09), + "incorrect value for a0, expected 4.65661287307739258e-09, is {:e}", + msg.a0 + ); + assert!( + msg.a1.almost_eq(1.49011611938476562e-08), + "incorrect value for a1, expected 1.49011611938476562e-08, is {:e}", + msg.a1 + ); + assert!( + msg.a2.almost_eq(-5.96046447753906250e-08), + "incorrect value for a2, expected -5.96046447753906250e-08, is {:e}", + msg.a2 + ); + assert!( + msg.a3.almost_eq(-5.96046447753906250e-08), + "incorrect value for a3, expected -5.96046447753906250e-08, is {:e}", + msg.a3 + ); + assert!( + msg.b0.almost_eq(7.78240000000000000e+04), + "incorrect value for b0, expected 7.78240000000000000e+04, is {:e}", + msg.b0 + ); + assert!( + msg.b1.almost_eq(4.91520000000000000e+04), + "incorrect value for b1, expected 4.91520000000000000e+04, is {:e}", + msg.b1 + ); + assert!( + msg.b2.almost_eq(-6.55360000000000000e+04), + "incorrect value for b2, expected -6.55360000000000000e+04, is {:e}", + msg.b2 + ); + assert!( + msg.b3.almost_eq(-3.27680000000000000e+05), + "incorrect value for b3, expected -3.27680000000000000e+05, is {:e}", + msg.b3 + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgIono"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_msg_sv_configuration_gps_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_sv_configuration_gps_dep.rs new file mode 100644 index 0000000000..897c417fb8 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_msg_sv_configuration_gps_dep.rs @@ -0,0 +1,212 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_msg_sv_configuration_gps_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSvConfigurationGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x91, + "Incorrect message type, expected 0x91, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.l2c_mask, 2808462402, + "incorrect value for l2c_mask, expected 2808462402, is {}", + msg.l2c_mask + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSvConfigurationGPSDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_msg_sv_configuration_gps_dep() { + { + let json_input = r#"{"crc":10770,"length":10,"msg_type":145,"payload":"AAAAAAAAQrxlpw==","preamble":85,"sender":123,"t_nmct":{"tow":0,"wn":0},"l2c_mask":2808462402}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSvConfigurationGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x91, + "Incorrect message type, expected 0x91, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.l2c_mask, 2808462402, + "incorrect value for l2c_mask, expected 2808462402, is {}", + msg.l2c_mask + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSvConfigurationGPSDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_msg_sv_configuration_gps_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_msg_sv_configuration_gps_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 145, 0, 123, 0, 10, 0, 0, 0, 0, 0, 0, 66, 188, 101, 167, 18, 42, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSvConfigurationGpsDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSvConfigurationGpsDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x91, + "Incorrect message type, expected 0x91, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x007b, + "incorrect sender id, expected 0x007b, is {sender_id}" + ); + assert_eq!( + msg.l2c_mask, 2808462402, + "incorrect value for l2c_mask, expected 2808462402, is {}", + msg.l2c_mask + ); + assert_eq!( + msg.t_nmct.tow, 0, + "incorrect value for t_nmct.tow, expected 0, is {}", + msg.t_nmct.tow + ); + assert_eq!( + msg.t_nmct.wn, 0, + "incorrect value for t_nmct.wn, expected 0, is {}", + msg.t_nmct.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSvConfigurationGPSDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_observation_observation_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_observation_observation_structs.rs new file mode 100644 index 0000000000..6c8b63758e --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_observation_observation_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/observation/test_observation_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_observation_observation_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_observation_observation_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_observation_observation_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_observation_observation_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_orientation_msg_baseline_heading.rs b/rust/sbp/tests/integration/auto_check_sbp_orientation_msg_baseline_heading.rs new file mode 100644 index 0000000000..cf1cbfeaf7 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_orientation_msg_baseline_heading.rs @@ -0,0 +1,227 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_orientation_msg_baseline_heading() { + { + let mut payload = Cursor::new(vec![ + 85, 15, 2, 211, 93, 10, 156, 45, 13, 196, 44, 84, 197, 61, 91, 91, 224, 254, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeading(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x20f, + "Incorrect message type, expected 0x20f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5dd3, + "incorrect sender id, expected 0x5dd3, is {sender_id}" + ); + assert_eq!( + msg.flags, 91, + "incorrect value for flags, expected 91, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 1036342316, + "incorrect value for heading, expected 1036342316, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 91, + "incorrect value for n_sats, expected 91, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 3289197980, + "incorrect value for tow, expected 3289197980, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeading"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_orientation_msg_baseline_heading() { + { + let json_input = r#"{"crc":65248,"length":10,"msg_type":527,"payload":"nC0NxCxUxT1bWw==","preamble":85,"sender":24019,"tow":3289197980,"heading":1036342316,"n_sats":91,"flags":91}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeading(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x20f, + "Incorrect message type, expected 0x20f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5dd3, + "incorrect sender id, expected 0x5dd3, is {sender_id}" + ); + assert_eq!( + msg.flags, 91, + "incorrect value for flags, expected 91, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 1036342316, + "incorrect value for heading, expected 1036342316, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 91, + "incorrect value for n_sats, expected 91, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 3289197980, + "incorrect value for tow, expected 3289197980, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeading"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_orientation_msg_baseline_heading`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_orientation_msg_baseline_heading() { + { + let mut payload = Cursor::new(vec![ + 85, 15, 2, 211, 93, 10, 156, 45, 13, 196, 44, 84, 197, 61, 91, 91, 224, 254, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgBaselineHeading( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgBaselineHeading(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x20f, + "Incorrect message type, expected 0x20f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5dd3, + "incorrect sender id, expected 0x5dd3, is {sender_id}" + ); + assert_eq!( + msg.flags, 91, + "incorrect value for flags, expected 91, is {}", + msg.flags + ); + assert_eq!( + msg.heading, 1036342316, + "incorrect value for heading, expected 1036342316, is {}", + msg.heading + ); + assert_eq!( + msg.n_sats, 91, + "incorrect value for n_sats, expected 91, is {}", + msg.n_sats + ); + assert_eq!( + msg.tow, 3289197980, + "incorrect value for tow, expected 3289197980, is {}", + msg.tow + ); + } + _ => panic!("Invalid message type! Expected a MsgBaselineHeading"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_almanac.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_almanac.rs new file mode 100644 index 0000000000..38e29d0ff7 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_almanac.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_almanac() { + { + let mut payload = Cursor::new(vec![85, 105, 0, 108, 138, 0, 249, 171]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanac(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x69, + "Incorrect message type, expected 0x69, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a6c, + "incorrect sender id, expected 0x8a6c, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanac"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_almanac() { + { + let json_input = + r#"{"crc":44025,"length":0,"msg_type":105,"payload":"","preamble":85,"sender":35436}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanac(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x69, + "Incorrect message type, expected 0x69, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a6c, + "incorrect sender id, expected 0x8a6c, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanac"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_almanac`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_almanac() { + { + let mut payload = Cursor::new(vec![85, 105, 0, 108, 138, 0, 249, 171]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgAlmanac( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgAlmanac(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x69, + "Incorrect message type, expected 0x69, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8a6c, + "incorrect sender id, expected 0x8a6c, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgAlmanac"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cell_modem_status.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cell_modem_status.rs new file mode 100644 index 0000000000..038c0e5119 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cell_modem_status.rs @@ -0,0 +1,3961 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_cell_modem_status() { + { + let mut payload = Cursor::new(vec![ + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, 52, 64, 176, 154, 98, 43, + 132, 196, 89, 253, 161, 250, 174, 204, 110, 47, 38, 187, 63, 102, 177, 162, 49, 80, + 194, 37, 107, 60, 225, 52, 101, 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, 80, + 243, 30, 206, 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, 85, 146, 100, 190, 232, 207, + 61, 61, 201, 220, 31, 78, 34, 57, 82, 59, 104, 65, 221, 0, 43, 210, 9, 32, 122, 29, + 237, 11, 151, 223, 18, 81, 204, 172, 234, 127, 3, 82, 133, 169, 12, 176, 193, 0, 24, + 121, 85, 55, 214, 198, 75, 234, 179, 214, 85, 94, 115, 21, 73, 121, 75, 46, 158, 63, + 100, 122, 213, 20, 85, 212, 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, 39, 164, 5, + 175, 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, 177, 0, 47, 140, 33, 126, 221, 110, + 144, 97, 74, 250, 181, 199, 27, 176, 65, 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, + 4, 90, 36, 7, 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, 83, 16, + 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, 141, 232, 33, 101, 231, 38, 75, + 178, 243, 119, 1, 248, 218, 86, 7, 88, 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, + 156, 217, 67, 239, 219, 31, 224, 176, 129, 81, 80, 40, 230, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCellModemStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbe, + "Incorrect message type, expected 0xbe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1b13, + "incorrect sender id, expected 0x1b13, is {sender_id}" + ); + assert_eq!( + msg.reserved[0], 123, + "incorrect value for reserved[0], expected 123, is {}", + msg.reserved[0] + ); + assert_eq!( + msg.reserved[1], 242, + "incorrect value for reserved[1], expected 242, is {}", + msg.reserved[1] + ); + assert_eq!( + msg.reserved[2], 46, + "incorrect value for reserved[2], expected 46, is {}", + msg.reserved[2] + ); + assert_eq!( + msg.reserved[3], 52, + "incorrect value for reserved[3], expected 52, is {}", + msg.reserved[3] + ); + assert_eq!( + msg.reserved[4], 64, + "incorrect value for reserved[4], expected 64, is {}", + msg.reserved[4] + ); + assert_eq!( + msg.reserved[5], 176, + "incorrect value for reserved[5], expected 176, is {}", + msg.reserved[5] + ); + assert_eq!( + msg.reserved[6], 154, + "incorrect value for reserved[6], expected 154, is {}", + msg.reserved[6] + ); + assert_eq!( + msg.reserved[7], 98, + "incorrect value for reserved[7], expected 98, is {}", + msg.reserved[7] + ); + assert_eq!( + msg.reserved[8], 43, + "incorrect value for reserved[8], expected 43, is {}", + msg.reserved[8] + ); + assert_eq!( + msg.reserved[9], 132, + "incorrect value for reserved[9], expected 132, is {}", + msg.reserved[9] + ); + assert_eq!( + msg.reserved[10], 196, + "incorrect value for reserved[10], expected 196, is {}", + msg.reserved[10] + ); + assert_eq!( + msg.reserved[11], 89, + "incorrect value for reserved[11], expected 89, is {}", + msg.reserved[11] + ); + assert_eq!( + msg.reserved[12], 253, + "incorrect value for reserved[12], expected 253, is {}", + msg.reserved[12] + ); + assert_eq!( + msg.reserved[13], 161, + "incorrect value for reserved[13], expected 161, is {}", + msg.reserved[13] + ); + assert_eq!( + msg.reserved[14], 250, + "incorrect value for reserved[14], expected 250, is {}", + msg.reserved[14] + ); + assert_eq!( + msg.reserved[15], 174, + "incorrect value for reserved[15], expected 174, is {}", + msg.reserved[15] + ); + assert_eq!( + msg.reserved[16], 204, + "incorrect value for reserved[16], expected 204, is {}", + msg.reserved[16] + ); + assert_eq!( + msg.reserved[17], 110, + "incorrect value for reserved[17], expected 110, is {}", + msg.reserved[17] + ); + assert_eq!( + msg.reserved[18], 47, + "incorrect value for reserved[18], expected 47, is {}", + msg.reserved[18] + ); + assert_eq!( + msg.reserved[19], 38, + "incorrect value for reserved[19], expected 38, is {}", + msg.reserved[19] + ); + assert_eq!( + msg.reserved[20], 187, + "incorrect value for reserved[20], expected 187, is {}", + msg.reserved[20] + ); + assert_eq!( + msg.reserved[21], 63, + "incorrect value for reserved[21], expected 63, is {}", + msg.reserved[21] + ); + assert_eq!( + msg.reserved[22], 102, + "incorrect value for reserved[22], expected 102, is {}", + msg.reserved[22] + ); + assert_eq!( + msg.reserved[23], 177, + "incorrect value for reserved[23], expected 177, is {}", + msg.reserved[23] + ); + assert_eq!( + msg.reserved[24], 162, + "incorrect value for reserved[24], expected 162, is {}", + msg.reserved[24] + ); + assert_eq!( + msg.reserved[25], 49, + "incorrect value for reserved[25], expected 49, is {}", + msg.reserved[25] + ); + assert_eq!( + msg.reserved[26], 80, + "incorrect value for reserved[26], expected 80, is {}", + msg.reserved[26] + ); + assert_eq!( + msg.reserved[27], 194, + "incorrect value for reserved[27], expected 194, is {}", + msg.reserved[27] + ); + assert_eq!( + msg.reserved[28], 37, + "incorrect value for reserved[28], expected 37, is {}", + msg.reserved[28] + ); + assert_eq!( + msg.reserved[29], 107, + "incorrect value for reserved[29], expected 107, is {}", + msg.reserved[29] + ); + assert_eq!( + msg.reserved[30], 60, + "incorrect value for reserved[30], expected 60, is {}", + msg.reserved[30] + ); + assert_eq!( + msg.reserved[31], 225, + "incorrect value for reserved[31], expected 225, is {}", + msg.reserved[31] + ); + assert_eq!( + msg.reserved[32], 52, + "incorrect value for reserved[32], expected 52, is {}", + msg.reserved[32] + ); + assert_eq!( + msg.reserved[33], 101, + "incorrect value for reserved[33], expected 101, is {}", + msg.reserved[33] + ); + assert_eq!( + msg.reserved[34], 178, + "incorrect value for reserved[34], expected 178, is {}", + msg.reserved[34] + ); + assert_eq!( + msg.reserved[35], 142, + "incorrect value for reserved[35], expected 142, is {}", + msg.reserved[35] + ); + assert_eq!( + msg.reserved[36], 246, + "incorrect value for reserved[36], expected 246, is {}", + msg.reserved[36] + ); + assert_eq!( + msg.reserved[37], 21, + "incorrect value for reserved[37], expected 21, is {}", + msg.reserved[37] + ); + assert_eq!( + msg.reserved[38], 17, + "incorrect value for reserved[38], expected 17, is {}", + msg.reserved[38] + ); + assert_eq!( + msg.reserved[39], 93, + "incorrect value for reserved[39], expected 93, is {}", + msg.reserved[39] + ); + assert_eq!( + msg.reserved[40], 75, + "incorrect value for reserved[40], expected 75, is {}", + msg.reserved[40] + ); + assert_eq!( + msg.reserved[41], 169, + "incorrect value for reserved[41], expected 169, is {}", + msg.reserved[41] + ); + assert_eq!( + msg.reserved[42], 86, + "incorrect value for reserved[42], expected 86, is {}", + msg.reserved[42] + ); + assert_eq!( + msg.reserved[43], 16, + "incorrect value for reserved[43], expected 16, is {}", + msg.reserved[43] + ); + assert_eq!( + msg.reserved[44], 209, + "incorrect value for reserved[44], expected 209, is {}", + msg.reserved[44] + ); + assert_eq!( + msg.reserved[45], 80, + "incorrect value for reserved[45], expected 80, is {}", + msg.reserved[45] + ); + assert_eq!( + msg.reserved[46], 243, + "incorrect value for reserved[46], expected 243, is {}", + msg.reserved[46] + ); + assert_eq!( + msg.reserved[47], 30, + "incorrect value for reserved[47], expected 30, is {}", + msg.reserved[47] + ); + assert_eq!( + msg.reserved[48], 206, + "incorrect value for reserved[48], expected 206, is {}", + msg.reserved[48] + ); + assert_eq!( + msg.reserved[49], 220, + "incorrect value for reserved[49], expected 220, is {}", + msg.reserved[49] + ); + assert_eq!( + msg.reserved[50], 206, + "incorrect value for reserved[50], expected 206, is {}", + msg.reserved[50] + ); + assert_eq!( + msg.reserved[51], 115, + "incorrect value for reserved[51], expected 115, is {}", + msg.reserved[51] + ); + assert_eq!( + msg.reserved[52], 47, + "incorrect value for reserved[52], expected 47, is {}", + msg.reserved[52] + ); + assert_eq!( + msg.reserved[53], 154, + "incorrect value for reserved[53], expected 154, is {}", + msg.reserved[53] + ); + assert_eq!( + msg.reserved[54], 91, + "incorrect value for reserved[54], expected 91, is {}", + msg.reserved[54] + ); + assert_eq!( + msg.reserved[55], 227, + "incorrect value for reserved[55], expected 227, is {}", + msg.reserved[55] + ); + assert_eq!( + msg.reserved[56], 88, + "incorrect value for reserved[56], expected 88, is {}", + msg.reserved[56] + ); + assert_eq!( + msg.reserved[57], 11, + "incorrect value for reserved[57], expected 11, is {}", + msg.reserved[57] + ); + assert_eq!( + msg.reserved[58], 1, + "incorrect value for reserved[58], expected 1, is {}", + msg.reserved[58] + ); + assert_eq!( + msg.reserved[59], 85, + "incorrect value for reserved[59], expected 85, is {}", + msg.reserved[59] + ); + assert_eq!( + msg.reserved[60], 146, + "incorrect value for reserved[60], expected 146, is {}", + msg.reserved[60] + ); + assert_eq!( + msg.reserved[61], 100, + "incorrect value for reserved[61], expected 100, is {}", + msg.reserved[61] + ); + assert_eq!( + msg.reserved[62], 190, + "incorrect value for reserved[62], expected 190, is {}", + msg.reserved[62] + ); + assert_eq!( + msg.reserved[63], 232, + "incorrect value for reserved[63], expected 232, is {}", + msg.reserved[63] + ); + assert_eq!( + msg.reserved[64], 207, + "incorrect value for reserved[64], expected 207, is {}", + msg.reserved[64] + ); + assert_eq!( + msg.reserved[65], 61, + "incorrect value for reserved[65], expected 61, is {}", + msg.reserved[65] + ); + assert_eq!( + msg.reserved[66], 61, + "incorrect value for reserved[66], expected 61, is {}", + msg.reserved[66] + ); + assert_eq!( + msg.reserved[67], 201, + "incorrect value for reserved[67], expected 201, is {}", + msg.reserved[67] + ); + assert_eq!( + msg.reserved[68], 220, + "incorrect value for reserved[68], expected 220, is {}", + msg.reserved[68] + ); + assert_eq!( + msg.reserved[69], 31, + "incorrect value for reserved[69], expected 31, is {}", + msg.reserved[69] + ); + assert_eq!( + msg.reserved[70], 78, + "incorrect value for reserved[70], expected 78, is {}", + msg.reserved[70] + ); + assert_eq!( + msg.reserved[71], 34, + "incorrect value for reserved[71], expected 34, is {}", + msg.reserved[71] + ); + assert_eq!( + msg.reserved[72], 57, + "incorrect value for reserved[72], expected 57, is {}", + msg.reserved[72] + ); + assert_eq!( + msg.reserved[73], 82, + "incorrect value for reserved[73], expected 82, is {}", + msg.reserved[73] + ); + assert_eq!( + msg.reserved[74], 59, + "incorrect value for reserved[74], expected 59, is {}", + msg.reserved[74] + ); + assert_eq!( + msg.reserved[75], 104, + "incorrect value for reserved[75], expected 104, is {}", + msg.reserved[75] + ); + assert_eq!( + msg.reserved[76], 65, + "incorrect value for reserved[76], expected 65, is {}", + msg.reserved[76] + ); + assert_eq!( + msg.reserved[77], 221, + "incorrect value for reserved[77], expected 221, is {}", + msg.reserved[77] + ); + assert_eq!( + msg.reserved[78], 0, + "incorrect value for reserved[78], expected 0, is {}", + msg.reserved[78] + ); + assert_eq!( + msg.reserved[79], 43, + "incorrect value for reserved[79], expected 43, is {}", + msg.reserved[79] + ); + assert_eq!( + msg.reserved[80], 210, + "incorrect value for reserved[80], expected 210, is {}", + msg.reserved[80] + ); + assert_eq!( + msg.reserved[81], 9, + "incorrect value for reserved[81], expected 9, is {}", + msg.reserved[81] + ); + assert_eq!( + msg.reserved[82], 32, + "incorrect value for reserved[82], expected 32, is {}", + msg.reserved[82] + ); + assert_eq!( + msg.reserved[83], 122, + "incorrect value for reserved[83], expected 122, is {}", + msg.reserved[83] + ); + assert_eq!( + msg.reserved[84], 29, + "incorrect value for reserved[84], expected 29, is {}", + msg.reserved[84] + ); + assert_eq!( + msg.reserved[85], 237, + "incorrect value for reserved[85], expected 237, is {}", + msg.reserved[85] + ); + assert_eq!( + msg.reserved[86], 11, + "incorrect value for reserved[86], expected 11, is {}", + msg.reserved[86] + ); + assert_eq!( + msg.reserved[87], 151, + "incorrect value for reserved[87], expected 151, is {}", + msg.reserved[87] + ); + assert_eq!( + msg.reserved[88], 223, + "incorrect value for reserved[88], expected 223, is {}", + msg.reserved[88] + ); + assert_eq!( + msg.reserved[89], 18, + "incorrect value for reserved[89], expected 18, is {}", + msg.reserved[89] + ); + assert_eq!( + msg.reserved[90], 81, + "incorrect value for reserved[90], expected 81, is {}", + msg.reserved[90] + ); + assert_eq!( + msg.reserved[91], 204, + "incorrect value for reserved[91], expected 204, is {}", + msg.reserved[91] + ); + assert_eq!( + msg.reserved[92], 172, + "incorrect value for reserved[92], expected 172, is {}", + msg.reserved[92] + ); + assert_eq!( + msg.reserved[93], 234, + "incorrect value for reserved[93], expected 234, is {}", + msg.reserved[93] + ); + assert_eq!( + msg.reserved[94], 127, + "incorrect value for reserved[94], expected 127, is {}", + msg.reserved[94] + ); + assert_eq!( + msg.reserved[95], 3, + "incorrect value for reserved[95], expected 3, is {}", + msg.reserved[95] + ); + assert_eq!( + msg.reserved[96], 82, + "incorrect value for reserved[96], expected 82, is {}", + msg.reserved[96] + ); + assert_eq!( + msg.reserved[97], 133, + "incorrect value for reserved[97], expected 133, is {}", + msg.reserved[97] + ); + assert_eq!( + msg.reserved[98], 169, + "incorrect value for reserved[98], expected 169, is {}", + msg.reserved[98] + ); + assert_eq!( + msg.reserved[99], 12, + "incorrect value for reserved[99], expected 12, is {}", + msg.reserved[99] + ); + assert_eq!( + msg.reserved[100], 176, + "incorrect value for reserved[100], expected 176, is {}", + msg.reserved[100] + ); + assert_eq!( + msg.reserved[101], 193, + "incorrect value for reserved[101], expected 193, is {}", + msg.reserved[101] + ); + assert_eq!( + msg.reserved[102], 0, + "incorrect value for reserved[102], expected 0, is {}", + msg.reserved[102] + ); + assert_eq!( + msg.reserved[103], 24, + "incorrect value for reserved[103], expected 24, is {}", + msg.reserved[103] + ); + assert_eq!( + msg.reserved[104], 121, + "incorrect value for reserved[104], expected 121, is {}", + msg.reserved[104] + ); + assert_eq!( + msg.reserved[105], 85, + "incorrect value for reserved[105], expected 85, is {}", + msg.reserved[105] + ); + assert_eq!( + msg.reserved[106], 55, + "incorrect value for reserved[106], expected 55, is {}", + msg.reserved[106] + ); + assert_eq!( + msg.reserved[107], 214, + "incorrect value for reserved[107], expected 214, is {}", + msg.reserved[107] + ); + assert_eq!( + msg.reserved[108], 198, + "incorrect value for reserved[108], expected 198, is {}", + msg.reserved[108] + ); + assert_eq!( + msg.reserved[109], 75, + "incorrect value for reserved[109], expected 75, is {}", + msg.reserved[109] + ); + assert_eq!( + msg.reserved[110], 234, + "incorrect value for reserved[110], expected 234, is {}", + msg.reserved[110] + ); + assert_eq!( + msg.reserved[111], 179, + "incorrect value for reserved[111], expected 179, is {}", + msg.reserved[111] + ); + assert_eq!( + msg.reserved[112], 214, + "incorrect value for reserved[112], expected 214, is {}", + msg.reserved[112] + ); + assert_eq!( + msg.reserved[113], 85, + "incorrect value for reserved[113], expected 85, is {}", + msg.reserved[113] + ); + assert_eq!( + msg.reserved[114], 94, + "incorrect value for reserved[114], expected 94, is {}", + msg.reserved[114] + ); + assert_eq!( + msg.reserved[115], 115, + "incorrect value for reserved[115], expected 115, is {}", + msg.reserved[115] + ); + assert_eq!( + msg.reserved[116], 21, + "incorrect value for reserved[116], expected 21, is {}", + msg.reserved[116] + ); + assert_eq!( + msg.reserved[117], 73, + "incorrect value for reserved[117], expected 73, is {}", + msg.reserved[117] + ); + assert_eq!( + msg.reserved[118], 121, + "incorrect value for reserved[118], expected 121, is {}", + msg.reserved[118] + ); + assert_eq!( + msg.reserved[119], 75, + "incorrect value for reserved[119], expected 75, is {}", + msg.reserved[119] + ); + assert_eq!( + msg.reserved[120], 46, + "incorrect value for reserved[120], expected 46, is {}", + msg.reserved[120] + ); + assert_eq!( + msg.reserved[121], 158, + "incorrect value for reserved[121], expected 158, is {}", + msg.reserved[121] + ); + assert_eq!( + msg.reserved[122], 63, + "incorrect value for reserved[122], expected 63, is {}", + msg.reserved[122] + ); + assert_eq!( + msg.reserved[123], 100, + "incorrect value for reserved[123], expected 100, is {}", + msg.reserved[123] + ); + assert_eq!( + msg.reserved[124], 122, + "incorrect value for reserved[124], expected 122, is {}", + msg.reserved[124] + ); + assert_eq!( + msg.reserved[125], 213, + "incorrect value for reserved[125], expected 213, is {}", + msg.reserved[125] + ); + assert_eq!( + msg.reserved[126], 20, + "incorrect value for reserved[126], expected 20, is {}", + msg.reserved[126] + ); + assert_eq!( + msg.reserved[127], 85, + "incorrect value for reserved[127], expected 85, is {}", + msg.reserved[127] + ); + assert_eq!( + msg.reserved[128], 212, + "incorrect value for reserved[128], expected 212, is {}", + msg.reserved[128] + ); + assert_eq!( + msg.reserved[129], 131, + "incorrect value for reserved[129], expected 131, is {}", + msg.reserved[129] + ); + assert_eq!( + msg.reserved[130], 50, + "incorrect value for reserved[130], expected 50, is {}", + msg.reserved[130] + ); + assert_eq!( + msg.reserved[131], 224, + "incorrect value for reserved[131], expected 224, is {}", + msg.reserved[131] + ); + assert_eq!( + msg.reserved[132], 218, + "incorrect value for reserved[132], expected 218, is {}", + msg.reserved[132] + ); + assert_eq!( + msg.reserved[133], 215, + "incorrect value for reserved[133], expected 215, is {}", + msg.reserved[133] + ); + assert_eq!( + msg.reserved[134], 215, + "incorrect value for reserved[134], expected 215, is {}", + msg.reserved[134] + ); + assert_eq!( + msg.reserved[135], 149, + "incorrect value for reserved[135], expected 149, is {}", + msg.reserved[135] + ); + assert_eq!( + msg.reserved[136], 2, + "incorrect value for reserved[136], expected 2, is {}", + msg.reserved[136] + ); + assert_eq!( + msg.reserved[137], 19, + "incorrect value for reserved[137], expected 19, is {}", + msg.reserved[137] + ); + assert_eq!( + msg.reserved[138], 129, + "incorrect value for reserved[138], expected 129, is {}", + msg.reserved[138] + ); + assert_eq!( + msg.reserved[139], 39, + "incorrect value for reserved[139], expected 39, is {}", + msg.reserved[139] + ); + assert_eq!( + msg.reserved[140], 164, + "incorrect value for reserved[140], expected 164, is {}", + msg.reserved[140] + ); + assert_eq!( + msg.reserved[141], 5, + "incorrect value for reserved[141], expected 5, is {}", + msg.reserved[141] + ); + assert_eq!( + msg.reserved[142], 175, + "incorrect value for reserved[142], expected 175, is {}", + msg.reserved[142] + ); + assert_eq!( + msg.reserved[143], 6, + "incorrect value for reserved[143], expected 6, is {}", + msg.reserved[143] + ); + assert_eq!( + msg.reserved[144], 62, + "incorrect value for reserved[144], expected 62, is {}", + msg.reserved[144] + ); + assert_eq!( + msg.reserved[145], 51, + "incorrect value for reserved[145], expected 51, is {}", + msg.reserved[145] + ); + assert_eq!( + msg.reserved[146], 78, + "incorrect value for reserved[146], expected 78, is {}", + msg.reserved[146] + ); + assert_eq!( + msg.reserved[147], 66, + "incorrect value for reserved[147], expected 66, is {}", + msg.reserved[147] + ); + assert_eq!( + msg.reserved[148], 248, + "incorrect value for reserved[148], expected 248, is {}", + msg.reserved[148] + ); + assert_eq!( + msg.reserved[149], 116, + "incorrect value for reserved[149], expected 116, is {}", + msg.reserved[149] + ); + assert_eq!( + msg.reserved[150], 88, + "incorrect value for reserved[150], expected 88, is {}", + msg.reserved[150] + ); + assert_eq!( + msg.reserved[151], 90, + "incorrect value for reserved[151], expected 90, is {}", + msg.reserved[151] + ); + assert_eq!( + msg.reserved[152], 128, + "incorrect value for reserved[152], expected 128, is {}", + msg.reserved[152] + ); + assert_eq!( + msg.reserved[153], 226, + "incorrect value for reserved[153], expected 226, is {}", + msg.reserved[153] + ); + assert_eq!( + msg.reserved[154], 177, + "incorrect value for reserved[154], expected 177, is {}", + msg.reserved[154] + ); + assert_eq!( + msg.reserved[155], 0, + "incorrect value for reserved[155], expected 0, is {}", + msg.reserved[155] + ); + assert_eq!( + msg.reserved[156], 47, + "incorrect value for reserved[156], expected 47, is {}", + msg.reserved[156] + ); + assert_eq!( + msg.reserved[157], 140, + "incorrect value for reserved[157], expected 140, is {}", + msg.reserved[157] + ); + assert_eq!( + msg.reserved[158], 33, + "incorrect value for reserved[158], expected 33, is {}", + msg.reserved[158] + ); + assert_eq!( + msg.reserved[159], 126, + "incorrect value for reserved[159], expected 126, is {}", + msg.reserved[159] + ); + assert_eq!( + msg.reserved[160], 221, + "incorrect value for reserved[160], expected 221, is {}", + msg.reserved[160] + ); + assert_eq!( + msg.reserved[161], 110, + "incorrect value for reserved[161], expected 110, is {}", + msg.reserved[161] + ); + assert_eq!( + msg.reserved[162], 144, + "incorrect value for reserved[162], expected 144, is {}", + msg.reserved[162] + ); + assert_eq!( + msg.reserved[163], 97, + "incorrect value for reserved[163], expected 97, is {}", + msg.reserved[163] + ); + assert_eq!( + msg.reserved[164], 74, + "incorrect value for reserved[164], expected 74, is {}", + msg.reserved[164] + ); + assert_eq!( + msg.reserved[165], 250, + "incorrect value for reserved[165], expected 250, is {}", + msg.reserved[165] + ); + assert_eq!( + msg.reserved[166], 181, + "incorrect value for reserved[166], expected 181, is {}", + msg.reserved[166] + ); + assert_eq!( + msg.reserved[167], 199, + "incorrect value for reserved[167], expected 199, is {}", + msg.reserved[167] + ); + assert_eq!( + msg.reserved[168], 27, + "incorrect value for reserved[168], expected 27, is {}", + msg.reserved[168] + ); + assert_eq!( + msg.reserved[169], 176, + "incorrect value for reserved[169], expected 176, is {}", + msg.reserved[169] + ); + assert_eq!( + msg.reserved[170], 65, + "incorrect value for reserved[170], expected 65, is {}", + msg.reserved[170] + ); + assert_eq!( + msg.reserved[171], 185, + "incorrect value for reserved[171], expected 185, is {}", + msg.reserved[171] + ); + assert_eq!( + msg.reserved[172], 110, + "incorrect value for reserved[172], expected 110, is {}", + msg.reserved[172] + ); + assert_eq!( + msg.reserved[173], 92, + "incorrect value for reserved[173], expected 92, is {}", + msg.reserved[173] + ); + assert_eq!( + msg.reserved[174], 34, + "incorrect value for reserved[174], expected 34, is {}", + msg.reserved[174] + ); + assert_eq!( + msg.reserved[175], 44, + "incorrect value for reserved[175], expected 44, is {}", + msg.reserved[175] + ); + assert_eq!( + msg.reserved[176], 131, + "incorrect value for reserved[176], expected 131, is {}", + msg.reserved[176] + ); + assert_eq!( + msg.reserved[177], 96, + "incorrect value for reserved[177], expected 96, is {}", + msg.reserved[177] + ); + assert_eq!( + msg.reserved[178], 178, + "incorrect value for reserved[178], expected 178, is {}", + msg.reserved[178] + ); + assert_eq!( + msg.reserved[179], 40, + "incorrect value for reserved[179], expected 40, is {}", + msg.reserved[179] + ); + assert_eq!( + msg.reserved[180], 176, + "incorrect value for reserved[180], expected 176, is {}", + msg.reserved[180] + ); + assert_eq!( + msg.reserved[181], 4, + "incorrect value for reserved[181], expected 4, is {}", + msg.reserved[181] + ); + assert_eq!( + msg.reserved[182], 90, + "incorrect value for reserved[182], expected 90, is {}", + msg.reserved[182] + ); + assert_eq!( + msg.reserved[183], 36, + "incorrect value for reserved[183], expected 36, is {}", + msg.reserved[183] + ); + assert_eq!( + msg.reserved[184], 7, + "incorrect value for reserved[184], expected 7, is {}", + msg.reserved[184] + ); + assert_eq!( + msg.reserved[185], 180, + "incorrect value for reserved[185], expected 180, is {}", + msg.reserved[185] + ); + assert_eq!( + msg.reserved[186], 244, + "incorrect value for reserved[186], expected 244, is {}", + msg.reserved[186] + ); + assert_eq!( + msg.reserved[187], 244, + "incorrect value for reserved[187], expected 244, is {}", + msg.reserved[187] + ); + assert_eq!( + msg.reserved[188], 23, + "incorrect value for reserved[188], expected 23, is {}", + msg.reserved[188] + ); + assert_eq!( + msg.reserved[189], 108, + "incorrect value for reserved[189], expected 108, is {}", + msg.reserved[189] + ); + assert_eq!( + msg.reserved[190], 171, + "incorrect value for reserved[190], expected 171, is {}", + msg.reserved[190] + ); + assert_eq!( + msg.reserved[191], 204, + "incorrect value for reserved[191], expected 204, is {}", + msg.reserved[191] + ); + assert_eq!( + msg.reserved[192], 196, + "incorrect value for reserved[192], expected 196, is {}", + msg.reserved[192] + ); + assert_eq!( + msg.reserved[193], 61, + "incorrect value for reserved[193], expected 61, is {}", + msg.reserved[193] + ); + assert_eq!( + msg.reserved[194], 51, + "incorrect value for reserved[194], expected 51, is {}", + msg.reserved[194] + ); + assert_eq!( + msg.reserved[195], 179, + "incorrect value for reserved[195], expected 179, is {}", + msg.reserved[195] + ); + assert_eq!( + msg.reserved[196], 242, + "incorrect value for reserved[196], expected 242, is {}", + msg.reserved[196] + ); + assert_eq!( + msg.reserved[197], 156, + "incorrect value for reserved[197], expected 156, is {}", + msg.reserved[197] + ); + assert_eq!( + msg.reserved[198], 81, + "incorrect value for reserved[198], expected 81, is {}", + msg.reserved[198] + ); + assert_eq!( + msg.reserved[199], 83, + "incorrect value for reserved[199], expected 83, is {}", + msg.reserved[199] + ); + assert_eq!( + msg.reserved[200], 16, + "incorrect value for reserved[200], expected 16, is {}", + msg.reserved[200] + ); + assert_eq!( + msg.reserved[201], 15, + "incorrect value for reserved[201], expected 15, is {}", + msg.reserved[201] + ); + assert_eq!( + msg.reserved[202], 134, + "incorrect value for reserved[202], expected 134, is {}", + msg.reserved[202] + ); + assert_eq!( + msg.reserved[203], 40, + "incorrect value for reserved[203], expected 40, is {}", + msg.reserved[203] + ); + assert_eq!( + msg.reserved[204], 245, + "incorrect value for reserved[204], expected 245, is {}", + msg.reserved[204] + ); + assert_eq!( + msg.reserved[205], 253, + "incorrect value for reserved[205], expected 253, is {}", + msg.reserved[205] + ); + assert_eq!( + msg.reserved[206], 150, + "incorrect value for reserved[206], expected 150, is {}", + msg.reserved[206] + ); + assert_eq!( + msg.reserved[207], 94, + "incorrect value for reserved[207], expected 94, is {}", + msg.reserved[207] + ); + assert_eq!( + msg.reserved[208], 150, + "incorrect value for reserved[208], expected 150, is {}", + msg.reserved[208] + ); + assert_eq!( + msg.reserved[209], 144, + "incorrect value for reserved[209], expected 144, is {}", + msg.reserved[209] + ); + assert_eq!( + msg.reserved[210], 197, + "incorrect value for reserved[210], expected 197, is {}", + msg.reserved[210] + ); + assert_eq!( + msg.reserved[211], 113, + "incorrect value for reserved[211], expected 113, is {}", + msg.reserved[211] + ); + assert_eq!( + msg.reserved[212], 5, + "incorrect value for reserved[212], expected 5, is {}", + msg.reserved[212] + ); + assert_eq!( + msg.reserved[213], 141, + "incorrect value for reserved[213], expected 141, is {}", + msg.reserved[213] + ); + assert_eq!( + msg.reserved[214], 232, + "incorrect value for reserved[214], expected 232, is {}", + msg.reserved[214] + ); + assert_eq!( + msg.reserved[215], 33, + "incorrect value for reserved[215], expected 33, is {}", + msg.reserved[215] + ); + assert_eq!( + msg.reserved[216], 101, + "incorrect value for reserved[216], expected 101, is {}", + msg.reserved[216] + ); + assert_eq!( + msg.reserved[217], 231, + "incorrect value for reserved[217], expected 231, is {}", + msg.reserved[217] + ); + assert_eq!( + msg.reserved[218], 38, + "incorrect value for reserved[218], expected 38, is {}", + msg.reserved[218] + ); + assert_eq!( + msg.reserved[219], 75, + "incorrect value for reserved[219], expected 75, is {}", + msg.reserved[219] + ); + assert_eq!( + msg.reserved[220], 178, + "incorrect value for reserved[220], expected 178, is {}", + msg.reserved[220] + ); + assert_eq!( + msg.reserved[221], 243, + "incorrect value for reserved[221], expected 243, is {}", + msg.reserved[221] + ); + assert_eq!( + msg.reserved[222], 119, + "incorrect value for reserved[222], expected 119, is {}", + msg.reserved[222] + ); + assert_eq!( + msg.reserved[223], 1, + "incorrect value for reserved[223], expected 1, is {}", + msg.reserved[223] + ); + assert_eq!( + msg.reserved[224], 248, + "incorrect value for reserved[224], expected 248, is {}", + msg.reserved[224] + ); + assert_eq!( + msg.reserved[225], 218, + "incorrect value for reserved[225], expected 218, is {}", + msg.reserved[225] + ); + assert_eq!( + msg.reserved[226], 86, + "incorrect value for reserved[226], expected 86, is {}", + msg.reserved[226] + ); + assert_eq!( + msg.reserved[227], 7, + "incorrect value for reserved[227], expected 7, is {}", + msg.reserved[227] + ); + assert_eq!( + msg.reserved[228], 88, + "incorrect value for reserved[228], expected 88, is {}", + msg.reserved[228] + ); + assert_eq!( + msg.reserved[229], 197, + "incorrect value for reserved[229], expected 197, is {}", + msg.reserved[229] + ); + assert_eq!( + msg.reserved[230], 148, + "incorrect value for reserved[230], expected 148, is {}", + msg.reserved[230] + ); + assert_eq!( + msg.reserved[231], 240, + "incorrect value for reserved[231], expected 240, is {}", + msg.reserved[231] + ); + assert_eq!( + msg.reserved[232], 227, + "incorrect value for reserved[232], expected 227, is {}", + msg.reserved[232] + ); + assert_eq!( + msg.reserved[233], 2, + "incorrect value for reserved[233], expected 2, is {}", + msg.reserved[233] + ); + assert_eq!( + msg.reserved[234], 65, + "incorrect value for reserved[234], expected 65, is {}", + msg.reserved[234] + ); + assert_eq!( + msg.reserved[235], 173, + "incorrect value for reserved[235], expected 173, is {}", + msg.reserved[235] + ); + assert_eq!( + msg.reserved[236], 122, + "incorrect value for reserved[236], expected 122, is {}", + msg.reserved[236] + ); + assert_eq!( + msg.reserved[237], 143, + "incorrect value for reserved[237], expected 143, is {}", + msg.reserved[237] + ); + assert_eq!( + msg.reserved[238], 251, + "incorrect value for reserved[238], expected 251, is {}", + msg.reserved[238] + ); + assert_eq!( + msg.reserved[239], 156, + "incorrect value for reserved[239], expected 156, is {}", + msg.reserved[239] + ); + assert_eq!( + msg.reserved[240], 217, + "incorrect value for reserved[240], expected 217, is {}", + msg.reserved[240] + ); + assert_eq!( + msg.reserved[241], 67, + "incorrect value for reserved[241], expected 67, is {}", + msg.reserved[241] + ); + assert_eq!( + msg.reserved[242], 239, + "incorrect value for reserved[242], expected 239, is {}", + msg.reserved[242] + ); + assert_eq!( + msg.reserved[243], 219, + "incorrect value for reserved[243], expected 219, is {}", + msg.reserved[243] + ); + assert_eq!( + msg.reserved[244], 31, + "incorrect value for reserved[244], expected 31, is {}", + msg.reserved[244] + ); + assert_eq!( + msg.reserved[245], 224, + "incorrect value for reserved[245], expected 224, is {}", + msg.reserved[245] + ); + assert_eq!( + msg.reserved[246], 176, + "incorrect value for reserved[246], expected 176, is {}", + msg.reserved[246] + ); + assert_eq!( + msg.reserved[247], 129, + "incorrect value for reserved[247], expected 129, is {}", + msg.reserved[247] + ); + assert_eq!( + msg.reserved[248], 81, + "incorrect value for reserved[248], expected 81, is {}", + msg.reserved[248] + ); + assert_eq!( + msg.reserved[249], 80, + "incorrect value for reserved[249], expected 80, is {}", + msg.reserved[249] + ); + assert!(msg.signal_error_rate.almost_eq( 8.58820019531250000e+03 ), "incorrect value for signal_error_rate, expected 8.58820019531250000e+03, is {:e}", msg.signal_error_rate); + assert_eq!( + msg.signal_strength, 103, + "incorrect value for signal_strength, expected 103, is {}", + msg.signal_strength + ); + } + _ => panic!("Invalid message type! Expected a MsgCellModemStatus"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_cell_modem_status() { + { + let json_input = r#"{"preamble":85,"msg_type":190,"sender":6931,"length":255,"payload":"Z80wBkZ78i40QLCaYiuExFn9ofquzG4vJrs/ZrGiMVDCJWs84TRlso72FRFdS6lWENFQ8x7O3M5zL5pb41gLAVWSZL7ozz09ydwfTiI5UjtoQd0AK9IJIHod7QuX3xJRzKzqfwNShakMsMEAGHlVN9bGS+qz1lVecxVJeUsunj9ketUUVdSDMuDa19eVAhOBJ6QFrwY+M05C+HRYWoDisQAvjCF+3W6QYUr6tccbsEG5blwiLINgsiiwBFokB7T09Bdsq8zEPTOz8pxRUxAPhij1/ZZelpDFcQWN6CFl5yZLsvN3AfjaVgdYxZTw4wJBrXqP+5zZQ+/bH+CwgVFQ","crc":58920,"signal_strength":103,"signal_error_rate":8588.2001953125,"reserved":[123,242,46,52,64,176,154,98,43,132,196,89,253,161,250,174,204,110,47,38,187,63,102,177,162,49,80,194,37,107,60,225,52,101,178,142,246,21,17,93,75,169,86,16,209,80,243,30,206,220,206,115,47,154,91,227,88,11,1,85,146,100,190,232,207,61,61,201,220,31,78,34,57,82,59,104,65,221,0,43,210,9,32,122,29,237,11,151,223,18,81,204,172,234,127,3,82,133,169,12,176,193,0,24,121,85,55,214,198,75,234,179,214,85,94,115,21,73,121,75,46,158,63,100,122,213,20,85,212,131,50,224,218,215,215,149,2,19,129,39,164,5,175,6,62,51,78,66,248,116,88,90,128,226,177,0,47,140,33,126,221,110,144,97,74,250,181,199,27,176,65,185,110,92,34,44,131,96,178,40,176,4,90,36,7,180,244,244,23,108,171,204,196,61,51,179,242,156,81,83,16,15,134,40,245,253,150,94,150,144,197,113,5,141,232,33,101,231,38,75,178,243,119,1,248,218,86,7,88,197,148,240,227,2,65,173,122,143,251,156,217,67,239,219,31,224,176,129,81,80]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCellModemStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbe, + "Incorrect message type, expected 0xbe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1b13, + "incorrect sender id, expected 0x1b13, is {sender_id}" + ); + assert_eq!( + msg.reserved[0], 123, + "incorrect value for reserved[0], expected 123, is {}", + msg.reserved[0] + ); + assert_eq!( + msg.reserved[1], 242, + "incorrect value for reserved[1], expected 242, is {}", + msg.reserved[1] + ); + assert_eq!( + msg.reserved[2], 46, + "incorrect value for reserved[2], expected 46, is {}", + msg.reserved[2] + ); + assert_eq!( + msg.reserved[3], 52, + "incorrect value for reserved[3], expected 52, is {}", + msg.reserved[3] + ); + assert_eq!( + msg.reserved[4], 64, + "incorrect value for reserved[4], expected 64, is {}", + msg.reserved[4] + ); + assert_eq!( + msg.reserved[5], 176, + "incorrect value for reserved[5], expected 176, is {}", + msg.reserved[5] + ); + assert_eq!( + msg.reserved[6], 154, + "incorrect value for reserved[6], expected 154, is {}", + msg.reserved[6] + ); + assert_eq!( + msg.reserved[7], 98, + "incorrect value for reserved[7], expected 98, is {}", + msg.reserved[7] + ); + assert_eq!( + msg.reserved[8], 43, + "incorrect value for reserved[8], expected 43, is {}", + msg.reserved[8] + ); + assert_eq!( + msg.reserved[9], 132, + "incorrect value for reserved[9], expected 132, is {}", + msg.reserved[9] + ); + assert_eq!( + msg.reserved[10], 196, + "incorrect value for reserved[10], expected 196, is {}", + msg.reserved[10] + ); + assert_eq!( + msg.reserved[11], 89, + "incorrect value for reserved[11], expected 89, is {}", + msg.reserved[11] + ); + assert_eq!( + msg.reserved[12], 253, + "incorrect value for reserved[12], expected 253, is {}", + msg.reserved[12] + ); + assert_eq!( + msg.reserved[13], 161, + "incorrect value for reserved[13], expected 161, is {}", + msg.reserved[13] + ); + assert_eq!( + msg.reserved[14], 250, + "incorrect value for reserved[14], expected 250, is {}", + msg.reserved[14] + ); + assert_eq!( + msg.reserved[15], 174, + "incorrect value for reserved[15], expected 174, is {}", + msg.reserved[15] + ); + assert_eq!( + msg.reserved[16], 204, + "incorrect value for reserved[16], expected 204, is {}", + msg.reserved[16] + ); + assert_eq!( + msg.reserved[17], 110, + "incorrect value for reserved[17], expected 110, is {}", + msg.reserved[17] + ); + assert_eq!( + msg.reserved[18], 47, + "incorrect value for reserved[18], expected 47, is {}", + msg.reserved[18] + ); + assert_eq!( + msg.reserved[19], 38, + "incorrect value for reserved[19], expected 38, is {}", + msg.reserved[19] + ); + assert_eq!( + msg.reserved[20], 187, + "incorrect value for reserved[20], expected 187, is {}", + msg.reserved[20] + ); + assert_eq!( + msg.reserved[21], 63, + "incorrect value for reserved[21], expected 63, is {}", + msg.reserved[21] + ); + assert_eq!( + msg.reserved[22], 102, + "incorrect value for reserved[22], expected 102, is {}", + msg.reserved[22] + ); + assert_eq!( + msg.reserved[23], 177, + "incorrect value for reserved[23], expected 177, is {}", + msg.reserved[23] + ); + assert_eq!( + msg.reserved[24], 162, + "incorrect value for reserved[24], expected 162, is {}", + msg.reserved[24] + ); + assert_eq!( + msg.reserved[25], 49, + "incorrect value for reserved[25], expected 49, is {}", + msg.reserved[25] + ); + assert_eq!( + msg.reserved[26], 80, + "incorrect value for reserved[26], expected 80, is {}", + msg.reserved[26] + ); + assert_eq!( + msg.reserved[27], 194, + "incorrect value for reserved[27], expected 194, is {}", + msg.reserved[27] + ); + assert_eq!( + msg.reserved[28], 37, + "incorrect value for reserved[28], expected 37, is {}", + msg.reserved[28] + ); + assert_eq!( + msg.reserved[29], 107, + "incorrect value for reserved[29], expected 107, is {}", + msg.reserved[29] + ); + assert_eq!( + msg.reserved[30], 60, + "incorrect value for reserved[30], expected 60, is {}", + msg.reserved[30] + ); + assert_eq!( + msg.reserved[31], 225, + "incorrect value for reserved[31], expected 225, is {}", + msg.reserved[31] + ); + assert_eq!( + msg.reserved[32], 52, + "incorrect value for reserved[32], expected 52, is {}", + msg.reserved[32] + ); + assert_eq!( + msg.reserved[33], 101, + "incorrect value for reserved[33], expected 101, is {}", + msg.reserved[33] + ); + assert_eq!( + msg.reserved[34], 178, + "incorrect value for reserved[34], expected 178, is {}", + msg.reserved[34] + ); + assert_eq!( + msg.reserved[35], 142, + "incorrect value for reserved[35], expected 142, is {}", + msg.reserved[35] + ); + assert_eq!( + msg.reserved[36], 246, + "incorrect value for reserved[36], expected 246, is {}", + msg.reserved[36] + ); + assert_eq!( + msg.reserved[37], 21, + "incorrect value for reserved[37], expected 21, is {}", + msg.reserved[37] + ); + assert_eq!( + msg.reserved[38], 17, + "incorrect value for reserved[38], expected 17, is {}", + msg.reserved[38] + ); + assert_eq!( + msg.reserved[39], 93, + "incorrect value for reserved[39], expected 93, is {}", + msg.reserved[39] + ); + assert_eq!( + msg.reserved[40], 75, + "incorrect value for reserved[40], expected 75, is {}", + msg.reserved[40] + ); + assert_eq!( + msg.reserved[41], 169, + "incorrect value for reserved[41], expected 169, is {}", + msg.reserved[41] + ); + assert_eq!( + msg.reserved[42], 86, + "incorrect value for reserved[42], expected 86, is {}", + msg.reserved[42] + ); + assert_eq!( + msg.reserved[43], 16, + "incorrect value for reserved[43], expected 16, is {}", + msg.reserved[43] + ); + assert_eq!( + msg.reserved[44], 209, + "incorrect value for reserved[44], expected 209, is {}", + msg.reserved[44] + ); + assert_eq!( + msg.reserved[45], 80, + "incorrect value for reserved[45], expected 80, is {}", + msg.reserved[45] + ); + assert_eq!( + msg.reserved[46], 243, + "incorrect value for reserved[46], expected 243, is {}", + msg.reserved[46] + ); + assert_eq!( + msg.reserved[47], 30, + "incorrect value for reserved[47], expected 30, is {}", + msg.reserved[47] + ); + assert_eq!( + msg.reserved[48], 206, + "incorrect value for reserved[48], expected 206, is {}", + msg.reserved[48] + ); + assert_eq!( + msg.reserved[49], 220, + "incorrect value for reserved[49], expected 220, is {}", + msg.reserved[49] + ); + assert_eq!( + msg.reserved[50], 206, + "incorrect value for reserved[50], expected 206, is {}", + msg.reserved[50] + ); + assert_eq!( + msg.reserved[51], 115, + "incorrect value for reserved[51], expected 115, is {}", + msg.reserved[51] + ); + assert_eq!( + msg.reserved[52], 47, + "incorrect value for reserved[52], expected 47, is {}", + msg.reserved[52] + ); + assert_eq!( + msg.reserved[53], 154, + "incorrect value for reserved[53], expected 154, is {}", + msg.reserved[53] + ); + assert_eq!( + msg.reserved[54], 91, + "incorrect value for reserved[54], expected 91, is {}", + msg.reserved[54] + ); + assert_eq!( + msg.reserved[55], 227, + "incorrect value for reserved[55], expected 227, is {}", + msg.reserved[55] + ); + assert_eq!( + msg.reserved[56], 88, + "incorrect value for reserved[56], expected 88, is {}", + msg.reserved[56] + ); + assert_eq!( + msg.reserved[57], 11, + "incorrect value for reserved[57], expected 11, is {}", + msg.reserved[57] + ); + assert_eq!( + msg.reserved[58], 1, + "incorrect value for reserved[58], expected 1, is {}", + msg.reserved[58] + ); + assert_eq!( + msg.reserved[59], 85, + "incorrect value for reserved[59], expected 85, is {}", + msg.reserved[59] + ); + assert_eq!( + msg.reserved[60], 146, + "incorrect value for reserved[60], expected 146, is {}", + msg.reserved[60] + ); + assert_eq!( + msg.reserved[61], 100, + "incorrect value for reserved[61], expected 100, is {}", + msg.reserved[61] + ); + assert_eq!( + msg.reserved[62], 190, + "incorrect value for reserved[62], expected 190, is {}", + msg.reserved[62] + ); + assert_eq!( + msg.reserved[63], 232, + "incorrect value for reserved[63], expected 232, is {}", + msg.reserved[63] + ); + assert_eq!( + msg.reserved[64], 207, + "incorrect value for reserved[64], expected 207, is {}", + msg.reserved[64] + ); + assert_eq!( + msg.reserved[65], 61, + "incorrect value for reserved[65], expected 61, is {}", + msg.reserved[65] + ); + assert_eq!( + msg.reserved[66], 61, + "incorrect value for reserved[66], expected 61, is {}", + msg.reserved[66] + ); + assert_eq!( + msg.reserved[67], 201, + "incorrect value for reserved[67], expected 201, is {}", + msg.reserved[67] + ); + assert_eq!( + msg.reserved[68], 220, + "incorrect value for reserved[68], expected 220, is {}", + msg.reserved[68] + ); + assert_eq!( + msg.reserved[69], 31, + "incorrect value for reserved[69], expected 31, is {}", + msg.reserved[69] + ); + assert_eq!( + msg.reserved[70], 78, + "incorrect value for reserved[70], expected 78, is {}", + msg.reserved[70] + ); + assert_eq!( + msg.reserved[71], 34, + "incorrect value for reserved[71], expected 34, is {}", + msg.reserved[71] + ); + assert_eq!( + msg.reserved[72], 57, + "incorrect value for reserved[72], expected 57, is {}", + msg.reserved[72] + ); + assert_eq!( + msg.reserved[73], 82, + "incorrect value for reserved[73], expected 82, is {}", + msg.reserved[73] + ); + assert_eq!( + msg.reserved[74], 59, + "incorrect value for reserved[74], expected 59, is {}", + msg.reserved[74] + ); + assert_eq!( + msg.reserved[75], 104, + "incorrect value for reserved[75], expected 104, is {}", + msg.reserved[75] + ); + assert_eq!( + msg.reserved[76], 65, + "incorrect value for reserved[76], expected 65, is {}", + msg.reserved[76] + ); + assert_eq!( + msg.reserved[77], 221, + "incorrect value for reserved[77], expected 221, is {}", + msg.reserved[77] + ); + assert_eq!( + msg.reserved[78], 0, + "incorrect value for reserved[78], expected 0, is {}", + msg.reserved[78] + ); + assert_eq!( + msg.reserved[79], 43, + "incorrect value for reserved[79], expected 43, is {}", + msg.reserved[79] + ); + assert_eq!( + msg.reserved[80], 210, + "incorrect value for reserved[80], expected 210, is {}", + msg.reserved[80] + ); + assert_eq!( + msg.reserved[81], 9, + "incorrect value for reserved[81], expected 9, is {}", + msg.reserved[81] + ); + assert_eq!( + msg.reserved[82], 32, + "incorrect value for reserved[82], expected 32, is {}", + msg.reserved[82] + ); + assert_eq!( + msg.reserved[83], 122, + "incorrect value for reserved[83], expected 122, is {}", + msg.reserved[83] + ); + assert_eq!( + msg.reserved[84], 29, + "incorrect value for reserved[84], expected 29, is {}", + msg.reserved[84] + ); + assert_eq!( + msg.reserved[85], 237, + "incorrect value for reserved[85], expected 237, is {}", + msg.reserved[85] + ); + assert_eq!( + msg.reserved[86], 11, + "incorrect value for reserved[86], expected 11, is {}", + msg.reserved[86] + ); + assert_eq!( + msg.reserved[87], 151, + "incorrect value for reserved[87], expected 151, is {}", + msg.reserved[87] + ); + assert_eq!( + msg.reserved[88], 223, + "incorrect value for reserved[88], expected 223, is {}", + msg.reserved[88] + ); + assert_eq!( + msg.reserved[89], 18, + "incorrect value for reserved[89], expected 18, is {}", + msg.reserved[89] + ); + assert_eq!( + msg.reserved[90], 81, + "incorrect value for reserved[90], expected 81, is {}", + msg.reserved[90] + ); + assert_eq!( + msg.reserved[91], 204, + "incorrect value for reserved[91], expected 204, is {}", + msg.reserved[91] + ); + assert_eq!( + msg.reserved[92], 172, + "incorrect value for reserved[92], expected 172, is {}", + msg.reserved[92] + ); + assert_eq!( + msg.reserved[93], 234, + "incorrect value for reserved[93], expected 234, is {}", + msg.reserved[93] + ); + assert_eq!( + msg.reserved[94], 127, + "incorrect value for reserved[94], expected 127, is {}", + msg.reserved[94] + ); + assert_eq!( + msg.reserved[95], 3, + "incorrect value for reserved[95], expected 3, is {}", + msg.reserved[95] + ); + assert_eq!( + msg.reserved[96], 82, + "incorrect value for reserved[96], expected 82, is {}", + msg.reserved[96] + ); + assert_eq!( + msg.reserved[97], 133, + "incorrect value for reserved[97], expected 133, is {}", + msg.reserved[97] + ); + assert_eq!( + msg.reserved[98], 169, + "incorrect value for reserved[98], expected 169, is {}", + msg.reserved[98] + ); + assert_eq!( + msg.reserved[99], 12, + "incorrect value for reserved[99], expected 12, is {}", + msg.reserved[99] + ); + assert_eq!( + msg.reserved[100], 176, + "incorrect value for reserved[100], expected 176, is {}", + msg.reserved[100] + ); + assert_eq!( + msg.reserved[101], 193, + "incorrect value for reserved[101], expected 193, is {}", + msg.reserved[101] + ); + assert_eq!( + msg.reserved[102], 0, + "incorrect value for reserved[102], expected 0, is {}", + msg.reserved[102] + ); + assert_eq!( + msg.reserved[103], 24, + "incorrect value for reserved[103], expected 24, is {}", + msg.reserved[103] + ); + assert_eq!( + msg.reserved[104], 121, + "incorrect value for reserved[104], expected 121, is {}", + msg.reserved[104] + ); + assert_eq!( + msg.reserved[105], 85, + "incorrect value for reserved[105], expected 85, is {}", + msg.reserved[105] + ); + assert_eq!( + msg.reserved[106], 55, + "incorrect value for reserved[106], expected 55, is {}", + msg.reserved[106] + ); + assert_eq!( + msg.reserved[107], 214, + "incorrect value for reserved[107], expected 214, is {}", + msg.reserved[107] + ); + assert_eq!( + msg.reserved[108], 198, + "incorrect value for reserved[108], expected 198, is {}", + msg.reserved[108] + ); + assert_eq!( + msg.reserved[109], 75, + "incorrect value for reserved[109], expected 75, is {}", + msg.reserved[109] + ); + assert_eq!( + msg.reserved[110], 234, + "incorrect value for reserved[110], expected 234, is {}", + msg.reserved[110] + ); + assert_eq!( + msg.reserved[111], 179, + "incorrect value for reserved[111], expected 179, is {}", + msg.reserved[111] + ); + assert_eq!( + msg.reserved[112], 214, + "incorrect value for reserved[112], expected 214, is {}", + msg.reserved[112] + ); + assert_eq!( + msg.reserved[113], 85, + "incorrect value for reserved[113], expected 85, is {}", + msg.reserved[113] + ); + assert_eq!( + msg.reserved[114], 94, + "incorrect value for reserved[114], expected 94, is {}", + msg.reserved[114] + ); + assert_eq!( + msg.reserved[115], 115, + "incorrect value for reserved[115], expected 115, is {}", + msg.reserved[115] + ); + assert_eq!( + msg.reserved[116], 21, + "incorrect value for reserved[116], expected 21, is {}", + msg.reserved[116] + ); + assert_eq!( + msg.reserved[117], 73, + "incorrect value for reserved[117], expected 73, is {}", + msg.reserved[117] + ); + assert_eq!( + msg.reserved[118], 121, + "incorrect value for reserved[118], expected 121, is {}", + msg.reserved[118] + ); + assert_eq!( + msg.reserved[119], 75, + "incorrect value for reserved[119], expected 75, is {}", + msg.reserved[119] + ); + assert_eq!( + msg.reserved[120], 46, + "incorrect value for reserved[120], expected 46, is {}", + msg.reserved[120] + ); + assert_eq!( + msg.reserved[121], 158, + "incorrect value for reserved[121], expected 158, is {}", + msg.reserved[121] + ); + assert_eq!( + msg.reserved[122], 63, + "incorrect value for reserved[122], expected 63, is {}", + msg.reserved[122] + ); + assert_eq!( + msg.reserved[123], 100, + "incorrect value for reserved[123], expected 100, is {}", + msg.reserved[123] + ); + assert_eq!( + msg.reserved[124], 122, + "incorrect value for reserved[124], expected 122, is {}", + msg.reserved[124] + ); + assert_eq!( + msg.reserved[125], 213, + "incorrect value for reserved[125], expected 213, is {}", + msg.reserved[125] + ); + assert_eq!( + msg.reserved[126], 20, + "incorrect value for reserved[126], expected 20, is {}", + msg.reserved[126] + ); + assert_eq!( + msg.reserved[127], 85, + "incorrect value for reserved[127], expected 85, is {}", + msg.reserved[127] + ); + assert_eq!( + msg.reserved[128], 212, + "incorrect value for reserved[128], expected 212, is {}", + msg.reserved[128] + ); + assert_eq!( + msg.reserved[129], 131, + "incorrect value for reserved[129], expected 131, is {}", + msg.reserved[129] + ); + assert_eq!( + msg.reserved[130], 50, + "incorrect value for reserved[130], expected 50, is {}", + msg.reserved[130] + ); + assert_eq!( + msg.reserved[131], 224, + "incorrect value for reserved[131], expected 224, is {}", + msg.reserved[131] + ); + assert_eq!( + msg.reserved[132], 218, + "incorrect value for reserved[132], expected 218, is {}", + msg.reserved[132] + ); + assert_eq!( + msg.reserved[133], 215, + "incorrect value for reserved[133], expected 215, is {}", + msg.reserved[133] + ); + assert_eq!( + msg.reserved[134], 215, + "incorrect value for reserved[134], expected 215, is {}", + msg.reserved[134] + ); + assert_eq!( + msg.reserved[135], 149, + "incorrect value for reserved[135], expected 149, is {}", + msg.reserved[135] + ); + assert_eq!( + msg.reserved[136], 2, + "incorrect value for reserved[136], expected 2, is {}", + msg.reserved[136] + ); + assert_eq!( + msg.reserved[137], 19, + "incorrect value for reserved[137], expected 19, is {}", + msg.reserved[137] + ); + assert_eq!( + msg.reserved[138], 129, + "incorrect value for reserved[138], expected 129, is {}", + msg.reserved[138] + ); + assert_eq!( + msg.reserved[139], 39, + "incorrect value for reserved[139], expected 39, is {}", + msg.reserved[139] + ); + assert_eq!( + msg.reserved[140], 164, + "incorrect value for reserved[140], expected 164, is {}", + msg.reserved[140] + ); + assert_eq!( + msg.reserved[141], 5, + "incorrect value for reserved[141], expected 5, is {}", + msg.reserved[141] + ); + assert_eq!( + msg.reserved[142], 175, + "incorrect value for reserved[142], expected 175, is {}", + msg.reserved[142] + ); + assert_eq!( + msg.reserved[143], 6, + "incorrect value for reserved[143], expected 6, is {}", + msg.reserved[143] + ); + assert_eq!( + msg.reserved[144], 62, + "incorrect value for reserved[144], expected 62, is {}", + msg.reserved[144] + ); + assert_eq!( + msg.reserved[145], 51, + "incorrect value for reserved[145], expected 51, is {}", + msg.reserved[145] + ); + assert_eq!( + msg.reserved[146], 78, + "incorrect value for reserved[146], expected 78, is {}", + msg.reserved[146] + ); + assert_eq!( + msg.reserved[147], 66, + "incorrect value for reserved[147], expected 66, is {}", + msg.reserved[147] + ); + assert_eq!( + msg.reserved[148], 248, + "incorrect value for reserved[148], expected 248, is {}", + msg.reserved[148] + ); + assert_eq!( + msg.reserved[149], 116, + "incorrect value for reserved[149], expected 116, is {}", + msg.reserved[149] + ); + assert_eq!( + msg.reserved[150], 88, + "incorrect value for reserved[150], expected 88, is {}", + msg.reserved[150] + ); + assert_eq!( + msg.reserved[151], 90, + "incorrect value for reserved[151], expected 90, is {}", + msg.reserved[151] + ); + assert_eq!( + msg.reserved[152], 128, + "incorrect value for reserved[152], expected 128, is {}", + msg.reserved[152] + ); + assert_eq!( + msg.reserved[153], 226, + "incorrect value for reserved[153], expected 226, is {}", + msg.reserved[153] + ); + assert_eq!( + msg.reserved[154], 177, + "incorrect value for reserved[154], expected 177, is {}", + msg.reserved[154] + ); + assert_eq!( + msg.reserved[155], 0, + "incorrect value for reserved[155], expected 0, is {}", + msg.reserved[155] + ); + assert_eq!( + msg.reserved[156], 47, + "incorrect value for reserved[156], expected 47, is {}", + msg.reserved[156] + ); + assert_eq!( + msg.reserved[157], 140, + "incorrect value for reserved[157], expected 140, is {}", + msg.reserved[157] + ); + assert_eq!( + msg.reserved[158], 33, + "incorrect value for reserved[158], expected 33, is {}", + msg.reserved[158] + ); + assert_eq!( + msg.reserved[159], 126, + "incorrect value for reserved[159], expected 126, is {}", + msg.reserved[159] + ); + assert_eq!( + msg.reserved[160], 221, + "incorrect value for reserved[160], expected 221, is {}", + msg.reserved[160] + ); + assert_eq!( + msg.reserved[161], 110, + "incorrect value for reserved[161], expected 110, is {}", + msg.reserved[161] + ); + assert_eq!( + msg.reserved[162], 144, + "incorrect value for reserved[162], expected 144, is {}", + msg.reserved[162] + ); + assert_eq!( + msg.reserved[163], 97, + "incorrect value for reserved[163], expected 97, is {}", + msg.reserved[163] + ); + assert_eq!( + msg.reserved[164], 74, + "incorrect value for reserved[164], expected 74, is {}", + msg.reserved[164] + ); + assert_eq!( + msg.reserved[165], 250, + "incorrect value for reserved[165], expected 250, is {}", + msg.reserved[165] + ); + assert_eq!( + msg.reserved[166], 181, + "incorrect value for reserved[166], expected 181, is {}", + msg.reserved[166] + ); + assert_eq!( + msg.reserved[167], 199, + "incorrect value for reserved[167], expected 199, is {}", + msg.reserved[167] + ); + assert_eq!( + msg.reserved[168], 27, + "incorrect value for reserved[168], expected 27, is {}", + msg.reserved[168] + ); + assert_eq!( + msg.reserved[169], 176, + "incorrect value for reserved[169], expected 176, is {}", + msg.reserved[169] + ); + assert_eq!( + msg.reserved[170], 65, + "incorrect value for reserved[170], expected 65, is {}", + msg.reserved[170] + ); + assert_eq!( + msg.reserved[171], 185, + "incorrect value for reserved[171], expected 185, is {}", + msg.reserved[171] + ); + assert_eq!( + msg.reserved[172], 110, + "incorrect value for reserved[172], expected 110, is {}", + msg.reserved[172] + ); + assert_eq!( + msg.reserved[173], 92, + "incorrect value for reserved[173], expected 92, is {}", + msg.reserved[173] + ); + assert_eq!( + msg.reserved[174], 34, + "incorrect value for reserved[174], expected 34, is {}", + msg.reserved[174] + ); + assert_eq!( + msg.reserved[175], 44, + "incorrect value for reserved[175], expected 44, is {}", + msg.reserved[175] + ); + assert_eq!( + msg.reserved[176], 131, + "incorrect value for reserved[176], expected 131, is {}", + msg.reserved[176] + ); + assert_eq!( + msg.reserved[177], 96, + "incorrect value for reserved[177], expected 96, is {}", + msg.reserved[177] + ); + assert_eq!( + msg.reserved[178], 178, + "incorrect value for reserved[178], expected 178, is {}", + msg.reserved[178] + ); + assert_eq!( + msg.reserved[179], 40, + "incorrect value for reserved[179], expected 40, is {}", + msg.reserved[179] + ); + assert_eq!( + msg.reserved[180], 176, + "incorrect value for reserved[180], expected 176, is {}", + msg.reserved[180] + ); + assert_eq!( + msg.reserved[181], 4, + "incorrect value for reserved[181], expected 4, is {}", + msg.reserved[181] + ); + assert_eq!( + msg.reserved[182], 90, + "incorrect value for reserved[182], expected 90, is {}", + msg.reserved[182] + ); + assert_eq!( + msg.reserved[183], 36, + "incorrect value for reserved[183], expected 36, is {}", + msg.reserved[183] + ); + assert_eq!( + msg.reserved[184], 7, + "incorrect value for reserved[184], expected 7, is {}", + msg.reserved[184] + ); + assert_eq!( + msg.reserved[185], 180, + "incorrect value for reserved[185], expected 180, is {}", + msg.reserved[185] + ); + assert_eq!( + msg.reserved[186], 244, + "incorrect value for reserved[186], expected 244, is {}", + msg.reserved[186] + ); + assert_eq!( + msg.reserved[187], 244, + "incorrect value for reserved[187], expected 244, is {}", + msg.reserved[187] + ); + assert_eq!( + msg.reserved[188], 23, + "incorrect value for reserved[188], expected 23, is {}", + msg.reserved[188] + ); + assert_eq!( + msg.reserved[189], 108, + "incorrect value for reserved[189], expected 108, is {}", + msg.reserved[189] + ); + assert_eq!( + msg.reserved[190], 171, + "incorrect value for reserved[190], expected 171, is {}", + msg.reserved[190] + ); + assert_eq!( + msg.reserved[191], 204, + "incorrect value for reserved[191], expected 204, is {}", + msg.reserved[191] + ); + assert_eq!( + msg.reserved[192], 196, + "incorrect value for reserved[192], expected 196, is {}", + msg.reserved[192] + ); + assert_eq!( + msg.reserved[193], 61, + "incorrect value for reserved[193], expected 61, is {}", + msg.reserved[193] + ); + assert_eq!( + msg.reserved[194], 51, + "incorrect value for reserved[194], expected 51, is {}", + msg.reserved[194] + ); + assert_eq!( + msg.reserved[195], 179, + "incorrect value for reserved[195], expected 179, is {}", + msg.reserved[195] + ); + assert_eq!( + msg.reserved[196], 242, + "incorrect value for reserved[196], expected 242, is {}", + msg.reserved[196] + ); + assert_eq!( + msg.reserved[197], 156, + "incorrect value for reserved[197], expected 156, is {}", + msg.reserved[197] + ); + assert_eq!( + msg.reserved[198], 81, + "incorrect value for reserved[198], expected 81, is {}", + msg.reserved[198] + ); + assert_eq!( + msg.reserved[199], 83, + "incorrect value for reserved[199], expected 83, is {}", + msg.reserved[199] + ); + assert_eq!( + msg.reserved[200], 16, + "incorrect value for reserved[200], expected 16, is {}", + msg.reserved[200] + ); + assert_eq!( + msg.reserved[201], 15, + "incorrect value for reserved[201], expected 15, is {}", + msg.reserved[201] + ); + assert_eq!( + msg.reserved[202], 134, + "incorrect value for reserved[202], expected 134, is {}", + msg.reserved[202] + ); + assert_eq!( + msg.reserved[203], 40, + "incorrect value for reserved[203], expected 40, is {}", + msg.reserved[203] + ); + assert_eq!( + msg.reserved[204], 245, + "incorrect value for reserved[204], expected 245, is {}", + msg.reserved[204] + ); + assert_eq!( + msg.reserved[205], 253, + "incorrect value for reserved[205], expected 253, is {}", + msg.reserved[205] + ); + assert_eq!( + msg.reserved[206], 150, + "incorrect value for reserved[206], expected 150, is {}", + msg.reserved[206] + ); + assert_eq!( + msg.reserved[207], 94, + "incorrect value for reserved[207], expected 94, is {}", + msg.reserved[207] + ); + assert_eq!( + msg.reserved[208], 150, + "incorrect value for reserved[208], expected 150, is {}", + msg.reserved[208] + ); + assert_eq!( + msg.reserved[209], 144, + "incorrect value for reserved[209], expected 144, is {}", + msg.reserved[209] + ); + assert_eq!( + msg.reserved[210], 197, + "incorrect value for reserved[210], expected 197, is {}", + msg.reserved[210] + ); + assert_eq!( + msg.reserved[211], 113, + "incorrect value for reserved[211], expected 113, is {}", + msg.reserved[211] + ); + assert_eq!( + msg.reserved[212], 5, + "incorrect value for reserved[212], expected 5, is {}", + msg.reserved[212] + ); + assert_eq!( + msg.reserved[213], 141, + "incorrect value for reserved[213], expected 141, is {}", + msg.reserved[213] + ); + assert_eq!( + msg.reserved[214], 232, + "incorrect value for reserved[214], expected 232, is {}", + msg.reserved[214] + ); + assert_eq!( + msg.reserved[215], 33, + "incorrect value for reserved[215], expected 33, is {}", + msg.reserved[215] + ); + assert_eq!( + msg.reserved[216], 101, + "incorrect value for reserved[216], expected 101, is {}", + msg.reserved[216] + ); + assert_eq!( + msg.reserved[217], 231, + "incorrect value for reserved[217], expected 231, is {}", + msg.reserved[217] + ); + assert_eq!( + msg.reserved[218], 38, + "incorrect value for reserved[218], expected 38, is {}", + msg.reserved[218] + ); + assert_eq!( + msg.reserved[219], 75, + "incorrect value for reserved[219], expected 75, is {}", + msg.reserved[219] + ); + assert_eq!( + msg.reserved[220], 178, + "incorrect value for reserved[220], expected 178, is {}", + msg.reserved[220] + ); + assert_eq!( + msg.reserved[221], 243, + "incorrect value for reserved[221], expected 243, is {}", + msg.reserved[221] + ); + assert_eq!( + msg.reserved[222], 119, + "incorrect value for reserved[222], expected 119, is {}", + msg.reserved[222] + ); + assert_eq!( + msg.reserved[223], 1, + "incorrect value for reserved[223], expected 1, is {}", + msg.reserved[223] + ); + assert_eq!( + msg.reserved[224], 248, + "incorrect value for reserved[224], expected 248, is {}", + msg.reserved[224] + ); + assert_eq!( + msg.reserved[225], 218, + "incorrect value for reserved[225], expected 218, is {}", + msg.reserved[225] + ); + assert_eq!( + msg.reserved[226], 86, + "incorrect value for reserved[226], expected 86, is {}", + msg.reserved[226] + ); + assert_eq!( + msg.reserved[227], 7, + "incorrect value for reserved[227], expected 7, is {}", + msg.reserved[227] + ); + assert_eq!( + msg.reserved[228], 88, + "incorrect value for reserved[228], expected 88, is {}", + msg.reserved[228] + ); + assert_eq!( + msg.reserved[229], 197, + "incorrect value for reserved[229], expected 197, is {}", + msg.reserved[229] + ); + assert_eq!( + msg.reserved[230], 148, + "incorrect value for reserved[230], expected 148, is {}", + msg.reserved[230] + ); + assert_eq!( + msg.reserved[231], 240, + "incorrect value for reserved[231], expected 240, is {}", + msg.reserved[231] + ); + assert_eq!( + msg.reserved[232], 227, + "incorrect value for reserved[232], expected 227, is {}", + msg.reserved[232] + ); + assert_eq!( + msg.reserved[233], 2, + "incorrect value for reserved[233], expected 2, is {}", + msg.reserved[233] + ); + assert_eq!( + msg.reserved[234], 65, + "incorrect value for reserved[234], expected 65, is {}", + msg.reserved[234] + ); + assert_eq!( + msg.reserved[235], 173, + "incorrect value for reserved[235], expected 173, is {}", + msg.reserved[235] + ); + assert_eq!( + msg.reserved[236], 122, + "incorrect value for reserved[236], expected 122, is {}", + msg.reserved[236] + ); + assert_eq!( + msg.reserved[237], 143, + "incorrect value for reserved[237], expected 143, is {}", + msg.reserved[237] + ); + assert_eq!( + msg.reserved[238], 251, + "incorrect value for reserved[238], expected 251, is {}", + msg.reserved[238] + ); + assert_eq!( + msg.reserved[239], 156, + "incorrect value for reserved[239], expected 156, is {}", + msg.reserved[239] + ); + assert_eq!( + msg.reserved[240], 217, + "incorrect value for reserved[240], expected 217, is {}", + msg.reserved[240] + ); + assert_eq!( + msg.reserved[241], 67, + "incorrect value for reserved[241], expected 67, is {}", + msg.reserved[241] + ); + assert_eq!( + msg.reserved[242], 239, + "incorrect value for reserved[242], expected 239, is {}", + msg.reserved[242] + ); + assert_eq!( + msg.reserved[243], 219, + "incorrect value for reserved[243], expected 219, is {}", + msg.reserved[243] + ); + assert_eq!( + msg.reserved[244], 31, + "incorrect value for reserved[244], expected 31, is {}", + msg.reserved[244] + ); + assert_eq!( + msg.reserved[245], 224, + "incorrect value for reserved[245], expected 224, is {}", + msg.reserved[245] + ); + assert_eq!( + msg.reserved[246], 176, + "incorrect value for reserved[246], expected 176, is {}", + msg.reserved[246] + ); + assert_eq!( + msg.reserved[247], 129, + "incorrect value for reserved[247], expected 129, is {}", + msg.reserved[247] + ); + assert_eq!( + msg.reserved[248], 81, + "incorrect value for reserved[248], expected 81, is {}", + msg.reserved[248] + ); + assert_eq!( + msg.reserved[249], 80, + "incorrect value for reserved[249], expected 80, is {}", + msg.reserved[249] + ); + assert!(msg.signal_error_rate.almost_eq( 8.58820019531250000e+03 ), "incorrect value for signal_error_rate, expected 8.58820019531250000e+03, is {:e}", msg.signal_error_rate); + assert_eq!( + msg.signal_strength, 103, + "incorrect value for signal_strength, expected 103, is {}", + msg.signal_strength + ); + } + _ => panic!("Invalid message type! Expected a MsgCellModemStatus"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_cell_modem_status`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_cell_modem_status() { + { + let mut payload = Cursor::new(vec![ + 85, 190, 0, 19, 27, 255, 103, 205, 48, 6, 70, 123, 242, 46, 52, 64, 176, 154, 98, 43, + 132, 196, 89, 253, 161, 250, 174, 204, 110, 47, 38, 187, 63, 102, 177, 162, 49, 80, + 194, 37, 107, 60, 225, 52, 101, 178, 142, 246, 21, 17, 93, 75, 169, 86, 16, 209, 80, + 243, 30, 206, 220, 206, 115, 47, 154, 91, 227, 88, 11, 1, 85, 146, 100, 190, 232, 207, + 61, 61, 201, 220, 31, 78, 34, 57, 82, 59, 104, 65, 221, 0, 43, 210, 9, 32, 122, 29, + 237, 11, 151, 223, 18, 81, 204, 172, 234, 127, 3, 82, 133, 169, 12, 176, 193, 0, 24, + 121, 85, 55, 214, 198, 75, 234, 179, 214, 85, 94, 115, 21, 73, 121, 75, 46, 158, 63, + 100, 122, 213, 20, 85, 212, 131, 50, 224, 218, 215, 215, 149, 2, 19, 129, 39, 164, 5, + 175, 6, 62, 51, 78, 66, 248, 116, 88, 90, 128, 226, 177, 0, 47, 140, 33, 126, 221, 110, + 144, 97, 74, 250, 181, 199, 27, 176, 65, 185, 110, 92, 34, 44, 131, 96, 178, 40, 176, + 4, 90, 36, 7, 180, 244, 244, 23, 108, 171, 204, 196, 61, 51, 179, 242, 156, 81, 83, 16, + 15, 134, 40, 245, 253, 150, 94, 150, 144, 197, 113, 5, 141, 232, 33, 101, 231, 38, 75, + 178, 243, 119, 1, 248, 218, 86, 7, 88, 197, 148, 240, 227, 2, 65, 173, 122, 143, 251, + 156, 217, 67, 239, 219, 31, 224, 176, 129, 81, 80, 40, 230, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCellModemStatus( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCellModemStatus(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbe, + "Incorrect message type, expected 0xbe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1b13, + "incorrect sender id, expected 0x1b13, is {sender_id}" + ); + assert_eq!( + msg.reserved[0], 123, + "incorrect value for reserved[0], expected 123, is {}", + msg.reserved[0] + ); + assert_eq!( + msg.reserved[1], 242, + "incorrect value for reserved[1], expected 242, is {}", + msg.reserved[1] + ); + assert_eq!( + msg.reserved[2], 46, + "incorrect value for reserved[2], expected 46, is {}", + msg.reserved[2] + ); + assert_eq!( + msg.reserved[3], 52, + "incorrect value for reserved[3], expected 52, is {}", + msg.reserved[3] + ); + assert_eq!( + msg.reserved[4], 64, + "incorrect value for reserved[4], expected 64, is {}", + msg.reserved[4] + ); + assert_eq!( + msg.reserved[5], 176, + "incorrect value for reserved[5], expected 176, is {}", + msg.reserved[5] + ); + assert_eq!( + msg.reserved[6], 154, + "incorrect value for reserved[6], expected 154, is {}", + msg.reserved[6] + ); + assert_eq!( + msg.reserved[7], 98, + "incorrect value for reserved[7], expected 98, is {}", + msg.reserved[7] + ); + assert_eq!( + msg.reserved[8], 43, + "incorrect value for reserved[8], expected 43, is {}", + msg.reserved[8] + ); + assert_eq!( + msg.reserved[9], 132, + "incorrect value for reserved[9], expected 132, is {}", + msg.reserved[9] + ); + assert_eq!( + msg.reserved[10], 196, + "incorrect value for reserved[10], expected 196, is {}", + msg.reserved[10] + ); + assert_eq!( + msg.reserved[11], 89, + "incorrect value for reserved[11], expected 89, is {}", + msg.reserved[11] + ); + assert_eq!( + msg.reserved[12], 253, + "incorrect value for reserved[12], expected 253, is {}", + msg.reserved[12] + ); + assert_eq!( + msg.reserved[13], 161, + "incorrect value for reserved[13], expected 161, is {}", + msg.reserved[13] + ); + assert_eq!( + msg.reserved[14], 250, + "incorrect value for reserved[14], expected 250, is {}", + msg.reserved[14] + ); + assert_eq!( + msg.reserved[15], 174, + "incorrect value for reserved[15], expected 174, is {}", + msg.reserved[15] + ); + assert_eq!( + msg.reserved[16], 204, + "incorrect value for reserved[16], expected 204, is {}", + msg.reserved[16] + ); + assert_eq!( + msg.reserved[17], 110, + "incorrect value for reserved[17], expected 110, is {}", + msg.reserved[17] + ); + assert_eq!( + msg.reserved[18], 47, + "incorrect value for reserved[18], expected 47, is {}", + msg.reserved[18] + ); + assert_eq!( + msg.reserved[19], 38, + "incorrect value for reserved[19], expected 38, is {}", + msg.reserved[19] + ); + assert_eq!( + msg.reserved[20], 187, + "incorrect value for reserved[20], expected 187, is {}", + msg.reserved[20] + ); + assert_eq!( + msg.reserved[21], 63, + "incorrect value for reserved[21], expected 63, is {}", + msg.reserved[21] + ); + assert_eq!( + msg.reserved[22], 102, + "incorrect value for reserved[22], expected 102, is {}", + msg.reserved[22] + ); + assert_eq!( + msg.reserved[23], 177, + "incorrect value for reserved[23], expected 177, is {}", + msg.reserved[23] + ); + assert_eq!( + msg.reserved[24], 162, + "incorrect value for reserved[24], expected 162, is {}", + msg.reserved[24] + ); + assert_eq!( + msg.reserved[25], 49, + "incorrect value for reserved[25], expected 49, is {}", + msg.reserved[25] + ); + assert_eq!( + msg.reserved[26], 80, + "incorrect value for reserved[26], expected 80, is {}", + msg.reserved[26] + ); + assert_eq!( + msg.reserved[27], 194, + "incorrect value for reserved[27], expected 194, is {}", + msg.reserved[27] + ); + assert_eq!( + msg.reserved[28], 37, + "incorrect value for reserved[28], expected 37, is {}", + msg.reserved[28] + ); + assert_eq!( + msg.reserved[29], 107, + "incorrect value for reserved[29], expected 107, is {}", + msg.reserved[29] + ); + assert_eq!( + msg.reserved[30], 60, + "incorrect value for reserved[30], expected 60, is {}", + msg.reserved[30] + ); + assert_eq!( + msg.reserved[31], 225, + "incorrect value for reserved[31], expected 225, is {}", + msg.reserved[31] + ); + assert_eq!( + msg.reserved[32], 52, + "incorrect value for reserved[32], expected 52, is {}", + msg.reserved[32] + ); + assert_eq!( + msg.reserved[33], 101, + "incorrect value for reserved[33], expected 101, is {}", + msg.reserved[33] + ); + assert_eq!( + msg.reserved[34], 178, + "incorrect value for reserved[34], expected 178, is {}", + msg.reserved[34] + ); + assert_eq!( + msg.reserved[35], 142, + "incorrect value for reserved[35], expected 142, is {}", + msg.reserved[35] + ); + assert_eq!( + msg.reserved[36], 246, + "incorrect value for reserved[36], expected 246, is {}", + msg.reserved[36] + ); + assert_eq!( + msg.reserved[37], 21, + "incorrect value for reserved[37], expected 21, is {}", + msg.reserved[37] + ); + assert_eq!( + msg.reserved[38], 17, + "incorrect value for reserved[38], expected 17, is {}", + msg.reserved[38] + ); + assert_eq!( + msg.reserved[39], 93, + "incorrect value for reserved[39], expected 93, is {}", + msg.reserved[39] + ); + assert_eq!( + msg.reserved[40], 75, + "incorrect value for reserved[40], expected 75, is {}", + msg.reserved[40] + ); + assert_eq!( + msg.reserved[41], 169, + "incorrect value for reserved[41], expected 169, is {}", + msg.reserved[41] + ); + assert_eq!( + msg.reserved[42], 86, + "incorrect value for reserved[42], expected 86, is {}", + msg.reserved[42] + ); + assert_eq!( + msg.reserved[43], 16, + "incorrect value for reserved[43], expected 16, is {}", + msg.reserved[43] + ); + assert_eq!( + msg.reserved[44], 209, + "incorrect value for reserved[44], expected 209, is {}", + msg.reserved[44] + ); + assert_eq!( + msg.reserved[45], 80, + "incorrect value for reserved[45], expected 80, is {}", + msg.reserved[45] + ); + assert_eq!( + msg.reserved[46], 243, + "incorrect value for reserved[46], expected 243, is {}", + msg.reserved[46] + ); + assert_eq!( + msg.reserved[47], 30, + "incorrect value for reserved[47], expected 30, is {}", + msg.reserved[47] + ); + assert_eq!( + msg.reserved[48], 206, + "incorrect value for reserved[48], expected 206, is {}", + msg.reserved[48] + ); + assert_eq!( + msg.reserved[49], 220, + "incorrect value for reserved[49], expected 220, is {}", + msg.reserved[49] + ); + assert_eq!( + msg.reserved[50], 206, + "incorrect value for reserved[50], expected 206, is {}", + msg.reserved[50] + ); + assert_eq!( + msg.reserved[51], 115, + "incorrect value for reserved[51], expected 115, is {}", + msg.reserved[51] + ); + assert_eq!( + msg.reserved[52], 47, + "incorrect value for reserved[52], expected 47, is {}", + msg.reserved[52] + ); + assert_eq!( + msg.reserved[53], 154, + "incorrect value for reserved[53], expected 154, is {}", + msg.reserved[53] + ); + assert_eq!( + msg.reserved[54], 91, + "incorrect value for reserved[54], expected 91, is {}", + msg.reserved[54] + ); + assert_eq!( + msg.reserved[55], 227, + "incorrect value for reserved[55], expected 227, is {}", + msg.reserved[55] + ); + assert_eq!( + msg.reserved[56], 88, + "incorrect value for reserved[56], expected 88, is {}", + msg.reserved[56] + ); + assert_eq!( + msg.reserved[57], 11, + "incorrect value for reserved[57], expected 11, is {}", + msg.reserved[57] + ); + assert_eq!( + msg.reserved[58], 1, + "incorrect value for reserved[58], expected 1, is {}", + msg.reserved[58] + ); + assert_eq!( + msg.reserved[59], 85, + "incorrect value for reserved[59], expected 85, is {}", + msg.reserved[59] + ); + assert_eq!( + msg.reserved[60], 146, + "incorrect value for reserved[60], expected 146, is {}", + msg.reserved[60] + ); + assert_eq!( + msg.reserved[61], 100, + "incorrect value for reserved[61], expected 100, is {}", + msg.reserved[61] + ); + assert_eq!( + msg.reserved[62], 190, + "incorrect value for reserved[62], expected 190, is {}", + msg.reserved[62] + ); + assert_eq!( + msg.reserved[63], 232, + "incorrect value for reserved[63], expected 232, is {}", + msg.reserved[63] + ); + assert_eq!( + msg.reserved[64], 207, + "incorrect value for reserved[64], expected 207, is {}", + msg.reserved[64] + ); + assert_eq!( + msg.reserved[65], 61, + "incorrect value for reserved[65], expected 61, is {}", + msg.reserved[65] + ); + assert_eq!( + msg.reserved[66], 61, + "incorrect value for reserved[66], expected 61, is {}", + msg.reserved[66] + ); + assert_eq!( + msg.reserved[67], 201, + "incorrect value for reserved[67], expected 201, is {}", + msg.reserved[67] + ); + assert_eq!( + msg.reserved[68], 220, + "incorrect value for reserved[68], expected 220, is {}", + msg.reserved[68] + ); + assert_eq!( + msg.reserved[69], 31, + "incorrect value for reserved[69], expected 31, is {}", + msg.reserved[69] + ); + assert_eq!( + msg.reserved[70], 78, + "incorrect value for reserved[70], expected 78, is {}", + msg.reserved[70] + ); + assert_eq!( + msg.reserved[71], 34, + "incorrect value for reserved[71], expected 34, is {}", + msg.reserved[71] + ); + assert_eq!( + msg.reserved[72], 57, + "incorrect value for reserved[72], expected 57, is {}", + msg.reserved[72] + ); + assert_eq!( + msg.reserved[73], 82, + "incorrect value for reserved[73], expected 82, is {}", + msg.reserved[73] + ); + assert_eq!( + msg.reserved[74], 59, + "incorrect value for reserved[74], expected 59, is {}", + msg.reserved[74] + ); + assert_eq!( + msg.reserved[75], 104, + "incorrect value for reserved[75], expected 104, is {}", + msg.reserved[75] + ); + assert_eq!( + msg.reserved[76], 65, + "incorrect value for reserved[76], expected 65, is {}", + msg.reserved[76] + ); + assert_eq!( + msg.reserved[77], 221, + "incorrect value for reserved[77], expected 221, is {}", + msg.reserved[77] + ); + assert_eq!( + msg.reserved[78], 0, + "incorrect value for reserved[78], expected 0, is {}", + msg.reserved[78] + ); + assert_eq!( + msg.reserved[79], 43, + "incorrect value for reserved[79], expected 43, is {}", + msg.reserved[79] + ); + assert_eq!( + msg.reserved[80], 210, + "incorrect value for reserved[80], expected 210, is {}", + msg.reserved[80] + ); + assert_eq!( + msg.reserved[81], 9, + "incorrect value for reserved[81], expected 9, is {}", + msg.reserved[81] + ); + assert_eq!( + msg.reserved[82], 32, + "incorrect value for reserved[82], expected 32, is {}", + msg.reserved[82] + ); + assert_eq!( + msg.reserved[83], 122, + "incorrect value for reserved[83], expected 122, is {}", + msg.reserved[83] + ); + assert_eq!( + msg.reserved[84], 29, + "incorrect value for reserved[84], expected 29, is {}", + msg.reserved[84] + ); + assert_eq!( + msg.reserved[85], 237, + "incorrect value for reserved[85], expected 237, is {}", + msg.reserved[85] + ); + assert_eq!( + msg.reserved[86], 11, + "incorrect value for reserved[86], expected 11, is {}", + msg.reserved[86] + ); + assert_eq!( + msg.reserved[87], 151, + "incorrect value for reserved[87], expected 151, is {}", + msg.reserved[87] + ); + assert_eq!( + msg.reserved[88], 223, + "incorrect value for reserved[88], expected 223, is {}", + msg.reserved[88] + ); + assert_eq!( + msg.reserved[89], 18, + "incorrect value for reserved[89], expected 18, is {}", + msg.reserved[89] + ); + assert_eq!( + msg.reserved[90], 81, + "incorrect value for reserved[90], expected 81, is {}", + msg.reserved[90] + ); + assert_eq!( + msg.reserved[91], 204, + "incorrect value for reserved[91], expected 204, is {}", + msg.reserved[91] + ); + assert_eq!( + msg.reserved[92], 172, + "incorrect value for reserved[92], expected 172, is {}", + msg.reserved[92] + ); + assert_eq!( + msg.reserved[93], 234, + "incorrect value for reserved[93], expected 234, is {}", + msg.reserved[93] + ); + assert_eq!( + msg.reserved[94], 127, + "incorrect value for reserved[94], expected 127, is {}", + msg.reserved[94] + ); + assert_eq!( + msg.reserved[95], 3, + "incorrect value for reserved[95], expected 3, is {}", + msg.reserved[95] + ); + assert_eq!( + msg.reserved[96], 82, + "incorrect value for reserved[96], expected 82, is {}", + msg.reserved[96] + ); + assert_eq!( + msg.reserved[97], 133, + "incorrect value for reserved[97], expected 133, is {}", + msg.reserved[97] + ); + assert_eq!( + msg.reserved[98], 169, + "incorrect value for reserved[98], expected 169, is {}", + msg.reserved[98] + ); + assert_eq!( + msg.reserved[99], 12, + "incorrect value for reserved[99], expected 12, is {}", + msg.reserved[99] + ); + assert_eq!( + msg.reserved[100], 176, + "incorrect value for reserved[100], expected 176, is {}", + msg.reserved[100] + ); + assert_eq!( + msg.reserved[101], 193, + "incorrect value for reserved[101], expected 193, is {}", + msg.reserved[101] + ); + assert_eq!( + msg.reserved[102], 0, + "incorrect value for reserved[102], expected 0, is {}", + msg.reserved[102] + ); + assert_eq!( + msg.reserved[103], 24, + "incorrect value for reserved[103], expected 24, is {}", + msg.reserved[103] + ); + assert_eq!( + msg.reserved[104], 121, + "incorrect value for reserved[104], expected 121, is {}", + msg.reserved[104] + ); + assert_eq!( + msg.reserved[105], 85, + "incorrect value for reserved[105], expected 85, is {}", + msg.reserved[105] + ); + assert_eq!( + msg.reserved[106], 55, + "incorrect value for reserved[106], expected 55, is {}", + msg.reserved[106] + ); + assert_eq!( + msg.reserved[107], 214, + "incorrect value for reserved[107], expected 214, is {}", + msg.reserved[107] + ); + assert_eq!( + msg.reserved[108], 198, + "incorrect value for reserved[108], expected 198, is {}", + msg.reserved[108] + ); + assert_eq!( + msg.reserved[109], 75, + "incorrect value for reserved[109], expected 75, is {}", + msg.reserved[109] + ); + assert_eq!( + msg.reserved[110], 234, + "incorrect value for reserved[110], expected 234, is {}", + msg.reserved[110] + ); + assert_eq!( + msg.reserved[111], 179, + "incorrect value for reserved[111], expected 179, is {}", + msg.reserved[111] + ); + assert_eq!( + msg.reserved[112], 214, + "incorrect value for reserved[112], expected 214, is {}", + msg.reserved[112] + ); + assert_eq!( + msg.reserved[113], 85, + "incorrect value for reserved[113], expected 85, is {}", + msg.reserved[113] + ); + assert_eq!( + msg.reserved[114], 94, + "incorrect value for reserved[114], expected 94, is {}", + msg.reserved[114] + ); + assert_eq!( + msg.reserved[115], 115, + "incorrect value for reserved[115], expected 115, is {}", + msg.reserved[115] + ); + assert_eq!( + msg.reserved[116], 21, + "incorrect value for reserved[116], expected 21, is {}", + msg.reserved[116] + ); + assert_eq!( + msg.reserved[117], 73, + "incorrect value for reserved[117], expected 73, is {}", + msg.reserved[117] + ); + assert_eq!( + msg.reserved[118], 121, + "incorrect value for reserved[118], expected 121, is {}", + msg.reserved[118] + ); + assert_eq!( + msg.reserved[119], 75, + "incorrect value for reserved[119], expected 75, is {}", + msg.reserved[119] + ); + assert_eq!( + msg.reserved[120], 46, + "incorrect value for reserved[120], expected 46, is {}", + msg.reserved[120] + ); + assert_eq!( + msg.reserved[121], 158, + "incorrect value for reserved[121], expected 158, is {}", + msg.reserved[121] + ); + assert_eq!( + msg.reserved[122], 63, + "incorrect value for reserved[122], expected 63, is {}", + msg.reserved[122] + ); + assert_eq!( + msg.reserved[123], 100, + "incorrect value for reserved[123], expected 100, is {}", + msg.reserved[123] + ); + assert_eq!( + msg.reserved[124], 122, + "incorrect value for reserved[124], expected 122, is {}", + msg.reserved[124] + ); + assert_eq!( + msg.reserved[125], 213, + "incorrect value for reserved[125], expected 213, is {}", + msg.reserved[125] + ); + assert_eq!( + msg.reserved[126], 20, + "incorrect value for reserved[126], expected 20, is {}", + msg.reserved[126] + ); + assert_eq!( + msg.reserved[127], 85, + "incorrect value for reserved[127], expected 85, is {}", + msg.reserved[127] + ); + assert_eq!( + msg.reserved[128], 212, + "incorrect value for reserved[128], expected 212, is {}", + msg.reserved[128] + ); + assert_eq!( + msg.reserved[129], 131, + "incorrect value for reserved[129], expected 131, is {}", + msg.reserved[129] + ); + assert_eq!( + msg.reserved[130], 50, + "incorrect value for reserved[130], expected 50, is {}", + msg.reserved[130] + ); + assert_eq!( + msg.reserved[131], 224, + "incorrect value for reserved[131], expected 224, is {}", + msg.reserved[131] + ); + assert_eq!( + msg.reserved[132], 218, + "incorrect value for reserved[132], expected 218, is {}", + msg.reserved[132] + ); + assert_eq!( + msg.reserved[133], 215, + "incorrect value for reserved[133], expected 215, is {}", + msg.reserved[133] + ); + assert_eq!( + msg.reserved[134], 215, + "incorrect value for reserved[134], expected 215, is {}", + msg.reserved[134] + ); + assert_eq!( + msg.reserved[135], 149, + "incorrect value for reserved[135], expected 149, is {}", + msg.reserved[135] + ); + assert_eq!( + msg.reserved[136], 2, + "incorrect value for reserved[136], expected 2, is {}", + msg.reserved[136] + ); + assert_eq!( + msg.reserved[137], 19, + "incorrect value for reserved[137], expected 19, is {}", + msg.reserved[137] + ); + assert_eq!( + msg.reserved[138], 129, + "incorrect value for reserved[138], expected 129, is {}", + msg.reserved[138] + ); + assert_eq!( + msg.reserved[139], 39, + "incorrect value for reserved[139], expected 39, is {}", + msg.reserved[139] + ); + assert_eq!( + msg.reserved[140], 164, + "incorrect value for reserved[140], expected 164, is {}", + msg.reserved[140] + ); + assert_eq!( + msg.reserved[141], 5, + "incorrect value for reserved[141], expected 5, is {}", + msg.reserved[141] + ); + assert_eq!( + msg.reserved[142], 175, + "incorrect value for reserved[142], expected 175, is {}", + msg.reserved[142] + ); + assert_eq!( + msg.reserved[143], 6, + "incorrect value for reserved[143], expected 6, is {}", + msg.reserved[143] + ); + assert_eq!( + msg.reserved[144], 62, + "incorrect value for reserved[144], expected 62, is {}", + msg.reserved[144] + ); + assert_eq!( + msg.reserved[145], 51, + "incorrect value for reserved[145], expected 51, is {}", + msg.reserved[145] + ); + assert_eq!( + msg.reserved[146], 78, + "incorrect value for reserved[146], expected 78, is {}", + msg.reserved[146] + ); + assert_eq!( + msg.reserved[147], 66, + "incorrect value for reserved[147], expected 66, is {}", + msg.reserved[147] + ); + assert_eq!( + msg.reserved[148], 248, + "incorrect value for reserved[148], expected 248, is {}", + msg.reserved[148] + ); + assert_eq!( + msg.reserved[149], 116, + "incorrect value for reserved[149], expected 116, is {}", + msg.reserved[149] + ); + assert_eq!( + msg.reserved[150], 88, + "incorrect value for reserved[150], expected 88, is {}", + msg.reserved[150] + ); + assert_eq!( + msg.reserved[151], 90, + "incorrect value for reserved[151], expected 90, is {}", + msg.reserved[151] + ); + assert_eq!( + msg.reserved[152], 128, + "incorrect value for reserved[152], expected 128, is {}", + msg.reserved[152] + ); + assert_eq!( + msg.reserved[153], 226, + "incorrect value for reserved[153], expected 226, is {}", + msg.reserved[153] + ); + assert_eq!( + msg.reserved[154], 177, + "incorrect value for reserved[154], expected 177, is {}", + msg.reserved[154] + ); + assert_eq!( + msg.reserved[155], 0, + "incorrect value for reserved[155], expected 0, is {}", + msg.reserved[155] + ); + assert_eq!( + msg.reserved[156], 47, + "incorrect value for reserved[156], expected 47, is {}", + msg.reserved[156] + ); + assert_eq!( + msg.reserved[157], 140, + "incorrect value for reserved[157], expected 140, is {}", + msg.reserved[157] + ); + assert_eq!( + msg.reserved[158], 33, + "incorrect value for reserved[158], expected 33, is {}", + msg.reserved[158] + ); + assert_eq!( + msg.reserved[159], 126, + "incorrect value for reserved[159], expected 126, is {}", + msg.reserved[159] + ); + assert_eq!( + msg.reserved[160], 221, + "incorrect value for reserved[160], expected 221, is {}", + msg.reserved[160] + ); + assert_eq!( + msg.reserved[161], 110, + "incorrect value for reserved[161], expected 110, is {}", + msg.reserved[161] + ); + assert_eq!( + msg.reserved[162], 144, + "incorrect value for reserved[162], expected 144, is {}", + msg.reserved[162] + ); + assert_eq!( + msg.reserved[163], 97, + "incorrect value for reserved[163], expected 97, is {}", + msg.reserved[163] + ); + assert_eq!( + msg.reserved[164], 74, + "incorrect value for reserved[164], expected 74, is {}", + msg.reserved[164] + ); + assert_eq!( + msg.reserved[165], 250, + "incorrect value for reserved[165], expected 250, is {}", + msg.reserved[165] + ); + assert_eq!( + msg.reserved[166], 181, + "incorrect value for reserved[166], expected 181, is {}", + msg.reserved[166] + ); + assert_eq!( + msg.reserved[167], 199, + "incorrect value for reserved[167], expected 199, is {}", + msg.reserved[167] + ); + assert_eq!( + msg.reserved[168], 27, + "incorrect value for reserved[168], expected 27, is {}", + msg.reserved[168] + ); + assert_eq!( + msg.reserved[169], 176, + "incorrect value for reserved[169], expected 176, is {}", + msg.reserved[169] + ); + assert_eq!( + msg.reserved[170], 65, + "incorrect value for reserved[170], expected 65, is {}", + msg.reserved[170] + ); + assert_eq!( + msg.reserved[171], 185, + "incorrect value for reserved[171], expected 185, is {}", + msg.reserved[171] + ); + assert_eq!( + msg.reserved[172], 110, + "incorrect value for reserved[172], expected 110, is {}", + msg.reserved[172] + ); + assert_eq!( + msg.reserved[173], 92, + "incorrect value for reserved[173], expected 92, is {}", + msg.reserved[173] + ); + assert_eq!( + msg.reserved[174], 34, + "incorrect value for reserved[174], expected 34, is {}", + msg.reserved[174] + ); + assert_eq!( + msg.reserved[175], 44, + "incorrect value for reserved[175], expected 44, is {}", + msg.reserved[175] + ); + assert_eq!( + msg.reserved[176], 131, + "incorrect value for reserved[176], expected 131, is {}", + msg.reserved[176] + ); + assert_eq!( + msg.reserved[177], 96, + "incorrect value for reserved[177], expected 96, is {}", + msg.reserved[177] + ); + assert_eq!( + msg.reserved[178], 178, + "incorrect value for reserved[178], expected 178, is {}", + msg.reserved[178] + ); + assert_eq!( + msg.reserved[179], 40, + "incorrect value for reserved[179], expected 40, is {}", + msg.reserved[179] + ); + assert_eq!( + msg.reserved[180], 176, + "incorrect value for reserved[180], expected 176, is {}", + msg.reserved[180] + ); + assert_eq!( + msg.reserved[181], 4, + "incorrect value for reserved[181], expected 4, is {}", + msg.reserved[181] + ); + assert_eq!( + msg.reserved[182], 90, + "incorrect value for reserved[182], expected 90, is {}", + msg.reserved[182] + ); + assert_eq!( + msg.reserved[183], 36, + "incorrect value for reserved[183], expected 36, is {}", + msg.reserved[183] + ); + assert_eq!( + msg.reserved[184], 7, + "incorrect value for reserved[184], expected 7, is {}", + msg.reserved[184] + ); + assert_eq!( + msg.reserved[185], 180, + "incorrect value for reserved[185], expected 180, is {}", + msg.reserved[185] + ); + assert_eq!( + msg.reserved[186], 244, + "incorrect value for reserved[186], expected 244, is {}", + msg.reserved[186] + ); + assert_eq!( + msg.reserved[187], 244, + "incorrect value for reserved[187], expected 244, is {}", + msg.reserved[187] + ); + assert_eq!( + msg.reserved[188], 23, + "incorrect value for reserved[188], expected 23, is {}", + msg.reserved[188] + ); + assert_eq!( + msg.reserved[189], 108, + "incorrect value for reserved[189], expected 108, is {}", + msg.reserved[189] + ); + assert_eq!( + msg.reserved[190], 171, + "incorrect value for reserved[190], expected 171, is {}", + msg.reserved[190] + ); + assert_eq!( + msg.reserved[191], 204, + "incorrect value for reserved[191], expected 204, is {}", + msg.reserved[191] + ); + assert_eq!( + msg.reserved[192], 196, + "incorrect value for reserved[192], expected 196, is {}", + msg.reserved[192] + ); + assert_eq!( + msg.reserved[193], 61, + "incorrect value for reserved[193], expected 61, is {}", + msg.reserved[193] + ); + assert_eq!( + msg.reserved[194], 51, + "incorrect value for reserved[194], expected 51, is {}", + msg.reserved[194] + ); + assert_eq!( + msg.reserved[195], 179, + "incorrect value for reserved[195], expected 179, is {}", + msg.reserved[195] + ); + assert_eq!( + msg.reserved[196], 242, + "incorrect value for reserved[196], expected 242, is {}", + msg.reserved[196] + ); + assert_eq!( + msg.reserved[197], 156, + "incorrect value for reserved[197], expected 156, is {}", + msg.reserved[197] + ); + assert_eq!( + msg.reserved[198], 81, + "incorrect value for reserved[198], expected 81, is {}", + msg.reserved[198] + ); + assert_eq!( + msg.reserved[199], 83, + "incorrect value for reserved[199], expected 83, is {}", + msg.reserved[199] + ); + assert_eq!( + msg.reserved[200], 16, + "incorrect value for reserved[200], expected 16, is {}", + msg.reserved[200] + ); + assert_eq!( + msg.reserved[201], 15, + "incorrect value for reserved[201], expected 15, is {}", + msg.reserved[201] + ); + assert_eq!( + msg.reserved[202], 134, + "incorrect value for reserved[202], expected 134, is {}", + msg.reserved[202] + ); + assert_eq!( + msg.reserved[203], 40, + "incorrect value for reserved[203], expected 40, is {}", + msg.reserved[203] + ); + assert_eq!( + msg.reserved[204], 245, + "incorrect value for reserved[204], expected 245, is {}", + msg.reserved[204] + ); + assert_eq!( + msg.reserved[205], 253, + "incorrect value for reserved[205], expected 253, is {}", + msg.reserved[205] + ); + assert_eq!( + msg.reserved[206], 150, + "incorrect value for reserved[206], expected 150, is {}", + msg.reserved[206] + ); + assert_eq!( + msg.reserved[207], 94, + "incorrect value for reserved[207], expected 94, is {}", + msg.reserved[207] + ); + assert_eq!( + msg.reserved[208], 150, + "incorrect value for reserved[208], expected 150, is {}", + msg.reserved[208] + ); + assert_eq!( + msg.reserved[209], 144, + "incorrect value for reserved[209], expected 144, is {}", + msg.reserved[209] + ); + assert_eq!( + msg.reserved[210], 197, + "incorrect value for reserved[210], expected 197, is {}", + msg.reserved[210] + ); + assert_eq!( + msg.reserved[211], 113, + "incorrect value for reserved[211], expected 113, is {}", + msg.reserved[211] + ); + assert_eq!( + msg.reserved[212], 5, + "incorrect value for reserved[212], expected 5, is {}", + msg.reserved[212] + ); + assert_eq!( + msg.reserved[213], 141, + "incorrect value for reserved[213], expected 141, is {}", + msg.reserved[213] + ); + assert_eq!( + msg.reserved[214], 232, + "incorrect value for reserved[214], expected 232, is {}", + msg.reserved[214] + ); + assert_eq!( + msg.reserved[215], 33, + "incorrect value for reserved[215], expected 33, is {}", + msg.reserved[215] + ); + assert_eq!( + msg.reserved[216], 101, + "incorrect value for reserved[216], expected 101, is {}", + msg.reserved[216] + ); + assert_eq!( + msg.reserved[217], 231, + "incorrect value for reserved[217], expected 231, is {}", + msg.reserved[217] + ); + assert_eq!( + msg.reserved[218], 38, + "incorrect value for reserved[218], expected 38, is {}", + msg.reserved[218] + ); + assert_eq!( + msg.reserved[219], 75, + "incorrect value for reserved[219], expected 75, is {}", + msg.reserved[219] + ); + assert_eq!( + msg.reserved[220], 178, + "incorrect value for reserved[220], expected 178, is {}", + msg.reserved[220] + ); + assert_eq!( + msg.reserved[221], 243, + "incorrect value for reserved[221], expected 243, is {}", + msg.reserved[221] + ); + assert_eq!( + msg.reserved[222], 119, + "incorrect value for reserved[222], expected 119, is {}", + msg.reserved[222] + ); + assert_eq!( + msg.reserved[223], 1, + "incorrect value for reserved[223], expected 1, is {}", + msg.reserved[223] + ); + assert_eq!( + msg.reserved[224], 248, + "incorrect value for reserved[224], expected 248, is {}", + msg.reserved[224] + ); + assert_eq!( + msg.reserved[225], 218, + "incorrect value for reserved[225], expected 218, is {}", + msg.reserved[225] + ); + assert_eq!( + msg.reserved[226], 86, + "incorrect value for reserved[226], expected 86, is {}", + msg.reserved[226] + ); + assert_eq!( + msg.reserved[227], 7, + "incorrect value for reserved[227], expected 7, is {}", + msg.reserved[227] + ); + assert_eq!( + msg.reserved[228], 88, + "incorrect value for reserved[228], expected 88, is {}", + msg.reserved[228] + ); + assert_eq!( + msg.reserved[229], 197, + "incorrect value for reserved[229], expected 197, is {}", + msg.reserved[229] + ); + assert_eq!( + msg.reserved[230], 148, + "incorrect value for reserved[230], expected 148, is {}", + msg.reserved[230] + ); + assert_eq!( + msg.reserved[231], 240, + "incorrect value for reserved[231], expected 240, is {}", + msg.reserved[231] + ); + assert_eq!( + msg.reserved[232], 227, + "incorrect value for reserved[232], expected 227, is {}", + msg.reserved[232] + ); + assert_eq!( + msg.reserved[233], 2, + "incorrect value for reserved[233], expected 2, is {}", + msg.reserved[233] + ); + assert_eq!( + msg.reserved[234], 65, + "incorrect value for reserved[234], expected 65, is {}", + msg.reserved[234] + ); + assert_eq!( + msg.reserved[235], 173, + "incorrect value for reserved[235], expected 173, is {}", + msg.reserved[235] + ); + assert_eq!( + msg.reserved[236], 122, + "incorrect value for reserved[236], expected 122, is {}", + msg.reserved[236] + ); + assert_eq!( + msg.reserved[237], 143, + "incorrect value for reserved[237], expected 143, is {}", + msg.reserved[237] + ); + assert_eq!( + msg.reserved[238], 251, + "incorrect value for reserved[238], expected 251, is {}", + msg.reserved[238] + ); + assert_eq!( + msg.reserved[239], 156, + "incorrect value for reserved[239], expected 156, is {}", + msg.reserved[239] + ); + assert_eq!( + msg.reserved[240], 217, + "incorrect value for reserved[240], expected 217, is {}", + msg.reserved[240] + ); + assert_eq!( + msg.reserved[241], 67, + "incorrect value for reserved[241], expected 67, is {}", + msg.reserved[241] + ); + assert_eq!( + msg.reserved[242], 239, + "incorrect value for reserved[242], expected 239, is {}", + msg.reserved[242] + ); + assert_eq!( + msg.reserved[243], 219, + "incorrect value for reserved[243], expected 219, is {}", + msg.reserved[243] + ); + assert_eq!( + msg.reserved[244], 31, + "incorrect value for reserved[244], expected 31, is {}", + msg.reserved[244] + ); + assert_eq!( + msg.reserved[245], 224, + "incorrect value for reserved[245], expected 224, is {}", + msg.reserved[245] + ); + assert_eq!( + msg.reserved[246], 176, + "incorrect value for reserved[246], expected 176, is {}", + msg.reserved[246] + ); + assert_eq!( + msg.reserved[247], 129, + "incorrect value for reserved[247], expected 129, is {}", + msg.reserved[247] + ); + assert_eq!( + msg.reserved[248], 81, + "incorrect value for reserved[248], expected 81, is {}", + msg.reserved[248] + ); + assert_eq!( + msg.reserved[249], 80, + "incorrect value for reserved[249], expected 80, is {}", + msg.reserved[249] + ); + assert!(msg.signal_error_rate.almost_eq( 8.58820019531250000e+03 ), "incorrect value for signal_error_rate, expected 8.58820019531250000e+03, is {:e}", msg.signal_error_rate); + assert_eq!( + msg.signal_strength, 103, + "incorrect value for signal_strength, expected 103, is {}", + msg.signal_strength + ); + } + _ => panic!("Invalid message type! Expected a MsgCellModemStatus"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_output.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_output.rs new file mode 100644 index 0000000000..28f1f815d0 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_output.rs @@ -0,0 +1,205 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_command_output() { + { + let mut payload = Cursor::new(vec![ + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, 32, 111, 117, 116, 112, + 117, 116, 32, 116, 101, 120, 116, 11, 109, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandOutput(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbc, + "Incorrect message type, expected 0xbc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5432, + "incorrect sender id, expected 0x5432, is {sender_id}" + ); + assert_eq!( + msg.line.as_bytes(), + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + "incorrect value for msg.line, expected string '{:?}', is '{:?}'", + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + msg.line.as_bytes() + ); + assert_eq!( + msg.sequence, 2507449470, + "incorrect value for sequence, expected 2507449470, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandOutput"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_command_output() { + { + let json_input = r#"{"crc":27915,"length":20,"msg_type":188,"payload":"fqR0lVNvbWUgb3V0cHV0IHRleHQ=","preamble":85,"sender":21554,"sequence":2507449470,"line":"Some output text"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandOutput(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbc, + "Incorrect message type, expected 0xbc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5432, + "incorrect sender id, expected 0x5432, is {sender_id}" + ); + assert_eq!( + msg.line.as_bytes(), + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + "incorrect value for msg.line, expected string '{:?}', is '{:?}'", + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + msg.line.as_bytes() + ); + assert_eq!( + msg.sequence, 2507449470, + "incorrect value for sequence, expected 2507449470, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandOutput"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_command_output`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_command_output() { + { + let mut payload = Cursor::new(vec![ + 85, 188, 0, 50, 84, 20, 126, 164, 116, 149, 83, 111, 109, 101, 32, 111, 117, 116, 112, + 117, 116, 32, 116, 101, 120, 116, 11, 109, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCommandOutput( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCommandOutput(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbc, + "Incorrect message type, expected 0xbc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5432, + "incorrect sender id, expected 0x5432, is {sender_id}" + ); + assert_eq!( + msg.line.as_bytes(), + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + "incorrect value for msg.line, expected string '{:?}', is '{:?}'", + &[83, 111, 109, 101, 32, 111, 117, 116, 112, 117, 116, 32, 116, 101, 120, 116], + msg.line.as_bytes() + ); + assert_eq!( + msg.sequence, 2507449470, + "incorrect value for sequence, expected 2507449470, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandOutput"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_req.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_req.rs new file mode 100644 index 0000000000..34eb60a5e2 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_req.rs @@ -0,0 +1,225 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_command_req() { + { + let mut payload = Cursor::new(vec![ + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 99, 111, 109, 109, 97, 110, 100, 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, + 24, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb8, + "Incorrect message type, expected 0xb8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb8aa, + "incorrect sender id, expected 0xb8aa, is {sender_id}" + ); + assert_eq!( + msg.command.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + "incorrect value for msg.command, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + msg.command.as_bytes() + ); + assert_eq!( + msg.sequence, 1755532595, + "incorrect value for sequence, expected 1755532595, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_command_req() { + { + let json_input = r#"{"crc":6182,"length":31,"msg_type":184,"payload":"M02jaC9wYXRoL3RvL2NvbW1hbmQgd2l0aCBhcmdzAA==","preamble":85,"sender":47274,"sequence":1755532595,"command":"/path/to/command with args\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb8, + "Incorrect message type, expected 0xb8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb8aa, + "incorrect sender id, expected 0xb8aa, is {sender_id}" + ); + assert_eq!( + msg.command.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + "incorrect value for msg.command, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + msg.command.as_bytes() + ); + assert_eq!( + msg.sequence, 1755532595, + "incorrect value for sequence, expected 1755532595, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_command_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_command_req() { + { + let mut payload = Cursor::new(vec![ + 85, 184, 0, 170, 184, 31, 51, 77, 163, 104, 47, 112, 97, 116, 104, 47, 116, 111, 47, + 99, 111, 109, 109, 97, 110, 100, 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0, 38, + 24, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCommandReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCommandReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb8, + "Incorrect message type, expected 0xb8, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb8aa, + "incorrect sender id, expected 0xb8aa, is {sender_id}" + ); + assert_eq!( + msg.command.as_bytes(), + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + "incorrect value for msg.command, expected string '{:?}', is '{:?}'", + &[ + 47, 112, 97, 116, 104, 47, 116, 111, 47, 99, 111, 109, 109, 97, 110, 100, + 32, 119, 105, 116, 104, 32, 97, 114, 103, 115, 0 + ], + msg.command.as_bytes() + ); + assert_eq!( + msg.sequence, 1755532595, + "incorrect value for sequence, expected 1755532595, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_resp.rs new file mode 100644 index 0000000000..a5dcf0ce59 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_command_resp.rs @@ -0,0 +1,197 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_command_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 185, 0, 57, 206, 8, 118, 215, 131, 160, 210, 110, 150, 103, 164, 240, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb9, + "Incorrect message type, expected 0xb9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce39, + "incorrect sender id, expected 0xce39, is {sender_id}" + ); + assert_eq!( + msg.code, 1737912018, + "incorrect value for code, expected 1737912018, is {}", + msg.code + ); + assert_eq!( + msg.sequence, 2692994934, + "incorrect value for sequence, expected 2692994934, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_command_resp() { + { + let json_input = r#"{"crc":61604,"length":8,"msg_type":185,"payload":"dteDoNJulmc=","preamble":85,"sender":52793,"sequence":2692994934,"code":1737912018}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCommandResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb9, + "Incorrect message type, expected 0xb9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce39, + "incorrect sender id, expected 0xce39, is {sender_id}" + ); + assert_eq!( + msg.code, 1737912018, + "incorrect value for code, expected 1737912018, is {}", + msg.code + ); + assert_eq!( + msg.sequence, 2692994934, + "incorrect value for sequence, expected 2692994934, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_command_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_command_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 185, 0, 57, 206, 8, 118, 215, 131, 160, 210, 110, 150, 103, 164, 240, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCommandResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCommandResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb9, + "Incorrect message type, expected 0xb9, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xce39, + "incorrect sender id, expected 0xce39, is {sender_id}" + ); + assert_eq!( + msg.code, 1737912018, + "incorrect value for code, expected 1737912018, is {}", + msg.code + ); + assert_eq!( + msg.sequence, 2692994934, + "incorrect value for sequence, expected 2692994934, is {}", + msg.sequence + ); + } + _ => panic!("Invalid message type! Expected a MsgCommandResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_results.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_results.rs new file mode 100644 index 0000000000..8a2c29ca98 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_results.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_cw_results() { + { + let mut payload = Cursor::new(vec![85, 192, 0, 99, 246, 0, 228, 72]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCwResults(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc0, + "Incorrect message type, expected 0xc0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf663, + "incorrect sender id, expected 0xf663, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwResults"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_cw_results() { + { + let json_input = + r#"{"crc":18660,"length":0,"msg_type":192,"payload":"","preamble":85,"sender":63075}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCwResults(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc0, + "Incorrect message type, expected 0xc0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf663, + "incorrect sender id, expected 0xf663, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwResults"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_cw_results`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_cw_results() { + { + let mut payload = Cursor::new(vec![85, 192, 0, 99, 246, 0, 228, 72]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCwResults( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCwResults(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc0, + "Incorrect message type, expected 0xc0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf663, + "incorrect sender id, expected 0xf663, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwResults"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_start.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_start.rs new file mode 100644 index 0000000000..250fed6724 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_cw_start.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_cw_start() { + { + let mut payload = Cursor::new(vec![85, 193, 0, 30, 179, 0, 213, 138]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCwStart(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc1, + "Incorrect message type, expected 0xc1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb31e, + "incorrect sender id, expected 0xb31e, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwStart"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_cw_start() { + { + let json_input = + r#"{"crc":35541,"length":0,"msg_type":193,"payload":"","preamble":85,"sender":45854}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCwStart(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc1, + "Incorrect message type, expected 0xc1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb31e, + "incorrect sender id, expected 0xb31e, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwStart"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_cw_start`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_cw_start() { + { + let mut payload = Cursor::new(vec![85, 193, 0, 30, 179, 0, 213, 138]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCwStart( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCwStart(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xc1, + "Incorrect message type, expected 0xc1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xb31e, + "incorrect sender id, expected 0xb31e, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgCwStart"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_front_end_gain.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_front_end_gain.rs new file mode 100644 index 0000000000..8168b3504a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_front_end_gain.rs @@ -0,0 +1,409 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_front_end_gain() { + { + let mut payload = Cursor::new(vec![ + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, 38, 38, 246, 233, 216, 80, 187, + 213, 85, 2, 235, 135, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFrontEndGain(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbf, + "Incorrect message type, expected 0xbf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf5af, + "incorrect sender id, expected 0xf5af, is {sender_id}" + ); + assert_eq!( + msg.if_gain[0], -10, + "incorrect value for if_gain[0], expected -10, is {}", + msg.if_gain[0] + ); + assert_eq!( + msg.if_gain[1], -23, + "incorrect value for if_gain[1], expected -23, is {}", + msg.if_gain[1] + ); + assert_eq!( + msg.if_gain[2], -40, + "incorrect value for if_gain[2], expected -40, is {}", + msg.if_gain[2] + ); + assert_eq!( + msg.if_gain[3], 80, + "incorrect value for if_gain[3], expected 80, is {}", + msg.if_gain[3] + ); + assert_eq!( + msg.if_gain[4], -69, + "incorrect value for if_gain[4], expected -69, is {}", + msg.if_gain[4] + ); + assert_eq!( + msg.if_gain[5], -43, + "incorrect value for if_gain[5], expected -43, is {}", + msg.if_gain[5] + ); + assert_eq!( + msg.if_gain[6], 85, + "incorrect value for if_gain[6], expected 85, is {}", + msg.if_gain[6] + ); + assert_eq!( + msg.if_gain[7], 2, + "incorrect value for if_gain[7], expected 2, is {}", + msg.if_gain[7] + ); + assert_eq!( + msg.rf_gain[0], 41, + "incorrect value for rf_gain[0], expected 41, is {}", + msg.rf_gain[0] + ); + assert_eq!( + msg.rf_gain[1], -123, + "incorrect value for rf_gain[1], expected -123, is {}", + msg.rf_gain[1] + ); + assert_eq!( + msg.rf_gain[2], -122, + "incorrect value for rf_gain[2], expected -122, is {}", + msg.rf_gain[2] + ); + assert_eq!( + msg.rf_gain[3], 10, + "incorrect value for rf_gain[3], expected 10, is {}", + msg.rf_gain[3] + ); + assert_eq!( + msg.rf_gain[4], 105, + "incorrect value for rf_gain[4], expected 105, is {}", + msg.rf_gain[4] + ); + assert_eq!( + msg.rf_gain[5], 20, + "incorrect value for rf_gain[5], expected 20, is {}", + msg.rf_gain[5] + ); + assert_eq!( + msg.rf_gain[6], 38, + "incorrect value for rf_gain[6], expected 38, is {}", + msg.rf_gain[6] + ); + assert_eq!( + msg.rf_gain[7], 38, + "incorrect value for rf_gain[7], expected 38, is {}", + msg.rf_gain[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgFrontEndGain"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_front_end_gain() { + { + let json_input = r#"{"crc":34795,"length":16,"msg_type":191,"payload":"KYWGCmkUJib26dhQu9VVAg==","preamble":85,"sender":62895,"rf_gain":[41,-123,-122,10,105,20,38,38],"if_gain":[-10,-23,-40,80,-69,-43,85,2]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgFrontEndGain(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbf, + "Incorrect message type, expected 0xbf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf5af, + "incorrect sender id, expected 0xf5af, is {sender_id}" + ); + assert_eq!( + msg.if_gain[0], -10, + "incorrect value for if_gain[0], expected -10, is {}", + msg.if_gain[0] + ); + assert_eq!( + msg.if_gain[1], -23, + "incorrect value for if_gain[1], expected -23, is {}", + msg.if_gain[1] + ); + assert_eq!( + msg.if_gain[2], -40, + "incorrect value for if_gain[2], expected -40, is {}", + msg.if_gain[2] + ); + assert_eq!( + msg.if_gain[3], 80, + "incorrect value for if_gain[3], expected 80, is {}", + msg.if_gain[3] + ); + assert_eq!( + msg.if_gain[4], -69, + "incorrect value for if_gain[4], expected -69, is {}", + msg.if_gain[4] + ); + assert_eq!( + msg.if_gain[5], -43, + "incorrect value for if_gain[5], expected -43, is {}", + msg.if_gain[5] + ); + assert_eq!( + msg.if_gain[6], 85, + "incorrect value for if_gain[6], expected 85, is {}", + msg.if_gain[6] + ); + assert_eq!( + msg.if_gain[7], 2, + "incorrect value for if_gain[7], expected 2, is {}", + msg.if_gain[7] + ); + assert_eq!( + msg.rf_gain[0], 41, + "incorrect value for rf_gain[0], expected 41, is {}", + msg.rf_gain[0] + ); + assert_eq!( + msg.rf_gain[1], -123, + "incorrect value for rf_gain[1], expected -123, is {}", + msg.rf_gain[1] + ); + assert_eq!( + msg.rf_gain[2], -122, + "incorrect value for rf_gain[2], expected -122, is {}", + msg.rf_gain[2] + ); + assert_eq!( + msg.rf_gain[3], 10, + "incorrect value for rf_gain[3], expected 10, is {}", + msg.rf_gain[3] + ); + assert_eq!( + msg.rf_gain[4], 105, + "incorrect value for rf_gain[4], expected 105, is {}", + msg.rf_gain[4] + ); + assert_eq!( + msg.rf_gain[5], 20, + "incorrect value for rf_gain[5], expected 20, is {}", + msg.rf_gain[5] + ); + assert_eq!( + msg.rf_gain[6], 38, + "incorrect value for rf_gain[6], expected 38, is {}", + msg.rf_gain[6] + ); + assert_eq!( + msg.rf_gain[7], 38, + "incorrect value for rf_gain[7], expected 38, is {}", + msg.rf_gain[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgFrontEndGain"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_front_end_gain`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_front_end_gain() { + { + let mut payload = Cursor::new(vec![ + 85, 191, 0, 175, 245, 16, 41, 133, 134, 10, 105, 20, 38, 38, 246, 233, 216, 80, 187, + 213, 85, 2, 235, 135, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgFrontEndGain( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgFrontEndGain(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbf, + "Incorrect message type, expected 0xbf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf5af, + "incorrect sender id, expected 0xf5af, is {sender_id}" + ); + assert_eq!( + msg.if_gain[0], -10, + "incorrect value for if_gain[0], expected -10, is {}", + msg.if_gain[0] + ); + assert_eq!( + msg.if_gain[1], -23, + "incorrect value for if_gain[1], expected -23, is {}", + msg.if_gain[1] + ); + assert_eq!( + msg.if_gain[2], -40, + "incorrect value for if_gain[2], expected -40, is {}", + msg.if_gain[2] + ); + assert_eq!( + msg.if_gain[3], 80, + "incorrect value for if_gain[3], expected 80, is {}", + msg.if_gain[3] + ); + assert_eq!( + msg.if_gain[4], -69, + "incorrect value for if_gain[4], expected -69, is {}", + msg.if_gain[4] + ); + assert_eq!( + msg.if_gain[5], -43, + "incorrect value for if_gain[5], expected -43, is {}", + msg.if_gain[5] + ); + assert_eq!( + msg.if_gain[6], 85, + "incorrect value for if_gain[6], expected 85, is {}", + msg.if_gain[6] + ); + assert_eq!( + msg.if_gain[7], 2, + "incorrect value for if_gain[7], expected 2, is {}", + msg.if_gain[7] + ); + assert_eq!( + msg.rf_gain[0], 41, + "incorrect value for rf_gain[0], expected 41, is {}", + msg.rf_gain[0] + ); + assert_eq!( + msg.rf_gain[1], -123, + "incorrect value for rf_gain[1], expected -123, is {}", + msg.rf_gain[1] + ); + assert_eq!( + msg.rf_gain[2], -122, + "incorrect value for rf_gain[2], expected -122, is {}", + msg.rf_gain[2] + ); + assert_eq!( + msg.rf_gain[3], 10, + "incorrect value for rf_gain[3], expected 10, is {}", + msg.rf_gain[3] + ); + assert_eq!( + msg.rf_gain[4], 105, + "incorrect value for rf_gain[4], expected 105, is {}", + msg.rf_gain[4] + ); + assert_eq!( + msg.rf_gain[5], 20, + "incorrect value for rf_gain[5], expected 20, is {}", + msg.rf_gain[5] + ); + assert_eq!( + msg.rf_gain[6], 38, + "incorrect value for rf_gain[6], expected 38, is {}", + msg.rf_gain[6] + ); + assert_eq!( + msg.rf_gain[7], 38, + "incorrect value for rf_gain[7], expected 38, is {}", + msg.rf_gain[7] + ); + } + _ => panic!("Invalid message type! Expected a MsgFrontEndGain"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_init_base_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_init_base_dep.rs new file mode 100644 index 0000000000..6d78088f70 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_init_base_dep.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_init_base_dep() { + { + let mut payload = Cursor::new(vec![85, 35, 0, 184, 41, 0, 70, 13]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgInitBaseDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x23, + "Incorrect message type, expected 0x23, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x29b8, + "incorrect sender id, expected 0x29b8, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgInitBaseDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_init_base_dep() { + { + let json_input = + r#"{"crc":3398,"length":0,"msg_type":35,"payload":"","preamble":85,"sender":10680}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgInitBaseDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x23, + "Incorrect message type, expected 0x23, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x29b8, + "incorrect sender id, expected 0x29b8, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgInitBaseDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_init_base_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_init_base_dep() { + { + let mut payload = Cursor::new(vec![85, 35, 0, 184, 41, 0, 70, 13]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgInitBaseDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgInitBaseDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x23, + "Incorrect message type, expected 0x23, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x29b8, + "incorrect sender id, expected 0x29b8, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgInitBaseDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite.rs new file mode 100644 index 0000000000..e16cffef24 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite.rs @@ -0,0 +1,208 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_mask_satellite() { + { + let mut payload = Cursor::new(vec![85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatellite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2b, + "Incorrect message type, expected 0x2b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97ad, + "incorrect sender id, expected 0x97ad, is {sender_id}" + ); + assert_eq!( + msg.mask, 183, + "incorrect value for mask, expected 183, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 57, + "incorrect value for sid.code, expected 57, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 87, + "incorrect value for sid.sat, expected 87, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatellite"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_mask_satellite() { + { + let json_input = r#"{"crc":37651,"length":3,"msg_type":43,"payload":"t1c5","preamble":85,"sender":38829,"mask":183,"sid":{"sat":87,"code":57}}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatellite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2b, + "Incorrect message type, expected 0x2b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97ad, + "incorrect sender id, expected 0x97ad, is {sender_id}" + ); + assert_eq!( + msg.mask, 183, + "incorrect value for mask, expected 183, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 57, + "incorrect value for sid.code, expected 57, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 87, + "incorrect value for sid.sat, expected 87, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatellite"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_mask_satellite`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_mask_satellite() { + { + let mut payload = Cursor::new(vec![85, 43, 0, 173, 151, 3, 183, 87, 57, 19, 147]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgMaskSatellite( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatellite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2b, + "Incorrect message type, expected 0x2b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97ad, + "incorrect sender id, expected 0x97ad, is {sender_id}" + ); + assert_eq!( + msg.mask, 183, + "incorrect value for mask, expected 183, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 57, + "incorrect value for sid.code, expected 57, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 87, + "incorrect value for sid.sat, expected 87, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatellite"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite_dep.rs new file mode 100644 index 0000000000..0e93fe9537 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_mask_satellite_dep.rs @@ -0,0 +1,223 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_mask_satellite_dep() { + { + let mut payload = Cursor::new(vec![85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatelliteDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1b, + "Incorrect message type, expected 0x1b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x86bb, + "incorrect sender id, expected 0x86bb, is {sender_id}" + ); + assert_eq!( + msg.mask, 33, + "incorrect value for mask, expected 33, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 95, + "incorrect value for sid.code, expected 95, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 4, + "incorrect value for sid.reserved, expected 4, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 39170, + "incorrect value for sid.sat, expected 39170, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatelliteDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_mask_satellite_dep() { + { + let json_input = r#"{"crc":48157,"length":5,"msg_type":27,"payload":"IQKZXwQ=","preamble":85,"sender":34491,"mask":33,"sid":{"sat":39170,"code":95,"reserved":4}}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatelliteDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1b, + "Incorrect message type, expected 0x1b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x86bb, + "incorrect sender id, expected 0x86bb, is {sender_id}" + ); + assert_eq!( + msg.mask, 33, + "incorrect value for mask, expected 33, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 95, + "incorrect value for sid.code, expected 95, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 4, + "incorrect value for sid.reserved, expected 4, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 39170, + "incorrect value for sid.sat, expected 39170, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatelliteDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_mask_satellite_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_mask_satellite_dep() { + { + let mut payload = Cursor::new(vec![85, 27, 0, 187, 134, 5, 33, 2, 153, 95, 4, 29, 188]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgMaskSatelliteDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgMaskSatelliteDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1b, + "Incorrect message type, expected 0x1b, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x86bb, + "incorrect sender id, expected 0x86bb, is {sender_id}" + ); + assert_eq!( + msg.mask, 33, + "incorrect value for mask, expected 33, is {}", + msg.mask + ); + assert_eq!( + msg.sid.code, 95, + "incorrect value for sid.code, expected 95, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 4, + "incorrect value for sid.reserved, expected 4, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 39170, + "incorrect value for sid.sat, expected 39170, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgMaskSatelliteDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_req.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_req.rs new file mode 100644 index 0000000000..592e9617a6 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_req.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_network_state_req() { + { + let mut payload = Cursor::new(vec![85, 186, 0, 83, 62, 0, 148, 73]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xba, + "Incorrect message type, expected 0xba, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3e53, + "incorrect sender id, expected 0x3e53, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_network_state_req() { + { + let json_input = + r#"{"crc":18836,"length":0,"msg_type":186,"payload":"","preamble":85,"sender":15955}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xba, + "Incorrect message type, expected 0xba, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3e53, + "incorrect sender id, expected 0x3e53, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_network_state_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_network_state_req() { + { + let mut payload = Cursor::new(vec![85, 186, 0, 83, 62, 0, 148, 73]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgNetworkStateReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xba, + "Incorrect message type, expected 0xba, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3e53, + "incorrect sender id, expected 0x3e53, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_resp.rs new file mode 100644 index 0000000000..b79248281f --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_network_state_resp.rs @@ -0,0 +1,567 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_network_state_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, 137, 32, 44, 114, 147, 68, 222, + 92, 192, 78, 235, 63, 208, 114, 53, 183, 24, 244, 231, 26, 105, 25, 136, 3, 105, 102, + 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbb, + "Incorrect message type, expected 0xbb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f28, + "incorrect sender id, expected 0x0f28, is {sender_id}" + ); + assert_eq!( + msg.flags, 2471552451, + "incorrect value for flags, expected 2471552451, is {}", + msg.flags + ); + assert_eq!( + msg.interface_name.as_bytes(), + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "incorrect value for msg.interface_name, expected string '{:?}', is '{:?}'", + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + msg.interface_name.as_bytes() + ); + assert_eq!( + msg.ipv4_address[0], 143, + "incorrect value for ipv4_address[0], expected 143, is {}", + msg.ipv4_address[0] + ); + assert_eq!( + msg.ipv4_address[1], 241, + "incorrect value for ipv4_address[1], expected 241, is {}", + msg.ipv4_address[1] + ); + assert_eq!( + msg.ipv4_address[2], 84, + "incorrect value for ipv4_address[2], expected 84, is {}", + msg.ipv4_address[2] + ); + assert_eq!( + msg.ipv4_address[3], 180, + "incorrect value for ipv4_address[3], expected 180, is {}", + msg.ipv4_address[3] + ); + assert_eq!( + msg.ipv4_mask_size, 152, + "incorrect value for ipv4_mask_size, expected 152, is {}", + msg.ipv4_mask_size + ); + assert_eq!( + msg.ipv6_address[0], 194, + "incorrect value for ipv6_address[0], expected 194, is {}", + msg.ipv6_address[0] + ); + assert_eq!( + msg.ipv6_address[1], 137, + "incorrect value for ipv6_address[1], expected 137, is {}", + msg.ipv6_address[1] + ); + assert_eq!( + msg.ipv6_address[2], 32, + "incorrect value for ipv6_address[2], expected 32, is {}", + msg.ipv6_address[2] + ); + assert_eq!( + msg.ipv6_address[3], 44, + "incorrect value for ipv6_address[3], expected 44, is {}", + msg.ipv6_address[3] + ); + assert_eq!( + msg.ipv6_address[4], 114, + "incorrect value for ipv6_address[4], expected 114, is {}", + msg.ipv6_address[4] + ); + assert_eq!( + msg.ipv6_address[5], 147, + "incorrect value for ipv6_address[5], expected 147, is {}", + msg.ipv6_address[5] + ); + assert_eq!( + msg.ipv6_address[6], 68, + "incorrect value for ipv6_address[6], expected 68, is {}", + msg.ipv6_address[6] + ); + assert_eq!( + msg.ipv6_address[7], 222, + "incorrect value for ipv6_address[7], expected 222, is {}", + msg.ipv6_address[7] + ); + assert_eq!( + msg.ipv6_address[8], 92, + "incorrect value for ipv6_address[8], expected 92, is {}", + msg.ipv6_address[8] + ); + assert_eq!( + msg.ipv6_address[9], 192, + "incorrect value for ipv6_address[9], expected 192, is {}", + msg.ipv6_address[9] + ); + assert_eq!( + msg.ipv6_address[10], 78, + "incorrect value for ipv6_address[10], expected 78, is {}", + msg.ipv6_address[10] + ); + assert_eq!( + msg.ipv6_address[11], 235, + "incorrect value for ipv6_address[11], expected 235, is {}", + msg.ipv6_address[11] + ); + assert_eq!( + msg.ipv6_address[12], 63, + "incorrect value for ipv6_address[12], expected 63, is {}", + msg.ipv6_address[12] + ); + assert_eq!( + msg.ipv6_address[13], 208, + "incorrect value for ipv6_address[13], expected 208, is {}", + msg.ipv6_address[13] + ); + assert_eq!( + msg.ipv6_address[14], 114, + "incorrect value for ipv6_address[14], expected 114, is {}", + msg.ipv6_address[14] + ); + assert_eq!( + msg.ipv6_address[15], 53, + "incorrect value for ipv6_address[15], expected 53, is {}", + msg.ipv6_address[15] + ); + assert_eq!( + msg.ipv6_mask_size, 183, + "incorrect value for ipv6_mask_size, expected 183, is {}", + msg.ipv6_mask_size + ); + assert_eq!( + msg.rx_bytes, 451408920, + "incorrect value for rx_bytes, expected 451408920, is {}", + msg.rx_bytes + ); + assert_eq!( + msg.tx_bytes, 59251049, + "incorrect value for tx_bytes, expected 59251049, is {}", + msg.tx_bytes + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_network_state_resp() { + { + let json_input = r#"{"crc":49526,"length":50,"msg_type":187,"payload":"j/FUtJjCiSAscpNE3lzATus/0HI1txj05xppGYgDaWYwAAAAAAAAAAAAAAAAAMPlUJM=","preamble":85,"sender":3880,"ipv4_address":[143,241,84,180],"ipv4_mask_size":152,"ipv6_address":[194,137,32,44,114,147,68,222,92,192,78,235,63,208,114,53],"ipv6_mask_size":183,"rx_bytes":451408920,"tx_bytes":59251049,"interface_name":"if0\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000","flags":2471552451}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbb, + "Incorrect message type, expected 0xbb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f28, + "incorrect sender id, expected 0x0f28, is {sender_id}" + ); + assert_eq!( + msg.flags, 2471552451, + "incorrect value for flags, expected 2471552451, is {}", + msg.flags + ); + assert_eq!( + msg.interface_name.as_bytes(), + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "incorrect value for msg.interface_name, expected string '{:?}', is '{:?}'", + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + msg.interface_name.as_bytes() + ); + assert_eq!( + msg.ipv4_address[0], 143, + "incorrect value for ipv4_address[0], expected 143, is {}", + msg.ipv4_address[0] + ); + assert_eq!( + msg.ipv4_address[1], 241, + "incorrect value for ipv4_address[1], expected 241, is {}", + msg.ipv4_address[1] + ); + assert_eq!( + msg.ipv4_address[2], 84, + "incorrect value for ipv4_address[2], expected 84, is {}", + msg.ipv4_address[2] + ); + assert_eq!( + msg.ipv4_address[3], 180, + "incorrect value for ipv4_address[3], expected 180, is {}", + msg.ipv4_address[3] + ); + assert_eq!( + msg.ipv4_mask_size, 152, + "incorrect value for ipv4_mask_size, expected 152, is {}", + msg.ipv4_mask_size + ); + assert_eq!( + msg.ipv6_address[0], 194, + "incorrect value for ipv6_address[0], expected 194, is {}", + msg.ipv6_address[0] + ); + assert_eq!( + msg.ipv6_address[1], 137, + "incorrect value for ipv6_address[1], expected 137, is {}", + msg.ipv6_address[1] + ); + assert_eq!( + msg.ipv6_address[2], 32, + "incorrect value for ipv6_address[2], expected 32, is {}", + msg.ipv6_address[2] + ); + assert_eq!( + msg.ipv6_address[3], 44, + "incorrect value for ipv6_address[3], expected 44, is {}", + msg.ipv6_address[3] + ); + assert_eq!( + msg.ipv6_address[4], 114, + "incorrect value for ipv6_address[4], expected 114, is {}", + msg.ipv6_address[4] + ); + assert_eq!( + msg.ipv6_address[5], 147, + "incorrect value for ipv6_address[5], expected 147, is {}", + msg.ipv6_address[5] + ); + assert_eq!( + msg.ipv6_address[6], 68, + "incorrect value for ipv6_address[6], expected 68, is {}", + msg.ipv6_address[6] + ); + assert_eq!( + msg.ipv6_address[7], 222, + "incorrect value for ipv6_address[7], expected 222, is {}", + msg.ipv6_address[7] + ); + assert_eq!( + msg.ipv6_address[8], 92, + "incorrect value for ipv6_address[8], expected 92, is {}", + msg.ipv6_address[8] + ); + assert_eq!( + msg.ipv6_address[9], 192, + "incorrect value for ipv6_address[9], expected 192, is {}", + msg.ipv6_address[9] + ); + assert_eq!( + msg.ipv6_address[10], 78, + "incorrect value for ipv6_address[10], expected 78, is {}", + msg.ipv6_address[10] + ); + assert_eq!( + msg.ipv6_address[11], 235, + "incorrect value for ipv6_address[11], expected 235, is {}", + msg.ipv6_address[11] + ); + assert_eq!( + msg.ipv6_address[12], 63, + "incorrect value for ipv6_address[12], expected 63, is {}", + msg.ipv6_address[12] + ); + assert_eq!( + msg.ipv6_address[13], 208, + "incorrect value for ipv6_address[13], expected 208, is {}", + msg.ipv6_address[13] + ); + assert_eq!( + msg.ipv6_address[14], 114, + "incorrect value for ipv6_address[14], expected 114, is {}", + msg.ipv6_address[14] + ); + assert_eq!( + msg.ipv6_address[15], 53, + "incorrect value for ipv6_address[15], expected 53, is {}", + msg.ipv6_address[15] + ); + assert_eq!( + msg.ipv6_mask_size, 183, + "incorrect value for ipv6_mask_size, expected 183, is {}", + msg.ipv6_mask_size + ); + assert_eq!( + msg.rx_bytes, 451408920, + "incorrect value for rx_bytes, expected 451408920, is {}", + msg.rx_bytes + ); + assert_eq!( + msg.tx_bytes, 59251049, + "incorrect value for tx_bytes, expected 59251049, is {}", + msg.tx_bytes + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_network_state_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_network_state_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 187, 0, 40, 15, 50, 143, 241, 84, 180, 152, 194, 137, 32, 44, 114, 147, 68, 222, + 92, 192, 78, 235, 63, 208, 114, 53, 183, 24, 244, 231, 26, 105, 25, 136, 3, 105, 102, + 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 195, 229, 80, 147, 118, 193, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgNetworkStateResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgNetworkStateResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xbb, + "Incorrect message type, expected 0xbb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f28, + "incorrect sender id, expected 0x0f28, is {sender_id}" + ); + assert_eq!( + msg.flags, 2471552451, + "incorrect value for flags, expected 2471552451, is {}", + msg.flags + ); + assert_eq!( + msg.interface_name.as_bytes(), + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + "incorrect value for msg.interface_name, expected string '{:?}', is '{:?}'", + &[105, 102, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + msg.interface_name.as_bytes() + ); + assert_eq!( + msg.ipv4_address[0], 143, + "incorrect value for ipv4_address[0], expected 143, is {}", + msg.ipv4_address[0] + ); + assert_eq!( + msg.ipv4_address[1], 241, + "incorrect value for ipv4_address[1], expected 241, is {}", + msg.ipv4_address[1] + ); + assert_eq!( + msg.ipv4_address[2], 84, + "incorrect value for ipv4_address[2], expected 84, is {}", + msg.ipv4_address[2] + ); + assert_eq!( + msg.ipv4_address[3], 180, + "incorrect value for ipv4_address[3], expected 180, is {}", + msg.ipv4_address[3] + ); + assert_eq!( + msg.ipv4_mask_size, 152, + "incorrect value for ipv4_mask_size, expected 152, is {}", + msg.ipv4_mask_size + ); + assert_eq!( + msg.ipv6_address[0], 194, + "incorrect value for ipv6_address[0], expected 194, is {}", + msg.ipv6_address[0] + ); + assert_eq!( + msg.ipv6_address[1], 137, + "incorrect value for ipv6_address[1], expected 137, is {}", + msg.ipv6_address[1] + ); + assert_eq!( + msg.ipv6_address[2], 32, + "incorrect value for ipv6_address[2], expected 32, is {}", + msg.ipv6_address[2] + ); + assert_eq!( + msg.ipv6_address[3], 44, + "incorrect value for ipv6_address[3], expected 44, is {}", + msg.ipv6_address[3] + ); + assert_eq!( + msg.ipv6_address[4], 114, + "incorrect value for ipv6_address[4], expected 114, is {}", + msg.ipv6_address[4] + ); + assert_eq!( + msg.ipv6_address[5], 147, + "incorrect value for ipv6_address[5], expected 147, is {}", + msg.ipv6_address[5] + ); + assert_eq!( + msg.ipv6_address[6], 68, + "incorrect value for ipv6_address[6], expected 68, is {}", + msg.ipv6_address[6] + ); + assert_eq!( + msg.ipv6_address[7], 222, + "incorrect value for ipv6_address[7], expected 222, is {}", + msg.ipv6_address[7] + ); + assert_eq!( + msg.ipv6_address[8], 92, + "incorrect value for ipv6_address[8], expected 92, is {}", + msg.ipv6_address[8] + ); + assert_eq!( + msg.ipv6_address[9], 192, + "incorrect value for ipv6_address[9], expected 192, is {}", + msg.ipv6_address[9] + ); + assert_eq!( + msg.ipv6_address[10], 78, + "incorrect value for ipv6_address[10], expected 78, is {}", + msg.ipv6_address[10] + ); + assert_eq!( + msg.ipv6_address[11], 235, + "incorrect value for ipv6_address[11], expected 235, is {}", + msg.ipv6_address[11] + ); + assert_eq!( + msg.ipv6_address[12], 63, + "incorrect value for ipv6_address[12], expected 63, is {}", + msg.ipv6_address[12] + ); + assert_eq!( + msg.ipv6_address[13], 208, + "incorrect value for ipv6_address[13], expected 208, is {}", + msg.ipv6_address[13] + ); + assert_eq!( + msg.ipv6_address[14], 114, + "incorrect value for ipv6_address[14], expected 114, is {}", + msg.ipv6_address[14] + ); + assert_eq!( + msg.ipv6_address[15], 53, + "incorrect value for ipv6_address[15], expected 53, is {}", + msg.ipv6_address[15] + ); + assert_eq!( + msg.ipv6_mask_size, 183, + "incorrect value for ipv6_mask_size, expected 183, is {}", + msg.ipv6_mask_size + ); + assert_eq!( + msg.rx_bytes, 451408920, + "incorrect value for rx_bytes, expected 451408920, is {}", + msg.rx_bytes + ); + assert_eq!( + msg.tx_bytes, 59251049, + "incorrect value for tx_bytes, expected 59251049, is {}", + msg.tx_bytes + ); + } + _ => panic!("Invalid message type! Expected a MsgNetworkStateResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset.rs new file mode 100644 index 0000000000..faf53d54ff --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_reset() { + { + let mut payload = Cursor::new(vec![85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgReset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb6, + "Incorrect message type, expected 0xb6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd23f, + "incorrect sender id, expected 0xd23f, is {sender_id}" + ); + assert_eq!( + msg.flags, 334428248, + "incorrect value for flags, expected 334428248, is {}", + msg.flags + ); + } + _ => panic!("Invalid message type! Expected a MsgReset"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_reset() { + { + let json_input = r#"{"crc":53066,"length":4,"msg_type":182,"payload":"WPjuEw==","preamble":85,"sender":53823,"flags":334428248}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgReset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb6, + "Incorrect message type, expected 0xb6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd23f, + "incorrect sender id, expected 0xd23f, is {sender_id}" + ); + assert_eq!( + msg.flags, 334428248, + "incorrect value for flags, expected 334428248, is {}", + msg.flags + ); + } + _ => panic!("Invalid message type! Expected a MsgReset"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_reset`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_reset() { + { + let mut payload = Cursor::new(vec![85, 182, 0, 63, 210, 4, 88, 248, 238, 19, 74, 207]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgReset( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgReset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb6, + "Incorrect message type, expected 0xb6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd23f, + "incorrect sender id, expected 0xd23f, is {sender_id}" + ); + assert_eq!( + msg.flags, 334428248, + "incorrect value for flags, expected 334428248, is {}", + msg.flags + ); + } + _ => panic!("Invalid message type! Expected a MsgReset"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_dep.rs new file mode 100644 index 0000000000..f17460ec37 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_dep.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_reset_dep() { + { + let mut payload = Cursor::new(vec![85, 178, 0, 64, 11, 0, 234, 171]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgResetDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb2, + "Incorrect message type, expected 0xb2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0b40, + "incorrect sender id, expected 0x0b40, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgResetDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_reset_dep() { + { + let json_input = + r#"{"crc":44010,"length":0,"msg_type":178,"payload":"","preamble":85,"sender":2880}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgResetDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb2, + "Incorrect message type, expected 0xb2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0b40, + "incorrect sender id, expected 0x0b40, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgResetDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_reset_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_reset_dep() { + { + let mut payload = Cursor::new(vec![85, 178, 0, 64, 11, 0, 234, 171]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgResetDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgResetDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xb2, + "Incorrect message type, expected 0xb2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0b40, + "incorrect sender id, expected 0x0b40, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgResetDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_filters.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_filters.rs new file mode 100644 index 0000000000..d396e30a79 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_reset_filters.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_reset_filters() { + { + let mut payload = Cursor::new(vec![85, 34, 0, 81, 200, 1, 100, 130, 45]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgResetFilters(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x22, + "Incorrect message type, expected 0x22, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc851, + "incorrect sender id, expected 0xc851, is {sender_id}" + ); + assert_eq!( + msg.filter, 100, + "incorrect value for filter, expected 100, is {}", + msg.filter + ); + } + _ => panic!("Invalid message type! Expected a MsgResetFilters"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_reset_filters() { + { + let json_input = r#"{"crc":11650,"length":1,"msg_type":34,"payload":"ZA==","preamble":85,"sender":51281,"filter":100}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgResetFilters(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x22, + "Incorrect message type, expected 0x22, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc851, + "incorrect sender id, expected 0xc851, is {sender_id}" + ); + assert_eq!( + msg.filter, 100, + "incorrect value for filter, expected 100, is {}", + msg.filter + ); + } + _ => panic!("Invalid message type! Expected a MsgResetFilters"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_reset_filters`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_reset_filters() { + { + let mut payload = Cursor::new(vec![85, 34, 0, 81, 200, 1, 100, 130, 45]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgResetFilters( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgResetFilters(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x22, + "Incorrect message type, expected 0x22, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc851, + "incorrect sender id, expected 0xc851, is {sender_id}" + ); + assert_eq!( + msg.filter, 100, + "incorrect value for filter, expected 100, is {}", + msg.filter + ); + } + _ => panic!("Invalid message type! Expected a MsgResetFilters"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_set_time.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_set_time.rs new file mode 100644 index 0000000000..b7c7bce01b --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_set_time.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_set_time() { + { + let mut payload = Cursor::new(vec![85, 104, 0, 21, 170, 0, 215, 65]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSetTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x68, + "Incorrect message type, expected 0x68, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaa15, + "incorrect sender id, expected 0xaa15, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSetTime"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_set_time() { + { + let json_input = + r#"{"crc":16855,"length":0,"msg_type":104,"payload":"","preamble":85,"sender":43541}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSetTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x68, + "Incorrect message type, expected 0x68, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaa15, + "incorrect sender id, expected 0xaa15, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSetTime"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_set_time`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_set_time() { + { + let mut payload = Cursor::new(vec![85, 104, 0, 21, 170, 0, 215, 65]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSetTime( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSetTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x68, + "Incorrect message type, expected 0x68, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xaa15, + "incorrect sender id, expected 0xaa15, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSetTime"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan.rs new file mode 100644 index 0000000000..c6500901ba --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan.rs @@ -0,0 +1,3718 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_specan() { + { + let mut payload = Cursor::new(vec![ + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, 215, 167, 211, 19, 154, + 201, 241, 69, 205, 136, 0, 70, 51, 67, 108, 69, 102, 38, 166, 68, 100, 179, 185, 17, + 175, 49, 193, 228, 228, 47, 33, 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, 223, + 167, 174, 9, 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, 218, 241, 101, 107, 45, 137, + 93, 114, 230, 43, 224, 23, 74, 209, 199, 211, 130, 89, 220, 163, 68, 20, 253, 7, 206, + 50, 129, 116, 194, 23, 31, 226, 217, 157, 205, 221, 5, 224, 92, 82, 109, 223, 195, 233, + 165, 1, 82, 141, 157, 177, 169, 244, 131, 96, 109, 111, 253, 149, 28, 225, 225, 72, + 158, 158, 210, 196, 206, 70, 63, 225, 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, 179, + 148, 66, 254, 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, 171, 102, 163, 175, 50, + 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, 237, 156, 62, 117, 47, 143, 94, 135, 22, + 155, 113, 110, 15, 243, 141, 227, 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, + 88, 38, 117, 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, 70, 182, 239, + 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, 123, 210, 168, 90, 124, 20, 7, 220, + 144, 168, 69, 22, 72, 162, 69, 111, 91, 251, 72, 220, 28, 119, 150, 95, 2, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSpecan(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x51, + "Incorrect message type, expected 0x51, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd41c, + "incorrect sender id, expected 0xd41c, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(3.78019995117187500e+03), + "incorrect value for amplitude_ref, expected 3.78019995117187500e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(1.32919995117187500e+03), + "incorrect value for amplitude_unit, expected 1.32919995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 100, + "incorrect value for amplitude_value[0], expected 100, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 179, + "incorrect value for amplitude_value[1], expected 179, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 185, + "incorrect value for amplitude_value[2], expected 185, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 17, + "incorrect value for amplitude_value[3], expected 17, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 175, + "incorrect value for amplitude_value[4], expected 175, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 49, + "incorrect value for amplitude_value[5], expected 49, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 193, + "incorrect value for amplitude_value[6], expected 193, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 228, + "incorrect value for amplitude_value[7], expected 228, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 228, + "incorrect value for amplitude_value[8], expected 228, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 47, + "incorrect value for amplitude_value[9], expected 47, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 33, + "incorrect value for amplitude_value[10], expected 33, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 24, + "incorrect value for amplitude_value[11], expected 24, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 141, + "incorrect value for amplitude_value[12], expected 141, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 177, + "incorrect value for amplitude_value[13], expected 177, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 18, + "incorrect value for amplitude_value[14], expected 18, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 99, + "incorrect value for amplitude_value[15], expected 99, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 246, + "incorrect value for amplitude_value[16], expected 246, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 121, + "incorrect value for amplitude_value[17], expected 121, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 61, + "incorrect value for amplitude_value[18], expected 61, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 40, + "incorrect value for amplitude_value[19], expected 40, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 91, + "incorrect value for amplitude_value[20], expected 91, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 145, + "incorrect value for amplitude_value[21], expected 145, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 223, + "incorrect value for amplitude_value[22], expected 223, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 167, + "incorrect value for amplitude_value[23], expected 167, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 174, + "incorrect value for amplitude_value[24], expected 174, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 9, + "incorrect value for amplitude_value[25], expected 9, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 116, + "incorrect value for amplitude_value[26], expected 116, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 11, + "incorrect value for amplitude_value[27], expected 11, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 247, + "incorrect value for amplitude_value[28], expected 247, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 84, + "incorrect value for amplitude_value[29], expected 84, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 49, + "incorrect value for amplitude_value[30], expected 49, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 153, + "incorrect value for amplitude_value[31], expected 153, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 205, + "incorrect value for amplitude_value[32], expected 205, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 2, + "incorrect value for amplitude_value[33], expected 2, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 230, + "incorrect value for amplitude_value[34], expected 230, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 194, + "incorrect value for amplitude_value[35], expected 194, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 218, + "incorrect value for amplitude_value[36], expected 218, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 241, + "incorrect value for amplitude_value[37], expected 241, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 101, + "incorrect value for amplitude_value[38], expected 101, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 107, + "incorrect value for amplitude_value[39], expected 107, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 45, + "incorrect value for amplitude_value[40], expected 45, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 137, + "incorrect value for amplitude_value[41], expected 137, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 93, + "incorrect value for amplitude_value[42], expected 93, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 114, + "incorrect value for amplitude_value[43], expected 114, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 230, + "incorrect value for amplitude_value[44], expected 230, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 43, + "incorrect value for amplitude_value[45], expected 43, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 224, + "incorrect value for amplitude_value[46], expected 224, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 23, + "incorrect value for amplitude_value[47], expected 23, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 74, + "incorrect value for amplitude_value[48], expected 74, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 209, + "incorrect value for amplitude_value[49], expected 209, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 199, + "incorrect value for amplitude_value[50], expected 199, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 211, + "incorrect value for amplitude_value[51], expected 211, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 130, + "incorrect value for amplitude_value[52], expected 130, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 89, + "incorrect value for amplitude_value[53], expected 89, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 220, + "incorrect value for amplitude_value[54], expected 220, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 163, + "incorrect value for amplitude_value[55], expected 163, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 68, + "incorrect value for amplitude_value[56], expected 68, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 20, + "incorrect value for amplitude_value[57], expected 20, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 253, + "incorrect value for amplitude_value[58], expected 253, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 7, + "incorrect value for amplitude_value[59], expected 7, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 206, + "incorrect value for amplitude_value[60], expected 206, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 50, + "incorrect value for amplitude_value[61], expected 50, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 129, + "incorrect value for amplitude_value[62], expected 129, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 116, + "incorrect value for amplitude_value[63], expected 116, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 194, + "incorrect value for amplitude_value[64], expected 194, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 23, + "incorrect value for amplitude_value[65], expected 23, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 31, + "incorrect value for amplitude_value[66], expected 31, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 226, + "incorrect value for amplitude_value[67], expected 226, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 217, + "incorrect value for amplitude_value[68], expected 217, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 157, + "incorrect value for amplitude_value[69], expected 157, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 205, + "incorrect value for amplitude_value[70], expected 205, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 221, + "incorrect value for amplitude_value[71], expected 221, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 5, + "incorrect value for amplitude_value[72], expected 5, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 224, + "incorrect value for amplitude_value[73], expected 224, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 92, + "incorrect value for amplitude_value[74], expected 92, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 82, + "incorrect value for amplitude_value[75], expected 82, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 109, + "incorrect value for amplitude_value[76], expected 109, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 223, + "incorrect value for amplitude_value[77], expected 223, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 195, + "incorrect value for amplitude_value[78], expected 195, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 233, + "incorrect value for amplitude_value[79], expected 233, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 165, + "incorrect value for amplitude_value[80], expected 165, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 1, + "incorrect value for amplitude_value[81], expected 1, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 82, + "incorrect value for amplitude_value[82], expected 82, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 141, + "incorrect value for amplitude_value[83], expected 141, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 157, + "incorrect value for amplitude_value[84], expected 157, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 177, + "incorrect value for amplitude_value[85], expected 177, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 169, + "incorrect value for amplitude_value[86], expected 169, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 244, + "incorrect value for amplitude_value[87], expected 244, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 131, + "incorrect value for amplitude_value[88], expected 131, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 96, + "incorrect value for amplitude_value[89], expected 96, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 109, + "incorrect value for amplitude_value[90], expected 109, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 111, + "incorrect value for amplitude_value[91], expected 111, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 253, + "incorrect value for amplitude_value[92], expected 253, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 149, + "incorrect value for amplitude_value[93], expected 149, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 28, + "incorrect value for amplitude_value[94], expected 28, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 225, + "incorrect value for amplitude_value[95], expected 225, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 225, + "incorrect value for amplitude_value[96], expected 225, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 72, + "incorrect value for amplitude_value[97], expected 72, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 158, + "incorrect value for amplitude_value[98], expected 158, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 158, + "incorrect value for amplitude_value[99], expected 158, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 210, + "incorrect value for amplitude_value[100], expected 210, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 196, + "incorrect value for amplitude_value[101], expected 196, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 206, + "incorrect value for amplitude_value[102], expected 206, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 70, + "incorrect value for amplitude_value[103], expected 70, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 63, + "incorrect value for amplitude_value[104], expected 63, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 225, + "incorrect value for amplitude_value[105], expected 225, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 184, + "incorrect value for amplitude_value[106], expected 184, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 150, + "incorrect value for amplitude_value[107], expected 150, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 174, + "incorrect value for amplitude_value[108], expected 174, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 240, + "incorrect value for amplitude_value[109], expected 240, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 45, + "incorrect value for amplitude_value[110], expected 45, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 146, + "incorrect value for amplitude_value[111], expected 146, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 59, + "incorrect value for amplitude_value[112], expected 59, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 82, + "incorrect value for amplitude_value[113], expected 82, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 194, + "incorrect value for amplitude_value[114], expected 194, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 4, + "incorrect value for amplitude_value[115], expected 4, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 179, + "incorrect value for amplitude_value[116], expected 179, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 148, + "incorrect value for amplitude_value[117], expected 148, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 66, + "incorrect value for amplitude_value[118], expected 66, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 254, + "incorrect value for amplitude_value[119], expected 254, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 115, + "incorrect value for amplitude_value[120], expected 115, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 77, + "incorrect value for amplitude_value[121], expected 77, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 30, + "incorrect value for amplitude_value[122], expected 30, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 46, + "incorrect value for amplitude_value[123], expected 46, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 4, + "incorrect value for amplitude_value[124], expected 4, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 204, + "incorrect value for amplitude_value[125], expected 204, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 37, + "incorrect value for amplitude_value[126], expected 37, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 200, + "incorrect value for amplitude_value[127], expected 200, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 121, + "incorrect value for amplitude_value[128], expected 121, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 18, + "incorrect value for amplitude_value[129], expected 18, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 17, + "incorrect value for amplitude_value[130], expected 17, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 171, + "incorrect value for amplitude_value[131], expected 171, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 102, + "incorrect value for amplitude_value[132], expected 102, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 163, + "incorrect value for amplitude_value[133], expected 163, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 175, + "incorrect value for amplitude_value[134], expected 175, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 50, + "incorrect value for amplitude_value[135], expected 50, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 66, + "incorrect value for amplitude_value[136], expected 66, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 101, + "incorrect value for amplitude_value[137], expected 101, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 69, + "incorrect value for amplitude_value[138], expected 69, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 13, + "incorrect value for amplitude_value[139], expected 13, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 223, + "incorrect value for amplitude_value[140], expected 223, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 172, + "incorrect value for amplitude_value[141], expected 172, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 160, + "incorrect value for amplitude_value[142], expected 160, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 233, + "incorrect value for amplitude_value[143], expected 233, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 220, + "incorrect value for amplitude_value[144], expected 220, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 101, + "incorrect value for amplitude_value[145], expected 101, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 237, + "incorrect value for amplitude_value[146], expected 237, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 156, + "incorrect value for amplitude_value[147], expected 156, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 62, + "incorrect value for amplitude_value[148], expected 62, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 117, + "incorrect value for amplitude_value[149], expected 117, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 47, + "incorrect value for amplitude_value[150], expected 47, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 143, + "incorrect value for amplitude_value[151], expected 143, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 94, + "incorrect value for amplitude_value[152], expected 94, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 135, + "incorrect value for amplitude_value[153], expected 135, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 22, + "incorrect value for amplitude_value[154], expected 22, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 155, + "incorrect value for amplitude_value[155], expected 155, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 113, + "incorrect value for amplitude_value[156], expected 113, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 110, + "incorrect value for amplitude_value[157], expected 110, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 15, + "incorrect value for amplitude_value[158], expected 15, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 243, + "incorrect value for amplitude_value[159], expected 243, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 141, + "incorrect value for amplitude_value[160], expected 141, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 227, + "incorrect value for amplitude_value[161], expected 227, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 46, + "incorrect value for amplitude_value[162], expected 46, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 143, + "incorrect value for amplitude_value[163], expected 143, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 227, + "incorrect value for amplitude_value[164], expected 227, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 209, + "incorrect value for amplitude_value[165], expected 209, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 249, + "incorrect value for amplitude_value[166], expected 249, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 2, + "incorrect value for amplitude_value[167], expected 2, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 153, + "incorrect value for amplitude_value[168], expected 153, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 168, + "incorrect value for amplitude_value[169], expected 168, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 131, + "incorrect value for amplitude_value[170], expected 131, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 249, + "incorrect value for amplitude_value[171], expected 249, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 160, + "incorrect value for amplitude_value[172], expected 160, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 88, + "incorrect value for amplitude_value[173], expected 88, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 38, + "incorrect value for amplitude_value[174], expected 38, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 117, + "incorrect value for amplitude_value[175], expected 117, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 129, + "incorrect value for amplitude_value[176], expected 129, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 57, + "incorrect value for amplitude_value[177], expected 57, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 40, + "incorrect value for amplitude_value[178], expected 40, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 109, + "incorrect value for amplitude_value[179], expected 109, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 209, + "incorrect value for amplitude_value[180], expected 209, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 177, + "incorrect value for amplitude_value[181], expected 177, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 38, + "incorrect value for amplitude_value[182], expected 38, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 47, + "incorrect value for amplitude_value[183], expected 47, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 12, + "incorrect value for amplitude_value[184], expected 12, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 15, + "incorrect value for amplitude_value[185], expected 15, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 16, + "incorrect value for amplitude_value[186], expected 16, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 9, + "incorrect value for amplitude_value[187], expected 9, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 175, + "incorrect value for amplitude_value[188], expected 175, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 69, + "incorrect value for amplitude_value[189], expected 69, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 70, + "incorrect value for amplitude_value[190], expected 70, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 182, + "incorrect value for amplitude_value[191], expected 182, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 239, + "incorrect value for amplitude_value[192], expected 239, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 117, + "incorrect value for amplitude_value[193], expected 117, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 135, + "incorrect value for amplitude_value[194], expected 135, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 6, + "incorrect value for amplitude_value[195], expected 6, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 71, + "incorrect value for amplitude_value[196], expected 71, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 99, + "incorrect value for amplitude_value[197], expected 99, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 230, + "incorrect value for amplitude_value[198], expected 230, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 115, + "incorrect value for amplitude_value[199], expected 115, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 2, + "incorrect value for amplitude_value[200], expected 2, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 71, + "incorrect value for amplitude_value[201], expected 71, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 165, + "incorrect value for amplitude_value[202], expected 165, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 228, + "incorrect value for amplitude_value[203], expected 228, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 123, + "incorrect value for amplitude_value[204], expected 123, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 210, + "incorrect value for amplitude_value[205], expected 210, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 168, + "incorrect value for amplitude_value[206], expected 168, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 90, + "incorrect value for amplitude_value[207], expected 90, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 124, + "incorrect value for amplitude_value[208], expected 124, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 20, + "incorrect value for amplitude_value[209], expected 20, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 7, + "incorrect value for amplitude_value[210], expected 7, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 220, + "incorrect value for amplitude_value[211], expected 220, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 144, + "incorrect value for amplitude_value[212], expected 144, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 168, + "incorrect value for amplitude_value[213], expected 168, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 69, + "incorrect value for amplitude_value[214], expected 69, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 22, + "incorrect value for amplitude_value[215], expected 22, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 72, + "incorrect value for amplitude_value[216], expected 72, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 162, + "incorrect value for amplitude_value[217], expected 162, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 69, + "incorrect value for amplitude_value[218], expected 69, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 111, + "incorrect value for amplitude_value[219], expected 111, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 91, + "incorrect value for amplitude_value[220], expected 91, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 251, + "incorrect value for amplitude_value[221], expected 251, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 72, + "incorrect value for amplitude_value[222], expected 72, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 220, + "incorrect value for amplitude_value[223], expected 220, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 28, + "incorrect value for amplitude_value[224], expected 28, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 119, + "incorrect value for amplitude_value[225], expected 119, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 150, + "incorrect value for amplitude_value[226], expected 150, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.channel_tag, 35146, + "incorrect value for channel_tag, expected 35146, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(7.73720019531250000e+03), + "incorrect value for freq_ref, expected 7.73720019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(8.22620019531250000e+03), + "incorrect value for freq_step, expected 8.22620019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.ns_residual, -1479025396, + "incorrect value for t.ns_residual, expected -1479025396, is {}", + msg.t.ns_residual + ); + assert_eq!( + msg.t.tow, 1227027783, + "incorrect value for t.tow, expected 1227027783, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 5075, + "incorrect value for t.wn, expected 5075, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecan"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_specan() { + { + let json_input = r#"{"preamble":85,"msg_type":81,"sender":54300,"length":255,"payload":"SolH9SJJDN3Xp9MTmsnxRc2IAEYzQ2xFZiamRGSzuRGvMcHk5C8hGI2xEmP2eT0oW5Hfp64JdAv3VDGZzQLmwtrxZWstiV1y5ivgF0rRx9OCWdyjRBT9B84ygXTCFx/i2Z3N3QXgXFJt38PppQFSjZ2xqfSDYG1v/ZUc4eFInp7SxM5GP+G4lq7wLZI7UsIEs5RC/nNNHi4EzCXIeRIRq2ajrzJCZUUN36yg6dxl7Zw+dS+PXocWm3FuD/ON4y6P49H5Apmog/mgWCZ1gTkobdGxJi8MDxAJr0VGtu91hwZHY+ZzAkel5HvSqFp8FAfckKhFFkiiRW9b+0jcHHeW","crc":607,"channel_tag":35146,"t":{"tow":1227027783,"ns_residual":-1479025396,"wn":5075},"freq_ref":7737.2001953125,"freq_step":8226.2001953125,"amplitude_ref":3780.199951171875,"amplitude_unit":1329.199951171875,"amplitude_value":[100,179,185,17,175,49,193,228,228,47,33,24,141,177,18,99,246,121,61,40,91,145,223,167,174,9,116,11,247,84,49,153,205,2,230,194,218,241,101,107,45,137,93,114,230,43,224,23,74,209,199,211,130,89,220,163,68,20,253,7,206,50,129,116,194,23,31,226,217,157,205,221,5,224,92,82,109,223,195,233,165,1,82,141,157,177,169,244,131,96,109,111,253,149,28,225,225,72,158,158,210,196,206,70,63,225,184,150,174,240,45,146,59,82,194,4,179,148,66,254,115,77,30,46,4,204,37,200,121,18,17,171,102,163,175,50,66,101,69,13,223,172,160,233,220,101,237,156,62,117,47,143,94,135,22,155,113,110,15,243,141,227,46,143,227,209,249,2,153,168,131,249,160,88,38,117,129,57,40,109,209,177,38,47,12,15,16,9,175,69,70,182,239,117,135,6,71,99,230,115,2,71,165,228,123,210,168,90,124,20,7,220,144,168,69,22,72,162,69,111,91,251,72,220,28,119,150]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSpecan(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x51, + "Incorrect message type, expected 0x51, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd41c, + "incorrect sender id, expected 0xd41c, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(3.78019995117187500e+03), + "incorrect value for amplitude_ref, expected 3.78019995117187500e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(1.32919995117187500e+03), + "incorrect value for amplitude_unit, expected 1.32919995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 100, + "incorrect value for amplitude_value[0], expected 100, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 179, + "incorrect value for amplitude_value[1], expected 179, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 185, + "incorrect value for amplitude_value[2], expected 185, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 17, + "incorrect value for amplitude_value[3], expected 17, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 175, + "incorrect value for amplitude_value[4], expected 175, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 49, + "incorrect value for amplitude_value[5], expected 49, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 193, + "incorrect value for amplitude_value[6], expected 193, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 228, + "incorrect value for amplitude_value[7], expected 228, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 228, + "incorrect value for amplitude_value[8], expected 228, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 47, + "incorrect value for amplitude_value[9], expected 47, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 33, + "incorrect value for amplitude_value[10], expected 33, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 24, + "incorrect value for amplitude_value[11], expected 24, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 141, + "incorrect value for amplitude_value[12], expected 141, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 177, + "incorrect value for amplitude_value[13], expected 177, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 18, + "incorrect value for amplitude_value[14], expected 18, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 99, + "incorrect value for amplitude_value[15], expected 99, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 246, + "incorrect value for amplitude_value[16], expected 246, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 121, + "incorrect value for amplitude_value[17], expected 121, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 61, + "incorrect value for amplitude_value[18], expected 61, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 40, + "incorrect value for amplitude_value[19], expected 40, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 91, + "incorrect value for amplitude_value[20], expected 91, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 145, + "incorrect value for amplitude_value[21], expected 145, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 223, + "incorrect value for amplitude_value[22], expected 223, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 167, + "incorrect value for amplitude_value[23], expected 167, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 174, + "incorrect value for amplitude_value[24], expected 174, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 9, + "incorrect value for amplitude_value[25], expected 9, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 116, + "incorrect value for amplitude_value[26], expected 116, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 11, + "incorrect value for amplitude_value[27], expected 11, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 247, + "incorrect value for amplitude_value[28], expected 247, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 84, + "incorrect value for amplitude_value[29], expected 84, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 49, + "incorrect value for amplitude_value[30], expected 49, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 153, + "incorrect value for amplitude_value[31], expected 153, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 205, + "incorrect value for amplitude_value[32], expected 205, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 2, + "incorrect value for amplitude_value[33], expected 2, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 230, + "incorrect value for amplitude_value[34], expected 230, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 194, + "incorrect value for amplitude_value[35], expected 194, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 218, + "incorrect value for amplitude_value[36], expected 218, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 241, + "incorrect value for amplitude_value[37], expected 241, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 101, + "incorrect value for amplitude_value[38], expected 101, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 107, + "incorrect value for amplitude_value[39], expected 107, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 45, + "incorrect value for amplitude_value[40], expected 45, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 137, + "incorrect value for amplitude_value[41], expected 137, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 93, + "incorrect value for amplitude_value[42], expected 93, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 114, + "incorrect value for amplitude_value[43], expected 114, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 230, + "incorrect value for amplitude_value[44], expected 230, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 43, + "incorrect value for amplitude_value[45], expected 43, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 224, + "incorrect value for amplitude_value[46], expected 224, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 23, + "incorrect value for amplitude_value[47], expected 23, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 74, + "incorrect value for amplitude_value[48], expected 74, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 209, + "incorrect value for amplitude_value[49], expected 209, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 199, + "incorrect value for amplitude_value[50], expected 199, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 211, + "incorrect value for amplitude_value[51], expected 211, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 130, + "incorrect value for amplitude_value[52], expected 130, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 89, + "incorrect value for amplitude_value[53], expected 89, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 220, + "incorrect value for amplitude_value[54], expected 220, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 163, + "incorrect value for amplitude_value[55], expected 163, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 68, + "incorrect value for amplitude_value[56], expected 68, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 20, + "incorrect value for amplitude_value[57], expected 20, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 253, + "incorrect value for amplitude_value[58], expected 253, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 7, + "incorrect value for amplitude_value[59], expected 7, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 206, + "incorrect value for amplitude_value[60], expected 206, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 50, + "incorrect value for amplitude_value[61], expected 50, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 129, + "incorrect value for amplitude_value[62], expected 129, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 116, + "incorrect value for amplitude_value[63], expected 116, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 194, + "incorrect value for amplitude_value[64], expected 194, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 23, + "incorrect value for amplitude_value[65], expected 23, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 31, + "incorrect value for amplitude_value[66], expected 31, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 226, + "incorrect value for amplitude_value[67], expected 226, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 217, + "incorrect value for amplitude_value[68], expected 217, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 157, + "incorrect value for amplitude_value[69], expected 157, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 205, + "incorrect value for amplitude_value[70], expected 205, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 221, + "incorrect value for amplitude_value[71], expected 221, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 5, + "incorrect value for amplitude_value[72], expected 5, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 224, + "incorrect value for amplitude_value[73], expected 224, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 92, + "incorrect value for amplitude_value[74], expected 92, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 82, + "incorrect value for amplitude_value[75], expected 82, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 109, + "incorrect value for amplitude_value[76], expected 109, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 223, + "incorrect value for amplitude_value[77], expected 223, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 195, + "incorrect value for amplitude_value[78], expected 195, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 233, + "incorrect value for amplitude_value[79], expected 233, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 165, + "incorrect value for amplitude_value[80], expected 165, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 1, + "incorrect value for amplitude_value[81], expected 1, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 82, + "incorrect value for amplitude_value[82], expected 82, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 141, + "incorrect value for amplitude_value[83], expected 141, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 157, + "incorrect value for amplitude_value[84], expected 157, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 177, + "incorrect value for amplitude_value[85], expected 177, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 169, + "incorrect value for amplitude_value[86], expected 169, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 244, + "incorrect value for amplitude_value[87], expected 244, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 131, + "incorrect value for amplitude_value[88], expected 131, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 96, + "incorrect value for amplitude_value[89], expected 96, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 109, + "incorrect value for amplitude_value[90], expected 109, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 111, + "incorrect value for amplitude_value[91], expected 111, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 253, + "incorrect value for amplitude_value[92], expected 253, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 149, + "incorrect value for amplitude_value[93], expected 149, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 28, + "incorrect value for amplitude_value[94], expected 28, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 225, + "incorrect value for amplitude_value[95], expected 225, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 225, + "incorrect value for amplitude_value[96], expected 225, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 72, + "incorrect value for amplitude_value[97], expected 72, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 158, + "incorrect value for amplitude_value[98], expected 158, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 158, + "incorrect value for amplitude_value[99], expected 158, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 210, + "incorrect value for amplitude_value[100], expected 210, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 196, + "incorrect value for amplitude_value[101], expected 196, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 206, + "incorrect value for amplitude_value[102], expected 206, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 70, + "incorrect value for amplitude_value[103], expected 70, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 63, + "incorrect value for amplitude_value[104], expected 63, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 225, + "incorrect value for amplitude_value[105], expected 225, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 184, + "incorrect value for amplitude_value[106], expected 184, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 150, + "incorrect value for amplitude_value[107], expected 150, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 174, + "incorrect value for amplitude_value[108], expected 174, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 240, + "incorrect value for amplitude_value[109], expected 240, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 45, + "incorrect value for amplitude_value[110], expected 45, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 146, + "incorrect value for amplitude_value[111], expected 146, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 59, + "incorrect value for amplitude_value[112], expected 59, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 82, + "incorrect value for amplitude_value[113], expected 82, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 194, + "incorrect value for amplitude_value[114], expected 194, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 4, + "incorrect value for amplitude_value[115], expected 4, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 179, + "incorrect value for amplitude_value[116], expected 179, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 148, + "incorrect value for amplitude_value[117], expected 148, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 66, + "incorrect value for amplitude_value[118], expected 66, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 254, + "incorrect value for amplitude_value[119], expected 254, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 115, + "incorrect value for amplitude_value[120], expected 115, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 77, + "incorrect value for amplitude_value[121], expected 77, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 30, + "incorrect value for amplitude_value[122], expected 30, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 46, + "incorrect value for amplitude_value[123], expected 46, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 4, + "incorrect value for amplitude_value[124], expected 4, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 204, + "incorrect value for amplitude_value[125], expected 204, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 37, + "incorrect value for amplitude_value[126], expected 37, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 200, + "incorrect value for amplitude_value[127], expected 200, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 121, + "incorrect value for amplitude_value[128], expected 121, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 18, + "incorrect value for amplitude_value[129], expected 18, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 17, + "incorrect value for amplitude_value[130], expected 17, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 171, + "incorrect value for amplitude_value[131], expected 171, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 102, + "incorrect value for amplitude_value[132], expected 102, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 163, + "incorrect value for amplitude_value[133], expected 163, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 175, + "incorrect value for amplitude_value[134], expected 175, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 50, + "incorrect value for amplitude_value[135], expected 50, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 66, + "incorrect value for amplitude_value[136], expected 66, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 101, + "incorrect value for amplitude_value[137], expected 101, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 69, + "incorrect value for amplitude_value[138], expected 69, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 13, + "incorrect value for amplitude_value[139], expected 13, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 223, + "incorrect value for amplitude_value[140], expected 223, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 172, + "incorrect value for amplitude_value[141], expected 172, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 160, + "incorrect value for amplitude_value[142], expected 160, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 233, + "incorrect value for amplitude_value[143], expected 233, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 220, + "incorrect value for amplitude_value[144], expected 220, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 101, + "incorrect value for amplitude_value[145], expected 101, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 237, + "incorrect value for amplitude_value[146], expected 237, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 156, + "incorrect value for amplitude_value[147], expected 156, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 62, + "incorrect value for amplitude_value[148], expected 62, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 117, + "incorrect value for amplitude_value[149], expected 117, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 47, + "incorrect value for amplitude_value[150], expected 47, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 143, + "incorrect value for amplitude_value[151], expected 143, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 94, + "incorrect value for amplitude_value[152], expected 94, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 135, + "incorrect value for amplitude_value[153], expected 135, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 22, + "incorrect value for amplitude_value[154], expected 22, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 155, + "incorrect value for amplitude_value[155], expected 155, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 113, + "incorrect value for amplitude_value[156], expected 113, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 110, + "incorrect value for amplitude_value[157], expected 110, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 15, + "incorrect value for amplitude_value[158], expected 15, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 243, + "incorrect value for amplitude_value[159], expected 243, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 141, + "incorrect value for amplitude_value[160], expected 141, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 227, + "incorrect value for amplitude_value[161], expected 227, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 46, + "incorrect value for amplitude_value[162], expected 46, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 143, + "incorrect value for amplitude_value[163], expected 143, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 227, + "incorrect value for amplitude_value[164], expected 227, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 209, + "incorrect value for amplitude_value[165], expected 209, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 249, + "incorrect value for amplitude_value[166], expected 249, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 2, + "incorrect value for amplitude_value[167], expected 2, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 153, + "incorrect value for amplitude_value[168], expected 153, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 168, + "incorrect value for amplitude_value[169], expected 168, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 131, + "incorrect value for amplitude_value[170], expected 131, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 249, + "incorrect value for amplitude_value[171], expected 249, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 160, + "incorrect value for amplitude_value[172], expected 160, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 88, + "incorrect value for amplitude_value[173], expected 88, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 38, + "incorrect value for amplitude_value[174], expected 38, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 117, + "incorrect value for amplitude_value[175], expected 117, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 129, + "incorrect value for amplitude_value[176], expected 129, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 57, + "incorrect value for amplitude_value[177], expected 57, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 40, + "incorrect value for amplitude_value[178], expected 40, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 109, + "incorrect value for amplitude_value[179], expected 109, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 209, + "incorrect value for amplitude_value[180], expected 209, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 177, + "incorrect value for amplitude_value[181], expected 177, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 38, + "incorrect value for amplitude_value[182], expected 38, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 47, + "incorrect value for amplitude_value[183], expected 47, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 12, + "incorrect value for amplitude_value[184], expected 12, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 15, + "incorrect value for amplitude_value[185], expected 15, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 16, + "incorrect value for amplitude_value[186], expected 16, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 9, + "incorrect value for amplitude_value[187], expected 9, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 175, + "incorrect value for amplitude_value[188], expected 175, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 69, + "incorrect value for amplitude_value[189], expected 69, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 70, + "incorrect value for amplitude_value[190], expected 70, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 182, + "incorrect value for amplitude_value[191], expected 182, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 239, + "incorrect value for amplitude_value[192], expected 239, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 117, + "incorrect value for amplitude_value[193], expected 117, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 135, + "incorrect value for amplitude_value[194], expected 135, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 6, + "incorrect value for amplitude_value[195], expected 6, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 71, + "incorrect value for amplitude_value[196], expected 71, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 99, + "incorrect value for amplitude_value[197], expected 99, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 230, + "incorrect value for amplitude_value[198], expected 230, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 115, + "incorrect value for amplitude_value[199], expected 115, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 2, + "incorrect value for amplitude_value[200], expected 2, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 71, + "incorrect value for amplitude_value[201], expected 71, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 165, + "incorrect value for amplitude_value[202], expected 165, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 228, + "incorrect value for amplitude_value[203], expected 228, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 123, + "incorrect value for amplitude_value[204], expected 123, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 210, + "incorrect value for amplitude_value[205], expected 210, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 168, + "incorrect value for amplitude_value[206], expected 168, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 90, + "incorrect value for amplitude_value[207], expected 90, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 124, + "incorrect value for amplitude_value[208], expected 124, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 20, + "incorrect value for amplitude_value[209], expected 20, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 7, + "incorrect value for amplitude_value[210], expected 7, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 220, + "incorrect value for amplitude_value[211], expected 220, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 144, + "incorrect value for amplitude_value[212], expected 144, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 168, + "incorrect value for amplitude_value[213], expected 168, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 69, + "incorrect value for amplitude_value[214], expected 69, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 22, + "incorrect value for amplitude_value[215], expected 22, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 72, + "incorrect value for amplitude_value[216], expected 72, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 162, + "incorrect value for amplitude_value[217], expected 162, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 69, + "incorrect value for amplitude_value[218], expected 69, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 111, + "incorrect value for amplitude_value[219], expected 111, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 91, + "incorrect value for amplitude_value[220], expected 91, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 251, + "incorrect value for amplitude_value[221], expected 251, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 72, + "incorrect value for amplitude_value[222], expected 72, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 220, + "incorrect value for amplitude_value[223], expected 220, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 28, + "incorrect value for amplitude_value[224], expected 28, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 119, + "incorrect value for amplitude_value[225], expected 119, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 150, + "incorrect value for amplitude_value[226], expected 150, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.channel_tag, 35146, + "incorrect value for channel_tag, expected 35146, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(7.73720019531250000e+03), + "incorrect value for freq_ref, expected 7.73720019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(8.22620019531250000e+03), + "incorrect value for freq_step, expected 8.22620019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.ns_residual, -1479025396, + "incorrect value for t.ns_residual, expected -1479025396, is {}", + msg.t.ns_residual + ); + assert_eq!( + msg.t.tow, 1227027783, + "incorrect value for t.tow, expected 1227027783, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 5075, + "incorrect value for t.wn, expected 5075, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecan"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_specan`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_specan() { + { + let mut payload = Cursor::new(vec![ + 85, 81, 0, 28, 212, 255, 74, 137, 71, 245, 34, 73, 12, 221, 215, 167, 211, 19, 154, + 201, 241, 69, 205, 136, 0, 70, 51, 67, 108, 69, 102, 38, 166, 68, 100, 179, 185, 17, + 175, 49, 193, 228, 228, 47, 33, 24, 141, 177, 18, 99, 246, 121, 61, 40, 91, 145, 223, + 167, 174, 9, 116, 11, 247, 84, 49, 153, 205, 2, 230, 194, 218, 241, 101, 107, 45, 137, + 93, 114, 230, 43, 224, 23, 74, 209, 199, 211, 130, 89, 220, 163, 68, 20, 253, 7, 206, + 50, 129, 116, 194, 23, 31, 226, 217, 157, 205, 221, 5, 224, 92, 82, 109, 223, 195, 233, + 165, 1, 82, 141, 157, 177, 169, 244, 131, 96, 109, 111, 253, 149, 28, 225, 225, 72, + 158, 158, 210, 196, 206, 70, 63, 225, 184, 150, 174, 240, 45, 146, 59, 82, 194, 4, 179, + 148, 66, 254, 115, 77, 30, 46, 4, 204, 37, 200, 121, 18, 17, 171, 102, 163, 175, 50, + 66, 101, 69, 13, 223, 172, 160, 233, 220, 101, 237, 156, 62, 117, 47, 143, 94, 135, 22, + 155, 113, 110, 15, 243, 141, 227, 46, 143, 227, 209, 249, 2, 153, 168, 131, 249, 160, + 88, 38, 117, 129, 57, 40, 109, 209, 177, 38, 47, 12, 15, 16, 9, 175, 69, 70, 182, 239, + 117, 135, 6, 71, 99, 230, 115, 2, 71, 165, 228, 123, 210, 168, 90, 124, 20, 7, 220, + 144, 168, 69, 22, 72, 162, 69, 111, 91, 251, 72, 220, 28, 119, 150, 95, 2, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSpecan( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSpecan(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x51, + "Incorrect message type, expected 0x51, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd41c, + "incorrect sender id, expected 0xd41c, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(3.78019995117187500e+03), + "incorrect value for amplitude_ref, expected 3.78019995117187500e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(1.32919995117187500e+03), + "incorrect value for amplitude_unit, expected 1.32919995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 100, + "incorrect value for amplitude_value[0], expected 100, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 179, + "incorrect value for amplitude_value[1], expected 179, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 185, + "incorrect value for amplitude_value[2], expected 185, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 17, + "incorrect value for amplitude_value[3], expected 17, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 175, + "incorrect value for amplitude_value[4], expected 175, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 49, + "incorrect value for amplitude_value[5], expected 49, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 193, + "incorrect value for amplitude_value[6], expected 193, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 228, + "incorrect value for amplitude_value[7], expected 228, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 228, + "incorrect value for amplitude_value[8], expected 228, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 47, + "incorrect value for amplitude_value[9], expected 47, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 33, + "incorrect value for amplitude_value[10], expected 33, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 24, + "incorrect value for amplitude_value[11], expected 24, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 141, + "incorrect value for amplitude_value[12], expected 141, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 177, + "incorrect value for amplitude_value[13], expected 177, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 18, + "incorrect value for amplitude_value[14], expected 18, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 99, + "incorrect value for amplitude_value[15], expected 99, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 246, + "incorrect value for amplitude_value[16], expected 246, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 121, + "incorrect value for amplitude_value[17], expected 121, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 61, + "incorrect value for amplitude_value[18], expected 61, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 40, + "incorrect value for amplitude_value[19], expected 40, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 91, + "incorrect value for amplitude_value[20], expected 91, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 145, + "incorrect value for amplitude_value[21], expected 145, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 223, + "incorrect value for amplitude_value[22], expected 223, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 167, + "incorrect value for amplitude_value[23], expected 167, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 174, + "incorrect value for amplitude_value[24], expected 174, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 9, + "incorrect value for amplitude_value[25], expected 9, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 116, + "incorrect value for amplitude_value[26], expected 116, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 11, + "incorrect value for amplitude_value[27], expected 11, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 247, + "incorrect value for amplitude_value[28], expected 247, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 84, + "incorrect value for amplitude_value[29], expected 84, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 49, + "incorrect value for amplitude_value[30], expected 49, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 153, + "incorrect value for amplitude_value[31], expected 153, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 205, + "incorrect value for amplitude_value[32], expected 205, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 2, + "incorrect value for amplitude_value[33], expected 2, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 230, + "incorrect value for amplitude_value[34], expected 230, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 194, + "incorrect value for amplitude_value[35], expected 194, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 218, + "incorrect value for amplitude_value[36], expected 218, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 241, + "incorrect value for amplitude_value[37], expected 241, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 101, + "incorrect value for amplitude_value[38], expected 101, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 107, + "incorrect value for amplitude_value[39], expected 107, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 45, + "incorrect value for amplitude_value[40], expected 45, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 137, + "incorrect value for amplitude_value[41], expected 137, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 93, + "incorrect value for amplitude_value[42], expected 93, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 114, + "incorrect value for amplitude_value[43], expected 114, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 230, + "incorrect value for amplitude_value[44], expected 230, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 43, + "incorrect value for amplitude_value[45], expected 43, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 224, + "incorrect value for amplitude_value[46], expected 224, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 23, + "incorrect value for amplitude_value[47], expected 23, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 74, + "incorrect value for amplitude_value[48], expected 74, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 209, + "incorrect value for amplitude_value[49], expected 209, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 199, + "incorrect value for amplitude_value[50], expected 199, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 211, + "incorrect value for amplitude_value[51], expected 211, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 130, + "incorrect value for amplitude_value[52], expected 130, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 89, + "incorrect value for amplitude_value[53], expected 89, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 220, + "incorrect value for amplitude_value[54], expected 220, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 163, + "incorrect value for amplitude_value[55], expected 163, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 68, + "incorrect value for amplitude_value[56], expected 68, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 20, + "incorrect value for amplitude_value[57], expected 20, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 253, + "incorrect value for amplitude_value[58], expected 253, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 7, + "incorrect value for amplitude_value[59], expected 7, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 206, + "incorrect value for amplitude_value[60], expected 206, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 50, + "incorrect value for amplitude_value[61], expected 50, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 129, + "incorrect value for amplitude_value[62], expected 129, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 116, + "incorrect value for amplitude_value[63], expected 116, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 194, + "incorrect value for amplitude_value[64], expected 194, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 23, + "incorrect value for amplitude_value[65], expected 23, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 31, + "incorrect value for amplitude_value[66], expected 31, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 226, + "incorrect value for amplitude_value[67], expected 226, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 217, + "incorrect value for amplitude_value[68], expected 217, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 157, + "incorrect value for amplitude_value[69], expected 157, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 205, + "incorrect value for amplitude_value[70], expected 205, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 221, + "incorrect value for amplitude_value[71], expected 221, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 5, + "incorrect value for amplitude_value[72], expected 5, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 224, + "incorrect value for amplitude_value[73], expected 224, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 92, + "incorrect value for amplitude_value[74], expected 92, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 82, + "incorrect value for amplitude_value[75], expected 82, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 109, + "incorrect value for amplitude_value[76], expected 109, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 223, + "incorrect value for amplitude_value[77], expected 223, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 195, + "incorrect value for amplitude_value[78], expected 195, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 233, + "incorrect value for amplitude_value[79], expected 233, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 165, + "incorrect value for amplitude_value[80], expected 165, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 1, + "incorrect value for amplitude_value[81], expected 1, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 82, + "incorrect value for amplitude_value[82], expected 82, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 141, + "incorrect value for amplitude_value[83], expected 141, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 157, + "incorrect value for amplitude_value[84], expected 157, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 177, + "incorrect value for amplitude_value[85], expected 177, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 169, + "incorrect value for amplitude_value[86], expected 169, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 244, + "incorrect value for amplitude_value[87], expected 244, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 131, + "incorrect value for amplitude_value[88], expected 131, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 96, + "incorrect value for amplitude_value[89], expected 96, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 109, + "incorrect value for amplitude_value[90], expected 109, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 111, + "incorrect value for amplitude_value[91], expected 111, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 253, + "incorrect value for amplitude_value[92], expected 253, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 149, + "incorrect value for amplitude_value[93], expected 149, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 28, + "incorrect value for amplitude_value[94], expected 28, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 225, + "incorrect value for amplitude_value[95], expected 225, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 225, + "incorrect value for amplitude_value[96], expected 225, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 72, + "incorrect value for amplitude_value[97], expected 72, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 158, + "incorrect value for amplitude_value[98], expected 158, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 158, + "incorrect value for amplitude_value[99], expected 158, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 210, + "incorrect value for amplitude_value[100], expected 210, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 196, + "incorrect value for amplitude_value[101], expected 196, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 206, + "incorrect value for amplitude_value[102], expected 206, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 70, + "incorrect value for amplitude_value[103], expected 70, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 63, + "incorrect value for amplitude_value[104], expected 63, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 225, + "incorrect value for amplitude_value[105], expected 225, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 184, + "incorrect value for amplitude_value[106], expected 184, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 150, + "incorrect value for amplitude_value[107], expected 150, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 174, + "incorrect value for amplitude_value[108], expected 174, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 240, + "incorrect value for amplitude_value[109], expected 240, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 45, + "incorrect value for amplitude_value[110], expected 45, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 146, + "incorrect value for amplitude_value[111], expected 146, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 59, + "incorrect value for amplitude_value[112], expected 59, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 82, + "incorrect value for amplitude_value[113], expected 82, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 194, + "incorrect value for amplitude_value[114], expected 194, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 4, + "incorrect value for amplitude_value[115], expected 4, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 179, + "incorrect value for amplitude_value[116], expected 179, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 148, + "incorrect value for amplitude_value[117], expected 148, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 66, + "incorrect value for amplitude_value[118], expected 66, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 254, + "incorrect value for amplitude_value[119], expected 254, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 115, + "incorrect value for amplitude_value[120], expected 115, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 77, + "incorrect value for amplitude_value[121], expected 77, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 30, + "incorrect value for amplitude_value[122], expected 30, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 46, + "incorrect value for amplitude_value[123], expected 46, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 4, + "incorrect value for amplitude_value[124], expected 4, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 204, + "incorrect value for amplitude_value[125], expected 204, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 37, + "incorrect value for amplitude_value[126], expected 37, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 200, + "incorrect value for amplitude_value[127], expected 200, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 121, + "incorrect value for amplitude_value[128], expected 121, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 18, + "incorrect value for amplitude_value[129], expected 18, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 17, + "incorrect value for amplitude_value[130], expected 17, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 171, + "incorrect value for amplitude_value[131], expected 171, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 102, + "incorrect value for amplitude_value[132], expected 102, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 163, + "incorrect value for amplitude_value[133], expected 163, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 175, + "incorrect value for amplitude_value[134], expected 175, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 50, + "incorrect value for amplitude_value[135], expected 50, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 66, + "incorrect value for amplitude_value[136], expected 66, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 101, + "incorrect value for amplitude_value[137], expected 101, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 69, + "incorrect value for amplitude_value[138], expected 69, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 13, + "incorrect value for amplitude_value[139], expected 13, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 223, + "incorrect value for amplitude_value[140], expected 223, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 172, + "incorrect value for amplitude_value[141], expected 172, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 160, + "incorrect value for amplitude_value[142], expected 160, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 233, + "incorrect value for amplitude_value[143], expected 233, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 220, + "incorrect value for amplitude_value[144], expected 220, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 101, + "incorrect value for amplitude_value[145], expected 101, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 237, + "incorrect value for amplitude_value[146], expected 237, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 156, + "incorrect value for amplitude_value[147], expected 156, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 62, + "incorrect value for amplitude_value[148], expected 62, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 117, + "incorrect value for amplitude_value[149], expected 117, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 47, + "incorrect value for amplitude_value[150], expected 47, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 143, + "incorrect value for amplitude_value[151], expected 143, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 94, + "incorrect value for amplitude_value[152], expected 94, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 135, + "incorrect value for amplitude_value[153], expected 135, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 22, + "incorrect value for amplitude_value[154], expected 22, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 155, + "incorrect value for amplitude_value[155], expected 155, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 113, + "incorrect value for amplitude_value[156], expected 113, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 110, + "incorrect value for amplitude_value[157], expected 110, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 15, + "incorrect value for amplitude_value[158], expected 15, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 243, + "incorrect value for amplitude_value[159], expected 243, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 141, + "incorrect value for amplitude_value[160], expected 141, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 227, + "incorrect value for amplitude_value[161], expected 227, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 46, + "incorrect value for amplitude_value[162], expected 46, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 143, + "incorrect value for amplitude_value[163], expected 143, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 227, + "incorrect value for amplitude_value[164], expected 227, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 209, + "incorrect value for amplitude_value[165], expected 209, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 249, + "incorrect value for amplitude_value[166], expected 249, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 2, + "incorrect value for amplitude_value[167], expected 2, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 153, + "incorrect value for amplitude_value[168], expected 153, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 168, + "incorrect value for amplitude_value[169], expected 168, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 131, + "incorrect value for amplitude_value[170], expected 131, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 249, + "incorrect value for amplitude_value[171], expected 249, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 160, + "incorrect value for amplitude_value[172], expected 160, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 88, + "incorrect value for amplitude_value[173], expected 88, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 38, + "incorrect value for amplitude_value[174], expected 38, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 117, + "incorrect value for amplitude_value[175], expected 117, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 129, + "incorrect value for amplitude_value[176], expected 129, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 57, + "incorrect value for amplitude_value[177], expected 57, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 40, + "incorrect value for amplitude_value[178], expected 40, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 109, + "incorrect value for amplitude_value[179], expected 109, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 209, + "incorrect value for amplitude_value[180], expected 209, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 177, + "incorrect value for amplitude_value[181], expected 177, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 38, + "incorrect value for amplitude_value[182], expected 38, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 47, + "incorrect value for amplitude_value[183], expected 47, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 12, + "incorrect value for amplitude_value[184], expected 12, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 15, + "incorrect value for amplitude_value[185], expected 15, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 16, + "incorrect value for amplitude_value[186], expected 16, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 9, + "incorrect value for amplitude_value[187], expected 9, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 175, + "incorrect value for amplitude_value[188], expected 175, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 69, + "incorrect value for amplitude_value[189], expected 69, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 70, + "incorrect value for amplitude_value[190], expected 70, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 182, + "incorrect value for amplitude_value[191], expected 182, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 239, + "incorrect value for amplitude_value[192], expected 239, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 117, + "incorrect value for amplitude_value[193], expected 117, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 135, + "incorrect value for amplitude_value[194], expected 135, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 6, + "incorrect value for amplitude_value[195], expected 6, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 71, + "incorrect value for amplitude_value[196], expected 71, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 99, + "incorrect value for amplitude_value[197], expected 99, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 230, + "incorrect value for amplitude_value[198], expected 230, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 115, + "incorrect value for amplitude_value[199], expected 115, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 2, + "incorrect value for amplitude_value[200], expected 2, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 71, + "incorrect value for amplitude_value[201], expected 71, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 165, + "incorrect value for amplitude_value[202], expected 165, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 228, + "incorrect value for amplitude_value[203], expected 228, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 123, + "incorrect value for amplitude_value[204], expected 123, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 210, + "incorrect value for amplitude_value[205], expected 210, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 168, + "incorrect value for amplitude_value[206], expected 168, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 90, + "incorrect value for amplitude_value[207], expected 90, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 124, + "incorrect value for amplitude_value[208], expected 124, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 20, + "incorrect value for amplitude_value[209], expected 20, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 7, + "incorrect value for amplitude_value[210], expected 7, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 220, + "incorrect value for amplitude_value[211], expected 220, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 144, + "incorrect value for amplitude_value[212], expected 144, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 168, + "incorrect value for amplitude_value[213], expected 168, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 69, + "incorrect value for amplitude_value[214], expected 69, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 22, + "incorrect value for amplitude_value[215], expected 22, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 72, + "incorrect value for amplitude_value[216], expected 72, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 162, + "incorrect value for amplitude_value[217], expected 162, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 69, + "incorrect value for amplitude_value[218], expected 69, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 111, + "incorrect value for amplitude_value[219], expected 111, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 91, + "incorrect value for amplitude_value[220], expected 91, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 251, + "incorrect value for amplitude_value[221], expected 251, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 72, + "incorrect value for amplitude_value[222], expected 72, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 220, + "incorrect value for amplitude_value[223], expected 220, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 28, + "incorrect value for amplitude_value[224], expected 28, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 119, + "incorrect value for amplitude_value[225], expected 119, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 150, + "incorrect value for amplitude_value[226], expected 150, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.channel_tag, 35146, + "incorrect value for channel_tag, expected 35146, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(7.73720019531250000e+03), + "incorrect value for freq_ref, expected 7.73720019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(8.22620019531250000e+03), + "incorrect value for freq_step, expected 8.22620019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.ns_residual, -1479025396, + "incorrect value for t.ns_residual, expected -1479025396, is {}", + msg.t.ns_residual + ); + assert_eq!( + msg.t.tow, 1227027783, + "incorrect value for t.tow, expected 1227027783, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 5075, + "incorrect value for t.wn, expected 5075, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecan"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan_dep.rs new file mode 100644 index 0000000000..706cda23a4 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_specan_dep.rs @@ -0,0 +1,3763 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_msg_specan_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, 154, 97, 198, 69, 154, 1, + 144, 69, 205, 20, 18, 70, 51, 211, 89, 69, 240, 14, 179, 186, 227, 244, 173, 240, 182, + 71, 166, 117, 196, 13, 44, 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, 77, 186, 68, + 135, 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, 216, 44, 67, 212, 156, 75, 81, 53, + 250, 225, 23, 205, 26, 34, 119, 50, 101, 64, 7, 231, 124, 183, 203, 102, 234, 84, 83, + 208, 23, 68, 54, 179, 98, 96, 116, 244, 246, 94, 104, 94, 13, 56, 210, 18, 191, 22, + 133, 81, 153, 159, 161, 219, 59, 21, 164, 121, 145, 203, 171, 132, 57, 180, 102, 101, + 11, 229, 175, 145, 73, 72, 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, 193, 7, 109, + 44, 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, 231, 161, 81, 216, 114, 60, 231, + 163, 163, 49, 237, 244, 185, 240, 89, 143, 174, 165, 211, 241, 13, 16, 61, 141, 101, + 89, 37, 117, 189, 86, 118, 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, + 100, 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, 181, 12, 140, 16, + 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, 59, 64, 241, 183, 238, 105, 181, 170, 45, + 8, 166, 164, 238, 83, 148, 173, 108, 228, 67, 89, 189, 67, 26, 39, 216, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSpecanDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x50, + "Incorrect message type, expected 0x50, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd970, + "incorrect sender id, expected 0xd970, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(9.34920019531250000e+03), + "incorrect value for amplitude_ref, expected 9.34920019531250000e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(3.48519995117187500e+03), + "incorrect value for amplitude_unit, expected 3.48519995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 240, + "incorrect value for amplitude_value[0], expected 240, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 14, + "incorrect value for amplitude_value[1], expected 14, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 179, + "incorrect value for amplitude_value[2], expected 179, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 186, + "incorrect value for amplitude_value[3], expected 186, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 227, + "incorrect value for amplitude_value[4], expected 227, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 244, + "incorrect value for amplitude_value[5], expected 244, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 173, + "incorrect value for amplitude_value[6], expected 173, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 240, + "incorrect value for amplitude_value[7], expected 240, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 182, + "incorrect value for amplitude_value[8], expected 182, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 71, + "incorrect value for amplitude_value[9], expected 71, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 166, + "incorrect value for amplitude_value[10], expected 166, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 117, + "incorrect value for amplitude_value[11], expected 117, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 196, + "incorrect value for amplitude_value[12], expected 196, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 13, + "incorrect value for amplitude_value[13], expected 13, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 44, + "incorrect value for amplitude_value[14], expected 44, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 27, + "incorrect value for amplitude_value[15], expected 27, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 33, + "incorrect value for amplitude_value[16], expected 33, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 28, + "incorrect value for amplitude_value[17], expected 28, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 67, + "incorrect value for amplitude_value[18], expected 67, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 254, + "incorrect value for amplitude_value[19], expected 254, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 3, + "incorrect value for amplitude_value[20], expected 3, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 249, + "incorrect value for amplitude_value[21], expected 249, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 92, + "incorrect value for amplitude_value[22], expected 92, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 44, + "incorrect value for amplitude_value[23], expected 44, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 122, + "incorrect value for amplitude_value[24], expected 122, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 169, + "incorrect value for amplitude_value[25], expected 169, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 77, + "incorrect value for amplitude_value[26], expected 77, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 186, + "incorrect value for amplitude_value[27], expected 186, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 68, + "incorrect value for amplitude_value[28], expected 68, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 135, + "incorrect value for amplitude_value[29], expected 135, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 63, + "incorrect value for amplitude_value[30], expected 63, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 168, + "incorrect value for amplitude_value[31], expected 168, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 162, + "incorrect value for amplitude_value[32], expected 162, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 89, + "incorrect value for amplitude_value[33], expected 89, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 36, + "incorrect value for amplitude_value[34], expected 36, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 186, + "incorrect value for amplitude_value[35], expected 186, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 99, + "incorrect value for amplitude_value[36], expected 99, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 63, + "incorrect value for amplitude_value[37], expected 63, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 105, + "incorrect value for amplitude_value[38], expected 105, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 116, + "incorrect value for amplitude_value[39], expected 116, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 216, + "incorrect value for amplitude_value[40], expected 216, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 44, + "incorrect value for amplitude_value[41], expected 44, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 67, + "incorrect value for amplitude_value[42], expected 67, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 212, + "incorrect value for amplitude_value[43], expected 212, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 156, + "incorrect value for amplitude_value[44], expected 156, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 75, + "incorrect value for amplitude_value[45], expected 75, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 81, + "incorrect value for amplitude_value[46], expected 81, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 53, + "incorrect value for amplitude_value[47], expected 53, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 250, + "incorrect value for amplitude_value[48], expected 250, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 225, + "incorrect value for amplitude_value[49], expected 225, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 23, + "incorrect value for amplitude_value[50], expected 23, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 205, + "incorrect value for amplitude_value[51], expected 205, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 26, + "incorrect value for amplitude_value[52], expected 26, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 34, + "incorrect value for amplitude_value[53], expected 34, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 119, + "incorrect value for amplitude_value[54], expected 119, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 50, + "incorrect value for amplitude_value[55], expected 50, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 101, + "incorrect value for amplitude_value[56], expected 101, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 64, + "incorrect value for amplitude_value[57], expected 64, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 7, + "incorrect value for amplitude_value[58], expected 7, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 231, + "incorrect value for amplitude_value[59], expected 231, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 124, + "incorrect value for amplitude_value[60], expected 124, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 183, + "incorrect value for amplitude_value[61], expected 183, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 203, + "incorrect value for amplitude_value[62], expected 203, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 102, + "incorrect value for amplitude_value[63], expected 102, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 234, + "incorrect value for amplitude_value[64], expected 234, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 84, + "incorrect value for amplitude_value[65], expected 84, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 83, + "incorrect value for amplitude_value[66], expected 83, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 208, + "incorrect value for amplitude_value[67], expected 208, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 23, + "incorrect value for amplitude_value[68], expected 23, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 68, + "incorrect value for amplitude_value[69], expected 68, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 54, + "incorrect value for amplitude_value[70], expected 54, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 179, + "incorrect value for amplitude_value[71], expected 179, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 98, + "incorrect value for amplitude_value[72], expected 98, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 96, + "incorrect value for amplitude_value[73], expected 96, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 116, + "incorrect value for amplitude_value[74], expected 116, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 244, + "incorrect value for amplitude_value[75], expected 244, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 246, + "incorrect value for amplitude_value[76], expected 246, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 94, + "incorrect value for amplitude_value[77], expected 94, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 104, + "incorrect value for amplitude_value[78], expected 104, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 94, + "incorrect value for amplitude_value[79], expected 94, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 13, + "incorrect value for amplitude_value[80], expected 13, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 56, + "incorrect value for amplitude_value[81], expected 56, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 210, + "incorrect value for amplitude_value[82], expected 210, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 18, + "incorrect value for amplitude_value[83], expected 18, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 191, + "incorrect value for amplitude_value[84], expected 191, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 22, + "incorrect value for amplitude_value[85], expected 22, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 133, + "incorrect value for amplitude_value[86], expected 133, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 81, + "incorrect value for amplitude_value[87], expected 81, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 153, + "incorrect value for amplitude_value[88], expected 153, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 159, + "incorrect value for amplitude_value[89], expected 159, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 161, + "incorrect value for amplitude_value[90], expected 161, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 219, + "incorrect value for amplitude_value[91], expected 219, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 59, + "incorrect value for amplitude_value[92], expected 59, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 21, + "incorrect value for amplitude_value[93], expected 21, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 164, + "incorrect value for amplitude_value[94], expected 164, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 121, + "incorrect value for amplitude_value[95], expected 121, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 145, + "incorrect value for amplitude_value[96], expected 145, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 203, + "incorrect value for amplitude_value[97], expected 203, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 171, + "incorrect value for amplitude_value[98], expected 171, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 132, + "incorrect value for amplitude_value[99], expected 132, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 57, + "incorrect value for amplitude_value[100], expected 57, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 180, + "incorrect value for amplitude_value[101], expected 180, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 102, + "incorrect value for amplitude_value[102], expected 102, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 101, + "incorrect value for amplitude_value[103], expected 101, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 11, + "incorrect value for amplitude_value[104], expected 11, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 229, + "incorrect value for amplitude_value[105], expected 229, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 175, + "incorrect value for amplitude_value[106], expected 175, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 145, + "incorrect value for amplitude_value[107], expected 145, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 73, + "incorrect value for amplitude_value[108], expected 73, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 72, + "incorrect value for amplitude_value[109], expected 72, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 124, + "incorrect value for amplitude_value[110], expected 124, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 4, + "incorrect value for amplitude_value[111], expected 4, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 184, + "incorrect value for amplitude_value[112], expected 184, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 228, + "incorrect value for amplitude_value[113], expected 228, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 61, + "incorrect value for amplitude_value[114], expected 61, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 234, + "incorrect value for amplitude_value[115], expected 234, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 218, + "incorrect value for amplitude_value[116], expected 218, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 62, + "incorrect value for amplitude_value[117], expected 62, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 226, + "incorrect value for amplitude_value[118], expected 226, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 217, + "incorrect value for amplitude_value[119], expected 217, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 193, + "incorrect value for amplitude_value[120], expected 193, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 7, + "incorrect value for amplitude_value[121], expected 7, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 109, + "incorrect value for amplitude_value[122], expected 109, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 44, + "incorrect value for amplitude_value[123], expected 44, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 83, + "incorrect value for amplitude_value[124], expected 83, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 201, + "incorrect value for amplitude_value[125], expected 201, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 20, + "incorrect value for amplitude_value[126], expected 20, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 101, + "incorrect value for amplitude_value[127], expected 101, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 9, + "incorrect value for amplitude_value[128], expected 9, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 140, + "incorrect value for amplitude_value[129], expected 140, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 186, + "incorrect value for amplitude_value[130], expected 186, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 162, + "incorrect value for amplitude_value[131], expected 162, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 81, + "incorrect value for amplitude_value[132], expected 81, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 91, + "incorrect value for amplitude_value[133], expected 91, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 30, + "incorrect value for amplitude_value[134], expected 30, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 231, + "incorrect value for amplitude_value[135], expected 231, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 161, + "incorrect value for amplitude_value[136], expected 161, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 81, + "incorrect value for amplitude_value[137], expected 81, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 216, + "incorrect value for amplitude_value[138], expected 216, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 114, + "incorrect value for amplitude_value[139], expected 114, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 60, + "incorrect value for amplitude_value[140], expected 60, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 231, + "incorrect value for amplitude_value[141], expected 231, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 163, + "incorrect value for amplitude_value[142], expected 163, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 163, + "incorrect value for amplitude_value[143], expected 163, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 49, + "incorrect value for amplitude_value[144], expected 49, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 237, + "incorrect value for amplitude_value[145], expected 237, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 244, + "incorrect value for amplitude_value[146], expected 244, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 185, + "incorrect value for amplitude_value[147], expected 185, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 240, + "incorrect value for amplitude_value[148], expected 240, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 89, + "incorrect value for amplitude_value[149], expected 89, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 143, + "incorrect value for amplitude_value[150], expected 143, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 174, + "incorrect value for amplitude_value[151], expected 174, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 165, + "incorrect value for amplitude_value[152], expected 165, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 211, + "incorrect value for amplitude_value[153], expected 211, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 241, + "incorrect value for amplitude_value[154], expected 241, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 13, + "incorrect value for amplitude_value[155], expected 13, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 16, + "incorrect value for amplitude_value[156], expected 16, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 61, + "incorrect value for amplitude_value[157], expected 61, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 141, + "incorrect value for amplitude_value[158], expected 141, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 101, + "incorrect value for amplitude_value[159], expected 101, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 89, + "incorrect value for amplitude_value[160], expected 89, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 37, + "incorrect value for amplitude_value[161], expected 37, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 117, + "incorrect value for amplitude_value[162], expected 117, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 189, + "incorrect value for amplitude_value[163], expected 189, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 86, + "incorrect value for amplitude_value[164], expected 86, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 118, + "incorrect value for amplitude_value[165], expected 118, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 176, + "incorrect value for amplitude_value[166], expected 176, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 228, + "incorrect value for amplitude_value[167], expected 228, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 12, + "incorrect value for amplitude_value[168], expected 12, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 14, + "incorrect value for amplitude_value[169], expected 14, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 119, + "incorrect value for amplitude_value[170], expected 119, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 135, + "incorrect value for amplitude_value[171], expected 135, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 129, + "incorrect value for amplitude_value[172], expected 129, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 243, + "incorrect value for amplitude_value[173], expected 243, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 50, + "incorrect value for amplitude_value[174], expected 50, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 29, + "incorrect value for amplitude_value[175], expected 29, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 207, + "incorrect value for amplitude_value[176], expected 207, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 198, + "incorrect value for amplitude_value[177], expected 198, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 117, + "incorrect value for amplitude_value[178], expected 117, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 100, + "incorrect value for amplitude_value[179], expected 100, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 225, + "incorrect value for amplitude_value[180], expected 225, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 6, + "incorrect value for amplitude_value[181], expected 6, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 139, + "incorrect value for amplitude_value[182], expected 139, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 110, + "incorrect value for amplitude_value[183], expected 110, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 39, + "incorrect value for amplitude_value[184], expected 39, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 210, + "incorrect value for amplitude_value[185], expected 210, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 68, + "incorrect value for amplitude_value[186], expected 68, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 199, + "incorrect value for amplitude_value[187], expected 199, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 43, + "incorrect value for amplitude_value[188], expected 43, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 132, + "incorrect value for amplitude_value[189], expected 132, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 64, + "incorrect value for amplitude_value[190], expected 64, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 17, + "incorrect value for amplitude_value[191], expected 17, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 51, + "incorrect value for amplitude_value[192], expected 51, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 173, + "incorrect value for amplitude_value[193], expected 173, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 181, + "incorrect value for amplitude_value[194], expected 181, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 12, + "incorrect value for amplitude_value[195], expected 12, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 140, + "incorrect value for amplitude_value[196], expected 140, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 16, + "incorrect value for amplitude_value[197], expected 16, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 247, + "incorrect value for amplitude_value[198], expected 247, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 84, + "incorrect value for amplitude_value[199], expected 84, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 183, + "incorrect value for amplitude_value[200], expected 183, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 105, + "incorrect value for amplitude_value[201], expected 105, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 39, + "incorrect value for amplitude_value[202], expected 39, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 157, + "incorrect value for amplitude_value[203], expected 157, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 77, + "incorrect value for amplitude_value[204], expected 77, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 30, + "incorrect value for amplitude_value[205], expected 30, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 205, + "incorrect value for amplitude_value[206], expected 205, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 194, + "incorrect value for amplitude_value[207], expected 194, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 59, + "incorrect value for amplitude_value[208], expected 59, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 64, + "incorrect value for amplitude_value[209], expected 64, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 241, + "incorrect value for amplitude_value[210], expected 241, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 183, + "incorrect value for amplitude_value[211], expected 183, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 238, + "incorrect value for amplitude_value[212], expected 238, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 105, + "incorrect value for amplitude_value[213], expected 105, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 181, + "incorrect value for amplitude_value[214], expected 181, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 170, + "incorrect value for amplitude_value[215], expected 170, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 45, + "incorrect value for amplitude_value[216], expected 45, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 8, + "incorrect value for amplitude_value[217], expected 8, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 166, + "incorrect value for amplitude_value[218], expected 166, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 164, + "incorrect value for amplitude_value[219], expected 164, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 238, + "incorrect value for amplitude_value[220], expected 238, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 83, + "incorrect value for amplitude_value[221], expected 83, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 148, + "incorrect value for amplitude_value[222], expected 148, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 173, + "incorrect value for amplitude_value[223], expected 173, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 108, + "incorrect value for amplitude_value[224], expected 108, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 228, + "incorrect value for amplitude_value[225], expected 228, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 67, + "incorrect value for amplitude_value[226], expected 67, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.amplitude_value[227], 89, + "incorrect value for amplitude_value[227], expected 89, is {}", + msg.amplitude_value[227] + ); + assert_eq!( + msg.amplitude_value[228], 189, + "incorrect value for amplitude_value[228], expected 189, is {}", + msg.amplitude_value[228] + ); + assert_eq!( + msg.amplitude_value[229], 67, + "incorrect value for amplitude_value[229], expected 67, is {}", + msg.amplitude_value[229] + ); + assert_eq!( + msg.amplitude_value[230], 26, + "incorrect value for amplitude_value[230], expected 26, is {}", + msg.amplitude_value[230] + ); + assert_eq!( + msg.channel_tag, 5878, + "incorrect value for channel_tag, expected 5878, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(6.34820019531250000e+03), + "incorrect value for freq_ref, expected 6.34820019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(4.60820019531250000e+03), + "incorrect value for freq_step, expected 4.60820019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.tow, 992295133, + "incorrect value for t.tow, expected 992295133, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 6957, + "incorrect value for t.wn, expected 6957, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecanDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_msg_specan_dep() { + { + let json_input = r#"{"preamble":85,"msg_type":80,"sender":55664,"length":255,"payload":"9hbdOCU7LRuaYcZFmgGQRc0UEkYz01lF8A6zuuP0rfC2R6Z1xA0sGyEcQ/4D+VwseqlNukSHP6iiWSS6Yz9pdNgsQ9ScS1E1+uEXzRoidzJlQAfnfLfLZupUU9AXRDazYmB09PZeaF4NONISvxaFUZmfods7FaR5kcurhDm0ZmUL5a+RSUh8BLjkPeraPuLZwQdtLFPJFGUJjLqiUVse56FR2HI856OjMe30ufBZj66l0/ENED2NZVkldb1WdrDkDA53h4HzMh3PxnVk4QaLbifSRMcrhEARM621DIwQ91S3aSedTR7NwjtA8bfuabWqLQimpO5TlK1s5ENZvUMa","crc":55335,"channel_tag":5878,"t":{"tow":992295133,"wn":6957},"freq_ref":6348.2001953125,"freq_step":4608.2001953125,"amplitude_ref":9349.2001953125,"amplitude_unit":3485.199951171875,"amplitude_value":[240,14,179,186,227,244,173,240,182,71,166,117,196,13,44,27,33,28,67,254,3,249,92,44,122,169,77,186,68,135,63,168,162,89,36,186,99,63,105,116,216,44,67,212,156,75,81,53,250,225,23,205,26,34,119,50,101,64,7,231,124,183,203,102,234,84,83,208,23,68,54,179,98,96,116,244,246,94,104,94,13,56,210,18,191,22,133,81,153,159,161,219,59,21,164,121,145,203,171,132,57,180,102,101,11,229,175,145,73,72,124,4,184,228,61,234,218,62,226,217,193,7,109,44,83,201,20,101,9,140,186,162,81,91,30,231,161,81,216,114,60,231,163,163,49,237,244,185,240,89,143,174,165,211,241,13,16,61,141,101,89,37,117,189,86,118,176,228,12,14,119,135,129,243,50,29,207,198,117,100,225,6,139,110,39,210,68,199,43,132,64,17,51,173,181,12,140,16,247,84,183,105,39,157,77,30,205,194,59,64,241,183,238,105,181,170,45,8,166,164,238,83,148,173,108,228,67,89,189,67,26]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSpecanDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x50, + "Incorrect message type, expected 0x50, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd970, + "incorrect sender id, expected 0xd970, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(9.34920019531250000e+03), + "incorrect value for amplitude_ref, expected 9.34920019531250000e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(3.48519995117187500e+03), + "incorrect value for amplitude_unit, expected 3.48519995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 240, + "incorrect value for amplitude_value[0], expected 240, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 14, + "incorrect value for amplitude_value[1], expected 14, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 179, + "incorrect value for amplitude_value[2], expected 179, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 186, + "incorrect value for amplitude_value[3], expected 186, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 227, + "incorrect value for amplitude_value[4], expected 227, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 244, + "incorrect value for amplitude_value[5], expected 244, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 173, + "incorrect value for amplitude_value[6], expected 173, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 240, + "incorrect value for amplitude_value[7], expected 240, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 182, + "incorrect value for amplitude_value[8], expected 182, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 71, + "incorrect value for amplitude_value[9], expected 71, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 166, + "incorrect value for amplitude_value[10], expected 166, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 117, + "incorrect value for amplitude_value[11], expected 117, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 196, + "incorrect value for amplitude_value[12], expected 196, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 13, + "incorrect value for amplitude_value[13], expected 13, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 44, + "incorrect value for amplitude_value[14], expected 44, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 27, + "incorrect value for amplitude_value[15], expected 27, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 33, + "incorrect value for amplitude_value[16], expected 33, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 28, + "incorrect value for amplitude_value[17], expected 28, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 67, + "incorrect value for amplitude_value[18], expected 67, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 254, + "incorrect value for amplitude_value[19], expected 254, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 3, + "incorrect value for amplitude_value[20], expected 3, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 249, + "incorrect value for amplitude_value[21], expected 249, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 92, + "incorrect value for amplitude_value[22], expected 92, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 44, + "incorrect value for amplitude_value[23], expected 44, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 122, + "incorrect value for amplitude_value[24], expected 122, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 169, + "incorrect value for amplitude_value[25], expected 169, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 77, + "incorrect value for amplitude_value[26], expected 77, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 186, + "incorrect value for amplitude_value[27], expected 186, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 68, + "incorrect value for amplitude_value[28], expected 68, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 135, + "incorrect value for amplitude_value[29], expected 135, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 63, + "incorrect value for amplitude_value[30], expected 63, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 168, + "incorrect value for amplitude_value[31], expected 168, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 162, + "incorrect value for amplitude_value[32], expected 162, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 89, + "incorrect value for amplitude_value[33], expected 89, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 36, + "incorrect value for amplitude_value[34], expected 36, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 186, + "incorrect value for amplitude_value[35], expected 186, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 99, + "incorrect value for amplitude_value[36], expected 99, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 63, + "incorrect value for amplitude_value[37], expected 63, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 105, + "incorrect value for amplitude_value[38], expected 105, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 116, + "incorrect value for amplitude_value[39], expected 116, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 216, + "incorrect value for amplitude_value[40], expected 216, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 44, + "incorrect value for amplitude_value[41], expected 44, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 67, + "incorrect value for amplitude_value[42], expected 67, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 212, + "incorrect value for amplitude_value[43], expected 212, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 156, + "incorrect value for amplitude_value[44], expected 156, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 75, + "incorrect value for amplitude_value[45], expected 75, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 81, + "incorrect value for amplitude_value[46], expected 81, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 53, + "incorrect value for amplitude_value[47], expected 53, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 250, + "incorrect value for amplitude_value[48], expected 250, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 225, + "incorrect value for amplitude_value[49], expected 225, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 23, + "incorrect value for amplitude_value[50], expected 23, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 205, + "incorrect value for amplitude_value[51], expected 205, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 26, + "incorrect value for amplitude_value[52], expected 26, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 34, + "incorrect value for amplitude_value[53], expected 34, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 119, + "incorrect value for amplitude_value[54], expected 119, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 50, + "incorrect value for amplitude_value[55], expected 50, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 101, + "incorrect value for amplitude_value[56], expected 101, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 64, + "incorrect value for amplitude_value[57], expected 64, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 7, + "incorrect value for amplitude_value[58], expected 7, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 231, + "incorrect value for amplitude_value[59], expected 231, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 124, + "incorrect value for amplitude_value[60], expected 124, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 183, + "incorrect value for amplitude_value[61], expected 183, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 203, + "incorrect value for amplitude_value[62], expected 203, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 102, + "incorrect value for amplitude_value[63], expected 102, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 234, + "incorrect value for amplitude_value[64], expected 234, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 84, + "incorrect value for amplitude_value[65], expected 84, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 83, + "incorrect value for amplitude_value[66], expected 83, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 208, + "incorrect value for amplitude_value[67], expected 208, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 23, + "incorrect value for amplitude_value[68], expected 23, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 68, + "incorrect value for amplitude_value[69], expected 68, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 54, + "incorrect value for amplitude_value[70], expected 54, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 179, + "incorrect value for amplitude_value[71], expected 179, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 98, + "incorrect value for amplitude_value[72], expected 98, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 96, + "incorrect value for amplitude_value[73], expected 96, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 116, + "incorrect value for amplitude_value[74], expected 116, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 244, + "incorrect value for amplitude_value[75], expected 244, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 246, + "incorrect value for amplitude_value[76], expected 246, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 94, + "incorrect value for amplitude_value[77], expected 94, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 104, + "incorrect value for amplitude_value[78], expected 104, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 94, + "incorrect value for amplitude_value[79], expected 94, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 13, + "incorrect value for amplitude_value[80], expected 13, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 56, + "incorrect value for amplitude_value[81], expected 56, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 210, + "incorrect value for amplitude_value[82], expected 210, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 18, + "incorrect value for amplitude_value[83], expected 18, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 191, + "incorrect value for amplitude_value[84], expected 191, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 22, + "incorrect value for amplitude_value[85], expected 22, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 133, + "incorrect value for amplitude_value[86], expected 133, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 81, + "incorrect value for amplitude_value[87], expected 81, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 153, + "incorrect value for amplitude_value[88], expected 153, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 159, + "incorrect value for amplitude_value[89], expected 159, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 161, + "incorrect value for amplitude_value[90], expected 161, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 219, + "incorrect value for amplitude_value[91], expected 219, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 59, + "incorrect value for amplitude_value[92], expected 59, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 21, + "incorrect value for amplitude_value[93], expected 21, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 164, + "incorrect value for amplitude_value[94], expected 164, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 121, + "incorrect value for amplitude_value[95], expected 121, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 145, + "incorrect value for amplitude_value[96], expected 145, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 203, + "incorrect value for amplitude_value[97], expected 203, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 171, + "incorrect value for amplitude_value[98], expected 171, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 132, + "incorrect value for amplitude_value[99], expected 132, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 57, + "incorrect value for amplitude_value[100], expected 57, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 180, + "incorrect value for amplitude_value[101], expected 180, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 102, + "incorrect value for amplitude_value[102], expected 102, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 101, + "incorrect value for amplitude_value[103], expected 101, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 11, + "incorrect value for amplitude_value[104], expected 11, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 229, + "incorrect value for amplitude_value[105], expected 229, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 175, + "incorrect value for amplitude_value[106], expected 175, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 145, + "incorrect value for amplitude_value[107], expected 145, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 73, + "incorrect value for amplitude_value[108], expected 73, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 72, + "incorrect value for amplitude_value[109], expected 72, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 124, + "incorrect value for amplitude_value[110], expected 124, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 4, + "incorrect value for amplitude_value[111], expected 4, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 184, + "incorrect value for amplitude_value[112], expected 184, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 228, + "incorrect value for amplitude_value[113], expected 228, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 61, + "incorrect value for amplitude_value[114], expected 61, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 234, + "incorrect value for amplitude_value[115], expected 234, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 218, + "incorrect value for amplitude_value[116], expected 218, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 62, + "incorrect value for amplitude_value[117], expected 62, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 226, + "incorrect value for amplitude_value[118], expected 226, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 217, + "incorrect value for amplitude_value[119], expected 217, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 193, + "incorrect value for amplitude_value[120], expected 193, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 7, + "incorrect value for amplitude_value[121], expected 7, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 109, + "incorrect value for amplitude_value[122], expected 109, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 44, + "incorrect value for amplitude_value[123], expected 44, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 83, + "incorrect value for amplitude_value[124], expected 83, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 201, + "incorrect value for amplitude_value[125], expected 201, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 20, + "incorrect value for amplitude_value[126], expected 20, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 101, + "incorrect value for amplitude_value[127], expected 101, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 9, + "incorrect value for amplitude_value[128], expected 9, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 140, + "incorrect value for amplitude_value[129], expected 140, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 186, + "incorrect value for amplitude_value[130], expected 186, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 162, + "incorrect value for amplitude_value[131], expected 162, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 81, + "incorrect value for amplitude_value[132], expected 81, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 91, + "incorrect value for amplitude_value[133], expected 91, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 30, + "incorrect value for amplitude_value[134], expected 30, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 231, + "incorrect value for amplitude_value[135], expected 231, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 161, + "incorrect value for amplitude_value[136], expected 161, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 81, + "incorrect value for amplitude_value[137], expected 81, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 216, + "incorrect value for amplitude_value[138], expected 216, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 114, + "incorrect value for amplitude_value[139], expected 114, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 60, + "incorrect value for amplitude_value[140], expected 60, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 231, + "incorrect value for amplitude_value[141], expected 231, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 163, + "incorrect value for amplitude_value[142], expected 163, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 163, + "incorrect value for amplitude_value[143], expected 163, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 49, + "incorrect value for amplitude_value[144], expected 49, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 237, + "incorrect value for amplitude_value[145], expected 237, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 244, + "incorrect value for amplitude_value[146], expected 244, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 185, + "incorrect value for amplitude_value[147], expected 185, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 240, + "incorrect value for amplitude_value[148], expected 240, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 89, + "incorrect value for amplitude_value[149], expected 89, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 143, + "incorrect value for amplitude_value[150], expected 143, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 174, + "incorrect value for amplitude_value[151], expected 174, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 165, + "incorrect value for amplitude_value[152], expected 165, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 211, + "incorrect value for amplitude_value[153], expected 211, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 241, + "incorrect value for amplitude_value[154], expected 241, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 13, + "incorrect value for amplitude_value[155], expected 13, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 16, + "incorrect value for amplitude_value[156], expected 16, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 61, + "incorrect value for amplitude_value[157], expected 61, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 141, + "incorrect value for amplitude_value[158], expected 141, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 101, + "incorrect value for amplitude_value[159], expected 101, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 89, + "incorrect value for amplitude_value[160], expected 89, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 37, + "incorrect value for amplitude_value[161], expected 37, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 117, + "incorrect value for amplitude_value[162], expected 117, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 189, + "incorrect value for amplitude_value[163], expected 189, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 86, + "incorrect value for amplitude_value[164], expected 86, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 118, + "incorrect value for amplitude_value[165], expected 118, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 176, + "incorrect value for amplitude_value[166], expected 176, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 228, + "incorrect value for amplitude_value[167], expected 228, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 12, + "incorrect value for amplitude_value[168], expected 12, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 14, + "incorrect value for amplitude_value[169], expected 14, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 119, + "incorrect value for amplitude_value[170], expected 119, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 135, + "incorrect value for amplitude_value[171], expected 135, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 129, + "incorrect value for amplitude_value[172], expected 129, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 243, + "incorrect value for amplitude_value[173], expected 243, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 50, + "incorrect value for amplitude_value[174], expected 50, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 29, + "incorrect value for amplitude_value[175], expected 29, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 207, + "incorrect value for amplitude_value[176], expected 207, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 198, + "incorrect value for amplitude_value[177], expected 198, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 117, + "incorrect value for amplitude_value[178], expected 117, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 100, + "incorrect value for amplitude_value[179], expected 100, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 225, + "incorrect value for amplitude_value[180], expected 225, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 6, + "incorrect value for amplitude_value[181], expected 6, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 139, + "incorrect value for amplitude_value[182], expected 139, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 110, + "incorrect value for amplitude_value[183], expected 110, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 39, + "incorrect value for amplitude_value[184], expected 39, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 210, + "incorrect value for amplitude_value[185], expected 210, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 68, + "incorrect value for amplitude_value[186], expected 68, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 199, + "incorrect value for amplitude_value[187], expected 199, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 43, + "incorrect value for amplitude_value[188], expected 43, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 132, + "incorrect value for amplitude_value[189], expected 132, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 64, + "incorrect value for amplitude_value[190], expected 64, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 17, + "incorrect value for amplitude_value[191], expected 17, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 51, + "incorrect value for amplitude_value[192], expected 51, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 173, + "incorrect value for amplitude_value[193], expected 173, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 181, + "incorrect value for amplitude_value[194], expected 181, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 12, + "incorrect value for amplitude_value[195], expected 12, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 140, + "incorrect value for amplitude_value[196], expected 140, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 16, + "incorrect value for amplitude_value[197], expected 16, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 247, + "incorrect value for amplitude_value[198], expected 247, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 84, + "incorrect value for amplitude_value[199], expected 84, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 183, + "incorrect value for amplitude_value[200], expected 183, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 105, + "incorrect value for amplitude_value[201], expected 105, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 39, + "incorrect value for amplitude_value[202], expected 39, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 157, + "incorrect value for amplitude_value[203], expected 157, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 77, + "incorrect value for amplitude_value[204], expected 77, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 30, + "incorrect value for amplitude_value[205], expected 30, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 205, + "incorrect value for amplitude_value[206], expected 205, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 194, + "incorrect value for amplitude_value[207], expected 194, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 59, + "incorrect value for amplitude_value[208], expected 59, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 64, + "incorrect value for amplitude_value[209], expected 64, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 241, + "incorrect value for amplitude_value[210], expected 241, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 183, + "incorrect value for amplitude_value[211], expected 183, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 238, + "incorrect value for amplitude_value[212], expected 238, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 105, + "incorrect value for amplitude_value[213], expected 105, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 181, + "incorrect value for amplitude_value[214], expected 181, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 170, + "incorrect value for amplitude_value[215], expected 170, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 45, + "incorrect value for amplitude_value[216], expected 45, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 8, + "incorrect value for amplitude_value[217], expected 8, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 166, + "incorrect value for amplitude_value[218], expected 166, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 164, + "incorrect value for amplitude_value[219], expected 164, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 238, + "incorrect value for amplitude_value[220], expected 238, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 83, + "incorrect value for amplitude_value[221], expected 83, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 148, + "incorrect value for amplitude_value[222], expected 148, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 173, + "incorrect value for amplitude_value[223], expected 173, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 108, + "incorrect value for amplitude_value[224], expected 108, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 228, + "incorrect value for amplitude_value[225], expected 228, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 67, + "incorrect value for amplitude_value[226], expected 67, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.amplitude_value[227], 89, + "incorrect value for amplitude_value[227], expected 89, is {}", + msg.amplitude_value[227] + ); + assert_eq!( + msg.amplitude_value[228], 189, + "incorrect value for amplitude_value[228], expected 189, is {}", + msg.amplitude_value[228] + ); + assert_eq!( + msg.amplitude_value[229], 67, + "incorrect value for amplitude_value[229], expected 67, is {}", + msg.amplitude_value[229] + ); + assert_eq!( + msg.amplitude_value[230], 26, + "incorrect value for amplitude_value[230], expected 26, is {}", + msg.amplitude_value[230] + ); + assert_eq!( + msg.channel_tag, 5878, + "incorrect value for channel_tag, expected 5878, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(6.34820019531250000e+03), + "incorrect value for freq_ref, expected 6.34820019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(4.60820019531250000e+03), + "incorrect value for freq_step, expected 4.60820019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.tow, 992295133, + "incorrect value for t.tow, expected 992295133, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 6957, + "incorrect value for t.wn, expected 6957, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecanDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_msg_specan_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_msg_specan_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 80, 0, 112, 217, 255, 246, 22, 221, 56, 37, 59, 45, 27, 154, 97, 198, 69, 154, 1, + 144, 69, 205, 20, 18, 70, 51, 211, 89, 69, 240, 14, 179, 186, 227, 244, 173, 240, 182, + 71, 166, 117, 196, 13, 44, 27, 33, 28, 67, 254, 3, 249, 92, 44, 122, 169, 77, 186, 68, + 135, 63, 168, 162, 89, 36, 186, 99, 63, 105, 116, 216, 44, 67, 212, 156, 75, 81, 53, + 250, 225, 23, 205, 26, 34, 119, 50, 101, 64, 7, 231, 124, 183, 203, 102, 234, 84, 83, + 208, 23, 68, 54, 179, 98, 96, 116, 244, 246, 94, 104, 94, 13, 56, 210, 18, 191, 22, + 133, 81, 153, 159, 161, 219, 59, 21, 164, 121, 145, 203, 171, 132, 57, 180, 102, 101, + 11, 229, 175, 145, 73, 72, 124, 4, 184, 228, 61, 234, 218, 62, 226, 217, 193, 7, 109, + 44, 83, 201, 20, 101, 9, 140, 186, 162, 81, 91, 30, 231, 161, 81, 216, 114, 60, 231, + 163, 163, 49, 237, 244, 185, 240, 89, 143, 174, 165, 211, 241, 13, 16, 61, 141, 101, + 89, 37, 117, 189, 86, 118, 176, 228, 12, 14, 119, 135, 129, 243, 50, 29, 207, 198, 117, + 100, 225, 6, 139, 110, 39, 210, 68, 199, 43, 132, 64, 17, 51, 173, 181, 12, 140, 16, + 247, 84, 183, 105, 39, 157, 77, 30, 205, 194, 59, 64, 241, 183, 238, 105, 181, 170, 45, + 8, 166, 164, 238, 83, 148, 173, 108, 228, 67, 89, 189, 67, 26, 39, 216, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSpecanDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSpecanDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x50, + "Incorrect message type, expected 0x50, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd970, + "incorrect sender id, expected 0xd970, is {sender_id}" + ); + assert!( + msg.amplitude_ref.almost_eq(9.34920019531250000e+03), + "incorrect value for amplitude_ref, expected 9.34920019531250000e+03, is {:e}", + msg.amplitude_ref + ); + assert!( + msg.amplitude_unit.almost_eq(3.48519995117187500e+03), + "incorrect value for amplitude_unit, expected 3.48519995117187500e+03, is {:e}", + msg.amplitude_unit + ); + assert_eq!( + msg.amplitude_value[0], 240, + "incorrect value for amplitude_value[0], expected 240, is {}", + msg.amplitude_value[0] + ); + assert_eq!( + msg.amplitude_value[1], 14, + "incorrect value for amplitude_value[1], expected 14, is {}", + msg.amplitude_value[1] + ); + assert_eq!( + msg.amplitude_value[2], 179, + "incorrect value for amplitude_value[2], expected 179, is {}", + msg.amplitude_value[2] + ); + assert_eq!( + msg.amplitude_value[3], 186, + "incorrect value for amplitude_value[3], expected 186, is {}", + msg.amplitude_value[3] + ); + assert_eq!( + msg.amplitude_value[4], 227, + "incorrect value for amplitude_value[4], expected 227, is {}", + msg.amplitude_value[4] + ); + assert_eq!( + msg.amplitude_value[5], 244, + "incorrect value for amplitude_value[5], expected 244, is {}", + msg.amplitude_value[5] + ); + assert_eq!( + msg.amplitude_value[6], 173, + "incorrect value for amplitude_value[6], expected 173, is {}", + msg.amplitude_value[6] + ); + assert_eq!( + msg.amplitude_value[7], 240, + "incorrect value for amplitude_value[7], expected 240, is {}", + msg.amplitude_value[7] + ); + assert_eq!( + msg.amplitude_value[8], 182, + "incorrect value for amplitude_value[8], expected 182, is {}", + msg.amplitude_value[8] + ); + assert_eq!( + msg.amplitude_value[9], 71, + "incorrect value for amplitude_value[9], expected 71, is {}", + msg.amplitude_value[9] + ); + assert_eq!( + msg.amplitude_value[10], 166, + "incorrect value for amplitude_value[10], expected 166, is {}", + msg.amplitude_value[10] + ); + assert_eq!( + msg.amplitude_value[11], 117, + "incorrect value for amplitude_value[11], expected 117, is {}", + msg.amplitude_value[11] + ); + assert_eq!( + msg.amplitude_value[12], 196, + "incorrect value for amplitude_value[12], expected 196, is {}", + msg.amplitude_value[12] + ); + assert_eq!( + msg.amplitude_value[13], 13, + "incorrect value for amplitude_value[13], expected 13, is {}", + msg.amplitude_value[13] + ); + assert_eq!( + msg.amplitude_value[14], 44, + "incorrect value for amplitude_value[14], expected 44, is {}", + msg.amplitude_value[14] + ); + assert_eq!( + msg.amplitude_value[15], 27, + "incorrect value for amplitude_value[15], expected 27, is {}", + msg.amplitude_value[15] + ); + assert_eq!( + msg.amplitude_value[16], 33, + "incorrect value for amplitude_value[16], expected 33, is {}", + msg.amplitude_value[16] + ); + assert_eq!( + msg.amplitude_value[17], 28, + "incorrect value for amplitude_value[17], expected 28, is {}", + msg.amplitude_value[17] + ); + assert_eq!( + msg.amplitude_value[18], 67, + "incorrect value for amplitude_value[18], expected 67, is {}", + msg.amplitude_value[18] + ); + assert_eq!( + msg.amplitude_value[19], 254, + "incorrect value for amplitude_value[19], expected 254, is {}", + msg.amplitude_value[19] + ); + assert_eq!( + msg.amplitude_value[20], 3, + "incorrect value for amplitude_value[20], expected 3, is {}", + msg.amplitude_value[20] + ); + assert_eq!( + msg.amplitude_value[21], 249, + "incorrect value for amplitude_value[21], expected 249, is {}", + msg.amplitude_value[21] + ); + assert_eq!( + msg.amplitude_value[22], 92, + "incorrect value for amplitude_value[22], expected 92, is {}", + msg.amplitude_value[22] + ); + assert_eq!( + msg.amplitude_value[23], 44, + "incorrect value for amplitude_value[23], expected 44, is {}", + msg.amplitude_value[23] + ); + assert_eq!( + msg.amplitude_value[24], 122, + "incorrect value for amplitude_value[24], expected 122, is {}", + msg.amplitude_value[24] + ); + assert_eq!( + msg.amplitude_value[25], 169, + "incorrect value for amplitude_value[25], expected 169, is {}", + msg.amplitude_value[25] + ); + assert_eq!( + msg.amplitude_value[26], 77, + "incorrect value for amplitude_value[26], expected 77, is {}", + msg.amplitude_value[26] + ); + assert_eq!( + msg.amplitude_value[27], 186, + "incorrect value for amplitude_value[27], expected 186, is {}", + msg.amplitude_value[27] + ); + assert_eq!( + msg.amplitude_value[28], 68, + "incorrect value for amplitude_value[28], expected 68, is {}", + msg.amplitude_value[28] + ); + assert_eq!( + msg.amplitude_value[29], 135, + "incorrect value for amplitude_value[29], expected 135, is {}", + msg.amplitude_value[29] + ); + assert_eq!( + msg.amplitude_value[30], 63, + "incorrect value for amplitude_value[30], expected 63, is {}", + msg.amplitude_value[30] + ); + assert_eq!( + msg.amplitude_value[31], 168, + "incorrect value for amplitude_value[31], expected 168, is {}", + msg.amplitude_value[31] + ); + assert_eq!( + msg.amplitude_value[32], 162, + "incorrect value for amplitude_value[32], expected 162, is {}", + msg.amplitude_value[32] + ); + assert_eq!( + msg.amplitude_value[33], 89, + "incorrect value for amplitude_value[33], expected 89, is {}", + msg.amplitude_value[33] + ); + assert_eq!( + msg.amplitude_value[34], 36, + "incorrect value for amplitude_value[34], expected 36, is {}", + msg.amplitude_value[34] + ); + assert_eq!( + msg.amplitude_value[35], 186, + "incorrect value for amplitude_value[35], expected 186, is {}", + msg.amplitude_value[35] + ); + assert_eq!( + msg.amplitude_value[36], 99, + "incorrect value for amplitude_value[36], expected 99, is {}", + msg.amplitude_value[36] + ); + assert_eq!( + msg.amplitude_value[37], 63, + "incorrect value for amplitude_value[37], expected 63, is {}", + msg.amplitude_value[37] + ); + assert_eq!( + msg.amplitude_value[38], 105, + "incorrect value for amplitude_value[38], expected 105, is {}", + msg.amplitude_value[38] + ); + assert_eq!( + msg.amplitude_value[39], 116, + "incorrect value for amplitude_value[39], expected 116, is {}", + msg.amplitude_value[39] + ); + assert_eq!( + msg.amplitude_value[40], 216, + "incorrect value for amplitude_value[40], expected 216, is {}", + msg.amplitude_value[40] + ); + assert_eq!( + msg.amplitude_value[41], 44, + "incorrect value for amplitude_value[41], expected 44, is {}", + msg.amplitude_value[41] + ); + assert_eq!( + msg.amplitude_value[42], 67, + "incorrect value for amplitude_value[42], expected 67, is {}", + msg.amplitude_value[42] + ); + assert_eq!( + msg.amplitude_value[43], 212, + "incorrect value for amplitude_value[43], expected 212, is {}", + msg.amplitude_value[43] + ); + assert_eq!( + msg.amplitude_value[44], 156, + "incorrect value for amplitude_value[44], expected 156, is {}", + msg.amplitude_value[44] + ); + assert_eq!( + msg.amplitude_value[45], 75, + "incorrect value for amplitude_value[45], expected 75, is {}", + msg.amplitude_value[45] + ); + assert_eq!( + msg.amplitude_value[46], 81, + "incorrect value for amplitude_value[46], expected 81, is {}", + msg.amplitude_value[46] + ); + assert_eq!( + msg.amplitude_value[47], 53, + "incorrect value for amplitude_value[47], expected 53, is {}", + msg.amplitude_value[47] + ); + assert_eq!( + msg.amplitude_value[48], 250, + "incorrect value for amplitude_value[48], expected 250, is {}", + msg.amplitude_value[48] + ); + assert_eq!( + msg.amplitude_value[49], 225, + "incorrect value for amplitude_value[49], expected 225, is {}", + msg.amplitude_value[49] + ); + assert_eq!( + msg.amplitude_value[50], 23, + "incorrect value for amplitude_value[50], expected 23, is {}", + msg.amplitude_value[50] + ); + assert_eq!( + msg.amplitude_value[51], 205, + "incorrect value for amplitude_value[51], expected 205, is {}", + msg.amplitude_value[51] + ); + assert_eq!( + msg.amplitude_value[52], 26, + "incorrect value for amplitude_value[52], expected 26, is {}", + msg.amplitude_value[52] + ); + assert_eq!( + msg.amplitude_value[53], 34, + "incorrect value for amplitude_value[53], expected 34, is {}", + msg.amplitude_value[53] + ); + assert_eq!( + msg.amplitude_value[54], 119, + "incorrect value for amplitude_value[54], expected 119, is {}", + msg.amplitude_value[54] + ); + assert_eq!( + msg.amplitude_value[55], 50, + "incorrect value for amplitude_value[55], expected 50, is {}", + msg.amplitude_value[55] + ); + assert_eq!( + msg.amplitude_value[56], 101, + "incorrect value for amplitude_value[56], expected 101, is {}", + msg.amplitude_value[56] + ); + assert_eq!( + msg.amplitude_value[57], 64, + "incorrect value for amplitude_value[57], expected 64, is {}", + msg.amplitude_value[57] + ); + assert_eq!( + msg.amplitude_value[58], 7, + "incorrect value for amplitude_value[58], expected 7, is {}", + msg.amplitude_value[58] + ); + assert_eq!( + msg.amplitude_value[59], 231, + "incorrect value for amplitude_value[59], expected 231, is {}", + msg.amplitude_value[59] + ); + assert_eq!( + msg.amplitude_value[60], 124, + "incorrect value for amplitude_value[60], expected 124, is {}", + msg.amplitude_value[60] + ); + assert_eq!( + msg.amplitude_value[61], 183, + "incorrect value for amplitude_value[61], expected 183, is {}", + msg.amplitude_value[61] + ); + assert_eq!( + msg.amplitude_value[62], 203, + "incorrect value for amplitude_value[62], expected 203, is {}", + msg.amplitude_value[62] + ); + assert_eq!( + msg.amplitude_value[63], 102, + "incorrect value for amplitude_value[63], expected 102, is {}", + msg.amplitude_value[63] + ); + assert_eq!( + msg.amplitude_value[64], 234, + "incorrect value for amplitude_value[64], expected 234, is {}", + msg.amplitude_value[64] + ); + assert_eq!( + msg.amplitude_value[65], 84, + "incorrect value for amplitude_value[65], expected 84, is {}", + msg.amplitude_value[65] + ); + assert_eq!( + msg.amplitude_value[66], 83, + "incorrect value for amplitude_value[66], expected 83, is {}", + msg.amplitude_value[66] + ); + assert_eq!( + msg.amplitude_value[67], 208, + "incorrect value for amplitude_value[67], expected 208, is {}", + msg.amplitude_value[67] + ); + assert_eq!( + msg.amplitude_value[68], 23, + "incorrect value for amplitude_value[68], expected 23, is {}", + msg.amplitude_value[68] + ); + assert_eq!( + msg.amplitude_value[69], 68, + "incorrect value for amplitude_value[69], expected 68, is {}", + msg.amplitude_value[69] + ); + assert_eq!( + msg.amplitude_value[70], 54, + "incorrect value for amplitude_value[70], expected 54, is {}", + msg.amplitude_value[70] + ); + assert_eq!( + msg.amplitude_value[71], 179, + "incorrect value for amplitude_value[71], expected 179, is {}", + msg.amplitude_value[71] + ); + assert_eq!( + msg.amplitude_value[72], 98, + "incorrect value for amplitude_value[72], expected 98, is {}", + msg.amplitude_value[72] + ); + assert_eq!( + msg.amplitude_value[73], 96, + "incorrect value for amplitude_value[73], expected 96, is {}", + msg.amplitude_value[73] + ); + assert_eq!( + msg.amplitude_value[74], 116, + "incorrect value for amplitude_value[74], expected 116, is {}", + msg.amplitude_value[74] + ); + assert_eq!( + msg.amplitude_value[75], 244, + "incorrect value for amplitude_value[75], expected 244, is {}", + msg.amplitude_value[75] + ); + assert_eq!( + msg.amplitude_value[76], 246, + "incorrect value for amplitude_value[76], expected 246, is {}", + msg.amplitude_value[76] + ); + assert_eq!( + msg.amplitude_value[77], 94, + "incorrect value for amplitude_value[77], expected 94, is {}", + msg.amplitude_value[77] + ); + assert_eq!( + msg.amplitude_value[78], 104, + "incorrect value for amplitude_value[78], expected 104, is {}", + msg.amplitude_value[78] + ); + assert_eq!( + msg.amplitude_value[79], 94, + "incorrect value for amplitude_value[79], expected 94, is {}", + msg.amplitude_value[79] + ); + assert_eq!( + msg.amplitude_value[80], 13, + "incorrect value for amplitude_value[80], expected 13, is {}", + msg.amplitude_value[80] + ); + assert_eq!( + msg.amplitude_value[81], 56, + "incorrect value for amplitude_value[81], expected 56, is {}", + msg.amplitude_value[81] + ); + assert_eq!( + msg.amplitude_value[82], 210, + "incorrect value for amplitude_value[82], expected 210, is {}", + msg.amplitude_value[82] + ); + assert_eq!( + msg.amplitude_value[83], 18, + "incorrect value for amplitude_value[83], expected 18, is {}", + msg.amplitude_value[83] + ); + assert_eq!( + msg.amplitude_value[84], 191, + "incorrect value for amplitude_value[84], expected 191, is {}", + msg.amplitude_value[84] + ); + assert_eq!( + msg.amplitude_value[85], 22, + "incorrect value for amplitude_value[85], expected 22, is {}", + msg.amplitude_value[85] + ); + assert_eq!( + msg.amplitude_value[86], 133, + "incorrect value for amplitude_value[86], expected 133, is {}", + msg.amplitude_value[86] + ); + assert_eq!( + msg.amplitude_value[87], 81, + "incorrect value for amplitude_value[87], expected 81, is {}", + msg.amplitude_value[87] + ); + assert_eq!( + msg.amplitude_value[88], 153, + "incorrect value for amplitude_value[88], expected 153, is {}", + msg.amplitude_value[88] + ); + assert_eq!( + msg.amplitude_value[89], 159, + "incorrect value for amplitude_value[89], expected 159, is {}", + msg.amplitude_value[89] + ); + assert_eq!( + msg.amplitude_value[90], 161, + "incorrect value for amplitude_value[90], expected 161, is {}", + msg.amplitude_value[90] + ); + assert_eq!( + msg.amplitude_value[91], 219, + "incorrect value for amplitude_value[91], expected 219, is {}", + msg.amplitude_value[91] + ); + assert_eq!( + msg.amplitude_value[92], 59, + "incorrect value for amplitude_value[92], expected 59, is {}", + msg.amplitude_value[92] + ); + assert_eq!( + msg.amplitude_value[93], 21, + "incorrect value for amplitude_value[93], expected 21, is {}", + msg.amplitude_value[93] + ); + assert_eq!( + msg.amplitude_value[94], 164, + "incorrect value for amplitude_value[94], expected 164, is {}", + msg.amplitude_value[94] + ); + assert_eq!( + msg.amplitude_value[95], 121, + "incorrect value for amplitude_value[95], expected 121, is {}", + msg.amplitude_value[95] + ); + assert_eq!( + msg.amplitude_value[96], 145, + "incorrect value for amplitude_value[96], expected 145, is {}", + msg.amplitude_value[96] + ); + assert_eq!( + msg.amplitude_value[97], 203, + "incorrect value for amplitude_value[97], expected 203, is {}", + msg.amplitude_value[97] + ); + assert_eq!( + msg.amplitude_value[98], 171, + "incorrect value for amplitude_value[98], expected 171, is {}", + msg.amplitude_value[98] + ); + assert_eq!( + msg.amplitude_value[99], 132, + "incorrect value for amplitude_value[99], expected 132, is {}", + msg.amplitude_value[99] + ); + assert_eq!( + msg.amplitude_value[100], 57, + "incorrect value for amplitude_value[100], expected 57, is {}", + msg.amplitude_value[100] + ); + assert_eq!( + msg.amplitude_value[101], 180, + "incorrect value for amplitude_value[101], expected 180, is {}", + msg.amplitude_value[101] + ); + assert_eq!( + msg.amplitude_value[102], 102, + "incorrect value for amplitude_value[102], expected 102, is {}", + msg.amplitude_value[102] + ); + assert_eq!( + msg.amplitude_value[103], 101, + "incorrect value for amplitude_value[103], expected 101, is {}", + msg.amplitude_value[103] + ); + assert_eq!( + msg.amplitude_value[104], 11, + "incorrect value for amplitude_value[104], expected 11, is {}", + msg.amplitude_value[104] + ); + assert_eq!( + msg.amplitude_value[105], 229, + "incorrect value for amplitude_value[105], expected 229, is {}", + msg.amplitude_value[105] + ); + assert_eq!( + msg.amplitude_value[106], 175, + "incorrect value for amplitude_value[106], expected 175, is {}", + msg.amplitude_value[106] + ); + assert_eq!( + msg.amplitude_value[107], 145, + "incorrect value for amplitude_value[107], expected 145, is {}", + msg.amplitude_value[107] + ); + assert_eq!( + msg.amplitude_value[108], 73, + "incorrect value for amplitude_value[108], expected 73, is {}", + msg.amplitude_value[108] + ); + assert_eq!( + msg.amplitude_value[109], 72, + "incorrect value for amplitude_value[109], expected 72, is {}", + msg.amplitude_value[109] + ); + assert_eq!( + msg.amplitude_value[110], 124, + "incorrect value for amplitude_value[110], expected 124, is {}", + msg.amplitude_value[110] + ); + assert_eq!( + msg.amplitude_value[111], 4, + "incorrect value for amplitude_value[111], expected 4, is {}", + msg.amplitude_value[111] + ); + assert_eq!( + msg.amplitude_value[112], 184, + "incorrect value for amplitude_value[112], expected 184, is {}", + msg.amplitude_value[112] + ); + assert_eq!( + msg.amplitude_value[113], 228, + "incorrect value for amplitude_value[113], expected 228, is {}", + msg.amplitude_value[113] + ); + assert_eq!( + msg.amplitude_value[114], 61, + "incorrect value for amplitude_value[114], expected 61, is {}", + msg.amplitude_value[114] + ); + assert_eq!( + msg.amplitude_value[115], 234, + "incorrect value for amplitude_value[115], expected 234, is {}", + msg.amplitude_value[115] + ); + assert_eq!( + msg.amplitude_value[116], 218, + "incorrect value for amplitude_value[116], expected 218, is {}", + msg.amplitude_value[116] + ); + assert_eq!( + msg.amplitude_value[117], 62, + "incorrect value for amplitude_value[117], expected 62, is {}", + msg.amplitude_value[117] + ); + assert_eq!( + msg.amplitude_value[118], 226, + "incorrect value for amplitude_value[118], expected 226, is {}", + msg.amplitude_value[118] + ); + assert_eq!( + msg.amplitude_value[119], 217, + "incorrect value for amplitude_value[119], expected 217, is {}", + msg.amplitude_value[119] + ); + assert_eq!( + msg.amplitude_value[120], 193, + "incorrect value for amplitude_value[120], expected 193, is {}", + msg.amplitude_value[120] + ); + assert_eq!( + msg.amplitude_value[121], 7, + "incorrect value for amplitude_value[121], expected 7, is {}", + msg.amplitude_value[121] + ); + assert_eq!( + msg.amplitude_value[122], 109, + "incorrect value for amplitude_value[122], expected 109, is {}", + msg.amplitude_value[122] + ); + assert_eq!( + msg.amplitude_value[123], 44, + "incorrect value for amplitude_value[123], expected 44, is {}", + msg.amplitude_value[123] + ); + assert_eq!( + msg.amplitude_value[124], 83, + "incorrect value for amplitude_value[124], expected 83, is {}", + msg.amplitude_value[124] + ); + assert_eq!( + msg.amplitude_value[125], 201, + "incorrect value for amplitude_value[125], expected 201, is {}", + msg.amplitude_value[125] + ); + assert_eq!( + msg.amplitude_value[126], 20, + "incorrect value for amplitude_value[126], expected 20, is {}", + msg.amplitude_value[126] + ); + assert_eq!( + msg.amplitude_value[127], 101, + "incorrect value for amplitude_value[127], expected 101, is {}", + msg.amplitude_value[127] + ); + assert_eq!( + msg.amplitude_value[128], 9, + "incorrect value for amplitude_value[128], expected 9, is {}", + msg.amplitude_value[128] + ); + assert_eq!( + msg.amplitude_value[129], 140, + "incorrect value for amplitude_value[129], expected 140, is {}", + msg.amplitude_value[129] + ); + assert_eq!( + msg.amplitude_value[130], 186, + "incorrect value for amplitude_value[130], expected 186, is {}", + msg.amplitude_value[130] + ); + assert_eq!( + msg.amplitude_value[131], 162, + "incorrect value for amplitude_value[131], expected 162, is {}", + msg.amplitude_value[131] + ); + assert_eq!( + msg.amplitude_value[132], 81, + "incorrect value for amplitude_value[132], expected 81, is {}", + msg.amplitude_value[132] + ); + assert_eq!( + msg.amplitude_value[133], 91, + "incorrect value for amplitude_value[133], expected 91, is {}", + msg.amplitude_value[133] + ); + assert_eq!( + msg.amplitude_value[134], 30, + "incorrect value for amplitude_value[134], expected 30, is {}", + msg.amplitude_value[134] + ); + assert_eq!( + msg.amplitude_value[135], 231, + "incorrect value for amplitude_value[135], expected 231, is {}", + msg.amplitude_value[135] + ); + assert_eq!( + msg.amplitude_value[136], 161, + "incorrect value for amplitude_value[136], expected 161, is {}", + msg.amplitude_value[136] + ); + assert_eq!( + msg.amplitude_value[137], 81, + "incorrect value for amplitude_value[137], expected 81, is {}", + msg.amplitude_value[137] + ); + assert_eq!( + msg.amplitude_value[138], 216, + "incorrect value for amplitude_value[138], expected 216, is {}", + msg.amplitude_value[138] + ); + assert_eq!( + msg.amplitude_value[139], 114, + "incorrect value for amplitude_value[139], expected 114, is {}", + msg.amplitude_value[139] + ); + assert_eq!( + msg.amplitude_value[140], 60, + "incorrect value for amplitude_value[140], expected 60, is {}", + msg.amplitude_value[140] + ); + assert_eq!( + msg.amplitude_value[141], 231, + "incorrect value for amplitude_value[141], expected 231, is {}", + msg.amplitude_value[141] + ); + assert_eq!( + msg.amplitude_value[142], 163, + "incorrect value for amplitude_value[142], expected 163, is {}", + msg.amplitude_value[142] + ); + assert_eq!( + msg.amplitude_value[143], 163, + "incorrect value for amplitude_value[143], expected 163, is {}", + msg.amplitude_value[143] + ); + assert_eq!( + msg.amplitude_value[144], 49, + "incorrect value for amplitude_value[144], expected 49, is {}", + msg.amplitude_value[144] + ); + assert_eq!( + msg.amplitude_value[145], 237, + "incorrect value for amplitude_value[145], expected 237, is {}", + msg.amplitude_value[145] + ); + assert_eq!( + msg.amplitude_value[146], 244, + "incorrect value for amplitude_value[146], expected 244, is {}", + msg.amplitude_value[146] + ); + assert_eq!( + msg.amplitude_value[147], 185, + "incorrect value for amplitude_value[147], expected 185, is {}", + msg.amplitude_value[147] + ); + assert_eq!( + msg.amplitude_value[148], 240, + "incorrect value for amplitude_value[148], expected 240, is {}", + msg.amplitude_value[148] + ); + assert_eq!( + msg.amplitude_value[149], 89, + "incorrect value for amplitude_value[149], expected 89, is {}", + msg.amplitude_value[149] + ); + assert_eq!( + msg.amplitude_value[150], 143, + "incorrect value for amplitude_value[150], expected 143, is {}", + msg.amplitude_value[150] + ); + assert_eq!( + msg.amplitude_value[151], 174, + "incorrect value for amplitude_value[151], expected 174, is {}", + msg.amplitude_value[151] + ); + assert_eq!( + msg.amplitude_value[152], 165, + "incorrect value for amplitude_value[152], expected 165, is {}", + msg.amplitude_value[152] + ); + assert_eq!( + msg.amplitude_value[153], 211, + "incorrect value for amplitude_value[153], expected 211, is {}", + msg.amplitude_value[153] + ); + assert_eq!( + msg.amplitude_value[154], 241, + "incorrect value for amplitude_value[154], expected 241, is {}", + msg.amplitude_value[154] + ); + assert_eq!( + msg.amplitude_value[155], 13, + "incorrect value for amplitude_value[155], expected 13, is {}", + msg.amplitude_value[155] + ); + assert_eq!( + msg.amplitude_value[156], 16, + "incorrect value for amplitude_value[156], expected 16, is {}", + msg.amplitude_value[156] + ); + assert_eq!( + msg.amplitude_value[157], 61, + "incorrect value for amplitude_value[157], expected 61, is {}", + msg.amplitude_value[157] + ); + assert_eq!( + msg.amplitude_value[158], 141, + "incorrect value for amplitude_value[158], expected 141, is {}", + msg.amplitude_value[158] + ); + assert_eq!( + msg.amplitude_value[159], 101, + "incorrect value for amplitude_value[159], expected 101, is {}", + msg.amplitude_value[159] + ); + assert_eq!( + msg.amplitude_value[160], 89, + "incorrect value for amplitude_value[160], expected 89, is {}", + msg.amplitude_value[160] + ); + assert_eq!( + msg.amplitude_value[161], 37, + "incorrect value for amplitude_value[161], expected 37, is {}", + msg.amplitude_value[161] + ); + assert_eq!( + msg.amplitude_value[162], 117, + "incorrect value for amplitude_value[162], expected 117, is {}", + msg.amplitude_value[162] + ); + assert_eq!( + msg.amplitude_value[163], 189, + "incorrect value for amplitude_value[163], expected 189, is {}", + msg.amplitude_value[163] + ); + assert_eq!( + msg.amplitude_value[164], 86, + "incorrect value for amplitude_value[164], expected 86, is {}", + msg.amplitude_value[164] + ); + assert_eq!( + msg.amplitude_value[165], 118, + "incorrect value for amplitude_value[165], expected 118, is {}", + msg.amplitude_value[165] + ); + assert_eq!( + msg.amplitude_value[166], 176, + "incorrect value for amplitude_value[166], expected 176, is {}", + msg.amplitude_value[166] + ); + assert_eq!( + msg.amplitude_value[167], 228, + "incorrect value for amplitude_value[167], expected 228, is {}", + msg.amplitude_value[167] + ); + assert_eq!( + msg.amplitude_value[168], 12, + "incorrect value for amplitude_value[168], expected 12, is {}", + msg.amplitude_value[168] + ); + assert_eq!( + msg.amplitude_value[169], 14, + "incorrect value for amplitude_value[169], expected 14, is {}", + msg.amplitude_value[169] + ); + assert_eq!( + msg.amplitude_value[170], 119, + "incorrect value for amplitude_value[170], expected 119, is {}", + msg.amplitude_value[170] + ); + assert_eq!( + msg.amplitude_value[171], 135, + "incorrect value for amplitude_value[171], expected 135, is {}", + msg.amplitude_value[171] + ); + assert_eq!( + msg.amplitude_value[172], 129, + "incorrect value for amplitude_value[172], expected 129, is {}", + msg.amplitude_value[172] + ); + assert_eq!( + msg.amplitude_value[173], 243, + "incorrect value for amplitude_value[173], expected 243, is {}", + msg.amplitude_value[173] + ); + assert_eq!( + msg.amplitude_value[174], 50, + "incorrect value for amplitude_value[174], expected 50, is {}", + msg.amplitude_value[174] + ); + assert_eq!( + msg.amplitude_value[175], 29, + "incorrect value for amplitude_value[175], expected 29, is {}", + msg.amplitude_value[175] + ); + assert_eq!( + msg.amplitude_value[176], 207, + "incorrect value for amplitude_value[176], expected 207, is {}", + msg.amplitude_value[176] + ); + assert_eq!( + msg.amplitude_value[177], 198, + "incorrect value for amplitude_value[177], expected 198, is {}", + msg.amplitude_value[177] + ); + assert_eq!( + msg.amplitude_value[178], 117, + "incorrect value for amplitude_value[178], expected 117, is {}", + msg.amplitude_value[178] + ); + assert_eq!( + msg.amplitude_value[179], 100, + "incorrect value for amplitude_value[179], expected 100, is {}", + msg.amplitude_value[179] + ); + assert_eq!( + msg.amplitude_value[180], 225, + "incorrect value for amplitude_value[180], expected 225, is {}", + msg.amplitude_value[180] + ); + assert_eq!( + msg.amplitude_value[181], 6, + "incorrect value for amplitude_value[181], expected 6, is {}", + msg.amplitude_value[181] + ); + assert_eq!( + msg.amplitude_value[182], 139, + "incorrect value for amplitude_value[182], expected 139, is {}", + msg.amplitude_value[182] + ); + assert_eq!( + msg.amplitude_value[183], 110, + "incorrect value for amplitude_value[183], expected 110, is {}", + msg.amplitude_value[183] + ); + assert_eq!( + msg.amplitude_value[184], 39, + "incorrect value for amplitude_value[184], expected 39, is {}", + msg.amplitude_value[184] + ); + assert_eq!( + msg.amplitude_value[185], 210, + "incorrect value for amplitude_value[185], expected 210, is {}", + msg.amplitude_value[185] + ); + assert_eq!( + msg.amplitude_value[186], 68, + "incorrect value for amplitude_value[186], expected 68, is {}", + msg.amplitude_value[186] + ); + assert_eq!( + msg.amplitude_value[187], 199, + "incorrect value for amplitude_value[187], expected 199, is {}", + msg.amplitude_value[187] + ); + assert_eq!( + msg.amplitude_value[188], 43, + "incorrect value for amplitude_value[188], expected 43, is {}", + msg.amplitude_value[188] + ); + assert_eq!( + msg.amplitude_value[189], 132, + "incorrect value for amplitude_value[189], expected 132, is {}", + msg.amplitude_value[189] + ); + assert_eq!( + msg.amplitude_value[190], 64, + "incorrect value for amplitude_value[190], expected 64, is {}", + msg.amplitude_value[190] + ); + assert_eq!( + msg.amplitude_value[191], 17, + "incorrect value for amplitude_value[191], expected 17, is {}", + msg.amplitude_value[191] + ); + assert_eq!( + msg.amplitude_value[192], 51, + "incorrect value for amplitude_value[192], expected 51, is {}", + msg.amplitude_value[192] + ); + assert_eq!( + msg.amplitude_value[193], 173, + "incorrect value for amplitude_value[193], expected 173, is {}", + msg.amplitude_value[193] + ); + assert_eq!( + msg.amplitude_value[194], 181, + "incorrect value for amplitude_value[194], expected 181, is {}", + msg.amplitude_value[194] + ); + assert_eq!( + msg.amplitude_value[195], 12, + "incorrect value for amplitude_value[195], expected 12, is {}", + msg.amplitude_value[195] + ); + assert_eq!( + msg.amplitude_value[196], 140, + "incorrect value for amplitude_value[196], expected 140, is {}", + msg.amplitude_value[196] + ); + assert_eq!( + msg.amplitude_value[197], 16, + "incorrect value for amplitude_value[197], expected 16, is {}", + msg.amplitude_value[197] + ); + assert_eq!( + msg.amplitude_value[198], 247, + "incorrect value for amplitude_value[198], expected 247, is {}", + msg.amplitude_value[198] + ); + assert_eq!( + msg.amplitude_value[199], 84, + "incorrect value for amplitude_value[199], expected 84, is {}", + msg.amplitude_value[199] + ); + assert_eq!( + msg.amplitude_value[200], 183, + "incorrect value for amplitude_value[200], expected 183, is {}", + msg.amplitude_value[200] + ); + assert_eq!( + msg.amplitude_value[201], 105, + "incorrect value for amplitude_value[201], expected 105, is {}", + msg.amplitude_value[201] + ); + assert_eq!( + msg.amplitude_value[202], 39, + "incorrect value for amplitude_value[202], expected 39, is {}", + msg.amplitude_value[202] + ); + assert_eq!( + msg.amplitude_value[203], 157, + "incorrect value for amplitude_value[203], expected 157, is {}", + msg.amplitude_value[203] + ); + assert_eq!( + msg.amplitude_value[204], 77, + "incorrect value for amplitude_value[204], expected 77, is {}", + msg.amplitude_value[204] + ); + assert_eq!( + msg.amplitude_value[205], 30, + "incorrect value for amplitude_value[205], expected 30, is {}", + msg.amplitude_value[205] + ); + assert_eq!( + msg.amplitude_value[206], 205, + "incorrect value for amplitude_value[206], expected 205, is {}", + msg.amplitude_value[206] + ); + assert_eq!( + msg.amplitude_value[207], 194, + "incorrect value for amplitude_value[207], expected 194, is {}", + msg.amplitude_value[207] + ); + assert_eq!( + msg.amplitude_value[208], 59, + "incorrect value for amplitude_value[208], expected 59, is {}", + msg.amplitude_value[208] + ); + assert_eq!( + msg.amplitude_value[209], 64, + "incorrect value for amplitude_value[209], expected 64, is {}", + msg.amplitude_value[209] + ); + assert_eq!( + msg.amplitude_value[210], 241, + "incorrect value for amplitude_value[210], expected 241, is {}", + msg.amplitude_value[210] + ); + assert_eq!( + msg.amplitude_value[211], 183, + "incorrect value for amplitude_value[211], expected 183, is {}", + msg.amplitude_value[211] + ); + assert_eq!( + msg.amplitude_value[212], 238, + "incorrect value for amplitude_value[212], expected 238, is {}", + msg.amplitude_value[212] + ); + assert_eq!( + msg.amplitude_value[213], 105, + "incorrect value for amplitude_value[213], expected 105, is {}", + msg.amplitude_value[213] + ); + assert_eq!( + msg.amplitude_value[214], 181, + "incorrect value for amplitude_value[214], expected 181, is {}", + msg.amplitude_value[214] + ); + assert_eq!( + msg.amplitude_value[215], 170, + "incorrect value for amplitude_value[215], expected 170, is {}", + msg.amplitude_value[215] + ); + assert_eq!( + msg.amplitude_value[216], 45, + "incorrect value for amplitude_value[216], expected 45, is {}", + msg.amplitude_value[216] + ); + assert_eq!( + msg.amplitude_value[217], 8, + "incorrect value for amplitude_value[217], expected 8, is {}", + msg.amplitude_value[217] + ); + assert_eq!( + msg.amplitude_value[218], 166, + "incorrect value for amplitude_value[218], expected 166, is {}", + msg.amplitude_value[218] + ); + assert_eq!( + msg.amplitude_value[219], 164, + "incorrect value for amplitude_value[219], expected 164, is {}", + msg.amplitude_value[219] + ); + assert_eq!( + msg.amplitude_value[220], 238, + "incorrect value for amplitude_value[220], expected 238, is {}", + msg.amplitude_value[220] + ); + assert_eq!( + msg.amplitude_value[221], 83, + "incorrect value for amplitude_value[221], expected 83, is {}", + msg.amplitude_value[221] + ); + assert_eq!( + msg.amplitude_value[222], 148, + "incorrect value for amplitude_value[222], expected 148, is {}", + msg.amplitude_value[222] + ); + assert_eq!( + msg.amplitude_value[223], 173, + "incorrect value for amplitude_value[223], expected 173, is {}", + msg.amplitude_value[223] + ); + assert_eq!( + msg.amplitude_value[224], 108, + "incorrect value for amplitude_value[224], expected 108, is {}", + msg.amplitude_value[224] + ); + assert_eq!( + msg.amplitude_value[225], 228, + "incorrect value for amplitude_value[225], expected 228, is {}", + msg.amplitude_value[225] + ); + assert_eq!( + msg.amplitude_value[226], 67, + "incorrect value for amplitude_value[226], expected 67, is {}", + msg.amplitude_value[226] + ); + assert_eq!( + msg.amplitude_value[227], 89, + "incorrect value for amplitude_value[227], expected 89, is {}", + msg.amplitude_value[227] + ); + assert_eq!( + msg.amplitude_value[228], 189, + "incorrect value for amplitude_value[228], expected 189, is {}", + msg.amplitude_value[228] + ); + assert_eq!( + msg.amplitude_value[229], 67, + "incorrect value for amplitude_value[229], expected 67, is {}", + msg.amplitude_value[229] + ); + assert_eq!( + msg.amplitude_value[230], 26, + "incorrect value for amplitude_value[230], expected 26, is {}", + msg.amplitude_value[230] + ); + assert_eq!( + msg.channel_tag, 5878, + "incorrect value for channel_tag, expected 5878, is {}", + msg.channel_tag + ); + assert!( + msg.freq_ref.almost_eq(6.34820019531250000e+03), + "incorrect value for freq_ref, expected 6.34820019531250000e+03, is {:e}", + msg.freq_ref + ); + assert!( + msg.freq_step.almost_eq(4.60820019531250000e+03), + "incorrect value for freq_step, expected 4.60820019531250000e+03, is {:e}", + msg.freq_step + ); + assert_eq!( + msg.t.tow, 992295133, + "incorrect value for t.tow, expected 992295133, is {}", + msg.t.tow + ); + assert_eq!( + msg.t.wn, 6957, + "incorrect value for t.wn, expected 6957, is {}", + msg.t.wn + ); + } + _ => panic!("Invalid message type! Expected a MsgSpecanDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_uart_state.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_uart_state.rs index df4f0117a0..782efede8d 100644 --- a/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_uart_state.rs +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_msg_uart_state.rs @@ -20,6 +20,147 @@ use crate::*; /// - Payload is identical #[test] fn test_auto_check_sbp_piksi_msg_uart_state() { + { + let mut payload = Cursor::new(vec![ + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, 89, 98, 79, 184, 138, + 244, 154, 73, 201, 69, 154, 65, 211, 69, 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, + 51, 211, 7, 69, 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, 10, 113, + 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, 107, 111, 253, 168, 244, 158, + 112, 19, 251, 131, 100, 225, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgUartState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1d, + "Incorrect message type, expected 0x1d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0c8, + "incorrect sender id, expected 0xe0c8, is {sender_id}" + ); + assert_eq!( + msg.latency.avg, 319865629, + "incorrect value for latency.avg, expected 319865629, is {}", + msg.latency.avg + ); + assert_eq!( + msg.latency.current, 364253831, + "incorrect value for latency.current, expected 364253831, is {}", + msg.latency.current + ); + assert_eq!( + msg.latency.lmax, -611749622, + "incorrect value for latency.lmax, expected -611749622, is {}", + msg.latency.lmax + ); + assert_eq!( + msg.latency.lmin, 289902239, + "incorrect value for latency.lmin, expected 289902239, is {}", + msg.latency.lmin + ); + assert_eq!( + msg.obs_period.avg, -1002717658, + "incorrect value for obs_period.avg, expected -1002717658, is {}", + msg.obs_period.avg + ); + assert_eq!( + msg.obs_period.current, -2080697488, + "incorrect value for obs_period.current, expected -2080697488, is {}", + msg.obs_period.current + ); + assert_eq!( + msg.obs_period.pmax, -1628133123, + "incorrect value for obs_period.pmax, expected -1628133123, is {}", + msg.obs_period.pmax + ); + assert_eq!( + msg.obs_period.pmin, 1869323177, + "incorrect value for obs_period.pmin, expected 1869323177, is {}", + msg.obs_period.pmin + ); + assert_eq!( + msg.uart_a.crc_error_count, 25177, + "incorrect value for uart_a.crc_error_count, expected 25177, is {}", + msg.uart_a.crc_error_count + ); + assert_eq!( + msg.uart_a.io_error_count, 47183, + "incorrect value for uart_a.io_error_count, expected 47183, is {}", + msg.uart_a.io_error_count + ); + assert_eq!( + msg.uart_a.rx_buffer_level, 244, + "incorrect value for uart_a.rx_buffer_level, expected 244, is {}", + msg.uart_a.rx_buffer_level + ); + assert!(msg.uart_a.rx_throughput.almost_eq( 1.85319995117187500e+03 ), "incorrect value for uart_a.rx_throughput, expected 1.85319995117187500e+03, is {:e}", msg.uart_a.rx_throughput); + assert_eq!( + msg.uart_a.tx_buffer_level, 138, + "incorrect value for uart_a.tx_buffer_level, expected 138, is {}", + msg.uart_a.tx_buffer_level + ); + assert!(msg.uart_a.tx_throughput.almost_eq( 7.76520019531250000e+03 ), "incorrect value for uart_a.tx_throughput, expected 7.76520019531250000e+03, is {:e}", msg.uart_a.tx_throughput); + assert_eq!( + msg.uart_b.crc_error_count, 4297, + "incorrect value for uart_b.crc_error_count, expected 4297, is {}", + msg.uart_b.crc_error_count + ); + assert_eq!( + msg.uart_b.io_error_count, 63847, + "incorrect value for uart_b.io_error_count, expected 63847, is {}", + msg.uart_b.io_error_count + ); + assert_eq!( + msg.uart_b.rx_buffer_level, 161, + "incorrect value for uart_b.rx_buffer_level, expected 161, is {}", + msg.uart_b.rx_buffer_level + ); + assert!(msg.uart_b.rx_throughput.almost_eq( 6.76020019531250000e+03 ), "incorrect value for uart_b.rx_throughput, expected 6.76020019531250000e+03, is {:e}", msg.uart_b.rx_throughput); + assert_eq!( + msg.uart_b.tx_buffer_level, 143, + "incorrect value for uart_b.tx_buffer_level, expected 143, is {}", + msg.uart_b.tx_buffer_level + ); + assert!(msg.uart_b.tx_throughput.almost_eq( 6.44120019531250000e+03 ), "incorrect value for uart_b.tx_throughput, expected 6.44120019531250000e+03, is {:e}", msg.uart_b.tx_throughput); + assert_eq!( + msg.uart_ftdi.crc_error_count, 38359, + "incorrect value for uart_ftdi.crc_error_count, expected 38359, is {}", + msg.uart_ftdi.crc_error_count + ); + assert_eq!( + msg.uart_ftdi.io_error_count, 6653, + "incorrect value for uart_ftdi.io_error_count, expected 6653, is {}", + msg.uart_ftdi.io_error_count + ); + assert_eq!( + msg.uart_ftdi.rx_buffer_level, 24, + "incorrect value for uart_ftdi.rx_buffer_level, expected 24, is {}", + msg.uart_ftdi.rx_buffer_level + ); + assert!(msg.uart_ftdi.rx_throughput.almost_eq( 2.17319995117187500e+03 ), "incorrect value for uart_ftdi.rx_throughput, expected 2.17319995117187500e+03, is {:e}", msg.uart_ftdi.rx_throughput); + assert_eq!( + msg.uart_ftdi.tx_buffer_level, 218, + "incorrect value for uart_ftdi.tx_buffer_level, expected 218, is {}", + msg.uart_ftdi.tx_buffer_level + ); + assert!(msg.uart_ftdi.tx_throughput.almost_eq( 5.95420019531250000e+03 ), "incorrect value for uart_ftdi.tx_throughput, expected 5.95420019531250000e+03, is {:e}", msg.uart_ftdi.tx_throughput); + } + _ => panic!("Invalid message type! Expected a MsgUartState"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } { let mut payload = Cursor::new(vec![ 85, 24, 0, 246, 215, 58, 26, 191, 93, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 123, 50, 62, @@ -270,6 +411,150 @@ fn test_auto_check_sbp_piksi_msg_uart_state() { #[test] #[cfg(feature = "json")] fn test_json2sbp_auto_check_sbp_piksi_msg_uart_state() { + { + let json_input = r#"{"preamble":85,"msg_type":29,"sender":57544,"length":74,"payload":"mqnyRWam50RZYk+4ivSaSclFmkHTRckQZ/mPoZoRukUz0wdF15X9GdoYHcMQE5+ORxEKcYnbhxK2FSa+O8Spm2tv/aj0nnAT+4M=","crc":57700,"uart_a":{"tx_throughput":7765.2001953125,"rx_throughput":1853.199951171875,"crc_error_count":25177,"io_error_count":47183,"tx_buffer_level":138,"rx_buffer_level":244},"uart_b":{"tx_throughput":6441.2001953125,"rx_throughput":6760.2001953125,"crc_error_count":4297,"io_error_count":63847,"tx_buffer_level":143,"rx_buffer_level":161},"uart_ftdi":{"tx_throughput":5954.2001953125,"rx_throughput":2173.199951171875,"crc_error_count":38359,"io_error_count":6653,"tx_buffer_level":218,"rx_buffer_level":24},"latency":{"avg":319865629,"lmin":289902239,"lmax":-611749622,"current":364253831},"obs_period":{"avg":-1002717658,"pmin":1869323177,"pmax":-1628133123,"current":-2080697488}}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgUartState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1d, + "Incorrect message type, expected 0x1d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0c8, + "incorrect sender id, expected 0xe0c8, is {sender_id}" + ); + assert_eq!( + msg.latency.avg, 319865629, + "incorrect value for latency.avg, expected 319865629, is {}", + msg.latency.avg + ); + assert_eq!( + msg.latency.current, 364253831, + "incorrect value for latency.current, expected 364253831, is {}", + msg.latency.current + ); + assert_eq!( + msg.latency.lmax, -611749622, + "incorrect value for latency.lmax, expected -611749622, is {}", + msg.latency.lmax + ); + assert_eq!( + msg.latency.lmin, 289902239, + "incorrect value for latency.lmin, expected 289902239, is {}", + msg.latency.lmin + ); + assert_eq!( + msg.obs_period.avg, -1002717658, + "incorrect value for obs_period.avg, expected -1002717658, is {}", + msg.obs_period.avg + ); + assert_eq!( + msg.obs_period.current, -2080697488, + "incorrect value for obs_period.current, expected -2080697488, is {}", + msg.obs_period.current + ); + assert_eq!( + msg.obs_period.pmax, -1628133123, + "incorrect value for obs_period.pmax, expected -1628133123, is {}", + msg.obs_period.pmax + ); + assert_eq!( + msg.obs_period.pmin, 1869323177, + "incorrect value for obs_period.pmin, expected 1869323177, is {}", + msg.obs_period.pmin + ); + assert_eq!( + msg.uart_a.crc_error_count, 25177, + "incorrect value for uart_a.crc_error_count, expected 25177, is {}", + msg.uart_a.crc_error_count + ); + assert_eq!( + msg.uart_a.io_error_count, 47183, + "incorrect value for uart_a.io_error_count, expected 47183, is {}", + msg.uart_a.io_error_count + ); + assert_eq!( + msg.uart_a.rx_buffer_level, 244, + "incorrect value for uart_a.rx_buffer_level, expected 244, is {}", + msg.uart_a.rx_buffer_level + ); + assert!(msg.uart_a.rx_throughput.almost_eq( 1.85319995117187500e+03 ), "incorrect value for uart_a.rx_throughput, expected 1.85319995117187500e+03, is {:e}", msg.uart_a.rx_throughput); + assert_eq!( + msg.uart_a.tx_buffer_level, 138, + "incorrect value for uart_a.tx_buffer_level, expected 138, is {}", + msg.uart_a.tx_buffer_level + ); + assert!(msg.uart_a.tx_throughput.almost_eq( 7.76520019531250000e+03 ), "incorrect value for uart_a.tx_throughput, expected 7.76520019531250000e+03, is {:e}", msg.uart_a.tx_throughput); + assert_eq!( + msg.uart_b.crc_error_count, 4297, + "incorrect value for uart_b.crc_error_count, expected 4297, is {}", + msg.uart_b.crc_error_count + ); + assert_eq!( + msg.uart_b.io_error_count, 63847, + "incorrect value for uart_b.io_error_count, expected 63847, is {}", + msg.uart_b.io_error_count + ); + assert_eq!( + msg.uart_b.rx_buffer_level, 161, + "incorrect value for uart_b.rx_buffer_level, expected 161, is {}", + msg.uart_b.rx_buffer_level + ); + assert!(msg.uart_b.rx_throughput.almost_eq( 6.76020019531250000e+03 ), "incorrect value for uart_b.rx_throughput, expected 6.76020019531250000e+03, is {:e}", msg.uart_b.rx_throughput); + assert_eq!( + msg.uart_b.tx_buffer_level, 143, + "incorrect value for uart_b.tx_buffer_level, expected 143, is {}", + msg.uart_b.tx_buffer_level + ); + assert!(msg.uart_b.tx_throughput.almost_eq( 6.44120019531250000e+03 ), "incorrect value for uart_b.tx_throughput, expected 6.44120019531250000e+03, is {:e}", msg.uart_b.tx_throughput); + assert_eq!( + msg.uart_ftdi.crc_error_count, 38359, + "incorrect value for uart_ftdi.crc_error_count, expected 38359, is {}", + msg.uart_ftdi.crc_error_count + ); + assert_eq!( + msg.uart_ftdi.io_error_count, 6653, + "incorrect value for uart_ftdi.io_error_count, expected 6653, is {}", + msg.uart_ftdi.io_error_count + ); + assert_eq!( + msg.uart_ftdi.rx_buffer_level, 24, + "incorrect value for uart_ftdi.rx_buffer_level, expected 24, is {}", + msg.uart_ftdi.rx_buffer_level + ); + assert!(msg.uart_ftdi.rx_throughput.almost_eq( 2.17319995117187500e+03 ), "incorrect value for uart_ftdi.rx_throughput, expected 2.17319995117187500e+03, is {:e}", msg.uart_ftdi.rx_throughput); + assert_eq!( + msg.uart_ftdi.tx_buffer_level, 218, + "incorrect value for uart_ftdi.tx_buffer_level, expected 218, is {}", + msg.uart_ftdi.tx_buffer_level + ); + assert!(msg.uart_ftdi.tx_throughput.almost_eq( 5.95420019531250000e+03 ), "incorrect value for uart_ftdi.tx_throughput, expected 5.95420019531250000e+03, is {:e}", msg.uart_ftdi.tx_throughput); + } + _ => panic!("Invalid message type! Expected a MsgUartState"), + }; + } { let json_input = r#"{"latency": {"current": -1, "lmax": 0, "avg": -1, "lmin": 0}, "sender": 55286, "msg_type": 24, "crc": 31815, "length": 58, "uart_b": {"rx_buffer_level": 0, "tx_buffer_level": 40, "rx_throughput": 0.0, "crc_error_count": 0, "io_error_count": 0, "tx_throughput": 2.9718310832977295}, "uart_a": {"rx_buffer_level": 0, "tx_buffer_level": 24, "rx_throughput": 0.0, "crc_error_count": 0, "io_error_count": 0, "tx_throughput": 0.8661972284317017}, "preamble": 85, "payload": "Gr9dPwAAAAAAAAAAGAB7Mj5AAAAAAAAAAAAoADYHokCxORA9AAAAAFEB/////wAAAAAAAAAA/////w==", "uart_ftdi": {"rx_buffer_level": 1, "tx_buffer_level": 81, "rx_throughput": 0.035211268812417984, "crc_error_count": 0, "io_error_count": 0, "tx_throughput": 5.063380241394043}}"#.as_bytes(); @@ -531,6 +816,166 @@ fn test_json2sbp_auto_check_sbp_piksi_msg_uart_state() { #[test] #[cfg(feature = "json")] fn test_sbp2json_auto_check_sbp_piksi_msg_uart_state() { + { + let mut payload = Cursor::new(vec![ + 85, 29, 0, 200, 224, 74, 154, 169, 242, 69, 102, 166, 231, 68, 89, 98, 79, 184, 138, + 244, 154, 73, 201, 69, 154, 65, 211, 69, 201, 16, 103, 249, 143, 161, 154, 17, 186, 69, + 51, 211, 7, 69, 215, 149, 253, 25, 218, 24, 29, 195, 16, 19, 159, 142, 71, 17, 10, 113, + 137, 219, 135, 18, 182, 21, 38, 190, 59, 196, 169, 155, 107, 111, 253, 168, 244, 158, + 112, 19, 251, 131, 100, 225, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgUartState( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgUartState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1d, + "Incorrect message type, expected 0x1d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0c8, + "incorrect sender id, expected 0xe0c8, is {sender_id}" + ); + assert_eq!( + msg.latency.avg, 319865629, + "incorrect value for latency.avg, expected 319865629, is {}", + msg.latency.avg + ); + assert_eq!( + msg.latency.current, 364253831, + "incorrect value for latency.current, expected 364253831, is {}", + msg.latency.current + ); + assert_eq!( + msg.latency.lmax, -611749622, + "incorrect value for latency.lmax, expected -611749622, is {}", + msg.latency.lmax + ); + assert_eq!( + msg.latency.lmin, 289902239, + "incorrect value for latency.lmin, expected 289902239, is {}", + msg.latency.lmin + ); + assert_eq!( + msg.obs_period.avg, -1002717658, + "incorrect value for obs_period.avg, expected -1002717658, is {}", + msg.obs_period.avg + ); + assert_eq!( + msg.obs_period.current, -2080697488, + "incorrect value for obs_period.current, expected -2080697488, is {}", + msg.obs_period.current + ); + assert_eq!( + msg.obs_period.pmax, -1628133123, + "incorrect value for obs_period.pmax, expected -1628133123, is {}", + msg.obs_period.pmax + ); + assert_eq!( + msg.obs_period.pmin, 1869323177, + "incorrect value for obs_period.pmin, expected 1869323177, is {}", + msg.obs_period.pmin + ); + assert_eq!( + msg.uart_a.crc_error_count, 25177, + "incorrect value for uart_a.crc_error_count, expected 25177, is {}", + msg.uart_a.crc_error_count + ); + assert_eq!( + msg.uart_a.io_error_count, 47183, + "incorrect value for uart_a.io_error_count, expected 47183, is {}", + msg.uart_a.io_error_count + ); + assert_eq!( + msg.uart_a.rx_buffer_level, 244, + "incorrect value for uart_a.rx_buffer_level, expected 244, is {}", + msg.uart_a.rx_buffer_level + ); + assert!(msg.uart_a.rx_throughput.almost_eq( 1.85319995117187500e+03 ), "incorrect value for uart_a.rx_throughput, expected 1.85319995117187500e+03, is {:e}", msg.uart_a.rx_throughput); + assert_eq!( + msg.uart_a.tx_buffer_level, 138, + "incorrect value for uart_a.tx_buffer_level, expected 138, is {}", + msg.uart_a.tx_buffer_level + ); + assert!(msg.uart_a.tx_throughput.almost_eq( 7.76520019531250000e+03 ), "incorrect value for uart_a.tx_throughput, expected 7.76520019531250000e+03, is {:e}", msg.uart_a.tx_throughput); + assert_eq!( + msg.uart_b.crc_error_count, 4297, + "incorrect value for uart_b.crc_error_count, expected 4297, is {}", + msg.uart_b.crc_error_count + ); + assert_eq!( + msg.uart_b.io_error_count, 63847, + "incorrect value for uart_b.io_error_count, expected 63847, is {}", + msg.uart_b.io_error_count + ); + assert_eq!( + msg.uart_b.rx_buffer_level, 161, + "incorrect value for uart_b.rx_buffer_level, expected 161, is {}", + msg.uart_b.rx_buffer_level + ); + assert!(msg.uart_b.rx_throughput.almost_eq( 6.76020019531250000e+03 ), "incorrect value for uart_b.rx_throughput, expected 6.76020019531250000e+03, is {:e}", msg.uart_b.rx_throughput); + assert_eq!( + msg.uart_b.tx_buffer_level, 143, + "incorrect value for uart_b.tx_buffer_level, expected 143, is {}", + msg.uart_b.tx_buffer_level + ); + assert!(msg.uart_b.tx_throughput.almost_eq( 6.44120019531250000e+03 ), "incorrect value for uart_b.tx_throughput, expected 6.44120019531250000e+03, is {:e}", msg.uart_b.tx_throughput); + assert_eq!( + msg.uart_ftdi.crc_error_count, 38359, + "incorrect value for uart_ftdi.crc_error_count, expected 38359, is {}", + msg.uart_ftdi.crc_error_count + ); + assert_eq!( + msg.uart_ftdi.io_error_count, 6653, + "incorrect value for uart_ftdi.io_error_count, expected 6653, is {}", + msg.uart_ftdi.io_error_count + ); + assert_eq!( + msg.uart_ftdi.rx_buffer_level, 24, + "incorrect value for uart_ftdi.rx_buffer_level, expected 24, is {}", + msg.uart_ftdi.rx_buffer_level + ); + assert!(msg.uart_ftdi.rx_throughput.almost_eq( 2.17319995117187500e+03 ), "incorrect value for uart_ftdi.rx_throughput, expected 2.17319995117187500e+03, is {:e}", msg.uart_ftdi.rx_throughput); + assert_eq!( + msg.uart_ftdi.tx_buffer_level, 218, + "incorrect value for uart_ftdi.tx_buffer_level, expected 218, is {}", + msg.uart_ftdi.tx_buffer_level + ); + assert!(msg.uart_ftdi.tx_throughput.almost_eq( 5.95420019531250000e+03 ), "incorrect value for uart_ftdi.tx_throughput, expected 5.95420019531250000e+03, is {:e}", msg.uart_ftdi.tx_throughput); + } + _ => panic!("Invalid message type! Expected a MsgUartState"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } { let mut payload = Cursor::new(vec![ 85, 24, 0, 246, 215, 58, 26, 191, 93, 63, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 123, 50, 62, diff --git a/rust/sbp/tests/integration/auto_check_sbp_piksi_piksi_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_piksi_piksi_structs.rs new file mode 100644 index 0000000000..cf472c824d --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_piksi_piksi_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/piksi/test_piksi_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_piksi_piksi_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_piksi_piksi_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_piksi_piksi_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_piksi_piksi_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_by_index_req.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_by_index_req.rs new file mode 100644 index 0000000000..fc3ff1add1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_by_index_req.rs @@ -0,0 +1,178 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_read_by_index_req() { + { + let mut payload = Cursor::new(vec![85, 162, 0, 122, 123, 2, 244, 34, 235, 23]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadByIndexReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa2, + "Incorrect message type, expected 0xa2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b7a, + "incorrect sender id, expected 0x7b7a, is {sender_id}" + ); + assert_eq!( + msg.index, 8948, + "incorrect value for index, expected 8948, is {}", + msg.index + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadByIndexReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_read_by_index_req() { + { + let json_input = r#"{"crc":6123,"length":2,"msg_type":162,"payload":"9CI=","preamble":85,"sender":31610,"index":8948}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadByIndexReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa2, + "Incorrect message type, expected 0xa2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b7a, + "incorrect sender id, expected 0x7b7a, is {sender_id}" + ); + assert_eq!( + msg.index, 8948, + "incorrect value for index, expected 8948, is {}", + msg.index + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadByIndexReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_read_by_index_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_read_by_index_req() { + { + let mut payload = Cursor::new(vec![85, 162, 0, 122, 123, 2, 244, 34, 235, 23]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsReadByIndexReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadByIndexReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa2, + "Incorrect message type, expected 0xa2, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b7a, + "incorrect sender id, expected 0x7b7a, is {sender_id}" + ); + assert_eq!( + msg.index, 8948, + "incorrect value for index, expected 8948, is {}", + msg.index + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadByIndexReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_req.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_req.rs new file mode 100644 index 0000000000..8ed1bbf7bf --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_req.rs @@ -0,0 +1,208 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_read_req() { + { + let mut payload = Cursor::new(vec![ + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa4, + "Incorrect message type, expected 0xa4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd698, + "incorrect sender id, expected 0xd698, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadReq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_read_req() { + { + let json_input = r#"{"crc":58549,"length":26,"msg_type":164,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQA=","preamble":85,"sender":54936,"setting":"section-name\u0000setting-name\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa4, + "Incorrect message type, expected 0xa4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd698, + "incorrect sender id, expected 0xd698, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadReq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_read_req`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_read_req() { + { + let mut payload = Cursor::new(vec![ + 85, 164, 0, 152, 214, 26, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 181, 228, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsReadReq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadReq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa4, + "Incorrect message type, expected 0xa4, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd698, + "incorrect sender id, expected 0xd698, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadReq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_resp.rs new file mode 100644 index 0000000000..850a37a2e1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_read_resp.rs @@ -0,0 +1,230 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, + 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 203, 199, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa5, + "Incorrect message type, expected 0xa5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf088, + "incorrect sender id, expected 0xf088, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_read_resp() { + { + let json_input = r#"{"crc":51147,"length":66,"msg_type":165,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA","preamble":85,"sender":61576,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa5, + "Incorrect message type, expected 0xa5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf088, + "incorrect sender id, expected 0xf088, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_read_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_read_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 165, 0, 136, 240, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, + 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 203, 199, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsReadResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsReadResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa5, + "Incorrect message type, expected 0xa5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf088, + "incorrect sender id, expected 0xf088, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsReadResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register.rs new file mode 100644 index 0000000000..35e02b93f3 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register.rs @@ -0,0 +1,230 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_register() { + { + let mut payload = Cursor::new(vec![ + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, + 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 142, 235, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegister(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xae, + "Incorrect message type, expected 0xae, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0654, + "incorrect sender id, expected 0x0654, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegister"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_register() { + { + let json_input = r#"{"crc":60302,"length":66,"msg_type":174,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA","preamble":85,"sender":1620,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegister(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xae, + "Incorrect message type, expected 0xae, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0654, + "incorrect sender id, expected 0x0654, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegister"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_register`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_register() { + { + let mut payload = Cursor::new(vec![ + 85, 174, 0, 84, 6, 66, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, + 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, 117, 101, 49, + 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 142, 235, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsRegister( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegister(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xae, + "Incorrect message type, expected 0xae, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0654, + "incorrect sender id, expected 0x0654, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegister"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register_resp.rs new file mode 100644 index 0000000000..6c389f7d34 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_register_resp.rs @@ -0,0 +1,247 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_register_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, + 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 82, + 16, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegisterResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1af, + "Incorrect message type, expected 0x1af, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd529, + "incorrect sender id, expected 0xd529, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 18, + "incorrect value for status, expected 18, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegisterResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_register_resp() { + { + let json_input = r#"{"crc":4178,"length":67,"msg_type":431,"payload":"EnNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA==","preamble":85,"sender":54569,"status":18,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegisterResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1af, + "Incorrect message type, expected 0x1af, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd529, + "incorrect sender id, expected 0xd529, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 18, + "incorrect value for status, expected 18, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegisterResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_register_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_register_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 175, 1, 41, 213, 67, 18, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, + 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 82, + 16, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsRegisterResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsRegisterResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1af, + "Incorrect message type, expected 0x1af, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd529, + "incorrect sender id, expected 0xd529, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 18, + "incorrect value for status, expected 18, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsRegisterResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_save.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_save.rs new file mode 100644 index 0000000000..48d4d7cd71 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_save.rs @@ -0,0 +1,165 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_save() { + { + let mut payload = Cursor::new(vec![85, 161, 0, 162, 224, 0, 123, 67]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsSave(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa1, + "Incorrect message type, expected 0xa1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0a2, + "incorrect sender id, expected 0xe0a2, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsSave"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_save() { + { + let json_input = + r#"{"crc":17275,"length":0,"msg_type":161,"payload":"","preamble":85,"sender":57506}"# + .as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsSave(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa1, + "Incorrect message type, expected 0xa1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0a2, + "incorrect sender id, expected 0xe0a2, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsSave"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_save`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_save() { + { + let mut payload = Cursor::new(vec![85, 161, 0, 162, 224, 0, 123, 67]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsSave( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsSave(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa1, + "Incorrect message type, expected 0xa1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe0a2, + "incorrect sender id, expected 0xe0a2, is {sender_id}" + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsSave"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write.rs new file mode 100644 index 0000000000..8923cae48a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write.rs @@ -0,0 +1,216 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_write() { + { + let mut payload = Cursor::new(vec![ + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWrite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa0, + "Incorrect message type, expected 0xa0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b, + "incorrect sender id, expected 0x7b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWrite"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_write() { + { + let json_input = r#"{"crc":2804,"length":40,"msg_type":160,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAA==","preamble":85,"sender":123,"setting":"section-name\u0000setting-name\u0000setting-value\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWrite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa0, + "Incorrect message type, expected 0xa0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b, + "incorrect sender id, expected 0x7b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWrite"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_write`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_write() { + { + let mut payload = Cursor::new(vec![ + 85, 160, 0, 123, 0, 40, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, + 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, + 110, 103, 45, 118, 97, 108, 117, 101, 0, 244, 10, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsWrite( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWrite(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xa0, + "Incorrect message type, expected 0xa0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x7b, + "incorrect sender id, expected 0x7b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0 + ], + msg.setting.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWrite"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write_resp.rs b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write_resp.rs new file mode 100644 index 0000000000..0f6616ab32 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_settings_msg_settings_write_resp.rs @@ -0,0 +1,245 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_settings_msg_settings_write_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, + 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWriteResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaf, + "Incorrect message type, expected 0xaf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x375b, + "incorrect sender id, expected 0x375b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 152, + "incorrect value for status, expected 152, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWriteResp"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_settings_msg_settings_write_resp() { + { + let json_input = r#"{"crc":54,"length":67,"msg_type":175,"payload":"mHNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA==","preamble":85,"sender":14171,"status":152,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWriteResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaf, + "Incorrect message type, expected 0xaf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x375b, + "incorrect sender id, expected 0x375b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 152, + "incorrect value for status, expected 152, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWriteResp"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_settings_msg_settings_write_resp`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_settings_msg_settings_write_resp() { + { + let mut payload = Cursor::new(vec![ + 85, 175, 0, 91, 55, 67, 152, 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, + 0, 115, 101, 116, 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, + 105, 110, 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, 51, 0, 54, 0, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSettingsWriteResp( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSettingsWriteResp(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xaf, + "Incorrect message type, expected 0xaf, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x375b, + "incorrect sender id, expected 0x375b, is {sender_id}" + ); + assert_eq!( + msg.setting.as_bytes(), + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + "incorrect value for msg.setting, expected string '{:?}', is '{:?}'", + &[ + 115, 101, 99, 116, 105, 111, 110, 45, 110, 97, 109, 101, 0, 115, 101, 116, + 116, 105, 110, 103, 45, 110, 97, 109, 101, 0, 115, 101, 116, 116, 105, 110, + 103, 45, 118, 97, 108, 117, 101, 0, 101, 110, 117, 109, 59, 118, 97, 108, + 117, 101, 49, 44, 118, 97, 108, 117, 101, 50, 44, 118, 97, 108, 117, 101, + 51, 0 + ], + msg.setting.as_bytes() + ); + assert_eq!( + msg.status, 152, + "incorrect value for status, expected 152, is {}", + msg.status + ); + } + _ => panic!("Invalid message type! Expected a MsgSettingsWriteResp"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_signing_signing_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_signing_signing_structs.rs new file mode 100644 index 0000000000..26e83b479e --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_signing_signing_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/signing/test_signing_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_signing_signing_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_signing_signing_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_signing_signing_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_signing_signing_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_soln_meta_soln_meta_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_soln_meta_soln_meta_structs.rs new file mode 100644 index 0000000000..214ef21b52 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_soln_meta_soln_meta_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/soln_meta/test_soln_meta_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_soln_meta_soln_meta_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_soln_meta_soln_meta_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_soln_meta_soln_meta_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_soln_meta_soln_meta_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta.rs b/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta.rs new file mode 100644 index 0000000000..123bb2332b --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta.rs @@ -0,0 +1,3853 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_solution_meta_msg_soln_meta() { + { + let mut payload = Cursor::new(vec![ + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, 144, 228, 8, 83, 89, 87, + 3, 213, 95, 109, 86, 131, 71, 70, 84, 73, 131, 26, 82, 247, 140, 97, 115, 110, 118, + 253, 2, 122, 186, 148, 122, 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, 208, 89, + 56, 10, 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, 238, 123, 102, 230, 76, 190, 225, + 182, 207, 228, 7, 218, 117, 89, 29, 191, 56, 248, 185, 255, 46, 18, 72, 142, 82, 113, + 26, 4, 172, 254, 178, 136, 113, 115, 58, 193, 89, 227, 182, 246, 76, 77, 108, 245, 41, + 31, 70, 124, 249, 145, 15, 78, 228, 38, 241, 129, 8, 176, 251, 72, 248, 80, 115, 244, + 231, 145, 191, 190, 178, 168, 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, 92, 79, + 101, 223, 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, 36, 219, 56, 146, 90, 219, + 104, 227, 102, 83, 12, 41, 122, 173, 94, 1, 174, 134, 130, 104, 237, 116, 249, 107, + 230, 130, 123, 25, 162, 57, 223, 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, + 100, 66, 72, 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, 141, 25, 183, + 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, 180, 46, 140, 130, 36, 17, 194, 209, + 65, 254, 115, 103, 152, 129, 234, 235, 194, 234, 170, 201, 210, 154, 150, 247, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMeta(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0e, + "Incorrect message type, expected 0xff0e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3c00, + "incorrect sender id, expected 0x3c00, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 21256, + "incorrect value for age_corrections, expected 21256, is {}", + msg.age_corrections + ); + assert_eq!( + msg.age_gnss, 3573765977, + "incorrect value for age_gnss, expected 3573765977, is {}", + msg.age_gnss + ); + assert_eq!( + msg.hdop, 41156, + "incorrect value for hdop, expected 41156, is {}", + msg.hdop + ); + assert_eq!( + msg.pdop, 11642, + "incorrect value for pdop, expected 11642, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 109, + "incorrect value for sol_in[0].flags, expected 109, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 95, + "incorrect value for sol_in[0].sensor_type, expected 95, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 131, + "incorrect value for sol_in[1].flags, expected 131, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 86, + "incorrect value for sol_in[1].sensor_type, expected 86, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 70, + "incorrect value for sol_in[2].flags, expected 70, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 71, + "incorrect value for sol_in[2].sensor_type, expected 71, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 73, + "incorrect value for sol_in[3].flags, expected 73, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 84, + "incorrect value for sol_in[3].sensor_type, expected 84, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 26, + "incorrect value for sol_in[4].flags, expected 26, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 131, + "incorrect value for sol_in[4].sensor_type, expected 131, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 247, + "incorrect value for sol_in[5].flags, expected 247, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 82, + "incorrect value for sol_in[5].sensor_type, expected 82, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 97, + "incorrect value for sol_in[6].flags, expected 97, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 140, + "incorrect value for sol_in[6].sensor_type, expected 140, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 110, + "incorrect value for sol_in[7].flags, expected 110, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 115, + "incorrect value for sol_in[7].sensor_type, expected 115, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 253, + "incorrect value for sol_in[8].flags, expected 253, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 118, + "incorrect value for sol_in[8].sensor_type, expected 118, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 122, + "incorrect value for sol_in[9].flags, expected 122, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 2, + "incorrect value for sol_in[9].sensor_type, expected 2, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 148, + "incorrect value for sol_in[10].flags, expected 148, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 186, + "incorrect value for sol_in[10].sensor_type, expected 186, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 148, + "incorrect value for sol_in[11].flags, expected 148, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 122, + "incorrect value for sol_in[11].sensor_type, expected 122, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 231, + "incorrect value for sol_in[12].flags, expected 231, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 180, + "incorrect value for sol_in[12].sensor_type, expected 180, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 46, + "incorrect value for sol_in[13].flags, expected 46, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 68, + "incorrect value for sol_in[13].sensor_type, expected 68, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 102, + "incorrect value for sol_in[14].flags, expected 102, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 190, + "incorrect value for sol_in[14].sensor_type, expected 190, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 48, + "incorrect value for sol_in[15].flags, expected 48, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 243, + "incorrect value for sol_in[15].sensor_type, expected 243, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 15, + "incorrect value for sol_in[16].flags, expected 15, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 192, + "incorrect value for sol_in[16].sensor_type, expected 192, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 89, + "incorrect value for sol_in[17].flags, expected 89, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 208, + "incorrect value for sol_in[17].sensor_type, expected 208, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 10, + "incorrect value for sol_in[18].flags, expected 10, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 56, + "incorrect value for sol_in[18].sensor_type, expected 56, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 2, + "incorrect value for sol_in[19].flags, expected 2, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 245, + "incorrect value for sol_in[19].sensor_type, expected 245, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 201, + "incorrect value for sol_in[20].flags, expected 201, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 254, + "incorrect value for sol_in[20].sensor_type, expected 254, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 32, + "incorrect value for sol_in[21].flags, expected 32, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 120, + "incorrect value for sol_in[21].sensor_type, expected 120, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 2, + "incorrect value for sol_in[22].flags, expected 2, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 126, + "incorrect value for sol_in[22].sensor_type, expected 126, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 161, + "incorrect value for sol_in[23].flags, expected 161, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 83, + "incorrect value for sol_in[23].sensor_type, expected 83, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 123, + "incorrect value for sol_in[24].flags, expected 123, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 238, + "incorrect value for sol_in[24].sensor_type, expected 238, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 230, + "incorrect value for sol_in[25].flags, expected 230, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 102, + "incorrect value for sol_in[25].sensor_type, expected 102, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 190, + "incorrect value for sol_in[26].flags, expected 190, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 76, + "incorrect value for sol_in[26].sensor_type, expected 76, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 182, + "incorrect value for sol_in[27].flags, expected 182, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 225, + "incorrect value for sol_in[27].sensor_type, expected 225, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 228, + "incorrect value for sol_in[28].flags, expected 228, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 207, + "incorrect value for sol_in[28].sensor_type, expected 207, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 218, + "incorrect value for sol_in[29].flags, expected 218, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 7, + "incorrect value for sol_in[29].sensor_type, expected 7, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 89, + "incorrect value for sol_in[30].flags, expected 89, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 117, + "incorrect value for sol_in[30].sensor_type, expected 117, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 191, + "incorrect value for sol_in[31].flags, expected 191, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 29, + "incorrect value for sol_in[31].sensor_type, expected 29, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 248, + "incorrect value for sol_in[32].flags, expected 248, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 56, + "incorrect value for sol_in[32].sensor_type, expected 56, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 255, + "incorrect value for sol_in[33].flags, expected 255, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 185, + "incorrect value for sol_in[33].sensor_type, expected 185, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 18, + "incorrect value for sol_in[34].flags, expected 18, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 46, + "incorrect value for sol_in[34].sensor_type, expected 46, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 142, + "incorrect value for sol_in[35].flags, expected 142, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 72, + "incorrect value for sol_in[35].sensor_type, expected 72, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 113, + "incorrect value for sol_in[36].flags, expected 113, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 82, + "incorrect value for sol_in[36].sensor_type, expected 82, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 4, + "incorrect value for sol_in[37].flags, expected 4, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 26, + "incorrect value for sol_in[37].sensor_type, expected 26, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 254, + "incorrect value for sol_in[38].flags, expected 254, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 172, + "incorrect value for sol_in[38].sensor_type, expected 172, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 136, + "incorrect value for sol_in[39].flags, expected 136, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 178, + "incorrect value for sol_in[39].sensor_type, expected 178, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 115, + "incorrect value for sol_in[40].flags, expected 115, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 113, + "incorrect value for sol_in[40].sensor_type, expected 113, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 193, + "incorrect value for sol_in[41].flags, expected 193, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 58, + "incorrect value for sol_in[41].sensor_type, expected 58, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 227, + "incorrect value for sol_in[42].flags, expected 227, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 89, + "incorrect value for sol_in[42].sensor_type, expected 89, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 246, + "incorrect value for sol_in[43].flags, expected 246, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 182, + "incorrect value for sol_in[43].sensor_type, expected 182, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 77, + "incorrect value for sol_in[44].flags, expected 77, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 76, + "incorrect value for sol_in[44].sensor_type, expected 76, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 245, + "incorrect value for sol_in[45].flags, expected 245, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 108, + "incorrect value for sol_in[45].sensor_type, expected 108, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 31, + "incorrect value for sol_in[46].flags, expected 31, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 41, + "incorrect value for sol_in[46].sensor_type, expected 41, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 124, + "incorrect value for sol_in[47].flags, expected 124, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 70, + "incorrect value for sol_in[47].sensor_type, expected 70, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 145, + "incorrect value for sol_in[48].flags, expected 145, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 249, + "incorrect value for sol_in[48].sensor_type, expected 249, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 78, + "incorrect value for sol_in[49].flags, expected 78, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 15, + "incorrect value for sol_in[49].sensor_type, expected 15, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 38, + "incorrect value for sol_in[50].flags, expected 38, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 228, + "incorrect value for sol_in[50].sensor_type, expected 228, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 129, + "incorrect value for sol_in[51].flags, expected 129, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 241, + "incorrect value for sol_in[51].sensor_type, expected 241, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 176, + "incorrect value for sol_in[52].flags, expected 176, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 8, + "incorrect value for sol_in[52].sensor_type, expected 8, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 72, + "incorrect value for sol_in[53].flags, expected 72, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 251, + "incorrect value for sol_in[53].sensor_type, expected 251, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 80, + "incorrect value for sol_in[54].flags, expected 80, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 248, + "incorrect value for sol_in[54].sensor_type, expected 248, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 244, + "incorrect value for sol_in[55].flags, expected 244, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 115, + "incorrect value for sol_in[55].sensor_type, expected 115, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 145, + "incorrect value for sol_in[56].flags, expected 145, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 231, + "incorrect value for sol_in[56].sensor_type, expected 231, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 190, + "incorrect value for sol_in[57].flags, expected 190, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 191, + "incorrect value for sol_in[57].sensor_type, expected 191, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 168, + "incorrect value for sol_in[58].flags, expected 168, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 178, + "incorrect value for sol_in[58].sensor_type, expected 178, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 233, + "incorrect value for sol_in[59].flags, expected 233, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 89, + "incorrect value for sol_in[59].sensor_type, expected 89, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 176, + "incorrect value for sol_in[60].flags, expected 176, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 69, + "incorrect value for sol_in[60].sensor_type, expected 69, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 140, + "incorrect value for sol_in[61].flags, expected 140, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 174, + "incorrect value for sol_in[61].sensor_type, expected 174, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 141, + "incorrect value for sol_in[62].flags, expected 141, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 182, + "incorrect value for sol_in[62].sensor_type, expected 182, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 82, + "incorrect value for sol_in[63].flags, expected 82, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 81, + "incorrect value for sol_in[63].sensor_type, expected 81, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 79, + "incorrect value for sol_in[64].flags, expected 79, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 92, + "incorrect value for sol_in[64].sensor_type, expected 92, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 223, + "incorrect value for sol_in[65].flags, expected 223, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 101, + "incorrect value for sol_in[65].sensor_type, expected 101, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 64, + "incorrect value for sol_in[66].flags, expected 64, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 100, + "incorrect value for sol_in[66].sensor_type, expected 100, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 215, + "incorrect value for sol_in[67].flags, expected 215, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 184, + "incorrect value for sol_in[67].sensor_type, expected 184, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 37, + "incorrect value for sol_in[68].flags, expected 37, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 124, + "incorrect value for sol_in[68].sensor_type, expected 124, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 227, + "incorrect value for sol_in[69].flags, expected 227, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 21, + "incorrect value for sol_in[69].sensor_type, expected 21, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 102, + "incorrect value for sol_in[70].flags, expected 102, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 135, + "incorrect value for sol_in[70].sensor_type, expected 135, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 36, + "incorrect value for sol_in[71].flags, expected 36, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 72, + "incorrect value for sol_in[71].sensor_type, expected 72, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 56, + "incorrect value for sol_in[72].flags, expected 56, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 219, + "incorrect value for sol_in[72].sensor_type, expected 219, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 90, + "incorrect value for sol_in[73].flags, expected 90, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 146, + "incorrect value for sol_in[73].sensor_type, expected 146, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 104, + "incorrect value for sol_in[74].flags, expected 104, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 219, + "incorrect value for sol_in[74].sensor_type, expected 219, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 102, + "incorrect value for sol_in[75].flags, expected 102, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 227, + "incorrect value for sol_in[75].sensor_type, expected 227, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 12, + "incorrect value for sol_in[76].flags, expected 12, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 83, + "incorrect value for sol_in[76].sensor_type, expected 83, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 122, + "incorrect value for sol_in[77].flags, expected 122, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 41, + "incorrect value for sol_in[77].sensor_type, expected 41, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 94, + "incorrect value for sol_in[78].flags, expected 94, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 173, + "incorrect value for sol_in[78].sensor_type, expected 173, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 174, + "incorrect value for sol_in[79].flags, expected 174, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 1, + "incorrect value for sol_in[79].sensor_type, expected 1, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 130, + "incorrect value for sol_in[80].flags, expected 130, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 134, + "incorrect value for sol_in[80].sensor_type, expected 134, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 237, + "incorrect value for sol_in[81].flags, expected 237, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 104, + "incorrect value for sol_in[81].sensor_type, expected 104, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 249, + "incorrect value for sol_in[82].flags, expected 249, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 116, + "incorrect value for sol_in[82].sensor_type, expected 116, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 230, + "incorrect value for sol_in[83].flags, expected 230, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 107, + "incorrect value for sol_in[83].sensor_type, expected 107, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 123, + "incorrect value for sol_in[84].flags, expected 123, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 130, + "incorrect value for sol_in[84].sensor_type, expected 130, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 162, + "incorrect value for sol_in[85].flags, expected 162, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 25, + "incorrect value for sol_in[85].sensor_type, expected 25, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 223, + "incorrect value for sol_in[86].flags, expected 223, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 57, + "incorrect value for sol_in[86].sensor_type, expected 57, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 174, + "incorrect value for sol_in[87].flags, expected 174, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 193, + "incorrect value for sol_in[87].sensor_type, expected 193, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 193, + "incorrect value for sol_in[88].flags, expected 193, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 146, + "incorrect value for sol_in[88].sensor_type, expected 146, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 44, + "incorrect value for sol_in[89].flags, expected 44, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 239, + "incorrect value for sol_in[89].sensor_type, expected 239, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 197, + "incorrect value for sol_in[90].flags, expected 197, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 246, + "incorrect value for sol_in[90].sensor_type, expected 246, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 80, + "incorrect value for sol_in[91].flags, expected 80, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 214, + "incorrect value for sol_in[91].sensor_type, expected 214, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 100, + "incorrect value for sol_in[92].flags, expected 100, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 83, + "incorrect value for sol_in[92].sensor_type, expected 83, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 72, + "incorrect value for sol_in[93].flags, expected 72, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 66, + "incorrect value for sol_in[93].sensor_type, expected 66, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 137, + "incorrect value for sol_in[94].flags, expected 137, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 133, + "incorrect value for sol_in[94].sensor_type, expected 133, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 82, + "incorrect value for sol_in[95].flags, expected 82, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 140, + "incorrect value for sol_in[95].sensor_type, expected 140, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 2, + "incorrect value for sol_in[96].flags, expected 2, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 2, + "incorrect value for sol_in[96].sensor_type, expected 2, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 9, + "incorrect value for sol_in[97].flags, expected 9, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 96, + "incorrect value for sol_in[97].sensor_type, expected 96, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 158, + "incorrect value for sol_in[98].flags, expected 158, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 96, + "incorrect value for sol_in[98].sensor_type, expected 96, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 97, + "incorrect value for sol_in[99].flags, expected 97, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 134, + "incorrect value for sol_in[99].sensor_type, expected 134, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 129, + "incorrect value for sol_in[100].flags, expected 129, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 43, + "incorrect value for sol_in[100].sensor_type, expected 43, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 25, + "incorrect value for sol_in[101].flags, expected 25, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 141, + "incorrect value for sol_in[101].sensor_type, expected 141, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 200, + "incorrect value for sol_in[102].flags, expected 200, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 183, + "incorrect value for sol_in[102].sensor_type, expected 183, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 57, + "incorrect value for sol_in[103].flags, expected 57, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 214, + "incorrect value for sol_in[103].sensor_type, expected 214, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 103, + "incorrect value for sol_in[104].flags, expected 103, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 248, + "incorrect value for sol_in[104].sensor_type, expected 248, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 65, + "incorrect value for sol_in[105].flags, expected 65, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 222, + "incorrect value for sol_in[105].sensor_type, expected 222, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 15, + "incorrect value for sol_in[106].flags, expected 15, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 195, + "incorrect value for sol_in[106].sensor_type, expected 195, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 21, + "incorrect value for sol_in[107].flags, expected 21, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 244, + "incorrect value for sol_in[107].sensor_type, expected 244, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 46, + "incorrect value for sol_in[108].flags, expected 46, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 180, + "incorrect value for sol_in[108].sensor_type, expected 180, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 130, + "incorrect value for sol_in[109].flags, expected 130, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 140, + "incorrect value for sol_in[109].sensor_type, expected 140, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 17, + "incorrect value for sol_in[110].flags, expected 17, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 36, + "incorrect value for sol_in[110].sensor_type, expected 36, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 209, + "incorrect value for sol_in[111].flags, expected 209, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 194, + "incorrect value for sol_in[111].sensor_type, expected 194, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 254, + "incorrect value for sol_in[112].flags, expected 254, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 65, + "incorrect value for sol_in[112].sensor_type, expected 65, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 103, + "incorrect value for sol_in[113].flags, expected 103, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 115, + "incorrect value for sol_in[113].sensor_type, expected 115, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 129, + "incorrect value for sol_in[114].flags, expected 129, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 152, + "incorrect value for sol_in[114].sensor_type, expected 152, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 235, + "incorrect value for sol_in[115].flags, expected 235, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 234, + "incorrect value for sol_in[115].sensor_type, expected 234, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 234, + "incorrect value for sol_in[116].flags, expected 234, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 194, + "incorrect value for sol_in[116].sensor_type, expected 194, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 201, + "incorrect value for sol_in[117].flags, expected 201, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 170, + "incorrect value for sol_in[117].sensor_type, expected 170, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.sol_in[118].flags, 154, + "incorrect value for sol_in[118].flags, expected 154, is {}", + msg.sol_in[118].flags + ); + assert_eq!( + msg.sol_in[118].sensor_type, 210, + "incorrect value for sol_in[118].sensor_type, expected 210, is {}", + msg.sol_in[118].sensor_type + ); + assert_eq!( + msg.tow, 3628191792, + "incorrect value for tow, expected 3628191792, is {}", + msg.tow + ); + assert_eq!( + msg.vdop, 58512, + "incorrect value for vdop, expected 58512, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMeta"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_solution_meta_msg_soln_meta() { + { + let json_input = r#"{"crc":63382,"length":254,"msg_type":65294,"payload":"MNBB2HotxKCQ5AhTWVcD1V9tVoNHRlRJgxpS94xhc252/QJ6upR6lLTnRC6+ZvMwwA/QWTgK9QL+yXggfgJToe57ZuZMvuG2z+QH2nVZHb84+Ln/LhJIjlJxGgSs/rKIcXM6wVnjtvZMTWz1KR9GfPmRD07kJvGBCLD7SPhQc/Tnkb++sqhZ6UWwroy2jVFSXE9l32RAuNd8JRXjh2ZIJNs4klrbaONmUwwpeq1eAa6GgmjtdPlr5oJ7GaI538GuksHvLPbF1lBTZEJIhYmMUgICYAlgnoZhK4GNGbfI1jn4Z95Bww/0FbQujIIkEcLRQf5zZ5iB6uvC6qrJ0po=","preamble":85,"sender":15360,"tow":3628191792,"pdop":11642,"hdop":41156,"vdop":58512,"age_corrections":21256,"age_gnss":3573765977,"sol_in":[{"sensor_type":95,"flags":109},{"sensor_type":86,"flags":131},{"sensor_type":71,"flags":70},{"sensor_type":84,"flags":73},{"sensor_type":131,"flags":26},{"sensor_type":82,"flags":247},{"sensor_type":140,"flags":97},{"sensor_type":115,"flags":110},{"sensor_type":118,"flags":253},{"sensor_type":2,"flags":122},{"sensor_type":186,"flags":148},{"sensor_type":122,"flags":148},{"sensor_type":180,"flags":231},{"sensor_type":68,"flags":46},{"sensor_type":190,"flags":102},{"sensor_type":243,"flags":48},{"sensor_type":192,"flags":15},{"sensor_type":208,"flags":89},{"sensor_type":56,"flags":10},{"sensor_type":245,"flags":2},{"sensor_type":254,"flags":201},{"sensor_type":120,"flags":32},{"sensor_type":126,"flags":2},{"sensor_type":83,"flags":161},{"sensor_type":238,"flags":123},{"sensor_type":102,"flags":230},{"sensor_type":76,"flags":190},{"sensor_type":225,"flags":182},{"sensor_type":207,"flags":228},{"sensor_type":7,"flags":218},{"sensor_type":117,"flags":89},{"sensor_type":29,"flags":191},{"sensor_type":56,"flags":248},{"sensor_type":185,"flags":255},{"sensor_type":46,"flags":18},{"sensor_type":72,"flags":142},{"sensor_type":82,"flags":113},{"sensor_type":26,"flags":4},{"sensor_type":172,"flags":254},{"sensor_type":178,"flags":136},{"sensor_type":113,"flags":115},{"sensor_type":58,"flags":193},{"sensor_type":89,"flags":227},{"sensor_type":182,"flags":246},{"sensor_type":76,"flags":77},{"sensor_type":108,"flags":245},{"sensor_type":41,"flags":31},{"sensor_type":70,"flags":124},{"sensor_type":249,"flags":145},{"sensor_type":15,"flags":78},{"sensor_type":228,"flags":38},{"sensor_type":241,"flags":129},{"sensor_type":8,"flags":176},{"sensor_type":251,"flags":72},{"sensor_type":248,"flags":80},{"sensor_type":115,"flags":244},{"sensor_type":231,"flags":145},{"sensor_type":191,"flags":190},{"sensor_type":178,"flags":168},{"sensor_type":89,"flags":233},{"sensor_type":69,"flags":176},{"sensor_type":174,"flags":140},{"sensor_type":182,"flags":141},{"sensor_type":81,"flags":82},{"sensor_type":92,"flags":79},{"sensor_type":101,"flags":223},{"sensor_type":100,"flags":64},{"sensor_type":184,"flags":215},{"sensor_type":124,"flags":37},{"sensor_type":21,"flags":227},{"sensor_type":135,"flags":102},{"sensor_type":72,"flags":36},{"sensor_type":219,"flags":56},{"sensor_type":146,"flags":90},{"sensor_type":219,"flags":104},{"sensor_type":227,"flags":102},{"sensor_type":83,"flags":12},{"sensor_type":41,"flags":122},{"sensor_type":173,"flags":94},{"sensor_type":1,"flags":174},{"sensor_type":134,"flags":130},{"sensor_type":104,"flags":237},{"sensor_type":116,"flags":249},{"sensor_type":107,"flags":230},{"sensor_type":130,"flags":123},{"sensor_type":25,"flags":162},{"sensor_type":57,"flags":223},{"sensor_type":193,"flags":174},{"sensor_type":146,"flags":193},{"sensor_type":239,"flags":44},{"sensor_type":246,"flags":197},{"sensor_type":214,"flags":80},{"sensor_type":83,"flags":100},{"sensor_type":66,"flags":72},{"sensor_type":133,"flags":137},{"sensor_type":140,"flags":82},{"sensor_type":2,"flags":2},{"sensor_type":96,"flags":9},{"sensor_type":96,"flags":158},{"sensor_type":134,"flags":97},{"sensor_type":43,"flags":129},{"sensor_type":141,"flags":25},{"sensor_type":183,"flags":200},{"sensor_type":214,"flags":57},{"sensor_type":248,"flags":103},{"sensor_type":222,"flags":65},{"sensor_type":195,"flags":15},{"sensor_type":244,"flags":21},{"sensor_type":180,"flags":46},{"sensor_type":140,"flags":130},{"sensor_type":36,"flags":17},{"sensor_type":194,"flags":209},{"sensor_type":65,"flags":254},{"sensor_type":115,"flags":103},{"sensor_type":152,"flags":129},{"sensor_type":234,"flags":235},{"sensor_type":194,"flags":234},{"sensor_type":170,"flags":201},{"sensor_type":210,"flags":154}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMeta(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0e, + "Incorrect message type, expected 0xff0e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3c00, + "incorrect sender id, expected 0x3c00, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 21256, + "incorrect value for age_corrections, expected 21256, is {}", + msg.age_corrections + ); + assert_eq!( + msg.age_gnss, 3573765977, + "incorrect value for age_gnss, expected 3573765977, is {}", + msg.age_gnss + ); + assert_eq!( + msg.hdop, 41156, + "incorrect value for hdop, expected 41156, is {}", + msg.hdop + ); + assert_eq!( + msg.pdop, 11642, + "incorrect value for pdop, expected 11642, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 109, + "incorrect value for sol_in[0].flags, expected 109, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 95, + "incorrect value for sol_in[0].sensor_type, expected 95, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 131, + "incorrect value for sol_in[1].flags, expected 131, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 86, + "incorrect value for sol_in[1].sensor_type, expected 86, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 70, + "incorrect value for sol_in[2].flags, expected 70, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 71, + "incorrect value for sol_in[2].sensor_type, expected 71, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 73, + "incorrect value for sol_in[3].flags, expected 73, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 84, + "incorrect value for sol_in[3].sensor_type, expected 84, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 26, + "incorrect value for sol_in[4].flags, expected 26, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 131, + "incorrect value for sol_in[4].sensor_type, expected 131, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 247, + "incorrect value for sol_in[5].flags, expected 247, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 82, + "incorrect value for sol_in[5].sensor_type, expected 82, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 97, + "incorrect value for sol_in[6].flags, expected 97, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 140, + "incorrect value for sol_in[6].sensor_type, expected 140, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 110, + "incorrect value for sol_in[7].flags, expected 110, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 115, + "incorrect value for sol_in[7].sensor_type, expected 115, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 253, + "incorrect value for sol_in[8].flags, expected 253, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 118, + "incorrect value for sol_in[8].sensor_type, expected 118, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 122, + "incorrect value for sol_in[9].flags, expected 122, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 2, + "incorrect value for sol_in[9].sensor_type, expected 2, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 148, + "incorrect value for sol_in[10].flags, expected 148, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 186, + "incorrect value for sol_in[10].sensor_type, expected 186, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 148, + "incorrect value for sol_in[11].flags, expected 148, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 122, + "incorrect value for sol_in[11].sensor_type, expected 122, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 231, + "incorrect value for sol_in[12].flags, expected 231, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 180, + "incorrect value for sol_in[12].sensor_type, expected 180, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 46, + "incorrect value for sol_in[13].flags, expected 46, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 68, + "incorrect value for sol_in[13].sensor_type, expected 68, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 102, + "incorrect value for sol_in[14].flags, expected 102, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 190, + "incorrect value for sol_in[14].sensor_type, expected 190, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 48, + "incorrect value for sol_in[15].flags, expected 48, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 243, + "incorrect value for sol_in[15].sensor_type, expected 243, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 15, + "incorrect value for sol_in[16].flags, expected 15, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 192, + "incorrect value for sol_in[16].sensor_type, expected 192, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 89, + "incorrect value for sol_in[17].flags, expected 89, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 208, + "incorrect value for sol_in[17].sensor_type, expected 208, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 10, + "incorrect value for sol_in[18].flags, expected 10, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 56, + "incorrect value for sol_in[18].sensor_type, expected 56, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 2, + "incorrect value for sol_in[19].flags, expected 2, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 245, + "incorrect value for sol_in[19].sensor_type, expected 245, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 201, + "incorrect value for sol_in[20].flags, expected 201, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 254, + "incorrect value for sol_in[20].sensor_type, expected 254, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 32, + "incorrect value for sol_in[21].flags, expected 32, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 120, + "incorrect value for sol_in[21].sensor_type, expected 120, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 2, + "incorrect value for sol_in[22].flags, expected 2, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 126, + "incorrect value for sol_in[22].sensor_type, expected 126, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 161, + "incorrect value for sol_in[23].flags, expected 161, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 83, + "incorrect value for sol_in[23].sensor_type, expected 83, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 123, + "incorrect value for sol_in[24].flags, expected 123, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 238, + "incorrect value for sol_in[24].sensor_type, expected 238, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 230, + "incorrect value for sol_in[25].flags, expected 230, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 102, + "incorrect value for sol_in[25].sensor_type, expected 102, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 190, + "incorrect value for sol_in[26].flags, expected 190, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 76, + "incorrect value for sol_in[26].sensor_type, expected 76, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 182, + "incorrect value for sol_in[27].flags, expected 182, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 225, + "incorrect value for sol_in[27].sensor_type, expected 225, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 228, + "incorrect value for sol_in[28].flags, expected 228, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 207, + "incorrect value for sol_in[28].sensor_type, expected 207, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 218, + "incorrect value for sol_in[29].flags, expected 218, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 7, + "incorrect value for sol_in[29].sensor_type, expected 7, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 89, + "incorrect value for sol_in[30].flags, expected 89, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 117, + "incorrect value for sol_in[30].sensor_type, expected 117, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 191, + "incorrect value for sol_in[31].flags, expected 191, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 29, + "incorrect value for sol_in[31].sensor_type, expected 29, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 248, + "incorrect value for sol_in[32].flags, expected 248, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 56, + "incorrect value for sol_in[32].sensor_type, expected 56, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 255, + "incorrect value for sol_in[33].flags, expected 255, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 185, + "incorrect value for sol_in[33].sensor_type, expected 185, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 18, + "incorrect value for sol_in[34].flags, expected 18, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 46, + "incorrect value for sol_in[34].sensor_type, expected 46, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 142, + "incorrect value for sol_in[35].flags, expected 142, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 72, + "incorrect value for sol_in[35].sensor_type, expected 72, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 113, + "incorrect value for sol_in[36].flags, expected 113, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 82, + "incorrect value for sol_in[36].sensor_type, expected 82, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 4, + "incorrect value for sol_in[37].flags, expected 4, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 26, + "incorrect value for sol_in[37].sensor_type, expected 26, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 254, + "incorrect value for sol_in[38].flags, expected 254, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 172, + "incorrect value for sol_in[38].sensor_type, expected 172, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 136, + "incorrect value for sol_in[39].flags, expected 136, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 178, + "incorrect value for sol_in[39].sensor_type, expected 178, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 115, + "incorrect value for sol_in[40].flags, expected 115, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 113, + "incorrect value for sol_in[40].sensor_type, expected 113, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 193, + "incorrect value for sol_in[41].flags, expected 193, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 58, + "incorrect value for sol_in[41].sensor_type, expected 58, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 227, + "incorrect value for sol_in[42].flags, expected 227, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 89, + "incorrect value for sol_in[42].sensor_type, expected 89, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 246, + "incorrect value for sol_in[43].flags, expected 246, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 182, + "incorrect value for sol_in[43].sensor_type, expected 182, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 77, + "incorrect value for sol_in[44].flags, expected 77, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 76, + "incorrect value for sol_in[44].sensor_type, expected 76, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 245, + "incorrect value for sol_in[45].flags, expected 245, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 108, + "incorrect value for sol_in[45].sensor_type, expected 108, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 31, + "incorrect value for sol_in[46].flags, expected 31, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 41, + "incorrect value for sol_in[46].sensor_type, expected 41, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 124, + "incorrect value for sol_in[47].flags, expected 124, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 70, + "incorrect value for sol_in[47].sensor_type, expected 70, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 145, + "incorrect value for sol_in[48].flags, expected 145, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 249, + "incorrect value for sol_in[48].sensor_type, expected 249, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 78, + "incorrect value for sol_in[49].flags, expected 78, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 15, + "incorrect value for sol_in[49].sensor_type, expected 15, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 38, + "incorrect value for sol_in[50].flags, expected 38, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 228, + "incorrect value for sol_in[50].sensor_type, expected 228, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 129, + "incorrect value for sol_in[51].flags, expected 129, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 241, + "incorrect value for sol_in[51].sensor_type, expected 241, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 176, + "incorrect value for sol_in[52].flags, expected 176, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 8, + "incorrect value for sol_in[52].sensor_type, expected 8, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 72, + "incorrect value for sol_in[53].flags, expected 72, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 251, + "incorrect value for sol_in[53].sensor_type, expected 251, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 80, + "incorrect value for sol_in[54].flags, expected 80, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 248, + "incorrect value for sol_in[54].sensor_type, expected 248, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 244, + "incorrect value for sol_in[55].flags, expected 244, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 115, + "incorrect value for sol_in[55].sensor_type, expected 115, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 145, + "incorrect value for sol_in[56].flags, expected 145, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 231, + "incorrect value for sol_in[56].sensor_type, expected 231, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 190, + "incorrect value for sol_in[57].flags, expected 190, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 191, + "incorrect value for sol_in[57].sensor_type, expected 191, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 168, + "incorrect value for sol_in[58].flags, expected 168, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 178, + "incorrect value for sol_in[58].sensor_type, expected 178, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 233, + "incorrect value for sol_in[59].flags, expected 233, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 89, + "incorrect value for sol_in[59].sensor_type, expected 89, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 176, + "incorrect value for sol_in[60].flags, expected 176, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 69, + "incorrect value for sol_in[60].sensor_type, expected 69, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 140, + "incorrect value for sol_in[61].flags, expected 140, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 174, + "incorrect value for sol_in[61].sensor_type, expected 174, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 141, + "incorrect value for sol_in[62].flags, expected 141, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 182, + "incorrect value for sol_in[62].sensor_type, expected 182, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 82, + "incorrect value for sol_in[63].flags, expected 82, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 81, + "incorrect value for sol_in[63].sensor_type, expected 81, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 79, + "incorrect value for sol_in[64].flags, expected 79, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 92, + "incorrect value for sol_in[64].sensor_type, expected 92, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 223, + "incorrect value for sol_in[65].flags, expected 223, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 101, + "incorrect value for sol_in[65].sensor_type, expected 101, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 64, + "incorrect value for sol_in[66].flags, expected 64, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 100, + "incorrect value for sol_in[66].sensor_type, expected 100, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 215, + "incorrect value for sol_in[67].flags, expected 215, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 184, + "incorrect value for sol_in[67].sensor_type, expected 184, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 37, + "incorrect value for sol_in[68].flags, expected 37, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 124, + "incorrect value for sol_in[68].sensor_type, expected 124, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 227, + "incorrect value for sol_in[69].flags, expected 227, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 21, + "incorrect value for sol_in[69].sensor_type, expected 21, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 102, + "incorrect value for sol_in[70].flags, expected 102, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 135, + "incorrect value for sol_in[70].sensor_type, expected 135, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 36, + "incorrect value for sol_in[71].flags, expected 36, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 72, + "incorrect value for sol_in[71].sensor_type, expected 72, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 56, + "incorrect value for sol_in[72].flags, expected 56, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 219, + "incorrect value for sol_in[72].sensor_type, expected 219, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 90, + "incorrect value for sol_in[73].flags, expected 90, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 146, + "incorrect value for sol_in[73].sensor_type, expected 146, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 104, + "incorrect value for sol_in[74].flags, expected 104, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 219, + "incorrect value for sol_in[74].sensor_type, expected 219, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 102, + "incorrect value for sol_in[75].flags, expected 102, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 227, + "incorrect value for sol_in[75].sensor_type, expected 227, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 12, + "incorrect value for sol_in[76].flags, expected 12, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 83, + "incorrect value for sol_in[76].sensor_type, expected 83, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 122, + "incorrect value for sol_in[77].flags, expected 122, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 41, + "incorrect value for sol_in[77].sensor_type, expected 41, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 94, + "incorrect value for sol_in[78].flags, expected 94, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 173, + "incorrect value for sol_in[78].sensor_type, expected 173, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 174, + "incorrect value for sol_in[79].flags, expected 174, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 1, + "incorrect value for sol_in[79].sensor_type, expected 1, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 130, + "incorrect value for sol_in[80].flags, expected 130, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 134, + "incorrect value for sol_in[80].sensor_type, expected 134, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 237, + "incorrect value for sol_in[81].flags, expected 237, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 104, + "incorrect value for sol_in[81].sensor_type, expected 104, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 249, + "incorrect value for sol_in[82].flags, expected 249, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 116, + "incorrect value for sol_in[82].sensor_type, expected 116, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 230, + "incorrect value for sol_in[83].flags, expected 230, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 107, + "incorrect value for sol_in[83].sensor_type, expected 107, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 123, + "incorrect value for sol_in[84].flags, expected 123, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 130, + "incorrect value for sol_in[84].sensor_type, expected 130, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 162, + "incorrect value for sol_in[85].flags, expected 162, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 25, + "incorrect value for sol_in[85].sensor_type, expected 25, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 223, + "incorrect value for sol_in[86].flags, expected 223, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 57, + "incorrect value for sol_in[86].sensor_type, expected 57, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 174, + "incorrect value for sol_in[87].flags, expected 174, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 193, + "incorrect value for sol_in[87].sensor_type, expected 193, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 193, + "incorrect value for sol_in[88].flags, expected 193, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 146, + "incorrect value for sol_in[88].sensor_type, expected 146, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 44, + "incorrect value for sol_in[89].flags, expected 44, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 239, + "incorrect value for sol_in[89].sensor_type, expected 239, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 197, + "incorrect value for sol_in[90].flags, expected 197, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 246, + "incorrect value for sol_in[90].sensor_type, expected 246, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 80, + "incorrect value for sol_in[91].flags, expected 80, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 214, + "incorrect value for sol_in[91].sensor_type, expected 214, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 100, + "incorrect value for sol_in[92].flags, expected 100, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 83, + "incorrect value for sol_in[92].sensor_type, expected 83, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 72, + "incorrect value for sol_in[93].flags, expected 72, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 66, + "incorrect value for sol_in[93].sensor_type, expected 66, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 137, + "incorrect value for sol_in[94].flags, expected 137, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 133, + "incorrect value for sol_in[94].sensor_type, expected 133, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 82, + "incorrect value for sol_in[95].flags, expected 82, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 140, + "incorrect value for sol_in[95].sensor_type, expected 140, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 2, + "incorrect value for sol_in[96].flags, expected 2, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 2, + "incorrect value for sol_in[96].sensor_type, expected 2, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 9, + "incorrect value for sol_in[97].flags, expected 9, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 96, + "incorrect value for sol_in[97].sensor_type, expected 96, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 158, + "incorrect value for sol_in[98].flags, expected 158, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 96, + "incorrect value for sol_in[98].sensor_type, expected 96, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 97, + "incorrect value for sol_in[99].flags, expected 97, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 134, + "incorrect value for sol_in[99].sensor_type, expected 134, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 129, + "incorrect value for sol_in[100].flags, expected 129, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 43, + "incorrect value for sol_in[100].sensor_type, expected 43, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 25, + "incorrect value for sol_in[101].flags, expected 25, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 141, + "incorrect value for sol_in[101].sensor_type, expected 141, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 200, + "incorrect value for sol_in[102].flags, expected 200, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 183, + "incorrect value for sol_in[102].sensor_type, expected 183, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 57, + "incorrect value for sol_in[103].flags, expected 57, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 214, + "incorrect value for sol_in[103].sensor_type, expected 214, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 103, + "incorrect value for sol_in[104].flags, expected 103, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 248, + "incorrect value for sol_in[104].sensor_type, expected 248, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 65, + "incorrect value for sol_in[105].flags, expected 65, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 222, + "incorrect value for sol_in[105].sensor_type, expected 222, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 15, + "incorrect value for sol_in[106].flags, expected 15, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 195, + "incorrect value for sol_in[106].sensor_type, expected 195, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 21, + "incorrect value for sol_in[107].flags, expected 21, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 244, + "incorrect value for sol_in[107].sensor_type, expected 244, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 46, + "incorrect value for sol_in[108].flags, expected 46, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 180, + "incorrect value for sol_in[108].sensor_type, expected 180, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 130, + "incorrect value for sol_in[109].flags, expected 130, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 140, + "incorrect value for sol_in[109].sensor_type, expected 140, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 17, + "incorrect value for sol_in[110].flags, expected 17, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 36, + "incorrect value for sol_in[110].sensor_type, expected 36, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 209, + "incorrect value for sol_in[111].flags, expected 209, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 194, + "incorrect value for sol_in[111].sensor_type, expected 194, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 254, + "incorrect value for sol_in[112].flags, expected 254, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 65, + "incorrect value for sol_in[112].sensor_type, expected 65, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 103, + "incorrect value for sol_in[113].flags, expected 103, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 115, + "incorrect value for sol_in[113].sensor_type, expected 115, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 129, + "incorrect value for sol_in[114].flags, expected 129, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 152, + "incorrect value for sol_in[114].sensor_type, expected 152, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 235, + "incorrect value for sol_in[115].flags, expected 235, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 234, + "incorrect value for sol_in[115].sensor_type, expected 234, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 234, + "incorrect value for sol_in[116].flags, expected 234, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 194, + "incorrect value for sol_in[116].sensor_type, expected 194, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 201, + "incorrect value for sol_in[117].flags, expected 201, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 170, + "incorrect value for sol_in[117].sensor_type, expected 170, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.sol_in[118].flags, 154, + "incorrect value for sol_in[118].flags, expected 154, is {}", + msg.sol_in[118].flags + ); + assert_eq!( + msg.sol_in[118].sensor_type, 210, + "incorrect value for sol_in[118].sensor_type, expected 210, is {}", + msg.sol_in[118].sensor_type + ); + assert_eq!( + msg.tow, 3628191792, + "incorrect value for tow, expected 3628191792, is {}", + msg.tow + ); + assert_eq!( + msg.vdop, 58512, + "incorrect value for vdop, expected 58512, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMeta"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_solution_meta_msg_soln_meta`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_solution_meta_msg_soln_meta() { + { + let mut payload = Cursor::new(vec![ + 85, 14, 255, 0, 60, 254, 48, 208, 65, 216, 122, 45, 196, 160, 144, 228, 8, 83, 89, 87, + 3, 213, 95, 109, 86, 131, 71, 70, 84, 73, 131, 26, 82, 247, 140, 97, 115, 110, 118, + 253, 2, 122, 186, 148, 122, 148, 180, 231, 68, 46, 190, 102, 243, 48, 192, 15, 208, 89, + 56, 10, 245, 2, 254, 201, 120, 32, 126, 2, 83, 161, 238, 123, 102, 230, 76, 190, 225, + 182, 207, 228, 7, 218, 117, 89, 29, 191, 56, 248, 185, 255, 46, 18, 72, 142, 82, 113, + 26, 4, 172, 254, 178, 136, 113, 115, 58, 193, 89, 227, 182, 246, 76, 77, 108, 245, 41, + 31, 70, 124, 249, 145, 15, 78, 228, 38, 241, 129, 8, 176, 251, 72, 248, 80, 115, 244, + 231, 145, 191, 190, 178, 168, 89, 233, 69, 176, 174, 140, 182, 141, 81, 82, 92, 79, + 101, 223, 100, 64, 184, 215, 124, 37, 21, 227, 135, 102, 72, 36, 219, 56, 146, 90, 219, + 104, 227, 102, 83, 12, 41, 122, 173, 94, 1, 174, 134, 130, 104, 237, 116, 249, 107, + 230, 130, 123, 25, 162, 57, 223, 193, 174, 146, 193, 239, 44, 246, 197, 214, 80, 83, + 100, 66, 72, 133, 137, 140, 82, 2, 2, 96, 9, 96, 158, 134, 97, 43, 129, 141, 25, 183, + 200, 214, 57, 248, 103, 222, 65, 195, 15, 244, 21, 180, 46, 140, 130, 36, 17, 194, 209, + 65, 254, 115, 103, 152, 129, 234, 235, 194, 234, 170, 201, 210, 154, 150, 247, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSolnMeta( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMeta(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0e, + "Incorrect message type, expected 0xff0e, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x3c00, + "incorrect sender id, expected 0x3c00, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 21256, + "incorrect value for age_corrections, expected 21256, is {}", + msg.age_corrections + ); + assert_eq!( + msg.age_gnss, 3573765977, + "incorrect value for age_gnss, expected 3573765977, is {}", + msg.age_gnss + ); + assert_eq!( + msg.hdop, 41156, + "incorrect value for hdop, expected 41156, is {}", + msg.hdop + ); + assert_eq!( + msg.pdop, 11642, + "incorrect value for pdop, expected 11642, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 109, + "incorrect value for sol_in[0].flags, expected 109, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 95, + "incorrect value for sol_in[0].sensor_type, expected 95, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 131, + "incorrect value for sol_in[1].flags, expected 131, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 86, + "incorrect value for sol_in[1].sensor_type, expected 86, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 70, + "incorrect value for sol_in[2].flags, expected 70, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 71, + "incorrect value for sol_in[2].sensor_type, expected 71, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 73, + "incorrect value for sol_in[3].flags, expected 73, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 84, + "incorrect value for sol_in[3].sensor_type, expected 84, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 26, + "incorrect value for sol_in[4].flags, expected 26, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 131, + "incorrect value for sol_in[4].sensor_type, expected 131, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 247, + "incorrect value for sol_in[5].flags, expected 247, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 82, + "incorrect value for sol_in[5].sensor_type, expected 82, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 97, + "incorrect value for sol_in[6].flags, expected 97, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 140, + "incorrect value for sol_in[6].sensor_type, expected 140, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 110, + "incorrect value for sol_in[7].flags, expected 110, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 115, + "incorrect value for sol_in[7].sensor_type, expected 115, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 253, + "incorrect value for sol_in[8].flags, expected 253, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 118, + "incorrect value for sol_in[8].sensor_type, expected 118, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 122, + "incorrect value for sol_in[9].flags, expected 122, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 2, + "incorrect value for sol_in[9].sensor_type, expected 2, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 148, + "incorrect value for sol_in[10].flags, expected 148, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 186, + "incorrect value for sol_in[10].sensor_type, expected 186, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 148, + "incorrect value for sol_in[11].flags, expected 148, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 122, + "incorrect value for sol_in[11].sensor_type, expected 122, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 231, + "incorrect value for sol_in[12].flags, expected 231, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 180, + "incorrect value for sol_in[12].sensor_type, expected 180, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 46, + "incorrect value for sol_in[13].flags, expected 46, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 68, + "incorrect value for sol_in[13].sensor_type, expected 68, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 102, + "incorrect value for sol_in[14].flags, expected 102, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 190, + "incorrect value for sol_in[14].sensor_type, expected 190, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 48, + "incorrect value for sol_in[15].flags, expected 48, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 243, + "incorrect value for sol_in[15].sensor_type, expected 243, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 15, + "incorrect value for sol_in[16].flags, expected 15, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 192, + "incorrect value for sol_in[16].sensor_type, expected 192, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 89, + "incorrect value for sol_in[17].flags, expected 89, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 208, + "incorrect value for sol_in[17].sensor_type, expected 208, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 10, + "incorrect value for sol_in[18].flags, expected 10, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 56, + "incorrect value for sol_in[18].sensor_type, expected 56, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 2, + "incorrect value for sol_in[19].flags, expected 2, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 245, + "incorrect value for sol_in[19].sensor_type, expected 245, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 201, + "incorrect value for sol_in[20].flags, expected 201, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 254, + "incorrect value for sol_in[20].sensor_type, expected 254, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 32, + "incorrect value for sol_in[21].flags, expected 32, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 120, + "incorrect value for sol_in[21].sensor_type, expected 120, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 2, + "incorrect value for sol_in[22].flags, expected 2, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 126, + "incorrect value for sol_in[22].sensor_type, expected 126, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 161, + "incorrect value for sol_in[23].flags, expected 161, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 83, + "incorrect value for sol_in[23].sensor_type, expected 83, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 123, + "incorrect value for sol_in[24].flags, expected 123, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 238, + "incorrect value for sol_in[24].sensor_type, expected 238, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 230, + "incorrect value for sol_in[25].flags, expected 230, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 102, + "incorrect value for sol_in[25].sensor_type, expected 102, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 190, + "incorrect value for sol_in[26].flags, expected 190, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 76, + "incorrect value for sol_in[26].sensor_type, expected 76, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 182, + "incorrect value for sol_in[27].flags, expected 182, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 225, + "incorrect value for sol_in[27].sensor_type, expected 225, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 228, + "incorrect value for sol_in[28].flags, expected 228, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 207, + "incorrect value for sol_in[28].sensor_type, expected 207, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 218, + "incorrect value for sol_in[29].flags, expected 218, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 7, + "incorrect value for sol_in[29].sensor_type, expected 7, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 89, + "incorrect value for sol_in[30].flags, expected 89, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 117, + "incorrect value for sol_in[30].sensor_type, expected 117, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 191, + "incorrect value for sol_in[31].flags, expected 191, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 29, + "incorrect value for sol_in[31].sensor_type, expected 29, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 248, + "incorrect value for sol_in[32].flags, expected 248, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 56, + "incorrect value for sol_in[32].sensor_type, expected 56, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 255, + "incorrect value for sol_in[33].flags, expected 255, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 185, + "incorrect value for sol_in[33].sensor_type, expected 185, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 18, + "incorrect value for sol_in[34].flags, expected 18, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 46, + "incorrect value for sol_in[34].sensor_type, expected 46, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 142, + "incorrect value for sol_in[35].flags, expected 142, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 72, + "incorrect value for sol_in[35].sensor_type, expected 72, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 113, + "incorrect value for sol_in[36].flags, expected 113, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 82, + "incorrect value for sol_in[36].sensor_type, expected 82, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 4, + "incorrect value for sol_in[37].flags, expected 4, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 26, + "incorrect value for sol_in[37].sensor_type, expected 26, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 254, + "incorrect value for sol_in[38].flags, expected 254, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 172, + "incorrect value for sol_in[38].sensor_type, expected 172, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 136, + "incorrect value for sol_in[39].flags, expected 136, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 178, + "incorrect value for sol_in[39].sensor_type, expected 178, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 115, + "incorrect value for sol_in[40].flags, expected 115, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 113, + "incorrect value for sol_in[40].sensor_type, expected 113, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 193, + "incorrect value for sol_in[41].flags, expected 193, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 58, + "incorrect value for sol_in[41].sensor_type, expected 58, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 227, + "incorrect value for sol_in[42].flags, expected 227, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 89, + "incorrect value for sol_in[42].sensor_type, expected 89, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 246, + "incorrect value for sol_in[43].flags, expected 246, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 182, + "incorrect value for sol_in[43].sensor_type, expected 182, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 77, + "incorrect value for sol_in[44].flags, expected 77, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 76, + "incorrect value for sol_in[44].sensor_type, expected 76, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 245, + "incorrect value for sol_in[45].flags, expected 245, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 108, + "incorrect value for sol_in[45].sensor_type, expected 108, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 31, + "incorrect value for sol_in[46].flags, expected 31, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 41, + "incorrect value for sol_in[46].sensor_type, expected 41, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 124, + "incorrect value for sol_in[47].flags, expected 124, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 70, + "incorrect value for sol_in[47].sensor_type, expected 70, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 145, + "incorrect value for sol_in[48].flags, expected 145, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 249, + "incorrect value for sol_in[48].sensor_type, expected 249, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 78, + "incorrect value for sol_in[49].flags, expected 78, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 15, + "incorrect value for sol_in[49].sensor_type, expected 15, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 38, + "incorrect value for sol_in[50].flags, expected 38, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 228, + "incorrect value for sol_in[50].sensor_type, expected 228, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 129, + "incorrect value for sol_in[51].flags, expected 129, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 241, + "incorrect value for sol_in[51].sensor_type, expected 241, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 176, + "incorrect value for sol_in[52].flags, expected 176, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 8, + "incorrect value for sol_in[52].sensor_type, expected 8, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 72, + "incorrect value for sol_in[53].flags, expected 72, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 251, + "incorrect value for sol_in[53].sensor_type, expected 251, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 80, + "incorrect value for sol_in[54].flags, expected 80, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 248, + "incorrect value for sol_in[54].sensor_type, expected 248, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 244, + "incorrect value for sol_in[55].flags, expected 244, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 115, + "incorrect value for sol_in[55].sensor_type, expected 115, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 145, + "incorrect value for sol_in[56].flags, expected 145, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 231, + "incorrect value for sol_in[56].sensor_type, expected 231, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 190, + "incorrect value for sol_in[57].flags, expected 190, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 191, + "incorrect value for sol_in[57].sensor_type, expected 191, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 168, + "incorrect value for sol_in[58].flags, expected 168, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 178, + "incorrect value for sol_in[58].sensor_type, expected 178, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 233, + "incorrect value for sol_in[59].flags, expected 233, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 89, + "incorrect value for sol_in[59].sensor_type, expected 89, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 176, + "incorrect value for sol_in[60].flags, expected 176, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 69, + "incorrect value for sol_in[60].sensor_type, expected 69, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 140, + "incorrect value for sol_in[61].flags, expected 140, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 174, + "incorrect value for sol_in[61].sensor_type, expected 174, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 141, + "incorrect value for sol_in[62].flags, expected 141, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 182, + "incorrect value for sol_in[62].sensor_type, expected 182, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 82, + "incorrect value for sol_in[63].flags, expected 82, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 81, + "incorrect value for sol_in[63].sensor_type, expected 81, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 79, + "incorrect value for sol_in[64].flags, expected 79, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 92, + "incorrect value for sol_in[64].sensor_type, expected 92, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 223, + "incorrect value for sol_in[65].flags, expected 223, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 101, + "incorrect value for sol_in[65].sensor_type, expected 101, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 64, + "incorrect value for sol_in[66].flags, expected 64, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 100, + "incorrect value for sol_in[66].sensor_type, expected 100, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 215, + "incorrect value for sol_in[67].flags, expected 215, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 184, + "incorrect value for sol_in[67].sensor_type, expected 184, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 37, + "incorrect value for sol_in[68].flags, expected 37, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 124, + "incorrect value for sol_in[68].sensor_type, expected 124, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 227, + "incorrect value for sol_in[69].flags, expected 227, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 21, + "incorrect value for sol_in[69].sensor_type, expected 21, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 102, + "incorrect value for sol_in[70].flags, expected 102, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 135, + "incorrect value for sol_in[70].sensor_type, expected 135, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 36, + "incorrect value for sol_in[71].flags, expected 36, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 72, + "incorrect value for sol_in[71].sensor_type, expected 72, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 56, + "incorrect value for sol_in[72].flags, expected 56, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 219, + "incorrect value for sol_in[72].sensor_type, expected 219, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 90, + "incorrect value for sol_in[73].flags, expected 90, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 146, + "incorrect value for sol_in[73].sensor_type, expected 146, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 104, + "incorrect value for sol_in[74].flags, expected 104, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 219, + "incorrect value for sol_in[74].sensor_type, expected 219, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 102, + "incorrect value for sol_in[75].flags, expected 102, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 227, + "incorrect value for sol_in[75].sensor_type, expected 227, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 12, + "incorrect value for sol_in[76].flags, expected 12, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 83, + "incorrect value for sol_in[76].sensor_type, expected 83, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 122, + "incorrect value for sol_in[77].flags, expected 122, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 41, + "incorrect value for sol_in[77].sensor_type, expected 41, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 94, + "incorrect value for sol_in[78].flags, expected 94, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 173, + "incorrect value for sol_in[78].sensor_type, expected 173, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 174, + "incorrect value for sol_in[79].flags, expected 174, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 1, + "incorrect value for sol_in[79].sensor_type, expected 1, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 130, + "incorrect value for sol_in[80].flags, expected 130, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 134, + "incorrect value for sol_in[80].sensor_type, expected 134, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 237, + "incorrect value for sol_in[81].flags, expected 237, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 104, + "incorrect value for sol_in[81].sensor_type, expected 104, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 249, + "incorrect value for sol_in[82].flags, expected 249, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 116, + "incorrect value for sol_in[82].sensor_type, expected 116, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 230, + "incorrect value for sol_in[83].flags, expected 230, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 107, + "incorrect value for sol_in[83].sensor_type, expected 107, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 123, + "incorrect value for sol_in[84].flags, expected 123, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 130, + "incorrect value for sol_in[84].sensor_type, expected 130, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 162, + "incorrect value for sol_in[85].flags, expected 162, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 25, + "incorrect value for sol_in[85].sensor_type, expected 25, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 223, + "incorrect value for sol_in[86].flags, expected 223, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 57, + "incorrect value for sol_in[86].sensor_type, expected 57, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 174, + "incorrect value for sol_in[87].flags, expected 174, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 193, + "incorrect value for sol_in[87].sensor_type, expected 193, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 193, + "incorrect value for sol_in[88].flags, expected 193, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 146, + "incorrect value for sol_in[88].sensor_type, expected 146, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 44, + "incorrect value for sol_in[89].flags, expected 44, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 239, + "incorrect value for sol_in[89].sensor_type, expected 239, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 197, + "incorrect value for sol_in[90].flags, expected 197, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 246, + "incorrect value for sol_in[90].sensor_type, expected 246, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 80, + "incorrect value for sol_in[91].flags, expected 80, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 214, + "incorrect value for sol_in[91].sensor_type, expected 214, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 100, + "incorrect value for sol_in[92].flags, expected 100, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 83, + "incorrect value for sol_in[92].sensor_type, expected 83, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 72, + "incorrect value for sol_in[93].flags, expected 72, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 66, + "incorrect value for sol_in[93].sensor_type, expected 66, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 137, + "incorrect value for sol_in[94].flags, expected 137, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 133, + "incorrect value for sol_in[94].sensor_type, expected 133, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 82, + "incorrect value for sol_in[95].flags, expected 82, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 140, + "incorrect value for sol_in[95].sensor_type, expected 140, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 2, + "incorrect value for sol_in[96].flags, expected 2, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 2, + "incorrect value for sol_in[96].sensor_type, expected 2, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 9, + "incorrect value for sol_in[97].flags, expected 9, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 96, + "incorrect value for sol_in[97].sensor_type, expected 96, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 158, + "incorrect value for sol_in[98].flags, expected 158, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 96, + "incorrect value for sol_in[98].sensor_type, expected 96, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 97, + "incorrect value for sol_in[99].flags, expected 97, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 134, + "incorrect value for sol_in[99].sensor_type, expected 134, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 129, + "incorrect value for sol_in[100].flags, expected 129, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 43, + "incorrect value for sol_in[100].sensor_type, expected 43, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 25, + "incorrect value for sol_in[101].flags, expected 25, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 141, + "incorrect value for sol_in[101].sensor_type, expected 141, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 200, + "incorrect value for sol_in[102].flags, expected 200, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 183, + "incorrect value for sol_in[102].sensor_type, expected 183, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 57, + "incorrect value for sol_in[103].flags, expected 57, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 214, + "incorrect value for sol_in[103].sensor_type, expected 214, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 103, + "incorrect value for sol_in[104].flags, expected 103, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 248, + "incorrect value for sol_in[104].sensor_type, expected 248, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 65, + "incorrect value for sol_in[105].flags, expected 65, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 222, + "incorrect value for sol_in[105].sensor_type, expected 222, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 15, + "incorrect value for sol_in[106].flags, expected 15, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 195, + "incorrect value for sol_in[106].sensor_type, expected 195, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 21, + "incorrect value for sol_in[107].flags, expected 21, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 244, + "incorrect value for sol_in[107].sensor_type, expected 244, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 46, + "incorrect value for sol_in[108].flags, expected 46, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 180, + "incorrect value for sol_in[108].sensor_type, expected 180, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 130, + "incorrect value for sol_in[109].flags, expected 130, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 140, + "incorrect value for sol_in[109].sensor_type, expected 140, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 17, + "incorrect value for sol_in[110].flags, expected 17, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 36, + "incorrect value for sol_in[110].sensor_type, expected 36, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 209, + "incorrect value for sol_in[111].flags, expected 209, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 194, + "incorrect value for sol_in[111].sensor_type, expected 194, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 254, + "incorrect value for sol_in[112].flags, expected 254, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 65, + "incorrect value for sol_in[112].sensor_type, expected 65, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 103, + "incorrect value for sol_in[113].flags, expected 103, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 115, + "incorrect value for sol_in[113].sensor_type, expected 115, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 129, + "incorrect value for sol_in[114].flags, expected 129, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 152, + "incorrect value for sol_in[114].sensor_type, expected 152, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 235, + "incorrect value for sol_in[115].flags, expected 235, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 234, + "incorrect value for sol_in[115].sensor_type, expected 234, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 234, + "incorrect value for sol_in[116].flags, expected 234, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 194, + "incorrect value for sol_in[116].sensor_type, expected 194, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 201, + "incorrect value for sol_in[117].flags, expected 201, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 170, + "incorrect value for sol_in[117].sensor_type, expected 170, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.sol_in[118].flags, 154, + "incorrect value for sol_in[118].flags, expected 154, is {}", + msg.sol_in[118].flags + ); + assert_eq!( + msg.sol_in[118].sensor_type, 210, + "incorrect value for sol_in[118].sensor_type, expected 210, is {}", + msg.sol_in[118].sensor_type + ); + assert_eq!( + msg.tow, 3628191792, + "incorrect value for tow, expected 3628191792, is {}", + msg.tow + ); + assert_eq!( + msg.vdop, 58512, + "incorrect value for vdop, expected 58512, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMeta"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta_dep_a.rs new file mode 100644 index 0000000000..9608d26c91 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_solution_meta_msg_soln_meta_dep_a.rs @@ -0,0 +1,3853 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_solution_meta_msg_soln_meta_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, 190, 115, 93, 59, 103, + 36, 83, 161, 156, 46, 253, 67, 87, 200, 39, 250, 245, 242, 228, 72, 18, 222, 11, 88, + 207, 218, 231, 13, 226, 224, 22, 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, 146, + 40, 204, 51, 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, 240, 190, 93, 219, 103, 42, + 41, 182, 76, 222, 17, 23, 125, 31, 18, 229, 28, 47, 214, 25, 100, 84, 106, 72, 48, 10, + 222, 232, 235, 73, 109, 163, 51, 152, 133, 235, 87, 70, 2, 108, 91, 101, 200, 55, 24, + 156, 233, 73, 39, 66, 97, 140, 252, 227, 230, 237, 135, 241, 245, 205, 70, 0, 219, 188, + 107, 136, 178, 58, 1, 29, 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, 203, 18, 3, + 222, 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, 159, 174, 121, 112, 167, 240, + 40, 59, 3, 230, 52, 149, 148, 218, 142, 212, 109, 176, 71, 179, 172, 77, 1, 193, 70, + 147, 149, 23, 144, 148, 239, 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, + 222, 222, 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, 106, 236, 93, + 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, 221, 185, 202, 21, 252, 51, 130, + 59, 166, 202, 127, 170, 58, 193, 215, 125, 22, 58, 135, 47, 88, 142, 77, 211, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMetaDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0f, + "Incorrect message type, expected 0xff0f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf154, + "incorrect sender id, expected 0xf154, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 48671, + "incorrect value for age_corrections, expected 48671, is {}", + msg.age_corrections + ); + assert_eq!( + msg.alignment_status, 115, + "incorrect value for alignment_status, expected 115, is {}", + msg.alignment_status + ); + assert_eq!( + msg.hdop, 31133, + "incorrect value for hdop, expected 31133, is {}", + msg.hdop + ); + assert_eq!( + msg.last_used_gnss_pos_tow, 610745181, + "incorrect value for last_used_gnss_pos_tow, expected 610745181, is {}", + msg.last_used_gnss_pos_tow + ); + assert_eq!( + msg.last_used_gnss_vel_tow, 782016851, + "incorrect value for last_used_gnss_vel_tow, expected 782016851, is {}", + msg.last_used_gnss_vel_tow + ); + assert_eq!( + msg.n_sats, 238, + "incorrect value for n_sats, expected 238, is {}", + msg.n_sats + ); + assert_eq!( + msg.pdop, 57015, + "incorrect value for pdop, expected 57015, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 67, + "incorrect value for sol_in[0].flags, expected 67, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 253, + "incorrect value for sol_in[0].sensor_type, expected 253, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 200, + "incorrect value for sol_in[1].flags, expected 200, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 87, + "incorrect value for sol_in[1].sensor_type, expected 87, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 250, + "incorrect value for sol_in[2].flags, expected 250, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 39, + "incorrect value for sol_in[2].sensor_type, expected 39, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 242, + "incorrect value for sol_in[3].flags, expected 242, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 245, + "incorrect value for sol_in[3].sensor_type, expected 245, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 72, + "incorrect value for sol_in[4].flags, expected 72, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 228, + "incorrect value for sol_in[4].sensor_type, expected 228, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 222, + "incorrect value for sol_in[5].flags, expected 222, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 18, + "incorrect value for sol_in[5].sensor_type, expected 18, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 88, + "incorrect value for sol_in[6].flags, expected 88, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 11, + "incorrect value for sol_in[6].sensor_type, expected 11, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 218, + "incorrect value for sol_in[7].flags, expected 218, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 207, + "incorrect value for sol_in[7].sensor_type, expected 207, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 13, + "incorrect value for sol_in[8].flags, expected 13, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 231, + "incorrect value for sol_in[8].sensor_type, expected 231, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 224, + "incorrect value for sol_in[9].flags, expected 224, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 226, + "incorrect value for sol_in[9].sensor_type, expected 226, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 196, + "incorrect value for sol_in[10].flags, expected 196, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 22, + "incorrect value for sol_in[10].sensor_type, expected 22, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 242, + "incorrect value for sol_in[11].flags, expected 242, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 21, + "incorrect value for sol_in[11].sensor_type, expected 21, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 89, + "incorrect value for sol_in[12].flags, expected 89, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 12, + "incorrect value for sol_in[12].sensor_type, expected 12, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 219, + "incorrect value for sol_in[13].flags, expected 219, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 71, + "incorrect value for sol_in[13].sensor_type, expected 71, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 85, + "incorrect value for sol_in[14].flags, expected 85, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 182, + "incorrect value for sol_in[14].sensor_type, expected 182, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 204, + "incorrect value for sol_in[15].flags, expected 204, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 145, + "incorrect value for sol_in[15].sensor_type, expected 145, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 40, + "incorrect value for sol_in[16].flags, expected 40, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 146, + "incorrect value for sol_in[16].sensor_type, expected 146, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 51, + "incorrect value for sol_in[17].flags, expected 51, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 204, + "incorrect value for sol_in[17].sensor_type, expected 204, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 153, + "incorrect value for sol_in[18].flags, expected 153, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 21, + "incorrect value for sol_in[18].sensor_type, expected 21, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 44, + "incorrect value for sol_in[19].flags, expected 44, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 227, + "incorrect value for sol_in[19].sensor_type, expected 227, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 28, + "incorrect value for sol_in[20].flags, expected 28, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 15, + "incorrect value for sol_in[20].sensor_type, expected 15, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 39, + "incorrect value for sol_in[21].flags, expected 39, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 255, + "incorrect value for sol_in[21].sensor_type, expected 255, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 216, + "incorrect value for sol_in[22].flags, expected 216, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 205, + "incorrect value for sol_in[22].sensor_type, expected 205, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 190, + "incorrect value for sol_in[23].flags, expected 190, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 240, + "incorrect value for sol_in[23].sensor_type, expected 240, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 219, + "incorrect value for sol_in[24].flags, expected 219, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 93, + "incorrect value for sol_in[24].sensor_type, expected 93, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 42, + "incorrect value for sol_in[25].flags, expected 42, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 103, + "incorrect value for sol_in[25].sensor_type, expected 103, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 182, + "incorrect value for sol_in[26].flags, expected 182, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 41, + "incorrect value for sol_in[26].sensor_type, expected 41, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 222, + "incorrect value for sol_in[27].flags, expected 222, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 76, + "incorrect value for sol_in[27].sensor_type, expected 76, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 23, + "incorrect value for sol_in[28].flags, expected 23, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 17, + "incorrect value for sol_in[28].sensor_type, expected 17, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 31, + "incorrect value for sol_in[29].flags, expected 31, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 125, + "incorrect value for sol_in[29].sensor_type, expected 125, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 229, + "incorrect value for sol_in[30].flags, expected 229, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 18, + "incorrect value for sol_in[30].sensor_type, expected 18, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 47, + "incorrect value for sol_in[31].flags, expected 47, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 28, + "incorrect value for sol_in[31].sensor_type, expected 28, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 25, + "incorrect value for sol_in[32].flags, expected 25, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 214, + "incorrect value for sol_in[32].sensor_type, expected 214, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 84, + "incorrect value for sol_in[33].flags, expected 84, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 100, + "incorrect value for sol_in[33].sensor_type, expected 100, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 72, + "incorrect value for sol_in[34].flags, expected 72, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 106, + "incorrect value for sol_in[34].sensor_type, expected 106, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 10, + "incorrect value for sol_in[35].flags, expected 10, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 48, + "incorrect value for sol_in[35].sensor_type, expected 48, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 232, + "incorrect value for sol_in[36].flags, expected 232, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 222, + "incorrect value for sol_in[36].sensor_type, expected 222, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 73, + "incorrect value for sol_in[37].flags, expected 73, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 235, + "incorrect value for sol_in[37].sensor_type, expected 235, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 163, + "incorrect value for sol_in[38].flags, expected 163, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 109, + "incorrect value for sol_in[38].sensor_type, expected 109, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 152, + "incorrect value for sol_in[39].flags, expected 152, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 51, + "incorrect value for sol_in[39].sensor_type, expected 51, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 235, + "incorrect value for sol_in[40].flags, expected 235, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 133, + "incorrect value for sol_in[40].sensor_type, expected 133, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 70, + "incorrect value for sol_in[41].flags, expected 70, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 87, + "incorrect value for sol_in[41].sensor_type, expected 87, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 108, + "incorrect value for sol_in[42].flags, expected 108, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 2, + "incorrect value for sol_in[42].sensor_type, expected 2, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 101, + "incorrect value for sol_in[43].flags, expected 101, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 91, + "incorrect value for sol_in[43].sensor_type, expected 91, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 55, + "incorrect value for sol_in[44].flags, expected 55, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 200, + "incorrect value for sol_in[44].sensor_type, expected 200, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 156, + "incorrect value for sol_in[45].flags, expected 156, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 24, + "incorrect value for sol_in[45].sensor_type, expected 24, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 73, + "incorrect value for sol_in[46].flags, expected 73, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 233, + "incorrect value for sol_in[46].sensor_type, expected 233, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 66, + "incorrect value for sol_in[47].flags, expected 66, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 39, + "incorrect value for sol_in[47].sensor_type, expected 39, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 140, + "incorrect value for sol_in[48].flags, expected 140, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 97, + "incorrect value for sol_in[48].sensor_type, expected 97, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 227, + "incorrect value for sol_in[49].flags, expected 227, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 252, + "incorrect value for sol_in[49].sensor_type, expected 252, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 237, + "incorrect value for sol_in[50].flags, expected 237, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 230, + "incorrect value for sol_in[50].sensor_type, expected 230, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 241, + "incorrect value for sol_in[51].flags, expected 241, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 135, + "incorrect value for sol_in[51].sensor_type, expected 135, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 205, + "incorrect value for sol_in[52].flags, expected 205, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 245, + "incorrect value for sol_in[52].sensor_type, expected 245, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 0, + "incorrect value for sol_in[53].flags, expected 0, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 70, + "incorrect value for sol_in[53].sensor_type, expected 70, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 188, + "incorrect value for sol_in[54].flags, expected 188, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 219, + "incorrect value for sol_in[54].sensor_type, expected 219, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 136, + "incorrect value for sol_in[55].flags, expected 136, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 107, + "incorrect value for sol_in[55].sensor_type, expected 107, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 58, + "incorrect value for sol_in[56].flags, expected 58, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 178, + "incorrect value for sol_in[56].sensor_type, expected 178, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 29, + "incorrect value for sol_in[57].flags, expected 29, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 1, + "incorrect value for sol_in[57].sensor_type, expected 1, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 213, + "incorrect value for sol_in[58].flags, expected 213, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 44, + "incorrect value for sol_in[58].sensor_type, expected 44, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 147, + "incorrect value for sol_in[59].flags, expected 147, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 225, + "incorrect value for sol_in[59].sensor_type, expected 225, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 96, + "incorrect value for sol_in[60].flags, expected 96, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 190, + "incorrect value for sol_in[60].sensor_type, expected 190, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 108, + "incorrect value for sol_in[61].flags, expected 108, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 192, + "incorrect value for sol_in[61].sensor_type, expected 192, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 15, + "incorrect value for sol_in[62].flags, expected 15, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 228, + "incorrect value for sol_in[62].sensor_type, expected 228, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 18, + "incorrect value for sol_in[63].flags, expected 18, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 203, + "incorrect value for sol_in[63].sensor_type, expected 203, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 222, + "incorrect value for sol_in[64].flags, expected 222, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 3, + "incorrect value for sol_in[64].sensor_type, expected 3, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 68, + "incorrect value for sol_in[65].flags, expected 68, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 180, + "incorrect value for sol_in[65].sensor_type, expected 180, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 229, + "incorrect value for sol_in[66].flags, expected 229, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 101, + "incorrect value for sol_in[66].sensor_type, expected 101, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 203, + "incorrect value for sol_in[67].flags, expected 203, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 223, + "incorrect value for sol_in[67].sensor_type, expected 223, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 164, + "incorrect value for sol_in[68].flags, expected 164, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 243, + "incorrect value for sol_in[68].sensor_type, expected 243, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 165, + "incorrect value for sol_in[69].flags, expected 165, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 92, + "incorrect value for sol_in[69].sensor_type, expected 92, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 159, + "incorrect value for sol_in[70].flags, expected 159, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 220, + "incorrect value for sol_in[70].sensor_type, expected 220, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 121, + "incorrect value for sol_in[71].flags, expected 121, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 174, + "incorrect value for sol_in[71].sensor_type, expected 174, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 167, + "incorrect value for sol_in[72].flags, expected 167, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 112, + "incorrect value for sol_in[72].sensor_type, expected 112, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 40, + "incorrect value for sol_in[73].flags, expected 40, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 240, + "incorrect value for sol_in[73].sensor_type, expected 240, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 3, + "incorrect value for sol_in[74].flags, expected 3, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 59, + "incorrect value for sol_in[74].sensor_type, expected 59, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 52, + "incorrect value for sol_in[75].flags, expected 52, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 230, + "incorrect value for sol_in[75].sensor_type, expected 230, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 148, + "incorrect value for sol_in[76].flags, expected 148, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 149, + "incorrect value for sol_in[76].sensor_type, expected 149, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 142, + "incorrect value for sol_in[77].flags, expected 142, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 218, + "incorrect value for sol_in[77].sensor_type, expected 218, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 109, + "incorrect value for sol_in[78].flags, expected 109, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 212, + "incorrect value for sol_in[78].sensor_type, expected 212, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 71, + "incorrect value for sol_in[79].flags, expected 71, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 176, + "incorrect value for sol_in[79].sensor_type, expected 176, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 172, + "incorrect value for sol_in[80].flags, expected 172, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 179, + "incorrect value for sol_in[80].sensor_type, expected 179, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 1, + "incorrect value for sol_in[81].flags, expected 1, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 77, + "incorrect value for sol_in[81].sensor_type, expected 77, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 70, + "incorrect value for sol_in[82].flags, expected 70, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 193, + "incorrect value for sol_in[82].sensor_type, expected 193, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 149, + "incorrect value for sol_in[83].flags, expected 149, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 147, + "incorrect value for sol_in[83].sensor_type, expected 147, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 144, + "incorrect value for sol_in[84].flags, expected 144, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 23, + "incorrect value for sol_in[84].sensor_type, expected 23, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 239, + "incorrect value for sol_in[85].flags, expected 239, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 148, + "incorrect value for sol_in[85].sensor_type, expected 148, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 186, + "incorrect value for sol_in[86].flags, expected 186, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 195, + "incorrect value for sol_in[86].sensor_type, expected 195, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 30, + "incorrect value for sol_in[87].flags, expected 30, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 86, + "incorrect value for sol_in[87].sensor_type, expected 86, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 143, + "incorrect value for sol_in[88].flags, expected 143, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 34, + "incorrect value for sol_in[88].sensor_type, expected 34, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 207, + "incorrect value for sol_in[89].flags, expected 207, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 156, + "incorrect value for sol_in[89].sensor_type, expected 156, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 55, + "incorrect value for sol_in[90].flags, expected 55, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 63, + "incorrect value for sol_in[90].sensor_type, expected 63, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 255, + "incorrect value for sol_in[91].flags, expected 255, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 117, + "incorrect value for sol_in[91].sensor_type, expected 117, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 222, + "incorrect value for sol_in[92].flags, expected 222, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 222, + "incorrect value for sol_in[92].sensor_type, expected 222, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 145, + "incorrect value for sol_in[93].flags, expected 145, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 219, + "incorrect value for sol_in[93].sensor_type, expected 219, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 191, + "incorrect value for sol_in[94].flags, expected 191, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 224, + "incorrect value for sol_in[94].sensor_type, expected 224, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 109, + "incorrect value for sol_in[95].flags, expected 109, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 210, + "incorrect value for sol_in[95].sensor_type, expected 210, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 153, + "incorrect value for sol_in[96].flags, expected 153, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 86, + "incorrect value for sol_in[96].sensor_type, expected 86, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 32, + "incorrect value for sol_in[97].flags, expected 32, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 21, + "incorrect value for sol_in[97].sensor_type, expected 21, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 10, + "incorrect value for sol_in[98].flags, expected 10, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 226, + "incorrect value for sol_in[98].sensor_type, expected 226, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 63, + "incorrect value for sol_in[99].flags, expected 63, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 60, + "incorrect value for sol_in[99].sensor_type, expected 60, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 236, + "incorrect value for sol_in[100].flags, expected 236, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 106, + "incorrect value for sol_in[100].sensor_type, expected 106, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 96, + "incorrect value for sol_in[101].flags, expected 96, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 93, + "incorrect value for sol_in[101].sensor_type, expected 93, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 163, + "incorrect value for sol_in[102].flags, expected 163, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 30, + "incorrect value for sol_in[102].sensor_type, expected 30, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 238, + "incorrect value for sol_in[103].flags, expected 238, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 106, + "incorrect value for sol_in[103].sensor_type, expected 106, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 133, + "incorrect value for sol_in[104].flags, expected 133, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 147, + "incorrect value for sol_in[104].sensor_type, expected 147, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 107, + "incorrect value for sol_in[105].flags, expected 107, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 132, + "incorrect value for sol_in[105].sensor_type, expected 132, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 214, + "incorrect value for sol_in[106].flags, expected 214, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 152, + "incorrect value for sol_in[106].sensor_type, expected 152, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 185, + "incorrect value for sol_in[107].flags, expected 185, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 221, + "incorrect value for sol_in[107].sensor_type, expected 221, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 21, + "incorrect value for sol_in[108].flags, expected 21, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 202, + "incorrect value for sol_in[108].sensor_type, expected 202, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 51, + "incorrect value for sol_in[109].flags, expected 51, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 252, + "incorrect value for sol_in[109].sensor_type, expected 252, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 59, + "incorrect value for sol_in[110].flags, expected 59, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 130, + "incorrect value for sol_in[110].sensor_type, expected 130, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 202, + "incorrect value for sol_in[111].flags, expected 202, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 166, + "incorrect value for sol_in[111].sensor_type, expected 166, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 170, + "incorrect value for sol_in[112].flags, expected 170, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 127, + "incorrect value for sol_in[112].sensor_type, expected 127, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 193, + "incorrect value for sol_in[113].flags, expected 193, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 58, + "incorrect value for sol_in[113].sensor_type, expected 58, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 125, + "incorrect value for sol_in[114].flags, expected 125, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 215, + "incorrect value for sol_in[114].sensor_type, expected 215, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 58, + "incorrect value for sol_in[115].flags, expected 58, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 22, + "incorrect value for sol_in[115].sensor_type, expected 22, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 47, + "incorrect value for sol_in[116].flags, expected 47, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 135, + "incorrect value for sol_in[116].sensor_type, expected 135, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 142, + "incorrect value for sol_in[117].flags, expected 142, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 88, + "incorrect value for sol_in[117].sensor_type, expected 88, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.vdop, 41989, + "incorrect value for vdop, expected 41989, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMetaDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_solution_meta_msg_soln_meta_dep_a() { + { + let json_input = r#"{"crc":54093,"length":254,"msg_type":65295,"payload":"t96deQWk7h++c107ZyRToZwu/UNXyCf69fLkSBLeC1jP2ucN4uAWxBXyDFlH27ZVkcySKMwzFZnjLA8c/yfN2PC+XdtnKim2TN4RF30fEuUcL9YZZFRqSDAK3ujrSW2jM5iF61dGAmxbZcg3GJzpSSdCYYz84+bth/H1zUYA27xriLI6AR0s1eGTvmDAbOQPyxID3rREZeXfy/OkXKXcn655cKfwKDsD5jSVlNqO1G2wR7OsTQHBRpOVF5CU78O6Vh4ij5zPPzd1/97e25Hgv9JtVpkVIOIKPD9q7F1gHqNq7pOFhGuY1t25yhX8M4I7psp/qjrB130WOocvWI4=","preamble":85,"sender":61780,"pdop":57015,"hdop":31133,"vdop":41989,"n_sats":238,"age_corrections":48671,"alignment_status":115,"last_used_gnss_pos_tow":610745181,"last_used_gnss_vel_tow":782016851,"sol_in":[{"sensor_type":253,"flags":67},{"sensor_type":87,"flags":200},{"sensor_type":39,"flags":250},{"sensor_type":245,"flags":242},{"sensor_type":228,"flags":72},{"sensor_type":18,"flags":222},{"sensor_type":11,"flags":88},{"sensor_type":207,"flags":218},{"sensor_type":231,"flags":13},{"sensor_type":226,"flags":224},{"sensor_type":22,"flags":196},{"sensor_type":21,"flags":242},{"sensor_type":12,"flags":89},{"sensor_type":71,"flags":219},{"sensor_type":182,"flags":85},{"sensor_type":145,"flags":204},{"sensor_type":146,"flags":40},{"sensor_type":204,"flags":51},{"sensor_type":21,"flags":153},{"sensor_type":227,"flags":44},{"sensor_type":15,"flags":28},{"sensor_type":255,"flags":39},{"sensor_type":205,"flags":216},{"sensor_type":240,"flags":190},{"sensor_type":93,"flags":219},{"sensor_type":103,"flags":42},{"sensor_type":41,"flags":182},{"sensor_type":76,"flags":222},{"sensor_type":17,"flags":23},{"sensor_type":125,"flags":31},{"sensor_type":18,"flags":229},{"sensor_type":28,"flags":47},{"sensor_type":214,"flags":25},{"sensor_type":100,"flags":84},{"sensor_type":106,"flags":72},{"sensor_type":48,"flags":10},{"sensor_type":222,"flags":232},{"sensor_type":235,"flags":73},{"sensor_type":109,"flags":163},{"sensor_type":51,"flags":152},{"sensor_type":133,"flags":235},{"sensor_type":87,"flags":70},{"sensor_type":2,"flags":108},{"sensor_type":91,"flags":101},{"sensor_type":200,"flags":55},{"sensor_type":24,"flags":156},{"sensor_type":233,"flags":73},{"sensor_type":39,"flags":66},{"sensor_type":97,"flags":140},{"sensor_type":252,"flags":227},{"sensor_type":230,"flags":237},{"sensor_type":135,"flags":241},{"sensor_type":245,"flags":205},{"sensor_type":70,"flags":0},{"sensor_type":219,"flags":188},{"sensor_type":107,"flags":136},{"sensor_type":178,"flags":58},{"sensor_type":1,"flags":29},{"sensor_type":44,"flags":213},{"sensor_type":225,"flags":147},{"sensor_type":190,"flags":96},{"sensor_type":192,"flags":108},{"sensor_type":228,"flags":15},{"sensor_type":203,"flags":18},{"sensor_type":3,"flags":222},{"sensor_type":180,"flags":68},{"sensor_type":101,"flags":229},{"sensor_type":223,"flags":203},{"sensor_type":243,"flags":164},{"sensor_type":92,"flags":165},{"sensor_type":220,"flags":159},{"sensor_type":174,"flags":121},{"sensor_type":112,"flags":167},{"sensor_type":240,"flags":40},{"sensor_type":59,"flags":3},{"sensor_type":230,"flags":52},{"sensor_type":149,"flags":148},{"sensor_type":218,"flags":142},{"sensor_type":212,"flags":109},{"sensor_type":176,"flags":71},{"sensor_type":179,"flags":172},{"sensor_type":77,"flags":1},{"sensor_type":193,"flags":70},{"sensor_type":147,"flags":149},{"sensor_type":23,"flags":144},{"sensor_type":148,"flags":239},{"sensor_type":195,"flags":186},{"sensor_type":86,"flags":30},{"sensor_type":34,"flags":143},{"sensor_type":156,"flags":207},{"sensor_type":63,"flags":55},{"sensor_type":117,"flags":255},{"sensor_type":222,"flags":222},{"sensor_type":219,"flags":145},{"sensor_type":224,"flags":191},{"sensor_type":210,"flags":109},{"sensor_type":86,"flags":153},{"sensor_type":21,"flags":32},{"sensor_type":226,"flags":10},{"sensor_type":60,"flags":63},{"sensor_type":106,"flags":236},{"sensor_type":93,"flags":96},{"sensor_type":30,"flags":163},{"sensor_type":106,"flags":238},{"sensor_type":147,"flags":133},{"sensor_type":132,"flags":107},{"sensor_type":152,"flags":214},{"sensor_type":221,"flags":185},{"sensor_type":202,"flags":21},{"sensor_type":252,"flags":51},{"sensor_type":130,"flags":59},{"sensor_type":166,"flags":202},{"sensor_type":127,"flags":170},{"sensor_type":58,"flags":193},{"sensor_type":215,"flags":125},{"sensor_type":22,"flags":58},{"sensor_type":135,"flags":47},{"sensor_type":88,"flags":142}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMetaDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0f, + "Incorrect message type, expected 0xff0f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf154, + "incorrect sender id, expected 0xf154, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 48671, + "incorrect value for age_corrections, expected 48671, is {}", + msg.age_corrections + ); + assert_eq!( + msg.alignment_status, 115, + "incorrect value for alignment_status, expected 115, is {}", + msg.alignment_status + ); + assert_eq!( + msg.hdop, 31133, + "incorrect value for hdop, expected 31133, is {}", + msg.hdop + ); + assert_eq!( + msg.last_used_gnss_pos_tow, 610745181, + "incorrect value for last_used_gnss_pos_tow, expected 610745181, is {}", + msg.last_used_gnss_pos_tow + ); + assert_eq!( + msg.last_used_gnss_vel_tow, 782016851, + "incorrect value for last_used_gnss_vel_tow, expected 782016851, is {}", + msg.last_used_gnss_vel_tow + ); + assert_eq!( + msg.n_sats, 238, + "incorrect value for n_sats, expected 238, is {}", + msg.n_sats + ); + assert_eq!( + msg.pdop, 57015, + "incorrect value for pdop, expected 57015, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 67, + "incorrect value for sol_in[0].flags, expected 67, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 253, + "incorrect value for sol_in[0].sensor_type, expected 253, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 200, + "incorrect value for sol_in[1].flags, expected 200, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 87, + "incorrect value for sol_in[1].sensor_type, expected 87, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 250, + "incorrect value for sol_in[2].flags, expected 250, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 39, + "incorrect value for sol_in[2].sensor_type, expected 39, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 242, + "incorrect value for sol_in[3].flags, expected 242, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 245, + "incorrect value for sol_in[3].sensor_type, expected 245, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 72, + "incorrect value for sol_in[4].flags, expected 72, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 228, + "incorrect value for sol_in[4].sensor_type, expected 228, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 222, + "incorrect value for sol_in[5].flags, expected 222, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 18, + "incorrect value for sol_in[5].sensor_type, expected 18, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 88, + "incorrect value for sol_in[6].flags, expected 88, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 11, + "incorrect value for sol_in[6].sensor_type, expected 11, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 218, + "incorrect value for sol_in[7].flags, expected 218, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 207, + "incorrect value for sol_in[7].sensor_type, expected 207, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 13, + "incorrect value for sol_in[8].flags, expected 13, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 231, + "incorrect value for sol_in[8].sensor_type, expected 231, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 224, + "incorrect value for sol_in[9].flags, expected 224, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 226, + "incorrect value for sol_in[9].sensor_type, expected 226, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 196, + "incorrect value for sol_in[10].flags, expected 196, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 22, + "incorrect value for sol_in[10].sensor_type, expected 22, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 242, + "incorrect value for sol_in[11].flags, expected 242, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 21, + "incorrect value for sol_in[11].sensor_type, expected 21, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 89, + "incorrect value for sol_in[12].flags, expected 89, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 12, + "incorrect value for sol_in[12].sensor_type, expected 12, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 219, + "incorrect value for sol_in[13].flags, expected 219, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 71, + "incorrect value for sol_in[13].sensor_type, expected 71, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 85, + "incorrect value for sol_in[14].flags, expected 85, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 182, + "incorrect value for sol_in[14].sensor_type, expected 182, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 204, + "incorrect value for sol_in[15].flags, expected 204, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 145, + "incorrect value for sol_in[15].sensor_type, expected 145, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 40, + "incorrect value for sol_in[16].flags, expected 40, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 146, + "incorrect value for sol_in[16].sensor_type, expected 146, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 51, + "incorrect value for sol_in[17].flags, expected 51, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 204, + "incorrect value for sol_in[17].sensor_type, expected 204, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 153, + "incorrect value for sol_in[18].flags, expected 153, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 21, + "incorrect value for sol_in[18].sensor_type, expected 21, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 44, + "incorrect value for sol_in[19].flags, expected 44, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 227, + "incorrect value for sol_in[19].sensor_type, expected 227, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 28, + "incorrect value for sol_in[20].flags, expected 28, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 15, + "incorrect value for sol_in[20].sensor_type, expected 15, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 39, + "incorrect value for sol_in[21].flags, expected 39, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 255, + "incorrect value for sol_in[21].sensor_type, expected 255, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 216, + "incorrect value for sol_in[22].flags, expected 216, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 205, + "incorrect value for sol_in[22].sensor_type, expected 205, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 190, + "incorrect value for sol_in[23].flags, expected 190, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 240, + "incorrect value for sol_in[23].sensor_type, expected 240, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 219, + "incorrect value for sol_in[24].flags, expected 219, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 93, + "incorrect value for sol_in[24].sensor_type, expected 93, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 42, + "incorrect value for sol_in[25].flags, expected 42, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 103, + "incorrect value for sol_in[25].sensor_type, expected 103, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 182, + "incorrect value for sol_in[26].flags, expected 182, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 41, + "incorrect value for sol_in[26].sensor_type, expected 41, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 222, + "incorrect value for sol_in[27].flags, expected 222, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 76, + "incorrect value for sol_in[27].sensor_type, expected 76, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 23, + "incorrect value for sol_in[28].flags, expected 23, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 17, + "incorrect value for sol_in[28].sensor_type, expected 17, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 31, + "incorrect value for sol_in[29].flags, expected 31, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 125, + "incorrect value for sol_in[29].sensor_type, expected 125, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 229, + "incorrect value for sol_in[30].flags, expected 229, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 18, + "incorrect value for sol_in[30].sensor_type, expected 18, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 47, + "incorrect value for sol_in[31].flags, expected 47, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 28, + "incorrect value for sol_in[31].sensor_type, expected 28, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 25, + "incorrect value for sol_in[32].flags, expected 25, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 214, + "incorrect value for sol_in[32].sensor_type, expected 214, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 84, + "incorrect value for sol_in[33].flags, expected 84, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 100, + "incorrect value for sol_in[33].sensor_type, expected 100, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 72, + "incorrect value for sol_in[34].flags, expected 72, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 106, + "incorrect value for sol_in[34].sensor_type, expected 106, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 10, + "incorrect value for sol_in[35].flags, expected 10, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 48, + "incorrect value for sol_in[35].sensor_type, expected 48, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 232, + "incorrect value for sol_in[36].flags, expected 232, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 222, + "incorrect value for sol_in[36].sensor_type, expected 222, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 73, + "incorrect value for sol_in[37].flags, expected 73, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 235, + "incorrect value for sol_in[37].sensor_type, expected 235, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 163, + "incorrect value for sol_in[38].flags, expected 163, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 109, + "incorrect value for sol_in[38].sensor_type, expected 109, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 152, + "incorrect value for sol_in[39].flags, expected 152, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 51, + "incorrect value for sol_in[39].sensor_type, expected 51, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 235, + "incorrect value for sol_in[40].flags, expected 235, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 133, + "incorrect value for sol_in[40].sensor_type, expected 133, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 70, + "incorrect value for sol_in[41].flags, expected 70, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 87, + "incorrect value for sol_in[41].sensor_type, expected 87, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 108, + "incorrect value for sol_in[42].flags, expected 108, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 2, + "incorrect value for sol_in[42].sensor_type, expected 2, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 101, + "incorrect value for sol_in[43].flags, expected 101, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 91, + "incorrect value for sol_in[43].sensor_type, expected 91, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 55, + "incorrect value for sol_in[44].flags, expected 55, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 200, + "incorrect value for sol_in[44].sensor_type, expected 200, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 156, + "incorrect value for sol_in[45].flags, expected 156, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 24, + "incorrect value for sol_in[45].sensor_type, expected 24, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 73, + "incorrect value for sol_in[46].flags, expected 73, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 233, + "incorrect value for sol_in[46].sensor_type, expected 233, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 66, + "incorrect value for sol_in[47].flags, expected 66, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 39, + "incorrect value for sol_in[47].sensor_type, expected 39, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 140, + "incorrect value for sol_in[48].flags, expected 140, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 97, + "incorrect value for sol_in[48].sensor_type, expected 97, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 227, + "incorrect value for sol_in[49].flags, expected 227, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 252, + "incorrect value for sol_in[49].sensor_type, expected 252, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 237, + "incorrect value for sol_in[50].flags, expected 237, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 230, + "incorrect value for sol_in[50].sensor_type, expected 230, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 241, + "incorrect value for sol_in[51].flags, expected 241, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 135, + "incorrect value for sol_in[51].sensor_type, expected 135, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 205, + "incorrect value for sol_in[52].flags, expected 205, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 245, + "incorrect value for sol_in[52].sensor_type, expected 245, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 0, + "incorrect value for sol_in[53].flags, expected 0, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 70, + "incorrect value for sol_in[53].sensor_type, expected 70, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 188, + "incorrect value for sol_in[54].flags, expected 188, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 219, + "incorrect value for sol_in[54].sensor_type, expected 219, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 136, + "incorrect value for sol_in[55].flags, expected 136, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 107, + "incorrect value for sol_in[55].sensor_type, expected 107, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 58, + "incorrect value for sol_in[56].flags, expected 58, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 178, + "incorrect value for sol_in[56].sensor_type, expected 178, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 29, + "incorrect value for sol_in[57].flags, expected 29, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 1, + "incorrect value for sol_in[57].sensor_type, expected 1, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 213, + "incorrect value for sol_in[58].flags, expected 213, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 44, + "incorrect value for sol_in[58].sensor_type, expected 44, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 147, + "incorrect value for sol_in[59].flags, expected 147, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 225, + "incorrect value for sol_in[59].sensor_type, expected 225, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 96, + "incorrect value for sol_in[60].flags, expected 96, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 190, + "incorrect value for sol_in[60].sensor_type, expected 190, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 108, + "incorrect value for sol_in[61].flags, expected 108, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 192, + "incorrect value for sol_in[61].sensor_type, expected 192, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 15, + "incorrect value for sol_in[62].flags, expected 15, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 228, + "incorrect value for sol_in[62].sensor_type, expected 228, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 18, + "incorrect value for sol_in[63].flags, expected 18, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 203, + "incorrect value for sol_in[63].sensor_type, expected 203, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 222, + "incorrect value for sol_in[64].flags, expected 222, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 3, + "incorrect value for sol_in[64].sensor_type, expected 3, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 68, + "incorrect value for sol_in[65].flags, expected 68, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 180, + "incorrect value for sol_in[65].sensor_type, expected 180, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 229, + "incorrect value for sol_in[66].flags, expected 229, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 101, + "incorrect value for sol_in[66].sensor_type, expected 101, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 203, + "incorrect value for sol_in[67].flags, expected 203, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 223, + "incorrect value for sol_in[67].sensor_type, expected 223, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 164, + "incorrect value for sol_in[68].flags, expected 164, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 243, + "incorrect value for sol_in[68].sensor_type, expected 243, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 165, + "incorrect value for sol_in[69].flags, expected 165, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 92, + "incorrect value for sol_in[69].sensor_type, expected 92, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 159, + "incorrect value for sol_in[70].flags, expected 159, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 220, + "incorrect value for sol_in[70].sensor_type, expected 220, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 121, + "incorrect value for sol_in[71].flags, expected 121, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 174, + "incorrect value for sol_in[71].sensor_type, expected 174, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 167, + "incorrect value for sol_in[72].flags, expected 167, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 112, + "incorrect value for sol_in[72].sensor_type, expected 112, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 40, + "incorrect value for sol_in[73].flags, expected 40, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 240, + "incorrect value for sol_in[73].sensor_type, expected 240, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 3, + "incorrect value for sol_in[74].flags, expected 3, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 59, + "incorrect value for sol_in[74].sensor_type, expected 59, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 52, + "incorrect value for sol_in[75].flags, expected 52, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 230, + "incorrect value for sol_in[75].sensor_type, expected 230, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 148, + "incorrect value for sol_in[76].flags, expected 148, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 149, + "incorrect value for sol_in[76].sensor_type, expected 149, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 142, + "incorrect value for sol_in[77].flags, expected 142, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 218, + "incorrect value for sol_in[77].sensor_type, expected 218, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 109, + "incorrect value for sol_in[78].flags, expected 109, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 212, + "incorrect value for sol_in[78].sensor_type, expected 212, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 71, + "incorrect value for sol_in[79].flags, expected 71, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 176, + "incorrect value for sol_in[79].sensor_type, expected 176, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 172, + "incorrect value for sol_in[80].flags, expected 172, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 179, + "incorrect value for sol_in[80].sensor_type, expected 179, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 1, + "incorrect value for sol_in[81].flags, expected 1, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 77, + "incorrect value for sol_in[81].sensor_type, expected 77, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 70, + "incorrect value for sol_in[82].flags, expected 70, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 193, + "incorrect value for sol_in[82].sensor_type, expected 193, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 149, + "incorrect value for sol_in[83].flags, expected 149, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 147, + "incorrect value for sol_in[83].sensor_type, expected 147, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 144, + "incorrect value for sol_in[84].flags, expected 144, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 23, + "incorrect value for sol_in[84].sensor_type, expected 23, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 239, + "incorrect value for sol_in[85].flags, expected 239, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 148, + "incorrect value for sol_in[85].sensor_type, expected 148, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 186, + "incorrect value for sol_in[86].flags, expected 186, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 195, + "incorrect value for sol_in[86].sensor_type, expected 195, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 30, + "incorrect value for sol_in[87].flags, expected 30, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 86, + "incorrect value for sol_in[87].sensor_type, expected 86, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 143, + "incorrect value for sol_in[88].flags, expected 143, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 34, + "incorrect value for sol_in[88].sensor_type, expected 34, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 207, + "incorrect value for sol_in[89].flags, expected 207, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 156, + "incorrect value for sol_in[89].sensor_type, expected 156, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 55, + "incorrect value for sol_in[90].flags, expected 55, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 63, + "incorrect value for sol_in[90].sensor_type, expected 63, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 255, + "incorrect value for sol_in[91].flags, expected 255, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 117, + "incorrect value for sol_in[91].sensor_type, expected 117, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 222, + "incorrect value for sol_in[92].flags, expected 222, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 222, + "incorrect value for sol_in[92].sensor_type, expected 222, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 145, + "incorrect value for sol_in[93].flags, expected 145, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 219, + "incorrect value for sol_in[93].sensor_type, expected 219, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 191, + "incorrect value for sol_in[94].flags, expected 191, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 224, + "incorrect value for sol_in[94].sensor_type, expected 224, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 109, + "incorrect value for sol_in[95].flags, expected 109, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 210, + "incorrect value for sol_in[95].sensor_type, expected 210, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 153, + "incorrect value for sol_in[96].flags, expected 153, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 86, + "incorrect value for sol_in[96].sensor_type, expected 86, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 32, + "incorrect value for sol_in[97].flags, expected 32, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 21, + "incorrect value for sol_in[97].sensor_type, expected 21, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 10, + "incorrect value for sol_in[98].flags, expected 10, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 226, + "incorrect value for sol_in[98].sensor_type, expected 226, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 63, + "incorrect value for sol_in[99].flags, expected 63, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 60, + "incorrect value for sol_in[99].sensor_type, expected 60, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 236, + "incorrect value for sol_in[100].flags, expected 236, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 106, + "incorrect value for sol_in[100].sensor_type, expected 106, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 96, + "incorrect value for sol_in[101].flags, expected 96, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 93, + "incorrect value for sol_in[101].sensor_type, expected 93, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 163, + "incorrect value for sol_in[102].flags, expected 163, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 30, + "incorrect value for sol_in[102].sensor_type, expected 30, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 238, + "incorrect value for sol_in[103].flags, expected 238, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 106, + "incorrect value for sol_in[103].sensor_type, expected 106, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 133, + "incorrect value for sol_in[104].flags, expected 133, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 147, + "incorrect value for sol_in[104].sensor_type, expected 147, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 107, + "incorrect value for sol_in[105].flags, expected 107, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 132, + "incorrect value for sol_in[105].sensor_type, expected 132, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 214, + "incorrect value for sol_in[106].flags, expected 214, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 152, + "incorrect value for sol_in[106].sensor_type, expected 152, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 185, + "incorrect value for sol_in[107].flags, expected 185, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 221, + "incorrect value for sol_in[107].sensor_type, expected 221, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 21, + "incorrect value for sol_in[108].flags, expected 21, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 202, + "incorrect value for sol_in[108].sensor_type, expected 202, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 51, + "incorrect value for sol_in[109].flags, expected 51, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 252, + "incorrect value for sol_in[109].sensor_type, expected 252, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 59, + "incorrect value for sol_in[110].flags, expected 59, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 130, + "incorrect value for sol_in[110].sensor_type, expected 130, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 202, + "incorrect value for sol_in[111].flags, expected 202, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 166, + "incorrect value for sol_in[111].sensor_type, expected 166, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 170, + "incorrect value for sol_in[112].flags, expected 170, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 127, + "incorrect value for sol_in[112].sensor_type, expected 127, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 193, + "incorrect value for sol_in[113].flags, expected 193, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 58, + "incorrect value for sol_in[113].sensor_type, expected 58, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 125, + "incorrect value for sol_in[114].flags, expected 125, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 215, + "incorrect value for sol_in[114].sensor_type, expected 215, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 58, + "incorrect value for sol_in[115].flags, expected 58, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 22, + "incorrect value for sol_in[115].sensor_type, expected 22, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 47, + "incorrect value for sol_in[116].flags, expected 47, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 135, + "incorrect value for sol_in[116].sensor_type, expected 135, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 142, + "incorrect value for sol_in[117].flags, expected 142, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 88, + "incorrect value for sol_in[117].sensor_type, expected 88, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.vdop, 41989, + "incorrect value for vdop, expected 41989, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMetaDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_solution_meta_msg_soln_meta_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_solution_meta_msg_soln_meta_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 15, 255, 84, 241, 254, 183, 222, 157, 121, 5, 164, 238, 31, 190, 115, 93, 59, 103, + 36, 83, 161, 156, 46, 253, 67, 87, 200, 39, 250, 245, 242, 228, 72, 18, 222, 11, 88, + 207, 218, 231, 13, 226, 224, 22, 196, 21, 242, 12, 89, 71, 219, 182, 85, 145, 204, 146, + 40, 204, 51, 21, 153, 227, 44, 15, 28, 255, 39, 205, 216, 240, 190, 93, 219, 103, 42, + 41, 182, 76, 222, 17, 23, 125, 31, 18, 229, 28, 47, 214, 25, 100, 84, 106, 72, 48, 10, + 222, 232, 235, 73, 109, 163, 51, 152, 133, 235, 87, 70, 2, 108, 91, 101, 200, 55, 24, + 156, 233, 73, 39, 66, 97, 140, 252, 227, 230, 237, 135, 241, 245, 205, 70, 0, 219, 188, + 107, 136, 178, 58, 1, 29, 44, 213, 225, 147, 190, 96, 192, 108, 228, 15, 203, 18, 3, + 222, 180, 68, 101, 229, 223, 203, 243, 164, 92, 165, 220, 159, 174, 121, 112, 167, 240, + 40, 59, 3, 230, 52, 149, 148, 218, 142, 212, 109, 176, 71, 179, 172, 77, 1, 193, 70, + 147, 149, 23, 144, 148, 239, 195, 186, 86, 30, 34, 143, 156, 207, 63, 55, 117, 255, + 222, 222, 219, 145, 224, 191, 210, 109, 86, 153, 21, 32, 226, 10, 60, 63, 106, 236, 93, + 96, 30, 163, 106, 238, 147, 133, 132, 107, 152, 214, 221, 185, 202, 21, 252, 51, 130, + 59, 166, 202, 127, 170, 58, 193, 215, 125, 22, 58, 135, 47, 88, 142, 77, 211, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSolnMetaDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSolnMetaDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff0f, + "Incorrect message type, expected 0xff0f, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf154, + "incorrect sender id, expected 0xf154, is {sender_id}" + ); + assert_eq!( + msg.age_corrections, 48671, + "incorrect value for age_corrections, expected 48671, is {}", + msg.age_corrections + ); + assert_eq!( + msg.alignment_status, 115, + "incorrect value for alignment_status, expected 115, is {}", + msg.alignment_status + ); + assert_eq!( + msg.hdop, 31133, + "incorrect value for hdop, expected 31133, is {}", + msg.hdop + ); + assert_eq!( + msg.last_used_gnss_pos_tow, 610745181, + "incorrect value for last_used_gnss_pos_tow, expected 610745181, is {}", + msg.last_used_gnss_pos_tow + ); + assert_eq!( + msg.last_used_gnss_vel_tow, 782016851, + "incorrect value for last_used_gnss_vel_tow, expected 782016851, is {}", + msg.last_used_gnss_vel_tow + ); + assert_eq!( + msg.n_sats, 238, + "incorrect value for n_sats, expected 238, is {}", + msg.n_sats + ); + assert_eq!( + msg.pdop, 57015, + "incorrect value for pdop, expected 57015, is {}", + msg.pdop + ); + assert_eq!( + msg.sol_in[0].flags, 67, + "incorrect value for sol_in[0].flags, expected 67, is {}", + msg.sol_in[0].flags + ); + assert_eq!( + msg.sol_in[0].sensor_type, 253, + "incorrect value for sol_in[0].sensor_type, expected 253, is {}", + msg.sol_in[0].sensor_type + ); + assert_eq!( + msg.sol_in[1].flags, 200, + "incorrect value for sol_in[1].flags, expected 200, is {}", + msg.sol_in[1].flags + ); + assert_eq!( + msg.sol_in[1].sensor_type, 87, + "incorrect value for sol_in[1].sensor_type, expected 87, is {}", + msg.sol_in[1].sensor_type + ); + assert_eq!( + msg.sol_in[2].flags, 250, + "incorrect value for sol_in[2].flags, expected 250, is {}", + msg.sol_in[2].flags + ); + assert_eq!( + msg.sol_in[2].sensor_type, 39, + "incorrect value for sol_in[2].sensor_type, expected 39, is {}", + msg.sol_in[2].sensor_type + ); + assert_eq!( + msg.sol_in[3].flags, 242, + "incorrect value for sol_in[3].flags, expected 242, is {}", + msg.sol_in[3].flags + ); + assert_eq!( + msg.sol_in[3].sensor_type, 245, + "incorrect value for sol_in[3].sensor_type, expected 245, is {}", + msg.sol_in[3].sensor_type + ); + assert_eq!( + msg.sol_in[4].flags, 72, + "incorrect value for sol_in[4].flags, expected 72, is {}", + msg.sol_in[4].flags + ); + assert_eq!( + msg.sol_in[4].sensor_type, 228, + "incorrect value for sol_in[4].sensor_type, expected 228, is {}", + msg.sol_in[4].sensor_type + ); + assert_eq!( + msg.sol_in[5].flags, 222, + "incorrect value for sol_in[5].flags, expected 222, is {}", + msg.sol_in[5].flags + ); + assert_eq!( + msg.sol_in[5].sensor_type, 18, + "incorrect value for sol_in[5].sensor_type, expected 18, is {}", + msg.sol_in[5].sensor_type + ); + assert_eq!( + msg.sol_in[6].flags, 88, + "incorrect value for sol_in[6].flags, expected 88, is {}", + msg.sol_in[6].flags + ); + assert_eq!( + msg.sol_in[6].sensor_type, 11, + "incorrect value for sol_in[6].sensor_type, expected 11, is {}", + msg.sol_in[6].sensor_type + ); + assert_eq!( + msg.sol_in[7].flags, 218, + "incorrect value for sol_in[7].flags, expected 218, is {}", + msg.sol_in[7].flags + ); + assert_eq!( + msg.sol_in[7].sensor_type, 207, + "incorrect value for sol_in[7].sensor_type, expected 207, is {}", + msg.sol_in[7].sensor_type + ); + assert_eq!( + msg.sol_in[8].flags, 13, + "incorrect value for sol_in[8].flags, expected 13, is {}", + msg.sol_in[8].flags + ); + assert_eq!( + msg.sol_in[8].sensor_type, 231, + "incorrect value for sol_in[8].sensor_type, expected 231, is {}", + msg.sol_in[8].sensor_type + ); + assert_eq!( + msg.sol_in[9].flags, 224, + "incorrect value for sol_in[9].flags, expected 224, is {}", + msg.sol_in[9].flags + ); + assert_eq!( + msg.sol_in[9].sensor_type, 226, + "incorrect value for sol_in[9].sensor_type, expected 226, is {}", + msg.sol_in[9].sensor_type + ); + assert_eq!( + msg.sol_in[10].flags, 196, + "incorrect value for sol_in[10].flags, expected 196, is {}", + msg.sol_in[10].flags + ); + assert_eq!( + msg.sol_in[10].sensor_type, 22, + "incorrect value for sol_in[10].sensor_type, expected 22, is {}", + msg.sol_in[10].sensor_type + ); + assert_eq!( + msg.sol_in[11].flags, 242, + "incorrect value for sol_in[11].flags, expected 242, is {}", + msg.sol_in[11].flags + ); + assert_eq!( + msg.sol_in[11].sensor_type, 21, + "incorrect value for sol_in[11].sensor_type, expected 21, is {}", + msg.sol_in[11].sensor_type + ); + assert_eq!( + msg.sol_in[12].flags, 89, + "incorrect value for sol_in[12].flags, expected 89, is {}", + msg.sol_in[12].flags + ); + assert_eq!( + msg.sol_in[12].sensor_type, 12, + "incorrect value for sol_in[12].sensor_type, expected 12, is {}", + msg.sol_in[12].sensor_type + ); + assert_eq!( + msg.sol_in[13].flags, 219, + "incorrect value for sol_in[13].flags, expected 219, is {}", + msg.sol_in[13].flags + ); + assert_eq!( + msg.sol_in[13].sensor_type, 71, + "incorrect value for sol_in[13].sensor_type, expected 71, is {}", + msg.sol_in[13].sensor_type + ); + assert_eq!( + msg.sol_in[14].flags, 85, + "incorrect value for sol_in[14].flags, expected 85, is {}", + msg.sol_in[14].flags + ); + assert_eq!( + msg.sol_in[14].sensor_type, 182, + "incorrect value for sol_in[14].sensor_type, expected 182, is {}", + msg.sol_in[14].sensor_type + ); + assert_eq!( + msg.sol_in[15].flags, 204, + "incorrect value for sol_in[15].flags, expected 204, is {}", + msg.sol_in[15].flags + ); + assert_eq!( + msg.sol_in[15].sensor_type, 145, + "incorrect value for sol_in[15].sensor_type, expected 145, is {}", + msg.sol_in[15].sensor_type + ); + assert_eq!( + msg.sol_in[16].flags, 40, + "incorrect value for sol_in[16].flags, expected 40, is {}", + msg.sol_in[16].flags + ); + assert_eq!( + msg.sol_in[16].sensor_type, 146, + "incorrect value for sol_in[16].sensor_type, expected 146, is {}", + msg.sol_in[16].sensor_type + ); + assert_eq!( + msg.sol_in[17].flags, 51, + "incorrect value for sol_in[17].flags, expected 51, is {}", + msg.sol_in[17].flags + ); + assert_eq!( + msg.sol_in[17].sensor_type, 204, + "incorrect value for sol_in[17].sensor_type, expected 204, is {}", + msg.sol_in[17].sensor_type + ); + assert_eq!( + msg.sol_in[18].flags, 153, + "incorrect value for sol_in[18].flags, expected 153, is {}", + msg.sol_in[18].flags + ); + assert_eq!( + msg.sol_in[18].sensor_type, 21, + "incorrect value for sol_in[18].sensor_type, expected 21, is {}", + msg.sol_in[18].sensor_type + ); + assert_eq!( + msg.sol_in[19].flags, 44, + "incorrect value for sol_in[19].flags, expected 44, is {}", + msg.sol_in[19].flags + ); + assert_eq!( + msg.sol_in[19].sensor_type, 227, + "incorrect value for sol_in[19].sensor_type, expected 227, is {}", + msg.sol_in[19].sensor_type + ); + assert_eq!( + msg.sol_in[20].flags, 28, + "incorrect value for sol_in[20].flags, expected 28, is {}", + msg.sol_in[20].flags + ); + assert_eq!( + msg.sol_in[20].sensor_type, 15, + "incorrect value for sol_in[20].sensor_type, expected 15, is {}", + msg.sol_in[20].sensor_type + ); + assert_eq!( + msg.sol_in[21].flags, 39, + "incorrect value for sol_in[21].flags, expected 39, is {}", + msg.sol_in[21].flags + ); + assert_eq!( + msg.sol_in[21].sensor_type, 255, + "incorrect value for sol_in[21].sensor_type, expected 255, is {}", + msg.sol_in[21].sensor_type + ); + assert_eq!( + msg.sol_in[22].flags, 216, + "incorrect value for sol_in[22].flags, expected 216, is {}", + msg.sol_in[22].flags + ); + assert_eq!( + msg.sol_in[22].sensor_type, 205, + "incorrect value for sol_in[22].sensor_type, expected 205, is {}", + msg.sol_in[22].sensor_type + ); + assert_eq!( + msg.sol_in[23].flags, 190, + "incorrect value for sol_in[23].flags, expected 190, is {}", + msg.sol_in[23].flags + ); + assert_eq!( + msg.sol_in[23].sensor_type, 240, + "incorrect value for sol_in[23].sensor_type, expected 240, is {}", + msg.sol_in[23].sensor_type + ); + assert_eq!( + msg.sol_in[24].flags, 219, + "incorrect value for sol_in[24].flags, expected 219, is {}", + msg.sol_in[24].flags + ); + assert_eq!( + msg.sol_in[24].sensor_type, 93, + "incorrect value for sol_in[24].sensor_type, expected 93, is {}", + msg.sol_in[24].sensor_type + ); + assert_eq!( + msg.sol_in[25].flags, 42, + "incorrect value for sol_in[25].flags, expected 42, is {}", + msg.sol_in[25].flags + ); + assert_eq!( + msg.sol_in[25].sensor_type, 103, + "incorrect value for sol_in[25].sensor_type, expected 103, is {}", + msg.sol_in[25].sensor_type + ); + assert_eq!( + msg.sol_in[26].flags, 182, + "incorrect value for sol_in[26].flags, expected 182, is {}", + msg.sol_in[26].flags + ); + assert_eq!( + msg.sol_in[26].sensor_type, 41, + "incorrect value for sol_in[26].sensor_type, expected 41, is {}", + msg.sol_in[26].sensor_type + ); + assert_eq!( + msg.sol_in[27].flags, 222, + "incorrect value for sol_in[27].flags, expected 222, is {}", + msg.sol_in[27].flags + ); + assert_eq!( + msg.sol_in[27].sensor_type, 76, + "incorrect value for sol_in[27].sensor_type, expected 76, is {}", + msg.sol_in[27].sensor_type + ); + assert_eq!( + msg.sol_in[28].flags, 23, + "incorrect value for sol_in[28].flags, expected 23, is {}", + msg.sol_in[28].flags + ); + assert_eq!( + msg.sol_in[28].sensor_type, 17, + "incorrect value for sol_in[28].sensor_type, expected 17, is {}", + msg.sol_in[28].sensor_type + ); + assert_eq!( + msg.sol_in[29].flags, 31, + "incorrect value for sol_in[29].flags, expected 31, is {}", + msg.sol_in[29].flags + ); + assert_eq!( + msg.sol_in[29].sensor_type, 125, + "incorrect value for sol_in[29].sensor_type, expected 125, is {}", + msg.sol_in[29].sensor_type + ); + assert_eq!( + msg.sol_in[30].flags, 229, + "incorrect value for sol_in[30].flags, expected 229, is {}", + msg.sol_in[30].flags + ); + assert_eq!( + msg.sol_in[30].sensor_type, 18, + "incorrect value for sol_in[30].sensor_type, expected 18, is {}", + msg.sol_in[30].sensor_type + ); + assert_eq!( + msg.sol_in[31].flags, 47, + "incorrect value for sol_in[31].flags, expected 47, is {}", + msg.sol_in[31].flags + ); + assert_eq!( + msg.sol_in[31].sensor_type, 28, + "incorrect value for sol_in[31].sensor_type, expected 28, is {}", + msg.sol_in[31].sensor_type + ); + assert_eq!( + msg.sol_in[32].flags, 25, + "incorrect value for sol_in[32].flags, expected 25, is {}", + msg.sol_in[32].flags + ); + assert_eq!( + msg.sol_in[32].sensor_type, 214, + "incorrect value for sol_in[32].sensor_type, expected 214, is {}", + msg.sol_in[32].sensor_type + ); + assert_eq!( + msg.sol_in[33].flags, 84, + "incorrect value for sol_in[33].flags, expected 84, is {}", + msg.sol_in[33].flags + ); + assert_eq!( + msg.sol_in[33].sensor_type, 100, + "incorrect value for sol_in[33].sensor_type, expected 100, is {}", + msg.sol_in[33].sensor_type + ); + assert_eq!( + msg.sol_in[34].flags, 72, + "incorrect value for sol_in[34].flags, expected 72, is {}", + msg.sol_in[34].flags + ); + assert_eq!( + msg.sol_in[34].sensor_type, 106, + "incorrect value for sol_in[34].sensor_type, expected 106, is {}", + msg.sol_in[34].sensor_type + ); + assert_eq!( + msg.sol_in[35].flags, 10, + "incorrect value for sol_in[35].flags, expected 10, is {}", + msg.sol_in[35].flags + ); + assert_eq!( + msg.sol_in[35].sensor_type, 48, + "incorrect value for sol_in[35].sensor_type, expected 48, is {}", + msg.sol_in[35].sensor_type + ); + assert_eq!( + msg.sol_in[36].flags, 232, + "incorrect value for sol_in[36].flags, expected 232, is {}", + msg.sol_in[36].flags + ); + assert_eq!( + msg.sol_in[36].sensor_type, 222, + "incorrect value for sol_in[36].sensor_type, expected 222, is {}", + msg.sol_in[36].sensor_type + ); + assert_eq!( + msg.sol_in[37].flags, 73, + "incorrect value for sol_in[37].flags, expected 73, is {}", + msg.sol_in[37].flags + ); + assert_eq!( + msg.sol_in[37].sensor_type, 235, + "incorrect value for sol_in[37].sensor_type, expected 235, is {}", + msg.sol_in[37].sensor_type + ); + assert_eq!( + msg.sol_in[38].flags, 163, + "incorrect value for sol_in[38].flags, expected 163, is {}", + msg.sol_in[38].flags + ); + assert_eq!( + msg.sol_in[38].sensor_type, 109, + "incorrect value for sol_in[38].sensor_type, expected 109, is {}", + msg.sol_in[38].sensor_type + ); + assert_eq!( + msg.sol_in[39].flags, 152, + "incorrect value for sol_in[39].flags, expected 152, is {}", + msg.sol_in[39].flags + ); + assert_eq!( + msg.sol_in[39].sensor_type, 51, + "incorrect value for sol_in[39].sensor_type, expected 51, is {}", + msg.sol_in[39].sensor_type + ); + assert_eq!( + msg.sol_in[40].flags, 235, + "incorrect value for sol_in[40].flags, expected 235, is {}", + msg.sol_in[40].flags + ); + assert_eq!( + msg.sol_in[40].sensor_type, 133, + "incorrect value for sol_in[40].sensor_type, expected 133, is {}", + msg.sol_in[40].sensor_type + ); + assert_eq!( + msg.sol_in[41].flags, 70, + "incorrect value for sol_in[41].flags, expected 70, is {}", + msg.sol_in[41].flags + ); + assert_eq!( + msg.sol_in[41].sensor_type, 87, + "incorrect value for sol_in[41].sensor_type, expected 87, is {}", + msg.sol_in[41].sensor_type + ); + assert_eq!( + msg.sol_in[42].flags, 108, + "incorrect value for sol_in[42].flags, expected 108, is {}", + msg.sol_in[42].flags + ); + assert_eq!( + msg.sol_in[42].sensor_type, 2, + "incorrect value for sol_in[42].sensor_type, expected 2, is {}", + msg.sol_in[42].sensor_type + ); + assert_eq!( + msg.sol_in[43].flags, 101, + "incorrect value for sol_in[43].flags, expected 101, is {}", + msg.sol_in[43].flags + ); + assert_eq!( + msg.sol_in[43].sensor_type, 91, + "incorrect value for sol_in[43].sensor_type, expected 91, is {}", + msg.sol_in[43].sensor_type + ); + assert_eq!( + msg.sol_in[44].flags, 55, + "incorrect value for sol_in[44].flags, expected 55, is {}", + msg.sol_in[44].flags + ); + assert_eq!( + msg.sol_in[44].sensor_type, 200, + "incorrect value for sol_in[44].sensor_type, expected 200, is {}", + msg.sol_in[44].sensor_type + ); + assert_eq!( + msg.sol_in[45].flags, 156, + "incorrect value for sol_in[45].flags, expected 156, is {}", + msg.sol_in[45].flags + ); + assert_eq!( + msg.sol_in[45].sensor_type, 24, + "incorrect value for sol_in[45].sensor_type, expected 24, is {}", + msg.sol_in[45].sensor_type + ); + assert_eq!( + msg.sol_in[46].flags, 73, + "incorrect value for sol_in[46].flags, expected 73, is {}", + msg.sol_in[46].flags + ); + assert_eq!( + msg.sol_in[46].sensor_type, 233, + "incorrect value for sol_in[46].sensor_type, expected 233, is {}", + msg.sol_in[46].sensor_type + ); + assert_eq!( + msg.sol_in[47].flags, 66, + "incorrect value for sol_in[47].flags, expected 66, is {}", + msg.sol_in[47].flags + ); + assert_eq!( + msg.sol_in[47].sensor_type, 39, + "incorrect value for sol_in[47].sensor_type, expected 39, is {}", + msg.sol_in[47].sensor_type + ); + assert_eq!( + msg.sol_in[48].flags, 140, + "incorrect value for sol_in[48].flags, expected 140, is {}", + msg.sol_in[48].flags + ); + assert_eq!( + msg.sol_in[48].sensor_type, 97, + "incorrect value for sol_in[48].sensor_type, expected 97, is {}", + msg.sol_in[48].sensor_type + ); + assert_eq!( + msg.sol_in[49].flags, 227, + "incorrect value for sol_in[49].flags, expected 227, is {}", + msg.sol_in[49].flags + ); + assert_eq!( + msg.sol_in[49].sensor_type, 252, + "incorrect value for sol_in[49].sensor_type, expected 252, is {}", + msg.sol_in[49].sensor_type + ); + assert_eq!( + msg.sol_in[50].flags, 237, + "incorrect value for sol_in[50].flags, expected 237, is {}", + msg.sol_in[50].flags + ); + assert_eq!( + msg.sol_in[50].sensor_type, 230, + "incorrect value for sol_in[50].sensor_type, expected 230, is {}", + msg.sol_in[50].sensor_type + ); + assert_eq!( + msg.sol_in[51].flags, 241, + "incorrect value for sol_in[51].flags, expected 241, is {}", + msg.sol_in[51].flags + ); + assert_eq!( + msg.sol_in[51].sensor_type, 135, + "incorrect value for sol_in[51].sensor_type, expected 135, is {}", + msg.sol_in[51].sensor_type + ); + assert_eq!( + msg.sol_in[52].flags, 205, + "incorrect value for sol_in[52].flags, expected 205, is {}", + msg.sol_in[52].flags + ); + assert_eq!( + msg.sol_in[52].sensor_type, 245, + "incorrect value for sol_in[52].sensor_type, expected 245, is {}", + msg.sol_in[52].sensor_type + ); + assert_eq!( + msg.sol_in[53].flags, 0, + "incorrect value for sol_in[53].flags, expected 0, is {}", + msg.sol_in[53].flags + ); + assert_eq!( + msg.sol_in[53].sensor_type, 70, + "incorrect value for sol_in[53].sensor_type, expected 70, is {}", + msg.sol_in[53].sensor_type + ); + assert_eq!( + msg.sol_in[54].flags, 188, + "incorrect value for sol_in[54].flags, expected 188, is {}", + msg.sol_in[54].flags + ); + assert_eq!( + msg.sol_in[54].sensor_type, 219, + "incorrect value for sol_in[54].sensor_type, expected 219, is {}", + msg.sol_in[54].sensor_type + ); + assert_eq!( + msg.sol_in[55].flags, 136, + "incorrect value for sol_in[55].flags, expected 136, is {}", + msg.sol_in[55].flags + ); + assert_eq!( + msg.sol_in[55].sensor_type, 107, + "incorrect value for sol_in[55].sensor_type, expected 107, is {}", + msg.sol_in[55].sensor_type + ); + assert_eq!( + msg.sol_in[56].flags, 58, + "incorrect value for sol_in[56].flags, expected 58, is {}", + msg.sol_in[56].flags + ); + assert_eq!( + msg.sol_in[56].sensor_type, 178, + "incorrect value for sol_in[56].sensor_type, expected 178, is {}", + msg.sol_in[56].sensor_type + ); + assert_eq!( + msg.sol_in[57].flags, 29, + "incorrect value for sol_in[57].flags, expected 29, is {}", + msg.sol_in[57].flags + ); + assert_eq!( + msg.sol_in[57].sensor_type, 1, + "incorrect value for sol_in[57].sensor_type, expected 1, is {}", + msg.sol_in[57].sensor_type + ); + assert_eq!( + msg.sol_in[58].flags, 213, + "incorrect value for sol_in[58].flags, expected 213, is {}", + msg.sol_in[58].flags + ); + assert_eq!( + msg.sol_in[58].sensor_type, 44, + "incorrect value for sol_in[58].sensor_type, expected 44, is {}", + msg.sol_in[58].sensor_type + ); + assert_eq!( + msg.sol_in[59].flags, 147, + "incorrect value for sol_in[59].flags, expected 147, is {}", + msg.sol_in[59].flags + ); + assert_eq!( + msg.sol_in[59].sensor_type, 225, + "incorrect value for sol_in[59].sensor_type, expected 225, is {}", + msg.sol_in[59].sensor_type + ); + assert_eq!( + msg.sol_in[60].flags, 96, + "incorrect value for sol_in[60].flags, expected 96, is {}", + msg.sol_in[60].flags + ); + assert_eq!( + msg.sol_in[60].sensor_type, 190, + "incorrect value for sol_in[60].sensor_type, expected 190, is {}", + msg.sol_in[60].sensor_type + ); + assert_eq!( + msg.sol_in[61].flags, 108, + "incorrect value for sol_in[61].flags, expected 108, is {}", + msg.sol_in[61].flags + ); + assert_eq!( + msg.sol_in[61].sensor_type, 192, + "incorrect value for sol_in[61].sensor_type, expected 192, is {}", + msg.sol_in[61].sensor_type + ); + assert_eq!( + msg.sol_in[62].flags, 15, + "incorrect value for sol_in[62].flags, expected 15, is {}", + msg.sol_in[62].flags + ); + assert_eq!( + msg.sol_in[62].sensor_type, 228, + "incorrect value for sol_in[62].sensor_type, expected 228, is {}", + msg.sol_in[62].sensor_type + ); + assert_eq!( + msg.sol_in[63].flags, 18, + "incorrect value for sol_in[63].flags, expected 18, is {}", + msg.sol_in[63].flags + ); + assert_eq!( + msg.sol_in[63].sensor_type, 203, + "incorrect value for sol_in[63].sensor_type, expected 203, is {}", + msg.sol_in[63].sensor_type + ); + assert_eq!( + msg.sol_in[64].flags, 222, + "incorrect value for sol_in[64].flags, expected 222, is {}", + msg.sol_in[64].flags + ); + assert_eq!( + msg.sol_in[64].sensor_type, 3, + "incorrect value for sol_in[64].sensor_type, expected 3, is {}", + msg.sol_in[64].sensor_type + ); + assert_eq!( + msg.sol_in[65].flags, 68, + "incorrect value for sol_in[65].flags, expected 68, is {}", + msg.sol_in[65].flags + ); + assert_eq!( + msg.sol_in[65].sensor_type, 180, + "incorrect value for sol_in[65].sensor_type, expected 180, is {}", + msg.sol_in[65].sensor_type + ); + assert_eq!( + msg.sol_in[66].flags, 229, + "incorrect value for sol_in[66].flags, expected 229, is {}", + msg.sol_in[66].flags + ); + assert_eq!( + msg.sol_in[66].sensor_type, 101, + "incorrect value for sol_in[66].sensor_type, expected 101, is {}", + msg.sol_in[66].sensor_type + ); + assert_eq!( + msg.sol_in[67].flags, 203, + "incorrect value for sol_in[67].flags, expected 203, is {}", + msg.sol_in[67].flags + ); + assert_eq!( + msg.sol_in[67].sensor_type, 223, + "incorrect value for sol_in[67].sensor_type, expected 223, is {}", + msg.sol_in[67].sensor_type + ); + assert_eq!( + msg.sol_in[68].flags, 164, + "incorrect value for sol_in[68].flags, expected 164, is {}", + msg.sol_in[68].flags + ); + assert_eq!( + msg.sol_in[68].sensor_type, 243, + "incorrect value for sol_in[68].sensor_type, expected 243, is {}", + msg.sol_in[68].sensor_type + ); + assert_eq!( + msg.sol_in[69].flags, 165, + "incorrect value for sol_in[69].flags, expected 165, is {}", + msg.sol_in[69].flags + ); + assert_eq!( + msg.sol_in[69].sensor_type, 92, + "incorrect value for sol_in[69].sensor_type, expected 92, is {}", + msg.sol_in[69].sensor_type + ); + assert_eq!( + msg.sol_in[70].flags, 159, + "incorrect value for sol_in[70].flags, expected 159, is {}", + msg.sol_in[70].flags + ); + assert_eq!( + msg.sol_in[70].sensor_type, 220, + "incorrect value for sol_in[70].sensor_type, expected 220, is {}", + msg.sol_in[70].sensor_type + ); + assert_eq!( + msg.sol_in[71].flags, 121, + "incorrect value for sol_in[71].flags, expected 121, is {}", + msg.sol_in[71].flags + ); + assert_eq!( + msg.sol_in[71].sensor_type, 174, + "incorrect value for sol_in[71].sensor_type, expected 174, is {}", + msg.sol_in[71].sensor_type + ); + assert_eq!( + msg.sol_in[72].flags, 167, + "incorrect value for sol_in[72].flags, expected 167, is {}", + msg.sol_in[72].flags + ); + assert_eq!( + msg.sol_in[72].sensor_type, 112, + "incorrect value for sol_in[72].sensor_type, expected 112, is {}", + msg.sol_in[72].sensor_type + ); + assert_eq!( + msg.sol_in[73].flags, 40, + "incorrect value for sol_in[73].flags, expected 40, is {}", + msg.sol_in[73].flags + ); + assert_eq!( + msg.sol_in[73].sensor_type, 240, + "incorrect value for sol_in[73].sensor_type, expected 240, is {}", + msg.sol_in[73].sensor_type + ); + assert_eq!( + msg.sol_in[74].flags, 3, + "incorrect value for sol_in[74].flags, expected 3, is {}", + msg.sol_in[74].flags + ); + assert_eq!( + msg.sol_in[74].sensor_type, 59, + "incorrect value for sol_in[74].sensor_type, expected 59, is {}", + msg.sol_in[74].sensor_type + ); + assert_eq!( + msg.sol_in[75].flags, 52, + "incorrect value for sol_in[75].flags, expected 52, is {}", + msg.sol_in[75].flags + ); + assert_eq!( + msg.sol_in[75].sensor_type, 230, + "incorrect value for sol_in[75].sensor_type, expected 230, is {}", + msg.sol_in[75].sensor_type + ); + assert_eq!( + msg.sol_in[76].flags, 148, + "incorrect value for sol_in[76].flags, expected 148, is {}", + msg.sol_in[76].flags + ); + assert_eq!( + msg.sol_in[76].sensor_type, 149, + "incorrect value for sol_in[76].sensor_type, expected 149, is {}", + msg.sol_in[76].sensor_type + ); + assert_eq!( + msg.sol_in[77].flags, 142, + "incorrect value for sol_in[77].flags, expected 142, is {}", + msg.sol_in[77].flags + ); + assert_eq!( + msg.sol_in[77].sensor_type, 218, + "incorrect value for sol_in[77].sensor_type, expected 218, is {}", + msg.sol_in[77].sensor_type + ); + assert_eq!( + msg.sol_in[78].flags, 109, + "incorrect value for sol_in[78].flags, expected 109, is {}", + msg.sol_in[78].flags + ); + assert_eq!( + msg.sol_in[78].sensor_type, 212, + "incorrect value for sol_in[78].sensor_type, expected 212, is {}", + msg.sol_in[78].sensor_type + ); + assert_eq!( + msg.sol_in[79].flags, 71, + "incorrect value for sol_in[79].flags, expected 71, is {}", + msg.sol_in[79].flags + ); + assert_eq!( + msg.sol_in[79].sensor_type, 176, + "incorrect value for sol_in[79].sensor_type, expected 176, is {}", + msg.sol_in[79].sensor_type + ); + assert_eq!( + msg.sol_in[80].flags, 172, + "incorrect value for sol_in[80].flags, expected 172, is {}", + msg.sol_in[80].flags + ); + assert_eq!( + msg.sol_in[80].sensor_type, 179, + "incorrect value for sol_in[80].sensor_type, expected 179, is {}", + msg.sol_in[80].sensor_type + ); + assert_eq!( + msg.sol_in[81].flags, 1, + "incorrect value for sol_in[81].flags, expected 1, is {}", + msg.sol_in[81].flags + ); + assert_eq!( + msg.sol_in[81].sensor_type, 77, + "incorrect value for sol_in[81].sensor_type, expected 77, is {}", + msg.sol_in[81].sensor_type + ); + assert_eq!( + msg.sol_in[82].flags, 70, + "incorrect value for sol_in[82].flags, expected 70, is {}", + msg.sol_in[82].flags + ); + assert_eq!( + msg.sol_in[82].sensor_type, 193, + "incorrect value for sol_in[82].sensor_type, expected 193, is {}", + msg.sol_in[82].sensor_type + ); + assert_eq!( + msg.sol_in[83].flags, 149, + "incorrect value for sol_in[83].flags, expected 149, is {}", + msg.sol_in[83].flags + ); + assert_eq!( + msg.sol_in[83].sensor_type, 147, + "incorrect value for sol_in[83].sensor_type, expected 147, is {}", + msg.sol_in[83].sensor_type + ); + assert_eq!( + msg.sol_in[84].flags, 144, + "incorrect value for sol_in[84].flags, expected 144, is {}", + msg.sol_in[84].flags + ); + assert_eq!( + msg.sol_in[84].sensor_type, 23, + "incorrect value for sol_in[84].sensor_type, expected 23, is {}", + msg.sol_in[84].sensor_type + ); + assert_eq!( + msg.sol_in[85].flags, 239, + "incorrect value for sol_in[85].flags, expected 239, is {}", + msg.sol_in[85].flags + ); + assert_eq!( + msg.sol_in[85].sensor_type, 148, + "incorrect value for sol_in[85].sensor_type, expected 148, is {}", + msg.sol_in[85].sensor_type + ); + assert_eq!( + msg.sol_in[86].flags, 186, + "incorrect value for sol_in[86].flags, expected 186, is {}", + msg.sol_in[86].flags + ); + assert_eq!( + msg.sol_in[86].sensor_type, 195, + "incorrect value for sol_in[86].sensor_type, expected 195, is {}", + msg.sol_in[86].sensor_type + ); + assert_eq!( + msg.sol_in[87].flags, 30, + "incorrect value for sol_in[87].flags, expected 30, is {}", + msg.sol_in[87].flags + ); + assert_eq!( + msg.sol_in[87].sensor_type, 86, + "incorrect value for sol_in[87].sensor_type, expected 86, is {}", + msg.sol_in[87].sensor_type + ); + assert_eq!( + msg.sol_in[88].flags, 143, + "incorrect value for sol_in[88].flags, expected 143, is {}", + msg.sol_in[88].flags + ); + assert_eq!( + msg.sol_in[88].sensor_type, 34, + "incorrect value for sol_in[88].sensor_type, expected 34, is {}", + msg.sol_in[88].sensor_type + ); + assert_eq!( + msg.sol_in[89].flags, 207, + "incorrect value for sol_in[89].flags, expected 207, is {}", + msg.sol_in[89].flags + ); + assert_eq!( + msg.sol_in[89].sensor_type, 156, + "incorrect value for sol_in[89].sensor_type, expected 156, is {}", + msg.sol_in[89].sensor_type + ); + assert_eq!( + msg.sol_in[90].flags, 55, + "incorrect value for sol_in[90].flags, expected 55, is {}", + msg.sol_in[90].flags + ); + assert_eq!( + msg.sol_in[90].sensor_type, 63, + "incorrect value for sol_in[90].sensor_type, expected 63, is {}", + msg.sol_in[90].sensor_type + ); + assert_eq!( + msg.sol_in[91].flags, 255, + "incorrect value for sol_in[91].flags, expected 255, is {}", + msg.sol_in[91].flags + ); + assert_eq!( + msg.sol_in[91].sensor_type, 117, + "incorrect value for sol_in[91].sensor_type, expected 117, is {}", + msg.sol_in[91].sensor_type + ); + assert_eq!( + msg.sol_in[92].flags, 222, + "incorrect value for sol_in[92].flags, expected 222, is {}", + msg.sol_in[92].flags + ); + assert_eq!( + msg.sol_in[92].sensor_type, 222, + "incorrect value for sol_in[92].sensor_type, expected 222, is {}", + msg.sol_in[92].sensor_type + ); + assert_eq!( + msg.sol_in[93].flags, 145, + "incorrect value for sol_in[93].flags, expected 145, is {}", + msg.sol_in[93].flags + ); + assert_eq!( + msg.sol_in[93].sensor_type, 219, + "incorrect value for sol_in[93].sensor_type, expected 219, is {}", + msg.sol_in[93].sensor_type + ); + assert_eq!( + msg.sol_in[94].flags, 191, + "incorrect value for sol_in[94].flags, expected 191, is {}", + msg.sol_in[94].flags + ); + assert_eq!( + msg.sol_in[94].sensor_type, 224, + "incorrect value for sol_in[94].sensor_type, expected 224, is {}", + msg.sol_in[94].sensor_type + ); + assert_eq!( + msg.sol_in[95].flags, 109, + "incorrect value for sol_in[95].flags, expected 109, is {}", + msg.sol_in[95].flags + ); + assert_eq!( + msg.sol_in[95].sensor_type, 210, + "incorrect value for sol_in[95].sensor_type, expected 210, is {}", + msg.sol_in[95].sensor_type + ); + assert_eq!( + msg.sol_in[96].flags, 153, + "incorrect value for sol_in[96].flags, expected 153, is {}", + msg.sol_in[96].flags + ); + assert_eq!( + msg.sol_in[96].sensor_type, 86, + "incorrect value for sol_in[96].sensor_type, expected 86, is {}", + msg.sol_in[96].sensor_type + ); + assert_eq!( + msg.sol_in[97].flags, 32, + "incorrect value for sol_in[97].flags, expected 32, is {}", + msg.sol_in[97].flags + ); + assert_eq!( + msg.sol_in[97].sensor_type, 21, + "incorrect value for sol_in[97].sensor_type, expected 21, is {}", + msg.sol_in[97].sensor_type + ); + assert_eq!( + msg.sol_in[98].flags, 10, + "incorrect value for sol_in[98].flags, expected 10, is {}", + msg.sol_in[98].flags + ); + assert_eq!( + msg.sol_in[98].sensor_type, 226, + "incorrect value for sol_in[98].sensor_type, expected 226, is {}", + msg.sol_in[98].sensor_type + ); + assert_eq!( + msg.sol_in[99].flags, 63, + "incorrect value for sol_in[99].flags, expected 63, is {}", + msg.sol_in[99].flags + ); + assert_eq!( + msg.sol_in[99].sensor_type, 60, + "incorrect value for sol_in[99].sensor_type, expected 60, is {}", + msg.sol_in[99].sensor_type + ); + assert_eq!( + msg.sol_in[100].flags, 236, + "incorrect value for sol_in[100].flags, expected 236, is {}", + msg.sol_in[100].flags + ); + assert_eq!( + msg.sol_in[100].sensor_type, 106, + "incorrect value for sol_in[100].sensor_type, expected 106, is {}", + msg.sol_in[100].sensor_type + ); + assert_eq!( + msg.sol_in[101].flags, 96, + "incorrect value for sol_in[101].flags, expected 96, is {}", + msg.sol_in[101].flags + ); + assert_eq!( + msg.sol_in[101].sensor_type, 93, + "incorrect value for sol_in[101].sensor_type, expected 93, is {}", + msg.sol_in[101].sensor_type + ); + assert_eq!( + msg.sol_in[102].flags, 163, + "incorrect value for sol_in[102].flags, expected 163, is {}", + msg.sol_in[102].flags + ); + assert_eq!( + msg.sol_in[102].sensor_type, 30, + "incorrect value for sol_in[102].sensor_type, expected 30, is {}", + msg.sol_in[102].sensor_type + ); + assert_eq!( + msg.sol_in[103].flags, 238, + "incorrect value for sol_in[103].flags, expected 238, is {}", + msg.sol_in[103].flags + ); + assert_eq!( + msg.sol_in[103].sensor_type, 106, + "incorrect value for sol_in[103].sensor_type, expected 106, is {}", + msg.sol_in[103].sensor_type + ); + assert_eq!( + msg.sol_in[104].flags, 133, + "incorrect value for sol_in[104].flags, expected 133, is {}", + msg.sol_in[104].flags + ); + assert_eq!( + msg.sol_in[104].sensor_type, 147, + "incorrect value for sol_in[104].sensor_type, expected 147, is {}", + msg.sol_in[104].sensor_type + ); + assert_eq!( + msg.sol_in[105].flags, 107, + "incorrect value for sol_in[105].flags, expected 107, is {}", + msg.sol_in[105].flags + ); + assert_eq!( + msg.sol_in[105].sensor_type, 132, + "incorrect value for sol_in[105].sensor_type, expected 132, is {}", + msg.sol_in[105].sensor_type + ); + assert_eq!( + msg.sol_in[106].flags, 214, + "incorrect value for sol_in[106].flags, expected 214, is {}", + msg.sol_in[106].flags + ); + assert_eq!( + msg.sol_in[106].sensor_type, 152, + "incorrect value for sol_in[106].sensor_type, expected 152, is {}", + msg.sol_in[106].sensor_type + ); + assert_eq!( + msg.sol_in[107].flags, 185, + "incorrect value for sol_in[107].flags, expected 185, is {}", + msg.sol_in[107].flags + ); + assert_eq!( + msg.sol_in[107].sensor_type, 221, + "incorrect value for sol_in[107].sensor_type, expected 221, is {}", + msg.sol_in[107].sensor_type + ); + assert_eq!( + msg.sol_in[108].flags, 21, + "incorrect value for sol_in[108].flags, expected 21, is {}", + msg.sol_in[108].flags + ); + assert_eq!( + msg.sol_in[108].sensor_type, 202, + "incorrect value for sol_in[108].sensor_type, expected 202, is {}", + msg.sol_in[108].sensor_type + ); + assert_eq!( + msg.sol_in[109].flags, 51, + "incorrect value for sol_in[109].flags, expected 51, is {}", + msg.sol_in[109].flags + ); + assert_eq!( + msg.sol_in[109].sensor_type, 252, + "incorrect value for sol_in[109].sensor_type, expected 252, is {}", + msg.sol_in[109].sensor_type + ); + assert_eq!( + msg.sol_in[110].flags, 59, + "incorrect value for sol_in[110].flags, expected 59, is {}", + msg.sol_in[110].flags + ); + assert_eq!( + msg.sol_in[110].sensor_type, 130, + "incorrect value for sol_in[110].sensor_type, expected 130, is {}", + msg.sol_in[110].sensor_type + ); + assert_eq!( + msg.sol_in[111].flags, 202, + "incorrect value for sol_in[111].flags, expected 202, is {}", + msg.sol_in[111].flags + ); + assert_eq!( + msg.sol_in[111].sensor_type, 166, + "incorrect value for sol_in[111].sensor_type, expected 166, is {}", + msg.sol_in[111].sensor_type + ); + assert_eq!( + msg.sol_in[112].flags, 170, + "incorrect value for sol_in[112].flags, expected 170, is {}", + msg.sol_in[112].flags + ); + assert_eq!( + msg.sol_in[112].sensor_type, 127, + "incorrect value for sol_in[112].sensor_type, expected 127, is {}", + msg.sol_in[112].sensor_type + ); + assert_eq!( + msg.sol_in[113].flags, 193, + "incorrect value for sol_in[113].flags, expected 193, is {}", + msg.sol_in[113].flags + ); + assert_eq!( + msg.sol_in[113].sensor_type, 58, + "incorrect value for sol_in[113].sensor_type, expected 58, is {}", + msg.sol_in[113].sensor_type + ); + assert_eq!( + msg.sol_in[114].flags, 125, + "incorrect value for sol_in[114].flags, expected 125, is {}", + msg.sol_in[114].flags + ); + assert_eq!( + msg.sol_in[114].sensor_type, 215, + "incorrect value for sol_in[114].sensor_type, expected 215, is {}", + msg.sol_in[114].sensor_type + ); + assert_eq!( + msg.sol_in[115].flags, 58, + "incorrect value for sol_in[115].flags, expected 58, is {}", + msg.sol_in[115].flags + ); + assert_eq!( + msg.sol_in[115].sensor_type, 22, + "incorrect value for sol_in[115].sensor_type, expected 22, is {}", + msg.sol_in[115].sensor_type + ); + assert_eq!( + msg.sol_in[116].flags, 47, + "incorrect value for sol_in[116].flags, expected 47, is {}", + msg.sol_in[116].flags + ); + assert_eq!( + msg.sol_in[116].sensor_type, 135, + "incorrect value for sol_in[116].sensor_type, expected 135, is {}", + msg.sol_in[116].sensor_type + ); + assert_eq!( + msg.sol_in[117].flags, 142, + "incorrect value for sol_in[117].flags, expected 142, is {}", + msg.sol_in[117].flags + ); + assert_eq!( + msg.sol_in[117].sensor_type, 88, + "incorrect value for sol_in[117].sensor_type, expected 88, is {}", + msg.sol_in[117].sensor_type + ); + assert_eq!( + msg.vdop, 41989, + "incorrect value for vdop, expected 41989, is {}", + msg.vdop + ); + } + _ => panic!("Invalid message type! Expected a MsgSolnMetaDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_code_biases.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_code_biases.rs new file mode 100644 index 0000000000..73039c9874 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_code_biases.rs @@ -0,0 +1,2713 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_code_biases() { + { + let mut payload = Cursor::new(vec![ + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, 254, 132, 51, 4, 131, 240, + 120, 83, 148, 209, 213, 62, 228, 232, 71, 66, 188, 210, 128, 54, 131, 152, 129, 111, + 139, 242, 177, 145, 44, 9, 245, 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, + 98, 191, 23, 128, 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, 209, 139, 13, 101, 32, + 7, 18, 29, 70, 250, 109, 73, 202, 79, 144, 9, 146, 69, 241, 52, 22, 99, 98, 204, 3, + 171, 230, 180, 75, 62, 145, 86, 130, 31, 30, 155, 37, 18, 55, 210, 39, 127, 242, 66, + 13, 237, 152, 170, 212, 15, 246, 59, 94, 180, 195, 157, 69, 100, 119, 16, 68, 179, 175, + 144, 113, 81, 82, 30, 151, 21, 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, 6, 78, 81, + 143, 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, 247, 34, 97, 74, 97, 176, 48, + 236, 173, 12, 174, 101, 130, 30, 169, 193, 190, 204, 196, 123, 107, 25, 225, 74, 9, 10, + 55, 3, 131, 246, 99, 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, 10, + 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, 191, 120, 77, 192, 91, + 224, 1, 226, 50, 87, 146, 148, 238, 100, 179, 125, 227, 215, 104, 184, 31, 57, 90, 79, + 21, 156, 245, 81, 60, 93, 170, 60, 200, 167, 13, 125, 132, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrCodeBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e1, + "Incorrect message type, expected 0x5e1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5727, + "incorrect sender id, expected 0x5727, is {sender_id}" + ); + assert_eq!( + msg.biases[0].code, 51, + "incorrect value for biases[0].code, expected 51, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].value, -31996, + "incorrect value for biases[0].value, expected -31996, is {}", + msg.biases[0].value + ); + assert_eq!( + msg.biases[1].code, 240, + "incorrect value for biases[1].code, expected 240, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].value, 21368, + "incorrect value for biases[1].value, expected 21368, is {}", + msg.biases[1].value + ); + assert_eq!( + msg.biases[2].code, 148, + "incorrect value for biases[2].code, expected 148, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].value, -10799, + "incorrect value for biases[2].value, expected -10799, is {}", + msg.biases[2].value + ); + assert_eq!( + msg.biases[3].code, 62, + "incorrect value for biases[3].code, expected 62, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].value, -5916, + "incorrect value for biases[3].value, expected -5916, is {}", + msg.biases[3].value + ); + assert_eq!( + msg.biases[4].code, 71, + "incorrect value for biases[4].code, expected 71, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].value, -17342, + "incorrect value for biases[4].value, expected -17342, is {}", + msg.biases[4].value + ); + assert_eq!( + msg.biases[5].code, 210, + "incorrect value for biases[5].code, expected 210, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].value, 13952, + "incorrect value for biases[5].value, expected 13952, is {}", + msg.biases[5].value + ); + assert_eq!( + msg.biases[6].code, 131, + "incorrect value for biases[6].code, expected 131, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].value, -32360, + "incorrect value for biases[6].value, expected -32360, is {}", + msg.biases[6].value + ); + assert_eq!( + msg.biases[7].code, 111, + "incorrect value for biases[7].code, expected 111, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].value, -3445, + "incorrect value for biases[7].value, expected -3445, is {}", + msg.biases[7].value + ); + assert_eq!( + msg.biases[8].code, 177, + "incorrect value for biases[8].code, expected 177, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].value, 11409, + "incorrect value for biases[8].value, expected 11409, is {}", + msg.biases[8].value + ); + assert_eq!( + msg.biases[9].code, 9, + "incorrect value for biases[9].code, expected 9, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].value, -12299, + "incorrect value for biases[9].value, expected -12299, is {}", + msg.biases[9].value + ); + assert_eq!( + msg.biases[10].code, 241, + "incorrect value for biases[10].code, expected 241, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].value, -26934, + "incorrect value for biases[10].value, expected -26934, is {}", + msg.biases[10].value + ); + assert_eq!( + msg.biases[11].code, 141, + "incorrect value for biases[11].code, expected 141, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].value, -24782, + "incorrect value for biases[11].value, expected -24782, is {}", + msg.biases[11].value + ); + assert_eq!( + msg.biases[12].code, 220, + "incorrect value for biases[12].code, expected 220, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].value, 9611, + "incorrect value for biases[12].value, expected 9611, is {}", + msg.biases[12].value + ); + assert_eq!( + msg.biases[13].code, 187, + "incorrect value for biases[13].code, expected 187, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].value, -16542, + "incorrect value for biases[13].value, expected -16542, is {}", + msg.biases[13].value + ); + assert_eq!( + msg.biases[14].code, 23, + "incorrect value for biases[14].code, expected 23, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].value, -30592, + "incorrect value for biases[14].value, expected -30592, is {}", + msg.biases[14].value + ); + assert_eq!( + msg.biases[15].code, 167, + "incorrect value for biases[15].code, expected 167, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].value, 1736, + "incorrect value for biases[15].value, expected 1736, is {}", + msg.biases[15].value + ); + assert_eq!( + msg.biases[16].code, 211, + "incorrect value for biases[16].code, expected 211, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].value, 5978, + "incorrect value for biases[16].value, expected 5978, is {}", + msg.biases[16].value + ); + assert_eq!( + msg.biases[17].code, 244, + "incorrect value for biases[17].code, expected 244, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].value, -10358, + "incorrect value for biases[17].value, expected -10358, is {}", + msg.biases[17].value + ); + assert_eq!( + msg.biases[18].code, 209, + "incorrect value for biases[18].code, expected 209, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].value, 3467, + "incorrect value for biases[18].value, expected 3467, is {}", + msg.biases[18].value + ); + assert_eq!( + msg.biases[19].code, 101, + "incorrect value for biases[19].code, expected 101, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].value, 1824, + "incorrect value for biases[19].value, expected 1824, is {}", + msg.biases[19].value + ); + assert_eq!( + msg.biases[20].code, 18, + "incorrect value for biases[20].code, expected 18, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].value, 17949, + "incorrect value for biases[20].value, expected 17949, is {}", + msg.biases[20].value + ); + assert_eq!( + msg.biases[21].code, 250, + "incorrect value for biases[21].code, expected 250, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].value, 18797, + "incorrect value for biases[21].value, expected 18797, is {}", + msg.biases[21].value + ); + assert_eq!( + msg.biases[22].code, 202, + "incorrect value for biases[22].code, expected 202, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].value, -28593, + "incorrect value for biases[22].value, expected -28593, is {}", + msg.biases[22].value + ); + assert_eq!( + msg.biases[23].code, 9, + "incorrect value for biases[23].code, expected 9, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].value, 17810, + "incorrect value for biases[23].value, expected 17810, is {}", + msg.biases[23].value + ); + assert_eq!( + msg.biases[24].code, 241, + "incorrect value for biases[24].code, expected 241, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].value, 5684, + "incorrect value for biases[24].value, expected 5684, is {}", + msg.biases[24].value + ); + assert_eq!( + msg.biases[25].code, 99, + "incorrect value for biases[25].code, expected 99, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].value, -13214, + "incorrect value for biases[25].value, expected -13214, is {}", + msg.biases[25].value + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].value, -6485, + "incorrect value for biases[26].value, expected -6485, is {}", + msg.biases[26].value + ); + assert_eq!( + msg.biases[27].code, 180, + "incorrect value for biases[27].code, expected 180, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].value, 15947, + "incorrect value for biases[27].value, expected 15947, is {}", + msg.biases[27].value + ); + assert_eq!( + msg.biases[28].code, 145, + "incorrect value for biases[28].code, expected 145, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].value, -32170, + "incorrect value for biases[28].value, expected -32170, is {}", + msg.biases[28].value + ); + assert_eq!( + msg.biases[29].code, 31, + "incorrect value for biases[29].code, expected 31, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].value, -25826, + "incorrect value for biases[29].value, expected -25826, is {}", + msg.biases[29].value + ); + assert_eq!( + msg.biases[30].code, 37, + "incorrect value for biases[30].code, expected 37, is {}", + msg.biases[30].code + ); + assert_eq!( + msg.biases[30].value, 14098, + "incorrect value for biases[30].value, expected 14098, is {}", + msg.biases[30].value + ); + assert_eq!( + msg.biases[31].code, 210, + "incorrect value for biases[31].code, expected 210, is {}", + msg.biases[31].code + ); + assert_eq!( + msg.biases[31].value, 32551, + "incorrect value for biases[31].value, expected 32551, is {}", + msg.biases[31].value + ); + assert_eq!( + msg.biases[32].code, 242, + "incorrect value for biases[32].code, expected 242, is {}", + msg.biases[32].code + ); + assert_eq!( + msg.biases[32].value, 3394, + "incorrect value for biases[32].value, expected 3394, is {}", + msg.biases[32].value + ); + assert_eq!( + msg.biases[33].code, 237, + "incorrect value for biases[33].code, expected 237, is {}", + msg.biases[33].code + ); + assert_eq!( + msg.biases[33].value, -21864, + "incorrect value for biases[33].value, expected -21864, is {}", + msg.biases[33].value + ); + assert_eq!( + msg.biases[34].code, 212, + "incorrect value for biases[34].code, expected 212, is {}", + msg.biases[34].code + ); + assert_eq!( + msg.biases[34].value, -2545, + "incorrect value for biases[34].value, expected -2545, is {}", + msg.biases[34].value + ); + assert_eq!( + msg.biases[35].code, 59, + "incorrect value for biases[35].code, expected 59, is {}", + msg.biases[35].code + ); + assert_eq!( + msg.biases[35].value, -19362, + "incorrect value for biases[35].value, expected -19362, is {}", + msg.biases[35].value + ); + assert_eq!( + msg.biases[36].code, 195, + "incorrect value for biases[36].code, expected 195, is {}", + msg.biases[36].code + ); + assert_eq!( + msg.biases[36].value, 17821, + "incorrect value for biases[36].value, expected 17821, is {}", + msg.biases[36].value + ); + assert_eq!( + msg.biases[37].code, 100, + "incorrect value for biases[37].code, expected 100, is {}", + msg.biases[37].code + ); + assert_eq!( + msg.biases[37].value, 4215, + "incorrect value for biases[37].value, expected 4215, is {}", + msg.biases[37].value + ); + assert_eq!( + msg.biases[38].code, 68, + "incorrect value for biases[38].code, expected 68, is {}", + msg.biases[38].code + ); + assert_eq!( + msg.biases[38].value, -20557, + "incorrect value for biases[38].value, expected -20557, is {}", + msg.biases[38].value + ); + assert_eq!( + msg.biases[39].code, 144, + "incorrect value for biases[39].code, expected 144, is {}", + msg.biases[39].code + ); + assert_eq!( + msg.biases[39].value, 20849, + "incorrect value for biases[39].value, expected 20849, is {}", + msg.biases[39].value + ); + assert_eq!( + msg.biases[40].code, 82, + "incorrect value for biases[40].code, expected 82, is {}", + msg.biases[40].code + ); + assert_eq!( + msg.biases[40].value, -26850, + "incorrect value for biases[40].value, expected -26850, is {}", + msg.biases[40].value + ); + assert_eq!( + msg.biases[41].code, 21, + "incorrect value for biases[41].code, expected 21, is {}", + msg.biases[41].code + ); + assert_eq!( + msg.biases[41].value, 10605, + "incorrect value for biases[41].value, expected 10605, is {}", + msg.biases[41].value + ); + assert_eq!( + msg.biases[42].code, 225, + "incorrect value for biases[42].code, expected 225, is {}", + msg.biases[42].code + ); + assert_eq!( + msg.biases[42].value, 19720, + "incorrect value for biases[42].value, expected 19720, is {}", + msg.biases[42].value + ); + assert_eq!( + msg.biases[43].code, 164, + "incorrect value for biases[43].code, expected 164, is {}", + msg.biases[43].code + ); + assert_eq!( + msg.biases[43].value, 157, + "incorrect value for biases[43].value, expected 157, is {}", + msg.biases[43].value + ); + assert_eq!( + msg.biases[44].code, 73, + "incorrect value for biases[44].code, expected 73, is {}", + msg.biases[44].code + ); + assert_eq!( + msg.biases[44].value, 1566, + "incorrect value for biases[44].value, expected 1566, is {}", + msg.biases[44].value + ); + assert_eq!( + msg.biases[45].code, 78, + "incorrect value for biases[45].code, expected 78, is {}", + msg.biases[45].code + ); + assert_eq!( + msg.biases[45].value, -28847, + "incorrect value for biases[45].value, expected -28847, is {}", + msg.biases[45].value + ); + assert_eq!( + msg.biases[46].code, 116, + "incorrect value for biases[46].code, expected 116, is {}", + msg.biases[46].code + ); + assert_eq!( + msg.biases[46].value, -26640, + "incorrect value for biases[46].value, expected -26640, is {}", + msg.biases[46].value + ); + assert_eq!( + msg.biases[47].code, 55, + "incorrect value for biases[47].code, expected 55, is {}", + msg.biases[47].code + ); + assert_eq!( + msg.biases[47].value, -22087, + "incorrect value for biases[47].value, expected -22087, is {}", + msg.biases[47].value + ); + assert_eq!( + msg.biases[48].code, 254, + "incorrect value for biases[48].code, expected 254, is {}", + msg.biases[48].code + ); + assert_eq!( + msg.biases[48].value, 10035, + "incorrect value for biases[48].value, expected 10035, is {}", + msg.biases[48].value + ); + assert_eq!( + msg.biases[49].code, 74, + "incorrect value for biases[49].code, expected 74, is {}", + msg.biases[49].code + ); + assert_eq!( + msg.biases[49].value, -2129, + "incorrect value for biases[49].value, expected -2129, is {}", + msg.biases[49].value + ); + assert_eq!( + msg.biases[50].code, 34, + "incorrect value for biases[50].code, expected 34, is {}", + msg.biases[50].code + ); + assert_eq!( + msg.biases[50].value, 19041, + "incorrect value for biases[50].value, expected 19041, is {}", + msg.biases[50].value + ); + assert_eq!( + msg.biases[51].code, 97, + "incorrect value for biases[51].code, expected 97, is {}", + msg.biases[51].code + ); + assert_eq!( + msg.biases[51].value, 12464, + "incorrect value for biases[51].value, expected 12464, is {}", + msg.biases[51].value + ); + assert_eq!( + msg.biases[52].code, 236, + "incorrect value for biases[52].code, expected 236, is {}", + msg.biases[52].code + ); + assert_eq!( + msg.biases[52].value, 3245, + "incorrect value for biases[52].value, expected 3245, is {}", + msg.biases[52].value + ); + assert_eq!( + msg.biases[53].code, 174, + "incorrect value for biases[53].code, expected 174, is {}", + msg.biases[53].code + ); + assert_eq!( + msg.biases[53].value, -32155, + "incorrect value for biases[53].value, expected -32155, is {}", + msg.biases[53].value + ); + assert_eq!( + msg.biases[54].code, 30, + "incorrect value for biases[54].code, expected 30, is {}", + msg.biases[54].code + ); + assert_eq!( + msg.biases[54].value, -15959, + "incorrect value for biases[54].value, expected -15959, is {}", + msg.biases[54].value + ); + assert_eq!( + msg.biases[55].code, 190, + "incorrect value for biases[55].code, expected 190, is {}", + msg.biases[55].code + ); + assert_eq!( + msg.biases[55].value, -15156, + "incorrect value for biases[55].value, expected -15156, is {}", + msg.biases[55].value + ); + assert_eq!( + msg.biases[56].code, 123, + "incorrect value for biases[56].code, expected 123, is {}", + msg.biases[56].code + ); + assert_eq!( + msg.biases[56].value, 6507, + "incorrect value for biases[56].value, expected 6507, is {}", + msg.biases[56].value + ); + assert_eq!( + msg.biases[57].code, 225, + "incorrect value for biases[57].code, expected 225, is {}", + msg.biases[57].code + ); + assert_eq!( + msg.biases[57].value, 2378, + "incorrect value for biases[57].value, expected 2378, is {}", + msg.biases[57].value + ); + assert_eq!( + msg.biases[58].code, 10, + "incorrect value for biases[58].code, expected 10, is {}", + msg.biases[58].code + ); + assert_eq!( + msg.biases[58].value, 823, + "incorrect value for biases[58].value, expected 823, is {}", + msg.biases[58].value + ); + assert_eq!( + msg.biases[59].code, 131, + "incorrect value for biases[59].code, expected 131, is {}", + msg.biases[59].code + ); + assert_eq!( + msg.biases[59].value, 25590, + "incorrect value for biases[59].value, expected 25590, is {}", + msg.biases[59].value + ); + assert_eq!( + msg.biases[60].code, 133, + "incorrect value for biases[60].code, expected 133, is {}", + msg.biases[60].code + ); + assert_eq!( + msg.biases[60].value, -7390, + "incorrect value for biases[60].value, expected -7390, is {}", + msg.biases[60].value + ); + assert_eq!( + msg.biases[61].code, 203, + "incorrect value for biases[61].code, expected 203, is {}", + msg.biases[61].code + ); + assert_eq!( + msg.biases[61].value, 4676, + "incorrect value for biases[61].value, expected 4676, is {}", + msg.biases[61].value + ); + assert_eq!( + msg.biases[62].code, 97, + "incorrect value for biases[62].code, expected 97, is {}", + msg.biases[62].code + ); + assert_eq!( + msg.biases[62].value, 23007, + "incorrect value for biases[62].value, expected 23007, is {}", + msg.biases[62].value + ); + assert_eq!( + msg.biases[63].code, 192, + "incorrect value for biases[63].code, expected 192, is {}", + msg.biases[63].code + ); + assert_eq!( + msg.biases[63].value, 13046, + "incorrect value for biases[63].value, expected 13046, is {}", + msg.biases[63].value + ); + assert_eq!( + msg.biases[64].code, 69, + "incorrect value for biases[64].code, expected 69, is {}", + msg.biases[64].code + ); + assert_eq!( + msg.biases[64].value, 2651, + "incorrect value for biases[64].value, expected 2651, is {}", + msg.biases[64].value + ); + assert_eq!( + msg.biases[65].code, 151, + "incorrect value for biases[65].code, expected 151, is {}", + msg.biases[65].code + ); + assert_eq!( + msg.biases[65].value, 30282, + "incorrect value for biases[65].value, expected 30282, is {}", + msg.biases[65].value + ); + assert_eq!( + msg.biases[66].code, 110, + "incorrect value for biases[66].code, expected 110, is {}", + msg.biases[66].code + ); + assert_eq!( + msg.biases[66].value, -22492, + "incorrect value for biases[66].value, expected -22492, is {}", + msg.biases[66].value + ); + assert_eq!( + msg.biases[67].code, 247, + "incorrect value for biases[67].code, expected 247, is {}", + msg.biases[67].code + ); + assert_eq!( + msg.biases[67].value, 19872, + "incorrect value for biases[67].value, expected 19872, is {}", + msg.biases[67].value + ); + assert_eq!( + msg.biases[68].code, 179, + "incorrect value for biases[68].code, expected 179, is {}", + msg.biases[68].code + ); + assert_eq!( + msg.biases[68].value, -19827, + "incorrect value for biases[68].value, expected -19827, is {}", + msg.biases[68].value + ); + assert_eq!( + msg.biases[69].code, 99, + "incorrect value for biases[69].code, expected 99, is {}", + msg.biases[69].code + ); + assert_eq!( + msg.biases[69].value, 30911, + "incorrect value for biases[69].value, expected 30911, is {}", + msg.biases[69].value + ); + assert_eq!( + msg.biases[70].code, 77, + "incorrect value for biases[70].code, expected 77, is {}", + msg.biases[70].code + ); + assert_eq!( + msg.biases[70].value, 23488, + "incorrect value for biases[70].value, expected 23488, is {}", + msg.biases[70].value + ); + assert_eq!( + msg.biases[71].code, 224, + "incorrect value for biases[71].code, expected 224, is {}", + msg.biases[71].code + ); + assert_eq!( + msg.biases[71].value, -7679, + "incorrect value for biases[71].value, expected -7679, is {}", + msg.biases[71].value + ); + assert_eq!( + msg.biases[72].code, 50, + "incorrect value for biases[72].code, expected 50, is {}", + msg.biases[72].code + ); + assert_eq!( + msg.biases[72].value, -28073, + "incorrect value for biases[72].value, expected -28073, is {}", + msg.biases[72].value + ); + assert_eq!( + msg.biases[73].code, 148, + "incorrect value for biases[73].code, expected 148, is {}", + msg.biases[73].code + ); + assert_eq!( + msg.biases[73].value, 25838, + "incorrect value for biases[73].value, expected 25838, is {}", + msg.biases[73].value + ); + assert_eq!( + msg.biases[74].code, 179, + "incorrect value for biases[74].code, expected 179, is {}", + msg.biases[74].code + ); + assert_eq!( + msg.biases[74].value, -7299, + "incorrect value for biases[74].value, expected -7299, is {}", + msg.biases[74].value + ); + assert_eq!( + msg.biases[75].code, 215, + "incorrect value for biases[75].code, expected 215, is {}", + msg.biases[75].code + ); + assert_eq!( + msg.biases[75].value, -18328, + "incorrect value for biases[75].value, expected -18328, is {}", + msg.biases[75].value + ); + assert_eq!( + msg.biases[76].code, 31, + "incorrect value for biases[76].code, expected 31, is {}", + msg.biases[76].code + ); + assert_eq!( + msg.biases[76].value, 23097, + "incorrect value for biases[76].value, expected 23097, is {}", + msg.biases[76].value + ); + assert_eq!( + msg.biases[77].code, 79, + "incorrect value for biases[77].code, expected 79, is {}", + msg.biases[77].code + ); + assert_eq!( + msg.biases[77].value, -25579, + "incorrect value for biases[77].value, expected -25579, is {}", + msg.biases[77].value + ); + assert_eq!( + msg.biases[78].code, 245, + "incorrect value for biases[78].code, expected 245, is {}", + msg.biases[78].code + ); + assert_eq!( + msg.biases[78].value, 15441, + "incorrect value for biases[78].value, expected 15441, is {}", + msg.biases[78].value + ); + assert_eq!( + msg.biases[79].code, 93, + "incorrect value for biases[79].code, expected 93, is {}", + msg.biases[79].code + ); + assert_eq!( + msg.biases[79].value, 15530, + "incorrect value for biases[79].value, expected 15530, is {}", + msg.biases[79].value + ); + assert_eq!( + msg.biases[80].code, 200, + "incorrect value for biases[80].code, expected 200, is {}", + msg.biases[80].code + ); + assert_eq!( + msg.biases[80].value, 3495, + "incorrect value for biases[80].value, expected 3495, is {}", + msg.biases[80].value + ); + assert_eq!( + msg.iod_ssr, 132, + "incorrect value for iod_ssr, expected 132, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.sid.code, 241, + "incorrect value for sid.code, expected 241, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 133, + "incorrect value for sid.sat, expected 133, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 387144400, + "incorrect value for time.tow, expected 387144400, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 16905, + "incorrect value for time.wn, expected 16905, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 254, + "incorrect value for update_interval, expected 254, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrCodeBiases"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_code_biases() { + { + let json_input = r#"{"crc":33917,"length":253,"msg_type":1505,"payload":"0FoTFwlChfH+hDMEg/B4U5TR1T7k6EdCvNKANoOYgW+L8rGRLAn1z/HKlo0yn9yLJbtivxeAiKfIBtNaF/SK19GLDWUgBxIdRvptScpPkAmSRfE0FmNizAOr5rRLPpFWgh8emyUSN9Inf/JCDe2YqtQP9jtetMOdRWR3EESzr5BxUVIelxVtKeEITaSdAEkeBk5Rj3Twlze5qf4zJ0qv9yJhSmGwMOytDK5lgh6pwb7MxHtrGeFKCQo3A4P2Y4Ui48tEEmHfWcD2MkVbCpdKdm4kqPegTbONsmO/eE3AW+AB4jJXkpTuZLN949douB85Wk8VnPVRPF2qPMinDQ==","preamble":85,"sender":22311,"time":{"tow":387144400,"wn":16905},"sid":{"sat":133,"code":241},"update_interval":254,"iod_ssr":132,"biases":[{"code":51,"value":-31996},{"code":240,"value":21368},{"code":148,"value":-10799},{"code":62,"value":-5916},{"code":71,"value":-17342},{"code":210,"value":13952},{"code":131,"value":-32360},{"code":111,"value":-3445},{"code":177,"value":11409},{"code":9,"value":-12299},{"code":241,"value":-26934},{"code":141,"value":-24782},{"code":220,"value":9611},{"code":187,"value":-16542},{"code":23,"value":-30592},{"code":167,"value":1736},{"code":211,"value":5978},{"code":244,"value":-10358},{"code":209,"value":3467},{"code":101,"value":1824},{"code":18,"value":17949},{"code":250,"value":18797},{"code":202,"value":-28593},{"code":9,"value":17810},{"code":241,"value":5684},{"code":99,"value":-13214},{"code":3,"value":-6485},{"code":180,"value":15947},{"code":145,"value":-32170},{"code":31,"value":-25826},{"code":37,"value":14098},{"code":210,"value":32551},{"code":242,"value":3394},{"code":237,"value":-21864},{"code":212,"value":-2545},{"code":59,"value":-19362},{"code":195,"value":17821},{"code":100,"value":4215},{"code":68,"value":-20557},{"code":144,"value":20849},{"code":82,"value":-26850},{"code":21,"value":10605},{"code":225,"value":19720},{"code":164,"value":157},{"code":73,"value":1566},{"code":78,"value":-28847},{"code":116,"value":-26640},{"code":55,"value":-22087},{"code":254,"value":10035},{"code":74,"value":-2129},{"code":34,"value":19041},{"code":97,"value":12464},{"code":236,"value":3245},{"code":174,"value":-32155},{"code":30,"value":-15959},{"code":190,"value":-15156},{"code":123,"value":6507},{"code":225,"value":2378},{"code":10,"value":823},{"code":131,"value":25590},{"code":133,"value":-7390},{"code":203,"value":4676},{"code":97,"value":23007},{"code":192,"value":13046},{"code":69,"value":2651},{"code":151,"value":30282},{"code":110,"value":-22492},{"code":247,"value":19872},{"code":179,"value":-19827},{"code":99,"value":30911},{"code":77,"value":23488},{"code":224,"value":-7679},{"code":50,"value":-28073},{"code":148,"value":25838},{"code":179,"value":-7299},{"code":215,"value":-18328},{"code":31,"value":23097},{"code":79,"value":-25579},{"code":245,"value":15441},{"code":93,"value":15530},{"code":200,"value":3495}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrCodeBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e1, + "Incorrect message type, expected 0x5e1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5727, + "incorrect sender id, expected 0x5727, is {sender_id}" + ); + assert_eq!( + msg.biases[0].code, 51, + "incorrect value for biases[0].code, expected 51, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].value, -31996, + "incorrect value for biases[0].value, expected -31996, is {}", + msg.biases[0].value + ); + assert_eq!( + msg.biases[1].code, 240, + "incorrect value for biases[1].code, expected 240, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].value, 21368, + "incorrect value for biases[1].value, expected 21368, is {}", + msg.biases[1].value + ); + assert_eq!( + msg.biases[2].code, 148, + "incorrect value for biases[2].code, expected 148, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].value, -10799, + "incorrect value for biases[2].value, expected -10799, is {}", + msg.biases[2].value + ); + assert_eq!( + msg.biases[3].code, 62, + "incorrect value for biases[3].code, expected 62, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].value, -5916, + "incorrect value for biases[3].value, expected -5916, is {}", + msg.biases[3].value + ); + assert_eq!( + msg.biases[4].code, 71, + "incorrect value for biases[4].code, expected 71, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].value, -17342, + "incorrect value for biases[4].value, expected -17342, is {}", + msg.biases[4].value + ); + assert_eq!( + msg.biases[5].code, 210, + "incorrect value for biases[5].code, expected 210, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].value, 13952, + "incorrect value for biases[5].value, expected 13952, is {}", + msg.biases[5].value + ); + assert_eq!( + msg.biases[6].code, 131, + "incorrect value for biases[6].code, expected 131, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].value, -32360, + "incorrect value for biases[6].value, expected -32360, is {}", + msg.biases[6].value + ); + assert_eq!( + msg.biases[7].code, 111, + "incorrect value for biases[7].code, expected 111, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].value, -3445, + "incorrect value for biases[7].value, expected -3445, is {}", + msg.biases[7].value + ); + assert_eq!( + msg.biases[8].code, 177, + "incorrect value for biases[8].code, expected 177, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].value, 11409, + "incorrect value for biases[8].value, expected 11409, is {}", + msg.biases[8].value + ); + assert_eq!( + msg.biases[9].code, 9, + "incorrect value for biases[9].code, expected 9, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].value, -12299, + "incorrect value for biases[9].value, expected -12299, is {}", + msg.biases[9].value + ); + assert_eq!( + msg.biases[10].code, 241, + "incorrect value for biases[10].code, expected 241, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].value, -26934, + "incorrect value for biases[10].value, expected -26934, is {}", + msg.biases[10].value + ); + assert_eq!( + msg.biases[11].code, 141, + "incorrect value for biases[11].code, expected 141, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].value, -24782, + "incorrect value for biases[11].value, expected -24782, is {}", + msg.biases[11].value + ); + assert_eq!( + msg.biases[12].code, 220, + "incorrect value for biases[12].code, expected 220, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].value, 9611, + "incorrect value for biases[12].value, expected 9611, is {}", + msg.biases[12].value + ); + assert_eq!( + msg.biases[13].code, 187, + "incorrect value for biases[13].code, expected 187, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].value, -16542, + "incorrect value for biases[13].value, expected -16542, is {}", + msg.biases[13].value + ); + assert_eq!( + msg.biases[14].code, 23, + "incorrect value for biases[14].code, expected 23, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].value, -30592, + "incorrect value for biases[14].value, expected -30592, is {}", + msg.biases[14].value + ); + assert_eq!( + msg.biases[15].code, 167, + "incorrect value for biases[15].code, expected 167, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].value, 1736, + "incorrect value for biases[15].value, expected 1736, is {}", + msg.biases[15].value + ); + assert_eq!( + msg.biases[16].code, 211, + "incorrect value for biases[16].code, expected 211, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].value, 5978, + "incorrect value for biases[16].value, expected 5978, is {}", + msg.biases[16].value + ); + assert_eq!( + msg.biases[17].code, 244, + "incorrect value for biases[17].code, expected 244, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].value, -10358, + "incorrect value for biases[17].value, expected -10358, is {}", + msg.biases[17].value + ); + assert_eq!( + msg.biases[18].code, 209, + "incorrect value for biases[18].code, expected 209, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].value, 3467, + "incorrect value for biases[18].value, expected 3467, is {}", + msg.biases[18].value + ); + assert_eq!( + msg.biases[19].code, 101, + "incorrect value for biases[19].code, expected 101, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].value, 1824, + "incorrect value for biases[19].value, expected 1824, is {}", + msg.biases[19].value + ); + assert_eq!( + msg.biases[20].code, 18, + "incorrect value for biases[20].code, expected 18, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].value, 17949, + "incorrect value for biases[20].value, expected 17949, is {}", + msg.biases[20].value + ); + assert_eq!( + msg.biases[21].code, 250, + "incorrect value for biases[21].code, expected 250, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].value, 18797, + "incorrect value for biases[21].value, expected 18797, is {}", + msg.biases[21].value + ); + assert_eq!( + msg.biases[22].code, 202, + "incorrect value for biases[22].code, expected 202, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].value, -28593, + "incorrect value for biases[22].value, expected -28593, is {}", + msg.biases[22].value + ); + assert_eq!( + msg.biases[23].code, 9, + "incorrect value for biases[23].code, expected 9, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].value, 17810, + "incorrect value for biases[23].value, expected 17810, is {}", + msg.biases[23].value + ); + assert_eq!( + msg.biases[24].code, 241, + "incorrect value for biases[24].code, expected 241, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].value, 5684, + "incorrect value for biases[24].value, expected 5684, is {}", + msg.biases[24].value + ); + assert_eq!( + msg.biases[25].code, 99, + "incorrect value for biases[25].code, expected 99, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].value, -13214, + "incorrect value for biases[25].value, expected -13214, is {}", + msg.biases[25].value + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].value, -6485, + "incorrect value for biases[26].value, expected -6485, is {}", + msg.biases[26].value + ); + assert_eq!( + msg.biases[27].code, 180, + "incorrect value for biases[27].code, expected 180, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].value, 15947, + "incorrect value for biases[27].value, expected 15947, is {}", + msg.biases[27].value + ); + assert_eq!( + msg.biases[28].code, 145, + "incorrect value for biases[28].code, expected 145, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].value, -32170, + "incorrect value for biases[28].value, expected -32170, is {}", + msg.biases[28].value + ); + assert_eq!( + msg.biases[29].code, 31, + "incorrect value for biases[29].code, expected 31, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].value, -25826, + "incorrect value for biases[29].value, expected -25826, is {}", + msg.biases[29].value + ); + assert_eq!( + msg.biases[30].code, 37, + "incorrect value for biases[30].code, expected 37, is {}", + msg.biases[30].code + ); + assert_eq!( + msg.biases[30].value, 14098, + "incorrect value for biases[30].value, expected 14098, is {}", + msg.biases[30].value + ); + assert_eq!( + msg.biases[31].code, 210, + "incorrect value for biases[31].code, expected 210, is {}", + msg.biases[31].code + ); + assert_eq!( + msg.biases[31].value, 32551, + "incorrect value for biases[31].value, expected 32551, is {}", + msg.biases[31].value + ); + assert_eq!( + msg.biases[32].code, 242, + "incorrect value for biases[32].code, expected 242, is {}", + msg.biases[32].code + ); + assert_eq!( + msg.biases[32].value, 3394, + "incorrect value for biases[32].value, expected 3394, is {}", + msg.biases[32].value + ); + assert_eq!( + msg.biases[33].code, 237, + "incorrect value for biases[33].code, expected 237, is {}", + msg.biases[33].code + ); + assert_eq!( + msg.biases[33].value, -21864, + "incorrect value for biases[33].value, expected -21864, is {}", + msg.biases[33].value + ); + assert_eq!( + msg.biases[34].code, 212, + "incorrect value for biases[34].code, expected 212, is {}", + msg.biases[34].code + ); + assert_eq!( + msg.biases[34].value, -2545, + "incorrect value for biases[34].value, expected -2545, is {}", + msg.biases[34].value + ); + assert_eq!( + msg.biases[35].code, 59, + "incorrect value for biases[35].code, expected 59, is {}", + msg.biases[35].code + ); + assert_eq!( + msg.biases[35].value, -19362, + "incorrect value for biases[35].value, expected -19362, is {}", + msg.biases[35].value + ); + assert_eq!( + msg.biases[36].code, 195, + "incorrect value for biases[36].code, expected 195, is {}", + msg.biases[36].code + ); + assert_eq!( + msg.biases[36].value, 17821, + "incorrect value for biases[36].value, expected 17821, is {}", + msg.biases[36].value + ); + assert_eq!( + msg.biases[37].code, 100, + "incorrect value for biases[37].code, expected 100, is {}", + msg.biases[37].code + ); + assert_eq!( + msg.biases[37].value, 4215, + "incorrect value for biases[37].value, expected 4215, is {}", + msg.biases[37].value + ); + assert_eq!( + msg.biases[38].code, 68, + "incorrect value for biases[38].code, expected 68, is {}", + msg.biases[38].code + ); + assert_eq!( + msg.biases[38].value, -20557, + "incorrect value for biases[38].value, expected -20557, is {}", + msg.biases[38].value + ); + assert_eq!( + msg.biases[39].code, 144, + "incorrect value for biases[39].code, expected 144, is {}", + msg.biases[39].code + ); + assert_eq!( + msg.biases[39].value, 20849, + "incorrect value for biases[39].value, expected 20849, is {}", + msg.biases[39].value + ); + assert_eq!( + msg.biases[40].code, 82, + "incorrect value for biases[40].code, expected 82, is {}", + msg.biases[40].code + ); + assert_eq!( + msg.biases[40].value, -26850, + "incorrect value for biases[40].value, expected -26850, is {}", + msg.biases[40].value + ); + assert_eq!( + msg.biases[41].code, 21, + "incorrect value for biases[41].code, expected 21, is {}", + msg.biases[41].code + ); + assert_eq!( + msg.biases[41].value, 10605, + "incorrect value for biases[41].value, expected 10605, is {}", + msg.biases[41].value + ); + assert_eq!( + msg.biases[42].code, 225, + "incorrect value for biases[42].code, expected 225, is {}", + msg.biases[42].code + ); + assert_eq!( + msg.biases[42].value, 19720, + "incorrect value for biases[42].value, expected 19720, is {}", + msg.biases[42].value + ); + assert_eq!( + msg.biases[43].code, 164, + "incorrect value for biases[43].code, expected 164, is {}", + msg.biases[43].code + ); + assert_eq!( + msg.biases[43].value, 157, + "incorrect value for biases[43].value, expected 157, is {}", + msg.biases[43].value + ); + assert_eq!( + msg.biases[44].code, 73, + "incorrect value for biases[44].code, expected 73, is {}", + msg.biases[44].code + ); + assert_eq!( + msg.biases[44].value, 1566, + "incorrect value for biases[44].value, expected 1566, is {}", + msg.biases[44].value + ); + assert_eq!( + msg.biases[45].code, 78, + "incorrect value for biases[45].code, expected 78, is {}", + msg.biases[45].code + ); + assert_eq!( + msg.biases[45].value, -28847, + "incorrect value for biases[45].value, expected -28847, is {}", + msg.biases[45].value + ); + assert_eq!( + msg.biases[46].code, 116, + "incorrect value for biases[46].code, expected 116, is {}", + msg.biases[46].code + ); + assert_eq!( + msg.biases[46].value, -26640, + "incorrect value for biases[46].value, expected -26640, is {}", + msg.biases[46].value + ); + assert_eq!( + msg.biases[47].code, 55, + "incorrect value for biases[47].code, expected 55, is {}", + msg.biases[47].code + ); + assert_eq!( + msg.biases[47].value, -22087, + "incorrect value for biases[47].value, expected -22087, is {}", + msg.biases[47].value + ); + assert_eq!( + msg.biases[48].code, 254, + "incorrect value for biases[48].code, expected 254, is {}", + msg.biases[48].code + ); + assert_eq!( + msg.biases[48].value, 10035, + "incorrect value for biases[48].value, expected 10035, is {}", + msg.biases[48].value + ); + assert_eq!( + msg.biases[49].code, 74, + "incorrect value for biases[49].code, expected 74, is {}", + msg.biases[49].code + ); + assert_eq!( + msg.biases[49].value, -2129, + "incorrect value for biases[49].value, expected -2129, is {}", + msg.biases[49].value + ); + assert_eq!( + msg.biases[50].code, 34, + "incorrect value for biases[50].code, expected 34, is {}", + msg.biases[50].code + ); + assert_eq!( + msg.biases[50].value, 19041, + "incorrect value for biases[50].value, expected 19041, is {}", + msg.biases[50].value + ); + assert_eq!( + msg.biases[51].code, 97, + "incorrect value for biases[51].code, expected 97, is {}", + msg.biases[51].code + ); + assert_eq!( + msg.biases[51].value, 12464, + "incorrect value for biases[51].value, expected 12464, is {}", + msg.biases[51].value + ); + assert_eq!( + msg.biases[52].code, 236, + "incorrect value for biases[52].code, expected 236, is {}", + msg.biases[52].code + ); + assert_eq!( + msg.biases[52].value, 3245, + "incorrect value for biases[52].value, expected 3245, is {}", + msg.biases[52].value + ); + assert_eq!( + msg.biases[53].code, 174, + "incorrect value for biases[53].code, expected 174, is {}", + msg.biases[53].code + ); + assert_eq!( + msg.biases[53].value, -32155, + "incorrect value for biases[53].value, expected -32155, is {}", + msg.biases[53].value + ); + assert_eq!( + msg.biases[54].code, 30, + "incorrect value for biases[54].code, expected 30, is {}", + msg.biases[54].code + ); + assert_eq!( + msg.biases[54].value, -15959, + "incorrect value for biases[54].value, expected -15959, is {}", + msg.biases[54].value + ); + assert_eq!( + msg.biases[55].code, 190, + "incorrect value for biases[55].code, expected 190, is {}", + msg.biases[55].code + ); + assert_eq!( + msg.biases[55].value, -15156, + "incorrect value for biases[55].value, expected -15156, is {}", + msg.biases[55].value + ); + assert_eq!( + msg.biases[56].code, 123, + "incorrect value for biases[56].code, expected 123, is {}", + msg.biases[56].code + ); + assert_eq!( + msg.biases[56].value, 6507, + "incorrect value for biases[56].value, expected 6507, is {}", + msg.biases[56].value + ); + assert_eq!( + msg.biases[57].code, 225, + "incorrect value for biases[57].code, expected 225, is {}", + msg.biases[57].code + ); + assert_eq!( + msg.biases[57].value, 2378, + "incorrect value for biases[57].value, expected 2378, is {}", + msg.biases[57].value + ); + assert_eq!( + msg.biases[58].code, 10, + "incorrect value for biases[58].code, expected 10, is {}", + msg.biases[58].code + ); + assert_eq!( + msg.biases[58].value, 823, + "incorrect value for biases[58].value, expected 823, is {}", + msg.biases[58].value + ); + assert_eq!( + msg.biases[59].code, 131, + "incorrect value for biases[59].code, expected 131, is {}", + msg.biases[59].code + ); + assert_eq!( + msg.biases[59].value, 25590, + "incorrect value for biases[59].value, expected 25590, is {}", + msg.biases[59].value + ); + assert_eq!( + msg.biases[60].code, 133, + "incorrect value for biases[60].code, expected 133, is {}", + msg.biases[60].code + ); + assert_eq!( + msg.biases[60].value, -7390, + "incorrect value for biases[60].value, expected -7390, is {}", + msg.biases[60].value + ); + assert_eq!( + msg.biases[61].code, 203, + "incorrect value for biases[61].code, expected 203, is {}", + msg.biases[61].code + ); + assert_eq!( + msg.biases[61].value, 4676, + "incorrect value for biases[61].value, expected 4676, is {}", + msg.biases[61].value + ); + assert_eq!( + msg.biases[62].code, 97, + "incorrect value for biases[62].code, expected 97, is {}", + msg.biases[62].code + ); + assert_eq!( + msg.biases[62].value, 23007, + "incorrect value for biases[62].value, expected 23007, is {}", + msg.biases[62].value + ); + assert_eq!( + msg.biases[63].code, 192, + "incorrect value for biases[63].code, expected 192, is {}", + msg.biases[63].code + ); + assert_eq!( + msg.biases[63].value, 13046, + "incorrect value for biases[63].value, expected 13046, is {}", + msg.biases[63].value + ); + assert_eq!( + msg.biases[64].code, 69, + "incorrect value for biases[64].code, expected 69, is {}", + msg.biases[64].code + ); + assert_eq!( + msg.biases[64].value, 2651, + "incorrect value for biases[64].value, expected 2651, is {}", + msg.biases[64].value + ); + assert_eq!( + msg.biases[65].code, 151, + "incorrect value for biases[65].code, expected 151, is {}", + msg.biases[65].code + ); + assert_eq!( + msg.biases[65].value, 30282, + "incorrect value for biases[65].value, expected 30282, is {}", + msg.biases[65].value + ); + assert_eq!( + msg.biases[66].code, 110, + "incorrect value for biases[66].code, expected 110, is {}", + msg.biases[66].code + ); + assert_eq!( + msg.biases[66].value, -22492, + "incorrect value for biases[66].value, expected -22492, is {}", + msg.biases[66].value + ); + assert_eq!( + msg.biases[67].code, 247, + "incorrect value for biases[67].code, expected 247, is {}", + msg.biases[67].code + ); + assert_eq!( + msg.biases[67].value, 19872, + "incorrect value for biases[67].value, expected 19872, is {}", + msg.biases[67].value + ); + assert_eq!( + msg.biases[68].code, 179, + "incorrect value for biases[68].code, expected 179, is {}", + msg.biases[68].code + ); + assert_eq!( + msg.biases[68].value, -19827, + "incorrect value for biases[68].value, expected -19827, is {}", + msg.biases[68].value + ); + assert_eq!( + msg.biases[69].code, 99, + "incorrect value for biases[69].code, expected 99, is {}", + msg.biases[69].code + ); + assert_eq!( + msg.biases[69].value, 30911, + "incorrect value for biases[69].value, expected 30911, is {}", + msg.biases[69].value + ); + assert_eq!( + msg.biases[70].code, 77, + "incorrect value for biases[70].code, expected 77, is {}", + msg.biases[70].code + ); + assert_eq!( + msg.biases[70].value, 23488, + "incorrect value for biases[70].value, expected 23488, is {}", + msg.biases[70].value + ); + assert_eq!( + msg.biases[71].code, 224, + "incorrect value for biases[71].code, expected 224, is {}", + msg.biases[71].code + ); + assert_eq!( + msg.biases[71].value, -7679, + "incorrect value for biases[71].value, expected -7679, is {}", + msg.biases[71].value + ); + assert_eq!( + msg.biases[72].code, 50, + "incorrect value for biases[72].code, expected 50, is {}", + msg.biases[72].code + ); + assert_eq!( + msg.biases[72].value, -28073, + "incorrect value for biases[72].value, expected -28073, is {}", + msg.biases[72].value + ); + assert_eq!( + msg.biases[73].code, 148, + "incorrect value for biases[73].code, expected 148, is {}", + msg.biases[73].code + ); + assert_eq!( + msg.biases[73].value, 25838, + "incorrect value for biases[73].value, expected 25838, is {}", + msg.biases[73].value + ); + assert_eq!( + msg.biases[74].code, 179, + "incorrect value for biases[74].code, expected 179, is {}", + msg.biases[74].code + ); + assert_eq!( + msg.biases[74].value, -7299, + "incorrect value for biases[74].value, expected -7299, is {}", + msg.biases[74].value + ); + assert_eq!( + msg.biases[75].code, 215, + "incorrect value for biases[75].code, expected 215, is {}", + msg.biases[75].code + ); + assert_eq!( + msg.biases[75].value, -18328, + "incorrect value for biases[75].value, expected -18328, is {}", + msg.biases[75].value + ); + assert_eq!( + msg.biases[76].code, 31, + "incorrect value for biases[76].code, expected 31, is {}", + msg.biases[76].code + ); + assert_eq!( + msg.biases[76].value, 23097, + "incorrect value for biases[76].value, expected 23097, is {}", + msg.biases[76].value + ); + assert_eq!( + msg.biases[77].code, 79, + "incorrect value for biases[77].code, expected 79, is {}", + msg.biases[77].code + ); + assert_eq!( + msg.biases[77].value, -25579, + "incorrect value for biases[77].value, expected -25579, is {}", + msg.biases[77].value + ); + assert_eq!( + msg.biases[78].code, 245, + "incorrect value for biases[78].code, expected 245, is {}", + msg.biases[78].code + ); + assert_eq!( + msg.biases[78].value, 15441, + "incorrect value for biases[78].value, expected 15441, is {}", + msg.biases[78].value + ); + assert_eq!( + msg.biases[79].code, 93, + "incorrect value for biases[79].code, expected 93, is {}", + msg.biases[79].code + ); + assert_eq!( + msg.biases[79].value, 15530, + "incorrect value for biases[79].value, expected 15530, is {}", + msg.biases[79].value + ); + assert_eq!( + msg.biases[80].code, 200, + "incorrect value for biases[80].code, expected 200, is {}", + msg.biases[80].code + ); + assert_eq!( + msg.biases[80].value, 3495, + "incorrect value for biases[80].value, expected 3495, is {}", + msg.biases[80].value + ); + assert_eq!( + msg.iod_ssr, 132, + "incorrect value for iod_ssr, expected 132, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.sid.code, 241, + "incorrect value for sid.code, expected 241, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 133, + "incorrect value for sid.sat, expected 133, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 387144400, + "incorrect value for time.tow, expected 387144400, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 16905, + "incorrect value for time.wn, expected 16905, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 254, + "incorrect value for update_interval, expected 254, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrCodeBiases"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_code_biases`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_code_biases() { + { + let mut payload = Cursor::new(vec![ + 85, 225, 5, 39, 87, 253, 208, 90, 19, 23, 9, 66, 133, 241, 254, 132, 51, 4, 131, 240, + 120, 83, 148, 209, 213, 62, 228, 232, 71, 66, 188, 210, 128, 54, 131, 152, 129, 111, + 139, 242, 177, 145, 44, 9, 245, 207, 241, 202, 150, 141, 50, 159, 220, 139, 37, 187, + 98, 191, 23, 128, 136, 167, 200, 6, 211, 90, 23, 244, 138, 215, 209, 139, 13, 101, 32, + 7, 18, 29, 70, 250, 109, 73, 202, 79, 144, 9, 146, 69, 241, 52, 22, 99, 98, 204, 3, + 171, 230, 180, 75, 62, 145, 86, 130, 31, 30, 155, 37, 18, 55, 210, 39, 127, 242, 66, + 13, 237, 152, 170, 212, 15, 246, 59, 94, 180, 195, 157, 69, 100, 119, 16, 68, 179, 175, + 144, 113, 81, 82, 30, 151, 21, 109, 41, 225, 8, 77, 164, 157, 0, 73, 30, 6, 78, 81, + 143, 116, 240, 151, 55, 185, 169, 254, 51, 39, 74, 175, 247, 34, 97, 74, 97, 176, 48, + 236, 173, 12, 174, 101, 130, 30, 169, 193, 190, 204, 196, 123, 107, 25, 225, 74, 9, 10, + 55, 3, 131, 246, 99, 133, 34, 227, 203, 68, 18, 97, 223, 89, 192, 246, 50, 69, 91, 10, + 151, 74, 118, 110, 36, 168, 247, 160, 77, 179, 141, 178, 99, 191, 120, 77, 192, 91, + 224, 1, 226, 50, 87, 146, 148, 238, 100, 179, 125, 227, 215, 104, 184, 31, 57, 90, 79, + 21, 156, 245, 81, 60, 93, 170, 60, 200, 167, 13, 125, 132, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrCodeBiases( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrCodeBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e1, + "Incorrect message type, expected 0x5e1, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5727, + "incorrect sender id, expected 0x5727, is {sender_id}" + ); + assert_eq!( + msg.biases[0].code, 51, + "incorrect value for biases[0].code, expected 51, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].value, -31996, + "incorrect value for biases[0].value, expected -31996, is {}", + msg.biases[0].value + ); + assert_eq!( + msg.biases[1].code, 240, + "incorrect value for biases[1].code, expected 240, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].value, 21368, + "incorrect value for biases[1].value, expected 21368, is {}", + msg.biases[1].value + ); + assert_eq!( + msg.biases[2].code, 148, + "incorrect value for biases[2].code, expected 148, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].value, -10799, + "incorrect value for biases[2].value, expected -10799, is {}", + msg.biases[2].value + ); + assert_eq!( + msg.biases[3].code, 62, + "incorrect value for biases[3].code, expected 62, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].value, -5916, + "incorrect value for biases[3].value, expected -5916, is {}", + msg.biases[3].value + ); + assert_eq!( + msg.biases[4].code, 71, + "incorrect value for biases[4].code, expected 71, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].value, -17342, + "incorrect value for biases[4].value, expected -17342, is {}", + msg.biases[4].value + ); + assert_eq!( + msg.biases[5].code, 210, + "incorrect value for biases[5].code, expected 210, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].value, 13952, + "incorrect value for biases[5].value, expected 13952, is {}", + msg.biases[5].value + ); + assert_eq!( + msg.biases[6].code, 131, + "incorrect value for biases[6].code, expected 131, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].value, -32360, + "incorrect value for biases[6].value, expected -32360, is {}", + msg.biases[6].value + ); + assert_eq!( + msg.biases[7].code, 111, + "incorrect value for biases[7].code, expected 111, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].value, -3445, + "incorrect value for biases[7].value, expected -3445, is {}", + msg.biases[7].value + ); + assert_eq!( + msg.biases[8].code, 177, + "incorrect value for biases[8].code, expected 177, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].value, 11409, + "incorrect value for biases[8].value, expected 11409, is {}", + msg.biases[8].value + ); + assert_eq!( + msg.biases[9].code, 9, + "incorrect value for biases[9].code, expected 9, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].value, -12299, + "incorrect value for biases[9].value, expected -12299, is {}", + msg.biases[9].value + ); + assert_eq!( + msg.biases[10].code, 241, + "incorrect value for biases[10].code, expected 241, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].value, -26934, + "incorrect value for biases[10].value, expected -26934, is {}", + msg.biases[10].value + ); + assert_eq!( + msg.biases[11].code, 141, + "incorrect value for biases[11].code, expected 141, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].value, -24782, + "incorrect value for biases[11].value, expected -24782, is {}", + msg.biases[11].value + ); + assert_eq!( + msg.biases[12].code, 220, + "incorrect value for biases[12].code, expected 220, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].value, 9611, + "incorrect value for biases[12].value, expected 9611, is {}", + msg.biases[12].value + ); + assert_eq!( + msg.biases[13].code, 187, + "incorrect value for biases[13].code, expected 187, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].value, -16542, + "incorrect value for biases[13].value, expected -16542, is {}", + msg.biases[13].value + ); + assert_eq!( + msg.biases[14].code, 23, + "incorrect value for biases[14].code, expected 23, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].value, -30592, + "incorrect value for biases[14].value, expected -30592, is {}", + msg.biases[14].value + ); + assert_eq!( + msg.biases[15].code, 167, + "incorrect value for biases[15].code, expected 167, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].value, 1736, + "incorrect value for biases[15].value, expected 1736, is {}", + msg.biases[15].value + ); + assert_eq!( + msg.biases[16].code, 211, + "incorrect value for biases[16].code, expected 211, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].value, 5978, + "incorrect value for biases[16].value, expected 5978, is {}", + msg.biases[16].value + ); + assert_eq!( + msg.biases[17].code, 244, + "incorrect value for biases[17].code, expected 244, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].value, -10358, + "incorrect value for biases[17].value, expected -10358, is {}", + msg.biases[17].value + ); + assert_eq!( + msg.biases[18].code, 209, + "incorrect value for biases[18].code, expected 209, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].value, 3467, + "incorrect value for biases[18].value, expected 3467, is {}", + msg.biases[18].value + ); + assert_eq!( + msg.biases[19].code, 101, + "incorrect value for biases[19].code, expected 101, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].value, 1824, + "incorrect value for biases[19].value, expected 1824, is {}", + msg.biases[19].value + ); + assert_eq!( + msg.biases[20].code, 18, + "incorrect value for biases[20].code, expected 18, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].value, 17949, + "incorrect value for biases[20].value, expected 17949, is {}", + msg.biases[20].value + ); + assert_eq!( + msg.biases[21].code, 250, + "incorrect value for biases[21].code, expected 250, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].value, 18797, + "incorrect value for biases[21].value, expected 18797, is {}", + msg.biases[21].value + ); + assert_eq!( + msg.biases[22].code, 202, + "incorrect value for biases[22].code, expected 202, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].value, -28593, + "incorrect value for biases[22].value, expected -28593, is {}", + msg.biases[22].value + ); + assert_eq!( + msg.biases[23].code, 9, + "incorrect value for biases[23].code, expected 9, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].value, 17810, + "incorrect value for biases[23].value, expected 17810, is {}", + msg.biases[23].value + ); + assert_eq!( + msg.biases[24].code, 241, + "incorrect value for biases[24].code, expected 241, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].value, 5684, + "incorrect value for biases[24].value, expected 5684, is {}", + msg.biases[24].value + ); + assert_eq!( + msg.biases[25].code, 99, + "incorrect value for biases[25].code, expected 99, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].value, -13214, + "incorrect value for biases[25].value, expected -13214, is {}", + msg.biases[25].value + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].value, -6485, + "incorrect value for biases[26].value, expected -6485, is {}", + msg.biases[26].value + ); + assert_eq!( + msg.biases[27].code, 180, + "incorrect value for biases[27].code, expected 180, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].value, 15947, + "incorrect value for biases[27].value, expected 15947, is {}", + msg.biases[27].value + ); + assert_eq!( + msg.biases[28].code, 145, + "incorrect value for biases[28].code, expected 145, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].value, -32170, + "incorrect value for biases[28].value, expected -32170, is {}", + msg.biases[28].value + ); + assert_eq!( + msg.biases[29].code, 31, + "incorrect value for biases[29].code, expected 31, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].value, -25826, + "incorrect value for biases[29].value, expected -25826, is {}", + msg.biases[29].value + ); + assert_eq!( + msg.biases[30].code, 37, + "incorrect value for biases[30].code, expected 37, is {}", + msg.biases[30].code + ); + assert_eq!( + msg.biases[30].value, 14098, + "incorrect value for biases[30].value, expected 14098, is {}", + msg.biases[30].value + ); + assert_eq!( + msg.biases[31].code, 210, + "incorrect value for biases[31].code, expected 210, is {}", + msg.biases[31].code + ); + assert_eq!( + msg.biases[31].value, 32551, + "incorrect value for biases[31].value, expected 32551, is {}", + msg.biases[31].value + ); + assert_eq!( + msg.biases[32].code, 242, + "incorrect value for biases[32].code, expected 242, is {}", + msg.biases[32].code + ); + assert_eq!( + msg.biases[32].value, 3394, + "incorrect value for biases[32].value, expected 3394, is {}", + msg.biases[32].value + ); + assert_eq!( + msg.biases[33].code, 237, + "incorrect value for biases[33].code, expected 237, is {}", + msg.biases[33].code + ); + assert_eq!( + msg.biases[33].value, -21864, + "incorrect value for biases[33].value, expected -21864, is {}", + msg.biases[33].value + ); + assert_eq!( + msg.biases[34].code, 212, + "incorrect value for biases[34].code, expected 212, is {}", + msg.biases[34].code + ); + assert_eq!( + msg.biases[34].value, -2545, + "incorrect value for biases[34].value, expected -2545, is {}", + msg.biases[34].value + ); + assert_eq!( + msg.biases[35].code, 59, + "incorrect value for biases[35].code, expected 59, is {}", + msg.biases[35].code + ); + assert_eq!( + msg.biases[35].value, -19362, + "incorrect value for biases[35].value, expected -19362, is {}", + msg.biases[35].value + ); + assert_eq!( + msg.biases[36].code, 195, + "incorrect value for biases[36].code, expected 195, is {}", + msg.biases[36].code + ); + assert_eq!( + msg.biases[36].value, 17821, + "incorrect value for biases[36].value, expected 17821, is {}", + msg.biases[36].value + ); + assert_eq!( + msg.biases[37].code, 100, + "incorrect value for biases[37].code, expected 100, is {}", + msg.biases[37].code + ); + assert_eq!( + msg.biases[37].value, 4215, + "incorrect value for biases[37].value, expected 4215, is {}", + msg.biases[37].value + ); + assert_eq!( + msg.biases[38].code, 68, + "incorrect value for biases[38].code, expected 68, is {}", + msg.biases[38].code + ); + assert_eq!( + msg.biases[38].value, -20557, + "incorrect value for biases[38].value, expected -20557, is {}", + msg.biases[38].value + ); + assert_eq!( + msg.biases[39].code, 144, + "incorrect value for biases[39].code, expected 144, is {}", + msg.biases[39].code + ); + assert_eq!( + msg.biases[39].value, 20849, + "incorrect value for biases[39].value, expected 20849, is {}", + msg.biases[39].value + ); + assert_eq!( + msg.biases[40].code, 82, + "incorrect value for biases[40].code, expected 82, is {}", + msg.biases[40].code + ); + assert_eq!( + msg.biases[40].value, -26850, + "incorrect value for biases[40].value, expected -26850, is {}", + msg.biases[40].value + ); + assert_eq!( + msg.biases[41].code, 21, + "incorrect value for biases[41].code, expected 21, is {}", + msg.biases[41].code + ); + assert_eq!( + msg.biases[41].value, 10605, + "incorrect value for biases[41].value, expected 10605, is {}", + msg.biases[41].value + ); + assert_eq!( + msg.biases[42].code, 225, + "incorrect value for biases[42].code, expected 225, is {}", + msg.biases[42].code + ); + assert_eq!( + msg.biases[42].value, 19720, + "incorrect value for biases[42].value, expected 19720, is {}", + msg.biases[42].value + ); + assert_eq!( + msg.biases[43].code, 164, + "incorrect value for biases[43].code, expected 164, is {}", + msg.biases[43].code + ); + assert_eq!( + msg.biases[43].value, 157, + "incorrect value for biases[43].value, expected 157, is {}", + msg.biases[43].value + ); + assert_eq!( + msg.biases[44].code, 73, + "incorrect value for biases[44].code, expected 73, is {}", + msg.biases[44].code + ); + assert_eq!( + msg.biases[44].value, 1566, + "incorrect value for biases[44].value, expected 1566, is {}", + msg.biases[44].value + ); + assert_eq!( + msg.biases[45].code, 78, + "incorrect value for biases[45].code, expected 78, is {}", + msg.biases[45].code + ); + assert_eq!( + msg.biases[45].value, -28847, + "incorrect value for biases[45].value, expected -28847, is {}", + msg.biases[45].value + ); + assert_eq!( + msg.biases[46].code, 116, + "incorrect value for biases[46].code, expected 116, is {}", + msg.biases[46].code + ); + assert_eq!( + msg.biases[46].value, -26640, + "incorrect value for biases[46].value, expected -26640, is {}", + msg.biases[46].value + ); + assert_eq!( + msg.biases[47].code, 55, + "incorrect value for biases[47].code, expected 55, is {}", + msg.biases[47].code + ); + assert_eq!( + msg.biases[47].value, -22087, + "incorrect value for biases[47].value, expected -22087, is {}", + msg.biases[47].value + ); + assert_eq!( + msg.biases[48].code, 254, + "incorrect value for biases[48].code, expected 254, is {}", + msg.biases[48].code + ); + assert_eq!( + msg.biases[48].value, 10035, + "incorrect value for biases[48].value, expected 10035, is {}", + msg.biases[48].value + ); + assert_eq!( + msg.biases[49].code, 74, + "incorrect value for biases[49].code, expected 74, is {}", + msg.biases[49].code + ); + assert_eq!( + msg.biases[49].value, -2129, + "incorrect value for biases[49].value, expected -2129, is {}", + msg.biases[49].value + ); + assert_eq!( + msg.biases[50].code, 34, + "incorrect value for biases[50].code, expected 34, is {}", + msg.biases[50].code + ); + assert_eq!( + msg.biases[50].value, 19041, + "incorrect value for biases[50].value, expected 19041, is {}", + msg.biases[50].value + ); + assert_eq!( + msg.biases[51].code, 97, + "incorrect value for biases[51].code, expected 97, is {}", + msg.biases[51].code + ); + assert_eq!( + msg.biases[51].value, 12464, + "incorrect value for biases[51].value, expected 12464, is {}", + msg.biases[51].value + ); + assert_eq!( + msg.biases[52].code, 236, + "incorrect value for biases[52].code, expected 236, is {}", + msg.biases[52].code + ); + assert_eq!( + msg.biases[52].value, 3245, + "incorrect value for biases[52].value, expected 3245, is {}", + msg.biases[52].value + ); + assert_eq!( + msg.biases[53].code, 174, + "incorrect value for biases[53].code, expected 174, is {}", + msg.biases[53].code + ); + assert_eq!( + msg.biases[53].value, -32155, + "incorrect value for biases[53].value, expected -32155, is {}", + msg.biases[53].value + ); + assert_eq!( + msg.biases[54].code, 30, + "incorrect value for biases[54].code, expected 30, is {}", + msg.biases[54].code + ); + assert_eq!( + msg.biases[54].value, -15959, + "incorrect value for biases[54].value, expected -15959, is {}", + msg.biases[54].value + ); + assert_eq!( + msg.biases[55].code, 190, + "incorrect value for biases[55].code, expected 190, is {}", + msg.biases[55].code + ); + assert_eq!( + msg.biases[55].value, -15156, + "incorrect value for biases[55].value, expected -15156, is {}", + msg.biases[55].value + ); + assert_eq!( + msg.biases[56].code, 123, + "incorrect value for biases[56].code, expected 123, is {}", + msg.biases[56].code + ); + assert_eq!( + msg.biases[56].value, 6507, + "incorrect value for biases[56].value, expected 6507, is {}", + msg.biases[56].value + ); + assert_eq!( + msg.biases[57].code, 225, + "incorrect value for biases[57].code, expected 225, is {}", + msg.biases[57].code + ); + assert_eq!( + msg.biases[57].value, 2378, + "incorrect value for biases[57].value, expected 2378, is {}", + msg.biases[57].value + ); + assert_eq!( + msg.biases[58].code, 10, + "incorrect value for biases[58].code, expected 10, is {}", + msg.biases[58].code + ); + assert_eq!( + msg.biases[58].value, 823, + "incorrect value for biases[58].value, expected 823, is {}", + msg.biases[58].value + ); + assert_eq!( + msg.biases[59].code, 131, + "incorrect value for biases[59].code, expected 131, is {}", + msg.biases[59].code + ); + assert_eq!( + msg.biases[59].value, 25590, + "incorrect value for biases[59].value, expected 25590, is {}", + msg.biases[59].value + ); + assert_eq!( + msg.biases[60].code, 133, + "incorrect value for biases[60].code, expected 133, is {}", + msg.biases[60].code + ); + assert_eq!( + msg.biases[60].value, -7390, + "incorrect value for biases[60].value, expected -7390, is {}", + msg.biases[60].value + ); + assert_eq!( + msg.biases[61].code, 203, + "incorrect value for biases[61].code, expected 203, is {}", + msg.biases[61].code + ); + assert_eq!( + msg.biases[61].value, 4676, + "incorrect value for biases[61].value, expected 4676, is {}", + msg.biases[61].value + ); + assert_eq!( + msg.biases[62].code, 97, + "incorrect value for biases[62].code, expected 97, is {}", + msg.biases[62].code + ); + assert_eq!( + msg.biases[62].value, 23007, + "incorrect value for biases[62].value, expected 23007, is {}", + msg.biases[62].value + ); + assert_eq!( + msg.biases[63].code, 192, + "incorrect value for biases[63].code, expected 192, is {}", + msg.biases[63].code + ); + assert_eq!( + msg.biases[63].value, 13046, + "incorrect value for biases[63].value, expected 13046, is {}", + msg.biases[63].value + ); + assert_eq!( + msg.biases[64].code, 69, + "incorrect value for biases[64].code, expected 69, is {}", + msg.biases[64].code + ); + assert_eq!( + msg.biases[64].value, 2651, + "incorrect value for biases[64].value, expected 2651, is {}", + msg.biases[64].value + ); + assert_eq!( + msg.biases[65].code, 151, + "incorrect value for biases[65].code, expected 151, is {}", + msg.biases[65].code + ); + assert_eq!( + msg.biases[65].value, 30282, + "incorrect value for biases[65].value, expected 30282, is {}", + msg.biases[65].value + ); + assert_eq!( + msg.biases[66].code, 110, + "incorrect value for biases[66].code, expected 110, is {}", + msg.biases[66].code + ); + assert_eq!( + msg.biases[66].value, -22492, + "incorrect value for biases[66].value, expected -22492, is {}", + msg.biases[66].value + ); + assert_eq!( + msg.biases[67].code, 247, + "incorrect value for biases[67].code, expected 247, is {}", + msg.biases[67].code + ); + assert_eq!( + msg.biases[67].value, 19872, + "incorrect value for biases[67].value, expected 19872, is {}", + msg.biases[67].value + ); + assert_eq!( + msg.biases[68].code, 179, + "incorrect value for biases[68].code, expected 179, is {}", + msg.biases[68].code + ); + assert_eq!( + msg.biases[68].value, -19827, + "incorrect value for biases[68].value, expected -19827, is {}", + msg.biases[68].value + ); + assert_eq!( + msg.biases[69].code, 99, + "incorrect value for biases[69].code, expected 99, is {}", + msg.biases[69].code + ); + assert_eq!( + msg.biases[69].value, 30911, + "incorrect value for biases[69].value, expected 30911, is {}", + msg.biases[69].value + ); + assert_eq!( + msg.biases[70].code, 77, + "incorrect value for biases[70].code, expected 77, is {}", + msg.biases[70].code + ); + assert_eq!( + msg.biases[70].value, 23488, + "incorrect value for biases[70].value, expected 23488, is {}", + msg.biases[70].value + ); + assert_eq!( + msg.biases[71].code, 224, + "incorrect value for biases[71].code, expected 224, is {}", + msg.biases[71].code + ); + assert_eq!( + msg.biases[71].value, -7679, + "incorrect value for biases[71].value, expected -7679, is {}", + msg.biases[71].value + ); + assert_eq!( + msg.biases[72].code, 50, + "incorrect value for biases[72].code, expected 50, is {}", + msg.biases[72].code + ); + assert_eq!( + msg.biases[72].value, -28073, + "incorrect value for biases[72].value, expected -28073, is {}", + msg.biases[72].value + ); + assert_eq!( + msg.biases[73].code, 148, + "incorrect value for biases[73].code, expected 148, is {}", + msg.biases[73].code + ); + assert_eq!( + msg.biases[73].value, 25838, + "incorrect value for biases[73].value, expected 25838, is {}", + msg.biases[73].value + ); + assert_eq!( + msg.biases[74].code, 179, + "incorrect value for biases[74].code, expected 179, is {}", + msg.biases[74].code + ); + assert_eq!( + msg.biases[74].value, -7299, + "incorrect value for biases[74].value, expected -7299, is {}", + msg.biases[74].value + ); + assert_eq!( + msg.biases[75].code, 215, + "incorrect value for biases[75].code, expected 215, is {}", + msg.biases[75].code + ); + assert_eq!( + msg.biases[75].value, -18328, + "incorrect value for biases[75].value, expected -18328, is {}", + msg.biases[75].value + ); + assert_eq!( + msg.biases[76].code, 31, + "incorrect value for biases[76].code, expected 31, is {}", + msg.biases[76].code + ); + assert_eq!( + msg.biases[76].value, 23097, + "incorrect value for biases[76].value, expected 23097, is {}", + msg.biases[76].value + ); + assert_eq!( + msg.biases[77].code, 79, + "incorrect value for biases[77].code, expected 79, is {}", + msg.biases[77].code + ); + assert_eq!( + msg.biases[77].value, -25579, + "incorrect value for biases[77].value, expected -25579, is {}", + msg.biases[77].value + ); + assert_eq!( + msg.biases[78].code, 245, + "incorrect value for biases[78].code, expected 245, is {}", + msg.biases[78].code + ); + assert_eq!( + msg.biases[78].value, 15441, + "incorrect value for biases[78].value, expected 15441, is {}", + msg.biases[78].value + ); + assert_eq!( + msg.biases[79].code, 93, + "incorrect value for biases[79].code, expected 93, is {}", + msg.biases[79].code + ); + assert_eq!( + msg.biases[79].value, 15530, + "incorrect value for biases[79].value, expected 15530, is {}", + msg.biases[79].value + ); + assert_eq!( + msg.biases[80].code, 200, + "incorrect value for biases[80].code, expected 200, is {}", + msg.biases[80].code + ); + assert_eq!( + msg.biases[80].value, 3495, + "incorrect value for biases[80].value, expected 3495, is {}", + msg.biases[80].value + ); + assert_eq!( + msg.iod_ssr, 132, + "incorrect value for iod_ssr, expected 132, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.sid.code, 241, + "incorrect value for sid.code, expected 241, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 133, + "incorrect value for sid.sat, expected 133, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 387144400, + "incorrect value for time.tow, expected 387144400, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 16905, + "incorrect value for time.wn, expected 16905, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 254, + "incorrect value for update_interval, expected 254, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrCodeBiases"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a.rs new file mode 100644 index 0000000000..bd1d89ade5 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a.rs @@ -0,0 +1,3973 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, 52, 92, 104, 25, 204, + 182, 22, 98, 203, 123, 211, 38, 13, 253, 129, 173, 171, 235, 253, 26, 203, 3, 120, 126, + 42, 44, 39, 87, 69, 154, 13, 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, 57, 120, + 243, 151, 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, 144, 158, 239, 90, 56, 71, + 120, 67, 221, 114, 10, 190, 4, 230, 164, 171, 78, 185, 90, 46, 177, 82, 228, 123, 222, + 227, 145, 195, 219, 27, 56, 227, 246, 215, 144, 158, 31, 214, 241, 254, 200, 86, 142, + 89, 12, 121, 29, 124, 9, 19, 153, 44, 35, 126, 14, 217, 65, 116, 26, 139, 122, 114, 90, + 124, 81, 0, 186, 246, 46, 98, 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, 42, 150, + 221, 102, 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, 128, 193, 53, 94, 99, 63, + 182, 2, 186, 220, 77, 186, 224, 220, 13, 212, 182, 88, 15, 151, 5, 93, 251, 164, 18, + 228, 168, 226, 195, 44, 170, 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, + 159, 189, 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, 19, 151, 136, + 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, 212, 68, 60, 206, 106, 207, 243, + 158, 94, 6, 3, 205, 92, 84, 2, 220, 50, 61, 38, 141, 117, 108, 101, 76, 139, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGridDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f5, + "Incorrect message type, expected 0x5f5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf7b5, + "incorrect sender id, expected 0xf7b5, is {sender_id}" + ); + assert_eq!( + msg.header.area_width, 43860, + "incorrect value for header.area_width, expected 43860, is {}", + msg.header.area_width + ); + assert_eq!( + msg.header.lat_nw_corner_enc, 34021, + "incorrect value for header.lat_nw_corner_enc, expected 34021, is {}", + msg.header.lat_nw_corner_enc + ); + assert_eq!( + msg.header.lon_nw_corner_enc, 11919, + "incorrect value for header.lon_nw_corner_enc, expected 11919, is {}", + msg.header.lon_nw_corner_enc + ); + assert_eq!( + msg.header.num_msgs, 204, + "incorrect value for header.num_msgs, expected 204, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.region_size_inverse, 11, + "incorrect value for header.region_size_inverse, expected 11, is {}", + msg.header.region_size_inverse + ); + assert_eq!( + msg.header.seq_num, 52, + "incorrect value for header.seq_num, expected 52, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.rle_list[0], 92, + "incorrect value for rle_list[0], expected 92, is {}", + msg.rle_list[0] + ); + assert_eq!( + msg.rle_list[1], 104, + "incorrect value for rle_list[1], expected 104, is {}", + msg.rle_list[1] + ); + assert_eq!( + msg.rle_list[2], 25, + "incorrect value for rle_list[2], expected 25, is {}", + msg.rle_list[2] + ); + assert_eq!( + msg.rle_list[3], 204, + "incorrect value for rle_list[3], expected 204, is {}", + msg.rle_list[3] + ); + assert_eq!( + msg.rle_list[4], 182, + "incorrect value for rle_list[4], expected 182, is {}", + msg.rle_list[4] + ); + assert_eq!( + msg.rle_list[5], 22, + "incorrect value for rle_list[5], expected 22, is {}", + msg.rle_list[5] + ); + assert_eq!( + msg.rle_list[6], 98, + "incorrect value for rle_list[6], expected 98, is {}", + msg.rle_list[6] + ); + assert_eq!( + msg.rle_list[7], 203, + "incorrect value for rle_list[7], expected 203, is {}", + msg.rle_list[7] + ); + assert_eq!( + msg.rle_list[8], 123, + "incorrect value for rle_list[8], expected 123, is {}", + msg.rle_list[8] + ); + assert_eq!( + msg.rle_list[9], 211, + "incorrect value for rle_list[9], expected 211, is {}", + msg.rle_list[9] + ); + assert_eq!( + msg.rle_list[10], 38, + "incorrect value for rle_list[10], expected 38, is {}", + msg.rle_list[10] + ); + assert_eq!( + msg.rle_list[11], 13, + "incorrect value for rle_list[11], expected 13, is {}", + msg.rle_list[11] + ); + assert_eq!( + msg.rle_list[12], 253, + "incorrect value for rle_list[12], expected 253, is {}", + msg.rle_list[12] + ); + assert_eq!( + msg.rle_list[13], 129, + "incorrect value for rle_list[13], expected 129, is {}", + msg.rle_list[13] + ); + assert_eq!( + msg.rle_list[14], 173, + "incorrect value for rle_list[14], expected 173, is {}", + msg.rle_list[14] + ); + assert_eq!( + msg.rle_list[15], 171, + "incorrect value for rle_list[15], expected 171, is {}", + msg.rle_list[15] + ); + assert_eq!( + msg.rle_list[16], 235, + "incorrect value for rle_list[16], expected 235, is {}", + msg.rle_list[16] + ); + assert_eq!( + msg.rle_list[17], 253, + "incorrect value for rle_list[17], expected 253, is {}", + msg.rle_list[17] + ); + assert_eq!( + msg.rle_list[18], 26, + "incorrect value for rle_list[18], expected 26, is {}", + msg.rle_list[18] + ); + assert_eq!( + msg.rle_list[19], 203, + "incorrect value for rle_list[19], expected 203, is {}", + msg.rle_list[19] + ); + assert_eq!( + msg.rle_list[20], 3, + "incorrect value for rle_list[20], expected 3, is {}", + msg.rle_list[20] + ); + assert_eq!( + msg.rle_list[21], 120, + "incorrect value for rle_list[21], expected 120, is {}", + msg.rle_list[21] + ); + assert_eq!( + msg.rle_list[22], 126, + "incorrect value for rle_list[22], expected 126, is {}", + msg.rle_list[22] + ); + assert_eq!( + msg.rle_list[23], 42, + "incorrect value for rle_list[23], expected 42, is {}", + msg.rle_list[23] + ); + assert_eq!( + msg.rle_list[24], 44, + "incorrect value for rle_list[24], expected 44, is {}", + msg.rle_list[24] + ); + assert_eq!( + msg.rle_list[25], 39, + "incorrect value for rle_list[25], expected 39, is {}", + msg.rle_list[25] + ); + assert_eq!( + msg.rle_list[26], 87, + "incorrect value for rle_list[26], expected 87, is {}", + msg.rle_list[26] + ); + assert_eq!( + msg.rle_list[27], 69, + "incorrect value for rle_list[27], expected 69, is {}", + msg.rle_list[27] + ); + assert_eq!( + msg.rle_list[28], 154, + "incorrect value for rle_list[28], expected 154, is {}", + msg.rle_list[28] + ); + assert_eq!( + msg.rle_list[29], 13, + "incorrect value for rle_list[29], expected 13, is {}", + msg.rle_list[29] + ); + assert_eq!( + msg.rle_list[30], 28, + "incorrect value for rle_list[30], expected 28, is {}", + msg.rle_list[30] + ); + assert_eq!( + msg.rle_list[31], 179, + "incorrect value for rle_list[31], expected 179, is {}", + msg.rle_list[31] + ); + assert_eq!( + msg.rle_list[32], 32, + "incorrect value for rle_list[32], expected 32, is {}", + msg.rle_list[32] + ); + assert_eq!( + msg.rle_list[33], 47, + "incorrect value for rle_list[33], expected 47, is {}", + msg.rle_list[33] + ); + assert_eq!( + msg.rle_list[34], 36, + "incorrect value for rle_list[34], expected 36, is {}", + msg.rle_list[34] + ); + assert_eq!( + msg.rle_list[35], 195, + "incorrect value for rle_list[35], expected 195, is {}", + msg.rle_list[35] + ); + assert_eq!( + msg.rle_list[36], 39, + "incorrect value for rle_list[36], expected 39, is {}", + msg.rle_list[36] + ); + assert_eq!( + msg.rle_list[37], 198, + "incorrect value for rle_list[37], expected 198, is {}", + msg.rle_list[37] + ); + assert_eq!( + msg.rle_list[38], 134, + "incorrect value for rle_list[38], expected 134, is {}", + msg.rle_list[38] + ); + assert_eq!( + msg.rle_list[39], 235, + "incorrect value for rle_list[39], expected 235, is {}", + msg.rle_list[39] + ); + assert_eq!( + msg.rle_list[40], 134, + "incorrect value for rle_list[40], expected 134, is {}", + msg.rle_list[40] + ); + assert_eq!( + msg.rle_list[41], 57, + "incorrect value for rle_list[41], expected 57, is {}", + msg.rle_list[41] + ); + assert_eq!( + msg.rle_list[42], 120, + "incorrect value for rle_list[42], expected 120, is {}", + msg.rle_list[42] + ); + assert_eq!( + msg.rle_list[43], 243, + "incorrect value for rle_list[43], expected 243, is {}", + msg.rle_list[43] + ); + assert_eq!( + msg.rle_list[44], 151, + "incorrect value for rle_list[44], expected 151, is {}", + msg.rle_list[44] + ); + assert_eq!( + msg.rle_list[45], 35, + "incorrect value for rle_list[45], expected 35, is {}", + msg.rle_list[45] + ); + assert_eq!( + msg.rle_list[46], 17, + "incorrect value for rle_list[46], expected 17, is {}", + msg.rle_list[46] + ); + assert_eq!( + msg.rle_list[47], 201, + "incorrect value for rle_list[47], expected 201, is {}", + msg.rle_list[47] + ); + assert_eq!( + msg.rle_list[48], 211, + "incorrect value for rle_list[48], expected 211, is {}", + msg.rle_list[48] + ); + assert_eq!( + msg.rle_list[49], 125, + "incorrect value for rle_list[49], expected 125, is {}", + msg.rle_list[49] + ); + assert_eq!( + msg.rle_list[50], 117, + "incorrect value for rle_list[50], expected 117, is {}", + msg.rle_list[50] + ); + assert_eq!( + msg.rle_list[51], 164, + "incorrect value for rle_list[51], expected 164, is {}", + msg.rle_list[51] + ); + assert_eq!( + msg.rle_list[52], 142, + "incorrect value for rle_list[52], expected 142, is {}", + msg.rle_list[52] + ); + assert_eq!( + msg.rle_list[53], 101, + "incorrect value for rle_list[53], expected 101, is {}", + msg.rle_list[53] + ); + assert_eq!( + msg.rle_list[54], 239, + "incorrect value for rle_list[54], expected 239, is {}", + msg.rle_list[54] + ); + assert_eq!( + msg.rle_list[55], 144, + "incorrect value for rle_list[55], expected 144, is {}", + msg.rle_list[55] + ); + assert_eq!( + msg.rle_list[56], 158, + "incorrect value for rle_list[56], expected 158, is {}", + msg.rle_list[56] + ); + assert_eq!( + msg.rle_list[57], 239, + "incorrect value for rle_list[57], expected 239, is {}", + msg.rle_list[57] + ); + assert_eq!( + msg.rle_list[58], 90, + "incorrect value for rle_list[58], expected 90, is {}", + msg.rle_list[58] + ); + assert_eq!( + msg.rle_list[59], 56, + "incorrect value for rle_list[59], expected 56, is {}", + msg.rle_list[59] + ); + assert_eq!( + msg.rle_list[60], 71, + "incorrect value for rle_list[60], expected 71, is {}", + msg.rle_list[60] + ); + assert_eq!( + msg.rle_list[61], 120, + "incorrect value for rle_list[61], expected 120, is {}", + msg.rle_list[61] + ); + assert_eq!( + msg.rle_list[62], 67, + "incorrect value for rle_list[62], expected 67, is {}", + msg.rle_list[62] + ); + assert_eq!( + msg.rle_list[63], 221, + "incorrect value for rle_list[63], expected 221, is {}", + msg.rle_list[63] + ); + assert_eq!( + msg.rle_list[64], 114, + "incorrect value for rle_list[64], expected 114, is {}", + msg.rle_list[64] + ); + assert_eq!( + msg.rle_list[65], 10, + "incorrect value for rle_list[65], expected 10, is {}", + msg.rle_list[65] + ); + assert_eq!( + msg.rle_list[66], 190, + "incorrect value for rle_list[66], expected 190, is {}", + msg.rle_list[66] + ); + assert_eq!( + msg.rle_list[67], 4, + "incorrect value for rle_list[67], expected 4, is {}", + msg.rle_list[67] + ); + assert_eq!( + msg.rle_list[68], 230, + "incorrect value for rle_list[68], expected 230, is {}", + msg.rle_list[68] + ); + assert_eq!( + msg.rle_list[69], 164, + "incorrect value for rle_list[69], expected 164, is {}", + msg.rle_list[69] + ); + assert_eq!( + msg.rle_list[70], 171, + "incorrect value for rle_list[70], expected 171, is {}", + msg.rle_list[70] + ); + assert_eq!( + msg.rle_list[71], 78, + "incorrect value for rle_list[71], expected 78, is {}", + msg.rle_list[71] + ); + assert_eq!( + msg.rle_list[72], 185, + "incorrect value for rle_list[72], expected 185, is {}", + msg.rle_list[72] + ); + assert_eq!( + msg.rle_list[73], 90, + "incorrect value for rle_list[73], expected 90, is {}", + msg.rle_list[73] + ); + assert_eq!( + msg.rle_list[74], 46, + "incorrect value for rle_list[74], expected 46, is {}", + msg.rle_list[74] + ); + assert_eq!( + msg.rle_list[75], 177, + "incorrect value for rle_list[75], expected 177, is {}", + msg.rle_list[75] + ); + assert_eq!( + msg.rle_list[76], 82, + "incorrect value for rle_list[76], expected 82, is {}", + msg.rle_list[76] + ); + assert_eq!( + msg.rle_list[77], 228, + "incorrect value for rle_list[77], expected 228, is {}", + msg.rle_list[77] + ); + assert_eq!( + msg.rle_list[78], 123, + "incorrect value for rle_list[78], expected 123, is {}", + msg.rle_list[78] + ); + assert_eq!( + msg.rle_list[79], 222, + "incorrect value for rle_list[79], expected 222, is {}", + msg.rle_list[79] + ); + assert_eq!( + msg.rle_list[80], 227, + "incorrect value for rle_list[80], expected 227, is {}", + msg.rle_list[80] + ); + assert_eq!( + msg.rle_list[81], 145, + "incorrect value for rle_list[81], expected 145, is {}", + msg.rle_list[81] + ); + assert_eq!( + msg.rle_list[82], 195, + "incorrect value for rle_list[82], expected 195, is {}", + msg.rle_list[82] + ); + assert_eq!( + msg.rle_list[83], 219, + "incorrect value for rle_list[83], expected 219, is {}", + msg.rle_list[83] + ); + assert_eq!( + msg.rle_list[84], 27, + "incorrect value for rle_list[84], expected 27, is {}", + msg.rle_list[84] + ); + assert_eq!( + msg.rle_list[85], 56, + "incorrect value for rle_list[85], expected 56, is {}", + msg.rle_list[85] + ); + assert_eq!( + msg.rle_list[86], 227, + "incorrect value for rle_list[86], expected 227, is {}", + msg.rle_list[86] + ); + assert_eq!( + msg.rle_list[87], 246, + "incorrect value for rle_list[87], expected 246, is {}", + msg.rle_list[87] + ); + assert_eq!( + msg.rle_list[88], 215, + "incorrect value for rle_list[88], expected 215, is {}", + msg.rle_list[88] + ); + assert_eq!( + msg.rle_list[89], 144, + "incorrect value for rle_list[89], expected 144, is {}", + msg.rle_list[89] + ); + assert_eq!( + msg.rle_list[90], 158, + "incorrect value for rle_list[90], expected 158, is {}", + msg.rle_list[90] + ); + assert_eq!( + msg.rle_list[91], 31, + "incorrect value for rle_list[91], expected 31, is {}", + msg.rle_list[91] + ); + assert_eq!( + msg.rle_list[92], 214, + "incorrect value for rle_list[92], expected 214, is {}", + msg.rle_list[92] + ); + assert_eq!( + msg.rle_list[93], 241, + "incorrect value for rle_list[93], expected 241, is {}", + msg.rle_list[93] + ); + assert_eq!( + msg.rle_list[94], 254, + "incorrect value for rle_list[94], expected 254, is {}", + msg.rle_list[94] + ); + assert_eq!( + msg.rle_list[95], 200, + "incorrect value for rle_list[95], expected 200, is {}", + msg.rle_list[95] + ); + assert_eq!( + msg.rle_list[96], 86, + "incorrect value for rle_list[96], expected 86, is {}", + msg.rle_list[96] + ); + assert_eq!( + msg.rle_list[97], 142, + "incorrect value for rle_list[97], expected 142, is {}", + msg.rle_list[97] + ); + assert_eq!( + msg.rle_list[98], 89, + "incorrect value for rle_list[98], expected 89, is {}", + msg.rle_list[98] + ); + assert_eq!( + msg.rle_list[99], 12, + "incorrect value for rle_list[99], expected 12, is {}", + msg.rle_list[99] + ); + assert_eq!( + msg.rle_list[100], 121, + "incorrect value for rle_list[100], expected 121, is {}", + msg.rle_list[100] + ); + assert_eq!( + msg.rle_list[101], 29, + "incorrect value for rle_list[101], expected 29, is {}", + msg.rle_list[101] + ); + assert_eq!( + msg.rle_list[102], 124, + "incorrect value for rle_list[102], expected 124, is {}", + msg.rle_list[102] + ); + assert_eq!( + msg.rle_list[103], 9, + "incorrect value for rle_list[103], expected 9, is {}", + msg.rle_list[103] + ); + assert_eq!( + msg.rle_list[104], 19, + "incorrect value for rle_list[104], expected 19, is {}", + msg.rle_list[104] + ); + assert_eq!( + msg.rle_list[105], 153, + "incorrect value for rle_list[105], expected 153, is {}", + msg.rle_list[105] + ); + assert_eq!( + msg.rle_list[106], 44, + "incorrect value for rle_list[106], expected 44, is {}", + msg.rle_list[106] + ); + assert_eq!( + msg.rle_list[107], 35, + "incorrect value for rle_list[107], expected 35, is {}", + msg.rle_list[107] + ); + assert_eq!( + msg.rle_list[108], 126, + "incorrect value for rle_list[108], expected 126, is {}", + msg.rle_list[108] + ); + assert_eq!( + msg.rle_list[109], 14, + "incorrect value for rle_list[109], expected 14, is {}", + msg.rle_list[109] + ); + assert_eq!( + msg.rle_list[110], 217, + "incorrect value for rle_list[110], expected 217, is {}", + msg.rle_list[110] + ); + assert_eq!( + msg.rle_list[111], 65, + "incorrect value for rle_list[111], expected 65, is {}", + msg.rle_list[111] + ); + assert_eq!( + msg.rle_list[112], 116, + "incorrect value for rle_list[112], expected 116, is {}", + msg.rle_list[112] + ); + assert_eq!( + msg.rle_list[113], 26, + "incorrect value for rle_list[113], expected 26, is {}", + msg.rle_list[113] + ); + assert_eq!( + msg.rle_list[114], 139, + "incorrect value for rle_list[114], expected 139, is {}", + msg.rle_list[114] + ); + assert_eq!( + msg.rle_list[115], 122, + "incorrect value for rle_list[115], expected 122, is {}", + msg.rle_list[115] + ); + assert_eq!( + msg.rle_list[116], 114, + "incorrect value for rle_list[116], expected 114, is {}", + msg.rle_list[116] + ); + assert_eq!( + msg.rle_list[117], 90, + "incorrect value for rle_list[117], expected 90, is {}", + msg.rle_list[117] + ); + assert_eq!( + msg.rle_list[118], 124, + "incorrect value for rle_list[118], expected 124, is {}", + msg.rle_list[118] + ); + assert_eq!( + msg.rle_list[119], 81, + "incorrect value for rle_list[119], expected 81, is {}", + msg.rle_list[119] + ); + assert_eq!( + msg.rle_list[120], 0, + "incorrect value for rle_list[120], expected 0, is {}", + msg.rle_list[120] + ); + assert_eq!( + msg.rle_list[121], 186, + "incorrect value for rle_list[121], expected 186, is {}", + msg.rle_list[121] + ); + assert_eq!( + msg.rle_list[122], 246, + "incorrect value for rle_list[122], expected 246, is {}", + msg.rle_list[122] + ); + assert_eq!( + msg.rle_list[123], 46, + "incorrect value for rle_list[123], expected 46, is {}", + msg.rle_list[123] + ); + assert_eq!( + msg.rle_list[124], 98, + "incorrect value for rle_list[124], expected 98, is {}", + msg.rle_list[124] + ); + assert_eq!( + msg.rle_list[125], 179, + "incorrect value for rle_list[125], expected 179, is {}", + msg.rle_list[125] + ); + assert_eq!( + msg.rle_list[126], 243, + "incorrect value for rle_list[126], expected 243, is {}", + msg.rle_list[126] + ); + assert_eq!( + msg.rle_list[127], 198, + "incorrect value for rle_list[127], expected 198, is {}", + msg.rle_list[127] + ); + assert_eq!( + msg.rle_list[128], 217, + "incorrect value for rle_list[128], expected 217, is {}", + msg.rle_list[128] + ); + assert_eq!( + msg.rle_list[129], 36, + "incorrect value for rle_list[129], expected 36, is {}", + msg.rle_list[129] + ); + assert_eq!( + msg.rle_list[130], 30, + "incorrect value for rle_list[130], expected 30, is {}", + msg.rle_list[130] + ); + assert_eq!( + msg.rle_list[131], 202, + "incorrect value for rle_list[131], expected 202, is {}", + msg.rle_list[131] + ); + assert_eq!( + msg.rle_list[132], 12, + "incorrect value for rle_list[132], expected 12, is {}", + msg.rle_list[132] + ); + assert_eq!( + msg.rle_list[133], 135, + "incorrect value for rle_list[133], expected 135, is {}", + msg.rle_list[133] + ); + assert_eq!( + msg.rle_list[134], 61, + "incorrect value for rle_list[134], expected 61, is {}", + msg.rle_list[134] + ); + assert_eq!( + msg.rle_list[135], 42, + "incorrect value for rle_list[135], expected 42, is {}", + msg.rle_list[135] + ); + assert_eq!( + msg.rle_list[136], 150, + "incorrect value for rle_list[136], expected 150, is {}", + msg.rle_list[136] + ); + assert_eq!( + msg.rle_list[137], 221, + "incorrect value for rle_list[137], expected 221, is {}", + msg.rle_list[137] + ); + assert_eq!( + msg.rle_list[138], 102, + "incorrect value for rle_list[138], expected 102, is {}", + msg.rle_list[138] + ); + assert_eq!( + msg.rle_list[139], 83, + "incorrect value for rle_list[139], expected 83, is {}", + msg.rle_list[139] + ); + assert_eq!( + msg.rle_list[140], 179, + "incorrect value for rle_list[140], expected 179, is {}", + msg.rle_list[140] + ); + assert_eq!( + msg.rle_list[141], 43, + "incorrect value for rle_list[141], expected 43, is {}", + msg.rle_list[141] + ); + assert_eq!( + msg.rle_list[142], 252, + "incorrect value for rle_list[142], expected 252, is {}", + msg.rle_list[142] + ); + assert_eq!( + msg.rle_list[143], 81, + "incorrect value for rle_list[143], expected 81, is {}", + msg.rle_list[143] + ); + assert_eq!( + msg.rle_list[144], 62, + "incorrect value for rle_list[144], expected 62, is {}", + msg.rle_list[144] + ); + assert_eq!( + msg.rle_list[145], 126, + "incorrect value for rle_list[145], expected 126, is {}", + msg.rle_list[145] + ); + assert_eq!( + msg.rle_list[146], 204, + "incorrect value for rle_list[146], expected 204, is {}", + msg.rle_list[146] + ); + assert_eq!( + msg.rle_list[147], 195, + "incorrect value for rle_list[147], expected 195, is {}", + msg.rle_list[147] + ); + assert_eq!( + msg.rle_list[148], 238, + "incorrect value for rle_list[148], expected 238, is {}", + msg.rle_list[148] + ); + assert_eq!( + msg.rle_list[149], 18, + "incorrect value for rle_list[149], expected 18, is {}", + msg.rle_list[149] + ); + assert_eq!( + msg.rle_list[150], 128, + "incorrect value for rle_list[150], expected 128, is {}", + msg.rle_list[150] + ); + assert_eq!( + msg.rle_list[151], 193, + "incorrect value for rle_list[151], expected 193, is {}", + msg.rle_list[151] + ); + assert_eq!( + msg.rle_list[152], 53, + "incorrect value for rle_list[152], expected 53, is {}", + msg.rle_list[152] + ); + assert_eq!( + msg.rle_list[153], 94, + "incorrect value for rle_list[153], expected 94, is {}", + msg.rle_list[153] + ); + assert_eq!( + msg.rle_list[154], 99, + "incorrect value for rle_list[154], expected 99, is {}", + msg.rle_list[154] + ); + assert_eq!( + msg.rle_list[155], 63, + "incorrect value for rle_list[155], expected 63, is {}", + msg.rle_list[155] + ); + assert_eq!( + msg.rle_list[156], 182, + "incorrect value for rle_list[156], expected 182, is {}", + msg.rle_list[156] + ); + assert_eq!( + msg.rle_list[157], 2, + "incorrect value for rle_list[157], expected 2, is {}", + msg.rle_list[157] + ); + assert_eq!( + msg.rle_list[158], 186, + "incorrect value for rle_list[158], expected 186, is {}", + msg.rle_list[158] + ); + assert_eq!( + msg.rle_list[159], 220, + "incorrect value for rle_list[159], expected 220, is {}", + msg.rle_list[159] + ); + assert_eq!( + msg.rle_list[160], 77, + "incorrect value for rle_list[160], expected 77, is {}", + msg.rle_list[160] + ); + assert_eq!( + msg.rle_list[161], 186, + "incorrect value for rle_list[161], expected 186, is {}", + msg.rle_list[161] + ); + assert_eq!( + msg.rle_list[162], 224, + "incorrect value for rle_list[162], expected 224, is {}", + msg.rle_list[162] + ); + assert_eq!( + msg.rle_list[163], 220, + "incorrect value for rle_list[163], expected 220, is {}", + msg.rle_list[163] + ); + assert_eq!( + msg.rle_list[164], 13, + "incorrect value for rle_list[164], expected 13, is {}", + msg.rle_list[164] + ); + assert_eq!( + msg.rle_list[165], 212, + "incorrect value for rle_list[165], expected 212, is {}", + msg.rle_list[165] + ); + assert_eq!( + msg.rle_list[166], 182, + "incorrect value for rle_list[166], expected 182, is {}", + msg.rle_list[166] + ); + assert_eq!( + msg.rle_list[167], 88, + "incorrect value for rle_list[167], expected 88, is {}", + msg.rle_list[167] + ); + assert_eq!( + msg.rle_list[168], 15, + "incorrect value for rle_list[168], expected 15, is {}", + msg.rle_list[168] + ); + assert_eq!( + msg.rle_list[169], 151, + "incorrect value for rle_list[169], expected 151, is {}", + msg.rle_list[169] + ); + assert_eq!( + msg.rle_list[170], 5, + "incorrect value for rle_list[170], expected 5, is {}", + msg.rle_list[170] + ); + assert_eq!( + msg.rle_list[171], 93, + "incorrect value for rle_list[171], expected 93, is {}", + msg.rle_list[171] + ); + assert_eq!( + msg.rle_list[172], 251, + "incorrect value for rle_list[172], expected 251, is {}", + msg.rle_list[172] + ); + assert_eq!( + msg.rle_list[173], 164, + "incorrect value for rle_list[173], expected 164, is {}", + msg.rle_list[173] + ); + assert_eq!( + msg.rle_list[174], 18, + "incorrect value for rle_list[174], expected 18, is {}", + msg.rle_list[174] + ); + assert_eq!( + msg.rle_list[175], 228, + "incorrect value for rle_list[175], expected 228, is {}", + msg.rle_list[175] + ); + assert_eq!( + msg.rle_list[176], 168, + "incorrect value for rle_list[176], expected 168, is {}", + msg.rle_list[176] + ); + assert_eq!( + msg.rle_list[177], 226, + "incorrect value for rle_list[177], expected 226, is {}", + msg.rle_list[177] + ); + assert_eq!( + msg.rle_list[178], 195, + "incorrect value for rle_list[178], expected 195, is {}", + msg.rle_list[178] + ); + assert_eq!( + msg.rle_list[179], 44, + "incorrect value for rle_list[179], expected 44, is {}", + msg.rle_list[179] + ); + assert_eq!( + msg.rle_list[180], 170, + "incorrect value for rle_list[180], expected 170, is {}", + msg.rle_list[180] + ); + assert_eq!( + msg.rle_list[181], 145, + "incorrect value for rle_list[181], expected 145, is {}", + msg.rle_list[181] + ); + assert_eq!( + msg.rle_list[182], 36, + "incorrect value for rle_list[182], expected 36, is {}", + msg.rle_list[182] + ); + assert_eq!( + msg.rle_list[183], 58, + "incorrect value for rle_list[183], expected 58, is {}", + msg.rle_list[183] + ); + assert_eq!( + msg.rle_list[184], 96, + "incorrect value for rle_list[184], expected 96, is {}", + msg.rle_list[184] + ); + assert_eq!( + msg.rle_list[185], 107, + "incorrect value for rle_list[185], expected 107, is {}", + msg.rle_list[185] + ); + assert_eq!( + msg.rle_list[186], 144, + "incorrect value for rle_list[186], expected 144, is {}", + msg.rle_list[186] + ); + assert_eq!( + msg.rle_list[187], 11, + "incorrect value for rle_list[187], expected 11, is {}", + msg.rle_list[187] + ); + assert_eq!( + msg.rle_list[188], 228, + "incorrect value for rle_list[188], expected 228, is {}", + msg.rle_list[188] + ); + assert_eq!( + msg.rle_list[189], 12, + "incorrect value for rle_list[189], expected 12, is {}", + msg.rle_list[189] + ); + assert_eq!( + msg.rle_list[190], 163, + "incorrect value for rle_list[190], expected 163, is {}", + msg.rle_list[190] + ); + assert_eq!( + msg.rle_list[191], 238, + "incorrect value for rle_list[191], expected 238, is {}", + msg.rle_list[191] + ); + assert_eq!( + msg.rle_list[192], 247, + "incorrect value for rle_list[192], expected 247, is {}", + msg.rle_list[192] + ); + assert_eq!( + msg.rle_list[193], 159, + "incorrect value for rle_list[193], expected 159, is {}", + msg.rle_list[193] + ); + assert_eq!( + msg.rle_list[194], 189, + "incorrect value for rle_list[194], expected 189, is {}", + msg.rle_list[194] + ); + assert_eq!( + msg.rle_list[195], 1, + "incorrect value for rle_list[195], expected 1, is {}", + msg.rle_list[195] + ); + assert_eq!( + msg.rle_list[196], 115, + "incorrect value for rle_list[196], expected 115, is {}", + msg.rle_list[196] + ); + assert_eq!( + msg.rle_list[197], 65, + "incorrect value for rle_list[197], expected 65, is {}", + msg.rle_list[197] + ); + assert_eq!( + msg.rle_list[198], 202, + "incorrect value for rle_list[198], expected 202, is {}", + msg.rle_list[198] + ); + assert_eq!( + msg.rle_list[199], 121, + "incorrect value for rle_list[199], expected 121, is {}", + msg.rle_list[199] + ); + assert_eq!( + msg.rle_list[200], 47, + "incorrect value for rle_list[200], expected 47, is {}", + msg.rle_list[200] + ); + assert_eq!( + msg.rle_list[201], 193, + "incorrect value for rle_list[201], expected 193, is {}", + msg.rle_list[201] + ); + assert_eq!( + msg.rle_list[202], 11, + "incorrect value for rle_list[202], expected 11, is {}", + msg.rle_list[202] + ); + assert_eq!( + msg.rle_list[203], 96, + "incorrect value for rle_list[203], expected 96, is {}", + msg.rle_list[203] + ); + assert_eq!( + msg.rle_list[204], 93, + "incorrect value for rle_list[204], expected 93, is {}", + msg.rle_list[204] + ); + assert_eq!( + msg.rle_list[205], 72, + "incorrect value for rle_list[205], expected 72, is {}", + msg.rle_list[205] + ); + assert_eq!( + msg.rle_list[206], 81, + "incorrect value for rle_list[206], expected 81, is {}", + msg.rle_list[206] + ); + assert_eq!( + msg.rle_list[207], 207, + "incorrect value for rle_list[207], expected 207, is {}", + msg.rle_list[207] + ); + assert_eq!( + msg.rle_list[208], 121, + "incorrect value for rle_list[208], expected 121, is {}", + msg.rle_list[208] + ); + assert_eq!( + msg.rle_list[209], 19, + "incorrect value for rle_list[209], expected 19, is {}", + msg.rle_list[209] + ); + assert_eq!( + msg.rle_list[210], 151, + "incorrect value for rle_list[210], expected 151, is {}", + msg.rle_list[210] + ); + assert_eq!( + msg.rle_list[211], 136, + "incorrect value for rle_list[211], expected 136, is {}", + msg.rle_list[211] + ); + assert_eq!( + msg.rle_list[212], 233, + "incorrect value for rle_list[212], expected 233, is {}", + msg.rle_list[212] + ); + assert_eq!( + msg.rle_list[213], 51, + "incorrect value for rle_list[213], expected 51, is {}", + msg.rle_list[213] + ); + assert_eq!( + msg.rle_list[214], 133, + "incorrect value for rle_list[214], expected 133, is {}", + msg.rle_list[214] + ); + assert_eq!( + msg.rle_list[215], 195, + "incorrect value for rle_list[215], expected 195, is {}", + msg.rle_list[215] + ); + assert_eq!( + msg.rle_list[216], 77, + "incorrect value for rle_list[216], expected 77, is {}", + msg.rle_list[216] + ); + assert_eq!( + msg.rle_list[217], 44, + "incorrect value for rle_list[217], expected 44, is {}", + msg.rle_list[217] + ); + assert_eq!( + msg.rle_list[218], 147, + "incorrect value for rle_list[218], expected 147, is {}", + msg.rle_list[218] + ); + assert_eq!( + msg.rle_list[219], 206, + "incorrect value for rle_list[219], expected 206, is {}", + msg.rle_list[219] + ); + assert_eq!( + msg.rle_list[220], 120, + "incorrect value for rle_list[220], expected 120, is {}", + msg.rle_list[220] + ); + assert_eq!( + msg.rle_list[221], 252, + "incorrect value for rle_list[221], expected 252, is {}", + msg.rle_list[221] + ); + assert_eq!( + msg.rle_list[222], 77, + "incorrect value for rle_list[222], expected 77, is {}", + msg.rle_list[222] + ); + assert_eq!( + msg.rle_list[223], 212, + "incorrect value for rle_list[223], expected 212, is {}", + msg.rle_list[223] + ); + assert_eq!( + msg.rle_list[224], 68, + "incorrect value for rle_list[224], expected 68, is {}", + msg.rle_list[224] + ); + assert_eq!( + msg.rle_list[225], 60, + "incorrect value for rle_list[225], expected 60, is {}", + msg.rle_list[225] + ); + assert_eq!( + msg.rle_list[226], 206, + "incorrect value for rle_list[226], expected 206, is {}", + msg.rle_list[226] + ); + assert_eq!( + msg.rle_list[227], 106, + "incorrect value for rle_list[227], expected 106, is {}", + msg.rle_list[227] + ); + assert_eq!( + msg.rle_list[228], 207, + "incorrect value for rle_list[228], expected 207, is {}", + msg.rle_list[228] + ); + assert_eq!( + msg.rle_list[229], 243, + "incorrect value for rle_list[229], expected 243, is {}", + msg.rle_list[229] + ); + assert_eq!( + msg.rle_list[230], 158, + "incorrect value for rle_list[230], expected 158, is {}", + msg.rle_list[230] + ); + assert_eq!( + msg.rle_list[231], 94, + "incorrect value for rle_list[231], expected 94, is {}", + msg.rle_list[231] + ); + assert_eq!( + msg.rle_list[232], 6, + "incorrect value for rle_list[232], expected 6, is {}", + msg.rle_list[232] + ); + assert_eq!( + msg.rle_list[233], 3, + "incorrect value for rle_list[233], expected 3, is {}", + msg.rle_list[233] + ); + assert_eq!( + msg.rle_list[234], 205, + "incorrect value for rle_list[234], expected 205, is {}", + msg.rle_list[234] + ); + assert_eq!( + msg.rle_list[235], 92, + "incorrect value for rle_list[235], expected 92, is {}", + msg.rle_list[235] + ); + assert_eq!( + msg.rle_list[236], 84, + "incorrect value for rle_list[236], expected 84, is {}", + msg.rle_list[236] + ); + assert_eq!( + msg.rle_list[237], 2, + "incorrect value for rle_list[237], expected 2, is {}", + msg.rle_list[237] + ); + assert_eq!( + msg.rle_list[238], 220, + "incorrect value for rle_list[238], expected 220, is {}", + msg.rle_list[238] + ); + assert_eq!( + msg.rle_list[239], 50, + "incorrect value for rle_list[239], expected 50, is {}", + msg.rle_list[239] + ); + assert_eq!( + msg.rle_list[240], 61, + "incorrect value for rle_list[240], expected 61, is {}", + msg.rle_list[240] + ); + assert_eq!( + msg.rle_list[241], 38, + "incorrect value for rle_list[241], expected 38, is {}", + msg.rle_list[241] + ); + assert_eq!( + msg.rle_list[242], 141, + "incorrect value for rle_list[242], expected 141, is {}", + msg.rle_list[242] + ); + assert_eq!( + msg.rle_list[243], 117, + "incorrect value for rle_list[243], expected 117, is {}", + msg.rle_list[243] + ); + assert_eq!( + msg.rle_list[244], 108, + "incorrect value for rle_list[244], expected 108, is {}", + msg.rle_list[244] + ); + assert_eq!( + msg.rle_list[245], 101, + "incorrect value for rle_list[245], expected 101, is {}", + msg.rle_list[245] + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGridDefinitionDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a() { + { + let json_input = r#"{"crc":35660,"length":255,"msg_type":1525,"payload":"C1Sr5YSPLsw0XGgZzLYWYst70yYN/YGtq+v9GssDeH4qLCdXRZoNHLMgLyTDJ8aG64Y5ePOXIxHJ0311pI5l75Ce71o4R3hD3XIKvgTmpKtOuVousVLke97jkcPbGzjj9teQnh/W8f7IVo5ZDHkdfAkTmSwjfg7ZQXQai3pyWnxRALr2LmKz88bZJB7KDIc9KpbdZlOzK/xRPn7Mw+4SgME1XmM/tgK63E264NwN1LZYD5cFXfukEuSo4sMsqpEkOmBrkAvkDKPu95+9AXNBynkvwQtgXUhRz3kTl4jpM4XDTSyTznj8TdREPM5qz/OeXgYDzVxUAtwyPSaNdWxl","preamble":85,"sender":63413,"header":{"region_size_inverse":11,"area_width":43860,"lat_nw_corner_enc":34021,"lon_nw_corner_enc":11919,"num_msgs":204,"seq_num":52},"rle_list":[92,104,25,204,182,22,98,203,123,211,38,13,253,129,173,171,235,253,26,203,3,120,126,42,44,39,87,69,154,13,28,179,32,47,36,195,39,198,134,235,134,57,120,243,151,35,17,201,211,125,117,164,142,101,239,144,158,239,90,56,71,120,67,221,114,10,190,4,230,164,171,78,185,90,46,177,82,228,123,222,227,145,195,219,27,56,227,246,215,144,158,31,214,241,254,200,86,142,89,12,121,29,124,9,19,153,44,35,126,14,217,65,116,26,139,122,114,90,124,81,0,186,246,46,98,179,243,198,217,36,30,202,12,135,61,42,150,221,102,83,179,43,252,81,62,126,204,195,238,18,128,193,53,94,99,63,182,2,186,220,77,186,224,220,13,212,182,88,15,151,5,93,251,164,18,228,168,226,195,44,170,145,36,58,96,107,144,11,228,12,163,238,247,159,189,1,115,65,202,121,47,193,11,96,93,72,81,207,121,19,151,136,233,51,133,195,77,44,147,206,120,252,77,212,68,60,206,106,207,243,158,94,6,3,205,92,84,2,220,50,61,38,141,117,108,101]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGridDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f5, + "Incorrect message type, expected 0x5f5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf7b5, + "incorrect sender id, expected 0xf7b5, is {sender_id}" + ); + assert_eq!( + msg.header.area_width, 43860, + "incorrect value for header.area_width, expected 43860, is {}", + msg.header.area_width + ); + assert_eq!( + msg.header.lat_nw_corner_enc, 34021, + "incorrect value for header.lat_nw_corner_enc, expected 34021, is {}", + msg.header.lat_nw_corner_enc + ); + assert_eq!( + msg.header.lon_nw_corner_enc, 11919, + "incorrect value for header.lon_nw_corner_enc, expected 11919, is {}", + msg.header.lon_nw_corner_enc + ); + assert_eq!( + msg.header.num_msgs, 204, + "incorrect value for header.num_msgs, expected 204, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.region_size_inverse, 11, + "incorrect value for header.region_size_inverse, expected 11, is {}", + msg.header.region_size_inverse + ); + assert_eq!( + msg.header.seq_num, 52, + "incorrect value for header.seq_num, expected 52, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.rle_list[0], 92, + "incorrect value for rle_list[0], expected 92, is {}", + msg.rle_list[0] + ); + assert_eq!( + msg.rle_list[1], 104, + "incorrect value for rle_list[1], expected 104, is {}", + msg.rle_list[1] + ); + assert_eq!( + msg.rle_list[2], 25, + "incorrect value for rle_list[2], expected 25, is {}", + msg.rle_list[2] + ); + assert_eq!( + msg.rle_list[3], 204, + "incorrect value for rle_list[3], expected 204, is {}", + msg.rle_list[3] + ); + assert_eq!( + msg.rle_list[4], 182, + "incorrect value for rle_list[4], expected 182, is {}", + msg.rle_list[4] + ); + assert_eq!( + msg.rle_list[5], 22, + "incorrect value for rle_list[5], expected 22, is {}", + msg.rle_list[5] + ); + assert_eq!( + msg.rle_list[6], 98, + "incorrect value for rle_list[6], expected 98, is {}", + msg.rle_list[6] + ); + assert_eq!( + msg.rle_list[7], 203, + "incorrect value for rle_list[7], expected 203, is {}", + msg.rle_list[7] + ); + assert_eq!( + msg.rle_list[8], 123, + "incorrect value for rle_list[8], expected 123, is {}", + msg.rle_list[8] + ); + assert_eq!( + msg.rle_list[9], 211, + "incorrect value for rle_list[9], expected 211, is {}", + msg.rle_list[9] + ); + assert_eq!( + msg.rle_list[10], 38, + "incorrect value for rle_list[10], expected 38, is {}", + msg.rle_list[10] + ); + assert_eq!( + msg.rle_list[11], 13, + "incorrect value for rle_list[11], expected 13, is {}", + msg.rle_list[11] + ); + assert_eq!( + msg.rle_list[12], 253, + "incorrect value for rle_list[12], expected 253, is {}", + msg.rle_list[12] + ); + assert_eq!( + msg.rle_list[13], 129, + "incorrect value for rle_list[13], expected 129, is {}", + msg.rle_list[13] + ); + assert_eq!( + msg.rle_list[14], 173, + "incorrect value for rle_list[14], expected 173, is {}", + msg.rle_list[14] + ); + assert_eq!( + msg.rle_list[15], 171, + "incorrect value for rle_list[15], expected 171, is {}", + msg.rle_list[15] + ); + assert_eq!( + msg.rle_list[16], 235, + "incorrect value for rle_list[16], expected 235, is {}", + msg.rle_list[16] + ); + assert_eq!( + msg.rle_list[17], 253, + "incorrect value for rle_list[17], expected 253, is {}", + msg.rle_list[17] + ); + assert_eq!( + msg.rle_list[18], 26, + "incorrect value for rle_list[18], expected 26, is {}", + msg.rle_list[18] + ); + assert_eq!( + msg.rle_list[19], 203, + "incorrect value for rle_list[19], expected 203, is {}", + msg.rle_list[19] + ); + assert_eq!( + msg.rle_list[20], 3, + "incorrect value for rle_list[20], expected 3, is {}", + msg.rle_list[20] + ); + assert_eq!( + msg.rle_list[21], 120, + "incorrect value for rle_list[21], expected 120, is {}", + msg.rle_list[21] + ); + assert_eq!( + msg.rle_list[22], 126, + "incorrect value for rle_list[22], expected 126, is {}", + msg.rle_list[22] + ); + assert_eq!( + msg.rle_list[23], 42, + "incorrect value for rle_list[23], expected 42, is {}", + msg.rle_list[23] + ); + assert_eq!( + msg.rle_list[24], 44, + "incorrect value for rle_list[24], expected 44, is {}", + msg.rle_list[24] + ); + assert_eq!( + msg.rle_list[25], 39, + "incorrect value for rle_list[25], expected 39, is {}", + msg.rle_list[25] + ); + assert_eq!( + msg.rle_list[26], 87, + "incorrect value for rle_list[26], expected 87, is {}", + msg.rle_list[26] + ); + assert_eq!( + msg.rle_list[27], 69, + "incorrect value for rle_list[27], expected 69, is {}", + msg.rle_list[27] + ); + assert_eq!( + msg.rle_list[28], 154, + "incorrect value for rle_list[28], expected 154, is {}", + msg.rle_list[28] + ); + assert_eq!( + msg.rle_list[29], 13, + "incorrect value for rle_list[29], expected 13, is {}", + msg.rle_list[29] + ); + assert_eq!( + msg.rle_list[30], 28, + "incorrect value for rle_list[30], expected 28, is {}", + msg.rle_list[30] + ); + assert_eq!( + msg.rle_list[31], 179, + "incorrect value for rle_list[31], expected 179, is {}", + msg.rle_list[31] + ); + assert_eq!( + msg.rle_list[32], 32, + "incorrect value for rle_list[32], expected 32, is {}", + msg.rle_list[32] + ); + assert_eq!( + msg.rle_list[33], 47, + "incorrect value for rle_list[33], expected 47, is {}", + msg.rle_list[33] + ); + assert_eq!( + msg.rle_list[34], 36, + "incorrect value for rle_list[34], expected 36, is {}", + msg.rle_list[34] + ); + assert_eq!( + msg.rle_list[35], 195, + "incorrect value for rle_list[35], expected 195, is {}", + msg.rle_list[35] + ); + assert_eq!( + msg.rle_list[36], 39, + "incorrect value for rle_list[36], expected 39, is {}", + msg.rle_list[36] + ); + assert_eq!( + msg.rle_list[37], 198, + "incorrect value for rle_list[37], expected 198, is {}", + msg.rle_list[37] + ); + assert_eq!( + msg.rle_list[38], 134, + "incorrect value for rle_list[38], expected 134, is {}", + msg.rle_list[38] + ); + assert_eq!( + msg.rle_list[39], 235, + "incorrect value for rle_list[39], expected 235, is {}", + msg.rle_list[39] + ); + assert_eq!( + msg.rle_list[40], 134, + "incorrect value for rle_list[40], expected 134, is {}", + msg.rle_list[40] + ); + assert_eq!( + msg.rle_list[41], 57, + "incorrect value for rle_list[41], expected 57, is {}", + msg.rle_list[41] + ); + assert_eq!( + msg.rle_list[42], 120, + "incorrect value for rle_list[42], expected 120, is {}", + msg.rle_list[42] + ); + assert_eq!( + msg.rle_list[43], 243, + "incorrect value for rle_list[43], expected 243, is {}", + msg.rle_list[43] + ); + assert_eq!( + msg.rle_list[44], 151, + "incorrect value for rle_list[44], expected 151, is {}", + msg.rle_list[44] + ); + assert_eq!( + msg.rle_list[45], 35, + "incorrect value for rle_list[45], expected 35, is {}", + msg.rle_list[45] + ); + assert_eq!( + msg.rle_list[46], 17, + "incorrect value for rle_list[46], expected 17, is {}", + msg.rle_list[46] + ); + assert_eq!( + msg.rle_list[47], 201, + "incorrect value for rle_list[47], expected 201, is {}", + msg.rle_list[47] + ); + assert_eq!( + msg.rle_list[48], 211, + "incorrect value for rle_list[48], expected 211, is {}", + msg.rle_list[48] + ); + assert_eq!( + msg.rle_list[49], 125, + "incorrect value for rle_list[49], expected 125, is {}", + msg.rle_list[49] + ); + assert_eq!( + msg.rle_list[50], 117, + "incorrect value for rle_list[50], expected 117, is {}", + msg.rle_list[50] + ); + assert_eq!( + msg.rle_list[51], 164, + "incorrect value for rle_list[51], expected 164, is {}", + msg.rle_list[51] + ); + assert_eq!( + msg.rle_list[52], 142, + "incorrect value for rle_list[52], expected 142, is {}", + msg.rle_list[52] + ); + assert_eq!( + msg.rle_list[53], 101, + "incorrect value for rle_list[53], expected 101, is {}", + msg.rle_list[53] + ); + assert_eq!( + msg.rle_list[54], 239, + "incorrect value for rle_list[54], expected 239, is {}", + msg.rle_list[54] + ); + assert_eq!( + msg.rle_list[55], 144, + "incorrect value for rle_list[55], expected 144, is {}", + msg.rle_list[55] + ); + assert_eq!( + msg.rle_list[56], 158, + "incorrect value for rle_list[56], expected 158, is {}", + msg.rle_list[56] + ); + assert_eq!( + msg.rle_list[57], 239, + "incorrect value for rle_list[57], expected 239, is {}", + msg.rle_list[57] + ); + assert_eq!( + msg.rle_list[58], 90, + "incorrect value for rle_list[58], expected 90, is {}", + msg.rle_list[58] + ); + assert_eq!( + msg.rle_list[59], 56, + "incorrect value for rle_list[59], expected 56, is {}", + msg.rle_list[59] + ); + assert_eq!( + msg.rle_list[60], 71, + "incorrect value for rle_list[60], expected 71, is {}", + msg.rle_list[60] + ); + assert_eq!( + msg.rle_list[61], 120, + "incorrect value for rle_list[61], expected 120, is {}", + msg.rle_list[61] + ); + assert_eq!( + msg.rle_list[62], 67, + "incorrect value for rle_list[62], expected 67, is {}", + msg.rle_list[62] + ); + assert_eq!( + msg.rle_list[63], 221, + "incorrect value for rle_list[63], expected 221, is {}", + msg.rle_list[63] + ); + assert_eq!( + msg.rle_list[64], 114, + "incorrect value for rle_list[64], expected 114, is {}", + msg.rle_list[64] + ); + assert_eq!( + msg.rle_list[65], 10, + "incorrect value for rle_list[65], expected 10, is {}", + msg.rle_list[65] + ); + assert_eq!( + msg.rle_list[66], 190, + "incorrect value for rle_list[66], expected 190, is {}", + msg.rle_list[66] + ); + assert_eq!( + msg.rle_list[67], 4, + "incorrect value for rle_list[67], expected 4, is {}", + msg.rle_list[67] + ); + assert_eq!( + msg.rle_list[68], 230, + "incorrect value for rle_list[68], expected 230, is {}", + msg.rle_list[68] + ); + assert_eq!( + msg.rle_list[69], 164, + "incorrect value for rle_list[69], expected 164, is {}", + msg.rle_list[69] + ); + assert_eq!( + msg.rle_list[70], 171, + "incorrect value for rle_list[70], expected 171, is {}", + msg.rle_list[70] + ); + assert_eq!( + msg.rle_list[71], 78, + "incorrect value for rle_list[71], expected 78, is {}", + msg.rle_list[71] + ); + assert_eq!( + msg.rle_list[72], 185, + "incorrect value for rle_list[72], expected 185, is {}", + msg.rle_list[72] + ); + assert_eq!( + msg.rle_list[73], 90, + "incorrect value for rle_list[73], expected 90, is {}", + msg.rle_list[73] + ); + assert_eq!( + msg.rle_list[74], 46, + "incorrect value for rle_list[74], expected 46, is {}", + msg.rle_list[74] + ); + assert_eq!( + msg.rle_list[75], 177, + "incorrect value for rle_list[75], expected 177, is {}", + msg.rle_list[75] + ); + assert_eq!( + msg.rle_list[76], 82, + "incorrect value for rle_list[76], expected 82, is {}", + msg.rle_list[76] + ); + assert_eq!( + msg.rle_list[77], 228, + "incorrect value for rle_list[77], expected 228, is {}", + msg.rle_list[77] + ); + assert_eq!( + msg.rle_list[78], 123, + "incorrect value for rle_list[78], expected 123, is {}", + msg.rle_list[78] + ); + assert_eq!( + msg.rle_list[79], 222, + "incorrect value for rle_list[79], expected 222, is {}", + msg.rle_list[79] + ); + assert_eq!( + msg.rle_list[80], 227, + "incorrect value for rle_list[80], expected 227, is {}", + msg.rle_list[80] + ); + assert_eq!( + msg.rle_list[81], 145, + "incorrect value for rle_list[81], expected 145, is {}", + msg.rle_list[81] + ); + assert_eq!( + msg.rle_list[82], 195, + "incorrect value for rle_list[82], expected 195, is {}", + msg.rle_list[82] + ); + assert_eq!( + msg.rle_list[83], 219, + "incorrect value for rle_list[83], expected 219, is {}", + msg.rle_list[83] + ); + assert_eq!( + msg.rle_list[84], 27, + "incorrect value for rle_list[84], expected 27, is {}", + msg.rle_list[84] + ); + assert_eq!( + msg.rle_list[85], 56, + "incorrect value for rle_list[85], expected 56, is {}", + msg.rle_list[85] + ); + assert_eq!( + msg.rle_list[86], 227, + "incorrect value for rle_list[86], expected 227, is {}", + msg.rle_list[86] + ); + assert_eq!( + msg.rle_list[87], 246, + "incorrect value for rle_list[87], expected 246, is {}", + msg.rle_list[87] + ); + assert_eq!( + msg.rle_list[88], 215, + "incorrect value for rle_list[88], expected 215, is {}", + msg.rle_list[88] + ); + assert_eq!( + msg.rle_list[89], 144, + "incorrect value for rle_list[89], expected 144, is {}", + msg.rle_list[89] + ); + assert_eq!( + msg.rle_list[90], 158, + "incorrect value for rle_list[90], expected 158, is {}", + msg.rle_list[90] + ); + assert_eq!( + msg.rle_list[91], 31, + "incorrect value for rle_list[91], expected 31, is {}", + msg.rle_list[91] + ); + assert_eq!( + msg.rle_list[92], 214, + "incorrect value for rle_list[92], expected 214, is {}", + msg.rle_list[92] + ); + assert_eq!( + msg.rle_list[93], 241, + "incorrect value for rle_list[93], expected 241, is {}", + msg.rle_list[93] + ); + assert_eq!( + msg.rle_list[94], 254, + "incorrect value for rle_list[94], expected 254, is {}", + msg.rle_list[94] + ); + assert_eq!( + msg.rle_list[95], 200, + "incorrect value for rle_list[95], expected 200, is {}", + msg.rle_list[95] + ); + assert_eq!( + msg.rle_list[96], 86, + "incorrect value for rle_list[96], expected 86, is {}", + msg.rle_list[96] + ); + assert_eq!( + msg.rle_list[97], 142, + "incorrect value for rle_list[97], expected 142, is {}", + msg.rle_list[97] + ); + assert_eq!( + msg.rle_list[98], 89, + "incorrect value for rle_list[98], expected 89, is {}", + msg.rle_list[98] + ); + assert_eq!( + msg.rle_list[99], 12, + "incorrect value for rle_list[99], expected 12, is {}", + msg.rle_list[99] + ); + assert_eq!( + msg.rle_list[100], 121, + "incorrect value for rle_list[100], expected 121, is {}", + msg.rle_list[100] + ); + assert_eq!( + msg.rle_list[101], 29, + "incorrect value for rle_list[101], expected 29, is {}", + msg.rle_list[101] + ); + assert_eq!( + msg.rle_list[102], 124, + "incorrect value for rle_list[102], expected 124, is {}", + msg.rle_list[102] + ); + assert_eq!( + msg.rle_list[103], 9, + "incorrect value for rle_list[103], expected 9, is {}", + msg.rle_list[103] + ); + assert_eq!( + msg.rle_list[104], 19, + "incorrect value for rle_list[104], expected 19, is {}", + msg.rle_list[104] + ); + assert_eq!( + msg.rle_list[105], 153, + "incorrect value for rle_list[105], expected 153, is {}", + msg.rle_list[105] + ); + assert_eq!( + msg.rle_list[106], 44, + "incorrect value for rle_list[106], expected 44, is {}", + msg.rle_list[106] + ); + assert_eq!( + msg.rle_list[107], 35, + "incorrect value for rle_list[107], expected 35, is {}", + msg.rle_list[107] + ); + assert_eq!( + msg.rle_list[108], 126, + "incorrect value for rle_list[108], expected 126, is {}", + msg.rle_list[108] + ); + assert_eq!( + msg.rle_list[109], 14, + "incorrect value for rle_list[109], expected 14, is {}", + msg.rle_list[109] + ); + assert_eq!( + msg.rle_list[110], 217, + "incorrect value for rle_list[110], expected 217, is {}", + msg.rle_list[110] + ); + assert_eq!( + msg.rle_list[111], 65, + "incorrect value for rle_list[111], expected 65, is {}", + msg.rle_list[111] + ); + assert_eq!( + msg.rle_list[112], 116, + "incorrect value for rle_list[112], expected 116, is {}", + msg.rle_list[112] + ); + assert_eq!( + msg.rle_list[113], 26, + "incorrect value for rle_list[113], expected 26, is {}", + msg.rle_list[113] + ); + assert_eq!( + msg.rle_list[114], 139, + "incorrect value for rle_list[114], expected 139, is {}", + msg.rle_list[114] + ); + assert_eq!( + msg.rle_list[115], 122, + "incorrect value for rle_list[115], expected 122, is {}", + msg.rle_list[115] + ); + assert_eq!( + msg.rle_list[116], 114, + "incorrect value for rle_list[116], expected 114, is {}", + msg.rle_list[116] + ); + assert_eq!( + msg.rle_list[117], 90, + "incorrect value for rle_list[117], expected 90, is {}", + msg.rle_list[117] + ); + assert_eq!( + msg.rle_list[118], 124, + "incorrect value for rle_list[118], expected 124, is {}", + msg.rle_list[118] + ); + assert_eq!( + msg.rle_list[119], 81, + "incorrect value for rle_list[119], expected 81, is {}", + msg.rle_list[119] + ); + assert_eq!( + msg.rle_list[120], 0, + "incorrect value for rle_list[120], expected 0, is {}", + msg.rle_list[120] + ); + assert_eq!( + msg.rle_list[121], 186, + "incorrect value for rle_list[121], expected 186, is {}", + msg.rle_list[121] + ); + assert_eq!( + msg.rle_list[122], 246, + "incorrect value for rle_list[122], expected 246, is {}", + msg.rle_list[122] + ); + assert_eq!( + msg.rle_list[123], 46, + "incorrect value for rle_list[123], expected 46, is {}", + msg.rle_list[123] + ); + assert_eq!( + msg.rle_list[124], 98, + "incorrect value for rle_list[124], expected 98, is {}", + msg.rle_list[124] + ); + assert_eq!( + msg.rle_list[125], 179, + "incorrect value for rle_list[125], expected 179, is {}", + msg.rle_list[125] + ); + assert_eq!( + msg.rle_list[126], 243, + "incorrect value for rle_list[126], expected 243, is {}", + msg.rle_list[126] + ); + assert_eq!( + msg.rle_list[127], 198, + "incorrect value for rle_list[127], expected 198, is {}", + msg.rle_list[127] + ); + assert_eq!( + msg.rle_list[128], 217, + "incorrect value for rle_list[128], expected 217, is {}", + msg.rle_list[128] + ); + assert_eq!( + msg.rle_list[129], 36, + "incorrect value for rle_list[129], expected 36, is {}", + msg.rle_list[129] + ); + assert_eq!( + msg.rle_list[130], 30, + "incorrect value for rle_list[130], expected 30, is {}", + msg.rle_list[130] + ); + assert_eq!( + msg.rle_list[131], 202, + "incorrect value for rle_list[131], expected 202, is {}", + msg.rle_list[131] + ); + assert_eq!( + msg.rle_list[132], 12, + "incorrect value for rle_list[132], expected 12, is {}", + msg.rle_list[132] + ); + assert_eq!( + msg.rle_list[133], 135, + "incorrect value for rle_list[133], expected 135, is {}", + msg.rle_list[133] + ); + assert_eq!( + msg.rle_list[134], 61, + "incorrect value for rle_list[134], expected 61, is {}", + msg.rle_list[134] + ); + assert_eq!( + msg.rle_list[135], 42, + "incorrect value for rle_list[135], expected 42, is {}", + msg.rle_list[135] + ); + assert_eq!( + msg.rle_list[136], 150, + "incorrect value for rle_list[136], expected 150, is {}", + msg.rle_list[136] + ); + assert_eq!( + msg.rle_list[137], 221, + "incorrect value for rle_list[137], expected 221, is {}", + msg.rle_list[137] + ); + assert_eq!( + msg.rle_list[138], 102, + "incorrect value for rle_list[138], expected 102, is {}", + msg.rle_list[138] + ); + assert_eq!( + msg.rle_list[139], 83, + "incorrect value for rle_list[139], expected 83, is {}", + msg.rle_list[139] + ); + assert_eq!( + msg.rle_list[140], 179, + "incorrect value for rle_list[140], expected 179, is {}", + msg.rle_list[140] + ); + assert_eq!( + msg.rle_list[141], 43, + "incorrect value for rle_list[141], expected 43, is {}", + msg.rle_list[141] + ); + assert_eq!( + msg.rle_list[142], 252, + "incorrect value for rle_list[142], expected 252, is {}", + msg.rle_list[142] + ); + assert_eq!( + msg.rle_list[143], 81, + "incorrect value for rle_list[143], expected 81, is {}", + msg.rle_list[143] + ); + assert_eq!( + msg.rle_list[144], 62, + "incorrect value for rle_list[144], expected 62, is {}", + msg.rle_list[144] + ); + assert_eq!( + msg.rle_list[145], 126, + "incorrect value for rle_list[145], expected 126, is {}", + msg.rle_list[145] + ); + assert_eq!( + msg.rle_list[146], 204, + "incorrect value for rle_list[146], expected 204, is {}", + msg.rle_list[146] + ); + assert_eq!( + msg.rle_list[147], 195, + "incorrect value for rle_list[147], expected 195, is {}", + msg.rle_list[147] + ); + assert_eq!( + msg.rle_list[148], 238, + "incorrect value for rle_list[148], expected 238, is {}", + msg.rle_list[148] + ); + assert_eq!( + msg.rle_list[149], 18, + "incorrect value for rle_list[149], expected 18, is {}", + msg.rle_list[149] + ); + assert_eq!( + msg.rle_list[150], 128, + "incorrect value for rle_list[150], expected 128, is {}", + msg.rle_list[150] + ); + assert_eq!( + msg.rle_list[151], 193, + "incorrect value for rle_list[151], expected 193, is {}", + msg.rle_list[151] + ); + assert_eq!( + msg.rle_list[152], 53, + "incorrect value for rle_list[152], expected 53, is {}", + msg.rle_list[152] + ); + assert_eq!( + msg.rle_list[153], 94, + "incorrect value for rle_list[153], expected 94, is {}", + msg.rle_list[153] + ); + assert_eq!( + msg.rle_list[154], 99, + "incorrect value for rle_list[154], expected 99, is {}", + msg.rle_list[154] + ); + assert_eq!( + msg.rle_list[155], 63, + "incorrect value for rle_list[155], expected 63, is {}", + msg.rle_list[155] + ); + assert_eq!( + msg.rle_list[156], 182, + "incorrect value for rle_list[156], expected 182, is {}", + msg.rle_list[156] + ); + assert_eq!( + msg.rle_list[157], 2, + "incorrect value for rle_list[157], expected 2, is {}", + msg.rle_list[157] + ); + assert_eq!( + msg.rle_list[158], 186, + "incorrect value for rle_list[158], expected 186, is {}", + msg.rle_list[158] + ); + assert_eq!( + msg.rle_list[159], 220, + "incorrect value for rle_list[159], expected 220, is {}", + msg.rle_list[159] + ); + assert_eq!( + msg.rle_list[160], 77, + "incorrect value for rle_list[160], expected 77, is {}", + msg.rle_list[160] + ); + assert_eq!( + msg.rle_list[161], 186, + "incorrect value for rle_list[161], expected 186, is {}", + msg.rle_list[161] + ); + assert_eq!( + msg.rle_list[162], 224, + "incorrect value for rle_list[162], expected 224, is {}", + msg.rle_list[162] + ); + assert_eq!( + msg.rle_list[163], 220, + "incorrect value for rle_list[163], expected 220, is {}", + msg.rle_list[163] + ); + assert_eq!( + msg.rle_list[164], 13, + "incorrect value for rle_list[164], expected 13, is {}", + msg.rle_list[164] + ); + assert_eq!( + msg.rle_list[165], 212, + "incorrect value for rle_list[165], expected 212, is {}", + msg.rle_list[165] + ); + assert_eq!( + msg.rle_list[166], 182, + "incorrect value for rle_list[166], expected 182, is {}", + msg.rle_list[166] + ); + assert_eq!( + msg.rle_list[167], 88, + "incorrect value for rle_list[167], expected 88, is {}", + msg.rle_list[167] + ); + assert_eq!( + msg.rle_list[168], 15, + "incorrect value for rle_list[168], expected 15, is {}", + msg.rle_list[168] + ); + assert_eq!( + msg.rle_list[169], 151, + "incorrect value for rle_list[169], expected 151, is {}", + msg.rle_list[169] + ); + assert_eq!( + msg.rle_list[170], 5, + "incorrect value for rle_list[170], expected 5, is {}", + msg.rle_list[170] + ); + assert_eq!( + msg.rle_list[171], 93, + "incorrect value for rle_list[171], expected 93, is {}", + msg.rle_list[171] + ); + assert_eq!( + msg.rle_list[172], 251, + "incorrect value for rle_list[172], expected 251, is {}", + msg.rle_list[172] + ); + assert_eq!( + msg.rle_list[173], 164, + "incorrect value for rle_list[173], expected 164, is {}", + msg.rle_list[173] + ); + assert_eq!( + msg.rle_list[174], 18, + "incorrect value for rle_list[174], expected 18, is {}", + msg.rle_list[174] + ); + assert_eq!( + msg.rle_list[175], 228, + "incorrect value for rle_list[175], expected 228, is {}", + msg.rle_list[175] + ); + assert_eq!( + msg.rle_list[176], 168, + "incorrect value for rle_list[176], expected 168, is {}", + msg.rle_list[176] + ); + assert_eq!( + msg.rle_list[177], 226, + "incorrect value for rle_list[177], expected 226, is {}", + msg.rle_list[177] + ); + assert_eq!( + msg.rle_list[178], 195, + "incorrect value for rle_list[178], expected 195, is {}", + msg.rle_list[178] + ); + assert_eq!( + msg.rle_list[179], 44, + "incorrect value for rle_list[179], expected 44, is {}", + msg.rle_list[179] + ); + assert_eq!( + msg.rle_list[180], 170, + "incorrect value for rle_list[180], expected 170, is {}", + msg.rle_list[180] + ); + assert_eq!( + msg.rle_list[181], 145, + "incorrect value for rle_list[181], expected 145, is {}", + msg.rle_list[181] + ); + assert_eq!( + msg.rle_list[182], 36, + "incorrect value for rle_list[182], expected 36, is {}", + msg.rle_list[182] + ); + assert_eq!( + msg.rle_list[183], 58, + "incorrect value for rle_list[183], expected 58, is {}", + msg.rle_list[183] + ); + assert_eq!( + msg.rle_list[184], 96, + "incorrect value for rle_list[184], expected 96, is {}", + msg.rle_list[184] + ); + assert_eq!( + msg.rle_list[185], 107, + "incorrect value for rle_list[185], expected 107, is {}", + msg.rle_list[185] + ); + assert_eq!( + msg.rle_list[186], 144, + "incorrect value for rle_list[186], expected 144, is {}", + msg.rle_list[186] + ); + assert_eq!( + msg.rle_list[187], 11, + "incorrect value for rle_list[187], expected 11, is {}", + msg.rle_list[187] + ); + assert_eq!( + msg.rle_list[188], 228, + "incorrect value for rle_list[188], expected 228, is {}", + msg.rle_list[188] + ); + assert_eq!( + msg.rle_list[189], 12, + "incorrect value for rle_list[189], expected 12, is {}", + msg.rle_list[189] + ); + assert_eq!( + msg.rle_list[190], 163, + "incorrect value for rle_list[190], expected 163, is {}", + msg.rle_list[190] + ); + assert_eq!( + msg.rle_list[191], 238, + "incorrect value for rle_list[191], expected 238, is {}", + msg.rle_list[191] + ); + assert_eq!( + msg.rle_list[192], 247, + "incorrect value for rle_list[192], expected 247, is {}", + msg.rle_list[192] + ); + assert_eq!( + msg.rle_list[193], 159, + "incorrect value for rle_list[193], expected 159, is {}", + msg.rle_list[193] + ); + assert_eq!( + msg.rle_list[194], 189, + "incorrect value for rle_list[194], expected 189, is {}", + msg.rle_list[194] + ); + assert_eq!( + msg.rle_list[195], 1, + "incorrect value for rle_list[195], expected 1, is {}", + msg.rle_list[195] + ); + assert_eq!( + msg.rle_list[196], 115, + "incorrect value for rle_list[196], expected 115, is {}", + msg.rle_list[196] + ); + assert_eq!( + msg.rle_list[197], 65, + "incorrect value for rle_list[197], expected 65, is {}", + msg.rle_list[197] + ); + assert_eq!( + msg.rle_list[198], 202, + "incorrect value for rle_list[198], expected 202, is {}", + msg.rle_list[198] + ); + assert_eq!( + msg.rle_list[199], 121, + "incorrect value for rle_list[199], expected 121, is {}", + msg.rle_list[199] + ); + assert_eq!( + msg.rle_list[200], 47, + "incorrect value for rle_list[200], expected 47, is {}", + msg.rle_list[200] + ); + assert_eq!( + msg.rle_list[201], 193, + "incorrect value for rle_list[201], expected 193, is {}", + msg.rle_list[201] + ); + assert_eq!( + msg.rle_list[202], 11, + "incorrect value for rle_list[202], expected 11, is {}", + msg.rle_list[202] + ); + assert_eq!( + msg.rle_list[203], 96, + "incorrect value for rle_list[203], expected 96, is {}", + msg.rle_list[203] + ); + assert_eq!( + msg.rle_list[204], 93, + "incorrect value for rle_list[204], expected 93, is {}", + msg.rle_list[204] + ); + assert_eq!( + msg.rle_list[205], 72, + "incorrect value for rle_list[205], expected 72, is {}", + msg.rle_list[205] + ); + assert_eq!( + msg.rle_list[206], 81, + "incorrect value for rle_list[206], expected 81, is {}", + msg.rle_list[206] + ); + assert_eq!( + msg.rle_list[207], 207, + "incorrect value for rle_list[207], expected 207, is {}", + msg.rle_list[207] + ); + assert_eq!( + msg.rle_list[208], 121, + "incorrect value for rle_list[208], expected 121, is {}", + msg.rle_list[208] + ); + assert_eq!( + msg.rle_list[209], 19, + "incorrect value for rle_list[209], expected 19, is {}", + msg.rle_list[209] + ); + assert_eq!( + msg.rle_list[210], 151, + "incorrect value for rle_list[210], expected 151, is {}", + msg.rle_list[210] + ); + assert_eq!( + msg.rle_list[211], 136, + "incorrect value for rle_list[211], expected 136, is {}", + msg.rle_list[211] + ); + assert_eq!( + msg.rle_list[212], 233, + "incorrect value for rle_list[212], expected 233, is {}", + msg.rle_list[212] + ); + assert_eq!( + msg.rle_list[213], 51, + "incorrect value for rle_list[213], expected 51, is {}", + msg.rle_list[213] + ); + assert_eq!( + msg.rle_list[214], 133, + "incorrect value for rle_list[214], expected 133, is {}", + msg.rle_list[214] + ); + assert_eq!( + msg.rle_list[215], 195, + "incorrect value for rle_list[215], expected 195, is {}", + msg.rle_list[215] + ); + assert_eq!( + msg.rle_list[216], 77, + "incorrect value for rle_list[216], expected 77, is {}", + msg.rle_list[216] + ); + assert_eq!( + msg.rle_list[217], 44, + "incorrect value for rle_list[217], expected 44, is {}", + msg.rle_list[217] + ); + assert_eq!( + msg.rle_list[218], 147, + "incorrect value for rle_list[218], expected 147, is {}", + msg.rle_list[218] + ); + assert_eq!( + msg.rle_list[219], 206, + "incorrect value for rle_list[219], expected 206, is {}", + msg.rle_list[219] + ); + assert_eq!( + msg.rle_list[220], 120, + "incorrect value for rle_list[220], expected 120, is {}", + msg.rle_list[220] + ); + assert_eq!( + msg.rle_list[221], 252, + "incorrect value for rle_list[221], expected 252, is {}", + msg.rle_list[221] + ); + assert_eq!( + msg.rle_list[222], 77, + "incorrect value for rle_list[222], expected 77, is {}", + msg.rle_list[222] + ); + assert_eq!( + msg.rle_list[223], 212, + "incorrect value for rle_list[223], expected 212, is {}", + msg.rle_list[223] + ); + assert_eq!( + msg.rle_list[224], 68, + "incorrect value for rle_list[224], expected 68, is {}", + msg.rle_list[224] + ); + assert_eq!( + msg.rle_list[225], 60, + "incorrect value for rle_list[225], expected 60, is {}", + msg.rle_list[225] + ); + assert_eq!( + msg.rle_list[226], 206, + "incorrect value for rle_list[226], expected 206, is {}", + msg.rle_list[226] + ); + assert_eq!( + msg.rle_list[227], 106, + "incorrect value for rle_list[227], expected 106, is {}", + msg.rle_list[227] + ); + assert_eq!( + msg.rle_list[228], 207, + "incorrect value for rle_list[228], expected 207, is {}", + msg.rle_list[228] + ); + assert_eq!( + msg.rle_list[229], 243, + "incorrect value for rle_list[229], expected 243, is {}", + msg.rle_list[229] + ); + assert_eq!( + msg.rle_list[230], 158, + "incorrect value for rle_list[230], expected 158, is {}", + msg.rle_list[230] + ); + assert_eq!( + msg.rle_list[231], 94, + "incorrect value for rle_list[231], expected 94, is {}", + msg.rle_list[231] + ); + assert_eq!( + msg.rle_list[232], 6, + "incorrect value for rle_list[232], expected 6, is {}", + msg.rle_list[232] + ); + assert_eq!( + msg.rle_list[233], 3, + "incorrect value for rle_list[233], expected 3, is {}", + msg.rle_list[233] + ); + assert_eq!( + msg.rle_list[234], 205, + "incorrect value for rle_list[234], expected 205, is {}", + msg.rle_list[234] + ); + assert_eq!( + msg.rle_list[235], 92, + "incorrect value for rle_list[235], expected 92, is {}", + msg.rle_list[235] + ); + assert_eq!( + msg.rle_list[236], 84, + "incorrect value for rle_list[236], expected 84, is {}", + msg.rle_list[236] + ); + assert_eq!( + msg.rle_list[237], 2, + "incorrect value for rle_list[237], expected 2, is {}", + msg.rle_list[237] + ); + assert_eq!( + msg.rle_list[238], 220, + "incorrect value for rle_list[238], expected 220, is {}", + msg.rle_list[238] + ); + assert_eq!( + msg.rle_list[239], 50, + "incorrect value for rle_list[239], expected 50, is {}", + msg.rle_list[239] + ); + assert_eq!( + msg.rle_list[240], 61, + "incorrect value for rle_list[240], expected 61, is {}", + msg.rle_list[240] + ); + assert_eq!( + msg.rle_list[241], 38, + "incorrect value for rle_list[241], expected 38, is {}", + msg.rle_list[241] + ); + assert_eq!( + msg.rle_list[242], 141, + "incorrect value for rle_list[242], expected 141, is {}", + msg.rle_list[242] + ); + assert_eq!( + msg.rle_list[243], 117, + "incorrect value for rle_list[243], expected 117, is {}", + msg.rle_list[243] + ); + assert_eq!( + msg.rle_list[244], 108, + "incorrect value for rle_list[244], expected 108, is {}", + msg.rle_list[244] + ); + assert_eq!( + msg.rle_list[245], 101, + "incorrect value for rle_list[245], expected 101, is {}", + msg.rle_list[245] + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGridDefinitionDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 245, 5, 181, 247, 255, 11, 84, 171, 229, 132, 143, 46, 204, 52, 92, 104, 25, 204, + 182, 22, 98, 203, 123, 211, 38, 13, 253, 129, 173, 171, 235, 253, 26, 203, 3, 120, 126, + 42, 44, 39, 87, 69, 154, 13, 28, 179, 32, 47, 36, 195, 39, 198, 134, 235, 134, 57, 120, + 243, 151, 35, 17, 201, 211, 125, 117, 164, 142, 101, 239, 144, 158, 239, 90, 56, 71, + 120, 67, 221, 114, 10, 190, 4, 230, 164, 171, 78, 185, 90, 46, 177, 82, 228, 123, 222, + 227, 145, 195, 219, 27, 56, 227, 246, 215, 144, 158, 31, 214, 241, 254, 200, 86, 142, + 89, 12, 121, 29, 124, 9, 19, 153, 44, 35, 126, 14, 217, 65, 116, 26, 139, 122, 114, 90, + 124, 81, 0, 186, 246, 46, 98, 179, 243, 198, 217, 36, 30, 202, 12, 135, 61, 42, 150, + 221, 102, 83, 179, 43, 252, 81, 62, 126, 204, 195, 238, 18, 128, 193, 53, 94, 99, 63, + 182, 2, 186, 220, 77, 186, 224, 220, 13, 212, 182, 88, 15, 151, 5, 93, 251, 164, 18, + 228, 168, 226, 195, 44, 170, 145, 36, 58, 96, 107, 144, 11, 228, 12, 163, 238, 247, + 159, 189, 1, 115, 65, 202, 121, 47, 193, 11, 96, 93, 72, 81, 207, 121, 19, 151, 136, + 233, 51, 133, 195, 77, 44, 147, 206, 120, 252, 77, 212, 68, 60, 206, 106, 207, 243, + 158, 94, 6, 3, 205, 92, 84, 2, 220, 50, 61, 38, 141, 117, 108, 101, 76, 139, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrGridDefinitionDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGridDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f5, + "Incorrect message type, expected 0x5f5, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf7b5, + "incorrect sender id, expected 0xf7b5, is {sender_id}" + ); + assert_eq!( + msg.header.area_width, 43860, + "incorrect value for header.area_width, expected 43860, is {}", + msg.header.area_width + ); + assert_eq!( + msg.header.lat_nw_corner_enc, 34021, + "incorrect value for header.lat_nw_corner_enc, expected 34021, is {}", + msg.header.lat_nw_corner_enc + ); + assert_eq!( + msg.header.lon_nw_corner_enc, 11919, + "incorrect value for header.lon_nw_corner_enc, expected 11919, is {}", + msg.header.lon_nw_corner_enc + ); + assert_eq!( + msg.header.num_msgs, 204, + "incorrect value for header.num_msgs, expected 204, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.region_size_inverse, 11, + "incorrect value for header.region_size_inverse, expected 11, is {}", + msg.header.region_size_inverse + ); + assert_eq!( + msg.header.seq_num, 52, + "incorrect value for header.seq_num, expected 52, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.rle_list[0], 92, + "incorrect value for rle_list[0], expected 92, is {}", + msg.rle_list[0] + ); + assert_eq!( + msg.rle_list[1], 104, + "incorrect value for rle_list[1], expected 104, is {}", + msg.rle_list[1] + ); + assert_eq!( + msg.rle_list[2], 25, + "incorrect value for rle_list[2], expected 25, is {}", + msg.rle_list[2] + ); + assert_eq!( + msg.rle_list[3], 204, + "incorrect value for rle_list[3], expected 204, is {}", + msg.rle_list[3] + ); + assert_eq!( + msg.rle_list[4], 182, + "incorrect value for rle_list[4], expected 182, is {}", + msg.rle_list[4] + ); + assert_eq!( + msg.rle_list[5], 22, + "incorrect value for rle_list[5], expected 22, is {}", + msg.rle_list[5] + ); + assert_eq!( + msg.rle_list[6], 98, + "incorrect value for rle_list[6], expected 98, is {}", + msg.rle_list[6] + ); + assert_eq!( + msg.rle_list[7], 203, + "incorrect value for rle_list[7], expected 203, is {}", + msg.rle_list[7] + ); + assert_eq!( + msg.rle_list[8], 123, + "incorrect value for rle_list[8], expected 123, is {}", + msg.rle_list[8] + ); + assert_eq!( + msg.rle_list[9], 211, + "incorrect value for rle_list[9], expected 211, is {}", + msg.rle_list[9] + ); + assert_eq!( + msg.rle_list[10], 38, + "incorrect value for rle_list[10], expected 38, is {}", + msg.rle_list[10] + ); + assert_eq!( + msg.rle_list[11], 13, + "incorrect value for rle_list[11], expected 13, is {}", + msg.rle_list[11] + ); + assert_eq!( + msg.rle_list[12], 253, + "incorrect value for rle_list[12], expected 253, is {}", + msg.rle_list[12] + ); + assert_eq!( + msg.rle_list[13], 129, + "incorrect value for rle_list[13], expected 129, is {}", + msg.rle_list[13] + ); + assert_eq!( + msg.rle_list[14], 173, + "incorrect value for rle_list[14], expected 173, is {}", + msg.rle_list[14] + ); + assert_eq!( + msg.rle_list[15], 171, + "incorrect value for rle_list[15], expected 171, is {}", + msg.rle_list[15] + ); + assert_eq!( + msg.rle_list[16], 235, + "incorrect value for rle_list[16], expected 235, is {}", + msg.rle_list[16] + ); + assert_eq!( + msg.rle_list[17], 253, + "incorrect value for rle_list[17], expected 253, is {}", + msg.rle_list[17] + ); + assert_eq!( + msg.rle_list[18], 26, + "incorrect value for rle_list[18], expected 26, is {}", + msg.rle_list[18] + ); + assert_eq!( + msg.rle_list[19], 203, + "incorrect value for rle_list[19], expected 203, is {}", + msg.rle_list[19] + ); + assert_eq!( + msg.rle_list[20], 3, + "incorrect value for rle_list[20], expected 3, is {}", + msg.rle_list[20] + ); + assert_eq!( + msg.rle_list[21], 120, + "incorrect value for rle_list[21], expected 120, is {}", + msg.rle_list[21] + ); + assert_eq!( + msg.rle_list[22], 126, + "incorrect value for rle_list[22], expected 126, is {}", + msg.rle_list[22] + ); + assert_eq!( + msg.rle_list[23], 42, + "incorrect value for rle_list[23], expected 42, is {}", + msg.rle_list[23] + ); + assert_eq!( + msg.rle_list[24], 44, + "incorrect value for rle_list[24], expected 44, is {}", + msg.rle_list[24] + ); + assert_eq!( + msg.rle_list[25], 39, + "incorrect value for rle_list[25], expected 39, is {}", + msg.rle_list[25] + ); + assert_eq!( + msg.rle_list[26], 87, + "incorrect value for rle_list[26], expected 87, is {}", + msg.rle_list[26] + ); + assert_eq!( + msg.rle_list[27], 69, + "incorrect value for rle_list[27], expected 69, is {}", + msg.rle_list[27] + ); + assert_eq!( + msg.rle_list[28], 154, + "incorrect value for rle_list[28], expected 154, is {}", + msg.rle_list[28] + ); + assert_eq!( + msg.rle_list[29], 13, + "incorrect value for rle_list[29], expected 13, is {}", + msg.rle_list[29] + ); + assert_eq!( + msg.rle_list[30], 28, + "incorrect value for rle_list[30], expected 28, is {}", + msg.rle_list[30] + ); + assert_eq!( + msg.rle_list[31], 179, + "incorrect value for rle_list[31], expected 179, is {}", + msg.rle_list[31] + ); + assert_eq!( + msg.rle_list[32], 32, + "incorrect value for rle_list[32], expected 32, is {}", + msg.rle_list[32] + ); + assert_eq!( + msg.rle_list[33], 47, + "incorrect value for rle_list[33], expected 47, is {}", + msg.rle_list[33] + ); + assert_eq!( + msg.rle_list[34], 36, + "incorrect value for rle_list[34], expected 36, is {}", + msg.rle_list[34] + ); + assert_eq!( + msg.rle_list[35], 195, + "incorrect value for rle_list[35], expected 195, is {}", + msg.rle_list[35] + ); + assert_eq!( + msg.rle_list[36], 39, + "incorrect value for rle_list[36], expected 39, is {}", + msg.rle_list[36] + ); + assert_eq!( + msg.rle_list[37], 198, + "incorrect value for rle_list[37], expected 198, is {}", + msg.rle_list[37] + ); + assert_eq!( + msg.rle_list[38], 134, + "incorrect value for rle_list[38], expected 134, is {}", + msg.rle_list[38] + ); + assert_eq!( + msg.rle_list[39], 235, + "incorrect value for rle_list[39], expected 235, is {}", + msg.rle_list[39] + ); + assert_eq!( + msg.rle_list[40], 134, + "incorrect value for rle_list[40], expected 134, is {}", + msg.rle_list[40] + ); + assert_eq!( + msg.rle_list[41], 57, + "incorrect value for rle_list[41], expected 57, is {}", + msg.rle_list[41] + ); + assert_eq!( + msg.rle_list[42], 120, + "incorrect value for rle_list[42], expected 120, is {}", + msg.rle_list[42] + ); + assert_eq!( + msg.rle_list[43], 243, + "incorrect value for rle_list[43], expected 243, is {}", + msg.rle_list[43] + ); + assert_eq!( + msg.rle_list[44], 151, + "incorrect value for rle_list[44], expected 151, is {}", + msg.rle_list[44] + ); + assert_eq!( + msg.rle_list[45], 35, + "incorrect value for rle_list[45], expected 35, is {}", + msg.rle_list[45] + ); + assert_eq!( + msg.rle_list[46], 17, + "incorrect value for rle_list[46], expected 17, is {}", + msg.rle_list[46] + ); + assert_eq!( + msg.rle_list[47], 201, + "incorrect value for rle_list[47], expected 201, is {}", + msg.rle_list[47] + ); + assert_eq!( + msg.rle_list[48], 211, + "incorrect value for rle_list[48], expected 211, is {}", + msg.rle_list[48] + ); + assert_eq!( + msg.rle_list[49], 125, + "incorrect value for rle_list[49], expected 125, is {}", + msg.rle_list[49] + ); + assert_eq!( + msg.rle_list[50], 117, + "incorrect value for rle_list[50], expected 117, is {}", + msg.rle_list[50] + ); + assert_eq!( + msg.rle_list[51], 164, + "incorrect value for rle_list[51], expected 164, is {}", + msg.rle_list[51] + ); + assert_eq!( + msg.rle_list[52], 142, + "incorrect value for rle_list[52], expected 142, is {}", + msg.rle_list[52] + ); + assert_eq!( + msg.rle_list[53], 101, + "incorrect value for rle_list[53], expected 101, is {}", + msg.rle_list[53] + ); + assert_eq!( + msg.rle_list[54], 239, + "incorrect value for rle_list[54], expected 239, is {}", + msg.rle_list[54] + ); + assert_eq!( + msg.rle_list[55], 144, + "incorrect value for rle_list[55], expected 144, is {}", + msg.rle_list[55] + ); + assert_eq!( + msg.rle_list[56], 158, + "incorrect value for rle_list[56], expected 158, is {}", + msg.rle_list[56] + ); + assert_eq!( + msg.rle_list[57], 239, + "incorrect value for rle_list[57], expected 239, is {}", + msg.rle_list[57] + ); + assert_eq!( + msg.rle_list[58], 90, + "incorrect value for rle_list[58], expected 90, is {}", + msg.rle_list[58] + ); + assert_eq!( + msg.rle_list[59], 56, + "incorrect value for rle_list[59], expected 56, is {}", + msg.rle_list[59] + ); + assert_eq!( + msg.rle_list[60], 71, + "incorrect value for rle_list[60], expected 71, is {}", + msg.rle_list[60] + ); + assert_eq!( + msg.rle_list[61], 120, + "incorrect value for rle_list[61], expected 120, is {}", + msg.rle_list[61] + ); + assert_eq!( + msg.rle_list[62], 67, + "incorrect value for rle_list[62], expected 67, is {}", + msg.rle_list[62] + ); + assert_eq!( + msg.rle_list[63], 221, + "incorrect value for rle_list[63], expected 221, is {}", + msg.rle_list[63] + ); + assert_eq!( + msg.rle_list[64], 114, + "incorrect value for rle_list[64], expected 114, is {}", + msg.rle_list[64] + ); + assert_eq!( + msg.rle_list[65], 10, + "incorrect value for rle_list[65], expected 10, is {}", + msg.rle_list[65] + ); + assert_eq!( + msg.rle_list[66], 190, + "incorrect value for rle_list[66], expected 190, is {}", + msg.rle_list[66] + ); + assert_eq!( + msg.rle_list[67], 4, + "incorrect value for rle_list[67], expected 4, is {}", + msg.rle_list[67] + ); + assert_eq!( + msg.rle_list[68], 230, + "incorrect value for rle_list[68], expected 230, is {}", + msg.rle_list[68] + ); + assert_eq!( + msg.rle_list[69], 164, + "incorrect value for rle_list[69], expected 164, is {}", + msg.rle_list[69] + ); + assert_eq!( + msg.rle_list[70], 171, + "incorrect value for rle_list[70], expected 171, is {}", + msg.rle_list[70] + ); + assert_eq!( + msg.rle_list[71], 78, + "incorrect value for rle_list[71], expected 78, is {}", + msg.rle_list[71] + ); + assert_eq!( + msg.rle_list[72], 185, + "incorrect value for rle_list[72], expected 185, is {}", + msg.rle_list[72] + ); + assert_eq!( + msg.rle_list[73], 90, + "incorrect value for rle_list[73], expected 90, is {}", + msg.rle_list[73] + ); + assert_eq!( + msg.rle_list[74], 46, + "incorrect value for rle_list[74], expected 46, is {}", + msg.rle_list[74] + ); + assert_eq!( + msg.rle_list[75], 177, + "incorrect value for rle_list[75], expected 177, is {}", + msg.rle_list[75] + ); + assert_eq!( + msg.rle_list[76], 82, + "incorrect value for rle_list[76], expected 82, is {}", + msg.rle_list[76] + ); + assert_eq!( + msg.rle_list[77], 228, + "incorrect value for rle_list[77], expected 228, is {}", + msg.rle_list[77] + ); + assert_eq!( + msg.rle_list[78], 123, + "incorrect value for rle_list[78], expected 123, is {}", + msg.rle_list[78] + ); + assert_eq!( + msg.rle_list[79], 222, + "incorrect value for rle_list[79], expected 222, is {}", + msg.rle_list[79] + ); + assert_eq!( + msg.rle_list[80], 227, + "incorrect value for rle_list[80], expected 227, is {}", + msg.rle_list[80] + ); + assert_eq!( + msg.rle_list[81], 145, + "incorrect value for rle_list[81], expected 145, is {}", + msg.rle_list[81] + ); + assert_eq!( + msg.rle_list[82], 195, + "incorrect value for rle_list[82], expected 195, is {}", + msg.rle_list[82] + ); + assert_eq!( + msg.rle_list[83], 219, + "incorrect value for rle_list[83], expected 219, is {}", + msg.rle_list[83] + ); + assert_eq!( + msg.rle_list[84], 27, + "incorrect value for rle_list[84], expected 27, is {}", + msg.rle_list[84] + ); + assert_eq!( + msg.rle_list[85], 56, + "incorrect value for rle_list[85], expected 56, is {}", + msg.rle_list[85] + ); + assert_eq!( + msg.rle_list[86], 227, + "incorrect value for rle_list[86], expected 227, is {}", + msg.rle_list[86] + ); + assert_eq!( + msg.rle_list[87], 246, + "incorrect value for rle_list[87], expected 246, is {}", + msg.rle_list[87] + ); + assert_eq!( + msg.rle_list[88], 215, + "incorrect value for rle_list[88], expected 215, is {}", + msg.rle_list[88] + ); + assert_eq!( + msg.rle_list[89], 144, + "incorrect value for rle_list[89], expected 144, is {}", + msg.rle_list[89] + ); + assert_eq!( + msg.rle_list[90], 158, + "incorrect value for rle_list[90], expected 158, is {}", + msg.rle_list[90] + ); + assert_eq!( + msg.rle_list[91], 31, + "incorrect value for rle_list[91], expected 31, is {}", + msg.rle_list[91] + ); + assert_eq!( + msg.rle_list[92], 214, + "incorrect value for rle_list[92], expected 214, is {}", + msg.rle_list[92] + ); + assert_eq!( + msg.rle_list[93], 241, + "incorrect value for rle_list[93], expected 241, is {}", + msg.rle_list[93] + ); + assert_eq!( + msg.rle_list[94], 254, + "incorrect value for rle_list[94], expected 254, is {}", + msg.rle_list[94] + ); + assert_eq!( + msg.rle_list[95], 200, + "incorrect value for rle_list[95], expected 200, is {}", + msg.rle_list[95] + ); + assert_eq!( + msg.rle_list[96], 86, + "incorrect value for rle_list[96], expected 86, is {}", + msg.rle_list[96] + ); + assert_eq!( + msg.rle_list[97], 142, + "incorrect value for rle_list[97], expected 142, is {}", + msg.rle_list[97] + ); + assert_eq!( + msg.rle_list[98], 89, + "incorrect value for rle_list[98], expected 89, is {}", + msg.rle_list[98] + ); + assert_eq!( + msg.rle_list[99], 12, + "incorrect value for rle_list[99], expected 12, is {}", + msg.rle_list[99] + ); + assert_eq!( + msg.rle_list[100], 121, + "incorrect value for rle_list[100], expected 121, is {}", + msg.rle_list[100] + ); + assert_eq!( + msg.rle_list[101], 29, + "incorrect value for rle_list[101], expected 29, is {}", + msg.rle_list[101] + ); + assert_eq!( + msg.rle_list[102], 124, + "incorrect value for rle_list[102], expected 124, is {}", + msg.rle_list[102] + ); + assert_eq!( + msg.rle_list[103], 9, + "incorrect value for rle_list[103], expected 9, is {}", + msg.rle_list[103] + ); + assert_eq!( + msg.rle_list[104], 19, + "incorrect value for rle_list[104], expected 19, is {}", + msg.rle_list[104] + ); + assert_eq!( + msg.rle_list[105], 153, + "incorrect value for rle_list[105], expected 153, is {}", + msg.rle_list[105] + ); + assert_eq!( + msg.rle_list[106], 44, + "incorrect value for rle_list[106], expected 44, is {}", + msg.rle_list[106] + ); + assert_eq!( + msg.rle_list[107], 35, + "incorrect value for rle_list[107], expected 35, is {}", + msg.rle_list[107] + ); + assert_eq!( + msg.rle_list[108], 126, + "incorrect value for rle_list[108], expected 126, is {}", + msg.rle_list[108] + ); + assert_eq!( + msg.rle_list[109], 14, + "incorrect value for rle_list[109], expected 14, is {}", + msg.rle_list[109] + ); + assert_eq!( + msg.rle_list[110], 217, + "incorrect value for rle_list[110], expected 217, is {}", + msg.rle_list[110] + ); + assert_eq!( + msg.rle_list[111], 65, + "incorrect value for rle_list[111], expected 65, is {}", + msg.rle_list[111] + ); + assert_eq!( + msg.rle_list[112], 116, + "incorrect value for rle_list[112], expected 116, is {}", + msg.rle_list[112] + ); + assert_eq!( + msg.rle_list[113], 26, + "incorrect value for rle_list[113], expected 26, is {}", + msg.rle_list[113] + ); + assert_eq!( + msg.rle_list[114], 139, + "incorrect value for rle_list[114], expected 139, is {}", + msg.rle_list[114] + ); + assert_eq!( + msg.rle_list[115], 122, + "incorrect value for rle_list[115], expected 122, is {}", + msg.rle_list[115] + ); + assert_eq!( + msg.rle_list[116], 114, + "incorrect value for rle_list[116], expected 114, is {}", + msg.rle_list[116] + ); + assert_eq!( + msg.rle_list[117], 90, + "incorrect value for rle_list[117], expected 90, is {}", + msg.rle_list[117] + ); + assert_eq!( + msg.rle_list[118], 124, + "incorrect value for rle_list[118], expected 124, is {}", + msg.rle_list[118] + ); + assert_eq!( + msg.rle_list[119], 81, + "incorrect value for rle_list[119], expected 81, is {}", + msg.rle_list[119] + ); + assert_eq!( + msg.rle_list[120], 0, + "incorrect value for rle_list[120], expected 0, is {}", + msg.rle_list[120] + ); + assert_eq!( + msg.rle_list[121], 186, + "incorrect value for rle_list[121], expected 186, is {}", + msg.rle_list[121] + ); + assert_eq!( + msg.rle_list[122], 246, + "incorrect value for rle_list[122], expected 246, is {}", + msg.rle_list[122] + ); + assert_eq!( + msg.rle_list[123], 46, + "incorrect value for rle_list[123], expected 46, is {}", + msg.rle_list[123] + ); + assert_eq!( + msg.rle_list[124], 98, + "incorrect value for rle_list[124], expected 98, is {}", + msg.rle_list[124] + ); + assert_eq!( + msg.rle_list[125], 179, + "incorrect value for rle_list[125], expected 179, is {}", + msg.rle_list[125] + ); + assert_eq!( + msg.rle_list[126], 243, + "incorrect value for rle_list[126], expected 243, is {}", + msg.rle_list[126] + ); + assert_eq!( + msg.rle_list[127], 198, + "incorrect value for rle_list[127], expected 198, is {}", + msg.rle_list[127] + ); + assert_eq!( + msg.rle_list[128], 217, + "incorrect value for rle_list[128], expected 217, is {}", + msg.rle_list[128] + ); + assert_eq!( + msg.rle_list[129], 36, + "incorrect value for rle_list[129], expected 36, is {}", + msg.rle_list[129] + ); + assert_eq!( + msg.rle_list[130], 30, + "incorrect value for rle_list[130], expected 30, is {}", + msg.rle_list[130] + ); + assert_eq!( + msg.rle_list[131], 202, + "incorrect value for rle_list[131], expected 202, is {}", + msg.rle_list[131] + ); + assert_eq!( + msg.rle_list[132], 12, + "incorrect value for rle_list[132], expected 12, is {}", + msg.rle_list[132] + ); + assert_eq!( + msg.rle_list[133], 135, + "incorrect value for rle_list[133], expected 135, is {}", + msg.rle_list[133] + ); + assert_eq!( + msg.rle_list[134], 61, + "incorrect value for rle_list[134], expected 61, is {}", + msg.rle_list[134] + ); + assert_eq!( + msg.rle_list[135], 42, + "incorrect value for rle_list[135], expected 42, is {}", + msg.rle_list[135] + ); + assert_eq!( + msg.rle_list[136], 150, + "incorrect value for rle_list[136], expected 150, is {}", + msg.rle_list[136] + ); + assert_eq!( + msg.rle_list[137], 221, + "incorrect value for rle_list[137], expected 221, is {}", + msg.rle_list[137] + ); + assert_eq!( + msg.rle_list[138], 102, + "incorrect value for rle_list[138], expected 102, is {}", + msg.rle_list[138] + ); + assert_eq!( + msg.rle_list[139], 83, + "incorrect value for rle_list[139], expected 83, is {}", + msg.rle_list[139] + ); + assert_eq!( + msg.rle_list[140], 179, + "incorrect value for rle_list[140], expected 179, is {}", + msg.rle_list[140] + ); + assert_eq!( + msg.rle_list[141], 43, + "incorrect value for rle_list[141], expected 43, is {}", + msg.rle_list[141] + ); + assert_eq!( + msg.rle_list[142], 252, + "incorrect value for rle_list[142], expected 252, is {}", + msg.rle_list[142] + ); + assert_eq!( + msg.rle_list[143], 81, + "incorrect value for rle_list[143], expected 81, is {}", + msg.rle_list[143] + ); + assert_eq!( + msg.rle_list[144], 62, + "incorrect value for rle_list[144], expected 62, is {}", + msg.rle_list[144] + ); + assert_eq!( + msg.rle_list[145], 126, + "incorrect value for rle_list[145], expected 126, is {}", + msg.rle_list[145] + ); + assert_eq!( + msg.rle_list[146], 204, + "incorrect value for rle_list[146], expected 204, is {}", + msg.rle_list[146] + ); + assert_eq!( + msg.rle_list[147], 195, + "incorrect value for rle_list[147], expected 195, is {}", + msg.rle_list[147] + ); + assert_eq!( + msg.rle_list[148], 238, + "incorrect value for rle_list[148], expected 238, is {}", + msg.rle_list[148] + ); + assert_eq!( + msg.rle_list[149], 18, + "incorrect value for rle_list[149], expected 18, is {}", + msg.rle_list[149] + ); + assert_eq!( + msg.rle_list[150], 128, + "incorrect value for rle_list[150], expected 128, is {}", + msg.rle_list[150] + ); + assert_eq!( + msg.rle_list[151], 193, + "incorrect value for rle_list[151], expected 193, is {}", + msg.rle_list[151] + ); + assert_eq!( + msg.rle_list[152], 53, + "incorrect value for rle_list[152], expected 53, is {}", + msg.rle_list[152] + ); + assert_eq!( + msg.rle_list[153], 94, + "incorrect value for rle_list[153], expected 94, is {}", + msg.rle_list[153] + ); + assert_eq!( + msg.rle_list[154], 99, + "incorrect value for rle_list[154], expected 99, is {}", + msg.rle_list[154] + ); + assert_eq!( + msg.rle_list[155], 63, + "incorrect value for rle_list[155], expected 63, is {}", + msg.rle_list[155] + ); + assert_eq!( + msg.rle_list[156], 182, + "incorrect value for rle_list[156], expected 182, is {}", + msg.rle_list[156] + ); + assert_eq!( + msg.rle_list[157], 2, + "incorrect value for rle_list[157], expected 2, is {}", + msg.rle_list[157] + ); + assert_eq!( + msg.rle_list[158], 186, + "incorrect value for rle_list[158], expected 186, is {}", + msg.rle_list[158] + ); + assert_eq!( + msg.rle_list[159], 220, + "incorrect value for rle_list[159], expected 220, is {}", + msg.rle_list[159] + ); + assert_eq!( + msg.rle_list[160], 77, + "incorrect value for rle_list[160], expected 77, is {}", + msg.rle_list[160] + ); + assert_eq!( + msg.rle_list[161], 186, + "incorrect value for rle_list[161], expected 186, is {}", + msg.rle_list[161] + ); + assert_eq!( + msg.rle_list[162], 224, + "incorrect value for rle_list[162], expected 224, is {}", + msg.rle_list[162] + ); + assert_eq!( + msg.rle_list[163], 220, + "incorrect value for rle_list[163], expected 220, is {}", + msg.rle_list[163] + ); + assert_eq!( + msg.rle_list[164], 13, + "incorrect value for rle_list[164], expected 13, is {}", + msg.rle_list[164] + ); + assert_eq!( + msg.rle_list[165], 212, + "incorrect value for rle_list[165], expected 212, is {}", + msg.rle_list[165] + ); + assert_eq!( + msg.rle_list[166], 182, + "incorrect value for rle_list[166], expected 182, is {}", + msg.rle_list[166] + ); + assert_eq!( + msg.rle_list[167], 88, + "incorrect value for rle_list[167], expected 88, is {}", + msg.rle_list[167] + ); + assert_eq!( + msg.rle_list[168], 15, + "incorrect value for rle_list[168], expected 15, is {}", + msg.rle_list[168] + ); + assert_eq!( + msg.rle_list[169], 151, + "incorrect value for rle_list[169], expected 151, is {}", + msg.rle_list[169] + ); + assert_eq!( + msg.rle_list[170], 5, + "incorrect value for rle_list[170], expected 5, is {}", + msg.rle_list[170] + ); + assert_eq!( + msg.rle_list[171], 93, + "incorrect value for rle_list[171], expected 93, is {}", + msg.rle_list[171] + ); + assert_eq!( + msg.rle_list[172], 251, + "incorrect value for rle_list[172], expected 251, is {}", + msg.rle_list[172] + ); + assert_eq!( + msg.rle_list[173], 164, + "incorrect value for rle_list[173], expected 164, is {}", + msg.rle_list[173] + ); + assert_eq!( + msg.rle_list[174], 18, + "incorrect value for rle_list[174], expected 18, is {}", + msg.rle_list[174] + ); + assert_eq!( + msg.rle_list[175], 228, + "incorrect value for rle_list[175], expected 228, is {}", + msg.rle_list[175] + ); + assert_eq!( + msg.rle_list[176], 168, + "incorrect value for rle_list[176], expected 168, is {}", + msg.rle_list[176] + ); + assert_eq!( + msg.rle_list[177], 226, + "incorrect value for rle_list[177], expected 226, is {}", + msg.rle_list[177] + ); + assert_eq!( + msg.rle_list[178], 195, + "incorrect value for rle_list[178], expected 195, is {}", + msg.rle_list[178] + ); + assert_eq!( + msg.rle_list[179], 44, + "incorrect value for rle_list[179], expected 44, is {}", + msg.rle_list[179] + ); + assert_eq!( + msg.rle_list[180], 170, + "incorrect value for rle_list[180], expected 170, is {}", + msg.rle_list[180] + ); + assert_eq!( + msg.rle_list[181], 145, + "incorrect value for rle_list[181], expected 145, is {}", + msg.rle_list[181] + ); + assert_eq!( + msg.rle_list[182], 36, + "incorrect value for rle_list[182], expected 36, is {}", + msg.rle_list[182] + ); + assert_eq!( + msg.rle_list[183], 58, + "incorrect value for rle_list[183], expected 58, is {}", + msg.rle_list[183] + ); + assert_eq!( + msg.rle_list[184], 96, + "incorrect value for rle_list[184], expected 96, is {}", + msg.rle_list[184] + ); + assert_eq!( + msg.rle_list[185], 107, + "incorrect value for rle_list[185], expected 107, is {}", + msg.rle_list[185] + ); + assert_eq!( + msg.rle_list[186], 144, + "incorrect value for rle_list[186], expected 144, is {}", + msg.rle_list[186] + ); + assert_eq!( + msg.rle_list[187], 11, + "incorrect value for rle_list[187], expected 11, is {}", + msg.rle_list[187] + ); + assert_eq!( + msg.rle_list[188], 228, + "incorrect value for rle_list[188], expected 228, is {}", + msg.rle_list[188] + ); + assert_eq!( + msg.rle_list[189], 12, + "incorrect value for rle_list[189], expected 12, is {}", + msg.rle_list[189] + ); + assert_eq!( + msg.rle_list[190], 163, + "incorrect value for rle_list[190], expected 163, is {}", + msg.rle_list[190] + ); + assert_eq!( + msg.rle_list[191], 238, + "incorrect value for rle_list[191], expected 238, is {}", + msg.rle_list[191] + ); + assert_eq!( + msg.rle_list[192], 247, + "incorrect value for rle_list[192], expected 247, is {}", + msg.rle_list[192] + ); + assert_eq!( + msg.rle_list[193], 159, + "incorrect value for rle_list[193], expected 159, is {}", + msg.rle_list[193] + ); + assert_eq!( + msg.rle_list[194], 189, + "incorrect value for rle_list[194], expected 189, is {}", + msg.rle_list[194] + ); + assert_eq!( + msg.rle_list[195], 1, + "incorrect value for rle_list[195], expected 1, is {}", + msg.rle_list[195] + ); + assert_eq!( + msg.rle_list[196], 115, + "incorrect value for rle_list[196], expected 115, is {}", + msg.rle_list[196] + ); + assert_eq!( + msg.rle_list[197], 65, + "incorrect value for rle_list[197], expected 65, is {}", + msg.rle_list[197] + ); + assert_eq!( + msg.rle_list[198], 202, + "incorrect value for rle_list[198], expected 202, is {}", + msg.rle_list[198] + ); + assert_eq!( + msg.rle_list[199], 121, + "incorrect value for rle_list[199], expected 121, is {}", + msg.rle_list[199] + ); + assert_eq!( + msg.rle_list[200], 47, + "incorrect value for rle_list[200], expected 47, is {}", + msg.rle_list[200] + ); + assert_eq!( + msg.rle_list[201], 193, + "incorrect value for rle_list[201], expected 193, is {}", + msg.rle_list[201] + ); + assert_eq!( + msg.rle_list[202], 11, + "incorrect value for rle_list[202], expected 11, is {}", + msg.rle_list[202] + ); + assert_eq!( + msg.rle_list[203], 96, + "incorrect value for rle_list[203], expected 96, is {}", + msg.rle_list[203] + ); + assert_eq!( + msg.rle_list[204], 93, + "incorrect value for rle_list[204], expected 93, is {}", + msg.rle_list[204] + ); + assert_eq!( + msg.rle_list[205], 72, + "incorrect value for rle_list[205], expected 72, is {}", + msg.rle_list[205] + ); + assert_eq!( + msg.rle_list[206], 81, + "incorrect value for rle_list[206], expected 81, is {}", + msg.rle_list[206] + ); + assert_eq!( + msg.rle_list[207], 207, + "incorrect value for rle_list[207], expected 207, is {}", + msg.rle_list[207] + ); + assert_eq!( + msg.rle_list[208], 121, + "incorrect value for rle_list[208], expected 121, is {}", + msg.rle_list[208] + ); + assert_eq!( + msg.rle_list[209], 19, + "incorrect value for rle_list[209], expected 19, is {}", + msg.rle_list[209] + ); + assert_eq!( + msg.rle_list[210], 151, + "incorrect value for rle_list[210], expected 151, is {}", + msg.rle_list[210] + ); + assert_eq!( + msg.rle_list[211], 136, + "incorrect value for rle_list[211], expected 136, is {}", + msg.rle_list[211] + ); + assert_eq!( + msg.rle_list[212], 233, + "incorrect value for rle_list[212], expected 233, is {}", + msg.rle_list[212] + ); + assert_eq!( + msg.rle_list[213], 51, + "incorrect value for rle_list[213], expected 51, is {}", + msg.rle_list[213] + ); + assert_eq!( + msg.rle_list[214], 133, + "incorrect value for rle_list[214], expected 133, is {}", + msg.rle_list[214] + ); + assert_eq!( + msg.rle_list[215], 195, + "incorrect value for rle_list[215], expected 195, is {}", + msg.rle_list[215] + ); + assert_eq!( + msg.rle_list[216], 77, + "incorrect value for rle_list[216], expected 77, is {}", + msg.rle_list[216] + ); + assert_eq!( + msg.rle_list[217], 44, + "incorrect value for rle_list[217], expected 44, is {}", + msg.rle_list[217] + ); + assert_eq!( + msg.rle_list[218], 147, + "incorrect value for rle_list[218], expected 147, is {}", + msg.rle_list[218] + ); + assert_eq!( + msg.rle_list[219], 206, + "incorrect value for rle_list[219], expected 206, is {}", + msg.rle_list[219] + ); + assert_eq!( + msg.rle_list[220], 120, + "incorrect value for rle_list[220], expected 120, is {}", + msg.rle_list[220] + ); + assert_eq!( + msg.rle_list[221], 252, + "incorrect value for rle_list[221], expected 252, is {}", + msg.rle_list[221] + ); + assert_eq!( + msg.rle_list[222], 77, + "incorrect value for rle_list[222], expected 77, is {}", + msg.rle_list[222] + ); + assert_eq!( + msg.rle_list[223], 212, + "incorrect value for rle_list[223], expected 212, is {}", + msg.rle_list[223] + ); + assert_eq!( + msg.rle_list[224], 68, + "incorrect value for rle_list[224], expected 68, is {}", + msg.rle_list[224] + ); + assert_eq!( + msg.rle_list[225], 60, + "incorrect value for rle_list[225], expected 60, is {}", + msg.rle_list[225] + ); + assert_eq!( + msg.rle_list[226], 206, + "incorrect value for rle_list[226], expected 206, is {}", + msg.rle_list[226] + ); + assert_eq!( + msg.rle_list[227], 106, + "incorrect value for rle_list[227], expected 106, is {}", + msg.rle_list[227] + ); + assert_eq!( + msg.rle_list[228], 207, + "incorrect value for rle_list[228], expected 207, is {}", + msg.rle_list[228] + ); + assert_eq!( + msg.rle_list[229], 243, + "incorrect value for rle_list[229], expected 243, is {}", + msg.rle_list[229] + ); + assert_eq!( + msg.rle_list[230], 158, + "incorrect value for rle_list[230], expected 158, is {}", + msg.rle_list[230] + ); + assert_eq!( + msg.rle_list[231], 94, + "incorrect value for rle_list[231], expected 94, is {}", + msg.rle_list[231] + ); + assert_eq!( + msg.rle_list[232], 6, + "incorrect value for rle_list[232], expected 6, is {}", + msg.rle_list[232] + ); + assert_eq!( + msg.rle_list[233], 3, + "incorrect value for rle_list[233], expected 3, is {}", + msg.rle_list[233] + ); + assert_eq!( + msg.rle_list[234], 205, + "incorrect value for rle_list[234], expected 205, is {}", + msg.rle_list[234] + ); + assert_eq!( + msg.rle_list[235], 92, + "incorrect value for rle_list[235], expected 92, is {}", + msg.rle_list[235] + ); + assert_eq!( + msg.rle_list[236], 84, + "incorrect value for rle_list[236], expected 84, is {}", + msg.rle_list[236] + ); + assert_eq!( + msg.rle_list[237], 2, + "incorrect value for rle_list[237], expected 2, is {}", + msg.rle_list[237] + ); + assert_eq!( + msg.rle_list[238], 220, + "incorrect value for rle_list[238], expected 220, is {}", + msg.rle_list[238] + ); + assert_eq!( + msg.rle_list[239], 50, + "incorrect value for rle_list[239], expected 50, is {}", + msg.rle_list[239] + ); + assert_eq!( + msg.rle_list[240], 61, + "incorrect value for rle_list[240], expected 61, is {}", + msg.rle_list[240] + ); + assert_eq!( + msg.rle_list[241], 38, + "incorrect value for rle_list[241], expected 38, is {}", + msg.rle_list[241] + ); + assert_eq!( + msg.rle_list[242], 141, + "incorrect value for rle_list[242], expected 141, is {}", + msg.rle_list[242] + ); + assert_eq!( + msg.rle_list[243], 117, + "incorrect value for rle_list[243], expected 117, is {}", + msg.rle_list[243] + ); + assert_eq!( + msg.rle_list[244], 108, + "incorrect value for rle_list[244], expected 108, is {}", + msg.rle_list[244] + ); + assert_eq!( + msg.rle_list[245], 101, + "incorrect value for rle_list[245], expected 101, is {}", + msg.rle_list[245] + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGridDefinitionDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction.rs new file mode 100644 index 0000000000..ea508f608e --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction.rs @@ -0,0 +1,2620 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_gridded_correction() { + { + let mut payload = Cursor::new(vec![ + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, 174, 229, 151, 189, 204, + 196, 105, 170, 120, 149, 169, 37, 244, 78, 72, 140, 101, 2, 173, 88, 70, 180, 54, 152, + 115, 78, 201, 161, 23, 135, 152, 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, 230, + 69, 172, 191, 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, 52, 166, 166, 120, 57, 221, + 12, 3, 156, 70, 156, 35, 127, 8, 127, 58, 128, 55, 115, 80, 157, 122, 153, 124, 27, + 128, 98, 103, 204, 75, 238, 128, 226, 148, 248, 61, 216, 208, 149, 167, 224, 40, 144, + 186, 157, 227, 72, 240, 100, 35, 12, 212, 7, 59, 176, 81, 86, 27, 24, 155, 67, 43, 132, + 45, 203, 44, 6, 112, 183, 231, 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, 23, 62, + 227, 240, 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, 176, 201, 202, 91, 105, 115, + 146, 59, 110, 44, 109, 128, 183, 185, 67, 31, 165, 92, 79, 189, 180, 94, 7, 162, 121, + 156, 210, 47, 7, 7, 205, 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, + 219, 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, 247, 64, 189, + 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, 45, 251, 239, 115, 88, 218, 10, 209, + 120, 65, 175, 131, 194, 41, 174, 137, 17, 68, 28, 253, 42, 178, 35, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrection(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fc, + "Incorrect message type, expected 0x5fc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf9c4, + "incorrect sender id, expected 0xf9c4, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 170, + "incorrect value for header.iod_atmo, expected 170, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 48535, + "incorrect value for header.num_msgs, expected 48535, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 50380, + "incorrect value for header.seq_num, expected 50380, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 12951, + "incorrect value for header.tile_id, expected 12951, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 3605, + "incorrect value for header.tile_set_id, expected 3605, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 2535294328, + "incorrect value for header.time.tow, expected 2535294328, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 58798, + "incorrect value for header.time.wn, expected 58798, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 120, + "incorrect value for header.tropo_quality_indicator, expected 120, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 105, + "incorrect value for header.update_interval, expected 105, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 43413, + "incorrect value for index, expected 43413, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -21246, + "incorrect value for stec_residuals[0].residual, expected -21246, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 88, + "incorrect value for stec_residuals[0].stddev, expected 88, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 101, "incorrect value for stec_residuals[0].sv_id.constellation, expected 101, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 140, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 140, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, -26570, + "incorrect value for stec_residuals[1].residual, expected -26570, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 115, + "incorrect value for stec_residuals[1].stddev, expected 115, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 180, "incorrect value for stec_residuals[1].sv_id.constellation, expected 180, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 70, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 6049, + "incorrect value for stec_residuals[2].residual, expected 6049, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 135, + "incorrect value for stec_residuals[2].stddev, expected 135, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 201, "incorrect value for stec_residuals[2].sv_id.constellation, expected 201, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 78, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 78, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, 19261, + "incorrect value for stec_residuals[3].residual, expected 19261, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 178, + "incorrect value for stec_residuals[3].stddev, expected 178, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 98, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 98, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 152, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 152, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 14226, + "incorrect value for stec_residuals[4].residual, expected 14226, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 58, + "incorrect value for stec_residuals[4].stddev, expected 58, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 229, "incorrect value for stec_residuals[4].sv_id.constellation, expected 229, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 120, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 120, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 17894, + "incorrect value for stec_residuals[5].residual, expected 17894, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 172, + "incorrect value for stec_residuals[5].stddev, expected 172, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 234, "incorrect value for stec_residuals[5].sv_id.constellation, expected 234, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 169, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 169, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 22930, + "incorrect value for stec_residuals[6].residual, expected 22930, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 150, + "incorrect value for stec_residuals[6].stddev, expected 150, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 127, "incorrect value for stec_residuals[6].sv_id.constellation, expected 127, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 191, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 191, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 10721, + "incorrect value for stec_residuals[7].residual, expected 10721, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 17, + "incorrect value for stec_residuals[7].stddev, expected 17, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 111, "incorrect value for stec_residuals[7].sv_id.constellation, expected 111, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 91, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 91, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, -22874, + "incorrect value for stec_residuals[8].residual, expected -22874, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 120, + "incorrect value for stec_residuals[8].stddev, expected 120, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 52, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 52, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 119, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 780, + "incorrect value for stec_residuals[9].residual, expected 780, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 156, + "incorrect value for stec_residuals[9].stddev, expected 156, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!(msg.stec_residuals[9].sv_id.constellation, 221, "incorrect value for stec_residuals[9].sv_id.constellation, expected 221, is {}", msg.stec_residuals[9].sv_id.constellation); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 57, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 57, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 32547, + "incorrect value for stec_residuals[10].residual, expected 32547, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 8, + "incorrect value for stec_residuals[10].stddev, expected 8, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 156, "incorrect value for stec_residuals[10].sv_id.constellation, expected 156, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 70, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 14208, + "incorrect value for stec_residuals[11].residual, expected 14208, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 115, + "incorrect value for stec_residuals[11].stddev, expected 115, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 58, "incorrect value for stec_residuals[11].sv_id.constellation, expected 58, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 127, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 127, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -26246, + "incorrect value for stec_residuals[12].residual, expected -26246, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 124, + "incorrect value for stec_residuals[12].stddev, expected 124, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 157, "incorrect value for stec_residuals[12].sv_id.constellation, expected 157, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 80, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 80, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, 26466, + "incorrect value for stec_residuals[13].residual, expected 26466, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 204, + "incorrect value for stec_residuals[13].stddev, expected 204, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 128, "incorrect value for stec_residuals[13].sv_id.constellation, expected 128, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 27, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 27, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -7552, + "incorrect value for stec_residuals[14].residual, expected -7552, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 148, + "incorrect value for stec_residuals[14].stddev, expected 148, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 238, "incorrect value for stec_residuals[14].sv_id.constellation, expected 238, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 75, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 75, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, -12072, + "incorrect value for stec_residuals[15].residual, expected -12072, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 149, + "incorrect value for stec_residuals[15].stddev, expected 149, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 61, "incorrect value for stec_residuals[15].sv_id.constellation, expected 61, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 248, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -28632, + "incorrect value for stec_residuals[16].residual, expected -28632, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 186, + "incorrect value for stec_residuals[16].stddev, expected 186, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 224, "incorrect value for stec_residuals[16].sv_id.constellation, expected 224, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 167, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 167, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, -4024, + "incorrect value for stec_residuals[17].residual, expected -4024, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 100, + "incorrect value for stec_residuals[17].stddev, expected 100, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 227, "incorrect value for stec_residuals[17].sv_id.constellation, expected 227, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 157, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 2004, + "incorrect value for stec_residuals[18].residual, expected 2004, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 59, + "incorrect value for stec_residuals[18].stddev, expected 59, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 12, "incorrect value for stec_residuals[18].sv_id.constellation, expected 12, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 35, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 35, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 6998, + "incorrect value for stec_residuals[19].residual, expected 6998, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 24, + "incorrect value for stec_residuals[19].stddev, expected 24, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 81, "incorrect value for stec_residuals[19].sv_id.constellation, expected 81, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 176, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 176, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -31701, + "incorrect value for stec_residuals[20].residual, expected -31701, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 45, + "incorrect value for stec_residuals[20].stddev, expected 45, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 67, "incorrect value for stec_residuals[20].sv_id.constellation, expected 67, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 155, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 155, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 28678, + "incorrect value for stec_residuals[21].residual, expected 28678, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 183, + "incorrect value for stec_residuals[21].stddev, expected 183, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 44, "incorrect value for stec_residuals[21].sv_id.constellation, expected 44, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 203, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -15793, + "incorrect value for stec_residuals[22].residual, expected -15793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 253, + "incorrect value for stec_residuals[22].stddev, expected 253, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 176, "incorrect value for stec_residuals[22].sv_id.constellation, expected 176, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 231, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -7589, + "incorrect value for stec_residuals[23].residual, expected -7589, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 116, + "incorrect value for stec_residuals[23].stddev, expected 116, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 103, "incorrect value for stec_residuals[23].sv_id.constellation, expected 103, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 247, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -7362, + "incorrect value for stec_residuals[24].residual, expected -7362, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 240, + "incorrect value for stec_residuals[24].stddev, expected 240, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 23, "incorrect value for stec_residuals[24].sv_id.constellation, expected 23, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 148, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 148, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 4813, + "incorrect value for stec_residuals[25].residual, expected 4813, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 242, + "incorrect value for stec_residuals[25].stddev, expected 242, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 219, "incorrect value for stec_residuals[25].sv_id.constellation, expected 219, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 29, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 29, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20295, + "incorrect value for stec_residuals[26].residual, expected 20295, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 37, + "incorrect value for stec_residuals[26].stddev, expected 37, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 72, "incorrect value for stec_residuals[26].sv_id.constellation, expected 72, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 207, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -13623, + "incorrect value for stec_residuals[27].residual, expected -13623, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 91, + "incorrect value for stec_residuals[27].stddev, expected 91, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 176, "incorrect value for stec_residuals[27].sv_id.constellation, expected 176, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 42, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 15250, + "incorrect value for stec_residuals[28].residual, expected 15250, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 110, + "incorrect value for stec_residuals[28].stddev, expected 110, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 115, "incorrect value for stec_residuals[28].sv_id.constellation, expected 115, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 105, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 105, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, -18560, + "incorrect value for stec_residuals[29].residual, expected -18560, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 185, + "incorrect value for stec_residuals[29].stddev, expected 185, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 109, "incorrect value for stec_residuals[29].sv_id.constellation, expected 109, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 44, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 44, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 23717, + "incorrect value for stec_residuals[30].residual, expected 23717, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 79, + "incorrect value for stec_residuals[30].stddev, expected 79, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 31, "incorrect value for stec_residuals[30].sv_id.constellation, expected 31, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 67, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 67, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 1886, + "incorrect value for stec_residuals[31].residual, expected 1886, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 162, + "incorrect value for stec_residuals[31].stddev, expected 162, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 180, "incorrect value for stec_residuals[31].sv_id.constellation, expected 180, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 189, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 189, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 12242, + "incorrect value for stec_residuals[32].residual, expected 12242, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 7, + "incorrect value for stec_residuals[32].stddev, expected 7, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 156, "incorrect value for stec_residuals[32].sv_id.constellation, expected 156, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 121, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 121, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 10670, + "incorrect value for stec_residuals[33].residual, expected 10670, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 241, + "incorrect value for stec_residuals[33].stddev, expected 241, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 205, "incorrect value for stec_residuals[33].sv_id.constellation, expected 205, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 7, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 7, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 25899, + "incorrect value for stec_residuals[34].residual, expected 25899, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 186, + "incorrect value for stec_residuals[34].stddev, expected 186, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 210, "incorrect value for stec_residuals[34].sv_id.constellation, expected 210, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 129, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 129, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -2078, + "incorrect value for stec_residuals[35].residual, expected -2078, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 187, + "incorrect value for stec_residuals[35].stddev, expected 187, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 195, "incorrect value for stec_residuals[35].sv_id.constellation, expected 195, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 208, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 208, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -16264, + "incorrect value for stec_residuals[36].residual, expected -16264, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 102, + "incorrect value for stec_residuals[36].stddev, expected 102, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 160, "incorrect value for stec_residuals[36].sv_id.constellation, expected 160, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 219, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 219, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -21002, + "incorrect value for stec_residuals[37].residual, expected -21002, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 94, + "incorrect value for stec_residuals[37].stddev, expected 94, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 42, "incorrect value for stec_residuals[37].sv_id.constellation, expected 42, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 166, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 166, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 7902, + "incorrect value for stec_residuals[38].residual, expected 7902, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 35, + "incorrect value for stec_residuals[38].stddev, expected 35, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 156, "incorrect value for stec_residuals[38].sv_id.constellation, expected 156, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 102, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 102, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -30275, + "incorrect value for stec_residuals[39].residual, expected -30275, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 204, + "incorrect value for stec_residuals[39].stddev, expected 204, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 64, "incorrect value for stec_residuals[39].sv_id.constellation, expected 64, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 247, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -8633, + "incorrect value for stec_residuals[40].residual, expected -8633, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 222, + "incorrect value for stec_residuals[40].stddev, expected 222, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 32, "incorrect value for stec_residuals[40].sv_id.constellation, expected 32, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 220, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 220, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 6403, + "incorrect value for stec_residuals[41].residual, expected 6403, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 45, + "incorrect value for stec_residuals[41].stddev, expected 45, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 246, "incorrect value for stec_residuals[41].sv_id.constellation, expected 246, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 201, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 22643, + "incorrect value for stec_residuals[42].residual, expected 22643, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 218, + "incorrect value for stec_residuals[42].stddev, expected 218, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 239, "incorrect value for stec_residuals[42].sv_id.constellation, expected 239, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 251, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 251, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 16760, + "incorrect value for stec_residuals[43].residual, expected 16760, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 175, + "incorrect value for stec_residuals[43].stddev, expected 175, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 209, "incorrect value for stec_residuals[43].sv_id.constellation, expected 209, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 10, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 10, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, -20951, + "incorrect value for stec_residuals[44].residual, expected -20951, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 137, + "incorrect value for stec_residuals[44].stddev, expected 137, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 194, "incorrect value for stec_residuals[44].sv_id.constellation, expected 194, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 131, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 131, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, -740, + "incorrect value for stec_residuals[45].residual, expected -740, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 42, + "incorrect value for stec_residuals[45].stddev, expected 42, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 68, "incorrect value for stec_residuals[45].sv_id.constellation, expected 68, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 17, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 17, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, -3035, + "incorrect value for tropo_delay_correction.hydro, expected -3035, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 72, + "incorrect value for tropo_delay_correction.stddev, expected 72, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 78, + "incorrect value for tropo_delay_correction.wet, expected 78, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrection"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_gridded_correction() { + { + let json_input = r#"{"crc":9138,"length":253,"msg_type":1532,"payload":"FQ6XMniFHZeu5Ze9zMRpqniVqSX0TkiMZQKtWEa0NphzTsmhF4eYYj1Lsnjlkjc6qermRay/f5JZlltv4SkRdzSmpng53QwDnEacI38IfzqAN3NQnXqZfBuAYmfMS+6A4pT4PdjQlafgKJC6neNI8GQjDNQHO7BRVhsYm0MrhC3LLAZwt+ewT8L992db4nSUFz7j8B3bzRLyz0hHTyUqsMnKW2lzkjtuLG2At7lDH6VcT720XgeieZzSLwcHza4p8YHSK2W60MPi97vboHjAZqYq9q1eZpzeHiP3QL2JzNwgR97eyfYDGS3773NY2grReEGvg8IprokRRBz9Kg==","preamble":85,"sender":63940,"header":{"tile_set_id":3605,"tile_id":12951,"time":{"tow":2535294328,"wn":58798},"num_msgs":48535,"seq_num":50380,"update_interval":105,"iod_atmo":170,"tropo_quality_indicator":120},"index":43413,"tropo_delay_correction":{"hydro":-3035,"wet":78,"stddev":72},"stec_residuals":[{"sv_id":{"satId":140,"constellation":101},"residual":-21246,"stddev":88},{"sv_id":{"satId":70,"constellation":180},"residual":-26570,"stddev":115},{"sv_id":{"satId":78,"constellation":201},"residual":6049,"stddev":135},{"sv_id":{"satId":152,"constellation":98},"residual":19261,"stddev":178},{"sv_id":{"satId":120,"constellation":229},"residual":14226,"stddev":58},{"sv_id":{"satId":169,"constellation":234},"residual":17894,"stddev":172},{"sv_id":{"satId":191,"constellation":127},"residual":22930,"stddev":150},{"sv_id":{"satId":91,"constellation":111},"residual":10721,"stddev":17},{"sv_id":{"satId":119,"constellation":52},"residual":-22874,"stddev":120},{"sv_id":{"satId":57,"constellation":221},"residual":780,"stddev":156},{"sv_id":{"satId":70,"constellation":156},"residual":32547,"stddev":8},{"sv_id":{"satId":127,"constellation":58},"residual":14208,"stddev":115},{"sv_id":{"satId":80,"constellation":157},"residual":-26246,"stddev":124},{"sv_id":{"satId":27,"constellation":128},"residual":26466,"stddev":204},{"sv_id":{"satId":75,"constellation":238},"residual":-7552,"stddev":148},{"sv_id":{"satId":248,"constellation":61},"residual":-12072,"stddev":149},{"sv_id":{"satId":167,"constellation":224},"residual":-28632,"stddev":186},{"sv_id":{"satId":157,"constellation":227},"residual":-4024,"stddev":100},{"sv_id":{"satId":35,"constellation":12},"residual":2004,"stddev":59},{"sv_id":{"satId":176,"constellation":81},"residual":6998,"stddev":24},{"sv_id":{"satId":155,"constellation":67},"residual":-31701,"stddev":45},{"sv_id":{"satId":203,"constellation":44},"residual":28678,"stddev":183},{"sv_id":{"satId":231,"constellation":176},"residual":-15793,"stddev":253},{"sv_id":{"satId":247,"constellation":103},"residual":-7589,"stddev":116},{"sv_id":{"satId":148,"constellation":23},"residual":-7362,"stddev":240},{"sv_id":{"satId":29,"constellation":219},"residual":4813,"stddev":242},{"sv_id":{"satId":207,"constellation":72},"residual":20295,"stddev":37},{"sv_id":{"satId":42,"constellation":176},"residual":-13623,"stddev":91},{"sv_id":{"satId":105,"constellation":115},"residual":15250,"stddev":110},{"sv_id":{"satId":44,"constellation":109},"residual":-18560,"stddev":185},{"sv_id":{"satId":67,"constellation":31},"residual":23717,"stddev":79},{"sv_id":{"satId":189,"constellation":180},"residual":1886,"stddev":162},{"sv_id":{"satId":121,"constellation":156},"residual":12242,"stddev":7},{"sv_id":{"satId":7,"constellation":205},"residual":10670,"stddev":241},{"sv_id":{"satId":129,"constellation":210},"residual":25899,"stddev":186},{"sv_id":{"satId":208,"constellation":195},"residual":-2078,"stddev":187},{"sv_id":{"satId":219,"constellation":160},"residual":-16264,"stddev":102},{"sv_id":{"satId":166,"constellation":42},"residual":-21002,"stddev":94},{"sv_id":{"satId":102,"constellation":156},"residual":7902,"stddev":35},{"sv_id":{"satId":247,"constellation":64},"residual":-30275,"stddev":204},{"sv_id":{"satId":220,"constellation":32},"residual":-8633,"stddev":222},{"sv_id":{"satId":201,"constellation":246},"residual":6403,"stddev":45},{"sv_id":{"satId":251,"constellation":239},"residual":22643,"stddev":218},{"sv_id":{"satId":10,"constellation":209},"residual":16760,"stddev":175},{"sv_id":{"satId":131,"constellation":194},"residual":-20951,"stddev":137},{"sv_id":{"satId":17,"constellation":68},"residual":-740,"stddev":42}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrection(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fc, + "Incorrect message type, expected 0x5fc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf9c4, + "incorrect sender id, expected 0xf9c4, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 170, + "incorrect value for header.iod_atmo, expected 170, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 48535, + "incorrect value for header.num_msgs, expected 48535, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 50380, + "incorrect value for header.seq_num, expected 50380, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 12951, + "incorrect value for header.tile_id, expected 12951, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 3605, + "incorrect value for header.tile_set_id, expected 3605, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 2535294328, + "incorrect value for header.time.tow, expected 2535294328, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 58798, + "incorrect value for header.time.wn, expected 58798, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 120, + "incorrect value for header.tropo_quality_indicator, expected 120, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 105, + "incorrect value for header.update_interval, expected 105, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 43413, + "incorrect value for index, expected 43413, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -21246, + "incorrect value for stec_residuals[0].residual, expected -21246, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 88, + "incorrect value for stec_residuals[0].stddev, expected 88, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 101, "incorrect value for stec_residuals[0].sv_id.constellation, expected 101, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 140, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 140, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, -26570, + "incorrect value for stec_residuals[1].residual, expected -26570, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 115, + "incorrect value for stec_residuals[1].stddev, expected 115, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 180, "incorrect value for stec_residuals[1].sv_id.constellation, expected 180, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 70, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 6049, + "incorrect value for stec_residuals[2].residual, expected 6049, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 135, + "incorrect value for stec_residuals[2].stddev, expected 135, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 201, "incorrect value for stec_residuals[2].sv_id.constellation, expected 201, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 78, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 78, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, 19261, + "incorrect value for stec_residuals[3].residual, expected 19261, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 178, + "incorrect value for stec_residuals[3].stddev, expected 178, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 98, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 98, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 152, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 152, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 14226, + "incorrect value for stec_residuals[4].residual, expected 14226, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 58, + "incorrect value for stec_residuals[4].stddev, expected 58, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 229, "incorrect value for stec_residuals[4].sv_id.constellation, expected 229, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 120, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 120, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 17894, + "incorrect value for stec_residuals[5].residual, expected 17894, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 172, + "incorrect value for stec_residuals[5].stddev, expected 172, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 234, "incorrect value for stec_residuals[5].sv_id.constellation, expected 234, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 169, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 169, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 22930, + "incorrect value for stec_residuals[6].residual, expected 22930, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 150, + "incorrect value for stec_residuals[6].stddev, expected 150, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 127, "incorrect value for stec_residuals[6].sv_id.constellation, expected 127, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 191, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 191, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 10721, + "incorrect value for stec_residuals[7].residual, expected 10721, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 17, + "incorrect value for stec_residuals[7].stddev, expected 17, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 111, "incorrect value for stec_residuals[7].sv_id.constellation, expected 111, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 91, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 91, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, -22874, + "incorrect value for stec_residuals[8].residual, expected -22874, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 120, + "incorrect value for stec_residuals[8].stddev, expected 120, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 52, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 52, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 119, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 780, + "incorrect value for stec_residuals[9].residual, expected 780, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 156, + "incorrect value for stec_residuals[9].stddev, expected 156, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!(msg.stec_residuals[9].sv_id.constellation, 221, "incorrect value for stec_residuals[9].sv_id.constellation, expected 221, is {}", msg.stec_residuals[9].sv_id.constellation); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 57, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 57, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 32547, + "incorrect value for stec_residuals[10].residual, expected 32547, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 8, + "incorrect value for stec_residuals[10].stddev, expected 8, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 156, "incorrect value for stec_residuals[10].sv_id.constellation, expected 156, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 70, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 14208, + "incorrect value for stec_residuals[11].residual, expected 14208, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 115, + "incorrect value for stec_residuals[11].stddev, expected 115, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 58, "incorrect value for stec_residuals[11].sv_id.constellation, expected 58, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 127, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 127, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -26246, + "incorrect value for stec_residuals[12].residual, expected -26246, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 124, + "incorrect value for stec_residuals[12].stddev, expected 124, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 157, "incorrect value for stec_residuals[12].sv_id.constellation, expected 157, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 80, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 80, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, 26466, + "incorrect value for stec_residuals[13].residual, expected 26466, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 204, + "incorrect value for stec_residuals[13].stddev, expected 204, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 128, "incorrect value for stec_residuals[13].sv_id.constellation, expected 128, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 27, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 27, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -7552, + "incorrect value for stec_residuals[14].residual, expected -7552, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 148, + "incorrect value for stec_residuals[14].stddev, expected 148, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 238, "incorrect value for stec_residuals[14].sv_id.constellation, expected 238, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 75, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 75, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, -12072, + "incorrect value for stec_residuals[15].residual, expected -12072, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 149, + "incorrect value for stec_residuals[15].stddev, expected 149, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 61, "incorrect value for stec_residuals[15].sv_id.constellation, expected 61, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 248, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -28632, + "incorrect value for stec_residuals[16].residual, expected -28632, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 186, + "incorrect value for stec_residuals[16].stddev, expected 186, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 224, "incorrect value for stec_residuals[16].sv_id.constellation, expected 224, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 167, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 167, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, -4024, + "incorrect value for stec_residuals[17].residual, expected -4024, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 100, + "incorrect value for stec_residuals[17].stddev, expected 100, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 227, "incorrect value for stec_residuals[17].sv_id.constellation, expected 227, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 157, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 2004, + "incorrect value for stec_residuals[18].residual, expected 2004, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 59, + "incorrect value for stec_residuals[18].stddev, expected 59, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 12, "incorrect value for stec_residuals[18].sv_id.constellation, expected 12, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 35, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 35, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 6998, + "incorrect value for stec_residuals[19].residual, expected 6998, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 24, + "incorrect value for stec_residuals[19].stddev, expected 24, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 81, "incorrect value for stec_residuals[19].sv_id.constellation, expected 81, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 176, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 176, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -31701, + "incorrect value for stec_residuals[20].residual, expected -31701, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 45, + "incorrect value for stec_residuals[20].stddev, expected 45, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 67, "incorrect value for stec_residuals[20].sv_id.constellation, expected 67, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 155, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 155, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 28678, + "incorrect value for stec_residuals[21].residual, expected 28678, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 183, + "incorrect value for stec_residuals[21].stddev, expected 183, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 44, "incorrect value for stec_residuals[21].sv_id.constellation, expected 44, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 203, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -15793, + "incorrect value for stec_residuals[22].residual, expected -15793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 253, + "incorrect value for stec_residuals[22].stddev, expected 253, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 176, "incorrect value for stec_residuals[22].sv_id.constellation, expected 176, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 231, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -7589, + "incorrect value for stec_residuals[23].residual, expected -7589, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 116, + "incorrect value for stec_residuals[23].stddev, expected 116, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 103, "incorrect value for stec_residuals[23].sv_id.constellation, expected 103, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 247, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -7362, + "incorrect value for stec_residuals[24].residual, expected -7362, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 240, + "incorrect value for stec_residuals[24].stddev, expected 240, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 23, "incorrect value for stec_residuals[24].sv_id.constellation, expected 23, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 148, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 148, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 4813, + "incorrect value for stec_residuals[25].residual, expected 4813, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 242, + "incorrect value for stec_residuals[25].stddev, expected 242, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 219, "incorrect value for stec_residuals[25].sv_id.constellation, expected 219, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 29, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 29, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20295, + "incorrect value for stec_residuals[26].residual, expected 20295, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 37, + "incorrect value for stec_residuals[26].stddev, expected 37, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 72, "incorrect value for stec_residuals[26].sv_id.constellation, expected 72, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 207, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -13623, + "incorrect value for stec_residuals[27].residual, expected -13623, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 91, + "incorrect value for stec_residuals[27].stddev, expected 91, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 176, "incorrect value for stec_residuals[27].sv_id.constellation, expected 176, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 42, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 15250, + "incorrect value for stec_residuals[28].residual, expected 15250, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 110, + "incorrect value for stec_residuals[28].stddev, expected 110, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 115, "incorrect value for stec_residuals[28].sv_id.constellation, expected 115, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 105, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 105, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, -18560, + "incorrect value for stec_residuals[29].residual, expected -18560, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 185, + "incorrect value for stec_residuals[29].stddev, expected 185, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 109, "incorrect value for stec_residuals[29].sv_id.constellation, expected 109, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 44, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 44, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 23717, + "incorrect value for stec_residuals[30].residual, expected 23717, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 79, + "incorrect value for stec_residuals[30].stddev, expected 79, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 31, "incorrect value for stec_residuals[30].sv_id.constellation, expected 31, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 67, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 67, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 1886, + "incorrect value for stec_residuals[31].residual, expected 1886, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 162, + "incorrect value for stec_residuals[31].stddev, expected 162, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 180, "incorrect value for stec_residuals[31].sv_id.constellation, expected 180, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 189, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 189, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 12242, + "incorrect value for stec_residuals[32].residual, expected 12242, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 7, + "incorrect value for stec_residuals[32].stddev, expected 7, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 156, "incorrect value for stec_residuals[32].sv_id.constellation, expected 156, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 121, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 121, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 10670, + "incorrect value for stec_residuals[33].residual, expected 10670, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 241, + "incorrect value for stec_residuals[33].stddev, expected 241, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 205, "incorrect value for stec_residuals[33].sv_id.constellation, expected 205, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 7, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 7, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 25899, + "incorrect value for stec_residuals[34].residual, expected 25899, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 186, + "incorrect value for stec_residuals[34].stddev, expected 186, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 210, "incorrect value for stec_residuals[34].sv_id.constellation, expected 210, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 129, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 129, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -2078, + "incorrect value for stec_residuals[35].residual, expected -2078, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 187, + "incorrect value for stec_residuals[35].stddev, expected 187, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 195, "incorrect value for stec_residuals[35].sv_id.constellation, expected 195, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 208, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 208, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -16264, + "incorrect value for stec_residuals[36].residual, expected -16264, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 102, + "incorrect value for stec_residuals[36].stddev, expected 102, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 160, "incorrect value for stec_residuals[36].sv_id.constellation, expected 160, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 219, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 219, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -21002, + "incorrect value for stec_residuals[37].residual, expected -21002, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 94, + "incorrect value for stec_residuals[37].stddev, expected 94, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 42, "incorrect value for stec_residuals[37].sv_id.constellation, expected 42, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 166, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 166, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 7902, + "incorrect value for stec_residuals[38].residual, expected 7902, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 35, + "incorrect value for stec_residuals[38].stddev, expected 35, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 156, "incorrect value for stec_residuals[38].sv_id.constellation, expected 156, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 102, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 102, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -30275, + "incorrect value for stec_residuals[39].residual, expected -30275, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 204, + "incorrect value for stec_residuals[39].stddev, expected 204, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 64, "incorrect value for stec_residuals[39].sv_id.constellation, expected 64, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 247, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -8633, + "incorrect value for stec_residuals[40].residual, expected -8633, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 222, + "incorrect value for stec_residuals[40].stddev, expected 222, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 32, "incorrect value for stec_residuals[40].sv_id.constellation, expected 32, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 220, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 220, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 6403, + "incorrect value for stec_residuals[41].residual, expected 6403, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 45, + "incorrect value for stec_residuals[41].stddev, expected 45, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 246, "incorrect value for stec_residuals[41].sv_id.constellation, expected 246, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 201, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 22643, + "incorrect value for stec_residuals[42].residual, expected 22643, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 218, + "incorrect value for stec_residuals[42].stddev, expected 218, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 239, "incorrect value for stec_residuals[42].sv_id.constellation, expected 239, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 251, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 251, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 16760, + "incorrect value for stec_residuals[43].residual, expected 16760, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 175, + "incorrect value for stec_residuals[43].stddev, expected 175, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 209, "incorrect value for stec_residuals[43].sv_id.constellation, expected 209, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 10, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 10, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, -20951, + "incorrect value for stec_residuals[44].residual, expected -20951, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 137, + "incorrect value for stec_residuals[44].stddev, expected 137, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 194, "incorrect value for stec_residuals[44].sv_id.constellation, expected 194, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 131, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 131, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, -740, + "incorrect value for stec_residuals[45].residual, expected -740, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 42, + "incorrect value for stec_residuals[45].stddev, expected 42, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 68, "incorrect value for stec_residuals[45].sv_id.constellation, expected 68, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 17, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 17, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, -3035, + "incorrect value for tropo_delay_correction.hydro, expected -3035, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 72, + "incorrect value for tropo_delay_correction.stddev, expected 72, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 78, + "incorrect value for tropo_delay_correction.wet, expected 78, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrection"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_gridded_correction`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_gridded_correction() { + { + let mut payload = Cursor::new(vec![ + 85, 252, 5, 196, 249, 253, 21, 14, 151, 50, 120, 133, 29, 151, 174, 229, 151, 189, 204, + 196, 105, 170, 120, 149, 169, 37, 244, 78, 72, 140, 101, 2, 173, 88, 70, 180, 54, 152, + 115, 78, 201, 161, 23, 135, 152, 98, 61, 75, 178, 120, 229, 146, 55, 58, 169, 234, 230, + 69, 172, 191, 127, 146, 89, 150, 91, 111, 225, 41, 17, 119, 52, 166, 166, 120, 57, 221, + 12, 3, 156, 70, 156, 35, 127, 8, 127, 58, 128, 55, 115, 80, 157, 122, 153, 124, 27, + 128, 98, 103, 204, 75, 238, 128, 226, 148, 248, 61, 216, 208, 149, 167, 224, 40, 144, + 186, 157, 227, 72, 240, 100, 35, 12, 212, 7, 59, 176, 81, 86, 27, 24, 155, 67, 43, 132, + 45, 203, 44, 6, 112, 183, 231, 176, 79, 194, 253, 247, 103, 91, 226, 116, 148, 23, 62, + 227, 240, 29, 219, 205, 18, 242, 207, 72, 71, 79, 37, 42, 176, 201, 202, 91, 105, 115, + 146, 59, 110, 44, 109, 128, 183, 185, 67, 31, 165, 92, 79, 189, 180, 94, 7, 162, 121, + 156, 210, 47, 7, 7, 205, 174, 41, 241, 129, 210, 43, 101, 186, 208, 195, 226, 247, 187, + 219, 160, 120, 192, 102, 166, 42, 246, 173, 94, 102, 156, 222, 30, 35, 247, 64, 189, + 137, 204, 220, 32, 71, 222, 222, 201, 246, 3, 25, 45, 251, 239, 115, 88, 218, 10, 209, + 120, 65, 175, 131, 194, 41, 174, 137, 17, 68, 28, 253, 42, 178, 35, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrGriddedCorrection( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrection(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fc, + "Incorrect message type, expected 0x5fc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf9c4, + "incorrect sender id, expected 0xf9c4, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 170, + "incorrect value for header.iod_atmo, expected 170, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 48535, + "incorrect value for header.num_msgs, expected 48535, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 50380, + "incorrect value for header.seq_num, expected 50380, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 12951, + "incorrect value for header.tile_id, expected 12951, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 3605, + "incorrect value for header.tile_set_id, expected 3605, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 2535294328, + "incorrect value for header.time.tow, expected 2535294328, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 58798, + "incorrect value for header.time.wn, expected 58798, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 120, + "incorrect value for header.tropo_quality_indicator, expected 120, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 105, + "incorrect value for header.update_interval, expected 105, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 43413, + "incorrect value for index, expected 43413, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -21246, + "incorrect value for stec_residuals[0].residual, expected -21246, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 88, + "incorrect value for stec_residuals[0].stddev, expected 88, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 101, "incorrect value for stec_residuals[0].sv_id.constellation, expected 101, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 140, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 140, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, -26570, + "incorrect value for stec_residuals[1].residual, expected -26570, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 115, + "incorrect value for stec_residuals[1].stddev, expected 115, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 180, "incorrect value for stec_residuals[1].sv_id.constellation, expected 180, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 70, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 6049, + "incorrect value for stec_residuals[2].residual, expected 6049, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 135, + "incorrect value for stec_residuals[2].stddev, expected 135, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 201, "incorrect value for stec_residuals[2].sv_id.constellation, expected 201, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 78, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 78, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, 19261, + "incorrect value for stec_residuals[3].residual, expected 19261, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 178, + "incorrect value for stec_residuals[3].stddev, expected 178, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 98, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 98, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 152, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 152, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 14226, + "incorrect value for stec_residuals[4].residual, expected 14226, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 58, + "incorrect value for stec_residuals[4].stddev, expected 58, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 229, "incorrect value for stec_residuals[4].sv_id.constellation, expected 229, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 120, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 120, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 17894, + "incorrect value for stec_residuals[5].residual, expected 17894, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 172, + "incorrect value for stec_residuals[5].stddev, expected 172, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 234, "incorrect value for stec_residuals[5].sv_id.constellation, expected 234, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 169, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 169, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 22930, + "incorrect value for stec_residuals[6].residual, expected 22930, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 150, + "incorrect value for stec_residuals[6].stddev, expected 150, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 127, "incorrect value for stec_residuals[6].sv_id.constellation, expected 127, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 191, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 191, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 10721, + "incorrect value for stec_residuals[7].residual, expected 10721, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 17, + "incorrect value for stec_residuals[7].stddev, expected 17, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 111, "incorrect value for stec_residuals[7].sv_id.constellation, expected 111, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 91, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 91, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, -22874, + "incorrect value for stec_residuals[8].residual, expected -22874, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 120, + "incorrect value for stec_residuals[8].stddev, expected 120, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 52, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 52, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 119, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 780, + "incorrect value for stec_residuals[9].residual, expected 780, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 156, + "incorrect value for stec_residuals[9].stddev, expected 156, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!(msg.stec_residuals[9].sv_id.constellation, 221, "incorrect value for stec_residuals[9].sv_id.constellation, expected 221, is {}", msg.stec_residuals[9].sv_id.constellation); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 57, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 57, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 32547, + "incorrect value for stec_residuals[10].residual, expected 32547, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 8, + "incorrect value for stec_residuals[10].stddev, expected 8, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 156, "incorrect value for stec_residuals[10].sv_id.constellation, expected 156, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 70, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 70, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 14208, + "incorrect value for stec_residuals[11].residual, expected 14208, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 115, + "incorrect value for stec_residuals[11].stddev, expected 115, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 58, "incorrect value for stec_residuals[11].sv_id.constellation, expected 58, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 127, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 127, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -26246, + "incorrect value for stec_residuals[12].residual, expected -26246, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 124, + "incorrect value for stec_residuals[12].stddev, expected 124, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 157, "incorrect value for stec_residuals[12].sv_id.constellation, expected 157, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 80, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 80, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, 26466, + "incorrect value for stec_residuals[13].residual, expected 26466, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 204, + "incorrect value for stec_residuals[13].stddev, expected 204, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 128, "incorrect value for stec_residuals[13].sv_id.constellation, expected 128, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 27, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 27, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -7552, + "incorrect value for stec_residuals[14].residual, expected -7552, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 148, + "incorrect value for stec_residuals[14].stddev, expected 148, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 238, "incorrect value for stec_residuals[14].sv_id.constellation, expected 238, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 75, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 75, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, -12072, + "incorrect value for stec_residuals[15].residual, expected -12072, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 149, + "incorrect value for stec_residuals[15].stddev, expected 149, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 61, "incorrect value for stec_residuals[15].sv_id.constellation, expected 61, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 248, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -28632, + "incorrect value for stec_residuals[16].residual, expected -28632, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 186, + "incorrect value for stec_residuals[16].stddev, expected 186, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 224, "incorrect value for stec_residuals[16].sv_id.constellation, expected 224, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 167, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 167, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, -4024, + "incorrect value for stec_residuals[17].residual, expected -4024, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 100, + "incorrect value for stec_residuals[17].stddev, expected 100, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 227, "incorrect value for stec_residuals[17].sv_id.constellation, expected 227, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 157, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 2004, + "incorrect value for stec_residuals[18].residual, expected 2004, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 59, + "incorrect value for stec_residuals[18].stddev, expected 59, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 12, "incorrect value for stec_residuals[18].sv_id.constellation, expected 12, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 35, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 35, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 6998, + "incorrect value for stec_residuals[19].residual, expected 6998, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 24, + "incorrect value for stec_residuals[19].stddev, expected 24, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 81, "incorrect value for stec_residuals[19].sv_id.constellation, expected 81, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 176, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 176, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -31701, + "incorrect value for stec_residuals[20].residual, expected -31701, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 45, + "incorrect value for stec_residuals[20].stddev, expected 45, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 67, "incorrect value for stec_residuals[20].sv_id.constellation, expected 67, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 155, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 155, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 28678, + "incorrect value for stec_residuals[21].residual, expected 28678, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 183, + "incorrect value for stec_residuals[21].stddev, expected 183, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 44, "incorrect value for stec_residuals[21].sv_id.constellation, expected 44, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 203, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -15793, + "incorrect value for stec_residuals[22].residual, expected -15793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 253, + "incorrect value for stec_residuals[22].stddev, expected 253, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 176, "incorrect value for stec_residuals[22].sv_id.constellation, expected 176, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 231, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -7589, + "incorrect value for stec_residuals[23].residual, expected -7589, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 116, + "incorrect value for stec_residuals[23].stddev, expected 116, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 103, "incorrect value for stec_residuals[23].sv_id.constellation, expected 103, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 247, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -7362, + "incorrect value for stec_residuals[24].residual, expected -7362, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 240, + "incorrect value for stec_residuals[24].stddev, expected 240, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 23, "incorrect value for stec_residuals[24].sv_id.constellation, expected 23, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 148, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 148, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 4813, + "incorrect value for stec_residuals[25].residual, expected 4813, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 242, + "incorrect value for stec_residuals[25].stddev, expected 242, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 219, "incorrect value for stec_residuals[25].sv_id.constellation, expected 219, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 29, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 29, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20295, + "incorrect value for stec_residuals[26].residual, expected 20295, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 37, + "incorrect value for stec_residuals[26].stddev, expected 37, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 72, "incorrect value for stec_residuals[26].sv_id.constellation, expected 72, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 207, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -13623, + "incorrect value for stec_residuals[27].residual, expected -13623, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 91, + "incorrect value for stec_residuals[27].stddev, expected 91, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 176, "incorrect value for stec_residuals[27].sv_id.constellation, expected 176, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 42, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 15250, + "incorrect value for stec_residuals[28].residual, expected 15250, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 110, + "incorrect value for stec_residuals[28].stddev, expected 110, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 115, "incorrect value for stec_residuals[28].sv_id.constellation, expected 115, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 105, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 105, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, -18560, + "incorrect value for stec_residuals[29].residual, expected -18560, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 185, + "incorrect value for stec_residuals[29].stddev, expected 185, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 109, "incorrect value for stec_residuals[29].sv_id.constellation, expected 109, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 44, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 44, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 23717, + "incorrect value for stec_residuals[30].residual, expected 23717, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 79, + "incorrect value for stec_residuals[30].stddev, expected 79, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 31, "incorrect value for stec_residuals[30].sv_id.constellation, expected 31, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 67, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 67, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 1886, + "incorrect value for stec_residuals[31].residual, expected 1886, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 162, + "incorrect value for stec_residuals[31].stddev, expected 162, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 180, "incorrect value for stec_residuals[31].sv_id.constellation, expected 180, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 189, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 189, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 12242, + "incorrect value for stec_residuals[32].residual, expected 12242, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 7, + "incorrect value for stec_residuals[32].stddev, expected 7, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 156, "incorrect value for stec_residuals[32].sv_id.constellation, expected 156, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 121, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 121, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 10670, + "incorrect value for stec_residuals[33].residual, expected 10670, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 241, + "incorrect value for stec_residuals[33].stddev, expected 241, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 205, "incorrect value for stec_residuals[33].sv_id.constellation, expected 205, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 7, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 7, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 25899, + "incorrect value for stec_residuals[34].residual, expected 25899, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 186, + "incorrect value for stec_residuals[34].stddev, expected 186, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 210, "incorrect value for stec_residuals[34].sv_id.constellation, expected 210, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 129, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 129, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -2078, + "incorrect value for stec_residuals[35].residual, expected -2078, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 187, + "incorrect value for stec_residuals[35].stddev, expected 187, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 195, "incorrect value for stec_residuals[35].sv_id.constellation, expected 195, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 208, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 208, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -16264, + "incorrect value for stec_residuals[36].residual, expected -16264, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 102, + "incorrect value for stec_residuals[36].stddev, expected 102, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 160, "incorrect value for stec_residuals[36].sv_id.constellation, expected 160, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 219, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 219, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -21002, + "incorrect value for stec_residuals[37].residual, expected -21002, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 94, + "incorrect value for stec_residuals[37].stddev, expected 94, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 42, "incorrect value for stec_residuals[37].sv_id.constellation, expected 42, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 166, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 166, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 7902, + "incorrect value for stec_residuals[38].residual, expected 7902, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 35, + "incorrect value for stec_residuals[38].stddev, expected 35, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 156, "incorrect value for stec_residuals[38].sv_id.constellation, expected 156, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 102, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 102, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -30275, + "incorrect value for stec_residuals[39].residual, expected -30275, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 204, + "incorrect value for stec_residuals[39].stddev, expected 204, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 64, "incorrect value for stec_residuals[39].sv_id.constellation, expected 64, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 247, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 247, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -8633, + "incorrect value for stec_residuals[40].residual, expected -8633, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 222, + "incorrect value for stec_residuals[40].stddev, expected 222, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 32, "incorrect value for stec_residuals[40].sv_id.constellation, expected 32, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 220, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 220, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 6403, + "incorrect value for stec_residuals[41].residual, expected 6403, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 45, + "incorrect value for stec_residuals[41].stddev, expected 45, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 246, "incorrect value for stec_residuals[41].sv_id.constellation, expected 246, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 201, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 22643, + "incorrect value for stec_residuals[42].residual, expected 22643, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 218, + "incorrect value for stec_residuals[42].stddev, expected 218, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 239, "incorrect value for stec_residuals[42].sv_id.constellation, expected 239, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 251, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 251, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 16760, + "incorrect value for stec_residuals[43].residual, expected 16760, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 175, + "incorrect value for stec_residuals[43].stddev, expected 175, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 209, "incorrect value for stec_residuals[43].sv_id.constellation, expected 209, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 10, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 10, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, -20951, + "incorrect value for stec_residuals[44].residual, expected -20951, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 137, + "incorrect value for stec_residuals[44].stddev, expected 137, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 194, "incorrect value for stec_residuals[44].sv_id.constellation, expected 194, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 131, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 131, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, -740, + "incorrect value for stec_residuals[45].residual, expected -740, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 42, + "incorrect value for stec_residuals[45].stddev, expected 42, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 68, "incorrect value for stec_residuals[45].sv_id.constellation, expected 68, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 17, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 17, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, -3035, + "incorrect value for tropo_delay_correction.hydro, expected -3035, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 72, + "incorrect value for tropo_delay_correction.stddev, expected 72, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 78, + "incorrect value for tropo_delay_correction.wet, expected 78, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrection"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a.rs new file mode 100644 index 0000000000..2da5f93151 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a.rs @@ -0,0 +1,2710 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, 104, 252, 133, 245, 28, + 95, 100, 147, 41, 33, 92, 87, 25, 142, 151, 74, 151, 95, 94, 7, 146, 237, 45, 167, 86, + 42, 116, 224, 169, 234, 220, 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, 206, 151, + 158, 22, 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, 110, 38, 65, 104, 244, 19, 238, + 227, 88, 169, 164, 146, 63, 37, 183, 85, 71, 235, 168, 114, 211, 105, 221, 156, 60, 18, + 230, 2, 142, 172, 16, 39, 33, 126, 106, 99, 188, 234, 41, 162, 197, 138, 227, 80, 12, + 54, 67, 238, 5, 93, 1, 207, 129, 13, 46, 115, 49, 58, 185, 127, 156, 200, 96, 217, 202, + 15, 245, 55, 198, 81, 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, 96, 138, 55, 214, + 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, 245, 112, 168, 210, 10, 5, 117, 1, + 57, 108, 248, 212, 145, 119, 226, 165, 5, 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, + 215, 12, 137, 16, 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, 31, 48, 132, 72, 229, + 126, 186, 68, 76, 133, 21, 0, 180, 139, 164, 148, 119, 149, 214, 120, 177, 201, 80, 80, + 105, 10, 136, 118, 77, 46, 233, 233, 227, 11, 158, 103, 167, 216, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fa, + "Incorrect message type, expected 0x5fa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6a6c, + "incorrect sender id, expected 0x6a6c, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 245, + "incorrect value for header.iod_atmo, expected 245, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 37695, + "incorrect value for header.num_msgs, expected 37695, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 64616, + "incorrect value for header.seq_num, expected 64616, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 892131748, + "incorrect value for header.time.tow, expected 892131748, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 23906, + "incorrect value for header.time.wn, expected 23906, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 28, + "incorrect value for header.tropo_quality_indicator, expected 28, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 133, + "incorrect value for header.update_interval, expected 133, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 25695, + "incorrect value for index, expected 25695, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -26738, + "incorrect value for stec_residuals[0].residual, expected -26738, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 74, + "incorrect value for stec_residuals[0].stddev, expected 74, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!( + msg.stec_residuals[0].sv_id.constellation, 25, + "incorrect value for stec_residuals[0].sv_id.constellation, expected 25, is {}", + msg.stec_residuals[0].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 87, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 87, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 1886, + "incorrect value for stec_residuals[1].residual, expected 1886, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 146, + "incorrect value for stec_residuals[1].stddev, expected 146, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!( + msg.stec_residuals[1].sv_id.constellation, 95, + "incorrect value for stec_residuals[1].sv_id.constellation, expected 95, is {}", + msg.stec_residuals[1].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 151, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 22183, + "incorrect value for stec_residuals[2].residual, expected 22183, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 42, + "incorrect value for stec_residuals[2].stddev, expected 42, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!( + msg.stec_residuals[2].sv_id.constellation, 45, + "incorrect value for stec_residuals[2].sv_id.constellation, expected 45, is {}", + msg.stec_residuals[2].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 237, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 237, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -5463, + "incorrect value for stec_residuals[3].residual, expected -5463, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 220, + "incorrect value for stec_residuals[3].stddev, expected 220, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!(msg.stec_residuals[3].sv_id.constellation, 224, "incorrect value for stec_residuals[3].sv_id.constellation, expected 224, is {}", msg.stec_residuals[3].sv_id.constellation); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 116, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 116, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 3346, + "incorrect value for stec_residuals[4].residual, expected 3346, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 178, + "incorrect value for stec_residuals[4].stddev, expected 178, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 176, "incorrect value for stec_residuals[4].sv_id.constellation, expected 176, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 23, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 28320, + "incorrect value for stec_residuals[5].residual, expected 28320, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 15, + "incorrect value for stec_residuals[5].stddev, expected 15, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 160, "incorrect value for stec_residuals[5].sv_id.constellation, expected 160, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 79, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 79, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, -24937, + "incorrect value for stec_residuals[6].residual, expected -24937, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 22, + "incorrect value for stec_residuals[6].stddev, expected 22, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 206, "incorrect value for stec_residuals[6].sv_id.constellation, expected 206, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 53, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 53, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, -21968, + "incorrect value for stec_residuals[7].residual, expected -21968, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 82, + "incorrect value for stec_residuals[7].stddev, expected 82, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 184, "incorrect value for stec_residuals[7].sv_id.constellation, expected 184, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 117, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 17786, + "incorrect value for stec_residuals[8].residual, expected 17786, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 180, + "incorrect value for stec_residuals[8].stddev, expected 180, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 53, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 53, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 40, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 26689, + "incorrect value for stec_residuals[9].residual, expected 26689, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 244, + "incorrect value for stec_residuals[9].stddev, expected 244, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 38, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 38, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 110, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 110, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 22755, + "incorrect value for stec_residuals[10].residual, expected 22755, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 169, + "incorrect value for stec_residuals[10].stddev, expected 169, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 238, "incorrect value for stec_residuals[10].sv_id.constellation, expected 238, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 19, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 19, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 9535, + "incorrect value for stec_residuals[11].residual, expected 9535, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 183, + "incorrect value for stec_residuals[11].stddev, expected 183, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 146, "incorrect value for stec_residuals[11].sv_id.constellation, expected 146, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 164, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 164, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -22293, + "incorrect value for stec_residuals[12].residual, expected -22293, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 114, + "incorrect value for stec_residuals[12].stddev, expected 114, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 71, "incorrect value for stec_residuals[12].sv_id.constellation, expected 71, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 85, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 85, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -25379, + "incorrect value for stec_residuals[13].residual, expected -25379, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 60, + "incorrect value for stec_residuals[13].stddev, expected 60, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 105, "incorrect value for stec_residuals[13].sv_id.constellation, expected 105, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 211, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 211, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -29182, + "incorrect value for stec_residuals[14].residual, expected -29182, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 172, + "incorrect value for stec_residuals[14].stddev, expected 172, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 230, "incorrect value for stec_residuals[14].sv_id.constellation, expected 230, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 18, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 32289, + "incorrect value for stec_residuals[15].residual, expected 32289, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 106, + "incorrect value for stec_residuals[15].stddev, expected 106, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 39, "incorrect value for stec_residuals[15].sv_id.constellation, expected 39, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 16, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, 10730, + "incorrect value for stec_residuals[16].residual, expected 10730, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 162, + "incorrect value for stec_residuals[16].stddev, expected 162, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 188, "incorrect value for stec_residuals[16].sv_id.constellation, expected 188, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 99, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 20707, + "incorrect value for stec_residuals[17].residual, expected 20707, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 12, + "incorrect value for stec_residuals[17].stddev, expected 12, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 138, "incorrect value for stec_residuals[17].sv_id.constellation, expected 138, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 197, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 1518, + "incorrect value for stec_residuals[18].residual, expected 1518, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 93, + "incorrect value for stec_residuals[18].stddev, expected 93, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 67, "incorrect value for stec_residuals[18].sv_id.constellation, expected 67, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 54, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 54, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 3457, + "incorrect value for stec_residuals[19].residual, expected 3457, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 46, + "incorrect value for stec_residuals[19].stddev, expected 46, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 207, "incorrect value for stec_residuals[19].sv_id.constellation, expected 207, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 1, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 1, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -18118, + "incorrect value for stec_residuals[20].residual, expected -18118, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 127, + "incorrect value for stec_residuals[20].stddev, expected 127, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 49, "incorrect value for stec_residuals[20].sv_id.constellation, expected 49, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 115, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 115, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, -9888, + "incorrect value for stec_residuals[21].residual, expected -9888, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 202, + "incorrect value for stec_residuals[21].stddev, expected 202, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 200, "incorrect value for stec_residuals[21].sv_id.constellation, expected 200, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 156, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -14793, + "incorrect value for stec_residuals[22].residual, expected -14793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 81, + "incorrect value for stec_residuals[22].stddev, expected 81, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 245, "incorrect value for stec_residuals[22].sv_id.constellation, expected 245, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 15, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 15, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, 18758, + "incorrect value for stec_residuals[23].residual, expected 18758, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 82, + "incorrect value for stec_residuals[23].stddev, expected 82, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 132, "incorrect value for stec_residuals[23].sv_id.constellation, expected 132, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 218, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 218, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, 3839, + "incorrect value for stec_residuals[24].residual, expected 3839, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 134, + "incorrect value for stec_residuals[24].stddev, expected 134, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 26, "incorrect value for stec_residuals[24].sv_id.constellation, expected 26, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 147, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 147, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, -10697, + "incorrect value for stec_residuals[25].residual, expected -10697, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 83, + "incorrect value for stec_residuals[25].stddev, expected 83, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 138, "incorrect value for stec_residuals[25].sv_id.constellation, expected 138, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 96, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 96, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20387, + "incorrect value for stec_residuals[26].residual, expected 20387, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 173, + "incorrect value for stec_residuals[26].stddev, expected 173, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 170, "incorrect value for stec_residuals[26].sv_id.constellation, expected 170, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 156, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -3789, + "incorrect value for stec_residuals[27].residual, expected -3789, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 107, + "incorrect value for stec_residuals[27].stddev, expected 107, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 115, "incorrect value for stec_residuals[27].sv_id.constellation, expected 115, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 228, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 228, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, -11608, + "incorrect value for stec_residuals[28].residual, expected -11608, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 10, + "incorrect value for stec_residuals[28].stddev, expected 10, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 112, "incorrect value for stec_residuals[28].sv_id.constellation, expected 112, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 245, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 245, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 14593, + "incorrect value for stec_residuals[29].residual, expected 14593, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 108, + "incorrect value for stec_residuals[29].stddev, expected 108, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 117, "incorrect value for stec_residuals[29].sv_id.constellation, expected 117, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 5, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 30609, + "incorrect value for stec_residuals[30].residual, expected 30609, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 226, + "incorrect value for stec_residuals[30].stddev, expected 226, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 212, "incorrect value for stec_residuals[30].sv_id.constellation, expected 212, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 248, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, -13683, + "incorrect value for stec_residuals[31].residual, expected -13683, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 106, + "incorrect value for stec_residuals[31].stddev, expected 106, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!( + msg.stec_residuals[31].sv_id.constellation, 5, + "incorrect value for stec_residuals[31].sv_id.constellation, expected 5, is {}", + msg.stec_residuals[31].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 165, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 165, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 15652, + "incorrect value for stec_residuals[32].residual, expected 15652, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 243, + "incorrect value for stec_residuals[32].stddev, expected 243, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 60, "incorrect value for stec_residuals[32].sv_id.constellation, expected 60, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 0, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 3287, + "incorrect value for stec_residuals[33].residual, expected 3287, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 137, + "incorrect value for stec_residuals[33].stddev, expected 137, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 216, "incorrect value for stec_residuals[33].sv_id.constellation, expected 216, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 203, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 29687, + "incorrect value for stec_residuals[34].residual, expected 29687, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 152, + "incorrect value for stec_residuals[34].stddev, expected 152, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 28, "incorrect value for stec_residuals[34].sv_id.constellation, expected 28, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 16, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -6960, + "incorrect value for stec_residuals[35].residual, expected -6960, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 203, + "incorrect value for stec_residuals[35].stddev, expected 203, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 119, "incorrect value for stec_residuals[35].sv_id.constellation, expected 119, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 181, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -15193, + "incorrect value for stec_residuals[36].residual, expected -15193, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 32, + "incorrect value for stec_residuals[36].stddev, expected 32, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 34, "incorrect value for stec_residuals[36].sv_id.constellation, expected 34, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 236, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 236, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, 25873, + "incorrect value for stec_residuals[37].residual, expected 25873, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 200, + "incorrect value for stec_residuals[37].stddev, expected 200, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!( + msg.stec_residuals[37].sv_id.constellation, 1, + "incorrect value for stec_residuals[37].sv_id.constellation, expected 1, is {}", + msg.stec_residuals[37].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 109, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 109, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, -22403, + "incorrect value for stec_residuals[38].residual, expected -22403, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 137, + "incorrect value for stec_residuals[38].stddev, expected 137, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 94, "incorrect value for stec_residuals[38].sv_id.constellation, expected 94, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 25, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 25, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, 7588, + "incorrect value for stec_residuals[39].residual, expected 7588, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 31, + "incorrect value for stec_residuals[39].stddev, expected 31, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!( + msg.stec_residuals[39].sv_id.constellation, 4, + "incorrect value for stec_residuals[39].sv_id.constellation, expected 4, is {}", + msg.stec_residuals[39].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 157, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -6840, + "incorrect value for stec_residuals[40].residual, expected -6840, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 126, + "incorrect value for stec_residuals[40].stddev, expected 126, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 132, "incorrect value for stec_residuals[40].sv_id.constellation, expected 132, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 48, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 48, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, -31412, + "incorrect value for stec_residuals[41].residual, expected -31412, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 21, + "incorrect value for stec_residuals[41].stddev, expected 21, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 68, "incorrect value for stec_residuals[41].sv_id.constellation, expected 68, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 186, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 186, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, -23413, + "incorrect value for stec_residuals[42].residual, expected -23413, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 148, + "incorrect value for stec_residuals[42].stddev, expected 148, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 180, "incorrect value for stec_residuals[42].sv_id.constellation, expected 180, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 0, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 30934, + "incorrect value for stec_residuals[43].residual, expected 30934, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 177, + "incorrect value for stec_residuals[43].stddev, expected 177, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 149, "incorrect value for stec_residuals[43].sv_id.constellation, expected 149, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 119, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 26960, + "incorrect value for stec_residuals[44].residual, expected 26960, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 10, + "incorrect value for stec_residuals[44].stddev, expected 10, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 80, "incorrect value for stec_residuals[44].sv_id.constellation, expected 80, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 201, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 11853, + "incorrect value for stec_residuals[45].residual, expected 11853, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 233, + "incorrect value for stec_residuals[45].stddev, expected 233, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 118, "incorrect value for stec_residuals[45].sv_id.constellation, expected 118, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 136, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 136, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -25077, + "incorrect value for stec_residuals[46].residual, expected -25077, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!( + msg.stec_residuals[46].stddev, 103, + "incorrect value for stec_residuals[46].stddev, expected 103, is {}", + msg.stec_residuals[46].stddev + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 227, "incorrect value for stec_residuals[46].sv_id.constellation, expected 227, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 233, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 10643, + "incorrect value for tropo_delay_correction.hydro, expected 10643, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 92, + "incorrect value for tropo_delay_correction.stddev, expected 92, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 33, + "incorrect value for tropo_delay_correction.wet, expected 33, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a() { + { + let json_input = r#"{"crc":55463,"length":254,"msg_type":1530,"payload":"pNksNWJdP5No/IX1HF9kkykhXFcZjpdKl19eB5LtLadWKnTgqercF7ASDbJPoKBuDzXOl54WdbgwqlIoNXpFtG4mQWj0E+7jWKmkkj8lt1VH66hy02ndnDwS5gKOrBAnIX5qY7zqKaLFiuNQDDZD7gVdAc+BDS5zMTq5f5zIYNnKD/U3xlHahEZJUpMa/w6GYIo31lOcqqNPreRzM/Fr9XCo0goFdQE5bPjUkXfipQWNymoAPCQ988vY1wyJEBz3c5i1d9Dky+wip8QgbQERZcgZXn2oiZ0EpB0fMIRI5X66REyFFQC0i6SUd5XWeLHJUFBpCoh2TS7p6eMLnmc=","preamble":85,"sender":27244,"header":{"time":{"tow":892131748,"wn":23906},"num_msgs":37695,"seq_num":64616,"update_interval":133,"iod_atmo":245,"tropo_quality_indicator":28},"index":25695,"tropo_delay_correction":{"hydro":10643,"wet":33,"stddev":92},"stec_residuals":[{"sv_id":{"satId":87,"constellation":25},"residual":-26738,"stddev":74},{"sv_id":{"satId":151,"constellation":95},"residual":1886,"stddev":146},{"sv_id":{"satId":237,"constellation":45},"residual":22183,"stddev":42},{"sv_id":{"satId":116,"constellation":224},"residual":-5463,"stddev":220},{"sv_id":{"satId":23,"constellation":176},"residual":3346,"stddev":178},{"sv_id":{"satId":79,"constellation":160},"residual":28320,"stddev":15},{"sv_id":{"satId":53,"constellation":206},"residual":-24937,"stddev":22},{"sv_id":{"satId":117,"constellation":184},"residual":-21968,"stddev":82},{"sv_id":{"satId":40,"constellation":53},"residual":17786,"stddev":180},{"sv_id":{"satId":110,"constellation":38},"residual":26689,"stddev":244},{"sv_id":{"satId":19,"constellation":238},"residual":22755,"stddev":169},{"sv_id":{"satId":164,"constellation":146},"residual":9535,"stddev":183},{"sv_id":{"satId":85,"constellation":71},"residual":-22293,"stddev":114},{"sv_id":{"satId":211,"constellation":105},"residual":-25379,"stddev":60},{"sv_id":{"satId":18,"constellation":230},"residual":-29182,"stddev":172},{"sv_id":{"satId":16,"constellation":39},"residual":32289,"stddev":106},{"sv_id":{"satId":99,"constellation":188},"residual":10730,"stddev":162},{"sv_id":{"satId":197,"constellation":138},"residual":20707,"stddev":12},{"sv_id":{"satId":54,"constellation":67},"residual":1518,"stddev":93},{"sv_id":{"satId":1,"constellation":207},"residual":3457,"stddev":46},{"sv_id":{"satId":115,"constellation":49},"residual":-18118,"stddev":127},{"sv_id":{"satId":156,"constellation":200},"residual":-9888,"stddev":202},{"sv_id":{"satId":15,"constellation":245},"residual":-14793,"stddev":81},{"sv_id":{"satId":218,"constellation":132},"residual":18758,"stddev":82},{"sv_id":{"satId":147,"constellation":26},"residual":3839,"stddev":134},{"sv_id":{"satId":96,"constellation":138},"residual":-10697,"stddev":83},{"sv_id":{"satId":156,"constellation":170},"residual":20387,"stddev":173},{"sv_id":{"satId":228,"constellation":115},"residual":-3789,"stddev":107},{"sv_id":{"satId":245,"constellation":112},"residual":-11608,"stddev":10},{"sv_id":{"satId":5,"constellation":117},"residual":14593,"stddev":108},{"sv_id":{"satId":248,"constellation":212},"residual":30609,"stddev":226},{"sv_id":{"satId":165,"constellation":5},"residual":-13683,"stddev":106},{"sv_id":{"satId":0,"constellation":60},"residual":15652,"stddev":243},{"sv_id":{"satId":203,"constellation":216},"residual":3287,"stddev":137},{"sv_id":{"satId":16,"constellation":28},"residual":29687,"stddev":152},{"sv_id":{"satId":181,"constellation":119},"residual":-6960,"stddev":203},{"sv_id":{"satId":236,"constellation":34},"residual":-15193,"stddev":32},{"sv_id":{"satId":109,"constellation":1},"residual":25873,"stddev":200},{"sv_id":{"satId":25,"constellation":94},"residual":-22403,"stddev":137},{"sv_id":{"satId":157,"constellation":4},"residual":7588,"stddev":31},{"sv_id":{"satId":48,"constellation":132},"residual":-6840,"stddev":126},{"sv_id":{"satId":186,"constellation":68},"residual":-31412,"stddev":21},{"sv_id":{"satId":0,"constellation":180},"residual":-23413,"stddev":148},{"sv_id":{"satId":119,"constellation":149},"residual":30934,"stddev":177},{"sv_id":{"satId":201,"constellation":80},"residual":26960,"stddev":10},{"sv_id":{"satId":136,"constellation":118},"residual":11853,"stddev":233},{"sv_id":{"satId":233,"constellation":227},"residual":-25077,"stddev":103}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fa, + "Incorrect message type, expected 0x5fa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6a6c, + "incorrect sender id, expected 0x6a6c, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 245, + "incorrect value for header.iod_atmo, expected 245, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 37695, + "incorrect value for header.num_msgs, expected 37695, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 64616, + "incorrect value for header.seq_num, expected 64616, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 892131748, + "incorrect value for header.time.tow, expected 892131748, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 23906, + "incorrect value for header.time.wn, expected 23906, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 28, + "incorrect value for header.tropo_quality_indicator, expected 28, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 133, + "incorrect value for header.update_interval, expected 133, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 25695, + "incorrect value for index, expected 25695, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -26738, + "incorrect value for stec_residuals[0].residual, expected -26738, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 74, + "incorrect value for stec_residuals[0].stddev, expected 74, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!( + msg.stec_residuals[0].sv_id.constellation, 25, + "incorrect value for stec_residuals[0].sv_id.constellation, expected 25, is {}", + msg.stec_residuals[0].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 87, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 87, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 1886, + "incorrect value for stec_residuals[1].residual, expected 1886, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 146, + "incorrect value for stec_residuals[1].stddev, expected 146, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!( + msg.stec_residuals[1].sv_id.constellation, 95, + "incorrect value for stec_residuals[1].sv_id.constellation, expected 95, is {}", + msg.stec_residuals[1].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 151, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 22183, + "incorrect value for stec_residuals[2].residual, expected 22183, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 42, + "incorrect value for stec_residuals[2].stddev, expected 42, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!( + msg.stec_residuals[2].sv_id.constellation, 45, + "incorrect value for stec_residuals[2].sv_id.constellation, expected 45, is {}", + msg.stec_residuals[2].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 237, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 237, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -5463, + "incorrect value for stec_residuals[3].residual, expected -5463, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 220, + "incorrect value for stec_residuals[3].stddev, expected 220, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!(msg.stec_residuals[3].sv_id.constellation, 224, "incorrect value for stec_residuals[3].sv_id.constellation, expected 224, is {}", msg.stec_residuals[3].sv_id.constellation); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 116, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 116, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 3346, + "incorrect value for stec_residuals[4].residual, expected 3346, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 178, + "incorrect value for stec_residuals[4].stddev, expected 178, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 176, "incorrect value for stec_residuals[4].sv_id.constellation, expected 176, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 23, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 28320, + "incorrect value for stec_residuals[5].residual, expected 28320, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 15, + "incorrect value for stec_residuals[5].stddev, expected 15, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 160, "incorrect value for stec_residuals[5].sv_id.constellation, expected 160, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 79, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 79, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, -24937, + "incorrect value for stec_residuals[6].residual, expected -24937, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 22, + "incorrect value for stec_residuals[6].stddev, expected 22, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 206, "incorrect value for stec_residuals[6].sv_id.constellation, expected 206, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 53, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 53, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, -21968, + "incorrect value for stec_residuals[7].residual, expected -21968, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 82, + "incorrect value for stec_residuals[7].stddev, expected 82, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 184, "incorrect value for stec_residuals[7].sv_id.constellation, expected 184, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 117, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 17786, + "incorrect value for stec_residuals[8].residual, expected 17786, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 180, + "incorrect value for stec_residuals[8].stddev, expected 180, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 53, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 53, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 40, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 26689, + "incorrect value for stec_residuals[9].residual, expected 26689, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 244, + "incorrect value for stec_residuals[9].stddev, expected 244, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 38, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 38, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 110, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 110, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 22755, + "incorrect value for stec_residuals[10].residual, expected 22755, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 169, + "incorrect value for stec_residuals[10].stddev, expected 169, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 238, "incorrect value for stec_residuals[10].sv_id.constellation, expected 238, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 19, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 19, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 9535, + "incorrect value for stec_residuals[11].residual, expected 9535, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 183, + "incorrect value for stec_residuals[11].stddev, expected 183, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 146, "incorrect value for stec_residuals[11].sv_id.constellation, expected 146, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 164, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 164, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -22293, + "incorrect value for stec_residuals[12].residual, expected -22293, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 114, + "incorrect value for stec_residuals[12].stddev, expected 114, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 71, "incorrect value for stec_residuals[12].sv_id.constellation, expected 71, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 85, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 85, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -25379, + "incorrect value for stec_residuals[13].residual, expected -25379, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 60, + "incorrect value for stec_residuals[13].stddev, expected 60, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 105, "incorrect value for stec_residuals[13].sv_id.constellation, expected 105, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 211, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 211, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -29182, + "incorrect value for stec_residuals[14].residual, expected -29182, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 172, + "incorrect value for stec_residuals[14].stddev, expected 172, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 230, "incorrect value for stec_residuals[14].sv_id.constellation, expected 230, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 18, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 32289, + "incorrect value for stec_residuals[15].residual, expected 32289, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 106, + "incorrect value for stec_residuals[15].stddev, expected 106, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 39, "incorrect value for stec_residuals[15].sv_id.constellation, expected 39, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 16, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, 10730, + "incorrect value for stec_residuals[16].residual, expected 10730, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 162, + "incorrect value for stec_residuals[16].stddev, expected 162, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 188, "incorrect value for stec_residuals[16].sv_id.constellation, expected 188, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 99, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 20707, + "incorrect value for stec_residuals[17].residual, expected 20707, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 12, + "incorrect value for stec_residuals[17].stddev, expected 12, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 138, "incorrect value for stec_residuals[17].sv_id.constellation, expected 138, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 197, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 1518, + "incorrect value for stec_residuals[18].residual, expected 1518, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 93, + "incorrect value for stec_residuals[18].stddev, expected 93, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 67, "incorrect value for stec_residuals[18].sv_id.constellation, expected 67, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 54, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 54, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 3457, + "incorrect value for stec_residuals[19].residual, expected 3457, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 46, + "incorrect value for stec_residuals[19].stddev, expected 46, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 207, "incorrect value for stec_residuals[19].sv_id.constellation, expected 207, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 1, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 1, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -18118, + "incorrect value for stec_residuals[20].residual, expected -18118, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 127, + "incorrect value for stec_residuals[20].stddev, expected 127, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 49, "incorrect value for stec_residuals[20].sv_id.constellation, expected 49, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 115, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 115, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, -9888, + "incorrect value for stec_residuals[21].residual, expected -9888, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 202, + "incorrect value for stec_residuals[21].stddev, expected 202, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 200, "incorrect value for stec_residuals[21].sv_id.constellation, expected 200, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 156, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -14793, + "incorrect value for stec_residuals[22].residual, expected -14793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 81, + "incorrect value for stec_residuals[22].stddev, expected 81, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 245, "incorrect value for stec_residuals[22].sv_id.constellation, expected 245, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 15, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 15, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, 18758, + "incorrect value for stec_residuals[23].residual, expected 18758, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 82, + "incorrect value for stec_residuals[23].stddev, expected 82, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 132, "incorrect value for stec_residuals[23].sv_id.constellation, expected 132, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 218, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 218, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, 3839, + "incorrect value for stec_residuals[24].residual, expected 3839, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 134, + "incorrect value for stec_residuals[24].stddev, expected 134, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 26, "incorrect value for stec_residuals[24].sv_id.constellation, expected 26, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 147, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 147, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, -10697, + "incorrect value for stec_residuals[25].residual, expected -10697, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 83, + "incorrect value for stec_residuals[25].stddev, expected 83, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 138, "incorrect value for stec_residuals[25].sv_id.constellation, expected 138, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 96, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 96, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20387, + "incorrect value for stec_residuals[26].residual, expected 20387, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 173, + "incorrect value for stec_residuals[26].stddev, expected 173, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 170, "incorrect value for stec_residuals[26].sv_id.constellation, expected 170, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 156, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -3789, + "incorrect value for stec_residuals[27].residual, expected -3789, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 107, + "incorrect value for stec_residuals[27].stddev, expected 107, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 115, "incorrect value for stec_residuals[27].sv_id.constellation, expected 115, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 228, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 228, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, -11608, + "incorrect value for stec_residuals[28].residual, expected -11608, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 10, + "incorrect value for stec_residuals[28].stddev, expected 10, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 112, "incorrect value for stec_residuals[28].sv_id.constellation, expected 112, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 245, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 245, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 14593, + "incorrect value for stec_residuals[29].residual, expected 14593, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 108, + "incorrect value for stec_residuals[29].stddev, expected 108, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 117, "incorrect value for stec_residuals[29].sv_id.constellation, expected 117, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 5, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 30609, + "incorrect value for stec_residuals[30].residual, expected 30609, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 226, + "incorrect value for stec_residuals[30].stddev, expected 226, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 212, "incorrect value for stec_residuals[30].sv_id.constellation, expected 212, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 248, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, -13683, + "incorrect value for stec_residuals[31].residual, expected -13683, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 106, + "incorrect value for stec_residuals[31].stddev, expected 106, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!( + msg.stec_residuals[31].sv_id.constellation, 5, + "incorrect value for stec_residuals[31].sv_id.constellation, expected 5, is {}", + msg.stec_residuals[31].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 165, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 165, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 15652, + "incorrect value for stec_residuals[32].residual, expected 15652, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 243, + "incorrect value for stec_residuals[32].stddev, expected 243, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 60, "incorrect value for stec_residuals[32].sv_id.constellation, expected 60, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 0, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 3287, + "incorrect value for stec_residuals[33].residual, expected 3287, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 137, + "incorrect value for stec_residuals[33].stddev, expected 137, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 216, "incorrect value for stec_residuals[33].sv_id.constellation, expected 216, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 203, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 29687, + "incorrect value for stec_residuals[34].residual, expected 29687, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 152, + "incorrect value for stec_residuals[34].stddev, expected 152, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 28, "incorrect value for stec_residuals[34].sv_id.constellation, expected 28, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 16, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -6960, + "incorrect value for stec_residuals[35].residual, expected -6960, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 203, + "incorrect value for stec_residuals[35].stddev, expected 203, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 119, "incorrect value for stec_residuals[35].sv_id.constellation, expected 119, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 181, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -15193, + "incorrect value for stec_residuals[36].residual, expected -15193, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 32, + "incorrect value for stec_residuals[36].stddev, expected 32, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 34, "incorrect value for stec_residuals[36].sv_id.constellation, expected 34, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 236, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 236, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, 25873, + "incorrect value for stec_residuals[37].residual, expected 25873, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 200, + "incorrect value for stec_residuals[37].stddev, expected 200, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!( + msg.stec_residuals[37].sv_id.constellation, 1, + "incorrect value for stec_residuals[37].sv_id.constellation, expected 1, is {}", + msg.stec_residuals[37].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 109, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 109, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, -22403, + "incorrect value for stec_residuals[38].residual, expected -22403, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 137, + "incorrect value for stec_residuals[38].stddev, expected 137, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 94, "incorrect value for stec_residuals[38].sv_id.constellation, expected 94, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 25, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 25, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, 7588, + "incorrect value for stec_residuals[39].residual, expected 7588, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 31, + "incorrect value for stec_residuals[39].stddev, expected 31, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!( + msg.stec_residuals[39].sv_id.constellation, 4, + "incorrect value for stec_residuals[39].sv_id.constellation, expected 4, is {}", + msg.stec_residuals[39].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 157, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -6840, + "incorrect value for stec_residuals[40].residual, expected -6840, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 126, + "incorrect value for stec_residuals[40].stddev, expected 126, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 132, "incorrect value for stec_residuals[40].sv_id.constellation, expected 132, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 48, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 48, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, -31412, + "incorrect value for stec_residuals[41].residual, expected -31412, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 21, + "incorrect value for stec_residuals[41].stddev, expected 21, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 68, "incorrect value for stec_residuals[41].sv_id.constellation, expected 68, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 186, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 186, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, -23413, + "incorrect value for stec_residuals[42].residual, expected -23413, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 148, + "incorrect value for stec_residuals[42].stddev, expected 148, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 180, "incorrect value for stec_residuals[42].sv_id.constellation, expected 180, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 0, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 30934, + "incorrect value for stec_residuals[43].residual, expected 30934, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 177, + "incorrect value for stec_residuals[43].stddev, expected 177, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 149, "incorrect value for stec_residuals[43].sv_id.constellation, expected 149, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 119, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 26960, + "incorrect value for stec_residuals[44].residual, expected 26960, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 10, + "incorrect value for stec_residuals[44].stddev, expected 10, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 80, "incorrect value for stec_residuals[44].sv_id.constellation, expected 80, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 201, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 11853, + "incorrect value for stec_residuals[45].residual, expected 11853, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 233, + "incorrect value for stec_residuals[45].stddev, expected 233, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 118, "incorrect value for stec_residuals[45].sv_id.constellation, expected 118, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 136, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 136, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -25077, + "incorrect value for stec_residuals[46].residual, expected -25077, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!( + msg.stec_residuals[46].stddev, 103, + "incorrect value for stec_residuals[46].stddev, expected 103, is {}", + msg.stec_residuals[46].stddev + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 227, "incorrect value for stec_residuals[46].sv_id.constellation, expected 227, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 233, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 10643, + "incorrect value for tropo_delay_correction.hydro, expected 10643, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 92, + "incorrect value for tropo_delay_correction.stddev, expected 92, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 33, + "incorrect value for tropo_delay_correction.wet, expected 33, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 250, 5, 108, 106, 254, 164, 217, 44, 53, 98, 93, 63, 147, 104, 252, 133, 245, 28, + 95, 100, 147, 41, 33, 92, 87, 25, 142, 151, 74, 151, 95, 94, 7, 146, 237, 45, 167, 86, + 42, 116, 224, 169, 234, 220, 23, 176, 18, 13, 178, 79, 160, 160, 110, 15, 53, 206, 151, + 158, 22, 117, 184, 48, 170, 82, 40, 53, 122, 69, 180, 110, 38, 65, 104, 244, 19, 238, + 227, 88, 169, 164, 146, 63, 37, 183, 85, 71, 235, 168, 114, 211, 105, 221, 156, 60, 18, + 230, 2, 142, 172, 16, 39, 33, 126, 106, 99, 188, 234, 41, 162, 197, 138, 227, 80, 12, + 54, 67, 238, 5, 93, 1, 207, 129, 13, 46, 115, 49, 58, 185, 127, 156, 200, 96, 217, 202, + 15, 245, 55, 198, 81, 218, 132, 70, 73, 82, 147, 26, 255, 14, 134, 96, 138, 55, 214, + 83, 156, 170, 163, 79, 173, 228, 115, 51, 241, 107, 245, 112, 168, 210, 10, 5, 117, 1, + 57, 108, 248, 212, 145, 119, 226, 165, 5, 141, 202, 106, 0, 60, 36, 61, 243, 203, 216, + 215, 12, 137, 16, 28, 247, 115, 152, 181, 119, 208, 228, 203, 236, 34, 167, 196, 32, + 109, 1, 17, 101, 200, 25, 94, 125, 168, 137, 157, 4, 164, 29, 31, 48, 132, 72, 229, + 126, 186, 68, 76, 133, 21, 0, 180, 139, 164, 148, 119, 149, 214, 120, 177, 201, 80, 80, + 105, 10, 136, 118, 77, 46, 233, 233, 227, 11, 158, 103, 167, 216, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrGriddedCorrectionDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fa, + "Incorrect message type, expected 0x5fa, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6a6c, + "incorrect sender id, expected 0x6a6c, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 245, + "incorrect value for header.iod_atmo, expected 245, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 37695, + "incorrect value for header.num_msgs, expected 37695, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 64616, + "incorrect value for header.seq_num, expected 64616, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 892131748, + "incorrect value for header.time.tow, expected 892131748, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 23906, + "incorrect value for header.time.wn, expected 23906, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 28, + "incorrect value for header.tropo_quality_indicator, expected 28, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 133, + "incorrect value for header.update_interval, expected 133, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 25695, + "incorrect value for index, expected 25695, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -26738, + "incorrect value for stec_residuals[0].residual, expected -26738, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!( + msg.stec_residuals[0].stddev, 74, + "incorrect value for stec_residuals[0].stddev, expected 74, is {}", + msg.stec_residuals[0].stddev + ); + assert_eq!( + msg.stec_residuals[0].sv_id.constellation, 25, + "incorrect value for stec_residuals[0].sv_id.constellation, expected 25, is {}", + msg.stec_residuals[0].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 87, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 87, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 1886, + "incorrect value for stec_residuals[1].residual, expected 1886, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!( + msg.stec_residuals[1].stddev, 146, + "incorrect value for stec_residuals[1].stddev, expected 146, is {}", + msg.stec_residuals[1].stddev + ); + assert_eq!( + msg.stec_residuals[1].sv_id.constellation, 95, + "incorrect value for stec_residuals[1].sv_id.constellation, expected 95, is {}", + msg.stec_residuals[1].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 151, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 22183, + "incorrect value for stec_residuals[2].residual, expected 22183, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!( + msg.stec_residuals[2].stddev, 42, + "incorrect value for stec_residuals[2].stddev, expected 42, is {}", + msg.stec_residuals[2].stddev + ); + assert_eq!( + msg.stec_residuals[2].sv_id.constellation, 45, + "incorrect value for stec_residuals[2].sv_id.constellation, expected 45, is {}", + msg.stec_residuals[2].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 237, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 237, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -5463, + "incorrect value for stec_residuals[3].residual, expected -5463, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].stddev, 220, + "incorrect value for stec_residuals[3].stddev, expected 220, is {}", + msg.stec_residuals[3].stddev + ); + assert_eq!(msg.stec_residuals[3].sv_id.constellation, 224, "incorrect value for stec_residuals[3].sv_id.constellation, expected 224, is {}", msg.stec_residuals[3].sv_id.constellation); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 116, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 116, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, 3346, + "incorrect value for stec_residuals[4].residual, expected 3346, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!( + msg.stec_residuals[4].stddev, 178, + "incorrect value for stec_residuals[4].stddev, expected 178, is {}", + msg.stec_residuals[4].stddev + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 176, "incorrect value for stec_residuals[4].sv_id.constellation, expected 176, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 23, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 28320, + "incorrect value for stec_residuals[5].residual, expected 28320, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!( + msg.stec_residuals[5].stddev, 15, + "incorrect value for stec_residuals[5].stddev, expected 15, is {}", + msg.stec_residuals[5].stddev + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 160, "incorrect value for stec_residuals[5].sv_id.constellation, expected 160, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 79, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 79, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, -24937, + "incorrect value for stec_residuals[6].residual, expected -24937, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!( + msg.stec_residuals[6].stddev, 22, + "incorrect value for stec_residuals[6].stddev, expected 22, is {}", + msg.stec_residuals[6].stddev + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 206, "incorrect value for stec_residuals[6].sv_id.constellation, expected 206, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 53, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 53, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, -21968, + "incorrect value for stec_residuals[7].residual, expected -21968, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].stddev, 82, + "incorrect value for stec_residuals[7].stddev, expected 82, is {}", + msg.stec_residuals[7].stddev + ); + assert_eq!(msg.stec_residuals[7].sv_id.constellation, 184, "incorrect value for stec_residuals[7].sv_id.constellation, expected 184, is {}", msg.stec_residuals[7].sv_id.constellation); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 117, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 17786, + "incorrect value for stec_residuals[8].residual, expected 17786, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].stddev, 180, + "incorrect value for stec_residuals[8].stddev, expected 180, is {}", + msg.stec_residuals[8].stddev + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 53, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 53, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 40, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 26689, + "incorrect value for stec_residuals[9].residual, expected 26689, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].stddev, 244, + "incorrect value for stec_residuals[9].stddev, expected 244, is {}", + msg.stec_residuals[9].stddev + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 38, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 38, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 110, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 110, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, 22755, + "incorrect value for stec_residuals[10].residual, expected 22755, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!( + msg.stec_residuals[10].stddev, 169, + "incorrect value for stec_residuals[10].stddev, expected 169, is {}", + msg.stec_residuals[10].stddev + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 238, "incorrect value for stec_residuals[10].sv_id.constellation, expected 238, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 19, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 19, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, 9535, + "incorrect value for stec_residuals[11].residual, expected 9535, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!( + msg.stec_residuals[11].stddev, 183, + "incorrect value for stec_residuals[11].stddev, expected 183, is {}", + msg.stec_residuals[11].stddev + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 146, "incorrect value for stec_residuals[11].sv_id.constellation, expected 146, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 164, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 164, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -22293, + "incorrect value for stec_residuals[12].residual, expected -22293, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!( + msg.stec_residuals[12].stddev, 114, + "incorrect value for stec_residuals[12].stddev, expected 114, is {}", + msg.stec_residuals[12].stddev + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 71, "incorrect value for stec_residuals[12].sv_id.constellation, expected 71, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 85, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 85, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -25379, + "incorrect value for stec_residuals[13].residual, expected -25379, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!( + msg.stec_residuals[13].stddev, 60, + "incorrect value for stec_residuals[13].stddev, expected 60, is {}", + msg.stec_residuals[13].stddev + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 105, "incorrect value for stec_residuals[13].sv_id.constellation, expected 105, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 211, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 211, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, -29182, + "incorrect value for stec_residuals[14].residual, expected -29182, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!( + msg.stec_residuals[14].stddev, 172, + "incorrect value for stec_residuals[14].stddev, expected 172, is {}", + msg.stec_residuals[14].stddev + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 230, "incorrect value for stec_residuals[14].sv_id.constellation, expected 230, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 18, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 32289, + "incorrect value for stec_residuals[15].residual, expected 32289, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!( + msg.stec_residuals[15].stddev, 106, + "incorrect value for stec_residuals[15].stddev, expected 106, is {}", + msg.stec_residuals[15].stddev + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 39, "incorrect value for stec_residuals[15].sv_id.constellation, expected 39, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 16, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, 10730, + "incorrect value for stec_residuals[16].residual, expected 10730, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!( + msg.stec_residuals[16].stddev, 162, + "incorrect value for stec_residuals[16].stddev, expected 162, is {}", + msg.stec_residuals[16].stddev + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 188, "incorrect value for stec_residuals[16].sv_id.constellation, expected 188, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 99, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 20707, + "incorrect value for stec_residuals[17].residual, expected 20707, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!( + msg.stec_residuals[17].stddev, 12, + "incorrect value for stec_residuals[17].stddev, expected 12, is {}", + msg.stec_residuals[17].stddev + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 138, "incorrect value for stec_residuals[17].sv_id.constellation, expected 138, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 197, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 1518, + "incorrect value for stec_residuals[18].residual, expected 1518, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!( + msg.stec_residuals[18].stddev, 93, + "incorrect value for stec_residuals[18].stddev, expected 93, is {}", + msg.stec_residuals[18].stddev + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 67, "incorrect value for stec_residuals[18].sv_id.constellation, expected 67, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 54, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 54, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, 3457, + "incorrect value for stec_residuals[19].residual, expected 3457, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!( + msg.stec_residuals[19].stddev, 46, + "incorrect value for stec_residuals[19].stddev, expected 46, is {}", + msg.stec_residuals[19].stddev + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 207, "incorrect value for stec_residuals[19].sv_id.constellation, expected 207, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 1, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 1, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -18118, + "incorrect value for stec_residuals[20].residual, expected -18118, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!( + msg.stec_residuals[20].stddev, 127, + "incorrect value for stec_residuals[20].stddev, expected 127, is {}", + msg.stec_residuals[20].stddev + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 49, "incorrect value for stec_residuals[20].sv_id.constellation, expected 49, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 115, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 115, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, -9888, + "incorrect value for stec_residuals[21].residual, expected -9888, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!( + msg.stec_residuals[21].stddev, 202, + "incorrect value for stec_residuals[21].stddev, expected 202, is {}", + msg.stec_residuals[21].stddev + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 200, "incorrect value for stec_residuals[21].sv_id.constellation, expected 200, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 156, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, -14793, + "incorrect value for stec_residuals[22].residual, expected -14793, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!( + msg.stec_residuals[22].stddev, 81, + "incorrect value for stec_residuals[22].stddev, expected 81, is {}", + msg.stec_residuals[22].stddev + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 245, "incorrect value for stec_residuals[22].sv_id.constellation, expected 245, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 15, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 15, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, 18758, + "incorrect value for stec_residuals[23].residual, expected 18758, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!( + msg.stec_residuals[23].stddev, 82, + "incorrect value for stec_residuals[23].stddev, expected 82, is {}", + msg.stec_residuals[23].stddev + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 132, "incorrect value for stec_residuals[23].sv_id.constellation, expected 132, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 218, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 218, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, 3839, + "incorrect value for stec_residuals[24].residual, expected 3839, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!( + msg.stec_residuals[24].stddev, 134, + "incorrect value for stec_residuals[24].stddev, expected 134, is {}", + msg.stec_residuals[24].stddev + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 26, "incorrect value for stec_residuals[24].sv_id.constellation, expected 26, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 147, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 147, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, -10697, + "incorrect value for stec_residuals[25].residual, expected -10697, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!( + msg.stec_residuals[25].stddev, 83, + "incorrect value for stec_residuals[25].stddev, expected 83, is {}", + msg.stec_residuals[25].stddev + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 138, "incorrect value for stec_residuals[25].sv_id.constellation, expected 138, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 96, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 96, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, 20387, + "incorrect value for stec_residuals[26].residual, expected 20387, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!( + msg.stec_residuals[26].stddev, 173, + "incorrect value for stec_residuals[26].stddev, expected 173, is {}", + msg.stec_residuals[26].stddev + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 170, "incorrect value for stec_residuals[26].sv_id.constellation, expected 170, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 156, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, -3789, + "incorrect value for stec_residuals[27].residual, expected -3789, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!( + msg.stec_residuals[27].stddev, 107, + "incorrect value for stec_residuals[27].stddev, expected 107, is {}", + msg.stec_residuals[27].stddev + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 115, "incorrect value for stec_residuals[27].sv_id.constellation, expected 115, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 228, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 228, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, -11608, + "incorrect value for stec_residuals[28].residual, expected -11608, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!( + msg.stec_residuals[28].stddev, 10, + "incorrect value for stec_residuals[28].stddev, expected 10, is {}", + msg.stec_residuals[28].stddev + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 112, "incorrect value for stec_residuals[28].sv_id.constellation, expected 112, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 245, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 245, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 14593, + "incorrect value for stec_residuals[29].residual, expected 14593, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!( + msg.stec_residuals[29].stddev, 108, + "incorrect value for stec_residuals[29].stddev, expected 108, is {}", + msg.stec_residuals[29].stddev + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 117, "incorrect value for stec_residuals[29].sv_id.constellation, expected 117, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 5, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, 30609, + "incorrect value for stec_residuals[30].residual, expected 30609, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!( + msg.stec_residuals[30].stddev, 226, + "incorrect value for stec_residuals[30].stddev, expected 226, is {}", + msg.stec_residuals[30].stddev + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 212, "incorrect value for stec_residuals[30].sv_id.constellation, expected 212, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 248, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 248, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, -13683, + "incorrect value for stec_residuals[31].residual, expected -13683, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!( + msg.stec_residuals[31].stddev, 106, + "incorrect value for stec_residuals[31].stddev, expected 106, is {}", + msg.stec_residuals[31].stddev + ); + assert_eq!( + msg.stec_residuals[31].sv_id.constellation, 5, + "incorrect value for stec_residuals[31].sv_id.constellation, expected 5, is {}", + msg.stec_residuals[31].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 165, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 165, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, 15652, + "incorrect value for stec_residuals[32].residual, expected 15652, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!( + msg.stec_residuals[32].stddev, 243, + "incorrect value for stec_residuals[32].stddev, expected 243, is {}", + msg.stec_residuals[32].stddev + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 60, "incorrect value for stec_residuals[32].sv_id.constellation, expected 60, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 0, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 3287, + "incorrect value for stec_residuals[33].residual, expected 3287, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!( + msg.stec_residuals[33].stddev, 137, + "incorrect value for stec_residuals[33].stddev, expected 137, is {}", + msg.stec_residuals[33].stddev + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 216, "incorrect value for stec_residuals[33].sv_id.constellation, expected 216, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 203, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, 29687, + "incorrect value for stec_residuals[34].residual, expected 29687, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!( + msg.stec_residuals[34].stddev, 152, + "incorrect value for stec_residuals[34].stddev, expected 152, is {}", + msg.stec_residuals[34].stddev + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 28, "incorrect value for stec_residuals[34].sv_id.constellation, expected 28, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 16, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 16, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, -6960, + "incorrect value for stec_residuals[35].residual, expected -6960, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!( + msg.stec_residuals[35].stddev, 203, + "incorrect value for stec_residuals[35].stddev, expected 203, is {}", + msg.stec_residuals[35].stddev + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 119, "incorrect value for stec_residuals[35].sv_id.constellation, expected 119, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 181, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -15193, + "incorrect value for stec_residuals[36].residual, expected -15193, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!( + msg.stec_residuals[36].stddev, 32, + "incorrect value for stec_residuals[36].stddev, expected 32, is {}", + msg.stec_residuals[36].stddev + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 34, "incorrect value for stec_residuals[36].sv_id.constellation, expected 34, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 236, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 236, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, 25873, + "incorrect value for stec_residuals[37].residual, expected 25873, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!( + msg.stec_residuals[37].stddev, 200, + "incorrect value for stec_residuals[37].stddev, expected 200, is {}", + msg.stec_residuals[37].stddev + ); + assert_eq!( + msg.stec_residuals[37].sv_id.constellation, 1, + "incorrect value for stec_residuals[37].sv_id.constellation, expected 1, is {}", + msg.stec_residuals[37].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 109, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 109, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, -22403, + "incorrect value for stec_residuals[38].residual, expected -22403, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!( + msg.stec_residuals[38].stddev, 137, + "incorrect value for stec_residuals[38].stddev, expected 137, is {}", + msg.stec_residuals[38].stddev + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 94, "incorrect value for stec_residuals[38].sv_id.constellation, expected 94, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 25, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 25, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, 7588, + "incorrect value for stec_residuals[39].residual, expected 7588, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!( + msg.stec_residuals[39].stddev, 31, + "incorrect value for stec_residuals[39].stddev, expected 31, is {}", + msg.stec_residuals[39].stddev + ); + assert_eq!( + msg.stec_residuals[39].sv_id.constellation, 4, + "incorrect value for stec_residuals[39].sv_id.constellation, expected 4, is {}", + msg.stec_residuals[39].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 157, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 157, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -6840, + "incorrect value for stec_residuals[40].residual, expected -6840, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!( + msg.stec_residuals[40].stddev, 126, + "incorrect value for stec_residuals[40].stddev, expected 126, is {}", + msg.stec_residuals[40].stddev + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 132, "incorrect value for stec_residuals[40].sv_id.constellation, expected 132, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 48, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 48, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, -31412, + "incorrect value for stec_residuals[41].residual, expected -31412, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!( + msg.stec_residuals[41].stddev, 21, + "incorrect value for stec_residuals[41].stddev, expected 21, is {}", + msg.stec_residuals[41].stddev + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 68, "incorrect value for stec_residuals[41].sv_id.constellation, expected 68, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 186, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 186, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, -23413, + "incorrect value for stec_residuals[42].residual, expected -23413, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!( + msg.stec_residuals[42].stddev, 148, + "incorrect value for stec_residuals[42].stddev, expected 148, is {}", + msg.stec_residuals[42].stddev + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 180, "incorrect value for stec_residuals[42].sv_id.constellation, expected 180, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 0, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 0, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 30934, + "incorrect value for stec_residuals[43].residual, expected 30934, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!( + msg.stec_residuals[43].stddev, 177, + "incorrect value for stec_residuals[43].stddev, expected 177, is {}", + msg.stec_residuals[43].stddev + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 149, "incorrect value for stec_residuals[43].sv_id.constellation, expected 149, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 119, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 119, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 26960, + "incorrect value for stec_residuals[44].residual, expected 26960, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!( + msg.stec_residuals[44].stddev, 10, + "incorrect value for stec_residuals[44].stddev, expected 10, is {}", + msg.stec_residuals[44].stddev + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 80, "incorrect value for stec_residuals[44].sv_id.constellation, expected 80, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 201, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 201, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 11853, + "incorrect value for stec_residuals[45].residual, expected 11853, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!( + msg.stec_residuals[45].stddev, 233, + "incorrect value for stec_residuals[45].stddev, expected 233, is {}", + msg.stec_residuals[45].stddev + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 118, "incorrect value for stec_residuals[45].sv_id.constellation, expected 118, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 136, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 136, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -25077, + "incorrect value for stec_residuals[46].residual, expected -25077, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!( + msg.stec_residuals[46].stddev, 103, + "incorrect value for stec_residuals[46].stddev, expected 103, is {}", + msg.stec_residuals[46].stddev + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 227, "incorrect value for stec_residuals[46].sv_id.constellation, expected 227, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 233, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 10643, + "incorrect value for tropo_delay_correction.hydro, expected 10643, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.stddev, 92, + "incorrect value for tropo_delay_correction.stddev, expected 92, is {}", + msg.tropo_delay_correction.stddev + ); + assert_eq!( + msg.tropo_delay_correction.wet, 33, + "incorrect value for tropo_delay_correction.wet, expected 33, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a.rs new file mode 100644 index 0000000000..3ab923eae1 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a.rs @@ -0,0 +1,2350 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, 67, 248, 233, 236, 230, + 230, 103, 122, 63, 101, 231, 157, 115, 162, 197, 146, 35, 107, 222, 109, 52, 41, 86, + 12, 237, 184, 65, 204, 137, 148, 171, 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, + 203, 92, 166, 30, 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, 95, 250, 99, 196, 92, + 214, 159, 253, 195, 222, 233, 146, 233, 63, 76, 24, 106, 40, 253, 65, 9, 183, 40, 215, + 188, 59, 117, 69, 97, 115, 60, 56, 0, 141, 207, 171, 54, 161, 23, 61, 0, 87, 230, 123, + 87, 36, 184, 255, 14, 163, 187, 224, 43, 151, 151, 104, 39, 57, 5, 54, 48, 224, 181, + 129, 60, 92, 171, 114, 109, 109, 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, 24, 68, 160, + 36, 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, 221, 253, 15, 62, 23, 121, 185, + 168, 116, 4, 147, 123, 72, 223, 119, 226, 242, 161, 204, 180, 202, 137, 166, 58, 24, + 124, 19, 181, 188, 16, 107, 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, + 221, 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, 99, 44, 95, 131, 89, + 192, 225, 55, 95, 171, 88, 205, 21, 116, 231, 83, 71, 71, 100, 110, 217, 254, 152, 212, + 18, 8, 40, 157, 244, 54, 72, 240, 231, 189, 111, 195, 205, 81, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionNoStdDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f0, + "Incorrect message type, expected 0x5f0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c66, + "incorrect sender id, expected 0x1c66, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 236, + "incorrect value for header.iod_atmo, expected 236, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 62837, + "incorrect value for header.num_msgs, expected 62837, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 63555, + "incorrect value for header.seq_num, expected 63555, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 2837573811, + "incorrect value for header.time.tow, expected 2837573811, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 8940, + "incorrect value for header.time.wn, expected 8940, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 230, + "incorrect value for header.tropo_quality_indicator, expected 230, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 233, + "incorrect value for header.update_interval, expected 233, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 26598, + "incorrect value for index, expected 26598, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -23949, + "incorrect value for stec_residuals[0].residual, expected -23949, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 157, "incorrect value for stec_residuals[0].sv_id.constellation, expected 157, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 231, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 27427, + "incorrect value for stec_residuals[1].residual, expected 27427, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 146, "incorrect value for stec_residuals[1].sv_id.constellation, expected 146, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 197, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 10548, + "incorrect value for stec_residuals[2].residual, expected 10548, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 109, "incorrect value for stec_residuals[2].sv_id.constellation, expected 109, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 222, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 222, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -18195, + "incorrect value for stec_residuals[3].residual, expected -18195, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 12, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 12, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 86, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 86, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, -27511, + "incorrect value for stec_residuals[4].residual, expected -27511, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 204, "incorrect value for stec_residuals[4].sv_id.constellation, expected 204, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 65, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 65, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 11, + "incorrect value for stec_residuals[5].residual, expected 11, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 183, "incorrect value for stec_residuals[5].sv_id.constellation, expected 183, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 171, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 13740, + "incorrect value for stec_residuals[6].residual, expected 13740, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 203, "incorrect value for stec_residuals[6].sv_id.constellation, expected 203, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 180, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 29626, + "incorrect value for stec_residuals[7].residual, expected 29626, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].sv_id.constellation, 85, + "incorrect value for stec_residuals[7].sv_id.constellation, expected 85, is {}", + msg.stec_residuals[7].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 196, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 196, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 7846, + "incorrect value for stec_residuals[8].residual, expected 7846, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 92, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 92, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 203, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 18376, + "incorrect value for stec_residuals[9].residual, expected 18376, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 13, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 13, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 42, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, -24357, + "incorrect value for stec_residuals[10].residual, expected -24357, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 137, "incorrect value for stec_residuals[10].sv_id.constellation, expected 137, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 98, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 98, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, -1441, + "incorrect value for stec_residuals[11].residual, expected -1441, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 216, "incorrect value for stec_residuals[11].sv_id.constellation, expected 216, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 95, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -10660, + "incorrect value for stec_residuals[12].residual, expected -10660, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 196, "incorrect value for stec_residuals[12].sv_id.constellation, expected 196, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 99, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -8509, + "incorrect value for stec_residuals[13].residual, expected -8509, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 253, "incorrect value for stec_residuals[13].sv_id.constellation, expected 253, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 159, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 159, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, 16361, + "incorrect value for stec_residuals[14].residual, expected 16361, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 146, "incorrect value for stec_residuals[14].sv_id.constellation, expected 146, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 233, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 10346, + "incorrect value for stec_residuals[15].residual, expected 10346, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 24, "incorrect value for stec_residuals[15].sv_id.constellation, expected 24, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 76, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 76, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -18679, + "incorrect value for stec_residuals[16].residual, expected -18679, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 65, "incorrect value for stec_residuals[16].sv_id.constellation, expected 65, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 253, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 253, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 15292, + "incorrect value for stec_residuals[17].residual, expected 15292, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 215, "incorrect value for stec_residuals[17].sv_id.constellation, expected 215, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 40, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 29537, + "incorrect value for stec_residuals[18].residual, expected 29537, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 69, "incorrect value for stec_residuals[18].sv_id.constellation, expected 69, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 117, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, -29440, + "incorrect value for stec_residuals[19].residual, expected -29440, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 56, "incorrect value for stec_residuals[19].sv_id.constellation, expected 56, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 60, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 60, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -24266, + "incorrect value for stec_residuals[20].residual, expected -24266, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 171, "incorrect value for stec_residuals[20].sv_id.constellation, expected 171, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 207, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 22272, + "incorrect value for stec_residuals[21].residual, expected 22272, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 61, "incorrect value for stec_residuals[21].sv_id.constellation, expected 61, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 23, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, 9303, + "incorrect value for stec_residuals[22].residual, expected 9303, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 123, "incorrect value for stec_residuals[22].sv_id.constellation, expected 123, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 230, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 230, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -23794, + "incorrect value for stec_residuals[23].residual, expected -23794, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 255, "incorrect value for stec_residuals[23].sv_id.constellation, expected 255, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 184, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 184, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -26837, + "incorrect value for stec_residuals[24].residual, expected -26837, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 224, "incorrect value for stec_residuals[24].sv_id.constellation, expected 224, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 187, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 187, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 14631, + "incorrect value for stec_residuals[25].residual, expected 14631, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 104, "incorrect value for stec_residuals[25].sv_id.constellation, expected 104, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 151, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, -8144, + "incorrect value for stec_residuals[26].residual, expected -8144, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 54, "incorrect value for stec_residuals[26].sv_id.constellation, expected 54, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 5, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, 23612, + "incorrect value for stec_residuals[27].residual, expected 23612, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 129, "incorrect value for stec_residuals[27].sv_id.constellation, expected 129, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 181, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 28013, + "incorrect value for stec_residuals[28].residual, expected 28013, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 114, "incorrect value for stec_residuals[28].sv_id.constellation, expected 114, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 171, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 2166, + "incorrect value for stec_residuals[29].residual, expected 2166, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 23, "incorrect value for stec_residuals[29].sv_id.constellation, expected 23, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 12, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 12, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, -10186, + "incorrect value for stec_residuals[30].residual, expected -10186, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 159, "incorrect value for stec_residuals[30].sv_id.constellation, expected 159, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 64, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 17432, + "incorrect value for stec_residuals[31].residual, expected 17432, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 20, "incorrect value for stec_residuals[31].sv_id.constellation, expected 20, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 33, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 33, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, -8666, + "incorrect value for stec_residuals[32].residual, expected -8666, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 36, "incorrect value for stec_residuals[32].sv_id.constellation, expected 36, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 160, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 160, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 25436, + "incorrect value for stec_residuals[33].residual, expected 25436, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 190, "incorrect value for stec_residuals[33].sv_id.constellation, expected 190, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 145, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 145, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, -3864, + "incorrect value for stec_residuals[34].residual, expected -3864, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 159, "incorrect value for stec_residuals[34].sv_id.constellation, expected 159, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 108, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 108, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, 4093, + "incorrect value for stec_residuals[35].residual, expected 4093, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 221, "incorrect value for stec_residuals[35].sv_id.constellation, expected 221, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 227, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 227, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -18055, + "incorrect value for stec_residuals[36].residual, expected -18055, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 23, "incorrect value for stec_residuals[36].sv_id.constellation, expected 23, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 62, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 62, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -27900, + "incorrect value for stec_residuals[37].residual, expected -27900, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 116, "incorrect value for stec_residuals[37].sv_id.constellation, expected 116, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 168, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 168, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 30687, + "incorrect value for stec_residuals[38].residual, expected 30687, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 72, "incorrect value for stec_residuals[38].sv_id.constellation, expected 72, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 123, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 123, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -13151, + "incorrect value for stec_residuals[39].residual, expected -13151, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 242, "incorrect value for stec_residuals[39].sv_id.constellation, expected 242, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 226, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 226, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -22903, + "incorrect value for stec_residuals[40].residual, expected -22903, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 202, "incorrect value for stec_residuals[40].sv_id.constellation, expected 202, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 180, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 4988, + "incorrect value for stec_residuals[41].residual, expected 4988, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 24, "incorrect value for stec_residuals[41].sv_id.constellation, expected 24, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 58, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 58, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 27408, + "incorrect value for stec_residuals[42].residual, expected 27408, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 188, "incorrect value for stec_residuals[42].sv_id.constellation, expected 188, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 181, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 319, + "incorrect value for stec_residuals[43].residual, expected 319, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 231, "incorrect value for stec_residuals[43].sv_id.constellation, expected 231, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 66, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 66, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 15987, + "incorrect value for stec_residuals[44].residual, expected 15987, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 252, "incorrect value for stec_residuals[44].sv_id.constellation, expected 252, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 64, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 22266, + "incorrect value for stec_residuals[45].residual, expected 22266, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 97, "incorrect value for stec_residuals[45].sv_id.constellation, expected 97, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 233, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -19919, + "incorrect value for stec_residuals[46].residual, expected -19919, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 221, "incorrect value for stec_residuals[46].sv_id.constellation, expected 221, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 156, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[47].residual, 17350, + "incorrect value for stec_residuals[47].residual, expected 17350, is {}", + msg.stec_residuals[47].residual + ); + assert_eq!(msg.stec_residuals[47].sv_id.constellation, 73, "incorrect value for stec_residuals[47].sv_id.constellation, expected 73, is {}", msg.stec_residuals[47].sv_id.constellation); + assert_eq!( + msg.stec_residuals[47].sv_id.sat_id, 32, + "incorrect value for stec_residuals[47].sv_id.sat_id, expected 32, is {}", + msg.stec_residuals[47].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[48].residual, 14410, + "incorrect value for stec_residuals[48].residual, expected 14410, is {}", + msg.stec_residuals[48].residual + ); + assert_eq!(msg.stec_residuals[48].sv_id.constellation, 253, "incorrect value for stec_residuals[48].sv_id.constellation, expected 253, is {}", msg.stec_residuals[48].sv_id.constellation); + assert_eq!( + msg.stec_residuals[48].sv_id.sat_id, 249, + "incorrect value for stec_residuals[48].sv_id.sat_id, expected 249, is {}", + msg.stec_residuals[48].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[49].residual, 23671, + "incorrect value for stec_residuals[49].residual, expected 23671, is {}", + msg.stec_residuals[49].residual + ); + assert_eq!(msg.stec_residuals[49].sv_id.constellation, 165, "incorrect value for stec_residuals[49].sv_id.constellation, expected 165, is {}", msg.stec_residuals[49].sv_id.constellation); + assert_eq!( + msg.stec_residuals[49].sv_id.sat_id, 38, + "incorrect value for stec_residuals[49].sv_id.sat_id, expected 38, is {}", + msg.stec_residuals[49].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[50].residual, -31905, + "incorrect value for stec_residuals[50].residual, expected -31905, is {}", + msg.stec_residuals[50].residual + ); + assert_eq!(msg.stec_residuals[50].sv_id.constellation, 44, "incorrect value for stec_residuals[50].sv_id.constellation, expected 44, is {}", msg.stec_residuals[50].sv_id.constellation); + assert_eq!( + msg.stec_residuals[50].sv_id.sat_id, 99, + "incorrect value for stec_residuals[50].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[50].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[51].residual, 14305, + "incorrect value for stec_residuals[51].residual, expected 14305, is {}", + msg.stec_residuals[51].residual + ); + assert_eq!(msg.stec_residuals[51].sv_id.constellation, 192, "incorrect value for stec_residuals[51].sv_id.constellation, expected 192, is {}", msg.stec_residuals[51].sv_id.constellation); + assert_eq!( + msg.stec_residuals[51].sv_id.sat_id, 89, + "incorrect value for stec_residuals[51].sv_id.sat_id, expected 89, is {}", + msg.stec_residuals[51].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[52].residual, -12968, + "incorrect value for stec_residuals[52].residual, expected -12968, is {}", + msg.stec_residuals[52].residual + ); + assert_eq!(msg.stec_residuals[52].sv_id.constellation, 171, "incorrect value for stec_residuals[52].sv_id.constellation, expected 171, is {}", msg.stec_residuals[52].sv_id.constellation); + assert_eq!( + msg.stec_residuals[52].sv_id.sat_id, 95, + "incorrect value for stec_residuals[52].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[52].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[53].residual, 21479, + "incorrect value for stec_residuals[53].residual, expected 21479, is {}", + msg.stec_residuals[53].residual + ); + assert_eq!(msg.stec_residuals[53].sv_id.constellation, 116, "incorrect value for stec_residuals[53].sv_id.constellation, expected 116, is {}", msg.stec_residuals[53].sv_id.constellation); + assert_eq!( + msg.stec_residuals[53].sv_id.sat_id, 21, + "incorrect value for stec_residuals[53].sv_id.sat_id, expected 21, is {}", + msg.stec_residuals[53].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[54].residual, 28260, + "incorrect value for stec_residuals[54].residual, expected 28260, is {}", + msg.stec_residuals[54].residual + ); + assert_eq!(msg.stec_residuals[54].sv_id.constellation, 71, "incorrect value for stec_residuals[54].sv_id.constellation, expected 71, is {}", msg.stec_residuals[54].sv_id.constellation); + assert_eq!( + msg.stec_residuals[54].sv_id.sat_id, 71, + "incorrect value for stec_residuals[54].sv_id.sat_id, expected 71, is {}", + msg.stec_residuals[54].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[55].residual, -11112, + "incorrect value for stec_residuals[55].residual, expected -11112, is {}", + msg.stec_residuals[55].residual + ); + assert_eq!(msg.stec_residuals[55].sv_id.constellation, 254, "incorrect value for stec_residuals[55].sv_id.constellation, expected 254, is {}", msg.stec_residuals[55].sv_id.constellation); + assert_eq!( + msg.stec_residuals[55].sv_id.sat_id, 217, + "incorrect value for stec_residuals[55].sv_id.sat_id, expected 217, is {}", + msg.stec_residuals[55].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[56].residual, -25304, + "incorrect value for stec_residuals[56].residual, expected -25304, is {}", + msg.stec_residuals[56].residual + ); + assert_eq!( + msg.stec_residuals[56].sv_id.constellation, 8, + "incorrect value for stec_residuals[56].sv_id.constellation, expected 8, is {}", + msg.stec_residuals[56].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[56].sv_id.sat_id, 18, + "incorrect value for stec_residuals[56].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[56].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[57].residual, -4024, + "incorrect value for stec_residuals[57].residual, expected -4024, is {}", + msg.stec_residuals[57].residual + ); + assert_eq!(msg.stec_residuals[57].sv_id.constellation, 54, "incorrect value for stec_residuals[57].sv_id.constellation, expected 54, is {}", msg.stec_residuals[57].sv_id.constellation); + assert_eq!( + msg.stec_residuals[57].sv_id.sat_id, 244, + "incorrect value for stec_residuals[57].sv_id.sat_id, expected 244, is {}", + msg.stec_residuals[57].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[58].residual, -15505, + "incorrect value for stec_residuals[58].residual, expected -15505, is {}", + msg.stec_residuals[58].residual + ); + assert_eq!(msg.stec_residuals[58].sv_id.constellation, 189, "incorrect value for stec_residuals[58].sv_id.constellation, expected 189, is {}", msg.stec_residuals[58].sv_id.constellation); + assert_eq!( + msg.stec_residuals[58].sv_id.sat_id, 231, + "incorrect value for stec_residuals[58].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[58].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 16250, + "incorrect value for tropo_delay_correction.hydro, expected 16250, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.wet, 101, + "incorrect value for tropo_delay_correction.wet, expected 101, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionNoStdDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a() { + { + let json_input = r#"{"crc":20941,"length":254,"msg_type":1520,"payload":"s/AhqewidfVD+Ons5uZnej9l551zosWSI2vebTQpVgztuEHMiZSrtwsAtMusNcRVunPLXKYeKg3IR2KJ26Bf2F/6Y8Rc1p/9w97pkuk/TBhqKP1BCbco17w7dUVhczw4AI3PqzahFz0AV+Z7VyS4/w6ju+Arl5doJzkFNjDgtYE8XKtybW0MF3YIQJ822CEUGESgJCbekb5cY2yf6PDj3f0PPhd5uah0BJN7SN934vKhzLTKiaY6GHwTtbwQa0LnPwFA/HM+6WH6VpzdMbIgScZD+f1KOCald1xjLF+DWcDhN1+rWM0VdOdTR0dkbtn+mNQSCCid9DZI8Oe9b8M=","preamble":85,"sender":7270,"header":{"time":{"tow":2837573811,"wn":8940},"num_msgs":62837,"seq_num":63555,"update_interval":233,"iod_atmo":236,"tropo_quality_indicator":230},"index":26598,"tropo_delay_correction":{"hydro":16250,"wet":101},"stec_residuals":[{"sv_id":{"satId":231,"constellation":157},"residual":-23949},{"sv_id":{"satId":197,"constellation":146},"residual":27427},{"sv_id":{"satId":222,"constellation":109},"residual":10548},{"sv_id":{"satId":86,"constellation":12},"residual":-18195},{"sv_id":{"satId":65,"constellation":204},"residual":-27511},{"sv_id":{"satId":171,"constellation":183},"residual":11},{"sv_id":{"satId":180,"constellation":203},"residual":13740},{"sv_id":{"satId":196,"constellation":85},"residual":29626},{"sv_id":{"satId":203,"constellation":92},"residual":7846},{"sv_id":{"satId":42,"constellation":13},"residual":18376},{"sv_id":{"satId":98,"constellation":137},"residual":-24357},{"sv_id":{"satId":95,"constellation":216},"residual":-1441},{"sv_id":{"satId":99,"constellation":196},"residual":-10660},{"sv_id":{"satId":159,"constellation":253},"residual":-8509},{"sv_id":{"satId":233,"constellation":146},"residual":16361},{"sv_id":{"satId":76,"constellation":24},"residual":10346},{"sv_id":{"satId":253,"constellation":65},"residual":-18679},{"sv_id":{"satId":40,"constellation":215},"residual":15292},{"sv_id":{"satId":117,"constellation":69},"residual":29537},{"sv_id":{"satId":60,"constellation":56},"residual":-29440},{"sv_id":{"satId":207,"constellation":171},"residual":-24266},{"sv_id":{"satId":23,"constellation":61},"residual":22272},{"sv_id":{"satId":230,"constellation":123},"residual":9303},{"sv_id":{"satId":184,"constellation":255},"residual":-23794},{"sv_id":{"satId":187,"constellation":224},"residual":-26837},{"sv_id":{"satId":151,"constellation":104},"residual":14631},{"sv_id":{"satId":5,"constellation":54},"residual":-8144},{"sv_id":{"satId":181,"constellation":129},"residual":23612},{"sv_id":{"satId":171,"constellation":114},"residual":28013},{"sv_id":{"satId":12,"constellation":23},"residual":2166},{"sv_id":{"satId":64,"constellation":159},"residual":-10186},{"sv_id":{"satId":33,"constellation":20},"residual":17432},{"sv_id":{"satId":160,"constellation":36},"residual":-8666},{"sv_id":{"satId":145,"constellation":190},"residual":25436},{"sv_id":{"satId":108,"constellation":159},"residual":-3864},{"sv_id":{"satId":227,"constellation":221},"residual":4093},{"sv_id":{"satId":62,"constellation":23},"residual":-18055},{"sv_id":{"satId":168,"constellation":116},"residual":-27900},{"sv_id":{"satId":123,"constellation":72},"residual":30687},{"sv_id":{"satId":226,"constellation":242},"residual":-13151},{"sv_id":{"satId":180,"constellation":202},"residual":-22903},{"sv_id":{"satId":58,"constellation":24},"residual":4988},{"sv_id":{"satId":181,"constellation":188},"residual":27408},{"sv_id":{"satId":66,"constellation":231},"residual":319},{"sv_id":{"satId":64,"constellation":252},"residual":15987},{"sv_id":{"satId":233,"constellation":97},"residual":22266},{"sv_id":{"satId":156,"constellation":221},"residual":-19919},{"sv_id":{"satId":32,"constellation":73},"residual":17350},{"sv_id":{"satId":249,"constellation":253},"residual":14410},{"sv_id":{"satId":38,"constellation":165},"residual":23671},{"sv_id":{"satId":99,"constellation":44},"residual":-31905},{"sv_id":{"satId":89,"constellation":192},"residual":14305},{"sv_id":{"satId":95,"constellation":171},"residual":-12968},{"sv_id":{"satId":21,"constellation":116},"residual":21479},{"sv_id":{"satId":71,"constellation":71},"residual":28260},{"sv_id":{"satId":217,"constellation":254},"residual":-11112},{"sv_id":{"satId":18,"constellation":8},"residual":-25304},{"sv_id":{"satId":244,"constellation":54},"residual":-4024},{"sv_id":{"satId":231,"constellation":189},"residual":-15505}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionNoStdDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f0, + "Incorrect message type, expected 0x5f0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c66, + "incorrect sender id, expected 0x1c66, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 236, + "incorrect value for header.iod_atmo, expected 236, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 62837, + "incorrect value for header.num_msgs, expected 62837, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 63555, + "incorrect value for header.seq_num, expected 63555, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 2837573811, + "incorrect value for header.time.tow, expected 2837573811, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 8940, + "incorrect value for header.time.wn, expected 8940, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 230, + "incorrect value for header.tropo_quality_indicator, expected 230, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 233, + "incorrect value for header.update_interval, expected 233, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 26598, + "incorrect value for index, expected 26598, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -23949, + "incorrect value for stec_residuals[0].residual, expected -23949, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 157, "incorrect value for stec_residuals[0].sv_id.constellation, expected 157, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 231, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 27427, + "incorrect value for stec_residuals[1].residual, expected 27427, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 146, "incorrect value for stec_residuals[1].sv_id.constellation, expected 146, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 197, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 10548, + "incorrect value for stec_residuals[2].residual, expected 10548, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 109, "incorrect value for stec_residuals[2].sv_id.constellation, expected 109, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 222, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 222, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -18195, + "incorrect value for stec_residuals[3].residual, expected -18195, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 12, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 12, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 86, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 86, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, -27511, + "incorrect value for stec_residuals[4].residual, expected -27511, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 204, "incorrect value for stec_residuals[4].sv_id.constellation, expected 204, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 65, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 65, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 11, + "incorrect value for stec_residuals[5].residual, expected 11, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 183, "incorrect value for stec_residuals[5].sv_id.constellation, expected 183, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 171, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 13740, + "incorrect value for stec_residuals[6].residual, expected 13740, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 203, "incorrect value for stec_residuals[6].sv_id.constellation, expected 203, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 180, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 29626, + "incorrect value for stec_residuals[7].residual, expected 29626, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].sv_id.constellation, 85, + "incorrect value for stec_residuals[7].sv_id.constellation, expected 85, is {}", + msg.stec_residuals[7].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 196, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 196, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 7846, + "incorrect value for stec_residuals[8].residual, expected 7846, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 92, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 92, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 203, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 18376, + "incorrect value for stec_residuals[9].residual, expected 18376, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 13, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 13, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 42, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, -24357, + "incorrect value for stec_residuals[10].residual, expected -24357, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 137, "incorrect value for stec_residuals[10].sv_id.constellation, expected 137, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 98, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 98, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, -1441, + "incorrect value for stec_residuals[11].residual, expected -1441, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 216, "incorrect value for stec_residuals[11].sv_id.constellation, expected 216, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 95, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -10660, + "incorrect value for stec_residuals[12].residual, expected -10660, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 196, "incorrect value for stec_residuals[12].sv_id.constellation, expected 196, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 99, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -8509, + "incorrect value for stec_residuals[13].residual, expected -8509, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 253, "incorrect value for stec_residuals[13].sv_id.constellation, expected 253, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 159, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 159, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, 16361, + "incorrect value for stec_residuals[14].residual, expected 16361, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 146, "incorrect value for stec_residuals[14].sv_id.constellation, expected 146, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 233, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 10346, + "incorrect value for stec_residuals[15].residual, expected 10346, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 24, "incorrect value for stec_residuals[15].sv_id.constellation, expected 24, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 76, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 76, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -18679, + "incorrect value for stec_residuals[16].residual, expected -18679, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 65, "incorrect value for stec_residuals[16].sv_id.constellation, expected 65, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 253, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 253, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 15292, + "incorrect value for stec_residuals[17].residual, expected 15292, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 215, "incorrect value for stec_residuals[17].sv_id.constellation, expected 215, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 40, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 29537, + "incorrect value for stec_residuals[18].residual, expected 29537, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 69, "incorrect value for stec_residuals[18].sv_id.constellation, expected 69, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 117, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, -29440, + "incorrect value for stec_residuals[19].residual, expected -29440, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 56, "incorrect value for stec_residuals[19].sv_id.constellation, expected 56, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 60, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 60, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -24266, + "incorrect value for stec_residuals[20].residual, expected -24266, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 171, "incorrect value for stec_residuals[20].sv_id.constellation, expected 171, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 207, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 22272, + "incorrect value for stec_residuals[21].residual, expected 22272, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 61, "incorrect value for stec_residuals[21].sv_id.constellation, expected 61, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 23, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, 9303, + "incorrect value for stec_residuals[22].residual, expected 9303, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 123, "incorrect value for stec_residuals[22].sv_id.constellation, expected 123, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 230, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 230, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -23794, + "incorrect value for stec_residuals[23].residual, expected -23794, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 255, "incorrect value for stec_residuals[23].sv_id.constellation, expected 255, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 184, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 184, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -26837, + "incorrect value for stec_residuals[24].residual, expected -26837, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 224, "incorrect value for stec_residuals[24].sv_id.constellation, expected 224, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 187, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 187, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 14631, + "incorrect value for stec_residuals[25].residual, expected 14631, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 104, "incorrect value for stec_residuals[25].sv_id.constellation, expected 104, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 151, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, -8144, + "incorrect value for stec_residuals[26].residual, expected -8144, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 54, "incorrect value for stec_residuals[26].sv_id.constellation, expected 54, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 5, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, 23612, + "incorrect value for stec_residuals[27].residual, expected 23612, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 129, "incorrect value for stec_residuals[27].sv_id.constellation, expected 129, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 181, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 28013, + "incorrect value for stec_residuals[28].residual, expected 28013, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 114, "incorrect value for stec_residuals[28].sv_id.constellation, expected 114, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 171, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 2166, + "incorrect value for stec_residuals[29].residual, expected 2166, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 23, "incorrect value for stec_residuals[29].sv_id.constellation, expected 23, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 12, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 12, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, -10186, + "incorrect value for stec_residuals[30].residual, expected -10186, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 159, "incorrect value for stec_residuals[30].sv_id.constellation, expected 159, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 64, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 17432, + "incorrect value for stec_residuals[31].residual, expected 17432, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 20, "incorrect value for stec_residuals[31].sv_id.constellation, expected 20, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 33, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 33, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, -8666, + "incorrect value for stec_residuals[32].residual, expected -8666, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 36, "incorrect value for stec_residuals[32].sv_id.constellation, expected 36, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 160, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 160, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 25436, + "incorrect value for stec_residuals[33].residual, expected 25436, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 190, "incorrect value for stec_residuals[33].sv_id.constellation, expected 190, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 145, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 145, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, -3864, + "incorrect value for stec_residuals[34].residual, expected -3864, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 159, "incorrect value for stec_residuals[34].sv_id.constellation, expected 159, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 108, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 108, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, 4093, + "incorrect value for stec_residuals[35].residual, expected 4093, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 221, "incorrect value for stec_residuals[35].sv_id.constellation, expected 221, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 227, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 227, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -18055, + "incorrect value for stec_residuals[36].residual, expected -18055, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 23, "incorrect value for stec_residuals[36].sv_id.constellation, expected 23, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 62, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 62, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -27900, + "incorrect value for stec_residuals[37].residual, expected -27900, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 116, "incorrect value for stec_residuals[37].sv_id.constellation, expected 116, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 168, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 168, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 30687, + "incorrect value for stec_residuals[38].residual, expected 30687, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 72, "incorrect value for stec_residuals[38].sv_id.constellation, expected 72, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 123, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 123, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -13151, + "incorrect value for stec_residuals[39].residual, expected -13151, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 242, "incorrect value for stec_residuals[39].sv_id.constellation, expected 242, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 226, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 226, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -22903, + "incorrect value for stec_residuals[40].residual, expected -22903, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 202, "incorrect value for stec_residuals[40].sv_id.constellation, expected 202, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 180, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 4988, + "incorrect value for stec_residuals[41].residual, expected 4988, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 24, "incorrect value for stec_residuals[41].sv_id.constellation, expected 24, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 58, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 58, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 27408, + "incorrect value for stec_residuals[42].residual, expected 27408, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 188, "incorrect value for stec_residuals[42].sv_id.constellation, expected 188, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 181, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 319, + "incorrect value for stec_residuals[43].residual, expected 319, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 231, "incorrect value for stec_residuals[43].sv_id.constellation, expected 231, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 66, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 66, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 15987, + "incorrect value for stec_residuals[44].residual, expected 15987, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 252, "incorrect value for stec_residuals[44].sv_id.constellation, expected 252, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 64, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 22266, + "incorrect value for stec_residuals[45].residual, expected 22266, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 97, "incorrect value for stec_residuals[45].sv_id.constellation, expected 97, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 233, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -19919, + "incorrect value for stec_residuals[46].residual, expected -19919, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 221, "incorrect value for stec_residuals[46].sv_id.constellation, expected 221, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 156, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[47].residual, 17350, + "incorrect value for stec_residuals[47].residual, expected 17350, is {}", + msg.stec_residuals[47].residual + ); + assert_eq!(msg.stec_residuals[47].sv_id.constellation, 73, "incorrect value for stec_residuals[47].sv_id.constellation, expected 73, is {}", msg.stec_residuals[47].sv_id.constellation); + assert_eq!( + msg.stec_residuals[47].sv_id.sat_id, 32, + "incorrect value for stec_residuals[47].sv_id.sat_id, expected 32, is {}", + msg.stec_residuals[47].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[48].residual, 14410, + "incorrect value for stec_residuals[48].residual, expected 14410, is {}", + msg.stec_residuals[48].residual + ); + assert_eq!(msg.stec_residuals[48].sv_id.constellation, 253, "incorrect value for stec_residuals[48].sv_id.constellation, expected 253, is {}", msg.stec_residuals[48].sv_id.constellation); + assert_eq!( + msg.stec_residuals[48].sv_id.sat_id, 249, + "incorrect value for stec_residuals[48].sv_id.sat_id, expected 249, is {}", + msg.stec_residuals[48].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[49].residual, 23671, + "incorrect value for stec_residuals[49].residual, expected 23671, is {}", + msg.stec_residuals[49].residual + ); + assert_eq!(msg.stec_residuals[49].sv_id.constellation, 165, "incorrect value for stec_residuals[49].sv_id.constellation, expected 165, is {}", msg.stec_residuals[49].sv_id.constellation); + assert_eq!( + msg.stec_residuals[49].sv_id.sat_id, 38, + "incorrect value for stec_residuals[49].sv_id.sat_id, expected 38, is {}", + msg.stec_residuals[49].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[50].residual, -31905, + "incorrect value for stec_residuals[50].residual, expected -31905, is {}", + msg.stec_residuals[50].residual + ); + assert_eq!(msg.stec_residuals[50].sv_id.constellation, 44, "incorrect value for stec_residuals[50].sv_id.constellation, expected 44, is {}", msg.stec_residuals[50].sv_id.constellation); + assert_eq!( + msg.stec_residuals[50].sv_id.sat_id, 99, + "incorrect value for stec_residuals[50].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[50].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[51].residual, 14305, + "incorrect value for stec_residuals[51].residual, expected 14305, is {}", + msg.stec_residuals[51].residual + ); + assert_eq!(msg.stec_residuals[51].sv_id.constellation, 192, "incorrect value for stec_residuals[51].sv_id.constellation, expected 192, is {}", msg.stec_residuals[51].sv_id.constellation); + assert_eq!( + msg.stec_residuals[51].sv_id.sat_id, 89, + "incorrect value for stec_residuals[51].sv_id.sat_id, expected 89, is {}", + msg.stec_residuals[51].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[52].residual, -12968, + "incorrect value for stec_residuals[52].residual, expected -12968, is {}", + msg.stec_residuals[52].residual + ); + assert_eq!(msg.stec_residuals[52].sv_id.constellation, 171, "incorrect value for stec_residuals[52].sv_id.constellation, expected 171, is {}", msg.stec_residuals[52].sv_id.constellation); + assert_eq!( + msg.stec_residuals[52].sv_id.sat_id, 95, + "incorrect value for stec_residuals[52].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[52].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[53].residual, 21479, + "incorrect value for stec_residuals[53].residual, expected 21479, is {}", + msg.stec_residuals[53].residual + ); + assert_eq!(msg.stec_residuals[53].sv_id.constellation, 116, "incorrect value for stec_residuals[53].sv_id.constellation, expected 116, is {}", msg.stec_residuals[53].sv_id.constellation); + assert_eq!( + msg.stec_residuals[53].sv_id.sat_id, 21, + "incorrect value for stec_residuals[53].sv_id.sat_id, expected 21, is {}", + msg.stec_residuals[53].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[54].residual, 28260, + "incorrect value for stec_residuals[54].residual, expected 28260, is {}", + msg.stec_residuals[54].residual + ); + assert_eq!(msg.stec_residuals[54].sv_id.constellation, 71, "incorrect value for stec_residuals[54].sv_id.constellation, expected 71, is {}", msg.stec_residuals[54].sv_id.constellation); + assert_eq!( + msg.stec_residuals[54].sv_id.sat_id, 71, + "incorrect value for stec_residuals[54].sv_id.sat_id, expected 71, is {}", + msg.stec_residuals[54].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[55].residual, -11112, + "incorrect value for stec_residuals[55].residual, expected -11112, is {}", + msg.stec_residuals[55].residual + ); + assert_eq!(msg.stec_residuals[55].sv_id.constellation, 254, "incorrect value for stec_residuals[55].sv_id.constellation, expected 254, is {}", msg.stec_residuals[55].sv_id.constellation); + assert_eq!( + msg.stec_residuals[55].sv_id.sat_id, 217, + "incorrect value for stec_residuals[55].sv_id.sat_id, expected 217, is {}", + msg.stec_residuals[55].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[56].residual, -25304, + "incorrect value for stec_residuals[56].residual, expected -25304, is {}", + msg.stec_residuals[56].residual + ); + assert_eq!( + msg.stec_residuals[56].sv_id.constellation, 8, + "incorrect value for stec_residuals[56].sv_id.constellation, expected 8, is {}", + msg.stec_residuals[56].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[56].sv_id.sat_id, 18, + "incorrect value for stec_residuals[56].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[56].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[57].residual, -4024, + "incorrect value for stec_residuals[57].residual, expected -4024, is {}", + msg.stec_residuals[57].residual + ); + assert_eq!(msg.stec_residuals[57].sv_id.constellation, 54, "incorrect value for stec_residuals[57].sv_id.constellation, expected 54, is {}", msg.stec_residuals[57].sv_id.constellation); + assert_eq!( + msg.stec_residuals[57].sv_id.sat_id, 244, + "incorrect value for stec_residuals[57].sv_id.sat_id, expected 244, is {}", + msg.stec_residuals[57].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[58].residual, -15505, + "incorrect value for stec_residuals[58].residual, expected -15505, is {}", + msg.stec_residuals[58].residual + ); + assert_eq!(msg.stec_residuals[58].sv_id.constellation, 189, "incorrect value for stec_residuals[58].sv_id.constellation, expected 189, is {}", msg.stec_residuals[58].sv_id.constellation); + assert_eq!( + msg.stec_residuals[58].sv_id.sat_id, 231, + "incorrect value for stec_residuals[58].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[58].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 16250, + "incorrect value for tropo_delay_correction.hydro, expected 16250, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.wet, 101, + "incorrect value for tropo_delay_correction.wet, expected 101, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionNoStdDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 240, 5, 102, 28, 254, 179, 240, 33, 169, 236, 34, 117, 245, 67, 248, 233, 236, 230, + 230, 103, 122, 63, 101, 231, 157, 115, 162, 197, 146, 35, 107, 222, 109, 52, 41, 86, + 12, 237, 184, 65, 204, 137, 148, 171, 183, 11, 0, 180, 203, 172, 53, 196, 85, 186, 115, + 203, 92, 166, 30, 42, 13, 200, 71, 98, 137, 219, 160, 95, 216, 95, 250, 99, 196, 92, + 214, 159, 253, 195, 222, 233, 146, 233, 63, 76, 24, 106, 40, 253, 65, 9, 183, 40, 215, + 188, 59, 117, 69, 97, 115, 60, 56, 0, 141, 207, 171, 54, 161, 23, 61, 0, 87, 230, 123, + 87, 36, 184, 255, 14, 163, 187, 224, 43, 151, 151, 104, 39, 57, 5, 54, 48, 224, 181, + 129, 60, 92, 171, 114, 109, 109, 12, 23, 118, 8, 64, 159, 54, 216, 33, 20, 24, 68, 160, + 36, 38, 222, 145, 190, 92, 99, 108, 159, 232, 240, 227, 221, 253, 15, 62, 23, 121, 185, + 168, 116, 4, 147, 123, 72, 223, 119, 226, 242, 161, 204, 180, 202, 137, 166, 58, 24, + 124, 19, 181, 188, 16, 107, 66, 231, 63, 1, 64, 252, 115, 62, 233, 97, 250, 86, 156, + 221, 49, 178, 32, 73, 198, 67, 249, 253, 74, 56, 38, 165, 119, 92, 99, 44, 95, 131, 89, + 192, 225, 55, 95, 171, 88, 205, 21, 116, 231, 83, 71, 71, 100, 110, 217, 254, 152, 212, + 18, 8, 40, 157, 244, 54, 72, 240, 231, 189, 111, 195, 205, 81, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrGriddedCorrectionNoStdDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrGriddedCorrectionNoStdDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f0, + "Incorrect message type, expected 0x5f0, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1c66, + "incorrect sender id, expected 0x1c66, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 236, + "incorrect value for header.iod_atmo, expected 236, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 62837, + "incorrect value for header.num_msgs, expected 62837, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 63555, + "incorrect value for header.seq_num, expected 63555, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 2837573811, + "incorrect value for header.time.tow, expected 2837573811, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 8940, + "incorrect value for header.time.wn, expected 8940, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.tropo_quality_indicator, 230, + "incorrect value for header.tropo_quality_indicator, expected 230, is {}", + msg.header.tropo_quality_indicator + ); + assert_eq!( + msg.header.update_interval, 233, + "incorrect value for header.update_interval, expected 233, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.index, 26598, + "incorrect value for index, expected 26598, is {}", + msg.index + ); + assert_eq!( + msg.stec_residuals[0].residual, -23949, + "incorrect value for stec_residuals[0].residual, expected -23949, is {}", + msg.stec_residuals[0].residual + ); + assert_eq!(msg.stec_residuals[0].sv_id.constellation, 157, "incorrect value for stec_residuals[0].sv_id.constellation, expected 157, is {}", msg.stec_residuals[0].sv_id.constellation); + assert_eq!( + msg.stec_residuals[0].sv_id.sat_id, 231, + "incorrect value for stec_residuals[0].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[1].residual, 27427, + "incorrect value for stec_residuals[1].residual, expected 27427, is {}", + msg.stec_residuals[1].residual + ); + assert_eq!(msg.stec_residuals[1].sv_id.constellation, 146, "incorrect value for stec_residuals[1].sv_id.constellation, expected 146, is {}", msg.stec_residuals[1].sv_id.constellation); + assert_eq!( + msg.stec_residuals[1].sv_id.sat_id, 197, + "incorrect value for stec_residuals[1].sv_id.sat_id, expected 197, is {}", + msg.stec_residuals[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[2].residual, 10548, + "incorrect value for stec_residuals[2].residual, expected 10548, is {}", + msg.stec_residuals[2].residual + ); + assert_eq!(msg.stec_residuals[2].sv_id.constellation, 109, "incorrect value for stec_residuals[2].sv_id.constellation, expected 109, is {}", msg.stec_residuals[2].sv_id.constellation); + assert_eq!( + msg.stec_residuals[2].sv_id.sat_id, 222, + "incorrect value for stec_residuals[2].sv_id.sat_id, expected 222, is {}", + msg.stec_residuals[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[3].residual, -18195, + "incorrect value for stec_residuals[3].residual, expected -18195, is {}", + msg.stec_residuals[3].residual + ); + assert_eq!( + msg.stec_residuals[3].sv_id.constellation, 12, + "incorrect value for stec_residuals[3].sv_id.constellation, expected 12, is {}", + msg.stec_residuals[3].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[3].sv_id.sat_id, 86, + "incorrect value for stec_residuals[3].sv_id.sat_id, expected 86, is {}", + msg.stec_residuals[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[4].residual, -27511, + "incorrect value for stec_residuals[4].residual, expected -27511, is {}", + msg.stec_residuals[4].residual + ); + assert_eq!(msg.stec_residuals[4].sv_id.constellation, 204, "incorrect value for stec_residuals[4].sv_id.constellation, expected 204, is {}", msg.stec_residuals[4].sv_id.constellation); + assert_eq!( + msg.stec_residuals[4].sv_id.sat_id, 65, + "incorrect value for stec_residuals[4].sv_id.sat_id, expected 65, is {}", + msg.stec_residuals[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[5].residual, 11, + "incorrect value for stec_residuals[5].residual, expected 11, is {}", + msg.stec_residuals[5].residual + ); + assert_eq!(msg.stec_residuals[5].sv_id.constellation, 183, "incorrect value for stec_residuals[5].sv_id.constellation, expected 183, is {}", msg.stec_residuals[5].sv_id.constellation); + assert_eq!( + msg.stec_residuals[5].sv_id.sat_id, 171, + "incorrect value for stec_residuals[5].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[6].residual, 13740, + "incorrect value for stec_residuals[6].residual, expected 13740, is {}", + msg.stec_residuals[6].residual + ); + assert_eq!(msg.stec_residuals[6].sv_id.constellation, 203, "incorrect value for stec_residuals[6].sv_id.constellation, expected 203, is {}", msg.stec_residuals[6].sv_id.constellation); + assert_eq!( + msg.stec_residuals[6].sv_id.sat_id, 180, + "incorrect value for stec_residuals[6].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[7].residual, 29626, + "incorrect value for stec_residuals[7].residual, expected 29626, is {}", + msg.stec_residuals[7].residual + ); + assert_eq!( + msg.stec_residuals[7].sv_id.constellation, 85, + "incorrect value for stec_residuals[7].sv_id.constellation, expected 85, is {}", + msg.stec_residuals[7].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[7].sv_id.sat_id, 196, + "incorrect value for stec_residuals[7].sv_id.sat_id, expected 196, is {}", + msg.stec_residuals[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[8].residual, 7846, + "incorrect value for stec_residuals[8].residual, expected 7846, is {}", + msg.stec_residuals[8].residual + ); + assert_eq!( + msg.stec_residuals[8].sv_id.constellation, 92, + "incorrect value for stec_residuals[8].sv_id.constellation, expected 92, is {}", + msg.stec_residuals[8].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[8].sv_id.sat_id, 203, + "incorrect value for stec_residuals[8].sv_id.sat_id, expected 203, is {}", + msg.stec_residuals[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[9].residual, 18376, + "incorrect value for stec_residuals[9].residual, expected 18376, is {}", + msg.stec_residuals[9].residual + ); + assert_eq!( + msg.stec_residuals[9].sv_id.constellation, 13, + "incorrect value for stec_residuals[9].sv_id.constellation, expected 13, is {}", + msg.stec_residuals[9].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[9].sv_id.sat_id, 42, + "incorrect value for stec_residuals[9].sv_id.sat_id, expected 42, is {}", + msg.stec_residuals[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[10].residual, -24357, + "incorrect value for stec_residuals[10].residual, expected -24357, is {}", + msg.stec_residuals[10].residual + ); + assert_eq!(msg.stec_residuals[10].sv_id.constellation, 137, "incorrect value for stec_residuals[10].sv_id.constellation, expected 137, is {}", msg.stec_residuals[10].sv_id.constellation); + assert_eq!( + msg.stec_residuals[10].sv_id.sat_id, 98, + "incorrect value for stec_residuals[10].sv_id.sat_id, expected 98, is {}", + msg.stec_residuals[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[11].residual, -1441, + "incorrect value for stec_residuals[11].residual, expected -1441, is {}", + msg.stec_residuals[11].residual + ); + assert_eq!(msg.stec_residuals[11].sv_id.constellation, 216, "incorrect value for stec_residuals[11].sv_id.constellation, expected 216, is {}", msg.stec_residuals[11].sv_id.constellation); + assert_eq!( + msg.stec_residuals[11].sv_id.sat_id, 95, + "incorrect value for stec_residuals[11].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[12].residual, -10660, + "incorrect value for stec_residuals[12].residual, expected -10660, is {}", + msg.stec_residuals[12].residual + ); + assert_eq!(msg.stec_residuals[12].sv_id.constellation, 196, "incorrect value for stec_residuals[12].sv_id.constellation, expected 196, is {}", msg.stec_residuals[12].sv_id.constellation); + assert_eq!( + msg.stec_residuals[12].sv_id.sat_id, 99, + "incorrect value for stec_residuals[12].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[13].residual, -8509, + "incorrect value for stec_residuals[13].residual, expected -8509, is {}", + msg.stec_residuals[13].residual + ); + assert_eq!(msg.stec_residuals[13].sv_id.constellation, 253, "incorrect value for stec_residuals[13].sv_id.constellation, expected 253, is {}", msg.stec_residuals[13].sv_id.constellation); + assert_eq!( + msg.stec_residuals[13].sv_id.sat_id, 159, + "incorrect value for stec_residuals[13].sv_id.sat_id, expected 159, is {}", + msg.stec_residuals[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[14].residual, 16361, + "incorrect value for stec_residuals[14].residual, expected 16361, is {}", + msg.stec_residuals[14].residual + ); + assert_eq!(msg.stec_residuals[14].sv_id.constellation, 146, "incorrect value for stec_residuals[14].sv_id.constellation, expected 146, is {}", msg.stec_residuals[14].sv_id.constellation); + assert_eq!( + msg.stec_residuals[14].sv_id.sat_id, 233, + "incorrect value for stec_residuals[14].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[15].residual, 10346, + "incorrect value for stec_residuals[15].residual, expected 10346, is {}", + msg.stec_residuals[15].residual + ); + assert_eq!(msg.stec_residuals[15].sv_id.constellation, 24, "incorrect value for stec_residuals[15].sv_id.constellation, expected 24, is {}", msg.stec_residuals[15].sv_id.constellation); + assert_eq!( + msg.stec_residuals[15].sv_id.sat_id, 76, + "incorrect value for stec_residuals[15].sv_id.sat_id, expected 76, is {}", + msg.stec_residuals[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[16].residual, -18679, + "incorrect value for stec_residuals[16].residual, expected -18679, is {}", + msg.stec_residuals[16].residual + ); + assert_eq!(msg.stec_residuals[16].sv_id.constellation, 65, "incorrect value for stec_residuals[16].sv_id.constellation, expected 65, is {}", msg.stec_residuals[16].sv_id.constellation); + assert_eq!( + msg.stec_residuals[16].sv_id.sat_id, 253, + "incorrect value for stec_residuals[16].sv_id.sat_id, expected 253, is {}", + msg.stec_residuals[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[17].residual, 15292, + "incorrect value for stec_residuals[17].residual, expected 15292, is {}", + msg.stec_residuals[17].residual + ); + assert_eq!(msg.stec_residuals[17].sv_id.constellation, 215, "incorrect value for stec_residuals[17].sv_id.constellation, expected 215, is {}", msg.stec_residuals[17].sv_id.constellation); + assert_eq!( + msg.stec_residuals[17].sv_id.sat_id, 40, + "incorrect value for stec_residuals[17].sv_id.sat_id, expected 40, is {}", + msg.stec_residuals[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[18].residual, 29537, + "incorrect value for stec_residuals[18].residual, expected 29537, is {}", + msg.stec_residuals[18].residual + ); + assert_eq!(msg.stec_residuals[18].sv_id.constellation, 69, "incorrect value for stec_residuals[18].sv_id.constellation, expected 69, is {}", msg.stec_residuals[18].sv_id.constellation); + assert_eq!( + msg.stec_residuals[18].sv_id.sat_id, 117, + "incorrect value for stec_residuals[18].sv_id.sat_id, expected 117, is {}", + msg.stec_residuals[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[19].residual, -29440, + "incorrect value for stec_residuals[19].residual, expected -29440, is {}", + msg.stec_residuals[19].residual + ); + assert_eq!(msg.stec_residuals[19].sv_id.constellation, 56, "incorrect value for stec_residuals[19].sv_id.constellation, expected 56, is {}", msg.stec_residuals[19].sv_id.constellation); + assert_eq!( + msg.stec_residuals[19].sv_id.sat_id, 60, + "incorrect value for stec_residuals[19].sv_id.sat_id, expected 60, is {}", + msg.stec_residuals[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[20].residual, -24266, + "incorrect value for stec_residuals[20].residual, expected -24266, is {}", + msg.stec_residuals[20].residual + ); + assert_eq!(msg.stec_residuals[20].sv_id.constellation, 171, "incorrect value for stec_residuals[20].sv_id.constellation, expected 171, is {}", msg.stec_residuals[20].sv_id.constellation); + assert_eq!( + msg.stec_residuals[20].sv_id.sat_id, 207, + "incorrect value for stec_residuals[20].sv_id.sat_id, expected 207, is {}", + msg.stec_residuals[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[21].residual, 22272, + "incorrect value for stec_residuals[21].residual, expected 22272, is {}", + msg.stec_residuals[21].residual + ); + assert_eq!(msg.stec_residuals[21].sv_id.constellation, 61, "incorrect value for stec_residuals[21].sv_id.constellation, expected 61, is {}", msg.stec_residuals[21].sv_id.constellation); + assert_eq!( + msg.stec_residuals[21].sv_id.sat_id, 23, + "incorrect value for stec_residuals[21].sv_id.sat_id, expected 23, is {}", + msg.stec_residuals[21].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[22].residual, 9303, + "incorrect value for stec_residuals[22].residual, expected 9303, is {}", + msg.stec_residuals[22].residual + ); + assert_eq!(msg.stec_residuals[22].sv_id.constellation, 123, "incorrect value for stec_residuals[22].sv_id.constellation, expected 123, is {}", msg.stec_residuals[22].sv_id.constellation); + assert_eq!( + msg.stec_residuals[22].sv_id.sat_id, 230, + "incorrect value for stec_residuals[22].sv_id.sat_id, expected 230, is {}", + msg.stec_residuals[22].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[23].residual, -23794, + "incorrect value for stec_residuals[23].residual, expected -23794, is {}", + msg.stec_residuals[23].residual + ); + assert_eq!(msg.stec_residuals[23].sv_id.constellation, 255, "incorrect value for stec_residuals[23].sv_id.constellation, expected 255, is {}", msg.stec_residuals[23].sv_id.constellation); + assert_eq!( + msg.stec_residuals[23].sv_id.sat_id, 184, + "incorrect value for stec_residuals[23].sv_id.sat_id, expected 184, is {}", + msg.stec_residuals[23].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[24].residual, -26837, + "incorrect value for stec_residuals[24].residual, expected -26837, is {}", + msg.stec_residuals[24].residual + ); + assert_eq!(msg.stec_residuals[24].sv_id.constellation, 224, "incorrect value for stec_residuals[24].sv_id.constellation, expected 224, is {}", msg.stec_residuals[24].sv_id.constellation); + assert_eq!( + msg.stec_residuals[24].sv_id.sat_id, 187, + "incorrect value for stec_residuals[24].sv_id.sat_id, expected 187, is {}", + msg.stec_residuals[24].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[25].residual, 14631, + "incorrect value for stec_residuals[25].residual, expected 14631, is {}", + msg.stec_residuals[25].residual + ); + assert_eq!(msg.stec_residuals[25].sv_id.constellation, 104, "incorrect value for stec_residuals[25].sv_id.constellation, expected 104, is {}", msg.stec_residuals[25].sv_id.constellation); + assert_eq!( + msg.stec_residuals[25].sv_id.sat_id, 151, + "incorrect value for stec_residuals[25].sv_id.sat_id, expected 151, is {}", + msg.stec_residuals[25].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[26].residual, -8144, + "incorrect value for stec_residuals[26].residual, expected -8144, is {}", + msg.stec_residuals[26].residual + ); + assert_eq!(msg.stec_residuals[26].sv_id.constellation, 54, "incorrect value for stec_residuals[26].sv_id.constellation, expected 54, is {}", msg.stec_residuals[26].sv_id.constellation); + assert_eq!( + msg.stec_residuals[26].sv_id.sat_id, 5, + "incorrect value for stec_residuals[26].sv_id.sat_id, expected 5, is {}", + msg.stec_residuals[26].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[27].residual, 23612, + "incorrect value for stec_residuals[27].residual, expected 23612, is {}", + msg.stec_residuals[27].residual + ); + assert_eq!(msg.stec_residuals[27].sv_id.constellation, 129, "incorrect value for stec_residuals[27].sv_id.constellation, expected 129, is {}", msg.stec_residuals[27].sv_id.constellation); + assert_eq!( + msg.stec_residuals[27].sv_id.sat_id, 181, + "incorrect value for stec_residuals[27].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[27].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[28].residual, 28013, + "incorrect value for stec_residuals[28].residual, expected 28013, is {}", + msg.stec_residuals[28].residual + ); + assert_eq!(msg.stec_residuals[28].sv_id.constellation, 114, "incorrect value for stec_residuals[28].sv_id.constellation, expected 114, is {}", msg.stec_residuals[28].sv_id.constellation); + assert_eq!( + msg.stec_residuals[28].sv_id.sat_id, 171, + "incorrect value for stec_residuals[28].sv_id.sat_id, expected 171, is {}", + msg.stec_residuals[28].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[29].residual, 2166, + "incorrect value for stec_residuals[29].residual, expected 2166, is {}", + msg.stec_residuals[29].residual + ); + assert_eq!(msg.stec_residuals[29].sv_id.constellation, 23, "incorrect value for stec_residuals[29].sv_id.constellation, expected 23, is {}", msg.stec_residuals[29].sv_id.constellation); + assert_eq!( + msg.stec_residuals[29].sv_id.sat_id, 12, + "incorrect value for stec_residuals[29].sv_id.sat_id, expected 12, is {}", + msg.stec_residuals[29].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[30].residual, -10186, + "incorrect value for stec_residuals[30].residual, expected -10186, is {}", + msg.stec_residuals[30].residual + ); + assert_eq!(msg.stec_residuals[30].sv_id.constellation, 159, "incorrect value for stec_residuals[30].sv_id.constellation, expected 159, is {}", msg.stec_residuals[30].sv_id.constellation); + assert_eq!( + msg.stec_residuals[30].sv_id.sat_id, 64, + "incorrect value for stec_residuals[30].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[30].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[31].residual, 17432, + "incorrect value for stec_residuals[31].residual, expected 17432, is {}", + msg.stec_residuals[31].residual + ); + assert_eq!(msg.stec_residuals[31].sv_id.constellation, 20, "incorrect value for stec_residuals[31].sv_id.constellation, expected 20, is {}", msg.stec_residuals[31].sv_id.constellation); + assert_eq!( + msg.stec_residuals[31].sv_id.sat_id, 33, + "incorrect value for stec_residuals[31].sv_id.sat_id, expected 33, is {}", + msg.stec_residuals[31].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[32].residual, -8666, + "incorrect value for stec_residuals[32].residual, expected -8666, is {}", + msg.stec_residuals[32].residual + ); + assert_eq!(msg.stec_residuals[32].sv_id.constellation, 36, "incorrect value for stec_residuals[32].sv_id.constellation, expected 36, is {}", msg.stec_residuals[32].sv_id.constellation); + assert_eq!( + msg.stec_residuals[32].sv_id.sat_id, 160, + "incorrect value for stec_residuals[32].sv_id.sat_id, expected 160, is {}", + msg.stec_residuals[32].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[33].residual, 25436, + "incorrect value for stec_residuals[33].residual, expected 25436, is {}", + msg.stec_residuals[33].residual + ); + assert_eq!(msg.stec_residuals[33].sv_id.constellation, 190, "incorrect value for stec_residuals[33].sv_id.constellation, expected 190, is {}", msg.stec_residuals[33].sv_id.constellation); + assert_eq!( + msg.stec_residuals[33].sv_id.sat_id, 145, + "incorrect value for stec_residuals[33].sv_id.sat_id, expected 145, is {}", + msg.stec_residuals[33].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[34].residual, -3864, + "incorrect value for stec_residuals[34].residual, expected -3864, is {}", + msg.stec_residuals[34].residual + ); + assert_eq!(msg.stec_residuals[34].sv_id.constellation, 159, "incorrect value for stec_residuals[34].sv_id.constellation, expected 159, is {}", msg.stec_residuals[34].sv_id.constellation); + assert_eq!( + msg.stec_residuals[34].sv_id.sat_id, 108, + "incorrect value for stec_residuals[34].sv_id.sat_id, expected 108, is {}", + msg.stec_residuals[34].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[35].residual, 4093, + "incorrect value for stec_residuals[35].residual, expected 4093, is {}", + msg.stec_residuals[35].residual + ); + assert_eq!(msg.stec_residuals[35].sv_id.constellation, 221, "incorrect value for stec_residuals[35].sv_id.constellation, expected 221, is {}", msg.stec_residuals[35].sv_id.constellation); + assert_eq!( + msg.stec_residuals[35].sv_id.sat_id, 227, + "incorrect value for stec_residuals[35].sv_id.sat_id, expected 227, is {}", + msg.stec_residuals[35].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[36].residual, -18055, + "incorrect value for stec_residuals[36].residual, expected -18055, is {}", + msg.stec_residuals[36].residual + ); + assert_eq!(msg.stec_residuals[36].sv_id.constellation, 23, "incorrect value for stec_residuals[36].sv_id.constellation, expected 23, is {}", msg.stec_residuals[36].sv_id.constellation); + assert_eq!( + msg.stec_residuals[36].sv_id.sat_id, 62, + "incorrect value for stec_residuals[36].sv_id.sat_id, expected 62, is {}", + msg.stec_residuals[36].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[37].residual, -27900, + "incorrect value for stec_residuals[37].residual, expected -27900, is {}", + msg.stec_residuals[37].residual + ); + assert_eq!(msg.stec_residuals[37].sv_id.constellation, 116, "incorrect value for stec_residuals[37].sv_id.constellation, expected 116, is {}", msg.stec_residuals[37].sv_id.constellation); + assert_eq!( + msg.stec_residuals[37].sv_id.sat_id, 168, + "incorrect value for stec_residuals[37].sv_id.sat_id, expected 168, is {}", + msg.stec_residuals[37].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[38].residual, 30687, + "incorrect value for stec_residuals[38].residual, expected 30687, is {}", + msg.stec_residuals[38].residual + ); + assert_eq!(msg.stec_residuals[38].sv_id.constellation, 72, "incorrect value for stec_residuals[38].sv_id.constellation, expected 72, is {}", msg.stec_residuals[38].sv_id.constellation); + assert_eq!( + msg.stec_residuals[38].sv_id.sat_id, 123, + "incorrect value for stec_residuals[38].sv_id.sat_id, expected 123, is {}", + msg.stec_residuals[38].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[39].residual, -13151, + "incorrect value for stec_residuals[39].residual, expected -13151, is {}", + msg.stec_residuals[39].residual + ); + assert_eq!(msg.stec_residuals[39].sv_id.constellation, 242, "incorrect value for stec_residuals[39].sv_id.constellation, expected 242, is {}", msg.stec_residuals[39].sv_id.constellation); + assert_eq!( + msg.stec_residuals[39].sv_id.sat_id, 226, + "incorrect value for stec_residuals[39].sv_id.sat_id, expected 226, is {}", + msg.stec_residuals[39].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[40].residual, -22903, + "incorrect value for stec_residuals[40].residual, expected -22903, is {}", + msg.stec_residuals[40].residual + ); + assert_eq!(msg.stec_residuals[40].sv_id.constellation, 202, "incorrect value for stec_residuals[40].sv_id.constellation, expected 202, is {}", msg.stec_residuals[40].sv_id.constellation); + assert_eq!( + msg.stec_residuals[40].sv_id.sat_id, 180, + "incorrect value for stec_residuals[40].sv_id.sat_id, expected 180, is {}", + msg.stec_residuals[40].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[41].residual, 4988, + "incorrect value for stec_residuals[41].residual, expected 4988, is {}", + msg.stec_residuals[41].residual + ); + assert_eq!(msg.stec_residuals[41].sv_id.constellation, 24, "incorrect value for stec_residuals[41].sv_id.constellation, expected 24, is {}", msg.stec_residuals[41].sv_id.constellation); + assert_eq!( + msg.stec_residuals[41].sv_id.sat_id, 58, + "incorrect value for stec_residuals[41].sv_id.sat_id, expected 58, is {}", + msg.stec_residuals[41].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[42].residual, 27408, + "incorrect value for stec_residuals[42].residual, expected 27408, is {}", + msg.stec_residuals[42].residual + ); + assert_eq!(msg.stec_residuals[42].sv_id.constellation, 188, "incorrect value for stec_residuals[42].sv_id.constellation, expected 188, is {}", msg.stec_residuals[42].sv_id.constellation); + assert_eq!( + msg.stec_residuals[42].sv_id.sat_id, 181, + "incorrect value for stec_residuals[42].sv_id.sat_id, expected 181, is {}", + msg.stec_residuals[42].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[43].residual, 319, + "incorrect value for stec_residuals[43].residual, expected 319, is {}", + msg.stec_residuals[43].residual + ); + assert_eq!(msg.stec_residuals[43].sv_id.constellation, 231, "incorrect value for stec_residuals[43].sv_id.constellation, expected 231, is {}", msg.stec_residuals[43].sv_id.constellation); + assert_eq!( + msg.stec_residuals[43].sv_id.sat_id, 66, + "incorrect value for stec_residuals[43].sv_id.sat_id, expected 66, is {}", + msg.stec_residuals[43].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[44].residual, 15987, + "incorrect value for stec_residuals[44].residual, expected 15987, is {}", + msg.stec_residuals[44].residual + ); + assert_eq!(msg.stec_residuals[44].sv_id.constellation, 252, "incorrect value for stec_residuals[44].sv_id.constellation, expected 252, is {}", msg.stec_residuals[44].sv_id.constellation); + assert_eq!( + msg.stec_residuals[44].sv_id.sat_id, 64, + "incorrect value for stec_residuals[44].sv_id.sat_id, expected 64, is {}", + msg.stec_residuals[44].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[45].residual, 22266, + "incorrect value for stec_residuals[45].residual, expected 22266, is {}", + msg.stec_residuals[45].residual + ); + assert_eq!(msg.stec_residuals[45].sv_id.constellation, 97, "incorrect value for stec_residuals[45].sv_id.constellation, expected 97, is {}", msg.stec_residuals[45].sv_id.constellation); + assert_eq!( + msg.stec_residuals[45].sv_id.sat_id, 233, + "incorrect value for stec_residuals[45].sv_id.sat_id, expected 233, is {}", + msg.stec_residuals[45].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[46].residual, -19919, + "incorrect value for stec_residuals[46].residual, expected -19919, is {}", + msg.stec_residuals[46].residual + ); + assert_eq!(msg.stec_residuals[46].sv_id.constellation, 221, "incorrect value for stec_residuals[46].sv_id.constellation, expected 221, is {}", msg.stec_residuals[46].sv_id.constellation); + assert_eq!( + msg.stec_residuals[46].sv_id.sat_id, 156, + "incorrect value for stec_residuals[46].sv_id.sat_id, expected 156, is {}", + msg.stec_residuals[46].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[47].residual, 17350, + "incorrect value for stec_residuals[47].residual, expected 17350, is {}", + msg.stec_residuals[47].residual + ); + assert_eq!(msg.stec_residuals[47].sv_id.constellation, 73, "incorrect value for stec_residuals[47].sv_id.constellation, expected 73, is {}", msg.stec_residuals[47].sv_id.constellation); + assert_eq!( + msg.stec_residuals[47].sv_id.sat_id, 32, + "incorrect value for stec_residuals[47].sv_id.sat_id, expected 32, is {}", + msg.stec_residuals[47].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[48].residual, 14410, + "incorrect value for stec_residuals[48].residual, expected 14410, is {}", + msg.stec_residuals[48].residual + ); + assert_eq!(msg.stec_residuals[48].sv_id.constellation, 253, "incorrect value for stec_residuals[48].sv_id.constellation, expected 253, is {}", msg.stec_residuals[48].sv_id.constellation); + assert_eq!( + msg.stec_residuals[48].sv_id.sat_id, 249, + "incorrect value for stec_residuals[48].sv_id.sat_id, expected 249, is {}", + msg.stec_residuals[48].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[49].residual, 23671, + "incorrect value for stec_residuals[49].residual, expected 23671, is {}", + msg.stec_residuals[49].residual + ); + assert_eq!(msg.stec_residuals[49].sv_id.constellation, 165, "incorrect value for stec_residuals[49].sv_id.constellation, expected 165, is {}", msg.stec_residuals[49].sv_id.constellation); + assert_eq!( + msg.stec_residuals[49].sv_id.sat_id, 38, + "incorrect value for stec_residuals[49].sv_id.sat_id, expected 38, is {}", + msg.stec_residuals[49].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[50].residual, -31905, + "incorrect value for stec_residuals[50].residual, expected -31905, is {}", + msg.stec_residuals[50].residual + ); + assert_eq!(msg.stec_residuals[50].sv_id.constellation, 44, "incorrect value for stec_residuals[50].sv_id.constellation, expected 44, is {}", msg.stec_residuals[50].sv_id.constellation); + assert_eq!( + msg.stec_residuals[50].sv_id.sat_id, 99, + "incorrect value for stec_residuals[50].sv_id.sat_id, expected 99, is {}", + msg.stec_residuals[50].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[51].residual, 14305, + "incorrect value for stec_residuals[51].residual, expected 14305, is {}", + msg.stec_residuals[51].residual + ); + assert_eq!(msg.stec_residuals[51].sv_id.constellation, 192, "incorrect value for stec_residuals[51].sv_id.constellation, expected 192, is {}", msg.stec_residuals[51].sv_id.constellation); + assert_eq!( + msg.stec_residuals[51].sv_id.sat_id, 89, + "incorrect value for stec_residuals[51].sv_id.sat_id, expected 89, is {}", + msg.stec_residuals[51].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[52].residual, -12968, + "incorrect value for stec_residuals[52].residual, expected -12968, is {}", + msg.stec_residuals[52].residual + ); + assert_eq!(msg.stec_residuals[52].sv_id.constellation, 171, "incorrect value for stec_residuals[52].sv_id.constellation, expected 171, is {}", msg.stec_residuals[52].sv_id.constellation); + assert_eq!( + msg.stec_residuals[52].sv_id.sat_id, 95, + "incorrect value for stec_residuals[52].sv_id.sat_id, expected 95, is {}", + msg.stec_residuals[52].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[53].residual, 21479, + "incorrect value for stec_residuals[53].residual, expected 21479, is {}", + msg.stec_residuals[53].residual + ); + assert_eq!(msg.stec_residuals[53].sv_id.constellation, 116, "incorrect value for stec_residuals[53].sv_id.constellation, expected 116, is {}", msg.stec_residuals[53].sv_id.constellation); + assert_eq!( + msg.stec_residuals[53].sv_id.sat_id, 21, + "incorrect value for stec_residuals[53].sv_id.sat_id, expected 21, is {}", + msg.stec_residuals[53].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[54].residual, 28260, + "incorrect value for stec_residuals[54].residual, expected 28260, is {}", + msg.stec_residuals[54].residual + ); + assert_eq!(msg.stec_residuals[54].sv_id.constellation, 71, "incorrect value for stec_residuals[54].sv_id.constellation, expected 71, is {}", msg.stec_residuals[54].sv_id.constellation); + assert_eq!( + msg.stec_residuals[54].sv_id.sat_id, 71, + "incorrect value for stec_residuals[54].sv_id.sat_id, expected 71, is {}", + msg.stec_residuals[54].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[55].residual, -11112, + "incorrect value for stec_residuals[55].residual, expected -11112, is {}", + msg.stec_residuals[55].residual + ); + assert_eq!(msg.stec_residuals[55].sv_id.constellation, 254, "incorrect value for stec_residuals[55].sv_id.constellation, expected 254, is {}", msg.stec_residuals[55].sv_id.constellation); + assert_eq!( + msg.stec_residuals[55].sv_id.sat_id, 217, + "incorrect value for stec_residuals[55].sv_id.sat_id, expected 217, is {}", + msg.stec_residuals[55].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[56].residual, -25304, + "incorrect value for stec_residuals[56].residual, expected -25304, is {}", + msg.stec_residuals[56].residual + ); + assert_eq!( + msg.stec_residuals[56].sv_id.constellation, 8, + "incorrect value for stec_residuals[56].sv_id.constellation, expected 8, is {}", + msg.stec_residuals[56].sv_id.constellation + ); + assert_eq!( + msg.stec_residuals[56].sv_id.sat_id, 18, + "incorrect value for stec_residuals[56].sv_id.sat_id, expected 18, is {}", + msg.stec_residuals[56].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[57].residual, -4024, + "incorrect value for stec_residuals[57].residual, expected -4024, is {}", + msg.stec_residuals[57].residual + ); + assert_eq!(msg.stec_residuals[57].sv_id.constellation, 54, "incorrect value for stec_residuals[57].sv_id.constellation, expected 54, is {}", msg.stec_residuals[57].sv_id.constellation); + assert_eq!( + msg.stec_residuals[57].sv_id.sat_id, 244, + "incorrect value for stec_residuals[57].sv_id.sat_id, expected 244, is {}", + msg.stec_residuals[57].sv_id.sat_id + ); + assert_eq!( + msg.stec_residuals[58].residual, -15505, + "incorrect value for stec_residuals[58].residual, expected -15505, is {}", + msg.stec_residuals[58].residual + ); + assert_eq!(msg.stec_residuals[58].sv_id.constellation, 189, "incorrect value for stec_residuals[58].sv_id.constellation, expected 189, is {}", msg.stec_residuals[58].sv_id.constellation); + assert_eq!( + msg.stec_residuals[58].sv_id.sat_id, 231, + "incorrect value for stec_residuals[58].sv_id.sat_id, expected 231, is {}", + msg.stec_residuals[58].sv_id.sat_id + ); + assert_eq!( + msg.tropo_delay_correction.hydro, 16250, + "incorrect value for tropo_delay_correction.hydro, expected 16250, is {}", + msg.tropo_delay_correction.hydro + ); + assert_eq!( + msg.tropo_delay_correction.wet, 101, + "incorrect value for tropo_delay_correction.wet, expected 101, is {}", + msg.tropo_delay_correction.wet + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrGriddedCorrectionNoStdDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock.rs new file mode 100644 index 0000000000..ece31ccbb0 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock.rs @@ -0,0 +1,413 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_orbit_clock() { + { + let mut payload = Cursor::new(vec![ + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, 203, 212, 236, 255, 152, 233, 207, + 55, 94, 54, 58, 128, 68, 27, 117, 176, 110, 251, 61, 244, 122, 50, 95, 52, 144, 232, + 24, 10, 37, 127, 163, 66, 177, 105, 156, 245, 10, 249, 107, 218, 17, 186, 56, 72, 14, + 22, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClock(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dd, + "Incorrect message type, expected 0x5dd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe535, + "incorrect sender id, expected 0xe535, is {sender_id}" + ); + assert_eq!( + msg.along, -1334502588, + "incorrect value for along, expected -1334502588, is {}", + msg.along + ); + assert_eq!( + msg.c0, -174298703, + "incorrect value for c0, expected -174298703, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -630458102, + "incorrect value for c1, expected -630458102, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, 1211677201, + "incorrect value for c2, expected 1211677201, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, -197264530, + "incorrect value for cross, expected -197264530, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 169404560, + "incorrect value for dot_along, expected 169404560, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 1118011173, + "incorrect value for dot_cross, expected 1118011173, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, 878654074, + "incorrect value for dot_radial, expected 878654074, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 936372632, + "incorrect value for iod, expected 936372632, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 255, + "incorrect value for iod_ssr, expected 255, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -2143668642, + "incorrect value for radial, expected -2143668642, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 212, + "incorrect value for sid.code, expected 212, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 203, + "incorrect value for sid.sat, expected 203, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3479621715, + "incorrect value for time.tow, expected 3479621715, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7588, + "incorrect value for time.wn, expected 7588, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 236, + "incorrect value for update_interval, expected 236, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClock"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_orbit_clock() { + { + let json_input = r#"{"crc":5646,"length":50,"msg_type":1501,"payload":"U9Bmz6Qdy9Ts/5jpzzdeNjqARBt1sG77PfR6Ml80kOgYCiV/o0KxaZz1Cvlr2hG6OEg=","preamble":85,"sender":58677,"time":{"tow":3479621715,"wn":7588},"sid":{"sat":203,"code":212},"update_interval":236,"iod_ssr":255,"iod":936372632,"radial":-2143668642,"along":-1334502588,"cross":-197264530,"dot_radial":878654074,"dot_along":169404560,"dot_cross":1118011173,"c0":-174298703,"c1":-630458102,"c2":1211677201}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClock(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dd, + "Incorrect message type, expected 0x5dd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe535, + "incorrect sender id, expected 0xe535, is {sender_id}" + ); + assert_eq!( + msg.along, -1334502588, + "incorrect value for along, expected -1334502588, is {}", + msg.along + ); + assert_eq!( + msg.c0, -174298703, + "incorrect value for c0, expected -174298703, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -630458102, + "incorrect value for c1, expected -630458102, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, 1211677201, + "incorrect value for c2, expected 1211677201, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, -197264530, + "incorrect value for cross, expected -197264530, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 169404560, + "incorrect value for dot_along, expected 169404560, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 1118011173, + "incorrect value for dot_cross, expected 1118011173, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, 878654074, + "incorrect value for dot_radial, expected 878654074, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 936372632, + "incorrect value for iod, expected 936372632, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 255, + "incorrect value for iod_ssr, expected 255, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -2143668642, + "incorrect value for radial, expected -2143668642, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 212, + "incorrect value for sid.code, expected 212, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 203, + "incorrect value for sid.sat, expected 203, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3479621715, + "incorrect value for time.tow, expected 3479621715, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7588, + "incorrect value for time.wn, expected 7588, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 236, + "incorrect value for update_interval, expected 236, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClock"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_orbit_clock`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_orbit_clock() { + { + let mut payload = Cursor::new(vec![ + 85, 221, 5, 53, 229, 50, 83, 208, 102, 207, 164, 29, 203, 212, 236, 255, 152, 233, 207, + 55, 94, 54, 58, 128, 68, 27, 117, 176, 110, 251, 61, 244, 122, 50, 95, 52, 144, 232, + 24, 10, 37, 127, 163, 66, 177, 105, 156, 245, 10, 249, 107, 218, 17, 186, 56, 72, 14, + 22, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrOrbitClock( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClock(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dd, + "Incorrect message type, expected 0x5dd, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xe535, + "incorrect sender id, expected 0xe535, is {sender_id}" + ); + assert_eq!( + msg.along, -1334502588, + "incorrect value for along, expected -1334502588, is {}", + msg.along + ); + assert_eq!( + msg.c0, -174298703, + "incorrect value for c0, expected -174298703, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -630458102, + "incorrect value for c1, expected -630458102, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, 1211677201, + "incorrect value for c2, expected 1211677201, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, -197264530, + "incorrect value for cross, expected -197264530, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 169404560, + "incorrect value for dot_along, expected 169404560, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 1118011173, + "incorrect value for dot_cross, expected 1118011173, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, 878654074, + "incorrect value for dot_radial, expected 878654074, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 936372632, + "incorrect value for iod, expected 936372632, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 255, + "incorrect value for iod_ssr, expected 255, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -2143668642, + "incorrect value for radial, expected -2143668642, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 212, + "incorrect value for sid.code, expected 212, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 203, + "incorrect value for sid.sat, expected 203, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3479621715, + "incorrect value for time.tow, expected 3479621715, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7588, + "incorrect value for time.wn, expected 7588, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 236, + "incorrect value for update_interval, expected 236, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClock"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a.rs new file mode 100644 index 0000000000..a6354acdcf --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a.rs @@ -0,0 +1,411 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, 194, 211, 193, 175, 161, + 143, 254, 56, 63, 232, 7, 216, 69, 1, 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, + 151, 18, 171, 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClockDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dc, + "Incorrect message type, expected 0x5dc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa621, + "incorrect sender id, expected 0xa621, is {sender_id}" + ); + assert_eq!( + msg.along, 132661048, + "incorrect value for along, expected 132661048, is {}", + msg.along + ); + assert_eq!( + msg.c0, -970026069, + "incorrect value for c0, expected -970026069, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -503975083, + "incorrect value for c1, expected -503975083, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, -759858197, + "incorrect value for c2, expected -759858197, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, 1845577176, + "incorrect value for cross, expected 1845577176, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 72905755, + "incorrect value for dot_along, expected 72905755, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 311886653, + "incorrect value for dot_cross, expected 311886653, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, -1111196507, + "incorrect value for dot_radial, expected -1111196507, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 193, + "incorrect value for iod, expected 193, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 211, + "incorrect value for iod_ssr, expected 211, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -24141393, + "incorrect value for radial, expected -24141393, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 30, + "incorrect value for sid.code, expected 30, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 1, + "incorrect value for sid.sat, expected 1, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3172954849, + "incorrect value for time.tow, expected 3172954849, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7723, + "incorrect value for time.wn, expected 7723, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 194, + "incorrect value for update_interval, expected 194, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClockDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a() { + { + let json_input = r#"{"crc":64669,"length":47,"msg_type":1500,"payload":"4XIfvSseAR7C08GvoY/+OD/oB9hFAW6lfMS9G3RYBD0DlxKrky7GVfP14et7tdI=","preamble":85,"sender":42529,"time":{"tow":3172954849,"wn":7723},"sid":{"sat":1,"code":30},"update_interval":194,"iod_ssr":211,"iod":193,"radial":-24141393,"along":132661048,"cross":1845577176,"dot_radial":-1111196507,"dot_along":72905755,"dot_cross":311886653,"c0":-970026069,"c1":-503975083,"c2":-759858197}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClockDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dc, + "Incorrect message type, expected 0x5dc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa621, + "incorrect sender id, expected 0xa621, is {sender_id}" + ); + assert_eq!( + msg.along, 132661048, + "incorrect value for along, expected 132661048, is {}", + msg.along + ); + assert_eq!( + msg.c0, -970026069, + "incorrect value for c0, expected -970026069, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -503975083, + "incorrect value for c1, expected -503975083, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, -759858197, + "incorrect value for c2, expected -759858197, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, 1845577176, + "incorrect value for cross, expected 1845577176, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 72905755, + "incorrect value for dot_along, expected 72905755, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 311886653, + "incorrect value for dot_cross, expected 311886653, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, -1111196507, + "incorrect value for dot_radial, expected -1111196507, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 193, + "incorrect value for iod, expected 193, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 211, + "incorrect value for iod_ssr, expected 211, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -24141393, + "incorrect value for radial, expected -24141393, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 30, + "incorrect value for sid.code, expected 30, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 1, + "incorrect value for sid.sat, expected 1, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3172954849, + "incorrect value for time.tow, expected 3172954849, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7723, + "incorrect value for time.wn, expected 7723, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 194, + "incorrect value for update_interval, expected 194, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClockDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 220, 5, 33, 166, 47, 225, 114, 31, 189, 43, 30, 1, 30, 194, 211, 193, 175, 161, + 143, 254, 56, 63, 232, 7, 216, 69, 1, 110, 165, 124, 196, 189, 27, 116, 88, 4, 61, 3, + 151, 18, 171, 147, 46, 198, 85, 243, 245, 225, 235, 123, 181, 210, 157, 252, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrOrbitClockDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrOrbitClockDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5dc, + "Incorrect message type, expected 0x5dc, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa621, + "incorrect sender id, expected 0xa621, is {sender_id}" + ); + assert_eq!( + msg.along, 132661048, + "incorrect value for along, expected 132661048, is {}", + msg.along + ); + assert_eq!( + msg.c0, -970026069, + "incorrect value for c0, expected -970026069, is {}", + msg.c0 + ); + assert_eq!( + msg.c1, -503975083, + "incorrect value for c1, expected -503975083, is {}", + msg.c1 + ); + assert_eq!( + msg.c2, -759858197, + "incorrect value for c2, expected -759858197, is {}", + msg.c2 + ); + assert_eq!( + msg.cross, 1845577176, + "incorrect value for cross, expected 1845577176, is {}", + msg.cross + ); + assert_eq!( + msg.dot_along, 72905755, + "incorrect value for dot_along, expected 72905755, is {}", + msg.dot_along + ); + assert_eq!( + msg.dot_cross, 311886653, + "incorrect value for dot_cross, expected 311886653, is {}", + msg.dot_cross + ); + assert_eq!( + msg.dot_radial, -1111196507, + "incorrect value for dot_radial, expected -1111196507, is {}", + msg.dot_radial + ); + assert_eq!( + msg.iod, 193, + "incorrect value for iod, expected 193, is {}", + msg.iod + ); + assert_eq!( + msg.iod_ssr, 211, + "incorrect value for iod_ssr, expected 211, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.radial, -24141393, + "incorrect value for radial, expected -24141393, is {}", + msg.radial + ); + assert_eq!( + msg.sid.code, 30, + "incorrect value for sid.code, expected 30, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 1, + "incorrect value for sid.sat, expected 1, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 3172954849, + "incorrect value for time.tow, expected 3172954849, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 7723, + "incorrect value for time.wn, expected 7723, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 194, + "incorrect value for update_interval, expected 194, is {}", + msg.update_interval + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrOrbitClockDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_phase_biases.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_phase_biases.rs new file mode 100644 index 0000000000..45552f5b06 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_phase_biases.rs @@ -0,0 +1,2437 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_phase_biases() { + { + let mut payload = Cursor::new(vec![ + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, 177, 230, 98, 209, + 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, 177, 207, 187, 33, 146, 58, 204, 164, 65, + 114, 49, 248, 52, 8, 161, 44, 252, 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, + 155, 129, 143, 184, 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, 203, 87, 34, 188, + 141, 104, 189, 102, 156, 252, 22, 251, 136, 49, 188, 157, 222, 245, 49, 132, 16, 34, + 142, 228, 85, 139, 221, 197, 235, 98, 74, 107, 70, 36, 38, 239, 251, 112, 188, 124, + 246, 141, 164, 150, 104, 7, 213, 44, 21, 244, 192, 4, 143, 24, 42, 21, 84, 136, 7, 42, + 118, 45, 23, 174, 175, 129, 54, 169, 14, 213, 2, 197, 98, 60, 13, 207, 105, 100, 129, + 72, 136, 240, 140, 129, 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, 242, 254, + 215, 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, 97, 36, 207, 92, 224, 26, 116, + 155, 211, 165, 47, 102, 38, 67, 199, 55, 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, + 62, 147, 173, 173, 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, 207, + 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, 75, 230, 26, 213, 181, 56, 64, + 97, 88, 255, 6, 147, 16, 89, 203, 27, 68, 243, 230, 55, 242, 167, 169, 219, 240, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrPhaseBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e6, + "Incorrect message type, expected 0x5e6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xcedb, + "incorrect sender id, expected 0xcedb, is {sender_id}" + ); + assert_eq!( + msg.biases[0].bias, -1311498533, + "incorrect value for biases[0].bias, expected -1311498533, is {}", + msg.biases[0].bias + ); + assert_eq!( + msg.biases[0].code, 29, + "incorrect value for biases[0].code, expected 29, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].discontinuity_counter, 193, + "incorrect value for biases[0].discontinuity_counter, expected 193, is {}", + msg.biases[0].discontinuity_counter + ); + assert_eq!( + msg.biases[0].integer_indicator, 250, + "incorrect value for biases[0].integer_indicator, expected 250, is {}", + msg.biases[0].integer_indicator + ); + assert_eq!( + msg.biases[0].widelane_integer_indicator, 245, + "incorrect value for biases[0].widelane_integer_indicator, expected 245, is {}", + msg.biases[0].widelane_integer_indicator + ); + assert_eq!( + msg.biases[1].bias, 1101319226, + "incorrect value for biases[1].bias, expected 1101319226, is {}", + msg.biases[1].bias + ); + assert_eq!( + msg.biases[1].code, 207, + "incorrect value for biases[1].code, expected 207, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].discontinuity_counter, 146, + "incorrect value for biases[1].discontinuity_counter, expected 146, is {}", + msg.biases[1].discontinuity_counter + ); + assert_eq!( + msg.biases[1].integer_indicator, 187, + "incorrect value for biases[1].integer_indicator, expected 187, is {}", + msg.biases[1].integer_indicator + ); + assert_eq!( + msg.biases[1].widelane_integer_indicator, 33, + "incorrect value for biases[1].widelane_integer_indicator, expected 33, is {}", + msg.biases[1].widelane_integer_indicator + ); + assert_eq!( + msg.biases[2].bias, -64184056, + "incorrect value for biases[2].bias, expected -64184056, is {}", + msg.biases[2].bias + ); + assert_eq!( + msg.biases[2].code, 114, + "incorrect value for biases[2].code, expected 114, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].discontinuity_counter, 52, + "incorrect value for biases[2].discontinuity_counter, expected 52, is {}", + msg.biases[2].discontinuity_counter + ); + assert_eq!( + msg.biases[2].integer_indicator, 49, + "incorrect value for biases[2].integer_indicator, expected 49, is {}", + msg.biases[2].integer_indicator + ); + assert_eq!( + msg.biases[2].widelane_integer_indicator, 248, + "incorrect value for biases[2].widelane_integer_indicator, expected 248, is {}", + msg.biases[2].widelane_integer_indicator + ); + assert_eq!( + msg.biases[3].bias, -240298362, + "incorrect value for biases[3].bias, expected -240298362, is {}", + msg.biases[3].bias + ); + assert_eq!( + msg.biases[3].code, 166, + "incorrect value for biases[3].code, expected 166, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].discontinuity_counter, 124, + "incorrect value for biases[3].discontinuity_counter, expected 124, is {}", + msg.biases[3].discontinuity_counter + ); + assert_eq!( + msg.biases[3].integer_indicator, 168, + "incorrect value for biases[3].integer_indicator, expected 168, is {}", + msg.biases[3].integer_indicator + ); + assert_eq!( + msg.biases[3].widelane_integer_indicator, 232, + "incorrect value for biases[3].widelane_integer_indicator, expected 232, is {}", + msg.biases[3].widelane_integer_indicator + ); + assert_eq!( + msg.biases[4].bias, -1581740159, + "incorrect value for biases[4].bias, expected -1581740159, is {}", + msg.biases[4].bias + ); + assert_eq!( + msg.biases[4].code, 174, + "incorrect value for biases[4].code, expected 174, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].discontinuity_counter, 155, + "incorrect value for biases[4].discontinuity_counter, expected 155, is {}", + msg.biases[4].discontinuity_counter + ); + assert_eq!( + msg.biases[4].integer_indicator, 44, + "incorrect value for biases[4].integer_indicator, expected 44, is {}", + msg.biases[4].integer_indicator + ); + assert_eq!( + msg.biases[4].widelane_integer_indicator, 142, + "incorrect value for biases[4].widelane_integer_indicator, expected 142, is {}", + msg.biases[4].widelane_integer_indicator + ); + assert_eq!( + msg.biases[5].bias, -1730297136, + "incorrect value for biases[5].bias, expected -1730297136, is {}", + msg.biases[5].bias + ); + assert_eq!( + msg.biases[5].code, 211, + "incorrect value for biases[5].code, expected 211, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].discontinuity_counter, 189, + "incorrect value for biases[5].discontinuity_counter, expected 189, is {}", + msg.biases[5].discontinuity_counter + ); + assert_eq!( + msg.biases[5].integer_indicator, 15, + "incorrect value for biases[5].integer_indicator, expected 15, is {}", + msg.biases[5].integer_indicator + ); + assert_eq!( + msg.biases[5].widelane_integer_indicator, 36, + "incorrect value for biases[5].widelane_integer_indicator, expected 36, is {}", + msg.biases[5].widelane_integer_indicator + ); + assert_eq!( + msg.biases[6].bias, -1117221444, + "incorrect value for biases[6].bias, expected -1117221444, is {}", + msg.biases[6].bias + ); + assert_eq!( + msg.biases[6].code, 16, + "incorrect value for biases[6].code, expected 16, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].discontinuity_counter, 34, + "incorrect value for biases[6].discontinuity_counter, expected 34, is {}", + msg.biases[6].discontinuity_counter + ); + assert_eq!( + msg.biases[6].integer_indicator, 203, + "incorrect value for biases[6].integer_indicator, expected 203, is {}", + msg.biases[6].integer_indicator + ); + assert_eq!( + msg.biases[6].widelane_integer_indicator, 87, + "incorrect value for biases[6].widelane_integer_indicator, expected 87, is {}", + msg.biases[6].widelane_integer_indicator + ); + assert_eq!( + msg.biases[7].bias, -1137604357, + "incorrect value for biases[7].bias, expected -1137604357, is {}", + msg.biases[7].bias + ); + assert_eq!( + msg.biases[7].code, 102, + "incorrect value for biases[7].code, expected 102, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].discontinuity_counter, 22, + "incorrect value for biases[7].discontinuity_counter, expected 22, is {}", + msg.biases[7].discontinuity_counter + ); + assert_eq!( + msg.biases[7].integer_indicator, 156, + "incorrect value for biases[7].integer_indicator, expected 156, is {}", + msg.biases[7].integer_indicator + ); + assert_eq!( + msg.biases[7].widelane_integer_indicator, 252, + "incorrect value for biases[7].widelane_integer_indicator, expected 252, is {}", + msg.biases[7].widelane_integer_indicator + ); + assert_eq!( + msg.biases[8].bias, -1910370172, + "incorrect value for biases[8].bias, expected -1910370172, is {}", + msg.biases[8].bias + ); + assert_eq!( + msg.biases[8].code, 157, + "incorrect value for biases[8].code, expected 157, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].discontinuity_counter, 49, + "incorrect value for biases[8].discontinuity_counter, expected 49, is {}", + msg.biases[8].discontinuity_counter + ); + assert_eq!( + msg.biases[8].integer_indicator, 222, + "incorrect value for biases[8].integer_indicator, expected 222, is {}", + msg.biases[8].integer_indicator + ); + assert_eq!( + msg.biases[8].widelane_integer_indicator, 245, + "incorrect value for biases[8].widelane_integer_indicator, expected 245, is {}", + msg.biases[8].widelane_integer_indicator + ); + assert_eq!( + msg.biases[9].bias, 1247996869, + "incorrect value for biases[9].bias, expected 1247996869, is {}", + msg.biases[9].bias + ); + assert_eq!( + msg.biases[9].code, 228, + "incorrect value for biases[9].code, expected 228, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].discontinuity_counter, 221, + "incorrect value for biases[9].discontinuity_counter, expected 221, is {}", + msg.biases[9].discontinuity_counter + ); + assert_eq!( + msg.biases[9].integer_indicator, 85, + "incorrect value for biases[9].integer_indicator, expected 85, is {}", + msg.biases[9].integer_indicator + ); + assert_eq!( + msg.biases[9].widelane_integer_indicator, 139, + "incorrect value for biases[9].widelane_integer_indicator, expected 139, is {}", + msg.biases[9].widelane_integer_indicator + ); + assert_eq!( + msg.biases[10].bias, -1133446161, + "incorrect value for biases[10].bias, expected -1133446161, is {}", + msg.biases[10].bias + ); + assert_eq!( + msg.biases[10].code, 107, + "incorrect value for biases[10].code, expected 107, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].discontinuity_counter, 38, + "incorrect value for biases[10].discontinuity_counter, expected 38, is {}", + msg.biases[10].discontinuity_counter + ); + assert_eq!( + msg.biases[10].integer_indicator, 70, + "incorrect value for biases[10].integer_indicator, expected 70, is {}", + msg.biases[10].integer_indicator + ); + assert_eq!( + msg.biases[10].widelane_integer_indicator, 36, + "incorrect value for biases[10].widelane_integer_indicator, expected 36, is {}", + msg.biases[10].widelane_integer_indicator + ); + assert_eq!( + msg.biases[11].bias, -720934762, + "incorrect value for biases[11].bias, expected -720934762, is {}", + msg.biases[11].bias + ); + assert_eq!( + msg.biases[11].code, 124, + "incorrect value for biases[11].code, expected 124, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].discontinuity_counter, 164, + "incorrect value for biases[11].discontinuity_counter, expected 164, is {}", + msg.biases[11].discontinuity_counter + ); + assert_eq!( + msg.biases[11].integer_indicator, 246, + "incorrect value for biases[11].integer_indicator, expected 246, is {}", + msg.biases[11].integer_indicator + ); + assert_eq!(msg.biases[11].widelane_integer_indicator, 141, "incorrect value for biases[11].widelane_integer_indicator, expected 141, is {}", msg.biases[11].widelane_integer_indicator); + assert_eq!( + msg.biases[12].bias, 706252548, + "incorrect value for biases[12].bias, expected 706252548, is {}", + msg.biases[12].bias + ); + assert_eq!( + msg.biases[12].code, 44, + "incorrect value for biases[12].code, expected 44, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].discontinuity_counter, 192, + "incorrect value for biases[12].discontinuity_counter, expected 192, is {}", + msg.biases[12].discontinuity_counter + ); + assert_eq!( + msg.biases[12].integer_indicator, 21, + "incorrect value for biases[12].integer_indicator, expected 21, is {}", + msg.biases[12].integer_indicator + ); + assert_eq!(msg.biases[12].widelane_integer_indicator, 244, "incorrect value for biases[12].widelane_integer_indicator, expected 244, is {}", msg.biases[12].widelane_integer_indicator); + assert_eq!( + msg.biases[13].bias, 388855338, + "incorrect value for biases[13].bias, expected 388855338, is {}", + msg.biases[13].bias + ); + assert_eq!( + msg.biases[13].code, 21, + "incorrect value for biases[13].code, expected 21, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].discontinuity_counter, 7, + "incorrect value for biases[13].discontinuity_counter, expected 7, is {}", + msg.biases[13].discontinuity_counter + ); + assert_eq!( + msg.biases[13].integer_indicator, 84, + "incorrect value for biases[13].integer_indicator, expected 84, is {}", + msg.biases[13].integer_indicator + ); + assert_eq!(msg.biases[13].widelane_integer_indicator, 136, "incorrect value for biases[13].widelane_integer_indicator, expected 136, is {}", msg.biases[13].widelane_integer_indicator); + assert_eq!( + msg.biases[14].bias, 47517353, + "incorrect value for biases[14].bias, expected 47517353, is {}", + msg.biases[14].bias + ); + assert_eq!( + msg.biases[14].code, 174, + "incorrect value for biases[14].code, expected 174, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].discontinuity_counter, 54, + "incorrect value for biases[14].discontinuity_counter, expected 54, is {}", + msg.biases[14].discontinuity_counter + ); + assert_eq!( + msg.biases[14].integer_indicator, 175, + "incorrect value for biases[14].integer_indicator, expected 175, is {}", + msg.biases[14].integer_indicator + ); + assert_eq!(msg.biases[14].widelane_integer_indicator, 129, "incorrect value for biases[14].widelane_integer_indicator, expected 129, is {}", msg.biases[14].widelane_integer_indicator); + assert_eq!( + msg.biases[15].bias, -2124125745, + "incorrect value for biases[15].bias, expected -2124125745, is {}", + msg.biases[15].bias + ); + assert_eq!( + msg.biases[15].code, 197, + "incorrect value for biases[15].code, expected 197, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].discontinuity_counter, 13, + "incorrect value for biases[15].discontinuity_counter, expected 13, is {}", + msg.biases[15].discontinuity_counter + ); + assert_eq!( + msg.biases[15].integer_indicator, 98, + "incorrect value for biases[15].integer_indicator, expected 98, is {}", + msg.biases[15].integer_indicator + ); + assert_eq!( + msg.biases[15].widelane_integer_indicator, 60, + "incorrect value for biases[15].widelane_integer_indicator, expected 60, is {}", + msg.biases[15].widelane_integer_indicator + ); + assert_eq!( + msg.biases[16].bias, -1401812607, + "incorrect value for biases[16].bias, expected -1401812607, is {}", + msg.biases[16].bias + ); + assert_eq!( + msg.biases[16].code, 72, + "incorrect value for biases[16].code, expected 72, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].discontinuity_counter, 140, + "incorrect value for biases[16].discontinuity_counter, expected 140, is {}", + msg.biases[16].discontinuity_counter + ); + assert_eq!( + msg.biases[16].integer_indicator, 136, + "incorrect value for biases[16].integer_indicator, expected 136, is {}", + msg.biases[16].integer_indicator + ); + assert_eq!(msg.biases[16].widelane_integer_indicator, 240, "incorrect value for biases[16].widelane_integer_indicator, expected 240, is {}", msg.biases[16].widelane_integer_indicator); + assert_eq!( + msg.biases[17].bias, 60257151, + "incorrect value for biases[17].bias, expected 60257151, is {}", + msg.biases[17].bias + ); + assert_eq!( + msg.biases[17].code, 151, + "incorrect value for biases[17].code, expected 151, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].discontinuity_counter, 210, + "incorrect value for biases[17].discontinuity_counter, expected 210, is {}", + msg.biases[17].discontinuity_counter + ); + assert_eq!( + msg.biases[17].integer_indicator, 150, + "incorrect value for biases[17].integer_indicator, expected 150, is {}", + msg.biases[17].integer_indicator + ); + assert_eq!( + msg.biases[17].widelane_integer_indicator, 17, + "incorrect value for biases[17].widelane_integer_indicator, expected 17, is {}", + msg.biases[17].widelane_integer_indicator + ); + assert_eq!( + msg.biases[18].bias, 41820677, + "incorrect value for biases[18].bias, expected 41820677, is {}", + msg.biases[18].bias + ); + assert_eq!( + msg.biases[18].code, 242, + "incorrect value for biases[18].code, expected 242, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].discontinuity_counter, 14, + "incorrect value for biases[18].discontinuity_counter, expected 14, is {}", + msg.biases[18].discontinuity_counter + ); + assert_eq!( + msg.biases[18].integer_indicator, 254, + "incorrect value for biases[18].integer_indicator, expected 254, is {}", + msg.biases[18].integer_indicator + ); + assert_eq!(msg.biases[18].widelane_integer_indicator, 215, "incorrect value for biases[18].widelane_integer_indicator, expected 215, is {}", msg.biases[18].widelane_integer_indicator); + assert_eq!( + msg.biases[19].bias, 1640616471, + "incorrect value for biases[19].bias, expected 1640616471, is {}", + msg.biases[19].bias + ); + assert_eq!( + msg.biases[19].code, 215, + "incorrect value for biases[19].code, expected 215, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].discontinuity_counter, 176, + "incorrect value for biases[19].discontinuity_counter, expected 176, is {}", + msg.biases[19].discontinuity_counter + ); + assert_eq!( + msg.biases[19].integer_indicator, 65, + "incorrect value for biases[19].integer_indicator, expected 65, is {}", + msg.biases[19].integer_indicator + ); + assert_eq!( + msg.biases[19].widelane_integer_indicator, 38, + "incorrect value for biases[19].widelane_integer_indicator, expected 38, is {}", + msg.biases[19].widelane_integer_indicator + ); + assert_eq!( + msg.biases[20].bias, -744786918, + "incorrect value for biases[20].bias, expected -744786918, is {}", + msg.biases[20].bias + ); + assert_eq!( + msg.biases[20].code, 36, + "incorrect value for biases[20].code, expected 36, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].discontinuity_counter, 224, + "incorrect value for biases[20].discontinuity_counter, expected 224, is {}", + msg.biases[20].discontinuity_counter + ); + assert_eq!( + msg.biases[20].integer_indicator, 207, + "incorrect value for biases[20].integer_indicator, expected 207, is {}", + msg.biases[20].integer_indicator + ); + assert_eq!( + msg.biases[20].widelane_integer_indicator, 92, + "incorrect value for biases[20].widelane_integer_indicator, expected 92, is {}", + msg.biases[20].widelane_integer_indicator + ); + assert_eq!( + msg.biases[21].bias, 1966589763, + "incorrect value for biases[21].bias, expected 1966589763, is {}", + msg.biases[21].bias + ); + assert_eq!( + msg.biases[21].code, 165, + "incorrect value for biases[21].code, expected 165, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].discontinuity_counter, 38, + "incorrect value for biases[21].discontinuity_counter, expected 38, is {}", + msg.biases[21].discontinuity_counter + ); + assert_eq!( + msg.biases[21].integer_indicator, 47, + "incorrect value for biases[21].integer_indicator, expected 47, is {}", + msg.biases[21].integer_indicator + ); + assert_eq!(msg.biases[21].widelane_integer_indicator, 102, "incorrect value for biases[21].widelane_integer_indicator, expected 102, is {}", msg.biases[21].widelane_integer_indicator); + assert_eq!( + msg.biases[22].bias, 364366310, + "incorrect value for biases[22].bias, expected 364366310, is {}", + msg.biases[22].bias + ); + assert_eq!( + msg.biases[22].code, 36, + "incorrect value for biases[22].code, expected 36, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].discontinuity_counter, 1, + "incorrect value for biases[22].discontinuity_counter, expected 1, is {}", + msg.biases[22].discontinuity_counter + ); + assert_eq!( + msg.biases[22].integer_indicator, 169, + "incorrect value for biases[22].integer_indicator, expected 169, is {}", + msg.biases[22].integer_indicator + ); + assert_eq!( + msg.biases[22].widelane_integer_indicator, 33, + "incorrect value for biases[22].widelane_integer_indicator, expected 33, is {}", + msg.biases[22].widelane_integer_indicator + ); + assert_eq!( + msg.biases[23].bias, -1839031379, + "incorrect value for biases[23].bias, expected -1839031379, is {}", + msg.biases[23].bias + ); + assert_eq!( + msg.biases[23].code, 42, + "incorrect value for biases[23].code, expected 42, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].discontinuity_counter, 173, + "incorrect value for biases[23].discontinuity_counter, expected 173, is {}", + msg.biases[23].discontinuity_counter + ); + assert_eq!( + msg.biases[23].integer_indicator, 62, + "incorrect value for biases[23].integer_indicator, expected 62, is {}", + msg.biases[23].integer_indicator + ); + assert_eq!(msg.biases[23].widelane_integer_indicator, 147, "incorrect value for biases[23].widelane_integer_indicator, expected 147, is {}", msg.biases[23].widelane_integer_indicator); + assert_eq!( + msg.biases[24].bias, 31817639, + "incorrect value for biases[24].bias, expected 31817639, is {}", + msg.biases[24].bias + ); + assert_eq!( + msg.biases[24].code, 231, + "incorrect value for biases[24].code, expected 231, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].discontinuity_counter, 82, + "incorrect value for biases[24].discontinuity_counter, expected 82, is {}", + msg.biases[24].discontinuity_counter + ); + assert_eq!( + msg.biases[24].integer_indicator, 167, + "incorrect value for biases[24].integer_indicator, expected 167, is {}", + msg.biases[24].integer_indicator + ); + assert_eq!(msg.biases[24].widelane_integer_indicator, 138, "incorrect value for biases[24].widelane_integer_indicator, expected 138, is {}", msg.biases[24].widelane_integer_indicator); + assert_eq!( + msg.biases[25].bias, -1619830156, + "incorrect value for biases[25].bias, expected -1619830156, is {}", + msg.biases[25].bias + ); + assert_eq!( + msg.biases[25].code, 2, + "incorrect value for biases[25].code, expected 2, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].discontinuity_counter, 207, + "incorrect value for biases[25].discontinuity_counter, expected 207, is {}", + msg.biases[25].discontinuity_counter + ); + assert_eq!( + msg.biases[25].integer_indicator, 127, + "incorrect value for biases[25].integer_indicator, expected 127, is {}", + msg.biases[25].integer_indicator + ); + assert_eq!(msg.biases[25].widelane_integer_indicator, 237, "incorrect value for biases[25].widelane_integer_indicator, expected 237, is {}", msg.biases[25].widelane_integer_indicator); + assert_eq!( + msg.biases[26].bias, -83375622, + "incorrect value for biases[26].bias, expected -83375622, is {}", + msg.biases[26].bias + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].discontinuity_counter, 145, + "incorrect value for biases[26].discontinuity_counter, expected 145, is {}", + msg.biases[26].discontinuity_counter + ); + assert_eq!( + msg.biases[26].integer_indicator, 42, + "incorrect value for biases[26].integer_indicator, expected 42, is {}", + msg.biases[26].integer_indicator + ); + assert_eq!( + msg.biases[26].widelane_integer_indicator, 66, + "incorrect value for biases[26].widelane_integer_indicator, expected 66, is {}", + msg.biases[26].widelane_integer_indicator + ); + assert_eq!( + msg.biases[27].bias, 1077458389, + "incorrect value for biases[27].bias, expected 1077458389, is {}", + msg.biases[27].bias + ); + assert_eq!( + msg.biases[27].code, 2, + "incorrect value for biases[27].code, expected 2, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].discontinuity_counter, 26, + "incorrect value for biases[27].discontinuity_counter, expected 26, is {}", + msg.biases[27].discontinuity_counter + ); + assert_eq!( + msg.biases[27].integer_indicator, 75, + "incorrect value for biases[27].integer_indicator, expected 75, is {}", + msg.biases[27].integer_indicator + ); + assert_eq!(msg.biases[27].widelane_integer_indicator, 230, "incorrect value for biases[27].widelane_integer_indicator, expected 230, is {}", msg.biases[27].widelane_integer_indicator); + assert_eq!( + msg.biases[28].bias, -883355501, + "incorrect value for biases[28].bias, expected -883355501, is {}", + msg.biases[28].bias + ); + assert_eq!( + msg.biases[28].code, 97, + "incorrect value for biases[28].code, expected 97, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].discontinuity_counter, 6, + "incorrect value for biases[28].discontinuity_counter, expected 6, is {}", + msg.biases[28].discontinuity_counter + ); + assert_eq!( + msg.biases[28].integer_indicator, 88, + "incorrect value for biases[28].integer_indicator, expected 88, is {}", + msg.biases[28].integer_indicator + ); + assert_eq!(msg.biases[28].widelane_integer_indicator, 255, "incorrect value for biases[28].widelane_integer_indicator, expected 255, is {}", msg.biases[28].widelane_integer_indicator); + assert_eq!( + msg.biases[29].bias, -1448611273, + "incorrect value for biases[29].bias, expected -1448611273, is {}", + msg.biases[29].bias + ); + assert_eq!( + msg.biases[29].code, 27, + "incorrect value for biases[29].code, expected 27, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].discontinuity_counter, 230, + "incorrect value for biases[29].discontinuity_counter, expected 230, is {}", + msg.biases[29].discontinuity_counter + ); + assert_eq!( + msg.biases[29].integer_indicator, 68, + "incorrect value for biases[29].integer_indicator, expected 68, is {}", + msg.biases[29].integer_indicator + ); + assert_eq!(msg.biases[29].widelane_integer_indicator, 243, "incorrect value for biases[29].widelane_integer_indicator, expected 243, is {}", msg.biases[29].widelane_integer_indicator); + assert_eq!( + msg.dispersive_bias, 98, + "incorrect value for dispersive_bias, expected 98, is {}", + msg.dispersive_bias + ); + assert_eq!( + msg.iod_ssr, 230, + "incorrect value for iod_ssr, expected 230, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.mw_consistency, 209, + "incorrect value for mw_consistency, expected 209, is {}", + msg.mw_consistency + ); + assert_eq!( + msg.sid.code, 82, + "incorrect value for sid.code, expected 82, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 169, + "incorrect value for sid.sat, expected 169, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 210803409, + "incorrect value for time.tow, expected 210803409, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 42197, + "incorrect value for time.wn, expected 42197, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 177, + "incorrect value for update_interval, expected 177, is {}", + msg.update_interval + ); + assert_eq!( + msg.yaw, 5881, + "incorrect value for yaw, expected 5881, is {}", + msg.yaw + ); + assert_eq!( + msg.yaw_rate, 17, + "incorrect value for yaw_rate, expected 17, is {}", + msg.yaw_rate + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrPhaseBiases"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_phase_biases() { + { + let json_input = r#"{"crc":61659,"length":255,"msg_type":1510,"payload":"0ZqQDNWkqVKx5mLR+RYRHfr1wdse1LHPuyGSOsykQXIx+DQIoSz8pqjofIZWrfGuLI6bgY+4odMPJL3Qwt2YEMtXIryNaL1mnPwW+4gxvJ3e9TGEECKO5FWL3cXrYkprRiQm7/twvHz2jaSWaAfVLBX0wASPGCoVVIgHKnYtF66vgTapDtUCxWI8Dc9pZIFIiPCMgQlyrJeWEdJ/c5cD8v7XDgUifgLXQSawF9LJYSTPXOAadJvTpS9mJkPHN3UkqSEB5sm3FSo+k62tm2KS56eKUqd/5QECf+3PdFpznwMqQpH6yQf7AkvmGtW1OEBhWP8GkxBZyxtE8+Y38qep","preamble":85,"sender":52955,"time":{"tow":210803409,"wn":42197},"sid":{"sat":169,"code":82},"update_interval":177,"iod_ssr":230,"dispersive_bias":98,"mw_consistency":209,"yaw":5881,"yaw_rate":17,"biases":[{"code":29,"integer_indicator":250,"widelane_integer_indicator":245,"discontinuity_counter":193,"bias":-1311498533},{"code":207,"integer_indicator":187,"widelane_integer_indicator":33,"discontinuity_counter":146,"bias":1101319226},{"code":114,"integer_indicator":49,"widelane_integer_indicator":248,"discontinuity_counter":52,"bias":-64184056},{"code":166,"integer_indicator":168,"widelane_integer_indicator":232,"discontinuity_counter":124,"bias":-240298362},{"code":174,"integer_indicator":44,"widelane_integer_indicator":142,"discontinuity_counter":155,"bias":-1581740159},{"code":211,"integer_indicator":15,"widelane_integer_indicator":36,"discontinuity_counter":189,"bias":-1730297136},{"code":16,"integer_indicator":203,"widelane_integer_indicator":87,"discontinuity_counter":34,"bias":-1117221444},{"code":102,"integer_indicator":156,"widelane_integer_indicator":252,"discontinuity_counter":22,"bias":-1137604357},{"code":157,"integer_indicator":222,"widelane_integer_indicator":245,"discontinuity_counter":49,"bias":-1910370172},{"code":228,"integer_indicator":85,"widelane_integer_indicator":139,"discontinuity_counter":221,"bias":1247996869},{"code":107,"integer_indicator":70,"widelane_integer_indicator":36,"discontinuity_counter":38,"bias":-1133446161},{"code":124,"integer_indicator":246,"widelane_integer_indicator":141,"discontinuity_counter":164,"bias":-720934762},{"code":44,"integer_indicator":21,"widelane_integer_indicator":244,"discontinuity_counter":192,"bias":706252548},{"code":21,"integer_indicator":84,"widelane_integer_indicator":136,"discontinuity_counter":7,"bias":388855338},{"code":174,"integer_indicator":175,"widelane_integer_indicator":129,"discontinuity_counter":54,"bias":47517353},{"code":197,"integer_indicator":98,"widelane_integer_indicator":60,"discontinuity_counter":13,"bias":-2124125745},{"code":72,"integer_indicator":136,"widelane_integer_indicator":240,"discontinuity_counter":140,"bias":-1401812607},{"code":151,"integer_indicator":150,"widelane_integer_indicator":17,"discontinuity_counter":210,"bias":60257151},{"code":242,"integer_indicator":254,"widelane_integer_indicator":215,"discontinuity_counter":14,"bias":41820677},{"code":215,"integer_indicator":65,"widelane_integer_indicator":38,"discontinuity_counter":176,"bias":1640616471},{"code":36,"integer_indicator":207,"widelane_integer_indicator":92,"discontinuity_counter":224,"bias":-744786918},{"code":165,"integer_indicator":47,"widelane_integer_indicator":102,"discontinuity_counter":38,"bias":1966589763},{"code":36,"integer_indicator":169,"widelane_integer_indicator":33,"discontinuity_counter":1,"bias":364366310},{"code":42,"integer_indicator":62,"widelane_integer_indicator":147,"discontinuity_counter":173,"bias":-1839031379},{"code":231,"integer_indicator":167,"widelane_integer_indicator":138,"discontinuity_counter":82,"bias":31817639},{"code":2,"integer_indicator":127,"widelane_integer_indicator":237,"discontinuity_counter":207,"bias":-1619830156},{"code":3,"integer_indicator":42,"widelane_integer_indicator":66,"discontinuity_counter":145,"bias":-83375622},{"code":2,"integer_indicator":75,"widelane_integer_indicator":230,"discontinuity_counter":26,"bias":1077458389},{"code":97,"integer_indicator":88,"widelane_integer_indicator":255,"discontinuity_counter":6,"bias":-883355501},{"code":27,"integer_indicator":68,"widelane_integer_indicator":243,"discontinuity_counter":230,"bias":-1448611273}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrPhaseBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e6, + "Incorrect message type, expected 0x5e6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xcedb, + "incorrect sender id, expected 0xcedb, is {sender_id}" + ); + assert_eq!( + msg.biases[0].bias, -1311498533, + "incorrect value for biases[0].bias, expected -1311498533, is {}", + msg.biases[0].bias + ); + assert_eq!( + msg.biases[0].code, 29, + "incorrect value for biases[0].code, expected 29, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].discontinuity_counter, 193, + "incorrect value for biases[0].discontinuity_counter, expected 193, is {}", + msg.biases[0].discontinuity_counter + ); + assert_eq!( + msg.biases[0].integer_indicator, 250, + "incorrect value for biases[0].integer_indicator, expected 250, is {}", + msg.biases[0].integer_indicator + ); + assert_eq!( + msg.biases[0].widelane_integer_indicator, 245, + "incorrect value for biases[0].widelane_integer_indicator, expected 245, is {}", + msg.biases[0].widelane_integer_indicator + ); + assert_eq!( + msg.biases[1].bias, 1101319226, + "incorrect value for biases[1].bias, expected 1101319226, is {}", + msg.biases[1].bias + ); + assert_eq!( + msg.biases[1].code, 207, + "incorrect value for biases[1].code, expected 207, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].discontinuity_counter, 146, + "incorrect value for biases[1].discontinuity_counter, expected 146, is {}", + msg.biases[1].discontinuity_counter + ); + assert_eq!( + msg.biases[1].integer_indicator, 187, + "incorrect value for biases[1].integer_indicator, expected 187, is {}", + msg.biases[1].integer_indicator + ); + assert_eq!( + msg.biases[1].widelane_integer_indicator, 33, + "incorrect value for biases[1].widelane_integer_indicator, expected 33, is {}", + msg.biases[1].widelane_integer_indicator + ); + assert_eq!( + msg.biases[2].bias, -64184056, + "incorrect value for biases[2].bias, expected -64184056, is {}", + msg.biases[2].bias + ); + assert_eq!( + msg.biases[2].code, 114, + "incorrect value for biases[2].code, expected 114, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].discontinuity_counter, 52, + "incorrect value for biases[2].discontinuity_counter, expected 52, is {}", + msg.biases[2].discontinuity_counter + ); + assert_eq!( + msg.biases[2].integer_indicator, 49, + "incorrect value for biases[2].integer_indicator, expected 49, is {}", + msg.biases[2].integer_indicator + ); + assert_eq!( + msg.biases[2].widelane_integer_indicator, 248, + "incorrect value for biases[2].widelane_integer_indicator, expected 248, is {}", + msg.biases[2].widelane_integer_indicator + ); + assert_eq!( + msg.biases[3].bias, -240298362, + "incorrect value for biases[3].bias, expected -240298362, is {}", + msg.biases[3].bias + ); + assert_eq!( + msg.biases[3].code, 166, + "incorrect value for biases[3].code, expected 166, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].discontinuity_counter, 124, + "incorrect value for biases[3].discontinuity_counter, expected 124, is {}", + msg.biases[3].discontinuity_counter + ); + assert_eq!( + msg.biases[3].integer_indicator, 168, + "incorrect value for biases[3].integer_indicator, expected 168, is {}", + msg.biases[3].integer_indicator + ); + assert_eq!( + msg.biases[3].widelane_integer_indicator, 232, + "incorrect value for biases[3].widelane_integer_indicator, expected 232, is {}", + msg.biases[3].widelane_integer_indicator + ); + assert_eq!( + msg.biases[4].bias, -1581740159, + "incorrect value for biases[4].bias, expected -1581740159, is {}", + msg.biases[4].bias + ); + assert_eq!( + msg.biases[4].code, 174, + "incorrect value for biases[4].code, expected 174, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].discontinuity_counter, 155, + "incorrect value for biases[4].discontinuity_counter, expected 155, is {}", + msg.biases[4].discontinuity_counter + ); + assert_eq!( + msg.biases[4].integer_indicator, 44, + "incorrect value for biases[4].integer_indicator, expected 44, is {}", + msg.biases[4].integer_indicator + ); + assert_eq!( + msg.biases[4].widelane_integer_indicator, 142, + "incorrect value for biases[4].widelane_integer_indicator, expected 142, is {}", + msg.biases[4].widelane_integer_indicator + ); + assert_eq!( + msg.biases[5].bias, -1730297136, + "incorrect value for biases[5].bias, expected -1730297136, is {}", + msg.biases[5].bias + ); + assert_eq!( + msg.biases[5].code, 211, + "incorrect value for biases[5].code, expected 211, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].discontinuity_counter, 189, + "incorrect value for biases[5].discontinuity_counter, expected 189, is {}", + msg.biases[5].discontinuity_counter + ); + assert_eq!( + msg.biases[5].integer_indicator, 15, + "incorrect value for biases[5].integer_indicator, expected 15, is {}", + msg.biases[5].integer_indicator + ); + assert_eq!( + msg.biases[5].widelane_integer_indicator, 36, + "incorrect value for biases[5].widelane_integer_indicator, expected 36, is {}", + msg.biases[5].widelane_integer_indicator + ); + assert_eq!( + msg.biases[6].bias, -1117221444, + "incorrect value for biases[6].bias, expected -1117221444, is {}", + msg.biases[6].bias + ); + assert_eq!( + msg.biases[6].code, 16, + "incorrect value for biases[6].code, expected 16, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].discontinuity_counter, 34, + "incorrect value for biases[6].discontinuity_counter, expected 34, is {}", + msg.biases[6].discontinuity_counter + ); + assert_eq!( + msg.biases[6].integer_indicator, 203, + "incorrect value for biases[6].integer_indicator, expected 203, is {}", + msg.biases[6].integer_indicator + ); + assert_eq!( + msg.biases[6].widelane_integer_indicator, 87, + "incorrect value for biases[6].widelane_integer_indicator, expected 87, is {}", + msg.biases[6].widelane_integer_indicator + ); + assert_eq!( + msg.biases[7].bias, -1137604357, + "incorrect value for biases[7].bias, expected -1137604357, is {}", + msg.biases[7].bias + ); + assert_eq!( + msg.biases[7].code, 102, + "incorrect value for biases[7].code, expected 102, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].discontinuity_counter, 22, + "incorrect value for biases[7].discontinuity_counter, expected 22, is {}", + msg.biases[7].discontinuity_counter + ); + assert_eq!( + msg.biases[7].integer_indicator, 156, + "incorrect value for biases[7].integer_indicator, expected 156, is {}", + msg.biases[7].integer_indicator + ); + assert_eq!( + msg.biases[7].widelane_integer_indicator, 252, + "incorrect value for biases[7].widelane_integer_indicator, expected 252, is {}", + msg.biases[7].widelane_integer_indicator + ); + assert_eq!( + msg.biases[8].bias, -1910370172, + "incorrect value for biases[8].bias, expected -1910370172, is {}", + msg.biases[8].bias + ); + assert_eq!( + msg.biases[8].code, 157, + "incorrect value for biases[8].code, expected 157, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].discontinuity_counter, 49, + "incorrect value for biases[8].discontinuity_counter, expected 49, is {}", + msg.biases[8].discontinuity_counter + ); + assert_eq!( + msg.biases[8].integer_indicator, 222, + "incorrect value for biases[8].integer_indicator, expected 222, is {}", + msg.biases[8].integer_indicator + ); + assert_eq!( + msg.biases[8].widelane_integer_indicator, 245, + "incorrect value for biases[8].widelane_integer_indicator, expected 245, is {}", + msg.biases[8].widelane_integer_indicator + ); + assert_eq!( + msg.biases[9].bias, 1247996869, + "incorrect value for biases[9].bias, expected 1247996869, is {}", + msg.biases[9].bias + ); + assert_eq!( + msg.biases[9].code, 228, + "incorrect value for biases[9].code, expected 228, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].discontinuity_counter, 221, + "incorrect value for biases[9].discontinuity_counter, expected 221, is {}", + msg.biases[9].discontinuity_counter + ); + assert_eq!( + msg.biases[9].integer_indicator, 85, + "incorrect value for biases[9].integer_indicator, expected 85, is {}", + msg.biases[9].integer_indicator + ); + assert_eq!( + msg.biases[9].widelane_integer_indicator, 139, + "incorrect value for biases[9].widelane_integer_indicator, expected 139, is {}", + msg.biases[9].widelane_integer_indicator + ); + assert_eq!( + msg.biases[10].bias, -1133446161, + "incorrect value for biases[10].bias, expected -1133446161, is {}", + msg.biases[10].bias + ); + assert_eq!( + msg.biases[10].code, 107, + "incorrect value for biases[10].code, expected 107, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].discontinuity_counter, 38, + "incorrect value for biases[10].discontinuity_counter, expected 38, is {}", + msg.biases[10].discontinuity_counter + ); + assert_eq!( + msg.biases[10].integer_indicator, 70, + "incorrect value for biases[10].integer_indicator, expected 70, is {}", + msg.biases[10].integer_indicator + ); + assert_eq!( + msg.biases[10].widelane_integer_indicator, 36, + "incorrect value for biases[10].widelane_integer_indicator, expected 36, is {}", + msg.biases[10].widelane_integer_indicator + ); + assert_eq!( + msg.biases[11].bias, -720934762, + "incorrect value for biases[11].bias, expected -720934762, is {}", + msg.biases[11].bias + ); + assert_eq!( + msg.biases[11].code, 124, + "incorrect value for biases[11].code, expected 124, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].discontinuity_counter, 164, + "incorrect value for biases[11].discontinuity_counter, expected 164, is {}", + msg.biases[11].discontinuity_counter + ); + assert_eq!( + msg.biases[11].integer_indicator, 246, + "incorrect value for biases[11].integer_indicator, expected 246, is {}", + msg.biases[11].integer_indicator + ); + assert_eq!(msg.biases[11].widelane_integer_indicator, 141, "incorrect value for biases[11].widelane_integer_indicator, expected 141, is {}", msg.biases[11].widelane_integer_indicator); + assert_eq!( + msg.biases[12].bias, 706252548, + "incorrect value for biases[12].bias, expected 706252548, is {}", + msg.biases[12].bias + ); + assert_eq!( + msg.biases[12].code, 44, + "incorrect value for biases[12].code, expected 44, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].discontinuity_counter, 192, + "incorrect value for biases[12].discontinuity_counter, expected 192, is {}", + msg.biases[12].discontinuity_counter + ); + assert_eq!( + msg.biases[12].integer_indicator, 21, + "incorrect value for biases[12].integer_indicator, expected 21, is {}", + msg.biases[12].integer_indicator + ); + assert_eq!(msg.biases[12].widelane_integer_indicator, 244, "incorrect value for biases[12].widelane_integer_indicator, expected 244, is {}", msg.biases[12].widelane_integer_indicator); + assert_eq!( + msg.biases[13].bias, 388855338, + "incorrect value for biases[13].bias, expected 388855338, is {}", + msg.biases[13].bias + ); + assert_eq!( + msg.biases[13].code, 21, + "incorrect value for biases[13].code, expected 21, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].discontinuity_counter, 7, + "incorrect value for biases[13].discontinuity_counter, expected 7, is {}", + msg.biases[13].discontinuity_counter + ); + assert_eq!( + msg.biases[13].integer_indicator, 84, + "incorrect value for biases[13].integer_indicator, expected 84, is {}", + msg.biases[13].integer_indicator + ); + assert_eq!(msg.biases[13].widelane_integer_indicator, 136, "incorrect value for biases[13].widelane_integer_indicator, expected 136, is {}", msg.biases[13].widelane_integer_indicator); + assert_eq!( + msg.biases[14].bias, 47517353, + "incorrect value for biases[14].bias, expected 47517353, is {}", + msg.biases[14].bias + ); + assert_eq!( + msg.biases[14].code, 174, + "incorrect value for biases[14].code, expected 174, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].discontinuity_counter, 54, + "incorrect value for biases[14].discontinuity_counter, expected 54, is {}", + msg.biases[14].discontinuity_counter + ); + assert_eq!( + msg.biases[14].integer_indicator, 175, + "incorrect value for biases[14].integer_indicator, expected 175, is {}", + msg.biases[14].integer_indicator + ); + assert_eq!(msg.biases[14].widelane_integer_indicator, 129, "incorrect value for biases[14].widelane_integer_indicator, expected 129, is {}", msg.biases[14].widelane_integer_indicator); + assert_eq!( + msg.biases[15].bias, -2124125745, + "incorrect value for biases[15].bias, expected -2124125745, is {}", + msg.biases[15].bias + ); + assert_eq!( + msg.biases[15].code, 197, + "incorrect value for biases[15].code, expected 197, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].discontinuity_counter, 13, + "incorrect value for biases[15].discontinuity_counter, expected 13, is {}", + msg.biases[15].discontinuity_counter + ); + assert_eq!( + msg.biases[15].integer_indicator, 98, + "incorrect value for biases[15].integer_indicator, expected 98, is {}", + msg.biases[15].integer_indicator + ); + assert_eq!( + msg.biases[15].widelane_integer_indicator, 60, + "incorrect value for biases[15].widelane_integer_indicator, expected 60, is {}", + msg.biases[15].widelane_integer_indicator + ); + assert_eq!( + msg.biases[16].bias, -1401812607, + "incorrect value for biases[16].bias, expected -1401812607, is {}", + msg.biases[16].bias + ); + assert_eq!( + msg.biases[16].code, 72, + "incorrect value for biases[16].code, expected 72, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].discontinuity_counter, 140, + "incorrect value for biases[16].discontinuity_counter, expected 140, is {}", + msg.biases[16].discontinuity_counter + ); + assert_eq!( + msg.biases[16].integer_indicator, 136, + "incorrect value for biases[16].integer_indicator, expected 136, is {}", + msg.biases[16].integer_indicator + ); + assert_eq!(msg.biases[16].widelane_integer_indicator, 240, "incorrect value for biases[16].widelane_integer_indicator, expected 240, is {}", msg.biases[16].widelane_integer_indicator); + assert_eq!( + msg.biases[17].bias, 60257151, + "incorrect value for biases[17].bias, expected 60257151, is {}", + msg.biases[17].bias + ); + assert_eq!( + msg.biases[17].code, 151, + "incorrect value for biases[17].code, expected 151, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].discontinuity_counter, 210, + "incorrect value for biases[17].discontinuity_counter, expected 210, is {}", + msg.biases[17].discontinuity_counter + ); + assert_eq!( + msg.biases[17].integer_indicator, 150, + "incorrect value for biases[17].integer_indicator, expected 150, is {}", + msg.biases[17].integer_indicator + ); + assert_eq!( + msg.biases[17].widelane_integer_indicator, 17, + "incorrect value for biases[17].widelane_integer_indicator, expected 17, is {}", + msg.biases[17].widelane_integer_indicator + ); + assert_eq!( + msg.biases[18].bias, 41820677, + "incorrect value for biases[18].bias, expected 41820677, is {}", + msg.biases[18].bias + ); + assert_eq!( + msg.biases[18].code, 242, + "incorrect value for biases[18].code, expected 242, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].discontinuity_counter, 14, + "incorrect value for biases[18].discontinuity_counter, expected 14, is {}", + msg.biases[18].discontinuity_counter + ); + assert_eq!( + msg.biases[18].integer_indicator, 254, + "incorrect value for biases[18].integer_indicator, expected 254, is {}", + msg.biases[18].integer_indicator + ); + assert_eq!(msg.biases[18].widelane_integer_indicator, 215, "incorrect value for biases[18].widelane_integer_indicator, expected 215, is {}", msg.biases[18].widelane_integer_indicator); + assert_eq!( + msg.biases[19].bias, 1640616471, + "incorrect value for biases[19].bias, expected 1640616471, is {}", + msg.biases[19].bias + ); + assert_eq!( + msg.biases[19].code, 215, + "incorrect value for biases[19].code, expected 215, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].discontinuity_counter, 176, + "incorrect value for biases[19].discontinuity_counter, expected 176, is {}", + msg.biases[19].discontinuity_counter + ); + assert_eq!( + msg.biases[19].integer_indicator, 65, + "incorrect value for biases[19].integer_indicator, expected 65, is {}", + msg.biases[19].integer_indicator + ); + assert_eq!( + msg.biases[19].widelane_integer_indicator, 38, + "incorrect value for biases[19].widelane_integer_indicator, expected 38, is {}", + msg.biases[19].widelane_integer_indicator + ); + assert_eq!( + msg.biases[20].bias, -744786918, + "incorrect value for biases[20].bias, expected -744786918, is {}", + msg.biases[20].bias + ); + assert_eq!( + msg.biases[20].code, 36, + "incorrect value for biases[20].code, expected 36, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].discontinuity_counter, 224, + "incorrect value for biases[20].discontinuity_counter, expected 224, is {}", + msg.biases[20].discontinuity_counter + ); + assert_eq!( + msg.biases[20].integer_indicator, 207, + "incorrect value for biases[20].integer_indicator, expected 207, is {}", + msg.biases[20].integer_indicator + ); + assert_eq!( + msg.biases[20].widelane_integer_indicator, 92, + "incorrect value for biases[20].widelane_integer_indicator, expected 92, is {}", + msg.biases[20].widelane_integer_indicator + ); + assert_eq!( + msg.biases[21].bias, 1966589763, + "incorrect value for biases[21].bias, expected 1966589763, is {}", + msg.biases[21].bias + ); + assert_eq!( + msg.biases[21].code, 165, + "incorrect value for biases[21].code, expected 165, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].discontinuity_counter, 38, + "incorrect value for biases[21].discontinuity_counter, expected 38, is {}", + msg.biases[21].discontinuity_counter + ); + assert_eq!( + msg.biases[21].integer_indicator, 47, + "incorrect value for biases[21].integer_indicator, expected 47, is {}", + msg.biases[21].integer_indicator + ); + assert_eq!(msg.biases[21].widelane_integer_indicator, 102, "incorrect value for biases[21].widelane_integer_indicator, expected 102, is {}", msg.biases[21].widelane_integer_indicator); + assert_eq!( + msg.biases[22].bias, 364366310, + "incorrect value for biases[22].bias, expected 364366310, is {}", + msg.biases[22].bias + ); + assert_eq!( + msg.biases[22].code, 36, + "incorrect value for biases[22].code, expected 36, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].discontinuity_counter, 1, + "incorrect value for biases[22].discontinuity_counter, expected 1, is {}", + msg.biases[22].discontinuity_counter + ); + assert_eq!( + msg.biases[22].integer_indicator, 169, + "incorrect value for biases[22].integer_indicator, expected 169, is {}", + msg.biases[22].integer_indicator + ); + assert_eq!( + msg.biases[22].widelane_integer_indicator, 33, + "incorrect value for biases[22].widelane_integer_indicator, expected 33, is {}", + msg.biases[22].widelane_integer_indicator + ); + assert_eq!( + msg.biases[23].bias, -1839031379, + "incorrect value for biases[23].bias, expected -1839031379, is {}", + msg.biases[23].bias + ); + assert_eq!( + msg.biases[23].code, 42, + "incorrect value for biases[23].code, expected 42, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].discontinuity_counter, 173, + "incorrect value for biases[23].discontinuity_counter, expected 173, is {}", + msg.biases[23].discontinuity_counter + ); + assert_eq!( + msg.biases[23].integer_indicator, 62, + "incorrect value for biases[23].integer_indicator, expected 62, is {}", + msg.biases[23].integer_indicator + ); + assert_eq!(msg.biases[23].widelane_integer_indicator, 147, "incorrect value for biases[23].widelane_integer_indicator, expected 147, is {}", msg.biases[23].widelane_integer_indicator); + assert_eq!( + msg.biases[24].bias, 31817639, + "incorrect value for biases[24].bias, expected 31817639, is {}", + msg.biases[24].bias + ); + assert_eq!( + msg.biases[24].code, 231, + "incorrect value for biases[24].code, expected 231, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].discontinuity_counter, 82, + "incorrect value for biases[24].discontinuity_counter, expected 82, is {}", + msg.biases[24].discontinuity_counter + ); + assert_eq!( + msg.biases[24].integer_indicator, 167, + "incorrect value for biases[24].integer_indicator, expected 167, is {}", + msg.biases[24].integer_indicator + ); + assert_eq!(msg.biases[24].widelane_integer_indicator, 138, "incorrect value for biases[24].widelane_integer_indicator, expected 138, is {}", msg.biases[24].widelane_integer_indicator); + assert_eq!( + msg.biases[25].bias, -1619830156, + "incorrect value for biases[25].bias, expected -1619830156, is {}", + msg.biases[25].bias + ); + assert_eq!( + msg.biases[25].code, 2, + "incorrect value for biases[25].code, expected 2, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].discontinuity_counter, 207, + "incorrect value for biases[25].discontinuity_counter, expected 207, is {}", + msg.biases[25].discontinuity_counter + ); + assert_eq!( + msg.biases[25].integer_indicator, 127, + "incorrect value for biases[25].integer_indicator, expected 127, is {}", + msg.biases[25].integer_indicator + ); + assert_eq!(msg.biases[25].widelane_integer_indicator, 237, "incorrect value for biases[25].widelane_integer_indicator, expected 237, is {}", msg.biases[25].widelane_integer_indicator); + assert_eq!( + msg.biases[26].bias, -83375622, + "incorrect value for biases[26].bias, expected -83375622, is {}", + msg.biases[26].bias + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].discontinuity_counter, 145, + "incorrect value for biases[26].discontinuity_counter, expected 145, is {}", + msg.biases[26].discontinuity_counter + ); + assert_eq!( + msg.biases[26].integer_indicator, 42, + "incorrect value for biases[26].integer_indicator, expected 42, is {}", + msg.biases[26].integer_indicator + ); + assert_eq!( + msg.biases[26].widelane_integer_indicator, 66, + "incorrect value for biases[26].widelane_integer_indicator, expected 66, is {}", + msg.biases[26].widelane_integer_indicator + ); + assert_eq!( + msg.biases[27].bias, 1077458389, + "incorrect value for biases[27].bias, expected 1077458389, is {}", + msg.biases[27].bias + ); + assert_eq!( + msg.biases[27].code, 2, + "incorrect value for biases[27].code, expected 2, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].discontinuity_counter, 26, + "incorrect value for biases[27].discontinuity_counter, expected 26, is {}", + msg.biases[27].discontinuity_counter + ); + assert_eq!( + msg.biases[27].integer_indicator, 75, + "incorrect value for biases[27].integer_indicator, expected 75, is {}", + msg.biases[27].integer_indicator + ); + assert_eq!(msg.biases[27].widelane_integer_indicator, 230, "incorrect value for biases[27].widelane_integer_indicator, expected 230, is {}", msg.biases[27].widelane_integer_indicator); + assert_eq!( + msg.biases[28].bias, -883355501, + "incorrect value for biases[28].bias, expected -883355501, is {}", + msg.biases[28].bias + ); + assert_eq!( + msg.biases[28].code, 97, + "incorrect value for biases[28].code, expected 97, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].discontinuity_counter, 6, + "incorrect value for biases[28].discontinuity_counter, expected 6, is {}", + msg.biases[28].discontinuity_counter + ); + assert_eq!( + msg.biases[28].integer_indicator, 88, + "incorrect value for biases[28].integer_indicator, expected 88, is {}", + msg.biases[28].integer_indicator + ); + assert_eq!(msg.biases[28].widelane_integer_indicator, 255, "incorrect value for biases[28].widelane_integer_indicator, expected 255, is {}", msg.biases[28].widelane_integer_indicator); + assert_eq!( + msg.biases[29].bias, -1448611273, + "incorrect value for biases[29].bias, expected -1448611273, is {}", + msg.biases[29].bias + ); + assert_eq!( + msg.biases[29].code, 27, + "incorrect value for biases[29].code, expected 27, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].discontinuity_counter, 230, + "incorrect value for biases[29].discontinuity_counter, expected 230, is {}", + msg.biases[29].discontinuity_counter + ); + assert_eq!( + msg.biases[29].integer_indicator, 68, + "incorrect value for biases[29].integer_indicator, expected 68, is {}", + msg.biases[29].integer_indicator + ); + assert_eq!(msg.biases[29].widelane_integer_indicator, 243, "incorrect value for biases[29].widelane_integer_indicator, expected 243, is {}", msg.biases[29].widelane_integer_indicator); + assert_eq!( + msg.dispersive_bias, 98, + "incorrect value for dispersive_bias, expected 98, is {}", + msg.dispersive_bias + ); + assert_eq!( + msg.iod_ssr, 230, + "incorrect value for iod_ssr, expected 230, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.mw_consistency, 209, + "incorrect value for mw_consistency, expected 209, is {}", + msg.mw_consistency + ); + assert_eq!( + msg.sid.code, 82, + "incorrect value for sid.code, expected 82, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 169, + "incorrect value for sid.sat, expected 169, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 210803409, + "incorrect value for time.tow, expected 210803409, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 42197, + "incorrect value for time.wn, expected 42197, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 177, + "incorrect value for update_interval, expected 177, is {}", + msg.update_interval + ); + assert_eq!( + msg.yaw, 5881, + "incorrect value for yaw, expected 5881, is {}", + msg.yaw + ); + assert_eq!( + msg.yaw_rate, 17, + "incorrect value for yaw_rate, expected 17, is {}", + msg.yaw_rate + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrPhaseBiases"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_phase_biases`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_phase_biases() { + { + let mut payload = Cursor::new(vec![ + 85, 230, 5, 219, 206, 255, 209, 154, 144, 12, 213, 164, 169, 82, 177, 230, 98, 209, + 249, 22, 17, 29, 250, 245, 193, 219, 30, 212, 177, 207, 187, 33, 146, 58, 204, 164, 65, + 114, 49, 248, 52, 8, 161, 44, 252, 166, 168, 232, 124, 134, 86, 173, 241, 174, 44, 142, + 155, 129, 143, 184, 161, 211, 15, 36, 189, 208, 194, 221, 152, 16, 203, 87, 34, 188, + 141, 104, 189, 102, 156, 252, 22, 251, 136, 49, 188, 157, 222, 245, 49, 132, 16, 34, + 142, 228, 85, 139, 221, 197, 235, 98, 74, 107, 70, 36, 38, 239, 251, 112, 188, 124, + 246, 141, 164, 150, 104, 7, 213, 44, 21, 244, 192, 4, 143, 24, 42, 21, 84, 136, 7, 42, + 118, 45, 23, 174, 175, 129, 54, 169, 14, 213, 2, 197, 98, 60, 13, 207, 105, 100, 129, + 72, 136, 240, 140, 129, 9, 114, 172, 151, 150, 17, 210, 127, 115, 151, 3, 242, 254, + 215, 14, 5, 34, 126, 2, 215, 65, 38, 176, 23, 210, 201, 97, 36, 207, 92, 224, 26, 116, + 155, 211, 165, 47, 102, 38, 67, 199, 55, 117, 36, 169, 33, 1, 230, 201, 183, 21, 42, + 62, 147, 173, 173, 155, 98, 146, 231, 167, 138, 82, 167, 127, 229, 1, 2, 127, 237, 207, + 116, 90, 115, 159, 3, 42, 66, 145, 250, 201, 7, 251, 2, 75, 230, 26, 213, 181, 56, 64, + 97, 88, 255, 6, 147, 16, 89, 203, 27, 68, 243, 230, 55, 242, 167, 169, 219, 240, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrPhaseBiases( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrPhaseBiases(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5e6, + "Incorrect message type, expected 0x5e6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xcedb, + "incorrect sender id, expected 0xcedb, is {sender_id}" + ); + assert_eq!( + msg.biases[0].bias, -1311498533, + "incorrect value for biases[0].bias, expected -1311498533, is {}", + msg.biases[0].bias + ); + assert_eq!( + msg.biases[0].code, 29, + "incorrect value for biases[0].code, expected 29, is {}", + msg.biases[0].code + ); + assert_eq!( + msg.biases[0].discontinuity_counter, 193, + "incorrect value for biases[0].discontinuity_counter, expected 193, is {}", + msg.biases[0].discontinuity_counter + ); + assert_eq!( + msg.biases[0].integer_indicator, 250, + "incorrect value for biases[0].integer_indicator, expected 250, is {}", + msg.biases[0].integer_indicator + ); + assert_eq!( + msg.biases[0].widelane_integer_indicator, 245, + "incorrect value for biases[0].widelane_integer_indicator, expected 245, is {}", + msg.biases[0].widelane_integer_indicator + ); + assert_eq!( + msg.biases[1].bias, 1101319226, + "incorrect value for biases[1].bias, expected 1101319226, is {}", + msg.biases[1].bias + ); + assert_eq!( + msg.biases[1].code, 207, + "incorrect value for biases[1].code, expected 207, is {}", + msg.biases[1].code + ); + assert_eq!( + msg.biases[1].discontinuity_counter, 146, + "incorrect value for biases[1].discontinuity_counter, expected 146, is {}", + msg.biases[1].discontinuity_counter + ); + assert_eq!( + msg.biases[1].integer_indicator, 187, + "incorrect value for biases[1].integer_indicator, expected 187, is {}", + msg.biases[1].integer_indicator + ); + assert_eq!( + msg.biases[1].widelane_integer_indicator, 33, + "incorrect value for biases[1].widelane_integer_indicator, expected 33, is {}", + msg.biases[1].widelane_integer_indicator + ); + assert_eq!( + msg.biases[2].bias, -64184056, + "incorrect value for biases[2].bias, expected -64184056, is {}", + msg.biases[2].bias + ); + assert_eq!( + msg.biases[2].code, 114, + "incorrect value for biases[2].code, expected 114, is {}", + msg.biases[2].code + ); + assert_eq!( + msg.biases[2].discontinuity_counter, 52, + "incorrect value for biases[2].discontinuity_counter, expected 52, is {}", + msg.biases[2].discontinuity_counter + ); + assert_eq!( + msg.biases[2].integer_indicator, 49, + "incorrect value for biases[2].integer_indicator, expected 49, is {}", + msg.biases[2].integer_indicator + ); + assert_eq!( + msg.biases[2].widelane_integer_indicator, 248, + "incorrect value for biases[2].widelane_integer_indicator, expected 248, is {}", + msg.biases[2].widelane_integer_indicator + ); + assert_eq!( + msg.biases[3].bias, -240298362, + "incorrect value for biases[3].bias, expected -240298362, is {}", + msg.biases[3].bias + ); + assert_eq!( + msg.biases[3].code, 166, + "incorrect value for biases[3].code, expected 166, is {}", + msg.biases[3].code + ); + assert_eq!( + msg.biases[3].discontinuity_counter, 124, + "incorrect value for biases[3].discontinuity_counter, expected 124, is {}", + msg.biases[3].discontinuity_counter + ); + assert_eq!( + msg.biases[3].integer_indicator, 168, + "incorrect value for biases[3].integer_indicator, expected 168, is {}", + msg.biases[3].integer_indicator + ); + assert_eq!( + msg.biases[3].widelane_integer_indicator, 232, + "incorrect value for biases[3].widelane_integer_indicator, expected 232, is {}", + msg.biases[3].widelane_integer_indicator + ); + assert_eq!( + msg.biases[4].bias, -1581740159, + "incorrect value for biases[4].bias, expected -1581740159, is {}", + msg.biases[4].bias + ); + assert_eq!( + msg.biases[4].code, 174, + "incorrect value for biases[4].code, expected 174, is {}", + msg.biases[4].code + ); + assert_eq!( + msg.biases[4].discontinuity_counter, 155, + "incorrect value for biases[4].discontinuity_counter, expected 155, is {}", + msg.biases[4].discontinuity_counter + ); + assert_eq!( + msg.biases[4].integer_indicator, 44, + "incorrect value for biases[4].integer_indicator, expected 44, is {}", + msg.biases[4].integer_indicator + ); + assert_eq!( + msg.biases[4].widelane_integer_indicator, 142, + "incorrect value for biases[4].widelane_integer_indicator, expected 142, is {}", + msg.biases[4].widelane_integer_indicator + ); + assert_eq!( + msg.biases[5].bias, -1730297136, + "incorrect value for biases[5].bias, expected -1730297136, is {}", + msg.biases[5].bias + ); + assert_eq!( + msg.biases[5].code, 211, + "incorrect value for biases[5].code, expected 211, is {}", + msg.biases[5].code + ); + assert_eq!( + msg.biases[5].discontinuity_counter, 189, + "incorrect value for biases[5].discontinuity_counter, expected 189, is {}", + msg.biases[5].discontinuity_counter + ); + assert_eq!( + msg.biases[5].integer_indicator, 15, + "incorrect value for biases[5].integer_indicator, expected 15, is {}", + msg.biases[5].integer_indicator + ); + assert_eq!( + msg.biases[5].widelane_integer_indicator, 36, + "incorrect value for biases[5].widelane_integer_indicator, expected 36, is {}", + msg.biases[5].widelane_integer_indicator + ); + assert_eq!( + msg.biases[6].bias, -1117221444, + "incorrect value for biases[6].bias, expected -1117221444, is {}", + msg.biases[6].bias + ); + assert_eq!( + msg.biases[6].code, 16, + "incorrect value for biases[6].code, expected 16, is {}", + msg.biases[6].code + ); + assert_eq!( + msg.biases[6].discontinuity_counter, 34, + "incorrect value for biases[6].discontinuity_counter, expected 34, is {}", + msg.biases[6].discontinuity_counter + ); + assert_eq!( + msg.biases[6].integer_indicator, 203, + "incorrect value for biases[6].integer_indicator, expected 203, is {}", + msg.biases[6].integer_indicator + ); + assert_eq!( + msg.biases[6].widelane_integer_indicator, 87, + "incorrect value for biases[6].widelane_integer_indicator, expected 87, is {}", + msg.biases[6].widelane_integer_indicator + ); + assert_eq!( + msg.biases[7].bias, -1137604357, + "incorrect value for biases[7].bias, expected -1137604357, is {}", + msg.biases[7].bias + ); + assert_eq!( + msg.biases[7].code, 102, + "incorrect value for biases[7].code, expected 102, is {}", + msg.biases[7].code + ); + assert_eq!( + msg.biases[7].discontinuity_counter, 22, + "incorrect value for biases[7].discontinuity_counter, expected 22, is {}", + msg.biases[7].discontinuity_counter + ); + assert_eq!( + msg.biases[7].integer_indicator, 156, + "incorrect value for biases[7].integer_indicator, expected 156, is {}", + msg.biases[7].integer_indicator + ); + assert_eq!( + msg.biases[7].widelane_integer_indicator, 252, + "incorrect value for biases[7].widelane_integer_indicator, expected 252, is {}", + msg.biases[7].widelane_integer_indicator + ); + assert_eq!( + msg.biases[8].bias, -1910370172, + "incorrect value for biases[8].bias, expected -1910370172, is {}", + msg.biases[8].bias + ); + assert_eq!( + msg.biases[8].code, 157, + "incorrect value for biases[8].code, expected 157, is {}", + msg.biases[8].code + ); + assert_eq!( + msg.biases[8].discontinuity_counter, 49, + "incorrect value for biases[8].discontinuity_counter, expected 49, is {}", + msg.biases[8].discontinuity_counter + ); + assert_eq!( + msg.biases[8].integer_indicator, 222, + "incorrect value for biases[8].integer_indicator, expected 222, is {}", + msg.biases[8].integer_indicator + ); + assert_eq!( + msg.biases[8].widelane_integer_indicator, 245, + "incorrect value for biases[8].widelane_integer_indicator, expected 245, is {}", + msg.biases[8].widelane_integer_indicator + ); + assert_eq!( + msg.biases[9].bias, 1247996869, + "incorrect value for biases[9].bias, expected 1247996869, is {}", + msg.biases[9].bias + ); + assert_eq!( + msg.biases[9].code, 228, + "incorrect value for biases[9].code, expected 228, is {}", + msg.biases[9].code + ); + assert_eq!( + msg.biases[9].discontinuity_counter, 221, + "incorrect value for biases[9].discontinuity_counter, expected 221, is {}", + msg.biases[9].discontinuity_counter + ); + assert_eq!( + msg.biases[9].integer_indicator, 85, + "incorrect value for biases[9].integer_indicator, expected 85, is {}", + msg.biases[9].integer_indicator + ); + assert_eq!( + msg.biases[9].widelane_integer_indicator, 139, + "incorrect value for biases[9].widelane_integer_indicator, expected 139, is {}", + msg.biases[9].widelane_integer_indicator + ); + assert_eq!( + msg.biases[10].bias, -1133446161, + "incorrect value for biases[10].bias, expected -1133446161, is {}", + msg.biases[10].bias + ); + assert_eq!( + msg.biases[10].code, 107, + "incorrect value for biases[10].code, expected 107, is {}", + msg.biases[10].code + ); + assert_eq!( + msg.biases[10].discontinuity_counter, 38, + "incorrect value for biases[10].discontinuity_counter, expected 38, is {}", + msg.biases[10].discontinuity_counter + ); + assert_eq!( + msg.biases[10].integer_indicator, 70, + "incorrect value for biases[10].integer_indicator, expected 70, is {}", + msg.biases[10].integer_indicator + ); + assert_eq!( + msg.biases[10].widelane_integer_indicator, 36, + "incorrect value for biases[10].widelane_integer_indicator, expected 36, is {}", + msg.biases[10].widelane_integer_indicator + ); + assert_eq!( + msg.biases[11].bias, -720934762, + "incorrect value for biases[11].bias, expected -720934762, is {}", + msg.biases[11].bias + ); + assert_eq!( + msg.biases[11].code, 124, + "incorrect value for biases[11].code, expected 124, is {}", + msg.biases[11].code + ); + assert_eq!( + msg.biases[11].discontinuity_counter, 164, + "incorrect value for biases[11].discontinuity_counter, expected 164, is {}", + msg.biases[11].discontinuity_counter + ); + assert_eq!( + msg.biases[11].integer_indicator, 246, + "incorrect value for biases[11].integer_indicator, expected 246, is {}", + msg.biases[11].integer_indicator + ); + assert_eq!(msg.biases[11].widelane_integer_indicator, 141, "incorrect value for biases[11].widelane_integer_indicator, expected 141, is {}", msg.biases[11].widelane_integer_indicator); + assert_eq!( + msg.biases[12].bias, 706252548, + "incorrect value for biases[12].bias, expected 706252548, is {}", + msg.biases[12].bias + ); + assert_eq!( + msg.biases[12].code, 44, + "incorrect value for biases[12].code, expected 44, is {}", + msg.biases[12].code + ); + assert_eq!( + msg.biases[12].discontinuity_counter, 192, + "incorrect value for biases[12].discontinuity_counter, expected 192, is {}", + msg.biases[12].discontinuity_counter + ); + assert_eq!( + msg.biases[12].integer_indicator, 21, + "incorrect value for biases[12].integer_indicator, expected 21, is {}", + msg.biases[12].integer_indicator + ); + assert_eq!(msg.biases[12].widelane_integer_indicator, 244, "incorrect value for biases[12].widelane_integer_indicator, expected 244, is {}", msg.biases[12].widelane_integer_indicator); + assert_eq!( + msg.biases[13].bias, 388855338, + "incorrect value for biases[13].bias, expected 388855338, is {}", + msg.biases[13].bias + ); + assert_eq!( + msg.biases[13].code, 21, + "incorrect value for biases[13].code, expected 21, is {}", + msg.biases[13].code + ); + assert_eq!( + msg.biases[13].discontinuity_counter, 7, + "incorrect value for biases[13].discontinuity_counter, expected 7, is {}", + msg.biases[13].discontinuity_counter + ); + assert_eq!( + msg.biases[13].integer_indicator, 84, + "incorrect value for biases[13].integer_indicator, expected 84, is {}", + msg.biases[13].integer_indicator + ); + assert_eq!(msg.biases[13].widelane_integer_indicator, 136, "incorrect value for biases[13].widelane_integer_indicator, expected 136, is {}", msg.biases[13].widelane_integer_indicator); + assert_eq!( + msg.biases[14].bias, 47517353, + "incorrect value for biases[14].bias, expected 47517353, is {}", + msg.biases[14].bias + ); + assert_eq!( + msg.biases[14].code, 174, + "incorrect value for biases[14].code, expected 174, is {}", + msg.biases[14].code + ); + assert_eq!( + msg.biases[14].discontinuity_counter, 54, + "incorrect value for biases[14].discontinuity_counter, expected 54, is {}", + msg.biases[14].discontinuity_counter + ); + assert_eq!( + msg.biases[14].integer_indicator, 175, + "incorrect value for biases[14].integer_indicator, expected 175, is {}", + msg.biases[14].integer_indicator + ); + assert_eq!(msg.biases[14].widelane_integer_indicator, 129, "incorrect value for biases[14].widelane_integer_indicator, expected 129, is {}", msg.biases[14].widelane_integer_indicator); + assert_eq!( + msg.biases[15].bias, -2124125745, + "incorrect value for biases[15].bias, expected -2124125745, is {}", + msg.biases[15].bias + ); + assert_eq!( + msg.biases[15].code, 197, + "incorrect value for biases[15].code, expected 197, is {}", + msg.biases[15].code + ); + assert_eq!( + msg.biases[15].discontinuity_counter, 13, + "incorrect value for biases[15].discontinuity_counter, expected 13, is {}", + msg.biases[15].discontinuity_counter + ); + assert_eq!( + msg.biases[15].integer_indicator, 98, + "incorrect value for biases[15].integer_indicator, expected 98, is {}", + msg.biases[15].integer_indicator + ); + assert_eq!( + msg.biases[15].widelane_integer_indicator, 60, + "incorrect value for biases[15].widelane_integer_indicator, expected 60, is {}", + msg.biases[15].widelane_integer_indicator + ); + assert_eq!( + msg.biases[16].bias, -1401812607, + "incorrect value for biases[16].bias, expected -1401812607, is {}", + msg.biases[16].bias + ); + assert_eq!( + msg.biases[16].code, 72, + "incorrect value for biases[16].code, expected 72, is {}", + msg.biases[16].code + ); + assert_eq!( + msg.biases[16].discontinuity_counter, 140, + "incorrect value for biases[16].discontinuity_counter, expected 140, is {}", + msg.biases[16].discontinuity_counter + ); + assert_eq!( + msg.biases[16].integer_indicator, 136, + "incorrect value for biases[16].integer_indicator, expected 136, is {}", + msg.biases[16].integer_indicator + ); + assert_eq!(msg.biases[16].widelane_integer_indicator, 240, "incorrect value for biases[16].widelane_integer_indicator, expected 240, is {}", msg.biases[16].widelane_integer_indicator); + assert_eq!( + msg.biases[17].bias, 60257151, + "incorrect value for biases[17].bias, expected 60257151, is {}", + msg.biases[17].bias + ); + assert_eq!( + msg.biases[17].code, 151, + "incorrect value for biases[17].code, expected 151, is {}", + msg.biases[17].code + ); + assert_eq!( + msg.biases[17].discontinuity_counter, 210, + "incorrect value for biases[17].discontinuity_counter, expected 210, is {}", + msg.biases[17].discontinuity_counter + ); + assert_eq!( + msg.biases[17].integer_indicator, 150, + "incorrect value for biases[17].integer_indicator, expected 150, is {}", + msg.biases[17].integer_indicator + ); + assert_eq!( + msg.biases[17].widelane_integer_indicator, 17, + "incorrect value for biases[17].widelane_integer_indicator, expected 17, is {}", + msg.biases[17].widelane_integer_indicator + ); + assert_eq!( + msg.biases[18].bias, 41820677, + "incorrect value for biases[18].bias, expected 41820677, is {}", + msg.biases[18].bias + ); + assert_eq!( + msg.biases[18].code, 242, + "incorrect value for biases[18].code, expected 242, is {}", + msg.biases[18].code + ); + assert_eq!( + msg.biases[18].discontinuity_counter, 14, + "incorrect value for biases[18].discontinuity_counter, expected 14, is {}", + msg.biases[18].discontinuity_counter + ); + assert_eq!( + msg.biases[18].integer_indicator, 254, + "incorrect value for biases[18].integer_indicator, expected 254, is {}", + msg.biases[18].integer_indicator + ); + assert_eq!(msg.biases[18].widelane_integer_indicator, 215, "incorrect value for biases[18].widelane_integer_indicator, expected 215, is {}", msg.biases[18].widelane_integer_indicator); + assert_eq!( + msg.biases[19].bias, 1640616471, + "incorrect value for biases[19].bias, expected 1640616471, is {}", + msg.biases[19].bias + ); + assert_eq!( + msg.biases[19].code, 215, + "incorrect value for biases[19].code, expected 215, is {}", + msg.biases[19].code + ); + assert_eq!( + msg.biases[19].discontinuity_counter, 176, + "incorrect value for biases[19].discontinuity_counter, expected 176, is {}", + msg.biases[19].discontinuity_counter + ); + assert_eq!( + msg.biases[19].integer_indicator, 65, + "incorrect value for biases[19].integer_indicator, expected 65, is {}", + msg.biases[19].integer_indicator + ); + assert_eq!( + msg.biases[19].widelane_integer_indicator, 38, + "incorrect value for biases[19].widelane_integer_indicator, expected 38, is {}", + msg.biases[19].widelane_integer_indicator + ); + assert_eq!( + msg.biases[20].bias, -744786918, + "incorrect value for biases[20].bias, expected -744786918, is {}", + msg.biases[20].bias + ); + assert_eq!( + msg.biases[20].code, 36, + "incorrect value for biases[20].code, expected 36, is {}", + msg.biases[20].code + ); + assert_eq!( + msg.biases[20].discontinuity_counter, 224, + "incorrect value for biases[20].discontinuity_counter, expected 224, is {}", + msg.biases[20].discontinuity_counter + ); + assert_eq!( + msg.biases[20].integer_indicator, 207, + "incorrect value for biases[20].integer_indicator, expected 207, is {}", + msg.biases[20].integer_indicator + ); + assert_eq!( + msg.biases[20].widelane_integer_indicator, 92, + "incorrect value for biases[20].widelane_integer_indicator, expected 92, is {}", + msg.biases[20].widelane_integer_indicator + ); + assert_eq!( + msg.biases[21].bias, 1966589763, + "incorrect value for biases[21].bias, expected 1966589763, is {}", + msg.biases[21].bias + ); + assert_eq!( + msg.biases[21].code, 165, + "incorrect value for biases[21].code, expected 165, is {}", + msg.biases[21].code + ); + assert_eq!( + msg.biases[21].discontinuity_counter, 38, + "incorrect value for biases[21].discontinuity_counter, expected 38, is {}", + msg.biases[21].discontinuity_counter + ); + assert_eq!( + msg.biases[21].integer_indicator, 47, + "incorrect value for biases[21].integer_indicator, expected 47, is {}", + msg.biases[21].integer_indicator + ); + assert_eq!(msg.biases[21].widelane_integer_indicator, 102, "incorrect value for biases[21].widelane_integer_indicator, expected 102, is {}", msg.biases[21].widelane_integer_indicator); + assert_eq!( + msg.biases[22].bias, 364366310, + "incorrect value for biases[22].bias, expected 364366310, is {}", + msg.biases[22].bias + ); + assert_eq!( + msg.biases[22].code, 36, + "incorrect value for biases[22].code, expected 36, is {}", + msg.biases[22].code + ); + assert_eq!( + msg.biases[22].discontinuity_counter, 1, + "incorrect value for biases[22].discontinuity_counter, expected 1, is {}", + msg.biases[22].discontinuity_counter + ); + assert_eq!( + msg.biases[22].integer_indicator, 169, + "incorrect value for biases[22].integer_indicator, expected 169, is {}", + msg.biases[22].integer_indicator + ); + assert_eq!( + msg.biases[22].widelane_integer_indicator, 33, + "incorrect value for biases[22].widelane_integer_indicator, expected 33, is {}", + msg.biases[22].widelane_integer_indicator + ); + assert_eq!( + msg.biases[23].bias, -1839031379, + "incorrect value for biases[23].bias, expected -1839031379, is {}", + msg.biases[23].bias + ); + assert_eq!( + msg.biases[23].code, 42, + "incorrect value for biases[23].code, expected 42, is {}", + msg.biases[23].code + ); + assert_eq!( + msg.biases[23].discontinuity_counter, 173, + "incorrect value for biases[23].discontinuity_counter, expected 173, is {}", + msg.biases[23].discontinuity_counter + ); + assert_eq!( + msg.biases[23].integer_indicator, 62, + "incorrect value for biases[23].integer_indicator, expected 62, is {}", + msg.biases[23].integer_indicator + ); + assert_eq!(msg.biases[23].widelane_integer_indicator, 147, "incorrect value for biases[23].widelane_integer_indicator, expected 147, is {}", msg.biases[23].widelane_integer_indicator); + assert_eq!( + msg.biases[24].bias, 31817639, + "incorrect value for biases[24].bias, expected 31817639, is {}", + msg.biases[24].bias + ); + assert_eq!( + msg.biases[24].code, 231, + "incorrect value for biases[24].code, expected 231, is {}", + msg.biases[24].code + ); + assert_eq!( + msg.biases[24].discontinuity_counter, 82, + "incorrect value for biases[24].discontinuity_counter, expected 82, is {}", + msg.biases[24].discontinuity_counter + ); + assert_eq!( + msg.biases[24].integer_indicator, 167, + "incorrect value for biases[24].integer_indicator, expected 167, is {}", + msg.biases[24].integer_indicator + ); + assert_eq!(msg.biases[24].widelane_integer_indicator, 138, "incorrect value for biases[24].widelane_integer_indicator, expected 138, is {}", msg.biases[24].widelane_integer_indicator); + assert_eq!( + msg.biases[25].bias, -1619830156, + "incorrect value for biases[25].bias, expected -1619830156, is {}", + msg.biases[25].bias + ); + assert_eq!( + msg.biases[25].code, 2, + "incorrect value for biases[25].code, expected 2, is {}", + msg.biases[25].code + ); + assert_eq!( + msg.biases[25].discontinuity_counter, 207, + "incorrect value for biases[25].discontinuity_counter, expected 207, is {}", + msg.biases[25].discontinuity_counter + ); + assert_eq!( + msg.biases[25].integer_indicator, 127, + "incorrect value for biases[25].integer_indicator, expected 127, is {}", + msg.biases[25].integer_indicator + ); + assert_eq!(msg.biases[25].widelane_integer_indicator, 237, "incorrect value for biases[25].widelane_integer_indicator, expected 237, is {}", msg.biases[25].widelane_integer_indicator); + assert_eq!( + msg.biases[26].bias, -83375622, + "incorrect value for biases[26].bias, expected -83375622, is {}", + msg.biases[26].bias + ); + assert_eq!( + msg.biases[26].code, 3, + "incorrect value for biases[26].code, expected 3, is {}", + msg.biases[26].code + ); + assert_eq!( + msg.biases[26].discontinuity_counter, 145, + "incorrect value for biases[26].discontinuity_counter, expected 145, is {}", + msg.biases[26].discontinuity_counter + ); + assert_eq!( + msg.biases[26].integer_indicator, 42, + "incorrect value for biases[26].integer_indicator, expected 42, is {}", + msg.biases[26].integer_indicator + ); + assert_eq!( + msg.biases[26].widelane_integer_indicator, 66, + "incorrect value for biases[26].widelane_integer_indicator, expected 66, is {}", + msg.biases[26].widelane_integer_indicator + ); + assert_eq!( + msg.biases[27].bias, 1077458389, + "incorrect value for biases[27].bias, expected 1077458389, is {}", + msg.biases[27].bias + ); + assert_eq!( + msg.biases[27].code, 2, + "incorrect value for biases[27].code, expected 2, is {}", + msg.biases[27].code + ); + assert_eq!( + msg.biases[27].discontinuity_counter, 26, + "incorrect value for biases[27].discontinuity_counter, expected 26, is {}", + msg.biases[27].discontinuity_counter + ); + assert_eq!( + msg.biases[27].integer_indicator, 75, + "incorrect value for biases[27].integer_indicator, expected 75, is {}", + msg.biases[27].integer_indicator + ); + assert_eq!(msg.biases[27].widelane_integer_indicator, 230, "incorrect value for biases[27].widelane_integer_indicator, expected 230, is {}", msg.biases[27].widelane_integer_indicator); + assert_eq!( + msg.biases[28].bias, -883355501, + "incorrect value for biases[28].bias, expected -883355501, is {}", + msg.biases[28].bias + ); + assert_eq!( + msg.biases[28].code, 97, + "incorrect value for biases[28].code, expected 97, is {}", + msg.biases[28].code + ); + assert_eq!( + msg.biases[28].discontinuity_counter, 6, + "incorrect value for biases[28].discontinuity_counter, expected 6, is {}", + msg.biases[28].discontinuity_counter + ); + assert_eq!( + msg.biases[28].integer_indicator, 88, + "incorrect value for biases[28].integer_indicator, expected 88, is {}", + msg.biases[28].integer_indicator + ); + assert_eq!(msg.biases[28].widelane_integer_indicator, 255, "incorrect value for biases[28].widelane_integer_indicator, expected 255, is {}", msg.biases[28].widelane_integer_indicator); + assert_eq!( + msg.biases[29].bias, -1448611273, + "incorrect value for biases[29].bias, expected -1448611273, is {}", + msg.biases[29].bias + ); + assert_eq!( + msg.biases[29].code, 27, + "incorrect value for biases[29].code, expected 27, is {}", + msg.biases[29].code + ); + assert_eq!( + msg.biases[29].discontinuity_counter, 230, + "incorrect value for biases[29].discontinuity_counter, expected 230, is {}", + msg.biases[29].discontinuity_counter + ); + assert_eq!( + msg.biases[29].integer_indicator, 68, + "incorrect value for biases[29].integer_indicator, expected 68, is {}", + msg.biases[29].integer_indicator + ); + assert_eq!(msg.biases[29].widelane_integer_indicator, 243, "incorrect value for biases[29].widelane_integer_indicator, expected 243, is {}", msg.biases[29].widelane_integer_indicator); + assert_eq!( + msg.dispersive_bias, 98, + "incorrect value for dispersive_bias, expected 98, is {}", + msg.dispersive_bias + ); + assert_eq!( + msg.iod_ssr, 230, + "incorrect value for iod_ssr, expected 230, is {}", + msg.iod_ssr + ); + assert_eq!( + msg.mw_consistency, 209, + "incorrect value for mw_consistency, expected 209, is {}", + msg.mw_consistency + ); + assert_eq!( + msg.sid.code, 82, + "incorrect value for sid.code, expected 82, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 169, + "incorrect value for sid.sat, expected 169, is {}", + msg.sid.sat + ); + assert_eq!( + msg.time.tow, 210803409, + "incorrect value for time.tow, expected 210803409, is {}", + msg.time.tow + ); + assert_eq!( + msg.time.wn, 42197, + "incorrect value for time.wn, expected 42197, is {}", + msg.time.wn + ); + assert_eq!( + msg.update_interval, 177, + "incorrect value for update_interval, expected 177, is {}", + msg.update_interval + ); + assert_eq!( + msg.yaw, 5881, + "incorrect value for yaw, expected 5881, is {}", + msg.yaw + ); + assert_eq!( + msg.yaw_rate, 17, + "incorrect value for yaw_rate, expected 17, is {}", + msg.yaw_rate + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrPhaseBiases"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a.rs new file mode 100644 index 0000000000..6b534565c7 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a.rs @@ -0,0 +1,3131 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, 214, 212, 4, 8, 33, 31, 80, + 21, 4, 105, 225, 39, 139, 124, 149, 48, 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, + 49, 135, 97, 39, 90, 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, 2, 102, 74, + 149, 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, 83, 188, 181, 194, 27, 84, 226, + 142, 123, 77, 217, 248, 67, 215, 129, 114, 138, 25, 240, 10, 56, 76, 61, 161, 216, 22, + 181, 174, 33, 13, 252, 236, 230, 196, 128, 215, 239, 234, 179, 220, 44, 212, 57, 44, + 173, 49, 36, 137, 248, 235, 97, 112, 157, 139, 26, 115, 192, 31, 85, 127, 228, 81, 252, + 219, 249, 110, 147, 8, 161, 215, 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, 74, 23, + 4, 239, 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, 99, 45, 83, 159, 11, 250, + 135, 170, 42, 217, 199, 233, 42, 170, 78, 206, 41, 43, 81, 247, 99, 198, 144, 2, 132, + 2, 224, 220, 148, 58, 85, 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, + 37, 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, 119, 101, 252, 223, + 144, 153, 50, 13, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrSatelliteApcDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x604, + "Incorrect message type, expected 0x604, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1338, + "incorrect sender id, expected 0x1338, is {sender_id}" + ); + assert_eq!( + msg.apc[0].pco[0], -21547, + "incorrect value for apc[0].pco[0], expected -21547, is {}", + msg.apc[0].pco[0] + ); + assert_eq!( + msg.apc[0].pco[1], -10498, + "incorrect value for apc[0].pco[1], expected -10498, is {}", + msg.apc[0].pco[1] + ); + assert_eq!( + msg.apc[0].pco[2], 1236, + "incorrect value for apc[0].pco[2], expected 1236, is {}", + msg.apc[0].pco[2] + ); + assert_eq!( + msg.apc[0].pcv[0], 8, + "incorrect value for apc[0].pcv[0], expected 8, is {}", + msg.apc[0].pcv[0] + ); + assert_eq!( + msg.apc[0].pcv[1], 33, + "incorrect value for apc[0].pcv[1], expected 33, is {}", + msg.apc[0].pcv[1] + ); + assert_eq!( + msg.apc[0].pcv[2], 31, + "incorrect value for apc[0].pcv[2], expected 31, is {}", + msg.apc[0].pcv[2] + ); + assert_eq!( + msg.apc[0].pcv[3], 80, + "incorrect value for apc[0].pcv[3], expected 80, is {}", + msg.apc[0].pcv[3] + ); + assert_eq!( + msg.apc[0].pcv[4], 21, + "incorrect value for apc[0].pcv[4], expected 21, is {}", + msg.apc[0].pcv[4] + ); + assert_eq!( + msg.apc[0].pcv[5], 4, + "incorrect value for apc[0].pcv[5], expected 4, is {}", + msg.apc[0].pcv[5] + ); + assert_eq!( + msg.apc[0].pcv[6], 105, + "incorrect value for apc[0].pcv[6], expected 105, is {}", + msg.apc[0].pcv[6] + ); + assert_eq!( + msg.apc[0].pcv[7], -31, + "incorrect value for apc[0].pcv[7], expected -31, is {}", + msg.apc[0].pcv[7] + ); + assert_eq!( + msg.apc[0].pcv[8], 39, + "incorrect value for apc[0].pcv[8], expected 39, is {}", + msg.apc[0].pcv[8] + ); + assert_eq!( + msg.apc[0].pcv[9], -117, + "incorrect value for apc[0].pcv[9], expected -117, is {}", + msg.apc[0].pcv[9] + ); + assert_eq!( + msg.apc[0].pcv[10], 124, + "incorrect value for apc[0].pcv[10], expected 124, is {}", + msg.apc[0].pcv[10] + ); + assert_eq!( + msg.apc[0].pcv[11], -107, + "incorrect value for apc[0].pcv[11], expected -107, is {}", + msg.apc[0].pcv[11] + ); + assert_eq!( + msg.apc[0].pcv[12], 48, + "incorrect value for apc[0].pcv[12], expected 48, is {}", + msg.apc[0].pcv[12] + ); + assert_eq!( + msg.apc[0].pcv[13], 15, + "incorrect value for apc[0].pcv[13], expected 15, is {}", + msg.apc[0].pcv[13] + ); + assert_eq!( + msg.apc[0].pcv[14], -42, + "incorrect value for apc[0].pcv[14], expected -42, is {}", + msg.apc[0].pcv[14] + ); + assert_eq!( + msg.apc[0].pcv[15], -59, + "incorrect value for apc[0].pcv[15], expected -59, is {}", + msg.apc[0].pcv[15] + ); + assert_eq!( + msg.apc[0].pcv[16], -115, + "incorrect value for apc[0].pcv[16], expected -115, is {}", + msg.apc[0].pcv[16] + ); + assert_eq!( + msg.apc[0].pcv[17], 32, + "incorrect value for apc[0].pcv[17], expected 32, is {}", + msg.apc[0].pcv[17] + ); + assert_eq!( + msg.apc[0].pcv[18], 33, + "incorrect value for apc[0].pcv[18], expected 33, is {}", + msg.apc[0].pcv[18] + ); + assert_eq!( + msg.apc[0].pcv[19], -121, + "incorrect value for apc[0].pcv[19], expected -121, is {}", + msg.apc[0].pcv[19] + ); + assert_eq!( + msg.apc[0].pcv[20], -106, + "incorrect value for apc[0].pcv[20], expected -106, is {}", + msg.apc[0].pcv[20] + ); + assert_eq!( + msg.apc[0].sat_info, 240, + "incorrect value for apc[0].sat_info, expected 240, is {}", + msg.apc[0].sat_info + ); + assert_eq!( + msg.apc[0].sid.code, 169, + "incorrect value for apc[0].sid.code, expected 169, is {}", + msg.apc[0].sid.code + ); + assert_eq!( + msg.apc[0].sid.sat, 203, + "incorrect value for apc[0].sid.sat, expected 203, is {}", + msg.apc[0].sid.sat + ); + assert_eq!( + msg.apc[0].svn, 1102, + "incorrect value for apc[0].svn, expected 1102, is {}", + msg.apc[0].svn + ); + assert_eq!( + msg.apc[1].pco[0], 23079, + "incorrect value for apc[1].pco[0], expected 23079, is {}", + msg.apc[1].pco[0] + ); + assert_eq!( + msg.apc[1].pco[1], -22252, + "incorrect value for apc[1].pco[1], expected -22252, is {}", + msg.apc[1].pco[1] + ); + assert_eq!( + msg.apc[1].pco[2], 12271, + "incorrect value for apc[1].pco[2], expected 12271, is {}", + msg.apc[1].pco[2] + ); + assert_eq!( + msg.apc[1].pcv[0], -103, + "incorrect value for apc[1].pcv[0], expected -103, is {}", + msg.apc[1].pcv[0] + ); + assert_eq!( + msg.apc[1].pcv[1], -81, + "incorrect value for apc[1].pcv[1], expected -81, is {}", + msg.apc[1].pcv[1] + ); + assert_eq!( + msg.apc[1].pcv[2], 35, + "incorrect value for apc[1].pcv[2], expected 35, is {}", + msg.apc[1].pcv[2] + ); + assert_eq!( + msg.apc[1].pcv[3], -111, + "incorrect value for apc[1].pcv[3], expected -111, is {}", + msg.apc[1].pcv[3] + ); + assert_eq!( + msg.apc[1].pcv[4], -111, + "incorrect value for apc[1].pcv[4], expected -111, is {}", + msg.apc[1].pcv[4] + ); + assert_eq!( + msg.apc[1].pcv[5], 123, + "incorrect value for apc[1].pcv[5], expected 123, is {}", + msg.apc[1].pcv[5] + ); + assert_eq!( + msg.apc[1].pcv[6], -62, + "incorrect value for apc[1].pcv[6], expected -62, is {}", + msg.apc[1].pcv[6] + ); + assert_eq!( + msg.apc[1].pcv[7], 2, + "incorrect value for apc[1].pcv[7], expected 2, is {}", + msg.apc[1].pcv[7] + ); + assert_eq!( + msg.apc[1].pcv[8], 102, + "incorrect value for apc[1].pcv[8], expected 102, is {}", + msg.apc[1].pcv[8] + ); + assert_eq!( + msg.apc[1].pcv[9], 74, + "incorrect value for apc[1].pcv[9], expected 74, is {}", + msg.apc[1].pcv[9] + ); + assert_eq!( + msg.apc[1].pcv[10], -107, + "incorrect value for apc[1].pcv[10], expected -107, is {}", + msg.apc[1].pcv[10] + ); + assert_eq!( + msg.apc[1].pcv[11], 95, + "incorrect value for apc[1].pcv[11], expected 95, is {}", + msg.apc[1].pcv[11] + ); + assert_eq!( + msg.apc[1].pcv[12], -85, + "incorrect value for apc[1].pcv[12], expected -85, is {}", + msg.apc[1].pcv[12] + ); + assert_eq!( + msg.apc[1].pcv[13], -18, + "incorrect value for apc[1].pcv[13], expected -18, is {}", + msg.apc[1].pcv[13] + ); + assert_eq!( + msg.apc[1].pcv[14], -7, + "incorrect value for apc[1].pcv[14], expected -7, is {}", + msg.apc[1].pcv[14] + ); + assert_eq!( + msg.apc[1].pcv[15], 7, + "incorrect value for apc[1].pcv[15], expected 7, is {}", + msg.apc[1].pcv[15] + ); + assert_eq!( + msg.apc[1].pcv[16], -19, + "incorrect value for apc[1].pcv[16], expected -19, is {}", + msg.apc[1].pcv[16] + ); + assert_eq!( + msg.apc[1].pcv[17], -86, + "incorrect value for apc[1].pcv[17], expected -86, is {}", + msg.apc[1].pcv[17] + ); + assert_eq!( + msg.apc[1].pcv[18], 125, + "incorrect value for apc[1].pcv[18], expected 125, is {}", + msg.apc[1].pcv[18] + ); + assert_eq!( + msg.apc[1].pcv[19], 106, + "incorrect value for apc[1].pcv[19], expected 106, is {}", + msg.apc[1].pcv[19] + ); + assert_eq!( + msg.apc[1].pcv[20], -98, + "incorrect value for apc[1].pcv[20], expected -98, is {}", + msg.apc[1].pcv[20] + ); + assert_eq!( + msg.apc[1].sat_info, 49, + "incorrect value for apc[1].sat_info, expected 49, is {}", + msg.apc[1].sat_info + ); + assert_eq!( + msg.apc[1].sid.code, 123, + "incorrect value for apc[1].sid.code, expected 123, is {}", + msg.apc[1].sid.code + ); + assert_eq!( + msg.apc[1].sid.sat, 148, + "incorrect value for apc[1].sid.sat, expected 148, is {}", + msg.apc[1].sid.sat + ); + assert_eq!( + msg.apc[1].svn, 24967, + "incorrect value for apc[1].svn, expected 24967, is {}", + msg.apc[1].svn + ); + assert_eq!( + msg.apc[2].pco[0], -7596, + "incorrect value for apc[2].pco[0], expected -7596, is {}", + msg.apc[2].pco[0] + ); + assert_eq!( + msg.apc[2].pco[1], 31630, + "incorrect value for apc[2].pco[1], expected 31630, is {}", + msg.apc[2].pco[1] + ); + assert_eq!( + msg.apc[2].pco[2], -9907, + "incorrect value for apc[2].pco[2], expected -9907, is {}", + msg.apc[2].pco[2] + ); + assert_eq!( + msg.apc[2].pcv[0], -8, + "incorrect value for apc[2].pcv[0], expected -8, is {}", + msg.apc[2].pcv[0] + ); + assert_eq!( + msg.apc[2].pcv[1], 67, + "incorrect value for apc[2].pcv[1], expected 67, is {}", + msg.apc[2].pcv[1] + ); + assert_eq!( + msg.apc[2].pcv[2], -41, + "incorrect value for apc[2].pcv[2], expected -41, is {}", + msg.apc[2].pcv[2] + ); + assert_eq!( + msg.apc[2].pcv[3], -127, + "incorrect value for apc[2].pcv[3], expected -127, is {}", + msg.apc[2].pcv[3] + ); + assert_eq!( + msg.apc[2].pcv[4], 114, + "incorrect value for apc[2].pcv[4], expected 114, is {}", + msg.apc[2].pcv[4] + ); + assert_eq!( + msg.apc[2].pcv[5], -118, + "incorrect value for apc[2].pcv[5], expected -118, is {}", + msg.apc[2].pcv[5] + ); + assert_eq!( + msg.apc[2].pcv[6], 25, + "incorrect value for apc[2].pcv[6], expected 25, is {}", + msg.apc[2].pcv[6] + ); + assert_eq!( + msg.apc[2].pcv[7], -16, + "incorrect value for apc[2].pcv[7], expected -16, is {}", + msg.apc[2].pcv[7] + ); + assert_eq!( + msg.apc[2].pcv[8], 10, + "incorrect value for apc[2].pcv[8], expected 10, is {}", + msg.apc[2].pcv[8] + ); + assert_eq!( + msg.apc[2].pcv[9], 56, + "incorrect value for apc[2].pcv[9], expected 56, is {}", + msg.apc[2].pcv[9] + ); + assert_eq!( + msg.apc[2].pcv[10], 76, + "incorrect value for apc[2].pcv[10], expected 76, is {}", + msg.apc[2].pcv[10] + ); + assert_eq!( + msg.apc[2].pcv[11], 61, + "incorrect value for apc[2].pcv[11], expected 61, is {}", + msg.apc[2].pcv[11] + ); + assert_eq!( + msg.apc[2].pcv[12], -95, + "incorrect value for apc[2].pcv[12], expected -95, is {}", + msg.apc[2].pcv[12] + ); + assert_eq!( + msg.apc[2].pcv[13], -40, + "incorrect value for apc[2].pcv[13], expected -40, is {}", + msg.apc[2].pcv[13] + ); + assert_eq!( + msg.apc[2].pcv[14], 22, + "incorrect value for apc[2].pcv[14], expected 22, is {}", + msg.apc[2].pcv[14] + ); + assert_eq!( + msg.apc[2].pcv[15], -75, + "incorrect value for apc[2].pcv[15], expected -75, is {}", + msg.apc[2].pcv[15] + ); + assert_eq!( + msg.apc[2].pcv[16], -82, + "incorrect value for apc[2].pcv[16], expected -82, is {}", + msg.apc[2].pcv[16] + ); + assert_eq!( + msg.apc[2].pcv[17], 33, + "incorrect value for apc[2].pcv[17], expected 33, is {}", + msg.apc[2].pcv[17] + ); + assert_eq!( + msg.apc[2].pcv[18], 13, + "incorrect value for apc[2].pcv[18], expected 13, is {}", + msg.apc[2].pcv[18] + ); + assert_eq!( + msg.apc[2].pcv[19], -4, + "incorrect value for apc[2].pcv[19], expected -4, is {}", + msg.apc[2].pcv[19] + ); + assert_eq!( + msg.apc[2].pcv[20], -20, + "incorrect value for apc[2].pcv[20], expected -20, is {}", + msg.apc[2].pcv[20] + ); + assert_eq!( + msg.apc[2].sat_info, 181, + "incorrect value for apc[2].sat_info, expected 181, is {}", + msg.apc[2].sat_info + ); + assert_eq!( + msg.apc[2].sid.code, 188, + "incorrect value for apc[2].sid.code, expected 188, is {}", + msg.apc[2].sid.code + ); + assert_eq!( + msg.apc[2].sid.sat, 83, + "incorrect value for apc[2].sid.sat, expected 83, is {}", + msg.apc[2].sid.sat + ); + assert_eq!( + msg.apc[2].svn, 7106, + "incorrect value for apc[2].svn, expected 7106, is {}", + msg.apc[2].svn + ); + assert_eq!( + msg.apc[3].pco[0], -19478, + "incorrect value for apc[3].pco[0], expected -19478, is {}", + msg.apc[3].pco[0] + ); + assert_eq!( + msg.apc[3].pco[1], 11484, + "incorrect value for apc[3].pco[1], expected 11484, is {}", + msg.apc[3].pco[1] + ); + assert_eq!( + msg.apc[3].pco[2], 14804, + "incorrect value for apc[3].pco[2], expected 14804, is {}", + msg.apc[3].pco[2] + ); + assert_eq!( + msg.apc[3].pcv[0], 44, + "incorrect value for apc[3].pcv[0], expected 44, is {}", + msg.apc[3].pcv[0] + ); + assert_eq!( + msg.apc[3].pcv[1], -83, + "incorrect value for apc[3].pcv[1], expected -83, is {}", + msg.apc[3].pcv[1] + ); + assert_eq!( + msg.apc[3].pcv[2], 49, + "incorrect value for apc[3].pcv[2], expected 49, is {}", + msg.apc[3].pcv[2] + ); + assert_eq!( + msg.apc[3].pcv[3], 36, + "incorrect value for apc[3].pcv[3], expected 36, is {}", + msg.apc[3].pcv[3] + ); + assert_eq!( + msg.apc[3].pcv[4], -119, + "incorrect value for apc[3].pcv[4], expected -119, is {}", + msg.apc[3].pcv[4] + ); + assert_eq!( + msg.apc[3].pcv[5], -8, + "incorrect value for apc[3].pcv[5], expected -8, is {}", + msg.apc[3].pcv[5] + ); + assert_eq!( + msg.apc[3].pcv[6], -21, + "incorrect value for apc[3].pcv[6], expected -21, is {}", + msg.apc[3].pcv[6] + ); + assert_eq!( + msg.apc[3].pcv[7], 97, + "incorrect value for apc[3].pcv[7], expected 97, is {}", + msg.apc[3].pcv[7] + ); + assert_eq!( + msg.apc[3].pcv[8], 112, + "incorrect value for apc[3].pcv[8], expected 112, is {}", + msg.apc[3].pcv[8] + ); + assert_eq!( + msg.apc[3].pcv[9], -99, + "incorrect value for apc[3].pcv[9], expected -99, is {}", + msg.apc[3].pcv[9] + ); + assert_eq!( + msg.apc[3].pcv[10], -117, + "incorrect value for apc[3].pcv[10], expected -117, is {}", + msg.apc[3].pcv[10] + ); + assert_eq!( + msg.apc[3].pcv[11], 26, + "incorrect value for apc[3].pcv[11], expected 26, is {}", + msg.apc[3].pcv[11] + ); + assert_eq!( + msg.apc[3].pcv[12], 115, + "incorrect value for apc[3].pcv[12], expected 115, is {}", + msg.apc[3].pcv[12] + ); + assert_eq!( + msg.apc[3].pcv[13], -64, + "incorrect value for apc[3].pcv[13], expected -64, is {}", + msg.apc[3].pcv[13] + ); + assert_eq!( + msg.apc[3].pcv[14], 31, + "incorrect value for apc[3].pcv[14], expected 31, is {}", + msg.apc[3].pcv[14] + ); + assert_eq!( + msg.apc[3].pcv[15], 85, + "incorrect value for apc[3].pcv[15], expected 85, is {}", + msg.apc[3].pcv[15] + ); + assert_eq!( + msg.apc[3].pcv[16], 127, + "incorrect value for apc[3].pcv[16], expected 127, is {}", + msg.apc[3].pcv[16] + ); + assert_eq!( + msg.apc[3].pcv[17], -28, + "incorrect value for apc[3].pcv[17], expected -28, is {}", + msg.apc[3].pcv[17] + ); + assert_eq!( + msg.apc[3].pcv[18], 81, + "incorrect value for apc[3].pcv[18], expected 81, is {}", + msg.apc[3].pcv[18] + ); + assert_eq!( + msg.apc[3].pcv[19], -4, + "incorrect value for apc[3].pcv[19], expected -4, is {}", + msg.apc[3].pcv[19] + ); + assert_eq!( + msg.apc[3].pcv[20], -37, + "incorrect value for apc[3].pcv[20], expected -37, is {}", + msg.apc[3].pcv[20] + ); + assert_eq!( + msg.apc[3].sat_info, 128, + "incorrect value for apc[3].sat_info, expected 128, is {}", + msg.apc[3].sat_info + ); + assert_eq!( + msg.apc[3].sid.code, 196, + "incorrect value for apc[3].sid.code, expected 196, is {}", + msg.apc[3].sid.code + ); + assert_eq!( + msg.apc[3].sid.sat, 230, + "incorrect value for apc[3].sid.sat, expected 230, is {}", + msg.apc[3].sid.sat + ); + assert_eq!( + msg.apc[3].svn, 61399, + "incorrect value for apc[3].svn, expected 61399, is {}", + msg.apc[3].svn + ); + assert_eq!( + msg.apc[4].pco[0], -11049, + "incorrect value for apc[4].pco[0], expected -11049, is {}", + msg.apc[4].pco[0] + ); + assert_eq!( + msg.apc[4].pco[1], 6580, + "incorrect value for apc[4].pco[1], expected 6580, is {}", + msg.apc[4].pco[1] + ); + assert_eq!( + msg.apc[4].pco[2], -28589, + "incorrect value for apc[4].pco[2], expected -28589, is {}", + msg.apc[4].pco[2] + ); + assert_eq!( + msg.apc[4].pcv[0], -9, + "incorrect value for apc[4].pcv[0], expected -9, is {}", + msg.apc[4].pcv[0] + ); + assert_eq!( + msg.apc[4].pcv[1], 12, + "incorrect value for apc[4].pcv[1], expected 12, is {}", + msg.apc[4].pcv[1] + ); + assert_eq!( + msg.apc[4].pcv[2], 27, + "incorrect value for apc[4].pcv[2], expected 27, is {}", + msg.apc[4].pcv[2] + ); + assert_eq!( + msg.apc[4].pcv[3], -57, + "incorrect value for apc[4].pcv[3], expected -57, is {}", + msg.apc[4].pcv[3] + ); + assert_eq!( + msg.apc[4].pcv[4], -83, + "incorrect value for apc[4].pcv[4], expected -83, is {}", + msg.apc[4].pcv[4] + ); + assert_eq!( + msg.apc[4].pcv[5], 74, + "incorrect value for apc[4].pcv[5], expected 74, is {}", + msg.apc[4].pcv[5] + ); + assert_eq!( + msg.apc[4].pcv[6], 23, + "incorrect value for apc[4].pcv[6], expected 23, is {}", + msg.apc[4].pcv[6] + ); + assert_eq!( + msg.apc[4].pcv[7], 4, + "incorrect value for apc[4].pcv[7], expected 4, is {}", + msg.apc[4].pcv[7] + ); + assert_eq!( + msg.apc[4].pcv[8], -17, + "incorrect value for apc[4].pcv[8], expected -17, is {}", + msg.apc[4].pcv[8] + ); + assert_eq!( + msg.apc[4].pcv[9], 103, + "incorrect value for apc[4].pcv[9], expected 103, is {}", + msg.apc[4].pcv[9] + ); + assert_eq!( + msg.apc[4].pcv[10], -33, + "incorrect value for apc[4].pcv[10], expected -33, is {}", + msg.apc[4].pcv[10] + ); + assert_eq!( + msg.apc[4].pcv[11], -36, + "incorrect value for apc[4].pcv[11], expected -36, is {}", + msg.apc[4].pcv[11] + ); + assert_eq!( + msg.apc[4].pcv[12], -117, + "incorrect value for apc[4].pcv[12], expected -117, is {}", + msg.apc[4].pcv[12] + ); + assert_eq!( + msg.apc[4].pcv[13], 91, + "incorrect value for apc[4].pcv[13], expected 91, is {}", + msg.apc[4].pcv[13] + ); + assert_eq!( + msg.apc[4].pcv[14], 127, + "incorrect value for apc[4].pcv[14], expected 127, is {}", + msg.apc[4].pcv[14] + ); + assert_eq!( + msg.apc[4].pcv[15], -42, + "incorrect value for apc[4].pcv[15], expected -42, is {}", + msg.apc[4].pcv[15] + ); + assert_eq!( + msg.apc[4].pcv[16], 86, + "incorrect value for apc[4].pcv[16], expected 86, is {}", + msg.apc[4].pcv[16] + ); + assert_eq!( + msg.apc[4].pcv[17], 48, + "incorrect value for apc[4].pcv[17], expected 48, is {}", + msg.apc[4].pcv[17] + ); + assert_eq!( + msg.apc[4].pcv[18], -53, + "incorrect value for apc[4].pcv[18], expected -53, is {}", + msg.apc[4].pcv[18] + ); + assert_eq!( + msg.apc[4].pcv[19], -28, + "incorrect value for apc[4].pcv[19], expected -28, is {}", + msg.apc[4].pcv[19] + ); + assert_eq!( + msg.apc[4].pcv[20], 99, + "incorrect value for apc[4].pcv[20], expected 99, is {}", + msg.apc[4].pcv[20] + ); + assert_eq!( + msg.apc[4].sat_info, 147, + "incorrect value for apc[4].sat_info, expected 147, is {}", + msg.apc[4].sat_info + ); + assert_eq!( + msg.apc[4].sid.code, 110, + "incorrect value for apc[4].sid.code, expected 110, is {}", + msg.apc[4].sid.code + ); + assert_eq!( + msg.apc[4].sid.sat, 249, + "incorrect value for apc[4].sid.sat, expected 249, is {}", + msg.apc[4].sid.sat + ); + assert_eq!( + msg.apc[4].svn, 41224, + "incorrect value for apc[4].svn, expected 41224, is {}", + msg.apc[4].svn + ); + assert_eq!( + msg.apc[5].pco[0], -21881, + "incorrect value for apc[5].pco[0], expected -21881, is {}", + msg.apc[5].pco[0] + ); + assert_eq!( + msg.apc[5].pco[1], -9942, + "incorrect value for apc[5].pco[1], expected -9942, is {}", + msg.apc[5].pco[1] + ); + assert_eq!( + msg.apc[5].pco[2], -5689, + "incorrect value for apc[5].pco[2], expected -5689, is {}", + msg.apc[5].pco[2] + ); + assert_eq!( + msg.apc[5].pcv[0], 42, + "incorrect value for apc[5].pcv[0], expected 42, is {}", + msg.apc[5].pcv[0] + ); + assert_eq!( + msg.apc[5].pcv[1], -86, + "incorrect value for apc[5].pcv[1], expected -86, is {}", + msg.apc[5].pcv[1] + ); + assert_eq!( + msg.apc[5].pcv[2], 78, + "incorrect value for apc[5].pcv[2], expected 78, is {}", + msg.apc[5].pcv[2] + ); + assert_eq!( + msg.apc[5].pcv[3], -50, + "incorrect value for apc[5].pcv[3], expected -50, is {}", + msg.apc[5].pcv[3] + ); + assert_eq!( + msg.apc[5].pcv[4], 41, + "incorrect value for apc[5].pcv[4], expected 41, is {}", + msg.apc[5].pcv[4] + ); + assert_eq!( + msg.apc[5].pcv[5], 43, + "incorrect value for apc[5].pcv[5], expected 43, is {}", + msg.apc[5].pcv[5] + ); + assert_eq!( + msg.apc[5].pcv[6], 81, + "incorrect value for apc[5].pcv[6], expected 81, is {}", + msg.apc[5].pcv[6] + ); + assert_eq!( + msg.apc[5].pcv[7], -9, + "incorrect value for apc[5].pcv[7], expected -9, is {}", + msg.apc[5].pcv[7] + ); + assert_eq!( + msg.apc[5].pcv[8], 99, + "incorrect value for apc[5].pcv[8], expected 99, is {}", + msg.apc[5].pcv[8] + ); + assert_eq!( + msg.apc[5].pcv[9], -58, + "incorrect value for apc[5].pcv[9], expected -58, is {}", + msg.apc[5].pcv[9] + ); + assert_eq!( + msg.apc[5].pcv[10], -112, + "incorrect value for apc[5].pcv[10], expected -112, is {}", + msg.apc[5].pcv[10] + ); + assert_eq!( + msg.apc[5].pcv[11], 2, + "incorrect value for apc[5].pcv[11], expected 2, is {}", + msg.apc[5].pcv[11] + ); + assert_eq!( + msg.apc[5].pcv[12], -124, + "incorrect value for apc[5].pcv[12], expected -124, is {}", + msg.apc[5].pcv[12] + ); + assert_eq!( + msg.apc[5].pcv[13], 2, + "incorrect value for apc[5].pcv[13], expected 2, is {}", + msg.apc[5].pcv[13] + ); + assert_eq!( + msg.apc[5].pcv[14], -32, + "incorrect value for apc[5].pcv[14], expected -32, is {}", + msg.apc[5].pcv[14] + ); + assert_eq!( + msg.apc[5].pcv[15], -36, + "incorrect value for apc[5].pcv[15], expected -36, is {}", + msg.apc[5].pcv[15] + ); + assert_eq!( + msg.apc[5].pcv[16], -108, + "incorrect value for apc[5].pcv[16], expected -108, is {}", + msg.apc[5].pcv[16] + ); + assert_eq!( + msg.apc[5].pcv[17], 58, + "incorrect value for apc[5].pcv[17], expected 58, is {}", + msg.apc[5].pcv[17] + ); + assert_eq!( + msg.apc[5].pcv[18], 85, + "incorrect value for apc[5].pcv[18], expected 85, is {}", + msg.apc[5].pcv[18] + ); + assert_eq!( + msg.apc[5].pcv[19], -118, + "incorrect value for apc[5].pcv[19], expected -118, is {}", + msg.apc[5].pcv[19] + ); + assert_eq!( + msg.apc[5].pcv[20], -46, + "incorrect value for apc[5].pcv[20], expected -46, is {}", + msg.apc[5].pcv[20] + ); + assert_eq!( + msg.apc[5].sat_info, 159, + "incorrect value for apc[5].sat_info, expected 159, is {}", + msg.apc[5].sat_info + ); + assert_eq!( + msg.apc[5].sid.code, 83, + "incorrect value for apc[5].sid.code, expected 83, is {}", + msg.apc[5].sid.code + ); + assert_eq!( + msg.apc[5].sid.sat, 45, + "incorrect value for apc[5].sid.sat, expected 45, is {}", + msg.apc[5].sid.sat + ); + assert_eq!( + msg.apc[5].svn, 64011, + "incorrect value for apc[5].svn, expected 64011, is {}", + msg.apc[5].svn + ); + assert_eq!( + msg.apc[6].pco[0], -14290, + "incorrect value for apc[6].pco[0], expected -14290, is {}", + msg.apc[6].pco[0] + ); + assert_eq!( + msg.apc[6].pco[1], 30340, + "incorrect value for apc[6].pco[1], expected 30340, is {}", + msg.apc[6].pco[1] + ); + assert_eq!( + msg.apc[6].pco[2], 3569, + "incorrect value for apc[6].pco[2], expected 3569, is {}", + msg.apc[6].pco[2] + ); + assert_eq!( + msg.apc[6].pcv[0], 37, + "incorrect value for apc[6].pcv[0], expected 37, is {}", + msg.apc[6].pcv[0] + ); + assert_eq!( + msg.apc[6].pcv[1], 62, + "incorrect value for apc[6].pcv[1], expected 62, is {}", + msg.apc[6].pcv[1] + ); + assert_eq!( + msg.apc[6].pcv[2], 107, + "incorrect value for apc[6].pcv[2], expected 107, is {}", + msg.apc[6].pcv[2] + ); + assert_eq!( + msg.apc[6].pcv[3], -3, + "incorrect value for apc[6].pcv[3], expected -3, is {}", + msg.apc[6].pcv[3] + ); + assert_eq!( + msg.apc[6].pcv[4], -66, + "incorrect value for apc[6].pcv[4], expected -66, is {}", + msg.apc[6].pcv[4] + ); + assert_eq!( + msg.apc[6].pcv[5], -120, + "incorrect value for apc[6].pcv[5], expected -120, is {}", + msg.apc[6].pcv[5] + ); + assert_eq!( + msg.apc[6].pcv[6], 66, + "incorrect value for apc[6].pcv[6], expected 66, is {}", + msg.apc[6].pcv[6] + ); + assert_eq!( + msg.apc[6].pcv[7], 9, + "incorrect value for apc[6].pcv[7], expected 9, is {}", + msg.apc[6].pcv[7] + ); + assert_eq!( + msg.apc[6].pcv[8], 84, + "incorrect value for apc[6].pcv[8], expected 84, is {}", + msg.apc[6].pcv[8] + ); + assert_eq!( + msg.apc[6].pcv[9], -101, + "incorrect value for apc[6].pcv[9], expected -101, is {}", + msg.apc[6].pcv[9] + ); + assert_eq!( + msg.apc[6].pcv[10], 86, + "incorrect value for apc[6].pcv[10], expected 86, is {}", + msg.apc[6].pcv[10] + ); + assert_eq!( + msg.apc[6].pcv[11], -76, + "incorrect value for apc[6].pcv[11], expected -76, is {}", + msg.apc[6].pcv[11] + ); + assert_eq!( + msg.apc[6].pcv[12], 41, + "incorrect value for apc[6].pcv[12], expected 41, is {}", + msg.apc[6].pcv[12] + ); + assert_eq!( + msg.apc[6].pcv[13], -60, + "incorrect value for apc[6].pcv[13], expected -60, is {}", + msg.apc[6].pcv[13] + ); + assert_eq!( + msg.apc[6].pcv[14], 40, + "incorrect value for apc[6].pcv[14], expected 40, is {}", + msg.apc[6].pcv[14] + ); + assert_eq!( + msg.apc[6].pcv[15], 119, + "incorrect value for apc[6].pcv[15], expected 119, is {}", + msg.apc[6].pcv[15] + ); + assert_eq!( + msg.apc[6].pcv[16], 101, + "incorrect value for apc[6].pcv[16], expected 101, is {}", + msg.apc[6].pcv[16] + ); + assert_eq!( + msg.apc[6].pcv[17], -4, + "incorrect value for apc[6].pcv[17], expected -4, is {}", + msg.apc[6].pcv[17] + ); + assert_eq!( + msg.apc[6].pcv[18], -33, + "incorrect value for apc[6].pcv[18], expected -33, is {}", + msg.apc[6].pcv[18] + ); + assert_eq!( + msg.apc[6].pcv[19], -112, + "incorrect value for apc[6].pcv[19], expected -112, is {}", + msg.apc[6].pcv[19] + ); + assert_eq!( + msg.apc[6].pcv[20], -103, + "incorrect value for apc[6].pcv[20], expected -103, is {}", + msg.apc[6].pcv[20] + ); + assert_eq!( + msg.apc[6].sat_info, 7, + "incorrect value for apc[6].sat_info, expected 7, is {}", + msg.apc[6].sat_info + ); + assert_eq!( + msg.apc[6].sid.code, 158, + "incorrect value for apc[6].sid.code, expected 158, is {}", + msg.apc[6].sid.code + ); + assert_eq!( + msg.apc[6].sid.sat, 200, + "incorrect value for apc[6].sid.sat, expected 200, is {}", + msg.apc[6].sid.sat + ); + assert_eq!( + msg.apc[6].svn, 17310, + "incorrect value for apc[6].svn, expected 17310, is {}", + msg.apc[6].svn + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrSatelliteApcDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a() { + { + let json_input = r#"{"crc":3378,"length":224,"msg_type":1540,"payload":"y6nwTgTVq/7W1AQIIR9QFQRp4SeLfJUwD9bFjSAhh5aUezGHYSdaFKnvL5mvI5GRe8ICZkqVX6vu+Qftqn1qnlO8tcIbVOKOe03Z+EPXgXKKGfAKOEw9odgWta4hDfzs5sSA1+/qs9ws1DksrTEkifjrYXCdixpzwB9Vf+RR/Nv5bpMIodfUtBlTkPcMG8etShcE72ff3Itbf9ZWMMvkYy1Tnwv6h6oq2cfpKqpOzikrUfdjxpAChALg3JQ6VYrSyJ4HnkMuyIR28Q0lPmv9vohCCVSbVrQpxCh3ZfzfkJk=","preamble":85,"sender":4920,"apc":[{"sid":{"sat":203,"code":169},"sat_info":240,"svn":1102,"pco":[-21547,-10498,1236],"pcv":[8,33,31,80,21,4,105,-31,39,-117,124,-107,48,15,-42,-59,-115,32,33,-121,-106]},{"sid":{"sat":148,"code":123},"sat_info":49,"svn":24967,"pco":[23079,-22252,12271],"pcv":[-103,-81,35,-111,-111,123,-62,2,102,74,-107,95,-85,-18,-7,7,-19,-86,125,106,-98]},{"sid":{"sat":83,"code":188},"sat_info":181,"svn":7106,"pco":[-7596,31630,-9907],"pcv":[-8,67,-41,-127,114,-118,25,-16,10,56,76,61,-95,-40,22,-75,-82,33,13,-4,-20]},{"sid":{"sat":230,"code":196},"sat_info":128,"svn":61399,"pco":[-19478,11484,14804],"pcv":[44,-83,49,36,-119,-8,-21,97,112,-99,-117,26,115,-64,31,85,127,-28,81,-4,-37]},{"sid":{"sat":249,"code":110},"sat_info":147,"svn":41224,"pco":[-11049,6580,-28589],"pcv":[-9,12,27,-57,-83,74,23,4,-17,103,-33,-36,-117,91,127,-42,86,48,-53,-28,99]},{"sid":{"sat":45,"code":83},"sat_info":159,"svn":64011,"pco":[-21881,-9942,-5689],"pcv":[42,-86,78,-50,41,43,81,-9,99,-58,-112,2,-124,2,-32,-36,-108,58,85,-118,-46]},{"sid":{"sat":200,"code":158},"sat_info":7,"svn":17310,"pco":[-14290,30340,3569],"pcv":[37,62,107,-3,-66,-120,66,9,84,-101,86,-76,41,-60,40,119,101,-4,-33,-112,-103]}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrSatelliteApcDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x604, + "Incorrect message type, expected 0x604, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1338, + "incorrect sender id, expected 0x1338, is {sender_id}" + ); + assert_eq!( + msg.apc[0].pco[0], -21547, + "incorrect value for apc[0].pco[0], expected -21547, is {}", + msg.apc[0].pco[0] + ); + assert_eq!( + msg.apc[0].pco[1], -10498, + "incorrect value for apc[0].pco[1], expected -10498, is {}", + msg.apc[0].pco[1] + ); + assert_eq!( + msg.apc[0].pco[2], 1236, + "incorrect value for apc[0].pco[2], expected 1236, is {}", + msg.apc[0].pco[2] + ); + assert_eq!( + msg.apc[0].pcv[0], 8, + "incorrect value for apc[0].pcv[0], expected 8, is {}", + msg.apc[0].pcv[0] + ); + assert_eq!( + msg.apc[0].pcv[1], 33, + "incorrect value for apc[0].pcv[1], expected 33, is {}", + msg.apc[0].pcv[1] + ); + assert_eq!( + msg.apc[0].pcv[2], 31, + "incorrect value for apc[0].pcv[2], expected 31, is {}", + msg.apc[0].pcv[2] + ); + assert_eq!( + msg.apc[0].pcv[3], 80, + "incorrect value for apc[0].pcv[3], expected 80, is {}", + msg.apc[0].pcv[3] + ); + assert_eq!( + msg.apc[0].pcv[4], 21, + "incorrect value for apc[0].pcv[4], expected 21, is {}", + msg.apc[0].pcv[4] + ); + assert_eq!( + msg.apc[0].pcv[5], 4, + "incorrect value for apc[0].pcv[5], expected 4, is {}", + msg.apc[0].pcv[5] + ); + assert_eq!( + msg.apc[0].pcv[6], 105, + "incorrect value for apc[0].pcv[6], expected 105, is {}", + msg.apc[0].pcv[6] + ); + assert_eq!( + msg.apc[0].pcv[7], -31, + "incorrect value for apc[0].pcv[7], expected -31, is {}", + msg.apc[0].pcv[7] + ); + assert_eq!( + msg.apc[0].pcv[8], 39, + "incorrect value for apc[0].pcv[8], expected 39, is {}", + msg.apc[0].pcv[8] + ); + assert_eq!( + msg.apc[0].pcv[9], -117, + "incorrect value for apc[0].pcv[9], expected -117, is {}", + msg.apc[0].pcv[9] + ); + assert_eq!( + msg.apc[0].pcv[10], 124, + "incorrect value for apc[0].pcv[10], expected 124, is {}", + msg.apc[0].pcv[10] + ); + assert_eq!( + msg.apc[0].pcv[11], -107, + "incorrect value for apc[0].pcv[11], expected -107, is {}", + msg.apc[0].pcv[11] + ); + assert_eq!( + msg.apc[0].pcv[12], 48, + "incorrect value for apc[0].pcv[12], expected 48, is {}", + msg.apc[0].pcv[12] + ); + assert_eq!( + msg.apc[0].pcv[13], 15, + "incorrect value for apc[0].pcv[13], expected 15, is {}", + msg.apc[0].pcv[13] + ); + assert_eq!( + msg.apc[0].pcv[14], -42, + "incorrect value for apc[0].pcv[14], expected -42, is {}", + msg.apc[0].pcv[14] + ); + assert_eq!( + msg.apc[0].pcv[15], -59, + "incorrect value for apc[0].pcv[15], expected -59, is {}", + msg.apc[0].pcv[15] + ); + assert_eq!( + msg.apc[0].pcv[16], -115, + "incorrect value for apc[0].pcv[16], expected -115, is {}", + msg.apc[0].pcv[16] + ); + assert_eq!( + msg.apc[0].pcv[17], 32, + "incorrect value for apc[0].pcv[17], expected 32, is {}", + msg.apc[0].pcv[17] + ); + assert_eq!( + msg.apc[0].pcv[18], 33, + "incorrect value for apc[0].pcv[18], expected 33, is {}", + msg.apc[0].pcv[18] + ); + assert_eq!( + msg.apc[0].pcv[19], -121, + "incorrect value for apc[0].pcv[19], expected -121, is {}", + msg.apc[0].pcv[19] + ); + assert_eq!( + msg.apc[0].pcv[20], -106, + "incorrect value for apc[0].pcv[20], expected -106, is {}", + msg.apc[0].pcv[20] + ); + assert_eq!( + msg.apc[0].sat_info, 240, + "incorrect value for apc[0].sat_info, expected 240, is {}", + msg.apc[0].sat_info + ); + assert_eq!( + msg.apc[0].sid.code, 169, + "incorrect value for apc[0].sid.code, expected 169, is {}", + msg.apc[0].sid.code + ); + assert_eq!( + msg.apc[0].sid.sat, 203, + "incorrect value for apc[0].sid.sat, expected 203, is {}", + msg.apc[0].sid.sat + ); + assert_eq!( + msg.apc[0].svn, 1102, + "incorrect value for apc[0].svn, expected 1102, is {}", + msg.apc[0].svn + ); + assert_eq!( + msg.apc[1].pco[0], 23079, + "incorrect value for apc[1].pco[0], expected 23079, is {}", + msg.apc[1].pco[0] + ); + assert_eq!( + msg.apc[1].pco[1], -22252, + "incorrect value for apc[1].pco[1], expected -22252, is {}", + msg.apc[1].pco[1] + ); + assert_eq!( + msg.apc[1].pco[2], 12271, + "incorrect value for apc[1].pco[2], expected 12271, is {}", + msg.apc[1].pco[2] + ); + assert_eq!( + msg.apc[1].pcv[0], -103, + "incorrect value for apc[1].pcv[0], expected -103, is {}", + msg.apc[1].pcv[0] + ); + assert_eq!( + msg.apc[1].pcv[1], -81, + "incorrect value for apc[1].pcv[1], expected -81, is {}", + msg.apc[1].pcv[1] + ); + assert_eq!( + msg.apc[1].pcv[2], 35, + "incorrect value for apc[1].pcv[2], expected 35, is {}", + msg.apc[1].pcv[2] + ); + assert_eq!( + msg.apc[1].pcv[3], -111, + "incorrect value for apc[1].pcv[3], expected -111, is {}", + msg.apc[1].pcv[3] + ); + assert_eq!( + msg.apc[1].pcv[4], -111, + "incorrect value for apc[1].pcv[4], expected -111, is {}", + msg.apc[1].pcv[4] + ); + assert_eq!( + msg.apc[1].pcv[5], 123, + "incorrect value for apc[1].pcv[5], expected 123, is {}", + msg.apc[1].pcv[5] + ); + assert_eq!( + msg.apc[1].pcv[6], -62, + "incorrect value for apc[1].pcv[6], expected -62, is {}", + msg.apc[1].pcv[6] + ); + assert_eq!( + msg.apc[1].pcv[7], 2, + "incorrect value for apc[1].pcv[7], expected 2, is {}", + msg.apc[1].pcv[7] + ); + assert_eq!( + msg.apc[1].pcv[8], 102, + "incorrect value for apc[1].pcv[8], expected 102, is {}", + msg.apc[1].pcv[8] + ); + assert_eq!( + msg.apc[1].pcv[9], 74, + "incorrect value for apc[1].pcv[9], expected 74, is {}", + msg.apc[1].pcv[9] + ); + assert_eq!( + msg.apc[1].pcv[10], -107, + "incorrect value for apc[1].pcv[10], expected -107, is {}", + msg.apc[1].pcv[10] + ); + assert_eq!( + msg.apc[1].pcv[11], 95, + "incorrect value for apc[1].pcv[11], expected 95, is {}", + msg.apc[1].pcv[11] + ); + assert_eq!( + msg.apc[1].pcv[12], -85, + "incorrect value for apc[1].pcv[12], expected -85, is {}", + msg.apc[1].pcv[12] + ); + assert_eq!( + msg.apc[1].pcv[13], -18, + "incorrect value for apc[1].pcv[13], expected -18, is {}", + msg.apc[1].pcv[13] + ); + assert_eq!( + msg.apc[1].pcv[14], -7, + "incorrect value for apc[1].pcv[14], expected -7, is {}", + msg.apc[1].pcv[14] + ); + assert_eq!( + msg.apc[1].pcv[15], 7, + "incorrect value for apc[1].pcv[15], expected 7, is {}", + msg.apc[1].pcv[15] + ); + assert_eq!( + msg.apc[1].pcv[16], -19, + "incorrect value for apc[1].pcv[16], expected -19, is {}", + msg.apc[1].pcv[16] + ); + assert_eq!( + msg.apc[1].pcv[17], -86, + "incorrect value for apc[1].pcv[17], expected -86, is {}", + msg.apc[1].pcv[17] + ); + assert_eq!( + msg.apc[1].pcv[18], 125, + "incorrect value for apc[1].pcv[18], expected 125, is {}", + msg.apc[1].pcv[18] + ); + assert_eq!( + msg.apc[1].pcv[19], 106, + "incorrect value for apc[1].pcv[19], expected 106, is {}", + msg.apc[1].pcv[19] + ); + assert_eq!( + msg.apc[1].pcv[20], -98, + "incorrect value for apc[1].pcv[20], expected -98, is {}", + msg.apc[1].pcv[20] + ); + assert_eq!( + msg.apc[1].sat_info, 49, + "incorrect value for apc[1].sat_info, expected 49, is {}", + msg.apc[1].sat_info + ); + assert_eq!( + msg.apc[1].sid.code, 123, + "incorrect value for apc[1].sid.code, expected 123, is {}", + msg.apc[1].sid.code + ); + assert_eq!( + msg.apc[1].sid.sat, 148, + "incorrect value for apc[1].sid.sat, expected 148, is {}", + msg.apc[1].sid.sat + ); + assert_eq!( + msg.apc[1].svn, 24967, + "incorrect value for apc[1].svn, expected 24967, is {}", + msg.apc[1].svn + ); + assert_eq!( + msg.apc[2].pco[0], -7596, + "incorrect value for apc[2].pco[0], expected -7596, is {}", + msg.apc[2].pco[0] + ); + assert_eq!( + msg.apc[2].pco[1], 31630, + "incorrect value for apc[2].pco[1], expected 31630, is {}", + msg.apc[2].pco[1] + ); + assert_eq!( + msg.apc[2].pco[2], -9907, + "incorrect value for apc[2].pco[2], expected -9907, is {}", + msg.apc[2].pco[2] + ); + assert_eq!( + msg.apc[2].pcv[0], -8, + "incorrect value for apc[2].pcv[0], expected -8, is {}", + msg.apc[2].pcv[0] + ); + assert_eq!( + msg.apc[2].pcv[1], 67, + "incorrect value for apc[2].pcv[1], expected 67, is {}", + msg.apc[2].pcv[1] + ); + assert_eq!( + msg.apc[2].pcv[2], -41, + "incorrect value for apc[2].pcv[2], expected -41, is {}", + msg.apc[2].pcv[2] + ); + assert_eq!( + msg.apc[2].pcv[3], -127, + "incorrect value for apc[2].pcv[3], expected -127, is {}", + msg.apc[2].pcv[3] + ); + assert_eq!( + msg.apc[2].pcv[4], 114, + "incorrect value for apc[2].pcv[4], expected 114, is {}", + msg.apc[2].pcv[4] + ); + assert_eq!( + msg.apc[2].pcv[5], -118, + "incorrect value for apc[2].pcv[5], expected -118, is {}", + msg.apc[2].pcv[5] + ); + assert_eq!( + msg.apc[2].pcv[6], 25, + "incorrect value for apc[2].pcv[6], expected 25, is {}", + msg.apc[2].pcv[6] + ); + assert_eq!( + msg.apc[2].pcv[7], -16, + "incorrect value for apc[2].pcv[7], expected -16, is {}", + msg.apc[2].pcv[7] + ); + assert_eq!( + msg.apc[2].pcv[8], 10, + "incorrect value for apc[2].pcv[8], expected 10, is {}", + msg.apc[2].pcv[8] + ); + assert_eq!( + msg.apc[2].pcv[9], 56, + "incorrect value for apc[2].pcv[9], expected 56, is {}", + msg.apc[2].pcv[9] + ); + assert_eq!( + msg.apc[2].pcv[10], 76, + "incorrect value for apc[2].pcv[10], expected 76, is {}", + msg.apc[2].pcv[10] + ); + assert_eq!( + msg.apc[2].pcv[11], 61, + "incorrect value for apc[2].pcv[11], expected 61, is {}", + msg.apc[2].pcv[11] + ); + assert_eq!( + msg.apc[2].pcv[12], -95, + "incorrect value for apc[2].pcv[12], expected -95, is {}", + msg.apc[2].pcv[12] + ); + assert_eq!( + msg.apc[2].pcv[13], -40, + "incorrect value for apc[2].pcv[13], expected -40, is {}", + msg.apc[2].pcv[13] + ); + assert_eq!( + msg.apc[2].pcv[14], 22, + "incorrect value for apc[2].pcv[14], expected 22, is {}", + msg.apc[2].pcv[14] + ); + assert_eq!( + msg.apc[2].pcv[15], -75, + "incorrect value for apc[2].pcv[15], expected -75, is {}", + msg.apc[2].pcv[15] + ); + assert_eq!( + msg.apc[2].pcv[16], -82, + "incorrect value for apc[2].pcv[16], expected -82, is {}", + msg.apc[2].pcv[16] + ); + assert_eq!( + msg.apc[2].pcv[17], 33, + "incorrect value for apc[2].pcv[17], expected 33, is {}", + msg.apc[2].pcv[17] + ); + assert_eq!( + msg.apc[2].pcv[18], 13, + "incorrect value for apc[2].pcv[18], expected 13, is {}", + msg.apc[2].pcv[18] + ); + assert_eq!( + msg.apc[2].pcv[19], -4, + "incorrect value for apc[2].pcv[19], expected -4, is {}", + msg.apc[2].pcv[19] + ); + assert_eq!( + msg.apc[2].pcv[20], -20, + "incorrect value for apc[2].pcv[20], expected -20, is {}", + msg.apc[2].pcv[20] + ); + assert_eq!( + msg.apc[2].sat_info, 181, + "incorrect value for apc[2].sat_info, expected 181, is {}", + msg.apc[2].sat_info + ); + assert_eq!( + msg.apc[2].sid.code, 188, + "incorrect value for apc[2].sid.code, expected 188, is {}", + msg.apc[2].sid.code + ); + assert_eq!( + msg.apc[2].sid.sat, 83, + "incorrect value for apc[2].sid.sat, expected 83, is {}", + msg.apc[2].sid.sat + ); + assert_eq!( + msg.apc[2].svn, 7106, + "incorrect value for apc[2].svn, expected 7106, is {}", + msg.apc[2].svn + ); + assert_eq!( + msg.apc[3].pco[0], -19478, + "incorrect value for apc[3].pco[0], expected -19478, is {}", + msg.apc[3].pco[0] + ); + assert_eq!( + msg.apc[3].pco[1], 11484, + "incorrect value for apc[3].pco[1], expected 11484, is {}", + msg.apc[3].pco[1] + ); + assert_eq!( + msg.apc[3].pco[2], 14804, + "incorrect value for apc[3].pco[2], expected 14804, is {}", + msg.apc[3].pco[2] + ); + assert_eq!( + msg.apc[3].pcv[0], 44, + "incorrect value for apc[3].pcv[0], expected 44, is {}", + msg.apc[3].pcv[0] + ); + assert_eq!( + msg.apc[3].pcv[1], -83, + "incorrect value for apc[3].pcv[1], expected -83, is {}", + msg.apc[3].pcv[1] + ); + assert_eq!( + msg.apc[3].pcv[2], 49, + "incorrect value for apc[3].pcv[2], expected 49, is {}", + msg.apc[3].pcv[2] + ); + assert_eq!( + msg.apc[3].pcv[3], 36, + "incorrect value for apc[3].pcv[3], expected 36, is {}", + msg.apc[3].pcv[3] + ); + assert_eq!( + msg.apc[3].pcv[4], -119, + "incorrect value for apc[3].pcv[4], expected -119, is {}", + msg.apc[3].pcv[4] + ); + assert_eq!( + msg.apc[3].pcv[5], -8, + "incorrect value for apc[3].pcv[5], expected -8, is {}", + msg.apc[3].pcv[5] + ); + assert_eq!( + msg.apc[3].pcv[6], -21, + "incorrect value for apc[3].pcv[6], expected -21, is {}", + msg.apc[3].pcv[6] + ); + assert_eq!( + msg.apc[3].pcv[7], 97, + "incorrect value for apc[3].pcv[7], expected 97, is {}", + msg.apc[3].pcv[7] + ); + assert_eq!( + msg.apc[3].pcv[8], 112, + "incorrect value for apc[3].pcv[8], expected 112, is {}", + msg.apc[3].pcv[8] + ); + assert_eq!( + msg.apc[3].pcv[9], -99, + "incorrect value for apc[3].pcv[9], expected -99, is {}", + msg.apc[3].pcv[9] + ); + assert_eq!( + msg.apc[3].pcv[10], -117, + "incorrect value for apc[3].pcv[10], expected -117, is {}", + msg.apc[3].pcv[10] + ); + assert_eq!( + msg.apc[3].pcv[11], 26, + "incorrect value for apc[3].pcv[11], expected 26, is {}", + msg.apc[3].pcv[11] + ); + assert_eq!( + msg.apc[3].pcv[12], 115, + "incorrect value for apc[3].pcv[12], expected 115, is {}", + msg.apc[3].pcv[12] + ); + assert_eq!( + msg.apc[3].pcv[13], -64, + "incorrect value for apc[3].pcv[13], expected -64, is {}", + msg.apc[3].pcv[13] + ); + assert_eq!( + msg.apc[3].pcv[14], 31, + "incorrect value for apc[3].pcv[14], expected 31, is {}", + msg.apc[3].pcv[14] + ); + assert_eq!( + msg.apc[3].pcv[15], 85, + "incorrect value for apc[3].pcv[15], expected 85, is {}", + msg.apc[3].pcv[15] + ); + assert_eq!( + msg.apc[3].pcv[16], 127, + "incorrect value for apc[3].pcv[16], expected 127, is {}", + msg.apc[3].pcv[16] + ); + assert_eq!( + msg.apc[3].pcv[17], -28, + "incorrect value for apc[3].pcv[17], expected -28, is {}", + msg.apc[3].pcv[17] + ); + assert_eq!( + msg.apc[3].pcv[18], 81, + "incorrect value for apc[3].pcv[18], expected 81, is {}", + msg.apc[3].pcv[18] + ); + assert_eq!( + msg.apc[3].pcv[19], -4, + "incorrect value for apc[3].pcv[19], expected -4, is {}", + msg.apc[3].pcv[19] + ); + assert_eq!( + msg.apc[3].pcv[20], -37, + "incorrect value for apc[3].pcv[20], expected -37, is {}", + msg.apc[3].pcv[20] + ); + assert_eq!( + msg.apc[3].sat_info, 128, + "incorrect value for apc[3].sat_info, expected 128, is {}", + msg.apc[3].sat_info + ); + assert_eq!( + msg.apc[3].sid.code, 196, + "incorrect value for apc[3].sid.code, expected 196, is {}", + msg.apc[3].sid.code + ); + assert_eq!( + msg.apc[3].sid.sat, 230, + "incorrect value for apc[3].sid.sat, expected 230, is {}", + msg.apc[3].sid.sat + ); + assert_eq!( + msg.apc[3].svn, 61399, + "incorrect value for apc[3].svn, expected 61399, is {}", + msg.apc[3].svn + ); + assert_eq!( + msg.apc[4].pco[0], -11049, + "incorrect value for apc[4].pco[0], expected -11049, is {}", + msg.apc[4].pco[0] + ); + assert_eq!( + msg.apc[4].pco[1], 6580, + "incorrect value for apc[4].pco[1], expected 6580, is {}", + msg.apc[4].pco[1] + ); + assert_eq!( + msg.apc[4].pco[2], -28589, + "incorrect value for apc[4].pco[2], expected -28589, is {}", + msg.apc[4].pco[2] + ); + assert_eq!( + msg.apc[4].pcv[0], -9, + "incorrect value for apc[4].pcv[0], expected -9, is {}", + msg.apc[4].pcv[0] + ); + assert_eq!( + msg.apc[4].pcv[1], 12, + "incorrect value for apc[4].pcv[1], expected 12, is {}", + msg.apc[4].pcv[1] + ); + assert_eq!( + msg.apc[4].pcv[2], 27, + "incorrect value for apc[4].pcv[2], expected 27, is {}", + msg.apc[4].pcv[2] + ); + assert_eq!( + msg.apc[4].pcv[3], -57, + "incorrect value for apc[4].pcv[3], expected -57, is {}", + msg.apc[4].pcv[3] + ); + assert_eq!( + msg.apc[4].pcv[4], -83, + "incorrect value for apc[4].pcv[4], expected -83, is {}", + msg.apc[4].pcv[4] + ); + assert_eq!( + msg.apc[4].pcv[5], 74, + "incorrect value for apc[4].pcv[5], expected 74, is {}", + msg.apc[4].pcv[5] + ); + assert_eq!( + msg.apc[4].pcv[6], 23, + "incorrect value for apc[4].pcv[6], expected 23, is {}", + msg.apc[4].pcv[6] + ); + assert_eq!( + msg.apc[4].pcv[7], 4, + "incorrect value for apc[4].pcv[7], expected 4, is {}", + msg.apc[4].pcv[7] + ); + assert_eq!( + msg.apc[4].pcv[8], -17, + "incorrect value for apc[4].pcv[8], expected -17, is {}", + msg.apc[4].pcv[8] + ); + assert_eq!( + msg.apc[4].pcv[9], 103, + "incorrect value for apc[4].pcv[9], expected 103, is {}", + msg.apc[4].pcv[9] + ); + assert_eq!( + msg.apc[4].pcv[10], -33, + "incorrect value for apc[4].pcv[10], expected -33, is {}", + msg.apc[4].pcv[10] + ); + assert_eq!( + msg.apc[4].pcv[11], -36, + "incorrect value for apc[4].pcv[11], expected -36, is {}", + msg.apc[4].pcv[11] + ); + assert_eq!( + msg.apc[4].pcv[12], -117, + "incorrect value for apc[4].pcv[12], expected -117, is {}", + msg.apc[4].pcv[12] + ); + assert_eq!( + msg.apc[4].pcv[13], 91, + "incorrect value for apc[4].pcv[13], expected 91, is {}", + msg.apc[4].pcv[13] + ); + assert_eq!( + msg.apc[4].pcv[14], 127, + "incorrect value for apc[4].pcv[14], expected 127, is {}", + msg.apc[4].pcv[14] + ); + assert_eq!( + msg.apc[4].pcv[15], -42, + "incorrect value for apc[4].pcv[15], expected -42, is {}", + msg.apc[4].pcv[15] + ); + assert_eq!( + msg.apc[4].pcv[16], 86, + "incorrect value for apc[4].pcv[16], expected 86, is {}", + msg.apc[4].pcv[16] + ); + assert_eq!( + msg.apc[4].pcv[17], 48, + "incorrect value for apc[4].pcv[17], expected 48, is {}", + msg.apc[4].pcv[17] + ); + assert_eq!( + msg.apc[4].pcv[18], -53, + "incorrect value for apc[4].pcv[18], expected -53, is {}", + msg.apc[4].pcv[18] + ); + assert_eq!( + msg.apc[4].pcv[19], -28, + "incorrect value for apc[4].pcv[19], expected -28, is {}", + msg.apc[4].pcv[19] + ); + assert_eq!( + msg.apc[4].pcv[20], 99, + "incorrect value for apc[4].pcv[20], expected 99, is {}", + msg.apc[4].pcv[20] + ); + assert_eq!( + msg.apc[4].sat_info, 147, + "incorrect value for apc[4].sat_info, expected 147, is {}", + msg.apc[4].sat_info + ); + assert_eq!( + msg.apc[4].sid.code, 110, + "incorrect value for apc[4].sid.code, expected 110, is {}", + msg.apc[4].sid.code + ); + assert_eq!( + msg.apc[4].sid.sat, 249, + "incorrect value for apc[4].sid.sat, expected 249, is {}", + msg.apc[4].sid.sat + ); + assert_eq!( + msg.apc[4].svn, 41224, + "incorrect value for apc[4].svn, expected 41224, is {}", + msg.apc[4].svn + ); + assert_eq!( + msg.apc[5].pco[0], -21881, + "incorrect value for apc[5].pco[0], expected -21881, is {}", + msg.apc[5].pco[0] + ); + assert_eq!( + msg.apc[5].pco[1], -9942, + "incorrect value for apc[5].pco[1], expected -9942, is {}", + msg.apc[5].pco[1] + ); + assert_eq!( + msg.apc[5].pco[2], -5689, + "incorrect value for apc[5].pco[2], expected -5689, is {}", + msg.apc[5].pco[2] + ); + assert_eq!( + msg.apc[5].pcv[0], 42, + "incorrect value for apc[5].pcv[0], expected 42, is {}", + msg.apc[5].pcv[0] + ); + assert_eq!( + msg.apc[5].pcv[1], -86, + "incorrect value for apc[5].pcv[1], expected -86, is {}", + msg.apc[5].pcv[1] + ); + assert_eq!( + msg.apc[5].pcv[2], 78, + "incorrect value for apc[5].pcv[2], expected 78, is {}", + msg.apc[5].pcv[2] + ); + assert_eq!( + msg.apc[5].pcv[3], -50, + "incorrect value for apc[5].pcv[3], expected -50, is {}", + msg.apc[5].pcv[3] + ); + assert_eq!( + msg.apc[5].pcv[4], 41, + "incorrect value for apc[5].pcv[4], expected 41, is {}", + msg.apc[5].pcv[4] + ); + assert_eq!( + msg.apc[5].pcv[5], 43, + "incorrect value for apc[5].pcv[5], expected 43, is {}", + msg.apc[5].pcv[5] + ); + assert_eq!( + msg.apc[5].pcv[6], 81, + "incorrect value for apc[5].pcv[6], expected 81, is {}", + msg.apc[5].pcv[6] + ); + assert_eq!( + msg.apc[5].pcv[7], -9, + "incorrect value for apc[5].pcv[7], expected -9, is {}", + msg.apc[5].pcv[7] + ); + assert_eq!( + msg.apc[5].pcv[8], 99, + "incorrect value for apc[5].pcv[8], expected 99, is {}", + msg.apc[5].pcv[8] + ); + assert_eq!( + msg.apc[5].pcv[9], -58, + "incorrect value for apc[5].pcv[9], expected -58, is {}", + msg.apc[5].pcv[9] + ); + assert_eq!( + msg.apc[5].pcv[10], -112, + "incorrect value for apc[5].pcv[10], expected -112, is {}", + msg.apc[5].pcv[10] + ); + assert_eq!( + msg.apc[5].pcv[11], 2, + "incorrect value for apc[5].pcv[11], expected 2, is {}", + msg.apc[5].pcv[11] + ); + assert_eq!( + msg.apc[5].pcv[12], -124, + "incorrect value for apc[5].pcv[12], expected -124, is {}", + msg.apc[5].pcv[12] + ); + assert_eq!( + msg.apc[5].pcv[13], 2, + "incorrect value for apc[5].pcv[13], expected 2, is {}", + msg.apc[5].pcv[13] + ); + assert_eq!( + msg.apc[5].pcv[14], -32, + "incorrect value for apc[5].pcv[14], expected -32, is {}", + msg.apc[5].pcv[14] + ); + assert_eq!( + msg.apc[5].pcv[15], -36, + "incorrect value for apc[5].pcv[15], expected -36, is {}", + msg.apc[5].pcv[15] + ); + assert_eq!( + msg.apc[5].pcv[16], -108, + "incorrect value for apc[5].pcv[16], expected -108, is {}", + msg.apc[5].pcv[16] + ); + assert_eq!( + msg.apc[5].pcv[17], 58, + "incorrect value for apc[5].pcv[17], expected 58, is {}", + msg.apc[5].pcv[17] + ); + assert_eq!( + msg.apc[5].pcv[18], 85, + "incorrect value for apc[5].pcv[18], expected 85, is {}", + msg.apc[5].pcv[18] + ); + assert_eq!( + msg.apc[5].pcv[19], -118, + "incorrect value for apc[5].pcv[19], expected -118, is {}", + msg.apc[5].pcv[19] + ); + assert_eq!( + msg.apc[5].pcv[20], -46, + "incorrect value for apc[5].pcv[20], expected -46, is {}", + msg.apc[5].pcv[20] + ); + assert_eq!( + msg.apc[5].sat_info, 159, + "incorrect value for apc[5].sat_info, expected 159, is {}", + msg.apc[5].sat_info + ); + assert_eq!( + msg.apc[5].sid.code, 83, + "incorrect value for apc[5].sid.code, expected 83, is {}", + msg.apc[5].sid.code + ); + assert_eq!( + msg.apc[5].sid.sat, 45, + "incorrect value for apc[5].sid.sat, expected 45, is {}", + msg.apc[5].sid.sat + ); + assert_eq!( + msg.apc[5].svn, 64011, + "incorrect value for apc[5].svn, expected 64011, is {}", + msg.apc[5].svn + ); + assert_eq!( + msg.apc[6].pco[0], -14290, + "incorrect value for apc[6].pco[0], expected -14290, is {}", + msg.apc[6].pco[0] + ); + assert_eq!( + msg.apc[6].pco[1], 30340, + "incorrect value for apc[6].pco[1], expected 30340, is {}", + msg.apc[6].pco[1] + ); + assert_eq!( + msg.apc[6].pco[2], 3569, + "incorrect value for apc[6].pco[2], expected 3569, is {}", + msg.apc[6].pco[2] + ); + assert_eq!( + msg.apc[6].pcv[0], 37, + "incorrect value for apc[6].pcv[0], expected 37, is {}", + msg.apc[6].pcv[0] + ); + assert_eq!( + msg.apc[6].pcv[1], 62, + "incorrect value for apc[6].pcv[1], expected 62, is {}", + msg.apc[6].pcv[1] + ); + assert_eq!( + msg.apc[6].pcv[2], 107, + "incorrect value for apc[6].pcv[2], expected 107, is {}", + msg.apc[6].pcv[2] + ); + assert_eq!( + msg.apc[6].pcv[3], -3, + "incorrect value for apc[6].pcv[3], expected -3, is {}", + msg.apc[6].pcv[3] + ); + assert_eq!( + msg.apc[6].pcv[4], -66, + "incorrect value for apc[6].pcv[4], expected -66, is {}", + msg.apc[6].pcv[4] + ); + assert_eq!( + msg.apc[6].pcv[5], -120, + "incorrect value for apc[6].pcv[5], expected -120, is {}", + msg.apc[6].pcv[5] + ); + assert_eq!( + msg.apc[6].pcv[6], 66, + "incorrect value for apc[6].pcv[6], expected 66, is {}", + msg.apc[6].pcv[6] + ); + assert_eq!( + msg.apc[6].pcv[7], 9, + "incorrect value for apc[6].pcv[7], expected 9, is {}", + msg.apc[6].pcv[7] + ); + assert_eq!( + msg.apc[6].pcv[8], 84, + "incorrect value for apc[6].pcv[8], expected 84, is {}", + msg.apc[6].pcv[8] + ); + assert_eq!( + msg.apc[6].pcv[9], -101, + "incorrect value for apc[6].pcv[9], expected -101, is {}", + msg.apc[6].pcv[9] + ); + assert_eq!( + msg.apc[6].pcv[10], 86, + "incorrect value for apc[6].pcv[10], expected 86, is {}", + msg.apc[6].pcv[10] + ); + assert_eq!( + msg.apc[6].pcv[11], -76, + "incorrect value for apc[6].pcv[11], expected -76, is {}", + msg.apc[6].pcv[11] + ); + assert_eq!( + msg.apc[6].pcv[12], 41, + "incorrect value for apc[6].pcv[12], expected 41, is {}", + msg.apc[6].pcv[12] + ); + assert_eq!( + msg.apc[6].pcv[13], -60, + "incorrect value for apc[6].pcv[13], expected -60, is {}", + msg.apc[6].pcv[13] + ); + assert_eq!( + msg.apc[6].pcv[14], 40, + "incorrect value for apc[6].pcv[14], expected 40, is {}", + msg.apc[6].pcv[14] + ); + assert_eq!( + msg.apc[6].pcv[15], 119, + "incorrect value for apc[6].pcv[15], expected 119, is {}", + msg.apc[6].pcv[15] + ); + assert_eq!( + msg.apc[6].pcv[16], 101, + "incorrect value for apc[6].pcv[16], expected 101, is {}", + msg.apc[6].pcv[16] + ); + assert_eq!( + msg.apc[6].pcv[17], -4, + "incorrect value for apc[6].pcv[17], expected -4, is {}", + msg.apc[6].pcv[17] + ); + assert_eq!( + msg.apc[6].pcv[18], -33, + "incorrect value for apc[6].pcv[18], expected -33, is {}", + msg.apc[6].pcv[18] + ); + assert_eq!( + msg.apc[6].pcv[19], -112, + "incorrect value for apc[6].pcv[19], expected -112, is {}", + msg.apc[6].pcv[19] + ); + assert_eq!( + msg.apc[6].pcv[20], -103, + "incorrect value for apc[6].pcv[20], expected -103, is {}", + msg.apc[6].pcv[20] + ); + assert_eq!( + msg.apc[6].sat_info, 7, + "incorrect value for apc[6].sat_info, expected 7, is {}", + msg.apc[6].sat_info + ); + assert_eq!( + msg.apc[6].sid.code, 158, + "incorrect value for apc[6].sid.code, expected 158, is {}", + msg.apc[6].sid.code + ); + assert_eq!( + msg.apc[6].sid.sat, 200, + "incorrect value for apc[6].sid.sat, expected 200, is {}", + msg.apc[6].sid.sat + ); + assert_eq!( + msg.apc[6].svn, 17310, + "incorrect value for apc[6].svn, expected 17310, is {}", + msg.apc[6].svn + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrSatelliteApcDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 6, 56, 19, 224, 203, 169, 240, 78, 4, 213, 171, 254, 214, 212, 4, 8, 33, 31, 80, + 21, 4, 105, 225, 39, 139, 124, 149, 48, 15, 214, 197, 141, 32, 33, 135, 150, 148, 123, + 49, 135, 97, 39, 90, 20, 169, 239, 47, 153, 175, 35, 145, 145, 123, 194, 2, 102, 74, + 149, 95, 171, 238, 249, 7, 237, 170, 125, 106, 158, 83, 188, 181, 194, 27, 84, 226, + 142, 123, 77, 217, 248, 67, 215, 129, 114, 138, 25, 240, 10, 56, 76, 61, 161, 216, 22, + 181, 174, 33, 13, 252, 236, 230, 196, 128, 215, 239, 234, 179, 220, 44, 212, 57, 44, + 173, 49, 36, 137, 248, 235, 97, 112, 157, 139, 26, 115, 192, 31, 85, 127, 228, 81, 252, + 219, 249, 110, 147, 8, 161, 215, 212, 180, 25, 83, 144, 247, 12, 27, 199, 173, 74, 23, + 4, 239, 103, 223, 220, 139, 91, 127, 214, 86, 48, 203, 228, 99, 45, 83, 159, 11, 250, + 135, 170, 42, 217, 199, 233, 42, 170, 78, 206, 41, 43, 81, 247, 99, 198, 144, 2, 132, + 2, 224, 220, 148, 58, 85, 138, 210, 200, 158, 7, 158, 67, 46, 200, 132, 118, 241, 13, + 37, 62, 107, 253, 190, 136, 66, 9, 84, 155, 86, 180, 41, 196, 40, 119, 101, 252, 223, + 144, 153, 50, 13, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrSatelliteApcDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrSatelliteApcDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x604, + "Incorrect message type, expected 0x604, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x1338, + "incorrect sender id, expected 0x1338, is {sender_id}" + ); + assert_eq!( + msg.apc[0].pco[0], -21547, + "incorrect value for apc[0].pco[0], expected -21547, is {}", + msg.apc[0].pco[0] + ); + assert_eq!( + msg.apc[0].pco[1], -10498, + "incorrect value for apc[0].pco[1], expected -10498, is {}", + msg.apc[0].pco[1] + ); + assert_eq!( + msg.apc[0].pco[2], 1236, + "incorrect value for apc[0].pco[2], expected 1236, is {}", + msg.apc[0].pco[2] + ); + assert_eq!( + msg.apc[0].pcv[0], 8, + "incorrect value for apc[0].pcv[0], expected 8, is {}", + msg.apc[0].pcv[0] + ); + assert_eq!( + msg.apc[0].pcv[1], 33, + "incorrect value for apc[0].pcv[1], expected 33, is {}", + msg.apc[0].pcv[1] + ); + assert_eq!( + msg.apc[0].pcv[2], 31, + "incorrect value for apc[0].pcv[2], expected 31, is {}", + msg.apc[0].pcv[2] + ); + assert_eq!( + msg.apc[0].pcv[3], 80, + "incorrect value for apc[0].pcv[3], expected 80, is {}", + msg.apc[0].pcv[3] + ); + assert_eq!( + msg.apc[0].pcv[4], 21, + "incorrect value for apc[0].pcv[4], expected 21, is {}", + msg.apc[0].pcv[4] + ); + assert_eq!( + msg.apc[0].pcv[5], 4, + "incorrect value for apc[0].pcv[5], expected 4, is {}", + msg.apc[0].pcv[5] + ); + assert_eq!( + msg.apc[0].pcv[6], 105, + "incorrect value for apc[0].pcv[6], expected 105, is {}", + msg.apc[0].pcv[6] + ); + assert_eq!( + msg.apc[0].pcv[7], -31, + "incorrect value for apc[0].pcv[7], expected -31, is {}", + msg.apc[0].pcv[7] + ); + assert_eq!( + msg.apc[0].pcv[8], 39, + "incorrect value for apc[0].pcv[8], expected 39, is {}", + msg.apc[0].pcv[8] + ); + assert_eq!( + msg.apc[0].pcv[9], -117, + "incorrect value for apc[0].pcv[9], expected -117, is {}", + msg.apc[0].pcv[9] + ); + assert_eq!( + msg.apc[0].pcv[10], 124, + "incorrect value for apc[0].pcv[10], expected 124, is {}", + msg.apc[0].pcv[10] + ); + assert_eq!( + msg.apc[0].pcv[11], -107, + "incorrect value for apc[0].pcv[11], expected -107, is {}", + msg.apc[0].pcv[11] + ); + assert_eq!( + msg.apc[0].pcv[12], 48, + "incorrect value for apc[0].pcv[12], expected 48, is {}", + msg.apc[0].pcv[12] + ); + assert_eq!( + msg.apc[0].pcv[13], 15, + "incorrect value for apc[0].pcv[13], expected 15, is {}", + msg.apc[0].pcv[13] + ); + assert_eq!( + msg.apc[0].pcv[14], -42, + "incorrect value for apc[0].pcv[14], expected -42, is {}", + msg.apc[0].pcv[14] + ); + assert_eq!( + msg.apc[0].pcv[15], -59, + "incorrect value for apc[0].pcv[15], expected -59, is {}", + msg.apc[0].pcv[15] + ); + assert_eq!( + msg.apc[0].pcv[16], -115, + "incorrect value for apc[0].pcv[16], expected -115, is {}", + msg.apc[0].pcv[16] + ); + assert_eq!( + msg.apc[0].pcv[17], 32, + "incorrect value for apc[0].pcv[17], expected 32, is {}", + msg.apc[0].pcv[17] + ); + assert_eq!( + msg.apc[0].pcv[18], 33, + "incorrect value for apc[0].pcv[18], expected 33, is {}", + msg.apc[0].pcv[18] + ); + assert_eq!( + msg.apc[0].pcv[19], -121, + "incorrect value for apc[0].pcv[19], expected -121, is {}", + msg.apc[0].pcv[19] + ); + assert_eq!( + msg.apc[0].pcv[20], -106, + "incorrect value for apc[0].pcv[20], expected -106, is {}", + msg.apc[0].pcv[20] + ); + assert_eq!( + msg.apc[0].sat_info, 240, + "incorrect value for apc[0].sat_info, expected 240, is {}", + msg.apc[0].sat_info + ); + assert_eq!( + msg.apc[0].sid.code, 169, + "incorrect value for apc[0].sid.code, expected 169, is {}", + msg.apc[0].sid.code + ); + assert_eq!( + msg.apc[0].sid.sat, 203, + "incorrect value for apc[0].sid.sat, expected 203, is {}", + msg.apc[0].sid.sat + ); + assert_eq!( + msg.apc[0].svn, 1102, + "incorrect value for apc[0].svn, expected 1102, is {}", + msg.apc[0].svn + ); + assert_eq!( + msg.apc[1].pco[0], 23079, + "incorrect value for apc[1].pco[0], expected 23079, is {}", + msg.apc[1].pco[0] + ); + assert_eq!( + msg.apc[1].pco[1], -22252, + "incorrect value for apc[1].pco[1], expected -22252, is {}", + msg.apc[1].pco[1] + ); + assert_eq!( + msg.apc[1].pco[2], 12271, + "incorrect value for apc[1].pco[2], expected 12271, is {}", + msg.apc[1].pco[2] + ); + assert_eq!( + msg.apc[1].pcv[0], -103, + "incorrect value for apc[1].pcv[0], expected -103, is {}", + msg.apc[1].pcv[0] + ); + assert_eq!( + msg.apc[1].pcv[1], -81, + "incorrect value for apc[1].pcv[1], expected -81, is {}", + msg.apc[1].pcv[1] + ); + assert_eq!( + msg.apc[1].pcv[2], 35, + "incorrect value for apc[1].pcv[2], expected 35, is {}", + msg.apc[1].pcv[2] + ); + assert_eq!( + msg.apc[1].pcv[3], -111, + "incorrect value for apc[1].pcv[3], expected -111, is {}", + msg.apc[1].pcv[3] + ); + assert_eq!( + msg.apc[1].pcv[4], -111, + "incorrect value for apc[1].pcv[4], expected -111, is {}", + msg.apc[1].pcv[4] + ); + assert_eq!( + msg.apc[1].pcv[5], 123, + "incorrect value for apc[1].pcv[5], expected 123, is {}", + msg.apc[1].pcv[5] + ); + assert_eq!( + msg.apc[1].pcv[6], -62, + "incorrect value for apc[1].pcv[6], expected -62, is {}", + msg.apc[1].pcv[6] + ); + assert_eq!( + msg.apc[1].pcv[7], 2, + "incorrect value for apc[1].pcv[7], expected 2, is {}", + msg.apc[1].pcv[7] + ); + assert_eq!( + msg.apc[1].pcv[8], 102, + "incorrect value for apc[1].pcv[8], expected 102, is {}", + msg.apc[1].pcv[8] + ); + assert_eq!( + msg.apc[1].pcv[9], 74, + "incorrect value for apc[1].pcv[9], expected 74, is {}", + msg.apc[1].pcv[9] + ); + assert_eq!( + msg.apc[1].pcv[10], -107, + "incorrect value for apc[1].pcv[10], expected -107, is {}", + msg.apc[1].pcv[10] + ); + assert_eq!( + msg.apc[1].pcv[11], 95, + "incorrect value for apc[1].pcv[11], expected 95, is {}", + msg.apc[1].pcv[11] + ); + assert_eq!( + msg.apc[1].pcv[12], -85, + "incorrect value for apc[1].pcv[12], expected -85, is {}", + msg.apc[1].pcv[12] + ); + assert_eq!( + msg.apc[1].pcv[13], -18, + "incorrect value for apc[1].pcv[13], expected -18, is {}", + msg.apc[1].pcv[13] + ); + assert_eq!( + msg.apc[1].pcv[14], -7, + "incorrect value for apc[1].pcv[14], expected -7, is {}", + msg.apc[1].pcv[14] + ); + assert_eq!( + msg.apc[1].pcv[15], 7, + "incorrect value for apc[1].pcv[15], expected 7, is {}", + msg.apc[1].pcv[15] + ); + assert_eq!( + msg.apc[1].pcv[16], -19, + "incorrect value for apc[1].pcv[16], expected -19, is {}", + msg.apc[1].pcv[16] + ); + assert_eq!( + msg.apc[1].pcv[17], -86, + "incorrect value for apc[1].pcv[17], expected -86, is {}", + msg.apc[1].pcv[17] + ); + assert_eq!( + msg.apc[1].pcv[18], 125, + "incorrect value for apc[1].pcv[18], expected 125, is {}", + msg.apc[1].pcv[18] + ); + assert_eq!( + msg.apc[1].pcv[19], 106, + "incorrect value for apc[1].pcv[19], expected 106, is {}", + msg.apc[1].pcv[19] + ); + assert_eq!( + msg.apc[1].pcv[20], -98, + "incorrect value for apc[1].pcv[20], expected -98, is {}", + msg.apc[1].pcv[20] + ); + assert_eq!( + msg.apc[1].sat_info, 49, + "incorrect value for apc[1].sat_info, expected 49, is {}", + msg.apc[1].sat_info + ); + assert_eq!( + msg.apc[1].sid.code, 123, + "incorrect value for apc[1].sid.code, expected 123, is {}", + msg.apc[1].sid.code + ); + assert_eq!( + msg.apc[1].sid.sat, 148, + "incorrect value for apc[1].sid.sat, expected 148, is {}", + msg.apc[1].sid.sat + ); + assert_eq!( + msg.apc[1].svn, 24967, + "incorrect value for apc[1].svn, expected 24967, is {}", + msg.apc[1].svn + ); + assert_eq!( + msg.apc[2].pco[0], -7596, + "incorrect value for apc[2].pco[0], expected -7596, is {}", + msg.apc[2].pco[0] + ); + assert_eq!( + msg.apc[2].pco[1], 31630, + "incorrect value for apc[2].pco[1], expected 31630, is {}", + msg.apc[2].pco[1] + ); + assert_eq!( + msg.apc[2].pco[2], -9907, + "incorrect value for apc[2].pco[2], expected -9907, is {}", + msg.apc[2].pco[2] + ); + assert_eq!( + msg.apc[2].pcv[0], -8, + "incorrect value for apc[2].pcv[0], expected -8, is {}", + msg.apc[2].pcv[0] + ); + assert_eq!( + msg.apc[2].pcv[1], 67, + "incorrect value for apc[2].pcv[1], expected 67, is {}", + msg.apc[2].pcv[1] + ); + assert_eq!( + msg.apc[2].pcv[2], -41, + "incorrect value for apc[2].pcv[2], expected -41, is {}", + msg.apc[2].pcv[2] + ); + assert_eq!( + msg.apc[2].pcv[3], -127, + "incorrect value for apc[2].pcv[3], expected -127, is {}", + msg.apc[2].pcv[3] + ); + assert_eq!( + msg.apc[2].pcv[4], 114, + "incorrect value for apc[2].pcv[4], expected 114, is {}", + msg.apc[2].pcv[4] + ); + assert_eq!( + msg.apc[2].pcv[5], -118, + "incorrect value for apc[2].pcv[5], expected -118, is {}", + msg.apc[2].pcv[5] + ); + assert_eq!( + msg.apc[2].pcv[6], 25, + "incorrect value for apc[2].pcv[6], expected 25, is {}", + msg.apc[2].pcv[6] + ); + assert_eq!( + msg.apc[2].pcv[7], -16, + "incorrect value for apc[2].pcv[7], expected -16, is {}", + msg.apc[2].pcv[7] + ); + assert_eq!( + msg.apc[2].pcv[8], 10, + "incorrect value for apc[2].pcv[8], expected 10, is {}", + msg.apc[2].pcv[8] + ); + assert_eq!( + msg.apc[2].pcv[9], 56, + "incorrect value for apc[2].pcv[9], expected 56, is {}", + msg.apc[2].pcv[9] + ); + assert_eq!( + msg.apc[2].pcv[10], 76, + "incorrect value for apc[2].pcv[10], expected 76, is {}", + msg.apc[2].pcv[10] + ); + assert_eq!( + msg.apc[2].pcv[11], 61, + "incorrect value for apc[2].pcv[11], expected 61, is {}", + msg.apc[2].pcv[11] + ); + assert_eq!( + msg.apc[2].pcv[12], -95, + "incorrect value for apc[2].pcv[12], expected -95, is {}", + msg.apc[2].pcv[12] + ); + assert_eq!( + msg.apc[2].pcv[13], -40, + "incorrect value for apc[2].pcv[13], expected -40, is {}", + msg.apc[2].pcv[13] + ); + assert_eq!( + msg.apc[2].pcv[14], 22, + "incorrect value for apc[2].pcv[14], expected 22, is {}", + msg.apc[2].pcv[14] + ); + assert_eq!( + msg.apc[2].pcv[15], -75, + "incorrect value for apc[2].pcv[15], expected -75, is {}", + msg.apc[2].pcv[15] + ); + assert_eq!( + msg.apc[2].pcv[16], -82, + "incorrect value for apc[2].pcv[16], expected -82, is {}", + msg.apc[2].pcv[16] + ); + assert_eq!( + msg.apc[2].pcv[17], 33, + "incorrect value for apc[2].pcv[17], expected 33, is {}", + msg.apc[2].pcv[17] + ); + assert_eq!( + msg.apc[2].pcv[18], 13, + "incorrect value for apc[2].pcv[18], expected 13, is {}", + msg.apc[2].pcv[18] + ); + assert_eq!( + msg.apc[2].pcv[19], -4, + "incorrect value for apc[2].pcv[19], expected -4, is {}", + msg.apc[2].pcv[19] + ); + assert_eq!( + msg.apc[2].pcv[20], -20, + "incorrect value for apc[2].pcv[20], expected -20, is {}", + msg.apc[2].pcv[20] + ); + assert_eq!( + msg.apc[2].sat_info, 181, + "incorrect value for apc[2].sat_info, expected 181, is {}", + msg.apc[2].sat_info + ); + assert_eq!( + msg.apc[2].sid.code, 188, + "incorrect value for apc[2].sid.code, expected 188, is {}", + msg.apc[2].sid.code + ); + assert_eq!( + msg.apc[2].sid.sat, 83, + "incorrect value for apc[2].sid.sat, expected 83, is {}", + msg.apc[2].sid.sat + ); + assert_eq!( + msg.apc[2].svn, 7106, + "incorrect value for apc[2].svn, expected 7106, is {}", + msg.apc[2].svn + ); + assert_eq!( + msg.apc[3].pco[0], -19478, + "incorrect value for apc[3].pco[0], expected -19478, is {}", + msg.apc[3].pco[0] + ); + assert_eq!( + msg.apc[3].pco[1], 11484, + "incorrect value for apc[3].pco[1], expected 11484, is {}", + msg.apc[3].pco[1] + ); + assert_eq!( + msg.apc[3].pco[2], 14804, + "incorrect value for apc[3].pco[2], expected 14804, is {}", + msg.apc[3].pco[2] + ); + assert_eq!( + msg.apc[3].pcv[0], 44, + "incorrect value for apc[3].pcv[0], expected 44, is {}", + msg.apc[3].pcv[0] + ); + assert_eq!( + msg.apc[3].pcv[1], -83, + "incorrect value for apc[3].pcv[1], expected -83, is {}", + msg.apc[3].pcv[1] + ); + assert_eq!( + msg.apc[3].pcv[2], 49, + "incorrect value for apc[3].pcv[2], expected 49, is {}", + msg.apc[3].pcv[2] + ); + assert_eq!( + msg.apc[3].pcv[3], 36, + "incorrect value for apc[3].pcv[3], expected 36, is {}", + msg.apc[3].pcv[3] + ); + assert_eq!( + msg.apc[3].pcv[4], -119, + "incorrect value for apc[3].pcv[4], expected -119, is {}", + msg.apc[3].pcv[4] + ); + assert_eq!( + msg.apc[3].pcv[5], -8, + "incorrect value for apc[3].pcv[5], expected -8, is {}", + msg.apc[3].pcv[5] + ); + assert_eq!( + msg.apc[3].pcv[6], -21, + "incorrect value for apc[3].pcv[6], expected -21, is {}", + msg.apc[3].pcv[6] + ); + assert_eq!( + msg.apc[3].pcv[7], 97, + "incorrect value for apc[3].pcv[7], expected 97, is {}", + msg.apc[3].pcv[7] + ); + assert_eq!( + msg.apc[3].pcv[8], 112, + "incorrect value for apc[3].pcv[8], expected 112, is {}", + msg.apc[3].pcv[8] + ); + assert_eq!( + msg.apc[3].pcv[9], -99, + "incorrect value for apc[3].pcv[9], expected -99, is {}", + msg.apc[3].pcv[9] + ); + assert_eq!( + msg.apc[3].pcv[10], -117, + "incorrect value for apc[3].pcv[10], expected -117, is {}", + msg.apc[3].pcv[10] + ); + assert_eq!( + msg.apc[3].pcv[11], 26, + "incorrect value for apc[3].pcv[11], expected 26, is {}", + msg.apc[3].pcv[11] + ); + assert_eq!( + msg.apc[3].pcv[12], 115, + "incorrect value for apc[3].pcv[12], expected 115, is {}", + msg.apc[3].pcv[12] + ); + assert_eq!( + msg.apc[3].pcv[13], -64, + "incorrect value for apc[3].pcv[13], expected -64, is {}", + msg.apc[3].pcv[13] + ); + assert_eq!( + msg.apc[3].pcv[14], 31, + "incorrect value for apc[3].pcv[14], expected 31, is {}", + msg.apc[3].pcv[14] + ); + assert_eq!( + msg.apc[3].pcv[15], 85, + "incorrect value for apc[3].pcv[15], expected 85, is {}", + msg.apc[3].pcv[15] + ); + assert_eq!( + msg.apc[3].pcv[16], 127, + "incorrect value for apc[3].pcv[16], expected 127, is {}", + msg.apc[3].pcv[16] + ); + assert_eq!( + msg.apc[3].pcv[17], -28, + "incorrect value for apc[3].pcv[17], expected -28, is {}", + msg.apc[3].pcv[17] + ); + assert_eq!( + msg.apc[3].pcv[18], 81, + "incorrect value for apc[3].pcv[18], expected 81, is {}", + msg.apc[3].pcv[18] + ); + assert_eq!( + msg.apc[3].pcv[19], -4, + "incorrect value for apc[3].pcv[19], expected -4, is {}", + msg.apc[3].pcv[19] + ); + assert_eq!( + msg.apc[3].pcv[20], -37, + "incorrect value for apc[3].pcv[20], expected -37, is {}", + msg.apc[3].pcv[20] + ); + assert_eq!( + msg.apc[3].sat_info, 128, + "incorrect value for apc[3].sat_info, expected 128, is {}", + msg.apc[3].sat_info + ); + assert_eq!( + msg.apc[3].sid.code, 196, + "incorrect value for apc[3].sid.code, expected 196, is {}", + msg.apc[3].sid.code + ); + assert_eq!( + msg.apc[3].sid.sat, 230, + "incorrect value for apc[3].sid.sat, expected 230, is {}", + msg.apc[3].sid.sat + ); + assert_eq!( + msg.apc[3].svn, 61399, + "incorrect value for apc[3].svn, expected 61399, is {}", + msg.apc[3].svn + ); + assert_eq!( + msg.apc[4].pco[0], -11049, + "incorrect value for apc[4].pco[0], expected -11049, is {}", + msg.apc[4].pco[0] + ); + assert_eq!( + msg.apc[4].pco[1], 6580, + "incorrect value for apc[4].pco[1], expected 6580, is {}", + msg.apc[4].pco[1] + ); + assert_eq!( + msg.apc[4].pco[2], -28589, + "incorrect value for apc[4].pco[2], expected -28589, is {}", + msg.apc[4].pco[2] + ); + assert_eq!( + msg.apc[4].pcv[0], -9, + "incorrect value for apc[4].pcv[0], expected -9, is {}", + msg.apc[4].pcv[0] + ); + assert_eq!( + msg.apc[4].pcv[1], 12, + "incorrect value for apc[4].pcv[1], expected 12, is {}", + msg.apc[4].pcv[1] + ); + assert_eq!( + msg.apc[4].pcv[2], 27, + "incorrect value for apc[4].pcv[2], expected 27, is {}", + msg.apc[4].pcv[2] + ); + assert_eq!( + msg.apc[4].pcv[3], -57, + "incorrect value for apc[4].pcv[3], expected -57, is {}", + msg.apc[4].pcv[3] + ); + assert_eq!( + msg.apc[4].pcv[4], -83, + "incorrect value for apc[4].pcv[4], expected -83, is {}", + msg.apc[4].pcv[4] + ); + assert_eq!( + msg.apc[4].pcv[5], 74, + "incorrect value for apc[4].pcv[5], expected 74, is {}", + msg.apc[4].pcv[5] + ); + assert_eq!( + msg.apc[4].pcv[6], 23, + "incorrect value for apc[4].pcv[6], expected 23, is {}", + msg.apc[4].pcv[6] + ); + assert_eq!( + msg.apc[4].pcv[7], 4, + "incorrect value for apc[4].pcv[7], expected 4, is {}", + msg.apc[4].pcv[7] + ); + assert_eq!( + msg.apc[4].pcv[8], -17, + "incorrect value for apc[4].pcv[8], expected -17, is {}", + msg.apc[4].pcv[8] + ); + assert_eq!( + msg.apc[4].pcv[9], 103, + "incorrect value for apc[4].pcv[9], expected 103, is {}", + msg.apc[4].pcv[9] + ); + assert_eq!( + msg.apc[4].pcv[10], -33, + "incorrect value for apc[4].pcv[10], expected -33, is {}", + msg.apc[4].pcv[10] + ); + assert_eq!( + msg.apc[4].pcv[11], -36, + "incorrect value for apc[4].pcv[11], expected -36, is {}", + msg.apc[4].pcv[11] + ); + assert_eq!( + msg.apc[4].pcv[12], -117, + "incorrect value for apc[4].pcv[12], expected -117, is {}", + msg.apc[4].pcv[12] + ); + assert_eq!( + msg.apc[4].pcv[13], 91, + "incorrect value for apc[4].pcv[13], expected 91, is {}", + msg.apc[4].pcv[13] + ); + assert_eq!( + msg.apc[4].pcv[14], 127, + "incorrect value for apc[4].pcv[14], expected 127, is {}", + msg.apc[4].pcv[14] + ); + assert_eq!( + msg.apc[4].pcv[15], -42, + "incorrect value for apc[4].pcv[15], expected -42, is {}", + msg.apc[4].pcv[15] + ); + assert_eq!( + msg.apc[4].pcv[16], 86, + "incorrect value for apc[4].pcv[16], expected 86, is {}", + msg.apc[4].pcv[16] + ); + assert_eq!( + msg.apc[4].pcv[17], 48, + "incorrect value for apc[4].pcv[17], expected 48, is {}", + msg.apc[4].pcv[17] + ); + assert_eq!( + msg.apc[4].pcv[18], -53, + "incorrect value for apc[4].pcv[18], expected -53, is {}", + msg.apc[4].pcv[18] + ); + assert_eq!( + msg.apc[4].pcv[19], -28, + "incorrect value for apc[4].pcv[19], expected -28, is {}", + msg.apc[4].pcv[19] + ); + assert_eq!( + msg.apc[4].pcv[20], 99, + "incorrect value for apc[4].pcv[20], expected 99, is {}", + msg.apc[4].pcv[20] + ); + assert_eq!( + msg.apc[4].sat_info, 147, + "incorrect value for apc[4].sat_info, expected 147, is {}", + msg.apc[4].sat_info + ); + assert_eq!( + msg.apc[4].sid.code, 110, + "incorrect value for apc[4].sid.code, expected 110, is {}", + msg.apc[4].sid.code + ); + assert_eq!( + msg.apc[4].sid.sat, 249, + "incorrect value for apc[4].sid.sat, expected 249, is {}", + msg.apc[4].sid.sat + ); + assert_eq!( + msg.apc[4].svn, 41224, + "incorrect value for apc[4].svn, expected 41224, is {}", + msg.apc[4].svn + ); + assert_eq!( + msg.apc[5].pco[0], -21881, + "incorrect value for apc[5].pco[0], expected -21881, is {}", + msg.apc[5].pco[0] + ); + assert_eq!( + msg.apc[5].pco[1], -9942, + "incorrect value for apc[5].pco[1], expected -9942, is {}", + msg.apc[5].pco[1] + ); + assert_eq!( + msg.apc[5].pco[2], -5689, + "incorrect value for apc[5].pco[2], expected -5689, is {}", + msg.apc[5].pco[2] + ); + assert_eq!( + msg.apc[5].pcv[0], 42, + "incorrect value for apc[5].pcv[0], expected 42, is {}", + msg.apc[5].pcv[0] + ); + assert_eq!( + msg.apc[5].pcv[1], -86, + "incorrect value for apc[5].pcv[1], expected -86, is {}", + msg.apc[5].pcv[1] + ); + assert_eq!( + msg.apc[5].pcv[2], 78, + "incorrect value for apc[5].pcv[2], expected 78, is {}", + msg.apc[5].pcv[2] + ); + assert_eq!( + msg.apc[5].pcv[3], -50, + "incorrect value for apc[5].pcv[3], expected -50, is {}", + msg.apc[5].pcv[3] + ); + assert_eq!( + msg.apc[5].pcv[4], 41, + "incorrect value for apc[5].pcv[4], expected 41, is {}", + msg.apc[5].pcv[4] + ); + assert_eq!( + msg.apc[5].pcv[5], 43, + "incorrect value for apc[5].pcv[5], expected 43, is {}", + msg.apc[5].pcv[5] + ); + assert_eq!( + msg.apc[5].pcv[6], 81, + "incorrect value for apc[5].pcv[6], expected 81, is {}", + msg.apc[5].pcv[6] + ); + assert_eq!( + msg.apc[5].pcv[7], -9, + "incorrect value for apc[5].pcv[7], expected -9, is {}", + msg.apc[5].pcv[7] + ); + assert_eq!( + msg.apc[5].pcv[8], 99, + "incorrect value for apc[5].pcv[8], expected 99, is {}", + msg.apc[5].pcv[8] + ); + assert_eq!( + msg.apc[5].pcv[9], -58, + "incorrect value for apc[5].pcv[9], expected -58, is {}", + msg.apc[5].pcv[9] + ); + assert_eq!( + msg.apc[5].pcv[10], -112, + "incorrect value for apc[5].pcv[10], expected -112, is {}", + msg.apc[5].pcv[10] + ); + assert_eq!( + msg.apc[5].pcv[11], 2, + "incorrect value for apc[5].pcv[11], expected 2, is {}", + msg.apc[5].pcv[11] + ); + assert_eq!( + msg.apc[5].pcv[12], -124, + "incorrect value for apc[5].pcv[12], expected -124, is {}", + msg.apc[5].pcv[12] + ); + assert_eq!( + msg.apc[5].pcv[13], 2, + "incorrect value for apc[5].pcv[13], expected 2, is {}", + msg.apc[5].pcv[13] + ); + assert_eq!( + msg.apc[5].pcv[14], -32, + "incorrect value for apc[5].pcv[14], expected -32, is {}", + msg.apc[5].pcv[14] + ); + assert_eq!( + msg.apc[5].pcv[15], -36, + "incorrect value for apc[5].pcv[15], expected -36, is {}", + msg.apc[5].pcv[15] + ); + assert_eq!( + msg.apc[5].pcv[16], -108, + "incorrect value for apc[5].pcv[16], expected -108, is {}", + msg.apc[5].pcv[16] + ); + assert_eq!( + msg.apc[5].pcv[17], 58, + "incorrect value for apc[5].pcv[17], expected 58, is {}", + msg.apc[5].pcv[17] + ); + assert_eq!( + msg.apc[5].pcv[18], 85, + "incorrect value for apc[5].pcv[18], expected 85, is {}", + msg.apc[5].pcv[18] + ); + assert_eq!( + msg.apc[5].pcv[19], -118, + "incorrect value for apc[5].pcv[19], expected -118, is {}", + msg.apc[5].pcv[19] + ); + assert_eq!( + msg.apc[5].pcv[20], -46, + "incorrect value for apc[5].pcv[20], expected -46, is {}", + msg.apc[5].pcv[20] + ); + assert_eq!( + msg.apc[5].sat_info, 159, + "incorrect value for apc[5].sat_info, expected 159, is {}", + msg.apc[5].sat_info + ); + assert_eq!( + msg.apc[5].sid.code, 83, + "incorrect value for apc[5].sid.code, expected 83, is {}", + msg.apc[5].sid.code + ); + assert_eq!( + msg.apc[5].sid.sat, 45, + "incorrect value for apc[5].sid.sat, expected 45, is {}", + msg.apc[5].sid.sat + ); + assert_eq!( + msg.apc[5].svn, 64011, + "incorrect value for apc[5].svn, expected 64011, is {}", + msg.apc[5].svn + ); + assert_eq!( + msg.apc[6].pco[0], -14290, + "incorrect value for apc[6].pco[0], expected -14290, is {}", + msg.apc[6].pco[0] + ); + assert_eq!( + msg.apc[6].pco[1], 30340, + "incorrect value for apc[6].pco[1], expected 30340, is {}", + msg.apc[6].pco[1] + ); + assert_eq!( + msg.apc[6].pco[2], 3569, + "incorrect value for apc[6].pco[2], expected 3569, is {}", + msg.apc[6].pco[2] + ); + assert_eq!( + msg.apc[6].pcv[0], 37, + "incorrect value for apc[6].pcv[0], expected 37, is {}", + msg.apc[6].pcv[0] + ); + assert_eq!( + msg.apc[6].pcv[1], 62, + "incorrect value for apc[6].pcv[1], expected 62, is {}", + msg.apc[6].pcv[1] + ); + assert_eq!( + msg.apc[6].pcv[2], 107, + "incorrect value for apc[6].pcv[2], expected 107, is {}", + msg.apc[6].pcv[2] + ); + assert_eq!( + msg.apc[6].pcv[3], -3, + "incorrect value for apc[6].pcv[3], expected -3, is {}", + msg.apc[6].pcv[3] + ); + assert_eq!( + msg.apc[6].pcv[4], -66, + "incorrect value for apc[6].pcv[4], expected -66, is {}", + msg.apc[6].pcv[4] + ); + assert_eq!( + msg.apc[6].pcv[5], -120, + "incorrect value for apc[6].pcv[5], expected -120, is {}", + msg.apc[6].pcv[5] + ); + assert_eq!( + msg.apc[6].pcv[6], 66, + "incorrect value for apc[6].pcv[6], expected 66, is {}", + msg.apc[6].pcv[6] + ); + assert_eq!( + msg.apc[6].pcv[7], 9, + "incorrect value for apc[6].pcv[7], expected 9, is {}", + msg.apc[6].pcv[7] + ); + assert_eq!( + msg.apc[6].pcv[8], 84, + "incorrect value for apc[6].pcv[8], expected 84, is {}", + msg.apc[6].pcv[8] + ); + assert_eq!( + msg.apc[6].pcv[9], -101, + "incorrect value for apc[6].pcv[9], expected -101, is {}", + msg.apc[6].pcv[9] + ); + assert_eq!( + msg.apc[6].pcv[10], 86, + "incorrect value for apc[6].pcv[10], expected 86, is {}", + msg.apc[6].pcv[10] + ); + assert_eq!( + msg.apc[6].pcv[11], -76, + "incorrect value for apc[6].pcv[11], expected -76, is {}", + msg.apc[6].pcv[11] + ); + assert_eq!( + msg.apc[6].pcv[12], 41, + "incorrect value for apc[6].pcv[12], expected 41, is {}", + msg.apc[6].pcv[12] + ); + assert_eq!( + msg.apc[6].pcv[13], -60, + "incorrect value for apc[6].pcv[13], expected -60, is {}", + msg.apc[6].pcv[13] + ); + assert_eq!( + msg.apc[6].pcv[14], 40, + "incorrect value for apc[6].pcv[14], expected 40, is {}", + msg.apc[6].pcv[14] + ); + assert_eq!( + msg.apc[6].pcv[15], 119, + "incorrect value for apc[6].pcv[15], expected 119, is {}", + msg.apc[6].pcv[15] + ); + assert_eq!( + msg.apc[6].pcv[16], 101, + "incorrect value for apc[6].pcv[16], expected 101, is {}", + msg.apc[6].pcv[16] + ); + assert_eq!( + msg.apc[6].pcv[17], -4, + "incorrect value for apc[6].pcv[17], expected -4, is {}", + msg.apc[6].pcv[17] + ); + assert_eq!( + msg.apc[6].pcv[18], -33, + "incorrect value for apc[6].pcv[18], expected -33, is {}", + msg.apc[6].pcv[18] + ); + assert_eq!( + msg.apc[6].pcv[19], -112, + "incorrect value for apc[6].pcv[19], expected -112, is {}", + msg.apc[6].pcv[19] + ); + assert_eq!( + msg.apc[6].pcv[20], -103, + "incorrect value for apc[6].pcv[20], expected -103, is {}", + msg.apc[6].pcv[20] + ); + assert_eq!( + msg.apc[6].sat_info, 7, + "incorrect value for apc[6].sat_info, expected 7, is {}", + msg.apc[6].sat_info + ); + assert_eq!( + msg.apc[6].sid.code, 158, + "incorrect value for apc[6].sid.code, expected 158, is {}", + msg.apc[6].sid.code + ); + assert_eq!( + msg.apc[6].sid.sat, 200, + "incorrect value for apc[6].sid.sat, expected 200, is {}", + msg.apc[6].sid.sat + ); + assert_eq!( + msg.apc[6].svn, 17310, + "incorrect value for apc[6].svn, expected 17310, is {}", + msg.apc[6].svn + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrSatelliteApcDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep.rs new file mode 100644 index 0000000000..12315fa5f9 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep.rs @@ -0,0 +1,2194 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_stec_correction_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, 119, 156, 157, 112, + 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, 3, 14, 8, 70, 12, 44, 53, 181, 90, 174, + 247, 150, 58, 172, 247, 179, 119, 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, 53, + 222, 187, 146, 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, 91, 234, 0, 213, 139, 95, + 179, 50, 21, 74, 174, 169, 61, 86, 91, 142, 51, 108, 9, 38, 225, 146, 101, 73, 139, 56, + 117, 82, 37, 213, 108, 205, 93, 18, 19, 195, 33, 202, 87, 206, 178, 125, 188, 119, 56, + 69, 150, 150, 76, 3, 131, 18, 73, 208, 72, 232, 8, 250, 203, 178, 170, 163, 252, 86, + 49, 247, 178, 166, 56, 31, 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, 124, 169, 121, + 158, 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, 110, 23, 12, 241, 88, 69, 239, + 252, 57, 93, 44, 201, 216, 173, 242, 178, 17, 5, 223, 169, 192, 3, 77, 107, 2, 144, + 233, 14, 88, 32, 209, 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, 126, 217, 79, 171, 239, + 237, 188, 238, 112, 201, 118, 141, 18, 163, 103, 35, 63, 21, 82, 129, 18, 117, 85, 190, + 79, 210, 215, 227, 177, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fb, + "Incorrect message type, expected 0x5fb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97cc, + "incorrect sender id, expected 0x97cc, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 60, + "incorrect value for header.iod_atmo, expected 60, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 157, + "incorrect value for header.num_msgs, expected 157, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 112, + "incorrect value for header.seq_num, expected 112, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 30066, + "incorrect value for header.tile_id, expected 30066, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 58526, + "incorrect value for header.tile_set_id, expected 58526, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 714907186, + "incorrect value for header.time.tow, expected 714907186, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 40055, + "incorrect value for header.time.wn, expected 40055, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 47, + "incorrect value for header.update_interval, expected 47, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -5289, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -5289, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -20141, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -20141, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 966, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 966, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 2062, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 2062, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 70, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 70, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 40, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 40, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], -19147, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected -19147, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], -20902, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected -20902, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], -26889, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected -26889, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -21446, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -21446, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 44, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 44, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 12, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 12, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 70, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 70, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], 32176, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected 32176, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -20220, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -20220, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 29157, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 29157, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 19726, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 19726, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 119, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 119, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 179, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 247, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 247, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], -8651, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected -8651, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], -27973, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected -27973, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], 23546, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected 23546, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -10284, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -10284, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 23, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 185, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 185, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 153, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 153, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 27486, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 27486, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 23329, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 23329, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], 234, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected 234, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -29739, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -29739, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 250, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 250, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 107, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 107, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], 18965, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected 18965, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -22098, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -22098, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 22077, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 22077, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -29093, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -29093, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 50, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 50, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 179, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 95, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 95, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -7898, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -7898, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], 26002, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected 26002, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -29879, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -29879, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], 30008, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected 30008, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 9, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 9, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 108, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 108, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 51, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 51, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -12948, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -12948, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4701, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4701, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], -15597, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected -15597, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -13791, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -13791, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 213, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 213, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 37, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 37, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 82, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 82, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], -17283, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected -17283, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], 14455, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected 14455, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], -27067, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected -27067, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 19606, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 19606, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 178, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 178, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 206, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 206, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 87, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 87, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -12215, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -12215, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], -6072, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected -6072, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], -1528, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected -1528, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -19765, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -19765, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 18, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 18, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 131, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 131, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 3, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 3, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 12630, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 12630, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], -19721, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected -19721, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], 14502, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected 14502, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 2591, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 2591, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 252, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 252, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[10].sv_id.constellation, 163, "incorrect value for stec_sat_list[10].sv_id.constellation, expected 163, is {}", msg.stec_sat_list[10].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 170, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 170, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], -23340, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected -23340, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -24063, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -24063, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 4650, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 4650, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], -22148, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected -22148, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 241, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 241, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 213, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 213, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 119, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 119, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 5944, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 5944, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 32142, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 32142, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 30760, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 30760, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], 11587, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected 11587, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 26, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 26, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[12].sv_id.constellation, 158, "incorrect value for stec_sat_list[12].sv_id.constellation, expected 158, is {}", msg.stec_sat_list[12].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 121, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 121, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], 3095, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected 3095, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 22769, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 22769, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -4283, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -4283, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], 14844, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected 14844, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 110, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 110, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 235, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 235, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -21032, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -21032, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -19726, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -19726, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 1297, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 1297, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -22049, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -22049, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 201, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 201, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[14].sv_id.constellation, 44, + "incorrect value for stec_sat_list[14].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[14].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 93, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 93, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], 619, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected 619, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -5744, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -5744, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], 22542, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected 22542, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], -12000, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected -12000, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 77, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 77, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[15].sv_id.constellation, 3, + "incorrect value for stec_sat_list[15].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[15].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 192, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 192, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], 10651, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected 10651, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -2889, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -2889, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], 21150, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected 21150, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], 26421, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected 26421, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 123, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 123, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[16].sv_id.constellation, 17, + "incorrect value for stec_sat_list[16].sv_id.constellation, expected 17, is {}", + msg.stec_sat_list[16].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 1, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 1, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], -19165, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected -19165, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 30229, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 30229, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -1282, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -1282, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -18382, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -18382, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 185, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 185, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[17].sv_id.constellation, 202, "incorrect value for stec_sat_list[17].sv_id.constellation, expected 202, is {}", msg.stec_sat_list[17].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], -23752, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected -23752, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 32433, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 32433, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 20441, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 20441, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], -4181, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected -4181, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 45, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 45, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 31, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 31, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 50, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 50, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -13968, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -13968, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -29322, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -29322, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], -23790, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected -23790, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 9063, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 9063, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 238, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 238, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 188, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 237, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 237, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 4737, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 4737, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], 21877, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected 21877, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], 20414, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected 20414, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -10286, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -10286, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 82, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 82, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[20].sv_id.constellation, 21, + "incorrect value for stec_sat_list[20].sv_id.constellation, expected 21, is {}", + msg.stec_sat_list[20].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 63, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 63, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDep"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_stec_correction_dep() { + { + let json_input = r#"{"crc":45539,"length":245,"msg_type":1531,"payload":"nuRydTKenCp3nJ1wLzyEKEZX61OxxgMOCEYMLDW1Wq73ljqs97N3sH0EseVxDk2ZuRc13ruS+lvU1w5r+l5rIVvqANWLX7MyFUquqT1WW44zbAkm4ZJlSYs4dVIl1WzNXRITwyHKV86yfbx3OEWWlkwDgxJJ0EjoCPrLsqqj/FYx97KmOB8Kd9Xx1KQBoioSfKl5nho4F459KHhDLX7rbhcM8VhF7/w5XSzJ2K3yshEF36nAA01rApDpDlgg0QERe5spt/SeUjVnDsq5I7UVdv76MrgyHy04o7F+2U+r7+287nDJdo0So2cjPxVSgRJ1Vb5P0tc=","preamble":85,"sender":38860,"header":{"tile_set_id":58526,"tile_id":30066,"time":{"tow":714907186,"wn":40055},"num_msgs":157,"seq_num":112,"update_interval":47,"iod_atmo":60},"stec_sat_list":[{"sv_id":{"satId":132,"constellation":40},"stec_quality_indicator":70,"stec_coeff":[-5289,-20141,966,2062]},{"sv_id":{"satId":70,"constellation":12},"stec_quality_indicator":44,"stec_coeff":[-19147,-20902,-26889,-21446]},{"sv_id":{"satId":247,"constellation":179},"stec_quality_indicator":119,"stec_coeff":[32176,-20220,29157,19726]},{"sv_id":{"satId":153,"constellation":185},"stec_quality_indicator":23,"stec_coeff":[-8651,-27973,23546,-10284]},{"sv_id":{"satId":14,"constellation":107},"stec_quality_indicator":250,"stec_coeff":[27486,23329,234,-29739]},{"sv_id":{"satId":95,"constellation":179},"stec_quality_indicator":50,"stec_coeff":[18965,-22098,22077,-29093]},{"sv_id":{"satId":51,"constellation":108},"stec_quality_indicator":9,"stec_coeff":[-7898,26002,-29879,30008]},{"sv_id":{"satId":82,"constellation":37},"stec_quality_indicator":213,"stec_coeff":[-12948,4701,-15597,-13791]},{"sv_id":{"satId":87,"constellation":206},"stec_quality_indicator":178,"stec_coeff":[-17283,14455,-27067,19606]},{"sv_id":{"satId":3,"constellation":131},"stec_quality_indicator":18,"stec_coeff":[-12215,-6072,-1528,-19765]},{"sv_id":{"satId":170,"constellation":163},"stec_quality_indicator":252,"stec_coeff":[12630,-19721,14502,2591]},{"sv_id":{"satId":119,"constellation":213},"stec_quality_indicator":241,"stec_coeff":[-23340,-24063,4650,-22148]},{"sv_id":{"satId":121,"constellation":158},"stec_quality_indicator":26,"stec_coeff":[5944,32142,30760,11587]},{"sv_id":{"satId":126,"constellation":235},"stec_quality_indicator":110,"stec_coeff":[3095,22769,-4283,14844]},{"sv_id":{"satId":93,"constellation":44},"stec_quality_indicator":201,"stec_coeff":[-21032,-19726,1297,-22049]},{"sv_id":{"satId":192,"constellation":3},"stec_quality_indicator":77,"stec_coeff":[619,-5744,22542,-12000]},{"sv_id":{"satId":1,"constellation":17},"stec_quality_indicator":123,"stec_coeff":[10651,-2889,21150,26421]},{"sv_id":{"satId":14,"constellation":202},"stec_quality_indicator":185,"stec_coeff":[-19165,30229,-1282,-18382]},{"sv_id":{"satId":50,"constellation":31},"stec_quality_indicator":45,"stec_coeff":[-23752,32433,20441,-4181]},{"sv_id":{"satId":237,"constellation":188},"stec_quality_indicator":238,"stec_coeff":[-13968,-29322,-23790,9063]},{"sv_id":{"satId":63,"constellation":21},"stec_quality_indicator":82,"stec_coeff":[4737,21877,20414,-10286]}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fb, + "Incorrect message type, expected 0x5fb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97cc, + "incorrect sender id, expected 0x97cc, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 60, + "incorrect value for header.iod_atmo, expected 60, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 157, + "incorrect value for header.num_msgs, expected 157, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 112, + "incorrect value for header.seq_num, expected 112, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 30066, + "incorrect value for header.tile_id, expected 30066, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 58526, + "incorrect value for header.tile_set_id, expected 58526, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 714907186, + "incorrect value for header.time.tow, expected 714907186, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 40055, + "incorrect value for header.time.wn, expected 40055, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 47, + "incorrect value for header.update_interval, expected 47, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -5289, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -5289, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -20141, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -20141, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 966, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 966, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 2062, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 2062, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 70, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 70, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 40, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 40, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], -19147, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected -19147, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], -20902, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected -20902, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], -26889, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected -26889, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -21446, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -21446, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 44, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 44, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 12, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 12, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 70, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 70, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], 32176, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected 32176, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -20220, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -20220, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 29157, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 29157, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 19726, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 19726, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 119, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 119, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 179, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 247, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 247, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], -8651, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected -8651, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], -27973, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected -27973, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], 23546, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected 23546, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -10284, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -10284, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 23, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 185, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 185, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 153, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 153, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 27486, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 27486, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 23329, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 23329, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], 234, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected 234, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -29739, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -29739, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 250, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 250, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 107, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 107, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], 18965, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected 18965, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -22098, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -22098, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 22077, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 22077, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -29093, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -29093, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 50, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 50, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 179, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 95, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 95, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -7898, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -7898, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], 26002, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected 26002, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -29879, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -29879, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], 30008, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected 30008, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 9, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 9, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 108, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 108, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 51, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 51, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -12948, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -12948, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4701, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4701, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], -15597, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected -15597, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -13791, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -13791, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 213, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 213, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 37, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 37, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 82, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 82, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], -17283, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected -17283, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], 14455, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected 14455, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], -27067, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected -27067, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 19606, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 19606, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 178, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 178, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 206, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 206, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 87, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 87, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -12215, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -12215, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], -6072, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected -6072, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], -1528, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected -1528, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -19765, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -19765, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 18, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 18, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 131, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 131, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 3, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 3, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 12630, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 12630, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], -19721, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected -19721, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], 14502, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected 14502, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 2591, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 2591, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 252, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 252, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[10].sv_id.constellation, 163, "incorrect value for stec_sat_list[10].sv_id.constellation, expected 163, is {}", msg.stec_sat_list[10].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 170, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 170, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], -23340, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected -23340, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -24063, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -24063, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 4650, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 4650, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], -22148, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected -22148, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 241, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 241, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 213, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 213, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 119, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 119, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 5944, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 5944, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 32142, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 32142, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 30760, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 30760, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], 11587, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected 11587, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 26, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 26, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[12].sv_id.constellation, 158, "incorrect value for stec_sat_list[12].sv_id.constellation, expected 158, is {}", msg.stec_sat_list[12].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 121, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 121, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], 3095, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected 3095, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 22769, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 22769, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -4283, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -4283, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], 14844, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected 14844, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 110, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 110, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 235, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 235, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -21032, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -21032, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -19726, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -19726, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 1297, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 1297, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -22049, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -22049, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 201, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 201, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[14].sv_id.constellation, 44, + "incorrect value for stec_sat_list[14].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[14].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 93, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 93, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], 619, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected 619, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -5744, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -5744, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], 22542, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected 22542, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], -12000, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected -12000, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 77, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 77, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[15].sv_id.constellation, 3, + "incorrect value for stec_sat_list[15].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[15].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 192, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 192, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], 10651, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected 10651, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -2889, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -2889, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], 21150, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected 21150, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], 26421, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected 26421, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 123, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 123, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[16].sv_id.constellation, 17, + "incorrect value for stec_sat_list[16].sv_id.constellation, expected 17, is {}", + msg.stec_sat_list[16].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 1, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 1, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], -19165, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected -19165, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 30229, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 30229, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -1282, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -1282, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -18382, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -18382, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 185, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 185, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[17].sv_id.constellation, 202, "incorrect value for stec_sat_list[17].sv_id.constellation, expected 202, is {}", msg.stec_sat_list[17].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], -23752, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected -23752, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 32433, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 32433, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 20441, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 20441, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], -4181, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected -4181, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 45, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 45, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 31, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 31, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 50, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 50, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -13968, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -13968, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -29322, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -29322, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], -23790, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected -23790, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 9063, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 9063, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 238, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 238, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 188, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 237, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 237, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 4737, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 4737, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], 21877, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected 21877, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], 20414, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected 20414, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -10286, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -10286, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 82, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 82, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[20].sv_id.constellation, 21, + "incorrect value for stec_sat_list[20].sv_id.constellation, expected 21, is {}", + msg.stec_sat_list[20].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 63, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 63, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDep"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_stec_correction_dep`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_stec_correction_dep() { + { + let mut payload = Cursor::new(vec![ + 85, 251, 5, 204, 151, 245, 158, 228, 114, 117, 50, 158, 156, 42, 119, 156, 157, 112, + 47, 60, 132, 40, 70, 87, 235, 83, 177, 198, 3, 14, 8, 70, 12, 44, 53, 181, 90, 174, + 247, 150, 58, 172, 247, 179, 119, 176, 125, 4, 177, 229, 113, 14, 77, 153, 185, 23, 53, + 222, 187, 146, 250, 91, 212, 215, 14, 107, 250, 94, 107, 33, 91, 234, 0, 213, 139, 95, + 179, 50, 21, 74, 174, 169, 61, 86, 91, 142, 51, 108, 9, 38, 225, 146, 101, 73, 139, 56, + 117, 82, 37, 213, 108, 205, 93, 18, 19, 195, 33, 202, 87, 206, 178, 125, 188, 119, 56, + 69, 150, 150, 76, 3, 131, 18, 73, 208, 72, 232, 8, 250, 203, 178, 170, 163, 252, 86, + 49, 247, 178, 166, 56, 31, 10, 119, 213, 241, 212, 164, 1, 162, 42, 18, 124, 169, 121, + 158, 26, 56, 23, 142, 125, 40, 120, 67, 45, 126, 235, 110, 23, 12, 241, 88, 69, 239, + 252, 57, 93, 44, 201, 216, 173, 242, 178, 17, 5, 223, 169, 192, 3, 77, 107, 2, 144, + 233, 14, 88, 32, 209, 1, 17, 123, 155, 41, 183, 244, 158, 82, 53, 103, 14, 202, 185, + 35, 181, 21, 118, 254, 250, 50, 184, 50, 31, 45, 56, 163, 177, 126, 217, 79, 171, 239, + 237, 188, 238, 112, 201, 118, 141, 18, 163, 103, 35, 63, 21, 82, 129, 18, 117, 85, 190, + 79, 210, 215, 227, 177, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrStecCorrectionDep( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDep(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5fb, + "Incorrect message type, expected 0x5fb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x97cc, + "incorrect sender id, expected 0x97cc, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 60, + "incorrect value for header.iod_atmo, expected 60, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 157, + "incorrect value for header.num_msgs, expected 157, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 112, + "incorrect value for header.seq_num, expected 112, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.tile_id, 30066, + "incorrect value for header.tile_id, expected 30066, is {}", + msg.header.tile_id + ); + assert_eq!( + msg.header.tile_set_id, 58526, + "incorrect value for header.tile_set_id, expected 58526, is {}", + msg.header.tile_set_id + ); + assert_eq!( + msg.header.time.tow, 714907186, + "incorrect value for header.time.tow, expected 714907186, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 40055, + "incorrect value for header.time.wn, expected 40055, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 47, + "incorrect value for header.update_interval, expected 47, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -5289, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -5289, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -20141, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -20141, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 966, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 966, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 2062, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 2062, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 70, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 70, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 40, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 40, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], -19147, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected -19147, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], -20902, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected -20902, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], -26889, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected -26889, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -21446, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -21446, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 44, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 44, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 12, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 12, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 70, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 70, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], 32176, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected 32176, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -20220, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -20220, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 29157, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 29157, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 19726, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 19726, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 119, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 119, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 179, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 247, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 247, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], -8651, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected -8651, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], -27973, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected -27973, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], 23546, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected 23546, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -10284, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -10284, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 23, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 185, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 185, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 153, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 153, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 27486, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 27486, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 23329, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 23329, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], 234, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected 234, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -29739, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -29739, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 250, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 250, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 107, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 107, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], 18965, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected 18965, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -22098, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -22098, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 22077, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 22077, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -29093, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -29093, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 50, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 50, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 179, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 179, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 95, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 95, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -7898, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -7898, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], 26002, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected 26002, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -29879, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -29879, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], 30008, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected 30008, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 9, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 9, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 108, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 108, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 51, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 51, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -12948, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -12948, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4701, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4701, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], -15597, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected -15597, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -13791, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -13791, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 213, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 213, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 37, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 37, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 82, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 82, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], -17283, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected -17283, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], 14455, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected 14455, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], -27067, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected -27067, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 19606, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 19606, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 178, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 178, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 206, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 206, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 87, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 87, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -12215, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -12215, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], -6072, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected -6072, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], -1528, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected -1528, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -19765, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -19765, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 18, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 18, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 131, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 131, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 3, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 3, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 12630, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 12630, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], -19721, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected -19721, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], 14502, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected 14502, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 2591, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 2591, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 252, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 252, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[10].sv_id.constellation, 163, "incorrect value for stec_sat_list[10].sv_id.constellation, expected 163, is {}", msg.stec_sat_list[10].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 170, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 170, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], -23340, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected -23340, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -24063, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -24063, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 4650, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 4650, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], -22148, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected -22148, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 241, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 241, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 213, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 213, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 119, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 119, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 5944, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 5944, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 32142, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 32142, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 30760, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 30760, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], 11587, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected 11587, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 26, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 26, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[12].sv_id.constellation, 158, "incorrect value for stec_sat_list[12].sv_id.constellation, expected 158, is {}", msg.stec_sat_list[12].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 121, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 121, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], 3095, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected 3095, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 22769, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 22769, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -4283, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -4283, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], 14844, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected 14844, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 110, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 110, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 235, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 235, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -21032, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -21032, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -19726, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -19726, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 1297, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 1297, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -22049, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -22049, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 201, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 201, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[14].sv_id.constellation, 44, + "incorrect value for stec_sat_list[14].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[14].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 93, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 93, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], 619, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected 619, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -5744, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -5744, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], 22542, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected 22542, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], -12000, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected -12000, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 77, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 77, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[15].sv_id.constellation, 3, + "incorrect value for stec_sat_list[15].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[15].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 192, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 192, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], 10651, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected 10651, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -2889, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -2889, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], 21150, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected 21150, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], 26421, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected 26421, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 123, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 123, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[16].sv_id.constellation, 17, + "incorrect value for stec_sat_list[16].sv_id.constellation, expected 17, is {}", + msg.stec_sat_list[16].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 1, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 1, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], -19165, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected -19165, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 30229, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 30229, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -1282, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -1282, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -18382, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -18382, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 185, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 185, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[17].sv_id.constellation, 202, "incorrect value for stec_sat_list[17].sv_id.constellation, expected 202, is {}", msg.stec_sat_list[17].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 14, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 14, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], -23752, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected -23752, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 32433, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 32433, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 20441, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 20441, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], -4181, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected -4181, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 45, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 45, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 31, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 31, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 50, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 50, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -13968, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -13968, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -29322, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -29322, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], -23790, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected -23790, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 9063, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 9063, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 238, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 238, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 188, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 237, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 237, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 4737, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 4737, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], 21877, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected 21877, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], 20414, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected 20414, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -10286, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -10286, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 82, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 82, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[20].sv_id.constellation, 21, + "incorrect value for stec_sat_list[20].sv_id.constellation, expected 21, is {}", + msg.stec_sat_list[20].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 63, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 63, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDep"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a.rs new file mode 100644 index 0000000000..5939db14ca --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a.rs @@ -0,0 +1,2245 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, 39, 4, 126, 19, 111, 97, + 248, 130, 217, 217, 106, 58, 12, 65, 230, 171, 81, 95, 86, 16, 39, 84, 228, 208, 201, + 81, 219, 99, 203, 61, 182, 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, 93, 218, + 247, 158, 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, 148, 147, 72, 225, 180, 236, + 205, 201, 33, 3, 246, 204, 19, 3, 98, 4, 194, 191, 246, 76, 219, 31, 191, 113, 79, 177, + 15, 251, 33, 19, 96, 54, 58, 146, 210, 100, 249, 72, 21, 161, 211, 198, 21, 238, 111, + 107, 36, 227, 225, 213, 3, 71, 243, 63, 65, 236, 92, 77, 0, 169, 15, 182, 5, 240, 180, + 9, 122, 86, 232, 6, 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, 216, 55, 50, 181, 5, + 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, 66, 124, 168, 59, 139, 106, 118, 51, + 187, 216, 191, 158, 77, 92, 58, 253, 132, 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, + 181, 196, 23, 53, 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, 201, + 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, 22, 178, 226, 109, 88, 157, + 30, 196, 175, 26, 76, 34, 116, 220, 154, 232, 12, 179, 244, 15, 155, 196, 202, 72, 70, + 115, 10, 214, 114, 39, 245, 28, 237, 68, 136, 155, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5eb, + "Incorrect message type, expected 0x5eb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0727, + "incorrect sender id, expected 0x0727, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 4, + "incorrect value for header.iod_atmo, expected 4, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 147, + "incorrect value for header.num_msgs, expected 147, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 123, + "incorrect value for header.seq_num, expected 123, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 3905179974, + "incorrect value for header.time.tow, expected 3905179974, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 11193, + "incorrect value for header.time.wn, expected 11193, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 39, + "incorrect value for header.update_interval, expected 39, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -1951, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -1951, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -9854, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -9854, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 27353, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 27353, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 3130, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 3130, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 111, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 111, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 19, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 19, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], 24401, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected 24401, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], 4182, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected 4182, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], 21543, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected 21543, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -12060, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -12060, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 171, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 171, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 230, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 230, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 65, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 65, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], -13469, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected -13469, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -18883, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -18883, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 32066, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 32066, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 971, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 971, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 219, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 219, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 81, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 81, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 201, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 201, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], 32220, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected 32220, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], 5436, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected 5436, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], -9635, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected -9635, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -24841, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -24841, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 100, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 100, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 44, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 193, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 193, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 3718, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 3718, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 12497, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 12497, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], -10482, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected -10482, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -27495, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -27495, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 129, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 129, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 93, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 93, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 207, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 207, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], -4940, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected -4940, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -13875, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -13875, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 801, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 801, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -13066, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -13066, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 225, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 225, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 72, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 72, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 147, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 147, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -15868, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -15868, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], -2369, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected -2369, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -9396, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -9396, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], -16609, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected -16609, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 98, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 98, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 3, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 19, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 19, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -1265, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -1265, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4897, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4897, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], 13920, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected 13920, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -28102, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -28102, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 177, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 177, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 79, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 79, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 113, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 113, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], 5448, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected 5448, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], -11359, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected -11359, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], 5574, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected 5574, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 28654, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 28654, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 249, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 249, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 100, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 100, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 210, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 210, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -10783, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -10783, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], 18179, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected 18179, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], 16371, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected 16371, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -5055, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -5055, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 227, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 227, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 36, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 36, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 107, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 107, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 4009, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 4009, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], 1462, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected 1462, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], -19216, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected -19216, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 31241, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 31241, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 0, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 0, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[10].sv_id.constellation, 77, + "incorrect value for stec_sat_list[10].sv_id.constellation, expected 77, is {}", + msg.stec_sat_list[10].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 92, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 92, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], 26727, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected 26727, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -16898, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -16898, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 28241, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 28241, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], 12546, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected 12546, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 6, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 6, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 232, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 232, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 86, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 86, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 12855, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 12855, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 1461, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 1461, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 20603, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 20603, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], -3023, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected -3023, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 216, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 216, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[12].sv_id.constellation, 84, + "incorrect value for stec_sat_list[12].sv_id.constellation, expected 84, is {}", + msg.stec_sat_list[12].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 202, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 202, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], -6492, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected -6492, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 16952, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 16952, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -22404, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -22404, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], -29893, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected -29893, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 125, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 125, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 188, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 224, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 224, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -10053, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -10053, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -24897, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -24897, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 23629, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 23629, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -710, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -710, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 51, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 51, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[14].sv_id.constellation, 118, "incorrect value for stec_sat_list[14].sv_id.constellation, expected 118, is {}", msg.stec_sat_list[14].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 106, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 106, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], -26103, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected -26103, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -9539, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -9539, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], -11971, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected -11971, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], 20993, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected 20993, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 165, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 165, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[15].sv_id.constellation, 150, "incorrect value for stec_sat_list[15].sv_id.constellation, expected 150, is {}", msg.stec_sat_list[15].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], -18891, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected -18891, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -16272, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -16272, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], -22578, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected -22578, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], -2915, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected -2915, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 23, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[16].sv_id.constellation, 196, "incorrect value for stec_sat_list[16].sv_id.constellation, expected 196, is {}", msg.stec_sat_list[16].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 181, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 181, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], 15833, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected 15833, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 24920, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 24920, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -13879, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -13879, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -1206, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -1206, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 189, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 189, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[17].sv_id.constellation, 1, + "incorrect value for stec_sat_list[17].sv_id.constellation, expected 1, is {}", + msg.stec_sat_list[17].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 35, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 35, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], 14008, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected 14008, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 18996, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 18996, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 2798, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 2798, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], 5761, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected 5761, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 104, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 104, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 14, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 14, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 217, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 217, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -25256, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -25256, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -15330, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -15330, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], 6831, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected 6831, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 8780, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 8780, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 109, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 109, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 226, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 226, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 178, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 178, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 3304, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 3304, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], -2893, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected -2893, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], -25841, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected -25841, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -13628, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -13628, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 154, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 154, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[20].sv_id.constellation, 220, "incorrect value for stec_sat_list[20].sv_id.constellation, expected 220, is {}", msg.stec_sat_list[20].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 116, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 116, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[0], -10742, + "incorrect value for stec_sat_list[21].stec_coeff[0], expected -10742, is {}", + msg.stec_sat_list[21].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[1], 10098, + "incorrect value for stec_sat_list[21].stec_coeff[1], expected 10098, is {}", + msg.stec_sat_list[21].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[2], 7413, + "incorrect value for stec_sat_list[21].stec_coeff[2], expected 7413, is {}", + msg.stec_sat_list[21].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[3], 17645, + "incorrect value for stec_sat_list[21].stec_coeff[3], expected 17645, is {}", + msg.stec_sat_list[21].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[21].stec_quality_indicator, 115, "incorrect value for stec_sat_list[21].stec_quality_indicator, expected 115, is {}", msg.stec_sat_list[21].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[21].sv_id.constellation, 70, + "incorrect value for stec_sat_list[21].sv_id.constellation, expected 70, is {}", + msg.stec_sat_list[21].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[21].sv_id.sat_id, 72, + "incorrect value for stec_sat_list[21].sv_id.sat_id, expected 72, is {}", + msg.stec_sat_list[21].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a() { + { + let json_input = r#"{"crc":39816,"length":252,"msg_type":1515,"payload":"RlHE6Lkrk3snBH4Tb2H4gtnZajoMQearUV9WECdU5NDJUdtjyz22Qn3LA8EsZNx9PBVd2veez12Bhg7RMA7XmZSTSOG07M3JIQP2zBMDYgTCv/ZM2x+/cU+xD/shE2A2OpLSZPlIFaHTxhXub2sk4+HVA0fzP0HsXE0AqQ+2BfC0CXpW6AZnaP69UW4CMcpU2DcytQV7UDH04Lx9pOY4QnyoO4tqdjO72L+eTVw6/YSWpQmavdo90QFStcQXNbZwwM6nnfQjAb3ZPVhhyclK+9kOaLg2NEruCoEWsuJtWJ0exK8aTCJ03JroDLP0D5vEykhGcwrWcif1HO1E","preamble":85,"sender":1831,"header":{"time":{"tow":3905179974,"wn":11193},"num_msgs":147,"seq_num":123,"update_interval":39,"iod_atmo":4},"stec_sat_list":[{"sv_id":{"satId":126,"constellation":19},"stec_quality_indicator":111,"stec_coeff":[-1951,-9854,27353,3130]},{"sv_id":{"satId":65,"constellation":230},"stec_quality_indicator":171,"stec_coeff":[24401,4182,21543,-12060]},{"sv_id":{"satId":201,"constellation":81},"stec_quality_indicator":219,"stec_coeff":[-13469,-18883,32066,971]},{"sv_id":{"satId":193,"constellation":44},"stec_quality_indicator":100,"stec_coeff":[32220,5436,-9635,-24841]},{"sv_id":{"satId":207,"constellation":93},"stec_quality_indicator":129,"stec_coeff":[3718,12497,-10482,-27495]},{"sv_id":{"satId":147,"constellation":72},"stec_quality_indicator":225,"stec_coeff":[-4940,-13875,801,-13066]},{"sv_id":{"satId":19,"constellation":3},"stec_quality_indicator":98,"stec_coeff":[-15868,-2369,-9396,-16609]},{"sv_id":{"satId":113,"constellation":79},"stec_quality_indicator":177,"stec_coeff":[-1265,4897,13920,-28102]},{"sv_id":{"satId":210,"constellation":100},"stec_quality_indicator":249,"stec_coeff":[5448,-11359,5574,28654]},{"sv_id":{"satId":107,"constellation":36},"stec_quality_indicator":227,"stec_coeff":[-10783,18179,16371,-5055]},{"sv_id":{"satId":92,"constellation":77},"stec_quality_indicator":0,"stec_coeff":[4009,1462,-19216,31241]},{"sv_id":{"satId":86,"constellation":232},"stec_quality_indicator":6,"stec_coeff":[26727,-16898,28241,12546]},{"sv_id":{"satId":202,"constellation":84},"stec_quality_indicator":216,"stec_coeff":[12855,1461,20603,-3023]},{"sv_id":{"satId":224,"constellation":188},"stec_quality_indicator":125,"stec_coeff":[-6492,16952,-22404,-29893]},{"sv_id":{"satId":106,"constellation":118},"stec_quality_indicator":51,"stec_coeff":[-10053,-24897,23629,-710]},{"sv_id":{"satId":132,"constellation":150},"stec_quality_indicator":165,"stec_coeff":[-26103,-9539,-11971,20993]},{"sv_id":{"satId":181,"constellation":196},"stec_quality_indicator":23,"stec_coeff":[-18891,-16272,-22578,-2915]},{"sv_id":{"satId":35,"constellation":1},"stec_quality_indicator":189,"stec_coeff":[15833,24920,-13879,-1206]},{"sv_id":{"satId":217,"constellation":14},"stec_quality_indicator":104,"stec_coeff":[14008,18996,2798,5761]},{"sv_id":{"satId":178,"constellation":226},"stec_quality_indicator":109,"stec_coeff":[-25256,-15330,6831,8780]},{"sv_id":{"satId":116,"constellation":220},"stec_quality_indicator":154,"stec_coeff":[3304,-2893,-25841,-13628]},{"sv_id":{"satId":72,"constellation":70},"stec_quality_indicator":115,"stec_coeff":[-10742,10098,7413,17645]}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5eb, + "Incorrect message type, expected 0x5eb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0727, + "incorrect sender id, expected 0x0727, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 4, + "incorrect value for header.iod_atmo, expected 4, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 147, + "incorrect value for header.num_msgs, expected 147, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 123, + "incorrect value for header.seq_num, expected 123, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 3905179974, + "incorrect value for header.time.tow, expected 3905179974, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 11193, + "incorrect value for header.time.wn, expected 11193, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 39, + "incorrect value for header.update_interval, expected 39, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -1951, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -1951, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -9854, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -9854, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 27353, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 27353, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 3130, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 3130, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 111, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 111, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 19, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 19, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], 24401, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected 24401, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], 4182, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected 4182, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], 21543, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected 21543, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -12060, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -12060, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 171, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 171, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 230, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 230, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 65, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 65, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], -13469, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected -13469, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -18883, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -18883, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 32066, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 32066, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 971, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 971, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 219, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 219, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 81, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 81, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 201, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 201, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], 32220, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected 32220, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], 5436, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected 5436, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], -9635, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected -9635, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -24841, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -24841, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 100, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 100, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 44, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 193, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 193, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 3718, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 3718, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 12497, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 12497, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], -10482, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected -10482, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -27495, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -27495, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 129, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 129, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 93, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 93, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 207, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 207, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], -4940, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected -4940, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -13875, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -13875, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 801, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 801, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -13066, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -13066, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 225, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 225, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 72, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 72, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 147, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 147, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -15868, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -15868, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], -2369, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected -2369, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -9396, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -9396, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], -16609, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected -16609, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 98, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 98, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 3, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 19, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 19, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -1265, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -1265, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4897, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4897, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], 13920, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected 13920, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -28102, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -28102, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 177, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 177, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 79, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 79, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 113, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 113, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], 5448, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected 5448, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], -11359, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected -11359, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], 5574, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected 5574, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 28654, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 28654, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 249, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 249, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 100, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 100, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 210, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 210, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -10783, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -10783, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], 18179, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected 18179, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], 16371, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected 16371, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -5055, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -5055, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 227, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 227, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 36, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 36, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 107, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 107, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 4009, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 4009, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], 1462, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected 1462, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], -19216, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected -19216, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 31241, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 31241, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 0, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 0, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[10].sv_id.constellation, 77, + "incorrect value for stec_sat_list[10].sv_id.constellation, expected 77, is {}", + msg.stec_sat_list[10].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 92, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 92, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], 26727, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected 26727, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -16898, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -16898, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 28241, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 28241, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], 12546, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected 12546, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 6, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 6, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 232, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 232, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 86, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 86, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 12855, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 12855, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 1461, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 1461, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 20603, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 20603, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], -3023, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected -3023, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 216, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 216, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[12].sv_id.constellation, 84, + "incorrect value for stec_sat_list[12].sv_id.constellation, expected 84, is {}", + msg.stec_sat_list[12].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 202, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 202, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], -6492, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected -6492, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 16952, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 16952, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -22404, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -22404, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], -29893, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected -29893, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 125, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 125, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 188, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 224, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 224, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -10053, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -10053, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -24897, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -24897, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 23629, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 23629, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -710, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -710, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 51, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 51, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[14].sv_id.constellation, 118, "incorrect value for stec_sat_list[14].sv_id.constellation, expected 118, is {}", msg.stec_sat_list[14].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 106, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 106, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], -26103, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected -26103, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -9539, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -9539, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], -11971, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected -11971, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], 20993, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected 20993, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 165, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 165, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[15].sv_id.constellation, 150, "incorrect value for stec_sat_list[15].sv_id.constellation, expected 150, is {}", msg.stec_sat_list[15].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], -18891, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected -18891, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -16272, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -16272, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], -22578, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected -22578, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], -2915, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected -2915, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 23, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[16].sv_id.constellation, 196, "incorrect value for stec_sat_list[16].sv_id.constellation, expected 196, is {}", msg.stec_sat_list[16].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 181, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 181, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], 15833, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected 15833, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 24920, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 24920, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -13879, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -13879, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -1206, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -1206, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 189, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 189, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[17].sv_id.constellation, 1, + "incorrect value for stec_sat_list[17].sv_id.constellation, expected 1, is {}", + msg.stec_sat_list[17].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 35, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 35, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], 14008, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected 14008, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 18996, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 18996, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 2798, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 2798, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], 5761, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected 5761, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 104, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 104, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 14, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 14, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 217, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 217, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -25256, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -25256, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -15330, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -15330, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], 6831, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected 6831, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 8780, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 8780, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 109, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 109, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 226, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 226, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 178, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 178, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 3304, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 3304, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], -2893, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected -2893, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], -25841, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected -25841, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -13628, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -13628, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 154, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 154, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[20].sv_id.constellation, 220, "incorrect value for stec_sat_list[20].sv_id.constellation, expected 220, is {}", msg.stec_sat_list[20].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 116, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 116, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[0], -10742, + "incorrect value for stec_sat_list[21].stec_coeff[0], expected -10742, is {}", + msg.stec_sat_list[21].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[1], 10098, + "incorrect value for stec_sat_list[21].stec_coeff[1], expected 10098, is {}", + msg.stec_sat_list[21].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[2], 7413, + "incorrect value for stec_sat_list[21].stec_coeff[2], expected 7413, is {}", + msg.stec_sat_list[21].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[3], 17645, + "incorrect value for stec_sat_list[21].stec_coeff[3], expected 17645, is {}", + msg.stec_sat_list[21].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[21].stec_quality_indicator, 115, "incorrect value for stec_sat_list[21].stec_quality_indicator, expected 115, is {}", msg.stec_sat_list[21].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[21].sv_id.constellation, 70, + "incorrect value for stec_sat_list[21].sv_id.constellation, expected 70, is {}", + msg.stec_sat_list[21].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[21].sv_id.sat_id, 72, + "incorrect value for stec_sat_list[21].sv_id.sat_id, expected 72, is {}", + msg.stec_sat_list[21].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 235, 5, 39, 7, 252, 70, 81, 196, 232, 185, 43, 147, 123, 39, 4, 126, 19, 111, 97, + 248, 130, 217, 217, 106, 58, 12, 65, 230, 171, 81, 95, 86, 16, 39, 84, 228, 208, 201, + 81, 219, 99, 203, 61, 182, 66, 125, 203, 3, 193, 44, 100, 220, 125, 60, 21, 93, 218, + 247, 158, 207, 93, 129, 134, 14, 209, 48, 14, 215, 153, 148, 147, 72, 225, 180, 236, + 205, 201, 33, 3, 246, 204, 19, 3, 98, 4, 194, 191, 246, 76, 219, 31, 191, 113, 79, 177, + 15, 251, 33, 19, 96, 54, 58, 146, 210, 100, 249, 72, 21, 161, 211, 198, 21, 238, 111, + 107, 36, 227, 225, 213, 3, 71, 243, 63, 65, 236, 92, 77, 0, 169, 15, 182, 5, 240, 180, + 9, 122, 86, 232, 6, 103, 104, 254, 189, 81, 110, 2, 49, 202, 84, 216, 55, 50, 181, 5, + 123, 80, 49, 244, 224, 188, 125, 164, 230, 56, 66, 124, 168, 59, 139, 106, 118, 51, + 187, 216, 191, 158, 77, 92, 58, 253, 132, 150, 165, 9, 154, 189, 218, 61, 209, 1, 82, + 181, 196, 23, 53, 182, 112, 192, 206, 167, 157, 244, 35, 1, 189, 217, 61, 88, 97, 201, + 201, 74, 251, 217, 14, 104, 184, 54, 52, 74, 238, 10, 129, 22, 178, 226, 109, 88, 157, + 30, 196, 175, 26, 76, 34, 116, 220, 154, 232, 12, 179, 244, 15, 155, 196, 202, 72, 70, + 115, 10, 214, 114, 39, 245, 28, 237, 68, 136, 155, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrStecCorrectionDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrStecCorrectionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5eb, + "Incorrect message type, expected 0x5eb, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0727, + "incorrect sender id, expected 0x0727, is {sender_id}" + ); + assert_eq!( + msg.header.iod_atmo, 4, + "incorrect value for header.iod_atmo, expected 4, is {}", + msg.header.iod_atmo + ); + assert_eq!( + msg.header.num_msgs, 147, + "incorrect value for header.num_msgs, expected 147, is {}", + msg.header.num_msgs + ); + assert_eq!( + msg.header.seq_num, 123, + "incorrect value for header.seq_num, expected 123, is {}", + msg.header.seq_num + ); + assert_eq!( + msg.header.time.tow, 3905179974, + "incorrect value for header.time.tow, expected 3905179974, is {}", + msg.header.time.tow + ); + assert_eq!( + msg.header.time.wn, 11193, + "incorrect value for header.time.wn, expected 11193, is {}", + msg.header.time.wn + ); + assert_eq!( + msg.header.update_interval, 39, + "incorrect value for header.update_interval, expected 39, is {}", + msg.header.update_interval + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[0], -1951, + "incorrect value for stec_sat_list[0].stec_coeff[0], expected -1951, is {}", + msg.stec_sat_list[0].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[1], -9854, + "incorrect value for stec_sat_list[0].stec_coeff[1], expected -9854, is {}", + msg.stec_sat_list[0].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[2], 27353, + "incorrect value for stec_sat_list[0].stec_coeff[2], expected 27353, is {}", + msg.stec_sat_list[0].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[0].stec_coeff[3], 3130, + "incorrect value for stec_sat_list[0].stec_coeff[3], expected 3130, is {}", + msg.stec_sat_list[0].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[0].stec_quality_indicator, 111, "incorrect value for stec_sat_list[0].stec_quality_indicator, expected 111, is {}", msg.stec_sat_list[0].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[0].sv_id.constellation, 19, + "incorrect value for stec_sat_list[0].sv_id.constellation, expected 19, is {}", + msg.stec_sat_list[0].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[0].sv_id.sat_id, 126, + "incorrect value for stec_sat_list[0].sv_id.sat_id, expected 126, is {}", + msg.stec_sat_list[0].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[0], 24401, + "incorrect value for stec_sat_list[1].stec_coeff[0], expected 24401, is {}", + msg.stec_sat_list[1].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[1], 4182, + "incorrect value for stec_sat_list[1].stec_coeff[1], expected 4182, is {}", + msg.stec_sat_list[1].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[2], 21543, + "incorrect value for stec_sat_list[1].stec_coeff[2], expected 21543, is {}", + msg.stec_sat_list[1].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[1].stec_coeff[3], -12060, + "incorrect value for stec_sat_list[1].stec_coeff[3], expected -12060, is {}", + msg.stec_sat_list[1].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[1].stec_quality_indicator, 171, "incorrect value for stec_sat_list[1].stec_quality_indicator, expected 171, is {}", msg.stec_sat_list[1].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[1].sv_id.constellation, 230, + "incorrect value for stec_sat_list[1].sv_id.constellation, expected 230, is {}", + msg.stec_sat_list[1].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[1].sv_id.sat_id, 65, + "incorrect value for stec_sat_list[1].sv_id.sat_id, expected 65, is {}", + msg.stec_sat_list[1].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[0], -13469, + "incorrect value for stec_sat_list[2].stec_coeff[0], expected -13469, is {}", + msg.stec_sat_list[2].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[1], -18883, + "incorrect value for stec_sat_list[2].stec_coeff[1], expected -18883, is {}", + msg.stec_sat_list[2].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[2], 32066, + "incorrect value for stec_sat_list[2].stec_coeff[2], expected 32066, is {}", + msg.stec_sat_list[2].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[2].stec_coeff[3], 971, + "incorrect value for stec_sat_list[2].stec_coeff[3], expected 971, is {}", + msg.stec_sat_list[2].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[2].stec_quality_indicator, 219, "incorrect value for stec_sat_list[2].stec_quality_indicator, expected 219, is {}", msg.stec_sat_list[2].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[2].sv_id.constellation, 81, + "incorrect value for stec_sat_list[2].sv_id.constellation, expected 81, is {}", + msg.stec_sat_list[2].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[2].sv_id.sat_id, 201, + "incorrect value for stec_sat_list[2].sv_id.sat_id, expected 201, is {}", + msg.stec_sat_list[2].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[0], 32220, + "incorrect value for stec_sat_list[3].stec_coeff[0], expected 32220, is {}", + msg.stec_sat_list[3].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[1], 5436, + "incorrect value for stec_sat_list[3].stec_coeff[1], expected 5436, is {}", + msg.stec_sat_list[3].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[2], -9635, + "incorrect value for stec_sat_list[3].stec_coeff[2], expected -9635, is {}", + msg.stec_sat_list[3].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[3].stec_coeff[3], -24841, + "incorrect value for stec_sat_list[3].stec_coeff[3], expected -24841, is {}", + msg.stec_sat_list[3].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[3].stec_quality_indicator, 100, "incorrect value for stec_sat_list[3].stec_quality_indicator, expected 100, is {}", msg.stec_sat_list[3].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[3].sv_id.constellation, 44, + "incorrect value for stec_sat_list[3].sv_id.constellation, expected 44, is {}", + msg.stec_sat_list[3].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[3].sv_id.sat_id, 193, + "incorrect value for stec_sat_list[3].sv_id.sat_id, expected 193, is {}", + msg.stec_sat_list[3].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[0], 3718, + "incorrect value for stec_sat_list[4].stec_coeff[0], expected 3718, is {}", + msg.stec_sat_list[4].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[1], 12497, + "incorrect value for stec_sat_list[4].stec_coeff[1], expected 12497, is {}", + msg.stec_sat_list[4].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[2], -10482, + "incorrect value for stec_sat_list[4].stec_coeff[2], expected -10482, is {}", + msg.stec_sat_list[4].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[4].stec_coeff[3], -27495, + "incorrect value for stec_sat_list[4].stec_coeff[3], expected -27495, is {}", + msg.stec_sat_list[4].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[4].stec_quality_indicator, 129, "incorrect value for stec_sat_list[4].stec_quality_indicator, expected 129, is {}", msg.stec_sat_list[4].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[4].sv_id.constellation, 93, + "incorrect value for stec_sat_list[4].sv_id.constellation, expected 93, is {}", + msg.stec_sat_list[4].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[4].sv_id.sat_id, 207, + "incorrect value for stec_sat_list[4].sv_id.sat_id, expected 207, is {}", + msg.stec_sat_list[4].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[0], -4940, + "incorrect value for stec_sat_list[5].stec_coeff[0], expected -4940, is {}", + msg.stec_sat_list[5].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[1], -13875, + "incorrect value for stec_sat_list[5].stec_coeff[1], expected -13875, is {}", + msg.stec_sat_list[5].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[2], 801, + "incorrect value for stec_sat_list[5].stec_coeff[2], expected 801, is {}", + msg.stec_sat_list[5].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[5].stec_coeff[3], -13066, + "incorrect value for stec_sat_list[5].stec_coeff[3], expected -13066, is {}", + msg.stec_sat_list[5].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[5].stec_quality_indicator, 225, "incorrect value for stec_sat_list[5].stec_quality_indicator, expected 225, is {}", msg.stec_sat_list[5].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[5].sv_id.constellation, 72, + "incorrect value for stec_sat_list[5].sv_id.constellation, expected 72, is {}", + msg.stec_sat_list[5].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[5].sv_id.sat_id, 147, + "incorrect value for stec_sat_list[5].sv_id.sat_id, expected 147, is {}", + msg.stec_sat_list[5].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[0], -15868, + "incorrect value for stec_sat_list[6].stec_coeff[0], expected -15868, is {}", + msg.stec_sat_list[6].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[1], -2369, + "incorrect value for stec_sat_list[6].stec_coeff[1], expected -2369, is {}", + msg.stec_sat_list[6].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[2], -9396, + "incorrect value for stec_sat_list[6].stec_coeff[2], expected -9396, is {}", + msg.stec_sat_list[6].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[6].stec_coeff[3], -16609, + "incorrect value for stec_sat_list[6].stec_coeff[3], expected -16609, is {}", + msg.stec_sat_list[6].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[6].stec_quality_indicator, 98, "incorrect value for stec_sat_list[6].stec_quality_indicator, expected 98, is {}", msg.stec_sat_list[6].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[6].sv_id.constellation, 3, + "incorrect value for stec_sat_list[6].sv_id.constellation, expected 3, is {}", + msg.stec_sat_list[6].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[6].sv_id.sat_id, 19, + "incorrect value for stec_sat_list[6].sv_id.sat_id, expected 19, is {}", + msg.stec_sat_list[6].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[0], -1265, + "incorrect value for stec_sat_list[7].stec_coeff[0], expected -1265, is {}", + msg.stec_sat_list[7].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[1], 4897, + "incorrect value for stec_sat_list[7].stec_coeff[1], expected 4897, is {}", + msg.stec_sat_list[7].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[2], 13920, + "incorrect value for stec_sat_list[7].stec_coeff[2], expected 13920, is {}", + msg.stec_sat_list[7].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[7].stec_coeff[3], -28102, + "incorrect value for stec_sat_list[7].stec_coeff[3], expected -28102, is {}", + msg.stec_sat_list[7].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[7].stec_quality_indicator, 177, "incorrect value for stec_sat_list[7].stec_quality_indicator, expected 177, is {}", msg.stec_sat_list[7].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[7].sv_id.constellation, 79, + "incorrect value for stec_sat_list[7].sv_id.constellation, expected 79, is {}", + msg.stec_sat_list[7].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[7].sv_id.sat_id, 113, + "incorrect value for stec_sat_list[7].sv_id.sat_id, expected 113, is {}", + msg.stec_sat_list[7].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[0], 5448, + "incorrect value for stec_sat_list[8].stec_coeff[0], expected 5448, is {}", + msg.stec_sat_list[8].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[1], -11359, + "incorrect value for stec_sat_list[8].stec_coeff[1], expected -11359, is {}", + msg.stec_sat_list[8].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[2], 5574, + "incorrect value for stec_sat_list[8].stec_coeff[2], expected 5574, is {}", + msg.stec_sat_list[8].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[8].stec_coeff[3], 28654, + "incorrect value for stec_sat_list[8].stec_coeff[3], expected 28654, is {}", + msg.stec_sat_list[8].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[8].stec_quality_indicator, 249, "incorrect value for stec_sat_list[8].stec_quality_indicator, expected 249, is {}", msg.stec_sat_list[8].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[8].sv_id.constellation, 100, + "incorrect value for stec_sat_list[8].sv_id.constellation, expected 100, is {}", + msg.stec_sat_list[8].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[8].sv_id.sat_id, 210, + "incorrect value for stec_sat_list[8].sv_id.sat_id, expected 210, is {}", + msg.stec_sat_list[8].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[0], -10783, + "incorrect value for stec_sat_list[9].stec_coeff[0], expected -10783, is {}", + msg.stec_sat_list[9].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[1], 18179, + "incorrect value for stec_sat_list[9].stec_coeff[1], expected 18179, is {}", + msg.stec_sat_list[9].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[2], 16371, + "incorrect value for stec_sat_list[9].stec_coeff[2], expected 16371, is {}", + msg.stec_sat_list[9].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[9].stec_coeff[3], -5055, + "incorrect value for stec_sat_list[9].stec_coeff[3], expected -5055, is {}", + msg.stec_sat_list[9].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[9].stec_quality_indicator, 227, "incorrect value for stec_sat_list[9].stec_quality_indicator, expected 227, is {}", msg.stec_sat_list[9].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[9].sv_id.constellation, 36, + "incorrect value for stec_sat_list[9].sv_id.constellation, expected 36, is {}", + msg.stec_sat_list[9].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[9].sv_id.sat_id, 107, + "incorrect value for stec_sat_list[9].sv_id.sat_id, expected 107, is {}", + msg.stec_sat_list[9].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[0], 4009, + "incorrect value for stec_sat_list[10].stec_coeff[0], expected 4009, is {}", + msg.stec_sat_list[10].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[1], 1462, + "incorrect value for stec_sat_list[10].stec_coeff[1], expected 1462, is {}", + msg.stec_sat_list[10].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[2], -19216, + "incorrect value for stec_sat_list[10].stec_coeff[2], expected -19216, is {}", + msg.stec_sat_list[10].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[10].stec_coeff[3], 31241, + "incorrect value for stec_sat_list[10].stec_coeff[3], expected 31241, is {}", + msg.stec_sat_list[10].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[10].stec_quality_indicator, 0, "incorrect value for stec_sat_list[10].stec_quality_indicator, expected 0, is {}", msg.stec_sat_list[10].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[10].sv_id.constellation, 77, + "incorrect value for stec_sat_list[10].sv_id.constellation, expected 77, is {}", + msg.stec_sat_list[10].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[10].sv_id.sat_id, 92, + "incorrect value for stec_sat_list[10].sv_id.sat_id, expected 92, is {}", + msg.stec_sat_list[10].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[0], 26727, + "incorrect value for stec_sat_list[11].stec_coeff[0], expected 26727, is {}", + msg.stec_sat_list[11].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[1], -16898, + "incorrect value for stec_sat_list[11].stec_coeff[1], expected -16898, is {}", + msg.stec_sat_list[11].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[2], 28241, + "incorrect value for stec_sat_list[11].stec_coeff[2], expected 28241, is {}", + msg.stec_sat_list[11].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[11].stec_coeff[3], 12546, + "incorrect value for stec_sat_list[11].stec_coeff[3], expected 12546, is {}", + msg.stec_sat_list[11].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[11].stec_quality_indicator, 6, "incorrect value for stec_sat_list[11].stec_quality_indicator, expected 6, is {}", msg.stec_sat_list[11].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[11].sv_id.constellation, 232, "incorrect value for stec_sat_list[11].sv_id.constellation, expected 232, is {}", msg.stec_sat_list[11].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[11].sv_id.sat_id, 86, + "incorrect value for stec_sat_list[11].sv_id.sat_id, expected 86, is {}", + msg.stec_sat_list[11].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[0], 12855, + "incorrect value for stec_sat_list[12].stec_coeff[0], expected 12855, is {}", + msg.stec_sat_list[12].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[1], 1461, + "incorrect value for stec_sat_list[12].stec_coeff[1], expected 1461, is {}", + msg.stec_sat_list[12].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[2], 20603, + "incorrect value for stec_sat_list[12].stec_coeff[2], expected 20603, is {}", + msg.stec_sat_list[12].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[12].stec_coeff[3], -3023, + "incorrect value for stec_sat_list[12].stec_coeff[3], expected -3023, is {}", + msg.stec_sat_list[12].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[12].stec_quality_indicator, 216, "incorrect value for stec_sat_list[12].stec_quality_indicator, expected 216, is {}", msg.stec_sat_list[12].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[12].sv_id.constellation, 84, + "incorrect value for stec_sat_list[12].sv_id.constellation, expected 84, is {}", + msg.stec_sat_list[12].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[12].sv_id.sat_id, 202, + "incorrect value for stec_sat_list[12].sv_id.sat_id, expected 202, is {}", + msg.stec_sat_list[12].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[0], -6492, + "incorrect value for stec_sat_list[13].stec_coeff[0], expected -6492, is {}", + msg.stec_sat_list[13].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[1], 16952, + "incorrect value for stec_sat_list[13].stec_coeff[1], expected 16952, is {}", + msg.stec_sat_list[13].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[2], -22404, + "incorrect value for stec_sat_list[13].stec_coeff[2], expected -22404, is {}", + msg.stec_sat_list[13].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[13].stec_coeff[3], -29893, + "incorrect value for stec_sat_list[13].stec_coeff[3], expected -29893, is {}", + msg.stec_sat_list[13].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[13].stec_quality_indicator, 125, "incorrect value for stec_sat_list[13].stec_quality_indicator, expected 125, is {}", msg.stec_sat_list[13].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[13].sv_id.constellation, 188, "incorrect value for stec_sat_list[13].sv_id.constellation, expected 188, is {}", msg.stec_sat_list[13].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[13].sv_id.sat_id, 224, + "incorrect value for stec_sat_list[13].sv_id.sat_id, expected 224, is {}", + msg.stec_sat_list[13].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[0], -10053, + "incorrect value for stec_sat_list[14].stec_coeff[0], expected -10053, is {}", + msg.stec_sat_list[14].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[1], -24897, + "incorrect value for stec_sat_list[14].stec_coeff[1], expected -24897, is {}", + msg.stec_sat_list[14].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[2], 23629, + "incorrect value for stec_sat_list[14].stec_coeff[2], expected 23629, is {}", + msg.stec_sat_list[14].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[14].stec_coeff[3], -710, + "incorrect value for stec_sat_list[14].stec_coeff[3], expected -710, is {}", + msg.stec_sat_list[14].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[14].stec_quality_indicator, 51, "incorrect value for stec_sat_list[14].stec_quality_indicator, expected 51, is {}", msg.stec_sat_list[14].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[14].sv_id.constellation, 118, "incorrect value for stec_sat_list[14].sv_id.constellation, expected 118, is {}", msg.stec_sat_list[14].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[14].sv_id.sat_id, 106, + "incorrect value for stec_sat_list[14].sv_id.sat_id, expected 106, is {}", + msg.stec_sat_list[14].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[0], -26103, + "incorrect value for stec_sat_list[15].stec_coeff[0], expected -26103, is {}", + msg.stec_sat_list[15].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[1], -9539, + "incorrect value for stec_sat_list[15].stec_coeff[1], expected -9539, is {}", + msg.stec_sat_list[15].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[2], -11971, + "incorrect value for stec_sat_list[15].stec_coeff[2], expected -11971, is {}", + msg.stec_sat_list[15].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[15].stec_coeff[3], 20993, + "incorrect value for stec_sat_list[15].stec_coeff[3], expected 20993, is {}", + msg.stec_sat_list[15].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[15].stec_quality_indicator, 165, "incorrect value for stec_sat_list[15].stec_quality_indicator, expected 165, is {}", msg.stec_sat_list[15].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[15].sv_id.constellation, 150, "incorrect value for stec_sat_list[15].sv_id.constellation, expected 150, is {}", msg.stec_sat_list[15].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[15].sv_id.sat_id, 132, + "incorrect value for stec_sat_list[15].sv_id.sat_id, expected 132, is {}", + msg.stec_sat_list[15].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[0], -18891, + "incorrect value for stec_sat_list[16].stec_coeff[0], expected -18891, is {}", + msg.stec_sat_list[16].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[1], -16272, + "incorrect value for stec_sat_list[16].stec_coeff[1], expected -16272, is {}", + msg.stec_sat_list[16].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[2], -22578, + "incorrect value for stec_sat_list[16].stec_coeff[2], expected -22578, is {}", + msg.stec_sat_list[16].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[16].stec_coeff[3], -2915, + "incorrect value for stec_sat_list[16].stec_coeff[3], expected -2915, is {}", + msg.stec_sat_list[16].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[16].stec_quality_indicator, 23, "incorrect value for stec_sat_list[16].stec_quality_indicator, expected 23, is {}", msg.stec_sat_list[16].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[16].sv_id.constellation, 196, "incorrect value for stec_sat_list[16].sv_id.constellation, expected 196, is {}", msg.stec_sat_list[16].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[16].sv_id.sat_id, 181, + "incorrect value for stec_sat_list[16].sv_id.sat_id, expected 181, is {}", + msg.stec_sat_list[16].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[0], 15833, + "incorrect value for stec_sat_list[17].stec_coeff[0], expected 15833, is {}", + msg.stec_sat_list[17].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[1], 24920, + "incorrect value for stec_sat_list[17].stec_coeff[1], expected 24920, is {}", + msg.stec_sat_list[17].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[2], -13879, + "incorrect value for stec_sat_list[17].stec_coeff[2], expected -13879, is {}", + msg.stec_sat_list[17].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[17].stec_coeff[3], -1206, + "incorrect value for stec_sat_list[17].stec_coeff[3], expected -1206, is {}", + msg.stec_sat_list[17].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[17].stec_quality_indicator, 189, "incorrect value for stec_sat_list[17].stec_quality_indicator, expected 189, is {}", msg.stec_sat_list[17].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[17].sv_id.constellation, 1, + "incorrect value for stec_sat_list[17].sv_id.constellation, expected 1, is {}", + msg.stec_sat_list[17].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[17].sv_id.sat_id, 35, + "incorrect value for stec_sat_list[17].sv_id.sat_id, expected 35, is {}", + msg.stec_sat_list[17].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[0], 14008, + "incorrect value for stec_sat_list[18].stec_coeff[0], expected 14008, is {}", + msg.stec_sat_list[18].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[1], 18996, + "incorrect value for stec_sat_list[18].stec_coeff[1], expected 18996, is {}", + msg.stec_sat_list[18].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[2], 2798, + "incorrect value for stec_sat_list[18].stec_coeff[2], expected 2798, is {}", + msg.stec_sat_list[18].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[18].stec_coeff[3], 5761, + "incorrect value for stec_sat_list[18].stec_coeff[3], expected 5761, is {}", + msg.stec_sat_list[18].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[18].stec_quality_indicator, 104, "incorrect value for stec_sat_list[18].stec_quality_indicator, expected 104, is {}", msg.stec_sat_list[18].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[18].sv_id.constellation, 14, + "incorrect value for stec_sat_list[18].sv_id.constellation, expected 14, is {}", + msg.stec_sat_list[18].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[18].sv_id.sat_id, 217, + "incorrect value for stec_sat_list[18].sv_id.sat_id, expected 217, is {}", + msg.stec_sat_list[18].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[0], -25256, + "incorrect value for stec_sat_list[19].stec_coeff[0], expected -25256, is {}", + msg.stec_sat_list[19].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[1], -15330, + "incorrect value for stec_sat_list[19].stec_coeff[1], expected -15330, is {}", + msg.stec_sat_list[19].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[2], 6831, + "incorrect value for stec_sat_list[19].stec_coeff[2], expected 6831, is {}", + msg.stec_sat_list[19].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[19].stec_coeff[3], 8780, + "incorrect value for stec_sat_list[19].stec_coeff[3], expected 8780, is {}", + msg.stec_sat_list[19].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[19].stec_quality_indicator, 109, "incorrect value for stec_sat_list[19].stec_quality_indicator, expected 109, is {}", msg.stec_sat_list[19].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[19].sv_id.constellation, 226, "incorrect value for stec_sat_list[19].sv_id.constellation, expected 226, is {}", msg.stec_sat_list[19].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[19].sv_id.sat_id, 178, + "incorrect value for stec_sat_list[19].sv_id.sat_id, expected 178, is {}", + msg.stec_sat_list[19].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[0], 3304, + "incorrect value for stec_sat_list[20].stec_coeff[0], expected 3304, is {}", + msg.stec_sat_list[20].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[1], -2893, + "incorrect value for stec_sat_list[20].stec_coeff[1], expected -2893, is {}", + msg.stec_sat_list[20].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[2], -25841, + "incorrect value for stec_sat_list[20].stec_coeff[2], expected -25841, is {}", + msg.stec_sat_list[20].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[20].stec_coeff[3], -13628, + "incorrect value for stec_sat_list[20].stec_coeff[3], expected -13628, is {}", + msg.stec_sat_list[20].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[20].stec_quality_indicator, 154, "incorrect value for stec_sat_list[20].stec_quality_indicator, expected 154, is {}", msg.stec_sat_list[20].stec_quality_indicator); + assert_eq!(msg.stec_sat_list[20].sv_id.constellation, 220, "incorrect value for stec_sat_list[20].sv_id.constellation, expected 220, is {}", msg.stec_sat_list[20].sv_id.constellation); + assert_eq!( + msg.stec_sat_list[20].sv_id.sat_id, 116, + "incorrect value for stec_sat_list[20].sv_id.sat_id, expected 116, is {}", + msg.stec_sat_list[20].sv_id.sat_id + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[0], -10742, + "incorrect value for stec_sat_list[21].stec_coeff[0], expected -10742, is {}", + msg.stec_sat_list[21].stec_coeff[0] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[1], 10098, + "incorrect value for stec_sat_list[21].stec_coeff[1], expected 10098, is {}", + msg.stec_sat_list[21].stec_coeff[1] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[2], 7413, + "incorrect value for stec_sat_list[21].stec_coeff[2], expected 7413, is {}", + msg.stec_sat_list[21].stec_coeff[2] + ); + assert_eq!( + msg.stec_sat_list[21].stec_coeff[3], 17645, + "incorrect value for stec_sat_list[21].stec_coeff[3], expected 17645, is {}", + msg.stec_sat_list[21].stec_coeff[3] + ); + assert_eq!(msg.stec_sat_list[21].stec_quality_indicator, 115, "incorrect value for stec_sat_list[21].stec_quality_indicator, expected 115, is {}", msg.stec_sat_list[21].stec_quality_indicator); + assert_eq!( + msg.stec_sat_list[21].sv_id.constellation, 70, + "incorrect value for stec_sat_list[21].sv_id.constellation, expected 70, is {}", + msg.stec_sat_list[21].sv_id.constellation + ); + assert_eq!( + msg.stec_sat_list[21].sv_id.sat_id, 72, + "incorrect value for stec_sat_list[21].sv_id.sat_id, expected 72, is {}", + msg.stec_sat_list[21].sv_id.sat_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrStecCorrectionDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a.rs new file mode 100644 index 0000000000..cd4c772fbf --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a.rs @@ -0,0 +1,304 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, 185, 9, 181, 162, 240, 65, 19, 255, + 143, 21, 191, 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrTileDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f6, + "Incorrect message type, expected 0x5f6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x85c8, + "incorrect sender id, expected 0x85c8, is {sender_id}" + ); + assert_eq!( + msg.bitmask, 11259375, + "incorrect value for bitmask, expected 11259375, is {}", + msg.bitmask + ); + assert_eq!( + msg.cols, 48917, + "incorrect value for cols, expected 48917, is {}", + msg.cols + ); + assert_eq!( + msg.corner_nw_lat, -18168, + "incorrect value for corner_nw_lat, expected -18168, is {}", + msg.corner_nw_lat + ); + assert_eq!( + msg.corner_nw_lon, -19191, + "incorrect value for corner_nw_lon, expected -19191, is {}", + msg.corner_nw_lon + ); + assert_eq!( + msg.rows, 36863, + "incorrect value for rows, expected 36863, is {}", + msg.rows + ); + assert_eq!( + msg.spacing_lat, 61602, + "incorrect value for spacing_lat, expected 61602, is {}", + msg.spacing_lat + ); + assert_eq!( + msg.spacing_lon, 4929, + "incorrect value for spacing_lon, expected 4929, is {}", + msg.spacing_lon + ); + assert_eq!( + msg.tile_id, 63410, + "incorrect value for tile_id, expected 63410, is {}", + msg.tile_id + ); + assert_eq!( + msg.tile_set_id, 48697, + "incorrect value for tile_set_id, expected 48697, is {}", + msg.tile_set_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrTileDefinitionDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a() { + { + let json_input = r#"{"crc":39489,"length":24,"msg_type":1526,"payload":"Ob6y9wi5CbWi8EET/48Vv+/NqwAAAAAA","preamble":85,"sender":34248,"tile_set_id":48697,"tile_id":63410,"corner_nw_lat":-18168,"corner_nw_lon":-19191,"spacing_lat":61602,"spacing_lon":4929,"rows":36863,"cols":48917,"bitmask":11259375}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgSsrTileDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f6, + "Incorrect message type, expected 0x5f6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x85c8, + "incorrect sender id, expected 0x85c8, is {sender_id}" + ); + assert_eq!( + msg.bitmask, 11259375, + "incorrect value for bitmask, expected 11259375, is {}", + msg.bitmask + ); + assert_eq!( + msg.cols, 48917, + "incorrect value for cols, expected 48917, is {}", + msg.cols + ); + assert_eq!( + msg.corner_nw_lat, -18168, + "incorrect value for corner_nw_lat, expected -18168, is {}", + msg.corner_nw_lat + ); + assert_eq!( + msg.corner_nw_lon, -19191, + "incorrect value for corner_nw_lon, expected -19191, is {}", + msg.corner_nw_lon + ); + assert_eq!( + msg.rows, 36863, + "incorrect value for rows, expected 36863, is {}", + msg.rows + ); + assert_eq!( + msg.spacing_lat, 61602, + "incorrect value for spacing_lat, expected 61602, is {}", + msg.spacing_lat + ); + assert_eq!( + msg.spacing_lon, 4929, + "incorrect value for spacing_lon, expected 4929, is {}", + msg.spacing_lon + ); + assert_eq!( + msg.tile_id, 63410, + "incorrect value for tile_id, expected 63410, is {}", + msg.tile_id + ); + assert_eq!( + msg.tile_set_id, 48697, + "incorrect value for tile_set_id, expected 48697, is {}", + msg.tile_set_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrTileDefinitionDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 246, 5, 200, 133, 24, 57, 190, 178, 247, 8, 185, 9, 181, 162, 240, 65, 19, 255, + 143, 21, 191, 239, 205, 171, 0, 0, 0, 0, 0, 65, 154, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgSsrTileDefinitionDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgSsrTileDefinitionDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x5f6, + "Incorrect message type, expected 0x5f6, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x85c8, + "incorrect sender id, expected 0x85c8, is {sender_id}" + ); + assert_eq!( + msg.bitmask, 11259375, + "incorrect value for bitmask, expected 11259375, is {}", + msg.bitmask + ); + assert_eq!( + msg.cols, 48917, + "incorrect value for cols, expected 48917, is {}", + msg.cols + ); + assert_eq!( + msg.corner_nw_lat, -18168, + "incorrect value for corner_nw_lat, expected -18168, is {}", + msg.corner_nw_lat + ); + assert_eq!( + msg.corner_nw_lon, -19191, + "incorrect value for corner_nw_lon, expected -19191, is {}", + msg.corner_nw_lon + ); + assert_eq!( + msg.rows, 36863, + "incorrect value for rows, expected 36863, is {}", + msg.rows + ); + assert_eq!( + msg.spacing_lat, 61602, + "incorrect value for spacing_lat, expected 61602, is {}", + msg.spacing_lat + ); + assert_eq!( + msg.spacing_lon, 4929, + "incorrect value for spacing_lon, expected 4929, is {}", + msg.spacing_lon + ); + assert_eq!( + msg.tile_id, 63410, + "incorrect value for tile_id, expected 63410, is {}", + msg.tile_id + ); + assert_eq!( + msg.tile_set_id, 48697, + "incorrect value for tile_set_id, expected 48697, is {}", + msg.tile_set_id + ); + } + _ => panic!("Invalid message type! Expected a MsgSsrTileDefinitionDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_ssr_ssr_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_ssr_ssr_structs.rs new file mode 100644 index 0000000000..942445a2ec --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_ssr_ssr_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/ssr/test_ssr_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_ssr_ssr_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_ssr_ssr_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_ssr_ssr_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_ssr_ssr_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry.rs b/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry.rs new file mode 100644 index 0000000000..163cd031f7 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry.rs @@ -0,0 +1,203 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_msg_csac_telemetry() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 255, 244, 169, 10, 105, 115, 111, 109, 101, 32, 100, 97, 116, 97, 229, 94, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetry(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff04, + "Incorrect message type, expected 0xff04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa9f4, + "incorrect sender id, expected 0xa9f4, is {sender_id}" + ); + assert_eq!( + msg.id, 105, + "incorrect value for id, expected 105, is {}", + msg.id + ); + assert_eq!( + msg.telemetry.as_bytes(), + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + "incorrect value for msg.telemetry, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + msg.telemetry.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetry"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_msg_csac_telemetry() { + { + let json_input = r#"{"preamble":85,"msg_type":65284,"sender":43508,"length":10,"payload":"aXNvbWUgZGF0YQ==","crc":24293,"id":105,"telemetry":"some data"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetry(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff04, + "Incorrect message type, expected 0xff04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa9f4, + "incorrect sender id, expected 0xa9f4, is {sender_id}" + ); + assert_eq!( + msg.id, 105, + "incorrect value for id, expected 105, is {}", + msg.id + ); + assert_eq!( + msg.telemetry.as_bytes(), + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + "incorrect value for msg.telemetry, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + msg.telemetry.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetry"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_msg_csac_telemetry`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_msg_csac_telemetry() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 255, 244, 169, 10, 105, 115, 111, 109, 101, 32, 100, 97, 116, 97, 229, 94, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCsacTelemetry( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetry(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff04, + "Incorrect message type, expected 0xff04, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xa9f4, + "incorrect sender id, expected 0xa9f4, is {sender_id}" + ); + assert_eq!( + msg.id, 105, + "incorrect value for id, expected 105, is {}", + msg.id + ); + assert_eq!( + msg.telemetry.as_bytes(), + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + "incorrect value for msg.telemetry, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 100, 97, 116, 97], + msg.telemetry.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetry"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry_labels.rs b/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry_labels.rs new file mode 100644 index 0000000000..a2296a5f85 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_msg_csac_telemetry_labels.rs @@ -0,0 +1,205 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_msg_csac_telemetry_labels() { + { + let mut payload = Cursor::new(vec![ + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115, 86, + 236, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetryLabels(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff05, + "Incorrect message type, expected 0xff05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc85b, + "incorrect sender id, expected 0xc85b, is {sender_id}" + ); + assert_eq!( + msg.id, 186, + "incorrect value for id, expected 186, is {}", + msg.id + ); + assert_eq!( + msg.telemetry_labels.as_bytes(), + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + "incorrect value for msg.telemetry_labels, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + msg.telemetry_labels.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetryLabels"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_msg_csac_telemetry_labels() { + { + let json_input = r#"{"preamble":85,"msg_type":65285,"sender":51291,"length":12,"payload":"unNvbWUgbGFiZWxz","crc":60502,"id":186,"telemetry_labels":"some labels"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetryLabels(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff05, + "Incorrect message type, expected 0xff05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc85b, + "incorrect sender id, expected 0xc85b, is {sender_id}" + ); + assert_eq!( + msg.id, 186, + "incorrect value for id, expected 186, is {}", + msg.id + ); + assert_eq!( + msg.telemetry_labels.as_bytes(), + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + "incorrect value for msg.telemetry_labels, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + msg.telemetry_labels.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetryLabels"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_msg_csac_telemetry_labels`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_msg_csac_telemetry_labels() { + { + let mut payload = Cursor::new(vec![ + 85, 5, 255, 91, 200, 12, 186, 115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115, 86, + 236, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgCsacTelemetryLabels( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgCsacTelemetryLabels(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff05, + "Incorrect message type, expected 0xff05, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xc85b, + "incorrect sender id, expected 0xc85b, is {sender_id}" + ); + assert_eq!( + msg.id, 186, + "incorrect value for id, expected 186, is {}", + msg.id + ); + assert_eq!( + msg.telemetry_labels.as_bytes(), + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + "incorrect value for msg.telemetry_labels, expected string '{:?}', is '{:?}'", + &[115, 111, 109, 101, 32, 108, 97, 98, 101, 108, 115], + msg.telemetry_labels.as_bytes() + ); + } + _ => panic!("Invalid message type! Expected a MsgCsacTelemetryLabels"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_msg_gnss_time_offset.rs b/rust/sbp/tests/integration/auto_check_sbp_system_msg_gnss_time_offset.rs new file mode 100644 index 0000000000..99f27ab884 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_msg_gnss_time_offset.rs @@ -0,0 +1,227 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_msg_gnss_time_offset() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGnssTimeOffset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff07, + "Incorrect message type, expected 0xff07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f16, + "incorrect sender id, expected 0x0f16, is {sender_id}" + ); + assert_eq!( + msg.flags, 221, + "incorrect value for flags, expected 221, is {}", + msg.flags + ); + assert_eq!( + msg.microseconds, 9494, + "incorrect value for microseconds, expected 9494, is {}", + msg.microseconds + ); + assert_eq!( + msg.milliseconds, 1728664402, + "incorrect value for milliseconds, expected 1728664402, is {}", + msg.milliseconds + ); + assert_eq!( + msg.weeks, 14857, + "incorrect value for weeks, expected 14857, is {}", + msg.weeks + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssTimeOffset"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_msg_gnss_time_offset() { + { + let json_input = r#"{"preamble":85,"msg_type":65287,"sender":3862,"length":9,"payload":"CTpSUwlnFiXd","crc":25684,"weeks":14857,"milliseconds":1728664402,"microseconds":9494,"flags":221}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgGnssTimeOffset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff07, + "Incorrect message type, expected 0xff07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f16, + "incorrect sender id, expected 0x0f16, is {sender_id}" + ); + assert_eq!( + msg.flags, 221, + "incorrect value for flags, expected 221, is {}", + msg.flags + ); + assert_eq!( + msg.microseconds, 9494, + "incorrect value for microseconds, expected 9494, is {}", + msg.microseconds + ); + assert_eq!( + msg.milliseconds, 1728664402, + "incorrect value for milliseconds, expected 1728664402, is {}", + msg.milliseconds + ); + assert_eq!( + msg.weeks, 14857, + "incorrect value for weeks, expected 14857, is {}", + msg.weeks + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssTimeOffset"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_msg_gnss_time_offset`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_msg_gnss_time_offset() { + { + let mut payload = Cursor::new(vec![ + 85, 7, 255, 22, 15, 9, 9, 58, 82, 83, 9, 103, 22, 37, 221, 84, 100, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgGnssTimeOffset( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgGnssTimeOffset(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff07, + "Incorrect message type, expected 0xff07, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x0f16, + "incorrect sender id, expected 0x0f16, is {sender_id}" + ); + assert_eq!( + msg.flags, 221, + "incorrect value for flags, expected 221, is {}", + msg.flags + ); + assert_eq!( + msg.microseconds, 9494, + "incorrect value for microseconds, expected 9494, is {}", + msg.microseconds + ); + assert_eq!( + msg.milliseconds, 1728664402, + "incorrect value for milliseconds, expected 1728664402, is {}", + msg.milliseconds + ); + assert_eq!( + msg.weeks, 14857, + "incorrect value for weeks, expected 14857, is {}", + msg.weeks + ); + } + _ => panic!("Invalid message type! Expected a MsgGnssTimeOffset"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_msg_pps_time.rs b/rust/sbp/tests/integration/auto_check_sbp_system_msg_pps_time.rs new file mode 100644 index 0000000000..99df23c618 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_msg_pps_time.rs @@ -0,0 +1,197 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_msg_pps_time() { + { + let mut payload = Cursor::new(vec![ + 85, 8, 255, 222, 209, 9, 140, 146, 133, 197, 160, 0, 0, 0, 255, 125, 149, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgPpsTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff08, + "Incorrect message type, expected 0xff08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd1de, + "incorrect sender id, expected 0xd1de, is {sender_id}" + ); + assert_eq!( + msg.flags, 255, + "incorrect value for flags, expected 255, is {}", + msg.flags + ); + assert_eq!( + msg.time, 690508632716, + "incorrect value for time, expected 690508632716, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgPpsTime"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_msg_pps_time() { + { + let json_input = r#"{"preamble":85,"msg_type":65288,"sender":53726,"length":9,"payload":"jJKFxaAAAAD/","crc":38269,"time":690508632716,"flags":255}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgPpsTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff08, + "Incorrect message type, expected 0xff08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd1de, + "incorrect sender id, expected 0xd1de, is {sender_id}" + ); + assert_eq!( + msg.flags, 255, + "incorrect value for flags, expected 255, is {}", + msg.flags + ); + assert_eq!( + msg.time, 690508632716, + "incorrect value for time, expected 690508632716, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgPpsTime"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_msg_pps_time`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_msg_pps_time() { + { + let mut payload = Cursor::new(vec![ + 85, 8, 255, 222, 209, 9, 140, 146, 133, 197, 160, 0, 0, 0, 255, 125, 149, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgPpsTime( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgPpsTime(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xff08, + "Incorrect message type, expected 0xff08, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd1de, + "incorrect sender id, expected 0xd1de, is {sender_id}" + ); + assert_eq!( + msg.flags, 255, + "incorrect value for flags, expected 255, is {}", + msg.flags + ); + assert_eq!( + msg.time, 690508632716, + "incorrect value for time, expected 690508632716, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgPpsTime"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_msg_status_report.rs b/rust/sbp/tests/integration/auto_check_sbp_system_msg_status_report.rs new file mode 100644 index 0000000000..6920d3bc7c --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_msg_status_report.rs @@ -0,0 +1,2953 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_msg_status_report() { + { + let mut payload = Cursor::new(vec![ + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, 233, 21, 208, 98, 247, 203, + 221, 198, 156, 207, 217, 238, 162, 136, 154, 11, 114, 236, 134, 235, 12, 133, 9, 30, + 175, 145, 26, 114, 215, 20, 146, 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, 5, + 248, 225, 149, 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, 103, 68, 76, 184, 33, 206, 194, + 163, 123, 30, 151, 176, 149, 172, 184, 231, 118, 230, 200, 168, 100, 109, 10, 233, 4, + 60, 247, 82, 215, 166, 28, 138, 110, 45, 98, 218, 244, 179, 126, 107, 92, 124, 94, 157, + 42, 187, 124, 6, 97, 247, 160, 188, 110, 120, 254, 214, 110, 51, 240, 164, 147, 18, 74, + 178, 67, 4, 27, 73, 190, 64, 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, 40, 161, + 173, 242, 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, 40, 191, 113, 230, 200, 72, 8, + 215, 245, 78, 59, 222, 250, 115, 32, 33, 30, 211, 170, 145, 92, 157, 75, 24, 169, 6, + 55, 62, 8, 107, 82, 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, 148, + 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, 23, 248, 192, 20, 83, 195, 95, + 180, 54, 36, 186, 75, 64, 20, 157, 133, 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, + 245, 30, 228, 88, 142, 212, 53, 224, 158, 166, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStatusReport(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xfffe, + "Incorrect message type, expected 0xfffe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5406, + "incorrect sender id, expected 0x5406, is {sender_id}" + ); + assert_eq!( + msg.reporting_system, 64850, + "incorrect value for reporting_system, expected 64850, is {}", + msg.reporting_system + ); + assert_eq!( + msg.sbp_version, 24497, + "incorrect value for sbp_version, expected 24497, is {}", + msg.sbp_version + ); + assert_eq!( + msg.sequence, 1519336451, + "incorrect value for sequence, expected 1519336451, is {}", + msg.sequence + ); + assert_eq!( + msg.status[0].component, 52215, + "incorrect value for status[0].component, expected 52215, is {}", + msg.status[0].component + ); + assert_eq!( + msg.status[0].generic, 221, + "incorrect value for status[0].generic, expected 221, is {}", + msg.status[0].generic + ); + assert_eq!( + msg.status[0].specific, 198, + "incorrect value for status[0].specific, expected 198, is {}", + msg.status[0].specific + ); + assert_eq!( + msg.status[1].component, 53148, + "incorrect value for status[1].component, expected 53148, is {}", + msg.status[1].component + ); + assert_eq!( + msg.status[1].generic, 217, + "incorrect value for status[1].generic, expected 217, is {}", + msg.status[1].generic + ); + assert_eq!( + msg.status[1].specific, 238, + "incorrect value for status[1].specific, expected 238, is {}", + msg.status[1].specific + ); + assert_eq!( + msg.status[2].component, 34978, + "incorrect value for status[2].component, expected 34978, is {}", + msg.status[2].component + ); + assert_eq!( + msg.status[2].generic, 154, + "incorrect value for status[2].generic, expected 154, is {}", + msg.status[2].generic + ); + assert_eq!( + msg.status[2].specific, 11, + "incorrect value for status[2].specific, expected 11, is {}", + msg.status[2].specific + ); + assert_eq!( + msg.status[3].component, 60530, + "incorrect value for status[3].component, expected 60530, is {}", + msg.status[3].component + ); + assert_eq!( + msg.status[3].generic, 134, + "incorrect value for status[3].generic, expected 134, is {}", + msg.status[3].generic + ); + assert_eq!( + msg.status[3].specific, 235, + "incorrect value for status[3].specific, expected 235, is {}", + msg.status[3].specific + ); + assert_eq!( + msg.status[4].component, 34060, + "incorrect value for status[4].component, expected 34060, is {}", + msg.status[4].component + ); + assert_eq!( + msg.status[4].generic, 9, + "incorrect value for status[4].generic, expected 9, is {}", + msg.status[4].generic + ); + assert_eq!( + msg.status[4].specific, 30, + "incorrect value for status[4].specific, expected 30, is {}", + msg.status[4].specific + ); + assert_eq!( + msg.status[5].component, 37295, + "incorrect value for status[5].component, expected 37295, is {}", + msg.status[5].component + ); + assert_eq!( + msg.status[5].generic, 26, + "incorrect value for status[5].generic, expected 26, is {}", + msg.status[5].generic + ); + assert_eq!( + msg.status[5].specific, 114, + "incorrect value for status[5].specific, expected 114, is {}", + msg.status[5].specific + ); + assert_eq!( + msg.status[6].component, 5335, + "incorrect value for status[6].component, expected 5335, is {}", + msg.status[6].component + ); + assert_eq!( + msg.status[6].generic, 146, + "incorrect value for status[6].generic, expected 146, is {}", + msg.status[6].generic + ); + assert_eq!( + msg.status[6].specific, 249, + "incorrect value for status[6].specific, expected 249, is {}", + msg.status[6].specific + ); + assert_eq!( + msg.status[7].component, 13878, + "incorrect value for status[7].component, expected 13878, is {}", + msg.status[7].component + ); + assert_eq!( + msg.status[7].generic, 133, + "incorrect value for status[7].generic, expected 133, is {}", + msg.status[7].generic + ); + assert_eq!( + msg.status[7].specific, 193, + "incorrect value for status[7].specific, expected 193, is {}", + msg.status[7].specific + ); + assert_eq!( + msg.status[8].component, 47722, + "incorrect value for status[8].component, expected 47722, is {}", + msg.status[8].component + ); + assert_eq!( + msg.status[8].generic, 210, + "incorrect value for status[8].generic, expected 210, is {}", + msg.status[8].generic + ); + assert_eq!( + msg.status[8].specific, 183, + "incorrect value for status[8].specific, expected 183, is {}", + msg.status[8].specific + ); + assert_eq!( + msg.status[9].component, 33024, + "incorrect value for status[9].component, expected 33024, is {}", + msg.status[9].component + ); + assert_eq!( + msg.status[9].generic, 5, + "incorrect value for status[9].generic, expected 5, is {}", + msg.status[9].generic + ); + assert_eq!( + msg.status[9].specific, 248, + "incorrect value for status[9].specific, expected 248, is {}", + msg.status[9].specific + ); + assert_eq!( + msg.status[10].component, 38369, + "incorrect value for status[10].component, expected 38369, is {}", + msg.status[10].component + ); + assert_eq!( + msg.status[10].generic, 135, + "incorrect value for status[10].generic, expected 135, is {}", + msg.status[10].generic + ); + assert_eq!( + msg.status[10].specific, 127, + "incorrect value for status[10].specific, expected 127, is {}", + msg.status[10].specific + ); + assert_eq!( + msg.status[11].component, 6658, + "incorrect value for status[11].component, expected 6658, is {}", + msg.status[11].component + ); + assert_eq!( + msg.status[11].generic, 88, + "incorrect value for status[11].generic, expected 88, is {}", + msg.status[11].generic + ); + assert_eq!( + msg.status[11].specific, 92, + "incorrect value for status[11].specific, expected 92, is {}", + msg.status[11].specific + ); + assert_eq!( + msg.status[12].component, 26378, + "incorrect value for status[12].component, expected 26378, is {}", + msg.status[12].component + ); + assert_eq!( + msg.status[12].generic, 73, + "incorrect value for status[12].generic, expected 73, is {}", + msg.status[12].generic + ); + assert_eq!( + msg.status[12].specific, 3, + "incorrect value for status[12].specific, expected 3, is {}", + msg.status[12].specific + ); + assert_eq!( + msg.status[13].component, 17511, + "incorrect value for status[13].component, expected 17511, is {}", + msg.status[13].component + ); + assert_eq!( + msg.status[13].generic, 76, + "incorrect value for status[13].generic, expected 76, is {}", + msg.status[13].generic + ); + assert_eq!( + msg.status[13].specific, 184, + "incorrect value for status[13].specific, expected 184, is {}", + msg.status[13].specific + ); + assert_eq!( + msg.status[14].component, 52769, + "incorrect value for status[14].component, expected 52769, is {}", + msg.status[14].component + ); + assert_eq!( + msg.status[14].generic, 194, + "incorrect value for status[14].generic, expected 194, is {}", + msg.status[14].generic + ); + assert_eq!( + msg.status[14].specific, 163, + "incorrect value for status[14].specific, expected 163, is {}", + msg.status[14].specific + ); + assert_eq!( + msg.status[15].component, 7803, + "incorrect value for status[15].component, expected 7803, is {}", + msg.status[15].component + ); + assert_eq!( + msg.status[15].generic, 151, + "incorrect value for status[15].generic, expected 151, is {}", + msg.status[15].generic + ); + assert_eq!( + msg.status[15].specific, 176, + "incorrect value for status[15].specific, expected 176, is {}", + msg.status[15].specific + ); + assert_eq!( + msg.status[16].component, 44181, + "incorrect value for status[16].component, expected 44181, is {}", + msg.status[16].component + ); + assert_eq!( + msg.status[16].generic, 184, + "incorrect value for status[16].generic, expected 184, is {}", + msg.status[16].generic + ); + assert_eq!( + msg.status[16].specific, 231, + "incorrect value for status[16].specific, expected 231, is {}", + msg.status[16].specific + ); + assert_eq!( + msg.status[17].component, 58998, + "incorrect value for status[17].component, expected 58998, is {}", + msg.status[17].component + ); + assert_eq!( + msg.status[17].generic, 200, + "incorrect value for status[17].generic, expected 200, is {}", + msg.status[17].generic + ); + assert_eq!( + msg.status[17].specific, 168, + "incorrect value for status[17].specific, expected 168, is {}", + msg.status[17].specific + ); + assert_eq!( + msg.status[18].component, 28004, + "incorrect value for status[18].component, expected 28004, is {}", + msg.status[18].component + ); + assert_eq!( + msg.status[18].generic, 10, + "incorrect value for status[18].generic, expected 10, is {}", + msg.status[18].generic + ); + assert_eq!( + msg.status[18].specific, 233, + "incorrect value for status[18].specific, expected 233, is {}", + msg.status[18].specific + ); + assert_eq!( + msg.status[19].component, 15364, + "incorrect value for status[19].component, expected 15364, is {}", + msg.status[19].component + ); + assert_eq!( + msg.status[19].generic, 247, + "incorrect value for status[19].generic, expected 247, is {}", + msg.status[19].generic + ); + assert_eq!( + msg.status[19].specific, 82, + "incorrect value for status[19].specific, expected 82, is {}", + msg.status[19].specific + ); + assert_eq!( + msg.status[20].component, 42711, + "incorrect value for status[20].component, expected 42711, is {}", + msg.status[20].component + ); + assert_eq!( + msg.status[20].generic, 28, + "incorrect value for status[20].generic, expected 28, is {}", + msg.status[20].generic + ); + assert_eq!( + msg.status[20].specific, 138, + "incorrect value for status[20].specific, expected 138, is {}", + msg.status[20].specific + ); + assert_eq!( + msg.status[21].component, 11630, + "incorrect value for status[21].component, expected 11630, is {}", + msg.status[21].component + ); + assert_eq!( + msg.status[21].generic, 98, + "incorrect value for status[21].generic, expected 98, is {}", + msg.status[21].generic + ); + assert_eq!( + msg.status[21].specific, 218, + "incorrect value for status[21].specific, expected 218, is {}", + msg.status[21].specific + ); + assert_eq!( + msg.status[22].component, 46068, + "incorrect value for status[22].component, expected 46068, is {}", + msg.status[22].component + ); + assert_eq!( + msg.status[22].generic, 126, + "incorrect value for status[22].generic, expected 126, is {}", + msg.status[22].generic + ); + assert_eq!( + msg.status[22].specific, 107, + "incorrect value for status[22].specific, expected 107, is {}", + msg.status[22].specific + ); + assert_eq!( + msg.status[23].component, 31836, + "incorrect value for status[23].component, expected 31836, is {}", + msg.status[23].component + ); + assert_eq!( + msg.status[23].generic, 94, + "incorrect value for status[23].generic, expected 94, is {}", + msg.status[23].generic + ); + assert_eq!( + msg.status[23].specific, 157, + "incorrect value for status[23].specific, expected 157, is {}", + msg.status[23].specific + ); + assert_eq!( + msg.status[24].component, 47914, + "incorrect value for status[24].component, expected 47914, is {}", + msg.status[24].component + ); + assert_eq!( + msg.status[24].generic, 124, + "incorrect value for status[24].generic, expected 124, is {}", + msg.status[24].generic + ); + assert_eq!( + msg.status[24].specific, 6, + "incorrect value for status[24].specific, expected 6, is {}", + msg.status[24].specific + ); + assert_eq!( + msg.status[25].component, 63329, + "incorrect value for status[25].component, expected 63329, is {}", + msg.status[25].component + ); + assert_eq!( + msg.status[25].generic, 160, + "incorrect value for status[25].generic, expected 160, is {}", + msg.status[25].generic + ); + assert_eq!( + msg.status[25].specific, 188, + "incorrect value for status[25].specific, expected 188, is {}", + msg.status[25].specific + ); + assert_eq!( + msg.status[26].component, 30830, + "incorrect value for status[26].component, expected 30830, is {}", + msg.status[26].component + ); + assert_eq!( + msg.status[26].generic, 254, + "incorrect value for status[26].generic, expected 254, is {}", + msg.status[26].generic + ); + assert_eq!( + msg.status[26].specific, 214, + "incorrect value for status[26].specific, expected 214, is {}", + msg.status[26].specific + ); + assert_eq!( + msg.status[27].component, 13166, + "incorrect value for status[27].component, expected 13166, is {}", + msg.status[27].component + ); + assert_eq!( + msg.status[27].generic, 240, + "incorrect value for status[27].generic, expected 240, is {}", + msg.status[27].generic + ); + assert_eq!( + msg.status[27].specific, 164, + "incorrect value for status[27].specific, expected 164, is {}", + msg.status[27].specific + ); + assert_eq!( + msg.status[28].component, 4755, + "incorrect value for status[28].component, expected 4755, is {}", + msg.status[28].component + ); + assert_eq!( + msg.status[28].generic, 74, + "incorrect value for status[28].generic, expected 74, is {}", + msg.status[28].generic + ); + assert_eq!( + msg.status[28].specific, 178, + "incorrect value for status[28].specific, expected 178, is {}", + msg.status[28].specific + ); + assert_eq!( + msg.status[29].component, 1091, + "incorrect value for status[29].component, expected 1091, is {}", + msg.status[29].component + ); + assert_eq!( + msg.status[29].generic, 27, + "incorrect value for status[29].generic, expected 27, is {}", + msg.status[29].generic + ); + assert_eq!( + msg.status[29].specific, 73, + "incorrect value for status[29].specific, expected 73, is {}", + msg.status[29].specific + ); + assert_eq!( + msg.status[30].component, 16574, + "incorrect value for status[30].component, expected 16574, is {}", + msg.status[30].component + ); + assert_eq!( + msg.status[30].generic, 179, + "incorrect value for status[30].generic, expected 179, is {}", + msg.status[30].generic + ); + assert_eq!( + msg.status[30].specific, 146, + "incorrect value for status[30].specific, expected 146, is {}", + msg.status[30].specific + ); + assert_eq!( + msg.status[31].component, 39293, + "incorrect value for status[31].component, expected 39293, is {}", + msg.status[31].component + ); + assert_eq!( + msg.status[31].generic, 192, + "incorrect value for status[31].generic, expected 192, is {}", + msg.status[31].generic + ); + assert_eq!( + msg.status[31].specific, 46, + "incorrect value for status[31].specific, expected 46, is {}", + msg.status[31].specific + ); + assert_eq!( + msg.status[32].component, 17098, + "incorrect value for status[32].component, expected 17098, is {}", + msg.status[32].component + ); + assert_eq!( + msg.status[32].generic, 248, + "incorrect value for status[32].generic, expected 248, is {}", + msg.status[32].generic + ); + assert_eq!( + msg.status[32].specific, 46, + "incorrect value for status[32].specific, expected 46, is {}", + msg.status[32].specific + ); + assert_eq!( + msg.status[33].component, 41256, + "incorrect value for status[33].component, expected 41256, is {}", + msg.status[33].component + ); + assert_eq!( + msg.status[33].generic, 173, + "incorrect value for status[33].generic, expected 173, is {}", + msg.status[33].generic + ); + assert_eq!( + msg.status[33].specific, 242, + "incorrect value for status[33].specific, expected 242, is {}", + msg.status[33].specific + ); + assert_eq!( + msg.status[34].component, 982, + "incorrect value for status[34].component, expected 982, is {}", + msg.status[34].component + ); + assert_eq!( + msg.status[34].generic, 11, + "incorrect value for status[34].generic, expected 11, is {}", + msg.status[34].generic + ); + assert_eq!( + msg.status[34].specific, 1, + "incorrect value for status[34].specific, expected 1, is {}", + msg.status[34].specific + ); + assert_eq!( + msg.status[35].component, 18038, + "incorrect value for status[35].component, expected 18038, is {}", + msg.status[35].component + ); + assert_eq!( + msg.status[35].generic, 162, + "incorrect value for status[35].generic, expected 162, is {}", + msg.status[35].generic + ); + assert_eq!( + msg.status[35].specific, 61, + "incorrect value for status[35].specific, expected 61, is {}", + msg.status[35].specific + ); + assert_eq!( + msg.status[36].component, 7090, + "incorrect value for status[36].component, expected 7090, is {}", + msg.status[36].component + ); + assert_eq!( + msg.status[36].generic, 156, + "incorrect value for status[36].generic, expected 156, is {}", + msg.status[36].generic + ); + assert_eq!( + msg.status[36].specific, 40, + "incorrect value for status[36].specific, expected 40, is {}", + msg.status[36].specific + ); + assert_eq!( + msg.status[37].component, 29119, + "incorrect value for status[37].component, expected 29119, is {}", + msg.status[37].component + ); + assert_eq!( + msg.status[37].generic, 230, + "incorrect value for status[37].generic, expected 230, is {}", + msg.status[37].generic + ); + assert_eq!( + msg.status[37].specific, 200, + "incorrect value for status[37].specific, expected 200, is {}", + msg.status[37].specific + ); + assert_eq!( + msg.status[38].component, 2120, + "incorrect value for status[38].component, expected 2120, is {}", + msg.status[38].component + ); + assert_eq!( + msg.status[38].generic, 215, + "incorrect value for status[38].generic, expected 215, is {}", + msg.status[38].generic + ); + assert_eq!( + msg.status[38].specific, 245, + "incorrect value for status[38].specific, expected 245, is {}", + msg.status[38].specific + ); + assert_eq!( + msg.status[39].component, 15182, + "incorrect value for status[39].component, expected 15182, is {}", + msg.status[39].component + ); + assert_eq!( + msg.status[39].generic, 222, + "incorrect value for status[39].generic, expected 222, is {}", + msg.status[39].generic + ); + assert_eq!( + msg.status[39].specific, 250, + "incorrect value for status[39].specific, expected 250, is {}", + msg.status[39].specific + ); + assert_eq!( + msg.status[40].component, 8307, + "incorrect value for status[40].component, expected 8307, is {}", + msg.status[40].component + ); + assert_eq!( + msg.status[40].generic, 33, + "incorrect value for status[40].generic, expected 33, is {}", + msg.status[40].generic + ); + assert_eq!( + msg.status[40].specific, 30, + "incorrect value for status[40].specific, expected 30, is {}", + msg.status[40].specific + ); + assert_eq!( + msg.status[41].component, 43731, + "incorrect value for status[41].component, expected 43731, is {}", + msg.status[41].component + ); + assert_eq!( + msg.status[41].generic, 145, + "incorrect value for status[41].generic, expected 145, is {}", + msg.status[41].generic + ); + assert_eq!( + msg.status[41].specific, 92, + "incorrect value for status[41].specific, expected 92, is {}", + msg.status[41].specific + ); + assert_eq!( + msg.status[42].component, 19357, + "incorrect value for status[42].component, expected 19357, is {}", + msg.status[42].component + ); + assert_eq!( + msg.status[42].generic, 24, + "incorrect value for status[42].generic, expected 24, is {}", + msg.status[42].generic + ); + assert_eq!( + msg.status[42].specific, 169, + "incorrect value for status[42].specific, expected 169, is {}", + msg.status[42].specific + ); + assert_eq!( + msg.status[43].component, 14086, + "incorrect value for status[43].component, expected 14086, is {}", + msg.status[43].component + ); + assert_eq!( + msg.status[43].generic, 62, + "incorrect value for status[43].generic, expected 62, is {}", + msg.status[43].generic + ); + assert_eq!( + msg.status[43].specific, 8, + "incorrect value for status[43].specific, expected 8, is {}", + msg.status[43].specific + ); + assert_eq!( + msg.status[44].component, 21099, + "incorrect value for status[44].component, expected 21099, is {}", + msg.status[44].component + ); + assert_eq!( + msg.status[44].generic, 140, + "incorrect value for status[44].generic, expected 140, is {}", + msg.status[44].generic + ); + assert_eq!( + msg.status[44].specific, 49, + "incorrect value for status[44].specific, expected 49, is {}", + msg.status[44].specific + ); + assert_eq!( + msg.status[45].component, 31411, + "incorrect value for status[45].component, expected 31411, is {}", + msg.status[45].component + ); + assert_eq!( + msg.status[45].generic, 90, + "incorrect value for status[45].generic, expected 90, is {}", + msg.status[45].generic + ); + assert_eq!( + msg.status[45].specific, 71, + "incorrect value for status[45].specific, expected 71, is {}", + msg.status[45].specific + ); + assert_eq!( + msg.status[46].component, 22556, + "incorrect value for status[46].component, expected 22556, is {}", + msg.status[46].component + ); + assert_eq!( + msg.status[46].generic, 103, + "incorrect value for status[46].generic, expected 103, is {}", + msg.status[46].generic + ); + assert_eq!( + msg.status[46].specific, 51, + "incorrect value for status[46].specific, expected 51, is {}", + msg.status[46].specific + ); + assert_eq!( + msg.status[47].component, 18609, + "incorrect value for status[47].component, expected 18609, is {}", + msg.status[47].component + ); + assert_eq!( + msg.status[47].generic, 93, + "incorrect value for status[47].generic, expected 93, is {}", + msg.status[47].generic + ); + assert_eq!( + msg.status[47].specific, 39, + "incorrect value for status[47].specific, expected 39, is {}", + msg.status[47].specific + ); + assert_eq!( + msg.status[48].component, 2964, + "incorrect value for status[48].component, expected 2964, is {}", + msg.status[48].component + ); + assert_eq!( + msg.status[48].generic, 202, + "incorrect value for status[48].generic, expected 202, is {}", + msg.status[48].generic + ); + assert_eq!( + msg.status[48].specific, 42, + "incorrect value for status[48].specific, expected 42, is {}", + msg.status[48].specific + ); + assert_eq!( + msg.status[49].component, 23586, + "incorrect value for status[49].component, expected 23586, is {}", + msg.status[49].component + ); + assert_eq!( + msg.status[49].generic, 204, + "incorrect value for status[49].generic, expected 204, is {}", + msg.status[49].generic + ); + assert_eq!( + msg.status[49].specific, 102, + "incorrect value for status[49].specific, expected 102, is {}", + msg.status[49].specific + ); + assert_eq!( + msg.status[50].component, 25117, + "incorrect value for status[50].component, expected 25117, is {}", + msg.status[50].component + ); + assert_eq!( + msg.status[50].generic, 249, + "incorrect value for status[50].generic, expected 249, is {}", + msg.status[50].generic + ); + assert_eq!( + msg.status[50].specific, 91, + "incorrect value for status[50].specific, expected 91, is {}", + msg.status[50].specific + ); + assert_eq!( + msg.status[51].component, 24454, + "incorrect value for status[51].component, expected 24454, is {}", + msg.status[51].component + ); + assert_eq!( + msg.status[51].generic, 23, + "incorrect value for status[51].generic, expected 23, is {}", + msg.status[51].generic + ); + assert_eq!( + msg.status[51].specific, 248, + "incorrect value for status[51].specific, expected 248, is {}", + msg.status[51].specific + ); + assert_eq!( + msg.status[52].component, 5312, + "incorrect value for status[52].component, expected 5312, is {}", + msg.status[52].component + ); + assert_eq!( + msg.status[52].generic, 83, + "incorrect value for status[52].generic, expected 83, is {}", + msg.status[52].generic + ); + assert_eq!( + msg.status[52].specific, 195, + "incorrect value for status[52].specific, expected 195, is {}", + msg.status[52].specific + ); + assert_eq!( + msg.status[53].component, 46175, + "incorrect value for status[53].component, expected 46175, is {}", + msg.status[53].component + ); + assert_eq!( + msg.status[53].generic, 54, + "incorrect value for status[53].generic, expected 54, is {}", + msg.status[53].generic + ); + assert_eq!( + msg.status[53].specific, 36, + "incorrect value for status[53].specific, expected 36, is {}", + msg.status[53].specific + ); + assert_eq!( + msg.status[54].component, 19386, + "incorrect value for status[54].component, expected 19386, is {}", + msg.status[54].component + ); + assert_eq!( + msg.status[54].generic, 64, + "incorrect value for status[54].generic, expected 64, is {}", + msg.status[54].generic + ); + assert_eq!( + msg.status[54].specific, 20, + "incorrect value for status[54].specific, expected 20, is {}", + msg.status[54].specific + ); + assert_eq!( + msg.status[55].component, 34205, + "incorrect value for status[55].component, expected 34205, is {}", + msg.status[55].component + ); + assert_eq!( + msg.status[55].generic, 12, + "incorrect value for status[55].generic, expected 12, is {}", + msg.status[55].generic + ); + assert_eq!( + msg.status[55].specific, 149, + "incorrect value for status[55].specific, expected 149, is {}", + msg.status[55].specific + ); + assert_eq!( + msg.status[56].component, 3612, + "incorrect value for status[56].component, expected 3612, is {}", + msg.status[56].component + ); + assert_eq!( + msg.status[56].generic, 185, + "incorrect value for status[56].generic, expected 185, is {}", + msg.status[56].generic + ); + assert_eq!( + msg.status[56].specific, 129, + "incorrect value for status[56].specific, expected 129, is {}", + msg.status[56].specific + ); + assert_eq!( + msg.status[57].component, 61285, + "incorrect value for status[57].component, expected 61285, is {}", + msg.status[57].component + ); + assert_eq!( + msg.status[57].generic, 74, + "incorrect value for status[57].generic, expected 74, is {}", + msg.status[57].generic + ); + assert_eq!( + msg.status[57].specific, 248, + "incorrect value for status[57].specific, expected 248, is {}", + msg.status[57].specific + ); + assert_eq!( + msg.status[58].component, 7925, + "incorrect value for status[58].component, expected 7925, is {}", + msg.status[58].component + ); + assert_eq!( + msg.status[58].generic, 228, + "incorrect value for status[58].generic, expected 228, is {}", + msg.status[58].generic + ); + assert_eq!( + msg.status[58].specific, 88, + "incorrect value for status[58].specific, expected 88, is {}", + msg.status[58].specific + ); + assert_eq!( + msg.status[59].component, 54414, + "incorrect value for status[59].component, expected 54414, is {}", + msg.status[59].component + ); + assert_eq!( + msg.status[59].generic, 53, + "incorrect value for status[59].generic, expected 53, is {}", + msg.status[59].generic + ); + assert_eq!( + msg.status[59].specific, 224, + "incorrect value for status[59].specific, expected 224, is {}", + msg.status[59].specific + ); + assert_eq!( + msg.uptime, 1657804265, + "incorrect value for uptime, expected 1657804265, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgStatusReport"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_msg_status_report() { + { + let json_input = r#"{"preamble":85,"msg_type":65534,"sender":21510,"length":252,"payload":"Uv2xXwM8j1rpFdBi98vdxpzP2e6iiJoLcuyG6wyFCR6vkRpy1xSS+TY2hcFqutK3AIEF+OGVh38CGlhcCmdJA2dETLghzsKjex6XsJWsuOd25sioZG0K6QQ891LXphyKbi1i2vSzfmtcfF6dKrt8BmH3oLxueP7WbjPwpJMSSrJDBBtJvkCzkn2ZwC7KQvguKKGt8tYDCwF2RqI9shucKL9x5shICNf1Tjve+nMgIR7TqpFcnUsYqQY3PghrUowxs3paRxxYZzOxSF0nlAvKKiJczGYdYvlbhl8X+MAUU8NftDYkuktAFJ2FDJUcDrmBZe9K+PUe5FiO1DXg","crc":42654,"reporting_system":64850,"sbp_version":24497,"sequence":1519336451,"uptime":1657804265,"status":[{"component":52215,"generic":221,"specific":198},{"component":53148,"generic":217,"specific":238},{"component":34978,"generic":154,"specific":11},{"component":60530,"generic":134,"specific":235},{"component":34060,"generic":9,"specific":30},{"component":37295,"generic":26,"specific":114},{"component":5335,"generic":146,"specific":249},{"component":13878,"generic":133,"specific":193},{"component":47722,"generic":210,"specific":183},{"component":33024,"generic":5,"specific":248},{"component":38369,"generic":135,"specific":127},{"component":6658,"generic":88,"specific":92},{"component":26378,"generic":73,"specific":3},{"component":17511,"generic":76,"specific":184},{"component":52769,"generic":194,"specific":163},{"component":7803,"generic":151,"specific":176},{"component":44181,"generic":184,"specific":231},{"component":58998,"generic":200,"specific":168},{"component":28004,"generic":10,"specific":233},{"component":15364,"generic":247,"specific":82},{"component":42711,"generic":28,"specific":138},{"component":11630,"generic":98,"specific":218},{"component":46068,"generic":126,"specific":107},{"component":31836,"generic":94,"specific":157},{"component":47914,"generic":124,"specific":6},{"component":63329,"generic":160,"specific":188},{"component":30830,"generic":254,"specific":214},{"component":13166,"generic":240,"specific":164},{"component":4755,"generic":74,"specific":178},{"component":1091,"generic":27,"specific":73},{"component":16574,"generic":179,"specific":146},{"component":39293,"generic":192,"specific":46},{"component":17098,"generic":248,"specific":46},{"component":41256,"generic":173,"specific":242},{"component":982,"generic":11,"specific":1},{"component":18038,"generic":162,"specific":61},{"component":7090,"generic":156,"specific":40},{"component":29119,"generic":230,"specific":200},{"component":2120,"generic":215,"specific":245},{"component":15182,"generic":222,"specific":250},{"component":8307,"generic":33,"specific":30},{"component":43731,"generic":145,"specific":92},{"component":19357,"generic":24,"specific":169},{"component":14086,"generic":62,"specific":8},{"component":21099,"generic":140,"specific":49},{"component":31411,"generic":90,"specific":71},{"component":22556,"generic":103,"specific":51},{"component":18609,"generic":93,"specific":39},{"component":2964,"generic":202,"specific":42},{"component":23586,"generic":204,"specific":102},{"component":25117,"generic":249,"specific":91},{"component":24454,"generic":23,"specific":248},{"component":5312,"generic":83,"specific":195},{"component":46175,"generic":54,"specific":36},{"component":19386,"generic":64,"specific":20},{"component":34205,"generic":12,"specific":149},{"component":3612,"generic":185,"specific":129},{"component":61285,"generic":74,"specific":248},{"component":7925,"generic":228,"specific":88},{"component":54414,"generic":53,"specific":224}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgStatusReport(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xfffe, + "Incorrect message type, expected 0xfffe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5406, + "incorrect sender id, expected 0x5406, is {sender_id}" + ); + assert_eq!( + msg.reporting_system, 64850, + "incorrect value for reporting_system, expected 64850, is {}", + msg.reporting_system + ); + assert_eq!( + msg.sbp_version, 24497, + "incorrect value for sbp_version, expected 24497, is {}", + msg.sbp_version + ); + assert_eq!( + msg.sequence, 1519336451, + "incorrect value for sequence, expected 1519336451, is {}", + msg.sequence + ); + assert_eq!( + msg.status[0].component, 52215, + "incorrect value for status[0].component, expected 52215, is {}", + msg.status[0].component + ); + assert_eq!( + msg.status[0].generic, 221, + "incorrect value for status[0].generic, expected 221, is {}", + msg.status[0].generic + ); + assert_eq!( + msg.status[0].specific, 198, + "incorrect value for status[0].specific, expected 198, is {}", + msg.status[0].specific + ); + assert_eq!( + msg.status[1].component, 53148, + "incorrect value for status[1].component, expected 53148, is {}", + msg.status[1].component + ); + assert_eq!( + msg.status[1].generic, 217, + "incorrect value for status[1].generic, expected 217, is {}", + msg.status[1].generic + ); + assert_eq!( + msg.status[1].specific, 238, + "incorrect value for status[1].specific, expected 238, is {}", + msg.status[1].specific + ); + assert_eq!( + msg.status[2].component, 34978, + "incorrect value for status[2].component, expected 34978, is {}", + msg.status[2].component + ); + assert_eq!( + msg.status[2].generic, 154, + "incorrect value for status[2].generic, expected 154, is {}", + msg.status[2].generic + ); + assert_eq!( + msg.status[2].specific, 11, + "incorrect value for status[2].specific, expected 11, is {}", + msg.status[2].specific + ); + assert_eq!( + msg.status[3].component, 60530, + "incorrect value for status[3].component, expected 60530, is {}", + msg.status[3].component + ); + assert_eq!( + msg.status[3].generic, 134, + "incorrect value for status[3].generic, expected 134, is {}", + msg.status[3].generic + ); + assert_eq!( + msg.status[3].specific, 235, + "incorrect value for status[3].specific, expected 235, is {}", + msg.status[3].specific + ); + assert_eq!( + msg.status[4].component, 34060, + "incorrect value for status[4].component, expected 34060, is {}", + msg.status[4].component + ); + assert_eq!( + msg.status[4].generic, 9, + "incorrect value for status[4].generic, expected 9, is {}", + msg.status[4].generic + ); + assert_eq!( + msg.status[4].specific, 30, + "incorrect value for status[4].specific, expected 30, is {}", + msg.status[4].specific + ); + assert_eq!( + msg.status[5].component, 37295, + "incorrect value for status[5].component, expected 37295, is {}", + msg.status[5].component + ); + assert_eq!( + msg.status[5].generic, 26, + "incorrect value for status[5].generic, expected 26, is {}", + msg.status[5].generic + ); + assert_eq!( + msg.status[5].specific, 114, + "incorrect value for status[5].specific, expected 114, is {}", + msg.status[5].specific + ); + assert_eq!( + msg.status[6].component, 5335, + "incorrect value for status[6].component, expected 5335, is {}", + msg.status[6].component + ); + assert_eq!( + msg.status[6].generic, 146, + "incorrect value for status[6].generic, expected 146, is {}", + msg.status[6].generic + ); + assert_eq!( + msg.status[6].specific, 249, + "incorrect value for status[6].specific, expected 249, is {}", + msg.status[6].specific + ); + assert_eq!( + msg.status[7].component, 13878, + "incorrect value for status[7].component, expected 13878, is {}", + msg.status[7].component + ); + assert_eq!( + msg.status[7].generic, 133, + "incorrect value for status[7].generic, expected 133, is {}", + msg.status[7].generic + ); + assert_eq!( + msg.status[7].specific, 193, + "incorrect value for status[7].specific, expected 193, is {}", + msg.status[7].specific + ); + assert_eq!( + msg.status[8].component, 47722, + "incorrect value for status[8].component, expected 47722, is {}", + msg.status[8].component + ); + assert_eq!( + msg.status[8].generic, 210, + "incorrect value for status[8].generic, expected 210, is {}", + msg.status[8].generic + ); + assert_eq!( + msg.status[8].specific, 183, + "incorrect value for status[8].specific, expected 183, is {}", + msg.status[8].specific + ); + assert_eq!( + msg.status[9].component, 33024, + "incorrect value for status[9].component, expected 33024, is {}", + msg.status[9].component + ); + assert_eq!( + msg.status[9].generic, 5, + "incorrect value for status[9].generic, expected 5, is {}", + msg.status[9].generic + ); + assert_eq!( + msg.status[9].specific, 248, + "incorrect value for status[9].specific, expected 248, is {}", + msg.status[9].specific + ); + assert_eq!( + msg.status[10].component, 38369, + "incorrect value for status[10].component, expected 38369, is {}", + msg.status[10].component + ); + assert_eq!( + msg.status[10].generic, 135, + "incorrect value for status[10].generic, expected 135, is {}", + msg.status[10].generic + ); + assert_eq!( + msg.status[10].specific, 127, + "incorrect value for status[10].specific, expected 127, is {}", + msg.status[10].specific + ); + assert_eq!( + msg.status[11].component, 6658, + "incorrect value for status[11].component, expected 6658, is {}", + msg.status[11].component + ); + assert_eq!( + msg.status[11].generic, 88, + "incorrect value for status[11].generic, expected 88, is {}", + msg.status[11].generic + ); + assert_eq!( + msg.status[11].specific, 92, + "incorrect value for status[11].specific, expected 92, is {}", + msg.status[11].specific + ); + assert_eq!( + msg.status[12].component, 26378, + "incorrect value for status[12].component, expected 26378, is {}", + msg.status[12].component + ); + assert_eq!( + msg.status[12].generic, 73, + "incorrect value for status[12].generic, expected 73, is {}", + msg.status[12].generic + ); + assert_eq!( + msg.status[12].specific, 3, + "incorrect value for status[12].specific, expected 3, is {}", + msg.status[12].specific + ); + assert_eq!( + msg.status[13].component, 17511, + "incorrect value for status[13].component, expected 17511, is {}", + msg.status[13].component + ); + assert_eq!( + msg.status[13].generic, 76, + "incorrect value for status[13].generic, expected 76, is {}", + msg.status[13].generic + ); + assert_eq!( + msg.status[13].specific, 184, + "incorrect value for status[13].specific, expected 184, is {}", + msg.status[13].specific + ); + assert_eq!( + msg.status[14].component, 52769, + "incorrect value for status[14].component, expected 52769, is {}", + msg.status[14].component + ); + assert_eq!( + msg.status[14].generic, 194, + "incorrect value for status[14].generic, expected 194, is {}", + msg.status[14].generic + ); + assert_eq!( + msg.status[14].specific, 163, + "incorrect value for status[14].specific, expected 163, is {}", + msg.status[14].specific + ); + assert_eq!( + msg.status[15].component, 7803, + "incorrect value for status[15].component, expected 7803, is {}", + msg.status[15].component + ); + assert_eq!( + msg.status[15].generic, 151, + "incorrect value for status[15].generic, expected 151, is {}", + msg.status[15].generic + ); + assert_eq!( + msg.status[15].specific, 176, + "incorrect value for status[15].specific, expected 176, is {}", + msg.status[15].specific + ); + assert_eq!( + msg.status[16].component, 44181, + "incorrect value for status[16].component, expected 44181, is {}", + msg.status[16].component + ); + assert_eq!( + msg.status[16].generic, 184, + "incorrect value for status[16].generic, expected 184, is {}", + msg.status[16].generic + ); + assert_eq!( + msg.status[16].specific, 231, + "incorrect value for status[16].specific, expected 231, is {}", + msg.status[16].specific + ); + assert_eq!( + msg.status[17].component, 58998, + "incorrect value for status[17].component, expected 58998, is {}", + msg.status[17].component + ); + assert_eq!( + msg.status[17].generic, 200, + "incorrect value for status[17].generic, expected 200, is {}", + msg.status[17].generic + ); + assert_eq!( + msg.status[17].specific, 168, + "incorrect value for status[17].specific, expected 168, is {}", + msg.status[17].specific + ); + assert_eq!( + msg.status[18].component, 28004, + "incorrect value for status[18].component, expected 28004, is {}", + msg.status[18].component + ); + assert_eq!( + msg.status[18].generic, 10, + "incorrect value for status[18].generic, expected 10, is {}", + msg.status[18].generic + ); + assert_eq!( + msg.status[18].specific, 233, + "incorrect value for status[18].specific, expected 233, is {}", + msg.status[18].specific + ); + assert_eq!( + msg.status[19].component, 15364, + "incorrect value for status[19].component, expected 15364, is {}", + msg.status[19].component + ); + assert_eq!( + msg.status[19].generic, 247, + "incorrect value for status[19].generic, expected 247, is {}", + msg.status[19].generic + ); + assert_eq!( + msg.status[19].specific, 82, + "incorrect value for status[19].specific, expected 82, is {}", + msg.status[19].specific + ); + assert_eq!( + msg.status[20].component, 42711, + "incorrect value for status[20].component, expected 42711, is {}", + msg.status[20].component + ); + assert_eq!( + msg.status[20].generic, 28, + "incorrect value for status[20].generic, expected 28, is {}", + msg.status[20].generic + ); + assert_eq!( + msg.status[20].specific, 138, + "incorrect value for status[20].specific, expected 138, is {}", + msg.status[20].specific + ); + assert_eq!( + msg.status[21].component, 11630, + "incorrect value for status[21].component, expected 11630, is {}", + msg.status[21].component + ); + assert_eq!( + msg.status[21].generic, 98, + "incorrect value for status[21].generic, expected 98, is {}", + msg.status[21].generic + ); + assert_eq!( + msg.status[21].specific, 218, + "incorrect value for status[21].specific, expected 218, is {}", + msg.status[21].specific + ); + assert_eq!( + msg.status[22].component, 46068, + "incorrect value for status[22].component, expected 46068, is {}", + msg.status[22].component + ); + assert_eq!( + msg.status[22].generic, 126, + "incorrect value for status[22].generic, expected 126, is {}", + msg.status[22].generic + ); + assert_eq!( + msg.status[22].specific, 107, + "incorrect value for status[22].specific, expected 107, is {}", + msg.status[22].specific + ); + assert_eq!( + msg.status[23].component, 31836, + "incorrect value for status[23].component, expected 31836, is {}", + msg.status[23].component + ); + assert_eq!( + msg.status[23].generic, 94, + "incorrect value for status[23].generic, expected 94, is {}", + msg.status[23].generic + ); + assert_eq!( + msg.status[23].specific, 157, + "incorrect value for status[23].specific, expected 157, is {}", + msg.status[23].specific + ); + assert_eq!( + msg.status[24].component, 47914, + "incorrect value for status[24].component, expected 47914, is {}", + msg.status[24].component + ); + assert_eq!( + msg.status[24].generic, 124, + "incorrect value for status[24].generic, expected 124, is {}", + msg.status[24].generic + ); + assert_eq!( + msg.status[24].specific, 6, + "incorrect value for status[24].specific, expected 6, is {}", + msg.status[24].specific + ); + assert_eq!( + msg.status[25].component, 63329, + "incorrect value for status[25].component, expected 63329, is {}", + msg.status[25].component + ); + assert_eq!( + msg.status[25].generic, 160, + "incorrect value for status[25].generic, expected 160, is {}", + msg.status[25].generic + ); + assert_eq!( + msg.status[25].specific, 188, + "incorrect value for status[25].specific, expected 188, is {}", + msg.status[25].specific + ); + assert_eq!( + msg.status[26].component, 30830, + "incorrect value for status[26].component, expected 30830, is {}", + msg.status[26].component + ); + assert_eq!( + msg.status[26].generic, 254, + "incorrect value for status[26].generic, expected 254, is {}", + msg.status[26].generic + ); + assert_eq!( + msg.status[26].specific, 214, + "incorrect value for status[26].specific, expected 214, is {}", + msg.status[26].specific + ); + assert_eq!( + msg.status[27].component, 13166, + "incorrect value for status[27].component, expected 13166, is {}", + msg.status[27].component + ); + assert_eq!( + msg.status[27].generic, 240, + "incorrect value for status[27].generic, expected 240, is {}", + msg.status[27].generic + ); + assert_eq!( + msg.status[27].specific, 164, + "incorrect value for status[27].specific, expected 164, is {}", + msg.status[27].specific + ); + assert_eq!( + msg.status[28].component, 4755, + "incorrect value for status[28].component, expected 4755, is {}", + msg.status[28].component + ); + assert_eq!( + msg.status[28].generic, 74, + "incorrect value for status[28].generic, expected 74, is {}", + msg.status[28].generic + ); + assert_eq!( + msg.status[28].specific, 178, + "incorrect value for status[28].specific, expected 178, is {}", + msg.status[28].specific + ); + assert_eq!( + msg.status[29].component, 1091, + "incorrect value for status[29].component, expected 1091, is {}", + msg.status[29].component + ); + assert_eq!( + msg.status[29].generic, 27, + "incorrect value for status[29].generic, expected 27, is {}", + msg.status[29].generic + ); + assert_eq!( + msg.status[29].specific, 73, + "incorrect value for status[29].specific, expected 73, is {}", + msg.status[29].specific + ); + assert_eq!( + msg.status[30].component, 16574, + "incorrect value for status[30].component, expected 16574, is {}", + msg.status[30].component + ); + assert_eq!( + msg.status[30].generic, 179, + "incorrect value for status[30].generic, expected 179, is {}", + msg.status[30].generic + ); + assert_eq!( + msg.status[30].specific, 146, + "incorrect value for status[30].specific, expected 146, is {}", + msg.status[30].specific + ); + assert_eq!( + msg.status[31].component, 39293, + "incorrect value for status[31].component, expected 39293, is {}", + msg.status[31].component + ); + assert_eq!( + msg.status[31].generic, 192, + "incorrect value for status[31].generic, expected 192, is {}", + msg.status[31].generic + ); + assert_eq!( + msg.status[31].specific, 46, + "incorrect value for status[31].specific, expected 46, is {}", + msg.status[31].specific + ); + assert_eq!( + msg.status[32].component, 17098, + "incorrect value for status[32].component, expected 17098, is {}", + msg.status[32].component + ); + assert_eq!( + msg.status[32].generic, 248, + "incorrect value for status[32].generic, expected 248, is {}", + msg.status[32].generic + ); + assert_eq!( + msg.status[32].specific, 46, + "incorrect value for status[32].specific, expected 46, is {}", + msg.status[32].specific + ); + assert_eq!( + msg.status[33].component, 41256, + "incorrect value for status[33].component, expected 41256, is {}", + msg.status[33].component + ); + assert_eq!( + msg.status[33].generic, 173, + "incorrect value for status[33].generic, expected 173, is {}", + msg.status[33].generic + ); + assert_eq!( + msg.status[33].specific, 242, + "incorrect value for status[33].specific, expected 242, is {}", + msg.status[33].specific + ); + assert_eq!( + msg.status[34].component, 982, + "incorrect value for status[34].component, expected 982, is {}", + msg.status[34].component + ); + assert_eq!( + msg.status[34].generic, 11, + "incorrect value for status[34].generic, expected 11, is {}", + msg.status[34].generic + ); + assert_eq!( + msg.status[34].specific, 1, + "incorrect value for status[34].specific, expected 1, is {}", + msg.status[34].specific + ); + assert_eq!( + msg.status[35].component, 18038, + "incorrect value for status[35].component, expected 18038, is {}", + msg.status[35].component + ); + assert_eq!( + msg.status[35].generic, 162, + "incorrect value for status[35].generic, expected 162, is {}", + msg.status[35].generic + ); + assert_eq!( + msg.status[35].specific, 61, + "incorrect value for status[35].specific, expected 61, is {}", + msg.status[35].specific + ); + assert_eq!( + msg.status[36].component, 7090, + "incorrect value for status[36].component, expected 7090, is {}", + msg.status[36].component + ); + assert_eq!( + msg.status[36].generic, 156, + "incorrect value for status[36].generic, expected 156, is {}", + msg.status[36].generic + ); + assert_eq!( + msg.status[36].specific, 40, + "incorrect value for status[36].specific, expected 40, is {}", + msg.status[36].specific + ); + assert_eq!( + msg.status[37].component, 29119, + "incorrect value for status[37].component, expected 29119, is {}", + msg.status[37].component + ); + assert_eq!( + msg.status[37].generic, 230, + "incorrect value for status[37].generic, expected 230, is {}", + msg.status[37].generic + ); + assert_eq!( + msg.status[37].specific, 200, + "incorrect value for status[37].specific, expected 200, is {}", + msg.status[37].specific + ); + assert_eq!( + msg.status[38].component, 2120, + "incorrect value for status[38].component, expected 2120, is {}", + msg.status[38].component + ); + assert_eq!( + msg.status[38].generic, 215, + "incorrect value for status[38].generic, expected 215, is {}", + msg.status[38].generic + ); + assert_eq!( + msg.status[38].specific, 245, + "incorrect value for status[38].specific, expected 245, is {}", + msg.status[38].specific + ); + assert_eq!( + msg.status[39].component, 15182, + "incorrect value for status[39].component, expected 15182, is {}", + msg.status[39].component + ); + assert_eq!( + msg.status[39].generic, 222, + "incorrect value for status[39].generic, expected 222, is {}", + msg.status[39].generic + ); + assert_eq!( + msg.status[39].specific, 250, + "incorrect value for status[39].specific, expected 250, is {}", + msg.status[39].specific + ); + assert_eq!( + msg.status[40].component, 8307, + "incorrect value for status[40].component, expected 8307, is {}", + msg.status[40].component + ); + assert_eq!( + msg.status[40].generic, 33, + "incorrect value for status[40].generic, expected 33, is {}", + msg.status[40].generic + ); + assert_eq!( + msg.status[40].specific, 30, + "incorrect value for status[40].specific, expected 30, is {}", + msg.status[40].specific + ); + assert_eq!( + msg.status[41].component, 43731, + "incorrect value for status[41].component, expected 43731, is {}", + msg.status[41].component + ); + assert_eq!( + msg.status[41].generic, 145, + "incorrect value for status[41].generic, expected 145, is {}", + msg.status[41].generic + ); + assert_eq!( + msg.status[41].specific, 92, + "incorrect value for status[41].specific, expected 92, is {}", + msg.status[41].specific + ); + assert_eq!( + msg.status[42].component, 19357, + "incorrect value for status[42].component, expected 19357, is {}", + msg.status[42].component + ); + assert_eq!( + msg.status[42].generic, 24, + "incorrect value for status[42].generic, expected 24, is {}", + msg.status[42].generic + ); + assert_eq!( + msg.status[42].specific, 169, + "incorrect value for status[42].specific, expected 169, is {}", + msg.status[42].specific + ); + assert_eq!( + msg.status[43].component, 14086, + "incorrect value for status[43].component, expected 14086, is {}", + msg.status[43].component + ); + assert_eq!( + msg.status[43].generic, 62, + "incorrect value for status[43].generic, expected 62, is {}", + msg.status[43].generic + ); + assert_eq!( + msg.status[43].specific, 8, + "incorrect value for status[43].specific, expected 8, is {}", + msg.status[43].specific + ); + assert_eq!( + msg.status[44].component, 21099, + "incorrect value for status[44].component, expected 21099, is {}", + msg.status[44].component + ); + assert_eq!( + msg.status[44].generic, 140, + "incorrect value for status[44].generic, expected 140, is {}", + msg.status[44].generic + ); + assert_eq!( + msg.status[44].specific, 49, + "incorrect value for status[44].specific, expected 49, is {}", + msg.status[44].specific + ); + assert_eq!( + msg.status[45].component, 31411, + "incorrect value for status[45].component, expected 31411, is {}", + msg.status[45].component + ); + assert_eq!( + msg.status[45].generic, 90, + "incorrect value for status[45].generic, expected 90, is {}", + msg.status[45].generic + ); + assert_eq!( + msg.status[45].specific, 71, + "incorrect value for status[45].specific, expected 71, is {}", + msg.status[45].specific + ); + assert_eq!( + msg.status[46].component, 22556, + "incorrect value for status[46].component, expected 22556, is {}", + msg.status[46].component + ); + assert_eq!( + msg.status[46].generic, 103, + "incorrect value for status[46].generic, expected 103, is {}", + msg.status[46].generic + ); + assert_eq!( + msg.status[46].specific, 51, + "incorrect value for status[46].specific, expected 51, is {}", + msg.status[46].specific + ); + assert_eq!( + msg.status[47].component, 18609, + "incorrect value for status[47].component, expected 18609, is {}", + msg.status[47].component + ); + assert_eq!( + msg.status[47].generic, 93, + "incorrect value for status[47].generic, expected 93, is {}", + msg.status[47].generic + ); + assert_eq!( + msg.status[47].specific, 39, + "incorrect value for status[47].specific, expected 39, is {}", + msg.status[47].specific + ); + assert_eq!( + msg.status[48].component, 2964, + "incorrect value for status[48].component, expected 2964, is {}", + msg.status[48].component + ); + assert_eq!( + msg.status[48].generic, 202, + "incorrect value for status[48].generic, expected 202, is {}", + msg.status[48].generic + ); + assert_eq!( + msg.status[48].specific, 42, + "incorrect value for status[48].specific, expected 42, is {}", + msg.status[48].specific + ); + assert_eq!( + msg.status[49].component, 23586, + "incorrect value for status[49].component, expected 23586, is {}", + msg.status[49].component + ); + assert_eq!( + msg.status[49].generic, 204, + "incorrect value for status[49].generic, expected 204, is {}", + msg.status[49].generic + ); + assert_eq!( + msg.status[49].specific, 102, + "incorrect value for status[49].specific, expected 102, is {}", + msg.status[49].specific + ); + assert_eq!( + msg.status[50].component, 25117, + "incorrect value for status[50].component, expected 25117, is {}", + msg.status[50].component + ); + assert_eq!( + msg.status[50].generic, 249, + "incorrect value for status[50].generic, expected 249, is {}", + msg.status[50].generic + ); + assert_eq!( + msg.status[50].specific, 91, + "incorrect value for status[50].specific, expected 91, is {}", + msg.status[50].specific + ); + assert_eq!( + msg.status[51].component, 24454, + "incorrect value for status[51].component, expected 24454, is {}", + msg.status[51].component + ); + assert_eq!( + msg.status[51].generic, 23, + "incorrect value for status[51].generic, expected 23, is {}", + msg.status[51].generic + ); + assert_eq!( + msg.status[51].specific, 248, + "incorrect value for status[51].specific, expected 248, is {}", + msg.status[51].specific + ); + assert_eq!( + msg.status[52].component, 5312, + "incorrect value for status[52].component, expected 5312, is {}", + msg.status[52].component + ); + assert_eq!( + msg.status[52].generic, 83, + "incorrect value for status[52].generic, expected 83, is {}", + msg.status[52].generic + ); + assert_eq!( + msg.status[52].specific, 195, + "incorrect value for status[52].specific, expected 195, is {}", + msg.status[52].specific + ); + assert_eq!( + msg.status[53].component, 46175, + "incorrect value for status[53].component, expected 46175, is {}", + msg.status[53].component + ); + assert_eq!( + msg.status[53].generic, 54, + "incorrect value for status[53].generic, expected 54, is {}", + msg.status[53].generic + ); + assert_eq!( + msg.status[53].specific, 36, + "incorrect value for status[53].specific, expected 36, is {}", + msg.status[53].specific + ); + assert_eq!( + msg.status[54].component, 19386, + "incorrect value for status[54].component, expected 19386, is {}", + msg.status[54].component + ); + assert_eq!( + msg.status[54].generic, 64, + "incorrect value for status[54].generic, expected 64, is {}", + msg.status[54].generic + ); + assert_eq!( + msg.status[54].specific, 20, + "incorrect value for status[54].specific, expected 20, is {}", + msg.status[54].specific + ); + assert_eq!( + msg.status[55].component, 34205, + "incorrect value for status[55].component, expected 34205, is {}", + msg.status[55].component + ); + assert_eq!( + msg.status[55].generic, 12, + "incorrect value for status[55].generic, expected 12, is {}", + msg.status[55].generic + ); + assert_eq!( + msg.status[55].specific, 149, + "incorrect value for status[55].specific, expected 149, is {}", + msg.status[55].specific + ); + assert_eq!( + msg.status[56].component, 3612, + "incorrect value for status[56].component, expected 3612, is {}", + msg.status[56].component + ); + assert_eq!( + msg.status[56].generic, 185, + "incorrect value for status[56].generic, expected 185, is {}", + msg.status[56].generic + ); + assert_eq!( + msg.status[56].specific, 129, + "incorrect value for status[56].specific, expected 129, is {}", + msg.status[56].specific + ); + assert_eq!( + msg.status[57].component, 61285, + "incorrect value for status[57].component, expected 61285, is {}", + msg.status[57].component + ); + assert_eq!( + msg.status[57].generic, 74, + "incorrect value for status[57].generic, expected 74, is {}", + msg.status[57].generic + ); + assert_eq!( + msg.status[57].specific, 248, + "incorrect value for status[57].specific, expected 248, is {}", + msg.status[57].specific + ); + assert_eq!( + msg.status[58].component, 7925, + "incorrect value for status[58].component, expected 7925, is {}", + msg.status[58].component + ); + assert_eq!( + msg.status[58].generic, 228, + "incorrect value for status[58].generic, expected 228, is {}", + msg.status[58].generic + ); + assert_eq!( + msg.status[58].specific, 88, + "incorrect value for status[58].specific, expected 88, is {}", + msg.status[58].specific + ); + assert_eq!( + msg.status[59].component, 54414, + "incorrect value for status[59].component, expected 54414, is {}", + msg.status[59].component + ); + assert_eq!( + msg.status[59].generic, 53, + "incorrect value for status[59].generic, expected 53, is {}", + msg.status[59].generic + ); + assert_eq!( + msg.status[59].specific, 224, + "incorrect value for status[59].specific, expected 224, is {}", + msg.status[59].specific + ); + assert_eq!( + msg.uptime, 1657804265, + "incorrect value for uptime, expected 1657804265, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgStatusReport"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_msg_status_report`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_msg_status_report() { + { + let mut payload = Cursor::new(vec![ + 85, 254, 255, 6, 84, 252, 82, 253, 177, 95, 3, 60, 143, 90, 233, 21, 208, 98, 247, 203, + 221, 198, 156, 207, 217, 238, 162, 136, 154, 11, 114, 236, 134, 235, 12, 133, 9, 30, + 175, 145, 26, 114, 215, 20, 146, 249, 54, 54, 133, 193, 106, 186, 210, 183, 0, 129, 5, + 248, 225, 149, 135, 127, 2, 26, 88, 92, 10, 103, 73, 3, 103, 68, 76, 184, 33, 206, 194, + 163, 123, 30, 151, 176, 149, 172, 184, 231, 118, 230, 200, 168, 100, 109, 10, 233, 4, + 60, 247, 82, 215, 166, 28, 138, 110, 45, 98, 218, 244, 179, 126, 107, 92, 124, 94, 157, + 42, 187, 124, 6, 97, 247, 160, 188, 110, 120, 254, 214, 110, 51, 240, 164, 147, 18, 74, + 178, 67, 4, 27, 73, 190, 64, 179, 146, 125, 153, 192, 46, 202, 66, 248, 46, 40, 161, + 173, 242, 214, 3, 11, 1, 118, 70, 162, 61, 178, 27, 156, 40, 191, 113, 230, 200, 72, 8, + 215, 245, 78, 59, 222, 250, 115, 32, 33, 30, 211, 170, 145, 92, 157, 75, 24, 169, 6, + 55, 62, 8, 107, 82, 140, 49, 179, 122, 90, 71, 28, 88, 103, 51, 177, 72, 93, 39, 148, + 11, 202, 42, 34, 92, 204, 102, 29, 98, 249, 91, 134, 95, 23, 248, 192, 20, 83, 195, 95, + 180, 54, 36, 186, 75, 64, 20, 157, 133, 12, 149, 28, 14, 185, 129, 101, 239, 74, 248, + 245, 30, 228, 88, 142, 212, 53, 224, 158, 166, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgStatusReport( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgStatusReport(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0xfffe, + "Incorrect message type, expected 0xfffe, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5406, + "incorrect sender id, expected 0x5406, is {sender_id}" + ); + assert_eq!( + msg.reporting_system, 64850, + "incorrect value for reporting_system, expected 64850, is {}", + msg.reporting_system + ); + assert_eq!( + msg.sbp_version, 24497, + "incorrect value for sbp_version, expected 24497, is {}", + msg.sbp_version + ); + assert_eq!( + msg.sequence, 1519336451, + "incorrect value for sequence, expected 1519336451, is {}", + msg.sequence + ); + assert_eq!( + msg.status[0].component, 52215, + "incorrect value for status[0].component, expected 52215, is {}", + msg.status[0].component + ); + assert_eq!( + msg.status[0].generic, 221, + "incorrect value for status[0].generic, expected 221, is {}", + msg.status[0].generic + ); + assert_eq!( + msg.status[0].specific, 198, + "incorrect value for status[0].specific, expected 198, is {}", + msg.status[0].specific + ); + assert_eq!( + msg.status[1].component, 53148, + "incorrect value for status[1].component, expected 53148, is {}", + msg.status[1].component + ); + assert_eq!( + msg.status[1].generic, 217, + "incorrect value for status[1].generic, expected 217, is {}", + msg.status[1].generic + ); + assert_eq!( + msg.status[1].specific, 238, + "incorrect value for status[1].specific, expected 238, is {}", + msg.status[1].specific + ); + assert_eq!( + msg.status[2].component, 34978, + "incorrect value for status[2].component, expected 34978, is {}", + msg.status[2].component + ); + assert_eq!( + msg.status[2].generic, 154, + "incorrect value for status[2].generic, expected 154, is {}", + msg.status[2].generic + ); + assert_eq!( + msg.status[2].specific, 11, + "incorrect value for status[2].specific, expected 11, is {}", + msg.status[2].specific + ); + assert_eq!( + msg.status[3].component, 60530, + "incorrect value for status[3].component, expected 60530, is {}", + msg.status[3].component + ); + assert_eq!( + msg.status[3].generic, 134, + "incorrect value for status[3].generic, expected 134, is {}", + msg.status[3].generic + ); + assert_eq!( + msg.status[3].specific, 235, + "incorrect value for status[3].specific, expected 235, is {}", + msg.status[3].specific + ); + assert_eq!( + msg.status[4].component, 34060, + "incorrect value for status[4].component, expected 34060, is {}", + msg.status[4].component + ); + assert_eq!( + msg.status[4].generic, 9, + "incorrect value for status[4].generic, expected 9, is {}", + msg.status[4].generic + ); + assert_eq!( + msg.status[4].specific, 30, + "incorrect value for status[4].specific, expected 30, is {}", + msg.status[4].specific + ); + assert_eq!( + msg.status[5].component, 37295, + "incorrect value for status[5].component, expected 37295, is {}", + msg.status[5].component + ); + assert_eq!( + msg.status[5].generic, 26, + "incorrect value for status[5].generic, expected 26, is {}", + msg.status[5].generic + ); + assert_eq!( + msg.status[5].specific, 114, + "incorrect value for status[5].specific, expected 114, is {}", + msg.status[5].specific + ); + assert_eq!( + msg.status[6].component, 5335, + "incorrect value for status[6].component, expected 5335, is {}", + msg.status[6].component + ); + assert_eq!( + msg.status[6].generic, 146, + "incorrect value for status[6].generic, expected 146, is {}", + msg.status[6].generic + ); + assert_eq!( + msg.status[6].specific, 249, + "incorrect value for status[6].specific, expected 249, is {}", + msg.status[6].specific + ); + assert_eq!( + msg.status[7].component, 13878, + "incorrect value for status[7].component, expected 13878, is {}", + msg.status[7].component + ); + assert_eq!( + msg.status[7].generic, 133, + "incorrect value for status[7].generic, expected 133, is {}", + msg.status[7].generic + ); + assert_eq!( + msg.status[7].specific, 193, + "incorrect value for status[7].specific, expected 193, is {}", + msg.status[7].specific + ); + assert_eq!( + msg.status[8].component, 47722, + "incorrect value for status[8].component, expected 47722, is {}", + msg.status[8].component + ); + assert_eq!( + msg.status[8].generic, 210, + "incorrect value for status[8].generic, expected 210, is {}", + msg.status[8].generic + ); + assert_eq!( + msg.status[8].specific, 183, + "incorrect value for status[8].specific, expected 183, is {}", + msg.status[8].specific + ); + assert_eq!( + msg.status[9].component, 33024, + "incorrect value for status[9].component, expected 33024, is {}", + msg.status[9].component + ); + assert_eq!( + msg.status[9].generic, 5, + "incorrect value for status[9].generic, expected 5, is {}", + msg.status[9].generic + ); + assert_eq!( + msg.status[9].specific, 248, + "incorrect value for status[9].specific, expected 248, is {}", + msg.status[9].specific + ); + assert_eq!( + msg.status[10].component, 38369, + "incorrect value for status[10].component, expected 38369, is {}", + msg.status[10].component + ); + assert_eq!( + msg.status[10].generic, 135, + "incorrect value for status[10].generic, expected 135, is {}", + msg.status[10].generic + ); + assert_eq!( + msg.status[10].specific, 127, + "incorrect value for status[10].specific, expected 127, is {}", + msg.status[10].specific + ); + assert_eq!( + msg.status[11].component, 6658, + "incorrect value for status[11].component, expected 6658, is {}", + msg.status[11].component + ); + assert_eq!( + msg.status[11].generic, 88, + "incorrect value for status[11].generic, expected 88, is {}", + msg.status[11].generic + ); + assert_eq!( + msg.status[11].specific, 92, + "incorrect value for status[11].specific, expected 92, is {}", + msg.status[11].specific + ); + assert_eq!( + msg.status[12].component, 26378, + "incorrect value for status[12].component, expected 26378, is {}", + msg.status[12].component + ); + assert_eq!( + msg.status[12].generic, 73, + "incorrect value for status[12].generic, expected 73, is {}", + msg.status[12].generic + ); + assert_eq!( + msg.status[12].specific, 3, + "incorrect value for status[12].specific, expected 3, is {}", + msg.status[12].specific + ); + assert_eq!( + msg.status[13].component, 17511, + "incorrect value for status[13].component, expected 17511, is {}", + msg.status[13].component + ); + assert_eq!( + msg.status[13].generic, 76, + "incorrect value for status[13].generic, expected 76, is {}", + msg.status[13].generic + ); + assert_eq!( + msg.status[13].specific, 184, + "incorrect value for status[13].specific, expected 184, is {}", + msg.status[13].specific + ); + assert_eq!( + msg.status[14].component, 52769, + "incorrect value for status[14].component, expected 52769, is {}", + msg.status[14].component + ); + assert_eq!( + msg.status[14].generic, 194, + "incorrect value for status[14].generic, expected 194, is {}", + msg.status[14].generic + ); + assert_eq!( + msg.status[14].specific, 163, + "incorrect value for status[14].specific, expected 163, is {}", + msg.status[14].specific + ); + assert_eq!( + msg.status[15].component, 7803, + "incorrect value for status[15].component, expected 7803, is {}", + msg.status[15].component + ); + assert_eq!( + msg.status[15].generic, 151, + "incorrect value for status[15].generic, expected 151, is {}", + msg.status[15].generic + ); + assert_eq!( + msg.status[15].specific, 176, + "incorrect value for status[15].specific, expected 176, is {}", + msg.status[15].specific + ); + assert_eq!( + msg.status[16].component, 44181, + "incorrect value for status[16].component, expected 44181, is {}", + msg.status[16].component + ); + assert_eq!( + msg.status[16].generic, 184, + "incorrect value for status[16].generic, expected 184, is {}", + msg.status[16].generic + ); + assert_eq!( + msg.status[16].specific, 231, + "incorrect value for status[16].specific, expected 231, is {}", + msg.status[16].specific + ); + assert_eq!( + msg.status[17].component, 58998, + "incorrect value for status[17].component, expected 58998, is {}", + msg.status[17].component + ); + assert_eq!( + msg.status[17].generic, 200, + "incorrect value for status[17].generic, expected 200, is {}", + msg.status[17].generic + ); + assert_eq!( + msg.status[17].specific, 168, + "incorrect value for status[17].specific, expected 168, is {}", + msg.status[17].specific + ); + assert_eq!( + msg.status[18].component, 28004, + "incorrect value for status[18].component, expected 28004, is {}", + msg.status[18].component + ); + assert_eq!( + msg.status[18].generic, 10, + "incorrect value for status[18].generic, expected 10, is {}", + msg.status[18].generic + ); + assert_eq!( + msg.status[18].specific, 233, + "incorrect value for status[18].specific, expected 233, is {}", + msg.status[18].specific + ); + assert_eq!( + msg.status[19].component, 15364, + "incorrect value for status[19].component, expected 15364, is {}", + msg.status[19].component + ); + assert_eq!( + msg.status[19].generic, 247, + "incorrect value for status[19].generic, expected 247, is {}", + msg.status[19].generic + ); + assert_eq!( + msg.status[19].specific, 82, + "incorrect value for status[19].specific, expected 82, is {}", + msg.status[19].specific + ); + assert_eq!( + msg.status[20].component, 42711, + "incorrect value for status[20].component, expected 42711, is {}", + msg.status[20].component + ); + assert_eq!( + msg.status[20].generic, 28, + "incorrect value for status[20].generic, expected 28, is {}", + msg.status[20].generic + ); + assert_eq!( + msg.status[20].specific, 138, + "incorrect value for status[20].specific, expected 138, is {}", + msg.status[20].specific + ); + assert_eq!( + msg.status[21].component, 11630, + "incorrect value for status[21].component, expected 11630, is {}", + msg.status[21].component + ); + assert_eq!( + msg.status[21].generic, 98, + "incorrect value for status[21].generic, expected 98, is {}", + msg.status[21].generic + ); + assert_eq!( + msg.status[21].specific, 218, + "incorrect value for status[21].specific, expected 218, is {}", + msg.status[21].specific + ); + assert_eq!( + msg.status[22].component, 46068, + "incorrect value for status[22].component, expected 46068, is {}", + msg.status[22].component + ); + assert_eq!( + msg.status[22].generic, 126, + "incorrect value for status[22].generic, expected 126, is {}", + msg.status[22].generic + ); + assert_eq!( + msg.status[22].specific, 107, + "incorrect value for status[22].specific, expected 107, is {}", + msg.status[22].specific + ); + assert_eq!( + msg.status[23].component, 31836, + "incorrect value for status[23].component, expected 31836, is {}", + msg.status[23].component + ); + assert_eq!( + msg.status[23].generic, 94, + "incorrect value for status[23].generic, expected 94, is {}", + msg.status[23].generic + ); + assert_eq!( + msg.status[23].specific, 157, + "incorrect value for status[23].specific, expected 157, is {}", + msg.status[23].specific + ); + assert_eq!( + msg.status[24].component, 47914, + "incorrect value for status[24].component, expected 47914, is {}", + msg.status[24].component + ); + assert_eq!( + msg.status[24].generic, 124, + "incorrect value for status[24].generic, expected 124, is {}", + msg.status[24].generic + ); + assert_eq!( + msg.status[24].specific, 6, + "incorrect value for status[24].specific, expected 6, is {}", + msg.status[24].specific + ); + assert_eq!( + msg.status[25].component, 63329, + "incorrect value for status[25].component, expected 63329, is {}", + msg.status[25].component + ); + assert_eq!( + msg.status[25].generic, 160, + "incorrect value for status[25].generic, expected 160, is {}", + msg.status[25].generic + ); + assert_eq!( + msg.status[25].specific, 188, + "incorrect value for status[25].specific, expected 188, is {}", + msg.status[25].specific + ); + assert_eq!( + msg.status[26].component, 30830, + "incorrect value for status[26].component, expected 30830, is {}", + msg.status[26].component + ); + assert_eq!( + msg.status[26].generic, 254, + "incorrect value for status[26].generic, expected 254, is {}", + msg.status[26].generic + ); + assert_eq!( + msg.status[26].specific, 214, + "incorrect value for status[26].specific, expected 214, is {}", + msg.status[26].specific + ); + assert_eq!( + msg.status[27].component, 13166, + "incorrect value for status[27].component, expected 13166, is {}", + msg.status[27].component + ); + assert_eq!( + msg.status[27].generic, 240, + "incorrect value for status[27].generic, expected 240, is {}", + msg.status[27].generic + ); + assert_eq!( + msg.status[27].specific, 164, + "incorrect value for status[27].specific, expected 164, is {}", + msg.status[27].specific + ); + assert_eq!( + msg.status[28].component, 4755, + "incorrect value for status[28].component, expected 4755, is {}", + msg.status[28].component + ); + assert_eq!( + msg.status[28].generic, 74, + "incorrect value for status[28].generic, expected 74, is {}", + msg.status[28].generic + ); + assert_eq!( + msg.status[28].specific, 178, + "incorrect value for status[28].specific, expected 178, is {}", + msg.status[28].specific + ); + assert_eq!( + msg.status[29].component, 1091, + "incorrect value for status[29].component, expected 1091, is {}", + msg.status[29].component + ); + assert_eq!( + msg.status[29].generic, 27, + "incorrect value for status[29].generic, expected 27, is {}", + msg.status[29].generic + ); + assert_eq!( + msg.status[29].specific, 73, + "incorrect value for status[29].specific, expected 73, is {}", + msg.status[29].specific + ); + assert_eq!( + msg.status[30].component, 16574, + "incorrect value for status[30].component, expected 16574, is {}", + msg.status[30].component + ); + assert_eq!( + msg.status[30].generic, 179, + "incorrect value for status[30].generic, expected 179, is {}", + msg.status[30].generic + ); + assert_eq!( + msg.status[30].specific, 146, + "incorrect value for status[30].specific, expected 146, is {}", + msg.status[30].specific + ); + assert_eq!( + msg.status[31].component, 39293, + "incorrect value for status[31].component, expected 39293, is {}", + msg.status[31].component + ); + assert_eq!( + msg.status[31].generic, 192, + "incorrect value for status[31].generic, expected 192, is {}", + msg.status[31].generic + ); + assert_eq!( + msg.status[31].specific, 46, + "incorrect value for status[31].specific, expected 46, is {}", + msg.status[31].specific + ); + assert_eq!( + msg.status[32].component, 17098, + "incorrect value for status[32].component, expected 17098, is {}", + msg.status[32].component + ); + assert_eq!( + msg.status[32].generic, 248, + "incorrect value for status[32].generic, expected 248, is {}", + msg.status[32].generic + ); + assert_eq!( + msg.status[32].specific, 46, + "incorrect value for status[32].specific, expected 46, is {}", + msg.status[32].specific + ); + assert_eq!( + msg.status[33].component, 41256, + "incorrect value for status[33].component, expected 41256, is {}", + msg.status[33].component + ); + assert_eq!( + msg.status[33].generic, 173, + "incorrect value for status[33].generic, expected 173, is {}", + msg.status[33].generic + ); + assert_eq!( + msg.status[33].specific, 242, + "incorrect value for status[33].specific, expected 242, is {}", + msg.status[33].specific + ); + assert_eq!( + msg.status[34].component, 982, + "incorrect value for status[34].component, expected 982, is {}", + msg.status[34].component + ); + assert_eq!( + msg.status[34].generic, 11, + "incorrect value for status[34].generic, expected 11, is {}", + msg.status[34].generic + ); + assert_eq!( + msg.status[34].specific, 1, + "incorrect value for status[34].specific, expected 1, is {}", + msg.status[34].specific + ); + assert_eq!( + msg.status[35].component, 18038, + "incorrect value for status[35].component, expected 18038, is {}", + msg.status[35].component + ); + assert_eq!( + msg.status[35].generic, 162, + "incorrect value for status[35].generic, expected 162, is {}", + msg.status[35].generic + ); + assert_eq!( + msg.status[35].specific, 61, + "incorrect value for status[35].specific, expected 61, is {}", + msg.status[35].specific + ); + assert_eq!( + msg.status[36].component, 7090, + "incorrect value for status[36].component, expected 7090, is {}", + msg.status[36].component + ); + assert_eq!( + msg.status[36].generic, 156, + "incorrect value for status[36].generic, expected 156, is {}", + msg.status[36].generic + ); + assert_eq!( + msg.status[36].specific, 40, + "incorrect value for status[36].specific, expected 40, is {}", + msg.status[36].specific + ); + assert_eq!( + msg.status[37].component, 29119, + "incorrect value for status[37].component, expected 29119, is {}", + msg.status[37].component + ); + assert_eq!( + msg.status[37].generic, 230, + "incorrect value for status[37].generic, expected 230, is {}", + msg.status[37].generic + ); + assert_eq!( + msg.status[37].specific, 200, + "incorrect value for status[37].specific, expected 200, is {}", + msg.status[37].specific + ); + assert_eq!( + msg.status[38].component, 2120, + "incorrect value for status[38].component, expected 2120, is {}", + msg.status[38].component + ); + assert_eq!( + msg.status[38].generic, 215, + "incorrect value for status[38].generic, expected 215, is {}", + msg.status[38].generic + ); + assert_eq!( + msg.status[38].specific, 245, + "incorrect value for status[38].specific, expected 245, is {}", + msg.status[38].specific + ); + assert_eq!( + msg.status[39].component, 15182, + "incorrect value for status[39].component, expected 15182, is {}", + msg.status[39].component + ); + assert_eq!( + msg.status[39].generic, 222, + "incorrect value for status[39].generic, expected 222, is {}", + msg.status[39].generic + ); + assert_eq!( + msg.status[39].specific, 250, + "incorrect value for status[39].specific, expected 250, is {}", + msg.status[39].specific + ); + assert_eq!( + msg.status[40].component, 8307, + "incorrect value for status[40].component, expected 8307, is {}", + msg.status[40].component + ); + assert_eq!( + msg.status[40].generic, 33, + "incorrect value for status[40].generic, expected 33, is {}", + msg.status[40].generic + ); + assert_eq!( + msg.status[40].specific, 30, + "incorrect value for status[40].specific, expected 30, is {}", + msg.status[40].specific + ); + assert_eq!( + msg.status[41].component, 43731, + "incorrect value for status[41].component, expected 43731, is {}", + msg.status[41].component + ); + assert_eq!( + msg.status[41].generic, 145, + "incorrect value for status[41].generic, expected 145, is {}", + msg.status[41].generic + ); + assert_eq!( + msg.status[41].specific, 92, + "incorrect value for status[41].specific, expected 92, is {}", + msg.status[41].specific + ); + assert_eq!( + msg.status[42].component, 19357, + "incorrect value for status[42].component, expected 19357, is {}", + msg.status[42].component + ); + assert_eq!( + msg.status[42].generic, 24, + "incorrect value for status[42].generic, expected 24, is {}", + msg.status[42].generic + ); + assert_eq!( + msg.status[42].specific, 169, + "incorrect value for status[42].specific, expected 169, is {}", + msg.status[42].specific + ); + assert_eq!( + msg.status[43].component, 14086, + "incorrect value for status[43].component, expected 14086, is {}", + msg.status[43].component + ); + assert_eq!( + msg.status[43].generic, 62, + "incorrect value for status[43].generic, expected 62, is {}", + msg.status[43].generic + ); + assert_eq!( + msg.status[43].specific, 8, + "incorrect value for status[43].specific, expected 8, is {}", + msg.status[43].specific + ); + assert_eq!( + msg.status[44].component, 21099, + "incorrect value for status[44].component, expected 21099, is {}", + msg.status[44].component + ); + assert_eq!( + msg.status[44].generic, 140, + "incorrect value for status[44].generic, expected 140, is {}", + msg.status[44].generic + ); + assert_eq!( + msg.status[44].specific, 49, + "incorrect value for status[44].specific, expected 49, is {}", + msg.status[44].specific + ); + assert_eq!( + msg.status[45].component, 31411, + "incorrect value for status[45].component, expected 31411, is {}", + msg.status[45].component + ); + assert_eq!( + msg.status[45].generic, 90, + "incorrect value for status[45].generic, expected 90, is {}", + msg.status[45].generic + ); + assert_eq!( + msg.status[45].specific, 71, + "incorrect value for status[45].specific, expected 71, is {}", + msg.status[45].specific + ); + assert_eq!( + msg.status[46].component, 22556, + "incorrect value for status[46].component, expected 22556, is {}", + msg.status[46].component + ); + assert_eq!( + msg.status[46].generic, 103, + "incorrect value for status[46].generic, expected 103, is {}", + msg.status[46].generic + ); + assert_eq!( + msg.status[46].specific, 51, + "incorrect value for status[46].specific, expected 51, is {}", + msg.status[46].specific + ); + assert_eq!( + msg.status[47].component, 18609, + "incorrect value for status[47].component, expected 18609, is {}", + msg.status[47].component + ); + assert_eq!( + msg.status[47].generic, 93, + "incorrect value for status[47].generic, expected 93, is {}", + msg.status[47].generic + ); + assert_eq!( + msg.status[47].specific, 39, + "incorrect value for status[47].specific, expected 39, is {}", + msg.status[47].specific + ); + assert_eq!( + msg.status[48].component, 2964, + "incorrect value for status[48].component, expected 2964, is {}", + msg.status[48].component + ); + assert_eq!( + msg.status[48].generic, 202, + "incorrect value for status[48].generic, expected 202, is {}", + msg.status[48].generic + ); + assert_eq!( + msg.status[48].specific, 42, + "incorrect value for status[48].specific, expected 42, is {}", + msg.status[48].specific + ); + assert_eq!( + msg.status[49].component, 23586, + "incorrect value for status[49].component, expected 23586, is {}", + msg.status[49].component + ); + assert_eq!( + msg.status[49].generic, 204, + "incorrect value for status[49].generic, expected 204, is {}", + msg.status[49].generic + ); + assert_eq!( + msg.status[49].specific, 102, + "incorrect value for status[49].specific, expected 102, is {}", + msg.status[49].specific + ); + assert_eq!( + msg.status[50].component, 25117, + "incorrect value for status[50].component, expected 25117, is {}", + msg.status[50].component + ); + assert_eq!( + msg.status[50].generic, 249, + "incorrect value for status[50].generic, expected 249, is {}", + msg.status[50].generic + ); + assert_eq!( + msg.status[50].specific, 91, + "incorrect value for status[50].specific, expected 91, is {}", + msg.status[50].specific + ); + assert_eq!( + msg.status[51].component, 24454, + "incorrect value for status[51].component, expected 24454, is {}", + msg.status[51].component + ); + assert_eq!( + msg.status[51].generic, 23, + "incorrect value for status[51].generic, expected 23, is {}", + msg.status[51].generic + ); + assert_eq!( + msg.status[51].specific, 248, + "incorrect value for status[51].specific, expected 248, is {}", + msg.status[51].specific + ); + assert_eq!( + msg.status[52].component, 5312, + "incorrect value for status[52].component, expected 5312, is {}", + msg.status[52].component + ); + assert_eq!( + msg.status[52].generic, 83, + "incorrect value for status[52].generic, expected 83, is {}", + msg.status[52].generic + ); + assert_eq!( + msg.status[52].specific, 195, + "incorrect value for status[52].specific, expected 195, is {}", + msg.status[52].specific + ); + assert_eq!( + msg.status[53].component, 46175, + "incorrect value for status[53].component, expected 46175, is {}", + msg.status[53].component + ); + assert_eq!( + msg.status[53].generic, 54, + "incorrect value for status[53].generic, expected 54, is {}", + msg.status[53].generic + ); + assert_eq!( + msg.status[53].specific, 36, + "incorrect value for status[53].specific, expected 36, is {}", + msg.status[53].specific + ); + assert_eq!( + msg.status[54].component, 19386, + "incorrect value for status[54].component, expected 19386, is {}", + msg.status[54].component + ); + assert_eq!( + msg.status[54].generic, 64, + "incorrect value for status[54].generic, expected 64, is {}", + msg.status[54].generic + ); + assert_eq!( + msg.status[54].specific, 20, + "incorrect value for status[54].specific, expected 20, is {}", + msg.status[54].specific + ); + assert_eq!( + msg.status[55].component, 34205, + "incorrect value for status[55].component, expected 34205, is {}", + msg.status[55].component + ); + assert_eq!( + msg.status[55].generic, 12, + "incorrect value for status[55].generic, expected 12, is {}", + msg.status[55].generic + ); + assert_eq!( + msg.status[55].specific, 149, + "incorrect value for status[55].specific, expected 149, is {}", + msg.status[55].specific + ); + assert_eq!( + msg.status[56].component, 3612, + "incorrect value for status[56].component, expected 3612, is {}", + msg.status[56].component + ); + assert_eq!( + msg.status[56].generic, 185, + "incorrect value for status[56].generic, expected 185, is {}", + msg.status[56].generic + ); + assert_eq!( + msg.status[56].specific, 129, + "incorrect value for status[56].specific, expected 129, is {}", + msg.status[56].specific + ); + assert_eq!( + msg.status[57].component, 61285, + "incorrect value for status[57].component, expected 61285, is {}", + msg.status[57].component + ); + assert_eq!( + msg.status[57].generic, 74, + "incorrect value for status[57].generic, expected 74, is {}", + msg.status[57].generic + ); + assert_eq!( + msg.status[57].specific, 248, + "incorrect value for status[57].specific, expected 248, is {}", + msg.status[57].specific + ); + assert_eq!( + msg.status[58].component, 7925, + "incorrect value for status[58].component, expected 7925, is {}", + msg.status[58].component + ); + assert_eq!( + msg.status[58].generic, 228, + "incorrect value for status[58].generic, expected 228, is {}", + msg.status[58].generic + ); + assert_eq!( + msg.status[58].specific, 88, + "incorrect value for status[58].specific, expected 88, is {}", + msg.status[58].specific + ); + assert_eq!( + msg.status[59].component, 54414, + "incorrect value for status[59].component, expected 54414, is {}", + msg.status[59].component + ); + assert_eq!( + msg.status[59].generic, 53, + "incorrect value for status[59].generic, expected 53, is {}", + msg.status[59].generic + ); + assert_eq!( + msg.status[59].specific, 224, + "incorrect value for status[59].specific, expected 224, is {}", + msg.status[59].specific + ); + assert_eq!( + msg.uptime, 1657804265, + "incorrect value for uptime, expected 1657804265, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgStatusReport"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_system_system_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_system_system_structs.rs new file mode 100644 index 0000000000..0654b5a87b --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_system_system_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/system/test_system_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_system_system_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_system_system_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_system_system_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_system_system_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_telemetry_acquisition_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_telemetry_acquisition_structs.rs new file mode 100644 index 0000000000..ca1bb7d665 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_telemetry_acquisition_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_acquisition_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_telemetry_acquisition_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_telemetry_acquisition_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_telemetry_acquisition_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_telemetry_acquisition_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_telemetry_telemetry_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_telemetry_telemetry_structs.rs new file mode 100644 index 0000000000..3bb1621c0a --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_telemetry_telemetry_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/telemetry/test_telemetry_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_telemetry_telemetry_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_telemetry_telemetry_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_telemetry_telemetry_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_telemetry_telemetry_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq.rs new file mode 100644 index 0000000000..abd57df594 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq.rs @@ -0,0 +1,304 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_msg_tracking_iq() { + { + let mut payload = Cursor::new(vec![ + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, 55, 45, 38, 189, 88, 159, 19, 208, + 12, 97, 167, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2d, + "Incorrect message type, expected 0x2d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5002, + "incorrect sender id, expected 0x5002, is {sender_id}" + ); + assert_eq!( + msg.channel, 145, + "incorrect value for channel, expected 145, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, -9937, + "incorrect value for corrs[0].i, expected -9937, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 14319, + "incorrect value for corrs[0].q, expected 14319, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 9773, + "incorrect value for corrs[1].i, expected 9773, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 22717, + "incorrect value for corrs[1].q, expected 22717, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 5023, + "incorrect value for corrs[2].i, expected 5023, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 3280, + "incorrect value for corrs[2].q, expected 3280, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 203, + "incorrect value for sid.code, expected 203, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 121, + "incorrect value for sid.sat, expected 121, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIq"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_iq() { + { + let json_input = r#"{"crc":42849,"length":15,"msg_type":45,"payload":"kXnLL9nvNy0mvVifE9AM","preamble":85,"sender":20482,"channel":145,"sid":{"sat":121,"code":203},"corrs":[{"I":-9937,"Q":14319},{"I":9773,"Q":22717},{"I":5023,"Q":3280}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2d, + "Incorrect message type, expected 0x2d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5002, + "incorrect sender id, expected 0x5002, is {sender_id}" + ); + assert_eq!( + msg.channel, 145, + "incorrect value for channel, expected 145, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, -9937, + "incorrect value for corrs[0].i, expected -9937, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 14319, + "incorrect value for corrs[0].q, expected 14319, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 9773, + "incorrect value for corrs[1].i, expected 9773, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 22717, + "incorrect value for corrs[1].q, expected 22717, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 5023, + "incorrect value for corrs[2].i, expected 5023, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 3280, + "incorrect value for corrs[2].q, expected 3280, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 203, + "incorrect value for sid.code, expected 203, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 121, + "incorrect value for sid.sat, expected 121, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIq"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_iq`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_iq() { + { + let mut payload = Cursor::new(vec![ + 85, 45, 0, 2, 80, 15, 145, 121, 203, 47, 217, 239, 55, 45, 38, 189, 88, 159, 19, 208, + 12, 97, 167, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingIq( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIq(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2d, + "Incorrect message type, expected 0x2d, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x5002, + "incorrect sender id, expected 0x5002, is {sender_id}" + ); + assert_eq!( + msg.channel, 145, + "incorrect value for channel, expected 145, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, -9937, + "incorrect value for corrs[0].i, expected -9937, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 14319, + "incorrect value for corrs[0].q, expected 14319, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 9773, + "incorrect value for corrs[1].i, expected 9773, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 22717, + "incorrect value for corrs[1].q, expected 22717, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 5023, + "incorrect value for corrs[2].i, expected 5023, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 3280, + "incorrect value for corrs[2].q, expected 3280, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 203, + "incorrect value for sid.code, expected 203, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 121, + "incorrect value for sid.sat, expected 121, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIq"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_a.rs new file mode 100644 index 0000000000..19e4360bc5 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_a.rs @@ -0,0 +1,319 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_msg_tracking_iq_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, 170, 96, 71, 121, 33, 161, 52, + 211, 162, 101, 41, 36, 226, 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1c, + "Incorrect message type, expected 0x1c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x43b8, + "incorrect sender id, expected 0x43b8, is {sender_id}" + ); + assert_eq!( + msg.channel, 139, + "incorrect value for channel, expected 139, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 1621776995, + "incorrect value for corrs[0].i, expected 1621776995, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, -1591641785, + "incorrect value for corrs[0].q, expected -1591641785, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 1705169716, + "incorrect value for corrs[1].i, expected 1705169716, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 1675764777, + "incorrect value for corrs[1].q, expected 1675764777, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, -267498681, + "incorrect value for corrs[2].i, expected -267498681, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1403998854, + "incorrect value for corrs[2].q, expected 1403998854, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 15, + "incorrect value for sid.code, expected 15, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 64028, + "incorrect value for sid.sat, expected 64028, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_iq_dep_a() { + { + let json_input = r#"{"crc":8721,"length":29,"msg_type":28,"payload":"ixz6DwBjWqpgR3khoTTTomUpJOJjR0sO8IZSr1M=","preamble":85,"sender":17336,"channel":139,"sid":{"sat":64028,"code":15,"reserved":0},"corrs":[{"I":1621776995,"Q":-1591641785},{"I":1705169716,"Q":1675764777},{"I":-267498681,"Q":1403998854}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1c, + "Incorrect message type, expected 0x1c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x43b8, + "incorrect sender id, expected 0x43b8, is {sender_id}" + ); + assert_eq!( + msg.channel, 139, + "incorrect value for channel, expected 139, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 1621776995, + "incorrect value for corrs[0].i, expected 1621776995, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, -1591641785, + "incorrect value for corrs[0].q, expected -1591641785, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 1705169716, + "incorrect value for corrs[1].i, expected 1705169716, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 1675764777, + "incorrect value for corrs[1].q, expected 1675764777, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, -267498681, + "incorrect value for corrs[2].i, expected -267498681, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1403998854, + "incorrect value for corrs[2].q, expected 1403998854, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 15, + "incorrect value for sid.code, expected 15, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 64028, + "incorrect value for sid.sat, expected 64028, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_iq_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_iq_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 28, 0, 184, 67, 29, 139, 28, 250, 15, 0, 99, 90, 170, 96, 71, 121, 33, 161, 52, + 211, 162, 101, 41, 36, 226, 99, 71, 75, 14, 240, 134, 82, 175, 83, 17, 34, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingIqDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x1c, + "Incorrect message type, expected 0x1c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x43b8, + "incorrect sender id, expected 0x43b8, is {sender_id}" + ); + assert_eq!( + msg.channel, 139, + "incorrect value for channel, expected 139, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 1621776995, + "incorrect value for corrs[0].i, expected 1621776995, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, -1591641785, + "incorrect value for corrs[0].q, expected -1591641785, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, 1705169716, + "incorrect value for corrs[1].i, expected 1705169716, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, 1675764777, + "incorrect value for corrs[1].q, expected 1675764777, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, -267498681, + "incorrect value for corrs[2].i, expected -267498681, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1403998854, + "incorrect value for corrs[2].q, expected 1403998854, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 15, + "incorrect value for sid.code, expected 15, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.reserved, 0, + "incorrect value for sid.reserved, expected 0, is {}", + msg.sid.reserved + ); + assert_eq!( + msg.sid.sat, 64028, + "incorrect value for sid.sat, expected 64028, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_b.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_b.rs new file mode 100644 index 0000000000..e362f5b784 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_iq_dep_b.rs @@ -0,0 +1,304 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_msg_tracking_iq_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, 15, 187, 249, 101, 24, 135, 146, + 180, 224, 123, 235, 142, 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2c, + "Incorrect message type, expected 0x2c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6527, + "incorrect sender id, expected 0x6527, is {sender_id}" + ); + assert_eq!( + msg.channel, 45, + "incorrect value for channel, expected 45, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 261994824, + "incorrect value for corrs[0].i, expected 261994824, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 409336251, + "incorrect value for corrs[0].q, expected 409336251, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, -525036921, + "incorrect value for corrs[1].i, expected -525036921, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, -795939973, + "incorrect value for corrs[1].q, expected -795939973, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 353988710, + "incorrect value for corrs[2].i, expected 353988710, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1148477617, + "incorrect value for corrs[2].q, expected 1148477617, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 183, + "incorrect value for sid.code, expected 183, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 188, + "incorrect value for sid.sat, expected 188, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepB"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_iq_dep_b() { + { + let json_input = r#"{"crc":39414,"length":27,"msg_type":44,"payload":"Lby3SLmdD7v5ZRiHkrTge+uO0GZwGRWxYHRE","preamble":85,"sender":25895,"channel":45,"sid":{"sat":188,"code":183},"corrs":[{"I":261994824,"Q":409336251},{"I":-525036921,"Q":-795939973},{"I":353988710,"Q":1148477617}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2c, + "Incorrect message type, expected 0x2c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6527, + "incorrect sender id, expected 0x6527, is {sender_id}" + ); + assert_eq!( + msg.channel, 45, + "incorrect value for channel, expected 45, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 261994824, + "incorrect value for corrs[0].i, expected 261994824, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 409336251, + "incorrect value for corrs[0].q, expected 409336251, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, -525036921, + "incorrect value for corrs[1].i, expected -525036921, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, -795939973, + "incorrect value for corrs[1].q, expected -795939973, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 353988710, + "incorrect value for corrs[2].i, expected 353988710, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1148477617, + "incorrect value for corrs[2].q, expected 1148477617, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 183, + "incorrect value for sid.code, expected 183, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 188, + "incorrect value for sid.sat, expected 188, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_iq_dep_b`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_iq_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 44, 0, 39, 101, 27, 45, 188, 183, 72, 185, 157, 15, 187, 249, 101, 24, 135, 146, + 180, 224, 123, 235, 142, 208, 102, 112, 25, 21, 177, 96, 116, 68, 246, 153, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingIqDepB( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingIqDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x2c, + "Incorrect message type, expected 0x2c, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6527, + "incorrect sender id, expected 0x6527, is {sender_id}" + ); + assert_eq!( + msg.channel, 45, + "incorrect value for channel, expected 45, is {}", + msg.channel + ); + assert_eq!( + msg.corrs[0].i, 261994824, + "incorrect value for corrs[0].i, expected 261994824, is {}", + msg.corrs[0].i + ); + assert_eq!( + msg.corrs[0].q, 409336251, + "incorrect value for corrs[0].q, expected 409336251, is {}", + msg.corrs[0].q + ); + assert_eq!( + msg.corrs[1].i, -525036921, + "incorrect value for corrs[1].i, expected -525036921, is {}", + msg.corrs[1].i + ); + assert_eq!( + msg.corrs[1].q, -795939973, + "incorrect value for corrs[1].q, expected -795939973, is {}", + msg.corrs[1].q + ); + assert_eq!( + msg.corrs[2].i, 353988710, + "incorrect value for corrs[2].i, expected 353988710, is {}", + msg.corrs[2].i + ); + assert_eq!( + msg.corrs[2].q, 1148477617, + "incorrect value for corrs[2].q, expected 1148477617, is {}", + msg.corrs[2].q + ); + assert_eq!( + msg.sid.code, 183, + "incorrect value for sid.code, expected 183, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 188, + "incorrect value for sid.sat, expected 188, is {}", + msg.sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingIqDepB"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state.rs index 7aa4708285..a0087474ec 100644 --- a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state.rs +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state.rs @@ -22,11 +22,20 @@ use crate::*; fn test_auto_check_sbp_tracking_msg_tracking_state() { { let mut payload = Cursor::new(vec![ - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, 66, 1, 203, 0, 0, 0, 231, 99, - 16, 66, 1, 208, 0, 0, 0, 212, 129, 22, 66, 1, 212, 0, 0, 0, 58, 21, 28, 66, 1, 217, 0, - 0, 0, 178, 33, 40, 66, 1, 218, 0, 0, 0, 235, 189, 21, 66, 1, 220, 0, 0, 0, 29, 177, 25, - 66, 1, 222, 0, 0, 0, 43, 169, 27, 66, 1, 225, 0, 0, 0, 137, 125, 42, 66, 0, 0, 0, 0, 0, - 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 222, 97, + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, 25, 4, 90, 195, 246, 108, + 75, 82, 137, 127, 45, 163, 32, 46, 187, 93, 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, + 219, 69, 254, 136, 3, 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, 218, 62, 242, + 84, 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, 253, 227, 216, 227, 24, 26, 210, + 179, 19, 15, 227, 255, 122, 75, 187, 200, 217, 48, 218, 122, 187, 238, 142, 149, 238, + 55, 251, 212, 128, 160, 194, 104, 113, 255, 141, 62, 43, 69, 245, 39, 100, 230, 108, + 56, 247, 68, 149, 143, 137, 101, 233, 70, 49, 165, 38, 110, 218, 230, 80, 213, 196, + 179, 139, 128, 15, 178, 196, 171, 8, 212, 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, 5, + 25, 105, 186, 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, 49, 86, 19, 142, 146, 91, + 124, 115, 64, 28, 230, 115, 178, 190, 131, 16, 242, 105, 59, 182, 113, 192, 180, 48, + 179, 166, 31, 172, 211, 77, 228, 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, + 129, 55, 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, 148, 190, 236, + 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, 219, 172, 145, 17, 192, 179, 111, 97, + 207, 56, 208, 134, 180, 17, 43, 226, 255, 182, 140, 113, 141, 111, ]); // Test the round trip payload parsing @@ -37,1220 +46,1291 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { .expect("failed to parse message") }; match &sbp_msg { - sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + sbp::messages::Sbp::MsgTrackingState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x13, - "Incorrect message type, expected 0x13, is {}", + msg_type, 0x41, + "Incorrect message type, expected 0x41, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0xd7f6, - "incorrect sender id, expected 0xd7f6, is {sender_id}" + sender_id, 0x8137, + "incorrect sender id, expected 0x8137, is {sender_id}" ); - assert!( - msg.states[0].cn0.almost_eq(3.92478218078613281e+01), - "incorrect value for states[0].cn0, expected 3.92478218078613281e+01, is {:e}", + assert_eq!( + msg.states[0].cn0, 102, + "incorrect value for states[0].cn0, expected 102, is {}", msg.states[0].cn0 ); assert_eq!( - msg.states[0].sid.code, 0, - "incorrect value for states[0].sid.code, expected 0, is {}", - msg.states[0].sid.code + msg.states[0].fcn, 3, + "incorrect value for states[0].fcn, expected 3, is {}", + msg.states[0].fcn ); assert_eq!( - msg.states[0].sid.reserved, 0, - "incorrect value for states[0].sid.reserved, expected 0, is {}", - msg.states[0].sid.reserved + msg.states[0].sid.code, 184, + "incorrect value for states[0].sid.code, expected 184, is {}", + msg.states[0].sid.code ); assert_eq!( - msg.states[0].sid.sat, 202, - "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat, 117, + "incorrect value for states[0].sid.sat, expected 117, is {}", msg.states[0].sid.sat ); assert_eq!( - msg.states[0].state, 1, - "incorrect value for states[0].state, expected 1, is {}", - msg.states[0].state - ); - assert!( - msg.states[1].cn0.almost_eq(3.60975608825683594e+01), - "incorrect value for states[1].cn0, expected 3.60975608825683594e+01, is {:e}", + msg.states[1].cn0, 141, + "incorrect value for states[1].cn0, expected 141, is {}", msg.states[1].cn0 ); assert_eq!( - msg.states[1].sid.code, 0, - "incorrect value for states[1].sid.code, expected 0, is {}", - msg.states[1].sid.code + msg.states[1].fcn, 140, + "incorrect value for states[1].fcn, expected 140, is {}", + msg.states[1].fcn ); assert_eq!( - msg.states[1].sid.reserved, 0, - "incorrect value for states[1].sid.reserved, expected 0, is {}", - msg.states[1].sid.reserved + msg.states[1].sid.code, 106, + "incorrect value for states[1].sid.code, expected 106, is {}", + msg.states[1].sid.code ); assert_eq!( - msg.states[1].sid.sat, 203, - "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat, 38, + "incorrect value for states[1].sid.sat, expected 38, is {}", msg.states[1].sid.sat ); assert_eq!( - msg.states[1].state, 1, - "incorrect value for states[1].state, expected 1, is {}", - msg.states[1].state - ); - assert!( - msg.states[2].cn0.almost_eq(3.76267852783203125e+01), - "incorrect value for states[2].cn0, expected 3.76267852783203125e+01, is {:e}", + msg.states[2].cn0, 195, + "incorrect value for states[2].cn0, expected 195, is {}", msg.states[2].cn0 ); assert_eq!( - msg.states[2].sid.code, 0, - "incorrect value for states[2].sid.code, expected 0, is {}", - msg.states[2].sid.code + msg.states[2].fcn, 90, + "incorrect value for states[2].fcn, expected 90, is {}", + msg.states[2].fcn ); assert_eq!( - msg.states[2].sid.reserved, 0, - "incorrect value for states[2].sid.reserved, expected 0, is {}", - msg.states[2].sid.reserved + msg.states[2].sid.code, 4, + "incorrect value for states[2].sid.code, expected 4, is {}", + msg.states[2].sid.code ); assert_eq!( - msg.states[2].sid.sat, 208, - "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat, 25, + "incorrect value for states[2].sid.sat, expected 25, is {}", msg.states[2].sid.sat ); assert_eq!( - msg.states[2].state, 1, - "incorrect value for states[2].state, expected 1, is {}", - msg.states[2].state - ); - assert!( - msg.states[3].cn0.almost_eq(3.90207290649414062e+01), - "incorrect value for states[3].cn0, expected 3.90207290649414062e+01, is {:e}", + msg.states[3].cn0, 82, + "incorrect value for states[3].cn0, expected 82, is {}", msg.states[3].cn0 ); assert_eq!( - msg.states[3].sid.code, 0, - "incorrect value for states[3].sid.code, expected 0, is {}", - msg.states[3].sid.code + msg.states[3].fcn, 75, + "incorrect value for states[3].fcn, expected 75, is {}", + msg.states[3].fcn ); assert_eq!( - msg.states[3].sid.reserved, 0, - "incorrect value for states[3].sid.reserved, expected 0, is {}", - msg.states[3].sid.reserved + msg.states[3].sid.code, 108, + "incorrect value for states[3].sid.code, expected 108, is {}", + msg.states[3].sid.code ); assert_eq!( - msg.states[3].sid.sat, 212, - "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat, 246, + "incorrect value for states[3].sid.sat, expected 246, is {}", msg.states[3].sid.sat ); assert_eq!( - msg.states[3].state, 1, - "incorrect value for states[3].state, expected 1, is {}", - msg.states[3].state - ); - assert!( - msg.states[4].cn0.almost_eq(4.20329055786132812e+01), - "incorrect value for states[4].cn0, expected 4.20329055786132812e+01, is {:e}", + msg.states[4].cn0, 163, + "incorrect value for states[4].cn0, expected 163, is {}", msg.states[4].cn0 ); assert_eq!( - msg.states[4].sid.code, 0, - "incorrect value for states[4].sid.code, expected 0, is {}", - msg.states[4].sid.code + msg.states[4].fcn, 45, + "incorrect value for states[4].fcn, expected 45, is {}", + msg.states[4].fcn ); assert_eq!( - msg.states[4].sid.reserved, 0, - "incorrect value for states[4].sid.reserved, expected 0, is {}", - msg.states[4].sid.reserved + msg.states[4].sid.code, 127, + "incorrect value for states[4].sid.code, expected 127, is {}", + msg.states[4].sid.code ); assert_eq!( - msg.states[4].sid.sat, 217, - "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat, 137, + "incorrect value for states[4].sid.sat, expected 137, is {}", msg.states[4].sid.sat ); assert_eq!( - msg.states[4].state, 1, - "incorrect value for states[4].state, expected 1, is {}", - msg.states[4].state - ); - assert!( - msg.states[5].cn0.almost_eq(3.74354667663574219e+01), - "incorrect value for states[5].cn0, expected 3.74354667663574219e+01, is {:e}", + msg.states[5].cn0, 93, + "incorrect value for states[5].cn0, expected 93, is {}", msg.states[5].cn0 ); assert_eq!( - msg.states[5].sid.code, 0, - "incorrect value for states[5].sid.code, expected 0, is {}", - msg.states[5].sid.code + msg.states[5].fcn, 187, + "incorrect value for states[5].fcn, expected 187, is {}", + msg.states[5].fcn ); assert_eq!( - msg.states[5].sid.reserved, 0, - "incorrect value for states[5].sid.reserved, expected 0, is {}", - msg.states[5].sid.reserved + msg.states[5].sid.code, 46, + "incorrect value for states[5].sid.code, expected 46, is {}", + msg.states[5].sid.code ); assert_eq!( - msg.states[5].sid.sat, 218, - "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat, 32, + "incorrect value for states[5].sid.sat, expected 32, is {}", msg.states[5].sid.sat ); assert_eq!( - msg.states[5].state, 1, - "incorrect value for states[5].state, expected 1, is {}", - msg.states[5].state - ); - assert!( - msg.states[6].cn0.almost_eq(3.84229621887207031e+01), - "incorrect value for states[6].cn0, expected 3.84229621887207031e+01, is {:e}", + msg.states[6].cn0, 147, + "incorrect value for states[6].cn0, expected 147, is {}", msg.states[6].cn0 ); assert_eq!( - msg.states[6].sid.code, 0, - "incorrect value for states[6].sid.code, expected 0, is {}", - msg.states[6].sid.code + msg.states[6].fcn, 201, + "incorrect value for states[6].fcn, expected 201, is {}", + msg.states[6].fcn ); assert_eq!( - msg.states[6].sid.reserved, 0, - "incorrect value for states[6].sid.reserved, expected 0, is {}", - msg.states[6].sid.reserved + msg.states[6].sid.code, 60, + "incorrect value for states[6].sid.code, expected 60, is {}", + msg.states[6].sid.code ); assert_eq!( - msg.states[6].sid.sat, 220, - "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat, 153, + "incorrect value for states[6].sid.sat, expected 153, is {}", msg.states[6].sid.sat ); assert_eq!( - msg.states[6].state, 1, - "incorrect value for states[6].state, expected 1, is {}", - msg.states[6].state - ); - assert!( - msg.states[7].cn0.almost_eq(3.89152030944824219e+01), - "incorrect value for states[7].cn0, expected 3.89152030944824219e+01, is {:e}", + msg.states[7].cn0, 208, + "incorrect value for states[7].cn0, expected 208, is {}", msg.states[7].cn0 ); assert_eq!( - msg.states[7].sid.code, 0, - "incorrect value for states[7].sid.code, expected 0, is {}", - msg.states[7].sid.code + msg.states[7].fcn, 5, + "incorrect value for states[7].fcn, expected 5, is {}", + msg.states[7].fcn ); assert_eq!( - msg.states[7].sid.reserved, 0, - "incorrect value for states[7].sid.reserved, expected 0, is {}", - msg.states[7].sid.reserved + msg.states[7].sid.code, 29, + "incorrect value for states[7].sid.code, expected 29, is {}", + msg.states[7].sid.code ); assert_eq!( - msg.states[7].sid.sat, 222, - "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat, 23, + "incorrect value for states[7].sid.sat, expected 23, is {}", msg.states[7].sid.sat ); assert_eq!( - msg.states[7].state, 1, - "incorrect value for states[7].state, expected 1, is {}", - msg.states[7].state - ); - assert!( - msg.states[8].cn0.almost_eq(4.26225929260253906e+01), - "incorrect value for states[8].cn0, expected 4.26225929260253906e+01, is {:e}", + msg.states[8].cn0, 69, + "incorrect value for states[8].cn0, expected 69, is {}", msg.states[8].cn0 ); assert_eq!( - msg.states[8].sid.code, 0, - "incorrect value for states[8].sid.code, expected 0, is {}", - msg.states[8].sid.code + msg.states[8].fcn, 219, + "incorrect value for states[8].fcn, expected 219, is {}", + msg.states[8].fcn ); assert_eq!( - msg.states[8].sid.reserved, 0, - "incorrect value for states[8].sid.reserved, expected 0, is {}", - msg.states[8].sid.reserved + msg.states[8].sid.code, 30, + "incorrect value for states[8].sid.code, expected 30, is {}", + msg.states[8].sid.code ); assert_eq!( - msg.states[8].sid.sat, 225, - "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat, 181, + "incorrect value for states[8].sid.sat, expected 181, is {}", msg.states[8].sid.sat ); assert_eq!( - msg.states[8].state, 1, - "incorrect value for states[8].state, expected 1, is {}", - msg.states[8].state - ); - assert!( - msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), - "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0, 121, + "incorrect value for states[9].cn0, expected 121, is {}", msg.states[9].cn0 ); assert_eq!( - msg.states[9].sid.code, 0, - "incorrect value for states[9].sid.code, expected 0, is {}", - msg.states[9].sid.code + msg.states[9].fcn, 3, + "incorrect value for states[9].fcn, expected 3, is {}", + msg.states[9].fcn ); assert_eq!( - msg.states[9].sid.reserved, 0, - "incorrect value for states[9].sid.reserved, expected 0, is {}", - msg.states[9].sid.reserved + msg.states[9].sid.code, 136, + "incorrect value for states[9].sid.code, expected 136, is {}", + msg.states[9].sid.code ); assert_eq!( - msg.states[9].sid.sat, 0, - "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat, 254, + "incorrect value for states[9].sid.sat, expected 254, is {}", msg.states[9].sid.sat ); assert_eq!( - msg.states[9].state, 0, - "incorrect value for states[9].state, expected 0, is {}", - msg.states[9].state + msg.states[10].cn0, 215, + "incorrect value for states[10].cn0, expected 215, is {}", + msg.states[10].cn0 ); - assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); assert_eq!( - msg.states[10].sid.code, 0, - "incorrect value for states[10].sid.code, expected 0, is {}", - msg.states[10].sid.code + msg.states[10].fcn, 144, + "incorrect value for states[10].fcn, expected 144, is {}", + msg.states[10].fcn ); assert_eq!( - msg.states[10].sid.reserved, 0, - "incorrect value for states[10].sid.reserved, expected 0, is {}", - msg.states[10].sid.reserved + msg.states[10].sid.code, 98, + "incorrect value for states[10].sid.code, expected 98, is {}", + msg.states[10].sid.code ); assert_eq!( - msg.states[10].sid.sat, 0, - "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat, 33, + "incorrect value for states[10].sid.sat, expected 33, is {}", msg.states[10].sid.sat ); assert_eq!( - msg.states[10].state, 0, - "incorrect value for states[10].state, expected 0, is {}", - msg.states[10].state + msg.states[11].cn0, 56, + "incorrect value for states[11].cn0, expected 56, is {}", + msg.states[11].cn0 ); - } - _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), - }; - let frame = sbp::to_vec(&sbp_msg).unwrap(); - assert_eq!(frame, payload.into_inner()); - } - { - let mut payload = Cursor::new(vec![ - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 250, 249, 27, 66, 1, 203, 0, 0, 0, 40, 143, - 11, 66, 1, 208, 0, 0, 0, 190, 200, 21, 66, 1, 212, 0, 0, 0, 251, 233, 26, 66, 1, 217, - 0, 0, 0, 209, 238, 39, 66, 1, 218, 0, 0, 0, 162, 219, 21, 66, 1, 220, 0, 0, 0, 162, - 197, 25, 66, 1, 222, 0, 0, 0, 14, 35, 28, 66, 1, 225, 0, 0, 0, 9, 153, 43, 66, 0, 0, 0, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 20, 31, - ]); - - // Test the round trip payload parsing - let sbp_msg = { - let mut msgs = iter_messages(&mut payload); - msgs.next() - .expect("no message found") - .expect("failed to parse message") - }; - match &sbp_msg { - sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { - let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x13, - "Incorrect message type, expected 0x13, is {}", - msg_type + msg.states[11].fcn, 14, + "incorrect value for states[11].fcn, expected 14, is {}", + msg.states[11].fcn ); - let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0xd7f6, - "incorrect sender id, expected 0xd7f6, is {sender_id}" + msg.states[11].sid.code, 182, + "incorrect value for states[11].sid.code, expected 182, is {}", + msg.states[11].sid.code ); - assert!( - msg.states[0].cn0.almost_eq(3.89941177368164062e+01), - "incorrect value for states[0].cn0, expected 3.89941177368164062e+01, is {:e}", - msg.states[0].cn0 + assert_eq!( + msg.states[11].sid.sat, 133, + "incorrect value for states[11].sid.sat, expected 133, is {}", + msg.states[11].sid.sat ); assert_eq!( - msg.states[0].sid.code, 0, - "incorrect value for states[0].sid.code, expected 0, is {}", - msg.states[0].sid.code + msg.states[12].cn0, 62, + "incorrect value for states[12].cn0, expected 62, is {}", + msg.states[12].cn0 ); assert_eq!( - msg.states[0].sid.reserved, 0, - "incorrect value for states[0].sid.reserved, expected 0, is {}", - msg.states[0].sid.reserved + msg.states[12].fcn, 218, + "incorrect value for states[12].fcn, expected 218, is {}", + msg.states[12].fcn ); assert_eq!( - msg.states[0].sid.sat, 202, - "incorrect value for states[0].sid.sat, expected 202, is {}", - msg.states[0].sid.sat + msg.states[12].sid.code, 77, + "incorrect value for states[12].sid.code, expected 77, is {}", + msg.states[12].sid.code ); assert_eq!( - msg.states[0].state, 1, - "incorrect value for states[0].state, expected 1, is {}", - msg.states[0].state + msg.states[12].sid.sat, 169, + "incorrect value for states[12].sid.sat, expected 169, is {}", + msg.states[12].sid.sat ); - assert!( - msg.states[1].cn0.almost_eq(3.48898010253906250e+01), - "incorrect value for states[1].cn0, expected 3.48898010253906250e+01, is {:e}", - msg.states[1].cn0 + assert_eq!( + msg.states[13].cn0, 249, + "incorrect value for states[13].cn0, expected 249, is {}", + msg.states[13].cn0 ); assert_eq!( - msg.states[1].sid.code, 0, - "incorrect value for states[1].sid.code, expected 0, is {}", - msg.states[1].sid.code + msg.states[13].fcn, 171, + "incorrect value for states[13].fcn, expected 171, is {}", + msg.states[13].fcn ); assert_eq!( - msg.states[1].sid.reserved, 0, - "incorrect value for states[1].sid.reserved, expected 0, is {}", - msg.states[1].sid.reserved + msg.states[13].sid.code, 84, + "incorrect value for states[13].sid.code, expected 84, is {}", + msg.states[13].sid.code ); assert_eq!( - msg.states[1].sid.sat, 203, - "incorrect value for states[1].sid.sat, expected 203, is {}", - msg.states[1].sid.sat + msg.states[13].sid.sat, 242, + "incorrect value for states[13].sid.sat, expected 242, is {}", + msg.states[13].sid.sat ); assert_eq!( - msg.states[1].state, 1, - "incorrect value for states[1].state, expected 1, is {}", - msg.states[1].state + msg.states[14].cn0, 130, + "incorrect value for states[14].cn0, expected 130, is {}", + msg.states[14].cn0 ); - assert!( - msg.states[2].cn0.almost_eq(3.74460372924804688e+01), - "incorrect value for states[2].cn0, expected 3.74460372924804688e+01, is {:e}", - msg.states[2].cn0 + assert_eq!( + msg.states[14].fcn, 131, + "incorrect value for states[14].fcn, expected 131, is {}", + msg.states[14].fcn ); assert_eq!( - msg.states[2].sid.code, 0, - "incorrect value for states[2].sid.code, expected 0, is {}", - msg.states[2].sid.code + msg.states[14].sid.code, 137, + "incorrect value for states[14].sid.code, expected 137, is {}", + msg.states[14].sid.code ); assert_eq!( - msg.states[2].sid.reserved, 0, - "incorrect value for states[2].sid.reserved, expected 0, is {}", - msg.states[2].sid.reserved + msg.states[14].sid.sat, 152, + "incorrect value for states[14].sid.sat, expected 152, is {}", + msg.states[14].sid.sat ); assert_eq!( - msg.states[2].sid.sat, 208, - "incorrect value for states[2].sid.sat, expected 208, is {}", - msg.states[2].sid.sat + msg.states[15].cn0, 68, + "incorrect value for states[15].cn0, expected 68, is {}", + msg.states[15].cn0 ); assert_eq!( - msg.states[2].state, 1, - "incorrect value for states[2].state, expected 1, is {}", - msg.states[2].state + msg.states[15].fcn, 42, + "incorrect value for states[15].fcn, expected 42, is {}", + msg.states[15].fcn ); - assert!( - msg.states[3].cn0.almost_eq(3.87284965515136719e+01), - "incorrect value for states[3].cn0, expected 3.87284965515136719e+01, is {:e}", - msg.states[3].cn0 + assert_eq!( + msg.states[15].sid.code, 21, + "incorrect value for states[15].sid.code, expected 21, is {}", + msg.states[15].sid.code ); assert_eq!( - msg.states[3].sid.code, 0, - "incorrect value for states[3].sid.code, expected 0, is {}", - msg.states[3].sid.code + msg.states[15].sid.sat, 193, + "incorrect value for states[15].sid.sat, expected 193, is {}", + msg.states[15].sid.sat ); assert_eq!( - msg.states[3].sid.reserved, 0, - "incorrect value for states[3].sid.reserved, expected 0, is {}", - msg.states[3].sid.reserved + msg.states[16].cn0, 227, + "incorrect value for states[16].cn0, expected 227, is {}", + msg.states[16].cn0 ); assert_eq!( - msg.states[3].sid.sat, 212, - "incorrect value for states[3].sid.sat, expected 212, is {}", - msg.states[3].sid.sat + msg.states[16].fcn, 216, + "incorrect value for states[16].fcn, expected 216, is {}", + msg.states[16].fcn ); assert_eq!( - msg.states[3].state, 1, - "incorrect value for states[3].state, expected 1, is {}", - msg.states[3].state + msg.states[16].sid.code, 227, + "incorrect value for states[16].sid.code, expected 227, is {}", + msg.states[16].sid.code ); - assert!( - msg.states[4].cn0.almost_eq(4.19832191467285156e+01), - "incorrect value for states[4].cn0, expected 4.19832191467285156e+01, is {:e}", - msg.states[4].cn0 + assert_eq!( + msg.states[16].sid.sat, 253, + "incorrect value for states[16].sid.sat, expected 253, is {}", + msg.states[16].sid.sat ); assert_eq!( - msg.states[4].sid.code, 0, - "incorrect value for states[4].sid.code, expected 0, is {}", - msg.states[4].sid.code + msg.states[17].cn0, 179, + "incorrect value for states[17].cn0, expected 179, is {}", + msg.states[17].cn0 ); assert_eq!( - msg.states[4].sid.reserved, 0, - "incorrect value for states[4].sid.reserved, expected 0, is {}", - msg.states[4].sid.reserved + msg.states[17].fcn, 210, + "incorrect value for states[17].fcn, expected 210, is {}", + msg.states[17].fcn ); assert_eq!( - msg.states[4].sid.sat, 217, - "incorrect value for states[4].sid.sat, expected 217, is {}", - msg.states[4].sid.sat + msg.states[17].sid.code, 26, + "incorrect value for states[17].sid.code, expected 26, is {}", + msg.states[17].sid.code ); assert_eq!( - msg.states[4].state, 1, - "incorrect value for states[4].state, expected 1, is {}", - msg.states[4].state + msg.states[17].sid.sat, 24, + "incorrect value for states[17].sid.sat, expected 24, is {}", + msg.states[17].sid.sat ); - assert!( - msg.states[5].cn0.almost_eq(3.74644851684570312e+01), - "incorrect value for states[5].cn0, expected 3.74644851684570312e+01, is {:e}", - msg.states[5].cn0 + assert_eq!( + msg.states[18].cn0, 255, + "incorrect value for states[18].cn0, expected 255, is {}", + msg.states[18].cn0 ); assert_eq!( - msg.states[5].sid.code, 0, - "incorrect value for states[5].sid.code, expected 0, is {}", - msg.states[5].sid.code + msg.states[18].fcn, 227, + "incorrect value for states[18].fcn, expected 227, is {}", + msg.states[18].fcn ); assert_eq!( - msg.states[5].sid.reserved, 0, - "incorrect value for states[5].sid.reserved, expected 0, is {}", - msg.states[5].sid.reserved + msg.states[18].sid.code, 15, + "incorrect value for states[18].sid.code, expected 15, is {}", + msg.states[18].sid.code ); assert_eq!( - msg.states[5].sid.sat, 218, - "incorrect value for states[5].sid.sat, expected 218, is {}", - msg.states[5].sid.sat + msg.states[18].sid.sat, 19, + "incorrect value for states[18].sid.sat, expected 19, is {}", + msg.states[18].sid.sat ); assert_eq!( - msg.states[5].state, 1, - "incorrect value for states[5].state, expected 1, is {}", - msg.states[5].state + msg.states[19].cn0, 200, + "incorrect value for states[19].cn0, expected 200, is {}", + msg.states[19].cn0 ); - assert!( - msg.states[6].cn0.almost_eq(3.84430007934570312e+01), - "incorrect value for states[6].cn0, expected 3.84430007934570312e+01, is {:e}", - msg.states[6].cn0 + assert_eq!( + msg.states[19].fcn, 187, + "incorrect value for states[19].fcn, expected 187, is {}", + msg.states[19].fcn ); assert_eq!( - msg.states[6].sid.code, 0, - "incorrect value for states[6].sid.code, expected 0, is {}", - msg.states[6].sid.code + msg.states[19].sid.code, 75, + "incorrect value for states[19].sid.code, expected 75, is {}", + msg.states[19].sid.code ); assert_eq!( - msg.states[6].sid.reserved, 0, - "incorrect value for states[6].sid.reserved, expected 0, is {}", - msg.states[6].sid.reserved + msg.states[19].sid.sat, 122, + "incorrect value for states[19].sid.sat, expected 122, is {}", + msg.states[19].sid.sat ); assert_eq!( - msg.states[6].sid.sat, 220, - "incorrect value for states[6].sid.sat, expected 220, is {}", - msg.states[6].sid.sat + msg.states[20].cn0, 122, + "incorrect value for states[20].cn0, expected 122, is {}", + msg.states[20].cn0 ); assert_eq!( - msg.states[6].state, 1, - "incorrect value for states[6].state, expected 1, is {}", - msg.states[6].state + msg.states[20].fcn, 218, + "incorrect value for states[20].fcn, expected 218, is {}", + msg.states[20].fcn ); - assert!( - msg.states[7].cn0.almost_eq(3.90342330932617188e+01), - "incorrect value for states[7].cn0, expected 3.90342330932617188e+01, is {:e}", - msg.states[7].cn0 + assert_eq!( + msg.states[20].sid.code, 48, + "incorrect value for states[20].sid.code, expected 48, is {}", + msg.states[20].sid.code ); assert_eq!( - msg.states[7].sid.code, 0, - "incorrect value for states[7].sid.code, expected 0, is {}", - msg.states[7].sid.code + msg.states[20].sid.sat, 217, + "incorrect value for states[20].sid.sat, expected 217, is {}", + msg.states[20].sid.sat ); assert_eq!( - msg.states[7].sid.reserved, 0, - "incorrect value for states[7].sid.reserved, expected 0, is {}", - msg.states[7].sid.reserved + msg.states[21].cn0, 149, + "incorrect value for states[21].cn0, expected 149, is {}", + msg.states[21].cn0 ); assert_eq!( - msg.states[7].sid.sat, 222, - "incorrect value for states[7].sid.sat, expected 222, is {}", - msg.states[7].sid.sat + msg.states[21].fcn, 142, + "incorrect value for states[21].fcn, expected 142, is {}", + msg.states[21].fcn ); assert_eq!( - msg.states[7].state, 1, - "incorrect value for states[7].state, expected 1, is {}", - msg.states[7].state + msg.states[21].sid.code, 238, + "incorrect value for states[21].sid.code, expected 238, is {}", + msg.states[21].sid.code ); - assert!( - msg.states[8].cn0.almost_eq(4.28994483947753906e+01), - "incorrect value for states[8].cn0, expected 4.28994483947753906e+01, is {:e}", - msg.states[8].cn0 + assert_eq!( + msg.states[21].sid.sat, 187, + "incorrect value for states[21].sid.sat, expected 187, is {}", + msg.states[21].sid.sat ); assert_eq!( - msg.states[8].sid.code, 0, - "incorrect value for states[8].sid.code, expected 0, is {}", - msg.states[8].sid.code + msg.states[22].cn0, 212, + "incorrect value for states[22].cn0, expected 212, is {}", + msg.states[22].cn0 ); assert_eq!( - msg.states[8].sid.reserved, 0, - "incorrect value for states[8].sid.reserved, expected 0, is {}", - msg.states[8].sid.reserved + msg.states[22].fcn, 251, + "incorrect value for states[22].fcn, expected 251, is {}", + msg.states[22].fcn ); assert_eq!( - msg.states[8].sid.sat, 225, - "incorrect value for states[8].sid.sat, expected 225, is {}", - msg.states[8].sid.sat + msg.states[22].sid.code, 55, + "incorrect value for states[22].sid.code, expected 55, is {}", + msg.states[22].sid.code ); assert_eq!( - msg.states[8].state, 1, - "incorrect value for states[8].state, expected 1, is {}", - msg.states[8].state + msg.states[22].sid.sat, 238, + "incorrect value for states[22].sid.sat, expected 238, is {}", + msg.states[22].sid.sat ); - assert!( - msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), - "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", - msg.states[9].cn0 + assert_eq!( + msg.states[23].cn0, 104, + "incorrect value for states[23].cn0, expected 104, is {}", + msg.states[23].cn0 ); assert_eq!( - msg.states[9].sid.code, 0, - "incorrect value for states[9].sid.code, expected 0, is {}", - msg.states[9].sid.code + msg.states[23].fcn, 194, + "incorrect value for states[23].fcn, expected 194, is {}", + msg.states[23].fcn ); assert_eq!( - msg.states[9].sid.reserved, 0, - "incorrect value for states[9].sid.reserved, expected 0, is {}", - msg.states[9].sid.reserved + msg.states[23].sid.code, 160, + "incorrect value for states[23].sid.code, expected 160, is {}", + msg.states[23].sid.code ); assert_eq!( - msg.states[9].sid.sat, 0, - "incorrect value for states[9].sid.sat, expected 0, is {}", - msg.states[9].sid.sat + msg.states[23].sid.sat, 128, + "incorrect value for states[23].sid.sat, expected 128, is {}", + msg.states[23].sid.sat ); assert_eq!( - msg.states[9].state, 0, - "incorrect value for states[9].state, expected 0, is {}", - msg.states[9].state + msg.states[24].cn0, 62, + "incorrect value for states[24].cn0, expected 62, is {}", + msg.states[24].cn0 ); - assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); assert_eq!( - msg.states[10].sid.code, 0, - "incorrect value for states[10].sid.code, expected 0, is {}", - msg.states[10].sid.code + msg.states[24].fcn, 141, + "incorrect value for states[24].fcn, expected 141, is {}", + msg.states[24].fcn ); assert_eq!( - msg.states[10].sid.reserved, 0, - "incorrect value for states[10].sid.reserved, expected 0, is {}", - msg.states[10].sid.reserved + msg.states[24].sid.code, 255, + "incorrect value for states[24].sid.code, expected 255, is {}", + msg.states[24].sid.code ); assert_eq!( - msg.states[10].sid.sat, 0, - "incorrect value for states[10].sid.sat, expected 0, is {}", - msg.states[10].sid.sat + msg.states[24].sid.sat, 113, + "incorrect value for states[24].sid.sat, expected 113, is {}", + msg.states[24].sid.sat ); assert_eq!( - msg.states[10].state, 0, - "incorrect value for states[10].state, expected 0, is {}", - msg.states[10].state + msg.states[25].cn0, 39, + "incorrect value for states[25].cn0, expected 39, is {}", + msg.states[25].cn0 ); - } - _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), - }; - let frame = sbp::to_vec(&sbp_msg).unwrap(); - assert_eq!(frame, payload.into_inner()); - } - { - let mut payload = Cursor::new(vec![ - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 123, 209, 27, 66, 1, 203, 0, 0, 0, 214, 64, - 15, 66, 1, 208, 0, 0, 0, 56, 55, 22, 66, 1, 212, 0, 0, 0, 91, 142, 27, 66, 1, 217, 0, - 0, 0, 253, 154, 41, 66, 1, 218, 0, 0, 0, 128, 142, 22, 66, 1, 220, 0, 0, 0, 17, 174, - 23, 66, 1, 222, 0, 0, 0, 155, 2, 29, 66, 1, 225, 0, 0, 0, 162, 100, 42, 66, 0, 0, 0, 0, - 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 233, 71, - ]); - - // Test the round trip payload parsing - let sbp_msg = { - let mut msgs = iter_messages(&mut payload); - msgs.next() - .expect("no message found") - .expect("failed to parse message") - }; - match &sbp_msg { - sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { - let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x13, - "Incorrect message type, expected 0x13, is {}", - msg_type + msg.states[25].fcn, 245, + "incorrect value for states[25].fcn, expected 245, is {}", + msg.states[25].fcn ); - let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0xd7f6, - "incorrect sender id, expected 0xd7f6, is {sender_id}" + msg.states[25].sid.code, 69, + "incorrect value for states[25].sid.code, expected 69, is {}", + msg.states[25].sid.code ); - assert!( - msg.states[0].cn0.almost_eq(3.89545707702636719e+01), - "incorrect value for states[0].cn0, expected 3.89545707702636719e+01, is {:e}", - msg.states[0].cn0 + assert_eq!( + msg.states[25].sid.sat, 43, + "incorrect value for states[25].sid.sat, expected 43, is {}", + msg.states[25].sid.sat ); assert_eq!( - msg.states[0].sid.code, 0, - "incorrect value for states[0].sid.code, expected 0, is {}", - msg.states[0].sid.code + msg.states[26].cn0, 56, + "incorrect value for states[26].cn0, expected 56, is {}", + msg.states[26].cn0 ); assert_eq!( - msg.states[0].sid.reserved, 0, - "incorrect value for states[0].sid.reserved, expected 0, is {}", - msg.states[0].sid.reserved + msg.states[26].fcn, 108, + "incorrect value for states[26].fcn, expected 108, is {}", + msg.states[26].fcn ); assert_eq!( - msg.states[0].sid.sat, 202, - "incorrect value for states[0].sid.sat, expected 202, is {}", - msg.states[0].sid.sat + msg.states[26].sid.code, 230, + "incorrect value for states[26].sid.code, expected 230, is {}", + msg.states[26].sid.code ); assert_eq!( - msg.states[0].state, 1, - "incorrect value for states[0].state, expected 1, is {}", - msg.states[0].state + msg.states[26].sid.sat, 100, + "incorrect value for states[26].sid.sat, expected 100, is {}", + msg.states[26].sid.sat ); - assert!( - msg.states[1].cn0.almost_eq(3.58133163452148438e+01), - "incorrect value for states[1].cn0, expected 3.58133163452148438e+01, is {:e}", - msg.states[1].cn0 + assert_eq!( + msg.states[27].cn0, 143, + "incorrect value for states[27].cn0, expected 143, is {}", + msg.states[27].cn0 ); assert_eq!( - msg.states[1].sid.code, 0, - "incorrect value for states[1].sid.code, expected 0, is {}", - msg.states[1].sid.code + msg.states[27].fcn, 149, + "incorrect value for states[27].fcn, expected 149, is {}", + msg.states[27].fcn ); assert_eq!( - msg.states[1].sid.reserved, 0, - "incorrect value for states[1].sid.reserved, expected 0, is {}", - msg.states[1].sid.reserved + msg.states[27].sid.code, 68, + "incorrect value for states[27].sid.code, expected 68, is {}", + msg.states[27].sid.code ); assert_eq!( - msg.states[1].sid.sat, 203, - "incorrect value for states[1].sid.sat, expected 203, is {}", - msg.states[1].sid.sat + msg.states[27].sid.sat, 247, + "incorrect value for states[27].sid.sat, expected 247, is {}", + msg.states[27].sid.sat ); assert_eq!( - msg.states[1].state, 1, - "incorrect value for states[1].state, expected 1, is {}", - msg.states[1].state + msg.states[28].cn0, 70, + "incorrect value for states[28].cn0, expected 70, is {}", + msg.states[28].cn0 ); - assert!( - msg.states[2].cn0.almost_eq(3.75539245605468750e+01), - "incorrect value for states[2].cn0, expected 3.75539245605468750e+01, is {:e}", - msg.states[2].cn0 + assert_eq!( + msg.states[28].fcn, 233, + "incorrect value for states[28].fcn, expected 233, is {}", + msg.states[28].fcn ); assert_eq!( - msg.states[2].sid.code, 0, - "incorrect value for states[2].sid.code, expected 0, is {}", - msg.states[2].sid.code + msg.states[28].sid.code, 101, + "incorrect value for states[28].sid.code, expected 101, is {}", + msg.states[28].sid.code ); assert_eq!( - msg.states[2].sid.reserved, 0, - "incorrect value for states[2].sid.reserved, expected 0, is {}", - msg.states[2].sid.reserved + msg.states[28].sid.sat, 137, + "incorrect value for states[28].sid.sat, expected 137, is {}", + msg.states[28].sid.sat ); assert_eq!( - msg.states[2].sid.sat, 208, - "incorrect value for states[2].sid.sat, expected 208, is {}", - msg.states[2].sid.sat + msg.states[29].cn0, 110, + "incorrect value for states[29].cn0, expected 110, is {}", + msg.states[29].cn0 ); assert_eq!( - msg.states[2].state, 1, - "incorrect value for states[2].state, expected 1, is {}", - msg.states[2].state + msg.states[29].fcn, 38, + "incorrect value for states[29].fcn, expected 38, is {}", + msg.states[29].fcn ); - assert!( - msg.states[3].cn0.almost_eq(3.88890190124511719e+01), - "incorrect value for states[3].cn0, expected 3.88890190124511719e+01, is {:e}", - msg.states[3].cn0 + assert_eq!( + msg.states[29].sid.code, 165, + "incorrect value for states[29].sid.code, expected 165, is {}", + msg.states[29].sid.code ); assert_eq!( - msg.states[3].sid.code, 0, - "incorrect value for states[3].sid.code, expected 0, is {}", - msg.states[3].sid.code + msg.states[29].sid.sat, 49, + "incorrect value for states[29].sid.sat, expected 49, is {}", + msg.states[29].sid.sat ); assert_eq!( - msg.states[3].sid.reserved, 0, - "incorrect value for states[3].sid.reserved, expected 0, is {}", - msg.states[3].sid.reserved + msg.states[30].cn0, 213, + "incorrect value for states[30].cn0, expected 213, is {}", + msg.states[30].cn0 ); assert_eq!( - msg.states[3].sid.sat, 212, - "incorrect value for states[3].sid.sat, expected 212, is {}", - msg.states[3].sid.sat + msg.states[30].fcn, 80, + "incorrect value for states[30].fcn, expected 80, is {}", + msg.states[30].fcn ); assert_eq!( - msg.states[3].state, 1, - "incorrect value for states[3].state, expected 1, is {}", - msg.states[3].state + msg.states[30].sid.code, 230, + "incorrect value for states[30].sid.code, expected 230, is {}", + msg.states[30].sid.code ); - assert!( - msg.states[4].cn0.almost_eq(4.24013557434082031e+01), - "incorrect value for states[4].cn0, expected 4.24013557434082031e+01, is {:e}", - msg.states[4].cn0 + assert_eq!( + msg.states[30].sid.sat, 218, + "incorrect value for states[30].sid.sat, expected 218, is {}", + msg.states[30].sid.sat ); assert_eq!( - msg.states[4].sid.code, 0, - "incorrect value for states[4].sid.code, expected 0, is {}", - msg.states[4].sid.code + msg.states[31].cn0, 128, + "incorrect value for states[31].cn0, expected 128, is {}", + msg.states[31].cn0 ); assert_eq!( - msg.states[4].sid.reserved, 0, - "incorrect value for states[4].sid.reserved, expected 0, is {}", - msg.states[4].sid.reserved + msg.states[31].fcn, 139, + "incorrect value for states[31].fcn, expected 139, is {}", + msg.states[31].fcn ); assert_eq!( - msg.states[4].sid.sat, 217, - "incorrect value for states[4].sid.sat, expected 217, is {}", - msg.states[4].sid.sat + msg.states[31].sid.code, 179, + "incorrect value for states[31].sid.code, expected 179, is {}", + msg.states[31].sid.code ); assert_eq!( - msg.states[4].state, 1, - "incorrect value for states[4].state, expected 1, is {}", - msg.states[4].state + msg.states[31].sid.sat, 196, + "incorrect value for states[31].sid.sat, expected 196, is {}", + msg.states[31].sid.sat ); - assert!( - msg.states[5].cn0.almost_eq(3.76391601562500000e+01), - "incorrect value for states[5].cn0, expected 3.76391601562500000e+01, is {:e}", - msg.states[5].cn0 + assert_eq!( + msg.states[32].cn0, 171, + "incorrect value for states[32].cn0, expected 171, is {}", + msg.states[32].cn0 ); assert_eq!( - msg.states[5].sid.code, 0, - "incorrect value for states[5].sid.code, expected 0, is {}", - msg.states[5].sid.code + msg.states[32].fcn, 196, + "incorrect value for states[32].fcn, expected 196, is {}", + msg.states[32].fcn ); assert_eq!( - msg.states[5].sid.reserved, 0, - "incorrect value for states[5].sid.reserved, expected 0, is {}", - msg.states[5].sid.reserved + msg.states[32].sid.code, 178, + "incorrect value for states[32].sid.code, expected 178, is {}", + msg.states[32].sid.code ); assert_eq!( - msg.states[5].sid.sat, 218, - "incorrect value for states[5].sid.sat, expected 218, is {}", - msg.states[5].sid.sat + msg.states[32].sid.sat, 15, + "incorrect value for states[32].sid.sat, expected 15, is {}", + msg.states[32].sid.sat ); assert_eq!( - msg.states[5].state, 1, - "incorrect value for states[5].state, expected 1, is {}", - msg.states[5].state + msg.states[33].cn0, 194, + "incorrect value for states[33].cn0, expected 194, is {}", + msg.states[33].cn0 ); - assert!( - msg.states[6].cn0.almost_eq(3.79199867248535156e+01), - "incorrect value for states[6].cn0, expected 3.79199867248535156e+01, is {:e}", - msg.states[6].cn0 + assert_eq!( + msg.states[33].fcn, 97, + "incorrect value for states[33].fcn, expected 97, is {}", + msg.states[33].fcn ); assert_eq!( - msg.states[6].sid.code, 0, - "incorrect value for states[6].sid.code, expected 0, is {}", - msg.states[6].sid.code + msg.states[33].sid.code, 212, + "incorrect value for states[33].sid.code, expected 212, is {}", + msg.states[33].sid.code ); assert_eq!( - msg.states[6].sid.reserved, 0, - "incorrect value for states[6].sid.reserved, expected 0, is {}", - msg.states[6].sid.reserved + msg.states[33].sid.sat, 8, + "incorrect value for states[33].sid.sat, expected 8, is {}", + msg.states[33].sid.sat ); assert_eq!( - msg.states[6].sid.sat, 220, - "incorrect value for states[6].sid.sat, expected 220, is {}", - msg.states[6].sid.sat + msg.states[34].cn0, 99, + "incorrect value for states[34].cn0, expected 99, is {}", + msg.states[34].cn0 ); assert_eq!( - msg.states[6].state, 1, - "incorrect value for states[6].state, expected 1, is {}", - msg.states[6].state + msg.states[34].fcn, 79, + "incorrect value for states[34].fcn, expected 79, is {}", + msg.states[34].fcn ); - assert!( - msg.states[7].cn0.almost_eq(3.92525444030761719e+01), - "incorrect value for states[7].cn0, expected 3.92525444030761719e+01, is {:e}", - msg.states[7].cn0 + assert_eq!( + msg.states[34].sid.code, 233, + "incorrect value for states[34].sid.code, expected 233, is {}", + msg.states[34].sid.code ); assert_eq!( - msg.states[7].sid.code, 0, - "incorrect value for states[7].sid.code, expected 0, is {}", - msg.states[7].sid.code + msg.states[34].sid.sat, 83, + "incorrect value for states[34].sid.sat, expected 83, is {}", + msg.states[34].sid.sat ); assert_eq!( - msg.states[7].sid.reserved, 0, - "incorrect value for states[7].sid.reserved, expected 0, is {}", - msg.states[7].sid.reserved + msg.states[35].cn0, 180, + "incorrect value for states[35].cn0, expected 180, is {}", + msg.states[35].cn0 ); assert_eq!( - msg.states[7].sid.sat, 222, - "incorrect value for states[7].sid.sat, expected 222, is {}", - msg.states[7].sid.sat + msg.states[35].fcn, 31, + "incorrect value for states[35].fcn, expected 31, is {}", + msg.states[35].fcn ); assert_eq!( - msg.states[7].state, 1, - "incorrect value for states[7].state, expected 1, is {}", - msg.states[7].state + msg.states[35].sid.code, 90, + "incorrect value for states[35].sid.code, expected 90, is {}", + msg.states[35].sid.code ); - assert!( - msg.states[8].cn0.almost_eq(4.25982742309570312e+01), - "incorrect value for states[8].cn0, expected 4.25982742309570312e+01, is {:e}", - msg.states[8].cn0 + assert_eq!( + msg.states[35].sid.sat, 55, + "incorrect value for states[35].sid.sat, expected 55, is {}", + msg.states[35].sid.sat ); assert_eq!( - msg.states[8].sid.code, 0, - "incorrect value for states[8].sid.code, expected 0, is {}", - msg.states[8].sid.code + msg.states[36].cn0, 186, + "incorrect value for states[36].cn0, expected 186, is {}", + msg.states[36].cn0 ); assert_eq!( - msg.states[8].sid.reserved, 0, - "incorrect value for states[8].sid.reserved, expected 0, is {}", - msg.states[8].sid.reserved + msg.states[36].fcn, 105, + "incorrect value for states[36].fcn, expected 105, is {}", + msg.states[36].fcn ); assert_eq!( - msg.states[8].sid.sat, 225, - "incorrect value for states[8].sid.sat, expected 225, is {}", - msg.states[8].sid.sat + msg.states[36].sid.code, 25, + "incorrect value for states[36].sid.code, expected 25, is {}", + msg.states[36].sid.code ); assert_eq!( - msg.states[8].state, 1, - "incorrect value for states[8].state, expected 1, is {}", - msg.states[8].state + msg.states[36].sid.sat, 5, + "incorrect value for states[36].sid.sat, expected 5, is {}", + msg.states[36].sid.sat ); - assert!( - msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), - "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", - msg.states[9].cn0 + assert_eq!( + msg.states[37].cn0, 111, + "incorrect value for states[37].cn0, expected 111, is {}", + msg.states[37].cn0 ); assert_eq!( - msg.states[9].sid.code, 0, - "incorrect value for states[9].sid.code, expected 0, is {}", - msg.states[9].sid.code + msg.states[37].fcn, 80, + "incorrect value for states[37].fcn, expected 80, is {}", + msg.states[37].fcn ); assert_eq!( - msg.states[9].sid.reserved, 0, - "incorrect value for states[9].sid.reserved, expected 0, is {}", - msg.states[9].sid.reserved + msg.states[37].sid.code, 224, + "incorrect value for states[37].sid.code, expected 224, is {}", + msg.states[37].sid.code ); assert_eq!( - msg.states[9].sid.sat, 0, - "incorrect value for states[9].sid.sat, expected 0, is {}", - msg.states[9].sid.sat + msg.states[37].sid.sat, 22, + "incorrect value for states[37].sid.sat, expected 22, is {}", + msg.states[37].sid.sat ); assert_eq!( - msg.states[9].state, 0, - "incorrect value for states[9].state, expected 0, is {}", - msg.states[9].state + msg.states[38].cn0, 166, + "incorrect value for states[38].cn0, expected 166, is {}", + msg.states[38].cn0 ); - assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); assert_eq!( - msg.states[10].sid.code, 0, - "incorrect value for states[10].sid.code, expected 0, is {}", - msg.states[10].sid.code + msg.states[38].fcn, 106, + "incorrect value for states[38].fcn, expected 106, is {}", + msg.states[38].fcn ); assert_eq!( - msg.states[10].sid.reserved, 0, - "incorrect value for states[10].sid.reserved, expected 0, is {}", - msg.states[10].sid.reserved + msg.states[38].sid.code, 48, + "incorrect value for states[38].sid.code, expected 48, is {}", + msg.states[38].sid.code ); assert_eq!( - msg.states[10].sid.sat, 0, - "incorrect value for states[10].sid.sat, expected 0, is {}", - msg.states[10].sid.sat + msg.states[38].sid.sat, 8, + "incorrect value for states[38].sid.sat, expected 8, is {}", + msg.states[38].sid.sat ); assert_eq!( - msg.states[10].state, 0, - "incorrect value for states[10].state, expected 0, is {}", - msg.states[10].state + msg.states[39].cn0, 49, + "incorrect value for states[39].cn0, expected 49, is {}", + msg.states[39].cn0 ); - } - _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), - }; - let frame = sbp::to_vec(&sbp_msg).unwrap(); - assert_eq!(frame, payload.into_inner()); - } - { - let mut payload = Cursor::new(vec![ - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 120, 122, 29, 66, 1, 203, 0, 0, 0, 66, 22, - 18, 66, 1, 208, 0, 0, 0, 153, 163, 24, 66, 1, 212, 0, 0, 0, 178, 204, 28, 66, 1, 217, - 0, 0, 0, 220, 59, 38, 66, 1, 218, 0, 0, 0, 161, 27, 20, 66, 1, 220, 0, 0, 0, 125, 107, - 24, 66, 1, 222, 0, 0, 0, 242, 46, 28, 66, 1, 225, 0, 0, 0, 231, 130, 41, 66, 0, 0, 0, - 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 73, 193, - ]); - - // Test the round trip payload parsing - let sbp_msg = { - let mut msgs = iter_messages(&mut payload); - msgs.next() - .expect("no message found") - .expect("failed to parse message") - }; - match &sbp_msg { - sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { - let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x13, - "Incorrect message type, expected 0x13, is {}", - msg_type + msg.states[39].fcn, 156, + "incorrect value for states[39].fcn, expected 156, is {}", + msg.states[39].fcn ); - let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0xd7f6, - "incorrect sender id, expected 0xd7f6, is {sender_id}" + msg.states[39].sid.code, 48, + "incorrect value for states[39].sid.code, expected 48, is {}", + msg.states[39].sid.code ); - assert!( - msg.states[0].cn0.almost_eq(3.93695983886718750e+01), - "incorrect value for states[0].cn0, expected 3.93695983886718750e+01, is {:e}", - msg.states[0].cn0 + assert_eq!( + msg.states[39].sid.sat, 4, + "incorrect value for states[39].sid.sat, expected 4, is {}", + msg.states[39].sid.sat ); assert_eq!( - msg.states[0].sid.code, 0, - "incorrect value for states[0].sid.code, expected 0, is {}", - msg.states[0].sid.code + msg.states[40].cn0, 146, + "incorrect value for states[40].cn0, expected 146, is {}", + msg.states[40].cn0 ); assert_eq!( - msg.states[0].sid.reserved, 0, - "incorrect value for states[0].sid.reserved, expected 0, is {}", - msg.states[0].sid.reserved + msg.states[40].fcn, 142, + "incorrect value for states[40].fcn, expected 142, is {}", + msg.states[40].fcn ); assert_eq!( - msg.states[0].sid.sat, 202, - "incorrect value for states[0].sid.sat, expected 202, is {}", - msg.states[0].sid.sat + msg.states[40].sid.code, 19, + "incorrect value for states[40].sid.code, expected 19, is {}", + msg.states[40].sid.code ); assert_eq!( - msg.states[0].state, 1, - "incorrect value for states[0].state, expected 1, is {}", - msg.states[0].state + msg.states[40].sid.sat, 86, + "incorrect value for states[40].sid.sat, expected 86, is {}", + msg.states[40].sid.sat ); - assert!( - msg.states[1].cn0.almost_eq(3.65217361450195312e+01), - "incorrect value for states[1].cn0, expected 3.65217361450195312e+01, is {:e}", - msg.states[1].cn0 + assert_eq!( + msg.states[41].cn0, 64, + "incorrect value for states[41].cn0, expected 64, is {}", + msg.states[41].cn0 ); assert_eq!( - msg.states[1].sid.code, 0, - "incorrect value for states[1].sid.code, expected 0, is {}", - msg.states[1].sid.code + msg.states[41].fcn, 115, + "incorrect value for states[41].fcn, expected 115, is {}", + msg.states[41].fcn ); assert_eq!( - msg.states[1].sid.reserved, 0, - "incorrect value for states[1].sid.reserved, expected 0, is {}", - msg.states[1].sid.reserved + msg.states[41].sid.code, 124, + "incorrect value for states[41].sid.code, expected 124, is {}", + msg.states[41].sid.code ); assert_eq!( - msg.states[1].sid.sat, 203, - "incorrect value for states[1].sid.sat, expected 203, is {}", - msg.states[1].sid.sat + msg.states[41].sid.sat, 91, + "incorrect value for states[41].sid.sat, expected 91, is {}", + msg.states[41].sid.sat ); assert_eq!( - msg.states[1].state, 1, - "incorrect value for states[1].state, expected 1, is {}", - msg.states[1].state + msg.states[42].cn0, 178, + "incorrect value for states[42].cn0, expected 178, is {}", + msg.states[42].cn0 ); - assert!( - msg.states[2].cn0.almost_eq(3.81597633361816406e+01), - "incorrect value for states[2].cn0, expected 3.81597633361816406e+01, is {:e}", - msg.states[2].cn0 + assert_eq!( + msg.states[42].fcn, 115, + "incorrect value for states[42].fcn, expected 115, is {}", + msg.states[42].fcn ); assert_eq!( - msg.states[2].sid.code, 0, - "incorrect value for states[2].sid.code, expected 0, is {}", - msg.states[2].sid.code + msg.states[42].sid.code, 230, + "incorrect value for states[42].sid.code, expected 230, is {}", + msg.states[42].sid.code ); assert_eq!( - msg.states[2].sid.reserved, 0, - "incorrect value for states[2].sid.reserved, expected 0, is {}", - msg.states[2].sid.reserved + msg.states[42].sid.sat, 28, + "incorrect value for states[42].sid.sat, expected 28, is {}", + msg.states[42].sid.sat ); assert_eq!( - msg.states[2].sid.sat, 208, - "incorrect value for states[2].sid.sat, expected 208, is {}", - msg.states[2].sid.sat + msg.states[43].cn0, 242, + "incorrect value for states[43].cn0, expected 242, is {}", + msg.states[43].cn0 ); assert_eq!( - msg.states[2].state, 1, - "incorrect value for states[2].state, expected 1, is {}", - msg.states[2].state + msg.states[43].fcn, 16, + "incorrect value for states[43].fcn, expected 16, is {}", + msg.states[43].fcn ); - assert!( - msg.states[3].cn0.almost_eq(3.91998977661132812e+01), - "incorrect value for states[3].cn0, expected 3.91998977661132812e+01, is {:e}", - msg.states[3].cn0 + assert_eq!( + msg.states[43].sid.code, 131, + "incorrect value for states[43].sid.code, expected 131, is {}", + msg.states[43].sid.code ); assert_eq!( - msg.states[3].sid.code, 0, - "incorrect value for states[3].sid.code, expected 0, is {}", - msg.states[3].sid.code + msg.states[43].sid.sat, 190, + "incorrect value for states[43].sid.sat, expected 190, is {}", + msg.states[43].sid.sat ); assert_eq!( - msg.states[3].sid.reserved, 0, - "incorrect value for states[3].sid.reserved, expected 0, is {}", - msg.states[3].sid.reserved + msg.states[44].cn0, 113, + "incorrect value for states[44].cn0, expected 113, is {}", + msg.states[44].cn0 ); assert_eq!( - msg.states[3].sid.sat, 212, - "incorrect value for states[3].sid.sat, expected 212, is {}", - msg.states[3].sid.sat + msg.states[44].fcn, 182, + "incorrect value for states[44].fcn, expected 182, is {}", + msg.states[44].fcn ); assert_eq!( - msg.states[3].state, 1, - "incorrect value for states[3].state, expected 1, is {}", - msg.states[3].state + msg.states[44].sid.code, 59, + "incorrect value for states[44].sid.code, expected 59, is {}", + msg.states[44].sid.code ); - assert!( - msg.states[4].cn0.almost_eq(4.15584564208984375e+01), - "incorrect value for states[4].cn0, expected 4.15584564208984375e+01, is {:e}", - msg.states[4].cn0 + assert_eq!( + msg.states[44].sid.sat, 105, + "incorrect value for states[44].sid.sat, expected 105, is {}", + msg.states[44].sid.sat ); assert_eq!( - msg.states[4].sid.code, 0, - "incorrect value for states[4].sid.code, expected 0, is {}", - msg.states[4].sid.code + msg.states[45].cn0, 179, + "incorrect value for states[45].cn0, expected 179, is {}", + msg.states[45].cn0 ); assert_eq!( - msg.states[4].sid.reserved, 0, - "incorrect value for states[4].sid.reserved, expected 0, is {}", - msg.states[4].sid.reserved + msg.states[45].fcn, 48, + "incorrect value for states[45].fcn, expected 48, is {}", + msg.states[45].fcn ); assert_eq!( - msg.states[4].sid.sat, 217, - "incorrect value for states[4].sid.sat, expected 217, is {}", - msg.states[4].sid.sat + msg.states[45].sid.code, 180, + "incorrect value for states[45].sid.code, expected 180, is {}", + msg.states[45].sid.code ); assert_eq!( - msg.states[4].state, 1, - "incorrect value for states[4].state, expected 1, is {}", - msg.states[4].state + msg.states[45].sid.sat, 192, + "incorrect value for states[45].sid.sat, expected 192, is {}", + msg.states[45].sid.sat ); - assert!( - msg.states[5].cn0.almost_eq(3.70269813537597656e+01), - "incorrect value for states[5].cn0, expected 3.70269813537597656e+01, is {:e}", - msg.states[5].cn0 + assert_eq!( + msg.states[46].cn0, 211, + "incorrect value for states[46].cn0, expected 211, is {}", + msg.states[46].cn0 ); assert_eq!( - msg.states[5].sid.code, 0, - "incorrect value for states[5].sid.code, expected 0, is {}", - msg.states[5].sid.code + msg.states[46].fcn, 172, + "incorrect value for states[46].fcn, expected 172, is {}", + msg.states[46].fcn ); assert_eq!( - msg.states[5].sid.reserved, 0, - "incorrect value for states[5].sid.reserved, expected 0, is {}", - msg.states[5].sid.reserved + msg.states[46].sid.code, 31, + "incorrect value for states[46].sid.code, expected 31, is {}", + msg.states[46].sid.code ); assert_eq!( - msg.states[5].sid.sat, 218, - "incorrect value for states[5].sid.sat, expected 218, is {}", - msg.states[5].sid.sat + msg.states[46].sid.sat, 166, + "incorrect value for states[46].sid.sat, expected 166, is {}", + msg.states[46].sid.sat ); assert_eq!( - msg.states[5].state, 1, - "incorrect value for states[5].state, expected 1, is {}", - msg.states[5].state + msg.states[47].cn0, 49, + "incorrect value for states[47].cn0, expected 49, is {}", + msg.states[47].cn0 ); - assert!( - msg.states[6].cn0.almost_eq(3.81049690246582031e+01), - "incorrect value for states[6].cn0, expected 3.81049690246582031e+01, is {:e}", - msg.states[6].cn0 + assert_eq!( + msg.states[47].fcn, 140, + "incorrect value for states[47].fcn, expected 140, is {}", + msg.states[47].fcn ); assert_eq!( - msg.states[6].sid.code, 0, - "incorrect value for states[6].sid.code, expected 0, is {}", - msg.states[6].sid.code + msg.states[47].sid.code, 228, + "incorrect value for states[47].sid.code, expected 228, is {}", + msg.states[47].sid.code ); assert_eq!( - msg.states[6].sid.reserved, 0, - "incorrect value for states[6].sid.reserved, expected 0, is {}", - msg.states[6].sid.reserved + msg.states[47].sid.sat, 77, + "incorrect value for states[47].sid.sat, expected 77, is {}", + msg.states[47].sid.sat ); assert_eq!( - msg.states[6].sid.sat, 220, - "incorrect value for states[6].sid.sat, expected 220, is {}", - msg.states[6].sid.sat + msg.states[48].cn0, 194, + "incorrect value for states[48].cn0, expected 194, is {}", + msg.states[48].cn0 ); assert_eq!( - msg.states[6].state, 1, - "incorrect value for states[6].state, expected 1, is {}", - msg.states[6].state + msg.states[48].fcn, 240, + "incorrect value for states[48].fcn, expected 240, is {}", + msg.states[48].fcn ); - assert!( - msg.states[7].cn0.almost_eq(3.90458450317382812e+01), - "incorrect value for states[7].cn0, expected 3.90458450317382812e+01, is {:e}", - msg.states[7].cn0 + assert_eq!( + msg.states[48].sid.code, 77, + "incorrect value for states[48].sid.code, expected 77, is {}", + msg.states[48].sid.code ); assert_eq!( - msg.states[7].sid.code, 0, - "incorrect value for states[7].sid.code, expected 0, is {}", - msg.states[7].sid.code + msg.states[48].sid.sat, 128, + "incorrect value for states[48].sid.sat, expected 128, is {}", + msg.states[48].sid.sat ); assert_eq!( - msg.states[7].sid.reserved, 0, - "incorrect value for states[7].sid.reserved, expected 0, is {}", - msg.states[7].sid.reserved + msg.states[49].cn0, 58, + "incorrect value for states[49].cn0, expected 58, is {}", + msg.states[49].cn0 ); assert_eq!( - msg.states[7].sid.sat, 222, - "incorrect value for states[7].sid.sat, expected 222, is {}", - msg.states[7].sid.sat + msg.states[49].fcn, 41, + "incorrect value for states[49].fcn, expected 41, is {}", + msg.states[49].fcn ); assert_eq!( - msg.states[7].state, 1, - "incorrect value for states[7].state, expected 1, is {}", - msg.states[7].state + msg.states[49].sid.code, 194, + "incorrect value for states[49].sid.code, expected 194, is {}", + msg.states[49].sid.code ); - assert!( - msg.states[8].cn0.almost_eq(4.23778343200683594e+01), - "incorrect value for states[8].cn0, expected 4.23778343200683594e+01, is {:e}", - msg.states[8].cn0 + assert_eq!( + msg.states[49].sid.sat, 134, + "incorrect value for states[49].sid.sat, expected 134, is {}", + msg.states[49].sid.sat ); assert_eq!( - msg.states[8].sid.code, 0, - "incorrect value for states[8].sid.code, expected 0, is {}", - msg.states[8].sid.code + msg.states[50].cn0, 55, + "incorrect value for states[50].cn0, expected 55, is {}", + msg.states[50].cn0 ); assert_eq!( - msg.states[8].sid.reserved, 0, - "incorrect value for states[8].sid.reserved, expected 0, is {}", - msg.states[8].sid.reserved + msg.states[50].fcn, 129, + "incorrect value for states[50].fcn, expected 129, is {}", + msg.states[50].fcn ); assert_eq!( - msg.states[8].sid.sat, 225, - "incorrect value for states[8].sid.sat, expected 225, is {}", - msg.states[8].sid.sat + msg.states[50].sid.code, 53, + "incorrect value for states[50].sid.code, expected 53, is {}", + msg.states[50].sid.code ); assert_eq!( - msg.states[8].state, 1, - "incorrect value for states[8].state, expected 1, is {}", - msg.states[8].state + msg.states[50].sid.sat, 18, + "incorrect value for states[50].sid.sat, expected 18, is {}", + msg.states[50].sid.sat ); - assert!( - msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), - "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", - msg.states[9].cn0 + assert_eq!( + msg.states[51].cn0, 92, + "incorrect value for states[51].cn0, expected 92, is {}", + msg.states[51].cn0 ); assert_eq!( - msg.states[9].sid.code, 0, - "incorrect value for states[9].sid.code, expected 0, is {}", - msg.states[9].sid.code + msg.states[51].fcn, 134, + "incorrect value for states[51].fcn, expected 134, is {}", + msg.states[51].fcn ); assert_eq!( - msg.states[9].sid.reserved, 0, - "incorrect value for states[9].sid.reserved, expected 0, is {}", - msg.states[9].sid.reserved + msg.states[51].sid.code, 72, + "incorrect value for states[51].sid.code, expected 72, is {}", + msg.states[51].sid.code ); assert_eq!( - msg.states[9].sid.sat, 0, - "incorrect value for states[9].sid.sat, expected 0, is {}", - msg.states[9].sid.sat + msg.states[51].sid.sat, 91, + "incorrect value for states[51].sid.sat, expected 91, is {}", + msg.states[51].sid.sat ); assert_eq!( - msg.states[9].state, 0, - "incorrect value for states[9].state, expected 0, is {}", - msg.states[9].state + msg.states[52].cn0, 56, + "incorrect value for states[52].cn0, expected 56, is {}", + msg.states[52].cn0 ); - assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); assert_eq!( - msg.states[10].sid.code, 0, - "incorrect value for states[10].sid.code, expected 0, is {}", - msg.states[10].sid.code + msg.states[52].fcn, 157, + "incorrect value for states[52].fcn, expected 157, is {}", + msg.states[52].fcn ); assert_eq!( - msg.states[10].sid.reserved, 0, - "incorrect value for states[10].sid.reserved, expected 0, is {}", - msg.states[10].sid.reserved + msg.states[52].sid.code, 224, + "incorrect value for states[52].sid.code, expected 224, is {}", + msg.states[52].sid.code ); assert_eq!( - msg.states[10].sid.sat, 0, - "incorrect value for states[10].sid.sat, expected 0, is {}", - msg.states[10].sid.sat + msg.states[52].sid.sat, 33, + "incorrect value for states[52].sid.sat, expected 33, is {}", + msg.states[52].sid.sat ); assert_eq!( - msg.states[10].state, 0, - "incorrect value for states[10].state, expected 0, is {}", - msg.states[10].state + msg.states[53].cn0, 174, + "incorrect value for states[53].cn0, expected 174, is {}", + msg.states[53].cn0 + ); + assert_eq!( + msg.states[53].fcn, 224, + "incorrect value for states[53].fcn, expected 224, is {}", + msg.states[53].fcn + ); + assert_eq!( + msg.states[53].sid.code, 54, + "incorrect value for states[53].sid.code, expected 54, is {}", + msg.states[53].sid.code + ); + assert_eq!( + msg.states[53].sid.sat, 186, + "incorrect value for states[53].sid.sat, expected 186, is {}", + msg.states[53].sid.sat + ); + assert_eq!( + msg.states[54].cn0, 190, + "incorrect value for states[54].cn0, expected 190, is {}", + msg.states[54].cn0 + ); + assert_eq!( + msg.states[54].fcn, 148, + "incorrect value for states[54].fcn, expected 148, is {}", + msg.states[54].fcn + ); + assert_eq!( + msg.states[54].sid.code, 84, + "incorrect value for states[54].sid.code, expected 84, is {}", + msg.states[54].sid.code + ); + assert_eq!( + msg.states[54].sid.sat, 82, + "incorrect value for states[54].sid.sat, expected 82, is {}", + msg.states[54].sid.sat + ); + assert_eq!( + msg.states[55].cn0, 67, + "incorrect value for states[55].cn0, expected 67, is {}", + msg.states[55].cn0 + ); + assert_eq!( + msg.states[55].fcn, 62, + "incorrect value for states[55].fcn, expected 62, is {}", + msg.states[55].fcn + ); + assert_eq!( + msg.states[55].sid.code, 54, + "incorrect value for states[55].sid.code, expected 54, is {}", + msg.states[55].sid.code + ); + assert_eq!( + msg.states[55].sid.sat, 236, + "incorrect value for states[55].sid.sat, expected 236, is {}", + msg.states[55].sid.sat + ); + assert_eq!( + msg.states[56].cn0, 254, + "incorrect value for states[56].cn0, expected 254, is {}", + msg.states[56].cn0 + ); + assert_eq!( + msg.states[56].fcn, 57, + "incorrect value for states[56].fcn, expected 57, is {}", + msg.states[56].fcn + ); + assert_eq!( + msg.states[56].sid.code, 215, + "incorrect value for states[56].sid.code, expected 215, is {}", + msg.states[56].sid.code + ); + assert_eq!( + msg.states[56].sid.sat, 52, + "incorrect value for states[56].sid.sat, expected 52, is {}", + msg.states[56].sid.sat + ); + assert_eq!( + msg.states[57].cn0, 174, + "incorrect value for states[57].cn0, expected 174, is {}", + msg.states[57].cn0 + ); + assert_eq!( + msg.states[57].fcn, 36, + "incorrect value for states[57].fcn, expected 36, is {}", + msg.states[57].fcn + ); + assert_eq!( + msg.states[57].sid.code, 133, + "incorrect value for states[57].sid.code, expected 133, is {}", + msg.states[57].sid.code + ); + assert_eq!( + msg.states[57].sid.sat, 16, + "incorrect value for states[57].sid.sat, expected 16, is {}", + msg.states[57].sid.sat + ); + assert_eq!( + msg.states[58].cn0, 17, + "incorrect value for states[58].cn0, expected 17, is {}", + msg.states[58].cn0 + ); + assert_eq!( + msg.states[58].fcn, 145, + "incorrect value for states[58].fcn, expected 145, is {}", + msg.states[58].fcn + ); + assert_eq!( + msg.states[58].sid.code, 172, + "incorrect value for states[58].sid.code, expected 172, is {}", + msg.states[58].sid.code + ); + assert_eq!( + msg.states[58].sid.sat, 219, + "incorrect value for states[58].sid.sat, expected 219, is {}", + msg.states[58].sid.sat + ); + assert_eq!( + msg.states[59].cn0, 97, + "incorrect value for states[59].cn0, expected 97, is {}", + msg.states[59].cn0 + ); + assert_eq!( + msg.states[59].fcn, 111, + "incorrect value for states[59].fcn, expected 111, is {}", + msg.states[59].fcn + ); + assert_eq!( + msg.states[59].sid.code, 179, + "incorrect value for states[59].sid.code, expected 179, is {}", + msg.states[59].sid.code + ); + assert_eq!( + msg.states[59].sid.sat, 192, + "incorrect value for states[59].sid.sat, expected 192, is {}", + msg.states[59].sid.sat + ); + assert_eq!( + msg.states[60].cn0, 134, + "incorrect value for states[60].cn0, expected 134, is {}", + msg.states[60].cn0 + ); + assert_eq!( + msg.states[60].fcn, 208, + "incorrect value for states[60].fcn, expected 208, is {}", + msg.states[60].fcn + ); + assert_eq!( + msg.states[60].sid.code, 56, + "incorrect value for states[60].sid.code, expected 56, is {}", + msg.states[60].sid.code + ); + assert_eq!( + msg.states[60].sid.sat, 207, + "incorrect value for states[60].sid.sat, expected 207, is {}", + msg.states[60].sid.sat + ); + assert_eq!( + msg.states[61].cn0, 226, + "incorrect value for states[61].cn0, expected 226, is {}", + msg.states[61].cn0 + ); + assert_eq!( + msg.states[61].fcn, 43, + "incorrect value for states[61].fcn, expected 43, is {}", + msg.states[61].fcn + ); + assert_eq!( + msg.states[61].sid.code, 17, + "incorrect value for states[61].sid.code, expected 17, is {}", + msg.states[61].sid.code + ); + assert_eq!( + msg.states[61].sid.sat, 180, + "incorrect value for states[61].sid.sat, expected 180, is {}", + msg.states[61].sid.sat + ); + assert_eq!( + msg.states[62].cn0, 113, + "incorrect value for states[62].cn0, expected 113, is {}", + msg.states[62].cn0 + ); + assert_eq!( + msg.states[62].fcn, 140, + "incorrect value for states[62].fcn, expected 140, is {}", + msg.states[62].fcn + ); + assert_eq!( + msg.states[62].sid.code, 182, + "incorrect value for states[62].sid.code, expected 182, is {}", + msg.states[62].sid.code + ); + assert_eq!( + msg.states[62].sid.sat, 255, + "incorrect value for states[62].sid.sat, expected 255, is {}", + msg.states[62].sid.sat ); } - _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + _ => panic!("Invalid message type! Expected a MsgTrackingState"), }; let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } { let mut payload = Cursor::new(vec![ - 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 103, 208, 30, 66, 1, 203, 0, 0, 0, 117, 24, - 18, 66, 1, 208, 0, 0, 0, 200, 173, 20, 66, 1, 212, 0, 0, 0, 137, 68, 27, 66, 1, 217, 0, - 0, 0, 243, 51, 40, 66, 1, 218, 0, 0, 0, 225, 58, 23, 66, 1, 220, 0, 0, 0, 132, 221, 22, - 66, 1, 222, 0, 0, 0, 157, 29, 26, 66, 1, 225, 0, 0, 0, 133, 21, 41, 66, 0, 0, 0, 0, 0, - 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 126, 47, + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, 66, 1, 203, 0, 0, 0, 231, 99, + 16, 66, 1, 208, 0, 0, 0, 212, 129, 22, 66, 1, 212, 0, 0, 0, 58, 21, 28, 66, 1, 217, 0, + 0, 0, 178, 33, 40, 66, 1, 218, 0, 0, 0, 235, 189, 21, 66, 1, 220, 0, 0, 0, 29, 177, 25, + 66, 1, 222, 0, 0, 0, 43, 169, 27, 66, 1, 225, 0, 0, 0, 137, 125, 42, 66, 0, 0, 0, 0, 0, + 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 222, 97, ]); // Test the round trip payload parsing @@ -1274,8 +1354,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert!( - msg.states[0].cn0.almost_eq(3.97035179138183594e+01), - "incorrect value for states[0].cn0, expected 3.97035179138183594e+01, is {:e}", + msg.states[0].cn0.almost_eq(3.92478218078613281e+01), + "incorrect value for states[0].cn0, expected 3.92478218078613281e+01, is {:e}", msg.states[0].cn0 ); assert_eq!( @@ -1299,8 +1379,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[0].state ); assert!( - msg.states[1].cn0.almost_eq(3.65238838195800781e+01), - "incorrect value for states[1].cn0, expected 3.65238838195800781e+01, is {:e}", + msg.states[1].cn0.almost_eq(3.60975608825683594e+01), + "incorrect value for states[1].cn0, expected 3.60975608825683594e+01, is {:e}", msg.states[1].cn0 ); assert_eq!( @@ -1324,8 +1404,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[1].state ); assert!( - msg.states[2].cn0.almost_eq(3.71697082519531250e+01), - "incorrect value for states[2].cn0, expected 3.71697082519531250e+01, is {:e}", + msg.states[2].cn0.almost_eq(3.76267852783203125e+01), + "incorrect value for states[2].cn0, expected 3.76267852783203125e+01, is {:e}", msg.states[2].cn0 ); assert_eq!( @@ -1349,8 +1429,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[2].state ); assert!( - msg.states[3].cn0.almost_eq(3.88169288635253906e+01), - "incorrect value for states[3].cn0, expected 3.88169288635253906e+01, is {:e}", + msg.states[3].cn0.almost_eq(3.90207290649414062e+01), + "incorrect value for states[3].cn0, expected 3.90207290649414062e+01, is {:e}", msg.states[3].cn0 ); assert_eq!( @@ -1374,8 +1454,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[3].state ); assert!( - msg.states[4].cn0.almost_eq(4.20507316589355469e+01), - "incorrect value for states[4].cn0, expected 4.20507316589355469e+01, is {:e}", + msg.states[4].cn0.almost_eq(4.20329055786132812e+01), + "incorrect value for states[4].cn0, expected 4.20329055786132812e+01, is {:e}", msg.states[4].cn0 ); assert_eq!( @@ -1399,8 +1479,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[4].state ); assert!( - msg.states[5].cn0.almost_eq(3.78074989318847656e+01), - "incorrect value for states[5].cn0, expected 3.78074989318847656e+01, is {:e}", + msg.states[5].cn0.almost_eq(3.74354667663574219e+01), + "incorrect value for states[5].cn0, expected 3.74354667663574219e+01, is {:e}", msg.states[5].cn0 ); assert_eq!( @@ -1424,8 +1504,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[5].state ); assert!( - msg.states[6].cn0.almost_eq(3.77163238525390625e+01), - "incorrect value for states[6].cn0, expected 3.77163238525390625e+01, is {:e}", + msg.states[6].cn0.almost_eq(3.84229621887207031e+01), + "incorrect value for states[6].cn0, expected 3.84229621887207031e+01, is {:e}", msg.states[6].cn0 ); assert_eq!( @@ -1449,8 +1529,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[6].state ); assert!( - msg.states[7].cn0.almost_eq(3.85289192199707031e+01), - "incorrect value for states[7].cn0, expected 3.85289192199707031e+01, is {:e}", + msg.states[7].cn0.almost_eq(3.89152030944824219e+01), + "incorrect value for states[7].cn0, expected 3.89152030944824219e+01, is {:e}", msg.states[7].cn0 ); assert_eq!( @@ -1474,8 +1554,8 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { msg.states[7].state ); assert!( - msg.states[8].cn0.almost_eq(4.22710151672363281e+01), - "incorrect value for states[8].cn0, expected 4.22710151672363281e+01, is {:e}", + msg.states[8].cn0.almost_eq(4.26225929260253906e+01), + "incorrect value for states[8].cn0, expected 4.26225929260253906e+01, is {:e}", msg.states[8].cn0 ); assert_eq!( @@ -1550,38 +1630,21 @@ fn test_auto_check_sbp_tracking_msg_tracking_state() { let frame = sbp::to_vec(&sbp_msg).unwrap(); assert_eq!(frame, payload.into_inner()); } -} - -/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message -/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. -/// -/// Asserts: -/// - SBP message constructed via payload is identical to from fields -/// - SBP fields equates to that of the field -/// - Payload is identical -#[test] -#[cfg(feature = "json")] -fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { { - let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.24782180786133, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.09756088256836, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.62678527832031, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 39.020729064941406, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.03290557861328, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.43546676635742, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.4229621887207, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 38.91520309448242, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.62259292602539, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 25054, "length": 99, "preamble": 85, "payload": "AcoAAADF/RxCAcsAAADnYxBCAdAAAADUgRZCAdQAAAA6FRxCAdkAAACyIShCAdoAAADrvRVCAdwAAAAdsRlCAd4AAAArqRtCAeEAAACJfSpCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + let mut payload = Cursor::new(vec![ + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 250, 249, 27, 66, 1, 203, 0, 0, 0, 40, 143, + 11, 66, 1, 208, 0, 0, 0, 190, 200, 21, 66, 1, 212, 0, 0, 0, 251, 233, 26, 66, 1, 217, + 0, 0, 0, 209, 238, 39, 66, 1, 218, 0, 0, 0, 162, 219, 21, 66, 1, 220, 0, 0, 0, 162, + 197, 25, 66, 1, 222, 0, 0, 0, 14, 35, 28, 66, 1, 225, 0, 0, 0, 9, 153, 43, 66, 0, 0, 0, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 20, 31, + ]); + // Test the round trip payload parsing let sbp_msg = { - // JSON to SBP message from payload - let mut iter = json2sbp_iter_msg(json_input); - let from_payload = iter - .next() - .expect("no message found") - .expect("failed to parse message"); - - // JSON to SBP message from fields - let mut iter = iter_messages_from_fields(json_input); - let from_fields = iter - .next() + let mut msgs = iter_messages(&mut payload); + msgs.next() .expect("no message found") - .expect("failed to parse message"); - - assert_eq!(from_fields, from_payload); - from_fields + .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { @@ -1597,8 +1660,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert!( - msg.states[0].cn0.almost_eq(3.92478218078613281e+01), - "incorrect value for states[0].cn0, expected 3.92478218078613281e+01, is {:e}", + msg.states[0].cn0.almost_eq(3.89941177368164062e+01), + "incorrect value for states[0].cn0, expected 3.89941177368164062e+01, is {:e}", msg.states[0].cn0 ); assert_eq!( @@ -1622,8 +1685,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[0].state ); assert!( - msg.states[1].cn0.almost_eq(3.60975608825683594e+01), - "incorrect value for states[1].cn0, expected 3.60975608825683594e+01, is {:e}", + msg.states[1].cn0.almost_eq(3.48898010253906250e+01), + "incorrect value for states[1].cn0, expected 3.48898010253906250e+01, is {:e}", msg.states[1].cn0 ); assert_eq!( @@ -1647,8 +1710,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[1].state ); assert!( - msg.states[2].cn0.almost_eq(3.76267852783203125e+01), - "incorrect value for states[2].cn0, expected 3.76267852783203125e+01, is {:e}", + msg.states[2].cn0.almost_eq(3.74460372924804688e+01), + "incorrect value for states[2].cn0, expected 3.74460372924804688e+01, is {:e}", msg.states[2].cn0 ); assert_eq!( @@ -1672,8 +1735,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[2].state ); assert!( - msg.states[3].cn0.almost_eq(3.90207290649414062e+01), - "incorrect value for states[3].cn0, expected 3.90207290649414062e+01, is {:e}", + msg.states[3].cn0.almost_eq(3.87284965515136719e+01), + "incorrect value for states[3].cn0, expected 3.87284965515136719e+01, is {:e}", msg.states[3].cn0 ); assert_eq!( @@ -1697,8 +1760,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[3].state ); assert!( - msg.states[4].cn0.almost_eq(4.20329055786132812e+01), - "incorrect value for states[4].cn0, expected 4.20329055786132812e+01, is {:e}", + msg.states[4].cn0.almost_eq(4.19832191467285156e+01), + "incorrect value for states[4].cn0, expected 4.19832191467285156e+01, is {:e}", msg.states[4].cn0 ); assert_eq!( @@ -1722,8 +1785,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[4].state ); assert!( - msg.states[5].cn0.almost_eq(3.74354667663574219e+01), - "incorrect value for states[5].cn0, expected 3.74354667663574219e+01, is {:e}", + msg.states[5].cn0.almost_eq(3.74644851684570312e+01), + "incorrect value for states[5].cn0, expected 3.74644851684570312e+01, is {:e}", msg.states[5].cn0 ); assert_eq!( @@ -1747,8 +1810,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[5].state ); assert!( - msg.states[6].cn0.almost_eq(3.84229621887207031e+01), - "incorrect value for states[6].cn0, expected 3.84229621887207031e+01, is {:e}", + msg.states[6].cn0.almost_eq(3.84430007934570312e+01), + "incorrect value for states[6].cn0, expected 3.84430007934570312e+01, is {:e}", msg.states[6].cn0 ); assert_eq!( @@ -1772,8 +1835,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[6].state ); assert!( - msg.states[7].cn0.almost_eq(3.89152030944824219e+01), - "incorrect value for states[7].cn0, expected 3.89152030944824219e+01, is {:e}", + msg.states[7].cn0.almost_eq(3.90342330932617188e+01), + "incorrect value for states[7].cn0, expected 3.90342330932617188e+01, is {:e}", msg.states[7].cn0 ); assert_eq!( @@ -1797,9 +1860,9 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[7].state ); assert!( - msg.states[8].cn0.almost_eq(4.26225929260253906e+01), - "incorrect value for states[8].cn0, expected 4.26225929260253906e+01, is {:e}", - msg.states[8].cn0 + msg.states[8].cn0.almost_eq(4.28994483947753906e+01), + "incorrect value for states[8].cn0, expected 4.28994483947753906e+01, is {:e}", + msg.states[8].cn0 ); assert_eq!( msg.states[8].sid.code, 0, @@ -1870,27 +1933,24 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { } _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); } { - let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 38.994117736816406, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 34.889801025390625, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.44603729248047, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.72849655151367, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 41.983219146728516, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.46448516845703, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.44300079345703, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.03423309326172, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.89944839477539, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 7956, "length": 99, "preamble": 85, "payload": "AcoAAAD6+RtCAcsAAAAojwtCAdAAAAC+yBVCAdQAAAD76RpCAdkAAADR7idCAdoAAACi2xVCAdwAAACixRlCAd4AAAAOIxxCAeEAAAAJmStCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + let mut payload = Cursor::new(vec![ + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 123, 209, 27, 66, 1, 203, 0, 0, 0, 214, 64, + 15, 66, 1, 208, 0, 0, 0, 56, 55, 22, 66, 1, 212, 0, 0, 0, 91, 142, 27, 66, 1, 217, 0, + 0, 0, 253, 154, 41, 66, 1, 218, 0, 0, 0, 128, 142, 22, 66, 1, 220, 0, 0, 0, 17, 174, + 23, 66, 1, 222, 0, 0, 0, 155, 2, 29, 66, 1, 225, 0, 0, 0, 162, 100, 42, 66, 0, 0, 0, 0, + 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 233, 71, + ]); + // Test the round trip payload parsing let sbp_msg = { - // JSON to SBP message from payload - let mut iter = json2sbp_iter_msg(json_input); - let from_payload = iter - .next() - .expect("no message found") - .expect("failed to parse message"); - - // JSON to SBP message from fields - let mut iter = iter_messages_from_fields(json_input); - let from_fields = iter - .next() + let mut msgs = iter_messages(&mut payload); + msgs.next() .expect("no message found") - .expect("failed to parse message"); - - assert_eq!(from_fields, from_payload); - from_fields + .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { @@ -1906,8 +1966,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert!( - msg.states[0].cn0.almost_eq(3.89941177368164062e+01), - "incorrect value for states[0].cn0, expected 3.89941177368164062e+01, is {:e}", + msg.states[0].cn0.almost_eq(3.89545707702636719e+01), + "incorrect value for states[0].cn0, expected 3.89545707702636719e+01, is {:e}", msg.states[0].cn0 ); assert_eq!( @@ -1931,8 +1991,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[0].state ); assert!( - msg.states[1].cn0.almost_eq(3.48898010253906250e+01), - "incorrect value for states[1].cn0, expected 3.48898010253906250e+01, is {:e}", + msg.states[1].cn0.almost_eq(3.58133163452148438e+01), + "incorrect value for states[1].cn0, expected 3.58133163452148438e+01, is {:e}", msg.states[1].cn0 ); assert_eq!( @@ -1956,8 +2016,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[1].state ); assert!( - msg.states[2].cn0.almost_eq(3.74460372924804688e+01), - "incorrect value for states[2].cn0, expected 3.74460372924804688e+01, is {:e}", + msg.states[2].cn0.almost_eq(3.75539245605468750e+01), + "incorrect value for states[2].cn0, expected 3.75539245605468750e+01, is {:e}", msg.states[2].cn0 ); assert_eq!( @@ -1981,8 +2041,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[2].state ); assert!( - msg.states[3].cn0.almost_eq(3.87284965515136719e+01), - "incorrect value for states[3].cn0, expected 3.87284965515136719e+01, is {:e}", + msg.states[3].cn0.almost_eq(3.88890190124511719e+01), + "incorrect value for states[3].cn0, expected 3.88890190124511719e+01, is {:e}", msg.states[3].cn0 ); assert_eq!( @@ -2006,8 +2066,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[3].state ); assert!( - msg.states[4].cn0.almost_eq(4.19832191467285156e+01), - "incorrect value for states[4].cn0, expected 4.19832191467285156e+01, is {:e}", + msg.states[4].cn0.almost_eq(4.24013557434082031e+01), + "incorrect value for states[4].cn0, expected 4.24013557434082031e+01, is {:e}", msg.states[4].cn0 ); assert_eq!( @@ -2031,8 +2091,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[4].state ); assert!( - msg.states[5].cn0.almost_eq(3.74644851684570312e+01), - "incorrect value for states[5].cn0, expected 3.74644851684570312e+01, is {:e}", + msg.states[5].cn0.almost_eq(3.76391601562500000e+01), + "incorrect value for states[5].cn0, expected 3.76391601562500000e+01, is {:e}", msg.states[5].cn0 ); assert_eq!( @@ -2056,8 +2116,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[5].state ); assert!( - msg.states[6].cn0.almost_eq(3.84430007934570312e+01), - "incorrect value for states[6].cn0, expected 3.84430007934570312e+01, is {:e}", + msg.states[6].cn0.almost_eq(3.79199867248535156e+01), + "incorrect value for states[6].cn0, expected 3.79199867248535156e+01, is {:e}", msg.states[6].cn0 ); assert_eq!( @@ -2081,8 +2141,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[6].state ); assert!( - msg.states[7].cn0.almost_eq(3.90342330932617188e+01), - "incorrect value for states[7].cn0, expected 3.90342330932617188e+01, is {:e}", + msg.states[7].cn0.almost_eq(3.92525444030761719e+01), + "incorrect value for states[7].cn0, expected 3.92525444030761719e+01, is {:e}", msg.states[7].cn0 ); assert_eq!( @@ -2106,8 +2166,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[7].state ); assert!( - msg.states[8].cn0.almost_eq(4.28994483947753906e+01), - "incorrect value for states[8].cn0, expected 4.28994483947753906e+01, is {:e}", + msg.states[8].cn0.almost_eq(4.25982742309570312e+01), + "incorrect value for states[8].cn0, expected 4.25982742309570312e+01, is {:e}", msg.states[8].cn0 ); assert_eq!( @@ -2179,27 +2239,24 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { } _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); } { - let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 38.95457077026367, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 35.813316345214844, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.553924560546875, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.88901901245117, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.4013557434082, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.63916015625, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 37.919986724853516, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.25254440307617, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.59827423095703, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 18409, "length": 99, "preamble": 85, "payload": "AcoAAAB70RtCAcsAAADWQA9CAdAAAAA4NxZCAdQAAABbjhtCAdkAAAD9milCAdoAAACAjhZCAdwAAAARrhdCAd4AAACbAh1CAeEAAACiZCpCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + let mut payload = Cursor::new(vec![ + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 120, 122, 29, 66, 1, 203, 0, 0, 0, 66, 22, + 18, 66, 1, 208, 0, 0, 0, 153, 163, 24, 66, 1, 212, 0, 0, 0, 178, 204, 28, 66, 1, 217, + 0, 0, 0, 220, 59, 38, 66, 1, 218, 0, 0, 0, 161, 27, 20, 66, 1, 220, 0, 0, 0, 125, 107, + 24, 66, 1, 222, 0, 0, 0, 242, 46, 28, 66, 1, 225, 0, 0, 0, 231, 130, 41, 66, 0, 0, 0, + 0, 0, 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 73, 193, + ]); + // Test the round trip payload parsing let sbp_msg = { - // JSON to SBP message from payload - let mut iter = json2sbp_iter_msg(json_input); - let from_payload = iter - .next() - .expect("no message found") - .expect("failed to parse message"); - - // JSON to SBP message from fields - let mut iter = iter_messages_from_fields(json_input); - let from_fields = iter - .next() + let mut msgs = iter_messages(&mut payload); + msgs.next() .expect("no message found") - .expect("failed to parse message"); - - assert_eq!(from_fields, from_payload); - from_fields + .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { @@ -2215,8 +2272,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert!( - msg.states[0].cn0.almost_eq(3.89545707702636719e+01), - "incorrect value for states[0].cn0, expected 3.89545707702636719e+01, is {:e}", + msg.states[0].cn0.almost_eq(3.93695983886718750e+01), + "incorrect value for states[0].cn0, expected 3.93695983886718750e+01, is {:e}", msg.states[0].cn0 ); assert_eq!( @@ -2240,8 +2297,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[0].state ); assert!( - msg.states[1].cn0.almost_eq(3.58133163452148438e+01), - "incorrect value for states[1].cn0, expected 3.58133163452148438e+01, is {:e}", + msg.states[1].cn0.almost_eq(3.65217361450195312e+01), + "incorrect value for states[1].cn0, expected 3.65217361450195312e+01, is {:e}", msg.states[1].cn0 ); assert_eq!( @@ -2265,8 +2322,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[1].state ); assert!( - msg.states[2].cn0.almost_eq(3.75539245605468750e+01), - "incorrect value for states[2].cn0, expected 3.75539245605468750e+01, is {:e}", + msg.states[2].cn0.almost_eq(3.81597633361816406e+01), + "incorrect value for states[2].cn0, expected 3.81597633361816406e+01, is {:e}", msg.states[2].cn0 ); assert_eq!( @@ -2290,8 +2347,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[2].state ); assert!( - msg.states[3].cn0.almost_eq(3.88890190124511719e+01), - "incorrect value for states[3].cn0, expected 3.88890190124511719e+01, is {:e}", + msg.states[3].cn0.almost_eq(3.91998977661132812e+01), + "incorrect value for states[3].cn0, expected 3.91998977661132812e+01, is {:e}", msg.states[3].cn0 ); assert_eq!( @@ -2315,8 +2372,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[3].state ); assert!( - msg.states[4].cn0.almost_eq(4.24013557434082031e+01), - "incorrect value for states[4].cn0, expected 4.24013557434082031e+01, is {:e}", + msg.states[4].cn0.almost_eq(4.15584564208984375e+01), + "incorrect value for states[4].cn0, expected 4.15584564208984375e+01, is {:e}", msg.states[4].cn0 ); assert_eq!( @@ -2340,8 +2397,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[4].state ); assert!( - msg.states[5].cn0.almost_eq(3.76391601562500000e+01), - "incorrect value for states[5].cn0, expected 3.76391601562500000e+01, is {:e}", + msg.states[5].cn0.almost_eq(3.70269813537597656e+01), + "incorrect value for states[5].cn0, expected 3.70269813537597656e+01, is {:e}", msg.states[5].cn0 ); assert_eq!( @@ -2365,8 +2422,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[5].state ); assert!( - msg.states[6].cn0.almost_eq(3.79199867248535156e+01), - "incorrect value for states[6].cn0, expected 3.79199867248535156e+01, is {:e}", + msg.states[6].cn0.almost_eq(3.81049690246582031e+01), + "incorrect value for states[6].cn0, expected 3.81049690246582031e+01, is {:e}", msg.states[6].cn0 ); assert_eq!( @@ -2390,8 +2447,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[6].state ); assert!( - msg.states[7].cn0.almost_eq(3.92525444030761719e+01), - "incorrect value for states[7].cn0, expected 3.92525444030761719e+01, is {:e}", + msg.states[7].cn0.almost_eq(3.90458450317382812e+01), + "incorrect value for states[7].cn0, expected 3.90458450317382812e+01, is {:e}", msg.states[7].cn0 ); assert_eq!( @@ -2415,8 +2472,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[7].state ); assert!( - msg.states[8].cn0.almost_eq(4.25982742309570312e+01), - "incorrect value for states[8].cn0, expected 4.25982742309570312e+01, is {:e}", + msg.states[8].cn0.almost_eq(4.23778343200683594e+01), + "incorrect value for states[8].cn0, expected 4.23778343200683594e+01, is {:e}", msg.states[8].cn0 ); assert_eq!( @@ -2488,27 +2545,24 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { } _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); } { - let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.369598388671875, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.52173614501953, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 38.15976333618164, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 39.19989776611328, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 41.55845642089844, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.026981353759766, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.1049690246582, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.04584503173828, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.37783432006836, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 49481, "length": 99, "preamble": 85, "payload": "AcoAAAB4eh1CAcsAAABCFhJCAdAAAACZoxhCAdQAAACyzBxCAdkAAADcOyZCAdoAAAChGxRCAdwAAAB9axhCAd4AAADyLhxCAeEAAADngilCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + let mut payload = Cursor::new(vec![ + 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 103, 208, 30, 66, 1, 203, 0, 0, 0, 117, 24, + 18, 66, 1, 208, 0, 0, 0, 200, 173, 20, 66, 1, 212, 0, 0, 0, 137, 68, 27, 66, 1, 217, 0, + 0, 0, 243, 51, 40, 66, 1, 218, 0, 0, 0, 225, 58, 23, 66, 1, 220, 0, 0, 0, 132, 221, 22, + 66, 1, 222, 0, 0, 0, 157, 29, 26, 66, 1, 225, 0, 0, 0, 133, 21, 41, 66, 0, 0, 0, 0, 0, + 0, 0, 128, 191, 0, 0, 0, 0, 0, 0, 0, 128, 191, 126, 47, + ]); + // Test the round trip payload parsing let sbp_msg = { - // JSON to SBP message from payload - let mut iter = json2sbp_iter_msg(json_input); - let from_payload = iter - .next() - .expect("no message found") - .expect("failed to parse message"); - - // JSON to SBP message from fields - let mut iter = iter_messages_from_fields(json_input); - let from_fields = iter - .next() + let mut msgs = iter_messages(&mut payload); + msgs.next() .expect("no message found") - .expect("failed to parse message"); - - assert_eq!(from_fields, from_payload); - from_fields + .expect("failed to parse message") }; match &sbp_msg { sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { @@ -2524,8 +2578,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { "incorrect sender id, expected 0xd7f6, is {sender_id}" ); assert!( - msg.states[0].cn0.almost_eq(3.93695983886718750e+01), - "incorrect value for states[0].cn0, expected 3.93695983886718750e+01, is {:e}", + msg.states[0].cn0.almost_eq(3.97035179138183594e+01), + "incorrect value for states[0].cn0, expected 3.97035179138183594e+01, is {:e}", msg.states[0].cn0 ); assert_eq!( @@ -2549,8 +2603,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[0].state ); assert!( - msg.states[1].cn0.almost_eq(3.65217361450195312e+01), - "incorrect value for states[1].cn0, expected 3.65217361450195312e+01, is {:e}", + msg.states[1].cn0.almost_eq(3.65238838195800781e+01), + "incorrect value for states[1].cn0, expected 3.65238838195800781e+01, is {:e}", msg.states[1].cn0 ); assert_eq!( @@ -2574,8 +2628,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[1].state ); assert!( - msg.states[2].cn0.almost_eq(3.81597633361816406e+01), - "incorrect value for states[2].cn0, expected 3.81597633361816406e+01, is {:e}", + msg.states[2].cn0.almost_eq(3.71697082519531250e+01), + "incorrect value for states[2].cn0, expected 3.71697082519531250e+01, is {:e}", msg.states[2].cn0 ); assert_eq!( @@ -2599,8 +2653,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[2].state ); assert!( - msg.states[3].cn0.almost_eq(3.91998977661132812e+01), - "incorrect value for states[3].cn0, expected 3.91998977661132812e+01, is {:e}", + msg.states[3].cn0.almost_eq(3.88169288635253906e+01), + "incorrect value for states[3].cn0, expected 3.88169288635253906e+01, is {:e}", msg.states[3].cn0 ); assert_eq!( @@ -2624,8 +2678,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[3].state ); assert!( - msg.states[4].cn0.almost_eq(4.15584564208984375e+01), - "incorrect value for states[4].cn0, expected 4.15584564208984375e+01, is {:e}", + msg.states[4].cn0.almost_eq(4.20507316589355469e+01), + "incorrect value for states[4].cn0, expected 4.20507316589355469e+01, is {:e}", msg.states[4].cn0 ); assert_eq!( @@ -2649,8 +2703,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[4].state ); assert!( - msg.states[5].cn0.almost_eq(3.70269813537597656e+01), - "incorrect value for states[5].cn0, expected 3.70269813537597656e+01, is {:e}", + msg.states[5].cn0.almost_eq(3.78074989318847656e+01), + "incorrect value for states[5].cn0, expected 3.78074989318847656e+01, is {:e}", msg.states[5].cn0 ); assert_eq!( @@ -2674,8 +2728,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[5].state ); assert!( - msg.states[6].cn0.almost_eq(3.81049690246582031e+01), - "incorrect value for states[6].cn0, expected 3.81049690246582031e+01, is {:e}", + msg.states[6].cn0.almost_eq(3.77163238525390625e+01), + "incorrect value for states[6].cn0, expected 3.77163238525390625e+01, is {:e}", msg.states[6].cn0 ); assert_eq!( @@ -2699,8 +2753,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[6].state ); assert!( - msg.states[7].cn0.almost_eq(3.90458450317382812e+01), - "incorrect value for states[7].cn0, expected 3.90458450317382812e+01, is {:e}", + msg.states[7].cn0.almost_eq(3.85289192199707031e+01), + "incorrect value for states[7].cn0, expected 3.85289192199707031e+01, is {:e}", msg.states[7].cn0 ); assert_eq!( @@ -2724,8 +2778,8 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { msg.states[7].state ); assert!( - msg.states[8].cn0.almost_eq(4.23778343200683594e+01), - "incorrect value for states[8].cn0, expected 4.23778343200683594e+01, is {:e}", + msg.states[8].cn0.almost_eq(4.22710151672363281e+01), + "incorrect value for states[8].cn0, expected 4.22710151672363281e+01, is {:e}", msg.states[8].cn0 ); assert_eq!( @@ -2797,9 +2851,23 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { } _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { { - let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.70351791381836, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.52388381958008, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.169708251953125, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.81692886352539, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.05073165893555, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.807498931884766, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 37.71632385253906, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 38.5289192199707, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.27101516723633, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 12158, "length": 99, "preamble": 85, "payload": "AcoAAABn0B5CAcsAAAB1GBJCAdAAAADIrRRCAdQAAACJRBtCAdkAAADzMyhCAdoAAADhOhdCAdwAAACE3RZCAd4AAACdHRpCAeEAAACFFSlCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + let json_input = r#"{"crc":28557,"length":252,"msg_type":65,"payload":"dbgDZiZqjI0ZBFrD9mxLUol/LaMgLrtdmTzJkxcdBdC1HttF/ogDeSFikNeFtg44qU3aPvJUq/mYiYOCwRUqRP3j2OMYGtKzEw/j/3pLu8jZMNp6u+6Ole43+9SAoMJocf+NPitF9Sdk5mw490SVj4ll6UYxpSZu2uZQ1cSzi4APssSrCNRhwlPpT2M3Wh+0BRlpuhbgUG8IMGqmBDCcMVYTjpJbfHNAHOZzsr6DEPJpO7ZxwLQws6YfrNNN5IwxgE3wwobCKToSNYE3W0iGXCHgnTi6NuCuUlSUvuw2PkM01zn+EIUkrtuskRHAs29hzzjQhrQRK+L/toxx","preamble":85,"sender":33079,"states":[{"sid":{"sat":117,"code":184},"fcn":3,"cn0":102},{"sid":{"sat":38,"code":106},"fcn":140,"cn0":141},{"sid":{"sat":25,"code":4},"fcn":90,"cn0":195},{"sid":{"sat":246,"code":108},"fcn":75,"cn0":82},{"sid":{"sat":137,"code":127},"fcn":45,"cn0":163},{"sid":{"sat":32,"code":46},"fcn":187,"cn0":93},{"sid":{"sat":153,"code":60},"fcn":201,"cn0":147},{"sid":{"sat":23,"code":29},"fcn":5,"cn0":208},{"sid":{"sat":181,"code":30},"fcn":219,"cn0":69},{"sid":{"sat":254,"code":136},"fcn":3,"cn0":121},{"sid":{"sat":33,"code":98},"fcn":144,"cn0":215},{"sid":{"sat":133,"code":182},"fcn":14,"cn0":56},{"sid":{"sat":169,"code":77},"fcn":218,"cn0":62},{"sid":{"sat":242,"code":84},"fcn":171,"cn0":249},{"sid":{"sat":152,"code":137},"fcn":131,"cn0":130},{"sid":{"sat":193,"code":21},"fcn":42,"cn0":68},{"sid":{"sat":253,"code":227},"fcn":216,"cn0":227},{"sid":{"sat":24,"code":26},"fcn":210,"cn0":179},{"sid":{"sat":19,"code":15},"fcn":227,"cn0":255},{"sid":{"sat":122,"code":75},"fcn":187,"cn0":200},{"sid":{"sat":217,"code":48},"fcn":218,"cn0":122},{"sid":{"sat":187,"code":238},"fcn":142,"cn0":149},{"sid":{"sat":238,"code":55},"fcn":251,"cn0":212},{"sid":{"sat":128,"code":160},"fcn":194,"cn0":104},{"sid":{"sat":113,"code":255},"fcn":141,"cn0":62},{"sid":{"sat":43,"code":69},"fcn":245,"cn0":39},{"sid":{"sat":100,"code":230},"fcn":108,"cn0":56},{"sid":{"sat":247,"code":68},"fcn":149,"cn0":143},{"sid":{"sat":137,"code":101},"fcn":233,"cn0":70},{"sid":{"sat":49,"code":165},"fcn":38,"cn0":110},{"sid":{"sat":218,"code":230},"fcn":80,"cn0":213},{"sid":{"sat":196,"code":179},"fcn":139,"cn0":128},{"sid":{"sat":15,"code":178},"fcn":196,"cn0":171},{"sid":{"sat":8,"code":212},"fcn":97,"cn0":194},{"sid":{"sat":83,"code":233},"fcn":79,"cn0":99},{"sid":{"sat":55,"code":90},"fcn":31,"cn0":180},{"sid":{"sat":5,"code":25},"fcn":105,"cn0":186},{"sid":{"sat":22,"code":224},"fcn":80,"cn0":111},{"sid":{"sat":8,"code":48},"fcn":106,"cn0":166},{"sid":{"sat":4,"code":48},"fcn":156,"cn0":49},{"sid":{"sat":86,"code":19},"fcn":142,"cn0":146},{"sid":{"sat":91,"code":124},"fcn":115,"cn0":64},{"sid":{"sat":28,"code":230},"fcn":115,"cn0":178},{"sid":{"sat":190,"code":131},"fcn":16,"cn0":242},{"sid":{"sat":105,"code":59},"fcn":182,"cn0":113},{"sid":{"sat":192,"code":180},"fcn":48,"cn0":179},{"sid":{"sat":166,"code":31},"fcn":172,"cn0":211},{"sid":{"sat":77,"code":228},"fcn":140,"cn0":49},{"sid":{"sat":128,"code":77},"fcn":240,"cn0":194},{"sid":{"sat":134,"code":194},"fcn":41,"cn0":58},{"sid":{"sat":18,"code":53},"fcn":129,"cn0":55},{"sid":{"sat":91,"code":72},"fcn":134,"cn0":92},{"sid":{"sat":33,"code":224},"fcn":157,"cn0":56},{"sid":{"sat":186,"code":54},"fcn":224,"cn0":174},{"sid":{"sat":82,"code":84},"fcn":148,"cn0":190},{"sid":{"sat":236,"code":54},"fcn":62,"cn0":67},{"sid":{"sat":52,"code":215},"fcn":57,"cn0":254},{"sid":{"sat":16,"code":133},"fcn":36,"cn0":174},{"sid":{"sat":219,"code":172},"fcn":145,"cn0":17},{"sid":{"sat":192,"code":179},"fcn":111,"cn0":97},{"sid":{"sat":207,"code":56},"fcn":208,"cn0":134},{"sid":{"sat":180,"code":17},"fcn":43,"cn0":226},{"sid":{"sat":255,"code":182},"fcn":140,"cn0":113}]}"#.as_bytes(); let sbp_msg = { // JSON to SBP message from payload @@ -2820,306 +2888,4163 @@ fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state() { from_fields }; match &sbp_msg { - sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + sbp::messages::Sbp::MsgTrackingState(msg) => { let msg_type = msg.message_type().unwrap(); assert_eq!( - msg_type, 0x13, - "Incorrect message type, expected 0x13, is {}", + msg_type, 0x41, + "Incorrect message type, expected 0x41, is {}", msg_type ); let sender_id = msg.sender_id().unwrap(); assert_eq!( - sender_id, 0xd7f6, - "incorrect sender id, expected 0xd7f6, is {sender_id}" + sender_id, 0x8137, + "incorrect sender id, expected 0x8137, is {sender_id}" ); - assert!( - msg.states[0].cn0.almost_eq(3.97035179138183594e+01), - "incorrect value for states[0].cn0, expected 3.97035179138183594e+01, is {:e}", + assert_eq!( + msg.states[0].cn0, 102, + "incorrect value for states[0].cn0, expected 102, is {}", msg.states[0].cn0 ); assert_eq!( - msg.states[0].sid.code, 0, - "incorrect value for states[0].sid.code, expected 0, is {}", - msg.states[0].sid.code + msg.states[0].fcn, 3, + "incorrect value for states[0].fcn, expected 3, is {}", + msg.states[0].fcn ); assert_eq!( - msg.states[0].sid.reserved, 0, - "incorrect value for states[0].sid.reserved, expected 0, is {}", - msg.states[0].sid.reserved + msg.states[0].sid.code, 184, + "incorrect value for states[0].sid.code, expected 184, is {}", + msg.states[0].sid.code ); assert_eq!( - msg.states[0].sid.sat, 202, - "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat, 117, + "incorrect value for states[0].sid.sat, expected 117, is {}", msg.states[0].sid.sat ); assert_eq!( - msg.states[0].state, 1, - "incorrect value for states[0].state, expected 1, is {}", - msg.states[0].state - ); - assert!( - msg.states[1].cn0.almost_eq(3.65238838195800781e+01), - "incorrect value for states[1].cn0, expected 3.65238838195800781e+01, is {:e}", + msg.states[1].cn0, 141, + "incorrect value for states[1].cn0, expected 141, is {}", msg.states[1].cn0 ); assert_eq!( - msg.states[1].sid.code, 0, - "incorrect value for states[1].sid.code, expected 0, is {}", - msg.states[1].sid.code + msg.states[1].fcn, 140, + "incorrect value for states[1].fcn, expected 140, is {}", + msg.states[1].fcn ); assert_eq!( - msg.states[1].sid.reserved, 0, - "incorrect value for states[1].sid.reserved, expected 0, is {}", - msg.states[1].sid.reserved + msg.states[1].sid.code, 106, + "incorrect value for states[1].sid.code, expected 106, is {}", + msg.states[1].sid.code ); assert_eq!( - msg.states[1].sid.sat, 203, - "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat, 38, + "incorrect value for states[1].sid.sat, expected 38, is {}", msg.states[1].sid.sat ); assert_eq!( - msg.states[1].state, 1, - "incorrect value for states[1].state, expected 1, is {}", - msg.states[1].state - ); - assert!( - msg.states[2].cn0.almost_eq(3.71697082519531250e+01), - "incorrect value for states[2].cn0, expected 3.71697082519531250e+01, is {:e}", + msg.states[2].cn0, 195, + "incorrect value for states[2].cn0, expected 195, is {}", msg.states[2].cn0 ); assert_eq!( - msg.states[2].sid.code, 0, - "incorrect value for states[2].sid.code, expected 0, is {}", - msg.states[2].sid.code + msg.states[2].fcn, 90, + "incorrect value for states[2].fcn, expected 90, is {}", + msg.states[2].fcn ); assert_eq!( - msg.states[2].sid.reserved, 0, - "incorrect value for states[2].sid.reserved, expected 0, is {}", - msg.states[2].sid.reserved + msg.states[2].sid.code, 4, + "incorrect value for states[2].sid.code, expected 4, is {}", + msg.states[2].sid.code ); assert_eq!( - msg.states[2].sid.sat, 208, - "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat, 25, + "incorrect value for states[2].sid.sat, expected 25, is {}", msg.states[2].sid.sat ); assert_eq!( - msg.states[2].state, 1, - "incorrect value for states[2].state, expected 1, is {}", - msg.states[2].state - ); - assert!( - msg.states[3].cn0.almost_eq(3.88169288635253906e+01), - "incorrect value for states[3].cn0, expected 3.88169288635253906e+01, is {:e}", + msg.states[3].cn0, 82, + "incorrect value for states[3].cn0, expected 82, is {}", msg.states[3].cn0 ); assert_eq!( - msg.states[3].sid.code, 0, - "incorrect value for states[3].sid.code, expected 0, is {}", - msg.states[3].sid.code + msg.states[3].fcn, 75, + "incorrect value for states[3].fcn, expected 75, is {}", + msg.states[3].fcn ); assert_eq!( - msg.states[3].sid.reserved, 0, - "incorrect value for states[3].sid.reserved, expected 0, is {}", - msg.states[3].sid.reserved + msg.states[3].sid.code, 108, + "incorrect value for states[3].sid.code, expected 108, is {}", + msg.states[3].sid.code ); assert_eq!( - msg.states[3].sid.sat, 212, - "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat, 246, + "incorrect value for states[3].sid.sat, expected 246, is {}", msg.states[3].sid.sat ); assert_eq!( - msg.states[3].state, 1, - "incorrect value for states[3].state, expected 1, is {}", - msg.states[3].state - ); - assert!( - msg.states[4].cn0.almost_eq(4.20507316589355469e+01), - "incorrect value for states[4].cn0, expected 4.20507316589355469e+01, is {:e}", + msg.states[4].cn0, 163, + "incorrect value for states[4].cn0, expected 163, is {}", msg.states[4].cn0 ); assert_eq!( - msg.states[4].sid.code, 0, - "incorrect value for states[4].sid.code, expected 0, is {}", - msg.states[4].sid.code + msg.states[4].fcn, 45, + "incorrect value for states[4].fcn, expected 45, is {}", + msg.states[4].fcn ); assert_eq!( - msg.states[4].sid.reserved, 0, - "incorrect value for states[4].sid.reserved, expected 0, is {}", - msg.states[4].sid.reserved + msg.states[4].sid.code, 127, + "incorrect value for states[4].sid.code, expected 127, is {}", + msg.states[4].sid.code ); assert_eq!( - msg.states[4].sid.sat, 217, - "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat, 137, + "incorrect value for states[4].sid.sat, expected 137, is {}", msg.states[4].sid.sat ); assert_eq!( - msg.states[4].state, 1, - "incorrect value for states[4].state, expected 1, is {}", - msg.states[4].state - ); - assert!( - msg.states[5].cn0.almost_eq(3.78074989318847656e+01), - "incorrect value for states[5].cn0, expected 3.78074989318847656e+01, is {:e}", + msg.states[5].cn0, 93, + "incorrect value for states[5].cn0, expected 93, is {}", msg.states[5].cn0 ); assert_eq!( - msg.states[5].sid.code, 0, - "incorrect value for states[5].sid.code, expected 0, is {}", - msg.states[5].sid.code + msg.states[5].fcn, 187, + "incorrect value for states[5].fcn, expected 187, is {}", + msg.states[5].fcn ); assert_eq!( - msg.states[5].sid.reserved, 0, - "incorrect value for states[5].sid.reserved, expected 0, is {}", - msg.states[5].sid.reserved + msg.states[5].sid.code, 46, + "incorrect value for states[5].sid.code, expected 46, is {}", + msg.states[5].sid.code ); assert_eq!( - msg.states[5].sid.sat, 218, - "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat, 32, + "incorrect value for states[5].sid.sat, expected 32, is {}", msg.states[5].sid.sat ); assert_eq!( - msg.states[5].state, 1, - "incorrect value for states[5].state, expected 1, is {}", - msg.states[5].state - ); - assert!( - msg.states[6].cn0.almost_eq(3.77163238525390625e+01), - "incorrect value for states[6].cn0, expected 3.77163238525390625e+01, is {:e}", + msg.states[6].cn0, 147, + "incorrect value for states[6].cn0, expected 147, is {}", msg.states[6].cn0 ); assert_eq!( - msg.states[6].sid.code, 0, - "incorrect value for states[6].sid.code, expected 0, is {}", - msg.states[6].sid.code + msg.states[6].fcn, 201, + "incorrect value for states[6].fcn, expected 201, is {}", + msg.states[6].fcn ); assert_eq!( - msg.states[6].sid.reserved, 0, - "incorrect value for states[6].sid.reserved, expected 0, is {}", - msg.states[6].sid.reserved + msg.states[6].sid.code, 60, + "incorrect value for states[6].sid.code, expected 60, is {}", + msg.states[6].sid.code ); assert_eq!( - msg.states[6].sid.sat, 220, - "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat, 153, + "incorrect value for states[6].sid.sat, expected 153, is {}", msg.states[6].sid.sat ); assert_eq!( - msg.states[6].state, 1, - "incorrect value for states[6].state, expected 1, is {}", - msg.states[6].state - ); - assert!( - msg.states[7].cn0.almost_eq(3.85289192199707031e+01), - "incorrect value for states[7].cn0, expected 3.85289192199707031e+01, is {:e}", + msg.states[7].cn0, 208, + "incorrect value for states[7].cn0, expected 208, is {}", msg.states[7].cn0 ); assert_eq!( - msg.states[7].sid.code, 0, - "incorrect value for states[7].sid.code, expected 0, is {}", - msg.states[7].sid.code + msg.states[7].fcn, 5, + "incorrect value for states[7].fcn, expected 5, is {}", + msg.states[7].fcn ); assert_eq!( - msg.states[7].sid.reserved, 0, - "incorrect value for states[7].sid.reserved, expected 0, is {}", - msg.states[7].sid.reserved + msg.states[7].sid.code, 29, + "incorrect value for states[7].sid.code, expected 29, is {}", + msg.states[7].sid.code ); assert_eq!( - msg.states[7].sid.sat, 222, - "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat, 23, + "incorrect value for states[7].sid.sat, expected 23, is {}", msg.states[7].sid.sat ); assert_eq!( - msg.states[7].state, 1, - "incorrect value for states[7].state, expected 1, is {}", - msg.states[7].state - ); - assert!( - msg.states[8].cn0.almost_eq(4.22710151672363281e+01), - "incorrect value for states[8].cn0, expected 4.22710151672363281e+01, is {:e}", + msg.states[8].cn0, 69, + "incorrect value for states[8].cn0, expected 69, is {}", msg.states[8].cn0 ); assert_eq!( - msg.states[8].sid.code, 0, - "incorrect value for states[8].sid.code, expected 0, is {}", - msg.states[8].sid.code + msg.states[8].fcn, 219, + "incorrect value for states[8].fcn, expected 219, is {}", + msg.states[8].fcn ); assert_eq!( - msg.states[8].sid.reserved, 0, - "incorrect value for states[8].sid.reserved, expected 0, is {}", - msg.states[8].sid.reserved + msg.states[8].sid.code, 30, + "incorrect value for states[8].sid.code, expected 30, is {}", + msg.states[8].sid.code ); assert_eq!( - msg.states[8].sid.sat, 225, - "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat, 181, + "incorrect value for states[8].sid.sat, expected 181, is {}", msg.states[8].sid.sat ); assert_eq!( - msg.states[8].state, 1, - "incorrect value for states[8].state, expected 1, is {}", - msg.states[8].state - ); - assert!( - msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), - "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0, 121, + "incorrect value for states[9].cn0, expected 121, is {}", msg.states[9].cn0 ); assert_eq!( - msg.states[9].sid.code, 0, - "incorrect value for states[9].sid.code, expected 0, is {}", - msg.states[9].sid.code + msg.states[9].fcn, 3, + "incorrect value for states[9].fcn, expected 3, is {}", + msg.states[9].fcn ); assert_eq!( - msg.states[9].sid.reserved, 0, - "incorrect value for states[9].sid.reserved, expected 0, is {}", - msg.states[9].sid.reserved + msg.states[9].sid.code, 136, + "incorrect value for states[9].sid.code, expected 136, is {}", + msg.states[9].sid.code ); assert_eq!( - msg.states[9].sid.sat, 0, - "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat, 254, + "incorrect value for states[9].sid.sat, expected 254, is {}", msg.states[9].sid.sat ); assert_eq!( - msg.states[9].state, 0, - "incorrect value for states[9].state, expected 0, is {}", - msg.states[9].state + msg.states[10].cn0, 215, + "incorrect value for states[10].cn0, expected 215, is {}", + msg.states[10].cn0 ); - assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); assert_eq!( - msg.states[10].sid.code, 0, - "incorrect value for states[10].sid.code, expected 0, is {}", - msg.states[10].sid.code + msg.states[10].fcn, 144, + "incorrect value for states[10].fcn, expected 144, is {}", + msg.states[10].fcn ); assert_eq!( - msg.states[10].sid.reserved, 0, - "incorrect value for states[10].sid.reserved, expected 0, is {}", - msg.states[10].sid.reserved + msg.states[10].sid.code, 98, + "incorrect value for states[10].sid.code, expected 98, is {}", + msg.states[10].sid.code ); assert_eq!( - msg.states[10].sid.sat, 0, - "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat, 33, + "incorrect value for states[10].sid.sat, expected 33, is {}", msg.states[10].sid.sat ); assert_eq!( - msg.states[10].state, 0, - "incorrect value for states[10].state, expected 0, is {}", - msg.states[10].state + msg.states[11].cn0, 56, + "incorrect value for states[11].cn0, expected 56, is {}", + msg.states[11].cn0 ); - } - _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), - }; - } -} - -/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON -/// -/// Assumes: -/// - [`self::test_auto_check_sbp_tracking_msg_tracking_state`] passes -/// -/// Asserts: -/// - SBP fields equates to that of the field -/// - Payload is identical -#[test] -#[cfg(feature = "json")] -fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_state() { + assert_eq!( + msg.states[11].fcn, 14, + "incorrect value for states[11].fcn, expected 14, is {}", + msg.states[11].fcn + ); + assert_eq!( + msg.states[11].sid.code, 182, + "incorrect value for states[11].sid.code, expected 182, is {}", + msg.states[11].sid.code + ); + assert_eq!( + msg.states[11].sid.sat, 133, + "incorrect value for states[11].sid.sat, expected 133, is {}", + msg.states[11].sid.sat + ); + assert_eq!( + msg.states[12].cn0, 62, + "incorrect value for states[12].cn0, expected 62, is {}", + msg.states[12].cn0 + ); + assert_eq!( + msg.states[12].fcn, 218, + "incorrect value for states[12].fcn, expected 218, is {}", + msg.states[12].fcn + ); + assert_eq!( + msg.states[12].sid.code, 77, + "incorrect value for states[12].sid.code, expected 77, is {}", + msg.states[12].sid.code + ); + assert_eq!( + msg.states[12].sid.sat, 169, + "incorrect value for states[12].sid.sat, expected 169, is {}", + msg.states[12].sid.sat + ); + assert_eq!( + msg.states[13].cn0, 249, + "incorrect value for states[13].cn0, expected 249, is {}", + msg.states[13].cn0 + ); + assert_eq!( + msg.states[13].fcn, 171, + "incorrect value for states[13].fcn, expected 171, is {}", + msg.states[13].fcn + ); + assert_eq!( + msg.states[13].sid.code, 84, + "incorrect value for states[13].sid.code, expected 84, is {}", + msg.states[13].sid.code + ); + assert_eq!( + msg.states[13].sid.sat, 242, + "incorrect value for states[13].sid.sat, expected 242, is {}", + msg.states[13].sid.sat + ); + assert_eq!( + msg.states[14].cn0, 130, + "incorrect value for states[14].cn0, expected 130, is {}", + msg.states[14].cn0 + ); + assert_eq!( + msg.states[14].fcn, 131, + "incorrect value for states[14].fcn, expected 131, is {}", + msg.states[14].fcn + ); + assert_eq!( + msg.states[14].sid.code, 137, + "incorrect value for states[14].sid.code, expected 137, is {}", + msg.states[14].sid.code + ); + assert_eq!( + msg.states[14].sid.sat, 152, + "incorrect value for states[14].sid.sat, expected 152, is {}", + msg.states[14].sid.sat + ); + assert_eq!( + msg.states[15].cn0, 68, + "incorrect value for states[15].cn0, expected 68, is {}", + msg.states[15].cn0 + ); + assert_eq!( + msg.states[15].fcn, 42, + "incorrect value for states[15].fcn, expected 42, is {}", + msg.states[15].fcn + ); + assert_eq!( + msg.states[15].sid.code, 21, + "incorrect value for states[15].sid.code, expected 21, is {}", + msg.states[15].sid.code + ); + assert_eq!( + msg.states[15].sid.sat, 193, + "incorrect value for states[15].sid.sat, expected 193, is {}", + msg.states[15].sid.sat + ); + assert_eq!( + msg.states[16].cn0, 227, + "incorrect value for states[16].cn0, expected 227, is {}", + msg.states[16].cn0 + ); + assert_eq!( + msg.states[16].fcn, 216, + "incorrect value for states[16].fcn, expected 216, is {}", + msg.states[16].fcn + ); + assert_eq!( + msg.states[16].sid.code, 227, + "incorrect value for states[16].sid.code, expected 227, is {}", + msg.states[16].sid.code + ); + assert_eq!( + msg.states[16].sid.sat, 253, + "incorrect value for states[16].sid.sat, expected 253, is {}", + msg.states[16].sid.sat + ); + assert_eq!( + msg.states[17].cn0, 179, + "incorrect value for states[17].cn0, expected 179, is {}", + msg.states[17].cn0 + ); + assert_eq!( + msg.states[17].fcn, 210, + "incorrect value for states[17].fcn, expected 210, is {}", + msg.states[17].fcn + ); + assert_eq!( + msg.states[17].sid.code, 26, + "incorrect value for states[17].sid.code, expected 26, is {}", + msg.states[17].sid.code + ); + assert_eq!( + msg.states[17].sid.sat, 24, + "incorrect value for states[17].sid.sat, expected 24, is {}", + msg.states[17].sid.sat + ); + assert_eq!( + msg.states[18].cn0, 255, + "incorrect value for states[18].cn0, expected 255, is {}", + msg.states[18].cn0 + ); + assert_eq!( + msg.states[18].fcn, 227, + "incorrect value for states[18].fcn, expected 227, is {}", + msg.states[18].fcn + ); + assert_eq!( + msg.states[18].sid.code, 15, + "incorrect value for states[18].sid.code, expected 15, is {}", + msg.states[18].sid.code + ); + assert_eq!( + msg.states[18].sid.sat, 19, + "incorrect value for states[18].sid.sat, expected 19, is {}", + msg.states[18].sid.sat + ); + assert_eq!( + msg.states[19].cn0, 200, + "incorrect value for states[19].cn0, expected 200, is {}", + msg.states[19].cn0 + ); + assert_eq!( + msg.states[19].fcn, 187, + "incorrect value for states[19].fcn, expected 187, is {}", + msg.states[19].fcn + ); + assert_eq!( + msg.states[19].sid.code, 75, + "incorrect value for states[19].sid.code, expected 75, is {}", + msg.states[19].sid.code + ); + assert_eq!( + msg.states[19].sid.sat, 122, + "incorrect value for states[19].sid.sat, expected 122, is {}", + msg.states[19].sid.sat + ); + assert_eq!( + msg.states[20].cn0, 122, + "incorrect value for states[20].cn0, expected 122, is {}", + msg.states[20].cn0 + ); + assert_eq!( + msg.states[20].fcn, 218, + "incorrect value for states[20].fcn, expected 218, is {}", + msg.states[20].fcn + ); + assert_eq!( + msg.states[20].sid.code, 48, + "incorrect value for states[20].sid.code, expected 48, is {}", + msg.states[20].sid.code + ); + assert_eq!( + msg.states[20].sid.sat, 217, + "incorrect value for states[20].sid.sat, expected 217, is {}", + msg.states[20].sid.sat + ); + assert_eq!( + msg.states[21].cn0, 149, + "incorrect value for states[21].cn0, expected 149, is {}", + msg.states[21].cn0 + ); + assert_eq!( + msg.states[21].fcn, 142, + "incorrect value for states[21].fcn, expected 142, is {}", + msg.states[21].fcn + ); + assert_eq!( + msg.states[21].sid.code, 238, + "incorrect value for states[21].sid.code, expected 238, is {}", + msg.states[21].sid.code + ); + assert_eq!( + msg.states[21].sid.sat, 187, + "incorrect value for states[21].sid.sat, expected 187, is {}", + msg.states[21].sid.sat + ); + assert_eq!( + msg.states[22].cn0, 212, + "incorrect value for states[22].cn0, expected 212, is {}", + msg.states[22].cn0 + ); + assert_eq!( + msg.states[22].fcn, 251, + "incorrect value for states[22].fcn, expected 251, is {}", + msg.states[22].fcn + ); + assert_eq!( + msg.states[22].sid.code, 55, + "incorrect value for states[22].sid.code, expected 55, is {}", + msg.states[22].sid.code + ); + assert_eq!( + msg.states[22].sid.sat, 238, + "incorrect value for states[22].sid.sat, expected 238, is {}", + msg.states[22].sid.sat + ); + assert_eq!( + msg.states[23].cn0, 104, + "incorrect value for states[23].cn0, expected 104, is {}", + msg.states[23].cn0 + ); + assert_eq!( + msg.states[23].fcn, 194, + "incorrect value for states[23].fcn, expected 194, is {}", + msg.states[23].fcn + ); + assert_eq!( + msg.states[23].sid.code, 160, + "incorrect value for states[23].sid.code, expected 160, is {}", + msg.states[23].sid.code + ); + assert_eq!( + msg.states[23].sid.sat, 128, + "incorrect value for states[23].sid.sat, expected 128, is {}", + msg.states[23].sid.sat + ); + assert_eq!( + msg.states[24].cn0, 62, + "incorrect value for states[24].cn0, expected 62, is {}", + msg.states[24].cn0 + ); + assert_eq!( + msg.states[24].fcn, 141, + "incorrect value for states[24].fcn, expected 141, is {}", + msg.states[24].fcn + ); + assert_eq!( + msg.states[24].sid.code, 255, + "incorrect value for states[24].sid.code, expected 255, is {}", + msg.states[24].sid.code + ); + assert_eq!( + msg.states[24].sid.sat, 113, + "incorrect value for states[24].sid.sat, expected 113, is {}", + msg.states[24].sid.sat + ); + assert_eq!( + msg.states[25].cn0, 39, + "incorrect value for states[25].cn0, expected 39, is {}", + msg.states[25].cn0 + ); + assert_eq!( + msg.states[25].fcn, 245, + "incorrect value for states[25].fcn, expected 245, is {}", + msg.states[25].fcn + ); + assert_eq!( + msg.states[25].sid.code, 69, + "incorrect value for states[25].sid.code, expected 69, is {}", + msg.states[25].sid.code + ); + assert_eq!( + msg.states[25].sid.sat, 43, + "incorrect value for states[25].sid.sat, expected 43, is {}", + msg.states[25].sid.sat + ); + assert_eq!( + msg.states[26].cn0, 56, + "incorrect value for states[26].cn0, expected 56, is {}", + msg.states[26].cn0 + ); + assert_eq!( + msg.states[26].fcn, 108, + "incorrect value for states[26].fcn, expected 108, is {}", + msg.states[26].fcn + ); + assert_eq!( + msg.states[26].sid.code, 230, + "incorrect value for states[26].sid.code, expected 230, is {}", + msg.states[26].sid.code + ); + assert_eq!( + msg.states[26].sid.sat, 100, + "incorrect value for states[26].sid.sat, expected 100, is {}", + msg.states[26].sid.sat + ); + assert_eq!( + msg.states[27].cn0, 143, + "incorrect value for states[27].cn0, expected 143, is {}", + msg.states[27].cn0 + ); + assert_eq!( + msg.states[27].fcn, 149, + "incorrect value for states[27].fcn, expected 149, is {}", + msg.states[27].fcn + ); + assert_eq!( + msg.states[27].sid.code, 68, + "incorrect value for states[27].sid.code, expected 68, is {}", + msg.states[27].sid.code + ); + assert_eq!( + msg.states[27].sid.sat, 247, + "incorrect value for states[27].sid.sat, expected 247, is {}", + msg.states[27].sid.sat + ); + assert_eq!( + msg.states[28].cn0, 70, + "incorrect value for states[28].cn0, expected 70, is {}", + msg.states[28].cn0 + ); + assert_eq!( + msg.states[28].fcn, 233, + "incorrect value for states[28].fcn, expected 233, is {}", + msg.states[28].fcn + ); + assert_eq!( + msg.states[28].sid.code, 101, + "incorrect value for states[28].sid.code, expected 101, is {}", + msg.states[28].sid.code + ); + assert_eq!( + msg.states[28].sid.sat, 137, + "incorrect value for states[28].sid.sat, expected 137, is {}", + msg.states[28].sid.sat + ); + assert_eq!( + msg.states[29].cn0, 110, + "incorrect value for states[29].cn0, expected 110, is {}", + msg.states[29].cn0 + ); + assert_eq!( + msg.states[29].fcn, 38, + "incorrect value for states[29].fcn, expected 38, is {}", + msg.states[29].fcn + ); + assert_eq!( + msg.states[29].sid.code, 165, + "incorrect value for states[29].sid.code, expected 165, is {}", + msg.states[29].sid.code + ); + assert_eq!( + msg.states[29].sid.sat, 49, + "incorrect value for states[29].sid.sat, expected 49, is {}", + msg.states[29].sid.sat + ); + assert_eq!( + msg.states[30].cn0, 213, + "incorrect value for states[30].cn0, expected 213, is {}", + msg.states[30].cn0 + ); + assert_eq!( + msg.states[30].fcn, 80, + "incorrect value for states[30].fcn, expected 80, is {}", + msg.states[30].fcn + ); + assert_eq!( + msg.states[30].sid.code, 230, + "incorrect value for states[30].sid.code, expected 230, is {}", + msg.states[30].sid.code + ); + assert_eq!( + msg.states[30].sid.sat, 218, + "incorrect value for states[30].sid.sat, expected 218, is {}", + msg.states[30].sid.sat + ); + assert_eq!( + msg.states[31].cn0, 128, + "incorrect value for states[31].cn0, expected 128, is {}", + msg.states[31].cn0 + ); + assert_eq!( + msg.states[31].fcn, 139, + "incorrect value for states[31].fcn, expected 139, is {}", + msg.states[31].fcn + ); + assert_eq!( + msg.states[31].sid.code, 179, + "incorrect value for states[31].sid.code, expected 179, is {}", + msg.states[31].sid.code + ); + assert_eq!( + msg.states[31].sid.sat, 196, + "incorrect value for states[31].sid.sat, expected 196, is {}", + msg.states[31].sid.sat + ); + assert_eq!( + msg.states[32].cn0, 171, + "incorrect value for states[32].cn0, expected 171, is {}", + msg.states[32].cn0 + ); + assert_eq!( + msg.states[32].fcn, 196, + "incorrect value for states[32].fcn, expected 196, is {}", + msg.states[32].fcn + ); + assert_eq!( + msg.states[32].sid.code, 178, + "incorrect value for states[32].sid.code, expected 178, is {}", + msg.states[32].sid.code + ); + assert_eq!( + msg.states[32].sid.sat, 15, + "incorrect value for states[32].sid.sat, expected 15, is {}", + msg.states[32].sid.sat + ); + assert_eq!( + msg.states[33].cn0, 194, + "incorrect value for states[33].cn0, expected 194, is {}", + msg.states[33].cn0 + ); + assert_eq!( + msg.states[33].fcn, 97, + "incorrect value for states[33].fcn, expected 97, is {}", + msg.states[33].fcn + ); + assert_eq!( + msg.states[33].sid.code, 212, + "incorrect value for states[33].sid.code, expected 212, is {}", + msg.states[33].sid.code + ); + assert_eq!( + msg.states[33].sid.sat, 8, + "incorrect value for states[33].sid.sat, expected 8, is {}", + msg.states[33].sid.sat + ); + assert_eq!( + msg.states[34].cn0, 99, + "incorrect value for states[34].cn0, expected 99, is {}", + msg.states[34].cn0 + ); + assert_eq!( + msg.states[34].fcn, 79, + "incorrect value for states[34].fcn, expected 79, is {}", + msg.states[34].fcn + ); + assert_eq!( + msg.states[34].sid.code, 233, + "incorrect value for states[34].sid.code, expected 233, is {}", + msg.states[34].sid.code + ); + assert_eq!( + msg.states[34].sid.sat, 83, + "incorrect value for states[34].sid.sat, expected 83, is {}", + msg.states[34].sid.sat + ); + assert_eq!( + msg.states[35].cn0, 180, + "incorrect value for states[35].cn0, expected 180, is {}", + msg.states[35].cn0 + ); + assert_eq!( + msg.states[35].fcn, 31, + "incorrect value for states[35].fcn, expected 31, is {}", + msg.states[35].fcn + ); + assert_eq!( + msg.states[35].sid.code, 90, + "incorrect value for states[35].sid.code, expected 90, is {}", + msg.states[35].sid.code + ); + assert_eq!( + msg.states[35].sid.sat, 55, + "incorrect value for states[35].sid.sat, expected 55, is {}", + msg.states[35].sid.sat + ); + assert_eq!( + msg.states[36].cn0, 186, + "incorrect value for states[36].cn0, expected 186, is {}", + msg.states[36].cn0 + ); + assert_eq!( + msg.states[36].fcn, 105, + "incorrect value for states[36].fcn, expected 105, is {}", + msg.states[36].fcn + ); + assert_eq!( + msg.states[36].sid.code, 25, + "incorrect value for states[36].sid.code, expected 25, is {}", + msg.states[36].sid.code + ); + assert_eq!( + msg.states[36].sid.sat, 5, + "incorrect value for states[36].sid.sat, expected 5, is {}", + msg.states[36].sid.sat + ); + assert_eq!( + msg.states[37].cn0, 111, + "incorrect value for states[37].cn0, expected 111, is {}", + msg.states[37].cn0 + ); + assert_eq!( + msg.states[37].fcn, 80, + "incorrect value for states[37].fcn, expected 80, is {}", + msg.states[37].fcn + ); + assert_eq!( + msg.states[37].sid.code, 224, + "incorrect value for states[37].sid.code, expected 224, is {}", + msg.states[37].sid.code + ); + assert_eq!( + msg.states[37].sid.sat, 22, + "incorrect value for states[37].sid.sat, expected 22, is {}", + msg.states[37].sid.sat + ); + assert_eq!( + msg.states[38].cn0, 166, + "incorrect value for states[38].cn0, expected 166, is {}", + msg.states[38].cn0 + ); + assert_eq!( + msg.states[38].fcn, 106, + "incorrect value for states[38].fcn, expected 106, is {}", + msg.states[38].fcn + ); + assert_eq!( + msg.states[38].sid.code, 48, + "incorrect value for states[38].sid.code, expected 48, is {}", + msg.states[38].sid.code + ); + assert_eq!( + msg.states[38].sid.sat, 8, + "incorrect value for states[38].sid.sat, expected 8, is {}", + msg.states[38].sid.sat + ); + assert_eq!( + msg.states[39].cn0, 49, + "incorrect value for states[39].cn0, expected 49, is {}", + msg.states[39].cn0 + ); + assert_eq!( + msg.states[39].fcn, 156, + "incorrect value for states[39].fcn, expected 156, is {}", + msg.states[39].fcn + ); + assert_eq!( + msg.states[39].sid.code, 48, + "incorrect value for states[39].sid.code, expected 48, is {}", + msg.states[39].sid.code + ); + assert_eq!( + msg.states[39].sid.sat, 4, + "incorrect value for states[39].sid.sat, expected 4, is {}", + msg.states[39].sid.sat + ); + assert_eq!( + msg.states[40].cn0, 146, + "incorrect value for states[40].cn0, expected 146, is {}", + msg.states[40].cn0 + ); + assert_eq!( + msg.states[40].fcn, 142, + "incorrect value for states[40].fcn, expected 142, is {}", + msg.states[40].fcn + ); + assert_eq!( + msg.states[40].sid.code, 19, + "incorrect value for states[40].sid.code, expected 19, is {}", + msg.states[40].sid.code + ); + assert_eq!( + msg.states[40].sid.sat, 86, + "incorrect value for states[40].sid.sat, expected 86, is {}", + msg.states[40].sid.sat + ); + assert_eq!( + msg.states[41].cn0, 64, + "incorrect value for states[41].cn0, expected 64, is {}", + msg.states[41].cn0 + ); + assert_eq!( + msg.states[41].fcn, 115, + "incorrect value for states[41].fcn, expected 115, is {}", + msg.states[41].fcn + ); + assert_eq!( + msg.states[41].sid.code, 124, + "incorrect value for states[41].sid.code, expected 124, is {}", + msg.states[41].sid.code + ); + assert_eq!( + msg.states[41].sid.sat, 91, + "incorrect value for states[41].sid.sat, expected 91, is {}", + msg.states[41].sid.sat + ); + assert_eq!( + msg.states[42].cn0, 178, + "incorrect value for states[42].cn0, expected 178, is {}", + msg.states[42].cn0 + ); + assert_eq!( + msg.states[42].fcn, 115, + "incorrect value for states[42].fcn, expected 115, is {}", + msg.states[42].fcn + ); + assert_eq!( + msg.states[42].sid.code, 230, + "incorrect value for states[42].sid.code, expected 230, is {}", + msg.states[42].sid.code + ); + assert_eq!( + msg.states[42].sid.sat, 28, + "incorrect value for states[42].sid.sat, expected 28, is {}", + msg.states[42].sid.sat + ); + assert_eq!( + msg.states[43].cn0, 242, + "incorrect value for states[43].cn0, expected 242, is {}", + msg.states[43].cn0 + ); + assert_eq!( + msg.states[43].fcn, 16, + "incorrect value for states[43].fcn, expected 16, is {}", + msg.states[43].fcn + ); + assert_eq!( + msg.states[43].sid.code, 131, + "incorrect value for states[43].sid.code, expected 131, is {}", + msg.states[43].sid.code + ); + assert_eq!( + msg.states[43].sid.sat, 190, + "incorrect value for states[43].sid.sat, expected 190, is {}", + msg.states[43].sid.sat + ); + assert_eq!( + msg.states[44].cn0, 113, + "incorrect value for states[44].cn0, expected 113, is {}", + msg.states[44].cn0 + ); + assert_eq!( + msg.states[44].fcn, 182, + "incorrect value for states[44].fcn, expected 182, is {}", + msg.states[44].fcn + ); + assert_eq!( + msg.states[44].sid.code, 59, + "incorrect value for states[44].sid.code, expected 59, is {}", + msg.states[44].sid.code + ); + assert_eq!( + msg.states[44].sid.sat, 105, + "incorrect value for states[44].sid.sat, expected 105, is {}", + msg.states[44].sid.sat + ); + assert_eq!( + msg.states[45].cn0, 179, + "incorrect value for states[45].cn0, expected 179, is {}", + msg.states[45].cn0 + ); + assert_eq!( + msg.states[45].fcn, 48, + "incorrect value for states[45].fcn, expected 48, is {}", + msg.states[45].fcn + ); + assert_eq!( + msg.states[45].sid.code, 180, + "incorrect value for states[45].sid.code, expected 180, is {}", + msg.states[45].sid.code + ); + assert_eq!( + msg.states[45].sid.sat, 192, + "incorrect value for states[45].sid.sat, expected 192, is {}", + msg.states[45].sid.sat + ); + assert_eq!( + msg.states[46].cn0, 211, + "incorrect value for states[46].cn0, expected 211, is {}", + msg.states[46].cn0 + ); + assert_eq!( + msg.states[46].fcn, 172, + "incorrect value for states[46].fcn, expected 172, is {}", + msg.states[46].fcn + ); + assert_eq!( + msg.states[46].sid.code, 31, + "incorrect value for states[46].sid.code, expected 31, is {}", + msg.states[46].sid.code + ); + assert_eq!( + msg.states[46].sid.sat, 166, + "incorrect value for states[46].sid.sat, expected 166, is {}", + msg.states[46].sid.sat + ); + assert_eq!( + msg.states[47].cn0, 49, + "incorrect value for states[47].cn0, expected 49, is {}", + msg.states[47].cn0 + ); + assert_eq!( + msg.states[47].fcn, 140, + "incorrect value for states[47].fcn, expected 140, is {}", + msg.states[47].fcn + ); + assert_eq!( + msg.states[47].sid.code, 228, + "incorrect value for states[47].sid.code, expected 228, is {}", + msg.states[47].sid.code + ); + assert_eq!( + msg.states[47].sid.sat, 77, + "incorrect value for states[47].sid.sat, expected 77, is {}", + msg.states[47].sid.sat + ); + assert_eq!( + msg.states[48].cn0, 194, + "incorrect value for states[48].cn0, expected 194, is {}", + msg.states[48].cn0 + ); + assert_eq!( + msg.states[48].fcn, 240, + "incorrect value for states[48].fcn, expected 240, is {}", + msg.states[48].fcn + ); + assert_eq!( + msg.states[48].sid.code, 77, + "incorrect value for states[48].sid.code, expected 77, is {}", + msg.states[48].sid.code + ); + assert_eq!( + msg.states[48].sid.sat, 128, + "incorrect value for states[48].sid.sat, expected 128, is {}", + msg.states[48].sid.sat + ); + assert_eq!( + msg.states[49].cn0, 58, + "incorrect value for states[49].cn0, expected 58, is {}", + msg.states[49].cn0 + ); + assert_eq!( + msg.states[49].fcn, 41, + "incorrect value for states[49].fcn, expected 41, is {}", + msg.states[49].fcn + ); + assert_eq!( + msg.states[49].sid.code, 194, + "incorrect value for states[49].sid.code, expected 194, is {}", + msg.states[49].sid.code + ); + assert_eq!( + msg.states[49].sid.sat, 134, + "incorrect value for states[49].sid.sat, expected 134, is {}", + msg.states[49].sid.sat + ); + assert_eq!( + msg.states[50].cn0, 55, + "incorrect value for states[50].cn0, expected 55, is {}", + msg.states[50].cn0 + ); + assert_eq!( + msg.states[50].fcn, 129, + "incorrect value for states[50].fcn, expected 129, is {}", + msg.states[50].fcn + ); + assert_eq!( + msg.states[50].sid.code, 53, + "incorrect value for states[50].sid.code, expected 53, is {}", + msg.states[50].sid.code + ); + assert_eq!( + msg.states[50].sid.sat, 18, + "incorrect value for states[50].sid.sat, expected 18, is {}", + msg.states[50].sid.sat + ); + assert_eq!( + msg.states[51].cn0, 92, + "incorrect value for states[51].cn0, expected 92, is {}", + msg.states[51].cn0 + ); + assert_eq!( + msg.states[51].fcn, 134, + "incorrect value for states[51].fcn, expected 134, is {}", + msg.states[51].fcn + ); + assert_eq!( + msg.states[51].sid.code, 72, + "incorrect value for states[51].sid.code, expected 72, is {}", + msg.states[51].sid.code + ); + assert_eq!( + msg.states[51].sid.sat, 91, + "incorrect value for states[51].sid.sat, expected 91, is {}", + msg.states[51].sid.sat + ); + assert_eq!( + msg.states[52].cn0, 56, + "incorrect value for states[52].cn0, expected 56, is {}", + msg.states[52].cn0 + ); + assert_eq!( + msg.states[52].fcn, 157, + "incorrect value for states[52].fcn, expected 157, is {}", + msg.states[52].fcn + ); + assert_eq!( + msg.states[52].sid.code, 224, + "incorrect value for states[52].sid.code, expected 224, is {}", + msg.states[52].sid.code + ); + assert_eq!( + msg.states[52].sid.sat, 33, + "incorrect value for states[52].sid.sat, expected 33, is {}", + msg.states[52].sid.sat + ); + assert_eq!( + msg.states[53].cn0, 174, + "incorrect value for states[53].cn0, expected 174, is {}", + msg.states[53].cn0 + ); + assert_eq!( + msg.states[53].fcn, 224, + "incorrect value for states[53].fcn, expected 224, is {}", + msg.states[53].fcn + ); + assert_eq!( + msg.states[53].sid.code, 54, + "incorrect value for states[53].sid.code, expected 54, is {}", + msg.states[53].sid.code + ); + assert_eq!( + msg.states[53].sid.sat, 186, + "incorrect value for states[53].sid.sat, expected 186, is {}", + msg.states[53].sid.sat + ); + assert_eq!( + msg.states[54].cn0, 190, + "incorrect value for states[54].cn0, expected 190, is {}", + msg.states[54].cn0 + ); + assert_eq!( + msg.states[54].fcn, 148, + "incorrect value for states[54].fcn, expected 148, is {}", + msg.states[54].fcn + ); + assert_eq!( + msg.states[54].sid.code, 84, + "incorrect value for states[54].sid.code, expected 84, is {}", + msg.states[54].sid.code + ); + assert_eq!( + msg.states[54].sid.sat, 82, + "incorrect value for states[54].sid.sat, expected 82, is {}", + msg.states[54].sid.sat + ); + assert_eq!( + msg.states[55].cn0, 67, + "incorrect value for states[55].cn0, expected 67, is {}", + msg.states[55].cn0 + ); + assert_eq!( + msg.states[55].fcn, 62, + "incorrect value for states[55].fcn, expected 62, is {}", + msg.states[55].fcn + ); + assert_eq!( + msg.states[55].sid.code, 54, + "incorrect value for states[55].sid.code, expected 54, is {}", + msg.states[55].sid.code + ); + assert_eq!( + msg.states[55].sid.sat, 236, + "incorrect value for states[55].sid.sat, expected 236, is {}", + msg.states[55].sid.sat + ); + assert_eq!( + msg.states[56].cn0, 254, + "incorrect value for states[56].cn0, expected 254, is {}", + msg.states[56].cn0 + ); + assert_eq!( + msg.states[56].fcn, 57, + "incorrect value for states[56].fcn, expected 57, is {}", + msg.states[56].fcn + ); + assert_eq!( + msg.states[56].sid.code, 215, + "incorrect value for states[56].sid.code, expected 215, is {}", + msg.states[56].sid.code + ); + assert_eq!( + msg.states[56].sid.sat, 52, + "incorrect value for states[56].sid.sat, expected 52, is {}", + msg.states[56].sid.sat + ); + assert_eq!( + msg.states[57].cn0, 174, + "incorrect value for states[57].cn0, expected 174, is {}", + msg.states[57].cn0 + ); + assert_eq!( + msg.states[57].fcn, 36, + "incorrect value for states[57].fcn, expected 36, is {}", + msg.states[57].fcn + ); + assert_eq!( + msg.states[57].sid.code, 133, + "incorrect value for states[57].sid.code, expected 133, is {}", + msg.states[57].sid.code + ); + assert_eq!( + msg.states[57].sid.sat, 16, + "incorrect value for states[57].sid.sat, expected 16, is {}", + msg.states[57].sid.sat + ); + assert_eq!( + msg.states[58].cn0, 17, + "incorrect value for states[58].cn0, expected 17, is {}", + msg.states[58].cn0 + ); + assert_eq!( + msg.states[58].fcn, 145, + "incorrect value for states[58].fcn, expected 145, is {}", + msg.states[58].fcn + ); + assert_eq!( + msg.states[58].sid.code, 172, + "incorrect value for states[58].sid.code, expected 172, is {}", + msg.states[58].sid.code + ); + assert_eq!( + msg.states[58].sid.sat, 219, + "incorrect value for states[58].sid.sat, expected 219, is {}", + msg.states[58].sid.sat + ); + assert_eq!( + msg.states[59].cn0, 97, + "incorrect value for states[59].cn0, expected 97, is {}", + msg.states[59].cn0 + ); + assert_eq!( + msg.states[59].fcn, 111, + "incorrect value for states[59].fcn, expected 111, is {}", + msg.states[59].fcn + ); + assert_eq!( + msg.states[59].sid.code, 179, + "incorrect value for states[59].sid.code, expected 179, is {}", + msg.states[59].sid.code + ); + assert_eq!( + msg.states[59].sid.sat, 192, + "incorrect value for states[59].sid.sat, expected 192, is {}", + msg.states[59].sid.sat + ); + assert_eq!( + msg.states[60].cn0, 134, + "incorrect value for states[60].cn0, expected 134, is {}", + msg.states[60].cn0 + ); + assert_eq!( + msg.states[60].fcn, 208, + "incorrect value for states[60].fcn, expected 208, is {}", + msg.states[60].fcn + ); + assert_eq!( + msg.states[60].sid.code, 56, + "incorrect value for states[60].sid.code, expected 56, is {}", + msg.states[60].sid.code + ); + assert_eq!( + msg.states[60].sid.sat, 207, + "incorrect value for states[60].sid.sat, expected 207, is {}", + msg.states[60].sid.sat + ); + assert_eq!( + msg.states[61].cn0, 226, + "incorrect value for states[61].cn0, expected 226, is {}", + msg.states[61].cn0 + ); + assert_eq!( + msg.states[61].fcn, 43, + "incorrect value for states[61].fcn, expected 43, is {}", + msg.states[61].fcn + ); + assert_eq!( + msg.states[61].sid.code, 17, + "incorrect value for states[61].sid.code, expected 17, is {}", + msg.states[61].sid.code + ); + assert_eq!( + msg.states[61].sid.sat, 180, + "incorrect value for states[61].sid.sat, expected 180, is {}", + msg.states[61].sid.sat + ); + assert_eq!( + msg.states[62].cn0, 113, + "incorrect value for states[62].cn0, expected 113, is {}", + msg.states[62].cn0 + ); + assert_eq!( + msg.states[62].fcn, 140, + "incorrect value for states[62].fcn, expected 140, is {}", + msg.states[62].fcn + ); + assert_eq!( + msg.states[62].sid.code, 182, + "incorrect value for states[62].sid.code, expected 182, is {}", + msg.states[62].sid.code + ); + assert_eq!( + msg.states[62].sid.sat, 255, + "incorrect value for states[62].sid.sat, expected 255, is {}", + msg.states[62].sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingState"), + }; + } + { + let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.24782180786133, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.09756088256836, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.62678527832031, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 39.020729064941406, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.03290557861328, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.43546676635742, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.4229621887207, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 38.91520309448242, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.62259292602539, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 25054, "length": 99, "preamble": 85, "payload": "AcoAAADF/RxCAcsAAADnYxBCAdAAAADUgRZCAdQAAAA6FRxCAdkAAACyIShCAdoAAADrvRVCAdwAAAAdsRlCAd4AAAArqRtCAeEAAACJfSpCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd7f6, + "incorrect sender id, expected 0xd7f6, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(3.92478218078613281e+01), + "incorrect value for states[0].cn0, expected 3.92478218078613281e+01, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 0, + "incorrect value for states[0].sid.code, expected 0, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 0, + "incorrect value for states[0].sid.reserved, expected 0, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 202, + "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 1, + "incorrect value for states[0].state, expected 1, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(3.60975608825683594e+01), + "incorrect value for states[1].cn0, expected 3.60975608825683594e+01, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 0, + "incorrect value for states[1].sid.code, expected 0, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 0, + "incorrect value for states[1].sid.reserved, expected 0, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 203, + "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 1, + "incorrect value for states[1].state, expected 1, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(3.76267852783203125e+01), + "incorrect value for states[2].cn0, expected 3.76267852783203125e+01, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 0, + "incorrect value for states[2].sid.code, expected 0, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 0, + "incorrect value for states[2].sid.reserved, expected 0, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 208, + "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 1, + "incorrect value for states[2].state, expected 1, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.90207290649414062e+01), + "incorrect value for states[3].cn0, expected 3.90207290649414062e+01, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 0, + "incorrect value for states[3].sid.code, expected 0, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 0, + "incorrect value for states[3].sid.reserved, expected 0, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 212, + "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 1, + "incorrect value for states[3].state, expected 1, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(4.20329055786132812e+01), + "incorrect value for states[4].cn0, expected 4.20329055786132812e+01, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 0, + "incorrect value for states[4].sid.code, expected 0, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 0, + "incorrect value for states[4].sid.reserved, expected 0, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 217, + "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 1, + "incorrect value for states[4].state, expected 1, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(3.74354667663574219e+01), + "incorrect value for states[5].cn0, expected 3.74354667663574219e+01, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 0, + "incorrect value for states[5].sid.code, expected 0, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 0, + "incorrect value for states[5].sid.reserved, expected 0, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 218, + "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 1, + "incorrect value for states[5].state, expected 1, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(3.84229621887207031e+01), + "incorrect value for states[6].cn0, expected 3.84229621887207031e+01, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 0, + "incorrect value for states[6].sid.code, expected 0, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 0, + "incorrect value for states[6].sid.reserved, expected 0, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 220, + "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 1, + "incorrect value for states[6].state, expected 1, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(3.89152030944824219e+01), + "incorrect value for states[7].cn0, expected 3.89152030944824219e+01, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 0, + "incorrect value for states[7].sid.code, expected 0, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 0, + "incorrect value for states[7].sid.reserved, expected 0, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 222, + "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 1, + "incorrect value for states[7].state, expected 1, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(4.26225929260253906e+01), + "incorrect value for states[8].cn0, expected 4.26225929260253906e+01, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 0, + "incorrect value for states[8].sid.code, expected 0, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 0, + "incorrect value for states[8].sid.reserved, expected 0, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 225, + "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 1, + "incorrect value for states[8].state, expected 1, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), + "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 0, + "incorrect value for states[9].sid.code, expected 0, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 0, + "incorrect value for states[9].sid.reserved, expected 0, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 0, + "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 0, + "incorrect value for states[9].state, expected 0, is {}", + msg.states[9].state + ); + assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); + assert_eq!( + msg.states[10].sid.code, 0, + "incorrect value for states[10].sid.code, expected 0, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 0, + "incorrect value for states[10].sid.reserved, expected 0, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 0, + "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 0, + "incorrect value for states[10].state, expected 0, is {}", + msg.states[10].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } + { + let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 38.994117736816406, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 34.889801025390625, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.44603729248047, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.72849655151367, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 41.983219146728516, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.46448516845703, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.44300079345703, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.03423309326172, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.89944839477539, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 7956, "length": 99, "preamble": 85, "payload": "AcoAAAD6+RtCAcsAAAAojwtCAdAAAAC+yBVCAdQAAAD76RpCAdkAAADR7idCAdoAAACi2xVCAdwAAACixRlCAd4AAAAOIxxCAeEAAAAJmStCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd7f6, + "incorrect sender id, expected 0xd7f6, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(3.89941177368164062e+01), + "incorrect value for states[0].cn0, expected 3.89941177368164062e+01, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 0, + "incorrect value for states[0].sid.code, expected 0, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 0, + "incorrect value for states[0].sid.reserved, expected 0, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 202, + "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 1, + "incorrect value for states[0].state, expected 1, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(3.48898010253906250e+01), + "incorrect value for states[1].cn0, expected 3.48898010253906250e+01, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 0, + "incorrect value for states[1].sid.code, expected 0, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 0, + "incorrect value for states[1].sid.reserved, expected 0, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 203, + "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 1, + "incorrect value for states[1].state, expected 1, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(3.74460372924804688e+01), + "incorrect value for states[2].cn0, expected 3.74460372924804688e+01, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 0, + "incorrect value for states[2].sid.code, expected 0, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 0, + "incorrect value for states[2].sid.reserved, expected 0, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 208, + "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 1, + "incorrect value for states[2].state, expected 1, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.87284965515136719e+01), + "incorrect value for states[3].cn0, expected 3.87284965515136719e+01, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 0, + "incorrect value for states[3].sid.code, expected 0, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 0, + "incorrect value for states[3].sid.reserved, expected 0, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 212, + "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 1, + "incorrect value for states[3].state, expected 1, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(4.19832191467285156e+01), + "incorrect value for states[4].cn0, expected 4.19832191467285156e+01, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 0, + "incorrect value for states[4].sid.code, expected 0, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 0, + "incorrect value for states[4].sid.reserved, expected 0, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 217, + "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 1, + "incorrect value for states[4].state, expected 1, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(3.74644851684570312e+01), + "incorrect value for states[5].cn0, expected 3.74644851684570312e+01, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 0, + "incorrect value for states[5].sid.code, expected 0, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 0, + "incorrect value for states[5].sid.reserved, expected 0, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 218, + "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 1, + "incorrect value for states[5].state, expected 1, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(3.84430007934570312e+01), + "incorrect value for states[6].cn0, expected 3.84430007934570312e+01, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 0, + "incorrect value for states[6].sid.code, expected 0, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 0, + "incorrect value for states[6].sid.reserved, expected 0, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 220, + "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 1, + "incorrect value for states[6].state, expected 1, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(3.90342330932617188e+01), + "incorrect value for states[7].cn0, expected 3.90342330932617188e+01, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 0, + "incorrect value for states[7].sid.code, expected 0, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 0, + "incorrect value for states[7].sid.reserved, expected 0, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 222, + "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 1, + "incorrect value for states[7].state, expected 1, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(4.28994483947753906e+01), + "incorrect value for states[8].cn0, expected 4.28994483947753906e+01, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 0, + "incorrect value for states[8].sid.code, expected 0, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 0, + "incorrect value for states[8].sid.reserved, expected 0, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 225, + "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 1, + "incorrect value for states[8].state, expected 1, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), + "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 0, + "incorrect value for states[9].sid.code, expected 0, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 0, + "incorrect value for states[9].sid.reserved, expected 0, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 0, + "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 0, + "incorrect value for states[9].state, expected 0, is {}", + msg.states[9].state + ); + assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); + assert_eq!( + msg.states[10].sid.code, 0, + "incorrect value for states[10].sid.code, expected 0, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 0, + "incorrect value for states[10].sid.reserved, expected 0, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 0, + "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 0, + "incorrect value for states[10].state, expected 0, is {}", + msg.states[10].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } + { + let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 38.95457077026367, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 35.813316345214844, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.553924560546875, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.88901901245117, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.4013557434082, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.63916015625, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 37.919986724853516, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.25254440307617, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.59827423095703, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 18409, "length": 99, "preamble": 85, "payload": "AcoAAAB70RtCAcsAAADWQA9CAdAAAAA4NxZCAdQAAABbjhtCAdkAAAD9milCAdoAAACAjhZCAdwAAAARrhdCAd4AAACbAh1CAeEAAACiZCpCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd7f6, + "incorrect sender id, expected 0xd7f6, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(3.89545707702636719e+01), + "incorrect value for states[0].cn0, expected 3.89545707702636719e+01, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 0, + "incorrect value for states[0].sid.code, expected 0, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 0, + "incorrect value for states[0].sid.reserved, expected 0, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 202, + "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 1, + "incorrect value for states[0].state, expected 1, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(3.58133163452148438e+01), + "incorrect value for states[1].cn0, expected 3.58133163452148438e+01, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 0, + "incorrect value for states[1].sid.code, expected 0, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 0, + "incorrect value for states[1].sid.reserved, expected 0, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 203, + "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 1, + "incorrect value for states[1].state, expected 1, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(3.75539245605468750e+01), + "incorrect value for states[2].cn0, expected 3.75539245605468750e+01, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 0, + "incorrect value for states[2].sid.code, expected 0, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 0, + "incorrect value for states[2].sid.reserved, expected 0, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 208, + "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 1, + "incorrect value for states[2].state, expected 1, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.88890190124511719e+01), + "incorrect value for states[3].cn0, expected 3.88890190124511719e+01, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 0, + "incorrect value for states[3].sid.code, expected 0, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 0, + "incorrect value for states[3].sid.reserved, expected 0, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 212, + "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 1, + "incorrect value for states[3].state, expected 1, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(4.24013557434082031e+01), + "incorrect value for states[4].cn0, expected 4.24013557434082031e+01, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 0, + "incorrect value for states[4].sid.code, expected 0, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 0, + "incorrect value for states[4].sid.reserved, expected 0, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 217, + "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 1, + "incorrect value for states[4].state, expected 1, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(3.76391601562500000e+01), + "incorrect value for states[5].cn0, expected 3.76391601562500000e+01, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 0, + "incorrect value for states[5].sid.code, expected 0, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 0, + "incorrect value for states[5].sid.reserved, expected 0, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 218, + "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 1, + "incorrect value for states[5].state, expected 1, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(3.79199867248535156e+01), + "incorrect value for states[6].cn0, expected 3.79199867248535156e+01, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 0, + "incorrect value for states[6].sid.code, expected 0, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 0, + "incorrect value for states[6].sid.reserved, expected 0, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 220, + "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 1, + "incorrect value for states[6].state, expected 1, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(3.92525444030761719e+01), + "incorrect value for states[7].cn0, expected 3.92525444030761719e+01, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 0, + "incorrect value for states[7].sid.code, expected 0, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 0, + "incorrect value for states[7].sid.reserved, expected 0, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 222, + "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 1, + "incorrect value for states[7].state, expected 1, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(4.25982742309570312e+01), + "incorrect value for states[8].cn0, expected 4.25982742309570312e+01, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 0, + "incorrect value for states[8].sid.code, expected 0, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 0, + "incorrect value for states[8].sid.reserved, expected 0, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 225, + "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 1, + "incorrect value for states[8].state, expected 1, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), + "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 0, + "incorrect value for states[9].sid.code, expected 0, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 0, + "incorrect value for states[9].sid.reserved, expected 0, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 0, + "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 0, + "incorrect value for states[9].state, expected 0, is {}", + msg.states[9].state + ); + assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); + assert_eq!( + msg.states[10].sid.code, 0, + "incorrect value for states[10].sid.code, expected 0, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 0, + "incorrect value for states[10].sid.reserved, expected 0, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 0, + "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 0, + "incorrect value for states[10].state, expected 0, is {}", + msg.states[10].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } + { + let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.369598388671875, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.52173614501953, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 38.15976333618164, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 39.19989776611328, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 41.55845642089844, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.026981353759766, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 38.1049690246582, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 39.04584503173828, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.37783432006836, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 49481, "length": 99, "preamble": 85, "payload": "AcoAAAB4eh1CAcsAAABCFhJCAdAAAACZoxhCAdQAAACyzBxCAdkAAADcOyZCAdoAAAChGxRCAdwAAAB9axhCAd4AAADyLhxCAeEAAADngilCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd7f6, + "incorrect sender id, expected 0xd7f6, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(3.93695983886718750e+01), + "incorrect value for states[0].cn0, expected 3.93695983886718750e+01, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 0, + "incorrect value for states[0].sid.code, expected 0, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 0, + "incorrect value for states[0].sid.reserved, expected 0, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 202, + "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 1, + "incorrect value for states[0].state, expected 1, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(3.65217361450195312e+01), + "incorrect value for states[1].cn0, expected 3.65217361450195312e+01, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 0, + "incorrect value for states[1].sid.code, expected 0, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 0, + "incorrect value for states[1].sid.reserved, expected 0, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 203, + "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 1, + "incorrect value for states[1].state, expected 1, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(3.81597633361816406e+01), + "incorrect value for states[2].cn0, expected 3.81597633361816406e+01, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 0, + "incorrect value for states[2].sid.code, expected 0, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 0, + "incorrect value for states[2].sid.reserved, expected 0, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 208, + "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 1, + "incorrect value for states[2].state, expected 1, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.91998977661132812e+01), + "incorrect value for states[3].cn0, expected 3.91998977661132812e+01, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 0, + "incorrect value for states[3].sid.code, expected 0, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 0, + "incorrect value for states[3].sid.reserved, expected 0, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 212, + "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 1, + "incorrect value for states[3].state, expected 1, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(4.15584564208984375e+01), + "incorrect value for states[4].cn0, expected 4.15584564208984375e+01, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 0, + "incorrect value for states[4].sid.code, expected 0, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 0, + "incorrect value for states[4].sid.reserved, expected 0, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 217, + "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 1, + "incorrect value for states[4].state, expected 1, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(3.70269813537597656e+01), + "incorrect value for states[5].cn0, expected 3.70269813537597656e+01, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 0, + "incorrect value for states[5].sid.code, expected 0, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 0, + "incorrect value for states[5].sid.reserved, expected 0, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 218, + "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 1, + "incorrect value for states[5].state, expected 1, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(3.81049690246582031e+01), + "incorrect value for states[6].cn0, expected 3.81049690246582031e+01, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 0, + "incorrect value for states[6].sid.code, expected 0, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 0, + "incorrect value for states[6].sid.reserved, expected 0, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 220, + "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 1, + "incorrect value for states[6].state, expected 1, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(3.90458450317382812e+01), + "incorrect value for states[7].cn0, expected 3.90458450317382812e+01, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 0, + "incorrect value for states[7].sid.code, expected 0, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 0, + "incorrect value for states[7].sid.reserved, expected 0, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 222, + "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 1, + "incorrect value for states[7].state, expected 1, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(4.23778343200683594e+01), + "incorrect value for states[8].cn0, expected 4.23778343200683594e+01, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 0, + "incorrect value for states[8].sid.code, expected 0, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 0, + "incorrect value for states[8].sid.reserved, expected 0, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 225, + "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 1, + "incorrect value for states[8].state, expected 1, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), + "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 0, + "incorrect value for states[9].sid.code, expected 0, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 0, + "incorrect value for states[9].sid.reserved, expected 0, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 0, + "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 0, + "incorrect value for states[9].state, expected 0, is {}", + msg.states[9].state + ); + assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); + assert_eq!( + msg.states[10].sid.code, 0, + "incorrect value for states[10].sid.code, expected 0, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 0, + "incorrect value for states[10].sid.reserved, expected 0, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 0, + "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 0, + "incorrect value for states[10].state, expected 0, is {}", + msg.states[10].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } + { + let json_input = r#"{"sender": 55286, "msg_type": 19, "states": [{"state": 1, "cn0": 39.70351791381836, "sid": {"code": 0, "reserved": 0, "sat": 202}}, {"state": 1, "cn0": 36.52388381958008, "sid": {"code": 0, "reserved": 0, "sat": 203}}, {"state": 1, "cn0": 37.169708251953125, "sid": {"code": 0, "reserved": 0, "sat": 208}}, {"state": 1, "cn0": 38.81692886352539, "sid": {"code": 0, "reserved": 0, "sat": 212}}, {"state": 1, "cn0": 42.05073165893555, "sid": {"code": 0, "reserved": 0, "sat": 217}}, {"state": 1, "cn0": 37.807498931884766, "sid": {"code": 0, "reserved": 0, "sat": 218}}, {"state": 1, "cn0": 37.71632385253906, "sid": {"code": 0, "reserved": 0, "sat": 220}}, {"state": 1, "cn0": 38.5289192199707, "sid": {"code": 0, "reserved": 0, "sat": 222}}, {"state": 1, "cn0": 42.27101516723633, "sid": {"code": 0, "reserved": 0, "sat": 225}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}, {"state": 0, "cn0": -1.0, "sid": {"code": 0, "reserved": 0, "sat": 0}}], "crc": 12158, "length": 99, "preamble": 85, "payload": "AcoAAABn0B5CAcsAAAB1GBJCAdAAAADIrRRCAdQAAACJRBtCAdkAAADzMyhCAdoAAADhOhdCAdwAAACE3RZCAd4AAACdHRpCAeEAAACFFSlCAAAAAAAAAIC/AAAAAAAAAIC/"}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xd7f6, + "incorrect sender id, expected 0xd7f6, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(3.97035179138183594e+01), + "incorrect value for states[0].cn0, expected 3.97035179138183594e+01, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 0, + "incorrect value for states[0].sid.code, expected 0, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 0, + "incorrect value for states[0].sid.reserved, expected 0, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 202, + "incorrect value for states[0].sid.sat, expected 202, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 1, + "incorrect value for states[0].state, expected 1, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(3.65238838195800781e+01), + "incorrect value for states[1].cn0, expected 3.65238838195800781e+01, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 0, + "incorrect value for states[1].sid.code, expected 0, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 0, + "incorrect value for states[1].sid.reserved, expected 0, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 203, + "incorrect value for states[1].sid.sat, expected 203, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 1, + "incorrect value for states[1].state, expected 1, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(3.71697082519531250e+01), + "incorrect value for states[2].cn0, expected 3.71697082519531250e+01, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 0, + "incorrect value for states[2].sid.code, expected 0, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 0, + "incorrect value for states[2].sid.reserved, expected 0, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 208, + "incorrect value for states[2].sid.sat, expected 208, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 1, + "incorrect value for states[2].state, expected 1, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.88169288635253906e+01), + "incorrect value for states[3].cn0, expected 3.88169288635253906e+01, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 0, + "incorrect value for states[3].sid.code, expected 0, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 0, + "incorrect value for states[3].sid.reserved, expected 0, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 212, + "incorrect value for states[3].sid.sat, expected 212, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 1, + "incorrect value for states[3].state, expected 1, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(4.20507316589355469e+01), + "incorrect value for states[4].cn0, expected 4.20507316589355469e+01, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 0, + "incorrect value for states[4].sid.code, expected 0, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 0, + "incorrect value for states[4].sid.reserved, expected 0, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 217, + "incorrect value for states[4].sid.sat, expected 217, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 1, + "incorrect value for states[4].state, expected 1, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(3.78074989318847656e+01), + "incorrect value for states[5].cn0, expected 3.78074989318847656e+01, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 0, + "incorrect value for states[5].sid.code, expected 0, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 0, + "incorrect value for states[5].sid.reserved, expected 0, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 218, + "incorrect value for states[5].sid.sat, expected 218, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 1, + "incorrect value for states[5].state, expected 1, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(3.77163238525390625e+01), + "incorrect value for states[6].cn0, expected 3.77163238525390625e+01, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 0, + "incorrect value for states[6].sid.code, expected 0, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 0, + "incorrect value for states[6].sid.reserved, expected 0, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 220, + "incorrect value for states[6].sid.sat, expected 220, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 1, + "incorrect value for states[6].state, expected 1, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(3.85289192199707031e+01), + "incorrect value for states[7].cn0, expected 3.85289192199707031e+01, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 0, + "incorrect value for states[7].sid.code, expected 0, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 0, + "incorrect value for states[7].sid.reserved, expected 0, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 222, + "incorrect value for states[7].sid.sat, expected 222, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 1, + "incorrect value for states[7].state, expected 1, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(4.22710151672363281e+01), + "incorrect value for states[8].cn0, expected 4.22710151672363281e+01, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 0, + "incorrect value for states[8].sid.code, expected 0, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 0, + "incorrect value for states[8].sid.reserved, expected 0, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 225, + "incorrect value for states[8].sid.sat, expected 225, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 1, + "incorrect value for states[8].state, expected 1, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(-1.00000000000000000e+00), + "incorrect value for states[9].cn0, expected -1.00000000000000000e+00, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 0, + "incorrect value for states[9].sid.code, expected 0, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 0, + "incorrect value for states[9].sid.reserved, expected 0, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 0, + "incorrect value for states[9].sid.sat, expected 0, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 0, + "incorrect value for states[9].state, expected 0, is {}", + msg.states[9].state + ); + assert!(msg.states[10].cn0.almost_eq( -1.00000000000000000e+00 ), "incorrect value for states[10].cn0, expected -1.00000000000000000e+00, is {:e}", msg.states[10].cn0); + assert_eq!( + msg.states[10].sid.code, 0, + "incorrect value for states[10].sid.code, expected 0, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 0, + "incorrect value for states[10].sid.reserved, expected 0, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 0, + "incorrect value for states[10].sid.sat, expected 0, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 0, + "incorrect value for states[10].state, expected 0, is {}", + msg.states[10].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_state`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_state() { + { + let mut payload = Cursor::new(vec![ + 85, 65, 0, 55, 129, 252, 117, 184, 3, 102, 38, 106, 140, 141, 25, 4, 90, 195, 246, 108, + 75, 82, 137, 127, 45, 163, 32, 46, 187, 93, 153, 60, 201, 147, 23, 29, 5, 208, 181, 30, + 219, 69, 254, 136, 3, 121, 33, 98, 144, 215, 133, 182, 14, 56, 169, 77, 218, 62, 242, + 84, 171, 249, 152, 137, 131, 130, 193, 21, 42, 68, 253, 227, 216, 227, 24, 26, 210, + 179, 19, 15, 227, 255, 122, 75, 187, 200, 217, 48, 218, 122, 187, 238, 142, 149, 238, + 55, 251, 212, 128, 160, 194, 104, 113, 255, 141, 62, 43, 69, 245, 39, 100, 230, 108, + 56, 247, 68, 149, 143, 137, 101, 233, 70, 49, 165, 38, 110, 218, 230, 80, 213, 196, + 179, 139, 128, 15, 178, 196, 171, 8, 212, 97, 194, 83, 233, 79, 99, 55, 90, 31, 180, 5, + 25, 105, 186, 22, 224, 80, 111, 8, 48, 106, 166, 4, 48, 156, 49, 86, 19, 142, 146, 91, + 124, 115, 64, 28, 230, 115, 178, 190, 131, 16, 242, 105, 59, 182, 113, 192, 180, 48, + 179, 166, 31, 172, 211, 77, 228, 140, 49, 128, 77, 240, 194, 134, 194, 41, 58, 18, 53, + 129, 55, 91, 72, 134, 92, 33, 224, 157, 56, 186, 54, 224, 174, 82, 84, 148, 190, 236, + 54, 62, 67, 52, 215, 57, 254, 16, 133, 36, 174, 219, 172, 145, 17, 192, 179, 111, 97, + 207, 56, 208, 134, 180, 17, 43, 226, 255, 182, 140, 113, 141, 111, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingState( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingState(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x41, + "Incorrect message type, expected 0x41, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x8137, + "incorrect sender id, expected 0x8137, is {sender_id}" + ); + assert_eq!( + msg.states[0].cn0, 102, + "incorrect value for states[0].cn0, expected 102, is {}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].fcn, 3, + "incorrect value for states[0].fcn, expected 3, is {}", + msg.states[0].fcn + ); + assert_eq!( + msg.states[0].sid.code, 184, + "incorrect value for states[0].sid.code, expected 184, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.sat, 117, + "incorrect value for states[0].sid.sat, expected 117, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[1].cn0, 141, + "incorrect value for states[1].cn0, expected 141, is {}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].fcn, 140, + "incorrect value for states[1].fcn, expected 140, is {}", + msg.states[1].fcn + ); + assert_eq!( + msg.states[1].sid.code, 106, + "incorrect value for states[1].sid.code, expected 106, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.sat, 38, + "incorrect value for states[1].sid.sat, expected 38, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[2].cn0, 195, + "incorrect value for states[2].cn0, expected 195, is {}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].fcn, 90, + "incorrect value for states[2].fcn, expected 90, is {}", + msg.states[2].fcn + ); + assert_eq!( + msg.states[2].sid.code, 4, + "incorrect value for states[2].sid.code, expected 4, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.sat, 25, + "incorrect value for states[2].sid.sat, expected 25, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[3].cn0, 82, + "incorrect value for states[3].cn0, expected 82, is {}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].fcn, 75, + "incorrect value for states[3].fcn, expected 75, is {}", + msg.states[3].fcn + ); + assert_eq!( + msg.states[3].sid.code, 108, + "incorrect value for states[3].sid.code, expected 108, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.sat, 246, + "incorrect value for states[3].sid.sat, expected 246, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[4].cn0, 163, + "incorrect value for states[4].cn0, expected 163, is {}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].fcn, 45, + "incorrect value for states[4].fcn, expected 45, is {}", + msg.states[4].fcn + ); + assert_eq!( + msg.states[4].sid.code, 127, + "incorrect value for states[4].sid.code, expected 127, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.sat, 137, + "incorrect value for states[4].sid.sat, expected 137, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[5].cn0, 93, + "incorrect value for states[5].cn0, expected 93, is {}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].fcn, 187, + "incorrect value for states[5].fcn, expected 187, is {}", + msg.states[5].fcn + ); + assert_eq!( + msg.states[5].sid.code, 46, + "incorrect value for states[5].sid.code, expected 46, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.sat, 32, + "incorrect value for states[5].sid.sat, expected 32, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[6].cn0, 147, + "incorrect value for states[6].cn0, expected 147, is {}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].fcn, 201, + "incorrect value for states[6].fcn, expected 201, is {}", + msg.states[6].fcn + ); + assert_eq!( + msg.states[6].sid.code, 60, + "incorrect value for states[6].sid.code, expected 60, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.sat, 153, + "incorrect value for states[6].sid.sat, expected 153, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[7].cn0, 208, + "incorrect value for states[7].cn0, expected 208, is {}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].fcn, 5, + "incorrect value for states[7].fcn, expected 5, is {}", + msg.states[7].fcn + ); + assert_eq!( + msg.states[7].sid.code, 29, + "incorrect value for states[7].sid.code, expected 29, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.sat, 23, + "incorrect value for states[7].sid.sat, expected 23, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[8].cn0, 69, + "incorrect value for states[8].cn0, expected 69, is {}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].fcn, 219, + "incorrect value for states[8].fcn, expected 219, is {}", + msg.states[8].fcn + ); + assert_eq!( + msg.states[8].sid.code, 30, + "incorrect value for states[8].sid.code, expected 30, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.sat, 181, + "incorrect value for states[8].sid.sat, expected 181, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[9].cn0, 121, + "incorrect value for states[9].cn0, expected 121, is {}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].fcn, 3, + "incorrect value for states[9].fcn, expected 3, is {}", + msg.states[9].fcn + ); + assert_eq!( + msg.states[9].sid.code, 136, + "incorrect value for states[9].sid.code, expected 136, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.sat, 254, + "incorrect value for states[9].sid.sat, expected 254, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[10].cn0, 215, + "incorrect value for states[10].cn0, expected 215, is {}", + msg.states[10].cn0 + ); + assert_eq!( + msg.states[10].fcn, 144, + "incorrect value for states[10].fcn, expected 144, is {}", + msg.states[10].fcn + ); + assert_eq!( + msg.states[10].sid.code, 98, + "incorrect value for states[10].sid.code, expected 98, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.sat, 33, + "incorrect value for states[10].sid.sat, expected 33, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[11].cn0, 56, + "incorrect value for states[11].cn0, expected 56, is {}", + msg.states[11].cn0 + ); + assert_eq!( + msg.states[11].fcn, 14, + "incorrect value for states[11].fcn, expected 14, is {}", + msg.states[11].fcn + ); + assert_eq!( + msg.states[11].sid.code, 182, + "incorrect value for states[11].sid.code, expected 182, is {}", + msg.states[11].sid.code + ); + assert_eq!( + msg.states[11].sid.sat, 133, + "incorrect value for states[11].sid.sat, expected 133, is {}", + msg.states[11].sid.sat + ); + assert_eq!( + msg.states[12].cn0, 62, + "incorrect value for states[12].cn0, expected 62, is {}", + msg.states[12].cn0 + ); + assert_eq!( + msg.states[12].fcn, 218, + "incorrect value for states[12].fcn, expected 218, is {}", + msg.states[12].fcn + ); + assert_eq!( + msg.states[12].sid.code, 77, + "incorrect value for states[12].sid.code, expected 77, is {}", + msg.states[12].sid.code + ); + assert_eq!( + msg.states[12].sid.sat, 169, + "incorrect value for states[12].sid.sat, expected 169, is {}", + msg.states[12].sid.sat + ); + assert_eq!( + msg.states[13].cn0, 249, + "incorrect value for states[13].cn0, expected 249, is {}", + msg.states[13].cn0 + ); + assert_eq!( + msg.states[13].fcn, 171, + "incorrect value for states[13].fcn, expected 171, is {}", + msg.states[13].fcn + ); + assert_eq!( + msg.states[13].sid.code, 84, + "incorrect value for states[13].sid.code, expected 84, is {}", + msg.states[13].sid.code + ); + assert_eq!( + msg.states[13].sid.sat, 242, + "incorrect value for states[13].sid.sat, expected 242, is {}", + msg.states[13].sid.sat + ); + assert_eq!( + msg.states[14].cn0, 130, + "incorrect value for states[14].cn0, expected 130, is {}", + msg.states[14].cn0 + ); + assert_eq!( + msg.states[14].fcn, 131, + "incorrect value for states[14].fcn, expected 131, is {}", + msg.states[14].fcn + ); + assert_eq!( + msg.states[14].sid.code, 137, + "incorrect value for states[14].sid.code, expected 137, is {}", + msg.states[14].sid.code + ); + assert_eq!( + msg.states[14].sid.sat, 152, + "incorrect value for states[14].sid.sat, expected 152, is {}", + msg.states[14].sid.sat + ); + assert_eq!( + msg.states[15].cn0, 68, + "incorrect value for states[15].cn0, expected 68, is {}", + msg.states[15].cn0 + ); + assert_eq!( + msg.states[15].fcn, 42, + "incorrect value for states[15].fcn, expected 42, is {}", + msg.states[15].fcn + ); + assert_eq!( + msg.states[15].sid.code, 21, + "incorrect value for states[15].sid.code, expected 21, is {}", + msg.states[15].sid.code + ); + assert_eq!( + msg.states[15].sid.sat, 193, + "incorrect value for states[15].sid.sat, expected 193, is {}", + msg.states[15].sid.sat + ); + assert_eq!( + msg.states[16].cn0, 227, + "incorrect value for states[16].cn0, expected 227, is {}", + msg.states[16].cn0 + ); + assert_eq!( + msg.states[16].fcn, 216, + "incorrect value for states[16].fcn, expected 216, is {}", + msg.states[16].fcn + ); + assert_eq!( + msg.states[16].sid.code, 227, + "incorrect value for states[16].sid.code, expected 227, is {}", + msg.states[16].sid.code + ); + assert_eq!( + msg.states[16].sid.sat, 253, + "incorrect value for states[16].sid.sat, expected 253, is {}", + msg.states[16].sid.sat + ); + assert_eq!( + msg.states[17].cn0, 179, + "incorrect value for states[17].cn0, expected 179, is {}", + msg.states[17].cn0 + ); + assert_eq!( + msg.states[17].fcn, 210, + "incorrect value for states[17].fcn, expected 210, is {}", + msg.states[17].fcn + ); + assert_eq!( + msg.states[17].sid.code, 26, + "incorrect value for states[17].sid.code, expected 26, is {}", + msg.states[17].sid.code + ); + assert_eq!( + msg.states[17].sid.sat, 24, + "incorrect value for states[17].sid.sat, expected 24, is {}", + msg.states[17].sid.sat + ); + assert_eq!( + msg.states[18].cn0, 255, + "incorrect value for states[18].cn0, expected 255, is {}", + msg.states[18].cn0 + ); + assert_eq!( + msg.states[18].fcn, 227, + "incorrect value for states[18].fcn, expected 227, is {}", + msg.states[18].fcn + ); + assert_eq!( + msg.states[18].sid.code, 15, + "incorrect value for states[18].sid.code, expected 15, is {}", + msg.states[18].sid.code + ); + assert_eq!( + msg.states[18].sid.sat, 19, + "incorrect value for states[18].sid.sat, expected 19, is {}", + msg.states[18].sid.sat + ); + assert_eq!( + msg.states[19].cn0, 200, + "incorrect value for states[19].cn0, expected 200, is {}", + msg.states[19].cn0 + ); + assert_eq!( + msg.states[19].fcn, 187, + "incorrect value for states[19].fcn, expected 187, is {}", + msg.states[19].fcn + ); + assert_eq!( + msg.states[19].sid.code, 75, + "incorrect value for states[19].sid.code, expected 75, is {}", + msg.states[19].sid.code + ); + assert_eq!( + msg.states[19].sid.sat, 122, + "incorrect value for states[19].sid.sat, expected 122, is {}", + msg.states[19].sid.sat + ); + assert_eq!( + msg.states[20].cn0, 122, + "incorrect value for states[20].cn0, expected 122, is {}", + msg.states[20].cn0 + ); + assert_eq!( + msg.states[20].fcn, 218, + "incorrect value for states[20].fcn, expected 218, is {}", + msg.states[20].fcn + ); + assert_eq!( + msg.states[20].sid.code, 48, + "incorrect value for states[20].sid.code, expected 48, is {}", + msg.states[20].sid.code + ); + assert_eq!( + msg.states[20].sid.sat, 217, + "incorrect value for states[20].sid.sat, expected 217, is {}", + msg.states[20].sid.sat + ); + assert_eq!( + msg.states[21].cn0, 149, + "incorrect value for states[21].cn0, expected 149, is {}", + msg.states[21].cn0 + ); + assert_eq!( + msg.states[21].fcn, 142, + "incorrect value for states[21].fcn, expected 142, is {}", + msg.states[21].fcn + ); + assert_eq!( + msg.states[21].sid.code, 238, + "incorrect value for states[21].sid.code, expected 238, is {}", + msg.states[21].sid.code + ); + assert_eq!( + msg.states[21].sid.sat, 187, + "incorrect value for states[21].sid.sat, expected 187, is {}", + msg.states[21].sid.sat + ); + assert_eq!( + msg.states[22].cn0, 212, + "incorrect value for states[22].cn0, expected 212, is {}", + msg.states[22].cn0 + ); + assert_eq!( + msg.states[22].fcn, 251, + "incorrect value for states[22].fcn, expected 251, is {}", + msg.states[22].fcn + ); + assert_eq!( + msg.states[22].sid.code, 55, + "incorrect value for states[22].sid.code, expected 55, is {}", + msg.states[22].sid.code + ); + assert_eq!( + msg.states[22].sid.sat, 238, + "incorrect value for states[22].sid.sat, expected 238, is {}", + msg.states[22].sid.sat + ); + assert_eq!( + msg.states[23].cn0, 104, + "incorrect value for states[23].cn0, expected 104, is {}", + msg.states[23].cn0 + ); + assert_eq!( + msg.states[23].fcn, 194, + "incorrect value for states[23].fcn, expected 194, is {}", + msg.states[23].fcn + ); + assert_eq!( + msg.states[23].sid.code, 160, + "incorrect value for states[23].sid.code, expected 160, is {}", + msg.states[23].sid.code + ); + assert_eq!( + msg.states[23].sid.sat, 128, + "incorrect value for states[23].sid.sat, expected 128, is {}", + msg.states[23].sid.sat + ); + assert_eq!( + msg.states[24].cn0, 62, + "incorrect value for states[24].cn0, expected 62, is {}", + msg.states[24].cn0 + ); + assert_eq!( + msg.states[24].fcn, 141, + "incorrect value for states[24].fcn, expected 141, is {}", + msg.states[24].fcn + ); + assert_eq!( + msg.states[24].sid.code, 255, + "incorrect value for states[24].sid.code, expected 255, is {}", + msg.states[24].sid.code + ); + assert_eq!( + msg.states[24].sid.sat, 113, + "incorrect value for states[24].sid.sat, expected 113, is {}", + msg.states[24].sid.sat + ); + assert_eq!( + msg.states[25].cn0, 39, + "incorrect value for states[25].cn0, expected 39, is {}", + msg.states[25].cn0 + ); + assert_eq!( + msg.states[25].fcn, 245, + "incorrect value for states[25].fcn, expected 245, is {}", + msg.states[25].fcn + ); + assert_eq!( + msg.states[25].sid.code, 69, + "incorrect value for states[25].sid.code, expected 69, is {}", + msg.states[25].sid.code + ); + assert_eq!( + msg.states[25].sid.sat, 43, + "incorrect value for states[25].sid.sat, expected 43, is {}", + msg.states[25].sid.sat + ); + assert_eq!( + msg.states[26].cn0, 56, + "incorrect value for states[26].cn0, expected 56, is {}", + msg.states[26].cn0 + ); + assert_eq!( + msg.states[26].fcn, 108, + "incorrect value for states[26].fcn, expected 108, is {}", + msg.states[26].fcn + ); + assert_eq!( + msg.states[26].sid.code, 230, + "incorrect value for states[26].sid.code, expected 230, is {}", + msg.states[26].sid.code + ); + assert_eq!( + msg.states[26].sid.sat, 100, + "incorrect value for states[26].sid.sat, expected 100, is {}", + msg.states[26].sid.sat + ); + assert_eq!( + msg.states[27].cn0, 143, + "incorrect value for states[27].cn0, expected 143, is {}", + msg.states[27].cn0 + ); + assert_eq!( + msg.states[27].fcn, 149, + "incorrect value for states[27].fcn, expected 149, is {}", + msg.states[27].fcn + ); + assert_eq!( + msg.states[27].sid.code, 68, + "incorrect value for states[27].sid.code, expected 68, is {}", + msg.states[27].sid.code + ); + assert_eq!( + msg.states[27].sid.sat, 247, + "incorrect value for states[27].sid.sat, expected 247, is {}", + msg.states[27].sid.sat + ); + assert_eq!( + msg.states[28].cn0, 70, + "incorrect value for states[28].cn0, expected 70, is {}", + msg.states[28].cn0 + ); + assert_eq!( + msg.states[28].fcn, 233, + "incorrect value for states[28].fcn, expected 233, is {}", + msg.states[28].fcn + ); + assert_eq!( + msg.states[28].sid.code, 101, + "incorrect value for states[28].sid.code, expected 101, is {}", + msg.states[28].sid.code + ); + assert_eq!( + msg.states[28].sid.sat, 137, + "incorrect value for states[28].sid.sat, expected 137, is {}", + msg.states[28].sid.sat + ); + assert_eq!( + msg.states[29].cn0, 110, + "incorrect value for states[29].cn0, expected 110, is {}", + msg.states[29].cn0 + ); + assert_eq!( + msg.states[29].fcn, 38, + "incorrect value for states[29].fcn, expected 38, is {}", + msg.states[29].fcn + ); + assert_eq!( + msg.states[29].sid.code, 165, + "incorrect value for states[29].sid.code, expected 165, is {}", + msg.states[29].sid.code + ); + assert_eq!( + msg.states[29].sid.sat, 49, + "incorrect value for states[29].sid.sat, expected 49, is {}", + msg.states[29].sid.sat + ); + assert_eq!( + msg.states[30].cn0, 213, + "incorrect value for states[30].cn0, expected 213, is {}", + msg.states[30].cn0 + ); + assert_eq!( + msg.states[30].fcn, 80, + "incorrect value for states[30].fcn, expected 80, is {}", + msg.states[30].fcn + ); + assert_eq!( + msg.states[30].sid.code, 230, + "incorrect value for states[30].sid.code, expected 230, is {}", + msg.states[30].sid.code + ); + assert_eq!( + msg.states[30].sid.sat, 218, + "incorrect value for states[30].sid.sat, expected 218, is {}", + msg.states[30].sid.sat + ); + assert_eq!( + msg.states[31].cn0, 128, + "incorrect value for states[31].cn0, expected 128, is {}", + msg.states[31].cn0 + ); + assert_eq!( + msg.states[31].fcn, 139, + "incorrect value for states[31].fcn, expected 139, is {}", + msg.states[31].fcn + ); + assert_eq!( + msg.states[31].sid.code, 179, + "incorrect value for states[31].sid.code, expected 179, is {}", + msg.states[31].sid.code + ); + assert_eq!( + msg.states[31].sid.sat, 196, + "incorrect value for states[31].sid.sat, expected 196, is {}", + msg.states[31].sid.sat + ); + assert_eq!( + msg.states[32].cn0, 171, + "incorrect value for states[32].cn0, expected 171, is {}", + msg.states[32].cn0 + ); + assert_eq!( + msg.states[32].fcn, 196, + "incorrect value for states[32].fcn, expected 196, is {}", + msg.states[32].fcn + ); + assert_eq!( + msg.states[32].sid.code, 178, + "incorrect value for states[32].sid.code, expected 178, is {}", + msg.states[32].sid.code + ); + assert_eq!( + msg.states[32].sid.sat, 15, + "incorrect value for states[32].sid.sat, expected 15, is {}", + msg.states[32].sid.sat + ); + assert_eq!( + msg.states[33].cn0, 194, + "incorrect value for states[33].cn0, expected 194, is {}", + msg.states[33].cn0 + ); + assert_eq!( + msg.states[33].fcn, 97, + "incorrect value for states[33].fcn, expected 97, is {}", + msg.states[33].fcn + ); + assert_eq!( + msg.states[33].sid.code, 212, + "incorrect value for states[33].sid.code, expected 212, is {}", + msg.states[33].sid.code + ); + assert_eq!( + msg.states[33].sid.sat, 8, + "incorrect value for states[33].sid.sat, expected 8, is {}", + msg.states[33].sid.sat + ); + assert_eq!( + msg.states[34].cn0, 99, + "incorrect value for states[34].cn0, expected 99, is {}", + msg.states[34].cn0 + ); + assert_eq!( + msg.states[34].fcn, 79, + "incorrect value for states[34].fcn, expected 79, is {}", + msg.states[34].fcn + ); + assert_eq!( + msg.states[34].sid.code, 233, + "incorrect value for states[34].sid.code, expected 233, is {}", + msg.states[34].sid.code + ); + assert_eq!( + msg.states[34].sid.sat, 83, + "incorrect value for states[34].sid.sat, expected 83, is {}", + msg.states[34].sid.sat + ); + assert_eq!( + msg.states[35].cn0, 180, + "incorrect value for states[35].cn0, expected 180, is {}", + msg.states[35].cn0 + ); + assert_eq!( + msg.states[35].fcn, 31, + "incorrect value for states[35].fcn, expected 31, is {}", + msg.states[35].fcn + ); + assert_eq!( + msg.states[35].sid.code, 90, + "incorrect value for states[35].sid.code, expected 90, is {}", + msg.states[35].sid.code + ); + assert_eq!( + msg.states[35].sid.sat, 55, + "incorrect value for states[35].sid.sat, expected 55, is {}", + msg.states[35].sid.sat + ); + assert_eq!( + msg.states[36].cn0, 186, + "incorrect value for states[36].cn0, expected 186, is {}", + msg.states[36].cn0 + ); + assert_eq!( + msg.states[36].fcn, 105, + "incorrect value for states[36].fcn, expected 105, is {}", + msg.states[36].fcn + ); + assert_eq!( + msg.states[36].sid.code, 25, + "incorrect value for states[36].sid.code, expected 25, is {}", + msg.states[36].sid.code + ); + assert_eq!( + msg.states[36].sid.sat, 5, + "incorrect value for states[36].sid.sat, expected 5, is {}", + msg.states[36].sid.sat + ); + assert_eq!( + msg.states[37].cn0, 111, + "incorrect value for states[37].cn0, expected 111, is {}", + msg.states[37].cn0 + ); + assert_eq!( + msg.states[37].fcn, 80, + "incorrect value for states[37].fcn, expected 80, is {}", + msg.states[37].fcn + ); + assert_eq!( + msg.states[37].sid.code, 224, + "incorrect value for states[37].sid.code, expected 224, is {}", + msg.states[37].sid.code + ); + assert_eq!( + msg.states[37].sid.sat, 22, + "incorrect value for states[37].sid.sat, expected 22, is {}", + msg.states[37].sid.sat + ); + assert_eq!( + msg.states[38].cn0, 166, + "incorrect value for states[38].cn0, expected 166, is {}", + msg.states[38].cn0 + ); + assert_eq!( + msg.states[38].fcn, 106, + "incorrect value for states[38].fcn, expected 106, is {}", + msg.states[38].fcn + ); + assert_eq!( + msg.states[38].sid.code, 48, + "incorrect value for states[38].sid.code, expected 48, is {}", + msg.states[38].sid.code + ); + assert_eq!( + msg.states[38].sid.sat, 8, + "incorrect value for states[38].sid.sat, expected 8, is {}", + msg.states[38].sid.sat + ); + assert_eq!( + msg.states[39].cn0, 49, + "incorrect value for states[39].cn0, expected 49, is {}", + msg.states[39].cn0 + ); + assert_eq!( + msg.states[39].fcn, 156, + "incorrect value for states[39].fcn, expected 156, is {}", + msg.states[39].fcn + ); + assert_eq!( + msg.states[39].sid.code, 48, + "incorrect value for states[39].sid.code, expected 48, is {}", + msg.states[39].sid.code + ); + assert_eq!( + msg.states[39].sid.sat, 4, + "incorrect value for states[39].sid.sat, expected 4, is {}", + msg.states[39].sid.sat + ); + assert_eq!( + msg.states[40].cn0, 146, + "incorrect value for states[40].cn0, expected 146, is {}", + msg.states[40].cn0 + ); + assert_eq!( + msg.states[40].fcn, 142, + "incorrect value for states[40].fcn, expected 142, is {}", + msg.states[40].fcn + ); + assert_eq!( + msg.states[40].sid.code, 19, + "incorrect value for states[40].sid.code, expected 19, is {}", + msg.states[40].sid.code + ); + assert_eq!( + msg.states[40].sid.sat, 86, + "incorrect value for states[40].sid.sat, expected 86, is {}", + msg.states[40].sid.sat + ); + assert_eq!( + msg.states[41].cn0, 64, + "incorrect value for states[41].cn0, expected 64, is {}", + msg.states[41].cn0 + ); + assert_eq!( + msg.states[41].fcn, 115, + "incorrect value for states[41].fcn, expected 115, is {}", + msg.states[41].fcn + ); + assert_eq!( + msg.states[41].sid.code, 124, + "incorrect value for states[41].sid.code, expected 124, is {}", + msg.states[41].sid.code + ); + assert_eq!( + msg.states[41].sid.sat, 91, + "incorrect value for states[41].sid.sat, expected 91, is {}", + msg.states[41].sid.sat + ); + assert_eq!( + msg.states[42].cn0, 178, + "incorrect value for states[42].cn0, expected 178, is {}", + msg.states[42].cn0 + ); + assert_eq!( + msg.states[42].fcn, 115, + "incorrect value for states[42].fcn, expected 115, is {}", + msg.states[42].fcn + ); + assert_eq!( + msg.states[42].sid.code, 230, + "incorrect value for states[42].sid.code, expected 230, is {}", + msg.states[42].sid.code + ); + assert_eq!( + msg.states[42].sid.sat, 28, + "incorrect value for states[42].sid.sat, expected 28, is {}", + msg.states[42].sid.sat + ); + assert_eq!( + msg.states[43].cn0, 242, + "incorrect value for states[43].cn0, expected 242, is {}", + msg.states[43].cn0 + ); + assert_eq!( + msg.states[43].fcn, 16, + "incorrect value for states[43].fcn, expected 16, is {}", + msg.states[43].fcn + ); + assert_eq!( + msg.states[43].sid.code, 131, + "incorrect value for states[43].sid.code, expected 131, is {}", + msg.states[43].sid.code + ); + assert_eq!( + msg.states[43].sid.sat, 190, + "incorrect value for states[43].sid.sat, expected 190, is {}", + msg.states[43].sid.sat + ); + assert_eq!( + msg.states[44].cn0, 113, + "incorrect value for states[44].cn0, expected 113, is {}", + msg.states[44].cn0 + ); + assert_eq!( + msg.states[44].fcn, 182, + "incorrect value for states[44].fcn, expected 182, is {}", + msg.states[44].fcn + ); + assert_eq!( + msg.states[44].sid.code, 59, + "incorrect value for states[44].sid.code, expected 59, is {}", + msg.states[44].sid.code + ); + assert_eq!( + msg.states[44].sid.sat, 105, + "incorrect value for states[44].sid.sat, expected 105, is {}", + msg.states[44].sid.sat + ); + assert_eq!( + msg.states[45].cn0, 179, + "incorrect value for states[45].cn0, expected 179, is {}", + msg.states[45].cn0 + ); + assert_eq!( + msg.states[45].fcn, 48, + "incorrect value for states[45].fcn, expected 48, is {}", + msg.states[45].fcn + ); + assert_eq!( + msg.states[45].sid.code, 180, + "incorrect value for states[45].sid.code, expected 180, is {}", + msg.states[45].sid.code + ); + assert_eq!( + msg.states[45].sid.sat, 192, + "incorrect value for states[45].sid.sat, expected 192, is {}", + msg.states[45].sid.sat + ); + assert_eq!( + msg.states[46].cn0, 211, + "incorrect value for states[46].cn0, expected 211, is {}", + msg.states[46].cn0 + ); + assert_eq!( + msg.states[46].fcn, 172, + "incorrect value for states[46].fcn, expected 172, is {}", + msg.states[46].fcn + ); + assert_eq!( + msg.states[46].sid.code, 31, + "incorrect value for states[46].sid.code, expected 31, is {}", + msg.states[46].sid.code + ); + assert_eq!( + msg.states[46].sid.sat, 166, + "incorrect value for states[46].sid.sat, expected 166, is {}", + msg.states[46].sid.sat + ); + assert_eq!( + msg.states[47].cn0, 49, + "incorrect value for states[47].cn0, expected 49, is {}", + msg.states[47].cn0 + ); + assert_eq!( + msg.states[47].fcn, 140, + "incorrect value for states[47].fcn, expected 140, is {}", + msg.states[47].fcn + ); + assert_eq!( + msg.states[47].sid.code, 228, + "incorrect value for states[47].sid.code, expected 228, is {}", + msg.states[47].sid.code + ); + assert_eq!( + msg.states[47].sid.sat, 77, + "incorrect value for states[47].sid.sat, expected 77, is {}", + msg.states[47].sid.sat + ); + assert_eq!( + msg.states[48].cn0, 194, + "incorrect value for states[48].cn0, expected 194, is {}", + msg.states[48].cn0 + ); + assert_eq!( + msg.states[48].fcn, 240, + "incorrect value for states[48].fcn, expected 240, is {}", + msg.states[48].fcn + ); + assert_eq!( + msg.states[48].sid.code, 77, + "incorrect value for states[48].sid.code, expected 77, is {}", + msg.states[48].sid.code + ); + assert_eq!( + msg.states[48].sid.sat, 128, + "incorrect value for states[48].sid.sat, expected 128, is {}", + msg.states[48].sid.sat + ); + assert_eq!( + msg.states[49].cn0, 58, + "incorrect value for states[49].cn0, expected 58, is {}", + msg.states[49].cn0 + ); + assert_eq!( + msg.states[49].fcn, 41, + "incorrect value for states[49].fcn, expected 41, is {}", + msg.states[49].fcn + ); + assert_eq!( + msg.states[49].sid.code, 194, + "incorrect value for states[49].sid.code, expected 194, is {}", + msg.states[49].sid.code + ); + assert_eq!( + msg.states[49].sid.sat, 134, + "incorrect value for states[49].sid.sat, expected 134, is {}", + msg.states[49].sid.sat + ); + assert_eq!( + msg.states[50].cn0, 55, + "incorrect value for states[50].cn0, expected 55, is {}", + msg.states[50].cn0 + ); + assert_eq!( + msg.states[50].fcn, 129, + "incorrect value for states[50].fcn, expected 129, is {}", + msg.states[50].fcn + ); + assert_eq!( + msg.states[50].sid.code, 53, + "incorrect value for states[50].sid.code, expected 53, is {}", + msg.states[50].sid.code + ); + assert_eq!( + msg.states[50].sid.sat, 18, + "incorrect value for states[50].sid.sat, expected 18, is {}", + msg.states[50].sid.sat + ); + assert_eq!( + msg.states[51].cn0, 92, + "incorrect value for states[51].cn0, expected 92, is {}", + msg.states[51].cn0 + ); + assert_eq!( + msg.states[51].fcn, 134, + "incorrect value for states[51].fcn, expected 134, is {}", + msg.states[51].fcn + ); + assert_eq!( + msg.states[51].sid.code, 72, + "incorrect value for states[51].sid.code, expected 72, is {}", + msg.states[51].sid.code + ); + assert_eq!( + msg.states[51].sid.sat, 91, + "incorrect value for states[51].sid.sat, expected 91, is {}", + msg.states[51].sid.sat + ); + assert_eq!( + msg.states[52].cn0, 56, + "incorrect value for states[52].cn0, expected 56, is {}", + msg.states[52].cn0 + ); + assert_eq!( + msg.states[52].fcn, 157, + "incorrect value for states[52].fcn, expected 157, is {}", + msg.states[52].fcn + ); + assert_eq!( + msg.states[52].sid.code, 224, + "incorrect value for states[52].sid.code, expected 224, is {}", + msg.states[52].sid.code + ); + assert_eq!( + msg.states[52].sid.sat, 33, + "incorrect value for states[52].sid.sat, expected 33, is {}", + msg.states[52].sid.sat + ); + assert_eq!( + msg.states[53].cn0, 174, + "incorrect value for states[53].cn0, expected 174, is {}", + msg.states[53].cn0 + ); + assert_eq!( + msg.states[53].fcn, 224, + "incorrect value for states[53].fcn, expected 224, is {}", + msg.states[53].fcn + ); + assert_eq!( + msg.states[53].sid.code, 54, + "incorrect value for states[53].sid.code, expected 54, is {}", + msg.states[53].sid.code + ); + assert_eq!( + msg.states[53].sid.sat, 186, + "incorrect value for states[53].sid.sat, expected 186, is {}", + msg.states[53].sid.sat + ); + assert_eq!( + msg.states[54].cn0, 190, + "incorrect value for states[54].cn0, expected 190, is {}", + msg.states[54].cn0 + ); + assert_eq!( + msg.states[54].fcn, 148, + "incorrect value for states[54].fcn, expected 148, is {}", + msg.states[54].fcn + ); + assert_eq!( + msg.states[54].sid.code, 84, + "incorrect value for states[54].sid.code, expected 84, is {}", + msg.states[54].sid.code + ); + assert_eq!( + msg.states[54].sid.sat, 82, + "incorrect value for states[54].sid.sat, expected 82, is {}", + msg.states[54].sid.sat + ); + assert_eq!( + msg.states[55].cn0, 67, + "incorrect value for states[55].cn0, expected 67, is {}", + msg.states[55].cn0 + ); + assert_eq!( + msg.states[55].fcn, 62, + "incorrect value for states[55].fcn, expected 62, is {}", + msg.states[55].fcn + ); + assert_eq!( + msg.states[55].sid.code, 54, + "incorrect value for states[55].sid.code, expected 54, is {}", + msg.states[55].sid.code + ); + assert_eq!( + msg.states[55].sid.sat, 236, + "incorrect value for states[55].sid.sat, expected 236, is {}", + msg.states[55].sid.sat + ); + assert_eq!( + msg.states[56].cn0, 254, + "incorrect value for states[56].cn0, expected 254, is {}", + msg.states[56].cn0 + ); + assert_eq!( + msg.states[56].fcn, 57, + "incorrect value for states[56].fcn, expected 57, is {}", + msg.states[56].fcn + ); + assert_eq!( + msg.states[56].sid.code, 215, + "incorrect value for states[56].sid.code, expected 215, is {}", + msg.states[56].sid.code + ); + assert_eq!( + msg.states[56].sid.sat, 52, + "incorrect value for states[56].sid.sat, expected 52, is {}", + msg.states[56].sid.sat + ); + assert_eq!( + msg.states[57].cn0, 174, + "incorrect value for states[57].cn0, expected 174, is {}", + msg.states[57].cn0 + ); + assert_eq!( + msg.states[57].fcn, 36, + "incorrect value for states[57].fcn, expected 36, is {}", + msg.states[57].fcn + ); + assert_eq!( + msg.states[57].sid.code, 133, + "incorrect value for states[57].sid.code, expected 133, is {}", + msg.states[57].sid.code + ); + assert_eq!( + msg.states[57].sid.sat, 16, + "incorrect value for states[57].sid.sat, expected 16, is {}", + msg.states[57].sid.sat + ); + assert_eq!( + msg.states[58].cn0, 17, + "incorrect value for states[58].cn0, expected 17, is {}", + msg.states[58].cn0 + ); + assert_eq!( + msg.states[58].fcn, 145, + "incorrect value for states[58].fcn, expected 145, is {}", + msg.states[58].fcn + ); + assert_eq!( + msg.states[58].sid.code, 172, + "incorrect value for states[58].sid.code, expected 172, is {}", + msg.states[58].sid.code + ); + assert_eq!( + msg.states[58].sid.sat, 219, + "incorrect value for states[58].sid.sat, expected 219, is {}", + msg.states[58].sid.sat + ); + assert_eq!( + msg.states[59].cn0, 97, + "incorrect value for states[59].cn0, expected 97, is {}", + msg.states[59].cn0 + ); + assert_eq!( + msg.states[59].fcn, 111, + "incorrect value for states[59].fcn, expected 111, is {}", + msg.states[59].fcn + ); + assert_eq!( + msg.states[59].sid.code, 179, + "incorrect value for states[59].sid.code, expected 179, is {}", + msg.states[59].sid.code + ); + assert_eq!( + msg.states[59].sid.sat, 192, + "incorrect value for states[59].sid.sat, expected 192, is {}", + msg.states[59].sid.sat + ); + assert_eq!( + msg.states[60].cn0, 134, + "incorrect value for states[60].cn0, expected 134, is {}", + msg.states[60].cn0 + ); + assert_eq!( + msg.states[60].fcn, 208, + "incorrect value for states[60].fcn, expected 208, is {}", + msg.states[60].fcn + ); + assert_eq!( + msg.states[60].sid.code, 56, + "incorrect value for states[60].sid.code, expected 56, is {}", + msg.states[60].sid.code + ); + assert_eq!( + msg.states[60].sid.sat, 207, + "incorrect value for states[60].sid.sat, expected 207, is {}", + msg.states[60].sid.sat + ); + assert_eq!( + msg.states[61].cn0, 226, + "incorrect value for states[61].cn0, expected 226, is {}", + msg.states[61].cn0 + ); + assert_eq!( + msg.states[61].fcn, 43, + "incorrect value for states[61].fcn, expected 43, is {}", + msg.states[61].fcn + ); + assert_eq!( + msg.states[61].sid.code, 17, + "incorrect value for states[61].sid.code, expected 17, is {}", + msg.states[61].sid.code + ); + assert_eq!( + msg.states[61].sid.sat, 180, + "incorrect value for states[61].sid.sat, expected 180, is {}", + msg.states[61].sid.sat + ); + assert_eq!( + msg.states[62].cn0, 113, + "incorrect value for states[62].cn0, expected 113, is {}", + msg.states[62].cn0 + ); + assert_eq!( + msg.states[62].fcn, 140, + "incorrect value for states[62].fcn, expected 140, is {}", + msg.states[62].fcn + ); + assert_eq!( + msg.states[62].sid.code, 182, + "incorrect value for states[62].sid.code, expected 182, is {}", + msg.states[62].sid.code + ); + assert_eq!( + msg.states[62].sid.sat, 255, + "incorrect value for states[62].sid.sat, expected 255, is {}", + msg.states[62].sid.sat + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingState"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } { let mut payload = Cursor::new(vec![ 85, 19, 0, 246, 215, 99, 1, 202, 0, 0, 0, 197, 253, 28, 66, 1, 203, 0, 0, 0, 231, 99, diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_dep_b.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_dep_b.rs new file mode 100644 index 0000000000..db9864d489 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_dep_b.rs @@ -0,0 +1,2293 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_msg_tracking_state_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, 69, 255, 175, 121, 43, + 222, 51, 67, 35, 69, 78, 240, 5, 53, 20, 51, 211, 54, 69, 153, 130, 237, 66, 155, 51, + 227, 71, 69, 53, 242, 136, 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, 154, + 217, 184, 69, 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, 115, 141, 27, 12, 154, 225, + 200, 69, 208, 44, 147, 39, 23, 51, 3, 66, 69, 237, 159, 251, 49, 203, 51, 99, 102, 69, + 70, 214, 87, 128, 206, 154, 121, 186, 69, 14, 206, 111, 218, 19, 154, 121, 169, 69, + 216, 98, 209, 54, 2, 154, 25, 219, 67, 200, 133, 99, 7, 34, 102, 198, 232, 68, 155, 43, + 85, 135, 46, 154, 177, 170, 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, 121, 43, 197, + 16, 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, 115, 66, 69, 36, 20, 61, 153, 51, + 154, 73, 134, 69, 46, 82, 116, 140, 22, 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, + 76, 107, 68, 220, 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, 135, 186, 171, 51, 163, 4, + 69, 18, 124, 155, 85, 170, 205, 208, 13, 70, 57, 244, 206, 255, 186, 154, 105, 149, 69, + 165, 199, 93, 181, 175, 51, 67, 64, 69, 6, 28, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf1f2, + "incorrect sender id, expected 0xf1f2, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(5.85620019531250000e+03), + "incorrect value for states[0].cn0, expected 5.85620019531250000e+03, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 63, + "incorrect value for states[0].sid.code, expected 63, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 68, + "incorrect value for states[0].sid.reserved, expected 68, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 58295, + "incorrect value for states[0].sid.sat, expected 58295, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 115, + "incorrect value for states[0].state, expected 115, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(2.61219995117187500e+03), + "incorrect value for states[1].cn0, expected 2.61219995117187500e+03, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 43, + "incorrect value for states[1].sid.code, expected 43, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 222, + "incorrect value for states[1].sid.reserved, expected 222, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 31151, + "incorrect value for states[1].sid.sat, expected 31151, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 255, + "incorrect value for states[1].state, expected 255, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(2.92519995117187500e+03), + "incorrect value for states[2].cn0, expected 2.92519995117187500e+03, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 53, + "incorrect value for states[2].sid.code, expected 53, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 20, + "incorrect value for states[2].sid.reserved, expected 20, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 1520, + "incorrect value for states[2].sid.sat, expected 1520, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 78, + "incorrect value for states[2].state, expected 78, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.19819995117187500e+03), + "incorrect value for states[3].cn0, expected 3.19819995117187500e+03, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 66, + "incorrect value for states[3].sid.code, expected 66, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 155, + "incorrect value for states[3].sid.reserved, expected 155, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 60802, + "incorrect value for states[3].sid.sat, expected 60802, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 153, + "incorrect value for states[3].state, expected 153, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(8.62320019531250000e+03), + "incorrect value for states[4].cn0, expected 8.62320019531250000e+03, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 161, + "incorrect value for states[4].sid.code, expected 161, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 190, + "incorrect value for states[4].sid.reserved, expected 190, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 35058, + "incorrect value for states[4].sid.sat, expected 35058, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 53, + "incorrect value for states[4].state, expected 53, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(5.91520019531250000e+03), + "incorrect value for states[5].cn0, expected 5.91520019531250000e+03, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 142, + "incorrect value for states[5].sid.code, expected 142, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 149, + "incorrect value for states[5].sid.reserved, expected 149, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 65405, + "incorrect value for states[5].sid.sat, expected 65405, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 153, + "incorrect value for states[5].state, expected 153, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(5.41220019531250000e+03), + "incorrect value for states[6].cn0, expected 5.41220019531250000e+03, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 31, + "incorrect value for states[6].sid.code, expected 31, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 76, + "incorrect value for states[6].sid.reserved, expected 76, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 24422, + "incorrect value for states[6].sid.sat, expected 24422, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 248, + "incorrect value for states[6].state, expected 248, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(6.42820019531250000e+03), + "incorrect value for states[7].cn0, expected 6.42820019531250000e+03, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 27, + "incorrect value for states[7].sid.code, expected 27, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 12, + "incorrect value for states[7].sid.reserved, expected 12, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 36211, + "incorrect value for states[7].sid.sat, expected 36211, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 131, + "incorrect value for states[7].state, expected 131, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(3.10419995117187500e+03), + "incorrect value for states[8].cn0, expected 3.10419995117187500e+03, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 39, + "incorrect value for states[8].sid.code, expected 39, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 23, + "incorrect value for states[8].sid.reserved, expected 23, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 37676, + "incorrect value for states[8].sid.sat, expected 37676, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 208, + "incorrect value for states[8].state, expected 208, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(3.68619995117187500e+03), + "incorrect value for states[9].cn0, expected 3.68619995117187500e+03, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 49, + "incorrect value for states[9].sid.code, expected 49, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 203, + "incorrect value for states[9].sid.reserved, expected 203, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 64415, + "incorrect value for states[9].sid.sat, expected 64415, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 237, + "incorrect value for states[9].state, expected 237, is {}", + msg.states[9].state + ); + assert!( + msg.states[10].cn0.almost_eq(5.96720019531250000e+03), + "incorrect value for states[10].cn0, expected 5.96720019531250000e+03, is {:e}", + msg.states[10].cn0 + ); + assert_eq!( + msg.states[10].sid.code, 128, + "incorrect value for states[10].sid.code, expected 128, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 206, + "incorrect value for states[10].sid.reserved, expected 206, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 22486, + "incorrect value for states[10].sid.sat, expected 22486, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 70, + "incorrect value for states[10].state, expected 70, is {}", + msg.states[10].state + ); + assert!( + msg.states[11].cn0.almost_eq(5.42320019531250000e+03), + "incorrect value for states[11].cn0, expected 5.42320019531250000e+03, is {:e}", + msg.states[11].cn0 + ); + assert_eq!( + msg.states[11].sid.code, 218, + "incorrect value for states[11].sid.code, expected 218, is {}", + msg.states[11].sid.code + ); + assert_eq!( + msg.states[11].sid.reserved, 19, + "incorrect value for states[11].sid.reserved, expected 19, is {}", + msg.states[11].sid.reserved + ); + assert_eq!( + msg.states[11].sid.sat, 28622, + "incorrect value for states[11].sid.sat, expected 28622, is {}", + msg.states[11].sid.sat + ); + assert_eq!( + msg.states[11].state, 14, + "incorrect value for states[11].state, expected 14, is {}", + msg.states[11].state + ); + assert!( + msg.states[12].cn0.almost_eq(4.38200012207031250e+02), + "incorrect value for states[12].cn0, expected 4.38200012207031250e+02, is {:e}", + msg.states[12].cn0 + ); + assert_eq!( + msg.states[12].sid.code, 54, + "incorrect value for states[12].sid.code, expected 54, is {}", + msg.states[12].sid.code + ); + assert_eq!( + msg.states[12].sid.reserved, 2, + "incorrect value for states[12].sid.reserved, expected 2, is {}", + msg.states[12].sid.reserved + ); + assert_eq!( + msg.states[12].sid.sat, 53602, + "incorrect value for states[12].sid.sat, expected 53602, is {}", + msg.states[12].sid.sat + ); + assert_eq!( + msg.states[12].state, 216, + "incorrect value for states[12].state, expected 216, is {}", + msg.states[12].state + ); + assert!( + msg.states[13].cn0.almost_eq(1.86219995117187500e+03), + "incorrect value for states[13].cn0, expected 1.86219995117187500e+03, is {:e}", + msg.states[13].cn0 + ); + assert_eq!( + msg.states[13].sid.code, 7, + "incorrect value for states[13].sid.code, expected 7, is {}", + msg.states[13].sid.code + ); + assert_eq!( + msg.states[13].sid.reserved, 34, + "incorrect value for states[13].sid.reserved, expected 34, is {}", + msg.states[13].sid.reserved + ); + assert_eq!( + msg.states[13].sid.sat, 25477, + "incorrect value for states[13].sid.sat, expected 25477, is {}", + msg.states[13].sid.sat + ); + assert_eq!( + msg.states[13].state, 200, + "incorrect value for states[13].state, expected 200, is {}", + msg.states[13].state + ); + assert!( + msg.states[14].cn0.almost_eq(5.46220019531250000e+03), + "incorrect value for states[14].cn0, expected 5.46220019531250000e+03, is {:e}", + msg.states[14].cn0 + ); + assert_eq!( + msg.states[14].sid.code, 135, + "incorrect value for states[14].sid.code, expected 135, is {}", + msg.states[14].sid.code + ); + assert_eq!( + msg.states[14].sid.reserved, 46, + "incorrect value for states[14].sid.reserved, expected 46, is {}", + msg.states[14].sid.reserved + ); + assert_eq!( + msg.states[14].sid.sat, 21803, + "incorrect value for states[14].sid.sat, expected 21803, is {}", + msg.states[14].sid.sat + ); + assert_eq!( + msg.states[14].state, 155, + "incorrect value for states[14].state, expected 155, is {}", + msg.states[14].state + ); + assert!( + msg.states[15].cn0.almost_eq(7.45420019531250000e+03), + "incorrect value for states[15].cn0, expected 7.45420019531250000e+03, is {:e}", + msg.states[15].cn0 + ); + assert_eq!( + msg.states[15].sid.code, 171, + "incorrect value for states[15].sid.code, expected 171, is {}", + msg.states[15].sid.code + ); + assert_eq!( + msg.states[15].sid.reserved, 201, + "incorrect value for states[15].sid.reserved, expected 201, is {}", + msg.states[15].sid.reserved + ); + assert_eq!( + msg.states[15].sid.sat, 21251, + "incorrect value for states[15].sid.sat, expected 21251, is {}", + msg.states[15].sid.sat + ); + assert_eq!( + msg.states[15].state, 155, + "incorrect value for states[15].state, expected 155, is {}", + msg.states[15].state + ); + assert!( + msg.states[16].cn0.almost_eq(7.13420019531250000e+03), + "incorrect value for states[16].cn0, expected 7.13420019531250000e+03, is {:e}", + msg.states[16].cn0 + ); + assert_eq!( + msg.states[16].sid.code, 16, + "incorrect value for states[16].sid.code, expected 16, is {}", + msg.states[16].sid.code + ); + assert_eq!( + msg.states[16].sid.reserved, 19, + "incorrect value for states[16].sid.reserved, expected 19, is {}", + msg.states[16].sid.reserved + ); + assert_eq!( + msg.states[16].sid.sat, 50475, + "incorrect value for states[16].sid.sat, expected 50475, is {}", + msg.states[16].sid.sat + ); + assert_eq!( + msg.states[16].state, 121, + "incorrect value for states[16].state, expected 121, is {}", + msg.states[16].state + ); + assert!( + msg.states[17].cn0.almost_eq(3.11119995117187500e+03), + "incorrect value for states[17].cn0, expected 3.11119995117187500e+03, is {:e}", + msg.states[17].cn0 + ); + assert_eq!( + msg.states[17].sid.code, 63, + "incorrect value for states[17].sid.code, expected 63, is {}", + msg.states[17].sid.code + ); + assert_eq!( + msg.states[17].sid.reserved, 176, + "incorrect value for states[17].sid.reserved, expected 176, is {}", + msg.states[17].sid.reserved + ); + assert_eq!( + msg.states[17].sid.sat, 13813, + "incorrect value for states[17].sid.sat, expected 13813, is {}", + msg.states[17].sid.sat + ); + assert_eq!( + msg.states[17].state, 128, + "incorrect value for states[17].state, expected 128, is {}", + msg.states[17].state + ); + assert!( + msg.states[18].cn0.almost_eq(4.29720019531250000e+03), + "incorrect value for states[18].cn0, expected 4.29720019531250000e+03, is {:e}", + msg.states[18].cn0 + ); + assert_eq!( + msg.states[18].sid.code, 153, + "incorrect value for states[18].sid.code, expected 153, is {}", + msg.states[18].sid.code + ); + assert_eq!( + msg.states[18].sid.reserved, 51, + "incorrect value for states[18].sid.reserved, expected 51, is {}", + msg.states[18].sid.reserved + ); + assert_eq!( + msg.states[18].sid.sat, 15636, + "incorrect value for states[18].sid.sat, expected 15636, is {}", + msg.states[18].sid.sat + ); + assert_eq!( + msg.states[18].state, 36, + "incorrect value for states[18].state, expected 36, is {}", + msg.states[18].state + ); + assert!( + msg.states[19].cn0.almost_eq(2.64919995117187500e+03), + "incorrect value for states[19].cn0, expected 2.64919995117187500e+03, is {:e}", + msg.states[19].cn0 + ); + assert_eq!( + msg.states[19].sid.code, 140, + "incorrect value for states[19].sid.code, expected 140, is {}", + msg.states[19].sid.code + ); + assert_eq!( + msg.states[19].sid.reserved, 22, + "incorrect value for states[19].sid.reserved, expected 22, is {}", + msg.states[19].sid.reserved + ); + assert_eq!( + msg.states[19].sid.sat, 29778, + "incorrect value for states[19].sid.sat, expected 29778, is {}", + msg.states[19].sid.sat + ); + assert_eq!( + msg.states[19].state, 46, + "incorrect value for states[19].state, expected 46, is {}", + msg.states[19].state + ); + assert!( + msg.states[20].cn0.almost_eq(9.41200012207031250e+02), + "incorrect value for states[20].cn0, expected 9.41200012207031250e+02, is {:e}", + msg.states[20].cn0 + ); + assert_eq!( + msg.states[20].sid.code, 96, + "incorrect value for states[20].sid.code, expected 96, is {}", + msg.states[20].sid.code + ); + assert_eq!( + msg.states[20].sid.reserved, 143, + "incorrect value for states[20].sid.reserved, expected 143, is {}", + msg.states[20].sid.reserved + ); + assert_eq!( + msg.states[20].sid.sat, 37443, + "incorrect value for states[20].sid.sat, expected 37443, is {}", + msg.states[20].sid.sat + ); + assert_eq!( + msg.states[20].state, 177, + "incorrect value for states[20].state, expected 177, is {}", + msg.states[20].state + ); + assert!( + msg.states[21].cn0.almost_eq(1.53919995117187500e+03), + "incorrect value for states[21].cn0, expected 1.53919995117187500e+03, is {:e}", + msg.states[21].cn0 + ); + assert_eq!( + msg.states[21].sid.code, 201, + "incorrect value for states[21].sid.code, expected 201, is {}", + msg.states[21].sid.code + ); + assert_eq!( + msg.states[21].sid.reserved, 251, + "incorrect value for states[21].sid.reserved, expected 251, is {}", + msg.states[21].sid.reserved + ); + assert_eq!( + msg.states[21].sid.sat, 41011, + "incorrect value for states[21].sid.sat, expected 41011, is {}", + msg.states[21].sid.sat + ); + assert_eq!( + msg.states[21].state, 220, + "incorrect value for states[21].state, expected 220, is {}", + msg.states[21].state + ); + assert!( + msg.states[22].cn0.almost_eq(1.44319995117187500e+03), + "incorrect value for states[22].cn0, expected 1.44319995117187500e+03, is {:e}", + msg.states[22].cn0 + ); + assert_eq!( + msg.states[22].sid.code, 161, + "incorrect value for states[22].sid.code, expected 161, is {}", + msg.states[22].sid.code + ); + assert_eq!( + msg.states[22].sid.reserved, 220, + "incorrect value for states[22].sid.reserved, expected 220, is {}", + msg.states[22].sid.reserved + ); + assert_eq!( + msg.states[22].sid.sat, 706, + "incorrect value for states[22].sid.sat, expected 706, is {}", + msg.states[22].sid.sat + ); + assert_eq!( + msg.states[22].state, 168, + "incorrect value for states[22].state, expected 168, is {}", + msg.states[22].state + ); + assert!( + msg.states[23].cn0.almost_eq(1.07419995117187500e+03), + "incorrect value for states[23].cn0, expected 1.07419995117187500e+03, is {:e}", + msg.states[23].cn0 + ); + assert_eq!( + msg.states[23].sid.code, 125, + "incorrect value for states[23].sid.code, expected 125, is {}", + msg.states[23].sid.code + ); + assert_eq!( + msg.states[23].sid.reserved, 178, + "incorrect value for states[23].sid.reserved, expected 178, is {}", + msg.states[23].sid.reserved + ); + assert_eq!( + msg.states[23].sid.sat, 2312, + "incorrect value for states[23].sid.sat, expected 2312, is {}", + msg.states[23].sid.sat + ); + assert_eq!( + msg.states[23].state, 69, + "incorrect value for states[23].state, expected 69, is {}", + msg.states[23].state + ); + assert!( + msg.states[24].cn0.almost_eq(2.12219995117187500e+03), + "incorrect value for states[24].cn0, expected 2.12219995117187500e+03, is {:e}", + msg.states[24].cn0 + ); + assert_eq!( + msg.states[24].sid.code, 186, + "incorrect value for states[24].sid.code, expected 186, is {}", + msg.states[24].sid.code + ); + assert_eq!( + msg.states[24].sid.reserved, 171, + "incorrect value for states[24].sid.reserved, expected 171, is {}", + msg.states[24].sid.reserved + ); + assert_eq!( + msg.states[24].sid.sat, 34580, + "incorrect value for states[24].sid.sat, expected 34580, is {}", + msg.states[24].sid.sat + ); + assert_eq!( + msg.states[24].state, 185, + "incorrect value for states[24].state, expected 185, is {}", + msg.states[24].state + ); + assert!( + msg.states[25].cn0.almost_eq(9.07620019531250000e+03), + "incorrect value for states[25].cn0, expected 9.07620019531250000e+03, is {:e}", + msg.states[25].cn0 + ); + assert_eq!( + msg.states[25].sid.code, 85, + "incorrect value for states[25].sid.code, expected 85, is {}", + msg.states[25].sid.code + ); + assert_eq!( + msg.states[25].sid.reserved, 170, + "incorrect value for states[25].sid.reserved, expected 170, is {}", + msg.states[25].sid.reserved + ); + assert_eq!( + msg.states[25].sid.sat, 39804, + "incorrect value for states[25].sid.sat, expected 39804, is {}", + msg.states[25].sid.sat + ); + assert_eq!( + msg.states[25].state, 18, + "incorrect value for states[25].state, expected 18, is {}", + msg.states[25].state + ); + assert!( + msg.states[26].cn0.almost_eq(4.78120019531250000e+03), + "incorrect value for states[26].cn0, expected 4.78120019531250000e+03, is {:e}", + msg.states[26].cn0 + ); + assert_eq!( + msg.states[26].sid.code, 255, + "incorrect value for states[26].sid.code, expected 255, is {}", + msg.states[26].sid.code + ); + assert_eq!( + msg.states[26].sid.reserved, 186, + "incorrect value for states[26].sid.reserved, expected 186, is {}", + msg.states[26].sid.reserved + ); + assert_eq!( + msg.states[26].sid.sat, 52980, + "incorrect value for states[26].sid.sat, expected 52980, is {}", + msg.states[26].sid.sat + ); + assert_eq!( + msg.states[26].state, 57, + "incorrect value for states[26].state, expected 57, is {}", + msg.states[26].state + ); + assert!( + msg.states[27].cn0.almost_eq(3.07619995117187500e+03), + "incorrect value for states[27].cn0, expected 3.07619995117187500e+03, is {:e}", + msg.states[27].cn0 + ); + assert_eq!( + msg.states[27].sid.code, 181, + "incorrect value for states[27].sid.code, expected 181, is {}", + msg.states[27].sid.code + ); + assert_eq!( + msg.states[27].sid.reserved, 175, + "incorrect value for states[27].sid.reserved, expected 175, is {}", + msg.states[27].sid.reserved + ); + assert_eq!( + msg.states[27].sid.sat, 24007, + "incorrect value for states[27].sid.sat, expected 24007, is {}", + msg.states[27].sid.sat + ); + assert_eq!( + msg.states[27].state, 165, + "incorrect value for states[27].state, expected 165, is {}", + msg.states[27].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state_dep_b() { + { + let json_input = r#"{"preamble":85,"msg_type":19,"sender":61938,"length":252,"payload":"c7fjP0SaAbdF/695K94zQyNFTvAFNRQz0zZFmYLtQpsz40dFNfKIob7NvAZGmX3/jpWa2bhF+GZfH0yaIalFg3ONGwya4chF0CyTJxczA0JF7Z/7McszY2ZFRtZXgM6aebpFDs5v2hOaealF2GLRNgKaGdtDyIVjByJmxuhEmytVhy6asapFmwNTq8ma8ehFeSvFEBOa8d5FgPU1P7Azc0JFJBQ9mTOaSYZFLlJ0jBYzkyVFsUOSYI/NTGtE3DOgyftmZsBEqMICodxmZrRERQgJfbJmRoZEuRSHuqszowRFEnybVarN0A1GOfTO/7qaaZVFpcddta8zQ0BF","crc":7174,"states":[{"state":115,"sid":{"sat":58295,"code":63,"reserved":68},"cn0":5856.2001953125},{"state":255,"sid":{"sat":31151,"code":43,"reserved":222},"cn0":2612.199951171875},{"state":78,"sid":{"sat":1520,"code":53,"reserved":20},"cn0":2925.199951171875},{"state":153,"sid":{"sat":60802,"code":66,"reserved":155},"cn0":3198.199951171875},{"state":53,"sid":{"sat":35058,"code":161,"reserved":190},"cn0":8623.2001953125},{"state":153,"sid":{"sat":65405,"code":142,"reserved":149},"cn0":5915.2001953125},{"state":248,"sid":{"sat":24422,"code":31,"reserved":76},"cn0":5412.2001953125},{"state":131,"sid":{"sat":36211,"code":27,"reserved":12},"cn0":6428.2001953125},{"state":208,"sid":{"sat":37676,"code":39,"reserved":23},"cn0":3104.199951171875},{"state":237,"sid":{"sat":64415,"code":49,"reserved":203},"cn0":3686.199951171875},{"state":70,"sid":{"sat":22486,"code":128,"reserved":206},"cn0":5967.2001953125},{"state":14,"sid":{"sat":28622,"code":218,"reserved":19},"cn0":5423.2001953125},{"state":216,"sid":{"sat":53602,"code":54,"reserved":2},"cn0":438.20001220703125},{"state":200,"sid":{"sat":25477,"code":7,"reserved":34},"cn0":1862.199951171875},{"state":155,"sid":{"sat":21803,"code":135,"reserved":46},"cn0":5462.2001953125},{"state":155,"sid":{"sat":21251,"code":171,"reserved":201},"cn0":7454.2001953125},{"state":121,"sid":{"sat":50475,"code":16,"reserved":19},"cn0":7134.2001953125},{"state":128,"sid":{"sat":13813,"code":63,"reserved":176},"cn0":3111.199951171875},{"state":36,"sid":{"sat":15636,"code":153,"reserved":51},"cn0":4297.2001953125},{"state":46,"sid":{"sat":29778,"code":140,"reserved":22},"cn0":2649.199951171875},{"state":177,"sid":{"sat":37443,"code":96,"reserved":143},"cn0":941.2000122070312},{"state":220,"sid":{"sat":41011,"code":201,"reserved":251},"cn0":1539.199951171875},{"state":168,"sid":{"sat":706,"code":161,"reserved":220},"cn0":1443.199951171875},{"state":69,"sid":{"sat":2312,"code":125,"reserved":178},"cn0":1074.199951171875},{"state":185,"sid":{"sat":34580,"code":186,"reserved":171},"cn0":2122.199951171875},{"state":18,"sid":{"sat":39804,"code":85,"reserved":170},"cn0":9076.2001953125},{"state":57,"sid":{"sat":52980,"code":255,"reserved":186},"cn0":4781.2001953125},{"state":165,"sid":{"sat":24007,"code":181,"reserved":175},"cn0":3076.199951171875}]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf1f2, + "incorrect sender id, expected 0xf1f2, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(5.85620019531250000e+03), + "incorrect value for states[0].cn0, expected 5.85620019531250000e+03, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 63, + "incorrect value for states[0].sid.code, expected 63, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 68, + "incorrect value for states[0].sid.reserved, expected 68, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 58295, + "incorrect value for states[0].sid.sat, expected 58295, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 115, + "incorrect value for states[0].state, expected 115, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(2.61219995117187500e+03), + "incorrect value for states[1].cn0, expected 2.61219995117187500e+03, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 43, + "incorrect value for states[1].sid.code, expected 43, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 222, + "incorrect value for states[1].sid.reserved, expected 222, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 31151, + "incorrect value for states[1].sid.sat, expected 31151, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 255, + "incorrect value for states[1].state, expected 255, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(2.92519995117187500e+03), + "incorrect value for states[2].cn0, expected 2.92519995117187500e+03, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 53, + "incorrect value for states[2].sid.code, expected 53, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 20, + "incorrect value for states[2].sid.reserved, expected 20, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 1520, + "incorrect value for states[2].sid.sat, expected 1520, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 78, + "incorrect value for states[2].state, expected 78, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.19819995117187500e+03), + "incorrect value for states[3].cn0, expected 3.19819995117187500e+03, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 66, + "incorrect value for states[3].sid.code, expected 66, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 155, + "incorrect value for states[3].sid.reserved, expected 155, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 60802, + "incorrect value for states[3].sid.sat, expected 60802, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 153, + "incorrect value for states[3].state, expected 153, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(8.62320019531250000e+03), + "incorrect value for states[4].cn0, expected 8.62320019531250000e+03, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 161, + "incorrect value for states[4].sid.code, expected 161, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 190, + "incorrect value for states[4].sid.reserved, expected 190, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 35058, + "incorrect value for states[4].sid.sat, expected 35058, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 53, + "incorrect value for states[4].state, expected 53, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(5.91520019531250000e+03), + "incorrect value for states[5].cn0, expected 5.91520019531250000e+03, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 142, + "incorrect value for states[5].sid.code, expected 142, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 149, + "incorrect value for states[5].sid.reserved, expected 149, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 65405, + "incorrect value for states[5].sid.sat, expected 65405, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 153, + "incorrect value for states[5].state, expected 153, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(5.41220019531250000e+03), + "incorrect value for states[6].cn0, expected 5.41220019531250000e+03, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 31, + "incorrect value for states[6].sid.code, expected 31, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 76, + "incorrect value for states[6].sid.reserved, expected 76, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 24422, + "incorrect value for states[6].sid.sat, expected 24422, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 248, + "incorrect value for states[6].state, expected 248, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(6.42820019531250000e+03), + "incorrect value for states[7].cn0, expected 6.42820019531250000e+03, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 27, + "incorrect value for states[7].sid.code, expected 27, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 12, + "incorrect value for states[7].sid.reserved, expected 12, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 36211, + "incorrect value for states[7].sid.sat, expected 36211, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 131, + "incorrect value for states[7].state, expected 131, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(3.10419995117187500e+03), + "incorrect value for states[8].cn0, expected 3.10419995117187500e+03, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 39, + "incorrect value for states[8].sid.code, expected 39, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 23, + "incorrect value for states[8].sid.reserved, expected 23, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 37676, + "incorrect value for states[8].sid.sat, expected 37676, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 208, + "incorrect value for states[8].state, expected 208, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(3.68619995117187500e+03), + "incorrect value for states[9].cn0, expected 3.68619995117187500e+03, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 49, + "incorrect value for states[9].sid.code, expected 49, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 203, + "incorrect value for states[9].sid.reserved, expected 203, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 64415, + "incorrect value for states[9].sid.sat, expected 64415, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 237, + "incorrect value for states[9].state, expected 237, is {}", + msg.states[9].state + ); + assert!( + msg.states[10].cn0.almost_eq(5.96720019531250000e+03), + "incorrect value for states[10].cn0, expected 5.96720019531250000e+03, is {:e}", + msg.states[10].cn0 + ); + assert_eq!( + msg.states[10].sid.code, 128, + "incorrect value for states[10].sid.code, expected 128, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 206, + "incorrect value for states[10].sid.reserved, expected 206, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 22486, + "incorrect value for states[10].sid.sat, expected 22486, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 70, + "incorrect value for states[10].state, expected 70, is {}", + msg.states[10].state + ); + assert!( + msg.states[11].cn0.almost_eq(5.42320019531250000e+03), + "incorrect value for states[11].cn0, expected 5.42320019531250000e+03, is {:e}", + msg.states[11].cn0 + ); + assert_eq!( + msg.states[11].sid.code, 218, + "incorrect value for states[11].sid.code, expected 218, is {}", + msg.states[11].sid.code + ); + assert_eq!( + msg.states[11].sid.reserved, 19, + "incorrect value for states[11].sid.reserved, expected 19, is {}", + msg.states[11].sid.reserved + ); + assert_eq!( + msg.states[11].sid.sat, 28622, + "incorrect value for states[11].sid.sat, expected 28622, is {}", + msg.states[11].sid.sat + ); + assert_eq!( + msg.states[11].state, 14, + "incorrect value for states[11].state, expected 14, is {}", + msg.states[11].state + ); + assert!( + msg.states[12].cn0.almost_eq(4.38200012207031250e+02), + "incorrect value for states[12].cn0, expected 4.38200012207031250e+02, is {:e}", + msg.states[12].cn0 + ); + assert_eq!( + msg.states[12].sid.code, 54, + "incorrect value for states[12].sid.code, expected 54, is {}", + msg.states[12].sid.code + ); + assert_eq!( + msg.states[12].sid.reserved, 2, + "incorrect value for states[12].sid.reserved, expected 2, is {}", + msg.states[12].sid.reserved + ); + assert_eq!( + msg.states[12].sid.sat, 53602, + "incorrect value for states[12].sid.sat, expected 53602, is {}", + msg.states[12].sid.sat + ); + assert_eq!( + msg.states[12].state, 216, + "incorrect value for states[12].state, expected 216, is {}", + msg.states[12].state + ); + assert!( + msg.states[13].cn0.almost_eq(1.86219995117187500e+03), + "incorrect value for states[13].cn0, expected 1.86219995117187500e+03, is {:e}", + msg.states[13].cn0 + ); + assert_eq!( + msg.states[13].sid.code, 7, + "incorrect value for states[13].sid.code, expected 7, is {}", + msg.states[13].sid.code + ); + assert_eq!( + msg.states[13].sid.reserved, 34, + "incorrect value for states[13].sid.reserved, expected 34, is {}", + msg.states[13].sid.reserved + ); + assert_eq!( + msg.states[13].sid.sat, 25477, + "incorrect value for states[13].sid.sat, expected 25477, is {}", + msg.states[13].sid.sat + ); + assert_eq!( + msg.states[13].state, 200, + "incorrect value for states[13].state, expected 200, is {}", + msg.states[13].state + ); + assert!( + msg.states[14].cn0.almost_eq(5.46220019531250000e+03), + "incorrect value for states[14].cn0, expected 5.46220019531250000e+03, is {:e}", + msg.states[14].cn0 + ); + assert_eq!( + msg.states[14].sid.code, 135, + "incorrect value for states[14].sid.code, expected 135, is {}", + msg.states[14].sid.code + ); + assert_eq!( + msg.states[14].sid.reserved, 46, + "incorrect value for states[14].sid.reserved, expected 46, is {}", + msg.states[14].sid.reserved + ); + assert_eq!( + msg.states[14].sid.sat, 21803, + "incorrect value for states[14].sid.sat, expected 21803, is {}", + msg.states[14].sid.sat + ); + assert_eq!( + msg.states[14].state, 155, + "incorrect value for states[14].state, expected 155, is {}", + msg.states[14].state + ); + assert!( + msg.states[15].cn0.almost_eq(7.45420019531250000e+03), + "incorrect value for states[15].cn0, expected 7.45420019531250000e+03, is {:e}", + msg.states[15].cn0 + ); + assert_eq!( + msg.states[15].sid.code, 171, + "incorrect value for states[15].sid.code, expected 171, is {}", + msg.states[15].sid.code + ); + assert_eq!( + msg.states[15].sid.reserved, 201, + "incorrect value for states[15].sid.reserved, expected 201, is {}", + msg.states[15].sid.reserved + ); + assert_eq!( + msg.states[15].sid.sat, 21251, + "incorrect value for states[15].sid.sat, expected 21251, is {}", + msg.states[15].sid.sat + ); + assert_eq!( + msg.states[15].state, 155, + "incorrect value for states[15].state, expected 155, is {}", + msg.states[15].state + ); + assert!( + msg.states[16].cn0.almost_eq(7.13420019531250000e+03), + "incorrect value for states[16].cn0, expected 7.13420019531250000e+03, is {:e}", + msg.states[16].cn0 + ); + assert_eq!( + msg.states[16].sid.code, 16, + "incorrect value for states[16].sid.code, expected 16, is {}", + msg.states[16].sid.code + ); + assert_eq!( + msg.states[16].sid.reserved, 19, + "incorrect value for states[16].sid.reserved, expected 19, is {}", + msg.states[16].sid.reserved + ); + assert_eq!( + msg.states[16].sid.sat, 50475, + "incorrect value for states[16].sid.sat, expected 50475, is {}", + msg.states[16].sid.sat + ); + assert_eq!( + msg.states[16].state, 121, + "incorrect value for states[16].state, expected 121, is {}", + msg.states[16].state + ); + assert!( + msg.states[17].cn0.almost_eq(3.11119995117187500e+03), + "incorrect value for states[17].cn0, expected 3.11119995117187500e+03, is {:e}", + msg.states[17].cn0 + ); + assert_eq!( + msg.states[17].sid.code, 63, + "incorrect value for states[17].sid.code, expected 63, is {}", + msg.states[17].sid.code + ); + assert_eq!( + msg.states[17].sid.reserved, 176, + "incorrect value for states[17].sid.reserved, expected 176, is {}", + msg.states[17].sid.reserved + ); + assert_eq!( + msg.states[17].sid.sat, 13813, + "incorrect value for states[17].sid.sat, expected 13813, is {}", + msg.states[17].sid.sat + ); + assert_eq!( + msg.states[17].state, 128, + "incorrect value for states[17].state, expected 128, is {}", + msg.states[17].state + ); + assert!( + msg.states[18].cn0.almost_eq(4.29720019531250000e+03), + "incorrect value for states[18].cn0, expected 4.29720019531250000e+03, is {:e}", + msg.states[18].cn0 + ); + assert_eq!( + msg.states[18].sid.code, 153, + "incorrect value for states[18].sid.code, expected 153, is {}", + msg.states[18].sid.code + ); + assert_eq!( + msg.states[18].sid.reserved, 51, + "incorrect value for states[18].sid.reserved, expected 51, is {}", + msg.states[18].sid.reserved + ); + assert_eq!( + msg.states[18].sid.sat, 15636, + "incorrect value for states[18].sid.sat, expected 15636, is {}", + msg.states[18].sid.sat + ); + assert_eq!( + msg.states[18].state, 36, + "incorrect value for states[18].state, expected 36, is {}", + msg.states[18].state + ); + assert!( + msg.states[19].cn0.almost_eq(2.64919995117187500e+03), + "incorrect value for states[19].cn0, expected 2.64919995117187500e+03, is {:e}", + msg.states[19].cn0 + ); + assert_eq!( + msg.states[19].sid.code, 140, + "incorrect value for states[19].sid.code, expected 140, is {}", + msg.states[19].sid.code + ); + assert_eq!( + msg.states[19].sid.reserved, 22, + "incorrect value for states[19].sid.reserved, expected 22, is {}", + msg.states[19].sid.reserved + ); + assert_eq!( + msg.states[19].sid.sat, 29778, + "incorrect value for states[19].sid.sat, expected 29778, is {}", + msg.states[19].sid.sat + ); + assert_eq!( + msg.states[19].state, 46, + "incorrect value for states[19].state, expected 46, is {}", + msg.states[19].state + ); + assert!( + msg.states[20].cn0.almost_eq(9.41200012207031250e+02), + "incorrect value for states[20].cn0, expected 9.41200012207031250e+02, is {:e}", + msg.states[20].cn0 + ); + assert_eq!( + msg.states[20].sid.code, 96, + "incorrect value for states[20].sid.code, expected 96, is {}", + msg.states[20].sid.code + ); + assert_eq!( + msg.states[20].sid.reserved, 143, + "incorrect value for states[20].sid.reserved, expected 143, is {}", + msg.states[20].sid.reserved + ); + assert_eq!( + msg.states[20].sid.sat, 37443, + "incorrect value for states[20].sid.sat, expected 37443, is {}", + msg.states[20].sid.sat + ); + assert_eq!( + msg.states[20].state, 177, + "incorrect value for states[20].state, expected 177, is {}", + msg.states[20].state + ); + assert!( + msg.states[21].cn0.almost_eq(1.53919995117187500e+03), + "incorrect value for states[21].cn0, expected 1.53919995117187500e+03, is {:e}", + msg.states[21].cn0 + ); + assert_eq!( + msg.states[21].sid.code, 201, + "incorrect value for states[21].sid.code, expected 201, is {}", + msg.states[21].sid.code + ); + assert_eq!( + msg.states[21].sid.reserved, 251, + "incorrect value for states[21].sid.reserved, expected 251, is {}", + msg.states[21].sid.reserved + ); + assert_eq!( + msg.states[21].sid.sat, 41011, + "incorrect value for states[21].sid.sat, expected 41011, is {}", + msg.states[21].sid.sat + ); + assert_eq!( + msg.states[21].state, 220, + "incorrect value for states[21].state, expected 220, is {}", + msg.states[21].state + ); + assert!( + msg.states[22].cn0.almost_eq(1.44319995117187500e+03), + "incorrect value for states[22].cn0, expected 1.44319995117187500e+03, is {:e}", + msg.states[22].cn0 + ); + assert_eq!( + msg.states[22].sid.code, 161, + "incorrect value for states[22].sid.code, expected 161, is {}", + msg.states[22].sid.code + ); + assert_eq!( + msg.states[22].sid.reserved, 220, + "incorrect value for states[22].sid.reserved, expected 220, is {}", + msg.states[22].sid.reserved + ); + assert_eq!( + msg.states[22].sid.sat, 706, + "incorrect value for states[22].sid.sat, expected 706, is {}", + msg.states[22].sid.sat + ); + assert_eq!( + msg.states[22].state, 168, + "incorrect value for states[22].state, expected 168, is {}", + msg.states[22].state + ); + assert!( + msg.states[23].cn0.almost_eq(1.07419995117187500e+03), + "incorrect value for states[23].cn0, expected 1.07419995117187500e+03, is {:e}", + msg.states[23].cn0 + ); + assert_eq!( + msg.states[23].sid.code, 125, + "incorrect value for states[23].sid.code, expected 125, is {}", + msg.states[23].sid.code + ); + assert_eq!( + msg.states[23].sid.reserved, 178, + "incorrect value for states[23].sid.reserved, expected 178, is {}", + msg.states[23].sid.reserved + ); + assert_eq!( + msg.states[23].sid.sat, 2312, + "incorrect value for states[23].sid.sat, expected 2312, is {}", + msg.states[23].sid.sat + ); + assert_eq!( + msg.states[23].state, 69, + "incorrect value for states[23].state, expected 69, is {}", + msg.states[23].state + ); + assert!( + msg.states[24].cn0.almost_eq(2.12219995117187500e+03), + "incorrect value for states[24].cn0, expected 2.12219995117187500e+03, is {:e}", + msg.states[24].cn0 + ); + assert_eq!( + msg.states[24].sid.code, 186, + "incorrect value for states[24].sid.code, expected 186, is {}", + msg.states[24].sid.code + ); + assert_eq!( + msg.states[24].sid.reserved, 171, + "incorrect value for states[24].sid.reserved, expected 171, is {}", + msg.states[24].sid.reserved + ); + assert_eq!( + msg.states[24].sid.sat, 34580, + "incorrect value for states[24].sid.sat, expected 34580, is {}", + msg.states[24].sid.sat + ); + assert_eq!( + msg.states[24].state, 185, + "incorrect value for states[24].state, expected 185, is {}", + msg.states[24].state + ); + assert!( + msg.states[25].cn0.almost_eq(9.07620019531250000e+03), + "incorrect value for states[25].cn0, expected 9.07620019531250000e+03, is {:e}", + msg.states[25].cn0 + ); + assert_eq!( + msg.states[25].sid.code, 85, + "incorrect value for states[25].sid.code, expected 85, is {}", + msg.states[25].sid.code + ); + assert_eq!( + msg.states[25].sid.reserved, 170, + "incorrect value for states[25].sid.reserved, expected 170, is {}", + msg.states[25].sid.reserved + ); + assert_eq!( + msg.states[25].sid.sat, 39804, + "incorrect value for states[25].sid.sat, expected 39804, is {}", + msg.states[25].sid.sat + ); + assert_eq!( + msg.states[25].state, 18, + "incorrect value for states[25].state, expected 18, is {}", + msg.states[25].state + ); + assert!( + msg.states[26].cn0.almost_eq(4.78120019531250000e+03), + "incorrect value for states[26].cn0, expected 4.78120019531250000e+03, is {:e}", + msg.states[26].cn0 + ); + assert_eq!( + msg.states[26].sid.code, 255, + "incorrect value for states[26].sid.code, expected 255, is {}", + msg.states[26].sid.code + ); + assert_eq!( + msg.states[26].sid.reserved, 186, + "incorrect value for states[26].sid.reserved, expected 186, is {}", + msg.states[26].sid.reserved + ); + assert_eq!( + msg.states[26].sid.sat, 52980, + "incorrect value for states[26].sid.sat, expected 52980, is {}", + msg.states[26].sid.sat + ); + assert_eq!( + msg.states[26].state, 57, + "incorrect value for states[26].state, expected 57, is {}", + msg.states[26].state + ); + assert!( + msg.states[27].cn0.almost_eq(3.07619995117187500e+03), + "incorrect value for states[27].cn0, expected 3.07619995117187500e+03, is {:e}", + msg.states[27].cn0 + ); + assert_eq!( + msg.states[27].sid.code, 181, + "incorrect value for states[27].sid.code, expected 181, is {}", + msg.states[27].sid.code + ); + assert_eq!( + msg.states[27].sid.reserved, 175, + "incorrect value for states[27].sid.reserved, expected 175, is {}", + msg.states[27].sid.reserved + ); + assert_eq!( + msg.states[27].sid.sat, 24007, + "incorrect value for states[27].sid.sat, expected 24007, is {}", + msg.states[27].sid.sat + ); + assert_eq!( + msg.states[27].state, 165, + "incorrect value for states[27].state, expected 165, is {}", + msg.states[27].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_state_dep_b`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_state_dep_b() { + { + let mut payload = Cursor::new(vec![ + 85, 19, 0, 242, 241, 252, 115, 183, 227, 63, 68, 154, 1, 183, 69, 255, 175, 121, 43, + 222, 51, 67, 35, 69, 78, 240, 5, 53, 20, 51, 211, 54, 69, 153, 130, 237, 66, 155, 51, + 227, 71, 69, 53, 242, 136, 161, 190, 205, 188, 6, 70, 153, 125, 255, 142, 149, 154, + 217, 184, 69, 248, 102, 95, 31, 76, 154, 33, 169, 69, 131, 115, 141, 27, 12, 154, 225, + 200, 69, 208, 44, 147, 39, 23, 51, 3, 66, 69, 237, 159, 251, 49, 203, 51, 99, 102, 69, + 70, 214, 87, 128, 206, 154, 121, 186, 69, 14, 206, 111, 218, 19, 154, 121, 169, 69, + 216, 98, 209, 54, 2, 154, 25, 219, 67, 200, 133, 99, 7, 34, 102, 198, 232, 68, 155, 43, + 85, 135, 46, 154, 177, 170, 69, 155, 3, 83, 171, 201, 154, 241, 232, 69, 121, 43, 197, + 16, 19, 154, 241, 222, 69, 128, 245, 53, 63, 176, 51, 115, 66, 69, 36, 20, 61, 153, 51, + 154, 73, 134, 69, 46, 82, 116, 140, 22, 51, 147, 37, 69, 177, 67, 146, 96, 143, 205, + 76, 107, 68, 220, 51, 160, 201, 251, 102, 102, 192, 68, 168, 194, 2, 161, 220, 102, + 102, 180, 68, 69, 8, 9, 125, 178, 102, 70, 134, 68, 185, 20, 135, 186, 171, 51, 163, 4, + 69, 18, 124, 155, 85, 170, 205, 208, 13, 70, 57, 244, 206, 255, 186, 154, 105, 149, 69, + 165, 199, 93, 181, 175, 51, 67, 64, 69, 6, 28, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingStateDepB( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDepB(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x13, + "Incorrect message type, expected 0x13, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0xf1f2, + "incorrect sender id, expected 0xf1f2, is {sender_id}" + ); + assert!( + msg.states[0].cn0.almost_eq(5.85620019531250000e+03), + "incorrect value for states[0].cn0, expected 5.85620019531250000e+03, is {:e}", + msg.states[0].cn0 + ); + assert_eq!( + msg.states[0].sid.code, 63, + "incorrect value for states[0].sid.code, expected 63, is {}", + msg.states[0].sid.code + ); + assert_eq!( + msg.states[0].sid.reserved, 68, + "incorrect value for states[0].sid.reserved, expected 68, is {}", + msg.states[0].sid.reserved + ); + assert_eq!( + msg.states[0].sid.sat, 58295, + "incorrect value for states[0].sid.sat, expected 58295, is {}", + msg.states[0].sid.sat + ); + assert_eq!( + msg.states[0].state, 115, + "incorrect value for states[0].state, expected 115, is {}", + msg.states[0].state + ); + assert!( + msg.states[1].cn0.almost_eq(2.61219995117187500e+03), + "incorrect value for states[1].cn0, expected 2.61219995117187500e+03, is {:e}", + msg.states[1].cn0 + ); + assert_eq!( + msg.states[1].sid.code, 43, + "incorrect value for states[1].sid.code, expected 43, is {}", + msg.states[1].sid.code + ); + assert_eq!( + msg.states[1].sid.reserved, 222, + "incorrect value for states[1].sid.reserved, expected 222, is {}", + msg.states[1].sid.reserved + ); + assert_eq!( + msg.states[1].sid.sat, 31151, + "incorrect value for states[1].sid.sat, expected 31151, is {}", + msg.states[1].sid.sat + ); + assert_eq!( + msg.states[1].state, 255, + "incorrect value for states[1].state, expected 255, is {}", + msg.states[1].state + ); + assert!( + msg.states[2].cn0.almost_eq(2.92519995117187500e+03), + "incorrect value for states[2].cn0, expected 2.92519995117187500e+03, is {:e}", + msg.states[2].cn0 + ); + assert_eq!( + msg.states[2].sid.code, 53, + "incorrect value for states[2].sid.code, expected 53, is {}", + msg.states[2].sid.code + ); + assert_eq!( + msg.states[2].sid.reserved, 20, + "incorrect value for states[2].sid.reserved, expected 20, is {}", + msg.states[2].sid.reserved + ); + assert_eq!( + msg.states[2].sid.sat, 1520, + "incorrect value for states[2].sid.sat, expected 1520, is {}", + msg.states[2].sid.sat + ); + assert_eq!( + msg.states[2].state, 78, + "incorrect value for states[2].state, expected 78, is {}", + msg.states[2].state + ); + assert!( + msg.states[3].cn0.almost_eq(3.19819995117187500e+03), + "incorrect value for states[3].cn0, expected 3.19819995117187500e+03, is {:e}", + msg.states[3].cn0 + ); + assert_eq!( + msg.states[3].sid.code, 66, + "incorrect value for states[3].sid.code, expected 66, is {}", + msg.states[3].sid.code + ); + assert_eq!( + msg.states[3].sid.reserved, 155, + "incorrect value for states[3].sid.reserved, expected 155, is {}", + msg.states[3].sid.reserved + ); + assert_eq!( + msg.states[3].sid.sat, 60802, + "incorrect value for states[3].sid.sat, expected 60802, is {}", + msg.states[3].sid.sat + ); + assert_eq!( + msg.states[3].state, 153, + "incorrect value for states[3].state, expected 153, is {}", + msg.states[3].state + ); + assert!( + msg.states[4].cn0.almost_eq(8.62320019531250000e+03), + "incorrect value for states[4].cn0, expected 8.62320019531250000e+03, is {:e}", + msg.states[4].cn0 + ); + assert_eq!( + msg.states[4].sid.code, 161, + "incorrect value for states[4].sid.code, expected 161, is {}", + msg.states[4].sid.code + ); + assert_eq!( + msg.states[4].sid.reserved, 190, + "incorrect value for states[4].sid.reserved, expected 190, is {}", + msg.states[4].sid.reserved + ); + assert_eq!( + msg.states[4].sid.sat, 35058, + "incorrect value for states[4].sid.sat, expected 35058, is {}", + msg.states[4].sid.sat + ); + assert_eq!( + msg.states[4].state, 53, + "incorrect value for states[4].state, expected 53, is {}", + msg.states[4].state + ); + assert!( + msg.states[5].cn0.almost_eq(5.91520019531250000e+03), + "incorrect value for states[5].cn0, expected 5.91520019531250000e+03, is {:e}", + msg.states[5].cn0 + ); + assert_eq!( + msg.states[5].sid.code, 142, + "incorrect value for states[5].sid.code, expected 142, is {}", + msg.states[5].sid.code + ); + assert_eq!( + msg.states[5].sid.reserved, 149, + "incorrect value for states[5].sid.reserved, expected 149, is {}", + msg.states[5].sid.reserved + ); + assert_eq!( + msg.states[5].sid.sat, 65405, + "incorrect value for states[5].sid.sat, expected 65405, is {}", + msg.states[5].sid.sat + ); + assert_eq!( + msg.states[5].state, 153, + "incorrect value for states[5].state, expected 153, is {}", + msg.states[5].state + ); + assert!( + msg.states[6].cn0.almost_eq(5.41220019531250000e+03), + "incorrect value for states[6].cn0, expected 5.41220019531250000e+03, is {:e}", + msg.states[6].cn0 + ); + assert_eq!( + msg.states[6].sid.code, 31, + "incorrect value for states[6].sid.code, expected 31, is {}", + msg.states[6].sid.code + ); + assert_eq!( + msg.states[6].sid.reserved, 76, + "incorrect value for states[6].sid.reserved, expected 76, is {}", + msg.states[6].sid.reserved + ); + assert_eq!( + msg.states[6].sid.sat, 24422, + "incorrect value for states[6].sid.sat, expected 24422, is {}", + msg.states[6].sid.sat + ); + assert_eq!( + msg.states[6].state, 248, + "incorrect value for states[6].state, expected 248, is {}", + msg.states[6].state + ); + assert!( + msg.states[7].cn0.almost_eq(6.42820019531250000e+03), + "incorrect value for states[7].cn0, expected 6.42820019531250000e+03, is {:e}", + msg.states[7].cn0 + ); + assert_eq!( + msg.states[7].sid.code, 27, + "incorrect value for states[7].sid.code, expected 27, is {}", + msg.states[7].sid.code + ); + assert_eq!( + msg.states[7].sid.reserved, 12, + "incorrect value for states[7].sid.reserved, expected 12, is {}", + msg.states[7].sid.reserved + ); + assert_eq!( + msg.states[7].sid.sat, 36211, + "incorrect value for states[7].sid.sat, expected 36211, is {}", + msg.states[7].sid.sat + ); + assert_eq!( + msg.states[7].state, 131, + "incorrect value for states[7].state, expected 131, is {}", + msg.states[7].state + ); + assert!( + msg.states[8].cn0.almost_eq(3.10419995117187500e+03), + "incorrect value for states[8].cn0, expected 3.10419995117187500e+03, is {:e}", + msg.states[8].cn0 + ); + assert_eq!( + msg.states[8].sid.code, 39, + "incorrect value for states[8].sid.code, expected 39, is {}", + msg.states[8].sid.code + ); + assert_eq!( + msg.states[8].sid.reserved, 23, + "incorrect value for states[8].sid.reserved, expected 23, is {}", + msg.states[8].sid.reserved + ); + assert_eq!( + msg.states[8].sid.sat, 37676, + "incorrect value for states[8].sid.sat, expected 37676, is {}", + msg.states[8].sid.sat + ); + assert_eq!( + msg.states[8].state, 208, + "incorrect value for states[8].state, expected 208, is {}", + msg.states[8].state + ); + assert!( + msg.states[9].cn0.almost_eq(3.68619995117187500e+03), + "incorrect value for states[9].cn0, expected 3.68619995117187500e+03, is {:e}", + msg.states[9].cn0 + ); + assert_eq!( + msg.states[9].sid.code, 49, + "incorrect value for states[9].sid.code, expected 49, is {}", + msg.states[9].sid.code + ); + assert_eq!( + msg.states[9].sid.reserved, 203, + "incorrect value for states[9].sid.reserved, expected 203, is {}", + msg.states[9].sid.reserved + ); + assert_eq!( + msg.states[9].sid.sat, 64415, + "incorrect value for states[9].sid.sat, expected 64415, is {}", + msg.states[9].sid.sat + ); + assert_eq!( + msg.states[9].state, 237, + "incorrect value for states[9].state, expected 237, is {}", + msg.states[9].state + ); + assert!( + msg.states[10].cn0.almost_eq(5.96720019531250000e+03), + "incorrect value for states[10].cn0, expected 5.96720019531250000e+03, is {:e}", + msg.states[10].cn0 + ); + assert_eq!( + msg.states[10].sid.code, 128, + "incorrect value for states[10].sid.code, expected 128, is {}", + msg.states[10].sid.code + ); + assert_eq!( + msg.states[10].sid.reserved, 206, + "incorrect value for states[10].sid.reserved, expected 206, is {}", + msg.states[10].sid.reserved + ); + assert_eq!( + msg.states[10].sid.sat, 22486, + "incorrect value for states[10].sid.sat, expected 22486, is {}", + msg.states[10].sid.sat + ); + assert_eq!( + msg.states[10].state, 70, + "incorrect value for states[10].state, expected 70, is {}", + msg.states[10].state + ); + assert!( + msg.states[11].cn0.almost_eq(5.42320019531250000e+03), + "incorrect value for states[11].cn0, expected 5.42320019531250000e+03, is {:e}", + msg.states[11].cn0 + ); + assert_eq!( + msg.states[11].sid.code, 218, + "incorrect value for states[11].sid.code, expected 218, is {}", + msg.states[11].sid.code + ); + assert_eq!( + msg.states[11].sid.reserved, 19, + "incorrect value for states[11].sid.reserved, expected 19, is {}", + msg.states[11].sid.reserved + ); + assert_eq!( + msg.states[11].sid.sat, 28622, + "incorrect value for states[11].sid.sat, expected 28622, is {}", + msg.states[11].sid.sat + ); + assert_eq!( + msg.states[11].state, 14, + "incorrect value for states[11].state, expected 14, is {}", + msg.states[11].state + ); + assert!( + msg.states[12].cn0.almost_eq(4.38200012207031250e+02), + "incorrect value for states[12].cn0, expected 4.38200012207031250e+02, is {:e}", + msg.states[12].cn0 + ); + assert_eq!( + msg.states[12].sid.code, 54, + "incorrect value for states[12].sid.code, expected 54, is {}", + msg.states[12].sid.code + ); + assert_eq!( + msg.states[12].sid.reserved, 2, + "incorrect value for states[12].sid.reserved, expected 2, is {}", + msg.states[12].sid.reserved + ); + assert_eq!( + msg.states[12].sid.sat, 53602, + "incorrect value for states[12].sid.sat, expected 53602, is {}", + msg.states[12].sid.sat + ); + assert_eq!( + msg.states[12].state, 216, + "incorrect value for states[12].state, expected 216, is {}", + msg.states[12].state + ); + assert!( + msg.states[13].cn0.almost_eq(1.86219995117187500e+03), + "incorrect value for states[13].cn0, expected 1.86219995117187500e+03, is {:e}", + msg.states[13].cn0 + ); + assert_eq!( + msg.states[13].sid.code, 7, + "incorrect value for states[13].sid.code, expected 7, is {}", + msg.states[13].sid.code + ); + assert_eq!( + msg.states[13].sid.reserved, 34, + "incorrect value for states[13].sid.reserved, expected 34, is {}", + msg.states[13].sid.reserved + ); + assert_eq!( + msg.states[13].sid.sat, 25477, + "incorrect value for states[13].sid.sat, expected 25477, is {}", + msg.states[13].sid.sat + ); + assert_eq!( + msg.states[13].state, 200, + "incorrect value for states[13].state, expected 200, is {}", + msg.states[13].state + ); + assert!( + msg.states[14].cn0.almost_eq(5.46220019531250000e+03), + "incorrect value for states[14].cn0, expected 5.46220019531250000e+03, is {:e}", + msg.states[14].cn0 + ); + assert_eq!( + msg.states[14].sid.code, 135, + "incorrect value for states[14].sid.code, expected 135, is {}", + msg.states[14].sid.code + ); + assert_eq!( + msg.states[14].sid.reserved, 46, + "incorrect value for states[14].sid.reserved, expected 46, is {}", + msg.states[14].sid.reserved + ); + assert_eq!( + msg.states[14].sid.sat, 21803, + "incorrect value for states[14].sid.sat, expected 21803, is {}", + msg.states[14].sid.sat + ); + assert_eq!( + msg.states[14].state, 155, + "incorrect value for states[14].state, expected 155, is {}", + msg.states[14].state + ); + assert!( + msg.states[15].cn0.almost_eq(7.45420019531250000e+03), + "incorrect value for states[15].cn0, expected 7.45420019531250000e+03, is {:e}", + msg.states[15].cn0 + ); + assert_eq!( + msg.states[15].sid.code, 171, + "incorrect value for states[15].sid.code, expected 171, is {}", + msg.states[15].sid.code + ); + assert_eq!( + msg.states[15].sid.reserved, 201, + "incorrect value for states[15].sid.reserved, expected 201, is {}", + msg.states[15].sid.reserved + ); + assert_eq!( + msg.states[15].sid.sat, 21251, + "incorrect value for states[15].sid.sat, expected 21251, is {}", + msg.states[15].sid.sat + ); + assert_eq!( + msg.states[15].state, 155, + "incorrect value for states[15].state, expected 155, is {}", + msg.states[15].state + ); + assert!( + msg.states[16].cn0.almost_eq(7.13420019531250000e+03), + "incorrect value for states[16].cn0, expected 7.13420019531250000e+03, is {:e}", + msg.states[16].cn0 + ); + assert_eq!( + msg.states[16].sid.code, 16, + "incorrect value for states[16].sid.code, expected 16, is {}", + msg.states[16].sid.code + ); + assert_eq!( + msg.states[16].sid.reserved, 19, + "incorrect value for states[16].sid.reserved, expected 19, is {}", + msg.states[16].sid.reserved + ); + assert_eq!( + msg.states[16].sid.sat, 50475, + "incorrect value for states[16].sid.sat, expected 50475, is {}", + msg.states[16].sid.sat + ); + assert_eq!( + msg.states[16].state, 121, + "incorrect value for states[16].state, expected 121, is {}", + msg.states[16].state + ); + assert!( + msg.states[17].cn0.almost_eq(3.11119995117187500e+03), + "incorrect value for states[17].cn0, expected 3.11119995117187500e+03, is {:e}", + msg.states[17].cn0 + ); + assert_eq!( + msg.states[17].sid.code, 63, + "incorrect value for states[17].sid.code, expected 63, is {}", + msg.states[17].sid.code + ); + assert_eq!( + msg.states[17].sid.reserved, 176, + "incorrect value for states[17].sid.reserved, expected 176, is {}", + msg.states[17].sid.reserved + ); + assert_eq!( + msg.states[17].sid.sat, 13813, + "incorrect value for states[17].sid.sat, expected 13813, is {}", + msg.states[17].sid.sat + ); + assert_eq!( + msg.states[17].state, 128, + "incorrect value for states[17].state, expected 128, is {}", + msg.states[17].state + ); + assert!( + msg.states[18].cn0.almost_eq(4.29720019531250000e+03), + "incorrect value for states[18].cn0, expected 4.29720019531250000e+03, is {:e}", + msg.states[18].cn0 + ); + assert_eq!( + msg.states[18].sid.code, 153, + "incorrect value for states[18].sid.code, expected 153, is {}", + msg.states[18].sid.code + ); + assert_eq!( + msg.states[18].sid.reserved, 51, + "incorrect value for states[18].sid.reserved, expected 51, is {}", + msg.states[18].sid.reserved + ); + assert_eq!( + msg.states[18].sid.sat, 15636, + "incorrect value for states[18].sid.sat, expected 15636, is {}", + msg.states[18].sid.sat + ); + assert_eq!( + msg.states[18].state, 36, + "incorrect value for states[18].state, expected 36, is {}", + msg.states[18].state + ); + assert!( + msg.states[19].cn0.almost_eq(2.64919995117187500e+03), + "incorrect value for states[19].cn0, expected 2.64919995117187500e+03, is {:e}", + msg.states[19].cn0 + ); + assert_eq!( + msg.states[19].sid.code, 140, + "incorrect value for states[19].sid.code, expected 140, is {}", + msg.states[19].sid.code + ); + assert_eq!( + msg.states[19].sid.reserved, 22, + "incorrect value for states[19].sid.reserved, expected 22, is {}", + msg.states[19].sid.reserved + ); + assert_eq!( + msg.states[19].sid.sat, 29778, + "incorrect value for states[19].sid.sat, expected 29778, is {}", + msg.states[19].sid.sat + ); + assert_eq!( + msg.states[19].state, 46, + "incorrect value for states[19].state, expected 46, is {}", + msg.states[19].state + ); + assert!( + msg.states[20].cn0.almost_eq(9.41200012207031250e+02), + "incorrect value for states[20].cn0, expected 9.41200012207031250e+02, is {:e}", + msg.states[20].cn0 + ); + assert_eq!( + msg.states[20].sid.code, 96, + "incorrect value for states[20].sid.code, expected 96, is {}", + msg.states[20].sid.code + ); + assert_eq!( + msg.states[20].sid.reserved, 143, + "incorrect value for states[20].sid.reserved, expected 143, is {}", + msg.states[20].sid.reserved + ); + assert_eq!( + msg.states[20].sid.sat, 37443, + "incorrect value for states[20].sid.sat, expected 37443, is {}", + msg.states[20].sid.sat + ); + assert_eq!( + msg.states[20].state, 177, + "incorrect value for states[20].state, expected 177, is {}", + msg.states[20].state + ); + assert!( + msg.states[21].cn0.almost_eq(1.53919995117187500e+03), + "incorrect value for states[21].cn0, expected 1.53919995117187500e+03, is {:e}", + msg.states[21].cn0 + ); + assert_eq!( + msg.states[21].sid.code, 201, + "incorrect value for states[21].sid.code, expected 201, is {}", + msg.states[21].sid.code + ); + assert_eq!( + msg.states[21].sid.reserved, 251, + "incorrect value for states[21].sid.reserved, expected 251, is {}", + msg.states[21].sid.reserved + ); + assert_eq!( + msg.states[21].sid.sat, 41011, + "incorrect value for states[21].sid.sat, expected 41011, is {}", + msg.states[21].sid.sat + ); + assert_eq!( + msg.states[21].state, 220, + "incorrect value for states[21].state, expected 220, is {}", + msg.states[21].state + ); + assert!( + msg.states[22].cn0.almost_eq(1.44319995117187500e+03), + "incorrect value for states[22].cn0, expected 1.44319995117187500e+03, is {:e}", + msg.states[22].cn0 + ); + assert_eq!( + msg.states[22].sid.code, 161, + "incorrect value for states[22].sid.code, expected 161, is {}", + msg.states[22].sid.code + ); + assert_eq!( + msg.states[22].sid.reserved, 220, + "incorrect value for states[22].sid.reserved, expected 220, is {}", + msg.states[22].sid.reserved + ); + assert_eq!( + msg.states[22].sid.sat, 706, + "incorrect value for states[22].sid.sat, expected 706, is {}", + msg.states[22].sid.sat + ); + assert_eq!( + msg.states[22].state, 168, + "incorrect value for states[22].state, expected 168, is {}", + msg.states[22].state + ); + assert!( + msg.states[23].cn0.almost_eq(1.07419995117187500e+03), + "incorrect value for states[23].cn0, expected 1.07419995117187500e+03, is {:e}", + msg.states[23].cn0 + ); + assert_eq!( + msg.states[23].sid.code, 125, + "incorrect value for states[23].sid.code, expected 125, is {}", + msg.states[23].sid.code + ); + assert_eq!( + msg.states[23].sid.reserved, 178, + "incorrect value for states[23].sid.reserved, expected 178, is {}", + msg.states[23].sid.reserved + ); + assert_eq!( + msg.states[23].sid.sat, 2312, + "incorrect value for states[23].sid.sat, expected 2312, is {}", + msg.states[23].sid.sat + ); + assert_eq!( + msg.states[23].state, 69, + "incorrect value for states[23].state, expected 69, is {}", + msg.states[23].state + ); + assert!( + msg.states[24].cn0.almost_eq(2.12219995117187500e+03), + "incorrect value for states[24].cn0, expected 2.12219995117187500e+03, is {:e}", + msg.states[24].cn0 + ); + assert_eq!( + msg.states[24].sid.code, 186, + "incorrect value for states[24].sid.code, expected 186, is {}", + msg.states[24].sid.code + ); + assert_eq!( + msg.states[24].sid.reserved, 171, + "incorrect value for states[24].sid.reserved, expected 171, is {}", + msg.states[24].sid.reserved + ); + assert_eq!( + msg.states[24].sid.sat, 34580, + "incorrect value for states[24].sid.sat, expected 34580, is {}", + msg.states[24].sid.sat + ); + assert_eq!( + msg.states[24].state, 185, + "incorrect value for states[24].state, expected 185, is {}", + msg.states[24].state + ); + assert!( + msg.states[25].cn0.almost_eq(9.07620019531250000e+03), + "incorrect value for states[25].cn0, expected 9.07620019531250000e+03, is {:e}", + msg.states[25].cn0 + ); + assert_eq!( + msg.states[25].sid.code, 85, + "incorrect value for states[25].sid.code, expected 85, is {}", + msg.states[25].sid.code + ); + assert_eq!( + msg.states[25].sid.reserved, 170, + "incorrect value for states[25].sid.reserved, expected 170, is {}", + msg.states[25].sid.reserved + ); + assert_eq!( + msg.states[25].sid.sat, 39804, + "incorrect value for states[25].sid.sat, expected 39804, is {}", + msg.states[25].sid.sat + ); + assert_eq!( + msg.states[25].state, 18, + "incorrect value for states[25].state, expected 18, is {}", + msg.states[25].state + ); + assert!( + msg.states[26].cn0.almost_eq(4.78120019531250000e+03), + "incorrect value for states[26].cn0, expected 4.78120019531250000e+03, is {:e}", + msg.states[26].cn0 + ); + assert_eq!( + msg.states[26].sid.code, 255, + "incorrect value for states[26].sid.code, expected 255, is {}", + msg.states[26].sid.code + ); + assert_eq!( + msg.states[26].sid.reserved, 186, + "incorrect value for states[26].sid.reserved, expected 186, is {}", + msg.states[26].sid.reserved + ); + assert_eq!( + msg.states[26].sid.sat, 52980, + "incorrect value for states[26].sid.sat, expected 52980, is {}", + msg.states[26].sid.sat + ); + assert_eq!( + msg.states[26].state, 57, + "incorrect value for states[26].state, expected 57, is {}", + msg.states[26].state + ); + assert!( + msg.states[27].cn0.almost_eq(3.07619995117187500e+03), + "incorrect value for states[27].cn0, expected 3.07619995117187500e+03, is {:e}", + msg.states[27].cn0 + ); + assert_eq!( + msg.states[27].sid.code, 181, + "incorrect value for states[27].sid.code, expected 181, is {}", + msg.states[27].sid.code + ); + assert_eq!( + msg.states[27].sid.reserved, 175, + "incorrect value for states[27].sid.reserved, expected 175, is {}", + msg.states[27].sid.reserved + ); + assert_eq!( + msg.states[27].sid.sat, 24007, + "incorrect value for states[27].sid.sat, expected 24007, is {}", + msg.states[27].sid.sat + ); + assert_eq!( + msg.states[27].state, 165, + "incorrect value for states[27].state, expected 165, is {}", + msg.states[27].state + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDepB"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a.rs new file mode 100644 index 0000000000..dbb1f93a61 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a.rs @@ -0,0 +1,548 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, 0, 133, 100, 71, 94, 192, 2, 160, + 207, 212, 255, 135, 139, 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, 59, + 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, 15, 91, 249, 117, 142, 90, 219, + 67, 25, 83, 62, 122, 100, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDetailedDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x21, + "Incorrect message type, expected 0x21, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6e9b, + "incorrect sender id, expected 0x6e9b, is {sender_id}" + ); + assert_eq!( + msg.l.f, 204, + "incorrect value for l.f, expected 204, is {}", + msg.l.f + ); + assert_eq!( + msg.l.i, -1601767965, + "incorrect value for l.i, expected -1601767965, is {}", + msg.l.i + ); + assert_eq!( + msg.p, 1044286343, + "incorrect value for p, expected 1044286343, is {}", + msg.p + ); + assert_eq!( + msg.p_std, 21427, + "incorrect value for p_std, expected 21427, is {}", + msg.p_std + ); + assert_eq!( + msg.acceleration, -114, + "incorrect value for acceleration, expected -114, is {}", + msg.acceleration + ); + assert_eq!( + msg.clock_drift, 23311, + "incorrect value for clock_drift, expected 23311, is {}", + msg.clock_drift + ); + assert_eq!( + msg.clock_offset, 6012, + "incorrect value for clock_offset, expected 6012, is {}", + msg.clock_offset + ); + assert_eq!( + msg.cn0, 78, + "incorrect value for cn0, expected 78, is {}", + msg.cn0 + ); + assert_eq!( + msg.corr_spacing, 30201, + "incorrect value for corr_spacing, expected 30201, is {}", + msg.corr_spacing + ); + assert_eq!( + msg.doppler, 1459556257, + "incorrect value for doppler, expected 1459556257, is {}", + msg.doppler + ); + assert_eq!( + msg.doppler_std, 63677, + "incorrect value for doppler_std, expected 63677, is {}", + msg.doppler_std + ); + assert_eq!( + msg.lock, 65375, + "incorrect value for lock, expected 65375, is {}", + msg.lock + ); + assert_eq!( + msg.misc_flags, 62, + "incorrect value for misc_flags, expected 62, is {}", + msg.misc_flags + ); + assert_eq!( + msg.nav_flags, 25, + "incorrect value for nav_flags, expected 25, is {}", + msg.nav_flags + ); + assert_eq!( + msg.pset_flags, 83, + "incorrect value for pset_flags, expected 83, is {}", + msg.pset_flags + ); + assert_eq!( + msg.recv_time, 941247176494, + "incorrect value for recv_time, expected 941247176494, is {}", + msg.recv_time + ); + assert_eq!( + msg.sid.code, 59, + "incorrect value for sid.code, expected 59, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 38, + "incorrect value for sid.sat, expected 38, is {}", + msg.sid.sat + ); + assert_eq!( + msg.sync_flags, 90, + "incorrect value for sync_flags, expected 90, is {}", + msg.sync_flags + ); + assert_eq!( + msg.tot.ns_residual, -811597120, + "incorrect value for tot.ns_residual, expected -811597120, is {}", + msg.tot.ns_residual + ); + assert_eq!( + msg.tot.tow, 1581737093, + "incorrect value for tot.tow, expected 1581737093, is {}", + msg.tot.tow + ); + assert_eq!( + msg.tot.wn, 65492, + "incorrect value for tot.wn, expected 65492, is {}", + msg.tot.wn + ); + assert_eq!( + msg.tow_flags, 219, + "incorrect value for tow_flags, expected 219, is {}", + msg.tow_flags + ); + assert_eq!( + msg.track_flags, 67, + "incorrect value for track_flags, expected 67, is {}", + msg.track_flags + ); + assert_eq!( + msg.uptime, 3263741727, + "incorrect value for uptime, expected 3263741727, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDetailedDepA"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a() { + { + let json_input = r#"{"crc":25722,"length":57,"msg_type":33,"payload":"Lh+0JtsAAACFZEdewAKgz9T/h4s+PrNT4/WGoMxOX/8mO6EP/1a9+B+/iMJ8Fw9b+XWOWttDGVM+","preamble":85,"sender":28315,"recv_time":941247176494,"tot":{"tow":1581737093,"ns_residual":-811597120,"wn":65492},"P":1044286343,"P_std":21427,"L":{"i":-1601767965,"f":204},"cn0":78,"lock":65375,"sid":{"sat":38,"code":59},"doppler":1459556257,"doppler_std":63677,"uptime":3263741727,"clock_offset":6012,"clock_drift":23311,"corr_spacing":30201,"acceleration":-114,"sync_flags":90,"tow_flags":219,"track_flags":67,"nav_flags":25,"pset_flags":83,"misc_flags":62}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDetailedDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x21, + "Incorrect message type, expected 0x21, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6e9b, + "incorrect sender id, expected 0x6e9b, is {sender_id}" + ); + assert_eq!( + msg.l.f, 204, + "incorrect value for l.f, expected 204, is {}", + msg.l.f + ); + assert_eq!( + msg.l.i, -1601767965, + "incorrect value for l.i, expected -1601767965, is {}", + msg.l.i + ); + assert_eq!( + msg.p, 1044286343, + "incorrect value for p, expected 1044286343, is {}", + msg.p + ); + assert_eq!( + msg.p_std, 21427, + "incorrect value for p_std, expected 21427, is {}", + msg.p_std + ); + assert_eq!( + msg.acceleration, -114, + "incorrect value for acceleration, expected -114, is {}", + msg.acceleration + ); + assert_eq!( + msg.clock_drift, 23311, + "incorrect value for clock_drift, expected 23311, is {}", + msg.clock_drift + ); + assert_eq!( + msg.clock_offset, 6012, + "incorrect value for clock_offset, expected 6012, is {}", + msg.clock_offset + ); + assert_eq!( + msg.cn0, 78, + "incorrect value for cn0, expected 78, is {}", + msg.cn0 + ); + assert_eq!( + msg.corr_spacing, 30201, + "incorrect value for corr_spacing, expected 30201, is {}", + msg.corr_spacing + ); + assert_eq!( + msg.doppler, 1459556257, + "incorrect value for doppler, expected 1459556257, is {}", + msg.doppler + ); + assert_eq!( + msg.doppler_std, 63677, + "incorrect value for doppler_std, expected 63677, is {}", + msg.doppler_std + ); + assert_eq!( + msg.lock, 65375, + "incorrect value for lock, expected 65375, is {}", + msg.lock + ); + assert_eq!( + msg.misc_flags, 62, + "incorrect value for misc_flags, expected 62, is {}", + msg.misc_flags + ); + assert_eq!( + msg.nav_flags, 25, + "incorrect value for nav_flags, expected 25, is {}", + msg.nav_flags + ); + assert_eq!( + msg.pset_flags, 83, + "incorrect value for pset_flags, expected 83, is {}", + msg.pset_flags + ); + assert_eq!( + msg.recv_time, 941247176494, + "incorrect value for recv_time, expected 941247176494, is {}", + msg.recv_time + ); + assert_eq!( + msg.sid.code, 59, + "incorrect value for sid.code, expected 59, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 38, + "incorrect value for sid.sat, expected 38, is {}", + msg.sid.sat + ); + assert_eq!( + msg.sync_flags, 90, + "incorrect value for sync_flags, expected 90, is {}", + msg.sync_flags + ); + assert_eq!( + msg.tot.ns_residual, -811597120, + "incorrect value for tot.ns_residual, expected -811597120, is {}", + msg.tot.ns_residual + ); + assert_eq!( + msg.tot.tow, 1581737093, + "incorrect value for tot.tow, expected 1581737093, is {}", + msg.tot.tow + ); + assert_eq!( + msg.tot.wn, 65492, + "incorrect value for tot.wn, expected 65492, is {}", + msg.tot.wn + ); + assert_eq!( + msg.tow_flags, 219, + "incorrect value for tow_flags, expected 219, is {}", + msg.tow_flags + ); + assert_eq!( + msg.track_flags, 67, + "incorrect value for track_flags, expected 67, is {}", + msg.track_flags + ); + assert_eq!( + msg.uptime, 3263741727, + "incorrect value for uptime, expected 3263741727, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDetailedDepA"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a() { + { + let mut payload = Cursor::new(vec![ + 85, 33, 0, 155, 110, 57, 46, 31, 180, 38, 219, 0, 0, 0, 133, 100, 71, 94, 192, 2, 160, + 207, 212, 255, 135, 139, 62, 62, 179, 83, 227, 245, 134, 160, 204, 78, 95, 255, 38, 59, + 161, 15, 255, 86, 189, 248, 31, 191, 136, 194, 124, 23, 15, 91, 249, 117, 142, 90, 219, + 67, 25, 83, 62, 122, 100, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgTrackingStateDetailedDepA( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgTrackingStateDetailedDepA(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x21, + "Incorrect message type, expected 0x21, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x6e9b, + "incorrect sender id, expected 0x6e9b, is {sender_id}" + ); + assert_eq!( + msg.l.f, 204, + "incorrect value for l.f, expected 204, is {}", + msg.l.f + ); + assert_eq!( + msg.l.i, -1601767965, + "incorrect value for l.i, expected -1601767965, is {}", + msg.l.i + ); + assert_eq!( + msg.p, 1044286343, + "incorrect value for p, expected 1044286343, is {}", + msg.p + ); + assert_eq!( + msg.p_std, 21427, + "incorrect value for p_std, expected 21427, is {}", + msg.p_std + ); + assert_eq!( + msg.acceleration, -114, + "incorrect value for acceleration, expected -114, is {}", + msg.acceleration + ); + assert_eq!( + msg.clock_drift, 23311, + "incorrect value for clock_drift, expected 23311, is {}", + msg.clock_drift + ); + assert_eq!( + msg.clock_offset, 6012, + "incorrect value for clock_offset, expected 6012, is {}", + msg.clock_offset + ); + assert_eq!( + msg.cn0, 78, + "incorrect value for cn0, expected 78, is {}", + msg.cn0 + ); + assert_eq!( + msg.corr_spacing, 30201, + "incorrect value for corr_spacing, expected 30201, is {}", + msg.corr_spacing + ); + assert_eq!( + msg.doppler, 1459556257, + "incorrect value for doppler, expected 1459556257, is {}", + msg.doppler + ); + assert_eq!( + msg.doppler_std, 63677, + "incorrect value for doppler_std, expected 63677, is {}", + msg.doppler_std + ); + assert_eq!( + msg.lock, 65375, + "incorrect value for lock, expected 65375, is {}", + msg.lock + ); + assert_eq!( + msg.misc_flags, 62, + "incorrect value for misc_flags, expected 62, is {}", + msg.misc_flags + ); + assert_eq!( + msg.nav_flags, 25, + "incorrect value for nav_flags, expected 25, is {}", + msg.nav_flags + ); + assert_eq!( + msg.pset_flags, 83, + "incorrect value for pset_flags, expected 83, is {}", + msg.pset_flags + ); + assert_eq!( + msg.recv_time, 941247176494, + "incorrect value for recv_time, expected 941247176494, is {}", + msg.recv_time + ); + assert_eq!( + msg.sid.code, 59, + "incorrect value for sid.code, expected 59, is {}", + msg.sid.code + ); + assert_eq!( + msg.sid.sat, 38, + "incorrect value for sid.sat, expected 38, is {}", + msg.sid.sat + ); + assert_eq!( + msg.sync_flags, 90, + "incorrect value for sync_flags, expected 90, is {}", + msg.sync_flags + ); + assert_eq!( + msg.tot.ns_residual, -811597120, + "incorrect value for tot.ns_residual, expected -811597120, is {}", + msg.tot.ns_residual + ); + assert_eq!( + msg.tot.tow, 1581737093, + "incorrect value for tot.tow, expected 1581737093, is {}", + msg.tot.tow + ); + assert_eq!( + msg.tot.wn, 65492, + "incorrect value for tot.wn, expected 65492, is {}", + msg.tot.wn + ); + assert_eq!( + msg.tow_flags, 219, + "incorrect value for tow_flags, expected 219, is {}", + msg.tow_flags + ); + assert_eq!( + msg.track_flags, 67, + "incorrect value for track_flags, expected 67, is {}", + msg.track_flags + ); + assert_eq!( + msg.uptime, 3263741727, + "incorrect value for uptime, expected 3263741727, is {}", + msg.uptime + ); + } + _ => panic!("Invalid message type! Expected a MsgTrackingStateDetailedDepA"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_tracking_tracking_structs.rs b/rust/sbp/tests/integration/auto_check_sbp_tracking_tracking_structs.rs new file mode 100644 index 0000000000..f8a88a366b --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_tracking_tracking_structs.rs @@ -0,0 +1,45 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/tracking/test_tracking_structs.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_tracking_tracking_structs() {} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_tracking_tracking_structs() {} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_tracking_tracking_structs`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_tracking_tracking_structs() {} diff --git a/rust/sbp/tests/integration/auto_check_sbp_user_msg_user_data.rs b/rust/sbp/tests/integration/auto_check_sbp_user_msg_user_data.rs new file mode 100644 index 0000000000..3ff311b49e --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_user_msg_user_data.rs @@ -0,0 +1,4018 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_user_msg_user_data() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, 149, 204, 113, 31, 108, 188, + 179, 154, 156, 167, 145, 139, 42, 207, 126, 242, 193, 9, 58, 75, 8, 135, 11, 92, 131, + 245, 24, 90, 255, 30, 58, 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, 50, 148, 1, + 99, 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, 97, 96, 75, 174, 58, 219, 180, 148, + 247, 59, 2, 116, 214, 114, 55, 134, 54, 119, 108, 128, 73, 181, 20, 233, 23, 23, 73, + 119, 136, 231, 189, 26, 174, 128, 93, 30, 76, 45, 109, 134, 81, 0, 116, 158, 127, 40, + 133, 208, 134, 127, 140, 232, 183, 184, 108, 6, 228, 54, 238, 59, 220, 30, 228, 212, + 50, 182, 97, 20, 41, 76, 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, 189, 44, 239, + 232, 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, 173, 157, 202, 172, 180, 150, + 213, 193, 177, 209, 156, 20, 174, 18, 73, 132, 215, 115, 128, 175, 169, 116, 132, 100, + 72, 45, 25, 14, 205, 213, 145, 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, + 6, 165, 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, 132, 59, 61, + 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, 56, 216, 19, 216, 70, 71, 161, 184, 5, + 177, 45, 37, 98, 56, 149, 0, 73, 221, 105, 239, 168, 205, 85, 81, 245, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgUserData(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x800, + "Incorrect message type, expected 0x800, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x217e, + "incorrect sender id, expected 0x217e, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 53, + "incorrect value for contents[0], expected 53, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 5, + "incorrect value for contents[1], expected 5, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 172, + "incorrect value for contents[2], expected 172, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 138, + "incorrect value for contents[3], expected 138, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 50, + "incorrect value for contents[4], expected 50, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 49, + "incorrect value for contents[5], expected 49, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 206, + "incorrect value for contents[6], expected 206, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 234, + "incorrect value for contents[7], expected 234, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 149, + "incorrect value for contents[8], expected 149, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 204, + "incorrect value for contents[9], expected 204, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 113, + "incorrect value for contents[10], expected 113, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 31, + "incorrect value for contents[11], expected 31, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 108, + "incorrect value for contents[12], expected 108, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 188, + "incorrect value for contents[13], expected 188, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 179, + "incorrect value for contents[14], expected 179, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 154, + "incorrect value for contents[15], expected 154, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 156, + "incorrect value for contents[16], expected 156, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 167, + "incorrect value for contents[17], expected 167, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 145, + "incorrect value for contents[18], expected 145, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 139, + "incorrect value for contents[19], expected 139, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 42, + "incorrect value for contents[20], expected 42, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 207, + "incorrect value for contents[21], expected 207, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 126, + "incorrect value for contents[22], expected 126, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 242, + "incorrect value for contents[23], expected 242, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 193, + "incorrect value for contents[24], expected 193, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 9, + "incorrect value for contents[25], expected 9, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 58, + "incorrect value for contents[26], expected 58, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 75, + "incorrect value for contents[27], expected 75, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 8, + "incorrect value for contents[28], expected 8, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 135, + "incorrect value for contents[29], expected 135, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 11, + "incorrect value for contents[30], expected 11, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 92, + "incorrect value for contents[31], expected 92, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 131, + "incorrect value for contents[32], expected 131, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 245, + "incorrect value for contents[33], expected 245, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 24, + "incorrect value for contents[34], expected 24, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 90, + "incorrect value for contents[35], expected 90, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 255, + "incorrect value for contents[36], expected 255, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 30, + "incorrect value for contents[37], expected 30, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 58, + "incorrect value for contents[38], expected 58, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 31, + "incorrect value for contents[39], expected 31, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 109, + "incorrect value for contents[40], expected 109, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 148, + "incorrect value for contents[41], expected 148, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 56, + "incorrect value for contents[42], expected 56, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 178, + "incorrect value for contents[43], expected 178, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 140, + "incorrect value for contents[44], expected 140, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 30, + "incorrect value for contents[45], expected 30, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 159, + "incorrect value for contents[46], expected 159, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 70, + "incorrect value for contents[47], expected 70, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 17, + "incorrect value for contents[48], expected 17, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 170, + "incorrect value for contents[49], expected 170, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 50, + "incorrect value for contents[50], expected 50, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 148, + "incorrect value for contents[51], expected 148, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 1, + "incorrect value for contents[52], expected 1, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 99, + "incorrect value for contents[53], expected 99, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 112, + "incorrect value for contents[54], expected 112, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 88, + "incorrect value for contents[55], expected 88, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 217, + "incorrect value for contents[56], expected 217, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 36, + "incorrect value for contents[57], expected 36, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 84, + "incorrect value for contents[58], expected 84, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 34, + "incorrect value for contents[59], expected 34, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 234, + "incorrect value for contents[60], expected 234, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 82, + "incorrect value for contents[61], expected 82, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 144, + "incorrect value for contents[62], expected 144, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 144, + "incorrect value for contents[63], expected 144, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 97, + "incorrect value for contents[64], expected 97, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 96, + "incorrect value for contents[65], expected 96, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 75, + "incorrect value for contents[66], expected 75, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 174, + "incorrect value for contents[67], expected 174, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 58, + "incorrect value for contents[68], expected 58, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 219, + "incorrect value for contents[69], expected 219, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 180, + "incorrect value for contents[70], expected 180, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 148, + "incorrect value for contents[71], expected 148, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 247, + "incorrect value for contents[72], expected 247, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 59, + "incorrect value for contents[73], expected 59, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 2, + "incorrect value for contents[74], expected 2, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 116, + "incorrect value for contents[75], expected 116, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 214, + "incorrect value for contents[76], expected 214, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 114, + "incorrect value for contents[77], expected 114, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 55, + "incorrect value for contents[78], expected 55, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 134, + "incorrect value for contents[79], expected 134, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 54, + "incorrect value for contents[80], expected 54, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 119, + "incorrect value for contents[81], expected 119, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 108, + "incorrect value for contents[82], expected 108, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 128, + "incorrect value for contents[83], expected 128, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 73, + "incorrect value for contents[84], expected 73, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 181, + "incorrect value for contents[85], expected 181, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 20, + "incorrect value for contents[86], expected 20, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 233, + "incorrect value for contents[87], expected 233, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 23, + "incorrect value for contents[88], expected 23, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 23, + "incorrect value for contents[89], expected 23, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 73, + "incorrect value for contents[90], expected 73, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 119, + "incorrect value for contents[91], expected 119, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 136, + "incorrect value for contents[92], expected 136, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 231, + "incorrect value for contents[93], expected 231, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 189, + "incorrect value for contents[94], expected 189, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 26, + "incorrect value for contents[95], expected 26, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 174, + "incorrect value for contents[96], expected 174, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 128, + "incorrect value for contents[97], expected 128, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 93, + "incorrect value for contents[98], expected 93, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 30, + "incorrect value for contents[99], expected 30, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 76, + "incorrect value for contents[100], expected 76, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 45, + "incorrect value for contents[101], expected 45, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 109, + "incorrect value for contents[102], expected 109, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 134, + "incorrect value for contents[103], expected 134, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 81, + "incorrect value for contents[104], expected 81, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 0, + "incorrect value for contents[105], expected 0, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 116, + "incorrect value for contents[106], expected 116, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 158, + "incorrect value for contents[107], expected 158, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 127, + "incorrect value for contents[108], expected 127, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 40, + "incorrect value for contents[109], expected 40, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 133, + "incorrect value for contents[110], expected 133, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 208, + "incorrect value for contents[111], expected 208, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 134, + "incorrect value for contents[112], expected 134, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 127, + "incorrect value for contents[113], expected 127, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 140, + "incorrect value for contents[114], expected 140, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 232, + "incorrect value for contents[115], expected 232, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 183, + "incorrect value for contents[116], expected 183, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 184, + "incorrect value for contents[117], expected 184, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 108, + "incorrect value for contents[118], expected 108, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 6, + "incorrect value for contents[119], expected 6, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 228, + "incorrect value for contents[120], expected 228, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 54, + "incorrect value for contents[121], expected 54, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 238, + "incorrect value for contents[122], expected 238, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 59, + "incorrect value for contents[123], expected 59, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 220, + "incorrect value for contents[124], expected 220, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 30, + "incorrect value for contents[125], expected 30, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 228, + "incorrect value for contents[126], expected 228, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 212, + "incorrect value for contents[127], expected 212, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 50, + "incorrect value for contents[128], expected 50, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 182, + "incorrect value for contents[129], expected 182, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 97, + "incorrect value for contents[130], expected 97, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 20, + "incorrect value for contents[131], expected 20, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 41, + "incorrect value for contents[132], expected 41, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 76, + "incorrect value for contents[133], expected 76, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 227, + "incorrect value for contents[134], expected 227, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 88, + "incorrect value for contents[135], expected 88, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 12, + "incorrect value for contents[136], expected 12, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 95, + "incorrect value for contents[137], expected 95, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 112, + "incorrect value for contents[138], expected 112, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 209, + "incorrect value for contents[139], expected 209, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 183, + "incorrect value for contents[140], expected 183, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 127, + "incorrect value for contents[141], expected 127, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 4, + "incorrect value for contents[142], expected 4, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 165, + "incorrect value for contents[143], expected 165, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 189, + "incorrect value for contents[144], expected 189, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 44, + "incorrect value for contents[145], expected 44, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 239, + "incorrect value for contents[146], expected 239, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 232, + "incorrect value for contents[147], expected 232, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 132, + "incorrect value for contents[148], expected 132, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 9, + "incorrect value for contents[149], expected 9, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 114, + "incorrect value for contents[150], expected 114, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 184, + "incorrect value for contents[151], expected 184, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 249, + "incorrect value for contents[152], expected 249, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 208, + "incorrect value for contents[153], expected 208, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 246, + "incorrect value for contents[154], expected 246, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 194, + "incorrect value for contents[155], expected 194, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 250, + "incorrect value for contents[156], expected 250, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 2, + "incorrect value for contents[157], expected 2, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 97, + "incorrect value for contents[158], expected 97, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 173, + "incorrect value for contents[159], expected 173, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 157, + "incorrect value for contents[160], expected 157, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 202, + "incorrect value for contents[161], expected 202, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 172, + "incorrect value for contents[162], expected 172, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 180, + "incorrect value for contents[163], expected 180, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 150, + "incorrect value for contents[164], expected 150, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 213, + "incorrect value for contents[165], expected 213, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 193, + "incorrect value for contents[166], expected 193, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 177, + "incorrect value for contents[167], expected 177, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 209, + "incorrect value for contents[168], expected 209, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 156, + "incorrect value for contents[169], expected 156, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 20, + "incorrect value for contents[170], expected 20, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 174, + "incorrect value for contents[171], expected 174, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 18, + "incorrect value for contents[172], expected 18, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 73, + "incorrect value for contents[173], expected 73, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 132, + "incorrect value for contents[174], expected 132, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 215, + "incorrect value for contents[175], expected 215, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 115, + "incorrect value for contents[176], expected 115, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 128, + "incorrect value for contents[177], expected 128, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 175, + "incorrect value for contents[178], expected 175, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 169, + "incorrect value for contents[179], expected 169, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 116, + "incorrect value for contents[180], expected 116, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 132, + "incorrect value for contents[181], expected 132, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 100, + "incorrect value for contents[182], expected 100, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 72, + "incorrect value for contents[183], expected 72, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 45, + "incorrect value for contents[184], expected 45, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 25, + "incorrect value for contents[185], expected 25, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 14, + "incorrect value for contents[186], expected 14, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 205, + "incorrect value for contents[187], expected 205, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 213, + "incorrect value for contents[188], expected 213, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 145, + "incorrect value for contents[189], expected 145, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 68, + "incorrect value for contents[190], expected 68, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 137, + "incorrect value for contents[191], expected 137, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 249, + "incorrect value for contents[192], expected 249, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 54, + "incorrect value for contents[193], expected 54, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 40, + "incorrect value for contents[194], expected 40, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 174, + "incorrect value for contents[195], expected 174, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 215, + "incorrect value for contents[196], expected 215, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 148, + "incorrect value for contents[197], expected 148, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 166, + "incorrect value for contents[198], expected 166, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 190, + "incorrect value for contents[199], expected 190, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 63, + "incorrect value for contents[200], expected 63, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 118, + "incorrect value for contents[201], expected 118, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 6, + "incorrect value for contents[202], expected 6, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 165, + "incorrect value for contents[203], expected 165, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 212, + "incorrect value for contents[204], expected 212, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 74, + "incorrect value for contents[205], expected 74, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 68, + "incorrect value for contents[206], expected 68, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 200, + "incorrect value for contents[207], expected 200, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 38, + "incorrect value for contents[208], expected 38, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 139, + "incorrect value for contents[209], expected 139, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 212, + "incorrect value for contents[210], expected 212, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 45, + "incorrect value for contents[212], expected 45, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 167, + "incorrect value for contents[213], expected 167, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 236, + "incorrect value for contents[214], expected 236, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 255, + "incorrect value for contents[215], expected 255, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 106, + "incorrect value for contents[216], expected 106, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 92, + "incorrect value for contents[217], expected 92, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 132, + "incorrect value for contents[218], expected 132, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 59, + "incorrect value for contents[219], expected 59, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 61, + "incorrect value for contents[220], expected 61, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 233, + "incorrect value for contents[221], expected 233, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 3, + "incorrect value for contents[222], expected 3, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 246, + "incorrect value for contents[223], expected 246, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 158, + "incorrect value for contents[224], expected 158, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 83, + "incorrect value for contents[225], expected 83, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 134, + "incorrect value for contents[226], expected 134, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 246, + "incorrect value for contents[227], expected 246, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 154, + "incorrect value for contents[228], expected 154, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 17, + "incorrect value for contents[229], expected 17, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 0, + "incorrect value for contents[230], expected 0, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 6, + "incorrect value for contents[231], expected 6, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 56, + "incorrect value for contents[232], expected 56, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 216, + "incorrect value for contents[233], expected 216, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 19, + "incorrect value for contents[234], expected 19, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 216, + "incorrect value for contents[235], expected 216, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 70, + "incorrect value for contents[236], expected 70, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 71, + "incorrect value for contents[237], expected 71, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 161, + "incorrect value for contents[238], expected 161, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 184, + "incorrect value for contents[239], expected 184, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 5, + "incorrect value for contents[240], expected 5, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 177, + "incorrect value for contents[241], expected 177, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 45, + "incorrect value for contents[242], expected 45, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 37, + "incorrect value for contents[243], expected 37, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 98, + "incorrect value for contents[244], expected 98, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 56, + "incorrect value for contents[245], expected 56, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 149, + "incorrect value for contents[246], expected 149, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 0, + "incorrect value for contents[247], expected 0, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 73, + "incorrect value for contents[248], expected 73, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 221, + "incorrect value for contents[249], expected 221, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 105, + "incorrect value for contents[250], expected 105, is {}", + msg.contents[250] + ); + assert_eq!( + msg.contents[251], 239, + "incorrect value for contents[251], expected 239, is {}", + msg.contents[251] + ); + assert_eq!( + msg.contents[252], 168, + "incorrect value for contents[252], expected 168, is {}", + msg.contents[252] + ); + assert_eq!( + msg.contents[253], 205, + "incorrect value for contents[253], expected 205, is {}", + msg.contents[253] + ); + assert_eq!( + msg.contents[254], 85, + "incorrect value for contents[254], expected 85, is {}", + msg.contents[254] + ); + } + _ => panic!("Invalid message type! Expected a MsgUserData"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_user_msg_user_data() { + { + let json_input = r#"{"crc":62801,"length":255,"msg_type":2048,"payload":"NQWsijIxzuqVzHEfbLyzmpynkYsqz37ywQk6SwiHC1yD9Rha/x46H22UOLKMHp9GEaoylAFjcFjZJFQi6lKQkGFgS64627SU9zsCdNZyN4Y2d2yASbUU6RcXSXeI570aroBdHkwtbYZRAHSefyiF0IZ/jOi3uGwG5DbuO9we5NQytmEUKUzjWAxfcNG3fwSlvSzv6IQJcrj50PbC+gJhrZ3KrLSW1cGx0ZwUrhJJhNdzgK+pdIRkSC0ZDs3VkUSJ+TYorteUpr4/dgal1EpEyCaL1HAtp+z/alyEOz3pA/aeU4b2mhEABjjYE9hGR6G4BbEtJWI4lQBJ3WnvqM1V","preamble":85,"sender":8574,"contents":[53,5,172,138,50,49,206,234,149,204,113,31,108,188,179,154,156,167,145,139,42,207,126,242,193,9,58,75,8,135,11,92,131,245,24,90,255,30,58,31,109,148,56,178,140,30,159,70,17,170,50,148,1,99,112,88,217,36,84,34,234,82,144,144,97,96,75,174,58,219,180,148,247,59,2,116,214,114,55,134,54,119,108,128,73,181,20,233,23,23,73,119,136,231,189,26,174,128,93,30,76,45,109,134,81,0,116,158,127,40,133,208,134,127,140,232,183,184,108,6,228,54,238,59,220,30,228,212,50,182,97,20,41,76,227,88,12,95,112,209,183,127,4,165,189,44,239,232,132,9,114,184,249,208,246,194,250,2,97,173,157,202,172,180,150,213,193,177,209,156,20,174,18,73,132,215,115,128,175,169,116,132,100,72,45,25,14,205,213,145,68,137,249,54,40,174,215,148,166,190,63,118,6,165,212,74,68,200,38,139,212,112,45,167,236,255,106,92,132,59,61,233,3,246,158,83,134,246,154,17,0,6,56,216,19,216,70,71,161,184,5,177,45,37,98,56,149,0,73,221,105,239,168,205,85]}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgUserData(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x800, + "Incorrect message type, expected 0x800, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x217e, + "incorrect sender id, expected 0x217e, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 53, + "incorrect value for contents[0], expected 53, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 5, + "incorrect value for contents[1], expected 5, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 172, + "incorrect value for contents[2], expected 172, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 138, + "incorrect value for contents[3], expected 138, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 50, + "incorrect value for contents[4], expected 50, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 49, + "incorrect value for contents[5], expected 49, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 206, + "incorrect value for contents[6], expected 206, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 234, + "incorrect value for contents[7], expected 234, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 149, + "incorrect value for contents[8], expected 149, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 204, + "incorrect value for contents[9], expected 204, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 113, + "incorrect value for contents[10], expected 113, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 31, + "incorrect value for contents[11], expected 31, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 108, + "incorrect value for contents[12], expected 108, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 188, + "incorrect value for contents[13], expected 188, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 179, + "incorrect value for contents[14], expected 179, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 154, + "incorrect value for contents[15], expected 154, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 156, + "incorrect value for contents[16], expected 156, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 167, + "incorrect value for contents[17], expected 167, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 145, + "incorrect value for contents[18], expected 145, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 139, + "incorrect value for contents[19], expected 139, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 42, + "incorrect value for contents[20], expected 42, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 207, + "incorrect value for contents[21], expected 207, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 126, + "incorrect value for contents[22], expected 126, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 242, + "incorrect value for contents[23], expected 242, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 193, + "incorrect value for contents[24], expected 193, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 9, + "incorrect value for contents[25], expected 9, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 58, + "incorrect value for contents[26], expected 58, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 75, + "incorrect value for contents[27], expected 75, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 8, + "incorrect value for contents[28], expected 8, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 135, + "incorrect value for contents[29], expected 135, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 11, + "incorrect value for contents[30], expected 11, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 92, + "incorrect value for contents[31], expected 92, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 131, + "incorrect value for contents[32], expected 131, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 245, + "incorrect value for contents[33], expected 245, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 24, + "incorrect value for contents[34], expected 24, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 90, + "incorrect value for contents[35], expected 90, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 255, + "incorrect value for contents[36], expected 255, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 30, + "incorrect value for contents[37], expected 30, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 58, + "incorrect value for contents[38], expected 58, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 31, + "incorrect value for contents[39], expected 31, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 109, + "incorrect value for contents[40], expected 109, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 148, + "incorrect value for contents[41], expected 148, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 56, + "incorrect value for contents[42], expected 56, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 178, + "incorrect value for contents[43], expected 178, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 140, + "incorrect value for contents[44], expected 140, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 30, + "incorrect value for contents[45], expected 30, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 159, + "incorrect value for contents[46], expected 159, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 70, + "incorrect value for contents[47], expected 70, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 17, + "incorrect value for contents[48], expected 17, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 170, + "incorrect value for contents[49], expected 170, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 50, + "incorrect value for contents[50], expected 50, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 148, + "incorrect value for contents[51], expected 148, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 1, + "incorrect value for contents[52], expected 1, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 99, + "incorrect value for contents[53], expected 99, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 112, + "incorrect value for contents[54], expected 112, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 88, + "incorrect value for contents[55], expected 88, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 217, + "incorrect value for contents[56], expected 217, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 36, + "incorrect value for contents[57], expected 36, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 84, + "incorrect value for contents[58], expected 84, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 34, + "incorrect value for contents[59], expected 34, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 234, + "incorrect value for contents[60], expected 234, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 82, + "incorrect value for contents[61], expected 82, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 144, + "incorrect value for contents[62], expected 144, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 144, + "incorrect value for contents[63], expected 144, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 97, + "incorrect value for contents[64], expected 97, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 96, + "incorrect value for contents[65], expected 96, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 75, + "incorrect value for contents[66], expected 75, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 174, + "incorrect value for contents[67], expected 174, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 58, + "incorrect value for contents[68], expected 58, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 219, + "incorrect value for contents[69], expected 219, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 180, + "incorrect value for contents[70], expected 180, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 148, + "incorrect value for contents[71], expected 148, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 247, + "incorrect value for contents[72], expected 247, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 59, + "incorrect value for contents[73], expected 59, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 2, + "incorrect value for contents[74], expected 2, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 116, + "incorrect value for contents[75], expected 116, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 214, + "incorrect value for contents[76], expected 214, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 114, + "incorrect value for contents[77], expected 114, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 55, + "incorrect value for contents[78], expected 55, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 134, + "incorrect value for contents[79], expected 134, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 54, + "incorrect value for contents[80], expected 54, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 119, + "incorrect value for contents[81], expected 119, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 108, + "incorrect value for contents[82], expected 108, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 128, + "incorrect value for contents[83], expected 128, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 73, + "incorrect value for contents[84], expected 73, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 181, + "incorrect value for contents[85], expected 181, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 20, + "incorrect value for contents[86], expected 20, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 233, + "incorrect value for contents[87], expected 233, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 23, + "incorrect value for contents[88], expected 23, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 23, + "incorrect value for contents[89], expected 23, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 73, + "incorrect value for contents[90], expected 73, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 119, + "incorrect value for contents[91], expected 119, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 136, + "incorrect value for contents[92], expected 136, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 231, + "incorrect value for contents[93], expected 231, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 189, + "incorrect value for contents[94], expected 189, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 26, + "incorrect value for contents[95], expected 26, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 174, + "incorrect value for contents[96], expected 174, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 128, + "incorrect value for contents[97], expected 128, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 93, + "incorrect value for contents[98], expected 93, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 30, + "incorrect value for contents[99], expected 30, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 76, + "incorrect value for contents[100], expected 76, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 45, + "incorrect value for contents[101], expected 45, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 109, + "incorrect value for contents[102], expected 109, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 134, + "incorrect value for contents[103], expected 134, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 81, + "incorrect value for contents[104], expected 81, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 0, + "incorrect value for contents[105], expected 0, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 116, + "incorrect value for contents[106], expected 116, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 158, + "incorrect value for contents[107], expected 158, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 127, + "incorrect value for contents[108], expected 127, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 40, + "incorrect value for contents[109], expected 40, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 133, + "incorrect value for contents[110], expected 133, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 208, + "incorrect value for contents[111], expected 208, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 134, + "incorrect value for contents[112], expected 134, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 127, + "incorrect value for contents[113], expected 127, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 140, + "incorrect value for contents[114], expected 140, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 232, + "incorrect value for contents[115], expected 232, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 183, + "incorrect value for contents[116], expected 183, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 184, + "incorrect value for contents[117], expected 184, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 108, + "incorrect value for contents[118], expected 108, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 6, + "incorrect value for contents[119], expected 6, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 228, + "incorrect value for contents[120], expected 228, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 54, + "incorrect value for contents[121], expected 54, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 238, + "incorrect value for contents[122], expected 238, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 59, + "incorrect value for contents[123], expected 59, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 220, + "incorrect value for contents[124], expected 220, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 30, + "incorrect value for contents[125], expected 30, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 228, + "incorrect value for contents[126], expected 228, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 212, + "incorrect value for contents[127], expected 212, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 50, + "incorrect value for contents[128], expected 50, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 182, + "incorrect value for contents[129], expected 182, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 97, + "incorrect value for contents[130], expected 97, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 20, + "incorrect value for contents[131], expected 20, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 41, + "incorrect value for contents[132], expected 41, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 76, + "incorrect value for contents[133], expected 76, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 227, + "incorrect value for contents[134], expected 227, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 88, + "incorrect value for contents[135], expected 88, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 12, + "incorrect value for contents[136], expected 12, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 95, + "incorrect value for contents[137], expected 95, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 112, + "incorrect value for contents[138], expected 112, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 209, + "incorrect value for contents[139], expected 209, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 183, + "incorrect value for contents[140], expected 183, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 127, + "incorrect value for contents[141], expected 127, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 4, + "incorrect value for contents[142], expected 4, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 165, + "incorrect value for contents[143], expected 165, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 189, + "incorrect value for contents[144], expected 189, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 44, + "incorrect value for contents[145], expected 44, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 239, + "incorrect value for contents[146], expected 239, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 232, + "incorrect value for contents[147], expected 232, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 132, + "incorrect value for contents[148], expected 132, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 9, + "incorrect value for contents[149], expected 9, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 114, + "incorrect value for contents[150], expected 114, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 184, + "incorrect value for contents[151], expected 184, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 249, + "incorrect value for contents[152], expected 249, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 208, + "incorrect value for contents[153], expected 208, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 246, + "incorrect value for contents[154], expected 246, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 194, + "incorrect value for contents[155], expected 194, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 250, + "incorrect value for contents[156], expected 250, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 2, + "incorrect value for contents[157], expected 2, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 97, + "incorrect value for contents[158], expected 97, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 173, + "incorrect value for contents[159], expected 173, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 157, + "incorrect value for contents[160], expected 157, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 202, + "incorrect value for contents[161], expected 202, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 172, + "incorrect value for contents[162], expected 172, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 180, + "incorrect value for contents[163], expected 180, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 150, + "incorrect value for contents[164], expected 150, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 213, + "incorrect value for contents[165], expected 213, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 193, + "incorrect value for contents[166], expected 193, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 177, + "incorrect value for contents[167], expected 177, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 209, + "incorrect value for contents[168], expected 209, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 156, + "incorrect value for contents[169], expected 156, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 20, + "incorrect value for contents[170], expected 20, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 174, + "incorrect value for contents[171], expected 174, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 18, + "incorrect value for contents[172], expected 18, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 73, + "incorrect value for contents[173], expected 73, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 132, + "incorrect value for contents[174], expected 132, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 215, + "incorrect value for contents[175], expected 215, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 115, + "incorrect value for contents[176], expected 115, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 128, + "incorrect value for contents[177], expected 128, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 175, + "incorrect value for contents[178], expected 175, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 169, + "incorrect value for contents[179], expected 169, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 116, + "incorrect value for contents[180], expected 116, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 132, + "incorrect value for contents[181], expected 132, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 100, + "incorrect value for contents[182], expected 100, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 72, + "incorrect value for contents[183], expected 72, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 45, + "incorrect value for contents[184], expected 45, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 25, + "incorrect value for contents[185], expected 25, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 14, + "incorrect value for contents[186], expected 14, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 205, + "incorrect value for contents[187], expected 205, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 213, + "incorrect value for contents[188], expected 213, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 145, + "incorrect value for contents[189], expected 145, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 68, + "incorrect value for contents[190], expected 68, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 137, + "incorrect value for contents[191], expected 137, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 249, + "incorrect value for contents[192], expected 249, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 54, + "incorrect value for contents[193], expected 54, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 40, + "incorrect value for contents[194], expected 40, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 174, + "incorrect value for contents[195], expected 174, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 215, + "incorrect value for contents[196], expected 215, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 148, + "incorrect value for contents[197], expected 148, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 166, + "incorrect value for contents[198], expected 166, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 190, + "incorrect value for contents[199], expected 190, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 63, + "incorrect value for contents[200], expected 63, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 118, + "incorrect value for contents[201], expected 118, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 6, + "incorrect value for contents[202], expected 6, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 165, + "incorrect value for contents[203], expected 165, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 212, + "incorrect value for contents[204], expected 212, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 74, + "incorrect value for contents[205], expected 74, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 68, + "incorrect value for contents[206], expected 68, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 200, + "incorrect value for contents[207], expected 200, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 38, + "incorrect value for contents[208], expected 38, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 139, + "incorrect value for contents[209], expected 139, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 212, + "incorrect value for contents[210], expected 212, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 45, + "incorrect value for contents[212], expected 45, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 167, + "incorrect value for contents[213], expected 167, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 236, + "incorrect value for contents[214], expected 236, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 255, + "incorrect value for contents[215], expected 255, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 106, + "incorrect value for contents[216], expected 106, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 92, + "incorrect value for contents[217], expected 92, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 132, + "incorrect value for contents[218], expected 132, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 59, + "incorrect value for contents[219], expected 59, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 61, + "incorrect value for contents[220], expected 61, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 233, + "incorrect value for contents[221], expected 233, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 3, + "incorrect value for contents[222], expected 3, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 246, + "incorrect value for contents[223], expected 246, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 158, + "incorrect value for contents[224], expected 158, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 83, + "incorrect value for contents[225], expected 83, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 134, + "incorrect value for contents[226], expected 134, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 246, + "incorrect value for contents[227], expected 246, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 154, + "incorrect value for contents[228], expected 154, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 17, + "incorrect value for contents[229], expected 17, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 0, + "incorrect value for contents[230], expected 0, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 6, + "incorrect value for contents[231], expected 6, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 56, + "incorrect value for contents[232], expected 56, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 216, + "incorrect value for contents[233], expected 216, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 19, + "incorrect value for contents[234], expected 19, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 216, + "incorrect value for contents[235], expected 216, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 70, + "incorrect value for contents[236], expected 70, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 71, + "incorrect value for contents[237], expected 71, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 161, + "incorrect value for contents[238], expected 161, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 184, + "incorrect value for contents[239], expected 184, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 5, + "incorrect value for contents[240], expected 5, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 177, + "incorrect value for contents[241], expected 177, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 45, + "incorrect value for contents[242], expected 45, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 37, + "incorrect value for contents[243], expected 37, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 98, + "incorrect value for contents[244], expected 98, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 56, + "incorrect value for contents[245], expected 56, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 149, + "incorrect value for contents[246], expected 149, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 0, + "incorrect value for contents[247], expected 0, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 73, + "incorrect value for contents[248], expected 73, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 221, + "incorrect value for contents[249], expected 221, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 105, + "incorrect value for contents[250], expected 105, is {}", + msg.contents[250] + ); + assert_eq!( + msg.contents[251], 239, + "incorrect value for contents[251], expected 239, is {}", + msg.contents[251] + ); + assert_eq!( + msg.contents[252], 168, + "incorrect value for contents[252], expected 168, is {}", + msg.contents[252] + ); + assert_eq!( + msg.contents[253], 205, + "incorrect value for contents[253], expected 205, is {}", + msg.contents[253] + ); + assert_eq!( + msg.contents[254], 85, + "incorrect value for contents[254], expected 85, is {}", + msg.contents[254] + ); + } + _ => panic!("Invalid message type! Expected a MsgUserData"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_user_msg_user_data`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_user_msg_user_data() { + { + let mut payload = Cursor::new(vec![ + 85, 0, 8, 126, 33, 255, 53, 5, 172, 138, 50, 49, 206, 234, 149, 204, 113, 31, 108, 188, + 179, 154, 156, 167, 145, 139, 42, 207, 126, 242, 193, 9, 58, 75, 8, 135, 11, 92, 131, + 245, 24, 90, 255, 30, 58, 31, 109, 148, 56, 178, 140, 30, 159, 70, 17, 170, 50, 148, 1, + 99, 112, 88, 217, 36, 84, 34, 234, 82, 144, 144, 97, 96, 75, 174, 58, 219, 180, 148, + 247, 59, 2, 116, 214, 114, 55, 134, 54, 119, 108, 128, 73, 181, 20, 233, 23, 23, 73, + 119, 136, 231, 189, 26, 174, 128, 93, 30, 76, 45, 109, 134, 81, 0, 116, 158, 127, 40, + 133, 208, 134, 127, 140, 232, 183, 184, 108, 6, 228, 54, 238, 59, 220, 30, 228, 212, + 50, 182, 97, 20, 41, 76, 227, 88, 12, 95, 112, 209, 183, 127, 4, 165, 189, 44, 239, + 232, 132, 9, 114, 184, 249, 208, 246, 194, 250, 2, 97, 173, 157, 202, 172, 180, 150, + 213, 193, 177, 209, 156, 20, 174, 18, 73, 132, 215, 115, 128, 175, 169, 116, 132, 100, + 72, 45, 25, 14, 205, 213, 145, 68, 137, 249, 54, 40, 174, 215, 148, 166, 190, 63, 118, + 6, 165, 212, 74, 68, 200, 38, 139, 212, 112, 45, 167, 236, 255, 106, 92, 132, 59, 61, + 233, 3, 246, 158, 83, 134, 246, 154, 17, 0, 6, 56, 216, 19, 216, 70, 71, 161, 184, 5, + 177, 45, 37, 98, 56, 149, 0, 73, 221, 105, 239, 168, 205, 85, 81, 245, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgUserData( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgUserData(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x800, + "Incorrect message type, expected 0x800, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x217e, + "incorrect sender id, expected 0x217e, is {sender_id}" + ); + assert_eq!( + msg.contents[0], 53, + "incorrect value for contents[0], expected 53, is {}", + msg.contents[0] + ); + assert_eq!( + msg.contents[1], 5, + "incorrect value for contents[1], expected 5, is {}", + msg.contents[1] + ); + assert_eq!( + msg.contents[2], 172, + "incorrect value for contents[2], expected 172, is {}", + msg.contents[2] + ); + assert_eq!( + msg.contents[3], 138, + "incorrect value for contents[3], expected 138, is {}", + msg.contents[3] + ); + assert_eq!( + msg.contents[4], 50, + "incorrect value for contents[4], expected 50, is {}", + msg.contents[4] + ); + assert_eq!( + msg.contents[5], 49, + "incorrect value for contents[5], expected 49, is {}", + msg.contents[5] + ); + assert_eq!( + msg.contents[6], 206, + "incorrect value for contents[6], expected 206, is {}", + msg.contents[6] + ); + assert_eq!( + msg.contents[7], 234, + "incorrect value for contents[7], expected 234, is {}", + msg.contents[7] + ); + assert_eq!( + msg.contents[8], 149, + "incorrect value for contents[8], expected 149, is {}", + msg.contents[8] + ); + assert_eq!( + msg.contents[9], 204, + "incorrect value for contents[9], expected 204, is {}", + msg.contents[9] + ); + assert_eq!( + msg.contents[10], 113, + "incorrect value for contents[10], expected 113, is {}", + msg.contents[10] + ); + assert_eq!( + msg.contents[11], 31, + "incorrect value for contents[11], expected 31, is {}", + msg.contents[11] + ); + assert_eq!( + msg.contents[12], 108, + "incorrect value for contents[12], expected 108, is {}", + msg.contents[12] + ); + assert_eq!( + msg.contents[13], 188, + "incorrect value for contents[13], expected 188, is {}", + msg.contents[13] + ); + assert_eq!( + msg.contents[14], 179, + "incorrect value for contents[14], expected 179, is {}", + msg.contents[14] + ); + assert_eq!( + msg.contents[15], 154, + "incorrect value for contents[15], expected 154, is {}", + msg.contents[15] + ); + assert_eq!( + msg.contents[16], 156, + "incorrect value for contents[16], expected 156, is {}", + msg.contents[16] + ); + assert_eq!( + msg.contents[17], 167, + "incorrect value for contents[17], expected 167, is {}", + msg.contents[17] + ); + assert_eq!( + msg.contents[18], 145, + "incorrect value for contents[18], expected 145, is {}", + msg.contents[18] + ); + assert_eq!( + msg.contents[19], 139, + "incorrect value for contents[19], expected 139, is {}", + msg.contents[19] + ); + assert_eq!( + msg.contents[20], 42, + "incorrect value for contents[20], expected 42, is {}", + msg.contents[20] + ); + assert_eq!( + msg.contents[21], 207, + "incorrect value for contents[21], expected 207, is {}", + msg.contents[21] + ); + assert_eq!( + msg.contents[22], 126, + "incorrect value for contents[22], expected 126, is {}", + msg.contents[22] + ); + assert_eq!( + msg.contents[23], 242, + "incorrect value for contents[23], expected 242, is {}", + msg.contents[23] + ); + assert_eq!( + msg.contents[24], 193, + "incorrect value for contents[24], expected 193, is {}", + msg.contents[24] + ); + assert_eq!( + msg.contents[25], 9, + "incorrect value for contents[25], expected 9, is {}", + msg.contents[25] + ); + assert_eq!( + msg.contents[26], 58, + "incorrect value for contents[26], expected 58, is {}", + msg.contents[26] + ); + assert_eq!( + msg.contents[27], 75, + "incorrect value for contents[27], expected 75, is {}", + msg.contents[27] + ); + assert_eq!( + msg.contents[28], 8, + "incorrect value for contents[28], expected 8, is {}", + msg.contents[28] + ); + assert_eq!( + msg.contents[29], 135, + "incorrect value for contents[29], expected 135, is {}", + msg.contents[29] + ); + assert_eq!( + msg.contents[30], 11, + "incorrect value for contents[30], expected 11, is {}", + msg.contents[30] + ); + assert_eq!( + msg.contents[31], 92, + "incorrect value for contents[31], expected 92, is {}", + msg.contents[31] + ); + assert_eq!( + msg.contents[32], 131, + "incorrect value for contents[32], expected 131, is {}", + msg.contents[32] + ); + assert_eq!( + msg.contents[33], 245, + "incorrect value for contents[33], expected 245, is {}", + msg.contents[33] + ); + assert_eq!( + msg.contents[34], 24, + "incorrect value for contents[34], expected 24, is {}", + msg.contents[34] + ); + assert_eq!( + msg.contents[35], 90, + "incorrect value for contents[35], expected 90, is {}", + msg.contents[35] + ); + assert_eq!( + msg.contents[36], 255, + "incorrect value for contents[36], expected 255, is {}", + msg.contents[36] + ); + assert_eq!( + msg.contents[37], 30, + "incorrect value for contents[37], expected 30, is {}", + msg.contents[37] + ); + assert_eq!( + msg.contents[38], 58, + "incorrect value for contents[38], expected 58, is {}", + msg.contents[38] + ); + assert_eq!( + msg.contents[39], 31, + "incorrect value for contents[39], expected 31, is {}", + msg.contents[39] + ); + assert_eq!( + msg.contents[40], 109, + "incorrect value for contents[40], expected 109, is {}", + msg.contents[40] + ); + assert_eq!( + msg.contents[41], 148, + "incorrect value for contents[41], expected 148, is {}", + msg.contents[41] + ); + assert_eq!( + msg.contents[42], 56, + "incorrect value for contents[42], expected 56, is {}", + msg.contents[42] + ); + assert_eq!( + msg.contents[43], 178, + "incorrect value for contents[43], expected 178, is {}", + msg.contents[43] + ); + assert_eq!( + msg.contents[44], 140, + "incorrect value for contents[44], expected 140, is {}", + msg.contents[44] + ); + assert_eq!( + msg.contents[45], 30, + "incorrect value for contents[45], expected 30, is {}", + msg.contents[45] + ); + assert_eq!( + msg.contents[46], 159, + "incorrect value for contents[46], expected 159, is {}", + msg.contents[46] + ); + assert_eq!( + msg.contents[47], 70, + "incorrect value for contents[47], expected 70, is {}", + msg.contents[47] + ); + assert_eq!( + msg.contents[48], 17, + "incorrect value for contents[48], expected 17, is {}", + msg.contents[48] + ); + assert_eq!( + msg.contents[49], 170, + "incorrect value for contents[49], expected 170, is {}", + msg.contents[49] + ); + assert_eq!( + msg.contents[50], 50, + "incorrect value for contents[50], expected 50, is {}", + msg.contents[50] + ); + assert_eq!( + msg.contents[51], 148, + "incorrect value for contents[51], expected 148, is {}", + msg.contents[51] + ); + assert_eq!( + msg.contents[52], 1, + "incorrect value for contents[52], expected 1, is {}", + msg.contents[52] + ); + assert_eq!( + msg.contents[53], 99, + "incorrect value for contents[53], expected 99, is {}", + msg.contents[53] + ); + assert_eq!( + msg.contents[54], 112, + "incorrect value for contents[54], expected 112, is {}", + msg.contents[54] + ); + assert_eq!( + msg.contents[55], 88, + "incorrect value for contents[55], expected 88, is {}", + msg.contents[55] + ); + assert_eq!( + msg.contents[56], 217, + "incorrect value for contents[56], expected 217, is {}", + msg.contents[56] + ); + assert_eq!( + msg.contents[57], 36, + "incorrect value for contents[57], expected 36, is {}", + msg.contents[57] + ); + assert_eq!( + msg.contents[58], 84, + "incorrect value for contents[58], expected 84, is {}", + msg.contents[58] + ); + assert_eq!( + msg.contents[59], 34, + "incorrect value for contents[59], expected 34, is {}", + msg.contents[59] + ); + assert_eq!( + msg.contents[60], 234, + "incorrect value for contents[60], expected 234, is {}", + msg.contents[60] + ); + assert_eq!( + msg.contents[61], 82, + "incorrect value for contents[61], expected 82, is {}", + msg.contents[61] + ); + assert_eq!( + msg.contents[62], 144, + "incorrect value for contents[62], expected 144, is {}", + msg.contents[62] + ); + assert_eq!( + msg.contents[63], 144, + "incorrect value for contents[63], expected 144, is {}", + msg.contents[63] + ); + assert_eq!( + msg.contents[64], 97, + "incorrect value for contents[64], expected 97, is {}", + msg.contents[64] + ); + assert_eq!( + msg.contents[65], 96, + "incorrect value for contents[65], expected 96, is {}", + msg.contents[65] + ); + assert_eq!( + msg.contents[66], 75, + "incorrect value for contents[66], expected 75, is {}", + msg.contents[66] + ); + assert_eq!( + msg.contents[67], 174, + "incorrect value for contents[67], expected 174, is {}", + msg.contents[67] + ); + assert_eq!( + msg.contents[68], 58, + "incorrect value for contents[68], expected 58, is {}", + msg.contents[68] + ); + assert_eq!( + msg.contents[69], 219, + "incorrect value for contents[69], expected 219, is {}", + msg.contents[69] + ); + assert_eq!( + msg.contents[70], 180, + "incorrect value for contents[70], expected 180, is {}", + msg.contents[70] + ); + assert_eq!( + msg.contents[71], 148, + "incorrect value for contents[71], expected 148, is {}", + msg.contents[71] + ); + assert_eq!( + msg.contents[72], 247, + "incorrect value for contents[72], expected 247, is {}", + msg.contents[72] + ); + assert_eq!( + msg.contents[73], 59, + "incorrect value for contents[73], expected 59, is {}", + msg.contents[73] + ); + assert_eq!( + msg.contents[74], 2, + "incorrect value for contents[74], expected 2, is {}", + msg.contents[74] + ); + assert_eq!( + msg.contents[75], 116, + "incorrect value for contents[75], expected 116, is {}", + msg.contents[75] + ); + assert_eq!( + msg.contents[76], 214, + "incorrect value for contents[76], expected 214, is {}", + msg.contents[76] + ); + assert_eq!( + msg.contents[77], 114, + "incorrect value for contents[77], expected 114, is {}", + msg.contents[77] + ); + assert_eq!( + msg.contents[78], 55, + "incorrect value for contents[78], expected 55, is {}", + msg.contents[78] + ); + assert_eq!( + msg.contents[79], 134, + "incorrect value for contents[79], expected 134, is {}", + msg.contents[79] + ); + assert_eq!( + msg.contents[80], 54, + "incorrect value for contents[80], expected 54, is {}", + msg.contents[80] + ); + assert_eq!( + msg.contents[81], 119, + "incorrect value for contents[81], expected 119, is {}", + msg.contents[81] + ); + assert_eq!( + msg.contents[82], 108, + "incorrect value for contents[82], expected 108, is {}", + msg.contents[82] + ); + assert_eq!( + msg.contents[83], 128, + "incorrect value for contents[83], expected 128, is {}", + msg.contents[83] + ); + assert_eq!( + msg.contents[84], 73, + "incorrect value for contents[84], expected 73, is {}", + msg.contents[84] + ); + assert_eq!( + msg.contents[85], 181, + "incorrect value for contents[85], expected 181, is {}", + msg.contents[85] + ); + assert_eq!( + msg.contents[86], 20, + "incorrect value for contents[86], expected 20, is {}", + msg.contents[86] + ); + assert_eq!( + msg.contents[87], 233, + "incorrect value for contents[87], expected 233, is {}", + msg.contents[87] + ); + assert_eq!( + msg.contents[88], 23, + "incorrect value for contents[88], expected 23, is {}", + msg.contents[88] + ); + assert_eq!( + msg.contents[89], 23, + "incorrect value for contents[89], expected 23, is {}", + msg.contents[89] + ); + assert_eq!( + msg.contents[90], 73, + "incorrect value for contents[90], expected 73, is {}", + msg.contents[90] + ); + assert_eq!( + msg.contents[91], 119, + "incorrect value for contents[91], expected 119, is {}", + msg.contents[91] + ); + assert_eq!( + msg.contents[92], 136, + "incorrect value for contents[92], expected 136, is {}", + msg.contents[92] + ); + assert_eq!( + msg.contents[93], 231, + "incorrect value for contents[93], expected 231, is {}", + msg.contents[93] + ); + assert_eq!( + msg.contents[94], 189, + "incorrect value for contents[94], expected 189, is {}", + msg.contents[94] + ); + assert_eq!( + msg.contents[95], 26, + "incorrect value for contents[95], expected 26, is {}", + msg.contents[95] + ); + assert_eq!( + msg.contents[96], 174, + "incorrect value for contents[96], expected 174, is {}", + msg.contents[96] + ); + assert_eq!( + msg.contents[97], 128, + "incorrect value for contents[97], expected 128, is {}", + msg.contents[97] + ); + assert_eq!( + msg.contents[98], 93, + "incorrect value for contents[98], expected 93, is {}", + msg.contents[98] + ); + assert_eq!( + msg.contents[99], 30, + "incorrect value for contents[99], expected 30, is {}", + msg.contents[99] + ); + assert_eq!( + msg.contents[100], 76, + "incorrect value for contents[100], expected 76, is {}", + msg.contents[100] + ); + assert_eq!( + msg.contents[101], 45, + "incorrect value for contents[101], expected 45, is {}", + msg.contents[101] + ); + assert_eq!( + msg.contents[102], 109, + "incorrect value for contents[102], expected 109, is {}", + msg.contents[102] + ); + assert_eq!( + msg.contents[103], 134, + "incorrect value for contents[103], expected 134, is {}", + msg.contents[103] + ); + assert_eq!( + msg.contents[104], 81, + "incorrect value for contents[104], expected 81, is {}", + msg.contents[104] + ); + assert_eq!( + msg.contents[105], 0, + "incorrect value for contents[105], expected 0, is {}", + msg.contents[105] + ); + assert_eq!( + msg.contents[106], 116, + "incorrect value for contents[106], expected 116, is {}", + msg.contents[106] + ); + assert_eq!( + msg.contents[107], 158, + "incorrect value for contents[107], expected 158, is {}", + msg.contents[107] + ); + assert_eq!( + msg.contents[108], 127, + "incorrect value for contents[108], expected 127, is {}", + msg.contents[108] + ); + assert_eq!( + msg.contents[109], 40, + "incorrect value for contents[109], expected 40, is {}", + msg.contents[109] + ); + assert_eq!( + msg.contents[110], 133, + "incorrect value for contents[110], expected 133, is {}", + msg.contents[110] + ); + assert_eq!( + msg.contents[111], 208, + "incorrect value for contents[111], expected 208, is {}", + msg.contents[111] + ); + assert_eq!( + msg.contents[112], 134, + "incorrect value for contents[112], expected 134, is {}", + msg.contents[112] + ); + assert_eq!( + msg.contents[113], 127, + "incorrect value for contents[113], expected 127, is {}", + msg.contents[113] + ); + assert_eq!( + msg.contents[114], 140, + "incorrect value for contents[114], expected 140, is {}", + msg.contents[114] + ); + assert_eq!( + msg.contents[115], 232, + "incorrect value for contents[115], expected 232, is {}", + msg.contents[115] + ); + assert_eq!( + msg.contents[116], 183, + "incorrect value for contents[116], expected 183, is {}", + msg.contents[116] + ); + assert_eq!( + msg.contents[117], 184, + "incorrect value for contents[117], expected 184, is {}", + msg.contents[117] + ); + assert_eq!( + msg.contents[118], 108, + "incorrect value for contents[118], expected 108, is {}", + msg.contents[118] + ); + assert_eq!( + msg.contents[119], 6, + "incorrect value for contents[119], expected 6, is {}", + msg.contents[119] + ); + assert_eq!( + msg.contents[120], 228, + "incorrect value for contents[120], expected 228, is {}", + msg.contents[120] + ); + assert_eq!( + msg.contents[121], 54, + "incorrect value for contents[121], expected 54, is {}", + msg.contents[121] + ); + assert_eq!( + msg.contents[122], 238, + "incorrect value for contents[122], expected 238, is {}", + msg.contents[122] + ); + assert_eq!( + msg.contents[123], 59, + "incorrect value for contents[123], expected 59, is {}", + msg.contents[123] + ); + assert_eq!( + msg.contents[124], 220, + "incorrect value for contents[124], expected 220, is {}", + msg.contents[124] + ); + assert_eq!( + msg.contents[125], 30, + "incorrect value for contents[125], expected 30, is {}", + msg.contents[125] + ); + assert_eq!( + msg.contents[126], 228, + "incorrect value for contents[126], expected 228, is {}", + msg.contents[126] + ); + assert_eq!( + msg.contents[127], 212, + "incorrect value for contents[127], expected 212, is {}", + msg.contents[127] + ); + assert_eq!( + msg.contents[128], 50, + "incorrect value for contents[128], expected 50, is {}", + msg.contents[128] + ); + assert_eq!( + msg.contents[129], 182, + "incorrect value for contents[129], expected 182, is {}", + msg.contents[129] + ); + assert_eq!( + msg.contents[130], 97, + "incorrect value for contents[130], expected 97, is {}", + msg.contents[130] + ); + assert_eq!( + msg.contents[131], 20, + "incorrect value for contents[131], expected 20, is {}", + msg.contents[131] + ); + assert_eq!( + msg.contents[132], 41, + "incorrect value for contents[132], expected 41, is {}", + msg.contents[132] + ); + assert_eq!( + msg.contents[133], 76, + "incorrect value for contents[133], expected 76, is {}", + msg.contents[133] + ); + assert_eq!( + msg.contents[134], 227, + "incorrect value for contents[134], expected 227, is {}", + msg.contents[134] + ); + assert_eq!( + msg.contents[135], 88, + "incorrect value for contents[135], expected 88, is {}", + msg.contents[135] + ); + assert_eq!( + msg.contents[136], 12, + "incorrect value for contents[136], expected 12, is {}", + msg.contents[136] + ); + assert_eq!( + msg.contents[137], 95, + "incorrect value for contents[137], expected 95, is {}", + msg.contents[137] + ); + assert_eq!( + msg.contents[138], 112, + "incorrect value for contents[138], expected 112, is {}", + msg.contents[138] + ); + assert_eq!( + msg.contents[139], 209, + "incorrect value for contents[139], expected 209, is {}", + msg.contents[139] + ); + assert_eq!( + msg.contents[140], 183, + "incorrect value for contents[140], expected 183, is {}", + msg.contents[140] + ); + assert_eq!( + msg.contents[141], 127, + "incorrect value for contents[141], expected 127, is {}", + msg.contents[141] + ); + assert_eq!( + msg.contents[142], 4, + "incorrect value for contents[142], expected 4, is {}", + msg.contents[142] + ); + assert_eq!( + msg.contents[143], 165, + "incorrect value for contents[143], expected 165, is {}", + msg.contents[143] + ); + assert_eq!( + msg.contents[144], 189, + "incorrect value for contents[144], expected 189, is {}", + msg.contents[144] + ); + assert_eq!( + msg.contents[145], 44, + "incorrect value for contents[145], expected 44, is {}", + msg.contents[145] + ); + assert_eq!( + msg.contents[146], 239, + "incorrect value for contents[146], expected 239, is {}", + msg.contents[146] + ); + assert_eq!( + msg.contents[147], 232, + "incorrect value for contents[147], expected 232, is {}", + msg.contents[147] + ); + assert_eq!( + msg.contents[148], 132, + "incorrect value for contents[148], expected 132, is {}", + msg.contents[148] + ); + assert_eq!( + msg.contents[149], 9, + "incorrect value for contents[149], expected 9, is {}", + msg.contents[149] + ); + assert_eq!( + msg.contents[150], 114, + "incorrect value for contents[150], expected 114, is {}", + msg.contents[150] + ); + assert_eq!( + msg.contents[151], 184, + "incorrect value for contents[151], expected 184, is {}", + msg.contents[151] + ); + assert_eq!( + msg.contents[152], 249, + "incorrect value for contents[152], expected 249, is {}", + msg.contents[152] + ); + assert_eq!( + msg.contents[153], 208, + "incorrect value for contents[153], expected 208, is {}", + msg.contents[153] + ); + assert_eq!( + msg.contents[154], 246, + "incorrect value for contents[154], expected 246, is {}", + msg.contents[154] + ); + assert_eq!( + msg.contents[155], 194, + "incorrect value for contents[155], expected 194, is {}", + msg.contents[155] + ); + assert_eq!( + msg.contents[156], 250, + "incorrect value for contents[156], expected 250, is {}", + msg.contents[156] + ); + assert_eq!( + msg.contents[157], 2, + "incorrect value for contents[157], expected 2, is {}", + msg.contents[157] + ); + assert_eq!( + msg.contents[158], 97, + "incorrect value for contents[158], expected 97, is {}", + msg.contents[158] + ); + assert_eq!( + msg.contents[159], 173, + "incorrect value for contents[159], expected 173, is {}", + msg.contents[159] + ); + assert_eq!( + msg.contents[160], 157, + "incorrect value for contents[160], expected 157, is {}", + msg.contents[160] + ); + assert_eq!( + msg.contents[161], 202, + "incorrect value for contents[161], expected 202, is {}", + msg.contents[161] + ); + assert_eq!( + msg.contents[162], 172, + "incorrect value for contents[162], expected 172, is {}", + msg.contents[162] + ); + assert_eq!( + msg.contents[163], 180, + "incorrect value for contents[163], expected 180, is {}", + msg.contents[163] + ); + assert_eq!( + msg.contents[164], 150, + "incorrect value for contents[164], expected 150, is {}", + msg.contents[164] + ); + assert_eq!( + msg.contents[165], 213, + "incorrect value for contents[165], expected 213, is {}", + msg.contents[165] + ); + assert_eq!( + msg.contents[166], 193, + "incorrect value for contents[166], expected 193, is {}", + msg.contents[166] + ); + assert_eq!( + msg.contents[167], 177, + "incorrect value for contents[167], expected 177, is {}", + msg.contents[167] + ); + assert_eq!( + msg.contents[168], 209, + "incorrect value for contents[168], expected 209, is {}", + msg.contents[168] + ); + assert_eq!( + msg.contents[169], 156, + "incorrect value for contents[169], expected 156, is {}", + msg.contents[169] + ); + assert_eq!( + msg.contents[170], 20, + "incorrect value for contents[170], expected 20, is {}", + msg.contents[170] + ); + assert_eq!( + msg.contents[171], 174, + "incorrect value for contents[171], expected 174, is {}", + msg.contents[171] + ); + assert_eq!( + msg.contents[172], 18, + "incorrect value for contents[172], expected 18, is {}", + msg.contents[172] + ); + assert_eq!( + msg.contents[173], 73, + "incorrect value for contents[173], expected 73, is {}", + msg.contents[173] + ); + assert_eq!( + msg.contents[174], 132, + "incorrect value for contents[174], expected 132, is {}", + msg.contents[174] + ); + assert_eq!( + msg.contents[175], 215, + "incorrect value for contents[175], expected 215, is {}", + msg.contents[175] + ); + assert_eq!( + msg.contents[176], 115, + "incorrect value for contents[176], expected 115, is {}", + msg.contents[176] + ); + assert_eq!( + msg.contents[177], 128, + "incorrect value for contents[177], expected 128, is {}", + msg.contents[177] + ); + assert_eq!( + msg.contents[178], 175, + "incorrect value for contents[178], expected 175, is {}", + msg.contents[178] + ); + assert_eq!( + msg.contents[179], 169, + "incorrect value for contents[179], expected 169, is {}", + msg.contents[179] + ); + assert_eq!( + msg.contents[180], 116, + "incorrect value for contents[180], expected 116, is {}", + msg.contents[180] + ); + assert_eq!( + msg.contents[181], 132, + "incorrect value for contents[181], expected 132, is {}", + msg.contents[181] + ); + assert_eq!( + msg.contents[182], 100, + "incorrect value for contents[182], expected 100, is {}", + msg.contents[182] + ); + assert_eq!( + msg.contents[183], 72, + "incorrect value for contents[183], expected 72, is {}", + msg.contents[183] + ); + assert_eq!( + msg.contents[184], 45, + "incorrect value for contents[184], expected 45, is {}", + msg.contents[184] + ); + assert_eq!( + msg.contents[185], 25, + "incorrect value for contents[185], expected 25, is {}", + msg.contents[185] + ); + assert_eq!( + msg.contents[186], 14, + "incorrect value for contents[186], expected 14, is {}", + msg.contents[186] + ); + assert_eq!( + msg.contents[187], 205, + "incorrect value for contents[187], expected 205, is {}", + msg.contents[187] + ); + assert_eq!( + msg.contents[188], 213, + "incorrect value for contents[188], expected 213, is {}", + msg.contents[188] + ); + assert_eq!( + msg.contents[189], 145, + "incorrect value for contents[189], expected 145, is {}", + msg.contents[189] + ); + assert_eq!( + msg.contents[190], 68, + "incorrect value for contents[190], expected 68, is {}", + msg.contents[190] + ); + assert_eq!( + msg.contents[191], 137, + "incorrect value for contents[191], expected 137, is {}", + msg.contents[191] + ); + assert_eq!( + msg.contents[192], 249, + "incorrect value for contents[192], expected 249, is {}", + msg.contents[192] + ); + assert_eq!( + msg.contents[193], 54, + "incorrect value for contents[193], expected 54, is {}", + msg.contents[193] + ); + assert_eq!( + msg.contents[194], 40, + "incorrect value for contents[194], expected 40, is {}", + msg.contents[194] + ); + assert_eq!( + msg.contents[195], 174, + "incorrect value for contents[195], expected 174, is {}", + msg.contents[195] + ); + assert_eq!( + msg.contents[196], 215, + "incorrect value for contents[196], expected 215, is {}", + msg.contents[196] + ); + assert_eq!( + msg.contents[197], 148, + "incorrect value for contents[197], expected 148, is {}", + msg.contents[197] + ); + assert_eq!( + msg.contents[198], 166, + "incorrect value for contents[198], expected 166, is {}", + msg.contents[198] + ); + assert_eq!( + msg.contents[199], 190, + "incorrect value for contents[199], expected 190, is {}", + msg.contents[199] + ); + assert_eq!( + msg.contents[200], 63, + "incorrect value for contents[200], expected 63, is {}", + msg.contents[200] + ); + assert_eq!( + msg.contents[201], 118, + "incorrect value for contents[201], expected 118, is {}", + msg.contents[201] + ); + assert_eq!( + msg.contents[202], 6, + "incorrect value for contents[202], expected 6, is {}", + msg.contents[202] + ); + assert_eq!( + msg.contents[203], 165, + "incorrect value for contents[203], expected 165, is {}", + msg.contents[203] + ); + assert_eq!( + msg.contents[204], 212, + "incorrect value for contents[204], expected 212, is {}", + msg.contents[204] + ); + assert_eq!( + msg.contents[205], 74, + "incorrect value for contents[205], expected 74, is {}", + msg.contents[205] + ); + assert_eq!( + msg.contents[206], 68, + "incorrect value for contents[206], expected 68, is {}", + msg.contents[206] + ); + assert_eq!( + msg.contents[207], 200, + "incorrect value for contents[207], expected 200, is {}", + msg.contents[207] + ); + assert_eq!( + msg.contents[208], 38, + "incorrect value for contents[208], expected 38, is {}", + msg.contents[208] + ); + assert_eq!( + msg.contents[209], 139, + "incorrect value for contents[209], expected 139, is {}", + msg.contents[209] + ); + assert_eq!( + msg.contents[210], 212, + "incorrect value for contents[210], expected 212, is {}", + msg.contents[210] + ); + assert_eq!( + msg.contents[211], 112, + "incorrect value for contents[211], expected 112, is {}", + msg.contents[211] + ); + assert_eq!( + msg.contents[212], 45, + "incorrect value for contents[212], expected 45, is {}", + msg.contents[212] + ); + assert_eq!( + msg.contents[213], 167, + "incorrect value for contents[213], expected 167, is {}", + msg.contents[213] + ); + assert_eq!( + msg.contents[214], 236, + "incorrect value for contents[214], expected 236, is {}", + msg.contents[214] + ); + assert_eq!( + msg.contents[215], 255, + "incorrect value for contents[215], expected 255, is {}", + msg.contents[215] + ); + assert_eq!( + msg.contents[216], 106, + "incorrect value for contents[216], expected 106, is {}", + msg.contents[216] + ); + assert_eq!( + msg.contents[217], 92, + "incorrect value for contents[217], expected 92, is {}", + msg.contents[217] + ); + assert_eq!( + msg.contents[218], 132, + "incorrect value for contents[218], expected 132, is {}", + msg.contents[218] + ); + assert_eq!( + msg.contents[219], 59, + "incorrect value for contents[219], expected 59, is {}", + msg.contents[219] + ); + assert_eq!( + msg.contents[220], 61, + "incorrect value for contents[220], expected 61, is {}", + msg.contents[220] + ); + assert_eq!( + msg.contents[221], 233, + "incorrect value for contents[221], expected 233, is {}", + msg.contents[221] + ); + assert_eq!( + msg.contents[222], 3, + "incorrect value for contents[222], expected 3, is {}", + msg.contents[222] + ); + assert_eq!( + msg.contents[223], 246, + "incorrect value for contents[223], expected 246, is {}", + msg.contents[223] + ); + assert_eq!( + msg.contents[224], 158, + "incorrect value for contents[224], expected 158, is {}", + msg.contents[224] + ); + assert_eq!( + msg.contents[225], 83, + "incorrect value for contents[225], expected 83, is {}", + msg.contents[225] + ); + assert_eq!( + msg.contents[226], 134, + "incorrect value for contents[226], expected 134, is {}", + msg.contents[226] + ); + assert_eq!( + msg.contents[227], 246, + "incorrect value for contents[227], expected 246, is {}", + msg.contents[227] + ); + assert_eq!( + msg.contents[228], 154, + "incorrect value for contents[228], expected 154, is {}", + msg.contents[228] + ); + assert_eq!( + msg.contents[229], 17, + "incorrect value for contents[229], expected 17, is {}", + msg.contents[229] + ); + assert_eq!( + msg.contents[230], 0, + "incorrect value for contents[230], expected 0, is {}", + msg.contents[230] + ); + assert_eq!( + msg.contents[231], 6, + "incorrect value for contents[231], expected 6, is {}", + msg.contents[231] + ); + assert_eq!( + msg.contents[232], 56, + "incorrect value for contents[232], expected 56, is {}", + msg.contents[232] + ); + assert_eq!( + msg.contents[233], 216, + "incorrect value for contents[233], expected 216, is {}", + msg.contents[233] + ); + assert_eq!( + msg.contents[234], 19, + "incorrect value for contents[234], expected 19, is {}", + msg.contents[234] + ); + assert_eq!( + msg.contents[235], 216, + "incorrect value for contents[235], expected 216, is {}", + msg.contents[235] + ); + assert_eq!( + msg.contents[236], 70, + "incorrect value for contents[236], expected 70, is {}", + msg.contents[236] + ); + assert_eq!( + msg.contents[237], 71, + "incorrect value for contents[237], expected 71, is {}", + msg.contents[237] + ); + assert_eq!( + msg.contents[238], 161, + "incorrect value for contents[238], expected 161, is {}", + msg.contents[238] + ); + assert_eq!( + msg.contents[239], 184, + "incorrect value for contents[239], expected 184, is {}", + msg.contents[239] + ); + assert_eq!( + msg.contents[240], 5, + "incorrect value for contents[240], expected 5, is {}", + msg.contents[240] + ); + assert_eq!( + msg.contents[241], 177, + "incorrect value for contents[241], expected 177, is {}", + msg.contents[241] + ); + assert_eq!( + msg.contents[242], 45, + "incorrect value for contents[242], expected 45, is {}", + msg.contents[242] + ); + assert_eq!( + msg.contents[243], 37, + "incorrect value for contents[243], expected 37, is {}", + msg.contents[243] + ); + assert_eq!( + msg.contents[244], 98, + "incorrect value for contents[244], expected 98, is {}", + msg.contents[244] + ); + assert_eq!( + msg.contents[245], 56, + "incorrect value for contents[245], expected 56, is {}", + msg.contents[245] + ); + assert_eq!( + msg.contents[246], 149, + "incorrect value for contents[246], expected 149, is {}", + msg.contents[246] + ); + assert_eq!( + msg.contents[247], 0, + "incorrect value for contents[247], expected 0, is {}", + msg.contents[247] + ); + assert_eq!( + msg.contents[248], 73, + "incorrect value for contents[248], expected 73, is {}", + msg.contents[248] + ); + assert_eq!( + msg.contents[249], 221, + "incorrect value for contents[249], expected 221, is {}", + msg.contents[249] + ); + assert_eq!( + msg.contents[250], 105, + "incorrect value for contents[250], expected 105, is {}", + msg.contents[250] + ); + assert_eq!( + msg.contents[251], 239, + "incorrect value for contents[251], expected 239, is {}", + msg.contents[251] + ); + assert_eq!( + msg.contents[252], 168, + "incorrect value for contents[252], expected 168, is {}", + msg.contents[252] + ); + assert_eq!( + msg.contents[253], 205, + "incorrect value for contents[253], expected 205, is {}", + msg.contents[253] + ); + assert_eq!( + msg.contents[254], 85, + "incorrect value for contents[254], expected 85, is {}", + msg.contents[254] + ); + } + _ => panic!("Invalid message type! Expected a MsgUserData"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/auto_check_sbp_vehicle_msg_wheeltick.rs b/rust/sbp/tests/integration/auto_check_sbp_vehicle_msg_wheeltick.rs new file mode 100644 index 0000000000..7b4c53d819 --- /dev/null +++ b/rust/sbp/tests/integration/auto_check_sbp_vehicle_msg_wheeltick.rs @@ -0,0 +1,227 @@ +// +// Copyright (C) 2019-2021 Swift Navigation Inc. +// Contact: https://support.swiftnav.com +// +// This source is subject to the license found in the file 'LICENSE' which must +// be be distributed together with this source. All other rights reserved. +// +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. + +// This file was auto-generated from spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml by generate.py. Do not modify by hand! + +use crate::*; + +/// Tests [`sbp::iter_messages`], from payload into SBP messages +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +fn test_auto_check_sbp_vehicle_msg_wheeltick() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + ]); + + // Test the round trip payload parsing + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + match &sbp_msg { + sbp::messages::Sbp::MsgWheeltick(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x904, + "Incorrect message type, expected 0x904, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x456b, + "incorrect sender id, expected 0x456b, is {sender_id}" + ); + assert_eq!( + msg.flags, 1, + "incorrect value for flags, expected 1, is {}", + msg.flags + ); + assert_eq!( + msg.source, 146, + "incorrect value for source, expected 146, is {}", + msg.source + ); + assert_eq!( + msg.ticks, -771148831, + "incorrect value for ticks, expected -771148831, is {}", + msg.ticks + ); + assert_eq!( + msg.time, 112414825470, + "incorrect value for time, expected 112414825470, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgWheeltick"), + }; + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} + +/// Tests [`sbp::json::iter_messages`] for JSON payload -> SBP message +/// and [`sbp::json::iter_messages_from_fields`] for JSON fields -> SBP message. +/// +/// Asserts: +/// - SBP message constructed via payload is identical to from fields +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_json2sbp_auto_check_sbp_vehicle_msg_wheeltick() { + { + let json_input = r#"{"preamble":85,"msg_type":2308,"sender":17771,"length":14,"payload":"/htyLBoAAAABkuEzCdI=","crc":14372,"time":112414825470,"flags":1,"source":146,"ticks":-771148831}"#.as_bytes(); + + let sbp_msg = { + // JSON to SBP message from payload + let mut iter = json2sbp_iter_msg(json_input); + let from_payload = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + // JSON to SBP message from fields + let mut iter = iter_messages_from_fields(json_input); + let from_fields = iter + .next() + .expect("no message found") + .expect("failed to parse message"); + + assert_eq!(from_fields, from_payload); + from_fields + }; + match &sbp_msg { + sbp::messages::Sbp::MsgWheeltick(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x904, + "Incorrect message type, expected 0x904, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x456b, + "incorrect sender id, expected 0x456b, is {sender_id}" + ); + assert_eq!( + msg.flags, 1, + "incorrect value for flags, expected 1, is {}", + msg.flags + ); + assert_eq!( + msg.source, 146, + "incorrect value for source, expected 146, is {}", + msg.source + ); + assert_eq!( + msg.ticks, -771148831, + "incorrect value for ticks, expected -771148831, is {}", + msg.ticks + ); + assert_eq!( + msg.time, 112414825470, + "incorrect value for time, expected 112414825470, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgWheeltick"), + }; + } +} + +/// Tests [`sbp::json::JsonEncoder`] for roundtrip SBP message -> JSON +/// +/// Assumes: +/// - [`self::test_auto_check_sbp_vehicle_msg_wheeltick`] passes +/// +/// Asserts: +/// - SBP fields equates to that of the field +/// - Payload is identical +#[test] +#[cfg(feature = "json")] +fn test_sbp2json_auto_check_sbp_vehicle_msg_wheeltick() { + { + let mut payload = Cursor::new(vec![ + 85, 4, 9, 107, 69, 14, 254, 27, 114, 44, 26, 0, 0, 0, 1, 146, 225, 51, 9, 210, 36, 56, + ]); + + // Construct sbp message + let sbp_msg = { + let mut msgs = iter_messages(&mut payload); + msgs.next() + .expect("no message found") + .expect("failed to parse message") + }; + + let mut json_buffer = vec![]; + // Populate json buffer, CompactFormatter + sbp::json::JsonEncoder::new(&mut json_buffer, sbp::json::CompactFormatter {}) + .send(&sbp_msg) + .unwrap(); + + // Reconstruct Sbp message from json fields, roundtrip + let sbp_msg = sbp::messages::Sbp::MsgWheeltick( + serde_json::from_str( + std::str::from_utf8(json_buffer.as_slice()) + .unwrap() + .to_string() + .as_str(), + ) + .unwrap(), + ); + match &sbp_msg { + sbp::messages::Sbp::MsgWheeltick(msg) => { + let msg_type = msg.message_type().unwrap(); + assert_eq!( + msg_type, 0x904, + "Incorrect message type, expected 0x904, is {}", + msg_type + ); + let sender_id = msg.sender_id().unwrap(); + assert_eq!( + sender_id, 0x456b, + "incorrect sender id, expected 0x456b, is {sender_id}" + ); + assert_eq!( + msg.flags, 1, + "incorrect value for flags, expected 1, is {}", + msg.flags + ); + assert_eq!( + msg.source, 146, + "incorrect value for source, expected 146, is {}", + msg.source + ); + assert_eq!( + msg.ticks, -771148831, + "incorrect value for ticks, expected -771148831, is {}", + msg.ticks + ); + assert_eq!( + msg.time, 112414825470, + "incorrect value for time, expected 112414825470, is {}", + msg.time + ); + } + _ => panic!("Invalid message type! Expected a MsgWheeltick"), + }; + + // Check payload is still identical + let frame = sbp::to_vec(&sbp_msg).unwrap(); + assert_eq!(frame, payload.into_inner()); + } +} diff --git a/rust/sbp/tests/integration/main.rs b/rust/sbp/tests/integration/main.rs index e6cc01ca47..088892b7e5 100644 --- a/rust/sbp/tests/integration/main.rs +++ b/rust/sbp/tests/integration/main.rs @@ -12,14 +12,40 @@ // This file was auto-generated. Do not modify by hand! #![allow(clippy::excessive_precision)] +mod auto_check_sbp_acquisition_msg_acq_result; mod auto_check_sbp_acquisition_msg_acq_result_dep_a; mod auto_check_sbp_acquisition_msg_acq_result_dep_b; mod auto_check_sbp_acquisition_msg_acq_result_dep_c; +mod auto_check_sbp_acquisition_msg_acq_sv_profile; +mod auto_check_sbp_acquisition_msg_acq_sv_profile_dep; +mod auto_check_sbp_bootload_msg_bootloader_handshake_req; mod auto_check_sbp_bootload_msg_bootloader_handshake_resp; +mod auto_check_sbp_bootload_msg_bootloader_jumpto_app; +mod auto_check_sbp_bootload_msg_nap_device_dna_req; +mod auto_check_sbp_bootload_msg_nap_device_dna_resp; mod auto_check_sbp_ext_events_msg_ext_event; +mod auto_check_sbp_file_io_msg_fileio_config_req; +mod auto_check_sbp_file_io_msg_fileio_config_resp; +mod auto_check_sbp_file_io_msg_fileio_read_dir_req; +mod auto_check_sbp_file_io_msg_fileio_read_dir_resp; +mod auto_check_sbp_file_io_msg_fileio_read_req; +mod auto_check_sbp_file_io_msg_fileio_read_resp; +mod auto_check_sbp_file_io_msg_fileio_remove; mod auto_check_sbp_file_io_msg_fileio_write_resp; +mod auto_check_sbp_flash_msg_flash_done; +mod auto_check_sbp_flash_msg_flash_erase; +mod auto_check_sbp_flash_msg_flash_program; +mod auto_check_sbp_flash_msg_flash_read_req; +mod auto_check_sbp_flash_msg_flash_read_resp; +mod auto_check_sbp_flash_msg_m25_flash_write_status; +mod auto_check_sbp_flash_msg_stm_flash_lock_sector; +mod auto_check_sbp_flash_msg_stm_flash_unlock_sector; +mod auto_check_sbp_flash_msg_stm_unique_id_req; +mod auto_check_sbp_flash_msg_stm_unique_id_resp; +mod auto_check_sbp_gnss_gnss_structs; mod auto_check_sbp_imu_msg_imu_aux; mod auto_check_sbp_imu_msg_imu_raw; +mod auto_check_sbp_integrity_integrity_structs; mod auto_check_sbp_integrity_msg_acknowledge; mod auto_check_sbp_integrity_msg_ssr_flag_high_level; mod auto_check_sbp_integrity_msg_ssr_flag_iono_grid_point_sat_los; @@ -27,12 +53,25 @@ mod auto_check_sbp_integrity_msg_ssr_flag_iono_grid_points; mod auto_check_sbp_integrity_msg_ssr_flag_iono_tile_sat_los; mod auto_check_sbp_integrity_msg_ssr_flag_satellites; mod auto_check_sbp_integrity_msg_ssr_flag_tropo_grid_points; +mod auto_check_sbp_linux_msg_linux_cpu_state; +mod auto_check_sbp_linux_msg_linux_cpu_state_dep_a; +mod auto_check_sbp_linux_msg_linux_mem_state; +mod auto_check_sbp_linux_msg_linux_mem_state_dep_a; +mod auto_check_sbp_linux_msg_linux_process_fd_count; +mod auto_check_sbp_linux_msg_linux_process_fd_summary; +mod auto_check_sbp_linux_msg_linux_process_socket_counts; +mod auto_check_sbp_linux_msg_linux_process_socket_queues; +mod auto_check_sbp_linux_msg_linux_socket_usage; +mod auto_check_sbp_linux_msg_linux_sys_state; +mod auto_check_sbp_linux_msg_linux_sys_state_dep_a; mod auto_check_sbp_logging_msg_fwd; mod auto_check_sbp_logging_msg_log; mod auto_check_sbp_logging_msg_print_dep; +mod auto_check_sbp_mag_msg_mag_raw; mod auto_check_sbp_navigation_msg_age_corrections; mod auto_check_sbp_navigation_msg_baseline_ecef; mod auto_check_sbp_navigation_msg_baseline_ecef_dep_a; +mod auto_check_sbp_navigation_msg_baseline_heading_dep_a; mod auto_check_sbp_navigation_msg_baseline_ned; mod auto_check_sbp_navigation_msg_baseline_ned_dep_a; mod auto_check_sbp_navigation_msg_dops; @@ -46,12 +85,14 @@ mod auto_check_sbp_navigation_msg_pos_ecef_cov_gnss; mod auto_check_sbp_navigation_msg_pos_ecef_dep_a; mod auto_check_sbp_navigation_msg_pos_ecefgnss; mod auto_check_sbp_navigation_msg_pos_llh; +mod auto_check_sbp_navigation_msg_pos_llh_acc; mod auto_check_sbp_navigation_msg_pos_llh_cov; mod auto_check_sbp_navigation_msg_pos_llh_cov_gnss; mod auto_check_sbp_navigation_msg_pos_llh_dep_a; mod auto_check_sbp_navigation_msg_pos_llh_gnss; mod auto_check_sbp_navigation_msg_pose_relative; mod auto_check_sbp_navigation_msg_protection_level; +mod auto_check_sbp_navigation_msg_protection_level_dep_a; mod auto_check_sbp_navigation_msg_reference_frame_param; mod auto_check_sbp_navigation_msg_utc_leap_second; mod auto_check_sbp_navigation_msg_utc_time; @@ -68,32 +109,88 @@ mod auto_check_sbp_navigation_msg_vel_ned_cov_gnss; mod auto_check_sbp_navigation_msg_vel_ned_dep_a; mod auto_check_sbp_navigation_msg_vel_ned_gnss; mod auto_check_sbp_navigation_msg_vel_nedcov; +mod auto_check_sbp_navigation_navigation_structs; +mod auto_check_sbp_ndb_msg_ndb_event; +mod auto_check_sbp_observation_msg_almanac_glo; +mod auto_check_sbp_observation_msg_almanac_glo_dep; +mod auto_check_sbp_observation_msg_almanac_gps; +mod auto_check_sbp_observation_msg_almanac_gps_dep; mod auto_check_sbp_observation_msg_base_pos_ecef; +mod auto_check_sbp_observation_msg_base_pos_llh; mod auto_check_sbp_observation_msg_ephemeris_bds; +mod auto_check_sbp_observation_msg_ephemeris_dep_a; mod auto_check_sbp_observation_msg_ephemeris_dep_b; +mod auto_check_sbp_observation_msg_ephemeris_dep_c; +mod auto_check_sbp_observation_msg_ephemeris_dep_d; mod auto_check_sbp_observation_msg_ephemeris_gal; +mod auto_check_sbp_observation_msg_ephemeris_gal_dep_a; mod auto_check_sbp_observation_msg_ephemeris_glo; +mod auto_check_sbp_observation_msg_ephemeris_glo_dep_a; +mod auto_check_sbp_observation_msg_ephemeris_glo_dep_b; +mod auto_check_sbp_observation_msg_ephemeris_glo_dep_c; +mod auto_check_sbp_observation_msg_ephemeris_glo_dep_d; mod auto_check_sbp_observation_msg_ephemeris_gps; +mod auto_check_sbp_observation_msg_ephemeris_gps_dep_e; +mod auto_check_sbp_observation_msg_ephemeris_gps_dep_f; mod auto_check_sbp_observation_msg_ephemeris_qzss; +mod auto_check_sbp_observation_msg_ephemeris_sbas; +mod auto_check_sbp_observation_msg_ephemeris_sbas_dep_a; +mod auto_check_sbp_observation_msg_ephemeris_sbas_dep_b; mod auto_check_sbp_observation_msg_glo_biases; +mod auto_check_sbp_observation_msg_gnss_capb; +mod auto_check_sbp_observation_msg_group_delay; +mod auto_check_sbp_observation_msg_group_delay_dep_a; +mod auto_check_sbp_observation_msg_group_delay_dep_b; +mod auto_check_sbp_observation_msg_iono; mod auto_check_sbp_observation_msg_obs; mod auto_check_sbp_observation_msg_obs_dep_a; mod auto_check_sbp_observation_msg_obs_dep_b; mod auto_check_sbp_observation_msg_obs_dep_c; mod auto_check_sbp_observation_msg_osr; mod auto_check_sbp_observation_msg_sv_az_el; +mod auto_check_sbp_observation_msg_sv_configuration_gps_dep; +mod auto_check_sbp_observation_observation_structs; mod auto_check_sbp_orientation_msg_angular_rate; +mod auto_check_sbp_orientation_msg_baseline_heading; mod auto_check_sbp_orientation_msg_orient_euler; mod auto_check_sbp_orientation_msg_orient_quat; +mod auto_check_sbp_piksi_msg_almanac; +mod auto_check_sbp_piksi_msg_cell_modem_status; +mod auto_check_sbp_piksi_msg_command_output; +mod auto_check_sbp_piksi_msg_command_req; +mod auto_check_sbp_piksi_msg_command_resp; +mod auto_check_sbp_piksi_msg_cw_results; +mod auto_check_sbp_piksi_msg_cw_start; mod auto_check_sbp_piksi_msg_device_monitor; +mod auto_check_sbp_piksi_msg_front_end_gain; mod auto_check_sbp_piksi_msg_iar_state; +mod auto_check_sbp_piksi_msg_init_base_dep; +mod auto_check_sbp_piksi_msg_mask_satellite; +mod auto_check_sbp_piksi_msg_mask_satellite_dep; mod auto_check_sbp_piksi_msg_network_bandwidth_usage; +mod auto_check_sbp_piksi_msg_network_state_req; +mod auto_check_sbp_piksi_msg_network_state_resp; +mod auto_check_sbp_piksi_msg_reset; +mod auto_check_sbp_piksi_msg_reset_dep; +mod auto_check_sbp_piksi_msg_reset_filters; +mod auto_check_sbp_piksi_msg_set_time; +mod auto_check_sbp_piksi_msg_specan; +mod auto_check_sbp_piksi_msg_specan_dep; mod auto_check_sbp_piksi_msg_thread_state; mod auto_check_sbp_piksi_msg_uart_state; mod auto_check_sbp_piksi_msg_uart_state_dep_a; +mod auto_check_sbp_piksi_piksi_structs; mod auto_check_sbp_sbas_msg_sbas_raw; mod auto_check_sbp_settings_msg_settings_read_by_index_done; +mod auto_check_sbp_settings_msg_settings_read_by_index_req; mod auto_check_sbp_settings_msg_settings_read_by_index_resp; +mod auto_check_sbp_settings_msg_settings_read_req; +mod auto_check_sbp_settings_msg_settings_read_resp; +mod auto_check_sbp_settings_msg_settings_register; +mod auto_check_sbp_settings_msg_settings_register_resp; +mod auto_check_sbp_settings_msg_settings_save; +mod auto_check_sbp_settings_msg_settings_write; +mod auto_check_sbp_settings_msg_settings_write_resp; mod auto_check_sbp_signing_msg_certificate_chain; mod auto_check_sbp_signing_msg_certificate_chain_dep; mod auto_check_sbp_signing_msg_ecdsa_certificate; @@ -103,28 +200,61 @@ mod auto_check_sbp_signing_msg_ecdsa_signature_dep_b; mod auto_check_sbp_signing_msg_ed25519_certificate_dep; mod auto_check_sbp_signing_msg_ed25519_signature_dep_a; mod auto_check_sbp_signing_msg_ed25519_signature_dep_b; +mod auto_check_sbp_signing_signing_structs; +mod auto_check_sbp_soln_meta_soln_meta_structs; +mod auto_check_sbp_solution_meta_msg_soln_meta; +mod auto_check_sbp_solution_meta_msg_soln_meta_dep_a; +mod auto_check_sbp_ssr_msg_ssr_code_biases; mod auto_check_sbp_ssr_msg_ssr_code_phase_biases_bounds; +mod auto_check_sbp_ssr_msg_ssr_grid_definition_dep_a; +mod auto_check_sbp_ssr_msg_ssr_gridded_correction; mod auto_check_sbp_ssr_msg_ssr_gridded_correction_bounds; +mod auto_check_sbp_ssr_msg_ssr_gridded_correction_dep_a; +mod auto_check_sbp_ssr_msg_ssr_gridded_correction_no_std_dep_a; +mod auto_check_sbp_ssr_msg_ssr_orbit_clock; mod auto_check_sbp_ssr_msg_ssr_orbit_clock_bounds; mod auto_check_sbp_ssr_msg_ssr_orbit_clock_bounds_degradation; +mod auto_check_sbp_ssr_msg_ssr_orbit_clock_dep_a; +mod auto_check_sbp_ssr_msg_ssr_phase_biases; mod auto_check_sbp_ssr_msg_ssr_satellite_apc; +mod auto_check_sbp_ssr_msg_ssr_satellite_apc_dep_a; mod auto_check_sbp_ssr_msg_ssr_stec_correction; +mod auto_check_sbp_ssr_msg_ssr_stec_correction_dep; +mod auto_check_sbp_ssr_msg_ssr_stec_correction_dep_a; mod auto_check_sbp_ssr_msg_ssr_tile_definition; +mod auto_check_sbp_ssr_msg_ssr_tile_definition_dep_a; mod auto_check_sbp_ssr_msg_ssr_tile_definition_dep_b; +mod auto_check_sbp_ssr_ssr_structs; +mod auto_check_sbp_system_msg_csac_telemetry; +mod auto_check_sbp_system_msg_csac_telemetry_labels; mod auto_check_sbp_system_msg_dgnss_status; +mod auto_check_sbp_system_msg_gnss_time_offset; mod auto_check_sbp_system_msg_group_meta; mod auto_check_sbp_system_msg_heartbeat; mod auto_check_sbp_system_msg_ins_status; mod auto_check_sbp_system_msg_ins_updates; +mod auto_check_sbp_system_msg_pps_time; mod auto_check_sbp_system_msg_sensor_aid_event; mod auto_check_sbp_system_msg_startup; mod auto_check_sbp_system_msg_status_journal; +mod auto_check_sbp_system_msg_status_report; +mod auto_check_sbp_system_system_structs; +mod auto_check_sbp_telemetry_acquisition_structs; mod auto_check_sbp_telemetry_msg_tel_sv; +mod auto_check_sbp_telemetry_telemetry_structs; mod auto_check_sbp_tracking_msg_measurement_state; +mod auto_check_sbp_tracking_msg_tracking_iq; +mod auto_check_sbp_tracking_msg_tracking_iq_dep_a; +mod auto_check_sbp_tracking_msg_tracking_iq_dep_b; mod auto_check_sbp_tracking_msg_tracking_state; +mod auto_check_sbp_tracking_msg_tracking_state_dep_b; mod auto_check_sbp_tracking_msg_tracking_state_detailed_dep; +mod auto_check_sbp_tracking_msg_tracking_state_detailed_dep_a; mod auto_check_sbp_tracking_msgtracking_state_dep_a; +mod auto_check_sbp_tracking_tracking_structs; +mod auto_check_sbp_user_msg_user_data; mod auto_check_sbp_vehicle_msg_odometry; +mod auto_check_sbp_vehicle_msg_wheeltick; pub use std::io::Cursor; diff --git a/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml new file mode 100644 index 0000000000..713d24385f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml @@ -0,0 +1,25 @@ +description: Unit tests for swiftnav.sbp.acquisition MsgAcqResult +generated_on: 2023-11-15 # manually generated +package: sbp.acquisition +tests: + +- msg: + fields: + cf: 8241.2001953125 + cn0: 14.5 + cp: 72.19999694824219 + sid: + code: 0 + sat: 8 + module: sbp.acquisition + name: MsgAcqResult + msg_type: '0x2f' + raw_json: '{"preamble":85,"msg_type":47,"sender":1219,"length":14,"payload":"AABoQWZmkELNxABGCAA=","crc":48591,"cn0":14.5,"cp":72.19999694824219,"cf":8241.2001953125,"sid":{"sat":8,"code":0}}' + raw_packet: VS8AwwQOAABoQWZmkELNxABGCADPvQ== + sbp: + crc: '0xbdcf' + length: 14 + msg_type: '0x2f' + payload: AABoQWZmkELNxABGCAA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml new file mode 100644 index 0000000000..f919440bef --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml @@ -0,0 +1,67 @@ +description: Unit tests for swiftnav.sbp.acquisition MsgAcqSvProfile +generated_on: 2023-11-15 # manually generated +package: sbp.acquisition +tests: + +- msg: + c_decoded_fields: + n_acq_sv_profile: + handle_as: vararray-len + related_to: acq_sv_profile + value: 3 + fields: + acq_sv_profile: + - bin_width: 174 + cf: 47 + cf_max: 147 + cf_min: 61 + cn0: 38 + cp: 140 + int_time: 97 + job_type: 7 + sid: + code: 0 + sat: 22 + status: 13 + time_spent: 49 + timestamp: 52 + - bin_width: 121 + cf: 237 + cf_max: 142 + cf_min: 175 + cn0: 59 + cp: 12 + int_time: 253 + job_type: 166 + sid: + code: 1 + sat: 23 + status: 210 + time_spent: 175 + timestamp: 190 + - bin_width: 8 + cf: 84 + cf_max: 191 + cf_min: 91 + cn0: 21 + cp: 82 + int_time: 153 + job_type: 126 + sid: + code: 0 + sat: 24 + status: 88 + time_spent: 172 + timestamp: 130 + module: sbp.acquisition + name: MsgAcqSvProfile + msg_type: '0x2e' + raw_json: '{"crc":45480,"length":99,"msg_type":46,"payload":"Bw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAA","preamble":85,"sender":1219,"acq_sv_profile":[{"job_type":7,"status":13,"cn0":38,"int_time":97,"sid":{"sat":22,"code":0},"bin_width":174,"timestamp":52,"time_spent":49,"cf_min":61,"cf_max":147,"cf":47,"cp":140},{"job_type":166,"status":210,"cn0":59,"int_time":253,"sid":{"sat":23,"code":1},"bin_width":121,"timestamp":190,"time_spent":175,"cf_min":175,"cf_max":142,"cf":237,"cp":12},{"job_type":126,"status":88,"cn0":21,"int_time":153,"sid":{"sat":24,"code":0},"bin_width":8,"timestamp":130,"time_spent":172,"cf_min":91,"cf_max":191,"cf":84,"cp":82}]}' + raw_packet: VS4AwwRjBw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAAqLE= + sbp: + crc: '0xb1a8' + length: 99 + msg_type: '0x2e' + payload: Bw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAA + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml new file mode 100644 index 0000000000..7bb457b992 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml @@ -0,0 +1,70 @@ +description: Unit tests for swiftnav.sbp.acquisition MsgAcqSvProfileDep +generated_on: 2023-11-15 # manually generated +package: sbp.acquisition +tests: + +- msg: + c_decoded_fields: + n_acq_sv_profile: + handle_as: vararray-len + related_to: acq_sv_profile + value: 3 + fields: + acq_sv_profile: + - bin_width: 187 + cf: 60 + cf_max: 36 + cf_min: 132 + cn0: 151 + cp: 241 + int_time: 12 + job_type: 67 + sid: + code: 0 + reserved: 0 + sat: 22 + status: 103 + time_spent: 75 + timestamp: 91 + - bin_width: 176 + cf: 212 + cf_max: 24 + cf_min: 155 + cn0: 111 + cp: 247 + int_time: 179 + job_type: 238 + sid: + code: 1 + reserved: 0 + sat: 23 + status: 38 + time_spent: 234 + timestamp: 166 + - bin_width: 52 + cf: 212 + cf_max: 248 + cf_min: 76 + cn0: 68 + cp: 101 + int_time: 53 + job_type: 142 + sid: + code: 0 + reserved: 0 + sat: 24 + status: 213 + time_spent: 245 + timestamp: 49 + module: sbp.acquisition + name: MsgAcqSvProfileDep + msg_type: '0x1e' + raw_json: '{"crc":33859,"length":105,"msg_type":30,"payload":"Q2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAA","preamble":85,"sender":1219,"acq_sv_profile":[{"job_type":67,"status":103,"cn0":151,"int_time":12,"sid":{"sat":22,"code":0,"reserved":0},"bin_width":187,"timestamp":91,"time_spent":75,"cf_min":132,"cf_max":36,"cf":60,"cp":241},{"job_type":238,"status":38,"cn0":111,"int_time":179,"sid":{"sat":23,"code":1,"reserved":0},"bin_width":176,"timestamp":166,"time_spent":234,"cf_min":155,"cf_max":24,"cf":212,"cp":247},{"job_type":142,"status":213,"cn0":68,"int_time":53,"sid":{"sat":24,"code":0,"reserved":0},"bin_width":52,"timestamp":49,"time_spent":245,"cf_min":76,"cf_max":248,"cf":212,"cp":101}]}' + raw_packet: VR4AwwRpQ2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAAQ4Q= + sbp: + crc: '0x8443' + length: 105 + msg_type: '0x1e' + payload: Q2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAA + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/acquisition/test_acquisition_structs.yaml b/spec/tests/yaml/swiftnav/sbp/acquisition/test_acquisition_structs.yaml new file mode 100644 index 0000000000..f04ed96cc1 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/acquisition/test_acquisition_structs.yaml @@ -0,0 +1,39 @@ +description: Unit tests for swiftnav.sbp.telemetry free structs +generated_on: 2023-11-15 # manually generated +package: sbp.telemetry +struct_tests: + + - encoded: Hm3MF+B9/7i6rqsBr2lY6AaJU+2Rxn3rSXG2kQSg7xY4 + fields: + job_type: 30 + status: 109 + cn0: 6092 + int_time: 224 + sid.sat: 125 + sid.code: 255 + bin_width: 47800 + timestamp: 2936122286 + time_spent: 115890281 + cf_min: -1846717559 + cf_max: 1240169926 + cf: 76658289 + cp: 941027232 + module: sbp.acquisition + name: AcqSvProfile + - encoded: ZHLeDuRUTJkALZwYwezRZHIk1yLlA4s96LN/fNM3J50z3qE= + fields: + job_type: 100 + status: 114 + cn0: 3806 + int_time: 228 + sid.sat: 19540 + sid.code: 153 + bin_width: 39981 + timestamp: 3521954072 + time_spent: 3609490020 + cf_min: -1962679006 + cf_max: 2142496829 + cf: 657970044 + cp: 2715693981 + module: sbp.acquisition + name: AcqSvProfileDep diff --git a/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml new file mode 100644 index 0000000000..141b834ee8 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.bootload MsgBootloaderHandshakeReq +generated_on: 2023-11-15 # manually generated +package: sbp.bootload +tests: + +- msg: + fields: + {} + module: sbp.bootload + name: MsgBootloaderHandshakeReq + msg_type: '0xb3' + raw_json: '{"crc":55361,"length":0,"msg_type":179,"payload":"","preamble":85,"sender":63368}' + raw_packet: VbMAiPcAQdg= + sbp: + crc: '0xd841' + length: 0 + msg_type: '0xb3' + payload: "" + preamble: '0x55' + sender: '0xf788' diff --git a/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml new file mode 100644 index 0000000000..80055aa960 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderJumptoApp.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.bootload MsgBootloaderJumpToApp +generated_on: 2023-11-15 # manually generated +package: sbp.bootload +tests: + +- msg: + fields: + jump: 216 + module: sbp.bootload + name: MsgBootloaderJumpToApp + msg_type: '0xb1' + raw_json: '{"crc":24681,"length":1,"msg_type":177,"payload":"2A==","preamble":85,"sender":4813,"jump":216}' + raw_packet: VbEAzRIB2Glg + sbp: + crc: '0x6069' + length: 1 + msg_type: '0xb1' + payload: 2A== + preamble: '0x55' + sender: '0x12cd' diff --git a/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml new file mode 100644 index 0000000000..3433ce26e3 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.bootload MsgNapDeviceDnaReq +generated_on: 2023-11-15 # manually generated +package: sbp.bootload +tests: + +- msg: + fields: + {} + module: sbp.bootload + name: MsgNapDeviceDnaReq + msg_type: '0xde' + raw_json: '{"crc":41191,"length":0,"msg_type":222,"payload":"","preamble":85,"sender":12928}' + raw_packet: Vd4AgDIA56A= + sbp: + crc: '0xa0e7' + length: 0 + msg_type: '0xde' + payload: "" + preamble: '0x55' + sender: '0x3280' diff --git a/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml new file mode 100644 index 0000000000..7ed4fc8a5f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/bootload/test_MsgNapDeviceDnaResp.yaml @@ -0,0 +1,28 @@ +description: Unit tests for swiftnav.sbp.bootload MsgNapDeviceDnaResp +generated_on: 2023-11-15 # manually generated +package: sbp.bootload +tests: + +- msg: + fields: + dna: + - 2 + - 187 + - 1 + - 130 + - 173 + - 244 + - 67 + - 122 + module: sbp.bootload + name: MsgNapDeviceDnaResp + msg_type: '0xdd' + raw_json: '{"crc":23366,"length":8,"msg_type":221,"payload":"ArsBgq30Q3o=","preamble":85,"sender":14505,"dna":[2,187,1,130,173,244,67,122]}' + raw_packet: Vd0AqTgIArsBgq30Q3pGWw== + sbp: + crc: '0x5b46' + length: 8 + msg_type: '0xdd' + payload: ArsBgq30Q3o= + preamble: '0x55' + sender: '0x38a9' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml new file mode 100644 index 0000000000..3b416ff023 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioConfigReq +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + fields: + sequence: 1514527339 + module: sbp.file_io + name: MsgFileioConfigReq + msg_type: '0x1001' + raw_json: '{"preamble":85,"msg_type":4097,"sender":1219,"length":4,"payload":"a9pFWg==","crc":7097,"sequence":1514527339}' + raw_packet: VQEQwwQEa9pFWrkb + sbp: + crc: '0x1bb9' + length: 4 + msg_type: '0x1001' + payload: a9pFWg== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml new file mode 100644 index 0000000000..247551c4fe --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioConfigResp.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioConfigResp +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + fields: + batch_size: 1040160728 + fileio_version: 2420269324 + sequence: 1530154154 + window_size: 53262997 + module: sbp.file_io + name: MsgFileioConfigResp + msg_type: '0x1002' + raw_json: '{"preamble":85,"msg_type":4098,"sender":1219,"length":16,"payload":"qkw0W5W6LAPYl/89DGFCkA==","crc":29679,"sequence":1530154154,"window_size":53262997,"batch_size":1040160728,"fileio_version":2420269324}' + raw_packet: VQIQwwQQqkw0W5W6LAPYl/89DGFCkO9z + sbp: + crc: '0x73ef' + length: 16 + msg_type: '0x1002' + payload: qkw0W5W6LAPYl/89DGFCkA== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml new file mode 100644 index 0000000000..be3fa6d62d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirReq.yaml @@ -0,0 +1,28 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioReadDirReq +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + c_decoded_fields: + dirname: + handle_as: encoded-string + encoded_len: 18 + fn_prefix: sbp_msg_fileio_read_dir_req_dirname + text: "/some/random/path" + fields: + dirname: "/some/random/path\0" + offset: 2251261636 + sequence: 1526720386 + module: sbp.file_io + name: MsgFileioReadDirReq + msg_type: '0xa9' + raw_json: '{"preamble":85,"msg_type":169,"sender":1219,"length":26,"payload":"guf/WsSGL4Yvc29tZS9yYW5kb20vcGF0aAA=","crc":47642,"sequence":1526720386,"offset":2251261636,"dirname":"/some/random/path\u0000"}' + raw_packet: VakAwwQaguf/WsSGL4Yvc29tZS9yYW5kb20vcGF0aAAaug== + sbp: + crc: '0xba1a' + length: 26 + msg_type: '0xa9' + payload: guf/WsSGL4Yvc29tZS9yYW5kb20vcGF0aAA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml new file mode 100644 index 0000000000..0af5fa51dc --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadDirResp.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioReadDirResp +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + c_decoded_fields: + contents: + handle_as: encoded-string + encoded_len: 41 + fn_prefix: sbp_msg_fileio_read_dir_resp_contents + min_len: 1 + sections: + - file1 + - another file + - definitely not a file + fields: + contents: "file1\0another file\0definitely not a file\0" + sequence: 3957390670 + module: sbp.file_io + name: MsgFileioReadDirResp + msg_type: '0xaa' + raw_json: '{"preamble":85,"msg_type":170,"sender":1219,"length":45,"payload":"Tv3g62ZpbGUxAGFub3RoZXIgZmlsZQBkZWZpbml0ZWx5IG5vdCBhIGZpbGUA","crc":35258,"sequence":3957390670,"contents":"file1\u0000another file\u0000definitely not a file\u0000"}' + raw_packet: VaoAwwQtTv3g62ZpbGUxAGFub3RoZXIgZmlsZQBkZWZpbml0ZWx5IG5vdCBhIGZpbGUAuok= + sbp: + crc: '0x89ba' + length: 45 + msg_type: '0xaa' + payload: Tv3g62ZpbGUxAGFub3RoZXIgZmlsZQBkZWZpbml0ZWx5IG5vdCBhIGZpbGUA + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml new file mode 100644 index 0000000000..ef33921e21 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadReq.yaml @@ -0,0 +1,29 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioReadReq +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + c_decoded_fields: + filename: + handle_as: encoded-string + encoded_len: 19 + fn_prefix: sbp_msg_fileio_read_req_filename + text: "/path/to/some/file" + fields: + chunk_size: 53 + filename: "/path/to/some/file\0" + offset: 398373474 + sequence: 679648290 + module: sbp.file_io + name: MsgFileioReadReq + msg_type: '0xa8' + raw_json: '{"crc":25686,"length":28,"msg_type":168,"payload":"IpyCKGKyvhc1L3BhdGgvdG8vc29tZS9maWxlAA==","preamble":85,"sender":1219,"sequence":679648290,"offset":398373474,"chunk_size":53,"filename":"/path/to/some/file\u0000"}' + raw_packet: VagAwwQcIpyCKGKyvhc1L3BhdGgvdG8vc29tZS9maWxlAFZk + sbp: + crc: '0x6456' + length: 28 + msg_type: '0xa8' + payload: IpyCKGKyvhc1L3BhdGgvdG8vc29tZS9maWxlAA== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml new file mode 100644 index 0000000000..c484d1ecdf --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioReadResp.yaml @@ -0,0 +1,277 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioReadResp +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + c_decoded_fields: + n_contents: + handle_as: vararray-len + relates_to: contents + value: 251 + fields: + contents: + - 73 + - 231 + - 227 + - 179 + - 18 + - 76 + - 68 + - 229 + - 216 + - 21 + - 98 + - 183 + - 69 + - 190 + - 5 + - 252 + - 176 + - 55 + - 32 + - 78 + - 8 + - 52 + - 127 + - 50 + - 71 + - 106 + - 61 + - 79 + - 191 + - 106 + - 46 + - 79 + - 118 + - 248 + - 118 + - 207 + - 206 + - 210 + - 91 + - 73 + - 251 + - 81 + - 131 + - 205 + - 193 + - 146 + - 206 + - 185 + - 140 + - 249 + - 163 + - 231 + - 65 + - 67 + - 94 + - 250 + - 109 + - 152 + - 95 + - 123 + - 77 + - 224 + - 124 + - 238 + - 205 + - 65 + - 103 + - 35 + - 104 + - 209 + - 5 + - 191 + - 47 + - 249 + - 176 + - 166 + - 213 + - 46 + - 192 + - 86 + - 32 + - 103 + - 146 + - 252 + - 4 + - 16 + - 54 + - 161 + - 60 + - 6 + - 13 + - 191 + - 116 + - 182 + - 42 + - 191 + - 213 + - 20 + - 217 + - 8 + - 142 + - 187 + - 238 + - 120 + - 184 + - 250 + - 31 + - 151 + - 37 + - 51 + - 177 + - 130 + - 190 + - 155 + - 71 + - 68 + - 56 + - 238 + - 92 + - 130 + - 37 + - 137 + - 146 + - 246 + - 114 + - 116 + - 138 + - 165 + - 217 + - 79 + - 10 + - 189 + - 128 + - 189 + - 2 + - 240 + - 92 + - 28 + - 126 + - 105 + - 236 + - 228 + - 194 + - 0 + - 51 + - 61 + - 74 + - 41 + - 10 + - 239 + - 133 + - 106 + - 190 + - 30 + - 27 + - 3 + - 240 + - 205 + - 253 + - 113 + - 25 + - 28 + - 187 + - 81 + - 101 + - 216 + - 121 + - 41 + - 179 + - 120 + - 152 + - 18 + - 116 + - 53 + - 212 + - 100 + - 2 + - 114 + - 198 + - 200 + - 10 + - 147 + - 25 + - 33 + - 115 + - 208 + - 113 + - 60 + - 179 + - 183 + - 0 + - 41 + - 217 + - 206 + - 255 + - 211 + - 225 + - 142 + - 191 + - 133 + - 81 + - 15 + - 248 + - 193 + - 66 + - 191 + - 244 + - 221 + - 248 + - 199 + - 241 + - 112 + - 51 + - 1 + - 180 + - 180 + - 125 + - 97 + - 145 + - 25 + - 72 + - 210 + - 215 + - 208 + - 15 + - 126 + - 56 + - 38 + - 65 + - 4 + - 64 + - 19 + - 74 + - 223 + - 111 + - 109 + - 52 + - 43 + - 167 + - 186 + - 202 + - 111 + - 11 + - 91 + - 21 + - 236 + - 234 + - 196 + - 36 + - 171 + - 147 + sequence: 259241795 + module: sbp.file_io + name: MsgFileioReadResp + msg_type: '0xa3' + raw_json: '{"crc":61450,"length":255,"msg_type":163,"payload":"Q7dzD0nn47MSTETl2BVit0W+BfywNyBOCDR/MkdqPU+/ai5Pdvh2z87SW0n7UYPNwZLOuYz5o+dBQ176bZhfe03gfO7NQWcjaNEFvy/5sKbVLsBWIGeS/AQQNqE8Bg2/dLYqv9UU2QiOu+54uPoflyUzsYK+m0dEOO5cgiWJkvZydIql2U8KvYC9AvBcHH5p7OTCADM9SikK74Vqvh4bA/DN/XEZHLtRZdh5KbN4mBJ0NdRkAnLGyAqTGSFz0HE8s7cAKdnO/9Phjr+FUQ/4wUK/9N34x/FwMwG0tH1hkRlI0tfQD344JkEEQBNK329tNCunuspvC1sV7OrEJKuT","preamble":85,"sender":1219,"sequence":259241795,"contents":[73,231,227,179,18,76,68,229,216,21,98,183,69,190,5,252,176,55,32,78,8,52,127,50,71,106,61,79,191,106,46,79,118,248,118,207,206,210,91,73,251,81,131,205,193,146,206,185,140,249,163,231,65,67,94,250,109,152,95,123,77,224,124,238,205,65,103,35,104,209,5,191,47,249,176,166,213,46,192,86,32,103,146,252,4,16,54,161,60,6,13,191,116,182,42,191,213,20,217,8,142,187,238,120,184,250,31,151,37,51,177,130,190,155,71,68,56,238,92,130,37,137,146,246,114,116,138,165,217,79,10,189,128,189,2,240,92,28,126,105,236,228,194,0,51,61,74,41,10,239,133,106,190,30,27,3,240,205,253,113,25,28,187,81,101,216,121,41,179,120,152,18,116,53,212,100,2,114,198,200,10,147,25,33,115,208,113,60,179,183,0,41,217,206,255,211,225,142,191,133,81,15,248,193,66,191,244,221,248,199,241,112,51,1,180,180,125,97,145,25,72,210,215,208,15,126,56,38,65,4,64,19,74,223,111,109,52,43,167,186,202,111,11,91,21,236,234,196,36,171,147]}' + raw_packet: VaMAwwT/Q7dzD0nn47MSTETl2BVit0W+BfywNyBOCDR/MkdqPU+/ai5Pdvh2z87SW0n7UYPNwZLOuYz5o+dBQ176bZhfe03gfO7NQWcjaNEFvy/5sKbVLsBWIGeS/AQQNqE8Bg2/dLYqv9UU2QiOu+54uPoflyUzsYK+m0dEOO5cgiWJkvZydIql2U8KvYC9AvBcHH5p7OTCADM9SikK74Vqvh4bA/DN/XEZHLtRZdh5KbN4mBJ0NdRkAnLGyAqTGSFz0HE8s7cAKdnO/9Phjr+FUQ/4wUK/9N34x/FwMwG0tH1hkRlI0tfQD344JkEEQBNK329tNCunuspvC1sV7OrEJKuTCvA= + sbp: + crc: '0xf00a' + length: 255 + msg_type: '0xa3' + payload: Q7dzD0nn47MSTETl2BVit0W+BfywNyBOCDR/MkdqPU+/ai5Pdvh2z87SW0n7UYPNwZLOuYz5o+dBQ176bZhfe03gfO7NQWcjaNEFvy/5sKbVLsBWIGeS/AQQNqE8Bg2/dLYqv9UU2QiOu+54uPoflyUzsYK+m0dEOO5cgiWJkvZydIql2U8KvYC9AvBcHH5p7OTCADM9SikK74Vqvh4bA/DN/XEZHLtRZdh5KbN4mBJ0NdRkAnLGyAqTGSFz0HE8s7cAKdnO/9Phjr+FUQ/4wUK/9N34x/FwMwG0tH1hkRlI0tfQD344JkEEQBNK329tNCunuspvC1sV7OrEJKuT + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml new file mode 100644 index 0000000000..cbefa057c9 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/file_io/test_MsgFileioRemove.yaml @@ -0,0 +1,26 @@ +description: Unit tests for swiftnav.sbp.file_io MsgFileioRemove +generated_on: 2023-11-15 # manually generated +package: sbp.file_io +tests: + +- msg: + c_decoded_fields: + filename: + handle_as: encoded-string + encoded_len: 14 + text: "/path/to/file" + fn_prefix: sbp_msg_fileio_remove_filename + fields: + filename: "/path/to/file\0" + module: sbp.file_io + name: MsgFileioRemove + msg_type: '0xac' + raw_json: '{"crc":62254,"length":14,"msg_type":172,"payload":"L3BhdGgvdG8vZmlsZQA=","preamble":85,"sender":1219,"filename":"/path/to/file\u0000"}' + raw_packet: VawAwwQOL3BhdGgvdG8vZmlsZQAu8w== + sbp: + crc: '0xf32e' + length: 14 + msg_type: '0xac' + payload: L3BhdGgvdG8vZmlsZQA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml new file mode 100644 index 0000000000..56f326cbcc --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashDone.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.flash MsgFlashDone +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + response: 82 + module: sbp.flash + name: MsgFlashDone + msg_type: '0xe0' + raw_json: '{"crc":13830,"length":1,"msg_type":224,"payload":"Ug==","preamble":85,"sender":1219,"response":82}' + raw_packet: VeAAwwQBUgY2 + sbp: + crc: '0x3606' + length: 1 + msg_type: '0xe0' + payload: Ug== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml new file mode 100644 index 0000000000..69360fd882 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashErase.yaml @@ -0,0 +1,21 @@ +description: Unit tests for swiftnav.sbp.flash MsgFlashErase +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + sector_num: 2222371310 + target: 74 + module: sbp.flash + name: MsgFlashErase + msg_type: '0xe2' + raw_json: '{"crc":64256,"length":5,"msg_type":226,"payload":"Su6xdoQ=","preamble":85,"sender":1219,"target":74,"sector_num":2222371310}' + raw_packet: VeIAwwQFSu6xdoQA+w== + sbp: + crc: '0xfb00' + length: 5 + msg_type: '0xe2' + payload: Su6xdoQ= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml new file mode 100644 index 0000000000..a1e1908e21 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashProgram.yaml @@ -0,0 +1,281 @@ +description: Unit tests for swiftnav.sbp.flash MsgFlashProgram +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + c_decoded_fields: + addr_len: + handle_as: vararray-len + value: 250 + relates_to: data + fields: + addr_len: 250 + addr_start: + - 87 + - 52 + - 244 + data: + - 176 + - 222 + - 235 + - 106 + - 144 + - 29 + - 141 + - 255 + - 3 + - 16 + - 192 + - 237 + - 172 + - 254 + - 213 + - 4 + - 220 + - 98 + - 34 + - 222 + - 230 + - 214 + - 6 + - 217 + - 172 + - 122 + - 46 + - 13 + - 38 + - 240 + - 236 + - 60 + - 121 + - 47 + - 252 + - 163 + - 141 + - 222 + - 29 + - 168 + - 214 + - 118 + - 55 + - 201 + - 233 + - 21 + - 214 + - 57 + - 245 + - 246 + - 19 + - 3 + - 121 + - 49 + - 231 + - 37 + - 186 + - 58 + - 238 + - 98 + - 39 + - 70 + - 232 + - 133 + - 25 + - 10 + - 134 + - 129 + - 69 + - 228 + - 134 + - 9 + - 88 + - 183 + - 133 + - 171 + - 255 + - 166 + - 100 + - 152 + - 231 + - 92 + - 9 + - 196 + - 106 + - 246 + - 29 + - 145 + - 156 + - 151 + - 32 + - 67 + - 188 + - 63 + - 233 + - 142 + - 174 + - 139 + - 154 + - 127 + - 35 + - 60 + - 56 + - 187 + - 121 + - 103 + - 135 + - 152 + - 182 + - 88 + - 160 + - 255 + - 227 + - 240 + - 54 + - 100 + - 91 + - 31 + - 141 + - 102 + - 130 + - 254 + - 54 + - 227 + - 229 + - 62 + - 53 + - 225 + - 143 + - 88 + - 139 + - 126 + - 235 + - 235 + - 35 + - 54 + - 134 + - 163 + - 92 + - 57 + - 87 + - 130 + - 178 + - 22 + - 158 + - 18 + - 237 + - 209 + - 187 + - 226 + - 1 + - 46 + - 64 + - 226 + - 235 + - 213 + - 186 + - 159 + - 221 + - 186 + - 25 + - 115 + - 84 + - 131 + - 167 + - 201 + - 104 + - 1 + - 200 + - 13 + - 50 + - 71 + - 73 + - 193 + - 201 + - 250 + - 172 + - 193 + - 13 + - 20 + - 238 + - 130 + - 243 + - 68 + - 4 + - 72 + - 46 + - 194 + - 113 + - 255 + - 238 + - 15 + - 230 + - 64 + - 178 + - 127 + - 217 + - 92 + - 160 + - 201 + - 118 + - 163 + - 144 + - 58 + - 28 + - 174 + - 65 + - 73 + - 45 + - 123 + - 118 + - 83 + - 107 + - 239 + - 168 + - 32 + - 212 + - 191 + - 81 + - 93 + - 186 + - 223 + - 32 + - 19 + - 58 + - 137 + - 72 + - 217 + - 151 + - 251 + - 83 + - 20 + - 113 + - 37 + - 151 + - 34 + - 37 + - 71 + - 95 + - 105 + - 235 + - 144 + - 164 + - 83 + - 197 + - 254 + - 183 + - 223 + - 91 + - 19 + target: 212 + module: sbp.flash + name: MsgFlashProgram + msg_type: '0xe6' + raw_json: '{"crc":58157,"length":255,"msg_type":230,"payload":"1Fc09Pqw3utqkB2N/wMQwO2s/tUE3GIi3ubWBtmsei4NJvDsPHkv/KON3h2o1nY3yekV1jn19hMDeTHnJbo67mInRuiFGQqGgUXkhglYt4Wr/6ZkmOdcCcRq9h2RnJcgQ7w/6Y6ui5p/Izw4u3lnh5i2WKD/4/A2ZFsfjWaC/jbj5T414Y9Yi37r6yM2hqNcOVeCshaeEu3Ru+IBLkDi69W6n926GXNUg6fJaAHIDTJHScHJ+qzBDRTugvNEBEguwnH/7g/mQLJ/2VygyXajkDocrkFJLXt2U2vvqCDUv1Fdut8gEzqJSNmX+1MUcSWXIiVHX2nrkKRTxf6331sT","preamble":85,"sender":1219,"target":212,"addr_start":[87,52,244],"addr_len":250,"data":[176,222,235,106,144,29,141,255,3,16,192,237,172,254,213,4,220,98,34,222,230,214,6,217,172,122,46,13,38,240,236,60,121,47,252,163,141,222,29,168,214,118,55,201,233,21,214,57,245,246,19,3,121,49,231,37,186,58,238,98,39,70,232,133,25,10,134,129,69,228,134,9,88,183,133,171,255,166,100,152,231,92,9,196,106,246,29,145,156,151,32,67,188,63,233,142,174,139,154,127,35,60,56,187,121,103,135,152,182,88,160,255,227,240,54,100,91,31,141,102,130,254,54,227,229,62,53,225,143,88,139,126,235,235,35,54,134,163,92,57,87,130,178,22,158,18,237,209,187,226,1,46,64,226,235,213,186,159,221,186,25,115,84,131,167,201,104,1,200,13,50,71,73,193,201,250,172,193,13,20,238,130,243,68,4,72,46,194,113,255,238,15,230,64,178,127,217,92,160,201,118,163,144,58,28,174,65,73,45,123,118,83,107,239,168,32,212,191,81,93,186,223,32,19,58,137,72,217,151,251,83,20,113,37,151,34,37,71,95,105,235,144,164,83,197,254,183,223,91,19]}' + raw_packet: VeYAwwT/1Fc09Pqw3utqkB2N/wMQwO2s/tUE3GIi3ubWBtmsei4NJvDsPHkv/KON3h2o1nY3yekV1jn19hMDeTHnJbo67mInRuiFGQqGgUXkhglYt4Wr/6ZkmOdcCcRq9h2RnJcgQ7w/6Y6ui5p/Izw4u3lnh5i2WKD/4/A2ZFsfjWaC/jbj5T414Y9Yi37r6yM2hqNcOVeCshaeEu3Ru+IBLkDi69W6n926GXNUg6fJaAHIDTJHScHJ+qzBDRTugvNEBEguwnH/7g/mQLJ/2VygyXajkDocrkFJLXt2U2vvqCDUv1Fdut8gEzqJSNmX+1MUcSWXIiVHX2nrkKRTxf6331sTLeM= + sbp: + crc: '0xe32d' + length: 255 + msg_type: '0xe6' + payload: 1Fc09Pqw3utqkB2N/wMQwO2s/tUE3GIi3ubWBtmsei4NJvDsPHkv/KON3h2o1nY3yekV1jn19hMDeTHnJbo67mInRuiFGQqGgUXkhglYt4Wr/6ZkmOdcCcRq9h2RnJcgQ7w/6Y6ui5p/Izw4u3lnh5i2WKD/4/A2ZFsfjWaC/jbj5T414Y9Yi37r6yM2hqNcOVeCshaeEu3Ru+IBLkDi69W6n926GXNUg6fJaAHIDTJHScHJ+qzBDRTugvNEBEguwnH/7g/mQLJ/2VygyXajkDocrkFJLXt2U2vvqCDUv1Fdut8gEzqJSNmX+1MUcSWXIiVHX2nrkKRTxf6331sT + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml new file mode 100644 index 0000000000..bd4e7067a1 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadReq.yaml @@ -0,0 +1,25 @@ +description: Unit tests for swiftnav.sbp.flash MsgFlashReadReq +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + addr_len: 71 + addr_start: + - 28 + - 75 + - 244 + target: 241 + module: sbp.flash + name: MsgFlashReadReq + msg_type: '0xe7' + raw_json: '{"crc":14802,"length":5,"msg_type":231,"payload":"8RxL9Ec=","preamble":85,"sender":1219,"target":241,"addr_start":[28,75,244],"addr_len":71}' + raw_packet: VecAwwQF8RxL9EfSOQ== + sbp: + crc: '0x39d2' + length: 5 + msg_type: '0xe7' + payload: 8RxL9Ec= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml new file mode 100644 index 0000000000..0803ff4ad2 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgFlashReadResp.yaml @@ -0,0 +1,25 @@ +description: Unit tests for swiftnav.sbp.flash MsgFlashReadResp +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + addr_len: 124 + addr_start: + - 155 + - 52 + - 172 + target: 136 + module: sbp.flash + name: MsgFlashReadResp + msg_type: '0xe1' + raw_json: '{"crc":34709,"length":5,"msg_type":225,"payload":"iJs0rHw=","preamble":85,"sender":1219,"target":136,"addr_start":[155,52,172],"addr_len":124}' + raw_packet: VeEAwwQFiJs0rHyVhw== + sbp: + crc: '0x8795' + length: 5 + msg_type: '0xe1' + payload: iJs0rHw= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml new file mode 100644 index 0000000000..0112bc6ebe --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgM25FlashWriteStatus.yaml @@ -0,0 +1,21 @@ +description: Unit tests for swiftnav.sbp.flash MsgM25FlashWriteStatus +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + status: + - 5 + module: sbp.flash + name: MsgM25FlashWriteStatus + msg_type: '0xf3' + raw_json: '{"crc":51312,"length":1,"msg_type":243,"payload":"BQ==","preamble":85,"sender":1219,"status":[5]}' + raw_packet: VfMAwwQBBXDI + sbp: + crc: '0xc870' + length: 1 + msg_type: '0xf3' + payload: BQ== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml new file mode 100644 index 0000000000..3636697f84 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashLockSector.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.flash MsgStmFlashLockSector +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + sector: 1137047457 + module: sbp.flash + name: MsgStmFlashLockSector + msg_type: '0xe3' + raw_json: '{"crc":8421,"length":4,"msg_type":227,"payload":"offFQw==","preamble":85,"sender":1219,"sector":1137047457}' + raw_packet: VeMAwwQEoffFQ+Ug + sbp: + crc: '0x20e5' + length: 4 + msg_type: '0xe3' + payload: offFQw== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml new file mode 100644 index 0000000000..32dbeebcc9 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmFlashUnlockSector.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.flash MsgStmFlashUnlockSector +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + sector: 837226527 + module: sbp.flash + name: MsgStmFlashUnlockSector + msg_type: '0xe4' + raw_json: '{"crc":55605,"length":4,"msg_type":228,"payload":"HxDnMQ==","preamble":85,"sender":1219,"sector":837226527}' + raw_packet: VeQAwwQEHxDnMTXZ + sbp: + crc: '0xd935' + length: 4 + msg_type: '0xe4' + payload: HxDnMQ== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml new file mode 100644 index 0000000000..d668e693a7 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.flash MsgStmUniqueIdReq +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + {} + module: sbp.flash + name: MsgStmUniqueIdReq + msg_type: '0xe8' + raw_json: '{"crc":35394,"length":0,"msg_type":232,"payload":"","preamble":85,"sender":1219}' + raw_packet: VegAwwQAQoo= + sbp: + crc: '0x8a42' + length: 0 + msg_type: '0xe8' + payload: "" + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml new file mode 100644 index 0000000000..6d5af5e3e5 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/flash/test_MsgStmUniqueIdResp.yaml @@ -0,0 +1,32 @@ +description: Unit tests for swiftnav.sbp.flash MsgStmUniqueIdResp +generated_on: 2023-11-15 # manually generated +package: sbp.flash +tests: + +- msg: + fields: + stm_id: + - 196 + - 16 + - 15 + - 163 + - 85 + - 221 + - 119 + - 102 + - 32 + - 194 + - 56 + - 144 + module: sbp.flash + name: MsgStmUniqueIdResp + msg_type: '0xe5' + raw_json: '{"crc":50397,"length":12,"msg_type":229,"payload":"xBAPo1Xdd2YgwjiQ","preamble":85,"sender":1219,"stm_id":[196,16,15,163,85,221,119,102,32,194,56,144]}' + raw_packet: VeUAwwQMxBAPo1Xdd2YgwjiQ3cQ= + sbp: + crc: '0xc4dd' + length: 12 + msg_type: '0xe5' + payload: xBAPo1Xdd2YgwjiQ + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/gnss/test_gnss_structs.yaml b/spec/tests/yaml/swiftnav/sbp/gnss/test_gnss_structs.yaml new file mode 100644 index 0000000000..b894493d55 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/gnss/test_gnss_structs.yaml @@ -0,0 +1,56 @@ +description: Unit tests for swiftnav.sbp.gnss free structs +generated_on: 2023-11-15 # manually generated +package: sbp.gnss + +struct_tests: + + - encoded: ovQ= + fields: + sat: 162 + code: 244 + module: sbp.gnss + name: V4GnssSignal + + - encoded: siw= + fields: + satId: 178 + constellation: 44 + module: sbp.gnss + name: SvId + + - encoded: w0Lx9Q== + fields: + sat: 17091 + code: 241 + reserved: 245 + module: sbp.gnss + name: GnssSignalDep + + - encoded: LEa0Vndo + fields: + tow: 1454655020 + wn: 26743 + module: sbp.gnss + name: GpsTimeDep + + - encoded: QOjcehbz + fields: + tow: 2061297728 + wn: 62230 + module: sbp.gnss + name: GpsTimeSec + + - encoded: Hw29BR6yHRwfuA== + fields: + tow: 96275743 + wn: 47135 + ns_residual: 471708190 + module: sbp.gnss + name: V4GpsTime + + - encoded: ItSwh3o= + fields: + i: -2018454494 + f: 122 + module: sbp.gnss + name: CarrierPhase diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPointSatLos.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPointSatLos.yaml index 736b3464bb..3a2720d690 100644 --- a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPointSatLos.yaml +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPointSatLos.yaml @@ -4,6 +4,11 @@ package: sbp.integrity tests: - msg: + c_decoded_fields: + n_faulty_los: + handle_as: vararray-len + relates_to: faulty_los + value: 2 fields: header: obs_time: diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPoints.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPoints.yaml index 81f568ba6f..49607941a6 100644 --- a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPoints.yaml +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoGridPoints.yaml @@ -4,6 +4,11 @@ package: sbp.integrity tests: - msg: + c_decoded_fields: + n_faulty_points: + handle_as: vararray-len + relates_to: faulty_points + value: 3 fields: header: obs_time: diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoTileSatLos.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoTileSatLos.yaml index 9ad0471f1b..ef5d6adc92 100644 --- a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoTileSatLos.yaml +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagIonoTileSatLos.yaml @@ -4,6 +4,11 @@ package: sbp.integrity tests: - msg: + c_decoded_fields: + n_faulty_los: + handle_as: vararray-len + relates_to: faulty_los + value: 2 fields: header: obs_time: diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagSatellites.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagSatellites.yaml index f06693fd24..38db18f4c1 100644 --- a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagSatellites.yaml +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagSatellites.yaml @@ -4,6 +4,11 @@ package: sbp.integrity tests: - msg: + c_decoded_fields: + n_faulty_sats: + handle_as: vararray-len + relates_to: faulty_sats + value: 3 fields: obs_time: tow: 180 diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagTropoGridPoints.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagTropoGridPoints.yaml index 44d096845c..82a703d8d4 100644 --- a/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagTropoGridPoints.yaml +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_MsgSsrFlagTropoGridPoints.yaml @@ -4,6 +4,11 @@ package: sbp.integrity tests: - msg: + c_decoded_fields: + n_faulty_points: + handle_as: vararray-len + relates_to: faulty_points + value: 3 fields: header: obs_time: diff --git a/spec/tests/yaml/swiftnav/sbp/integrity/test_integrity_structs.yaml b/spec/tests/yaml/swiftnav/sbp/integrity/test_integrity_structs.yaml new file mode 100644 index 0000000000..93c6326e32 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/integrity/test_integrity_structs.yaml @@ -0,0 +1,17 @@ +description: Unit tests for swiftnav.sbp.integrity free structs +generated_on: 2023-11-15 # manually generated +package: sbp.integrity +struct_tests: + + - encoded: l9k4GrSR8A1dLGE2T8g= + fields: + obs_time.wn: 37300 + obs_time.tow: 439933335 + num_msgs: 240 + seq_num: 13 + ssr_sol_id: 93 + tile_set_id: 24876 + tile_id: 20278 + chain_id: 200 + module: sbp.integrity + name: IntegritySsrHeader diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml new file mode 100644 index 0000000000..89acc0ca0f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuState.yaml @@ -0,0 +1,32 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxCpuState +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_cpu_state_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + flags: 20 + index: 101 + pcpu: 98 + pid: 50042 + time: 3948815319 + tname: "process-name\0\0\0" + module: sbp.linux + name: MsgLinuxCpuState + msg_type: '0x7f08' + raw_json: '{"crc":58692,"length":70,"msg_type":32520,"payload":"ZXrDYtcjXusUcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":34196,"index":101,"pid":50042,"pcpu":98,"time":3948815319,"flags":20,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQh/lIVGZXrDYtcjXusUcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNETl + sbp: + crc: '0xe544' + length: 70 + msg_type: '0x7f08' + payload: ZXrDYtcjXusUcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA== + preamble: '0x55' + sender: '0x8594' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml new file mode 100644 index 0000000000..e60c3aae59 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxCpuStateDepA.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxCpuStateDepA +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_cpu_state_dep_a_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + index: 51 + pcpu: 178 + pid: 64240 + tname: "process-name\0\0\0" + module: sbp.linux + name: MsgLinuxCpuStateDepA + msg_type: '0x7f00' + raw_json: '{"crc":12368,"length":65,"msg_type":32512,"payload":"M/D6snByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ=","preamble":85,"sender":23308,"index":51,"pid":64240,"pcpu":178,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQB/DFtBM/D6snByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzRQMA== + sbp: + crc: '0x3050' + length: 65 + msg_type: '0x7f00' + payload: M/D6snByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ= + preamble: '0x55' + sender: '0x5b0c' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml new file mode 100644 index 0000000000..a1283d7fad --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemState.yaml @@ -0,0 +1,32 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxMemState +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_mem_state_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + flags: 76 + index: 154 + pid: 57279 + pmem: 19 + time: 3139057143 + tname: "process-name\0\0\0" + module: sbp.linux + name: MsgLinuxMemState + msg_type: '0x7f09' + raw_json: '{"crc":46339,"length":70,"msg_type":32521,"payload":"mr/fE/c1GrtMcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":64863,"index":154,"pid":57279,"pmem":19,"time":3139057143,"flags":76,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQl/X/1Gmr/fE/c1GrtMcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNAO1 + sbp: + crc: '0xb503' + length: 70 + msg_type: '0x7f09' + payload: mr/fE/c1GrtMcHJvY2Vzcy1uYW1lAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA== + preamble: '0x55' + sender: '0xfd5f' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml new file mode 100644 index 0000000000..156cabcbab --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxMemStateDepA.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxMemStateDepA +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_mem_state_dep_a_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + index: 247 + pid: 12381 + pmem: 193 + tname: "process-name\0\0\0" + module: sbp.linux + name: MsgLinuxMemStateDepA + msg_type: '0x7f01' + raw_json: '{"crc":35089,"length":65,"msg_type":32513,"payload":"910wwXByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ=","preamble":85,"sender":28089,"index":247,"pid":12381,"pmem":193,"tname":"process-name\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQF/uW1B910wwXByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQRiQ== + sbp: + crc: '0x8911' + length: 65 + msg_type: '0x7f01' + payload: 910wwXByb2Nlc3MtbmFtZQAAAC9wYXRoL3RvL3Byb2Nlc3MtbmFtZSBhcmcwIGFyZzEgYXJnMiBhcmczIGFyZzQ= + preamble: '0x55' + sender: '0x6db9' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml new file mode 100644 index 0000000000..f1340a3d45 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdCount.yaml @@ -0,0 +1,29 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxProcessFdCount +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_process_fd_count_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fd_count: 35589 + index: 164 + pid: 42429 + module: sbp.linux + name: MsgLinuxProcessFdCount + msg_type: '0x7f06' + raw_json: '{"crc":24066,"length":51,"msg_type":32518,"payload":"pL2lBYsvcGF0aC90by9wcm9jZXNzLW5hbWUgYXJnMCBhcmcxIGFyZzIgYXJnMyBhcmc0","preamble":85,"sender":49950,"index":164,"pid":42429,"fd_count":35589,"cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQZ/HsMzpL2lBYsvcGF0aC90by9wcm9jZXNzLW5hbWUgYXJnMCBhcmcxIGFyZzIgYXJnMyBhcmc0Al4= + sbp: + crc: '0x5e02' + length: 51 + msg_type: '0x7f06' + payload: pL2lBYsvcGF0aC90by9wcm9jZXNzLW5hbWUgYXJnMCBhcmcxIGFyZzIgYXJnMyBhcmc0 + preamble: '0x55' + sender: '0xc31e' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml new file mode 100644 index 0000000000..e127caad88 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessFdSummary.yaml @@ -0,0 +1,34 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxProcessFdSummary +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + most_opened: + handle_as: encoded-string + encoded_len: 25 + min_len: 25 + fn_prefix: sbp_msg_linux_process_fd_summary_most_opened + sections: + - fd1 + - fd2 + - fd3 + - fd4 + - fd5 + - fd6 + fields: + most_opened: "fd1\0fd2\0fd3\0fd4\0fd5\0fd6\0\0" + sys_fd_count: 1304986387 + module: sbp.linux + name: MsgLinuxProcessFdSummary + msg_type: '0x7f07' + raw_json: '{"crc":20609,"length":29,"msg_type":32519,"payload":"E4PITWZkMQBmZDIAZmQzAGZkNABmZDUAZmQ2AAA=","preamble":85,"sender":63591,"sys_fd_count":1304986387,"most_opened":"fd1\u0000fd2\u0000fd3\u0000fd4\u0000fd5\u0000fd6\u0000\u0000"}' + raw_packet: VQd/Z/gdE4PITWZkMQBmZDIAZmQzAGZkNABmZDUAZmQ2AACBUA== + sbp: + crc: '0x5081' + length: 29 + msg_type: '0x7f07' + payload: E4PITWZkMQBmZDIAZmQzAGZkNABmZDUAZmQ2AAA= + preamble: '0x55' + sender: '0xf867' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml new file mode 100644 index 0000000000..88c6373a85 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketCounts.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxProcessSocketCounts +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_process_socket_counts_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + index: 51 + pid: 28553 + socket_count: 30287 + socket_states: 29554 + socket_types: 35843 + module: sbp.linux + name: MsgLinuxProcessSocketCounts + msg_type: '0x7f03' + raw_json: '{"crc":33716,"length":55,"msg_type":32515,"payload":"M4lvT3YDjHJzL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":2412,"index":51,"pid":28553,"socket_count":30287,"socket_types":35843,"socket_states":29554,"cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQN/bAk3M4lvT3YDjHJzL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNLSD + sbp: + crc: '0x83b4' + length: 55 + msg_type: '0x7f03' + payload: M4lvT3YDjHJzL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA== + preamble: '0x55' + sender: '0x096c' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml new file mode 100644 index 0000000000..695b48f246 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxProcessSocketQueues.yaml @@ -0,0 +1,34 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxProcessSocketQueues +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + c_decoded_fields: + cmdline: + handle_as: encoded-string + encoded_len: 46 + fn_prefix: sbp_msg_linux_process_socket_queues_cmdline + text: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + fields: + address_of_largest: "address of largest\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ + \0\0\0\0\0\0\0\0\0\0\0\0\0\0" + cmdline: /path/to/process-name arg0 arg1 arg2 arg3 arg4 + index: 181 + pid: 19335 + recv_queued: 54265 + send_queued: 64547 + socket_states: 57103 + socket_types: 27984 + module: sbp.linux + name: MsgLinuxProcessSocketQueues + msg_type: '0x7f04' + raw_json: '{"crc":63234,"length":121,"msg_type":32516,"payload":"tYdL+dMj/FBtD99hZGRyZXNzIG9mIGxhcmdlc3QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA==","preamble":85,"sender":59579,"index":181,"pid":19335,"recv_queued":54265,"send_queued":64547,"socket_types":27984,"socket_states":57103,"address_of_largest":"address of largest\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000","cmdline":"/path/to/process-name arg0 arg1 arg2 arg3 arg4"}' + raw_packet: VQR/u+h5tYdL+dMj/FBtD99hZGRyZXNzIG9mIGxhcmdlc3QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNAL3 + sbp: + crc: '0xf702' + length: 121 + msg_type: '0x7f04' + payload: tYdL+dMj/FBtD99hZGRyZXNzIG9mIGxhcmdlc3QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAL3BhdGgvdG8vcHJvY2Vzcy1uYW1lIGFyZzAgYXJnMSBhcmcyIGFyZzMgYXJnNA== + preamble: '0x55' + sender: '0xe8bb' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml new file mode 100644 index 0000000000..b0cf263ac6 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSocketUsage.yaml @@ -0,0 +1,55 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxSocketUsage +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + fields: + avg_queue_depth: 2907030541 + max_queue_depth: 3048922691 + socket_state_counts: + - 39670 + - 4603 + - 46048 + - 43290 + - 23217 + - 54677 + - 1750 + - 16510 + - 47480 + - 33620 + - 28616 + - 36128 + - 53721 + - 3636 + - 37822 + - 63135 + socket_type_counts: + - 31373 + - 30676 + - 7811 + - 12152 + - 27929 + - 16794 + - 42116 + - 7719 + - 44830 + - 11272 + - 28444 + - 61676 + - 19120 + - 33183 + - 39322 + - 58786 + module: sbp.linux + name: MsgLinuxSocketUsage + msg_type: '0x7f05' + raw_json: '{"crc":39554,"length":72,"msg_type":32517,"payload":"DcRFrUPeurX2mvsR4LMaqbFaldXWBn5AeLlUg8hvII3Z0TQOvpOf9o161HeDHngvGW2aQYSkJx4erwgsHG/s8LBKn4GamaLl","preamble":85,"sender":35442,"avg_queue_depth":2907030541,"max_queue_depth":3048922691,"socket_state_counts":[39670,4603,46048,43290,23217,54677,1750,16510,47480,33620,28616,36128,53721,3636,37822,63135],"socket_type_counts":[31373,30676,7811,12152,27929,16794,42116,7719,44830,11272,28444,61676,19120,33183,39322,58786]}' + raw_packet: VQV/copIDcRFrUPeurX2mvsR4LMaqbFaldXWBn5AeLlUg8hvII3Z0TQOvpOf9o161HeDHngvGW2aQYSkJx4erwgsHG/s8LBKn4GamaLlgpo= + sbp: + crc: '0x9a82' + length: 72 + msg_type: '0x7f05' + payload: DcRFrUPeurX2mvsR4LMaqbFaldXWBn5AeLlUg8hvII3Z0TQOvpOf9o161HeDHngvGW2aQYSkJx4erwgsHG/s8LBKn4GamaLl + preamble: '0x55' + sender: '0x8a72' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml new file mode 100644 index 0000000000..d6685dee6e --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysState.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxSysState +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + fields: + flags: 9 + mem_total: 53012 + pcpu: 125 + pid_count: 47866 + pmem: 215 + procs_starting: 18372 + procs_stopping: 58785 + time: 90840684 + module: sbp.linux + name: MsgLinuxSysState + msg_type: '0x7f0a' + raw_json: '{"crc":62181,"length":15,"msg_type":32522,"payload":"FM9918RHoeX6umweagUJ","preamble":85,"sender":42837,"mem_total":53012,"pcpu":125,"pmem":215,"procs_starting":18372,"procs_stopping":58785,"pid_count":47866,"time":90840684,"flags":9}' + raw_packet: VQp/VacPFM9918RHoeX6umweagUJ5fI= + sbp: + crc: '0xf2e5' + length: 15 + msg_type: '0x7f0a' + payload: FM9918RHoeX6umweagUJ + preamble: '0x55' + sender: '0xa755' diff --git a/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml new file mode 100644 index 0000000000..a5028497cf --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/linux/test_MsgLinuxSysStateDepA.yaml @@ -0,0 +1,25 @@ +description: Unit tests for swiftnav.sbp.linux MsgLinuxSysStateDepA +generated_on: 2023-11-15 # manually generated +package: sbp.linux +tests: + +- msg: + fields: + mem_total: 41916 + pcpu: 211 + pid_count: 51580 + pmem: 194 + procs_starting: 18291 + procs_stopping: 26469 + module: sbp.linux + name: MsgLinuxSysStateDepA + msg_type: '0x7f02' + raw_json: '{"crc":57311,"length":10,"msg_type":32514,"payload":"vKPTwnNHZWd8yQ==","preamble":85,"sender":14420,"mem_total":41916,"pcpu":211,"pmem":194,"procs_starting":18291,"procs_stopping":26469,"pid_count":51580}' + raw_packet: VQJ/VDgKvKPTwnNHZWd8yd/f + sbp: + crc: '0xdfdf' + length: 10 + msg_type: '0x7f02' + payload: vKPTwnNHZWd8yQ== + preamble: '0x55' + sender: '0x3854' diff --git a/spec/tests/yaml/swiftnav/sbp/logging/test_MsgFwd.yaml b/spec/tests/yaml/swiftnav/sbp/logging/test_MsgFwd.yaml index 8655630dbe..2b0b159b30 100644 --- a/spec/tests/yaml/swiftnav/sbp/logging/test_MsgFwd.yaml +++ b/spec/tests/yaml/swiftnav/sbp/logging/test_MsgFwd.yaml @@ -10,7 +10,10 @@ tests: protocol: 0 source: 0 c_decoded_fields: - n_fwd_payload: 16 + n_fwd_payload: + handle_as: vararray-len + relates_to: fwd_payload + value: 16 module: sbp.logging name: MsgFwd msg_type: '0x402' diff --git a/spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml b/spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml new file mode 100644 index 0000000000..076ace4433 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/mag/test_MsgMagRaw.yaml @@ -0,0 +1,24 @@ +description: Unit tests for swiftnav.sbp.mag MsgMagRaw +generated_on: 2023-11-15 # manually generated +package: sbp.mag +tests: + +- msg: + fields: + mag_x: 866 + mag_y: 742 + mag_z: -6802 + tow: 3332301741 + tow_f: 206 + module: sbp.mag + name: MsgMagRaw + msg_type: '0x902' + raw_json: '{"preamble":85,"msg_type":2306,"sender":1219,"length":11,"payload":"reOexs5iA+YCbuU=","crc":6047,"tow":3332301741,"tow_f":206,"mag_x":866,"mag_y":742,"mag_z":-6802}' + raw_packet: VQIJwwQLreOexs5iA+YCbuWfFw== + sbp: + crc: '0x179f' + length: 11 + msg_type: '0x902' + payload: reOexs5iA+YCbuU= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml new file mode 100644 index 0000000000..4afd065ae6 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgBaselineHeadingDepA.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.navigation MsgBaselineHeadingDepA +generated_on: 2023-11-15 # manually generated +package: sbp.navigation +tests: + +- msg: + fields: + flags: 58 + heading: 3411152452 + n_sats: 186 + tow: 2958585170 + module: sbp.navigation + name: MsgBaselineHeadingDepA + msg_type: '0x207' + raw_json: '{"crc":46765,"length":10,"msg_type":519,"payload":"Um1YsEQOUsu6Og==","preamble":85,"sender":52860,"tow":2958585170,"heading":3411152452,"n_sats":186,"flags":58}' + raw_packet: VQcCfM4KUm1YsEQOUsu6Oq22 + sbp: + crc: '0xb6ad' + length: 10 + msg_type: '0x207' + payload: Um1YsEQOUsu6Og== + preamble: '0x55' + sender: '0xce7c' diff --git a/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml new file mode 100644 index 0000000000..2fd3a5b485 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgPosLlhAcc.yaml @@ -0,0 +1,35 @@ +description: Unit tests for swiftnav.sbp.navigation MsgPosLLHAcc +generated_on: 2023-11-15 # manually generated +package: sbp.navigation +tests: + +- msg: + fields: + at_accuracy: 6297.2001953125 + confidence_and_geoid: 95 + ct_accuracy: 1948.199951171875 + flags: 72 + h_accuracy: 2410.199951171875 + h_ellipse: + orientation: 2550.199951171875 + semi_major: 8248.2001953125 + semi_minor: 3202.199951171875 + height: 4257.2 + lat: 7563.2 + lon: 8494.2 + n_sats: 27 + orthometric_height: 4965.2 + tow: 309229607 + v_accuracy: 5539.2001953125 + module: sbp.navigation + name: MsgPosLLHAcc + msg_type: '0x218' + raw_json: '{"preamble":85,"msg_type":536,"sender":7170,"length":67,"payload":"J3huEjMzMzMzi71AmpmZmRmXwEAzMzMzM6GwQDMzMzMzZbNAM6MWRZoZrUVmhvNEmsnERc3gAEYzI0hFM2MfRV8bSA==","crc":45532,"tow":309229607,"lat":7563.2,"lon":8494.2,"height":4257.2,"orthometric_height":4965.2,"h_accuracy":2410.199951171875,"v_accuracy":5539.2001953125,"ct_accuracy":1948.199951171875,"at_accuracy":6297.2001953125,"h_ellipse":{"semi_major":8248.2001953125,"semi_minor":3202.199951171875,"orientation":2550.199951171875},"confidence_and_geoid":95,"n_sats":27,"flags":72}' + raw_packet: VRgCAhxDJ3huEjMzMzMzi71AmpmZmRmXwEAzMzMzM6GwQDMzMzMzZbNAM6MWRZoZrUVmhvNEmsnERc3gAEYzI0hFM2MfRV8bSNyx + sbp: + crc: '0xb1dc' + length: 67 + msg_type: '0x218' + payload: J3huEjMzMzMzi71AmpmZmRmXwEAzMzMzM6GwQDMzMzMzZbNAM6MWRZoZrUVmhvNEmsnERc3gAEYzI0hFM2MfRV8bSA== + preamble: '0x55' + sender: '0x1c02' diff --git a/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevel.yaml b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevel.yaml index 599bfbd4d9..662392e6c1 100644 --- a/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevel.yaml +++ b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevel.yaml @@ -1,29 +1,40 @@ ---- -description: Unit tests for swiftnav.sbp.system MsgProtectionLevel -generated_on: 2020-04-22 00:00:00.00 # manually generated +description: Unit tests for swiftnav.sbp.navigation MsgProtectionLevel +generated_on: 2023-11-15 # manually generated package: sbp.navigation tests: - msg: fields: - tow: 501867400 - vpl: 0 - hpl: 0 - lat: 0.0 - lon: 0.0 - height: 0.0 - flags: 0 + atpl: 10663 + ctpl: 5433 + flags: 555755625 + heading: -529244741 + height: 412.2 + hopl: 26707 + hpl: 41013 + hvpl: 62681 + lat: 5290.2 + lon: 9904.2 + pitch: -1598561301 + popl: 35212 + roll: 1018834477 + ropl: 63066 + tow: 4060370030 + v_x: -584647705 + v_y: 1353168848 + v_z: -1537140001 + vpl: 21593 + vvpl: 41277 + wn: 13102 module: sbp.navigation - name: MsgProtectionLevelDepA - msg_type: '0x216' - raw_json: '{"tow":501867400,"vpl":0,"hpl":0,"lat":0.0,"lon":0.0,"height":0.0,"flags":0,"preamble":85,"msg_type":534,"sender":4096,"payload":"iOPpHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","crc":50002,"length":33}' - raw_packet: VRYCABAhiOPpHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUsM= + name: MsgProtectionLevel + msg_type: '0x217' + raw_json: '{"preamble":85,"msg_type":535,"sender":813,"length":76,"payload":"blQE8i4zNaBZVKcpORXZ9D2hU2iMiVr2MzMzMzOqtECamZmZGVjDQDMzMzMzw3lA5/sm3dC3p1DfGmGkLS66POvjt6C7XXTgaSggIQ==","crc":48261,"tow":4060370030,"wn":13102,"hpl":41013,"vpl":21593,"atpl":10663,"ctpl":5433,"hvpl":62681,"vvpl":41277,"hopl":26707,"popl":35212,"ropl":63066,"lat":5290.2,"lon":9904.2,"height":412.2,"v_x":-584647705,"v_y":1353168848,"v_z":-1537140001,"roll":1018834477,"pitch":-1598561301,"heading":-529244741,"flags":555755625}' + raw_packet: VRcCLQNMblQE8i4zNaBZVKcpORXZ9D2hU2iMiVr2MzMzMzOqtECamZmZGVjDQDMzMzMzw3lA5/sm3dC3p1DfGmGkLS66POvjt6C7XXTgaSggIYW8 sbp: - crc: '0xc352' - length: 0x21 - payload: iOPpHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - msg_type: '0x216' + crc: '0xbc85' + length: 76 + msg_type: '0x217' + payload: blQE8i4zNaBZVKcpORXZ9D2hU2iMiVr2MzMzMzOqtECamZmZGVjDQDMzMzMzw3lA5/sm3dC3p1DfGmGkLS66POvjt6C7XXTgaSggIQ== preamble: '0x55' - sender: '0x1000' - - + sender: '0x032d' diff --git a/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml new file mode 100644 index 0000000000..c6ccf620c3 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/navigation/test_MsgProtectionLevelDepA.yaml @@ -0,0 +1,26 @@ +description: Unit tests for swiftnav.sbp.navigation MsgProtectionLevelDepA +generated_on: 2023-11-15 # manually generated +package: sbp.navigation +tests: + +- msg: + fields: + flags: 248 + height: 8270.2 + hpl: 35588 + lat: 7924.2 + lon: 3174.2 + tow: 3108339252 + vpl: 21807 + module: sbp.navigation + name: MsgProtectionLevelDepA + msg_type: '0x216' + raw_json: '{"crc":26705,"length":33,"msg_type":534,"payload":"NH5FuS9VBIszMzMzM/S+QGZmZmZmzKhAmpmZmRknwED4","preamble":85,"sender":5780,"tow":3108339252,"vpl":21807,"hpl":35588,"lat":7924.2,"lon":3174.2,"height":8270.2,"flags":248}' + raw_packet: VRYClBYhNH5FuS9VBIszMzMzM/S+QGZmZmZmzKhAmpmZmRknwED4UWg= + sbp: + crc: '0x6851' + length: 33 + msg_type: '0x216' + payload: NH5FuS9VBIszMzMzM/S+QGZmZmZmzKhAmpmZmRknwED4 + preamble: '0x55' + sender: '0x1694' diff --git a/spec/tests/yaml/swiftnav/sbp/navigation/test_navigation_structs.yaml b/spec/tests/yaml/swiftnav/sbp/navigation/test_navigation_structs.yaml new file mode 100644 index 0000000000..5a0a77c6a2 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/navigation/test_navigation_structs.yaml @@ -0,0 +1,12 @@ +description: Unit tests for swiftnav.sbp.navigation free structs +generated_on: 2023-11-15 # manually generated +package: sbp.navigation +struct_tests: + +- encoded: mimYRZqBukVmZrZC + fields: + semi_major: 4869.200195 + semi_minor: 5968.200195 + orientation: 91.199997 + module: sbp.navigation + name: EstimatedHorizontalErrorEllipse diff --git a/spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml b/spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml new file mode 100644 index 0000000000..aa1cb8acb9 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ndb/test_MsgNdbEvent.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.ndb MsgNdbEvent +generated_on: 2023-11-15 # manually generated +package: sbp.ndb +tests: + +- msg: + fields: + data_source: 115 + event: 249 + object_sid: + code: 74 + sat: 238 + object_type: 73 + original_sender: 38070 + recv_time: 299461164286 + result: 205 + src_sid: + code: 66 + sat: 98 + module: sbp.ndb + name: MsgNdbEvent + msg_type: '0x400' + raw_json: '{"preamble":85,"msg_type":1024,"sender":44708,"length":18,"payload":"/rxGuUUAAAD5Sc1z7kpiQraU","crc":42512,"recv_time":299461164286,"event":249,"object_type":73,"result":205,"data_source":115,"object_sid":{"sat":238,"code":74},"src_sid":{"sat":98,"code":66},"original_sender":38070}' + raw_packet: VQAEpK4S/rxGuUUAAAD5Sc1z7kpiQraUEKY= + sbp: + crc: '0xa610' + length: 18 + msg_type: '0x400' + payload: /rxGuUUAAAD5Sc1z7kpiQraU + preamble: '0x55' + sender: '0xaea4' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml new file mode 100644 index 0000000000..e46647a3cf --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLO.yaml @@ -0,0 +1,37 @@ +description: Unit tests for swiftnav.sbp.observation MsgAlmanacGlo +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + sat: 22 + toa: + tow: 446384 + wn: 2154 + ura: 2.2 + valid: 1 + epsilon: -0.9893036629599647 + i: 5153.550029754639 + lambda_na: -0.02200078842114688 + omega: 0.9341514480259797 + t: -1.8731818448797617 + t_dot: -8.903585155774196e-09 + t_lambda_na: 0.007072207052260637 + module: sbp.observation + name: MsgAlmanacGlo + msg_type: '0x73' + raw_json: '{"preamble":85,"msg_type":115,"sender":1219,"length":78,"payload":"FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/","crc":22427,"common":{"sid":{"sat":22,"code":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"lambda_na":-0.02200078842114688,"t_lambda_na":0.007072207052260637,"i":5153.550029754639,"t":-1.8731818448797617,"t_dot":-8.903585155774196e-09,"epsilon":-0.9893036629599647,"omega":0.9341514480259797}' + raw_packet: VXMAwwROFgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/m1c= + sbp: + crc: '0x579b' + length: 78 + msg_type: '0x73' + payload: FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/ + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml new file mode 100644 index 0000000000..15f5400fc9 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGLODep.yaml @@ -0,0 +1,38 @@ +description: Unit tests for swiftnav.sbp.observation MsgAlmanacGloDep +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + reserved: 0 + sat: 22 + toa: + tow: 446384 + wn: 2154 + ura: 2.2 + valid: 1 + epsilon: -0.9893036629599647 + i: 5153.550029754639 + lambda_na: -0.02200078842114688 + omega: 0.9341514480259797 + t: -1.8731818448797617 + t_dot: -8.903585155774196e-09 + t_lambda_na: 0.007072207052260637 + module: sbp.observation + name: MsgAlmanacGloDep + msg_type: '0x71' + raw_json: '{"preamble":85,"msg_type":113,"sender":1219,"length":80,"payload":"FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8=","crc":45771,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"lambda_na":-0.02200078842114688,"t_lambda_na":0.007072207052260637,"i":5153.550029754639,"t":-1.8731818448797617,"t_dot":-8.903585155774196e-09,"epsilon":-0.9893036629599647,"omega":0.9341514480259797}' + raw_packet: VXEAwwRQFgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T/Lsg== + sbp: + crc: '0xb2cb' + length: 80 + msg_type: '0x71' + payload: FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml new file mode 100644 index 0000000000..034ffbb005 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPS.yaml @@ -0,0 +1,39 @@ +description: Unit tests for swiftnav.sbp.observation MsgAlmanacGPS +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + sat: 22 + toa: + tow: 446384 + wn: 2154 + ura: 2.2 + valid: 1 + ecc: 0.007072207052260637 + inc: 0.9341514480259797 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + sqrta: 5153.550029754639 + w: -0.9893036629599647 + module: sbp.observation + name: MsgAlmanacGPS + msg_type: '0x72' + raw_json: '{"preamble":85,"msg_type":114,"sender":1219,"length":94,"payload":"FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/AAAAAGyxRL8AAAAAAMCjPQ==","crc":11710,"common":{"sid":{"sat":22,"code":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12}' + raw_packet: VXIAwwReFgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/AAAAAGyxRL8AAAAAAMCjPb4t + sbp: + crc: '0x2dbe' + length: 94 + msg_type: '0x72' + payload: FgCwzwYAagiamZmZmZkBQEA4AAABAI4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/AAAAAGyxRL8AAAAAAMCjPQ== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml new file mode 100644 index 0000000000..dae340fa89 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgAlmanacGPSDep.yaml @@ -0,0 +1,40 @@ +description: Unit tests for swiftnav.sbp.observation MsgAlmanacGPSDep +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + reserved: 0 + sat: 22 + toa: + tow: 446384 + wn: 2154 + ura: 2.2 + valid: 1 + ecc: 0.007072207052260637 + inc: 0.9341514480259797 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + sqrta: 5153.550029754639 + w: -0.9893036629599647 + module: sbp.observation + name: MsgAlmanacGPSDep + msg_type: '0x70' + raw_json: '{"preamble":85,"msg_type":112,"sender":1219,"length":96,"payload":"FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8AAAAAbLFEvwAAAAAAwKM9","crc":59536,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toa":{"tow":446384,"wn":2154},"ura":2.2,"fit_interval":14400,"valid":1,"health_bits":0},"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12}' + raw_packet: VXAAwwRgFgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8AAAAAbLFEvwAAAAAAwKM9kOg= + sbp: + crc: '0xe890' + length: 96 + msg_type: '0x70' + payload: FgAAALDPBgBqCJqZmZmZmQFAQDgAAAEAjikF61+Hlr8AAAAgv/d8PwAAwM6MIbRAKYOzho34/b/jhVE2zB5Dvtg7xydgqO+/RwvZk5Hk7T8AAAAAbLFEvwAAAAAAwKM9 + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml new file mode 100644 index 0000000000..d07c06c5aa --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgBasePosLLH.yaml @@ -0,0 +1,22 @@ +description: Unit tests for swiftnav.sbp.observation MsgBasePosLLH +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + height: 37.939512310879216 + lat: 37.251292578377395 + lon: -121.87505609407974 + module: sbp.observation + name: MsgBasePosLLH + msg_type: '0x44' + raw_json: '{"crc":58962,"length":24,"msg_type":68,"payload":"4e3uWiqgQkA7j0brAHhewDO1fPBB+EJA","preamble":85,"sender":123,"lat":37.251292578377395,"lon":-121.87505609407974,"height":37.939512310879216}' + raw_packet: VUQAewAY4e3uWiqgQkA7j0brAHhewDO1fPBB+EJAUuY= + sbp: + crc: '0xe652' + length: 24 + msg_type: '0x44' + payload: 4e3uWiqgQkA7j0brAHhewDO1fPBB+EJA + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml new file mode 100644 index 0000000000..d4ba2e22fe --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepA.yaml @@ -0,0 +1,45 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisDepA +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + af2: 0.2 + c_ic: 7.450580596923828e-09 + c_is: -1.1548399925231934e-07 + c_rc: 308.625 + c_rs: -52.3125 + c_uc: -2.7436763048171997e-06 + c_us: 3.1366944313049316e-06 + dn: 5.694522914022375e-09 + ecc: 0.007072207052260637 + healthy: 0 + inc: 0.9341514480259797 + inc_dot: -4.035882396415757e-11 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + prn: 22 + sqrta: 5153.550029754639 + tgd: -1.7695128917694092e-08 + toc_tow: 446384.2 + toc_wn: 2154 + toe_tow: 446384.2 + toe_wn: 2154 + valid: 1 + w: -0.9893036629599647 + module: sbp.observation + name: MsgEphemerisDepA + msg_type: '0x1a' + raw_json: '{"preamble":85,"msg_type":26,"sender":1219,"length":175,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFg==","crc":21746,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"prn":22}' + raw_packet: VRoAwwSvAAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFvJU + sbp: + crc: '0x54f2' + length: 175 + msg_type: '0x1a' + payload: AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFg== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml new file mode 100644 index 0000000000..d26e9e170a --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepC.yaml @@ -0,0 +1,51 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisDepC +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + af2: 0.2 + c_ic: 7.450580596923828e-09 + c_is: -1.1548399925231934e-07 + c_rc: 308.625 + c_rs: -52.3125 + c_uc: -2.7436763048171997e-06 + c_us: 3.1366944313049316e-06 + dn: 5.694522914022375e-09 + ecc: 0.007072207052260637 + healthy: 0 + inc: 0.9341514480259797 + inc_dot: -4.035882396415757e-11 + iodc: 45 + iode: 45 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + reserved: 0 + sid: + code: 0 + reserved: 0 + sat: 22 + sqrta: 5153.550029754639 + tgd: -1.7695128917694092e-08 + toc_tow: 446384.2 + toc_wn: 2154 + toe_tow: 446384.2 + toe_wn: 2154 + valid: 1 + w: -0.9893036629599647 + module: sbp.observation + name: MsgEphemerisDepC + msg_type: '0x47' + raw_json: '{"preamble":85,"msg_type":71,"sender":1219,"length":185,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA=","crc":43543,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"sid":{"sat":22,"code":0,"reserved":0},"iode":45,"iodc":45,"reserved":0}' + raw_packet: VUcAwwS5AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAAXqg== + sbp: + crc: '0xaa17' + length: 185 + msg_type: '0x47' + payload: AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml new file mode 100644 index 0000000000..aceac2b2ed --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisDepD.yaml @@ -0,0 +1,51 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisDepD +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + af2: 0.2 + c_ic: 7.450580596923828e-09 + c_is: -1.1548399925231934e-07 + c_rc: 308.625 + c_rs: -52.3125 + c_uc: -2.7436763048171997e-06 + c_us: 3.1366944313049316e-06 + dn: 5.694522914022375e-09 + ecc: 0.007072207052260637 + healthy: 0 + inc: 0.9341514480259797 + inc_dot: -4.035882396415757e-11 + iodc: 45 + iode: 45 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + reserved: 0 + sid: + code: 0 + reserved: 0 + sat: 22 + sqrta: 5153.550029754639 + tgd: -1.7695128917694092e-08 + toc_tow: 446384.2 + toc_wn: 2154 + toe_tow: 446384.2 + toe_wn: 2154 + valid: 1 + w: -0.9893036629599647 + module: sbp.observation + name: MsgEphemerisDepD + msg_type: '0x80' + raw_json: '{"preamble":85,"msg_type":128,"sender":1219,"length":185,"payload":"AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA=","crc":1887,"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0.2,"toe_tow":446384.2,"toe_wn":2154,"toc_tow":446384.2,"toc_wn":2154,"valid":1,"healthy":0,"sid":{"sat":22,"code":0,"reserved":0},"iode":45,"iodc":45,"reserved":0}' + raw_packet: VYAAwwS5AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAABfBw== + sbp: + crc: '0x075f' + length: 185 + msg_type: '0x80' + payload: AAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9mpmZmZmZyT/NzMzMwD4bQWoIzczMzMA+G0FqCAEAFgAAAC0tAAAAAAA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml new file mode 100644 index 0000000000..a2dcc29eb1 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepA.yaml @@ -0,0 +1,45 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGloDepA +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 2400 + health_bits: 0 + sid: + code: 3 + reserved: 0 + sat: 4 + toe: + tow: 443718 + wn: 2154 + ura: 5.2 + valid: 1 + gamma: 9.094947017729282e-13 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + tau: -8.36281105875969e-05 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisGloDepA + msg_type: '0x83' + raw_json: '{"preamble":85,"msg_type":131,"sender":1219,"length":112,"payload":"BAADAEbFBgBqCM3MzMzMzBRAYAkAAAEAAAAAAAAAcD0AAAAAMOwVvwAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg==","crc":61130,"common":{"sid":{"sat":4,"code":3,"reserved":0},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06]}' + raw_packet: VYMAwwRwBAADAEbFBgBqCM3MzMzMzBRAYAkAAAEAAAAAAAAAcD0AAAAAMOwVvwAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPsru + sbp: + crc: '0xeeca' + length: 112 + msg_type: '0x83' + payload: BAADAEbFBgBqCM3MzMzMzBRAYAkAAAEAAAAAAAAAcD0AAAAAMOwVvwAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg== + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml new file mode 100644 index 0000000000..f7f6fdc90c --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepB.yaml @@ -0,0 +1,44 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGloDepB +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 2400 + health_bits: 0 + sid: + code: 3 + sat: 4 + toe: + tow: 443718 + wn: 2154 + ura: 5.2 + valid: 1 + gamma: 9.094947017729282e-13 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + tau: -8.36281105875969e-05 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisGloDepB + msg_type: '0x85' + raw_json: '{"preamble":85,"msg_type":133,"sender":1219,"length":110,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAIBC9jlnwQAAACKqTiJBAADwx1RWdcEAAABiBvqawAAAANk63aPAAAAAuIoui0AAAAAAAECvPgAAAAAAQK8+AAAAAABwxz4=","crc":32634,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06]}' + raw_packet: VYUAwwRuBANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAIBC9jlnwQAAACKqTiJBAADwx1RWdcEAAABiBvqawAAAANk63aPAAAAAuIoui0AAAAAAAECvPgAAAAAAQK8+AAAAAABwxz56fw== + sbp: + crc: '0x7f7a' + length: 110 + msg_type: '0x85' + payload: BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAIBC9jlnwQAAACKqTiJBAADwx1RWdcEAAABiBvqawAAAANk63aPAAAAAuIoui0AAAAAAAECvPgAAAAAAQK8+AAAAAABwxz4= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml new file mode 100644 index 0000000000..43e3ee9d6f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepC.yaml @@ -0,0 +1,46 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGloDepC +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 2400 + health_bits: 0 + sid: + code: 3 + sat: 4 + toe: + tow: 443718 + wn: 2154 + ura: 5.2 + valid: 1 + d_tau: -2.7939677238464355e-09 + fcn: 14 + gamma: 9.094947017729282e-13 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + tau: -8.36281105875969e-05 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisGloDepC + msg_type: '0x87' + raw_json: '{"preamble":85,"msg_type":135,"sender":1219,"length":119,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg4=","crc":16791,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"d_tau":-2.7939677238464355e-09,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"fcn":14}' + raw_packet: VYcAwwR3BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg6XQQ== + sbp: + crc: '0x4197' + length: 119 + msg_type: '0x87' + payload: BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg4= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml new file mode 100644 index 0000000000..b8db74b38a --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGLODepD.yaml @@ -0,0 +1,47 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGloDepD +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 2400 + health_bits: 0 + sid: + code: 3 + sat: 4 + toe: + tow: 443718 + wn: 2154 + ura: 5.2 + valid: 1 + d_tau: -2.7939677238464355e-09 + fcn: 14 + gamma: 9.094947017729282e-13 + iod: 100 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + tau: -8.36281105875969e-05 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisGloDepD + msg_type: '0x88' + raw_json: '{"preamble":85,"msg_type":136,"sender":1219,"length":120,"payload":"BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg5k","crc":16466,"common":{"sid":{"sat":4,"code":3},"toe":{"tow":443718,"wn":2154},"ura":5.2,"fit_interval":2400,"valid":1,"health_bits":0},"gamma":9.094947017729282e-13,"tau":-8.36281105875969e-05,"d_tau":-2.7939677238464355e-09,"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"fcn":14,"iod":100}' + raw_packet: VYgAwwR4BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg5kUkA= + sbp: + crc: '0x4052' + length: 120 + msg_type: '0x88' + payload: BANGxQYAagjNzMzMzMwUQGAJAAABAAAAAAAAAHA9AAAAADDsFb8AAAAAAAAovgAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPg5k + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml new file mode 100644 index 0000000000..6be6294d11 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepE.yaml @@ -0,0 +1,55 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGPSDepE +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + af2: 0.0 + c_ic: 7.450580596923828e-09 + c_is: -1.1548399925231934e-07 + c_rc: 308.625 + c_rs: -52.3125 + c_uc: -2.7436763048171997e-06 + c_us: 3.1366944313049316e-06 + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + reserved: 0 + sat: 22 + toe: + tow: 446384 + wn: 2154 + ura: 2.0 + valid: 1 + dn: 5.694522914022375e-09 + ecc: 0.007072207052260637 + inc: 0.9341514480259797 + inc_dot: -4.035882396415757e-11 + iodc: 45 + iode: 45 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + sqrta: 5153.550029754639 + tgd: -1.7695128917694092e-08 + toc: + tow: 446384 + wn: 2154 + w: -0.9893036629599647 + module: sbp.observation + name: MsgEphemerisGPSDepE + msg_type: '0x81' + raw_json: '{"crc":60934,"length":185,"msg_type":129,"payload":"FgAAALDPBgBqCAAAAAAAAABAQDgAAAEAAAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9AAAAAAAAAACwzwYAaggtLQA=","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":0,"reserved":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":14400,"valid":1,"health_bits":0},"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0,"toc":{"tow":446384,"wn":2154},"iode":45,"iodc":45}' + raw_packet: VYEAewC5FgAAALDPBgBqCAAAAAAAAABAQDgAAAEAAAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9AAAAAAAAAACwzwYAaggtLQAG7g== + sbp: + crc: '0xee06' + length: 185 + msg_type: '0x81' + payload: FgAAALDPBgBqCAAAAAAAAABAQDgAAAEAAAAAAAAAU74AAAAAAChKwAAAAAAASnNAAAAAAAAEx74AAAAAAFDKPgAAAAAAAEA+AAAAAAAAf75y2GC0MXU4Po4pBetfh5a/AAAAIL/3fD8AAMDOjCG0QCmDs4aN+P2/44VRNsweQ77YO8cnYKjvv0cL2ZOR5O0/3S9k4P8vxr0AAAAAbLFEvwAAAAAAwKM9AAAAAAAAAACwzwYAaggtLQA= + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml new file mode 100644 index 0000000000..4a27e5f168 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGPSDepF.yaml @@ -0,0 +1,54 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGPSDepF +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -0.0006315018981695175 + af1: 8.981260180007666e-12 + af2: 0.0 + c_ic: 7.450580596923828e-09 + c_is: -1.1548399925231934e-07 + c_rc: 308.625 + c_rs: -52.3125 + c_uc: -2.7436763048171997e-06 + c_us: 3.1366944313049316e-06 + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 0 + sat: 22 + toe: + tow: 446384 + wn: 2154 + ura: 2.0 + valid: 1 + dn: 5.694522914022375e-09 + ecc: 0.007072207052260637 + inc: 0.9341514480259797 + inc_dot: -4.035882396415757e-11 + iodc: 45 + iode: 45 + m0: -0.02200078842114688 + omega0: -1.8731818448797617 + omegadot: -8.903585155774196e-09 + sqrta: 5153.550029754639 + tgd: -1.7695128917694092e-08 + toc: + tow: 446384 + wn: 2154 + w: -0.9893036629599647 + module: sbp.observation + name: MsgEphemerisGPSDepF + msg_type: '0x86' + raw_json: '{"crc":65139,"length":183,"msg_type":134,"payload":"FgCwzwYAaggAAAAAAAAAQEA4AAABAAAAAAAAAFO+AAAAAAAoSsAAAAAAAEpzQAAAAAAABMe+AAAAAABQyj4AAAAAAABAPgAAAAAAAH++cthgtDF1OD6OKQXrX4eWvwAAACC/93w/AADAzowhtEApg7OGjfj9v+OFUTbMHkO+2DvHJ2Co779HC9mTkeTtP90vZOD/L8a9AAAAAGyxRL8AAAAAAMCjPQAAAAAAAAAAsM8GAGoILS0A","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":14400,"valid":1,"health_bits":0},"tgd":-1.7695128917694092e-08,"c_rs":-52.3125,"c_rc":308.625,"c_uc":-2.7436763048171997e-06,"c_us":3.1366944313049316e-06,"c_ic":7.450580596923828e-09,"c_is":-1.1548399925231934e-07,"dn":5.694522914022375e-09,"m0":-0.02200078842114688,"ecc":0.007072207052260637,"sqrta":5153.550029754639,"omega0":-1.8731818448797617,"omegadot":-8.903585155774196e-09,"w":-0.9893036629599647,"inc":0.9341514480259797,"inc_dot":-4.035882396415757e-11,"af0":-0.0006315018981695175,"af1":8.981260180007666e-12,"af2":0,"toc":{"tow":446384,"wn":2154},"iode":45,"iodc":45}' + raw_packet: VYYAewC3FgCwzwYAaggAAAAAAAAAQEA4AAABAAAAAAAAAFO+AAAAAAAoSsAAAAAAAEpzQAAAAAAABMe+AAAAAABQyj4AAAAAAABAPgAAAAAAAH++cthgtDF1OD6OKQXrX4eWvwAAACC/93w/AADAzowhtEApg7OGjfj9v+OFUTbMHkO+2DvHJ2Co779HC9mTkeTtP90vZOD/L8a9AAAAAGyxRL8AAAAAAMCjPQAAAAAAAAAAsM8GAGoILS0Ac/4= + sbp: + crc: '0xfe73' + length: 183 + msg_type: '0x86' + payload: FgCwzwYAaggAAAAAAAAAQEA4AAABAAAAAAAAAFO+AAAAAAAoSsAAAAAAAEpzQAAAAAAABMe+AAAAAABQyj4AAAAAAABAPgAAAAAAAH++cthgtDF1OD6OKQXrX4eWvwAAACC/93w/AADAzowhtEApg7OGjfj9v+OFUTbMHkO+2DvHJ2Co779HC9mTkeTtP90vZOD/L8a9AAAAAGyxRL8AAAAAAMCjPQAAAAAAAAAAsM8GAGoILS0A + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml new file mode 100644 index 0000000000..d58d4901d5 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisGalDepA.yaml @@ -0,0 +1,55 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisGalDepA +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + af0: -1.7088896129280325e-05 + af1: -8.185452315956353e-12 + af2: 0.20000000298023224 + bgd_e1e5a: 1.2000000476837158 + bgd_e1e5b: 2.200000047683716 + c_ic: 3.200000047683716 + c_is: 4.199999809265137 + c_rc: 265.4375 + c_rs: 10.125 + c_uc: 5.199999809265137 + c_us: 6.199999809265137 + common: + fit_interval: 14400 + health_bits: 0 + sid: + code: 14 + sat: 27 + toe: + tow: 448800 + wn: 2154 + ura: 7.199999809265137 + valid: 1 + dn: 3.2262058129932258e-09 + ecc: 0.00017060607206076384 + inc: 0.9777456094977858 + inc_dot: -3.1787038343451465e-10 + iodc: 108 + iode: 108 + m0: -1.8457115744155868 + omega0: 1.16967730598334 + omegadot: -5.757382675240872e-09 + sqrta: 5440.602401733398 + toc: + tow: 448800 + wn: 2154 + w: 0.12250912091662625 + module: sbp.observation + name: MsgEphemerisGalDepA + msg_type: '0x95' + raw_json: '{"preamble":85,"msg_type":149,"sender":1219,"length":152,"payload":"Gw4g2QYAaghmZuZAQDgAAAEAmpmZP83MDEAAACJBALiEQ2ZmpkBmZsZAzcxMQGZmhkDZzIJpgLYrPvhqH9wIiP2/AAAAAJdcJj8AAAA3mkC1QDgmAY3/tvI/3pOIJ0+6OL5Qcsz7wVy/P+03EymxSe8/MUG98AjY9b3/////Q+vxvv///////6G9zcxMPiDZBgBqCGwAbAA=","crc":12712,"common":{"sid":{"sat":27,"code":14},"toe":{"tow":448800,"wn":2154},"ura":7.199999809265137,"fit_interval":14400,"valid":1,"health_bits":0},"bgd_e1e5a":1.2000000476837158,"bgd_e1e5b":2.200000047683716,"c_rs":10.125,"c_rc":265.4375,"c_uc":5.199999809265137,"c_us":6.199999809265137,"c_ic":3.200000047683716,"c_is":4.199999809265137,"dn":3.2262058129932258e-09,"m0":-1.8457115744155868,"ecc":0.00017060607206076384,"sqrta":5440.602401733398,"omega0":1.16967730598334,"omegadot":-5.757382675240872e-09,"w":0.12250912091662625,"inc":0.9777456094977858,"inc_dot":-3.1787038343451465e-10,"af0":-1.7088896129280325e-05,"af1":-8.185452315956353e-12,"af2":0.20000000298023224,"toc":{"tow":448800,"wn":2154},"iode":108,"iodc":108}' + raw_packet: VZUAwwSYGw4g2QYAaghmZuZAQDgAAAEAmpmZP83MDEAAACJBALiEQ2ZmpkBmZsZAzcxMQGZmhkDZzIJpgLYrPvhqH9wIiP2/AAAAAJdcJj8AAAA3mkC1QDgmAY3/tvI/3pOIJ0+6OL5Qcsz7wVy/P+03EymxSe8/MUG98AjY9b3/////Q+vxvv///////6G9zcxMPiDZBgBqCGwAbACoMQ== + sbp: + crc: '0x31a8' + length: 152 + msg_type: '0x95' + payload: Gw4g2QYAaghmZuZAQDgAAAEAmpmZP83MDEAAACJBALiEQ2ZmpkBmZsZAzcxMQGZmhkDZzIJpgLYrPvhqH9wIiP2/AAAAAJdcJj8AAAA3mkC1QDgmAY3/tvI/3pOIJ0+6OL5Qcsz7wVy/P+03EymxSe8/MUG98AjY9b3/////Q+vxvv///////6G9zcxMPiDZBgBqCGwAbAA= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml new file mode 100644 index 0000000000..0cb7c84fe5 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbas.yaml @@ -0,0 +1,44 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisSbas +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + a_gf0: -0.0006315018981695175 + a_gf1: 8.981260180007666e-12 + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 0 + health_bits: 0 + sid: + code: 6 + sat: 22 + toe: + tow: 446384 + wn: 2154 + ura: -2.7939677238464355e-09 + valid: 1 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + vel: + - -1726.5062255859375 + - -2542.614990234375 + - 869.8177490234375 + module: sbp.observation + name: MsgEphemerisSbas + msg_type: '0x8c' + raw_json: '{"crc":37824,"length":74,"msg_type":140,"payload":"FgawzwYAaggAAECxAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBM9DXxNfpHsVWdFlEAAB6NQAAejUAgDs2YIslugAAHi0=","preamble":85,"sender":1219,"common":{"sid":{"sat":22,"code":6},"toe":{"tow":446384,"wn":2154},"ura":-2.7939677238464355e-09,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.5062255859375,-2542.614990234375,869.8177490234375],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}' + raw_packet: VYwAwwRKFgawzwYAaggAAECxAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBM9DXxNfpHsVWdFlEAAB6NQAAejUAgDs2YIslugAAHi3Akw== + sbp: + crc: '0x93c0' + length: 74 + msg_type: '0x8c' + payload: FgawzwYAaggAAECxAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBM9DXxNfpHsVWdFlEAAB6NQAAejUAgDs2YIslugAAHi0= + preamble: '0x55' + sender: '0x04c3' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml new file mode 100644 index 0000000000..8fa6235ed0 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepA.yaml @@ -0,0 +1,45 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisSbasDepA +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + a_gf0: -0.0006315018981695175 + a_gf1: 8.981260180007666e-12 + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 0 + health_bits: 0 + sid: + code: 6 + reserved: 0 + sat: 22 + toe: + tow: 446384 + wn: 2154 + ura: 2.0 + valid: 1 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisSbasDepA + msg_type: '0x82' + raw_json: '{"crc":46258,"length":112,"msg_type":130,"payload":"FgAGALDPBgBqCAAAAAAAAABAAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBAAAAYgb6msAAAADZOt2jwAAAALiKLotAAAAAAABArz4AAAAAAECvPgAAAAAAcMc+AAAAAGyxRL8AAAAAAMCjPQ==","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":6,"reserved":0},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}' + raw_packet: VYIAewBwFgAGALDPBgBqCAAAAAAAAABAAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBAAAAYgb6msAAAADZOt2jwAAAALiKLotAAAAAAABArz4AAAAAAECvPgAAAAAAcMc+AAAAAGyxRL8AAAAAAMCjPbK0 + sbp: + crc: '0xb4b2' + length: 112 + msg_type: '0x82' + payload: FgAGALDPBgBqCAAAAAAAAABAAAAAAAEAAACAQvY5Z8EAAAAiqk4iQQAA8MdUVnXBAAAAYgb6msAAAADZOt2jwAAAALiKLotAAAAAAABArz4AAAAAAECvPgAAAAAAcMc+AAAAAGyxRL8AAAAAAMCjPQ== + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml new file mode 100644 index 0000000000..5df847f57b --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgEphemerisSbasDepB.yaml @@ -0,0 +1,44 @@ +description: Unit tests for swiftnav.sbp.observation MsgEphemerisSbasDepB +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + a_gf0: -0.0006315018981695175 + a_gf1: 8.981260180007666e-12 + acc: + - 9.313225746154785e-07 + - 9.313225746154785e-07 + - 2.7939677238464355e-06 + common: + fit_interval: 0 + health_bits: 0 + sid: + code: 6 + sat: 22 + toe: + tow: 446384 + wn: 2154 + ura: 2.0 + valid: 1 + pos: + - -12177330.078125 + - 599893.06640625 + - -22373708.49609375 + vel: + - -1726.506233215332 + - -2542.6149368286133 + - 869.8177337646484 + module: sbp.observation + name: MsgEphemerisSbasDepB + msg_type: '0x84' + raw_json: '{"crc":26769,"length":110,"msg_type":132,"payload":"FgawzwYAaggAAAAAAAAAQAAAAAABAAAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPgAAAABssUS/AAAAAADAoz0=","preamble":85,"sender":123,"common":{"sid":{"sat":22,"code":6},"toe":{"tow":446384,"wn":2154},"ura":2,"fit_interval":0,"valid":1,"health_bits":0},"pos":[-12177330.078125,599893.06640625,-22373708.49609375],"vel":[-1726.506233215332,-2542.6149368286133,869.8177337646484],"acc":[9.313225746154785e-07,9.313225746154785e-07,2.7939677238464355e-06],"a_gf0":-0.0006315018981695175,"a_gf1":8.981260180007666e-12}' + raw_packet: VYQAewBuFgawzwYAaggAAAAAAAAAQAAAAAABAAAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPgAAAABssUS/AAAAAADAoz2RaA== + sbp: + crc: '0x6891' + length: 110 + msg_type: '0x84' + payload: FgawzwYAaggAAAAAAAAAQAAAAAABAAAAgEL2OWfBAAAAIqpOIkEAAPDHVFZ1wQAAAGIG+prAAAAA2Trdo8AAAAC4ii6LQAAAAAAAQK8+AAAAAABArz4AAAAAAHDHPgAAAABssUS/AAAAAADAoz0= + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml new file mode 100644 index 0000000000..8ea873dd51 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGnssCapb.yaml @@ -0,0 +1,38 @@ +description: Unit tests for swiftnav.sbp.observation MsgGnssCapb +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + gc: + bds_active: 1929005864 + bds_b2: 33839445 + bds_b2a: 378107113 + bds_d2nav: 1367053175 + gal_active: 1392028637 + gal_e5: 484261628 + glo_active: 13159676 + glo_l2of: 824073421 + glo_l3: 404081648 + gps_active: 1079028506 + gps_l2c: 781233489 + gps_l5: 1818069969 + qzss_active: 198929863 + sbas_active: 548822484 + sbas_l5: 465576041 + t_nmct: + tow: 446384 + wn: 2154 + module: sbp.observation + name: MsgGnssCapb + msg_type: '0x96' + raw_json: '{"crc":23203,"length":110,"msg_type":150,"payload":"sM8GAGoIGqtQQAAAAABRrZAuAAAAANGLXWwAAAAA/MzIAM1cHjHwyxUY1F22IAAAAABpIMAbAAAAAChL+nIAAAAAd5N7UQAAAABVWQQCAAAAAOl0iRYAAAAAx23bC92r+FIAAAAA/D7dHAAAAAA=","preamble":85,"sender":123,"t_nmct":{"tow":446384,"wn":2154},"gc":{"gps_active":1079028506,"gps_l2c":781233489,"gps_l5":1818069969,"glo_active":13159676,"glo_l2of":824073421,"glo_l3":404081648,"sbas_active":548822484,"sbas_l5":465576041,"bds_active":1929005864,"bds_d2nav":1367053175,"bds_b2":33839445,"bds_b2a":378107113,"qzss_active":198929863,"gal_active":1392028637,"gal_e5":484261628}}' + raw_packet: VZYAewBusM8GAGoIGqtQQAAAAABRrZAuAAAAANGLXWwAAAAA/MzIAM1cHjHwyxUY1F22IAAAAABpIMAbAAAAAChL+nIAAAAAd5N7UQAAAABVWQQCAAAAAOl0iRYAAAAAx23bC92r+FIAAAAA/D7dHAAAAACjWg== + sbp: + crc: '0x5aa3' + length: 110 + msg_type: '0x96' + payload: sM8GAGoIGqtQQAAAAABRrZAuAAAAANGLXWwAAAAA/MzIAM1cHjHwyxUY1F22IAAAAABpIMAbAAAAAChL+nIAAAAAd5N7UQAAAABVWQQCAAAAAOl0iRYAAAAAx23bC92r+FIAAAAA/D7dHAAAAAA= + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml new file mode 100644 index 0000000000..2e8422625d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelay.yaml @@ -0,0 +1,29 @@ +description: Unit tests for swiftnav.sbp.observation MsgGroupDelay +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + isc_l1ca: -91 + isc_l2c: 6125 + sid: + code: 0 + sat: 22 + t_op: + tow: 446384 + wn: 2154 + tgd: -514 + valid: 1 + module: sbp.observation + name: MsgGroupDelay + msg_type: '0x94' + raw_json: '{"crc":51458,"length":15,"msg_type":148,"payload":"sM8GAGoIFgAB/v2l/+0X","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"sid":{"sat":22,"code":0},"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}' + raw_packet: VZQAewAPsM8GAGoIFgAB/v2l/+0XAsk= + sbp: + crc: '0xc902' + length: 15 + msg_type: '0x94' + payload: sM8GAGoIFgAB/v2l/+0X + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml new file mode 100644 index 0000000000..f47e61df3d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepA.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.observation MsgGroupDelayDepA +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + isc_l1ca: -91 + isc_l2c: 6125 + prn: 22 + t_op: + tow: 446384 + wn: 2154 + tgd: -514 + valid: 1 + module: sbp.observation + name: MsgGroupDelayDepA + msg_type: '0x92' + raw_json: '{"crc":23458,"length":14,"msg_type":146,"payload":"sM8GAGoIFgH+/aX/7Rc=","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"prn":22,"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}' + raw_packet: VZIAewAOsM8GAGoIFgH+/aX/7ReiWw== + sbp: + crc: '0x5ba2' + length: 14 + msg_type: '0x92' + payload: sM8GAGoIFgH+/aX/7Rc= + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml new file mode 100644 index 0000000000..4c8baa373f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgGroupDelayDepB.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.observation MsgGroupDelayDepB +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + isc_l1ca: -91 + isc_l2c: 6125 + sid: + code: 0 + reserved: 0 + sat: 22 + t_op: + tow: 446384 + wn: 2154 + tgd: -514 + valid: 1 + module: sbp.observation + name: MsgGroupDelayDepB + msg_type: '0x93' + raw_json: '{"crc":51933,"length":17,"msg_type":147,"payload":"sM8GAGoIFgAAAAH+/aX/7Rc=","preamble":85,"sender":123,"t_op":{"tow":446384,"wn":2154},"sid":{"sat":22,"code":0,"reserved":0},"valid":1,"tgd":-514,"isc_l1ca":-91,"isc_l2c":6125}' + raw_packet: VZMAewARsM8GAGoIFgAAAAH+/aX/7Rfdyg== + sbp: + crc: '0xcadd' + length: 17 + msg_type: '0x93' + payload: sM8GAGoIFgAAAAH+/aX/7Rc= + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml new file mode 100644 index 0000000000..5798b3ab49 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgIono.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.observation MsgIono +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + a0: 4.6566128730773926e-09 + a1: 1.4901161193847656e-08 + a2: -5.960464477539063e-08 + a3: -5.960464477539063e-08 + b0: 77824.0 + b1: 49152.0 + b2: -65536.0 + b3: -327680.0 + t_nmct: + tow: 0 + wn: 0 + module: sbp.observation + name: MsgIono + msg_type: '0x90' + raw_json: '{"crc":8037,"length":70,"msg_type":144,"payload":"AAAAAAAAAAAAAAAAND4AAAAAAABQPgAAAAAAAHC+AAAAAAAAcL4AAAAAAADzQAAAAAAAAOhAAAAAAAAA8MAAAAAAAAAUwQ==","preamble":85,"sender":123,"t_nmct":{"tow":0,"wn":0},"a0":4.6566128730773926e-09,"a1":1.4901161193847656e-08,"a2":-5.960464477539063e-08,"a3":-5.960464477539063e-08,"b0":77824,"b1":49152,"b2":-65536,"b3":-327680}' + raw_packet: VZAAewBGAAAAAAAAAAAAAAAAND4AAAAAAABQPgAAAAAAAHC+AAAAAAAAcL4AAAAAAADzQAAAAAAAAOhAAAAAAAAA8MAAAAAAAAAUwWUf + sbp: + crc: '0x1f65' + length: 70 + msg_type: '0x90' + payload: AAAAAAAAAAAAAAAAND4AAAAAAABQPgAAAAAAAHC+AAAAAAAAcL4AAAAAAADzQAAAAAAAAOhAAAAAAAAA8MAAAAAAAAAUwQ== + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObs.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObs.yaml index 68aab39a93..ecaece7306 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObs.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObs.yaml @@ -196,7 +196,10 @@ tests: sat: 18 code: 3 c_decoded_fields: - n_obs: 14 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 14 module: sbp.observation name: MsgObs msg_type: '0x4a' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepB.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepB.yaml index 224566e598..d5848f9669 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepB.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepB.yaml @@ -73,7 +73,10 @@ tests: reserved: 0 sat: 218 c_decoded_fields: - n_obs: 6 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 6 module: sbp.observation name: MsgObsDepB msg_type: '0x43' @@ -137,7 +140,10 @@ tests: reserved: 0 sat: 225 c_decoded_fields: - n_obs: 3 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 3 module: sbp.observation name: MsgObsDepB msg_type: '0x43' @@ -226,7 +232,10 @@ tests: reserved: 0 sat: 218 c_decoded_fields: - n_obs: 6 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 6 module: sbp.observation name: MsgObsDepB msg_type: '0x43' @@ -290,7 +299,10 @@ tests: reserved: 0 sat: 225 c_decoded_fields: - n_obs: 3 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 3 module: sbp.observation name: MsgObsDepB msg_type: '0x43' @@ -379,7 +391,10 @@ tests: reserved: 0 sat: 218 c_decoded_fields: - n_obs: 6 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 6 module: sbp.observation name: MsgObsDepB msg_type: '0x43' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepC.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepC.yaml index 1afa166725..665941cdd0 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepC.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgObsDepC.yaml @@ -63,7 +63,10 @@ tests: reserved: 0 sat: 12 c_decoded_fields: - n_obs: 5 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 5 module: sbp.observation name: MsgObsDepC msg_type: '0x49' @@ -125,7 +128,10 @@ tests: reserved: 0 sat: 29 c_decoded_fields: - n_obs: 3 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 3 module: sbp.observation name: MsgObsDepC msg_type: '0x49' @@ -204,7 +210,10 @@ tests: reserved: 0 sat: 12 c_decoded_fields: - n_obs: 5 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 5 module: sbp.observation name: MsgObsDepC msg_type: '0x49' @@ -266,7 +275,10 @@ tests: reserved: 0 sat: 29 c_decoded_fields: - n_obs: 3 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 3 module: sbp.observation name: MsgObsDepC msg_type: '0x49' @@ -345,7 +357,10 @@ tests: reserved: 0 sat: 12 c_decoded_fields: - n_obs: 5 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 5 module: sbp.observation name: MsgObsDepC msg_type: '0x49' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgOsr.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgOsr.yaml index 6e07e00c8b..cdce74b08b 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgOsr.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgOsr.yaml @@ -158,7 +158,10 @@ tests: tropo_std: 5 range_std: 5 c_decoded_fields: - n_obs: 12 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 12 module: sbp.observation name: MsgOsr msg_type: '0x640' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvAzEl.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvAzEl.yaml index ec0fea9332..06b9da33e3 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvAzEl.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvAzEl.yaml @@ -171,7 +171,10 @@ tests: code: 14 sat: 36 c_decoded_fields: - n_azel: 33 + n_azel: + handle_as: vararray-len + relates_to: azel + value: 33 module: sbp.observation name: MsgSvAzEl msg_type: '0x97' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml new file mode 100644 index 0000000000..e836d2cb03 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_MsgSvConfigurationGpsDep.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.observation MsgSvConfigurationGpsDep +generated_on: 2023-11-15 # manually generated +package: sbp.observation +tests: + +- msg: + fields: + l2c_mask: 2808462402 + t_nmct: + tow: 0 + wn: 0 + module: sbp.observation + name: MsgSvConfigurationGPSDep + msg_type: '0x91' + raw_json: '{"crc":10770,"length":10,"msg_type":145,"payload":"AAAAAAAAQrxlpw==","preamble":85,"sender":123,"t_nmct":{"tow":0,"wn":0},"l2c_mask":2808462402}' + raw_packet: VZEAewAKAAAAAAAAQrxlpxIq + sbp: + crc: '0x2a12' + length: 10 + msg_type: '0x91' + payload: AAAAAAAAQrxlpw== + preamble: '0x55' + sender: '0x007b' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_msgObsDepA.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_msgObsDepA.yaml index a62f432a0d..c065455a1a 100644 --- a/spec/tests/yaml/swiftnav/sbp/observation/test_msgObsDepA.yaml +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_msgObsDepA.yaml @@ -62,7 +62,10 @@ tests: lock: 15074 prn: 30 c_decoded_fields: - n_obs: 7 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 7 module: sbp.observation name: MsgObsDepA msg_type: '0x45' @@ -101,7 +104,10 @@ tests: lock: 64062 prn: 31 c_decoded_fields: - n_obs: 1 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 1 module: sbp.observation name: MsgObsDepA msg_type: '0x45' @@ -176,7 +182,10 @@ tests: lock: 15074 prn: 30 c_decoded_fields: - n_obs: 7 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 7 module: sbp.observation name: MsgObsDepA msg_type: '0x45' @@ -215,7 +224,10 @@ tests: lock: 64062 prn: 31 c_decoded_fields: - n_obs: 1 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 1 module: sbp.observation name: MsgObsDepA msg_type: '0x45' @@ -276,7 +288,10 @@ tests: lock: 22736 prn: 30 c_decoded_fields: - n_obs: 5 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 5 module: sbp.observation name: MsgObsDepA msg_type: '0x45' @@ -341,7 +356,10 @@ tests: lock: 22736 prn: 30 c_decoded_fields: - n_obs: 5 + n_obs: + handle_as: vararray-len + relates_to: obs + value: 5 module: sbp.observation name: MsgObsDepA msg_type: '0x45' diff --git a/spec/tests/yaml/swiftnav/sbp/observation/test_observation_structs.yaml b/spec/tests/yaml/swiftnav/sbp/observation/test_observation_structs.yaml new file mode 100644 index 0000000000..66d7c063c2 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/observation/test_observation_structs.yaml @@ -0,0 +1,205 @@ +description: Unit tests for swiftnav.sbp.observation free structs +generated_on: 2023-11-15 # manually generated +package: sbp.observation +struct_tests: + + - encoded: gQTKR1UxTdN6sEQ= + fields: + t: + wn: 45178 + tow: 1204421761 + ns_residual: -749915819 + n_obs: 68 + module: sbp.observation + name: ObservationHeader + - encoded: TyO5 + fields: + i: 9039 + f: 185 + module: sbp.observation + name: Doppler + - encoded: 6nz480O1XpJxIUSMNrlBquY= + fields: + P: 4093148394 + L: + i: -1839286973 + f: 113 + D: + i: 17441 + f: 140 + cn0: 54 + lock: 185 + flags: 65 + sid: + sat: 170 + code: 230 + module: sbp.observation + name: PackedObsContent + - encoded: jUwU7y0trjXY5ig4vcsoC2MkCQ== + fields: + P: 4011084941 + L: + i: 900607277 + f: 216 + lock: 230 + flags: 40 + sid: + sat: 56 + code: 189 + iono_std: 10443 + tropo_std: 25355 + range_std: 2340 + module: sbp.observation + name: PackedOsrContent + - encoded: Rl2IxRRi+5kzE1tFW5wzP/pz + fields: + sid: + sat: 70 + code: 93 + toe: + wn: 39419 + tow: 1645528456 + ura: 3505.199951 + fit_interval: 1060346971 + valid: 250 + health_bits: 115 + module: sbp.observation + name: EphemerisCommonContent + - encoded: BaKzl/WqywEzMzMzM/i7QKnTnwtGYA== + fields: + sid: + sat: 5 + code: 162 + toe: + wn: 459 + tow: 2868221875 + ura: 7160.200000 + fit_interval: 195023785 + valid: 70 + health_bits: 96 + module: sbp.observation + name: EphemerisCommonContentDepB + - encoded: caLhAOnjpWJasWZmZmZmbKhAKTUB18dx + fields: + sid: + sat: 41585 + code: 225 + toe: + wn: 45402 + tow: 1655038953 + ura: 3126.200000 + fit_interval: 3607180585 + valid: 199 + health_bits: 113 + module: sbp.observation + name: EphemerisCommonContentDepA + - encoded: h/Bc+BA6IQ== + fields: + t: + tow: 4166840455 + wn: 14864 + n_obs: 33 + module: sbp.observation + name: ObservationHeaderDep + - encoded: hzXfQ9k= + fields: + i: 1138701703 + f: 217 + module: sbp.observation + name: CarrierPhaseDepA + - encoded: FnmSV3Fs38PTr1LLkw== + fields: + P: 1469217046 + L: + f: 211 + i: -1008767887 + cn0: 175 + lock: 52050 + prn: 147 + module: sbp.observation + name: PackedObsContentDepA + - encoded: hZrvrSpkEOub355CyqZn0A== + fields: + P: 2918161029 + L: + f: 155 + i: -351247318 + cn0: 223 + lock: 17054 + sid: + sat: 42698 + code: 103 + reserved: 208 + module: sbp.observation + name: PackedObsContentDepB + - encoded: QKxwxnC9WF5OcTJoKNGgWg== + fields: + P: 3329272896 + L: + f: 78 + i: 1582873968 + cn0: 113 + lock: 26674 + sid: + sat: 53544 + code: 160 + reserved: 90 + module: sbp.observation + name: PackedObsContentDepC + - encoded: s3DhscIAAACvXrXCAgAAAClrRIVfAAAAbdan19vAvJsFKUh2DrmVm8IAAABmDsZH0QAAAEngkLf6AAAAy2h3XecAAADjxLaCzAAAALaO+E3YAAAAU+a5fcRG2CqmAAAAbnUOSBMAAAA= + fields: + gps_active: 836207997107 + gps_l2c: 11856600751 + gps_l5: 410257746729 + glo_active: 3618100845 + glo_l2of: 2612838619 + glo_l3: 1984440581 + sbas_active: 835833936142 + sbas_l5: 898852327014 + bds_active: 1076821549129 + bds_d2nav: 993705552075 + bds_b2: 878366344419 + bds_b2a: 929021071030 + qzss_active: 2109335123 + gal_active: 713683388100 + gal_e5: 82813285742 + module: sbp.observation + name: GnssCapb + - encoded: o7UAQzzG3TozMzMzM2q/QPEggLlAGA== + fields: + sid: + sat: 163 + code: 181 + toa: + wn: 15069 + tow: 3325838080 + ura: 8042.200000 + fit_interval: 3112182001 + valid: 64 + health_bits: 24 + module: sbp.observation + name: AlmanacCommonContent + - encoded: nN8gCm2gIUyKCzMzMzMzWrpAFbve9DSO + fields: + sid: + sat: 57244 + code: 32 + reserved: 10 + toa: + wn: 2954 + tow: 1277272173 + ura: 6746.200000 + fit_interval: 4108237589 + valid: 52 + health_bits: 142 + module: sbp.observation + name: AlmanacCommonContentDep + - encoded: cy5/Vw== + fields: + sid: + sat: 115 + code: 46 + az: 127 + el: 87 + module: sbp.observation + name: SvAzEl diff --git a/spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml b/spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml new file mode 100644 index 0000000000..49cd255fc3 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/orientation/test_MsgBaselineHeading.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.orientation MsgBaselineHeading +generated_on: 2023-11-15 # manually generated +package: sbp.orientation +tests: + +- msg: + fields: + flags: 91 + heading: 1036342316 + n_sats: 91 + tow: 3289197980 + module: sbp.orientation + name: MsgBaselineHeading + msg_type: '0x20f' + raw_json: '{"crc":65248,"length":10,"msg_type":527,"payload":"nC0NxCxUxT1bWw==","preamble":85,"sender":24019,"tow":3289197980,"heading":1036342316,"n_sats":91,"flags":91}' + raw_packet: VQ8C010KnC0NxCxUxT1bW+D+ + sbp: + crc: '0xfee0' + length: 10 + msg_type: '0x20f' + payload: nC0NxCxUxT1bWw== + preamble: '0x55' + sender: '0x5dd3' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml new file mode 100644 index 0000000000..7d1f63798e --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgAlmanac.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgAlmanac +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgAlmanac + msg_type: '0x69' + raw_json: '{"crc":44025,"length":0,"msg_type":105,"payload":"","preamble":85,"sender":35436}' + raw_packet: VWkAbIoA+as= + sbp: + crc: '0xabf9' + length: 0 + msg_type: '0x69' + payload: "" + preamble: '0x55' + sender: '0x8a6c' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml new file mode 100644 index 0000000000..0d202a8852 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCellModemStatus.yaml @@ -0,0 +1,277 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCellModemStatus +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + c_decoded_fields: + n_reserved: + handle_as: vararray-len + relates_to: reserved + value: 250 + fields: + reserved: + - 123 + - 242 + - 46 + - 52 + - 64 + - 176 + - 154 + - 98 + - 43 + - 132 + - 196 + - 89 + - 253 + - 161 + - 250 + - 174 + - 204 + - 110 + - 47 + - 38 + - 187 + - 63 + - 102 + - 177 + - 162 + - 49 + - 80 + - 194 + - 37 + - 107 + - 60 + - 225 + - 52 + - 101 + - 178 + - 142 + - 246 + - 21 + - 17 + - 93 + - 75 + - 169 + - 86 + - 16 + - 209 + - 80 + - 243 + - 30 + - 206 + - 220 + - 206 + - 115 + - 47 + - 154 + - 91 + - 227 + - 88 + - 11 + - 1 + - 85 + - 146 + - 100 + - 190 + - 232 + - 207 + - 61 + - 61 + - 201 + - 220 + - 31 + - 78 + - 34 + - 57 + - 82 + - 59 + - 104 + - 65 + - 221 + - 0 + - 43 + - 210 + - 9 + - 32 + - 122 + - 29 + - 237 + - 11 + - 151 + - 223 + - 18 + - 81 + - 204 + - 172 + - 234 + - 127 + - 3 + - 82 + - 133 + - 169 + - 12 + - 176 + - 193 + - 0 + - 24 + - 121 + - 85 + - 55 + - 214 + - 198 + - 75 + - 234 + - 179 + - 214 + - 85 + - 94 + - 115 + - 21 + - 73 + - 121 + - 75 + - 46 + - 158 + - 63 + - 100 + - 122 + - 213 + - 20 + - 85 + - 212 + - 131 + - 50 + - 224 + - 218 + - 215 + - 215 + - 149 + - 2 + - 19 + - 129 + - 39 + - 164 + - 5 + - 175 + - 6 + - 62 + - 51 + - 78 + - 66 + - 248 + - 116 + - 88 + - 90 + - 128 + - 226 + - 177 + - 0 + - 47 + - 140 + - 33 + - 126 + - 221 + - 110 + - 144 + - 97 + - 74 + - 250 + - 181 + - 199 + - 27 + - 176 + - 65 + - 185 + - 110 + - 92 + - 34 + - 44 + - 131 + - 96 + - 178 + - 40 + - 176 + - 4 + - 90 + - 36 + - 7 + - 180 + - 244 + - 244 + - 23 + - 108 + - 171 + - 204 + - 196 + - 61 + - 51 + - 179 + - 242 + - 156 + - 81 + - 83 + - 16 + - 15 + - 134 + - 40 + - 245 + - 253 + - 150 + - 94 + - 150 + - 144 + - 197 + - 113 + - 5 + - 141 + - 232 + - 33 + - 101 + - 231 + - 38 + - 75 + - 178 + - 243 + - 119 + - 1 + - 248 + - 218 + - 86 + - 7 + - 88 + - 197 + - 148 + - 240 + - 227 + - 2 + - 65 + - 173 + - 122 + - 143 + - 251 + - 156 + - 217 + - 67 + - 239 + - 219 + - 31 + - 224 + - 176 + - 129 + - 81 + - 80 + signal_error_rate: 8588.2001953125 + signal_strength: 103 + module: sbp.piksi + name: MsgCellModemStatus + msg_type: '0xbe' + raw_json: '{"preamble":85,"msg_type":190,"sender":6931,"length":255,"payload":"Z80wBkZ78i40QLCaYiuExFn9ofquzG4vJrs/ZrGiMVDCJWs84TRlso72FRFdS6lWENFQ8x7O3M5zL5pb41gLAVWSZL7ozz09ydwfTiI5UjtoQd0AK9IJIHod7QuX3xJRzKzqfwNShakMsMEAGHlVN9bGS+qz1lVecxVJeUsunj9ketUUVdSDMuDa19eVAhOBJ6QFrwY+M05C+HRYWoDisQAvjCF+3W6QYUr6tccbsEG5blwiLINgsiiwBFokB7T09Bdsq8zEPTOz8pxRUxAPhij1/ZZelpDFcQWN6CFl5yZLsvN3AfjaVgdYxZTw4wJBrXqP+5zZQ+/bH+CwgVFQ","crc":58920,"signal_strength":103,"signal_error_rate":8588.2001953125,"reserved":[123,242,46,52,64,176,154,98,43,132,196,89,253,161,250,174,204,110,47,38,187,63,102,177,162,49,80,194,37,107,60,225,52,101,178,142,246,21,17,93,75,169,86,16,209,80,243,30,206,220,206,115,47,154,91,227,88,11,1,85,146,100,190,232,207,61,61,201,220,31,78,34,57,82,59,104,65,221,0,43,210,9,32,122,29,237,11,151,223,18,81,204,172,234,127,3,82,133,169,12,176,193,0,24,121,85,55,214,198,75,234,179,214,85,94,115,21,73,121,75,46,158,63,100,122,213,20,85,212,131,50,224,218,215,215,149,2,19,129,39,164,5,175,6,62,51,78,66,248,116,88,90,128,226,177,0,47,140,33,126,221,110,144,97,74,250,181,199,27,176,65,185,110,92,34,44,131,96,178,40,176,4,90,36,7,180,244,244,23,108,171,204,196,61,51,179,242,156,81,83,16,15,134,40,245,253,150,94,150,144,197,113,5,141,232,33,101,231,38,75,178,243,119,1,248,218,86,7,88,197,148,240,227,2,65,173,122,143,251,156,217,67,239,219,31,224,176,129,81,80]}' + raw_packet: Vb4AExv/Z80wBkZ78i40QLCaYiuExFn9ofquzG4vJrs/ZrGiMVDCJWs84TRlso72FRFdS6lWENFQ8x7O3M5zL5pb41gLAVWSZL7ozz09ydwfTiI5UjtoQd0AK9IJIHod7QuX3xJRzKzqfwNShakMsMEAGHlVN9bGS+qz1lVecxVJeUsunj9ketUUVdSDMuDa19eVAhOBJ6QFrwY+M05C+HRYWoDisQAvjCF+3W6QYUr6tccbsEG5blwiLINgsiiwBFokB7T09Bdsq8zEPTOz8pxRUxAPhij1/ZZelpDFcQWN6CFl5yZLsvN3AfjaVgdYxZTw4wJBrXqP+5zZQ+/bH+CwgVFQKOY= + sbp: + crc: '0xe628' + length: 255 + msg_type: '0xbe' + payload: Z80wBkZ78i40QLCaYiuExFn9ofquzG4vJrs/ZrGiMVDCJWs84TRlso72FRFdS6lWENFQ8x7O3M5zL5pb41gLAVWSZL7ozz09ydwfTiI5UjtoQd0AK9IJIHod7QuX3xJRzKzqfwNShakMsMEAGHlVN9bGS+qz1lVecxVJeUsunj9ketUUVdSDMuDa19eVAhOBJ6QFrwY+M05C+HRYWoDisQAvjCF+3W6QYUr6tccbsEG5blwiLINgsiiwBFokB7T09Bdsq8zEPTOz8pxRUxAPhij1/ZZelpDFcQWN6CFl5yZLsvN3AfjaVgdYxZTw4wJBrXqP+5zZQ+/bH+CwgVFQ + preamble: '0x55' + sender: '0x1b13' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml new file mode 100644 index 0000000000..72b759315d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandOutput.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCommandOutput +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + c_decoded_fields: + line: + handle_as: encoded-string + encoded_len: 16 + fn_prefix: sbp_msg_command_output_line + text: Some output text + fields: + line: Some output text + sequence: 2507449470 + module: sbp.piksi + name: MsgCommandOutput + msg_type: '0xbc' + raw_json: '{"crc":27915,"length":20,"msg_type":188,"payload":"fqR0lVNvbWUgb3V0cHV0IHRleHQ=","preamble":85,"sender":21554,"sequence":2507449470,"line":"Some output text"}' + raw_packet: VbwAMlQUfqR0lVNvbWUgb3V0cHV0IHRleHQLbQ== + sbp: + crc: '0x6d0b' + length: 20 + msg_type: '0xbc' + payload: fqR0lVNvbWUgb3V0cHV0IHRleHQ= + preamble: '0x55' + sender: '0x5432' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml new file mode 100644 index 0000000000..b24c5fcff8 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandReq.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCommandReq +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + c_decoded_fields: + command: + handle_as: encoded-string + encoded_len: 27 + fn_prefix: sbp_msg_command_req_command + text: "/path/to/command with args" + fields: + command: "/path/to/command with args\0" + sequence: 1755532595 + module: sbp.piksi + name: MsgCommandReq + msg_type: '0xb8' + raw_json: '{"crc":6182,"length":31,"msg_type":184,"payload":"M02jaC9wYXRoL3RvL2NvbW1hbmQgd2l0aCBhcmdzAA==","preamble":85,"sender":47274,"sequence":1755532595,"command":"/path/to/command with args\u0000"}' + raw_packet: VbgAqrgfM02jaC9wYXRoL3RvL2NvbW1hbmQgd2l0aCBhcmdzACYY + sbp: + crc: '0x1826' + length: 31 + msg_type: '0xb8' + payload: M02jaC9wYXRoL3RvL2NvbW1hbmQgd2l0aCBhcmdzAA== + preamble: '0x55' + sender: '0xb8aa' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml new file mode 100644 index 0000000000..62234bde5d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCommandResp.yaml @@ -0,0 +1,21 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCommandResp +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + code: 1737912018 + sequence: 2692994934 + module: sbp.piksi + name: MsgCommandResp + msg_type: '0xb9' + raw_json: '{"crc":61604,"length":8,"msg_type":185,"payload":"dteDoNJulmc=","preamble":85,"sender":52793,"sequence":2692994934,"code":1737912018}' + raw_packet: VbkAOc4IdteDoNJulmek8A== + sbp: + crc: '0xf0a4' + length: 8 + msg_type: '0xb9' + payload: dteDoNJulmc= + preamble: '0x55' + sender: '0xce39' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml new file mode 100644 index 0000000000..3fe1c6da40 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwResults.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCwResults +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgCwResults + msg_type: '0xc0' + raw_json: '{"crc":18660,"length":0,"msg_type":192,"payload":"","preamble":85,"sender":63075}' + raw_packet: VcAAY/YA5Eg= + sbp: + crc: '0x48e4' + length: 0 + msg_type: '0xc0' + payload: "" + preamble: '0x55' + sender: '0xf663' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml new file mode 100644 index 0000000000..6eec1a00f7 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgCwStart.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgCwStart +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgCwStart + msg_type: '0xc1' + raw_json: '{"crc":35541,"length":0,"msg_type":193,"payload":"","preamble":85,"sender":45854}' + raw_packet: VcEAHrMA1Yo= + sbp: + crc: '0x8ad5' + length: 0 + msg_type: '0xc1' + payload: "" + preamble: '0x55' + sender: '0xb31e' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml new file mode 100644 index 0000000000..34ef052d77 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgFrontEndGain.yaml @@ -0,0 +1,37 @@ +description: Unit tests for swiftnav.sbp.piksi MsgFrontEndGain +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + if_gain: + - -10 + - -23 + - -40 + - 80 + - -69 + - -43 + - 85 + - 2 + rf_gain: + - 41 + - -123 + - -122 + - 10 + - 105 + - 20 + - 38 + - 38 + module: sbp.piksi + name: MsgFrontEndGain + msg_type: '0xbf' + raw_json: '{"crc":34795,"length":16,"msg_type":191,"payload":"KYWGCmkUJib26dhQu9VVAg==","preamble":85,"sender":62895,"rf_gain":[41,-123,-122,10,105,20,38,38],"if_gain":[-10,-23,-40,80,-69,-43,85,2]}' + raw_packet: Vb8Ar/UQKYWGCmkUJib26dhQu9VVAuuH + sbp: + crc: '0x87eb' + length: 16 + msg_type: '0xbf' + payload: KYWGCmkUJib26dhQu9VVAg== + preamble: '0x55' + sender: '0xf5af' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml new file mode 100644 index 0000000000..068480ae45 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgInitBaseDep.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgInitBaseDep +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgInitBaseDep + msg_type: '0x23' + raw_json: '{"crc":3398,"length":0,"msg_type":35,"payload":"","preamble":85,"sender":10680}' + raw_packet: VSMAuCkARg0= + sbp: + crc: '0x0d46' + length: 0 + msg_type: '0x23' + payload: "" + preamble: '0x55' + sender: '0x29b8' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml new file mode 100644 index 0000000000..69b174c68c --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatellite.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.piksi MsgMaskSatellite +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + mask: 183 + sid: + code: 57 + sat: 87 + module: sbp.piksi + name: MsgMaskSatellite + msg_type: '0x2b' + raw_json: '{"crc":37651,"length":3,"msg_type":43,"payload":"t1c5","preamble":85,"sender":38829,"mask":183,"sid":{"sat":87,"code":57}}' + raw_packet: VSsArZcDt1c5E5M= + sbp: + crc: '0x9313' + length: 3 + msg_type: '0x2b' + payload: t1c5 + preamble: '0x55' + sender: '0x97ad' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml new file mode 100644 index 0000000000..cf286a78db --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgMaskSatelliteDep.yaml @@ -0,0 +1,24 @@ +description: Unit tests for swiftnav.sbp.piksi MsgMaskSatelliteDep +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + mask: 33 + sid: + code: 95 + reserved: 4 + sat: 39170 + module: sbp.piksi + name: MsgMaskSatelliteDep + msg_type: '0x1b' + raw_json: '{"crc":48157,"length":5,"msg_type":27,"payload":"IQKZXwQ=","preamble":85,"sender":34491,"mask":33,"sid":{"sat":39170,"code":95,"reserved":4}}' + raw_packet: VRsAu4YFIQKZXwQdvA== + sbp: + crc: '0xbc1d' + length: 5 + msg_type: '0x1b' + payload: IQKZXwQ= + preamble: '0x55' + sender: '0x86bb' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkBandwidthUsage.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkBandwidthUsage.yaml index 737599c2f2..9969a1eb2b 100644 --- a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkBandwidthUsage.yaml +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkBandwidthUsage.yaml @@ -31,7 +31,10 @@ tests: total_bytes: 0 tx_bytes: 0 c_decoded_fields: - n_interfaces: 5 + n_interfaces: + handle_as: vararray-len + relates_to: interfaces + value: 5 module: sbp.piksi name: MsgNetworkBandwidthUsage msg_type: '0xBD' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml new file mode 100644 index 0000000000..3cc5c8eb50 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgNetworkStateReq +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgNetworkStateReq + msg_type: '0xba' + raw_json: '{"crc":18836,"length":0,"msg_type":186,"payload":"","preamble":85,"sender":15955}' + raw_packet: VboAUz4AlEk= + sbp: + crc: '0x4994' + length: 0 + msg_type: '0xba' + payload: "" + preamble: '0x55' + sender: '0x3e53' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml new file mode 100644 index 0000000000..a74681bbde --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgNetworkStateResp.yaml @@ -0,0 +1,47 @@ +description: Unit tests for swiftnav.sbp.piksi MsgNetworkStateResp +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + flags: 2471552451 + interface_name: "if0\0\0\0\0\0\0\0\0\0\0\0\0\0" + ipv4_address: + - 143 + - 241 + - 84 + - 180 + ipv4_mask_size: 152 + ipv6_address: + - 194 + - 137 + - 32 + - 44 + - 114 + - 147 + - 68 + - 222 + - 92 + - 192 + - 78 + - 235 + - 63 + - 208 + - 114 + - 53 + ipv6_mask_size: 183 + rx_bytes: 451408920 + tx_bytes: 59251049 + module: sbp.piksi + name: MsgNetworkStateResp + msg_type: '0xbb' + raw_json: '{"crc":49526,"length":50,"msg_type":187,"payload":"j/FUtJjCiSAscpNE3lzATus/0HI1txj05xppGYgDaWYwAAAAAAAAAAAAAAAAAMPlUJM=","preamble":85,"sender":3880,"ipv4_address":[143,241,84,180],"ipv4_mask_size":152,"ipv6_address":[194,137,32,44,114,147,68,222,92,192,78,235,63,208,114,53],"ipv6_mask_size":183,"rx_bytes":451408920,"tx_bytes":59251049,"interface_name":"if0\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000","flags":2471552451}' + raw_packet: VbsAKA8yj/FUtJjCiSAscpNE3lzATus/0HI1txj05xppGYgDaWYwAAAAAAAAAAAAAAAAAMPlUJN2wQ== + sbp: + crc: '0xc176' + length: 50 + msg_type: '0xbb' + payload: j/FUtJjCiSAscpNE3lzATus/0HI1txj05xppGYgDaWYwAAAAAAAAAAAAAAAAAMPlUJM= + preamble: '0x55' + sender: '0x0f28' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml new file mode 100644 index 0000000000..5918e41d25 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgReset.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgReset +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + flags: 334428248 + module: sbp.piksi + name: MsgReset + msg_type: '0xb6' + raw_json: '{"crc":53066,"length":4,"msg_type":182,"payload":"WPjuEw==","preamble":85,"sender":53823,"flags":334428248}' + raw_packet: VbYAP9IEWPjuE0rP + sbp: + crc: '0xcf4a' + length: 4 + msg_type: '0xb6' + payload: WPjuEw== + preamble: '0x55' + sender: '0xd23f' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml new file mode 100644 index 0000000000..8b0c54de83 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetDep.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgResetDep +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgResetDep + msg_type: '0xb2' + raw_json: '{"crc":44010,"length":0,"msg_type":178,"payload":"","preamble":85,"sender":2880}' + raw_packet: VbIAQAsA6qs= + sbp: + crc: '0xabea' + length: 0 + msg_type: '0xb2' + payload: "" + preamble: '0x55' + sender: '0x0b40' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml new file mode 100644 index 0000000000..4015c16c1a --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgResetFilters.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgResetFilters +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + filter: 100 + module: sbp.piksi + name: MsgResetFilters + msg_type: '0x22' + raw_json: '{"crc":11650,"length":1,"msg_type":34,"payload":"ZA==","preamble":85,"sender":51281,"filter":100}' + raw_packet: VSIAUcgBZIIt + sbp: + crc: '0x2d82' + length: 1 + msg_type: '0x22' + payload: ZA== + preamble: '0x55' + sender: '0xc851' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml new file mode 100644 index 0000000000..917a4898c1 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSetTime.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.piksi MsgSetTime +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + fields: + {} + module: sbp.piksi + name: MsgSetTime + msg_type: '0x68' + raw_json: '{"crc":16855,"length":0,"msg_type":104,"payload":"","preamble":85,"sender":43541}' + raw_packet: VWgAFaoA10E= + sbp: + crc: '0x41d7' + length: 0 + msg_type: '0x68' + payload: "" + preamble: '0x55' + sender: '0xaa15' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml new file mode 100644 index 0000000000..be8831fb3e --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecan.yaml @@ -0,0 +1,261 @@ +description: Unit tests for swiftnav.sbp.piksi MsgSpecan +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + c_decoded_fields: + n_amplitude_value: + handle_as: vararray-len + relates_to: amplitude_value + value: 227 + fields: + amplitude_ref: 3780.199951171875 + amplitude_unit: 1329.199951171875 + amplitude_value: + - 100 + - 179 + - 185 + - 17 + - 175 + - 49 + - 193 + - 228 + - 228 + - 47 + - 33 + - 24 + - 141 + - 177 + - 18 + - 99 + - 246 + - 121 + - 61 + - 40 + - 91 + - 145 + - 223 + - 167 + - 174 + - 9 + - 116 + - 11 + - 247 + - 84 + - 49 + - 153 + - 205 + - 2 + - 230 + - 194 + - 218 + - 241 + - 101 + - 107 + - 45 + - 137 + - 93 + - 114 + - 230 + - 43 + - 224 + - 23 + - 74 + - 209 + - 199 + - 211 + - 130 + - 89 + - 220 + - 163 + - 68 + - 20 + - 253 + - 7 + - 206 + - 50 + - 129 + - 116 + - 194 + - 23 + - 31 + - 226 + - 217 + - 157 + - 205 + - 221 + - 5 + - 224 + - 92 + - 82 + - 109 + - 223 + - 195 + - 233 + - 165 + - 1 + - 82 + - 141 + - 157 + - 177 + - 169 + - 244 + - 131 + - 96 + - 109 + - 111 + - 253 + - 149 + - 28 + - 225 + - 225 + - 72 + - 158 + - 158 + - 210 + - 196 + - 206 + - 70 + - 63 + - 225 + - 184 + - 150 + - 174 + - 240 + - 45 + - 146 + - 59 + - 82 + - 194 + - 4 + - 179 + - 148 + - 66 + - 254 + - 115 + - 77 + - 30 + - 46 + - 4 + - 204 + - 37 + - 200 + - 121 + - 18 + - 17 + - 171 + - 102 + - 163 + - 175 + - 50 + - 66 + - 101 + - 69 + - 13 + - 223 + - 172 + - 160 + - 233 + - 220 + - 101 + - 237 + - 156 + - 62 + - 117 + - 47 + - 143 + - 94 + - 135 + - 22 + - 155 + - 113 + - 110 + - 15 + - 243 + - 141 + - 227 + - 46 + - 143 + - 227 + - 209 + - 249 + - 2 + - 153 + - 168 + - 131 + - 249 + - 160 + - 88 + - 38 + - 117 + - 129 + - 57 + - 40 + - 109 + - 209 + - 177 + - 38 + - 47 + - 12 + - 15 + - 16 + - 9 + - 175 + - 69 + - 70 + - 182 + - 239 + - 117 + - 135 + - 6 + - 71 + - 99 + - 230 + - 115 + - 2 + - 71 + - 165 + - 228 + - 123 + - 210 + - 168 + - 90 + - 124 + - 20 + - 7 + - 220 + - 144 + - 168 + - 69 + - 22 + - 72 + - 162 + - 69 + - 111 + - 91 + - 251 + - 72 + - 220 + - 28 + - 119 + - 150 + channel_tag: 35146 + freq_ref: 7737.2001953125 + freq_step: 8226.2001953125 + t: + ns_residual: -1479025396 + tow: 1227027783 + wn: 5075 + module: sbp.piksi + name: MsgSpecan + msg_type: '0x51' + raw_json: '{"preamble":85,"msg_type":81,"sender":54300,"length":255,"payload":"SolH9SJJDN3Xp9MTmsnxRc2IAEYzQ2xFZiamRGSzuRGvMcHk5C8hGI2xEmP2eT0oW5Hfp64JdAv3VDGZzQLmwtrxZWstiV1y5ivgF0rRx9OCWdyjRBT9B84ygXTCFx/i2Z3N3QXgXFJt38PppQFSjZ2xqfSDYG1v/ZUc4eFInp7SxM5GP+G4lq7wLZI7UsIEs5RC/nNNHi4EzCXIeRIRq2ajrzJCZUUN36yg6dxl7Zw+dS+PXocWm3FuD/ON4y6P49H5Apmog/mgWCZ1gTkobdGxJi8MDxAJr0VGtu91hwZHY+ZzAkel5HvSqFp8FAfckKhFFkiiRW9b+0jcHHeW","crc":607,"channel_tag":35146,"t":{"tow":1227027783,"ns_residual":-1479025396,"wn":5075},"freq_ref":7737.2001953125,"freq_step":8226.2001953125,"amplitude_ref":3780.199951171875,"amplitude_unit":1329.199951171875,"amplitude_value":[100,179,185,17,175,49,193,228,228,47,33,24,141,177,18,99,246,121,61,40,91,145,223,167,174,9,116,11,247,84,49,153,205,2,230,194,218,241,101,107,45,137,93,114,230,43,224,23,74,209,199,211,130,89,220,163,68,20,253,7,206,50,129,116,194,23,31,226,217,157,205,221,5,224,92,82,109,223,195,233,165,1,82,141,157,177,169,244,131,96,109,111,253,149,28,225,225,72,158,158,210,196,206,70,63,225,184,150,174,240,45,146,59,82,194,4,179,148,66,254,115,77,30,46,4,204,37,200,121,18,17,171,102,163,175,50,66,101,69,13,223,172,160,233,220,101,237,156,62,117,47,143,94,135,22,155,113,110,15,243,141,227,46,143,227,209,249,2,153,168,131,249,160,88,38,117,129,57,40,109,209,177,38,47,12,15,16,9,175,69,70,182,239,117,135,6,71,99,230,115,2,71,165,228,123,210,168,90,124,20,7,220,144,168,69,22,72,162,69,111,91,251,72,220,28,119,150]}' + raw_packet: VVEAHNT/SolH9SJJDN3Xp9MTmsnxRc2IAEYzQ2xFZiamRGSzuRGvMcHk5C8hGI2xEmP2eT0oW5Hfp64JdAv3VDGZzQLmwtrxZWstiV1y5ivgF0rRx9OCWdyjRBT9B84ygXTCFx/i2Z3N3QXgXFJt38PppQFSjZ2xqfSDYG1v/ZUc4eFInp7SxM5GP+G4lq7wLZI7UsIEs5RC/nNNHi4EzCXIeRIRq2ajrzJCZUUN36yg6dxl7Zw+dS+PXocWm3FuD/ON4y6P49H5Apmog/mgWCZ1gTkobdGxJi8MDxAJr0VGtu91hwZHY+ZzAkel5HvSqFp8FAfckKhFFkiiRW9b+0jcHHeWXwI= + sbp: + crc: '0x025f' + length: 255 + msg_type: '0x51' + payload: SolH9SJJDN3Xp9MTmsnxRc2IAEYzQ2xFZiamRGSzuRGvMcHk5C8hGI2xEmP2eT0oW5Hfp64JdAv3VDGZzQLmwtrxZWstiV1y5ivgF0rRx9OCWdyjRBT9B84ygXTCFx/i2Z3N3QXgXFJt38PppQFSjZ2xqfSDYG1v/ZUc4eFInp7SxM5GP+G4lq7wLZI7UsIEs5RC/nNNHi4EzCXIeRIRq2ajrzJCZUUN36yg6dxl7Zw+dS+PXocWm3FuD/ON4y6P49H5Apmog/mgWCZ1gTkobdGxJi8MDxAJr0VGtu91hwZHY+ZzAkel5HvSqFp8FAfckKhFFkiiRW9b+0jcHHeW + preamble: '0x55' + sender: '0xd41c' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml new file mode 100644 index 0000000000..e014acf742 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgSpecanDep.yaml @@ -0,0 +1,264 @@ +description: Unit tests for swiftnav.sbp.piksi MsgSpecanDep +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +tests: + +- msg: + c_decoded_fields: + n_amplitude_value: + handle_as: vararray-len + relates_to: amplitude_value + value: 231 + fields: + amplitude_ref: 9349.2001953125 + amplitude_unit: 3485.199951171875 + amplitude_value: + - 240 + - 14 + - 179 + - 186 + - 227 + - 244 + - 173 + - 240 + - 182 + - 71 + - 166 + - 117 + - 196 + - 13 + - 44 + - 27 + - 33 + - 28 + - 67 + - 254 + - 3 + - 249 + - 92 + - 44 + - 122 + - 169 + - 77 + - 186 + - 68 + - 135 + - 63 + - 168 + - 162 + - 89 + - 36 + - 186 + - 99 + - 63 + - 105 + - 116 + - 216 + - 44 + - 67 + - 212 + - 156 + - 75 + - 81 + - 53 + - 250 + - 225 + - 23 + - 205 + - 26 + - 34 + - 119 + - 50 + - 101 + - 64 + - 7 + - 231 + - 124 + - 183 + - 203 + - 102 + - 234 + - 84 + - 83 + - 208 + - 23 + - 68 + - 54 + - 179 + - 98 + - 96 + - 116 + - 244 + - 246 + - 94 + - 104 + - 94 + - 13 + - 56 + - 210 + - 18 + - 191 + - 22 + - 133 + - 81 + - 153 + - 159 + - 161 + - 219 + - 59 + - 21 + - 164 + - 121 + - 145 + - 203 + - 171 + - 132 + - 57 + - 180 + - 102 + - 101 + - 11 + - 229 + - 175 + - 145 + - 73 + - 72 + - 124 + - 4 + - 184 + - 228 + - 61 + - 234 + - 218 + - 62 + - 226 + - 217 + - 193 + - 7 + - 109 + - 44 + - 83 + - 201 + - 20 + - 101 + - 9 + - 140 + - 186 + - 162 + - 81 + - 91 + - 30 + - 231 + - 161 + - 81 + - 216 + - 114 + - 60 + - 231 + - 163 + - 163 + - 49 + - 237 + - 244 + - 185 + - 240 + - 89 + - 143 + - 174 + - 165 + - 211 + - 241 + - 13 + - 16 + - 61 + - 141 + - 101 + - 89 + - 37 + - 117 + - 189 + - 86 + - 118 + - 176 + - 228 + - 12 + - 14 + - 119 + - 135 + - 129 + - 243 + - 50 + - 29 + - 207 + - 198 + - 117 + - 100 + - 225 + - 6 + - 139 + - 110 + - 39 + - 210 + - 68 + - 199 + - 43 + - 132 + - 64 + - 17 + - 51 + - 173 + - 181 + - 12 + - 140 + - 16 + - 247 + - 84 + - 183 + - 105 + - 39 + - 157 + - 77 + - 30 + - 205 + - 194 + - 59 + - 64 + - 241 + - 183 + - 238 + - 105 + - 181 + - 170 + - 45 + - 8 + - 166 + - 164 + - 238 + - 83 + - 148 + - 173 + - 108 + - 228 + - 67 + - 89 + - 189 + - 67 + - 26 + channel_tag: 5878 + freq_ref: 6348.2001953125 + freq_step: 4608.2001953125 + t: + tow: 992295133 + wn: 6957 + module: sbp.piksi + name: MsgSpecanDep + msg_type: '0x50' + raw_json: '{"preamble":85,"msg_type":80,"sender":55664,"length":255,"payload":"9hbdOCU7LRuaYcZFmgGQRc0UEkYz01lF8A6zuuP0rfC2R6Z1xA0sGyEcQ/4D+VwseqlNukSHP6iiWSS6Yz9pdNgsQ9ScS1E1+uEXzRoidzJlQAfnfLfLZupUU9AXRDazYmB09PZeaF4NONISvxaFUZmfods7FaR5kcurhDm0ZmUL5a+RSUh8BLjkPeraPuLZwQdtLFPJFGUJjLqiUVse56FR2HI856OjMe30ufBZj66l0/ENED2NZVkldb1WdrDkDA53h4HzMh3PxnVk4QaLbifSRMcrhEARM621DIwQ91S3aSedTR7NwjtA8bfuabWqLQimpO5TlK1s5ENZvUMa","crc":55335,"channel_tag":5878,"t":{"tow":992295133,"wn":6957},"freq_ref":6348.2001953125,"freq_step":4608.2001953125,"amplitude_ref":9349.2001953125,"amplitude_unit":3485.199951171875,"amplitude_value":[240,14,179,186,227,244,173,240,182,71,166,117,196,13,44,27,33,28,67,254,3,249,92,44,122,169,77,186,68,135,63,168,162,89,36,186,99,63,105,116,216,44,67,212,156,75,81,53,250,225,23,205,26,34,119,50,101,64,7,231,124,183,203,102,234,84,83,208,23,68,54,179,98,96,116,244,246,94,104,94,13,56,210,18,191,22,133,81,153,159,161,219,59,21,164,121,145,203,171,132,57,180,102,101,11,229,175,145,73,72,124,4,184,228,61,234,218,62,226,217,193,7,109,44,83,201,20,101,9,140,186,162,81,91,30,231,161,81,216,114,60,231,163,163,49,237,244,185,240,89,143,174,165,211,241,13,16,61,141,101,89,37,117,189,86,118,176,228,12,14,119,135,129,243,50,29,207,198,117,100,225,6,139,110,39,210,68,199,43,132,64,17,51,173,181,12,140,16,247,84,183,105,39,157,77,30,205,194,59,64,241,183,238,105,181,170,45,8,166,164,238,83,148,173,108,228,67,89,189,67,26]}' + raw_packet: VVAAcNn/9hbdOCU7LRuaYcZFmgGQRc0UEkYz01lF8A6zuuP0rfC2R6Z1xA0sGyEcQ/4D+VwseqlNukSHP6iiWSS6Yz9pdNgsQ9ScS1E1+uEXzRoidzJlQAfnfLfLZupUU9AXRDazYmB09PZeaF4NONISvxaFUZmfods7FaR5kcurhDm0ZmUL5a+RSUh8BLjkPeraPuLZwQdtLFPJFGUJjLqiUVse56FR2HI856OjMe30ufBZj66l0/ENED2NZVkldb1WdrDkDA53h4HzMh3PxnVk4QaLbifSRMcrhEARM621DIwQ91S3aSedTR7NwjtA8bfuabWqLQimpO5TlK1s5ENZvUMaJ9g= + sbp: + crc: '0xd827' + length: 255 + msg_type: '0x50' + payload: 9hbdOCU7LRuaYcZFmgGQRc0UEkYz01lF8A6zuuP0rfC2R6Z1xA0sGyEcQ/4D+VwseqlNukSHP6iiWSS6Yz9pdNgsQ9ScS1E1+uEXzRoidzJlQAfnfLfLZupUU9AXRDazYmB09PZeaF4NONISvxaFUZmfods7FaR5kcurhDm0ZmUL5a+RSUh8BLjkPeraPuLZwQdtLFPJFGUJjLqiUVse56FR2HI856OjMe30ufBZj66l0/ENED2NZVkldb1WdrDkDA53h4HzMh3PxnVk4QaLbifSRMcrhEARM621DIwQ91S3aSedTR7NwjtA8bfuabWqLQimpO5TlK1s5ENZvUMa + preamble: '0x55' + sender: '0xd970' diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgUartState.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgUartState.yaml index 518965684a..b807c940de 100644 --- a/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgUartState.yaml +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_MsgUartState.yaml @@ -1,9 +1,54 @@ ---- -description: Unit tests for swiftnav.sbp.piksi MsgUartState v0.53. -generated_on: 2015-01-15 16:50:00.0 +description: Unit tests for swiftnav.sbp.piksi MsgUartState +generated_on: 2023-11-15 # manually generated package: sbp.piksi tests: +- msg: + fields: + latency: + avg: 319865629 + current: 364253831 + lmax: -611749622 + lmin: 289902239 + obs_period: + avg: -1002717658 + current: -2080697488 + pmax: -1628133123 + pmin: 1869323177 + uart_a: + crc_error_count: 25177 + io_error_count: 47183 + rx_buffer_level: 244 + rx_throughput: 1853.199951171875 + tx_buffer_level: 138 + tx_throughput: 7765.2001953125 + uart_b: + crc_error_count: 4297 + io_error_count: 63847 + rx_buffer_level: 161 + rx_throughput: 6760.2001953125 + tx_buffer_level: 143 + tx_throughput: 6441.2001953125 + uart_ftdi: + crc_error_count: 38359 + io_error_count: 6653 + rx_buffer_level: 24 + rx_throughput: 2173.199951171875 + tx_buffer_level: 218 + tx_throughput: 5954.2001953125 + module: sbp.piksi + name: MsgUartState + msg_type: '0x1d' + raw_json: '{"preamble":85,"msg_type":29,"sender":57544,"length":74,"payload":"mqnyRWam50RZYk+4ivSaSclFmkHTRckQZ/mPoZoRukUz0wdF15X9GdoYHcMQE5+ORxEKcYnbhxK2FSa+O8Spm2tv/aj0nnAT+4M=","crc":57700,"uart_a":{"tx_throughput":7765.2001953125,"rx_throughput":1853.199951171875,"crc_error_count":25177,"io_error_count":47183,"tx_buffer_level":138,"rx_buffer_level":244},"uart_b":{"tx_throughput":6441.2001953125,"rx_throughput":6760.2001953125,"crc_error_count":4297,"io_error_count":63847,"tx_buffer_level":143,"rx_buffer_level":161},"uart_ftdi":{"tx_throughput":5954.2001953125,"rx_throughput":2173.199951171875,"crc_error_count":38359,"io_error_count":6653,"tx_buffer_level":218,"rx_buffer_level":24},"latency":{"avg":319865629,"lmin":289902239,"lmax":-611749622,"current":364253831},"obs_period":{"avg":-1002717658,"pmin":1869323177,"pmax":-1628133123,"current":-2080697488}}' + raw_packet: VR0AyOBKmqnyRWam50RZYk+4ivSaSclFmkHTRckQZ/mPoZoRukUz0wdF15X9GdoYHcMQE5+ORxEKcYnbhxK2FSa+O8Spm2tv/aj0nnAT+4Nk4Q== + sbp: + crc: '0xe164' + length: 74 + msg_type: '0x1d' + payload: mqnyRWam50RZYk+4ivSaSclFmkHTRckQZ/mPoZoRukUz0wdF15X9GdoYHcMQE5+ORxEKcYnbhxK2FSa+O8Spm2tv/aj0nnAT+4M= + preamble: '0x55' + sender: '0xe0c8' + - msg: fields: latency: diff --git a/spec/tests/yaml/swiftnav/sbp/piksi/test_piksi_structs.yaml b/spec/tests/yaml/swiftnav/sbp/piksi/test_piksi_structs.yaml new file mode 100644 index 0000000000..9f6365f325 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/piksi/test_piksi_structs.yaml @@ -0,0 +1,40 @@ +description: Unit tests for swiftnav.sbp.piksi free structs +generated_on: 2023-11-15 # manually generated +package: sbp.piksi +struct_tests: + + - encoded: zXAZRmaGjUT8D2nRmqw= + fields: + tx_throughput: 9820.200195 + rx_throughput: 1132.199951 + crc_error_count: 4092 + io_error_count: 53609 + tx_buffer_level: 154 + rx_buffer_level: 172 + module: sbp.piksi + name: UartChannel + - encoded: +F+YOsDNdrYua4JBHsgz+w== + fields: + avg: 983064568 + pmin: -1233728064 + pmax: 1099066158 + current: -80492514 + module: sbp.piksi + name: Period + - encoded: JF1Lgq9uwymD5agUb3j8GA== + fields: + avg: -2108990172 + lmin: 700673711 + lmax: 346613123 + current: 419199087 + module: sbp.piksi + name: Latency + - encoded: 3ShKdx0AAAAV3T/qIgAAABjaAqY6oSxXaWYwAAAAAAAAAAAAAAAAAA== + fields: + duration: 126555400413 + total_bytes: 149958941973 + rx_bytes: 2785204760 + tx_bytes: 1462542650 + interface_name: if0 + module: sbp.piksi + name: NetworkUsage diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml new file mode 100644 index 0000000000..a68e497ab6 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexReq.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsReadByIndexReq +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + fields: + index: 8948 + module: sbp.settings + name: MsgSettingsReadByIndexReq + msg_type: '0xa2' + raw_json: '{"crc":6123,"length":2,"msg_type":162,"payload":"9CI=","preamble":85,"sender":31610,"index":8948}' + raw_packet: VaIAensC9CLrFw== + sbp: + crc: '0x17eb' + length: 2 + msg_type: '0xa2' + payload: 9CI= + preamble: '0x55' + sender: '0x7b7a' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexResp.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexResp.yaml index 44d370d614..8666ea41d1 100644 --- a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexResp.yaml +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadByIndexResp.yaml @@ -13,6 +13,7 @@ tests: handle_as: encoded-string fn_prefix: sbp_msg_settings_read_by_index_resp_setting encoded_len: 76 + min_len: 1 sections: - "telemetry_radio" - "configuration_string" @@ -41,6 +42,7 @@ tests: handle_as: encoded-string fn_prefix: sbp_msg_settings_read_by_index_resp_setting encoded_len: 33 + min_len: 1 sections: - "uart_ftdi" - "mode" @@ -70,6 +72,7 @@ tests: handle_as: encoded-string fn_prefix: sbp_msg_settings_read_by_index_resp_setting encoded_len: 33 + min_len: 1 sections: - "uart_ftdi" - "sbp_message_mask" @@ -98,6 +101,7 @@ tests: handle_as: encoded-string fn_prefix: sbp_msg_settings_read_by_index_resp_setting encoded_len: 27 + min_len: 1 sections: - "uart_ftdi" - "baudrate" @@ -126,6 +130,7 @@ tests: handle_as: encoded-string fn_prefix: sbp_msg_settings_read_by_index_resp_setting encoded_len: 34 + min_len: 1 sections: - "uart_uarta" - "mode" diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml new file mode 100644 index 0000000000..1373eec869 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadReq.yaml @@ -0,0 +1,29 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsReadReq +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 26 + min_len: 1 + fn_prefix: sbp_msg_settings_read_req_setting + sections: + - "section-name" + - "setting-name" + fields: + setting: "section-name\0setting-name\0" + module: sbp.settings + name: MsgSettingsReadReq + msg_type: '0xa4' + raw_json: '{"crc":58549,"length":26,"msg_type":164,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQA=","preamble":85,"sender":54936,"setting":"section-name\u0000setting-name\u0000"}' + raw_packet: VaQAmNYac2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQC15A== + sbp: + crc: '0xe4b5' + length: 26 + msg_type: '0xa4' + payload: c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQA= + preamble: '0x55' + sender: '0xd698' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml new file mode 100644 index 0000000000..8b2b6159da --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsReadResp.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsReadResp +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 66 + min_len: 1 + fn_prefix: sbp_msg_settings_read_resp_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + - "enum;value1,value2,value3" + fields: + setting: "section-name\0setting-name\0setting-value\0enum;value1,value2,value3\0" + module: sbp.settings + name: MsgSettingsReadResp + msg_type: '0xa5' + raw_json: '{"crc":51147,"length":66,"msg_type":165,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA","preamble":85,"sender":61576,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}' + raw_packet: VaUAiPBCc2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMAy8c= + sbp: + crc: '0xc7cb' + length: 66 + msg_type: '0xa5' + payload: c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA + preamble: '0x55' + sender: '0xf088' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml new file mode 100644 index 0000000000..ae8671d602 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegister.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsRegister +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 66 + min_len: 1 + fn_prefix: sbp_msg_settings_register_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + - "enum;value1,value2,value3" + fields: + setting: "section-name\0setting-name\0setting-value\0enum;value1,value2,value3\0" + module: sbp.settings + name: MsgSettingsRegister + msg_type: '0xae' + raw_json: '{"crc":60302,"length":66,"msg_type":174,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA","preamble":85,"sender":1620,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}' + raw_packet: Va4AVAZCc2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMAjus= + sbp: + crc: '0xeb8e' + length: 66 + msg_type: '0xae' + payload: c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAGVudW07dmFsdWUxLHZhbHVlMix2YWx1ZTMA + preamble: '0x55' + sender: '0x0654' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml new file mode 100644 index 0000000000..495040f4dc --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsRegisterResp.yaml @@ -0,0 +1,32 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsRegisterResp +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 66 + min_len: 1 + fn_prefix: sbp_msg_settings_register_resp_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + - "enum;value1,value2,value3" + fields: + setting: "section-name\0setting-name\0setting-value\0enum;value1,value2,value3\0" + status: 18 + module: sbp.settings + name: MsgSettingsRegisterResp + msg_type: '0x1af' + raw_json: '{"crc":4178,"length":67,"msg_type":431,"payload":"EnNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA==","preamble":85,"sender":54569,"status":18,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}' + raw_packet: Va8BKdVDEnNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAFIQ + sbp: + crc: '0x1052' + length: 67 + msg_type: '0x1af' + payload: EnNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA== + preamble: '0x55' + sender: '0xd529' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml new file mode 100644 index 0000000000..7b834e5c9f --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsSave.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsSave +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + fields: + {} + module: sbp.settings + name: MsgSettingsSave + msg_type: '0xa1' + raw_json: '{"crc":17275,"length":0,"msg_type":161,"payload":"","preamble":85,"sender":57506}' + raw_packet: VaEAouAAe0M= + sbp: + crc: '0x437b' + length: 0 + msg_type: '0xa1' + payload: "" + preamble: '0x55' + sender: '0xe0a2' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml new file mode 100644 index 0000000000..31b5c4062c --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWrite.yaml @@ -0,0 +1,39 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsWrite +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 40 + fn_prefix: sbp_msg_settings_write_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + fields: + setting: "section-name\0setting-name\0setting-value\0" + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 40 + min_len: 1 + fn_prefix: sbp_msg_settings_write_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + module: sbp.settings + name: MsgSettingsWrite + msg_type: '0xa0' + raw_json: '{"crc":2804,"length":40,"msg_type":160,"payload":"c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAA==","preamble":85,"sender":123,"setting":"section-name\u0000setting-name\u0000setting-value\u0000"}' + raw_packet: VaAAewAoc2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAPQK + sbp: + crc: '0xaf4' + length: 40 + msg_type: '0xa0' + payload: c2VjdGlvbi1uYW1lAHNldHRpbmctbmFtZQBzZXR0aW5nLXZhbHVlAA== + preamble: '0x55' + sender: '0x7b' diff --git a/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml new file mode 100644 index 0000000000..c8e7fdbb63 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/settings/test_MsgSettingsWriteResp.yaml @@ -0,0 +1,32 @@ +description: Unit tests for swiftnav.sbp.settings MsgSettingsWriteResp +generated_on: 2023-11-15 # manually generated +package: sbp.settings +tests: + +- msg: + c_decoded_fields: + setting: + handle_as: encoded-string + encoded_len: 66 + min_len: 1 + fn_prefix: sbp_msg_settings_write_resp_setting + sections: + - "section-name" + - "setting-name" + - "setting-value" + - "enum;value1,value2,value3" + fields: + setting: "section-name\0setting-name\0setting-value\0enum;value1,value2,value3\0" + status: 152 + module: sbp.settings + name: MsgSettingsWriteResp + msg_type: '0xaf' + raw_json: '{"crc":54,"length":67,"msg_type":175,"payload":"mHNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA==","preamble":85,"sender":14171,"status":152,"setting":"section-name\u0000setting-name\u0000setting-value\u0000enum;value1,value2,value3\u0000"}' + raw_packet: Va8AWzdDmHNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzADYA + sbp: + crc: '0x0036' + length: 67 + msg_type: '0xaf' + payload: mHNlY3Rpb24tbmFtZQBzZXR0aW5nLW5hbWUAc2V0dGluZy12YWx1ZQBlbnVtO3ZhbHVlMSx2YWx1ZTIsdmFsdWUzAA== + preamble: '0x55' + sender: '0x375b' diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaCertificate.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaCertificate.yaml index f9a9b87507..01d63f8e3c 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaCertificate.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaCertificate.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_certificate_bytes: 247 + n_certificate_bytes: + handle_as: vararray-len + relates_to: certificate_bytes + value: 247 fields: certificate_bytes: - 180 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignature.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignature.yaml index 15949a8921..abc7739a2e 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignature.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignature.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_signed_messages: 3 + n_signed_messages: + handle_as: vararray-len + relates_to: signed_messages + value: 3 fields: certificate_id: - 1 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepA.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepA.yaml index 894d2b44ff..954ba0b534 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepA.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepA.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_signed_messages: 184 + n_signed_messages: + handle_as: vararray-len + relates_to: signed_messages + value: 184 fields: certificate_id: - 1 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepB.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepB.yaml index e4c6dd21cc..cecf6485ae 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepB.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEcdsaSignatureDepB.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_signed_messages: 3 + n_signed_messages: + handle_as: vararray-len + relates_to: signed_messages + value: 3 fields: certificate_id: - 1 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519CertificateDep.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519CertificateDep.yaml index dcae493d38..a1acd2a130 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519CertificateDep.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519CertificateDep.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_certificate_bytes: 85 + n_certificate_bytes: + handle_as: vararray-len + relates_to: certificate_bytes + value: 85 fields: certificate_bytes: - 0 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepA.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepA.yaml index 88fcf574ad..0027e59428 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepA.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepA.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_signed_messages: 25 + n_signed_messages: + handle_as: vararray-len + relates_to: signed_messages + value: 25 fields: fingerprint: - 100 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepB.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepB.yaml index 335c564ec5..27b574d27b 100644 --- a/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepB.yaml +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_MsgEd25519SignatureDepB.yaml @@ -4,7 +4,10 @@ package: sbp.signing tests: - msg: c_decoded_fields: - n_signed_messages: 25 + n_signed_messages: + handle_as: vararray-len + relates_to: signed_messages + value: 25 fields: fingerprint: - 100 diff --git a/spec/tests/yaml/swiftnav/sbp/signing/test_signing_structs.yaml b/spec/tests/yaml/swiftnav/sbp/signing/test_signing_structs.yaml new file mode 100644 index 0000000000..3e3f5dd0f6 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/signing/test_signing_structs.yaml @@ -0,0 +1,94 @@ +description: Unit tests for swiftnav.sbp.signing free structs +generated_on: 2023-11-15 # manually generated +package: sbp.signing +struct_tests: + + - encoded: 5ntAgjoFeYQehBQ= + fields: + year: 31718 + month: 64 + day: 130 + hours: 58 + minutes: 5 + seconds: 121 + ns: 344202884 + module: sbp.signing + name: UtcTime + - encoded: pr35ptP2B1PetnkWQBK+nNQXD94pBdAxfx5S1v0El3r+Ohd1m+m0ds+gVHU5LujORJuvM7pv8CEUaz9yzHNA8ZHYoGDWNbV4hA== + fields: + len: 166 + data: + - 189 + - 249 + - 166 + - 211 + - 246 + - 7 + - 83 + - 222 + - 182 + - 121 + - 22 + - 64 + - 18 + - 190 + - 156 + - 212 + - 23 + - 15 + - 222 + - 41 + - 5 + - 208 + - 49 + - 127 + - 30 + - 82 + - 214 + - 253 + - 4 + - 151 + - 122 + - 254 + - 58 + - 23 + - 117 + - 155 + - 233 + - 180 + - 118 + - 207 + - 160 + - 84 + - 117 + - 57 + - 46 + - 232 + - 206 + - 68 + - 155 + - 175 + - 51 + - 186 + - 111 + - 240 + - 33 + - 20 + - 107 + - 63 + - 114 + - 204 + - 115 + - 64 + - 241 + - 145 + - 216 + - 160 + - 96 + - 214 + - 53 + - 181 + - 120 + - 132 + module: sbp.signing + name: EcdsaSignature diff --git a/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml new file mode 100644 index 0000000000..7af96594b6 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMeta.yaml @@ -0,0 +1,269 @@ +description: Unit tests for swiftnav.sbp.solution_meta MsgSolnMeta +generated_on: 2023-11-15 # manually generated +package: sbp.solution_meta +tests: + +- msg: + c_decoded_fields: + n_sol_in: + handle_as: vararray-len + relates_to: sol_in + value: 119 + fields: + age_corrections: 21256 + age_gnss: 3573765977 + hdop: 41156 + pdop: 11642 + sol_in: + - flags: 109 + sensor_type: 95 + - flags: 131 + sensor_type: 86 + - flags: 70 + sensor_type: 71 + - flags: 73 + sensor_type: 84 + - flags: 26 + sensor_type: 131 + - flags: 247 + sensor_type: 82 + - flags: 97 + sensor_type: 140 + - flags: 110 + sensor_type: 115 + - flags: 253 + sensor_type: 118 + - flags: 122 + sensor_type: 2 + - flags: 148 + sensor_type: 186 + - flags: 148 + sensor_type: 122 + - flags: 231 + sensor_type: 180 + - flags: 46 + sensor_type: 68 + - flags: 102 + sensor_type: 190 + - flags: 48 + sensor_type: 243 + - flags: 15 + sensor_type: 192 + - flags: 89 + sensor_type: 208 + - flags: 10 + sensor_type: 56 + - flags: 2 + sensor_type: 245 + - flags: 201 + sensor_type: 254 + - flags: 32 + sensor_type: 120 + - flags: 2 + sensor_type: 126 + - flags: 161 + sensor_type: 83 + - flags: 123 + sensor_type: 238 + - flags: 230 + sensor_type: 102 + - flags: 190 + sensor_type: 76 + - flags: 182 + sensor_type: 225 + - flags: 228 + sensor_type: 207 + - flags: 218 + sensor_type: 7 + - flags: 89 + sensor_type: 117 + - flags: 191 + sensor_type: 29 + - flags: 248 + sensor_type: 56 + - flags: 255 + sensor_type: 185 + - flags: 18 + sensor_type: 46 + - flags: 142 + sensor_type: 72 + - flags: 113 + sensor_type: 82 + - flags: 4 + sensor_type: 26 + - flags: 254 + sensor_type: 172 + - flags: 136 + sensor_type: 178 + - flags: 115 + sensor_type: 113 + - flags: 193 + sensor_type: 58 + - flags: 227 + sensor_type: 89 + - flags: 246 + sensor_type: 182 + - flags: 77 + sensor_type: 76 + - flags: 245 + sensor_type: 108 + - flags: 31 + sensor_type: 41 + - flags: 124 + sensor_type: 70 + - flags: 145 + sensor_type: 249 + - flags: 78 + sensor_type: 15 + - flags: 38 + sensor_type: 228 + - flags: 129 + sensor_type: 241 + - flags: 176 + sensor_type: 8 + - flags: 72 + sensor_type: 251 + - flags: 80 + sensor_type: 248 + - flags: 244 + sensor_type: 115 + - flags: 145 + sensor_type: 231 + - flags: 190 + sensor_type: 191 + - flags: 168 + sensor_type: 178 + - flags: 233 + sensor_type: 89 + - flags: 176 + sensor_type: 69 + - flags: 140 + sensor_type: 174 + - flags: 141 + sensor_type: 182 + - flags: 82 + sensor_type: 81 + - flags: 79 + sensor_type: 92 + - flags: 223 + sensor_type: 101 + - flags: 64 + sensor_type: 100 + - flags: 215 + sensor_type: 184 + - flags: 37 + sensor_type: 124 + - flags: 227 + sensor_type: 21 + - flags: 102 + sensor_type: 135 + - flags: 36 + sensor_type: 72 + - flags: 56 + sensor_type: 219 + - flags: 90 + sensor_type: 146 + - flags: 104 + sensor_type: 219 + - flags: 102 + sensor_type: 227 + - flags: 12 + sensor_type: 83 + - flags: 122 + sensor_type: 41 + - flags: 94 + sensor_type: 173 + - flags: 174 + sensor_type: 1 + - flags: 130 + sensor_type: 134 + - flags: 237 + sensor_type: 104 + - flags: 249 + sensor_type: 116 + - flags: 230 + sensor_type: 107 + - flags: 123 + sensor_type: 130 + - flags: 162 + sensor_type: 25 + - flags: 223 + sensor_type: 57 + - flags: 174 + sensor_type: 193 + - flags: 193 + sensor_type: 146 + - flags: 44 + sensor_type: 239 + - flags: 197 + sensor_type: 246 + - flags: 80 + sensor_type: 214 + - flags: 100 + sensor_type: 83 + - flags: 72 + sensor_type: 66 + - flags: 137 + sensor_type: 133 + - flags: 82 + sensor_type: 140 + - flags: 2 + sensor_type: 2 + - flags: 9 + sensor_type: 96 + - flags: 158 + sensor_type: 96 + - flags: 97 + sensor_type: 134 + - flags: 129 + sensor_type: 43 + - flags: 25 + sensor_type: 141 + - flags: 200 + sensor_type: 183 + - flags: 57 + sensor_type: 214 + - flags: 103 + sensor_type: 248 + - flags: 65 + sensor_type: 222 + - flags: 15 + sensor_type: 195 + - flags: 21 + sensor_type: 244 + - flags: 46 + sensor_type: 180 + - flags: 130 + sensor_type: 140 + - flags: 17 + sensor_type: 36 + - flags: 209 + sensor_type: 194 + - flags: 254 + sensor_type: 65 + - flags: 103 + sensor_type: 115 + - flags: 129 + sensor_type: 152 + - flags: 235 + sensor_type: 234 + - flags: 234 + sensor_type: 194 + - flags: 201 + sensor_type: 170 + - flags: 154 + sensor_type: 210 + tow: 3628191792 + vdop: 58512 + module: sbp.solution_meta + name: MsgSolnMeta + msg_type: '0xff0e' + raw_json: '{"crc":63382,"length":254,"msg_type":65294,"payload":"MNBB2HotxKCQ5AhTWVcD1V9tVoNHRlRJgxpS94xhc252/QJ6upR6lLTnRC6+ZvMwwA/QWTgK9QL+yXggfgJToe57ZuZMvuG2z+QH2nVZHb84+Ln/LhJIjlJxGgSs/rKIcXM6wVnjtvZMTWz1KR9GfPmRD07kJvGBCLD7SPhQc/Tnkb++sqhZ6UWwroy2jVFSXE9l32RAuNd8JRXjh2ZIJNs4klrbaONmUwwpeq1eAa6GgmjtdPlr5oJ7GaI538GuksHvLPbF1lBTZEJIhYmMUgICYAlgnoZhK4GNGbfI1jn4Z95Bww/0FbQujIIkEcLRQf5zZ5iB6uvC6qrJ0po=","preamble":85,"sender":15360,"tow":3628191792,"pdop":11642,"hdop":41156,"vdop":58512,"age_corrections":21256,"age_gnss":3573765977,"sol_in":[{"sensor_type":95,"flags":109},{"sensor_type":86,"flags":131},{"sensor_type":71,"flags":70},{"sensor_type":84,"flags":73},{"sensor_type":131,"flags":26},{"sensor_type":82,"flags":247},{"sensor_type":140,"flags":97},{"sensor_type":115,"flags":110},{"sensor_type":118,"flags":253},{"sensor_type":2,"flags":122},{"sensor_type":186,"flags":148},{"sensor_type":122,"flags":148},{"sensor_type":180,"flags":231},{"sensor_type":68,"flags":46},{"sensor_type":190,"flags":102},{"sensor_type":243,"flags":48},{"sensor_type":192,"flags":15},{"sensor_type":208,"flags":89},{"sensor_type":56,"flags":10},{"sensor_type":245,"flags":2},{"sensor_type":254,"flags":201},{"sensor_type":120,"flags":32},{"sensor_type":126,"flags":2},{"sensor_type":83,"flags":161},{"sensor_type":238,"flags":123},{"sensor_type":102,"flags":230},{"sensor_type":76,"flags":190},{"sensor_type":225,"flags":182},{"sensor_type":207,"flags":228},{"sensor_type":7,"flags":218},{"sensor_type":117,"flags":89},{"sensor_type":29,"flags":191},{"sensor_type":56,"flags":248},{"sensor_type":185,"flags":255},{"sensor_type":46,"flags":18},{"sensor_type":72,"flags":142},{"sensor_type":82,"flags":113},{"sensor_type":26,"flags":4},{"sensor_type":172,"flags":254},{"sensor_type":178,"flags":136},{"sensor_type":113,"flags":115},{"sensor_type":58,"flags":193},{"sensor_type":89,"flags":227},{"sensor_type":182,"flags":246},{"sensor_type":76,"flags":77},{"sensor_type":108,"flags":245},{"sensor_type":41,"flags":31},{"sensor_type":70,"flags":124},{"sensor_type":249,"flags":145},{"sensor_type":15,"flags":78},{"sensor_type":228,"flags":38},{"sensor_type":241,"flags":129},{"sensor_type":8,"flags":176},{"sensor_type":251,"flags":72},{"sensor_type":248,"flags":80},{"sensor_type":115,"flags":244},{"sensor_type":231,"flags":145},{"sensor_type":191,"flags":190},{"sensor_type":178,"flags":168},{"sensor_type":89,"flags":233},{"sensor_type":69,"flags":176},{"sensor_type":174,"flags":140},{"sensor_type":182,"flags":141},{"sensor_type":81,"flags":82},{"sensor_type":92,"flags":79},{"sensor_type":101,"flags":223},{"sensor_type":100,"flags":64},{"sensor_type":184,"flags":215},{"sensor_type":124,"flags":37},{"sensor_type":21,"flags":227},{"sensor_type":135,"flags":102},{"sensor_type":72,"flags":36},{"sensor_type":219,"flags":56},{"sensor_type":146,"flags":90},{"sensor_type":219,"flags":104},{"sensor_type":227,"flags":102},{"sensor_type":83,"flags":12},{"sensor_type":41,"flags":122},{"sensor_type":173,"flags":94},{"sensor_type":1,"flags":174},{"sensor_type":134,"flags":130},{"sensor_type":104,"flags":237},{"sensor_type":116,"flags":249},{"sensor_type":107,"flags":230},{"sensor_type":130,"flags":123},{"sensor_type":25,"flags":162},{"sensor_type":57,"flags":223},{"sensor_type":193,"flags":174},{"sensor_type":146,"flags":193},{"sensor_type":239,"flags":44},{"sensor_type":246,"flags":197},{"sensor_type":214,"flags":80},{"sensor_type":83,"flags":100},{"sensor_type":66,"flags":72},{"sensor_type":133,"flags":137},{"sensor_type":140,"flags":82},{"sensor_type":2,"flags":2},{"sensor_type":96,"flags":9},{"sensor_type":96,"flags":158},{"sensor_type":134,"flags":97},{"sensor_type":43,"flags":129},{"sensor_type":141,"flags":25},{"sensor_type":183,"flags":200},{"sensor_type":214,"flags":57},{"sensor_type":248,"flags":103},{"sensor_type":222,"flags":65},{"sensor_type":195,"flags":15},{"sensor_type":244,"flags":21},{"sensor_type":180,"flags":46},{"sensor_type":140,"flags":130},{"sensor_type":36,"flags":17},{"sensor_type":194,"flags":209},{"sensor_type":65,"flags":254},{"sensor_type":115,"flags":103},{"sensor_type":152,"flags":129},{"sensor_type":234,"flags":235},{"sensor_type":194,"flags":234},{"sensor_type":170,"flags":201},{"sensor_type":210,"flags":154}]}' + raw_packet: VQ7/ADz+MNBB2HotxKCQ5AhTWVcD1V9tVoNHRlRJgxpS94xhc252/QJ6upR6lLTnRC6+ZvMwwA/QWTgK9QL+yXggfgJToe57ZuZMvuG2z+QH2nVZHb84+Ln/LhJIjlJxGgSs/rKIcXM6wVnjtvZMTWz1KR9GfPmRD07kJvGBCLD7SPhQc/Tnkb++sqhZ6UWwroy2jVFSXE9l32RAuNd8JRXjh2ZIJNs4klrbaONmUwwpeq1eAa6GgmjtdPlr5oJ7GaI538GuksHvLPbF1lBTZEJIhYmMUgICYAlgnoZhK4GNGbfI1jn4Z95Bww/0FbQujIIkEcLRQf5zZ5iB6uvC6qrJ0pqW9w== + sbp: + crc: '0xf796' + length: 254 + msg_type: '0xff0e' + payload: MNBB2HotxKCQ5AhTWVcD1V9tVoNHRlRJgxpS94xhc252/QJ6upR6lLTnRC6+ZvMwwA/QWTgK9QL+yXggfgJToe57ZuZMvuG2z+QH2nVZHb84+Ln/LhJIjlJxGgSs/rKIcXM6wVnjtvZMTWz1KR9GfPmRD07kJvGBCLD7SPhQc/Tnkb++sqhZ6UWwroy2jVFSXE9l32RAuNd8JRXjh2ZIJNs4klrbaONmUwwpeq1eAa6GgmjtdPlr5oJ7GaI538GuksHvLPbF1lBTZEJIhYmMUgICYAlgnoZhK4GNGbfI1jn4Z95Bww/0FbQujIIkEcLRQf5zZ5iB6uvC6qrJ0po= + preamble: '0x55' + sender: '0x3c00' diff --git a/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml new file mode 100644 index 0000000000..85406f78f1 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_MsgSolnMetaDepA.yaml @@ -0,0 +1,269 @@ +description: Unit tests for swiftnav.sbp.solution_meta MsgSolnMetaDepA +generated_on: 2023-11-15 # manually generated +package: sbp.solution_meta +tests: + +- msg: + c_decoded_fields: + n_sol_in: + handle_as: vararray-len + relates_to: sol_in + value: 118 + fields: + age_corrections: 48671 + alignment_status: 115 + hdop: 31133 + last_used_gnss_pos_tow: 610745181 + last_used_gnss_vel_tow: 782016851 + n_sats: 238 + pdop: 57015 + sol_in: + - flags: 67 + sensor_type: 253 + - flags: 200 + sensor_type: 87 + - flags: 250 + sensor_type: 39 + - flags: 242 + sensor_type: 245 + - flags: 72 + sensor_type: 228 + - flags: 222 + sensor_type: 18 + - flags: 88 + sensor_type: 11 + - flags: 218 + sensor_type: 207 + - flags: 13 + sensor_type: 231 + - flags: 224 + sensor_type: 226 + - flags: 196 + sensor_type: 22 + - flags: 242 + sensor_type: 21 + - flags: 89 + sensor_type: 12 + - flags: 219 + sensor_type: 71 + - flags: 85 + sensor_type: 182 + - flags: 204 + sensor_type: 145 + - flags: 40 + sensor_type: 146 + - flags: 51 + sensor_type: 204 + - flags: 153 + sensor_type: 21 + - flags: 44 + sensor_type: 227 + - flags: 28 + sensor_type: 15 + - flags: 39 + sensor_type: 255 + - flags: 216 + sensor_type: 205 + - flags: 190 + sensor_type: 240 + - flags: 219 + sensor_type: 93 + - flags: 42 + sensor_type: 103 + - flags: 182 + sensor_type: 41 + - flags: 222 + sensor_type: 76 + - flags: 23 + sensor_type: 17 + - flags: 31 + sensor_type: 125 + - flags: 229 + sensor_type: 18 + - flags: 47 + sensor_type: 28 + - flags: 25 + sensor_type: 214 + - flags: 84 + sensor_type: 100 + - flags: 72 + sensor_type: 106 + - flags: 10 + sensor_type: 48 + - flags: 232 + sensor_type: 222 + - flags: 73 + sensor_type: 235 + - flags: 163 + sensor_type: 109 + - flags: 152 + sensor_type: 51 + - flags: 235 + sensor_type: 133 + - flags: 70 + sensor_type: 87 + - flags: 108 + sensor_type: 2 + - flags: 101 + sensor_type: 91 + - flags: 55 + sensor_type: 200 + - flags: 156 + sensor_type: 24 + - flags: 73 + sensor_type: 233 + - flags: 66 + sensor_type: 39 + - flags: 140 + sensor_type: 97 + - flags: 227 + sensor_type: 252 + - flags: 237 + sensor_type: 230 + - flags: 241 + sensor_type: 135 + - flags: 205 + sensor_type: 245 + - flags: 0 + sensor_type: 70 + - flags: 188 + sensor_type: 219 + - flags: 136 + sensor_type: 107 + - flags: 58 + sensor_type: 178 + - flags: 29 + sensor_type: 1 + - flags: 213 + sensor_type: 44 + - flags: 147 + sensor_type: 225 + - flags: 96 + sensor_type: 190 + - flags: 108 + sensor_type: 192 + - flags: 15 + sensor_type: 228 + - flags: 18 + sensor_type: 203 + - flags: 222 + sensor_type: 3 + - flags: 68 + sensor_type: 180 + - flags: 229 + sensor_type: 101 + - flags: 203 + sensor_type: 223 + - flags: 164 + sensor_type: 243 + - flags: 165 + sensor_type: 92 + - flags: 159 + sensor_type: 220 + - flags: 121 + sensor_type: 174 + - flags: 167 + sensor_type: 112 + - flags: 40 + sensor_type: 240 + - flags: 3 + sensor_type: 59 + - flags: 52 + sensor_type: 230 + - flags: 148 + sensor_type: 149 + - flags: 142 + sensor_type: 218 + - flags: 109 + sensor_type: 212 + - flags: 71 + sensor_type: 176 + - flags: 172 + sensor_type: 179 + - flags: 1 + sensor_type: 77 + - flags: 70 + sensor_type: 193 + - flags: 149 + sensor_type: 147 + - flags: 144 + sensor_type: 23 + - flags: 239 + sensor_type: 148 + - flags: 186 + sensor_type: 195 + - flags: 30 + sensor_type: 86 + - flags: 143 + sensor_type: 34 + - flags: 207 + sensor_type: 156 + - flags: 55 + sensor_type: 63 + - flags: 255 + sensor_type: 117 + - flags: 222 + sensor_type: 222 + - flags: 145 + sensor_type: 219 + - flags: 191 + sensor_type: 224 + - flags: 109 + sensor_type: 210 + - flags: 153 + sensor_type: 86 + - flags: 32 + sensor_type: 21 + - flags: 10 + sensor_type: 226 + - flags: 63 + sensor_type: 60 + - flags: 236 + sensor_type: 106 + - flags: 96 + sensor_type: 93 + - flags: 163 + sensor_type: 30 + - flags: 238 + sensor_type: 106 + - flags: 133 + sensor_type: 147 + - flags: 107 + sensor_type: 132 + - flags: 214 + sensor_type: 152 + - flags: 185 + sensor_type: 221 + - flags: 21 + sensor_type: 202 + - flags: 51 + sensor_type: 252 + - flags: 59 + sensor_type: 130 + - flags: 202 + sensor_type: 166 + - flags: 170 + sensor_type: 127 + - flags: 193 + sensor_type: 58 + - flags: 125 + sensor_type: 215 + - flags: 58 + sensor_type: 22 + - flags: 47 + sensor_type: 135 + - flags: 142 + sensor_type: 88 + vdop: 41989 + module: sbp.solution_meta + name: MsgSolnMetaDepA + msg_type: '0xff0f' + raw_json: '{"crc":54093,"length":254,"msg_type":65295,"payload":"t96deQWk7h++c107ZyRToZwu/UNXyCf69fLkSBLeC1jP2ucN4uAWxBXyDFlH27ZVkcySKMwzFZnjLA8c/yfN2PC+XdtnKim2TN4RF30fEuUcL9YZZFRqSDAK3ujrSW2jM5iF61dGAmxbZcg3GJzpSSdCYYz84+bth/H1zUYA27xriLI6AR0s1eGTvmDAbOQPyxID3rREZeXfy/OkXKXcn655cKfwKDsD5jSVlNqO1G2wR7OsTQHBRpOVF5CU78O6Vh4ij5zPPzd1/97e25Hgv9JtVpkVIOIKPD9q7F1gHqNq7pOFhGuY1t25yhX8M4I7psp/qjrB130WOocvWI4=","preamble":85,"sender":61780,"pdop":57015,"hdop":31133,"vdop":41989,"n_sats":238,"age_corrections":48671,"alignment_status":115,"last_used_gnss_pos_tow":610745181,"last_used_gnss_vel_tow":782016851,"sol_in":[{"sensor_type":253,"flags":67},{"sensor_type":87,"flags":200},{"sensor_type":39,"flags":250},{"sensor_type":245,"flags":242},{"sensor_type":228,"flags":72},{"sensor_type":18,"flags":222},{"sensor_type":11,"flags":88},{"sensor_type":207,"flags":218},{"sensor_type":231,"flags":13},{"sensor_type":226,"flags":224},{"sensor_type":22,"flags":196},{"sensor_type":21,"flags":242},{"sensor_type":12,"flags":89},{"sensor_type":71,"flags":219},{"sensor_type":182,"flags":85},{"sensor_type":145,"flags":204},{"sensor_type":146,"flags":40},{"sensor_type":204,"flags":51},{"sensor_type":21,"flags":153},{"sensor_type":227,"flags":44},{"sensor_type":15,"flags":28},{"sensor_type":255,"flags":39},{"sensor_type":205,"flags":216},{"sensor_type":240,"flags":190},{"sensor_type":93,"flags":219},{"sensor_type":103,"flags":42},{"sensor_type":41,"flags":182},{"sensor_type":76,"flags":222},{"sensor_type":17,"flags":23},{"sensor_type":125,"flags":31},{"sensor_type":18,"flags":229},{"sensor_type":28,"flags":47},{"sensor_type":214,"flags":25},{"sensor_type":100,"flags":84},{"sensor_type":106,"flags":72},{"sensor_type":48,"flags":10},{"sensor_type":222,"flags":232},{"sensor_type":235,"flags":73},{"sensor_type":109,"flags":163},{"sensor_type":51,"flags":152},{"sensor_type":133,"flags":235},{"sensor_type":87,"flags":70},{"sensor_type":2,"flags":108},{"sensor_type":91,"flags":101},{"sensor_type":200,"flags":55},{"sensor_type":24,"flags":156},{"sensor_type":233,"flags":73},{"sensor_type":39,"flags":66},{"sensor_type":97,"flags":140},{"sensor_type":252,"flags":227},{"sensor_type":230,"flags":237},{"sensor_type":135,"flags":241},{"sensor_type":245,"flags":205},{"sensor_type":70,"flags":0},{"sensor_type":219,"flags":188},{"sensor_type":107,"flags":136},{"sensor_type":178,"flags":58},{"sensor_type":1,"flags":29},{"sensor_type":44,"flags":213},{"sensor_type":225,"flags":147},{"sensor_type":190,"flags":96},{"sensor_type":192,"flags":108},{"sensor_type":228,"flags":15},{"sensor_type":203,"flags":18},{"sensor_type":3,"flags":222},{"sensor_type":180,"flags":68},{"sensor_type":101,"flags":229},{"sensor_type":223,"flags":203},{"sensor_type":243,"flags":164},{"sensor_type":92,"flags":165},{"sensor_type":220,"flags":159},{"sensor_type":174,"flags":121},{"sensor_type":112,"flags":167},{"sensor_type":240,"flags":40},{"sensor_type":59,"flags":3},{"sensor_type":230,"flags":52},{"sensor_type":149,"flags":148},{"sensor_type":218,"flags":142},{"sensor_type":212,"flags":109},{"sensor_type":176,"flags":71},{"sensor_type":179,"flags":172},{"sensor_type":77,"flags":1},{"sensor_type":193,"flags":70},{"sensor_type":147,"flags":149},{"sensor_type":23,"flags":144},{"sensor_type":148,"flags":239},{"sensor_type":195,"flags":186},{"sensor_type":86,"flags":30},{"sensor_type":34,"flags":143},{"sensor_type":156,"flags":207},{"sensor_type":63,"flags":55},{"sensor_type":117,"flags":255},{"sensor_type":222,"flags":222},{"sensor_type":219,"flags":145},{"sensor_type":224,"flags":191},{"sensor_type":210,"flags":109},{"sensor_type":86,"flags":153},{"sensor_type":21,"flags":32},{"sensor_type":226,"flags":10},{"sensor_type":60,"flags":63},{"sensor_type":106,"flags":236},{"sensor_type":93,"flags":96},{"sensor_type":30,"flags":163},{"sensor_type":106,"flags":238},{"sensor_type":147,"flags":133},{"sensor_type":132,"flags":107},{"sensor_type":152,"flags":214},{"sensor_type":221,"flags":185},{"sensor_type":202,"flags":21},{"sensor_type":252,"flags":51},{"sensor_type":130,"flags":59},{"sensor_type":166,"flags":202},{"sensor_type":127,"flags":170},{"sensor_type":58,"flags":193},{"sensor_type":215,"flags":125},{"sensor_type":22,"flags":58},{"sensor_type":135,"flags":47},{"sensor_type":88,"flags":142}]}' + raw_packet: VQ//VPH+t96deQWk7h++c107ZyRToZwu/UNXyCf69fLkSBLeC1jP2ucN4uAWxBXyDFlH27ZVkcySKMwzFZnjLA8c/yfN2PC+XdtnKim2TN4RF30fEuUcL9YZZFRqSDAK3ujrSW2jM5iF61dGAmxbZcg3GJzpSSdCYYz84+bth/H1zUYA27xriLI6AR0s1eGTvmDAbOQPyxID3rREZeXfy/OkXKXcn655cKfwKDsD5jSVlNqO1G2wR7OsTQHBRpOVF5CU78O6Vh4ij5zPPzd1/97e25Hgv9JtVpkVIOIKPD9q7F1gHqNq7pOFhGuY1t25yhX8M4I7psp/qjrB130WOocvWI5N0w== + sbp: + crc: '0xd34d' + length: 254 + msg_type: '0xff0f' + payload: t96deQWk7h++c107ZyRToZwu/UNXyCf69fLkSBLeC1jP2ucN4uAWxBXyDFlH27ZVkcySKMwzFZnjLA8c/yfN2PC+XdtnKim2TN4RF30fEuUcL9YZZFRqSDAK3ujrSW2jM5iF61dGAmxbZcg3GJzpSSdCYYz84+bth/H1zUYA27xriLI6AR0s1eGTvmDAbOQPyxID3rREZeXfy/OkXKXcn655cKfwKDsD5jSVlNqO1G2wR7OsTQHBRpOVF5CU78O6Vh4ij5zPPzd1/97e25Hgv9JtVpkVIOIKPD9q7F1gHqNq7pOFhGuY1t25yhX8M4I7psp/qjrB130WOocvWI4= + preamble: '0x55' + sender: '0xf154' diff --git a/spec/tests/yaml/swiftnav/sbp/soln_meta/test_soln_meta_structs.yaml b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_soln_meta_structs.yaml new file mode 100644 index 0000000000..98d8512965 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/soln_meta/test_soln_meta_structs.yaml @@ -0,0 +1,26 @@ +description: Unit tests for swiftnav.sbp.soln_meta free structs +generated_on: 2023-11-15 # manually generated +package: sbp.soln_meta +struct_tests: + + - encoded: Zu0= + fields: + sensor_type: 102 + flags: 237 + module: sbp.solution_meta + name: SolutionInputType + - encoded: Ng== + fields: + flags: 54 + module: sbp.solution_meta + name: GnssInputType + - encoded: 1g== + fields: + flags: 214 + module: sbp.solution_meta + name: ImuInputType + - encoded: 5g== + fields: + flags: 230 + module: sbp.solution_meta + name: OdoInputType diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml new file mode 100644 index 0000000000..170b9bdf98 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodeBiases.yaml @@ -0,0 +1,195 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrCodeBiases +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_biases: + handle_as: vararray-len + relates_to: biases + value: 81 + fields: + biases: + - code: 51 + value: -31996 + - code: 240 + value: 21368 + - code: 148 + value: -10799 + - code: 62 + value: -5916 + - code: 71 + value: -17342 + - code: 210 + value: 13952 + - code: 131 + value: -32360 + - code: 111 + value: -3445 + - code: 177 + value: 11409 + - code: 9 + value: -12299 + - code: 241 + value: -26934 + - code: 141 + value: -24782 + - code: 220 + value: 9611 + - code: 187 + value: -16542 + - code: 23 + value: -30592 + - code: 167 + value: 1736 + - code: 211 + value: 5978 + - code: 244 + value: -10358 + - code: 209 + value: 3467 + - code: 101 + value: 1824 + - code: 18 + value: 17949 + - code: 250 + value: 18797 + - code: 202 + value: -28593 + - code: 9 + value: 17810 + - code: 241 + value: 5684 + - code: 99 + value: -13214 + - code: 3 + value: -6485 + - code: 180 + value: 15947 + - code: 145 + value: -32170 + - code: 31 + value: -25826 + - code: 37 + value: 14098 + - code: 210 + value: 32551 + - code: 242 + value: 3394 + - code: 237 + value: -21864 + - code: 212 + value: -2545 + - code: 59 + value: -19362 + - code: 195 + value: 17821 + - code: 100 + value: 4215 + - code: 68 + value: -20557 + - code: 144 + value: 20849 + - code: 82 + value: -26850 + - code: 21 + value: 10605 + - code: 225 + value: 19720 + - code: 164 + value: 157 + - code: 73 + value: 1566 + - code: 78 + value: -28847 + - code: 116 + value: -26640 + - code: 55 + value: -22087 + - code: 254 + value: 10035 + - code: 74 + value: -2129 + - code: 34 + value: 19041 + - code: 97 + value: 12464 + - code: 236 + value: 3245 + - code: 174 + value: -32155 + - code: 30 + value: -15959 + - code: 190 + value: -15156 + - code: 123 + value: 6507 + - code: 225 + value: 2378 + - code: 10 + value: 823 + - code: 131 + value: 25590 + - code: 133 + value: -7390 + - code: 203 + value: 4676 + - code: 97 + value: 23007 + - code: 192 + value: 13046 + - code: 69 + value: 2651 + - code: 151 + value: 30282 + - code: 110 + value: -22492 + - code: 247 + value: 19872 + - code: 179 + value: -19827 + - code: 99 + value: 30911 + - code: 77 + value: 23488 + - code: 224 + value: -7679 + - code: 50 + value: -28073 + - code: 148 + value: 25838 + - code: 179 + value: -7299 + - code: 215 + value: -18328 + - code: 31 + value: 23097 + - code: 79 + value: -25579 + - code: 245 + value: 15441 + - code: 93 + value: 15530 + - code: 200 + value: 3495 + iod_ssr: 132 + sid: + code: 241 + sat: 133 + time: + tow: 387144400 + wn: 16905 + update_interval: 254 + module: sbp.ssr + name: MsgSsrCodeBiases + msg_type: '0x5e1' + raw_json: '{"crc":33917,"length":253,"msg_type":1505,"payload":"0FoTFwlChfH+hDMEg/B4U5TR1T7k6EdCvNKANoOYgW+L8rGRLAn1z/HKlo0yn9yLJbtivxeAiKfIBtNaF/SK19GLDWUgBxIdRvptScpPkAmSRfE0FmNizAOr5rRLPpFWgh8emyUSN9Inf/JCDe2YqtQP9jtetMOdRWR3EESzr5BxUVIelxVtKeEITaSdAEkeBk5Rj3Twlze5qf4zJ0qv9yJhSmGwMOytDK5lgh6pwb7MxHtrGeFKCQo3A4P2Y4Ui48tEEmHfWcD2MkVbCpdKdm4kqPegTbONsmO/eE3AW+AB4jJXkpTuZLN949douB85Wk8VnPVRPF2qPMinDQ==","preamble":85,"sender":22311,"time":{"tow":387144400,"wn":16905},"sid":{"sat":133,"code":241},"update_interval":254,"iod_ssr":132,"biases":[{"code":51,"value":-31996},{"code":240,"value":21368},{"code":148,"value":-10799},{"code":62,"value":-5916},{"code":71,"value":-17342},{"code":210,"value":13952},{"code":131,"value":-32360},{"code":111,"value":-3445},{"code":177,"value":11409},{"code":9,"value":-12299},{"code":241,"value":-26934},{"code":141,"value":-24782},{"code":220,"value":9611},{"code":187,"value":-16542},{"code":23,"value":-30592},{"code":167,"value":1736},{"code":211,"value":5978},{"code":244,"value":-10358},{"code":209,"value":3467},{"code":101,"value":1824},{"code":18,"value":17949},{"code":250,"value":18797},{"code":202,"value":-28593},{"code":9,"value":17810},{"code":241,"value":5684},{"code":99,"value":-13214},{"code":3,"value":-6485},{"code":180,"value":15947},{"code":145,"value":-32170},{"code":31,"value":-25826},{"code":37,"value":14098},{"code":210,"value":32551},{"code":242,"value":3394},{"code":237,"value":-21864},{"code":212,"value":-2545},{"code":59,"value":-19362},{"code":195,"value":17821},{"code":100,"value":4215},{"code":68,"value":-20557},{"code":144,"value":20849},{"code":82,"value":-26850},{"code":21,"value":10605},{"code":225,"value":19720},{"code":164,"value":157},{"code":73,"value":1566},{"code":78,"value":-28847},{"code":116,"value":-26640},{"code":55,"value":-22087},{"code":254,"value":10035},{"code":74,"value":-2129},{"code":34,"value":19041},{"code":97,"value":12464},{"code":236,"value":3245},{"code":174,"value":-32155},{"code":30,"value":-15959},{"code":190,"value":-15156},{"code":123,"value":6507},{"code":225,"value":2378},{"code":10,"value":823},{"code":131,"value":25590},{"code":133,"value":-7390},{"code":203,"value":4676},{"code":97,"value":23007},{"code":192,"value":13046},{"code":69,"value":2651},{"code":151,"value":30282},{"code":110,"value":-22492},{"code":247,"value":19872},{"code":179,"value":-19827},{"code":99,"value":30911},{"code":77,"value":23488},{"code":224,"value":-7679},{"code":50,"value":-28073},{"code":148,"value":25838},{"code":179,"value":-7299},{"code":215,"value":-18328},{"code":31,"value":23097},{"code":79,"value":-25579},{"code":245,"value":15441},{"code":93,"value":15530},{"code":200,"value":3495}]}' + raw_packet: VeEFJ1f90FoTFwlChfH+hDMEg/B4U5TR1T7k6EdCvNKANoOYgW+L8rGRLAn1z/HKlo0yn9yLJbtivxeAiKfIBtNaF/SK19GLDWUgBxIdRvptScpPkAmSRfE0FmNizAOr5rRLPpFWgh8emyUSN9Inf/JCDe2YqtQP9jtetMOdRWR3EESzr5BxUVIelxVtKeEITaSdAEkeBk5Rj3Twlze5qf4zJ0qv9yJhSmGwMOytDK5lgh6pwb7MxHtrGeFKCQo3A4P2Y4Ui48tEEmHfWcD2MkVbCpdKdm4kqPegTbONsmO/eE3AW+AB4jJXkpTuZLN949douB85Wk8VnPVRPF2qPMinDX2E + sbp: + crc: '0x847d' + length: 253 + msg_type: '0x5e1' + payload: 0FoTFwlChfH+hDMEg/B4U5TR1T7k6EdCvNKANoOYgW+L8rGRLAn1z/HKlo0yn9yLJbtivxeAiKfIBtNaF/SK19GLDWUgBxIdRvptScpPkAmSRfE0FmNizAOr5rRLPpFWgh8emyUSN9Inf/JCDe2YqtQP9jtetMOdRWR3EESzr5BxUVIelxVtKeEITaSdAEkeBk5Rj3Twlze5qf4zJ0qv9yJhSmGwMOytDK5lgh6pwb7MxHtrGeFKCQo3A4P2Y4Ui48tEEmHfWcD2MkVbCpdKdm4kqPegTbONsmO/eE3AW+AB4jJXkpTuZLN949douB85Wk8VnPVRPF2qPMinDQ== + preamble: '0x55' + sender: '0x5727' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodePhaseBiasesBounds.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodePhaseBiasesBounds.yaml index 47cd493044..ab217fef7b 100644 --- a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodePhaseBiasesBounds.yaml +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrCodePhaseBiasesBounds.yaml @@ -4,6 +4,11 @@ package: sbp.ssr tests: - msg: + c_decoded_fields: + n_sats_signals: + handle_as: vararray-len + relates_to: satellites_signals + value: 3 fields: header: time: diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml new file mode 100644 index 0000000000..3883827ab2 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGridDefinitionDepA.yaml @@ -0,0 +1,278 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrGridDefinitionDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_rle_list: + handle_as: vararray-len + relates_to: rle_list + value: 246 + fields: + header: + area_width: 43860 + lat_nw_corner_enc: 34021 + lon_nw_corner_enc: 11919 + num_msgs: 204 + region_size_inverse: 11 + seq_num: 52 + rle_list: + - 92 + - 104 + - 25 + - 204 + - 182 + - 22 + - 98 + - 203 + - 123 + - 211 + - 38 + - 13 + - 253 + - 129 + - 173 + - 171 + - 235 + - 253 + - 26 + - 203 + - 3 + - 120 + - 126 + - 42 + - 44 + - 39 + - 87 + - 69 + - 154 + - 13 + - 28 + - 179 + - 32 + - 47 + - 36 + - 195 + - 39 + - 198 + - 134 + - 235 + - 134 + - 57 + - 120 + - 243 + - 151 + - 35 + - 17 + - 201 + - 211 + - 125 + - 117 + - 164 + - 142 + - 101 + - 239 + - 144 + - 158 + - 239 + - 90 + - 56 + - 71 + - 120 + - 67 + - 221 + - 114 + - 10 + - 190 + - 4 + - 230 + - 164 + - 171 + - 78 + - 185 + - 90 + - 46 + - 177 + - 82 + - 228 + - 123 + - 222 + - 227 + - 145 + - 195 + - 219 + - 27 + - 56 + - 227 + - 246 + - 215 + - 144 + - 158 + - 31 + - 214 + - 241 + - 254 + - 200 + - 86 + - 142 + - 89 + - 12 + - 121 + - 29 + - 124 + - 9 + - 19 + - 153 + - 44 + - 35 + - 126 + - 14 + - 217 + - 65 + - 116 + - 26 + - 139 + - 122 + - 114 + - 90 + - 124 + - 81 + - 0 + - 186 + - 246 + - 46 + - 98 + - 179 + - 243 + - 198 + - 217 + - 36 + - 30 + - 202 + - 12 + - 135 + - 61 + - 42 + - 150 + - 221 + - 102 + - 83 + - 179 + - 43 + - 252 + - 81 + - 62 + - 126 + - 204 + - 195 + - 238 + - 18 + - 128 + - 193 + - 53 + - 94 + - 99 + - 63 + - 182 + - 2 + - 186 + - 220 + - 77 + - 186 + - 224 + - 220 + - 13 + - 212 + - 182 + - 88 + - 15 + - 151 + - 5 + - 93 + - 251 + - 164 + - 18 + - 228 + - 168 + - 226 + - 195 + - 44 + - 170 + - 145 + - 36 + - 58 + - 96 + - 107 + - 144 + - 11 + - 228 + - 12 + - 163 + - 238 + - 247 + - 159 + - 189 + - 1 + - 115 + - 65 + - 202 + - 121 + - 47 + - 193 + - 11 + - 96 + - 93 + - 72 + - 81 + - 207 + - 121 + - 19 + - 151 + - 136 + - 233 + - 51 + - 133 + - 195 + - 77 + - 44 + - 147 + - 206 + - 120 + - 252 + - 77 + - 212 + - 68 + - 60 + - 206 + - 106 + - 207 + - 243 + - 158 + - 94 + - 6 + - 3 + - 205 + - 92 + - 84 + - 2 + - 220 + - 50 + - 61 + - 38 + - 141 + - 117 + - 108 + - 101 + module: sbp.ssr + name: MsgSsrGridDefinitionDepA + msg_type: '0x5f5' + raw_json: '{"crc":35660,"length":255,"msg_type":1525,"payload":"C1Sr5YSPLsw0XGgZzLYWYst70yYN/YGtq+v9GssDeH4qLCdXRZoNHLMgLyTDJ8aG64Y5ePOXIxHJ0311pI5l75Ce71o4R3hD3XIKvgTmpKtOuVousVLke97jkcPbGzjj9teQnh/W8f7IVo5ZDHkdfAkTmSwjfg7ZQXQai3pyWnxRALr2LmKz88bZJB7KDIc9KpbdZlOzK/xRPn7Mw+4SgME1XmM/tgK63E264NwN1LZYD5cFXfukEuSo4sMsqpEkOmBrkAvkDKPu95+9AXNBynkvwQtgXUhRz3kTl4jpM4XDTSyTznj8TdREPM5qz/OeXgYDzVxUAtwyPSaNdWxl","preamble":85,"sender":63413,"header":{"region_size_inverse":11,"area_width":43860,"lat_nw_corner_enc":34021,"lon_nw_corner_enc":11919,"num_msgs":204,"seq_num":52},"rle_list":[92,104,25,204,182,22,98,203,123,211,38,13,253,129,173,171,235,253,26,203,3,120,126,42,44,39,87,69,154,13,28,179,32,47,36,195,39,198,134,235,134,57,120,243,151,35,17,201,211,125,117,164,142,101,239,144,158,239,90,56,71,120,67,221,114,10,190,4,230,164,171,78,185,90,46,177,82,228,123,222,227,145,195,219,27,56,227,246,215,144,158,31,214,241,254,200,86,142,89,12,121,29,124,9,19,153,44,35,126,14,217,65,116,26,139,122,114,90,124,81,0,186,246,46,98,179,243,198,217,36,30,202,12,135,61,42,150,221,102,83,179,43,252,81,62,126,204,195,238,18,128,193,53,94,99,63,182,2,186,220,77,186,224,220,13,212,182,88,15,151,5,93,251,164,18,228,168,226,195,44,170,145,36,58,96,107,144,11,228,12,163,238,247,159,189,1,115,65,202,121,47,193,11,96,93,72,81,207,121,19,151,136,233,51,133,195,77,44,147,206,120,252,77,212,68,60,206,106,207,243,158,94,6,3,205,92,84,2,220,50,61,38,141,117,108,101]}' + raw_packet: VfUFtff/C1Sr5YSPLsw0XGgZzLYWYst70yYN/YGtq+v9GssDeH4qLCdXRZoNHLMgLyTDJ8aG64Y5ePOXIxHJ0311pI5l75Ce71o4R3hD3XIKvgTmpKtOuVousVLke97jkcPbGzjj9teQnh/W8f7IVo5ZDHkdfAkTmSwjfg7ZQXQai3pyWnxRALr2LmKz88bZJB7KDIc9KpbdZlOzK/xRPn7Mw+4SgME1XmM/tgK63E264NwN1LZYD5cFXfukEuSo4sMsqpEkOmBrkAvkDKPu95+9AXNBynkvwQtgXUhRz3kTl4jpM4XDTSyTznj8TdREPM5qz/OeXgYDzVxUAtwyPSaNdWxlTIs= + sbp: + crc: '0x8b4c' + length: 255 + msg_type: '0x5f5' + payload: C1Sr5YSPLsw0XGgZzLYWYst70yYN/YGtq+v9GssDeH4qLCdXRZoNHLMgLyTDJ8aG64Y5ePOXIxHJ0311pI5l75Ce71o4R3hD3XIKvgTmpKtOuVousVLke97jkcPbGzjj9teQnh/W8f7IVo5ZDHkdfAkTmSwjfg7ZQXQai3pyWnxRALr2LmKz88bZJB7KDIc9KpbdZlOzK/xRPn7Mw+4SgME1XmM/tgK63E264NwN1LZYD5cFXfukEuSo4sMsqpEkOmBrkAvkDKPu95+9AXNBynkvwQtgXUhRz3kTl4jpM4XDTSyTznj8TdREPM5qz/OeXgYDzVxUAtwyPSaNdWxl + preamble: '0x55' + sender: '0xf7b5' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml new file mode 100644 index 0000000000..a954c47416 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrection.yaml @@ -0,0 +1,271 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrGriddedCorrection +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_stec_residuals: + handle_as: vararray-len + relates_to: stec_residuals + value: 46 + fields: + header: + iod_atmo: 170 + num_msgs: 48535 + seq_num: 50380 + tile_id: 12951 + tile_set_id: 3605 + time: + tow: 2535294328 + wn: 58798 + tropo_quality_indicator: 120 + update_interval: 105 + index: 43413 + stec_residuals: + - residual: -21246 + stddev: 88 + sv_id: + constellation: 101 + satId: 140 + - residual: -26570 + stddev: 115 + sv_id: + constellation: 180 + satId: 70 + - residual: 6049 + stddev: 135 + sv_id: + constellation: 201 + satId: 78 + - residual: 19261 + stddev: 178 + sv_id: + constellation: 98 + satId: 152 + - residual: 14226 + stddev: 58 + sv_id: + constellation: 229 + satId: 120 + - residual: 17894 + stddev: 172 + sv_id: + constellation: 234 + satId: 169 + - residual: 22930 + stddev: 150 + sv_id: + constellation: 127 + satId: 191 + - residual: 10721 + stddev: 17 + sv_id: + constellation: 111 + satId: 91 + - residual: -22874 + stddev: 120 + sv_id: + constellation: 52 + satId: 119 + - residual: 780 + stddev: 156 + sv_id: + constellation: 221 + satId: 57 + - residual: 32547 + stddev: 8 + sv_id: + constellation: 156 + satId: 70 + - residual: 14208 + stddev: 115 + sv_id: + constellation: 58 + satId: 127 + - residual: -26246 + stddev: 124 + sv_id: + constellation: 157 + satId: 80 + - residual: 26466 + stddev: 204 + sv_id: + constellation: 128 + satId: 27 + - residual: -7552 + stddev: 148 + sv_id: + constellation: 238 + satId: 75 + - residual: -12072 + stddev: 149 + sv_id: + constellation: 61 + satId: 248 + - residual: -28632 + stddev: 186 + sv_id: + constellation: 224 + satId: 167 + - residual: -4024 + stddev: 100 + sv_id: + constellation: 227 + satId: 157 + - residual: 2004 + stddev: 59 + sv_id: + constellation: 12 + satId: 35 + - residual: 6998 + stddev: 24 + sv_id: + constellation: 81 + satId: 176 + - residual: -31701 + stddev: 45 + sv_id: + constellation: 67 + satId: 155 + - residual: 28678 + stddev: 183 + sv_id: + constellation: 44 + satId: 203 + - residual: -15793 + stddev: 253 + sv_id: + constellation: 176 + satId: 231 + - residual: -7589 + stddev: 116 + sv_id: + constellation: 103 + satId: 247 + - residual: -7362 + stddev: 240 + sv_id: + constellation: 23 + satId: 148 + - residual: 4813 + stddev: 242 + sv_id: + constellation: 219 + satId: 29 + - residual: 20295 + stddev: 37 + sv_id: + constellation: 72 + satId: 207 + - residual: -13623 + stddev: 91 + sv_id: + constellation: 176 + satId: 42 + - residual: 15250 + stddev: 110 + sv_id: + constellation: 115 + satId: 105 + - residual: -18560 + stddev: 185 + sv_id: + constellation: 109 + satId: 44 + - residual: 23717 + stddev: 79 + sv_id: + constellation: 31 + satId: 67 + - residual: 1886 + stddev: 162 + sv_id: + constellation: 180 + satId: 189 + - residual: 12242 + stddev: 7 + sv_id: + constellation: 156 + satId: 121 + - residual: 10670 + stddev: 241 + sv_id: + constellation: 205 + satId: 7 + - residual: 25899 + stddev: 186 + sv_id: + constellation: 210 + satId: 129 + - residual: -2078 + stddev: 187 + sv_id: + constellation: 195 + satId: 208 + - residual: -16264 + stddev: 102 + sv_id: + constellation: 160 + satId: 219 + - residual: -21002 + stddev: 94 + sv_id: + constellation: 42 + satId: 166 + - residual: 7902 + stddev: 35 + sv_id: + constellation: 156 + satId: 102 + - residual: -30275 + stddev: 204 + sv_id: + constellation: 64 + satId: 247 + - residual: -8633 + stddev: 222 + sv_id: + constellation: 32 + satId: 220 + - residual: 6403 + stddev: 45 + sv_id: + constellation: 246 + satId: 201 + - residual: 22643 + stddev: 218 + sv_id: + constellation: 239 + satId: 251 + - residual: 16760 + stddev: 175 + sv_id: + constellation: 209 + satId: 10 + - residual: -20951 + stddev: 137 + sv_id: + constellation: 194 + satId: 131 + - residual: -740 + stddev: 42 + sv_id: + constellation: 68 + satId: 17 + tropo_delay_correction: + hydro: -3035 + stddev: 72 + wet: 78 + module: sbp.ssr + name: MsgSsrGriddedCorrection + msg_type: '0x5fc' + raw_json: '{"crc":9138,"length":253,"msg_type":1532,"payload":"FQ6XMniFHZeu5Ze9zMRpqniVqSX0TkiMZQKtWEa0NphzTsmhF4eYYj1Lsnjlkjc6qermRay/f5JZlltv4SkRdzSmpng53QwDnEacI38IfzqAN3NQnXqZfBuAYmfMS+6A4pT4PdjQlafgKJC6neNI8GQjDNQHO7BRVhsYm0MrhC3LLAZwt+ewT8L992db4nSUFz7j8B3bzRLyz0hHTyUqsMnKW2lzkjtuLG2At7lDH6VcT720XgeieZzSLwcHza4p8YHSK2W60MPi97vboHjAZqYq9q1eZpzeHiP3QL2JzNwgR97eyfYDGS3773NY2grReEGvg8IprokRRBz9Kg==","preamble":85,"sender":63940,"header":{"tile_set_id":3605,"tile_id":12951,"time":{"tow":2535294328,"wn":58798},"num_msgs":48535,"seq_num":50380,"update_interval":105,"iod_atmo":170,"tropo_quality_indicator":120},"index":43413,"tropo_delay_correction":{"hydro":-3035,"wet":78,"stddev":72},"stec_residuals":[{"sv_id":{"satId":140,"constellation":101},"residual":-21246,"stddev":88},{"sv_id":{"satId":70,"constellation":180},"residual":-26570,"stddev":115},{"sv_id":{"satId":78,"constellation":201},"residual":6049,"stddev":135},{"sv_id":{"satId":152,"constellation":98},"residual":19261,"stddev":178},{"sv_id":{"satId":120,"constellation":229},"residual":14226,"stddev":58},{"sv_id":{"satId":169,"constellation":234},"residual":17894,"stddev":172},{"sv_id":{"satId":191,"constellation":127},"residual":22930,"stddev":150},{"sv_id":{"satId":91,"constellation":111},"residual":10721,"stddev":17},{"sv_id":{"satId":119,"constellation":52},"residual":-22874,"stddev":120},{"sv_id":{"satId":57,"constellation":221},"residual":780,"stddev":156},{"sv_id":{"satId":70,"constellation":156},"residual":32547,"stddev":8},{"sv_id":{"satId":127,"constellation":58},"residual":14208,"stddev":115},{"sv_id":{"satId":80,"constellation":157},"residual":-26246,"stddev":124},{"sv_id":{"satId":27,"constellation":128},"residual":26466,"stddev":204},{"sv_id":{"satId":75,"constellation":238},"residual":-7552,"stddev":148},{"sv_id":{"satId":248,"constellation":61},"residual":-12072,"stddev":149},{"sv_id":{"satId":167,"constellation":224},"residual":-28632,"stddev":186},{"sv_id":{"satId":157,"constellation":227},"residual":-4024,"stddev":100},{"sv_id":{"satId":35,"constellation":12},"residual":2004,"stddev":59},{"sv_id":{"satId":176,"constellation":81},"residual":6998,"stddev":24},{"sv_id":{"satId":155,"constellation":67},"residual":-31701,"stddev":45},{"sv_id":{"satId":203,"constellation":44},"residual":28678,"stddev":183},{"sv_id":{"satId":231,"constellation":176},"residual":-15793,"stddev":253},{"sv_id":{"satId":247,"constellation":103},"residual":-7589,"stddev":116},{"sv_id":{"satId":148,"constellation":23},"residual":-7362,"stddev":240},{"sv_id":{"satId":29,"constellation":219},"residual":4813,"stddev":242},{"sv_id":{"satId":207,"constellation":72},"residual":20295,"stddev":37},{"sv_id":{"satId":42,"constellation":176},"residual":-13623,"stddev":91},{"sv_id":{"satId":105,"constellation":115},"residual":15250,"stddev":110},{"sv_id":{"satId":44,"constellation":109},"residual":-18560,"stddev":185},{"sv_id":{"satId":67,"constellation":31},"residual":23717,"stddev":79},{"sv_id":{"satId":189,"constellation":180},"residual":1886,"stddev":162},{"sv_id":{"satId":121,"constellation":156},"residual":12242,"stddev":7},{"sv_id":{"satId":7,"constellation":205},"residual":10670,"stddev":241},{"sv_id":{"satId":129,"constellation":210},"residual":25899,"stddev":186},{"sv_id":{"satId":208,"constellation":195},"residual":-2078,"stddev":187},{"sv_id":{"satId":219,"constellation":160},"residual":-16264,"stddev":102},{"sv_id":{"satId":166,"constellation":42},"residual":-21002,"stddev":94},{"sv_id":{"satId":102,"constellation":156},"residual":7902,"stddev":35},{"sv_id":{"satId":247,"constellation":64},"residual":-30275,"stddev":204},{"sv_id":{"satId":220,"constellation":32},"residual":-8633,"stddev":222},{"sv_id":{"satId":201,"constellation":246},"residual":6403,"stddev":45},{"sv_id":{"satId":251,"constellation":239},"residual":22643,"stddev":218},{"sv_id":{"satId":10,"constellation":209},"residual":16760,"stddev":175},{"sv_id":{"satId":131,"constellation":194},"residual":-20951,"stddev":137},{"sv_id":{"satId":17,"constellation":68},"residual":-740,"stddev":42}]}' + raw_packet: VfwFxPn9FQ6XMniFHZeu5Ze9zMRpqniVqSX0TkiMZQKtWEa0NphzTsmhF4eYYj1Lsnjlkjc6qermRay/f5JZlltv4SkRdzSmpng53QwDnEacI38IfzqAN3NQnXqZfBuAYmfMS+6A4pT4PdjQlafgKJC6neNI8GQjDNQHO7BRVhsYm0MrhC3LLAZwt+ewT8L992db4nSUFz7j8B3bzRLyz0hHTyUqsMnKW2lzkjtuLG2At7lDH6VcT720XgeieZzSLwcHza4p8YHSK2W60MPi97vboHjAZqYq9q1eZpzeHiP3QL2JzNwgR97eyfYDGS3773NY2grReEGvg8IprokRRBz9KrIj + sbp: + crc: '0x23b2' + length: 253 + msg_type: '0x5fc' + payload: FQ6XMniFHZeu5Ze9zMRpqniVqSX0TkiMZQKtWEa0NphzTsmhF4eYYj1Lsnjlkjc6qermRay/f5JZlltv4SkRdzSmpng53QwDnEacI38IfzqAN3NQnXqZfBuAYmfMS+6A4pT4PdjQlafgKJC6neNI8GQjDNQHO7BRVhsYm0MrhC3LLAZwt+ewT8L992db4nSUFz7j8B3bzRLyz0hHTyUqsMnKW2lzkjtuLG2At7lDH6VcT720XgeieZzSLwcHza4p8YHSK2W60MPi97vboHjAZqYq9q1eZpzeHiP3QL2JzNwgR97eyfYDGS3773NY2grReEGvg8IprokRRBz9Kg== + preamble: '0x55' + sender: '0xf9c4' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionBounds.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionBounds.yaml index cd52818539..860089a1fa 100644 --- a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionBounds.yaml +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionBounds.yaml @@ -4,6 +4,11 @@ package: sbp.ssr tests: - msg: + c_decoded_fields: + n_sats: + handle_as: vararray-len + relates_to: stec_sat_list + value: 2 fields: header: time: @@ -110,4 +115,4 @@ tests: sender: '0x0042' length: 27 payload: tAAAAAMAAQAKAA8BAAoAJ+gD9AFkyJZklmQA - crc: '0x249B' \ No newline at end of file + crc: '0x249B' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml new file mode 100644 index 0000000000..26770d02c9 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionDepA.yaml @@ -0,0 +1,274 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrGriddedCorrectionDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_stec_residuals: + handle_as: vararray-len + relates_to: stec_residuals + value: 47 + fields: + header: + iod_atmo: 245 + num_msgs: 37695 + seq_num: 64616 + time: + tow: 892131748 + wn: 23906 + tropo_quality_indicator: 28 + update_interval: 133 + index: 25695 + stec_residuals: + - residual: -26738 + stddev: 74 + sv_id: + constellation: 25 + satId: 87 + - residual: 1886 + stddev: 146 + sv_id: + constellation: 95 + satId: 151 + - residual: 22183 + stddev: 42 + sv_id: + constellation: 45 + satId: 237 + - residual: -5463 + stddev: 220 + sv_id: + constellation: 224 + satId: 116 + - residual: 3346 + stddev: 178 + sv_id: + constellation: 176 + satId: 23 + - residual: 28320 + stddev: 15 + sv_id: + constellation: 160 + satId: 79 + - residual: -24937 + stddev: 22 + sv_id: + constellation: 206 + satId: 53 + - residual: -21968 + stddev: 82 + sv_id: + constellation: 184 + satId: 117 + - residual: 17786 + stddev: 180 + sv_id: + constellation: 53 + satId: 40 + - residual: 26689 + stddev: 244 + sv_id: + constellation: 38 + satId: 110 + - residual: 22755 + stddev: 169 + sv_id: + constellation: 238 + satId: 19 + - residual: 9535 + stddev: 183 + sv_id: + constellation: 146 + satId: 164 + - residual: -22293 + stddev: 114 + sv_id: + constellation: 71 + satId: 85 + - residual: -25379 + stddev: 60 + sv_id: + constellation: 105 + satId: 211 + - residual: -29182 + stddev: 172 + sv_id: + constellation: 230 + satId: 18 + - residual: 32289 + stddev: 106 + sv_id: + constellation: 39 + satId: 16 + - residual: 10730 + stddev: 162 + sv_id: + constellation: 188 + satId: 99 + - residual: 20707 + stddev: 12 + sv_id: + constellation: 138 + satId: 197 + - residual: 1518 + stddev: 93 + sv_id: + constellation: 67 + satId: 54 + - residual: 3457 + stddev: 46 + sv_id: + constellation: 207 + satId: 1 + - residual: -18118 + stddev: 127 + sv_id: + constellation: 49 + satId: 115 + - residual: -9888 + stddev: 202 + sv_id: + constellation: 200 + satId: 156 + - residual: -14793 + stddev: 81 + sv_id: + constellation: 245 + satId: 15 + - residual: 18758 + stddev: 82 + sv_id: + constellation: 132 + satId: 218 + - residual: 3839 + stddev: 134 + sv_id: + constellation: 26 + satId: 147 + - residual: -10697 + stddev: 83 + sv_id: + constellation: 138 + satId: 96 + - residual: 20387 + stddev: 173 + sv_id: + constellation: 170 + satId: 156 + - residual: -3789 + stddev: 107 + sv_id: + constellation: 115 + satId: 228 + - residual: -11608 + stddev: 10 + sv_id: + constellation: 112 + satId: 245 + - residual: 14593 + stddev: 108 + sv_id: + constellation: 117 + satId: 5 + - residual: 30609 + stddev: 226 + sv_id: + constellation: 212 + satId: 248 + - residual: -13683 + stddev: 106 + sv_id: + constellation: 5 + satId: 165 + - residual: 15652 + stddev: 243 + sv_id: + constellation: 60 + satId: 0 + - residual: 3287 + stddev: 137 + sv_id: + constellation: 216 + satId: 203 + - residual: 29687 + stddev: 152 + sv_id: + constellation: 28 + satId: 16 + - residual: -6960 + stddev: 203 + sv_id: + constellation: 119 + satId: 181 + - residual: -15193 + stddev: 32 + sv_id: + constellation: 34 + satId: 236 + - residual: 25873 + stddev: 200 + sv_id: + constellation: 1 + satId: 109 + - residual: -22403 + stddev: 137 + sv_id: + constellation: 94 + satId: 25 + - residual: 7588 + stddev: 31 + sv_id: + constellation: 4 + satId: 157 + - residual: -6840 + stddev: 126 + sv_id: + constellation: 132 + satId: 48 + - residual: -31412 + stddev: 21 + sv_id: + constellation: 68 + satId: 186 + - residual: -23413 + stddev: 148 + sv_id: + constellation: 180 + satId: 0 + - residual: 30934 + stddev: 177 + sv_id: + constellation: 149 + satId: 119 + - residual: 26960 + stddev: 10 + sv_id: + constellation: 80 + satId: 201 + - residual: 11853 + stddev: 233 + sv_id: + constellation: 118 + satId: 136 + - residual: -25077 + stddev: 103 + sv_id: + constellation: 227 + satId: 233 + tropo_delay_correction: + hydro: 10643 + stddev: 92 + wet: 33 + module: sbp.ssr + name: MsgSsrGriddedCorrectionDepA + msg_type: '0x5fa' + raw_json: '{"crc":55463,"length":254,"msg_type":1530,"payload":"pNksNWJdP5No/IX1HF9kkykhXFcZjpdKl19eB5LtLadWKnTgqercF7ASDbJPoKBuDzXOl54WdbgwqlIoNXpFtG4mQWj0E+7jWKmkkj8lt1VH66hy02ndnDwS5gKOrBAnIX5qY7zqKaLFiuNQDDZD7gVdAc+BDS5zMTq5f5zIYNnKD/U3xlHahEZJUpMa/w6GYIo31lOcqqNPreRzM/Fr9XCo0goFdQE5bPjUkXfipQWNymoAPCQ988vY1wyJEBz3c5i1d9Dky+wip8QgbQERZcgZXn2oiZ0EpB0fMIRI5X66REyFFQC0i6SUd5XWeLHJUFBpCoh2TS7p6eMLnmc=","preamble":85,"sender":27244,"header":{"time":{"tow":892131748,"wn":23906},"num_msgs":37695,"seq_num":64616,"update_interval":133,"iod_atmo":245,"tropo_quality_indicator":28},"index":25695,"tropo_delay_correction":{"hydro":10643,"wet":33,"stddev":92},"stec_residuals":[{"sv_id":{"satId":87,"constellation":25},"residual":-26738,"stddev":74},{"sv_id":{"satId":151,"constellation":95},"residual":1886,"stddev":146},{"sv_id":{"satId":237,"constellation":45},"residual":22183,"stddev":42},{"sv_id":{"satId":116,"constellation":224},"residual":-5463,"stddev":220},{"sv_id":{"satId":23,"constellation":176},"residual":3346,"stddev":178},{"sv_id":{"satId":79,"constellation":160},"residual":28320,"stddev":15},{"sv_id":{"satId":53,"constellation":206},"residual":-24937,"stddev":22},{"sv_id":{"satId":117,"constellation":184},"residual":-21968,"stddev":82},{"sv_id":{"satId":40,"constellation":53},"residual":17786,"stddev":180},{"sv_id":{"satId":110,"constellation":38},"residual":26689,"stddev":244},{"sv_id":{"satId":19,"constellation":238},"residual":22755,"stddev":169},{"sv_id":{"satId":164,"constellation":146},"residual":9535,"stddev":183},{"sv_id":{"satId":85,"constellation":71},"residual":-22293,"stddev":114},{"sv_id":{"satId":211,"constellation":105},"residual":-25379,"stddev":60},{"sv_id":{"satId":18,"constellation":230},"residual":-29182,"stddev":172},{"sv_id":{"satId":16,"constellation":39},"residual":32289,"stddev":106},{"sv_id":{"satId":99,"constellation":188},"residual":10730,"stddev":162},{"sv_id":{"satId":197,"constellation":138},"residual":20707,"stddev":12},{"sv_id":{"satId":54,"constellation":67},"residual":1518,"stddev":93},{"sv_id":{"satId":1,"constellation":207},"residual":3457,"stddev":46},{"sv_id":{"satId":115,"constellation":49},"residual":-18118,"stddev":127},{"sv_id":{"satId":156,"constellation":200},"residual":-9888,"stddev":202},{"sv_id":{"satId":15,"constellation":245},"residual":-14793,"stddev":81},{"sv_id":{"satId":218,"constellation":132},"residual":18758,"stddev":82},{"sv_id":{"satId":147,"constellation":26},"residual":3839,"stddev":134},{"sv_id":{"satId":96,"constellation":138},"residual":-10697,"stddev":83},{"sv_id":{"satId":156,"constellation":170},"residual":20387,"stddev":173},{"sv_id":{"satId":228,"constellation":115},"residual":-3789,"stddev":107},{"sv_id":{"satId":245,"constellation":112},"residual":-11608,"stddev":10},{"sv_id":{"satId":5,"constellation":117},"residual":14593,"stddev":108},{"sv_id":{"satId":248,"constellation":212},"residual":30609,"stddev":226},{"sv_id":{"satId":165,"constellation":5},"residual":-13683,"stddev":106},{"sv_id":{"satId":0,"constellation":60},"residual":15652,"stddev":243},{"sv_id":{"satId":203,"constellation":216},"residual":3287,"stddev":137},{"sv_id":{"satId":16,"constellation":28},"residual":29687,"stddev":152},{"sv_id":{"satId":181,"constellation":119},"residual":-6960,"stddev":203},{"sv_id":{"satId":236,"constellation":34},"residual":-15193,"stddev":32},{"sv_id":{"satId":109,"constellation":1},"residual":25873,"stddev":200},{"sv_id":{"satId":25,"constellation":94},"residual":-22403,"stddev":137},{"sv_id":{"satId":157,"constellation":4},"residual":7588,"stddev":31},{"sv_id":{"satId":48,"constellation":132},"residual":-6840,"stddev":126},{"sv_id":{"satId":186,"constellation":68},"residual":-31412,"stddev":21},{"sv_id":{"satId":0,"constellation":180},"residual":-23413,"stddev":148},{"sv_id":{"satId":119,"constellation":149},"residual":30934,"stddev":177},{"sv_id":{"satId":201,"constellation":80},"residual":26960,"stddev":10},{"sv_id":{"satId":136,"constellation":118},"residual":11853,"stddev":233},{"sv_id":{"satId":233,"constellation":227},"residual":-25077,"stddev":103}]}' + raw_packet: VfoFbGr+pNksNWJdP5No/IX1HF9kkykhXFcZjpdKl19eB5LtLadWKnTgqercF7ASDbJPoKBuDzXOl54WdbgwqlIoNXpFtG4mQWj0E+7jWKmkkj8lt1VH66hy02ndnDwS5gKOrBAnIX5qY7zqKaLFiuNQDDZD7gVdAc+BDS5zMTq5f5zIYNnKD/U3xlHahEZJUpMa/w6GYIo31lOcqqNPreRzM/Fr9XCo0goFdQE5bPjUkXfipQWNymoAPCQ988vY1wyJEBz3c5i1d9Dky+wip8QgbQERZcgZXn2oiZ0EpB0fMIRI5X66REyFFQC0i6SUd5XWeLHJUFBpCoh2TS7p6eMLnmen2A== + sbp: + crc: '0xd8a7' + length: 254 + msg_type: '0x5fa' + payload: pNksNWJdP5No/IX1HF9kkykhXFcZjpdKl19eB5LtLadWKnTgqercF7ASDbJPoKBuDzXOl54WdbgwqlIoNXpFtG4mQWj0E+7jWKmkkj8lt1VH66hy02ndnDwS5gKOrBAnIX5qY7zqKaLFiuNQDDZD7gVdAc+BDS5zMTq5f5zIYNnKD/U3xlHahEZJUpMa/w6GYIo31lOcqqNPreRzM/Fr9XCo0goFdQE5bPjUkXfipQWNymoAPCQ988vY1wyJEBz3c5i1d9Dky+wip8QgbQERZcgZXn2oiZ0EpB0fMIRI5X66REyFFQC0i6SUd5XWeLHJUFBpCoh2TS7p6eMLnmc= + preamble: '0x55' + sender: '0x6a6c' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml new file mode 100644 index 0000000000..ffab52543d --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrGriddedCorrectionNoStdDepA.yaml @@ -0,0 +1,274 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrGriddedCorrectionNoStdDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_stec_residuals: + handle_as: vararray-len + relates_to: stec_residuals + value: 59 + fields: + header: + iod_atmo: 236 + num_msgs: 62837 + seq_num: 63555 + time: + tow: 2837573811 + wn: 8940 + tropo_quality_indicator: 230 + update_interval: 233 + index: 26598 + stec_residuals: + - residual: -23949 + sv_id: + constellation: 157 + satId: 231 + - residual: 27427 + sv_id: + constellation: 146 + satId: 197 + - residual: 10548 + sv_id: + constellation: 109 + satId: 222 + - residual: -18195 + sv_id: + constellation: 12 + satId: 86 + - residual: -27511 + sv_id: + constellation: 204 + satId: 65 + - residual: 11 + sv_id: + constellation: 183 + satId: 171 + - residual: 13740 + sv_id: + constellation: 203 + satId: 180 + - residual: 29626 + sv_id: + constellation: 85 + satId: 196 + - residual: 7846 + sv_id: + constellation: 92 + satId: 203 + - residual: 18376 + sv_id: + constellation: 13 + satId: 42 + - residual: -24357 + sv_id: + constellation: 137 + satId: 98 + - residual: -1441 + sv_id: + constellation: 216 + satId: 95 + - residual: -10660 + sv_id: + constellation: 196 + satId: 99 + - residual: -8509 + sv_id: + constellation: 253 + satId: 159 + - residual: 16361 + sv_id: + constellation: 146 + satId: 233 + - residual: 10346 + sv_id: + constellation: 24 + satId: 76 + - residual: -18679 + sv_id: + constellation: 65 + satId: 253 + - residual: 15292 + sv_id: + constellation: 215 + satId: 40 + - residual: 29537 + sv_id: + constellation: 69 + satId: 117 + - residual: -29440 + sv_id: + constellation: 56 + satId: 60 + - residual: -24266 + sv_id: + constellation: 171 + satId: 207 + - residual: 22272 + sv_id: + constellation: 61 + satId: 23 + - residual: 9303 + sv_id: + constellation: 123 + satId: 230 + - residual: -23794 + sv_id: + constellation: 255 + satId: 184 + - residual: -26837 + sv_id: + constellation: 224 + satId: 187 + - residual: 14631 + sv_id: + constellation: 104 + satId: 151 + - residual: -8144 + sv_id: + constellation: 54 + satId: 5 + - residual: 23612 + sv_id: + constellation: 129 + satId: 181 + - residual: 28013 + sv_id: + constellation: 114 + satId: 171 + - residual: 2166 + sv_id: + constellation: 23 + satId: 12 + - residual: -10186 + sv_id: + constellation: 159 + satId: 64 + - residual: 17432 + sv_id: + constellation: 20 + satId: 33 + - residual: -8666 + sv_id: + constellation: 36 + satId: 160 + - residual: 25436 + sv_id: + constellation: 190 + satId: 145 + - residual: -3864 + sv_id: + constellation: 159 + satId: 108 + - residual: 4093 + sv_id: + constellation: 221 + satId: 227 + - residual: -18055 + sv_id: + constellation: 23 + satId: 62 + - residual: -27900 + sv_id: + constellation: 116 + satId: 168 + - residual: 30687 + sv_id: + constellation: 72 + satId: 123 + - residual: -13151 + sv_id: + constellation: 242 + satId: 226 + - residual: -22903 + sv_id: + constellation: 202 + satId: 180 + - residual: 4988 + sv_id: + constellation: 24 + satId: 58 + - residual: 27408 + sv_id: + constellation: 188 + satId: 181 + - residual: 319 + sv_id: + constellation: 231 + satId: 66 + - residual: 15987 + sv_id: + constellation: 252 + satId: 64 + - residual: 22266 + sv_id: + constellation: 97 + satId: 233 + - residual: -19919 + sv_id: + constellation: 221 + satId: 156 + - residual: 17350 + sv_id: + constellation: 73 + satId: 32 + - residual: 14410 + sv_id: + constellation: 253 + satId: 249 + - residual: 23671 + sv_id: + constellation: 165 + satId: 38 + - residual: -31905 + sv_id: + constellation: 44 + satId: 99 + - residual: 14305 + sv_id: + constellation: 192 + satId: 89 + - residual: -12968 + sv_id: + constellation: 171 + satId: 95 + - residual: 21479 + sv_id: + constellation: 116 + satId: 21 + - residual: 28260 + sv_id: + constellation: 71 + satId: 71 + - residual: -11112 + sv_id: + constellation: 254 + satId: 217 + - residual: -25304 + sv_id: + constellation: 8 + satId: 18 + - residual: -4024 + sv_id: + constellation: 54 + satId: 244 + - residual: -15505 + sv_id: + constellation: 189 + satId: 231 + tropo_delay_correction: + hydro: 16250 + wet: 101 + module: sbp.ssr + name: MsgSsrGriddedCorrectionNoStdDepA + msg_type: '0x5f0' + raw_json: '{"crc":20941,"length":254,"msg_type":1520,"payload":"s/AhqewidfVD+Ons5uZnej9l551zosWSI2vebTQpVgztuEHMiZSrtwsAtMusNcRVunPLXKYeKg3IR2KJ26Bf2F/6Y8Rc1p/9w97pkuk/TBhqKP1BCbco17w7dUVhczw4AI3PqzahFz0AV+Z7VyS4/w6ju+Arl5doJzkFNjDgtYE8XKtybW0MF3YIQJ822CEUGESgJCbekb5cY2yf6PDj3f0PPhd5uah0BJN7SN934vKhzLTKiaY6GHwTtbwQa0LnPwFA/HM+6WH6VpzdMbIgScZD+f1KOCald1xjLF+DWcDhN1+rWM0VdOdTR0dkbtn+mNQSCCid9DZI8Oe9b8M=","preamble":85,"sender":7270,"header":{"time":{"tow":2837573811,"wn":8940},"num_msgs":62837,"seq_num":63555,"update_interval":233,"iod_atmo":236,"tropo_quality_indicator":230},"index":26598,"tropo_delay_correction":{"hydro":16250,"wet":101},"stec_residuals":[{"sv_id":{"satId":231,"constellation":157},"residual":-23949},{"sv_id":{"satId":197,"constellation":146},"residual":27427},{"sv_id":{"satId":222,"constellation":109},"residual":10548},{"sv_id":{"satId":86,"constellation":12},"residual":-18195},{"sv_id":{"satId":65,"constellation":204},"residual":-27511},{"sv_id":{"satId":171,"constellation":183},"residual":11},{"sv_id":{"satId":180,"constellation":203},"residual":13740},{"sv_id":{"satId":196,"constellation":85},"residual":29626},{"sv_id":{"satId":203,"constellation":92},"residual":7846},{"sv_id":{"satId":42,"constellation":13},"residual":18376},{"sv_id":{"satId":98,"constellation":137},"residual":-24357},{"sv_id":{"satId":95,"constellation":216},"residual":-1441},{"sv_id":{"satId":99,"constellation":196},"residual":-10660},{"sv_id":{"satId":159,"constellation":253},"residual":-8509},{"sv_id":{"satId":233,"constellation":146},"residual":16361},{"sv_id":{"satId":76,"constellation":24},"residual":10346},{"sv_id":{"satId":253,"constellation":65},"residual":-18679},{"sv_id":{"satId":40,"constellation":215},"residual":15292},{"sv_id":{"satId":117,"constellation":69},"residual":29537},{"sv_id":{"satId":60,"constellation":56},"residual":-29440},{"sv_id":{"satId":207,"constellation":171},"residual":-24266},{"sv_id":{"satId":23,"constellation":61},"residual":22272},{"sv_id":{"satId":230,"constellation":123},"residual":9303},{"sv_id":{"satId":184,"constellation":255},"residual":-23794},{"sv_id":{"satId":187,"constellation":224},"residual":-26837},{"sv_id":{"satId":151,"constellation":104},"residual":14631},{"sv_id":{"satId":5,"constellation":54},"residual":-8144},{"sv_id":{"satId":181,"constellation":129},"residual":23612},{"sv_id":{"satId":171,"constellation":114},"residual":28013},{"sv_id":{"satId":12,"constellation":23},"residual":2166},{"sv_id":{"satId":64,"constellation":159},"residual":-10186},{"sv_id":{"satId":33,"constellation":20},"residual":17432},{"sv_id":{"satId":160,"constellation":36},"residual":-8666},{"sv_id":{"satId":145,"constellation":190},"residual":25436},{"sv_id":{"satId":108,"constellation":159},"residual":-3864},{"sv_id":{"satId":227,"constellation":221},"residual":4093},{"sv_id":{"satId":62,"constellation":23},"residual":-18055},{"sv_id":{"satId":168,"constellation":116},"residual":-27900},{"sv_id":{"satId":123,"constellation":72},"residual":30687},{"sv_id":{"satId":226,"constellation":242},"residual":-13151},{"sv_id":{"satId":180,"constellation":202},"residual":-22903},{"sv_id":{"satId":58,"constellation":24},"residual":4988},{"sv_id":{"satId":181,"constellation":188},"residual":27408},{"sv_id":{"satId":66,"constellation":231},"residual":319},{"sv_id":{"satId":64,"constellation":252},"residual":15987},{"sv_id":{"satId":233,"constellation":97},"residual":22266},{"sv_id":{"satId":156,"constellation":221},"residual":-19919},{"sv_id":{"satId":32,"constellation":73},"residual":17350},{"sv_id":{"satId":249,"constellation":253},"residual":14410},{"sv_id":{"satId":38,"constellation":165},"residual":23671},{"sv_id":{"satId":99,"constellation":44},"residual":-31905},{"sv_id":{"satId":89,"constellation":192},"residual":14305},{"sv_id":{"satId":95,"constellation":171},"residual":-12968},{"sv_id":{"satId":21,"constellation":116},"residual":21479},{"sv_id":{"satId":71,"constellation":71},"residual":28260},{"sv_id":{"satId":217,"constellation":254},"residual":-11112},{"sv_id":{"satId":18,"constellation":8},"residual":-25304},{"sv_id":{"satId":244,"constellation":54},"residual":-4024},{"sv_id":{"satId":231,"constellation":189},"residual":-15505}]}' + raw_packet: VfAFZhz+s/AhqewidfVD+Ons5uZnej9l551zosWSI2vebTQpVgztuEHMiZSrtwsAtMusNcRVunPLXKYeKg3IR2KJ26Bf2F/6Y8Rc1p/9w97pkuk/TBhqKP1BCbco17w7dUVhczw4AI3PqzahFz0AV+Z7VyS4/w6ju+Arl5doJzkFNjDgtYE8XKtybW0MF3YIQJ822CEUGESgJCbekb5cY2yf6PDj3f0PPhd5uah0BJN7SN934vKhzLTKiaY6GHwTtbwQa0LnPwFA/HM+6WH6VpzdMbIgScZD+f1KOCald1xjLF+DWcDhN1+rWM0VdOdTR0dkbtn+mNQSCCid9DZI8Oe9b8PNUQ== + sbp: + crc: '0x51cd' + length: 254 + msg_type: '0x5f0' + payload: s/AhqewidfVD+Ons5uZnej9l551zosWSI2vebTQpVgztuEHMiZSrtwsAtMusNcRVunPLXKYeKg3IR2KJ26Bf2F/6Y8Rc1p/9w97pkuk/TBhqKP1BCbco17w7dUVhczw4AI3PqzahFz0AV+Z7VyS4/w6ju+Arl5doJzkFNjDgtYE8XKtybW0MF3YIQJ822CEUGESgJCbekb5cY2yf6PDj3f0PPhd5uah0BJN7SN934vKhzLTKiaY6GHwTtbwQa0LnPwFA/HM+6WH6VpzdMbIgScZD+f1KOCald1xjLF+DWcDhN1+rWM0VdOdTR0dkbtn+mNQSCCid9DZI8Oe9b8M= + preamble: '0x55' + sender: '0x1c66' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml new file mode 100644 index 0000000000..694581dc84 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClock.yaml @@ -0,0 +1,37 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrOrbitClock +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + fields: + along: -1334502588 + c0: -174298703 + c1: -630458102 + c2: 1211677201 + cross: -197264530 + dot_along: 169404560 + dot_cross: 1118011173 + dot_radial: 878654074 + iod: 936372632 + iod_ssr: 255 + radial: -2143668642 + sid: + code: 212 + sat: 203 + time: + tow: 3479621715 + wn: 7588 + update_interval: 236 + module: sbp.ssr + name: MsgSsrOrbitClock + msg_type: '0x5dd' + raw_json: '{"crc":5646,"length":50,"msg_type":1501,"payload":"U9Bmz6Qdy9Ts/5jpzzdeNjqARBt1sG77PfR6Ml80kOgYCiV/o0KxaZz1Cvlr2hG6OEg=","preamble":85,"sender":58677,"time":{"tow":3479621715,"wn":7588},"sid":{"sat":203,"code":212},"update_interval":236,"iod_ssr":255,"iod":936372632,"radial":-2143668642,"along":-1334502588,"cross":-197264530,"dot_radial":878654074,"dot_along":169404560,"dot_cross":1118011173,"c0":-174298703,"c1":-630458102,"c2":1211677201}' + raw_packet: Vd0FNeUyU9Bmz6Qdy9Ts/5jpzzdeNjqARBt1sG77PfR6Ml80kOgYCiV/o0KxaZz1Cvlr2hG6OEgOFg== + sbp: + crc: '0x160e' + length: 50 + msg_type: '0x5dd' + payload: U9Bmz6Qdy9Ts/5jpzzdeNjqARBt1sG77PfR6Ml80kOgYCiV/o0KxaZz1Cvlr2hG6OEg= + preamble: '0x55' + sender: '0xe535' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockBounds.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockBounds.yaml index dc63445ebc..8462a9edae 100644 --- a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockBounds.yaml +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockBounds.yaml @@ -4,6 +4,11 @@ package: sbp.ssr tests: - msg: + c_decoded_fields: + n_sats: + handle_as: vararray-len + relates_to: orbit_clock_bounds + value: 2 fields: header: time: diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml new file mode 100644 index 0000000000..144855c933 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrOrbitClockDepA.yaml @@ -0,0 +1,37 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrOrbitClockDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + fields: + along: 132661048 + c0: -970026069 + c1: -503975083 + c2: -759858197 + cross: 1845577176 + dot_along: 72905755 + dot_cross: 311886653 + dot_radial: -1111196507 + iod: 193 + iod_ssr: 211 + radial: -24141393 + sid: + code: 30 + sat: 1 + time: + tow: 3172954849 + wn: 7723 + update_interval: 194 + module: sbp.ssr + name: MsgSsrOrbitClockDepA + msg_type: '0x5dc' + raw_json: '{"crc":64669,"length":47,"msg_type":1500,"payload":"4XIfvSseAR7C08GvoY/+OD/oB9hFAW6lfMS9G3RYBD0DlxKrky7GVfP14et7tdI=","preamble":85,"sender":42529,"time":{"tow":3172954849,"wn":7723},"sid":{"sat":1,"code":30},"update_interval":194,"iod_ssr":211,"iod":193,"radial":-24141393,"along":132661048,"cross":1845577176,"dot_radial":-1111196507,"dot_along":72905755,"dot_cross":311886653,"c0":-970026069,"c1":-503975083,"c2":-759858197}' + raw_packet: VdwFIaYv4XIfvSseAR7C08GvoY/+OD/oB9hFAW6lfMS9G3RYBD0DlxKrky7GVfP14et7tdKd/A== + sbp: + crc: '0xfc9d' + length: 47 + msg_type: '0x5dc' + payload: 4XIfvSseAR7C08GvoY/+OD/oB9hFAW6lfMS9G3RYBD0DlxKrky7GVfP14et7tdI= + preamble: '0x55' + sender: '0xa621' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml new file mode 100644 index 0000000000..9028fb8f29 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrPhaseBiases.yaml @@ -0,0 +1,187 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrPhaseBiases +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_biases: + handle_as: vararray-len + relates_to: biases + value: 30 + fields: + biases: + - bias: -1311498533 + code: 29 + discontinuity_counter: 193 + integer_indicator: 250 + widelane_integer_indicator: 245 + - bias: 1101319226 + code: 207 + discontinuity_counter: 146 + integer_indicator: 187 + widelane_integer_indicator: 33 + - bias: -64184056 + code: 114 + discontinuity_counter: 52 + integer_indicator: 49 + widelane_integer_indicator: 248 + - bias: -240298362 + code: 166 + discontinuity_counter: 124 + integer_indicator: 168 + widelane_integer_indicator: 232 + - bias: -1581740159 + code: 174 + discontinuity_counter: 155 + integer_indicator: 44 + widelane_integer_indicator: 142 + - bias: -1730297136 + code: 211 + discontinuity_counter: 189 + integer_indicator: 15 + widelane_integer_indicator: 36 + - bias: -1117221444 + code: 16 + discontinuity_counter: 34 + integer_indicator: 203 + widelane_integer_indicator: 87 + - bias: -1137604357 + code: 102 + discontinuity_counter: 22 + integer_indicator: 156 + widelane_integer_indicator: 252 + - bias: -1910370172 + code: 157 + discontinuity_counter: 49 + integer_indicator: 222 + widelane_integer_indicator: 245 + - bias: 1247996869 + code: 228 + discontinuity_counter: 221 + integer_indicator: 85 + widelane_integer_indicator: 139 + - bias: -1133446161 + code: 107 + discontinuity_counter: 38 + integer_indicator: 70 + widelane_integer_indicator: 36 + - bias: -720934762 + code: 124 + discontinuity_counter: 164 + integer_indicator: 246 + widelane_integer_indicator: 141 + - bias: 706252548 + code: 44 + discontinuity_counter: 192 + integer_indicator: 21 + widelane_integer_indicator: 244 + - bias: 388855338 + code: 21 + discontinuity_counter: 7 + integer_indicator: 84 + widelane_integer_indicator: 136 + - bias: 47517353 + code: 174 + discontinuity_counter: 54 + integer_indicator: 175 + widelane_integer_indicator: 129 + - bias: -2124125745 + code: 197 + discontinuity_counter: 13 + integer_indicator: 98 + widelane_integer_indicator: 60 + - bias: -1401812607 + code: 72 + discontinuity_counter: 140 + integer_indicator: 136 + widelane_integer_indicator: 240 + - bias: 60257151 + code: 151 + discontinuity_counter: 210 + integer_indicator: 150 + widelane_integer_indicator: 17 + - bias: 41820677 + code: 242 + discontinuity_counter: 14 + integer_indicator: 254 + widelane_integer_indicator: 215 + - bias: 1640616471 + code: 215 + discontinuity_counter: 176 + integer_indicator: 65 + widelane_integer_indicator: 38 + - bias: -744786918 + code: 36 + discontinuity_counter: 224 + integer_indicator: 207 + widelane_integer_indicator: 92 + - bias: 1966589763 + code: 165 + discontinuity_counter: 38 + integer_indicator: 47 + widelane_integer_indicator: 102 + - bias: 364366310 + code: 36 + discontinuity_counter: 1 + integer_indicator: 169 + widelane_integer_indicator: 33 + - bias: -1839031379 + code: 42 + discontinuity_counter: 173 + integer_indicator: 62 + widelane_integer_indicator: 147 + - bias: 31817639 + code: 231 + discontinuity_counter: 82 + integer_indicator: 167 + widelane_integer_indicator: 138 + - bias: -1619830156 + code: 2 + discontinuity_counter: 207 + integer_indicator: 127 + widelane_integer_indicator: 237 + - bias: -83375622 + code: 3 + discontinuity_counter: 145 + integer_indicator: 42 + widelane_integer_indicator: 66 + - bias: 1077458389 + code: 2 + discontinuity_counter: 26 + integer_indicator: 75 + widelane_integer_indicator: 230 + - bias: -883355501 + code: 97 + discontinuity_counter: 6 + integer_indicator: 88 + widelane_integer_indicator: 255 + - bias: -1448611273 + code: 27 + discontinuity_counter: 230 + integer_indicator: 68 + widelane_integer_indicator: 243 + dispersive_bias: 98 + iod_ssr: 230 + mw_consistency: 209 + sid: + code: 82 + sat: 169 + time: + tow: 210803409 + wn: 42197 + update_interval: 177 + yaw: 5881 + yaw_rate: 17 + module: sbp.ssr + name: MsgSsrPhaseBiases + msg_type: '0x5e6' + raw_json: '{"crc":61659,"length":255,"msg_type":1510,"payload":"0ZqQDNWkqVKx5mLR+RYRHfr1wdse1LHPuyGSOsykQXIx+DQIoSz8pqjofIZWrfGuLI6bgY+4odMPJL3Qwt2YEMtXIryNaL1mnPwW+4gxvJ3e9TGEECKO5FWL3cXrYkprRiQm7/twvHz2jaSWaAfVLBX0wASPGCoVVIgHKnYtF66vgTapDtUCxWI8Dc9pZIFIiPCMgQlyrJeWEdJ/c5cD8v7XDgUifgLXQSawF9LJYSTPXOAadJvTpS9mJkPHN3UkqSEB5sm3FSo+k62tm2KS56eKUqd/5QECf+3PdFpznwMqQpH6yQf7AkvmGtW1OEBhWP8GkxBZyxtE8+Y38qep","preamble":85,"sender":52955,"time":{"tow":210803409,"wn":42197},"sid":{"sat":169,"code":82},"update_interval":177,"iod_ssr":230,"dispersive_bias":98,"mw_consistency":209,"yaw":5881,"yaw_rate":17,"biases":[{"code":29,"integer_indicator":250,"widelane_integer_indicator":245,"discontinuity_counter":193,"bias":-1311498533},{"code":207,"integer_indicator":187,"widelane_integer_indicator":33,"discontinuity_counter":146,"bias":1101319226},{"code":114,"integer_indicator":49,"widelane_integer_indicator":248,"discontinuity_counter":52,"bias":-64184056},{"code":166,"integer_indicator":168,"widelane_integer_indicator":232,"discontinuity_counter":124,"bias":-240298362},{"code":174,"integer_indicator":44,"widelane_integer_indicator":142,"discontinuity_counter":155,"bias":-1581740159},{"code":211,"integer_indicator":15,"widelane_integer_indicator":36,"discontinuity_counter":189,"bias":-1730297136},{"code":16,"integer_indicator":203,"widelane_integer_indicator":87,"discontinuity_counter":34,"bias":-1117221444},{"code":102,"integer_indicator":156,"widelane_integer_indicator":252,"discontinuity_counter":22,"bias":-1137604357},{"code":157,"integer_indicator":222,"widelane_integer_indicator":245,"discontinuity_counter":49,"bias":-1910370172},{"code":228,"integer_indicator":85,"widelane_integer_indicator":139,"discontinuity_counter":221,"bias":1247996869},{"code":107,"integer_indicator":70,"widelane_integer_indicator":36,"discontinuity_counter":38,"bias":-1133446161},{"code":124,"integer_indicator":246,"widelane_integer_indicator":141,"discontinuity_counter":164,"bias":-720934762},{"code":44,"integer_indicator":21,"widelane_integer_indicator":244,"discontinuity_counter":192,"bias":706252548},{"code":21,"integer_indicator":84,"widelane_integer_indicator":136,"discontinuity_counter":7,"bias":388855338},{"code":174,"integer_indicator":175,"widelane_integer_indicator":129,"discontinuity_counter":54,"bias":47517353},{"code":197,"integer_indicator":98,"widelane_integer_indicator":60,"discontinuity_counter":13,"bias":-2124125745},{"code":72,"integer_indicator":136,"widelane_integer_indicator":240,"discontinuity_counter":140,"bias":-1401812607},{"code":151,"integer_indicator":150,"widelane_integer_indicator":17,"discontinuity_counter":210,"bias":60257151},{"code":242,"integer_indicator":254,"widelane_integer_indicator":215,"discontinuity_counter":14,"bias":41820677},{"code":215,"integer_indicator":65,"widelane_integer_indicator":38,"discontinuity_counter":176,"bias":1640616471},{"code":36,"integer_indicator":207,"widelane_integer_indicator":92,"discontinuity_counter":224,"bias":-744786918},{"code":165,"integer_indicator":47,"widelane_integer_indicator":102,"discontinuity_counter":38,"bias":1966589763},{"code":36,"integer_indicator":169,"widelane_integer_indicator":33,"discontinuity_counter":1,"bias":364366310},{"code":42,"integer_indicator":62,"widelane_integer_indicator":147,"discontinuity_counter":173,"bias":-1839031379},{"code":231,"integer_indicator":167,"widelane_integer_indicator":138,"discontinuity_counter":82,"bias":31817639},{"code":2,"integer_indicator":127,"widelane_integer_indicator":237,"discontinuity_counter":207,"bias":-1619830156},{"code":3,"integer_indicator":42,"widelane_integer_indicator":66,"discontinuity_counter":145,"bias":-83375622},{"code":2,"integer_indicator":75,"widelane_integer_indicator":230,"discontinuity_counter":26,"bias":1077458389},{"code":97,"integer_indicator":88,"widelane_integer_indicator":255,"discontinuity_counter":6,"bias":-883355501},{"code":27,"integer_indicator":68,"widelane_integer_indicator":243,"discontinuity_counter":230,"bias":-1448611273}]}' + raw_packet: VeYF287/0ZqQDNWkqVKx5mLR+RYRHfr1wdse1LHPuyGSOsykQXIx+DQIoSz8pqjofIZWrfGuLI6bgY+4odMPJL3Qwt2YEMtXIryNaL1mnPwW+4gxvJ3e9TGEECKO5FWL3cXrYkprRiQm7/twvHz2jaSWaAfVLBX0wASPGCoVVIgHKnYtF66vgTapDtUCxWI8Dc9pZIFIiPCMgQlyrJeWEdJ/c5cD8v7XDgUifgLXQSawF9LJYSTPXOAadJvTpS9mJkPHN3UkqSEB5sm3FSo+k62tm2KS56eKUqd/5QECf+3PdFpznwMqQpH6yQf7AkvmGtW1OEBhWP8GkxBZyxtE8+Y38qep2/A= + sbp: + crc: '0xf0db' + length: 255 + msg_type: '0x5e6' + payload: 0ZqQDNWkqVKx5mLR+RYRHfr1wdse1LHPuyGSOsykQXIx+DQIoSz8pqjofIZWrfGuLI6bgY+4odMPJL3Qwt2YEMtXIryNaL1mnPwW+4gxvJ3e9TGEECKO5FWL3cXrYkprRiQm7/twvHz2jaSWaAfVLBX0wASPGCoVVIgHKnYtF66vgTapDtUCxWI8Dc9pZIFIiPCMgQlyrJeWEdJ/c5cD8v7XDgUifgLXQSawF9LJYSTPXOAadJvTpS9mJkPHN3UkqSEB5sm3FSo+k62tm2KS56eKUqd/5QECf+3PdFpznwMqQpH6yQf7AkvmGtW1OEBhWP8GkxBZyxtE8+Y38qep + preamble: '0x55' + sender: '0xcedb' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApc.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApc.yaml index 6f2d7e1e6a..e3e65738b2 100644 --- a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApc.yaml +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApc.yaml @@ -4,7 +4,10 @@ package: sbp.ssr tests: - msg: c_decoded_fields: - n_apc: 1 + n_apc: + handle_as: vararray-len + relates_to: apc + value: 1 fields: apc: - pco: diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml new file mode 100644 index 0000000000..89960c8b6c --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrSatelliteApcDepA.yaml @@ -0,0 +1,242 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrSatelliteApcDep +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_apc: + handle_as: vararray-len + relates_to: apc + value: 7 + fields: + apc: + - pco: + - -21547 + - -10498 + - 1236 + pcv: + - 8 + - 33 + - 31 + - 80 + - 21 + - 4 + - 105 + - -31 + - 39 + - -117 + - 124 + - -107 + - 48 + - 15 + - -42 + - -59 + - -115 + - 32 + - 33 + - -121 + - -106 + sat_info: 240 + sid: + code: 169 + sat: 203 + svn: 1102 + - pco: + - 23079 + - -22252 + - 12271 + pcv: + - -103 + - -81 + - 35 + - -111 + - -111 + - 123 + - -62 + - 2 + - 102 + - 74 + - -107 + - 95 + - -85 + - -18 + - -7 + - 7 + - -19 + - -86 + - 125 + - 106 + - -98 + sat_info: 49 + sid: + code: 123 + sat: 148 + svn: 24967 + - pco: + - -7596 + - 31630 + - -9907 + pcv: + - -8 + - 67 + - -41 + - -127 + - 114 + - -118 + - 25 + - -16 + - 10 + - 56 + - 76 + - 61 + - -95 + - -40 + - 22 + - -75 + - -82 + - 33 + - 13 + - -4 + - -20 + sat_info: 181 + sid: + code: 188 + sat: 83 + svn: 7106 + - pco: + - -19478 + - 11484 + - 14804 + pcv: + - 44 + - -83 + - 49 + - 36 + - -119 + - -8 + - -21 + - 97 + - 112 + - -99 + - -117 + - 26 + - 115 + - -64 + - 31 + - 85 + - 127 + - -28 + - 81 + - -4 + - -37 + sat_info: 128 + sid: + code: 196 + sat: 230 + svn: 61399 + - pco: + - -11049 + - 6580 + - -28589 + pcv: + - -9 + - 12 + - 27 + - -57 + - -83 + - 74 + - 23 + - 4 + - -17 + - 103 + - -33 + - -36 + - -117 + - 91 + - 127 + - -42 + - 86 + - 48 + - -53 + - -28 + - 99 + sat_info: 147 + sid: + code: 110 + sat: 249 + svn: 41224 + - pco: + - -21881 + - -9942 + - -5689 + pcv: + - 42 + - -86 + - 78 + - -50 + - 41 + - 43 + - 81 + - -9 + - 99 + - -58 + - -112 + - 2 + - -124 + - 2 + - -32 + - -36 + - -108 + - 58 + - 85 + - -118 + - -46 + sat_info: 159 + sid: + code: 83 + sat: 45 + svn: 64011 + - pco: + - -14290 + - 30340 + - 3569 + pcv: + - 37 + - 62 + - 107 + - -3 + - -66 + - -120 + - 66 + - 9 + - 84 + - -101 + - 86 + - -76 + - 41 + - -60 + - 40 + - 119 + - 101 + - -4 + - -33 + - -112 + - -103 + sat_info: 7 + sid: + code: 158 + sat: 200 + svn: 17310 + module: sbp.ssr + name: MsgSsrSatelliteApcDep + msg_type: '0x604' + raw_json: '{"crc":3378,"length":224,"msg_type":1540,"payload":"y6nwTgTVq/7W1AQIIR9QFQRp4SeLfJUwD9bFjSAhh5aUezGHYSdaFKnvL5mvI5GRe8ICZkqVX6vu+Qftqn1qnlO8tcIbVOKOe03Z+EPXgXKKGfAKOEw9odgWta4hDfzs5sSA1+/qs9ws1DksrTEkifjrYXCdixpzwB9Vf+RR/Nv5bpMIodfUtBlTkPcMG8etShcE72ff3Itbf9ZWMMvkYy1Tnwv6h6oq2cfpKqpOzikrUfdjxpAChALg3JQ6VYrSyJ4HnkMuyIR28Q0lPmv9vohCCVSbVrQpxCh3ZfzfkJk=","preamble":85,"sender":4920,"apc":[{"sid":{"sat":203,"code":169},"sat_info":240,"svn":1102,"pco":[-21547,-10498,1236],"pcv":[8,33,31,80,21,4,105,-31,39,-117,124,-107,48,15,-42,-59,-115,32,33,-121,-106]},{"sid":{"sat":148,"code":123},"sat_info":49,"svn":24967,"pco":[23079,-22252,12271],"pcv":[-103,-81,35,-111,-111,123,-62,2,102,74,-107,95,-85,-18,-7,7,-19,-86,125,106,-98]},{"sid":{"sat":83,"code":188},"sat_info":181,"svn":7106,"pco":[-7596,31630,-9907],"pcv":[-8,67,-41,-127,114,-118,25,-16,10,56,76,61,-95,-40,22,-75,-82,33,13,-4,-20]},{"sid":{"sat":230,"code":196},"sat_info":128,"svn":61399,"pco":[-19478,11484,14804],"pcv":[44,-83,49,36,-119,-8,-21,97,112,-99,-117,26,115,-64,31,85,127,-28,81,-4,-37]},{"sid":{"sat":249,"code":110},"sat_info":147,"svn":41224,"pco":[-11049,6580,-28589],"pcv":[-9,12,27,-57,-83,74,23,4,-17,103,-33,-36,-117,91,127,-42,86,48,-53,-28,99]},{"sid":{"sat":45,"code":83},"sat_info":159,"svn":64011,"pco":[-21881,-9942,-5689],"pcv":[42,-86,78,-50,41,43,81,-9,99,-58,-112,2,-124,2,-32,-36,-108,58,85,-118,-46]},{"sid":{"sat":200,"code":158},"sat_info":7,"svn":17310,"pco":[-14290,30340,3569],"pcv":[37,62,107,-3,-66,-120,66,9,84,-101,86,-76,41,-60,40,119,101,-4,-33,-112,-103]}]}' + raw_packet: VQQGOBPgy6nwTgTVq/7W1AQIIR9QFQRp4SeLfJUwD9bFjSAhh5aUezGHYSdaFKnvL5mvI5GRe8ICZkqVX6vu+Qftqn1qnlO8tcIbVOKOe03Z+EPXgXKKGfAKOEw9odgWta4hDfzs5sSA1+/qs9ws1DksrTEkifjrYXCdixpzwB9Vf+RR/Nv5bpMIodfUtBlTkPcMG8etShcE72ff3Itbf9ZWMMvkYy1Tnwv6h6oq2cfpKqpOzikrUfdjxpAChALg3JQ6VYrSyJ4HnkMuyIR28Q0lPmv9vohCCVSbVrQpxCh3ZfzfkJkyDQ== + sbp: + crc: '0x0d32' + length: 224 + msg_type: '0x604' + payload: y6nwTgTVq/7W1AQIIR9QFQRp4SeLfJUwD9bFjSAhh5aUezGHYSdaFKnvL5mvI5GRe8ICZkqVX6vu+Qftqn1qnlO8tcIbVOKOe03Z+EPXgXKKGfAKOEw9odgWta4hDfzs5sSA1+/qs9ws1DksrTEkifjrYXCdixpzwB9Vf+RR/Nv5bpMIodfUtBlTkPcMG8etShcE72ff3Itbf9ZWMMvkYy1Tnwv6h6oq2cfpKqpOzikrUfdjxpAChALg3JQ6VYrSyJ4HnkMuyIR28Q0lPmv9vohCCVSbVrQpxCh3ZfzfkJk= + preamble: '0x55' + sender: '0x1338' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrection.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrection.yaml index a0f9a7a3af..20d0e8b768 100644 --- a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrection.yaml +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrection.yaml @@ -4,6 +4,11 @@ package: sbp.ssr tests: - msg: + c_decoded_fields: + n_sats: + handle_as: vararray-len + relates_to: stec_sat_list + value: 2 fields: header: time: diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml new file mode 100644 index 0000000000..38eba85c42 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDep.yaml @@ -0,0 +1,224 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrStecCorrectionDep +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_stec_sat_list: + handle_as: vararray-len + relates_to: stec_sat_list + value: 21 + fields: + header: + iod_atmo: 60 + num_msgs: 157 + seq_num: 112 + tile_id: 30066 + tile_set_id: 58526 + time: + tow: 714907186 + wn: 40055 + update_interval: 47 + stec_sat_list: + - stec_coeff: + - -5289 + - -20141 + - 966 + - 2062 + stec_quality_indicator: 70 + sv_id: + constellation: 40 + satId: 132 + - stec_coeff: + - -19147 + - -20902 + - -26889 + - -21446 + stec_quality_indicator: 44 + sv_id: + constellation: 12 + satId: 70 + - stec_coeff: + - 32176 + - -20220 + - 29157 + - 19726 + stec_quality_indicator: 119 + sv_id: + constellation: 179 + satId: 247 + - stec_coeff: + - -8651 + - -27973 + - 23546 + - -10284 + stec_quality_indicator: 23 + sv_id: + constellation: 185 + satId: 153 + - stec_coeff: + - 27486 + - 23329 + - 234 + - -29739 + stec_quality_indicator: 250 + sv_id: + constellation: 107 + satId: 14 + - stec_coeff: + - 18965 + - -22098 + - 22077 + - -29093 + stec_quality_indicator: 50 + sv_id: + constellation: 179 + satId: 95 + - stec_coeff: + - -7898 + - 26002 + - -29879 + - 30008 + stec_quality_indicator: 9 + sv_id: + constellation: 108 + satId: 51 + - stec_coeff: + - -12948 + - 4701 + - -15597 + - -13791 + stec_quality_indicator: 213 + sv_id: + constellation: 37 + satId: 82 + - stec_coeff: + - -17283 + - 14455 + - -27067 + - 19606 + stec_quality_indicator: 178 + sv_id: + constellation: 206 + satId: 87 + - stec_coeff: + - -12215 + - -6072 + - -1528 + - -19765 + stec_quality_indicator: 18 + sv_id: + constellation: 131 + satId: 3 + - stec_coeff: + - 12630 + - -19721 + - 14502 + - 2591 + stec_quality_indicator: 252 + sv_id: + constellation: 163 + satId: 170 + - stec_coeff: + - -23340 + - -24063 + - 4650 + - -22148 + stec_quality_indicator: 241 + sv_id: + constellation: 213 + satId: 119 + - stec_coeff: + - 5944 + - 32142 + - 30760 + - 11587 + stec_quality_indicator: 26 + sv_id: + constellation: 158 + satId: 121 + - stec_coeff: + - 3095 + - 22769 + - -4283 + - 14844 + stec_quality_indicator: 110 + sv_id: + constellation: 235 + satId: 126 + - stec_coeff: + - -21032 + - -19726 + - 1297 + - -22049 + stec_quality_indicator: 201 + sv_id: + constellation: 44 + satId: 93 + - stec_coeff: + - 619 + - -5744 + - 22542 + - -12000 + stec_quality_indicator: 77 + sv_id: + constellation: 3 + satId: 192 + - stec_coeff: + - 10651 + - -2889 + - 21150 + - 26421 + stec_quality_indicator: 123 + sv_id: + constellation: 17 + satId: 1 + - stec_coeff: + - -19165 + - 30229 + - -1282 + - -18382 + stec_quality_indicator: 185 + sv_id: + constellation: 202 + satId: 14 + - stec_coeff: + - -23752 + - 32433 + - 20441 + - -4181 + stec_quality_indicator: 45 + sv_id: + constellation: 31 + satId: 50 + - stec_coeff: + - -13968 + - -29322 + - -23790 + - 9063 + stec_quality_indicator: 238 + sv_id: + constellation: 188 + satId: 237 + - stec_coeff: + - 4737 + - 21877 + - 20414 + - -10286 + stec_quality_indicator: 82 + sv_id: + constellation: 21 + satId: 63 + module: sbp.ssr + name: MsgSsrStecCorrectionDep + msg_type: '0x5fb' + raw_json: '{"crc":45539,"length":245,"msg_type":1531,"payload":"nuRydTKenCp3nJ1wLzyEKEZX61OxxgMOCEYMLDW1Wq73ljqs97N3sH0EseVxDk2ZuRc13ruS+lvU1w5r+l5rIVvqANWLX7MyFUquqT1WW44zbAkm4ZJlSYs4dVIl1WzNXRITwyHKV86yfbx3OEWWlkwDgxJJ0EjoCPrLsqqj/FYx97KmOB8Kd9Xx1KQBoioSfKl5nho4F459KHhDLX7rbhcM8VhF7/w5XSzJ2K3yshEF36nAA01rApDpDlgg0QERe5spt/SeUjVnDsq5I7UVdv76MrgyHy04o7F+2U+r7+287nDJdo0So2cjPxVSgRJ1Vb5P0tc=","preamble":85,"sender":38860,"header":{"tile_set_id":58526,"tile_id":30066,"time":{"tow":714907186,"wn":40055},"num_msgs":157,"seq_num":112,"update_interval":47,"iod_atmo":60},"stec_sat_list":[{"sv_id":{"satId":132,"constellation":40},"stec_quality_indicator":70,"stec_coeff":[-5289,-20141,966,2062]},{"sv_id":{"satId":70,"constellation":12},"stec_quality_indicator":44,"stec_coeff":[-19147,-20902,-26889,-21446]},{"sv_id":{"satId":247,"constellation":179},"stec_quality_indicator":119,"stec_coeff":[32176,-20220,29157,19726]},{"sv_id":{"satId":153,"constellation":185},"stec_quality_indicator":23,"stec_coeff":[-8651,-27973,23546,-10284]},{"sv_id":{"satId":14,"constellation":107},"stec_quality_indicator":250,"stec_coeff":[27486,23329,234,-29739]},{"sv_id":{"satId":95,"constellation":179},"stec_quality_indicator":50,"stec_coeff":[18965,-22098,22077,-29093]},{"sv_id":{"satId":51,"constellation":108},"stec_quality_indicator":9,"stec_coeff":[-7898,26002,-29879,30008]},{"sv_id":{"satId":82,"constellation":37},"stec_quality_indicator":213,"stec_coeff":[-12948,4701,-15597,-13791]},{"sv_id":{"satId":87,"constellation":206},"stec_quality_indicator":178,"stec_coeff":[-17283,14455,-27067,19606]},{"sv_id":{"satId":3,"constellation":131},"stec_quality_indicator":18,"stec_coeff":[-12215,-6072,-1528,-19765]},{"sv_id":{"satId":170,"constellation":163},"stec_quality_indicator":252,"stec_coeff":[12630,-19721,14502,2591]},{"sv_id":{"satId":119,"constellation":213},"stec_quality_indicator":241,"stec_coeff":[-23340,-24063,4650,-22148]},{"sv_id":{"satId":121,"constellation":158},"stec_quality_indicator":26,"stec_coeff":[5944,32142,30760,11587]},{"sv_id":{"satId":126,"constellation":235},"stec_quality_indicator":110,"stec_coeff":[3095,22769,-4283,14844]},{"sv_id":{"satId":93,"constellation":44},"stec_quality_indicator":201,"stec_coeff":[-21032,-19726,1297,-22049]},{"sv_id":{"satId":192,"constellation":3},"stec_quality_indicator":77,"stec_coeff":[619,-5744,22542,-12000]},{"sv_id":{"satId":1,"constellation":17},"stec_quality_indicator":123,"stec_coeff":[10651,-2889,21150,26421]},{"sv_id":{"satId":14,"constellation":202},"stec_quality_indicator":185,"stec_coeff":[-19165,30229,-1282,-18382]},{"sv_id":{"satId":50,"constellation":31},"stec_quality_indicator":45,"stec_coeff":[-23752,32433,20441,-4181]},{"sv_id":{"satId":237,"constellation":188},"stec_quality_indicator":238,"stec_coeff":[-13968,-29322,-23790,9063]},{"sv_id":{"satId":63,"constellation":21},"stec_quality_indicator":82,"stec_coeff":[4737,21877,20414,-10286]}]}' + raw_packet: VfsFzJf1nuRydTKenCp3nJ1wLzyEKEZX61OxxgMOCEYMLDW1Wq73ljqs97N3sH0EseVxDk2ZuRc13ruS+lvU1w5r+l5rIVvqANWLX7MyFUquqT1WW44zbAkm4ZJlSYs4dVIl1WzNXRITwyHKV86yfbx3OEWWlkwDgxJJ0EjoCPrLsqqj/FYx97KmOB8Kd9Xx1KQBoioSfKl5nho4F459KHhDLX7rbhcM8VhF7/w5XSzJ2K3yshEF36nAA01rApDpDlgg0QERe5spt/SeUjVnDsq5I7UVdv76MrgyHy04o7F+2U+r7+287nDJdo0So2cjPxVSgRJ1Vb5P0tfjsQ== + sbp: + crc: '0xb1e3' + length: 245 + msg_type: '0x5fb' + payload: nuRydTKenCp3nJ1wLzyEKEZX61OxxgMOCEYMLDW1Wq73ljqs97N3sH0EseVxDk2ZuRc13ruS+lvU1w5r+l5rIVvqANWLX7MyFUquqT1WW44zbAkm4ZJlSYs4dVIl1WzNXRITwyHKV86yfbx3OEWWlkwDgxJJ0EjoCPrLsqqj/FYx97KmOB8Kd9Xx1KQBoioSfKl5nho4F459KHhDLX7rbhcM8VhF7/w5XSzJ2K3yshEF36nAA01rApDpDlgg0QERe5spt/SeUjVnDsq5I7UVdv76MrgyHy04o7F+2U+r7+287nDJdo0So2cjPxVSgRJ1Vb5P0tc= + preamble: '0x55' + sender: '0x97cc' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml new file mode 100644 index 0000000000..c8b95464c8 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrStecCorrectionDepA.yaml @@ -0,0 +1,231 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrStecCorrectionDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + c_decoded_fields: + n_stec_sat_list: + handle_as: vararray-len + relates_to: stec_sat_list + value: 22 + fields: + header: + iod_atmo: 4 + num_msgs: 147 + seq_num: 123 + time: + tow: 3905179974 + wn: 11193 + update_interval: 39 + stec_sat_list: + - stec_coeff: + - -1951 + - -9854 + - 27353 + - 3130 + stec_quality_indicator: 111 + sv_id: + constellation: 19 + satId: 126 + - stec_coeff: + - 24401 + - 4182 + - 21543 + - -12060 + stec_quality_indicator: 171 + sv_id: + constellation: 230 + satId: 65 + - stec_coeff: + - -13469 + - -18883 + - 32066 + - 971 + stec_quality_indicator: 219 + sv_id: + constellation: 81 + satId: 201 + - stec_coeff: + - 32220 + - 5436 + - -9635 + - -24841 + stec_quality_indicator: 100 + sv_id: + constellation: 44 + satId: 193 + - stec_coeff: + - 3718 + - 12497 + - -10482 + - -27495 + stec_quality_indicator: 129 + sv_id: + constellation: 93 + satId: 207 + - stec_coeff: + - -4940 + - -13875 + - 801 + - -13066 + stec_quality_indicator: 225 + sv_id: + constellation: 72 + satId: 147 + - stec_coeff: + - -15868 + - -2369 + - -9396 + - -16609 + stec_quality_indicator: 98 + sv_id: + constellation: 3 + satId: 19 + - stec_coeff: + - -1265 + - 4897 + - 13920 + - -28102 + stec_quality_indicator: 177 + sv_id: + constellation: 79 + satId: 113 + - stec_coeff: + - 5448 + - -11359 + - 5574 + - 28654 + stec_quality_indicator: 249 + sv_id: + constellation: 100 + satId: 210 + - stec_coeff: + - -10783 + - 18179 + - 16371 + - -5055 + stec_quality_indicator: 227 + sv_id: + constellation: 36 + satId: 107 + - stec_coeff: + - 4009 + - 1462 + - -19216 + - 31241 + stec_quality_indicator: 0 + sv_id: + constellation: 77 + satId: 92 + - stec_coeff: + - 26727 + - -16898 + - 28241 + - 12546 + stec_quality_indicator: 6 + sv_id: + constellation: 232 + satId: 86 + - stec_coeff: + - 12855 + - 1461 + - 20603 + - -3023 + stec_quality_indicator: 216 + sv_id: + constellation: 84 + satId: 202 + - stec_coeff: + - -6492 + - 16952 + - -22404 + - -29893 + stec_quality_indicator: 125 + sv_id: + constellation: 188 + satId: 224 + - stec_coeff: + - -10053 + - -24897 + - 23629 + - -710 + stec_quality_indicator: 51 + sv_id: + constellation: 118 + satId: 106 + - stec_coeff: + - -26103 + - -9539 + - -11971 + - 20993 + stec_quality_indicator: 165 + sv_id: + constellation: 150 + satId: 132 + - stec_coeff: + - -18891 + - -16272 + - -22578 + - -2915 + stec_quality_indicator: 23 + sv_id: + constellation: 196 + satId: 181 + - stec_coeff: + - 15833 + - 24920 + - -13879 + - -1206 + stec_quality_indicator: 189 + sv_id: + constellation: 1 + satId: 35 + - stec_coeff: + - 14008 + - 18996 + - 2798 + - 5761 + stec_quality_indicator: 104 + sv_id: + constellation: 14 + satId: 217 + - stec_coeff: + - -25256 + - -15330 + - 6831 + - 8780 + stec_quality_indicator: 109 + sv_id: + constellation: 226 + satId: 178 + - stec_coeff: + - 3304 + - -2893 + - -25841 + - -13628 + stec_quality_indicator: 154 + sv_id: + constellation: 220 + satId: 116 + - stec_coeff: + - -10742 + - 10098 + - 7413 + - 17645 + stec_quality_indicator: 115 + sv_id: + constellation: 70 + satId: 72 + module: sbp.ssr + name: MsgSsrStecCorrectionDepA + msg_type: '0x5eb' + raw_json: '{"crc":39816,"length":252,"msg_type":1515,"payload":"RlHE6Lkrk3snBH4Tb2H4gtnZajoMQearUV9WECdU5NDJUdtjyz22Qn3LA8EsZNx9PBVd2veez12Bhg7RMA7XmZSTSOG07M3JIQP2zBMDYgTCv/ZM2x+/cU+xD/shE2A2OpLSZPlIFaHTxhXub2sk4+HVA0fzP0HsXE0AqQ+2BfC0CXpW6AZnaP69UW4CMcpU2DcytQV7UDH04Lx9pOY4QnyoO4tqdjO72L+eTVw6/YSWpQmavdo90QFStcQXNbZwwM6nnfQjAb3ZPVhhyclK+9kOaLg2NEruCoEWsuJtWJ0exK8aTCJ03JroDLP0D5vEykhGcwrWcif1HO1E","preamble":85,"sender":1831,"header":{"time":{"tow":3905179974,"wn":11193},"num_msgs":147,"seq_num":123,"update_interval":39,"iod_atmo":4},"stec_sat_list":[{"sv_id":{"satId":126,"constellation":19},"stec_quality_indicator":111,"stec_coeff":[-1951,-9854,27353,3130]},{"sv_id":{"satId":65,"constellation":230},"stec_quality_indicator":171,"stec_coeff":[24401,4182,21543,-12060]},{"sv_id":{"satId":201,"constellation":81},"stec_quality_indicator":219,"stec_coeff":[-13469,-18883,32066,971]},{"sv_id":{"satId":193,"constellation":44},"stec_quality_indicator":100,"stec_coeff":[32220,5436,-9635,-24841]},{"sv_id":{"satId":207,"constellation":93},"stec_quality_indicator":129,"stec_coeff":[3718,12497,-10482,-27495]},{"sv_id":{"satId":147,"constellation":72},"stec_quality_indicator":225,"stec_coeff":[-4940,-13875,801,-13066]},{"sv_id":{"satId":19,"constellation":3},"stec_quality_indicator":98,"stec_coeff":[-15868,-2369,-9396,-16609]},{"sv_id":{"satId":113,"constellation":79},"stec_quality_indicator":177,"stec_coeff":[-1265,4897,13920,-28102]},{"sv_id":{"satId":210,"constellation":100},"stec_quality_indicator":249,"stec_coeff":[5448,-11359,5574,28654]},{"sv_id":{"satId":107,"constellation":36},"stec_quality_indicator":227,"stec_coeff":[-10783,18179,16371,-5055]},{"sv_id":{"satId":92,"constellation":77},"stec_quality_indicator":0,"stec_coeff":[4009,1462,-19216,31241]},{"sv_id":{"satId":86,"constellation":232},"stec_quality_indicator":6,"stec_coeff":[26727,-16898,28241,12546]},{"sv_id":{"satId":202,"constellation":84},"stec_quality_indicator":216,"stec_coeff":[12855,1461,20603,-3023]},{"sv_id":{"satId":224,"constellation":188},"stec_quality_indicator":125,"stec_coeff":[-6492,16952,-22404,-29893]},{"sv_id":{"satId":106,"constellation":118},"stec_quality_indicator":51,"stec_coeff":[-10053,-24897,23629,-710]},{"sv_id":{"satId":132,"constellation":150},"stec_quality_indicator":165,"stec_coeff":[-26103,-9539,-11971,20993]},{"sv_id":{"satId":181,"constellation":196},"stec_quality_indicator":23,"stec_coeff":[-18891,-16272,-22578,-2915]},{"sv_id":{"satId":35,"constellation":1},"stec_quality_indicator":189,"stec_coeff":[15833,24920,-13879,-1206]},{"sv_id":{"satId":217,"constellation":14},"stec_quality_indicator":104,"stec_coeff":[14008,18996,2798,5761]},{"sv_id":{"satId":178,"constellation":226},"stec_quality_indicator":109,"stec_coeff":[-25256,-15330,6831,8780]},{"sv_id":{"satId":116,"constellation":220},"stec_quality_indicator":154,"stec_coeff":[3304,-2893,-25841,-13628]},{"sv_id":{"satId":72,"constellation":70},"stec_quality_indicator":115,"stec_coeff":[-10742,10098,7413,17645]}]}' + raw_packet: VesFJwf8RlHE6Lkrk3snBH4Tb2H4gtnZajoMQearUV9WECdU5NDJUdtjyz22Qn3LA8EsZNx9PBVd2veez12Bhg7RMA7XmZSTSOG07M3JIQP2zBMDYgTCv/ZM2x+/cU+xD/shE2A2OpLSZPlIFaHTxhXub2sk4+HVA0fzP0HsXE0AqQ+2BfC0CXpW6AZnaP69UW4CMcpU2DcytQV7UDH04Lx9pOY4QnyoO4tqdjO72L+eTVw6/YSWpQmavdo90QFStcQXNbZwwM6nnfQjAb3ZPVhhyclK+9kOaLg2NEruCoEWsuJtWJ0exK8aTCJ03JroDLP0D5vEykhGcwrWcif1HO1EiJs= + sbp: + crc: '0x9b88' + length: 252 + msg_type: '0x5eb' + payload: RlHE6Lkrk3snBH4Tb2H4gtnZajoMQearUV9WECdU5NDJUdtjyz22Qn3LA8EsZNx9PBVd2veez12Bhg7RMA7XmZSTSOG07M3JIQP2zBMDYgTCv/ZM2x+/cU+xD/shE2A2OpLSZPlIFaHTxhXub2sk4+HVA0fzP0HsXE0AqQ+2BfC0CXpW6AZnaP69UW4CMcpU2DcytQV7UDH04Lx9pOY4QnyoO4tqdjO72L+eTVw6/YSWpQmavdo90QFStcQXNbZwwM6nnfQjAb3ZPVhhyclK+9kOaLg2NEruCoEWsuJtWJ0exK8aTCJ03JroDLP0D5vEykhGcwrWcif1HO1E + preamble: '0x55' + sender: '0x0727' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml new file mode 100644 index 0000000000..6c911be7b4 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_MsgSsrTileDefinitionDepA.yaml @@ -0,0 +1,28 @@ +description: Unit tests for swiftnav.sbp.ssr MsgSsrTileDefinitionDepA +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +tests: + +- msg: + fields: + bitmask: 11259375 + cols: 48917 + corner_nw_lat: -18168 + corner_nw_lon: -19191 + rows: 36863 + spacing_lat: 61602 + spacing_lon: 4929 + tile_id: 63410 + tile_set_id: 48697 + module: sbp.ssr + name: MsgSsrTileDefinitionDepA + msg_type: '0x5f6' + raw_json: '{"crc":39489,"length":24,"msg_type":1526,"payload":"Ob6y9wi5CbWi8EET/48Vv+/NqwAAAAAA","preamble":85,"sender":34248,"tile_set_id":48697,"tile_id":63410,"corner_nw_lat":-18168,"corner_nw_lon":-19191,"spacing_lat":61602,"spacing_lon":4929,"rows":36863,"cols":48917,"bitmask":11259375}' + raw_packet: VfYFyIUYOb6y9wi5CbWi8EET/48Vv+/NqwAAAAAAQZo= + sbp: + crc: '0x9a41' + length: 24 + msg_type: '0x5f6' + payload: Ob6y9wi5CbWi8EET/48Vv+/NqwAAAAAA + preamble: '0x55' + sender: '0x85c8' diff --git a/spec/tests/yaml/swiftnav/sbp/ssr/test_ssr_structs.yaml b/spec/tests/yaml/swiftnav/sbp/ssr/test_ssr_structs.yaml new file mode 100644 index 0000000000..3a8c994573 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/ssr/test_ssr_structs.yaml @@ -0,0 +1,217 @@ +description: Unit tests for swiftnav.sbp.ssr free structs +generated_on: 2023-11-15 # manually generated +package: sbp.ssr +struct_tests: + + - encoded: uSqR + fields: + code: 185 + value: -28374 + module: sbp.ssr + name: CodeBiasesContent + - encoded: UOYo+sI+jAs= + fields: + code: 80 + integer_indicator: 230 + widelane_integer_indicator: 40 + discontinuity_counter: 250 + bias: 193740482 + module: sbp.ssr + name: PhaseBiasesContent + - encoded: AGWw6CuT/7VJ4AbHV8M= + fields: + tile_set_id: 25856 + tile_id: 59568 + time: + wn: 57417 + tow: 3053425451 + num_msgs: 6 + seq_num: 199 + update_interval: 87 + iod_atmo: 195 + module: sbp.ssr + name: StecHeader + - encoded: GaQtzqxwK/UU+cAJot2Qw3o= + fields: + tile_set_id: 42009 + tile_id: 52781 + time: + wn: 63764 + tow: 4113264812 + num_msgs: 2496 + seq_num: 56738 + update_interval: 144 + iod_atmo: 195 + tropo_quality_indicator: 122 + module: sbp.ssr + name: GriddedCorrectionHeader + - encoded: YMGowa+trxOEZF4= + fields: + sv_id: + satId: 96 + constellation: 193 + stec_quality_indicator: 168 + stec_coeff[0]: -20543 + stec_coeff[1]: -20563 + stec_coeff[2]: -31725 + stec_coeff[3]: 24164 + module: sbp.ssr + name: StecSatElement + - encoded: ezxL + fields: + hydro: 15483 + wet: 75 + module: sbp.ssr + name: TroposphericDelayCorrectionNoStd + - encoded: EX/wJg== + fields: + hydro: 32529 + wet: -16 + stddev: 38 + module: sbp.ssr + name: TroposphericDelayCorrection + - encoded: ZWdEzw== + fields: + sv_id: + constellation: 103 + satId: 101 + residual: -12476 + module: sbp.ssr + name: StecResidualNoStd + - encoded: qfUuZgc= + fields: + sv_id: + constellation: 245 + satId: 169 + residual: 26158 + stddev: 7 + module: sbp.ssr + name: StecResidual + - encoded: sCh/OXKMKM3xBw== + fields: + time: + wn: 35954 + tow: 964634800 + num_msgs: 40 + seq_num: 205 + update_interval: 241 + sol_id: 7 + module: sbp.ssr + name: BoundsHeader + - encoded: U1imUFmApzQ8 + fields: + stec_residual: + stddev: 89 + residual: 20646 + sv_id: + satId: 83 + constellation: 88 + stec_bound_mu: 128 + stec_bound_sig: 167 + stec_bound_mu_dot: 52 + stec_bound_sig_dot: 60 + module: sbp.ssr + name: StecSatElementIntegrity + - encoded: zw2+pHHVIA25VRE4cSKxyu2y7r5KwO2mlL96byvd8U4= + fields: + sid: + sat: 207 + code: 13 + sat_info: 190 + svn: 29092 + pco: + - 8405 + - -18163 + - 4437 + pcv: + - 56 + - 113 + - 34 + - -79 + - -54 + - -19 + - -78 + - -18 + - -66 + - 74 + - -64 + - -19 + - -90 + - -108 + - -65 + - 122 + - 111 + - 43 + - -35 + - -15 + - 78 + module: sbp.ssr + name: SatelliteApc + - encoded: EeSjLFbwuaNpTA== + fields: + time: + wn: 61526 + tow: 748938257 + num_msgs: 185 + seq_num: 163 + update_interval: 105 + iod_atmo: 76 + module: sbp.ssr + name: StecHeaderDepA + - encoded: CWzfvcB7iMUlmdfHhw== + fields: + time: + tow: 3185536009 + wn: 31680 + num_msgs: 50568 + seq_num: 39205 + update_interval: 215 + iod_atmo: 199 + tropo_quality_indicator: 135 + module: sbp.ssr + name: GriddedCorrectionHeaderDepA + - encoded: 8OafFZZjZNnH + fields: + region_size_inverse: 240 + area_width: 40934 + lat_nw_corner_enc: 38421 + lon_nw_corner_enc: 25699 + num_msgs: 217 + seq_num: 199 + module: sbp.ssr + name: GridDefinitionHeaderDepA + - encoded: 8zbSPec8e+vt + fields: + sat_id: 243 + orb_radial_bound_mu: 54 + orb_along_bound_mu: 210 + orb_cross_bound_mu: 61 + orb_radial_bound_sig: 231 + orb_along_bound_sig: 60 + orb_cross_bound_sig: 123 + clock_bound_mu: 235 + clock_bound_sig: 237 + module: sbp.ssr + name: OrbitClockBound + - encoded: 6CYAVwB2 + fields: + sat_id: 232 + signal_id: 38 + code_bias_bound_mu: 0 + code_bias_bound_sig: 87 + phase_bias_bound_mu: 0 + phase_bias_bound_sig: 118 + module: sbp.ssr + name: CodePhaseBiasesSatSig + - encoded: bHDul2NSRT8= + fields: + orb_radial_bound_mu_dot: 108 + orb_along_bound_mu_dot: 112 + orb_cross_bound_mu_dot: 238 + orb_radial_bound_sig_dot: 151 + orb_along_bound_sig_dot: 99 + orb_cross_bound_sig_dot: 82 + clock_bound_mu_dot: 69 + clock_bound_sig_dot: 63 + module: sbp.ssr + name: OrbitClockBoundDegradation diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml new file mode 100644 index 0000000000..a9c6264a5e --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetry.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.system MsgCsacTelemetry +generated_on: 2023-11-15 # manually generated +package: sbp.system +tests: + +- msg: + c_decoded_fields: + telemetry: + handle_as: encoded-string + encoded_len: 9 + text: some data + fn_prefix: sbp_msg_csac_telemetry_telemetry + fields: + id: 105 + telemetry: some data + module: sbp.system + name: MsgCsacTelemetry + msg_type: '0xff04' + raw_json: '{"preamble":85,"msg_type":65284,"sender":43508,"length":10,"payload":"aXNvbWUgZGF0YQ==","crc":24293,"id":105,"telemetry":"some data"}' + raw_packet: VQT/9KkKaXNvbWUgZGF0YeVe + sbp: + crc: '0x5ee5' + length: 10 + msg_type: '0xff04' + payload: aXNvbWUgZGF0YQ== + preamble: '0x55' + sender: '0xa9f4' diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml new file mode 100644 index 0000000000..89116a6320 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgCsacTelemetryLabels.yaml @@ -0,0 +1,27 @@ +description: Unit tests for swiftnav.sbp.system MsgCsacTelemetryLabels +generated_on: 2023-11-15 # manually generated +package: sbp.system +tests: + +- msg: + c_decoded_fields: + telemetry_labels: + handle_as: encoded-string + encoded_len: 11 + fn_prefix: sbp_msg_csac_telemetry_labels_telemetry_labels + text: some labels + fields: + id: 186 + telemetry_labels: some labels + module: sbp.system + name: MsgCsacTelemetryLabels + msg_type: '0xff05' + raw_json: '{"preamble":85,"msg_type":65285,"sender":51291,"length":12,"payload":"unNvbWUgbGFiZWxz","crc":60502,"id":186,"telemetry_labels":"some labels"}' + raw_packet: VQX/W8gMunNvbWUgbGFiZWxzVuw= + sbp: + crc: '0xec56' + length: 12 + msg_type: '0xff05' + payload: unNvbWUgbGFiZWxz + preamble: '0x55' + sender: '0xc85b' diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml new file mode 100644 index 0000000000..a1755cc0fb --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgGnssTimeOffset.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.system MsgGnssTimeOffset +generated_on: 2023-11-15 # manually generated +package: sbp.system +tests: + +- msg: + fields: + flags: 221 + microseconds: 9494 + milliseconds: 1728664402 + weeks: 14857 + module: sbp.system + name: MsgGnssTimeOffset + msg_type: '0xff07' + raw_json: '{"preamble":85,"msg_type":65287,"sender":3862,"length":9,"payload":"CTpSUwlnFiXd","crc":25684,"weeks":14857,"milliseconds":1728664402,"microseconds":9494,"flags":221}' + raw_packet: VQf/Fg8JCTpSUwlnFiXdVGQ= + sbp: + crc: '0x6454' + length: 9 + msg_type: '0xff07' + payload: CTpSUwlnFiXd + preamble: '0x55' + sender: '0x0f16' diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgGroupMeta.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgGroupMeta.yaml index f078e44392..1ba1379acc 100644 --- a/spec/tests/yaml/swiftnav/sbp/system/test_MsgGroupMeta.yaml +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgGroupMeta.yaml @@ -5,6 +5,11 @@ package: sbp.system tests: - msg: + c_decoded_fields: + n_group_msgs: + handle_as: vararray-len + relates_to: group_msgs + value: 3 # includes group_meta itself fields: group_id: 1 flags: 0b00000010 # gnss+ins (fuzed) @@ -28,6 +33,11 @@ tests: sender: '0xEEEE' - msg: + c_decoded_fields: + n_group_msgs: + handle_as: vararray-len + relates_to: group_msgs + value: 14 fields: group_id: 1 flags: 1 diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml new file mode 100644 index 0000000000..9a043f959e --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgPpsTime.yaml @@ -0,0 +1,21 @@ +description: Unit tests for swiftnav.sbp.system MsgPpsTime +generated_on: 2023-11-15 # manually generated +package: sbp.system +tests: + +- msg: + fields: + flags: 255 + time: 690508632716 + module: sbp.system + name: MsgPpsTime + msg_type: '0xff08' + raw_json: '{"preamble":85,"msg_type":65288,"sender":53726,"length":9,"payload":"jJKFxaAAAAD/","crc":38269,"time":690508632716,"flags":255}' + raw_packet: VQj/3tEJjJKFxaAAAAD/fZU= + sbp: + crc: '0x957d' + length: 9 + msg_type: '0xff08' + payload: jJKFxaAAAAD/ + preamble: '0x55' + sender: '0xd1de' diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusJournal.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusJournal.yaml index 43ccf62f38..ef65e2574e 100644 --- a/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusJournal.yaml +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusJournal.yaml @@ -4,7 +4,10 @@ package: sbp.system tests: - msg: c_decoded_fields: - n_journal: 3 + n_journal: + handle_as: vararray-len + relates_to: journal + value: 3 fields: reporting_system: 1 sbp_version: 1025 @@ -40,7 +43,10 @@ tests: sender: '0x88D3' - msg: c_decoded_fields: - n_journal: 1 + n_journal: + handle_as: vararray-len + relates_to: journal + value: 1 fields: journal: - report: diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml new file mode 100644 index 0000000000..3a49b6dd90 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_MsgStatusReport.yaml @@ -0,0 +1,209 @@ +description: Unit tests for swiftnav.sbp.system MsgStatusReport +generated_on: 2023-11-15 # manually generated +package: sbp.system +tests: + +- msg: + c_decoded_fields: + n_status: + handle_as: vararray-len + relates_to: status + value: 60 + fields: + reporting_system: 64850 + sbp_version: 24497 + sequence: 1519336451 + status: + - component: 52215 + generic: 221 + specific: 198 + - component: 53148 + generic: 217 + specific: 238 + - component: 34978 + generic: 154 + specific: 11 + - component: 60530 + generic: 134 + specific: 235 + - component: 34060 + generic: 9 + specific: 30 + - component: 37295 + generic: 26 + specific: 114 + - component: 5335 + generic: 146 + specific: 249 + - component: 13878 + generic: 133 + specific: 193 + - component: 47722 + generic: 210 + specific: 183 + - component: 33024 + generic: 5 + specific: 248 + - component: 38369 + generic: 135 + specific: 127 + - component: 6658 + generic: 88 + specific: 92 + - component: 26378 + generic: 73 + specific: 3 + - component: 17511 + generic: 76 + specific: 184 + - component: 52769 + generic: 194 + specific: 163 + - component: 7803 + generic: 151 + specific: 176 + - component: 44181 + generic: 184 + specific: 231 + - component: 58998 + generic: 200 + specific: 168 + - component: 28004 + generic: 10 + specific: 233 + - component: 15364 + generic: 247 + specific: 82 + - component: 42711 + generic: 28 + specific: 138 + - component: 11630 + generic: 98 + specific: 218 + - component: 46068 + generic: 126 + specific: 107 + - component: 31836 + generic: 94 + specific: 157 + - component: 47914 + generic: 124 + specific: 6 + - component: 63329 + generic: 160 + specific: 188 + - component: 30830 + generic: 254 + specific: 214 + - component: 13166 + generic: 240 + specific: 164 + - component: 4755 + generic: 74 + specific: 178 + - component: 1091 + generic: 27 + specific: 73 + - component: 16574 + generic: 179 + specific: 146 + - component: 39293 + generic: 192 + specific: 46 + - component: 17098 + generic: 248 + specific: 46 + - component: 41256 + generic: 173 + specific: 242 + - component: 982 + generic: 11 + specific: 1 + - component: 18038 + generic: 162 + specific: 61 + - component: 7090 + generic: 156 + specific: 40 + - component: 29119 + generic: 230 + specific: 200 + - component: 2120 + generic: 215 + specific: 245 + - component: 15182 + generic: 222 + specific: 250 + - component: 8307 + generic: 33 + specific: 30 + - component: 43731 + generic: 145 + specific: 92 + - component: 19357 + generic: 24 + specific: 169 + - component: 14086 + generic: 62 + specific: 8 + - component: 21099 + generic: 140 + specific: 49 + - component: 31411 + generic: 90 + specific: 71 + - component: 22556 + generic: 103 + specific: 51 + - component: 18609 + generic: 93 + specific: 39 + - component: 2964 + generic: 202 + specific: 42 + - component: 23586 + generic: 204 + specific: 102 + - component: 25117 + generic: 249 + specific: 91 + - component: 24454 + generic: 23 + specific: 248 + - component: 5312 + generic: 83 + specific: 195 + - component: 46175 + generic: 54 + specific: 36 + - component: 19386 + generic: 64 + specific: 20 + - component: 34205 + generic: 12 + specific: 149 + - component: 3612 + generic: 185 + specific: 129 + - component: 61285 + generic: 74 + specific: 248 + - component: 7925 + generic: 228 + specific: 88 + - component: 54414 + generic: 53 + specific: 224 + uptime: 1657804265 + module: sbp.system + name: MsgStatusReport + msg_type: '0xfffe' + raw_json: '{"preamble":85,"msg_type":65534,"sender":21510,"length":252,"payload":"Uv2xXwM8j1rpFdBi98vdxpzP2e6iiJoLcuyG6wyFCR6vkRpy1xSS+TY2hcFqutK3AIEF+OGVh38CGlhcCmdJA2dETLghzsKjex6XsJWsuOd25sioZG0K6QQ891LXphyKbi1i2vSzfmtcfF6dKrt8BmH3oLxueP7WbjPwpJMSSrJDBBtJvkCzkn2ZwC7KQvguKKGt8tYDCwF2RqI9shucKL9x5shICNf1Tjve+nMgIR7TqpFcnUsYqQY3PghrUowxs3paRxxYZzOxSF0nlAvKKiJczGYdYvlbhl8X+MAUU8NftDYkuktAFJ2FDJUcDrmBZe9K+PUe5FiO1DXg","crc":42654,"reporting_system":64850,"sbp_version":24497,"sequence":1519336451,"uptime":1657804265,"status":[{"component":52215,"generic":221,"specific":198},{"component":53148,"generic":217,"specific":238},{"component":34978,"generic":154,"specific":11},{"component":60530,"generic":134,"specific":235},{"component":34060,"generic":9,"specific":30},{"component":37295,"generic":26,"specific":114},{"component":5335,"generic":146,"specific":249},{"component":13878,"generic":133,"specific":193},{"component":47722,"generic":210,"specific":183},{"component":33024,"generic":5,"specific":248},{"component":38369,"generic":135,"specific":127},{"component":6658,"generic":88,"specific":92},{"component":26378,"generic":73,"specific":3},{"component":17511,"generic":76,"specific":184},{"component":52769,"generic":194,"specific":163},{"component":7803,"generic":151,"specific":176},{"component":44181,"generic":184,"specific":231},{"component":58998,"generic":200,"specific":168},{"component":28004,"generic":10,"specific":233},{"component":15364,"generic":247,"specific":82},{"component":42711,"generic":28,"specific":138},{"component":11630,"generic":98,"specific":218},{"component":46068,"generic":126,"specific":107},{"component":31836,"generic":94,"specific":157},{"component":47914,"generic":124,"specific":6},{"component":63329,"generic":160,"specific":188},{"component":30830,"generic":254,"specific":214},{"component":13166,"generic":240,"specific":164},{"component":4755,"generic":74,"specific":178},{"component":1091,"generic":27,"specific":73},{"component":16574,"generic":179,"specific":146},{"component":39293,"generic":192,"specific":46},{"component":17098,"generic":248,"specific":46},{"component":41256,"generic":173,"specific":242},{"component":982,"generic":11,"specific":1},{"component":18038,"generic":162,"specific":61},{"component":7090,"generic":156,"specific":40},{"component":29119,"generic":230,"specific":200},{"component":2120,"generic":215,"specific":245},{"component":15182,"generic":222,"specific":250},{"component":8307,"generic":33,"specific":30},{"component":43731,"generic":145,"specific":92},{"component":19357,"generic":24,"specific":169},{"component":14086,"generic":62,"specific":8},{"component":21099,"generic":140,"specific":49},{"component":31411,"generic":90,"specific":71},{"component":22556,"generic":103,"specific":51},{"component":18609,"generic":93,"specific":39},{"component":2964,"generic":202,"specific":42},{"component":23586,"generic":204,"specific":102},{"component":25117,"generic":249,"specific":91},{"component":24454,"generic":23,"specific":248},{"component":5312,"generic":83,"specific":195},{"component":46175,"generic":54,"specific":36},{"component":19386,"generic":64,"specific":20},{"component":34205,"generic":12,"specific":149},{"component":3612,"generic":185,"specific":129},{"component":61285,"generic":74,"specific":248},{"component":7925,"generic":228,"specific":88},{"component":54414,"generic":53,"specific":224}]}' + raw_packet: Vf7/BlT8Uv2xXwM8j1rpFdBi98vdxpzP2e6iiJoLcuyG6wyFCR6vkRpy1xSS+TY2hcFqutK3AIEF+OGVh38CGlhcCmdJA2dETLghzsKjex6XsJWsuOd25sioZG0K6QQ891LXphyKbi1i2vSzfmtcfF6dKrt8BmH3oLxueP7WbjPwpJMSSrJDBBtJvkCzkn2ZwC7KQvguKKGt8tYDCwF2RqI9shucKL9x5shICNf1Tjve+nMgIR7TqpFcnUsYqQY3PghrUowxs3paRxxYZzOxSF0nlAvKKiJczGYdYvlbhl8X+MAUU8NftDYkuktAFJ2FDJUcDrmBZe9K+PUe5FiO1DXgnqY= + sbp: + crc: '0xa69e' + length: 252 + msg_type: '0xfffe' + payload: Uv2xXwM8j1rpFdBi98vdxpzP2e6iiJoLcuyG6wyFCR6vkRpy1xSS+TY2hcFqutK3AIEF+OGVh38CGlhcCmdJA2dETLghzsKjex6XsJWsuOd25sioZG0K6QQ891LXphyKbi1i2vSzfmtcfF6dKrt8BmH3oLxueP7WbjPwpJMSSrJDBBtJvkCzkn2ZwC7KQvguKKGt8tYDCwF2RqI9shucKL9x5shICNf1Tjve+nMgIR7TqpFcnUsYqQY3PghrUowxs3paRxxYZzOxSF0nlAvKKiJczGYdYvlbhl8X+MAUU8NftDYkuktAFJ2FDJUcDrmBZe9K+PUe5FiO1DXg + preamble: '0x55' + sender: '0x5406' diff --git a/spec/tests/yaml/swiftnav/sbp/system/test_system_structs.yaml b/spec/tests/yaml/swiftnav/sbp/system/test_system_structs.yaml new file mode 100644 index 0000000000..2685f071a4 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/system/test_system_structs.yaml @@ -0,0 +1,21 @@ +description: Unit tests for swiftnav.sbp.system free structs +generated_on: 2023-11-15 # manually generated +package: sbp.system +struct_tests: + + - encoded: bdJRag== + fields: + component: 53869 + generic: 81 + specific: 106 + module: sbp.system + name: SubSystemReport + - encoded: frKTSqWyzcs= + fields: + uptime: 1251193470 + report: + specific: 203 + generic: 205 + component: 45733 + module: sbp.system + name: StatusJournalItem diff --git a/spec/tests/yaml/swiftnav/sbp/telemetry/test_MsgTelSv.yaml b/spec/tests/yaml/swiftnav/sbp/telemetry/test_MsgTelSv.yaml index a64f4e070a..ba6ac0ab70 100644 --- a/spec/tests/yaml/swiftnav/sbp/telemetry/test_MsgTelSv.yaml +++ b/spec/tests/yaml/swiftnav/sbp/telemetry/test_MsgTelSv.yaml @@ -4,7 +4,10 @@ package: sbp.telemetry tests: - msg: c_decoded_fields: - n_sv_tel: 1 + n_sv_tel: + handle_as: vararray-len + relates_to: sv_tel + value: 1 fields: n_obs: 16 origin_flags: 1 diff --git a/spec/tests/yaml/swiftnav/sbp/telemetry/test_telemetry_structs.yaml b/spec/tests/yaml/swiftnav/sbp/telemetry/test_telemetry_structs.yaml new file mode 100644 index 0000000000..30f54530df --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/telemetry/test_telemetry_structs.yaml @@ -0,0 +1,20 @@ +description: Unit tests for swiftnav.sbp.telemetry free structs +generated_on: 2023-11-15 # manually generated +package: sbp.telemetry +struct_tests: + + - encoded: QWAXzkS6kyU0BljE + fields: + az: 65 + el: 96 + availability_flags: 23 + pseudorange_residual: 17614 + phase_residual: -27718 + outlier_flags: 37 + ephemeris_flags: 52 + correction_flags: 6 + sid: + sat: 88 + code: 196 + module: sbp.telemetry + name: TelemetrySv diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgMeasurementState.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgMeasurementState.yaml index 58ce116416..d7ad7d4859 100644 --- a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgMeasurementState.yaml +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgMeasurementState.yaml @@ -322,7 +322,10 @@ tests: code: 0 sat: 0 c_decoded_fields: - n_states: 79 + n_states: + handle_as: vararray-len + relates_to: states + value: 79 module: sbp.tracking name: MsgMeasurementState msg_type: '0x61' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml new file mode 100644 index 0000000000..f83a0b3299 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIq.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.tracking MsgTrackingIq +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +tests: + +- msg: + fields: + channel: 145 + corrs: + - I: -9937 + Q: 14319 + - I: 9773 + Q: 22717 + - I: 5023 + Q: 3280 + sid: + code: 203 + sat: 121 + module: sbp.tracking + name: MsgTrackingIq + msg_type: '0x2d' + raw_json: '{"crc":42849,"length":15,"msg_type":45,"payload":"kXnLL9nvNy0mvVifE9AM","preamble":85,"sender":20482,"channel":145,"sid":{"sat":121,"code":203},"corrs":[{"I":-9937,"Q":14319},{"I":9773,"Q":22717},{"I":5023,"Q":3280}]}' + raw_packet: VS0AAlAPkXnLL9nvNy0mvVifE9AMYac= + sbp: + crc: '0xa761' + length: 15 + msg_type: '0x2d' + payload: kXnLL9nvNy0mvVifE9AM + preamble: '0x55' + sender: '0x5002' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml new file mode 100644 index 0000000000..0a5d865744 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepA.yaml @@ -0,0 +1,31 @@ +description: Unit tests for swiftnav.sbp.tracking MsgTrackingIqDepA +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +tests: + +- msg: + fields: + channel: 139 + corrs: + - I: 1621776995 + Q: -1591641785 + - I: 1705169716 + Q: 1675764777 + - I: -267498681 + Q: 1403998854 + sid: + code: 15 + reserved: 0 + sat: 64028 + module: sbp.tracking + name: MsgTrackingIqDepA + msg_type: '0x1c' + raw_json: '{"crc":8721,"length":29,"msg_type":28,"payload":"ixz6DwBjWqpgR3khoTTTomUpJOJjR0sO8IZSr1M=","preamble":85,"sender":17336,"channel":139,"sid":{"sat":64028,"code":15,"reserved":0},"corrs":[{"I":1621776995,"Q":-1591641785},{"I":1705169716,"Q":1675764777},{"I":-267498681,"Q":1403998854}]}' + raw_packet: VRwAuEMdixz6DwBjWqpgR3khoTTTomUpJOJjR0sO8IZSr1MRIg== + sbp: + crc: '0x2211' + length: 29 + msg_type: '0x1c' + payload: ixz6DwBjWqpgR3khoTTTomUpJOJjR0sO8IZSr1M= + preamble: '0x55' + sender: '0x43b8' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml new file mode 100644 index 0000000000..a2f590d923 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingIqDepB.yaml @@ -0,0 +1,30 @@ +description: Unit tests for swiftnav.sbp.tracking MsgTrackingIqDepB +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +tests: + +- msg: + fields: + channel: 45 + corrs: + - I: 261994824 + Q: 409336251 + - I: -525036921 + Q: -795939973 + - I: 353988710 + Q: 1148477617 + sid: + code: 183 + sat: 188 + module: sbp.tracking + name: MsgTrackingIqDepB + msg_type: '0x2c' + raw_json: '{"crc":39414,"length":27,"msg_type":44,"payload":"Lby3SLmdD7v5ZRiHkrTge+uO0GZwGRWxYHRE","preamble":85,"sender":25895,"channel":45,"sid":{"sat":188,"code":183},"corrs":[{"I":261994824,"Q":409336251},{"I":-525036921,"Q":-795939973},{"I":353988710,"Q":1148477617}]}' + raw_packet: VSwAJ2UbLby3SLmdD7v5ZRiHkrTge+uO0GZwGRWxYHRE9pk= + sbp: + crc: '0x99f6' + length: 27 + msg_type: '0x2c' + payload: Lby3SLmdD7v5ZRiHkrTge+uO0GZwGRWxYHRE + preamble: '0x55' + sender: '0x6527' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingState.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingState.yaml index 2782f2eecc..cade92319b 100644 --- a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingState.yaml +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingState.yaml @@ -1,9 +1,344 @@ ---- -description: Unit tests for swiftnav.sbp.tracking MsgTrackingState v0.51. -generated_on: 2015-11-09 15:15:45.758477 +description: Unit tests for swiftnav.sbp.tracking MsgTrackingState +generated_on: 2023-11-15 # manually generated package: sbp.tracking tests: +- msg: + c_decoded_fields: + n_states: + handle_as: vararray-len + relates_to: states + value: 63 + fields: + states: + - cn0: 102 + fcn: 3 + sid: + code: 184 + sat: 117 + - cn0: 141 + fcn: 140 + sid: + code: 106 + sat: 38 + - cn0: 195 + fcn: 90 + sid: + code: 4 + sat: 25 + - cn0: 82 + fcn: 75 + sid: + code: 108 + sat: 246 + - cn0: 163 + fcn: 45 + sid: + code: 127 + sat: 137 + - cn0: 93 + fcn: 187 + sid: + code: 46 + sat: 32 + - cn0: 147 + fcn: 201 + sid: + code: 60 + sat: 153 + - cn0: 208 + fcn: 5 + sid: + code: 29 + sat: 23 + - cn0: 69 + fcn: 219 + sid: + code: 30 + sat: 181 + - cn0: 121 + fcn: 3 + sid: + code: 136 + sat: 254 + - cn0: 215 + fcn: 144 + sid: + code: 98 + sat: 33 + - cn0: 56 + fcn: 14 + sid: + code: 182 + sat: 133 + - cn0: 62 + fcn: 218 + sid: + code: 77 + sat: 169 + - cn0: 249 + fcn: 171 + sid: + code: 84 + sat: 242 + - cn0: 130 + fcn: 131 + sid: + code: 137 + sat: 152 + - cn0: 68 + fcn: 42 + sid: + code: 21 + sat: 193 + - cn0: 227 + fcn: 216 + sid: + code: 227 + sat: 253 + - cn0: 179 + fcn: 210 + sid: + code: 26 + sat: 24 + - cn0: 255 + fcn: 227 + sid: + code: 15 + sat: 19 + - cn0: 200 + fcn: 187 + sid: + code: 75 + sat: 122 + - cn0: 122 + fcn: 218 + sid: + code: 48 + sat: 217 + - cn0: 149 + fcn: 142 + sid: + code: 238 + sat: 187 + - cn0: 212 + fcn: 251 + sid: + code: 55 + sat: 238 + - cn0: 104 + fcn: 194 + sid: + code: 160 + sat: 128 + - cn0: 62 + fcn: 141 + sid: + code: 255 + sat: 113 + - cn0: 39 + fcn: 245 + sid: + code: 69 + sat: 43 + - cn0: 56 + fcn: 108 + sid: + code: 230 + sat: 100 + - cn0: 143 + fcn: 149 + sid: + code: 68 + sat: 247 + - cn0: 70 + fcn: 233 + sid: + code: 101 + sat: 137 + - cn0: 110 + fcn: 38 + sid: + code: 165 + sat: 49 + - cn0: 213 + fcn: 80 + sid: + code: 230 + sat: 218 + - cn0: 128 + fcn: 139 + sid: + code: 179 + sat: 196 + - cn0: 171 + fcn: 196 + sid: + code: 178 + sat: 15 + - cn0: 194 + fcn: 97 + sid: + code: 212 + sat: 8 + - cn0: 99 + fcn: 79 + sid: + code: 233 + sat: 83 + - cn0: 180 + fcn: 31 + sid: + code: 90 + sat: 55 + - cn0: 186 + fcn: 105 + sid: + code: 25 + sat: 5 + - cn0: 111 + fcn: 80 + sid: + code: 224 + sat: 22 + - cn0: 166 + fcn: 106 + sid: + code: 48 + sat: 8 + - cn0: 49 + fcn: 156 + sid: + code: 48 + sat: 4 + - cn0: 146 + fcn: 142 + sid: + code: 19 + sat: 86 + - cn0: 64 + fcn: 115 + sid: + code: 124 + sat: 91 + - cn0: 178 + fcn: 115 + sid: + code: 230 + sat: 28 + - cn0: 242 + fcn: 16 + sid: + code: 131 + sat: 190 + - cn0: 113 + fcn: 182 + sid: + code: 59 + sat: 105 + - cn0: 179 + fcn: 48 + sid: + code: 180 + sat: 192 + - cn0: 211 + fcn: 172 + sid: + code: 31 + sat: 166 + - cn0: 49 + fcn: 140 + sid: + code: 228 + sat: 77 + - cn0: 194 + fcn: 240 + sid: + code: 77 + sat: 128 + - cn0: 58 + fcn: 41 + sid: + code: 194 + sat: 134 + - cn0: 55 + fcn: 129 + sid: + code: 53 + sat: 18 + - cn0: 92 + fcn: 134 + sid: + code: 72 + sat: 91 + - cn0: 56 + fcn: 157 + sid: + code: 224 + sat: 33 + - cn0: 174 + fcn: 224 + sid: + code: 54 + sat: 186 + - cn0: 190 + fcn: 148 + sid: + code: 84 + sat: 82 + - cn0: 67 + fcn: 62 + sid: + code: 54 + sat: 236 + - cn0: 254 + fcn: 57 + sid: + code: 215 + sat: 52 + - cn0: 174 + fcn: 36 + sid: + code: 133 + sat: 16 + - cn0: 17 + fcn: 145 + sid: + code: 172 + sat: 219 + - cn0: 97 + fcn: 111 + sid: + code: 179 + sat: 192 + - cn0: 134 + fcn: 208 + sid: + code: 56 + sat: 207 + - cn0: 226 + fcn: 43 + sid: + code: 17 + sat: 180 + - cn0: 113 + fcn: 140 + sid: + code: 182 + sat: 255 + module: sbp.tracking + name: MsgTrackingState + msg_type: '0x41' + raw_json: '{"crc":28557,"length":252,"msg_type":65,"payload":"dbgDZiZqjI0ZBFrD9mxLUol/LaMgLrtdmTzJkxcdBdC1HttF/ogDeSFikNeFtg44qU3aPvJUq/mYiYOCwRUqRP3j2OMYGtKzEw/j/3pLu8jZMNp6u+6Ole43+9SAoMJocf+NPitF9Sdk5mw490SVj4ll6UYxpSZu2uZQ1cSzi4APssSrCNRhwlPpT2M3Wh+0BRlpuhbgUG8IMGqmBDCcMVYTjpJbfHNAHOZzsr6DEPJpO7ZxwLQws6YfrNNN5IwxgE3wwobCKToSNYE3W0iGXCHgnTi6NuCuUlSUvuw2PkM01zn+EIUkrtuskRHAs29hzzjQhrQRK+L/toxx","preamble":85,"sender":33079,"states":[{"sid":{"sat":117,"code":184},"fcn":3,"cn0":102},{"sid":{"sat":38,"code":106},"fcn":140,"cn0":141},{"sid":{"sat":25,"code":4},"fcn":90,"cn0":195},{"sid":{"sat":246,"code":108},"fcn":75,"cn0":82},{"sid":{"sat":137,"code":127},"fcn":45,"cn0":163},{"sid":{"sat":32,"code":46},"fcn":187,"cn0":93},{"sid":{"sat":153,"code":60},"fcn":201,"cn0":147},{"sid":{"sat":23,"code":29},"fcn":5,"cn0":208},{"sid":{"sat":181,"code":30},"fcn":219,"cn0":69},{"sid":{"sat":254,"code":136},"fcn":3,"cn0":121},{"sid":{"sat":33,"code":98},"fcn":144,"cn0":215},{"sid":{"sat":133,"code":182},"fcn":14,"cn0":56},{"sid":{"sat":169,"code":77},"fcn":218,"cn0":62},{"sid":{"sat":242,"code":84},"fcn":171,"cn0":249},{"sid":{"sat":152,"code":137},"fcn":131,"cn0":130},{"sid":{"sat":193,"code":21},"fcn":42,"cn0":68},{"sid":{"sat":253,"code":227},"fcn":216,"cn0":227},{"sid":{"sat":24,"code":26},"fcn":210,"cn0":179},{"sid":{"sat":19,"code":15},"fcn":227,"cn0":255},{"sid":{"sat":122,"code":75},"fcn":187,"cn0":200},{"sid":{"sat":217,"code":48},"fcn":218,"cn0":122},{"sid":{"sat":187,"code":238},"fcn":142,"cn0":149},{"sid":{"sat":238,"code":55},"fcn":251,"cn0":212},{"sid":{"sat":128,"code":160},"fcn":194,"cn0":104},{"sid":{"sat":113,"code":255},"fcn":141,"cn0":62},{"sid":{"sat":43,"code":69},"fcn":245,"cn0":39},{"sid":{"sat":100,"code":230},"fcn":108,"cn0":56},{"sid":{"sat":247,"code":68},"fcn":149,"cn0":143},{"sid":{"sat":137,"code":101},"fcn":233,"cn0":70},{"sid":{"sat":49,"code":165},"fcn":38,"cn0":110},{"sid":{"sat":218,"code":230},"fcn":80,"cn0":213},{"sid":{"sat":196,"code":179},"fcn":139,"cn0":128},{"sid":{"sat":15,"code":178},"fcn":196,"cn0":171},{"sid":{"sat":8,"code":212},"fcn":97,"cn0":194},{"sid":{"sat":83,"code":233},"fcn":79,"cn0":99},{"sid":{"sat":55,"code":90},"fcn":31,"cn0":180},{"sid":{"sat":5,"code":25},"fcn":105,"cn0":186},{"sid":{"sat":22,"code":224},"fcn":80,"cn0":111},{"sid":{"sat":8,"code":48},"fcn":106,"cn0":166},{"sid":{"sat":4,"code":48},"fcn":156,"cn0":49},{"sid":{"sat":86,"code":19},"fcn":142,"cn0":146},{"sid":{"sat":91,"code":124},"fcn":115,"cn0":64},{"sid":{"sat":28,"code":230},"fcn":115,"cn0":178},{"sid":{"sat":190,"code":131},"fcn":16,"cn0":242},{"sid":{"sat":105,"code":59},"fcn":182,"cn0":113},{"sid":{"sat":192,"code":180},"fcn":48,"cn0":179},{"sid":{"sat":166,"code":31},"fcn":172,"cn0":211},{"sid":{"sat":77,"code":228},"fcn":140,"cn0":49},{"sid":{"sat":128,"code":77},"fcn":240,"cn0":194},{"sid":{"sat":134,"code":194},"fcn":41,"cn0":58},{"sid":{"sat":18,"code":53},"fcn":129,"cn0":55},{"sid":{"sat":91,"code":72},"fcn":134,"cn0":92},{"sid":{"sat":33,"code":224},"fcn":157,"cn0":56},{"sid":{"sat":186,"code":54},"fcn":224,"cn0":174},{"sid":{"sat":82,"code":84},"fcn":148,"cn0":190},{"sid":{"sat":236,"code":54},"fcn":62,"cn0":67},{"sid":{"sat":52,"code":215},"fcn":57,"cn0":254},{"sid":{"sat":16,"code":133},"fcn":36,"cn0":174},{"sid":{"sat":219,"code":172},"fcn":145,"cn0":17},{"sid":{"sat":192,"code":179},"fcn":111,"cn0":97},{"sid":{"sat":207,"code":56},"fcn":208,"cn0":134},{"sid":{"sat":180,"code":17},"fcn":43,"cn0":226},{"sid":{"sat":255,"code":182},"fcn":140,"cn0":113}]}' + raw_packet: VUEAN4H8dbgDZiZqjI0ZBFrD9mxLUol/LaMgLrtdmTzJkxcdBdC1HttF/ogDeSFikNeFtg44qU3aPvJUq/mYiYOCwRUqRP3j2OMYGtKzEw/j/3pLu8jZMNp6u+6Ole43+9SAoMJocf+NPitF9Sdk5mw490SVj4ll6UYxpSZu2uZQ1cSzi4APssSrCNRhwlPpT2M3Wh+0BRlpuhbgUG8IMGqmBDCcMVYTjpJbfHNAHOZzsr6DEPJpO7ZxwLQws6YfrNNN5IwxgE3wwobCKToSNYE3W0iGXCHgnTi6NuCuUlSUvuw2PkM01zn+EIUkrtuskRHAs29hzzjQhrQRK+L/toxxjW8= + sbp: + crc: '0x6f8d' + length: 252 + msg_type: '0x41' + payload: dbgDZiZqjI0ZBFrD9mxLUol/LaMgLrtdmTzJkxcdBdC1HttF/ogDeSFikNeFtg44qU3aPvJUq/mYiYOCwRUqRP3j2OMYGtKzEw/j/3pLu8jZMNp6u+6Ole43+9SAoMJocf+NPitF9Sdk5mw490SVj4ll6UYxpSZu2uZQ1cSzi4APssSrCNRhwlPpT2M3Wh+0BRlpuhbgUG8IMGqmBDCcMVYTjpJbfHNAHOZzsr6DEPJpO7ZxwLQws6YfrNNN5IwxgE3wwobCKToSNYE3W0iGXCHgnTi6NuCuUlSUvuw2PkM01zn+EIUkrtuskRHAs29hzzjQhrQRK+L/toxx + preamble: '0x55' + sender: '0x8137' + - msg: fields: states: @@ -74,7 +409,10 @@ tests: sat: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepB msg_type: '0x13' @@ -170,7 +508,10 @@ tests: sat: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepB msg_type: '0x13' @@ -266,7 +607,10 @@ tests: sat: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepB msg_type: '0x13' @@ -362,7 +706,10 @@ tests: sat: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepB msg_type: '0x13' @@ -458,7 +805,10 @@ tests: sat: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepB msg_type: '0x13' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml new file mode 100644 index 0000000000..cb30026a9a --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDepB.yaml @@ -0,0 +1,193 @@ +description: Unit tests for swiftnav.sbp.tracking MsgTrackingStateDepB +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +tests: + +- msg: + c_decoded_fields: + n_states: + handle_as: vararray-len + relates_to: states + value: 28 + fields: + states: + - cn0: 5856.2001953125 + sid: + code: 63 + reserved: 68 + sat: 58295 + state: 115 + - cn0: 2612.199951171875 + sid: + code: 43 + reserved: 222 + sat: 31151 + state: 255 + - cn0: 2925.199951171875 + sid: + code: 53 + reserved: 20 + sat: 1520 + state: 78 + - cn0: 3198.199951171875 + sid: + code: 66 + reserved: 155 + sat: 60802 + state: 153 + - cn0: 8623.2001953125 + sid: + code: 161 + reserved: 190 + sat: 35058 + state: 53 + - cn0: 5915.2001953125 + sid: + code: 142 + reserved: 149 + sat: 65405 + state: 153 + - cn0: 5412.2001953125 + sid: + code: 31 + reserved: 76 + sat: 24422 + state: 248 + - cn0: 6428.2001953125 + sid: + code: 27 + reserved: 12 + sat: 36211 + state: 131 + - cn0: 3104.199951171875 + sid: + code: 39 + reserved: 23 + sat: 37676 + state: 208 + - cn0: 3686.199951171875 + sid: + code: 49 + reserved: 203 + sat: 64415 + state: 237 + - cn0: 5967.2001953125 + sid: + code: 128 + reserved: 206 + sat: 22486 + state: 70 + - cn0: 5423.2001953125 + sid: + code: 218 + reserved: 19 + sat: 28622 + state: 14 + - cn0: 438.20001220703125 + sid: + code: 54 + reserved: 2 + sat: 53602 + state: 216 + - cn0: 1862.199951171875 + sid: + code: 7 + reserved: 34 + sat: 25477 + state: 200 + - cn0: 5462.2001953125 + sid: + code: 135 + reserved: 46 + sat: 21803 + state: 155 + - cn0: 7454.2001953125 + sid: + code: 171 + reserved: 201 + sat: 21251 + state: 155 + - cn0: 7134.2001953125 + sid: + code: 16 + reserved: 19 + sat: 50475 + state: 121 + - cn0: 3111.199951171875 + sid: + code: 63 + reserved: 176 + sat: 13813 + state: 128 + - cn0: 4297.2001953125 + sid: + code: 153 + reserved: 51 + sat: 15636 + state: 36 + - cn0: 2649.199951171875 + sid: + code: 140 + reserved: 22 + sat: 29778 + state: 46 + - cn0: 941.2000122070312 + sid: + code: 96 + reserved: 143 + sat: 37443 + state: 177 + - cn0: 1539.199951171875 + sid: + code: 201 + reserved: 251 + sat: 41011 + state: 220 + - cn0: 1443.199951171875 + sid: + code: 161 + reserved: 220 + sat: 706 + state: 168 + - cn0: 1074.199951171875 + sid: + code: 125 + reserved: 178 + sat: 2312 + state: 69 + - cn0: 2122.199951171875 + sid: + code: 186 + reserved: 171 + sat: 34580 + state: 185 + - cn0: 9076.2001953125 + sid: + code: 85 + reserved: 170 + sat: 39804 + state: 18 + - cn0: 4781.2001953125 + sid: + code: 255 + reserved: 186 + sat: 52980 + state: 57 + - cn0: 3076.199951171875 + sid: + code: 181 + reserved: 175 + sat: 24007 + state: 165 + module: sbp.tracking + name: MsgTrackingStateDepB + msg_type: '0x13' + raw_json: '{"preamble":85,"msg_type":19,"sender":61938,"length":252,"payload":"c7fjP0SaAbdF/695K94zQyNFTvAFNRQz0zZFmYLtQpsz40dFNfKIob7NvAZGmX3/jpWa2bhF+GZfH0yaIalFg3ONGwya4chF0CyTJxczA0JF7Z/7McszY2ZFRtZXgM6aebpFDs5v2hOaealF2GLRNgKaGdtDyIVjByJmxuhEmytVhy6asapFmwNTq8ma8ehFeSvFEBOa8d5FgPU1P7Azc0JFJBQ9mTOaSYZFLlJ0jBYzkyVFsUOSYI/NTGtE3DOgyftmZsBEqMICodxmZrRERQgJfbJmRoZEuRSHuqszowRFEnybVarN0A1GOfTO/7qaaZVFpcddta8zQ0BF","crc":7174,"states":[{"state":115,"sid":{"sat":58295,"code":63,"reserved":68},"cn0":5856.2001953125},{"state":255,"sid":{"sat":31151,"code":43,"reserved":222},"cn0":2612.199951171875},{"state":78,"sid":{"sat":1520,"code":53,"reserved":20},"cn0":2925.199951171875},{"state":153,"sid":{"sat":60802,"code":66,"reserved":155},"cn0":3198.199951171875},{"state":53,"sid":{"sat":35058,"code":161,"reserved":190},"cn0":8623.2001953125},{"state":153,"sid":{"sat":65405,"code":142,"reserved":149},"cn0":5915.2001953125},{"state":248,"sid":{"sat":24422,"code":31,"reserved":76},"cn0":5412.2001953125},{"state":131,"sid":{"sat":36211,"code":27,"reserved":12},"cn0":6428.2001953125},{"state":208,"sid":{"sat":37676,"code":39,"reserved":23},"cn0":3104.199951171875},{"state":237,"sid":{"sat":64415,"code":49,"reserved":203},"cn0":3686.199951171875},{"state":70,"sid":{"sat":22486,"code":128,"reserved":206},"cn0":5967.2001953125},{"state":14,"sid":{"sat":28622,"code":218,"reserved":19},"cn0":5423.2001953125},{"state":216,"sid":{"sat":53602,"code":54,"reserved":2},"cn0":438.20001220703125},{"state":200,"sid":{"sat":25477,"code":7,"reserved":34},"cn0":1862.199951171875},{"state":155,"sid":{"sat":21803,"code":135,"reserved":46},"cn0":5462.2001953125},{"state":155,"sid":{"sat":21251,"code":171,"reserved":201},"cn0":7454.2001953125},{"state":121,"sid":{"sat":50475,"code":16,"reserved":19},"cn0":7134.2001953125},{"state":128,"sid":{"sat":13813,"code":63,"reserved":176},"cn0":3111.199951171875},{"state":36,"sid":{"sat":15636,"code":153,"reserved":51},"cn0":4297.2001953125},{"state":46,"sid":{"sat":29778,"code":140,"reserved":22},"cn0":2649.199951171875},{"state":177,"sid":{"sat":37443,"code":96,"reserved":143},"cn0":941.2000122070312},{"state":220,"sid":{"sat":41011,"code":201,"reserved":251},"cn0":1539.199951171875},{"state":168,"sid":{"sat":706,"code":161,"reserved":220},"cn0":1443.199951171875},{"state":69,"sid":{"sat":2312,"code":125,"reserved":178},"cn0":1074.199951171875},{"state":185,"sid":{"sat":34580,"code":186,"reserved":171},"cn0":2122.199951171875},{"state":18,"sid":{"sat":39804,"code":85,"reserved":170},"cn0":9076.2001953125},{"state":57,"sid":{"sat":52980,"code":255,"reserved":186},"cn0":4781.2001953125},{"state":165,"sid":{"sat":24007,"code":181,"reserved":175},"cn0":3076.199951171875}]}' + raw_packet: VRMA8vH8c7fjP0SaAbdF/695K94zQyNFTvAFNRQz0zZFmYLtQpsz40dFNfKIob7NvAZGmX3/jpWa2bhF+GZfH0yaIalFg3ONGwya4chF0CyTJxczA0JF7Z/7McszY2ZFRtZXgM6aebpFDs5v2hOaealF2GLRNgKaGdtDyIVjByJmxuhEmytVhy6asapFmwNTq8ma8ehFeSvFEBOa8d5FgPU1P7Azc0JFJBQ9mTOaSYZFLlJ0jBYzkyVFsUOSYI/NTGtE3DOgyftmZsBEqMICodxmZrRERQgJfbJmRoZEuRSHuqszowRFEnybVarN0A1GOfTO/7qaaZVFpcddta8zQ0BFBhw= + sbp: + crc: '0x1c06' + length: 252 + msg_type: '0x13' + payload: c7fjP0SaAbdF/695K94zQyNFTvAFNRQz0zZFmYLtQpsz40dFNfKIob7NvAZGmX3/jpWa2bhF+GZfH0yaIalFg3ONGwya4chF0CyTJxczA0JF7Z/7McszY2ZFRtZXgM6aebpFDs5v2hOaealF2GLRNgKaGdtDyIVjByJmxuhEmytVhy6asapFmwNTq8ma8ehFeSvFEBOa8d5FgPU1P7Azc0JFJBQ9mTOaSYZFLlJ0jBYzkyVFsUOSYI/NTGtE3DOgyftmZsBEqMICodxmZrRERQgJfbJmRoZEuRSHuqszowRFEnybVarN0A1GOfTO/7qaaZVFpcddta8zQ0BF + preamble: '0x55' + sender: '0xf1f2' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml new file mode 100644 index 0000000000..bb578703cd --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgTrackingStateDetailedDepA.yaml @@ -0,0 +1,47 @@ +description: Unit tests for swiftnav.sbp.tracking MsgTrackingStateDetailedDepA +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +tests: + +- msg: + fields: + L: + f: 204 + i: -1601767965 + P: 1044286343 + P_std: 21427 + acceleration: -114 + clock_drift: 23311 + clock_offset: 6012 + cn0: 78 + corr_spacing: 30201 + doppler: 1459556257 + doppler_std: 63677 + lock: 65375 + misc_flags: 62 + nav_flags: 25 + pset_flags: 83 + recv_time: 941247176494 + sid: + code: 59 + sat: 38 + sync_flags: 90 + tot: + ns_residual: -811597120 + tow: 1581737093 + wn: 65492 + tow_flags: 219 + track_flags: 67 + uptime: 3263741727 + module: sbp.tracking + name: MsgTrackingStateDetailedDepA + msg_type: '0x21' + raw_json: '{"crc":25722,"length":57,"msg_type":33,"payload":"Lh+0JtsAAACFZEdewAKgz9T/h4s+PrNT4/WGoMxOX/8mO6EP/1a9+B+/iMJ8Fw9b+XWOWttDGVM+","preamble":85,"sender":28315,"recv_time":941247176494,"tot":{"tow":1581737093,"ns_residual":-811597120,"wn":65492},"P":1044286343,"P_std":21427,"L":{"i":-1601767965,"f":204},"cn0":78,"lock":65375,"sid":{"sat":38,"code":59},"doppler":1459556257,"doppler_std":63677,"uptime":3263741727,"clock_offset":6012,"clock_drift":23311,"corr_spacing":30201,"acceleration":-114,"sync_flags":90,"tow_flags":219,"track_flags":67,"nav_flags":25,"pset_flags":83,"misc_flags":62}' + raw_packet: VSEAm245Lh+0JtsAAACFZEdewAKgz9T/h4s+PrNT4/WGoMxOX/8mO6EP/1a9+B+/iMJ8Fw9b+XWOWttDGVM+emQ= + sbp: + crc: '0x647a' + length: 57 + msg_type: '0x21' + payload: Lh+0JtsAAACFZEdewAKgz9T/h4s+PrNT4/WGoMxOX/8mO6EP/1a9+B+/iMJ8Fw9b+XWOWttDGVM+ + preamble: '0x55' + sender: '0x6e9b' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgtrackingStateDepA.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgtrackingStateDepA.yaml index fd57977f93..03ebc04118 100644 --- a/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgtrackingStateDepA.yaml +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_MsgtrackingStateDepA.yaml @@ -41,7 +41,10 @@ tests: prn: 6 state: 1 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' @@ -99,7 +102,10 @@ tests: prn: 6 state: 1 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' @@ -157,7 +163,10 @@ tests: prn: 6 state: 1 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' @@ -215,7 +224,10 @@ tests: prn: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' @@ -272,7 +284,10 @@ tests: prn: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' @@ -329,7 +344,10 @@ tests: prn: 0 state: 0 c_decoded_fields: - n_states: 11 + n_states: + handle_as: vararray-len + relates_to: states + value: 11 module: sbp.tracking name: MsgTrackingStateDepA msg_type: '0x16' diff --git a/spec/tests/yaml/swiftnav/sbp/tracking/test_tracking_structs.yaml b/spec/tests/yaml/swiftnav/sbp/tracking/test_tracking_structs.yaml new file mode 100644 index 0000000000..14adfb417c --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/tracking/test_tracking_structs.yaml @@ -0,0 +1,55 @@ +description: Unit tests for swiftnav.sbp.tracking free structs +generated_on: 2023-11-15 # manually generated +package: sbp.tracking +struct_tests: + + - encoded: "FgAKLQ==" + fields: + sid: + sat: 22 + code: 0 + fcn: 10 + cn0: 45 + module: sbp.tracking + name: TrackingChannelState + + - encoded: FwEe + fields: + mesid: + sat: 23 + code: 1 + cn0: 30 + module: sbp.tracking + name: MeasurementState + + - encoded: 3ZFyIg== + fields: + I: 37341 + Q: 8818 + module: sbp.tracking + name: TrackingChannelCorrelation + + - encoded: 49loAEB2tjA= + fields: + I: 6871523 + Q: 817264192 + module: sbp.tracking + name: TrackingChannelCorrelationDep + + - encoded: E8MzEzlF + fields: + state: 19 + prn: 195 + cn0: 2961.199951 + module: sbp.tracking + name: TrackingChannelStateDepA + + - encoded: dsML7AAzUxNF + fields: + state: 118 + sid: + sat: 3011 + code: 236 + cn0: 2357.199951 + module: sbp.tracking + name: TrackingChannelStateDepB diff --git a/spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml b/spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml new file mode 100644 index 0000000000..89264bfac7 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/user/test_MsgUserData.yaml @@ -0,0 +1,280 @@ +description: Unit tests for swiftnav.sbp.user MsgUserData +generated_on: 2023-11-15 # manually generated +package: sbp.user +tests: + +- msg: + c_decoded_fields: + n_contents: + handle_as: vararray-len + relates_to: contents + value: 255 + fields: + contents: + - 53 + - 5 + - 172 + - 138 + - 50 + - 49 + - 206 + - 234 + - 149 + - 204 + - 113 + - 31 + - 108 + - 188 + - 179 + - 154 + - 156 + - 167 + - 145 + - 139 + - 42 + - 207 + - 126 + - 242 + - 193 + - 9 + - 58 + - 75 + - 8 + - 135 + - 11 + - 92 + - 131 + - 245 + - 24 + - 90 + - 255 + - 30 + - 58 + - 31 + - 109 + - 148 + - 56 + - 178 + - 140 + - 30 + - 159 + - 70 + - 17 + - 170 + - 50 + - 148 + - 1 + - 99 + - 112 + - 88 + - 217 + - 36 + - 84 + - 34 + - 234 + - 82 + - 144 + - 144 + - 97 + - 96 + - 75 + - 174 + - 58 + - 219 + - 180 + - 148 + - 247 + - 59 + - 2 + - 116 + - 214 + - 114 + - 55 + - 134 + - 54 + - 119 + - 108 + - 128 + - 73 + - 181 + - 20 + - 233 + - 23 + - 23 + - 73 + - 119 + - 136 + - 231 + - 189 + - 26 + - 174 + - 128 + - 93 + - 30 + - 76 + - 45 + - 109 + - 134 + - 81 + - 0 + - 116 + - 158 + - 127 + - 40 + - 133 + - 208 + - 134 + - 127 + - 140 + - 232 + - 183 + - 184 + - 108 + - 6 + - 228 + - 54 + - 238 + - 59 + - 220 + - 30 + - 228 + - 212 + - 50 + - 182 + - 97 + - 20 + - 41 + - 76 + - 227 + - 88 + - 12 + - 95 + - 112 + - 209 + - 183 + - 127 + - 4 + - 165 + - 189 + - 44 + - 239 + - 232 + - 132 + - 9 + - 114 + - 184 + - 249 + - 208 + - 246 + - 194 + - 250 + - 2 + - 97 + - 173 + - 157 + - 202 + - 172 + - 180 + - 150 + - 213 + - 193 + - 177 + - 209 + - 156 + - 20 + - 174 + - 18 + - 73 + - 132 + - 215 + - 115 + - 128 + - 175 + - 169 + - 116 + - 132 + - 100 + - 72 + - 45 + - 25 + - 14 + - 205 + - 213 + - 145 + - 68 + - 137 + - 249 + - 54 + - 40 + - 174 + - 215 + - 148 + - 166 + - 190 + - 63 + - 118 + - 6 + - 165 + - 212 + - 74 + - 68 + - 200 + - 38 + - 139 + - 212 + - 112 + - 45 + - 167 + - 236 + - 255 + - 106 + - 92 + - 132 + - 59 + - 61 + - 233 + - 3 + - 246 + - 158 + - 83 + - 134 + - 246 + - 154 + - 17 + - 0 + - 6 + - 56 + - 216 + - 19 + - 216 + - 70 + - 71 + - 161 + - 184 + - 5 + - 177 + - 45 + - 37 + - 98 + - 56 + - 149 + - 0 + - 73 + - 221 + - 105 + - 239 + - 168 + - 205 + - 85 + module: sbp.user + name: MsgUserData + msg_type: '0x800' + raw_json: '{"crc":62801,"length":255,"msg_type":2048,"payload":"NQWsijIxzuqVzHEfbLyzmpynkYsqz37ywQk6SwiHC1yD9Rha/x46H22UOLKMHp9GEaoylAFjcFjZJFQi6lKQkGFgS64627SU9zsCdNZyN4Y2d2yASbUU6RcXSXeI570aroBdHkwtbYZRAHSefyiF0IZ/jOi3uGwG5DbuO9we5NQytmEUKUzjWAxfcNG3fwSlvSzv6IQJcrj50PbC+gJhrZ3KrLSW1cGx0ZwUrhJJhNdzgK+pdIRkSC0ZDs3VkUSJ+TYorteUpr4/dgal1EpEyCaL1HAtp+z/alyEOz3pA/aeU4b2mhEABjjYE9hGR6G4BbEtJWI4lQBJ3WnvqM1V","preamble":85,"sender":8574,"contents":[53,5,172,138,50,49,206,234,149,204,113,31,108,188,179,154,156,167,145,139,42,207,126,242,193,9,58,75,8,135,11,92,131,245,24,90,255,30,58,31,109,148,56,178,140,30,159,70,17,170,50,148,1,99,112,88,217,36,84,34,234,82,144,144,97,96,75,174,58,219,180,148,247,59,2,116,214,114,55,134,54,119,108,128,73,181,20,233,23,23,73,119,136,231,189,26,174,128,93,30,76,45,109,134,81,0,116,158,127,40,133,208,134,127,140,232,183,184,108,6,228,54,238,59,220,30,228,212,50,182,97,20,41,76,227,88,12,95,112,209,183,127,4,165,189,44,239,232,132,9,114,184,249,208,246,194,250,2,97,173,157,202,172,180,150,213,193,177,209,156,20,174,18,73,132,215,115,128,175,169,116,132,100,72,45,25,14,205,213,145,68,137,249,54,40,174,215,148,166,190,63,118,6,165,212,74,68,200,38,139,212,112,45,167,236,255,106,92,132,59,61,233,3,246,158,83,134,246,154,17,0,6,56,216,19,216,70,71,161,184,5,177,45,37,98,56,149,0,73,221,105,239,168,205,85]}' + raw_packet: VQAIfiH/NQWsijIxzuqVzHEfbLyzmpynkYsqz37ywQk6SwiHC1yD9Rha/x46H22UOLKMHp9GEaoylAFjcFjZJFQi6lKQkGFgS64627SU9zsCdNZyN4Y2d2yASbUU6RcXSXeI570aroBdHkwtbYZRAHSefyiF0IZ/jOi3uGwG5DbuO9we5NQytmEUKUzjWAxfcNG3fwSlvSzv6IQJcrj50PbC+gJhrZ3KrLSW1cGx0ZwUrhJJhNdzgK+pdIRkSC0ZDs3VkUSJ+TYorteUpr4/dgal1EpEyCaL1HAtp+z/alyEOz3pA/aeU4b2mhEABjjYE9hGR6G4BbEtJWI4lQBJ3WnvqM1VUfU= + sbp: + crc: '0xf551' + length: 255 + msg_type: '0x800' + payload: NQWsijIxzuqVzHEfbLyzmpynkYsqz37ywQk6SwiHC1yD9Rha/x46H22UOLKMHp9GEaoylAFjcFjZJFQi6lKQkGFgS64627SU9zsCdNZyN4Y2d2yASbUU6RcXSXeI570aroBdHkwtbYZRAHSefyiF0IZ/jOi3uGwG5DbuO9we5NQytmEUKUzjWAxfcNG3fwSlvSzv6IQJcrj50PbC+gJhrZ3KrLSW1cGx0ZwUrhJJhNdzgK+pdIRkSC0ZDs3VkUSJ+TYorteUpr4/dgal1EpEyCaL1HAtp+z/alyEOz3pA/aeU4b2mhEABjjYE9hGR6G4BbEtJWI4lQBJ3WnvqM1V + preamble: '0x55' + sender: '0x217e' diff --git a/spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml b/spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml new file mode 100644 index 0000000000..6a53ae8825 --- /dev/null +++ b/spec/tests/yaml/swiftnav/sbp/vehicle/test_MsgWheeltick.yaml @@ -0,0 +1,23 @@ +description: Unit tests for swiftnav.sbp.vehicle MsgWheeltick +generated_on: 2023-11-15 # manually generated +package: sbp.vehicle +tests: + +- msg: + fields: + flags: 1 + source: 146 + ticks: -771148831 + time: 112414825470 + module: sbp.vehicle + name: MsgWheeltick + msg_type: '0x904' + raw_json: '{"preamble":85,"msg_type":2308,"sender":17771,"length":14,"payload":"/htyLBoAAAABkuEzCdI=","crc":14372,"time":112414825470,"flags":1,"source":146,"ticks":-771148831}' + raw_packet: VQQJa0UO/htyLBoAAAABkuEzCdIkOA== + sbp: + crc: '0x3824' + length: 14 + msg_type: '0x904' + payload: /htyLBoAAAABkuEzCdI= + preamble: '0x55' + sender: '0x456b'